| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/fs/nfs/callback_xdr.c | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2004 Trond Myklebust | 
|  | 5 | * | 
|  | 6 | * NFSv4 callback encode/decode procedures | 
|  | 7 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/kernel.h> | 
|  | 9 | #include <linux/sunrpc/svc.h> | 
|  | 10 | #include <linux/nfs4.h> | 
|  | 11 | #include <linux/nfs_fs.h> | 
| Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 12 | #include "nfs4_fs.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #define NFSDBG_FACILITY NFSDBG_CALLBACK | 
|  | 29 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 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 *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 44 | static __be32 nfs4_callback_null(struct svc_rqst *rqstp, void *argp, void *resp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { | 
|  | 46 | return htonl(NFS4_OK); | 
|  | 47 | } | 
|  | 48 |  | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 49 | static int nfs4_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { | 
|  | 51 | return xdr_argsize_check(rqstp, p); | 
|  | 52 | } | 
|  | 53 |  | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 54 | static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { | 
|  | 56 | return xdr_ressize_check(rqstp, p); | 
|  | 57 | } | 
|  | 58 |  | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 59 | static __be32 *read_buf(struct xdr_stream *xdr, int nbytes) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 61 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 69 | static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, const char **str) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 71 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 89 | static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 91 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 107 | static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 109 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 126 | static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 128 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 137 | static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 139 | __be32 *p; | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 140 | __be32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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! */ | 
| Chuck Lever | 5cce428 | 2007-10-26 13:33:01 -0400 | [diff] [blame] | 146 | if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | printk("NFSv4 CALLBACK %s: client sent tag of length %u\n", | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 148 | __func__, hdr->taglen); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | return htonl(NFS4ERR_RESOURCE); | 
|  | 150 | } | 
|  | 151 | p = read_buf(xdr, 12); | 
|  | 152 | if (unlikely(p == NULL)) | 
|  | 153 | return htonl(NFS4ERR_RESOURCE); | 
| Benny Halevy | b8f2ef8 | 2009-04-01 09:23:19 -0400 | [diff] [blame] | 154 | hdr->minorversion = ntohl(*p++); | 
| Benny Halevy | 48a9e2d | 2009-04-01 09:23:20 -0400 | [diff] [blame] | 155 | /* Check minor version is zero or one. */ | 
|  | 156 | if (hdr->minorversion <= 1) { | 
|  | 157 | p++;	/* skip callback_ident */ | 
|  | 158 | } else { | 
| Benny Halevy | b8f2ef8 | 2009-04-01 09:23:19 -0400 | [diff] [blame] | 159 | printk(KERN_WARNING "%s: NFSv4 server callback with " | 
|  | 160 | "illegal minor version %u!\n", | 
|  | 161 | __func__, hdr->minorversion); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); | 
|  | 163 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | hdr->nops = ntohl(*p); | 
| Benny Halevy | b8f2ef8 | 2009-04-01 09:23:19 -0400 | [diff] [blame] | 165 | dprintk("%s: minorversion %d nops %d\n", __func__, | 
|  | 166 | hdr->minorversion, hdr->nops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return 0; | 
|  | 168 | } | 
|  | 169 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 170 | static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 172 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 180 | static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 182 | __be32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
|  | 184 | status = decode_fh(xdr, &args->fh); | 
|  | 185 | if (unlikely(status != 0)) | 
|  | 186 | goto out; | 
| Chuck Lever | 671beed | 2007-12-10 14:58:22 -0500 | [diff] [blame] | 187 | args->addr = svc_addr(rqstp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | status = decode_bitmap(xdr, args->bitmap); | 
|  | 189 | out: | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 190 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | return status; | 
|  | 192 | } | 
|  | 193 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 194 | static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallargs *args) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 196 | __be32 *p; | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 197 | __be32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 |  | 
| Chuck Lever | c1d3586 | 2007-12-10 14:58:29 -0500 | [diff] [blame] | 199 | args->addr = svc_addr(rqstp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 211 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); | 
| Alexey Dobriyan | 3873bc5 | 2006-05-27 03:31:12 +0400 | [diff] [blame] | 212 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } | 
|  | 214 |  | 
| Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 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)) | 
| Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 225 | return htonl(NFS4ERR_RESOURCE); | 
| Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 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 |  | 
| Ricardo Labiaga | 65fc64e | 2009-04-01 09:23:30 -0400 | [diff] [blame] | 286 | args->csa_addr = svc_addr(rqstp); | 
| Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 331 | static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 333 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 344 | static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 346 | __be32 bm[2]; | 
|  | 347 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 374 | static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 376 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 |  | 
|  | 378 | if (!(bitmap[0] & FATTR4_WORD0_CHANGE)) | 
|  | 379 | return 0; | 
|  | 380 | p = xdr_reserve_space(xdr, 8); | 
| Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 381 | if (unlikely(!p)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return htonl(NFS4ERR_RESOURCE); | 
|  | 383 | p = xdr_encode_hyper(p, change); | 
|  | 384 | return 0; | 
|  | 385 | } | 
|  | 386 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 387 | static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 389 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 |  | 
|  | 391 | if (!(bitmap[0] & FATTR4_WORD0_SIZE)) | 
|  | 392 | return 0; | 
|  | 393 | p = xdr_reserve_space(xdr, 8); | 
| Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 394 | if (unlikely(!p)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return htonl(NFS4ERR_RESOURCE); | 
|  | 396 | p = xdr_encode_hyper(p, size); | 
|  | 397 | return 0; | 
|  | 398 | } | 
|  | 399 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 400 | static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec *time) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 402 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 |  | 
|  | 404 | p = xdr_reserve_space(xdr, 12); | 
| Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 405 | if (unlikely(!p)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 412 | static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { | 
|  | 414 | if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) | 
|  | 415 | return 0; | 
|  | 416 | return encode_attr_time(xdr,time); | 
|  | 417 | } | 
|  | 418 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 419 | static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { | 
|  | 421 | if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) | 
|  | 422 | return 0; | 
|  | 423 | return encode_attr_time(xdr,time); | 
|  | 424 | } | 
|  | 425 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 426 | static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 428 | __be32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 442 | static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 444 | __be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 454 | static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_getattrres *res) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 456 | __be32 *savep = NULL; | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 457 | __be32 status = res->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 476 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | return status; | 
|  | 478 | } | 
|  | 479 |  | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 480 | #if defined(CONFIG_NFS_V4_1) | 
|  | 481 |  | 
| Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 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 |  | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 521 | static __be32 | 
|  | 522 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | 
|  | 523 | { | 
| Benny Halevy | 281fe15 | 2009-04-01 09:23:27 -0400 | [diff] [blame] | 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 |  | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 532 | switch (op_nr) { | 
|  | 533 | case OP_CB_GETATTR: | 
|  | 534 | case OP_CB_RECALL: | 
| Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 535 | case OP_CB_SEQUENCE: | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 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: | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 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, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | struct xdr_stream *xdr_in, void *argp, | 
|  | 585 | struct xdr_stream *xdr_out, void *resp) | 
|  | 586 | { | 
| Trond Myklebust | a162a6b | 2006-03-20 13:44:10 -0500 | [diff] [blame] | 587 | struct callback_op *op = &callback_ops[0]; | 
|  | 588 | unsigned int op_nr = OP_CB_ILLEGAL; | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 589 | __be32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | long maxlen; | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 591 | __be32 res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 593 | dprintk("%s: start\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | status = decode_op_hdr(xdr_in, &op_nr); | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 595 | if (unlikely(status)) { | 
|  | 596 | status = htonl(NFS4ERR_OP_ILLEGAL); | 
|  | 597 | goto out; | 
| Trond Myklebust | a162a6b | 2006-03-20 13:44:10 -0500 | [diff] [blame] | 598 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 |  | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 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: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 622 | dprintk("%s: done, status = %d\n", __func__, ntohl(status)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return status; | 
|  | 624 | } | 
|  | 625 |  | 
|  | 626 | /* | 
|  | 627 | * Decode, process and encode a COMPOUND | 
|  | 628 | */ | 
| Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 629 | static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *resp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { | 
| Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 631 | struct cb_compound_hdr_arg hdr_arg = { 0 }; | 
|  | 632 | struct cb_compound_hdr_res hdr_res = { NULL }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | struct xdr_stream xdr_in, xdr_out; | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 634 | __be32 *p; | 
| Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 635 | __be32 status; | 
| Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 636 | unsigned int nops = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 638 | dprintk("%s: start\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 |  | 
|  | 640 | xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base); | 
|  | 641 |  | 
| Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 642 | p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | xdr_init_encode(&xdr_out, &rqstp->rq_res, p); | 
|  | 644 |  | 
| Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 645 | status = decode_compound_hdr_arg(&xdr_in, &hdr_arg); | 
|  | 646 | if (status == __constant_htonl(NFS4ERR_RESOURCE)) | 
|  | 647 | return rpc_garbage_args; | 
|  | 648 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | hdr_res.taglen = hdr_arg.taglen; | 
|  | 650 | hdr_res.tag = hdr_arg.tag; | 
| Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 651 | if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0) | 
|  | 652 | return rpc_system_err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 |  | 
| Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 654 | while (status == 0 && nops != hdr_arg.nops) { | 
| Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 655 | status = process_op(hdr_arg.minorversion, nops, | 
|  | 656 | rqstp, &xdr_in, argp, &xdr_out, resp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | nops++; | 
|  | 658 | } | 
| Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 659 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | *hdr_res.status = status; | 
|  | 661 | *hdr_res.nops = htonl(nops); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 662 | dprintk("%s: done, status = %u\n", __func__, ntohl(status)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, | 
| Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 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 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  |