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