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 | |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 210 | static __be32 |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 211 | nfsd4_decode_component4(struct nfsd4_compoundargs *argp, char **namp, u32 *lenp) |
| 212 | { |
| 213 | __be32 *p, status; |
| 214 | |
| 215 | if (xdr_stream_decode_u32(argp->xdr, lenp) < 0) |
| 216 | return nfserr_bad_xdr; |
| 217 | p = xdr_inline_decode(argp->xdr, *lenp); |
| 218 | if (!p) |
| 219 | return nfserr_bad_xdr; |
| 220 | status = check_filename((char *)p, *lenp); |
| 221 | if (status) |
| 222 | return status; |
| 223 | *namp = svcxdr_tmpalloc(argp, *lenp); |
| 224 | if (!*namp) |
| 225 | return nfserr_jukebox; |
| 226 | memcpy(*namp, p, *lenp); |
| 227 | |
| 228 | return nfs_ok; |
| 229 | } |
| 230 | |
| 231 | static __be32 |
J. Bruce Fields | bdba536 | 2019-06-05 14:17:42 -0400 | [diff] [blame] | 232 | nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 233 | { |
| 234 | DECODE_HEAD; |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 235 | |
| 236 | READ_BUF(12); |
J. Bruce Fields | bdba536 | 2019-06-05 14:17:42 -0400 | [diff] [blame] | 237 | p = xdr_decode_hyper(p, &tv->tv_sec); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 238 | tv->tv_nsec = be32_to_cpup(p++); |
| 239 | if (tv->tv_nsec >= (u32)1000000000) |
| 240 | return nfserr_inval; |
| 241 | |
| 242 | DECODE_TAIL; |
| 243 | } |
| 244 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 245 | static __be32 |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 246 | nfsd4_decode_nfstime4(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
| 247 | { |
| 248 | __be32 *p; |
| 249 | |
| 250 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 3); |
| 251 | if (!p) |
| 252 | return nfserr_bad_xdr; |
| 253 | p = xdr_decode_hyper(p, &tv->tv_sec); |
| 254 | tv->tv_nsec = be32_to_cpup(p++); |
| 255 | if (tv->tv_nsec >= (u32)1000000000) |
| 256 | return nfserr_inval; |
| 257 | return nfs_ok; |
| 258 | } |
| 259 | |
| 260 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) |
| 262 | { |
| 263 | u32 bmlen; |
| 264 | DECODE_HEAD; |
| 265 | |
| 266 | bmval[0] = 0; |
| 267 | bmval[1] = 0; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 268 | bmval[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 271 | bmlen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | if (bmlen > 1000) |
| 273 | goto xdr_error; |
| 274 | |
| 275 | READ_BUF(bmlen << 2); |
| 276 | if (bmlen > 0) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 277 | bmval[0] = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (bmlen > 1) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 279 | bmval[1] = be32_to_cpup(p++); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 280 | if (bmlen > 2) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 281 | bmval[2] = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | DECODE_TAIL; |
| 284 | } |
| 285 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 286 | /** |
| 287 | * nfsd4_decode_bitmap4 - Decode an NFSv4 bitmap4 |
| 288 | * @argp: NFSv4 compound argument structure |
| 289 | * @bmval: pointer to an array of u32's to decode into |
| 290 | * @bmlen: size of the @bmval array |
| 291 | * |
| 292 | * The server needs to return nfs_ok rather than nfserr_bad_xdr when |
| 293 | * encountering bitmaps containing bits it does not recognize. This |
| 294 | * includes bits in bitmap words past WORDn, where WORDn is the last |
| 295 | * bitmap WORD the implementation currently supports. Thus we are |
| 296 | * careful here to simply ignore bits in bitmap words that this |
| 297 | * implementation has yet to support explicitly. |
| 298 | * |
| 299 | * Return values: |
| 300 | * %nfs_ok: @bmval populated successfully |
| 301 | * %nfserr_bad_xdr: the encoded bitmap was invalid |
| 302 | */ |
| 303 | static __be32 |
| 304 | nfsd4_decode_bitmap4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen) |
| 305 | { |
| 306 | u32 i, count; |
| 307 | __be32 *p; |
| 308 | |
| 309 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 310 | return nfserr_bad_xdr; |
| 311 | /* request sanity */ |
| 312 | if (count > 1000) |
| 313 | return nfserr_bad_xdr; |
| 314 | p = xdr_inline_decode(argp->xdr, count << 2); |
| 315 | if (!p) |
| 316 | return nfserr_bad_xdr; |
| 317 | i = 0; |
| 318 | while (i < count) |
| 319 | bmval[i++] = be32_to_cpup(p++); |
| 320 | while (i < bmlen) |
| 321 | bmval[i++] = 0; |
| 322 | |
| 323 | return nfs_ok; |
| 324 | } |
| 325 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 326 | static __be32 |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 327 | nfsd4_decode_nfsace4(struct nfsd4_compoundargs *argp, struct nfs4_ace *ace) |
| 328 | { |
| 329 | __be32 *p, status; |
| 330 | u32 length; |
| 331 | |
| 332 | if (xdr_stream_decode_u32(argp->xdr, &ace->type) < 0) |
| 333 | return nfserr_bad_xdr; |
| 334 | if (xdr_stream_decode_u32(argp->xdr, &ace->flag) < 0) |
| 335 | return nfserr_bad_xdr; |
| 336 | if (xdr_stream_decode_u32(argp->xdr, &ace->access_mask) < 0) |
| 337 | return nfserr_bad_xdr; |
| 338 | |
| 339 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 340 | return nfserr_bad_xdr; |
| 341 | p = xdr_inline_decode(argp->xdr, length); |
| 342 | if (!p) |
| 343 | return nfserr_bad_xdr; |
| 344 | ace->whotype = nfs4_acl_get_whotype((char *)p, length); |
| 345 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
| 346 | status = nfs_ok; |
| 347 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
| 348 | status = nfsd_map_name_to_gid(argp->rqstp, |
| 349 | (char *)p, length, &ace->who_gid); |
| 350 | else |
| 351 | status = nfsd_map_name_to_uid(argp->rqstp, |
| 352 | (char *)p, length, &ace->who_uid); |
| 353 | |
| 354 | return status; |
| 355 | } |
| 356 | |
| 357 | /* A counted array of nfsace4's */ |
| 358 | static noinline __be32 |
| 359 | nfsd4_decode_acl(struct nfsd4_compoundargs *argp, struct nfs4_acl **acl) |
| 360 | { |
| 361 | struct nfs4_ace *ace; |
| 362 | __be32 status; |
| 363 | u32 count; |
| 364 | |
| 365 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 366 | return nfserr_bad_xdr; |
| 367 | |
| 368 | if (count > xdr_stream_remaining(argp->xdr) / 20) |
| 369 | /* |
| 370 | * Even with 4-byte names there wouldn't be |
| 371 | * space for that many aces; something fishy is |
| 372 | * going on: |
| 373 | */ |
| 374 | return nfserr_fbig; |
| 375 | |
| 376 | *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(count)); |
| 377 | if (*acl == NULL) |
| 378 | return nfserr_jukebox; |
| 379 | |
| 380 | (*acl)->naces = count; |
| 381 | for (ace = (*acl)->aces; ace < (*acl)->aces + count; ace++) { |
| 382 | status = nfsd4_decode_nfsace4(argp, ace); |
| 383 | if (status) |
| 384 | return status; |
| 385 | } |
| 386 | |
| 387 | return nfs_ok; |
| 388 | } |
| 389 | |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 390 | static noinline __be32 |
| 391 | nfsd4_decode_security_label(struct nfsd4_compoundargs *argp, |
| 392 | struct xdr_netobj *label) |
| 393 | { |
| 394 | u32 lfs, pi, length; |
| 395 | __be32 *p; |
| 396 | |
| 397 | if (xdr_stream_decode_u32(argp->xdr, &lfs) < 0) |
| 398 | return nfserr_bad_xdr; |
| 399 | if (xdr_stream_decode_u32(argp->xdr, &pi) < 0) |
| 400 | return nfserr_bad_xdr; |
| 401 | |
| 402 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 403 | return nfserr_bad_xdr; |
| 404 | if (length > NFS4_MAXLABELLEN) |
| 405 | return nfserr_badlabel; |
| 406 | p = xdr_inline_decode(argp->xdr, length); |
| 407 | if (!p) |
| 408 | return nfserr_bad_xdr; |
| 409 | label->len = length; |
| 410 | label->data = svcxdr_dupstr(argp, p, length); |
| 411 | if (!label->data) |
| 412 | return nfserr_jukebox; |
| 413 | |
| 414 | return nfs_ok; |
| 415 | } |
| 416 | |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 417 | static __be32 |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 418 | nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, |
| 419 | struct iattr *iattr, struct nfs4_acl **acl, |
| 420 | struct xdr_netobj *label, int *umask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 422 | unsigned int starting_pos; |
| 423 | u32 attrlist4_count; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 424 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | iattr->ia_valid = 0; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 427 | status = nfsd4_decode_bitmap4(argp, bmval, bmlen); |
| 428 | if (status) |
| 429 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
J. Bruce Fields | e864c18 | 2016-06-10 16:56:05 -0400 | [diff] [blame] | 431 | if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 |
| 432 | || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 |
| 433 | || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) { |
| 434 | if (nfsd_attrs_supported(argp->minorversion, bmval)) |
| 435 | return nfserr_inval; |
| 436 | return nfserr_attrnotsupp; |
| 437 | } |
| 438 | |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 439 | if (xdr_stream_decode_u32(argp->xdr, &attrlist4_count) < 0) |
| 440 | return nfserr_bad_xdr; |
| 441 | starting_pos = xdr_stream_pos(argp->xdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | if (bmval[0] & FATTR4_WORD0_SIZE) { |
Chuck Lever | 2ac1b9b | 2020-11-19 13:47:16 -0500 | [diff] [blame] | 444 | u64 size; |
| 445 | |
| 446 | if (xdr_stream_decode_u64(argp->xdr, &size) < 0) |
| 447 | return nfserr_bad_xdr; |
| 448 | iattr->ia_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | iattr->ia_valid |= ATTR_SIZE; |
| 450 | } |
| 451 | if (bmval[0] & FATTR4_WORD0_ACL) { |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 452 | status = nfsd4_decode_acl(argp, acl); |
| 453 | if (status) |
| 454 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } else |
| 456 | *acl = NULL; |
| 457 | if (bmval[1] & FATTR4_WORD1_MODE) { |
Chuck Lever | 1c8f0ad | 2020-11-19 13:54:26 -0500 | [diff] [blame] | 458 | u32 mode; |
| 459 | |
| 460 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 461 | return nfserr_bad_xdr; |
| 462 | iattr->ia_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
| 464 | iattr->ia_valid |= ATTR_MODE; |
| 465 | } |
| 466 | if (bmval[1] & FATTR4_WORD1_OWNER) { |
Chuck Lever | 9853a5a | 2020-11-19 13:56:42 -0500 | [diff] [blame] | 467 | u32 length; |
| 468 | |
| 469 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 470 | return nfserr_bad_xdr; |
| 471 | p = xdr_inline_decode(argp->xdr, length); |
| 472 | if (!p) |
| 473 | return nfserr_bad_xdr; |
| 474 | status = nfsd_map_name_to_uid(argp->rqstp, (char *)p, length, |
| 475 | &iattr->ia_uid); |
| 476 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 477 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | iattr->ia_valid |= ATTR_UID; |
| 479 | } |
| 480 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { |
Chuck Lever | 393c31d | 2020-11-19 13:58:18 -0500 | [diff] [blame] | 481 | u32 length; |
| 482 | |
| 483 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 484 | return nfserr_bad_xdr; |
| 485 | p = xdr_inline_decode(argp->xdr, length); |
| 486 | if (!p) |
| 487 | return nfserr_bad_xdr; |
| 488 | status = nfsd_map_name_to_gid(argp->rqstp, (char *)p, length, |
| 489 | &iattr->ia_gid); |
| 490 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 491 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | iattr->ia_valid |= ATTR_GID; |
| 493 | } |
| 494 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 495 | u32 set_it; |
| 496 | |
| 497 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 498 | return nfserr_bad_xdr; |
| 499 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 501 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_atime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 502 | if (status) |
| 503 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
| 505 | break; |
| 506 | case NFS4_SET_TO_SERVER_TIME: |
| 507 | iattr->ia_valid |= ATTR_ATIME; |
| 508 | break; |
| 509 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 510 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 514 | u32 set_it; |
| 515 | |
| 516 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 517 | return nfserr_bad_xdr; |
| 518 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 520 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_mtime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 521 | if (status) |
| 522 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
| 524 | break; |
| 525 | case NFS4_SET_TO_SERVER_TIME: |
| 526 | iattr->ia_valid |= ATTR_MTIME; |
| 527 | break; |
| 528 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 529 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 532 | label->len = 0; |
Arnd Bergmann | 2285ae7 | 2018-01-22 22:09:12 +0100 | [diff] [blame] | 533 | if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) && |
| 534 | bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 535 | status = nfsd4_decode_security_label(argp, label); |
| 536 | if (status) |
| 537 | return status; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 538 | } |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 539 | if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 540 | u32 mode, mask; |
| 541 | |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 542 | if (!umask) |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 543 | return nfserr_bad_xdr; |
| 544 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 545 | return nfserr_bad_xdr; |
| 546 | iattr->ia_mode = mode & (S_IFMT | S_IALLUGO); |
| 547 | if (xdr_stream_decode_u32(argp->xdr, &mask) < 0) |
| 548 | return nfserr_bad_xdr; |
| 549 | *umask = mask & S_IRWXUGO; |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 550 | iattr->ia_valid |= ATTR_MODE; |
| 551 | } |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 552 | |
| 553 | /* request sanity: did attrlist4 contain the expected number of words? */ |
| 554 | if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos) |
| 555 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 557 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 560 | static __be32 |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 561 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 562 | { |
| 563 | DECODE_HEAD; |
| 564 | |
| 565 | READ_BUF(sizeof(stateid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 566 | sid->si_generation = be32_to_cpup(p++); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 567 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 568 | |
| 569 | DECODE_TAIL; |
| 570 | } |
| 571 | |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 572 | static __be32 |
| 573 | nfsd4_decode_stateid4(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 574 | { |
| 575 | __be32 *p; |
| 576 | |
| 577 | p = xdr_inline_decode(argp->xdr, NFS4_STATEID_SIZE); |
| 578 | if (!p) |
| 579 | return nfserr_bad_xdr; |
| 580 | sid->si_generation = be32_to_cpup(p++); |
| 581 | memcpy(&sid->si_opaque, p, sizeof(sid->si_opaque)); |
| 582 | return nfs_ok; |
| 583 | } |
| 584 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 585 | static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs) |
| 586 | { |
| 587 | DECODE_HEAD; |
Trond Myklebust | e45d1a1 | 2019-04-09 12:13:42 -0400 | [diff] [blame] | 588 | struct user_namespace *userns = nfsd_user_namespace(argp->rqstp); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 589 | u32 dummy, uid, gid; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 590 | char *machine_name; |
| 591 | int i; |
| 592 | int nr_secflavs; |
| 593 | |
| 594 | /* callback_sec_params4 */ |
| 595 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 596 | nr_secflavs = be32_to_cpup(p++); |
J. Bruce Fields | 57569a7 | 2013-05-17 16:25:32 -0400 | [diff] [blame] | 597 | if (nr_secflavs) |
| 598 | cbs->flavor = (u32)(-1); |
| 599 | else |
| 600 | /* Is this legal? Be generous, take it to mean AUTH_NONE: */ |
| 601 | cbs->flavor = 0; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 602 | for (i = 0; i < nr_secflavs; ++i) { |
| 603 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 604 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 605 | switch (dummy) { |
| 606 | case RPC_AUTH_NULL: |
| 607 | /* Nothing to read */ |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 608 | if (cbs->flavor == (u32)(-1)) |
| 609 | cbs->flavor = RPC_AUTH_NULL; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 610 | break; |
| 611 | case RPC_AUTH_UNIX: |
| 612 | READ_BUF(8); |
| 613 | /* stamp */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 614 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 615 | |
| 616 | /* machine name */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 617 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 618 | READ_BUF(dummy); |
| 619 | SAVEMEM(machine_name, dummy); |
| 620 | |
| 621 | /* uid, gid */ |
| 622 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 623 | uid = be32_to_cpup(p++); |
| 624 | gid = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 625 | |
| 626 | /* more gids */ |
| 627 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 628 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 629 | READ_BUF(dummy * 4); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 630 | if (cbs->flavor == (u32)(-1)) { |
Trond Myklebust | e45d1a1 | 2019-04-09 12:13:42 -0400 | [diff] [blame] | 631 | kuid_t kuid = make_kuid(userns, uid); |
| 632 | kgid_t kgid = make_kgid(userns, gid); |
Eric W. Biederman | 03bc6d1 | 2013-02-02 06:24:49 -0800 | [diff] [blame] | 633 | if (uid_valid(kuid) && gid_valid(kgid)) { |
| 634 | cbs->uid = kuid; |
| 635 | cbs->gid = kgid; |
| 636 | cbs->flavor = RPC_AUTH_UNIX; |
| 637 | } else { |
| 638 | dprintk("RPC_AUTH_UNIX with invalid" |
| 639 | "uid or gid ignoring!\n"); |
| 640 | } |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 641 | } |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 642 | break; |
| 643 | case RPC_AUTH_GSS: |
| 644 | dprintk("RPC_AUTH_GSS callback secflavor " |
| 645 | "not supported!\n"); |
| 646 | READ_BUF(8); |
| 647 | /* gcbp_service */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 648 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 649 | /* gcbp_handle_from_server */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 650 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 651 | READ_BUF(dummy); |
| 652 | p += XDR_QUADLEN(dummy); |
| 653 | /* gcbp_handle_from_client */ |
| 654 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 655 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 656 | READ_BUF(dummy); |
| 657 | break; |
| 658 | default: |
| 659 | dprintk("Illegal callback secflavor\n"); |
| 660 | return nfserr_inval; |
| 661 | } |
| 662 | } |
| 663 | DECODE_TAIL; |
| 664 | } |
| 665 | |
Chuck Lever | d169a6a | 2020-11-03 13:12:27 -0500 | [diff] [blame] | 666 | /* |
| 667 | * NFSv4 operation argument decoders |
| 668 | */ |
| 669 | |
| 670 | static __be32 |
| 671 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, |
| 672 | struct nfsd4_access *access) |
| 673 | { |
| 674 | if (xdr_stream_decode_u32(argp->xdr, &access->ac_req_access) < 0) |
| 675 | return nfserr_bad_xdr; |
| 676 | return nfs_ok; |
| 677 | } |
| 678 | |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 679 | static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc) |
| 680 | { |
| 681 | DECODE_HEAD; |
| 682 | |
| 683 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 684 | bc->bc_cb_program = be32_to_cpup(p++); |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 685 | nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec); |
| 686 | |
| 687 | DECODE_TAIL; |
| 688 | } |
| 689 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 690 | static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts) |
| 691 | { |
| 692 | DECODE_HEAD; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 693 | |
| 694 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 8); |
| 695 | COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 696 | bcts->dir = be32_to_cpup(p++); |
Bryan Schumaker | 6ce2357 | 2011-04-27 15:47:16 -0400 | [diff] [blame] | 697 | /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker |
| 698 | * could help us figure out we should be using it. */ |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 699 | DECODE_TAIL; |
| 700 | } |
| 701 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 702 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
| 704 | { |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 705 | if (xdr_stream_decode_u32(argp->xdr, &close->cl_seqid) < 0) |
| 706 | return nfserr_bad_xdr; |
| 707 | return nfsd4_decode_stateid4(argp, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 711 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
| 713 | { |
Chuck Lever | cbd9abb | 2020-11-03 13:19:51 -0500 | [diff] [blame] | 714 | if (xdr_stream_decode_u64(argp->xdr, &commit->co_offset) < 0) |
| 715 | return nfserr_bad_xdr; |
| 716 | if (xdr_stream_decode_u32(argp->xdr, &commit->co_count) < 0) |
| 717 | return nfserr_bad_xdr; |
| 718 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 721 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
| 723 | { |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 724 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 726 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_type) < 0) |
| 727 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | switch (create->cr_type) { |
| 729 | case NF4LNK: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 730 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_datalen) < 0) |
| 731 | return nfserr_bad_xdr; |
| 732 | p = xdr_inline_decode(argp->xdr, create->cr_datalen); |
| 733 | if (!p) |
| 734 | return nfserr_bad_xdr; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 735 | create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen); |
J. Bruce Fields | 7fb8430 | 2014-06-24 15:06:41 -0400 | [diff] [blame] | 736 | if (!create->cr_data) |
J. Bruce Fields | 76f47128 | 2014-06-19 16:44:48 -0400 | [diff] [blame] | 737 | return nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | break; |
| 739 | case NF4BLK: |
| 740 | case NF4CHR: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 741 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata1) < 0) |
| 742 | return nfserr_bad_xdr; |
| 743 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata2) < 0) |
| 744 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | break; |
| 746 | case NF4SOCK: |
| 747 | case NF4FIFO: |
| 748 | case NF4DIR: |
| 749 | default: |
| 750 | break; |
| 751 | } |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 752 | status = nfsd4_decode_component4(argp, &create->cr_name, |
| 753 | &create->cr_namelen); |
| 754 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 756 | status = nfsd4_decode_fattr4(argp, create->cr_bmval, |
| 757 | ARRAY_SIZE(create->cr_bmval), |
| 758 | &create->cr_iattr, &create->cr_acl, |
| 759 | &create->cr_label, &create->cr_umask); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 760 | if (status) |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 761 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 763 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 766 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
| 768 | { |
Chuck Lever | 95e6482 | 2020-11-21 14:11:58 -0500 | [diff] [blame] | 769 | return nfsd4_decode_stateid4(argp, &dr->dr_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 772 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
| 774 | { |
Chuck Lever | f759eff | 2020-11-19 14:40:20 -0500 | [diff] [blame^] | 775 | return nfsd4_decode_bitmap4(argp, getattr->ga_bmval, |
| 776 | ARRAY_SIZE(getattr->ga_bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 779 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
| 781 | { |
| 782 | DECODE_HEAD; |
| 783 | |
| 784 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 785 | link->li_namelen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | READ_BUF(link->li_namelen); |
| 787 | SAVEMEM(link->li_name, link->li_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 788 | if ((status = check_filename(link->li_name, link->li_namelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | return status; |
| 790 | |
| 791 | DECODE_TAIL; |
| 792 | } |
| 793 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 794 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 796 | { |
| 797 | DECODE_HEAD; |
| 798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | /* |
| 800 | * type, reclaim(boolean), offset, length, new_lock_owner(boolean) |
| 801 | */ |
| 802 | READ_BUF(28); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 803 | lock->lk_type = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT)) |
| 805 | goto xdr_error; |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 806 | lock->lk_reclaim = be32_to_cpup(p++); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 807 | p = xdr_decode_hyper(p, &lock->lk_offset); |
| 808 | p = xdr_decode_hyper(p, &lock->lk_length); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 809 | lock->lk_is_new = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | if (lock->lk_is_new) { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 812 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 813 | lock->lk_new_open_seqid = be32_to_cpup(p++); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 814 | status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid); |
| 815 | if (status) |
| 816 | return status; |
| 817 | READ_BUF(8 + sizeof(clientid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 818 | lock->lk_new_lock_seqid = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 820 | lock->lk_new_owner.len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | READ_BUF(lock->lk_new_owner.len); |
| 822 | READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len); |
| 823 | } else { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 824 | status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid); |
| 825 | if (status) |
| 826 | return status; |
| 827 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 828 | lock->lk_old_lock_seqid = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | DECODE_TAIL; |
| 832 | } |
| 833 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 834 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
| 836 | { |
| 837 | DECODE_HEAD; |
| 838 | |
| 839 | READ_BUF(32); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 840 | lockt->lt_type = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
| 842 | goto xdr_error; |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 843 | p = xdr_decode_hyper(p, &lockt->lt_offset); |
| 844 | p = xdr_decode_hyper(p, &lockt->lt_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | COPYMEM(&lockt->lt_clientid, 8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 846 | lockt->lt_owner.len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | READ_BUF(lockt->lt_owner.len); |
| 848 | READMEM(lockt->lt_owner.data, lockt->lt_owner.len); |
| 849 | |
| 850 | DECODE_TAIL; |
| 851 | } |
| 852 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 853 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
| 855 | { |
| 856 | DECODE_HEAD; |
| 857 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 858 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 859 | locku->lu_type = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) |
| 861 | goto xdr_error; |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 862 | locku->lu_seqid = be32_to_cpup(p++); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 863 | status = nfsd4_decode_stateid(argp, &locku->lu_stateid); |
| 864 | if (status) |
| 865 | return status; |
| 866 | READ_BUF(16); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 867 | p = xdr_decode_hyper(p, &locku->lu_offset); |
| 868 | p = xdr_decode_hyper(p, &locku->lu_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | DECODE_TAIL; |
| 871 | } |
| 872 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 873 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
| 875 | { |
| 876 | DECODE_HEAD; |
| 877 | |
| 878 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 879 | lookup->lo_len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | READ_BUF(lookup->lo_len); |
| 881 | SAVEMEM(lookup->lo_name, lookup->lo_len); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 882 | if ((status = check_filename(lookup->lo_name, lookup->lo_len))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | return status; |
| 884 | |
| 885 | DECODE_TAIL; |
| 886 | } |
| 887 | |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 888 | 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] | 889 | { |
| 890 | __be32 *p; |
| 891 | u32 w; |
| 892 | |
| 893 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 894 | w = be32_to_cpup(p++); |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 895 | *share_access = w & NFS4_SHARE_ACCESS_MASK; |
| 896 | *deleg_want = w & NFS4_SHARE_WANT_MASK; |
| 897 | if (deleg_when) |
| 898 | *deleg_when = w & NFS4_SHARE_WHEN_MASK; |
| 899 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 900 | switch (w & NFS4_SHARE_ACCESS_MASK) { |
| 901 | case NFS4_SHARE_ACCESS_READ: |
| 902 | case NFS4_SHARE_ACCESS_WRITE: |
| 903 | case NFS4_SHARE_ACCESS_BOTH: |
| 904 | break; |
| 905 | default: |
| 906 | return nfserr_bad_xdr; |
| 907 | } |
Benny Halevy | fc0d14f | 2011-10-27 20:43:01 +0200 | [diff] [blame] | 908 | w &= ~NFS4_SHARE_ACCESS_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 909 | if (!w) |
| 910 | return nfs_ok; |
| 911 | if (!argp->minorversion) |
| 912 | return nfserr_bad_xdr; |
| 913 | switch (w & NFS4_SHARE_WANT_MASK) { |
| 914 | case NFS4_SHARE_WANT_NO_PREFERENCE: |
| 915 | case NFS4_SHARE_WANT_READ_DELEG: |
| 916 | case NFS4_SHARE_WANT_WRITE_DELEG: |
| 917 | case NFS4_SHARE_WANT_ANY_DELEG: |
| 918 | case NFS4_SHARE_WANT_NO_DELEG: |
| 919 | case NFS4_SHARE_WANT_CANCEL: |
| 920 | break; |
| 921 | default: |
| 922 | return nfserr_bad_xdr; |
| 923 | } |
Benny Halevy | 92bac8c | 2011-10-19 19:13:29 -0700 | [diff] [blame] | 924 | w &= ~NFS4_SHARE_WANT_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 925 | if (!w) |
| 926 | return nfs_ok; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 927 | |
| 928 | if (!deleg_when) /* open_downgrade */ |
| 929 | return nfserr_inval; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 930 | switch (w) { |
| 931 | case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL: |
| 932 | case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED: |
Benny Halevy | c668fc6 | 2011-10-19 19:13:13 -0700 | [diff] [blame] | 933 | case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL | |
| 934 | NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED): |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 935 | return nfs_ok; |
| 936 | } |
| 937 | xdr_error: |
| 938 | return nfserr_bad_xdr; |
| 939 | } |
| 940 | |
| 941 | static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x) |
| 942 | { |
| 943 | __be32 *p; |
| 944 | |
| 945 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 946 | *x = be32_to_cpup(p++); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 947 | /* Note: unlinke access bits, deny bits may be zero. */ |
Dan Carpenter | 01cd4af | 2011-10-17 10:41:17 +0300 | [diff] [blame] | 948 | if (*x & ~NFS4_SHARE_DENY_BOTH) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 949 | return nfserr_bad_xdr; |
| 950 | return nfs_ok; |
| 951 | xdr_error: |
| 952 | return nfserr_bad_xdr; |
| 953 | } |
| 954 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 955 | static __be32 nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o) |
| 956 | { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 957 | DECODE_HEAD; |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 958 | |
| 959 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 960 | o->len = be32_to_cpup(p++); |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 961 | |
| 962 | if (o->len == 0 || o->len > NFS4_OPAQUE_LIMIT) |
| 963 | return nfserr_bad_xdr; |
| 964 | |
| 965 | READ_BUF(o->len); |
| 966 | SAVEMEM(o->data, o->len); |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 967 | |
| 968 | DECODE_TAIL; |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 969 | } |
| 970 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 971 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 973 | { |
| 974 | DECODE_HEAD; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 975 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
| 977 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); |
| 978 | open->op_iattr.ia_valid = 0; |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 979 | open->op_openowner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 981 | open->op_xdr_error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | /* seqid, share_access, share_deny, clientid, ownerlen */ |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 983 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 984 | open->op_seqid = be32_to_cpup(p++); |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 985 | /* decode, yet ignore deleg_when until supported */ |
| 986 | status = nfsd4_decode_share_access(argp, &open->op_share_access, |
| 987 | &open->op_deleg_want, &dummy); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 988 | if (status) |
| 989 | goto xdr_error; |
| 990 | status = nfsd4_decode_share_deny(argp, &open->op_share_deny); |
| 991 | if (status) |
| 992 | goto xdr_error; |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 993 | READ_BUF(sizeof(clientid_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | COPYMEM(&open->op_clientid, sizeof(clientid_t)); |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 995 | status = nfsd4_decode_opaque(argp, &open->op_owner); |
| 996 | if (status) |
| 997 | goto xdr_error; |
| 998 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 999 | open->op_create = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | switch (open->op_create) { |
| 1001 | case NFS4_OPEN_NOCREATE: |
| 1002 | break; |
| 1003 | case NFS4_OPEN_CREATE: |
| 1004 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1005 | open->op_createmode = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | switch (open->op_createmode) { |
| 1007 | case NFS4_CREATE_UNCHECKED: |
| 1008 | case NFS4_CREATE_GUARDED: |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 1009 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 1010 | ARRAY_SIZE(open->op_bmval), |
| 1011 | &open->op_iattr, &open->op_acl, |
| 1012 | &open->op_label, &open->op_umask); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 1013 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | goto out; |
| 1015 | break; |
| 1016 | case NFS4_CREATE_EXCLUSIVE: |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1017 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1018 | COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | break; |
Benny Halevy | 79fb54a | 2009-04-03 08:29:17 +0300 | [diff] [blame] | 1020 | case NFS4_CREATE_EXCLUSIVE4_1: |
| 1021 | if (argp->minorversion < 1) |
| 1022 | goto xdr_error; |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1023 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1024 | COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE); |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 1025 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 1026 | ARRAY_SIZE(open->op_bmval), |
| 1027 | &open->op_iattr, &open->op_acl, |
| 1028 | &open->op_label, &open->op_umask); |
Benny Halevy | 79fb54a | 2009-04-03 08:29:17 +0300 | [diff] [blame] | 1029 | if (status) |
| 1030 | goto out; |
| 1031 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | default: |
| 1033 | goto xdr_error; |
| 1034 | } |
| 1035 | break; |
| 1036 | default: |
| 1037 | goto xdr_error; |
| 1038 | } |
| 1039 | |
| 1040 | /* open_claim */ |
| 1041 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1042 | open->op_claim_type = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | switch (open->op_claim_type) { |
| 1044 | case NFS4_OPEN_CLAIM_NULL: |
| 1045 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1046 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1047 | open->op_fname.len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | READ_BUF(open->op_fname.len); |
| 1049 | SAVEMEM(open->op_fname.data, open->op_fname.len); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1050 | if ((status = check_filename(open->op_fname.data, open->op_fname.len))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | return status; |
| 1052 | break; |
| 1053 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1054 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1055 | open->op_delegate_type = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | break; |
| 1057 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1058 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); |
| 1059 | if (status) |
| 1060 | return status; |
| 1061 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1062 | open->op_fname.len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | READ_BUF(open->op_fname.len); |
| 1064 | SAVEMEM(open->op_fname.data, open->op_fname.len); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1065 | if ((status = check_filename(open->op_fname.data, open->op_fname.len))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | return status; |
| 1067 | break; |
J. Bruce Fields | 8b289b2 | 2011-10-19 11:52:12 -0400 | [diff] [blame] | 1068 | case NFS4_OPEN_CLAIM_FH: |
| 1069 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1070 | if (argp->minorversion < 1) |
| 1071 | goto xdr_error; |
| 1072 | /* void */ |
| 1073 | break; |
| 1074 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1075 | if (argp->minorversion < 1) |
| 1076 | goto xdr_error; |
| 1077 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); |
| 1078 | if (status) |
| 1079 | return status; |
| 1080 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | default: |
| 1082 | goto xdr_error; |
| 1083 | } |
| 1084 | |
| 1085 | DECODE_TAIL; |
| 1086 | } |
| 1087 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1088 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
| 1090 | { |
| 1091 | DECODE_HEAD; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1092 | |
| 1093 | if (argp->minorversion >= 1) |
| 1094 | return nfserr_notsupp; |
| 1095 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1096 | status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid); |
| 1097 | if (status) |
| 1098 | return status; |
| 1099 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1100 | open_conf->oc_seqid = be32_to_cpup(p++); |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | DECODE_TAIL; |
| 1103 | } |
| 1104 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1105 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
| 1107 | { |
| 1108 | DECODE_HEAD; |
| 1109 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1110 | status = nfsd4_decode_stateid(argp, &open_down->od_stateid); |
| 1111 | if (status) |
| 1112 | return status; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1113 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1114 | open_down->od_seqid = be32_to_cpup(p++); |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1115 | status = nfsd4_decode_share_access(argp, &open_down->od_share_access, |
| 1116 | &open_down->od_deleg_want, NULL); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1117 | if (status) |
| 1118 | return status; |
| 1119 | status = nfsd4_decode_share_deny(argp, &open_down->od_share_deny); |
| 1120 | if (status) |
| 1121 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | DECODE_TAIL; |
| 1123 | } |
| 1124 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1125 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
| 1127 | { |
| 1128 | DECODE_HEAD; |
| 1129 | |
| 1130 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1131 | putfh->pf_fhlen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
| 1133 | goto xdr_error; |
| 1134 | READ_BUF(putfh->pf_fhlen); |
| 1135 | SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen); |
| 1136 | |
| 1137 | DECODE_TAIL; |
| 1138 | } |
| 1139 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1140 | static __be32 |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1141 | nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p) |
| 1142 | { |
| 1143 | if (argp->minorversion == 0) |
| 1144 | return nfs_ok; |
| 1145 | return nfserr_notsupp; |
| 1146 | } |
| 1147 | |
| 1148 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
| 1150 | { |
| 1151 | DECODE_HEAD; |
| 1152 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1153 | status = nfsd4_decode_stateid(argp, &read->rd_stateid); |
| 1154 | if (status) |
| 1155 | return status; |
| 1156 | READ_BUF(12); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 1157 | p = xdr_decode_hyper(p, &read->rd_offset); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1158 | read->rd_length = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
| 1160 | DECODE_TAIL; |
| 1161 | } |
| 1162 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1163 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
| 1165 | { |
| 1166 | DECODE_HEAD; |
| 1167 | |
| 1168 | READ_BUF(24); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 1169 | p = xdr_decode_hyper(p, &readdir->rd_cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1171 | readdir->rd_dircount = be32_to_cpup(p++); |
| 1172 | readdir->rd_maxcount = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval))) |
| 1174 | goto out; |
| 1175 | |
| 1176 | DECODE_TAIL; |
| 1177 | } |
| 1178 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1179 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
| 1181 | { |
| 1182 | DECODE_HEAD; |
| 1183 | |
| 1184 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1185 | remove->rm_namelen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | READ_BUF(remove->rm_namelen); |
| 1187 | SAVEMEM(remove->rm_name, remove->rm_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1188 | if ((status = check_filename(remove->rm_name, remove->rm_namelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | return status; |
| 1190 | |
| 1191 | DECODE_TAIL; |
| 1192 | } |
| 1193 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1194 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
| 1196 | { |
| 1197 | DECODE_HEAD; |
| 1198 | |
| 1199 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1200 | rename->rn_snamelen = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1201 | READ_BUF(rename->rn_snamelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | SAVEMEM(rename->rn_sname, rename->rn_snamelen); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1203 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1204 | rename->rn_tnamelen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | READ_BUF(rename->rn_tnamelen); |
| 1206 | SAVEMEM(rename->rn_tname, rename->rn_tnamelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1207 | if ((status = check_filename(rename->rn_sname, rename->rn_snamelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | return status; |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1209 | if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | return status; |
| 1211 | |
| 1212 | DECODE_TAIL; |
| 1213 | } |
| 1214 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1215 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 1217 | { |
| 1218 | DECODE_HEAD; |
| 1219 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1220 | if (argp->minorversion >= 1) |
| 1221 | return nfserr_notsupp; |
| 1222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | READ_BUF(sizeof(clientid_t)); |
| 1224 | COPYMEM(clientid, sizeof(clientid_t)); |
| 1225 | |
| 1226 | DECODE_TAIL; |
| 1227 | } |
| 1228 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1229 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1230 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, |
| 1231 | struct nfsd4_secinfo *secinfo) |
| 1232 | { |
| 1233 | DECODE_HEAD; |
| 1234 | |
| 1235 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1236 | secinfo->si_namelen = be32_to_cpup(p++); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1237 | READ_BUF(secinfo->si_namelen); |
| 1238 | SAVEMEM(secinfo->si_name, secinfo->si_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1239 | status = check_filename(secinfo->si_name, secinfo->si_namelen); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1240 | if (status) |
| 1241 | return status; |
| 1242 | DECODE_TAIL; |
| 1243 | } |
| 1244 | |
| 1245 | static __be32 |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1246 | nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp, |
| 1247 | struct nfsd4_secinfo_no_name *sin) |
| 1248 | { |
| 1249 | DECODE_HEAD; |
| 1250 | |
| 1251 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1252 | sin->sin_style = be32_to_cpup(p++); |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1253 | DECODE_TAIL; |
| 1254 | } |
| 1255 | |
| 1256 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
| 1258 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1259 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1261 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); |
| 1262 | if (status) |
| 1263 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 1264 | return nfsd4_decode_fattr4(argp, setattr->sa_bmval, |
| 1265 | ARRAY_SIZE(setattr->sa_bmval), |
| 1266 | &setattr->sa_iattr, &setattr->sa_acl, |
| 1267 | &setattr->sa_label, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1270 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
| 1272 | { |
| 1273 | DECODE_HEAD; |
| 1274 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1275 | if (argp->minorversion >= 1) |
| 1276 | return nfserr_notsupp; |
| 1277 | |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1278 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1279 | COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1281 | status = nfsd4_decode_opaque(argp, &setclientid->se_name); |
| 1282 | if (status) |
| 1283 | return nfserr_bad_xdr; |
| 1284 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1285 | setclientid->se_callback_prog = be32_to_cpup(p++); |
| 1286 | setclientid->se_callback_netid_len = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1287 | READ_BUF(setclientid->se_callback_netid_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1289 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1290 | setclientid->se_callback_addr_len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1292 | READ_BUF(setclientid->se_callback_addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1294 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1295 | setclientid->se_callback_ident = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
| 1297 | DECODE_TAIL; |
| 1298 | } |
| 1299 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1300 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
| 1302 | { |
| 1303 | DECODE_HEAD; |
| 1304 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1305 | if (argp->minorversion >= 1) |
| 1306 | return nfserr_notsupp; |
| 1307 | |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1308 | READ_BUF(8 + NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | COPYMEM(&scd_c->sc_clientid, 8); |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1310 | COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
| 1312 | DECODE_TAIL; |
| 1313 | } |
| 1314 | |
| 1315 | /* Also used for NVERIFY */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1316 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
| 1318 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | DECODE_HEAD; |
| 1320 | |
| 1321 | if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval))) |
| 1322 | goto out; |
| 1323 | |
| 1324 | /* For convenience's sake, we compare raw xdr'd attributes in |
J. Bruce Fields | e5f9570 | 2012-11-30 17:24:18 -0500 | [diff] [blame] | 1325 | * nfsd4_proc_verify */ |
| 1326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1328 | verify->ve_attrlen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | READ_BUF(verify->ve_attrlen); |
| 1330 | SAVEMEM(verify->ve_attrval, verify->ve_attrlen); |
| 1331 | |
| 1332 | DECODE_TAIL; |
| 1333 | } |
| 1334 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1335 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
| 1337 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | DECODE_HEAD; |
| 1339 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1340 | status = nfsd4_decode_stateid(argp, &write->wr_stateid); |
| 1341 | if (status) |
| 1342 | return status; |
| 1343 | READ_BUF(16); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 1344 | p = xdr_decode_hyper(p, &write->wr_offset); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1345 | write->wr_stable_how = be32_to_cpup(p++); |
Kinglong Mee | 54bbb7d | 2016-12-31 20:59:53 +0800 | [diff] [blame] | 1346 | if (write->wr_stable_how > NFS_FILE_SYNC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | goto xdr_error; |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1348 | write->wr_buflen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1350 | if (!xdr_stream_subsegment(argp->xdr, &write->wr_payload, write->wr_buflen)) |
| 1351 | goto xdr_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
| 1353 | DECODE_TAIL; |
| 1354 | } |
| 1355 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1356 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
| 1358 | { |
| 1359 | DECODE_HEAD; |
| 1360 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1361 | if (argp->minorversion >= 1) |
| 1362 | return nfserr_notsupp; |
| 1363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | READ_BUF(12); |
| 1365 | COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1366 | rlockowner->rl_owner.len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | READ_BUF(rlockowner->rl_owner.len); |
| 1368 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); |
| 1369 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 1370 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) |
| 1371 | return nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | DECODE_TAIL; |
| 1373 | } |
| 1374 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1375 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1376 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1377 | struct nfsd4_exchange_id *exid) |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1378 | { |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1379 | int dummy, tmp; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1380 | DECODE_HEAD; |
| 1381 | |
| 1382 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1383 | COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE); |
| 1384 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1385 | status = nfsd4_decode_opaque(argp, &exid->clname); |
| 1386 | if (status) |
| 1387 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1388 | |
| 1389 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1390 | exid->flags = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1391 | |
| 1392 | /* Ignore state_protect4_a */ |
| 1393 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1394 | exid->spa_how = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1395 | switch (exid->spa_how) { |
| 1396 | case SP4_NONE: |
| 1397 | break; |
| 1398 | case SP4_MACH_CRED: |
| 1399 | /* spo_must_enforce */ |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1400 | status = nfsd4_decode_bitmap(argp, |
| 1401 | exid->spo_must_enforce); |
| 1402 | if (status) |
| 1403 | goto out; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1404 | /* spo_must_allow */ |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1405 | status = nfsd4_decode_bitmap(argp, exid->spo_must_allow); |
| 1406 | if (status) |
| 1407 | goto out; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1408 | break; |
| 1409 | case SP4_SSV: |
| 1410 | /* ssp_ops */ |
| 1411 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1412 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1413 | READ_BUF(dummy * 4); |
| 1414 | p += dummy; |
| 1415 | |
| 1416 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1417 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1418 | READ_BUF(dummy * 4); |
| 1419 | p += dummy; |
| 1420 | |
| 1421 | /* ssp_hash_algs<> */ |
| 1422 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1423 | tmp = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1424 | while (tmp--) { |
| 1425 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1426 | dummy = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1427 | READ_BUF(dummy); |
| 1428 | p += XDR_QUADLEN(dummy); |
| 1429 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1430 | |
| 1431 | /* ssp_encr_algs<> */ |
| 1432 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1433 | tmp = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1434 | while (tmp--) { |
| 1435 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1436 | dummy = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1437 | READ_BUF(dummy); |
| 1438 | p += XDR_QUADLEN(dummy); |
| 1439 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1440 | |
nixiaoming | 5ed96bc | 2018-07-23 09:57:11 +0800 | [diff] [blame] | 1441 | /* ignore ssp_window and ssp_num_gss_handles: */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1442 | READ_BUF(8); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1443 | break; |
| 1444 | default: |
| 1445 | goto xdr_error; |
| 1446 | } |
| 1447 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1448 | READ_BUF(4); /* nfs_impl_id4 array length */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1449 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1450 | |
| 1451 | if (dummy > 1) |
| 1452 | goto xdr_error; |
| 1453 | |
| 1454 | if (dummy == 1) { |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1455 | status = nfsd4_decode_opaque(argp, &exid->nii_domain); |
| 1456 | if (status) |
| 1457 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1458 | |
| 1459 | /* nii_name */ |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1460 | status = nfsd4_decode_opaque(argp, &exid->nii_name); |
| 1461 | if (status) |
| 1462 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1463 | |
| 1464 | /* nii_date */ |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1465 | status = nfsd4_decode_time(argp, &exid->nii_time); |
| 1466 | if (status) |
| 1467 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1468 | } |
| 1469 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | static __be32 |
| 1473 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, |
| 1474 | struct nfsd4_create_session *sess) |
| 1475 | { |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1476 | DECODE_HEAD; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1477 | |
| 1478 | READ_BUF(16); |
| 1479 | COPYMEM(&sess->clientid, 8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1480 | sess->seqid = be32_to_cpup(p++); |
| 1481 | sess->flags = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1482 | |
| 1483 | /* Fore channel attrs */ |
| 1484 | READ_BUF(28); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 1485 | p++; /* headerpadsz is always 0 */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1486 | sess->fore_channel.maxreq_sz = be32_to_cpup(p++); |
| 1487 | sess->fore_channel.maxresp_sz = be32_to_cpup(p++); |
| 1488 | sess->fore_channel.maxresp_cached = be32_to_cpup(p++); |
| 1489 | sess->fore_channel.maxops = be32_to_cpup(p++); |
| 1490 | sess->fore_channel.maxreqs = be32_to_cpup(p++); |
| 1491 | sess->fore_channel.nr_rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1492 | if (sess->fore_channel.nr_rdma_attrs == 1) { |
| 1493 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1494 | sess->fore_channel.rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1495 | } else if (sess->fore_channel.nr_rdma_attrs > 1) { |
| 1496 | dprintk("Too many fore channel attr bitmaps!\n"); |
| 1497 | goto xdr_error; |
| 1498 | } |
| 1499 | |
| 1500 | /* Back channel attrs */ |
| 1501 | READ_BUF(28); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 1502 | p++; /* headerpadsz is always 0 */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1503 | sess->back_channel.maxreq_sz = be32_to_cpup(p++); |
| 1504 | sess->back_channel.maxresp_sz = be32_to_cpup(p++); |
| 1505 | sess->back_channel.maxresp_cached = be32_to_cpup(p++); |
| 1506 | sess->back_channel.maxops = be32_to_cpup(p++); |
| 1507 | sess->back_channel.maxreqs = be32_to_cpup(p++); |
| 1508 | sess->back_channel.nr_rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1509 | if (sess->back_channel.nr_rdma_attrs == 1) { |
| 1510 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1511 | sess->back_channel.rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1512 | } else if (sess->back_channel.nr_rdma_attrs > 1) { |
| 1513 | dprintk("Too many back channel attr bitmaps!\n"); |
| 1514 | goto xdr_error; |
| 1515 | } |
| 1516 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1517 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1518 | sess->callback_prog = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1519 | nfsd4_decode_cb_sec(argp, &sess->cb_sec); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1520 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | static __be32 |
| 1524 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, |
| 1525 | struct nfsd4_destroy_session *destroy_session) |
| 1526 | { |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1527 | DECODE_HEAD; |
| 1528 | READ_BUF(NFS4_MAX_SESSIONID_LEN); |
| 1529 | COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 1530 | |
| 1531 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | static __be32 |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1535 | nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, |
| 1536 | struct nfsd4_free_stateid *free_stateid) |
| 1537 | { |
| 1538 | DECODE_HEAD; |
| 1539 | |
| 1540 | READ_BUF(sizeof(stateid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1541 | free_stateid->fr_stateid.si_generation = be32_to_cpup(p++); |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1542 | COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t)); |
| 1543 | |
| 1544 | DECODE_TAIL; |
| 1545 | } |
| 1546 | |
| 1547 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1548 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, |
| 1549 | struct nfsd4_sequence *seq) |
| 1550 | { |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1551 | DECODE_HEAD; |
| 1552 | |
| 1553 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); |
| 1554 | COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1555 | seq->seqid = be32_to_cpup(p++); |
| 1556 | seq->slotid = be32_to_cpup(p++); |
| 1557 | seq->maxslots = be32_to_cpup(p++); |
| 1558 | seq->cachethis = be32_to_cpup(p++); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1559 | |
| 1560 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1561 | } |
| 1562 | |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1563 | static __be32 |
| 1564 | nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid) |
| 1565 | { |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1566 | int i; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1567 | __be32 *p, status; |
| 1568 | struct nfsd4_test_stateid_id *stateid; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1569 | |
| 1570 | READ_BUF(4); |
| 1571 | test_stateid->ts_num_ids = ntohl(*p++); |
| 1572 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1573 | INIT_LIST_HEAD(&test_stateid->ts_stateid_list); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1574 | |
| 1575 | for (i = 0; i < test_stateid->ts_num_ids; i++) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 1576 | stateid = svcxdr_tmpalloc(argp, sizeof(*stateid)); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1577 | if (!stateid) { |
Al Viro | afcf679 | 2012-04-13 00:15:37 -0400 | [diff] [blame] | 1578 | status = nfserrno(-ENOMEM); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1579 | goto out; |
| 1580 | } |
| 1581 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1582 | INIT_LIST_HEAD(&stateid->ts_id_list); |
| 1583 | list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list); |
| 1584 | |
| 1585 | status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1586 | if (status) |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1587 | goto out; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | status = 0; |
| 1591 | out: |
| 1592 | return status; |
| 1593 | xdr_error: |
| 1594 | dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__); |
| 1595 | status = nfserr_bad_xdr; |
| 1596 | goto out; |
| 1597 | } |
| 1598 | |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 1599 | static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc) |
| 1600 | { |
| 1601 | DECODE_HEAD; |
| 1602 | |
| 1603 | READ_BUF(8); |
| 1604 | COPYMEM(&dc->clientid, 8); |
| 1605 | |
| 1606 | DECODE_TAIL; |
| 1607 | } |
| 1608 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1609 | static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc) |
| 1610 | { |
| 1611 | DECODE_HEAD; |
| 1612 | |
| 1613 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1614 | rc->rca_one_fs = be32_to_cpup(p++); |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1615 | |
| 1616 | DECODE_TAIL; |
| 1617 | } |
| 1618 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1619 | #ifdef CONFIG_NFSD_PNFS |
| 1620 | static __be32 |
| 1621 | nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp, |
| 1622 | struct nfsd4_getdeviceinfo *gdev) |
| 1623 | { |
| 1624 | DECODE_HEAD; |
| 1625 | u32 num, i; |
| 1626 | |
| 1627 | READ_BUF(sizeof(struct nfsd4_deviceid) + 3 * 4); |
| 1628 | COPYMEM(&gdev->gd_devid, sizeof(struct nfsd4_deviceid)); |
| 1629 | gdev->gd_layout_type = be32_to_cpup(p++); |
| 1630 | gdev->gd_maxcount = be32_to_cpup(p++); |
| 1631 | num = be32_to_cpup(p++); |
| 1632 | if (num) { |
Scott Mayhew | 3171822f | 2018-06-08 16:31:46 -0400 | [diff] [blame] | 1633 | if (num > 1000) |
| 1634 | goto xdr_error; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1635 | READ_BUF(4 * num); |
| 1636 | gdev->gd_notify_types = be32_to_cpup(p++); |
| 1637 | for (i = 1; i < num; i++) { |
| 1638 | if (be32_to_cpup(p++)) { |
| 1639 | status = nfserr_inval; |
| 1640 | goto out; |
| 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | DECODE_TAIL; |
| 1645 | } |
| 1646 | |
| 1647 | static __be32 |
| 1648 | nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp, |
| 1649 | struct nfsd4_layoutget *lgp) |
| 1650 | { |
| 1651 | DECODE_HEAD; |
| 1652 | |
| 1653 | READ_BUF(36); |
| 1654 | lgp->lg_signal = be32_to_cpup(p++); |
| 1655 | lgp->lg_layout_type = be32_to_cpup(p++); |
| 1656 | lgp->lg_seg.iomode = be32_to_cpup(p++); |
| 1657 | p = xdr_decode_hyper(p, &lgp->lg_seg.offset); |
| 1658 | p = xdr_decode_hyper(p, &lgp->lg_seg.length); |
| 1659 | p = xdr_decode_hyper(p, &lgp->lg_minlength); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1660 | |
| 1661 | status = nfsd4_decode_stateid(argp, &lgp->lg_sid); |
| 1662 | if (status) |
| 1663 | return status; |
| 1664 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1665 | READ_BUF(4); |
| 1666 | lgp->lg_maxcount = be32_to_cpup(p++); |
| 1667 | |
| 1668 | DECODE_TAIL; |
| 1669 | } |
| 1670 | |
| 1671 | static __be32 |
| 1672 | nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, |
| 1673 | struct nfsd4_layoutcommit *lcp) |
| 1674 | { |
| 1675 | DECODE_HEAD; |
| 1676 | u32 timechange; |
| 1677 | |
| 1678 | READ_BUF(20); |
| 1679 | p = xdr_decode_hyper(p, &lcp->lc_seg.offset); |
| 1680 | p = xdr_decode_hyper(p, &lcp->lc_seg.length); |
| 1681 | lcp->lc_reclaim = be32_to_cpup(p++); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1682 | |
| 1683 | status = nfsd4_decode_stateid(argp, &lcp->lc_sid); |
| 1684 | if (status) |
| 1685 | return status; |
| 1686 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1687 | READ_BUF(4); |
| 1688 | lcp->lc_newoffset = be32_to_cpup(p++); |
| 1689 | if (lcp->lc_newoffset) { |
| 1690 | READ_BUF(8); |
| 1691 | p = xdr_decode_hyper(p, &lcp->lc_last_wr); |
| 1692 | } else |
| 1693 | lcp->lc_last_wr = 0; |
| 1694 | READ_BUF(4); |
| 1695 | timechange = be32_to_cpup(p++); |
| 1696 | if (timechange) { |
| 1697 | status = nfsd4_decode_time(argp, &lcp->lc_mtime); |
| 1698 | if (status) |
| 1699 | return status; |
| 1700 | } else { |
| 1701 | lcp->lc_mtime.tv_nsec = UTIME_NOW; |
| 1702 | } |
| 1703 | READ_BUF(8); |
| 1704 | lcp->lc_layout_type = be32_to_cpup(p++); |
| 1705 | |
| 1706 | /* |
| 1707 | * Save the layout update in XDR format and let the layout driver deal |
| 1708 | * with it later. |
| 1709 | */ |
| 1710 | lcp->lc_up_len = be32_to_cpup(p++); |
| 1711 | if (lcp->lc_up_len > 0) { |
| 1712 | READ_BUF(lcp->lc_up_len); |
| 1713 | READMEM(lcp->lc_up_layout, lcp->lc_up_len); |
| 1714 | } |
| 1715 | |
| 1716 | DECODE_TAIL; |
| 1717 | } |
| 1718 | |
| 1719 | static __be32 |
| 1720 | nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp, |
| 1721 | struct nfsd4_layoutreturn *lrp) |
| 1722 | { |
| 1723 | DECODE_HEAD; |
| 1724 | |
| 1725 | READ_BUF(16); |
| 1726 | lrp->lr_reclaim = be32_to_cpup(p++); |
| 1727 | lrp->lr_layout_type = be32_to_cpup(p++); |
| 1728 | lrp->lr_seg.iomode = be32_to_cpup(p++); |
| 1729 | lrp->lr_return_type = be32_to_cpup(p++); |
| 1730 | if (lrp->lr_return_type == RETURN_FILE) { |
| 1731 | READ_BUF(16); |
| 1732 | p = xdr_decode_hyper(p, &lrp->lr_seg.offset); |
| 1733 | p = xdr_decode_hyper(p, &lrp->lr_seg.length); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1734 | |
| 1735 | status = nfsd4_decode_stateid(argp, &lrp->lr_sid); |
| 1736 | if (status) |
| 1737 | return status; |
| 1738 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1739 | READ_BUF(4); |
| 1740 | lrp->lrf_body_len = be32_to_cpup(p++); |
| 1741 | if (lrp->lrf_body_len > 0) { |
| 1742 | READ_BUF(lrp->lrf_body_len); |
| 1743 | READMEM(lrp->lrf_body, lrp->lrf_body_len); |
| 1744 | } |
| 1745 | } else { |
| 1746 | lrp->lr_seg.offset = 0; |
| 1747 | lrp->lr_seg.length = NFS4_MAX_UINT64; |
| 1748 | } |
| 1749 | |
| 1750 | DECODE_TAIL; |
| 1751 | } |
| 1752 | #endif /* CONFIG_NFSD_PNFS */ |
| 1753 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1754 | static __be32 |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1755 | nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, |
| 1756 | struct nfsd4_fallocate *fallocate) |
| 1757 | { |
| 1758 | DECODE_HEAD; |
| 1759 | |
| 1760 | status = nfsd4_decode_stateid(argp, &fallocate->falloc_stateid); |
| 1761 | if (status) |
| 1762 | return status; |
| 1763 | |
| 1764 | READ_BUF(16); |
| 1765 | p = xdr_decode_hyper(p, &fallocate->falloc_offset); |
| 1766 | xdr_decode_hyper(p, &fallocate->falloc_length); |
| 1767 | |
| 1768 | DECODE_TAIL; |
| 1769 | } |
| 1770 | |
| 1771 | static __be32 |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1772 | nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone) |
| 1773 | { |
| 1774 | DECODE_HEAD; |
| 1775 | |
| 1776 | status = nfsd4_decode_stateid(argp, &clone->cl_src_stateid); |
| 1777 | if (status) |
| 1778 | return status; |
| 1779 | status = nfsd4_decode_stateid(argp, &clone->cl_dst_stateid); |
| 1780 | if (status) |
| 1781 | return status; |
| 1782 | |
| 1783 | READ_BUF(8 + 8 + 8); |
| 1784 | p = xdr_decode_hyper(p, &clone->cl_src_pos); |
| 1785 | p = xdr_decode_hyper(p, &clone->cl_dst_pos); |
| 1786 | p = xdr_decode_hyper(p, &clone->cl_count); |
| 1787 | DECODE_TAIL; |
| 1788 | } |
| 1789 | |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1790 | static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, |
| 1791 | struct nl4_server *ns) |
| 1792 | { |
| 1793 | DECODE_HEAD; |
| 1794 | struct nfs42_netaddr *naddr; |
| 1795 | |
| 1796 | READ_BUF(4); |
| 1797 | ns->nl4_type = be32_to_cpup(p++); |
| 1798 | |
| 1799 | /* currently support for 1 inter-server source server */ |
| 1800 | switch (ns->nl4_type) { |
| 1801 | case NL4_NETADDR: |
| 1802 | naddr = &ns->u.nl4_addr; |
| 1803 | |
| 1804 | READ_BUF(4); |
| 1805 | naddr->netid_len = be32_to_cpup(p++); |
| 1806 | if (naddr->netid_len > RPCBIND_MAXNETIDLEN) |
| 1807 | goto xdr_error; |
| 1808 | |
| 1809 | READ_BUF(naddr->netid_len + 4); /* 4 for uaddr len */ |
| 1810 | COPYMEM(naddr->netid, naddr->netid_len); |
| 1811 | |
| 1812 | naddr->addr_len = be32_to_cpup(p++); |
| 1813 | if (naddr->addr_len > RPCBIND_MAXUADDRLEN) |
| 1814 | goto xdr_error; |
| 1815 | |
| 1816 | READ_BUF(naddr->addr_len); |
| 1817 | COPYMEM(naddr->addr, naddr->addr_len); |
| 1818 | break; |
| 1819 | default: |
| 1820 | goto xdr_error; |
| 1821 | } |
| 1822 | DECODE_TAIL; |
| 1823 | } |
| 1824 | |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1825 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1826 | nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) |
| 1827 | { |
| 1828 | DECODE_HEAD; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1829 | struct nl4_server *ns_dummy; |
| 1830 | int i, count; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1831 | |
| 1832 | status = nfsd4_decode_stateid(argp, ©->cp_src_stateid); |
| 1833 | if (status) |
| 1834 | return status; |
| 1835 | status = nfsd4_decode_stateid(argp, ©->cp_dst_stateid); |
| 1836 | if (status) |
| 1837 | return status; |
| 1838 | |
| 1839 | READ_BUF(8 + 8 + 8 + 4 + 4 + 4); |
| 1840 | p = xdr_decode_hyper(p, ©->cp_src_pos); |
| 1841 | p = xdr_decode_hyper(p, ©->cp_dst_pos); |
| 1842 | p = xdr_decode_hyper(p, ©->cp_count); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 1843 | p++; /* ca_consecutive: we always do consecutive copies */ |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1844 | copy->cp_synchronous = be32_to_cpup(p++); |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1845 | |
| 1846 | count = be32_to_cpup(p++); |
| 1847 | |
| 1848 | copy->cp_intra = false; |
| 1849 | if (count == 0) { /* intra-server copy */ |
| 1850 | copy->cp_intra = true; |
| 1851 | goto intra; |
| 1852 | } |
| 1853 | |
| 1854 | /* decode all the supplied server addresses but use first */ |
| 1855 | status = nfsd4_decode_nl4_server(argp, ©->cp_src); |
| 1856 | if (status) |
| 1857 | return status; |
| 1858 | |
| 1859 | ns_dummy = kmalloc(sizeof(struct nl4_server), GFP_KERNEL); |
| 1860 | if (ns_dummy == NULL) |
| 1861 | return nfserrno(-ENOMEM); |
| 1862 | for (i = 0; i < count - 1; i++) { |
| 1863 | status = nfsd4_decode_nl4_server(argp, ns_dummy); |
| 1864 | if (status) { |
| 1865 | kfree(ns_dummy); |
| 1866 | return status; |
| 1867 | } |
| 1868 | } |
| 1869 | kfree(ns_dummy); |
| 1870 | intra: |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1871 | |
| 1872 | DECODE_TAIL; |
| 1873 | } |
| 1874 | |
| 1875 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 1876 | nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp, |
| 1877 | struct nfsd4_offload_status *os) |
| 1878 | { |
| 1879 | return nfsd4_decode_stateid(argp, &os->stateid); |
| 1880 | } |
| 1881 | |
| 1882 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1883 | nfsd4_decode_copy_notify(struct nfsd4_compoundargs *argp, |
| 1884 | struct nfsd4_copy_notify *cn) |
| 1885 | { |
Chuck Lever | 5aff7d0 | 2020-09-11 14:47:59 -0400 | [diff] [blame] | 1886 | __be32 status; |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1887 | |
| 1888 | status = nfsd4_decode_stateid(argp, &cn->cpn_src_stateid); |
| 1889 | if (status) |
| 1890 | return status; |
| 1891 | return nfsd4_decode_nl4_server(argp, &cn->cpn_dst); |
| 1892 | } |
| 1893 | |
| 1894 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1895 | nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek) |
| 1896 | { |
| 1897 | DECODE_HEAD; |
| 1898 | |
| 1899 | status = nfsd4_decode_stateid(argp, &seek->seek_stateid); |
| 1900 | if (status) |
| 1901 | return status; |
| 1902 | |
| 1903 | READ_BUF(8 + 4); |
| 1904 | p = xdr_decode_hyper(p, &seek->seek_offset); |
| 1905 | seek->seek_whence = be32_to_cpup(p); |
| 1906 | |
| 1907 | DECODE_TAIL; |
| 1908 | } |
| 1909 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1910 | /* |
| 1911 | * XDR data that is more than PAGE_SIZE in size is normally part of a |
| 1912 | * read or write. However, the size of extended attributes is limited |
| 1913 | * by the maximum request size, and then further limited by the underlying |
| 1914 | * filesystem limits. This can exceed PAGE_SIZE (currently, XATTR_SIZE_MAX |
| 1915 | * is 64k). Since there is no kvec- or page-based interface to xattrs, |
| 1916 | * and we're not dealing with contiguous pages, we need to do some copying. |
| 1917 | */ |
| 1918 | |
| 1919 | /* |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1920 | * Decode data into buffer. |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1921 | */ |
| 1922 | static __be32 |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1923 | nfsd4_vbuf_from_vector(struct nfsd4_compoundargs *argp, struct xdr_buf *xdr, |
| 1924 | char **bufp, u32 buflen) |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1925 | { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1926 | struct page **pages = xdr->pages; |
| 1927 | struct kvec *head = xdr->head; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1928 | char *tmp, *dp; |
| 1929 | u32 len; |
| 1930 | |
| 1931 | if (buflen <= head->iov_len) { |
| 1932 | /* |
| 1933 | * We're in luck, the head has enough space. Just return |
| 1934 | * the head, no need for copying. |
| 1935 | */ |
| 1936 | *bufp = head->iov_base; |
| 1937 | return 0; |
| 1938 | } |
| 1939 | |
| 1940 | tmp = svcxdr_tmpalloc(argp, buflen); |
| 1941 | if (tmp == NULL) |
| 1942 | return nfserr_jukebox; |
| 1943 | |
| 1944 | dp = tmp; |
| 1945 | memcpy(dp, head->iov_base, head->iov_len); |
| 1946 | buflen -= head->iov_len; |
| 1947 | dp += head->iov_len; |
| 1948 | |
| 1949 | while (buflen > 0) { |
| 1950 | len = min_t(u32, buflen, PAGE_SIZE); |
| 1951 | memcpy(dp, page_address(*pages), len); |
| 1952 | |
| 1953 | buflen -= len; |
| 1954 | dp += len; |
| 1955 | pages++; |
| 1956 | } |
| 1957 | |
| 1958 | *bufp = tmp; |
| 1959 | return 0; |
| 1960 | } |
| 1961 | |
| 1962 | /* |
| 1963 | * Get a user extended attribute name from the XDR buffer. |
| 1964 | * It will not have the "user." prefix, so prepend it. |
| 1965 | * Lastly, check for nul characters in the name. |
| 1966 | */ |
| 1967 | static __be32 |
| 1968 | nfsd4_decode_xattr_name(struct nfsd4_compoundargs *argp, char **namep) |
| 1969 | { |
| 1970 | DECODE_HEAD; |
| 1971 | char *name, *sp, *dp; |
| 1972 | u32 namelen, cnt; |
| 1973 | |
| 1974 | READ_BUF(4); |
| 1975 | namelen = be32_to_cpup(p++); |
| 1976 | |
| 1977 | if (namelen > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) |
| 1978 | return nfserr_nametoolong; |
| 1979 | |
| 1980 | if (namelen == 0) |
| 1981 | goto xdr_error; |
| 1982 | |
| 1983 | READ_BUF(namelen); |
| 1984 | |
| 1985 | name = svcxdr_tmpalloc(argp, namelen + XATTR_USER_PREFIX_LEN + 1); |
| 1986 | if (!name) |
| 1987 | return nfserr_jukebox; |
| 1988 | |
| 1989 | memcpy(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); |
| 1990 | |
| 1991 | /* |
| 1992 | * Copy the extended attribute name over while checking for 0 |
| 1993 | * characters. |
| 1994 | */ |
| 1995 | sp = (char *)p; |
| 1996 | dp = name + XATTR_USER_PREFIX_LEN; |
| 1997 | cnt = namelen; |
| 1998 | |
| 1999 | while (cnt-- > 0) { |
| 2000 | if (*sp == '\0') |
| 2001 | goto xdr_error; |
| 2002 | *dp++ = *sp++; |
| 2003 | } |
| 2004 | *dp = '\0'; |
| 2005 | |
| 2006 | *namep = name; |
| 2007 | |
| 2008 | DECODE_TAIL; |
| 2009 | } |
| 2010 | |
| 2011 | /* |
| 2012 | * A GETXATTR op request comes without a length specifier. We just set the |
| 2013 | * maximum length for the reply based on XATTR_SIZE_MAX and the maximum |
| 2014 | * channel reply size. nfsd_getxattr will probe the length of the xattr, |
| 2015 | * check it against getxa_len, and allocate + return the value. |
| 2016 | */ |
| 2017 | static __be32 |
| 2018 | nfsd4_decode_getxattr(struct nfsd4_compoundargs *argp, |
| 2019 | struct nfsd4_getxattr *getxattr) |
| 2020 | { |
| 2021 | __be32 status; |
| 2022 | u32 maxcount; |
| 2023 | |
| 2024 | status = nfsd4_decode_xattr_name(argp, &getxattr->getxa_name); |
| 2025 | if (status) |
| 2026 | return status; |
| 2027 | |
| 2028 | maxcount = svc_max_payload(argp->rqstp); |
| 2029 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2030 | |
| 2031 | getxattr->getxa_len = maxcount; |
| 2032 | |
| 2033 | return status; |
| 2034 | } |
| 2035 | |
| 2036 | static __be32 |
| 2037 | nfsd4_decode_setxattr(struct nfsd4_compoundargs *argp, |
| 2038 | struct nfsd4_setxattr *setxattr) |
| 2039 | { |
| 2040 | DECODE_HEAD; |
| 2041 | u32 flags, maxcount, size; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2042 | |
| 2043 | READ_BUF(4); |
| 2044 | flags = be32_to_cpup(p++); |
| 2045 | |
| 2046 | if (flags > SETXATTR4_REPLACE) |
| 2047 | return nfserr_inval; |
| 2048 | setxattr->setxa_flags = flags; |
| 2049 | |
| 2050 | status = nfsd4_decode_xattr_name(argp, &setxattr->setxa_name); |
| 2051 | if (status) |
| 2052 | return status; |
| 2053 | |
| 2054 | maxcount = svc_max_payload(argp->rqstp); |
| 2055 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2056 | |
| 2057 | READ_BUF(4); |
| 2058 | size = be32_to_cpup(p++); |
| 2059 | if (size > maxcount) |
| 2060 | return nfserr_xattr2big; |
| 2061 | |
| 2062 | setxattr->setxa_len = size; |
| 2063 | if (size > 0) { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2064 | struct xdr_buf payload; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2065 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2066 | if (!xdr_stream_subsegment(argp->xdr, &payload, size)) |
| 2067 | goto xdr_error; |
| 2068 | status = nfsd4_vbuf_from_vector(argp, &payload, |
| 2069 | &setxattr->setxa_buf, size); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | DECODE_TAIL; |
| 2073 | } |
| 2074 | |
| 2075 | static __be32 |
| 2076 | nfsd4_decode_listxattrs(struct nfsd4_compoundargs *argp, |
| 2077 | struct nfsd4_listxattrs *listxattrs) |
| 2078 | { |
| 2079 | DECODE_HEAD; |
| 2080 | u32 maxcount; |
| 2081 | |
| 2082 | READ_BUF(12); |
| 2083 | p = xdr_decode_hyper(p, &listxattrs->lsxa_cookie); |
| 2084 | |
| 2085 | /* |
| 2086 | * If the cookie is too large to have even one user.x attribute |
| 2087 | * plus trailing '\0' left in a maximum size buffer, it's invalid. |
| 2088 | */ |
| 2089 | if (listxattrs->lsxa_cookie >= |
| 2090 | (XATTR_LIST_MAX / (XATTR_USER_PREFIX_LEN + 2))) |
| 2091 | return nfserr_badcookie; |
| 2092 | |
| 2093 | maxcount = be32_to_cpup(p++); |
| 2094 | if (maxcount < 8) |
| 2095 | /* Always need at least 2 words (length and one character) */ |
| 2096 | return nfserr_inval; |
| 2097 | |
| 2098 | maxcount = min(maxcount, svc_max_payload(argp->rqstp)); |
| 2099 | listxattrs->lsxa_maxcount = maxcount; |
| 2100 | |
| 2101 | DECODE_TAIL; |
| 2102 | } |
| 2103 | |
| 2104 | static __be32 |
| 2105 | nfsd4_decode_removexattr(struct nfsd4_compoundargs *argp, |
| 2106 | struct nfsd4_removexattr *removexattr) |
| 2107 | { |
| 2108 | return nfsd4_decode_xattr_name(argp, &removexattr->rmxa_name); |
| 2109 | } |
| 2110 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2111 | static __be32 |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2112 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) |
| 2113 | { |
| 2114 | return nfs_ok; |
| 2115 | } |
| 2116 | |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2117 | static __be32 |
| 2118 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
| 2119 | { |
Benny Halevy | 1e685ec | 2009-03-04 23:06:06 +0200 | [diff] [blame] | 2120 | return nfserr_notsupp; |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2121 | } |
| 2122 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2123 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
| 2124 | |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 2125 | static const nfsd4_dec nfsd4_dec_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2126 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
| 2127 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, |
| 2128 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, |
| 2129 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, |
| 2130 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2131 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, |
| 2132 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, |
| 2133 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2134 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, |
| 2135 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, |
| 2136 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, |
| 2137 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, |
| 2138 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, |
| 2139 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, |
| 2140 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2141 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, |
| 2142 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2143 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
| 2144 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
| 2145 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2146 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2147 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2148 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
| 2149 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
| 2150 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, |
| 2151 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, |
| 2152 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, |
| 2153 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, |
| 2154 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2155 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2156 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, |
| 2157 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, |
| 2158 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, |
| 2159 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, |
| 2160 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2161 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, |
| 2162 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2163 | |
| 2164 | /* new operations for NFSv4.1 */ |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 2165 | [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2166 | [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] | 2167 | [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, |
| 2168 | [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, |
| 2169 | [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 2170 | [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2171 | [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2172 | #ifdef CONFIG_NFSD_PNFS |
| 2173 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_getdeviceinfo, |
| 2174 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2175 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_layoutcommit, |
| 2176 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_layoutget, |
| 2177 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_layoutreturn, |
| 2178 | #else |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2179 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2180 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2181 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2182 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2183 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2184 | #endif |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 2185 | [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2186 | [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence, |
| 2187 | [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 2188 | [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2189 | [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 2190 | [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 2191 | [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2192 | |
| 2193 | /* new operations for NFSv4.2 */ |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 2194 | [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2195 | [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2196 | [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_copy_notify, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 2197 | [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2198 | [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2199 | [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2200 | [OP_LAYOUTSTATS] = (nfsd4_dec)nfsd4_decode_notsupp, |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 2201 | [OP_OFFLOAD_CANCEL] = (nfsd4_dec)nfsd4_decode_offload_status, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 2202 | [OP_OFFLOAD_STATUS] = (nfsd4_dec)nfsd4_decode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2203 | [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_read, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2204 | [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2205 | [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 2206 | [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2207 | /* RFC 8276 extended atributes operations */ |
| 2208 | [OP_GETXATTR] = (nfsd4_dec)nfsd4_decode_getxattr, |
| 2209 | [OP_SETXATTR] = (nfsd4_dec)nfsd4_decode_setxattr, |
| 2210 | [OP_LISTXATTRS] = (nfsd4_dec)nfsd4_decode_listxattrs, |
| 2211 | [OP_REMOVEXATTR] = (nfsd4_dec)nfsd4_decode_removexattr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2212 | }; |
| 2213 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2214 | static inline bool |
| 2215 | nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op) |
| 2216 | { |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2217 | if (op->opnum < FIRST_NFS4_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2218 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2219 | else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2220 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2221 | else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP) |
| 2222 | return false; |
| 2223 | else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2224 | return false; |
| 2225 | return true; |
| 2226 | } |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 2227 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2228 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
| 2230 | { |
| 2231 | DECODE_HEAD; |
| 2232 | struct nfsd4_op *op; |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2233 | bool cachethis = false; |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2234 | int auth_slack= argp->rqstp->rq_auth_slack; |
| 2235 | int max_reply = auth_slack + 8; /* opcnt, status */ |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2236 | int readcount = 0; |
| 2237 | int readbytes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | int i; |
| 2239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2241 | argp->taglen = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2242 | READ_BUF(argp->taglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | SAVEMEM(argp->tag, argp->taglen); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2244 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2245 | argp->minorversion = be32_to_cpup(p++); |
| 2246 | argp->opcnt = be32_to_cpup(p++); |
J. Bruce Fields | 4f0cefb | 2014-03-11 15:39:13 -0400 | [diff] [blame] | 2247 | max_reply += 4 + (XDR_QUADLEN(argp->taglen) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | |
| 2249 | if (argp->taglen > NFSD4_MAX_TAGLEN) |
| 2250 | goto xdr_error; |
J. Bruce Fields | 0078117 | 2017-11-15 12:30:27 -0500 | [diff] [blame] | 2251 | /* |
| 2252 | * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS |
| 2253 | * here, so we return success at the xdr level so that |
| 2254 | * nfsd4_proc can handle this is an NFS-level error. |
| 2255 | */ |
| 2256 | if (argp->opcnt > NFSD_MAX_OPS_PER_COMPOUND) |
| 2257 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 2259 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
J. Bruce Fields | 5d6031c | 2014-07-17 16:20:39 -0400 | [diff] [blame] | 2260 | argp->ops = kzalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | if (!argp->ops) { |
| 2262 | argp->ops = argp->iops; |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 2263 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | goto xdr_error; |
| 2265 | } |
| 2266 | } |
| 2267 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2268 | if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION) |
Benny Halevy | 30cff1f | 2008-07-02 11:13:18 +0300 | [diff] [blame] | 2269 | argp->opcnt = 0; |
| 2270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | for (i = 0; i < argp->opcnt; i++) { |
| 2272 | op = &argp->ops[i]; |
| 2273 | op->replay = NULL; |
| 2274 | |
J. Bruce Fields | 8a61b18 | 2012-11-16 22:28:38 -0500 | [diff] [blame] | 2275 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2276 | op->opnum = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2278 | if (nfsd4_opnum_in_range(argp, op)) { |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2279 | op->status = nfsd4_dec_ops[op->opnum](argp, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2280 | if (op->status != nfs_ok) |
| 2281 | trace_nfsd_compound_decode_err(argp->rqstp, |
| 2282 | argp->opcnt, i, |
| 2283 | op->opnum, |
| 2284 | op->status); |
| 2285 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | op->opnum = OP_ILLEGAL; |
| 2287 | op->status = nfserr_op_illegal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | } |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2289 | op->opdesc = OPDESC(op); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2290 | /* |
| 2291 | * We'll try to cache the result in the DRC if any one |
| 2292 | * op in the compound wants to be cached: |
| 2293 | */ |
| 2294 | cachethis |= nfsd4_cache_this_op(op); |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 2295 | |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2296 | if (op->opnum == OP_READ || op->opnum == OP_READ_PLUS) { |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2297 | readcount++; |
| 2298 | readbytes += nfsd4_max_reply(argp->rqstp, op); |
| 2299 | } else |
| 2300 | max_reply += nfsd4_max_reply(argp->rqstp, op); |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2301 | /* |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2302 | * OP_LOCK and OP_LOCKT may return a conflicting lock. |
| 2303 | * (Special case because it will just skip encoding this |
| 2304 | * if it runs out of xdr buffer space, and it is the only |
| 2305 | * operation that behaves this way.) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2306 | */ |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2307 | if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2308 | max_reply += NFS4_OPAQUE_LIMIT; |
J. Bruce Fields | e372ba6 | 2014-05-19 12:27:11 -0400 | [diff] [blame] | 2309 | |
| 2310 | if (op->status) { |
| 2311 | argp->opcnt = i+1; |
| 2312 | break; |
| 2313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | } |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2315 | /* Sessions make the DRC unnecessary: */ |
| 2316 | if (argp->minorversion) |
| 2317 | cachethis = false; |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2318 | svc_reserve(argp->rqstp, max_reply + readbytes); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2319 | argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2321 | if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack) |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 2322 | clear_bit(RQ_SPLICE_OK, &argp->rqstp->rq_flags); |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | DECODE_TAIL; |
| 2325 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2327 | static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode, |
| 2328 | struct svc_export *exp) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2329 | { |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2330 | if (exp->ex_flags & NFSEXP_V4ROOT) { |
| 2331 | *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time)); |
| 2332 | *p++ = 0; |
| 2333 | } else if (IS_I_VERSION(inode)) { |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 2334 | p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode)); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2335 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2336 | *p++ = cpu_to_be32(stat->ctime.tv_sec); |
| 2337 | *p++ = cpu_to_be32(stat->ctime.tv_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2338 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2339 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2340 | } |
| 2341 | |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2342 | /* |
| 2343 | * ctime (in NFSv4, time_metadata) is not writeable, and the client |
| 2344 | * doesn't really care what resolution could theoretically be stored by |
| 2345 | * the filesystem. |
| 2346 | * |
| 2347 | * The client cares how close together changes can be while still |
| 2348 | * guaranteeing ctime changes. For most filesystems (which have |
| 2349 | * timestamps with nanosecond fields) that is limited by the resolution |
| 2350 | * of the time returned from current_time() (which I'm assuming to be |
| 2351 | * 1/HZ). |
| 2352 | */ |
| 2353 | static __be32 *encode_time_delta(__be32 *p, struct inode *inode) |
| 2354 | { |
Arnd Bergmann | e4598e3 | 2019-10-31 15:14:03 +0100 | [diff] [blame] | 2355 | struct timespec64 ts; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2356 | u32 ns; |
| 2357 | |
| 2358 | 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] | 2359 | ts = ns_to_timespec64(ns); |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2360 | |
| 2361 | p = xdr_encode_hyper(p, ts.tv_sec); |
| 2362 | *p++ = cpu_to_be32(ts.tv_nsec); |
| 2363 | |
| 2364 | return p; |
| 2365 | } |
| 2366 | |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2367 | static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2368 | { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2369 | *p++ = cpu_to_be32(c->atomic); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2370 | if (c->change_supported) { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2371 | p = xdr_encode_hyper(p, c->before_change); |
| 2372 | p = xdr_encode_hyper(p, c->after_change); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2373 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2374 | *p++ = cpu_to_be32(c->before_ctime_sec); |
| 2375 | *p++ = cpu_to_be32(c->before_ctime_nsec); |
| 2376 | *p++ = cpu_to_be32(c->after_ctime_sec); |
| 2377 | *p++ = cpu_to_be32(c->after_ctime_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2378 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2379 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2382 | /* Encode as an array of strings the string given with components |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2383 | * separated @sep, escaped with esc_enter and esc_exit. |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2384 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2385 | static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, |
| 2386 | char *components, char esc_enter, |
| 2387 | char esc_exit) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2388 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2389 | __be32 *p; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2390 | __be32 pathlen; |
| 2391 | int pathlen_offset; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2392 | int strlen, count=0; |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2393 | char *str, *end, *next; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2394 | |
| 2395 | dprintk("nfsd4_encode_components(%s)\n", components); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2396 | |
| 2397 | pathlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2398 | p = xdr_reserve_space(xdr, 4); |
| 2399 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2400 | return nfserr_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2401 | p++; /* We will fill this in with @count later */ |
| 2402 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2403 | end = str = components; |
| 2404 | while (*end) { |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2405 | bool found_esc = false; |
| 2406 | |
| 2407 | /* try to parse as esc_start, ..., esc_end, sep */ |
| 2408 | if (*str == esc_enter) { |
| 2409 | for (; *end && (*end != esc_exit); end++) |
| 2410 | /* find esc_exit or end of string */; |
| 2411 | next = end + 1; |
| 2412 | if (*end && (!*next || *next == sep)) { |
| 2413 | str++; |
| 2414 | found_esc = true; |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | if (!found_esc) |
| 2419 | for (; *end && (*end != sep); end++) |
| 2420 | /* find sep or end of string */; |
| 2421 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2422 | strlen = end - str; |
| 2423 | if (strlen) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2424 | p = xdr_reserve_space(xdr, strlen + 4); |
| 2425 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2426 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2427 | p = xdr_encode_opaque(p, str, strlen); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2428 | count++; |
| 2429 | } |
| 2430 | else |
| 2431 | end++; |
Benjamin Coddington | 5a64e56 | 2014-12-07 16:05:47 -0500 | [diff] [blame] | 2432 | if (found_esc) |
| 2433 | end = next; |
| 2434 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2435 | str = end; |
| 2436 | } |
Benjamin Coddington | bf7491f | 2014-12-07 16:05:48 -0500 | [diff] [blame] | 2437 | pathlen = htonl(count); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2438 | write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2439 | return 0; |
| 2440 | } |
| 2441 | |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2442 | /* Encode as an array of strings the string given with components |
| 2443 | * separated @sep. |
| 2444 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2445 | static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep, |
| 2446 | char *components) |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2447 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2448 | return nfsd4_encode_components_esc(xdr, sep, components, 0, 0); |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2449 | } |
| 2450 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2451 | /* |
| 2452 | * encode a location element of a fs_locations structure |
| 2453 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2454 | static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr, |
| 2455 | struct nfsd4_fs_location *location) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2456 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2457 | __be32 status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2458 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2459 | status = nfsd4_encode_components_esc(xdr, ':', location->hosts, |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2460 | '[', ']'); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2461 | if (status) |
| 2462 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2463 | status = nfsd4_encode_components(xdr, '/', location->path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2464 | if (status) |
| 2465 | return status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2466 | return 0; |
| 2467 | } |
| 2468 | |
| 2469 | /* |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2470 | * Encode a path in RFC3530 'pathname4' format |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2471 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2472 | static __be32 nfsd4_encode_path(struct xdr_stream *xdr, |
| 2473 | const struct path *root, |
| 2474 | const struct path *path) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2475 | { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2476 | struct path cur = *path; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2477 | __be32 *p; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2478 | struct dentry **components = NULL; |
| 2479 | unsigned int ncomponents = 0; |
| 2480 | __be32 err = nfserr_jukebox; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2481 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2482 | dprintk("nfsd4_encode_components("); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2483 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2484 | path_get(&cur); |
| 2485 | /* First walk the path up to the nfsd root, and store the |
| 2486 | * dentries/path components in an array. |
| 2487 | */ |
| 2488 | for (;;) { |
Kinglong Mee | b77a4b2 | 2015-03-15 23:13:32 +0800 | [diff] [blame] | 2489 | if (path_equal(&cur, root)) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2490 | break; |
| 2491 | if (cur.dentry == cur.mnt->mnt_root) { |
| 2492 | if (follow_up(&cur)) |
| 2493 | continue; |
| 2494 | goto out_free; |
| 2495 | } |
| 2496 | if ((ncomponents & 15) == 0) { |
| 2497 | struct dentry **new; |
| 2498 | new = krealloc(components, |
| 2499 | sizeof(*new) * (ncomponents + 16), |
| 2500 | GFP_KERNEL); |
| 2501 | if (!new) |
| 2502 | goto out_free; |
| 2503 | components = new; |
| 2504 | } |
| 2505 | components[ncomponents++] = cur.dentry; |
| 2506 | cur.dentry = dget_parent(cur.dentry); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2507 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2508 | err = nfserr_resource; |
| 2509 | p = xdr_reserve_space(xdr, 4); |
| 2510 | if (!p) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2511 | goto out_free; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2512 | *p++ = cpu_to_be32(ncomponents); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2513 | |
| 2514 | while (ncomponents) { |
| 2515 | struct dentry *dentry = components[ncomponents - 1]; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2516 | unsigned int len; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2517 | |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2518 | spin_lock(&dentry->d_lock); |
| 2519 | len = dentry->d_name.len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2520 | p = xdr_reserve_space(xdr, len + 4); |
| 2521 | if (!p) { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2522 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2523 | goto out_free; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2524 | } |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2525 | p = xdr_encode_opaque(p, dentry->d_name.name, len); |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 2526 | dprintk("/%pd", dentry); |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2527 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2528 | dput(dentry); |
| 2529 | ncomponents--; |
| 2530 | } |
| 2531 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2532 | err = 0; |
| 2533 | out_free: |
| 2534 | dprintk(")\n"); |
| 2535 | while (ncomponents) |
| 2536 | dput(components[--ncomponents]); |
| 2537 | kfree(components); |
| 2538 | path_put(&cur); |
| 2539 | return err; |
| 2540 | } |
| 2541 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2542 | static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr, |
| 2543 | struct svc_rqst *rqstp, const struct path *path) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2544 | { |
| 2545 | struct svc_export *exp_ps; |
| 2546 | __be32 res; |
| 2547 | |
| 2548 | exp_ps = rqst_find_fsidzero_export(rqstp); |
| 2549 | if (IS_ERR(exp_ps)) |
| 2550 | return nfserrno(PTR_ERR(exp_ps)); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2551 | res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2552 | exp_put(exp_ps); |
| 2553 | return res; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | /* |
| 2557 | * encode a fs_locations structure |
| 2558 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2559 | static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr, |
| 2560 | struct svc_rqst *rqstp, struct svc_export *exp) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2561 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2562 | __be32 status; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 2563 | int i; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2564 | __be32 *p; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2565 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2566 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2567 | status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2568 | if (status) |
| 2569 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2570 | p = xdr_reserve_space(xdr, 4); |
| 2571 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2572 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2573 | *p++ = cpu_to_be32(fslocs->locations_count); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2574 | for (i=0; i<fslocs->locations_count; i++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2575 | status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2576 | if (status) |
| 2577 | return status; |
| 2578 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2579 | return 0; |
| 2580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2582 | static u32 nfs4_file_type(umode_t mode) |
| 2583 | { |
| 2584 | switch (mode & S_IFMT) { |
| 2585 | case S_IFIFO: return NF4FIFO; |
| 2586 | case S_IFCHR: return NF4CHR; |
| 2587 | case S_IFDIR: return NF4DIR; |
| 2588 | case S_IFBLK: return NF4BLK; |
| 2589 | case S_IFLNK: return NF4LNK; |
| 2590 | case S_IFREG: return NF4REG; |
| 2591 | case S_IFSOCK: return NF4SOCK; |
| 2592 | default: return NF4BAD; |
Tom Rix | 25fef48 | 2020-11-01 07:32:34 -0800 | [diff] [blame] | 2593 | } |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2596 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2597 | nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2598 | struct nfs4_ace *ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | { |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2600 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2601 | return nfs4_acl_write_who(xdr, ace->whotype); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2602 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2603 | return nfsd4_encode_group(xdr, rqstp, ace->who_gid); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2604 | else |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2605 | return nfsd4_encode_user(xdr, rqstp, ace->who_uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2608 | static inline __be32 |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2609 | nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2610 | { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2611 | __be32 *p; |
| 2612 | unsigned long i = hweight_long(layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2613 | |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2614 | p = xdr_reserve_space(xdr, 4 + 4 * i); |
| 2615 | if (!p) |
| 2616 | return nfserr_resource; |
| 2617 | |
| 2618 | *p++ = cpu_to_be32(i); |
| 2619 | |
| 2620 | for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) |
| 2621 | if (layout_types & (1 << i)) |
| 2622 | *p++ = cpu_to_be32(i); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2623 | |
| 2624 | return 0; |
| 2625 | } |
| 2626 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2627 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
| 2628 | FATTR4_WORD0_RDATTR_ERROR) |
| 2629 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2630 | #define WORD2_ABSENT_FS_ATTRS 0 |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2631 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2632 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 2633 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2634 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2635 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2636 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2637 | __be32 *p; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2638 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2639 | p = xdr_reserve_space(xdr, len + 4 + 4 + 4); |
| 2640 | if (!p) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2641 | return nfserr_resource; |
| 2642 | |
| 2643 | /* |
| 2644 | * For now we use a 0 here to indicate the null translation; in |
| 2645 | * the future we may place a call to translation code here. |
| 2646 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2647 | *p++ = cpu_to_be32(0); /* lfs */ |
| 2648 | *p++ = cpu_to_be32(0); /* pi */ |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2649 | p = xdr_encode_opaque(p, context, len); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2650 | return 0; |
| 2651 | } |
| 2652 | #else |
| 2653 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2654 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2655 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2656 | { return 0; } |
| 2657 | #endif |
| 2658 | |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2659 | 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] | 2660 | { |
| 2661 | /* As per referral draft: */ |
| 2662 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || |
| 2663 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { |
| 2664 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || |
| 2665 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) |
| 2666 | *rdattr_err = NFSERR_MOVED; |
| 2667 | else |
| 2668 | return nfserr_moved; |
| 2669 | } |
| 2670 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; |
| 2671 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2672 | *bmval2 &= WORD2_ABSENT_FS_ATTRS; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2673 | return 0; |
| 2674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2676 | |
| 2677 | static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) |
| 2678 | { |
| 2679 | struct path path = exp->ex_path; |
| 2680 | int err; |
| 2681 | |
| 2682 | path_get(&path); |
| 2683 | while (follow_up(&path)) { |
| 2684 | if (path.dentry != path.mnt->mnt_root) |
| 2685 | break; |
| 2686 | } |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2687 | 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] | 2688 | path_put(&path); |
| 2689 | return err; |
| 2690 | } |
| 2691 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2692 | static __be32 |
| 2693 | nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2) |
| 2694 | { |
| 2695 | __be32 *p; |
| 2696 | |
| 2697 | if (bmval2) { |
| 2698 | p = xdr_reserve_space(xdr, 16); |
| 2699 | if (!p) |
| 2700 | goto out_resource; |
| 2701 | *p++ = cpu_to_be32(3); |
| 2702 | *p++ = cpu_to_be32(bmval0); |
| 2703 | *p++ = cpu_to_be32(bmval1); |
| 2704 | *p++ = cpu_to_be32(bmval2); |
| 2705 | } else if (bmval1) { |
| 2706 | p = xdr_reserve_space(xdr, 12); |
| 2707 | if (!p) |
| 2708 | goto out_resource; |
| 2709 | *p++ = cpu_to_be32(2); |
| 2710 | *p++ = cpu_to_be32(bmval0); |
| 2711 | *p++ = cpu_to_be32(bmval1); |
| 2712 | } else { |
| 2713 | p = xdr_reserve_space(xdr, 8); |
| 2714 | if (!p) |
| 2715 | goto out_resource; |
| 2716 | *p++ = cpu_to_be32(1); |
| 2717 | *p++ = cpu_to_be32(bmval0); |
| 2718 | } |
| 2719 | |
| 2720 | return 0; |
| 2721 | out_resource: |
| 2722 | return nfserr_resource; |
| 2723 | } |
| 2724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | /* |
| 2726 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle |
| 2727 | * ourselves. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | */ |
Jeff Layton | da2ebce | 2014-05-30 09:09:25 -0400 | [diff] [blame] | 2729 | static __be32 |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 2730 | nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, |
| 2731 | struct svc_export *exp, |
| 2732 | struct dentry *dentry, u32 *bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2733 | struct svc_rqst *rqstp, int ignore_crossmnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | { |
| 2735 | u32 bmval0 = bmval[0]; |
| 2736 | u32 bmval1 = bmval[1]; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2737 | u32 bmval2 = bmval[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | struct kstat stat; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2739 | struct svc_fh *tempfh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | struct kstatfs statfs; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2741 | __be32 *p; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 2742 | int starting_len = xdr->buf->len; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2743 | int attrlen_offset; |
| 2744 | __be32 attrlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | u32 dummy; |
| 2746 | u64 dummy64; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2747 | u32 rdattr_err = 0; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2748 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2749 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | struct nfs4_acl *acl = NULL; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2751 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2752 | void *context = NULL; |
| 2753 | int contextlen; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2754 | #endif |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2755 | bool contextsupport = false; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2756 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 2757 | u32 minorversion = resp->cstate.minorversion; |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2758 | struct path path = { |
| 2759 | .mnt = exp->ex_path.mnt, |
| 2760 | .dentry = dentry, |
| 2761 | }; |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 2762 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
| 2764 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2765 | BUG_ON(!nfsd_attrs_supported(minorversion, bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2767 | if (exp->ex_fslocs.migrated) { |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2768 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err); |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2769 | if (status) |
| 2770 | goto out; |
| 2771 | } |
| 2772 | |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2773 | 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] | 2774 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | goto out_nfserr; |
Christoph Hellwig | 1233790 | 2014-05-28 10:46:13 +0200 | [diff] [blame] | 2776 | if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | |
| 2777 | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
| 2779 | FATTR4_WORD1_SPACE_TOTAL))) { |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2780 | err = vfs_statfs(&path, &statfs); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2781 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | goto out_nfserr; |
| 2783 | } |
| 2784 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2785 | tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
| 2786 | status = nfserr_jukebox; |
| 2787 | if (!tempfh) |
| 2788 | goto out; |
| 2789 | fh_init(tempfh, NFS4_FHSIZE); |
| 2790 | status = fh_compose(tempfh, exp, dentry, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | if (status) |
| 2792 | goto out; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2793 | fhp = tempfh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | } |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2795 | if (bmval0 & FATTR4_WORD0_ACL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2796 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2797 | if (err == -EOPNOTSUPP) |
| 2798 | bmval0 &= ~FATTR4_WORD0_ACL; |
| 2799 | else if (err == -EINVAL) { |
| 2800 | status = nfserr_attrnotsupp; |
| 2801 | goto out; |
| 2802 | } else if (err != 0) |
| 2803 | goto out_nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2806 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2807 | if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) || |
| 2808 | bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2809 | if (exp->ex_flags & NFSEXP_SECURITY_LABEL) |
| 2810 | err = security_inode_getsecctx(d_inode(dentry), |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2811 | &context, &contextlen); |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2812 | else |
| 2813 | err = -EOPNOTSUPP; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2814 | contextsupport = (err == 0); |
| 2815 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 2816 | if (err == -EOPNOTSUPP) |
| 2817 | bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2818 | else if (err) |
| 2819 | goto out_nfserr; |
| 2820 | } |
| 2821 | } |
| 2822 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
| 2823 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2824 | status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2); |
| 2825 | if (status) |
| 2826 | goto out; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2827 | |
| 2828 | attrlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2829 | p = xdr_reserve_space(xdr, 4); |
| 2830 | if (!p) |
| 2831 | goto out_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2832 | p++; /* to be backfilled later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | |
| 2834 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | dcd20869 | 2017-01-11 20:34:50 -0500 | [diff] [blame] | 2835 | u32 supp[3]; |
| 2836 | |
| 2837 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2838 | |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2839 | if (!IS_POSIXACL(dentry->d_inode)) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2840 | supp[0] &= ~FATTR4_WORD0_ACL; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2841 | if (!contextsupport) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2842 | supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2843 | if (!supp[2]) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2844 | p = xdr_reserve_space(xdr, 12); |
| 2845 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2846 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2847 | *p++ = cpu_to_be32(2); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2848 | *p++ = cpu_to_be32(supp[0]); |
| 2849 | *p++ = cpu_to_be32(supp[1]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2850 | } else { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2851 | p = xdr_reserve_space(xdr, 16); |
| 2852 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2853 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2854 | *p++ = cpu_to_be32(3); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2855 | *p++ = cpu_to_be32(supp[0]); |
| 2856 | *p++ = cpu_to_be32(supp[1]); |
| 2857 | *p++ = cpu_to_be32(supp[2]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | } |
| 2860 | if (bmval0 & FATTR4_WORD0_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2861 | p = xdr_reserve_space(xdr, 4); |
| 2862 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | goto out_resource; |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2864 | dummy = nfs4_file_type(stat.mode); |
J. Bruce Fields | 6b6d8137 | 2013-01-16 17:11:11 -0500 | [diff] [blame] | 2865 | if (dummy == NF4BAD) { |
| 2866 | status = nfserr_serverfault; |
| 2867 | goto out; |
| 2868 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2869 | *p++ = cpu_to_be32(dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | } |
| 2871 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2872 | p = xdr_reserve_space(xdr, 4); |
| 2873 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | goto out_resource; |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2875 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2876 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT); |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2877 | else |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2878 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT| |
| 2879 | NFS4_FH_VOL_RENAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | } |
| 2881 | if (bmval0 & FATTR4_WORD0_CHANGE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2882 | p = xdr_reserve_space(xdr, 8); |
| 2883 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | goto out_resource; |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2885 | p = encode_change(p, &stat, d_inode(dentry), exp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | } |
| 2887 | if (bmval0 & FATTR4_WORD0_SIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2888 | p = xdr_reserve_space(xdr, 8); |
| 2889 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2891 | p = xdr_encode_hyper(p, stat.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | } |
| 2893 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2894 | p = xdr_reserve_space(xdr, 4); |
| 2895 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2897 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | } |
| 2899 | if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2900 | p = xdr_reserve_space(xdr, 4); |
| 2901 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2903 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | } |
| 2905 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2906 | p = xdr_reserve_space(xdr, 4); |
| 2907 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2909 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | } |
| 2911 | if (bmval0 & FATTR4_WORD0_FSID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2912 | p = xdr_reserve_space(xdr, 16); |
| 2913 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2915 | if (exp->ex_fslocs.migrated) { |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2916 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR); |
| 2917 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2918 | } else switch(fsid_source(fhp)) { |
| 2919 | case FSIDSOURCE_FSID: |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2920 | p = xdr_encode_hyper(p, (u64)exp->ex_fsid); |
| 2921 | p = xdr_encode_hyper(p, (u64)0); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2922 | break; |
| 2923 | case FSIDSOURCE_DEV: |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2924 | *p++ = cpu_to_be32(0); |
| 2925 | *p++ = cpu_to_be32(MAJOR(stat.dev)); |
| 2926 | *p++ = cpu_to_be32(0); |
| 2927 | *p++ = cpu_to_be32(MINOR(stat.dev)); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2928 | break; |
| 2929 | case FSIDSOURCE_UUID: |
Kinglong Mee | 94eb368 | 2014-05-23 20:00:19 +0800 | [diff] [blame] | 2930 | p = xdr_encode_opaque_fixed(p, exp->ex_uuid, |
| 2931 | EX_UUID_LEN); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2932 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | } |
| 2934 | } |
| 2935 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2936 | p = xdr_reserve_space(xdr, 4); |
| 2937 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2939 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | } |
| 2941 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2942 | p = xdr_reserve_space(xdr, 4); |
| 2943 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2945 | *p++ = cpu_to_be32(nn->nfsd4_lease); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | } |
| 2947 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { |
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(rdattr_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | } |
| 2953 | if (bmval0 & FATTR4_WORD0_ACL) { |
| 2954 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | |
| 2956 | if (acl == NULL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2957 | p = xdr_reserve_space(xdr, 4); |
| 2958 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | goto out_resource; |
| 2960 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2961 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | goto out_acl; |
| 2963 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2964 | p = xdr_reserve_space(xdr, 4); |
| 2965 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2967 | *p++ = cpu_to_be32(acl->naces); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 2969 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2970 | p = xdr_reserve_space(xdr, 4*3); |
| 2971 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2973 | *p++ = cpu_to_be32(ace->type); |
| 2974 | *p++ = cpu_to_be32(ace->flag); |
| 2975 | *p++ = cpu_to_be32(ace->access_mask & |
| 2976 | NFS4_ACE_MASK_ALL); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2977 | status = nfsd4_encode_aclname(xdr, rqstp, ace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | if (status) |
| 2979 | goto out; |
| 2980 | } |
| 2981 | } |
| 2982 | out_acl: |
| 2983 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2984 | p = xdr_reserve_space(xdr, 4); |
| 2985 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | goto out_resource; |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2987 | *p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
| 2989 | } |
| 2990 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2991 | p = xdr_reserve_space(xdr, 4); |
| 2992 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2994 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | } |
| 2996 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2997 | p = xdr_reserve_space(xdr, 4); |
| 2998 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3000 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | } |
| 3002 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3003 | p = xdr_reserve_space(xdr, 4); |
| 3004 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3006 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | } |
| 3008 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3009 | p = xdr_reserve_space(xdr, 4); |
| 3010 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3012 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | } |
| 3014 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3015 | p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4); |
| 3016 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | goto out_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3018 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, |
| 3019 | fhp->fh_handle.fh_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | } |
| 3021 | if (bmval0 & FATTR4_WORD0_FILEID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3022 | p = xdr_reserve_space(xdr, 8); |
| 3023 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3025 | p = xdr_encode_hyper(p, stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | } |
| 3027 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3028 | p = xdr_reserve_space(xdr, 8); |
| 3029 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3031 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | } |
| 3033 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3034 | p = xdr_reserve_space(xdr, 8); |
| 3035 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3037 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | } |
| 3039 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3040 | p = xdr_reserve_space(xdr, 8); |
| 3041 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3043 | p = xdr_encode_hyper(p, (u64) statfs.f_files); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3045 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3046 | status = nfsd4_encode_fs_locations(xdr, rqstp, exp); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3047 | if (status) |
| 3048 | goto out; |
| 3049 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
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(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | if (bmval0 & FATTR4_WORD0_MAXFILESIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3057 | p = xdr_reserve_space(xdr, 8); |
| 3058 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3060 | 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] | 3061 | } |
| 3062 | if (bmval0 & FATTR4_WORD0_MAXLINK) { |
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(255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | } |
| 3068 | if (bmval0 & FATTR4_WORD0_MAXNAME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3069 | p = xdr_reserve_space(xdr, 4); |
| 3070 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3072 | *p++ = cpu_to_be32(statfs.f_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | } |
| 3074 | if (bmval0 & FATTR4_WORD0_MAXREAD) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3075 | p = xdr_reserve_space(xdr, 8); |
| 3076 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3078 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | } |
| 3080 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3081 | p = xdr_reserve_space(xdr, 8); |
| 3082 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3084 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | } |
| 3086 | if (bmval1 & FATTR4_WORD1_MODE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3087 | p = xdr_reserve_space(xdr, 4); |
| 3088 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3090 | *p++ = cpu_to_be32(stat.mode & S_IALLUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | } |
| 3092 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3093 | p = xdr_reserve_space(xdr, 4); |
| 3094 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3096 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | } |
| 3098 | if (bmval1 & FATTR4_WORD1_NUMLINKS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3099 | p = xdr_reserve_space(xdr, 4); |
| 3100 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3102 | *p++ = cpu_to_be32(stat.nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | } |
| 3104 | if (bmval1 & FATTR4_WORD1_OWNER) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3105 | status = nfsd4_encode_user(xdr, rqstp, stat.uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | if (status) |
| 3107 | goto out; |
| 3108 | } |
| 3109 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3110 | status = nfsd4_encode_group(xdr, rqstp, stat.gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | if (status) |
| 3112 | goto out; |
| 3113 | } |
| 3114 | if (bmval1 & FATTR4_WORD1_RAWDEV) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3115 | p = xdr_reserve_space(xdr, 8); |
| 3116 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3118 | *p++ = cpu_to_be32((u32) MAJOR(stat.rdev)); |
| 3119 | *p++ = cpu_to_be32((u32) MINOR(stat.rdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | } |
| 3121 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3122 | p = xdr_reserve_space(xdr, 8); |
| 3123 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | goto out_resource; |
| 3125 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3126 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | } |
| 3128 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { |
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; |
| 3132 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3133 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | } |
| 3135 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3136 | p = xdr_reserve_space(xdr, 8); |
| 3137 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | goto out_resource; |
| 3139 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3140 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | } |
| 3142 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3143 | p = xdr_reserve_space(xdr, 8); |
| 3144 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | goto out_resource; |
| 3146 | dummy64 = (u64)stat.blocks << 9; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3147 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | } |
| 3149 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3150 | p = xdr_reserve_space(xdr, 12); |
| 3151 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3153 | p = xdr_encode_hyper(p, (s64)stat.atime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3154 | *p++ = cpu_to_be32(stat.atime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | } |
| 3156 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3157 | p = xdr_reserve_space(xdr, 12); |
| 3158 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | goto out_resource; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 3160 | p = encode_time_delta(p, d_inode(dentry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | } |
| 3162 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3163 | p = xdr_reserve_space(xdr, 12); |
| 3164 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3166 | p = xdr_encode_hyper(p, (s64)stat.ctime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3167 | *p++ = cpu_to_be32(stat.ctime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | } |
| 3169 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3170 | p = xdr_reserve_space(xdr, 12); |
| 3171 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3173 | p = xdr_encode_hyper(p, (s64)stat.mtime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3174 | *p++ = cpu_to_be32(stat.mtime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | } |
| 3176 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3177 | struct kstat parent_stat; |
| 3178 | u64 ino = stat.ino; |
| 3179 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3180 | p = xdr_reserve_space(xdr, 8); |
| 3181 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | goto out_resource; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3183 | /* |
| 3184 | * Get parent's attributes if not ignoring crossmount |
| 3185 | * and this is the root of a cross-mounted filesystem. |
| 3186 | */ |
| 3187 | if (ignore_crossmnt == 0 && |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3188 | dentry == exp->ex_path.mnt->mnt_root) { |
| 3189 | err = get_parent_attributes(exp, &parent_stat); |
| 3190 | if (err) |
| 3191 | goto out_nfserr; |
| 3192 | ino = parent_stat.ino; |
| 3193 | } |
| 3194 | p = xdr_encode_hyper(p, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3196 | #ifdef CONFIG_NFSD_PNFS |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3197 | if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3198 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3199 | if (status) |
| 3200 | goto out; |
| 3201 | } |
| 3202 | |
| 3203 | if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3204 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3205 | if (status) |
| 3206 | goto out; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) { |
| 3210 | p = xdr_reserve_space(xdr, 4); |
| 3211 | if (!p) |
| 3212 | goto out_resource; |
| 3213 | *p++ = cpu_to_be32(stat.blksize); |
| 3214 | } |
| 3215 | #endif /* CONFIG_NFSD_PNFS */ |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3216 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { |
Trond Myklebust | b26b78c | 2017-05-09 16:24:59 -0400 | [diff] [blame] | 3217 | u32 supp[3]; |
| 3218 | |
| 3219 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
| 3220 | supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0; |
| 3221 | supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1; |
| 3222 | supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2; |
| 3223 | |
| 3224 | status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]); |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3225 | if (status) |
| 3226 | goto out; |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3227 | } |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3228 | |
J. Bruce Fields | a858576 | 2018-04-25 13:26:23 -0400 | [diff] [blame] | 3229 | if (bmval2 & FATTR4_WORD2_CHANGE_ATTR_TYPE) { |
| 3230 | p = xdr_reserve_space(xdr, 4); |
| 3231 | if (!p) |
| 3232 | goto out_resource; |
| 3233 | if (IS_I_VERSION(d_inode(dentry))) |
| 3234 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR); |
| 3235 | else |
| 3236 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA); |
| 3237 | } |
| 3238 | |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3239 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3240 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 3241 | status = nfsd4_encode_security_label(xdr, rqstp, context, |
| 3242 | contextlen); |
| 3243 | if (status) |
| 3244 | goto out; |
| 3245 | } |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3246 | #endif |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3247 | |
Frank van der Linden | 0e885e8 | 2020-06-23 22:39:27 +0000 | [diff] [blame] | 3248 | if (bmval2 & FATTR4_WORD2_XATTR_SUPPORT) { |
| 3249 | p = xdr_reserve_space(xdr, 4); |
| 3250 | if (!p) |
| 3251 | goto out_resource; |
| 3252 | err = xattr_supported_namespace(d_inode(dentry), |
| 3253 | XATTR_USER_PREFIX); |
| 3254 | *p++ = cpu_to_be32(err == 0); |
| 3255 | } |
| 3256 | |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 3257 | attrlen = htonl(xdr->buf->len - attrlen_offset - 4); |
| 3258 | write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | status = nfs_ok; |
| 3260 | |
| 3261 | out: |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3262 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3263 | if (context) |
| 3264 | security_release_secctx(context, contextlen); |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3265 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3266 | kfree(acl); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3267 | if (tempfh) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 3268 | fh_put(tempfh); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3269 | kfree(tempfh); |
| 3270 | } |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3271 | if (status) |
| 3272 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | return status; |
| 3274 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 3275 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | goto out; |
| 3277 | out_resource: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | status = nfserr_resource; |
| 3279 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3282 | static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr, |
| 3283 | struct xdr_buf *buf, __be32 *p, int bytes) |
| 3284 | { |
| 3285 | xdr->scratch.iov_len = 0; |
| 3286 | memset(buf, 0, sizeof(struct xdr_buf)); |
| 3287 | buf->head[0].iov_base = p; |
| 3288 | buf->head[0].iov_len = 0; |
| 3289 | buf->len = 0; |
| 3290 | xdr->buf = buf; |
| 3291 | xdr->iov = buf->head; |
| 3292 | xdr->p = p; |
| 3293 | xdr->end = (void *)p + bytes; |
| 3294 | buf->buflen = bytes; |
| 3295 | } |
| 3296 | |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3297 | __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, |
| 3298 | struct svc_fh *fhp, struct svc_export *exp, |
| 3299 | struct dentry *dentry, u32 *bmval, |
| 3300 | struct svc_rqst *rqstp, int ignore_crossmnt) |
| 3301 | { |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3302 | struct xdr_buf dummy; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3303 | struct xdr_stream xdr; |
| 3304 | __be32 ret; |
| 3305 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3306 | svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2); |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3307 | ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp, |
| 3308 | ignore_crossmnt); |
| 3309 | *p = xdr.p; |
| 3310 | return ret; |
| 3311 | } |
| 3312 | |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 3313 | static inline int attributes_need_mount(u32 *bmval) |
| 3314 | { |
| 3315 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) |
| 3316 | return 1; |
| 3317 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 3318 | return 1; |
| 3319 | return 0; |
| 3320 | } |
| 3321 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3322 | static __be32 |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3323 | nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, |
| 3324 | const char *name, int namlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | { |
| 3326 | struct svc_export *exp = cd->rd_fhp->fh_export; |
| 3327 | struct dentry *dentry; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3328 | __be32 nfserr; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3329 | int ignore_crossmnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | |
Al Viro | 6c2d4798 | 2019-10-31 01:21:58 -0400 | [diff] [blame] | 3331 | dentry = lookup_positive_unlocked(name, cd->rd_fhp->fh_dentry, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | if (IS_ERR(dentry)) |
| 3333 | return nfserrno(PTR_ERR(dentry)); |
| 3334 | |
| 3335 | exp_get(exp); |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3336 | /* |
| 3337 | * In the case of a mountpoint, the client may be asking for |
| 3338 | * attributes that are only properties of the underlying filesystem |
| 3339 | * as opposed to the cross-mounted file system. In such a case, |
| 3340 | * we will not follow the cross mount and will fill the attribtutes |
| 3341 | * directly from the mountpoint dentry. |
| 3342 | */ |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3343 | if (nfsd_mountpoint(dentry, exp)) { |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3344 | int err; |
| 3345 | |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3346 | if (!(exp->ex_flags & NFSEXP_V4ROOT) |
| 3347 | && !attributes_need_mount(cd->rd_bmval)) { |
| 3348 | ignore_crossmnt = 1; |
| 3349 | goto out_encode; |
| 3350 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3351 | /* |
| 3352 | * Why the heck aren't we just using nfsd_lookup?? |
| 3353 | * Different "."/".." handling? Something else? |
| 3354 | * At least, add a comment here to explain.... |
| 3355 | */ |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3356 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
| 3357 | if (err) { |
| 3358 | nfserr = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | goto out_put; |
| 3360 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3361 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
| 3362 | if (nfserr) |
| 3363 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | |
| 3365 | } |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3366 | out_encode: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3367 | nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3368 | cd->rd_rqstp, ignore_crossmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | out_put: |
| 3370 | dput(dentry); |
| 3371 | exp_put(exp); |
| 3372 | return nfserr; |
| 3373 | } |
| 3374 | |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3375 | static __be32 * |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3376 | nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | { |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3378 | __be32 *p; |
| 3379 | |
Kinglong Mee | c3a4561 | 2014-07-06 11:34:43 +0800 | [diff] [blame] | 3380 | p = xdr_reserve_space(xdr, 20); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3381 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | return NULL; |
| 3383 | *p++ = htonl(2); |
| 3384 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ |
| 3385 | *p++ = htonl(0); /* bmval1 */ |
| 3386 | |
J. Bruce Fields | 87915c6 | 2013-01-16 17:33:28 -0500 | [diff] [blame] | 3387 | *p++ = htonl(4); /* attribute length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | *p++ = nfserr; /* no htonl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | return p; |
| 3390 | } |
| 3391 | |
| 3392 | static int |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3393 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
| 3394 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | { |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3396 | struct readdir_cd *ccd = ccdv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3398 | struct xdr_stream *xdr = cd->xdr; |
| 3399 | int start_offset = xdr->buf->len; |
| 3400 | int cookie_offset; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3401 | u32 name_and_cookie; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3402 | int entry_bytes; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3403 | __be32 nfserr = nfserr_toosmall; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3404 | __be64 wire_offset; |
| 3405 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | |
| 3407 | /* In nfsv4, "." and ".." never make it onto the wire.. */ |
| 3408 | if (name && isdotent(name, namlen)) { |
| 3409 | cd->common.err = nfs_ok; |
| 3410 | return 0; |
| 3411 | } |
| 3412 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3413 | if (cd->cookie_offset) { |
| 3414 | wire_offset = cpu_to_be64(offset); |
| 3415 | write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset, |
| 3416 | &wire_offset, 8); |
| 3417 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3419 | p = xdr_reserve_space(xdr, 4); |
| 3420 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | *p++ = xdr_one; /* mark entry present */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3423 | cookie_offset = xdr->buf->len; |
| 3424 | p = xdr_reserve_space(xdr, 3*4 + namlen); |
| 3425 | if (!p) |
| 3426 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
| 3428 | p = xdr_encode_array(p, name, namlen); /* name length & name */ |
| 3429 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3430 | nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | switch (nfserr) { |
| 3432 | case nfs_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | break; |
| 3434 | case nfserr_resource: |
| 3435 | nfserr = nfserr_toosmall; |
| 3436 | goto fail; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3437 | case nfserr_noent: |
Kinglong Mee | f41c5ad | 2014-06-13 17:32:42 +0800 | [diff] [blame] | 3438 | xdr_truncate_encode(xdr, start_offset); |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3439 | goto skip_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | default: |
| 3441 | /* |
| 3442 | * If the client requested the RDATTR_ERROR attribute, |
| 3443 | * we stuff the error code into this attribute |
| 3444 | * and continue. If this attribute was not requested, |
| 3445 | * then in accordance with the spec, we fail the |
| 3446 | * entire READDIR operation(!) |
| 3447 | */ |
| 3448 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) |
| 3449 | goto fail; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3450 | p = nfsd4_encode_rdattr_error(xdr, nfserr); |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3451 | if (p == NULL) { |
| 3452 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | goto fail; |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | } |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3456 | nfserr = nfserr_toosmall; |
| 3457 | entry_bytes = xdr->buf->len - start_offset; |
| 3458 | if (entry_bytes > cd->rd_maxcount) |
| 3459 | goto fail; |
| 3460 | cd->rd_maxcount -= entry_bytes; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3461 | /* |
| 3462 | * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so |
| 3463 | * let's always let through the first entry, at least: |
| 3464 | */ |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3465 | if (!cd->rd_dircount) |
| 3466 | goto fail; |
| 3467 | name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3468 | if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) |
| 3469 | goto fail; |
| 3470 | cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3471 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3472 | cd->cookie_offset = cookie_offset; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3473 | skip_entry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | cd->common.err = nfs_ok; |
| 3475 | return 0; |
| 3476 | fail: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3477 | xdr_truncate_encode(xdr, start_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | cd->common.err = nfserr; |
| 3479 | return -EINVAL; |
| 3480 | } |
| 3481 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3482 | static __be32 |
| 3483 | nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid) |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3484 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3485 | __be32 *p; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3486 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3487 | p = xdr_reserve_space(xdr, sizeof(stateid_t)); |
| 3488 | if (!p) |
| 3489 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3490 | *p++ = cpu_to_be32(sid->si_generation); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3491 | p = xdr_encode_opaque_fixed(p, &sid->si_opaque, |
| 3492 | sizeof(stateid_opaque_t)); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3493 | return 0; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3494 | } |
| 3495 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3496 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3497 | 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] | 3498 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3499 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3500 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3502 | p = xdr_reserve_space(xdr, 8); |
| 3503 | if (!p) |
| 3504 | return nfserr_resource; |
| 3505 | *p++ = cpu_to_be32(access->ac_supported); |
| 3506 | *p++ = cpu_to_be32(access->ac_resp_access); |
| 3507 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3510 | static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts) |
| 3511 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3512 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3513 | __be32 *p; |
| 3514 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3515 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 8); |
| 3516 | if (!p) |
| 3517 | return nfserr_resource; |
| 3518 | p = xdr_encode_opaque_fixed(p, bcts->sessionid.data, |
| 3519 | NFS4_MAX_SESSIONID_LEN); |
| 3520 | *p++ = cpu_to_be32(bcts->dir); |
| 3521 | /* Upshifting from TCP to RDMA is not supported */ |
| 3522 | *p++ = cpu_to_be32(0); |
| 3523 | return 0; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3524 | } |
| 3525 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3526 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3527 | 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] | 3528 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3529 | struct xdr_stream *xdr = &resp->xdr; |
| 3530 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3531 | return nfsd4_encode_stateid(xdr, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3535 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3536 | 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] | 3537 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3538 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3539 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3541 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 3542 | if (!p) |
| 3543 | return nfserr_resource; |
| 3544 | p = xdr_encode_opaque_fixed(p, commit->co_verf.data, |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3545 | NFS4_VERIFIER_SIZE); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3546 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3549 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3550 | 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] | 3551 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3552 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3553 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3555 | p = xdr_reserve_space(xdr, 20); |
| 3556 | if (!p) |
| 3557 | return nfserr_resource; |
| 3558 | encode_cinfo(p, &create->cr_cinfo); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 3559 | return nfsd4_encode_bitmap(xdr, create->cr_bmval[0], |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3560 | create->cr_bmval[1], create->cr_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3563 | static __be32 |
| 3564 | 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] | 3565 | { |
| 3566 | struct svc_fh *fhp = getattr->ga_fhp; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3567 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3569 | return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry, |
| 3570 | getattr->ga_bmval, resp->rqstp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3573 | static __be32 |
| 3574 | 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] | 3575 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3576 | struct xdr_stream *xdr = &resp->xdr; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3577 | struct svc_fh *fhp = *fhpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | unsigned int len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3579 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3581 | len = fhp->fh_handle.fh_size; |
| 3582 | p = xdr_reserve_space(xdr, len + 4); |
| 3583 | if (!p) |
| 3584 | return nfserr_resource; |
| 3585 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len); |
| 3586 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | /* |
| 3590 | * Including all fields other than the name, a LOCK4denied structure requires |
| 3591 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. |
| 3592 | */ |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3593 | static __be32 |
| 3594 | 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] | 3595 | { |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3596 | struct xdr_netobj *conf = &ld->ld_owner; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3597 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3599 | again: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3600 | p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3601 | if (!p) { |
| 3602 | /* |
| 3603 | * Don't fail to return the result just because we can't |
| 3604 | * return the conflicting open: |
| 3605 | */ |
| 3606 | if (conf->len) { |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3607 | kfree(conf->data); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3608 | conf->len = 0; |
| 3609 | conf->data = NULL; |
| 3610 | goto again; |
| 3611 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3612 | return nfserr_resource; |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3613 | } |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3614 | p = xdr_encode_hyper(p, ld->ld_start); |
| 3615 | p = xdr_encode_hyper(p, ld->ld_length); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3616 | *p++ = cpu_to_be32(ld->ld_type); |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3617 | if (conf->len) { |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3618 | p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8); |
| 3619 | p = xdr_encode_opaque(p, conf->data, conf->len); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3620 | kfree(conf->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3622 | p = xdr_encode_hyper(p, (u64)0); /* clientid */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3623 | *p++ = cpu_to_be32(0); /* length of owner name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3625 | return nfserr_denied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3628 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3629 | 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] | 3630 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3631 | struct xdr_stream *xdr = &resp->xdr; |
| 3632 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3633 | if (!nfserr) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3634 | nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid); |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3635 | else if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3636 | nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3637 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3638 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3641 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3642 | 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] | 3643 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3644 | struct xdr_stream *xdr = &resp->xdr; |
| 3645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3647 | nfsd4_encode_lock_denied(xdr, &lockt->lt_denied); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3648 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3651 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3652 | 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] | 3653 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3654 | struct xdr_stream *xdr = &resp->xdr; |
| 3655 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3656 | return nfsd4_encode_stateid(xdr, &locku->lu_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3660 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3661 | 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] | 3662 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3663 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3664 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3666 | p = xdr_reserve_space(xdr, 20); |
| 3667 | if (!p) |
| 3668 | return nfserr_resource; |
| 3669 | p = encode_cinfo(p, &link->li_cinfo); |
| 3670 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3674 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3675 | 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] | 3676 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3677 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3678 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3680 | nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid); |
| 3681 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3682 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3683 | p = xdr_reserve_space(xdr, 24); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3684 | if (!p) |
| 3685 | return nfserr_resource; |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 3686 | p = encode_cinfo(p, &open->op_cinfo); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3687 | *p++ = cpu_to_be32(open->op_rflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3689 | nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1], |
| 3690 | open->op_bmval[2]); |
| 3691 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3692 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3693 | |
| 3694 | p = xdr_reserve_space(xdr, 4); |
| 3695 | if (!p) |
| 3696 | return nfserr_resource; |
| 3697 | |
| 3698 | *p++ = cpu_to_be32(open->op_delegate_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | switch (open->op_delegate_type) { |
| 3700 | case NFS4_OPEN_DELEGATE_NONE: |
| 3701 | break; |
| 3702 | case NFS4_OPEN_DELEGATE_READ: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3703 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3704 | if (nfserr) |
| 3705 | return nfserr; |
| 3706 | p = xdr_reserve_space(xdr, 20); |
| 3707 | if (!p) |
| 3708 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3709 | *p++ = cpu_to_be32(open->op_recall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | |
| 3711 | /* |
| 3712 | * TODO: ACE's in delegations |
| 3713 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3714 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3715 | *p++ = cpu_to_be32(0); |
| 3716 | *p++ = cpu_to_be32(0); |
| 3717 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | break; |
| 3719 | case NFS4_OPEN_DELEGATE_WRITE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3720 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3721 | if (nfserr) |
| 3722 | return nfserr; |
| 3723 | p = xdr_reserve_space(xdr, 32); |
| 3724 | if (!p) |
| 3725 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3726 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | |
| 3728 | /* |
| 3729 | * TODO: space_limit's in delegations |
| 3730 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3731 | *p++ = cpu_to_be32(NFS4_LIMIT_SIZE); |
| 3732 | *p++ = cpu_to_be32(~(u32)0); |
| 3733 | *p++ = cpu_to_be32(~(u32)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | |
| 3735 | /* |
| 3736 | * TODO: ACE's in delegations |
| 3737 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3738 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3739 | *p++ = cpu_to_be32(0); |
| 3740 | *p++ = cpu_to_be32(0); |
| 3741 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | break; |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3743 | case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ |
| 3744 | switch (open->op_why_no_deleg) { |
| 3745 | case WND4_CONTENTION: |
| 3746 | case WND4_RESOURCE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3747 | p = xdr_reserve_space(xdr, 8); |
| 3748 | if (!p) |
| 3749 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3750 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
| 3751 | /* deleg signaling not supported yet: */ |
| 3752 | *p++ = cpu_to_be32(0); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3753 | break; |
| 3754 | default: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3755 | p = xdr_reserve_space(xdr, 4); |
| 3756 | if (!p) |
| 3757 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3758 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3759 | } |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3760 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | default: |
| 3762 | BUG(); |
| 3763 | } |
| 3764 | /* XXX save filehandle here */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3765 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3768 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3769 | 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] | 3770 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3771 | struct xdr_stream *xdr = &resp->xdr; |
| 3772 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3773 | return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3776 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3777 | 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] | 3778 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3779 | struct xdr_stream *xdr = &resp->xdr; |
| 3780 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3781 | return nfsd4_encode_stateid(xdr, &od->od_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3784 | static __be32 nfsd4_encode_splice_read( |
| 3785 | struct nfsd4_compoundres *resp, |
| 3786 | struct nfsd4_read *read, |
| 3787 | struct file *file, unsigned long maxcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | { |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3789 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3790 | struct xdr_buf *buf = xdr->buf; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3791 | int status, space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3792 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3793 | __be32 nfserr; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3794 | __be32 *p = xdr->p - 2; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3795 | |
Kinglong Mee | d5d5c30 | 2014-07-09 21:51:27 +0800 | [diff] [blame] | 3796 | /* Make sure there will be room for padding if needed */ |
| 3797 | if (xdr->end - xdr->p < 1) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3798 | return nfserr_resource; |
| 3799 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3800 | nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3801 | file, read->rd_offset, &maxcount, &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3802 | read->rd_length = maxcount; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3803 | if (nfserr) |
| 3804 | goto out_err; |
| 3805 | status = svc_encode_result_payload(read->rd_rqstp, |
| 3806 | buf->head[0].iov_len, maxcount); |
| 3807 | if (status) { |
| 3808 | nfserr = nfserrno(status); |
| 3809 | goto out_err; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3810 | } |
| 3811 | |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3812 | *(p++) = htonl(eof); |
| 3813 | *(p++) = htonl(maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3814 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3815 | buf->page_len = maxcount; |
| 3816 | buf->len += maxcount; |
J. Bruce Fields | 15b23ef | 2014-09-24 16:32:34 -0400 | [diff] [blame] | 3817 | xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) |
| 3818 | / PAGE_SIZE; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3819 | |
| 3820 | /* Use rest of head for padding and remaining ops: */ |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3821 | buf->tail[0].iov_base = xdr->p; |
| 3822 | buf->tail[0].iov_len = 0; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3823 | xdr->iov = buf->tail; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3824 | if (maxcount&3) { |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3825 | int pad = 4 - (maxcount&3); |
| 3826 | |
| 3827 | *(xdr->p++) = 0; |
| 3828 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3829 | buf->tail[0].iov_base += maxcount&3; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3830 | buf->tail[0].iov_len = pad; |
| 3831 | buf->len += pad; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | space_left = min_t(int, (void *)xdr->end - (void *)xdr->p, |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3835 | buf->buflen - buf->len); |
| 3836 | buf->buflen = buf->len + space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3837 | xdr->end = (__be32 *)((void *)xdr->end + space_left); |
| 3838 | |
| 3839 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3840 | |
| 3841 | out_err: |
| 3842 | /* |
| 3843 | * nfsd_splice_actor may have already messed with the |
| 3844 | * page length; reset it so as not to confuse |
| 3845 | * xdr_truncate_encode in our caller. |
| 3846 | */ |
| 3847 | buf->page_len = 0; |
| 3848 | return nfserr; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, |
| 3852 | struct nfsd4_read *read, |
| 3853 | struct file *file, unsigned long maxcount) |
| 3854 | { |
| 3855 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3857 | int starting_len = xdr->buf->len - 8; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3858 | __be32 nfserr; |
| 3859 | __be32 tmp; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3860 | int pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | |
Anna Schumaker | 403217f | 2020-08-17 12:53:06 -0400 | [diff] [blame] | 3862 | read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, maxcount); |
| 3863 | if (read->rd_vlen < 0) |
| 3864 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3866 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3867 | resp->rqstp->rq_vec, read->rd_vlen, &maxcount, |
| 3868 | &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3869 | read->rd_length = maxcount; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3870 | if (nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | return nfserr; |
Chuck Lever | 03493bc | 2020-06-10 10:36:42 -0400 | [diff] [blame] | 3872 | if (svc_encode_result_payload(resp->rqstp, starting_len + 8, maxcount)) |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 3873 | return nfserr_io; |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3874 | xdr_truncate_encode(xdr, starting_len + 8 + xdr_align_size(maxcount)); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3875 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3876 | tmp = htonl(eof); |
| 3877 | write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); |
| 3878 | tmp = htonl(maxcount); |
| 3879 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
| 3880 | |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3881 | tmp = xdr_zero; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3882 | pad = (maxcount&3) ? 4 - (maxcount&3) : 0; |
| 3883 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount, |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3884 | &tmp, pad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3885 | return 0; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3886 | |
| 3887 | } |
| 3888 | |
| 3889 | static __be32 |
| 3890 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 3891 | struct nfsd4_read *read) |
| 3892 | { |
| 3893 | unsigned long maxcount; |
| 3894 | struct xdr_stream *xdr = &resp->xdr; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3895 | struct file *file; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3896 | int starting_len = xdr->buf->len; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3897 | __be32 *p; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3898 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3899 | if (nfserr) |
| 3900 | return nfserr; |
| 3901 | file = read->rd_nf->nf_file; |
| 3902 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3903 | p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */ |
| 3904 | if (!p) { |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 3905 | 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] | 3906 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3907 | } |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3908 | if (resp->xdr.buf->page_len && |
| 3909 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) { |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3910 | WARN_ON_ONCE(1); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3911 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3912 | } |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3913 | xdr_commit_encode(xdr); |
| 3914 | |
| 3915 | maxcount = svc_max_payload(resp->rqstp); |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3916 | maxcount = min_t(unsigned long, maxcount, |
| 3917 | (xdr->buf->buflen - xdr->buf->len)); |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 3918 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3919 | |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3920 | if (file->f_op->splice_read && |
| 3921 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3922 | nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3923 | else |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3924 | nfserr = nfsd4_encode_readv(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3925 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3926 | if (nfserr) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3927 | xdr_truncate_encode(xdr, starting_len); |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3928 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3929 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3932 | static __be32 |
| 3933 | 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] | 3934 | { |
| 3935 | int maxcount; |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 3936 | __be32 wire_count; |
| 3937 | int zero = 0; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3938 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3939 | int length_offset = xdr->buf->len; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3940 | int status; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3941 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3943 | p = xdr_reserve_space(xdr, 4); |
| 3944 | if (!p) |
| 3945 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 | maxcount = PAGE_SIZE; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3947 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 3948 | p = xdr_reserve_space(xdr, maxcount); |
| 3949 | if (!p) |
J. Bruce Fields | 4e21ac4 | 2014-03-22 15:15:11 -0400 | [diff] [blame] | 3950 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | /* |
Miklos Szeredi | fd4a0edf | 2016-12-09 16:45:04 +0100 | [diff] [blame] | 3952 | * XXX: By default, vfs_readlink() will truncate symlinks if they |
| 3953 | * would overflow the buffer. Is this kosher in NFSv4? If not, one |
| 3954 | * easy fix is: if vfs_readlink() precisely fills the buffer, assume |
| 3955 | * that truncation occurred, and return NFS4ERR_RESOURCE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | */ |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 3957 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, |
| 3958 | (char *)p, &maxcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | if (nfserr == nfserr_isdir) |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 3960 | nfserr = nfserr_inval; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3961 | if (nfserr) |
| 3962 | goto out_err; |
| 3963 | status = svc_encode_result_payload(readlink->rl_rqstp, length_offset, |
| 3964 | maxcount); |
| 3965 | if (status) { |
| 3966 | nfserr = nfserrno(status); |
| 3967 | goto out_err; |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 3968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 3970 | wire_count = htonl(maxcount); |
| 3971 | write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4); |
Avi Kivity | 69bbd9c | 2014-06-26 17:23:12 +0300 | [diff] [blame] | 3972 | xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4)); |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 3973 | if (maxcount & 3) |
| 3974 | write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, |
| 3975 | &zero, 4 - (maxcount&3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3977 | |
| 3978 | out_err: |
| 3979 | xdr_truncate_encode(xdr, length_offset); |
| 3980 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3983 | static __be32 |
| 3984 | 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] | 3985 | { |
| 3986 | int maxcount; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3987 | int bytes_left; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | loff_t offset; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3989 | __be64 wire_offset; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3990 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3991 | int starting_len = xdr->buf->len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3992 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3994 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 3995 | if (!p) |
| 3996 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | |
| 3998 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3999 | *p++ = cpu_to_be32(0); |
| 4000 | *p++ = cpu_to_be32(0); |
J. Bruce Fields | 4aea24b | 2014-01-15 15:17:58 -0500 | [diff] [blame] | 4001 | resp->xdr.buf->head[0].iov_len = ((char *)resp->xdr.p) |
| 4002 | - (char *)resp->xdr.buf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | |
| 4004 | /* |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4005 | * Number of bytes left for directory entries allowing for the |
| 4006 | * final 8 bytes of the readdir and a following failed op: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4008 | bytes_left = xdr->buf->buflen - xdr->buf->len |
| 4009 | - COMPOUND_ERR_SLACK_SPACE - 8; |
| 4010 | if (bytes_left < 0) { |
| 4011 | nfserr = nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | goto err_no_verf; |
| 4013 | } |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4014 | maxcount = svc_max_payload(resp->rqstp); |
| 4015 | maxcount = min_t(u32, readdir->rd_maxcount, maxcount); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4016 | /* |
| 4017 | * Note the rfc defines rd_maxcount as the size of the |
| 4018 | * READDIR4resok structure, which includes the verifier above |
| 4019 | * and the 8 bytes encoded at the end of this function: |
| 4020 | */ |
| 4021 | if (maxcount < 16) { |
| 4022 | nfserr = nfserr_toosmall; |
| 4023 | goto err_no_verf; |
| 4024 | } |
| 4025 | maxcount = min_t(int, maxcount-16, bytes_left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4027 | /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ |
| 4028 | if (!readdir->rd_dircount) |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4029 | readdir->rd_dircount = svc_max_payload(resp->rqstp); |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4030 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4031 | readdir->xdr = xdr; |
| 4032 | readdir->rd_maxcount = maxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | readdir->common.err = 0; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4034 | readdir->cookie_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | |
| 4036 | offset = readdir->rd_cookie; |
| 4037 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, |
| 4038 | &offset, |
| 4039 | &readdir->common, nfsd4_encode_dirent); |
| 4040 | if (nfserr == nfs_ok && |
| 4041 | readdir->common.err == nfserr_toosmall && |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4042 | xdr->buf->len == starting_len + 8) { |
| 4043 | /* nothing encoded; which limit did we hit?: */ |
| 4044 | if (maxcount - 16 < bytes_left) |
| 4045 | /* It was the fault of rd_maxcount: */ |
| 4046 | nfserr = nfserr_toosmall; |
| 4047 | else |
| 4048 | /* We ran out of buffer space: */ |
| 4049 | nfserr = nfserr_resource; |
| 4050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | if (nfserr) |
| 4052 | goto err_no_verf; |
| 4053 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4054 | if (readdir->cookie_offset) { |
| 4055 | wire_offset = cpu_to_be64(offset); |
| 4056 | write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, |
| 4057 | &wire_offset, 8); |
| 4058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4060 | p = xdr_reserve_space(xdr, 8); |
| 4061 | if (!p) { |
| 4062 | WARN_ON_ONCE(1); |
| 4063 | goto err_no_verf; |
| 4064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | *p++ = 0; /* no more entries */ |
| 4066 | *p++ = htonl(readdir->common.err == nfserr_eof); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | |
| 4068 | return 0; |
| 4069 | err_no_verf: |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4070 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | return nfserr; |
| 4072 | } |
| 4073 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4074 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4075 | 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] | 4076 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4077 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4078 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4080 | p = xdr_reserve_space(xdr, 20); |
| 4081 | if (!p) |
| 4082 | return nfserr_resource; |
| 4083 | p = encode_cinfo(p, &remove->rm_cinfo); |
| 4084 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4087 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4088 | 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] | 4089 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4090 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4091 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4093 | p = xdr_reserve_space(xdr, 40); |
| 4094 | if (!p) |
| 4095 | return nfserr_resource; |
| 4096 | p = encode_cinfo(p, &rename->rn_sinfo); |
| 4097 | p = encode_cinfo(p, &rename->rn_tinfo); |
| 4098 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | } |
| 4100 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4101 | static __be32 |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4102 | nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4103 | { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4104 | u32 i, nflavs, supported; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4105 | struct exp_flavor_info *flavs; |
| 4106 | struct exp_flavor_info def_flavs[2]; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4107 | __be32 *p, *flavorsp; |
| 4108 | static bool report = true; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4109 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4110 | if (exp->ex_nflavors) { |
| 4111 | flavs = exp->ex_flavors; |
| 4112 | nflavs = exp->ex_nflavors; |
| 4113 | } else { /* Handling of some defaults in absence of real secinfo: */ |
| 4114 | flavs = def_flavs; |
| 4115 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { |
| 4116 | nflavs = 2; |
| 4117 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; |
| 4118 | flavs[1].pseudoflavor = RPC_AUTH_NULL; |
| 4119 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { |
| 4120 | nflavs = 1; |
| 4121 | flavs[0].pseudoflavor |
| 4122 | = svcauth_gss_flavor(exp->ex_client); |
| 4123 | } else { |
| 4124 | nflavs = 1; |
| 4125 | flavs[0].pseudoflavor |
| 4126 | = exp->ex_client->flavour->flavour; |
| 4127 | } |
| 4128 | } |
| 4129 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4130 | supported = 0; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4131 | p = xdr_reserve_space(xdr, 4); |
| 4132 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4133 | return nfserr_resource; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4134 | flavorsp = p++; /* to be backfilled later */ |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4135 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4136 | for (i = 0; i < nflavs; i++) { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4137 | rpc_authflavor_t pf = flavs[i].pseudoflavor; |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4138 | struct rpcsec_gss_info info; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4139 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4140 | if (rpcauth_get_gssinfo(pf, &info) == 0) { |
| 4141 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4142 | p = xdr_reserve_space(xdr, 4 + 4 + |
| 4143 | XDR_LEN(info.oid.len) + 4 + 4); |
| 4144 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4145 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4146 | *p++ = cpu_to_be32(RPC_AUTH_GSS); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4147 | p = xdr_encode_opaque(p, info.oid.data, info.oid.len); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4148 | *p++ = cpu_to_be32(info.qop); |
| 4149 | *p++ = cpu_to_be32(info.service); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4150 | } else if (pf < RPC_AUTH_MAXFLAVOR) { |
| 4151 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4152 | p = xdr_reserve_space(xdr, 4); |
| 4153 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4154 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4155 | *p++ = cpu_to_be32(pf); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4156 | } else { |
| 4157 | if (report) |
| 4158 | pr_warn("NFS: SECINFO: security flavor %u " |
| 4159 | "is not supported\n", pf); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4160 | } |
| 4161 | } |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4162 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4163 | if (nflavs != supported) |
| 4164 | report = false; |
| 4165 | *flavorsp = htonl(supported); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4166 | return 0; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4167 | } |
| 4168 | |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4169 | static __be32 |
| 4170 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4171 | struct nfsd4_secinfo *secinfo) |
| 4172 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4173 | struct xdr_stream *xdr = &resp->xdr; |
| 4174 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4175 | return nfsd4_do_encode_secinfo(xdr, secinfo->si_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | static __be32 |
| 4179 | nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4180 | struct nfsd4_secinfo_no_name *secinfo) |
| 4181 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4182 | struct xdr_stream *xdr = &resp->xdr; |
| 4183 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4184 | return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4185 | } |
| 4186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | /* |
| 4188 | * The SETATTR encode routine is special -- it always encodes a bitmap, |
| 4189 | * regardless of the error status. |
| 4190 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4191 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4192 | 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] | 4193 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4194 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4195 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4197 | p = xdr_reserve_space(xdr, 16); |
| 4198 | if (!p) |
| 4199 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | if (nfserr) { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4201 | *p++ = cpu_to_be32(3); |
| 4202 | *p++ = cpu_to_be32(0); |
| 4203 | *p++ = cpu_to_be32(0); |
| 4204 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | } |
| 4206 | else { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4207 | *p++ = cpu_to_be32(3); |
| 4208 | *p++ = cpu_to_be32(setattr->sa_bmval[0]); |
| 4209 | *p++ = cpu_to_be32(setattr->sa_bmval[1]); |
| 4210 | *p++ = cpu_to_be32(setattr->sa_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4212 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4215 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4216 | 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] | 4217 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4218 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4219 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | |
| 4221 | if (!nfserr) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4222 | p = xdr_reserve_space(xdr, 8 + NFS4_VERIFIER_SIZE); |
| 4223 | if (!p) |
| 4224 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4225 | p = xdr_encode_opaque_fixed(p, &scd->se_clientid, 8); |
| 4226 | p = xdr_encode_opaque_fixed(p, &scd->se_confirm, |
| 4227 | NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | } |
| 4229 | else if (nfserr == nfserr_clid_inuse) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4230 | p = xdr_reserve_space(xdr, 8); |
| 4231 | if (!p) |
| 4232 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4233 | *p++ = cpu_to_be32(0); |
| 4234 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4236 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | } |
| 4238 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4239 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4240 | 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] | 4241 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4242 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4243 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4245 | p = xdr_reserve_space(xdr, 16); |
| 4246 | if (!p) |
| 4247 | return nfserr_resource; |
| 4248 | *p++ = cpu_to_be32(write->wr_bytes_written); |
| 4249 | *p++ = cpu_to_be32(write->wr_how_written); |
| 4250 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4251 | NFS4_VERIFIER_SIZE); |
| 4252 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4255 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4256 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4257 | struct nfsd4_exchange_id *exid) |
| 4258 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4259 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4260 | __be32 *p; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4261 | char *major_id; |
| 4262 | char *server_scope; |
| 4263 | int major_id_sz; |
| 4264 | int server_scope_sz; |
| 4265 | uint64_t minor_id = 0; |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4266 | 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] | 4267 | |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4268 | major_id = nn->nfsd_name; |
| 4269 | major_id_sz = strlen(nn->nfsd_name); |
| 4270 | server_scope = nn->nfsd_name; |
| 4271 | server_scope_sz = strlen(nn->nfsd_name); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4272 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4273 | p = xdr_reserve_space(xdr, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4274 | 8 /* eir_clientid */ + |
| 4275 | 4 /* eir_sequenceid */ + |
| 4276 | 4 /* eir_flags */ + |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4277 | 4 /* spr_how */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4278 | if (!p) |
| 4279 | return nfserr_resource; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4280 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4281 | p = xdr_encode_opaque_fixed(p, &exid->clientid, 8); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4282 | *p++ = cpu_to_be32(exid->seqid); |
| 4283 | *p++ = cpu_to_be32(exid->flags); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4284 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4285 | *p++ = cpu_to_be32(exid->spa_how); |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4286 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4287 | switch (exid->spa_how) { |
| 4288 | case SP4_NONE: |
| 4289 | break; |
| 4290 | case SP4_MACH_CRED: |
| 4291 | /* spo_must_enforce bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4292 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4293 | exid->spo_must_enforce[0], |
| 4294 | exid->spo_must_enforce[1], |
| 4295 | exid->spo_must_enforce[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4296 | if (nfserr) |
| 4297 | return nfserr; |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4298 | /* spo_must_allow bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4299 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4300 | exid->spo_must_allow[0], |
| 4301 | exid->spo_must_allow[1], |
| 4302 | exid->spo_must_allow[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4303 | if (nfserr) |
| 4304 | return nfserr; |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4305 | break; |
| 4306 | default: |
| 4307 | WARN_ON_ONCE(1); |
| 4308 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4309 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4310 | p = xdr_reserve_space(xdr, |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4311 | 8 /* so_minor_id */ + |
| 4312 | 4 /* so_major_id.len */ + |
| 4313 | (XDR_QUADLEN(major_id_sz) * 4) + |
| 4314 | 4 /* eir_server_scope.len */ + |
| 4315 | (XDR_QUADLEN(server_scope_sz) * 4) + |
| 4316 | 4 /* eir_server_impl_id.count (0) */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4317 | if (!p) |
| 4318 | return nfserr_resource; |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4319 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4320 | /* The server_owner struct */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 4321 | p = xdr_encode_hyper(p, minor_id); /* Minor id */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4322 | /* major id */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4323 | p = xdr_encode_opaque(p, major_id, major_id_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4324 | |
| 4325 | /* Server scope */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4326 | p = xdr_encode_opaque(p, server_scope, server_scope_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4327 | |
| 4328 | /* Implementation id */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4329 | *p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4330 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4334 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4335 | struct nfsd4_create_session *sess) |
| 4336 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4337 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4338 | __be32 *p; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4339 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4340 | p = xdr_reserve_space(xdr, 24); |
| 4341 | if (!p) |
| 4342 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4343 | p = xdr_encode_opaque_fixed(p, sess->sessionid.data, |
| 4344 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4345 | *p++ = cpu_to_be32(sess->seqid); |
| 4346 | *p++ = cpu_to_be32(sess->flags); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4347 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4348 | p = xdr_reserve_space(xdr, 28); |
| 4349 | if (!p) |
| 4350 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4351 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4352 | *p++ = cpu_to_be32(sess->fore_channel.maxreq_sz); |
| 4353 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_sz); |
| 4354 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_cached); |
| 4355 | *p++ = cpu_to_be32(sess->fore_channel.maxops); |
| 4356 | *p++ = cpu_to_be32(sess->fore_channel.maxreqs); |
| 4357 | *p++ = cpu_to_be32(sess->fore_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4358 | |
| 4359 | if (sess->fore_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4360 | p = xdr_reserve_space(xdr, 4); |
| 4361 | if (!p) |
| 4362 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4363 | *p++ = cpu_to_be32(sess->fore_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4364 | } |
| 4365 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4366 | p = xdr_reserve_space(xdr, 28); |
| 4367 | if (!p) |
| 4368 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4369 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4370 | *p++ = cpu_to_be32(sess->back_channel.maxreq_sz); |
| 4371 | *p++ = cpu_to_be32(sess->back_channel.maxresp_sz); |
| 4372 | *p++ = cpu_to_be32(sess->back_channel.maxresp_cached); |
| 4373 | *p++ = cpu_to_be32(sess->back_channel.maxops); |
| 4374 | *p++ = cpu_to_be32(sess->back_channel.maxreqs); |
| 4375 | *p++ = cpu_to_be32(sess->back_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4376 | |
| 4377 | if (sess->back_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4378 | p = xdr_reserve_space(xdr, 4); |
| 4379 | if (!p) |
| 4380 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4381 | *p++ = cpu_to_be32(sess->back_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4382 | } |
| 4383 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4387 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4388 | struct nfsd4_sequence *seq) |
| 4389 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4390 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4391 | __be32 *p; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4392 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4393 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20); |
| 4394 | if (!p) |
| 4395 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4396 | p = xdr_encode_opaque_fixed(p, seq->sessionid.data, |
| 4397 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4398 | *p++ = cpu_to_be32(seq->seqid); |
| 4399 | *p++ = cpu_to_be32(seq->slotid); |
J. Bruce Fields | b7d7ca3 | 2011-08-31 15:39:30 -0400 | [diff] [blame] | 4400 | /* Note slotid's are numbered from zero: */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4401 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */ |
| 4402 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */ |
| 4403 | *p++ = cpu_to_be32(seq->status_flags); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4404 | |
J. Bruce Fields | f523601 | 2014-03-21 17:57:57 -0400 | [diff] [blame] | 4405 | resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */ |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4406 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4407 | } |
| 4408 | |
J. Bruce Fields | 2355c59 | 2012-04-25 16:56:22 -0400 | [diff] [blame] | 4409 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4410 | nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4411 | struct nfsd4_test_stateid *test_stateid) |
| 4412 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4413 | struct xdr_stream *xdr = &resp->xdr; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4414 | struct nfsd4_test_stateid_id *stateid, *next; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4415 | __be32 *p; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4416 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4417 | p = xdr_reserve_space(xdr, 4 + (4 * test_stateid->ts_num_ids)); |
| 4418 | if (!p) |
| 4419 | return nfserr_resource; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4420 | *p++ = htonl(test_stateid->ts_num_ids); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4421 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4422 | 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] | 4423 | *p++ = stateid->ts_id_status; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4424 | } |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4425 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4426 | return 0; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4427 | } |
| 4428 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4429 | #ifdef CONFIG_NFSD_PNFS |
| 4430 | static __be32 |
| 4431 | nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4432 | struct nfsd4_getdeviceinfo *gdev) |
| 4433 | { |
| 4434 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4435 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4436 | u32 starting_len = xdr->buf->len, needed_len; |
| 4437 | __be32 *p; |
| 4438 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4439 | p = xdr_reserve_space(xdr, 4); |
| 4440 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4441 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4442 | |
| 4443 | *p++ = cpu_to_be32(gdev->gd_layout_type); |
| 4444 | |
| 4445 | /* If maxcount is 0 then just update notifications */ |
| 4446 | if (gdev->gd_maxcount != 0) { |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4447 | ops = nfsd4_layout_ops[gdev->gd_layout_type]; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4448 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); |
| 4449 | if (nfserr) { |
| 4450 | /* |
| 4451 | * We don't bother to burden the layout drivers with |
| 4452 | * enforcing gd_maxcount, just tell the client to |
| 4453 | * come back with a bigger buffer if it's not enough. |
| 4454 | */ |
| 4455 | if (xdr->buf->len + 4 > gdev->gd_maxcount) |
| 4456 | goto toosmall; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4457 | return nfserr; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4458 | } |
| 4459 | } |
| 4460 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4461 | if (gdev->gd_notify_types) { |
| 4462 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4463 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4464 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4465 | *p++ = cpu_to_be32(1); /* bitmap length */ |
| 4466 | *p++ = cpu_to_be32(gdev->gd_notify_types); |
| 4467 | } else { |
| 4468 | p = xdr_reserve_space(xdr, 4); |
| 4469 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4470 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4471 | *p++ = 0; |
| 4472 | } |
| 4473 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4474 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4475 | toosmall: |
| 4476 | dprintk("%s: maxcount too small\n", __func__); |
| 4477 | needed_len = xdr->buf->len + 4 /* notifications */; |
| 4478 | xdr_truncate_encode(xdr, starting_len); |
| 4479 | p = xdr_reserve_space(xdr, 4); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4480 | if (!p) |
| 4481 | return nfserr_resource; |
| 4482 | *p++ = cpu_to_be32(needed_len); |
| 4483 | return nfserr_toosmall; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | static __be32 |
| 4487 | nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4488 | struct nfsd4_layoutget *lgp) |
| 4489 | { |
| 4490 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4491 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4492 | __be32 *p; |
| 4493 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4494 | p = xdr_reserve_space(xdr, 36 + sizeof(stateid_opaque_t)); |
| 4495 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4496 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4497 | |
| 4498 | *p++ = cpu_to_be32(1); /* we always set return-on-close */ |
| 4499 | *p++ = cpu_to_be32(lgp->lg_sid.si_generation); |
| 4500 | p = xdr_encode_opaque_fixed(p, &lgp->lg_sid.si_opaque, |
| 4501 | sizeof(stateid_opaque_t)); |
| 4502 | |
| 4503 | *p++ = cpu_to_be32(1); /* we always return a single layout */ |
| 4504 | p = xdr_encode_hyper(p, lgp->lg_seg.offset); |
| 4505 | p = xdr_encode_hyper(p, lgp->lg_seg.length); |
| 4506 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); |
| 4507 | *p++ = cpu_to_be32(lgp->lg_layout_type); |
| 4508 | |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4509 | ops = nfsd4_layout_ops[lgp->lg_layout_type]; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4510 | return ops->encode_layoutget(xdr, lgp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | static __be32 |
| 4514 | nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4515 | struct nfsd4_layoutcommit *lcp) |
| 4516 | { |
| 4517 | struct xdr_stream *xdr = &resp->xdr; |
| 4518 | __be32 *p; |
| 4519 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4520 | p = xdr_reserve_space(xdr, 4); |
| 4521 | if (!p) |
| 4522 | return nfserr_resource; |
| 4523 | *p++ = cpu_to_be32(lcp->lc_size_chg); |
| 4524 | if (lcp->lc_size_chg) { |
| 4525 | p = xdr_reserve_space(xdr, 8); |
| 4526 | if (!p) |
| 4527 | return nfserr_resource; |
| 4528 | p = xdr_encode_hyper(p, lcp->lc_newsize); |
| 4529 | } |
| 4530 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4531 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4532 | } |
| 4533 | |
| 4534 | static __be32 |
| 4535 | nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4536 | struct nfsd4_layoutreturn *lrp) |
| 4537 | { |
| 4538 | struct xdr_stream *xdr = &resp->xdr; |
| 4539 | __be32 *p; |
| 4540 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4541 | p = xdr_reserve_space(xdr, 4); |
| 4542 | if (!p) |
| 4543 | return nfserr_resource; |
| 4544 | *p++ = cpu_to_be32(lrp->lrs_present); |
| 4545 | if (lrp->lrs_present) |
Kinglong Mee | 376675d | 2015-03-22 22:17:10 +0800 | [diff] [blame] | 4546 | return nfsd4_encode_stateid(xdr, &lrp->lr_sid); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4547 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4548 | } |
| 4549 | #endif /* CONFIG_NFSD_PNFS */ |
| 4550 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4551 | static __be32 |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4552 | nfsd42_encode_write_res(struct nfsd4_compoundres *resp, |
| 4553 | struct nfsd42_write_res *write, bool sync) |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4554 | { |
| 4555 | __be32 *p; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4556 | p = xdr_reserve_space(&resp->xdr, 4); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4557 | if (!p) |
| 4558 | return nfserr_resource; |
| 4559 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4560 | if (sync) |
| 4561 | *p++ = cpu_to_be32(0); |
| 4562 | else { |
| 4563 | __be32 nfserr; |
| 4564 | *p++ = cpu_to_be32(1); |
| 4565 | nfserr = nfsd4_encode_stateid(&resp->xdr, &write->cb_stateid); |
| 4566 | if (nfserr) |
| 4567 | return nfserr; |
| 4568 | } |
| 4569 | p = xdr_reserve_space(&resp->xdr, 8 + 4 + NFS4_VERIFIER_SIZE); |
| 4570 | if (!p) |
| 4571 | return nfserr_resource; |
| 4572 | |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4573 | p = xdr_encode_hyper(p, write->wr_bytes_written); |
| 4574 | *p++ = cpu_to_be32(write->wr_stable_how); |
| 4575 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4576 | NFS4_VERIFIER_SIZE); |
| 4577 | return nfs_ok; |
| 4578 | } |
| 4579 | |
| 4580 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4581 | nfsd42_encode_nl4_server(struct nfsd4_compoundres *resp, struct nl4_server *ns) |
| 4582 | { |
| 4583 | struct xdr_stream *xdr = &resp->xdr; |
| 4584 | struct nfs42_netaddr *addr; |
| 4585 | __be32 *p; |
| 4586 | |
| 4587 | p = xdr_reserve_space(xdr, 4); |
| 4588 | *p++ = cpu_to_be32(ns->nl4_type); |
| 4589 | |
| 4590 | switch (ns->nl4_type) { |
| 4591 | case NL4_NETADDR: |
| 4592 | addr = &ns->u.nl4_addr; |
| 4593 | |
| 4594 | /* netid_len, netid, uaddr_len, uaddr (port included |
| 4595 | * in RPCBIND_MAXUADDRLEN) |
| 4596 | */ |
| 4597 | p = xdr_reserve_space(xdr, |
| 4598 | 4 /* netid len */ + |
| 4599 | (XDR_QUADLEN(addr->netid_len) * 4) + |
| 4600 | 4 /* uaddr len */ + |
| 4601 | (XDR_QUADLEN(addr->addr_len) * 4)); |
| 4602 | if (!p) |
| 4603 | return nfserr_resource; |
| 4604 | |
| 4605 | *p++ = cpu_to_be32(addr->netid_len); |
| 4606 | p = xdr_encode_opaque_fixed(p, addr->netid, |
| 4607 | addr->netid_len); |
| 4608 | *p++ = cpu_to_be32(addr->addr_len); |
| 4609 | p = xdr_encode_opaque_fixed(p, addr->addr, |
| 4610 | addr->addr_len); |
| 4611 | break; |
| 4612 | default: |
| 4613 | WARN_ON_ONCE(ns->nl4_type != NL4_NETADDR); |
| 4614 | return nfserr_inval; |
| 4615 | } |
| 4616 | |
| 4617 | return 0; |
| 4618 | } |
| 4619 | |
| 4620 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4621 | nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4622 | struct nfsd4_copy *copy) |
| 4623 | { |
| 4624 | __be32 *p; |
| 4625 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4626 | nfserr = nfsd42_encode_write_res(resp, ©->cp_res, |
| 4627 | copy->cp_synchronous); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4628 | if (nfserr) |
| 4629 | return nfserr; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4630 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4631 | p = xdr_reserve_space(&resp->xdr, 4 + 4); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 4632 | *p++ = xdr_one; /* cr_consecutive */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4633 | *p++ = cpu_to_be32(copy->cp_synchronous); |
| 4634 | return 0; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4638 | nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4639 | struct nfsd4_offload_status *os) |
| 4640 | { |
| 4641 | struct xdr_stream *xdr = &resp->xdr; |
| 4642 | __be32 *p; |
| 4643 | |
| 4644 | p = xdr_reserve_space(xdr, 8 + 4); |
| 4645 | if (!p) |
| 4646 | return nfserr_resource; |
| 4647 | p = xdr_encode_hyper(p, os->count); |
| 4648 | *p++ = cpu_to_be32(0); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4649 | return nfserr; |
| 4650 | } |
| 4651 | |
| 4652 | static __be32 |
| 4653 | nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, |
| 4654 | struct nfsd4_read *read, |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4655 | unsigned long *maxcount, u32 *eof, |
| 4656 | loff_t *pos) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4657 | { |
| 4658 | struct xdr_stream *xdr = &resp->xdr; |
| 4659 | struct file *file = read->rd_nf->nf_file; |
| 4660 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4661 | loff_t hole_pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4662 | __be32 nfserr; |
| 4663 | __be32 *p, tmp; |
| 4664 | __be64 tmp64; |
| 4665 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4666 | hole_pos = pos ? *pos : vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4667 | if (hole_pos > read->rd_offset) |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4668 | *maxcount = min_t(unsigned long, *maxcount, hole_pos - read->rd_offset); |
| 4669 | *maxcount = min_t(unsigned long, *maxcount, (xdr->buf->buflen - xdr->buf->len)); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4670 | |
| 4671 | /* Content type, offset, byte count */ |
| 4672 | p = xdr_reserve_space(xdr, 4 + 8 + 4); |
| 4673 | if (!p) |
| 4674 | return nfserr_resource; |
| 4675 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4676 | 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] | 4677 | if (read->rd_vlen < 0) |
| 4678 | return nfserr_resource; |
| 4679 | |
| 4680 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4681 | resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4682 | if (nfserr) |
| 4683 | return nfserr; |
| 4684 | |
| 4685 | tmp = htonl(NFS4_CONTENT_DATA); |
| 4686 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4687 | tmp64 = cpu_to_be64(read->rd_offset); |
| 4688 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp64, 8); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4689 | tmp = htonl(*maxcount); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4690 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp, 4); |
| 4691 | return nfs_ok; |
| 4692 | } |
| 4693 | |
| 4694 | static __be32 |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4695 | nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, |
| 4696 | struct nfsd4_read *read, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4697 | unsigned long *maxcount, u32 *eof) |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4698 | { |
| 4699 | struct file *file = read->rd_nf->nf_file; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4700 | loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4701 | loff_t f_size = i_size_read(file_inode(file)); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4702 | unsigned long count; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4703 | __be32 *p; |
| 4704 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4705 | if (data_pos == -ENXIO) |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4706 | data_pos = f_size; |
| 4707 | else if (data_pos <= read->rd_offset || (data_pos < f_size && data_pos % PAGE_SIZE)) |
| 4708 | return nfsd4_encode_read_plus_data(resp, read, maxcount, eof, &f_size); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4709 | count = data_pos - read->rd_offset; |
| 4710 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4711 | /* Content type, offset, byte count */ |
| 4712 | p = xdr_reserve_space(&resp->xdr, 4 + 8 + 8); |
| 4713 | if (!p) |
| 4714 | return nfserr_resource; |
| 4715 | |
| 4716 | *p++ = htonl(NFS4_CONTENT_HOLE); |
| 4717 | p = xdr_encode_hyper(p, read->rd_offset); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4718 | p = xdr_encode_hyper(p, count); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4719 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4720 | *eof = (read->rd_offset + count) >= f_size; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4721 | *maxcount = min_t(unsigned long, count, *maxcount); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4722 | return nfs_ok; |
| 4723 | } |
| 4724 | |
| 4725 | static __be32 |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4726 | nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4727 | struct nfsd4_read *read) |
| 4728 | { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4729 | unsigned long maxcount, count; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4730 | struct xdr_stream *xdr = &resp->xdr; |
| 4731 | struct file *file; |
| 4732 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4733 | int last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4734 | int segments = 0; |
| 4735 | __be32 *p, tmp; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4736 | bool is_data; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4737 | loff_t pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4738 | u32 eof; |
| 4739 | |
| 4740 | if (nfserr) |
| 4741 | return nfserr; |
| 4742 | file = read->rd_nf->nf_file; |
| 4743 | |
| 4744 | /* eof flag, segment count */ |
| 4745 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4746 | if (!p) |
| 4747 | return nfserr_resource; |
| 4748 | xdr_commit_encode(xdr); |
| 4749 | |
| 4750 | maxcount = svc_max_payload(resp->rqstp); |
| 4751 | maxcount = min_t(unsigned long, maxcount, |
| 4752 | (xdr->buf->buflen - xdr->buf->len)); |
| 4753 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4754 | count = maxcount; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4755 | |
| 4756 | eof = read->rd_offset >= i_size_read(file_inode(file)); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4757 | if (eof) |
| 4758 | goto out; |
| 4759 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4760 | pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
| 4761 | is_data = pos > read->rd_offset; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4762 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4763 | while (count > 0 && !eof) { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4764 | maxcount = count; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4765 | if (is_data) |
| 4766 | nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof, |
| 4767 | segments == 0 ? &pos : NULL); |
| 4768 | else |
| 4769 | nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4770 | if (nfserr) |
| 4771 | goto out; |
| 4772 | count -= maxcount; |
| 4773 | read->rd_offset += maxcount; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4774 | is_data = !is_data; |
| 4775 | last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4776 | segments++; |
| 4777 | } |
| 4778 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4779 | out: |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4780 | if (nfserr && segments == 0) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4781 | xdr_truncate_encode(xdr, starting_len); |
| 4782 | else { |
| 4783 | tmp = htonl(eof); |
| 4784 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4785 | tmp = htonl(segments); |
| 4786 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4787 | if (nfserr) { |
| 4788 | xdr_truncate_encode(xdr, last_segment); |
| 4789 | nfserr = nfs_ok; |
| 4790 | } |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4791 | } |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4792 | |
| 4793 | return nfserr; |
| 4794 | } |
| 4795 | |
| 4796 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4797 | nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4798 | struct nfsd4_copy_notify *cn) |
| 4799 | { |
| 4800 | struct xdr_stream *xdr = &resp->xdr; |
| 4801 | __be32 *p; |
| 4802 | |
| 4803 | if (nfserr) |
| 4804 | return nfserr; |
| 4805 | |
| 4806 | /* 8 sec, 4 nsec */ |
| 4807 | p = xdr_reserve_space(xdr, 12); |
| 4808 | if (!p) |
| 4809 | return nfserr_resource; |
| 4810 | |
| 4811 | /* cnr_lease_time */ |
| 4812 | p = xdr_encode_hyper(p, cn->cpn_sec); |
| 4813 | *p++ = cpu_to_be32(cn->cpn_nsec); |
| 4814 | |
| 4815 | /* cnr_stateid */ |
| 4816 | nfserr = nfsd4_encode_stateid(xdr, &cn->cpn_cnr_stateid); |
| 4817 | if (nfserr) |
| 4818 | return nfserr; |
| 4819 | |
| 4820 | /* cnr_src.nl_nsvr */ |
| 4821 | p = xdr_reserve_space(xdr, 4); |
| 4822 | if (!p) |
| 4823 | return nfserr_resource; |
| 4824 | |
| 4825 | *p++ = cpu_to_be32(1); |
| 4826 | |
| 4827 | return nfsd42_encode_nl4_server(resp, &cn->cpn_src); |
| 4828 | } |
| 4829 | |
| 4830 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4831 | nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4832 | struct nfsd4_seek *seek) |
| 4833 | { |
| 4834 | __be32 *p; |
| 4835 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4836 | p = xdr_reserve_space(&resp->xdr, 4 + 8); |
| 4837 | *p++ = cpu_to_be32(seek->seek_eof); |
| 4838 | p = xdr_encode_hyper(p, seek->seek_pos); |
| 4839 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4840 | return 0; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | static __be32 |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4844 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
| 4845 | { |
| 4846 | return nfserr; |
| 4847 | } |
| 4848 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4849 | /* |
| 4850 | * Encode kmalloc-ed buffer in to XDR stream. |
| 4851 | */ |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 4852 | static __be32 |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4853 | nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen) |
| 4854 | { |
| 4855 | u32 cplen; |
| 4856 | __be32 *p; |
| 4857 | |
| 4858 | cplen = min_t(unsigned long, buflen, |
| 4859 | ((void *)xdr->end - (void *)xdr->p)); |
| 4860 | p = xdr_reserve_space(xdr, cplen); |
| 4861 | if (!p) |
| 4862 | return nfserr_resource; |
| 4863 | |
| 4864 | memcpy(p, buf, cplen); |
| 4865 | buf += cplen; |
| 4866 | buflen -= cplen; |
| 4867 | |
| 4868 | while (buflen) { |
| 4869 | cplen = min_t(u32, buflen, PAGE_SIZE); |
| 4870 | p = xdr_reserve_space(xdr, cplen); |
| 4871 | if (!p) |
| 4872 | return nfserr_resource; |
| 4873 | |
| 4874 | memcpy(p, buf, cplen); |
| 4875 | |
| 4876 | if (cplen < PAGE_SIZE) { |
| 4877 | /* |
| 4878 | * We're done, with a length that wasn't page |
| 4879 | * aligned, so possibly not word aligned. Pad |
| 4880 | * any trailing bytes with 0. |
| 4881 | */ |
| 4882 | xdr_encode_opaque_fixed(p, NULL, cplen); |
| 4883 | break; |
| 4884 | } |
| 4885 | |
| 4886 | buflen -= PAGE_SIZE; |
| 4887 | buf += PAGE_SIZE; |
| 4888 | } |
| 4889 | |
| 4890 | return 0; |
| 4891 | } |
| 4892 | |
| 4893 | static __be32 |
| 4894 | nfsd4_encode_getxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4895 | struct nfsd4_getxattr *getxattr) |
| 4896 | { |
| 4897 | struct xdr_stream *xdr = &resp->xdr; |
| 4898 | __be32 *p, err; |
| 4899 | |
| 4900 | p = xdr_reserve_space(xdr, 4); |
| 4901 | if (!p) |
| 4902 | return nfserr_resource; |
| 4903 | |
| 4904 | *p = cpu_to_be32(getxattr->getxa_len); |
| 4905 | |
| 4906 | if (getxattr->getxa_len == 0) |
| 4907 | return 0; |
| 4908 | |
| 4909 | err = nfsd4_vbuf_to_stream(xdr, getxattr->getxa_buf, |
| 4910 | getxattr->getxa_len); |
| 4911 | |
| 4912 | kvfree(getxattr->getxa_buf); |
| 4913 | |
| 4914 | return err; |
| 4915 | } |
| 4916 | |
| 4917 | static __be32 |
| 4918 | nfsd4_encode_setxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4919 | struct nfsd4_setxattr *setxattr) |
| 4920 | { |
| 4921 | struct xdr_stream *xdr = &resp->xdr; |
| 4922 | __be32 *p; |
| 4923 | |
| 4924 | p = xdr_reserve_space(xdr, 20); |
| 4925 | if (!p) |
| 4926 | return nfserr_resource; |
| 4927 | |
| 4928 | encode_cinfo(p, &setxattr->setxa_cinfo); |
| 4929 | |
| 4930 | return 0; |
| 4931 | } |
| 4932 | |
| 4933 | /* |
| 4934 | * See if there are cookie values that can be rejected outright. |
| 4935 | */ |
| 4936 | static __be32 |
| 4937 | nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs, |
| 4938 | u32 *offsetp) |
| 4939 | { |
| 4940 | u64 cookie = listxattrs->lsxa_cookie; |
| 4941 | |
| 4942 | /* |
| 4943 | * If the cookie is larger than the maximum number we can fit |
| 4944 | * in either the buffer we just got back from vfs_listxattr, or, |
| 4945 | * XDR-encoded, in the return buffer, it's invalid. |
| 4946 | */ |
| 4947 | if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2)) |
| 4948 | return nfserr_badcookie; |
| 4949 | |
| 4950 | if (cookie > (listxattrs->lsxa_maxcount / |
| 4951 | (XDR_QUADLEN(XATTR_USER_PREFIX_LEN + 2) + 4))) |
| 4952 | return nfserr_badcookie; |
| 4953 | |
| 4954 | *offsetp = (u32)cookie; |
| 4955 | return 0; |
| 4956 | } |
| 4957 | |
| 4958 | static __be32 |
| 4959 | nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4960 | struct nfsd4_listxattrs *listxattrs) |
| 4961 | { |
| 4962 | struct xdr_stream *xdr = &resp->xdr; |
| 4963 | u32 cookie_offset, count_offset, eof; |
| 4964 | u32 left, xdrleft, slen, count; |
| 4965 | u32 xdrlen, offset; |
| 4966 | u64 cookie; |
| 4967 | char *sp; |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 4968 | __be32 status, tmp; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4969 | __be32 *p; |
| 4970 | u32 nuser; |
| 4971 | |
| 4972 | eof = 1; |
| 4973 | |
| 4974 | status = nfsd4_listxattr_validate_cookie(listxattrs, &offset); |
| 4975 | if (status) |
| 4976 | goto out; |
| 4977 | |
| 4978 | /* |
| 4979 | * Reserve space for the cookie and the name array count. Record |
| 4980 | * the offsets to save them later. |
| 4981 | */ |
| 4982 | cookie_offset = xdr->buf->len; |
| 4983 | count_offset = cookie_offset + 8; |
| 4984 | p = xdr_reserve_space(xdr, 12); |
| 4985 | if (!p) { |
| 4986 | status = nfserr_resource; |
| 4987 | goto out; |
| 4988 | } |
| 4989 | |
| 4990 | count = 0; |
| 4991 | left = listxattrs->lsxa_len; |
| 4992 | sp = listxattrs->lsxa_buf; |
| 4993 | nuser = 0; |
| 4994 | |
| 4995 | xdrleft = listxattrs->lsxa_maxcount; |
| 4996 | |
| 4997 | while (left > 0 && xdrleft > 0) { |
| 4998 | slen = strlen(sp); |
| 4999 | |
| 5000 | /* |
Alex Dewar | 4cce11fa | 2020-08-17 18:51:26 +0100 | [diff] [blame] | 5001 | * 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] | 5002 | */ |
| 5003 | if (strncmp(sp, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) |
| 5004 | goto contloop; |
| 5005 | |
| 5006 | slen -= XATTR_USER_PREFIX_LEN; |
| 5007 | xdrlen = 4 + ((slen + 3) & ~3); |
| 5008 | if (xdrlen > xdrleft) { |
| 5009 | if (count == 0) { |
| 5010 | /* |
| 5011 | * Can't even fit the first attribute name. |
| 5012 | */ |
| 5013 | status = nfserr_toosmall; |
| 5014 | goto out; |
| 5015 | } |
| 5016 | eof = 0; |
| 5017 | goto wreof; |
| 5018 | } |
| 5019 | |
| 5020 | left -= XATTR_USER_PREFIX_LEN; |
| 5021 | sp += XATTR_USER_PREFIX_LEN; |
| 5022 | if (nuser++ < offset) |
| 5023 | goto contloop; |
| 5024 | |
| 5025 | |
| 5026 | p = xdr_reserve_space(xdr, xdrlen); |
| 5027 | if (!p) { |
| 5028 | status = nfserr_resource; |
| 5029 | goto out; |
| 5030 | } |
| 5031 | |
Alex Dewar | e2a1840 | 2020-08-12 15:12:51 +0100 | [diff] [blame] | 5032 | xdr_encode_opaque(p, sp, slen); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5033 | |
| 5034 | xdrleft -= xdrlen; |
| 5035 | count++; |
| 5036 | contloop: |
| 5037 | sp += slen + 1; |
| 5038 | left -= slen + 1; |
| 5039 | } |
| 5040 | |
| 5041 | /* |
| 5042 | * If there were user attributes to copy, but we didn't copy |
| 5043 | * any, the offset was too large (e.g. the cookie was invalid). |
| 5044 | */ |
| 5045 | if (nuser > 0 && count == 0) { |
| 5046 | status = nfserr_badcookie; |
| 5047 | goto out; |
| 5048 | } |
| 5049 | |
| 5050 | wreof: |
| 5051 | p = xdr_reserve_space(xdr, 4); |
| 5052 | if (!p) { |
| 5053 | status = nfserr_resource; |
| 5054 | goto out; |
| 5055 | } |
| 5056 | *p = cpu_to_be32(eof); |
| 5057 | |
| 5058 | cookie = offset + count; |
| 5059 | |
| 5060 | write_bytes_to_xdr_buf(xdr->buf, cookie_offset, &cookie, 8); |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5061 | tmp = cpu_to_be32(count); |
| 5062 | 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] | 5063 | out: |
| 5064 | if (listxattrs->lsxa_len) |
| 5065 | kvfree(listxattrs->lsxa_buf); |
| 5066 | return status; |
| 5067 | } |
| 5068 | |
| 5069 | static __be32 |
| 5070 | nfsd4_encode_removexattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5071 | struct nfsd4_removexattr *removexattr) |
| 5072 | { |
| 5073 | struct xdr_stream *xdr = &resp->xdr; |
| 5074 | __be32 *p; |
| 5075 | |
| 5076 | p = xdr_reserve_space(xdr, 20); |
| 5077 | if (!p) |
| 5078 | return nfserr_resource; |
| 5079 | |
| 5080 | p = encode_cinfo(p, &removexattr->rmxa_cinfo); |
| 5081 | return 0; |
| 5082 | } |
| 5083 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5084 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
| 5085 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5086 | /* |
| 5087 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 |
| 5088 | * since we don't need to filter out obsolete ops as this is |
| 5089 | * done in the decoding phase. |
| 5090 | */ |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 5091 | static const nfsd4_enc nfsd4_enc_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5092 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
| 5093 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
| 5094 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, |
| 5095 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, |
| 5096 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5097 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
| 5098 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, |
| 5099 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, |
| 5100 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, |
| 5101 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, |
| 5102 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, |
| 5103 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, |
| 5104 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5105 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5106 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5107 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, |
Benny Halevy | 84f09f4 | 2009-03-04 23:05:35 +0200 | [diff] [blame] | 5108 | [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5109 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
| 5110 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, |
| 5111 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5112 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5113 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5114 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, |
| 5115 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, |
| 5116 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, |
| 5117 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, |
| 5118 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, |
| 5119 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, |
| 5120 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5121 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5122 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, |
| 5123 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, |
| 5124 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, |
| 5125 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, |
| 5126 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5127 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
| 5128 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5129 | |
| 5130 | /* NFSv4.1 operations */ |
| 5131 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 5132 | [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] | 5133 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, |
| 5134 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, |
Kinglong Mee | 43212cc | 2013-12-09 19:04:23 +0800 | [diff] [blame] | 5135 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5136 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5137 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5138 | #ifdef CONFIG_NFSD_PNFS |
| 5139 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_getdeviceinfo, |
| 5140 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5141 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_layoutcommit, |
| 5142 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_layoutget, |
| 5143 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_layoutreturn, |
| 5144 | #else |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5145 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, |
| 5146 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5147 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, |
| 5148 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, |
| 5149 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5150 | #endif |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 5151 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5152 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, |
| 5153 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 5154 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5155 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5156 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, |
| 5157 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5158 | |
| 5159 | /* NFSv4.2 operations */ |
| 5160 | [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 5161 | [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 5162 | [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_copy_notify, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5163 | [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5164 | [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5165 | [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop, |
| 5166 | [OP_LAYOUTSTATS] = (nfsd4_enc)nfsd4_encode_noop, |
| 5167 | [OP_OFFLOAD_CANCEL] = (nfsd4_enc)nfsd4_encode_noop, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 5168 | [OP_OFFLOAD_STATUS] = (nfsd4_enc)nfsd4_encode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 5169 | [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_read_plus, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 5170 | [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5171 | [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 5172 | [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5173 | |
| 5174 | /* RFC 8276 extended atributes operations */ |
| 5175 | [OP_GETXATTR] = (nfsd4_enc)nfsd4_encode_getxattr, |
| 5176 | [OP_SETXATTR] = (nfsd4_enc)nfsd4_encode_setxattr, |
| 5177 | [OP_LISTXATTRS] = (nfsd4_enc)nfsd4_encode_listxattrs, |
| 5178 | [OP_REMOVEXATTR] = (nfsd4_enc)nfsd4_encode_removexattr, |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5179 | }; |
| 5180 | |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5181 | /* |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5182 | * Calculate whether we still have space to encode repsize bytes. |
| 5183 | * There are two considerations: |
| 5184 | * - For NFS versions >=4.1, the size of the reply must stay within |
| 5185 | * session limits |
| 5186 | * - For all NFS versions, we must stay within limited preallocated |
| 5187 | * buffer space. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5188 | * |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5189 | * This is called before the operation is processed, so can only provide |
| 5190 | * an upper estimate. For some nonidempotent operations (such as |
| 5191 | * getattr), it's not necessarily a problem if that estimate is wrong, |
| 5192 | * as we can fail it after processing without significant side effects. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5193 | */ |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5194 | __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize) |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5195 | { |
J. Bruce Fields | 67492c9 | 2014-03-08 16:42:05 -0500 | [diff] [blame] | 5196 | struct xdr_buf *buf = &resp->rqstp->rq_res; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5197 | struct nfsd4_slot *slot = resp->cstate.slot; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5198 | |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5199 | if (buf->len + respsize <= buf->buflen) |
| 5200 | return nfs_ok; |
| 5201 | if (!nfsd4_has_session(&resp->cstate)) |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5202 | return nfserr_resource; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5203 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) { |
| 5204 | WARN_ON_ONCE(1); |
| 5205 | return nfserr_rep_too_big_to_cache; |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5206 | } |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5207 | return nfserr_rep_too_big; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5208 | } |
| 5209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | void |
| 5211 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 5212 | { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5213 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5214 | struct nfs4_stateowner *so = resp->cstate.replay_owner; |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5215 | struct svc_rqst *rqstp = resp->rqstp; |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5216 | const struct nfsd4_operation *opdesc = op->opdesc; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5217 | int post_err_offset; |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5218 | nfsd4_enc encoder; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5219 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5221 | p = xdr_reserve_space(xdr, 8); |
| 5222 | if (!p) { |
| 5223 | WARN_ON_ONCE(1); |
| 5224 | return; |
| 5225 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5226 | *p++ = cpu_to_be32(op->opnum); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5227 | post_err_offset = xdr->buf->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5229 | if (op->opnum == OP_ILLEGAL) |
| 5230 | goto status; |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 5231 | if (op->status && opdesc && |
| 5232 | !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE)) |
| 5233 | goto status; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5234 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
| 5235 | !nfsd4_enc_ops[op->opnum]); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5236 | encoder = nfsd4_enc_ops[op->opnum]; |
| 5237 | op->status = encoder(resp, op->status, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 5238 | if (op->status) |
| 5239 | trace_nfsd_compound_encode_err(rqstp, op->opnum, op->status); |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5240 | if (opdesc && opdesc->op_release) |
| 5241 | opdesc->op_release(&op->u); |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5242 | xdr_commit_encode(xdr); |
| 5243 | |
J. Bruce Fields | 067e1ac | 2014-03-21 17:26:44 -0400 | [diff] [blame] | 5244 | /* nfsd4_check_resp_size guarantees enough room for error status */ |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5245 | if (!op->status) { |
| 5246 | int space_needed = 0; |
| 5247 | if (!nfsd4_last_compound_op(rqstp)) |
| 5248 | space_needed = COMPOUND_ERR_SLACK_SPACE; |
| 5249 | op->status = nfsd4_check_resp_size(resp, space_needed); |
| 5250 | } |
J. Bruce Fields | c8f13d9 | 2014-05-08 17:38:18 -0400 | [diff] [blame] | 5251 | if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) { |
| 5252 | struct nfsd4_slot *slot = resp->cstate.slot; |
| 5253 | |
| 5254 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) |
| 5255 | op->status = nfserr_rep_too_big_to_cache; |
| 5256 | else |
| 5257 | op->status = nfserr_rep_too_big; |
| 5258 | } |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5259 | if (op->status == nfserr_resource || |
| 5260 | op->status == nfserr_rep_too_big || |
| 5261 | op->status == nfserr_rep_too_big_to_cache) { |
| 5262 | /* |
| 5263 | * The operation may have already been encoded or |
| 5264 | * partially encoded. No op returns anything additional |
| 5265 | * in the case of one of these three errors, so we can |
| 5266 | * just truncate back to after the status. But it's a |
| 5267 | * bug if we had to do this on a non-idempotent op: |
| 5268 | */ |
| 5269 | warn_on_nonidempotent_op(op); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5270 | xdr_truncate_encode(xdr, post_err_offset); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5271 | } |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5272 | if (so) { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5273 | int len = xdr->buf->len - post_err_offset; |
| 5274 | |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5275 | so->so_replay.rp_status = op->status; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5276 | so->so_replay.rp_buflen = len; |
| 5277 | read_bytes_from_xdr_buf(xdr->buf, post_err_offset, |
| 5278 | so->so_replay.rp_buf, len); |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5279 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5280 | status: |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5281 | /* Note that op->status is already in network byte order: */ |
| 5282 | 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] | 5283 | } |
| 5284 | |
| 5285 | /* |
| 5286 | * Encode the reply stored in the stateowner reply cache |
| 5287 | * |
| 5288 | * XDR note: do not encode rp->rp_buflen: the buffer contains the |
| 5289 | * previously sent already encoded operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5290 | */ |
| 5291 | void |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5292 | nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5294 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | struct nfs4_replay *rp = op->replay; |
| 5296 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5297 | p = xdr_reserve_space(xdr, 8 + rp->rp_buflen); |
| 5298 | if (!p) { |
| 5299 | WARN_ON_ONCE(1); |
| 5300 | return; |
| 5301 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5302 | *p++ = cpu_to_be32(op->opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5303 | *p++ = rp->rp_status; /* already xdr'ed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5304 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 5305 | p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | } |
| 5307 | |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 5308 | void nfsd4_release_compoundargs(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5309 | { |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5310 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | if (args->ops != args->iops) { |
| 5313 | kfree(args->ops); |
| 5314 | args->ops = args->iops; |
| 5315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | while (args->to_free) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 5317 | struct svcxdr_tmpbuf *tb = args->to_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | args->to_free = tb->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | kfree(tb); |
| 5320 | } |
| 5321 | } |
| 5322 | |
| 5323 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5324 | nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5326 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5327 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5328 | /* svcxdr_tmp_alloc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5329 | args->tmpp = NULL; |
| 5330 | args->to_free = NULL; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5331 | |
| 5332 | args->xdr = &rqstp->rq_arg_stream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5333 | args->ops = args->iops; |
| 5334 | args->rqstp = rqstp; |
| 5335 | |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5336 | return !nfsd4_decode_compound(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5340 | nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5342 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
J. Bruce Fields | 6ac9039 | 2014-02-26 17:39:35 -0500 | [diff] [blame] | 5343 | struct xdr_buf *buf = resp->xdr.buf; |
| 5344 | |
| 5345 | WARN_ON_ONCE(buf->len != buf->head[0].iov_len + buf->page_len + |
| 5346 | buf->tail[0].iov_len); |
J. Bruce Fields | dd97fdd | 2014-02-26 17:16:27 -0500 | [diff] [blame] | 5347 | |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 5348 | *p = resp->cstate.status; |
| 5349 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5350 | rqstp->rq_next_page = resp->xdr.page_ptr + 1; |
| 5351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5352 | p = resp->tagp; |
| 5353 | *p++ = htonl(resp->taglen); |
| 5354 | memcpy(p, resp->tag, resp->taglen); |
| 5355 | p += XDR_QUADLEN(resp->taglen); |
| 5356 | *p++ = htonl(resp->opcnt); |
| 5357 | |
Trond Myklebust | b607664 | 2014-06-30 11:48:35 -0400 | [diff] [blame] | 5358 | nfsd4_sequence_done(resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | return 1; |
| 5360 | } |
| 5361 | |
| 5362 | /* |
| 5363 | * Local variables: |
| 5364 | * c-basic-offset: 8 |
| 5365 | * End: |
| 5366 | */ |