blob: 5ee1b0f0d904490bb0a08478101ae49cd09acb57 [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
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007#include "nfs42.h"
8
Anna Schumakerf4ac1672014-11-25 13:18:15 -05009#define encode_fallocate_maxsz (encode_stateid_maxsz + \
10 2 /* offset */ + \
11 2 /* length */)
Anna Schumaker2e724482013-05-21 16:53:03 -040012#define NFS42_WRITE_RES_SIZE (1 /* wr_callback_id size */ +\
13 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
14 2 /* wr_count */ + \
15 1 /* wr_committed */ + \
16 XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Anna Schumakerf4ac1672014-11-25 13:18:15 -050017#define encode_allocate_maxsz (op_encode_hdr_maxsz + \
18 encode_fallocate_maxsz)
19#define decode_allocate_maxsz (op_decode_hdr_maxsz)
Anna Schumaker2e724482013-05-21 16:53:03 -040020#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 */)
Anna Schumaker624bd5b2014-11-25 13:18:16 -050028#define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
29 encode_fallocate_maxsz)
30#define decode_deallocate_maxsz (op_decode_hdr_maxsz)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -040031#define encode_seek_maxsz (op_encode_hdr_maxsz + \
32 encode_stateid_maxsz + \
33 2 /* offset */ + \
34 1 /* whence */)
35#define decode_seek_maxsz (op_decode_hdr_maxsz + \
36 1 /* eof */ + \
37 1 /* whence */ + \
38 2 /* offset */ + \
39 2 /* length */)
Trond Myklebustbe3a5d22015-06-23 19:51:55 +080040#define encode_io_info_maxsz 4
41#define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \
42 2 /* offset */ + \
43 2 /* length */ + \
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)
Peng Tao36022772015-09-26 02:24:34 +080050#define encode_clone_maxsz (encode_stateid_maxsz + \
51 encode_stateid_maxsz + \
52 2 /* src offset */ + \
53 2 /* dst offset */ + \
54 2 /* count */)
55#define decode_clone_maxsz (op_decode_hdr_maxsz)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -040056
Anna Schumakerf4ac1672014-11-25 13:18:15 -050057#define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
58 encode_putfh_maxsz + \
Anna Schumaker9a519402015-03-16 14:06:23 -040059 encode_allocate_maxsz + \
60 encode_getattr_maxsz)
Anna Schumakerf4ac1672014-11-25 13:18:15 -050061#define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
62 decode_putfh_maxsz + \
Anna Schumaker9a519402015-03-16 14:06:23 -040063 decode_allocate_maxsz + \
64 decode_getattr_maxsz)
Anna Schumaker2e724482013-05-21 16:53:03 -040065#define NFS4_enc_copy_sz (compound_encode_hdr_maxsz + \
66 encode_putfh_maxsz + \
67 encode_savefh_maxsz + \
68 encode_putfh_maxsz + \
Olga Kornievskaiae0926932017-05-08 18:02:24 -040069 encode_copy_maxsz + \
70 encode_commit_maxsz)
Anna Schumaker2e724482013-05-21 16:53:03 -040071#define NFS4_dec_copy_sz (compound_decode_hdr_maxsz + \
72 decode_putfh_maxsz + \
73 decode_savefh_maxsz + \
74 decode_putfh_maxsz + \
Olga Kornievskaiae0926932017-05-08 18:02:24 -040075 decode_copy_maxsz + \
76 decode_commit_maxsz)
Anna Schumaker624bd5b2014-11-25 13:18:16 -050077#define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
78 encode_putfh_maxsz + \
Anna Schumaker9a519402015-03-16 14:06:23 -040079 encode_deallocate_maxsz + \
80 encode_getattr_maxsz)
Anna Schumaker624bd5b2014-11-25 13:18:16 -050081#define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
82 decode_putfh_maxsz + \
Anna Schumaker9a519402015-03-16 14:06:23 -040083 decode_deallocate_maxsz + \
84 decode_getattr_maxsz)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -040085#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
86 encode_putfh_maxsz + \
87 encode_seek_maxsz)
88#define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
89 decode_putfh_maxsz + \
90 decode_seek_maxsz)
Trond Myklebustbe3a5d22015-06-23 19:51:55 +080091#define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \
92 encode_sequence_maxsz + \
93 encode_putfh_maxsz + \
94 PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz)
95#define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \
96 decode_sequence_maxsz + \
97 decode_putfh_maxsz + \
98 PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz)
Peng Tao36022772015-09-26 02:24:34 +080099#define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \
100 encode_sequence_maxsz + \
101 encode_putfh_maxsz + \
102 encode_savefh_maxsz + \
103 encode_putfh_maxsz + \
104 encode_clone_maxsz + \
105 encode_getattr_maxsz)
106#define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \
107 decode_sequence_maxsz + \
108 decode_putfh_maxsz + \
109 decode_savefh_maxsz + \
110 decode_putfh_maxsz + \
111 decode_clone_maxsz + \
112 decode_getattr_maxsz)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400113
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500114static void encode_fallocate(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200115 const struct nfs42_falloc_args *args)
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500116{
117 encode_nfs4_stateid(xdr, &args->falloc_stateid);
118 encode_uint64(xdr, args->falloc_offset);
119 encode_uint64(xdr, args->falloc_length);
120}
121
122static void encode_allocate(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200123 const struct nfs42_falloc_args *args,
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500124 struct compound_hdr *hdr)
125{
126 encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr);
127 encode_fallocate(xdr, args);
128}
129
Anna Schumaker2e724482013-05-21 16:53:03 -0400130static void encode_copy(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200131 const struct nfs42_copy_args *args,
Anna Schumaker2e724482013-05-21 16:53:03 -0400132 struct compound_hdr *hdr)
133{
134 encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr);
135 encode_nfs4_stateid(xdr, &args->src_stateid);
136 encode_nfs4_stateid(xdr, &args->dst_stateid);
137
138 encode_uint64(xdr, args->src_pos);
139 encode_uint64(xdr, args->dst_pos);
140 encode_uint64(xdr, args->count);
141
142 encode_uint32(xdr, 1); /* consecutive = true */
143 encode_uint32(xdr, 1); /* synchronous = true */
144 encode_uint32(xdr, 0); /* src server list */
145}
146
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500147static void encode_deallocate(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200148 const struct nfs42_falloc_args *args,
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500149 struct compound_hdr *hdr)
150{
151 encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
152 encode_fallocate(xdr, args);
153}
154
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400155static void encode_seek(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200156 const struct nfs42_seek_args *args,
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400157 struct compound_hdr *hdr)
158{
159 encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
160 encode_nfs4_stateid(xdr, &args->sa_stateid);
161 encode_uint64(xdr, args->sa_offset);
162 encode_uint32(xdr, args->sa_what);
163}
164
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800165static void encode_layoutstats(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200166 const struct nfs42_layoutstat_args *args,
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800167 struct nfs42_layoutstat_devinfo *devinfo,
168 struct compound_hdr *hdr)
169{
170 __be32 *p;
171
172 encode_op_hdr(xdr, OP_LAYOUTSTATS, decode_layoutstats_maxsz, hdr);
173 p = reserve_space(xdr, 8 + 8);
174 p = xdr_encode_hyper(p, devinfo->offset);
175 p = xdr_encode_hyper(p, devinfo->length);
176 encode_nfs4_stateid(xdr, &args->stateid);
177 p = reserve_space(xdr, 4*8 + NFS4_DEVICEID4_SIZE + 4);
178 p = xdr_encode_hyper(p, devinfo->read_count);
179 p = xdr_encode_hyper(p, devinfo->read_bytes);
180 p = xdr_encode_hyper(p, devinfo->write_count);
181 p = xdr_encode_hyper(p, devinfo->write_bytes);
182 p = xdr_encode_opaque_fixed(p, devinfo->dev_id.data,
183 NFS4_DEVICEID4_SIZE);
184 /* Encode layoutupdate4 */
185 *p++ = cpu_to_be32(devinfo->layout_type);
Trond Myklebust422c93c2016-10-06 17:53:20 -0400186 if (devinfo->ld_private.ops)
187 devinfo->ld_private.ops->encode(xdr, args,
188 &devinfo->ld_private);
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800189 else
190 encode_uint32(xdr, 0);
191}
192
Peng Tao36022772015-09-26 02:24:34 +0800193static void encode_clone(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200194 const struct nfs42_clone_args *args,
Peng Tao36022772015-09-26 02:24:34 +0800195 struct compound_hdr *hdr)
196{
197 __be32 *p;
198
199 encode_op_hdr(xdr, OP_CLONE, decode_clone_maxsz, hdr);
200 encode_nfs4_stateid(xdr, &args->src_stateid);
201 encode_nfs4_stateid(xdr, &args->dst_stateid);
202 p = reserve_space(xdr, 3*8);
203 p = xdr_encode_hyper(p, args->src_offset);
204 p = xdr_encode_hyper(p, args->dst_offset);
205 xdr_encode_hyper(p, args->count);
206}
207
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400208/*
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500209 * Encode ALLOCATE request
210 */
211static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
212 struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200213 const void *data)
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500214{
Christoph Hellwig0096d392017-05-08 10:01:49 +0200215 const struct nfs42_falloc_args *args = data;
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500216 struct compound_hdr hdr = {
217 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
218 };
219
220 encode_compound_hdr(xdr, req, &hdr);
221 encode_sequence(xdr, &args->seq_args, &hdr);
222 encode_putfh(xdr, args->falloc_fh, &hdr);
223 encode_allocate(xdr, args, &hdr);
Anna Schumaker9a519402015-03-16 14:06:23 -0400224 encode_getfattr(xdr, args->falloc_bitmask, &hdr);
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500225 encode_nops(&hdr);
226}
227
Olga Kornievskaiae0926932017-05-08 18:02:24 -0400228static void encode_copy_commit(struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200229 const struct nfs42_copy_args *args,
Olga Kornievskaiae0926932017-05-08 18:02:24 -0400230 struct compound_hdr *hdr)
231{
232 __be32 *p;
233
234 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
235 p = reserve_space(xdr, 12);
236 p = xdr_encode_hyper(p, args->dst_pos);
237 *p = cpu_to_be32(args->count);
238}
239
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500240/*
Anna Schumaker2e724482013-05-21 16:53:03 -0400241 * Encode COPY request
242 */
243static void nfs4_xdr_enc_copy(struct rpc_rqst *req,
244 struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200245 const void *data)
Anna Schumaker2e724482013-05-21 16:53:03 -0400246{
Christoph Hellwig0096d392017-05-08 10:01:49 +0200247 const struct nfs42_copy_args *args = data;
Anna Schumaker2e724482013-05-21 16:53:03 -0400248 struct compound_hdr hdr = {
249 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
250 };
251
252 encode_compound_hdr(xdr, req, &hdr);
253 encode_sequence(xdr, &args->seq_args, &hdr);
254 encode_putfh(xdr, args->src_fh, &hdr);
255 encode_savefh(xdr, &hdr);
256 encode_putfh(xdr, args->dst_fh, &hdr);
257 encode_copy(xdr, args, &hdr);
Olga Kornievskaiae0926932017-05-08 18:02:24 -0400258 encode_copy_commit(xdr, args, &hdr);
Anna Schumaker2e724482013-05-21 16:53:03 -0400259 encode_nops(&hdr);
260}
261
262/*
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500263 * Encode DEALLOCATE request
264 */
265static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
266 struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200267 const void *data)
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500268{
Christoph Hellwig0096d392017-05-08 10:01:49 +0200269 const struct nfs42_falloc_args *args = data;
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500270 struct compound_hdr hdr = {
271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
272 };
273
274 encode_compound_hdr(xdr, req, &hdr);
275 encode_sequence(xdr, &args->seq_args, &hdr);
276 encode_putfh(xdr, args->falloc_fh, &hdr);
277 encode_deallocate(xdr, args, &hdr);
Anna Schumaker9a519402015-03-16 14:06:23 -0400278 encode_getfattr(xdr, args->falloc_bitmask, &hdr);
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500279 encode_nops(&hdr);
280}
281
282/*
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400283 * Encode SEEK request
284 */
285static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
286 struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200287 const void *data)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400288{
Christoph Hellwig0096d392017-05-08 10:01:49 +0200289 const struct nfs42_seek_args *args = data;
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400290 struct compound_hdr hdr = {
291 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
292 };
293
294 encode_compound_hdr(xdr, req, &hdr);
295 encode_sequence(xdr, &args->seq_args, &hdr);
296 encode_putfh(xdr, args->sa_fh, &hdr);
297 encode_seek(xdr, args, &hdr);
298 encode_nops(&hdr);
299}
300
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800301/*
302 * Encode LAYOUTSTATS request
303 */
304static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req,
305 struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200306 const void *data)
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800307{
Christoph Hellwig0096d392017-05-08 10:01:49 +0200308 const struct nfs42_layoutstat_args *args = data;
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800309 int i;
310
311 struct compound_hdr hdr = {
312 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
313 };
314
315 encode_compound_hdr(xdr, req, &hdr);
316 encode_sequence(xdr, &args->seq_args, &hdr);
317 encode_putfh(xdr, args->fh, &hdr);
318 WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
319 for (i = 0; i < args->num_dev; i++)
320 encode_layoutstats(xdr, args, &args->devinfo[i], &hdr);
321 encode_nops(&hdr);
322}
323
Peng Tao36022772015-09-26 02:24:34 +0800324/*
325 * Encode CLONE request
326 */
327static void nfs4_xdr_enc_clone(struct rpc_rqst *req,
328 struct xdr_stream *xdr,
Christoph Hellwig0096d392017-05-08 10:01:49 +0200329 const void *data)
Peng Tao36022772015-09-26 02:24:34 +0800330{
Christoph Hellwig0096d392017-05-08 10:01:49 +0200331 const struct nfs42_clone_args *args = data;
Peng Tao36022772015-09-26 02:24:34 +0800332 struct compound_hdr hdr = {
333 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
334 };
335
336 encode_compound_hdr(xdr, req, &hdr);
337 encode_sequence(xdr, &args->seq_args, &hdr);
338 encode_putfh(xdr, args->src_fh, &hdr);
339 encode_savefh(xdr, &hdr);
340 encode_putfh(xdr, args->dst_fh, &hdr);
341 encode_clone(xdr, args, &hdr);
342 encode_getfattr(xdr, args->dst_bitmask, &hdr);
343 encode_nops(&hdr);
344}
345
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500346static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
347{
348 return decode_op_hdr(xdr, OP_ALLOCATE);
349}
350
Anna Schumaker2e724482013-05-21 16:53:03 -0400351static int decode_write_response(struct xdr_stream *xdr,
352 struct nfs42_write_res *res)
353{
354 __be32 *p;
Anna Schumaker2e724482013-05-21 16:53:03 -0400355
356 p = xdr_inline_decode(xdr, 4 + 8 + 4);
357 if (unlikely(!p))
358 goto out_overflow;
359
Trond Myklebust6fdf3392016-07-24 17:17:16 -0400360 /*
361 * We never use asynchronous mode, so warn if a server returns
362 * a stateid.
363 */
364 if (unlikely(*p != 0)) {
365 pr_err_once("%s: server has set unrequested "
366 "asynchronous mode\n", __func__);
367 return -EREMOTEIO;
368 }
369 p++;
Anna Schumaker2e724482013-05-21 16:53:03 -0400370 p = xdr_decode_hyper(p, &res->count);
371 res->verifier.committed = be32_to_cpup(p);
372 return decode_verifier(xdr, &res->verifier.verifier);
373
374out_overflow:
375 print_overflow_msg(__func__, xdr);
376 return -EIO;
377}
378
379static int decode_copy_requirements(struct xdr_stream *xdr,
380 struct nfs42_copy_res *res) {
381 __be32 *p;
382
383 p = xdr_inline_decode(xdr, 4 + 4);
384 if (unlikely(!p))
385 goto out_overflow;
386
387 res->consecutive = be32_to_cpup(p++);
388 res->synchronous = be32_to_cpup(p++);
389 return 0;
390out_overflow:
391 print_overflow_msg(__func__, xdr);
392 return -EIO;
393}
394
395static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res)
396{
397 int status;
398
399 status = decode_op_hdr(xdr, OP_COPY);
400 if (status == NFS4ERR_OFFLOAD_NO_REQS) {
401 status = decode_copy_requirements(xdr, res);
402 if (status)
403 return status;
404 return NFS4ERR_OFFLOAD_NO_REQS;
405 } else if (status)
406 return status;
407
408 status = decode_write_response(xdr, &res->write_res);
409 if (status)
410 return status;
411
412 return decode_copy_requirements(xdr, res);
413}
414
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500415static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
416{
417 return decode_op_hdr(xdr, OP_DEALLOCATE);
418}
419
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400420static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
421{
422 int status;
423 __be32 *p;
424
425 status = decode_op_hdr(xdr, OP_SEEK);
426 if (status)
427 return status;
428
429 p = xdr_inline_decode(xdr, 4 + 8);
430 if (unlikely(!p))
431 goto out_overflow;
432
433 res->sr_eof = be32_to_cpup(p++);
434 p = xdr_decode_hyper(p, &res->sr_offset);
435 return 0;
436
437out_overflow:
438 print_overflow_msg(__func__, xdr);
439 return -EIO;
440}
441
Peng Tao19cf6332015-08-26 00:13:15 +0800442static int decode_layoutstats(struct xdr_stream *xdr)
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800443{
Trond Myklebustda2e8122015-06-27 11:30:57 -0400444 return decode_op_hdr(xdr, OP_LAYOUTSTATS);
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800445}
446
Peng Tao36022772015-09-26 02:24:34 +0800447static int decode_clone(struct xdr_stream *xdr)
448{
449 return decode_op_hdr(xdr, OP_CLONE);
450}
451
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400452/*
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500453 * Decode ALLOCATE request
454 */
455static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
456 struct xdr_stream *xdr,
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200457 void *data)
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500458{
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200459 struct nfs42_falloc_res *res = data;
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500460 struct compound_hdr hdr;
461 int status;
462
463 status = decode_compound_hdr(xdr, &hdr);
464 if (status)
465 goto out;
466 status = decode_sequence(xdr, &res->seq_res, rqstp);
467 if (status)
468 goto out;
469 status = decode_putfh(xdr);
470 if (status)
471 goto out;
472 status = decode_allocate(xdr, res);
Anna Schumaker9a519402015-03-16 14:06:23 -0400473 if (status)
474 goto out;
475 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
Anna Schumakerf4ac1672014-11-25 13:18:15 -0500476out:
477 return status;
478}
479
480/*
Anna Schumaker2e724482013-05-21 16:53:03 -0400481 * Decode COPY response
482 */
483static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp,
484 struct xdr_stream *xdr,
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200485 void *data)
Anna Schumaker2e724482013-05-21 16:53:03 -0400486{
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200487 struct nfs42_copy_res *res = data;
Anna Schumaker2e724482013-05-21 16:53:03 -0400488 struct compound_hdr hdr;
489 int status;
490
491 status = decode_compound_hdr(xdr, &hdr);
492 if (status)
493 goto out;
494 status = decode_sequence(xdr, &res->seq_res, rqstp);
495 if (status)
496 goto out;
497 status = decode_putfh(xdr);
498 if (status)
499 goto out;
500 status = decode_savefh(xdr);
501 if (status)
502 goto out;
503 status = decode_putfh(xdr);
504 if (status)
505 goto out;
506 status = decode_copy(xdr, res);
Olga Kornievskaiae0926932017-05-08 18:02:24 -0400507 if (status)
508 goto out;
509 status = decode_commit(xdr, &res->commit_res);
Anna Schumaker2e724482013-05-21 16:53:03 -0400510out:
511 return status;
512}
513
514/*
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500515 * Decode DEALLOCATE request
516 */
517static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
518 struct xdr_stream *xdr,
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200519 void *data)
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500520{
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200521 struct nfs42_falloc_res *res = data;
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500522 struct compound_hdr hdr;
523 int status;
524
525 status = decode_compound_hdr(xdr, &hdr);
526 if (status)
527 goto out;
528 status = decode_sequence(xdr, &res->seq_res, rqstp);
529 if (status)
530 goto out;
531 status = decode_putfh(xdr);
532 if (status)
533 goto out;
534 status = decode_deallocate(xdr, res);
Anna Schumaker9a519402015-03-16 14:06:23 -0400535 if (status)
536 goto out;
537 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
Anna Schumaker624bd5b2014-11-25 13:18:16 -0500538out:
539 return status;
540}
541
542/*
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400543 * Decode SEEK request
544 */
545static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
546 struct xdr_stream *xdr,
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200547 void *data)
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400548{
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200549 struct nfs42_seek_res *res = data;
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400550 struct compound_hdr hdr;
551 int status;
552
553 status = decode_compound_hdr(xdr, &hdr);
554 if (status)
555 goto out;
556 status = decode_sequence(xdr, &res->seq_res, rqstp);
557 if (status)
558 goto out;
559 status = decode_putfh(xdr);
560 if (status)
561 goto out;
562 status = decode_seek(xdr, res);
563out:
564 return status;
565}
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800566
567/*
568 * Decode LAYOUTSTATS request
569 */
570static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp,
571 struct xdr_stream *xdr,
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200572 void *data)
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800573{
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200574 struct nfs42_layoutstat_res *res = data;
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800575 struct compound_hdr hdr;
576 int status, i;
577
578 status = decode_compound_hdr(xdr, &hdr);
579 if (status)
580 goto out;
581 status = decode_sequence(xdr, &res->seq_res, rqstp);
582 if (status)
583 goto out;
584 status = decode_putfh(xdr);
585 if (status)
586 goto out;
587 WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV);
588 for (i = 0; i < res->num_dev; i++) {
Peng Tao19cf6332015-08-26 00:13:15 +0800589 status = decode_layoutstats(xdr);
Trond Myklebustbe3a5d22015-06-23 19:51:55 +0800590 if (status)
591 goto out;
592 }
593out:
594 res->rpc_status = status;
595 return status;
596}
597
Peng Tao36022772015-09-26 02:24:34 +0800598/*
599 * Decode CLONE request
600 */
601static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp,
602 struct xdr_stream *xdr,
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200603 void *data)
Peng Tao36022772015-09-26 02:24:34 +0800604{
Christoph Hellwig18d9cff2017-05-08 15:09:02 +0200605 struct nfs42_clone_res *res = data;
Peng Tao36022772015-09-26 02:24:34 +0800606 struct compound_hdr hdr;
607 int status;
608
609 status = decode_compound_hdr(xdr, &hdr);
610 if (status)
611 goto out;
612 status = decode_sequence(xdr, &res->seq_res, rqstp);
613 if (status)
614 goto out;
615 status = decode_putfh(xdr);
616 if (status)
617 goto out;
618 status = decode_savefh(xdr);
619 if (status)
620 goto out;
621 status = decode_putfh(xdr);
622 if (status)
623 goto out;
624 status = decode_clone(xdr);
625 if (status)
626 goto out;
627 status = decode_getfattr(xdr, res->dst_fattr, res->server);
628
629out:
630 res->rpc_status = status;
631 return status;
632}
633
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -0400634#endif /* __LINUX_FS_NFS_NFS4_2XDR_H */