nfs42xdr.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
  3. */
  4. #ifndef __LINUX_FS_NFS_NFS4_2XDR_H
  5. #define __LINUX_FS_NFS_NFS4_2XDR_H
  6. #include "nfs42.h"
  7. #define encode_fallocate_maxsz (encode_stateid_maxsz + \
  8. 2 /* offset */ + \
  9. 2 /* length */)
  10. #define NFS42_WRITE_RES_SIZE (1 /* wr_callback_id size */ +\
  11. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  12. 2 /* wr_count */ + \
  13. 1 /* wr_committed */ + \
  14. XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  15. #define encode_allocate_maxsz (op_encode_hdr_maxsz + \
  16. encode_fallocate_maxsz)
  17. #define decode_allocate_maxsz (op_decode_hdr_maxsz)
  18. #define encode_copy_maxsz (op_encode_hdr_maxsz + \
  19. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  20. XDR_QUADLEN(NFS4_STATEID_SIZE) + \
  21. 2 + 2 + 2 + 1 + 1 + 1)
  22. #define decode_copy_maxsz (op_decode_hdr_maxsz + \
  23. NFS42_WRITE_RES_SIZE + \
  24. 1 /* cr_consecutive */ + \
  25. 1 /* cr_synchronous */)
  26. #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
  27. encode_fallocate_maxsz)
  28. #define decode_deallocate_maxsz (op_decode_hdr_maxsz)
  29. #define encode_seek_maxsz (op_encode_hdr_maxsz + \
  30. encode_stateid_maxsz + \
  31. 2 /* offset */ + \
  32. 1 /* whence */)
  33. #define decode_seek_maxsz (op_decode_hdr_maxsz + \
  34. 1 /* eof */ + \
  35. 1 /* whence */ + \
  36. 2 /* offset */ + \
  37. 2 /* length */)
  38. #define encode_io_info_maxsz 4
  39. #define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \
  40. 2 /* offset */ + \
  41. 2 /* length */ + \
  42. encode_stateid_maxsz + \
  43. encode_io_info_maxsz + \
  44. encode_io_info_maxsz + \
  45. 1 /* opaque devaddr4 length */ + \
  46. XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE))
  47. #define decode_layoutstats_maxsz (op_decode_hdr_maxsz)
  48. #define encode_clone_maxsz (encode_stateid_maxsz + \
  49. encode_stateid_maxsz + \
  50. 2 /* src offset */ + \
  51. 2 /* dst offset */ + \
  52. 2 /* count */)
  53. #define decode_clone_maxsz (op_decode_hdr_maxsz)
  54. #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
  55. encode_putfh_maxsz + \
  56. encode_allocate_maxsz + \
  57. encode_getattr_maxsz)
  58. #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
  59. decode_putfh_maxsz + \
  60. decode_allocate_maxsz + \
  61. decode_getattr_maxsz)
  62. #define NFS4_enc_copy_sz (compound_encode_hdr_maxsz + \
  63. encode_putfh_maxsz + \
  64. encode_savefh_maxsz + \
  65. encode_putfh_maxsz + \
  66. encode_copy_maxsz)
  67. #define NFS4_dec_copy_sz (compound_decode_hdr_maxsz + \
  68. decode_putfh_maxsz + \
  69. decode_savefh_maxsz + \
  70. decode_putfh_maxsz + \
  71. decode_copy_maxsz)
  72. #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
  73. encode_putfh_maxsz + \
  74. encode_deallocate_maxsz + \
  75. encode_getattr_maxsz)
  76. #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
  77. decode_putfh_maxsz + \
  78. decode_deallocate_maxsz + \
  79. decode_getattr_maxsz)
  80. #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
  81. encode_putfh_maxsz + \
  82. encode_seek_maxsz)
  83. #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
  84. decode_putfh_maxsz + \
  85. decode_seek_maxsz)
  86. #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
  87. encode_sequence_maxsz + \
  88. encode_putfh_maxsz + \
  89. PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
  90. #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
  91. decode_sequence_maxsz + \
  92. decode_putfh_maxsz + \
  93. PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
  94. #define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \
  95. encode_sequence_maxsz + \
  96. encode_putfh_maxsz + \
  97. encode_savefh_maxsz + \
  98. encode_putfh_maxsz + \
  99. encode_clone_maxsz + \
  100. encode_getattr_maxsz)
  101. #define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \
  102. decode_sequence_maxsz + \
  103. decode_putfh_maxsz + \
  104. decode_savefh_maxsz + \
  105. decode_putfh_maxsz + \
  106. decode_clone_maxsz + \
  107. decode_getattr_maxsz)
  108. static void encode_fallocate(struct xdr_stream *xdr,
  109. struct nfs42_falloc_args *args)
  110. {
  111. encode_nfs4_stateid(xdr, &args->falloc_stateid);
  112. encode_uint64(xdr, args->falloc_offset);
  113. encode_uint64(xdr, args->falloc_length);
  114. }
  115. static void encode_allocate(struct xdr_stream *xdr,
  116. struct nfs42_falloc_args *args,
  117. struct compound_hdr *hdr)
  118. {
  119. encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
  120. encode_fallocate(xdr, args);
  121. }
  122. static void encode_copy(struct xdr_stream *xdr,
  123. struct nfs42_copy_args *args,
  124. struct compound_hdr *hdr)
  125. {
  126. encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr);
  127. encode_nfs4_stateid(xdr, &args->src_stateid);
  128. encode_nfs4_stateid(xdr, &args->dst_stateid);
  129. encode_uint64(xdr, args->src_pos);
  130. encode_uint64(xdr, args->dst_pos);
  131. encode_uint64(xdr, args->count);
  132. encode_uint32(xdr, 1); /* consecutive = true */
  133. encode_uint32(xdr, 1); /* synchronous = true */
  134. encode_uint32(xdr, 0); /* src server list */
  135. }
  136. static void encode_deallocate(struct xdr_stream *xdr,
  137. struct nfs42_falloc_args *args,
  138. struct compound_hdr *hdr)
  139. {
  140. encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
  141. encode_fallocate(xdr, args);
  142. }
  143. static void encode_seek(struct xdr_stream *xdr,
  144. struct nfs42_seek_args *args,
  145. struct compound_hdr *hdr)
  146. {
  147. encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
  148. encode_nfs4_stateid(xdr, &args->sa_stateid);
  149. encode_uint64(xdr, args->sa_offset);
  150. encode_uint32(xdr, args->sa_what);
  151. }
  152. static void encode_layoutstats(struct xdr_stream *xdr,
  153. struct nfs42_layoutstat_args *args,
  154. struct nfs42_layoutstat_devinfo *devinfo,
  155. struct compound_hdr *hdr)
  156. {
  157. __be32 *p;
  158. encode_op_hdr(xdr, OP_LAYOUTSTATS, decode_layoutstats_maxsz, hdr);
  159. p = reserve_space(xdr, 8 + 8);
  160. p = xdr_encode_hyper(p, devinfo->offset);
  161. p = xdr_encode_hyper(p, devinfo->length);
  162. encode_nfs4_stateid(xdr, &args->stateid);
  163. p = reserve_space(xdr, 4*8 + NFS4_DEVICEID4_SIZE + 4);
  164. p = xdr_encode_hyper(p, devinfo->read_count);
  165. p = xdr_encode_hyper(p, devinfo->read_bytes);
  166. p = xdr_encode_hyper(p, devinfo->write_count);
  167. p = xdr_encode_hyper(p, devinfo->write_bytes);
  168. p = xdr_encode_opaque_fixed(p, devinfo->dev_id.data,
  169. NFS4_DEVICEID4_SIZE);
  170. /* Encode layoutupdate4 */
  171. *p++ = cpu_to_be32(devinfo->layout_type);
  172. if (devinfo->layoutstats_encode != NULL)
  173. devinfo->layoutstats_encode(xdr, args, devinfo);
  174. else
  175. encode_uint32(xdr, 0);
  176. }
  177. static void encode_clone(struct xdr_stream *xdr,
  178. struct nfs42_clone_args *args,
  179. struct compound_hdr *hdr)
  180. {
  181. __be32 *p;
  182. encode_op_hdr(xdr, OP_CLONE, decode_clone_maxsz, hdr);
  183. encode_nfs4_stateid(xdr, &args->src_stateid);
  184. encode_nfs4_stateid(xdr, &args->dst_stateid);
  185. p = reserve_space(xdr, 3*8);
  186. p = xdr_encode_hyper(p, args->src_offset);
  187. p = xdr_encode_hyper(p, args->dst_offset);
  188. xdr_encode_hyper(p, args->count);
  189. }
  190. /*
  191. * Encode ALLOCATE request
  192. */
  193. static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
  194. struct xdr_stream *xdr,
  195. struct nfs42_falloc_args *args)
  196. {
  197. struct compound_hdr hdr = {
  198. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  199. };
  200. encode_compound_hdr(xdr, req, &hdr);
  201. encode_sequence(xdr, &args->seq_args, &hdr);
  202. encode_putfh(xdr, args->falloc_fh, &hdr);
  203. encode_allocate(xdr, args, &hdr);
  204. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  205. encode_nops(&hdr);
  206. }
  207. /*
  208. * Encode COPY request
  209. */
  210. static void nfs4_xdr_enc_copy(struct rpc_rqst *req,
  211. struct xdr_stream *xdr,
  212. struct nfs42_copy_args *args)
  213. {
  214. struct compound_hdr hdr = {
  215. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  216. };
  217. encode_compound_hdr(xdr, req, &hdr);
  218. encode_sequence(xdr, &args->seq_args, &hdr);
  219. encode_putfh(xdr, args->src_fh, &hdr);
  220. encode_savefh(xdr, &hdr);
  221. encode_putfh(xdr, args->dst_fh, &hdr);
  222. encode_copy(xdr, args, &hdr);
  223. encode_nops(&hdr);
  224. }
  225. /*
  226. * Encode DEALLOCATE request
  227. */
  228. static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
  229. struct xdr_stream *xdr,
  230. struct nfs42_falloc_args *args)
  231. {
  232. struct compound_hdr hdr = {
  233. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  234. };
  235. encode_compound_hdr(xdr, req, &hdr);
  236. encode_sequence(xdr, &args->seq_args, &hdr);
  237. encode_putfh(xdr, args->falloc_fh, &hdr);
  238. encode_deallocate(xdr, args, &hdr);
  239. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  240. encode_nops(&hdr);
  241. }
  242. /*
  243. * Encode SEEK request
  244. */
  245. static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
  246. struct xdr_stream *xdr,
  247. struct nfs42_seek_args *args)
  248. {
  249. struct compound_hdr hdr = {
  250. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  251. };
  252. encode_compound_hdr(xdr, req, &hdr);
  253. encode_sequence(xdr, &args->seq_args, &hdr);
  254. encode_putfh(xdr, args->sa_fh, &hdr);
  255. encode_seek(xdr, args, &hdr);
  256. encode_nops(&hdr);
  257. }
  258. /*
  259. * Encode LAYOUTSTATS request
  260. */
  261. static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req,
  262. struct xdr_stream *xdr,
  263. struct nfs42_layoutstat_args *args)
  264. {
  265. int i;
  266. struct compound_hdr hdr = {
  267. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  268. };
  269. encode_compound_hdr(xdr, req, &hdr);
  270. encode_sequence(xdr, &args->seq_args, &hdr);
  271. encode_putfh(xdr, args->fh, &hdr);
  272. WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  273. for (i = 0; i < args->num_dev; i++)
  274. encode_layoutstats(xdr, args, &args->devinfo[i], &hdr);
  275. encode_nops(&hdr);
  276. }
  277. /*
  278. * Encode CLONE request
  279. */
  280. static void nfs4_xdr_enc_clone(struct rpc_rqst *req,
  281. struct xdr_stream *xdr,
  282. struct nfs42_clone_args *args)
  283. {
  284. struct compound_hdr hdr = {
  285. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  286. };
  287. encode_compound_hdr(xdr, req, &hdr);
  288. encode_sequence(xdr, &args->seq_args, &hdr);
  289. encode_putfh(xdr, args->src_fh, &hdr);
  290. encode_savefh(xdr, &hdr);
  291. encode_putfh(xdr, args->dst_fh, &hdr);
  292. encode_clone(xdr, args, &hdr);
  293. encode_getfattr(xdr, args->dst_bitmask, &hdr);
  294. encode_nops(&hdr);
  295. }
  296. static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  297. {
  298. return decode_op_hdr(xdr, OP_ALLOCATE);
  299. }
  300. static int decode_write_response(struct xdr_stream *xdr,
  301. struct nfs42_write_res *res)
  302. {
  303. __be32 *p;
  304. int stateids;
  305. p = xdr_inline_decode(xdr, 4 + 8 + 4);
  306. if (unlikely(!p))
  307. goto out_overflow;
  308. stateids = be32_to_cpup(p++);
  309. p = xdr_decode_hyper(p, &res->count);
  310. res->verifier.committed = be32_to_cpup(p);
  311. return decode_verifier(xdr, &res->verifier.verifier);
  312. out_overflow:
  313. print_overflow_msg(__func__, xdr);
  314. return -EIO;
  315. }
  316. static int decode_copy_requirements(struct xdr_stream *xdr,
  317. struct nfs42_copy_res *res) {
  318. __be32 *p;
  319. p = xdr_inline_decode(xdr, 4 + 4);
  320. if (unlikely(!p))
  321. goto out_overflow;
  322. res->consecutive = be32_to_cpup(p++);
  323. res->synchronous = be32_to_cpup(p++);
  324. return 0;
  325. out_overflow:
  326. print_overflow_msg(__func__, xdr);
  327. return -EIO;
  328. }
  329. static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res)
  330. {
  331. int status;
  332. status = decode_op_hdr(xdr, OP_COPY);
  333. if (status == NFS4ERR_OFFLOAD_NO_REQS) {
  334. status = decode_copy_requirements(xdr, res);
  335. if (status)
  336. return status;
  337. return NFS4ERR_OFFLOAD_NO_REQS;
  338. } else if (status)
  339. return status;
  340. status = decode_write_response(xdr, &res->write_res);
  341. if (status)
  342. return status;
  343. return decode_copy_requirements(xdr, res);
  344. }
  345. static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  346. {
  347. return decode_op_hdr(xdr, OP_DEALLOCATE);
  348. }
  349. static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
  350. {
  351. int status;
  352. __be32 *p;
  353. status = decode_op_hdr(xdr, OP_SEEK);
  354. if (status)
  355. return status;
  356. p = xdr_inline_decode(xdr, 4 + 8);
  357. if (unlikely(!p))
  358. goto out_overflow;
  359. res->sr_eof = be32_to_cpup(p++);
  360. p = xdr_decode_hyper(p, &res->sr_offset);
  361. return 0;
  362. out_overflow:
  363. print_overflow_msg(__func__, xdr);
  364. return -EIO;
  365. }
  366. static int decode_layoutstats(struct xdr_stream *xdr)
  367. {
  368. return decode_op_hdr(xdr, OP_LAYOUTSTATS);
  369. }
  370. static int decode_clone(struct xdr_stream *xdr)
  371. {
  372. return decode_op_hdr(xdr, OP_CLONE);
  373. }
  374. /*
  375. * Decode ALLOCATE request
  376. */
  377. static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
  378. struct xdr_stream *xdr,
  379. struct nfs42_falloc_res *res)
  380. {
  381. struct compound_hdr hdr;
  382. int status;
  383. status = decode_compound_hdr(xdr, &hdr);
  384. if (status)
  385. goto out;
  386. status = decode_sequence(xdr, &res->seq_res, rqstp);
  387. if (status)
  388. goto out;
  389. status = decode_putfh(xdr);
  390. if (status)
  391. goto out;
  392. status = decode_allocate(xdr, res);
  393. if (status)
  394. goto out;
  395. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  396. out:
  397. return status;
  398. }
  399. /*
  400. * Decode COPY response
  401. */
  402. static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp,
  403. struct xdr_stream *xdr,
  404. struct nfs42_copy_res *res)
  405. {
  406. struct compound_hdr hdr;
  407. int status;
  408. status = decode_compound_hdr(xdr, &hdr);
  409. if (status)
  410. goto out;
  411. status = decode_sequence(xdr, &res->seq_res, rqstp);
  412. if (status)
  413. goto out;
  414. status = decode_putfh(xdr);
  415. if (status)
  416. goto out;
  417. status = decode_savefh(xdr);
  418. if (status)
  419. goto out;
  420. status = decode_putfh(xdr);
  421. if (status)
  422. goto out;
  423. status = decode_copy(xdr, res);
  424. out:
  425. return status;
  426. }
  427. /*
  428. * Decode DEALLOCATE request
  429. */
  430. static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
  431. struct xdr_stream *xdr,
  432. struct nfs42_falloc_res *res)
  433. {
  434. struct compound_hdr hdr;
  435. int status;
  436. status = decode_compound_hdr(xdr, &hdr);
  437. if (status)
  438. goto out;
  439. status = decode_sequence(xdr, &res->seq_res, rqstp);
  440. if (status)
  441. goto out;
  442. status = decode_putfh(xdr);
  443. if (status)
  444. goto out;
  445. status = decode_deallocate(xdr, res);
  446. if (status)
  447. goto out;
  448. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  449. out:
  450. return status;
  451. }
  452. /*
  453. * Decode SEEK request
  454. */
  455. static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
  456. struct xdr_stream *xdr,
  457. struct nfs42_seek_res *res)
  458. {
  459. struct compound_hdr hdr;
  460. int status;
  461. status = decode_compound_hdr(xdr, &hdr);
  462. if (status)
  463. goto out;
  464. status = decode_sequence(xdr, &res->seq_res, rqstp);
  465. if (status)
  466. goto out;
  467. status = decode_putfh(xdr);
  468. if (status)
  469. goto out;
  470. status = decode_seek(xdr, res);
  471. out:
  472. return status;
  473. }
  474. /*
  475. * Decode LAYOUTSTATS request
  476. */
  477. static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp,
  478. struct xdr_stream *xdr,
  479. struct nfs42_layoutstat_res *res)
  480. {
  481. struct compound_hdr hdr;
  482. int status, i;
  483. status = decode_compound_hdr(xdr, &hdr);
  484. if (status)
  485. goto out;
  486. status = decode_sequence(xdr, &res->seq_res, rqstp);
  487. if (status)
  488. goto out;
  489. status = decode_putfh(xdr);
  490. if (status)
  491. goto out;
  492. WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  493. for (i = 0; i < res->num_dev; i++) {
  494. status = decode_layoutstats(xdr);
  495. if (status)
  496. goto out;
  497. }
  498. out:
  499. res->rpc_status = status;
  500. return status;
  501. }
  502. /*
  503. * Decode CLONE request
  504. */
  505. static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp,
  506. struct xdr_stream *xdr,
  507. struct nfs42_clone_res *res)
  508. {
  509. struct compound_hdr hdr;
  510. int status;
  511. status = decode_compound_hdr(xdr, &hdr);
  512. if (status)
  513. goto out;
  514. status = decode_sequence(xdr, &res->seq_res, rqstp);
  515. if (status)
  516. goto out;
  517. status = decode_putfh(xdr);
  518. if (status)
  519. goto out;
  520. status = decode_savefh(xdr);
  521. if (status)
  522. goto out;
  523. status = decode_putfh(xdr);
  524. if (status)
  525. goto out;
  526. status = decode_clone(xdr);
  527. if (status)
  528. goto out;
  529. status = decode_getfattr(xdr, res->dst_fattr, res->server);
  530. out:
  531. res->rpc_status = status;
  532. return status;
  533. }
  534. #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */