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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #define DECODE_HEAD \ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 106 | __be32 *p; \ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 107 | __be32 status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define DECODE_TAIL \ |
| 109 | status = 0; \ |
| 110 | out: \ |
| 111 | return status; \ |
| 112 | xdr_error: \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 113 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 114 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | status = nfserr_bad_xdr; \ |
| 116 | goto out |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define READMEM(x,nbytes) do { \ |
| 119 | x = (char *)p; \ |
| 120 | p += XDR_QUADLEN(nbytes); \ |
| 121 | } while (0) |
| 122 | #define SAVEMEM(x,nbytes) do { \ |
| 123 | if (!(x = (p==argp->tmp || p == argp->tmpp) ? \ |
| 124 | savemem(argp, p, nbytes) : \ |
| 125 | (char *)p)) { \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 126 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 127 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | goto xdr_error; \ |
| 129 | } \ |
| 130 | p += XDR_QUADLEN(nbytes); \ |
| 131 | } while (0) |
| 132 | #define COPYMEM(x,nbytes) do { \ |
| 133 | memcpy((x), p, nbytes); \ |
| 134 | p += XDR_QUADLEN(nbytes); \ |
| 135 | } while (0) |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 136 | #define READ_BUF(nbytes) \ |
| 137 | do { \ |
| 138 | p = xdr_inline_decode(argp->xdr,\ |
| 139 | nbytes); \ |
| 140 | if (!p) \ |
| 141 | goto xdr_error; \ |
| 142 | } while (0) |
J. Bruce Fields | 2b86e3a | 2019-08-28 21:13:45 -0400 | [diff] [blame] | 143 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 144 | static int zero_clientid(clientid_t *clid) |
| 145 | { |
| 146 | return (clid->cl_boot == 0) && (clid->cl_id == 0); |
| 147 | } |
| 148 | |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 149 | /** |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 150 | * svcxdr_tmpalloc - allocate memory to be freed after compound processing |
J. Bruce Fields | ce043ac | 2014-06-24 16:51:12 -0400 | [diff] [blame] | 151 | * @argp: NFSv4 compound argument structure |
Trond Myklebust | ed99275 | 2019-08-18 14:18:59 -0400 | [diff] [blame] | 152 | * @len: length of buffer to allocate |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 153 | * |
Trond Myklebust | ed99275 | 2019-08-18 14:18:59 -0400 | [diff] [blame] | 154 | * Allocates a buffer of size @len to be freed when processing the compound |
| 155 | * operation described in @argp finishes. |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 156 | */ |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 157 | static void * |
| 158 | svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, u32 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 160 | struct svcxdr_tmpbuf *tb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 162 | tb = kmalloc(sizeof(*tb) + len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | if (!tb) |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 164 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | tb->next = argp->to_free; |
| 166 | argp->to_free = tb; |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 167 | return tb->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 170 | /* |
| 171 | * For xdr strings that need to be passed to other kernel api's |
| 172 | * as null-terminated strings. |
| 173 | * |
| 174 | * Note null-terminating in place usually isn't safe since the |
| 175 | * buffer might end on a page boundary. |
| 176 | */ |
| 177 | static char * |
| 178 | svcxdr_dupstr(struct nfsd4_compoundargs *argp, void *buf, u32 len) |
| 179 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 180 | char *p = svcxdr_tmpalloc(argp, len + 1); |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 181 | |
| 182 | if (!p) |
| 183 | return NULL; |
| 184 | memcpy(p, buf, len); |
| 185 | p[len] = '\0'; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 186 | return p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 189 | /** |
| 190 | * savemem - duplicate a chunk of memory for later processing |
| 191 | * @argp: NFSv4 compound argument structure to be freed with |
| 192 | * @p: pointer to be duplicated |
| 193 | * @nbytes: length to be duplicated |
| 194 | * |
| 195 | * Returns a pointer to a copy of @nbytes bytes of memory at @p |
| 196 | * that are preserved until processing of the NFSv4 compound |
| 197 | * operation described by @argp finishes. |
| 198 | */ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 199 | static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 201 | void *ret; |
| 202 | |
| 203 | ret = svcxdr_tmpalloc(argp, nbytes); |
| 204 | if (!ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return NULL; |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 206 | memcpy(ret, p, nbytes); |
| 207 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Chuck Lever | 5dcbfab | 2020-11-04 11:41:55 -0500 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * NFSv4 basic data type decoders |
| 213 | */ |
| 214 | |
| 215 | static __be32 |
| 216 | nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o) |
| 217 | { |
| 218 | __be32 *p; |
| 219 | u32 len; |
| 220 | |
| 221 | if (xdr_stream_decode_u32(argp->xdr, &len) < 0) |
| 222 | return nfserr_bad_xdr; |
| 223 | if (len == 0 || len > NFS4_OPAQUE_LIMIT) |
| 224 | return nfserr_bad_xdr; |
| 225 | p = xdr_inline_decode(argp->xdr, len); |
| 226 | if (!p) |
| 227 | return nfserr_bad_xdr; |
| 228 | o->data = svcxdr_tmpalloc(argp, len); |
| 229 | if (!o->data) |
| 230 | return nfserr_jukebox; |
| 231 | o->len = len; |
| 232 | memcpy(o->data, p, len); |
| 233 | |
| 234 | return nfs_ok; |
| 235 | } |
| 236 | |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 237 | static __be32 |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 238 | nfsd4_decode_component4(struct nfsd4_compoundargs *argp, char **namp, u32 *lenp) |
| 239 | { |
| 240 | __be32 *p, status; |
| 241 | |
| 242 | if (xdr_stream_decode_u32(argp->xdr, lenp) < 0) |
| 243 | return nfserr_bad_xdr; |
| 244 | p = xdr_inline_decode(argp->xdr, *lenp); |
| 245 | if (!p) |
| 246 | return nfserr_bad_xdr; |
| 247 | status = check_filename((char *)p, *lenp); |
| 248 | if (status) |
| 249 | return status; |
| 250 | *namp = svcxdr_tmpalloc(argp, *lenp); |
| 251 | if (!*namp) |
| 252 | return nfserr_jukebox; |
| 253 | memcpy(*namp, p, *lenp); |
| 254 | |
| 255 | return nfs_ok; |
| 256 | } |
| 257 | |
| 258 | static __be32 |
J. Bruce Fields | bdba536 | 2019-06-05 14:17:42 -0400 | [diff] [blame] | 259 | nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 260 | { |
| 261 | DECODE_HEAD; |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 262 | |
| 263 | READ_BUF(12); |
J. Bruce Fields | bdba536 | 2019-06-05 14:17:42 -0400 | [diff] [blame] | 264 | p = xdr_decode_hyper(p, &tv->tv_sec); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 265 | tv->tv_nsec = be32_to_cpup(p++); |
| 266 | if (tv->tv_nsec >= (u32)1000000000) |
| 267 | return nfserr_inval; |
| 268 | |
| 269 | DECODE_TAIL; |
| 270 | } |
| 271 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 272 | static __be32 |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 273 | nfsd4_decode_nfstime4(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
| 274 | { |
| 275 | __be32 *p; |
| 276 | |
| 277 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 3); |
| 278 | if (!p) |
| 279 | return nfserr_bad_xdr; |
| 280 | p = xdr_decode_hyper(p, &tv->tv_sec); |
| 281 | tv->tv_nsec = be32_to_cpup(p++); |
| 282 | if (tv->tv_nsec >= (u32)1000000000) |
| 283 | return nfserr_inval; |
| 284 | return nfs_ok; |
| 285 | } |
| 286 | |
| 287 | static __be32 |
Chuck Lever | 796dd1c | 2020-11-16 17:34:01 -0500 | [diff] [blame] | 288 | nfsd4_decode_verifier4(struct nfsd4_compoundargs *argp, nfs4_verifier *verf) |
| 289 | { |
| 290 | __be32 *p; |
| 291 | |
| 292 | p = xdr_inline_decode(argp->xdr, NFS4_VERIFIER_SIZE); |
| 293 | if (!p) |
| 294 | return nfserr_bad_xdr; |
| 295 | memcpy(verf->data, p, sizeof(verf->data)); |
| 296 | return nfs_ok; |
| 297 | } |
| 298 | |
| 299 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) |
| 301 | { |
| 302 | u32 bmlen; |
| 303 | DECODE_HEAD; |
| 304 | |
| 305 | bmval[0] = 0; |
| 306 | bmval[1] = 0; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 307 | bmval[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 310 | bmlen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (bmlen > 1000) |
| 312 | goto xdr_error; |
| 313 | |
| 314 | READ_BUF(bmlen << 2); |
| 315 | if (bmlen > 0) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 316 | bmval[0] = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (bmlen > 1) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 318 | bmval[1] = be32_to_cpup(p++); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 319 | if (bmlen > 2) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 320 | bmval[2] = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | DECODE_TAIL; |
| 323 | } |
| 324 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 325 | /** |
| 326 | * nfsd4_decode_bitmap4 - Decode an NFSv4 bitmap4 |
| 327 | * @argp: NFSv4 compound argument structure |
| 328 | * @bmval: pointer to an array of u32's to decode into |
| 329 | * @bmlen: size of the @bmval array |
| 330 | * |
| 331 | * The server needs to return nfs_ok rather than nfserr_bad_xdr when |
| 332 | * encountering bitmaps containing bits it does not recognize. This |
| 333 | * includes bits in bitmap words past WORDn, where WORDn is the last |
| 334 | * bitmap WORD the implementation currently supports. Thus we are |
| 335 | * careful here to simply ignore bits in bitmap words that this |
| 336 | * implementation has yet to support explicitly. |
| 337 | * |
| 338 | * Return values: |
| 339 | * %nfs_ok: @bmval populated successfully |
| 340 | * %nfserr_bad_xdr: the encoded bitmap was invalid |
| 341 | */ |
| 342 | static __be32 |
| 343 | nfsd4_decode_bitmap4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen) |
| 344 | { |
| 345 | u32 i, count; |
| 346 | __be32 *p; |
| 347 | |
| 348 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 349 | return nfserr_bad_xdr; |
| 350 | /* request sanity */ |
| 351 | if (count > 1000) |
| 352 | return nfserr_bad_xdr; |
| 353 | p = xdr_inline_decode(argp->xdr, count << 2); |
| 354 | if (!p) |
| 355 | return nfserr_bad_xdr; |
| 356 | i = 0; |
| 357 | while (i < count) |
| 358 | bmval[i++] = be32_to_cpup(p++); |
| 359 | while (i < bmlen) |
| 360 | bmval[i++] = 0; |
| 361 | |
| 362 | return nfs_ok; |
| 363 | } |
| 364 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 365 | static __be32 |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 366 | nfsd4_decode_nfsace4(struct nfsd4_compoundargs *argp, struct nfs4_ace *ace) |
| 367 | { |
| 368 | __be32 *p, status; |
| 369 | u32 length; |
| 370 | |
| 371 | if (xdr_stream_decode_u32(argp->xdr, &ace->type) < 0) |
| 372 | return nfserr_bad_xdr; |
| 373 | if (xdr_stream_decode_u32(argp->xdr, &ace->flag) < 0) |
| 374 | return nfserr_bad_xdr; |
| 375 | if (xdr_stream_decode_u32(argp->xdr, &ace->access_mask) < 0) |
| 376 | return nfserr_bad_xdr; |
| 377 | |
| 378 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 379 | return nfserr_bad_xdr; |
| 380 | p = xdr_inline_decode(argp->xdr, length); |
| 381 | if (!p) |
| 382 | return nfserr_bad_xdr; |
| 383 | ace->whotype = nfs4_acl_get_whotype((char *)p, length); |
| 384 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
| 385 | status = nfs_ok; |
| 386 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
| 387 | status = nfsd_map_name_to_gid(argp->rqstp, |
| 388 | (char *)p, length, &ace->who_gid); |
| 389 | else |
| 390 | status = nfsd_map_name_to_uid(argp->rqstp, |
| 391 | (char *)p, length, &ace->who_uid); |
| 392 | |
| 393 | return status; |
| 394 | } |
| 395 | |
| 396 | /* A counted array of nfsace4's */ |
| 397 | static noinline __be32 |
| 398 | nfsd4_decode_acl(struct nfsd4_compoundargs *argp, struct nfs4_acl **acl) |
| 399 | { |
| 400 | struct nfs4_ace *ace; |
| 401 | __be32 status; |
| 402 | u32 count; |
| 403 | |
| 404 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 405 | return nfserr_bad_xdr; |
| 406 | |
| 407 | if (count > xdr_stream_remaining(argp->xdr) / 20) |
| 408 | /* |
| 409 | * Even with 4-byte names there wouldn't be |
| 410 | * space for that many aces; something fishy is |
| 411 | * going on: |
| 412 | */ |
| 413 | return nfserr_fbig; |
| 414 | |
| 415 | *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(count)); |
| 416 | if (*acl == NULL) |
| 417 | return nfserr_jukebox; |
| 418 | |
| 419 | (*acl)->naces = count; |
| 420 | for (ace = (*acl)->aces; ace < (*acl)->aces + count; ace++) { |
| 421 | status = nfsd4_decode_nfsace4(argp, ace); |
| 422 | if (status) |
| 423 | return status; |
| 424 | } |
| 425 | |
| 426 | return nfs_ok; |
| 427 | } |
| 428 | |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 429 | static noinline __be32 |
| 430 | nfsd4_decode_security_label(struct nfsd4_compoundargs *argp, |
| 431 | struct xdr_netobj *label) |
| 432 | { |
| 433 | u32 lfs, pi, length; |
| 434 | __be32 *p; |
| 435 | |
| 436 | if (xdr_stream_decode_u32(argp->xdr, &lfs) < 0) |
| 437 | return nfserr_bad_xdr; |
| 438 | if (xdr_stream_decode_u32(argp->xdr, &pi) < 0) |
| 439 | return nfserr_bad_xdr; |
| 440 | |
| 441 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 442 | return nfserr_bad_xdr; |
| 443 | if (length > NFS4_MAXLABELLEN) |
| 444 | return nfserr_badlabel; |
| 445 | p = xdr_inline_decode(argp->xdr, length); |
| 446 | if (!p) |
| 447 | return nfserr_bad_xdr; |
| 448 | label->len = length; |
| 449 | label->data = svcxdr_dupstr(argp, p, length); |
| 450 | if (!label->data) |
| 451 | return nfserr_jukebox; |
| 452 | |
| 453 | return nfs_ok; |
| 454 | } |
| 455 | |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 456 | static __be32 |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 457 | nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, |
| 458 | struct iattr *iattr, struct nfs4_acl **acl, |
| 459 | struct xdr_netobj *label, int *umask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 461 | unsigned int starting_pos; |
| 462 | u32 attrlist4_count; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 463 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | iattr->ia_valid = 0; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 466 | status = nfsd4_decode_bitmap4(argp, bmval, bmlen); |
| 467 | if (status) |
| 468 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
J. Bruce Fields | e864c18 | 2016-06-10 16:56:05 -0400 | [diff] [blame] | 470 | if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 |
| 471 | || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 |
| 472 | || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) { |
| 473 | if (nfsd_attrs_supported(argp->minorversion, bmval)) |
| 474 | return nfserr_inval; |
| 475 | return nfserr_attrnotsupp; |
| 476 | } |
| 477 | |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 478 | if (xdr_stream_decode_u32(argp->xdr, &attrlist4_count) < 0) |
| 479 | return nfserr_bad_xdr; |
| 480 | starting_pos = xdr_stream_pos(argp->xdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | if (bmval[0] & FATTR4_WORD0_SIZE) { |
Chuck Lever | 2ac1b9b | 2020-11-19 13:47:16 -0500 | [diff] [blame] | 483 | u64 size; |
| 484 | |
| 485 | if (xdr_stream_decode_u64(argp->xdr, &size) < 0) |
| 486 | return nfserr_bad_xdr; |
| 487 | iattr->ia_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | iattr->ia_valid |= ATTR_SIZE; |
| 489 | } |
| 490 | if (bmval[0] & FATTR4_WORD0_ACL) { |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 491 | status = nfsd4_decode_acl(argp, acl); |
| 492 | if (status) |
| 493 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } else |
| 495 | *acl = NULL; |
| 496 | if (bmval[1] & FATTR4_WORD1_MODE) { |
Chuck Lever | 1c8f0ad | 2020-11-19 13:54:26 -0500 | [diff] [blame] | 497 | u32 mode; |
| 498 | |
| 499 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 500 | return nfserr_bad_xdr; |
| 501 | iattr->ia_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
| 503 | iattr->ia_valid |= ATTR_MODE; |
| 504 | } |
| 505 | if (bmval[1] & FATTR4_WORD1_OWNER) { |
Chuck Lever | 9853a5a | 2020-11-19 13:56:42 -0500 | [diff] [blame] | 506 | u32 length; |
| 507 | |
| 508 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 509 | return nfserr_bad_xdr; |
| 510 | p = xdr_inline_decode(argp->xdr, length); |
| 511 | if (!p) |
| 512 | return nfserr_bad_xdr; |
| 513 | status = nfsd_map_name_to_uid(argp->rqstp, (char *)p, length, |
| 514 | &iattr->ia_uid); |
| 515 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 516 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | iattr->ia_valid |= ATTR_UID; |
| 518 | } |
| 519 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { |
Chuck Lever | 393c31d | 2020-11-19 13:58:18 -0500 | [diff] [blame] | 520 | u32 length; |
| 521 | |
| 522 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 523 | return nfserr_bad_xdr; |
| 524 | p = xdr_inline_decode(argp->xdr, length); |
| 525 | if (!p) |
| 526 | return nfserr_bad_xdr; |
| 527 | status = nfsd_map_name_to_gid(argp->rqstp, (char *)p, length, |
| 528 | &iattr->ia_gid); |
| 529 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 530 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | iattr->ia_valid |= ATTR_GID; |
| 532 | } |
| 533 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 534 | u32 set_it; |
| 535 | |
| 536 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 537 | return nfserr_bad_xdr; |
| 538 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 540 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_atime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 541 | if (status) |
| 542 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
| 544 | break; |
| 545 | case NFS4_SET_TO_SERVER_TIME: |
| 546 | iattr->ia_valid |= ATTR_ATIME; |
| 547 | break; |
| 548 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 549 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 553 | u32 set_it; |
| 554 | |
| 555 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 556 | return nfserr_bad_xdr; |
| 557 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 559 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_mtime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 560 | if (status) |
| 561 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
| 563 | break; |
| 564 | case NFS4_SET_TO_SERVER_TIME: |
| 565 | iattr->ia_valid |= ATTR_MTIME; |
| 566 | break; |
| 567 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 568 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 571 | label->len = 0; |
Arnd Bergmann | 2285ae7 | 2018-01-22 22:09:12 +0100 | [diff] [blame] | 572 | if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) && |
| 573 | bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 574 | status = nfsd4_decode_security_label(argp, label); |
| 575 | if (status) |
| 576 | return status; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 577 | } |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 578 | if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 579 | u32 mode, mask; |
| 580 | |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 581 | if (!umask) |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 582 | return nfserr_bad_xdr; |
| 583 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 584 | return nfserr_bad_xdr; |
| 585 | iattr->ia_mode = mode & (S_IFMT | S_IALLUGO); |
| 586 | if (xdr_stream_decode_u32(argp->xdr, &mask) < 0) |
| 587 | return nfserr_bad_xdr; |
| 588 | *umask = mask & S_IRWXUGO; |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 589 | iattr->ia_valid |= ATTR_MODE; |
| 590 | } |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 591 | |
| 592 | /* request sanity: did attrlist4 contain the expected number of words? */ |
| 593 | if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos) |
| 594 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 596 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 599 | static __be32 |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 600 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 601 | { |
| 602 | DECODE_HEAD; |
| 603 | |
| 604 | READ_BUF(sizeof(stateid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 605 | sid->si_generation = be32_to_cpup(p++); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 606 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 607 | |
| 608 | DECODE_TAIL; |
| 609 | } |
| 610 | |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 611 | static __be32 |
| 612 | nfsd4_decode_stateid4(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 613 | { |
| 614 | __be32 *p; |
| 615 | |
| 616 | p = xdr_inline_decode(argp->xdr, NFS4_STATEID_SIZE); |
| 617 | if (!p) |
| 618 | return nfserr_bad_xdr; |
| 619 | sid->si_generation = be32_to_cpup(p++); |
| 620 | memcpy(&sid->si_opaque, p, sizeof(sid->si_opaque)); |
| 621 | return nfs_ok; |
| 622 | } |
| 623 | |
Chuck Lever | 144e826 | 2020-11-16 17:25:02 -0500 | [diff] [blame] | 624 | static __be32 |
| 625 | nfsd4_decode_clientid4(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 626 | { |
| 627 | __be32 *p; |
| 628 | |
| 629 | p = xdr_inline_decode(argp->xdr, sizeof(__be64)); |
| 630 | if (!p) |
| 631 | return nfserr_bad_xdr; |
| 632 | memcpy(clientid, p, sizeof(*clientid)); |
| 633 | return nfs_ok; |
| 634 | } |
| 635 | |
| 636 | static __be32 |
| 637 | nfsd4_decode_state_owner4(struct nfsd4_compoundargs *argp, |
| 638 | clientid_t *clientid, struct xdr_netobj *owner) |
| 639 | { |
| 640 | __be32 status; |
| 641 | |
| 642 | status = nfsd4_decode_clientid4(argp, clientid); |
| 643 | if (status) |
| 644 | return status; |
| 645 | return nfsd4_decode_opaque(argp, owner); |
| 646 | } |
| 647 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 648 | static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs) |
| 649 | { |
| 650 | DECODE_HEAD; |
Trond Myklebust | e45d1a1 | 2019-04-09 12:13:42 -0400 | [diff] [blame] | 651 | struct user_namespace *userns = nfsd_user_namespace(argp->rqstp); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 652 | u32 dummy, uid, gid; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 653 | char *machine_name; |
| 654 | int i; |
| 655 | int nr_secflavs; |
| 656 | |
| 657 | /* callback_sec_params4 */ |
| 658 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 659 | nr_secflavs = be32_to_cpup(p++); |
J. Bruce Fields | 57569a7 | 2013-05-17 16:25:32 -0400 | [diff] [blame] | 660 | if (nr_secflavs) |
| 661 | cbs->flavor = (u32)(-1); |
| 662 | else |
| 663 | /* Is this legal? Be generous, take it to mean AUTH_NONE: */ |
| 664 | cbs->flavor = 0; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 665 | for (i = 0; i < nr_secflavs; ++i) { |
| 666 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 667 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 668 | switch (dummy) { |
| 669 | case RPC_AUTH_NULL: |
| 670 | /* Nothing to read */ |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 671 | if (cbs->flavor == (u32)(-1)) |
| 672 | cbs->flavor = RPC_AUTH_NULL; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 673 | break; |
| 674 | case RPC_AUTH_UNIX: |
| 675 | READ_BUF(8); |
| 676 | /* stamp */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 677 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 678 | |
| 679 | /* machine name */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 680 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 681 | READ_BUF(dummy); |
| 682 | SAVEMEM(machine_name, dummy); |
| 683 | |
| 684 | /* uid, gid */ |
| 685 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 686 | uid = be32_to_cpup(p++); |
| 687 | gid = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 688 | |
| 689 | /* more gids */ |
| 690 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 691 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 692 | READ_BUF(dummy * 4); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 693 | if (cbs->flavor == (u32)(-1)) { |
Trond Myklebust | e45d1a1 | 2019-04-09 12:13:42 -0400 | [diff] [blame] | 694 | kuid_t kuid = make_kuid(userns, uid); |
| 695 | kgid_t kgid = make_kgid(userns, gid); |
Eric W. Biederman | 03bc6d1 | 2013-02-02 06:24:49 -0800 | [diff] [blame] | 696 | if (uid_valid(kuid) && gid_valid(kgid)) { |
| 697 | cbs->uid = kuid; |
| 698 | cbs->gid = kgid; |
| 699 | cbs->flavor = RPC_AUTH_UNIX; |
| 700 | } else { |
| 701 | dprintk("RPC_AUTH_UNIX with invalid" |
| 702 | "uid or gid ignoring!\n"); |
| 703 | } |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 704 | } |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 705 | break; |
| 706 | case RPC_AUTH_GSS: |
| 707 | dprintk("RPC_AUTH_GSS callback secflavor " |
| 708 | "not supported!\n"); |
| 709 | READ_BUF(8); |
| 710 | /* gcbp_service */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 711 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 712 | /* gcbp_handle_from_server */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 713 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 714 | READ_BUF(dummy); |
| 715 | p += XDR_QUADLEN(dummy); |
| 716 | /* gcbp_handle_from_client */ |
| 717 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 718 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 719 | READ_BUF(dummy); |
| 720 | break; |
| 721 | default: |
| 722 | dprintk("Illegal callback secflavor\n"); |
| 723 | return nfserr_inval; |
| 724 | } |
| 725 | } |
| 726 | DECODE_TAIL; |
| 727 | } |
| 728 | |
Chuck Lever | d169a6a | 2020-11-03 13:12:27 -0500 | [diff] [blame] | 729 | /* |
| 730 | * NFSv4 operation argument decoders |
| 731 | */ |
| 732 | |
| 733 | static __be32 |
| 734 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, |
| 735 | struct nfsd4_access *access) |
| 736 | { |
| 737 | if (xdr_stream_decode_u32(argp->xdr, &access->ac_req_access) < 0) |
| 738 | return nfserr_bad_xdr; |
| 739 | return nfs_ok; |
| 740 | } |
| 741 | |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 742 | static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc) |
| 743 | { |
| 744 | DECODE_HEAD; |
| 745 | |
| 746 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 747 | bc->bc_cb_program = be32_to_cpup(p++); |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 748 | nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec); |
| 749 | |
| 750 | DECODE_TAIL; |
| 751 | } |
| 752 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 753 | static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts) |
| 754 | { |
| 755 | DECODE_HEAD; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 756 | |
| 757 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 8); |
| 758 | COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 759 | bcts->dir = be32_to_cpup(p++); |
Bryan Schumaker | 6ce2357 | 2011-04-27 15:47:16 -0400 | [diff] [blame] | 760 | /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker |
| 761 | * could help us figure out we should be using it. */ |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 762 | DECODE_TAIL; |
| 763 | } |
| 764 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 765 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
| 767 | { |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 768 | if (xdr_stream_decode_u32(argp->xdr, &close->cl_seqid) < 0) |
| 769 | return nfserr_bad_xdr; |
| 770 | return nfsd4_decode_stateid4(argp, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 774 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
| 776 | { |
Chuck Lever | cbd9abb | 2020-11-03 13:19:51 -0500 | [diff] [blame] | 777 | if (xdr_stream_decode_u64(argp->xdr, &commit->co_offset) < 0) |
| 778 | return nfserr_bad_xdr; |
| 779 | if (xdr_stream_decode_u32(argp->xdr, &commit->co_count) < 0) |
| 780 | return nfserr_bad_xdr; |
| 781 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 784 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
| 786 | { |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 787 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 789 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_type) < 0) |
| 790 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | switch (create->cr_type) { |
| 792 | case NF4LNK: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 793 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_datalen) < 0) |
| 794 | return nfserr_bad_xdr; |
| 795 | p = xdr_inline_decode(argp->xdr, create->cr_datalen); |
| 796 | if (!p) |
| 797 | return nfserr_bad_xdr; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 798 | create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen); |
J. Bruce Fields | 7fb8430 | 2014-06-24 15:06:41 -0400 | [diff] [blame] | 799 | if (!create->cr_data) |
J. Bruce Fields | 76f47128 | 2014-06-19 16:44:48 -0400 | [diff] [blame] | 800 | return nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | break; |
| 802 | case NF4BLK: |
| 803 | case NF4CHR: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 804 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata1) < 0) |
| 805 | return nfserr_bad_xdr; |
| 806 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata2) < 0) |
| 807 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | break; |
| 809 | case NF4SOCK: |
| 810 | case NF4FIFO: |
| 811 | case NF4DIR: |
| 812 | default: |
| 813 | break; |
| 814 | } |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 815 | status = nfsd4_decode_component4(argp, &create->cr_name, |
| 816 | &create->cr_namelen); |
| 817 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 819 | status = nfsd4_decode_fattr4(argp, create->cr_bmval, |
| 820 | ARRAY_SIZE(create->cr_bmval), |
| 821 | &create->cr_iattr, &create->cr_acl, |
| 822 | &create->cr_label, &create->cr_umask); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 823 | if (status) |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 824 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 826 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 829 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
| 831 | { |
Chuck Lever | 95e6482 | 2020-11-21 14:11:58 -0500 | [diff] [blame] | 832 | return nfsd4_decode_stateid4(argp, &dr->dr_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 835 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
| 837 | { |
Chuck Lever | f759eff | 2020-11-19 14:40:20 -0500 | [diff] [blame] | 838 | return nfsd4_decode_bitmap4(argp, getattr->ga_bmval, |
| 839 | ARRAY_SIZE(getattr->ga_bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 842 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
| 844 | { |
Chuck Lever | 5c505d1 | 2020-11-04 15:01:24 -0500 | [diff] [blame] | 845 | return nfsd4_decode_component4(argp, &link->li_name, &link->li_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 848 | static __be32 |
Chuck Lever | 8918cc0 | 2020-11-16 17:16:52 -0500 | [diff] [blame] | 849 | nfsd4_decode_open_to_lock_owner4(struct nfsd4_compoundargs *argp, |
| 850 | struct nfsd4_lock *lock) |
| 851 | { |
| 852 | __be32 status; |
| 853 | |
| 854 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_open_seqid) < 0) |
| 855 | return nfserr_bad_xdr; |
| 856 | status = nfsd4_decode_stateid4(argp, &lock->lk_new_open_stateid); |
| 857 | if (status) |
| 858 | return status; |
| 859 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_lock_seqid) < 0) |
| 860 | return nfserr_bad_xdr; |
| 861 | return nfsd4_decode_state_owner4(argp, &lock->lk_new_clientid, |
| 862 | &lock->lk_new_owner); |
| 863 | } |
| 864 | |
| 865 | static __be32 |
| 866 | nfsd4_decode_exist_lock_owner4(struct nfsd4_compoundargs *argp, |
| 867 | struct nfsd4_lock *lock) |
| 868 | { |
| 869 | __be32 status; |
| 870 | |
| 871 | status = nfsd4_decode_stateid4(argp, &lock->lk_old_lock_stateid); |
| 872 | if (status) |
| 873 | return status; |
| 874 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_old_lock_seqid) < 0) |
| 875 | return nfserr_bad_xdr; |
| 876 | |
| 877 | return nfs_ok; |
| 878 | } |
| 879 | |
| 880 | static __be32 |
| 881 | nfsd4_decode_locker4(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 882 | { |
| 883 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_is_new) < 0) |
| 884 | return nfserr_bad_xdr; |
| 885 | if (lock->lk_is_new) |
| 886 | return nfsd4_decode_open_to_lock_owner4(argp, lock); |
| 887 | return nfsd4_decode_exist_lock_owner4(argp, lock); |
| 888 | } |
| 889 | |
| 890 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 892 | { |
Chuck Lever | 7c59dee | 2020-11-03 13:29:27 -0500 | [diff] [blame] | 893 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_type) < 0) |
| 894 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | 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] | 896 | return nfserr_bad_xdr; |
| 897 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_reclaim) < 0) |
| 898 | return nfserr_bad_xdr; |
| 899 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_offset) < 0) |
| 900 | return nfserr_bad_xdr; |
| 901 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_length) < 0) |
| 902 | return nfserr_bad_xdr; |
| 903 | return nfsd4_decode_locker4(argp, lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 906 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
| 908 | { |
Chuck Lever | 0a146f0 | 2020-11-03 13:31:44 -0500 | [diff] [blame] | 909 | if (xdr_stream_decode_u32(argp->xdr, &lockt->lt_type) < 0) |
| 910 | return nfserr_bad_xdr; |
| 911 | if ((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
| 912 | return nfserr_bad_xdr; |
| 913 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_offset) < 0) |
| 914 | return nfserr_bad_xdr; |
| 915 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_length) < 0) |
| 916 | return nfserr_bad_xdr; |
| 917 | return nfsd4_decode_state_owner4(argp, &lockt->lt_clientid, |
| 918 | &lockt->lt_owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 921 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
| 923 | { |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 924 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 926 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_type) < 0) |
| 927 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | 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] | 929 | return nfserr_bad_xdr; |
| 930 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_seqid) < 0) |
| 931 | return nfserr_bad_xdr; |
| 932 | status = nfsd4_decode_stateid4(argp, &locku->lu_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 933 | if (status) |
| 934 | return status; |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 935 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_offset) < 0) |
| 936 | return nfserr_bad_xdr; |
| 937 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_length) < 0) |
| 938 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 940 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 943 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
| 945 | { |
Chuck Lever | 3d5877e | 2020-11-04 15:02:40 -0500 | [diff] [blame] | 946 | return nfsd4_decode_component4(argp, &lookup->lo_name, &lookup->lo_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Chuck Lever | bf33bab | 2020-11-16 17:37:42 -0500 | [diff] [blame] | 949 | static __be32 |
| 950 | nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 951 | { |
| 952 | __be32 status; |
| 953 | |
| 954 | if (xdr_stream_decode_u32(argp->xdr, &open->op_createmode) < 0) |
| 955 | return nfserr_bad_xdr; |
| 956 | switch (open->op_createmode) { |
| 957 | case NFS4_CREATE_UNCHECKED: |
| 958 | case NFS4_CREATE_GUARDED: |
| 959 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 960 | ARRAY_SIZE(open->op_bmval), |
| 961 | &open->op_iattr, &open->op_acl, |
| 962 | &open->op_label, &open->op_umask); |
| 963 | if (status) |
| 964 | return status; |
| 965 | break; |
| 966 | case NFS4_CREATE_EXCLUSIVE: |
| 967 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 968 | if (status) |
| 969 | return status; |
| 970 | break; |
| 971 | case NFS4_CREATE_EXCLUSIVE4_1: |
| 972 | if (argp->minorversion < 1) |
| 973 | return nfserr_bad_xdr; |
| 974 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 975 | if (status) |
| 976 | return status; |
| 977 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 978 | ARRAY_SIZE(open->op_bmval), |
| 979 | &open->op_iattr, &open->op_acl, |
| 980 | &open->op_label, &open->op_umask); |
| 981 | if (status) |
| 982 | return status; |
| 983 | break; |
| 984 | default: |
| 985 | return nfserr_bad_xdr; |
| 986 | } |
| 987 | |
| 988 | return nfs_ok; |
| 989 | } |
| 990 | |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 991 | static __be32 |
| 992 | nfsd4_decode_openflag4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 993 | { |
| 994 | __be32 status; |
| 995 | |
| 996 | if (xdr_stream_decode_u32(argp->xdr, &open->op_create) < 0) |
| 997 | return nfserr_bad_xdr; |
| 998 | switch (open->op_create) { |
| 999 | case NFS4_OPEN_NOCREATE: |
| 1000 | break; |
| 1001 | case NFS4_OPEN_CREATE: |
| 1002 | status = nfsd4_decode_createhow4(argp, open); |
| 1003 | if (status) |
| 1004 | return status; |
| 1005 | break; |
| 1006 | default: |
| 1007 | return nfserr_bad_xdr; |
| 1008 | } |
| 1009 | |
| 1010 | return nfs_ok; |
| 1011 | } |
| 1012 | |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1013 | 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] | 1014 | { |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1015 | u32 w; |
| 1016 | |
Chuck Lever | 9aa62f5 | 2020-11-16 17:54:48 -0500 | [diff] [blame] | 1017 | if (xdr_stream_decode_u32(argp->xdr, &w) < 0) |
| 1018 | return nfserr_bad_xdr; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1019 | *share_access = w & NFS4_SHARE_ACCESS_MASK; |
| 1020 | *deleg_want = w & NFS4_SHARE_WANT_MASK; |
| 1021 | if (deleg_when) |
| 1022 | *deleg_when = w & NFS4_SHARE_WHEN_MASK; |
| 1023 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1024 | switch (w & NFS4_SHARE_ACCESS_MASK) { |
| 1025 | case NFS4_SHARE_ACCESS_READ: |
| 1026 | case NFS4_SHARE_ACCESS_WRITE: |
| 1027 | case NFS4_SHARE_ACCESS_BOTH: |
| 1028 | break; |
| 1029 | default: |
| 1030 | return nfserr_bad_xdr; |
| 1031 | } |
Benny Halevy | fc0d14f | 2011-10-27 20:43:01 +0200 | [diff] [blame] | 1032 | w &= ~NFS4_SHARE_ACCESS_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1033 | if (!w) |
| 1034 | return nfs_ok; |
| 1035 | if (!argp->minorversion) |
| 1036 | return nfserr_bad_xdr; |
| 1037 | switch (w & NFS4_SHARE_WANT_MASK) { |
| 1038 | case NFS4_SHARE_WANT_NO_PREFERENCE: |
| 1039 | case NFS4_SHARE_WANT_READ_DELEG: |
| 1040 | case NFS4_SHARE_WANT_WRITE_DELEG: |
| 1041 | case NFS4_SHARE_WANT_ANY_DELEG: |
| 1042 | case NFS4_SHARE_WANT_NO_DELEG: |
| 1043 | case NFS4_SHARE_WANT_CANCEL: |
| 1044 | break; |
| 1045 | default: |
| 1046 | return nfserr_bad_xdr; |
| 1047 | } |
Benny Halevy | 92bac8c | 2011-10-19 19:13:29 -0700 | [diff] [blame] | 1048 | w &= ~NFS4_SHARE_WANT_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1049 | if (!w) |
| 1050 | return nfs_ok; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1051 | |
| 1052 | if (!deleg_when) /* open_downgrade */ |
| 1053 | return nfserr_inval; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1054 | switch (w) { |
| 1055 | case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL: |
| 1056 | case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED: |
Benny Halevy | c668fc6 | 2011-10-19 19:13:13 -0700 | [diff] [blame] | 1057 | case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL | |
| 1058 | NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED): |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1059 | return nfs_ok; |
| 1060 | } |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1061 | return nfserr_bad_xdr; |
| 1062 | } |
| 1063 | |
| 1064 | static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x) |
| 1065 | { |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1066 | if (xdr_stream_decode_u32(argp->xdr, x) < 0) |
| 1067 | return nfserr_bad_xdr; |
| 1068 | /* Note: unlike access bits, deny bits may be zero. */ |
Dan Carpenter | 01cd4af | 2011-10-17 10:41:17 +0300 | [diff] [blame] | 1069 | if (*x & ~NFS4_SHARE_DENY_BOTH) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1070 | return nfserr_bad_xdr; |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1071 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1072 | return nfs_ok; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1075 | static __be32 |
Chuck Lever | 1708e50 | 2020-11-16 17:45:04 -0500 | [diff] [blame] | 1076 | nfsd4_decode_open_claim4(struct nfsd4_compoundargs *argp, |
| 1077 | struct nfsd4_open *open) |
| 1078 | { |
| 1079 | __be32 status; |
| 1080 | |
| 1081 | if (xdr_stream_decode_u32(argp->xdr, &open->op_claim_type) < 0) |
| 1082 | return nfserr_bad_xdr; |
| 1083 | switch (open->op_claim_type) { |
| 1084 | case NFS4_OPEN_CLAIM_NULL: |
| 1085 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1086 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1087 | &open->op_fnamelen); |
| 1088 | if (status) |
| 1089 | return status; |
| 1090 | break; |
| 1091 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1092 | if (xdr_stream_decode_u32(argp->xdr, &open->op_delegate_type) < 0) |
| 1093 | return nfserr_bad_xdr; |
| 1094 | break; |
| 1095 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1096 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1097 | if (status) |
| 1098 | return status; |
| 1099 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1100 | &open->op_fnamelen); |
| 1101 | if (status) |
| 1102 | return status; |
| 1103 | break; |
| 1104 | case NFS4_OPEN_CLAIM_FH: |
| 1105 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1106 | if (argp->minorversion < 1) |
| 1107 | return nfserr_bad_xdr; |
| 1108 | /* void */ |
| 1109 | break; |
| 1110 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1111 | if (argp->minorversion < 1) |
| 1112 | return nfserr_bad_xdr; |
| 1113 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1114 | if (status) |
| 1115 | return status; |
| 1116 | break; |
| 1117 | default: |
| 1118 | return nfserr_bad_xdr; |
| 1119 | } |
| 1120 | |
| 1121 | return nfs_ok; |
| 1122 | } |
| 1123 | |
| 1124 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 1126 | { |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1127 | __be32 status; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1128 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); |
| 1131 | open->op_iattr.ia_valid = 0; |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 1132 | open->op_openowner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 1134 | open->op_xdr_error = 0; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1135 | if (xdr_stream_decode_u32(argp->xdr, &open->op_seqid) < 0) |
| 1136 | return nfserr_bad_xdr; |
| 1137 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1138 | status = nfsd4_decode_share_access(argp, &open->op_share_access, |
| 1139 | &open->op_deleg_want, &dummy); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1140 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1141 | return status; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1142 | status = nfsd4_decode_share_deny(argp, &open->op_share_deny); |
| 1143 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1144 | return status; |
| 1145 | status = nfsd4_decode_state_owner4(argp, &open->op_clientid, |
| 1146 | &open->op_owner); |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1147 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1148 | return status; |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 1149 | status = nfsd4_decode_openflag4(argp, open); |
| 1150 | if (status) |
| 1151 | return status; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1152 | return nfsd4_decode_open_claim4(argp, open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1155 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
| 1157 | { |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1158 | __be32 status; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1159 | |
| 1160 | if (argp->minorversion >= 1) |
| 1161 | return nfserr_notsupp; |
| 1162 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1163 | status = nfsd4_decode_stateid4(argp, &open_conf->oc_req_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1164 | if (status) |
| 1165 | return status; |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1166 | if (xdr_stream_decode_u32(argp->xdr, &open_conf->oc_seqid) < 0) |
| 1167 | return nfserr_bad_xdr; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1168 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1169 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1172 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
| 1174 | { |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1175 | __be32 status; |
| 1176 | |
| 1177 | status = nfsd4_decode_stateid4(argp, &open_down->od_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1178 | if (status) |
| 1179 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1180 | if (xdr_stream_decode_u32(argp->xdr, &open_down->od_seqid) < 0) |
| 1181 | return nfserr_bad_xdr; |
| 1182 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1183 | status = nfsd4_decode_share_access(argp, &open_down->od_share_access, |
| 1184 | &open_down->od_deleg_want, NULL); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1185 | if (status) |
| 1186 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1187 | return nfsd4_decode_share_deny(argp, &open_down->od_share_deny); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1190 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
| 1192 | { |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1193 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1195 | if (xdr_stream_decode_u32(argp->xdr, &putfh->pf_fhlen) < 0) |
| 1196 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1198 | return nfserr_bad_xdr; |
| 1199 | p = xdr_inline_decode(argp->xdr, putfh->pf_fhlen); |
| 1200 | if (!p) |
| 1201 | return nfserr_bad_xdr; |
| 1202 | putfh->pf_fhval = svcxdr_tmpalloc(argp, putfh->pf_fhlen); |
| 1203 | if (!putfh->pf_fhval) |
| 1204 | return nfserr_jukebox; |
| 1205 | memcpy(putfh->pf_fhval, p, putfh->pf_fhlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1207 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1210 | static __be32 |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1211 | nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p) |
| 1212 | { |
| 1213 | if (argp->minorversion == 0) |
| 1214 | return nfs_ok; |
| 1215 | return nfserr_notsupp; |
| 1216 | } |
| 1217 | |
| 1218 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
| 1220 | { |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1221 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1223 | status = nfsd4_decode_stateid4(argp, &read->rd_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1224 | if (status) |
| 1225 | return status; |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1226 | if (xdr_stream_decode_u64(argp->xdr, &read->rd_offset) < 0) |
| 1227 | return nfserr_bad_xdr; |
| 1228 | if (xdr_stream_decode_u32(argp->xdr, &read->rd_length) < 0) |
| 1229 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1231 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1234 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
| 1236 | { |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1237 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1239 | if (xdr_stream_decode_u64(argp->xdr, &readdir->rd_cookie) < 0) |
| 1240 | return nfserr_bad_xdr; |
| 1241 | status = nfsd4_decode_verifier4(argp, &readdir->rd_verf); |
| 1242 | if (status) |
| 1243 | return status; |
| 1244 | if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_dircount) < 0) |
| 1245 | return nfserr_bad_xdr; |
| 1246 | if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_maxcount) < 0) |
| 1247 | return nfserr_bad_xdr; |
| 1248 | if (xdr_stream_decode_uint32_array(argp->xdr, readdir->rd_bmval, |
| 1249 | ARRAY_SIZE(readdir->rd_bmval)) < 0) |
| 1250 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1252 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1255 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
| 1257 | { |
Chuck Lever | b7f5fbf | 2020-11-04 15:04:36 -0500 | [diff] [blame] | 1258 | return nfsd4_decode_component4(argp, &remove->rm_name, &remove->rm_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1261 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
| 1263 | { |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1264 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1266 | status = nfsd4_decode_component4(argp, &rename->rn_sname, &rename->rn_snamelen); |
| 1267 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | return status; |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1269 | return nfsd4_decode_component4(argp, &rename->rn_tname, &rename->rn_tnamelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1272 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 1274 | { |
Chuck Lever | d12f904 | 2020-11-04 15:08:50 -0500 | [diff] [blame] | 1275 | return nfsd4_decode_clientid4(argp, clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1278 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1279 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, |
| 1280 | struct nfsd4_secinfo *secinfo) |
| 1281 | { |
Chuck Lever | d0abdae | 2020-11-04 15:09:42 -0500 | [diff] [blame] | 1282 | return nfsd4_decode_component4(argp, &secinfo->si_name, &secinfo->si_namelen); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | static __be32 |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1286 | nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp, |
| 1287 | struct nfsd4_secinfo_no_name *sin) |
| 1288 | { |
| 1289 | DECODE_HEAD; |
| 1290 | |
| 1291 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1292 | sin->sin_style = be32_to_cpup(p++); |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1293 | DECODE_TAIL; |
| 1294 | } |
| 1295 | |
| 1296 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
| 1298 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1299 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
Chuck Lever | 44592fe | 2020-11-21 14:14:59 -0500 | [diff] [blame] | 1301 | status = nfsd4_decode_stateid4(argp, &setattr->sa_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1302 | if (status) |
| 1303 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 1304 | return nfsd4_decode_fattr4(argp, setattr->sa_bmval, |
| 1305 | ARRAY_SIZE(setattr->sa_bmval), |
| 1306 | &setattr->sa_iattr, &setattr->sa_acl, |
| 1307 | &setattr->sa_label, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1310 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
| 1312 | { |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1313 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1315 | if (argp->minorversion >= 1) |
| 1316 | return nfserr_notsupp; |
| 1317 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1318 | status = nfsd4_decode_verifier4(argp, &setclientid->se_verf); |
| 1319 | if (status) |
| 1320 | return status; |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1321 | status = nfsd4_decode_opaque(argp, &setclientid->se_name); |
| 1322 | if (status) |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1323 | return status; |
| 1324 | 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] | 1325 | return nfserr_bad_xdr; |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1326 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_netid_len) < 0) |
| 1327 | return nfserr_bad_xdr; |
| 1328 | p = xdr_inline_decode(argp->xdr, setclientid->se_callback_netid_len); |
| 1329 | if (!p) |
| 1330 | return nfserr_bad_xdr; |
| 1331 | setclientid->se_callback_netid_val = svcxdr_tmpalloc(argp, |
| 1332 | setclientid->se_callback_netid_len); |
| 1333 | if (!setclientid->se_callback_netid_val) |
| 1334 | return nfserr_jukebox; |
| 1335 | memcpy(setclientid->se_callback_netid_val, p, |
| 1336 | setclientid->se_callback_netid_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1338 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_addr_len) < 0) |
| 1339 | return nfserr_bad_xdr; |
| 1340 | p = xdr_inline_decode(argp->xdr, setclientid->se_callback_addr_len); |
| 1341 | if (!p) |
| 1342 | return nfserr_bad_xdr; |
| 1343 | setclientid->se_callback_addr_val = svcxdr_tmpalloc(argp, |
| 1344 | setclientid->se_callback_addr_len); |
| 1345 | if (!setclientid->se_callback_addr_val) |
| 1346 | return nfserr_jukebox; |
| 1347 | memcpy(setclientid->se_callback_addr_val, p, |
| 1348 | setclientid->se_callback_addr_len); |
| 1349 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_ident) < 0) |
| 1350 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1352 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1355 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
| 1357 | { |
Chuck Lever | d1ca551 | 2020-11-04 15:12:33 -0500 | [diff] [blame^] | 1358 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1360 | if (argp->minorversion >= 1) |
| 1361 | return nfserr_notsupp; |
| 1362 | |
Chuck Lever | d1ca551 | 2020-11-04 15:12:33 -0500 | [diff] [blame^] | 1363 | status = nfsd4_decode_clientid4(argp, &scd_c->sc_clientid); |
| 1364 | if (status) |
| 1365 | return status; |
| 1366 | return nfsd4_decode_verifier4(argp, &scd_c->sc_confirm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | /* Also used for NVERIFY */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1370 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
| 1372 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | DECODE_HEAD; |
| 1374 | |
| 1375 | if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval))) |
| 1376 | goto out; |
| 1377 | |
| 1378 | /* For convenience's sake, we compare raw xdr'd attributes in |
J. Bruce Fields | e5f9570 | 2012-11-30 17:24:18 -0500 | [diff] [blame] | 1379 | * nfsd4_proc_verify */ |
| 1380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1382 | verify->ve_attrlen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | READ_BUF(verify->ve_attrlen); |
| 1384 | SAVEMEM(verify->ve_attrval, verify->ve_attrlen); |
| 1385 | |
| 1386 | DECODE_TAIL; |
| 1387 | } |
| 1388 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1389 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
| 1391 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | DECODE_HEAD; |
| 1393 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1394 | status = nfsd4_decode_stateid(argp, &write->wr_stateid); |
| 1395 | if (status) |
| 1396 | return status; |
| 1397 | READ_BUF(16); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 1398 | p = xdr_decode_hyper(p, &write->wr_offset); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1399 | write->wr_stable_how = be32_to_cpup(p++); |
Kinglong Mee | 54bbb7d | 2016-12-31 20:59:53 +0800 | [diff] [blame] | 1400 | if (write->wr_stable_how > NFS_FILE_SYNC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | goto xdr_error; |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1402 | write->wr_buflen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1404 | if (!xdr_stream_subsegment(argp->xdr, &write->wr_payload, write->wr_buflen)) |
| 1405 | goto xdr_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
| 1407 | DECODE_TAIL; |
| 1408 | } |
| 1409 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1410 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
| 1412 | { |
| 1413 | DECODE_HEAD; |
| 1414 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1415 | if (argp->minorversion >= 1) |
| 1416 | return nfserr_notsupp; |
| 1417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | READ_BUF(12); |
| 1419 | COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1420 | rlockowner->rl_owner.len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | READ_BUF(rlockowner->rl_owner.len); |
| 1422 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); |
| 1423 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 1424 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) |
| 1425 | return nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | DECODE_TAIL; |
| 1427 | } |
| 1428 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1429 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1430 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1431 | struct nfsd4_exchange_id *exid) |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1432 | { |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1433 | int dummy, tmp; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1434 | DECODE_HEAD; |
| 1435 | |
| 1436 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1437 | COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE); |
| 1438 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1439 | status = nfsd4_decode_opaque(argp, &exid->clname); |
| 1440 | if (status) |
| 1441 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1442 | |
| 1443 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1444 | exid->flags = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1445 | |
| 1446 | /* Ignore state_protect4_a */ |
| 1447 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1448 | exid->spa_how = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1449 | switch (exid->spa_how) { |
| 1450 | case SP4_NONE: |
| 1451 | break; |
| 1452 | case SP4_MACH_CRED: |
| 1453 | /* spo_must_enforce */ |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1454 | status = nfsd4_decode_bitmap(argp, |
| 1455 | exid->spo_must_enforce); |
| 1456 | if (status) |
| 1457 | goto out; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1458 | /* spo_must_allow */ |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1459 | status = nfsd4_decode_bitmap(argp, exid->spo_must_allow); |
| 1460 | if (status) |
| 1461 | goto out; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1462 | break; |
| 1463 | case SP4_SSV: |
| 1464 | /* ssp_ops */ |
| 1465 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1466 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1467 | READ_BUF(dummy * 4); |
| 1468 | p += dummy; |
| 1469 | |
| 1470 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1471 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1472 | READ_BUF(dummy * 4); |
| 1473 | p += dummy; |
| 1474 | |
| 1475 | /* ssp_hash_algs<> */ |
| 1476 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1477 | tmp = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1478 | while (tmp--) { |
| 1479 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1480 | dummy = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1481 | READ_BUF(dummy); |
| 1482 | p += XDR_QUADLEN(dummy); |
| 1483 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1484 | |
| 1485 | /* ssp_encr_algs<> */ |
| 1486 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1487 | tmp = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1488 | while (tmp--) { |
| 1489 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1490 | dummy = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1491 | READ_BUF(dummy); |
| 1492 | p += XDR_QUADLEN(dummy); |
| 1493 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1494 | |
nixiaoming | 5ed96bc | 2018-07-23 09:57:11 +0800 | [diff] [blame] | 1495 | /* ignore ssp_window and ssp_num_gss_handles: */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1496 | READ_BUF(8); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1497 | break; |
| 1498 | default: |
| 1499 | goto xdr_error; |
| 1500 | } |
| 1501 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1502 | READ_BUF(4); /* nfs_impl_id4 array length */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1503 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1504 | |
| 1505 | if (dummy > 1) |
| 1506 | goto xdr_error; |
| 1507 | |
| 1508 | if (dummy == 1) { |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1509 | status = nfsd4_decode_opaque(argp, &exid->nii_domain); |
| 1510 | if (status) |
| 1511 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1512 | |
| 1513 | /* nii_name */ |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1514 | status = nfsd4_decode_opaque(argp, &exid->nii_name); |
| 1515 | if (status) |
| 1516 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1517 | |
| 1518 | /* nii_date */ |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1519 | status = nfsd4_decode_time(argp, &exid->nii_time); |
| 1520 | if (status) |
| 1521 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1522 | } |
| 1523 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | static __be32 |
| 1527 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, |
| 1528 | struct nfsd4_create_session *sess) |
| 1529 | { |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1530 | DECODE_HEAD; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1531 | |
| 1532 | READ_BUF(16); |
| 1533 | COPYMEM(&sess->clientid, 8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1534 | sess->seqid = be32_to_cpup(p++); |
| 1535 | sess->flags = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1536 | |
| 1537 | /* Fore channel attrs */ |
| 1538 | READ_BUF(28); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 1539 | p++; /* headerpadsz is always 0 */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1540 | sess->fore_channel.maxreq_sz = be32_to_cpup(p++); |
| 1541 | sess->fore_channel.maxresp_sz = be32_to_cpup(p++); |
| 1542 | sess->fore_channel.maxresp_cached = be32_to_cpup(p++); |
| 1543 | sess->fore_channel.maxops = be32_to_cpup(p++); |
| 1544 | sess->fore_channel.maxreqs = be32_to_cpup(p++); |
| 1545 | sess->fore_channel.nr_rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1546 | if (sess->fore_channel.nr_rdma_attrs == 1) { |
| 1547 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1548 | sess->fore_channel.rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1549 | } else if (sess->fore_channel.nr_rdma_attrs > 1) { |
| 1550 | dprintk("Too many fore channel attr bitmaps!\n"); |
| 1551 | goto xdr_error; |
| 1552 | } |
| 1553 | |
| 1554 | /* Back channel attrs */ |
| 1555 | READ_BUF(28); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 1556 | p++; /* headerpadsz is always 0 */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1557 | sess->back_channel.maxreq_sz = be32_to_cpup(p++); |
| 1558 | sess->back_channel.maxresp_sz = be32_to_cpup(p++); |
| 1559 | sess->back_channel.maxresp_cached = be32_to_cpup(p++); |
| 1560 | sess->back_channel.maxops = be32_to_cpup(p++); |
| 1561 | sess->back_channel.maxreqs = be32_to_cpup(p++); |
| 1562 | sess->back_channel.nr_rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1563 | if (sess->back_channel.nr_rdma_attrs == 1) { |
| 1564 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1565 | sess->back_channel.rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1566 | } else if (sess->back_channel.nr_rdma_attrs > 1) { |
| 1567 | dprintk("Too many back channel attr bitmaps!\n"); |
| 1568 | goto xdr_error; |
| 1569 | } |
| 1570 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1571 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1572 | sess->callback_prog = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1573 | nfsd4_decode_cb_sec(argp, &sess->cb_sec); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1574 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | static __be32 |
| 1578 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, |
| 1579 | struct nfsd4_destroy_session *destroy_session) |
| 1580 | { |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1581 | DECODE_HEAD; |
| 1582 | READ_BUF(NFS4_MAX_SESSIONID_LEN); |
| 1583 | COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 1584 | |
| 1585 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | static __be32 |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1589 | nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, |
| 1590 | struct nfsd4_free_stateid *free_stateid) |
| 1591 | { |
| 1592 | DECODE_HEAD; |
| 1593 | |
| 1594 | READ_BUF(sizeof(stateid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1595 | free_stateid->fr_stateid.si_generation = be32_to_cpup(p++); |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1596 | COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t)); |
| 1597 | |
| 1598 | DECODE_TAIL; |
| 1599 | } |
| 1600 | |
| 1601 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1602 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, |
| 1603 | struct nfsd4_sequence *seq) |
| 1604 | { |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1605 | DECODE_HEAD; |
| 1606 | |
| 1607 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); |
| 1608 | COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1609 | seq->seqid = be32_to_cpup(p++); |
| 1610 | seq->slotid = be32_to_cpup(p++); |
| 1611 | seq->maxslots = be32_to_cpup(p++); |
| 1612 | seq->cachethis = be32_to_cpup(p++); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1613 | |
| 1614 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1615 | } |
| 1616 | |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1617 | static __be32 |
| 1618 | nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid) |
| 1619 | { |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1620 | int i; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1621 | __be32 *p, status; |
| 1622 | struct nfsd4_test_stateid_id *stateid; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1623 | |
| 1624 | READ_BUF(4); |
| 1625 | test_stateid->ts_num_ids = ntohl(*p++); |
| 1626 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1627 | INIT_LIST_HEAD(&test_stateid->ts_stateid_list); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1628 | |
| 1629 | for (i = 0; i < test_stateid->ts_num_ids; i++) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 1630 | stateid = svcxdr_tmpalloc(argp, sizeof(*stateid)); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1631 | if (!stateid) { |
Al Viro | afcf679 | 2012-04-13 00:15:37 -0400 | [diff] [blame] | 1632 | status = nfserrno(-ENOMEM); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1633 | goto out; |
| 1634 | } |
| 1635 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1636 | INIT_LIST_HEAD(&stateid->ts_id_list); |
| 1637 | list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list); |
| 1638 | |
| 1639 | status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1640 | if (status) |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1641 | goto out; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | status = 0; |
| 1645 | out: |
| 1646 | return status; |
| 1647 | xdr_error: |
| 1648 | dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__); |
| 1649 | status = nfserr_bad_xdr; |
| 1650 | goto out; |
| 1651 | } |
| 1652 | |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 1653 | static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc) |
| 1654 | { |
| 1655 | DECODE_HEAD; |
| 1656 | |
| 1657 | READ_BUF(8); |
| 1658 | COPYMEM(&dc->clientid, 8); |
| 1659 | |
| 1660 | DECODE_TAIL; |
| 1661 | } |
| 1662 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1663 | static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc) |
| 1664 | { |
| 1665 | DECODE_HEAD; |
| 1666 | |
| 1667 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1668 | rc->rca_one_fs = be32_to_cpup(p++); |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1669 | |
| 1670 | DECODE_TAIL; |
| 1671 | } |
| 1672 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1673 | #ifdef CONFIG_NFSD_PNFS |
| 1674 | static __be32 |
| 1675 | nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp, |
| 1676 | struct nfsd4_getdeviceinfo *gdev) |
| 1677 | { |
| 1678 | DECODE_HEAD; |
| 1679 | u32 num, i; |
| 1680 | |
| 1681 | READ_BUF(sizeof(struct nfsd4_deviceid) + 3 * 4); |
| 1682 | COPYMEM(&gdev->gd_devid, sizeof(struct nfsd4_deviceid)); |
| 1683 | gdev->gd_layout_type = be32_to_cpup(p++); |
| 1684 | gdev->gd_maxcount = be32_to_cpup(p++); |
| 1685 | num = be32_to_cpup(p++); |
| 1686 | if (num) { |
Scott Mayhew | 3171822f | 2018-06-08 16:31:46 -0400 | [diff] [blame] | 1687 | if (num > 1000) |
| 1688 | goto xdr_error; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1689 | READ_BUF(4 * num); |
| 1690 | gdev->gd_notify_types = be32_to_cpup(p++); |
| 1691 | for (i = 1; i < num; i++) { |
| 1692 | if (be32_to_cpup(p++)) { |
| 1693 | status = nfserr_inval; |
| 1694 | goto out; |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | DECODE_TAIL; |
| 1699 | } |
| 1700 | |
| 1701 | static __be32 |
| 1702 | nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp, |
| 1703 | struct nfsd4_layoutget *lgp) |
| 1704 | { |
| 1705 | DECODE_HEAD; |
| 1706 | |
| 1707 | READ_BUF(36); |
| 1708 | lgp->lg_signal = be32_to_cpup(p++); |
| 1709 | lgp->lg_layout_type = be32_to_cpup(p++); |
| 1710 | lgp->lg_seg.iomode = be32_to_cpup(p++); |
| 1711 | p = xdr_decode_hyper(p, &lgp->lg_seg.offset); |
| 1712 | p = xdr_decode_hyper(p, &lgp->lg_seg.length); |
| 1713 | p = xdr_decode_hyper(p, &lgp->lg_minlength); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1714 | |
| 1715 | status = nfsd4_decode_stateid(argp, &lgp->lg_sid); |
| 1716 | if (status) |
| 1717 | return status; |
| 1718 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1719 | READ_BUF(4); |
| 1720 | lgp->lg_maxcount = be32_to_cpup(p++); |
| 1721 | |
| 1722 | DECODE_TAIL; |
| 1723 | } |
| 1724 | |
| 1725 | static __be32 |
| 1726 | nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, |
| 1727 | struct nfsd4_layoutcommit *lcp) |
| 1728 | { |
| 1729 | DECODE_HEAD; |
| 1730 | u32 timechange; |
| 1731 | |
| 1732 | READ_BUF(20); |
| 1733 | p = xdr_decode_hyper(p, &lcp->lc_seg.offset); |
| 1734 | p = xdr_decode_hyper(p, &lcp->lc_seg.length); |
| 1735 | lcp->lc_reclaim = be32_to_cpup(p++); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1736 | |
| 1737 | status = nfsd4_decode_stateid(argp, &lcp->lc_sid); |
| 1738 | if (status) |
| 1739 | return status; |
| 1740 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1741 | READ_BUF(4); |
| 1742 | lcp->lc_newoffset = be32_to_cpup(p++); |
| 1743 | if (lcp->lc_newoffset) { |
| 1744 | READ_BUF(8); |
| 1745 | p = xdr_decode_hyper(p, &lcp->lc_last_wr); |
| 1746 | } else |
| 1747 | lcp->lc_last_wr = 0; |
| 1748 | READ_BUF(4); |
| 1749 | timechange = be32_to_cpup(p++); |
| 1750 | if (timechange) { |
| 1751 | status = nfsd4_decode_time(argp, &lcp->lc_mtime); |
| 1752 | if (status) |
| 1753 | return status; |
| 1754 | } else { |
| 1755 | lcp->lc_mtime.tv_nsec = UTIME_NOW; |
| 1756 | } |
| 1757 | READ_BUF(8); |
| 1758 | lcp->lc_layout_type = be32_to_cpup(p++); |
| 1759 | |
| 1760 | /* |
| 1761 | * Save the layout update in XDR format and let the layout driver deal |
| 1762 | * with it later. |
| 1763 | */ |
| 1764 | lcp->lc_up_len = be32_to_cpup(p++); |
| 1765 | if (lcp->lc_up_len > 0) { |
| 1766 | READ_BUF(lcp->lc_up_len); |
| 1767 | READMEM(lcp->lc_up_layout, lcp->lc_up_len); |
| 1768 | } |
| 1769 | |
| 1770 | DECODE_TAIL; |
| 1771 | } |
| 1772 | |
| 1773 | static __be32 |
| 1774 | nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp, |
| 1775 | struct nfsd4_layoutreturn *lrp) |
| 1776 | { |
| 1777 | DECODE_HEAD; |
| 1778 | |
| 1779 | READ_BUF(16); |
| 1780 | lrp->lr_reclaim = be32_to_cpup(p++); |
| 1781 | lrp->lr_layout_type = be32_to_cpup(p++); |
| 1782 | lrp->lr_seg.iomode = be32_to_cpup(p++); |
| 1783 | lrp->lr_return_type = be32_to_cpup(p++); |
| 1784 | if (lrp->lr_return_type == RETURN_FILE) { |
| 1785 | READ_BUF(16); |
| 1786 | p = xdr_decode_hyper(p, &lrp->lr_seg.offset); |
| 1787 | p = xdr_decode_hyper(p, &lrp->lr_seg.length); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1788 | |
| 1789 | status = nfsd4_decode_stateid(argp, &lrp->lr_sid); |
| 1790 | if (status) |
| 1791 | return status; |
| 1792 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1793 | READ_BUF(4); |
| 1794 | lrp->lrf_body_len = be32_to_cpup(p++); |
| 1795 | if (lrp->lrf_body_len > 0) { |
| 1796 | READ_BUF(lrp->lrf_body_len); |
| 1797 | READMEM(lrp->lrf_body, lrp->lrf_body_len); |
| 1798 | } |
| 1799 | } else { |
| 1800 | lrp->lr_seg.offset = 0; |
| 1801 | lrp->lr_seg.length = NFS4_MAX_UINT64; |
| 1802 | } |
| 1803 | |
| 1804 | DECODE_TAIL; |
| 1805 | } |
| 1806 | #endif /* CONFIG_NFSD_PNFS */ |
| 1807 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1808 | static __be32 |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1809 | nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, |
| 1810 | struct nfsd4_fallocate *fallocate) |
| 1811 | { |
| 1812 | DECODE_HEAD; |
| 1813 | |
| 1814 | status = nfsd4_decode_stateid(argp, &fallocate->falloc_stateid); |
| 1815 | if (status) |
| 1816 | return status; |
| 1817 | |
| 1818 | READ_BUF(16); |
| 1819 | p = xdr_decode_hyper(p, &fallocate->falloc_offset); |
| 1820 | xdr_decode_hyper(p, &fallocate->falloc_length); |
| 1821 | |
| 1822 | DECODE_TAIL; |
| 1823 | } |
| 1824 | |
| 1825 | static __be32 |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1826 | nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone) |
| 1827 | { |
| 1828 | DECODE_HEAD; |
| 1829 | |
| 1830 | status = nfsd4_decode_stateid(argp, &clone->cl_src_stateid); |
| 1831 | if (status) |
| 1832 | return status; |
| 1833 | status = nfsd4_decode_stateid(argp, &clone->cl_dst_stateid); |
| 1834 | if (status) |
| 1835 | return status; |
| 1836 | |
| 1837 | READ_BUF(8 + 8 + 8); |
| 1838 | p = xdr_decode_hyper(p, &clone->cl_src_pos); |
| 1839 | p = xdr_decode_hyper(p, &clone->cl_dst_pos); |
| 1840 | p = xdr_decode_hyper(p, &clone->cl_count); |
| 1841 | DECODE_TAIL; |
| 1842 | } |
| 1843 | |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1844 | static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, |
| 1845 | struct nl4_server *ns) |
| 1846 | { |
| 1847 | DECODE_HEAD; |
| 1848 | struct nfs42_netaddr *naddr; |
| 1849 | |
| 1850 | READ_BUF(4); |
| 1851 | ns->nl4_type = be32_to_cpup(p++); |
| 1852 | |
| 1853 | /* currently support for 1 inter-server source server */ |
| 1854 | switch (ns->nl4_type) { |
| 1855 | case NL4_NETADDR: |
| 1856 | naddr = &ns->u.nl4_addr; |
| 1857 | |
| 1858 | READ_BUF(4); |
| 1859 | naddr->netid_len = be32_to_cpup(p++); |
| 1860 | if (naddr->netid_len > RPCBIND_MAXNETIDLEN) |
| 1861 | goto xdr_error; |
| 1862 | |
| 1863 | READ_BUF(naddr->netid_len + 4); /* 4 for uaddr len */ |
| 1864 | COPYMEM(naddr->netid, naddr->netid_len); |
| 1865 | |
| 1866 | naddr->addr_len = be32_to_cpup(p++); |
| 1867 | if (naddr->addr_len > RPCBIND_MAXUADDRLEN) |
| 1868 | goto xdr_error; |
| 1869 | |
| 1870 | READ_BUF(naddr->addr_len); |
| 1871 | COPYMEM(naddr->addr, naddr->addr_len); |
| 1872 | break; |
| 1873 | default: |
| 1874 | goto xdr_error; |
| 1875 | } |
| 1876 | DECODE_TAIL; |
| 1877 | } |
| 1878 | |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1879 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1880 | nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) |
| 1881 | { |
| 1882 | DECODE_HEAD; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1883 | struct nl4_server *ns_dummy; |
| 1884 | int i, count; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1885 | |
| 1886 | status = nfsd4_decode_stateid(argp, ©->cp_src_stateid); |
| 1887 | if (status) |
| 1888 | return status; |
| 1889 | status = nfsd4_decode_stateid(argp, ©->cp_dst_stateid); |
| 1890 | if (status) |
| 1891 | return status; |
| 1892 | |
| 1893 | READ_BUF(8 + 8 + 8 + 4 + 4 + 4); |
| 1894 | p = xdr_decode_hyper(p, ©->cp_src_pos); |
| 1895 | p = xdr_decode_hyper(p, ©->cp_dst_pos); |
| 1896 | p = xdr_decode_hyper(p, ©->cp_count); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 1897 | p++; /* ca_consecutive: we always do consecutive copies */ |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1898 | copy->cp_synchronous = be32_to_cpup(p++); |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1899 | |
| 1900 | count = be32_to_cpup(p++); |
| 1901 | |
| 1902 | copy->cp_intra = false; |
| 1903 | if (count == 0) { /* intra-server copy */ |
| 1904 | copy->cp_intra = true; |
| 1905 | goto intra; |
| 1906 | } |
| 1907 | |
| 1908 | /* decode all the supplied server addresses but use first */ |
| 1909 | status = nfsd4_decode_nl4_server(argp, ©->cp_src); |
| 1910 | if (status) |
| 1911 | return status; |
| 1912 | |
| 1913 | ns_dummy = kmalloc(sizeof(struct nl4_server), GFP_KERNEL); |
| 1914 | if (ns_dummy == NULL) |
| 1915 | return nfserrno(-ENOMEM); |
| 1916 | for (i = 0; i < count - 1; i++) { |
| 1917 | status = nfsd4_decode_nl4_server(argp, ns_dummy); |
| 1918 | if (status) { |
| 1919 | kfree(ns_dummy); |
| 1920 | return status; |
| 1921 | } |
| 1922 | } |
| 1923 | kfree(ns_dummy); |
| 1924 | intra: |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1925 | |
| 1926 | DECODE_TAIL; |
| 1927 | } |
| 1928 | |
| 1929 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 1930 | nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp, |
| 1931 | struct nfsd4_offload_status *os) |
| 1932 | { |
| 1933 | return nfsd4_decode_stateid(argp, &os->stateid); |
| 1934 | } |
| 1935 | |
| 1936 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1937 | nfsd4_decode_copy_notify(struct nfsd4_compoundargs *argp, |
| 1938 | struct nfsd4_copy_notify *cn) |
| 1939 | { |
Chuck Lever | 5aff7d0 | 2020-09-11 14:47:59 -0400 | [diff] [blame] | 1940 | __be32 status; |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1941 | |
| 1942 | status = nfsd4_decode_stateid(argp, &cn->cpn_src_stateid); |
| 1943 | if (status) |
| 1944 | return status; |
| 1945 | return nfsd4_decode_nl4_server(argp, &cn->cpn_dst); |
| 1946 | } |
| 1947 | |
| 1948 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1949 | nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek) |
| 1950 | { |
| 1951 | DECODE_HEAD; |
| 1952 | |
| 1953 | status = nfsd4_decode_stateid(argp, &seek->seek_stateid); |
| 1954 | if (status) |
| 1955 | return status; |
| 1956 | |
| 1957 | READ_BUF(8 + 4); |
| 1958 | p = xdr_decode_hyper(p, &seek->seek_offset); |
| 1959 | seek->seek_whence = be32_to_cpup(p); |
| 1960 | |
| 1961 | DECODE_TAIL; |
| 1962 | } |
| 1963 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1964 | /* |
| 1965 | * XDR data that is more than PAGE_SIZE in size is normally part of a |
| 1966 | * read or write. However, the size of extended attributes is limited |
| 1967 | * by the maximum request size, and then further limited by the underlying |
| 1968 | * filesystem limits. This can exceed PAGE_SIZE (currently, XATTR_SIZE_MAX |
| 1969 | * is 64k). Since there is no kvec- or page-based interface to xattrs, |
| 1970 | * and we're not dealing with contiguous pages, we need to do some copying. |
| 1971 | */ |
| 1972 | |
| 1973 | /* |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1974 | * Decode data into buffer. |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1975 | */ |
| 1976 | static __be32 |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1977 | nfsd4_vbuf_from_vector(struct nfsd4_compoundargs *argp, struct xdr_buf *xdr, |
| 1978 | char **bufp, u32 buflen) |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1979 | { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1980 | struct page **pages = xdr->pages; |
| 1981 | struct kvec *head = xdr->head; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1982 | char *tmp, *dp; |
| 1983 | u32 len; |
| 1984 | |
| 1985 | if (buflen <= head->iov_len) { |
| 1986 | /* |
| 1987 | * We're in luck, the head has enough space. Just return |
| 1988 | * the head, no need for copying. |
| 1989 | */ |
| 1990 | *bufp = head->iov_base; |
| 1991 | return 0; |
| 1992 | } |
| 1993 | |
| 1994 | tmp = svcxdr_tmpalloc(argp, buflen); |
| 1995 | if (tmp == NULL) |
| 1996 | return nfserr_jukebox; |
| 1997 | |
| 1998 | dp = tmp; |
| 1999 | memcpy(dp, head->iov_base, head->iov_len); |
| 2000 | buflen -= head->iov_len; |
| 2001 | dp += head->iov_len; |
| 2002 | |
| 2003 | while (buflen > 0) { |
| 2004 | len = min_t(u32, buflen, PAGE_SIZE); |
| 2005 | memcpy(dp, page_address(*pages), len); |
| 2006 | |
| 2007 | buflen -= len; |
| 2008 | dp += len; |
| 2009 | pages++; |
| 2010 | } |
| 2011 | |
| 2012 | *bufp = tmp; |
| 2013 | return 0; |
| 2014 | } |
| 2015 | |
| 2016 | /* |
| 2017 | * Get a user extended attribute name from the XDR buffer. |
| 2018 | * It will not have the "user." prefix, so prepend it. |
| 2019 | * Lastly, check for nul characters in the name. |
| 2020 | */ |
| 2021 | static __be32 |
| 2022 | nfsd4_decode_xattr_name(struct nfsd4_compoundargs *argp, char **namep) |
| 2023 | { |
| 2024 | DECODE_HEAD; |
| 2025 | char *name, *sp, *dp; |
| 2026 | u32 namelen, cnt; |
| 2027 | |
| 2028 | READ_BUF(4); |
| 2029 | namelen = be32_to_cpup(p++); |
| 2030 | |
| 2031 | if (namelen > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) |
| 2032 | return nfserr_nametoolong; |
| 2033 | |
| 2034 | if (namelen == 0) |
| 2035 | goto xdr_error; |
| 2036 | |
| 2037 | READ_BUF(namelen); |
| 2038 | |
| 2039 | name = svcxdr_tmpalloc(argp, namelen + XATTR_USER_PREFIX_LEN + 1); |
| 2040 | if (!name) |
| 2041 | return nfserr_jukebox; |
| 2042 | |
| 2043 | memcpy(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); |
| 2044 | |
| 2045 | /* |
| 2046 | * Copy the extended attribute name over while checking for 0 |
| 2047 | * characters. |
| 2048 | */ |
| 2049 | sp = (char *)p; |
| 2050 | dp = name + XATTR_USER_PREFIX_LEN; |
| 2051 | cnt = namelen; |
| 2052 | |
| 2053 | while (cnt-- > 0) { |
| 2054 | if (*sp == '\0') |
| 2055 | goto xdr_error; |
| 2056 | *dp++ = *sp++; |
| 2057 | } |
| 2058 | *dp = '\0'; |
| 2059 | |
| 2060 | *namep = name; |
| 2061 | |
| 2062 | DECODE_TAIL; |
| 2063 | } |
| 2064 | |
| 2065 | /* |
| 2066 | * A GETXATTR op request comes without a length specifier. We just set the |
| 2067 | * maximum length for the reply based on XATTR_SIZE_MAX and the maximum |
| 2068 | * channel reply size. nfsd_getxattr will probe the length of the xattr, |
| 2069 | * check it against getxa_len, and allocate + return the value. |
| 2070 | */ |
| 2071 | static __be32 |
| 2072 | nfsd4_decode_getxattr(struct nfsd4_compoundargs *argp, |
| 2073 | struct nfsd4_getxattr *getxattr) |
| 2074 | { |
| 2075 | __be32 status; |
| 2076 | u32 maxcount; |
| 2077 | |
| 2078 | status = nfsd4_decode_xattr_name(argp, &getxattr->getxa_name); |
| 2079 | if (status) |
| 2080 | return status; |
| 2081 | |
| 2082 | maxcount = svc_max_payload(argp->rqstp); |
| 2083 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2084 | |
| 2085 | getxattr->getxa_len = maxcount; |
| 2086 | |
| 2087 | return status; |
| 2088 | } |
| 2089 | |
| 2090 | static __be32 |
| 2091 | nfsd4_decode_setxattr(struct nfsd4_compoundargs *argp, |
| 2092 | struct nfsd4_setxattr *setxattr) |
| 2093 | { |
| 2094 | DECODE_HEAD; |
| 2095 | u32 flags, maxcount, size; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2096 | |
| 2097 | READ_BUF(4); |
| 2098 | flags = be32_to_cpup(p++); |
| 2099 | |
| 2100 | if (flags > SETXATTR4_REPLACE) |
| 2101 | return nfserr_inval; |
| 2102 | setxattr->setxa_flags = flags; |
| 2103 | |
| 2104 | status = nfsd4_decode_xattr_name(argp, &setxattr->setxa_name); |
| 2105 | if (status) |
| 2106 | return status; |
| 2107 | |
| 2108 | maxcount = svc_max_payload(argp->rqstp); |
| 2109 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2110 | |
| 2111 | READ_BUF(4); |
| 2112 | size = be32_to_cpup(p++); |
| 2113 | if (size > maxcount) |
| 2114 | return nfserr_xattr2big; |
| 2115 | |
| 2116 | setxattr->setxa_len = size; |
| 2117 | if (size > 0) { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2118 | struct xdr_buf payload; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2119 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2120 | if (!xdr_stream_subsegment(argp->xdr, &payload, size)) |
| 2121 | goto xdr_error; |
| 2122 | status = nfsd4_vbuf_from_vector(argp, &payload, |
| 2123 | &setxattr->setxa_buf, size); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | DECODE_TAIL; |
| 2127 | } |
| 2128 | |
| 2129 | static __be32 |
| 2130 | nfsd4_decode_listxattrs(struct nfsd4_compoundargs *argp, |
| 2131 | struct nfsd4_listxattrs *listxattrs) |
| 2132 | { |
| 2133 | DECODE_HEAD; |
| 2134 | u32 maxcount; |
| 2135 | |
| 2136 | READ_BUF(12); |
| 2137 | p = xdr_decode_hyper(p, &listxattrs->lsxa_cookie); |
| 2138 | |
| 2139 | /* |
| 2140 | * If the cookie is too large to have even one user.x attribute |
| 2141 | * plus trailing '\0' left in a maximum size buffer, it's invalid. |
| 2142 | */ |
| 2143 | if (listxattrs->lsxa_cookie >= |
| 2144 | (XATTR_LIST_MAX / (XATTR_USER_PREFIX_LEN + 2))) |
| 2145 | return nfserr_badcookie; |
| 2146 | |
| 2147 | maxcount = be32_to_cpup(p++); |
| 2148 | if (maxcount < 8) |
| 2149 | /* Always need at least 2 words (length and one character) */ |
| 2150 | return nfserr_inval; |
| 2151 | |
| 2152 | maxcount = min(maxcount, svc_max_payload(argp->rqstp)); |
| 2153 | listxattrs->lsxa_maxcount = maxcount; |
| 2154 | |
| 2155 | DECODE_TAIL; |
| 2156 | } |
| 2157 | |
| 2158 | static __be32 |
| 2159 | nfsd4_decode_removexattr(struct nfsd4_compoundargs *argp, |
| 2160 | struct nfsd4_removexattr *removexattr) |
| 2161 | { |
| 2162 | return nfsd4_decode_xattr_name(argp, &removexattr->rmxa_name); |
| 2163 | } |
| 2164 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2165 | static __be32 |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2166 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) |
| 2167 | { |
| 2168 | return nfs_ok; |
| 2169 | } |
| 2170 | |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2171 | static __be32 |
| 2172 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
| 2173 | { |
Benny Halevy | 1e685ec | 2009-03-04 23:06:06 +0200 | [diff] [blame] | 2174 | return nfserr_notsupp; |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2175 | } |
| 2176 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2177 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
| 2178 | |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 2179 | static const nfsd4_dec nfsd4_dec_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2180 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
| 2181 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, |
| 2182 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, |
| 2183 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, |
| 2184 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2185 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, |
| 2186 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, |
| 2187 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2188 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, |
| 2189 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, |
| 2190 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, |
| 2191 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, |
| 2192 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, |
| 2193 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, |
| 2194 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2195 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, |
| 2196 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2197 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
| 2198 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
| 2199 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2200 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2201 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2202 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
| 2203 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
| 2204 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, |
| 2205 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, |
| 2206 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, |
| 2207 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, |
| 2208 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2209 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2210 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, |
| 2211 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, |
| 2212 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, |
| 2213 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, |
| 2214 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2215 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, |
| 2216 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2217 | |
| 2218 | /* new operations for NFSv4.1 */ |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 2219 | [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2220 | [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] | 2221 | [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, |
| 2222 | [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, |
| 2223 | [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 2224 | [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2225 | [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2226 | #ifdef CONFIG_NFSD_PNFS |
| 2227 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_getdeviceinfo, |
| 2228 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2229 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_layoutcommit, |
| 2230 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_layoutget, |
| 2231 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_layoutreturn, |
| 2232 | #else |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2233 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2234 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2235 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2236 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2237 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2238 | #endif |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 2239 | [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2240 | [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence, |
| 2241 | [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 2242 | [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2243 | [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 2244 | [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 2245 | [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2246 | |
| 2247 | /* new operations for NFSv4.2 */ |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 2248 | [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2249 | [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2250 | [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_copy_notify, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 2251 | [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2252 | [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2253 | [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2254 | [OP_LAYOUTSTATS] = (nfsd4_dec)nfsd4_decode_notsupp, |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 2255 | [OP_OFFLOAD_CANCEL] = (nfsd4_dec)nfsd4_decode_offload_status, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 2256 | [OP_OFFLOAD_STATUS] = (nfsd4_dec)nfsd4_decode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2257 | [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_read, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2258 | [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2259 | [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 2260 | [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2261 | /* RFC 8276 extended atributes operations */ |
| 2262 | [OP_GETXATTR] = (nfsd4_dec)nfsd4_decode_getxattr, |
| 2263 | [OP_SETXATTR] = (nfsd4_dec)nfsd4_decode_setxattr, |
| 2264 | [OP_LISTXATTRS] = (nfsd4_dec)nfsd4_decode_listxattrs, |
| 2265 | [OP_REMOVEXATTR] = (nfsd4_dec)nfsd4_decode_removexattr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2266 | }; |
| 2267 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2268 | static inline bool |
| 2269 | nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op) |
| 2270 | { |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2271 | if (op->opnum < FIRST_NFS4_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2272 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2273 | else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2274 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2275 | else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP) |
| 2276 | return false; |
| 2277 | else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2278 | return false; |
| 2279 | return true; |
| 2280 | } |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 2281 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2282 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
| 2284 | { |
| 2285 | DECODE_HEAD; |
| 2286 | struct nfsd4_op *op; |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2287 | bool cachethis = false; |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2288 | int auth_slack= argp->rqstp->rq_auth_slack; |
| 2289 | int max_reply = auth_slack + 8; /* opcnt, status */ |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2290 | int readcount = 0; |
| 2291 | int readbytes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | int i; |
| 2293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2295 | argp->taglen = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2296 | READ_BUF(argp->taglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | SAVEMEM(argp->tag, argp->taglen); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2298 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2299 | argp->minorversion = be32_to_cpup(p++); |
| 2300 | argp->opcnt = be32_to_cpup(p++); |
J. Bruce Fields | 4f0cefb | 2014-03-11 15:39:13 -0400 | [diff] [blame] | 2301 | max_reply += 4 + (XDR_QUADLEN(argp->taglen) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | |
| 2303 | if (argp->taglen > NFSD4_MAX_TAGLEN) |
| 2304 | goto xdr_error; |
J. Bruce Fields | 0078117 | 2017-11-15 12:30:27 -0500 | [diff] [blame] | 2305 | /* |
| 2306 | * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS |
| 2307 | * here, so we return success at the xdr level so that |
| 2308 | * nfsd4_proc can handle this is an NFS-level error. |
| 2309 | */ |
| 2310 | if (argp->opcnt > NFSD_MAX_OPS_PER_COMPOUND) |
| 2311 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 2313 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
J. Bruce Fields | 5d6031c | 2014-07-17 16:20:39 -0400 | [diff] [blame] | 2314 | argp->ops = kzalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | if (!argp->ops) { |
| 2316 | argp->ops = argp->iops; |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 2317 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | goto xdr_error; |
| 2319 | } |
| 2320 | } |
| 2321 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2322 | if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION) |
Benny Halevy | 30cff1f | 2008-07-02 11:13:18 +0300 | [diff] [blame] | 2323 | argp->opcnt = 0; |
| 2324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | for (i = 0; i < argp->opcnt; i++) { |
| 2326 | op = &argp->ops[i]; |
| 2327 | op->replay = NULL; |
| 2328 | |
J. Bruce Fields | 8a61b18 | 2012-11-16 22:28:38 -0500 | [diff] [blame] | 2329 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2330 | op->opnum = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2332 | if (nfsd4_opnum_in_range(argp, op)) { |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2333 | op->status = nfsd4_dec_ops[op->opnum](argp, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2334 | if (op->status != nfs_ok) |
| 2335 | trace_nfsd_compound_decode_err(argp->rqstp, |
| 2336 | argp->opcnt, i, |
| 2337 | op->opnum, |
| 2338 | op->status); |
| 2339 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | op->opnum = OP_ILLEGAL; |
| 2341 | op->status = nfserr_op_illegal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | } |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2343 | op->opdesc = OPDESC(op); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2344 | /* |
| 2345 | * We'll try to cache the result in the DRC if any one |
| 2346 | * op in the compound wants to be cached: |
| 2347 | */ |
| 2348 | cachethis |= nfsd4_cache_this_op(op); |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 2349 | |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2350 | if (op->opnum == OP_READ || op->opnum == OP_READ_PLUS) { |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2351 | readcount++; |
| 2352 | readbytes += nfsd4_max_reply(argp->rqstp, op); |
| 2353 | } else |
| 2354 | max_reply += nfsd4_max_reply(argp->rqstp, op); |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2355 | /* |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2356 | * OP_LOCK and OP_LOCKT may return a conflicting lock. |
| 2357 | * (Special case because it will just skip encoding this |
| 2358 | * if it runs out of xdr buffer space, and it is the only |
| 2359 | * operation that behaves this way.) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2360 | */ |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2361 | if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2362 | max_reply += NFS4_OPAQUE_LIMIT; |
J. Bruce Fields | e372ba6 | 2014-05-19 12:27:11 -0400 | [diff] [blame] | 2363 | |
| 2364 | if (op->status) { |
| 2365 | argp->opcnt = i+1; |
| 2366 | break; |
| 2367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | } |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2369 | /* Sessions make the DRC unnecessary: */ |
| 2370 | if (argp->minorversion) |
| 2371 | cachethis = false; |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2372 | svc_reserve(argp->rqstp, max_reply + readbytes); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2373 | argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2375 | if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack) |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 2376 | clear_bit(RQ_SPLICE_OK, &argp->rqstp->rq_flags); |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | DECODE_TAIL; |
| 2379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2381 | static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode, |
| 2382 | struct svc_export *exp) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2383 | { |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2384 | if (exp->ex_flags & NFSEXP_V4ROOT) { |
| 2385 | *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time)); |
| 2386 | *p++ = 0; |
| 2387 | } else if (IS_I_VERSION(inode)) { |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 2388 | p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode)); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2389 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2390 | *p++ = cpu_to_be32(stat->ctime.tv_sec); |
| 2391 | *p++ = cpu_to_be32(stat->ctime.tv_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2392 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2393 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2394 | } |
| 2395 | |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2396 | /* |
| 2397 | * ctime (in NFSv4, time_metadata) is not writeable, and the client |
| 2398 | * doesn't really care what resolution could theoretically be stored by |
| 2399 | * the filesystem. |
| 2400 | * |
| 2401 | * The client cares how close together changes can be while still |
| 2402 | * guaranteeing ctime changes. For most filesystems (which have |
| 2403 | * timestamps with nanosecond fields) that is limited by the resolution |
| 2404 | * of the time returned from current_time() (which I'm assuming to be |
| 2405 | * 1/HZ). |
| 2406 | */ |
| 2407 | static __be32 *encode_time_delta(__be32 *p, struct inode *inode) |
| 2408 | { |
Arnd Bergmann | e4598e3 | 2019-10-31 15:14:03 +0100 | [diff] [blame] | 2409 | struct timespec64 ts; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2410 | u32 ns; |
| 2411 | |
| 2412 | 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] | 2413 | ts = ns_to_timespec64(ns); |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2414 | |
| 2415 | p = xdr_encode_hyper(p, ts.tv_sec); |
| 2416 | *p++ = cpu_to_be32(ts.tv_nsec); |
| 2417 | |
| 2418 | return p; |
| 2419 | } |
| 2420 | |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2421 | static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2422 | { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2423 | *p++ = cpu_to_be32(c->atomic); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2424 | if (c->change_supported) { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2425 | p = xdr_encode_hyper(p, c->before_change); |
| 2426 | p = xdr_encode_hyper(p, c->after_change); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2427 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2428 | *p++ = cpu_to_be32(c->before_ctime_sec); |
| 2429 | *p++ = cpu_to_be32(c->before_ctime_nsec); |
| 2430 | *p++ = cpu_to_be32(c->after_ctime_sec); |
| 2431 | *p++ = cpu_to_be32(c->after_ctime_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2432 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2433 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2436 | /* Encode as an array of strings the string given with components |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2437 | * separated @sep, escaped with esc_enter and esc_exit. |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2438 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2439 | static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, |
| 2440 | char *components, char esc_enter, |
| 2441 | char esc_exit) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2442 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2443 | __be32 *p; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2444 | __be32 pathlen; |
| 2445 | int pathlen_offset; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2446 | int strlen, count=0; |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2447 | char *str, *end, *next; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2448 | |
| 2449 | dprintk("nfsd4_encode_components(%s)\n", components); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2450 | |
| 2451 | pathlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2452 | p = xdr_reserve_space(xdr, 4); |
| 2453 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2454 | return nfserr_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2455 | p++; /* We will fill this in with @count later */ |
| 2456 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2457 | end = str = components; |
| 2458 | while (*end) { |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2459 | bool found_esc = false; |
| 2460 | |
| 2461 | /* try to parse as esc_start, ..., esc_end, sep */ |
| 2462 | if (*str == esc_enter) { |
| 2463 | for (; *end && (*end != esc_exit); end++) |
| 2464 | /* find esc_exit or end of string */; |
| 2465 | next = end + 1; |
| 2466 | if (*end && (!*next || *next == sep)) { |
| 2467 | str++; |
| 2468 | found_esc = true; |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | if (!found_esc) |
| 2473 | for (; *end && (*end != sep); end++) |
| 2474 | /* find sep or end of string */; |
| 2475 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2476 | strlen = end - str; |
| 2477 | if (strlen) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2478 | p = xdr_reserve_space(xdr, strlen + 4); |
| 2479 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2480 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2481 | p = xdr_encode_opaque(p, str, strlen); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2482 | count++; |
| 2483 | } |
| 2484 | else |
| 2485 | end++; |
Benjamin Coddington | 5a64e56 | 2014-12-07 16:05:47 -0500 | [diff] [blame] | 2486 | if (found_esc) |
| 2487 | end = next; |
| 2488 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2489 | str = end; |
| 2490 | } |
Benjamin Coddington | bf7491f | 2014-12-07 16:05:48 -0500 | [diff] [blame] | 2491 | pathlen = htonl(count); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2492 | write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2493 | return 0; |
| 2494 | } |
| 2495 | |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2496 | /* Encode as an array of strings the string given with components |
| 2497 | * separated @sep. |
| 2498 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2499 | static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep, |
| 2500 | char *components) |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2501 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2502 | return nfsd4_encode_components_esc(xdr, sep, components, 0, 0); |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2503 | } |
| 2504 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2505 | /* |
| 2506 | * encode a location element of a fs_locations structure |
| 2507 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2508 | static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr, |
| 2509 | struct nfsd4_fs_location *location) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2510 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2511 | __be32 status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2512 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2513 | status = nfsd4_encode_components_esc(xdr, ':', location->hosts, |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2514 | '[', ']'); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2515 | if (status) |
| 2516 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2517 | status = nfsd4_encode_components(xdr, '/', location->path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2518 | if (status) |
| 2519 | return status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2520 | return 0; |
| 2521 | } |
| 2522 | |
| 2523 | /* |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2524 | * Encode a path in RFC3530 'pathname4' format |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2525 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2526 | static __be32 nfsd4_encode_path(struct xdr_stream *xdr, |
| 2527 | const struct path *root, |
| 2528 | const struct path *path) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2529 | { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2530 | struct path cur = *path; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2531 | __be32 *p; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2532 | struct dentry **components = NULL; |
| 2533 | unsigned int ncomponents = 0; |
| 2534 | __be32 err = nfserr_jukebox; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2535 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2536 | dprintk("nfsd4_encode_components("); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2537 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2538 | path_get(&cur); |
| 2539 | /* First walk the path up to the nfsd root, and store the |
| 2540 | * dentries/path components in an array. |
| 2541 | */ |
| 2542 | for (;;) { |
Kinglong Mee | b77a4b2 | 2015-03-15 23:13:32 +0800 | [diff] [blame] | 2543 | if (path_equal(&cur, root)) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2544 | break; |
| 2545 | if (cur.dentry == cur.mnt->mnt_root) { |
| 2546 | if (follow_up(&cur)) |
| 2547 | continue; |
| 2548 | goto out_free; |
| 2549 | } |
| 2550 | if ((ncomponents & 15) == 0) { |
| 2551 | struct dentry **new; |
| 2552 | new = krealloc(components, |
| 2553 | sizeof(*new) * (ncomponents + 16), |
| 2554 | GFP_KERNEL); |
| 2555 | if (!new) |
| 2556 | goto out_free; |
| 2557 | components = new; |
| 2558 | } |
| 2559 | components[ncomponents++] = cur.dentry; |
| 2560 | cur.dentry = dget_parent(cur.dentry); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2561 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2562 | err = nfserr_resource; |
| 2563 | p = xdr_reserve_space(xdr, 4); |
| 2564 | if (!p) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2565 | goto out_free; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2566 | *p++ = cpu_to_be32(ncomponents); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2567 | |
| 2568 | while (ncomponents) { |
| 2569 | struct dentry *dentry = components[ncomponents - 1]; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2570 | unsigned int len; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2571 | |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2572 | spin_lock(&dentry->d_lock); |
| 2573 | len = dentry->d_name.len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2574 | p = xdr_reserve_space(xdr, len + 4); |
| 2575 | if (!p) { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2576 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2577 | goto out_free; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2578 | } |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2579 | p = xdr_encode_opaque(p, dentry->d_name.name, len); |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 2580 | dprintk("/%pd", dentry); |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2581 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2582 | dput(dentry); |
| 2583 | ncomponents--; |
| 2584 | } |
| 2585 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2586 | err = 0; |
| 2587 | out_free: |
| 2588 | dprintk(")\n"); |
| 2589 | while (ncomponents) |
| 2590 | dput(components[--ncomponents]); |
| 2591 | kfree(components); |
| 2592 | path_put(&cur); |
| 2593 | return err; |
| 2594 | } |
| 2595 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2596 | static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr, |
| 2597 | struct svc_rqst *rqstp, const struct path *path) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2598 | { |
| 2599 | struct svc_export *exp_ps; |
| 2600 | __be32 res; |
| 2601 | |
| 2602 | exp_ps = rqst_find_fsidzero_export(rqstp); |
| 2603 | if (IS_ERR(exp_ps)) |
| 2604 | return nfserrno(PTR_ERR(exp_ps)); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2605 | res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2606 | exp_put(exp_ps); |
| 2607 | return res; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | /* |
| 2611 | * encode a fs_locations structure |
| 2612 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2613 | static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr, |
| 2614 | struct svc_rqst *rqstp, struct svc_export *exp) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2615 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2616 | __be32 status; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 2617 | int i; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2618 | __be32 *p; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2619 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2620 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2621 | status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2622 | if (status) |
| 2623 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2624 | p = xdr_reserve_space(xdr, 4); |
| 2625 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2626 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2627 | *p++ = cpu_to_be32(fslocs->locations_count); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2628 | for (i=0; i<fslocs->locations_count; i++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2629 | status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2630 | if (status) |
| 2631 | return status; |
| 2632 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2633 | return 0; |
| 2634 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2636 | static u32 nfs4_file_type(umode_t mode) |
| 2637 | { |
| 2638 | switch (mode & S_IFMT) { |
| 2639 | case S_IFIFO: return NF4FIFO; |
| 2640 | case S_IFCHR: return NF4CHR; |
| 2641 | case S_IFDIR: return NF4DIR; |
| 2642 | case S_IFBLK: return NF4BLK; |
| 2643 | case S_IFLNK: return NF4LNK; |
| 2644 | case S_IFREG: return NF4REG; |
| 2645 | case S_IFSOCK: return NF4SOCK; |
| 2646 | default: return NF4BAD; |
Tom Rix | 25fef48 | 2020-11-01 07:32:34 -0800 | [diff] [blame] | 2647 | } |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2650 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2651 | nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2652 | struct nfs4_ace *ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | { |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2654 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2655 | return nfs4_acl_write_who(xdr, ace->whotype); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2656 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2657 | return nfsd4_encode_group(xdr, rqstp, ace->who_gid); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2658 | else |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2659 | return nfsd4_encode_user(xdr, rqstp, ace->who_uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2662 | static inline __be32 |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2663 | nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2664 | { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2665 | __be32 *p; |
| 2666 | unsigned long i = hweight_long(layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2667 | |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2668 | p = xdr_reserve_space(xdr, 4 + 4 * i); |
| 2669 | if (!p) |
| 2670 | return nfserr_resource; |
| 2671 | |
| 2672 | *p++ = cpu_to_be32(i); |
| 2673 | |
| 2674 | for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) |
| 2675 | if (layout_types & (1 << i)) |
| 2676 | *p++ = cpu_to_be32(i); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2677 | |
| 2678 | return 0; |
| 2679 | } |
| 2680 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2681 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
| 2682 | FATTR4_WORD0_RDATTR_ERROR) |
| 2683 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2684 | #define WORD2_ABSENT_FS_ATTRS 0 |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2685 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2686 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 2687 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2688 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2689 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2690 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2691 | __be32 *p; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2692 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2693 | p = xdr_reserve_space(xdr, len + 4 + 4 + 4); |
| 2694 | if (!p) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2695 | return nfserr_resource; |
| 2696 | |
| 2697 | /* |
| 2698 | * For now we use a 0 here to indicate the null translation; in |
| 2699 | * the future we may place a call to translation code here. |
| 2700 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2701 | *p++ = cpu_to_be32(0); /* lfs */ |
| 2702 | *p++ = cpu_to_be32(0); /* pi */ |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2703 | p = xdr_encode_opaque(p, context, len); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2704 | return 0; |
| 2705 | } |
| 2706 | #else |
| 2707 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2708 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2709 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2710 | { return 0; } |
| 2711 | #endif |
| 2712 | |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2713 | 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] | 2714 | { |
| 2715 | /* As per referral draft: */ |
| 2716 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || |
| 2717 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { |
| 2718 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || |
| 2719 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) |
| 2720 | *rdattr_err = NFSERR_MOVED; |
| 2721 | else |
| 2722 | return nfserr_moved; |
| 2723 | } |
| 2724 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; |
| 2725 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2726 | *bmval2 &= WORD2_ABSENT_FS_ATTRS; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2727 | return 0; |
| 2728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2730 | |
| 2731 | static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) |
| 2732 | { |
| 2733 | struct path path = exp->ex_path; |
| 2734 | int err; |
| 2735 | |
| 2736 | path_get(&path); |
| 2737 | while (follow_up(&path)) { |
| 2738 | if (path.dentry != path.mnt->mnt_root) |
| 2739 | break; |
| 2740 | } |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2741 | 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] | 2742 | path_put(&path); |
| 2743 | return err; |
| 2744 | } |
| 2745 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2746 | static __be32 |
| 2747 | nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2) |
| 2748 | { |
| 2749 | __be32 *p; |
| 2750 | |
| 2751 | if (bmval2) { |
| 2752 | p = xdr_reserve_space(xdr, 16); |
| 2753 | if (!p) |
| 2754 | goto out_resource; |
| 2755 | *p++ = cpu_to_be32(3); |
| 2756 | *p++ = cpu_to_be32(bmval0); |
| 2757 | *p++ = cpu_to_be32(bmval1); |
| 2758 | *p++ = cpu_to_be32(bmval2); |
| 2759 | } else if (bmval1) { |
| 2760 | p = xdr_reserve_space(xdr, 12); |
| 2761 | if (!p) |
| 2762 | goto out_resource; |
| 2763 | *p++ = cpu_to_be32(2); |
| 2764 | *p++ = cpu_to_be32(bmval0); |
| 2765 | *p++ = cpu_to_be32(bmval1); |
| 2766 | } else { |
| 2767 | p = xdr_reserve_space(xdr, 8); |
| 2768 | if (!p) |
| 2769 | goto out_resource; |
| 2770 | *p++ = cpu_to_be32(1); |
| 2771 | *p++ = cpu_to_be32(bmval0); |
| 2772 | } |
| 2773 | |
| 2774 | return 0; |
| 2775 | out_resource: |
| 2776 | return nfserr_resource; |
| 2777 | } |
| 2778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | /* |
| 2780 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle |
| 2781 | * ourselves. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | */ |
Jeff Layton | da2ebce | 2014-05-30 09:09:25 -0400 | [diff] [blame] | 2783 | static __be32 |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 2784 | nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, |
| 2785 | struct svc_export *exp, |
| 2786 | struct dentry *dentry, u32 *bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2787 | struct svc_rqst *rqstp, int ignore_crossmnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | { |
| 2789 | u32 bmval0 = bmval[0]; |
| 2790 | u32 bmval1 = bmval[1]; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2791 | u32 bmval2 = bmval[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | struct kstat stat; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2793 | struct svc_fh *tempfh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | struct kstatfs statfs; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2795 | __be32 *p; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 2796 | int starting_len = xdr->buf->len; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2797 | int attrlen_offset; |
| 2798 | __be32 attrlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | u32 dummy; |
| 2800 | u64 dummy64; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2801 | u32 rdattr_err = 0; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2802 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2803 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | struct nfs4_acl *acl = NULL; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2805 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2806 | void *context = NULL; |
| 2807 | int contextlen; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2808 | #endif |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2809 | bool contextsupport = false; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2810 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 2811 | u32 minorversion = resp->cstate.minorversion; |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2812 | struct path path = { |
| 2813 | .mnt = exp->ex_path.mnt, |
| 2814 | .dentry = dentry, |
| 2815 | }; |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 2816 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | |
| 2818 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2819 | BUG_ON(!nfsd_attrs_supported(minorversion, bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2821 | if (exp->ex_fslocs.migrated) { |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2822 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err); |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2823 | if (status) |
| 2824 | goto out; |
| 2825 | } |
| 2826 | |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2827 | 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] | 2828 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | goto out_nfserr; |
Christoph Hellwig | 1233790 | 2014-05-28 10:46:13 +0200 | [diff] [blame] | 2830 | if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | |
| 2831 | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
| 2833 | FATTR4_WORD1_SPACE_TOTAL))) { |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2834 | err = vfs_statfs(&path, &statfs); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2835 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | goto out_nfserr; |
| 2837 | } |
| 2838 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2839 | tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
| 2840 | status = nfserr_jukebox; |
| 2841 | if (!tempfh) |
| 2842 | goto out; |
| 2843 | fh_init(tempfh, NFS4_FHSIZE); |
| 2844 | status = fh_compose(tempfh, exp, dentry, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | if (status) |
| 2846 | goto out; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2847 | fhp = tempfh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | } |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2849 | if (bmval0 & FATTR4_WORD0_ACL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2850 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2851 | if (err == -EOPNOTSUPP) |
| 2852 | bmval0 &= ~FATTR4_WORD0_ACL; |
| 2853 | else if (err == -EINVAL) { |
| 2854 | status = nfserr_attrnotsupp; |
| 2855 | goto out; |
| 2856 | } else if (err != 0) |
| 2857 | goto out_nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2860 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2861 | if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) || |
| 2862 | bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2863 | if (exp->ex_flags & NFSEXP_SECURITY_LABEL) |
| 2864 | err = security_inode_getsecctx(d_inode(dentry), |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2865 | &context, &contextlen); |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2866 | else |
| 2867 | err = -EOPNOTSUPP; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2868 | contextsupport = (err == 0); |
| 2869 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 2870 | if (err == -EOPNOTSUPP) |
| 2871 | bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2872 | else if (err) |
| 2873 | goto out_nfserr; |
| 2874 | } |
| 2875 | } |
| 2876 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
| 2877 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2878 | status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2); |
| 2879 | if (status) |
| 2880 | goto out; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2881 | |
| 2882 | attrlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2883 | p = xdr_reserve_space(xdr, 4); |
| 2884 | if (!p) |
| 2885 | goto out_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2886 | p++; /* to be backfilled later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | |
| 2888 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | dcd20869 | 2017-01-11 20:34:50 -0500 | [diff] [blame] | 2889 | u32 supp[3]; |
| 2890 | |
| 2891 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2892 | |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2893 | if (!IS_POSIXACL(dentry->d_inode)) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2894 | supp[0] &= ~FATTR4_WORD0_ACL; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2895 | if (!contextsupport) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2896 | supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2897 | if (!supp[2]) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2898 | p = xdr_reserve_space(xdr, 12); |
| 2899 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2900 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2901 | *p++ = cpu_to_be32(2); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2902 | *p++ = cpu_to_be32(supp[0]); |
| 2903 | *p++ = cpu_to_be32(supp[1]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2904 | } else { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2905 | p = xdr_reserve_space(xdr, 16); |
| 2906 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2907 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2908 | *p++ = cpu_to_be32(3); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2909 | *p++ = cpu_to_be32(supp[0]); |
| 2910 | *p++ = cpu_to_be32(supp[1]); |
| 2911 | *p++ = cpu_to_be32(supp[2]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | } |
| 2914 | if (bmval0 & FATTR4_WORD0_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2915 | p = xdr_reserve_space(xdr, 4); |
| 2916 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | goto out_resource; |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2918 | dummy = nfs4_file_type(stat.mode); |
J. Bruce Fields | 6b6d8137 | 2013-01-16 17:11:11 -0500 | [diff] [blame] | 2919 | if (dummy == NF4BAD) { |
| 2920 | status = nfserr_serverfault; |
| 2921 | goto out; |
| 2922 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2923 | *p++ = cpu_to_be32(dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | } |
| 2925 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2926 | p = xdr_reserve_space(xdr, 4); |
| 2927 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | goto out_resource; |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2929 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2930 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT); |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2931 | else |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2932 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT| |
| 2933 | NFS4_FH_VOL_RENAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | } |
| 2935 | if (bmval0 & FATTR4_WORD0_CHANGE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2936 | p = xdr_reserve_space(xdr, 8); |
| 2937 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | goto out_resource; |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2939 | p = encode_change(p, &stat, d_inode(dentry), exp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | } |
| 2941 | if (bmval0 & FATTR4_WORD0_SIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2942 | p = xdr_reserve_space(xdr, 8); |
| 2943 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2945 | p = xdr_encode_hyper(p, stat.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | } |
| 2947 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2948 | p = xdr_reserve_space(xdr, 4); |
| 2949 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2951 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | } |
| 2953 | if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2954 | p = xdr_reserve_space(xdr, 4); |
| 2955 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2957 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | } |
| 2959 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2960 | p = xdr_reserve_space(xdr, 4); |
| 2961 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2963 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | } |
| 2965 | if (bmval0 & FATTR4_WORD0_FSID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2966 | p = xdr_reserve_space(xdr, 16); |
| 2967 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2969 | if (exp->ex_fslocs.migrated) { |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2970 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR); |
| 2971 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2972 | } else switch(fsid_source(fhp)) { |
| 2973 | case FSIDSOURCE_FSID: |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2974 | p = xdr_encode_hyper(p, (u64)exp->ex_fsid); |
| 2975 | p = xdr_encode_hyper(p, (u64)0); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2976 | break; |
| 2977 | case FSIDSOURCE_DEV: |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2978 | *p++ = cpu_to_be32(0); |
| 2979 | *p++ = cpu_to_be32(MAJOR(stat.dev)); |
| 2980 | *p++ = cpu_to_be32(0); |
| 2981 | *p++ = cpu_to_be32(MINOR(stat.dev)); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2982 | break; |
| 2983 | case FSIDSOURCE_UUID: |
Kinglong Mee | 94eb368 | 2014-05-23 20:00:19 +0800 | [diff] [blame] | 2984 | p = xdr_encode_opaque_fixed(p, exp->ex_uuid, |
| 2985 | EX_UUID_LEN); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2986 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | } |
| 2988 | } |
| 2989 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { |
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(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | } |
| 2995 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { |
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(nn->nfsd4_lease); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | } |
| 3001 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { |
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(rdattr_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | } |
| 3007 | if (bmval0 & FATTR4_WORD0_ACL) { |
| 3008 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | |
| 3010 | if (acl == NULL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3011 | p = xdr_reserve_space(xdr, 4); |
| 3012 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | goto out_resource; |
| 3014 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3015 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | goto out_acl; |
| 3017 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3018 | p = xdr_reserve_space(xdr, 4); |
| 3019 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3021 | *p++ = cpu_to_be32(acl->naces); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3023 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3024 | p = xdr_reserve_space(xdr, 4*3); |
| 3025 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3027 | *p++ = cpu_to_be32(ace->type); |
| 3028 | *p++ = cpu_to_be32(ace->flag); |
| 3029 | *p++ = cpu_to_be32(ace->access_mask & |
| 3030 | NFS4_ACE_MASK_ALL); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3031 | status = nfsd4_encode_aclname(xdr, rqstp, ace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | if (status) |
| 3033 | goto out; |
| 3034 | } |
| 3035 | } |
| 3036 | out_acl: |
| 3037 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { |
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; |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 3041 | *p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
| 3043 | } |
| 3044 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3045 | p = xdr_reserve_space(xdr, 4); |
| 3046 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3048 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | } |
| 3050 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3051 | p = xdr_reserve_space(xdr, 4); |
| 3052 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3054 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3057 | p = xdr_reserve_space(xdr, 4); |
| 3058 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3060 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | } |
| 3062 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3063 | p = xdr_reserve_space(xdr, 4); |
| 3064 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3066 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | } |
| 3068 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3069 | p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4); |
| 3070 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | goto out_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3072 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, |
| 3073 | fhp->fh_handle.fh_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | } |
| 3075 | if (bmval0 & FATTR4_WORD0_FILEID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3076 | p = xdr_reserve_space(xdr, 8); |
| 3077 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3079 | p = xdr_encode_hyper(p, stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | } |
| 3081 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3082 | p = xdr_reserve_space(xdr, 8); |
| 3083 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3085 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | } |
| 3087 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3088 | p = xdr_reserve_space(xdr, 8); |
| 3089 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3091 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | } |
| 3093 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3094 | p = xdr_reserve_space(xdr, 8); |
| 3095 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3097 | p = xdr_encode_hyper(p, (u64) statfs.f_files); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3099 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3100 | status = nfsd4_encode_fs_locations(xdr, rqstp, exp); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3101 | if (status) |
| 3102 | goto out; |
| 3103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
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_MAXFILESIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3111 | p = xdr_reserve_space(xdr, 8); |
| 3112 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3114 | 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] | 3115 | } |
| 3116 | if (bmval0 & FATTR4_WORD0_MAXLINK) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3117 | p = xdr_reserve_space(xdr, 4); |
| 3118 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3120 | *p++ = cpu_to_be32(255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | } |
| 3122 | if (bmval0 & FATTR4_WORD0_MAXNAME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3123 | p = xdr_reserve_space(xdr, 4); |
| 3124 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3126 | *p++ = cpu_to_be32(statfs.f_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | } |
| 3128 | if (bmval0 & FATTR4_WORD0_MAXREAD) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3129 | p = xdr_reserve_space(xdr, 8); |
| 3130 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3132 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | } |
| 3134 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3135 | p = xdr_reserve_space(xdr, 8); |
| 3136 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3138 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | } |
| 3140 | if (bmval1 & FATTR4_WORD1_MODE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3141 | p = xdr_reserve_space(xdr, 4); |
| 3142 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3144 | *p++ = cpu_to_be32(stat.mode & S_IALLUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
| 3146 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { |
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 (bmval1 & FATTR4_WORD1_NUMLINKS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3153 | p = xdr_reserve_space(xdr, 4); |
| 3154 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3156 | *p++ = cpu_to_be32(stat.nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | } |
| 3158 | if (bmval1 & FATTR4_WORD1_OWNER) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3159 | status = nfsd4_encode_user(xdr, rqstp, stat.uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | if (status) |
| 3161 | goto out; |
| 3162 | } |
| 3163 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3164 | status = nfsd4_encode_group(xdr, rqstp, stat.gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | if (status) |
| 3166 | goto out; |
| 3167 | } |
| 3168 | if (bmval1 & FATTR4_WORD1_RAWDEV) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3169 | p = xdr_reserve_space(xdr, 8); |
| 3170 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3172 | *p++ = cpu_to_be32((u32) MAJOR(stat.rdev)); |
| 3173 | *p++ = cpu_to_be32((u32) MINOR(stat.rdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | } |
| 3175 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3176 | p = xdr_reserve_space(xdr, 8); |
| 3177 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | goto out_resource; |
| 3179 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3180 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | } |
| 3182 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3183 | p = xdr_reserve_space(xdr, 8); |
| 3184 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | goto out_resource; |
| 3186 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3187 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | } |
| 3189 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3190 | p = xdr_reserve_space(xdr, 8); |
| 3191 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | goto out_resource; |
| 3193 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3194 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
| 3196 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3197 | p = xdr_reserve_space(xdr, 8); |
| 3198 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | goto out_resource; |
| 3200 | dummy64 = (u64)stat.blocks << 9; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3201 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | } |
| 3203 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3204 | p = xdr_reserve_space(xdr, 12); |
| 3205 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3207 | p = xdr_encode_hyper(p, (s64)stat.atime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3208 | *p++ = cpu_to_be32(stat.atime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | } |
| 3210 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3211 | p = xdr_reserve_space(xdr, 12); |
| 3212 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | goto out_resource; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 3214 | p = encode_time_delta(p, d_inode(dentry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } |
| 3216 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3217 | p = xdr_reserve_space(xdr, 12); |
| 3218 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3220 | p = xdr_encode_hyper(p, (s64)stat.ctime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3221 | *p++ = cpu_to_be32(stat.ctime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | } |
| 3223 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3224 | p = xdr_reserve_space(xdr, 12); |
| 3225 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3227 | p = xdr_encode_hyper(p, (s64)stat.mtime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3228 | *p++ = cpu_to_be32(stat.mtime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | } |
| 3230 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3231 | struct kstat parent_stat; |
| 3232 | u64 ino = stat.ino; |
| 3233 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3234 | p = xdr_reserve_space(xdr, 8); |
| 3235 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | goto out_resource; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3237 | /* |
| 3238 | * Get parent's attributes if not ignoring crossmount |
| 3239 | * and this is the root of a cross-mounted filesystem. |
| 3240 | */ |
| 3241 | if (ignore_crossmnt == 0 && |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3242 | dentry == exp->ex_path.mnt->mnt_root) { |
| 3243 | err = get_parent_attributes(exp, &parent_stat); |
| 3244 | if (err) |
| 3245 | goto out_nfserr; |
| 3246 | ino = parent_stat.ino; |
| 3247 | } |
| 3248 | p = xdr_encode_hyper(p, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | } |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3250 | #ifdef CONFIG_NFSD_PNFS |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3251 | if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3252 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3253 | if (status) |
| 3254 | goto out; |
| 3255 | } |
| 3256 | |
| 3257 | if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3258 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3259 | if (status) |
| 3260 | goto out; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) { |
| 3264 | p = xdr_reserve_space(xdr, 4); |
| 3265 | if (!p) |
| 3266 | goto out_resource; |
| 3267 | *p++ = cpu_to_be32(stat.blksize); |
| 3268 | } |
| 3269 | #endif /* CONFIG_NFSD_PNFS */ |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3270 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { |
Trond Myklebust | b26b78c | 2017-05-09 16:24:59 -0400 | [diff] [blame] | 3271 | u32 supp[3]; |
| 3272 | |
| 3273 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
| 3274 | supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0; |
| 3275 | supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1; |
| 3276 | supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2; |
| 3277 | |
| 3278 | status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]); |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3279 | if (status) |
| 3280 | goto out; |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3281 | } |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3282 | |
J. Bruce Fields | a858576 | 2018-04-25 13:26:23 -0400 | [diff] [blame] | 3283 | if (bmval2 & FATTR4_WORD2_CHANGE_ATTR_TYPE) { |
| 3284 | p = xdr_reserve_space(xdr, 4); |
| 3285 | if (!p) |
| 3286 | goto out_resource; |
| 3287 | if (IS_I_VERSION(d_inode(dentry))) |
| 3288 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR); |
| 3289 | else |
| 3290 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA); |
| 3291 | } |
| 3292 | |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3293 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3294 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 3295 | status = nfsd4_encode_security_label(xdr, rqstp, context, |
| 3296 | contextlen); |
| 3297 | if (status) |
| 3298 | goto out; |
| 3299 | } |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3300 | #endif |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3301 | |
Frank van der Linden | 0e885e8 | 2020-06-23 22:39:27 +0000 | [diff] [blame] | 3302 | if (bmval2 & FATTR4_WORD2_XATTR_SUPPORT) { |
| 3303 | p = xdr_reserve_space(xdr, 4); |
| 3304 | if (!p) |
| 3305 | goto out_resource; |
| 3306 | err = xattr_supported_namespace(d_inode(dentry), |
| 3307 | XATTR_USER_PREFIX); |
| 3308 | *p++ = cpu_to_be32(err == 0); |
| 3309 | } |
| 3310 | |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 3311 | attrlen = htonl(xdr->buf->len - attrlen_offset - 4); |
| 3312 | write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | status = nfs_ok; |
| 3314 | |
| 3315 | out: |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3316 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3317 | if (context) |
| 3318 | security_release_secctx(context, contextlen); |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3319 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3320 | kfree(acl); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3321 | if (tempfh) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 3322 | fh_put(tempfh); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3323 | kfree(tempfh); |
| 3324 | } |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3325 | if (status) |
| 3326 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | return status; |
| 3328 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 3329 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | goto out; |
| 3331 | out_resource: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | status = nfserr_resource; |
| 3333 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3336 | static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr, |
| 3337 | struct xdr_buf *buf, __be32 *p, int bytes) |
| 3338 | { |
| 3339 | xdr->scratch.iov_len = 0; |
| 3340 | memset(buf, 0, sizeof(struct xdr_buf)); |
| 3341 | buf->head[0].iov_base = p; |
| 3342 | buf->head[0].iov_len = 0; |
| 3343 | buf->len = 0; |
| 3344 | xdr->buf = buf; |
| 3345 | xdr->iov = buf->head; |
| 3346 | xdr->p = p; |
| 3347 | xdr->end = (void *)p + bytes; |
| 3348 | buf->buflen = bytes; |
| 3349 | } |
| 3350 | |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3351 | __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, |
| 3352 | struct svc_fh *fhp, struct svc_export *exp, |
| 3353 | struct dentry *dentry, u32 *bmval, |
| 3354 | struct svc_rqst *rqstp, int ignore_crossmnt) |
| 3355 | { |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3356 | struct xdr_buf dummy; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3357 | struct xdr_stream xdr; |
| 3358 | __be32 ret; |
| 3359 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3360 | svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2); |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3361 | ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp, |
| 3362 | ignore_crossmnt); |
| 3363 | *p = xdr.p; |
| 3364 | return ret; |
| 3365 | } |
| 3366 | |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 3367 | static inline int attributes_need_mount(u32 *bmval) |
| 3368 | { |
| 3369 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) |
| 3370 | return 1; |
| 3371 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 3372 | return 1; |
| 3373 | return 0; |
| 3374 | } |
| 3375 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3376 | static __be32 |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3377 | nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, |
| 3378 | const char *name, int namlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | { |
| 3380 | struct svc_export *exp = cd->rd_fhp->fh_export; |
| 3381 | struct dentry *dentry; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3382 | __be32 nfserr; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3383 | int ignore_crossmnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | |
Al Viro | 6c2d4798 | 2019-10-31 01:21:58 -0400 | [diff] [blame] | 3385 | dentry = lookup_positive_unlocked(name, cd->rd_fhp->fh_dentry, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | if (IS_ERR(dentry)) |
| 3387 | return nfserrno(PTR_ERR(dentry)); |
| 3388 | |
| 3389 | exp_get(exp); |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3390 | /* |
| 3391 | * In the case of a mountpoint, the client may be asking for |
| 3392 | * attributes that are only properties of the underlying filesystem |
| 3393 | * as opposed to the cross-mounted file system. In such a case, |
| 3394 | * we will not follow the cross mount and will fill the attribtutes |
| 3395 | * directly from the mountpoint dentry. |
| 3396 | */ |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3397 | if (nfsd_mountpoint(dentry, exp)) { |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3398 | int err; |
| 3399 | |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3400 | if (!(exp->ex_flags & NFSEXP_V4ROOT) |
| 3401 | && !attributes_need_mount(cd->rd_bmval)) { |
| 3402 | ignore_crossmnt = 1; |
| 3403 | goto out_encode; |
| 3404 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3405 | /* |
| 3406 | * Why the heck aren't we just using nfsd_lookup?? |
| 3407 | * Different "."/".." handling? Something else? |
| 3408 | * At least, add a comment here to explain.... |
| 3409 | */ |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3410 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
| 3411 | if (err) { |
| 3412 | nfserr = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | goto out_put; |
| 3414 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3415 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
| 3416 | if (nfserr) |
| 3417 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | |
| 3419 | } |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3420 | out_encode: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3421 | nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3422 | cd->rd_rqstp, ignore_crossmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | out_put: |
| 3424 | dput(dentry); |
| 3425 | exp_put(exp); |
| 3426 | return nfserr; |
| 3427 | } |
| 3428 | |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3429 | static __be32 * |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3430 | nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | { |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3432 | __be32 *p; |
| 3433 | |
Kinglong Mee | c3a4561 | 2014-07-06 11:34:43 +0800 | [diff] [blame] | 3434 | p = xdr_reserve_space(xdr, 20); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3435 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | return NULL; |
| 3437 | *p++ = htonl(2); |
| 3438 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ |
| 3439 | *p++ = htonl(0); /* bmval1 */ |
| 3440 | |
J. Bruce Fields | 87915c6 | 2013-01-16 17:33:28 -0500 | [diff] [blame] | 3441 | *p++ = htonl(4); /* attribute length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | *p++ = nfserr; /* no htonl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | return p; |
| 3444 | } |
| 3445 | |
| 3446 | static int |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3447 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
| 3448 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | { |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3450 | struct readdir_cd *ccd = ccdv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3452 | struct xdr_stream *xdr = cd->xdr; |
| 3453 | int start_offset = xdr->buf->len; |
| 3454 | int cookie_offset; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3455 | u32 name_and_cookie; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3456 | int entry_bytes; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3457 | __be32 nfserr = nfserr_toosmall; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3458 | __be64 wire_offset; |
| 3459 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | |
| 3461 | /* In nfsv4, "." and ".." never make it onto the wire.. */ |
| 3462 | if (name && isdotent(name, namlen)) { |
| 3463 | cd->common.err = nfs_ok; |
| 3464 | return 0; |
| 3465 | } |
| 3466 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3467 | if (cd->cookie_offset) { |
| 3468 | wire_offset = cpu_to_be64(offset); |
| 3469 | write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset, |
| 3470 | &wire_offset, 8); |
| 3471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3473 | p = xdr_reserve_space(xdr, 4); |
| 3474 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | *p++ = xdr_one; /* mark entry present */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3477 | cookie_offset = xdr->buf->len; |
| 3478 | p = xdr_reserve_space(xdr, 3*4 + namlen); |
| 3479 | if (!p) |
| 3480 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
| 3482 | p = xdr_encode_array(p, name, namlen); /* name length & name */ |
| 3483 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3484 | nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | switch (nfserr) { |
| 3486 | case nfs_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | break; |
| 3488 | case nfserr_resource: |
| 3489 | nfserr = nfserr_toosmall; |
| 3490 | goto fail; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3491 | case nfserr_noent: |
Kinglong Mee | f41c5ad | 2014-06-13 17:32:42 +0800 | [diff] [blame] | 3492 | xdr_truncate_encode(xdr, start_offset); |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3493 | goto skip_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | default: |
| 3495 | /* |
| 3496 | * If the client requested the RDATTR_ERROR attribute, |
| 3497 | * we stuff the error code into this attribute |
| 3498 | * and continue. If this attribute was not requested, |
| 3499 | * then in accordance with the spec, we fail the |
| 3500 | * entire READDIR operation(!) |
| 3501 | */ |
| 3502 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) |
| 3503 | goto fail; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3504 | p = nfsd4_encode_rdattr_error(xdr, nfserr); |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3505 | if (p == NULL) { |
| 3506 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | goto fail; |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | } |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3510 | nfserr = nfserr_toosmall; |
| 3511 | entry_bytes = xdr->buf->len - start_offset; |
| 3512 | if (entry_bytes > cd->rd_maxcount) |
| 3513 | goto fail; |
| 3514 | cd->rd_maxcount -= entry_bytes; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3515 | /* |
| 3516 | * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so |
| 3517 | * let's always let through the first entry, at least: |
| 3518 | */ |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3519 | if (!cd->rd_dircount) |
| 3520 | goto fail; |
| 3521 | name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3522 | if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) |
| 3523 | goto fail; |
| 3524 | cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3525 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3526 | cd->cookie_offset = cookie_offset; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3527 | skip_entry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | cd->common.err = nfs_ok; |
| 3529 | return 0; |
| 3530 | fail: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3531 | xdr_truncate_encode(xdr, start_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | cd->common.err = nfserr; |
| 3533 | return -EINVAL; |
| 3534 | } |
| 3535 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3536 | static __be32 |
| 3537 | nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid) |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3538 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3539 | __be32 *p; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3540 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3541 | p = xdr_reserve_space(xdr, sizeof(stateid_t)); |
| 3542 | if (!p) |
| 3543 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3544 | *p++ = cpu_to_be32(sid->si_generation); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3545 | p = xdr_encode_opaque_fixed(p, &sid->si_opaque, |
| 3546 | sizeof(stateid_opaque_t)); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3547 | return 0; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3548 | } |
| 3549 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3550 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3551 | 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] | 3552 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3553 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3554 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3556 | p = xdr_reserve_space(xdr, 8); |
| 3557 | if (!p) |
| 3558 | return nfserr_resource; |
| 3559 | *p++ = cpu_to_be32(access->ac_supported); |
| 3560 | *p++ = cpu_to_be32(access->ac_resp_access); |
| 3561 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3564 | static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts) |
| 3565 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3566 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3567 | __be32 *p; |
| 3568 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3569 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 8); |
| 3570 | if (!p) |
| 3571 | return nfserr_resource; |
| 3572 | p = xdr_encode_opaque_fixed(p, bcts->sessionid.data, |
| 3573 | NFS4_MAX_SESSIONID_LEN); |
| 3574 | *p++ = cpu_to_be32(bcts->dir); |
| 3575 | /* Upshifting from TCP to RDMA is not supported */ |
| 3576 | *p++ = cpu_to_be32(0); |
| 3577 | return 0; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3578 | } |
| 3579 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3580 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3581 | 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] | 3582 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3583 | struct xdr_stream *xdr = &resp->xdr; |
| 3584 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3585 | return nfsd4_encode_stateid(xdr, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3589 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3590 | 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] | 3591 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3592 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3593 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3595 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 3596 | if (!p) |
| 3597 | return nfserr_resource; |
| 3598 | p = xdr_encode_opaque_fixed(p, commit->co_verf.data, |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3599 | NFS4_VERIFIER_SIZE); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3600 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3603 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3604 | 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] | 3605 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3606 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3607 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3609 | p = xdr_reserve_space(xdr, 20); |
| 3610 | if (!p) |
| 3611 | return nfserr_resource; |
| 3612 | encode_cinfo(p, &create->cr_cinfo); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 3613 | return nfsd4_encode_bitmap(xdr, create->cr_bmval[0], |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3614 | create->cr_bmval[1], create->cr_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3617 | static __be32 |
| 3618 | 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] | 3619 | { |
| 3620 | struct svc_fh *fhp = getattr->ga_fhp; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3621 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3623 | return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry, |
| 3624 | getattr->ga_bmval, resp->rqstp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | } |
| 3626 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3627 | static __be32 |
| 3628 | 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] | 3629 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3630 | struct xdr_stream *xdr = &resp->xdr; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3631 | struct svc_fh *fhp = *fhpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | unsigned int len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3633 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3635 | len = fhp->fh_handle.fh_size; |
| 3636 | p = xdr_reserve_space(xdr, len + 4); |
| 3637 | if (!p) |
| 3638 | return nfserr_resource; |
| 3639 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len); |
| 3640 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | /* |
| 3644 | * Including all fields other than the name, a LOCK4denied structure requires |
| 3645 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. |
| 3646 | */ |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3647 | static __be32 |
| 3648 | 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] | 3649 | { |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3650 | struct xdr_netobj *conf = &ld->ld_owner; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3651 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3653 | again: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3654 | p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3655 | if (!p) { |
| 3656 | /* |
| 3657 | * Don't fail to return the result just because we can't |
| 3658 | * return the conflicting open: |
| 3659 | */ |
| 3660 | if (conf->len) { |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3661 | kfree(conf->data); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3662 | conf->len = 0; |
| 3663 | conf->data = NULL; |
| 3664 | goto again; |
| 3665 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3666 | return nfserr_resource; |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3667 | } |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3668 | p = xdr_encode_hyper(p, ld->ld_start); |
| 3669 | p = xdr_encode_hyper(p, ld->ld_length); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3670 | *p++ = cpu_to_be32(ld->ld_type); |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3671 | if (conf->len) { |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3672 | p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8); |
| 3673 | p = xdr_encode_opaque(p, conf->data, conf->len); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3674 | kfree(conf->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3676 | p = xdr_encode_hyper(p, (u64)0); /* clientid */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3677 | *p++ = cpu_to_be32(0); /* length of owner name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3679 | return nfserr_denied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3682 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3683 | 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] | 3684 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3685 | struct xdr_stream *xdr = &resp->xdr; |
| 3686 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3687 | if (!nfserr) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3688 | nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid); |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3689 | else if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3690 | nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3691 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3692 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3695 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3696 | 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] | 3697 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3698 | struct xdr_stream *xdr = &resp->xdr; |
| 3699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3701 | nfsd4_encode_lock_denied(xdr, &lockt->lt_denied); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3702 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3705 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3706 | 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] | 3707 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3708 | struct xdr_stream *xdr = &resp->xdr; |
| 3709 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3710 | return nfsd4_encode_stateid(xdr, &locku->lu_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3714 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3715 | 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] | 3716 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3717 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3718 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3720 | p = xdr_reserve_space(xdr, 20); |
| 3721 | if (!p) |
| 3722 | return nfserr_resource; |
| 3723 | p = encode_cinfo(p, &link->li_cinfo); |
| 3724 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3728 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3729 | 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] | 3730 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3731 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3732 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3734 | nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid); |
| 3735 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3736 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3737 | p = xdr_reserve_space(xdr, 24); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3738 | if (!p) |
| 3739 | return nfserr_resource; |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 3740 | p = encode_cinfo(p, &open->op_cinfo); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3741 | *p++ = cpu_to_be32(open->op_rflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3743 | nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1], |
| 3744 | open->op_bmval[2]); |
| 3745 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3746 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3747 | |
| 3748 | p = xdr_reserve_space(xdr, 4); |
| 3749 | if (!p) |
| 3750 | return nfserr_resource; |
| 3751 | |
| 3752 | *p++ = cpu_to_be32(open->op_delegate_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | switch (open->op_delegate_type) { |
| 3754 | case NFS4_OPEN_DELEGATE_NONE: |
| 3755 | break; |
| 3756 | case NFS4_OPEN_DELEGATE_READ: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3757 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3758 | if (nfserr) |
| 3759 | return nfserr; |
| 3760 | p = xdr_reserve_space(xdr, 20); |
| 3761 | if (!p) |
| 3762 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3763 | *p++ = cpu_to_be32(open->op_recall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | |
| 3765 | /* |
| 3766 | * TODO: ACE's in delegations |
| 3767 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3768 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3769 | *p++ = cpu_to_be32(0); |
| 3770 | *p++ = cpu_to_be32(0); |
| 3771 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | break; |
| 3773 | case NFS4_OPEN_DELEGATE_WRITE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3774 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3775 | if (nfserr) |
| 3776 | return nfserr; |
| 3777 | p = xdr_reserve_space(xdr, 32); |
| 3778 | if (!p) |
| 3779 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3780 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | |
| 3782 | /* |
| 3783 | * TODO: space_limit's in delegations |
| 3784 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3785 | *p++ = cpu_to_be32(NFS4_LIMIT_SIZE); |
| 3786 | *p++ = cpu_to_be32(~(u32)0); |
| 3787 | *p++ = cpu_to_be32(~(u32)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | |
| 3789 | /* |
| 3790 | * TODO: ACE's in delegations |
| 3791 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3792 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3793 | *p++ = cpu_to_be32(0); |
| 3794 | *p++ = cpu_to_be32(0); |
| 3795 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | break; |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3797 | case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ |
| 3798 | switch (open->op_why_no_deleg) { |
| 3799 | case WND4_CONTENTION: |
| 3800 | case WND4_RESOURCE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3801 | p = xdr_reserve_space(xdr, 8); |
| 3802 | if (!p) |
| 3803 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3804 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
| 3805 | /* deleg signaling not supported yet: */ |
| 3806 | *p++ = cpu_to_be32(0); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3807 | break; |
| 3808 | default: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3809 | p = xdr_reserve_space(xdr, 4); |
| 3810 | if (!p) |
| 3811 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3812 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3813 | } |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3814 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | default: |
| 3816 | BUG(); |
| 3817 | } |
| 3818 | /* XXX save filehandle here */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3819 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3822 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3823 | 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] | 3824 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3825 | struct xdr_stream *xdr = &resp->xdr; |
| 3826 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3827 | return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3830 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3831 | 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] | 3832 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3833 | struct xdr_stream *xdr = &resp->xdr; |
| 3834 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3835 | return nfsd4_encode_stateid(xdr, &od->od_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3838 | static __be32 nfsd4_encode_splice_read( |
| 3839 | struct nfsd4_compoundres *resp, |
| 3840 | struct nfsd4_read *read, |
| 3841 | struct file *file, unsigned long maxcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | { |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3843 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3844 | struct xdr_buf *buf = xdr->buf; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3845 | int status, space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3846 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3847 | __be32 nfserr; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3848 | __be32 *p = xdr->p - 2; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3849 | |
Kinglong Mee | d5d5c30 | 2014-07-09 21:51:27 +0800 | [diff] [blame] | 3850 | /* Make sure there will be room for padding if needed */ |
| 3851 | if (xdr->end - xdr->p < 1) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3852 | return nfserr_resource; |
| 3853 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3854 | nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3855 | file, read->rd_offset, &maxcount, &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3856 | read->rd_length = maxcount; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3857 | if (nfserr) |
| 3858 | goto out_err; |
| 3859 | status = svc_encode_result_payload(read->rd_rqstp, |
| 3860 | buf->head[0].iov_len, maxcount); |
| 3861 | if (status) { |
| 3862 | nfserr = nfserrno(status); |
| 3863 | goto out_err; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3864 | } |
| 3865 | |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3866 | *(p++) = htonl(eof); |
| 3867 | *(p++) = htonl(maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3868 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3869 | buf->page_len = maxcount; |
| 3870 | buf->len += maxcount; |
J. Bruce Fields | 15b23ef | 2014-09-24 16:32:34 -0400 | [diff] [blame] | 3871 | xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) |
| 3872 | / PAGE_SIZE; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3873 | |
| 3874 | /* Use rest of head for padding and remaining ops: */ |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3875 | buf->tail[0].iov_base = xdr->p; |
| 3876 | buf->tail[0].iov_len = 0; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3877 | xdr->iov = buf->tail; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3878 | if (maxcount&3) { |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3879 | int pad = 4 - (maxcount&3); |
| 3880 | |
| 3881 | *(xdr->p++) = 0; |
| 3882 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3883 | buf->tail[0].iov_base += maxcount&3; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3884 | buf->tail[0].iov_len = pad; |
| 3885 | buf->len += pad; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | space_left = min_t(int, (void *)xdr->end - (void *)xdr->p, |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3889 | buf->buflen - buf->len); |
| 3890 | buf->buflen = buf->len + space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3891 | xdr->end = (__be32 *)((void *)xdr->end + space_left); |
| 3892 | |
| 3893 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3894 | |
| 3895 | out_err: |
| 3896 | /* |
| 3897 | * nfsd_splice_actor may have already messed with the |
| 3898 | * page length; reset it so as not to confuse |
| 3899 | * xdr_truncate_encode in our caller. |
| 3900 | */ |
| 3901 | buf->page_len = 0; |
| 3902 | return nfserr; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, |
| 3906 | struct nfsd4_read *read, |
| 3907 | struct file *file, unsigned long maxcount) |
| 3908 | { |
| 3909 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3911 | int starting_len = xdr->buf->len - 8; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3912 | __be32 nfserr; |
| 3913 | __be32 tmp; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3914 | int pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | |
Anna Schumaker | 403217f | 2020-08-17 12:53:06 -0400 | [diff] [blame] | 3916 | read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, maxcount); |
| 3917 | if (read->rd_vlen < 0) |
| 3918 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3920 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3921 | resp->rqstp->rq_vec, read->rd_vlen, &maxcount, |
| 3922 | &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3923 | read->rd_length = maxcount; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3924 | if (nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | return nfserr; |
Chuck Lever | 03493bc | 2020-06-10 10:36:42 -0400 | [diff] [blame] | 3926 | if (svc_encode_result_payload(resp->rqstp, starting_len + 8, maxcount)) |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 3927 | return nfserr_io; |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3928 | xdr_truncate_encode(xdr, starting_len + 8 + xdr_align_size(maxcount)); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3929 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3930 | tmp = htonl(eof); |
| 3931 | write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); |
| 3932 | tmp = htonl(maxcount); |
| 3933 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
| 3934 | |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3935 | tmp = xdr_zero; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3936 | pad = (maxcount&3) ? 4 - (maxcount&3) : 0; |
| 3937 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount, |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3938 | &tmp, pad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | return 0; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3940 | |
| 3941 | } |
| 3942 | |
| 3943 | static __be32 |
| 3944 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 3945 | struct nfsd4_read *read) |
| 3946 | { |
| 3947 | unsigned long maxcount; |
| 3948 | struct xdr_stream *xdr = &resp->xdr; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3949 | struct file *file; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3950 | int starting_len = xdr->buf->len; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3951 | __be32 *p; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3952 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3953 | if (nfserr) |
| 3954 | return nfserr; |
| 3955 | file = read->rd_nf->nf_file; |
| 3956 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3957 | p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */ |
| 3958 | if (!p) { |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 3959 | 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] | 3960 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3961 | } |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3962 | if (resp->xdr.buf->page_len && |
| 3963 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) { |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3964 | WARN_ON_ONCE(1); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3965 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3966 | } |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3967 | xdr_commit_encode(xdr); |
| 3968 | |
| 3969 | maxcount = svc_max_payload(resp->rqstp); |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3970 | maxcount = min_t(unsigned long, maxcount, |
| 3971 | (xdr->buf->buflen - xdr->buf->len)); |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 3972 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3973 | |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3974 | if (file->f_op->splice_read && |
| 3975 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3976 | nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3977 | else |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3978 | nfserr = nfsd4_encode_readv(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3979 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3980 | if (nfserr) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3981 | xdr_truncate_encode(xdr, starting_len); |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3982 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3983 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3986 | static __be32 |
| 3987 | 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] | 3988 | { |
| 3989 | int maxcount; |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 3990 | __be32 wire_count; |
| 3991 | int zero = 0; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3992 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3993 | int length_offset = xdr->buf->len; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3994 | int status; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3995 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3997 | p = xdr_reserve_space(xdr, 4); |
| 3998 | if (!p) |
| 3999 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | maxcount = PAGE_SIZE; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4001 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4002 | p = xdr_reserve_space(xdr, maxcount); |
| 4003 | if (!p) |
J. Bruce Fields | 4e21ac4 | 2014-03-22 15:15:11 -0400 | [diff] [blame] | 4004 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | /* |
Miklos Szeredi | fd4a0edf | 2016-12-09 16:45:04 +0100 | [diff] [blame] | 4006 | * XXX: By default, vfs_readlink() will truncate symlinks if they |
| 4007 | * would overflow the buffer. Is this kosher in NFSv4? If not, one |
| 4008 | * easy fix is: if vfs_readlink() precisely fills the buffer, assume |
| 4009 | * that truncation occurred, and return NFS4ERR_RESOURCE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | */ |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4011 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, |
| 4012 | (char *)p, &maxcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | if (nfserr == nfserr_isdir) |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4014 | nfserr = nfserr_inval; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4015 | if (nfserr) |
| 4016 | goto out_err; |
| 4017 | status = svc_encode_result_payload(readlink->rl_rqstp, length_offset, |
| 4018 | maxcount); |
| 4019 | if (status) { |
| 4020 | nfserr = nfserrno(status); |
| 4021 | goto out_err; |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4024 | wire_count = htonl(maxcount); |
| 4025 | write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4); |
Avi Kivity | 69bbd9c | 2014-06-26 17:23:12 +0300 | [diff] [blame] | 4026 | xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4)); |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4027 | if (maxcount & 3) |
| 4028 | write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, |
| 4029 | &zero, 4 - (maxcount&3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4031 | |
| 4032 | out_err: |
| 4033 | xdr_truncate_encode(xdr, length_offset); |
| 4034 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4037 | static __be32 |
| 4038 | 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] | 4039 | { |
| 4040 | int maxcount; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4041 | int bytes_left; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | loff_t offset; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4043 | __be64 wire_offset; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 4044 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4045 | int starting_len = xdr->buf->len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4046 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4048 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 4049 | if (!p) |
| 4050 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | |
| 4052 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4053 | *p++ = cpu_to_be32(0); |
| 4054 | *p++ = cpu_to_be32(0); |
J. Bruce Fields | 4aea24b | 2014-01-15 15:17:58 -0500 | [diff] [blame] | 4055 | resp->xdr.buf->head[0].iov_len = ((char *)resp->xdr.p) |
| 4056 | - (char *)resp->xdr.buf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | |
| 4058 | /* |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4059 | * Number of bytes left for directory entries allowing for the |
| 4060 | * final 8 bytes of the readdir and a following failed op: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4062 | bytes_left = xdr->buf->buflen - xdr->buf->len |
| 4063 | - COMPOUND_ERR_SLACK_SPACE - 8; |
| 4064 | if (bytes_left < 0) { |
| 4065 | nfserr = nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | goto err_no_verf; |
| 4067 | } |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4068 | maxcount = svc_max_payload(resp->rqstp); |
| 4069 | maxcount = min_t(u32, readdir->rd_maxcount, maxcount); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4070 | /* |
| 4071 | * Note the rfc defines rd_maxcount as the size of the |
| 4072 | * READDIR4resok structure, which includes the verifier above |
| 4073 | * and the 8 bytes encoded at the end of this function: |
| 4074 | */ |
| 4075 | if (maxcount < 16) { |
| 4076 | nfserr = nfserr_toosmall; |
| 4077 | goto err_no_verf; |
| 4078 | } |
| 4079 | maxcount = min_t(int, maxcount-16, bytes_left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4081 | /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ |
| 4082 | if (!readdir->rd_dircount) |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4083 | readdir->rd_dircount = svc_max_payload(resp->rqstp); |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4084 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4085 | readdir->xdr = xdr; |
| 4086 | readdir->rd_maxcount = maxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | readdir->common.err = 0; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4088 | readdir->cookie_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | |
| 4090 | offset = readdir->rd_cookie; |
| 4091 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, |
| 4092 | &offset, |
| 4093 | &readdir->common, nfsd4_encode_dirent); |
| 4094 | if (nfserr == nfs_ok && |
| 4095 | readdir->common.err == nfserr_toosmall && |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4096 | xdr->buf->len == starting_len + 8) { |
| 4097 | /* nothing encoded; which limit did we hit?: */ |
| 4098 | if (maxcount - 16 < bytes_left) |
| 4099 | /* It was the fault of rd_maxcount: */ |
| 4100 | nfserr = nfserr_toosmall; |
| 4101 | else |
| 4102 | /* We ran out of buffer space: */ |
| 4103 | nfserr = nfserr_resource; |
| 4104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | if (nfserr) |
| 4106 | goto err_no_verf; |
| 4107 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4108 | if (readdir->cookie_offset) { |
| 4109 | wire_offset = cpu_to_be64(offset); |
| 4110 | write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, |
| 4111 | &wire_offset, 8); |
| 4112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4114 | p = xdr_reserve_space(xdr, 8); |
| 4115 | if (!p) { |
| 4116 | WARN_ON_ONCE(1); |
| 4117 | goto err_no_verf; |
| 4118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | *p++ = 0; /* no more entries */ |
| 4120 | *p++ = htonl(readdir->common.err == nfserr_eof); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | |
| 4122 | return 0; |
| 4123 | err_no_verf: |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4124 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | return nfserr; |
| 4126 | } |
| 4127 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4128 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4129 | 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] | 4130 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4131 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4132 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4134 | p = xdr_reserve_space(xdr, 20); |
| 4135 | if (!p) |
| 4136 | return nfserr_resource; |
| 4137 | p = encode_cinfo(p, &remove->rm_cinfo); |
| 4138 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4141 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4142 | 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] | 4143 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4144 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4145 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4147 | p = xdr_reserve_space(xdr, 40); |
| 4148 | if (!p) |
| 4149 | return nfserr_resource; |
| 4150 | p = encode_cinfo(p, &rename->rn_sinfo); |
| 4151 | p = encode_cinfo(p, &rename->rn_tinfo); |
| 4152 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4155 | static __be32 |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4156 | nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4157 | { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4158 | u32 i, nflavs, supported; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4159 | struct exp_flavor_info *flavs; |
| 4160 | struct exp_flavor_info def_flavs[2]; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4161 | __be32 *p, *flavorsp; |
| 4162 | static bool report = true; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4163 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4164 | if (exp->ex_nflavors) { |
| 4165 | flavs = exp->ex_flavors; |
| 4166 | nflavs = exp->ex_nflavors; |
| 4167 | } else { /* Handling of some defaults in absence of real secinfo: */ |
| 4168 | flavs = def_flavs; |
| 4169 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { |
| 4170 | nflavs = 2; |
| 4171 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; |
| 4172 | flavs[1].pseudoflavor = RPC_AUTH_NULL; |
| 4173 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { |
| 4174 | nflavs = 1; |
| 4175 | flavs[0].pseudoflavor |
| 4176 | = svcauth_gss_flavor(exp->ex_client); |
| 4177 | } else { |
| 4178 | nflavs = 1; |
| 4179 | flavs[0].pseudoflavor |
| 4180 | = exp->ex_client->flavour->flavour; |
| 4181 | } |
| 4182 | } |
| 4183 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4184 | supported = 0; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4185 | p = xdr_reserve_space(xdr, 4); |
| 4186 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4187 | return nfserr_resource; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4188 | flavorsp = p++; /* to be backfilled later */ |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4189 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4190 | for (i = 0; i < nflavs; i++) { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4191 | rpc_authflavor_t pf = flavs[i].pseudoflavor; |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4192 | struct rpcsec_gss_info info; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4193 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4194 | if (rpcauth_get_gssinfo(pf, &info) == 0) { |
| 4195 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4196 | p = xdr_reserve_space(xdr, 4 + 4 + |
| 4197 | XDR_LEN(info.oid.len) + 4 + 4); |
| 4198 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4199 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4200 | *p++ = cpu_to_be32(RPC_AUTH_GSS); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4201 | p = xdr_encode_opaque(p, info.oid.data, info.oid.len); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4202 | *p++ = cpu_to_be32(info.qop); |
| 4203 | *p++ = cpu_to_be32(info.service); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4204 | } else if (pf < RPC_AUTH_MAXFLAVOR) { |
| 4205 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4206 | p = xdr_reserve_space(xdr, 4); |
| 4207 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4208 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4209 | *p++ = cpu_to_be32(pf); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4210 | } else { |
| 4211 | if (report) |
| 4212 | pr_warn("NFS: SECINFO: security flavor %u " |
| 4213 | "is not supported\n", pf); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4214 | } |
| 4215 | } |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4216 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4217 | if (nflavs != supported) |
| 4218 | report = false; |
| 4219 | *flavorsp = htonl(supported); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4220 | return 0; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4223 | static __be32 |
| 4224 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4225 | struct nfsd4_secinfo *secinfo) |
| 4226 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4227 | struct xdr_stream *xdr = &resp->xdr; |
| 4228 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4229 | return nfsd4_do_encode_secinfo(xdr, secinfo->si_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | static __be32 |
| 4233 | nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4234 | struct nfsd4_secinfo_no_name *secinfo) |
| 4235 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4236 | struct xdr_stream *xdr = &resp->xdr; |
| 4237 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4238 | return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4239 | } |
| 4240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | /* |
| 4242 | * The SETATTR encode routine is special -- it always encodes a bitmap, |
| 4243 | * regardless of the error status. |
| 4244 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4245 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4246 | 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] | 4247 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4248 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4249 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4251 | p = xdr_reserve_space(xdr, 16); |
| 4252 | if (!p) |
| 4253 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | if (nfserr) { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4255 | *p++ = cpu_to_be32(3); |
| 4256 | *p++ = cpu_to_be32(0); |
| 4257 | *p++ = cpu_to_be32(0); |
| 4258 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | } |
| 4260 | else { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4261 | *p++ = cpu_to_be32(3); |
| 4262 | *p++ = cpu_to_be32(setattr->sa_bmval[0]); |
| 4263 | *p++ = cpu_to_be32(setattr->sa_bmval[1]); |
| 4264 | *p++ = cpu_to_be32(setattr->sa_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4266 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | } |
| 4268 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4269 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4270 | 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] | 4271 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4272 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4273 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | |
| 4275 | if (!nfserr) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4276 | p = xdr_reserve_space(xdr, 8 + NFS4_VERIFIER_SIZE); |
| 4277 | if (!p) |
| 4278 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4279 | p = xdr_encode_opaque_fixed(p, &scd->se_clientid, 8); |
| 4280 | p = xdr_encode_opaque_fixed(p, &scd->se_confirm, |
| 4281 | NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | } |
| 4283 | else if (nfserr == nfserr_clid_inuse) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4284 | p = xdr_reserve_space(xdr, 8); |
| 4285 | if (!p) |
| 4286 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4287 | *p++ = cpu_to_be32(0); |
| 4288 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4290 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | } |
| 4292 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4293 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4294 | 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] | 4295 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4296 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4297 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4299 | p = xdr_reserve_space(xdr, 16); |
| 4300 | if (!p) |
| 4301 | return nfserr_resource; |
| 4302 | *p++ = cpu_to_be32(write->wr_bytes_written); |
| 4303 | *p++ = cpu_to_be32(write->wr_how_written); |
| 4304 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4305 | NFS4_VERIFIER_SIZE); |
| 4306 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | } |
| 4308 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4309 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4310 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4311 | struct nfsd4_exchange_id *exid) |
| 4312 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4313 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4314 | __be32 *p; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4315 | char *major_id; |
| 4316 | char *server_scope; |
| 4317 | int major_id_sz; |
| 4318 | int server_scope_sz; |
| 4319 | uint64_t minor_id = 0; |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4320 | 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] | 4321 | |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4322 | major_id = nn->nfsd_name; |
| 4323 | major_id_sz = strlen(nn->nfsd_name); |
| 4324 | server_scope = nn->nfsd_name; |
| 4325 | server_scope_sz = strlen(nn->nfsd_name); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4326 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4327 | p = xdr_reserve_space(xdr, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4328 | 8 /* eir_clientid */ + |
| 4329 | 4 /* eir_sequenceid */ + |
| 4330 | 4 /* eir_flags */ + |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4331 | 4 /* spr_how */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4332 | if (!p) |
| 4333 | return nfserr_resource; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4334 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4335 | p = xdr_encode_opaque_fixed(p, &exid->clientid, 8); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4336 | *p++ = cpu_to_be32(exid->seqid); |
| 4337 | *p++ = cpu_to_be32(exid->flags); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4338 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4339 | *p++ = cpu_to_be32(exid->spa_how); |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4340 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4341 | switch (exid->spa_how) { |
| 4342 | case SP4_NONE: |
| 4343 | break; |
| 4344 | case SP4_MACH_CRED: |
| 4345 | /* spo_must_enforce bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4346 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4347 | exid->spo_must_enforce[0], |
| 4348 | exid->spo_must_enforce[1], |
| 4349 | exid->spo_must_enforce[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4350 | if (nfserr) |
| 4351 | return nfserr; |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4352 | /* spo_must_allow bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4353 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4354 | exid->spo_must_allow[0], |
| 4355 | exid->spo_must_allow[1], |
| 4356 | exid->spo_must_allow[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4357 | if (nfserr) |
| 4358 | return nfserr; |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4359 | break; |
| 4360 | default: |
| 4361 | WARN_ON_ONCE(1); |
| 4362 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4363 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4364 | p = xdr_reserve_space(xdr, |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4365 | 8 /* so_minor_id */ + |
| 4366 | 4 /* so_major_id.len */ + |
| 4367 | (XDR_QUADLEN(major_id_sz) * 4) + |
| 4368 | 4 /* eir_server_scope.len */ + |
| 4369 | (XDR_QUADLEN(server_scope_sz) * 4) + |
| 4370 | 4 /* eir_server_impl_id.count (0) */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4371 | if (!p) |
| 4372 | return nfserr_resource; |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4373 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4374 | /* The server_owner struct */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 4375 | p = xdr_encode_hyper(p, minor_id); /* Minor id */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4376 | /* major id */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4377 | p = xdr_encode_opaque(p, major_id, major_id_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4378 | |
| 4379 | /* Server scope */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4380 | p = xdr_encode_opaque(p, server_scope, server_scope_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4381 | |
| 4382 | /* Implementation id */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4383 | *p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4384 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4388 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4389 | struct nfsd4_create_session *sess) |
| 4390 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4391 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4392 | __be32 *p; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4393 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4394 | p = xdr_reserve_space(xdr, 24); |
| 4395 | if (!p) |
| 4396 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4397 | p = xdr_encode_opaque_fixed(p, sess->sessionid.data, |
| 4398 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4399 | *p++ = cpu_to_be32(sess->seqid); |
| 4400 | *p++ = cpu_to_be32(sess->flags); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4401 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4402 | p = xdr_reserve_space(xdr, 28); |
| 4403 | if (!p) |
| 4404 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4405 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4406 | *p++ = cpu_to_be32(sess->fore_channel.maxreq_sz); |
| 4407 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_sz); |
| 4408 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_cached); |
| 4409 | *p++ = cpu_to_be32(sess->fore_channel.maxops); |
| 4410 | *p++ = cpu_to_be32(sess->fore_channel.maxreqs); |
| 4411 | *p++ = cpu_to_be32(sess->fore_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4412 | |
| 4413 | if (sess->fore_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4414 | p = xdr_reserve_space(xdr, 4); |
| 4415 | if (!p) |
| 4416 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4417 | *p++ = cpu_to_be32(sess->fore_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4418 | } |
| 4419 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4420 | p = xdr_reserve_space(xdr, 28); |
| 4421 | if (!p) |
| 4422 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4423 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4424 | *p++ = cpu_to_be32(sess->back_channel.maxreq_sz); |
| 4425 | *p++ = cpu_to_be32(sess->back_channel.maxresp_sz); |
| 4426 | *p++ = cpu_to_be32(sess->back_channel.maxresp_cached); |
| 4427 | *p++ = cpu_to_be32(sess->back_channel.maxops); |
| 4428 | *p++ = cpu_to_be32(sess->back_channel.maxreqs); |
| 4429 | *p++ = cpu_to_be32(sess->back_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4430 | |
| 4431 | if (sess->back_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4432 | p = xdr_reserve_space(xdr, 4); |
| 4433 | if (!p) |
| 4434 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4435 | *p++ = cpu_to_be32(sess->back_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4436 | } |
| 4437 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4441 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4442 | struct nfsd4_sequence *seq) |
| 4443 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4444 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4445 | __be32 *p; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4446 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4447 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20); |
| 4448 | if (!p) |
| 4449 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4450 | p = xdr_encode_opaque_fixed(p, seq->sessionid.data, |
| 4451 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4452 | *p++ = cpu_to_be32(seq->seqid); |
| 4453 | *p++ = cpu_to_be32(seq->slotid); |
J. Bruce Fields | b7d7ca3 | 2011-08-31 15:39:30 -0400 | [diff] [blame] | 4454 | /* Note slotid's are numbered from zero: */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4455 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */ |
| 4456 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */ |
| 4457 | *p++ = cpu_to_be32(seq->status_flags); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4458 | |
J. Bruce Fields | f523601 | 2014-03-21 17:57:57 -0400 | [diff] [blame] | 4459 | resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */ |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4460 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4461 | } |
| 4462 | |
J. Bruce Fields | 2355c59 | 2012-04-25 16:56:22 -0400 | [diff] [blame] | 4463 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4464 | nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4465 | struct nfsd4_test_stateid *test_stateid) |
| 4466 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4467 | struct xdr_stream *xdr = &resp->xdr; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4468 | struct nfsd4_test_stateid_id *stateid, *next; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4469 | __be32 *p; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4470 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4471 | p = xdr_reserve_space(xdr, 4 + (4 * test_stateid->ts_num_ids)); |
| 4472 | if (!p) |
| 4473 | return nfserr_resource; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4474 | *p++ = htonl(test_stateid->ts_num_ids); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4475 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4476 | 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] | 4477 | *p++ = stateid->ts_id_status; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4478 | } |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4479 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4480 | return 0; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4481 | } |
| 4482 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4483 | #ifdef CONFIG_NFSD_PNFS |
| 4484 | static __be32 |
| 4485 | nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4486 | struct nfsd4_getdeviceinfo *gdev) |
| 4487 | { |
| 4488 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4489 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4490 | u32 starting_len = xdr->buf->len, needed_len; |
| 4491 | __be32 *p; |
| 4492 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4493 | p = xdr_reserve_space(xdr, 4); |
| 4494 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4495 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4496 | |
| 4497 | *p++ = cpu_to_be32(gdev->gd_layout_type); |
| 4498 | |
| 4499 | /* If maxcount is 0 then just update notifications */ |
| 4500 | if (gdev->gd_maxcount != 0) { |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4501 | ops = nfsd4_layout_ops[gdev->gd_layout_type]; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4502 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); |
| 4503 | if (nfserr) { |
| 4504 | /* |
| 4505 | * We don't bother to burden the layout drivers with |
| 4506 | * enforcing gd_maxcount, just tell the client to |
| 4507 | * come back with a bigger buffer if it's not enough. |
| 4508 | */ |
| 4509 | if (xdr->buf->len + 4 > gdev->gd_maxcount) |
| 4510 | goto toosmall; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4511 | return nfserr; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4515 | if (gdev->gd_notify_types) { |
| 4516 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4517 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4518 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4519 | *p++ = cpu_to_be32(1); /* bitmap length */ |
| 4520 | *p++ = cpu_to_be32(gdev->gd_notify_types); |
| 4521 | } else { |
| 4522 | p = xdr_reserve_space(xdr, 4); |
| 4523 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4524 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4525 | *p++ = 0; |
| 4526 | } |
| 4527 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4528 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4529 | toosmall: |
| 4530 | dprintk("%s: maxcount too small\n", __func__); |
| 4531 | needed_len = xdr->buf->len + 4 /* notifications */; |
| 4532 | xdr_truncate_encode(xdr, starting_len); |
| 4533 | p = xdr_reserve_space(xdr, 4); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4534 | if (!p) |
| 4535 | return nfserr_resource; |
| 4536 | *p++ = cpu_to_be32(needed_len); |
| 4537 | return nfserr_toosmall; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | static __be32 |
| 4541 | nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4542 | struct nfsd4_layoutget *lgp) |
| 4543 | { |
| 4544 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4545 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4546 | __be32 *p; |
| 4547 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4548 | p = xdr_reserve_space(xdr, 36 + sizeof(stateid_opaque_t)); |
| 4549 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4550 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4551 | |
| 4552 | *p++ = cpu_to_be32(1); /* we always set return-on-close */ |
| 4553 | *p++ = cpu_to_be32(lgp->lg_sid.si_generation); |
| 4554 | p = xdr_encode_opaque_fixed(p, &lgp->lg_sid.si_opaque, |
| 4555 | sizeof(stateid_opaque_t)); |
| 4556 | |
| 4557 | *p++ = cpu_to_be32(1); /* we always return a single layout */ |
| 4558 | p = xdr_encode_hyper(p, lgp->lg_seg.offset); |
| 4559 | p = xdr_encode_hyper(p, lgp->lg_seg.length); |
| 4560 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); |
| 4561 | *p++ = cpu_to_be32(lgp->lg_layout_type); |
| 4562 | |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4563 | ops = nfsd4_layout_ops[lgp->lg_layout_type]; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4564 | return ops->encode_layoutget(xdr, lgp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4565 | } |
| 4566 | |
| 4567 | static __be32 |
| 4568 | nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4569 | struct nfsd4_layoutcommit *lcp) |
| 4570 | { |
| 4571 | struct xdr_stream *xdr = &resp->xdr; |
| 4572 | __be32 *p; |
| 4573 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4574 | p = xdr_reserve_space(xdr, 4); |
| 4575 | if (!p) |
| 4576 | return nfserr_resource; |
| 4577 | *p++ = cpu_to_be32(lcp->lc_size_chg); |
| 4578 | if (lcp->lc_size_chg) { |
| 4579 | p = xdr_reserve_space(xdr, 8); |
| 4580 | if (!p) |
| 4581 | return nfserr_resource; |
| 4582 | p = xdr_encode_hyper(p, lcp->lc_newsize); |
| 4583 | } |
| 4584 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4585 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | static __be32 |
| 4589 | nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4590 | struct nfsd4_layoutreturn *lrp) |
| 4591 | { |
| 4592 | struct xdr_stream *xdr = &resp->xdr; |
| 4593 | __be32 *p; |
| 4594 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4595 | p = xdr_reserve_space(xdr, 4); |
| 4596 | if (!p) |
| 4597 | return nfserr_resource; |
| 4598 | *p++ = cpu_to_be32(lrp->lrs_present); |
| 4599 | if (lrp->lrs_present) |
Kinglong Mee | 376675d | 2015-03-22 22:17:10 +0800 | [diff] [blame] | 4600 | return nfsd4_encode_stateid(xdr, &lrp->lr_sid); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4601 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4602 | } |
| 4603 | #endif /* CONFIG_NFSD_PNFS */ |
| 4604 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4605 | static __be32 |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4606 | nfsd42_encode_write_res(struct nfsd4_compoundres *resp, |
| 4607 | struct nfsd42_write_res *write, bool sync) |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4608 | { |
| 4609 | __be32 *p; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4610 | p = xdr_reserve_space(&resp->xdr, 4); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4611 | if (!p) |
| 4612 | return nfserr_resource; |
| 4613 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4614 | if (sync) |
| 4615 | *p++ = cpu_to_be32(0); |
| 4616 | else { |
| 4617 | __be32 nfserr; |
| 4618 | *p++ = cpu_to_be32(1); |
| 4619 | nfserr = nfsd4_encode_stateid(&resp->xdr, &write->cb_stateid); |
| 4620 | if (nfserr) |
| 4621 | return nfserr; |
| 4622 | } |
| 4623 | p = xdr_reserve_space(&resp->xdr, 8 + 4 + NFS4_VERIFIER_SIZE); |
| 4624 | if (!p) |
| 4625 | return nfserr_resource; |
| 4626 | |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4627 | p = xdr_encode_hyper(p, write->wr_bytes_written); |
| 4628 | *p++ = cpu_to_be32(write->wr_stable_how); |
| 4629 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4630 | NFS4_VERIFIER_SIZE); |
| 4631 | return nfs_ok; |
| 4632 | } |
| 4633 | |
| 4634 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4635 | nfsd42_encode_nl4_server(struct nfsd4_compoundres *resp, struct nl4_server *ns) |
| 4636 | { |
| 4637 | struct xdr_stream *xdr = &resp->xdr; |
| 4638 | struct nfs42_netaddr *addr; |
| 4639 | __be32 *p; |
| 4640 | |
| 4641 | p = xdr_reserve_space(xdr, 4); |
| 4642 | *p++ = cpu_to_be32(ns->nl4_type); |
| 4643 | |
| 4644 | switch (ns->nl4_type) { |
| 4645 | case NL4_NETADDR: |
| 4646 | addr = &ns->u.nl4_addr; |
| 4647 | |
| 4648 | /* netid_len, netid, uaddr_len, uaddr (port included |
| 4649 | * in RPCBIND_MAXUADDRLEN) |
| 4650 | */ |
| 4651 | p = xdr_reserve_space(xdr, |
| 4652 | 4 /* netid len */ + |
| 4653 | (XDR_QUADLEN(addr->netid_len) * 4) + |
| 4654 | 4 /* uaddr len */ + |
| 4655 | (XDR_QUADLEN(addr->addr_len) * 4)); |
| 4656 | if (!p) |
| 4657 | return nfserr_resource; |
| 4658 | |
| 4659 | *p++ = cpu_to_be32(addr->netid_len); |
| 4660 | p = xdr_encode_opaque_fixed(p, addr->netid, |
| 4661 | addr->netid_len); |
| 4662 | *p++ = cpu_to_be32(addr->addr_len); |
| 4663 | p = xdr_encode_opaque_fixed(p, addr->addr, |
| 4664 | addr->addr_len); |
| 4665 | break; |
| 4666 | default: |
| 4667 | WARN_ON_ONCE(ns->nl4_type != NL4_NETADDR); |
| 4668 | return nfserr_inval; |
| 4669 | } |
| 4670 | |
| 4671 | return 0; |
| 4672 | } |
| 4673 | |
| 4674 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4675 | nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4676 | struct nfsd4_copy *copy) |
| 4677 | { |
| 4678 | __be32 *p; |
| 4679 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4680 | nfserr = nfsd42_encode_write_res(resp, ©->cp_res, |
| 4681 | copy->cp_synchronous); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4682 | if (nfserr) |
| 4683 | return nfserr; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4684 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4685 | p = xdr_reserve_space(&resp->xdr, 4 + 4); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 4686 | *p++ = xdr_one; /* cr_consecutive */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4687 | *p++ = cpu_to_be32(copy->cp_synchronous); |
| 4688 | return 0; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4692 | nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4693 | struct nfsd4_offload_status *os) |
| 4694 | { |
| 4695 | struct xdr_stream *xdr = &resp->xdr; |
| 4696 | __be32 *p; |
| 4697 | |
| 4698 | p = xdr_reserve_space(xdr, 8 + 4); |
| 4699 | if (!p) |
| 4700 | return nfserr_resource; |
| 4701 | p = xdr_encode_hyper(p, os->count); |
| 4702 | *p++ = cpu_to_be32(0); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4703 | return nfserr; |
| 4704 | } |
| 4705 | |
| 4706 | static __be32 |
| 4707 | nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, |
| 4708 | struct nfsd4_read *read, |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4709 | unsigned long *maxcount, u32 *eof, |
| 4710 | loff_t *pos) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4711 | { |
| 4712 | struct xdr_stream *xdr = &resp->xdr; |
| 4713 | struct file *file = read->rd_nf->nf_file; |
| 4714 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4715 | loff_t hole_pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4716 | __be32 nfserr; |
| 4717 | __be32 *p, tmp; |
| 4718 | __be64 tmp64; |
| 4719 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4720 | hole_pos = pos ? *pos : vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4721 | if (hole_pos > read->rd_offset) |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4722 | *maxcount = min_t(unsigned long, *maxcount, hole_pos - read->rd_offset); |
| 4723 | *maxcount = min_t(unsigned long, *maxcount, (xdr->buf->buflen - xdr->buf->len)); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4724 | |
| 4725 | /* Content type, offset, byte count */ |
| 4726 | p = xdr_reserve_space(xdr, 4 + 8 + 4); |
| 4727 | if (!p) |
| 4728 | return nfserr_resource; |
| 4729 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4730 | 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] | 4731 | if (read->rd_vlen < 0) |
| 4732 | return nfserr_resource; |
| 4733 | |
| 4734 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4735 | resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4736 | if (nfserr) |
| 4737 | return nfserr; |
| 4738 | |
| 4739 | tmp = htonl(NFS4_CONTENT_DATA); |
| 4740 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4741 | tmp64 = cpu_to_be64(read->rd_offset); |
| 4742 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp64, 8); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4743 | tmp = htonl(*maxcount); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4744 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp, 4); |
| 4745 | return nfs_ok; |
| 4746 | } |
| 4747 | |
| 4748 | static __be32 |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4749 | nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, |
| 4750 | struct nfsd4_read *read, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4751 | unsigned long *maxcount, u32 *eof) |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4752 | { |
| 4753 | struct file *file = read->rd_nf->nf_file; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4754 | loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4755 | loff_t f_size = i_size_read(file_inode(file)); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4756 | unsigned long count; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4757 | __be32 *p; |
| 4758 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4759 | if (data_pos == -ENXIO) |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4760 | data_pos = f_size; |
| 4761 | else if (data_pos <= read->rd_offset || (data_pos < f_size && data_pos % PAGE_SIZE)) |
| 4762 | return nfsd4_encode_read_plus_data(resp, read, maxcount, eof, &f_size); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4763 | count = data_pos - read->rd_offset; |
| 4764 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4765 | /* Content type, offset, byte count */ |
| 4766 | p = xdr_reserve_space(&resp->xdr, 4 + 8 + 8); |
| 4767 | if (!p) |
| 4768 | return nfserr_resource; |
| 4769 | |
| 4770 | *p++ = htonl(NFS4_CONTENT_HOLE); |
| 4771 | p = xdr_encode_hyper(p, read->rd_offset); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4772 | p = xdr_encode_hyper(p, count); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4773 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4774 | *eof = (read->rd_offset + count) >= f_size; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4775 | *maxcount = min_t(unsigned long, count, *maxcount); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4776 | return nfs_ok; |
| 4777 | } |
| 4778 | |
| 4779 | static __be32 |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4780 | nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4781 | struct nfsd4_read *read) |
| 4782 | { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4783 | unsigned long maxcount, count; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4784 | struct xdr_stream *xdr = &resp->xdr; |
| 4785 | struct file *file; |
| 4786 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4787 | int last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4788 | int segments = 0; |
| 4789 | __be32 *p, tmp; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4790 | bool is_data; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4791 | loff_t pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4792 | u32 eof; |
| 4793 | |
| 4794 | if (nfserr) |
| 4795 | return nfserr; |
| 4796 | file = read->rd_nf->nf_file; |
| 4797 | |
| 4798 | /* eof flag, segment count */ |
| 4799 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4800 | if (!p) |
| 4801 | return nfserr_resource; |
| 4802 | xdr_commit_encode(xdr); |
| 4803 | |
| 4804 | maxcount = svc_max_payload(resp->rqstp); |
| 4805 | maxcount = min_t(unsigned long, maxcount, |
| 4806 | (xdr->buf->buflen - xdr->buf->len)); |
| 4807 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4808 | count = maxcount; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4809 | |
| 4810 | eof = read->rd_offset >= i_size_read(file_inode(file)); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4811 | if (eof) |
| 4812 | goto out; |
| 4813 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4814 | pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
| 4815 | is_data = pos > read->rd_offset; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4816 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4817 | while (count > 0 && !eof) { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4818 | maxcount = count; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4819 | if (is_data) |
| 4820 | nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof, |
| 4821 | segments == 0 ? &pos : NULL); |
| 4822 | else |
| 4823 | nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4824 | if (nfserr) |
| 4825 | goto out; |
| 4826 | count -= maxcount; |
| 4827 | read->rd_offset += maxcount; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4828 | is_data = !is_data; |
| 4829 | last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4830 | segments++; |
| 4831 | } |
| 4832 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4833 | out: |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4834 | if (nfserr && segments == 0) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4835 | xdr_truncate_encode(xdr, starting_len); |
| 4836 | else { |
| 4837 | tmp = htonl(eof); |
| 4838 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4839 | tmp = htonl(segments); |
| 4840 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4841 | if (nfserr) { |
| 4842 | xdr_truncate_encode(xdr, last_segment); |
| 4843 | nfserr = nfs_ok; |
| 4844 | } |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4845 | } |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4846 | |
| 4847 | return nfserr; |
| 4848 | } |
| 4849 | |
| 4850 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4851 | nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4852 | struct nfsd4_copy_notify *cn) |
| 4853 | { |
| 4854 | struct xdr_stream *xdr = &resp->xdr; |
| 4855 | __be32 *p; |
| 4856 | |
| 4857 | if (nfserr) |
| 4858 | return nfserr; |
| 4859 | |
| 4860 | /* 8 sec, 4 nsec */ |
| 4861 | p = xdr_reserve_space(xdr, 12); |
| 4862 | if (!p) |
| 4863 | return nfserr_resource; |
| 4864 | |
| 4865 | /* cnr_lease_time */ |
| 4866 | p = xdr_encode_hyper(p, cn->cpn_sec); |
| 4867 | *p++ = cpu_to_be32(cn->cpn_nsec); |
| 4868 | |
| 4869 | /* cnr_stateid */ |
| 4870 | nfserr = nfsd4_encode_stateid(xdr, &cn->cpn_cnr_stateid); |
| 4871 | if (nfserr) |
| 4872 | return nfserr; |
| 4873 | |
| 4874 | /* cnr_src.nl_nsvr */ |
| 4875 | p = xdr_reserve_space(xdr, 4); |
| 4876 | if (!p) |
| 4877 | return nfserr_resource; |
| 4878 | |
| 4879 | *p++ = cpu_to_be32(1); |
| 4880 | |
| 4881 | return nfsd42_encode_nl4_server(resp, &cn->cpn_src); |
| 4882 | } |
| 4883 | |
| 4884 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4885 | nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4886 | struct nfsd4_seek *seek) |
| 4887 | { |
| 4888 | __be32 *p; |
| 4889 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4890 | p = xdr_reserve_space(&resp->xdr, 4 + 8); |
| 4891 | *p++ = cpu_to_be32(seek->seek_eof); |
| 4892 | p = xdr_encode_hyper(p, seek->seek_pos); |
| 4893 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4894 | return 0; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | static __be32 |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4898 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
| 4899 | { |
| 4900 | return nfserr; |
| 4901 | } |
| 4902 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4903 | /* |
| 4904 | * Encode kmalloc-ed buffer in to XDR stream. |
| 4905 | */ |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 4906 | static __be32 |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4907 | nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen) |
| 4908 | { |
| 4909 | u32 cplen; |
| 4910 | __be32 *p; |
| 4911 | |
| 4912 | cplen = min_t(unsigned long, buflen, |
| 4913 | ((void *)xdr->end - (void *)xdr->p)); |
| 4914 | p = xdr_reserve_space(xdr, cplen); |
| 4915 | if (!p) |
| 4916 | return nfserr_resource; |
| 4917 | |
| 4918 | memcpy(p, buf, cplen); |
| 4919 | buf += cplen; |
| 4920 | buflen -= cplen; |
| 4921 | |
| 4922 | while (buflen) { |
| 4923 | cplen = min_t(u32, buflen, PAGE_SIZE); |
| 4924 | p = xdr_reserve_space(xdr, cplen); |
| 4925 | if (!p) |
| 4926 | return nfserr_resource; |
| 4927 | |
| 4928 | memcpy(p, buf, cplen); |
| 4929 | |
| 4930 | if (cplen < PAGE_SIZE) { |
| 4931 | /* |
| 4932 | * We're done, with a length that wasn't page |
| 4933 | * aligned, so possibly not word aligned. Pad |
| 4934 | * any trailing bytes with 0. |
| 4935 | */ |
| 4936 | xdr_encode_opaque_fixed(p, NULL, cplen); |
| 4937 | break; |
| 4938 | } |
| 4939 | |
| 4940 | buflen -= PAGE_SIZE; |
| 4941 | buf += PAGE_SIZE; |
| 4942 | } |
| 4943 | |
| 4944 | return 0; |
| 4945 | } |
| 4946 | |
| 4947 | static __be32 |
| 4948 | nfsd4_encode_getxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4949 | struct nfsd4_getxattr *getxattr) |
| 4950 | { |
| 4951 | struct xdr_stream *xdr = &resp->xdr; |
| 4952 | __be32 *p, err; |
| 4953 | |
| 4954 | p = xdr_reserve_space(xdr, 4); |
| 4955 | if (!p) |
| 4956 | return nfserr_resource; |
| 4957 | |
| 4958 | *p = cpu_to_be32(getxattr->getxa_len); |
| 4959 | |
| 4960 | if (getxattr->getxa_len == 0) |
| 4961 | return 0; |
| 4962 | |
| 4963 | err = nfsd4_vbuf_to_stream(xdr, getxattr->getxa_buf, |
| 4964 | getxattr->getxa_len); |
| 4965 | |
| 4966 | kvfree(getxattr->getxa_buf); |
| 4967 | |
| 4968 | return err; |
| 4969 | } |
| 4970 | |
| 4971 | static __be32 |
| 4972 | nfsd4_encode_setxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4973 | struct nfsd4_setxattr *setxattr) |
| 4974 | { |
| 4975 | struct xdr_stream *xdr = &resp->xdr; |
| 4976 | __be32 *p; |
| 4977 | |
| 4978 | p = xdr_reserve_space(xdr, 20); |
| 4979 | if (!p) |
| 4980 | return nfserr_resource; |
| 4981 | |
| 4982 | encode_cinfo(p, &setxattr->setxa_cinfo); |
| 4983 | |
| 4984 | return 0; |
| 4985 | } |
| 4986 | |
| 4987 | /* |
| 4988 | * See if there are cookie values that can be rejected outright. |
| 4989 | */ |
| 4990 | static __be32 |
| 4991 | nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs, |
| 4992 | u32 *offsetp) |
| 4993 | { |
| 4994 | u64 cookie = listxattrs->lsxa_cookie; |
| 4995 | |
| 4996 | /* |
| 4997 | * If the cookie is larger than the maximum number we can fit |
| 4998 | * in either the buffer we just got back from vfs_listxattr, or, |
| 4999 | * XDR-encoded, in the return buffer, it's invalid. |
| 5000 | */ |
| 5001 | if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2)) |
| 5002 | return nfserr_badcookie; |
| 5003 | |
| 5004 | if (cookie > (listxattrs->lsxa_maxcount / |
| 5005 | (XDR_QUADLEN(XATTR_USER_PREFIX_LEN + 2) + 4))) |
| 5006 | return nfserr_badcookie; |
| 5007 | |
| 5008 | *offsetp = (u32)cookie; |
| 5009 | return 0; |
| 5010 | } |
| 5011 | |
| 5012 | static __be32 |
| 5013 | nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5014 | struct nfsd4_listxattrs *listxattrs) |
| 5015 | { |
| 5016 | struct xdr_stream *xdr = &resp->xdr; |
| 5017 | u32 cookie_offset, count_offset, eof; |
| 5018 | u32 left, xdrleft, slen, count; |
| 5019 | u32 xdrlen, offset; |
| 5020 | u64 cookie; |
| 5021 | char *sp; |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5022 | __be32 status, tmp; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5023 | __be32 *p; |
| 5024 | u32 nuser; |
| 5025 | |
| 5026 | eof = 1; |
| 5027 | |
| 5028 | status = nfsd4_listxattr_validate_cookie(listxattrs, &offset); |
| 5029 | if (status) |
| 5030 | goto out; |
| 5031 | |
| 5032 | /* |
| 5033 | * Reserve space for the cookie and the name array count. Record |
| 5034 | * the offsets to save them later. |
| 5035 | */ |
| 5036 | cookie_offset = xdr->buf->len; |
| 5037 | count_offset = cookie_offset + 8; |
| 5038 | p = xdr_reserve_space(xdr, 12); |
| 5039 | if (!p) { |
| 5040 | status = nfserr_resource; |
| 5041 | goto out; |
| 5042 | } |
| 5043 | |
| 5044 | count = 0; |
| 5045 | left = listxattrs->lsxa_len; |
| 5046 | sp = listxattrs->lsxa_buf; |
| 5047 | nuser = 0; |
| 5048 | |
| 5049 | xdrleft = listxattrs->lsxa_maxcount; |
| 5050 | |
| 5051 | while (left > 0 && xdrleft > 0) { |
| 5052 | slen = strlen(sp); |
| 5053 | |
| 5054 | /* |
Alex Dewar | 4cce11fa | 2020-08-17 18:51:26 +0100 | [diff] [blame] | 5055 | * 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] | 5056 | */ |
| 5057 | if (strncmp(sp, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) |
| 5058 | goto contloop; |
| 5059 | |
| 5060 | slen -= XATTR_USER_PREFIX_LEN; |
| 5061 | xdrlen = 4 + ((slen + 3) & ~3); |
| 5062 | if (xdrlen > xdrleft) { |
| 5063 | if (count == 0) { |
| 5064 | /* |
| 5065 | * Can't even fit the first attribute name. |
| 5066 | */ |
| 5067 | status = nfserr_toosmall; |
| 5068 | goto out; |
| 5069 | } |
| 5070 | eof = 0; |
| 5071 | goto wreof; |
| 5072 | } |
| 5073 | |
| 5074 | left -= XATTR_USER_PREFIX_LEN; |
| 5075 | sp += XATTR_USER_PREFIX_LEN; |
| 5076 | if (nuser++ < offset) |
| 5077 | goto contloop; |
| 5078 | |
| 5079 | |
| 5080 | p = xdr_reserve_space(xdr, xdrlen); |
| 5081 | if (!p) { |
| 5082 | status = nfserr_resource; |
| 5083 | goto out; |
| 5084 | } |
| 5085 | |
Alex Dewar | e2a1840 | 2020-08-12 15:12:51 +0100 | [diff] [blame] | 5086 | xdr_encode_opaque(p, sp, slen); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5087 | |
| 5088 | xdrleft -= xdrlen; |
| 5089 | count++; |
| 5090 | contloop: |
| 5091 | sp += slen + 1; |
| 5092 | left -= slen + 1; |
| 5093 | } |
| 5094 | |
| 5095 | /* |
| 5096 | * If there were user attributes to copy, but we didn't copy |
| 5097 | * any, the offset was too large (e.g. the cookie was invalid). |
| 5098 | */ |
| 5099 | if (nuser > 0 && count == 0) { |
| 5100 | status = nfserr_badcookie; |
| 5101 | goto out; |
| 5102 | } |
| 5103 | |
| 5104 | wreof: |
| 5105 | p = xdr_reserve_space(xdr, 4); |
| 5106 | if (!p) { |
| 5107 | status = nfserr_resource; |
| 5108 | goto out; |
| 5109 | } |
| 5110 | *p = cpu_to_be32(eof); |
| 5111 | |
| 5112 | cookie = offset + count; |
| 5113 | |
| 5114 | write_bytes_to_xdr_buf(xdr->buf, cookie_offset, &cookie, 8); |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5115 | tmp = cpu_to_be32(count); |
| 5116 | 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] | 5117 | out: |
| 5118 | if (listxattrs->lsxa_len) |
| 5119 | kvfree(listxattrs->lsxa_buf); |
| 5120 | return status; |
| 5121 | } |
| 5122 | |
| 5123 | static __be32 |
| 5124 | nfsd4_encode_removexattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5125 | struct nfsd4_removexattr *removexattr) |
| 5126 | { |
| 5127 | struct xdr_stream *xdr = &resp->xdr; |
| 5128 | __be32 *p; |
| 5129 | |
| 5130 | p = xdr_reserve_space(xdr, 20); |
| 5131 | if (!p) |
| 5132 | return nfserr_resource; |
| 5133 | |
| 5134 | p = encode_cinfo(p, &removexattr->rmxa_cinfo); |
| 5135 | return 0; |
| 5136 | } |
| 5137 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5138 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
| 5139 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5140 | /* |
| 5141 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 |
| 5142 | * since we don't need to filter out obsolete ops as this is |
| 5143 | * done in the decoding phase. |
| 5144 | */ |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 5145 | static const nfsd4_enc nfsd4_enc_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5146 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
| 5147 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
| 5148 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, |
| 5149 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, |
| 5150 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5151 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
| 5152 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, |
| 5153 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, |
| 5154 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, |
| 5155 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, |
| 5156 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, |
| 5157 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, |
| 5158 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5159 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5160 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5161 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, |
Benny Halevy | 84f09f4 | 2009-03-04 23:05:35 +0200 | [diff] [blame] | 5162 | [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5163 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
| 5164 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, |
| 5165 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5166 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5167 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5168 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, |
| 5169 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, |
| 5170 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, |
| 5171 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, |
| 5172 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, |
| 5173 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, |
| 5174 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5175 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5176 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, |
| 5177 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, |
| 5178 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, |
| 5179 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, |
| 5180 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5181 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
| 5182 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5183 | |
| 5184 | /* NFSv4.1 operations */ |
| 5185 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 5186 | [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] | 5187 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, |
| 5188 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, |
Kinglong Mee | 43212cc | 2013-12-09 19:04:23 +0800 | [diff] [blame] | 5189 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5190 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5191 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5192 | #ifdef CONFIG_NFSD_PNFS |
| 5193 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_getdeviceinfo, |
| 5194 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5195 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_layoutcommit, |
| 5196 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_layoutget, |
| 5197 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_layoutreturn, |
| 5198 | #else |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5199 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, |
| 5200 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5201 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, |
| 5202 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, |
| 5203 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5204 | #endif |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 5205 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5206 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, |
| 5207 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 5208 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5209 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5210 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, |
| 5211 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5212 | |
| 5213 | /* NFSv4.2 operations */ |
| 5214 | [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 5215 | [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 5216 | [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_copy_notify, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5217 | [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5218 | [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5219 | [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop, |
| 5220 | [OP_LAYOUTSTATS] = (nfsd4_enc)nfsd4_encode_noop, |
| 5221 | [OP_OFFLOAD_CANCEL] = (nfsd4_enc)nfsd4_encode_noop, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 5222 | [OP_OFFLOAD_STATUS] = (nfsd4_enc)nfsd4_encode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 5223 | [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_read_plus, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 5224 | [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5225 | [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 5226 | [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5227 | |
| 5228 | /* RFC 8276 extended atributes operations */ |
| 5229 | [OP_GETXATTR] = (nfsd4_enc)nfsd4_encode_getxattr, |
| 5230 | [OP_SETXATTR] = (nfsd4_enc)nfsd4_encode_setxattr, |
| 5231 | [OP_LISTXATTRS] = (nfsd4_enc)nfsd4_encode_listxattrs, |
| 5232 | [OP_REMOVEXATTR] = (nfsd4_enc)nfsd4_encode_removexattr, |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5233 | }; |
| 5234 | |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5235 | /* |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5236 | * Calculate whether we still have space to encode repsize bytes. |
| 5237 | * There are two considerations: |
| 5238 | * - For NFS versions >=4.1, the size of the reply must stay within |
| 5239 | * session limits |
| 5240 | * - For all NFS versions, we must stay within limited preallocated |
| 5241 | * buffer space. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5242 | * |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5243 | * This is called before the operation is processed, so can only provide |
| 5244 | * an upper estimate. For some nonidempotent operations (such as |
| 5245 | * getattr), it's not necessarily a problem if that estimate is wrong, |
| 5246 | * as we can fail it after processing without significant side effects. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5247 | */ |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5248 | __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize) |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5249 | { |
J. Bruce Fields | 67492c9 | 2014-03-08 16:42:05 -0500 | [diff] [blame] | 5250 | struct xdr_buf *buf = &resp->rqstp->rq_res; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5251 | struct nfsd4_slot *slot = resp->cstate.slot; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5252 | |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5253 | if (buf->len + respsize <= buf->buflen) |
| 5254 | return nfs_ok; |
| 5255 | if (!nfsd4_has_session(&resp->cstate)) |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5256 | return nfserr_resource; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5257 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) { |
| 5258 | WARN_ON_ONCE(1); |
| 5259 | return nfserr_rep_too_big_to_cache; |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5260 | } |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5261 | return nfserr_rep_too_big; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5262 | } |
| 5263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | void |
| 5265 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 5266 | { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5267 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5268 | struct nfs4_stateowner *so = resp->cstate.replay_owner; |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5269 | struct svc_rqst *rqstp = resp->rqstp; |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5270 | const struct nfsd4_operation *opdesc = op->opdesc; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5271 | int post_err_offset; |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5272 | nfsd4_enc encoder; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5273 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5275 | p = xdr_reserve_space(xdr, 8); |
| 5276 | if (!p) { |
| 5277 | WARN_ON_ONCE(1); |
| 5278 | return; |
| 5279 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5280 | *p++ = cpu_to_be32(op->opnum); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5281 | post_err_offset = xdr->buf->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5282 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5283 | if (op->opnum == OP_ILLEGAL) |
| 5284 | goto status; |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 5285 | if (op->status && opdesc && |
| 5286 | !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE)) |
| 5287 | goto status; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5288 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
| 5289 | !nfsd4_enc_ops[op->opnum]); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5290 | encoder = nfsd4_enc_ops[op->opnum]; |
| 5291 | op->status = encoder(resp, op->status, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 5292 | if (op->status) |
| 5293 | trace_nfsd_compound_encode_err(rqstp, op->opnum, op->status); |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5294 | if (opdesc && opdesc->op_release) |
| 5295 | opdesc->op_release(&op->u); |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5296 | xdr_commit_encode(xdr); |
| 5297 | |
J. Bruce Fields | 067e1ac | 2014-03-21 17:26:44 -0400 | [diff] [blame] | 5298 | /* nfsd4_check_resp_size guarantees enough room for error status */ |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5299 | if (!op->status) { |
| 5300 | int space_needed = 0; |
| 5301 | if (!nfsd4_last_compound_op(rqstp)) |
| 5302 | space_needed = COMPOUND_ERR_SLACK_SPACE; |
| 5303 | op->status = nfsd4_check_resp_size(resp, space_needed); |
| 5304 | } |
J. Bruce Fields | c8f13d9 | 2014-05-08 17:38:18 -0400 | [diff] [blame] | 5305 | if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) { |
| 5306 | struct nfsd4_slot *slot = resp->cstate.slot; |
| 5307 | |
| 5308 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) |
| 5309 | op->status = nfserr_rep_too_big_to_cache; |
| 5310 | else |
| 5311 | op->status = nfserr_rep_too_big; |
| 5312 | } |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5313 | if (op->status == nfserr_resource || |
| 5314 | op->status == nfserr_rep_too_big || |
| 5315 | op->status == nfserr_rep_too_big_to_cache) { |
| 5316 | /* |
| 5317 | * The operation may have already been encoded or |
| 5318 | * partially encoded. No op returns anything additional |
| 5319 | * in the case of one of these three errors, so we can |
| 5320 | * just truncate back to after the status. But it's a |
| 5321 | * bug if we had to do this on a non-idempotent op: |
| 5322 | */ |
| 5323 | warn_on_nonidempotent_op(op); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5324 | xdr_truncate_encode(xdr, post_err_offset); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5325 | } |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5326 | if (so) { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5327 | int len = xdr->buf->len - post_err_offset; |
| 5328 | |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5329 | so->so_replay.rp_status = op->status; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5330 | so->so_replay.rp_buflen = len; |
| 5331 | read_bytes_from_xdr_buf(xdr->buf, post_err_offset, |
| 5332 | so->so_replay.rp_buf, len); |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5333 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5334 | status: |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5335 | /* Note that op->status is already in network byte order: */ |
| 5336 | 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] | 5337 | } |
| 5338 | |
| 5339 | /* |
| 5340 | * Encode the reply stored in the stateowner reply cache |
| 5341 | * |
| 5342 | * XDR note: do not encode rp->rp_buflen: the buffer contains the |
| 5343 | * previously sent already encoded operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | */ |
| 5345 | void |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5346 | nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5347 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5348 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | struct nfs4_replay *rp = op->replay; |
| 5350 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5351 | p = xdr_reserve_space(xdr, 8 + rp->rp_buflen); |
| 5352 | if (!p) { |
| 5353 | WARN_ON_ONCE(1); |
| 5354 | return; |
| 5355 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5356 | *p++ = cpu_to_be32(op->opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | *p++ = rp->rp_status; /* already xdr'ed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 5359 | p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | } |
| 5361 | |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 5362 | void nfsd4_release_compoundargs(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | { |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5364 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | if (args->ops != args->iops) { |
| 5367 | kfree(args->ops); |
| 5368 | args->ops = args->iops; |
| 5369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | while (args->to_free) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 5371 | struct svcxdr_tmpbuf *tb = args->to_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | args->to_free = tb->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | kfree(tb); |
| 5374 | } |
| 5375 | } |
| 5376 | |
| 5377 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5378 | nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5380 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5381 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5382 | /* svcxdr_tmp_alloc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | args->tmpp = NULL; |
| 5384 | args->to_free = NULL; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5385 | |
| 5386 | args->xdr = &rqstp->rq_arg_stream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5387 | args->ops = args->iops; |
| 5388 | args->rqstp = rqstp; |
| 5389 | |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5390 | return !nfsd4_decode_compound(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5394 | nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5395 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5396 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
J. Bruce Fields | 6ac9039 | 2014-02-26 17:39:35 -0500 | [diff] [blame] | 5397 | struct xdr_buf *buf = resp->xdr.buf; |
| 5398 | |
| 5399 | WARN_ON_ONCE(buf->len != buf->head[0].iov_len + buf->page_len + |
| 5400 | buf->tail[0].iov_len); |
J. Bruce Fields | dd97fdd | 2014-02-26 17:16:27 -0500 | [diff] [blame] | 5401 | |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 5402 | *p = resp->cstate.status; |
| 5403 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5404 | rqstp->rq_next_page = resp->xdr.page_ptr + 1; |
| 5405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5406 | p = resp->tagp; |
| 5407 | *p++ = htonl(resp->taglen); |
| 5408 | memcpy(p, resp->tag, resp->taglen); |
| 5409 | p += XDR_QUADLEN(resp->taglen); |
| 5410 | *p++ = htonl(resp->opcnt); |
| 5411 | |
Trond Myklebust | b607664 | 2014-06-30 11:48:35 -0400 | [diff] [blame] | 5412 | nfsd4_sequence_done(resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 | return 1; |
| 5414 | } |
| 5415 | |
| 5416 | /* |
| 5417 | * Local variables: |
| 5418 | * c-basic-offset: 8 |
| 5419 | * End: |
| 5420 | */ |