]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/nfs/callback_xdr.c | |
3 | * | |
4 | * Copyright (C) 2004 Trond Myklebust | |
5 | * | |
6 | * NFSv4 callback encode/decode procedures | |
7 | */ | |
1da177e4 LT |
8 | #include <linux/kernel.h> |
9 | #include <linux/sunrpc/svc.h> | |
10 | #include <linux/nfs4.h> | |
11 | #include <linux/nfs_fs.h> | |
9a3ba432 TM |
12 | #include <linux/ratelimit.h> |
13 | #include <linux/printk.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
c36fca52 | 15 | #include <linux/sunrpc/bc_xprt.h> |
4ce79717 | 16 | #include "nfs4_fs.h" |
1da177e4 | 17 | #include "callback.h" |
c36fca52 | 18 | #include "internal.h" |
76e697ba | 19 | #include "nfs4session.h" |
1da177e4 | 20 | |
45724e8a KM |
21 | #define CB_OP_TAGLEN_MAXSZ (512) |
22 | #define CB_OP_HDR_RES_MAXSZ (2 * 4) // opcode, status | |
23 | #define CB_OP_GETATTR_BITMAP_MAXSZ (4 * 4) // bitmap length, 3 bitmaps | |
24 | #define CB_OP_GETATTR_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ | |
25 | CB_OP_GETATTR_BITMAP_MAXSZ + \ | |
26 | /* change, size, ctime, mtime */\ | |
27 | (2 + 2 + 3 + 3) * 4) | |
28 | #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) | |
1da177e4 | 29 | |
4aece6a1 | 30 | #if defined(CONFIG_NFS_V4_1) |
f2a62561 | 31 | #define CB_OP_LAYOUTRECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
1be5683b | 32 | #define CB_OP_DEVICENOTIFY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
4aece6a1 | 33 | #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ |
45724e8a KM |
34 | NFS4_MAX_SESSIONID_LEN + \ |
35 | (1 + 3) * 4) // seqid, 3 slotids | |
31f09607 | 36 | #define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
b9efa1b2 | 37 | #define CB_OP_RECALLSLOT_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
db783688 | 38 | #define CB_OP_NOTIFY_LOCK_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
4aece6a1 BH |
39 | #endif /* CONFIG_NFS_V4_1 */ |
40 | ||
1da177e4 LT |
41 | #define NFSDBG_FACILITY NFSDBG_CALLBACK |
42 | ||
31d2b435 AA |
43 | /* Internal error code */ |
44 | #define NFS4ERR_RESOURCE_HDR 11050 | |
45 | ||
1da177e4 | 46 | struct callback_op { |
f4dac4ad CH |
47 | __be32 (*process_op)(void *, void *, struct cb_process_state *); |
48 | __be32 (*decode_args)(struct svc_rqst *, struct xdr_stream *, void *); | |
49 | __be32 (*encode_res)(struct svc_rqst *, struct xdr_stream *, | |
50 | const void *); | |
1da177e4 LT |
51 | long res_maxsize; |
52 | }; | |
53 | ||
54 | static struct callback_op callback_ops[]; | |
55 | ||
a6beb732 | 56 | static __be32 nfs4_callback_null(struct svc_rqst *rqstp) |
1da177e4 LT |
57 | { |
58 | return htonl(NFS4_OK); | |
59 | } | |
60 | ||
026fec7e | 61 | static int nfs4_decode_void(struct svc_rqst *rqstp, __be32 *p) |
1da177e4 LT |
62 | { |
63 | return xdr_argsize_check(rqstp, p); | |
64 | } | |
65 | ||
63f8de37 | 66 | static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p) |
1da177e4 LT |
67 | { |
68 | return xdr_ressize_check(rqstp, p); | |
69 | } | |
70 | ||
b60475c9 | 71 | static __be32 *read_buf(struct xdr_stream *xdr, size_t nbytes) |
1da177e4 | 72 | { |
5704fdeb | 73 | __be32 *p; |
1da177e4 LT |
74 | |
75 | p = xdr_inline_decode(xdr, nbytes); | |
76 | if (unlikely(p == NULL)) | |
756b9b37 | 77 | printk(KERN_WARNING "NFS: NFSv4 callback reply buffer overflowed!\n"); |
1da177e4 LT |
78 | return p; |
79 | } | |
80 | ||
c065eeea TM |
81 | static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, |
82 | const char **str, size_t maxlen) | |
1da177e4 | 83 | { |
c065eeea | 84 | ssize_t err; |
1da177e4 | 85 | |
c065eeea TM |
86 | err = xdr_stream_decode_opaque_inline(xdr, (void **)str, maxlen); |
87 | if (err < 0) | |
88 | return cpu_to_be32(NFS4ERR_RESOURCE); | |
89 | *len = err; | |
1da177e4 LT |
90 | return 0; |
91 | } | |
92 | ||
e6f684f6 | 93 | static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh) |
1da177e4 | 94 | { |
5704fdeb | 95 | __be32 *p; |
1da177e4 LT |
96 | |
97 | p = read_buf(xdr, 4); | |
98 | if (unlikely(p == NULL)) | |
99 | return htonl(NFS4ERR_RESOURCE); | |
100 | fh->size = ntohl(*p); | |
101 | if (fh->size > NFS4_FHSIZE) | |
102 | return htonl(NFS4ERR_BADHANDLE); | |
103 | p = read_buf(xdr, fh->size); | |
104 | if (unlikely(p == NULL)) | |
105 | return htonl(NFS4ERR_RESOURCE); | |
106 | memcpy(&fh->data[0], p, fh->size); | |
107 | memset(&fh->data[fh->size], 0, sizeof(fh->data) - fh->size); | |
108 | return 0; | |
109 | } | |
110 | ||
e6f684f6 | 111 | static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) |
1da177e4 | 112 | { |
5704fdeb | 113 | __be32 *p; |
1da177e4 LT |
114 | unsigned int attrlen; |
115 | ||
116 | p = read_buf(xdr, 4); | |
117 | if (unlikely(p == NULL)) | |
118 | return htonl(NFS4ERR_RESOURCE); | |
119 | attrlen = ntohl(*p); | |
120 | p = read_buf(xdr, attrlen << 2); | |
121 | if (unlikely(p == NULL)) | |
122 | return htonl(NFS4ERR_RESOURCE); | |
123 | if (likely(attrlen > 0)) | |
124 | bitmap[0] = ntohl(*p++); | |
125 | if (attrlen > 1) | |
126 | bitmap[1] = ntohl(*p); | |
127 | return 0; | |
128 | } | |
129 | ||
e6f684f6 | 130 | static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
1da177e4 | 131 | { |
5704fdeb | 132 | __be32 *p; |
1da177e4 | 133 | |
2d2f24ad | 134 | p = read_buf(xdr, NFS4_STATEID_SIZE); |
1da177e4 LT |
135 | if (unlikely(p == NULL)) |
136 | return htonl(NFS4ERR_RESOURCE); | |
93b717fd | 137 | memcpy(stateid->data, p, NFS4_STATEID_SIZE); |
1da177e4 LT |
138 | return 0; |
139 | } | |
140 | ||
93b717fd TM |
141 | static __be32 decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
142 | { | |
143 | stateid->type = NFS4_DELEGATION_STATEID_TYPE; | |
144 | return decode_stateid(xdr, stateid); | |
145 | } | |
146 | ||
e6f684f6 | 147 | static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr) |
1da177e4 | 148 | { |
5704fdeb | 149 | __be32 *p; |
e6f684f6 | 150 | __be32 status; |
1da177e4 | 151 | |
c065eeea | 152 | status = decode_string(xdr, &hdr->taglen, &hdr->tag, CB_OP_TAGLEN_MAXSZ); |
1da177e4 LT |
153 | if (unlikely(status != 0)) |
154 | return status; | |
1da177e4 LT |
155 | p = read_buf(xdr, 12); |
156 | if (unlikely(p == NULL)) | |
157 | return htonl(NFS4ERR_RESOURCE); | |
b8f2ef84 | 158 | hdr->minorversion = ntohl(*p++); |
459de2ed BS |
159 | /* Check for minor version support */ |
160 | if (hdr->minorversion <= NFS4_MAX_MINOR_VERSION) { | |
42c2c424 | 161 | hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 and v4.2 */ |
48a9e2d2 | 162 | } else { |
9a3ba432 | 163 | pr_warn_ratelimited("NFS: %s: NFSv4 server callback with " |
b8f2ef84 BH |
164 | "illegal minor version %u!\n", |
165 | __func__, hdr->minorversion); | |
1da177e4 LT |
166 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
167 | } | |
1da177e4 LT |
168 | hdr->nops = ntohl(*p); |
169 | return 0; | |
170 | } | |
171 | ||
e6f684f6 | 172 | static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op) |
1da177e4 | 173 | { |
5704fdeb | 174 | __be32 *p; |
1da177e4 LT |
175 | p = read_buf(xdr, 4); |
176 | if (unlikely(p == NULL)) | |
31d2b435 | 177 | return htonl(NFS4ERR_RESOURCE_HDR); |
1da177e4 LT |
178 | *op = ntohl(*p); |
179 | return 0; | |
180 | } | |
181 | ||
f4dac4ad CH |
182 | static __be32 decode_getattr_args(struct svc_rqst *rqstp, |
183 | struct xdr_stream *xdr, void *argp) | |
1da177e4 | 184 | { |
f4dac4ad | 185 | struct cb_getattrargs *args = argp; |
e6f684f6 | 186 | __be32 status; |
1da177e4 LT |
187 | |
188 | status = decode_fh(xdr, &args->fh); | |
189 | if (unlikely(status != 0)) | |
56938bb7 AS |
190 | return status; |
191 | return decode_bitmap(xdr, args->bitmap); | |
1da177e4 LT |
192 | } |
193 | ||
f4dac4ad CH |
194 | static __be32 decode_recall_args(struct svc_rqst *rqstp, |
195 | struct xdr_stream *xdr, void *argp) | |
1da177e4 | 196 | { |
f4dac4ad | 197 | struct cb_recallargs *args = argp; |
5704fdeb | 198 | __be32 *p; |
e6f684f6 | 199 | __be32 status; |
1da177e4 | 200 | |
93b717fd | 201 | status = decode_delegation_stateid(xdr, &args->stateid); |
1da177e4 | 202 | if (unlikely(status != 0)) |
135a4ea0 | 203 | return status; |
1da177e4 | 204 | p = read_buf(xdr, 4); |
135a4ea0 AS |
205 | if (unlikely(p == NULL)) |
206 | return htonl(NFS4ERR_RESOURCE); | |
1da177e4 | 207 | args->truncate = ntohl(*p); |
135a4ea0 | 208 | return decode_fh(xdr, &args->fh); |
1da177e4 LT |
209 | } |
210 | ||
4aece6a1 | 211 | #if defined(CONFIG_NFS_V4_1) |
93b717fd TM |
212 | static __be32 decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
213 | { | |
214 | stateid->type = NFS4_LAYOUT_STATEID_TYPE; | |
215 | return decode_stateid(xdr, stateid); | |
216 | } | |
4aece6a1 | 217 | |
f2a62561 | 218 | static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp, |
f4dac4ad | 219 | struct xdr_stream *xdr, void *argp) |
f2a62561 | 220 | { |
f4dac4ad | 221 | struct cb_layoutrecallargs *args = argp; |
f2a62561 FI |
222 | __be32 *p; |
223 | __be32 status = 0; | |
224 | uint32_t iomode; | |
225 | ||
f2a62561 | 226 | p = read_buf(xdr, 4 * sizeof(uint32_t)); |
c79d56d2 AS |
227 | if (unlikely(p == NULL)) |
228 | return htonl(NFS4ERR_BADXDR); | |
f2a62561 FI |
229 | |
230 | args->cbl_layout_type = ntohl(*p++); | |
231 | /* Depite the spec's xdr, iomode really belongs in the FILE switch, | |
25985edc | 232 | * as it is unusable and ignored with the other types. |
f2a62561 FI |
233 | */ |
234 | iomode = ntohl(*p++); | |
235 | args->cbl_layoutchanged = ntohl(*p++); | |
236 | args->cbl_recall_type = ntohl(*p++); | |
237 | ||
238 | if (args->cbl_recall_type == RETURN_FILE) { | |
239 | args->cbl_range.iomode = iomode; | |
240 | status = decode_fh(xdr, &args->cbl_fh); | |
241 | if (unlikely(status != 0)) | |
c79d56d2 | 242 | return status; |
f2a62561 FI |
243 | |
244 | p = read_buf(xdr, 2 * sizeof(uint64_t)); | |
c79d56d2 AS |
245 | if (unlikely(p == NULL)) |
246 | return htonl(NFS4ERR_BADXDR); | |
f2a62561 FI |
247 | p = xdr_decode_hyper(p, &args->cbl_range.offset); |
248 | p = xdr_decode_hyper(p, &args->cbl_range.length); | |
c79d56d2 | 249 | return decode_layout_stateid(xdr, &args->cbl_stateid); |
f2a62561 FI |
250 | } else if (args->cbl_recall_type == RETURN_FSID) { |
251 | p = read_buf(xdr, 2 * sizeof(uint64_t)); | |
c79d56d2 AS |
252 | if (unlikely(p == NULL)) |
253 | return htonl(NFS4ERR_BADXDR); | |
f2a62561 FI |
254 | p = xdr_decode_hyper(p, &args->cbl_fsid.major); |
255 | p = xdr_decode_hyper(p, &args->cbl_fsid.minor); | |
c79d56d2 AS |
256 | } else if (args->cbl_recall_type != RETURN_ALL) |
257 | return htonl(NFS4ERR_BADXDR); | |
258 | return 0; | |
f2a62561 FI |
259 | } |
260 | ||
1be5683b ME |
261 | static |
262 | __be32 decode_devicenotify_args(struct svc_rqst *rqstp, | |
263 | struct xdr_stream *xdr, | |
f4dac4ad | 264 | void *argp) |
1be5683b | 265 | { |
f4dac4ad | 266 | struct cb_devicenotifyargs *args = argp; |
1be5683b ME |
267 | __be32 *p; |
268 | __be32 status = 0; | |
269 | u32 tmp; | |
270 | int n, i; | |
271 | args->ndevs = 0; | |
272 | ||
273 | /* Num of device notifications */ | |
274 | p = read_buf(xdr, sizeof(uint32_t)); | |
275 | if (unlikely(p == NULL)) { | |
276 | status = htonl(NFS4ERR_BADXDR); | |
277 | goto out; | |
278 | } | |
279 | n = ntohl(*p++); | |
280 | if (n <= 0) | |
281 | goto out; | |
363e0df0 DC |
282 | if (n > ULONG_MAX / sizeof(*args->devs)) { |
283 | status = htonl(NFS4ERR_BADXDR); | |
284 | goto out; | |
285 | } | |
1be5683b | 286 | |
a4f743a6 | 287 | args->devs = kmalloc_array(n, sizeof(*args->devs), GFP_KERNEL); |
1be5683b ME |
288 | if (!args->devs) { |
289 | status = htonl(NFS4ERR_DELAY); | |
290 | goto out; | |
291 | } | |
292 | ||
293 | /* Decode each dev notification */ | |
294 | for (i = 0; i < n; i++) { | |
295 | struct cb_devicenotifyitem *dev = &args->devs[i]; | |
296 | ||
297 | p = read_buf(xdr, (4 * sizeof(uint32_t)) + NFS4_DEVICEID4_SIZE); | |
298 | if (unlikely(p == NULL)) { | |
299 | status = htonl(NFS4ERR_BADXDR); | |
300 | goto err; | |
301 | } | |
302 | ||
303 | tmp = ntohl(*p++); /* bitmap size */ | |
304 | if (tmp != 1) { | |
305 | status = htonl(NFS4ERR_INVAL); | |
306 | goto err; | |
307 | } | |
308 | dev->cbd_notify_type = ntohl(*p++); | |
309 | if (dev->cbd_notify_type != NOTIFY_DEVICEID4_CHANGE && | |
310 | dev->cbd_notify_type != NOTIFY_DEVICEID4_DELETE) { | |
311 | status = htonl(NFS4ERR_INVAL); | |
312 | goto err; | |
313 | } | |
314 | ||
315 | tmp = ntohl(*p++); /* opaque size */ | |
316 | if (((dev->cbd_notify_type == NOTIFY_DEVICEID4_CHANGE) && | |
317 | (tmp != NFS4_DEVICEID4_SIZE + 8)) || | |
318 | ((dev->cbd_notify_type == NOTIFY_DEVICEID4_DELETE) && | |
319 | (tmp != NFS4_DEVICEID4_SIZE + 4))) { | |
320 | status = htonl(NFS4ERR_INVAL); | |
321 | goto err; | |
322 | } | |
323 | dev->cbd_layout_type = ntohl(*p++); | |
324 | memcpy(dev->cbd_dev_id.data, p, NFS4_DEVICEID4_SIZE); | |
325 | p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE); | |
326 | ||
327 | if (dev->cbd_layout_type == NOTIFY_DEVICEID4_CHANGE) { | |
328 | p = read_buf(xdr, sizeof(uint32_t)); | |
329 | if (unlikely(p == NULL)) { | |
330 | status = htonl(NFS4ERR_BADXDR); | |
331 | goto err; | |
332 | } | |
333 | dev->cbd_immediate = ntohl(*p++); | |
334 | } else { | |
335 | dev->cbd_immediate = 0; | |
336 | } | |
337 | ||
338 | args->ndevs++; | |
339 | ||
340 | dprintk("%s: type %d layout 0x%x immediate %d\n", | |
341 | __func__, dev->cbd_notify_type, dev->cbd_layout_type, | |
342 | dev->cbd_immediate); | |
343 | } | |
344 | out: | |
345 | dprintk("%s: status %d ndevs %d\n", | |
346 | __func__, ntohl(status), args->ndevs); | |
347 | return status; | |
348 | err: | |
349 | kfree(args->devs); | |
350 | goto out; | |
351 | } | |
352 | ||
9733f0d9 | 353 | static __be32 decode_sessionid(struct xdr_stream *xdr, |
4aece6a1 BH |
354 | struct nfs4_sessionid *sid) |
355 | { | |
9733f0d9 | 356 | __be32 *p; |
4aece6a1 | 357 | |
590184a6 | 358 | p = read_buf(xdr, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 | 359 | if (unlikely(p == NULL)) |
a419aef8 | 360 | return htonl(NFS4ERR_RESOURCE); |
4aece6a1 | 361 | |
590184a6 | 362 | memcpy(sid->data, p, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 BH |
363 | return 0; |
364 | } | |
365 | ||
9733f0d9 | 366 | static __be32 decode_rc_list(struct xdr_stream *xdr, |
4aece6a1 BH |
367 | struct referring_call_list *rc_list) |
368 | { | |
9733f0d9 | 369 | __be32 *p; |
4aece6a1 | 370 | int i; |
9733f0d9 | 371 | __be32 status; |
4aece6a1 BH |
372 | |
373 | status = decode_sessionid(xdr, &rc_list->rcl_sessionid); | |
374 | if (status) | |
375 | goto out; | |
376 | ||
377 | status = htonl(NFS4ERR_RESOURCE); | |
378 | p = read_buf(xdr, sizeof(uint32_t)); | |
379 | if (unlikely(p == NULL)) | |
380 | goto out; | |
381 | ||
382 | rc_list->rcl_nrefcalls = ntohl(*p++); | |
383 | if (rc_list->rcl_nrefcalls) { | |
384 | p = read_buf(xdr, | |
385 | rc_list->rcl_nrefcalls * 2 * sizeof(uint32_t)); | |
386 | if (unlikely(p == NULL)) | |
387 | goto out; | |
a4f743a6 | 388 | rc_list->rcl_refcalls = kmalloc_array(rc_list->rcl_nrefcalls, |
4aece6a1 BH |
389 | sizeof(*rc_list->rcl_refcalls), |
390 | GFP_KERNEL); | |
391 | if (unlikely(rc_list->rcl_refcalls == NULL)) | |
392 | goto out; | |
393 | for (i = 0; i < rc_list->rcl_nrefcalls; i++) { | |
394 | rc_list->rcl_refcalls[i].rc_sequenceid = ntohl(*p++); | |
395 | rc_list->rcl_refcalls[i].rc_slotid = ntohl(*p++); | |
396 | } | |
397 | } | |
398 | status = 0; | |
399 | ||
400 | out: | |
401 | return status; | |
402 | } | |
403 | ||
9733f0d9 | 404 | static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, |
4aece6a1 | 405 | struct xdr_stream *xdr, |
f4dac4ad | 406 | void *argp) |
4aece6a1 | 407 | { |
f4dac4ad | 408 | struct cb_sequenceargs *args = argp; |
9733f0d9 | 409 | __be32 *p; |
4aece6a1 | 410 | int i; |
9733f0d9 | 411 | __be32 status; |
4aece6a1 BH |
412 | |
413 | status = decode_sessionid(xdr, &args->csa_sessionid); | |
414 | if (status) | |
1796549a | 415 | return status; |
4aece6a1 | 416 | |
4aece6a1 BH |
417 | p = read_buf(xdr, 5 * sizeof(uint32_t)); |
418 | if (unlikely(p == NULL)) | |
1796549a | 419 | return htonl(NFS4ERR_RESOURCE); |
4aece6a1 | 420 | |
65fc64e5 | 421 | args->csa_addr = svc_addr(rqstp); |
4aece6a1 BH |
422 | args->csa_sequenceid = ntohl(*p++); |
423 | args->csa_slotid = ntohl(*p++); | |
424 | args->csa_highestslotid = ntohl(*p++); | |
425 | args->csa_cachethis = ntohl(*p++); | |
426 | args->csa_nrclists = ntohl(*p++); | |
427 | args->csa_rclists = NULL; | |
428 | if (args->csa_nrclists) { | |
0439f31c DC |
429 | args->csa_rclists = kmalloc_array(args->csa_nrclists, |
430 | sizeof(*args->csa_rclists), | |
431 | GFP_KERNEL); | |
4aece6a1 | 432 | if (unlikely(args->csa_rclists == NULL)) |
1796549a | 433 | return htonl(NFS4ERR_RESOURCE); |
4aece6a1 BH |
434 | |
435 | for (i = 0; i < args->csa_nrclists; i++) { | |
436 | status = decode_rc_list(xdr, &args->csa_rclists[i]); | |
d8ba1f97 TM |
437 | if (status) { |
438 | args->csa_nrclists = i; | |
4aece6a1 | 439 | goto out_free; |
d8ba1f97 | 440 | } |
4aece6a1 BH |
441 | } |
442 | } | |
1796549a | 443 | return 0; |
4aece6a1 BH |
444 | |
445 | out_free: | |
446 | for (i = 0; i < args->csa_nrclists; i++) | |
447 | kfree(args->csa_rclists[i].rcl_refcalls); | |
448 | kfree(args->csa_rclists); | |
1796549a | 449 | return status; |
4aece6a1 BH |
450 | } |
451 | ||
9733f0d9 | 452 | static __be32 decode_recallany_args(struct svc_rqst *rqstp, |
31f09607 | 453 | struct xdr_stream *xdr, |
f4dac4ad | 454 | void *argp) |
31f09607 | 455 | { |
f4dac4ad | 456 | struct cb_recallanyargs *args = argp; |
d743c3c9 PT |
457 | uint32_t bitmap[2]; |
458 | __be32 *p, status; | |
31f09607 | 459 | |
31f09607 AB |
460 | p = read_buf(xdr, 4); |
461 | if (unlikely(p == NULL)) | |
462 | return htonl(NFS4ERR_BADXDR); | |
463 | args->craa_objs_to_keep = ntohl(*p++); | |
d743c3c9 PT |
464 | status = decode_bitmap(xdr, bitmap); |
465 | if (unlikely(status)) | |
466 | return status; | |
467 | args->craa_type_mask = bitmap[0]; | |
31f09607 AB |
468 | |
469 | return 0; | |
470 | } | |
471 | ||
9733f0d9 | 472 | static __be32 decode_recallslot_args(struct svc_rqst *rqstp, |
b9efa1b2 | 473 | struct xdr_stream *xdr, |
f4dac4ad | 474 | void *argp) |
b9efa1b2 | 475 | { |
f4dac4ad | 476 | struct cb_recallslotargs *args = argp; |
b9efa1b2 AA |
477 | __be32 *p; |
478 | ||
b9efa1b2 AA |
479 | p = read_buf(xdr, 4); |
480 | if (unlikely(p == NULL)) | |
481 | return htonl(NFS4ERR_BADXDR); | |
d5fb4ce3 | 482 | args->crsa_target_highest_slotid = ntohl(*p++); |
b9efa1b2 AA |
483 | return 0; |
484 | } | |
485 | ||
db783688 JL |
486 | static __be32 decode_lockowner(struct xdr_stream *xdr, struct cb_notify_lock_args *args) |
487 | { | |
488 | __be32 *p; | |
489 | unsigned int len; | |
490 | ||
491 | p = read_buf(xdr, 12); | |
492 | if (unlikely(p == NULL)) | |
493 | return htonl(NFS4ERR_BADXDR); | |
494 | ||
495 | p = xdr_decode_hyper(p, &args->cbnl_owner.clientid); | |
496 | len = be32_to_cpu(*p); | |
497 | ||
498 | p = read_buf(xdr, len); | |
499 | if (unlikely(p == NULL)) | |
500 | return htonl(NFS4ERR_BADXDR); | |
501 | ||
502 | /* Only try to decode if the length is right */ | |
503 | if (len == 20) { | |
504 | p += 2; /* skip "lock id:" */ | |
505 | args->cbnl_owner.s_dev = be32_to_cpu(*p++); | |
506 | xdr_decode_hyper(p, &args->cbnl_owner.id); | |
507 | args->cbnl_valid = true; | |
508 | } else { | |
509 | args->cbnl_owner.s_dev = 0; | |
510 | args->cbnl_owner.id = 0; | |
511 | args->cbnl_valid = false; | |
512 | } | |
513 | return 0; | |
514 | } | |
515 | ||
f4dac4ad CH |
516 | static __be32 decode_notify_lock_args(struct svc_rqst *rqstp, |
517 | struct xdr_stream *xdr, void *argp) | |
db783688 | 518 | { |
f4dac4ad | 519 | struct cb_notify_lock_args *args = argp; |
db783688 JL |
520 | __be32 status; |
521 | ||
522 | status = decode_fh(xdr, &args->cbnl_fh); | |
523 | if (unlikely(status != 0)) | |
535ece2b AS |
524 | return status; |
525 | return decode_lockowner(xdr, args); | |
db783688 JL |
526 | } |
527 | ||
4aece6a1 BH |
528 | #endif /* CONFIG_NFS_V4_1 */ |
529 | ||
e6f684f6 | 530 | static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) |
1da177e4 | 531 | { |
ab6e9aaf TM |
532 | if (unlikely(xdr_stream_encode_opaque(xdr, str, len) < 0)) |
533 | return cpu_to_be32(NFS4ERR_RESOURCE); | |
1da177e4 LT |
534 | return 0; |
535 | } | |
536 | ||
537 | #define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) | |
538 | #define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) | |
5704fdeb | 539 | static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep) |
1da177e4 | 540 | { |
5704fdeb AV |
541 | __be32 bm[2]; |
542 | __be32 *p; | |
1da177e4 LT |
543 | |
544 | bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0); | |
545 | bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1); | |
546 | if (bm[1] != 0) { | |
547 | p = xdr_reserve_space(xdr, 16); | |
548 | if (unlikely(p == NULL)) | |
549 | return htonl(NFS4ERR_RESOURCE); | |
550 | *p++ = htonl(2); | |
551 | *p++ = bm[0]; | |
552 | *p++ = bm[1]; | |
553 | } else if (bm[0] != 0) { | |
554 | p = xdr_reserve_space(xdr, 12); | |
555 | if (unlikely(p == NULL)) | |
556 | return htonl(NFS4ERR_RESOURCE); | |
557 | *p++ = htonl(1); | |
558 | *p++ = bm[0]; | |
559 | } else { | |
560 | p = xdr_reserve_space(xdr, 8); | |
561 | if (unlikely(p == NULL)) | |
562 | return htonl(NFS4ERR_RESOURCE); | |
563 | *p++ = htonl(0); | |
564 | } | |
565 | *savep = p; | |
566 | return 0; | |
567 | } | |
568 | ||
e6f684f6 | 569 | static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change) |
1da177e4 | 570 | { |
5704fdeb | 571 | __be32 *p; |
1da177e4 LT |
572 | |
573 | if (!(bitmap[0] & FATTR4_WORD0_CHANGE)) | |
574 | return 0; | |
575 | p = xdr_reserve_space(xdr, 8); | |
90dc7d27 | 576 | if (unlikely(!p)) |
1da177e4 LT |
577 | return htonl(NFS4ERR_RESOURCE); |
578 | p = xdr_encode_hyper(p, change); | |
579 | return 0; | |
580 | } | |
581 | ||
e6f684f6 | 582 | static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size) |
1da177e4 | 583 | { |
5704fdeb | 584 | __be32 *p; |
1da177e4 LT |
585 | |
586 | if (!(bitmap[0] & FATTR4_WORD0_SIZE)) | |
587 | return 0; | |
588 | p = xdr_reserve_space(xdr, 8); | |
90dc7d27 | 589 | if (unlikely(!p)) |
1da177e4 LT |
590 | return htonl(NFS4ERR_RESOURCE); |
591 | p = xdr_encode_hyper(p, size); | |
592 | return 0; | |
593 | } | |
594 | ||
e6f684f6 | 595 | static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec *time) |
1da177e4 | 596 | { |
5704fdeb | 597 | __be32 *p; |
1da177e4 LT |
598 | |
599 | p = xdr_reserve_space(xdr, 12); | |
90dc7d27 | 600 | if (unlikely(!p)) |
1da177e4 LT |
601 | return htonl(NFS4ERR_RESOURCE); |
602 | p = xdr_encode_hyper(p, time->tv_sec); | |
603 | *p = htonl(time->tv_nsec); | |
604 | return 0; | |
605 | } | |
606 | ||
e6f684f6 | 607 | static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time) |
1da177e4 LT |
608 | { |
609 | if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) | |
610 | return 0; | |
611 | return encode_attr_time(xdr,time); | |
612 | } | |
613 | ||
e6f684f6 | 614 | static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time) |
1da177e4 LT |
615 | { |
616 | if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) | |
617 | return 0; | |
618 | return encode_attr_time(xdr,time); | |
619 | } | |
620 | ||
e6f684f6 | 621 | static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr) |
1da177e4 | 622 | { |
e6f684f6 | 623 | __be32 status; |
1da177e4 LT |
624 | |
625 | hdr->status = xdr_reserve_space(xdr, 4); | |
626 | if (unlikely(hdr->status == NULL)) | |
627 | return htonl(NFS4ERR_RESOURCE); | |
628 | status = encode_string(xdr, hdr->taglen, hdr->tag); | |
629 | if (unlikely(status != 0)) | |
630 | return status; | |
631 | hdr->nops = xdr_reserve_space(xdr, 4); | |
632 | if (unlikely(hdr->nops == NULL)) | |
633 | return htonl(NFS4ERR_RESOURCE); | |
634 | return 0; | |
635 | } | |
636 | ||
e6f684f6 | 637 | static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res) |
1da177e4 | 638 | { |
5704fdeb | 639 | __be32 *p; |
1da177e4 LT |
640 | |
641 | p = xdr_reserve_space(xdr, 8); | |
642 | if (unlikely(p == NULL)) | |
31d2b435 | 643 | return htonl(NFS4ERR_RESOURCE_HDR); |
1da177e4 LT |
644 | *p++ = htonl(op); |
645 | *p = res; | |
646 | return 0; | |
647 | } | |
648 | ||
f4dac4ad CH |
649 | static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, |
650 | const void *resp) | |
1da177e4 | 651 | { |
f4dac4ad | 652 | const struct cb_getattrres *res = resp; |
5704fdeb | 653 | __be32 *savep = NULL; |
e6f684f6 | 654 | __be32 status = res->status; |
1da177e4 LT |
655 | |
656 | if (unlikely(status != 0)) | |
657 | goto out; | |
658 | status = encode_attr_bitmap(xdr, res->bitmap, &savep); | |
659 | if (unlikely(status != 0)) | |
660 | goto out; | |
661 | status = encode_attr_change(xdr, res->bitmap, res->change_attr); | |
662 | if (unlikely(status != 0)) | |
663 | goto out; | |
664 | status = encode_attr_size(xdr, res->bitmap, res->size); | |
665 | if (unlikely(status != 0)) | |
666 | goto out; | |
667 | status = encode_attr_ctime(xdr, res->bitmap, &res->ctime); | |
668 | if (unlikely(status != 0)) | |
669 | goto out; | |
670 | status = encode_attr_mtime(xdr, res->bitmap, &res->mtime); | |
671 | *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1))); | |
672 | out: | |
1da177e4 LT |
673 | return status; |
674 | } | |
675 | ||
34bc47c9 BH |
676 | #if defined(CONFIG_NFS_V4_1) |
677 | ||
9733f0d9 | 678 | static __be32 encode_sessionid(struct xdr_stream *xdr, |
4aece6a1 BH |
679 | const struct nfs4_sessionid *sid) |
680 | { | |
9733f0d9 | 681 | __be32 *p; |
4aece6a1 | 682 | |
590184a6 | 683 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 BH |
684 | if (unlikely(p == NULL)) |
685 | return htonl(NFS4ERR_RESOURCE); | |
686 | ||
590184a6 | 687 | memcpy(p, sid, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 BH |
688 | return 0; |
689 | } | |
690 | ||
9733f0d9 | 691 | static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp, |
4aece6a1 | 692 | struct xdr_stream *xdr, |
f4dac4ad | 693 | const void *resp) |
4aece6a1 | 694 | { |
f4dac4ad | 695 | const struct cb_sequenceres *res = resp; |
9733f0d9 | 696 | __be32 *p; |
e216c8c7 | 697 | __be32 status = res->csr_status; |
4aece6a1 BH |
698 | |
699 | if (unlikely(status != 0)) | |
3d0bfaa6 | 700 | return status; |
4aece6a1 | 701 | |
e0a63c0b KM |
702 | status = encode_sessionid(xdr, &res->csr_sessionid); |
703 | if (status) | |
3d0bfaa6 | 704 | return status; |
4aece6a1 BH |
705 | |
706 | p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t)); | |
707 | if (unlikely(p == NULL)) | |
708 | return htonl(NFS4ERR_RESOURCE); | |
709 | ||
710 | *p++ = htonl(res->csr_sequenceid); | |
711 | *p++ = htonl(res->csr_slotid); | |
712 | *p++ = htonl(res->csr_highestslotid); | |
713 | *p++ = htonl(res->csr_target_highestslotid); | |
3d0bfaa6 | 714 | return 0; |
4aece6a1 BH |
715 | } |
716 | ||
34bc47c9 BH |
717 | static __be32 |
718 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | |
719 | { | |
281fe15d BH |
720 | if (op_nr == OP_CB_SEQUENCE) { |
721 | if (nop != 0) | |
722 | return htonl(NFS4ERR_SEQUENCE_POS); | |
723 | } else { | |
724 | if (nop == 0) | |
725 | return htonl(NFS4ERR_OP_NOT_IN_SESSION); | |
726 | } | |
727 | ||
34bc47c9 BH |
728 | switch (op_nr) { |
729 | case OP_CB_GETATTR: | |
730 | case OP_CB_RECALL: | |
4aece6a1 | 731 | case OP_CB_SEQUENCE: |
31f09607 | 732 | case OP_CB_RECALL_ANY: |
b9efa1b2 | 733 | case OP_CB_RECALL_SLOT: |
f2a62561 | 734 | case OP_CB_LAYOUTRECALL: |
1be5683b | 735 | case OP_CB_NOTIFY_DEVICEID: |
db783688 | 736 | case OP_CB_NOTIFY_LOCK: |
34bc47c9 BH |
737 | *op = &callback_ops[op_nr]; |
738 | break; | |
739 | ||
34bc47c9 BH |
740 | case OP_CB_NOTIFY: |
741 | case OP_CB_PUSH_DELEG: | |
34bc47c9 | 742 | case OP_CB_RECALLABLE_OBJ_AVAIL: |
34bc47c9 | 743 | case OP_CB_WANTS_CANCELLED: |
34bc47c9 BH |
744 | return htonl(NFS4ERR_NOTSUPP); |
745 | ||
746 | default: | |
747 | return htonl(NFS4ERR_OP_ILLEGAL); | |
748 | } | |
749 | ||
750 | return htonl(NFS_OK); | |
751 | } | |
752 | ||
810d82e6 TM |
753 | static void nfs4_callback_free_slot(struct nfs4_session *session, |
754 | struct nfs4_slot *slot) | |
42acd021 AA |
755 | { |
756 | struct nfs4_slot_table *tbl = &session->bc_slot_table; | |
757 | ||
758 | spin_lock(&tbl->slot_tbl_lock); | |
759 | /* | |
760 | * Let the state manager know callback processing done. | |
761 | * A single slot, so highest used slotid is either 0 or -1 | |
762 | */ | |
810d82e6 | 763 | nfs4_free_slot(tbl, slot); |
42acd021 AA |
764 | spin_unlock(&tbl->slot_tbl_lock); |
765 | } | |
766 | ||
55a67399 | 767 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
42acd021 | 768 | { |
810d82e6 TM |
769 | if (cps->slot) { |
770 | nfs4_callback_free_slot(cps->clp->cl_session, cps->slot); | |
771 | cps->slot = NULL; | |
772 | } | |
42acd021 AA |
773 | } |
774 | ||
34bc47c9 BH |
775 | #else /* CONFIG_NFS_V4_1 */ |
776 | ||
777 | static __be32 | |
778 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | |
779 | { | |
780 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); | |
781 | } | |
782 | ||
55a67399 | 783 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
42acd021 AA |
784 | { |
785 | } | |
34bc47c9 BH |
786 | #endif /* CONFIG_NFS_V4_1 */ |
787 | ||
6b140b85 BS |
788 | #ifdef CONFIG_NFS_V4_2 |
789 | static __be32 | |
790 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) | |
791 | { | |
792 | __be32 status = preprocess_nfs41_op(nop, op_nr, op); | |
793 | if (status != htonl(NFS4ERR_OP_ILLEGAL)) | |
794 | return status; | |
795 | ||
796 | if (op_nr == OP_CB_OFFLOAD) | |
797 | return htonl(NFS4ERR_NOTSUPP); | |
798 | return htonl(NFS4ERR_OP_ILLEGAL); | |
799 | } | |
800 | #else /* CONFIG_NFS_V4_2 */ | |
801 | static __be32 | |
802 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) | |
803 | { | |
804 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); | |
805 | } | |
806 | #endif /* CONFIG_NFS_V4_2 */ | |
807 | ||
34bc47c9 BH |
808 | static __be32 |
809 | preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op) | |
810 | { | |
811 | switch (op_nr) { | |
812 | case OP_CB_GETATTR: | |
813 | case OP_CB_RECALL: | |
814 | *op = &callback_ops[op_nr]; | |
815 | break; | |
816 | default: | |
817 | return htonl(NFS4ERR_OP_ILLEGAL); | |
818 | } | |
819 | ||
820 | return htonl(NFS_OK); | |
821 | } | |
822 | ||
459de2ed | 823 | static __be32 process_op(int nop, struct svc_rqst *rqstp, |
1da177e4 | 824 | struct xdr_stream *xdr_in, void *argp, |
c36fca52 AA |
825 | struct xdr_stream *xdr_out, void *resp, |
826 | struct cb_process_state *cps) | |
1da177e4 | 827 | { |
a162a6b8 | 828 | struct callback_op *op = &callback_ops[0]; |
31d2b435 | 829 | unsigned int op_nr; |
34bc47c9 | 830 | __be32 status; |
1da177e4 | 831 | long maxlen; |
e6f684f6 | 832 | __be32 res; |
1da177e4 | 833 | |
1da177e4 | 834 | status = decode_op_hdr(xdr_in, &op_nr); |
31d2b435 AA |
835 | if (unlikely(status)) |
836 | return status; | |
1da177e4 | 837 | |
6b140b85 BS |
838 | switch (cps->minorversion) { |
839 | case 0: | |
840 | status = preprocess_nfs4_op(op_nr, &op); | |
841 | break; | |
842 | case 1: | |
843 | status = preprocess_nfs41_op(nop, op_nr, &op); | |
844 | break; | |
845 | case 2: | |
846 | status = preprocess_nfs42_op(nop, op_nr, &op); | |
847 | break; | |
848 | default: | |
849 | status = htonl(NFS4ERR_MINOR_VERS_MISMATCH); | |
850 | } | |
34bc47c9 | 851 | |
34bc47c9 BH |
852 | if (status == htonl(NFS4ERR_OP_ILLEGAL)) |
853 | op_nr = OP_CB_ILLEGAL; | |
b92b3019 AA |
854 | if (status) |
855 | goto encode_hdr; | |
31d2b435 | 856 | |
c36fca52 AA |
857 | if (cps->drc_status) { |
858 | status = cps->drc_status; | |
4911096f AA |
859 | goto encode_hdr; |
860 | } | |
861 | ||
1da177e4 LT |
862 | maxlen = xdr_out->end - xdr_out->p; |
863 | if (maxlen > 0 && maxlen < PAGE_SIZE) { | |
e95e60da AA |
864 | status = op->decode_args(rqstp, xdr_in, argp); |
865 | if (likely(status == 0)) | |
c36fca52 | 866 | status = op->process_op(argp, resp, cps); |
1da177e4 LT |
867 | } else |
868 | status = htonl(NFS4ERR_RESOURCE); | |
869 | ||
b92b3019 | 870 | encode_hdr: |
1da177e4 | 871 | res = encode_op_hdr(xdr_out, op_nr, status); |
31d2b435 AA |
872 | if (unlikely(res)) |
873 | return res; | |
1da177e4 LT |
874 | if (op->encode_res != NULL && status == 0) |
875 | status = op->encode_res(rqstp, xdr_out, resp); | |
1da177e4 LT |
876 | return status; |
877 | } | |
878 | ||
879 | /* | |
880 | * Decode, process and encode a COMPOUND | |
881 | */ | |
a6beb732 | 882 | static __be32 nfs4_callback_compound(struct svc_rqst *rqstp) |
1da177e4 | 883 | { |
3a6258e1 TM |
884 | struct cb_compound_hdr_arg hdr_arg = { 0 }; |
885 | struct cb_compound_hdr_res hdr_res = { NULL }; | |
1da177e4 | 886 | struct xdr_stream xdr_in, xdr_out; |
c36fca52 AA |
887 | __be32 *p, status; |
888 | struct cb_process_state cps = { | |
889 | .drc_status = 0, | |
890 | .clp = NULL, | |
9695c705 | 891 | .net = SVC_NET(rqstp), |
c36fca52 | 892 | }; |
3a6258e1 | 893 | unsigned int nops = 0; |
1da177e4 | 894 | |
756b9b37 | 895 | xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base); |
1da177e4 | 896 | |
5704fdeb | 897 | p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len); |
1da177e4 LT |
898 | xdr_init_encode(&xdr_out, &rqstp->rq_res, p); |
899 | ||
3a6258e1 | 900 | status = decode_compound_hdr_arg(&xdr_in, &hdr_arg); |
4ed0d83d | 901 | if (status == htonl(NFS4ERR_RESOURCE)) |
3a6258e1 TM |
902 | return rpc_garbage_args; |
903 | ||
c36fca52 | 904 | if (hdr_arg.minorversion == 0) { |
9695c705 | 905 | cps.clp = nfs4_find_client_ident(SVC_NET(rqstp), hdr_arg.cb_ident); |
778be232 | 906 | if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp)) |
a4e187d8 | 907 | goto out_invalidcred; |
778be232 | 908 | } |
c36fca52 | 909 | |
459de2ed | 910 | cps.minorversion = hdr_arg.minorversion; |
1da177e4 LT |
911 | hdr_res.taglen = hdr_arg.taglen; |
912 | hdr_res.tag = hdr_arg.tag; | |
3a6258e1 TM |
913 | if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0) |
914 | return rpc_system_err; | |
1da177e4 | 915 | |
3a6258e1 | 916 | while (status == 0 && nops != hdr_arg.nops) { |
459de2ed | 917 | status = process_op(nops, rqstp, &xdr_in, |
a6beb732 CH |
918 | rqstp->rq_argp, &xdr_out, rqstp->rq_resp, |
919 | &cps); | |
1da177e4 LT |
920 | nops++; |
921 | } | |
3a6258e1 | 922 | |
31d2b435 AA |
923 | /* Buffer overflow in decode_ops_hdr or encode_ops_hdr. Return |
924 | * resource error in cb_compound status without returning op */ | |
925 | if (unlikely(status == htonl(NFS4ERR_RESOURCE_HDR))) { | |
926 | status = htonl(NFS4ERR_RESOURCE); | |
927 | nops--; | |
928 | } | |
929 | ||
1da177e4 LT |
930 | *hdr_res.status = status; |
931 | *hdr_res.nops = htonl(nops); | |
55a67399 | 932 | nfs4_cb_free_slot(&cps); |
c36fca52 | 933 | nfs_put_client(cps.clp); |
1da177e4 | 934 | return rpc_success; |
a4e187d8 CL |
935 | |
936 | out_invalidcred: | |
937 | pr_warn_ratelimited("NFS: NFSv4 callback contains invalid cred\n"); | |
938 | return rpc_autherr_badcred; | |
1da177e4 LT |
939 | } |
940 | ||
941 | /* | |
942 | * Define NFS4 callback COMPOUND ops. | |
943 | */ | |
944 | static struct callback_op callback_ops[] = { | |
945 | [0] = { | |
946 | .res_maxsize = CB_OP_HDR_RES_MAXSZ, | |
947 | }, | |
948 | [OP_CB_GETATTR] = { | |
f4dac4ad CH |
949 | .process_op = nfs4_callback_getattr, |
950 | .decode_args = decode_getattr_args, | |
951 | .encode_res = encode_getattr_res, | |
1da177e4 LT |
952 | .res_maxsize = CB_OP_GETATTR_RES_MAXSZ, |
953 | }, | |
954 | [OP_CB_RECALL] = { | |
f4dac4ad CH |
955 | .process_op = nfs4_callback_recall, |
956 | .decode_args = decode_recall_args, | |
1da177e4 | 957 | .res_maxsize = CB_OP_RECALL_RES_MAXSZ, |
4aece6a1 BH |
958 | }, |
959 | #if defined(CONFIG_NFS_V4_1) | |
f2a62561 | 960 | [OP_CB_LAYOUTRECALL] = { |
f4dac4ad CH |
961 | .process_op = nfs4_callback_layoutrecall, |
962 | .decode_args = decode_layoutrecall_args, | |
f2a62561 FI |
963 | .res_maxsize = CB_OP_LAYOUTRECALL_RES_MAXSZ, |
964 | }, | |
1be5683b | 965 | [OP_CB_NOTIFY_DEVICEID] = { |
f4dac4ad CH |
966 | .process_op = nfs4_callback_devicenotify, |
967 | .decode_args = decode_devicenotify_args, | |
1be5683b ME |
968 | .res_maxsize = CB_OP_DEVICENOTIFY_RES_MAXSZ, |
969 | }, | |
4aece6a1 | 970 | [OP_CB_SEQUENCE] = { |
f4dac4ad CH |
971 | .process_op = nfs4_callback_sequence, |
972 | .decode_args = decode_cb_sequence_args, | |
973 | .encode_res = encode_cb_sequence_res, | |
4aece6a1 BH |
974 | .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ, |
975 | }, | |
31f09607 | 976 | [OP_CB_RECALL_ANY] = { |
f4dac4ad CH |
977 | .process_op = nfs4_callback_recallany, |
978 | .decode_args = decode_recallany_args, | |
31f09607 AB |
979 | .res_maxsize = CB_OP_RECALLANY_RES_MAXSZ, |
980 | }, | |
b9efa1b2 | 981 | [OP_CB_RECALL_SLOT] = { |
f4dac4ad CH |
982 | .process_op = nfs4_callback_recallslot, |
983 | .decode_args = decode_recallslot_args, | |
b9efa1b2 AA |
984 | .res_maxsize = CB_OP_RECALLSLOT_RES_MAXSZ, |
985 | }, | |
db783688 | 986 | [OP_CB_NOTIFY_LOCK] = { |
f4dac4ad CH |
987 | .process_op = nfs4_callback_notify_lock, |
988 | .decode_args = decode_notify_lock_args, | |
db783688 JL |
989 | .res_maxsize = CB_OP_NOTIFY_LOCK_RES_MAXSZ, |
990 | }, | |
4aece6a1 | 991 | #endif /* CONFIG_NFS_V4_1 */ |
1da177e4 LT |
992 | }; |
993 | ||
994 | /* | |
995 | * Define NFS4 callback procedures | |
996 | */ | |
860bda29 | 997 | static const struct svc_procedure nfs4_callback_procedures1[] = { |
1da177e4 LT |
998 | [CB_NULL] = { |
999 | .pc_func = nfs4_callback_null, | |
026fec7e | 1000 | .pc_decode = nfs4_decode_void, |
63f8de37 | 1001 | .pc_encode = nfs4_encode_void, |
1da177e4 LT |
1002 | .pc_xdrressize = 1, |
1003 | }, | |
1004 | [CB_COMPOUND] = { | |
1005 | .pc_func = nfs4_callback_compound, | |
63f8de37 | 1006 | .pc_encode = nfs4_encode_void, |
1da177e4 LT |
1007 | .pc_argsize = 256, |
1008 | .pc_ressize = 256, | |
1009 | .pc_xdrressize = NFS4_CALLBACK_BUFSIZE, | |
1010 | } | |
1011 | }; | |
1012 | ||
7fd38af9 | 1013 | static unsigned int nfs4_callback_count1[ARRAY_SIZE(nfs4_callback_procedures1)]; |
e9679189 | 1014 | const struct svc_version nfs4_callback_version1 = { |
1da177e4 LT |
1015 | .vs_vers = 1, |
1016 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), | |
1017 | .vs_proc = nfs4_callback_procedures1, | |
7fd38af9 | 1018 | .vs_count = nfs4_callback_count1, |
1da177e4 LT |
1019 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
1020 | .vs_dispatch = NULL, | |
05a45a2d | 1021 | .vs_hidden = true, |
5283b03e | 1022 | .vs_need_cong_ctrl = true, |
1da177e4 LT |
1023 | }; |
1024 | ||
7fd38af9 | 1025 | static unsigned int nfs4_callback_count4[ARRAY_SIZE(nfs4_callback_procedures1)]; |
e9679189 | 1026 | const struct svc_version nfs4_callback_version4 = { |
07bccc2d AB |
1027 | .vs_vers = 4, |
1028 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), | |
1029 | .vs_proc = nfs4_callback_procedures1, | |
7fd38af9 | 1030 | .vs_count = nfs4_callback_count4, |
07bccc2d AB |
1031 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
1032 | .vs_dispatch = NULL, | |
05a45a2d | 1033 | .vs_hidden = true, |
5283b03e | 1034 | .vs_need_cong_ctrl = true, |
07bccc2d | 1035 | }; |