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