callback_xdr.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. * linux/fs/nfs/callback_xdr.c
  3. *
  4. * Copyright (C) 2004 Trond Myklebust
  5. *
  6. * NFSv4 callback encode/decode procedures
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/sunrpc/svc.h>
  10. #include <linux/nfs4.h>
  11. #include <linux/nfs_fs.h>
  12. #include "nfs4_fs.h"
  13. #include "callback.h"
  14. #define CB_OP_TAGLEN_MAXSZ (512)
  15. #define CB_OP_HDR_RES_MAXSZ (2 + CB_OP_TAGLEN_MAXSZ)
  16. #define CB_OP_GETATTR_BITMAP_MAXSZ (4)
  17. #define CB_OP_GETATTR_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \
  18. CB_OP_GETATTR_BITMAP_MAXSZ + \
  19. 2 + 2 + 3 + 3)
  20. #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)
  21. #if defined(CONFIG_NFS_V4_1)
  22. #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \
  23. 4 + 1 + 3)
  24. #endif /* CONFIG_NFS_V4_1 */
  25. #define NFSDBG_FACILITY NFSDBG_CALLBACK
  26. typedef __be32 (*callback_process_op_t)(void *, void *);
  27. typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *);
  28. typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *);
  29. struct callback_op {
  30. callback_process_op_t process_op;
  31. callback_decode_arg_t decode_args;
  32. callback_encode_res_t encode_res;
  33. long res_maxsize;
  34. };
  35. static struct callback_op callback_ops[];
  36. static __be32 nfs4_callback_null(struct svc_rqst *rqstp, void *argp, void *resp)
  37. {
  38. return htonl(NFS4_OK);
  39. }
  40. static int nfs4_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  41. {
  42. return xdr_argsize_check(rqstp, p);
  43. }
  44. static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  45. {
  46. return xdr_ressize_check(rqstp, p);
  47. }
  48. static __be32 *read_buf(struct xdr_stream *xdr, int nbytes)
  49. {
  50. __be32 *p;
  51. p = xdr_inline_decode(xdr, nbytes);
  52. if (unlikely(p == NULL))
  53. printk(KERN_WARNING "NFSv4 callback reply buffer overflowed!\n");
  54. return p;
  55. }
  56. static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, const char **str)
  57. {
  58. __be32 *p;
  59. p = read_buf(xdr, 4);
  60. if (unlikely(p == NULL))
  61. return htonl(NFS4ERR_RESOURCE);
  62. *len = ntohl(*p);
  63. if (*len != 0) {
  64. p = read_buf(xdr, *len);
  65. if (unlikely(p == NULL))
  66. return htonl(NFS4ERR_RESOURCE);
  67. *str = (const char *)p;
  68. } else
  69. *str = NULL;
  70. return 0;
  71. }
  72. static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
  73. {
  74. __be32 *p;
  75. p = read_buf(xdr, 4);
  76. if (unlikely(p == NULL))
  77. return htonl(NFS4ERR_RESOURCE);
  78. fh->size = ntohl(*p);
  79. if (fh->size > NFS4_FHSIZE)
  80. return htonl(NFS4ERR_BADHANDLE);
  81. p = read_buf(xdr, fh->size);
  82. if (unlikely(p == NULL))
  83. return htonl(NFS4ERR_RESOURCE);
  84. memcpy(&fh->data[0], p, fh->size);
  85. memset(&fh->data[fh->size], 0, sizeof(fh->data) - fh->size);
  86. return 0;
  87. }
  88. static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  89. {
  90. __be32 *p;
  91. unsigned int attrlen;
  92. p = read_buf(xdr, 4);
  93. if (unlikely(p == NULL))
  94. return htonl(NFS4ERR_RESOURCE);
  95. attrlen = ntohl(*p);
  96. p = read_buf(xdr, attrlen << 2);
  97. if (unlikely(p == NULL))
  98. return htonl(NFS4ERR_RESOURCE);
  99. if (likely(attrlen > 0))
  100. bitmap[0] = ntohl(*p++);
  101. if (attrlen > 1)
  102. bitmap[1] = ntohl(*p);
  103. return 0;
  104. }
  105. static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  106. {
  107. __be32 *p;
  108. p = read_buf(xdr, 16);
  109. if (unlikely(p == NULL))
  110. return htonl(NFS4ERR_RESOURCE);
  111. memcpy(stateid->data, p, 16);
  112. return 0;
  113. }
  114. static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
  115. {
  116. __be32 *p;
  117. __be32 status;
  118. status = decode_string(xdr, &hdr->taglen, &hdr->tag);
  119. if (unlikely(status != 0))
  120. return status;
  121. /* We do not like overly long tags! */
  122. if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
  123. printk("NFSv4 CALLBACK %s: client sent tag of length %u\n",
  124. __func__, hdr->taglen);
  125. return htonl(NFS4ERR_RESOURCE);
  126. }
  127. p = read_buf(xdr, 12);
  128. if (unlikely(p == NULL))
  129. return htonl(NFS4ERR_RESOURCE);
  130. hdr->minorversion = ntohl(*p++);
  131. /* Check minor version is zero or one. */
  132. if (hdr->minorversion <= 1) {
  133. p++; /* skip callback_ident */
  134. } else {
  135. printk(KERN_WARNING "%s: NFSv4 server callback with "
  136. "illegal minor version %u!\n",
  137. __func__, hdr->minorversion);
  138. return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
  139. }
  140. hdr->nops = ntohl(*p);
  141. dprintk("%s: minorversion %d nops %d\n", __func__,
  142. hdr->minorversion, hdr->nops);
  143. return 0;
  144. }
  145. static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op)
  146. {
  147. __be32 *p;
  148. p = read_buf(xdr, 4);
  149. if (unlikely(p == NULL))
  150. return htonl(NFS4ERR_RESOURCE);
  151. *op = ntohl(*p);
  152. return 0;
  153. }
  154. static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args)
  155. {
  156. __be32 status;
  157. status = decode_fh(xdr, &args->fh);
  158. if (unlikely(status != 0))
  159. goto out;
  160. args->addr = svc_addr(rqstp);
  161. status = decode_bitmap(xdr, args->bitmap);
  162. out:
  163. dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
  164. return status;
  165. }
  166. static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallargs *args)
  167. {
  168. __be32 *p;
  169. __be32 status;
  170. args->addr = svc_addr(rqstp);
  171. status = decode_stateid(xdr, &args->stateid);
  172. if (unlikely(status != 0))
  173. goto out;
  174. p = read_buf(xdr, 4);
  175. if (unlikely(p == NULL)) {
  176. status = htonl(NFS4ERR_RESOURCE);
  177. goto out;
  178. }
  179. args->truncate = ntohl(*p);
  180. status = decode_fh(xdr, &args->fh);
  181. out:
  182. dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
  183. return status;
  184. }
  185. #if defined(CONFIG_NFS_V4_1)
  186. static unsigned decode_sessionid(struct xdr_stream *xdr,
  187. struct nfs4_sessionid *sid)
  188. {
  189. uint32_t *p;
  190. int len = NFS4_MAX_SESSIONID_LEN;
  191. p = read_buf(xdr, len);
  192. if (unlikely(p == NULL))
  193. return htonl(NFS4ERR_RESOURCE);;
  194. memcpy(sid->data, p, len);
  195. return 0;
  196. }
  197. static unsigned decode_rc_list(struct xdr_stream *xdr,
  198. struct referring_call_list *rc_list)
  199. {
  200. uint32_t *p;
  201. int i;
  202. unsigned status;
  203. status = decode_sessionid(xdr, &rc_list->rcl_sessionid);
  204. if (status)
  205. goto out;
  206. status = htonl(NFS4ERR_RESOURCE);
  207. p = read_buf(xdr, sizeof(uint32_t));
  208. if (unlikely(p == NULL))
  209. goto out;
  210. rc_list->rcl_nrefcalls = ntohl(*p++);
  211. if (rc_list->rcl_nrefcalls) {
  212. p = read_buf(xdr,
  213. rc_list->rcl_nrefcalls * 2 * sizeof(uint32_t));
  214. if (unlikely(p == NULL))
  215. goto out;
  216. rc_list->rcl_refcalls = kmalloc(rc_list->rcl_nrefcalls *
  217. sizeof(*rc_list->rcl_refcalls),
  218. GFP_KERNEL);
  219. if (unlikely(rc_list->rcl_refcalls == NULL))
  220. goto out;
  221. for (i = 0; i < rc_list->rcl_nrefcalls; i++) {
  222. rc_list->rcl_refcalls[i].rc_sequenceid = ntohl(*p++);
  223. rc_list->rcl_refcalls[i].rc_slotid = ntohl(*p++);
  224. }
  225. }
  226. status = 0;
  227. out:
  228. return status;
  229. }
  230. static unsigned decode_cb_sequence_args(struct svc_rqst *rqstp,
  231. struct xdr_stream *xdr,
  232. struct cb_sequenceargs *args)
  233. {
  234. uint32_t *p;
  235. int i;
  236. unsigned status;
  237. status = decode_sessionid(xdr, &args->csa_sessionid);
  238. if (status)
  239. goto out;
  240. status = htonl(NFS4ERR_RESOURCE);
  241. p = read_buf(xdr, 5 * sizeof(uint32_t));
  242. if (unlikely(p == NULL))
  243. goto out;
  244. args->csa_addr = svc_addr(rqstp);
  245. args->csa_sequenceid = ntohl(*p++);
  246. args->csa_slotid = ntohl(*p++);
  247. args->csa_highestslotid = ntohl(*p++);
  248. args->csa_cachethis = ntohl(*p++);
  249. args->csa_nrclists = ntohl(*p++);
  250. args->csa_rclists = NULL;
  251. if (args->csa_nrclists) {
  252. args->csa_rclists = kmalloc(args->csa_nrclists *
  253. sizeof(*args->csa_rclists),
  254. GFP_KERNEL);
  255. if (unlikely(args->csa_rclists == NULL))
  256. goto out;
  257. for (i = 0; i < args->csa_nrclists; i++) {
  258. status = decode_rc_list(xdr, &args->csa_rclists[i]);
  259. if (status)
  260. goto out_free;
  261. }
  262. }
  263. status = 0;
  264. dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u slotid %u "
  265. "highestslotid %u cachethis %d nrclists %u\n",
  266. __func__,
  267. ((u32 *)&args->csa_sessionid)[0],
  268. ((u32 *)&args->csa_sessionid)[1],
  269. ((u32 *)&args->csa_sessionid)[2],
  270. ((u32 *)&args->csa_sessionid)[3],
  271. args->csa_sequenceid, args->csa_slotid,
  272. args->csa_highestslotid, args->csa_cachethis,
  273. args->csa_nrclists);
  274. out:
  275. dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
  276. return status;
  277. out_free:
  278. for (i = 0; i < args->csa_nrclists; i++)
  279. kfree(args->csa_rclists[i].rcl_refcalls);
  280. kfree(args->csa_rclists);
  281. goto out;
  282. }
  283. #endif /* CONFIG_NFS_V4_1 */
  284. static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  285. {
  286. __be32 *p;
  287. p = xdr_reserve_space(xdr, 4 + len);
  288. if (unlikely(p == NULL))
  289. return htonl(NFS4ERR_RESOURCE);
  290. xdr_encode_opaque(p, str, len);
  291. return 0;
  292. }
  293. #define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE)
  294. #define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY)
  295. static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep)
  296. {
  297. __be32 bm[2];
  298. __be32 *p;
  299. bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0);
  300. bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1);
  301. if (bm[1] != 0) {
  302. p = xdr_reserve_space(xdr, 16);
  303. if (unlikely(p == NULL))
  304. return htonl(NFS4ERR_RESOURCE);
  305. *p++ = htonl(2);
  306. *p++ = bm[0];
  307. *p++ = bm[1];
  308. } else if (bm[0] != 0) {
  309. p = xdr_reserve_space(xdr, 12);
  310. if (unlikely(p == NULL))
  311. return htonl(NFS4ERR_RESOURCE);
  312. *p++ = htonl(1);
  313. *p++ = bm[0];
  314. } else {
  315. p = xdr_reserve_space(xdr, 8);
  316. if (unlikely(p == NULL))
  317. return htonl(NFS4ERR_RESOURCE);
  318. *p++ = htonl(0);
  319. }
  320. *savep = p;
  321. return 0;
  322. }
  323. static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change)
  324. {
  325. __be32 *p;
  326. if (!(bitmap[0] & FATTR4_WORD0_CHANGE))
  327. return 0;
  328. p = xdr_reserve_space(xdr, 8);
  329. if (unlikely(!p))
  330. return htonl(NFS4ERR_RESOURCE);
  331. p = xdr_encode_hyper(p, change);
  332. return 0;
  333. }
  334. static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size)
  335. {
  336. __be32 *p;
  337. if (!(bitmap[0] & FATTR4_WORD0_SIZE))
  338. return 0;
  339. p = xdr_reserve_space(xdr, 8);
  340. if (unlikely(!p))
  341. return htonl(NFS4ERR_RESOURCE);
  342. p = xdr_encode_hyper(p, size);
  343. return 0;
  344. }
  345. static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec *time)
  346. {
  347. __be32 *p;
  348. p = xdr_reserve_space(xdr, 12);
  349. if (unlikely(!p))
  350. return htonl(NFS4ERR_RESOURCE);
  351. p = xdr_encode_hyper(p, time->tv_sec);
  352. *p = htonl(time->tv_nsec);
  353. return 0;
  354. }
  355. static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
  356. {
  357. if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA))
  358. return 0;
  359. return encode_attr_time(xdr,time);
  360. }
  361. static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
  362. {
  363. if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY))
  364. return 0;
  365. return encode_attr_time(xdr,time);
  366. }
  367. static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr)
  368. {
  369. __be32 status;
  370. hdr->status = xdr_reserve_space(xdr, 4);
  371. if (unlikely(hdr->status == NULL))
  372. return htonl(NFS4ERR_RESOURCE);
  373. status = encode_string(xdr, hdr->taglen, hdr->tag);
  374. if (unlikely(status != 0))
  375. return status;
  376. hdr->nops = xdr_reserve_space(xdr, 4);
  377. if (unlikely(hdr->nops == NULL))
  378. return htonl(NFS4ERR_RESOURCE);
  379. return 0;
  380. }
  381. static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res)
  382. {
  383. __be32 *p;
  384. p = xdr_reserve_space(xdr, 8);
  385. if (unlikely(p == NULL))
  386. return htonl(NFS4ERR_RESOURCE);
  387. *p++ = htonl(op);
  388. *p = res;
  389. return 0;
  390. }
  391. static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_getattrres *res)
  392. {
  393. __be32 *savep = NULL;
  394. __be32 status = res->status;
  395. if (unlikely(status != 0))
  396. goto out;
  397. status = encode_attr_bitmap(xdr, res->bitmap, &savep);
  398. if (unlikely(status != 0))
  399. goto out;
  400. status = encode_attr_change(xdr, res->bitmap, res->change_attr);
  401. if (unlikely(status != 0))
  402. goto out;
  403. status = encode_attr_size(xdr, res->bitmap, res->size);
  404. if (unlikely(status != 0))
  405. goto out;
  406. status = encode_attr_ctime(xdr, res->bitmap, &res->ctime);
  407. if (unlikely(status != 0))
  408. goto out;
  409. status = encode_attr_mtime(xdr, res->bitmap, &res->mtime);
  410. *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1)));
  411. out:
  412. dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
  413. return status;
  414. }
  415. #if defined(CONFIG_NFS_V4_1)
  416. static unsigned encode_sessionid(struct xdr_stream *xdr,
  417. const struct nfs4_sessionid *sid)
  418. {
  419. uint32_t *p;
  420. int len = NFS4_MAX_SESSIONID_LEN;
  421. p = xdr_reserve_space(xdr, len);
  422. if (unlikely(p == NULL))
  423. return htonl(NFS4ERR_RESOURCE);
  424. memcpy(p, sid, len);
  425. return 0;
  426. }
  427. static unsigned encode_cb_sequence_res(struct svc_rqst *rqstp,
  428. struct xdr_stream *xdr,
  429. const struct cb_sequenceres *res)
  430. {
  431. uint32_t *p;
  432. unsigned status = res->csr_status;
  433. if (unlikely(status != 0))
  434. goto out;
  435. encode_sessionid(xdr, &res->csr_sessionid);
  436. p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t));
  437. if (unlikely(p == NULL))
  438. return htonl(NFS4ERR_RESOURCE);
  439. *p++ = htonl(res->csr_sequenceid);
  440. *p++ = htonl(res->csr_slotid);
  441. *p++ = htonl(res->csr_highestslotid);
  442. *p++ = htonl(res->csr_target_highestslotid);
  443. out:
  444. dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
  445. return status;
  446. }
  447. static __be32
  448. preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
  449. {
  450. if (op_nr == OP_CB_SEQUENCE) {
  451. if (nop != 0)
  452. return htonl(NFS4ERR_SEQUENCE_POS);
  453. } else {
  454. if (nop == 0)
  455. return htonl(NFS4ERR_OP_NOT_IN_SESSION);
  456. }
  457. switch (op_nr) {
  458. case OP_CB_GETATTR:
  459. case OP_CB_RECALL:
  460. case OP_CB_SEQUENCE:
  461. *op = &callback_ops[op_nr];
  462. break;
  463. case OP_CB_LAYOUTRECALL:
  464. case OP_CB_NOTIFY_DEVICEID:
  465. case OP_CB_NOTIFY:
  466. case OP_CB_PUSH_DELEG:
  467. case OP_CB_RECALL_ANY:
  468. case OP_CB_RECALLABLE_OBJ_AVAIL:
  469. case OP_CB_RECALL_SLOT:
  470. case OP_CB_WANTS_CANCELLED:
  471. case OP_CB_NOTIFY_LOCK:
  472. return htonl(NFS4ERR_NOTSUPP);
  473. default:
  474. return htonl(NFS4ERR_OP_ILLEGAL);
  475. }
  476. return htonl(NFS_OK);
  477. }
  478. #else /* CONFIG_NFS_V4_1 */
  479. static __be32
  480. preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op)
  481. {
  482. return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
  483. }
  484. #endif /* CONFIG_NFS_V4_1 */
  485. static __be32
  486. preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op)
  487. {
  488. switch (op_nr) {
  489. case OP_CB_GETATTR:
  490. case OP_CB_RECALL:
  491. *op = &callback_ops[op_nr];
  492. break;
  493. default:
  494. return htonl(NFS4ERR_OP_ILLEGAL);
  495. }
  496. return htonl(NFS_OK);
  497. }
  498. static __be32 process_op(uint32_t minorversion, int nop,
  499. struct svc_rqst *rqstp,
  500. struct xdr_stream *xdr_in, void *argp,
  501. struct xdr_stream *xdr_out, void *resp)
  502. {
  503. struct callback_op *op = &callback_ops[0];
  504. unsigned int op_nr = OP_CB_ILLEGAL;
  505. __be32 status;
  506. long maxlen;
  507. __be32 res;
  508. dprintk("%s: start\n", __func__);
  509. status = decode_op_hdr(xdr_in, &op_nr);
  510. if (unlikely(status)) {
  511. status = htonl(NFS4ERR_OP_ILLEGAL);
  512. goto out;
  513. }
  514. dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
  515. __func__, minorversion, nop, op_nr);
  516. status = minorversion ? preprocess_nfs41_op(nop, op_nr, &op) :
  517. preprocess_nfs4_op(op_nr, &op);
  518. if (status == htonl(NFS4ERR_OP_ILLEGAL))
  519. op_nr = OP_CB_ILLEGAL;
  520. out:
  521. maxlen = xdr_out->end - xdr_out->p;
  522. if (maxlen > 0 && maxlen < PAGE_SIZE) {
  523. if (likely(status == 0 && op->decode_args != NULL))
  524. status = op->decode_args(rqstp, xdr_in, argp);
  525. if (likely(status == 0 && op->process_op != NULL))
  526. status = op->process_op(argp, resp);
  527. } else
  528. status = htonl(NFS4ERR_RESOURCE);
  529. res = encode_op_hdr(xdr_out, op_nr, status);
  530. if (status == 0)
  531. status = res;
  532. if (op->encode_res != NULL && status == 0)
  533. status = op->encode_res(rqstp, xdr_out, resp);
  534. dprintk("%s: done, status = %d\n", __func__, ntohl(status));
  535. return status;
  536. }
  537. /*
  538. * Decode, process and encode a COMPOUND
  539. */
  540. static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *resp)
  541. {
  542. struct cb_compound_hdr_arg hdr_arg = { 0 };
  543. struct cb_compound_hdr_res hdr_res = { NULL };
  544. struct xdr_stream xdr_in, xdr_out;
  545. __be32 *p;
  546. __be32 status;
  547. unsigned int nops = 0;
  548. dprintk("%s: start\n", __func__);
  549. xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base);
  550. p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len);
  551. xdr_init_encode(&xdr_out, &rqstp->rq_res, p);
  552. status = decode_compound_hdr_arg(&xdr_in, &hdr_arg);
  553. if (status == __constant_htonl(NFS4ERR_RESOURCE))
  554. return rpc_garbage_args;
  555. hdr_res.taglen = hdr_arg.taglen;
  556. hdr_res.tag = hdr_arg.tag;
  557. if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0)
  558. return rpc_system_err;
  559. while (status == 0 && nops != hdr_arg.nops) {
  560. status = process_op(hdr_arg.minorversion, nops,
  561. rqstp, &xdr_in, argp, &xdr_out, resp);
  562. nops++;
  563. }
  564. *hdr_res.status = status;
  565. *hdr_res.nops = htonl(nops);
  566. dprintk("%s: done, status = %u\n", __func__, ntohl(status));
  567. return rpc_success;
  568. }
  569. /*
  570. * Define NFS4 callback COMPOUND ops.
  571. */
  572. static struct callback_op callback_ops[] = {
  573. [0] = {
  574. .res_maxsize = CB_OP_HDR_RES_MAXSZ,
  575. },
  576. [OP_CB_GETATTR] = {
  577. .process_op = (callback_process_op_t)nfs4_callback_getattr,
  578. .decode_args = (callback_decode_arg_t)decode_getattr_args,
  579. .encode_res = (callback_encode_res_t)encode_getattr_res,
  580. .res_maxsize = CB_OP_GETATTR_RES_MAXSZ,
  581. },
  582. [OP_CB_RECALL] = {
  583. .process_op = (callback_process_op_t)nfs4_callback_recall,
  584. .decode_args = (callback_decode_arg_t)decode_recall_args,
  585. .res_maxsize = CB_OP_RECALL_RES_MAXSZ,
  586. },
  587. #if defined(CONFIG_NFS_V4_1)
  588. [OP_CB_SEQUENCE] = {
  589. .process_op = (callback_process_op_t)nfs4_callback_sequence,
  590. .decode_args = (callback_decode_arg_t)decode_cb_sequence_args,
  591. .encode_res = (callback_encode_res_t)encode_cb_sequence_res,
  592. .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ,
  593. },
  594. #endif /* CONFIG_NFS_V4_1 */
  595. };
  596. /*
  597. * Define NFS4 callback procedures
  598. */
  599. static struct svc_procedure nfs4_callback_procedures1[] = {
  600. [CB_NULL] = {
  601. .pc_func = nfs4_callback_null,
  602. .pc_decode = (kxdrproc_t)nfs4_decode_void,
  603. .pc_encode = (kxdrproc_t)nfs4_encode_void,
  604. .pc_xdrressize = 1,
  605. },
  606. [CB_COMPOUND] = {
  607. .pc_func = nfs4_callback_compound,
  608. .pc_encode = (kxdrproc_t)nfs4_encode_void,
  609. .pc_argsize = 256,
  610. .pc_ressize = 256,
  611. .pc_xdrressize = NFS4_CALLBACK_BUFSIZE,
  612. }
  613. };
  614. struct svc_version nfs4_callback_version1 = {
  615. .vs_vers = 1,
  616. .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1),
  617. .vs_proc = nfs4_callback_procedures1,
  618. .vs_xdrsize = NFS4_CALLBACK_XDRSIZE,
  619. .vs_dispatch = NULL,
  620. };