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