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