Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4xdr.c |
| 3 | * |
| 4 | * Server-side XDR for NFSv4 |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | * |
| 37 | * TODO: Neil Brown made the following observation: We currently |
| 38 | * initially reserve NFSD_BUFSIZE space on the transmit queue and |
| 39 | * never release any of that until the request is complete. |
| 40 | * It would be good to calculate a new maximum response size while |
| 41 | * decoding the COMPOUND, and call svc_reserve with this number |
| 42 | * at the end of nfs4svc_decode_compoundargs. |
| 43 | */ |
| 44 | |
| 45 | #include <linux/param.h> |
| 46 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/fs.h> |
| 48 | #include <linux/namei.h> |
| 49 | #include <linux/vfs.h> |
| 50 | #include <linux/sunrpc/xdr.h> |
| 51 | #include <linux/sunrpc/svc.h> |
| 52 | #include <linux/sunrpc/clnt.h> |
| 53 | #include <linux/nfsd/nfsd.h> |
| 54 | #include <linux/nfsd/state.h> |
| 55 | #include <linux/nfsd/xdr4.h> |
| 56 | #include <linux/nfsd_idmap.h> |
| 57 | #include <linux/nfs4.h> |
| 58 | #include <linux/nfs4_acl.h> |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 59 | #include <linux/sunrpc/gss_api.h> |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 60 | #include <linux/sunrpc/svcauth_gss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define NFSDDBG_FACILITY NFSDDBG_XDR |
| 63 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 64 | /* |
| 65 | * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing |
| 66 | * directory in order to indicate to the client that a filesystem boundary is present |
| 67 | * We use a fixed fsid for a referral |
| 68 | */ |
| 69 | #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL |
| 70 | #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL |
| 71 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 72 | static __be32 |
| 73 | check_filename(char *str, int len, __be32 err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | int i; |
| 76 | |
| 77 | if (len == 0) |
| 78 | return nfserr_inval; |
| 79 | if (isdotent(str, len)) |
| 80 | return err; |
| 81 | for (i = 0; i < len; i++) |
| 82 | if (str[i] == '/') |
| 83 | return err; |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * START OF "GENERIC" DECODE ROUTINES. |
| 89 | * These may look a little ugly since they are imported from a "generic" |
| 90 | * set of XDR encode/decode routines which are intended to be shared by |
| 91 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). |
| 92 | * |
| 93 | * If the pain of reading these is too great, it should be a straightforward |
| 94 | * task to translate them into Linux-specific versions which are more |
| 95 | * consistent with the style used in NFSv2/v3... |
| 96 | */ |
| 97 | #define DECODE_HEAD \ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 98 | __be32 *p; \ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 99 | __be32 status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #define DECODE_TAIL \ |
| 101 | status = 0; \ |
| 102 | out: \ |
| 103 | return status; \ |
| 104 | xdr_error: \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 105 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 106 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | status = nfserr_bad_xdr; \ |
| 108 | goto out |
| 109 | |
| 110 | #define READ32(x) (x) = ntohl(*p++) |
| 111 | #define READ64(x) do { \ |
| 112 | (x) = (u64)ntohl(*p++) << 32; \ |
| 113 | (x) |= ntohl(*p++); \ |
| 114 | } while (0) |
| 115 | #define READTIME(x) do { \ |
| 116 | p++; \ |
| 117 | (x) = ntohl(*p++); \ |
| 118 | p++; \ |
| 119 | } while (0) |
| 120 | #define READMEM(x,nbytes) do { \ |
| 121 | x = (char *)p; \ |
| 122 | p += XDR_QUADLEN(nbytes); \ |
| 123 | } while (0) |
| 124 | #define SAVEMEM(x,nbytes) do { \ |
| 125 | if (!(x = (p==argp->tmp || p == argp->tmpp) ? \ |
| 126 | savemem(argp, p, nbytes) : \ |
| 127 | (char *)p)) { \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 128 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 129 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | goto xdr_error; \ |
| 131 | } \ |
| 132 | p += XDR_QUADLEN(nbytes); \ |
| 133 | } while (0) |
| 134 | #define COPYMEM(x,nbytes) do { \ |
| 135 | memcpy((x), p, nbytes); \ |
| 136 | p += XDR_QUADLEN(nbytes); \ |
| 137 | } while (0) |
| 138 | |
| 139 | /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */ |
| 140 | #define READ_BUF(nbytes) do { \ |
| 141 | if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \ |
| 142 | p = argp->p; \ |
| 143 | argp->p += XDR_QUADLEN(nbytes); \ |
| 144 | } else if (!(p = read_buf(argp, nbytes))) { \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 145 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 146 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | goto xdr_error; \ |
| 148 | } \ |
| 149 | } while (0) |
| 150 | |
J. Bruce Fields | ca2a05a | 2007-11-11 15:43:12 -0500 | [diff] [blame] | 151 | static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | /* We want more bytes than seem to be available. |
| 154 | * Maybe we need a new page, maybe we have just run out |
| 155 | */ |
J. Bruce Fields | ca2a05a | 2007-11-11 15:43:12 -0500 | [diff] [blame] | 156 | unsigned int avail = (char *)argp->end - (char *)argp->p; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 157 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | if (avail + argp->pagelen < nbytes) |
| 159 | return NULL; |
| 160 | if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */ |
| 161 | return NULL; |
| 162 | /* ok, we can do it with the current plus the next page */ |
| 163 | if (nbytes <= sizeof(argp->tmp)) |
| 164 | p = argp->tmp; |
| 165 | else { |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 166 | kfree(argp->tmpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL); |
| 168 | if (!p) |
| 169 | return NULL; |
| 170 | |
| 171 | } |
J. Bruce Fields | ca2a05a | 2007-11-11 15:43:12 -0500 | [diff] [blame] | 172 | /* |
| 173 | * The following memcpy is safe because read_buf is always |
| 174 | * called with nbytes > avail, and the two cases above both |
| 175 | * guarantee p points to at least nbytes bytes. |
| 176 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | memcpy(p, argp->p, avail); |
| 178 | /* step to next page */ |
| 179 | argp->p = page_address(argp->pagelist[0]); |
| 180 | argp->pagelist++; |
| 181 | if (argp->pagelen < PAGE_SIZE) { |
| 182 | argp->end = p + (argp->pagelen>>2); |
| 183 | argp->pagelen = 0; |
| 184 | } else { |
| 185 | argp->end = p + (PAGE_SIZE>>2); |
| 186 | argp->pagelen -= PAGE_SIZE; |
| 187 | } |
| 188 | memcpy(((char*)p)+avail, argp->p, (nbytes - avail)); |
| 189 | argp->p += XDR_QUADLEN(nbytes - avail); |
| 190 | return p; |
| 191 | } |
| 192 | |
| 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) { |
J. Bruce Fields | a4db5fe | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 212 | p = kmalloc(nbytes, GFP_KERNEL); |
| 213 | if (!p) |
| 214 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | memcpy(p, argp->tmp, nbytes); |
| 216 | } else { |
Eric Sesterhenn | 73dff8b | 2006-10-03 23:37:14 +0200 | [diff] [blame] | 217 | BUG_ON(p != argp->tmpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | argp->tmpp = NULL; |
| 219 | } |
| 220 | if (defer_free(argp, kfree, p)) { |
J. Bruce Fields | a4db5fe | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 221 | kfree(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | return NULL; |
| 223 | } else |
| 224 | return (char *)p; |
| 225 | } |
| 226 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 227 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) |
| 229 | { |
| 230 | u32 bmlen; |
| 231 | DECODE_HEAD; |
| 232 | |
| 233 | bmval[0] = 0; |
| 234 | bmval[1] = 0; |
| 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]); |
| 246 | |
| 247 | DECODE_TAIL; |
| 248 | } |
| 249 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 250 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, struct iattr *iattr, |
| 252 | struct nfs4_acl **acl) |
| 253 | { |
| 254 | int expected_len, len = 0; |
| 255 | u32 dummy32; |
| 256 | char *buf; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 257 | int host_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | DECODE_HEAD; |
| 260 | iattr->ia_valid = 0; |
| 261 | if ((status = nfsd4_decode_bitmap(argp, bmval))) |
| 262 | return status; |
| 263 | |
| 264 | /* |
J. Bruce Fields | f34f924 | 2007-02-16 01:28:34 -0800 | [diff] [blame] | 265 | * According to spec, unsupported attributes return ERR_ATTRNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | * read-only attributes return ERR_INVAL. |
| 267 | */ |
| 268 | if ((bmval[0] & ~NFSD_SUPPORTED_ATTRS_WORD0) || (bmval[1] & ~NFSD_SUPPORTED_ATTRS_WORD1)) |
| 269 | return nfserr_attrnotsupp; |
| 270 | if ((bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0) || (bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1)) |
| 271 | return nfserr_inval; |
| 272 | |
| 273 | READ_BUF(4); |
| 274 | READ32(expected_len); |
| 275 | |
| 276 | if (bmval[0] & FATTR4_WORD0_SIZE) { |
| 277 | READ_BUF(8); |
| 278 | len += 8; |
| 279 | READ64(iattr->ia_size); |
| 280 | iattr->ia_valid |= ATTR_SIZE; |
| 281 | } |
| 282 | if (bmval[0] & FATTR4_WORD0_ACL) { |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 283 | int nace; |
| 284 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | READ_BUF(4); len += 4; |
| 287 | READ32(nace); |
| 288 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 289 | if (nace > NFS4_ACL_MAX) |
| 290 | return nfserr_resource; |
| 291 | |
| 292 | *acl = nfs4_acl_new(nace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | if (*acl == NULL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 294 | host_err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | goto out_nfserr; |
| 296 | } |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 297 | defer_free(argp, kfree, *acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 299 | (*acl)->naces = nace; |
| 300 | for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | READ_BUF(16); len += 16; |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 302 | READ32(ace->type); |
| 303 | READ32(ace->flag); |
| 304 | READ32(ace->access_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | READ32(dummy32); |
| 306 | READ_BUF(dummy32); |
| 307 | len += XDR_QUADLEN(dummy32) << 2; |
| 308 | READMEM(buf, dummy32); |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 309 | ace->whotype = nfs4_acl_get_whotype(buf, dummy32); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 310 | host_err = 0; |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 311 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
| 312 | ace->who = 0; |
| 313 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 314 | host_err = nfsd_map_name_to_gid(argp->rqstp, |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 315 | buf, dummy32, &ace->who); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | else |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 317 | host_err = nfsd_map_name_to_uid(argp->rqstp, |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 318 | buf, dummy32, &ace->who); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 319 | if (host_err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | goto out_nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | } else |
| 323 | *acl = NULL; |
| 324 | if (bmval[1] & FATTR4_WORD1_MODE) { |
| 325 | READ_BUF(4); |
| 326 | len += 4; |
| 327 | READ32(iattr->ia_mode); |
| 328 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
| 329 | iattr->ia_valid |= ATTR_MODE; |
| 330 | } |
| 331 | if (bmval[1] & FATTR4_WORD1_OWNER) { |
| 332 | READ_BUF(4); |
| 333 | len += 4; |
| 334 | READ32(dummy32); |
| 335 | READ_BUF(dummy32); |
| 336 | len += (XDR_QUADLEN(dummy32) << 2); |
| 337 | READMEM(buf, dummy32); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 338 | if ((host_err = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | goto out_nfserr; |
| 340 | iattr->ia_valid |= ATTR_UID; |
| 341 | } |
| 342 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { |
| 343 | READ_BUF(4); |
| 344 | len += 4; |
| 345 | READ32(dummy32); |
| 346 | READ_BUF(dummy32); |
| 347 | len += (XDR_QUADLEN(dummy32) << 2); |
| 348 | READMEM(buf, dummy32); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 349 | if ((host_err = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | goto out_nfserr; |
| 351 | iattr->ia_valid |= ATTR_GID; |
| 352 | } |
| 353 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { |
| 354 | READ_BUF(4); |
| 355 | len += 4; |
| 356 | READ32(dummy32); |
| 357 | switch (dummy32) { |
| 358 | case NFS4_SET_TO_CLIENT_TIME: |
| 359 | /* We require the high 32 bits of 'seconds' to be 0, and we ignore |
| 360 | all 32 bits of 'nseconds'. */ |
| 361 | READ_BUF(12); |
| 362 | len += 12; |
| 363 | READ32(dummy32); |
| 364 | if (dummy32) |
| 365 | return nfserr_inval; |
| 366 | READ32(iattr->ia_atime.tv_sec); |
| 367 | READ32(iattr->ia_atime.tv_nsec); |
| 368 | if (iattr->ia_atime.tv_nsec >= (u32)1000000000) |
| 369 | return nfserr_inval; |
| 370 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
| 371 | break; |
| 372 | case NFS4_SET_TO_SERVER_TIME: |
| 373 | iattr->ia_valid |= ATTR_ATIME; |
| 374 | break; |
| 375 | default: |
| 376 | goto xdr_error; |
| 377 | } |
| 378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
| 380 | READ_BUF(4); |
| 381 | len += 4; |
| 382 | READ32(dummy32); |
| 383 | switch (dummy32) { |
| 384 | case NFS4_SET_TO_CLIENT_TIME: |
| 385 | /* We require the high 32 bits of 'seconds' to be 0, and we ignore |
| 386 | all 32 bits of 'nseconds'. */ |
| 387 | READ_BUF(12); |
| 388 | len += 12; |
| 389 | READ32(dummy32); |
| 390 | if (dummy32) |
| 391 | return nfserr_inval; |
| 392 | READ32(iattr->ia_mtime.tv_sec); |
| 393 | READ32(iattr->ia_mtime.tv_nsec); |
| 394 | if (iattr->ia_mtime.tv_nsec >= (u32)1000000000) |
| 395 | return nfserr_inval; |
| 396 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
| 397 | break; |
| 398 | case NFS4_SET_TO_SERVER_TIME: |
| 399 | iattr->ia_valid |= ATTR_MTIME; |
| 400 | break; |
| 401 | default: |
| 402 | goto xdr_error; |
| 403 | } |
| 404 | } |
| 405 | if (len != expected_len) |
| 406 | goto xdr_error; |
| 407 | |
| 408 | DECODE_TAIL; |
| 409 | |
| 410 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 411 | status = nfserrno(host_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | goto out; |
| 413 | } |
| 414 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 415 | static __be32 |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 416 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 417 | { |
| 418 | DECODE_HEAD; |
| 419 | |
| 420 | READ_BUF(sizeof(stateid_t)); |
| 421 | READ32(sid->si_generation); |
| 422 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 423 | |
| 424 | DECODE_TAIL; |
| 425 | } |
| 426 | |
| 427 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access) |
| 429 | { |
| 430 | DECODE_HEAD; |
| 431 | |
| 432 | READ_BUF(4); |
| 433 | READ32(access->ac_req_access); |
| 434 | |
| 435 | DECODE_TAIL; |
| 436 | } |
| 437 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 438 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
| 440 | { |
| 441 | DECODE_HEAD; |
| 442 | |
| 443 | close->cl_stateowner = NULL; |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 444 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | READ32(close->cl_seqid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 446 | return nfsd4_decode_stateid(argp, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | DECODE_TAIL; |
| 449 | } |
| 450 | |
| 451 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 452 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
| 454 | { |
| 455 | DECODE_HEAD; |
| 456 | |
| 457 | READ_BUF(12); |
| 458 | READ64(commit->co_offset); |
| 459 | READ32(commit->co_count); |
| 460 | |
| 461 | DECODE_TAIL; |
| 462 | } |
| 463 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 464 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
| 466 | { |
| 467 | DECODE_HEAD; |
| 468 | |
| 469 | READ_BUF(4); |
| 470 | READ32(create->cr_type); |
| 471 | switch (create->cr_type) { |
| 472 | case NF4LNK: |
| 473 | READ_BUF(4); |
| 474 | READ32(create->cr_linklen); |
| 475 | READ_BUF(create->cr_linklen); |
| 476 | SAVEMEM(create->cr_linkname, create->cr_linklen); |
| 477 | break; |
| 478 | case NF4BLK: |
| 479 | case NF4CHR: |
| 480 | READ_BUF(8); |
| 481 | READ32(create->cr_specdata1); |
| 482 | READ32(create->cr_specdata2); |
| 483 | break; |
| 484 | case NF4SOCK: |
| 485 | case NF4FIFO: |
| 486 | case NF4DIR: |
| 487 | default: |
| 488 | break; |
| 489 | } |
| 490 | |
| 491 | READ_BUF(4); |
| 492 | READ32(create->cr_namelen); |
| 493 | READ_BUF(create->cr_namelen); |
| 494 | SAVEMEM(create->cr_name, create->cr_namelen); |
| 495 | if ((status = check_filename(create->cr_name, create->cr_namelen, nfserr_inval))) |
| 496 | return status; |
| 497 | |
| 498 | if ((status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr, &create->cr_acl))) |
| 499 | goto out; |
| 500 | |
| 501 | DECODE_TAIL; |
| 502 | } |
| 503 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 504 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
| 506 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 507 | return nfsd4_decode_stateid(argp, &dr->dr_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 510 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
| 512 | { |
| 513 | return nfsd4_decode_bitmap(argp, getattr->ga_bmval); |
| 514 | } |
| 515 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 516 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
| 518 | { |
| 519 | DECODE_HEAD; |
| 520 | |
| 521 | READ_BUF(4); |
| 522 | READ32(link->li_namelen); |
| 523 | READ_BUF(link->li_namelen); |
| 524 | SAVEMEM(link->li_name, link->li_namelen); |
| 525 | if ((status = check_filename(link->li_name, link->li_namelen, nfserr_inval))) |
| 526 | return status; |
| 527 | |
| 528 | DECODE_TAIL; |
| 529 | } |
| 530 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 531 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 533 | { |
| 534 | DECODE_HEAD; |
| 535 | |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 536 | lock->lk_replay_owner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* |
| 538 | * type, reclaim(boolean), offset, length, new_lock_owner(boolean) |
| 539 | */ |
| 540 | READ_BUF(28); |
| 541 | READ32(lock->lk_type); |
| 542 | if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT)) |
| 543 | goto xdr_error; |
| 544 | READ32(lock->lk_reclaim); |
| 545 | READ64(lock->lk_offset); |
| 546 | READ64(lock->lk_length); |
| 547 | READ32(lock->lk_is_new); |
| 548 | |
| 549 | if (lock->lk_is_new) { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 550 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | READ32(lock->lk_new_open_seqid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 552 | status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid); |
| 553 | if (status) |
| 554 | return status; |
| 555 | READ_BUF(8 + sizeof(clientid_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | READ32(lock->lk_new_lock_seqid); |
| 557 | COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t)); |
| 558 | READ32(lock->lk_new_owner.len); |
| 559 | READ_BUF(lock->lk_new_owner.len); |
| 560 | READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len); |
| 561 | } else { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 562 | status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid); |
| 563 | if (status) |
| 564 | return status; |
| 565 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | READ32(lock->lk_old_lock_seqid); |
| 567 | } |
| 568 | |
| 569 | DECODE_TAIL; |
| 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_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
| 574 | { |
| 575 | DECODE_HEAD; |
| 576 | |
| 577 | READ_BUF(32); |
| 578 | READ32(lockt->lt_type); |
| 579 | if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
| 580 | goto xdr_error; |
| 581 | READ64(lockt->lt_offset); |
| 582 | READ64(lockt->lt_length); |
| 583 | COPYMEM(&lockt->lt_clientid, 8); |
| 584 | READ32(lockt->lt_owner.len); |
| 585 | READ_BUF(lockt->lt_owner.len); |
| 586 | READMEM(lockt->lt_owner.data, lockt->lt_owner.len); |
| 587 | |
| 588 | DECODE_TAIL; |
| 589 | } |
| 590 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 591 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
| 593 | { |
| 594 | DECODE_HEAD; |
| 595 | |
| 596 | locku->lu_stateowner = NULL; |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 597 | READ_BUF(8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | READ32(locku->lu_type); |
| 599 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) |
| 600 | goto xdr_error; |
| 601 | READ32(locku->lu_seqid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 602 | status = nfsd4_decode_stateid(argp, &locku->lu_stateid); |
| 603 | if (status) |
| 604 | return status; |
| 605 | READ_BUF(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | READ64(locku->lu_offset); |
| 607 | READ64(locku->lu_length); |
| 608 | |
| 609 | DECODE_TAIL; |
| 610 | } |
| 611 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 612 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
| 614 | { |
| 615 | DECODE_HEAD; |
| 616 | |
| 617 | READ_BUF(4); |
| 618 | READ32(lookup->lo_len); |
| 619 | READ_BUF(lookup->lo_len); |
| 620 | SAVEMEM(lookup->lo_name, lookup->lo_len); |
| 621 | if ((status = check_filename(lookup->lo_name, lookup->lo_len, nfserr_noent))) |
| 622 | return status; |
| 623 | |
| 624 | DECODE_TAIL; |
| 625 | } |
| 626 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 627 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 629 | { |
| 630 | DECODE_HEAD; |
| 631 | |
| 632 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); |
| 633 | open->op_iattr.ia_valid = 0; |
| 634 | open->op_stateowner = NULL; |
| 635 | |
| 636 | /* seqid, share_access, share_deny, clientid, ownerlen */ |
| 637 | READ_BUF(16 + sizeof(clientid_t)); |
| 638 | READ32(open->op_seqid); |
| 639 | READ32(open->op_share_access); |
| 640 | READ32(open->op_share_deny); |
| 641 | COPYMEM(&open->op_clientid, sizeof(clientid_t)); |
| 642 | READ32(open->op_owner.len); |
| 643 | |
| 644 | /* owner, open_flag */ |
| 645 | READ_BUF(open->op_owner.len + 4); |
| 646 | SAVEMEM(open->op_owner.data, open->op_owner.len); |
| 647 | READ32(open->op_create); |
| 648 | switch (open->op_create) { |
| 649 | case NFS4_OPEN_NOCREATE: |
| 650 | break; |
| 651 | case NFS4_OPEN_CREATE: |
| 652 | READ_BUF(4); |
| 653 | READ32(open->op_createmode); |
| 654 | switch (open->op_createmode) { |
| 655 | case NFS4_CREATE_UNCHECKED: |
| 656 | case NFS4_CREATE_GUARDED: |
| 657 | if ((status = nfsd4_decode_fattr(argp, open->op_bmval, &open->op_iattr, &open->op_acl))) |
| 658 | goto out; |
| 659 | break; |
| 660 | case NFS4_CREATE_EXCLUSIVE: |
| 661 | READ_BUF(8); |
| 662 | COPYMEM(open->op_verf.data, 8); |
| 663 | break; |
| 664 | default: |
| 665 | goto xdr_error; |
| 666 | } |
| 667 | break; |
| 668 | default: |
| 669 | goto xdr_error; |
| 670 | } |
| 671 | |
| 672 | /* open_claim */ |
| 673 | READ_BUF(4); |
| 674 | READ32(open->op_claim_type); |
| 675 | switch (open->op_claim_type) { |
| 676 | case NFS4_OPEN_CLAIM_NULL: |
| 677 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 678 | READ_BUF(4); |
| 679 | READ32(open->op_fname.len); |
| 680 | READ_BUF(open->op_fname.len); |
| 681 | SAVEMEM(open->op_fname.data, open->op_fname.len); |
| 682 | if ((status = check_filename(open->op_fname.data, open->op_fname.len, nfserr_inval))) |
| 683 | return status; |
| 684 | break; |
| 685 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 686 | READ_BUF(4); |
| 687 | READ32(open->op_delegate_type); |
| 688 | break; |
| 689 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 690 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); |
| 691 | if (status) |
| 692 | return status; |
| 693 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | READ32(open->op_fname.len); |
| 695 | READ_BUF(open->op_fname.len); |
| 696 | SAVEMEM(open->op_fname.data, open->op_fname.len); |
| 697 | if ((status = check_filename(open->op_fname.data, open->op_fname.len, nfserr_inval))) |
| 698 | return status; |
| 699 | break; |
| 700 | default: |
| 701 | goto xdr_error; |
| 702 | } |
| 703 | |
| 704 | DECODE_TAIL; |
| 705 | } |
| 706 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 707 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
| 709 | { |
| 710 | DECODE_HEAD; |
| 711 | |
| 712 | open_conf->oc_stateowner = NULL; |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 713 | status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid); |
| 714 | if (status) |
| 715 | return status; |
| 716 | READ_BUF(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | READ32(open_conf->oc_seqid); |
| 718 | |
| 719 | DECODE_TAIL; |
| 720 | } |
| 721 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 722 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
| 724 | { |
| 725 | DECODE_HEAD; |
| 726 | |
| 727 | open_down->od_stateowner = NULL; |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 728 | status = nfsd4_decode_stateid(argp, &open_down->od_stateid); |
| 729 | if (status) |
| 730 | return status; |
| 731 | READ_BUF(12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | READ32(open_down->od_seqid); |
| 733 | READ32(open_down->od_share_access); |
| 734 | READ32(open_down->od_share_deny); |
| 735 | |
| 736 | DECODE_TAIL; |
| 737 | } |
| 738 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 739 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
| 741 | { |
| 742 | DECODE_HEAD; |
| 743 | |
| 744 | READ_BUF(4); |
| 745 | READ32(putfh->pf_fhlen); |
| 746 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
| 747 | goto xdr_error; |
| 748 | READ_BUF(putfh->pf_fhlen); |
| 749 | SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen); |
| 750 | |
| 751 | DECODE_TAIL; |
| 752 | } |
| 753 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 754 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
| 756 | { |
| 757 | DECODE_HEAD; |
| 758 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 759 | status = nfsd4_decode_stateid(argp, &read->rd_stateid); |
| 760 | if (status) |
| 761 | return status; |
| 762 | READ_BUF(12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | READ64(read->rd_offset); |
| 764 | READ32(read->rd_length); |
| 765 | |
| 766 | DECODE_TAIL; |
| 767 | } |
| 768 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 769 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
| 771 | { |
| 772 | DECODE_HEAD; |
| 773 | |
| 774 | READ_BUF(24); |
| 775 | READ64(readdir->rd_cookie); |
| 776 | COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data)); |
| 777 | READ32(readdir->rd_dircount); /* just in case you needed a useless field... */ |
| 778 | READ32(readdir->rd_maxcount); |
| 779 | if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval))) |
| 780 | goto out; |
| 781 | |
| 782 | DECODE_TAIL; |
| 783 | } |
| 784 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 785 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
| 787 | { |
| 788 | DECODE_HEAD; |
| 789 | |
| 790 | READ_BUF(4); |
| 791 | READ32(remove->rm_namelen); |
| 792 | READ_BUF(remove->rm_namelen); |
| 793 | SAVEMEM(remove->rm_name, remove->rm_namelen); |
| 794 | if ((status = check_filename(remove->rm_name, remove->rm_namelen, nfserr_noent))) |
| 795 | return status; |
| 796 | |
| 797 | DECODE_TAIL; |
| 798 | } |
| 799 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 800 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
| 802 | { |
| 803 | DECODE_HEAD; |
| 804 | |
| 805 | READ_BUF(4); |
| 806 | READ32(rename->rn_snamelen); |
| 807 | READ_BUF(rename->rn_snamelen + 4); |
| 808 | SAVEMEM(rename->rn_sname, rename->rn_snamelen); |
| 809 | READ32(rename->rn_tnamelen); |
| 810 | READ_BUF(rename->rn_tnamelen); |
| 811 | SAVEMEM(rename->rn_tname, rename->rn_tnamelen); |
| 812 | if ((status = check_filename(rename->rn_sname, rename->rn_snamelen, nfserr_noent))) |
| 813 | return status; |
| 814 | if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen, nfserr_inval))) |
| 815 | return status; |
| 816 | |
| 817 | DECODE_TAIL; |
| 818 | } |
| 819 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 820 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 822 | { |
| 823 | DECODE_HEAD; |
| 824 | |
| 825 | READ_BUF(sizeof(clientid_t)); |
| 826 | COPYMEM(clientid, sizeof(clientid_t)); |
| 827 | |
| 828 | DECODE_TAIL; |
| 829 | } |
| 830 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 831 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 832 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, |
| 833 | struct nfsd4_secinfo *secinfo) |
| 834 | { |
| 835 | DECODE_HEAD; |
| 836 | |
| 837 | READ_BUF(4); |
| 838 | READ32(secinfo->si_namelen); |
| 839 | READ_BUF(secinfo->si_namelen); |
| 840 | SAVEMEM(secinfo->si_name, secinfo->si_namelen); |
| 841 | status = check_filename(secinfo->si_name, secinfo->si_namelen, |
| 842 | nfserr_noent); |
| 843 | if (status) |
| 844 | return status; |
| 845 | DECODE_TAIL; |
| 846 | } |
| 847 | |
| 848 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
| 850 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 851 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 853 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); |
| 854 | if (status) |
| 855 | return status; |
| 856 | return nfsd4_decode_fattr(argp, setattr->sa_bmval, |
| 857 | &setattr->sa_iattr, &setattr->sa_acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 860 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
| 862 | { |
| 863 | DECODE_HEAD; |
| 864 | |
| 865 | READ_BUF(12); |
| 866 | COPYMEM(setclientid->se_verf.data, 8); |
| 867 | READ32(setclientid->se_namelen); |
| 868 | |
| 869 | READ_BUF(setclientid->se_namelen + 8); |
| 870 | SAVEMEM(setclientid->se_name, setclientid->se_namelen); |
| 871 | READ32(setclientid->se_callback_prog); |
| 872 | READ32(setclientid->se_callback_netid_len); |
| 873 | |
| 874 | READ_BUF(setclientid->se_callback_netid_len + 4); |
| 875 | SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len); |
| 876 | READ32(setclientid->se_callback_addr_len); |
| 877 | |
| 878 | READ_BUF(setclientid->se_callback_addr_len + 4); |
| 879 | SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len); |
| 880 | READ32(setclientid->se_callback_ident); |
| 881 | |
| 882 | DECODE_TAIL; |
| 883 | } |
| 884 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 885 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
| 887 | { |
| 888 | DECODE_HEAD; |
| 889 | |
| 890 | READ_BUF(8 + sizeof(nfs4_verifier)); |
| 891 | COPYMEM(&scd_c->sc_clientid, 8); |
| 892 | COPYMEM(&scd_c->sc_confirm, sizeof(nfs4_verifier)); |
| 893 | |
| 894 | DECODE_TAIL; |
| 895 | } |
| 896 | |
| 897 | /* Also used for NVERIFY */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 898 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
| 900 | { |
| 901 | #if 0 |
| 902 | struct nfsd4_compoundargs save = { |
| 903 | .p = argp->p, |
| 904 | .end = argp->end, |
| 905 | .rqstp = argp->rqstp, |
| 906 | }; |
| 907 | u32 ve_bmval[2]; |
| 908 | struct iattr ve_iattr; /* request */ |
| 909 | struct nfs4_acl *ve_acl; /* request */ |
| 910 | #endif |
| 911 | DECODE_HEAD; |
| 912 | |
| 913 | if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval))) |
| 914 | goto out; |
| 915 | |
| 916 | /* For convenience's sake, we compare raw xdr'd attributes in |
| 917 | * nfsd4_proc_verify; however we still decode here just to return |
| 918 | * correct error in case of bad xdr. */ |
| 919 | #if 0 |
| 920 | status = nfsd4_decode_fattr(ve_bmval, &ve_iattr, &ve_acl); |
| 921 | if (status == nfserr_inval) { |
| 922 | status = nfserrno(status); |
| 923 | goto out; |
| 924 | } |
| 925 | #endif |
| 926 | READ_BUF(4); |
| 927 | READ32(verify->ve_attrlen); |
| 928 | READ_BUF(verify->ve_attrlen); |
| 929 | SAVEMEM(verify->ve_attrval, verify->ve_attrlen); |
| 930 | |
| 931 | DECODE_TAIL; |
| 932 | } |
| 933 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 934 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
| 936 | { |
| 937 | int avail; |
| 938 | int v; |
| 939 | int len; |
| 940 | DECODE_HEAD; |
| 941 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 942 | status = nfsd4_decode_stateid(argp, &write->wr_stateid); |
| 943 | if (status) |
| 944 | return status; |
| 945 | READ_BUF(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | READ64(write->wr_offset); |
| 947 | READ32(write->wr_stable_how); |
| 948 | if (write->wr_stable_how > 2) |
| 949 | goto xdr_error; |
| 950 | READ32(write->wr_buflen); |
| 951 | |
| 952 | /* Sorry .. no magic macros for this.. * |
| 953 | * READ_BUF(write->wr_buflen); |
| 954 | * SAVEMEM(write->wr_buf, write->wr_buflen); |
| 955 | */ |
| 956 | avail = (char*)argp->end - (char*)argp->p; |
| 957 | if (avail + argp->pagelen < write->wr_buflen) { |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 958 | dprintk("NFSD: xdr error (%s:%d)\n", |
| 959 | __FILE__, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | goto xdr_error; |
| 961 | } |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 962 | argp->rqstp->rq_vec[0].iov_base = p; |
| 963 | argp->rqstp->rq_vec[0].iov_len = avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | v = 0; |
| 965 | len = write->wr_buflen; |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 966 | while (len > argp->rqstp->rq_vec[v].iov_len) { |
| 967 | len -= argp->rqstp->rq_vec[v].iov_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | v++; |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 969 | argp->rqstp->rq_vec[v].iov_base = page_address(argp->pagelist[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | argp->pagelist++; |
| 971 | if (argp->pagelen >= PAGE_SIZE) { |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 972 | argp->rqstp->rq_vec[v].iov_len = PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | argp->pagelen -= PAGE_SIZE; |
| 974 | } else { |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 975 | argp->rqstp->rq_vec[v].iov_len = argp->pagelen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | argp->pagelen -= len; |
| 977 | } |
| 978 | } |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 979 | argp->end = (__be32*) (argp->rqstp->rq_vec[v].iov_base + argp->rqstp->rq_vec[v].iov_len); |
| 980 | argp->p = (__be32*) (argp->rqstp->rq_vec[v].iov_base + (XDR_QUADLEN(len) << 2)); |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 981 | argp->rqstp->rq_vec[v].iov_len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | write->wr_vlen = v+1; |
| 983 | |
| 984 | DECODE_TAIL; |
| 985 | } |
| 986 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 987 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
| 989 | { |
| 990 | DECODE_HEAD; |
| 991 | |
| 992 | READ_BUF(12); |
| 993 | COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t)); |
| 994 | READ32(rlockowner->rl_owner.len); |
| 995 | READ_BUF(rlockowner->rl_owner.len); |
| 996 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); |
| 997 | |
| 998 | DECODE_TAIL; |
| 999 | } |
| 1000 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1001 | static __be32 |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1002 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) |
| 1003 | { |
| 1004 | return nfs_ok; |
| 1005 | } |
| 1006 | |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 1007 | static __be32 |
| 1008 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
| 1009 | { |
| 1010 | return nfserr_opnotsupp; |
| 1011 | } |
| 1012 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1013 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
| 1014 | |
| 1015 | static nfsd4_dec nfsd4_dec_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 1016 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
| 1017 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, |
| 1018 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, |
| 1019 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, |
| 1020 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1021 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, |
| 1022 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, |
| 1023 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1024 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, |
| 1025 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, |
| 1026 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, |
| 1027 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, |
| 1028 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, |
| 1029 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, |
| 1030 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 1031 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, |
| 1032 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1033 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
| 1034 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
| 1035 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
| 1036 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 1037 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1038 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
| 1039 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
| 1040 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, |
| 1041 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, |
| 1042 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, |
| 1043 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, |
| 1044 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1045 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 1046 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, |
| 1047 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, |
| 1048 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, |
| 1049 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, |
| 1050 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 1051 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, |
| 1052 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1053 | }; |
| 1054 | |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 1055 | struct nfsd4_minorversion_ops { |
| 1056 | nfsd4_dec *decoders; |
| 1057 | int nops; |
| 1058 | }; |
| 1059 | |
| 1060 | static struct nfsd4_minorversion_ops nfsd4_minorversion[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 1061 | [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) }, |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 1062 | }; |
| 1063 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1064 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
| 1066 | { |
| 1067 | DECODE_HEAD; |
| 1068 | struct nfsd4_op *op; |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 1069 | struct nfsd4_minorversion_ops *ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | int i; |
| 1071 | |
| 1072 | /* |
| 1073 | * XXX: According to spec, we should check the tag |
| 1074 | * for UTF-8 compliance. I'm postponing this for |
| 1075 | * now because it seems that some clients do use |
| 1076 | * binary tags. |
| 1077 | */ |
| 1078 | READ_BUF(4); |
| 1079 | READ32(argp->taglen); |
| 1080 | READ_BUF(argp->taglen + 8); |
| 1081 | SAVEMEM(argp->tag, argp->taglen); |
| 1082 | READ32(argp->minorversion); |
| 1083 | READ32(argp->opcnt); |
| 1084 | |
| 1085 | if (argp->taglen > NFSD4_MAX_TAGLEN) |
| 1086 | goto xdr_error; |
| 1087 | if (argp->opcnt > 100) |
| 1088 | goto xdr_error; |
| 1089 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 1090 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
| 1092 | if (!argp->ops) { |
| 1093 | argp->ops = argp->iops; |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 1094 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | goto xdr_error; |
| 1096 | } |
| 1097 | } |
| 1098 | |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 1099 | if (argp->minorversion >= ARRAY_SIZE(nfsd4_minorversion)) |
Benny Halevy | 30cff1f | 2008-07-02 11:13:18 +0300 | [diff] [blame] | 1100 | argp->opcnt = 0; |
| 1101 | |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 1102 | ops = &nfsd4_minorversion[argp->minorversion]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | for (i = 0; i < argp->opcnt; i++) { |
| 1104 | op = &argp->ops[i]; |
| 1105 | op->replay = NULL; |
| 1106 | |
| 1107 | /* |
| 1108 | * We can't use READ_BUF() here because we need to handle |
| 1109 | * a missing opcode as an OP_WRITE + 1. So we need to check |
| 1110 | * to see if we're truly at the end of our buffer or if there |
| 1111 | * is another page we need to flip to. |
| 1112 | */ |
| 1113 | |
| 1114 | if (argp->p == argp->end) { |
| 1115 | if (argp->pagelen < 4) { |
| 1116 | /* There isn't an opcode still on the wire */ |
| 1117 | op->opnum = OP_WRITE + 1; |
| 1118 | op->status = nfserr_bad_xdr; |
| 1119 | argp->opcnt = i+1; |
| 1120 | break; |
| 1121 | } |
| 1122 | |
| 1123 | /* |
| 1124 | * False alarm. We just hit a page boundary, but there |
| 1125 | * is still data available. Move pointer across page |
| 1126 | * boundary. *snip from READ_BUF* |
| 1127 | */ |
| 1128 | argp->p = page_address(argp->pagelist[0]); |
| 1129 | argp->pagelist++; |
| 1130 | if (argp->pagelen < PAGE_SIZE) { |
| 1131 | argp->end = p + (argp->pagelen>>2); |
| 1132 | argp->pagelen = 0; |
| 1133 | } else { |
| 1134 | argp->end = p + (PAGE_SIZE>>2); |
| 1135 | argp->pagelen -= PAGE_SIZE; |
| 1136 | } |
| 1137 | } |
| 1138 | op->opnum = ntohl(*argp->p++); |
| 1139 | |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 1140 | if (op->opnum >= OP_ACCESS && op->opnum < ops->nops) |
| 1141 | op->status = ops->decoders[op->opnum](argp, &op->u); |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 1142 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | op->opnum = OP_ILLEGAL; |
| 1144 | op->status = nfserr_op_illegal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | if (op->status) { |
| 1148 | argp->opcnt = i+1; |
| 1149 | break; |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | DECODE_TAIL; |
| 1154 | } |
| 1155 | /* |
| 1156 | * END OF "GENERIC" DECODE ROUTINES. |
| 1157 | */ |
| 1158 | |
| 1159 | /* |
| 1160 | * START OF "GENERIC" ENCODE ROUTINES. |
| 1161 | * These may look a little ugly since they are imported from a "generic" |
| 1162 | * set of XDR encode/decode routines which are intended to be shared by |
| 1163 | * all of our NFSv4 implementations (OpenBSD, MacOS X...). |
| 1164 | * |
| 1165 | * If the pain of reading these is too great, it should be a straightforward |
| 1166 | * task to translate them into Linux-specific versions which are more |
| 1167 | * consistent with the style used in NFSv2/v3... |
| 1168 | */ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1169 | #define ENCODE_HEAD __be32 *p |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
| 1171 | #define WRITE32(n) *p++ = htonl(n) |
| 1172 | #define WRITE64(n) do { \ |
| 1173 | *p++ = htonl((u32)((n) >> 32)); \ |
| 1174 | *p++ = htonl((u32)(n)); \ |
| 1175 | } while (0) |
Harvey Harrison | 5108b27 | 2008-07-17 21:33:04 -0700 | [diff] [blame] | 1176 | #define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | *(p + XDR_QUADLEN(nbytes) -1) = 0; \ |
| 1178 | memcpy(p, ptr, nbytes); \ |
| 1179 | p += XDR_QUADLEN(nbytes); \ |
Harvey Harrison | 5108b27 | 2008-07-17 21:33:04 -0700 | [diff] [blame] | 1180 | }} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | #define WRITECINFO(c) do { \ |
| 1182 | *p++ = htonl(c.atomic); \ |
| 1183 | *p++ = htonl(c.before_ctime_sec); \ |
| 1184 | *p++ = htonl(c.before_ctime_nsec); \ |
| 1185 | *p++ = htonl(c.after_ctime_sec); \ |
| 1186 | *p++ = htonl(c.after_ctime_nsec); \ |
| 1187 | } while (0) |
| 1188 | |
| 1189 | #define RESERVE_SPACE(nbytes) do { \ |
| 1190 | p = resp->p; \ |
| 1191 | BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \ |
| 1192 | } while (0) |
| 1193 | #define ADJUST_ARGS() resp->p = p |
| 1194 | |
| 1195 | /* |
| 1196 | * Header routine to setup seqid operation replay cache |
| 1197 | */ |
| 1198 | #define ENCODE_SEQID_OP_HEAD \ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1199 | __be32 *save; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | \ |
| 1201 | save = resp->p; |
| 1202 | |
| 1203 | /* |
NeilBrown | 7fb64ce | 2005-07-07 17:59:20 -0700 | [diff] [blame] | 1204 | * Routine for encoding the result of a "seqid-mutating" NFSv4 operation. This |
| 1205 | * is where sequence id's are incremented, and the replay cache is filled. |
| 1206 | * Note that we increment sequence id's here, at the last moment, so we're sure |
| 1207 | * we know whether the error to be returned is a sequence id mutating error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | */ |
| 1209 | |
| 1210 | #define ENCODE_SEQID_OP_TAIL(stateowner) do { \ |
| 1211 | if (seqid_mutating_err(nfserr) && stateowner) { \ |
NeilBrown | bd9aac5 | 2005-07-07 17:59:19 -0700 | [diff] [blame] | 1212 | stateowner->so_seqid++; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | stateowner->so_replay.rp_status = nfserr; \ |
| 1214 | stateowner->so_replay.rp_buflen = \ |
| 1215 | (((char *)(resp)->p - (char *)save)); \ |
| 1216 | memcpy(stateowner->so_replay.rp_buf, save, \ |
| 1217 | stateowner->so_replay.rp_buflen); \ |
| 1218 | } } while (0); |
| 1219 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1220 | /* Encode as an array of strings the string given with components |
| 1221 | * seperated @sep. |
| 1222 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1223 | static __be32 nfsd4_encode_components(char sep, char *components, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1224 | __be32 **pp, int *buflen) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1225 | { |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1226 | __be32 *p = *pp; |
| 1227 | __be32 *countp = p; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1228 | int strlen, count=0; |
| 1229 | char *str, *end; |
| 1230 | |
| 1231 | dprintk("nfsd4_encode_components(%s)\n", components); |
| 1232 | if ((*buflen -= 4) < 0) |
| 1233 | return nfserr_resource; |
| 1234 | WRITE32(0); /* We will fill this in with @count later */ |
| 1235 | end = str = components; |
| 1236 | while (*end) { |
| 1237 | for (; *end && (*end != sep); end++) |
| 1238 | ; /* Point to end of component */ |
| 1239 | strlen = end - str; |
| 1240 | if (strlen) { |
| 1241 | if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0) |
| 1242 | return nfserr_resource; |
| 1243 | WRITE32(strlen); |
| 1244 | WRITEMEM(str, strlen); |
| 1245 | count++; |
| 1246 | } |
| 1247 | else |
| 1248 | end++; |
| 1249 | str = end; |
| 1250 | } |
| 1251 | *pp = p; |
| 1252 | p = countp; |
| 1253 | WRITE32(count); |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | /* |
| 1258 | * encode a location element of a fs_locations structure |
| 1259 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1260 | static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1261 | __be32 **pp, int *buflen) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1262 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1263 | __be32 status; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1264 | __be32 *p = *pp; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1265 | |
| 1266 | status = nfsd4_encode_components(':', location->hosts, &p, buflen); |
| 1267 | if (status) |
| 1268 | return status; |
| 1269 | status = nfsd4_encode_components('/', location->path, &p, buflen); |
| 1270 | if (status) |
| 1271 | return status; |
| 1272 | *pp = p; |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * Return the path to an export point in the pseudo filesystem namespace |
| 1278 | * Returned string is safe to use as long as the caller holds a reference |
| 1279 | * to @exp. |
| 1280 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1281 | static char *nfsd4_path(struct svc_rqst *rqstp, struct svc_export *exp, __be32 *stat) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1282 | { |
| 1283 | struct svc_fh tmp_fh; |
| 1284 | char *path, *rootpath; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1285 | |
| 1286 | fh_init(&tmp_fh, NFS4_FHSIZE); |
J. Bruce Fields | df547ef | 2007-07-17 04:04:43 -0700 | [diff] [blame] | 1287 | *stat = exp_pseudoroot(rqstp, &tmp_fh); |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 1288 | if (*stat) |
| 1289 | return NULL; |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 1290 | rootpath = tmp_fh.fh_export->ex_pathname; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1291 | |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 1292 | path = exp->ex_pathname; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1293 | |
| 1294 | if (strncmp(path, rootpath, strlen(rootpath))) { |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 1295 | dprintk("nfsd: fs_locations failed;" |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1296 | "%s is not contained in %s\n", path, rootpath); |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 1297 | *stat = nfserr_notsupp; |
| 1298 | return NULL; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | return path + strlen(rootpath); |
| 1302 | } |
| 1303 | |
| 1304 | /* |
| 1305 | * encode a fs_locations structure |
| 1306 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1307 | static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp, |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1308 | struct svc_export *exp, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1309 | __be32 **pp, int *buflen) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1310 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1311 | __be32 status; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 1312 | int i; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1313 | __be32 *p = *pp; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1314 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 1315 | char *root = nfsd4_path(rqstp, exp, &status); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1316 | |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 1317 | if (status) |
| 1318 | return status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1319 | status = nfsd4_encode_components('/', root, &p, buflen); |
| 1320 | if (status) |
| 1321 | return status; |
| 1322 | if ((*buflen -= 4) < 0) |
| 1323 | return nfserr_resource; |
| 1324 | WRITE32(fslocs->locations_count); |
| 1325 | for (i=0; i<fslocs->locations_count; i++) { |
| 1326 | status = nfsd4_encode_fs_location4(&fslocs->locations[i], |
| 1327 | &p, buflen); |
| 1328 | if (status) |
| 1329 | return status; |
| 1330 | } |
| 1331 | *pp = p; |
| 1332 | return 0; |
| 1333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | |
| 1335 | static u32 nfs4_ftypes[16] = { |
| 1336 | NF4BAD, NF4FIFO, NF4CHR, NF4BAD, |
| 1337 | NF4DIR, NF4BAD, NF4BLK, NF4BAD, |
| 1338 | NF4REG, NF4BAD, NF4LNK, NF4BAD, |
| 1339 | NF4SOCK, NF4BAD, NF4LNK, NF4BAD, |
| 1340 | }; |
| 1341 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1342 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, uid_t id, int group, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1344 | __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | { |
| 1346 | int status; |
| 1347 | |
| 1348 | if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4) |
| 1349 | return nfserr_resource; |
| 1350 | if (whotype != NFS4_ACL_WHO_NAMED) |
| 1351 | status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1)); |
| 1352 | else if (group) |
| 1353 | status = nfsd_map_gid_to_name(rqstp, id, (u8 *)(*p + 1)); |
| 1354 | else |
| 1355 | status = nfsd_map_uid_to_name(rqstp, id, (u8 *)(*p + 1)); |
| 1356 | if (status < 0) |
| 1357 | return nfserrno(status); |
| 1358 | *p = xdr_encode_opaque(*p, NULL, status); |
| 1359 | *buflen -= (XDR_QUADLEN(status) << 2) + 4; |
| 1360 | BUG_ON(*buflen < 0); |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1364 | static inline __be32 |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1365 | nfsd4_encode_user(struct svc_rqst *rqstp, uid_t uid, __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | { |
| 1367 | return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, uid, 0, p, buflen); |
| 1368 | } |
| 1369 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1370 | static inline __be32 |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1371 | nfsd4_encode_group(struct svc_rqst *rqstp, uid_t gid, __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | { |
| 1373 | return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, gid, 1, p, buflen); |
| 1374 | } |
| 1375 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1376 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | nfsd4_encode_aclname(struct svc_rqst *rqstp, int whotype, uid_t id, int group, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1378 | __be32 **p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | { |
| 1380 | return nfsd4_encode_name(rqstp, whotype, id, group, p, buflen); |
| 1381 | } |
| 1382 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1383 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
| 1384 | FATTR4_WORD0_RDATTR_ERROR) |
| 1385 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID |
| 1386 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1387 | 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] | 1388 | { |
| 1389 | /* As per referral draft: */ |
| 1390 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || |
| 1391 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { |
| 1392 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || |
| 1393 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) |
| 1394 | *rdattr_err = NFSERR_MOVED; |
| 1395 | else |
| 1396 | return nfserr_moved; |
| 1397 | } |
| 1398 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; |
| 1399 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; |
| 1400 | return 0; |
| 1401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
| 1403 | /* |
| 1404 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle |
| 1405 | * ourselves. |
| 1406 | * |
| 1407 | * @countp is the buffer size in _words_; upon successful return this becomes |
| 1408 | * replaced with the number of words written. |
| 1409 | */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1410 | __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1412 | struct dentry *dentry, __be32 *buffer, int *countp, u32 *bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 1413 | struct svc_rqst *rqstp, int ignore_crossmnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | { |
| 1415 | u32 bmval0 = bmval[0]; |
| 1416 | u32 bmval1 = bmval[1]; |
| 1417 | struct kstat stat; |
| 1418 | struct svc_fh tempfh; |
| 1419 | struct kstatfs statfs; |
| 1420 | int buflen = *countp << 2; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1421 | __be32 *attrlenp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | u32 dummy; |
| 1423 | u64 dummy64; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1424 | u32 rdattr_err = 0; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1425 | __be32 *p = buffer; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1426 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1427 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | int aclsupport = 0; |
| 1429 | struct nfs4_acl *acl = NULL; |
| 1430 | |
| 1431 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
| 1432 | BUG_ON(bmval0 & ~NFSD_SUPPORTED_ATTRS_WORD0); |
| 1433 | BUG_ON(bmval1 & ~NFSD_SUPPORTED_ATTRS_WORD1); |
| 1434 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1435 | if (exp->ex_fslocs.migrated) { |
| 1436 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err); |
| 1437 | if (status) |
| 1438 | goto out; |
| 1439 | } |
| 1440 | |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 1441 | err = vfs_getattr(exp->ex_path.mnt, dentry, &stat); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1442 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | goto out_nfserr; |
J. Bruce Fields | a16e92e | 2007-09-28 16:45:51 -0400 | [diff] [blame] | 1444 | if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | |
| 1445 | FATTR4_WORD0_MAXNAME)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
| 1447 | FATTR4_WORD1_SPACE_TOTAL))) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1448 | err = vfs_statfs(dentry, &statfs); |
| 1449 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | goto out_nfserr; |
| 1451 | } |
| 1452 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { |
| 1453 | fh_init(&tempfh, NFS4_FHSIZE); |
| 1454 | status = fh_compose(&tempfh, exp, dentry, NULL); |
| 1455 | if (status) |
| 1456 | goto out; |
| 1457 | fhp = &tempfh; |
| 1458 | } |
| 1459 | if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT |
| 1460 | | FATTR4_WORD0_SUPPORTED_ATTRS)) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1461 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
| 1462 | aclsupport = (err == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | if (bmval0 & FATTR4_WORD0_ACL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1464 | if (err == -EOPNOTSUPP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | bmval0 &= ~FATTR4_WORD0_ACL; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1466 | else if (err == -EINVAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | status = nfserr_attrnotsupp; |
| 1468 | goto out; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1469 | } else if (err != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | goto out_nfserr; |
| 1471 | } |
| 1472 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1473 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
| 1474 | if (exp->ex_fslocs.locations == NULL) { |
| 1475 | bmval0 &= ~FATTR4_WORD0_FS_LOCATIONS; |
| 1476 | } |
| 1477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | if ((buflen -= 16) < 0) |
| 1479 | goto out_resource; |
| 1480 | |
| 1481 | WRITE32(2); |
| 1482 | WRITE32(bmval0); |
| 1483 | WRITE32(bmval1); |
| 1484 | attrlenp = p++; /* to be backfilled later */ |
| 1485 | |
| 1486 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1487 | u32 word0 = NFSD_SUPPORTED_ATTRS_WORD0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | if ((buflen -= 12) < 0) |
| 1489 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1490 | if (!aclsupport) |
| 1491 | word0 &= ~FATTR4_WORD0_ACL; |
| 1492 | if (!exp->ex_fslocs.locations) |
| 1493 | word0 &= ~FATTR4_WORD0_FS_LOCATIONS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | WRITE32(2); |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1495 | WRITE32(word0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | WRITE32(NFSD_SUPPORTED_ATTRS_WORD1); |
| 1497 | } |
| 1498 | if (bmval0 & FATTR4_WORD0_TYPE) { |
| 1499 | if ((buflen -= 4) < 0) |
| 1500 | goto out_resource; |
| 1501 | dummy = nfs4_ftypes[(stat.mode & S_IFMT) >> 12]; |
| 1502 | if (dummy == NF4BAD) |
| 1503 | goto out_serverfault; |
| 1504 | WRITE32(dummy); |
| 1505 | } |
| 1506 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { |
| 1507 | if ((buflen -= 4) < 0) |
| 1508 | goto out_resource; |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 1509 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
NeilBrown | e34ac86 | 2005-07-07 17:59:30 -0700 | [diff] [blame] | 1510 | WRITE32(NFS4_FH_PERSISTENT); |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 1511 | else |
NeilBrown | e34ac86 | 2005-07-07 17:59:30 -0700 | [diff] [blame] | 1512 | WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | } |
| 1514 | if (bmval0 & FATTR4_WORD0_CHANGE) { |
| 1515 | /* |
| 1516 | * Note: This _must_ be consistent with the scheme for writing |
| 1517 | * change_info, so any changes made here must be reflected there |
| 1518 | * as well. (See xdr4.h:set_change_info() and the WRITECINFO() |
| 1519 | * macro above.) |
| 1520 | */ |
| 1521 | if ((buflen -= 8) < 0) |
| 1522 | goto out_resource; |
| 1523 | WRITE32(stat.ctime.tv_sec); |
| 1524 | WRITE32(stat.ctime.tv_nsec); |
| 1525 | } |
| 1526 | if (bmval0 & FATTR4_WORD0_SIZE) { |
| 1527 | if ((buflen -= 8) < 0) |
| 1528 | goto out_resource; |
| 1529 | WRITE64(stat.size); |
| 1530 | } |
| 1531 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { |
| 1532 | if ((buflen -= 4) < 0) |
| 1533 | goto out_resource; |
| 1534 | WRITE32(1); |
| 1535 | } |
| 1536 | if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) { |
| 1537 | if ((buflen -= 4) < 0) |
| 1538 | goto out_resource; |
| 1539 | WRITE32(1); |
| 1540 | } |
| 1541 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { |
| 1542 | if ((buflen -= 4) < 0) |
| 1543 | goto out_resource; |
| 1544 | WRITE32(0); |
| 1545 | } |
| 1546 | if (bmval0 & FATTR4_WORD0_FSID) { |
| 1547 | if ((buflen -= 16) < 0) |
| 1548 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1549 | if (exp->ex_fslocs.migrated) { |
| 1550 | WRITE64(NFS4_REFERRAL_FSID_MAJOR); |
| 1551 | WRITE64(NFS4_REFERRAL_FSID_MINOR); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 1552 | } else switch(fsid_source(fhp)) { |
| 1553 | case FSIDSOURCE_FSID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | WRITE64((u64)exp->ex_fsid); |
| 1555 | WRITE64((u64)0); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 1556 | break; |
| 1557 | case FSIDSOURCE_DEV: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | WRITE32(0); |
| 1559 | WRITE32(MAJOR(stat.dev)); |
| 1560 | WRITE32(0); |
| 1561 | WRITE32(MINOR(stat.dev)); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 1562 | break; |
| 1563 | case FSIDSOURCE_UUID: |
| 1564 | WRITEMEM(exp->ex_uuid, 16); |
| 1565 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { |
| 1569 | if ((buflen -= 4) < 0) |
| 1570 | goto out_resource; |
| 1571 | WRITE32(0); |
| 1572 | } |
| 1573 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { |
| 1574 | if ((buflen -= 4) < 0) |
| 1575 | goto out_resource; |
| 1576 | WRITE32(NFSD_LEASE_TIME); |
| 1577 | } |
| 1578 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { |
| 1579 | if ((buflen -= 4) < 0) |
| 1580 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 1581 | WRITE32(rdattr_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | if (bmval0 & FATTR4_WORD0_ACL) { |
| 1584 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | |
| 1586 | if (acl == NULL) { |
| 1587 | if ((buflen -= 4) < 0) |
| 1588 | goto out_resource; |
| 1589 | |
| 1590 | WRITE32(0); |
| 1591 | goto out_acl; |
| 1592 | } |
| 1593 | if ((buflen -= 4) < 0) |
| 1594 | goto out_resource; |
| 1595 | WRITE32(acl->naces); |
| 1596 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 1597 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | if ((buflen -= 4*3) < 0) |
| 1599 | goto out_resource; |
| 1600 | WRITE32(ace->type); |
| 1601 | WRITE32(ace->flag); |
| 1602 | WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL); |
| 1603 | status = nfsd4_encode_aclname(rqstp, ace->whotype, |
| 1604 | ace->who, ace->flag & NFS4_ACE_IDENTIFIER_GROUP, |
| 1605 | &p, &buflen); |
| 1606 | if (status == nfserr_resource) |
| 1607 | goto out_resource; |
| 1608 | if (status) |
| 1609 | goto out; |
| 1610 | } |
| 1611 | } |
| 1612 | out_acl: |
| 1613 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { |
| 1614 | if ((buflen -= 4) < 0) |
| 1615 | goto out_resource; |
| 1616 | WRITE32(aclsupport ? |
| 1617 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
| 1618 | } |
| 1619 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { |
| 1620 | if ((buflen -= 4) < 0) |
| 1621 | goto out_resource; |
| 1622 | WRITE32(1); |
| 1623 | } |
| 1624 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { |
| 1625 | if ((buflen -= 4) < 0) |
| 1626 | goto out_resource; |
| 1627 | WRITE32(1); |
| 1628 | } |
| 1629 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { |
| 1630 | if ((buflen -= 4) < 0) |
| 1631 | goto out_resource; |
| 1632 | WRITE32(1); |
| 1633 | } |
| 1634 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { |
| 1635 | if ((buflen -= 4) < 0) |
| 1636 | goto out_resource; |
| 1637 | WRITE32(1); |
| 1638 | } |
| 1639 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { |
| 1640 | buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4; |
| 1641 | if (buflen < 0) |
| 1642 | goto out_resource; |
| 1643 | WRITE32(fhp->fh_handle.fh_size); |
| 1644 | WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size); |
| 1645 | } |
| 1646 | if (bmval0 & FATTR4_WORD0_FILEID) { |
| 1647 | if ((buflen -= 8) < 0) |
| 1648 | goto out_resource; |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 1649 | WRITE64(stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | } |
| 1651 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { |
| 1652 | if ((buflen -= 8) < 0) |
| 1653 | goto out_resource; |
| 1654 | WRITE64((u64) statfs.f_ffree); |
| 1655 | } |
| 1656 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { |
| 1657 | if ((buflen -= 8) < 0) |
| 1658 | goto out_resource; |
| 1659 | WRITE64((u64) statfs.f_ffree); |
| 1660 | } |
| 1661 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { |
| 1662 | if ((buflen -= 8) < 0) |
| 1663 | goto out_resource; |
| 1664 | WRITE64((u64) statfs.f_files); |
| 1665 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 1666 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
| 1667 | status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen); |
| 1668 | if (status == nfserr_resource) |
| 1669 | goto out_resource; |
| 1670 | if (status) |
| 1671 | goto out; |
| 1672 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
| 1674 | if ((buflen -= 4) < 0) |
| 1675 | goto out_resource; |
| 1676 | WRITE32(1); |
| 1677 | } |
| 1678 | if (bmval0 & FATTR4_WORD0_MAXFILESIZE) { |
| 1679 | if ((buflen -= 8) < 0) |
| 1680 | goto out_resource; |
| 1681 | WRITE64(~(u64)0); |
| 1682 | } |
| 1683 | if (bmval0 & FATTR4_WORD0_MAXLINK) { |
| 1684 | if ((buflen -= 4) < 0) |
| 1685 | goto out_resource; |
| 1686 | WRITE32(255); |
| 1687 | } |
| 1688 | if (bmval0 & FATTR4_WORD0_MAXNAME) { |
| 1689 | if ((buflen -= 4) < 0) |
| 1690 | goto out_resource; |
J. Bruce Fields | a16e92e | 2007-09-28 16:45:51 -0400 | [diff] [blame] | 1691 | WRITE32(statfs.f_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | } |
| 1693 | if (bmval0 & FATTR4_WORD0_MAXREAD) { |
| 1694 | if ((buflen -= 8) < 0) |
| 1695 | goto out_resource; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 1696 | WRITE64((u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | } |
| 1698 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { |
| 1699 | if ((buflen -= 8) < 0) |
| 1700 | goto out_resource; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 1701 | WRITE64((u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | } |
| 1703 | if (bmval1 & FATTR4_WORD1_MODE) { |
| 1704 | if ((buflen -= 4) < 0) |
| 1705 | goto out_resource; |
| 1706 | WRITE32(stat.mode & S_IALLUGO); |
| 1707 | } |
| 1708 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { |
| 1709 | if ((buflen -= 4) < 0) |
| 1710 | goto out_resource; |
| 1711 | WRITE32(1); |
| 1712 | } |
| 1713 | if (bmval1 & FATTR4_WORD1_NUMLINKS) { |
| 1714 | if ((buflen -= 4) < 0) |
| 1715 | goto out_resource; |
| 1716 | WRITE32(stat.nlink); |
| 1717 | } |
| 1718 | if (bmval1 & FATTR4_WORD1_OWNER) { |
| 1719 | status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen); |
| 1720 | if (status == nfserr_resource) |
| 1721 | goto out_resource; |
| 1722 | if (status) |
| 1723 | goto out; |
| 1724 | } |
| 1725 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { |
| 1726 | status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen); |
| 1727 | if (status == nfserr_resource) |
| 1728 | goto out_resource; |
| 1729 | if (status) |
| 1730 | goto out; |
| 1731 | } |
| 1732 | if (bmval1 & FATTR4_WORD1_RAWDEV) { |
| 1733 | if ((buflen -= 8) < 0) |
| 1734 | goto out_resource; |
| 1735 | WRITE32((u32) MAJOR(stat.rdev)); |
| 1736 | WRITE32((u32) MINOR(stat.rdev)); |
| 1737 | } |
| 1738 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { |
| 1739 | if ((buflen -= 8) < 0) |
| 1740 | goto out_resource; |
| 1741 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; |
| 1742 | WRITE64(dummy64); |
| 1743 | } |
| 1744 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { |
| 1745 | if ((buflen -= 8) < 0) |
| 1746 | goto out_resource; |
| 1747 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; |
| 1748 | WRITE64(dummy64); |
| 1749 | } |
| 1750 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { |
| 1751 | if ((buflen -= 8) < 0) |
| 1752 | goto out_resource; |
| 1753 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; |
| 1754 | WRITE64(dummy64); |
| 1755 | } |
| 1756 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { |
| 1757 | if ((buflen -= 8) < 0) |
| 1758 | goto out_resource; |
| 1759 | dummy64 = (u64)stat.blocks << 9; |
| 1760 | WRITE64(dummy64); |
| 1761 | } |
| 1762 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { |
| 1763 | if ((buflen -= 12) < 0) |
| 1764 | goto out_resource; |
| 1765 | WRITE32(0); |
| 1766 | WRITE32(stat.atime.tv_sec); |
| 1767 | WRITE32(stat.atime.tv_nsec); |
| 1768 | } |
| 1769 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { |
| 1770 | if ((buflen -= 12) < 0) |
| 1771 | goto out_resource; |
| 1772 | WRITE32(0); |
| 1773 | WRITE32(1); |
| 1774 | WRITE32(0); |
| 1775 | } |
| 1776 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { |
| 1777 | if ((buflen -= 12) < 0) |
| 1778 | goto out_resource; |
| 1779 | WRITE32(0); |
| 1780 | WRITE32(stat.ctime.tv_sec); |
| 1781 | WRITE32(stat.ctime.tv_nsec); |
| 1782 | } |
| 1783 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { |
| 1784 | if ((buflen -= 12) < 0) |
| 1785 | goto out_resource; |
| 1786 | WRITE32(0); |
| 1787 | WRITE32(stat.mtime.tv_sec); |
| 1788 | WRITE32(stat.mtime.tv_nsec); |
| 1789 | } |
| 1790 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | if ((buflen -= 8) < 0) |
| 1792 | goto out_resource; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 1793 | /* |
| 1794 | * Get parent's attributes if not ignoring crossmount |
| 1795 | * and this is the root of a cross-mounted filesystem. |
| 1796 | */ |
| 1797 | if (ignore_crossmnt == 0 && |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 1798 | exp->ex_path.mnt->mnt_root->d_inode == dentry->d_inode) { |
| 1799 | err = vfs_getattr(exp->ex_path.mnt->mnt_parent, |
| 1800 | exp->ex_path.mnt->mnt_mountpoint, &stat); |
Peter Staubach | 40ee5dc | 2007-08-16 12:10:07 -0400 | [diff] [blame] | 1801 | if (err) |
| 1802 | goto out_nfserr; |
| 1803 | } |
| 1804 | WRITE64(stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | } |
| 1806 | *attrlenp = htonl((char *)p - (char *)attrlenp - 4); |
| 1807 | *countp = p - buffer; |
| 1808 | status = nfs_ok; |
| 1809 | |
| 1810 | out: |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 1811 | kfree(acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | if (fhp == &tempfh) |
| 1813 | fh_put(&tempfh); |
| 1814 | return status; |
| 1815 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 1816 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | goto out; |
| 1818 | out_resource: |
| 1819 | *countp = 0; |
| 1820 | status = nfserr_resource; |
| 1821 | goto out; |
| 1822 | out_serverfault: |
| 1823 | status = nfserr_serverfault; |
| 1824 | goto out; |
| 1825 | } |
| 1826 | |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 1827 | static inline int attributes_need_mount(u32 *bmval) |
| 1828 | { |
| 1829 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) |
| 1830 | return 1; |
| 1831 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 1832 | return 1; |
| 1833 | return 0; |
| 1834 | } |
| 1835 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1836 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd, |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1838 | const char *name, int namlen, __be32 *p, int *buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | { |
| 1840 | struct svc_export *exp = cd->rd_fhp->fh_export; |
| 1841 | struct dentry *dentry; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1842 | __be32 nfserr; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 1843 | int ignore_crossmnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
| 1845 | dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen); |
| 1846 | if (IS_ERR(dentry)) |
| 1847 | return nfserrno(PTR_ERR(dentry)); |
| 1848 | |
| 1849 | exp_get(exp); |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 1850 | /* |
| 1851 | * In the case of a mountpoint, the client may be asking for |
| 1852 | * attributes that are only properties of the underlying filesystem |
| 1853 | * as opposed to the cross-mounted file system. In such a case, |
| 1854 | * we will not follow the cross mount and will fill the attribtutes |
| 1855 | * directly from the mountpoint dentry. |
| 1856 | */ |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 1857 | if (d_mountpoint(dentry) && !attributes_need_mount(cd->rd_bmval)) |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 1858 | ignore_crossmnt = 1; |
| 1859 | else if (d_mountpoint(dentry)) { |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 1860 | int err; |
| 1861 | |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1862 | /* |
| 1863 | * Why the heck aren't we just using nfsd_lookup?? |
| 1864 | * Different "."/".." handling? Something else? |
| 1865 | * At least, add a comment here to explain.... |
| 1866 | */ |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 1867 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
| 1868 | if (err) { |
| 1869 | nfserr = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | goto out_put; |
| 1871 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1872 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
| 1873 | if (nfserr) |
| 1874 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | |
| 1876 | } |
| 1877 | nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 1878 | cd->rd_rqstp, ignore_crossmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | out_put: |
| 1880 | dput(dentry); |
| 1881 | exp_put(exp); |
| 1882 | return nfserr; |
| 1883 | } |
| 1884 | |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1885 | static __be32 * |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1886 | nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | { |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1888 | __be32 *attrlenp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
| 1890 | if (buflen < 6) |
| 1891 | return NULL; |
| 1892 | *p++ = htonl(2); |
| 1893 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ |
| 1894 | *p++ = htonl(0); /* bmval1 */ |
| 1895 | |
| 1896 | attrlenp = p++; |
| 1897 | *p++ = nfserr; /* no htonl */ |
| 1898 | *attrlenp = htonl((char *)p - (char *)attrlenp - 4); |
| 1899 | return p; |
| 1900 | } |
| 1901 | |
| 1902 | static int |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 1903 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
| 1904 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | { |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 1906 | struct readdir_cd *ccd = ccdv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
| 1908 | int buflen; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 1909 | __be32 *p = cd->buffer; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1910 | __be32 nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | |
| 1912 | /* In nfsv4, "." and ".." never make it onto the wire.. */ |
| 1913 | if (name && isdotent(name, namlen)) { |
| 1914 | cd->common.err = nfs_ok; |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
| 1918 | if (cd->offset) |
| 1919 | xdr_encode_hyper(cd->offset, (u64) offset); |
| 1920 | |
| 1921 | buflen = cd->buflen - 4 - XDR_QUADLEN(namlen); |
| 1922 | if (buflen < 0) |
| 1923 | goto fail; |
| 1924 | |
| 1925 | *p++ = xdr_one; /* mark entry present */ |
| 1926 | cd->offset = p; /* remember pointer */ |
| 1927 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
| 1928 | p = xdr_encode_array(p, name, namlen); /* name length & name */ |
| 1929 | |
| 1930 | nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, p, &buflen); |
| 1931 | switch (nfserr) { |
| 1932 | case nfs_ok: |
| 1933 | p += buflen; |
| 1934 | break; |
| 1935 | case nfserr_resource: |
| 1936 | nfserr = nfserr_toosmall; |
| 1937 | goto fail; |
| 1938 | case nfserr_dropit: |
| 1939 | goto fail; |
| 1940 | default: |
| 1941 | /* |
| 1942 | * If the client requested the RDATTR_ERROR attribute, |
| 1943 | * we stuff the error code into this attribute |
| 1944 | * and continue. If this attribute was not requested, |
| 1945 | * then in accordance with the spec, we fail the |
| 1946 | * entire READDIR operation(!) |
| 1947 | */ |
| 1948 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) |
| 1949 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | p = nfsd4_encode_rdattr_error(p, buflen, nfserr); |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 1951 | if (p == NULL) { |
| 1952 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | goto fail; |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 1954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | } |
| 1956 | cd->buflen -= (p - cd->buffer); |
| 1957 | cd->buffer = p; |
| 1958 | cd->common.err = nfs_ok; |
| 1959 | return 0; |
| 1960 | fail: |
| 1961 | cd->common.err = nfserr; |
| 1962 | return -EINVAL; |
| 1963 | } |
| 1964 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 1965 | static void |
| 1966 | nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid) |
| 1967 | { |
| 1968 | ENCODE_HEAD; |
| 1969 | |
| 1970 | RESERVE_SPACE(sizeof(stateid_t)); |
| 1971 | WRITE32(sid->si_generation); |
| 1972 | WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 1973 | ADJUST_ARGS(); |
| 1974 | } |
| 1975 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 1976 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1977 | 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] | 1978 | { |
| 1979 | ENCODE_HEAD; |
| 1980 | |
| 1981 | if (!nfserr) { |
| 1982 | RESERVE_SPACE(8); |
| 1983 | WRITE32(access->ac_supported); |
| 1984 | WRITE32(access->ac_resp_access); |
| 1985 | ADJUST_ARGS(); |
| 1986 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 1987 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 1990 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1991 | 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] | 1992 | { |
| 1993 | ENCODE_SEQID_OP_HEAD; |
| 1994 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 1995 | if (!nfserr) |
| 1996 | nfsd4_encode_stateid(resp, &close->cl_stateid); |
| 1997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | ENCODE_SEQID_OP_TAIL(close->cl_stateowner); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 1999 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2003 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2004 | 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] | 2005 | { |
| 2006 | ENCODE_HEAD; |
| 2007 | |
| 2008 | if (!nfserr) { |
| 2009 | RESERVE_SPACE(8); |
| 2010 | WRITEMEM(commit->co_verf.data, 8); |
| 2011 | ADJUST_ARGS(); |
| 2012 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2013 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2016 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2017 | 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] | 2018 | { |
| 2019 | ENCODE_HEAD; |
| 2020 | |
| 2021 | if (!nfserr) { |
| 2022 | RESERVE_SPACE(32); |
| 2023 | WRITECINFO(create->cr_cinfo); |
| 2024 | WRITE32(2); |
| 2025 | WRITE32(create->cr_bmval[0]); |
| 2026 | WRITE32(create->cr_bmval[1]); |
| 2027 | ADJUST_ARGS(); |
| 2028 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2029 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2032 | static __be32 |
| 2033 | 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] | 2034 | { |
| 2035 | struct svc_fh *fhp = getattr->ga_fhp; |
| 2036 | int buflen; |
| 2037 | |
| 2038 | if (nfserr) |
| 2039 | return nfserr; |
| 2040 | |
| 2041 | buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2); |
| 2042 | nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry, |
| 2043 | resp->p, &buflen, getattr->ga_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2044 | resp->rqstp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | if (!nfserr) |
| 2046 | resp->p += buflen; |
| 2047 | return nfserr; |
| 2048 | } |
| 2049 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2050 | static __be32 |
| 2051 | 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] | 2052 | { |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2053 | struct svc_fh *fhp = *fhpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | unsigned int len; |
| 2055 | ENCODE_HEAD; |
| 2056 | |
| 2057 | if (!nfserr) { |
| 2058 | len = fhp->fh_handle.fh_size; |
| 2059 | RESERVE_SPACE(len + 4); |
| 2060 | WRITE32(len); |
| 2061 | WRITEMEM(&fhp->fh_handle.fh_base, len); |
| 2062 | ADJUST_ARGS(); |
| 2063 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2064 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | /* |
| 2068 | * Including all fields other than the name, a LOCK4denied structure requires |
| 2069 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. |
| 2070 | */ |
| 2071 | static void |
| 2072 | nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld) |
| 2073 | { |
| 2074 | ENCODE_HEAD; |
| 2075 | |
| 2076 | RESERVE_SPACE(32 + XDR_LEN(ld->ld_sop ? ld->ld_sop->so_owner.len : 0)); |
| 2077 | WRITE64(ld->ld_start); |
| 2078 | WRITE64(ld->ld_length); |
| 2079 | WRITE32(ld->ld_type); |
| 2080 | if (ld->ld_sop) { |
| 2081 | WRITEMEM(&ld->ld_clientid, 8); |
| 2082 | WRITE32(ld->ld_sop->so_owner.len); |
| 2083 | WRITEMEM(ld->ld_sop->so_owner.data, ld->ld_sop->so_owner.len); |
| 2084 | kref_put(&ld->ld_sop->so_ref, nfs4_free_stateowner); |
| 2085 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
| 2086 | WRITE64((u64)0); /* clientid */ |
| 2087 | WRITE32(0); /* length of owner name */ |
| 2088 | } |
| 2089 | ADJUST_ARGS(); |
| 2090 | } |
| 2091 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2092 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2093 | 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] | 2094 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | ENCODE_SEQID_OP_HEAD; |
| 2096 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2097 | if (!nfserr) |
| 2098 | nfsd4_encode_stateid(resp, &lock->lk_resp_stateid); |
| 2099 | else if (nfserr == nfserr_denied) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | nfsd4_encode_lock_denied(resp, &lock->lk_denied); |
| 2101 | |
J. Bruce Fields | 3a65588 | 2006-01-18 17:43:19 -0800 | [diff] [blame] | 2102 | ENCODE_SEQID_OP_TAIL(lock->lk_replay_owner); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2103 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2106 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2107 | 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] | 2108 | { |
| 2109 | if (nfserr == nfserr_denied) |
| 2110 | nfsd4_encode_lock_denied(resp, &lockt->lt_denied); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2111 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2114 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2115 | 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] | 2116 | { |
| 2117 | ENCODE_SEQID_OP_HEAD; |
| 2118 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2119 | if (!nfserr) |
| 2120 | nfsd4_encode_stateid(resp, &locku->lu_stateid); |
| 2121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | ENCODE_SEQID_OP_TAIL(locku->lu_stateowner); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2123 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2127 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2128 | 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] | 2129 | { |
| 2130 | ENCODE_HEAD; |
| 2131 | |
| 2132 | if (!nfserr) { |
| 2133 | RESERVE_SPACE(20); |
| 2134 | WRITECINFO(link->li_cinfo); |
| 2135 | ADJUST_ARGS(); |
| 2136 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2137 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2141 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2142 | 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] | 2143 | { |
Benny Halevy | 1b6b225 | 2008-08-12 20:45:28 +0300 | [diff] [blame] | 2144 | ENCODE_HEAD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | ENCODE_SEQID_OP_HEAD; |
| 2146 | |
| 2147 | if (nfserr) |
| 2148 | goto out; |
| 2149 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2150 | nfsd4_encode_stateid(resp, &open->op_stateid); |
| 2151 | RESERVE_SPACE(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | WRITECINFO(open->op_cinfo); |
| 2153 | WRITE32(open->op_rflags); |
| 2154 | WRITE32(2); |
| 2155 | WRITE32(open->op_bmval[0]); |
| 2156 | WRITE32(open->op_bmval[1]); |
| 2157 | WRITE32(open->op_delegate_type); |
| 2158 | ADJUST_ARGS(); |
| 2159 | |
| 2160 | switch (open->op_delegate_type) { |
| 2161 | case NFS4_OPEN_DELEGATE_NONE: |
| 2162 | break; |
| 2163 | case NFS4_OPEN_DELEGATE_READ: |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2164 | nfsd4_encode_stateid(resp, &open->op_delegate_stateid); |
| 2165 | RESERVE_SPACE(20); |
NeilBrown | 7b190fe | 2005-06-23 22:03:23 -0700 | [diff] [blame] | 2166 | WRITE32(open->op_recall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | |
| 2168 | /* |
| 2169 | * TODO: ACE's in delegations |
| 2170 | */ |
| 2171 | WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 2172 | WRITE32(0); |
| 2173 | WRITE32(0); |
| 2174 | WRITE32(0); /* XXX: is NULL principal ok? */ |
| 2175 | ADJUST_ARGS(); |
| 2176 | break; |
| 2177 | case NFS4_OPEN_DELEGATE_WRITE: |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2178 | nfsd4_encode_stateid(resp, &open->op_delegate_stateid); |
| 2179 | RESERVE_SPACE(32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | WRITE32(0); |
| 2181 | |
| 2182 | /* |
| 2183 | * TODO: space_limit's in delegations |
| 2184 | */ |
| 2185 | WRITE32(NFS4_LIMIT_SIZE); |
| 2186 | WRITE32(~(u32)0); |
| 2187 | WRITE32(~(u32)0); |
| 2188 | |
| 2189 | /* |
| 2190 | * TODO: ACE's in delegations |
| 2191 | */ |
| 2192 | WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 2193 | WRITE32(0); |
| 2194 | WRITE32(0); |
| 2195 | WRITE32(0); /* XXX: is NULL principal ok? */ |
| 2196 | ADJUST_ARGS(); |
| 2197 | break; |
| 2198 | default: |
| 2199 | BUG(); |
| 2200 | } |
| 2201 | /* XXX save filehandle here */ |
| 2202 | out: |
| 2203 | ENCODE_SEQID_OP_TAIL(open->op_stateowner); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2204 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2207 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2208 | 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] | 2209 | { |
| 2210 | ENCODE_SEQID_OP_HEAD; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2211 | |
| 2212 | if (!nfserr) |
| 2213 | nfsd4_encode_stateid(resp, &oc->oc_resp_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | |
| 2215 | ENCODE_SEQID_OP_TAIL(oc->oc_stateowner); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2216 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2219 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2220 | 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] | 2221 | { |
| 2222 | ENCODE_SEQID_OP_HEAD; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 2223 | |
| 2224 | if (!nfserr) |
| 2225 | nfsd4_encode_stateid(resp, &od->od_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | |
| 2227 | ENCODE_SEQID_OP_TAIL(od->od_stateowner); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2228 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2231 | static __be32 |
| 2232 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2233 | struct nfsd4_read *read) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | { |
| 2235 | u32 eof; |
| 2236 | int v, pn; |
| 2237 | unsigned long maxcount; |
| 2238 | long len; |
| 2239 | ENCODE_HEAD; |
| 2240 | |
| 2241 | if (nfserr) |
| 2242 | return nfserr; |
| 2243 | if (resp->xbuf->page_len) |
| 2244 | return nfserr_resource; |
| 2245 | |
| 2246 | RESERVE_SPACE(8); /* eof flag and byte count */ |
| 2247 | |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 2248 | maxcount = svc_max_payload(resp->rqstp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | if (maxcount > read->rd_length) |
| 2250 | maxcount = read->rd_length; |
| 2251 | |
| 2252 | len = maxcount; |
| 2253 | v = 0; |
| 2254 | while (len > 0) { |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2255 | pn = resp->rqstp->rq_resused++; |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 2256 | resp->rqstp->rq_vec[v].iov_base = |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2257 | page_address(resp->rqstp->rq_respages[pn]); |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 2258 | resp->rqstp->rq_vec[v].iov_len = |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2259 | len < PAGE_SIZE ? len : PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | v++; |
| 2261 | len -= PAGE_SIZE; |
| 2262 | } |
| 2263 | read->rd_vlen = v; |
| 2264 | |
| 2265 | nfserr = nfsd_read(read->rd_rqstp, read->rd_fhp, read->rd_filp, |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 2266 | read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | &maxcount); |
| 2268 | |
| 2269 | if (nfserr == nfserr_symlink) |
| 2270 | nfserr = nfserr_inval; |
| 2271 | if (nfserr) |
| 2272 | return nfserr; |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2273 | eof = (read->rd_offset + maxcount >= |
| 2274 | read->rd_fhp->fh_dentry->d_inode->i_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | |
| 2276 | WRITE32(eof); |
| 2277 | WRITE32(maxcount); |
| 2278 | ADJUST_ARGS(); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2279 | resp->xbuf->head[0].iov_len = (char*)p |
| 2280 | - (char*)resp->xbuf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | resp->xbuf->page_len = maxcount; |
| 2282 | |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2283 | /* Use rest of head for padding and remaining ops: */ |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2284 | resp->xbuf->tail[0].iov_base = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | resp->xbuf->tail[0].iov_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | if (maxcount&3) { |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2287 | RESERVE_SPACE(4); |
| 2288 | WRITE32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | resp->xbuf->tail[0].iov_base += maxcount&3; |
| 2290 | resp->xbuf->tail[0].iov_len = 4 - (maxcount&3); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2291 | ADJUST_ARGS(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | } |
| 2293 | return 0; |
| 2294 | } |
| 2295 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2296 | static __be32 |
| 2297 | 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] | 2298 | { |
| 2299 | int maxcount; |
| 2300 | char *page; |
| 2301 | ENCODE_HEAD; |
| 2302 | |
| 2303 | if (nfserr) |
| 2304 | return nfserr; |
| 2305 | if (resp->xbuf->page_len) |
| 2306 | return nfserr_resource; |
| 2307 | |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2308 | page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
| 2310 | maxcount = PAGE_SIZE; |
| 2311 | RESERVE_SPACE(4); |
| 2312 | |
| 2313 | /* |
| 2314 | * XXX: By default, the ->readlink() VFS op will truncate symlinks |
| 2315 | * if they would overflow the buffer. Is this kosher in NFSv4? If |
| 2316 | * not, one easy fix is: if ->readlink() precisely fills the buffer, |
| 2317 | * assume that truncation occurred, and return NFS4ERR_RESOURCE. |
| 2318 | */ |
| 2319 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount); |
| 2320 | if (nfserr == nfserr_isdir) |
| 2321 | return nfserr_inval; |
| 2322 | if (nfserr) |
| 2323 | return nfserr; |
| 2324 | |
| 2325 | WRITE32(maxcount); |
| 2326 | ADJUST_ARGS(); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2327 | resp->xbuf->head[0].iov_len = (char*)p |
| 2328 | - (char*)resp->xbuf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | resp->xbuf->page_len = maxcount; |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2330 | |
| 2331 | /* Use rest of head for padding and remaining ops: */ |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2332 | resp->xbuf->tail[0].iov_base = p; |
| 2333 | resp->xbuf->tail[0].iov_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | if (maxcount&3) { |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2335 | RESERVE_SPACE(4); |
| 2336 | WRITE32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | resp->xbuf->tail[0].iov_base += maxcount&3; |
| 2338 | resp->xbuf->tail[0].iov_len = 4 - (maxcount&3); |
NeilBrown | 6ed6dec | 2006-04-10 22:55:32 -0700 | [diff] [blame] | 2339 | ADJUST_ARGS(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | } |
| 2341 | return 0; |
| 2342 | } |
| 2343 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2344 | static __be32 |
| 2345 | 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] | 2346 | { |
| 2347 | int maxcount; |
| 2348 | loff_t offset; |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2349 | __be32 *page, *savep, *tailbase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | ENCODE_HEAD; |
| 2351 | |
| 2352 | if (nfserr) |
| 2353 | return nfserr; |
| 2354 | if (resp->xbuf->page_len) |
| 2355 | return nfserr_resource; |
| 2356 | |
| 2357 | RESERVE_SPACE(8); /* verifier */ |
| 2358 | savep = p; |
| 2359 | |
| 2360 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
| 2361 | WRITE32(0); |
| 2362 | WRITE32(0); |
| 2363 | ADJUST_ARGS(); |
| 2364 | 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] | 2365 | tailbase = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
| 2367 | maxcount = PAGE_SIZE; |
| 2368 | if (maxcount > readdir->rd_maxcount) |
| 2369 | maxcount = readdir->rd_maxcount; |
| 2370 | |
| 2371 | /* |
| 2372 | * Convert from bytes to words, account for the two words already |
| 2373 | * written, make sure to leave two words at the end for the next |
| 2374 | * pointer and eof field. |
| 2375 | */ |
| 2376 | maxcount = (maxcount >> 2) - 4; |
| 2377 | if (maxcount < 0) { |
| 2378 | nfserr = nfserr_toosmall; |
| 2379 | goto err_no_verf; |
| 2380 | } |
| 2381 | |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2382 | page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | readdir->common.err = 0; |
| 2384 | readdir->buflen = maxcount; |
| 2385 | readdir->buffer = page; |
| 2386 | readdir->offset = NULL; |
| 2387 | |
| 2388 | offset = readdir->rd_cookie; |
| 2389 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, |
| 2390 | &offset, |
| 2391 | &readdir->common, nfsd4_encode_dirent); |
| 2392 | if (nfserr == nfs_ok && |
| 2393 | readdir->common.err == nfserr_toosmall && |
| 2394 | readdir->buffer == page) |
| 2395 | nfserr = nfserr_toosmall; |
| 2396 | if (nfserr == nfserr_symlink) |
| 2397 | nfserr = nfserr_notdir; |
| 2398 | if (nfserr) |
| 2399 | goto err_no_verf; |
| 2400 | |
| 2401 | if (readdir->offset) |
| 2402 | xdr_encode_hyper(readdir->offset, offset); |
| 2403 | |
| 2404 | p = readdir->buffer; |
| 2405 | *p++ = 0; /* no more entries */ |
| 2406 | *p++ = htonl(readdir->common.err == nfserr_eof); |
NeilBrown | 4452435 | 2006-10-04 02:15:46 -0700 | [diff] [blame] | 2407 | resp->xbuf->page_len = ((char*)p) - (char*)page_address( |
| 2408 | resp->rqstp->rq_respages[resp->rqstp->rq_resused-1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | |
NeilBrown | bb6e8a9 | 2006-04-10 22:55:33 -0700 | [diff] [blame] | 2410 | /* Use rest of head for padding and remaining ops: */ |
NeilBrown | bb6e8a9 | 2006-04-10 22:55:33 -0700 | [diff] [blame] | 2411 | resp->xbuf->tail[0].iov_base = tailbase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | resp->xbuf->tail[0].iov_len = 0; |
| 2413 | resp->p = resp->xbuf->tail[0].iov_base; |
NeilBrown | bb6e8a9 | 2006-04-10 22:55:33 -0700 | [diff] [blame] | 2414 | 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] | 2415 | |
| 2416 | return 0; |
| 2417 | err_no_verf: |
| 2418 | p = savep; |
| 2419 | ADJUST_ARGS(); |
| 2420 | return nfserr; |
| 2421 | } |
| 2422 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2423 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2424 | 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] | 2425 | { |
| 2426 | ENCODE_HEAD; |
| 2427 | |
| 2428 | if (!nfserr) { |
| 2429 | RESERVE_SPACE(20); |
| 2430 | WRITECINFO(remove->rm_cinfo); |
| 2431 | ADJUST_ARGS(); |
| 2432 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2433 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2436 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2437 | 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] | 2438 | { |
| 2439 | ENCODE_HEAD; |
| 2440 | |
| 2441 | if (!nfserr) { |
| 2442 | RESERVE_SPACE(40); |
| 2443 | WRITECINFO(rename->rn_sinfo); |
| 2444 | WRITECINFO(rename->rn_tinfo); |
| 2445 | ADJUST_ARGS(); |
| 2446 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2447 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2450 | static __be32 |
Al Viro | ca5c8cd | 2007-07-26 17:33:49 +0100 | [diff] [blame] | 2451 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2452 | struct nfsd4_secinfo *secinfo) |
| 2453 | { |
| 2454 | int i = 0; |
| 2455 | struct svc_export *exp = secinfo->si_exp; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2456 | u32 nflavs; |
| 2457 | struct exp_flavor_info *flavs; |
| 2458 | struct exp_flavor_info def_flavs[2]; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2459 | ENCODE_HEAD; |
| 2460 | |
| 2461 | if (nfserr) |
| 2462 | goto out; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2463 | if (exp->ex_nflavors) { |
| 2464 | flavs = exp->ex_flavors; |
| 2465 | nflavs = exp->ex_nflavors; |
| 2466 | } else { /* Handling of some defaults in absence of real secinfo: */ |
| 2467 | flavs = def_flavs; |
| 2468 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { |
| 2469 | nflavs = 2; |
| 2470 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; |
| 2471 | flavs[1].pseudoflavor = RPC_AUTH_NULL; |
| 2472 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { |
| 2473 | nflavs = 1; |
| 2474 | flavs[0].pseudoflavor |
| 2475 | = svcauth_gss_flavor(exp->ex_client); |
| 2476 | } else { |
| 2477 | nflavs = 1; |
| 2478 | flavs[0].pseudoflavor |
| 2479 | = exp->ex_client->flavour->flavour; |
| 2480 | } |
| 2481 | } |
| 2482 | |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2483 | RESERVE_SPACE(4); |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2484 | WRITE32(nflavs); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2485 | ADJUST_ARGS(); |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2486 | for (i = 0; i < nflavs; i++) { |
| 2487 | u32 flav = flavs[i].pseudoflavor; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2488 | struct gss_api_mech *gm = gss_mech_get_by_pseudoflavor(flav); |
| 2489 | |
| 2490 | if (gm) { |
| 2491 | RESERVE_SPACE(4); |
| 2492 | WRITE32(RPC_AUTH_GSS); |
| 2493 | ADJUST_ARGS(); |
| 2494 | RESERVE_SPACE(4 + gm->gm_oid.len); |
| 2495 | WRITE32(gm->gm_oid.len); |
| 2496 | WRITEMEM(gm->gm_oid.data, gm->gm_oid.len); |
| 2497 | ADJUST_ARGS(); |
| 2498 | RESERVE_SPACE(4); |
| 2499 | WRITE32(0); /* qop */ |
| 2500 | ADJUST_ARGS(); |
| 2501 | RESERVE_SPACE(4); |
| 2502 | WRITE32(gss_pseudoflavor_to_service(gm, flav)); |
| 2503 | ADJUST_ARGS(); |
| 2504 | gss_mech_put(gm); |
| 2505 | } else { |
| 2506 | RESERVE_SPACE(4); |
| 2507 | WRITE32(flav); |
| 2508 | ADJUST_ARGS(); |
| 2509 | } |
| 2510 | } |
| 2511 | out: |
| 2512 | if (exp) |
| 2513 | exp_put(exp); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2514 | return nfserr; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | /* |
| 2518 | * The SETATTR encode routine is special -- it always encodes a bitmap, |
| 2519 | * regardless of the error status. |
| 2520 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2521 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2522 | 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] | 2523 | { |
| 2524 | ENCODE_HEAD; |
| 2525 | |
| 2526 | RESERVE_SPACE(12); |
| 2527 | if (nfserr) { |
| 2528 | WRITE32(2); |
| 2529 | WRITE32(0); |
| 2530 | WRITE32(0); |
| 2531 | } |
| 2532 | else { |
| 2533 | WRITE32(2); |
| 2534 | WRITE32(setattr->sa_bmval[0]); |
| 2535 | WRITE32(setattr->sa_bmval[1]); |
| 2536 | } |
| 2537 | ADJUST_ARGS(); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2538 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2541 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2542 | 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] | 2543 | { |
| 2544 | ENCODE_HEAD; |
| 2545 | |
| 2546 | if (!nfserr) { |
| 2547 | RESERVE_SPACE(8 + sizeof(nfs4_verifier)); |
| 2548 | WRITEMEM(&scd->se_clientid, 8); |
| 2549 | WRITEMEM(&scd->se_confirm, sizeof(nfs4_verifier)); |
| 2550 | ADJUST_ARGS(); |
| 2551 | } |
| 2552 | else if (nfserr == nfserr_clid_inuse) { |
| 2553 | RESERVE_SPACE(8); |
| 2554 | WRITE32(0); |
| 2555 | WRITE32(0); |
| 2556 | ADJUST_ARGS(); |
| 2557 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2558 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2561 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2562 | 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] | 2563 | { |
| 2564 | ENCODE_HEAD; |
| 2565 | |
| 2566 | if (!nfserr) { |
| 2567 | RESERVE_SPACE(16); |
| 2568 | WRITE32(write->wr_bytes_written); |
| 2569 | WRITE32(write->wr_how_written); |
| 2570 | WRITEMEM(write->wr_verifier.data, 8); |
| 2571 | ADJUST_ARGS(); |
| 2572 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2573 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2576 | static __be32 |
| 2577 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
| 2578 | { |
| 2579 | return nfserr; |
| 2580 | } |
| 2581 | |
| 2582 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
| 2583 | |
| 2584 | static nfsd4_enc nfsd4_enc_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2585 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
| 2586 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
| 2587 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, |
| 2588 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, |
| 2589 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, |
| 2590 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
| 2591 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, |
| 2592 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, |
| 2593 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, |
| 2594 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, |
| 2595 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, |
| 2596 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, |
| 2597 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, |
| 2598 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, |
| 2599 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 2600 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, |
| 2601 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
| 2602 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, |
| 2603 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 2604 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 2605 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 2606 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, |
| 2607 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, |
| 2608 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, |
| 2609 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, |
| 2610 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, |
| 2611 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, |
| 2612 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 2613 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 2614 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, |
| 2615 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, |
| 2616 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, |
| 2617 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, |
| 2618 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 2619 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
| 2620 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2621 | }; |
| 2622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | void |
| 2624 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 2625 | { |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2626 | __be32 *statp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | ENCODE_HEAD; |
| 2628 | |
| 2629 | RESERVE_SPACE(8); |
| 2630 | WRITE32(op->opnum); |
| 2631 | statp = p++; /* to be backfilled at the end */ |
| 2632 | ADJUST_ARGS(); |
| 2633 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 2634 | if (op->opnum == OP_ILLEGAL) |
| 2635 | goto status; |
| 2636 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
| 2637 | !nfsd4_enc_ops[op->opnum]); |
| 2638 | op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u); |
| 2639 | status: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | /* |
| 2641 | * Note: We write the status directly, instead of using WRITE32(), |
| 2642 | * since it is already in network byte order. |
| 2643 | */ |
| 2644 | *statp = op->status; |
| 2645 | } |
| 2646 | |
| 2647 | /* |
| 2648 | * Encode the reply stored in the stateowner reply cache |
| 2649 | * |
| 2650 | * XDR note: do not encode rp->rp_buflen: the buffer contains the |
| 2651 | * previously sent already encoded operation. |
| 2652 | * |
| 2653 | * called with nfs4_lock_state() held |
| 2654 | */ |
| 2655 | void |
| 2656 | nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 2657 | { |
| 2658 | ENCODE_HEAD; |
| 2659 | struct nfs4_replay *rp = op->replay; |
| 2660 | |
| 2661 | BUG_ON(!rp); |
| 2662 | |
| 2663 | RESERVE_SPACE(8); |
| 2664 | WRITE32(op->opnum); |
| 2665 | *p++ = rp->rp_status; /* already xdr'ed */ |
| 2666 | ADJUST_ARGS(); |
| 2667 | |
| 2668 | RESERVE_SPACE(rp->rp_buflen); |
| 2669 | WRITEMEM(rp->rp_buf, rp->rp_buflen); |
| 2670 | ADJUST_ARGS(); |
| 2671 | } |
| 2672 | |
| 2673 | /* |
| 2674 | * END OF "GENERIC" ENCODE ROUTINES. |
| 2675 | */ |
| 2676 | |
| 2677 | int |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2678 | nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | { |
| 2680 | return xdr_ressize_check(rqstp, p); |
| 2681 | } |
| 2682 | |
| 2683 | void nfsd4_release_compoundargs(struct nfsd4_compoundargs *args) |
| 2684 | { |
| 2685 | if (args->ops != args->iops) { |
| 2686 | kfree(args->ops); |
| 2687 | args->ops = args->iops; |
| 2688 | } |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 2689 | kfree(args->tmpp); |
| 2690 | args->tmpp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | while (args->to_free) { |
| 2692 | struct tmpbuf *tb = args->to_free; |
| 2693 | args->to_free = tb->next; |
| 2694 | tb->release(tb->buf); |
| 2695 | kfree(tb); |
| 2696 | } |
| 2697 | } |
| 2698 | |
| 2699 | int |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2700 | 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] | 2701 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2702 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | |
| 2704 | args->p = p; |
| 2705 | args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len; |
| 2706 | args->pagelist = rqstp->rq_arg.pages; |
| 2707 | args->pagelen = rqstp->rq_arg.page_len; |
| 2708 | args->tmpp = NULL; |
| 2709 | args->to_free = NULL; |
| 2710 | args->ops = args->iops; |
| 2711 | args->rqstp = rqstp; |
| 2712 | |
| 2713 | status = nfsd4_decode_compound(args); |
| 2714 | if (status) { |
| 2715 | nfsd4_release_compoundargs(args); |
| 2716 | } |
| 2717 | return !status; |
| 2718 | } |
| 2719 | |
| 2720 | int |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 2721 | 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] | 2722 | { |
| 2723 | /* |
| 2724 | * All that remains is to write the tag and operation count... |
| 2725 | */ |
| 2726 | struct kvec *iov; |
| 2727 | p = resp->tagp; |
| 2728 | *p++ = htonl(resp->taglen); |
| 2729 | memcpy(p, resp->tag, resp->taglen); |
| 2730 | p += XDR_QUADLEN(resp->taglen); |
| 2731 | *p++ = htonl(resp->opcnt); |
| 2732 | |
| 2733 | if (rqstp->rq_res.page_len) |
| 2734 | iov = &rqstp->rq_res.tail[0]; |
| 2735 | else |
| 2736 | iov = &rqstp->rq_res.head[0]; |
| 2737 | iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base; |
| 2738 | BUG_ON(iov->iov_len > PAGE_SIZE); |
| 2739 | return 1; |
| 2740 | } |
| 2741 | |
| 2742 | /* |
| 2743 | * Local variables: |
| 2744 | * c-basic-offset: 8 |
| 2745 | * End: |
| 2746 | */ |