Merge branch 'for-2.6.31' of git://fieldses.org/git/linux-nfsd
[linux-2.6] / fs / nfs / callback_xdr.c
1 /*
2  * linux/fs/nfs/callback_xdr.c
3  *
4  * Copyright (C) 2004 Trond Myklebust
5  *
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 "nfs4_fs.h"
13 #include "callback.h"
14
15 #define CB_OP_TAGLEN_MAXSZ      (512)
16 #define CB_OP_HDR_RES_MAXSZ     (2 + CB_OP_TAGLEN_MAXSZ)
17 #define CB_OP_GETATTR_BITMAP_MAXSZ      (4)
18 #define CB_OP_GETATTR_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \
19                                 CB_OP_GETATTR_BITMAP_MAXSZ + \
20                                 2 + 2 + 3 + 3)
21 #define CB_OP_RECALL_RES_MAXSZ  (CB_OP_HDR_RES_MAXSZ)
22
23 #if defined(CONFIG_NFS_V4_1)
24 #define CB_OP_SEQUENCE_RES_MAXSZ        (CB_OP_HDR_RES_MAXSZ + \
25                                         4 + 1 + 3)
26 #endif /* CONFIG_NFS_V4_1 */
27
28 #define NFSDBG_FACILITY NFSDBG_CALLBACK
29
30 typedef __be32 (*callback_process_op_t)(void *, void *);
31 typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *);
32 typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *);
33
34
35 struct callback_op {
36         callback_process_op_t process_op;
37         callback_decode_arg_t decode_args;
38         callback_encode_res_t encode_res;
39         long res_maxsize;
40 };
41
42 static struct callback_op callback_ops[];
43
44 static __be32 nfs4_callback_null(struct svc_rqst *rqstp, void *argp, void *resp)
45 {
46         return htonl(NFS4_OK);
47 }
48
49 static int nfs4_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
50 {
51         return xdr_argsize_check(rqstp, p);
52 }
53
54 static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
55 {
56         return xdr_ressize_check(rqstp, p);
57 }
58
59 static __be32 *read_buf(struct xdr_stream *xdr, int nbytes)
60 {
61         __be32 *p;
62
63         p = xdr_inline_decode(xdr, nbytes);
64         if (unlikely(p == NULL))
65                 printk(KERN_WARNING "NFSv4 callback reply buffer overflowed!\n");
66         return p;
67 }
68
69 static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, const char **str)
70 {
71         __be32 *p;
72
73         p = read_buf(xdr, 4);
74         if (unlikely(p == NULL))
75                 return htonl(NFS4ERR_RESOURCE);
76         *len = ntohl(*p);
77
78         if (*len != 0) {
79                 p = read_buf(xdr, *len);
80                 if (unlikely(p == NULL))
81                         return htonl(NFS4ERR_RESOURCE);
82                 *str = (const char *)p;
83         } else
84                 *str = NULL;
85
86         return 0;
87 }
88
89 static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
90 {
91         __be32 *p;
92
93         p = read_buf(xdr, 4);
94         if (unlikely(p == NULL))
95                 return htonl(NFS4ERR_RESOURCE);
96         fh->size = ntohl(*p);
97         if (fh->size > NFS4_FHSIZE)
98                 return htonl(NFS4ERR_BADHANDLE);
99         p = read_buf(xdr, fh->size);
100         if (unlikely(p == NULL))
101                 return htonl(NFS4ERR_RESOURCE);
102         memcpy(&fh->data[0], p, fh->size);
103         memset(&fh->data[fh->size], 0, sizeof(fh->data) - fh->size);
104         return 0;
105 }
106
107 static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
108 {
109         __be32 *p;
110         unsigned int attrlen;
111
112         p = read_buf(xdr, 4);
113         if (unlikely(p == NULL))
114                 return htonl(NFS4ERR_RESOURCE);
115         attrlen = ntohl(*p);
116         p = read_buf(xdr, attrlen << 2);
117         if (unlikely(p == NULL))
118                 return htonl(NFS4ERR_RESOURCE);
119         if (likely(attrlen > 0))
120                 bitmap[0] = ntohl(*p++);
121         if (attrlen > 1)
122                 bitmap[1] = ntohl(*p);
123         return 0;
124 }
125
126 static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
127 {
128         __be32 *p;
129
130         p = read_buf(xdr, 16);
131         if (unlikely(p == NULL))
132                 return htonl(NFS4ERR_RESOURCE);
133         memcpy(stateid->data, p, 16);
134         return 0;
135 }
136
137 static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
138 {
139         __be32 *p;
140         __be32 status;
141
142         status = decode_string(xdr, &hdr->taglen, &hdr->tag);
143         if (unlikely(status != 0))
144                 return status;
145         /* We do not like overly long tags! */
146         if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
147                 printk("NFSv4 CALLBACK %s: client sent tag of length %u\n",
148                                 __func__, hdr->taglen);
149                 return htonl(NFS4ERR_RESOURCE);
150         }
151         p = read_buf(xdr, 12);
152         if (unlikely(p == NULL))
153                 return htonl(NFS4ERR_RESOURCE);
154         hdr->minorversion = ntohl(*p++);
155         /* Check minor version is zero or one. */
156         if (hdr->minorversion <= 1) {
157                 p++;    /* skip callback_ident */
158         } else {
159                 printk(KERN_WARNING "%s: NFSv4 server callback with "
160                         "illegal minor version %u!\n",
161                         __func__, hdr->minorversion);
162                 return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
163         }
164         hdr->nops = ntohl(*p);
165         dprintk("%s: minorversion %d nops %d\n", __func__,
166                 hdr->minorversion, hdr->nops);
167         return 0;
168 }
169
170 static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op)
171 {
172         __be32 *p;
173         p = read_buf(xdr, 4);
174         if (unlikely(p == NULL))
175                 return htonl(NFS4ERR_RESOURCE);
176         *op = ntohl(*p);
177         return 0;
178 }
179
180 static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args)
181 {
182         __be32 status;
183
184         status = decode_fh(xdr, &args->fh);
185         if (unlikely(status != 0))
186                 goto out;
187         args->addr = svc_addr(rqstp);
188         status = decode_bitmap(xdr, args->bitmap);
189 out:
190         dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
191         return status;
192 }
193
194 static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallargs *args)
195 {
196         __be32 *p;
197         __be32 status;
198
199         args->addr = svc_addr(rqstp);
200         status = decode_stateid(xdr, &args->stateid);
201         if (unlikely(status != 0))
202                 goto out;
203         p = read_buf(xdr, 4);
204         if (unlikely(p == NULL)) {
205                 status = htonl(NFS4ERR_RESOURCE);
206                 goto out;
207         }
208         args->truncate = ntohl(*p);
209         status = decode_fh(xdr, &args->fh);
210 out:
211         dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
212         return status;
213 }
214
215 #if defined(CONFIG_NFS_V4_1)
216
217 static unsigned decode_sessionid(struct xdr_stream *xdr,
218                                  struct nfs4_sessionid *sid)
219 {
220         uint32_t *p;
221         int len = NFS4_MAX_SESSIONID_LEN;
222
223         p = read_buf(xdr, len);
224         if (unlikely(p == NULL))
225                 return htonl(NFS4ERR_RESOURCE);;
226
227         memcpy(sid->data, p, len);
228         return 0;
229 }
230
231 static unsigned decode_rc_list(struct xdr_stream *xdr,
232                                struct referring_call_list *rc_list)
233 {
234         uint32_t *p;
235         int i;
236         unsigned status;
237
238         status = decode_sessionid(xdr, &rc_list->rcl_sessionid);
239         if (status)
240                 goto out;
241
242         status = htonl(NFS4ERR_RESOURCE);
243         p = read_buf(xdr, sizeof(uint32_t));
244         if (unlikely(p == NULL))
245                 goto out;
246
247         rc_list->rcl_nrefcalls = ntohl(*p++);
248         if (rc_list->rcl_nrefcalls) {
249                 p = read_buf(xdr,
250                              rc_list->rcl_nrefcalls * 2 * sizeof(uint32_t));
251                 if (unlikely(p == NULL))
252                         goto out;
253                 rc_list->rcl_refcalls = kmalloc(rc_list->rcl_nrefcalls *
254                                                 sizeof(*rc_list->rcl_refcalls),
255                                                 GFP_KERNEL);
256                 if (unlikely(rc_list->rcl_refcalls == NULL))
257                         goto out;
258                 for (i = 0; i < rc_list->rcl_nrefcalls; i++) {
259                         rc_list->rcl_refcalls[i].rc_sequenceid = ntohl(*p++);
260                         rc_list->rcl_refcalls[i].rc_slotid = ntohl(*p++);
261                 }
262         }
263         status = 0;
264
265 out:
266         return status;
267 }
268
269 static unsigned decode_cb_sequence_args(struct svc_rqst *rqstp,
270                                         struct xdr_stream *xdr,
271                                         struct cb_sequenceargs *args)
272 {
273         uint32_t *p;
274         int i;
275         unsigned status;
276
277         status = decode_sessionid(xdr, &args->csa_sessionid);
278         if (status)
279                 goto out;
280
281         status = htonl(NFS4ERR_RESOURCE);
282         p = read_buf(xdr, 5 * sizeof(uint32_t));
283         if (unlikely(p == NULL))
284                 goto out;
285
286         args->csa_addr = svc_addr(rqstp);
287         args->csa_sequenceid = ntohl(*p++);
288         args->csa_slotid = ntohl(*p++);
289         args->csa_highestslotid = ntohl(*p++);
290         args->csa_cachethis = ntohl(*p++);
291         args->csa_nrclists = ntohl(*p++);
292         args->csa_rclists = NULL;
293         if (args->csa_nrclists) {
294                 args->csa_rclists = kmalloc(args->csa_nrclists *
295                                             sizeof(*args->csa_rclists),
296                                             GFP_KERNEL);
297                 if (unlikely(args->csa_rclists == NULL))
298                         goto out;
299
300                 for (i = 0; i < args->csa_nrclists; i++) {
301                         status = decode_rc_list(xdr, &args->csa_rclists[i]);
302                         if (status)
303                                 goto out_free;
304                 }
305         }
306         status = 0;
307
308         dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u slotid %u "
309                 "highestslotid %u cachethis %d nrclists %u\n",
310                 __func__,
311                 ((u32 *)&args->csa_sessionid)[0],
312                 ((u32 *)&args->csa_sessionid)[1],
313                 ((u32 *)&args->csa_sessionid)[2],
314                 ((u32 *)&args->csa_sessionid)[3],
315                 args->csa_sequenceid, args->csa_slotid,
316                 args->csa_highestslotid, args->csa_cachethis,
317                 args->csa_nrclists);
318 out:
319         dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
320         return status;
321
322 out_free:
323         for (i = 0; i < args->csa_nrclists; i++)
324                 kfree(args->csa_rclists[i].rcl_refcalls);
325         kfree(args->csa_rclists);
326         goto out;
327 }
328
329 #endif /* CONFIG_NFS_V4_1 */
330
331 static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
332 {
333         __be32 *p;
334
335         p = xdr_reserve_space(xdr, 4 + len);
336         if (unlikely(p == NULL))
337                 return htonl(NFS4ERR_RESOURCE);
338         xdr_encode_opaque(p, str, len);
339         return 0;
340 }
341
342 #define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE)
343 #define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY)
344 static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep)
345 {
346         __be32 bm[2];
347         __be32 *p;
348
349         bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0);
350         bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1);
351         if (bm[1] != 0) {
352                 p = xdr_reserve_space(xdr, 16);
353                 if (unlikely(p == NULL))
354                         return htonl(NFS4ERR_RESOURCE);
355                 *p++ = htonl(2);
356                 *p++ = bm[0];
357                 *p++ = bm[1];
358         } else if (bm[0] != 0) {
359                 p = xdr_reserve_space(xdr, 12);
360                 if (unlikely(p == NULL))
361                         return htonl(NFS4ERR_RESOURCE);
362                 *p++ = htonl(1);
363                 *p++ = bm[0];
364         } else {
365                 p = xdr_reserve_space(xdr, 8);
366                 if (unlikely(p == NULL))
367                         return htonl(NFS4ERR_RESOURCE);
368                 *p++ = htonl(0);
369         }
370         *savep = p;
371         return 0;
372 }
373
374 static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change)
375 {
376         __be32 *p;
377
378         if (!(bitmap[0] & FATTR4_WORD0_CHANGE))
379                 return 0;
380         p = xdr_reserve_space(xdr, 8);
381         if (unlikely(!p))
382                 return htonl(NFS4ERR_RESOURCE);
383         p = xdr_encode_hyper(p, change);
384         return 0;
385 }
386
387 static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size)
388 {
389         __be32 *p;
390
391         if (!(bitmap[0] & FATTR4_WORD0_SIZE))
392                 return 0;
393         p = xdr_reserve_space(xdr, 8);
394         if (unlikely(!p))
395                 return htonl(NFS4ERR_RESOURCE);
396         p = xdr_encode_hyper(p, size);
397         return 0;
398 }
399
400 static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec *time)
401 {
402         __be32 *p;
403
404         p = xdr_reserve_space(xdr, 12);
405         if (unlikely(!p))
406                 return htonl(NFS4ERR_RESOURCE);
407         p = xdr_encode_hyper(p, time->tv_sec);
408         *p = htonl(time->tv_nsec);
409         return 0;
410 }
411
412 static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
413 {
414         if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA))
415                 return 0;
416         return encode_attr_time(xdr,time);
417 }
418
419 static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
420 {
421         if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY))
422                 return 0;
423         return encode_attr_time(xdr,time);
424 }
425
426 static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr)
427 {
428         __be32 status;
429
430         hdr->status = xdr_reserve_space(xdr, 4);
431         if (unlikely(hdr->status == NULL))
432                 return htonl(NFS4ERR_RESOURCE);
433         status = encode_string(xdr, hdr->taglen, hdr->tag);
434         if (unlikely(status != 0))
435                 return status;
436         hdr->nops = xdr_reserve_space(xdr, 4);
437         if (unlikely(hdr->nops == NULL))
438                 return htonl(NFS4ERR_RESOURCE);
439         return 0;
440 }
441
442 static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res)
443 {
444         __be32 *p;
445         
446         p = xdr_reserve_space(xdr, 8);
447         if (unlikely(p == NULL))
448                 return htonl(NFS4ERR_RESOURCE);
449         *p++ = htonl(op);
450         *p = res;
451         return 0;
452 }
453
454 static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_getattrres *res)
455 {
456         __be32 *savep = NULL;
457         __be32 status = res->status;
458         
459         if (unlikely(status != 0))
460                 goto out;
461         status = encode_attr_bitmap(xdr, res->bitmap, &savep);
462         if (unlikely(status != 0))
463                 goto out;
464         status = encode_attr_change(xdr, res->bitmap, res->change_attr);
465         if (unlikely(status != 0))
466                 goto out;
467         status = encode_attr_size(xdr, res->bitmap, res->size);
468         if (unlikely(status != 0))
469                 goto out;
470         status = encode_attr_ctime(xdr, res->bitmap, &res->ctime);
471         if (unlikely(status != 0))
472                 goto out;
473         status = encode_attr_mtime(xdr, res->bitmap, &res->mtime);
474         *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1)));
475 out:
476         dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
477         return status;
478 }
479
480 #if defined(CONFIG_NFS_V4_1)
481
482 static unsigned encode_sessionid(struct xdr_stream *xdr,
483                                  const struct nfs4_sessionid *sid)
484 {
485         uint32_t *p;
486         int len = NFS4_MAX_SESSIONID_LEN;
487
488         p = xdr_reserve_space(xdr, len);
489         if (unlikely(p == NULL))
490                 return htonl(NFS4ERR_RESOURCE);
491
492         memcpy(p, sid, len);
493         return 0;
494 }
495
496 static unsigned encode_cb_sequence_res(struct svc_rqst *rqstp,
497                                        struct xdr_stream *xdr,
498                                        const struct cb_sequenceres *res)
499 {
500         uint32_t *p;
501         unsigned status = res->csr_status;
502
503         if (unlikely(status != 0))
504                 goto out;
505
506         encode_sessionid(xdr, &res->csr_sessionid);
507
508         p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t));
509         if (unlikely(p == NULL))
510                 return htonl(NFS4ERR_RESOURCE);
511
512         *p++ = htonl(res->csr_sequenceid);
513         *p++ = htonl(res->csr_slotid);
514         *p++ = htonl(res->csr_highestslotid);
515         *p++ = htonl(res->csr_target_highestslotid);
516 out:
517         dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
518         return status;
519 }
520
521 static __be32
522 preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
523 {
524         if (op_nr == OP_CB_SEQUENCE) {
525                 if (nop != 0)
526                         return htonl(NFS4ERR_SEQUENCE_POS);
527         } else {
528                 if (nop == 0)
529                         return htonl(NFS4ERR_OP_NOT_IN_SESSION);
530         }
531
532         switch (op_nr) {
533         case OP_CB_GETATTR:
534         case OP_CB_RECALL:
535         case OP_CB_SEQUENCE:
536                 *op = &callback_ops[op_nr];
537                 break;
538
539         case OP_CB_LAYOUTRECALL:
540         case OP_CB_NOTIFY_DEVICEID:
541         case OP_CB_NOTIFY:
542         case OP_CB_PUSH_DELEG:
543         case OP_CB_RECALL_ANY:
544         case OP_CB_RECALLABLE_OBJ_AVAIL:
545         case OP_CB_RECALL_SLOT:
546         case OP_CB_WANTS_CANCELLED:
547         case OP_CB_NOTIFY_LOCK:
548                 return htonl(NFS4ERR_NOTSUPP);
549
550         default:
551                 return htonl(NFS4ERR_OP_ILLEGAL);
552         }
553
554         return htonl(NFS_OK);
555 }
556
557 #else /* CONFIG_NFS_V4_1 */
558
559 static __be32
560 preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
561 {
562         return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
563 }
564
565 #endif /* CONFIG_NFS_V4_1 */
566
567 static __be32
568 preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op)
569 {
570         switch (op_nr) {
571         case OP_CB_GETATTR:
572         case OP_CB_RECALL:
573                 *op = &callback_ops[op_nr];
574                 break;
575         default:
576                 return htonl(NFS4ERR_OP_ILLEGAL);
577         }
578
579         return htonl(NFS_OK);
580 }
581
582 static __be32 process_op(uint32_t minorversion, int nop,
583                 struct svc_rqst *rqstp,
584                 struct xdr_stream *xdr_in, void *argp,
585                 struct xdr_stream *xdr_out, void *resp)
586 {
587         struct callback_op *op = &callback_ops[0];
588         unsigned int op_nr = OP_CB_ILLEGAL;
589         __be32 status;
590         long maxlen;
591         __be32 res;
592
593         dprintk("%s: start\n", __func__);
594         status = decode_op_hdr(xdr_in, &op_nr);
595         if (unlikely(status)) {
596                 status = htonl(NFS4ERR_OP_ILLEGAL);
597                 goto out;
598         }
599
600         dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
601                 __func__, minorversion, nop, op_nr);
602
603         status = minorversion ? preprocess_nfs41_op(nop, op_nr, &op) :
604                                 preprocess_nfs4_op(op_nr, &op);
605         if (status == htonl(NFS4ERR_OP_ILLEGAL))
606                 op_nr = OP_CB_ILLEGAL;
607 out:
608         maxlen = xdr_out->end - xdr_out->p;
609         if (maxlen > 0 && maxlen < PAGE_SIZE) {
610                 if (likely(status == 0 && op->decode_args != NULL))
611                         status = op->decode_args(rqstp, xdr_in, argp);
612                 if (likely(status == 0 && op->process_op != NULL))
613                         status = op->process_op(argp, resp);
614         } else
615                 status = htonl(NFS4ERR_RESOURCE);
616
617         res = encode_op_hdr(xdr_out, op_nr, status);
618         if (status == 0)
619                 status = res;
620         if (op->encode_res != NULL && status == 0)
621                 status = op->encode_res(rqstp, xdr_out, resp);
622         dprintk("%s: done, status = %d\n", __func__, ntohl(status));
623         return status;
624 }
625
626 /*
627  * Decode, process and encode a COMPOUND
628  */
629 static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *resp)
630 {
631         struct cb_compound_hdr_arg hdr_arg = { 0 };
632         struct cb_compound_hdr_res hdr_res = { NULL };
633         struct xdr_stream xdr_in, xdr_out;
634         __be32 *p;
635         __be32 status;
636         unsigned int nops = 0;
637
638         dprintk("%s: start\n", __func__);
639
640         xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base);
641
642         p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len);
643         xdr_init_encode(&xdr_out, &rqstp->rq_res, p);
644
645         status = decode_compound_hdr_arg(&xdr_in, &hdr_arg);
646         if (status == __constant_htonl(NFS4ERR_RESOURCE))
647                 return rpc_garbage_args;
648
649         hdr_res.taglen = hdr_arg.taglen;
650         hdr_res.tag = hdr_arg.tag;
651         if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0)
652                 return rpc_system_err;
653
654         while (status == 0 && nops != hdr_arg.nops) {
655                 status = process_op(hdr_arg.minorversion, nops,
656                                     rqstp, &xdr_in, argp, &xdr_out, resp);
657                 nops++;
658         }
659
660         *hdr_res.status = status;
661         *hdr_res.nops = htonl(nops);
662         dprintk("%s: done, status = %u\n", __func__, ntohl(status));
663         return rpc_success;
664 }
665
666 /*
667  * Define NFS4 callback COMPOUND ops.
668  */
669 static struct callback_op callback_ops[] = {
670         [0] = {
671                 .res_maxsize = CB_OP_HDR_RES_MAXSZ,
672         },
673         [OP_CB_GETATTR] = {
674                 .process_op = (callback_process_op_t)nfs4_callback_getattr,
675                 .decode_args = (callback_decode_arg_t)decode_getattr_args,
676                 .encode_res = (callback_encode_res_t)encode_getattr_res,
677                 .res_maxsize = CB_OP_GETATTR_RES_MAXSZ,
678         },
679         [OP_CB_RECALL] = {
680                 .process_op = (callback_process_op_t)nfs4_callback_recall,
681                 .decode_args = (callback_decode_arg_t)decode_recall_args,
682                 .res_maxsize = CB_OP_RECALL_RES_MAXSZ,
683         },
684 #if defined(CONFIG_NFS_V4_1)
685         [OP_CB_SEQUENCE] = {
686                 .process_op = (callback_process_op_t)nfs4_callback_sequence,
687                 .decode_args = (callback_decode_arg_t)decode_cb_sequence_args,
688                 .encode_res = (callback_encode_res_t)encode_cb_sequence_res,
689                 .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ,
690         },
691 #endif /* CONFIG_NFS_V4_1 */
692 };
693
694 /*
695  * Define NFS4 callback procedures
696  */
697 static struct svc_procedure nfs4_callback_procedures1[] = {
698         [CB_NULL] = {
699                 .pc_func = nfs4_callback_null,
700                 .pc_decode = (kxdrproc_t)nfs4_decode_void,
701                 .pc_encode = (kxdrproc_t)nfs4_encode_void,
702                 .pc_xdrressize = 1,
703         },
704         [CB_COMPOUND] = {
705                 .pc_func = nfs4_callback_compound,
706                 .pc_encode = (kxdrproc_t)nfs4_encode_void,
707                 .pc_argsize = 256,
708                 .pc_ressize = 256,
709                 .pc_xdrressize = NFS4_CALLBACK_BUFSIZE,
710         }
711 };
712
713 struct svc_version nfs4_callback_version1 = {
714         .vs_vers = 1,
715         .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1),
716         .vs_proc = nfs4_callback_procedures1,
717         .vs_xdrsize = NFS4_CALLBACK_XDRSIZE,
718         .vs_dispatch = NULL,
719 };
720