nfs42xdr.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
  36. encode_putfh_maxsz + \
  37. encode_allocate_maxsz + \
  38. encode_getattr_maxsz)
  39. #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
  40. decode_putfh_maxsz + \
  41. decode_allocate_maxsz + \
  42. decode_getattr_maxsz)
  43. #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
  44. encode_putfh_maxsz + \
  45. encode_deallocate_maxsz + \
  46. encode_getattr_maxsz)
  47. #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
  48. decode_putfh_maxsz + \
  49. decode_deallocate_maxsz + \
  50. decode_getattr_maxsz)
  51. #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
  52. encode_putfh_maxsz + \
  53. encode_seek_maxsz)
  54. #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
  55. decode_putfh_maxsz + \
  56. decode_seek_maxsz)
  57. #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
  58. encode_sequence_maxsz + \
  59. encode_putfh_maxsz + \
  60. PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
  61. #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
  62. decode_sequence_maxsz + \
  63. decode_putfh_maxsz + \
  64. PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
  65. static void encode_fallocate(struct xdr_stream *xdr,
  66. struct nfs42_falloc_args *args)
  67. {
  68. encode_nfs4_stateid(xdr, &args->falloc_stateid);
  69. encode_uint64(xdr, args->falloc_offset);
  70. encode_uint64(xdr, args->falloc_length);
  71. }
  72. static void encode_allocate(struct xdr_stream *xdr,
  73. struct nfs42_falloc_args *args,
  74. struct compound_hdr *hdr)
  75. {
  76. encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
  77. encode_fallocate(xdr, args);
  78. }
  79. static void encode_deallocate(struct xdr_stream *xdr,
  80. struct nfs42_falloc_args *args,
  81. struct compound_hdr *hdr)
  82. {
  83. encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
  84. encode_fallocate(xdr, args);
  85. }
  86. static void encode_seek(struct xdr_stream *xdr,
  87. struct nfs42_seek_args *args,
  88. struct compound_hdr *hdr)
  89. {
  90. encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
  91. encode_nfs4_stateid(xdr, &args->sa_stateid);
  92. encode_uint64(xdr, args->sa_offset);
  93. encode_uint32(xdr, args->sa_what);
  94. }
  95. static void encode_layoutstats(struct xdr_stream *xdr,
  96. struct nfs42_layoutstat_args *args,
  97. struct nfs42_layoutstat_devinfo *devinfo,
  98. struct compound_hdr *hdr)
  99. {
  100. __be32 *p;
  101. encode_op_hdr(xdr, OP_LAYOUTSTATS, decode_layoutstats_maxsz, hdr);
  102. p = reserve_space(xdr, 8 + 8);
  103. p = xdr_encode_hyper(p, devinfo->offset);
  104. p = xdr_encode_hyper(p, devinfo->length);
  105. encode_nfs4_stateid(xdr, &args->stateid);
  106. p = reserve_space(xdr, 4*8 + NFS4_DEVICEID4_SIZE + 4);
  107. p = xdr_encode_hyper(p, devinfo->read_count);
  108. p = xdr_encode_hyper(p, devinfo->read_bytes);
  109. p = xdr_encode_hyper(p, devinfo->write_count);
  110. p = xdr_encode_hyper(p, devinfo->write_bytes);
  111. p = xdr_encode_opaque_fixed(p, devinfo->dev_id.data,
  112. NFS4_DEVICEID4_SIZE);
  113. /* Encode layoutupdate4 */
  114. *p++ = cpu_to_be32(devinfo->layout_type);
  115. if (devinfo->layoutstats_encode != NULL)
  116. devinfo->layoutstats_encode(xdr, args, devinfo);
  117. else
  118. encode_uint32(xdr, 0);
  119. }
  120. /*
  121. * Encode ALLOCATE request
  122. */
  123. static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
  124. struct xdr_stream *xdr,
  125. struct nfs42_falloc_args *args)
  126. {
  127. struct compound_hdr hdr = {
  128. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  129. };
  130. encode_compound_hdr(xdr, req, &hdr);
  131. encode_sequence(xdr, &args->seq_args, &hdr);
  132. encode_putfh(xdr, args->falloc_fh, &hdr);
  133. encode_allocate(xdr, args, &hdr);
  134. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  135. encode_nops(&hdr);
  136. }
  137. /*
  138. * Encode DEALLOCATE request
  139. */
  140. static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
  141. struct xdr_stream *xdr,
  142. struct nfs42_falloc_args *args)
  143. {
  144. struct compound_hdr hdr = {
  145. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  146. };
  147. encode_compound_hdr(xdr, req, &hdr);
  148. encode_sequence(xdr, &args->seq_args, &hdr);
  149. encode_putfh(xdr, args->falloc_fh, &hdr);
  150. encode_deallocate(xdr, args, &hdr);
  151. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  152. encode_nops(&hdr);
  153. }
  154. /*
  155. * Encode SEEK request
  156. */
  157. static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
  158. struct xdr_stream *xdr,
  159. struct nfs42_seek_args *args)
  160. {
  161. struct compound_hdr hdr = {
  162. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  163. };
  164. encode_compound_hdr(xdr, req, &hdr);
  165. encode_sequence(xdr, &args->seq_args, &hdr);
  166. encode_putfh(xdr, args->sa_fh, &hdr);
  167. encode_seek(xdr, args, &hdr);
  168. encode_nops(&hdr);
  169. }
  170. /*
  171. * Encode LAYOUTSTATS request
  172. */
  173. static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req,
  174. struct xdr_stream *xdr,
  175. struct nfs42_layoutstat_args *args)
  176. {
  177. int i;
  178. struct compound_hdr hdr = {
  179. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  180. };
  181. encode_compound_hdr(xdr, req, &hdr);
  182. encode_sequence(xdr, &args->seq_args, &hdr);
  183. encode_putfh(xdr, args->fh, &hdr);
  184. WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  185. for (i = 0; i < args->num_dev; i++)
  186. encode_layoutstats(xdr, args, &args->devinfo[i], &hdr);
  187. encode_nops(&hdr);
  188. }
  189. static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  190. {
  191. return decode_op_hdr(xdr, OP_ALLOCATE);
  192. }
  193. static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  194. {
  195. return decode_op_hdr(xdr, OP_DEALLOCATE);
  196. }
  197. static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
  198. {
  199. int status;
  200. __be32 *p;
  201. status = decode_op_hdr(xdr, OP_SEEK);
  202. if (status)
  203. return status;
  204. p = xdr_inline_decode(xdr, 4 + 8);
  205. if (unlikely(!p))
  206. goto out_overflow;
  207. res->sr_eof = be32_to_cpup(p++);
  208. p = xdr_decode_hyper(p, &res->sr_offset);
  209. return 0;
  210. out_overflow:
  211. print_overflow_msg(__func__, xdr);
  212. return -EIO;
  213. }
  214. static int decode_layoutstats(struct xdr_stream *xdr,
  215. struct nfs42_layoutstat_res *res)
  216. {
  217. return decode_op_hdr(xdr, OP_LAYOUTSTATS);
  218. }
  219. /*
  220. * Decode ALLOCATE request
  221. */
  222. static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
  223. struct xdr_stream *xdr,
  224. struct nfs42_falloc_res *res)
  225. {
  226. struct compound_hdr hdr;
  227. int status;
  228. status = decode_compound_hdr(xdr, &hdr);
  229. if (status)
  230. goto out;
  231. status = decode_sequence(xdr, &res->seq_res, rqstp);
  232. if (status)
  233. goto out;
  234. status = decode_putfh(xdr);
  235. if (status)
  236. goto out;
  237. status = decode_allocate(xdr, res);
  238. if (status)
  239. goto out;
  240. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  241. out:
  242. return status;
  243. }
  244. /*
  245. * Decode DEALLOCATE request
  246. */
  247. static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
  248. struct xdr_stream *xdr,
  249. struct nfs42_falloc_res *res)
  250. {
  251. struct compound_hdr hdr;
  252. int status;
  253. status = decode_compound_hdr(xdr, &hdr);
  254. if (status)
  255. goto out;
  256. status = decode_sequence(xdr, &res->seq_res, rqstp);
  257. if (status)
  258. goto out;
  259. status = decode_putfh(xdr);
  260. if (status)
  261. goto out;
  262. status = decode_deallocate(xdr, res);
  263. if (status)
  264. goto out;
  265. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  266. out:
  267. return status;
  268. }
  269. /*
  270. * Decode SEEK request
  271. */
  272. static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
  273. struct xdr_stream *xdr,
  274. struct nfs42_seek_res *res)
  275. {
  276. struct compound_hdr hdr;
  277. int status;
  278. status = decode_compound_hdr(xdr, &hdr);
  279. if (status)
  280. goto out;
  281. status = decode_sequence(xdr, &res->seq_res, rqstp);
  282. if (status)
  283. goto out;
  284. status = decode_putfh(xdr);
  285. if (status)
  286. goto out;
  287. status = decode_seek(xdr, res);
  288. out:
  289. return status;
  290. }
  291. /*
  292. * Decode LAYOUTSTATS request
  293. */
  294. static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp,
  295. struct xdr_stream *xdr,
  296. struct nfs42_layoutstat_res *res)
  297. {
  298. struct compound_hdr hdr;
  299. int status, i;
  300. status = decode_compound_hdr(xdr, &hdr);
  301. if (status)
  302. goto out;
  303. status = decode_sequence(xdr, &res->seq_res, rqstp);
  304. if (status)
  305. goto out;
  306. status = decode_putfh(xdr);
  307. if (status)
  308. goto out;
  309. WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
  310. for (i = 0; i < res->num_dev; i++) {
  311. status = decode_layoutstats(xdr, res);
  312. if (status)
  313. goto out;
  314. }
  315. out:
  316. res->rpc_status = status;
  317. return status;
  318. }
  319. #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */