2 * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
4 #ifndef __LINUX_FS_NFS_NFS4_2XDR_H
5 #define __LINUX_FS_NFS_NFS4_2XDR_H
9 #define encode_fallocate_maxsz (encode_stateid_maxsz + \
12 #define encode_allocate_maxsz (op_encode_hdr_maxsz + \
13 encode_fallocate_maxsz)
14 #define decode_allocate_maxsz (op_decode_hdr_maxsz)
15 #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
16 encode_fallocate_maxsz)
17 #define decode_deallocate_maxsz (op_decode_hdr_maxsz)
18 #define encode_seek_maxsz (op_encode_hdr_maxsz + \
19 encode_stateid_maxsz + \
22 #define decode_seek_maxsz (op_decode_hdr_maxsz + \
27 #define encode_io_info_maxsz 4
28 #define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \
31 encode_stateid_maxsz + \
32 encode_io_info_maxsz + \
33 encode_io_info_maxsz + \
34 1 /* opaque devaddr4 length */ + \
35 XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE))
36 #define decode_layoutstats_maxsz (op_decode_hdr_maxsz)
38 #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
39 encode_putfh_maxsz + \
40 encode_allocate_maxsz + \
42 #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
43 decode_putfh_maxsz + \
44 decode_allocate_maxsz + \
46 #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
47 encode_putfh_maxsz + \
48 encode_deallocate_maxsz + \
50 #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
51 decode_putfh_maxsz + \
52 decode_deallocate_maxsz + \
54 #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
55 encode_putfh_maxsz + \
57 #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
58 decode_putfh_maxsz + \
60 #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
61 encode_sequence_maxsz + \
62 encode_putfh_maxsz + \
63 PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
64 #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
65 decode_sequence_maxsz + \
66 decode_putfh_maxsz + \
67 PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
70 static void encode_fallocate(struct xdr_stream
*xdr
,
71 struct nfs42_falloc_args
*args
)
73 encode_nfs4_stateid(xdr
, &args
->falloc_stateid
);
74 encode_uint64(xdr
, args
->falloc_offset
);
75 encode_uint64(xdr
, args
->falloc_length
);
78 static void encode_allocate(struct xdr_stream
*xdr
,
79 struct nfs42_falloc_args
*args
,
80 struct compound_hdr
*hdr
)
82 encode_op_hdr(xdr
, OP_ALLOCATE
, decode_allocate_maxsz
, hdr
);
83 encode_fallocate(xdr
, args
);
86 static void encode_deallocate(struct xdr_stream
*xdr
,
87 struct nfs42_falloc_args
*args
,
88 struct compound_hdr
*hdr
)
90 encode_op_hdr(xdr
, OP_DEALLOCATE
, decode_deallocate_maxsz
, hdr
);
91 encode_fallocate(xdr
, args
);
94 static void encode_seek(struct xdr_stream
*xdr
,
95 struct nfs42_seek_args
*args
,
96 struct compound_hdr
*hdr
)
98 encode_op_hdr(xdr
, OP_SEEK
, decode_seek_maxsz
, hdr
);
99 encode_nfs4_stateid(xdr
, &args
->sa_stateid
);
100 encode_uint64(xdr
, args
->sa_offset
);
101 encode_uint32(xdr
, args
->sa_what
);
104 static void encode_layoutstats(struct xdr_stream
*xdr
,
105 struct nfs42_layoutstat_args
*args
,
106 struct nfs42_layoutstat_devinfo
*devinfo
,
107 struct compound_hdr
*hdr
)
111 encode_op_hdr(xdr
, OP_LAYOUTSTATS
, decode_layoutstats_maxsz
, hdr
);
112 p
= reserve_space(xdr
, 8 + 8);
113 p
= xdr_encode_hyper(p
, devinfo
->offset
);
114 p
= xdr_encode_hyper(p
, devinfo
->length
);
115 encode_nfs4_stateid(xdr
, &args
->stateid
);
116 p
= reserve_space(xdr
, 4*8 + NFS4_DEVICEID4_SIZE
+ 4);
117 p
= xdr_encode_hyper(p
, devinfo
->read_count
);
118 p
= xdr_encode_hyper(p
, devinfo
->read_bytes
);
119 p
= xdr_encode_hyper(p
, devinfo
->write_count
);
120 p
= xdr_encode_hyper(p
, devinfo
->write_bytes
);
121 p
= xdr_encode_opaque_fixed(p
, devinfo
->dev_id
.data
,
122 NFS4_DEVICEID4_SIZE
);
123 /* Encode layoutupdate4 */
124 *p
++ = cpu_to_be32(devinfo
->layout_type
);
125 if (devinfo
->layoutstats_encode
!= NULL
)
126 devinfo
->layoutstats_encode(xdr
, args
, devinfo
);
128 encode_uint32(xdr
, 0);
132 * Encode ALLOCATE request
134 static void nfs4_xdr_enc_allocate(struct rpc_rqst
*req
,
135 struct xdr_stream
*xdr
,
136 struct nfs42_falloc_args
*args
)
138 struct compound_hdr hdr
= {
139 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
142 encode_compound_hdr(xdr
, req
, &hdr
);
143 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
144 encode_putfh(xdr
, args
->falloc_fh
, &hdr
);
145 encode_allocate(xdr
, args
, &hdr
);
146 encode_getfattr(xdr
, args
->falloc_bitmask
, &hdr
);
151 * Encode DEALLOCATE request
153 static void nfs4_xdr_enc_deallocate(struct rpc_rqst
*req
,
154 struct xdr_stream
*xdr
,
155 struct nfs42_falloc_args
*args
)
157 struct compound_hdr hdr
= {
158 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
161 encode_compound_hdr(xdr
, req
, &hdr
);
162 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
163 encode_putfh(xdr
, args
->falloc_fh
, &hdr
);
164 encode_deallocate(xdr
, args
, &hdr
);
165 encode_getfattr(xdr
, args
->falloc_bitmask
, &hdr
);
170 * Encode SEEK request
172 static void nfs4_xdr_enc_seek(struct rpc_rqst
*req
,
173 struct xdr_stream
*xdr
,
174 struct nfs42_seek_args
*args
)
176 struct compound_hdr hdr
= {
177 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
180 encode_compound_hdr(xdr
, req
, &hdr
);
181 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
182 encode_putfh(xdr
, args
->sa_fh
, &hdr
);
183 encode_seek(xdr
, args
, &hdr
);
188 * Encode LAYOUTSTATS request
190 static void nfs4_xdr_enc_layoutstats(struct rpc_rqst
*req
,
191 struct xdr_stream
*xdr
,
192 struct nfs42_layoutstat_args
*args
)
196 struct compound_hdr hdr
= {
197 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
200 encode_compound_hdr(xdr
, req
, &hdr
);
201 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
202 encode_putfh(xdr
, args
->fh
, &hdr
);
203 WARN_ON(args
->num_dev
> PNFS_LAYOUTSTATS_MAXDEV
);
204 for (i
= 0; i
< args
->num_dev
; i
++)
205 encode_layoutstats(xdr
, args
, &args
->devinfo
[i
], &hdr
);
209 static int decode_allocate(struct xdr_stream
*xdr
, struct nfs42_falloc_res
*res
)
211 return decode_op_hdr(xdr
, OP_ALLOCATE
);
214 static int decode_deallocate(struct xdr_stream
*xdr
, struct nfs42_falloc_res
*res
)
216 return decode_op_hdr(xdr
, OP_DEALLOCATE
);
219 static int decode_seek(struct xdr_stream
*xdr
, struct nfs42_seek_res
*res
)
224 status
= decode_op_hdr(xdr
, OP_SEEK
);
228 p
= xdr_inline_decode(xdr
, 4 + 8);
232 res
->sr_eof
= be32_to_cpup(p
++);
233 p
= xdr_decode_hyper(p
, &res
->sr_offset
);
237 print_overflow_msg(__func__
, xdr
);
241 static int decode_layoutstats(struct xdr_stream
*xdr
)
243 return decode_op_hdr(xdr
, OP_LAYOUTSTATS
);
247 * Decode ALLOCATE request
249 static int nfs4_xdr_dec_allocate(struct rpc_rqst
*rqstp
,
250 struct xdr_stream
*xdr
,
251 struct nfs42_falloc_res
*res
)
253 struct compound_hdr hdr
;
256 status
= decode_compound_hdr(xdr
, &hdr
);
259 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
262 status
= decode_putfh(xdr
);
265 status
= decode_allocate(xdr
, res
);
268 decode_getfattr(xdr
, res
->falloc_fattr
, res
->falloc_server
);
274 * Decode DEALLOCATE request
276 static int nfs4_xdr_dec_deallocate(struct rpc_rqst
*rqstp
,
277 struct xdr_stream
*xdr
,
278 struct nfs42_falloc_res
*res
)
280 struct compound_hdr hdr
;
283 status
= decode_compound_hdr(xdr
, &hdr
);
286 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
289 status
= decode_putfh(xdr
);
292 status
= decode_deallocate(xdr
, res
);
295 decode_getfattr(xdr
, res
->falloc_fattr
, res
->falloc_server
);
301 * Decode SEEK request
303 static int nfs4_xdr_dec_seek(struct rpc_rqst
*rqstp
,
304 struct xdr_stream
*xdr
,
305 struct nfs42_seek_res
*res
)
307 struct compound_hdr hdr
;
310 status
= decode_compound_hdr(xdr
, &hdr
);
313 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
316 status
= decode_putfh(xdr
);
319 status
= decode_seek(xdr
, res
);
325 * Decode LAYOUTSTATS request
327 static int nfs4_xdr_dec_layoutstats(struct rpc_rqst
*rqstp
,
328 struct xdr_stream
*xdr
,
329 struct nfs42_layoutstat_res
*res
)
331 struct compound_hdr hdr
;
334 status
= decode_compound_hdr(xdr
, &hdr
);
337 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
340 status
= decode_putfh(xdr
);
343 WARN_ON(res
->num_dev
> PNFS_LAYOUTSTATS_MAXDEV
);
344 for (i
= 0; i
< res
->num_dev
; i
++) {
345 status
= decode_layoutstats(xdr
);
350 res
->rpc_status
= status
;
354 #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */