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. |
| 34 | * |
| 35 | * TODO: Neil Brown made the following observation: We currently |
| 36 | * initially reserve NFSD_BUFSIZE space on the transmit queue and |
| 37 | * never release any of that until the request is complete. |
| 38 | * It would be good to calculate a new maximum response size while |
| 39 | * decoding the COMPOUND, and call svc_reserve with this number |
| 40 | * at the end of nfs4svc_decode_compoundargs. |
| 41 | */ |
| 42 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/namei.h> |
Boaz Harrosh | 341eb18 | 2009-12-03 20:29:12 +0200 | [diff] [blame] | 45 | #include <linux/statfs.h> |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 46 | #include <linux/utsname.h> |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 47 | #include <linux/pagemap.h> |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 48 | #include <linux/sunrpc/svcauth_gss.h> |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 49 | |
J. Bruce Fields | 2ca72e1 | 2011-01-04 17:37:15 -0500 | [diff] [blame] | 50 | #include "idmap.h" |
| 51 | #include "acl.h" |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 52 | #include "xdr4.h" |
J. Bruce Fields | 0a3adad | 2009-11-04 18:12:35 -0500 | [diff] [blame] | 53 | #include "vfs.h" |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 54 | #include "state.h" |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 55 | #include "cache.h" |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 56 | #include "netns.h" |
J. Bruce Fields | 2ca72e1 | 2011-01-04 17:37:15 -0500 | [diff] [blame] | 57 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 58 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 59 | #include <linux/security.h> |
| 60 | #endif |
| 61 | |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define NFSDDBG_FACILITY NFSDDBG_XDR |
| 64 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 65 | /* |
| 66 | * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing |
| 67 | * directory in order to indicate to the client that a filesystem boundary is present |
| 68 | * We use a fixed fsid for a referral |
| 69 | */ |
| 70 | #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL |
| 71 | #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL |
| 72 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 73 | static __be32 |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 74 | check_filename(char *str, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
| 76 | int i; |
| 77 | |
| 78 | if (len == 0) |
| 79 | return nfserr_inval; |
| 80 | if (isdotent(str, len)) |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 81 | return nfserr_badname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | for (i = 0; i < len; i++) |
| 83 | if (str[i] == '/') |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 84 | return nfserr_badname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define DECODE_HEAD \ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 89 | __be32 *p; \ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 90 | __be32 status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #define DECODE_TAIL \ |
| 92 | status = 0; \ |
| 93 | out: \ |
| 94 | return status; \ |
| 95 | xdr_error: \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 96 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 97 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | status = nfserr_bad_xdr; \ |
| 99 | goto out |
| 100 | |
| 101 | #define READ32(x) (x) = ntohl(*p++) |
| 102 | #define READ64(x) do { \ |
| 103 | (x) = (u64)ntohl(*p++) << 32; \ |
| 104 | (x) |= ntohl(*p++); \ |
| 105 | } while (0) |
| 106 | #define READTIME(x) do { \ |
| 107 | p++; \ |
| 108 | (x) = ntohl(*p++); \ |
| 109 | p++; \ |
| 110 | } while (0) |
| 111 | #define READMEM(x,nbytes) do { \ |
| 112 | x = (char *)p; \ |
| 113 | p += XDR_QUADLEN(nbytes); \ |
| 114 | } while (0) |
| 115 | #define SAVEMEM(x,nbytes) do { \ |
| 116 | if (!(x = (p==argp->tmp || p == argp->tmpp) ? \ |
| 117 | savemem(argp, p, nbytes) : \ |
| 118 | (char *)p)) { \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 119 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 120 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | goto xdr_error; \ |
| 122 | } \ |
| 123 | p += XDR_QUADLEN(nbytes); \ |
| 124 | } while (0) |
| 125 | #define COPYMEM(x,nbytes) do { \ |
| 126 | memcpy((x), p, nbytes); \ |
| 127 | p += XDR_QUADLEN(nbytes); \ |
| 128 | } while (0) |
| 129 | |
| 130 | /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */ |
| 131 | #define READ_BUF(nbytes) do { \ |
| 132 | if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \ |
| 133 | p = argp->p; \ |
| 134 | argp->p += XDR_QUADLEN(nbytes); \ |
| 135 | } else if (!(p = read_buf(argp, nbytes))) { \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 136 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 137 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | goto xdr_error; \ |
| 139 | } \ |
| 140 | } while (0) |
| 141 | |
J. Bruce Fields | 590b743 | 2013-06-21 17:06:29 -0400 | [diff] [blame] | 142 | static void next_decode_page(struct nfsd4_compoundargs *argp) |
| 143 | { |
J. Bruce Fields | 590b743 | 2013-06-21 17:06:29 -0400 | [diff] [blame] | 144 | argp->p = page_address(argp->pagelist[0]); |
J. Bruce Fields | 365da4a | 2013-11-19 17:32:43 -0500 | [diff] [blame] | 145 | argp->pagelist++; |
J. Bruce Fields | 590b743 | 2013-06-21 17:06:29 -0400 | [diff] [blame] | 146 | if (argp->pagelen < PAGE_SIZE) { |
| 147 | argp->end = argp->p + (argp->pagelen>>2); |
| 148 | argp->pagelen = 0; |
| 149 | } else { |
| 150 | argp->end = argp->p + (PAGE_SIZE>>2); |
| 151 | argp->pagelen -= PAGE_SIZE; |
| 152 | } |
| 153 | } |
| 154 | |
J. Bruce Fields | ca2a05a | 2007-11-11 15:43:12 -0500 | [diff] [blame] | 155 | static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
| 157 | /* We want more bytes than seem to be available. |
| 158 | * Maybe we need a new page, maybe we have just run out |
| 159 | */ |
J. Bruce Fields | ca2a05a | 2007-11-11 15:43:12 -0500 | [diff] [blame] | 160 | unsigned int avail = (char *)argp->end - (char *)argp->p; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 161 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | if (avail + argp->pagelen < nbytes) |
| 163 | return NULL; |
| 164 | if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */ |
| 165 | return NULL; |
| 166 | /* ok, we can do it with the current plus the next page */ |
| 167 | if (nbytes <= sizeof(argp->tmp)) |
| 168 | p = argp->tmp; |
| 169 | else { |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 170 | kfree(argp->tmpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL); |
| 172 | if (!p) |
| 173 | return NULL; |
| 174 | |
| 175 | } |
J. Bruce Fields | ca2a05a | 2007-11-11 15:43:12 -0500 | [diff] [blame] | 176 | /* |
| 177 | * The following memcpy is safe because read_buf is always |
| 178 | * called with nbytes > avail, and the two cases above both |
| 179 | * guarantee p points to at least nbytes bytes. |
| 180 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | memcpy(p, argp->p, avail); |
J. Bruce Fields | 590b743 | 2013-06-21 17:06:29 -0400 | [diff] [blame] | 182 | next_decode_page(argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | memcpy(((char*)p)+avail, argp->p, (nbytes - avail)); |
| 184 | argp->p += XDR_QUADLEN(nbytes - avail); |
| 185 | return p; |
| 186 | } |
| 187 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 188 | static int zero_clientid(clientid_t *clid) |
| 189 | { |
| 190 | return (clid->cl_boot == 0) && (clid->cl_id == 0); |
| 191 | } |
| 192 | |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 193 | /** |
| 194 | * defer_free - mark an allocation as deferred freed |
| 195 | * @argp: NFSv4 compound argument structure to be freed with |
| 196 | * @release: release callback to free @p, typically kfree() |
| 197 | * @p: pointer to be freed |
| 198 | * |
| 199 | * Marks @p to be freed when processing the compound operation |
| 200 | * described in @argp finishes. |
| 201 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | static int |
| 203 | defer_free(struct nfsd4_compoundargs *argp, |
| 204 | void (*release)(const void *), void *p) |
| 205 | { |
| 206 | struct tmpbuf *tb; |
| 207 | |
| 208 | tb = kmalloc(sizeof(*tb), GFP_KERNEL); |
| 209 | if (!tb) |
| 210 | return -ENOMEM; |
| 211 | tb->buf = p; |
| 212 | tb->release = release; |
| 213 | tb->next = argp->to_free; |
| 214 | argp->to_free = tb; |
| 215 | return 0; |
| 216 | } |
| 217 | |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 218 | /** |
| 219 | * savemem - duplicate a chunk of memory for later processing |
| 220 | * @argp: NFSv4 compound argument structure to be freed with |
| 221 | * @p: pointer to be duplicated |
| 222 | * @nbytes: length to be duplicated |
| 223 | * |
| 224 | * Returns a pointer to a copy of @nbytes bytes of memory at @p |
| 225 | * that are preserved until processing of the NFSv4 compound |
| 226 | * operation described by @argp finishes. |
| 227 | */ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 228 | static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if (p == argp->tmp) { |
Thomas Meyer | 67114fe | 2011-11-17 23:43:40 +0100 | [diff] [blame] | 231 | p = kmemdup(argp->tmp, nbytes, GFP_KERNEL); |
J. Bruce Fields | a4db5fe | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 232 | if (!p) |
| 233 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } else { |
Eric Sesterhenn | 73dff8b | 2006-10-03 23:37:14 +0200 | [diff] [blame] | 235 | BUG_ON(p != argp->tmpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | argp->tmpp = NULL; |
| 237 | } |
| 238 | if (defer_free(argp, kfree, p)) { |
J. Bruce Fields | a4db5fe | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 239 | kfree(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | return NULL; |
| 241 | } else |
| 242 | return (char *)p; |
| 243 | } |
| 244 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 245 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) |
| 247 | { |
| 248 | u32 bmlen; |
| 249 | DECODE_HEAD; |
| 250 | |
| 251 | bmval[0] = 0; |
| 252 | bmval[1] = 0; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 253 | bmval[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | READ_BUF(4); |
| 256 | READ32(bmlen); |
| 257 | if (bmlen > 1000) |
| 258 | goto xdr_error; |
| 259 | |
| 260 | READ_BUF(bmlen << 2); |
| 261 | if (bmlen > 0) |
| 262 | READ32(bmval[0]); |
| 263 | if (bmlen > 1) |
| 264 | READ32(bmval[1]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 265 | if (bmlen > 2) |
| 266 | READ32(bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | DECODE_TAIL; |
| 269 | } |
| 270 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 271 | static __be32 |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 272 | nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 273 | struct iattr *iattr, struct nfs4_acl **acl, |
| 274 | struct xdr_netobj *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
| 276 | int expected_len, len = 0; |
| 277 | u32 dummy32; |
| 278 | char *buf; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 279 | int host_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | DECODE_HEAD; |
| 282 | iattr->ia_valid = 0; |
| 283 | if ((status = nfsd4_decode_bitmap(argp, bmval))) |
| 284 | return status; |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | READ_BUF(4); |
| 287 | READ32(expected_len); |
| 288 | |
| 289 | if (bmval[0] & FATTR4_WORD0_SIZE) { |
| 290 | READ_BUF(8); |
| 291 | len += 8; |
| 292 | READ64(iattr->ia_size); |
| 293 | iattr->ia_valid |= ATTR_SIZE; |
| 294 | } |
| 295 | if (bmval[0] & FATTR4_WORD0_ACL) { |
J. Bruce Fields | 64a817c | 2013-03-26 14:11:13 -0400 | [diff] [blame] | 296 | u32 nace; |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 297 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | READ_BUF(4); len += 4; |
| 300 | READ32(nace); |
| 301 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 302 | if (nace > NFS4_ACL_MAX) |
| 303 | return nfserr_resource; |
| 304 | |
| 305 | *acl = nfs4_acl_new(nace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | if (*acl == NULL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 307 | host_err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | goto out_nfserr; |
| 309 | } |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 310 | defer_free(argp, kfree, *acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 312 | (*acl)->naces = nace; |
| 313 | for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | READ_BUF(16); len += 16; |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 315 | READ32(ace->type); |
| 316 | READ32(ace->flag); |
| 317 | READ32(ace->access_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | READ32(dummy32); |
| 319 | READ_BUF(dummy32); |
| 320 | len += XDR_QUADLEN(dummy32) << 2; |
| 321 | READMEM(buf, dummy32); |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 322 | ace->whotype = nfs4_acl_get_whotype(buf, dummy32); |
J. Bruce Fields | 3c72602 | 2011-01-04 17:53:52 -0500 | [diff] [blame] | 323 | status = nfs_ok; |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 324 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 325 | ; |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 326 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
J. Bruce Fields | 3c72602 | 2011-01-04 17:53:52 -0500 | [diff] [blame] | 327 | status = nfsd_map_name_to_gid(argp->rqstp, |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 328 | buf, dummy32, &ace->who_gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | else |
J. Bruce Fields | 3c72602 | 2011-01-04 17:53:52 -0500 | [diff] [blame] | 330 | status = nfsd_map_name_to_uid(argp->rqstp, |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 331 | buf, dummy32, &ace->who_uid); |
J. Bruce Fields | 3c72602 | 2011-01-04 17:53:52 -0500 | [diff] [blame] | 332 | if (status) |
| 333 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | } else |
| 336 | *acl = NULL; |
| 337 | if (bmval[1] & FATTR4_WORD1_MODE) { |
| 338 | READ_BUF(4); |
| 339 | len += 4; |
| 340 | READ32(iattr->ia_mode); |
| 341 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
| 342 | iattr->ia_valid |= ATTR_MODE; |
| 343 | } |
| 344 | if (bmval[1] & FATTR4_WORD1_OWNER) { |
| 345 | READ_BUF(4); |
| 346 | len += 4; |
| 347 | READ32(dummy32); |
| 348 | READ_BUF(dummy32); |
| 349 | len += (XDR_QUADLEN(dummy32) << 2); |
| 350 | READMEM(buf, dummy32); |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 351 | if ((status = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid))) |
| 352 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | iattr->ia_valid |= ATTR_UID; |
| 354 | } |
| 355 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { |
| 356 | READ_BUF(4); |
| 357 | len += 4; |
| 358 | READ32(dummy32); |
| 359 | READ_BUF(dummy32); |
| 360 | len += (XDR_QUADLEN(dummy32) << 2); |
| 361 | READMEM(buf, dummy32); |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 362 | if ((status = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid))) |
| 363 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | iattr->ia_valid |= ATTR_GID; |
| 365 | } |
| 366 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { |
| 367 | READ_BUF(4); |
| 368 | len += 4; |
| 369 | READ32(dummy32); |
| 370 | switch (dummy32) { |
| 371 | case NFS4_SET_TO_CLIENT_TIME: |
| 372 | /* We require the high 32 bits of 'seconds' to be 0, and we ignore |
| 373 | all 32 bits of 'nseconds'. */ |
| 374 | READ_BUF(12); |
| 375 | len += 12; |
Bryan Schumaker | bf8d909 | 2013-04-19 16:09:38 -0400 | [diff] [blame] | 376 | READ64(iattr->ia_atime.tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | READ32(iattr->ia_atime.tv_nsec); |
| 378 | if (iattr->ia_atime.tv_nsec >= (u32)1000000000) |
| 379 | return nfserr_inval; |
| 380 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
| 381 | break; |
| 382 | case NFS4_SET_TO_SERVER_TIME: |
| 383 | iattr->ia_valid |= ATTR_ATIME; |
| 384 | break; |
| 385 | default: |
| 386 | goto xdr_error; |
| 387 | } |
| 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
| 390 | READ_BUF(4); |
| 391 | len += 4; |
| 392 | READ32(dummy32); |
| 393 | switch (dummy32) { |
| 394 | case NFS4_SET_TO_CLIENT_TIME: |
| 395 | /* We require the high 32 bits of 'seconds' to be 0, and we ignore |
| 396 | all 32 bits of 'nseconds'. */ |
| 397 | READ_BUF(12); |
| 398 | len += 12; |
Bryan Schumaker | bf8d909 | 2013-04-19 16:09:38 -0400 | [diff] [blame] | 399 | READ64(iattr->ia_mtime.tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | READ32(iattr->ia_mtime.tv_nsec); |
| 401 | if (iattr->ia_mtime.tv_nsec >= (u32)1000000000) |
| 402 | return nfserr_inval; |
| 403 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
| 404 | break; |
| 405 | case NFS4_SET_TO_SERVER_TIME: |
| 406 | iattr->ia_valid |= ATTR_MTIME; |
| 407 | break; |
| 408 | default: |
| 409 | goto xdr_error; |
| 410 | } |
| 411 | } |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 412 | |
| 413 | label->len = 0; |
| 414 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 415 | if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { |
| 416 | READ_BUF(4); |
| 417 | len += 4; |
| 418 | READ32(dummy32); /* lfs: we don't use it */ |
| 419 | READ_BUF(4); |
| 420 | len += 4; |
| 421 | READ32(dummy32); /* pi: we don't use it either */ |
| 422 | READ_BUF(4); |
| 423 | len += 4; |
| 424 | READ32(dummy32); |
| 425 | READ_BUF(dummy32); |
| 426 | if (dummy32 > NFSD4_MAX_SEC_LABEL_LEN) |
| 427 | return nfserr_badlabel; |
| 428 | len += (XDR_QUADLEN(dummy32) << 2); |
| 429 | READMEM(buf, dummy32); |
| 430 | label->data = kzalloc(dummy32 + 1, GFP_KERNEL); |
| 431 | if (!label->data) |
| 432 | return nfserr_jukebox; |
J. Bruce Fields | 3378b7f | 2013-11-01 10:42:15 -0400 | [diff] [blame] | 433 | label->len = dummy32; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 434 | defer_free(argp, kfree, label->data); |
| 435 | memcpy(label->data, buf, dummy32); |
| 436 | } |
| 437 | #endif |
| 438 | |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 439 | if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 |
| 440 | || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 |
| 441 | || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) |
| 442 | READ_BUF(expected_len - len); |
| 443 | else if (len != expected_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | goto xdr_error; |
| 445 | |
| 446 | DECODE_TAIL; |
| 447 | |
| 448 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 449 | status = nfserrno(host_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | goto out; |
| 451 | } |
| 452 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 453 | static __be32 |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 454 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 455 | { |
| 456 | DECODE_HEAD; |
| 457 | |
| 458 | READ_BUF(sizeof(stateid_t)); |
| 459 | READ32(sid->si_generation); |
| 460 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 461 | |
| 462 | DECODE_TAIL; |
| 463 | } |
| 464 | |
| 465 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access) |
| 467 | { |
| 468 | DECODE_HEAD; |
| 469 | |
| 470 | READ_BUF(4); |
| 471 | READ32(access->ac_req_access); |
| 472 | |
| 473 | DECODE_TAIL; |
| 474 | } |
| 475 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 476 | static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs) |
| 477 | { |
| 478 | DECODE_HEAD; |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 479 | u32 dummy, uid, gid; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 480 | char *machine_name; |
| 481 | int i; |
| 482 | int nr_secflavs; |
| 483 | |
| 484 | /* callback_sec_params4 */ |
| 485 | READ_BUF(4); |
| 486 | READ32(nr_secflavs); |
J. Bruce Fields | 57569a7 | 2013-05-17 16:25:32 -0400 | [diff] [blame] | 487 | if (nr_secflavs) |
| 488 | cbs->flavor = (u32)(-1); |
| 489 | else |
| 490 | /* Is this legal? Be generous, take it to mean AUTH_NONE: */ |
| 491 | cbs->flavor = 0; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 492 | for (i = 0; i < nr_secflavs; ++i) { |
| 493 | READ_BUF(4); |
| 494 | READ32(dummy); |
| 495 | switch (dummy) { |
| 496 | case RPC_AUTH_NULL: |
| 497 | /* Nothing to read */ |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 498 | if (cbs->flavor == (u32)(-1)) |
| 499 | cbs->flavor = RPC_AUTH_NULL; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 500 | break; |
| 501 | case RPC_AUTH_UNIX: |
| 502 | READ_BUF(8); |
| 503 | /* stamp */ |
| 504 | READ32(dummy); |
| 505 | |
| 506 | /* machine name */ |
| 507 | READ32(dummy); |
| 508 | READ_BUF(dummy); |
| 509 | SAVEMEM(machine_name, dummy); |
| 510 | |
| 511 | /* uid, gid */ |
| 512 | READ_BUF(8); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 513 | READ32(uid); |
| 514 | READ32(gid); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 515 | |
| 516 | /* more gids */ |
| 517 | READ_BUF(4); |
| 518 | READ32(dummy); |
| 519 | READ_BUF(dummy * 4); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 520 | if (cbs->flavor == (u32)(-1)) { |
Eric W. Biederman | 03bc6d1 | 2013-02-02 06:24:49 -0800 | [diff] [blame] | 521 | kuid_t kuid = make_kuid(&init_user_ns, uid); |
| 522 | kgid_t kgid = make_kgid(&init_user_ns, gid); |
| 523 | if (uid_valid(kuid) && gid_valid(kgid)) { |
| 524 | cbs->uid = kuid; |
| 525 | cbs->gid = kgid; |
| 526 | cbs->flavor = RPC_AUTH_UNIX; |
| 527 | } else { |
| 528 | dprintk("RPC_AUTH_UNIX with invalid" |
| 529 | "uid or gid ignoring!\n"); |
| 530 | } |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 531 | } |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 532 | break; |
| 533 | case RPC_AUTH_GSS: |
| 534 | dprintk("RPC_AUTH_GSS callback secflavor " |
| 535 | "not supported!\n"); |
| 536 | READ_BUF(8); |
| 537 | /* gcbp_service */ |
| 538 | READ32(dummy); |
| 539 | /* gcbp_handle_from_server */ |
| 540 | READ32(dummy); |
| 541 | READ_BUF(dummy); |
| 542 | p += XDR_QUADLEN(dummy); |
| 543 | /* gcbp_handle_from_client */ |
| 544 | READ_BUF(4); |
| 545 | READ32(dummy); |
| 546 | READ_BUF(dummy); |
| 547 | break; |
| 548 | default: |
| 549 | dprintk("Illegal callback secflavor\n"); |
| 550 | return nfserr_inval; |
| 551 | } |
| 552 | } |
| 553 | DECODE_TAIL; |
| 554 | } |
| 555 | |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 556 | static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc) |
| 557 | { |
| 558 | DECODE_HEAD; |
| 559 | |
| 560 | READ_BUF(4); |
| 561 | READ32(bc->bc_cb_program); |
| 562 | nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec); |
| 563 | |
| 564 | DECODE_TAIL; |
| 565 | } |
| 566 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 567 | static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts) |
| 568 | { |
| 569 | DECODE_HEAD; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 570 | |
| 571 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 8); |
| 572 | COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 573 | READ32(bcts->dir); |
Bryan Schumaker | 6ce2357 | 2011-04-27 15:47:16 -0400 | [diff] [blame] | 574 | /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker |
| 575 | * could help us figure out we should be using it. */ |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 576 | DECODE_TAIL; |
| 577 | } |
| 578 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 579 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
| 581 | { |
| 582 | DECODE_HEAD; |
| 583 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 584 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | READ32(close->cl_seqid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 586 | return nfsd4_decode_stateid(argp, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | DECODE_TAIL; |
| 589 | } |
| 590 | |
| 591 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 592 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
| 594 | { |
| 595 | DECODE_HEAD; |
| 596 | |
| 597 | READ_BUF(12); |
| 598 | READ64(commit->co_offset); |
| 599 | READ32(commit->co_count); |
| 600 | |
| 601 | DECODE_TAIL; |
| 602 | } |
| 603 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 604 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
| 606 | { |
| 607 | DECODE_HEAD; |
| 608 | |
| 609 | READ_BUF(4); |
| 610 | READ32(create->cr_type); |
| 611 | switch (create->cr_type) { |
| 612 | case NF4LNK: |
| 613 | READ_BUF(4); |
| 614 | READ32(create->cr_linklen); |
| 615 | READ_BUF(create->cr_linklen); |
| 616 | SAVEMEM(create->cr_linkname, create->cr_linklen); |
| 617 | break; |
| 618 | case NF4BLK: |
| 619 | case NF4CHR: |
| 620 | READ_BUF(8); |
| 621 | READ32(create->cr_specdata1); |
| 622 | READ32(create->cr_specdata2); |
| 623 | break; |
| 624 | case NF4SOCK: |
| 625 | case NF4FIFO: |
| 626 | case NF4DIR: |
| 627 | default: |
| 628 | break; |
| 629 | } |
| 630 | |
| 631 | READ_BUF(4); |
| 632 | READ32(create->cr_namelen); |
| 633 | READ_BUF(create->cr_namelen); |
| 634 | SAVEMEM(create->cr_name, create->cr_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 635 | if ((status = check_filename(create->cr_name, create->cr_namelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | return status; |
| 637 | |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 638 | status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr, |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 639 | &create->cr_acl, &create->cr_label); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 640 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | goto out; |
| 642 | |
| 643 | DECODE_TAIL; |
| 644 | } |
| 645 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 646 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
| 648 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 649 | return nfsd4_decode_stateid(argp, &dr->dr_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 652 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
| 654 | { |
| 655 | return nfsd4_decode_bitmap(argp, getattr->ga_bmval); |
| 656 | } |
| 657 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 658 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
| 660 | { |
| 661 | DECODE_HEAD; |
| 662 | |
| 663 | READ_BUF(4); |
| 664 | READ32(link->li_namelen); |
| 665 | READ_BUF(link->li_namelen); |
| 666 | SAVEMEM(link->li_name, link->li_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 667 | if ((status = check_filename(link->li_name, link->li_namelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return status; |
| 669 | |
| 670 | DECODE_TAIL; |
| 671 | } |
| 672 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 673 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 675 | { |
| 676 | DECODE_HEAD; |
| 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* |
| 679 | * type, reclaim(boolean), offset, length, new_lock_owner(boolean) |
| 680 | */ |
| 681 | READ_BUF(28); |
| 682 | READ32(lock->lk_type); |
| 683 | if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT)) |
| 684 | goto xdr_error; |
| 685 | READ32(lock->lk_reclaim); |
| 686 | READ64(lock->lk_offset); |
| 687 | READ64(lock->lk_length); |
| 688 | READ32(lock->lk_is_new); |
| 689 | |
| 690 | if (lock->lk_is_new) { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 691 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | READ32(lock->lk_new_open_seqid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 693 | status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid); |
| 694 | if (status) |
| 695 | return status; |
| 696 | READ_BUF(8 + sizeof(clientid_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | READ32(lock->lk_new_lock_seqid); |
| 698 | COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t)); |
| 699 | READ32(lock->lk_new_owner.len); |
| 700 | READ_BUF(lock->lk_new_owner.len); |
| 701 | READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len); |
| 702 | } else { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 703 | status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid); |
| 704 | if (status) |
| 705 | return status; |
| 706 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | READ32(lock->lk_old_lock_seqid); |
| 708 | } |
| 709 | |
| 710 | DECODE_TAIL; |
| 711 | } |
| 712 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 713 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
| 715 | { |
| 716 | DECODE_HEAD; |
| 717 | |
| 718 | READ_BUF(32); |
| 719 | READ32(lockt->lt_type); |
| 720 | if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
| 721 | goto xdr_error; |
| 722 | READ64(lockt->lt_offset); |
| 723 | READ64(lockt->lt_length); |
| 724 | COPYMEM(&lockt->lt_clientid, 8); |
| 725 | READ32(lockt->lt_owner.len); |
| 726 | READ_BUF(lockt->lt_owner.len); |
| 727 | READMEM(lockt->lt_owner.data, lockt->lt_owner.len); |
| 728 | |
| 729 | DECODE_TAIL; |
| 730 | } |
| 731 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 732 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
| 734 | { |
| 735 | DECODE_HEAD; |
| 736 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 737 | READ_BUF(8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | READ32(locku->lu_type); |
| 739 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) |
| 740 | goto xdr_error; |
| 741 | READ32(locku->lu_seqid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 742 | status = nfsd4_decode_stateid(argp, &locku->lu_stateid); |
| 743 | if (status) |
| 744 | return status; |
| 745 | READ_BUF(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | READ64(locku->lu_offset); |
| 747 | READ64(locku->lu_length); |
| 748 | |
| 749 | DECODE_TAIL; |
| 750 | } |
| 751 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 752 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
| 754 | { |
| 755 | DECODE_HEAD; |
| 756 | |
| 757 | READ_BUF(4); |
| 758 | READ32(lookup->lo_len); |
| 759 | READ_BUF(lookup->lo_len); |
| 760 | SAVEMEM(lookup->lo_name, lookup->lo_len); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 761 | if ((status = check_filename(lookup->lo_name, lookup->lo_len))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | return status; |
| 763 | |
| 764 | DECODE_TAIL; |
| 765 | } |
| 766 | |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 767 | 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] | 768 | { |
| 769 | __be32 *p; |
| 770 | u32 w; |
| 771 | |
| 772 | READ_BUF(4); |
| 773 | READ32(w); |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 774 | *share_access = w & NFS4_SHARE_ACCESS_MASK; |
| 775 | *deleg_want = w & NFS4_SHARE_WANT_MASK; |
| 776 | if (deleg_when) |
| 777 | *deleg_when = w & NFS4_SHARE_WHEN_MASK; |
| 778 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 779 | switch (w & NFS4_SHARE_ACCESS_MASK) { |
| 780 | case NFS4_SHARE_ACCESS_READ: |
| 781 | case NFS4_SHARE_ACCESS_WRITE: |
| 782 | case NFS4_SHARE_ACCESS_BOTH: |
| 783 | break; |
| 784 | default: |
| 785 | return nfserr_bad_xdr; |
| 786 | } |
Benny Halevy | fc0d14f | 2011-10-27 20:43:01 +0200 | [diff] [blame] | 787 | w &= ~NFS4_SHARE_ACCESS_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 788 | if (!w) |
| 789 | return nfs_ok; |
| 790 | if (!argp->minorversion) |
| 791 | return nfserr_bad_xdr; |
| 792 | switch (w & NFS4_SHARE_WANT_MASK) { |
| 793 | case NFS4_SHARE_WANT_NO_PREFERENCE: |
| 794 | case NFS4_SHARE_WANT_READ_DELEG: |
| 795 | case NFS4_SHARE_WANT_WRITE_DELEG: |
| 796 | case NFS4_SHARE_WANT_ANY_DELEG: |
| 797 | case NFS4_SHARE_WANT_NO_DELEG: |
| 798 | case NFS4_SHARE_WANT_CANCEL: |
| 799 | break; |
| 800 | default: |
| 801 | return nfserr_bad_xdr; |
| 802 | } |
Benny Halevy | 92bac8c | 2011-10-19 19:13:29 -0700 | [diff] [blame] | 803 | w &= ~NFS4_SHARE_WANT_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 804 | if (!w) |
| 805 | return nfs_ok; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 806 | |
| 807 | if (!deleg_when) /* open_downgrade */ |
| 808 | return nfserr_inval; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 809 | switch (w) { |
| 810 | case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL: |
| 811 | case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED: |
Benny Halevy | c668fc6 | 2011-10-19 19:13:13 -0700 | [diff] [blame] | 812 | case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL | |
| 813 | NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED): |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 814 | return nfs_ok; |
| 815 | } |
| 816 | xdr_error: |
| 817 | return nfserr_bad_xdr; |
| 818 | } |
| 819 | |
| 820 | static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x) |
| 821 | { |
| 822 | __be32 *p; |
| 823 | |
| 824 | READ_BUF(4); |
| 825 | READ32(*x); |
| 826 | /* Note: unlinke access bits, deny bits may be zero. */ |
Dan Carpenter | 01cd4af | 2011-10-17 10:41:17 +0300 | [diff] [blame] | 827 | if (*x & ~NFS4_SHARE_DENY_BOTH) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 828 | return nfserr_bad_xdr; |
| 829 | return nfs_ok; |
| 830 | xdr_error: |
| 831 | return nfserr_bad_xdr; |
| 832 | } |
| 833 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 834 | static __be32 nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o) |
| 835 | { |
| 836 | __be32 *p; |
| 837 | |
| 838 | READ_BUF(4); |
| 839 | READ32(o->len); |
| 840 | |
| 841 | if (o->len == 0 || o->len > NFS4_OPAQUE_LIMIT) |
| 842 | return nfserr_bad_xdr; |
| 843 | |
| 844 | READ_BUF(o->len); |
| 845 | SAVEMEM(o->data, o->len); |
| 846 | return nfs_ok; |
| 847 | xdr_error: |
| 848 | return nfserr_bad_xdr; |
| 849 | } |
| 850 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 851 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 853 | { |
| 854 | DECODE_HEAD; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 855 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); |
| 858 | open->op_iattr.ia_valid = 0; |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 859 | open->op_openowner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 861 | open->op_xdr_error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | /* seqid, share_access, share_deny, clientid, ownerlen */ |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 863 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | READ32(open->op_seqid); |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 865 | /* decode, yet ignore deleg_when until supported */ |
| 866 | status = nfsd4_decode_share_access(argp, &open->op_share_access, |
| 867 | &open->op_deleg_want, &dummy); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 868 | if (status) |
| 869 | goto xdr_error; |
| 870 | status = nfsd4_decode_share_deny(argp, &open->op_share_deny); |
| 871 | if (status) |
| 872 | goto xdr_error; |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 873 | READ_BUF(sizeof(clientid_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | COPYMEM(&open->op_clientid, sizeof(clientid_t)); |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 875 | status = nfsd4_decode_opaque(argp, &open->op_owner); |
| 876 | if (status) |
| 877 | goto xdr_error; |
| 878 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | READ32(open->op_create); |
| 880 | switch (open->op_create) { |
| 881 | case NFS4_OPEN_NOCREATE: |
| 882 | break; |
| 883 | case NFS4_OPEN_CREATE: |
| 884 | READ_BUF(4); |
| 885 | READ32(open->op_createmode); |
| 886 | switch (open->op_createmode) { |
| 887 | case NFS4_CREATE_UNCHECKED: |
| 888 | case NFS4_CREATE_GUARDED: |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 889 | status = nfsd4_decode_fattr(argp, open->op_bmval, |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 890 | &open->op_iattr, &open->op_acl, &open->op_label); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 891 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | goto out; |
| 893 | break; |
| 894 | case NFS4_CREATE_EXCLUSIVE: |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 895 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 896 | COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | break; |
Benny Halevy | 79fb54a | 2009-04-03 08:29:17 +0300 | [diff] [blame] | 898 | case NFS4_CREATE_EXCLUSIVE4_1: |
| 899 | if (argp->minorversion < 1) |
| 900 | goto xdr_error; |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 901 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 902 | COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE); |
Benny Halevy | 79fb54a | 2009-04-03 08:29:17 +0300 | [diff] [blame] | 903 | status = nfsd4_decode_fattr(argp, open->op_bmval, |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 904 | &open->op_iattr, &open->op_acl, &open->op_label); |
Benny Halevy | 79fb54a | 2009-04-03 08:29:17 +0300 | [diff] [blame] | 905 | if (status) |
| 906 | goto out; |
| 907 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | default: |
| 909 | goto xdr_error; |
| 910 | } |
| 911 | break; |
| 912 | default: |
| 913 | goto xdr_error; |
| 914 | } |
| 915 | |
| 916 | /* open_claim */ |
| 917 | READ_BUF(4); |
| 918 | READ32(open->op_claim_type); |
| 919 | switch (open->op_claim_type) { |
| 920 | case NFS4_OPEN_CLAIM_NULL: |
| 921 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 922 | READ_BUF(4); |
| 923 | READ32(open->op_fname.len); |
| 924 | READ_BUF(open->op_fname.len); |
| 925 | SAVEMEM(open->op_fname.data, open->op_fname.len); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 926 | if ((status = check_filename(open->op_fname.data, open->op_fname.len))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | return status; |
| 928 | break; |
| 929 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 930 | READ_BUF(4); |
| 931 | READ32(open->op_delegate_type); |
| 932 | break; |
| 933 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 934 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); |
| 935 | if (status) |
| 936 | return status; |
| 937 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | READ32(open->op_fname.len); |
| 939 | READ_BUF(open->op_fname.len); |
| 940 | SAVEMEM(open->op_fname.data, open->op_fname.len); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 941 | if ((status = check_filename(open->op_fname.data, open->op_fname.len))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | return status; |
| 943 | break; |
J. Bruce Fields | 8b289b2 | 2011-10-19 11:52:12 -0400 | [diff] [blame] | 944 | case NFS4_OPEN_CLAIM_FH: |
| 945 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 946 | if (argp->minorversion < 1) |
| 947 | goto xdr_error; |
| 948 | /* void */ |
| 949 | break; |
| 950 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 951 | if (argp->minorversion < 1) |
| 952 | goto xdr_error; |
| 953 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); |
| 954 | if (status) |
| 955 | return status; |
| 956 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | default: |
| 958 | goto xdr_error; |
| 959 | } |
| 960 | |
| 961 | DECODE_TAIL; |
| 962 | } |
| 963 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 964 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
| 966 | { |
| 967 | DECODE_HEAD; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 968 | |
| 969 | if (argp->minorversion >= 1) |
| 970 | return nfserr_notsupp; |
| 971 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 972 | status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid); |
| 973 | if (status) |
| 974 | return status; |
| 975 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | READ32(open_conf->oc_seqid); |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | DECODE_TAIL; |
| 979 | } |
| 980 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 981 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
| 983 | { |
| 984 | DECODE_HEAD; |
| 985 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 986 | status = nfsd4_decode_stateid(argp, &open_down->od_stateid); |
| 987 | if (status) |
| 988 | return status; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 989 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | READ32(open_down->od_seqid); |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 991 | status = nfsd4_decode_share_access(argp, &open_down->od_share_access, |
| 992 | &open_down->od_deleg_want, NULL); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 993 | if (status) |
| 994 | return status; |
| 995 | status = nfsd4_decode_share_deny(argp, &open_down->od_share_deny); |
| 996 | if (status) |
| 997 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | DECODE_TAIL; |
| 999 | } |
| 1000 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1001 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
| 1003 | { |
| 1004 | DECODE_HEAD; |
| 1005 | |
| 1006 | READ_BUF(4); |
| 1007 | READ32(putfh->pf_fhlen); |
| 1008 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
| 1009 | goto xdr_error; |
| 1010 | READ_BUF(putfh->pf_fhlen); |
| 1011 | SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen); |
| 1012 | |
| 1013 | DECODE_TAIL; |
| 1014 | } |
| 1015 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1016 | static __be32 |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1017 | nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p) |
| 1018 | { |
| 1019 | if (argp->minorversion == 0) |
| 1020 | return nfs_ok; |
| 1021 | return nfserr_notsupp; |
| 1022 | } |
| 1023 | |
| 1024 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
| 1026 | { |
| 1027 | DECODE_HEAD; |
| 1028 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1029 | status = nfsd4_decode_stateid(argp, &read->rd_stateid); |
| 1030 | if (status) |
| 1031 | return status; |
| 1032 | READ_BUF(12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | READ64(read->rd_offset); |
| 1034 | READ32(read->rd_length); |
| 1035 | |
| 1036 | DECODE_TAIL; |
| 1037 | } |
| 1038 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1039 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
| 1041 | { |
| 1042 | DECODE_HEAD; |
| 1043 | |
| 1044 | READ_BUF(24); |
| 1045 | READ64(readdir->rd_cookie); |
| 1046 | COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data)); |
| 1047 | READ32(readdir->rd_dircount); /* just in case you needed a useless field... */ |
| 1048 | READ32(readdir->rd_maxcount); |
| 1049 | if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval))) |
| 1050 | goto out; |
| 1051 | |
| 1052 | DECODE_TAIL; |
| 1053 | } |
| 1054 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1055 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
| 1057 | { |
| 1058 | DECODE_HEAD; |
| 1059 | |
| 1060 | READ_BUF(4); |
| 1061 | READ32(remove->rm_namelen); |
| 1062 | READ_BUF(remove->rm_namelen); |
| 1063 | SAVEMEM(remove->rm_name, remove->rm_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1064 | if ((status = check_filename(remove->rm_name, remove->rm_namelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | return status; |
| 1066 | |
| 1067 | DECODE_TAIL; |
| 1068 | } |
| 1069 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1070 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
| 1072 | { |
| 1073 | DECODE_HEAD; |
| 1074 | |
| 1075 | READ_BUF(4); |
| 1076 | READ32(rename->rn_snamelen); |
| 1077 | READ_BUF(rename->rn_snamelen + 4); |
| 1078 | SAVEMEM(rename->rn_sname, rename->rn_snamelen); |
| 1079 | READ32(rename->rn_tnamelen); |
| 1080 | READ_BUF(rename->rn_tnamelen); |
| 1081 | SAVEMEM(rename->rn_tname, rename->rn_tnamelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1082 | if ((status = check_filename(rename->rn_sname, rename->rn_snamelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | return status; |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1084 | if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | return status; |
| 1086 | |
| 1087 | DECODE_TAIL; |
| 1088 | } |
| 1089 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1090 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 1092 | { |
| 1093 | DECODE_HEAD; |
| 1094 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1095 | if (argp->minorversion >= 1) |
| 1096 | return nfserr_notsupp; |
| 1097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | READ_BUF(sizeof(clientid_t)); |
| 1099 | COPYMEM(clientid, sizeof(clientid_t)); |
| 1100 | |
| 1101 | DECODE_TAIL; |
| 1102 | } |
| 1103 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1104 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1105 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, |
| 1106 | struct nfsd4_secinfo *secinfo) |
| 1107 | { |
| 1108 | DECODE_HEAD; |
| 1109 | |
| 1110 | READ_BUF(4); |
| 1111 | READ32(secinfo->si_namelen); |
| 1112 | READ_BUF(secinfo->si_namelen); |
| 1113 | SAVEMEM(secinfo->si_name, secinfo->si_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1114 | status = check_filename(secinfo->si_name, secinfo->si_namelen); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1115 | if (status) |
| 1116 | return status; |
| 1117 | DECODE_TAIL; |
| 1118 | } |
| 1119 | |
| 1120 | static __be32 |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1121 | nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp, |
| 1122 | struct nfsd4_secinfo_no_name *sin) |
| 1123 | { |
| 1124 | DECODE_HEAD; |
| 1125 | |
| 1126 | READ_BUF(4); |
| 1127 | READ32(sin->sin_style); |
| 1128 | DECODE_TAIL; |
| 1129 | } |
| 1130 | |
| 1131 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
| 1133 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1134 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1136 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); |
| 1137 | if (status) |
| 1138 | return status; |
Yu Zhiguo | 3c8e031 | 2009-05-16 16:22:31 +0800 | [diff] [blame] | 1139 | return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr, |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 1140 | &setattr->sa_acl, &setattr->sa_label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1143 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
| 1145 | { |
| 1146 | DECODE_HEAD; |
| 1147 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1148 | if (argp->minorversion >= 1) |
| 1149 | return nfserr_notsupp; |
| 1150 | |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1151 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1152 | COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1154 | status = nfsd4_decode_opaque(argp, &setclientid->se_name); |
| 1155 | if (status) |
| 1156 | return nfserr_bad_xdr; |
| 1157 | READ_BUF(8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | READ32(setclientid->se_callback_prog); |
| 1159 | READ32(setclientid->se_callback_netid_len); |
| 1160 | |
| 1161 | READ_BUF(setclientid->se_callback_netid_len + 4); |
| 1162 | SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len); |
| 1163 | READ32(setclientid->se_callback_addr_len); |
| 1164 | |
| 1165 | READ_BUF(setclientid->se_callback_addr_len + 4); |
| 1166 | SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len); |
| 1167 | READ32(setclientid->se_callback_ident); |
| 1168 | |
| 1169 | DECODE_TAIL; |
| 1170 | } |
| 1171 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1172 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
| 1174 | { |
| 1175 | DECODE_HEAD; |
| 1176 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1177 | if (argp->minorversion >= 1) |
| 1178 | return nfserr_notsupp; |
| 1179 | |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1180 | READ_BUF(8 + NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | COPYMEM(&scd_c->sc_clientid, 8); |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1182 | COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
| 1184 | DECODE_TAIL; |
| 1185 | } |
| 1186 | |
| 1187 | /* Also used for NVERIFY */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1188 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
| 1190 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | DECODE_HEAD; |
| 1192 | |
| 1193 | if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval))) |
| 1194 | goto out; |
| 1195 | |
| 1196 | /* For convenience's sake, we compare raw xdr'd attributes in |
J. Bruce Fields | e5f9570 | 2012-11-30 17:24:18 -0500 | [diff] [blame] | 1197 | * nfsd4_proc_verify */ |
| 1198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | READ_BUF(4); |
| 1200 | READ32(verify->ve_attrlen); |
| 1201 | READ_BUF(verify->ve_attrlen); |
| 1202 | SAVEMEM(verify->ve_attrval, verify->ve_attrlen); |
| 1203 | |
| 1204 | DECODE_TAIL; |
| 1205 | } |
| 1206 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1207 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
| 1209 | { |
| 1210 | int avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | int len; |
| 1212 | DECODE_HEAD; |
| 1213 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1214 | status = nfsd4_decode_stateid(argp, &write->wr_stateid); |
| 1215 | if (status) |
| 1216 | return status; |
| 1217 | READ_BUF(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | READ64(write->wr_offset); |
| 1219 | READ32(write->wr_stable_how); |
| 1220 | if (write->wr_stable_how > 2) |
| 1221 | goto xdr_error; |
| 1222 | READ32(write->wr_buflen); |
| 1223 | |
| 1224 | /* Sorry .. no magic macros for this.. * |
| 1225 | * READ_BUF(write->wr_buflen); |
| 1226 | * SAVEMEM(write->wr_buf, write->wr_buflen); |
| 1227 | */ |
| 1228 | avail = (char*)argp->end - (char*)argp->p; |
| 1229 | if (avail + argp->pagelen < write->wr_buflen) { |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 1230 | dprintk("NFSD: xdr error (%s:%d)\n", |
| 1231 | __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | goto xdr_error; |
| 1233 | } |
J. Bruce Fields | 70cc7f7 | 2012-11-16 14:16:46 -0500 | [diff] [blame] | 1234 | write->wr_head.iov_base = p; |
| 1235 | write->wr_head.iov_len = avail; |
J. Bruce Fields | 5a80a54 | 2012-11-16 10:01:30 -0500 | [diff] [blame] | 1236 | WARN_ON(avail != (XDR_QUADLEN(avail) << 2)); |
J. Bruce Fields | 70cc7f7 | 2012-11-16 14:16:46 -0500 | [diff] [blame] | 1237 | write->wr_pagelist = argp->pagelist; |
J. Bruce Fields | 5a80a54 | 2012-11-16 10:01:30 -0500 | [diff] [blame] | 1238 | |
| 1239 | len = XDR_QUADLEN(write->wr_buflen) << 2; |
| 1240 | if (len >= avail) { |
| 1241 | int pages; |
| 1242 | |
| 1243 | len -= avail; |
| 1244 | |
| 1245 | pages = len >> PAGE_SHIFT; |
| 1246 | argp->pagelist += pages; |
| 1247 | argp->pagelen -= pages * PAGE_SIZE; |
| 1248 | len -= pages * PAGE_SIZE; |
| 1249 | |
| 1250 | argp->p = (__be32 *)page_address(argp->pagelist[0]); |
J. Bruce Fields | 365da4a | 2013-11-19 17:32:43 -0500 | [diff] [blame] | 1251 | argp->pagelist++; |
J. Bruce Fields | 5a80a54 | 2012-11-16 10:01:30 -0500 | [diff] [blame] | 1252 | argp->end = argp->p + XDR_QUADLEN(PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | } |
J. Bruce Fields | 5a80a54 | 2012-11-16 10:01:30 -0500 | [diff] [blame] | 1254 | argp->p += XDR_QUADLEN(len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
| 1256 | DECODE_TAIL; |
| 1257 | } |
| 1258 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1259 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
| 1261 | { |
| 1262 | DECODE_HEAD; |
| 1263 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1264 | if (argp->minorversion >= 1) |
| 1265 | return nfserr_notsupp; |
| 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | READ_BUF(12); |
| 1268 | COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t)); |
| 1269 | READ32(rlockowner->rl_owner.len); |
| 1270 | READ_BUF(rlockowner->rl_owner.len); |
| 1271 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); |
| 1272 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 1273 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) |
| 1274 | return nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | DECODE_TAIL; |
| 1276 | } |
| 1277 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1278 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1279 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1280 | struct nfsd4_exchange_id *exid) |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1281 | { |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1282 | int dummy, tmp; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1283 | DECODE_HEAD; |
| 1284 | |
| 1285 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1286 | COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE); |
| 1287 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1288 | status = nfsd4_decode_opaque(argp, &exid->clname); |
| 1289 | if (status) |
| 1290 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1291 | |
| 1292 | READ_BUF(4); |
| 1293 | READ32(exid->flags); |
| 1294 | |
| 1295 | /* Ignore state_protect4_a */ |
| 1296 | READ_BUF(4); |
| 1297 | READ32(exid->spa_how); |
| 1298 | switch (exid->spa_how) { |
| 1299 | case SP4_NONE: |
| 1300 | break; |
| 1301 | case SP4_MACH_CRED: |
| 1302 | /* spo_must_enforce */ |
| 1303 | READ_BUF(4); |
| 1304 | READ32(dummy); |
| 1305 | READ_BUF(dummy * 4); |
| 1306 | p += dummy; |
| 1307 | |
| 1308 | /* spo_must_allow */ |
| 1309 | READ_BUF(4); |
| 1310 | READ32(dummy); |
| 1311 | READ_BUF(dummy * 4); |
| 1312 | p += dummy; |
| 1313 | break; |
| 1314 | case SP4_SSV: |
| 1315 | /* ssp_ops */ |
| 1316 | READ_BUF(4); |
| 1317 | READ32(dummy); |
| 1318 | READ_BUF(dummy * 4); |
| 1319 | p += dummy; |
| 1320 | |
| 1321 | READ_BUF(4); |
| 1322 | READ32(dummy); |
| 1323 | READ_BUF(dummy * 4); |
| 1324 | p += dummy; |
| 1325 | |
| 1326 | /* ssp_hash_algs<> */ |
| 1327 | READ_BUF(4); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1328 | READ32(tmp); |
| 1329 | while (tmp--) { |
| 1330 | READ_BUF(4); |
| 1331 | READ32(dummy); |
| 1332 | READ_BUF(dummy); |
| 1333 | p += XDR_QUADLEN(dummy); |
| 1334 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1335 | |
| 1336 | /* ssp_encr_algs<> */ |
| 1337 | READ_BUF(4); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1338 | READ32(tmp); |
| 1339 | while (tmp--) { |
| 1340 | READ_BUF(4); |
| 1341 | READ32(dummy); |
| 1342 | READ_BUF(dummy); |
| 1343 | p += XDR_QUADLEN(dummy); |
| 1344 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1345 | |
| 1346 | /* ssp_window and ssp_num_gss_handles */ |
| 1347 | READ_BUF(8); |
| 1348 | READ32(dummy); |
| 1349 | READ32(dummy); |
| 1350 | break; |
| 1351 | default: |
| 1352 | goto xdr_error; |
| 1353 | } |
| 1354 | |
| 1355 | /* Ignore Implementation ID */ |
| 1356 | READ_BUF(4); /* nfs_impl_id4 array length */ |
| 1357 | READ32(dummy); |
| 1358 | |
| 1359 | if (dummy > 1) |
| 1360 | goto xdr_error; |
| 1361 | |
| 1362 | if (dummy == 1) { |
| 1363 | /* nii_domain */ |
| 1364 | READ_BUF(4); |
| 1365 | READ32(dummy); |
| 1366 | READ_BUF(dummy); |
| 1367 | p += XDR_QUADLEN(dummy); |
| 1368 | |
| 1369 | /* nii_name */ |
| 1370 | READ_BUF(4); |
| 1371 | READ32(dummy); |
| 1372 | READ_BUF(dummy); |
| 1373 | p += XDR_QUADLEN(dummy); |
| 1374 | |
| 1375 | /* nii_date */ |
| 1376 | READ_BUF(12); |
| 1377 | p += 3; |
| 1378 | } |
| 1379 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | static __be32 |
| 1383 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, |
| 1384 | struct nfsd4_create_session *sess) |
| 1385 | { |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1386 | DECODE_HEAD; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1387 | u32 dummy; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1388 | |
| 1389 | READ_BUF(16); |
| 1390 | COPYMEM(&sess->clientid, 8); |
| 1391 | READ32(sess->seqid); |
| 1392 | READ32(sess->flags); |
| 1393 | |
| 1394 | /* Fore channel attrs */ |
| 1395 | READ_BUF(28); |
| 1396 | READ32(dummy); /* headerpadsz is always 0 */ |
| 1397 | READ32(sess->fore_channel.maxreq_sz); |
| 1398 | READ32(sess->fore_channel.maxresp_sz); |
| 1399 | READ32(sess->fore_channel.maxresp_cached); |
| 1400 | READ32(sess->fore_channel.maxops); |
| 1401 | READ32(sess->fore_channel.maxreqs); |
| 1402 | READ32(sess->fore_channel.nr_rdma_attrs); |
| 1403 | if (sess->fore_channel.nr_rdma_attrs == 1) { |
| 1404 | READ_BUF(4); |
| 1405 | READ32(sess->fore_channel.rdma_attrs); |
| 1406 | } else if (sess->fore_channel.nr_rdma_attrs > 1) { |
| 1407 | dprintk("Too many fore channel attr bitmaps!\n"); |
| 1408 | goto xdr_error; |
| 1409 | } |
| 1410 | |
| 1411 | /* Back channel attrs */ |
| 1412 | READ_BUF(28); |
| 1413 | READ32(dummy); /* headerpadsz is always 0 */ |
| 1414 | READ32(sess->back_channel.maxreq_sz); |
| 1415 | READ32(sess->back_channel.maxresp_sz); |
| 1416 | READ32(sess->back_channel.maxresp_cached); |
| 1417 | READ32(sess->back_channel.maxops); |
| 1418 | READ32(sess->back_channel.maxreqs); |
| 1419 | READ32(sess->back_channel.nr_rdma_attrs); |
| 1420 | if (sess->back_channel.nr_rdma_attrs == 1) { |
| 1421 | READ_BUF(4); |
| 1422 | READ32(sess->back_channel.rdma_attrs); |
| 1423 | } else if (sess->back_channel.nr_rdma_attrs > 1) { |
| 1424 | dprintk("Too many back channel attr bitmaps!\n"); |
| 1425 | goto xdr_error; |
| 1426 | } |
| 1427 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1428 | READ_BUF(4); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1429 | READ32(sess->callback_prog); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1430 | nfsd4_decode_cb_sec(argp, &sess->cb_sec); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1431 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | static __be32 |
| 1435 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, |
| 1436 | struct nfsd4_destroy_session *destroy_session) |
| 1437 | { |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1438 | DECODE_HEAD; |
| 1439 | READ_BUF(NFS4_MAX_SESSIONID_LEN); |
| 1440 | COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 1441 | |
| 1442 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | static __be32 |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1446 | nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, |
| 1447 | struct nfsd4_free_stateid *free_stateid) |
| 1448 | { |
| 1449 | DECODE_HEAD; |
| 1450 | |
| 1451 | READ_BUF(sizeof(stateid_t)); |
| 1452 | READ32(free_stateid->fr_stateid.si_generation); |
| 1453 | COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t)); |
| 1454 | |
| 1455 | DECODE_TAIL; |
| 1456 | } |
| 1457 | |
| 1458 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1459 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, |
| 1460 | struct nfsd4_sequence *seq) |
| 1461 | { |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1462 | DECODE_HEAD; |
| 1463 | |
| 1464 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); |
| 1465 | COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 1466 | READ32(seq->seqid); |
| 1467 | READ32(seq->slotid); |
| 1468 | READ32(seq->maxslots); |
| 1469 | READ32(seq->cachethis); |
| 1470 | |
| 1471 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1472 | } |
| 1473 | |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1474 | static __be32 |
| 1475 | nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid) |
| 1476 | { |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1477 | int i; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1478 | __be32 *p, status; |
| 1479 | struct nfsd4_test_stateid_id *stateid; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1480 | |
| 1481 | READ_BUF(4); |
| 1482 | test_stateid->ts_num_ids = ntohl(*p++); |
| 1483 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1484 | INIT_LIST_HEAD(&test_stateid->ts_stateid_list); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1485 | |
| 1486 | for (i = 0; i < test_stateid->ts_num_ids; i++) { |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1487 | stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL); |
| 1488 | if (!stateid) { |
Al Viro | afcf679 | 2012-04-13 00:15:37 -0400 | [diff] [blame] | 1489 | status = nfserrno(-ENOMEM); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1490 | goto out; |
| 1491 | } |
| 1492 | |
| 1493 | defer_free(argp, kfree, stateid); |
| 1494 | INIT_LIST_HEAD(&stateid->ts_id_list); |
| 1495 | list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list); |
| 1496 | |
| 1497 | status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1498 | if (status) |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1499 | goto out; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | status = 0; |
| 1503 | out: |
| 1504 | return status; |
| 1505 | xdr_error: |
| 1506 | dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__); |
| 1507 | status = nfserr_bad_xdr; |
| 1508 | goto out; |
| 1509 | } |
| 1510 | |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 1511 | static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc) |
| 1512 | { |
| 1513 | DECODE_HEAD; |
| 1514 | |
| 1515 | READ_BUF(8); |
| 1516 | COPYMEM(&dc->clientid, 8); |
| 1517 | |
| 1518 | DECODE_TAIL; |
| 1519 | } |
| 1520 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1521 | static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc) |
| 1522 | { |
| 1523 | DECODE_HEAD; |
| 1524 | |
| 1525 | READ_BUF(4); |
| 1526 | READ32(rc->rca_one_fs); |
| 1527 | |
| 1528 | DECODE_TAIL; |
| 1529 | } |
| 1530 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1531 | static __be32 |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1532 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) |
| 1533 | { |
| 1534 | return nfs_ok; |
| 1535 | } |
| 1536 | |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 1537 | static __be32 |
| 1538 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
| 1539 | { |
Benny Halevy | 1e685ec | 2009-03-04 23:06:06 +0200 | [diff] [blame] | 1540 | return nfserr_notsupp; |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 1541 | } |
| 1542 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1543 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
| 1544 | |
| 1545 | static nfsd4_dec nfsd4_dec_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 1546 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
| 1547 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, |
| 1548 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, |
| 1549 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, |
| 1550 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1551 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, |
| 1552 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, |
| 1553 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1554 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, |
| 1555 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, |
| 1556 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, |
| 1557 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, |
| 1558 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, |
| 1559 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, |
| 1560 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 1561 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, |
| 1562 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1563 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
| 1564 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
| 1565 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1566 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 1567 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1568 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
| 1569 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
| 1570 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, |
| 1571 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, |
| 1572 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, |
| 1573 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, |
| 1574 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1575 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1576 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, |
| 1577 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, |
| 1578 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, |
| 1579 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, |
| 1580 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 1581 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, |
| 1582 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1583 | |
| 1584 | /* new operations for NFSv4.1 */ |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 1585 | [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 1586 | [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] | 1587 | [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, |
| 1588 | [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, |
| 1589 | [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1590 | [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 1591 | [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1592 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1593 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1594 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1595 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1596 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp, |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1597 | [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 1598 | [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence, |
| 1599 | [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1600 | [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 1601 | [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 1602 | [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1603 | [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1604 | }; |
| 1605 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1606 | static inline bool |
| 1607 | nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op) |
| 1608 | { |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 1609 | if (op->opnum < FIRST_NFS4_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1610 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 1611 | else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1612 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 1613 | else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP) |
| 1614 | return false; |
| 1615 | else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1616 | return false; |
| 1617 | return true; |
| 1618 | } |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 1619 | |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 1620 | /* |
| 1621 | * Return a rough estimate of the maximum possible reply size. Note the |
| 1622 | * estimate includes rpc headers so is meant to be passed to |
| 1623 | * svc_reserve, not svc_reserve_auth. |
| 1624 | * |
| 1625 | * Also note the current compound encoding permits only one operation to |
| 1626 | * use pages beyond the first one, so the maximum possible length is the |
| 1627 | * maximum over these values, not the sum. |
| 1628 | */ |
| 1629 | static int nfsd4_max_reply(u32 opnum) |
| 1630 | { |
| 1631 | switch (opnum) { |
| 1632 | case OP_READLINK: |
| 1633 | case OP_READDIR: |
| 1634 | /* |
| 1635 | * Both of these ops take a single page for data and put |
| 1636 | * the head and tail in another page: |
| 1637 | */ |
| 1638 | return 2 * PAGE_SIZE; |
| 1639 | case OP_READ: |
| 1640 | return INT_MAX; |
| 1641 | default: |
| 1642 | return PAGE_SIZE; |
| 1643 | } |
| 1644 | } |
| 1645 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1646 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
| 1648 | { |
| 1649 | DECODE_HEAD; |
| 1650 | struct nfsd4_op *op; |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 1651 | bool cachethis = false; |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 1652 | int max_reply = PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | int i; |
| 1654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | READ_BUF(4); |
| 1656 | READ32(argp->taglen); |
| 1657 | READ_BUF(argp->taglen + 8); |
| 1658 | SAVEMEM(argp->tag, argp->taglen); |
| 1659 | READ32(argp->minorversion); |
| 1660 | READ32(argp->opcnt); |
| 1661 | |
| 1662 | if (argp->taglen > NFSD4_MAX_TAGLEN) |
| 1663 | goto xdr_error; |
| 1664 | if (argp->opcnt > 100) |
| 1665 | goto xdr_error; |
| 1666 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 1667 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
| 1669 | if (!argp->ops) { |
| 1670 | argp->ops = argp->iops; |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 1671 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | goto xdr_error; |
| 1673 | } |
| 1674 | } |
| 1675 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1676 | if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION) |
Benny Halevy | 30cff1f | 2008-07-02 11:13:18 +0300 | [diff] [blame] | 1677 | argp->opcnt = 0; |
| 1678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | for (i = 0; i < argp->opcnt; i++) { |
| 1680 | op = &argp->ops[i]; |
| 1681 | op->replay = NULL; |
| 1682 | |
J. Bruce Fields | 8a61b18 | 2012-11-16 22:28:38 -0500 | [diff] [blame] | 1683 | READ_BUF(4); |
| 1684 | READ32(op->opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1686 | if (nfsd4_opnum_in_range(argp, op)) |
| 1687 | op->status = nfsd4_dec_ops[op->opnum](argp, &op->u); |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1688 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | op->opnum = OP_ILLEGAL; |
| 1690 | op->status = nfserr_op_illegal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | if (op->status) { |
| 1694 | argp->opcnt = i+1; |
| 1695 | break; |
| 1696 | } |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 1697 | /* |
| 1698 | * We'll try to cache the result in the DRC if any one |
| 1699 | * op in the compound wants to be cached: |
| 1700 | */ |
| 1701 | cachethis |= nfsd4_cache_this_op(op); |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 1702 | |
| 1703 | max_reply = max(max_reply, nfsd4_max_reply(op->opnum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | } |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 1705 | /* Sessions make the DRC unnecessary: */ |
| 1706 | if (argp->minorversion) |
| 1707 | cachethis = false; |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 1708 | if (max_reply != INT_MAX) |
| 1709 | svc_reserve(argp->rqstp, max_reply); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 1710 | argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | |
| 1712 | DECODE_TAIL; |
| 1713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | #define WRITE32(n) *p++ = htonl(n) |
| 1716 | #define WRITE64(n) do { \ |
| 1717 | *p++ = htonl((u32)((n) >> 32)); \ |
| 1718 | *p++ = htonl((u32)(n)); \ |
| 1719 | } while (0) |
Harvey Harrison | 5108b27 | 2008-07-17 21:33:04 -0700 | [diff] [blame] | 1720 | #define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | *(p + XDR_QUADLEN(nbytes) -1) = 0; \ |
| 1722 | memcpy(p, ptr, nbytes); \ |
| 1723 | p += XDR_QUADLEN(nbytes); \ |
Harvey Harrison | 5108b27 | 2008-07-17 21:33:04 -0700 | [diff] [blame] | 1724 | }} while (0) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 1725 | |
| 1726 | static void write32(__be32 **p, u32 n) |
| 1727 | { |
J. Bruce Fields | 45eaa1c | 2012-04-25 18:11:04 -0400 | [diff] [blame] | 1728 | *(*p)++ = htonl(n); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | static void write64(__be32 **p, u64 n) |
| 1732 | { |
J. Bruce Fields | 45eaa1c | 2012-04-25 18:11:04 -0400 | [diff] [blame] | 1733 | write32(p, (n >> 32)); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 1734 | write32(p, (u32)n); |
| 1735 | } |
| 1736 | |
| 1737 | static void write_change(__be32 **p, struct kstat *stat, struct inode *inode) |
| 1738 | { |
| 1739 | if (IS_I_VERSION(inode)) { |
| 1740 | write64(p, inode->i_version); |
| 1741 | } else { |
| 1742 | write32(p, stat->ctime.tv_sec); |
| 1743 | write32(p, stat->ctime.tv_nsec); |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | static void write_cinfo(__be32 **p, struct nfsd4_change_info *c) |
| 1748 | { |
| 1749 | write32(p, c->atomic); |
| 1750 | if (c->change_supported) { |
| 1751 | write64(p, c->before_change); |
| 1752 | write64(p, c->after_change); |
| 1753 | } else { |
| 1754 | write32(p, c->before_ctime_sec); |
| 1755 | write32(p, c->before_ctime_nsec); |
| 1756 | write32(p, c->after_ctime_sec); |
| 1757 | write32(p, c->after_ctime_nsec); |
| 1758 | } |
| 1759 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
| 1761 | #define RESERVE_SPACE(nbytes) do { \ |
| 1762 | p = resp->p; \ |
| 1763 | BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \ |
| 1764 | } while (0) |
| 1765 | #define ADJUST_ARGS() resp->p = p |
| 1766 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1767 | /* Encode as an array of strings the string given with components |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 1768 | * separated @sep, escaped with esc_enter and esc_exit. |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1769 | */ |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 1770 | static __be32 nfsd4_encode_components_esc(char sep, char *components, |
| 1771 | __be32 **pp, int *buflen, |
| 1772 | char esc_enter, char esc_exit) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1773 | { |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1774 | __be32 *p = *pp; |
| 1775 | __be32 *countp = p; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1776 | int strlen, count=0; |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 1777 | char *str, *end, *next; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1778 | |
| 1779 | dprintk("nfsd4_encode_components(%s)\n", components); |
| 1780 | if ((*buflen -= 4) < 0) |
| 1781 | return nfserr_resource; |
| 1782 | WRITE32(0); /* We will fill this in with @count later */ |
| 1783 | end = str = components; |
| 1784 | while (*end) { |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 1785 | bool found_esc = false; |
| 1786 | |
| 1787 | /* try to parse as esc_start, ..., esc_end, sep */ |
| 1788 | if (*str == esc_enter) { |
| 1789 | for (; *end && (*end != esc_exit); end++) |
| 1790 | /* find esc_exit or end of string */; |
| 1791 | next = end + 1; |
| 1792 | if (*end && (!*next || *next == sep)) { |
| 1793 | str++; |
| 1794 | found_esc = true; |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | if (!found_esc) |
| 1799 | for (; *end && (*end != sep); end++) |
| 1800 | /* find sep or end of string */; |
| 1801 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1802 | strlen = end - str; |
| 1803 | if (strlen) { |
| 1804 | if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0) |
| 1805 | return nfserr_resource; |
| 1806 | WRITE32(strlen); |
| 1807 | WRITEMEM(str, strlen); |
| 1808 | count++; |
| 1809 | } |
| 1810 | else |
| 1811 | end++; |
| 1812 | str = end; |
| 1813 | } |
| 1814 | *pp = p; |
| 1815 | p = countp; |
| 1816 | WRITE32(count); |
| 1817 | return 0; |
| 1818 | } |
| 1819 | |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 1820 | /* Encode as an array of strings the string given with components |
| 1821 | * separated @sep. |
| 1822 | */ |
| 1823 | static __be32 nfsd4_encode_components(char sep, char *components, |
| 1824 | __be32 **pp, int *buflen) |
| 1825 | { |
| 1826 | return nfsd4_encode_components_esc(sep, components, pp, buflen, 0, 0); |
| 1827 | } |
| 1828 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1829 | /* |
| 1830 | * encode a location element of a fs_locations structure |
| 1831 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1832 | static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1833 | __be32 **pp, int *buflen) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1834 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1835 | __be32 status; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1836 | __be32 *p = *pp; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1837 | |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 1838 | status = nfsd4_encode_components_esc(':', location->hosts, &p, buflen, |
| 1839 | '[', ']'); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1840 | if (status) |
| 1841 | return status; |
| 1842 | status = nfsd4_encode_components('/', location->path, &p, buflen); |
| 1843 | if (status) |
| 1844 | return status; |
| 1845 | *pp = p; |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
| 1849 | /* |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1850 | * Encode a path in RFC3530 'pathname4' format |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1851 | */ |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1852 | static __be32 nfsd4_encode_path(const struct path *root, |
| 1853 | const struct path *path, __be32 **pp, int *buflen) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1854 | { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 1855 | struct path cur = *path; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1856 | __be32 *p = *pp; |
| 1857 | struct dentry **components = NULL; |
| 1858 | unsigned int ncomponents = 0; |
| 1859 | __be32 err = nfserr_jukebox; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1860 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1861 | dprintk("nfsd4_encode_components("); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1862 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1863 | path_get(&cur); |
| 1864 | /* First walk the path up to the nfsd root, and store the |
| 1865 | * dentries/path components in an array. |
| 1866 | */ |
| 1867 | for (;;) { |
| 1868 | if (cur.dentry == root->dentry && cur.mnt == root->mnt) |
| 1869 | break; |
| 1870 | if (cur.dentry == cur.mnt->mnt_root) { |
| 1871 | if (follow_up(&cur)) |
| 1872 | continue; |
| 1873 | goto out_free; |
| 1874 | } |
| 1875 | if ((ncomponents & 15) == 0) { |
| 1876 | struct dentry **new; |
| 1877 | new = krealloc(components, |
| 1878 | sizeof(*new) * (ncomponents + 16), |
| 1879 | GFP_KERNEL); |
| 1880 | if (!new) |
| 1881 | goto out_free; |
| 1882 | components = new; |
| 1883 | } |
| 1884 | components[ncomponents++] = cur.dentry; |
| 1885 | cur.dentry = dget_parent(cur.dentry); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1886 | } |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1887 | |
| 1888 | *buflen -= 4; |
| 1889 | if (*buflen < 0) |
| 1890 | goto out_free; |
| 1891 | WRITE32(ncomponents); |
| 1892 | |
| 1893 | while (ncomponents) { |
| 1894 | struct dentry *dentry = components[ncomponents - 1]; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 1895 | unsigned int len; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1896 | |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 1897 | spin_lock(&dentry->d_lock); |
| 1898 | len = dentry->d_name.len; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1899 | *buflen -= 4 + (XDR_QUADLEN(len) << 2); |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 1900 | if (*buflen < 0) { |
| 1901 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1902 | goto out_free; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 1903 | } |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1904 | WRITE32(len); |
| 1905 | WRITEMEM(dentry->d_name.name, len); |
| 1906 | dprintk("/%s", dentry->d_name.name); |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 1907 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1908 | dput(dentry); |
| 1909 | ncomponents--; |
| 1910 | } |
| 1911 | |
| 1912 | *pp = p; |
| 1913 | err = 0; |
| 1914 | out_free: |
| 1915 | dprintk(")\n"); |
| 1916 | while (ncomponents) |
| 1917 | dput(components[--ncomponents]); |
| 1918 | kfree(components); |
| 1919 | path_put(&cur); |
| 1920 | return err; |
| 1921 | } |
| 1922 | |
| 1923 | static __be32 nfsd4_encode_fsloc_fsroot(struct svc_rqst *rqstp, |
| 1924 | const struct path *path, __be32 **pp, int *buflen) |
| 1925 | { |
| 1926 | struct svc_export *exp_ps; |
| 1927 | __be32 res; |
| 1928 | |
| 1929 | exp_ps = rqst_find_fsidzero_export(rqstp); |
| 1930 | if (IS_ERR(exp_ps)) |
| 1931 | return nfserrno(PTR_ERR(exp_ps)); |
| 1932 | res = nfsd4_encode_path(&exp_ps->ex_path, path, pp, buflen); |
| 1933 | exp_put(exp_ps); |
| 1934 | return res; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | /* |
| 1938 | * encode a fs_locations structure |
| 1939 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1940 | static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp, |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1941 | struct svc_export *exp, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1942 | __be32 **pp, int *buflen) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1943 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1944 | __be32 status; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 1945 | int i; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1946 | __be32 *p = *pp; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1947 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1948 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 1949 | status = nfsd4_encode_fsloc_fsroot(rqstp, &exp->ex_path, &p, buflen); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1950 | if (status) |
| 1951 | return status; |
| 1952 | if ((*buflen -= 4) < 0) |
| 1953 | return nfserr_resource; |
| 1954 | WRITE32(fslocs->locations_count); |
| 1955 | for (i=0; i<fslocs->locations_count; i++) { |
| 1956 | status = nfsd4_encode_fs_location4(&fslocs->locations[i], |
| 1957 | &p, buflen); |
| 1958 | if (status) |
| 1959 | return status; |
| 1960 | } |
| 1961 | *pp = p; |
| 1962 | return 0; |
| 1963 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 1965 | static u32 nfs4_file_type(umode_t mode) |
| 1966 | { |
| 1967 | switch (mode & S_IFMT) { |
| 1968 | case S_IFIFO: return NF4FIFO; |
| 1969 | case S_IFCHR: return NF4CHR; |
| 1970 | case S_IFDIR: return NF4DIR; |
| 1971 | case S_IFBLK: return NF4BLK; |
| 1972 | case S_IFLNK: return NF4LNK; |
| 1973 | case S_IFREG: return NF4REG; |
| 1974 | case S_IFSOCK: return NF4SOCK; |
| 1975 | default: return NF4BAD; |
| 1976 | }; |
| 1977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1979 | static __be32 |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 1980 | nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, kuid_t uid, kgid_t gid, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1981 | __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | { |
| 1983 | int status; |
| 1984 | |
| 1985 | if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4) |
| 1986 | return nfserr_resource; |
| 1987 | if (whotype != NFS4_ACL_WHO_NAMED) |
| 1988 | status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1)); |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 1989 | else if (gid_valid(gid)) |
| 1990 | status = nfsd_map_gid_to_name(rqstp, gid, (u8 *)(*p + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | else |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 1992 | status = nfsd_map_uid_to_name(rqstp, uid, (u8 *)(*p + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | if (status < 0) |
| 1994 | return nfserrno(status); |
| 1995 | *p = xdr_encode_opaque(*p, NULL, status); |
| 1996 | *buflen -= (XDR_QUADLEN(status) << 2) + 4; |
| 1997 | BUG_ON(*buflen < 0); |
| 1998 | return 0; |
| 1999 | } |
| 2000 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2001 | static inline __be32 |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 2002 | nfsd4_encode_user(struct svc_rqst *rqstp, kuid_t user, __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | { |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 2004 | return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, user, INVALID_GID, |
| 2005 | p, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2008 | static inline __be32 |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 2009 | nfsd4_encode_group(struct svc_rqst *rqstp, kgid_t group, __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | { |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 2011 | return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, INVALID_UID, group, |
| 2012 | p, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2015 | static inline __be32 |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 2016 | nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2017 | __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | { |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 2019 | kuid_t uid = INVALID_UID; |
| 2020 | kgid_t gid = INVALID_GID; |
| 2021 | |
| 2022 | if (ace->whotype == NFS4_ACL_WHO_NAMED) { |
| 2023 | if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
| 2024 | gid = ace->who_gid; |
| 2025 | else |
| 2026 | uid = ace->who_uid; |
| 2027 | } |
| 2028 | return nfsd4_encode_name(rqstp, ace->whotype, uid, gid, p, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2031 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
| 2032 | FATTR4_WORD0_RDATTR_ERROR) |
| 2033 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID |
| 2034 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2035 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 2036 | static inline __be32 |
| 2037 | nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen) |
| 2038 | { |
| 2039 | __be32 *p = *pp; |
| 2040 | |
| 2041 | if (*buflen < ((XDR_QUADLEN(len) << 2) + 4 + 4 + 4)) |
| 2042 | return nfserr_resource; |
| 2043 | |
| 2044 | /* |
| 2045 | * For now we use a 0 here to indicate the null translation; in |
| 2046 | * the future we may place a call to translation code here. |
| 2047 | */ |
| 2048 | if ((*buflen -= 8) < 0) |
| 2049 | return nfserr_resource; |
| 2050 | |
| 2051 | WRITE32(0); /* lfs */ |
| 2052 | WRITE32(0); /* pi */ |
| 2053 | p = xdr_encode_opaque(p, context, len); |
| 2054 | *buflen -= (XDR_QUADLEN(len) << 2) + 4; |
| 2055 | |
| 2056 | *pp = p; |
| 2057 | return 0; |
| 2058 | } |
| 2059 | #else |
| 2060 | static inline __be32 |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 2061 | nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2062 | { return 0; } |
| 2063 | #endif |
| 2064 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2065 | static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err) |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2066 | { |
| 2067 | /* As per referral draft: */ |
| 2068 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || |
| 2069 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { |
| 2070 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || |
| 2071 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) |
| 2072 | *rdattr_err = NFSERR_MOVED; |
| 2073 | else |
| 2074 | return nfserr_moved; |
| 2075 | } |
| 2076 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; |
| 2077 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; |
| 2078 | return 0; |
| 2079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2081 | |
| 2082 | static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) |
| 2083 | { |
| 2084 | struct path path = exp->ex_path; |
| 2085 | int err; |
| 2086 | |
| 2087 | path_get(&path); |
| 2088 | while (follow_up(&path)) { |
| 2089 | if (path.dentry != path.mnt->mnt_root) |
| 2090 | break; |
| 2091 | } |
Al Viro | 3dadecc | 2013-01-24 02:18:08 -0500 | [diff] [blame] | 2092 | err = vfs_getattr(&path, stat); |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2093 | path_put(&path); |
| 2094 | return err; |
| 2095 | } |
| 2096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | /* |
| 2098 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle |
| 2099 | * ourselves. |
| 2100 | * |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2101 | * countp is the buffer size in _words_ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2103 | __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2105 | struct dentry *dentry, __be32 **buffer, int count, u32 *bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2106 | struct svc_rqst *rqstp, int ignore_crossmnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | { |
| 2108 | u32 bmval0 = bmval[0]; |
| 2109 | u32 bmval1 = bmval[1]; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2110 | u32 bmval2 = bmval[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | struct kstat stat; |
| 2112 | struct svc_fh tempfh; |
| 2113 | struct kstatfs statfs; |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2114 | int buflen = count << 2; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2115 | __be32 *attrlenp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | u32 dummy; |
| 2117 | u64 dummy64; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2118 | u32 rdattr_err = 0; |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2119 | __be32 *p = *buffer; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2120 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2121 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | int aclsupport = 0; |
| 2123 | struct nfs4_acl *acl = NULL; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2124 | void *context = NULL; |
| 2125 | int contextlen; |
| 2126 | bool contextsupport = false; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2127 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 2128 | u32 minorversion = resp->cstate.minorversion; |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2129 | struct path path = { |
| 2130 | .mnt = exp->ex_path.mnt, |
| 2131 | .dentry = dentry, |
| 2132 | }; |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 2133 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | |
| 2135 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2136 | BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion)); |
| 2137 | BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion)); |
| 2138 | BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2140 | if (exp->ex_fslocs.migrated) { |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2141 | BUG_ON(bmval[2]); |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2142 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err); |
| 2143 | if (status) |
| 2144 | goto out; |
| 2145 | } |
| 2146 | |
Al Viro | 3dadecc | 2013-01-24 02:18:08 -0500 | [diff] [blame] | 2147 | err = vfs_getattr(&path, &stat); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2148 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | goto out_nfserr; |
J. Bruce Fields | a16e92e | 2007-09-28 16:45:51 -0400 | [diff] [blame] | 2150 | if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | |
| 2151 | FATTR4_WORD0_MAXNAME)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
| 2153 | FATTR4_WORD1_SPACE_TOTAL))) { |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2154 | err = vfs_statfs(&path, &statfs); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2155 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | goto out_nfserr; |
| 2157 | } |
| 2158 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { |
| 2159 | fh_init(&tempfh, NFS4_FHSIZE); |
| 2160 | status = fh_compose(&tempfh, exp, dentry, NULL); |
| 2161 | if (status) |
| 2162 | goto out; |
| 2163 | fhp = &tempfh; |
| 2164 | } |
| 2165 | if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT |
| 2166 | | FATTR4_WORD0_SUPPORTED_ATTRS)) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2167 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
| 2168 | aclsupport = (err == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | if (bmval0 & FATTR4_WORD0_ACL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2170 | if (err == -EOPNOTSUPP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | bmval0 &= ~FATTR4_WORD0_ACL; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2172 | else if (err == -EINVAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | status = nfserr_attrnotsupp; |
| 2174 | goto out; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2175 | } else if (err != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | goto out_nfserr; |
| 2177 | } |
| 2178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2180 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 2181 | if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) || |
| 2182 | bmval[0] & FATTR4_WORD0_SUPPORTED_ATTRS) { |
| 2183 | err = security_inode_getsecctx(dentry->d_inode, |
| 2184 | &context, &contextlen); |
| 2185 | contextsupport = (err == 0); |
| 2186 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 2187 | if (err == -EOPNOTSUPP) |
| 2188 | bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2189 | else if (err) |
| 2190 | goto out_nfserr; |
| 2191 | } |
| 2192 | } |
| 2193 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
| 2194 | |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2195 | if (bmval2) { |
| 2196 | if ((buflen -= 16) < 0) |
| 2197 | goto out_resource; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2198 | WRITE32(3); |
| 2199 | WRITE32(bmval0); |
| 2200 | WRITE32(bmval1); |
| 2201 | WRITE32(bmval2); |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2202 | } else if (bmval1) { |
| 2203 | if ((buflen -= 12) < 0) |
| 2204 | goto out_resource; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2205 | WRITE32(2); |
| 2206 | WRITE32(bmval0); |
| 2207 | WRITE32(bmval1); |
| 2208 | } else { |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2209 | if ((buflen -= 8) < 0) |
| 2210 | goto out_resource; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2211 | WRITE32(1); |
| 2212 | WRITE32(bmval0); |
| 2213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | attrlenp = p++; /* to be backfilled later */ |
| 2215 | |
| 2216 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2217 | u32 word0 = nfsd_suppattrs0(minorversion); |
| 2218 | u32 word1 = nfsd_suppattrs1(minorversion); |
| 2219 | u32 word2 = nfsd_suppattrs2(minorversion); |
| 2220 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2221 | if (!aclsupport) |
| 2222 | word0 &= ~FATTR4_WORD0_ACL; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2223 | if (!contextsupport) |
| 2224 | word2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2225 | if (!word2) { |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2226 | if ((buflen -= 12) < 0) |
| 2227 | goto out_resource; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2228 | WRITE32(2); |
| 2229 | WRITE32(word0); |
| 2230 | WRITE32(word1); |
| 2231 | } else { |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2232 | if ((buflen -= 16) < 0) |
| 2233 | goto out_resource; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2234 | WRITE32(3); |
| 2235 | WRITE32(word0); |
| 2236 | WRITE32(word1); |
| 2237 | WRITE32(word2); |
| 2238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | } |
| 2240 | if (bmval0 & FATTR4_WORD0_TYPE) { |
| 2241 | if ((buflen -= 4) < 0) |
| 2242 | goto out_resource; |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2243 | dummy = nfs4_file_type(stat.mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | if (dummy == NF4BAD) |
| 2245 | goto out_serverfault; |
| 2246 | WRITE32(dummy); |
| 2247 | } |
| 2248 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { |
| 2249 | if ((buflen -= 4) < 0) |
| 2250 | goto out_resource; |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2251 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
NeilBrown | e34ac86 | 2005-07-07 17:59:30 -0700 | [diff] [blame] | 2252 | WRITE32(NFS4_FH_PERSISTENT); |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2253 | else |
NeilBrown | e34ac86 | 2005-07-07 17:59:30 -0700 | [diff] [blame] | 2254 | WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | } |
| 2256 | if (bmval0 & FATTR4_WORD0_CHANGE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | if ((buflen -= 8) < 0) |
| 2258 | goto out_resource; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2259 | write_change(&p, &stat, dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | } |
| 2261 | if (bmval0 & FATTR4_WORD0_SIZE) { |
| 2262 | if ((buflen -= 8) < 0) |
| 2263 | goto out_resource; |
| 2264 | WRITE64(stat.size); |
| 2265 | } |
| 2266 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { |
| 2267 | if ((buflen -= 4) < 0) |
| 2268 | goto out_resource; |
| 2269 | WRITE32(1); |
| 2270 | } |
| 2271 | if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) { |
| 2272 | if ((buflen -= 4) < 0) |
| 2273 | goto out_resource; |
| 2274 | WRITE32(1); |
| 2275 | } |
| 2276 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { |
| 2277 | if ((buflen -= 4) < 0) |
| 2278 | goto out_resource; |
| 2279 | WRITE32(0); |
| 2280 | } |
| 2281 | if (bmval0 & FATTR4_WORD0_FSID) { |
| 2282 | if ((buflen -= 16) < 0) |
| 2283 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2284 | if (exp->ex_fslocs.migrated) { |
| 2285 | WRITE64(NFS4_REFERRAL_FSID_MAJOR); |
| 2286 | WRITE64(NFS4_REFERRAL_FSID_MINOR); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2287 | } else switch(fsid_source(fhp)) { |
| 2288 | case FSIDSOURCE_FSID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | WRITE64((u64)exp->ex_fsid); |
| 2290 | WRITE64((u64)0); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2291 | break; |
| 2292 | case FSIDSOURCE_DEV: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | WRITE32(0); |
| 2294 | WRITE32(MAJOR(stat.dev)); |
| 2295 | WRITE32(0); |
| 2296 | WRITE32(MINOR(stat.dev)); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2297 | break; |
| 2298 | case FSIDSOURCE_UUID: |
| 2299 | WRITEMEM(exp->ex_uuid, 16); |
| 2300 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | } |
| 2302 | } |
| 2303 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { |
| 2304 | if ((buflen -= 4) < 0) |
| 2305 | goto out_resource; |
| 2306 | WRITE32(0); |
| 2307 | } |
| 2308 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { |
| 2309 | if ((buflen -= 4) < 0) |
| 2310 | goto out_resource; |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 2311 | WRITE32(nn->nfsd4_lease); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | } |
| 2313 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { |
| 2314 | if ((buflen -= 4) < 0) |
| 2315 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2316 | WRITE32(rdattr_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | } |
| 2318 | if (bmval0 & FATTR4_WORD0_ACL) { |
| 2319 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
| 2321 | if (acl == NULL) { |
| 2322 | if ((buflen -= 4) < 0) |
| 2323 | goto out_resource; |
| 2324 | |
| 2325 | WRITE32(0); |
| 2326 | goto out_acl; |
| 2327 | } |
| 2328 | if ((buflen -= 4) < 0) |
| 2329 | goto out_resource; |
| 2330 | WRITE32(acl->naces); |
| 2331 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 2332 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | if ((buflen -= 4*3) < 0) |
| 2334 | goto out_resource; |
| 2335 | WRITE32(ace->type); |
| 2336 | WRITE32(ace->flag); |
| 2337 | WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL); |
Eric W. Biederman | ab8e4ae | 2013-02-02 05:18:08 -0800 | [diff] [blame] | 2338 | status = nfsd4_encode_aclname(rqstp, ace, &p, &buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | if (status == nfserr_resource) |
| 2340 | goto out_resource; |
| 2341 | if (status) |
| 2342 | goto out; |
| 2343 | } |
| 2344 | } |
| 2345 | out_acl: |
| 2346 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { |
| 2347 | if ((buflen -= 4) < 0) |
| 2348 | goto out_resource; |
| 2349 | WRITE32(aclsupport ? |
| 2350 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
| 2351 | } |
| 2352 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { |
| 2353 | if ((buflen -= 4) < 0) |
| 2354 | goto out_resource; |
| 2355 | WRITE32(1); |
| 2356 | } |
| 2357 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { |
| 2358 | if ((buflen -= 4) < 0) |
| 2359 | goto out_resource; |
J. Bruce Fields | 2930d38 | 2012-06-05 16:52:06 -0400 | [diff] [blame] | 2360 | WRITE32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | } |
| 2362 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { |
| 2363 | if ((buflen -= 4) < 0) |
| 2364 | goto out_resource; |
| 2365 | WRITE32(1); |
| 2366 | } |
| 2367 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { |
| 2368 | if ((buflen -= 4) < 0) |
| 2369 | goto out_resource; |
| 2370 | WRITE32(1); |
| 2371 | } |
| 2372 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { |
| 2373 | buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4; |
| 2374 | if (buflen < 0) |
| 2375 | goto out_resource; |
| 2376 | WRITE32(fhp->fh_handle.fh_size); |
| 2377 | WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size); |
| 2378 | } |
| 2379 | if (bmval0 & FATTR4_WORD0_FILEID) { |
| 2380 | if ((buflen -= 8) < 0) |
| 2381 | goto out_resource; |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 2382 | WRITE64(stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { |
| 2385 | if ((buflen -= 8) < 0) |
| 2386 | goto out_resource; |
| 2387 | WRITE64((u64) statfs.f_ffree); |
| 2388 | } |
| 2389 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { |
| 2390 | if ((buflen -= 8) < 0) |
| 2391 | goto out_resource; |
| 2392 | WRITE64((u64) statfs.f_ffree); |
| 2393 | } |
| 2394 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { |
| 2395 | if ((buflen -= 8) < 0) |
| 2396 | goto out_resource; |
| 2397 | WRITE64((u64) statfs.f_files); |
| 2398 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2399 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
| 2400 | status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen); |
| 2401 | if (status == nfserr_resource) |
| 2402 | goto out_resource; |
| 2403 | if (status) |
| 2404 | goto out; |
| 2405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
| 2407 | if ((buflen -= 4) < 0) |
| 2408 | goto out_resource; |
| 2409 | WRITE32(1); |
| 2410 | } |
| 2411 | if (bmval0 & FATTR4_WORD0_MAXFILESIZE) { |
| 2412 | if ((buflen -= 8) < 0) |
| 2413 | goto out_resource; |
Christoph Hellwig | aea240f | 2013-11-14 05:50:10 -0800 | [diff] [blame] | 2414 | WRITE64(exp->ex_path.mnt->mnt_sb->s_maxbytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | } |
| 2416 | if (bmval0 & FATTR4_WORD0_MAXLINK) { |
| 2417 | if ((buflen -= 4) < 0) |
| 2418 | goto out_resource; |
| 2419 | WRITE32(255); |
| 2420 | } |
| 2421 | if (bmval0 & FATTR4_WORD0_MAXNAME) { |
| 2422 | if ((buflen -= 4) < 0) |
| 2423 | goto out_resource; |
J. Bruce Fields | a16e92e | 2007-09-28 16:45:51 -0400 | [diff] [blame] | 2424 | WRITE32(statfs.f_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | } |
| 2426 | if (bmval0 & FATTR4_WORD0_MAXREAD) { |
| 2427 | if ((buflen -= 8) < 0) |
| 2428 | goto out_resource; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 2429 | WRITE64((u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | } |
| 2431 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { |
| 2432 | if ((buflen -= 8) < 0) |
| 2433 | goto out_resource; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 2434 | WRITE64((u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | } |
| 2436 | if (bmval1 & FATTR4_WORD1_MODE) { |
| 2437 | if ((buflen -= 4) < 0) |
| 2438 | goto out_resource; |
| 2439 | WRITE32(stat.mode & S_IALLUGO); |
| 2440 | } |
| 2441 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { |
| 2442 | if ((buflen -= 4) < 0) |
| 2443 | goto out_resource; |
| 2444 | WRITE32(1); |
| 2445 | } |
| 2446 | if (bmval1 & FATTR4_WORD1_NUMLINKS) { |
| 2447 | if ((buflen -= 4) < 0) |
| 2448 | goto out_resource; |
| 2449 | WRITE32(stat.nlink); |
| 2450 | } |
| 2451 | if (bmval1 & FATTR4_WORD1_OWNER) { |
| 2452 | status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen); |
| 2453 | if (status == nfserr_resource) |
| 2454 | goto out_resource; |
| 2455 | if (status) |
| 2456 | goto out; |
| 2457 | } |
| 2458 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { |
| 2459 | status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen); |
| 2460 | if (status == nfserr_resource) |
| 2461 | goto out_resource; |
| 2462 | if (status) |
| 2463 | goto out; |
| 2464 | } |
| 2465 | if (bmval1 & FATTR4_WORD1_RAWDEV) { |
| 2466 | if ((buflen -= 8) < 0) |
| 2467 | goto out_resource; |
| 2468 | WRITE32((u32) MAJOR(stat.rdev)); |
| 2469 | WRITE32((u32) MINOR(stat.rdev)); |
| 2470 | } |
| 2471 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { |
| 2472 | if ((buflen -= 8) < 0) |
| 2473 | goto out_resource; |
| 2474 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; |
| 2475 | WRITE64(dummy64); |
| 2476 | } |
| 2477 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { |
| 2478 | if ((buflen -= 8) < 0) |
| 2479 | goto out_resource; |
| 2480 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; |
| 2481 | WRITE64(dummy64); |
| 2482 | } |
| 2483 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { |
| 2484 | if ((buflen -= 8) < 0) |
| 2485 | goto out_resource; |
| 2486 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; |
| 2487 | WRITE64(dummy64); |
| 2488 | } |
| 2489 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { |
| 2490 | if ((buflen -= 8) < 0) |
| 2491 | goto out_resource; |
| 2492 | dummy64 = (u64)stat.blocks << 9; |
| 2493 | WRITE64(dummy64); |
| 2494 | } |
| 2495 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { |
| 2496 | if ((buflen -= 12) < 0) |
| 2497 | goto out_resource; |
Bryan Schumaker | bf8d909 | 2013-04-19 16:09:38 -0400 | [diff] [blame] | 2498 | WRITE64((s64)stat.atime.tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | WRITE32(stat.atime.tv_nsec); |
| 2500 | } |
| 2501 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { |
| 2502 | if ((buflen -= 12) < 0) |
| 2503 | goto out_resource; |
| 2504 | WRITE32(0); |
| 2505 | WRITE32(1); |
| 2506 | WRITE32(0); |
| 2507 | } |
| 2508 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { |
| 2509 | if ((buflen -= 12) < 0) |
| 2510 | goto out_resource; |
Bryan Schumaker | bf8d909 | 2013-04-19 16:09:38 -0400 | [diff] [blame] | 2511 | WRITE64((s64)stat.ctime.tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | WRITE32(stat.ctime.tv_nsec); |
| 2513 | } |
| 2514 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { |
| 2515 | if ((buflen -= 12) < 0) |
| 2516 | goto out_resource; |
Bryan Schumaker | bf8d909 | 2013-04-19 16:09:38 -0400 | [diff] [blame] | 2517 | WRITE64((s64)stat.mtime.tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | WRITE32(stat.mtime.tv_nsec); |
| 2519 | } |
| 2520 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | if ((buflen -= 8) < 0) |
| 2522 | goto out_resource; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2523 | /* |
| 2524 | * Get parent's attributes if not ignoring crossmount |
| 2525 | * and this is the root of a cross-mounted filesystem. |
| 2526 | */ |
| 2527 | if (ignore_crossmnt == 0 && |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2528 | dentry == exp->ex_path.mnt->mnt_root) |
| 2529 | get_parent_attributes(exp, &stat); |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 2530 | WRITE64(stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | } |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2532 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 2533 | status = nfsd4_encode_security_label(rqstp, context, |
| 2534 | contextlen, &p, &buflen); |
| 2535 | if (status) |
| 2536 | goto out; |
| 2537 | } |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 2538 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { |
| 2539 | WRITE32(3); |
| 2540 | WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0); |
| 2541 | WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1); |
| 2542 | WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2); |
| 2543 | } |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | *attrlenp = htonl((char *)p - (char *)attrlenp - 4); |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2546 | *buffer = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | status = nfs_ok; |
| 2548 | |
| 2549 | out: |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 2550 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2551 | if (context) |
| 2552 | security_release_secctx(context, contextlen); |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 2553 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 2554 | kfree(acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | if (fhp == &tempfh) |
| 2556 | fh_put(&tempfh); |
| 2557 | return status; |
| 2558 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2559 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | goto out; |
| 2561 | out_resource: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | status = nfserr_resource; |
| 2563 | goto out; |
| 2564 | out_serverfault: |
| 2565 | status = nfserr_serverfault; |
| 2566 | goto out; |
| 2567 | } |
| 2568 | |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 2569 | static inline int attributes_need_mount(u32 *bmval) |
| 2570 | { |
| 2571 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) |
| 2572 | return 1; |
| 2573 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 2574 | return 1; |
| 2575 | return 0; |
| 2576 | } |
| 2577 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2578 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd, |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2580 | const char *name, int namlen, __be32 **p, int buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | { |
| 2582 | struct svc_export *exp = cd->rd_fhp->fh_export; |
| 2583 | struct dentry *dentry; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2584 | __be32 nfserr; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2585 | int ignore_crossmnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | |
| 2587 | dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen); |
| 2588 | if (IS_ERR(dentry)) |
| 2589 | return nfserrno(PTR_ERR(dentry)); |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 2590 | if (!dentry->d_inode) { |
| 2591 | /* |
| 2592 | * nfsd_buffered_readdir drops the i_mutex between |
| 2593 | * readdir and calling this callback, leaving a window |
| 2594 | * where this directory entry could have gone away. |
| 2595 | */ |
| 2596 | dput(dentry); |
| 2597 | return nfserr_noent; |
| 2598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | |
| 2600 | exp_get(exp); |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2601 | /* |
| 2602 | * In the case of a mountpoint, the client may be asking for |
| 2603 | * attributes that are only properties of the underlying filesystem |
| 2604 | * as opposed to the cross-mounted file system. In such a case, |
| 2605 | * we will not follow the cross mount and will fill the attribtutes |
| 2606 | * directly from the mountpoint dentry. |
| 2607 | */ |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 2608 | if (nfsd_mountpoint(dentry, exp)) { |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 2609 | int err; |
| 2610 | |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 2611 | if (!(exp->ex_flags & NFSEXP_V4ROOT) |
| 2612 | && !attributes_need_mount(cd->rd_bmval)) { |
| 2613 | ignore_crossmnt = 1; |
| 2614 | goto out_encode; |
| 2615 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2616 | /* |
| 2617 | * Why the heck aren't we just using nfsd_lookup?? |
| 2618 | * Different "."/".." handling? Something else? |
| 2619 | * At least, add a comment here to explain.... |
| 2620 | */ |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 2621 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
| 2622 | if (err) { |
| 2623 | nfserr = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | goto out_put; |
| 2625 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2626 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
| 2627 | if (nfserr) |
| 2628 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | |
| 2630 | } |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 2631 | out_encode: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2633 | cd->rd_rqstp, ignore_crossmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | out_put: |
| 2635 | dput(dentry); |
| 2636 | exp_put(exp); |
| 2637 | return nfserr; |
| 2638 | } |
| 2639 | |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2640 | static __be32 * |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2641 | nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | { |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2643 | __be32 *attrlenp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | |
| 2645 | if (buflen < 6) |
| 2646 | return NULL; |
| 2647 | *p++ = htonl(2); |
| 2648 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ |
| 2649 | *p++ = htonl(0); /* bmval1 */ |
| 2650 | |
| 2651 | attrlenp = p++; |
| 2652 | *p++ = nfserr; /* no htonl */ |
| 2653 | *attrlenp = htonl((char *)p - (char *)attrlenp - 4); |
| 2654 | return p; |
| 2655 | } |
| 2656 | |
| 2657 | static int |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 2658 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
| 2659 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | { |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 2661 | struct readdir_cd *ccd = ccdv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
| 2663 | int buflen; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2664 | __be32 *p = cd->buffer; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 2665 | __be32 *cookiep; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2666 | __be32 nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | |
| 2668 | /* In nfsv4, "." and ".." never make it onto the wire.. */ |
| 2669 | if (name && isdotent(name, namlen)) { |
| 2670 | cd->common.err = nfs_ok; |
| 2671 | return 0; |
| 2672 | } |
| 2673 | |
| 2674 | if (cd->offset) |
| 2675 | xdr_encode_hyper(cd->offset, (u64) offset); |
| 2676 | |
| 2677 | buflen = cd->buflen - 4 - XDR_QUADLEN(namlen); |
| 2678 | if (buflen < 0) |
| 2679 | goto fail; |
| 2680 | |
| 2681 | *p++ = xdr_one; /* mark entry present */ |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 2682 | cookiep = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
| 2684 | p = xdr_encode_array(p, name, namlen); /* name length & name */ |
| 2685 | |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2686 | nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, &p, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | switch (nfserr) { |
| 2688 | case nfs_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | break; |
| 2690 | case nfserr_resource: |
| 2691 | nfserr = nfserr_toosmall; |
| 2692 | goto fail; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 2693 | case nfserr_noent: |
| 2694 | goto skip_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | default: |
| 2696 | /* |
| 2697 | * If the client requested the RDATTR_ERROR attribute, |
| 2698 | * we stuff the error code into this attribute |
| 2699 | * and continue. If this attribute was not requested, |
| 2700 | * then in accordance with the spec, we fail the |
| 2701 | * entire READDIR operation(!) |
| 2702 | */ |
| 2703 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) |
| 2704 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | p = nfsd4_encode_rdattr_error(p, buflen, nfserr); |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 2706 | if (p == NULL) { |
| 2707 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | goto fail; |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 2709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | } |
| 2711 | cd->buflen -= (p - cd->buffer); |
| 2712 | cd->buffer = p; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 2713 | cd->offset = cookiep; |
| 2714 | skip_entry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | cd->common.err = nfs_ok; |
| 2716 | return 0; |
| 2717 | fail: |
| 2718 | cd->common.err = nfserr; |
| 2719 | return -EINVAL; |
| 2720 | } |
| 2721 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2722 | static void |
| 2723 | nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid) |
| 2724 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2725 | __be32 *p; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2726 | |
| 2727 | RESERVE_SPACE(sizeof(stateid_t)); |
| 2728 | WRITE32(sid->si_generation); |
| 2729 | WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 2730 | ADJUST_ARGS(); |
| 2731 | } |
| 2732 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2733 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2734 | 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] | 2735 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2736 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | |
| 2738 | if (!nfserr) { |
| 2739 | RESERVE_SPACE(8); |
| 2740 | WRITE32(access->ac_supported); |
| 2741 | WRITE32(access->ac_resp_access); |
| 2742 | ADJUST_ARGS(); |
| 2743 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2744 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2747 | static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts) |
| 2748 | { |
| 2749 | __be32 *p; |
| 2750 | |
| 2751 | if (!nfserr) { |
| 2752 | RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 8); |
| 2753 | WRITEMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 2754 | WRITE32(bcts->dir); |
J. Bruce Fields | 6e67b5d | 2012-09-13 09:49:43 -0400 | [diff] [blame] | 2755 | /* Sorry, we do not yet support RDMA over 4.1: */ |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2756 | WRITE32(0); |
| 2757 | ADJUST_ARGS(); |
| 2758 | } |
| 2759 | return nfserr; |
| 2760 | } |
| 2761 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2762 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2763 | 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] | 2764 | { |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2765 | if (!nfserr) |
| 2766 | nfsd4_encode_stateid(resp, &close->cl_stateid); |
| 2767 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2768 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2772 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2773 | 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] | 2774 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2775 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | |
| 2777 | if (!nfserr) { |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 2778 | RESERVE_SPACE(NFS4_VERIFIER_SIZE); |
| 2779 | WRITEMEM(commit->co_verf.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | ADJUST_ARGS(); |
| 2781 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2782 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2785 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2786 | 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] | 2787 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2788 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | |
| 2790 | if (!nfserr) { |
| 2791 | RESERVE_SPACE(32); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2792 | write_cinfo(&p, &create->cr_cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | WRITE32(2); |
| 2794 | WRITE32(create->cr_bmval[0]); |
| 2795 | WRITE32(create->cr_bmval[1]); |
| 2796 | ADJUST_ARGS(); |
| 2797 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2798 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2801 | static __be32 |
| 2802 | 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] | 2803 | { |
| 2804 | struct svc_fh *fhp = getattr->ga_fhp; |
| 2805 | int buflen; |
| 2806 | |
| 2807 | if (nfserr) |
| 2808 | return nfserr; |
| 2809 | |
| 2810 | buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2); |
| 2811 | nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry, |
J. Bruce Fields | 84822d0 | 2012-12-14 17:57:50 -0500 | [diff] [blame] | 2812 | &resp->p, buflen, getattr->ga_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2813 | resp->rqstp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | return nfserr; |
| 2815 | } |
| 2816 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2817 | static __be32 |
| 2818 | 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] | 2819 | { |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2820 | struct svc_fh *fhp = *fhpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | unsigned int len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2822 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | |
| 2824 | if (!nfserr) { |
| 2825 | len = fhp->fh_handle.fh_size; |
| 2826 | RESERVE_SPACE(len + 4); |
| 2827 | WRITE32(len); |
| 2828 | WRITEMEM(&fhp->fh_handle.fh_base, len); |
| 2829 | ADJUST_ARGS(); |
| 2830 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2831 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | /* |
| 2835 | * Including all fields other than the name, a LOCK4denied structure requires |
| 2836 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. |
| 2837 | */ |
| 2838 | static void |
| 2839 | nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld) |
| 2840 | { |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 2841 | struct xdr_netobj *conf = &ld->ld_owner; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2842 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 2844 | RESERVE_SPACE(32 + XDR_LEN(conf->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | WRITE64(ld->ld_start); |
| 2846 | WRITE64(ld->ld_length); |
| 2847 | WRITE32(ld->ld_type); |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 2848 | if (conf->len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | WRITEMEM(&ld->ld_clientid, 8); |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 2850 | WRITE32(conf->len); |
| 2851 | WRITEMEM(conf->data, conf->len); |
| 2852 | kfree(conf->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
| 2854 | WRITE64((u64)0); /* clientid */ |
| 2855 | WRITE32(0); /* length of owner name */ |
| 2856 | } |
| 2857 | ADJUST_ARGS(); |
| 2858 | } |
| 2859 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2860 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2861 | 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] | 2862 | { |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2863 | if (!nfserr) |
| 2864 | nfsd4_encode_stateid(resp, &lock->lk_resp_stateid); |
| 2865 | else if (nfserr == nfserr_denied) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | nfsd4_encode_lock_denied(resp, &lock->lk_denied); |
| 2867 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2868 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2871 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2872 | 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] | 2873 | { |
| 2874 | if (nfserr == nfserr_denied) |
| 2875 | nfsd4_encode_lock_denied(resp, &lockt->lt_denied); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2876 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2879 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2880 | 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] | 2881 | { |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2882 | if (!nfserr) |
| 2883 | nfsd4_encode_stateid(resp, &locku->lu_stateid); |
| 2884 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2885 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2889 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2890 | 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] | 2891 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2892 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | |
| 2894 | if (!nfserr) { |
| 2895 | RESERVE_SPACE(20); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2896 | write_cinfo(&p, &link->li_cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | ADJUST_ARGS(); |
| 2898 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2899 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2903 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2904 | 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] | 2905 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 2906 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | |
| 2908 | if (nfserr) |
| 2909 | goto out; |
| 2910 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2911 | nfsd4_encode_stateid(resp, &open->op_stateid); |
| 2912 | RESERVE_SPACE(40); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2913 | write_cinfo(&p, &open->op_cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | WRITE32(open->op_rflags); |
| 2915 | WRITE32(2); |
| 2916 | WRITE32(open->op_bmval[0]); |
| 2917 | WRITE32(open->op_bmval[1]); |
| 2918 | WRITE32(open->op_delegate_type); |
| 2919 | ADJUST_ARGS(); |
| 2920 | |
| 2921 | switch (open->op_delegate_type) { |
| 2922 | case NFS4_OPEN_DELEGATE_NONE: |
| 2923 | break; |
| 2924 | case NFS4_OPEN_DELEGATE_READ: |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2925 | nfsd4_encode_stateid(resp, &open->op_delegate_stateid); |
| 2926 | RESERVE_SPACE(20); |
NeilBrown | 7b190fe | 2005-06-23 22:03:23 -0700 | [diff] [blame] | 2927 | WRITE32(open->op_recall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | |
| 2929 | /* |
| 2930 | * TODO: ACE's in delegations |
| 2931 | */ |
| 2932 | WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 2933 | WRITE32(0); |
| 2934 | WRITE32(0); |
| 2935 | WRITE32(0); /* XXX: is NULL principal ok? */ |
| 2936 | ADJUST_ARGS(); |
| 2937 | break; |
| 2938 | case NFS4_OPEN_DELEGATE_WRITE: |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2939 | nfsd4_encode_stateid(resp, &open->op_delegate_stateid); |
| 2940 | RESERVE_SPACE(32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | WRITE32(0); |
| 2942 | |
| 2943 | /* |
| 2944 | * TODO: space_limit's in delegations |
| 2945 | */ |
| 2946 | WRITE32(NFS4_LIMIT_SIZE); |
| 2947 | WRITE32(~(u32)0); |
| 2948 | WRITE32(~(u32)0); |
| 2949 | |
| 2950 | /* |
| 2951 | * TODO: ACE's in delegations |
| 2952 | */ |
| 2953 | WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 2954 | WRITE32(0); |
| 2955 | WRITE32(0); |
| 2956 | WRITE32(0); /* XXX: is NULL principal ok? */ |
| 2957 | ADJUST_ARGS(); |
| 2958 | break; |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 2959 | case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ |
| 2960 | switch (open->op_why_no_deleg) { |
| 2961 | case WND4_CONTENTION: |
| 2962 | case WND4_RESOURCE: |
| 2963 | RESERVE_SPACE(8); |
| 2964 | WRITE32(open->op_why_no_deleg); |
| 2965 | WRITE32(0); /* deleg signaling not supported yet */ |
| 2966 | break; |
| 2967 | default: |
| 2968 | RESERVE_SPACE(4); |
| 2969 | WRITE32(open->op_why_no_deleg); |
| 2970 | } |
| 2971 | ADJUST_ARGS(); |
| 2972 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | default: |
| 2974 | BUG(); |
| 2975 | } |
| 2976 | /* XXX save filehandle here */ |
| 2977 | out: |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2978 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | } |
| 2980 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2981 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2982 | 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] | 2983 | { |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2984 | if (!nfserr) |
| 2985 | nfsd4_encode_stateid(resp, &oc->oc_resp_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2987 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2990 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2991 | 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] | 2992 | { |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2993 | if (!nfserr) |
| 2994 | nfsd4_encode_stateid(resp, &od->od_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2996 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2999 | static __be32 |
| 3000 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 3001 | struct nfsd4_read *read) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | { |
| 3003 | u32 eof; |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3004 | int v; |
| 3005 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | unsigned long maxcount; |
| 3007 | long len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3008 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | |
| 3010 | if (nfserr) |
| 3011 | return nfserr; |
| 3012 | if (resp->xbuf->page_len) |
| 3013 | return nfserr_resource; |
| 3014 | |
| 3015 | RESERVE_SPACE(8); /* eof flag and byte count */ |
| 3016 | |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 3017 | maxcount = svc_max_payload(resp->rqstp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | if (maxcount > read->rd_length) |
| 3019 | maxcount = read->rd_length; |
| 3020 | |
| 3021 | len = maxcount; |
| 3022 | v = 0; |
| 3023 | while (len > 0) { |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3024 | page = *(resp->rqstp->rq_next_page); |
| 3025 | if (!page) { /* ran out of pages */ |
J. Bruce Fields | d5f50b0 | 2012-12-04 18:25:10 -0500 | [diff] [blame] | 3026 | maxcount -= len; |
| 3027 | break; |
| 3028 | } |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3029 | resp->rqstp->rq_vec[v].iov_base = page_address(page); |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 3030 | resp->rqstp->rq_vec[v].iov_len = |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 3031 | len < PAGE_SIZE ? len : PAGE_SIZE; |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3032 | resp->rqstp->rq_next_page++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | v++; |
| 3034 | len -= PAGE_SIZE; |
| 3035 | } |
| 3036 | read->rd_vlen = v; |
| 3037 | |
J. Bruce Fields | 039a87c | 2010-07-30 11:33:32 -0400 | [diff] [blame] | 3038 | nfserr = nfsd_read_file(read->rd_rqstp, read->rd_fhp, read->rd_filp, |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 3039 | read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | &maxcount); |
| 3041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | if (nfserr) |
| 3043 | return nfserr; |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 3044 | eof = (read->rd_offset + maxcount >= |
| 3045 | read->rd_fhp->fh_dentry->d_inode->i_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | |
| 3047 | WRITE32(eof); |
| 3048 | WRITE32(maxcount); |
| 3049 | ADJUST_ARGS(); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3050 | resp->xbuf->head[0].iov_len = (char*)p |
| 3051 | - (char*)resp->xbuf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | resp->xbuf->page_len = maxcount; |
| 3053 | |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3054 | /* Use rest of head for padding and remaining ops: */ |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3055 | resp->xbuf->tail[0].iov_base = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | resp->xbuf->tail[0].iov_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | if (maxcount&3) { |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3058 | RESERVE_SPACE(4); |
| 3059 | WRITE32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | resp->xbuf->tail[0].iov_base += maxcount&3; |
| 3061 | resp->xbuf->tail[0].iov_len = 4 - (maxcount&3); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3062 | ADJUST_ARGS(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | } |
| 3064 | return 0; |
| 3065 | } |
| 3066 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3067 | static __be32 |
| 3068 | 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] | 3069 | { |
| 3070 | int maxcount; |
| 3071 | char *page; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3072 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | |
| 3074 | if (nfserr) |
| 3075 | return nfserr; |
| 3076 | if (resp->xbuf->page_len) |
| 3077 | return nfserr_resource; |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3078 | if (!*resp->rqstp->rq_next_page) |
J. Bruce Fields | d5f50b0 | 2012-12-04 18:25:10 -0500 | [diff] [blame] | 3079 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3081 | page = page_address(*(resp->rqstp->rq_next_page++)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | |
| 3083 | maxcount = PAGE_SIZE; |
| 3084 | RESERVE_SPACE(4); |
| 3085 | |
| 3086 | /* |
| 3087 | * XXX: By default, the ->readlink() VFS op will truncate symlinks |
| 3088 | * if they would overflow the buffer. Is this kosher in NFSv4? If |
| 3089 | * not, one easy fix is: if ->readlink() precisely fills the buffer, |
| 3090 | * assume that truncation occurred, and return NFS4ERR_RESOURCE. |
| 3091 | */ |
| 3092 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount); |
| 3093 | if (nfserr == nfserr_isdir) |
| 3094 | return nfserr_inval; |
| 3095 | if (nfserr) |
| 3096 | return nfserr; |
| 3097 | |
| 3098 | WRITE32(maxcount); |
| 3099 | ADJUST_ARGS(); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3100 | resp->xbuf->head[0].iov_len = (char*)p |
| 3101 | - (char*)resp->xbuf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | resp->xbuf->page_len = maxcount; |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3103 | |
| 3104 | /* Use rest of head for padding and remaining ops: */ |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3105 | resp->xbuf->tail[0].iov_base = p; |
| 3106 | resp->xbuf->tail[0].iov_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | if (maxcount&3) { |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3108 | RESERVE_SPACE(4); |
| 3109 | WRITE32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | resp->xbuf->tail[0].iov_base += maxcount&3; |
| 3111 | resp->xbuf->tail[0].iov_len = 4 - (maxcount&3); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 3112 | ADJUST_ARGS(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | } |
| 3114 | return 0; |
| 3115 | } |
| 3116 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3117 | static __be32 |
| 3118 | 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] | 3119 | { |
| 3120 | int maxcount; |
| 3121 | loff_t offset; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3122 | __be32 *page, *savep, *tailbase; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3123 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | |
| 3125 | if (nfserr) |
| 3126 | return nfserr; |
| 3127 | if (resp->xbuf->page_len) |
| 3128 | return nfserr_resource; |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3129 | if (!*resp->rqstp->rq_next_page) |
J. Bruce Fields | d5f50b0 | 2012-12-04 18:25:10 -0500 | [diff] [blame] | 3130 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 3132 | RESERVE_SPACE(NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | savep = p; |
| 3134 | |
| 3135 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
| 3136 | WRITE32(0); |
| 3137 | WRITE32(0); |
| 3138 | ADJUST_ARGS(); |
| 3139 | resp->xbuf->head[0].iov_len = ((char*)resp->p) - (char*)resp->xbuf->head[0].iov_base; |
NeilBrown | bb6e8a9 | 2006-04-10 22:55:33 -0700 | [diff] [blame] | 3140 | tailbase = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | |
| 3142 | maxcount = PAGE_SIZE; |
| 3143 | if (maxcount > readdir->rd_maxcount) |
| 3144 | maxcount = readdir->rd_maxcount; |
| 3145 | |
| 3146 | /* |
| 3147 | * Convert from bytes to words, account for the two words already |
| 3148 | * written, make sure to leave two words at the end for the next |
| 3149 | * pointer and eof field. |
| 3150 | */ |
| 3151 | maxcount = (maxcount >> 2) - 4; |
| 3152 | if (maxcount < 0) { |
| 3153 | nfserr = nfserr_toosmall; |
| 3154 | goto err_no_verf; |
| 3155 | } |
| 3156 | |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3157 | page = page_address(*(resp->rqstp->rq_next_page++)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | readdir->common.err = 0; |
| 3159 | readdir->buflen = maxcount; |
| 3160 | readdir->buffer = page; |
| 3161 | readdir->offset = NULL; |
| 3162 | |
| 3163 | offset = readdir->rd_cookie; |
| 3164 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, |
| 3165 | &offset, |
| 3166 | &readdir->common, nfsd4_encode_dirent); |
| 3167 | if (nfserr == nfs_ok && |
| 3168 | readdir->common.err == nfserr_toosmall && |
| 3169 | readdir->buffer == page) |
| 3170 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | if (nfserr) |
| 3172 | goto err_no_verf; |
| 3173 | |
| 3174 | if (readdir->offset) |
| 3175 | xdr_encode_hyper(readdir->offset, offset); |
| 3176 | |
| 3177 | p = readdir->buffer; |
| 3178 | *p++ = 0; /* no more entries */ |
| 3179 | *p++ = htonl(readdir->common.err == nfserr_eof); |
J. Bruce Fields | afc5940 | 2012-12-10 18:01:37 -0500 | [diff] [blame] | 3180 | resp->xbuf->page_len = ((char*)p) - |
| 3181 | (char*)page_address(*(resp->rqstp->rq_next_page-1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | |
NeilBrown | bb6e8a9 | 2006-04-10 22:55:33 -0700 | [diff] [blame] | 3183 | /* Use rest of head for padding and remaining ops: */ |
NeilBrown | bb6e8a9 | 2006-04-10 22:55:33 -0700 | [diff] [blame] | 3184 | resp->xbuf->tail[0].iov_base = tailbase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | resp->xbuf->tail[0].iov_len = 0; |
| 3186 | resp->p = resp->xbuf->tail[0].iov_base; |
NeilBrown | bb6e8a9 | 2006-04-10 22:55:33 -0700 | [diff] [blame] | 3187 | resp->end = resp->p + (PAGE_SIZE - resp->xbuf->head[0].iov_len)/4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | |
| 3189 | return 0; |
| 3190 | err_no_verf: |
| 3191 | p = savep; |
| 3192 | ADJUST_ARGS(); |
| 3193 | return nfserr; |
| 3194 | } |
| 3195 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3196 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3197 | 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] | 3198 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3199 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | |
| 3201 | if (!nfserr) { |
| 3202 | RESERVE_SPACE(20); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 3203 | write_cinfo(&p, &remove->rm_cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | ADJUST_ARGS(); |
| 3205 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3206 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3209 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3210 | 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] | 3211 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3212 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | |
| 3214 | if (!nfserr) { |
| 3215 | RESERVE_SPACE(40); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 3216 | write_cinfo(&p, &rename->rn_sinfo); |
| 3217 | write_cinfo(&p, &rename->rn_tinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | ADJUST_ARGS(); |
| 3219 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3220 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3223 | static __be32 |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 3224 | nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp, |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 3225 | __be32 nfserr, struct svc_export *exp) |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3226 | { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3227 | u32 i, nflavs, supported; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3228 | struct exp_flavor_info *flavs; |
| 3229 | struct exp_flavor_info def_flavs[2]; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3230 | __be32 *p, *flavorsp; |
| 3231 | static bool report = true; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3232 | |
| 3233 | if (nfserr) |
| 3234 | goto out; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3235 | if (exp->ex_nflavors) { |
| 3236 | flavs = exp->ex_flavors; |
| 3237 | nflavs = exp->ex_nflavors; |
| 3238 | } else { /* Handling of some defaults in absence of real secinfo: */ |
| 3239 | flavs = def_flavs; |
| 3240 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { |
| 3241 | nflavs = 2; |
| 3242 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; |
| 3243 | flavs[1].pseudoflavor = RPC_AUTH_NULL; |
| 3244 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { |
| 3245 | nflavs = 1; |
| 3246 | flavs[0].pseudoflavor |
| 3247 | = svcauth_gss_flavor(exp->ex_client); |
| 3248 | } else { |
| 3249 | nflavs = 1; |
| 3250 | flavs[0].pseudoflavor |
| 3251 | = exp->ex_client->flavour->flavour; |
| 3252 | } |
| 3253 | } |
| 3254 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3255 | supported = 0; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3256 | RESERVE_SPACE(4); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3257 | flavorsp = p++; /* to be backfilled later */ |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3258 | ADJUST_ARGS(); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3259 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3260 | for (i = 0; i < nflavs; i++) { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3261 | rpc_authflavor_t pf = flavs[i].pseudoflavor; |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 3262 | struct rpcsec_gss_info info; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3263 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3264 | if (rpcauth_get_gssinfo(pf, &info) == 0) { |
| 3265 | supported++; |
Chuck Lever | ed9411a | 2013-04-30 18:48:45 -0400 | [diff] [blame] | 3266 | RESERVE_SPACE(4 + 4 + info.oid.len + 4 + 4); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3267 | WRITE32(RPC_AUTH_GSS); |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 3268 | WRITE32(info.oid.len); |
| 3269 | WRITEMEM(info.oid.data, info.oid.len); |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 3270 | WRITE32(info.qop); |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 3271 | WRITE32(info.service); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3272 | ADJUST_ARGS(); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3273 | } else if (pf < RPC_AUTH_MAXFLAVOR) { |
| 3274 | supported++; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3275 | RESERVE_SPACE(4); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3276 | WRITE32(pf); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3277 | ADJUST_ARGS(); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3278 | } else { |
| 3279 | if (report) |
| 3280 | pr_warn("NFS: SECINFO: security flavor %u " |
| 3281 | "is not supported\n", pf); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3282 | } |
| 3283 | } |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 3284 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 3285 | if (nflavs != supported) |
| 3286 | report = false; |
| 3287 | *flavorsp = htonl(supported); |
| 3288 | |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3289 | out: |
| 3290 | if (exp) |
| 3291 | exp_put(exp); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3292 | return nfserr; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 3295 | static __be32 |
| 3296 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 3297 | struct nfsd4_secinfo *secinfo) |
| 3298 | { |
| 3299 | return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->si_exp); |
| 3300 | } |
| 3301 | |
| 3302 | static __be32 |
| 3303 | nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 3304 | struct nfsd4_secinfo_no_name *secinfo) |
| 3305 | { |
| 3306 | return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->sin_exp); |
| 3307 | } |
| 3308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | /* |
| 3310 | * The SETATTR encode routine is special -- it always encodes a bitmap, |
| 3311 | * regardless of the error status. |
| 3312 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3313 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3314 | 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] | 3315 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3316 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3318 | RESERVE_SPACE(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | if (nfserr) { |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3320 | WRITE32(3); |
| 3321 | WRITE32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | WRITE32(0); |
| 3323 | WRITE32(0); |
| 3324 | } |
| 3325 | else { |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3326 | WRITE32(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | WRITE32(setattr->sa_bmval[0]); |
| 3328 | WRITE32(setattr->sa_bmval[1]); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3329 | WRITE32(setattr->sa_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | } |
| 3331 | ADJUST_ARGS(); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3332 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3335 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3336 | 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] | 3337 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3338 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | |
| 3340 | if (!nfserr) { |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 3341 | RESERVE_SPACE(8 + NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | WRITEMEM(&scd->se_clientid, 8); |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 3343 | WRITEMEM(&scd->se_confirm, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | ADJUST_ARGS(); |
| 3345 | } |
| 3346 | else if (nfserr == nfserr_clid_inuse) { |
| 3347 | RESERVE_SPACE(8); |
| 3348 | WRITE32(0); |
| 3349 | WRITE32(0); |
| 3350 | ADJUST_ARGS(); |
| 3351 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3352 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3355 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3356 | 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] | 3357 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3358 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | |
| 3360 | if (!nfserr) { |
| 3361 | RESERVE_SPACE(16); |
| 3362 | WRITE32(write->wr_bytes_written); |
| 3363 | WRITE32(write->wr_how_written); |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 3364 | WRITEMEM(write->wr_verifier.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | ADJUST_ARGS(); |
| 3366 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3367 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 3370 | static const u32 nfs4_minimal_spo_must_enforce[2] = { |
| 3371 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 3372 | 1 << (OP_EXCHANGE_ID - 32) | |
| 3373 | 1 << (OP_CREATE_SESSION - 32) | |
| 3374 | 1 << (OP_DESTROY_SESSION - 32) | |
| 3375 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 3376 | }; |
| 3377 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3378 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 3379 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3380 | struct nfsd4_exchange_id *exid) |
| 3381 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3382 | __be32 *p; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 3383 | char *major_id; |
| 3384 | char *server_scope; |
| 3385 | int major_id_sz; |
| 3386 | int server_scope_sz; |
| 3387 | uint64_t minor_id = 0; |
| 3388 | |
| 3389 | if (nfserr) |
| 3390 | return nfserr; |
| 3391 | |
| 3392 | major_id = utsname()->nodename; |
| 3393 | major_id_sz = strlen(major_id); |
| 3394 | server_scope = utsname()->nodename; |
| 3395 | server_scope_sz = strlen(server_scope); |
| 3396 | |
| 3397 | RESERVE_SPACE( |
| 3398 | 8 /* eir_clientid */ + |
| 3399 | 4 /* eir_sequenceid */ + |
| 3400 | 4 /* eir_flags */ + |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame^] | 3401 | 4 /* spr_how */); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 3402 | |
| 3403 | WRITEMEM(&exid->clientid, 8); |
| 3404 | WRITE32(exid->seqid); |
| 3405 | WRITE32(exid->flags); |
| 3406 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 3407 | WRITE32(exid->spa_how); |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame^] | 3408 | ADJUST_ARGS(); |
| 3409 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 3410 | switch (exid->spa_how) { |
| 3411 | case SP4_NONE: |
| 3412 | break; |
| 3413 | case SP4_MACH_CRED: |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame^] | 3414 | /* spo_must_enforce, spo_must_allow */ |
| 3415 | RESERVE_SPACE(16); |
| 3416 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 3417 | /* spo_must_enforce bitmap: */ |
| 3418 | WRITE32(2); |
| 3419 | WRITE32(nfs4_minimal_spo_must_enforce[0]); |
| 3420 | WRITE32(nfs4_minimal_spo_must_enforce[1]); |
| 3421 | /* empty spo_must_allow bitmap: */ |
| 3422 | WRITE32(0); |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame^] | 3423 | |
| 3424 | ADJUST_ARGS(); |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 3425 | break; |
| 3426 | default: |
| 3427 | WARN_ON_ONCE(1); |
| 3428 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 3429 | |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame^] | 3430 | RESERVE_SPACE( |
| 3431 | 8 /* so_minor_id */ + |
| 3432 | 4 /* so_major_id.len */ + |
| 3433 | (XDR_QUADLEN(major_id_sz) * 4) + |
| 3434 | 4 /* eir_server_scope.len */ + |
| 3435 | (XDR_QUADLEN(server_scope_sz) * 4) + |
| 3436 | 4 /* eir_server_impl_id.count (0) */); |
| 3437 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 3438 | /* The server_owner struct */ |
| 3439 | WRITE64(minor_id); /* Minor id */ |
| 3440 | /* major id */ |
| 3441 | WRITE32(major_id_sz); |
| 3442 | WRITEMEM(major_id, major_id_sz); |
| 3443 | |
| 3444 | /* Server scope */ |
| 3445 | WRITE32(server_scope_sz); |
| 3446 | WRITEMEM(server_scope, server_scope_sz); |
| 3447 | |
| 3448 | /* Implementation id */ |
| 3449 | WRITE32(0); /* zero length nfs_impl_id4 array */ |
| 3450 | ADJUST_ARGS(); |
| 3451 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 3455 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3456 | struct nfsd4_create_session *sess) |
| 3457 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3458 | __be32 *p; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 3459 | |
| 3460 | if (nfserr) |
| 3461 | return nfserr; |
| 3462 | |
| 3463 | RESERVE_SPACE(24); |
| 3464 | WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 3465 | WRITE32(sess->seqid); |
| 3466 | WRITE32(sess->flags); |
| 3467 | ADJUST_ARGS(); |
| 3468 | |
| 3469 | RESERVE_SPACE(28); |
| 3470 | WRITE32(0); /* headerpadsz */ |
| 3471 | WRITE32(sess->fore_channel.maxreq_sz); |
| 3472 | WRITE32(sess->fore_channel.maxresp_sz); |
| 3473 | WRITE32(sess->fore_channel.maxresp_cached); |
| 3474 | WRITE32(sess->fore_channel.maxops); |
| 3475 | WRITE32(sess->fore_channel.maxreqs); |
| 3476 | WRITE32(sess->fore_channel.nr_rdma_attrs); |
| 3477 | ADJUST_ARGS(); |
| 3478 | |
| 3479 | if (sess->fore_channel.nr_rdma_attrs) { |
| 3480 | RESERVE_SPACE(4); |
| 3481 | WRITE32(sess->fore_channel.rdma_attrs); |
| 3482 | ADJUST_ARGS(); |
| 3483 | } |
| 3484 | |
| 3485 | RESERVE_SPACE(28); |
| 3486 | WRITE32(0); /* headerpadsz */ |
| 3487 | WRITE32(sess->back_channel.maxreq_sz); |
| 3488 | WRITE32(sess->back_channel.maxresp_sz); |
| 3489 | WRITE32(sess->back_channel.maxresp_cached); |
| 3490 | WRITE32(sess->back_channel.maxops); |
| 3491 | WRITE32(sess->back_channel.maxreqs); |
| 3492 | WRITE32(sess->back_channel.nr_rdma_attrs); |
| 3493 | ADJUST_ARGS(); |
| 3494 | |
| 3495 | if (sess->back_channel.nr_rdma_attrs) { |
| 3496 | RESERVE_SPACE(4); |
| 3497 | WRITE32(sess->back_channel.rdma_attrs); |
| 3498 | ADJUST_ARGS(); |
| 3499 | } |
| 3500 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 3504 | nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3505 | struct nfsd4_destroy_session *destroy_session) |
| 3506 | { |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3507 | return nfserr; |
| 3508 | } |
| 3509 | |
Daniel Mack | c47d832 | 2011-05-16 16:38:14 +0200 | [diff] [blame] | 3510 | static __be32 |
J. Bruce Fields | d1829b3 | 2012-04-25 18:04:54 -0400 | [diff] [blame] | 3511 | nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3512 | struct nfsd4_free_stateid *free_stateid) |
| 3513 | { |
| 3514 | __be32 *p; |
| 3515 | |
| 3516 | if (nfserr) |
| 3517 | return nfserr; |
| 3518 | |
| 3519 | RESERVE_SPACE(4); |
J. Bruce Fields | d1829b3 | 2012-04-25 18:04:54 -0400 | [diff] [blame] | 3520 | *p++ = nfserr; |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3521 | ADJUST_ARGS(); |
| 3522 | return nfserr; |
| 3523 | } |
| 3524 | |
| 3525 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 3526 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3527 | struct nfsd4_sequence *seq) |
| 3528 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3529 | __be32 *p; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 3530 | |
| 3531 | if (nfserr) |
| 3532 | return nfserr; |
| 3533 | |
| 3534 | RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20); |
| 3535 | WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 3536 | WRITE32(seq->seqid); |
| 3537 | WRITE32(seq->slotid); |
J. Bruce Fields | b7d7ca3 | 2011-08-31 15:39:30 -0400 | [diff] [blame] | 3538 | /* Note slotid's are numbered from zero: */ |
| 3539 | WRITE32(seq->maxslots - 1); /* sr_highest_slotid */ |
| 3540 | WRITE32(seq->maxslots - 1); /* sr_target_highest_slotid */ |
J. Bruce Fields | 0d7bb71 | 2010-11-18 08:30:33 -0500 | [diff] [blame] | 3541 | WRITE32(seq->status_flags); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 3542 | |
| 3543 | ADJUST_ARGS(); |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 3544 | resp->cstate.datap = p; /* DRC cache data pointer */ |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 3545 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3546 | } |
| 3547 | |
J. Bruce Fields | 2355c59 | 2012-04-25 16:56:22 -0400 | [diff] [blame] | 3548 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 3549 | nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3550 | struct nfsd4_test_stateid *test_stateid) |
| 3551 | { |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 3552 | struct nfsd4_test_stateid_id *stateid, *next; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3553 | __be32 *p; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3554 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 3555 | RESERVE_SPACE(4 + (4 * test_stateid->ts_num_ids)); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3556 | *p++ = htonl(test_stateid->ts_num_ids); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3557 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 3558 | 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] | 3559 | *p++ = stateid->ts_id_status; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3560 | } |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3561 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 3562 | ADJUST_ARGS(); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3563 | return nfserr; |
| 3564 | } |
| 3565 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3566 | static __be32 |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3567 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
| 3568 | { |
| 3569 | return nfserr; |
| 3570 | } |
| 3571 | |
| 3572 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
| 3573 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3574 | /* |
| 3575 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 |
| 3576 | * since we don't need to filter out obsolete ops as this is |
| 3577 | * done in the decoding phase. |
| 3578 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3579 | static nfsd4_enc nfsd4_enc_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 3580 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
| 3581 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
| 3582 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, |
| 3583 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, |
| 3584 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, |
| 3585 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
| 3586 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, |
| 3587 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, |
| 3588 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, |
| 3589 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, |
| 3590 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, |
| 3591 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, |
| 3592 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, |
| 3593 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, |
| 3594 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 3595 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, |
Benny Halevy | 84f09f4 | 2009-03-04 23:05:35 +0200 | [diff] [blame] | 3596 | [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 3597 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
| 3598 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, |
| 3599 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 3600 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 3601 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 3602 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, |
| 3603 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, |
| 3604 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, |
| 3605 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, |
| 3606 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, |
| 3607 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, |
| 3608 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 3609 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 3610 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, |
| 3611 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, |
| 3612 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, |
| 3613 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, |
| 3614 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 3615 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
| 3616 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3617 | |
| 3618 | /* NFSv4.1 operations */ |
| 3619 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3620 | [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] | 3621 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, |
| 3622 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, |
| 3623 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 3624 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3625 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
| 3626 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, |
| 3627 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 3628 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, |
| 3629 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, |
| 3630 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 3631 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3632 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, |
| 3633 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 3634 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 3635 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
| 3636 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, |
| 3637 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3638 | }; |
| 3639 | |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3640 | /* |
| 3641 | * Calculate the total amount of memory that the compound response has taken |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3642 | * after encoding the current operation with pad. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3643 | * |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3644 | * pad: if operation is non-idempotent, pad was calculate by op_rsize_bop() |
| 3645 | * which was specified at nfsd4_operation, else pad is zero. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3646 | * |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3647 | * Compare this length to the session se_fmaxresp_sz and se_fmaxresp_cached. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3648 | * |
| 3649 | * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so |
| 3650 | * will be at least a page and will therefore hold the xdr_buf head. |
| 3651 | */ |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 3652 | __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad) |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3653 | { |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3654 | struct xdr_buf *xb = &resp->rqstp->rq_res; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3655 | struct nfsd4_session *session = NULL; |
| 3656 | struct nfsd4_slot *slot = resp->cstate.slot; |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3657 | u32 length, tlen = 0; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3658 | |
| 3659 | if (!nfsd4_has_session(&resp->cstate)) |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3660 | return 0; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3661 | |
| 3662 | session = resp->cstate.session; |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3663 | if (session == NULL) |
| 3664 | return 0; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3665 | |
| 3666 | if (xb->page_len == 0) { |
| 3667 | length = (char *)resp->p - (char *)xb->head[0].iov_base + pad; |
| 3668 | } else { |
| 3669 | if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0) |
| 3670 | tlen = (char *)resp->p - (char *)xb->tail[0].iov_base; |
| 3671 | |
| 3672 | length = xb->head[0].iov_len + xb->page_len + tlen + pad; |
| 3673 | } |
| 3674 | dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__, |
| 3675 | length, xb->page_len, tlen, pad); |
| 3676 | |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3677 | if (length > session->se_fchannel.maxresp_sz) |
| 3678 | return nfserr_rep_too_big; |
| 3679 | |
J. Bruce Fields | 73e7948 | 2012-02-13 16:39:00 -0500 | [diff] [blame] | 3680 | if ((slot->sl_flags & NFSD4_SLOT_CACHETHIS) && |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3681 | length > session->se_fchannel.maxresp_cached) |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3682 | return nfserr_rep_too_big_to_cache; |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3683 | |
| 3684 | return 0; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3685 | } |
| 3686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | void |
| 3688 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 3689 | { |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 3690 | struct nfs4_stateowner *so = resp->cstate.replay_owner; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3691 | __be32 *statp; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3692 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | |
| 3694 | RESERVE_SPACE(8); |
| 3695 | WRITE32(op->opnum); |
| 3696 | statp = p++; /* to be backfilled at the end */ |
| 3697 | ADJUST_ARGS(); |
| 3698 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3699 | if (op->opnum == OP_ILLEGAL) |
| 3700 | goto status; |
| 3701 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
| 3702 | !nfsd4_enc_ops[op->opnum]); |
| 3703 | op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u); |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 3704 | /* nfsd4_check_drc_limit guarantees enough room for error status */ |
Mi Jinlong | 58e7b33 | 2011-08-28 18:18:56 +0800 | [diff] [blame] | 3705 | if (!op->status) |
| 3706 | op->status = nfsd4_check_resp_size(resp, 0); |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 3707 | if (so) { |
| 3708 | so->so_replay.rp_status = op->status; |
| 3709 | so->so_replay.rp_buflen = (char *)resp->p - (char *)(statp+1); |
| 3710 | memcpy(so->so_replay.rp_buf, statp+1, so->so_replay.rp_buflen); |
| 3711 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3712 | status: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | /* |
| 3714 | * Note: We write the status directly, instead of using WRITE32(), |
| 3715 | * since it is already in network byte order. |
| 3716 | */ |
| 3717 | *statp = op->status; |
| 3718 | } |
| 3719 | |
| 3720 | /* |
| 3721 | * Encode the reply stored in the stateowner reply cache |
| 3722 | * |
| 3723 | * XDR note: do not encode rp->rp_buflen: the buffer contains the |
| 3724 | * previously sent already encoded operation. |
| 3725 | * |
| 3726 | * called with nfs4_lock_state() held |
| 3727 | */ |
| 3728 | void |
| 3729 | nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 3730 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3731 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | struct nfs4_replay *rp = op->replay; |
| 3733 | |
| 3734 | BUG_ON(!rp); |
| 3735 | |
| 3736 | RESERVE_SPACE(8); |
| 3737 | WRITE32(op->opnum); |
| 3738 | *p++ = rp->rp_status; /* already xdr'ed */ |
| 3739 | ADJUST_ARGS(); |
| 3740 | |
| 3741 | RESERVE_SPACE(rp->rp_buflen); |
| 3742 | WRITEMEM(rp->rp_buf, rp->rp_buflen); |
| 3743 | ADJUST_ARGS(); |
| 3744 | } |
| 3745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | int |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3747 | nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | { |
| 3749 | return xdr_ressize_check(rqstp, p); |
| 3750 | } |
| 3751 | |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 3752 | int nfsd4_release_compoundargs(void *rq, __be32 *p, void *resp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | { |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 3754 | struct svc_rqst *rqstp = rq; |
| 3755 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 3756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | if (args->ops != args->iops) { |
| 3758 | kfree(args->ops); |
| 3759 | args->ops = args->iops; |
| 3760 | } |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 3761 | kfree(args->tmpp); |
| 3762 | args->tmpp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | while (args->to_free) { |
| 3764 | struct tmpbuf *tb = args->to_free; |
| 3765 | args->to_free = tb->next; |
| 3766 | tb->release(tb->buf); |
| 3767 | kfree(tb); |
| 3768 | } |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 3769 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | int |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3773 | nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | args->p = p; |
| 3776 | args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len; |
| 3777 | args->pagelist = rqstp->rq_arg.pages; |
| 3778 | args->pagelen = rqstp->rq_arg.page_len; |
| 3779 | args->tmpp = NULL; |
| 3780 | args->to_free = NULL; |
| 3781 | args->ops = args->iops; |
| 3782 | args->rqstp = rqstp; |
| 3783 | |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 3784 | return !nfsd4_decode_compound(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | int |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3788 | nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundres *resp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | { |
| 3790 | /* |
| 3791 | * All that remains is to write the tag and operation count... |
| 3792 | */ |
Andy Adamson | 557ce26 | 2009-08-28 08:45:04 -0400 | [diff] [blame] | 3793 | struct nfsd4_compound_state *cs = &resp->cstate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | struct kvec *iov; |
| 3795 | p = resp->tagp; |
| 3796 | *p++ = htonl(resp->taglen); |
| 3797 | memcpy(p, resp->tag, resp->taglen); |
| 3798 | p += XDR_QUADLEN(resp->taglen); |
| 3799 | *p++ = htonl(resp->opcnt); |
| 3800 | |
| 3801 | if (rqstp->rq_res.page_len) |
| 3802 | iov = &rqstp->rq_res.tail[0]; |
| 3803 | else |
| 3804 | iov = &rqstp->rq_res.head[0]; |
| 3805 | iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base; |
| 3806 | BUG_ON(iov->iov_len > PAGE_SIZE); |
J. Bruce Fields | 26c0c75 | 2010-04-24 15:35:43 -0400 | [diff] [blame] | 3807 | if (nfsd4_has_session(cs)) { |
J. Bruce Fields | f0f51f5 | 2013-06-18 14:26:02 -0400 | [diff] [blame] | 3808 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
| 3809 | struct nfs4_client *clp = cs->session->se_client; |
J. Bruce Fields | 26c0c75 | 2010-04-24 15:35:43 -0400 | [diff] [blame] | 3810 | if (cs->status != nfserr_replay_cache) { |
| 3811 | nfsd4_store_cache_entry(resp); |
J. Bruce Fields | 73e7948 | 2012-02-13 16:39:00 -0500 | [diff] [blame] | 3812 | cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE; |
J. Bruce Fields | 26c0c75 | 2010-04-24 15:35:43 -0400 | [diff] [blame] | 3813 | } |
Benny Halevy | d768298 | 2010-05-12 00:13:54 +0300 | [diff] [blame] | 3814 | /* Renew the clientid on success and on replay */ |
J. Bruce Fields | f0f51f5 | 2013-06-18 14:26:02 -0400 | [diff] [blame] | 3815 | spin_lock(&nn->client_lock); |
J. Bruce Fields | 221a687 | 2013-04-01 22:23:49 -0400 | [diff] [blame] | 3816 | nfsd4_put_session(cs->session); |
J. Bruce Fields | f0f51f5 | 2013-06-18 14:26:02 -0400 | [diff] [blame] | 3817 | spin_unlock(&nn->client_lock); |
| 3818 | put_client_renew(clp); |
Andy Adamson | da3846a | 2009-04-03 08:28:22 +0300 | [diff] [blame] | 3819 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | return 1; |
| 3821 | } |
| 3822 | |
| 3823 | /* |
| 3824 | * Local variables: |
| 3825 | * c-basic-offset: 8 |
| 3826 | * End: |
| 3827 | */ |