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