Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Server-side XDR for NFSv4 |
3 | * | |
4 | * Copyright (c) 2002 The Regents of the University of Michigan. | |
5 | * All rights reserved. | |
6 | * | |
7 | * Kendrick Smith <kmsmith@umich.edu> | |
8 | * Andy Adamson <andros@umich.edu> | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | |
13 | * | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions and the following disclaimer. | |
16 | * 2. Redistributions in binary form must reproduce the above copyright | |
17 | * notice, this list of conditions and the following disclaimer in the | |
18 | * documentation and/or other materials provided with the distribution. | |
19 | * 3. Neither the name of the University nor the names of its | |
20 | * contributors may be used to endorse or promote products derived | |
21 | * from this software without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
26 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
1da177e4 LT |
34 | */ |
35 | ||
96bcad50 | 36 | #include <linux/file.h> |
5a0e3ad6 | 37 | #include <linux/slab.h> |
1da177e4 | 38 | #include <linux/namei.h> |
341eb184 | 39 | #include <linux/statfs.h> |
0733d213 | 40 | #include <linux/utsname.h> |
17456804 | 41 | #include <linux/pagemap.h> |
4796f457 | 42 | #include <linux/sunrpc/svcauth_gss.h> |
9a74af21 | 43 | |
2ca72e17 BF |
44 | #include "idmap.h" |
45 | #include "acl.h" | |
9a74af21 | 46 | #include "xdr4.h" |
0a3adade | 47 | #include "vfs.h" |
17456804 | 48 | #include "state.h" |
1091006c | 49 | #include "cache.h" |
3d733711 | 50 | #include "netns.h" |
9cf514cc | 51 | #include "pnfs.h" |
5c4583b2 | 52 | #include "filecache.h" |
2ca72e17 | 53 | |
18032ca0 DQ |
54 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
55 | #include <linux/security.h> | |
56 | #endif | |
57 | ||
58 | ||
1da177e4 LT |
59 | #define NFSDDBG_FACILITY NFSDDBG_XDR |
60 | ||
5cf23dbb | 61 | const u32 nfsd_suppattrs[3][3] = { |
916d2d84 BF |
62 | {NFSD4_SUPPORTED_ATTRS_WORD0, |
63 | NFSD4_SUPPORTED_ATTRS_WORD1, | |
64 | NFSD4_SUPPORTED_ATTRS_WORD2}, | |
65 | ||
66 | {NFSD4_1_SUPPORTED_ATTRS_WORD0, | |
67 | NFSD4_1_SUPPORTED_ATTRS_WORD1, | |
68 | NFSD4_1_SUPPORTED_ATTRS_WORD2}, | |
69 | ||
70 | {NFSD4_1_SUPPORTED_ATTRS_WORD0, | |
71 | NFSD4_1_SUPPORTED_ATTRS_WORD1, | |
72 | NFSD4_2_SUPPORTED_ATTRS_WORD2}, | |
73 | }; | |
74 | ||
42ca0993 BF |
75 | /* |
76 | * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing | |
77 | * directory in order to indicate to the client that a filesystem boundary is present | |
78 | * We use a fixed fsid for a referral | |
79 | */ | |
80 | #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL | |
81 | #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL | |
82 | ||
b37ad28b | 83 | static __be32 |
a36b1725 | 84 | check_filename(char *str, int len) |
1da177e4 LT |
85 | { |
86 | int i; | |
87 | ||
88 | if (len == 0) | |
89 | return nfserr_inval; | |
90 | if (isdotent(str, len)) | |
a36b1725 | 91 | return nfserr_badname; |
1da177e4 LT |
92 | for (i = 0; i < len; i++) |
93 | if (str[i] == '/') | |
a36b1725 | 94 | return nfserr_badname; |
1da177e4 LT |
95 | return 0; |
96 | } | |
97 | ||
1da177e4 | 98 | #define DECODE_HEAD \ |
2ebbc012 | 99 | __be32 *p; \ |
b37ad28b | 100 | __be32 status |
1da177e4 LT |
101 | #define DECODE_TAIL \ |
102 | status = 0; \ | |
103 | out: \ | |
104 | return status; \ | |
105 | xdr_error: \ | |
817cb9d4 CL |
106 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
107 | __FILE__, __LINE__); \ | |
1da177e4 LT |
108 | status = nfserr_bad_xdr; \ |
109 | goto out | |
110 | ||
1da177e4 LT |
111 | #define READMEM(x,nbytes) do { \ |
112 | x = (char *)p; \ | |
113 | p += XDR_QUADLEN(nbytes); \ | |
114 | } while (0) | |
115 | #define SAVEMEM(x,nbytes) do { \ | |
116 | if (!(x = (p==argp->tmp || p == argp->tmpp) ? \ | |
117 | savemem(argp, p, nbytes) : \ | |
118 | (char *)p)) { \ | |
817cb9d4 CL |
119 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
120 | __FILE__, __LINE__); \ | |
1da177e4 LT |
121 | goto xdr_error; \ |
122 | } \ | |
123 | p += XDR_QUADLEN(nbytes); \ | |
124 | } while (0) | |
125 | #define COPYMEM(x,nbytes) do { \ | |
126 | memcpy((x), p, nbytes); \ | |
127 | p += XDR_QUADLEN(nbytes); \ | |
128 | } while (0) | |
129 | ||
130 | /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */ | |
131 | #define READ_BUF(nbytes) do { \ | |
132 | if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \ | |
133 | p = argp->p; \ | |
134 | argp->p += XDR_QUADLEN(nbytes); \ | |
135 | } else if (!(p = read_buf(argp, nbytes))) { \ | |
817cb9d4 CL |
136 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
137 | __FILE__, __LINE__); \ | |
1da177e4 LT |
138 | goto xdr_error; \ |
139 | } \ | |
140 | } while (0) | |
141 | ||
590b7431 BF |
142 | static void next_decode_page(struct nfsd4_compoundargs *argp) |
143 | { | |
590b7431 | 144 | argp->p = page_address(argp->pagelist[0]); |
365da4ad | 145 | argp->pagelist++; |
590b7431 | 146 | if (argp->pagelen < PAGE_SIZE) { |
fc788f64 | 147 | argp->end = argp->p + XDR_QUADLEN(argp->pagelen); |
590b7431 BF |
148 | argp->pagelen = 0; |
149 | } else { | |
150 | argp->end = argp->p + (PAGE_SIZE>>2); | |
151 | argp->pagelen -= PAGE_SIZE; | |
152 | } | |
153 | } | |
154 | ||
ca2a05aa | 155 | static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) |
1da177e4 LT |
156 | { |
157 | /* We want more bytes than seem to be available. | |
158 | * Maybe we need a new page, maybe we have just run out | |
159 | */ | |
ca2a05aa | 160 | unsigned int avail = (char *)argp->end - (char *)argp->p; |
2ebbc012 | 161 | __be32 *p; |
eae03e2a CL |
162 | |
163 | if (argp->pagelen == 0) { | |
164 | struct kvec *vec = &argp->rqstp->rq_arg.tail[0]; | |
165 | ||
166 | if (!argp->tail) { | |
167 | argp->tail = true; | |
168 | avail = vec->iov_len; | |
169 | argp->p = vec->iov_base; | |
170 | argp->end = vec->iov_base + avail; | |
171 | } | |
172 | ||
173 | if (avail < nbytes) | |
174 | return NULL; | |
175 | ||
176 | p = argp->p; | |
177 | argp->p += XDR_QUADLEN(nbytes); | |
178 | return p; | |
179 | } | |
180 | ||
1da177e4 LT |
181 | if (avail + argp->pagelen < nbytes) |
182 | return NULL; | |
183 | if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */ | |
184 | return NULL; | |
185 | /* ok, we can do it with the current plus the next page */ | |
186 | if (nbytes <= sizeof(argp->tmp)) | |
187 | p = argp->tmp; | |
188 | else { | |
f99d49ad | 189 | kfree(argp->tmpp); |
1da177e4 LT |
190 | p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL); |
191 | if (!p) | |
192 | return NULL; | |
193 | ||
194 | } | |
ca2a05aa BF |
195 | /* |
196 | * The following memcpy is safe because read_buf is always | |
197 | * called with nbytes > avail, and the two cases above both | |
198 | * guarantee p points to at least nbytes bytes. | |
199 | */ | |
1da177e4 | 200 | memcpy(p, argp->p, avail); |
590b7431 | 201 | next_decode_page(argp); |
1da177e4 LT |
202 | memcpy(((char*)p)+avail, argp->p, (nbytes - avail)); |
203 | argp->p += XDR_QUADLEN(nbytes - avail); | |
204 | return p; | |
205 | } | |
206 | ||
60adfc50 AA |
207 | static int zero_clientid(clientid_t *clid) |
208 | { | |
209 | return (clid->cl_boot == 0) && (clid->cl_id == 0); | |
210 | } | |
211 | ||
2d8498db | 212 | /** |
d5e23383 | 213 | * svcxdr_tmpalloc - allocate memory to be freed after compound processing |
ce043ac8 BF |
214 | * @argp: NFSv4 compound argument structure |
215 | * @p: pointer to be freed (with kfree()) | |
2d8498db CH |
216 | * |
217 | * Marks @p to be freed when processing the compound operation | |
218 | * described in @argp finishes. | |
219 | */ | |
d5e23383 BF |
220 | static void * |
221 | svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, u32 len) | |
1da177e4 | 222 | { |
d5e23383 | 223 | struct svcxdr_tmpbuf *tb; |
1da177e4 | 224 | |
d5e23383 | 225 | tb = kmalloc(sizeof(*tb) + len, GFP_KERNEL); |
1da177e4 | 226 | if (!tb) |
d5e23383 | 227 | return NULL; |
1da177e4 LT |
228 | tb->next = argp->to_free; |
229 | argp->to_free = tb; | |
d5e23383 | 230 | return tb->buf; |
1da177e4 LT |
231 | } |
232 | ||
29c353b3 BF |
233 | /* |
234 | * For xdr strings that need to be passed to other kernel api's | |
235 | * as null-terminated strings. | |
236 | * | |
237 | * Note null-terminating in place usually isn't safe since the | |
238 | * buffer might end on a page boundary. | |
239 | */ | |
240 | static char * | |
241 | svcxdr_dupstr(struct nfsd4_compoundargs *argp, void *buf, u32 len) | |
242 | { | |
d5e23383 | 243 | char *p = svcxdr_tmpalloc(argp, len + 1); |
29c353b3 BF |
244 | |
245 | if (!p) | |
246 | return NULL; | |
247 | memcpy(p, buf, len); | |
248 | p[len] = '\0'; | |
29c353b3 | 249 | return p; |
1da177e4 LT |
250 | } |
251 | ||
2d8498db CH |
252 | /** |
253 | * savemem - duplicate a chunk of memory for later processing | |
254 | * @argp: NFSv4 compound argument structure to be freed with | |
255 | * @p: pointer to be duplicated | |
256 | * @nbytes: length to be duplicated | |
257 | * | |
258 | * Returns a pointer to a copy of @nbytes bytes of memory at @p | |
259 | * that are preserved until processing of the NFSv4 compound | |
260 | * operation described by @argp finishes. | |
261 | */ | |
2ebbc012 | 262 | static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes) |
1da177e4 | 263 | { |
d5e23383 BF |
264 | void *ret; |
265 | ||
266 | ret = svcxdr_tmpalloc(argp, nbytes); | |
267 | if (!ret) | |
1da177e4 | 268 | return NULL; |
d5e23383 BF |
269 | memcpy(ret, p, nbytes); |
270 | return ret; | |
1da177e4 LT |
271 | } |
272 | ||
4c94e13e | 273 | static __be32 |
bdba5368 | 274 | nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
4c94e13e CH |
275 | { |
276 | DECODE_HEAD; | |
4c94e13e CH |
277 | |
278 | READ_BUF(12); | |
bdba5368 | 279 | p = xdr_decode_hyper(p, &tv->tv_sec); |
4c94e13e CH |
280 | tv->tv_nsec = be32_to_cpup(p++); |
281 | if (tv->tv_nsec >= (u32)1000000000) | |
282 | return nfserr_inval; | |
283 | ||
284 | DECODE_TAIL; | |
285 | } | |
286 | ||
b37ad28b | 287 | static __be32 |
1da177e4 LT |
288 | nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) |
289 | { | |
290 | u32 bmlen; | |
291 | DECODE_HEAD; | |
292 | ||
293 | bmval[0] = 0; | |
294 | bmval[1] = 0; | |
7e705706 | 295 | bmval[2] = 0; |
1da177e4 LT |
296 | |
297 | READ_BUF(4); | |
06553991 | 298 | bmlen = be32_to_cpup(p++); |
1da177e4 LT |
299 | if (bmlen > 1000) |
300 | goto xdr_error; | |
301 | ||
302 | READ_BUF(bmlen << 2); | |
303 | if (bmlen > 0) | |
06553991 | 304 | bmval[0] = be32_to_cpup(p++); |
1da177e4 | 305 | if (bmlen > 1) |
06553991 | 306 | bmval[1] = be32_to_cpup(p++); |
7e705706 | 307 | if (bmlen > 2) |
06553991 | 308 | bmval[2] = be32_to_cpup(p++); |
1da177e4 LT |
309 | |
310 | DECODE_TAIL; | |
311 | } | |
312 | ||
b37ad28b | 313 | static __be32 |
3c8e0316 | 314 | nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, |
18032ca0 | 315 | struct iattr *iattr, struct nfs4_acl **acl, |
47057abd | 316 | struct xdr_netobj *label, int *umask) |
1da177e4 LT |
317 | { |
318 | int expected_len, len = 0; | |
319 | u32 dummy32; | |
320 | char *buf; | |
321 | ||
322 | DECODE_HEAD; | |
323 | iattr->ia_valid = 0; | |
324 | if ((status = nfsd4_decode_bitmap(argp, bmval))) | |
325 | return status; | |
326 | ||
e864c189 BF |
327 | if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 |
328 | || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 | |
329 | || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) { | |
330 | if (nfsd_attrs_supported(argp->minorversion, bmval)) | |
331 | return nfserr_inval; | |
332 | return nfserr_attrnotsupp; | |
333 | } | |
334 | ||
1da177e4 | 335 | READ_BUF(4); |
06553991 | 336 | expected_len = be32_to_cpup(p++); |
1da177e4 LT |
337 | |
338 | if (bmval[0] & FATTR4_WORD0_SIZE) { | |
339 | READ_BUF(8); | |
340 | len += 8; | |
542d1ab3 | 341 | p = xdr_decode_hyper(p, &iattr->ia_size); |
1da177e4 LT |
342 | iattr->ia_valid |= ATTR_SIZE; |
343 | } | |
344 | if (bmval[0] & FATTR4_WORD0_ACL) { | |
64a817cf | 345 | u32 nace; |
28e05dd8 | 346 | struct nfs4_ace *ace; |
1da177e4 LT |
347 | |
348 | READ_BUF(4); len += 4; | |
06553991 | 349 | nace = be32_to_cpup(p++); |
1da177e4 | 350 | |
28e05dd8 | 351 | if (nace > NFS4_ACL_MAX) |
798df338 | 352 | return nfserr_fbig; |
28e05dd8 | 353 | |
d5e23383 | 354 | *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(nace)); |
eba1c99c KM |
355 | if (*acl == NULL) |
356 | return nfserr_jukebox; | |
357 | ||
28e05dd8 BF |
358 | (*acl)->naces = nace; |
359 | for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) { | |
1da177e4 | 360 | READ_BUF(16); len += 16; |
06553991 BF |
361 | ace->type = be32_to_cpup(p++); |
362 | ace->flag = be32_to_cpup(p++); | |
363 | ace->access_mask = be32_to_cpup(p++); | |
364 | dummy32 = be32_to_cpup(p++); | |
1da177e4 LT |
365 | READ_BUF(dummy32); |
366 | len += XDR_QUADLEN(dummy32) << 2; | |
367 | READMEM(buf, dummy32); | |
28e05dd8 | 368 | ace->whotype = nfs4_acl_get_whotype(buf, dummy32); |
3c726023 | 369 | status = nfs_ok; |
28e05dd8 | 370 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
ab8e4aee | 371 | ; |
28e05dd8 | 372 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
3c726023 | 373 | status = nfsd_map_name_to_gid(argp->rqstp, |
ab8e4aee | 374 | buf, dummy32, &ace->who_gid); |
1da177e4 | 375 | else |
3c726023 | 376 | status = nfsd_map_name_to_uid(argp->rqstp, |
ab8e4aee | 377 | buf, dummy32, &ace->who_uid); |
3c726023 BF |
378 | if (status) |
379 | return status; | |
1da177e4 LT |
380 | } |
381 | } else | |
382 | *acl = NULL; | |
383 | if (bmval[1] & FATTR4_WORD1_MODE) { | |
384 | READ_BUF(4); | |
385 | len += 4; | |
06553991 | 386 | iattr->ia_mode = be32_to_cpup(p++); |
1da177e4 LT |
387 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
388 | iattr->ia_valid |= ATTR_MODE; | |
389 | } | |
390 | if (bmval[1] & FATTR4_WORD1_OWNER) { | |
391 | READ_BUF(4); | |
392 | len += 4; | |
06553991 | 393 | dummy32 = be32_to_cpup(p++); |
1da177e4 LT |
394 | READ_BUF(dummy32); |
395 | len += (XDR_QUADLEN(dummy32) << 2); | |
396 | READMEM(buf, dummy32); | |
47c85291 N |
397 | if ((status = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid))) |
398 | return status; | |
1da177e4 LT |
399 | iattr->ia_valid |= ATTR_UID; |
400 | } | |
401 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { | |
402 | READ_BUF(4); | |
403 | len += 4; | |
06553991 | 404 | dummy32 = be32_to_cpup(p++); |
1da177e4 LT |
405 | READ_BUF(dummy32); |
406 | len += (XDR_QUADLEN(dummy32) << 2); | |
407 | READMEM(buf, dummy32); | |
47c85291 N |
408 | if ((status = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid))) |
409 | return status; | |
1da177e4 LT |
410 | iattr->ia_valid |= ATTR_GID; |
411 | } | |
412 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { | |
413 | READ_BUF(4); | |
414 | len += 4; | |
06553991 | 415 | dummy32 = be32_to_cpup(p++); |
1da177e4 LT |
416 | switch (dummy32) { |
417 | case NFS4_SET_TO_CLIENT_TIME: | |
1da177e4 | 418 | len += 12; |
bdba5368 | 419 | status = nfsd4_decode_time(argp, &iattr->ia_atime); |
4c94e13e CH |
420 | if (status) |
421 | return status; | |
1da177e4 LT |
422 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
423 | break; | |
424 | case NFS4_SET_TO_SERVER_TIME: | |
425 | iattr->ia_valid |= ATTR_ATIME; | |
426 | break; | |
427 | default: | |
428 | goto xdr_error; | |
429 | } | |
430 | } | |
1da177e4 LT |
431 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
432 | READ_BUF(4); | |
433 | len += 4; | |
06553991 | 434 | dummy32 = be32_to_cpup(p++); |
1da177e4 LT |
435 | switch (dummy32) { |
436 | case NFS4_SET_TO_CLIENT_TIME: | |
1da177e4 | 437 | len += 12; |
bdba5368 | 438 | status = nfsd4_decode_time(argp, &iattr->ia_mtime); |
4c94e13e CH |
439 | if (status) |
440 | return status; | |
1da177e4 LT |
441 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
442 | break; | |
443 | case NFS4_SET_TO_SERVER_TIME: | |
444 | iattr->ia_valid |= ATTR_MTIME; | |
445 | break; | |
446 | default: | |
447 | goto xdr_error; | |
448 | } | |
449 | } | |
18032ca0 DQ |
450 | |
451 | label->len = 0; | |
2285ae76 AB |
452 | if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) && |
453 | bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { | |
18032ca0 DQ |
454 | READ_BUF(4); |
455 | len += 4; | |
06553991 | 456 | dummy32 = be32_to_cpup(p++); /* lfs: we don't use it */ |
18032ca0 DQ |
457 | READ_BUF(4); |
458 | len += 4; | |
06553991 | 459 | dummy32 = be32_to_cpup(p++); /* pi: we don't use it either */ |
18032ca0 DQ |
460 | READ_BUF(4); |
461 | len += 4; | |
06553991 | 462 | dummy32 = be32_to_cpup(p++); |
18032ca0 | 463 | READ_BUF(dummy32); |
1ec8c0c4 | 464 | if (dummy32 > NFS4_MAXLABELLEN) |
18032ca0 DQ |
465 | return nfserr_badlabel; |
466 | len += (XDR_QUADLEN(dummy32) << 2); | |
467 | READMEM(buf, dummy32); | |
29c353b3 BF |
468 | label->len = dummy32; |
469 | label->data = svcxdr_dupstr(argp, buf, dummy32); | |
18032ca0 DQ |
470 | if (!label->data) |
471 | return nfserr_jukebox; | |
18032ca0 | 472 | } |
47057abd AG |
473 | if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { |
474 | if (!umask) | |
475 | goto xdr_error; | |
476 | READ_BUF(8); | |
477 | len += 8; | |
478 | dummy32 = be32_to_cpup(p++); | |
479 | iattr->ia_mode = dummy32 & (S_IFMT | S_IALLUGO); | |
480 | dummy32 = be32_to_cpup(p++); | |
481 | *umask = dummy32 & S_IRWXUGO; | |
482 | iattr->ia_valid |= ATTR_MODE; | |
483 | } | |
e864c189 | 484 | if (len != expected_len) |
1da177e4 LT |
485 | goto xdr_error; |
486 | ||
487 | DECODE_TAIL; | |
1da177e4 LT |
488 | } |
489 | ||
e31a1b66 BH |
490 | static __be32 |
491 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) | |
492 | { | |
493 | DECODE_HEAD; | |
494 | ||
495 | READ_BUF(sizeof(stateid_t)); | |
06553991 | 496 | sid->si_generation = be32_to_cpup(p++); |
e31a1b66 BH |
497 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
498 | ||
499 | DECODE_TAIL; | |
500 | } | |
501 | ||
b37ad28b | 502 | static __be32 |
1da177e4 LT |
503 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access) |
504 | { | |
505 | DECODE_HEAD; | |
506 | ||
507 | READ_BUF(4); | |
06553991 | 508 | access->ac_req_access = be32_to_cpup(p++); |
1da177e4 LT |
509 | |
510 | DECODE_TAIL; | |
511 | } | |
512 | ||
acb2887e BF |
513 | static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs) |
514 | { | |
515 | DECODE_HEAD; | |
e45d1a18 | 516 | struct user_namespace *userns = nfsd_user_namespace(argp->rqstp); |
12fc3e92 | 517 | u32 dummy, uid, gid; |
acb2887e BF |
518 | char *machine_name; |
519 | int i; | |
520 | int nr_secflavs; | |
521 | ||
522 | /* callback_sec_params4 */ | |
523 | READ_BUF(4); | |
06553991 | 524 | nr_secflavs = be32_to_cpup(p++); |
57569a70 BF |
525 | if (nr_secflavs) |
526 | cbs->flavor = (u32)(-1); | |
527 | else | |
528 | /* Is this legal? Be generous, take it to mean AUTH_NONE: */ | |
529 | cbs->flavor = 0; | |
acb2887e BF |
530 | for (i = 0; i < nr_secflavs; ++i) { |
531 | READ_BUF(4); | |
06553991 | 532 | dummy = be32_to_cpup(p++); |
acb2887e BF |
533 | switch (dummy) { |
534 | case RPC_AUTH_NULL: | |
535 | /* Nothing to read */ | |
12fc3e92 BF |
536 | if (cbs->flavor == (u32)(-1)) |
537 | cbs->flavor = RPC_AUTH_NULL; | |
acb2887e BF |
538 | break; |
539 | case RPC_AUTH_UNIX: | |
540 | READ_BUF(8); | |
541 | /* stamp */ | |
06553991 | 542 | dummy = be32_to_cpup(p++); |
acb2887e BF |
543 | |
544 | /* machine name */ | |
06553991 | 545 | dummy = be32_to_cpup(p++); |
acb2887e BF |
546 | READ_BUF(dummy); |
547 | SAVEMEM(machine_name, dummy); | |
548 | ||
549 | /* uid, gid */ | |
550 | READ_BUF(8); | |
06553991 BF |
551 | uid = be32_to_cpup(p++); |
552 | gid = be32_to_cpup(p++); | |
acb2887e BF |
553 | |
554 | /* more gids */ | |
555 | READ_BUF(4); | |
06553991 | 556 | dummy = be32_to_cpup(p++); |
acb2887e | 557 | READ_BUF(dummy * 4); |
12fc3e92 | 558 | if (cbs->flavor == (u32)(-1)) { |
e45d1a18 TM |
559 | kuid_t kuid = make_kuid(userns, uid); |
560 | kgid_t kgid = make_kgid(userns, gid); | |
03bc6d1c EB |
561 | if (uid_valid(kuid) && gid_valid(kgid)) { |
562 | cbs->uid = kuid; | |
563 | cbs->gid = kgid; | |
564 | cbs->flavor = RPC_AUTH_UNIX; | |
565 | } else { | |
566 | dprintk("RPC_AUTH_UNIX with invalid" | |
567 | "uid or gid ignoring!\n"); | |
568 | } | |
12fc3e92 | 569 | } |
acb2887e BF |
570 | break; |
571 | case RPC_AUTH_GSS: | |
572 | dprintk("RPC_AUTH_GSS callback secflavor " | |
573 | "not supported!\n"); | |
574 | READ_BUF(8); | |
575 | /* gcbp_service */ | |
06553991 | 576 | dummy = be32_to_cpup(p++); |
acb2887e | 577 | /* gcbp_handle_from_server */ |
06553991 | 578 | dummy = be32_to_cpup(p++); |
acb2887e BF |
579 | READ_BUF(dummy); |
580 | p += XDR_QUADLEN(dummy); | |
581 | /* gcbp_handle_from_client */ | |
582 | READ_BUF(4); | |
06553991 | 583 | dummy = be32_to_cpup(p++); |
acb2887e BF |
584 | READ_BUF(dummy); |
585 | break; | |
586 | default: | |
587 | dprintk("Illegal callback secflavor\n"); | |
588 | return nfserr_inval; | |
589 | } | |
590 | } | |
591 | DECODE_TAIL; | |
592 | } | |
593 | ||
cb73a9f4 BF |
594 | static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc) |
595 | { | |
596 | DECODE_HEAD; | |
597 | ||
598 | READ_BUF(4); | |
06553991 | 599 | bc->bc_cb_program = be32_to_cpup(p++); |
cb73a9f4 BF |
600 | nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec); |
601 | ||
602 | DECODE_TAIL; | |
603 | } | |
604 | ||
1d1bc8f2 BF |
605 | static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts) |
606 | { | |
607 | DECODE_HEAD; | |
1d1bc8f2 BF |
608 | |
609 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 8); | |
610 | COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN); | |
06553991 | 611 | bcts->dir = be32_to_cpup(p++); |
6ce2357f BS |
612 | /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker |
613 | * could help us figure out we should be using it. */ | |
1d1bc8f2 BF |
614 | DECODE_TAIL; |
615 | } | |
616 | ||
b37ad28b | 617 | static __be32 |
1da177e4 LT |
618 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
619 | { | |
620 | DECODE_HEAD; | |
621 | ||
e31a1b66 | 622 | READ_BUF(4); |
06553991 | 623 | close->cl_seqid = be32_to_cpup(p++); |
e31a1b66 | 624 | return nfsd4_decode_stateid(argp, &close->cl_stateid); |
1da177e4 LT |
625 | |
626 | DECODE_TAIL; | |
627 | } | |
628 | ||
629 | ||
b37ad28b | 630 | static __be32 |
1da177e4 LT |
631 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
632 | { | |
633 | DECODE_HEAD; | |
634 | ||
635 | READ_BUF(12); | |
542d1ab3 | 636 | p = xdr_decode_hyper(p, &commit->co_offset); |
06553991 | 637 | commit->co_count = be32_to_cpup(p++); |
1da177e4 LT |
638 | |
639 | DECODE_TAIL; | |
640 | } | |
641 | ||
b37ad28b | 642 | static __be32 |
1da177e4 LT |
643 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
644 | { | |
645 | DECODE_HEAD; | |
646 | ||
647 | READ_BUF(4); | |
06553991 | 648 | create->cr_type = be32_to_cpup(p++); |
1da177e4 LT |
649 | switch (create->cr_type) { |
650 | case NF4LNK: | |
651 | READ_BUF(4); | |
7fb84306 BF |
652 | create->cr_datalen = be32_to_cpup(p++); |
653 | READ_BUF(create->cr_datalen); | |
29c353b3 | 654 | create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen); |
7fb84306 | 655 | if (!create->cr_data) |
76f47128 | 656 | return nfserr_jukebox; |
1da177e4 LT |
657 | break; |
658 | case NF4BLK: | |
659 | case NF4CHR: | |
660 | READ_BUF(8); | |
06553991 BF |
661 | create->cr_specdata1 = be32_to_cpup(p++); |
662 | create->cr_specdata2 = be32_to_cpup(p++); | |
1da177e4 LT |
663 | break; |
664 | case NF4SOCK: | |
665 | case NF4FIFO: | |
666 | case NF4DIR: | |
667 | default: | |
668 | break; | |
669 | } | |
670 | ||
671 | READ_BUF(4); | |
06553991 | 672 | create->cr_namelen = be32_to_cpup(p++); |
1da177e4 LT |
673 | READ_BUF(create->cr_namelen); |
674 | SAVEMEM(create->cr_name, create->cr_namelen); | |
a36b1725 | 675 | if ((status = check_filename(create->cr_name, create->cr_namelen))) |
1da177e4 LT |
676 | return status; |
677 | ||
3c8e0316 | 678 | status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr, |
47057abd | 679 | &create->cr_acl, &create->cr_label, |
880a3a53 | 680 | &create->cr_umask); |
c0d6fc8a | 681 | if (status) |
1da177e4 LT |
682 | goto out; |
683 | ||
684 | DECODE_TAIL; | |
685 | } | |
686 | ||
b37ad28b | 687 | static inline __be32 |
1da177e4 LT |
688 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
689 | { | |
e31a1b66 | 690 | return nfsd4_decode_stateid(argp, &dr->dr_stateid); |
1da177e4 LT |
691 | } |
692 | ||
b37ad28b | 693 | static inline __be32 |
1da177e4 LT |
694 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
695 | { | |
696 | return nfsd4_decode_bitmap(argp, getattr->ga_bmval); | |
697 | } | |
698 | ||
b37ad28b | 699 | static __be32 |
1da177e4 LT |
700 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
701 | { | |
702 | DECODE_HEAD; | |
703 | ||
704 | READ_BUF(4); | |
06553991 | 705 | link->li_namelen = be32_to_cpup(p++); |
1da177e4 LT |
706 | READ_BUF(link->li_namelen); |
707 | SAVEMEM(link->li_name, link->li_namelen); | |
a36b1725 | 708 | if ((status = check_filename(link->li_name, link->li_namelen))) |
1da177e4 LT |
709 | return status; |
710 | ||
711 | DECODE_TAIL; | |
712 | } | |
713 | ||
b37ad28b | 714 | static __be32 |
1da177e4 LT |
715 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
716 | { | |
717 | DECODE_HEAD; | |
718 | ||
1da177e4 LT |
719 | /* |
720 | * type, reclaim(boolean), offset, length, new_lock_owner(boolean) | |
721 | */ | |
722 | READ_BUF(28); | |
06553991 | 723 | lock->lk_type = be32_to_cpup(p++); |
1da177e4 LT |
724 | if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT)) |
725 | goto xdr_error; | |
06553991 | 726 | lock->lk_reclaim = be32_to_cpup(p++); |
542d1ab3 BF |
727 | p = xdr_decode_hyper(p, &lock->lk_offset); |
728 | p = xdr_decode_hyper(p, &lock->lk_length); | |
06553991 | 729 | lock->lk_is_new = be32_to_cpup(p++); |
1da177e4 LT |
730 | |
731 | if (lock->lk_is_new) { | |
e31a1b66 | 732 | READ_BUF(4); |
06553991 | 733 | lock->lk_new_open_seqid = be32_to_cpup(p++); |
e31a1b66 BH |
734 | status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid); |
735 | if (status) | |
736 | return status; | |
737 | READ_BUF(8 + sizeof(clientid_t)); | |
06553991 | 738 | lock->lk_new_lock_seqid = be32_to_cpup(p++); |
1da177e4 | 739 | COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t)); |
06553991 | 740 | lock->lk_new_owner.len = be32_to_cpup(p++); |
1da177e4 LT |
741 | READ_BUF(lock->lk_new_owner.len); |
742 | READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len); | |
743 | } else { | |
e31a1b66 BH |
744 | status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid); |
745 | if (status) | |
746 | return status; | |
747 | READ_BUF(4); | |
06553991 | 748 | lock->lk_old_lock_seqid = be32_to_cpup(p++); |
1da177e4 LT |
749 | } |
750 | ||
751 | DECODE_TAIL; | |
752 | } | |
753 | ||
b37ad28b | 754 | static __be32 |
1da177e4 LT |
755 | nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
756 | { | |
757 | DECODE_HEAD; | |
758 | ||
759 | READ_BUF(32); | |
06553991 | 760 | lockt->lt_type = be32_to_cpup(p++); |
1da177e4 LT |
761 | if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
762 | goto xdr_error; | |
542d1ab3 BF |
763 | p = xdr_decode_hyper(p, &lockt->lt_offset); |
764 | p = xdr_decode_hyper(p, &lockt->lt_length); | |
1da177e4 | 765 | COPYMEM(&lockt->lt_clientid, 8); |
06553991 | 766 | lockt->lt_owner.len = be32_to_cpup(p++); |
1da177e4 LT |
767 | READ_BUF(lockt->lt_owner.len); |
768 | READMEM(lockt->lt_owner.data, lockt->lt_owner.len); | |
769 | ||
770 | DECODE_TAIL; | |
771 | } | |
772 | ||
b37ad28b | 773 | static __be32 |
1da177e4 LT |
774 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
775 | { | |
776 | DECODE_HEAD; | |
777 | ||
e31a1b66 | 778 | READ_BUF(8); |
06553991 | 779 | locku->lu_type = be32_to_cpup(p++); |
1da177e4 LT |
780 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) |
781 | goto xdr_error; | |
06553991 | 782 | locku->lu_seqid = be32_to_cpup(p++); |
e31a1b66 BH |
783 | status = nfsd4_decode_stateid(argp, &locku->lu_stateid); |
784 | if (status) | |
785 | return status; | |
786 | READ_BUF(16); | |
542d1ab3 BF |
787 | p = xdr_decode_hyper(p, &locku->lu_offset); |
788 | p = xdr_decode_hyper(p, &locku->lu_length); | |
1da177e4 LT |
789 | |
790 | DECODE_TAIL; | |
791 | } | |
792 | ||
b37ad28b | 793 | static __be32 |
1da177e4 LT |
794 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
795 | { | |
796 | DECODE_HEAD; | |
797 | ||
798 | READ_BUF(4); | |
06553991 | 799 | lookup->lo_len = be32_to_cpup(p++); |
1da177e4 LT |
800 | READ_BUF(lookup->lo_len); |
801 | SAVEMEM(lookup->lo_name, lookup->lo_len); | |
a36b1725 | 802 | if ((status = check_filename(lookup->lo_name, lookup->lo_len))) |
1da177e4 LT |
803 | return status; |
804 | ||
805 | DECODE_TAIL; | |
806 | } | |
807 | ||
2c8bd7e0 | 808 | static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *share_access, u32 *deleg_want, u32 *deleg_when) |
04f9e664 BF |
809 | { |
810 | __be32 *p; | |
811 | u32 w; | |
812 | ||
813 | READ_BUF(4); | |
06553991 | 814 | w = be32_to_cpup(p++); |
2c8bd7e0 BH |
815 | *share_access = w & NFS4_SHARE_ACCESS_MASK; |
816 | *deleg_want = w & NFS4_SHARE_WANT_MASK; | |
817 | if (deleg_when) | |
818 | *deleg_when = w & NFS4_SHARE_WHEN_MASK; | |
819 | ||
04f9e664 BF |
820 | switch (w & NFS4_SHARE_ACCESS_MASK) { |
821 | case NFS4_SHARE_ACCESS_READ: | |
822 | case NFS4_SHARE_ACCESS_WRITE: | |
823 | case NFS4_SHARE_ACCESS_BOTH: | |
824 | break; | |
825 | default: | |
826 | return nfserr_bad_xdr; | |
827 | } | |
fc0d14fe | 828 | w &= ~NFS4_SHARE_ACCESS_MASK; |
04f9e664 BF |
829 | if (!w) |
830 | return nfs_ok; | |
831 | if (!argp->minorversion) | |
832 | return nfserr_bad_xdr; | |
833 | switch (w & NFS4_SHARE_WANT_MASK) { | |
834 | case NFS4_SHARE_WANT_NO_PREFERENCE: | |
835 | case NFS4_SHARE_WANT_READ_DELEG: | |
836 | case NFS4_SHARE_WANT_WRITE_DELEG: | |
837 | case NFS4_SHARE_WANT_ANY_DELEG: | |
838 | case NFS4_SHARE_WANT_NO_DELEG: | |
839 | case NFS4_SHARE_WANT_CANCEL: | |
840 | break; | |
841 | default: | |
842 | return nfserr_bad_xdr; | |
843 | } | |
92bac8c5 | 844 | w &= ~NFS4_SHARE_WANT_MASK; |
04f9e664 BF |
845 | if (!w) |
846 | return nfs_ok; | |
2c8bd7e0 BH |
847 | |
848 | if (!deleg_when) /* open_downgrade */ | |
849 | return nfserr_inval; | |
04f9e664 BF |
850 | switch (w) { |
851 | case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL: | |
852 | case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED: | |
c668fc6d BH |
853 | case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL | |
854 | NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED): | |
04f9e664 BF |
855 | return nfs_ok; |
856 | } | |
857 | xdr_error: | |
858 | return nfserr_bad_xdr; | |
859 | } | |
860 | ||
861 | static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x) | |
862 | { | |
863 | __be32 *p; | |
864 | ||
865 | READ_BUF(4); | |
06553991 | 866 | *x = be32_to_cpup(p++); |
04f9e664 | 867 | /* Note: unlinke access bits, deny bits may be zero. */ |
01cd4afa | 868 | if (*x & ~NFS4_SHARE_DENY_BOTH) |
04f9e664 BF |
869 | return nfserr_bad_xdr; |
870 | return nfs_ok; | |
871 | xdr_error: | |
872 | return nfserr_bad_xdr; | |
873 | } | |
874 | ||
a084daf5 BF |
875 | static __be32 nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o) |
876 | { | |
877 | __be32 *p; | |
878 | ||
879 | READ_BUF(4); | |
06553991 | 880 | o->len = be32_to_cpup(p++); |
a084daf5 BF |
881 | |
882 | if (o->len == 0 || o->len > NFS4_OPAQUE_LIMIT) | |
883 | return nfserr_bad_xdr; | |
884 | ||
885 | READ_BUF(o->len); | |
886 | SAVEMEM(o->data, o->len); | |
887 | return nfs_ok; | |
888 | xdr_error: | |
889 | return nfserr_bad_xdr; | |
890 | } | |
891 | ||
b37ad28b | 892 | static __be32 |
1da177e4 LT |
893 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
894 | { | |
895 | DECODE_HEAD; | |
2c8bd7e0 | 896 | u32 dummy; |
1da177e4 LT |
897 | |
898 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); | |
899 | open->op_iattr.ia_valid = 0; | |
fe0750e5 | 900 | open->op_openowner = NULL; |
1da177e4 | 901 | |
9d313b17 | 902 | open->op_xdr_error = 0; |
1da177e4 | 903 | /* seqid, share_access, share_deny, clientid, ownerlen */ |
04f9e664 | 904 | READ_BUF(4); |
06553991 | 905 | open->op_seqid = be32_to_cpup(p++); |
2c8bd7e0 BH |
906 | /* decode, yet ignore deleg_when until supported */ |
907 | status = nfsd4_decode_share_access(argp, &open->op_share_access, | |
908 | &open->op_deleg_want, &dummy); | |
04f9e664 BF |
909 | if (status) |
910 | goto xdr_error; | |
911 | status = nfsd4_decode_share_deny(argp, &open->op_share_deny); | |
912 | if (status) | |
913 | goto xdr_error; | |
a084daf5 | 914 | READ_BUF(sizeof(clientid_t)); |
1da177e4 | 915 | COPYMEM(&open->op_clientid, sizeof(clientid_t)); |
a084daf5 BF |
916 | status = nfsd4_decode_opaque(argp, &open->op_owner); |
917 | if (status) | |
918 | goto xdr_error; | |
919 | READ_BUF(4); | |
06553991 | 920 | open->op_create = be32_to_cpup(p++); |
1da177e4 LT |
921 | switch (open->op_create) { |
922 | case NFS4_OPEN_NOCREATE: | |
923 | break; | |
924 | case NFS4_OPEN_CREATE: | |
925 | READ_BUF(4); | |
06553991 | 926 | open->op_createmode = be32_to_cpup(p++); |
1da177e4 LT |
927 | switch (open->op_createmode) { |
928 | case NFS4_CREATE_UNCHECKED: | |
929 | case NFS4_CREATE_GUARDED: | |
c0d6fc8a | 930 | status = nfsd4_decode_fattr(argp, open->op_bmval, |
47057abd | 931 | &open->op_iattr, &open->op_acl, &open->op_label, |
880a3a53 | 932 | &open->op_umask); |
c0d6fc8a | 933 | if (status) |
1da177e4 LT |
934 | goto out; |
935 | break; | |
936 | case NFS4_CREATE_EXCLUSIVE: | |
ab4684d1 CL |
937 | READ_BUF(NFS4_VERIFIER_SIZE); |
938 | COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE); | |
1da177e4 | 939 | break; |
79fb54ab BH |
940 | case NFS4_CREATE_EXCLUSIVE4_1: |
941 | if (argp->minorversion < 1) | |
942 | goto xdr_error; | |
ab4684d1 CL |
943 | READ_BUF(NFS4_VERIFIER_SIZE); |
944 | COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE); | |
79fb54ab | 945 | status = nfsd4_decode_fattr(argp, open->op_bmval, |
47057abd | 946 | &open->op_iattr, &open->op_acl, &open->op_label, |
880a3a53 | 947 | &open->op_umask); |
79fb54ab BH |
948 | if (status) |
949 | goto out; | |
950 | break; | |
1da177e4 LT |
951 | default: |
952 | goto xdr_error; | |
953 | } | |
954 | break; | |
955 | default: | |
956 | goto xdr_error; | |
957 | } | |
958 | ||
959 | /* open_claim */ | |
960 | READ_BUF(4); | |
06553991 | 961 | open->op_claim_type = be32_to_cpup(p++); |
1da177e4 LT |
962 | switch (open->op_claim_type) { |
963 | case NFS4_OPEN_CLAIM_NULL: | |
964 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: | |
965 | READ_BUF(4); | |
06553991 | 966 | open->op_fname.len = be32_to_cpup(p++); |
1da177e4 LT |
967 | READ_BUF(open->op_fname.len); |
968 | SAVEMEM(open->op_fname.data, open->op_fname.len); | |
a36b1725 | 969 | if ((status = check_filename(open->op_fname.data, open->op_fname.len))) |
1da177e4 LT |
970 | return status; |
971 | break; | |
972 | case NFS4_OPEN_CLAIM_PREVIOUS: | |
973 | READ_BUF(4); | |
06553991 | 974 | open->op_delegate_type = be32_to_cpup(p++); |
1da177e4 LT |
975 | break; |
976 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | |
e31a1b66 BH |
977 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); |
978 | if (status) | |
979 | return status; | |
980 | READ_BUF(4); | |
06553991 | 981 | open->op_fname.len = be32_to_cpup(p++); |
1da177e4 LT |
982 | READ_BUF(open->op_fname.len); |
983 | SAVEMEM(open->op_fname.data, open->op_fname.len); | |
a36b1725 | 984 | if ((status = check_filename(open->op_fname.data, open->op_fname.len))) |
1da177e4 LT |
985 | return status; |
986 | break; | |
8b289b2c BF |
987 | case NFS4_OPEN_CLAIM_FH: |
988 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | |
989 | if (argp->minorversion < 1) | |
990 | goto xdr_error; | |
991 | /* void */ | |
992 | break; | |
993 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | |
994 | if (argp->minorversion < 1) | |
995 | goto xdr_error; | |
996 | status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid); | |
997 | if (status) | |
998 | return status; | |
999 | break; | |
1da177e4 LT |
1000 | default: |
1001 | goto xdr_error; | |
1002 | } | |
1003 | ||
1004 | DECODE_TAIL; | |
1005 | } | |
1006 | ||
b37ad28b | 1007 | static __be32 |
1da177e4 LT |
1008 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
1009 | { | |
1010 | DECODE_HEAD; | |
e1a90ebd AS |
1011 | |
1012 | if (argp->minorversion >= 1) | |
1013 | return nfserr_notsupp; | |
1014 | ||
e31a1b66 BH |
1015 | status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid); |
1016 | if (status) | |
1017 | return status; | |
1018 | READ_BUF(4); | |
06553991 | 1019 | open_conf->oc_seqid = be32_to_cpup(p++); |
e1a90ebd | 1020 | |
1da177e4 LT |
1021 | DECODE_TAIL; |
1022 | } | |
1023 | ||
b37ad28b | 1024 | static __be32 |
1da177e4 LT |
1025 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
1026 | { | |
1027 | DECODE_HEAD; | |
1028 | ||
e31a1b66 BH |
1029 | status = nfsd4_decode_stateid(argp, &open_down->od_stateid); |
1030 | if (status) | |
1031 | return status; | |
04f9e664 | 1032 | READ_BUF(4); |
06553991 | 1033 | open_down->od_seqid = be32_to_cpup(p++); |
2c8bd7e0 BH |
1034 | status = nfsd4_decode_share_access(argp, &open_down->od_share_access, |
1035 | &open_down->od_deleg_want, NULL); | |
04f9e664 BF |
1036 | if (status) |
1037 | return status; | |
1038 | status = nfsd4_decode_share_deny(argp, &open_down->od_share_deny); | |
1039 | if (status) | |
1040 | return status; | |
1da177e4 LT |
1041 | DECODE_TAIL; |
1042 | } | |
1043 | ||
b37ad28b | 1044 | static __be32 |
1da177e4 LT |
1045 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
1046 | { | |
1047 | DECODE_HEAD; | |
1048 | ||
1049 | READ_BUF(4); | |
06553991 | 1050 | putfh->pf_fhlen = be32_to_cpup(p++); |
1da177e4 LT |
1051 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
1052 | goto xdr_error; | |
1053 | READ_BUF(putfh->pf_fhlen); | |
1054 | SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen); | |
1055 | ||
1056 | DECODE_TAIL; | |
1057 | } | |
1058 | ||
e1a90ebd AS |
1059 | static __be32 |
1060 | nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p) | |
1061 | { | |
1062 | if (argp->minorversion == 0) | |
1063 | return nfs_ok; | |
1064 | return nfserr_notsupp; | |
1065 | } | |
1066 | ||
b37ad28b | 1067 | static __be32 |
1da177e4 LT |
1068 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
1069 | { | |
1070 | DECODE_HEAD; | |
1071 | ||
e31a1b66 BH |
1072 | status = nfsd4_decode_stateid(argp, &read->rd_stateid); |
1073 | if (status) | |
1074 | return status; | |
1075 | READ_BUF(12); | |
542d1ab3 | 1076 | p = xdr_decode_hyper(p, &read->rd_offset); |
06553991 | 1077 | read->rd_length = be32_to_cpup(p++); |
1da177e4 LT |
1078 | |
1079 | DECODE_TAIL; | |
1080 | } | |
1081 | ||
b37ad28b | 1082 | static __be32 |
1da177e4 LT |
1083 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
1084 | { | |
1085 | DECODE_HEAD; | |
1086 | ||
1087 | READ_BUF(24); | |
542d1ab3 | 1088 | p = xdr_decode_hyper(p, &readdir->rd_cookie); |
1da177e4 | 1089 | COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data)); |
06553991 BF |
1090 | readdir->rd_dircount = be32_to_cpup(p++); |
1091 | readdir->rd_maxcount = be32_to_cpup(p++); | |
1da177e4 LT |
1092 | if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval))) |
1093 | goto out; | |
1094 | ||
1095 | DECODE_TAIL; | |
1096 | } | |
1097 | ||
b37ad28b | 1098 | static __be32 |
1da177e4 LT |
1099 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
1100 | { | |
1101 | DECODE_HEAD; | |
1102 | ||
1103 | READ_BUF(4); | |
06553991 | 1104 | remove->rm_namelen = be32_to_cpup(p++); |
1da177e4 LT |
1105 | READ_BUF(remove->rm_namelen); |
1106 | SAVEMEM(remove->rm_name, remove->rm_namelen); | |
a36b1725 | 1107 | if ((status = check_filename(remove->rm_name, remove->rm_namelen))) |
1da177e4 LT |
1108 | return status; |
1109 | ||
1110 | DECODE_TAIL; | |
1111 | } | |
1112 | ||
b37ad28b | 1113 | static __be32 |
1da177e4 LT |
1114 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
1115 | { | |
1116 | DECODE_HEAD; | |
1117 | ||
1118 | READ_BUF(4); | |
06553991 | 1119 | rename->rn_snamelen = be32_to_cpup(p++); |
4aed9c46 | 1120 | READ_BUF(rename->rn_snamelen); |
1da177e4 | 1121 | SAVEMEM(rename->rn_sname, rename->rn_snamelen); |
4aed9c46 | 1122 | READ_BUF(4); |
06553991 | 1123 | rename->rn_tnamelen = be32_to_cpup(p++); |
1da177e4 LT |
1124 | READ_BUF(rename->rn_tnamelen); |
1125 | SAVEMEM(rename->rn_tname, rename->rn_tnamelen); | |
a36b1725 | 1126 | if ((status = check_filename(rename->rn_sname, rename->rn_snamelen))) |
1da177e4 | 1127 | return status; |
a36b1725 | 1128 | if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen))) |
1da177e4 LT |
1129 | return status; |
1130 | ||
1131 | DECODE_TAIL; | |
1132 | } | |
1133 | ||
b37ad28b | 1134 | static __be32 |
1da177e4 LT |
1135 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
1136 | { | |
1137 | DECODE_HEAD; | |
1138 | ||
e1a90ebd AS |
1139 | if (argp->minorversion >= 1) |
1140 | return nfserr_notsupp; | |
1141 | ||
1da177e4 LT |
1142 | READ_BUF(sizeof(clientid_t)); |
1143 | COPYMEM(clientid, sizeof(clientid_t)); | |
1144 | ||
1145 | DECODE_TAIL; | |
1146 | } | |
1147 | ||
dcb488a3 AA |
1148 | static __be32 |
1149 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, | |
1150 | struct nfsd4_secinfo *secinfo) | |
1151 | { | |
1152 | DECODE_HEAD; | |
1153 | ||
1154 | READ_BUF(4); | |
06553991 | 1155 | secinfo->si_namelen = be32_to_cpup(p++); |
dcb488a3 AA |
1156 | READ_BUF(secinfo->si_namelen); |
1157 | SAVEMEM(secinfo->si_name, secinfo->si_namelen); | |
a36b1725 | 1158 | status = check_filename(secinfo->si_name, secinfo->si_namelen); |
dcb488a3 AA |
1159 | if (status) |
1160 | return status; | |
1161 | DECODE_TAIL; | |
1162 | } | |
1163 | ||
04f4ad16 BF |
1164 | static __be32 |
1165 | nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp, | |
1166 | struct nfsd4_secinfo_no_name *sin) | |
1167 | { | |
1168 | DECODE_HEAD; | |
1169 | ||
1170 | READ_BUF(4); | |
06553991 | 1171 | sin->sin_style = be32_to_cpup(p++); |
04f4ad16 BF |
1172 | DECODE_TAIL; |
1173 | } | |
1174 | ||
b37ad28b | 1175 | static __be32 |
1da177e4 LT |
1176 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
1177 | { | |
e31a1b66 | 1178 | __be32 status; |
1da177e4 | 1179 | |
e31a1b66 BH |
1180 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); |
1181 | if (status) | |
1182 | return status; | |
3c8e0316 | 1183 | return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr, |
47057abd | 1184 | &setattr->sa_acl, &setattr->sa_label, NULL); |
1da177e4 LT |
1185 | } |
1186 | ||
b37ad28b | 1187 | static __be32 |
1da177e4 LT |
1188 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
1189 | { | |
1190 | DECODE_HEAD; | |
1191 | ||
e1a90ebd AS |
1192 | if (argp->minorversion >= 1) |
1193 | return nfserr_notsupp; | |
1194 | ||
ab4684d1 CL |
1195 | READ_BUF(NFS4_VERIFIER_SIZE); |
1196 | COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE); | |
1da177e4 | 1197 | |
a084daf5 BF |
1198 | status = nfsd4_decode_opaque(argp, &setclientid->se_name); |
1199 | if (status) | |
1200 | return nfserr_bad_xdr; | |
1201 | READ_BUF(8); | |
06553991 BF |
1202 | setclientid->se_callback_prog = be32_to_cpup(p++); |
1203 | setclientid->se_callback_netid_len = be32_to_cpup(p++); | |
4aed9c46 | 1204 | READ_BUF(setclientid->se_callback_netid_len); |
1da177e4 | 1205 | SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len); |
4aed9c46 | 1206 | READ_BUF(4); |
06553991 | 1207 | setclientid->se_callback_addr_len = be32_to_cpup(p++); |
1da177e4 | 1208 | |
4aed9c46 | 1209 | READ_BUF(setclientid->se_callback_addr_len); |
1da177e4 | 1210 | SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len); |
4aed9c46 | 1211 | READ_BUF(4); |
06553991 | 1212 | setclientid->se_callback_ident = be32_to_cpup(p++); |
1da177e4 LT |
1213 | |
1214 | DECODE_TAIL; | |
1215 | } | |
1216 | ||
b37ad28b | 1217 | static __be32 |
1da177e4 LT |
1218 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
1219 | { | |
1220 | DECODE_HEAD; | |
1221 | ||
e1a90ebd AS |
1222 | if (argp->minorversion >= 1) |
1223 | return nfserr_notsupp; | |
1224 | ||
ab4684d1 | 1225 | READ_BUF(8 + NFS4_VERIFIER_SIZE); |
1da177e4 | 1226 | COPYMEM(&scd_c->sc_clientid, 8); |
ab4684d1 | 1227 | COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE); |
1da177e4 LT |
1228 | |
1229 | DECODE_TAIL; | |
1230 | } | |
1231 | ||
1232 | /* Also used for NVERIFY */ | |
b37ad28b | 1233 | static __be32 |
1da177e4 LT |
1234 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
1235 | { | |
1da177e4 LT |
1236 | DECODE_HEAD; |
1237 | ||
1238 | if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval))) | |
1239 | goto out; | |
1240 | ||
1241 | /* For convenience's sake, we compare raw xdr'd attributes in | |
e5f95703 BF |
1242 | * nfsd4_proc_verify */ |
1243 | ||
1da177e4 | 1244 | READ_BUF(4); |
06553991 | 1245 | verify->ve_attrlen = be32_to_cpup(p++); |
1da177e4 LT |
1246 | READ_BUF(verify->ve_attrlen); |
1247 | SAVEMEM(verify->ve_attrval, verify->ve_attrlen); | |
1248 | ||
1249 | DECODE_TAIL; | |
1250 | } | |
1251 | ||
b37ad28b | 1252 | static __be32 |
1da177e4 LT |
1253 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
1254 | { | |
1255 | int avail; | |
1da177e4 LT |
1256 | int len; |
1257 | DECODE_HEAD; | |
1258 | ||
e31a1b66 BH |
1259 | status = nfsd4_decode_stateid(argp, &write->wr_stateid); |
1260 | if (status) | |
1261 | return status; | |
1262 | READ_BUF(16); | |
542d1ab3 | 1263 | p = xdr_decode_hyper(p, &write->wr_offset); |
06553991 | 1264 | write->wr_stable_how = be32_to_cpup(p++); |
54bbb7d2 | 1265 | if (write->wr_stable_how > NFS_FILE_SYNC) |
1da177e4 | 1266 | goto xdr_error; |
06553991 | 1267 | write->wr_buflen = be32_to_cpup(p++); |
1da177e4 LT |
1268 | |
1269 | /* Sorry .. no magic macros for this.. * | |
1270 | * READ_BUF(write->wr_buflen); | |
1271 | * SAVEMEM(write->wr_buf, write->wr_buflen); | |
1272 | */ | |
1273 | avail = (char*)argp->end - (char*)argp->p; | |
1274 | if (avail + argp->pagelen < write->wr_buflen) { | |
817cb9d4 CL |
1275 | dprintk("NFSD: xdr error (%s:%d)\n", |
1276 | __FILE__, __LINE__); | |
1da177e4 LT |
1277 | goto xdr_error; |
1278 | } | |
70cc7f75 BF |
1279 | write->wr_head.iov_base = p; |
1280 | write->wr_head.iov_len = avail; | |
70cc7f75 | 1281 | write->wr_pagelist = argp->pagelist; |
5a80a54d BF |
1282 | |
1283 | len = XDR_QUADLEN(write->wr_buflen) << 2; | |
1284 | if (len >= avail) { | |
1285 | int pages; | |
1286 | ||
1287 | len -= avail; | |
1288 | ||
1289 | pages = len >> PAGE_SHIFT; | |
1290 | argp->pagelist += pages; | |
1291 | argp->pagelen -= pages * PAGE_SIZE; | |
1292 | len -= pages * PAGE_SIZE; | |
1293 | ||
fc788f64 | 1294 | next_decode_page(argp); |
1da177e4 | 1295 | } |
5a80a54d | 1296 | argp->p += XDR_QUADLEN(len); |
1da177e4 LT |
1297 | |
1298 | DECODE_TAIL; | |
1299 | } | |
1300 | ||
b37ad28b | 1301 | static __be32 |
1da177e4 LT |
1302 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
1303 | { | |
1304 | DECODE_HEAD; | |
1305 | ||
e1a90ebd AS |
1306 | if (argp->minorversion >= 1) |
1307 | return nfserr_notsupp; | |
1308 | ||
1da177e4 LT |
1309 | READ_BUF(12); |
1310 | COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t)); | |
06553991 | 1311 | rlockowner->rl_owner.len = be32_to_cpup(p++); |
1da177e4 LT |
1312 | READ_BUF(rlockowner->rl_owner.len); |
1313 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); | |
1314 | ||
60adfc50 AA |
1315 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) |
1316 | return nfserr_inval; | |
1da177e4 LT |
1317 | DECODE_TAIL; |
1318 | } | |
1319 | ||
2db134eb AA |
1320 | static __be32 |
1321 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, | |
0733d213 | 1322 | struct nfsd4_exchange_id *exid) |
2db134eb | 1323 | { |
5afa040b | 1324 | int dummy, tmp; |
0733d213 AA |
1325 | DECODE_HEAD; |
1326 | ||
1327 | READ_BUF(NFS4_VERIFIER_SIZE); | |
1328 | COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE); | |
1329 | ||
a084daf5 BF |
1330 | status = nfsd4_decode_opaque(argp, &exid->clname); |
1331 | if (status) | |
1332 | return nfserr_bad_xdr; | |
0733d213 AA |
1333 | |
1334 | READ_BUF(4); | |
06553991 | 1335 | exid->flags = be32_to_cpup(p++); |
0733d213 AA |
1336 | |
1337 | /* Ignore state_protect4_a */ | |
1338 | READ_BUF(4); | |
06553991 | 1339 | exid->spa_how = be32_to_cpup(p++); |
0733d213 AA |
1340 | switch (exid->spa_how) { |
1341 | case SP4_NONE: | |
1342 | break; | |
1343 | case SP4_MACH_CRED: | |
1344 | /* spo_must_enforce */ | |
ed941643 AE |
1345 | status = nfsd4_decode_bitmap(argp, |
1346 | exid->spo_must_enforce); | |
1347 | if (status) | |
1348 | goto out; | |
0733d213 | 1349 | /* spo_must_allow */ |
ed941643 AE |
1350 | status = nfsd4_decode_bitmap(argp, exid->spo_must_allow); |
1351 | if (status) | |
1352 | goto out; | |
0733d213 AA |
1353 | break; |
1354 | case SP4_SSV: | |
1355 | /* ssp_ops */ | |
1356 | READ_BUF(4); | |
06553991 | 1357 | dummy = be32_to_cpup(p++); |
0733d213 AA |
1358 | READ_BUF(dummy * 4); |
1359 | p += dummy; | |
1360 | ||
1361 | READ_BUF(4); | |
06553991 | 1362 | dummy = be32_to_cpup(p++); |
0733d213 AA |
1363 | READ_BUF(dummy * 4); |
1364 | p += dummy; | |
1365 | ||
1366 | /* ssp_hash_algs<> */ | |
1367 | READ_BUF(4); | |
06553991 | 1368 | tmp = be32_to_cpup(p++); |
5afa040b MJ |
1369 | while (tmp--) { |
1370 | READ_BUF(4); | |
06553991 | 1371 | dummy = be32_to_cpup(p++); |
5afa040b MJ |
1372 | READ_BUF(dummy); |
1373 | p += XDR_QUADLEN(dummy); | |
1374 | } | |
0733d213 AA |
1375 | |
1376 | /* ssp_encr_algs<> */ | |
1377 | READ_BUF(4); | |
06553991 | 1378 | tmp = be32_to_cpup(p++); |
5afa040b MJ |
1379 | while (tmp--) { |
1380 | READ_BUF(4); | |
06553991 | 1381 | dummy = be32_to_cpup(p++); |
5afa040b MJ |
1382 | READ_BUF(dummy); |
1383 | p += XDR_QUADLEN(dummy); | |
1384 | } | |
0733d213 | 1385 | |
5ed96bc5 | 1386 | /* ignore ssp_window and ssp_num_gss_handles: */ |
0733d213 | 1387 | READ_BUF(8); |
0733d213 AA |
1388 | break; |
1389 | default: | |
1390 | goto xdr_error; | |
1391 | } | |
1392 | ||
0733d213 | 1393 | READ_BUF(4); /* nfs_impl_id4 array length */ |
06553991 | 1394 | dummy = be32_to_cpup(p++); |
0733d213 AA |
1395 | |
1396 | if (dummy > 1) | |
1397 | goto xdr_error; | |
1398 | ||
1399 | if (dummy == 1) { | |
79123444 BF |
1400 | status = nfsd4_decode_opaque(argp, &exid->nii_domain); |
1401 | if (status) | |
1402 | goto xdr_error; | |
0733d213 AA |
1403 | |
1404 | /* nii_name */ | |
79123444 BF |
1405 | status = nfsd4_decode_opaque(argp, &exid->nii_name); |
1406 | if (status) | |
1407 | goto xdr_error; | |
0733d213 AA |
1408 | |
1409 | /* nii_date */ | |
79123444 BF |
1410 | status = nfsd4_decode_time(argp, &exid->nii_time); |
1411 | if (status) | |
1412 | goto xdr_error; | |
0733d213 AA |
1413 | } |
1414 | DECODE_TAIL; | |
2db134eb AA |
1415 | } |
1416 | ||
1417 | static __be32 | |
1418 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, | |
1419 | struct nfsd4_create_session *sess) | |
1420 | { | |
ec6b5d7b | 1421 | DECODE_HEAD; |
ec6b5d7b AA |
1422 | |
1423 | READ_BUF(16); | |
1424 | COPYMEM(&sess->clientid, 8); | |
06553991 BF |
1425 | sess->seqid = be32_to_cpup(p++); |
1426 | sess->flags = be32_to_cpup(p++); | |
ec6b5d7b AA |
1427 | |
1428 | /* Fore channel attrs */ | |
1429 | READ_BUF(28); | |
b96811cd | 1430 | p++; /* headerpadsz is always 0 */ |
06553991 BF |
1431 | sess->fore_channel.maxreq_sz = be32_to_cpup(p++); |
1432 | sess->fore_channel.maxresp_sz = be32_to_cpup(p++); | |
1433 | sess->fore_channel.maxresp_cached = be32_to_cpup(p++); | |
1434 | sess->fore_channel.maxops = be32_to_cpup(p++); | |
1435 | sess->fore_channel.maxreqs = be32_to_cpup(p++); | |
1436 | sess->fore_channel.nr_rdma_attrs = be32_to_cpup(p++); | |
ec6b5d7b AA |
1437 | if (sess->fore_channel.nr_rdma_attrs == 1) { |
1438 | READ_BUF(4); | |
06553991 | 1439 | sess->fore_channel.rdma_attrs = be32_to_cpup(p++); |
ec6b5d7b AA |
1440 | } else if (sess->fore_channel.nr_rdma_attrs > 1) { |
1441 | dprintk("Too many fore channel attr bitmaps!\n"); | |
1442 | goto xdr_error; | |
1443 | } | |
1444 | ||
1445 | /* Back channel attrs */ | |
1446 | READ_BUF(28); | |
b96811cd | 1447 | p++; /* headerpadsz is always 0 */ |
06553991 BF |
1448 | sess->back_channel.maxreq_sz = be32_to_cpup(p++); |
1449 | sess->back_channel.maxresp_sz = be32_to_cpup(p++); | |
1450 | sess->back_channel.maxresp_cached = be32_to_cpup(p++); | |
1451 | sess->back_channel.maxops = be32_to_cpup(p++); | |
1452 | sess->back_channel.maxreqs = be32_to_cpup(p++); | |
1453 | sess->back_channel.nr_rdma_attrs = be32_to_cpup(p++); | |
ec6b5d7b AA |
1454 | if (sess->back_channel.nr_rdma_attrs == 1) { |
1455 | READ_BUF(4); | |
06553991 | 1456 | sess->back_channel.rdma_attrs = be32_to_cpup(p++); |
ec6b5d7b AA |
1457 | } else if (sess->back_channel.nr_rdma_attrs > 1) { |
1458 | dprintk("Too many back channel attr bitmaps!\n"); | |
1459 | goto xdr_error; | |
1460 | } | |
1461 | ||
acb2887e | 1462 | READ_BUF(4); |
06553991 | 1463 | sess->callback_prog = be32_to_cpup(p++); |
acb2887e | 1464 | nfsd4_decode_cb_sec(argp, &sess->cb_sec); |
ec6b5d7b | 1465 | DECODE_TAIL; |
2db134eb AA |
1466 | } |
1467 | ||
1468 | static __be32 | |
1469 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, | |
1470 | struct nfsd4_destroy_session *destroy_session) | |
1471 | { | |
e10e0cfc BH |
1472 | DECODE_HEAD; |
1473 | READ_BUF(NFS4_MAX_SESSIONID_LEN); | |
1474 | COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN); | |
1475 | ||
1476 | DECODE_TAIL; | |
2db134eb AA |
1477 | } |
1478 | ||
e1ca12df BS |
1479 | static __be32 |
1480 | nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, | |
1481 | struct nfsd4_free_stateid *free_stateid) | |
1482 | { | |
1483 | DECODE_HEAD; | |
1484 | ||
1485 | READ_BUF(sizeof(stateid_t)); | |
06553991 | 1486 | free_stateid->fr_stateid.si_generation = be32_to_cpup(p++); |
e1ca12df BS |
1487 | COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t)); |
1488 | ||
1489 | DECODE_TAIL; | |
1490 | } | |
1491 | ||
2db134eb AA |
1492 | static __be32 |
1493 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, | |
1494 | struct nfsd4_sequence *seq) | |
1495 | { | |
b85d4c01 BH |
1496 | DECODE_HEAD; |
1497 | ||
1498 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); | |
1499 | COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); | |
06553991 BF |
1500 | seq->seqid = be32_to_cpup(p++); |
1501 | seq->slotid = be32_to_cpup(p++); | |
1502 | seq->maxslots = be32_to_cpup(p++); | |
1503 | seq->cachethis = be32_to_cpup(p++); | |
b85d4c01 BH |
1504 | |
1505 | DECODE_TAIL; | |
2db134eb AA |
1506 | } |
1507 | ||
17456804 BS |
1508 | static __be32 |
1509 | nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid) | |
1510 | { | |
17456804 | 1511 | int i; |
03cfb420 BS |
1512 | __be32 *p, status; |
1513 | struct nfsd4_test_stateid_id *stateid; | |
17456804 BS |
1514 | |
1515 | READ_BUF(4); | |
1516 | test_stateid->ts_num_ids = ntohl(*p++); | |
1517 | ||
03cfb420 | 1518 | INIT_LIST_HEAD(&test_stateid->ts_stateid_list); |
17456804 BS |
1519 | |
1520 | for (i = 0; i < test_stateid->ts_num_ids; i++) { | |
d5e23383 | 1521 | stateid = svcxdr_tmpalloc(argp, sizeof(*stateid)); |
03cfb420 | 1522 | if (!stateid) { |
afcf6792 | 1523 | status = nfserrno(-ENOMEM); |
03cfb420 BS |
1524 | goto out; |
1525 | } | |
1526 | ||
03cfb420 BS |
1527 | INIT_LIST_HEAD(&stateid->ts_id_list); |
1528 | list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list); | |
1529 | ||
1530 | status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid); | |
17456804 | 1531 | if (status) |
03cfb420 | 1532 | goto out; |
17456804 BS |
1533 | } |
1534 | ||
1535 | status = 0; | |
1536 | out: | |
1537 | return status; | |
1538 | xdr_error: | |
1539 | dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__); | |
1540 | status = nfserr_bad_xdr; | |
1541 | goto out; | |
1542 | } | |
1543 | ||
345c2842 MJ |
1544 | static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc) |
1545 | { | |
1546 | DECODE_HEAD; | |
1547 | ||
1548 | READ_BUF(8); | |
1549 | COPYMEM(&dc->clientid, 8); | |
1550 | ||
1551 | DECODE_TAIL; | |
1552 | } | |
1553 | ||
4dc6ec00 BF |
1554 | static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc) |
1555 | { | |
1556 | DECODE_HEAD; | |
1557 | ||
1558 | READ_BUF(4); | |
06553991 | 1559 | rc->rca_one_fs = be32_to_cpup(p++); |
4dc6ec00 BF |
1560 | |
1561 | DECODE_TAIL; | |
1562 | } | |
1563 | ||
9cf514cc CH |
1564 | #ifdef CONFIG_NFSD_PNFS |
1565 | static __be32 | |
1566 | nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp, | |
1567 | struct nfsd4_getdeviceinfo *gdev) | |
1568 | { | |
1569 | DECODE_HEAD; | |
1570 | u32 num, i; | |
1571 | ||
1572 | READ_BUF(sizeof(struct nfsd4_deviceid) + 3 * 4); | |
1573 | COPYMEM(&gdev->gd_devid, sizeof(struct nfsd4_deviceid)); | |
1574 | gdev->gd_layout_type = be32_to_cpup(p++); | |
1575 | gdev->gd_maxcount = be32_to_cpup(p++); | |
1576 | num = be32_to_cpup(p++); | |
1577 | if (num) { | |
3171822f SM |
1578 | if (num > 1000) |
1579 | goto xdr_error; | |
9cf514cc CH |
1580 | READ_BUF(4 * num); |
1581 | gdev->gd_notify_types = be32_to_cpup(p++); | |
1582 | for (i = 1; i < num; i++) { | |
1583 | if (be32_to_cpup(p++)) { | |
1584 | status = nfserr_inval; | |
1585 | goto out; | |
1586 | } | |
1587 | } | |
1588 | } | |
1589 | DECODE_TAIL; | |
1590 | } | |
1591 | ||
1592 | static __be32 | |
1593 | nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp, | |
1594 | struct nfsd4_layoutget *lgp) | |
1595 | { | |
1596 | DECODE_HEAD; | |
1597 | ||
1598 | READ_BUF(36); | |
1599 | lgp->lg_signal = be32_to_cpup(p++); | |
1600 | lgp->lg_layout_type = be32_to_cpup(p++); | |
1601 | lgp->lg_seg.iomode = be32_to_cpup(p++); | |
1602 | p = xdr_decode_hyper(p, &lgp->lg_seg.offset); | |
1603 | p = xdr_decode_hyper(p, &lgp->lg_seg.length); | |
1604 | p = xdr_decode_hyper(p, &lgp->lg_minlength); | |
db59c0ef KM |
1605 | |
1606 | status = nfsd4_decode_stateid(argp, &lgp->lg_sid); | |
1607 | if (status) | |
1608 | return status; | |
1609 | ||
9cf514cc CH |
1610 | READ_BUF(4); |
1611 | lgp->lg_maxcount = be32_to_cpup(p++); | |
1612 | ||
1613 | DECODE_TAIL; | |
1614 | } | |
1615 | ||
1616 | static __be32 | |
1617 | nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, | |
1618 | struct nfsd4_layoutcommit *lcp) | |
1619 | { | |
1620 | DECODE_HEAD; | |
1621 | u32 timechange; | |
1622 | ||
1623 | READ_BUF(20); | |
1624 | p = xdr_decode_hyper(p, &lcp->lc_seg.offset); | |
1625 | p = xdr_decode_hyper(p, &lcp->lc_seg.length); | |
1626 | lcp->lc_reclaim = be32_to_cpup(p++); | |
db59c0ef KM |
1627 | |
1628 | status = nfsd4_decode_stateid(argp, &lcp->lc_sid); | |
1629 | if (status) | |
1630 | return status; | |
1631 | ||
9cf514cc CH |
1632 | READ_BUF(4); |
1633 | lcp->lc_newoffset = be32_to_cpup(p++); | |
1634 | if (lcp->lc_newoffset) { | |
1635 | READ_BUF(8); | |
1636 | p = xdr_decode_hyper(p, &lcp->lc_last_wr); | |
1637 | } else | |
1638 | lcp->lc_last_wr = 0; | |
1639 | READ_BUF(4); | |
1640 | timechange = be32_to_cpup(p++); | |
1641 | if (timechange) { | |
1642 | status = nfsd4_decode_time(argp, &lcp->lc_mtime); | |
1643 | if (status) | |
1644 | return status; | |
1645 | } else { | |
1646 | lcp->lc_mtime.tv_nsec = UTIME_NOW; | |
1647 | } | |
1648 | READ_BUF(8); | |
1649 | lcp->lc_layout_type = be32_to_cpup(p++); | |
1650 | ||
1651 | /* | |
1652 | * Save the layout update in XDR format and let the layout driver deal | |
1653 | * with it later. | |
1654 | */ | |
1655 | lcp->lc_up_len = be32_to_cpup(p++); | |
1656 | if (lcp->lc_up_len > 0) { | |
1657 | READ_BUF(lcp->lc_up_len); | |
1658 | READMEM(lcp->lc_up_layout, lcp->lc_up_len); | |
1659 | } | |
1660 | ||
1661 | DECODE_TAIL; | |
1662 | } | |
1663 | ||
1664 | static __be32 | |
1665 | nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp, | |
1666 | struct nfsd4_layoutreturn *lrp) | |
1667 | { | |
1668 | DECODE_HEAD; | |
1669 | ||
1670 | READ_BUF(16); | |
1671 | lrp->lr_reclaim = be32_to_cpup(p++); | |
1672 | lrp->lr_layout_type = be32_to_cpup(p++); | |
1673 | lrp->lr_seg.iomode = be32_to_cpup(p++); | |
1674 | lrp->lr_return_type = be32_to_cpup(p++); | |
1675 | if (lrp->lr_return_type == RETURN_FILE) { | |
1676 | READ_BUF(16); | |
1677 | p = xdr_decode_hyper(p, &lrp->lr_seg.offset); | |
1678 | p = xdr_decode_hyper(p, &lrp->lr_seg.length); | |
db59c0ef KM |
1679 | |
1680 | status = nfsd4_decode_stateid(argp, &lrp->lr_sid); | |
1681 | if (status) | |
1682 | return status; | |
1683 | ||
9cf514cc CH |
1684 | READ_BUF(4); |
1685 | lrp->lrf_body_len = be32_to_cpup(p++); | |
1686 | if (lrp->lrf_body_len > 0) { | |
1687 | READ_BUF(lrp->lrf_body_len); | |
1688 | READMEM(lrp->lrf_body, lrp->lrf_body_len); | |
1689 | } | |
1690 | } else { | |
1691 | lrp->lr_seg.offset = 0; | |
1692 | lrp->lr_seg.length = NFS4_MAX_UINT64; | |
1693 | } | |
1694 | ||
1695 | DECODE_TAIL; | |
1696 | } | |
1697 | #endif /* CONFIG_NFSD_PNFS */ | |
1698 | ||
95d871f0 AS |
1699 | static __be32 |
1700 | nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, | |
1701 | struct nfsd4_fallocate *fallocate) | |
1702 | { | |
1703 | DECODE_HEAD; | |
1704 | ||
1705 | status = nfsd4_decode_stateid(argp, &fallocate->falloc_stateid); | |
1706 | if (status) | |
1707 | return status; | |
1708 | ||
1709 | READ_BUF(16); | |
1710 | p = xdr_decode_hyper(p, &fallocate->falloc_offset); | |
1711 | xdr_decode_hyper(p, &fallocate->falloc_length); | |
1712 | ||
1713 | DECODE_TAIL; | |
1714 | } | |
1715 | ||
ffa0160a CH |
1716 | static __be32 |
1717 | nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone) | |
1718 | { | |
1719 | DECODE_HEAD; | |
1720 | ||
1721 | status = nfsd4_decode_stateid(argp, &clone->cl_src_stateid); | |
1722 | if (status) | |
1723 | return status; | |
1724 | status = nfsd4_decode_stateid(argp, &clone->cl_dst_stateid); | |
1725 | if (status) | |
1726 | return status; | |
1727 | ||
1728 | READ_BUF(8 + 8 + 8); | |
1729 | p = xdr_decode_hyper(p, &clone->cl_src_pos); | |
1730 | p = xdr_decode_hyper(p, &clone->cl_dst_pos); | |
1731 | p = xdr_decode_hyper(p, &clone->cl_count); | |
1732 | DECODE_TAIL; | |
1733 | } | |
1734 | ||
29ae7f9d AS |
1735 | static __be32 |
1736 | nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) | |
1737 | { | |
1738 | DECODE_HEAD; | |
29ae7f9d AS |
1739 | |
1740 | status = nfsd4_decode_stateid(argp, ©->cp_src_stateid); | |
1741 | if (status) | |
1742 | return status; | |
1743 | status = nfsd4_decode_stateid(argp, ©->cp_dst_stateid); | |
1744 | if (status) | |
1745 | return status; | |
1746 | ||
1747 | READ_BUF(8 + 8 + 8 + 4 + 4 + 4); | |
1748 | p = xdr_decode_hyper(p, ©->cp_src_pos); | |
1749 | p = xdr_decode_hyper(p, ©->cp_dst_pos); | |
1750 | p = xdr_decode_hyper(p, ©->cp_count); | |
edcc8452 | 1751 | p++; /* ca_consecutive: we always do consecutive copies */ |
29ae7f9d | 1752 | copy->cp_synchronous = be32_to_cpup(p++); |
b96811cd | 1753 | /* tmp = be32_to_cpup(p); Source server list not supported */ |
29ae7f9d AS |
1754 | |
1755 | DECODE_TAIL; | |
1756 | } | |
1757 | ||
6308bc98 OK |
1758 | static __be32 |
1759 | nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp, | |
1760 | struct nfsd4_offload_status *os) | |
1761 | { | |
1762 | return nfsd4_decode_stateid(argp, &os->stateid); | |
1763 | } | |
1764 | ||
24bab491 AS |
1765 | static __be32 |
1766 | nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek) | |
1767 | { | |
1768 | DECODE_HEAD; | |
1769 | ||
1770 | status = nfsd4_decode_stateid(argp, &seek->seek_stateid); | |
1771 | if (status) | |
1772 | return status; | |
1773 | ||
1774 | READ_BUF(8 + 4); | |
1775 | p = xdr_decode_hyper(p, &seek->seek_offset); | |
1776 | seek->seek_whence = be32_to_cpup(p); | |
1777 | ||
1778 | DECODE_TAIL; | |
1779 | } | |
1780 | ||
347e0ad9 BH |
1781 | static __be32 |
1782 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) | |
1783 | { | |
1784 | return nfs_ok; | |
1785 | } | |
1786 | ||
3c375c6f BH |
1787 | static __be32 |
1788 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) | |
1789 | { | |
1e685ec2 | 1790 | return nfserr_notsupp; |
3c375c6f BH |
1791 | } |
1792 | ||
347e0ad9 BH |
1793 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
1794 | ||
c1df609d | 1795 | static const nfsd4_dec nfsd4_dec_ops[] = { |
ad1060c8 BF |
1796 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
1797 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, | |
1798 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, | |
1799 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, | |
1800 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, | |
1801 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, | |
1802 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, | |
1803 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, | |
1804 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, | |
1805 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, | |
1806 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, | |
1807 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, | |
1808 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, | |
1809 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, | |
1810 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, | |
1811 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, | |
1812 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, | |
1813 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, | |
1814 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, | |
1815 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, | |
e1a90ebd | 1816 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh, |
ad1060c8 BF |
1817 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
1818 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, | |
1819 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, | |
1820 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, | |
1821 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, | |
1822 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, | |
1823 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, | |
1824 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, | |
1825 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, | |
1826 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, | |
1827 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, | |
1828 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, | |
1829 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, | |
1830 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, | |
1831 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, | |
1832 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, | |
2db134eb AA |
1833 | |
1834 | /* new operations for NFSv4.1 */ | |
cb73a9f4 | 1835 | [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl, |
1d1bc8f2 | 1836 | [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session, |
9064caae RD |
1837 | [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, |
1838 | [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, | |
1839 | [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, | |
e1ca12df | 1840 | [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, |
9064caae | 1841 | [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
9cf514cc CH |
1842 | #ifdef CONFIG_NFSD_PNFS |
1843 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_getdeviceinfo, | |
1844 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, | |
1845 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_layoutcommit, | |
1846 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_layoutget, | |
1847 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_layoutreturn, | |
1848 | #else | |
9064caae RD |
1849 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, |
1850 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, | |
1851 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp, | |
1852 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp, | |
1853 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp, | |
9cf514cc | 1854 | #endif |
04f4ad16 | 1855 | [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name, |
9064caae RD |
1856 | [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence, |
1857 | [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp, | |
17456804 | 1858 | [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid, |
9064caae | 1859 | [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
345c2842 | 1860 | [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid, |
4dc6ec00 | 1861 | [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete, |
87a15a80 AS |
1862 | |
1863 | /* new operations for NFSv4.2 */ | |
95d871f0 | 1864 | [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
29ae7f9d | 1865 | [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy, |
87a15a80 | 1866 | [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_notsupp, |
b0cb9085 | 1867 | [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
87a15a80 AS |
1868 | [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp, |
1869 | [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp, | |
1870 | [OP_LAYOUTSTATS] = (nfsd4_dec)nfsd4_decode_notsupp, | |
885e2bf3 | 1871 | [OP_OFFLOAD_CANCEL] = (nfsd4_dec)nfsd4_decode_offload_status, |
6308bc98 | 1872 | [OP_OFFLOAD_STATUS] = (nfsd4_dec)nfsd4_decode_offload_status, |
87a15a80 | 1873 | [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_notsupp, |
24bab491 | 1874 | [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, |
87a15a80 | 1875 | [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, |
ffa0160a | 1876 | [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, |
2db134eb AA |
1877 | }; |
1878 | ||
e1a90ebd AS |
1879 | static inline bool |
1880 | nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op) | |
1881 | { | |
8217d146 | 1882 | if (op->opnum < FIRST_NFS4_OP) |
e1a90ebd | 1883 | return false; |
8217d146 | 1884 | else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP) |
e1a90ebd | 1885 | return false; |
8217d146 AS |
1886 | else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP) |
1887 | return false; | |
1888 | else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP) | |
e1a90ebd AS |
1889 | return false; |
1890 | return true; | |
1891 | } | |
f2feb96b | 1892 | |
b37ad28b | 1893 | static __be32 |
1da177e4 LT |
1894 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
1895 | { | |
1896 | DECODE_HEAD; | |
1897 | struct nfsd4_op *op; | |
1091006c | 1898 | bool cachethis = false; |
a5cddc88 BF |
1899 | int auth_slack= argp->rqstp->rq_auth_slack; |
1900 | int max_reply = auth_slack + 8; /* opcnt, status */ | |
b0e35fda BF |
1901 | int readcount = 0; |
1902 | int readbytes = 0; | |
1da177e4 LT |
1903 | int i; |
1904 | ||
1da177e4 | 1905 | READ_BUF(4); |
06553991 | 1906 | argp->taglen = be32_to_cpup(p++); |
4aed9c46 | 1907 | READ_BUF(argp->taglen); |
1da177e4 | 1908 | SAVEMEM(argp->tag, argp->taglen); |
4aed9c46 | 1909 | READ_BUF(8); |
06553991 BF |
1910 | argp->minorversion = be32_to_cpup(p++); |
1911 | argp->opcnt = be32_to_cpup(p++); | |
4f0cefbf | 1912 | max_reply += 4 + (XDR_QUADLEN(argp->taglen) << 2); |
1da177e4 LT |
1913 | |
1914 | if (argp->taglen > NFSD4_MAX_TAGLEN) | |
1915 | goto xdr_error; | |
0078117c BF |
1916 | /* |
1917 | * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS | |
1918 | * here, so we return success at the xdr level so that | |
1919 | * nfsd4_proc can handle this is an NFS-level error. | |
1920 | */ | |
1921 | if (argp->opcnt > NFSD_MAX_OPS_PER_COMPOUND) | |
1922 | return 0; | |
1da177e4 | 1923 | |
e8c96f8c | 1924 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
5d6031ca | 1925 | argp->ops = kzalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
1da177e4 LT |
1926 | if (!argp->ops) { |
1927 | argp->ops = argp->iops; | |
817cb9d4 | 1928 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
1da177e4 LT |
1929 | goto xdr_error; |
1930 | } | |
1931 | } | |
1932 | ||
e1a90ebd | 1933 | if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION) |
30cff1ff BH |
1934 | argp->opcnt = 0; |
1935 | ||
1da177e4 LT |
1936 | for (i = 0; i < argp->opcnt; i++) { |
1937 | op = &argp->ops[i]; | |
1938 | op->replay = NULL; | |
1939 | ||
8a61b18c | 1940 | READ_BUF(4); |
06553991 | 1941 | op->opnum = be32_to_cpup(p++); |
1da177e4 | 1942 | |
e1a90ebd AS |
1943 | if (nfsd4_opnum_in_range(argp, op)) |
1944 | op->status = nfsd4_dec_ops[op->opnum](argp, &op->u); | |
347e0ad9 | 1945 | else { |
1da177e4 LT |
1946 | op->opnum = OP_ILLEGAL; |
1947 | op->status = nfserr_op_illegal; | |
1da177e4 | 1948 | } |
f4f9ef4a | 1949 | op->opdesc = OPDESC(op); |
1091006c BF |
1950 | /* |
1951 | * We'll try to cache the result in the DRC if any one | |
1952 | * op in the compound wants to be cached: | |
1953 | */ | |
1954 | cachethis |= nfsd4_cache_this_op(op); | |
6ff40dec | 1955 | |
b0e35fda BF |
1956 | if (op->opnum == OP_READ) { |
1957 | readcount++; | |
1958 | readbytes += nfsd4_max_reply(argp->rqstp, op); | |
1959 | } else | |
1960 | max_reply += nfsd4_max_reply(argp->rqstp, op); | |
f7b43d0c | 1961 | /* |
7323f0d2 KM |
1962 | * OP_LOCK and OP_LOCKT may return a conflicting lock. |
1963 | * (Special case because it will just skip encoding this | |
1964 | * if it runs out of xdr buffer space, and it is the only | |
1965 | * operation that behaves this way.) | |
f7b43d0c | 1966 | */ |
7323f0d2 | 1967 | if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT) |
f7b43d0c | 1968 | max_reply += NFS4_OPAQUE_LIMIT; |
e372ba60 BF |
1969 | |
1970 | if (op->status) { | |
1971 | argp->opcnt = i+1; | |
1972 | break; | |
1973 | } | |
1da177e4 | 1974 | } |
1091006c BF |
1975 | /* Sessions make the DRC unnecessary: */ |
1976 | if (argp->minorversion) | |
1977 | cachethis = false; | |
b0e35fda | 1978 | svc_reserve(argp->rqstp, max_reply + readbytes); |
1091006c | 1979 | argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE; |
1da177e4 | 1980 | |
a5cddc88 | 1981 | if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack) |
779fb0f3 | 1982 | clear_bit(RQ_SPLICE_OK, &argp->rqstp->rq_flags); |
b0e35fda | 1983 | |
1da177e4 LT |
1984 | DECODE_TAIL; |
1985 | } | |
1da177e4 | 1986 | |
b8800921 N |
1987 | static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode, |
1988 | struct svc_export *exp) | |
c654b8a9 | 1989 | { |
b8800921 N |
1990 | if (exp->ex_flags & NFSEXP_V4ROOT) { |
1991 | *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time)); | |
1992 | *p++ = 0; | |
1993 | } else if (IS_I_VERSION(inode)) { | |
39ca1bf6 | 1994 | p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode)); |
c654b8a9 | 1995 | } else { |
d05d5744 BF |
1996 | *p++ = cpu_to_be32(stat->ctime.tv_sec); |
1997 | *p++ = cpu_to_be32(stat->ctime.tv_nsec); | |
c654b8a9 | 1998 | } |
d05d5744 | 1999 | return p; |
c654b8a9 BF |
2000 | } |
2001 | ||
16945141 BF |
2002 | /* |
2003 | * ctime (in NFSv4, time_metadata) is not writeable, and the client | |
2004 | * doesn't really care what resolution could theoretically be stored by | |
2005 | * the filesystem. | |
2006 | * | |
2007 | * The client cares how close together changes can be while still | |
2008 | * guaranteeing ctime changes. For most filesystems (which have | |
2009 | * timestamps with nanosecond fields) that is limited by the resolution | |
2010 | * of the time returned from current_time() (which I'm assuming to be | |
2011 | * 1/HZ). | |
2012 | */ | |
2013 | static __be32 *encode_time_delta(__be32 *p, struct inode *inode) | |
2014 | { | |
2015 | struct timespec ts; | |
2016 | u32 ns; | |
2017 | ||
2018 | ns = max_t(u32, NSEC_PER_SEC/HZ, inode->i_sb->s_time_gran); | |
2019 | ts = ns_to_timespec(ns); | |
2020 | ||
2021 | p = xdr_encode_hyper(p, ts.tv_sec); | |
2022 | *p++ = cpu_to_be32(ts.tv_nsec); | |
2023 | ||
2024 | return p; | |
2025 | } | |
2026 | ||
d05d5744 | 2027 | static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c) |
c654b8a9 | 2028 | { |
d05d5744 | 2029 | *p++ = cpu_to_be32(c->atomic); |
c654b8a9 | 2030 | if (c->change_supported) { |
d05d5744 BF |
2031 | p = xdr_encode_hyper(p, c->before_change); |
2032 | p = xdr_encode_hyper(p, c->after_change); | |
c654b8a9 | 2033 | } else { |
d05d5744 BF |
2034 | *p++ = cpu_to_be32(c->before_ctime_sec); |
2035 | *p++ = cpu_to_be32(c->before_ctime_nsec); | |
2036 | *p++ = cpu_to_be32(c->after_ctime_sec); | |
2037 | *p++ = cpu_to_be32(c->after_ctime_nsec); | |
c654b8a9 | 2038 | } |
d05d5744 | 2039 | return p; |
c654b8a9 | 2040 | } |
1da177e4 | 2041 | |
81c3f413 | 2042 | /* Encode as an array of strings the string given with components |
e7a0444a | 2043 | * separated @sep, escaped with esc_enter and esc_exit. |
81c3f413 | 2044 | */ |
ddd1ea56 BF |
2045 | static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, |
2046 | char *components, char esc_enter, | |
2047 | char esc_exit) | |
81c3f413 | 2048 | { |
ddd1ea56 | 2049 | __be32 *p; |
082d4bd7 BF |
2050 | __be32 pathlen; |
2051 | int pathlen_offset; | |
81c3f413 | 2052 | int strlen, count=0; |
e7a0444a | 2053 | char *str, *end, *next; |
81c3f413 BF |
2054 | |
2055 | dprintk("nfsd4_encode_components(%s)\n", components); | |
082d4bd7 BF |
2056 | |
2057 | pathlen_offset = xdr->buf->len; | |
ddd1ea56 BF |
2058 | p = xdr_reserve_space(xdr, 4); |
2059 | if (!p) | |
81c3f413 | 2060 | return nfserr_resource; |
082d4bd7 BF |
2061 | p++; /* We will fill this in with @count later */ |
2062 | ||
81c3f413 BF |
2063 | end = str = components; |
2064 | while (*end) { | |
e7a0444a WAA |
2065 | bool found_esc = false; |
2066 | ||
2067 | /* try to parse as esc_start, ..., esc_end, sep */ | |
2068 | if (*str == esc_enter) { | |
2069 | for (; *end && (*end != esc_exit); end++) | |
2070 | /* find esc_exit or end of string */; | |
2071 | next = end + 1; | |
2072 | if (*end && (!*next || *next == sep)) { | |
2073 | str++; | |
2074 | found_esc = true; | |
2075 | } | |
2076 | } | |
2077 | ||
2078 | if (!found_esc) | |
2079 | for (; *end && (*end != sep); end++) | |
2080 | /* find sep or end of string */; | |
2081 | ||
81c3f413 BF |
2082 | strlen = end - str; |
2083 | if (strlen) { | |
ddd1ea56 BF |
2084 | p = xdr_reserve_space(xdr, strlen + 4); |
2085 | if (!p) | |
81c3f413 | 2086 | return nfserr_resource; |
0c0c267b | 2087 | p = xdr_encode_opaque(p, str, strlen); |
81c3f413 BF |
2088 | count++; |
2089 | } | |
2090 | else | |
2091 | end++; | |
5a64e569 BC |
2092 | if (found_esc) |
2093 | end = next; | |
2094 | ||
81c3f413 BF |
2095 | str = end; |
2096 | } | |
bf7491f1 | 2097 | pathlen = htonl(count); |
082d4bd7 | 2098 | write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4); |
81c3f413 BF |
2099 | return 0; |
2100 | } | |
2101 | ||
e7a0444a WAA |
2102 | /* Encode as an array of strings the string given with components |
2103 | * separated @sep. | |
2104 | */ | |
ddd1ea56 BF |
2105 | static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep, |
2106 | char *components) | |
e7a0444a | 2107 | { |
ddd1ea56 | 2108 | return nfsd4_encode_components_esc(xdr, sep, components, 0, 0); |
e7a0444a WAA |
2109 | } |
2110 | ||
81c3f413 BF |
2111 | /* |
2112 | * encode a location element of a fs_locations structure | |
2113 | */ | |
ddd1ea56 BF |
2114 | static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr, |
2115 | struct nfsd4_fs_location *location) | |
81c3f413 | 2116 | { |
b37ad28b | 2117 | __be32 status; |
81c3f413 | 2118 | |
ddd1ea56 | 2119 | status = nfsd4_encode_components_esc(xdr, ':', location->hosts, |
e7a0444a | 2120 | '[', ']'); |
81c3f413 BF |
2121 | if (status) |
2122 | return status; | |
ddd1ea56 | 2123 | status = nfsd4_encode_components(xdr, '/', location->path); |
81c3f413 BF |
2124 | if (status) |
2125 | return status; | |
81c3f413 BF |
2126 | return 0; |
2127 | } | |
2128 | ||
2129 | /* | |
ed748aac | 2130 | * Encode a path in RFC3530 'pathname4' format |
81c3f413 | 2131 | */ |
ddd1ea56 BF |
2132 | static __be32 nfsd4_encode_path(struct xdr_stream *xdr, |
2133 | const struct path *root, | |
2134 | const struct path *path) | |
81c3f413 | 2135 | { |
301f0268 | 2136 | struct path cur = *path; |
ddd1ea56 | 2137 | __be32 *p; |
ed748aac TM |
2138 | struct dentry **components = NULL; |
2139 | unsigned int ncomponents = 0; | |
2140 | __be32 err = nfserr_jukebox; | |
81c3f413 | 2141 | |
ed748aac | 2142 | dprintk("nfsd4_encode_components("); |
81c3f413 | 2143 | |
ed748aac TM |
2144 | path_get(&cur); |
2145 | /* First walk the path up to the nfsd root, and store the | |
2146 | * dentries/path components in an array. | |
2147 | */ | |
2148 | for (;;) { | |
b77a4b2e | 2149 | if (path_equal(&cur, root)) |
ed748aac TM |
2150 | break; |
2151 | if (cur.dentry == cur.mnt->mnt_root) { | |
2152 | if (follow_up(&cur)) | |
2153 | continue; | |
2154 | goto out_free; | |
2155 | } | |
2156 | if ((ncomponents & 15) == 0) { | |
2157 | struct dentry **new; | |
2158 | new = krealloc(components, | |
2159 | sizeof(*new) * (ncomponents + 16), | |
2160 | GFP_KERNEL); | |
2161 | if (!new) | |
2162 | goto out_free; | |
2163 | components = new; | |
2164 | } | |
2165 | components[ncomponents++] = cur.dentry; | |
2166 | cur.dentry = dget_parent(cur.dentry); | |
2167 | } | |
ddd1ea56 BF |
2168 | err = nfserr_resource; |
2169 | p = xdr_reserve_space(xdr, 4); | |
2170 | if (!p) | |
ed748aac | 2171 | goto out_free; |
c373b0a4 | 2172 | *p++ = cpu_to_be32(ncomponents); |
ed748aac TM |
2173 | |
2174 | while (ncomponents) { | |
2175 | struct dentry *dentry = components[ncomponents - 1]; | |
301f0268 | 2176 | unsigned int len; |
ed748aac | 2177 | |
301f0268 AV |
2178 | spin_lock(&dentry->d_lock); |
2179 | len = dentry->d_name.len; | |
ddd1ea56 BF |
2180 | p = xdr_reserve_space(xdr, len + 4); |
2181 | if (!p) { | |
301f0268 | 2182 | spin_unlock(&dentry->d_lock); |
ed748aac | 2183 | goto out_free; |
301f0268 | 2184 | } |
0c0c267b | 2185 | p = xdr_encode_opaque(p, dentry->d_name.name, len); |
a455589f | 2186 | dprintk("/%pd", dentry); |
301f0268 | 2187 | spin_unlock(&dentry->d_lock); |
ed748aac TM |
2188 | dput(dentry); |
2189 | ncomponents--; | |
81c3f413 | 2190 | } |
ed748aac | 2191 | |
ed748aac TM |
2192 | err = 0; |
2193 | out_free: | |
2194 | dprintk(")\n"); | |
2195 | while (ncomponents) | |
2196 | dput(components[--ncomponents]); | |
2197 | kfree(components); | |
2198 | path_put(&cur); | |
2199 | return err; | |
2200 | } | |
2201 | ||
ddd1ea56 BF |
2202 | static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr, |
2203 | struct svc_rqst *rqstp, const struct path *path) | |
ed748aac TM |
2204 | { |
2205 | struct svc_export *exp_ps; | |
2206 | __be32 res; | |
2207 | ||
2208 | exp_ps = rqst_find_fsidzero_export(rqstp); | |
2209 | if (IS_ERR(exp_ps)) | |
2210 | return nfserrno(PTR_ERR(exp_ps)); | |
ddd1ea56 | 2211 | res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path); |
ed748aac TM |
2212 | exp_put(exp_ps); |
2213 | return res; | |
81c3f413 BF |
2214 | } |
2215 | ||
2216 | /* | |
2217 | * encode a fs_locations structure | |
2218 | */ | |
ddd1ea56 BF |
2219 | static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr, |
2220 | struct svc_rqst *rqstp, struct svc_export *exp) | |
81c3f413 | 2221 | { |
b37ad28b | 2222 | __be32 status; |
cc45f017 | 2223 | int i; |
ddd1ea56 | 2224 | __be32 *p; |
81c3f413 | 2225 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
81c3f413 | 2226 | |
ddd1ea56 | 2227 | status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path); |
81c3f413 BF |
2228 | if (status) |
2229 | return status; | |
ddd1ea56 BF |
2230 | p = xdr_reserve_space(xdr, 4); |
2231 | if (!p) | |
81c3f413 | 2232 | return nfserr_resource; |
c373b0a4 | 2233 | *p++ = cpu_to_be32(fslocs->locations_count); |
81c3f413 | 2234 | for (i=0; i<fslocs->locations_count; i++) { |
ddd1ea56 | 2235 | status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]); |
81c3f413 BF |
2236 | if (status) |
2237 | return status; | |
2238 | } | |
81c3f413 BF |
2239 | return 0; |
2240 | } | |
1da177e4 | 2241 | |
3d2544b1 BF |
2242 | static u32 nfs4_file_type(umode_t mode) |
2243 | { | |
2244 | switch (mode & S_IFMT) { | |
2245 | case S_IFIFO: return NF4FIFO; | |
2246 | case S_IFCHR: return NF4CHR; | |
2247 | case S_IFDIR: return NF4DIR; | |
2248 | case S_IFBLK: return NF4BLK; | |
2249 | case S_IFLNK: return NF4LNK; | |
2250 | case S_IFREG: return NF4REG; | |
2251 | case S_IFSOCK: return NF4SOCK; | |
2252 | default: return NF4BAD; | |
2253 | }; | |
2254 | } | |
1da177e4 | 2255 | |
b37ad28b | 2256 | static inline __be32 |
ddd1ea56 BF |
2257 | nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
2258 | struct nfs4_ace *ace) | |
1da177e4 | 2259 | { |
3554116d | 2260 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
ddd1ea56 | 2261 | return nfs4_acl_write_who(xdr, ace->whotype); |
3554116d | 2262 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
ddd1ea56 | 2263 | return nfsd4_encode_group(xdr, rqstp, ace->who_gid); |
3554116d | 2264 | else |
ddd1ea56 | 2265 | return nfsd4_encode_user(xdr, rqstp, ace->who_uid); |
1da177e4 LT |
2266 | } |
2267 | ||
6896f15a | 2268 | static inline __be32 |
8a4c3926 | 2269 | nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) |
6896f15a | 2270 | { |
8a4c3926 JL |
2271 | __be32 *p; |
2272 | unsigned long i = hweight_long(layout_types); | |
6896f15a | 2273 | |
8a4c3926 JL |
2274 | p = xdr_reserve_space(xdr, 4 + 4 * i); |
2275 | if (!p) | |
2276 | return nfserr_resource; | |
2277 | ||
2278 | *p++ = cpu_to_be32(i); | |
2279 | ||
2280 | for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) | |
2281 | if (layout_types & (1 << i)) | |
2282 | *p++ = cpu_to_be32(i); | |
6896f15a KM |
2283 | |
2284 | return 0; | |
2285 | } | |
2286 | ||
42ca0993 BF |
2287 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
2288 | FATTR4_WORD0_RDATTR_ERROR) | |
2289 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID | |
c2227a39 | 2290 | #define WORD2_ABSENT_FS_ATTRS 0 |
42ca0993 | 2291 | |
18032ca0 DQ |
2292 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
2293 | static inline __be32 | |
ddd1ea56 BF |
2294 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
2295 | void *context, int len) | |
18032ca0 | 2296 | { |
ddd1ea56 | 2297 | __be32 *p; |
18032ca0 | 2298 | |
ddd1ea56 BF |
2299 | p = xdr_reserve_space(xdr, len + 4 + 4 + 4); |
2300 | if (!p) | |
18032ca0 DQ |
2301 | return nfserr_resource; |
2302 | ||
2303 | /* | |
2304 | * For now we use a 0 here to indicate the null translation; in | |
2305 | * the future we may place a call to translation code here. | |
2306 | */ | |
c373b0a4 BF |
2307 | *p++ = cpu_to_be32(0); /* lfs */ |
2308 | *p++ = cpu_to_be32(0); /* pi */ | |
18032ca0 | 2309 | p = xdr_encode_opaque(p, context, len); |
18032ca0 DQ |
2310 | return 0; |
2311 | } | |
2312 | #else | |
2313 | static inline __be32 | |
ddd1ea56 BF |
2314 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
2315 | void *context, int len) | |
18032ca0 DQ |
2316 | { return 0; } |
2317 | #endif | |
2318 | ||
c2227a39 | 2319 | static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *bmval2, u32 *rdattr_err) |
42ca0993 BF |
2320 | { |
2321 | /* As per referral draft: */ | |
2322 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || | |
2323 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { | |
2324 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || | |
2325 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) | |
2326 | *rdattr_err = NFSERR_MOVED; | |
2327 | else | |
2328 | return nfserr_moved; | |
2329 | } | |
2330 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; | |
2331 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; | |
c2227a39 | 2332 | *bmval2 &= WORD2_ABSENT_FS_ATTRS; |
42ca0993 BF |
2333 | return 0; |
2334 | } | |
1da177e4 | 2335 | |
ae7095a7 BF |
2336 | |
2337 | static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) | |
2338 | { | |
2339 | struct path path = exp->ex_path; | |
2340 | int err; | |
2341 | ||
2342 | path_get(&path); | |
2343 | while (follow_up(&path)) { | |
2344 | if (path.dentry != path.mnt->mnt_root) | |
2345 | break; | |
2346 | } | |
a528d35e | 2347 | err = vfs_getattr(&path, stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); |
ae7095a7 BF |
2348 | path_put(&path); |
2349 | return err; | |
2350 | } | |
2351 | ||
75976de6 KM |
2352 | static __be32 |
2353 | nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2) | |
2354 | { | |
2355 | __be32 *p; | |
2356 | ||
2357 | if (bmval2) { | |
2358 | p = xdr_reserve_space(xdr, 16); | |
2359 | if (!p) | |
2360 | goto out_resource; | |
2361 | *p++ = cpu_to_be32(3); | |
2362 | *p++ = cpu_to_be32(bmval0); | |
2363 | *p++ = cpu_to_be32(bmval1); | |
2364 | *p++ = cpu_to_be32(bmval2); | |
2365 | } else if (bmval1) { | |
2366 | p = xdr_reserve_space(xdr, 12); | |
2367 | if (!p) | |
2368 | goto out_resource; | |
2369 | *p++ = cpu_to_be32(2); | |
2370 | *p++ = cpu_to_be32(bmval0); | |
2371 | *p++ = cpu_to_be32(bmval1); | |
2372 | } else { | |
2373 | p = xdr_reserve_space(xdr, 8); | |
2374 | if (!p) | |
2375 | goto out_resource; | |
2376 | *p++ = cpu_to_be32(1); | |
2377 | *p++ = cpu_to_be32(bmval0); | |
2378 | } | |
2379 | ||
2380 | return 0; | |
2381 | out_resource: | |
2382 | return nfserr_resource; | |
2383 | } | |
2384 | ||
1da177e4 LT |
2385 | /* |
2386 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle | |
2387 | * ourselves. | |
1da177e4 | 2388 | */ |
da2ebce6 | 2389 | static __be32 |
d5184658 BF |
2390 | nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, |
2391 | struct svc_export *exp, | |
2392 | struct dentry *dentry, u32 *bmval, | |
406a7ea9 | 2393 | struct svc_rqst *rqstp, int ignore_crossmnt) |
1da177e4 LT |
2394 | { |
2395 | u32 bmval0 = bmval[0]; | |
2396 | u32 bmval1 = bmval[1]; | |
7e705706 | 2397 | u32 bmval2 = bmval[2]; |
1da177e4 | 2398 | struct kstat stat; |
d50e6136 | 2399 | struct svc_fh *tempfh = NULL; |
1da177e4 | 2400 | struct kstatfs statfs; |
ddd1ea56 | 2401 | __be32 *p; |
1fcea5b2 | 2402 | int starting_len = xdr->buf->len; |
082d4bd7 BF |
2403 | int attrlen_offset; |
2404 | __be32 attrlen; | |
1da177e4 LT |
2405 | u32 dummy; |
2406 | u64 dummy64; | |
42ca0993 | 2407 | u32 rdattr_err = 0; |
b37ad28b | 2408 | __be32 status; |
b8dd7b9a | 2409 | int err; |
1da177e4 | 2410 | struct nfs4_acl *acl = NULL; |
0ab88ca4 | 2411 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
18032ca0 DQ |
2412 | void *context = NULL; |
2413 | int contextlen; | |
0ab88ca4 | 2414 | #endif |
18032ca0 | 2415 | bool contextsupport = false; |
7e705706 AA |
2416 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
2417 | u32 minorversion = resp->cstate.minorversion; | |
ebabe9a9 CH |
2418 | struct path path = { |
2419 | .mnt = exp->ex_path.mnt, | |
2420 | .dentry = dentry, | |
2421 | }; | |
3d733711 | 2422 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
1da177e4 LT |
2423 | |
2424 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); | |
916d2d84 | 2425 | BUG_ON(!nfsd_attrs_supported(minorversion, bmval)); |
1da177e4 | 2426 | |
42ca0993 | 2427 | if (exp->ex_fslocs.migrated) { |
c2227a39 | 2428 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err); |
42ca0993 BF |
2429 | if (status) |
2430 | goto out; | |
2431 | } | |
2432 | ||
a528d35e | 2433 | err = vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); |
b8dd7b9a | 2434 | if (err) |
1da177e4 | 2435 | goto out_nfserr; |
12337901 CH |
2436 | if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | |
2437 | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || | |
1da177e4 LT |
2438 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
2439 | FATTR4_WORD1_SPACE_TOTAL))) { | |
ebabe9a9 | 2440 | err = vfs_statfs(&path, &statfs); |
b8dd7b9a | 2441 | if (err) |
1da177e4 LT |
2442 | goto out_nfserr; |
2443 | } | |
2444 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { | |
d50e6136 BF |
2445 | tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
2446 | status = nfserr_jukebox; | |
2447 | if (!tempfh) | |
2448 | goto out; | |
2449 | fh_init(tempfh, NFS4_FHSIZE); | |
2450 | status = fh_compose(tempfh, exp, dentry, NULL); | |
1da177e4 LT |
2451 | if (status) |
2452 | goto out; | |
d50e6136 | 2453 | fhp = tempfh; |
1da177e4 | 2454 | } |
0c9d65e7 | 2455 | if (bmval0 & FATTR4_WORD0_ACL) { |
b8dd7b9a | 2456 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
0c9d65e7 AG |
2457 | if (err == -EOPNOTSUPP) |
2458 | bmval0 &= ~FATTR4_WORD0_ACL; | |
2459 | else if (err == -EINVAL) { | |
2460 | status = nfserr_attrnotsupp; | |
2461 | goto out; | |
2462 | } else if (err != 0) | |
2463 | goto out_nfserr; | |
1da177e4 | 2464 | } |
1da177e4 | 2465 | |
18032ca0 | 2466 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
c2227a39 KM |
2467 | if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) || |
2468 | bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { | |
32ddd944 BF |
2469 | if (exp->ex_flags & NFSEXP_SECURITY_LABEL) |
2470 | err = security_inode_getsecctx(d_inode(dentry), | |
18032ca0 | 2471 | &context, &contextlen); |
32ddd944 BF |
2472 | else |
2473 | err = -EOPNOTSUPP; | |
18032ca0 DQ |
2474 | contextsupport = (err == 0); |
2475 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { | |
2476 | if (err == -EOPNOTSUPP) | |
2477 | bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL; | |
2478 | else if (err) | |
2479 | goto out_nfserr; | |
2480 | } | |
2481 | } | |
2482 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ | |
2483 | ||
75976de6 KM |
2484 | status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2); |
2485 | if (status) | |
2486 | goto out; | |
082d4bd7 BF |
2487 | |
2488 | attrlen_offset = xdr->buf->len; | |
ddd1ea56 BF |
2489 | p = xdr_reserve_space(xdr, 4); |
2490 | if (!p) | |
2491 | goto out_resource; | |
082d4bd7 | 2492 | p++; /* to be backfilled later */ |
1da177e4 LT |
2493 | |
2494 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { | |
dcd20869 BF |
2495 | u32 supp[3]; |
2496 | ||
2497 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); | |
7e705706 | 2498 | |
0c9d65e7 | 2499 | if (!IS_POSIXACL(dentry->d_inode)) |
916d2d84 | 2500 | supp[0] &= ~FATTR4_WORD0_ACL; |
18032ca0 | 2501 | if (!contextsupport) |
916d2d84 BF |
2502 | supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
2503 | if (!supp[2]) { | |
ddd1ea56 BF |
2504 | p = xdr_reserve_space(xdr, 12); |
2505 | if (!p) | |
2b44f1ba | 2506 | goto out_resource; |
c373b0a4 | 2507 | *p++ = cpu_to_be32(2); |
916d2d84 BF |
2508 | *p++ = cpu_to_be32(supp[0]); |
2509 | *p++ = cpu_to_be32(supp[1]); | |
7e705706 | 2510 | } else { |
ddd1ea56 BF |
2511 | p = xdr_reserve_space(xdr, 16); |
2512 | if (!p) | |
2b44f1ba | 2513 | goto out_resource; |
c373b0a4 | 2514 | *p++ = cpu_to_be32(3); |
916d2d84 BF |
2515 | *p++ = cpu_to_be32(supp[0]); |
2516 | *p++ = cpu_to_be32(supp[1]); | |
2517 | *p++ = cpu_to_be32(supp[2]); | |
7e705706 | 2518 | } |
1da177e4 LT |
2519 | } |
2520 | if (bmval0 & FATTR4_WORD0_TYPE) { | |
ddd1ea56 BF |
2521 | p = xdr_reserve_space(xdr, 4); |
2522 | if (!p) | |
1da177e4 | 2523 | goto out_resource; |
3d2544b1 | 2524 | dummy = nfs4_file_type(stat.mode); |
6b6d8137 BF |
2525 | if (dummy == NF4BAD) { |
2526 | status = nfserr_serverfault; | |
2527 | goto out; | |
2528 | } | |
c373b0a4 | 2529 | *p++ = cpu_to_be32(dummy); |
1da177e4 LT |
2530 | } |
2531 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { | |
ddd1ea56 BF |
2532 | p = xdr_reserve_space(xdr, 4); |
2533 | if (!p) | |
1da177e4 | 2534 | goto out_resource; |
49640001 | 2535 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
c373b0a4 | 2536 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT); |
49640001 | 2537 | else |
c373b0a4 BF |
2538 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT| |
2539 | NFS4_FH_VOL_RENAME); | |
1da177e4 LT |
2540 | } |
2541 | if (bmval0 & FATTR4_WORD0_CHANGE) { | |
ddd1ea56 BF |
2542 | p = xdr_reserve_space(xdr, 8); |
2543 | if (!p) | |
1da177e4 | 2544 | goto out_resource; |
b8800921 | 2545 | p = encode_change(p, &stat, d_inode(dentry), exp); |
1da177e4 LT |
2546 | } |
2547 | if (bmval0 & FATTR4_WORD0_SIZE) { | |
ddd1ea56 BF |
2548 | p = xdr_reserve_space(xdr, 8); |
2549 | if (!p) | |
1da177e4 | 2550 | goto out_resource; |
b64c7f3b | 2551 | p = xdr_encode_hyper(p, stat.size); |
1da177e4 LT |
2552 | } |
2553 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { | |
ddd1ea56 BF |
2554 | p = xdr_reserve_space(xdr, 4); |
2555 | if (!p) | |
1da177e4 | 2556 | goto out_resource; |
c373b0a4 | 2557 | *p++ = cpu_to_be32(1); |
1da177e4 LT |
2558 | } |
2559 | if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) { | |
ddd1ea56 BF |
2560 | p = xdr_reserve_space(xdr, 4); |
2561 | if (!p) | |
1da177e4 | 2562 | goto out_resource; |
c373b0a4 | 2563 | *p++ = cpu_to_be32(1); |
1da177e4 LT |
2564 | } |
2565 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { | |
ddd1ea56 BF |
2566 | p = xdr_reserve_space(xdr, 4); |
2567 | if (!p) | |
1da177e4 | 2568 | goto out_resource; |
c373b0a4 | 2569 | *p++ = cpu_to_be32(0); |
1da177e4 LT |
2570 | } |
2571 | if (bmval0 & FATTR4_WORD0_FSID) { | |
ddd1ea56 BF |
2572 | p = xdr_reserve_space(xdr, 16); |
2573 | if (!p) | |
1da177e4 | 2574 | goto out_resource; |
42ca0993 | 2575 | if (exp->ex_fslocs.migrated) { |
b64c7f3b BF |
2576 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR); |
2577 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR); | |
af6a4e28 N |
2578 | } else switch(fsid_source(fhp)) { |
2579 | case FSIDSOURCE_FSID: | |
b64c7f3b BF |
2580 | p = xdr_encode_hyper(p, (u64)exp->ex_fsid); |
2581 | p = xdr_encode_hyper(p, (u64)0); | |
af6a4e28 N |
2582 | break; |
2583 | case FSIDSOURCE_DEV: | |
c373b0a4 BF |
2584 | *p++ = cpu_to_be32(0); |
2585 | *p++ = cpu_to_be32(MAJOR(stat.dev)); | |
2586 | *p++ = cpu_to_be32(0); | |
2587 | *p++ = cpu_to_be32(MINOR(stat.dev)); | |
af6a4e28 N |
2588 | break; |
2589 | case FSIDSOURCE_UUID: | |
94eb3689 KM |
2590 | p = xdr_encode_opaque_fixed(p, exp->ex_uuid, |
2591 | EX_UUID_LEN); | |
af6a4e28 | 2592 | break; |
1da177e4 LT |
2593 | } |
2594 | } | |
2595 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { | |
ddd1ea56 BF |
2596 | p = xdr_reserve_space(xdr, 4); |
2597 | if (!p) | |
1da177e4 | 2598 | goto out_resource; |
c373b0a4 | 2599 | *p++ = cpu_to_be32(0); |
1da177e4 LT |
2600 | } |
2601 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { | |
ddd1ea56 BF |
2602 | p = xdr_reserve_space(xdr, 4); |
2603 | if (!p) | |
1da177e4 | 2604 | goto out_resource; |
c373b0a4 | 2605 | *p++ = cpu_to_be32(nn->nfsd4_lease); |
1da177e4 LT |
2606 | } |
2607 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { | |
ddd1ea56 BF |
2608 | p = xdr_reserve_space(xdr, 4); |
2609 | if (!p) | |
1da177e4 | 2610 | goto out_resource; |
c373b0a4 | 2611 | *p++ = cpu_to_be32(rdattr_err); |
1da177e4 LT |
2612 | } |
2613 | if (bmval0 & FATTR4_WORD0_ACL) { | |
2614 | struct nfs4_ace *ace; | |
1da177e4 LT |
2615 | |
2616 | if (acl == NULL) { | |
ddd1ea56 BF |
2617 | p = xdr_reserve_space(xdr, 4); |
2618 | if (!p) | |
1da177e4 LT |
2619 | goto out_resource; |
2620 | ||
c373b0a4 | 2621 | *p++ = cpu_to_be32(0); |
1da177e4 LT |
2622 | goto out_acl; |
2623 | } | |
ddd1ea56 BF |
2624 | p = xdr_reserve_space(xdr, 4); |
2625 | if (!p) | |
1da177e4 | 2626 | goto out_resource; |
c373b0a4 | 2627 | *p++ = cpu_to_be32(acl->naces); |
1da177e4 | 2628 | |
28e05dd8 | 2629 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
ddd1ea56 BF |
2630 | p = xdr_reserve_space(xdr, 4*3); |
2631 | if (!p) | |
1da177e4 | 2632 | goto out_resource; |
c373b0a4 BF |
2633 | *p++ = cpu_to_be32(ace->type); |
2634 | *p++ = cpu_to_be32(ace->flag); | |
2635 | *p++ = cpu_to_be32(ace->access_mask & | |
2636 | NFS4_ACE_MASK_ALL); | |
ddd1ea56 | 2637 | status = nfsd4_encode_aclname(xdr, rqstp, ace); |
1da177e4 LT |
2638 | if (status) |
2639 | goto out; | |
2640 | } | |
2641 | } | |
2642 | out_acl: | |
2643 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { | |
ddd1ea56 BF |
2644 | p = xdr_reserve_space(xdr, 4); |
2645 | if (!p) | |
1da177e4 | 2646 | goto out_resource; |
0c9d65e7 | 2647 | *p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ? |
1da177e4 LT |
2648 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
2649 | } | |
2650 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { | |
ddd1ea56 BF |
2651 | p = xdr_reserve_space(xdr, 4); |
2652 | if (!p) | |
1da177e4 | 2653 | goto out_resource; |
c373b0a4 | 2654 | *p++ = cpu_to_be32(1); |
1da177e4 LT |
2655 | } |
2656 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { | |
ddd1ea56 BF |
2657 | p = xdr_reserve_space(xdr, 4); |
2658 | if (!p) | |
1da177e4 | 2659 | goto out_resource; |
c373b0a4 | 2660 | *p++ = cpu_to_be32(0); |
1da177e4 LT |
2661 | } |
2662 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { | |
ddd1ea56 BF |
2663 | p = xdr_reserve_space(xdr, 4); |
2664 | if (!p) | |
1da177e4 | 2665 | goto out_resource; |
c373b0a4 | 2666 | *p++ = cpu_to_be32(1); |
1da177e4 LT |
2667 | } |
2668 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { | |
ddd1ea56 BF |
2669 | p = xdr_reserve_space(xdr, 4); |
2670 | if (!p) | |
1da177e4 | 2671 | goto out_resource; |
c373b0a4 | 2672 | *p++ = cpu_to_be32(1); |
1da177e4 LT |
2673 | } |
2674 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { | |
ddd1ea56 BF |
2675 | p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4); |
2676 | if (!p) | |
1da177e4 | 2677 | goto out_resource; |
0c0c267b BF |
2678 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, |
2679 | fhp->fh_handle.fh_size); | |
1da177e4 LT |
2680 | } |
2681 | if (bmval0 & FATTR4_WORD0_FILEID) { | |
ddd1ea56 BF |
2682 | p = xdr_reserve_space(xdr, 8); |
2683 | if (!p) | |
1da177e4 | 2684 | goto out_resource; |
b64c7f3b | 2685 | p = xdr_encode_hyper(p, stat.ino); |
1da177e4 LT |
2686 | } |
2687 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { | |
ddd1ea56 BF |
2688 | p = xdr_reserve_space(xdr, 8); |
2689 | if (!p) | |
1da177e4 | 2690 | goto out_resource; |
b64c7f3b | 2691 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
1da177e4 LT |
2692 | } |
2693 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { | |
ddd1ea56 BF |
2694 | p = xdr_reserve_space(xdr, 8); |
2695 | if (!p) | |
1da177e4 | 2696 | goto out_resource; |
b64c7f3b | 2697 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
1da177e4 LT |
2698 | } |
2699 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { | |
ddd1ea56 BF |
2700 | p = xdr_reserve_space(xdr, 8); |
2701 | if (!p) | |
1da177e4 | 2702 | goto out_resource; |
b64c7f3b | 2703 | p = xdr_encode_hyper(p, (u64) statfs.f_files); |
1da177e4 | 2704 | } |
81c3f413 | 2705 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
ddd1ea56 | 2706 | status = nfsd4_encode_fs_locations(xdr, rqstp, exp); |
81c3f413 BF |
2707 | if (status) |
2708 | goto out; | |
2709 | } | |
1da177e4 | 2710 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
ddd1ea56 BF |
2711 | p = xdr_reserve_space(xdr, 4); |
2712 | if (!p) | |
1da177e4 | 2713 | goto out_resource; |
c373b0a4 | 2714 | *p++ = cpu_to_be32(1); |
1da177e4 LT |
2715 | } |
2716 | if (bmval0 & FATTR4_WORD0_MAXFILESIZE) { | |
ddd1ea56 BF |
2717 | p = xdr_reserve_space(xdr, 8); |
2718 | if (!p) | |
1da177e4 | 2719 | goto out_resource; |
b64c7f3b | 2720 | p = xdr_encode_hyper(p, exp->ex_path.mnt->mnt_sb->s_maxbytes); |
1da177e4 LT |
2721 | } |
2722 | if (bmval0 & FATTR4_WORD0_MAXLINK) { | |
ddd1ea56 BF |
2723 | p = xdr_reserve_space(xdr, 4); |
2724 | if (!p) | |
1da177e4 | 2725 | goto out_resource; |
c373b0a4 | 2726 | *p++ = cpu_to_be32(255); |
1da177e4 LT |
2727 | } |
2728 | if (bmval0 & FATTR4_WORD0_MAXNAME) { | |
ddd1ea56 BF |
2729 | p = xdr_reserve_space(xdr, 4); |
2730 | if (!p) | |
1da177e4 | 2731 | goto out_resource; |
c373b0a4 | 2732 | *p++ = cpu_to_be32(statfs.f_namelen); |
1da177e4 LT |
2733 | } |
2734 | if (bmval0 & FATTR4_WORD0_MAXREAD) { | |
ddd1ea56 BF |
2735 | p = xdr_reserve_space(xdr, 8); |
2736 | if (!p) | |
1da177e4 | 2737 | goto out_resource; |
b64c7f3b | 2738 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
1da177e4 LT |
2739 | } |
2740 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { | |
ddd1ea56 BF |
2741 | p = xdr_reserve_space(xdr, 8); |
2742 | if (!p) | |
1da177e4 | 2743 | goto out_resource; |
b64c7f3b | 2744 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
1da177e4 LT |
2745 | } |
2746 | if (bmval1 & FATTR4_WORD1_MODE) { | |
ddd1ea56 BF |
2747 | p = xdr_reserve_space(xdr, 4); |
2748 | if (!p) | |
1da177e4 | 2749 | goto out_resource; |
c373b0a4 | 2750 | *p++ = cpu_to_be32(stat.mode & S_IALLUGO); |
1da177e4 LT |
2751 | } |
2752 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { | |
ddd1ea56 BF |
2753 | p = xdr_reserve_space(xdr, 4); |
2754 | if (!p) | |
1da177e4 | 2755 | goto out_resource; |
c373b0a4 | 2756 | *p++ = cpu_to_be32(1); |
1da177e4 LT |
2757 | } |
2758 | if (bmval1 & FATTR4_WORD1_NUMLINKS) { | |
ddd1ea56 BF |
2759 | p = xdr_reserve_space(xdr, 4); |
2760 | if (!p) | |
1da177e4 | 2761 | goto out_resource; |
c373b0a4 | 2762 | *p++ = cpu_to_be32(stat.nlink); |
1da177e4 LT |
2763 | } |
2764 | if (bmval1 & FATTR4_WORD1_OWNER) { | |
ddd1ea56 | 2765 | status = nfsd4_encode_user(xdr, rqstp, stat.uid); |
1da177e4 LT |
2766 | if (status) |
2767 | goto out; | |
2768 | } | |
2769 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { | |
ddd1ea56 | 2770 | status = nfsd4_encode_group(xdr, rqstp, stat.gid); |
1da177e4 LT |
2771 | if (status) |
2772 | goto out; | |
2773 | } | |
2774 | if (bmval1 & FATTR4_WORD1_RAWDEV) { | |
ddd1ea56 BF |
2775 | p = xdr_reserve_space(xdr, 8); |
2776 | if (!p) | |
1da177e4 | 2777 | goto out_resource; |
c373b0a4 BF |
2778 | *p++ = cpu_to_be32((u32) MAJOR(stat.rdev)); |
2779 | *p++ = cpu_to_be32((u32) MINOR(stat.rdev)); | |
1da177e4 LT |
2780 | } |
2781 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { | |
ddd1ea56 BF |
2782 | p = xdr_reserve_space(xdr, 8); |
2783 | if (!p) | |
1da177e4 LT |
2784 | goto out_resource; |
2785 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; | |
b64c7f3b | 2786 | p = xdr_encode_hyper(p, dummy64); |
1da177e4 LT |
2787 | } |
2788 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { | |
ddd1ea56 BF |
2789 | p = xdr_reserve_space(xdr, 8); |
2790 | if (!p) | |
1da177e4 LT |
2791 | goto out_resource; |
2792 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; | |
b64c7f3b | 2793 | p = xdr_encode_hyper(p, dummy64); |
1da177e4 LT |
2794 | } |
2795 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { | |
ddd1ea56 BF |
2796 | p = xdr_reserve_space(xdr, 8); |
2797 | if (!p) | |
1da177e4 LT |
2798 | goto out_resource; |
2799 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; | |
b64c7f3b | 2800 | p = xdr_encode_hyper(p, dummy64); |
1da177e4 LT |
2801 | } |
2802 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { | |
ddd1ea56 BF |
2803 | p = xdr_reserve_space(xdr, 8); |
2804 | if (!p) | |
1da177e4 LT |
2805 | goto out_resource; |
2806 | dummy64 = (u64)stat.blocks << 9; | |
b64c7f3b | 2807 | p = xdr_encode_hyper(p, dummy64); |
1da177e4 LT |
2808 | } |
2809 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { | |
ddd1ea56 BF |
2810 | p = xdr_reserve_space(xdr, 12); |
2811 | if (!p) | |
1da177e4 | 2812 | goto out_resource; |
b64c7f3b | 2813 | p = xdr_encode_hyper(p, (s64)stat.atime.tv_sec); |
c373b0a4 | 2814 | *p++ = cpu_to_be32(stat.atime.tv_nsec); |
1da177e4 LT |
2815 | } |
2816 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { | |
ddd1ea56 BF |
2817 | p = xdr_reserve_space(xdr, 12); |
2818 | if (!p) | |
1da177e4 | 2819 | goto out_resource; |
16945141 | 2820 | p = encode_time_delta(p, d_inode(dentry)); |
1da177e4 LT |
2821 | } |
2822 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { | |
ddd1ea56 BF |
2823 | p = xdr_reserve_space(xdr, 12); |
2824 | if (!p) | |
1da177e4 | 2825 | goto out_resource; |
b64c7f3b | 2826 | p = xdr_encode_hyper(p, (s64)stat.ctime.tv_sec); |
c373b0a4 | 2827 | *p++ = cpu_to_be32(stat.ctime.tv_nsec); |
1da177e4 LT |
2828 | } |
2829 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { | |
ddd1ea56 BF |
2830 | p = xdr_reserve_space(xdr, 12); |
2831 | if (!p) | |
1da177e4 | 2832 | goto out_resource; |
b64c7f3b | 2833 | p = xdr_encode_hyper(p, (s64)stat.mtime.tv_sec); |
c373b0a4 | 2834 | *p++ = cpu_to_be32(stat.mtime.tv_nsec); |
1da177e4 LT |
2835 | } |
2836 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { | |
0a2050d7 KM |
2837 | struct kstat parent_stat; |
2838 | u64 ino = stat.ino; | |
2839 | ||
ddd1ea56 BF |
2840 | p = xdr_reserve_space(xdr, 8); |
2841 | if (!p) | |
1da177e4 | 2842 | goto out_resource; |
406a7ea9 FF |
2843 | /* |
2844 | * Get parent's attributes if not ignoring crossmount | |
2845 | * and this is the root of a cross-mounted filesystem. | |
2846 | */ | |
2847 | if (ignore_crossmnt == 0 && | |
0a2050d7 KM |
2848 | dentry == exp->ex_path.mnt->mnt_root) { |
2849 | err = get_parent_attributes(exp, &parent_stat); | |
2850 | if (err) | |
2851 | goto out_nfserr; | |
2852 | ino = parent_stat.ino; | |
2853 | } | |
2854 | p = xdr_encode_hyper(p, ino); | |
1da177e4 | 2855 | } |
9cf514cc | 2856 | #ifdef CONFIG_NFSD_PNFS |
6896f15a | 2857 | if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) { |
8a4c3926 | 2858 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
6896f15a KM |
2859 | if (status) |
2860 | goto out; | |
2861 | } | |
2862 | ||
2863 | if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) { | |
8a4c3926 | 2864 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
6896f15a KM |
2865 | if (status) |
2866 | goto out; | |
9cf514cc CH |
2867 | } |
2868 | ||
2869 | if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) { | |
2870 | p = xdr_reserve_space(xdr, 4); | |
2871 | if (!p) | |
2872 | goto out_resource; | |
2873 | *p++ = cpu_to_be32(stat.blksize); | |
2874 | } | |
2875 | #endif /* CONFIG_NFSD_PNFS */ | |
8c18f205 | 2876 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { |
b26b78cb TM |
2877 | u32 supp[3]; |
2878 | ||
2879 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); | |
2880 | supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0; | |
2881 | supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1; | |
2882 | supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2; | |
2883 | ||
2884 | status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]); | |
75976de6 KM |
2885 | if (status) |
2886 | goto out; | |
8c18f205 | 2887 | } |
7e705706 | 2888 | |
a8585763 BF |
2889 | if (bmval2 & FATTR4_WORD2_CHANGE_ATTR_TYPE) { |
2890 | p = xdr_reserve_space(xdr, 4); | |
2891 | if (!p) | |
2892 | goto out_resource; | |
2893 | if (IS_I_VERSION(d_inode(dentry))) | |
2894 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR); | |
2895 | else | |
2896 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA); | |
2897 | } | |
2898 | ||
0ab88ca4 | 2899 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
7d580722 KM |
2900 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
2901 | status = nfsd4_encode_security_label(xdr, rqstp, context, | |
2902 | contextlen); | |
2903 | if (status) | |
2904 | goto out; | |
2905 | } | |
0ab88ca4 | 2906 | #endif |
7d580722 | 2907 | |
082d4bd7 BF |
2908 | attrlen = htonl(xdr->buf->len - attrlen_offset - 4); |
2909 | write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4); | |
1da177e4 LT |
2910 | status = nfs_ok; |
2911 | ||
2912 | out: | |
ba4e55bb | 2913 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
18032ca0 DQ |
2914 | if (context) |
2915 | security_release_secctx(context, contextlen); | |
ba4e55bb | 2916 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
28e05dd8 | 2917 | kfree(acl); |
18df11d0 | 2918 | if (tempfh) { |
d50e6136 | 2919 | fh_put(tempfh); |
18df11d0 YZ |
2920 | kfree(tempfh); |
2921 | } | |
1fcea5b2 BF |
2922 | if (status) |
2923 | xdr_truncate_encode(xdr, starting_len); | |
1da177e4 LT |
2924 | return status; |
2925 | out_nfserr: | |
b8dd7b9a | 2926 | status = nfserrno(err); |
1da177e4 LT |
2927 | goto out; |
2928 | out_resource: | |
1da177e4 LT |
2929 | status = nfserr_resource; |
2930 | goto out; | |
1da177e4 LT |
2931 | } |
2932 | ||
2825a7f9 BF |
2933 | static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr, |
2934 | struct xdr_buf *buf, __be32 *p, int bytes) | |
2935 | { | |
2936 | xdr->scratch.iov_len = 0; | |
2937 | memset(buf, 0, sizeof(struct xdr_buf)); | |
2938 | buf->head[0].iov_base = p; | |
2939 | buf->head[0].iov_len = 0; | |
2940 | buf->len = 0; | |
2941 | xdr->buf = buf; | |
2942 | xdr->iov = buf->head; | |
2943 | xdr->p = p; | |
2944 | xdr->end = (void *)p + bytes; | |
2945 | buf->buflen = bytes; | |
2946 | } | |
2947 | ||
d5184658 BF |
2948 | __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, |
2949 | struct svc_fh *fhp, struct svc_export *exp, | |
2950 | struct dentry *dentry, u32 *bmval, | |
2951 | struct svc_rqst *rqstp, int ignore_crossmnt) | |
2952 | { | |
2825a7f9 | 2953 | struct xdr_buf dummy; |
d5184658 BF |
2954 | struct xdr_stream xdr; |
2955 | __be32 ret; | |
2956 | ||
2825a7f9 | 2957 | svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2); |
d5184658 BF |
2958 | ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp, |
2959 | ignore_crossmnt); | |
2960 | *p = xdr.p; | |
2961 | return ret; | |
2962 | } | |
2963 | ||
c0ce6ec8 BF |
2964 | static inline int attributes_need_mount(u32 *bmval) |
2965 | { | |
2966 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) | |
2967 | return 1; | |
2968 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) | |
2969 | return 1; | |
2970 | return 0; | |
2971 | } | |
2972 | ||
b37ad28b | 2973 | static __be32 |
561f0ed4 BF |
2974 | nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, |
2975 | const char *name, int namlen) | |
1da177e4 LT |
2976 | { |
2977 | struct svc_export *exp = cd->rd_fhp->fh_export; | |
2978 | struct dentry *dentry; | |
b37ad28b | 2979 | __be32 nfserr; |
406a7ea9 | 2980 | int ignore_crossmnt = 0; |
1da177e4 | 2981 | |
bbddca8e | 2982 | dentry = lookup_one_len_unlocked(name, cd->rd_fhp->fh_dentry, namlen); |
1da177e4 LT |
2983 | if (IS_ERR(dentry)) |
2984 | return nfserrno(PTR_ERR(dentry)); | |
2b0143b5 | 2985 | if (d_really_is_negative(dentry)) { |
b2c0cea6 | 2986 | /* |
bbddca8e N |
2987 | * we're not holding the i_mutex here, so there's |
2988 | * a window where this directory entry could have gone | |
2989 | * away. | |
b2c0cea6 BF |
2990 | */ |
2991 | dput(dentry); | |
2992 | return nfserr_noent; | |
2993 | } | |
1da177e4 LT |
2994 | |
2995 | exp_get(exp); | |
406a7ea9 FF |
2996 | /* |
2997 | * In the case of a mountpoint, the client may be asking for | |
2998 | * attributes that are only properties of the underlying filesystem | |
2999 | * as opposed to the cross-mounted file system. In such a case, | |
3000 | * we will not follow the cross mount and will fill the attribtutes | |
3001 | * directly from the mountpoint dentry. | |
3002 | */ | |
3227fa41 | 3003 | if (nfsd_mountpoint(dentry, exp)) { |
021d3a72 BF |
3004 | int err; |
3005 | ||
3227fa41 BF |
3006 | if (!(exp->ex_flags & NFSEXP_V4ROOT) |
3007 | && !attributes_need_mount(cd->rd_bmval)) { | |
3008 | ignore_crossmnt = 1; | |
3009 | goto out_encode; | |
3010 | } | |
dcb488a3 AA |
3011 | /* |
3012 | * Why the heck aren't we just using nfsd_lookup?? | |
3013 | * Different "."/".." handling? Something else? | |
3014 | * At least, add a comment here to explain.... | |
3015 | */ | |
021d3a72 BF |
3016 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
3017 | if (err) { | |
3018 | nfserr = nfserrno(err); | |
1da177e4 LT |
3019 | goto out_put; |
3020 | } | |
dcb488a3 AA |
3021 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
3022 | if (nfserr) | |
3023 | goto out_put; | |
1da177e4 LT |
3024 | |
3025 | } | |
3227fa41 | 3026 | out_encode: |
561f0ed4 | 3027 | nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval, |
406a7ea9 | 3028 | cd->rd_rqstp, ignore_crossmnt); |
1da177e4 LT |
3029 | out_put: |
3030 | dput(dentry); | |
3031 | exp_put(exp); | |
3032 | return nfserr; | |
3033 | } | |
3034 | ||
2ebbc012 | 3035 | static __be32 * |
561f0ed4 | 3036 | nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) |
1da177e4 | 3037 | { |
561f0ed4 BF |
3038 | __be32 *p; |
3039 | ||
c3a45617 | 3040 | p = xdr_reserve_space(xdr, 20); |
561f0ed4 | 3041 | if (!p) |
1da177e4 LT |
3042 | return NULL; |
3043 | *p++ = htonl(2); | |
3044 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ | |
3045 | *p++ = htonl(0); /* bmval1 */ | |
3046 | ||
87915c64 | 3047 | *p++ = htonl(4); /* attribute length */ |
1da177e4 | 3048 | *p++ = nfserr; /* no htonl */ |
1da177e4 LT |
3049 | return p; |
3050 | } | |
3051 | ||
3052 | static int | |
a0ad13ef N |
3053 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
3054 | loff_t offset, u64 ino, unsigned int d_type) | |
1da177e4 | 3055 | { |
a0ad13ef | 3056 | struct readdir_cd *ccd = ccdv; |
1da177e4 | 3057 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
561f0ed4 BF |
3058 | struct xdr_stream *xdr = cd->xdr; |
3059 | int start_offset = xdr->buf->len; | |
3060 | int cookie_offset; | |
aee37764 | 3061 | u32 name_and_cookie; |
561f0ed4 | 3062 | int entry_bytes; |
b37ad28b | 3063 | __be32 nfserr = nfserr_toosmall; |
561f0ed4 BF |
3064 | __be64 wire_offset; |
3065 | __be32 *p; | |
1da177e4 LT |
3066 | |
3067 | /* In nfsv4, "." and ".." never make it onto the wire.. */ | |
3068 | if (name && isdotent(name, namlen)) { | |
3069 | cd->common.err = nfs_ok; | |
3070 | return 0; | |
3071 | } | |
3072 | ||
561f0ed4 BF |
3073 | if (cd->cookie_offset) { |
3074 | wire_offset = cpu_to_be64(offset); | |
3075 | write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset, | |
3076 | &wire_offset, 8); | |
3077 | } | |
1da177e4 | 3078 | |
561f0ed4 BF |
3079 | p = xdr_reserve_space(xdr, 4); |
3080 | if (!p) | |
1da177e4 | 3081 | goto fail; |
1da177e4 | 3082 | *p++ = xdr_one; /* mark entry present */ |
561f0ed4 BF |
3083 | cookie_offset = xdr->buf->len; |
3084 | p = xdr_reserve_space(xdr, 3*4 + namlen); | |
3085 | if (!p) | |
3086 | goto fail; | |
1da177e4 LT |
3087 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
3088 | p = xdr_encode_array(p, name, namlen); /* name length & name */ | |
3089 | ||
561f0ed4 | 3090 | nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen); |
1da177e4 LT |
3091 | switch (nfserr) { |
3092 | case nfs_ok: | |
1da177e4 LT |
3093 | break; |
3094 | case nfserr_resource: | |
3095 | nfserr = nfserr_toosmall; | |
3096 | goto fail; | |
b2c0cea6 | 3097 | case nfserr_noent: |
f41c5ad2 | 3098 | xdr_truncate_encode(xdr, start_offset); |
b2c0cea6 | 3099 | goto skip_entry; |
1da177e4 LT |
3100 | default: |
3101 | /* | |
3102 | * If the client requested the RDATTR_ERROR attribute, | |
3103 | * we stuff the error code into this attribute | |
3104 | * and continue. If this attribute was not requested, | |
3105 | * then in accordance with the spec, we fail the | |
3106 | * entire READDIR operation(!) | |
3107 | */ | |
3108 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) | |
3109 | goto fail; | |
561f0ed4 | 3110 | p = nfsd4_encode_rdattr_error(xdr, nfserr); |
34081efc FI |
3111 | if (p == NULL) { |
3112 | nfserr = nfserr_toosmall; | |
1da177e4 | 3113 | goto fail; |
34081efc | 3114 | } |
1da177e4 | 3115 | } |
561f0ed4 BF |
3116 | nfserr = nfserr_toosmall; |
3117 | entry_bytes = xdr->buf->len - start_offset; | |
3118 | if (entry_bytes > cd->rd_maxcount) | |
3119 | goto fail; | |
3120 | cd->rd_maxcount -= entry_bytes; | |
aee37764 BF |
3121 | /* |
3122 | * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so | |
3123 | * let's always let through the first entry, at least: | |
3124 | */ | |
0ec016e3 BF |
3125 | if (!cd->rd_dircount) |
3126 | goto fail; | |
3127 | name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; | |
aee37764 BF |
3128 | if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) |
3129 | goto fail; | |
3130 | cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); | |
0ec016e3 | 3131 | |
561f0ed4 | 3132 | cd->cookie_offset = cookie_offset; |
b2c0cea6 | 3133 | skip_entry: |
1da177e4 LT |
3134 | cd->common.err = nfs_ok; |
3135 | return 0; | |
3136 | fail: | |
561f0ed4 | 3137 | xdr_truncate_encode(xdr, start_offset); |
1da177e4 LT |
3138 | cd->common.err = nfserr; |
3139 | return -EINVAL; | |
3140 | } | |
3141 | ||
d0a381dd BF |
3142 | static __be32 |
3143 | nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid) | |
e2f282b9 | 3144 | { |
bc749ca4 | 3145 | __be32 *p; |
e2f282b9 | 3146 | |
d0a381dd BF |
3147 | p = xdr_reserve_space(xdr, sizeof(stateid_t)); |
3148 | if (!p) | |
3149 | return nfserr_resource; | |
c373b0a4 | 3150 | *p++ = cpu_to_be32(sid->si_generation); |
0c0c267b BF |
3151 | p = xdr_encode_opaque_fixed(p, &sid->si_opaque, |
3152 | sizeof(stateid_opaque_t)); | |
d0a381dd | 3153 | return 0; |
e2f282b9 BH |
3154 | } |
3155 | ||
695e12f8 | 3156 | static __be32 |
b37ad28b | 3157 | nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access) |
1da177e4 | 3158 | { |
d0a381dd | 3159 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3160 | __be32 *p; |
1da177e4 | 3161 | |
bac966d6 BF |
3162 | p = xdr_reserve_space(xdr, 8); |
3163 | if (!p) | |
3164 | return nfserr_resource; | |
3165 | *p++ = cpu_to_be32(access->ac_supported); | |
3166 | *p++ = cpu_to_be32(access->ac_resp_access); | |
3167 | return 0; | |
1da177e4 LT |
3168 | } |
3169 | ||
1d1bc8f2 BF |
3170 | static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts) |
3171 | { | |
d0a381dd | 3172 | struct xdr_stream *xdr = &resp->xdr; |
1d1bc8f2 BF |
3173 | __be32 *p; |
3174 | ||
bac966d6 BF |
3175 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 8); |
3176 | if (!p) | |
3177 | return nfserr_resource; | |
3178 | p = xdr_encode_opaque_fixed(p, bcts->sessionid.data, | |
3179 | NFS4_MAX_SESSIONID_LEN); | |
3180 | *p++ = cpu_to_be32(bcts->dir); | |
3181 | /* Upshifting from TCP to RDMA is not supported */ | |
3182 | *p++ = cpu_to_be32(0); | |
3183 | return 0; | |
1d1bc8f2 BF |
3184 | } |
3185 | ||
695e12f8 | 3186 | static __be32 |
b37ad28b | 3187 | nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close) |
1da177e4 | 3188 | { |
d0a381dd BF |
3189 | struct xdr_stream *xdr = &resp->xdr; |
3190 | ||
bac966d6 | 3191 | return nfsd4_encode_stateid(xdr, &close->cl_stateid); |
1da177e4 LT |
3192 | } |
3193 | ||
3194 | ||
695e12f8 | 3195 | static __be32 |
b37ad28b | 3196 | nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit) |
1da177e4 | 3197 | { |
d0a381dd | 3198 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3199 | __be32 *p; |
1da177e4 | 3200 | |
bac966d6 BF |
3201 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
3202 | if (!p) | |
3203 | return nfserr_resource; | |
3204 | p = xdr_encode_opaque_fixed(p, commit->co_verf.data, | |
0c0c267b | 3205 | NFS4_VERIFIER_SIZE); |
bac966d6 | 3206 | return 0; |
1da177e4 LT |
3207 | } |
3208 | ||
695e12f8 | 3209 | static __be32 |
b37ad28b | 3210 | nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create) |
1da177e4 | 3211 | { |
d0a381dd | 3212 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3213 | __be32 *p; |
1da177e4 | 3214 | |
bac966d6 BF |
3215 | p = xdr_reserve_space(xdr, 20); |
3216 | if (!p) | |
3217 | return nfserr_resource; | |
3218 | encode_cinfo(p, &create->cr_cinfo); | |
b96811cd | 3219 | return nfsd4_encode_bitmap(xdr, create->cr_bmval[0], |
bac966d6 | 3220 | create->cr_bmval[1], create->cr_bmval[2]); |
1da177e4 LT |
3221 | } |
3222 | ||
b37ad28b AV |
3223 | static __be32 |
3224 | nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr) | |
1da177e4 LT |
3225 | { |
3226 | struct svc_fh *fhp = getattr->ga_fhp; | |
d5184658 | 3227 | struct xdr_stream *xdr = &resp->xdr; |
1da177e4 | 3228 | |
bac966d6 BF |
3229 | return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry, |
3230 | getattr->ga_bmval, resp->rqstp, 0); | |
1da177e4 LT |
3231 | } |
3232 | ||
695e12f8 BH |
3233 | static __be32 |
3234 | nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp) | |
1da177e4 | 3235 | { |
d0a381dd | 3236 | struct xdr_stream *xdr = &resp->xdr; |
695e12f8 | 3237 | struct svc_fh *fhp = *fhpp; |
1da177e4 | 3238 | unsigned int len; |
bc749ca4 | 3239 | __be32 *p; |
1da177e4 | 3240 | |
bac966d6 BF |
3241 | len = fhp->fh_handle.fh_size; |
3242 | p = xdr_reserve_space(xdr, len + 4); | |
3243 | if (!p) | |
3244 | return nfserr_resource; | |
3245 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len); | |
3246 | return 0; | |
1da177e4 LT |
3247 | } |
3248 | ||
3249 | /* | |
3250 | * Including all fields other than the name, a LOCK4denied structure requires | |
3251 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. | |
3252 | */ | |
d0a381dd BF |
3253 | static __be32 |
3254 | nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld) | |
1da177e4 | 3255 | { |
7c13f344 | 3256 | struct xdr_netobj *conf = &ld->ld_owner; |
bc749ca4 | 3257 | __be32 *p; |
1da177e4 | 3258 | |
8c7424cf | 3259 | again: |
d0a381dd | 3260 | p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); |
8c7424cf BF |
3261 | if (!p) { |
3262 | /* | |
3263 | * Don't fail to return the result just because we can't | |
3264 | * return the conflicting open: | |
3265 | */ | |
3266 | if (conf->len) { | |
f98bac5a | 3267 | kfree(conf->data); |
8c7424cf BF |
3268 | conf->len = 0; |
3269 | conf->data = NULL; | |
3270 | goto again; | |
3271 | } | |
d0a381dd | 3272 | return nfserr_resource; |
8c7424cf | 3273 | } |
b64c7f3b BF |
3274 | p = xdr_encode_hyper(p, ld->ld_start); |
3275 | p = xdr_encode_hyper(p, ld->ld_length); | |
c373b0a4 | 3276 | *p++ = cpu_to_be32(ld->ld_type); |
7c13f344 | 3277 | if (conf->len) { |
0c0c267b BF |
3278 | p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8); |
3279 | p = xdr_encode_opaque(p, conf->data, conf->len); | |
f98bac5a | 3280 | kfree(conf->data); |
1da177e4 | 3281 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
b64c7f3b | 3282 | p = xdr_encode_hyper(p, (u64)0); /* clientid */ |
c373b0a4 | 3283 | *p++ = cpu_to_be32(0); /* length of owner name */ |
1da177e4 | 3284 | } |
d0a381dd | 3285 | return nfserr_denied; |
1da177e4 LT |
3286 | } |
3287 | ||
695e12f8 | 3288 | static __be32 |
b37ad28b | 3289 | nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock) |
1da177e4 | 3290 | { |
d0a381dd BF |
3291 | struct xdr_stream *xdr = &resp->xdr; |
3292 | ||
e2f282b9 | 3293 | if (!nfserr) |
d0a381dd | 3294 | nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid); |
e2f282b9 | 3295 | else if (nfserr == nfserr_denied) |
d0a381dd | 3296 | nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied); |
f98bac5a | 3297 | |
695e12f8 | 3298 | return nfserr; |
1da177e4 LT |
3299 | } |
3300 | ||
695e12f8 | 3301 | static __be32 |
b37ad28b | 3302 | nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt) |
1da177e4 | 3303 | { |
d0a381dd BF |
3304 | struct xdr_stream *xdr = &resp->xdr; |
3305 | ||
1da177e4 | 3306 | if (nfserr == nfserr_denied) |
d0a381dd | 3307 | nfsd4_encode_lock_denied(xdr, &lockt->lt_denied); |
695e12f8 | 3308 | return nfserr; |
1da177e4 LT |
3309 | } |
3310 | ||
695e12f8 | 3311 | static __be32 |
b37ad28b | 3312 | nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku) |
1da177e4 | 3313 | { |
d0a381dd BF |
3314 | struct xdr_stream *xdr = &resp->xdr; |
3315 | ||
bac966d6 | 3316 | return nfsd4_encode_stateid(xdr, &locku->lu_stateid); |
1da177e4 LT |
3317 | } |
3318 | ||
3319 | ||
695e12f8 | 3320 | static __be32 |
b37ad28b | 3321 | nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link) |
1da177e4 | 3322 | { |
d0a381dd | 3323 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3324 | __be32 *p; |
1da177e4 | 3325 | |
bac966d6 BF |
3326 | p = xdr_reserve_space(xdr, 20); |
3327 | if (!p) | |
3328 | return nfserr_resource; | |
3329 | p = encode_cinfo(p, &link->li_cinfo); | |
3330 | return 0; | |
1da177e4 LT |
3331 | } |
3332 | ||
3333 | ||
695e12f8 | 3334 | static __be32 |
b37ad28b | 3335 | nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open) |
1da177e4 | 3336 | { |
d0a381dd | 3337 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3338 | __be32 *p; |
1da177e4 | 3339 | |
d0a381dd BF |
3340 | nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid); |
3341 | if (nfserr) | |
bac966d6 | 3342 | return nfserr; |
75976de6 | 3343 | p = xdr_reserve_space(xdr, 24); |
d0a381dd BF |
3344 | if (!p) |
3345 | return nfserr_resource; | |
d05d5744 | 3346 | p = encode_cinfo(p, &open->op_cinfo); |
c373b0a4 | 3347 | *p++ = cpu_to_be32(open->op_rflags); |
1da177e4 | 3348 | |
75976de6 KM |
3349 | nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1], |
3350 | open->op_bmval[2]); | |
3351 | if (nfserr) | |
bac966d6 | 3352 | return nfserr; |
75976de6 KM |
3353 | |
3354 | p = xdr_reserve_space(xdr, 4); | |
3355 | if (!p) | |
3356 | return nfserr_resource; | |
3357 | ||
3358 | *p++ = cpu_to_be32(open->op_delegate_type); | |
1da177e4 LT |
3359 | switch (open->op_delegate_type) { |
3360 | case NFS4_OPEN_DELEGATE_NONE: | |
3361 | break; | |
3362 | case NFS4_OPEN_DELEGATE_READ: | |
d0a381dd BF |
3363 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
3364 | if (nfserr) | |
3365 | return nfserr; | |
3366 | p = xdr_reserve_space(xdr, 20); | |
3367 | if (!p) | |
3368 | return nfserr_resource; | |
c373b0a4 | 3369 | *p++ = cpu_to_be32(open->op_recall); |
1da177e4 LT |
3370 | |
3371 | /* | |
3372 | * TODO: ACE's in delegations | |
3373 | */ | |
c373b0a4 BF |
3374 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
3375 | *p++ = cpu_to_be32(0); | |
3376 | *p++ = cpu_to_be32(0); | |
3377 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ | |
1da177e4 LT |
3378 | break; |
3379 | case NFS4_OPEN_DELEGATE_WRITE: | |
d0a381dd BF |
3380 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
3381 | if (nfserr) | |
3382 | return nfserr; | |
3383 | p = xdr_reserve_space(xdr, 32); | |
3384 | if (!p) | |
3385 | return nfserr_resource; | |
c373b0a4 | 3386 | *p++ = cpu_to_be32(0); |
1da177e4 LT |
3387 | |
3388 | /* | |
3389 | * TODO: space_limit's in delegations | |
3390 | */ | |
c373b0a4 BF |
3391 | *p++ = cpu_to_be32(NFS4_LIMIT_SIZE); |
3392 | *p++ = cpu_to_be32(~(u32)0); | |
3393 | *p++ = cpu_to_be32(~(u32)0); | |
1da177e4 LT |
3394 | |
3395 | /* | |
3396 | * TODO: ACE's in delegations | |
3397 | */ | |
c373b0a4 BF |
3398 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
3399 | *p++ = cpu_to_be32(0); | |
3400 | *p++ = cpu_to_be32(0); | |
3401 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ | |
1da177e4 | 3402 | break; |
d24433cd BH |
3403 | case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ |
3404 | switch (open->op_why_no_deleg) { | |
3405 | case WND4_CONTENTION: | |
3406 | case WND4_RESOURCE: | |
d0a381dd BF |
3407 | p = xdr_reserve_space(xdr, 8); |
3408 | if (!p) | |
3409 | return nfserr_resource; | |
c373b0a4 BF |
3410 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
3411 | /* deleg signaling not supported yet: */ | |
3412 | *p++ = cpu_to_be32(0); | |
d24433cd BH |
3413 | break; |
3414 | default: | |
d0a381dd BF |
3415 | p = xdr_reserve_space(xdr, 4); |
3416 | if (!p) | |
3417 | return nfserr_resource; | |
c373b0a4 | 3418 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
d24433cd | 3419 | } |
d24433cd | 3420 | break; |
1da177e4 LT |
3421 | default: |
3422 | BUG(); | |
3423 | } | |
3424 | /* XXX save filehandle here */ | |
bac966d6 | 3425 | return 0; |
1da177e4 LT |
3426 | } |
3427 | ||
695e12f8 | 3428 | static __be32 |
b37ad28b | 3429 | nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc) |
1da177e4 | 3430 | { |
d0a381dd BF |
3431 | struct xdr_stream *xdr = &resp->xdr; |
3432 | ||
bac966d6 | 3433 | return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid); |
1da177e4 LT |
3434 | } |
3435 | ||
695e12f8 | 3436 | static __be32 |
b37ad28b | 3437 | nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od) |
1da177e4 | 3438 | { |
d0a381dd BF |
3439 | struct xdr_stream *xdr = &resp->xdr; |
3440 | ||
bac966d6 | 3441 | return nfsd4_encode_stateid(xdr, &od->od_stateid); |
1da177e4 LT |
3442 | } |
3443 | ||
dc97618d BF |
3444 | static __be32 nfsd4_encode_splice_read( |
3445 | struct nfsd4_compoundres *resp, | |
3446 | struct nfsd4_read *read, | |
3447 | struct file *file, unsigned long maxcount) | |
1da177e4 | 3448 | { |
ddd1ea56 | 3449 | struct xdr_stream *xdr = &resp->xdr; |
34a78b48 | 3450 | struct xdr_buf *buf = xdr->buf; |
dc97618d | 3451 | u32 eof; |
ac503e4a | 3452 | long len; |
30596768 | 3453 | int space_left; |
dc97618d | 3454 | __be32 nfserr; |
fec25fa4 | 3455 | __be32 *p = xdr->p - 2; |
1da177e4 | 3456 | |
d5d5c304 KM |
3457 | /* Make sure there will be room for padding if needed */ |
3458 | if (xdr->end - xdr->p < 1) | |
d0a381dd | 3459 | return nfserr_resource; |
dc97618d | 3460 | |
ac503e4a | 3461 | len = maxcount; |
87c5942e CL |
3462 | nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp, |
3463 | file, read->rd_offset, &maxcount); | |
3464 | read->rd_length = maxcount; | |
dc97618d BF |
3465 | if (nfserr) { |
3466 | /* | |
3467 | * nfsd_splice_actor may have already messed with the | |
3468 | * page length; reset it so as not to confuse | |
3469 | * xdr_truncate_encode: | |
3470 | */ | |
34a78b48 | 3471 | buf->page_len = 0; |
dc97618d | 3472 | return nfserr; |
b0e35fda | 3473 | } |
1da177e4 | 3474 | |
ac503e4a BC |
3475 | eof = nfsd_eof_on_read(len, maxcount, read->rd_offset, |
3476 | d_inode(read->rd_fhp->fh_dentry)->i_size); | |
4e21ac4b | 3477 | |
fec25fa4 BF |
3478 | *(p++) = htonl(eof); |
3479 | *(p++) = htonl(maxcount); | |
dc97618d | 3480 | |
34a78b48 BF |
3481 | buf->page_len = maxcount; |
3482 | buf->len += maxcount; | |
15b23ef5 BF |
3483 | xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) |
3484 | / PAGE_SIZE; | |
dc97618d BF |
3485 | |
3486 | /* Use rest of head for padding and remaining ops: */ | |
34a78b48 BF |
3487 | buf->tail[0].iov_base = xdr->p; |
3488 | buf->tail[0].iov_len = 0; | |
fec25fa4 | 3489 | xdr->iov = buf->tail; |
dc97618d | 3490 | if (maxcount&3) { |
fec25fa4 BF |
3491 | int pad = 4 - (maxcount&3); |
3492 | ||
3493 | *(xdr->p++) = 0; | |
3494 | ||
34a78b48 | 3495 | buf->tail[0].iov_base += maxcount&3; |
fec25fa4 BF |
3496 | buf->tail[0].iov_len = pad; |
3497 | buf->len += pad; | |
b0e35fda | 3498 | } |
2825a7f9 | 3499 | |
dc97618d | 3500 | space_left = min_t(int, (void *)xdr->end - (void *)xdr->p, |
34a78b48 BF |
3501 | buf->buflen - buf->len); |
3502 | buf->buflen = buf->len + space_left; | |
dc97618d BF |
3503 | xdr->end = (__be32 *)((void *)xdr->end + space_left); |
3504 | ||
3505 | return 0; | |
3506 | } | |
3507 | ||
3508 | static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, | |
3509 | struct nfsd4_read *read, | |
3510 | struct file *file, unsigned long maxcount) | |
3511 | { | |
3512 | struct xdr_stream *xdr = &resp->xdr; | |
3513 | u32 eof; | |
3514 | int v; | |
dc97618d | 3515 | int starting_len = xdr->buf->len - 8; |
dc97618d | 3516 | long len; |
b0420980 | 3517 | int thislen; |
dc97618d BF |
3518 | __be32 nfserr; |
3519 | __be32 tmp; | |
3520 | __be32 *p; | |
b0420980 BF |
3521 | u32 zzz = 0; |
3522 | int pad; | |
1da177e4 LT |
3523 | |
3524 | len = maxcount; | |
3525 | v = 0; | |
6ff9897d | 3526 | |
1055414f | 3527 | thislen = min_t(long, len, ((void *)xdr->end - (void *)xdr->p)); |
b0420980 BF |
3528 | p = xdr_reserve_space(xdr, (thislen+3)&~3); |
3529 | WARN_ON_ONCE(!p); | |
3530 | resp->rqstp->rq_vec[v].iov_base = p; | |
3531 | resp->rqstp->rq_vec[v].iov_len = thislen; | |
3532 | v++; | |
3533 | len -= thislen; | |
3534 | ||
3535 | while (len) { | |
6ff9897d | 3536 | thislen = min_t(long, len, PAGE_SIZE); |
b0420980 BF |
3537 | p = xdr_reserve_space(xdr, (thislen+3)&~3); |
3538 | WARN_ON_ONCE(!p); | |
3539 | resp->rqstp->rq_vec[v].iov_base = p; | |
6ff9897d | 3540 | resp->rqstp->rq_vec[v].iov_len = thislen; |
1da177e4 | 3541 | v++; |
6ff9897d | 3542 | len -= thislen; |
1da177e4 LT |
3543 | } |
3544 | read->rd_vlen = v; | |
3545 | ||
ac503e4a | 3546 | len = maxcount; |
87c5942e CL |
3547 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
3548 | resp->rqstp->rq_vec, read->rd_vlen, &maxcount); | |
3549 | read->rd_length = maxcount; | |
dc97618d | 3550 | if (nfserr) |
1da177e4 | 3551 | return nfserr; |
b0420980 | 3552 | xdr_truncate_encode(xdr, starting_len + 8 + ((maxcount+3)&~3)); |
dc97618d | 3553 | |
ac503e4a BC |
3554 | eof = nfsd_eof_on_read(len, maxcount, read->rd_offset, |
3555 | d_inode(read->rd_fhp->fh_dentry)->i_size); | |
1da177e4 | 3556 | |
dc97618d BF |
3557 | tmp = htonl(eof); |
3558 | write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); | |
3559 | tmp = htonl(maxcount); | |
3560 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); | |
3561 | ||
b0420980 BF |
3562 | pad = (maxcount&3) ? 4 - (maxcount&3) : 0; |
3563 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount, | |
3564 | &zzz, pad); | |
1da177e4 | 3565 | return 0; |
dc97618d BF |
3566 | |
3567 | } | |
3568 | ||
3569 | static __be32 | |
3570 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, | |
3571 | struct nfsd4_read *read) | |
3572 | { | |
3573 | unsigned long maxcount; | |
3574 | struct xdr_stream *xdr = &resp->xdr; | |
5c4583b2 | 3575 | struct file *file; |
dc97618d | 3576 | int starting_len = xdr->buf->len; |
dc97618d | 3577 | __be32 *p; |
dc97618d | 3578 | |
5c4583b2 JL |
3579 | if (nfserr) |
3580 | return nfserr; | |
3581 | file = read->rd_nf->nf_file; | |
3582 | ||
dc97618d BF |
3583 | p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */ |
3584 | if (!p) { | |
779fb0f3 | 3585 | WARN_ON_ONCE(test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)); |
bac966d6 | 3586 | return nfserr_resource; |
dc97618d | 3587 | } |
68e8bb03 CH |
3588 | if (resp->xdr.buf->page_len && |
3589 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) { | |
b0420980 | 3590 | WARN_ON_ONCE(1); |
bac966d6 | 3591 | return nfserr_resource; |
dc97618d | 3592 | } |
dc97618d BF |
3593 | xdr_commit_encode(xdr); |
3594 | ||
3595 | maxcount = svc_max_payload(resp->rqstp); | |
68e8bb03 CH |
3596 | maxcount = min_t(unsigned long, maxcount, |
3597 | (xdr->buf->buflen - xdr->buf->len)); | |
3c7aa15d | 3598 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
dc97618d | 3599 | |
68e8bb03 CH |
3600 | if (file->f_op->splice_read && |
3601 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) | |
96bcad50 | 3602 | nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount); |
dc97618d | 3603 | else |
96bcad50 | 3604 | nfserr = nfsd4_encode_readv(resp, read, file, maxcount); |
dc97618d | 3605 | |
96bcad50 | 3606 | if (nfserr) |
dc97618d | 3607 | xdr_truncate_encode(xdr, starting_len); |
96bcad50 | 3608 | |
96bcad50 | 3609 | return nfserr; |
1da177e4 LT |
3610 | } |
3611 | ||
b37ad28b AV |
3612 | static __be32 |
3613 | nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink) | |
1da177e4 LT |
3614 | { |
3615 | int maxcount; | |
476a7b1f BF |
3616 | __be32 wire_count; |
3617 | int zero = 0; | |
ddd1ea56 | 3618 | struct xdr_stream *xdr = &resp->xdr; |
1fcea5b2 | 3619 | int length_offset = xdr->buf->len; |
bc749ca4 | 3620 | __be32 *p; |
1da177e4 | 3621 | |
2825a7f9 BF |
3622 | p = xdr_reserve_space(xdr, 4); |
3623 | if (!p) | |
3624 | return nfserr_resource; | |
1da177e4 | 3625 | maxcount = PAGE_SIZE; |
d0a381dd | 3626 | |
476a7b1f BF |
3627 | p = xdr_reserve_space(xdr, maxcount); |
3628 | if (!p) | |
4e21ac4b | 3629 | return nfserr_resource; |
1da177e4 | 3630 | /* |
fd4a0edf MS |
3631 | * XXX: By default, vfs_readlink() will truncate symlinks if they |
3632 | * would overflow the buffer. Is this kosher in NFSv4? If not, one | |
3633 | * easy fix is: if vfs_readlink() precisely fills the buffer, assume | |
3634 | * that truncation occurred, and return NFS4ERR_RESOURCE. | |
1da177e4 | 3635 | */ |
476a7b1f BF |
3636 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, |
3637 | (char *)p, &maxcount); | |
1da177e4 | 3638 | if (nfserr == nfserr_isdir) |
d3f627c8 BF |
3639 | nfserr = nfserr_inval; |
3640 | if (nfserr) { | |
1fcea5b2 | 3641 | xdr_truncate_encode(xdr, length_offset); |
1da177e4 | 3642 | return nfserr; |
d3f627c8 | 3643 | } |
1da177e4 | 3644 | |
476a7b1f BF |
3645 | wire_count = htonl(maxcount); |
3646 | write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4); | |
69bbd9c7 | 3647 | xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4)); |
476a7b1f BF |
3648 | if (maxcount & 3) |
3649 | write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, | |
3650 | &zero, 4 - (maxcount&3)); | |
1da177e4 LT |
3651 | return 0; |
3652 | } | |
3653 | ||
b37ad28b AV |
3654 | static __be32 |
3655 | nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir) | |
1da177e4 LT |
3656 | { |
3657 | int maxcount; | |
561f0ed4 | 3658 | int bytes_left; |
1da177e4 | 3659 | loff_t offset; |
561f0ed4 | 3660 | __be64 wire_offset; |
ddd1ea56 | 3661 | struct xdr_stream *xdr = &resp->xdr; |
1fcea5b2 | 3662 | int starting_len = xdr->buf->len; |
bc749ca4 | 3663 | __be32 *p; |
1da177e4 | 3664 | |
d0a381dd BF |
3665 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
3666 | if (!p) | |
3667 | return nfserr_resource; | |
1da177e4 LT |
3668 | |
3669 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ | |
c373b0a4 BF |
3670 | *p++ = cpu_to_be32(0); |
3671 | *p++ = cpu_to_be32(0); | |
4aea24b2 BF |
3672 | resp->xdr.buf->head[0].iov_len = ((char *)resp->xdr.p) |
3673 | - (char *)resp->xdr.buf->head[0].iov_base; | |
1da177e4 LT |
3674 | |
3675 | /* | |
561f0ed4 BF |
3676 | * Number of bytes left for directory entries allowing for the |
3677 | * final 8 bytes of the readdir and a following failed op: | |
3678 | */ | |
3679 | bytes_left = xdr->buf->buflen - xdr->buf->len | |
3680 | - COMPOUND_ERR_SLACK_SPACE - 8; | |
3681 | if (bytes_left < 0) { | |
3682 | nfserr = nfserr_resource; | |
3683 | goto err_no_verf; | |
3684 | } | |
9c2ece6e SM |
3685 | maxcount = svc_max_payload(resp->rqstp); |
3686 | maxcount = min_t(u32, readdir->rd_maxcount, maxcount); | |
561f0ed4 BF |
3687 | /* |
3688 | * Note the rfc defines rd_maxcount as the size of the | |
3689 | * READDIR4resok structure, which includes the verifier above | |
3690 | * and the 8 bytes encoded at the end of this function: | |
1da177e4 | 3691 | */ |
561f0ed4 BF |
3692 | if (maxcount < 16) { |
3693 | nfserr = nfserr_toosmall; | |
1da177e4 LT |
3694 | goto err_no_verf; |
3695 | } | |
561f0ed4 | 3696 | maxcount = min_t(int, maxcount-16, bytes_left); |
1da177e4 | 3697 | |
aee37764 BF |
3698 | /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ |
3699 | if (!readdir->rd_dircount) | |
9c2ece6e | 3700 | readdir->rd_dircount = svc_max_payload(resp->rqstp); |
aee37764 | 3701 | |
561f0ed4 BF |
3702 | readdir->xdr = xdr; |
3703 | readdir->rd_maxcount = maxcount; | |
1da177e4 | 3704 | readdir->common.err = 0; |
561f0ed4 | 3705 | readdir->cookie_offset = 0; |
1da177e4 LT |
3706 | |
3707 | offset = readdir->rd_cookie; | |
3708 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, | |
3709 | &offset, | |
3710 | &readdir->common, nfsd4_encode_dirent); | |
3711 | if (nfserr == nfs_ok && | |
3712 | readdir->common.err == nfserr_toosmall && | |
561f0ed4 BF |
3713 | xdr->buf->len == starting_len + 8) { |
3714 | /* nothing encoded; which limit did we hit?: */ | |
3715 | if (maxcount - 16 < bytes_left) | |
3716 | /* It was the fault of rd_maxcount: */ | |
3717 | nfserr = nfserr_toosmall; | |
3718 | else | |
3719 | /* We ran out of buffer space: */ | |
3720 | nfserr = nfserr_resource; | |
3721 | } | |
1da177e4 LT |
3722 | if (nfserr) |
3723 | goto err_no_verf; | |
3724 | ||
561f0ed4 BF |
3725 | if (readdir->cookie_offset) { |
3726 | wire_offset = cpu_to_be64(offset); | |
3727 | write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, | |
3728 | &wire_offset, 8); | |
3729 | } | |
1da177e4 | 3730 | |
561f0ed4 BF |
3731 | p = xdr_reserve_space(xdr, 8); |
3732 | if (!p) { | |
3733 | WARN_ON_ONCE(1); | |
3734 | goto err_no_verf; | |
3735 | } | |
1da177e4 LT |
3736 | *p++ = 0; /* no more entries */ |
3737 | *p++ = htonl(readdir->common.err == nfserr_eof); | |
1da177e4 LT |
3738 | |
3739 | return 0; | |
3740 | err_no_verf: | |
1fcea5b2 | 3741 | xdr_truncate_encode(xdr, starting_len); |
1da177e4 LT |
3742 | return nfserr; |
3743 | } | |
3744 | ||
695e12f8 | 3745 | static __be32 |
b37ad28b | 3746 | nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove) |
1da177e4 | 3747 | { |
d0a381dd | 3748 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3749 | __be32 *p; |
1da177e4 | 3750 | |
bac966d6 BF |
3751 | p = xdr_reserve_space(xdr, 20); |
3752 | if (!p) | |
3753 | return nfserr_resource; | |
3754 | p = encode_cinfo(p, &remove->rm_cinfo); | |
3755 | return 0; | |
1da177e4 LT |
3756 | } |
3757 | ||
695e12f8 | 3758 | static __be32 |
b37ad28b | 3759 | nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename) |
1da177e4 | 3760 | { |
d0a381dd | 3761 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3762 | __be32 *p; |
1da177e4 | 3763 | |
bac966d6 BF |
3764 | p = xdr_reserve_space(xdr, 40); |
3765 | if (!p) | |
3766 | return nfserr_resource; | |
3767 | p = encode_cinfo(p, &rename->rn_sinfo); | |
3768 | p = encode_cinfo(p, &rename->rn_tinfo); | |
3769 | return 0; | |
1da177e4 LT |
3770 | } |
3771 | ||
695e12f8 | 3772 | static __be32 |
bac966d6 | 3773 | nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) |
dcb488a3 | 3774 | { |
676e4ebd | 3775 | u32 i, nflavs, supported; |
4796f457 BF |
3776 | struct exp_flavor_info *flavs; |
3777 | struct exp_flavor_info def_flavs[2]; | |
676e4ebd CL |
3778 | __be32 *p, *flavorsp; |
3779 | static bool report = true; | |
dcb488a3 | 3780 | |
4796f457 BF |
3781 | if (exp->ex_nflavors) { |
3782 | flavs = exp->ex_flavors; | |
3783 | nflavs = exp->ex_nflavors; | |
3784 | } else { /* Handling of some defaults in absence of real secinfo: */ | |
3785 | flavs = def_flavs; | |
3786 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { | |
3787 | nflavs = 2; | |
3788 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; | |
3789 | flavs[1].pseudoflavor = RPC_AUTH_NULL; | |
3790 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { | |
3791 | nflavs = 1; | |
3792 | flavs[0].pseudoflavor | |
3793 | = svcauth_gss_flavor(exp->ex_client); | |
3794 | } else { | |
3795 | nflavs = 1; | |
3796 | flavs[0].pseudoflavor | |
3797 | = exp->ex_client->flavour->flavour; | |
3798 | } | |
3799 | } | |
3800 | ||
676e4ebd | 3801 | supported = 0; |
d0a381dd BF |
3802 | p = xdr_reserve_space(xdr, 4); |
3803 | if (!p) | |
bac966d6 | 3804 | return nfserr_resource; |
676e4ebd | 3805 | flavorsp = p++; /* to be backfilled later */ |
676e4ebd | 3806 | |
4796f457 | 3807 | for (i = 0; i < nflavs; i++) { |
676e4ebd | 3808 | rpc_authflavor_t pf = flavs[i].pseudoflavor; |
a77c806f | 3809 | struct rpcsec_gss_info info; |
dcb488a3 | 3810 | |
676e4ebd CL |
3811 | if (rpcauth_get_gssinfo(pf, &info) == 0) { |
3812 | supported++; | |
d0a381dd BF |
3813 | p = xdr_reserve_space(xdr, 4 + 4 + |
3814 | XDR_LEN(info.oid.len) + 4 + 4); | |
3815 | if (!p) | |
bac966d6 | 3816 | return nfserr_resource; |
c373b0a4 | 3817 | *p++ = cpu_to_be32(RPC_AUTH_GSS); |
0c0c267b | 3818 | p = xdr_encode_opaque(p, info.oid.data, info.oid.len); |
c373b0a4 BF |
3819 | *p++ = cpu_to_be32(info.qop); |
3820 | *p++ = cpu_to_be32(info.service); | |
676e4ebd CL |
3821 | } else if (pf < RPC_AUTH_MAXFLAVOR) { |
3822 | supported++; | |
d0a381dd BF |
3823 | p = xdr_reserve_space(xdr, 4); |
3824 | if (!p) | |
bac966d6 | 3825 | return nfserr_resource; |
c373b0a4 | 3826 | *p++ = cpu_to_be32(pf); |
676e4ebd CL |
3827 | } else { |
3828 | if (report) | |
3829 | pr_warn("NFS: SECINFO: security flavor %u " | |
3830 | "is not supported\n", pf); | |
dcb488a3 AA |
3831 | } |
3832 | } | |
a77c806f | 3833 | |
676e4ebd CL |
3834 | if (nflavs != supported) |
3835 | report = false; | |
3836 | *flavorsp = htonl(supported); | |
bac966d6 | 3837 | return 0; |
dcb488a3 AA |
3838 | } |
3839 | ||
22b6dee8 MJ |
3840 | static __be32 |
3841 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, | |
3842 | struct nfsd4_secinfo *secinfo) | |
3843 | { | |
d0a381dd BF |
3844 | struct xdr_stream *xdr = &resp->xdr; |
3845 | ||
bac966d6 | 3846 | return nfsd4_do_encode_secinfo(xdr, secinfo->si_exp); |
22b6dee8 MJ |
3847 | } |
3848 | ||
3849 | static __be32 | |
3850 | nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr, | |
3851 | struct nfsd4_secinfo_no_name *secinfo) | |
3852 | { | |
d0a381dd BF |
3853 | struct xdr_stream *xdr = &resp->xdr; |
3854 | ||
bac966d6 | 3855 | return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp); |
22b6dee8 MJ |
3856 | } |
3857 | ||
1da177e4 LT |
3858 | /* |
3859 | * The SETATTR encode routine is special -- it always encodes a bitmap, | |
3860 | * regardless of the error status. | |
3861 | */ | |
695e12f8 | 3862 | static __be32 |
b37ad28b | 3863 | nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr) |
1da177e4 | 3864 | { |
d0a381dd | 3865 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3866 | __be32 *p; |
1da177e4 | 3867 | |
d0a381dd BF |
3868 | p = xdr_reserve_space(xdr, 16); |
3869 | if (!p) | |
3870 | return nfserr_resource; | |
1da177e4 | 3871 | if (nfserr) { |
c373b0a4 BF |
3872 | *p++ = cpu_to_be32(3); |
3873 | *p++ = cpu_to_be32(0); | |
3874 | *p++ = cpu_to_be32(0); | |
3875 | *p++ = cpu_to_be32(0); | |
1da177e4 LT |
3876 | } |
3877 | else { | |
c373b0a4 BF |
3878 | *p++ = cpu_to_be32(3); |
3879 | *p++ = cpu_to_be32(setattr->sa_bmval[0]); | |
3880 | *p++ = cpu_to_be32(setattr->sa_bmval[1]); | |
3881 | *p++ = cpu_to_be32(setattr->sa_bmval[2]); | |
1da177e4 | 3882 | } |
695e12f8 | 3883 | return nfserr; |
1da177e4 LT |
3884 | } |
3885 | ||
695e12f8 | 3886 | static __be32 |
b37ad28b | 3887 | nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd) |
1da177e4 | 3888 | { |
d0a381dd | 3889 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3890 | __be32 *p; |
1da177e4 LT |
3891 | |
3892 | if (!nfserr) { | |
d0a381dd BF |
3893 | p = xdr_reserve_space(xdr, 8 + NFS4_VERIFIER_SIZE); |
3894 | if (!p) | |
3895 | return nfserr_resource; | |
0c0c267b BF |
3896 | p = xdr_encode_opaque_fixed(p, &scd->se_clientid, 8); |
3897 | p = xdr_encode_opaque_fixed(p, &scd->se_confirm, | |
3898 | NFS4_VERIFIER_SIZE); | |
1da177e4 LT |
3899 | } |
3900 | else if (nfserr == nfserr_clid_inuse) { | |
d0a381dd BF |
3901 | p = xdr_reserve_space(xdr, 8); |
3902 | if (!p) | |
3903 | return nfserr_resource; | |
c373b0a4 BF |
3904 | *p++ = cpu_to_be32(0); |
3905 | *p++ = cpu_to_be32(0); | |
1da177e4 | 3906 | } |
695e12f8 | 3907 | return nfserr; |
1da177e4 LT |
3908 | } |
3909 | ||
695e12f8 | 3910 | static __be32 |
b37ad28b | 3911 | nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write) |
1da177e4 | 3912 | { |
d0a381dd | 3913 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3914 | __be32 *p; |
1da177e4 | 3915 | |
bac966d6 BF |
3916 | p = xdr_reserve_space(xdr, 16); |
3917 | if (!p) | |
3918 | return nfserr_resource; | |
3919 | *p++ = cpu_to_be32(write->wr_bytes_written); | |
3920 | *p++ = cpu_to_be32(write->wr_how_written); | |
3921 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, | |
3922 | NFS4_VERIFIER_SIZE); | |
3923 | return 0; | |
1da177e4 LT |
3924 | } |
3925 | ||
2db134eb | 3926 | static __be32 |
57b7b43b | 3927 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, |
2db134eb AA |
3928 | struct nfsd4_exchange_id *exid) |
3929 | { | |
d0a381dd | 3930 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 3931 | __be32 *p; |
0733d213 AA |
3932 | char *major_id; |
3933 | char *server_scope; | |
3934 | int major_id_sz; | |
3935 | int server_scope_sz; | |
3936 | uint64_t minor_id = 0; | |
3937 | ||
0733d213 AA |
3938 | major_id = utsname()->nodename; |
3939 | major_id_sz = strlen(major_id); | |
3940 | server_scope = utsname()->nodename; | |
3941 | server_scope_sz = strlen(server_scope); | |
3942 | ||
d0a381dd | 3943 | p = xdr_reserve_space(xdr, |
0733d213 AA |
3944 | 8 /* eir_clientid */ + |
3945 | 4 /* eir_sequenceid */ + | |
3946 | 4 /* eir_flags */ + | |
a8bb84bc | 3947 | 4 /* spr_how */); |
d0a381dd BF |
3948 | if (!p) |
3949 | return nfserr_resource; | |
0733d213 | 3950 | |
0c0c267b | 3951 | p = xdr_encode_opaque_fixed(p, &exid->clientid, 8); |
c373b0a4 BF |
3952 | *p++ = cpu_to_be32(exid->seqid); |
3953 | *p++ = cpu_to_be32(exid->flags); | |
0733d213 | 3954 | |
c373b0a4 | 3955 | *p++ = cpu_to_be32(exid->spa_how); |
a8bb84bc | 3956 | |
57266a6e BF |
3957 | switch (exid->spa_how) { |
3958 | case SP4_NONE: | |
3959 | break; | |
3960 | case SP4_MACH_CRED: | |
3961 | /* spo_must_enforce bitmap: */ | |
bac966d6 | 3962 | nfserr = nfsd4_encode_bitmap(xdr, |
ed941643 AE |
3963 | exid->spo_must_enforce[0], |
3964 | exid->spo_must_enforce[1], | |
3965 | exid->spo_must_enforce[2]); | |
bac966d6 BF |
3966 | if (nfserr) |
3967 | return nfserr; | |
ed941643 | 3968 | /* spo_must_allow bitmap: */ |
bac966d6 | 3969 | nfserr = nfsd4_encode_bitmap(xdr, |
ed941643 AE |
3970 | exid->spo_must_allow[0], |
3971 | exid->spo_must_allow[1], | |
3972 | exid->spo_must_allow[2]); | |
bac966d6 BF |
3973 | if (nfserr) |
3974 | return nfserr; | |
57266a6e BF |
3975 | break; |
3976 | default: | |
3977 | WARN_ON_ONCE(1); | |
3978 | } | |
0733d213 | 3979 | |
d0a381dd | 3980 | p = xdr_reserve_space(xdr, |
a8bb84bc KM |
3981 | 8 /* so_minor_id */ + |
3982 | 4 /* so_major_id.len */ + | |
3983 | (XDR_QUADLEN(major_id_sz) * 4) + | |
3984 | 4 /* eir_server_scope.len */ + | |
3985 | (XDR_QUADLEN(server_scope_sz) * 4) + | |
3986 | 4 /* eir_server_impl_id.count (0) */); | |
d0a381dd BF |
3987 | if (!p) |
3988 | return nfserr_resource; | |
a8bb84bc | 3989 | |
0733d213 | 3990 | /* The server_owner struct */ |
b64c7f3b | 3991 | p = xdr_encode_hyper(p, minor_id); /* Minor id */ |
0733d213 | 3992 | /* major id */ |
0c0c267b | 3993 | p = xdr_encode_opaque(p, major_id, major_id_sz); |
0733d213 AA |
3994 | |
3995 | /* Server scope */ | |
0c0c267b | 3996 | p = xdr_encode_opaque(p, server_scope, server_scope_sz); |
0733d213 AA |
3997 | |
3998 | /* Implementation id */ | |
c373b0a4 | 3999 | *p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */ |
0733d213 | 4000 | return 0; |
2db134eb AA |
4001 | } |
4002 | ||
4003 | static __be32 | |
57b7b43b | 4004 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
2db134eb AA |
4005 | struct nfsd4_create_session *sess) |
4006 | { | |
d0a381dd | 4007 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 4008 | __be32 *p; |
ec6b5d7b | 4009 | |
d0a381dd BF |
4010 | p = xdr_reserve_space(xdr, 24); |
4011 | if (!p) | |
4012 | return nfserr_resource; | |
0c0c267b BF |
4013 | p = xdr_encode_opaque_fixed(p, sess->sessionid.data, |
4014 | NFS4_MAX_SESSIONID_LEN); | |
c373b0a4 BF |
4015 | *p++ = cpu_to_be32(sess->seqid); |
4016 | *p++ = cpu_to_be32(sess->flags); | |
ec6b5d7b | 4017 | |
d0a381dd BF |
4018 | p = xdr_reserve_space(xdr, 28); |
4019 | if (!p) | |
4020 | return nfserr_resource; | |
c373b0a4 BF |
4021 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
4022 | *p++ = cpu_to_be32(sess->fore_channel.maxreq_sz); | |
4023 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_sz); | |
4024 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_cached); | |
4025 | *p++ = cpu_to_be32(sess->fore_channel.maxops); | |
4026 | *p++ = cpu_to_be32(sess->fore_channel.maxreqs); | |
4027 | *p++ = cpu_to_be32(sess->fore_channel.nr_rdma_attrs); | |
ec6b5d7b AA |
4028 | |
4029 | if (sess->fore_channel.nr_rdma_attrs) { | |
d0a381dd BF |
4030 | p = xdr_reserve_space(xdr, 4); |
4031 | if (!p) | |
4032 | return nfserr_resource; | |
c373b0a4 | 4033 | *p++ = cpu_to_be32(sess->fore_channel.rdma_attrs); |
ec6b5d7b AA |
4034 | } |
4035 | ||
d0a381dd BF |
4036 | p = xdr_reserve_space(xdr, 28); |
4037 | if (!p) | |
4038 | return nfserr_resource; | |
c373b0a4 BF |
4039 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
4040 | *p++ = cpu_to_be32(sess->back_channel.maxreq_sz); | |
4041 | *p++ = cpu_to_be32(sess->back_channel.maxresp_sz); | |
4042 | *p++ = cpu_to_be32(sess->back_channel.maxresp_cached); | |
4043 | *p++ = cpu_to_be32(sess->back_channel.maxops); | |
4044 | *p++ = cpu_to_be32(sess->back_channel.maxreqs); | |
4045 | *p++ = cpu_to_be32(sess->back_channel.nr_rdma_attrs); | |
ec6b5d7b AA |
4046 | |
4047 | if (sess->back_channel.nr_rdma_attrs) { | |
d0a381dd BF |
4048 | p = xdr_reserve_space(xdr, 4); |
4049 | if (!p) | |
4050 | return nfserr_resource; | |
c373b0a4 | 4051 | *p++ = cpu_to_be32(sess->back_channel.rdma_attrs); |
ec6b5d7b AA |
4052 | } |
4053 | return 0; | |
2db134eb AA |
4054 | } |
4055 | ||
c47d832b | 4056 | static __be32 |
57b7b43b | 4057 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, |
2db134eb AA |
4058 | struct nfsd4_sequence *seq) |
4059 | { | |
d0a381dd | 4060 | struct xdr_stream *xdr = &resp->xdr; |
bc749ca4 | 4061 | __be32 *p; |
b85d4c01 | 4062 | |
d0a381dd BF |
4063 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20); |
4064 | if (!p) | |
4065 | return nfserr_resource; | |
0c0c267b BF |
4066 | p = xdr_encode_opaque_fixed(p, seq->sessionid.data, |
4067 | NFS4_MAX_SESSIONID_LEN); | |
c373b0a4 BF |
4068 | *p++ = cpu_to_be32(seq->seqid); |
4069 | *p++ = cpu_to_be32(seq->slotid); | |
b7d7ca35 | 4070 | /* Note slotid's are numbered from zero: */ |
c373b0a4 BF |
4071 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */ |
4072 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */ | |
4073 | *p++ = cpu_to_be32(seq->status_flags); | |
b85d4c01 | 4074 | |
f5236013 | 4075 | resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */ |
b85d4c01 | 4076 | return 0; |
2db134eb AA |
4077 | } |
4078 | ||
2355c596 | 4079 | static __be32 |
57b7b43b | 4080 | nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
17456804 BS |
4081 | struct nfsd4_test_stateid *test_stateid) |
4082 | { | |
d0a381dd | 4083 | struct xdr_stream *xdr = &resp->xdr; |
03cfb420 | 4084 | struct nfsd4_test_stateid_id *stateid, *next; |
17456804 | 4085 | __be32 *p; |
17456804 | 4086 | |
d0a381dd BF |
4087 | p = xdr_reserve_space(xdr, 4 + (4 * test_stateid->ts_num_ids)); |
4088 | if (!p) | |
4089 | return nfserr_resource; | |
17456804 | 4090 | *p++ = htonl(test_stateid->ts_num_ids); |
17456804 | 4091 | |
03cfb420 | 4092 | list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) { |
02f5fde5 | 4093 | *p++ = stateid->ts_id_status; |
17456804 | 4094 | } |
17456804 | 4095 | |
bac966d6 | 4096 | return 0; |
17456804 BS |
4097 | } |
4098 | ||
9cf514cc CH |
4099 | #ifdef CONFIG_NFSD_PNFS |
4100 | static __be32 | |
4101 | nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, | |
4102 | struct nfsd4_getdeviceinfo *gdev) | |
4103 | { | |
4104 | struct xdr_stream *xdr = &resp->xdr; | |
f961e3f2 | 4105 | const struct nfsd4_layout_ops *ops; |
9cf514cc CH |
4106 | u32 starting_len = xdr->buf->len, needed_len; |
4107 | __be32 *p; | |
4108 | ||
9cf514cc CH |
4109 | p = xdr_reserve_space(xdr, 4); |
4110 | if (!p) | |
bac966d6 | 4111 | return nfserr_resource; |
9cf514cc CH |
4112 | |
4113 | *p++ = cpu_to_be32(gdev->gd_layout_type); | |
4114 | ||
4115 | /* If maxcount is 0 then just update notifications */ | |
4116 | if (gdev->gd_maxcount != 0) { | |
f961e3f2 | 4117 | ops = nfsd4_layout_ops[gdev->gd_layout_type]; |
9cf514cc CH |
4118 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); |
4119 | if (nfserr) { | |
4120 | /* | |
4121 | * We don't bother to burden the layout drivers with | |
4122 | * enforcing gd_maxcount, just tell the client to | |
4123 | * come back with a bigger buffer if it's not enough. | |
4124 | */ | |
4125 | if (xdr->buf->len + 4 > gdev->gd_maxcount) | |
4126 | goto toosmall; | |
bac966d6 | 4127 | return nfserr; |
9cf514cc CH |
4128 | } |
4129 | } | |
4130 | ||
9cf514cc CH |
4131 | if (gdev->gd_notify_types) { |
4132 | p = xdr_reserve_space(xdr, 4 + 4); | |
4133 | if (!p) | |
bac966d6 | 4134 | return nfserr_resource; |
9cf514cc CH |
4135 | *p++ = cpu_to_be32(1); /* bitmap length */ |
4136 | *p++ = cpu_to_be32(gdev->gd_notify_types); | |
4137 | } else { | |
4138 | p = xdr_reserve_space(xdr, 4); | |
4139 | if (!p) | |
bac966d6 | 4140 | return nfserr_resource; |
9cf514cc CH |
4141 | *p++ = 0; |
4142 | } | |
4143 | ||
bac966d6 | 4144 | return 0; |
9cf514cc CH |
4145 | toosmall: |
4146 | dprintk("%s: maxcount too small\n", __func__); | |
4147 | needed_len = xdr->buf->len + 4 /* notifications */; | |
4148 | xdr_truncate_encode(xdr, starting_len); | |
4149 | p = xdr_reserve_space(xdr, 4); | |
bac966d6 BF |
4150 | if (!p) |
4151 | return nfserr_resource; | |
4152 | *p++ = cpu_to_be32(needed_len); | |
4153 | return nfserr_toosmall; | |
9cf514cc CH |
4154 | } |
4155 | ||
4156 | static __be32 | |
4157 | nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, | |
4158 | struct nfsd4_layoutget *lgp) | |
4159 | { | |
4160 | struct xdr_stream *xdr = &resp->xdr; | |
f961e3f2 | 4161 | const struct nfsd4_layout_ops *ops; |
9cf514cc CH |
4162 | __be32 *p; |
4163 | ||
9cf514cc CH |
4164 | p = xdr_reserve_space(xdr, 36 + sizeof(stateid_opaque_t)); |
4165 | if (!p) | |
bac966d6 | 4166 | return nfserr_resource; |
9cf514cc CH |
4167 | |
4168 | *p++ = cpu_to_be32(1); /* we always set return-on-close */ | |
4169 | *p++ = cpu_to_be32(lgp->lg_sid.si_generation); | |
4170 | p = xdr_encode_opaque_fixed(p, &lgp->lg_sid.si_opaque, | |
4171 | sizeof(stateid_opaque_t)); | |
4172 | ||
4173 | *p++ = cpu_to_be32(1); /* we always return a single layout */ | |
4174 | p = xdr_encode_hyper(p, lgp->lg_seg.offset); | |
4175 | p = xdr_encode_hyper(p, lgp->lg_seg.length); | |
4176 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); | |
4177 | *p++ = cpu_to_be32(lgp->lg_layout_type); | |
4178 | ||
f961e3f2 | 4179 | ops = nfsd4_layout_ops[lgp->lg_layout_type]; |
bac966d6 | 4180 | return ops->encode_layoutget(xdr, lgp); |
9cf514cc CH |
4181 | } |
4182 | ||
4183 | static __be32 | |
4184 | nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr, | |
4185 | struct nfsd4_layoutcommit *lcp) | |
4186 | { | |
4187 | struct xdr_stream *xdr = &resp->xdr; | |
4188 | __be32 *p; | |
4189 | ||
9cf514cc CH |
4190 | p = xdr_reserve_space(xdr, 4); |
4191 | if (!p) | |
4192 | return nfserr_resource; | |
4193 | *p++ = cpu_to_be32(lcp->lc_size_chg); | |
4194 | if (lcp->lc_size_chg) { | |
4195 | p = xdr_reserve_space(xdr, 8); | |
4196 | if (!p) | |
4197 | return nfserr_resource; | |
4198 | p = xdr_encode_hyper(p, lcp->lc_newsize); | |
4199 | } | |
4200 | ||
bac966d6 | 4201 | return 0; |
9cf514cc CH |
4202 | } |
4203 | ||
4204 | static __be32 | |
4205 | nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr, | |
4206 | struct nfsd4_layoutreturn *lrp) | |
4207 | { | |
4208 | struct xdr_stream *xdr = &resp->xdr; | |
4209 | __be32 *p; | |
4210 | ||
9cf514cc CH |
4211 | p = xdr_reserve_space(xdr, 4); |
4212 | if (!p) | |
4213 | return nfserr_resource; | |
4214 | *p++ = cpu_to_be32(lrp->lrs_present); | |
4215 | if (lrp->lrs_present) | |
376675da | 4216 | return nfsd4_encode_stateid(xdr, &lrp->lr_sid); |
bac966d6 | 4217 | return 0; |
9cf514cc CH |
4218 | } |
4219 | #endif /* CONFIG_NFSD_PNFS */ | |
4220 | ||
29ae7f9d | 4221 | static __be32 |
e0639dc5 OK |
4222 | nfsd42_encode_write_res(struct nfsd4_compoundres *resp, |
4223 | struct nfsd42_write_res *write, bool sync) | |
29ae7f9d AS |
4224 | { |
4225 | __be32 *p; | |
e0639dc5 OK |
4226 | p = xdr_reserve_space(&resp->xdr, 4); |
4227 | if (!p) | |
4228 | return nfserr_resource; | |
29ae7f9d | 4229 | |
e0639dc5 OK |
4230 | if (sync) |
4231 | *p++ = cpu_to_be32(0); | |
4232 | else { | |
4233 | __be32 nfserr; | |
4234 | *p++ = cpu_to_be32(1); | |
4235 | nfserr = nfsd4_encode_stateid(&resp->xdr, &write->cb_stateid); | |
4236 | if (nfserr) | |
4237 | return nfserr; | |
4238 | } | |
4239 | p = xdr_reserve_space(&resp->xdr, 8 + 4 + NFS4_VERIFIER_SIZE); | |
29ae7f9d AS |
4240 | if (!p) |
4241 | return nfserr_resource; | |
4242 | ||
29ae7f9d AS |
4243 | p = xdr_encode_hyper(p, write->wr_bytes_written); |
4244 | *p++ = cpu_to_be32(write->wr_stable_how); | |
4245 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, | |
4246 | NFS4_VERIFIER_SIZE); | |
4247 | return nfs_ok; | |
4248 | } | |
4249 | ||
4250 | static __be32 | |
4251 | nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr, | |
4252 | struct nfsd4_copy *copy) | |
4253 | { | |
4254 | __be32 *p; | |
4255 | ||
e0639dc5 OK |
4256 | nfserr = nfsd42_encode_write_res(resp, ©->cp_res, |
4257 | copy->cp_synchronous); | |
bac966d6 BF |
4258 | if (nfserr) |
4259 | return nfserr; | |
29ae7f9d | 4260 | |
bac966d6 | 4261 | p = xdr_reserve_space(&resp->xdr, 4 + 4); |
edcc8452 | 4262 | *p++ = xdr_one; /* cr_consecutive */ |
bac966d6 BF |
4263 | *p++ = cpu_to_be32(copy->cp_synchronous); |
4264 | return 0; | |
29ae7f9d AS |
4265 | } |
4266 | ||
6308bc98 OK |
4267 | static __be32 |
4268 | nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr, | |
4269 | struct nfsd4_offload_status *os) | |
4270 | { | |
4271 | struct xdr_stream *xdr = &resp->xdr; | |
4272 | __be32 *p; | |
4273 | ||
4274 | p = xdr_reserve_space(xdr, 8 + 4); | |
4275 | if (!p) | |
4276 | return nfserr_resource; | |
4277 | p = xdr_encode_hyper(p, os->count); | |
4278 | *p++ = cpu_to_be32(0); | |
4279 | ||
4280 | return nfserr; | |
4281 | } | |
4282 | ||
24bab491 AS |
4283 | static __be32 |
4284 | nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr, | |
4285 | struct nfsd4_seek *seek) | |
4286 | { | |
4287 | __be32 *p; | |
4288 | ||
24bab491 AS |
4289 | p = xdr_reserve_space(&resp->xdr, 4 + 8); |
4290 | *p++ = cpu_to_be32(seek->seek_eof); | |
4291 | p = xdr_encode_hyper(p, seek->seek_pos); | |
4292 | ||
bac966d6 | 4293 | return 0; |
24bab491 AS |
4294 | } |
4295 | ||
695e12f8 BH |
4296 | static __be32 |
4297 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) | |
4298 | { | |
4299 | return nfserr; | |
4300 | } | |
4301 | ||
4302 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); | |
4303 | ||
2db134eb AA |
4304 | /* |
4305 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 | |
4306 | * since we don't need to filter out obsolete ops as this is | |
4307 | * done in the decoding phase. | |
4308 | */ | |
c1df609d | 4309 | static const nfsd4_enc nfsd4_enc_ops[] = { |
ad1060c8 BF |
4310 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
4311 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, | |
4312 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, | |
4313 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, | |
4314 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, | |
4315 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, | |
4316 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, | |
4317 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, | |
4318 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, | |
4319 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, | |
4320 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, | |
4321 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, | |
4322 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, | |
4323 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, | |
4324 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, | |
4325 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, | |
84f09f46 | 4326 | [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop, |
ad1060c8 BF |
4327 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
4328 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, | |
4329 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, | |
4330 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, | |
4331 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, | |
4332 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, | |
4333 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, | |
4334 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, | |
4335 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, | |
4336 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, | |
4337 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, | |
4338 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, | |
4339 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, | |
4340 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, | |
4341 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, | |
4342 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, | |
4343 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, | |
4344 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, | |
4345 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, | |
4346 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, | |
2db134eb AA |
4347 | |
4348 | /* NFSv4.1 operations */ | |
4349 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, | |
1d1bc8f2 | 4350 | [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session, |
2db134eb AA |
4351 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, |
4352 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, | |
43212cc7 KM |
4353 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_noop, |
4354 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, | |
2db134eb | 4355 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
9cf514cc CH |
4356 | #ifdef CONFIG_NFSD_PNFS |
4357 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_getdeviceinfo, | |
4358 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, | |
4359 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_layoutcommit, | |
4360 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_layoutget, | |
4361 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_layoutreturn, | |
4362 | #else | |
2db134eb AA |
4363 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, |
4364 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, | |
4365 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, | |
4366 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, | |
4367 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, | |
9cf514cc | 4368 | #endif |
22b6dee8 | 4369 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name, |
2db134eb AA |
4370 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, |
4371 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, | |
17456804 | 4372 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid, |
2db134eb AA |
4373 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
4374 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, | |
4375 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, | |
87a15a80 AS |
4376 | |
4377 | /* NFSv4.2 operations */ | |
4378 | [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, | |
29ae7f9d | 4379 | [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy, |
87a15a80 AS |
4380 | [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_noop, |
4381 | [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, | |
4382 | [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop, | |
4383 | [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop, | |
4384 | [OP_LAYOUTSTATS] = (nfsd4_enc)nfsd4_encode_noop, | |
4385 | [OP_OFFLOAD_CANCEL] = (nfsd4_enc)nfsd4_encode_noop, | |
6308bc98 | 4386 | [OP_OFFLOAD_STATUS] = (nfsd4_enc)nfsd4_encode_offload_status, |
87a15a80 | 4387 | [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_noop, |
24bab491 | 4388 | [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, |
87a15a80 | 4389 | [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, |
ffa0160a | 4390 | [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, |
695e12f8 BH |
4391 | }; |
4392 | ||
496c262c | 4393 | /* |
a8095f7e BF |
4394 | * Calculate whether we still have space to encode repsize bytes. |
4395 | * There are two considerations: | |
4396 | * - For NFS versions >=4.1, the size of the reply must stay within | |
4397 | * session limits | |
4398 | * - For all NFS versions, we must stay within limited preallocated | |
4399 | * buffer space. | |
496c262c | 4400 | * |
a8095f7e BF |
4401 | * This is called before the operation is processed, so can only provide |
4402 | * an upper estimate. For some nonidempotent operations (such as | |
4403 | * getattr), it's not necessarily a problem if that estimate is wrong, | |
4404 | * as we can fail it after processing without significant side effects. | |
496c262c | 4405 | */ |
a8095f7e | 4406 | __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize) |
496c262c | 4407 | { |
67492c99 | 4408 | struct xdr_buf *buf = &resp->rqstp->rq_res; |
47ee5298 | 4409 | struct nfsd4_slot *slot = resp->cstate.slot; |
496c262c | 4410 | |
47ee5298 BF |
4411 | if (buf->len + respsize <= buf->buflen) |
4412 | return nfs_ok; | |
4413 | if (!nfsd4_has_session(&resp->cstate)) | |
ea8d7720 | 4414 | return nfserr_resource; |
47ee5298 BF |
4415 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) { |
4416 | WARN_ON_ONCE(1); | |
4417 | return nfserr_rep_too_big_to_cache; | |
ea8d7720 | 4418 | } |
47ee5298 | 4419 | return nfserr_rep_too_big; |
496c262c AA |
4420 | } |
4421 | ||
1da177e4 LT |
4422 | void |
4423 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) | |
4424 | { | |
082d4bd7 | 4425 | struct xdr_stream *xdr = &resp->xdr; |
9411b1d4 | 4426 | struct nfs4_stateowner *so = resp->cstate.replay_owner; |
5f4ab945 | 4427 | struct svc_rqst *rqstp = resp->rqstp; |
34b1744c | 4428 | const struct nfsd4_operation *opdesc = op->opdesc; |
082d4bd7 | 4429 | int post_err_offset; |
07d1f802 | 4430 | nfsd4_enc encoder; |
bc749ca4 | 4431 | __be32 *p; |
1da177e4 | 4432 | |
d0a381dd BF |
4433 | p = xdr_reserve_space(xdr, 8); |
4434 | if (!p) { | |
4435 | WARN_ON_ONCE(1); | |
4436 | return; | |
4437 | } | |
c373b0a4 | 4438 | *p++ = cpu_to_be32(op->opnum); |
082d4bd7 | 4439 | post_err_offset = xdr->buf->len; |
1da177e4 | 4440 | |
695e12f8 BH |
4441 | if (op->opnum == OP_ILLEGAL) |
4442 | goto status; | |
b7571e4c BF |
4443 | if (op->status && opdesc && |
4444 | !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE)) | |
4445 | goto status; | |
695e12f8 BH |
4446 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
4447 | !nfsd4_enc_ops[op->opnum]); | |
07d1f802 BF |
4448 | encoder = nfsd4_enc_ops[op->opnum]; |
4449 | op->status = encoder(resp, op->status, &op->u); | |
34b1744c BF |
4450 | if (opdesc && opdesc->op_release) |
4451 | opdesc->op_release(&op->u); | |
2825a7f9 BF |
4452 | xdr_commit_encode(xdr); |
4453 | ||
067e1ace | 4454 | /* nfsd4_check_resp_size guarantees enough room for error status */ |
5f4ab945 BF |
4455 | if (!op->status) { |
4456 | int space_needed = 0; | |
4457 | if (!nfsd4_last_compound_op(rqstp)) | |
4458 | space_needed = COMPOUND_ERR_SLACK_SPACE; | |
4459 | op->status = nfsd4_check_resp_size(resp, space_needed); | |
4460 | } | |
c8f13d97 BF |
4461 | if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) { |
4462 | struct nfsd4_slot *slot = resp->cstate.slot; | |
4463 | ||
4464 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) | |
4465 | op->status = nfserr_rep_too_big_to_cache; | |
4466 | else | |
4467 | op->status = nfserr_rep_too_big; | |
4468 | } | |
07d1f802 BF |
4469 | if (op->status == nfserr_resource || |
4470 | op->status == nfserr_rep_too_big || | |
4471 | op->status == nfserr_rep_too_big_to_cache) { | |
4472 | /* | |
4473 | * The operation may have already been encoded or | |
4474 | * partially encoded. No op returns anything additional | |
4475 | * in the case of one of these three errors, so we can | |
4476 | * just truncate back to after the status. But it's a | |
4477 | * bug if we had to do this on a non-idempotent op: | |
4478 | */ | |
4479 | warn_on_nonidempotent_op(op); | |
082d4bd7 | 4480 | xdr_truncate_encode(xdr, post_err_offset); |
07d1f802 | 4481 | } |
9411b1d4 | 4482 | if (so) { |
082d4bd7 BF |
4483 | int len = xdr->buf->len - post_err_offset; |
4484 | ||
9411b1d4 | 4485 | so->so_replay.rp_status = op->status; |
082d4bd7 BF |
4486 | so->so_replay.rp_buflen = len; |
4487 | read_bytes_from_xdr_buf(xdr->buf, post_err_offset, | |
4488 | so->so_replay.rp_buf, len); | |
9411b1d4 | 4489 | } |
695e12f8 | 4490 | status: |
082d4bd7 BF |
4491 | /* Note that op->status is already in network byte order: */ |
4492 | write_bytes_to_xdr_buf(xdr->buf, post_err_offset - 4, &op->status, 4); | |
1da177e4 LT |
4493 | } |
4494 | ||
4495 | /* | |
4496 | * Encode the reply stored in the stateowner reply cache | |
4497 | * | |
4498 | * XDR note: do not encode rp->rp_buflen: the buffer contains the | |
4499 | * previously sent already encoded operation. | |
1da177e4 LT |
4500 | */ |
4501 | void | |
d0a381dd | 4502 | nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op) |
1da177e4 | 4503 | { |
bc749ca4 | 4504 | __be32 *p; |
1da177e4 LT |
4505 | struct nfs4_replay *rp = op->replay; |
4506 | ||
4507 | BUG_ON(!rp); | |
4508 | ||
d0a381dd BF |
4509 | p = xdr_reserve_space(xdr, 8 + rp->rp_buflen); |
4510 | if (!p) { | |
4511 | WARN_ON_ONCE(1); | |
4512 | return; | |
4513 | } | |
c373b0a4 | 4514 | *p++ = cpu_to_be32(op->opnum); |
1da177e4 | 4515 | *p++ = rp->rp_status; /* already xdr'ed */ |
1da177e4 | 4516 | |
0c0c267b | 4517 | p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen); |
1da177e4 LT |
4518 | } |
4519 | ||
1da177e4 | 4520 | int |
63f8de37 | 4521 | nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p) |
1da177e4 LT |
4522 | { |
4523 | return xdr_ressize_check(rqstp, p); | |
4524 | } | |
4525 | ||
8537488b | 4526 | void nfsd4_release_compoundargs(struct svc_rqst *rqstp) |
1da177e4 | 4527 | { |
3e98abff BF |
4528 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
4529 | ||
1da177e4 LT |
4530 | if (args->ops != args->iops) { |
4531 | kfree(args->ops); | |
4532 | args->ops = args->iops; | |
4533 | } | |
f99d49ad JJ |
4534 | kfree(args->tmpp); |
4535 | args->tmpp = NULL; | |
1da177e4 | 4536 | while (args->to_free) { |
d5e23383 | 4537 | struct svcxdr_tmpbuf *tb = args->to_free; |
1da177e4 | 4538 | args->to_free = tb->next; |
1da177e4 LT |
4539 | kfree(tb); |
4540 | } | |
4541 | } | |
4542 | ||
4543 | int | |
026fec7e | 4544 | nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p) |
1da177e4 | 4545 | { |
026fec7e CH |
4546 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
4547 | ||
e874f9f8 JL |
4548 | if (rqstp->rq_arg.head[0].iov_len % 4) { |
4549 | /* client is nuts */ | |
4550 | dprintk("%s: compound not properly padded! (peeraddr=%pISc xid=0x%x)", | |
4551 | __func__, svc_addr(rqstp), be32_to_cpu(rqstp->rq_xid)); | |
4552 | return 0; | |
4553 | } | |
1da177e4 LT |
4554 | args->p = p; |
4555 | args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len; | |
4556 | args->pagelist = rqstp->rq_arg.pages; | |
4557 | args->pagelen = rqstp->rq_arg.page_len; | |
eae03e2a | 4558 | args->tail = false; |
1da177e4 LT |
4559 | args->tmpp = NULL; |
4560 | args->to_free = NULL; | |
4561 | args->ops = args->iops; | |
4562 | args->rqstp = rqstp; | |
4563 | ||
3e98abff | 4564 | return !nfsd4_decode_compound(args); |
1da177e4 LT |
4565 | } |
4566 | ||
4567 | int | |
63f8de37 | 4568 | nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p) |
1da177e4 LT |
4569 | { |
4570 | /* | |
4571 | * All that remains is to write the tag and operation count... | |
4572 | */ | |
63f8de37 | 4573 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
6ac90391 BF |
4574 | struct xdr_buf *buf = resp->xdr.buf; |
4575 | ||
4576 | WARN_ON_ONCE(buf->len != buf->head[0].iov_len + buf->page_len + | |
4577 | buf->tail[0].iov_len); | |
dd97fdde | 4578 | |
2825a7f9 BF |
4579 | rqstp->rq_next_page = resp->xdr.page_ptr + 1; |
4580 | ||
1da177e4 LT |
4581 | p = resp->tagp; |
4582 | *p++ = htonl(resp->taglen); | |
4583 | memcpy(p, resp->tag, resp->taglen); | |
4584 | p += XDR_QUADLEN(resp->taglen); | |
4585 | *p++ = htonl(resp->opcnt); | |
4586 | ||
b607664e | 4587 | nfsd4_sequence_done(resp); |
1da177e4 LT |
4588 | return 1; |
4589 | } | |
4590 | ||
4591 | /* | |
4592 | * Local variables: | |
4593 | * c-basic-offset: 8 | |
4594 | * End: | |
4595 | */ |