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