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 NFS42_WRITE_RES_SIZE (1 /* wr_callback_id size */ +\
13 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
15 1 /* wr_committed */ + \
16 XDR_QUADLEN(NFS4_VERIFIER_SIZE))
17 #define encode_allocate_maxsz (op_encode_hdr_maxsz + \
18 encode_fallocate_maxsz)
19 #define decode_allocate_maxsz (op_decode_hdr_maxsz)
20 #define encode_copy_maxsz (op_encode_hdr_maxsz + \
21 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
22 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
23 2 + 2 + 2 + 1 + 1 + 1)
24 #define decode_copy_maxsz (op_decode_hdr_maxsz + \
25 NFS42_WRITE_RES_SIZE + \
26 1 /* cr_consecutive */ + \
27 1 /* cr_synchronous */)
28 #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
29 encode_fallocate_maxsz)
30 #define decode_deallocate_maxsz (op_decode_hdr_maxsz)
31 #define encode_seek_maxsz (op_encode_hdr_maxsz + \
32 encode_stateid_maxsz + \
35 #define decode_seek_maxsz (op_decode_hdr_maxsz + \
40 #define encode_io_info_maxsz 4
41 #define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \
44 encode_stateid_maxsz + \
45 encode_io_info_maxsz + \
46 encode_io_info_maxsz + \
47 1 /* opaque devaddr4 length */ + \
48 XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE))
49 #define decode_layoutstats_maxsz (op_decode_hdr_maxsz)
50 #define encode_clone_maxsz (encode_stateid_maxsz + \
51 encode_stateid_maxsz + \
52 2 /* src offset */ + \
53 2 /* dst offset */ + \
55 #define decode_clone_maxsz (op_decode_hdr_maxsz)
57 #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
58 encode_putfh_maxsz + \
59 encode_allocate_maxsz + \
61 #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
62 decode_putfh_maxsz + \
63 decode_allocate_maxsz + \
65 #define NFS4_enc_copy_sz (compound_encode_hdr_maxsz + \
66 encode_putfh_maxsz + \
67 encode_savefh_maxsz + \
68 encode_putfh_maxsz + \
70 #define NFS4_dec_copy_sz (compound_decode_hdr_maxsz + \
71 decode_putfh_maxsz + \
72 decode_savefh_maxsz + \
73 decode_putfh_maxsz + \
75 #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
76 encode_putfh_maxsz + \
77 encode_deallocate_maxsz + \
79 #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
80 decode_putfh_maxsz + \
81 decode_deallocate_maxsz + \
83 #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
84 encode_putfh_maxsz + \
86 #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
87 decode_putfh_maxsz + \
89 #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
90 encode_sequence_maxsz + \
91 encode_putfh_maxsz + \
92 PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
93 #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
94 decode_sequence_maxsz + \
95 decode_putfh_maxsz + \
96 PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
97 #define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \
98 encode_sequence_maxsz + \
99 encode_putfh_maxsz + \
100 encode_savefh_maxsz + \
101 encode_putfh_maxsz + \
102 encode_clone_maxsz + \
103 encode_getattr_maxsz)
104 #define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \
105 decode_sequence_maxsz + \
106 decode_putfh_maxsz + \
107 decode_savefh_maxsz + \
108 decode_putfh_maxsz + \
109 decode_clone_maxsz + \
110 decode_getattr_maxsz)
112 static void encode_fallocate(struct xdr_stream
*xdr
,
113 struct nfs42_falloc_args
*args
)
115 encode_nfs4_stateid(xdr
, &args
->falloc_stateid
);
116 encode_uint64(xdr
, args
->falloc_offset
);
117 encode_uint64(xdr
, args
->falloc_length
);
120 static void encode_allocate(struct xdr_stream
*xdr
,
121 struct nfs42_falloc_args
*args
,
122 struct compound_hdr
*hdr
)
124 encode_op_hdr(xdr
, OP_ALLOCATE
, decode_allocate_maxsz
, hdr
);
125 encode_fallocate(xdr
, args
);
128 static void encode_copy(struct xdr_stream
*xdr
,
129 struct nfs42_copy_args
*args
,
130 struct compound_hdr
*hdr
)
132 encode_op_hdr(xdr
, OP_COPY
, decode_copy_maxsz
, hdr
);
133 encode_nfs4_stateid(xdr
, &args
->src_stateid
);
134 encode_nfs4_stateid(xdr
, &args
->dst_stateid
);
136 encode_uint64(xdr
, args
->src_pos
);
137 encode_uint64(xdr
, args
->dst_pos
);
138 encode_uint64(xdr
, args
->count
);
140 encode_uint32(xdr
, 1); /* consecutive = true */
141 encode_uint32(xdr
, 1); /* synchronous = true */
142 encode_uint32(xdr
, 0); /* src server list */
145 static void encode_deallocate(struct xdr_stream
*xdr
,
146 struct nfs42_falloc_args
*args
,
147 struct compound_hdr
*hdr
)
149 encode_op_hdr(xdr
, OP_DEALLOCATE
, decode_deallocate_maxsz
, hdr
);
150 encode_fallocate(xdr
, args
);
153 static void encode_seek(struct xdr_stream
*xdr
,
154 struct nfs42_seek_args
*args
,
155 struct compound_hdr
*hdr
)
157 encode_op_hdr(xdr
, OP_SEEK
, decode_seek_maxsz
, hdr
);
158 encode_nfs4_stateid(xdr
, &args
->sa_stateid
);
159 encode_uint64(xdr
, args
->sa_offset
);
160 encode_uint32(xdr
, args
->sa_what
);
163 static void encode_layoutstats(struct xdr_stream
*xdr
,
164 struct nfs42_layoutstat_args
*args
,
165 struct nfs42_layoutstat_devinfo
*devinfo
,
166 struct compound_hdr
*hdr
)
170 encode_op_hdr(xdr
, OP_LAYOUTSTATS
, decode_layoutstats_maxsz
, hdr
);
171 p
= reserve_space(xdr
, 8 + 8);
172 p
= xdr_encode_hyper(p
, devinfo
->offset
);
173 p
= xdr_encode_hyper(p
, devinfo
->length
);
174 encode_nfs4_stateid(xdr
, &args
->stateid
);
175 p
= reserve_space(xdr
, 4*8 + NFS4_DEVICEID4_SIZE
+ 4);
176 p
= xdr_encode_hyper(p
, devinfo
->read_count
);
177 p
= xdr_encode_hyper(p
, devinfo
->read_bytes
);
178 p
= xdr_encode_hyper(p
, devinfo
->write_count
);
179 p
= xdr_encode_hyper(p
, devinfo
->write_bytes
);
180 p
= xdr_encode_opaque_fixed(p
, devinfo
->dev_id
.data
,
181 NFS4_DEVICEID4_SIZE
);
182 /* Encode layoutupdate4 */
183 *p
++ = cpu_to_be32(devinfo
->layout_type
);
184 if (devinfo
->ld_private
.ops
)
185 devinfo
->ld_private
.ops
->encode(xdr
, args
,
186 &devinfo
->ld_private
);
188 encode_uint32(xdr
, 0);
191 static void encode_clone(struct xdr_stream
*xdr
,
192 struct nfs42_clone_args
*args
,
193 struct compound_hdr
*hdr
)
197 encode_op_hdr(xdr
, OP_CLONE
, decode_clone_maxsz
, hdr
);
198 encode_nfs4_stateid(xdr
, &args
->src_stateid
);
199 encode_nfs4_stateid(xdr
, &args
->dst_stateid
);
200 p
= reserve_space(xdr
, 3*8);
201 p
= xdr_encode_hyper(p
, args
->src_offset
);
202 p
= xdr_encode_hyper(p
, args
->dst_offset
);
203 xdr_encode_hyper(p
, args
->count
);
207 * Encode ALLOCATE request
209 static void nfs4_xdr_enc_allocate(struct rpc_rqst
*req
,
210 struct xdr_stream
*xdr
,
211 struct nfs42_falloc_args
*args
)
213 struct compound_hdr hdr
= {
214 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
217 encode_compound_hdr(xdr
, req
, &hdr
);
218 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
219 encode_putfh(xdr
, args
->falloc_fh
, &hdr
);
220 encode_allocate(xdr
, args
, &hdr
);
221 encode_getfattr(xdr
, args
->falloc_bitmask
, &hdr
);
226 * Encode COPY request
228 static void nfs4_xdr_enc_copy(struct rpc_rqst
*req
,
229 struct xdr_stream
*xdr
,
230 struct nfs42_copy_args
*args
)
232 struct compound_hdr hdr
= {
233 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
236 encode_compound_hdr(xdr
, req
, &hdr
);
237 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
238 encode_putfh(xdr
, args
->src_fh
, &hdr
);
239 encode_savefh(xdr
, &hdr
);
240 encode_putfh(xdr
, args
->dst_fh
, &hdr
);
241 encode_copy(xdr
, args
, &hdr
);
246 * Encode DEALLOCATE request
248 static void nfs4_xdr_enc_deallocate(struct rpc_rqst
*req
,
249 struct xdr_stream
*xdr
,
250 struct nfs42_falloc_args
*args
)
252 struct compound_hdr hdr
= {
253 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
256 encode_compound_hdr(xdr
, req
, &hdr
);
257 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
258 encode_putfh(xdr
, args
->falloc_fh
, &hdr
);
259 encode_deallocate(xdr
, args
, &hdr
);
260 encode_getfattr(xdr
, args
->falloc_bitmask
, &hdr
);
265 * Encode SEEK request
267 static void nfs4_xdr_enc_seek(struct rpc_rqst
*req
,
268 struct xdr_stream
*xdr
,
269 struct nfs42_seek_args
*args
)
271 struct compound_hdr hdr
= {
272 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
275 encode_compound_hdr(xdr
, req
, &hdr
);
276 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
277 encode_putfh(xdr
, args
->sa_fh
, &hdr
);
278 encode_seek(xdr
, args
, &hdr
);
283 * Encode LAYOUTSTATS request
285 static void nfs4_xdr_enc_layoutstats(struct rpc_rqst
*req
,
286 struct xdr_stream
*xdr
,
287 struct nfs42_layoutstat_args
*args
)
291 struct compound_hdr hdr
= {
292 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
295 encode_compound_hdr(xdr
, req
, &hdr
);
296 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
297 encode_putfh(xdr
, args
->fh
, &hdr
);
298 WARN_ON(args
->num_dev
> PNFS_LAYOUTSTATS_MAXDEV
);
299 for (i
= 0; i
< args
->num_dev
; i
++)
300 encode_layoutstats(xdr
, args
, &args
->devinfo
[i
], &hdr
);
305 * Encode CLONE request
307 static void nfs4_xdr_enc_clone(struct rpc_rqst
*req
,
308 struct xdr_stream
*xdr
,
309 struct nfs42_clone_args
*args
)
311 struct compound_hdr hdr
= {
312 .minorversion
= nfs4_xdr_minorversion(&args
->seq_args
),
315 encode_compound_hdr(xdr
, req
, &hdr
);
316 encode_sequence(xdr
, &args
->seq_args
, &hdr
);
317 encode_putfh(xdr
, args
->src_fh
, &hdr
);
318 encode_savefh(xdr
, &hdr
);
319 encode_putfh(xdr
, args
->dst_fh
, &hdr
);
320 encode_clone(xdr
, args
, &hdr
);
321 encode_getfattr(xdr
, args
->dst_bitmask
, &hdr
);
325 static int decode_allocate(struct xdr_stream
*xdr
, struct nfs42_falloc_res
*res
)
327 return decode_op_hdr(xdr
, OP_ALLOCATE
);
330 static int decode_write_response(struct xdr_stream
*xdr
,
331 struct nfs42_write_res
*res
)
335 p
= xdr_inline_decode(xdr
, 4 + 8 + 4);
340 * We never use asynchronous mode, so warn if a server returns
343 if (unlikely(*p
!= 0)) {
344 pr_err_once("%s: server has set unrequested "
345 "asynchronous mode\n", __func__
);
349 p
= xdr_decode_hyper(p
, &res
->count
);
350 res
->verifier
.committed
= be32_to_cpup(p
);
351 return decode_verifier(xdr
, &res
->verifier
.verifier
);
354 print_overflow_msg(__func__
, xdr
);
358 static int decode_copy_requirements(struct xdr_stream
*xdr
,
359 struct nfs42_copy_res
*res
) {
362 p
= xdr_inline_decode(xdr
, 4 + 4);
366 res
->consecutive
= be32_to_cpup(p
++);
367 res
->synchronous
= be32_to_cpup(p
++);
370 print_overflow_msg(__func__
, xdr
);
374 static int decode_copy(struct xdr_stream
*xdr
, struct nfs42_copy_res
*res
)
378 status
= decode_op_hdr(xdr
, OP_COPY
);
379 if (status
== NFS4ERR_OFFLOAD_NO_REQS
) {
380 status
= decode_copy_requirements(xdr
, res
);
383 return NFS4ERR_OFFLOAD_NO_REQS
;
387 status
= decode_write_response(xdr
, &res
->write_res
);
391 return decode_copy_requirements(xdr
, res
);
394 static int decode_deallocate(struct xdr_stream
*xdr
, struct nfs42_falloc_res
*res
)
396 return decode_op_hdr(xdr
, OP_DEALLOCATE
);
399 static int decode_seek(struct xdr_stream
*xdr
, struct nfs42_seek_res
*res
)
404 status
= decode_op_hdr(xdr
, OP_SEEK
);
408 p
= xdr_inline_decode(xdr
, 4 + 8);
412 res
->sr_eof
= be32_to_cpup(p
++);
413 p
= xdr_decode_hyper(p
, &res
->sr_offset
);
417 print_overflow_msg(__func__
, xdr
);
421 static int decode_layoutstats(struct xdr_stream
*xdr
)
423 return decode_op_hdr(xdr
, OP_LAYOUTSTATS
);
426 static int decode_clone(struct xdr_stream
*xdr
)
428 return decode_op_hdr(xdr
, OP_CLONE
);
432 * Decode ALLOCATE request
434 static int nfs4_xdr_dec_allocate(struct rpc_rqst
*rqstp
,
435 struct xdr_stream
*xdr
,
436 struct nfs42_falloc_res
*res
)
438 struct compound_hdr hdr
;
441 status
= decode_compound_hdr(xdr
, &hdr
);
444 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
447 status
= decode_putfh(xdr
);
450 status
= decode_allocate(xdr
, res
);
453 decode_getfattr(xdr
, res
->falloc_fattr
, res
->falloc_server
);
459 * Decode COPY response
461 static int nfs4_xdr_dec_copy(struct rpc_rqst
*rqstp
,
462 struct xdr_stream
*xdr
,
463 struct nfs42_copy_res
*res
)
465 struct compound_hdr hdr
;
468 status
= decode_compound_hdr(xdr
, &hdr
);
471 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
474 status
= decode_putfh(xdr
);
477 status
= decode_savefh(xdr
);
480 status
= decode_putfh(xdr
);
483 status
= decode_copy(xdr
, res
);
489 * Decode DEALLOCATE request
491 static int nfs4_xdr_dec_deallocate(struct rpc_rqst
*rqstp
,
492 struct xdr_stream
*xdr
,
493 struct nfs42_falloc_res
*res
)
495 struct compound_hdr hdr
;
498 status
= decode_compound_hdr(xdr
, &hdr
);
501 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
504 status
= decode_putfh(xdr
);
507 status
= decode_deallocate(xdr
, res
);
510 decode_getfattr(xdr
, res
->falloc_fattr
, res
->falloc_server
);
516 * Decode SEEK request
518 static int nfs4_xdr_dec_seek(struct rpc_rqst
*rqstp
,
519 struct xdr_stream
*xdr
,
520 struct nfs42_seek_res
*res
)
522 struct compound_hdr hdr
;
525 status
= decode_compound_hdr(xdr
, &hdr
);
528 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
531 status
= decode_putfh(xdr
);
534 status
= decode_seek(xdr
, res
);
540 * Decode LAYOUTSTATS request
542 static int nfs4_xdr_dec_layoutstats(struct rpc_rqst
*rqstp
,
543 struct xdr_stream
*xdr
,
544 struct nfs42_layoutstat_res
*res
)
546 struct compound_hdr hdr
;
549 status
= decode_compound_hdr(xdr
, &hdr
);
552 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
555 status
= decode_putfh(xdr
);
558 WARN_ON(res
->num_dev
> PNFS_LAYOUTSTATS_MAXDEV
);
559 for (i
= 0; i
< res
->num_dev
; i
++) {
560 status
= decode_layoutstats(xdr
);
565 res
->rpc_status
= status
;
570 * Decode CLONE request
572 static int nfs4_xdr_dec_clone(struct rpc_rqst
*rqstp
,
573 struct xdr_stream
*xdr
,
574 struct nfs42_clone_res
*res
)
576 struct compound_hdr hdr
;
579 status
= decode_compound_hdr(xdr
, &hdr
);
582 status
= decode_sequence(xdr
, &res
->seq_res
, rqstp
);
585 status
= decode_putfh(xdr
);
588 status
= decode_savefh(xdr
);
591 status
= decode_putfh(xdr
);
594 status
= decode_clone(xdr
);
597 status
= decode_getfattr(xdr
, res
->dst_fattr
, res
->server
);
600 res
->rpc_status
= status
;
604 #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */