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