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