blob: 4248d034479c992cfa8920dabcf09833dec9d1c1 [file] [log] [blame]
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04001/*
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
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007#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)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -040013#define encode_seek_maxsz (op_encode_hdr_maxsz + \
14 encode_stateid_maxsz + \
15 2 /* offset */ + \
16 1 /* whence */)
17#define decode_seek_maxsz (op_decode_hdr_maxsz + \
18 1 /* eof */ + \
19 1 /* whence */ + \
20 2 /* offset */ + \
21 2 /* length */)
22
Anna Schumakerf4ac1672014-11-25 13:18:15 -050023#define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
24 encode_putfh_maxsz + \
25 encode_allocate_maxsz)
26#define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
27 decode_putfh_maxsz + \
28 decode_allocate_maxsz)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -040029#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
30 encode_putfh_maxsz + \
31 encode_seek_maxsz)
32#define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
33 decode_putfh_maxsz + \
34 decode_seek_maxsz)
35
36
Anna Schumakerf4ac1672014-11-25 13:18:15 -050037static void encode_fallocate(struct xdr_stream *xdr,
38 struct nfs42_falloc_args *args)
39{
40 encode_nfs4_stateid(xdr, &args->falloc_stateid);
41 encode_uint64(xdr, args->falloc_offset);
42 encode_uint64(xdr, args->falloc_length);
43}
44
45static void encode_allocate(struct xdr_stream *xdr,
46 struct nfs42_falloc_args *args,
47 struct compound_hdr *hdr)
48{
49 encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
50 encode_fallocate(xdr, args);
51}
52
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -040053static void encode_seek(struct xdr_stream *xdr,
54 struct nfs42_seek_args *args,
55 struct compound_hdr *hdr)
56{
57 encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
58 encode_nfs4_stateid(xdr, &args->sa_stateid);
59 encode_uint64(xdr, args->sa_offset);
60 encode_uint32(xdr, args->sa_what);
61}
62
63/*
Anna Schumakerf4ac1672014-11-25 13:18:15 -050064 * Encode ALLOCATE request
65 */
66static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
67 struct xdr_stream *xdr,
68 struct nfs42_falloc_args *args)
69{
70 struct compound_hdr hdr = {
71 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
72 };
73
74 encode_compound_hdr(xdr, req, &hdr);
75 encode_sequence(xdr, &args->seq_args, &hdr);
76 encode_putfh(xdr, args->falloc_fh, &hdr);
77 encode_allocate(xdr, args, &hdr);
78 encode_nops(&hdr);
79}
80
81/*
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -040082 * Encode SEEK request
83 */
84static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
85 struct xdr_stream *xdr,
86 struct nfs42_seek_args *args)
87{
88 struct compound_hdr hdr = {
89 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
90 };
91
92 encode_compound_hdr(xdr, req, &hdr);
93 encode_sequence(xdr, &args->seq_args, &hdr);
94 encode_putfh(xdr, args->sa_fh, &hdr);
95 encode_seek(xdr, args, &hdr);
96 encode_nops(&hdr);
97}
98
Anna Schumakerf4ac1672014-11-25 13:18:15 -050099static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
100{
101 return decode_op_hdr(xdr, OP_ALLOCATE);
102}
103
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400104static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
105{
106 int status;
107 __be32 *p;
108
109 status = decode_op_hdr(xdr, OP_SEEK);
110 if (status)
111 return status;
112
113 p = xdr_inline_decode(xdr, 4 + 8);
114 if (unlikely(!p))
115 goto out_overflow;
116
117 res->sr_eof = be32_to_cpup(p++);
118 p = xdr_decode_hyper(p, &res->sr_offset);
119 return 0;
120
121out_overflow:
122 print_overflow_msg(__func__, xdr);
123 return -EIO;
124}
125
126/*
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500127 * Decode ALLOCATE request
128 */
129static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
130 struct xdr_stream *xdr,
131 struct nfs42_falloc_res *res)
132{
133 struct compound_hdr hdr;
134 int status;
135
136 status = decode_compound_hdr(xdr, &hdr);
137 if (status)
138 goto out;
139 status = decode_sequence(xdr, &res->seq_res, rqstp);
140 if (status)
141 goto out;
142 status = decode_putfh(xdr);
143 if (status)
144 goto out;
145 status = decode_allocate(xdr, res);
146out:
147 return status;
148}
149
150/*
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400151 * Decode SEEK request
152 */
153static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
154 struct xdr_stream *xdr,
155 struct nfs42_seek_res *res)
156{
157 struct compound_hdr hdr;
158 int status;
159
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_seek(xdr, res);
170out:
171 return status;
172}
173#endif /* __LINUX_FS_NFS_NFS4_2XDR_H */