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