1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com> 4 */ 5 #ifndef __LINUX_FS_NFS_NFS4_2XDR_H 6 #define __LINUX_FS_NFS_NFS4_2XDR_H 7 8 #include "nfs42.h" 9 10 #define encode_fallocate_maxsz (encode_stateid_maxsz + \ 11 2 /* offset */ + \ 12 2 /* length */) 13 #define NFS42_WRITE_RES_SIZE (1 /* wr_callback_id size */ +\ 14 XDR_QUADLEN(NFS4_STATEID_SIZE) + \ 15 2 /* wr_count */ + \ 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 */\ 26 1 + /* nl4_type */ \ 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) + \ 37 1 + /* nl4_type */ \ 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 */\ 43 1 + /* nl4_type */ \ 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_DATA_SEGMENT_SIZE \ 51 (1 /* data_content4 */ + \ 52 2 /* data_info4.di_offset */ + \ 53 1 /* data_info4.di_length */) 54 #define decode_read_plus_maxsz (op_decode_hdr_maxsz + \ 55 1 /* rpr_eof */ + \ 56 1 /* rpr_contents count */ + \ 57 NFS42_READ_PLUS_DATA_SEGMENT_SIZE) 58 #define encode_seek_maxsz (op_encode_hdr_maxsz + \ 59 encode_stateid_maxsz + \ 60 2 /* offset */ + \ 61 1 /* whence */) 62 #define decode_seek_maxsz (op_decode_hdr_maxsz + \ 63 1 /* eof */ + \ 64 1 /* whence */ + \ 65 2 /* offset */ + \ 66 2 /* length */) 67 #define encode_io_info_maxsz 4 68 #define encode_layoutstats_maxsz (op_decode_hdr_maxsz + \ 69 2 /* offset */ + \ 70 2 /* length */ + \ 71 encode_stateid_maxsz + \ 72 encode_io_info_maxsz + \ 73 encode_io_info_maxsz + \ 74 1 /* opaque devaddr4 length */ + \ 75 XDR_QUADLEN(PNFS_LAYOUTSTATS_MAXSIZE)) 76 #define decode_layoutstats_maxsz (op_decode_hdr_maxsz) 77 #define encode_device_error_maxsz (XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 78 1 /* status */ + 1 /* opnum */) 79 #define encode_layouterror_maxsz (op_decode_hdr_maxsz + \ 80 2 /* offset */ + \ 81 2 /* length */ + \ 82 encode_stateid_maxsz + \ 83 1 /* Array size */ + \ 84 encode_device_error_maxsz) 85 #define decode_layouterror_maxsz (op_decode_hdr_maxsz) 86 #define encode_clone_maxsz (encode_stateid_maxsz + \ 87 encode_stateid_maxsz + \ 88 2 /* src offset */ + \ 89 2 /* dst offset */ + \ 90 2 /* count */) 91 #define decode_clone_maxsz (op_decode_hdr_maxsz) 92 93 #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \ 94 encode_sequence_maxsz + \ 95 encode_putfh_maxsz + \ 96 encode_allocate_maxsz + \ 97 encode_getattr_maxsz) 98 #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \ 99 decode_sequence_maxsz + \ 100 decode_putfh_maxsz + \ 101 decode_allocate_maxsz + \ 102 decode_getattr_maxsz) 103 #define NFS4_enc_copy_sz (compound_encode_hdr_maxsz + \ 104 encode_sequence_maxsz + \ 105 encode_putfh_maxsz + \ 106 encode_savefh_maxsz + \ 107 encode_putfh_maxsz + \ 108 encode_copy_maxsz + \ 109 encode_commit_maxsz) 110 #define NFS4_dec_copy_sz (compound_decode_hdr_maxsz + \ 111 decode_sequence_maxsz + \ 112 decode_putfh_maxsz + \ 113 decode_savefh_maxsz + \ 114 decode_putfh_maxsz + \ 115 decode_copy_maxsz + \ 116 decode_commit_maxsz) 117 #define NFS4_enc_offload_cancel_sz (compound_encode_hdr_maxsz + \ 118 encode_sequence_maxsz + \ 119 encode_putfh_maxsz + \ 120 encode_offload_cancel_maxsz) 121 #define NFS4_dec_offload_cancel_sz (compound_decode_hdr_maxsz + \ 122 decode_sequence_maxsz + \ 123 decode_putfh_maxsz + \ 124 decode_offload_cancel_maxsz) 125 #define NFS4_enc_copy_notify_sz (compound_encode_hdr_maxsz + \ 126 encode_putfh_maxsz + \ 127 encode_copy_notify_maxsz) 128 #define NFS4_dec_copy_notify_sz (compound_decode_hdr_maxsz + \ 129 decode_putfh_maxsz + \ 130 decode_copy_notify_maxsz) 131 #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \ 132 encode_sequence_maxsz + \ 133 encode_putfh_maxsz + \ 134 encode_deallocate_maxsz + \ 135 encode_getattr_maxsz) 136 #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \ 137 decode_sequence_maxsz + \ 138 decode_putfh_maxsz + \ 139 decode_deallocate_maxsz + \ 140 decode_getattr_maxsz) 141 #define NFS4_enc_read_plus_sz (compound_encode_hdr_maxsz + \ 142 encode_sequence_maxsz + \ 143 encode_putfh_maxsz + \ 144 encode_read_plus_maxsz) 145 #define NFS4_dec_read_plus_sz (compound_decode_hdr_maxsz + \ 146 decode_sequence_maxsz + \ 147 decode_putfh_maxsz + \ 148 decode_read_plus_maxsz) 149 #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \ 150 encode_sequence_maxsz + \ 151 encode_putfh_maxsz + \ 152 encode_seek_maxsz) 153 #define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \ 154 decode_sequence_maxsz + \ 155 decode_putfh_maxsz + \ 156 decode_seek_maxsz) 157 #define NFS4_enc_layoutstats_sz (compound_encode_hdr_maxsz + \ 158 encode_sequence_maxsz + \ 159 encode_putfh_maxsz + \ 160 PNFS_LAYOUTSTATS_MAXDEV * encode_layoutstats_maxsz) 161 #define NFS4_dec_layoutstats_sz (compound_decode_hdr_maxsz + \ 162 decode_sequence_maxsz + \ 163 decode_putfh_maxsz + \ 164 PNFS_LAYOUTSTATS_MAXDEV * decode_layoutstats_maxsz) 165 #define NFS4_enc_layouterror_sz (compound_encode_hdr_maxsz + \ 166 encode_sequence_maxsz + \ 167 encode_putfh_maxsz + \ 168 NFS42_LAYOUTERROR_MAX * \ 169 encode_layouterror_maxsz) 170 #define NFS4_dec_layouterror_sz (compound_decode_hdr_maxsz + \ 171 decode_sequence_maxsz + \ 172 decode_putfh_maxsz + \ 173 NFS42_LAYOUTERROR_MAX * \ 174 decode_layouterror_maxsz) 175 #define NFS4_enc_clone_sz (compound_encode_hdr_maxsz + \ 176 encode_sequence_maxsz + \ 177 encode_putfh_maxsz + \ 178 encode_savefh_maxsz + \ 179 encode_putfh_maxsz + \ 180 encode_clone_maxsz + \ 181 encode_getattr_maxsz) 182 #define NFS4_dec_clone_sz (compound_decode_hdr_maxsz + \ 183 decode_sequence_maxsz + \ 184 decode_putfh_maxsz + \ 185 decode_savefh_maxsz + \ 186 decode_putfh_maxsz + \ 187 decode_clone_maxsz + \ 188 decode_getattr_maxsz) 189 190 /* Not limited by NFS itself, limited by the generic xattr code */ 191 #define nfs4_xattr_name_maxsz XDR_QUADLEN(XATTR_NAME_MAX) 192 193 #define encode_getxattr_maxsz (op_encode_hdr_maxsz + 1 + \ 194 nfs4_xattr_name_maxsz) 195 #define decode_getxattr_maxsz (op_decode_hdr_maxsz + 1 + pagepad_maxsz) 196 #define encode_setxattr_maxsz (op_encode_hdr_maxsz + \ 197 1 + nfs4_xattr_name_maxsz + 1) 198 #define decode_setxattr_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 199 #define encode_listxattrs_maxsz (op_encode_hdr_maxsz + 2 + 1) 200 #define decode_listxattrs_maxsz (op_decode_hdr_maxsz + 2 + 1 + 1 + 1) 201 #define encode_removexattr_maxsz (op_encode_hdr_maxsz + 1 + \ 202 nfs4_xattr_name_maxsz) 203 #define decode_removexattr_maxsz (op_decode_hdr_maxsz + \ 204 decode_change_info_maxsz) 205 206 #define NFS4_enc_getxattr_sz (compound_encode_hdr_maxsz + \ 207 encode_sequence_maxsz + \ 208 encode_putfh_maxsz + \ 209 encode_getxattr_maxsz) 210 #define NFS4_dec_getxattr_sz (compound_decode_hdr_maxsz + \ 211 decode_sequence_maxsz + \ 212 decode_putfh_maxsz + \ 213 decode_getxattr_maxsz) 214 #define NFS4_enc_setxattr_sz (compound_encode_hdr_maxsz + \ 215 encode_sequence_maxsz + \ 216 encode_putfh_maxsz + \ 217 encode_setxattr_maxsz) 218 #define NFS4_dec_setxattr_sz (compound_decode_hdr_maxsz + \ 219 decode_sequence_maxsz + \ 220 decode_putfh_maxsz + \ 221 decode_setxattr_maxsz) 222 #define NFS4_enc_listxattrs_sz (compound_encode_hdr_maxsz + \ 223 encode_sequence_maxsz + \ 224 encode_putfh_maxsz + \ 225 encode_listxattrs_maxsz) 226 #define NFS4_dec_listxattrs_sz (compound_decode_hdr_maxsz + \ 227 decode_sequence_maxsz + \ 228 decode_putfh_maxsz + \ 229 decode_listxattrs_maxsz) 230 #define NFS4_enc_removexattr_sz (compound_encode_hdr_maxsz + \ 231 encode_sequence_maxsz + \ 232 encode_putfh_maxsz + \ 233 encode_removexattr_maxsz) 234 #define NFS4_dec_removexattr_sz (compound_decode_hdr_maxsz + \ 235 decode_sequence_maxsz + \ 236 decode_putfh_maxsz + \ 237 decode_removexattr_maxsz) 238 239 /* 240 * These values specify the maximum amount of data that is not 241 * associated with the extended attribute name or extended 242 * attribute list in the SETXATTR, GETXATTR and LISTXATTR 243 * respectively. 244 */ 245 const u32 nfs42_maxsetxattr_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 246 compound_encode_hdr_maxsz + 247 encode_sequence_maxsz + 248 encode_putfh_maxsz + 1 + 249 nfs4_xattr_name_maxsz) 250 * XDR_UNIT); 251 252 const u32 nfs42_maxgetxattr_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 253 compound_decode_hdr_maxsz + 254 decode_sequence_maxsz + 255 decode_putfh_maxsz + 1) * XDR_UNIT); 256 257 const u32 nfs42_maxlistxattrs_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 258 compound_decode_hdr_maxsz + 259 decode_sequence_maxsz + 260 decode_putfh_maxsz + 3) * XDR_UNIT); 261 262 static void encode_fallocate(struct xdr_stream *xdr, 263 const struct nfs42_falloc_args *args) 264 { 265 encode_nfs4_stateid(xdr, &args->falloc_stateid); 266 encode_uint64(xdr, args->falloc_offset); 267 encode_uint64(xdr, args->falloc_length); 268 } 269 270 static void encode_allocate(struct xdr_stream *xdr, 271 const struct nfs42_falloc_args *args, 272 struct compound_hdr *hdr) 273 { 274 encode_op_hdr(xdr, OP_ALLOCATE, decode_allocate_maxsz, hdr); 275 encode_fallocate(xdr, args); 276 } 277 278 static void encode_nl4_server(struct xdr_stream *xdr, 279 const struct nl4_server *ns) 280 { 281 encode_uint32(xdr, ns->nl4_type); 282 switch (ns->nl4_type) { 283 case NL4_NAME: 284 case NL4_URL: 285 encode_string(xdr, ns->u.nl4_str_sz, ns->u.nl4_str); 286 break; 287 case NL4_NETADDR: 288 encode_string(xdr, ns->u.nl4_addr.netid_len, 289 ns->u.nl4_addr.netid); 290 encode_string(xdr, ns->u.nl4_addr.addr_len, 291 ns->u.nl4_addr.addr); 292 break; 293 default: 294 WARN_ON_ONCE(1); 295 } 296 } 297 298 static void encode_copy(struct xdr_stream *xdr, 299 const struct nfs42_copy_args *args, 300 struct compound_hdr *hdr) 301 { 302 encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr); 303 encode_nfs4_stateid(xdr, &args->src_stateid); 304 encode_nfs4_stateid(xdr, &args->dst_stateid); 305 306 encode_uint64(xdr, args->src_pos); 307 encode_uint64(xdr, args->dst_pos); 308 encode_uint64(xdr, args->count); 309 310 encode_uint32(xdr, 1); /* consecutive = true */ 311 encode_uint32(xdr, args->sync); 312 if (args->cp_src == NULL) { /* intra-ssc */ 313 encode_uint32(xdr, 0); /* no src server list */ 314 return; 315 } 316 encode_uint32(xdr, 1); /* supporting 1 server */ 317 encode_nl4_server(xdr, args->cp_src); 318 } 319 320 static void encode_copy_commit(struct xdr_stream *xdr, 321 const struct nfs42_copy_args *args, 322 struct compound_hdr *hdr) 323 { 324 __be32 *p; 325 326 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 327 p = reserve_space(xdr, 12); 328 p = xdr_encode_hyper(p, args->dst_pos); 329 *p = cpu_to_be32(args->count); 330 } 331 332 static void encode_offload_cancel(struct xdr_stream *xdr, 333 const struct nfs42_offload_status_args *args, 334 struct compound_hdr *hdr) 335 { 336 encode_op_hdr(xdr, OP_OFFLOAD_CANCEL, decode_offload_cancel_maxsz, hdr); 337 encode_nfs4_stateid(xdr, &args->osa_stateid); 338 } 339 340 static void encode_copy_notify(struct xdr_stream *xdr, 341 const struct nfs42_copy_notify_args *args, 342 struct compound_hdr *hdr) 343 { 344 encode_op_hdr(xdr, OP_COPY_NOTIFY, decode_copy_notify_maxsz, hdr); 345 encode_nfs4_stateid(xdr, &args->cna_src_stateid); 346 encode_nl4_server(xdr, &args->cna_dst); 347 } 348 349 static void encode_deallocate(struct xdr_stream *xdr, 350 const struct nfs42_falloc_args *args, 351 struct compound_hdr *hdr) 352 { 353 encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr); 354 encode_fallocate(xdr, args); 355 } 356 357 static void encode_read_plus(struct xdr_stream *xdr, 358 const struct nfs_pgio_args *args, 359 struct compound_hdr *hdr) 360 { 361 encode_op_hdr(xdr, OP_READ_PLUS, decode_read_plus_maxsz, hdr); 362 encode_nfs4_stateid(xdr, &args->stateid); 363 encode_uint64(xdr, args->offset); 364 encode_uint32(xdr, args->count); 365 } 366 367 static void encode_seek(struct xdr_stream *xdr, 368 const struct nfs42_seek_args *args, 369 struct compound_hdr *hdr) 370 { 371 encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr); 372 encode_nfs4_stateid(xdr, &args->sa_stateid); 373 encode_uint64(xdr, args->sa_offset); 374 encode_uint32(xdr, args->sa_what); 375 } 376 377 static void encode_layoutstats(struct xdr_stream *xdr, 378 const struct nfs42_layoutstat_args *args, 379 struct nfs42_layoutstat_devinfo *devinfo, 380 struct compound_hdr *hdr) 381 { 382 __be32 *p; 383 384 encode_op_hdr(xdr, OP_LAYOUTSTATS, decode_layoutstats_maxsz, hdr); 385 p = reserve_space(xdr, 8 + 8); 386 p = xdr_encode_hyper(p, devinfo->offset); 387 p = xdr_encode_hyper(p, devinfo->length); 388 encode_nfs4_stateid(xdr, &args->stateid); 389 p = reserve_space(xdr, 4*8 + NFS4_DEVICEID4_SIZE + 4); 390 p = xdr_encode_hyper(p, devinfo->read_count); 391 p = xdr_encode_hyper(p, devinfo->read_bytes); 392 p = xdr_encode_hyper(p, devinfo->write_count); 393 p = xdr_encode_hyper(p, devinfo->write_bytes); 394 p = xdr_encode_opaque_fixed(p, devinfo->dev_id.data, 395 NFS4_DEVICEID4_SIZE); 396 /* Encode layoutupdate4 */ 397 *p++ = cpu_to_be32(devinfo->layout_type); 398 if (devinfo->ld_private.ops) 399 devinfo->ld_private.ops->encode(xdr, args, 400 &devinfo->ld_private); 401 else 402 encode_uint32(xdr, 0); 403 } 404 405 static void encode_clone(struct xdr_stream *xdr, 406 const struct nfs42_clone_args *args, 407 struct compound_hdr *hdr) 408 { 409 __be32 *p; 410 411 encode_op_hdr(xdr, OP_CLONE, decode_clone_maxsz, hdr); 412 encode_nfs4_stateid(xdr, &args->src_stateid); 413 encode_nfs4_stateid(xdr, &args->dst_stateid); 414 p = reserve_space(xdr, 3*8); 415 p = xdr_encode_hyper(p, args->src_offset); 416 p = xdr_encode_hyper(p, args->dst_offset); 417 xdr_encode_hyper(p, args->count); 418 } 419 420 static void encode_device_error(struct xdr_stream *xdr, 421 const struct nfs42_device_error *error) 422 { 423 __be32 *p; 424 425 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 2*4); 426 p = xdr_encode_opaque_fixed(p, error->dev_id.data, 427 NFS4_DEVICEID4_SIZE); 428 *p++ = cpu_to_be32(error->status); 429 *p = cpu_to_be32(error->opnum); 430 } 431 432 static void encode_layouterror(struct xdr_stream *xdr, 433 const struct nfs42_layout_error *args, 434 struct compound_hdr *hdr) 435 { 436 __be32 *p; 437 438 encode_op_hdr(xdr, OP_LAYOUTERROR, decode_layouterror_maxsz, hdr); 439 p = reserve_space(xdr, 8 + 8); 440 p = xdr_encode_hyper(p, args->offset); 441 p = xdr_encode_hyper(p, args->length); 442 encode_nfs4_stateid(xdr, &args->stateid); 443 p = reserve_space(xdr, 4); 444 *p = cpu_to_be32(1); 445 encode_device_error(xdr, &args->errors[0]); 446 } 447 448 static void encode_setxattr(struct xdr_stream *xdr, 449 const struct nfs42_setxattrargs *arg, 450 struct compound_hdr *hdr) 451 { 452 __be32 *p; 453 454 BUILD_BUG_ON(XATTR_CREATE != SETXATTR4_CREATE); 455 BUILD_BUG_ON(XATTR_REPLACE != SETXATTR4_REPLACE); 456 457 encode_op_hdr(xdr, OP_SETXATTR, decode_setxattr_maxsz, hdr); 458 p = reserve_space(xdr, 4); 459 *p = cpu_to_be32(arg->xattr_flags); 460 encode_string(xdr, strlen(arg->xattr_name), arg->xattr_name); 461 p = reserve_space(xdr, 4); 462 *p = cpu_to_be32(arg->xattr_len); 463 if (arg->xattr_len) 464 xdr_write_pages(xdr, arg->xattr_pages, 0, arg->xattr_len); 465 } 466 467 static void encode_getxattr(struct xdr_stream *xdr, const char *name, 468 struct compound_hdr *hdr) 469 { 470 encode_op_hdr(xdr, OP_GETXATTR, decode_getxattr_maxsz, hdr); 471 encode_string(xdr, strlen(name), name); 472 } 473 474 static void encode_removexattr(struct xdr_stream *xdr, const char *name, 475 struct compound_hdr *hdr) 476 { 477 encode_op_hdr(xdr, OP_REMOVEXATTR, decode_removexattr_maxsz, hdr); 478 encode_string(xdr, strlen(name), name); 479 } 480 481 static void encode_listxattrs(struct xdr_stream *xdr, 482 const struct nfs42_listxattrsargs *arg, 483 struct compound_hdr *hdr) 484 { 485 __be32 *p; 486 487 encode_op_hdr(xdr, OP_LISTXATTRS, decode_listxattrs_maxsz, hdr); 488 489 p = reserve_space(xdr, 12); 490 if (unlikely(!p)) 491 return; 492 493 p = xdr_encode_hyper(p, arg->cookie); 494 /* 495 * RFC 8276 says to specify the full max length of the LISTXATTRS 496 * XDR reply. Count is set to the XDR length of the names array 497 * plus the EOF marker. So, add the cookie and the names count. 498 */ 499 *p = cpu_to_be32(arg->count + 8 + 4); 500 } 501 502 /* 503 * Encode ALLOCATE request 504 */ 505 static void nfs4_xdr_enc_allocate(struct rpc_rqst *req, 506 struct xdr_stream *xdr, 507 const void *data) 508 { 509 const struct nfs42_falloc_args *args = data; 510 struct compound_hdr hdr = { 511 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 512 }; 513 514 encode_compound_hdr(xdr, req, &hdr); 515 encode_sequence(xdr, &args->seq_args, &hdr); 516 encode_putfh(xdr, args->falloc_fh, &hdr); 517 encode_allocate(xdr, args, &hdr); 518 encode_getfattr(xdr, args->falloc_bitmask, &hdr); 519 encode_nops(&hdr); 520 } 521 522 /* 523 * Encode COPY request 524 */ 525 static void nfs4_xdr_enc_copy(struct rpc_rqst *req, 526 struct xdr_stream *xdr, 527 const void *data) 528 { 529 const struct nfs42_copy_args *args = data; 530 struct compound_hdr hdr = { 531 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 532 }; 533 534 encode_compound_hdr(xdr, req, &hdr); 535 encode_sequence(xdr, &args->seq_args, &hdr); 536 encode_putfh(xdr, args->src_fh, &hdr); 537 encode_savefh(xdr, &hdr); 538 encode_putfh(xdr, args->dst_fh, &hdr); 539 encode_copy(xdr, args, &hdr); 540 if (args->sync) 541 encode_copy_commit(xdr, args, &hdr); 542 encode_nops(&hdr); 543 } 544 545 /* 546 * Encode OFFLOAD_CANEL request 547 */ 548 static void nfs4_xdr_enc_offload_cancel(struct rpc_rqst *req, 549 struct xdr_stream *xdr, 550 const void *data) 551 { 552 const struct nfs42_offload_status_args *args = data; 553 struct compound_hdr hdr = { 554 .minorversion = nfs4_xdr_minorversion(&args->osa_seq_args), 555 }; 556 557 encode_compound_hdr(xdr, req, &hdr); 558 encode_sequence(xdr, &args->osa_seq_args, &hdr); 559 encode_putfh(xdr, args->osa_src_fh, &hdr); 560 encode_offload_cancel(xdr, args, &hdr); 561 encode_nops(&hdr); 562 } 563 564 /* 565 * Encode COPY_NOTIFY request 566 */ 567 static void nfs4_xdr_enc_copy_notify(struct rpc_rqst *req, 568 struct xdr_stream *xdr, 569 const void *data) 570 { 571 const struct nfs42_copy_notify_args *args = data; 572 struct compound_hdr hdr = { 573 .minorversion = nfs4_xdr_minorversion(&args->cna_seq_args), 574 }; 575 576 encode_compound_hdr(xdr, req, &hdr); 577 encode_sequence(xdr, &args->cna_seq_args, &hdr); 578 encode_putfh(xdr, args->cna_src_fh, &hdr); 579 encode_copy_notify(xdr, args, &hdr); 580 encode_nops(&hdr); 581 } 582 583 /* 584 * Encode DEALLOCATE request 585 */ 586 static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req, 587 struct xdr_stream *xdr, 588 const void *data) 589 { 590 const struct nfs42_falloc_args *args = data; 591 struct compound_hdr hdr = { 592 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 593 }; 594 595 encode_compound_hdr(xdr, req, &hdr); 596 encode_sequence(xdr, &args->seq_args, &hdr); 597 encode_putfh(xdr, args->falloc_fh, &hdr); 598 encode_deallocate(xdr, args, &hdr); 599 encode_getfattr(xdr, args->falloc_bitmask, &hdr); 600 encode_nops(&hdr); 601 } 602 603 /* 604 * Encode READ_PLUS request 605 */ 606 static void nfs4_xdr_enc_read_plus(struct rpc_rqst *req, 607 struct xdr_stream *xdr, 608 const void *data) 609 { 610 const struct nfs_pgio_args *args = data; 611 struct compound_hdr hdr = { 612 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 613 }; 614 615 encode_compound_hdr(xdr, req, &hdr); 616 encode_sequence(xdr, &args->seq_args, &hdr); 617 encode_putfh(xdr, args->fh, &hdr); 618 encode_read_plus(xdr, args, &hdr); 619 620 rpc_prepare_reply_pages(req, args->pages, args->pgbase, 621 args->count, hdr.replen); 622 encode_nops(&hdr); 623 } 624 625 /* 626 * Encode SEEK request 627 */ 628 static void nfs4_xdr_enc_seek(struct rpc_rqst *req, 629 struct xdr_stream *xdr, 630 const void *data) 631 { 632 const struct nfs42_seek_args *args = data; 633 struct compound_hdr hdr = { 634 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 635 }; 636 637 encode_compound_hdr(xdr, req, &hdr); 638 encode_sequence(xdr, &args->seq_args, &hdr); 639 encode_putfh(xdr, args->sa_fh, &hdr); 640 encode_seek(xdr, args, &hdr); 641 encode_nops(&hdr); 642 } 643 644 /* 645 * Encode LAYOUTSTATS request 646 */ 647 static void nfs4_xdr_enc_layoutstats(struct rpc_rqst *req, 648 struct xdr_stream *xdr, 649 const void *data) 650 { 651 const struct nfs42_layoutstat_args *args = data; 652 int i; 653 654 struct compound_hdr hdr = { 655 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 656 }; 657 658 encode_compound_hdr(xdr, req, &hdr); 659 encode_sequence(xdr, &args->seq_args, &hdr); 660 encode_putfh(xdr, args->fh, &hdr); 661 WARN_ON(args->num_dev > PNFS_LAYOUTSTATS_MAXDEV); 662 for (i = 0; i < args->num_dev; i++) 663 encode_layoutstats(xdr, args, &args->devinfo[i], &hdr); 664 encode_nops(&hdr); 665 } 666 667 /* 668 * Encode CLONE request 669 */ 670 static void nfs4_xdr_enc_clone(struct rpc_rqst *req, 671 struct xdr_stream *xdr, 672 const void *data) 673 { 674 const struct nfs42_clone_args *args = data; 675 struct compound_hdr hdr = { 676 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 677 }; 678 679 encode_compound_hdr(xdr, req, &hdr); 680 encode_sequence(xdr, &args->seq_args, &hdr); 681 encode_putfh(xdr, args->src_fh, &hdr); 682 encode_savefh(xdr, &hdr); 683 encode_putfh(xdr, args->dst_fh, &hdr); 684 encode_clone(xdr, args, &hdr); 685 encode_getfattr(xdr, args->dst_bitmask, &hdr); 686 encode_nops(&hdr); 687 } 688 689 /* 690 * Encode LAYOUTERROR request 691 */ 692 static void nfs4_xdr_enc_layouterror(struct rpc_rqst *req, 693 struct xdr_stream *xdr, 694 const void *data) 695 { 696 const struct nfs42_layouterror_args *args = data; 697 struct compound_hdr hdr = { 698 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 699 }; 700 int i; 701 702 encode_compound_hdr(xdr, req, &hdr); 703 encode_sequence(xdr, &args->seq_args, &hdr); 704 encode_putfh(xdr, NFS_FH(args->inode), &hdr); 705 for (i = 0; i < args->num_errors; i++) 706 encode_layouterror(xdr, &args->errors[i], &hdr); 707 encode_nops(&hdr); 708 } 709 710 /* 711 * Encode SETXATTR request 712 */ 713 static void nfs4_xdr_enc_setxattr(struct rpc_rqst *req, struct xdr_stream *xdr, 714 const void *data) 715 { 716 const struct nfs42_setxattrargs *args = data; 717 struct compound_hdr hdr = { 718 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 719 }; 720 721 encode_compound_hdr(xdr, req, &hdr); 722 encode_sequence(xdr, &args->seq_args, &hdr); 723 encode_putfh(xdr, args->fh, &hdr); 724 encode_setxattr(xdr, args, &hdr); 725 encode_nops(&hdr); 726 } 727 728 /* 729 * Encode GETXATTR request 730 */ 731 static void nfs4_xdr_enc_getxattr(struct rpc_rqst *req, struct xdr_stream *xdr, 732 const void *data) 733 { 734 const struct nfs42_getxattrargs *args = data; 735 struct compound_hdr hdr = { 736 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 737 }; 738 uint32_t replen; 739 740 encode_compound_hdr(xdr, req, &hdr); 741 encode_sequence(xdr, &args->seq_args, &hdr); 742 encode_putfh(xdr, args->fh, &hdr); 743 replen = hdr.replen + op_decode_hdr_maxsz + 1; 744 encode_getxattr(xdr, args->xattr_name, &hdr); 745 746 rpc_prepare_reply_pages(req, args->xattr_pages, 0, args->xattr_len, 747 replen); 748 749 encode_nops(&hdr); 750 } 751 752 /* 753 * Encode LISTXATTR request 754 */ 755 static void nfs4_xdr_enc_listxattrs(struct rpc_rqst *req, 756 struct xdr_stream *xdr, const void *data) 757 { 758 const struct nfs42_listxattrsargs *args = data; 759 struct compound_hdr hdr = { 760 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 761 }; 762 uint32_t replen; 763 764 encode_compound_hdr(xdr, req, &hdr); 765 encode_sequence(xdr, &args->seq_args, &hdr); 766 encode_putfh(xdr, args->fh, &hdr); 767 replen = hdr.replen + op_decode_hdr_maxsz + 2 + 1; 768 encode_listxattrs(xdr, args, &hdr); 769 770 rpc_prepare_reply_pages(req, args->xattr_pages, 0, args->count, replen); 771 772 encode_nops(&hdr); 773 } 774 775 /* 776 * Encode REMOVEXATTR request 777 */ 778 static void nfs4_xdr_enc_removexattr(struct rpc_rqst *req, 779 struct xdr_stream *xdr, const void *data) 780 { 781 const struct nfs42_removexattrargs *args = data; 782 struct compound_hdr hdr = { 783 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 784 }; 785 786 encode_compound_hdr(xdr, req, &hdr); 787 encode_sequence(xdr, &args->seq_args, &hdr); 788 encode_putfh(xdr, args->fh, &hdr); 789 encode_removexattr(xdr, args->xattr_name, &hdr); 790 encode_nops(&hdr); 791 } 792 793 static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) 794 { 795 return decode_op_hdr(xdr, OP_ALLOCATE); 796 } 797 798 static int decode_write_response(struct xdr_stream *xdr, 799 struct nfs42_write_res *res) 800 { 801 __be32 *p; 802 int status, count; 803 804 p = xdr_inline_decode(xdr, 4); 805 if (unlikely(!p)) 806 return -EIO; 807 count = be32_to_cpup(p); 808 if (count > 1) 809 return -EREMOTEIO; 810 else if (count == 1) { 811 status = decode_opaque_fixed(xdr, &res->stateid, 812 NFS4_STATEID_SIZE); 813 if (unlikely(status)) 814 return -EIO; 815 } 816 p = xdr_inline_decode(xdr, 8 + 4); 817 if (unlikely(!p)) 818 return -EIO; 819 p = xdr_decode_hyper(p, &res->count); 820 res->verifier.committed = be32_to_cpup(p); 821 return decode_verifier(xdr, &res->verifier.verifier); 822 } 823 824 static int decode_nl4_server(struct xdr_stream *xdr, struct nl4_server *ns) 825 { 826 struct nfs42_netaddr *naddr; 827 uint32_t dummy; 828 char *dummy_str; 829 __be32 *p; 830 int status; 831 832 /* nl_type */ 833 p = xdr_inline_decode(xdr, 4); 834 if (unlikely(!p)) 835 return -EIO; 836 ns->nl4_type = be32_to_cpup(p); 837 switch (ns->nl4_type) { 838 case NL4_NAME: 839 case NL4_URL: 840 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 841 if (unlikely(status)) 842 return status; 843 if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 844 return -EIO; 845 memcpy(&ns->u.nl4_str, dummy_str, dummy); 846 ns->u.nl4_str_sz = dummy; 847 break; 848 case NL4_NETADDR: 849 naddr = &ns->u.nl4_addr; 850 851 /* netid string */ 852 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 853 if (unlikely(status)) 854 return status; 855 if (unlikely(dummy > RPCBIND_MAXNETIDLEN)) 856 return -EIO; 857 naddr->netid_len = dummy; 858 memcpy(naddr->netid, dummy_str, naddr->netid_len); 859 860 /* uaddr string */ 861 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 862 if (unlikely(status)) 863 return status; 864 if (unlikely(dummy > RPCBIND_MAXUADDRLEN)) 865 return -EIO; 866 naddr->addr_len = dummy; 867 memcpy(naddr->addr, dummy_str, naddr->addr_len); 868 break; 869 default: 870 WARN_ON_ONCE(1); 871 return -EIO; 872 } 873 return 0; 874 } 875 876 static int decode_copy_requirements(struct xdr_stream *xdr, 877 struct nfs42_copy_res *res) { 878 __be32 *p; 879 880 p = xdr_inline_decode(xdr, 4 + 4); 881 if (unlikely(!p)) 882 return -EIO; 883 884 res->consecutive = be32_to_cpup(p++); 885 res->synchronous = be32_to_cpup(p++); 886 return 0; 887 } 888 889 static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res) 890 { 891 int status; 892 893 status = decode_op_hdr(xdr, OP_COPY); 894 if (status == NFS4ERR_OFFLOAD_NO_REQS) { 895 status = decode_copy_requirements(xdr, res); 896 if (status) 897 return status; 898 return NFS4ERR_OFFLOAD_NO_REQS; 899 } else if (status) 900 return status; 901 902 status = decode_write_response(xdr, &res->write_res); 903 if (status) 904 return status; 905 906 return decode_copy_requirements(xdr, res); 907 } 908 909 static int decode_offload_cancel(struct xdr_stream *xdr, 910 struct nfs42_offload_status_res *res) 911 { 912 return decode_op_hdr(xdr, OP_OFFLOAD_CANCEL); 913 } 914 915 static int decode_copy_notify(struct xdr_stream *xdr, 916 struct nfs42_copy_notify_res *res) 917 { 918 __be32 *p; 919 int status, count; 920 921 status = decode_op_hdr(xdr, OP_COPY_NOTIFY); 922 if (status) 923 return status; 924 /* cnr_lease_time */ 925 p = xdr_inline_decode(xdr, 12); 926 if (unlikely(!p)) 927 return -EIO; 928 p = xdr_decode_hyper(p, &res->cnr_lease_time.seconds); 929 res->cnr_lease_time.nseconds = be32_to_cpup(p); 930 931 status = decode_opaque_fixed(xdr, &res->cnr_stateid, NFS4_STATEID_SIZE); 932 if (unlikely(status)) 933 return -EIO; 934 935 /* number of source addresses */ 936 p = xdr_inline_decode(xdr, 4); 937 if (unlikely(!p)) 938 return -EIO; 939 940 count = be32_to_cpup(p); 941 if (count > 1) 942 pr_warn("NFS: %s: nsvr %d > Supported. Use first servers\n", 943 __func__, count); 944 945 status = decode_nl4_server(xdr, &res->cnr_src); 946 if (unlikely(status)) 947 return -EIO; 948 return 0; 949 } 950 951 static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res) 952 { 953 return decode_op_hdr(xdr, OP_DEALLOCATE); 954 } 955 956 struct read_plus_segment { 957 enum data_content4 type; 958 uint64_t offset; 959 union { 960 struct { 961 uint64_t length; 962 } hole; 963 964 struct { 965 uint32_t length; 966 unsigned int from; 967 } data; 968 }; 969 }; 970 971 static inline uint64_t read_plus_segment_length(struct read_plus_segment *seg) 972 { 973 return seg->type == NFS4_CONTENT_DATA ? seg->data.length : seg->hole.length; 974 } 975 976 static int decode_read_plus_segment(struct xdr_stream *xdr, 977 struct read_plus_segment *seg) 978 { 979 __be32 *p; 980 981 p = xdr_inline_decode(xdr, 4); 982 if (!p) 983 return -EIO; 984 seg->type = be32_to_cpup(p++); 985 986 p = xdr_inline_decode(xdr, seg->type == NFS4_CONTENT_DATA ? 12 : 16); 987 if (!p) 988 return -EIO; 989 p = xdr_decode_hyper(p, &seg->offset); 990 991 if (seg->type == NFS4_CONTENT_DATA) { 992 struct xdr_buf buf; 993 uint32_t len = be32_to_cpup(p); 994 995 seg->data.length = len; 996 seg->data.from = xdr_stream_pos(xdr); 997 998 if (!xdr_stream_subsegment(xdr, &buf, xdr_align_size(len))) 999 return -EIO; 1000 } else if (seg->type == NFS4_CONTENT_HOLE) { 1001 xdr_decode_hyper(p, &seg->hole.length); 1002 } else 1003 return -EINVAL; 1004 return 0; 1005 } 1006 1007 static int process_read_plus_segment(struct xdr_stream *xdr, 1008 struct nfs_pgio_args *args, 1009 struct nfs_pgio_res *res, 1010 struct read_plus_segment *seg) 1011 { 1012 unsigned long offset = seg->offset; 1013 unsigned long length = read_plus_segment_length(seg); 1014 unsigned int bufpos; 1015 1016 if (offset + length < args->offset) 1017 return 0; 1018 else if (offset > args->offset + args->count) { 1019 res->eof = 0; 1020 return 0; 1021 } else if (offset < args->offset) { 1022 length -= (args->offset - offset); 1023 offset = args->offset; 1024 } else if (offset + length > args->offset + args->count) { 1025 length = (args->offset + args->count) - offset; 1026 res->eof = 0; 1027 } 1028 1029 bufpos = xdr->buf->head[0].iov_len + (offset - args->offset); 1030 if (seg->type == NFS4_CONTENT_HOLE) 1031 return xdr_stream_zero(xdr, bufpos, length); 1032 else 1033 return xdr_stream_move_subsegment(xdr, seg->data.from, bufpos, length); 1034 } 1035 1036 static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res) 1037 { 1038 struct nfs_pgio_header *hdr = 1039 container_of(res, struct nfs_pgio_header, res); 1040 struct nfs_pgio_args *args = &hdr->args; 1041 uint32_t segments; 1042 struct read_plus_segment *segs; 1043 int status, i; 1044 __be32 *p; 1045 1046 status = decode_op_hdr(xdr, OP_READ_PLUS); 1047 if (status) 1048 return status; 1049 1050 p = xdr_inline_decode(xdr, 4 + 4); 1051 if (unlikely(!p)) 1052 return -EIO; 1053 1054 res->count = 0; 1055 res->eof = be32_to_cpup(p++); 1056 segments = be32_to_cpup(p++); 1057 if (segments == 0) 1058 return status; 1059 1060 segs = kmalloc_array(segments, sizeof(*segs), GFP_KERNEL); 1061 if (!segs) 1062 return -ENOMEM; 1063 1064 status = -EIO; 1065 for (i = 0; i < segments; i++) { 1066 status = decode_read_plus_segment(xdr, &segs[i]); 1067 if (status < 0) 1068 goto out; 1069 } 1070 1071 xdr_set_pagelen(xdr, xdr_align_size(args->count)); 1072 for (i = segments; i > 0; i--) 1073 res->count += process_read_plus_segment(xdr, args, res, &segs[i-1]); 1074 status = 0; 1075 1076 out: 1077 kfree(segs); 1078 return status; 1079 } 1080 1081 static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res) 1082 { 1083 int status; 1084 __be32 *p; 1085 1086 status = decode_op_hdr(xdr, OP_SEEK); 1087 if (status) 1088 return status; 1089 1090 p = xdr_inline_decode(xdr, 4 + 8); 1091 if (unlikely(!p)) 1092 return -EIO; 1093 1094 res->sr_eof = be32_to_cpup(p++); 1095 p = xdr_decode_hyper(p, &res->sr_offset); 1096 return 0; 1097 } 1098 1099 static int decode_layoutstats(struct xdr_stream *xdr) 1100 { 1101 return decode_op_hdr(xdr, OP_LAYOUTSTATS); 1102 } 1103 1104 static int decode_clone(struct xdr_stream *xdr) 1105 { 1106 return decode_op_hdr(xdr, OP_CLONE); 1107 } 1108 1109 static int decode_layouterror(struct xdr_stream *xdr) 1110 { 1111 return decode_op_hdr(xdr, OP_LAYOUTERROR); 1112 } 1113 1114 static int decode_setxattr(struct xdr_stream *xdr, 1115 struct nfs4_change_info *cinfo) 1116 { 1117 int status; 1118 1119 status = decode_op_hdr(xdr, OP_SETXATTR); 1120 if (status) 1121 goto out; 1122 status = decode_change_info(xdr, cinfo); 1123 out: 1124 return status; 1125 } 1126 1127 static int decode_getxattr(struct xdr_stream *xdr, 1128 struct nfs42_getxattrres *res, 1129 struct rpc_rqst *req) 1130 { 1131 int status; 1132 __be32 *p; 1133 u32 len, rdlen; 1134 1135 status = decode_op_hdr(xdr, OP_GETXATTR); 1136 if (status) 1137 return status; 1138 1139 p = xdr_inline_decode(xdr, 4); 1140 if (unlikely(!p)) 1141 return -EIO; 1142 1143 len = be32_to_cpup(p); 1144 1145 /* 1146 * Only check against the page length here. The actual 1147 * requested length may be smaller, but that is only 1148 * checked against after possibly caching a valid reply. 1149 */ 1150 if (len > req->rq_rcv_buf.page_len) 1151 return -ERANGE; 1152 1153 res->xattr_len = len; 1154 1155 if (len > 0) { 1156 rdlen = xdr_read_pages(xdr, len); 1157 if (rdlen < len) 1158 return -EIO; 1159 } 1160 1161 return 0; 1162 } 1163 1164 static int decode_removexattr(struct xdr_stream *xdr, 1165 struct nfs4_change_info *cinfo) 1166 { 1167 int status; 1168 1169 status = decode_op_hdr(xdr, OP_REMOVEXATTR); 1170 if (status) 1171 goto out; 1172 1173 status = decode_change_info(xdr, cinfo); 1174 out: 1175 return status; 1176 } 1177 1178 static int decode_listxattrs(struct xdr_stream *xdr, 1179 struct nfs42_listxattrsres *res) 1180 { 1181 int status; 1182 __be32 *p; 1183 u32 count, len, ulen; 1184 size_t left, copied; 1185 char *buf; 1186 1187 status = decode_op_hdr(xdr, OP_LISTXATTRS); 1188 if (status) { 1189 /* 1190 * Special case: for LISTXATTRS, NFS4ERR_TOOSMALL 1191 * should be translated to ERANGE. 1192 */ 1193 if (status == -ETOOSMALL) 1194 status = -ERANGE; 1195 /* 1196 * Special case: for LISTXATTRS, NFS4ERR_NOXATTR 1197 * should be translated to success with zero-length reply. 1198 */ 1199 if (status == -ENODATA) { 1200 res->eof = true; 1201 status = 0; 1202 } 1203 goto out; 1204 } 1205 1206 p = xdr_inline_decode(xdr, 8); 1207 if (unlikely(!p)) 1208 return -EIO; 1209 1210 xdr_decode_hyper(p, &res->cookie); 1211 1212 p = xdr_inline_decode(xdr, 4); 1213 if (unlikely(!p)) 1214 return -EIO; 1215 1216 left = res->xattr_len; 1217 buf = res->xattr_buf; 1218 1219 count = be32_to_cpup(p); 1220 copied = 0; 1221 1222 /* 1223 * We have asked for enough room to encode the maximum number 1224 * of possible attribute names, so everything should fit. 1225 * 1226 * But, don't rely on that assumption. Just decode entries 1227 * until they don't fit anymore, just in case the server did 1228 * something odd. 1229 */ 1230 while (count--) { 1231 p = xdr_inline_decode(xdr, 4); 1232 if (unlikely(!p)) 1233 return -EIO; 1234 1235 len = be32_to_cpup(p); 1236 if (len > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) { 1237 status = -ERANGE; 1238 goto out; 1239 } 1240 1241 p = xdr_inline_decode(xdr, len); 1242 if (unlikely(!p)) 1243 return -EIO; 1244 1245 ulen = len + XATTR_USER_PREFIX_LEN + 1; 1246 if (buf) { 1247 if (ulen > left) { 1248 status = -ERANGE; 1249 goto out; 1250 } 1251 1252 memcpy(buf, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 1253 memcpy(buf + XATTR_USER_PREFIX_LEN, p, len); 1254 1255 buf[ulen - 1] = 0; 1256 buf += ulen; 1257 left -= ulen; 1258 } 1259 copied += ulen; 1260 } 1261 1262 p = xdr_inline_decode(xdr, 4); 1263 if (unlikely(!p)) 1264 return -EIO; 1265 1266 res->eof = be32_to_cpup(p); 1267 res->copied = copied; 1268 1269 out: 1270 if (status == -ERANGE && res->xattr_len == XATTR_LIST_MAX) 1271 status = -E2BIG; 1272 1273 return status; 1274 } 1275 1276 /* 1277 * Decode ALLOCATE request 1278 */ 1279 static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp, 1280 struct xdr_stream *xdr, 1281 void *data) 1282 { 1283 struct nfs42_falloc_res *res = data; 1284 struct compound_hdr hdr; 1285 int status; 1286 1287 status = decode_compound_hdr(xdr, &hdr); 1288 if (status) 1289 goto out; 1290 status = decode_sequence(xdr, &res->seq_res, rqstp); 1291 if (status) 1292 goto out; 1293 status = decode_putfh(xdr); 1294 if (status) 1295 goto out; 1296 status = decode_allocate(xdr, res); 1297 if (status) 1298 goto out; 1299 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); 1300 out: 1301 return status; 1302 } 1303 1304 /* 1305 * Decode COPY response 1306 */ 1307 static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp, 1308 struct xdr_stream *xdr, 1309 void *data) 1310 { 1311 struct nfs42_copy_res *res = data; 1312 struct compound_hdr hdr; 1313 int status; 1314 1315 status = decode_compound_hdr(xdr, &hdr); 1316 if (status) 1317 goto out; 1318 status = decode_sequence(xdr, &res->seq_res, rqstp); 1319 if (status) 1320 goto out; 1321 status = decode_putfh(xdr); 1322 if (status) 1323 goto out; 1324 status = decode_savefh(xdr); 1325 if (status) 1326 goto out; 1327 status = decode_putfh(xdr); 1328 if (status) 1329 goto out; 1330 status = decode_copy(xdr, res); 1331 if (status) 1332 goto out; 1333 if (res->commit_res.verf) 1334 status = decode_commit(xdr, &res->commit_res); 1335 out: 1336 return status; 1337 } 1338 1339 /* 1340 * Decode OFFLOAD_CANCEL response 1341 */ 1342 static int nfs4_xdr_dec_offload_cancel(struct rpc_rqst *rqstp, 1343 struct xdr_stream *xdr, 1344 void *data) 1345 { 1346 struct nfs42_offload_status_res *res = data; 1347 struct compound_hdr hdr; 1348 int status; 1349 1350 status = decode_compound_hdr(xdr, &hdr); 1351 if (status) 1352 goto out; 1353 status = decode_sequence(xdr, &res->osr_seq_res, rqstp); 1354 if (status) 1355 goto out; 1356 status = decode_putfh(xdr); 1357 if (status) 1358 goto out; 1359 status = decode_offload_cancel(xdr, res); 1360 1361 out: 1362 return status; 1363 } 1364 1365 /* 1366 * Decode COPY_NOTIFY response 1367 */ 1368 static int nfs4_xdr_dec_copy_notify(struct rpc_rqst *rqstp, 1369 struct xdr_stream *xdr, 1370 void *data) 1371 { 1372 struct nfs42_copy_notify_res *res = data; 1373 struct compound_hdr hdr; 1374 int status; 1375 1376 status = decode_compound_hdr(xdr, &hdr); 1377 if (status) 1378 goto out; 1379 status = decode_sequence(xdr, &res->cnr_seq_res, rqstp); 1380 if (status) 1381 goto out; 1382 status = decode_putfh(xdr); 1383 if (status) 1384 goto out; 1385 status = decode_copy_notify(xdr, res); 1386 1387 out: 1388 return status; 1389 } 1390 1391 /* 1392 * Decode DEALLOCATE request 1393 */ 1394 static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp, 1395 struct xdr_stream *xdr, 1396 void *data) 1397 { 1398 struct nfs42_falloc_res *res = data; 1399 struct compound_hdr hdr; 1400 int status; 1401 1402 status = decode_compound_hdr(xdr, &hdr); 1403 if (status) 1404 goto out; 1405 status = decode_sequence(xdr, &res->seq_res, rqstp); 1406 if (status) 1407 goto out; 1408 status = decode_putfh(xdr); 1409 if (status) 1410 goto out; 1411 status = decode_deallocate(xdr, res); 1412 if (status) 1413 goto out; 1414 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server); 1415 out: 1416 return status; 1417 } 1418 1419 /* 1420 * Decode READ_PLUS request 1421 */ 1422 static int nfs4_xdr_dec_read_plus(struct rpc_rqst *rqstp, 1423 struct xdr_stream *xdr, 1424 void *data) 1425 { 1426 struct nfs_pgio_res *res = data; 1427 struct compound_hdr hdr; 1428 int status; 1429 1430 xdr_set_scratch_buffer(xdr, res->scratch, sizeof(res->scratch)); 1431 1432 status = decode_compound_hdr(xdr, &hdr); 1433 if (status) 1434 goto out; 1435 status = decode_sequence(xdr, &res->seq_res, rqstp); 1436 if (status) 1437 goto out; 1438 status = decode_putfh(xdr); 1439 if (status) 1440 goto out; 1441 status = decode_read_plus(xdr, res); 1442 if (!status) 1443 status = res->count; 1444 out: 1445 return status; 1446 } 1447 1448 /* 1449 * Decode SEEK request 1450 */ 1451 static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp, 1452 struct xdr_stream *xdr, 1453 void *data) 1454 { 1455 struct nfs42_seek_res *res = data; 1456 struct compound_hdr hdr; 1457 int status; 1458 1459 status = decode_compound_hdr(xdr, &hdr); 1460 if (status) 1461 goto out; 1462 status = decode_sequence(xdr, &res->seq_res, rqstp); 1463 if (status) 1464 goto out; 1465 status = decode_putfh(xdr); 1466 if (status) 1467 goto out; 1468 status = decode_seek(xdr, res); 1469 out: 1470 return status; 1471 } 1472 1473 /* 1474 * Decode LAYOUTSTATS request 1475 */ 1476 static int nfs4_xdr_dec_layoutstats(struct rpc_rqst *rqstp, 1477 struct xdr_stream *xdr, 1478 void *data) 1479 { 1480 struct nfs42_layoutstat_res *res = data; 1481 struct compound_hdr hdr; 1482 int status, i; 1483 1484 status = decode_compound_hdr(xdr, &hdr); 1485 if (status) 1486 goto out; 1487 status = decode_sequence(xdr, &res->seq_res, rqstp); 1488 if (status) 1489 goto out; 1490 status = decode_putfh(xdr); 1491 if (status) 1492 goto out; 1493 WARN_ON(res->num_dev > PNFS_LAYOUTSTATS_MAXDEV); 1494 for (i = 0; i < res->num_dev; i++) { 1495 status = decode_layoutstats(xdr); 1496 if (status) 1497 goto out; 1498 } 1499 out: 1500 res->rpc_status = status; 1501 return status; 1502 } 1503 1504 /* 1505 * Decode CLONE request 1506 */ 1507 static int nfs4_xdr_dec_clone(struct rpc_rqst *rqstp, 1508 struct xdr_stream *xdr, 1509 void *data) 1510 { 1511 struct nfs42_clone_res *res = data; 1512 struct compound_hdr hdr; 1513 int status; 1514 1515 status = decode_compound_hdr(xdr, &hdr); 1516 if (status) 1517 goto out; 1518 status = decode_sequence(xdr, &res->seq_res, rqstp); 1519 if (status) 1520 goto out; 1521 status = decode_putfh(xdr); 1522 if (status) 1523 goto out; 1524 status = decode_savefh(xdr); 1525 if (status) 1526 goto out; 1527 status = decode_putfh(xdr); 1528 if (status) 1529 goto out; 1530 status = decode_clone(xdr); 1531 if (status) 1532 goto out; 1533 decode_getfattr(xdr, res->dst_fattr, res->server); 1534 out: 1535 res->rpc_status = status; 1536 return status; 1537 } 1538 1539 /* 1540 * Decode LAYOUTERROR request 1541 */ 1542 static int nfs4_xdr_dec_layouterror(struct rpc_rqst *rqstp, 1543 struct xdr_stream *xdr, 1544 void *data) 1545 { 1546 struct nfs42_layouterror_res *res = data; 1547 struct compound_hdr hdr; 1548 int status, i; 1549 1550 status = decode_compound_hdr(xdr, &hdr); 1551 if (status) 1552 goto out; 1553 status = decode_sequence(xdr, &res->seq_res, rqstp); 1554 if (status) 1555 goto out; 1556 status = decode_putfh(xdr); 1557 1558 for (i = 0; i < res->num_errors && status == 0; i++) 1559 status = decode_layouterror(xdr); 1560 out: 1561 res->rpc_status = status; 1562 return status; 1563 } 1564 1565 /* 1566 * Decode SETXATTR request 1567 */ 1568 static int nfs4_xdr_dec_setxattr(struct rpc_rqst *req, struct xdr_stream *xdr, 1569 void *data) 1570 { 1571 struct nfs42_setxattrres *res = data; 1572 struct compound_hdr hdr; 1573 int status; 1574 1575 status = decode_compound_hdr(xdr, &hdr); 1576 if (status) 1577 goto out; 1578 status = decode_sequence(xdr, &res->seq_res, req); 1579 if (status) 1580 goto out; 1581 status = decode_putfh(xdr); 1582 if (status) 1583 goto out; 1584 1585 status = decode_setxattr(xdr, &res->cinfo); 1586 out: 1587 return status; 1588 } 1589 1590 /* 1591 * Decode GETXATTR request 1592 */ 1593 static int nfs4_xdr_dec_getxattr(struct rpc_rqst *rqstp, 1594 struct xdr_stream *xdr, void *data) 1595 { 1596 struct nfs42_getxattrres *res = data; 1597 struct compound_hdr hdr; 1598 int status; 1599 1600 status = decode_compound_hdr(xdr, &hdr); 1601 if (status) 1602 goto out; 1603 status = decode_sequence(xdr, &res->seq_res, rqstp); 1604 if (status) 1605 goto out; 1606 status = decode_putfh(xdr); 1607 if (status) 1608 goto out; 1609 status = decode_getxattr(xdr, res, rqstp); 1610 out: 1611 return status; 1612 } 1613 1614 /* 1615 * Decode LISTXATTR request 1616 */ 1617 static int nfs4_xdr_dec_listxattrs(struct rpc_rqst *rqstp, 1618 struct xdr_stream *xdr, void *data) 1619 { 1620 struct nfs42_listxattrsres *res = data; 1621 struct compound_hdr hdr; 1622 int status; 1623 1624 xdr_set_scratch_page(xdr, res->scratch); 1625 1626 status = decode_compound_hdr(xdr, &hdr); 1627 if (status) 1628 goto out; 1629 status = decode_sequence(xdr, &res->seq_res, rqstp); 1630 if (status) 1631 goto out; 1632 status = decode_putfh(xdr); 1633 if (status) 1634 goto out; 1635 status = decode_listxattrs(xdr, res); 1636 out: 1637 return status; 1638 } 1639 1640 /* 1641 * Decode REMOVEXATTR request 1642 */ 1643 static int nfs4_xdr_dec_removexattr(struct rpc_rqst *req, 1644 struct xdr_stream *xdr, void *data) 1645 { 1646 struct nfs42_removexattrres *res = data; 1647 struct compound_hdr hdr; 1648 int status; 1649 1650 status = decode_compound_hdr(xdr, &hdr); 1651 if (status) 1652 goto out; 1653 status = decode_sequence(xdr, &res->seq_res, req); 1654 if (status) 1655 goto out; 1656 status = decode_putfh(xdr); 1657 if (status) 1658 goto out; 1659 1660 status = decode_removexattr(xdr, &res->cinfo); 1661 out: 1662 return status; 1663 } 1664 #endif /* __LINUX_FS_NFS_NFS4_2XDR_H */ 1665