GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / fs / nfs / callback_xdr.c
blob05af212f0edfb1558e238bb0ce95a5ef7688987f
1 /*
2 * linux/fs/nfs/callback_xdr.c
4 * Copyright (C) 2004 Trond Myklebust
6 * NFSv4 callback encode/decode procedures
7 */
8 #include <linux/kernel.h>
9 #include <linux/sunrpc/svc.h>
10 #include <linux/nfs4.h>
11 #include <linux/nfs_fs.h>
12 #include <linux/slab.h>
13 #include "nfs4_fs.h"
14 #include "callback.h"
16 #define CB_OP_TAGLEN_MAXSZ (512)
17 #define CB_OP_HDR_RES_MAXSZ (2 + CB_OP_TAGLEN_MAXSZ)
18 #define CB_OP_GETATTR_BITMAP_MAXSZ (4)
19 #define CB_OP_GETATTR_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \
20 CB_OP_GETATTR_BITMAP_MAXSZ + \
21 2 + 2 + 3 + 3)
22 #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
24 #if defined(CONFIG_NFS_V4_1)
25 #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \
26 4 + 1 + 3)
27 #define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
28 #define CB_OP_RECALLSLOT_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
29 #endif /* CONFIG_NFS_V4_1 */
31 #define NFSDBG_FACILITY NFSDBG_CALLBACK
33 /* Internal error code */
34 #define NFS4ERR_RESOURCE_HDR 11050
36 typedef __be32 (*callback_process_op_t)(void *, void *);
37 typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *);
38 typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *);
41 struct callback_op {
42 callback_process_op_t process_op;
43 callback_decode_arg_t decode_args;
44 callback_encode_res_t encode_res;
45 long res_maxsize;
48 static struct callback_op callback_ops[];
50 static __be32 nfs4_callback_null(struct svc_rqst *rqstp, void *argp, void *resp)
52 return htonl(NFS4_OK);
55 static int nfs4_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
57 return xdr_argsize_check(rqstp, p);
60 static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
62 return xdr_ressize_check(rqstp, p);
65 static __be32 *read_buf(struct xdr_stream *xdr, int nbytes)
67 __be32 *p;
69 p = xdr_inline_decode(xdr, nbytes);
70 if (unlikely(p == NULL))
71 printk(KERN_WARNING "NFSv4 callback reply buffer overflowed!\n");
72 return p;
75 static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, const char **str)
77 __be32 *p;
79 p = read_buf(xdr, 4);
80 if (unlikely(p == NULL))
81 return htonl(NFS4ERR_RESOURCE);
82 *len = ntohl(*p);
84 if (*len != 0) {
85 p = read_buf(xdr, *len);
86 if (unlikely(p == NULL))
87 return htonl(NFS4ERR_RESOURCE);
88 *str = (const char *)p;
89 } else
90 *str = NULL;
92 return 0;
95 static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
97 __be32 *p;
99 p = read_buf(xdr, 4);
100 if (unlikely(p == NULL))
101 return htonl(NFS4ERR_RESOURCE);
102 fh->size = ntohl(*p);
103 if (fh->size > NFS4_FHSIZE)
104 return htonl(NFS4ERR_BADHANDLE);
105 p = read_buf(xdr, fh->size);
106 if (unlikely(p == NULL))
107 return htonl(NFS4ERR_RESOURCE);
108 memcpy(&fh->data[0], p, fh->size);
109 memset(&fh->data[fh->size], 0, sizeof(fh->data) - fh->size);
110 return 0;
113 static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
115 __be32 *p;
116 unsigned int attrlen;
118 p = read_buf(xdr, 4);
119 if (unlikely(p == NULL))
120 return htonl(NFS4ERR_RESOURCE);
121 attrlen = ntohl(*p);
122 p = read_buf(xdr, attrlen << 2);
123 if (unlikely(p == NULL))
124 return htonl(NFS4ERR_RESOURCE);
125 if (likely(attrlen > 0))
126 bitmap[0] = ntohl(*p++);
127 if (attrlen > 1)
128 bitmap[1] = ntohl(*p);
129 return 0;
132 static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
134 __be32 *p;
136 p = read_buf(xdr, 16);
137 if (unlikely(p == NULL))
138 return htonl(NFS4ERR_RESOURCE);
139 memcpy(stateid->data, p, 16);
140 return 0;
143 static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
145 __be32 *p;
146 __be32 status;
148 status = decode_string(xdr, &hdr->taglen, &hdr->tag);
149 if (unlikely(status != 0))
150 return status;
151 /* We do not like overly long tags! */
152 if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
153 printk("NFSv4 CALLBACK %s: client sent tag of length %u\n",
154 __func__, hdr->taglen);
155 return htonl(NFS4ERR_RESOURCE);
157 p = read_buf(xdr, 12);
158 if (unlikely(p == NULL))
159 return htonl(NFS4ERR_RESOURCE);
160 hdr->minorversion = ntohl(*p++);
161 /* Check minor version is zero or one. */
162 if (hdr->minorversion <= 1) {
163 p++; /* skip callback_ident */
164 } else {
165 printk(KERN_WARNING "%s: NFSv4 server callback with "
166 "illegal minor version %u!\n",
167 __func__, hdr->minorversion);
168 return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
170 hdr->nops = ntohl(*p);
171 dprintk("%s: minorversion %d nops %d\n", __func__,
172 hdr->minorversion, hdr->nops);
173 return 0;
176 static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op)
178 __be32 *p;
179 p = read_buf(xdr, 4);
180 if (unlikely(p == NULL))
181 return htonl(NFS4ERR_RESOURCE_HDR);
182 *op = ntohl(*p);
183 return 0;
186 static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args)
188 __be32 status;
190 status = decode_fh(xdr, &args->fh);
191 if (unlikely(status != 0))
192 goto out;
193 args->addr = svc_addr(rqstp);
194 status = decode_bitmap(xdr, args->bitmap);
195 out:
196 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
197 return status;
200 static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallargs *args)
202 __be32 *p;
203 __be32 status;
205 args->addr = svc_addr(rqstp);
206 status = decode_stateid(xdr, &args->stateid);
207 if (unlikely(status != 0))
208 goto out;
209 p = read_buf(xdr, 4);
210 if (unlikely(p == NULL)) {
211 status = htonl(NFS4ERR_RESOURCE);
212 goto out;
214 args->truncate = ntohl(*p);
215 status = decode_fh(xdr, &args->fh);
216 out:
217 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
218 return status;
221 #if defined(CONFIG_NFS_V4_1)
223 static __be32 decode_sessionid(struct xdr_stream *xdr,
224 struct nfs4_sessionid *sid)
226 __be32 *p;
227 int len = NFS4_MAX_SESSIONID_LEN;
229 p = read_buf(xdr, len);
230 if (unlikely(p == NULL))
231 return htonl(NFS4ERR_RESOURCE);
233 memcpy(sid->data, p, len);
234 return 0;
237 static __be32 decode_rc_list(struct xdr_stream *xdr,
238 struct referring_call_list *rc_list)
240 __be32 *p;
241 int i;
242 __be32 status;
244 status = decode_sessionid(xdr, &rc_list->rcl_sessionid);
245 if (status)
246 goto out;
248 status = htonl(NFS4ERR_RESOURCE);
249 p = read_buf(xdr, sizeof(uint32_t));
250 if (unlikely(p == NULL))
251 goto out;
253 rc_list->rcl_nrefcalls = ntohl(*p++);
254 if (rc_list->rcl_nrefcalls) {
255 p = read_buf(xdr,
256 rc_list->rcl_nrefcalls * 2 * sizeof(uint32_t));
257 if (unlikely(p == NULL))
258 goto out;
259 rc_list->rcl_refcalls = kmalloc(rc_list->rcl_nrefcalls *
260 sizeof(*rc_list->rcl_refcalls),
261 GFP_KERNEL);
262 if (unlikely(rc_list->rcl_refcalls == NULL))
263 goto out;
264 for (i = 0; i < rc_list->rcl_nrefcalls; i++) {
265 rc_list->rcl_refcalls[i].rc_sequenceid = ntohl(*p++);
266 rc_list->rcl_refcalls[i].rc_slotid = ntohl(*p++);
269 status = 0;
271 out:
272 return status;
275 static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp,
276 struct xdr_stream *xdr,
277 struct cb_sequenceargs *args)
279 __be32 *p;
280 int i;
281 __be32 status;
283 status = decode_sessionid(xdr, &args->csa_sessionid);
284 if (status)
285 goto out;
287 status = htonl(NFS4ERR_RESOURCE);
288 p = read_buf(xdr, 5 * sizeof(uint32_t));
289 if (unlikely(p == NULL))
290 goto out;
292 args->csa_addr = svc_addr(rqstp);
293 args->csa_sequenceid = ntohl(*p++);
294 args->csa_slotid = ntohl(*p++);
295 args->csa_highestslotid = ntohl(*p++);
296 args->csa_cachethis = ntohl(*p++);
297 args->csa_nrclists = ntohl(*p++);
298 args->csa_rclists = NULL;
299 if (args->csa_nrclists) {
300 args->csa_rclists = kmalloc(args->csa_nrclists *
301 sizeof(*args->csa_rclists),
302 GFP_KERNEL);
303 if (unlikely(args->csa_rclists == NULL))
304 goto out;
306 for (i = 0; i < args->csa_nrclists; i++) {
307 status = decode_rc_list(xdr, &args->csa_rclists[i]);
308 if (status)
309 goto out_free;
312 status = 0;
314 dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u slotid %u "
315 "highestslotid %u cachethis %d nrclists %u\n",
316 __func__,
317 ((u32 *)&args->csa_sessionid)[0],
318 ((u32 *)&args->csa_sessionid)[1],
319 ((u32 *)&args->csa_sessionid)[2],
320 ((u32 *)&args->csa_sessionid)[3],
321 args->csa_sequenceid, args->csa_slotid,
322 args->csa_highestslotid, args->csa_cachethis,
323 args->csa_nrclists);
324 out:
325 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
326 return status;
328 out_free:
329 for (i = 0; i < args->csa_nrclists; i++)
330 kfree(args->csa_rclists[i].rcl_refcalls);
331 kfree(args->csa_rclists);
332 goto out;
335 static __be32 decode_recallany_args(struct svc_rqst *rqstp,
336 struct xdr_stream *xdr,
337 struct cb_recallanyargs *args)
339 __be32 *p;
341 args->craa_addr = svc_addr(rqstp);
342 p = read_buf(xdr, 4);
343 if (unlikely(p == NULL))
344 return htonl(NFS4ERR_BADXDR);
345 args->craa_objs_to_keep = ntohl(*p++);
346 p = read_buf(xdr, 4);
347 if (unlikely(p == NULL))
348 return htonl(NFS4ERR_BADXDR);
349 args->craa_type_mask = ntohl(*p);
351 return 0;
354 static __be32 decode_recallslot_args(struct svc_rqst *rqstp,
355 struct xdr_stream *xdr,
356 struct cb_recallslotargs *args)
358 __be32 *p;
360 args->crsa_addr = svc_addr(rqstp);
361 p = read_buf(xdr, 4);
362 if (unlikely(p == NULL))
363 return htonl(NFS4ERR_BADXDR);
364 args->crsa_target_max_slots = ntohl(*p++);
365 return 0;
368 #endif /* CONFIG_NFS_V4_1 */
370 static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
372 __be32 *p;
374 p = xdr_reserve_space(xdr, 4 + len);
375 if (unlikely(p == NULL))
376 return htonl(NFS4ERR_RESOURCE);
377 xdr_encode_opaque(p, str, len);
378 return 0;
381 #define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE)
382 #define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY)
383 static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep)
385 __be32 bm[2];
386 __be32 *p;
388 bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0);
389 bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1);
390 if (bm[1] != 0) {
391 p = xdr_reserve_space(xdr, 16);
392 if (unlikely(p == NULL))
393 return htonl(NFS4ERR_RESOURCE);
394 *p++ = htonl(2);
395 *p++ = bm[0];
396 *p++ = bm[1];
397 } else if (bm[0] != 0) {
398 p = xdr_reserve_space(xdr, 12);
399 if (unlikely(p == NULL))
400 return htonl(NFS4ERR_RESOURCE);
401 *p++ = htonl(1);
402 *p++ = bm[0];
403 } else {
404 p = xdr_reserve_space(xdr, 8);
405 if (unlikely(p == NULL))
406 return htonl(NFS4ERR_RESOURCE);
407 *p++ = htonl(0);
409 *savep = p;
410 return 0;
413 static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change)
415 __be32 *p;
417 if (!(bitmap[0] & FATTR4_WORD0_CHANGE))
418 return 0;
419 p = xdr_reserve_space(xdr, 8);
420 if (unlikely(!p))
421 return htonl(NFS4ERR_RESOURCE);
422 p = xdr_encode_hyper(p, change);
423 return 0;
426 static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size)
428 __be32 *p;
430 if (!(bitmap[0] & FATTR4_WORD0_SIZE))
431 return 0;
432 p = xdr_reserve_space(xdr, 8);
433 if (unlikely(!p))
434 return htonl(NFS4ERR_RESOURCE);
435 p = xdr_encode_hyper(p, size);
436 return 0;
439 static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec *time)
441 __be32 *p;
443 p = xdr_reserve_space(xdr, 12);
444 if (unlikely(!p))
445 return htonl(NFS4ERR_RESOURCE);
446 p = xdr_encode_hyper(p, time->tv_sec);
447 *p = htonl(time->tv_nsec);
448 return 0;
451 static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
453 if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA))
454 return 0;
455 return encode_attr_time(xdr,time);
458 static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
460 if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY))
461 return 0;
462 return encode_attr_time(xdr,time);
465 static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr)
467 __be32 status;
469 hdr->status = xdr_reserve_space(xdr, 4);
470 if (unlikely(hdr->status == NULL))
471 return htonl(NFS4ERR_RESOURCE);
472 status = encode_string(xdr, hdr->taglen, hdr->tag);
473 if (unlikely(status != 0))
474 return status;
475 hdr->nops = xdr_reserve_space(xdr, 4);
476 if (unlikely(hdr->nops == NULL))
477 return htonl(NFS4ERR_RESOURCE);
478 return 0;
481 static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res)
483 __be32 *p;
485 p = xdr_reserve_space(xdr, 8);
486 if (unlikely(p == NULL))
487 return htonl(NFS4ERR_RESOURCE_HDR);
488 *p++ = htonl(op);
489 *p = res;
490 return 0;
493 static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_getattrres *res)
495 __be32 *savep = NULL;
496 __be32 status = res->status;
498 if (unlikely(status != 0))
499 goto out;
500 status = encode_attr_bitmap(xdr, res->bitmap, &savep);
501 if (unlikely(status != 0))
502 goto out;
503 status = encode_attr_change(xdr, res->bitmap, res->change_attr);
504 if (unlikely(status != 0))
505 goto out;
506 status = encode_attr_size(xdr, res->bitmap, res->size);
507 if (unlikely(status != 0))
508 goto out;
509 status = encode_attr_ctime(xdr, res->bitmap, &res->ctime);
510 if (unlikely(status != 0))
511 goto out;
512 status = encode_attr_mtime(xdr, res->bitmap, &res->mtime);
513 *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1)));
514 out:
515 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
516 return status;
519 #if defined(CONFIG_NFS_V4_1)
521 static __be32 encode_sessionid(struct xdr_stream *xdr,
522 const struct nfs4_sessionid *sid)
524 __be32 *p;
525 int len = NFS4_MAX_SESSIONID_LEN;
527 p = xdr_reserve_space(xdr, len);
528 if (unlikely(p == NULL))
529 return htonl(NFS4ERR_RESOURCE);
531 memcpy(p, sid, len);
532 return 0;
535 static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp,
536 struct xdr_stream *xdr,
537 const struct cb_sequenceres *res)
539 __be32 *p;
540 unsigned status = res->csr_status;
542 if (unlikely(status != 0))
543 goto out;
545 encode_sessionid(xdr, &res->csr_sessionid);
547 p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t));
548 if (unlikely(p == NULL))
549 return htonl(NFS4ERR_RESOURCE);
551 *p++ = htonl(res->csr_sequenceid);
552 *p++ = htonl(res->csr_slotid);
553 *p++ = htonl(res->csr_highestslotid);
554 *p++ = htonl(res->csr_target_highestslotid);
555 out:
556 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
557 return status;
560 static __be32
561 preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
563 if (op_nr == OP_CB_SEQUENCE) {
564 if (nop != 0)
565 return htonl(NFS4ERR_SEQUENCE_POS);
566 } else {
567 if (nop == 0)
568 return htonl(NFS4ERR_OP_NOT_IN_SESSION);
571 switch (op_nr) {
572 case OP_CB_GETATTR:
573 case OP_CB_RECALL:
574 case OP_CB_SEQUENCE:
575 case OP_CB_RECALL_ANY:
576 case OP_CB_RECALL_SLOT:
577 *op = &callback_ops[op_nr];
578 break;
580 case OP_CB_LAYOUTRECALL:
581 case OP_CB_NOTIFY_DEVICEID:
582 case OP_CB_NOTIFY:
583 case OP_CB_PUSH_DELEG:
584 case OP_CB_RECALLABLE_OBJ_AVAIL:
585 case OP_CB_WANTS_CANCELLED:
586 case OP_CB_NOTIFY_LOCK:
587 return htonl(NFS4ERR_NOTSUPP);
589 default:
590 return htonl(NFS4ERR_OP_ILLEGAL);
593 return htonl(NFS_OK);
596 #else /* CONFIG_NFS_V4_1 */
598 static __be32
599 preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
601 return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
604 #endif /* CONFIG_NFS_V4_1 */
606 static __be32
607 preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op)
609 switch (op_nr) {
610 case OP_CB_GETATTR:
611 case OP_CB_RECALL:
612 *op = &callback_ops[op_nr];
613 break;
614 default:
615 return htonl(NFS4ERR_OP_ILLEGAL);
618 return htonl(NFS_OK);
621 static __be32 process_op(uint32_t minorversion, int nop,
622 struct svc_rqst *rqstp,
623 struct xdr_stream *xdr_in, void *argp,
624 struct xdr_stream *xdr_out, void *resp, int* drc_status)
626 struct callback_op *op = &callback_ops[0];
627 unsigned int op_nr;
628 __be32 status;
629 long maxlen;
630 __be32 res;
632 dprintk("%s: start\n", __func__);
633 status = decode_op_hdr(xdr_in, &op_nr);
634 if (unlikely(status))
635 return status;
637 dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
638 __func__, minorversion, nop, op_nr);
640 status = minorversion ? preprocess_nfs41_op(nop, op_nr, &op) :
641 preprocess_nfs4_op(op_nr, &op);
642 if (status == htonl(NFS4ERR_OP_ILLEGAL))
643 op_nr = OP_CB_ILLEGAL;
644 if (status)
645 goto encode_hdr;
647 if (*drc_status) {
648 status = *drc_status;
649 goto encode_hdr;
652 maxlen = xdr_out->end - xdr_out->p;
653 if (maxlen > 0 && maxlen < PAGE_SIZE) {
654 status = op->decode_args(rqstp, xdr_in, argp);
655 if (likely(status == 0))
656 status = op->process_op(argp, resp);
657 } else
658 status = htonl(NFS4ERR_RESOURCE);
660 /* Only set by OP_CB_SEQUENCE processing */
661 if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) {
662 *drc_status = status;
663 status = 0;
666 encode_hdr:
667 res = encode_op_hdr(xdr_out, op_nr, status);
668 if (unlikely(res))
669 return res;
670 if (op->encode_res != NULL && status == 0)
671 status = op->encode_res(rqstp, xdr_out, resp);
672 dprintk("%s: done, status = %d\n", __func__, ntohl(status));
673 return status;
677 * Decode, process and encode a COMPOUND
679 static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *resp)
681 struct cb_compound_hdr_arg hdr_arg = { 0 };
682 struct cb_compound_hdr_res hdr_res = { NULL };
683 struct xdr_stream xdr_in, xdr_out;
684 __be32 *p;
685 __be32 status, drc_status = 0;
686 unsigned int nops = 0;
688 dprintk("%s: start\n", __func__);
690 xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base);
692 p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len);
693 xdr_init_encode(&xdr_out, &rqstp->rq_res, p);
695 status = decode_compound_hdr_arg(&xdr_in, &hdr_arg);
696 if (status == __constant_htonl(NFS4ERR_RESOURCE))
697 return rpc_garbage_args;
699 hdr_res.taglen = hdr_arg.taglen;
700 hdr_res.tag = hdr_arg.tag;
701 if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0)
702 return rpc_system_err;
704 while (status == 0 && nops != hdr_arg.nops) {
705 status = process_op(hdr_arg.minorversion, nops, rqstp,
706 &xdr_in, argp, &xdr_out, resp, &drc_status);
707 nops++;
710 /* Buffer overflow in decode_ops_hdr or encode_ops_hdr. Return
711 * resource error in cb_compound status without returning op */
712 if (unlikely(status == htonl(NFS4ERR_RESOURCE_HDR))) {
713 status = htonl(NFS4ERR_RESOURCE);
714 nops--;
717 *hdr_res.status = status;
718 *hdr_res.nops = htonl(nops);
719 dprintk("%s: done, status = %u\n", __func__, ntohl(status));
720 return rpc_success;
724 * Define NFS4 callback COMPOUND ops.
726 static struct callback_op callback_ops[] = {
727 [0] = {
728 .res_maxsize = CB_OP_HDR_RES_MAXSZ,
730 [OP_CB_GETATTR] = {
731 .process_op = (callback_process_op_t)nfs4_callback_getattr,
732 .decode_args = (callback_decode_arg_t)decode_getattr_args,
733 .encode_res = (callback_encode_res_t)encode_getattr_res,
734 .res_maxsize = CB_OP_GETATTR_RES_MAXSZ,
736 [OP_CB_RECALL] = {
737 .process_op = (callback_process_op_t)nfs4_callback_recall,
738 .decode_args = (callback_decode_arg_t)decode_recall_args,
739 .res_maxsize = CB_OP_RECALL_RES_MAXSZ,
741 #if defined(CONFIG_NFS_V4_1)
742 [OP_CB_SEQUENCE] = {
743 .process_op = (callback_process_op_t)nfs4_callback_sequence,
744 .decode_args = (callback_decode_arg_t)decode_cb_sequence_args,
745 .encode_res = (callback_encode_res_t)encode_cb_sequence_res,
746 .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ,
748 [OP_CB_RECALL_ANY] = {
749 .process_op = (callback_process_op_t)nfs4_callback_recallany,
750 .decode_args = (callback_decode_arg_t)decode_recallany_args,
751 .res_maxsize = CB_OP_RECALLANY_RES_MAXSZ,
753 [OP_CB_RECALL_SLOT] = {
754 .process_op = (callback_process_op_t)nfs4_callback_recallslot,
755 .decode_args = (callback_decode_arg_t)decode_recallslot_args,
756 .res_maxsize = CB_OP_RECALLSLOT_RES_MAXSZ,
758 #endif /* CONFIG_NFS_V4_1 */
762 * Define NFS4 callback procedures
764 static struct svc_procedure nfs4_callback_procedures1[] = {
765 [CB_NULL] = {
766 .pc_func = nfs4_callback_null,
767 .pc_decode = (kxdrproc_t)nfs4_decode_void,
768 .pc_encode = (kxdrproc_t)nfs4_encode_void,
769 .pc_xdrressize = 1,
771 [CB_COMPOUND] = {
772 .pc_func = nfs4_callback_compound,
773 .pc_encode = (kxdrproc_t)nfs4_encode_void,
774 .pc_argsize = 256,
775 .pc_ressize = 256,
776 .pc_xdrressize = NFS4_CALLBACK_BUFSIZE,
780 struct svc_version nfs4_callback_version1 = {
781 .vs_vers = 1,
782 .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1),
783 .vs_proc = nfs4_callback_procedures1,
784 .vs_xdrsize = NFS4_CALLBACK_XDRSIZE,
785 .vs_dispatch = NULL,
786 .vs_hidden = 1,
789 struct svc_version nfs4_callback_version4 = {
790 .vs_vers = 4,
791 .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1),
792 .vs_proc = nfs4_callback_procedures1,
793 .vs_xdrsize = NFS4_CALLBACK_XDRSIZE,
794 .vs_dispatch = NULL,