nfs42xdr.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_seek_maxsz (op_encode_hdr_maxsz + \
  7. encode_stateid_maxsz + \
  8. 2 /* offset */ + \
  9. 1 /* whence */)
  10. #define decode_seek_maxsz (op_decode_hdr_maxsz + \
  11. 1 /* eof */ + \
  12. 1 /* whence */ + \
  13. 2 /* offset */ + \
  14. 2 /* length */)
  15. #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
  16. encode_putfh_maxsz + \
  17. encode_seek_maxsz)
  18. #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
  19. decode_putfh_maxsz + \
  20. decode_seek_maxsz)
  21. static void encode_seek(struct xdr_stream *xdr,
  22. struct nfs42_seek_args *args,
  23. struct compound_hdr *hdr)
  24. {
  25. encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
  26. encode_nfs4_stateid(xdr, &args->sa_stateid);
  27. encode_uint64(xdr, args->sa_offset);
  28. encode_uint32(xdr, args->sa_what);
  29. }
  30. /*
  31. * Encode SEEK request
  32. */
  33. static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
  34. struct xdr_stream *xdr,
  35. struct nfs42_seek_args *args)
  36. {
  37. struct compound_hdr hdr = {
  38. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  39. };
  40. encode_compound_hdr(xdr, req, &hdr);
  41. encode_sequence(xdr, &args->seq_args, &hdr);
  42. encode_putfh(xdr, args->sa_fh, &hdr);
  43. encode_seek(xdr, args, &hdr);
  44. encode_nops(&hdr);
  45. }
  46. static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
  47. {
  48. int status;
  49. __be32 *p;
  50. status = decode_op_hdr(xdr, OP_SEEK);
  51. if (status)
  52. return status;
  53. p = xdr_inline_decode(xdr, 4 + 8);
  54. if (unlikely(!p))
  55. goto out_overflow;
  56. res->sr_eof = be32_to_cpup(p++);
  57. p = xdr_decode_hyper(p, &res->sr_offset);
  58. return 0;
  59. out_overflow:
  60. print_overflow_msg(__func__, xdr);
  61. return -EIO;
  62. }
  63. /*
  64. * Decode SEEK request
  65. */
  66. static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
  67. struct xdr_stream *xdr,
  68. struct nfs42_seek_res *res)
  69. {
  70. struct compound_hdr hdr;
  71. int status;
  72. status = decode_compound_hdr(xdr, &hdr);
  73. if (status)
  74. goto out;
  75. status = decode_sequence(xdr, &res->seq_res, rqstp);
  76. if (status)
  77. goto out;
  78. status = decode_putfh(xdr);
  79. if (status)
  80. goto out;
  81. status = decode_seek(xdr, res);
  82. out:
  83. return status;
  84. }
  85. #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */