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