nfs42xdr.c 5.7 KB

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