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