nfs42xdr.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. #define encode_fallocate_maxsz (encode_stateid_maxsz + \
  7. 2 /* offset */ + \
  8. 2 /* length */)
  9. #define encode_allocate_maxsz (op_encode_hdr_maxsz + \
  10. encode_fallocate_maxsz)
  11. #define decode_allocate_maxsz (op_decode_hdr_maxsz)
  12. #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
  13. encode_fallocate_maxsz)
  14. #define decode_deallocate_maxsz (op_decode_hdr_maxsz)
  15. #define encode_seek_maxsz (op_encode_hdr_maxsz + \
  16. encode_stateid_maxsz + \
  17. 2 /* offset */ + \
  18. 1 /* whence */)
  19. #define decode_seek_maxsz (op_decode_hdr_maxsz + \
  20. 1 /* eof */ + \
  21. 1 /* whence */ + \
  22. 2 /* offset */ + \
  23. 2 /* length */)
  24. #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
  25. encode_putfh_maxsz + \
  26. encode_allocate_maxsz + \
  27. encode_getattr_maxsz)
  28. #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
  29. decode_putfh_maxsz + \
  30. decode_allocate_maxsz + \
  31. decode_getattr_maxsz)
  32. #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
  33. encode_putfh_maxsz + \
  34. encode_deallocate_maxsz + \
  35. encode_getattr_maxsz)
  36. #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
  37. decode_putfh_maxsz + \
  38. decode_deallocate_maxsz + \
  39. decode_getattr_maxsz)
  40. #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
  41. encode_putfh_maxsz + \
  42. encode_seek_maxsz)
  43. #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
  44. decode_putfh_maxsz + \
  45. decode_seek_maxsz)
  46. static void encode_fallocate(struct xdr_stream *xdr,
  47. struct nfs42_falloc_args *args)
  48. {
  49. encode_nfs4_stateid(xdr, &args->falloc_stateid);
  50. encode_uint64(xdr, args->falloc_offset);
  51. encode_uint64(xdr, args->falloc_length);
  52. }
  53. static void encode_allocate(struct xdr_stream *xdr,
  54. struct nfs42_falloc_args *args,
  55. struct compound_hdr *hdr)
  56. {
  57. encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
  58. encode_fallocate(xdr, args);
  59. }
  60. static void encode_deallocate(struct xdr_stream *xdr,
  61. struct nfs42_falloc_args *args,
  62. struct compound_hdr *hdr)
  63. {
  64. encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
  65. encode_fallocate(xdr, args);
  66. }
  67. static void encode_seek(struct xdr_stream *xdr,
  68. struct nfs42_seek_args *args,
  69. struct compound_hdr *hdr)
  70. {
  71. encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
  72. encode_nfs4_stateid(xdr, &args->sa_stateid);
  73. encode_uint64(xdr, args->sa_offset);
  74. encode_uint32(xdr, args->sa_what);
  75. }
  76. /*
  77. * Encode ALLOCATE request
  78. */
  79. static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
  80. struct xdr_stream *xdr,
  81. struct nfs42_falloc_args *args)
  82. {
  83. struct compound_hdr hdr = {
  84. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  85. };
  86. encode_compound_hdr(xdr, req, &hdr);
  87. encode_sequence(xdr, &args->seq_args, &hdr);
  88. encode_putfh(xdr, args->falloc_fh, &hdr);
  89. encode_allocate(xdr, args, &hdr);
  90. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  91. encode_nops(&hdr);
  92. }
  93. /*
  94. * Encode DEALLOCATE request
  95. */
  96. static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
  97. struct xdr_stream *xdr,
  98. struct nfs42_falloc_args *args)
  99. {
  100. struct compound_hdr hdr = {
  101. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  102. };
  103. encode_compound_hdr(xdr, req, &hdr);
  104. encode_sequence(xdr, &args->seq_args, &hdr);
  105. encode_putfh(xdr, args->falloc_fh, &hdr);
  106. encode_deallocate(xdr, args, &hdr);
  107. encode_getfattr(xdr, args->falloc_bitmask, &hdr);
  108. encode_nops(&hdr);
  109. }
  110. /*
  111. * Encode SEEK request
  112. */
  113. static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
  114. struct xdr_stream *xdr,
  115. struct nfs42_seek_args *args)
  116. {
  117. struct compound_hdr hdr = {
  118. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  119. };
  120. encode_compound_hdr(xdr, req, &hdr);
  121. encode_sequence(xdr, &args->seq_args, &hdr);
  122. encode_putfh(xdr, args->sa_fh, &hdr);
  123. encode_seek(xdr, args, &hdr);
  124. encode_nops(&hdr);
  125. }
  126. static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  127. {
  128. return decode_op_hdr(xdr, OP_ALLOCATE);
  129. }
  130. static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
  131. {
  132. return decode_op_hdr(xdr, OP_DEALLOCATE);
  133. }
  134. static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
  135. {
  136. int status;
  137. __be32 *p;
  138. status = decode_op_hdr(xdr, OP_SEEK);
  139. if (status)
  140. return status;
  141. p = xdr_inline_decode(xdr, 4 + 8);
  142. if (unlikely(!p))
  143. goto out_overflow;
  144. res->sr_eof = be32_to_cpup(p++);
  145. p = xdr_decode_hyper(p, &res->sr_offset);
  146. return 0;
  147. out_overflow:
  148. print_overflow_msg(__func__, xdr);
  149. return -EIO;
  150. }
  151. /*
  152. * Decode ALLOCATE request
  153. */
  154. static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
  155. struct xdr_stream *xdr,
  156. struct nfs42_falloc_res *res)
  157. {
  158. struct compound_hdr hdr;
  159. int status;
  160. status = decode_compound_hdr(xdr, &hdr);
  161. if (status)
  162. goto out;
  163. status = decode_sequence(xdr, &res->seq_res, rqstp);
  164. if (status)
  165. goto out;
  166. status = decode_putfh(xdr);
  167. if (status)
  168. goto out;
  169. status = decode_allocate(xdr, res);
  170. if (status)
  171. goto out;
  172. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  173. out:
  174. return status;
  175. }
  176. /*
  177. * Decode DEALLOCATE request
  178. */
  179. static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
  180. struct xdr_stream *xdr,
  181. struct nfs42_falloc_res *res)
  182. {
  183. struct compound_hdr hdr;
  184. int status;
  185. status = decode_compound_hdr(xdr, &hdr);
  186. if (status)
  187. goto out;
  188. status = decode_sequence(xdr, &res->seq_res, rqstp);
  189. if (status)
  190. goto out;
  191. status = decode_putfh(xdr);
  192. if (status)
  193. goto out;
  194. status = decode_deallocate(xdr, res);
  195. if (status)
  196. goto out;
  197. decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
  198. out:
  199. return status;
  200. }
  201. /*
  202. * Decode SEEK request
  203. */
  204. static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
  205. struct xdr_stream *xdr,
  206. struct nfs42_seek_res *res)
  207. {
  208. struct compound_hdr hdr;
  209. int status;
  210. status = decode_compound_hdr(xdr, &hdr);
  211. if (status)
  212. goto out;
  213. status = decode_sequence(xdr, &res->seq_res, rqstp);
  214. if (status)
  215. goto out;
  216. status = decode_putfh(xdr);
  217. if (status)
  218. goto out;
  219. status = decode_seek(xdr, res);
  220. out:
  221. return status;
  222. }
  223. #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */