1/* 2 * fs/nfs/nfs4xdr.c 3 * 4 * Client-side XDR for NFSv4. 5 * 6 * Copyright (c) 2002 The Regents of the University of Michigan. 7 * All rights reserved. 8 * 9 * Kendrick Smith <kmsmith@umich.edu> 10 * Andy Adamson <andros@umich.edu> 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. Neither the name of the University nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#include <linux/param.h> 39#include <linux/time.h> 40#include <linux/mm.h> 41#include <linux/errno.h> 42#include <linux/string.h> 43#include <linux/in.h> 44#include <linux/pagemap.h> 45#include <linux/proc_fs.h> 46#include <linux/kdev_t.h> 47#include <linux/sunrpc/clnt.h> 48#include <linux/sunrpc/msg_prot.h> 49#include <linux/nfs.h> 50#include <linux/nfs4.h> 51#include <linux/nfs_fs.h> 52#include <linux/nfs_idmap.h> 53#include "nfs4_fs.h" 54#include "internal.h" 55 56#define NFSDBG_FACILITY NFSDBG_XDR 57 58/* Mapping from NFS error code to "errno" error code. */ 59#define errno_NFSERR_IO EIO 60 61static int nfs4_stat_to_errno(int); 62 63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 64#ifdef DEBUG 65#define NFS4_MAXTAGLEN 20 66#else 67#define NFS4_MAXTAGLEN 0 68#endif 69 70/* lock,open owner id: 71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 72 */ 73#define open_owner_id_maxsz (1 + 4) 74#define lock_owner_id_maxsz (1 + 4) 75#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 76#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 78#define op_encode_hdr_maxsz (1) 79#define op_decode_hdr_maxsz (2) 80#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 84#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 85 (NFS4_FHSIZE >> 2)) 86#define decode_putfh_maxsz (op_decode_hdr_maxsz) 87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 89#define encode_getfh_maxsz (op_encode_hdr_maxsz) 90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 91 ((3+NFS4_FHSIZE) >> 2)) 92#define nfs4_fattr_bitmap_maxsz 3 93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 94#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 96#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 98/* This is based on getfattr, which uses the most attributes: */ 99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz)) 101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 102 nfs4_fattr_value_maxsz) 103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 105 1 + 2 + 1 + \ 106 nfs4_owner_maxsz + \ 107 nfs4_group_maxsz + \ 108 4 + 4) 109#define encode_savefh_maxsz (op_encode_hdr_maxsz) 110#define decode_savefh_maxsz (op_decode_hdr_maxsz) 111#define encode_restorefh_maxsz (op_encode_hdr_maxsz) 112#define decode_restorefh_maxsz (op_decode_hdr_maxsz) 113#define encode_fsinfo_maxsz (encode_getattr_maxsz) 114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11) 115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 116#define decode_renew_maxsz (op_decode_hdr_maxsz) 117#define encode_setclientid_maxsz \ 118 (op_encode_hdr_maxsz + \ 119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ 121 1 /* sc_prog */ + \ 122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 124 1) /* sc_cb_ident */ 125#define decode_setclientid_maxsz \ 126 (op_decode_hdr_maxsz + \ 127 2 + \ 128 1024) /* large value for CLID_INUSE */ 129#define encode_setclientid_confirm_maxsz \ 130 (op_encode_hdr_maxsz + \ 131 3 + (NFS4_VERIFIER_SIZE >> 2)) 132#define decode_setclientid_confirm_maxsz \ 133 (op_decode_hdr_maxsz) 134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 135#define decode_lookup_maxsz (op_decode_hdr_maxsz) 136#define encode_share_access_maxsz \ 137 (2) 138#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 139#define encode_opentype_maxsz (1 + encode_createmode_maxsz) 140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 141#define encode_open_maxsz (op_encode_hdr_maxsz + \ 142 2 + encode_share_access_maxsz + 2 + \ 143 open_owner_id_maxsz + \ 144 encode_opentype_maxsz + \ 145 encode_claim_null_maxsz) 146#define decode_ace_maxsz (3 + nfs4_owner_maxsz) 147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 148 decode_ace_maxsz) 149#define decode_change_info_maxsz (5) 150#define decode_open_maxsz (op_decode_hdr_maxsz + \ 151 decode_stateid_maxsz + \ 152 decode_change_info_maxsz + 1 + \ 153 nfs4_fattr_bitmap_maxsz + \ 154 decode_delegation_maxsz) 155#define encode_open_confirm_maxsz \ 156 (op_encode_hdr_maxsz + \ 157 encode_stateid_maxsz + 1) 158#define decode_open_confirm_maxsz \ 159 (op_decode_hdr_maxsz + \ 160 decode_stateid_maxsz) 161#define encode_open_downgrade_maxsz \ 162 (op_encode_hdr_maxsz + \ 163 encode_stateid_maxsz + 1 + \ 164 encode_share_access_maxsz) 165#define decode_open_downgrade_maxsz \ 166 (op_decode_hdr_maxsz + \ 167 decode_stateid_maxsz) 168#define encode_close_maxsz (op_encode_hdr_maxsz + \ 169 1 + encode_stateid_maxsz) 170#define decode_close_maxsz (op_decode_hdr_maxsz + \ 171 decode_stateid_maxsz) 172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 173 encode_stateid_maxsz + \ 174 encode_attrs_maxsz) 175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 176 nfs4_fattr_bitmap_maxsz) 177#define encode_read_maxsz (op_encode_hdr_maxsz + \ 178 encode_stateid_maxsz + 3) 179#define decode_read_maxsz (op_decode_hdr_maxsz + 2) 180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 181 2 + encode_verifier_maxsz + 5) 182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 183 decode_verifier_maxsz) 184#define encode_readlink_maxsz (op_encode_hdr_maxsz) 185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 186#define encode_write_maxsz (op_encode_hdr_maxsz + \ 187 encode_stateid_maxsz + 4) 188#define decode_write_maxsz (op_decode_hdr_maxsz + \ 189 2 + decode_verifier_maxsz) 190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 191#define decode_commit_maxsz (op_decode_hdr_maxsz + \ 192 decode_verifier_maxsz) 193#define encode_remove_maxsz (op_encode_hdr_maxsz + \ 194 nfs4_name_maxsz) 195#define decode_remove_maxsz (op_decode_hdr_maxsz + \ 196 decode_change_info_maxsz) 197#define encode_rename_maxsz (op_encode_hdr_maxsz + \ 198 2 * nfs4_name_maxsz) 199#define decode_rename_maxsz (op_decode_hdr_maxsz + \ 200 decode_change_info_maxsz + \ 201 decode_change_info_maxsz) 202#define encode_link_maxsz (op_encode_hdr_maxsz + \ 203 nfs4_name_maxsz) 204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 205#define encode_lockowner_maxsz (7) 206#define encode_lock_maxsz (op_encode_hdr_maxsz + \ 207 7 + \ 208 1 + encode_stateid_maxsz + 1 + \ 209 encode_lockowner_maxsz) 210#define decode_lock_denied_maxsz \ 211 (8 + decode_lockowner_maxsz) 212#define decode_lock_maxsz (op_decode_hdr_maxsz + \ 213 decode_lock_denied_maxsz) 214#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 215 encode_lockowner_maxsz) 216#define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 217 decode_lock_denied_maxsz) 218#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 219 encode_stateid_maxsz + \ 220 4) 221#define decode_locku_maxsz (op_decode_hdr_maxsz + \ 222 decode_stateid_maxsz) 223#define encode_release_lockowner_maxsz \ 224 (op_encode_hdr_maxsz + \ 225 encode_lockowner_maxsz) 226#define decode_release_lockowner_maxsz \ 227 (op_decode_hdr_maxsz) 228#define encode_access_maxsz (op_encode_hdr_maxsz + 1) 229#define decode_access_maxsz (op_decode_hdr_maxsz + 2) 230#define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 231 1 + nfs4_name_maxsz + \ 232 1 + \ 233 nfs4_fattr_maxsz) 234#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 235#define encode_create_maxsz (op_encode_hdr_maxsz + \ 236 1 + 2 + nfs4_name_maxsz + \ 237 encode_attrs_maxsz) 238#define decode_create_maxsz (op_decode_hdr_maxsz + \ 239 decode_change_info_maxsz + \ 240 nfs4_fattr_bitmap_maxsz) 241#define encode_statfs_maxsz (encode_getattr_maxsz) 242#define decode_statfs_maxsz (decode_getattr_maxsz) 243#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 244#define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 245#define encode_getacl_maxsz (encode_getattr_maxsz) 246#define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 247 nfs4_fattr_bitmap_maxsz + 1) 248#define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 249 encode_stateid_maxsz + 3) 250#define decode_setacl_maxsz (decode_setattr_maxsz) 251#define encode_fs_locations_maxsz \ 252 (encode_getattr_maxsz) 253#define decode_fs_locations_maxsz \ 254 (0) 255 256#if defined(CONFIG_NFS_V4_1) 257#define NFS4_MAX_MACHINE_NAME_LEN (64) 258 259#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 260 encode_verifier_maxsz + \ 261 1 /* co_ownerid.len */ + \ 262 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ 263 1 /* flags */ + \ 264 1 /* spa_how */ + \ 265 0 /* SP4_NONE (for now) */ + \ 266 1 /* zero implemetation id array */) 267#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 268 2 /* eir_clientid */ + \ 269 1 /* eir_sequenceid */ + \ 270 1 /* eir_flags */ + \ 271 1 /* spr_how */ + \ 272 0 /* SP4_NONE (for now) */ + \ 273 2 /* eir_server_owner.so_minor_id */ + \ 274 /* eir_server_owner.so_major_id<> */ \ 275 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 276 /* eir_server_scope<> */ \ 277 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 278 1 /* eir_server_impl_id array length */ + \ 279 0 /* ignored eir_server_impl_id contents */) 280#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 281#define decode_channel_attrs_maxsz (6 + \ 282 1 /* ca_rdma_ird.len */ + \ 283 1 /* ca_rdma_ird */) 284#define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 285 2 /* csa_clientid */ + \ 286 1 /* csa_sequence */ + \ 287 1 /* csa_flags */ + \ 288 encode_channel_attrs_maxsz + \ 289 encode_channel_attrs_maxsz + \ 290 1 /* csa_cb_program */ + \ 291 1 /* csa_sec_parms.len (1) */ + \ 292 1 /* cb_secflavor (AUTH_SYS) */ + \ 293 1 /* stamp */ + \ 294 1 /* machinename.len */ + \ 295 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 296 1 /* uid */ + \ 297 1 /* gid */ + \ 298 1 /* gids.len (0) */) 299#define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 301 1 /* csr_sequence */ + \ 302 1 /* csr_flags */ + \ 303 decode_channel_attrs_maxsz + \ 304 decode_channel_attrs_maxsz) 305#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 306#define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 307#define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 308 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 309#define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 310 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 311#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 312#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 313#else /* CONFIG_NFS_V4_1 */ 314#define encode_sequence_maxsz 0 315#define decode_sequence_maxsz 0 316#endif /* CONFIG_NFS_V4_1 */ 317 318#define NFS4_enc_compound_sz (1024) 319#define NFS4_dec_compound_sz (1024) 320#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 321 encode_sequence_maxsz + \ 322 encode_putfh_maxsz + \ 323 encode_read_maxsz) 324#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 325 decode_sequence_maxsz + \ 326 decode_putfh_maxsz + \ 327 decode_read_maxsz) 328#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 329 encode_sequence_maxsz + \ 330 encode_putfh_maxsz + \ 331 encode_readlink_maxsz) 332#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 333 decode_sequence_maxsz + \ 334 decode_putfh_maxsz + \ 335 decode_readlink_maxsz) 336#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 337 encode_sequence_maxsz + \ 338 encode_putfh_maxsz + \ 339 encode_readdir_maxsz) 340#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 341 decode_sequence_maxsz + \ 342 decode_putfh_maxsz + \ 343 decode_readdir_maxsz) 344#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 345 encode_sequence_maxsz + \ 346 encode_putfh_maxsz + \ 347 encode_write_maxsz + \ 348 encode_getattr_maxsz) 349#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 350 decode_sequence_maxsz + \ 351 decode_putfh_maxsz + \ 352 decode_write_maxsz + \ 353 decode_getattr_maxsz) 354#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 355 encode_sequence_maxsz + \ 356 encode_putfh_maxsz + \ 357 encode_commit_maxsz + \ 358 encode_getattr_maxsz) 359#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 360 decode_sequence_maxsz + \ 361 decode_putfh_maxsz + \ 362 decode_commit_maxsz + \ 363 decode_getattr_maxsz) 364#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 365 encode_sequence_maxsz + \ 366 encode_putfh_maxsz + \ 367 encode_savefh_maxsz + \ 368 encode_open_maxsz + \ 369 encode_getfh_maxsz + \ 370 encode_getattr_maxsz + \ 371 encode_restorefh_maxsz + \ 372 encode_getattr_maxsz) 373#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 374 decode_sequence_maxsz + \ 375 decode_putfh_maxsz + \ 376 decode_savefh_maxsz + \ 377 decode_open_maxsz + \ 378 decode_getfh_maxsz + \ 379 decode_getattr_maxsz + \ 380 decode_restorefh_maxsz + \ 381 decode_getattr_maxsz) 382#define NFS4_enc_open_confirm_sz \ 383 (compound_encode_hdr_maxsz + \ 384 encode_putfh_maxsz + \ 385 encode_open_confirm_maxsz) 386#define NFS4_dec_open_confirm_sz \ 387 (compound_decode_hdr_maxsz + \ 388 decode_putfh_maxsz + \ 389 decode_open_confirm_maxsz) 390#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 391 encode_sequence_maxsz + \ 392 encode_putfh_maxsz + \ 393 encode_open_maxsz + \ 394 encode_getattr_maxsz) 395#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 396 decode_sequence_maxsz + \ 397 decode_putfh_maxsz + \ 398 decode_open_maxsz + \ 399 decode_getattr_maxsz) 400#define NFS4_enc_open_downgrade_sz \ 401 (compound_encode_hdr_maxsz + \ 402 encode_sequence_maxsz + \ 403 encode_putfh_maxsz + \ 404 encode_open_downgrade_maxsz + \ 405 encode_getattr_maxsz) 406#define NFS4_dec_open_downgrade_sz \ 407 (compound_decode_hdr_maxsz + \ 408 decode_sequence_maxsz + \ 409 decode_putfh_maxsz + \ 410 decode_open_downgrade_maxsz + \ 411 decode_getattr_maxsz) 412#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 413 encode_sequence_maxsz + \ 414 encode_putfh_maxsz + \ 415 encode_close_maxsz + \ 416 encode_getattr_maxsz) 417#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 418 decode_sequence_maxsz + \ 419 decode_putfh_maxsz + \ 420 decode_close_maxsz + \ 421 decode_getattr_maxsz) 422#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 423 encode_sequence_maxsz + \ 424 encode_putfh_maxsz + \ 425 encode_setattr_maxsz + \ 426 encode_getattr_maxsz) 427#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 428 decode_sequence_maxsz + \ 429 decode_putfh_maxsz + \ 430 decode_setattr_maxsz + \ 431 decode_getattr_maxsz) 432#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 433 encode_sequence_maxsz + \ 434 encode_putfh_maxsz + \ 435 encode_fsinfo_maxsz) 436#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 437 decode_sequence_maxsz + \ 438 decode_putfh_maxsz + \ 439 decode_fsinfo_maxsz) 440#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 441 encode_renew_maxsz) 442#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 443 decode_renew_maxsz) 444#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 445 encode_setclientid_maxsz) 446#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 447 decode_setclientid_maxsz) 448#define NFS4_enc_setclientid_confirm_sz \ 449 (compound_encode_hdr_maxsz + \ 450 encode_setclientid_confirm_maxsz + \ 451 encode_putrootfh_maxsz + \ 452 encode_fsinfo_maxsz) 453#define NFS4_dec_setclientid_confirm_sz \ 454 (compound_decode_hdr_maxsz + \ 455 decode_setclientid_confirm_maxsz + \ 456 decode_putrootfh_maxsz + \ 457 decode_fsinfo_maxsz) 458#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 459 encode_sequence_maxsz + \ 460 encode_putfh_maxsz + \ 461 encode_lock_maxsz) 462#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 463 decode_sequence_maxsz + \ 464 decode_putfh_maxsz + \ 465 decode_lock_maxsz) 466#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 467 encode_sequence_maxsz + \ 468 encode_putfh_maxsz + \ 469 encode_lockt_maxsz) 470#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 471 decode_sequence_maxsz + \ 472 decode_putfh_maxsz + \ 473 decode_lockt_maxsz) 474#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 475 encode_sequence_maxsz + \ 476 encode_putfh_maxsz + \ 477 encode_locku_maxsz) 478#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 479 decode_sequence_maxsz + \ 480 decode_putfh_maxsz + \ 481 decode_locku_maxsz) 482#define NFS4_enc_release_lockowner_sz \ 483 (compound_encode_hdr_maxsz + \ 484 encode_lockowner_maxsz) 485#define NFS4_dec_release_lockowner_sz \ 486 (compound_decode_hdr_maxsz + \ 487 decode_lockowner_maxsz) 488#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 489 encode_sequence_maxsz + \ 490 encode_putfh_maxsz + \ 491 encode_access_maxsz + \ 492 encode_getattr_maxsz) 493#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 494 decode_sequence_maxsz + \ 495 decode_putfh_maxsz + \ 496 decode_access_maxsz + \ 497 decode_getattr_maxsz) 498#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 499 encode_sequence_maxsz + \ 500 encode_putfh_maxsz + \ 501 encode_getattr_maxsz) 502#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 503 decode_sequence_maxsz + \ 504 decode_putfh_maxsz + \ 505 decode_getattr_maxsz) 506#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 507 encode_sequence_maxsz + \ 508 encode_putfh_maxsz + \ 509 encode_lookup_maxsz + \ 510 encode_getattr_maxsz + \ 511 encode_getfh_maxsz) 512#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 513 decode_sequence_maxsz + \ 514 decode_putfh_maxsz + \ 515 decode_lookup_maxsz + \ 516 decode_getattr_maxsz + \ 517 decode_getfh_maxsz) 518#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 519 encode_sequence_maxsz + \ 520 encode_putrootfh_maxsz + \ 521 encode_getattr_maxsz + \ 522 encode_getfh_maxsz) 523#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 524 decode_sequence_maxsz + \ 525 decode_putrootfh_maxsz + \ 526 decode_getattr_maxsz + \ 527 decode_getfh_maxsz) 528#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 529 encode_sequence_maxsz + \ 530 encode_putfh_maxsz + \ 531 encode_remove_maxsz + \ 532 encode_getattr_maxsz) 533#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 534 decode_sequence_maxsz + \ 535 decode_putfh_maxsz + \ 536 decode_remove_maxsz + \ 537 decode_getattr_maxsz) 538#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 539 encode_sequence_maxsz + \ 540 encode_putfh_maxsz + \ 541 encode_savefh_maxsz + \ 542 encode_putfh_maxsz + \ 543 encode_rename_maxsz + \ 544 encode_getattr_maxsz + \ 545 encode_restorefh_maxsz + \ 546 encode_getattr_maxsz) 547#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 548 decode_sequence_maxsz + \ 549 decode_putfh_maxsz + \ 550 decode_savefh_maxsz + \ 551 decode_putfh_maxsz + \ 552 decode_rename_maxsz + \ 553 decode_getattr_maxsz + \ 554 decode_restorefh_maxsz + \ 555 decode_getattr_maxsz) 556#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 557 encode_sequence_maxsz + \ 558 encode_putfh_maxsz + \ 559 encode_savefh_maxsz + \ 560 encode_putfh_maxsz + \ 561 encode_link_maxsz + \ 562 decode_getattr_maxsz + \ 563 encode_restorefh_maxsz + \ 564 decode_getattr_maxsz) 565#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 566 decode_sequence_maxsz + \ 567 decode_putfh_maxsz + \ 568 decode_savefh_maxsz + \ 569 decode_putfh_maxsz + \ 570 decode_link_maxsz + \ 571 decode_getattr_maxsz + \ 572 decode_restorefh_maxsz + \ 573 decode_getattr_maxsz) 574#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 575 encode_sequence_maxsz + \ 576 encode_putfh_maxsz + \ 577 encode_symlink_maxsz + \ 578 encode_getattr_maxsz + \ 579 encode_getfh_maxsz) 580#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 581 decode_sequence_maxsz + \ 582 decode_putfh_maxsz + \ 583 decode_symlink_maxsz + \ 584 decode_getattr_maxsz + \ 585 decode_getfh_maxsz) 586#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 587 encode_sequence_maxsz + \ 588 encode_putfh_maxsz + \ 589 encode_savefh_maxsz + \ 590 encode_create_maxsz + \ 591 encode_getfh_maxsz + \ 592 encode_getattr_maxsz + \ 593 encode_restorefh_maxsz + \ 594 encode_getattr_maxsz) 595#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 596 decode_sequence_maxsz + \ 597 decode_putfh_maxsz + \ 598 decode_savefh_maxsz + \ 599 decode_create_maxsz + \ 600 decode_getfh_maxsz + \ 601 decode_getattr_maxsz + \ 602 decode_restorefh_maxsz + \ 603 decode_getattr_maxsz) 604#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 605 encode_sequence_maxsz + \ 606 encode_putfh_maxsz + \ 607 encode_getattr_maxsz) 608#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 609 decode_sequence_maxsz + \ 610 decode_putfh_maxsz + \ 611 decode_getattr_maxsz) 612#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 613 encode_sequence_maxsz + \ 614 encode_putfh_maxsz + \ 615 encode_statfs_maxsz) 616#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 617 decode_sequence_maxsz + \ 618 decode_putfh_maxsz + \ 619 decode_statfs_maxsz) 620#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 621 encode_sequence_maxsz + \ 622 encode_putfh_maxsz + \ 623 encode_getattr_maxsz) 624#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 625 decode_sequence_maxsz + \ 626 decode_putfh_maxsz + \ 627 decode_getattr_maxsz) 628#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 629 encode_sequence_maxsz + \ 630 encode_putfh_maxsz + \ 631 encode_delegreturn_maxsz + \ 632 encode_getattr_maxsz) 633#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 634 decode_sequence_maxsz + \ 635 decode_delegreturn_maxsz + \ 636 decode_getattr_maxsz) 637#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 638 encode_sequence_maxsz + \ 639 encode_putfh_maxsz + \ 640 encode_getacl_maxsz) 641#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 642 decode_sequence_maxsz + \ 643 decode_putfh_maxsz + \ 644 decode_getacl_maxsz) 645#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 646 encode_sequence_maxsz + \ 647 encode_putfh_maxsz + \ 648 encode_setacl_maxsz) 649#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 650 decode_sequence_maxsz + \ 651 decode_putfh_maxsz + \ 652 decode_setacl_maxsz) 653#define NFS4_enc_fs_locations_sz \ 654 (compound_encode_hdr_maxsz + \ 655 encode_sequence_maxsz + \ 656 encode_putfh_maxsz + \ 657 encode_lookup_maxsz + \ 658 encode_fs_locations_maxsz) 659#define NFS4_dec_fs_locations_sz \ 660 (compound_decode_hdr_maxsz + \ 661 decode_sequence_maxsz + \ 662 decode_putfh_maxsz + \ 663 decode_lookup_maxsz + \ 664 decode_fs_locations_maxsz) 665#if defined(CONFIG_NFS_V4_1) 666#define NFS4_enc_exchange_id_sz \ 667 (compound_encode_hdr_maxsz + \ 668 encode_exchange_id_maxsz) 669#define NFS4_dec_exchange_id_sz \ 670 (compound_decode_hdr_maxsz + \ 671 decode_exchange_id_maxsz) 672#define NFS4_enc_create_session_sz \ 673 (compound_encode_hdr_maxsz + \ 674 encode_create_session_maxsz) 675#define NFS4_dec_create_session_sz \ 676 (compound_decode_hdr_maxsz + \ 677 decode_create_session_maxsz) 678#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 679 encode_destroy_session_maxsz) 680#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 681 decode_destroy_session_maxsz) 682#define NFS4_enc_sequence_sz \ 683 (compound_decode_hdr_maxsz + \ 684 encode_sequence_maxsz) 685#define NFS4_dec_sequence_sz \ 686 (compound_decode_hdr_maxsz + \ 687 decode_sequence_maxsz) 688#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 689 encode_sequence_maxsz + \ 690 encode_putrootfh_maxsz + \ 691 encode_fsinfo_maxsz) 692#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 693 decode_sequence_maxsz + \ 694 decode_putrootfh_maxsz + \ 695 decode_fsinfo_maxsz) 696#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 697 encode_sequence_maxsz + \ 698 encode_reclaim_complete_maxsz) 699#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 700 decode_sequence_maxsz + \ 701 decode_reclaim_complete_maxsz) 702 703const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 704 compound_encode_hdr_maxsz + 705 encode_sequence_maxsz + 706 encode_putfh_maxsz + 707 encode_getattr_maxsz) * 708 XDR_UNIT); 709 710const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 711 compound_decode_hdr_maxsz + 712 decode_sequence_maxsz + 713 decode_putfh_maxsz) * 714 XDR_UNIT); 715#endif /* CONFIG_NFS_V4_1 */ 716 717static const umode_t nfs_type2fmt[] = { 718 [NF4BAD] = 0, 719 [NF4REG] = S_IFREG, 720 [NF4DIR] = S_IFDIR, 721 [NF4BLK] = S_IFBLK, 722 [NF4CHR] = S_IFCHR, 723 [NF4LNK] = S_IFLNK, 724 [NF4SOCK] = S_IFSOCK, 725 [NF4FIFO] = S_IFIFO, 726 [NF4ATTRDIR] = 0, 727 [NF4NAMEDATTR] = 0, 728}; 729 730struct compound_hdr { 731 int32_t status; 732 uint32_t nops; 733 __be32 * nops_p; 734 uint32_t taglen; 735 char * tag; 736 uint32_t replen; /* expected reply words */ 737 u32 minorversion; 738}; 739 740static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 741{ 742 __be32 *p = xdr_reserve_space(xdr, nbytes); 743 BUG_ON(!p); 744 return p; 745} 746 747static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 748{ 749 __be32 *p; 750 751 p = xdr_reserve_space(xdr, 4 + len); 752 BUG_ON(p == NULL); 753 xdr_encode_opaque(p, str, len); 754} 755 756static void encode_compound_hdr(struct xdr_stream *xdr, 757 struct rpc_rqst *req, 758 struct compound_hdr *hdr) 759{ 760 __be32 *p; 761 struct rpc_auth *auth = req->rq_cred->cr_auth; 762 763 /* initialize running count of expected bytes in reply. 764 * NOTE: the replied tag SHOULD be the same is the one sent, 765 * but this is not required as a MUST for the server to do so. */ 766 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 767 768 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag); 769 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 770 p = reserve_space(xdr, 4 + hdr->taglen + 8); 771 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen); 772 *p++ = cpu_to_be32(hdr->minorversion); 773 hdr->nops_p = p; 774 *p = cpu_to_be32(hdr->nops); 775} 776 777static void encode_nops(struct compound_hdr *hdr) 778{ 779 BUG_ON(hdr->nops > NFS4_MAX_OPS); 780 *hdr->nops_p = htonl(hdr->nops); 781} 782 783static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 784{ 785 __be32 *p; 786 787 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); 788 BUG_ON(p == NULL); 789 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); 790} 791 792static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) 793{ 794 char owner_name[IDMAP_NAMESZ]; 795 char owner_group[IDMAP_NAMESZ]; 796 int owner_namelen = 0; 797 int owner_grouplen = 0; 798 __be32 *p; 799 __be32 *q; 800 int len; 801 uint32_t bmval0 = 0; 802 uint32_t bmval1 = 0; 803 804 /* 805 * We reserve enough space to write the entire attribute buffer at once. 806 * In the worst-case, this would be 807 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 808 * = 36 bytes, plus any contribution from variable-length fields 809 * such as owner/group. 810 */ 811 len = 16; 812 813 /* Sigh */ 814 if (iap->ia_valid & ATTR_SIZE) 815 len += 8; 816 if (iap->ia_valid & ATTR_MODE) 817 len += 4; 818 if (iap->ia_valid & ATTR_UID) { 819 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name); 820 if (owner_namelen < 0) { 821 dprintk("nfs: couldn't resolve uid %d to string\n", 822 iap->ia_uid); 823 strcpy(owner_name, "nobody"); 824 owner_namelen = sizeof("nobody") - 1; 825 /* goto out; */ 826 } 827 len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 828 } 829 if (iap->ia_valid & ATTR_GID) { 830 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group); 831 if (owner_grouplen < 0) { 832 dprintk("nfs: couldn't resolve gid %d to string\n", 833 iap->ia_gid); 834 strcpy(owner_group, "nobody"); 835 owner_grouplen = sizeof("nobody") - 1; 836 /* goto out; */ 837 } 838 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 839 } 840 if (iap->ia_valid & ATTR_ATIME_SET) 841 len += 16; 842 else if (iap->ia_valid & ATTR_ATIME) 843 len += 4; 844 if (iap->ia_valid & ATTR_MTIME_SET) 845 len += 16; 846 else if (iap->ia_valid & ATTR_MTIME) 847 len += 4; 848 p = reserve_space(xdr, len); 849 850 /* 851 * We write the bitmap length now, but leave the bitmap and the attribute 852 * buffer length to be backfilled at the end of this routine. 853 */ 854 *p++ = cpu_to_be32(2); 855 q = p; 856 p += 3; 857 858 if (iap->ia_valid & ATTR_SIZE) { 859 bmval0 |= FATTR4_WORD0_SIZE; 860 p = xdr_encode_hyper(p, iap->ia_size); 861 } 862 if (iap->ia_valid & ATTR_MODE) { 863 bmval1 |= FATTR4_WORD1_MODE; 864 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 865 } 866 if (iap->ia_valid & ATTR_UID) { 867 bmval1 |= FATTR4_WORD1_OWNER; 868 p = xdr_encode_opaque(p, owner_name, owner_namelen); 869 } 870 if (iap->ia_valid & ATTR_GID) { 871 bmval1 |= FATTR4_WORD1_OWNER_GROUP; 872 p = xdr_encode_opaque(p, owner_group, owner_grouplen); 873 } 874 if (iap->ia_valid & ATTR_ATIME_SET) { 875 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 876 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 877 *p++ = cpu_to_be32(0); 878 *p++ = cpu_to_be32(iap->ia_atime.tv_sec); 879 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 880 } 881 else if (iap->ia_valid & ATTR_ATIME) { 882 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 883 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 884 } 885 if (iap->ia_valid & ATTR_MTIME_SET) { 886 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 887 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 888 *p++ = cpu_to_be32(0); 889 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec); 890 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 891 } 892 else if (iap->ia_valid & ATTR_MTIME) { 893 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 894 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 895 } 896 897 /* 898 * Now we backfill the bitmap and the attribute buffer length. 899 */ 900 if (len != ((char *)p - (char *)q) + 4) { 901 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n", 902 len, ((char *)p - (char *)q) + 4); 903 BUG(); 904 } 905 len = (char *)p - (char *)q - 12; 906 *q++ = htonl(bmval0); 907 *q++ = htonl(bmval1); 908 *q = htonl(len); 909 910/* out: */ 911} 912 913static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 914{ 915 __be32 *p; 916 917 p = reserve_space(xdr, 8); 918 *p++ = cpu_to_be32(OP_ACCESS); 919 *p = cpu_to_be32(access); 920 hdr->nops++; 921 hdr->replen += decode_access_maxsz; 922} 923 924static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 925{ 926 __be32 *p; 927 928 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE); 929 *p++ = cpu_to_be32(OP_CLOSE); 930 *p++ = cpu_to_be32(arg->seqid->sequence->counter); 931 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); 932 hdr->nops++; 933 hdr->replen += decode_close_maxsz; 934} 935 936static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 937{ 938 __be32 *p; 939 940 p = reserve_space(xdr, 16); 941 *p++ = cpu_to_be32(OP_COMMIT); 942 p = xdr_encode_hyper(p, args->offset); 943 *p = cpu_to_be32(args->count); 944 hdr->nops++; 945 hdr->replen += decode_commit_maxsz; 946} 947 948static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 949{ 950 __be32 *p; 951 952 p = reserve_space(xdr, 8); 953 *p++ = cpu_to_be32(OP_CREATE); 954 *p = cpu_to_be32(create->ftype); 955 956 switch (create->ftype) { 957 case NF4LNK: 958 p = reserve_space(xdr, 4); 959 *p = cpu_to_be32(create->u.symlink.len); 960 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 961 break; 962 963 case NF4BLK: case NF4CHR: 964 p = reserve_space(xdr, 8); 965 *p++ = cpu_to_be32(create->u.device.specdata1); 966 *p = cpu_to_be32(create->u.device.specdata2); 967 break; 968 969 default: 970 break; 971 } 972 973 encode_string(xdr, create->name->len, create->name->name); 974 hdr->nops++; 975 hdr->replen += decode_create_maxsz; 976 977 encode_attrs(xdr, create->attrs, create->server); 978} 979 980static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 981{ 982 __be32 *p; 983 984 p = reserve_space(xdr, 12); 985 *p++ = cpu_to_be32(OP_GETATTR); 986 *p++ = cpu_to_be32(1); 987 *p = cpu_to_be32(bitmap); 988 hdr->nops++; 989 hdr->replen += decode_getattr_maxsz; 990} 991 992static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 993{ 994 __be32 *p; 995 996 p = reserve_space(xdr, 16); 997 *p++ = cpu_to_be32(OP_GETATTR); 998 *p++ = cpu_to_be32(2); 999 *p++ = cpu_to_be32(bm0); 1000 *p = cpu_to_be32(bm1); 1001 hdr->nops++; 1002 hdr->replen += decode_getattr_maxsz; 1003} 1004 1005static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1006{ 1007 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1008 bitmask[1] & nfs4_fattr_bitmap[1], hdr); 1009} 1010 1011static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1012{ 1013 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0], 1014 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr); 1015} 1016 1017static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1018{ 1019 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1020 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1021} 1022 1023static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1024{ 1025 __be32 *p; 1026 1027 p = reserve_space(xdr, 4); 1028 *p = cpu_to_be32(OP_GETFH); 1029 hdr->nops++; 1030 hdr->replen += decode_getfh_maxsz; 1031} 1032 1033static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1034{ 1035 __be32 *p; 1036 1037 p = reserve_space(xdr, 8 + name->len); 1038 *p++ = cpu_to_be32(OP_LINK); 1039 xdr_encode_opaque(p, name->name, name->len); 1040 hdr->nops++; 1041 hdr->replen += decode_link_maxsz; 1042} 1043 1044static inline int nfs4_lock_type(struct file_lock *fl, int block) 1045{ 1046 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) 1047 return block ? NFS4_READW_LT : NFS4_READ_LT; 1048 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1049} 1050 1051static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1052{ 1053 if (fl->fl_end == OFFSET_MAX) 1054 return ~(uint64_t)0; 1055 return fl->fl_end - fl->fl_start + 1; 1056} 1057 1058static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1059{ 1060 __be32 *p; 1061 1062 p = reserve_space(xdr, 28); 1063 p = xdr_encode_hyper(p, lowner->clientid); 1064 *p++ = cpu_to_be32(16); 1065 p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1066 xdr_encode_hyper(p, lowner->id); 1067} 1068 1069/* 1070 * opcode,type,reclaim,offset,length,new_lock_owner = 32 1071 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 1072 */ 1073static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 1074{ 1075 __be32 *p; 1076 1077 p = reserve_space(xdr, 32); 1078 *p++ = cpu_to_be32(OP_LOCK); 1079 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1080 *p++ = cpu_to_be32(args->reclaim); 1081 p = xdr_encode_hyper(p, args->fl->fl_start); 1082 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1083 *p = cpu_to_be32(args->new_lock_owner); 1084 if (args->new_lock_owner){ 1085 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1086 *p++ = cpu_to_be32(args->open_seqid->sequence->counter); 1087 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE); 1088 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter); 1089 encode_lockowner(xdr, &args->lock_owner); 1090 } 1091 else { 1092 p = reserve_space(xdr, NFS4_STATEID_SIZE+4); 1093 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE); 1094 *p = cpu_to_be32(args->lock_seqid->sequence->counter); 1095 } 1096 hdr->nops++; 1097 hdr->replen += decode_lock_maxsz; 1098} 1099 1100static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 1101{ 1102 __be32 *p; 1103 1104 p = reserve_space(xdr, 24); 1105 *p++ = cpu_to_be32(OP_LOCKT); 1106 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1107 p = xdr_encode_hyper(p, args->fl->fl_start); 1108 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1109 encode_lockowner(xdr, &args->lock_owner); 1110 hdr->nops++; 1111 hdr->replen += decode_lockt_maxsz; 1112} 1113 1114static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 1115{ 1116 __be32 *p; 1117 1118 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16); 1119 *p++ = cpu_to_be32(OP_LOCKU); 1120 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1121 *p++ = cpu_to_be32(args->seqid->sequence->counter); 1122 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE); 1123 p = xdr_encode_hyper(p, args->fl->fl_start); 1124 xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1125 hdr->nops++; 1126 hdr->replen += decode_locku_maxsz; 1127} 1128 1129static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1130{ 1131 __be32 *p; 1132 1133 p = reserve_space(xdr, 4); 1134 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER); 1135 encode_lockowner(xdr, lowner); 1136 hdr->nops++; 1137 hdr->replen += decode_release_lockowner_maxsz; 1138} 1139 1140static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1141{ 1142 int len = name->len; 1143 __be32 *p; 1144 1145 p = reserve_space(xdr, 8 + len); 1146 *p++ = cpu_to_be32(OP_LOOKUP); 1147 xdr_encode_opaque(p, name->name, len); 1148 hdr->nops++; 1149 hdr->replen += decode_lookup_maxsz; 1150} 1151 1152static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 1153{ 1154 __be32 *p; 1155 1156 p = reserve_space(xdr, 8); 1157 switch (fmode & (FMODE_READ|FMODE_WRITE)) { 1158 case FMODE_READ: 1159 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 1160 break; 1161 case FMODE_WRITE: 1162 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 1163 break; 1164 case FMODE_READ|FMODE_WRITE: 1165 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 1166 break; 1167 default: 1168 *p++ = cpu_to_be32(0); 1169 } 1170 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 1171} 1172 1173static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 1174{ 1175 __be32 *p; 1176 /* 1177 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 1178 * owner 4 = 32 1179 */ 1180 p = reserve_space(xdr, 8); 1181 *p++ = cpu_to_be32(OP_OPEN); 1182 *p = cpu_to_be32(arg->seqid->sequence->counter); 1183 encode_share_access(xdr, arg->fmode); 1184 p = reserve_space(xdr, 28); 1185 p = xdr_encode_hyper(p, arg->clientid); 1186 *p++ = cpu_to_be32(16); 1187 p = xdr_encode_opaque_fixed(p, "open id:", 8); 1188 xdr_encode_hyper(p, arg->id); 1189} 1190 1191static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 1192{ 1193 __be32 *p; 1194 struct nfs_client *clp; 1195 1196 p = reserve_space(xdr, 4); 1197 switch(arg->open_flags & O_EXCL) { 1198 case 0: 1199 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 1200 encode_attrs(xdr, arg->u.attrs, arg->server); 1201 break; 1202 default: 1203 clp = arg->server->nfs_client; 1204 if (clp->cl_mvops->minor_version > 0) { 1205 if (nfs4_has_persistent_session(clp)) { 1206 *p = cpu_to_be32(NFS4_CREATE_GUARDED); 1207 encode_attrs(xdr, arg->u.attrs, arg->server); 1208 } else { 1209 struct iattr dummy; 1210 1211 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 1212 encode_nfs4_verifier(xdr, &arg->u.verifier); 1213 dummy.ia_valid = 0; 1214 encode_attrs(xdr, &dummy, arg->server); 1215 } 1216 } else { 1217 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1218 encode_nfs4_verifier(xdr, &arg->u.verifier); 1219 } 1220 } 1221} 1222 1223static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 1224{ 1225 __be32 *p; 1226 1227 p = reserve_space(xdr, 4); 1228 switch (arg->open_flags & O_CREAT) { 1229 case 0: 1230 *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 1231 break; 1232 default: 1233 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 1234 *p = cpu_to_be32(NFS4_OPEN_CREATE); 1235 encode_createmode(xdr, arg); 1236 } 1237} 1238 1239static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 1240{ 1241 __be32 *p; 1242 1243 p = reserve_space(xdr, 4); 1244 switch (delegation_type) { 1245 case 0: 1246 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 1247 break; 1248 case FMODE_READ: 1249 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 1250 break; 1251 case FMODE_WRITE|FMODE_READ: 1252 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 1253 break; 1254 default: 1255 BUG(); 1256 } 1257} 1258 1259static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 1260{ 1261 __be32 *p; 1262 1263 p = reserve_space(xdr, 4); 1264 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 1265 encode_string(xdr, name->len, name->name); 1266} 1267 1268static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 1269{ 1270 __be32 *p; 1271 1272 p = reserve_space(xdr, 4); 1273 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 1274 encode_delegation_type(xdr, type); 1275} 1276 1277static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 1278{ 1279 __be32 *p; 1280 1281 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1282 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1283 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); 1284 encode_string(xdr, name->len, name->name); 1285} 1286 1287static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 1288{ 1289 encode_openhdr(xdr, arg); 1290 encode_opentype(xdr, arg); 1291 switch (arg->claim) { 1292 case NFS4_OPEN_CLAIM_NULL: 1293 encode_claim_null(xdr, arg->name); 1294 break; 1295 case NFS4_OPEN_CLAIM_PREVIOUS: 1296 encode_claim_previous(xdr, arg->u.delegation_type); 1297 break; 1298 case NFS4_OPEN_CLAIM_DELEGATE_CUR: 1299 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 1300 break; 1301 default: 1302 BUG(); 1303 } 1304 hdr->nops++; 1305 hdr->replen += decode_open_maxsz; 1306} 1307 1308static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 1309{ 1310 __be32 *p; 1311 1312 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1313 *p++ = cpu_to_be32(OP_OPEN_CONFIRM); 1314 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); 1315 *p = cpu_to_be32(arg->seqid->sequence->counter); 1316 hdr->nops++; 1317 hdr->replen += decode_open_confirm_maxsz; 1318} 1319 1320static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 1321{ 1322 __be32 *p; 1323 1324 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1325 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE); 1326 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE); 1327 *p = cpu_to_be32(arg->seqid->sequence->counter); 1328 encode_share_access(xdr, arg->fmode); 1329 hdr->nops++; 1330 hdr->replen += decode_open_downgrade_maxsz; 1331} 1332 1333static void 1334encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 1335{ 1336 int len = fh->size; 1337 __be32 *p; 1338 1339 p = reserve_space(xdr, 8 + len); 1340 *p++ = cpu_to_be32(OP_PUTFH); 1341 xdr_encode_opaque(p, fh->data, len); 1342 hdr->nops++; 1343 hdr->replen += decode_putfh_maxsz; 1344} 1345 1346static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1347{ 1348 __be32 *p; 1349 1350 p = reserve_space(xdr, 4); 1351 *p = cpu_to_be32(OP_PUTROOTFH); 1352 hdr->nops++; 1353 hdr->replen += decode_putrootfh_maxsz; 1354} 1355 1356static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx) 1357{ 1358 nfs4_stateid stateid; 1359 __be32 *p; 1360 1361 p = reserve_space(xdr, NFS4_STATEID_SIZE); 1362 if (ctx->state != NULL) { 1363 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid); 1364 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE); 1365 } else 1366 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); 1367} 1368 1369static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 1370{ 1371 __be32 *p; 1372 1373 p = reserve_space(xdr, 4); 1374 *p = cpu_to_be32(OP_READ); 1375 1376 encode_stateid(xdr, args->context, args->lock_context); 1377 1378 p = reserve_space(xdr, 12); 1379 p = xdr_encode_hyper(p, args->offset); 1380 *p = cpu_to_be32(args->count); 1381 hdr->nops++; 1382 hdr->replen += decode_read_maxsz; 1383} 1384 1385static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 1386{ 1387 uint32_t attrs[2] = { 1388 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID, 1389 FATTR4_WORD1_MOUNTED_ON_FILEID, 1390 }; 1391 __be32 *p; 1392 1393 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20); 1394 *p++ = cpu_to_be32(OP_READDIR); 1395 p = xdr_encode_hyper(p, readdir->cookie); 1396 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE); 1397 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */ 1398 *p++ = cpu_to_be32(readdir->count); 1399 *p++ = cpu_to_be32(2); 1400 /* Switch to mounted_on_fileid if the server supports it */ 1401 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) 1402 attrs[0] &= ~FATTR4_WORD0_FILEID; 1403 else 1404 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 1405 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 1406 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1407 hdr->nops++; 1408 hdr->replen += decode_readdir_maxsz; 1409 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 1410 __func__, 1411 (unsigned long long)readdir->cookie, 1412 ((u32 *)readdir->verifier.data)[0], 1413 ((u32 *)readdir->verifier.data)[1], 1414 attrs[0] & readdir->bitmask[0], 1415 attrs[1] & readdir->bitmask[1]); 1416} 1417 1418static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 1419{ 1420 __be32 *p; 1421 1422 p = reserve_space(xdr, 4); 1423 *p = cpu_to_be32(OP_READLINK); 1424 hdr->nops++; 1425 hdr->replen += decode_readlink_maxsz; 1426} 1427 1428static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1429{ 1430 __be32 *p; 1431 1432 p = reserve_space(xdr, 8 + name->len); 1433 *p++ = cpu_to_be32(OP_REMOVE); 1434 xdr_encode_opaque(p, name->name, name->len); 1435 hdr->nops++; 1436 hdr->replen += decode_remove_maxsz; 1437} 1438 1439static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 1440{ 1441 __be32 *p; 1442 1443 p = reserve_space(xdr, 4); 1444 *p = cpu_to_be32(OP_RENAME); 1445 encode_string(xdr, oldname->len, oldname->name); 1446 encode_string(xdr, newname->len, newname->name); 1447 hdr->nops++; 1448 hdr->replen += decode_rename_maxsz; 1449} 1450 1451static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr) 1452{ 1453 __be32 *p; 1454 1455 p = reserve_space(xdr, 12); 1456 *p++ = cpu_to_be32(OP_RENEW); 1457 xdr_encode_hyper(p, client_stateid->cl_clientid); 1458 hdr->nops++; 1459 hdr->replen += decode_renew_maxsz; 1460} 1461 1462static void 1463encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1464{ 1465 __be32 *p; 1466 1467 p = reserve_space(xdr, 4); 1468 *p = cpu_to_be32(OP_RESTOREFH); 1469 hdr->nops++; 1470 hdr->replen += decode_restorefh_maxsz; 1471} 1472 1473static int 1474encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 1475{ 1476 __be32 *p; 1477 1478 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1479 *p++ = cpu_to_be32(OP_SETATTR); 1480 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); 1481 p = reserve_space(xdr, 2*4); 1482 *p++ = cpu_to_be32(1); 1483 *p = cpu_to_be32(FATTR4_WORD0_ACL); 1484 if (arg->acl_len % 4) 1485 return -EINVAL; 1486 p = reserve_space(xdr, 4); 1487 *p = cpu_to_be32(arg->acl_len); 1488 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 1489 hdr->nops++; 1490 hdr->replen += decode_setacl_maxsz; 1491 return 0; 1492} 1493 1494static void 1495encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1496{ 1497 __be32 *p; 1498 1499 p = reserve_space(xdr, 4); 1500 *p = cpu_to_be32(OP_SAVEFH); 1501 hdr->nops++; 1502 hdr->replen += decode_savefh_maxsz; 1503} 1504 1505static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 1506{ 1507 __be32 *p; 1508 1509 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1510 *p++ = cpu_to_be32(OP_SETATTR); 1511 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE); 1512 hdr->nops++; 1513 hdr->replen += decode_setattr_maxsz; 1514 encode_attrs(xdr, arg->iap, server); 1515} 1516 1517static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 1518{ 1519 __be32 *p; 1520 1521 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE); 1522 *p++ = cpu_to_be32(OP_SETCLIENTID); 1523 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE); 1524 1525 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 1526 p = reserve_space(xdr, 4); 1527 *p = cpu_to_be32(setclientid->sc_prog); 1528 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 1529 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 1530 p = reserve_space(xdr, 4); 1531 *p = cpu_to_be32(setclientid->sc_cb_ident); 1532 hdr->nops++; 1533 hdr->replen += decode_setclientid_maxsz; 1534} 1535 1536static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 1537{ 1538 __be32 *p; 1539 1540 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE); 1541 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM); 1542 p = xdr_encode_hyper(p, arg->clientid); 1543 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE); 1544 hdr->nops++; 1545 hdr->replen += decode_setclientid_confirm_maxsz; 1546} 1547 1548static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 1549{ 1550 __be32 *p; 1551 1552 p = reserve_space(xdr, 4); 1553 *p = cpu_to_be32(OP_WRITE); 1554 1555 encode_stateid(xdr, args->context, args->lock_context); 1556 1557 p = reserve_space(xdr, 16); 1558 p = xdr_encode_hyper(p, args->offset); 1559 *p++ = cpu_to_be32(args->stable); 1560 *p = cpu_to_be32(args->count); 1561 1562 xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 1563 hdr->nops++; 1564 hdr->replen += decode_write_maxsz; 1565} 1566 1567static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 1568{ 1569 __be32 *p; 1570 1571 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1572 1573 *p++ = cpu_to_be32(OP_DELEGRETURN); 1574 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); 1575 hdr->nops++; 1576 hdr->replen += decode_delegreturn_maxsz; 1577} 1578 1579#if defined(CONFIG_NFS_V4_1) 1580/* NFSv4.1 operations */ 1581static void encode_exchange_id(struct xdr_stream *xdr, 1582 struct nfs41_exchange_id_args *args, 1583 struct compound_hdr *hdr) 1584{ 1585 __be32 *p; 1586 1587 p = reserve_space(xdr, 4 + sizeof(args->verifier->data)); 1588 *p++ = cpu_to_be32(OP_EXCHANGE_ID); 1589 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data)); 1590 1591 encode_string(xdr, args->id_len, args->id); 1592 1593 p = reserve_space(xdr, 12); 1594 *p++ = cpu_to_be32(args->flags); 1595 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1596 *p = cpu_to_be32(0); /* zero length implementation id array */ 1597 hdr->nops++; 1598 hdr->replen += decode_exchange_id_maxsz; 1599} 1600 1601static void encode_create_session(struct xdr_stream *xdr, 1602 struct nfs41_create_session_args *args, 1603 struct compound_hdr *hdr) 1604{ 1605 __be32 *p; 1606 char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1607 uint32_t len; 1608 struct nfs_client *clp = args->client; 1609 u32 max_resp_sz_cached; 1610 1611 /* 1612 * Assumes OPEN is the biggest non-idempotent compound. 1613 * 2 is the verifier. 1614 */ 1615 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 1616 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1617 1618 len = scnprintf(machine_name, sizeof(machine_name), "%s", 1619 clp->cl_ipaddr); 1620 1621 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12); 1622 *p++ = cpu_to_be32(OP_CREATE_SESSION); 1623 p = xdr_encode_hyper(p, clp->cl_ex_clid); 1624 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1625 *p++ = cpu_to_be32(args->flags); /*flags */ 1626 1627 /* Fore Channel */ 1628 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */ 1629 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1630 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 1631 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1632 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1633 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1634 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1635 1636 /* Back Channel */ 1637 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */ 1638 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1639 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1640 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1641 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1642 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1643 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1644 1645 *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1646 *p++ = cpu_to_be32(1); 1647 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1648 1649 /* authsys_parms rfc1831 */ 1650 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ 1651 p = xdr_encode_opaque(p, machine_name, len); 1652 *p++ = cpu_to_be32(0); /* UID */ 1653 *p++ = cpu_to_be32(0); /* GID */ 1654 *p = cpu_to_be32(0); /* No more gids */ 1655 hdr->nops++; 1656 hdr->replen += decode_create_session_maxsz; 1657} 1658 1659static void encode_destroy_session(struct xdr_stream *xdr, 1660 struct nfs4_session *session, 1661 struct compound_hdr *hdr) 1662{ 1663 __be32 *p; 1664 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN); 1665 *p++ = cpu_to_be32(OP_DESTROY_SESSION); 1666 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1667 hdr->nops++; 1668 hdr->replen += decode_destroy_session_maxsz; 1669} 1670 1671static void encode_reclaim_complete(struct xdr_stream *xdr, 1672 struct nfs41_reclaim_complete_args *args, 1673 struct compound_hdr *hdr) 1674{ 1675 __be32 *p; 1676 1677 p = reserve_space(xdr, 8); 1678 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE); 1679 *p++ = cpu_to_be32(args->one_fs); 1680 hdr->nops++; 1681 hdr->replen += decode_reclaim_complete_maxsz; 1682} 1683#endif /* CONFIG_NFS_V4_1 */ 1684 1685static void encode_sequence(struct xdr_stream *xdr, 1686 const struct nfs4_sequence_args *args, 1687 struct compound_hdr *hdr) 1688{ 1689#if defined(CONFIG_NFS_V4_1) 1690 struct nfs4_session *session = args->sa_session; 1691 struct nfs4_slot_table *tp; 1692 struct nfs4_slot *slot; 1693 __be32 *p; 1694 1695 if (!session) 1696 return; 1697 1698 tp = &session->fc_slot_table; 1699 1700 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1701 slot = tp->slots + args->sa_slotid; 1702 1703 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16); 1704 *p++ = cpu_to_be32(OP_SEQUENCE); 1705 1706 /* 1707 * Sessionid + seqid + slotid + max slotid + cache_this 1708 */ 1709 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1710 "max_slotid=%d cache_this=%d\n", 1711 __func__, 1712 ((u32 *)session->sess_id.data)[0], 1713 ((u32 *)session->sess_id.data)[1], 1714 ((u32 *)session->sess_id.data)[2], 1715 ((u32 *)session->sess_id.data)[3], 1716 slot->seq_nr, args->sa_slotid, 1717 tp->highest_used_slotid, args->sa_cache_this); 1718 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1719 *p++ = cpu_to_be32(slot->seq_nr); 1720 *p++ = cpu_to_be32(args->sa_slotid); 1721 *p++ = cpu_to_be32(tp->highest_used_slotid); 1722 *p = cpu_to_be32(args->sa_cache_this); 1723 hdr->nops++; 1724 hdr->replen += decode_sequence_maxsz; 1725#endif /* CONFIG_NFS_V4_1 */ 1726} 1727 1728/* 1729 * END OF "GENERIC" ENCODE ROUTINES. 1730 */ 1731 1732static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 1733{ 1734#if defined(CONFIG_NFS_V4_1) 1735 if (args->sa_session) 1736 return args->sa_session->clp->cl_mvops->minor_version; 1737#endif /* CONFIG_NFS_V4_1 */ 1738 return 0; 1739} 1740 1741/* 1742 * Encode an ACCESS request 1743 */ 1744static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args) 1745{ 1746 struct xdr_stream xdr; 1747 struct compound_hdr hdr = { 1748 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1749 }; 1750 1751 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1752 encode_compound_hdr(&xdr, req, &hdr); 1753 encode_sequence(&xdr, &args->seq_args, &hdr); 1754 encode_putfh(&xdr, args->fh, &hdr); 1755 encode_access(&xdr, args->access, &hdr); 1756 encode_getfattr(&xdr, args->bitmask, &hdr); 1757 encode_nops(&hdr); 1758 return 0; 1759} 1760 1761/* 1762 * Encode LOOKUP request 1763 */ 1764static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args) 1765{ 1766 struct xdr_stream xdr; 1767 struct compound_hdr hdr = { 1768 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1769 }; 1770 1771 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1772 encode_compound_hdr(&xdr, req, &hdr); 1773 encode_sequence(&xdr, &args->seq_args, &hdr); 1774 encode_putfh(&xdr, args->dir_fh, &hdr); 1775 encode_lookup(&xdr, args->name, &hdr); 1776 encode_getfh(&xdr, &hdr); 1777 encode_getfattr(&xdr, args->bitmask, &hdr); 1778 encode_nops(&hdr); 1779 return 0; 1780} 1781 1782/* 1783 * Encode LOOKUP_ROOT request 1784 */ 1785static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args) 1786{ 1787 struct xdr_stream xdr; 1788 struct compound_hdr hdr = { 1789 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1790 }; 1791 1792 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1793 encode_compound_hdr(&xdr, req, &hdr); 1794 encode_sequence(&xdr, &args->seq_args, &hdr); 1795 encode_putrootfh(&xdr, &hdr); 1796 encode_getfh(&xdr, &hdr); 1797 encode_getfattr(&xdr, args->bitmask, &hdr); 1798 encode_nops(&hdr); 1799 return 0; 1800} 1801 1802/* 1803 * Encode REMOVE request 1804 */ 1805static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) 1806{ 1807 struct xdr_stream xdr; 1808 struct compound_hdr hdr = { 1809 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1810 }; 1811 1812 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1813 encode_compound_hdr(&xdr, req, &hdr); 1814 encode_sequence(&xdr, &args->seq_args, &hdr); 1815 encode_putfh(&xdr, args->fh, &hdr); 1816 encode_remove(&xdr, &args->name, &hdr); 1817 encode_getfattr(&xdr, args->bitmask, &hdr); 1818 encode_nops(&hdr); 1819 return 0; 1820} 1821 1822/* 1823 * Encode RENAME request 1824 */ 1825static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args) 1826{ 1827 struct xdr_stream xdr; 1828 struct compound_hdr hdr = { 1829 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1830 }; 1831 1832 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1833 encode_compound_hdr(&xdr, req, &hdr); 1834 encode_sequence(&xdr, &args->seq_args, &hdr); 1835 encode_putfh(&xdr, args->old_dir, &hdr); 1836 encode_savefh(&xdr, &hdr); 1837 encode_putfh(&xdr, args->new_dir, &hdr); 1838 encode_rename(&xdr, args->old_name, args->new_name, &hdr); 1839 encode_getfattr(&xdr, args->bitmask, &hdr); 1840 encode_restorefh(&xdr, &hdr); 1841 encode_getfattr(&xdr, args->bitmask, &hdr); 1842 encode_nops(&hdr); 1843 return 0; 1844} 1845 1846/* 1847 * Encode LINK request 1848 */ 1849static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args) 1850{ 1851 struct xdr_stream xdr; 1852 struct compound_hdr hdr = { 1853 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1854 }; 1855 1856 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1857 encode_compound_hdr(&xdr, req, &hdr); 1858 encode_sequence(&xdr, &args->seq_args, &hdr); 1859 encode_putfh(&xdr, args->fh, &hdr); 1860 encode_savefh(&xdr, &hdr); 1861 encode_putfh(&xdr, args->dir_fh, &hdr); 1862 encode_link(&xdr, args->name, &hdr); 1863 encode_getfattr(&xdr, args->bitmask, &hdr); 1864 encode_restorefh(&xdr, &hdr); 1865 encode_getfattr(&xdr, args->bitmask, &hdr); 1866 encode_nops(&hdr); 1867 return 0; 1868} 1869 1870/* 1871 * Encode CREATE request 1872 */ 1873static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) 1874{ 1875 struct xdr_stream xdr; 1876 struct compound_hdr hdr = { 1877 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1878 }; 1879 1880 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1881 encode_compound_hdr(&xdr, req, &hdr); 1882 encode_sequence(&xdr, &args->seq_args, &hdr); 1883 encode_putfh(&xdr, args->dir_fh, &hdr); 1884 encode_savefh(&xdr, &hdr); 1885 encode_create(&xdr, args, &hdr); 1886 encode_getfh(&xdr, &hdr); 1887 encode_getfattr(&xdr, args->bitmask, &hdr); 1888 encode_restorefh(&xdr, &hdr); 1889 encode_getfattr(&xdr, args->bitmask, &hdr); 1890 encode_nops(&hdr); 1891 return 0; 1892} 1893 1894/* 1895 * Encode SYMLINK request 1896 */ 1897static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) 1898{ 1899 return nfs4_xdr_enc_create(req, p, args); 1900} 1901 1902/* 1903 * Encode GETATTR request 1904 */ 1905static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args) 1906{ 1907 struct xdr_stream xdr; 1908 struct compound_hdr hdr = { 1909 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1910 }; 1911 1912 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1913 encode_compound_hdr(&xdr, req, &hdr); 1914 encode_sequence(&xdr, &args->seq_args, &hdr); 1915 encode_putfh(&xdr, args->fh, &hdr); 1916 encode_getfattr(&xdr, args->bitmask, &hdr); 1917 encode_nops(&hdr); 1918 return 0; 1919} 1920 1921/* 1922 * Encode a CLOSE request 1923 */ 1924static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) 1925{ 1926 struct xdr_stream xdr; 1927 struct compound_hdr hdr = { 1928 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1929 }; 1930 1931 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1932 encode_compound_hdr(&xdr, req, &hdr); 1933 encode_sequence(&xdr, &args->seq_args, &hdr); 1934 encode_putfh(&xdr, args->fh, &hdr); 1935 encode_close(&xdr, args, &hdr); 1936 encode_getfattr(&xdr, args->bitmask, &hdr); 1937 encode_nops(&hdr); 1938 return 0; 1939} 1940 1941/* 1942 * Encode an OPEN request 1943 */ 1944static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) 1945{ 1946 struct xdr_stream xdr; 1947 struct compound_hdr hdr = { 1948 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1949 }; 1950 1951 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1952 encode_compound_hdr(&xdr, req, &hdr); 1953 encode_sequence(&xdr, &args->seq_args, &hdr); 1954 encode_putfh(&xdr, args->fh, &hdr); 1955 encode_savefh(&xdr, &hdr); 1956 encode_open(&xdr, args, &hdr); 1957 encode_getfh(&xdr, &hdr); 1958 encode_getfattr(&xdr, args->bitmask, &hdr); 1959 encode_restorefh(&xdr, &hdr); 1960 encode_getfattr(&xdr, args->bitmask, &hdr); 1961 encode_nops(&hdr); 1962 return 0; 1963} 1964 1965/* 1966 * Encode an OPEN_CONFIRM request 1967 */ 1968static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args) 1969{ 1970 struct xdr_stream xdr; 1971 struct compound_hdr hdr = { 1972 .nops = 0, 1973 }; 1974 1975 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1976 encode_compound_hdr(&xdr, req, &hdr); 1977 encode_putfh(&xdr, args->fh, &hdr); 1978 encode_open_confirm(&xdr, args, &hdr); 1979 encode_nops(&hdr); 1980 return 0; 1981} 1982 1983/* 1984 * Encode an OPEN request with no attributes. 1985 */ 1986static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) 1987{ 1988 struct xdr_stream xdr; 1989 struct compound_hdr hdr = { 1990 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 1991 }; 1992 1993 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1994 encode_compound_hdr(&xdr, req, &hdr); 1995 encode_sequence(&xdr, &args->seq_args, &hdr); 1996 encode_putfh(&xdr, args->fh, &hdr); 1997 encode_open(&xdr, args, &hdr); 1998 encode_getfattr(&xdr, args->bitmask, &hdr); 1999 encode_nops(&hdr); 2000 return 0; 2001} 2002 2003/* 2004 * Encode an OPEN_DOWNGRADE request 2005 */ 2006static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) 2007{ 2008 struct xdr_stream xdr; 2009 struct compound_hdr hdr = { 2010 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2011 }; 2012 2013 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2014 encode_compound_hdr(&xdr, req, &hdr); 2015 encode_sequence(&xdr, &args->seq_args, &hdr); 2016 encode_putfh(&xdr, args->fh, &hdr); 2017 encode_open_downgrade(&xdr, args, &hdr); 2018 encode_getfattr(&xdr, args->bitmask, &hdr); 2019 encode_nops(&hdr); 2020 return 0; 2021} 2022 2023/* 2024 * Encode a LOCK request 2025 */ 2026static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args) 2027{ 2028 struct xdr_stream xdr; 2029 struct compound_hdr hdr = { 2030 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2031 }; 2032 2033 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2034 encode_compound_hdr(&xdr, req, &hdr); 2035 encode_sequence(&xdr, &args->seq_args, &hdr); 2036 encode_putfh(&xdr, args->fh, &hdr); 2037 encode_lock(&xdr, args, &hdr); 2038 encode_nops(&hdr); 2039 return 0; 2040} 2041 2042/* 2043 * Encode a LOCKT request 2044 */ 2045static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args) 2046{ 2047 struct xdr_stream xdr; 2048 struct compound_hdr hdr = { 2049 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2050 }; 2051 2052 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2053 encode_compound_hdr(&xdr, req, &hdr); 2054 encode_sequence(&xdr, &args->seq_args, &hdr); 2055 encode_putfh(&xdr, args->fh, &hdr); 2056 encode_lockt(&xdr, args, &hdr); 2057 encode_nops(&hdr); 2058 return 0; 2059} 2060 2061/* 2062 * Encode a LOCKU request 2063 */ 2064static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args) 2065{ 2066 struct xdr_stream xdr; 2067 struct compound_hdr hdr = { 2068 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2069 }; 2070 2071 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2072 encode_compound_hdr(&xdr, req, &hdr); 2073 encode_sequence(&xdr, &args->seq_args, &hdr); 2074 encode_putfh(&xdr, args->fh, &hdr); 2075 encode_locku(&xdr, args, &hdr); 2076 encode_nops(&hdr); 2077 return 0; 2078} 2079 2080static int nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, __be32 *p, struct nfs_release_lockowner_args *args) 2081{ 2082 struct xdr_stream xdr; 2083 struct compound_hdr hdr = { 2084 .minorversion = 0, 2085 }; 2086 2087 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2088 encode_compound_hdr(&xdr, req, &hdr); 2089 encode_release_lockowner(&xdr, &args->lock_owner, &hdr); 2090 encode_nops(&hdr); 2091 return 0; 2092} 2093 2094/* 2095 * Encode a READLINK request 2096 */ 2097static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args) 2098{ 2099 struct xdr_stream xdr; 2100 struct compound_hdr hdr = { 2101 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2102 }; 2103 2104 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2105 encode_compound_hdr(&xdr, req, &hdr); 2106 encode_sequence(&xdr, &args->seq_args, &hdr); 2107 encode_putfh(&xdr, args->fh, &hdr); 2108 encode_readlink(&xdr, args, req, &hdr); 2109 2110 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2111 args->pgbase, args->pglen); 2112 encode_nops(&hdr); 2113 return 0; 2114} 2115 2116/* 2117 * Encode a READDIR request 2118 */ 2119static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args) 2120{ 2121 struct xdr_stream xdr; 2122 struct compound_hdr hdr = { 2123 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2124 }; 2125 2126 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2127 encode_compound_hdr(&xdr, req, &hdr); 2128 encode_sequence(&xdr, &args->seq_args, &hdr); 2129 encode_putfh(&xdr, args->fh, &hdr); 2130 encode_readdir(&xdr, args, req, &hdr); 2131 2132 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2133 args->pgbase, args->count); 2134 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 2135 __func__, hdr.replen << 2, args->pages, 2136 args->pgbase, args->count); 2137 encode_nops(&hdr); 2138 return 0; 2139} 2140 2141/* 2142 * Encode a READ request 2143 */ 2144static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) 2145{ 2146 struct xdr_stream xdr; 2147 struct compound_hdr hdr = { 2148 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2149 }; 2150 2151 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2152 encode_compound_hdr(&xdr, req, &hdr); 2153 encode_sequence(&xdr, &args->seq_args, &hdr); 2154 encode_putfh(&xdr, args->fh, &hdr); 2155 encode_read(&xdr, args, &hdr); 2156 2157 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 2158 args->pages, args->pgbase, args->count); 2159 req->rq_rcv_buf.flags |= XDRBUF_READ; 2160 encode_nops(&hdr); 2161 return 0; 2162} 2163 2164/* 2165 * Encode an SETATTR request 2166 */ 2167static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args) 2168{ 2169 struct xdr_stream xdr; 2170 struct compound_hdr hdr = { 2171 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2172 }; 2173 2174 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2175 encode_compound_hdr(&xdr, req, &hdr); 2176 encode_sequence(&xdr, &args->seq_args, &hdr); 2177 encode_putfh(&xdr, args->fh, &hdr); 2178 encode_setattr(&xdr, args, args->server, &hdr); 2179 encode_getfattr(&xdr, args->bitmask, &hdr); 2180 encode_nops(&hdr); 2181 return 0; 2182} 2183 2184/* 2185 * Encode a GETACL request 2186 */ 2187static int 2188nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p, 2189 struct nfs_getaclargs *args) 2190{ 2191 struct xdr_stream xdr; 2192 struct compound_hdr hdr = { 2193 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2194 }; 2195 uint32_t replen; 2196 2197 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2198 encode_compound_hdr(&xdr, req, &hdr); 2199 encode_sequence(&xdr, &args->seq_args, &hdr); 2200 encode_putfh(&xdr, args->fh, &hdr); 2201 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1; 2202 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr); 2203 2204 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2205 args->acl_pages, args->acl_pgbase, args->acl_len); 2206 encode_nops(&hdr); 2207 return 0; 2208} 2209 2210/* 2211 * Encode a WRITE request 2212 */ 2213static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 2214{ 2215 struct xdr_stream xdr; 2216 struct compound_hdr hdr = { 2217 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2218 }; 2219 2220 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2221 encode_compound_hdr(&xdr, req, &hdr); 2222 encode_sequence(&xdr, &args->seq_args, &hdr); 2223 encode_putfh(&xdr, args->fh, &hdr); 2224 encode_write(&xdr, args, &hdr); 2225 req->rq_snd_buf.flags |= XDRBUF_WRITE; 2226 encode_getfattr(&xdr, args->bitmask, &hdr); 2227 encode_nops(&hdr); 2228 return 0; 2229} 2230 2231/* 2232 * a COMMIT request 2233 */ 2234static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) 2235{ 2236 struct xdr_stream xdr; 2237 struct compound_hdr hdr = { 2238 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2239 }; 2240 2241 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2242 encode_compound_hdr(&xdr, req, &hdr); 2243 encode_sequence(&xdr, &args->seq_args, &hdr); 2244 encode_putfh(&xdr, args->fh, &hdr); 2245 encode_commit(&xdr, args, &hdr); 2246 encode_getfattr(&xdr, args->bitmask, &hdr); 2247 encode_nops(&hdr); 2248 return 0; 2249} 2250 2251/* 2252 * FSINFO request 2253 */ 2254static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args) 2255{ 2256 struct xdr_stream xdr; 2257 struct compound_hdr hdr = { 2258 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2259 }; 2260 2261 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2262 encode_compound_hdr(&xdr, req, &hdr); 2263 encode_sequence(&xdr, &args->seq_args, &hdr); 2264 encode_putfh(&xdr, args->fh, &hdr); 2265 encode_fsinfo(&xdr, args->bitmask, &hdr); 2266 encode_nops(&hdr); 2267 return 0; 2268} 2269 2270/* 2271 * a PATHCONF request 2272 */ 2273static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args) 2274{ 2275 struct xdr_stream xdr; 2276 struct compound_hdr hdr = { 2277 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2278 }; 2279 2280 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2281 encode_compound_hdr(&xdr, req, &hdr); 2282 encode_sequence(&xdr, &args->seq_args, &hdr); 2283 encode_putfh(&xdr, args->fh, &hdr); 2284 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2285 &hdr); 2286 encode_nops(&hdr); 2287 return 0; 2288} 2289 2290/* 2291 * a STATFS request 2292 */ 2293static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args) 2294{ 2295 struct xdr_stream xdr; 2296 struct compound_hdr hdr = { 2297 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2298 }; 2299 2300 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2301 encode_compound_hdr(&xdr, req, &hdr); 2302 encode_sequence(&xdr, &args->seq_args, &hdr); 2303 encode_putfh(&xdr, args->fh, &hdr); 2304 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2305 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2306 encode_nops(&hdr); 2307 return 0; 2308} 2309 2310/* 2311 * GETATTR_BITMAP request 2312 */ 2313static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, 2314 struct nfs4_server_caps_arg *args) 2315{ 2316 struct xdr_stream xdr; 2317 struct compound_hdr hdr = { 2318 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2319 }; 2320 2321 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2322 encode_compound_hdr(&xdr, req, &hdr); 2323 encode_sequence(&xdr, &args->seq_args, &hdr); 2324 encode_putfh(&xdr, args->fhandle, &hdr); 2325 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2326 FATTR4_WORD0_LINK_SUPPORT| 2327 FATTR4_WORD0_SYMLINK_SUPPORT| 2328 FATTR4_WORD0_ACLSUPPORT, &hdr); 2329 encode_nops(&hdr); 2330 return 0; 2331} 2332 2333/* 2334 * a RENEW request 2335 */ 2336static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) 2337{ 2338 struct xdr_stream xdr; 2339 struct compound_hdr hdr = { 2340 .nops = 0, 2341 }; 2342 2343 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2344 encode_compound_hdr(&xdr, req, &hdr); 2345 encode_renew(&xdr, clp, &hdr); 2346 encode_nops(&hdr); 2347 return 0; 2348} 2349 2350/* 2351 * a SETCLIENTID request 2352 */ 2353static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc) 2354{ 2355 struct xdr_stream xdr; 2356 struct compound_hdr hdr = { 2357 .nops = 0, 2358 }; 2359 2360 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2361 encode_compound_hdr(&xdr, req, &hdr); 2362 encode_setclientid(&xdr, sc, &hdr); 2363 encode_nops(&hdr); 2364 return 0; 2365} 2366 2367/* 2368 * a SETCLIENTID_CONFIRM request 2369 */ 2370static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg) 2371{ 2372 struct xdr_stream xdr; 2373 struct compound_hdr hdr = { 2374 .nops = 0, 2375 }; 2376 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; 2377 2378 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2379 encode_compound_hdr(&xdr, req, &hdr); 2380 encode_setclientid_confirm(&xdr, arg, &hdr); 2381 encode_putrootfh(&xdr, &hdr); 2382 encode_fsinfo(&xdr, lease_bitmap, &hdr); 2383 encode_nops(&hdr); 2384 return 0; 2385} 2386 2387/* 2388 * DELEGRETURN request 2389 */ 2390static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args) 2391{ 2392 struct xdr_stream xdr; 2393 struct compound_hdr hdr = { 2394 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2395 }; 2396 2397 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2398 encode_compound_hdr(&xdr, req, &hdr); 2399 encode_sequence(&xdr, &args->seq_args, &hdr); 2400 encode_putfh(&xdr, args->fhandle, &hdr); 2401 encode_delegreturn(&xdr, args->stateid, &hdr); 2402 encode_getfattr(&xdr, args->bitmask, &hdr); 2403 encode_nops(&hdr); 2404 return 0; 2405} 2406 2407/* 2408 * Encode FS_LOCATIONS request 2409 */ 2410static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args) 2411{ 2412 struct xdr_stream xdr; 2413 struct compound_hdr hdr = { 2414 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2415 }; 2416 uint32_t replen; 2417 2418 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2419 encode_compound_hdr(&xdr, req, &hdr); 2420 encode_sequence(&xdr, &args->seq_args, &hdr); 2421 encode_putfh(&xdr, args->dir_fh, &hdr); 2422 encode_lookup(&xdr, args->name, &hdr); 2423 replen = hdr.replen; /* get the attribute into args->page */ 2424 encode_fs_locations(&xdr, args->bitmask, &hdr); 2425 2426 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2427 0, PAGE_SIZE); 2428 encode_nops(&hdr); 2429 return 0; 2430} 2431 2432#if defined(CONFIG_NFS_V4_1) 2433/* 2434 * EXCHANGE_ID request 2435 */ 2436static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p, 2437 struct nfs41_exchange_id_args *args) 2438{ 2439 struct xdr_stream xdr; 2440 struct compound_hdr hdr = { 2441 .minorversion = args->client->cl_mvops->minor_version, 2442 }; 2443 2444 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2445 encode_compound_hdr(&xdr, req, &hdr); 2446 encode_exchange_id(&xdr, args, &hdr); 2447 encode_nops(&hdr); 2448 return 0; 2449} 2450 2451/* 2452 * a CREATE_SESSION request 2453 */ 2454static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p, 2455 struct nfs41_create_session_args *args) 2456{ 2457 struct xdr_stream xdr; 2458 struct compound_hdr hdr = { 2459 .minorversion = args->client->cl_mvops->minor_version, 2460 }; 2461 2462 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2463 encode_compound_hdr(&xdr, req, &hdr); 2464 encode_create_session(&xdr, args, &hdr); 2465 encode_nops(&hdr); 2466 return 0; 2467} 2468 2469/* 2470 * a DESTROY_SESSION request 2471 */ 2472static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p, 2473 struct nfs4_session *session) 2474{ 2475 struct xdr_stream xdr; 2476 struct compound_hdr hdr = { 2477 .minorversion = session->clp->cl_mvops->minor_version, 2478 }; 2479 2480 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2481 encode_compound_hdr(&xdr, req, &hdr); 2482 encode_destroy_session(&xdr, session, &hdr); 2483 encode_nops(&hdr); 2484 return 0; 2485} 2486 2487/* 2488 * a SEQUENCE request 2489 */ 2490static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p, 2491 struct nfs4_sequence_args *args) 2492{ 2493 struct xdr_stream xdr; 2494 struct compound_hdr hdr = { 2495 .minorversion = nfs4_xdr_minorversion(args), 2496 }; 2497 2498 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2499 encode_compound_hdr(&xdr, req, &hdr); 2500 encode_sequence(&xdr, args, &hdr); 2501 encode_nops(&hdr); 2502 return 0; 2503} 2504 2505/* 2506 * a GET_LEASE_TIME request 2507 */ 2508static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p, 2509 struct nfs4_get_lease_time_args *args) 2510{ 2511 struct xdr_stream xdr; 2512 struct compound_hdr hdr = { 2513 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 2514 }; 2515 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; 2516 2517 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2518 encode_compound_hdr(&xdr, req, &hdr); 2519 encode_sequence(&xdr, &args->la_seq_args, &hdr); 2520 encode_putrootfh(&xdr, &hdr); 2521 encode_fsinfo(&xdr, lease_bitmap, &hdr); 2522 encode_nops(&hdr); 2523 return 0; 2524} 2525 2526/* 2527 * a RECLAIM_COMPLETE request 2528 */ 2529static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p, 2530 struct nfs41_reclaim_complete_args *args) 2531{ 2532 struct xdr_stream xdr; 2533 struct compound_hdr hdr = { 2534 .minorversion = nfs4_xdr_minorversion(&args->seq_args) 2535 }; 2536 2537 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 2538 encode_compound_hdr(&xdr, req, &hdr); 2539 encode_sequence(&xdr, &args->seq_args, &hdr); 2540 encode_reclaim_complete(&xdr, args, &hdr); 2541 encode_nops(&hdr); 2542 return 0; 2543} 2544 2545#endif /* CONFIG_NFS_V4_1 */ 2546 2547static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 2548{ 2549 dprintk("nfs: %s: prematurely hit end of receive buffer. " 2550 "Remaining buffer length is %tu words.\n", 2551 func, xdr->end - xdr->p); 2552} 2553 2554static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 2555{ 2556 __be32 *p; 2557 2558 p = xdr_inline_decode(xdr, 4); 2559 if (unlikely(!p)) 2560 goto out_overflow; 2561 *len = be32_to_cpup(p); 2562 p = xdr_inline_decode(xdr, *len); 2563 if (unlikely(!p)) 2564 goto out_overflow; 2565 *string = (char *)p; 2566 return 0; 2567out_overflow: 2568 print_overflow_msg(__func__, xdr); 2569 return -EIO; 2570} 2571 2572static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 2573{ 2574 __be32 *p; 2575 2576 p = xdr_inline_decode(xdr, 8); 2577 if (unlikely(!p)) 2578 goto out_overflow; 2579 hdr->status = be32_to_cpup(p++); 2580 hdr->taglen = be32_to_cpup(p); 2581 2582 p = xdr_inline_decode(xdr, hdr->taglen + 4); 2583 if (unlikely(!p)) 2584 goto out_overflow; 2585 hdr->tag = (char *)p; 2586 p += XDR_QUADLEN(hdr->taglen); 2587 hdr->nops = be32_to_cpup(p); 2588 if (unlikely(hdr->nops < 1)) 2589 return nfs4_stat_to_errno(hdr->status); 2590 return 0; 2591out_overflow: 2592 print_overflow_msg(__func__, xdr); 2593 return -EIO; 2594} 2595 2596static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 2597{ 2598 __be32 *p; 2599 uint32_t opnum; 2600 int32_t nfserr; 2601 2602 p = xdr_inline_decode(xdr, 8); 2603 if (unlikely(!p)) 2604 goto out_overflow; 2605 opnum = be32_to_cpup(p++); 2606 if (opnum != expected) { 2607 dprintk("nfs: Server returned operation" 2608 " %d but we issued a request for %d\n", 2609 opnum, expected); 2610 return -EIO; 2611 } 2612 nfserr = be32_to_cpup(p); 2613 if (nfserr != NFS_OK) 2614 return nfs4_stat_to_errno(nfserr); 2615 return 0; 2616out_overflow: 2617 print_overflow_msg(__func__, xdr); 2618 return -EIO; 2619} 2620 2621/* Dummy routine */ 2622static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 2623{ 2624 __be32 *p; 2625 unsigned int strlen; 2626 char *str; 2627 2628 p = xdr_inline_decode(xdr, 12); 2629 if (likely(p)) 2630 return decode_opaque_inline(xdr, &strlen, &str); 2631 print_overflow_msg(__func__, xdr); 2632 return -EIO; 2633} 2634 2635static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 2636{ 2637 uint32_t bmlen; 2638 __be32 *p; 2639 2640 p = xdr_inline_decode(xdr, 4); 2641 if (unlikely(!p)) 2642 goto out_overflow; 2643 bmlen = be32_to_cpup(p); 2644 2645 bitmap[0] = bitmap[1] = 0; 2646 p = xdr_inline_decode(xdr, (bmlen << 2)); 2647 if (unlikely(!p)) 2648 goto out_overflow; 2649 if (bmlen > 0) { 2650 bitmap[0] = be32_to_cpup(p++); 2651 if (bmlen > 1) 2652 bitmap[1] = be32_to_cpup(p); 2653 } 2654 return 0; 2655out_overflow: 2656 print_overflow_msg(__func__, xdr); 2657 return -EIO; 2658} 2659 2660static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) 2661{ 2662 __be32 *p; 2663 2664 p = xdr_inline_decode(xdr, 4); 2665 if (unlikely(!p)) 2666 goto out_overflow; 2667 *attrlen = be32_to_cpup(p); 2668 *savep = xdr->p; 2669 return 0; 2670out_overflow: 2671 print_overflow_msg(__func__, xdr); 2672 return -EIO; 2673} 2674 2675static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 2676{ 2677 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 2678 decode_attr_bitmap(xdr, bitmask); 2679 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 2680 } else 2681 bitmask[0] = bitmask[1] = 0; 2682 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]); 2683 return 0; 2684} 2685 2686static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 2687{ 2688 __be32 *p; 2689 int ret = 0; 2690 2691 *type = 0; 2692 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 2693 return -EIO; 2694 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 2695 p = xdr_inline_decode(xdr, 4); 2696 if (unlikely(!p)) 2697 goto out_overflow; 2698 *type = be32_to_cpup(p); 2699 if (*type < NF4REG || *type > NF4NAMEDATTR) { 2700 dprintk("%s: bad type %d\n", __func__, *type); 2701 return -EIO; 2702 } 2703 bitmap[0] &= ~FATTR4_WORD0_TYPE; 2704 ret = NFS_ATTR_FATTR_TYPE; 2705 } 2706 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 2707 return ret; 2708out_overflow: 2709 print_overflow_msg(__func__, xdr); 2710 return -EIO; 2711} 2712 2713static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 2714{ 2715 __be32 *p; 2716 int ret = 0; 2717 2718 *change = 0; 2719 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 2720 return -EIO; 2721 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 2722 p = xdr_inline_decode(xdr, 8); 2723 if (unlikely(!p)) 2724 goto out_overflow; 2725 xdr_decode_hyper(p, change); 2726 bitmap[0] &= ~FATTR4_WORD0_CHANGE; 2727 ret = NFS_ATTR_FATTR_CHANGE; 2728 } 2729 dprintk("%s: change attribute=%Lu\n", __func__, 2730 (unsigned long long)*change); 2731 return ret; 2732out_overflow: 2733 print_overflow_msg(__func__, xdr); 2734 return -EIO; 2735} 2736 2737static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 2738{ 2739 __be32 *p; 2740 int ret = 0; 2741 2742 *size = 0; 2743 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 2744 return -EIO; 2745 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 2746 p = xdr_inline_decode(xdr, 8); 2747 if (unlikely(!p)) 2748 goto out_overflow; 2749 xdr_decode_hyper(p, size); 2750 bitmap[0] &= ~FATTR4_WORD0_SIZE; 2751 ret = NFS_ATTR_FATTR_SIZE; 2752 } 2753 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 2754 return ret; 2755out_overflow: 2756 print_overflow_msg(__func__, xdr); 2757 return -EIO; 2758} 2759 2760static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2761{ 2762 __be32 *p; 2763 2764 *res = 0; 2765 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 2766 return -EIO; 2767 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 2768 p = xdr_inline_decode(xdr, 4); 2769 if (unlikely(!p)) 2770 goto out_overflow; 2771 *res = be32_to_cpup(p); 2772 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 2773 } 2774 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 2775 return 0; 2776out_overflow: 2777 print_overflow_msg(__func__, xdr); 2778 return -EIO; 2779} 2780 2781static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2782{ 2783 __be32 *p; 2784 2785 *res = 0; 2786 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 2787 return -EIO; 2788 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 2789 p = xdr_inline_decode(xdr, 4); 2790 if (unlikely(!p)) 2791 goto out_overflow; 2792 *res = be32_to_cpup(p); 2793 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 2794 } 2795 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 2796 return 0; 2797out_overflow: 2798 print_overflow_msg(__func__, xdr); 2799 return -EIO; 2800} 2801 2802static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 2803{ 2804 __be32 *p; 2805 int ret = 0; 2806 2807 fsid->major = 0; 2808 fsid->minor = 0; 2809 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 2810 return -EIO; 2811 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 2812 p = xdr_inline_decode(xdr, 16); 2813 if (unlikely(!p)) 2814 goto out_overflow; 2815 p = xdr_decode_hyper(p, &fsid->major); 2816 xdr_decode_hyper(p, &fsid->minor); 2817 bitmap[0] &= ~FATTR4_WORD0_FSID; 2818 ret = NFS_ATTR_FATTR_FSID; 2819 } 2820 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 2821 (unsigned long long)fsid->major, 2822 (unsigned long long)fsid->minor); 2823 return ret; 2824out_overflow: 2825 print_overflow_msg(__func__, xdr); 2826 return -EIO; 2827} 2828 2829static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2830{ 2831 __be32 *p; 2832 2833 *res = 60; 2834 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 2835 return -EIO; 2836 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 2837 p = xdr_inline_decode(xdr, 4); 2838 if (unlikely(!p)) 2839 goto out_overflow; 2840 *res = be32_to_cpup(p); 2841 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 2842 } 2843 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 2844 return 0; 2845out_overflow: 2846 print_overflow_msg(__func__, xdr); 2847 return -EIO; 2848} 2849 2850static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 2851{ 2852 __be32 *p; 2853 2854 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 2855 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 2856 return -EIO; 2857 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 2858 p = xdr_inline_decode(xdr, 4); 2859 if (unlikely(!p)) 2860 goto out_overflow; 2861 *res = be32_to_cpup(p); 2862 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 2863 } 2864 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 2865 return 0; 2866out_overflow: 2867 print_overflow_msg(__func__, xdr); 2868 return -EIO; 2869} 2870 2871static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 2872{ 2873 __be32 *p; 2874 int ret = 0; 2875 2876 *fileid = 0; 2877 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 2878 return -EIO; 2879 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 2880 p = xdr_inline_decode(xdr, 8); 2881 if (unlikely(!p)) 2882 goto out_overflow; 2883 xdr_decode_hyper(p, fileid); 2884 bitmap[0] &= ~FATTR4_WORD0_FILEID; 2885 ret = NFS_ATTR_FATTR_FILEID; 2886 } 2887 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 2888 return ret; 2889out_overflow: 2890 print_overflow_msg(__func__, xdr); 2891 return -EIO; 2892} 2893 2894static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 2895{ 2896 __be32 *p; 2897 int ret = 0; 2898 2899 *fileid = 0; 2900 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 2901 return -EIO; 2902 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 2903 p = xdr_inline_decode(xdr, 8); 2904 if (unlikely(!p)) 2905 goto out_overflow; 2906 xdr_decode_hyper(p, fileid); 2907 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 2908 ret = NFS_ATTR_FATTR_FILEID; 2909 } 2910 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 2911 return ret; 2912out_overflow: 2913 print_overflow_msg(__func__, xdr); 2914 return -EIO; 2915} 2916 2917static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2918{ 2919 __be32 *p; 2920 int status = 0; 2921 2922 *res = 0; 2923 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 2924 return -EIO; 2925 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 2926 p = xdr_inline_decode(xdr, 8); 2927 if (unlikely(!p)) 2928 goto out_overflow; 2929 xdr_decode_hyper(p, res); 2930 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 2931 } 2932 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 2933 return status; 2934out_overflow: 2935 print_overflow_msg(__func__, xdr); 2936 return -EIO; 2937} 2938 2939static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2940{ 2941 __be32 *p; 2942 int status = 0; 2943 2944 *res = 0; 2945 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 2946 return -EIO; 2947 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 2948 p = xdr_inline_decode(xdr, 8); 2949 if (unlikely(!p)) 2950 goto out_overflow; 2951 xdr_decode_hyper(p, res); 2952 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 2953 } 2954 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 2955 return status; 2956out_overflow: 2957 print_overflow_msg(__func__, xdr); 2958 return -EIO; 2959} 2960 2961static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 2962{ 2963 __be32 *p; 2964 int status = 0; 2965 2966 *res = 0; 2967 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 2968 return -EIO; 2969 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 2970 p = xdr_inline_decode(xdr, 8); 2971 if (unlikely(!p)) 2972 goto out_overflow; 2973 xdr_decode_hyper(p, res); 2974 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 2975 } 2976 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 2977 return status; 2978out_overflow: 2979 print_overflow_msg(__func__, xdr); 2980 return -EIO; 2981} 2982 2983static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 2984{ 2985 u32 n; 2986 __be32 *p; 2987 int status = 0; 2988 2989 p = xdr_inline_decode(xdr, 4); 2990 if (unlikely(!p)) 2991 goto out_overflow; 2992 n = be32_to_cpup(p); 2993 if (n == 0) 2994 goto root_path; 2995 dprintk("path "); 2996 path->ncomponents = 0; 2997 while (path->ncomponents < n) { 2998 struct nfs4_string *component = &path->components[path->ncomponents]; 2999 status = decode_opaque_inline(xdr, &component->len, &component->data); 3000 if (unlikely(status != 0)) 3001 goto out_eio; 3002 if (path->ncomponents != n) 3003 dprintk("/"); 3004 dprintk("%s", component->data); 3005 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 3006 path->ncomponents++; 3007 else { 3008 dprintk("cannot parse %d components in path\n", n); 3009 goto out_eio; 3010 } 3011 } 3012out: 3013 dprintk("\n"); 3014 return status; 3015root_path: 3016/* a root pathname is sent as a zero component4 */ 3017 path->ncomponents = 1; 3018 path->components[0].len=0; 3019 path->components[0].data=NULL; 3020 dprintk("path /\n"); 3021 goto out; 3022out_eio: 3023 dprintk(" status %d", status); 3024 status = -EIO; 3025 goto out; 3026out_overflow: 3027 print_overflow_msg(__func__, xdr); 3028 return -EIO; 3029} 3030 3031static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3032{ 3033 int n; 3034 __be32 *p; 3035 int status = -EIO; 3036 3037 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3038 goto out; 3039 status = 0; 3040 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3041 goto out; 3042 dprintk("%s: fsroot ", __func__); 3043 status = decode_pathname(xdr, &res->fs_path); 3044 if (unlikely(status != 0)) 3045 goto out; 3046 p = xdr_inline_decode(xdr, 4); 3047 if (unlikely(!p)) 3048 goto out_overflow; 3049 n = be32_to_cpup(p); 3050 if (n <= 0) 3051 goto out_eio; 3052 res->nlocations = 0; 3053 while (res->nlocations < n) { 3054 u32 m; 3055 struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 3056 3057 p = xdr_inline_decode(xdr, 4); 3058 if (unlikely(!p)) 3059 goto out_overflow; 3060 m = be32_to_cpup(p); 3061 3062 loc->nservers = 0; 3063 dprintk("%s: servers ", __func__); 3064 while (loc->nservers < m) { 3065 struct nfs4_string *server = &loc->servers[loc->nservers]; 3066 status = decode_opaque_inline(xdr, &server->len, &server->data); 3067 if (unlikely(status != 0)) 3068 goto out_eio; 3069 dprintk("%s ", server->data); 3070 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) 3071 loc->nservers++; 3072 else { 3073 unsigned int i; 3074 dprintk("%s: using first %u of %u servers " 3075 "returned for location %u\n", 3076 __func__, 3077 NFS4_FS_LOCATION_MAXSERVERS, 3078 m, res->nlocations); 3079 for (i = loc->nservers; i < m; i++) { 3080 unsigned int len; 3081 char *data; 3082 status = decode_opaque_inline(xdr, &len, &data); 3083 if (unlikely(status != 0)) 3084 goto out_eio; 3085 } 3086 } 3087 } 3088 status = decode_pathname(xdr, &loc->rootpath); 3089 if (unlikely(status != 0)) 3090 goto out_eio; 3091 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) 3092 res->nlocations++; 3093 } 3094 if (res->nlocations != 0) 3095 status = NFS_ATTR_FATTR_V4_REFERRAL; 3096out: 3097 dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3098 return status; 3099out_overflow: 3100 print_overflow_msg(__func__, xdr); 3101out_eio: 3102 status = -EIO; 3103 goto out; 3104} 3105 3106static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3107{ 3108 __be32 *p; 3109 int status = 0; 3110 3111 *res = 0; 3112 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 3113 return -EIO; 3114 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3115 p = xdr_inline_decode(xdr, 8); 3116 if (unlikely(!p)) 3117 goto out_overflow; 3118 xdr_decode_hyper(p, res); 3119 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 3120 } 3121 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 3122 return status; 3123out_overflow: 3124 print_overflow_msg(__func__, xdr); 3125 return -EIO; 3126} 3127 3128static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 3129{ 3130 __be32 *p; 3131 int status = 0; 3132 3133 *maxlink = 1; 3134 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 3135 return -EIO; 3136 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3137 p = xdr_inline_decode(xdr, 4); 3138 if (unlikely(!p)) 3139 goto out_overflow; 3140 *maxlink = be32_to_cpup(p); 3141 bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 3142 } 3143 dprintk("%s: maxlink=%u\n", __func__, *maxlink); 3144 return status; 3145out_overflow: 3146 print_overflow_msg(__func__, xdr); 3147 return -EIO; 3148} 3149 3150static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 3151{ 3152 __be32 *p; 3153 int status = 0; 3154 3155 *maxname = 1024; 3156 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 3157 return -EIO; 3158 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3159 p = xdr_inline_decode(xdr, 4); 3160 if (unlikely(!p)) 3161 goto out_overflow; 3162 *maxname = be32_to_cpup(p); 3163 bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 3164 } 3165 dprintk("%s: maxname=%u\n", __func__, *maxname); 3166 return status; 3167out_overflow: 3168 print_overflow_msg(__func__, xdr); 3169 return -EIO; 3170} 3171 3172static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 3173{ 3174 __be32 *p; 3175 int status = 0; 3176 3177 *res = 1024; 3178 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 3179 return -EIO; 3180 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 3181 uint64_t maxread; 3182 p = xdr_inline_decode(xdr, 8); 3183 if (unlikely(!p)) 3184 goto out_overflow; 3185 xdr_decode_hyper(p, &maxread); 3186 if (maxread > 0x7FFFFFFF) 3187 maxread = 0x7FFFFFFF; 3188 *res = (uint32_t)maxread; 3189 bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 3190 } 3191 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 3192 return status; 3193out_overflow: 3194 print_overflow_msg(__func__, xdr); 3195 return -EIO; 3196} 3197 3198static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 3199{ 3200 __be32 *p; 3201 int status = 0; 3202 3203 *res = 1024; 3204 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 3205 return -EIO; 3206 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 3207 uint64_t maxwrite; 3208 p = xdr_inline_decode(xdr, 8); 3209 if (unlikely(!p)) 3210 goto out_overflow; 3211 xdr_decode_hyper(p, &maxwrite); 3212 if (maxwrite > 0x7FFFFFFF) 3213 maxwrite = 0x7FFFFFFF; 3214 *res = (uint32_t)maxwrite; 3215 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 3216 } 3217 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 3218 return status; 3219out_overflow: 3220 print_overflow_msg(__func__, xdr); 3221 return -EIO; 3222} 3223 3224static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 3225{ 3226 uint32_t tmp; 3227 __be32 *p; 3228 int ret = 0; 3229 3230 *mode = 0; 3231 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 3232 return -EIO; 3233 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3234 p = xdr_inline_decode(xdr, 4); 3235 if (unlikely(!p)) 3236 goto out_overflow; 3237 tmp = be32_to_cpup(p); 3238 *mode = tmp & ~S_IFMT; 3239 bitmap[1] &= ~FATTR4_WORD1_MODE; 3240 ret = NFS_ATTR_FATTR_MODE; 3241 } 3242 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3243 return ret; 3244out_overflow: 3245 print_overflow_msg(__func__, xdr); 3246 return -EIO; 3247} 3248 3249static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 3250{ 3251 __be32 *p; 3252 int ret = 0; 3253 3254 *nlink = 1; 3255 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 3256 return -EIO; 3257 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3258 p = xdr_inline_decode(xdr, 4); 3259 if (unlikely(!p)) 3260 goto out_overflow; 3261 *nlink = be32_to_cpup(p); 3262 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3263 ret = NFS_ATTR_FATTR_NLINK; 3264 } 3265 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3266 return ret; 3267out_overflow: 3268 print_overflow_msg(__func__, xdr); 3269 return -EIO; 3270} 3271 3272static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3273 struct nfs_client *clp, uint32_t *uid, int may_sleep) 3274{ 3275 uint32_t len; 3276 __be32 *p; 3277 int ret = 0; 3278 3279 *uid = -2; 3280 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 3281 return -EIO; 3282 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3283 p = xdr_inline_decode(xdr, 4); 3284 if (unlikely(!p)) 3285 goto out_overflow; 3286 len = be32_to_cpup(p); 3287 p = xdr_inline_decode(xdr, len); 3288 if (unlikely(!p)) 3289 goto out_overflow; 3290 if (!may_sleep) { 3291 /* do nothing */ 3292 } else if (len < XDR_MAX_NETOBJ) { 3293 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0) 3294 ret = NFS_ATTR_FATTR_OWNER; 3295 else 3296 dprintk("%s: nfs_map_name_to_uid failed!\n", 3297 __func__); 3298 } else 3299 dprintk("%s: name too long (%u)!\n", 3300 __func__, len); 3301 bitmap[1] &= ~FATTR4_WORD1_OWNER; 3302 } 3303 dprintk("%s: uid=%d\n", __func__, (int)*uid); 3304 return ret; 3305out_overflow: 3306 print_overflow_msg(__func__, xdr); 3307 return -EIO; 3308} 3309 3310static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3311 struct nfs_client *clp, uint32_t *gid, int may_sleep) 3312{ 3313 uint32_t len; 3314 __be32 *p; 3315 int ret = 0; 3316 3317 *gid = -2; 3318 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 3319 return -EIO; 3320 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3321 p = xdr_inline_decode(xdr, 4); 3322 if (unlikely(!p)) 3323 goto out_overflow; 3324 len = be32_to_cpup(p); 3325 p = xdr_inline_decode(xdr, len); 3326 if (unlikely(!p)) 3327 goto out_overflow; 3328 if (!may_sleep) { 3329 /* do nothing */ 3330 } else if (len < XDR_MAX_NETOBJ) { 3331 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0) 3332 ret = NFS_ATTR_FATTR_GROUP; 3333 else 3334 dprintk("%s: nfs_map_group_to_gid failed!\n", 3335 __func__); 3336 } else 3337 dprintk("%s: name too long (%u)!\n", 3338 __func__, len); 3339 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 3340 } 3341 dprintk("%s: gid=%d\n", __func__, (int)*gid); 3342 return ret; 3343out_overflow: 3344 print_overflow_msg(__func__, xdr); 3345 return -EIO; 3346} 3347 3348static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 3349{ 3350 uint32_t major = 0, minor = 0; 3351 __be32 *p; 3352 int ret = 0; 3353 3354 *rdev = MKDEV(0,0); 3355 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 3356 return -EIO; 3357 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 3358 dev_t tmp; 3359 3360 p = xdr_inline_decode(xdr, 8); 3361 if (unlikely(!p)) 3362 goto out_overflow; 3363 major = be32_to_cpup(p++); 3364 minor = be32_to_cpup(p); 3365 tmp = MKDEV(major, minor); 3366 if (MAJOR(tmp) == major && MINOR(tmp) == minor) 3367 *rdev = tmp; 3368 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3369 ret = NFS_ATTR_FATTR_RDEV; 3370 } 3371 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3372 return ret; 3373out_overflow: 3374 print_overflow_msg(__func__, xdr); 3375 return -EIO; 3376} 3377 3378static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3379{ 3380 __be32 *p; 3381 int status = 0; 3382 3383 *res = 0; 3384 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 3385 return -EIO; 3386 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3387 p = xdr_inline_decode(xdr, 8); 3388 if (unlikely(!p)) 3389 goto out_overflow; 3390 xdr_decode_hyper(p, res); 3391 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 3392 } 3393 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 3394 return status; 3395out_overflow: 3396 print_overflow_msg(__func__, xdr); 3397 return -EIO; 3398} 3399 3400static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3401{ 3402 __be32 *p; 3403 int status = 0; 3404 3405 *res = 0; 3406 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 3407 return -EIO; 3408 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3409 p = xdr_inline_decode(xdr, 8); 3410 if (unlikely(!p)) 3411 goto out_overflow; 3412 xdr_decode_hyper(p, res); 3413 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 3414 } 3415 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 3416 return status; 3417out_overflow: 3418 print_overflow_msg(__func__, xdr); 3419 return -EIO; 3420} 3421 3422static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 3423{ 3424 __be32 *p; 3425 int status = 0; 3426 3427 *res = 0; 3428 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 3429 return -EIO; 3430 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 3431 p = xdr_inline_decode(xdr, 8); 3432 if (unlikely(!p)) 3433 goto out_overflow; 3434 xdr_decode_hyper(p, res); 3435 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 3436 } 3437 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 3438 return status; 3439out_overflow: 3440 print_overflow_msg(__func__, xdr); 3441 return -EIO; 3442} 3443 3444static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 3445{ 3446 __be32 *p; 3447 int ret = 0; 3448 3449 *used = 0; 3450 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 3451 return -EIO; 3452 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 3453 p = xdr_inline_decode(xdr, 8); 3454 if (unlikely(!p)) 3455 goto out_overflow; 3456 xdr_decode_hyper(p, used); 3457 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 3458 ret = NFS_ATTR_FATTR_SPACE_USED; 3459 } 3460 dprintk("%s: space used=%Lu\n", __func__, 3461 (unsigned long long)*used); 3462 return ret; 3463out_overflow: 3464 print_overflow_msg(__func__, xdr); 3465 return -EIO; 3466} 3467 3468static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 3469{ 3470 __be32 *p; 3471 uint64_t sec; 3472 uint32_t nsec; 3473 3474 p = xdr_inline_decode(xdr, 12); 3475 if (unlikely(!p)) 3476 goto out_overflow; 3477 p = xdr_decode_hyper(p, &sec); 3478 nsec = be32_to_cpup(p); 3479 time->tv_sec = (time_t)sec; 3480 time->tv_nsec = (long)nsec; 3481 return 0; 3482out_overflow: 3483 print_overflow_msg(__func__, xdr); 3484 return -EIO; 3485} 3486 3487static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 3488{ 3489 int status = 0; 3490 3491 time->tv_sec = 0; 3492 time->tv_nsec = 0; 3493 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 3494 return -EIO; 3495 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 3496 status = decode_attr_time(xdr, time); 3497 if (status == 0) 3498 status = NFS_ATTR_FATTR_ATIME; 3499 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 3500 } 3501 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 3502 return status; 3503} 3504 3505static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 3506{ 3507 int status = 0; 3508 3509 time->tv_sec = 0; 3510 time->tv_nsec = 0; 3511 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 3512 return -EIO; 3513 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 3514 status = decode_attr_time(xdr, time); 3515 if (status == 0) 3516 status = NFS_ATTR_FATTR_CTIME; 3517 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 3518 } 3519 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 3520 return status; 3521} 3522 3523static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 3524{ 3525 int status = 0; 3526 3527 time->tv_sec = 0; 3528 time->tv_nsec = 0; 3529 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 3530 return -EIO; 3531 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 3532 status = decode_attr_time(xdr, time); 3533 if (status == 0) 3534 status = NFS_ATTR_FATTR_MTIME; 3535 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 3536 } 3537 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 3538 return status; 3539} 3540 3541static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) 3542{ 3543 unsigned int attrwords = XDR_QUADLEN(attrlen); 3544 unsigned int nwords = xdr->p - savep; 3545 3546 if (unlikely(attrwords != nwords)) { 3547 dprintk("%s: server returned incorrect attribute length: " 3548 "%u %c %u\n", 3549 __func__, 3550 attrwords << 2, 3551 (attrwords < nwords) ? '<' : '>', 3552 nwords << 2); 3553 return -EIO; 3554 } 3555 return 0; 3556} 3557 3558static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 3559{ 3560 __be32 *p; 3561 3562 p = xdr_inline_decode(xdr, 20); 3563 if (unlikely(!p)) 3564 goto out_overflow; 3565 cinfo->atomic = be32_to_cpup(p++); 3566 p = xdr_decode_hyper(p, &cinfo->before); 3567 xdr_decode_hyper(p, &cinfo->after); 3568 return 0; 3569out_overflow: 3570 print_overflow_msg(__func__, xdr); 3571 return -EIO; 3572} 3573 3574static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 3575{ 3576 __be32 *p; 3577 uint32_t supp, acc; 3578 int status; 3579 3580 status = decode_op_hdr(xdr, OP_ACCESS); 3581 if (status) 3582 return status; 3583 p = xdr_inline_decode(xdr, 8); 3584 if (unlikely(!p)) 3585 goto out_overflow; 3586 supp = be32_to_cpup(p++); 3587 acc = be32_to_cpup(p); 3588 access->supported = supp; 3589 access->access = acc; 3590 return 0; 3591out_overflow: 3592 print_overflow_msg(__func__, xdr); 3593 return -EIO; 3594} 3595 3596static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 3597{ 3598 __be32 *p; 3599 3600 p = xdr_inline_decode(xdr, len); 3601 if (likely(p)) { 3602 memcpy(buf, p, len); 3603 return 0; 3604 } 3605 print_overflow_msg(__func__, xdr); 3606 return -EIO; 3607} 3608 3609static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 3610{ 3611 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE); 3612} 3613 3614static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 3615{ 3616 int status; 3617 3618 status = decode_op_hdr(xdr, OP_CLOSE); 3619 if (status != -EIO) 3620 nfs_increment_open_seqid(status, res->seqid); 3621 if (!status) 3622 status = decode_stateid(xdr, &res->stateid); 3623 return status; 3624} 3625 3626static int decode_verifier(struct xdr_stream *xdr, void *verifier) 3627{ 3628 return decode_opaque_fixed(xdr, verifier, 8); 3629} 3630 3631static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) 3632{ 3633 int status; 3634 3635 status = decode_op_hdr(xdr, OP_COMMIT); 3636 if (!status) 3637 status = decode_verifier(xdr, res->verf->verifier); 3638 return status; 3639} 3640 3641static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 3642{ 3643 __be32 *p; 3644 uint32_t bmlen; 3645 int status; 3646 3647 status = decode_op_hdr(xdr, OP_CREATE); 3648 if (status) 3649 return status; 3650 if ((status = decode_change_info(xdr, cinfo))) 3651 return status; 3652 p = xdr_inline_decode(xdr, 4); 3653 if (unlikely(!p)) 3654 goto out_overflow; 3655 bmlen = be32_to_cpup(p); 3656 p = xdr_inline_decode(xdr, bmlen << 2); 3657 if (likely(p)) 3658 return 0; 3659out_overflow: 3660 print_overflow_msg(__func__, xdr); 3661 return -EIO; 3662} 3663 3664static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 3665{ 3666 __be32 *savep; 3667 uint32_t attrlen, bitmap[2] = {0}; 3668 int status; 3669 3670 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3671 goto xdr_error; 3672 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3673 goto xdr_error; 3674 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3675 goto xdr_error; 3676 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 3677 goto xdr_error; 3678 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 3679 goto xdr_error; 3680 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 3681 goto xdr_error; 3682 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 3683 goto xdr_error; 3684 status = verify_attr_len(xdr, savep, attrlen); 3685xdr_error: 3686 dprintk("%s: xdr returned %d!\n", __func__, -status); 3687 return status; 3688} 3689 3690static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 3691{ 3692 __be32 *savep; 3693 uint32_t attrlen, bitmap[2] = {0}; 3694 int status; 3695 3696 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3697 goto xdr_error; 3698 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3699 goto xdr_error; 3700 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3701 goto xdr_error; 3702 3703 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 3704 goto xdr_error; 3705 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 3706 goto xdr_error; 3707 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 3708 goto xdr_error; 3709 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 3710 goto xdr_error; 3711 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 3712 goto xdr_error; 3713 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 3714 goto xdr_error; 3715 3716 status = verify_attr_len(xdr, savep, attrlen); 3717xdr_error: 3718 dprintk("%s: xdr returned %d!\n", __func__, -status); 3719 return status; 3720} 3721 3722static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 3723{ 3724 __be32 *savep; 3725 uint32_t attrlen, bitmap[2] = {0}; 3726 int status; 3727 3728 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3729 goto xdr_error; 3730 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3731 goto xdr_error; 3732 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3733 goto xdr_error; 3734 3735 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 3736 goto xdr_error; 3737 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 3738 goto xdr_error; 3739 3740 status = verify_attr_len(xdr, savep, attrlen); 3741xdr_error: 3742 dprintk("%s: xdr returned %d!\n", __func__, -status); 3743 return status; 3744} 3745 3746static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 3747 const struct nfs_server *server, int may_sleep) 3748{ 3749 __be32 *savep; 3750 uint32_t attrlen, 3751 bitmap[2] = {0}, 3752 type; 3753 int status; 3754 umode_t fmode = 0; 3755 uint64_t fileid; 3756 3757 status = decode_op_hdr(xdr, OP_GETATTR); 3758 if (status < 0) 3759 goto xdr_error; 3760 3761 status = decode_attr_bitmap(xdr, bitmap); 3762 if (status < 0) 3763 goto xdr_error; 3764 3765 status = decode_attr_length(xdr, &attrlen, &savep); 3766 if (status < 0) 3767 goto xdr_error; 3768 3769 3770 status = decode_attr_type(xdr, bitmap, &type); 3771 if (status < 0) 3772 goto xdr_error; 3773 fattr->mode = 0; 3774 if (status != 0) { 3775 fattr->mode |= nfs_type2fmt[type]; 3776 fattr->valid |= status; 3777 } 3778 3779 status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 3780 if (status < 0) 3781 goto xdr_error; 3782 fattr->valid |= status; 3783 3784 status = decode_attr_size(xdr, bitmap, &fattr->size); 3785 if (status < 0) 3786 goto xdr_error; 3787 fattr->valid |= status; 3788 3789 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 3790 if (status < 0) 3791 goto xdr_error; 3792 fattr->valid |= status; 3793 3794 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 3795 if (status < 0) 3796 goto xdr_error; 3797 fattr->valid |= status; 3798 3799 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, 3800 struct nfs4_fs_locations, 3801 fattr)); 3802 if (status < 0) 3803 goto xdr_error; 3804 fattr->valid |= status; 3805 3806 status = decode_attr_mode(xdr, bitmap, &fmode); 3807 if (status < 0) 3808 goto xdr_error; 3809 if (status != 0) { 3810 fattr->mode |= fmode; 3811 fattr->valid |= status; 3812 } 3813 3814 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 3815 if (status < 0) 3816 goto xdr_error; 3817 fattr->valid |= status; 3818 3819 status = decode_attr_owner(xdr, bitmap, server->nfs_client, 3820 &fattr->uid, may_sleep); 3821 if (status < 0) 3822 goto xdr_error; 3823 fattr->valid |= status; 3824 3825 status = decode_attr_group(xdr, bitmap, server->nfs_client, 3826 &fattr->gid, may_sleep); 3827 if (status < 0) 3828 goto xdr_error; 3829 fattr->valid |= status; 3830 3831 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 3832 if (status < 0) 3833 goto xdr_error; 3834 fattr->valid |= status; 3835 3836 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 3837 if (status < 0) 3838 goto xdr_error; 3839 fattr->valid |= status; 3840 3841 status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 3842 if (status < 0) 3843 goto xdr_error; 3844 fattr->valid |= status; 3845 3846 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 3847 if (status < 0) 3848 goto xdr_error; 3849 fattr->valid |= status; 3850 3851 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 3852 if (status < 0) 3853 goto xdr_error; 3854 fattr->valid |= status; 3855 3856 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid); 3857 if (status < 0) 3858 goto xdr_error; 3859 if (status != 0 && !(fattr->valid & status)) { 3860 fattr->fileid = fileid; 3861 fattr->valid |= status; 3862 } 3863 3864 status = verify_attr_len(xdr, savep, attrlen); 3865xdr_error: 3866 dprintk("%s: xdr returned %d\n", __func__, -status); 3867 return status; 3868} 3869 3870 3871static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 3872{ 3873 __be32 *savep; 3874 uint32_t attrlen, bitmap[2]; 3875 int status; 3876 3877 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 3878 goto xdr_error; 3879 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 3880 goto xdr_error; 3881 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 3882 goto xdr_error; 3883 3884 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 3885 3886 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 3887 goto xdr_error; 3888 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 3889 goto xdr_error; 3890 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 3891 goto xdr_error; 3892 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 3893 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 3894 goto xdr_error; 3895 fsinfo->wtpref = fsinfo->wtmax; 3896 3897 status = verify_attr_len(xdr, savep, attrlen); 3898xdr_error: 3899 dprintk("%s: xdr returned %d!\n", __func__, -status); 3900 return status; 3901} 3902 3903static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 3904{ 3905 __be32 *p; 3906 uint32_t len; 3907 int status; 3908 3909 /* Zero handle first to allow comparisons */ 3910 memset(fh, 0, sizeof(*fh)); 3911 3912 status = decode_op_hdr(xdr, OP_GETFH); 3913 if (status) 3914 return status; 3915 3916 p = xdr_inline_decode(xdr, 4); 3917 if (unlikely(!p)) 3918 goto out_overflow; 3919 len = be32_to_cpup(p); 3920 if (len > NFS4_FHSIZE) 3921 return -EIO; 3922 fh->size = len; 3923 p = xdr_inline_decode(xdr, len); 3924 if (unlikely(!p)) 3925 goto out_overflow; 3926 memcpy(fh->data, p, len); 3927 return 0; 3928out_overflow: 3929 print_overflow_msg(__func__, xdr); 3930 return -EIO; 3931} 3932 3933static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 3934{ 3935 int status; 3936 3937 status = decode_op_hdr(xdr, OP_LINK); 3938 if (status) 3939 return status; 3940 return decode_change_info(xdr, cinfo); 3941} 3942 3943/* 3944 * We create the owner, so we know a proper owner.id length is 4. 3945 */ 3946static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 3947{ 3948 uint64_t offset, length, clientid; 3949 __be32 *p; 3950 uint32_t namelen, type; 3951 3952 p = xdr_inline_decode(xdr, 32); 3953 if (unlikely(!p)) 3954 goto out_overflow; 3955 p = xdr_decode_hyper(p, &offset); 3956 p = xdr_decode_hyper(p, &length); 3957 type = be32_to_cpup(p++); 3958 if (fl != NULL) { 3959 fl->fl_start = (loff_t)offset; 3960 fl->fl_end = fl->fl_start + (loff_t)length - 1; 3961 if (length == ~(uint64_t)0) 3962 fl->fl_end = OFFSET_MAX; 3963 fl->fl_type = F_WRLCK; 3964 if (type & 1) 3965 fl->fl_type = F_RDLCK; 3966 fl->fl_pid = 0; 3967 } 3968 p = xdr_decode_hyper(p, &clientid); 3969 namelen = be32_to_cpup(p); 3970 p = xdr_inline_decode(xdr, namelen); 3971 if (likely(p)) 3972 return -NFS4ERR_DENIED; 3973out_overflow: 3974 print_overflow_msg(__func__, xdr); 3975 return -EIO; 3976} 3977 3978static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 3979{ 3980 int status; 3981 3982 status = decode_op_hdr(xdr, OP_LOCK); 3983 if (status == -EIO) 3984 goto out; 3985 if (status == 0) { 3986 status = decode_stateid(xdr, &res->stateid); 3987 if (unlikely(status)) 3988 goto out; 3989 } else if (status == -NFS4ERR_DENIED) 3990 status = decode_lock_denied(xdr, NULL); 3991 if (res->open_seqid != NULL) 3992 nfs_increment_open_seqid(status, res->open_seqid); 3993 nfs_increment_lock_seqid(status, res->lock_seqid); 3994out: 3995 return status; 3996} 3997 3998static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 3999{ 4000 int status; 4001 status = decode_op_hdr(xdr, OP_LOCKT); 4002 if (status == -NFS4ERR_DENIED) 4003 return decode_lock_denied(xdr, res->denied); 4004 return status; 4005} 4006 4007static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 4008{ 4009 int status; 4010 4011 status = decode_op_hdr(xdr, OP_LOCKU); 4012 if (status != -EIO) 4013 nfs_increment_lock_seqid(status, res->seqid); 4014 if (status == 0) 4015 status = decode_stateid(xdr, &res->stateid); 4016 return status; 4017} 4018 4019static int decode_release_lockowner(struct xdr_stream *xdr) 4020{ 4021 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4022} 4023 4024static int decode_lookup(struct xdr_stream *xdr) 4025{ 4026 return decode_op_hdr(xdr, OP_LOOKUP); 4027} 4028 4029/* This is too sick! */ 4030static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 4031{ 4032 __be32 *p; 4033 uint32_t limit_type, nblocks, blocksize; 4034 4035 p = xdr_inline_decode(xdr, 12); 4036 if (unlikely(!p)) 4037 goto out_overflow; 4038 limit_type = be32_to_cpup(p++); 4039 switch (limit_type) { 4040 case 1: 4041 xdr_decode_hyper(p, maxsize); 4042 break; 4043 case 2: 4044 nblocks = be32_to_cpup(p++); 4045 blocksize = be32_to_cpup(p); 4046 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 4047 } 4048 return 0; 4049out_overflow: 4050 print_overflow_msg(__func__, xdr); 4051 return -EIO; 4052} 4053 4054static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 4055{ 4056 __be32 *p; 4057 uint32_t delegation_type; 4058 int status; 4059 4060 p = xdr_inline_decode(xdr, 4); 4061 if (unlikely(!p)) 4062 goto out_overflow; 4063 delegation_type = be32_to_cpup(p); 4064 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 4065 res->delegation_type = 0; 4066 return 0; 4067 } 4068 status = decode_stateid(xdr, &res->delegation); 4069 if (unlikely(status)) 4070 return status; 4071 p = xdr_inline_decode(xdr, 4); 4072 if (unlikely(!p)) 4073 goto out_overflow; 4074 res->do_recall = be32_to_cpup(p); 4075 4076 switch (delegation_type) { 4077 case NFS4_OPEN_DELEGATE_READ: 4078 res->delegation_type = FMODE_READ; 4079 break; 4080 case NFS4_OPEN_DELEGATE_WRITE: 4081 res->delegation_type = FMODE_WRITE|FMODE_READ; 4082 if (decode_space_limit(xdr, &res->maxsize) < 0) 4083 return -EIO; 4084 } 4085 return decode_ace(xdr, NULL, res->server->nfs_client); 4086out_overflow: 4087 print_overflow_msg(__func__, xdr); 4088 return -EIO; 4089} 4090 4091static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 4092{ 4093 __be32 *p; 4094 uint32_t savewords, bmlen, i; 4095 int status; 4096 4097 status = decode_op_hdr(xdr, OP_OPEN); 4098 if (status != -EIO) 4099 nfs_increment_open_seqid(status, res->seqid); 4100 if (!status) 4101 status = decode_stateid(xdr, &res->stateid); 4102 if (unlikely(status)) 4103 return status; 4104 4105 decode_change_info(xdr, &res->cinfo); 4106 4107 p = xdr_inline_decode(xdr, 8); 4108 if (unlikely(!p)) 4109 goto out_overflow; 4110 res->rflags = be32_to_cpup(p++); 4111 bmlen = be32_to_cpup(p); 4112 if (bmlen > 10) 4113 goto xdr_error; 4114 4115 p = xdr_inline_decode(xdr, bmlen << 2); 4116 if (unlikely(!p)) 4117 goto out_overflow; 4118 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 4119 for (i = 0; i < savewords; ++i) 4120 res->attrset[i] = be32_to_cpup(p++); 4121 for (; i < NFS4_BITMAP_SIZE; i++) 4122 res->attrset[i] = 0; 4123 4124 return decode_delegation(xdr, res); 4125xdr_error: 4126 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 4127 return -EIO; 4128out_overflow: 4129 print_overflow_msg(__func__, xdr); 4130 return -EIO; 4131} 4132 4133static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 4134{ 4135 int status; 4136 4137 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 4138 if (status != -EIO) 4139 nfs_increment_open_seqid(status, res->seqid); 4140 if (!status) 4141 status = decode_stateid(xdr, &res->stateid); 4142 return status; 4143} 4144 4145static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 4146{ 4147 int status; 4148 4149 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 4150 if (status != -EIO) 4151 nfs_increment_open_seqid(status, res->seqid); 4152 if (!status) 4153 status = decode_stateid(xdr, &res->stateid); 4154 return status; 4155} 4156 4157static int decode_putfh(struct xdr_stream *xdr) 4158{ 4159 return decode_op_hdr(xdr, OP_PUTFH); 4160} 4161 4162static int decode_putrootfh(struct xdr_stream *xdr) 4163{ 4164 return decode_op_hdr(xdr, OP_PUTROOTFH); 4165} 4166 4167static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 4168{ 4169 struct kvec *iov = req->rq_rcv_buf.head; 4170 __be32 *p; 4171 uint32_t count, eof, recvd, hdrlen; 4172 int status; 4173 4174 status = decode_op_hdr(xdr, OP_READ); 4175 if (status) 4176 return status; 4177 p = xdr_inline_decode(xdr, 8); 4178 if (unlikely(!p)) 4179 goto out_overflow; 4180 eof = be32_to_cpup(p++); 4181 count = be32_to_cpup(p); 4182 hdrlen = (u8 *) p - (u8 *) iov->iov_base; 4183 recvd = req->rq_rcv_buf.len - hdrlen; 4184 if (count > recvd) { 4185 dprintk("NFS: server cheating in read reply: " 4186 "count %u > recvd %u\n", count, recvd); 4187 count = recvd; 4188 eof = 0; 4189 } 4190 xdr_read_pages(xdr, count); 4191 res->eof = eof; 4192 res->count = count; 4193 return 0; 4194out_overflow: 4195 print_overflow_msg(__func__, xdr); 4196 return -EIO; 4197} 4198 4199static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 4200{ 4201 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 4202 struct page *page = *rcvbuf->pages; 4203 struct kvec *iov = rcvbuf->head; 4204 size_t hdrlen; 4205 u32 recvd, pglen = rcvbuf->page_len; 4206 __be32 *end, *entry, *p, *kaddr; 4207 unsigned int nr = 0; 4208 int status; 4209 4210 status = decode_op_hdr(xdr, OP_READDIR); 4211 if (!status) 4212 status = decode_verifier(xdr, readdir->verifier.data); 4213 if (unlikely(status)) 4214 return status; 4215 dprintk("%s: verifier = %08x:%08x\n", 4216 __func__, 4217 ((u32 *)readdir->verifier.data)[0], 4218 ((u32 *)readdir->verifier.data)[1]); 4219 4220 4221 hdrlen = (char *) xdr->p - (char *) iov->iov_base; 4222 recvd = rcvbuf->len - hdrlen; 4223 if (pglen > recvd) 4224 pglen = recvd; 4225 xdr_read_pages(xdr, pglen); 4226 4227 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE); 4228 kaddr = p = kmap_atomic(page, KM_USER0); 4229 end = p + ((pglen + readdir->pgbase) >> 2); 4230 entry = p; 4231 4232 /* Make sure the packet actually has a value_follows and EOF entry */ 4233 if ((entry + 1) > end) 4234 goto short_pkt; 4235 4236 for (; *p++; nr++) { 4237 u32 len, attrlen, xlen; 4238 if (end - p < 3) 4239 goto short_pkt; 4240 dprintk("cookie = %Lu, ", *((unsigned long long *)p)); 4241 p += 2; /* cookie */ 4242 len = ntohl(*p++); /* filename length */ 4243 if (len > NFS4_MAXNAMLEN) { 4244 dprintk("NFS: giant filename in readdir (len 0x%x)\n", 4245 len); 4246 goto err_unmap; 4247 } 4248 xlen = XDR_QUADLEN(len); 4249 if (end - p < xlen + 1) 4250 goto short_pkt; 4251 dprintk("filename = %*s\n", len, (char *)p); 4252 p += xlen; 4253 len = ntohl(*p++); /* bitmap length */ 4254 if (end - p < len + 1) 4255 goto short_pkt; 4256 p += len; 4257 attrlen = XDR_QUADLEN(ntohl(*p++)); 4258 if (end - p < attrlen + 2) 4259 goto short_pkt; 4260 p += attrlen; /* attributes */ 4261 entry = p; 4262 } 4263 /* 4264 * Apparently some server sends responses that are a valid size, but 4265 * contain no entries, and have value_follows==0 and EOF==0. For 4266 * those, just set the EOF marker. 4267 */ 4268 if (!nr && entry[1] == 0) { 4269 dprintk("NFS: readdir reply truncated!\n"); 4270 entry[1] = 1; 4271 } 4272out: 4273 kunmap_atomic(kaddr, KM_USER0); 4274 return 0; 4275short_pkt: 4276 /* 4277 * When we get a short packet there are 2 possibilities. We can 4278 * return an error, or fix up the response to look like a valid 4279 * response and return what we have so far. If there are no 4280 * entries and the packet was short, then return -EIO. If there 4281 * are valid entries in the response, return them and pretend that 4282 * the call was successful, but incomplete. The caller can retry the 4283 * readdir starting at the last cookie. 4284 */ 4285 dprintk("%s: short packet at entry %d\n", __func__, nr); 4286 entry[0] = entry[1] = 0; 4287 if (nr) 4288 goto out; 4289err_unmap: 4290 kunmap_atomic(kaddr, KM_USER0); 4291 return -errno_NFSERR_IO; 4292} 4293 4294static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 4295{ 4296 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 4297 struct kvec *iov = rcvbuf->head; 4298 size_t hdrlen; 4299 u32 len, recvd; 4300 __be32 *p; 4301 char *kaddr; 4302 int status; 4303 4304 status = decode_op_hdr(xdr, OP_READLINK); 4305 if (status) 4306 return status; 4307 4308 /* Convert length of symlink */ 4309 p = xdr_inline_decode(xdr, 4); 4310 if (unlikely(!p)) 4311 goto out_overflow; 4312 len = be32_to_cpup(p); 4313 if (len >= rcvbuf->page_len || len <= 0) { 4314 dprintk("nfs: server returned giant symlink!\n"); 4315 return -ENAMETOOLONG; 4316 } 4317 hdrlen = (char *) xdr->p - (char *) iov->iov_base; 4318 recvd = req->rq_rcv_buf.len - hdrlen; 4319 if (recvd < len) { 4320 dprintk("NFS: server cheating in readlink reply: " 4321 "count %u > recvd %u\n", len, recvd); 4322 return -EIO; 4323 } 4324 xdr_read_pages(xdr, len); 4325 /* 4326 * The XDR encode routine has set things up so that 4327 * the link text will be copied directly into the 4328 * buffer. We just have to do overflow-checking, 4329 * and and null-terminate the text (the VFS expects 4330 * null-termination). 4331 */ 4332 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0); 4333 kaddr[len+rcvbuf->page_base] = '\0'; 4334 kunmap_atomic(kaddr, KM_USER0); 4335 return 0; 4336out_overflow: 4337 print_overflow_msg(__func__, xdr); 4338 return -EIO; 4339} 4340 4341static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 4342{ 4343 int status; 4344 4345 status = decode_op_hdr(xdr, OP_REMOVE); 4346 if (status) 4347 goto out; 4348 status = decode_change_info(xdr, cinfo); 4349out: 4350 return status; 4351} 4352 4353static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 4354 struct nfs4_change_info *new_cinfo) 4355{ 4356 int status; 4357 4358 status = decode_op_hdr(xdr, OP_RENAME); 4359 if (status) 4360 goto out; 4361 if ((status = decode_change_info(xdr, old_cinfo))) 4362 goto out; 4363 status = decode_change_info(xdr, new_cinfo); 4364out: 4365 return status; 4366} 4367 4368static int decode_renew(struct xdr_stream *xdr) 4369{ 4370 return decode_op_hdr(xdr, OP_RENEW); 4371} 4372 4373static int 4374decode_restorefh(struct xdr_stream *xdr) 4375{ 4376 return decode_op_hdr(xdr, OP_RESTOREFH); 4377} 4378 4379static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 4380 size_t *acl_len) 4381{ 4382 __be32 *savep; 4383 uint32_t attrlen, 4384 bitmap[2] = {0}; 4385 struct kvec *iov = req->rq_rcv_buf.head; 4386 int status; 4387 4388 *acl_len = 0; 4389 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 4390 goto out; 4391 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 4392 goto out; 4393 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 4394 goto out; 4395 4396 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 4397 return -EIO; 4398 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 4399 size_t hdrlen; 4400 u32 recvd; 4401 4402 /* We ignore &savep and don't do consistency checks on 4403 * the attr length. Let userspace figure it out.... */ 4404 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; 4405 recvd = req->rq_rcv_buf.len - hdrlen; 4406 if (attrlen > recvd) { 4407 dprintk("NFS: server cheating in getattr" 4408 " acl reply: attrlen %u > recvd %u\n", 4409 attrlen, recvd); 4410 return -EINVAL; 4411 } 4412 xdr_read_pages(xdr, attrlen); 4413 *acl_len = attrlen; 4414 } else 4415 status = -EOPNOTSUPP; 4416 4417out: 4418 return status; 4419} 4420 4421static int 4422decode_savefh(struct xdr_stream *xdr) 4423{ 4424 return decode_op_hdr(xdr, OP_SAVEFH); 4425} 4426 4427static int decode_setattr(struct xdr_stream *xdr) 4428{ 4429 __be32 *p; 4430 uint32_t bmlen; 4431 int status; 4432 4433 status = decode_op_hdr(xdr, OP_SETATTR); 4434 if (status) 4435 return status; 4436 p = xdr_inline_decode(xdr, 4); 4437 if (unlikely(!p)) 4438 goto out_overflow; 4439 bmlen = be32_to_cpup(p); 4440 p = xdr_inline_decode(xdr, bmlen << 2); 4441 if (likely(p)) 4442 return 0; 4443out_overflow: 4444 print_overflow_msg(__func__, xdr); 4445 return -EIO; 4446} 4447 4448static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 4449{ 4450 __be32 *p; 4451 uint32_t opnum; 4452 int32_t nfserr; 4453 4454 p = xdr_inline_decode(xdr, 8); 4455 if (unlikely(!p)) 4456 goto out_overflow; 4457 opnum = be32_to_cpup(p++); 4458 if (opnum != OP_SETCLIENTID) { 4459 dprintk("nfs: decode_setclientid: Server returned operation" 4460 " %d\n", opnum); 4461 return -EIO; 4462 } 4463 nfserr = be32_to_cpup(p); 4464 if (nfserr == NFS_OK) { 4465 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 4466 if (unlikely(!p)) 4467 goto out_overflow; 4468 p = xdr_decode_hyper(p, &res->clientid); 4469 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 4470 } else if (nfserr == NFSERR_CLID_INUSE) { 4471 uint32_t len; 4472 4473 /* skip netid string */ 4474 p = xdr_inline_decode(xdr, 4); 4475 if (unlikely(!p)) 4476 goto out_overflow; 4477 len = be32_to_cpup(p); 4478 p = xdr_inline_decode(xdr, len); 4479 if (unlikely(!p)) 4480 goto out_overflow; 4481 4482 /* skip uaddr string */ 4483 p = xdr_inline_decode(xdr, 4); 4484 if (unlikely(!p)) 4485 goto out_overflow; 4486 len = be32_to_cpup(p); 4487 p = xdr_inline_decode(xdr, len); 4488 if (unlikely(!p)) 4489 goto out_overflow; 4490 return -NFSERR_CLID_INUSE; 4491 } else 4492 return nfs4_stat_to_errno(nfserr); 4493 4494 return 0; 4495out_overflow: 4496 print_overflow_msg(__func__, xdr); 4497 return -EIO; 4498} 4499 4500static int decode_setclientid_confirm(struct xdr_stream *xdr) 4501{ 4502 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 4503} 4504 4505static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 4506{ 4507 __be32 *p; 4508 int status; 4509 4510 status = decode_op_hdr(xdr, OP_WRITE); 4511 if (status) 4512 return status; 4513 4514 p = xdr_inline_decode(xdr, 16); 4515 if (unlikely(!p)) 4516 goto out_overflow; 4517 res->count = be32_to_cpup(p++); 4518 res->verf->committed = be32_to_cpup(p++); 4519 memcpy(res->verf->verifier, p, 8); 4520 return 0; 4521out_overflow: 4522 print_overflow_msg(__func__, xdr); 4523 return -EIO; 4524} 4525 4526static int decode_delegreturn(struct xdr_stream *xdr) 4527{ 4528 return decode_op_hdr(xdr, OP_DELEGRETURN); 4529} 4530 4531#if defined(CONFIG_NFS_V4_1) 4532static int decode_exchange_id(struct xdr_stream *xdr, 4533 struct nfs41_exchange_id_res *res) 4534{ 4535 __be32 *p; 4536 uint32_t dummy; 4537 char *dummy_str; 4538 int status; 4539 struct nfs_client *clp = res->client; 4540 4541 status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 4542 if (status) 4543 return status; 4544 4545 p = xdr_inline_decode(xdr, 8); 4546 if (unlikely(!p)) 4547 goto out_overflow; 4548 xdr_decode_hyper(p, &clp->cl_ex_clid); 4549 p = xdr_inline_decode(xdr, 12); 4550 if (unlikely(!p)) 4551 goto out_overflow; 4552 clp->cl_seqid = be32_to_cpup(p++); 4553 clp->cl_exchange_flags = be32_to_cpup(p++); 4554 4555 /* We ask for SP4_NONE */ 4556 dummy = be32_to_cpup(p); 4557 if (dummy != SP4_NONE) 4558 return -EIO; 4559 4560 /* Throw away minor_id */ 4561 p = xdr_inline_decode(xdr, 8); 4562 if (unlikely(!p)) 4563 goto out_overflow; 4564 4565 /* Throw away Major id */ 4566 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 4567 if (unlikely(status)) 4568 return status; 4569 4570 /* Throw away server_scope */ 4571 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 4572 if (unlikely(status)) 4573 return status; 4574 4575 /* Throw away Implementation id array */ 4576 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 4577 if (unlikely(status)) 4578 return status; 4579 4580 return 0; 4581out_overflow: 4582 print_overflow_msg(__func__, xdr); 4583 return -EIO; 4584} 4585 4586static int decode_chan_attrs(struct xdr_stream *xdr, 4587 struct nfs4_channel_attrs *attrs) 4588{ 4589 __be32 *p; 4590 u32 nr_attrs; 4591 4592 p = xdr_inline_decode(xdr, 28); 4593 if (unlikely(!p)) 4594 goto out_overflow; 4595 attrs->headerpadsz = be32_to_cpup(p++); 4596 attrs->max_rqst_sz = be32_to_cpup(p++); 4597 attrs->max_resp_sz = be32_to_cpup(p++); 4598 attrs->max_resp_sz_cached = be32_to_cpup(p++); 4599 attrs->max_ops = be32_to_cpup(p++); 4600 attrs->max_reqs = be32_to_cpup(p++); 4601 nr_attrs = be32_to_cpup(p); 4602 if (unlikely(nr_attrs > 1)) { 4603 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n", 4604 __func__, nr_attrs); 4605 return -EINVAL; 4606 } 4607 if (nr_attrs == 1) { 4608 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 4609 if (unlikely(!p)) 4610 goto out_overflow; 4611 } 4612 return 0; 4613out_overflow: 4614 print_overflow_msg(__func__, xdr); 4615 return -EIO; 4616} 4617 4618static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 4619{ 4620 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 4621} 4622 4623static int decode_create_session(struct xdr_stream *xdr, 4624 struct nfs41_create_session_res *res) 4625{ 4626 __be32 *p; 4627 int status; 4628 struct nfs_client *clp = res->client; 4629 struct nfs4_session *session = clp->cl_session; 4630 4631 status = decode_op_hdr(xdr, OP_CREATE_SESSION); 4632 if (!status) 4633 status = decode_sessionid(xdr, &session->sess_id); 4634 if (unlikely(status)) 4635 return status; 4636 4637 /* seqid, flags */ 4638 p = xdr_inline_decode(xdr, 8); 4639 if (unlikely(!p)) 4640 goto out_overflow; 4641 clp->cl_seqid = be32_to_cpup(p++); 4642 session->flags = be32_to_cpup(p); 4643 4644 /* Channel attributes */ 4645 status = decode_chan_attrs(xdr, &session->fc_attrs); 4646 if (!status) 4647 status = decode_chan_attrs(xdr, &session->bc_attrs); 4648 return status; 4649out_overflow: 4650 print_overflow_msg(__func__, xdr); 4651 return -EIO; 4652} 4653 4654static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 4655{ 4656 return decode_op_hdr(xdr, OP_DESTROY_SESSION); 4657} 4658 4659static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 4660{ 4661 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 4662} 4663#endif /* CONFIG_NFS_V4_1 */ 4664 4665static int decode_sequence(struct xdr_stream *xdr, 4666 struct nfs4_sequence_res *res, 4667 struct rpc_rqst *rqstp) 4668{ 4669#if defined(CONFIG_NFS_V4_1) 4670 struct nfs4_slot *slot; 4671 struct nfs4_sessionid id; 4672 u32 dummy; 4673 int status; 4674 __be32 *p; 4675 4676 if (!res->sr_session) 4677 return 0; 4678 4679 status = decode_op_hdr(xdr, OP_SEQUENCE); 4680 if (!status) 4681 status = decode_sessionid(xdr, &id); 4682 if (unlikely(status)) 4683 goto out_err; 4684 4685 /* 4686 * If the server returns different values for sessionID, slotID or 4687 * sequence number, the server is looney tunes. 4688 */ 4689 status = -EREMOTEIO; 4690 4691 if (memcmp(id.data, res->sr_session->sess_id.data, 4692 NFS4_MAX_SESSIONID_LEN)) { 4693 dprintk("%s Invalid session id\n", __func__); 4694 goto out_err; 4695 } 4696 4697 p = xdr_inline_decode(xdr, 20); 4698 if (unlikely(!p)) 4699 goto out_overflow; 4700 4701 /* seqid */ 4702 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid]; 4703 dummy = be32_to_cpup(p++); 4704 if (dummy != slot->seq_nr) { 4705 dprintk("%s Invalid sequence number\n", __func__); 4706 goto out_err; 4707 } 4708 /* slot id */ 4709 dummy = be32_to_cpup(p++); 4710 if (dummy != res->sr_slotid) { 4711 dprintk("%s Invalid slot id\n", __func__); 4712 goto out_err; 4713 } 4714 /* highest slot id - currently not processed */ 4715 dummy = be32_to_cpup(p++); 4716 /* target highest slot id - currently not processed */ 4717 dummy = be32_to_cpup(p++); 4718 /* result flags */ 4719 res->sr_status_flags = be32_to_cpup(p); 4720 status = 0; 4721out_err: 4722 res->sr_status = status; 4723 return status; 4724out_overflow: 4725 print_overflow_msg(__func__, xdr); 4726 status = -EIO; 4727 goto out_err; 4728#else /* CONFIG_NFS_V4_1 */ 4729 return 0; 4730#endif /* CONFIG_NFS_V4_1 */ 4731} 4732 4733/* 4734 * END OF "GENERIC" DECODE ROUTINES. 4735 */ 4736 4737/* 4738 * Decode OPEN_DOWNGRADE response 4739 */ 4740static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) 4741{ 4742 struct xdr_stream xdr; 4743 struct compound_hdr hdr; 4744 int status; 4745 4746 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4747 status = decode_compound_hdr(&xdr, &hdr); 4748 if (status) 4749 goto out; 4750 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4751 if (status) 4752 goto out; 4753 status = decode_putfh(&xdr); 4754 if (status) 4755 goto out; 4756 status = decode_open_downgrade(&xdr, res); 4757 if (status != 0) 4758 goto out; 4759 decode_getfattr(&xdr, res->fattr, res->server, 4760 !RPC_IS_ASYNC(rqstp->rq_task)); 4761out: 4762 return status; 4763} 4764 4765/* 4766 * Decode ACCESS response 4767 */ 4768static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res) 4769{ 4770 struct xdr_stream xdr; 4771 struct compound_hdr hdr; 4772 int status; 4773 4774 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4775 status = decode_compound_hdr(&xdr, &hdr); 4776 if (status) 4777 goto out; 4778 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4779 if (status) 4780 goto out; 4781 status = decode_putfh(&xdr); 4782 if (status != 0) 4783 goto out; 4784 status = decode_access(&xdr, res); 4785 if (status != 0) 4786 goto out; 4787 decode_getfattr(&xdr, res->fattr, res->server, 4788 !RPC_IS_ASYNC(rqstp->rq_task)); 4789out: 4790 return status; 4791} 4792 4793/* 4794 * Decode LOOKUP response 4795 */ 4796static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) 4797{ 4798 struct xdr_stream xdr; 4799 struct compound_hdr hdr; 4800 int status; 4801 4802 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4803 status = decode_compound_hdr(&xdr, &hdr); 4804 if (status) 4805 goto out; 4806 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4807 if (status) 4808 goto out; 4809 if ((status = decode_putfh(&xdr)) != 0) 4810 goto out; 4811 if ((status = decode_lookup(&xdr)) != 0) 4812 goto out; 4813 if ((status = decode_getfh(&xdr, res->fh)) != 0) 4814 goto out; 4815 status = decode_getfattr(&xdr, res->fattr, res->server 4816 ,!RPC_IS_ASYNC(rqstp->rq_task)); 4817out: 4818 return status; 4819} 4820 4821/* 4822 * Decode LOOKUP_ROOT response 4823 */ 4824static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) 4825{ 4826 struct xdr_stream xdr; 4827 struct compound_hdr hdr; 4828 int status; 4829 4830 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4831 status = decode_compound_hdr(&xdr, &hdr); 4832 if (status) 4833 goto out; 4834 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4835 if (status) 4836 goto out; 4837 if ((status = decode_putrootfh(&xdr)) != 0) 4838 goto out; 4839 if ((status = decode_getfh(&xdr, res->fh)) == 0) 4840 status = decode_getfattr(&xdr, res->fattr, res->server, 4841 !RPC_IS_ASYNC(rqstp->rq_task)); 4842out: 4843 return status; 4844} 4845 4846/* 4847 * Decode REMOVE response 4848 */ 4849static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res) 4850{ 4851 struct xdr_stream xdr; 4852 struct compound_hdr hdr; 4853 int status; 4854 4855 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4856 status = decode_compound_hdr(&xdr, &hdr); 4857 if (status) 4858 goto out; 4859 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4860 if (status) 4861 goto out; 4862 if ((status = decode_putfh(&xdr)) != 0) 4863 goto out; 4864 if ((status = decode_remove(&xdr, &res->cinfo)) != 0) 4865 goto out; 4866 decode_getfattr(&xdr, res->dir_attr, res->server, 4867 !RPC_IS_ASYNC(rqstp->rq_task)); 4868out: 4869 return status; 4870} 4871 4872/* 4873 * Decode RENAME response 4874 */ 4875static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res) 4876{ 4877 struct xdr_stream xdr; 4878 struct compound_hdr hdr; 4879 int status; 4880 4881 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4882 status = decode_compound_hdr(&xdr, &hdr); 4883 if (status) 4884 goto out; 4885 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4886 if (status) 4887 goto out; 4888 if ((status = decode_putfh(&xdr)) != 0) 4889 goto out; 4890 if ((status = decode_savefh(&xdr)) != 0) 4891 goto out; 4892 if ((status = decode_putfh(&xdr)) != 0) 4893 goto out; 4894 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) 4895 goto out; 4896 /* Current FH is target directory */ 4897 if (decode_getfattr(&xdr, res->new_fattr, res->server, 4898 !RPC_IS_ASYNC(rqstp->rq_task)) != 0) 4899 goto out; 4900 if ((status = decode_restorefh(&xdr)) != 0) 4901 goto out; 4902 decode_getfattr(&xdr, res->old_fattr, res->server, 4903 !RPC_IS_ASYNC(rqstp->rq_task)); 4904out: 4905 return status; 4906} 4907 4908/* 4909 * Decode LINK response 4910 */ 4911static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res) 4912{ 4913 struct xdr_stream xdr; 4914 struct compound_hdr hdr; 4915 int status; 4916 4917 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4918 status = decode_compound_hdr(&xdr, &hdr); 4919 if (status) 4920 goto out; 4921 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4922 if (status) 4923 goto out; 4924 if ((status = decode_putfh(&xdr)) != 0) 4925 goto out; 4926 if ((status = decode_savefh(&xdr)) != 0) 4927 goto out; 4928 if ((status = decode_putfh(&xdr)) != 0) 4929 goto out; 4930 if ((status = decode_link(&xdr, &res->cinfo)) != 0) 4931 goto out; 4932 /* 4933 * Note order: OP_LINK leaves the directory as the current 4934 * filehandle. 4935 */ 4936 if (decode_getfattr(&xdr, res->dir_attr, res->server, 4937 !RPC_IS_ASYNC(rqstp->rq_task)) != 0) 4938 goto out; 4939 if ((status = decode_restorefh(&xdr)) != 0) 4940 goto out; 4941 decode_getfattr(&xdr, res->fattr, res->server, 4942 !RPC_IS_ASYNC(rqstp->rq_task)); 4943out: 4944 return status; 4945} 4946 4947/* 4948 * Decode CREATE response 4949 */ 4950static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) 4951{ 4952 struct xdr_stream xdr; 4953 struct compound_hdr hdr; 4954 int status; 4955 4956 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 4957 status = decode_compound_hdr(&xdr, &hdr); 4958 if (status) 4959 goto out; 4960 status = decode_sequence(&xdr, &res->seq_res, rqstp); 4961 if (status) 4962 goto out; 4963 if ((status = decode_putfh(&xdr)) != 0) 4964 goto out; 4965 if ((status = decode_savefh(&xdr)) != 0) 4966 goto out; 4967 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) 4968 goto out; 4969 if ((status = decode_getfh(&xdr, res->fh)) != 0) 4970 goto out; 4971 if (decode_getfattr(&xdr, res->fattr, res->server, 4972 !RPC_IS_ASYNC(rqstp->rq_task)) != 0) 4973 goto out; 4974 if ((status = decode_restorefh(&xdr)) != 0) 4975 goto out; 4976 decode_getfattr(&xdr, res->dir_fattr, res->server, 4977 !RPC_IS_ASYNC(rqstp->rq_task)); 4978out: 4979 return status; 4980} 4981 4982/* 4983 * Decode SYMLINK response 4984 */ 4985static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) 4986{ 4987 return nfs4_xdr_dec_create(rqstp, p, res); 4988} 4989 4990/* 4991 * Decode GETATTR response 4992 */ 4993static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res) 4994{ 4995 struct xdr_stream xdr; 4996 struct compound_hdr hdr; 4997 int status; 4998 4999 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5000 status = decode_compound_hdr(&xdr, &hdr); 5001 if (status) 5002 goto out; 5003 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5004 if (status) 5005 goto out; 5006 status = decode_putfh(&xdr); 5007 if (status) 5008 goto out; 5009 status = decode_getfattr(&xdr, res->fattr, res->server, 5010 !RPC_IS_ASYNC(rqstp->rq_task)); 5011out: 5012 return status; 5013} 5014 5015/* 5016 * Encode an SETACL request 5017 */ 5018static int 5019nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args) 5020{ 5021 struct xdr_stream xdr; 5022 struct compound_hdr hdr = { 5023 .minorversion = nfs4_xdr_minorversion(&args->seq_args), 5024 }; 5025 int status; 5026 5027 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 5028 encode_compound_hdr(&xdr, req, &hdr); 5029 encode_sequence(&xdr, &args->seq_args, &hdr); 5030 encode_putfh(&xdr, args->fh, &hdr); 5031 status = encode_setacl(&xdr, args, &hdr); 5032 encode_nops(&hdr); 5033 return status; 5034} 5035 5036/* 5037 * Decode SETACL response 5038 */ 5039static int 5040nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, 5041 struct nfs_setaclres *res) 5042{ 5043 struct xdr_stream xdr; 5044 struct compound_hdr hdr; 5045 int status; 5046 5047 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5048 status = decode_compound_hdr(&xdr, &hdr); 5049 if (status) 5050 goto out; 5051 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5052 if (status) 5053 goto out; 5054 status = decode_putfh(&xdr); 5055 if (status) 5056 goto out; 5057 status = decode_setattr(&xdr); 5058out: 5059 return status; 5060} 5061 5062/* 5063 * Decode GETACL response 5064 */ 5065static int 5066nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, 5067 struct nfs_getaclres *res) 5068{ 5069 struct xdr_stream xdr; 5070 struct compound_hdr hdr; 5071 int status; 5072 5073 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5074 status = decode_compound_hdr(&xdr, &hdr); 5075 if (status) 5076 goto out; 5077 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5078 if (status) 5079 goto out; 5080 status = decode_putfh(&xdr); 5081 if (status) 5082 goto out; 5083 status = decode_getacl(&xdr, rqstp, &res->acl_len); 5084 5085out: 5086 return status; 5087} 5088 5089/* 5090 * Decode CLOSE response 5091 */ 5092static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) 5093{ 5094 struct xdr_stream xdr; 5095 struct compound_hdr hdr; 5096 int status; 5097 5098 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5099 status = decode_compound_hdr(&xdr, &hdr); 5100 if (status) 5101 goto out; 5102 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5103 if (status) 5104 goto out; 5105 status = decode_putfh(&xdr); 5106 if (status) 5107 goto out; 5108 status = decode_close(&xdr, res); 5109 if (status != 0) 5110 goto out; 5111 /* 5112 * Note: Server may do delete on close for this file 5113 * in which case the getattr call will fail with 5114 * an ESTALE error. Shouldn't be a problem, 5115 * though, since fattr->valid will remain unset. 5116 */ 5117 decode_getfattr(&xdr, res->fattr, res->server, 5118 !RPC_IS_ASYNC(rqstp->rq_task)); 5119out: 5120 return status; 5121} 5122 5123/* 5124 * Decode OPEN response 5125 */ 5126static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) 5127{ 5128 struct xdr_stream xdr; 5129 struct compound_hdr hdr; 5130 int status; 5131 5132 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5133 status = decode_compound_hdr(&xdr, &hdr); 5134 if (status) 5135 goto out; 5136 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5137 if (status) 5138 goto out; 5139 status = decode_putfh(&xdr); 5140 if (status) 5141 goto out; 5142 status = decode_savefh(&xdr); 5143 if (status) 5144 goto out; 5145 status = decode_open(&xdr, res); 5146 if (status) 5147 goto out; 5148 if (decode_getfh(&xdr, &res->fh) != 0) 5149 goto out; 5150 if (decode_getfattr(&xdr, res->f_attr, res->server, 5151 !RPC_IS_ASYNC(rqstp->rq_task)) != 0) 5152 goto out; 5153 if (decode_restorefh(&xdr) != 0) 5154 goto out; 5155 decode_getfattr(&xdr, res->dir_attr, res->server, 5156 !RPC_IS_ASYNC(rqstp->rq_task)); 5157out: 5158 return status; 5159} 5160 5161/* 5162 * Decode OPEN_CONFIRM response 5163 */ 5164static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res) 5165{ 5166 struct xdr_stream xdr; 5167 struct compound_hdr hdr; 5168 int status; 5169 5170 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5171 status = decode_compound_hdr(&xdr, &hdr); 5172 if (status) 5173 goto out; 5174 status = decode_putfh(&xdr); 5175 if (status) 5176 goto out; 5177 status = decode_open_confirm(&xdr, res); 5178out: 5179 return status; 5180} 5181 5182/* 5183 * Decode OPEN response 5184 */ 5185static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) 5186{ 5187 struct xdr_stream xdr; 5188 struct compound_hdr hdr; 5189 int status; 5190 5191 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5192 status = decode_compound_hdr(&xdr, &hdr); 5193 if (status) 5194 goto out; 5195 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5196 if (status) 5197 goto out; 5198 status = decode_putfh(&xdr); 5199 if (status) 5200 goto out; 5201 status = decode_open(&xdr, res); 5202 if (status) 5203 goto out; 5204 decode_getfattr(&xdr, res->f_attr, res->server, 5205 !RPC_IS_ASYNC(rqstp->rq_task)); 5206out: 5207 return status; 5208} 5209 5210/* 5211 * Decode SETATTR response 5212 */ 5213static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res) 5214{ 5215 struct xdr_stream xdr; 5216 struct compound_hdr hdr; 5217 int status; 5218 5219 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5220 status = decode_compound_hdr(&xdr, &hdr); 5221 if (status) 5222 goto out; 5223 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5224 if (status) 5225 goto out; 5226 status = decode_putfh(&xdr); 5227 if (status) 5228 goto out; 5229 status = decode_setattr(&xdr); 5230 if (status) 5231 goto out; 5232 decode_getfattr(&xdr, res->fattr, res->server, 5233 !RPC_IS_ASYNC(rqstp->rq_task)); 5234out: 5235 return status; 5236} 5237 5238/* 5239 * Decode LOCK response 5240 */ 5241static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res) 5242{ 5243 struct xdr_stream xdr; 5244 struct compound_hdr hdr; 5245 int status; 5246 5247 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5248 status = decode_compound_hdr(&xdr, &hdr); 5249 if (status) 5250 goto out; 5251 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5252 if (status) 5253 goto out; 5254 status = decode_putfh(&xdr); 5255 if (status) 5256 goto out; 5257 status = decode_lock(&xdr, res); 5258out: 5259 return status; 5260} 5261 5262/* 5263 * Decode LOCKT response 5264 */ 5265static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res) 5266{ 5267 struct xdr_stream xdr; 5268 struct compound_hdr hdr; 5269 int status; 5270 5271 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5272 status = decode_compound_hdr(&xdr, &hdr); 5273 if (status) 5274 goto out; 5275 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5276 if (status) 5277 goto out; 5278 status = decode_putfh(&xdr); 5279 if (status) 5280 goto out; 5281 status = decode_lockt(&xdr, res); 5282out: 5283 return status; 5284} 5285 5286/* 5287 * Decode LOCKU response 5288 */ 5289static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res) 5290{ 5291 struct xdr_stream xdr; 5292 struct compound_hdr hdr; 5293 int status; 5294 5295 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5296 status = decode_compound_hdr(&xdr, &hdr); 5297 if (status) 5298 goto out; 5299 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5300 if (status) 5301 goto out; 5302 status = decode_putfh(&xdr); 5303 if (status) 5304 goto out; 5305 status = decode_locku(&xdr, res); 5306out: 5307 return status; 5308} 5309 5310static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, __be32 *p, void *dummy) 5311{ 5312 struct xdr_stream xdr; 5313 struct compound_hdr hdr; 5314 int status; 5315 5316 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5317 status = decode_compound_hdr(&xdr, &hdr); 5318 if (!status) 5319 status = decode_release_lockowner(&xdr); 5320 return status; 5321} 5322 5323/* 5324 * Decode READLINK response 5325 */ 5326static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, 5327 struct nfs4_readlink_res *res) 5328{ 5329 struct xdr_stream xdr; 5330 struct compound_hdr hdr; 5331 int status; 5332 5333 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5334 status = decode_compound_hdr(&xdr, &hdr); 5335 if (status) 5336 goto out; 5337 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5338 if (status) 5339 goto out; 5340 status = decode_putfh(&xdr); 5341 if (status) 5342 goto out; 5343 status = decode_readlink(&xdr, rqstp); 5344out: 5345 return status; 5346} 5347 5348/* 5349 * Decode READDIR response 5350 */ 5351static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res) 5352{ 5353 struct xdr_stream xdr; 5354 struct compound_hdr hdr; 5355 int status; 5356 5357 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5358 status = decode_compound_hdr(&xdr, &hdr); 5359 if (status) 5360 goto out; 5361 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5362 if (status) 5363 goto out; 5364 status = decode_putfh(&xdr); 5365 if (status) 5366 goto out; 5367 status = decode_readdir(&xdr, rqstp, res); 5368out: 5369 return status; 5370} 5371 5372/* 5373 * Decode Read response 5374 */ 5375static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res) 5376{ 5377 struct xdr_stream xdr; 5378 struct compound_hdr hdr; 5379 int status; 5380 5381 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5382 status = decode_compound_hdr(&xdr, &hdr); 5383 if (status) 5384 goto out; 5385 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5386 if (status) 5387 goto out; 5388 status = decode_putfh(&xdr); 5389 if (status) 5390 goto out; 5391 status = decode_read(&xdr, rqstp, res); 5392 if (!status) 5393 status = res->count; 5394out: 5395 return status; 5396} 5397 5398/* 5399 * Decode WRITE response 5400 */ 5401static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) 5402{ 5403 struct xdr_stream xdr; 5404 struct compound_hdr hdr; 5405 int status; 5406 5407 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5408 status = decode_compound_hdr(&xdr, &hdr); 5409 if (status) 5410 goto out; 5411 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5412 if (status) 5413 goto out; 5414 status = decode_putfh(&xdr); 5415 if (status) 5416 goto out; 5417 status = decode_write(&xdr, res); 5418 if (status) 5419 goto out; 5420 decode_getfattr(&xdr, res->fattr, res->server, 5421 !RPC_IS_ASYNC(rqstp->rq_task)); 5422 if (!status) 5423 status = res->count; 5424out: 5425 return status; 5426} 5427 5428/* 5429 * Decode COMMIT response 5430 */ 5431static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) 5432{ 5433 struct xdr_stream xdr; 5434 struct compound_hdr hdr; 5435 int status; 5436 5437 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5438 status = decode_compound_hdr(&xdr, &hdr); 5439 if (status) 5440 goto out; 5441 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5442 if (status) 5443 goto out; 5444 status = decode_putfh(&xdr); 5445 if (status) 5446 goto out; 5447 status = decode_commit(&xdr, res); 5448 if (status) 5449 goto out; 5450 decode_getfattr(&xdr, res->fattr, res->server, 5451 !RPC_IS_ASYNC(rqstp->rq_task)); 5452out: 5453 return status; 5454} 5455 5456/* 5457 * Decode FSINFO response 5458 */ 5459static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, 5460 struct nfs4_fsinfo_res *res) 5461{ 5462 struct xdr_stream xdr; 5463 struct compound_hdr hdr; 5464 int status; 5465 5466 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5467 status = decode_compound_hdr(&xdr, &hdr); 5468 if (!status) 5469 status = decode_sequence(&xdr, &res->seq_res, req); 5470 if (!status) 5471 status = decode_putfh(&xdr); 5472 if (!status) 5473 status = decode_fsinfo(&xdr, res->fsinfo); 5474 return status; 5475} 5476 5477/* 5478 * Decode PATHCONF response 5479 */ 5480static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, 5481 struct nfs4_pathconf_res *res) 5482{ 5483 struct xdr_stream xdr; 5484 struct compound_hdr hdr; 5485 int status; 5486 5487 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5488 status = decode_compound_hdr(&xdr, &hdr); 5489 if (!status) 5490 status = decode_sequence(&xdr, &res->seq_res, req); 5491 if (!status) 5492 status = decode_putfh(&xdr); 5493 if (!status) 5494 status = decode_pathconf(&xdr, res->pathconf); 5495 return status; 5496} 5497 5498/* 5499 * Decode STATFS response 5500 */ 5501static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, 5502 struct nfs4_statfs_res *res) 5503{ 5504 struct xdr_stream xdr; 5505 struct compound_hdr hdr; 5506 int status; 5507 5508 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5509 status = decode_compound_hdr(&xdr, &hdr); 5510 if (!status) 5511 status = decode_sequence(&xdr, &res->seq_res, req); 5512 if (!status) 5513 status = decode_putfh(&xdr); 5514 if (!status) 5515 status = decode_statfs(&xdr, res->fsstat); 5516 return status; 5517} 5518 5519/* 5520 * Decode GETATTR_BITMAP response 5521 */ 5522static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res) 5523{ 5524 struct xdr_stream xdr; 5525 struct compound_hdr hdr; 5526 int status; 5527 5528 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5529 status = decode_compound_hdr(&xdr, &hdr); 5530 if (status) 5531 goto out; 5532 status = decode_sequence(&xdr, &res->seq_res, req); 5533 if (status) 5534 goto out; 5535 if ((status = decode_putfh(&xdr)) != 0) 5536 goto out; 5537 status = decode_server_caps(&xdr, res); 5538out: 5539 return status; 5540} 5541 5542/* 5543 * Decode RENEW response 5544 */ 5545static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy) 5546{ 5547 struct xdr_stream xdr; 5548 struct compound_hdr hdr; 5549 int status; 5550 5551 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5552 status = decode_compound_hdr(&xdr, &hdr); 5553 if (!status) 5554 status = decode_renew(&xdr); 5555 return status; 5556} 5557 5558/* 5559 * Decode SETCLIENTID response 5560 */ 5561static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p, 5562 struct nfs4_setclientid_res *res) 5563{ 5564 struct xdr_stream xdr; 5565 struct compound_hdr hdr; 5566 int status; 5567 5568 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5569 status = decode_compound_hdr(&xdr, &hdr); 5570 if (!status) 5571 status = decode_setclientid(&xdr, res); 5572 return status; 5573} 5574 5575/* 5576 * Decode SETCLIENTID_CONFIRM response 5577 */ 5578static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo) 5579{ 5580 struct xdr_stream xdr; 5581 struct compound_hdr hdr; 5582 int status; 5583 5584 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5585 status = decode_compound_hdr(&xdr, &hdr); 5586 if (!status) 5587 status = decode_setclientid_confirm(&xdr); 5588 if (!status) 5589 status = decode_putrootfh(&xdr); 5590 if (!status) 5591 status = decode_fsinfo(&xdr, fsinfo); 5592 return status; 5593} 5594 5595/* 5596 * Decode DELEGRETURN response 5597 */ 5598static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res) 5599{ 5600 struct xdr_stream xdr; 5601 struct compound_hdr hdr; 5602 int status; 5603 5604 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5605 status = decode_compound_hdr(&xdr, &hdr); 5606 if (status) 5607 goto out; 5608 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5609 if (status) 5610 goto out; 5611 status = decode_putfh(&xdr); 5612 if (status != 0) 5613 goto out; 5614 status = decode_delegreturn(&xdr); 5615 if (status != 0) 5616 goto out; 5617 decode_getfattr(&xdr, res->fattr, res->server, 5618 !RPC_IS_ASYNC(rqstp->rq_task)); 5619out: 5620 return status; 5621} 5622 5623/* 5624 * Decode FS_LOCATIONS response 5625 */ 5626static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, 5627 struct nfs4_fs_locations_res *res) 5628{ 5629 struct xdr_stream xdr; 5630 struct compound_hdr hdr; 5631 int status; 5632 5633 xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 5634 status = decode_compound_hdr(&xdr, &hdr); 5635 if (status) 5636 goto out; 5637 status = decode_sequence(&xdr, &res->seq_res, req); 5638 if (status) 5639 goto out; 5640 if ((status = decode_putfh(&xdr)) != 0) 5641 goto out; 5642 if ((status = decode_lookup(&xdr)) != 0) 5643 goto out; 5644 xdr_enter_page(&xdr, PAGE_SIZE); 5645 status = decode_getfattr(&xdr, &res->fs_locations->fattr, 5646 res->fs_locations->server, 5647 !RPC_IS_ASYNC(req->rq_task)); 5648out: 5649 return status; 5650} 5651 5652#if defined(CONFIG_NFS_V4_1) 5653/* 5654 * Decode EXCHANGE_ID response 5655 */ 5656static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p, 5657 void *res) 5658{ 5659 struct xdr_stream xdr; 5660 struct compound_hdr hdr; 5661 int status; 5662 5663 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5664 status = decode_compound_hdr(&xdr, &hdr); 5665 if (!status) 5666 status = decode_exchange_id(&xdr, res); 5667 return status; 5668} 5669 5670/* 5671 * Decode CREATE_SESSION response 5672 */ 5673static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p, 5674 struct nfs41_create_session_res *res) 5675{ 5676 struct xdr_stream xdr; 5677 struct compound_hdr hdr; 5678 int status; 5679 5680 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5681 status = decode_compound_hdr(&xdr, &hdr); 5682 if (!status) 5683 status = decode_create_session(&xdr, res); 5684 return status; 5685} 5686 5687/* 5688 * Decode DESTROY_SESSION response 5689 */ 5690static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p, 5691 void *dummy) 5692{ 5693 struct xdr_stream xdr; 5694 struct compound_hdr hdr; 5695 int status; 5696 5697 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5698 status = decode_compound_hdr(&xdr, &hdr); 5699 if (!status) 5700 status = decode_destroy_session(&xdr, dummy); 5701 return status; 5702} 5703 5704/* 5705 * Decode SEQUENCE response 5706 */ 5707static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p, 5708 struct nfs4_sequence_res *res) 5709{ 5710 struct xdr_stream xdr; 5711 struct compound_hdr hdr; 5712 int status; 5713 5714 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5715 status = decode_compound_hdr(&xdr, &hdr); 5716 if (!status) 5717 status = decode_sequence(&xdr, res, rqstp); 5718 return status; 5719} 5720 5721/* 5722 * Decode GET_LEASE_TIME response 5723 */ 5724static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p, 5725 struct nfs4_get_lease_time_res *res) 5726{ 5727 struct xdr_stream xdr; 5728 struct compound_hdr hdr; 5729 int status; 5730 5731 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5732 status = decode_compound_hdr(&xdr, &hdr); 5733 if (!status) 5734 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp); 5735 if (!status) 5736 status = decode_putrootfh(&xdr); 5737 if (!status) 5738 status = decode_fsinfo(&xdr, res->lr_fsinfo); 5739 return status; 5740} 5741 5742/* 5743 * Decode RECLAIM_COMPLETE response 5744 */ 5745static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p, 5746 struct nfs41_reclaim_complete_res *res) 5747{ 5748 struct xdr_stream xdr; 5749 struct compound_hdr hdr; 5750 int status; 5751 5752 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); 5753 status = decode_compound_hdr(&xdr, &hdr); 5754 if (!status) 5755 status = decode_sequence(&xdr, &res->seq_res, rqstp); 5756 if (!status) 5757 status = decode_reclaim_complete(&xdr, (void *)NULL); 5758 return status; 5759} 5760#endif /* CONFIG_NFS_V4_1 */ 5761 5762__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus) 5763{ 5764 uint32_t bitmap[2] = {0}; 5765 uint32_t len; 5766 5767 if (!*p++) { 5768 if (!*p) 5769 return ERR_PTR(-EAGAIN); 5770 entry->eof = 1; 5771 return ERR_PTR(-EBADCOOKIE); 5772 } 5773 5774 entry->prev_cookie = entry->cookie; 5775 p = xdr_decode_hyper(p, &entry->cookie); 5776 entry->len = ntohl(*p++); 5777 entry->name = (const char *) p; 5778 p += XDR_QUADLEN(entry->len); 5779 5780 /* 5781 * In case the server doesn't return an inode number, 5782 * we fake one here. (We don't use inode number 0, 5783 * since glibc seems to choke on it...) 5784 */ 5785 entry->ino = 1; 5786 5787 len = ntohl(*p++); /* bitmap length */ 5788 if (len-- > 0) { 5789 bitmap[0] = ntohl(*p++); 5790 if (len-- > 0) { 5791 bitmap[1] = ntohl(*p++); 5792 p += len; 5793 } 5794 } 5795 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */ 5796 if (len > 0) { 5797 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) { 5798 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 5799 /* Ignore the return value of rdattr_error for now */ 5800 p++; 5801 len--; 5802 } 5803 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID) 5804 xdr_decode_hyper(p, &entry->ino); 5805 else if (bitmap[0] == FATTR4_WORD0_FILEID) 5806 xdr_decode_hyper(p, &entry->ino); 5807 p += len; 5808 } 5809 5810 entry->eof = !p[0] && p[1]; 5811 return p; 5812} 5813 5814/* 5815 * We need to translate between nfs status return values and 5816 * the local errno values which may not be the same. 5817 */ 5818static struct { 5819 int stat; 5820 int errno; 5821} nfs_errtbl[] = { 5822 { NFS4_OK, 0 }, 5823 { NFS4ERR_PERM, -EPERM }, 5824 { NFS4ERR_NOENT, -ENOENT }, 5825 { NFS4ERR_IO, -errno_NFSERR_IO}, 5826 { NFS4ERR_NXIO, -ENXIO }, 5827 { NFS4ERR_ACCESS, -EACCES }, 5828 { NFS4ERR_EXIST, -EEXIST }, 5829 { NFS4ERR_XDEV, -EXDEV }, 5830 { NFS4ERR_NOTDIR, -ENOTDIR }, 5831 { NFS4ERR_ISDIR, -EISDIR }, 5832 { NFS4ERR_INVAL, -EINVAL }, 5833 { NFS4ERR_FBIG, -EFBIG }, 5834 { NFS4ERR_NOSPC, -ENOSPC }, 5835 { NFS4ERR_ROFS, -EROFS }, 5836 { NFS4ERR_MLINK, -EMLINK }, 5837 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 5838 { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 5839 { NFS4ERR_DQUOT, -EDQUOT }, 5840 { NFS4ERR_STALE, -ESTALE }, 5841 { NFS4ERR_BADHANDLE, -EBADHANDLE }, 5842 { NFS4ERR_BADOWNER, -EINVAL }, 5843 { NFS4ERR_BADNAME, -EINVAL }, 5844 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 5845 { NFS4ERR_NOTSUPP, -ENOTSUPP }, 5846 { NFS4ERR_TOOSMALL, -ETOOSMALL }, 5847 { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 5848 { NFS4ERR_BADTYPE, -EBADTYPE }, 5849 { NFS4ERR_LOCKED, -EAGAIN }, 5850 { NFS4ERR_SYMLINK, -ELOOP }, 5851 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 5852 { NFS4ERR_DEADLOCK, -EDEADLK }, 5853 { NFS4ERR_WRONGSEC, -EPERM }, 5854 { -1, -EIO } 5855}; 5856 5857/* 5858 * Convert an NFS error code to a local one. 5859 * This one is used jointly by NFSv2 and NFSv3. 5860 */ 5861static int 5862nfs4_stat_to_errno(int stat) 5863{ 5864 int i; 5865 for (i = 0; nfs_errtbl[i].stat != -1; i++) { 5866 if (nfs_errtbl[i].stat == stat) 5867 return nfs_errtbl[i].errno; 5868 } 5869 if (stat <= 10000 || stat > 10100) { 5870 /* The server is looney tunes. */ 5871 return -EREMOTEIO; 5872 } 5873 /* If we cannot translate the error, the recovery routines should 5874 * handle it. 5875 * Note: remaining NFSv4 error codes have values > 10000, so should 5876 * not conflict with native Linux error codes. 5877 */ 5878 return -stat; 5879} 5880 5881#define PROC(proc, argtype, restype) \ 5882[NFSPROC4_CLNT_##proc] = { \ 5883 .p_proc = NFSPROC4_COMPOUND, \ 5884 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ 5885 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ 5886 .p_arglen = NFS4_##argtype##_sz, \ 5887 .p_replen = NFS4_##restype##_sz, \ 5888 .p_statidx = NFSPROC4_CLNT_##proc, \ 5889 .p_name = #proc, \ 5890} 5891 5892struct rpc_procinfo nfs4_procedures[] = { 5893 PROC(READ, enc_read, dec_read), 5894 PROC(WRITE, enc_write, dec_write), 5895 PROC(COMMIT, enc_commit, dec_commit), 5896 PROC(OPEN, enc_open, dec_open), 5897 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 5898 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 5899 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 5900 PROC(CLOSE, enc_close, dec_close), 5901 PROC(SETATTR, enc_setattr, dec_setattr), 5902 PROC(FSINFO, enc_fsinfo, dec_fsinfo), 5903 PROC(RENEW, enc_renew, dec_renew), 5904 PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 5905 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 5906 PROC(LOCK, enc_lock, dec_lock), 5907 PROC(LOCKT, enc_lockt, dec_lockt), 5908 PROC(LOCKU, enc_locku, dec_locku), 5909 PROC(ACCESS, enc_access, dec_access), 5910 PROC(GETATTR, enc_getattr, dec_getattr), 5911 PROC(LOOKUP, enc_lookup, dec_lookup), 5912 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 5913 PROC(REMOVE, enc_remove, dec_remove), 5914 PROC(RENAME, enc_rename, dec_rename), 5915 PROC(LINK, enc_link, dec_link), 5916 PROC(SYMLINK, enc_symlink, dec_symlink), 5917 PROC(CREATE, enc_create, dec_create), 5918 PROC(PATHCONF, enc_pathconf, dec_pathconf), 5919 PROC(STATFS, enc_statfs, dec_statfs), 5920 PROC(READLINK, enc_readlink, dec_readlink), 5921 PROC(READDIR, enc_readdir, dec_readdir), 5922 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 5923 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 5924 PROC(GETACL, enc_getacl, dec_getacl), 5925 PROC(SETACL, enc_setacl, dec_setacl), 5926 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 5927 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 5928#if defined(CONFIG_NFS_V4_1) 5929 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 5930 PROC(CREATE_SESSION, enc_create_session, dec_create_session), 5931 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 5932 PROC(SEQUENCE, enc_sequence, dec_sequence), 5933 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 5934 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 5935#endif /* CONFIG_NFS_V4_1 */ 5936}; 5937 5938struct rpc_version nfs_version4 = { 5939 .number = 4, 5940 .nrprocs = ARRAY_SIZE(nfs4_procedures), 5941 .procs = nfs4_procedures 5942}; 5943 5944/* 5945 * Local variables: 5946 * c-basic-offset: 8 5947 * End: 5948 */ 5949