nfs42xdr.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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 encode_allocate_maxsz (op_encode_hdr_maxsz + \
  11. encode_fallocate_maxsz)
  12. #define decode_allocate_maxsz (op_decode_hdr_maxsz)
  13. #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
  14. encode_fallocate_maxsz)
  15. #define decode_deallocate_maxsz (op_decode_hdr_maxsz)
  16. #define encode_seek_maxsz (op_encode_hdr_maxsz + \
  17. encode_stateid_maxsz + \
  18. 2 /* offset */ + \
  19. 1 /* whence */)
  20. #define decode_seek_maxsz (op_decode_hdr_maxsz + \
  21. 1 /* eof */ + \
  22. 1 /* whence */ + \
  23. 2 /* offset */ + \
  24. 2 /* length */)
  25. #define encode_io_info_maxsz 4
  26. #define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \
  27. 2 /* offset */ + \
  28. 2 /* length */ + \
  29. encode_stateid_maxsz + \
  30. encode_io_info_maxsz + \
  31. encode_io_info_maxsz + \
  32. 1 /* opaque devaddr4 length */ + \
  33. XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE))
  34. #define decode_layoutstats_maxsz (op_decode_hdr_maxsz)
  35. #define encode_clone_maxsz (encode_stateid_maxsz + \
  36. encode_stateid_maxsz + \
  37. 2 /* src offset */ + \
  38. 2 /* dst offset */ + \
  39. 2 /* count */)
  40. #define decode_clone_maxsz (op_decode_hdr_maxsz)
  41. #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
  42. encode_putfh_maxsz + \
  43. encode_allocate_maxsz + \
  44. encode_getattr_maxsz)
  45. #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
  46. decode_putfh_maxsz + \
  47. decode_allocate_maxsz + \
  48. decode_getattr_maxsz)
  49. #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
  50. encode_putfh_maxsz + \
  51. encode_deallocate_maxsz + \
  52. encode_getattr_maxsz)
  53. #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
  54. decode_putfh_maxsz + \
  55. decode_deallocate_maxsz + \
  56. decode_getattr_maxsz)
  57. #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
  58. encode_putfh_maxsz + \
  59. encode_seek_maxsz)
  60. #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
  61. decode_putfh_maxsz + \
  62. decode_seek_maxsz)
  63. #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
  64. encode_sequence_maxsz + \
  65. encode_putfh_maxsz + \
  66. PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
  67. #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
  68. decode_sequence_maxsz + \
  69. decode_putfh_maxsz + \
  70. PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
  71. #define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \
  72. encode_sequence_maxsz + \
  73. encode_putfh_maxsz + \
  74. encode_savefh_maxsz + \
  75. encode_putfh_maxsz + \
  76. encode_clone_maxsz + \
  77. encode_getattr_maxsz)
  78. #define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \
  79. decode_sequence_maxsz + \
  80. decode_putfh_maxsz + \
  81. decode_savefh_maxsz + \
  82. decode_putfh_maxsz + \
  83. decode_clone_maxsz + \
  84. decode_getattr_maxsz)
  85. static void encode_fallocate(struct xdr_stream *xdr,
  86. struct nfs42_falloc_args *args)
  87. {
  88. encode_nfs4_stateid(xdr, &args->falloc_stateid);
  89. encode_uint64(xdr, args->falloc_offset);
  90. encode_uint64(xdr, args->falloc_length);
  91. }
  92. static void encode_allocate(struct xdr_stream *xdr,
  93. struct nfs42_falloc_args *args,
  94. struct compound_hdr *hdr)
  95. {
  96. encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
  97. encode_fallocate(xdr, args);
  98. }
  99. static void encode_deallocate(struct xdr_stream *xdr,
  100. struct nfs42_falloc_args *args,
  101. struct compound_hdr *hdr)
  102. {
  103. encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
  104. encode_fallocate(xdr, args);
  105. }
  106. static void encode_seek(struct xdr_stream *xdr,
  107. struct nfs42_seek_args *args,
  108. struct compound_hdr *hdr)
  109. {
  110. encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
  111. encode_nfs4_stateid(xdr, &args->sa_stateid);
  112. encode_uint64(xdr, args->sa_offset);
  113. encode_uint32(xdr, args->sa_what);
  114. }
  115. static void encode_layoutstats(struct xdr_stream *xdr,
  116. struct nfs42_layoutstat_args *args,
  117. struct nfs42_layoutstat_devinfo *devinfo,
  118. struct compound_hdr *hdr)
  119. {
  120. __be32 *p;
  121. encode_op_hdr(xdr, OP_LAYOUTSTATS, decode_layoutstats_maxsz, hdr);
  122. p = reserve_space(xdr, 8 + 8);
  123. p = xdr_encode_hyper(p, devinfo->offset);
  124. p = xdr_encode_hyper(p, devinfo->length);
  125. encode_nfs4_stateid(xdr, &args->stateid);
  126. p = reserve_space(xdr, 4*8 + NFS4_DEVICEID4_SIZE + 4);
  127. p = xdr_encode_hyper(p, devinfo->read_count);
  128. p = xdr_encode_hyper(p, devinfo->read_bytes);
  129. p = xdr_encode_hyper(p, devinfo->write_count);
  130. p = xdr_encode_hyper(p, devinfo->write_bytes);
  131. p = xdr_encode_opaque_fixed(p, devinfo->dev_id.data,
  132. NFS4_DEVICEID4_SIZE);
  133. /* Encode layoutupdate4 */
  134. *p++ = cpu_to_be32(devinfo->layout_type);
  135. if (devinfo->layoutstats_encode != NULL)
  136. devinfo->layoutstats_encode(xdr, args, devinfo);
  137. else
  138. encode_uint32(xdr, 0);
  139. }
  140. static void encode_clone(struct xdr_stream *xdr,
  141. struct nfs42_clone_args *args,
  142. struct compound_hdr *hdr)
  143. {
  144. __be32 *p;
  145. encode_op_hdr(xdr, OP_CLONE, decode_clone_maxsz, hdr);
  146. encode_nfs4_stateid(xdr, &args->src_stateid);
  147. encode_nfs4_stateid(xdr, &args->dst_stateid);
  148. p = reserve_space(xdr, 3*8);
  149. p = xdr_encode_hyper(p, args->src_offset);
  150. p = xdr_encode_hyper(p, args->dst_offset);
  151. xdr_encode_hyper(p, args->count);
  152. }
  153. /*
  154. * Encode ALLOCATE request
  155. */
  156. static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
  157. struct xdr_stream *xdr,
  158. struct nfs42_falloc_args *args)
  159. {
  160. struct compound_hdr hdr = {
  161. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  162. };
  163. encode_compound_hdr(xdr, req, &hdr);
  164. encode_sequence(xdr, &args->seq_args, &hdr);
  165. encode_putfh(xdr, args->falloc_fh, &hdr);
  166. encode_allocate(xdr, args, &hdr);
  167. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  168. encode_nops(&hdr);
  169. }
  170. /*
  171. * Encode DEALLOCATE request
  172. */
  173. static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
  174. struct xdr_stream *xdr,
  175. struct nfs42_falloc_args *args)
  176. {
  177. struct compound_hdr hdr = {
  178. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  179. };
  180. encode_compound_hdr(xdr, req, &hdr);
  181. encode_sequence(xdr, &args->seq_args, &hdr);
  182. encode_putfh(xdr, args->falloc_fh, &hdr);
  183. encode_deallocate(xdr, args, &hdr);
  184. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  185. encode_nops(&hdr);
  186. }
  187. /*
  188. * Encode SEEK request
  189. */
  190. static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
  191. struct xdr_stream *xdr,
  192. struct nfs42_seek_args *args)
  193. {
  194. struct compound_hdr hdr = {
  195. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  196. };
  197. encode_compound_hdr(xdr, req, &hdr);
  198. encode_sequence(xdr, &args->seq_args, &hdr);
  199. encode_putfh(xdr, args->sa_fh, &hdr);
  200. encode_seek(xdr, args, &hdr);
  201. encode_nops(&hdr);
  202. }
  203. /*
  204. * Encode LAYOUTSTATS request
  205. */
  206. static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req,
  207. struct xdr_stream *xdr,
  208. struct nfs42_layoutstat_args *args)
  209. {
  210. int i;
  211. struct compound_hdr hdr = {
  212. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  213. };
  214. encode_compound_hdr(xdr, req, &hdr);
  215. encode_sequence(xdr, &args->seq_args, &hdr);
  216. encode_putfh(xdr, args->fh, &hdr);
  217. WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  218. for (i = 0; i < args->num_dev; i++)
  219. encode_layoutstats(xdr, args, &args->devinfo[i], &hdr);
  220. encode_nops(&hdr);
  221. }
  222. /*
  223. * Encode CLONE request
  224. */
  225. static void nfs4_xdr_enc_clone(struct rpc_rqst *req,
  226. struct xdr_stream *xdr,
  227. struct nfs42_clone_args *args)
  228. {
  229. struct compound_hdr hdr = {
  230. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  231. };
  232. encode_compound_hdr(xdr, req, &hdr);
  233. encode_sequence(xdr, &args->seq_args, &hdr);
  234. encode_putfh(xdr, args->src_fh, &hdr);
  235. encode_savefh(xdr, &hdr);
  236. encode_putfh(xdr, args->dst_fh, &hdr);
  237. encode_clone(xdr, args, &hdr);
  238. encode_getfattr(xdr, args->dst_bitmask, &hdr);
  239. encode_nops(&hdr);
  240. }
  241. static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  242. {
  243. return decode_op_hdr(xdr, OP_ALLOCATE);
  244. }
  245. static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  246. {
  247. return decode_op_hdr(xdr, OP_DEALLOCATE);
  248. }
  249. static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
  250. {
  251. int status;
  252. __be32 *p;
  253. status = decode_op_hdr(xdr, OP_SEEK);
  254. if (status)
  255. return status;
  256. p = xdr_inline_decode(xdr, 4 + 8);
  257. if (unlikely(!p))
  258. goto out_overflow;
  259. res->sr_eof = be32_to_cpup(p++);
  260. p = xdr_decode_hyper(p, &res->sr_offset);
  261. return 0;
  262. out_overflow:
  263. print_overflow_msg(__func__, xdr);
  264. return -EIO;
  265. }
  266. static int decode_layoutstats(struct xdr_stream *xdr)
  267. {
  268. return decode_op_hdr(xdr, OP_LAYOUTSTATS);
  269. }
  270. static int decode_clone(struct xdr_stream *xdr)
  271. {
  272. return decode_op_hdr(xdr, OP_CLONE);
  273. }
  274. /*
  275. * Decode ALLOCATE request
  276. */
  277. static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
  278. struct xdr_stream *xdr,
  279. struct nfs42_falloc_res *res)
  280. {
  281. struct compound_hdr hdr;
  282. int status;
  283. status = decode_compound_hdr(xdr, &hdr);
  284. if (status)
  285. goto out;
  286. status = decode_sequence(xdr, &res->seq_res, rqstp);
  287. if (status)
  288. goto out;
  289. status = decode_putfh(xdr);
  290. if (status)
  291. goto out;
  292. status = decode_allocate(xdr, res);
  293. if (status)
  294. goto out;
  295. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  296. out:
  297. return status;
  298. }
  299. /*
  300. * Decode DEALLOCATE request
  301. */
  302. static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
  303. struct xdr_stream *xdr,
  304. struct nfs42_falloc_res *res)
  305. {
  306. struct compound_hdr hdr;
  307. int status;
  308. status = decode_compound_hdr(xdr, &hdr);
  309. if (status)
  310. goto out;
  311. status = decode_sequence(xdr, &res->seq_res, rqstp);
  312. if (status)
  313. goto out;
  314. status = decode_putfh(xdr);
  315. if (status)
  316. goto out;
  317. status = decode_deallocate(xdr, res);
  318. if (status)
  319. goto out;
  320. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  321. out:
  322. return status;
  323. }
  324. /*
  325. * Decode SEEK request
  326. */
  327. static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
  328. struct xdr_stream *xdr,
  329. struct nfs42_seek_res *res)
  330. {
  331. struct compound_hdr hdr;
  332. int status;
  333. status = decode_compound_hdr(xdr, &hdr);
  334. if (status)
  335. goto out;
  336. status = decode_sequence(xdr, &res->seq_res, rqstp);
  337. if (status)
  338. goto out;
  339. status = decode_putfh(xdr);
  340. if (status)
  341. goto out;
  342. status = decode_seek(xdr, res);
  343. out:
  344. return status;
  345. }
  346. /*
  347. * Decode LAYOUTSTATS request
  348. */
  349. static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp,
  350. struct xdr_stream *xdr,
  351. struct nfs42_layoutstat_res *res)
  352. {
  353. struct compound_hdr hdr;
  354. int status, i;
  355. status = decode_compound_hdr(xdr, &hdr);
  356. if (status)
  357. goto out;
  358. status = decode_sequence(xdr, &res->seq_res, rqstp);
  359. if (status)
  360. goto out;
  361. status = decode_putfh(xdr);
  362. if (status)
  363. goto out;
  364. WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  365. for (i = 0; i < res->num_dev; i++) {
  366. status = decode_layoutstats(xdr);
  367. if (status)
  368. goto out;
  369. }
  370. out:
  371. res->rpc_status = status;
  372. return status;
  373. }
  374. /*
  375. * Decode CLONE request
  376. */
  377. static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp,
  378. struct xdr_stream *xdr,
  379. struct nfs42_clone_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_savefh(xdr);
  393. if (status)
  394. goto out;
  395. status = decode_putfh(xdr);
  396. if (status)
  397. goto out;
  398. status = decode_clone(xdr);
  399. if (status)
  400. goto out;
  401. status = decode_getfattr(xdr, res->dst_fattr, res->server);
  402. out:
  403. res->rpc_status = status;
  404. return status;
  405. }
  406. #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */