Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 1 | /* |
| 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 Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 7 | #include "nfs42.h" |
| 8 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9 | #define encode_fallocate_maxsz (encode_stateid_maxsz + \ |
| 10 | 2 /* offset */ + \ |
| 11 | 2 /* length */) |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 12 | #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 Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 17 | #define encode_allocate_maxsz (op_encode_hdr_maxsz + \ |
| 18 | encode_fallocate_maxsz) |
| 19 | #define decode_allocate_maxsz (op_decode_hdr_maxsz) |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 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 */) |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 28 | #define encode_deallocate_maxsz (op_encode_hdr_maxsz + \ |
| 29 | encode_fallocate_maxsz) |
| 30 | #define decode_deallocate_maxsz (op_decode_hdr_maxsz) |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 31 | #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 Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 40 | #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 Tao | 3602277 | 2015-09-26 02:24:34 +0800 | [diff] [blame] | 50 | #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 Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 56 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 57 | #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \ |
| 58 | encode_putfh_maxsz + \ |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 59 | encode_allocate_maxsz + \ |
| 60 | encode_getattr_maxsz) |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 61 | #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \ |
| 62 | decode_putfh_maxsz + \ |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 63 | decode_allocate_maxsz + \ |
| 64 | decode_getattr_maxsz) |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 65 | #define NFS4_enc_copy_sz (compound_encode_hdr_maxsz + \ |
| 66 | encode_putfh_maxsz + \ |
| 67 | encode_savefh_maxsz + \ |
| 68 | encode_putfh_maxsz + \ |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 69 | encode_copy_maxsz + \ |
| 70 | encode_commit_maxsz) |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 71 | #define NFS4_dec_copy_sz (compound_decode_hdr_maxsz + \ |
| 72 | decode_putfh_maxsz + \ |
| 73 | decode_savefh_maxsz + \ |
| 74 | decode_putfh_maxsz + \ |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 75 | decode_copy_maxsz + \ |
| 76 | decode_commit_maxsz) |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 77 | #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \ |
| 78 | encode_putfh_maxsz + \ |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 79 | encode_deallocate_maxsz + \ |
| 80 | encode_getattr_maxsz) |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 81 | #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \ |
| 82 | decode_putfh_maxsz + \ |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 83 | decode_deallocate_maxsz + \ |
| 84 | decode_getattr_maxsz) |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 85 | #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 Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 91 | #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 Tao | 3602277 | 2015-09-26 02:24:34 +0800 | [diff] [blame] | 99 | #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 Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 113 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 114 | static void encode_fallocate(struct xdr_stream *xdr, |
| 115 | struct nfs42_falloc_args *args) |
| 116 | { |
| 117 | encode_nfs4_stateid(xdr, &args->falloc_stateid); |
| 118 | encode_uint64(xdr, args->falloc_offset); |
| 119 | encode_uint64(xdr, args->falloc_length); |
| 120 | } |
| 121 | |
| 122 | static void encode_allocate(struct xdr_stream *xdr, |
| 123 | struct nfs42_falloc_args *args, |
| 124 | struct compound_hdr *hdr) |
| 125 | { |
| 126 | encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr); |
| 127 | encode_fallocate(xdr, args); |
| 128 | } |
| 129 | |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 130 | static void encode_copy(struct xdr_stream *xdr, |
| 131 | struct nfs42_copy_args *args, |
| 132 | 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 Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 147 | static void encode_deallocate(struct xdr_stream *xdr, |
| 148 | struct nfs42_falloc_args *args, |
| 149 | struct compound_hdr *hdr) |
| 150 | { |
| 151 | encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr); |
| 152 | encode_fallocate(xdr, args); |
| 153 | } |
| 154 | |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 155 | static void encode_seek(struct xdr_stream *xdr, |
| 156 | struct nfs42_seek_args *args, |
| 157 | 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 Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 165 | static void encode_layoutstats(struct xdr_stream *xdr, |
| 166 | struct nfs42_layoutstat_args *args, |
| 167 | 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 Myklebust | 422c93c | 2016-10-06 17:53:20 -0400 | [diff] [blame] | 186 | if (devinfo->ld_private.ops) |
| 187 | devinfo->ld_private.ops->encode(xdr, args, |
| 188 | &devinfo->ld_private); |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 189 | else |
| 190 | encode_uint32(xdr, 0); |
| 191 | } |
| 192 | |
Peng Tao | 3602277 | 2015-09-26 02:24:34 +0800 | [diff] [blame] | 193 | static void encode_clone(struct xdr_stream *xdr, |
| 194 | struct nfs42_clone_args *args, |
| 195 | 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 Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 208 | /* |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 209 | * Encode ALLOCATE request |
| 210 | */ |
| 211 | static void nfs4_xdr_enc_allocate(struct rpc_rqst *req, |
| 212 | struct xdr_stream *xdr, |
| 213 | struct nfs42_falloc_args *args) |
| 214 | { |
| 215 | struct compound_hdr hdr = { |
| 216 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
| 217 | }; |
| 218 | |
| 219 | encode_compound_hdr(xdr, req, &hdr); |
| 220 | encode_sequence(xdr, &args->seq_args, &hdr); |
| 221 | encode_putfh(xdr, args->falloc_fh, &hdr); |
| 222 | encode_allocate(xdr, args, &hdr); |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 223 | encode_getfattr(xdr, args->falloc_bitmask, &hdr); |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 224 | encode_nops(&hdr); |
| 225 | } |
| 226 | |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 227 | static void encode_copy_commit(struct xdr_stream *xdr, |
| 228 | struct nfs42_copy_args *args, |
| 229 | struct compound_hdr *hdr) |
| 230 | { |
| 231 | __be32 *p; |
| 232 | |
| 233 | encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); |
| 234 | p = reserve_space(xdr, 12); |
| 235 | p = xdr_encode_hyper(p, args->dst_pos); |
| 236 | *p = cpu_to_be32(args->count); |
| 237 | } |
| 238 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 239 | /* |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 240 | * Encode COPY request |
| 241 | */ |
| 242 | static void nfs4_xdr_enc_copy(struct rpc_rqst *req, |
| 243 | struct xdr_stream *xdr, |
| 244 | struct nfs42_copy_args *args) |
| 245 | { |
| 246 | struct compound_hdr hdr = { |
| 247 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
| 248 | }; |
| 249 | |
| 250 | encode_compound_hdr(xdr, req, &hdr); |
| 251 | encode_sequence(xdr, &args->seq_args, &hdr); |
| 252 | encode_putfh(xdr, args->src_fh, &hdr); |
| 253 | encode_savefh(xdr, &hdr); |
| 254 | encode_putfh(xdr, args->dst_fh, &hdr); |
| 255 | encode_copy(xdr, args, &hdr); |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 256 | encode_copy_commit(xdr, args, &hdr); |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 257 | encode_nops(&hdr); |
| 258 | } |
| 259 | |
| 260 | /* |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 261 | * Encode DEALLOCATE request |
| 262 | */ |
| 263 | static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req, |
| 264 | struct xdr_stream *xdr, |
| 265 | struct nfs42_falloc_args *args) |
| 266 | { |
| 267 | struct compound_hdr hdr = { |
| 268 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
| 269 | }; |
| 270 | |
| 271 | encode_compound_hdr(xdr, req, &hdr); |
| 272 | encode_sequence(xdr, &args->seq_args, &hdr); |
| 273 | encode_putfh(xdr, args->falloc_fh, &hdr); |
| 274 | encode_deallocate(xdr, args, &hdr); |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 275 | encode_getfattr(xdr, args->falloc_bitmask, &hdr); |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 276 | encode_nops(&hdr); |
| 277 | } |
| 278 | |
| 279 | /* |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 280 | * Encode SEEK request |
| 281 | */ |
| 282 | static void nfs4_xdr_enc_seek(struct rpc_rqst *req, |
| 283 | struct xdr_stream *xdr, |
| 284 | struct nfs42_seek_args *args) |
| 285 | { |
| 286 | struct compound_hdr hdr = { |
| 287 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
| 288 | }; |
| 289 | |
| 290 | encode_compound_hdr(xdr, req, &hdr); |
| 291 | encode_sequence(xdr, &args->seq_args, &hdr); |
| 292 | encode_putfh(xdr, args->sa_fh, &hdr); |
| 293 | encode_seek(xdr, args, &hdr); |
| 294 | encode_nops(&hdr); |
| 295 | } |
| 296 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 297 | /* |
| 298 | * Encode LAYOUTSTATS request |
| 299 | */ |
| 300 | static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req, |
| 301 | struct xdr_stream *xdr, |
| 302 | struct nfs42_layoutstat_args *args) |
| 303 | { |
| 304 | int i; |
| 305 | |
| 306 | struct compound_hdr hdr = { |
| 307 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
| 308 | }; |
| 309 | |
| 310 | encode_compound_hdr(xdr, req, &hdr); |
| 311 | encode_sequence(xdr, &args->seq_args, &hdr); |
| 312 | encode_putfh(xdr, args->fh, &hdr); |
| 313 | WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV); |
| 314 | for (i = 0; i < args->num_dev; i++) |
| 315 | encode_layoutstats(xdr, args, &args->devinfo[i], &hdr); |
| 316 | encode_nops(&hdr); |
| 317 | } |
| 318 | |
Peng Tao | 3602277 | 2015-09-26 02:24:34 +0800 | [diff] [blame] | 319 | /* |
| 320 | * Encode CLONE request |
| 321 | */ |
| 322 | static void nfs4_xdr_enc_clone(struct rpc_rqst *req, |
| 323 | struct xdr_stream *xdr, |
| 324 | struct nfs42_clone_args *args) |
| 325 | { |
| 326 | struct compound_hdr hdr = { |
| 327 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
| 328 | }; |
| 329 | |
| 330 | encode_compound_hdr(xdr, req, &hdr); |
| 331 | encode_sequence(xdr, &args->seq_args, &hdr); |
| 332 | encode_putfh(xdr, args->src_fh, &hdr); |
| 333 | encode_savefh(xdr, &hdr); |
| 334 | encode_putfh(xdr, args->dst_fh, &hdr); |
| 335 | encode_clone(xdr, args, &hdr); |
| 336 | encode_getfattr(xdr, args->dst_bitmask, &hdr); |
| 337 | encode_nops(&hdr); |
| 338 | } |
| 339 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 340 | static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) |
| 341 | { |
| 342 | return decode_op_hdr(xdr, OP_ALLOCATE); |
| 343 | } |
| 344 | |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 345 | static int decode_write_response(struct xdr_stream *xdr, |
| 346 | struct nfs42_write_res *res) |
| 347 | { |
| 348 | __be32 *p; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 349 | |
| 350 | p = xdr_inline_decode(xdr, 4 + 8 + 4); |
| 351 | if (unlikely(!p)) |
| 352 | goto out_overflow; |
| 353 | |
Trond Myklebust | 6fdf339 | 2016-07-24 17:17:16 -0400 | [diff] [blame] | 354 | /* |
| 355 | * We never use asynchronous mode, so warn if a server returns |
| 356 | * a stateid. |
| 357 | */ |
| 358 | if (unlikely(*p != 0)) { |
| 359 | pr_err_once("%s: server has set unrequested " |
| 360 | "asynchronous mode\n", __func__); |
| 361 | return -EREMOTEIO; |
| 362 | } |
| 363 | p++; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 364 | p = xdr_decode_hyper(p, &res->count); |
| 365 | res->verifier.committed = be32_to_cpup(p); |
| 366 | return decode_verifier(xdr, &res->verifier.verifier); |
| 367 | |
| 368 | out_overflow: |
| 369 | print_overflow_msg(__func__, xdr); |
| 370 | return -EIO; |
| 371 | } |
| 372 | |
| 373 | static int decode_copy_requirements(struct xdr_stream *xdr, |
| 374 | struct nfs42_copy_res *res) { |
| 375 | __be32 *p; |
| 376 | |
| 377 | p = xdr_inline_decode(xdr, 4 + 4); |
| 378 | if (unlikely(!p)) |
| 379 | goto out_overflow; |
| 380 | |
| 381 | res->consecutive = be32_to_cpup(p++); |
| 382 | res->synchronous = be32_to_cpup(p++); |
| 383 | return 0; |
| 384 | out_overflow: |
| 385 | print_overflow_msg(__func__, xdr); |
| 386 | return -EIO; |
| 387 | } |
| 388 | |
| 389 | static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res) |
| 390 | { |
| 391 | int status; |
| 392 | |
| 393 | status = decode_op_hdr(xdr, OP_COPY); |
| 394 | if (status == NFS4ERR_OFFLOAD_NO_REQS) { |
| 395 | status = decode_copy_requirements(xdr, res); |
| 396 | if (status) |
| 397 | return status; |
| 398 | return NFS4ERR_OFFLOAD_NO_REQS; |
| 399 | } else if (status) |
| 400 | return status; |
| 401 | |
| 402 | status = decode_write_response(xdr, &res->write_res); |
| 403 | if (status) |
| 404 | return status; |
| 405 | |
| 406 | return decode_copy_requirements(xdr, res); |
| 407 | } |
| 408 | |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 409 | static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) |
| 410 | { |
| 411 | return decode_op_hdr(xdr, OP_DEALLOCATE); |
| 412 | } |
| 413 | |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 414 | static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res) |
| 415 | { |
| 416 | int status; |
| 417 | __be32 *p; |
| 418 | |
| 419 | status = decode_op_hdr(xdr, OP_SEEK); |
| 420 | if (status) |
| 421 | return status; |
| 422 | |
| 423 | p = xdr_inline_decode(xdr, 4 + 8); |
| 424 | if (unlikely(!p)) |
| 425 | goto out_overflow; |
| 426 | |
| 427 | res->sr_eof = be32_to_cpup(p++); |
| 428 | p = xdr_decode_hyper(p, &res->sr_offset); |
| 429 | return 0; |
| 430 | |
| 431 | out_overflow: |
| 432 | print_overflow_msg(__func__, xdr); |
| 433 | return -EIO; |
| 434 | } |
| 435 | |
Peng Tao | 19cf633 | 2015-08-26 00:13:15 +0800 | [diff] [blame] | 436 | static int decode_layoutstats(struct xdr_stream *xdr) |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 437 | { |
Trond Myklebust | da2e812 | 2015-06-27 11:30:57 -0400 | [diff] [blame] | 438 | return decode_op_hdr(xdr, OP_LAYOUTSTATS); |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 439 | } |
| 440 | |
Peng Tao | 3602277 | 2015-09-26 02:24:34 +0800 | [diff] [blame] | 441 | static int decode_clone(struct xdr_stream *xdr) |
| 442 | { |
| 443 | return decode_op_hdr(xdr, OP_CLONE); |
| 444 | } |
| 445 | |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 446 | /* |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 447 | * Decode ALLOCATE request |
| 448 | */ |
| 449 | static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp, |
| 450 | struct xdr_stream *xdr, |
| 451 | struct nfs42_falloc_res *res) |
| 452 | { |
| 453 | struct compound_hdr hdr; |
| 454 | int status; |
| 455 | |
| 456 | status = decode_compound_hdr(xdr, &hdr); |
| 457 | if (status) |
| 458 | goto out; |
| 459 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| 460 | if (status) |
| 461 | goto out; |
| 462 | status = decode_putfh(xdr); |
| 463 | if (status) |
| 464 | goto out; |
| 465 | status = decode_allocate(xdr, res); |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 466 | if (status) |
| 467 | goto out; |
| 468 | decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 469 | out: |
| 470 | return status; |
| 471 | } |
| 472 | |
| 473 | /* |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 474 | * Decode COPY response |
| 475 | */ |
| 476 | static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp, |
| 477 | struct xdr_stream *xdr, |
| 478 | struct nfs42_copy_res *res) |
| 479 | { |
| 480 | struct compound_hdr hdr; |
| 481 | int status; |
| 482 | |
| 483 | status = decode_compound_hdr(xdr, &hdr); |
| 484 | if (status) |
| 485 | goto out; |
| 486 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| 487 | if (status) |
| 488 | goto out; |
| 489 | status = decode_putfh(xdr); |
| 490 | if (status) |
| 491 | goto out; |
| 492 | status = decode_savefh(xdr); |
| 493 | if (status) |
| 494 | goto out; |
| 495 | status = decode_putfh(xdr); |
| 496 | if (status) |
| 497 | goto out; |
| 498 | status = decode_copy(xdr, res); |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 499 | if (status) |
| 500 | goto out; |
| 501 | status = decode_commit(xdr, &res->commit_res); |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 502 | out: |
| 503 | return status; |
| 504 | } |
| 505 | |
| 506 | /* |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 507 | * Decode DEALLOCATE request |
| 508 | */ |
| 509 | static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp, |
| 510 | struct xdr_stream *xdr, |
| 511 | struct nfs42_falloc_res *res) |
| 512 | { |
| 513 | struct compound_hdr hdr; |
| 514 | int status; |
| 515 | |
| 516 | status = decode_compound_hdr(xdr, &hdr); |
| 517 | if (status) |
| 518 | goto out; |
| 519 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| 520 | if (status) |
| 521 | goto out; |
| 522 | status = decode_putfh(xdr); |
| 523 | if (status) |
| 524 | goto out; |
| 525 | status = decode_deallocate(xdr, res); |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 526 | if (status) |
| 527 | goto out; |
| 528 | decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 529 | out: |
| 530 | return status; |
| 531 | } |
| 532 | |
| 533 | /* |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 534 | * Decode SEEK request |
| 535 | */ |
| 536 | static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp, |
| 537 | struct xdr_stream *xdr, |
| 538 | struct nfs42_seek_res *res) |
| 539 | { |
| 540 | struct compound_hdr hdr; |
| 541 | int status; |
| 542 | |
| 543 | status = decode_compound_hdr(xdr, &hdr); |
| 544 | if (status) |
| 545 | goto out; |
| 546 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| 547 | if (status) |
| 548 | goto out; |
| 549 | status = decode_putfh(xdr); |
| 550 | if (status) |
| 551 | goto out; |
| 552 | status = decode_seek(xdr, res); |
| 553 | out: |
| 554 | return status; |
| 555 | } |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 556 | |
| 557 | /* |
| 558 | * Decode LAYOUTSTATS request |
| 559 | */ |
| 560 | static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp, |
| 561 | struct xdr_stream *xdr, |
| 562 | struct nfs42_layoutstat_res *res) |
| 563 | { |
| 564 | struct compound_hdr hdr; |
| 565 | int status, i; |
| 566 | |
| 567 | status = decode_compound_hdr(xdr, &hdr); |
| 568 | if (status) |
| 569 | goto out; |
| 570 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| 571 | if (status) |
| 572 | goto out; |
| 573 | status = decode_putfh(xdr); |
| 574 | if (status) |
| 575 | goto out; |
| 576 | WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV); |
| 577 | for (i = 0; i < res->num_dev; i++) { |
Peng Tao | 19cf633 | 2015-08-26 00:13:15 +0800 | [diff] [blame] | 578 | status = decode_layoutstats(xdr); |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 579 | if (status) |
| 580 | goto out; |
| 581 | } |
| 582 | out: |
| 583 | res->rpc_status = status; |
| 584 | return status; |
| 585 | } |
| 586 | |
Peng Tao | 3602277 | 2015-09-26 02:24:34 +0800 | [diff] [blame] | 587 | /* |
| 588 | * Decode CLONE request |
| 589 | */ |
| 590 | static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp, |
| 591 | struct xdr_stream *xdr, |
| 592 | struct nfs42_clone_res *res) |
| 593 | { |
| 594 | struct compound_hdr hdr; |
| 595 | int status; |
| 596 | |
| 597 | status = decode_compound_hdr(xdr, &hdr); |
| 598 | if (status) |
| 599 | goto out; |
| 600 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| 601 | if (status) |
| 602 | goto out; |
| 603 | status = decode_putfh(xdr); |
| 604 | if (status) |
| 605 | goto out; |
| 606 | status = decode_savefh(xdr); |
| 607 | if (status) |
| 608 | goto out; |
| 609 | status = decode_putfh(xdr); |
| 610 | if (status) |
| 611 | goto out; |
| 612 | status = decode_clone(xdr); |
| 613 | if (status) |
| 614 | goto out; |
| 615 | status = decode_getfattr(xdr, res->dst_fattr, res->server); |
| 616 | |
| 617 | out: |
| 618 | res->rpc_status = status; |
| 619 | return status; |
| 620 | } |
| 621 | |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 622 | #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */ |