1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
5 #ifndef __LINUX_FS_NFS_NFS4_2XDR_H
6 #define __LINUX_FS_NFS_NFS4_2XDR_H
10 #define encode_fallocate_maxsz (encode_stateid_maxsz + \
13 #define NFS42_WRITE_RES_SIZE (1 /* wr_callback_id size */ +\
14 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
16 1 /* wr_committed */ + \
17 XDR_QUADLEN(NFS4_VERIFIER_SIZE))
18 #define encode_allocate_maxsz (op_encode_hdr_maxsz + \
19 encode_fallocate_maxsz)
20 #define decode_allocate_maxsz (op_decode_hdr_maxsz)
21 #define encode_copy_maxsz (op_encode_hdr_maxsz + \
22 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
23 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
24 2 + 2 + 2 + 1 + 1 + 1 +\
25 1 + /* One cnr_source_server */\
27 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
28 #define decode_copy_maxsz (op_decode_hdr_maxsz + \
29 NFS42_WRITE_RES_SIZE + \
30 1 /* cr_consecutive */ + \
31 1 /* cr_synchronous */)
32 #define encode_offload_cancel_maxsz (op_encode_hdr_maxsz + \
33 XDR_QUADLEN(NFS4_STATEID_SIZE))
34 #define decode_offload_cancel_maxsz (op_decode_hdr_maxsz)
35 #define encode_copy_notify_maxsz (op_encode_hdr_maxsz + \
36 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
38 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
39 #define decode_copy_notify_maxsz (op_decode_hdr_maxsz + \
40 3 + /* cnr_lease_time */\
41 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
42 1 + /* Support 1 cnr_source_server */\
44 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
45 #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
46 encode_fallocate_maxsz)
47 #define decode_deallocate_maxsz (op_decode_hdr_maxsz)
48 #define encode_read_plus_maxsz (op_encode_hdr_maxsz + \
49 encode_stateid_maxsz + 3)
50 #define NFS42_READ_PLUS_SEGMENT_SIZE (1 /* data_content4 */ + \
51 2 /* data_info4.di_offset */ + \
52 2 /* data_info4.di_length */)
53 #define decode_read_plus_maxsz (op_decode_hdr_maxsz + \
55 1 /* rpr_contents count */ + \
56 2 * NFS42_READ_PLUS_SEGMENT_SIZE)
57 #define encode_seek_maxsz (op_encode_hdr_maxsz + \
58 encode_stateid_maxsz + \
61 #define decode_seek_maxsz (op_decode_hdr_maxsz + \
66 #define encode_io_info_maxsz 4
67 #define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \
70 encode_stateid_maxsz + \
71 encode_io_info_maxsz + \
72 encode_io_info_maxsz + \
73 1 /* opaque devaddr4 length */ + \
74 XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE))
75 #define decode_layoutstats_maxsz (op_decode_hdr_maxsz)
76 #define encode_device_error_maxsz (XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
77 1 /* status */ + 1 /* opnum */)
78 #define encode_layouterror_maxsz (op_decode_hdr_maxsz + \
81 encode_stateid_maxsz + \
82 1 /* Array size */ + \
83 encode_device_error_maxsz)
84 #define decode_layouterror_maxsz (op_decode_hdr_maxsz)
85 #define encode_clone_maxsz (encode_stateid_maxsz + \
86 encode_stateid_maxsz + \
87 2 /* src offset */ + \
88 2 /* dst offset */ + \
90 #define decode_clone_maxsz (op_decode_hdr_maxsz)
92 #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
93 encode_sequence_maxsz + \
94 encode_putfh_maxsz + \
95 encode_allocate_maxsz + \
97 #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
98 decode_sequence_maxsz + \
99 decode_putfh_maxsz + \
100 decode_allocate_maxsz + \
101 decode_getattr_maxsz)
102 #define NFS4_enc_copy_sz (compound_encode_hdr_maxsz + \
103 encode_sequence_maxsz + \
104 encode_putfh_maxsz + \
105 encode_savefh_maxsz + \
106 encode_putfh_maxsz + \
107 encode_copy_maxsz + \
109 #define NFS4_dec_copy_sz (compound_decode_hdr_maxsz + \
110 decode_sequence_maxsz + \
111 decode_putfh_maxsz + \
112 decode_savefh_maxsz + \
113 decode_putfh_maxsz + \
114 decode_copy_maxsz + \
116 #define NFS4_enc_offload_cancel_sz (compound_encode_hdr_maxsz + \
117 encode_sequence_maxsz + \
118 encode_putfh_maxsz + \
119 encode_offload_cancel_maxsz)
120 #define NFS4_dec_offload_cancel_sz (compound_decode_hdr_maxsz + \
121 decode_sequence_maxsz + \
122 decode_putfh_maxsz + \
123 decode_offload_cancel_maxsz)
124 #define NFS4_enc_copy_notify_sz (compound_encode_hdr_maxsz + \
125 encode_putfh_maxsz + \
126 encode_copy_notify_maxsz)
127 #define NFS4_dec_copy_notify_sz (compound_decode_hdr_maxsz + \
128 decode_putfh_maxsz + \
129 decode_copy_notify_maxsz)
130 #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
131 encode_sequence_maxsz + \
132 encode_putfh_maxsz + \
133 encode_deallocate_maxsz + \
134 encode_getattr_maxsz)
135 #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
136 decode_sequence_maxsz + \
137 decode_putfh_maxsz + \
138 decode_deallocate_maxsz + \
139 decode_getattr_maxsz)
140 #define NFS4_enc_read_plus_sz (compound_encode_hdr_maxsz + \
141 encode_sequence_maxsz + \
142 encode_putfh_maxsz + \
143 encode_read_plus_maxsz)
144 #define NFS4_dec_read_plus_sz (compound_decode_hdr_maxsz + \
145 decode_sequence_maxsz + \
146 decode_putfh_maxsz + \
147 decode_read_plus_maxsz)
148 #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
149 encode_sequence_maxsz + \
150 encode_putfh_maxsz + \
152 #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
153 decode_sequence_maxsz + \
154 decode_putfh_maxsz + \
156 #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
157 encode_sequence_maxsz + \
158 encode_putfh_maxsz + \
159 PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
160 #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
161 decode_sequence_maxsz + \
162 decode_putfh_maxsz + \
163 PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
164 #define NFS4_enc_layouterror_sz (compound_encode_hdr_maxsz + \
165 encode_sequence_maxsz + \
166 encode_putfh_maxsz + \
167 NFS42_LAYOUTERROR_MAX * \
168 encode_layouterror_maxsz)
169 #define NFS4_dec_layouterror_sz (compound_decode_hdr_maxsz + \
170 decode_sequence_maxsz + \
171 decode_putfh_maxsz + \
172 NFS42_LAYOUTERROR_MAX * \
173 decode_layouterror_maxsz)
174 #define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \
175 encode_sequence_maxsz + \
176 encode_putfh_maxsz + \
177 encode_savefh_maxsz + \
178 encode_putfh_maxsz + \
179 encode_clone_maxsz + \
180 encode_getattr_maxsz)
181 #define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \
182 decode_sequence_maxsz + \
183 decode_putfh_maxsz + \
184 decode_savefh_maxsz + \
185 decode_putfh_maxsz + \
186 decode_clone_maxsz + \
187 decode_getattr_maxsz)
189 /* Not limited by NFS itself, limited by the generic xattr code */
190 #define nfs4_xattr_name_maxsz XDR_QUADLEN(XATTR_NAME_MAX)
192 #define encode_getxattr_maxsz (op_encode_hdr_maxsz + 1 + \
193 nfs4_xattr_name_maxsz)
194 #define decode_getxattr_maxsz (op_decode_hdr_maxsz + 1 + pagepad_maxsz)
195 #define encode_setxattr_maxsz (op_encode_hdr_maxsz + \
196 1 + nfs4_xattr_name_maxsz + 1)
197 #define decode_setxattr_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
198 #define encode_listxattrs_maxsz (op_encode_hdr_maxsz + 2 + 1)
199 #define decode_listxattrs_maxsz (op_decode_hdr_maxsz + 2 + 1 + 1 + 1)
200 #define encode_removexattr_maxsz (op_encode_hdr_maxsz + 1 + \
201 nfs4_xattr_name_maxsz)
202 #define decode_removexattr_maxsz (op_decode_hdr_maxsz + \
203 decode_change_info_maxsz)
205 #define NFS4_enc_getxattr_sz (compound_encode_hdr_maxsz + \
206 encode_sequence_maxsz + \
207 encode_putfh_maxsz + \
208 encode_getxattr_maxsz)
209 #define NFS4_dec_getxattr_sz (compound_decode_hdr_maxsz + \
210 decode_sequence_maxsz + \
211 decode_putfh_maxsz + \
212 decode_getxattr_maxsz)
213 #define NFS4_enc_setxattr_sz (compound_encode_hdr_maxsz + \
214 encode_sequence_maxsz + \
215 encode_putfh_maxsz + \
216 encode_setxattr_maxsz)
217 #define NFS4_dec_setxattr_sz (compound_decode_hdr_maxsz + \
218 decode_sequence_maxsz + \
219 decode_putfh_maxsz + \
220 decode_setxattr_maxsz)
221 #define NFS4_enc_listxattrs_sz (compound_encode_hdr_maxsz + \
222 encode_sequence_maxsz + \
223 encode_putfh_maxsz + \
224 encode_listxattrs_maxsz)
225 #define NFS4_dec_listxattrs_sz (compound_decode_hdr_maxsz + \
226 decode_sequence_maxsz + \
227 decode_putfh_maxsz + \
228 decode_listxattrs_maxsz)
229 #define NFS4_enc_removexattr_sz (compound_encode_hdr_maxsz + \
230 encode_sequence_maxsz + \
231 encode_putfh_maxsz + \
232 encode_removexattr_maxsz)
233 #define NFS4_dec_removexattr_sz (compound_decode_hdr_maxsz + \
234 decode_sequence_maxsz + \
235 decode_putfh_maxsz + \
236 decode_removexattr_maxsz)
239 * These values specify the maximum amount of data that is not
240 * associated with the extended attribute name or extended
241 * attribute list in the SETXATTR, GETXATTR and LISTXATTR
244 const u32 nfs42_maxsetxattr_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
245 compound_encode_hdr_maxsz +
246 encode_sequence_maxsz +
247 encode_putfh_maxsz + 1 +
248 nfs4_xattr_name_maxsz)
251 const u32 nfs42_maxgetxattr_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
252 compound_decode_hdr_maxsz +
253 decode_sequence_maxsz +
254 decode_putfh_maxsz + 1) * XDR_UNIT);
256 const u32 nfs42_maxlistxattrs_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
257 compound_decode_hdr_maxsz +
258 decode_sequence_maxsz +
259 decode_putfh_maxsz + 3) * XDR_UNIT);
261 static void encode_fallocate(struct xdr_stream *xdr,
262 const struct nfs42_falloc_args *args)
264 encode_nfs4_stateid(xdr, &args->falloc_stateid);
265 encode_uint64(xdr, args->falloc_offset);
266 encode_uint64(xdr, args->falloc_length);
269 static void encode_allocate(struct xdr_stream *xdr,
270 const struct nfs42_falloc_args *args,
271 struct compound_hdr *hdr)
273 encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
274 encode_fallocate(xdr, args);
277 static void encode_nl4_server(struct xdr_stream *xdr,
278 const struct nl4_server *ns)
280 encode_uint32(xdr, ns->nl4_type);
281 switch (ns->nl4_type) {
284 encode_string(xdr, ns->u.nl4_str_sz, ns->u.nl4_str);
287 encode_string(xdr, ns->u.nl4_addr.netid_len,
288 ns->u.nl4_addr.netid);
289 encode_string(xdr, ns->u.nl4_addr.addr_len,
290 ns->u.nl4_addr.addr);
297 static void encode_copy(struct xdr_stream *xdr,
298 const struct nfs42_copy_args *args,
299 struct compound_hdr *hdr)
301 encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr);
302 encode_nfs4_stateid(xdr, &args->src_stateid);
303 encode_nfs4_stateid(xdr, &args->dst_stateid);
305 encode_uint64(xdr, args->src_pos);
306 encode_uint64(xdr, args->dst_pos);
307 encode_uint64(xdr, args->count);
309 encode_uint32(xdr, 1); /* consecutive = true */
310 encode_uint32(xdr, args->sync);
311 if (args->cp_src == NULL) { /* intra-ssc */
312 encode_uint32(xdr, 0); /* no src server list */
315 encode_uint32(xdr, 1); /* supporting 1 server */
316 encode_nl4_server(xdr, args->cp_src);
319 static void encode_offload_cancel(struct xdr_stream *xdr,
320 const struct nfs42_offload_status_args *args,
321 struct compound_hdr *hdr)
323 encode_op_hdr(xdr, OP_OFFLOAD_CANCEL, decode_offload_cancel_maxsz, hdr);
324 encode_nfs4_stateid(xdr, &args->osa_stateid);
327 static void encode_copy_notify(struct xdr_stream *xdr,
328 const struct nfs42_copy_notify_args *args,
329 struct compound_hdr *hdr)
331 encode_op_hdr(xdr, OP_COPY_NOTIFY, decode_copy_notify_maxsz, hdr);
332 encode_nfs4_stateid(xdr, &args->cna_src_stateid);
333 encode_nl4_server(xdr, &args->cna_dst);
336 static void encode_deallocate(struct xdr_stream *xdr,
337 const struct nfs42_falloc_args *args,
338 struct compound_hdr *hdr)
340 encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
341 encode_fallocate(xdr, args);
344 static void encode_read_plus(struct xdr_stream *xdr,
345 const struct nfs_pgio_args *args,
346 struct compound_hdr *hdr)
348 encode_op_hdr(xdr, OP_READ_PLUS, decode_read_plus_maxsz, hdr);
349 encode_nfs4_stateid(xdr, &args->stateid);
350 encode_uint64(xdr, args->offset);
351 encode_uint32(xdr, args->count);
354 static void encode_seek(struct xdr_stream *xdr,
355 const struct nfs42_seek_args *args,
356 struct compound_hdr *hdr)
358 encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
359 encode_nfs4_stateid(xdr, &args->sa_stateid);
360 encode_uint64(xdr, args->sa_offset);
361 encode_uint32(xdr, args->sa_what);
364 static void encode_layoutstats(struct xdr_stream *xdr,
365 const struct nfs42_layoutstat_args *args,
366 struct nfs42_layoutstat_devinfo *devinfo,
367 struct compound_hdr *hdr)
371 encode_op_hdr(xdr, OP_LAYOUTSTATS, decode_layoutstats_maxsz, hdr);
372 p = reserve_space(xdr, 8 + 8);
373 p = xdr_encode_hyper(p, devinfo->offset);
374 p = xdr_encode_hyper(p, devinfo->length);
375 encode_nfs4_stateid(xdr, &args->stateid);
376 p = reserve_space(xdr, 4*8 + NFS4_DEVICEID4_SIZE + 4);
377 p = xdr_encode_hyper(p, devinfo->read_count);
378 p = xdr_encode_hyper(p, devinfo->read_bytes);
379 p = xdr_encode_hyper(p, devinfo->write_count);
380 p = xdr_encode_hyper(p, devinfo->write_bytes);
381 p = xdr_encode_opaque_fixed(p, devinfo->dev_id.data,
382 NFS4_DEVICEID4_SIZE);
383 /* Encode layoutupdate4 */
384 *p++ = cpu_to_be32(devinfo->layout_type);
385 if (devinfo->ld_private.ops)
386 devinfo->ld_private.ops->encode(xdr, args,
387 &devinfo->ld_private);
389 encode_uint32(xdr, 0);
392 static void encode_clone(struct xdr_stream *xdr,
393 const struct nfs42_clone_args *args,
394 struct compound_hdr *hdr)
398 encode_op_hdr(xdr, OP_CLONE, decode_clone_maxsz, hdr);
399 encode_nfs4_stateid(xdr, &args->src_stateid);
400 encode_nfs4_stateid(xdr, &args->dst_stateid);
401 p = reserve_space(xdr, 3*8);
402 p = xdr_encode_hyper(p, args->src_offset);
403 p = xdr_encode_hyper(p, args->dst_offset);
404 xdr_encode_hyper(p, args->count);
407 static void encode_device_error(struct xdr_stream *xdr,
408 const struct nfs42_device_error *error)
412 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 2*4);
413 p = xdr_encode_opaque_fixed(p, error->dev_id.data,
414 NFS4_DEVICEID4_SIZE);
415 *p++ = cpu_to_be32(error->status);
416 *p = cpu_to_be32(error->opnum);
419 static void encode_layouterror(struct xdr_stream *xdr,
420 const struct nfs42_layout_error *args,
421 struct compound_hdr *hdr)
425 encode_op_hdr(xdr, OP_LAYOUTERROR, decode_layouterror_maxsz, hdr);
426 p = reserve_space(xdr, 8 + 8);
427 p = xdr_encode_hyper(p, args->offset);
428 p = xdr_encode_hyper(p, args->length);
429 encode_nfs4_stateid(xdr, &args->stateid);
430 p = reserve_space(xdr, 4);
432 encode_device_error(xdr, &args->errors[0]);
435 static void encode_setxattr(struct xdr_stream *xdr,
436 const struct nfs42_setxattrargs *arg,
437 struct compound_hdr *hdr)
441 BUILD_BUG_ON(XATTR_CREATE != SETXATTR4_CREATE);
442 BUILD_BUG_ON(XATTR_REPLACE != SETXATTR4_REPLACE);
444 encode_op_hdr(xdr, OP_SETXATTR, decode_setxattr_maxsz, hdr);
445 p = reserve_space(xdr, 4);
446 *p = cpu_to_be32(arg->xattr_flags);
447 encode_string(xdr, strlen(arg->xattr_name), arg->xattr_name);
448 p = reserve_space(xdr, 4);
449 *p = cpu_to_be32(arg->xattr_len);
451 xdr_write_pages(xdr, arg->xattr_pages, 0, arg->xattr_len);
454 static int decode_setxattr(struct xdr_stream *xdr,
455 struct nfs4_change_info *cinfo)
459 status = decode_op_hdr(xdr, OP_SETXATTR);
462 status = decode_change_info(xdr, cinfo);
468 static void encode_getxattr(struct xdr_stream *xdr, const char *name,
469 struct compound_hdr *hdr)
471 encode_op_hdr(xdr, OP_GETXATTR, decode_getxattr_maxsz, hdr);
472 encode_string(xdr, strlen(name), name);
475 static int decode_getxattr(struct xdr_stream *xdr,
476 struct nfs42_getxattrres *res,
477 struct rpc_rqst *req)
483 status = decode_op_hdr(xdr, OP_GETXATTR);
487 p = xdr_inline_decode(xdr, 4);
491 len = be32_to_cpup(p);
494 * Only check against the page length here. The actual
495 * requested length may be smaller, but that is only
496 * checked against after possibly caching a valid reply.
498 if (len > req->rq_rcv_buf.page_len)
501 res->xattr_len = len;
504 rdlen = xdr_read_pages(xdr, len);
512 static void encode_removexattr(struct xdr_stream *xdr, const char *name,
513 struct compound_hdr *hdr)
515 encode_op_hdr(xdr, OP_REMOVEXATTR, decode_removexattr_maxsz, hdr);
516 encode_string(xdr, strlen(name), name);
520 static int decode_removexattr(struct xdr_stream *xdr,
521 struct nfs4_change_info *cinfo)
525 status = decode_op_hdr(xdr, OP_REMOVEXATTR);
529 status = decode_change_info(xdr, cinfo);
534 static void encode_listxattrs(struct xdr_stream *xdr,
535 const struct nfs42_listxattrsargs *arg,
536 struct compound_hdr *hdr)
540 encode_op_hdr(xdr, OP_LISTXATTRS, decode_listxattrs_maxsz, hdr);
542 p = reserve_space(xdr, 12);
546 p = xdr_encode_hyper(p, arg->cookie);
548 * RFC 8276 says to specify the full max length of the LISTXATTRS
549 * XDR reply. Count is set to the XDR length of the names array
550 * plus the EOF marker. So, add the cookie and the names count.
552 *p = cpu_to_be32(arg->count + 8 + 4);
555 static int decode_listxattrs(struct xdr_stream *xdr,
556 struct nfs42_listxattrsres *res)
560 u32 count, len, ulen;
564 status = decode_op_hdr(xdr, OP_LISTXATTRS);
567 * Special case: for LISTXATTRS, NFS4ERR_TOOSMALL
568 * should be translated to ERANGE.
570 if (status == -ETOOSMALL)
573 * Special case: for LISTXATTRS, NFS4ERR_NOXATTR
574 * should be translated to success with zero-length reply.
576 if (status == -ENODATA) {
583 p = xdr_inline_decode(xdr, 8);
587 xdr_decode_hyper(p, &res->cookie);
589 p = xdr_inline_decode(xdr, 4);
593 left = res->xattr_len;
594 buf = res->xattr_buf;
596 count = be32_to_cpup(p);
600 * We have asked for enough room to encode the maximum number
601 * of possible attribute names, so everything should fit.
603 * But, don't rely on that assumption. Just decode entries
604 * until they don't fit anymore, just in case the server did
608 p = xdr_inline_decode(xdr, 4);
612 len = be32_to_cpup(p);
613 if (len > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) {
618 p = xdr_inline_decode(xdr, len);
622 ulen = len + XATTR_USER_PREFIX_LEN + 1;
629 memcpy(buf, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
630 memcpy(buf + XATTR_USER_PREFIX_LEN, p, len);
639 p = xdr_inline_decode(xdr, 4);
643 res->eof = be32_to_cpup(p);
644 res->copied = copied;
647 if (status == -ERANGE && res->xattr_len == XATTR_LIST_MAX)
654 * Encode ALLOCATE request
656 static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
657 struct xdr_stream *xdr,
660 const struct nfs42_falloc_args *args = data;
661 struct compound_hdr hdr = {
662 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
665 encode_compound_hdr(xdr, req, &hdr);
666 encode_sequence(xdr, &args->seq_args, &hdr);
667 encode_putfh(xdr, args->falloc_fh, &hdr);
668 encode_allocate(xdr, args, &hdr);
669 encode_getfattr(xdr, args->falloc_bitmask, &hdr);
673 static void encode_copy_commit(struct xdr_stream *xdr,
674 const struct nfs42_copy_args *args,
675 struct compound_hdr *hdr)
679 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
680 p = reserve_space(xdr, 12);
681 p = xdr_encode_hyper(p, args->dst_pos);
682 *p = cpu_to_be32(args->count);
686 * Encode COPY request
688 static void nfs4_xdr_enc_copy(struct rpc_rqst *req,
689 struct xdr_stream *xdr,
692 const struct nfs42_copy_args *args = data;
693 struct compound_hdr hdr = {
694 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
697 encode_compound_hdr(xdr, req, &hdr);
698 encode_sequence(xdr, &args->seq_args, &hdr);
699 encode_putfh(xdr, args->src_fh, &hdr);
700 encode_savefh(xdr, &hdr);
701 encode_putfh(xdr, args->dst_fh, &hdr);
702 encode_copy(xdr, args, &hdr);
704 encode_copy_commit(xdr, args, &hdr);
709 * Encode OFFLOAD_CANEL request
711 static void nfs4_xdr_enc_offload_cancel(struct rpc_rqst *req,
712 struct xdr_stream *xdr,
715 const struct nfs42_offload_status_args *args = data;
716 struct compound_hdr hdr = {
717 .minorversion = nfs4_xdr_minorversion(&args->osa_seq_args),
720 encode_compound_hdr(xdr, req, &hdr);
721 encode_sequence(xdr, &args->osa_seq_args, &hdr);
722 encode_putfh(xdr, args->osa_src_fh, &hdr);
723 encode_offload_cancel(xdr, args, &hdr);
728 * Encode COPY_NOTIFY request
730 static void nfs4_xdr_enc_copy_notify(struct rpc_rqst *req,
731 struct xdr_stream *xdr,
734 const struct nfs42_copy_notify_args *args = data;
735 struct compound_hdr hdr = {
736 .minorversion = nfs4_xdr_minorversion(&args->cna_seq_args),
739 encode_compound_hdr(xdr, req, &hdr);
740 encode_sequence(xdr, &args->cna_seq_args, &hdr);
741 encode_putfh(xdr, args->cna_src_fh, &hdr);
742 encode_copy_notify(xdr, args, &hdr);
747 * Encode DEALLOCATE request
749 static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
750 struct xdr_stream *xdr,
753 const struct nfs42_falloc_args *args = data;
754 struct compound_hdr hdr = {
755 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
758 encode_compound_hdr(xdr, req, &hdr);
759 encode_sequence(xdr, &args->seq_args, &hdr);
760 encode_putfh(xdr, args->falloc_fh, &hdr);
761 encode_deallocate(xdr, args, &hdr);
762 encode_getfattr(xdr, args->falloc_bitmask, &hdr);
767 * Encode READ_PLUS request
769 static void nfs4_xdr_enc_read_plus(struct rpc_rqst *req,
770 struct xdr_stream *xdr,
773 const struct nfs_pgio_args *args = data;
774 struct compound_hdr hdr = {
775 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
778 encode_compound_hdr(xdr, req, &hdr);
779 encode_sequence(xdr, &args->seq_args, &hdr);
780 encode_putfh(xdr, args->fh, &hdr);
781 encode_read_plus(xdr, args, &hdr);
783 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
784 args->count, hdr.replen);
789 * Encode SEEK request
791 static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
792 struct xdr_stream *xdr,
795 const struct nfs42_seek_args *args = data;
796 struct compound_hdr hdr = {
797 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
800 encode_compound_hdr(xdr, req, &hdr);
801 encode_sequence(xdr, &args->seq_args, &hdr);
802 encode_putfh(xdr, args->sa_fh, &hdr);
803 encode_seek(xdr, args, &hdr);
808 * Encode LAYOUTSTATS request
810 static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req,
811 struct xdr_stream *xdr,
814 const struct nfs42_layoutstat_args *args = data;
817 struct compound_hdr hdr = {
818 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
821 encode_compound_hdr(xdr, req, &hdr);
822 encode_sequence(xdr, &args->seq_args, &hdr);
823 encode_putfh(xdr, args->fh, &hdr);
824 WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
825 for (i = 0; i < args->num_dev; i++)
826 encode_layoutstats(xdr, args, &args->devinfo[i], &hdr);
831 * Encode CLONE request
833 static void nfs4_xdr_enc_clone(struct rpc_rqst *req,
834 struct xdr_stream *xdr,
837 const struct nfs42_clone_args *args = data;
838 struct compound_hdr hdr = {
839 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
842 encode_compound_hdr(xdr, req, &hdr);
843 encode_sequence(xdr, &args->seq_args, &hdr);
844 encode_putfh(xdr, args->src_fh, &hdr);
845 encode_savefh(xdr, &hdr);
846 encode_putfh(xdr, args->dst_fh, &hdr);
847 encode_clone(xdr, args, &hdr);
848 encode_getfattr(xdr, args->dst_bitmask, &hdr);
853 * Encode LAYOUTERROR request
855 static void nfs4_xdr_enc_layouterror(struct rpc_rqst *req,
856 struct xdr_stream *xdr,
859 const struct nfs42_layouterror_args *args = data;
860 struct compound_hdr hdr = {
861 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
865 encode_compound_hdr(xdr, req, &hdr);
866 encode_sequence(xdr, &args->seq_args, &hdr);
867 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
868 for (i = 0; i < args->num_errors; i++)
869 encode_layouterror(xdr, &args->errors[i], &hdr);
873 static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
875 return decode_op_hdr(xdr, OP_ALLOCATE);
878 static int decode_write_response(struct xdr_stream *xdr,
879 struct nfs42_write_res *res)
884 p = xdr_inline_decode(xdr, 4);
887 count = be32_to_cpup(p);
890 else if (count == 1) {
891 status = decode_opaque_fixed(xdr, &res->stateid,
893 if (unlikely(status))
896 p = xdr_inline_decode(xdr, 8 + 4);
899 p = xdr_decode_hyper(p, &res->count);
900 res->verifier.committed = be32_to_cpup(p);
901 return decode_verifier(xdr, &res->verifier.verifier);
904 static int decode_nl4_server(struct xdr_stream *xdr, struct nl4_server *ns)
906 struct nfs42_netaddr *naddr;
913 p = xdr_inline_decode(xdr, 4);
916 ns->nl4_type = be32_to_cpup(p);
917 switch (ns->nl4_type) {
920 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
921 if (unlikely(status))
923 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
925 memcpy(&ns->u.nl4_str, dummy_str, dummy);
926 ns->u.nl4_str_sz = dummy;
929 naddr = &ns->u.nl4_addr;
932 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
933 if (unlikely(status))
935 if (unlikely(dummy > RPCBIND_MAXNETIDLEN))
937 naddr->netid_len = dummy;
938 memcpy(naddr->netid, dummy_str, naddr->netid_len);
941 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
942 if (unlikely(status))
944 if (unlikely(dummy > RPCBIND_MAXUADDRLEN))
946 naddr->addr_len = dummy;
947 memcpy(naddr->addr, dummy_str, naddr->addr_len);
956 static int decode_copy_requirements(struct xdr_stream *xdr,
957 struct nfs42_copy_res *res) {
960 p = xdr_inline_decode(xdr, 4 + 4);
964 res->consecutive = be32_to_cpup(p++);
965 res->synchronous = be32_to_cpup(p++);
969 static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res)
973 status = decode_op_hdr(xdr, OP_COPY);
974 if (status == NFS4ERR_OFFLOAD_NO_REQS) {
975 status = decode_copy_requirements(xdr, res);
978 return NFS4ERR_OFFLOAD_NO_REQS;
982 status = decode_write_response(xdr, &res->write_res);
986 return decode_copy_requirements(xdr, res);
989 static int decode_offload_cancel(struct xdr_stream *xdr,
990 struct nfs42_offload_status_res *res)
992 return decode_op_hdr(xdr, OP_OFFLOAD_CANCEL);
995 static int decode_copy_notify(struct xdr_stream *xdr,
996 struct nfs42_copy_notify_res *res)
1001 status = decode_op_hdr(xdr, OP_COPY_NOTIFY);
1004 /* cnr_lease_time */
1005 p = xdr_inline_decode(xdr, 12);
1008 p = xdr_decode_hyper(p, &res->cnr_lease_time.seconds);
1009 res->cnr_lease_time.nseconds = be32_to_cpup(p);
1011 status = decode_opaque_fixed(xdr, &res->cnr_stateid, NFS4_STATEID_SIZE);
1012 if (unlikely(status))
1015 /* number of source addresses */
1016 p = xdr_inline_decode(xdr, 4);
1020 count = be32_to_cpup(p);
1022 pr_warn("NFS: %s: nsvr %d > Supported. Use first servers\n",
1025 status = decode_nl4_server(xdr, &res->cnr_src);
1026 if (unlikely(status))
1031 static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
1033 return decode_op_hdr(xdr, OP_DEALLOCATE);
1036 struct read_plus_segment {
1037 enum data_content4 type;
1051 static inline uint64_t read_plus_segment_length(struct read_plus_segment *seg)
1053 return seg->type == NFS4_CONTENT_DATA ? seg->data.length : seg->hole.length;
1056 static int decode_read_plus_segment(struct xdr_stream *xdr,
1057 struct read_plus_segment *seg)
1061 p = xdr_inline_decode(xdr, 4);
1064 seg->type = be32_to_cpup(p++);
1066 p = xdr_inline_decode(xdr, seg->type == NFS4_CONTENT_DATA ? 12 : 16);
1069 p = xdr_decode_hyper(p, &seg->offset);
1071 if (seg->type == NFS4_CONTENT_DATA) {
1073 uint32_t len = be32_to_cpup(p);
1075 seg->data.length = len;
1076 seg->data.from = xdr_stream_pos(xdr);
1078 if (!xdr_stream_subsegment(xdr, &buf, xdr_align_size(len)))
1080 } else if (seg->type == NFS4_CONTENT_HOLE) {
1081 xdr_decode_hyper(p, &seg->hole.length);
1087 static int process_read_plus_segment(struct xdr_stream *xdr,
1088 struct nfs_pgio_args *args,
1089 struct nfs_pgio_res *res,
1090 struct read_plus_segment *seg)
1092 unsigned long offset = seg->offset;
1093 unsigned long length = read_plus_segment_length(seg);
1094 unsigned int bufpos;
1096 if (offset + length < args->offset)
1098 else if (offset > args->offset + args->count) {
1101 } else if (offset < args->offset) {
1102 length -= (args->offset - offset);
1103 offset = args->offset;
1104 } else if (offset + length > args->offset + args->count) {
1105 length = (args->offset + args->count) - offset;
1109 bufpos = xdr->buf->head[0].iov_len + (offset - args->offset);
1110 if (seg->type == NFS4_CONTENT_HOLE)
1111 return xdr_stream_zero(xdr, bufpos, length);
1113 return xdr_stream_move_subsegment(xdr, seg->data.from, bufpos, length);
1116 static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
1118 struct nfs_pgio_header *hdr =
1119 container_of(res, struct nfs_pgio_header, res);
1120 struct nfs_pgio_args *args = &hdr->args;
1122 struct read_plus_segment *segs;
1124 char scratch_buf[16];
1127 status = decode_op_hdr(xdr, OP_READ_PLUS);
1131 p = xdr_inline_decode(xdr, 4 + 4);
1136 res->eof = be32_to_cpup(p++);
1137 segments = be32_to_cpup(p++);
1141 segs = kmalloc_array(segments, sizeof(*segs), GFP_KERNEL);
1145 xdr_set_scratch_buffer(xdr, &scratch_buf, sizeof(scratch_buf));
1147 for (i = 0; i < segments; i++) {
1148 status = decode_read_plus_segment(xdr, &segs[i]);
1153 xdr_set_pagelen(xdr, xdr_align_size(args->count));
1154 for (i = segments; i > 0; i--)
1155 res->count += process_read_plus_segment(xdr, args, res, &segs[i-1]);
1163 static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
1168 status = decode_op_hdr(xdr, OP_SEEK);
1172 p = xdr_inline_decode(xdr, 4 + 8);
1176 res->sr_eof = be32_to_cpup(p++);
1177 p = xdr_decode_hyper(p, &res->sr_offset);
1181 static int decode_layoutstats(struct xdr_stream *xdr)
1183 return decode_op_hdr(xdr, OP_LAYOUTSTATS);
1186 static int decode_clone(struct xdr_stream *xdr)
1188 return decode_op_hdr(xdr, OP_CLONE);
1191 static int decode_layouterror(struct xdr_stream *xdr)
1193 return decode_op_hdr(xdr, OP_LAYOUTERROR);
1197 * Decode ALLOCATE request
1199 static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
1200 struct xdr_stream *xdr,
1203 struct nfs42_falloc_res *res = data;
1204 struct compound_hdr hdr;
1207 status = decode_compound_hdr(xdr, &hdr);
1210 status = decode_sequence(xdr, &res->seq_res, rqstp);
1213 status = decode_putfh(xdr);
1216 status = decode_allocate(xdr, res);
1219 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
1225 * Decode COPY response
1227 static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp,
1228 struct xdr_stream *xdr,
1231 struct nfs42_copy_res *res = data;
1232 struct compound_hdr hdr;
1235 status = decode_compound_hdr(xdr, &hdr);
1238 status = decode_sequence(xdr, &res->seq_res, rqstp);
1241 status = decode_putfh(xdr);
1244 status = decode_savefh(xdr);
1247 status = decode_putfh(xdr);
1250 status = decode_copy(xdr, res);
1253 if (res->commit_res.verf)
1254 status = decode_commit(xdr, &res->commit_res);
1260 * Decode OFFLOAD_CANCEL response
1262 static int nfs4_xdr_dec_offload_cancel(struct rpc_rqst *rqstp,
1263 struct xdr_stream *xdr,
1266 struct nfs42_offload_status_res *res = data;
1267 struct compound_hdr hdr;
1270 status = decode_compound_hdr(xdr, &hdr);
1273 status = decode_sequence(xdr, &res->osr_seq_res, rqstp);
1276 status = decode_putfh(xdr);
1279 status = decode_offload_cancel(xdr, res);
1286 * Decode COPY_NOTIFY response
1288 static int nfs4_xdr_dec_copy_notify(struct rpc_rqst *rqstp,
1289 struct xdr_stream *xdr,
1292 struct nfs42_copy_notify_res *res = data;
1293 struct compound_hdr hdr;
1296 status = decode_compound_hdr(xdr, &hdr);
1299 status = decode_sequence(xdr, &res->cnr_seq_res, rqstp);
1302 status = decode_putfh(xdr);
1305 status = decode_copy_notify(xdr, res);
1312 * Decode DEALLOCATE request
1314 static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
1315 struct xdr_stream *xdr,
1318 struct nfs42_falloc_res *res = data;
1319 struct compound_hdr hdr;
1322 status = decode_compound_hdr(xdr, &hdr);
1325 status = decode_sequence(xdr, &res->seq_res, rqstp);
1328 status = decode_putfh(xdr);
1331 status = decode_deallocate(xdr, res);
1334 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
1340 * Decode READ_PLUS request
1342 static int nfs4_xdr_dec_read_plus(struct rpc_rqst *rqstp,
1343 struct xdr_stream *xdr,
1346 struct nfs_pgio_res *res = data;
1347 struct compound_hdr hdr;
1350 status = decode_compound_hdr(xdr, &hdr);
1353 status = decode_sequence(xdr, &res->seq_res, rqstp);
1356 status = decode_putfh(xdr);
1359 status = decode_read_plus(xdr, res);
1361 status = res->count;
1367 * Decode SEEK request
1369 static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
1370 struct xdr_stream *xdr,
1373 struct nfs42_seek_res *res = data;
1374 struct compound_hdr hdr;
1377 status = decode_compound_hdr(xdr, &hdr);
1380 status = decode_sequence(xdr, &res->seq_res, rqstp);
1383 status = decode_putfh(xdr);
1386 status = decode_seek(xdr, res);
1392 * Decode LAYOUTSTATS request
1394 static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp,
1395 struct xdr_stream *xdr,
1398 struct nfs42_layoutstat_res *res = data;
1399 struct compound_hdr hdr;
1402 status = decode_compound_hdr(xdr, &hdr);
1405 status = decode_sequence(xdr, &res->seq_res, rqstp);
1408 status = decode_putfh(xdr);
1411 WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
1412 for (i = 0; i < res->num_dev; i++) {
1413 status = decode_layoutstats(xdr);
1418 res->rpc_status = status;
1423 * Decode CLONE request
1425 static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp,
1426 struct xdr_stream *xdr,
1429 struct nfs42_clone_res *res = data;
1430 struct compound_hdr hdr;
1433 status = decode_compound_hdr(xdr, &hdr);
1436 status = decode_sequence(xdr, &res->seq_res, rqstp);
1439 status = decode_putfh(xdr);
1442 status = decode_savefh(xdr);
1445 status = decode_putfh(xdr);
1448 status = decode_clone(xdr);
1451 decode_getfattr(xdr, res->dst_fattr, res->server);
1453 res->rpc_status = status;
1458 * Decode LAYOUTERROR request
1460 static int nfs4_xdr_dec_layouterror(struct rpc_rqst *rqstp,
1461 struct xdr_stream *xdr,
1464 struct nfs42_layouterror_res *res = data;
1465 struct compound_hdr hdr;
1468 status = decode_compound_hdr(xdr, &hdr);
1471 status = decode_sequence(xdr, &res->seq_res, rqstp);
1474 status = decode_putfh(xdr);
1476 for (i = 0; i < res->num_errors && status == 0; i++)
1477 status = decode_layouterror(xdr);
1479 res->rpc_status = status;
1483 #ifdef CONFIG_NFS_V4_2
1484 static void nfs4_xdr_enc_setxattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1487 const struct nfs42_setxattrargs *args = data;
1488 struct compound_hdr hdr = {
1489 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1492 encode_compound_hdr(xdr, req, &hdr);
1493 encode_sequence(xdr, &args->seq_args, &hdr);
1494 encode_putfh(xdr, args->fh, &hdr);
1495 encode_setxattr(xdr, args, &hdr);
1499 static int nfs4_xdr_dec_setxattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1502 struct nfs42_setxattrres *res = data;
1503 struct compound_hdr hdr;
1506 status = decode_compound_hdr(xdr, &hdr);
1509 status = decode_sequence(xdr, &res->seq_res, req);
1512 status = decode_putfh(xdr);
1516 status = decode_setxattr(xdr, &res->cinfo);
1521 static void nfs4_xdr_enc_getxattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1524 const struct nfs42_getxattrargs *args = data;
1525 struct compound_hdr hdr = {
1526 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1530 encode_compound_hdr(xdr, req, &hdr);
1531 encode_sequence(xdr, &args->seq_args, &hdr);
1532 encode_putfh(xdr, args->fh, &hdr);
1533 replen = hdr.replen + op_decode_hdr_maxsz + 1;
1534 encode_getxattr(xdr, args->xattr_name, &hdr);
1536 rpc_prepare_reply_pages(req, args->xattr_pages, 0, args->xattr_len,
1542 static int nfs4_xdr_dec_getxattr(struct rpc_rqst *rqstp,
1543 struct xdr_stream *xdr, void *data)
1545 struct nfs42_getxattrres *res = data;
1546 struct compound_hdr hdr;
1549 status = decode_compound_hdr(xdr, &hdr);
1552 status = decode_sequence(xdr, &res->seq_res, rqstp);
1555 status = decode_putfh(xdr);
1558 status = decode_getxattr(xdr, res, rqstp);
1563 static void nfs4_xdr_enc_listxattrs(struct rpc_rqst *req,
1564 struct xdr_stream *xdr, const void *data)
1566 const struct nfs42_listxattrsargs *args = data;
1567 struct compound_hdr hdr = {
1568 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1572 encode_compound_hdr(xdr, req, &hdr);
1573 encode_sequence(xdr, &args->seq_args, &hdr);
1574 encode_putfh(xdr, args->fh, &hdr);
1575 replen = hdr.replen + op_decode_hdr_maxsz + 2 + 1;
1576 encode_listxattrs(xdr, args, &hdr);
1578 rpc_prepare_reply_pages(req, args->xattr_pages, 0, args->count, replen);
1583 static int nfs4_xdr_dec_listxattrs(struct rpc_rqst *rqstp,
1584 struct xdr_stream *xdr, void *data)
1586 struct nfs42_listxattrsres *res = data;
1587 struct compound_hdr hdr;
1590 xdr_set_scratch_page(xdr, res->scratch);
1592 status = decode_compound_hdr(xdr, &hdr);
1595 status = decode_sequence(xdr, &res->seq_res, rqstp);
1598 status = decode_putfh(xdr);
1601 status = decode_listxattrs(xdr, res);
1606 static void nfs4_xdr_enc_removexattr(struct rpc_rqst *req,
1607 struct xdr_stream *xdr, const void *data)
1609 const struct nfs42_removexattrargs *args = data;
1610 struct compound_hdr hdr = {
1611 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1614 encode_compound_hdr(xdr, req, &hdr);
1615 encode_sequence(xdr, &args->seq_args, &hdr);
1616 encode_putfh(xdr, args->fh, &hdr);
1617 encode_removexattr(xdr, args->xattr_name, &hdr);
1621 static int nfs4_xdr_dec_removexattr(struct rpc_rqst *req,
1622 struct xdr_stream *xdr, void *data)
1624 struct nfs42_removexattrres *res = data;
1625 struct compound_hdr hdr;
1628 status = decode_compound_hdr(xdr, &hdr);
1631 status = decode_sequence(xdr, &res->seq_res, req);
1634 status = decode_putfh(xdr);
1638 status = decode_removexattr(xdr, &res->cinfo);
1643 #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */