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