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