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