linux/fs/nfs/nfs4xdr.c
<<
>>
Prefs
   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/module.h>
  48#include <linux/utsname.h>
  49#include <linux/sunrpc/clnt.h>
  50#include <linux/sunrpc/msg_prot.h>
  51#include <linux/sunrpc/gss_api.h>
  52#include <linux/nfs.h>
  53#include <linux/nfs4.h>
  54#include <linux/nfs_fs.h>
  55
  56#include "nfs4_fs.h"
  57#include "nfs4trace.h"
  58#include "internal.h"
  59#include "nfs4idmap.h"
  60#include "nfs4session.h"
  61#include "pnfs.h"
  62#include "netns.h"
  63
  64#define NFSDBG_FACILITY         NFSDBG_XDR
  65
  66/* Mapping from NFS error code to "errno" error code. */
  67#define errno_NFSERR_IO         EIO
  68
  69struct compound_hdr;
  70static int nfs4_stat_to_errno(int);
  71static void encode_layoutget(struct xdr_stream *xdr,
  72                             const struct nfs4_layoutget_args *args,
  73                             struct compound_hdr *hdr);
  74static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  75                             struct nfs4_layoutget_res *res);
  76
  77/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  78#ifdef DEBUG
  79#define NFS4_MAXTAGLEN          20
  80#else
  81#define NFS4_MAXTAGLEN          0
  82#endif
  83
  84/* lock,open owner id:
  85 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
  86 */
  87#define pagepad_maxsz           (1)
  88#define open_owner_id_maxsz     (1 + 2 + 1 + 1 + 2)
  89#define lock_owner_id_maxsz     (1 + 1 + 4)
  90#define decode_lockowner_maxsz  (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  91#define compound_encode_hdr_maxsz       (3 + (NFS4_MAXTAGLEN >> 2))
  92#define compound_decode_hdr_maxsz       (3 + (NFS4_MAXTAGLEN >> 2))
  93#define op_encode_hdr_maxsz     (1)
  94#define op_decode_hdr_maxsz     (2)
  95#define encode_stateid_maxsz    (XDR_QUADLEN(NFS4_STATEID_SIZE))
  96#define decode_stateid_maxsz    (XDR_QUADLEN(NFS4_STATEID_SIZE))
  97#define encode_verifier_maxsz   (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  98#define decode_verifier_maxsz   (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  99#define encode_putfh_maxsz      (op_encode_hdr_maxsz + 1 + \
 100                                (NFS4_FHSIZE >> 2))
 101#define decode_putfh_maxsz      (op_decode_hdr_maxsz)
 102#define encode_putrootfh_maxsz  (op_encode_hdr_maxsz)
 103#define decode_putrootfh_maxsz  (op_decode_hdr_maxsz)
 104#define encode_getfh_maxsz      (op_encode_hdr_maxsz)
 105#define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
 106                                ((3+NFS4_FHSIZE) >> 2))
 107#define nfs4_fattr_bitmap_maxsz 4
 108#define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
 109#define nfstime4_maxsz          (3)
 110#define nfs4_name_maxsz         (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
 111#define nfs4_path_maxsz         (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
 112#define nfs4_owner_maxsz        (1 + XDR_QUADLEN(IDMAP_NAMESZ))
 113#define nfs4_group_maxsz        (1 + XDR_QUADLEN(IDMAP_NAMESZ))
 114#ifdef CONFIG_NFS_V4_SECURITY_LABEL
 115/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
 116#define nfs4_label_maxsz        (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
 117#else
 118#define nfs4_label_maxsz        0
 119#endif
 120/* We support only one layout type per file system */
 121#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
 122/* This is based on getfattr, which uses the most attributes: */
 123#define nfs4_fattr_value_maxsz  (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
 124                                3*nfstime4_maxsz + \
 125                                nfs4_owner_maxsz + \
 126                                nfs4_group_maxsz + nfs4_label_maxsz + \
 127                                 decode_mdsthreshold_maxsz))
 128#define nfs4_fattr_maxsz        (nfs4_fattr_bitmap_maxsz + \
 129                                nfs4_fattr_value_maxsz)
 130#define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
 131#define encode_attrs_maxsz      (nfs4_fattr_bitmap_maxsz + \
 132                                 1 + 2 + 1 + \
 133                                nfs4_owner_maxsz + \
 134                                nfs4_group_maxsz + \
 135                                nfs4_label_maxsz + \
 136                                1 + nfstime4_maxsz + \
 137                                1 + nfstime4_maxsz)
 138#define encode_savefh_maxsz     (op_encode_hdr_maxsz)
 139#define decode_savefh_maxsz     (op_decode_hdr_maxsz)
 140#define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
 141#define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
 142#define encode_fsinfo_maxsz     (encode_getattr_maxsz)
 143/* The 5 accounts for the PNFS attributes, and assumes that at most three
 144 * layout types will be returned.
 145 */
 146#define decode_fsinfo_maxsz     (op_decode_hdr_maxsz + \
 147                                 nfs4_fattr_bitmap_maxsz + 1 + \
 148                                 1 /* lease time */ + \
 149                                 2 /* max filesize */ + \
 150                                 2 /* max read */ + \
 151                                 2 /* max write */ + \
 152                                 nfstime4_maxsz /* time delta */ + \
 153                                 5 /* fs layout types */ + \
 154                                 1 /* layout blksize */ + \
 155                                 1 /* clone blksize */ + \
 156                                 1 /* change attr type */ + \
 157                                 1 /* xattr support */)
 158#define encode_renew_maxsz      (op_encode_hdr_maxsz + 3)
 159#define decode_renew_maxsz      (op_decode_hdr_maxsz)
 160#define encode_setclientid_maxsz \
 161                                (op_encode_hdr_maxsz + \
 162                                XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
 163                                /* client name */ \
 164                                1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
 165                                1 /* sc_prog */ + \
 166                                1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
 167                                1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
 168                                1) /* sc_cb_ident */
 169#define decode_setclientid_maxsz \
 170                                (op_decode_hdr_maxsz + \
 171                                2 /* clientid */ + \
 172                                XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
 173                                1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
 174                                1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
 175#define encode_setclientid_confirm_maxsz \
 176                                (op_encode_hdr_maxsz + \
 177                                3 + (NFS4_VERIFIER_SIZE >> 2))
 178#define decode_setclientid_confirm_maxsz \
 179                                (op_decode_hdr_maxsz)
 180#define encode_lookup_maxsz     (op_encode_hdr_maxsz + nfs4_name_maxsz)
 181#define decode_lookup_maxsz     (op_decode_hdr_maxsz)
 182#define encode_lookupp_maxsz    (op_encode_hdr_maxsz)
 183#define decode_lookupp_maxsz    (op_decode_hdr_maxsz)
 184#define encode_share_access_maxsz \
 185                                (2)
 186#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
 187#define encode_opentype_maxsz   (1 + encode_createmode_maxsz)
 188#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
 189#define encode_open_maxsz       (op_encode_hdr_maxsz + \
 190                                2 + encode_share_access_maxsz + 2 + \
 191                                open_owner_id_maxsz + \
 192                                encode_opentype_maxsz + \
 193                                encode_claim_null_maxsz)
 194#define decode_space_limit_maxsz        (3)
 195#define decode_ace_maxsz        (3 + nfs4_owner_maxsz)
 196#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
 197                                decode_space_limit_maxsz + \
 198                                decode_ace_maxsz)
 199#define decode_change_info_maxsz        (5)
 200#define decode_open_maxsz       (op_decode_hdr_maxsz + \
 201                                decode_stateid_maxsz + \
 202                                decode_change_info_maxsz + 1 + \
 203                                nfs4_fattr_bitmap_maxsz + \
 204                                decode_delegation_maxsz)
 205#define encode_open_confirm_maxsz \
 206                                (op_encode_hdr_maxsz + \
 207                                 encode_stateid_maxsz + 1)
 208#define decode_open_confirm_maxsz \
 209                                (op_decode_hdr_maxsz + \
 210                                 decode_stateid_maxsz)
 211#define encode_open_downgrade_maxsz \
 212                                (op_encode_hdr_maxsz + \
 213                                 encode_stateid_maxsz + 1 + \
 214                                 encode_share_access_maxsz)
 215#define decode_open_downgrade_maxsz \
 216                                (op_decode_hdr_maxsz + \
 217                                 decode_stateid_maxsz)
 218#define encode_close_maxsz      (op_encode_hdr_maxsz + \
 219                                 1 + encode_stateid_maxsz)
 220#define decode_close_maxsz      (op_decode_hdr_maxsz + \
 221                                 decode_stateid_maxsz)
 222#define encode_setattr_maxsz    (op_encode_hdr_maxsz + \
 223                                 encode_stateid_maxsz + \
 224                                 encode_attrs_maxsz)
 225#define decode_setattr_maxsz    (op_decode_hdr_maxsz + \
 226                                 nfs4_fattr_bitmap_maxsz)
 227#define encode_read_maxsz       (op_encode_hdr_maxsz + \
 228                                 encode_stateid_maxsz + 3)
 229#define decode_read_maxsz       (op_decode_hdr_maxsz + 2 + pagepad_maxsz)
 230#define encode_readdir_maxsz    (op_encode_hdr_maxsz + \
 231                                 2 + encode_verifier_maxsz + 5 + \
 232                                nfs4_label_maxsz)
 233#define decode_readdir_maxsz    (op_decode_hdr_maxsz + \
 234                                 decode_verifier_maxsz + pagepad_maxsz)
 235#define encode_readlink_maxsz   (op_encode_hdr_maxsz)
 236#define decode_readlink_maxsz   (op_decode_hdr_maxsz + 1 + pagepad_maxsz)
 237#define encode_write_maxsz      (op_encode_hdr_maxsz + \
 238                                 encode_stateid_maxsz + 4)
 239#define decode_write_maxsz      (op_decode_hdr_maxsz + \
 240                                 2 + decode_verifier_maxsz)
 241#define encode_commit_maxsz     (op_encode_hdr_maxsz + 3)
 242#define decode_commit_maxsz     (op_decode_hdr_maxsz + \
 243                                 decode_verifier_maxsz)
 244#define encode_remove_maxsz     (op_encode_hdr_maxsz + \
 245                                nfs4_name_maxsz)
 246#define decode_remove_maxsz     (op_decode_hdr_maxsz + \
 247                                 decode_change_info_maxsz)
 248#define encode_rename_maxsz     (op_encode_hdr_maxsz + \
 249                                2 * nfs4_name_maxsz)
 250#define decode_rename_maxsz     (op_decode_hdr_maxsz + \
 251                                 decode_change_info_maxsz + \
 252                                 decode_change_info_maxsz)
 253#define encode_link_maxsz       (op_encode_hdr_maxsz + \
 254                                nfs4_name_maxsz)
 255#define decode_link_maxsz       (op_decode_hdr_maxsz + decode_change_info_maxsz)
 256#define encode_lockowner_maxsz  (7)
 257#define encode_lock_maxsz       (op_encode_hdr_maxsz + \
 258                                 7 + \
 259                                 1 + encode_stateid_maxsz + 1 + \
 260                                 encode_lockowner_maxsz)
 261#define decode_lock_denied_maxsz \
 262                                (8 + decode_lockowner_maxsz)
 263#define decode_lock_maxsz       (op_decode_hdr_maxsz + \
 264                                 decode_lock_denied_maxsz)
 265#define encode_lockt_maxsz      (op_encode_hdr_maxsz + 5 + \
 266                                encode_lockowner_maxsz)
 267#define decode_lockt_maxsz      (op_decode_hdr_maxsz + \
 268                                 decode_lock_denied_maxsz)
 269#define encode_locku_maxsz      (op_encode_hdr_maxsz + 3 + \
 270                                 encode_stateid_maxsz + \
 271                                 4)
 272#define decode_locku_maxsz      (op_decode_hdr_maxsz + \
 273                                 decode_stateid_maxsz)
 274#define encode_release_lockowner_maxsz \
 275                                (op_encode_hdr_maxsz + \
 276                                 encode_lockowner_maxsz)
 277#define decode_release_lockowner_maxsz \
 278                                (op_decode_hdr_maxsz)
 279#define encode_access_maxsz     (op_encode_hdr_maxsz + 1)
 280#define decode_access_maxsz     (op_decode_hdr_maxsz + 2)
 281#define encode_symlink_maxsz    (op_encode_hdr_maxsz + \
 282                                1 + nfs4_name_maxsz + \
 283                                1 + \
 284                                nfs4_fattr_maxsz)
 285#define decode_symlink_maxsz    (op_decode_hdr_maxsz + 8)
 286#define encode_create_maxsz     (op_encode_hdr_maxsz + \
 287                                1 + 2 + nfs4_name_maxsz + \
 288                                encode_attrs_maxsz)
 289#define decode_create_maxsz     (op_decode_hdr_maxsz + \
 290                                decode_change_info_maxsz + \
 291                                nfs4_fattr_bitmap_maxsz)
 292#define encode_statfs_maxsz     (encode_getattr_maxsz)
 293#define decode_statfs_maxsz     (decode_getattr_maxsz)
 294#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
 295#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
 296#define encode_getacl_maxsz     (encode_getattr_maxsz)
 297#define decode_getacl_maxsz     (op_decode_hdr_maxsz + \
 298                                 nfs4_fattr_bitmap_maxsz + 1 + pagepad_maxsz)
 299#define encode_setacl_maxsz     (op_encode_hdr_maxsz + \
 300                                 encode_stateid_maxsz + 3)
 301#define decode_setacl_maxsz     (decode_setattr_maxsz)
 302#define encode_fs_locations_maxsz \
 303                                (encode_getattr_maxsz)
 304#define decode_fs_locations_maxsz \
 305                                (pagepad_maxsz)
 306#define encode_secinfo_maxsz    (op_encode_hdr_maxsz + nfs4_name_maxsz)
 307#define decode_secinfo_maxsz    (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
 308
 309#if defined(CONFIG_NFS_V4_1)
 310#define NFS4_MAX_MACHINE_NAME_LEN (64)
 311#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
 312                         sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
 313
 314#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
 315                                encode_verifier_maxsz + \
 316                                1 /* co_ownerid.len */ + \
 317                                /* eia_clientowner */ \
 318                                1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
 319                                1 /* flags */ + \
 320                                1 /* spa_how */ + \
 321                                /* max is SP4_MACH_CRED (for now) */ + \
 322                                1 + NFS4_OP_MAP_NUM_WORDS + \
 323                                1 + NFS4_OP_MAP_NUM_WORDS + \
 324                                1 /* implementation id array of size 1 */ + \
 325                                1 /* nii_domain */ + \
 326                                XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
 327                                1 /* nii_name */ + \
 328                                XDR_QUADLEN(IMPL_NAME_LIMIT) + \
 329                                3 /* nii_date */)
 330#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
 331                                2 /* eir_clientid */ + \
 332                                1 /* eir_sequenceid */ + \
 333                                1 /* eir_flags */ + \
 334                                1 /* spr_how */ + \
 335                                  /* max is SP4_MACH_CRED (for now) */ + \
 336                                1 + NFS4_OP_MAP_NUM_WORDS + \
 337                                1 + NFS4_OP_MAP_NUM_WORDS + \
 338                                2 /* eir_server_owner.so_minor_id */ + \
 339                                /* eir_server_owner.so_major_id<> */ \
 340                                XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
 341                                /* eir_server_scope<> */ \
 342                                XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
 343                                1 /* eir_server_impl_id array length */ + \
 344                                1 /* nii_domain */ + \
 345                                XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
 346                                1 /* nii_name */ + \
 347                                XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
 348                                3 /* nii_date */)
 349#define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
 350#define decode_channel_attrs_maxsz  (6 + \
 351                                     1 /* ca_rdma_ird.len */ + \
 352                                     1 /* ca_rdma_ird */)
 353#define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
 354                                     2 /* csa_clientid */ + \
 355                                     1 /* csa_sequence */ + \
 356                                     1 /* csa_flags */ + \
 357                                     encode_channel_attrs_maxsz + \
 358                                     encode_channel_attrs_maxsz + \
 359                                     1 /* csa_cb_program */ + \
 360                                     1 /* csa_sec_parms.len (1) */ + \
 361                                     1 /* cb_secflavor (AUTH_SYS) */ + \
 362                                     1 /* stamp */ + \
 363                                     1 /* machinename.len */ + \
 364                                     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
 365                                     1 /* uid */ + \
 366                                     1 /* gid */ + \
 367                                     1 /* gids.len (0) */)
 368#define decode_create_session_maxsz  (op_decode_hdr_maxsz +     \
 369                                     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
 370                                     1 /* csr_sequence */ + \
 371                                     1 /* csr_flags */ + \
 372                                     decode_channel_attrs_maxsz + \
 373                                     decode_channel_attrs_maxsz)
 374#define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
 375                                     /* bctsa_sessid */ \
 376                                     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
 377                                     1 /* bctsa_dir */ + \
 378                                     1 /* bctsa_use_conn_in_rdma_mode */)
 379#define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +       \
 380                                     /* bctsr_sessid */ \
 381                                     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
 382                                     1 /* bctsr_dir */ + \
 383                                     1 /* bctsr_use_conn_in_rdma_mode */)
 384#define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
 385#define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
 386#define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
 387#define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
 388#define encode_sequence_maxsz   (op_encode_hdr_maxsz + \
 389                                XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
 390#define decode_sequence_maxsz   (op_decode_hdr_maxsz + \
 391                                XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
 392#define encode_reclaim_complete_maxsz   (op_encode_hdr_maxsz + 4)
 393#define decode_reclaim_complete_maxsz   (op_decode_hdr_maxsz + 4)
 394#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
 395                                XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
 396                                1 /* layout type */ + \
 397                                1 /* maxcount */ + \
 398                                1 /* bitmap size */ + \
 399                                1 /* notification bitmap length */ + \
 400                                1 /* notification bitmap, word 0 */)
 401#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
 402                                1 /* layout type */ + \
 403                                1 /* opaque devaddr4 length */ + \
 404                                  /* devaddr4 payload is read into page */ \
 405                                1 /* notification bitmap length */ + \
 406                                1 /* notification bitmap, word 0 */ + \
 407                                pagepad_maxsz /* possible XDR padding */)
 408#define encode_layoutget_maxsz  (op_encode_hdr_maxsz + 10 + \
 409                                encode_stateid_maxsz)
 410#define decode_layoutget_maxsz  (op_decode_hdr_maxsz + 8 + \
 411                                decode_stateid_maxsz + \
 412                                XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + \
 413                                pagepad_maxsz)
 414#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
 415                                2 /* offset */ + \
 416                                2 /* length */ + \
 417                                1 /* reclaim */ + \
 418                                encode_stateid_maxsz + \
 419                                1 /* new offset (true) */ + \
 420                                2 /* last byte written */ + \
 421                                1 /* nt_timechanged (false) */ + \
 422                                1 /* layoutupdate4 layout type */ + \
 423                                1 /* layoutupdate4 opaqueue len */)
 424                                  /* the actual content of layoutupdate4 should
 425                                     be allocated by drivers and spliced in
 426                                     using xdr_write_pages */
 427#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
 428#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
 429                                encode_stateid_maxsz + \
 430                                1 + \
 431                                XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
 432#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
 433                                1 + decode_stateid_maxsz)
 434#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
 435#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
 436#define encode_test_stateid_maxsz       (op_encode_hdr_maxsz + 2 + \
 437                                         XDR_QUADLEN(NFS4_STATEID_SIZE))
 438#define decode_test_stateid_maxsz       (op_decode_hdr_maxsz + 2 + 1)
 439#define encode_free_stateid_maxsz       (op_encode_hdr_maxsz + 1 + \
 440                                         XDR_QUADLEN(NFS4_STATEID_SIZE))
 441#define decode_free_stateid_maxsz       (op_decode_hdr_maxsz)
 442#else /* CONFIG_NFS_V4_1 */
 443#define encode_sequence_maxsz   0
 444#define decode_sequence_maxsz   0
 445#define encode_layoutreturn_maxsz 0
 446#define decode_layoutreturn_maxsz 0
 447#define encode_layoutget_maxsz  0
 448#define decode_layoutget_maxsz  0
 449#endif /* CONFIG_NFS_V4_1 */
 450
 451#define NFS4_enc_compound_sz    (1024)  /* XXX: large enough? */
 452#define NFS4_dec_compound_sz    (1024)  /* XXX: large enough? */
 453#define NFS4_enc_read_sz        (compound_encode_hdr_maxsz + \
 454                                encode_sequence_maxsz + \
 455                                encode_putfh_maxsz + \
 456                                encode_read_maxsz)
 457#define NFS4_dec_read_sz        (compound_decode_hdr_maxsz + \
 458                                decode_sequence_maxsz + \
 459                                decode_putfh_maxsz + \
 460                                decode_read_maxsz)
 461#define NFS4_enc_readlink_sz    (compound_encode_hdr_maxsz + \
 462                                encode_sequence_maxsz + \
 463                                encode_putfh_maxsz + \
 464                                encode_readlink_maxsz)
 465#define NFS4_dec_readlink_sz    (compound_decode_hdr_maxsz + \
 466                                decode_sequence_maxsz + \
 467                                decode_putfh_maxsz + \
 468                                decode_readlink_maxsz)
 469#define NFS4_enc_readdir_sz     (compound_encode_hdr_maxsz + \
 470                                encode_sequence_maxsz + \
 471                                encode_putfh_maxsz + \
 472                                encode_readdir_maxsz)
 473#define NFS4_dec_readdir_sz     (compound_decode_hdr_maxsz + \
 474                                decode_sequence_maxsz + \
 475                                decode_putfh_maxsz + \
 476                                decode_readdir_maxsz)
 477#define NFS4_enc_write_sz       (compound_encode_hdr_maxsz + \
 478                                encode_sequence_maxsz + \
 479                                encode_putfh_maxsz + \
 480                                encode_write_maxsz + \
 481                                encode_getattr_maxsz)
 482#define NFS4_dec_write_sz       (compound_decode_hdr_maxsz + \
 483                                decode_sequence_maxsz + \
 484                                decode_putfh_maxsz + \
 485                                decode_write_maxsz + \
 486                                decode_getattr_maxsz)
 487#define NFS4_enc_commit_sz      (compound_encode_hdr_maxsz + \
 488                                encode_sequence_maxsz + \
 489                                encode_putfh_maxsz + \
 490                                encode_commit_maxsz)
 491#define NFS4_dec_commit_sz      (compound_decode_hdr_maxsz + \
 492                                decode_sequence_maxsz + \
 493                                decode_putfh_maxsz + \
 494                                decode_commit_maxsz)
 495#define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
 496                                encode_sequence_maxsz + \
 497                                encode_putfh_maxsz + \
 498                                encode_open_maxsz + \
 499                                encode_access_maxsz + \
 500                                encode_getfh_maxsz + \
 501                                encode_getattr_maxsz + \
 502                                encode_layoutget_maxsz)
 503#define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
 504                                decode_sequence_maxsz + \
 505                                decode_putfh_maxsz + \
 506                                decode_open_maxsz + \
 507                                decode_access_maxsz + \
 508                                decode_getfh_maxsz + \
 509                                decode_getattr_maxsz + \
 510                                decode_layoutget_maxsz)
 511#define NFS4_enc_open_confirm_sz \
 512                                (compound_encode_hdr_maxsz + \
 513                                 encode_putfh_maxsz + \
 514                                 encode_open_confirm_maxsz)
 515#define NFS4_dec_open_confirm_sz \
 516                                (compound_decode_hdr_maxsz + \
 517                                 decode_putfh_maxsz + \
 518                                 decode_open_confirm_maxsz)
 519#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
 520                                        encode_sequence_maxsz + \
 521                                        encode_putfh_maxsz + \
 522                                        encode_open_maxsz + \
 523                                        encode_access_maxsz + \
 524                                        encode_getattr_maxsz + \
 525                                        encode_layoutget_maxsz)
 526#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
 527                                        decode_sequence_maxsz + \
 528                                        decode_putfh_maxsz + \
 529                                        decode_open_maxsz + \
 530                                        decode_access_maxsz + \
 531                                        decode_getattr_maxsz + \
 532                                        decode_layoutget_maxsz)
 533#define NFS4_enc_open_downgrade_sz \
 534                                (compound_encode_hdr_maxsz + \
 535                                 encode_sequence_maxsz + \
 536                                 encode_putfh_maxsz + \
 537                                 encode_layoutreturn_maxsz + \
 538                                 encode_open_downgrade_maxsz)
 539#define NFS4_dec_open_downgrade_sz \
 540                                (compound_decode_hdr_maxsz + \
 541                                 decode_sequence_maxsz + \
 542                                 decode_putfh_maxsz + \
 543                                 decode_layoutreturn_maxsz + \
 544                                 decode_open_downgrade_maxsz)
 545#define NFS4_enc_close_sz       (compound_encode_hdr_maxsz + \
 546                                 encode_sequence_maxsz + \
 547                                 encode_putfh_maxsz + \
 548                                 encode_layoutreturn_maxsz + \
 549                                 encode_close_maxsz + \
 550                                 encode_getattr_maxsz)
 551#define NFS4_dec_close_sz       (compound_decode_hdr_maxsz + \
 552                                 decode_sequence_maxsz + \
 553                                 decode_putfh_maxsz + \
 554                                 decode_layoutreturn_maxsz + \
 555                                 decode_close_maxsz + \
 556                                 decode_getattr_maxsz)
 557#define NFS4_enc_setattr_sz     (compound_encode_hdr_maxsz + \
 558                                 encode_sequence_maxsz + \
 559                                 encode_putfh_maxsz + \
 560                                 encode_setattr_maxsz + \
 561                                 encode_getattr_maxsz)
 562#define NFS4_dec_setattr_sz     (compound_decode_hdr_maxsz + \
 563                                 decode_sequence_maxsz + \
 564                                 decode_putfh_maxsz + \
 565                                 decode_setattr_maxsz + \
 566                                 decode_getattr_maxsz)
 567#define NFS4_enc_fsinfo_sz      (compound_encode_hdr_maxsz + \
 568                                encode_sequence_maxsz + \
 569                                encode_putfh_maxsz + \
 570                                encode_fsinfo_maxsz)
 571#define NFS4_dec_fsinfo_sz      (compound_decode_hdr_maxsz + \
 572                                decode_sequence_maxsz + \
 573                                decode_putfh_maxsz + \
 574                                decode_fsinfo_maxsz)
 575#define NFS4_enc_renew_sz       (compound_encode_hdr_maxsz + \
 576                                encode_renew_maxsz)
 577#define NFS4_dec_renew_sz       (compound_decode_hdr_maxsz + \
 578                                decode_renew_maxsz)
 579#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
 580                                encode_setclientid_maxsz)
 581#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
 582                                decode_setclientid_maxsz)
 583#define NFS4_enc_setclientid_confirm_sz \
 584                                (compound_encode_hdr_maxsz + \
 585                                encode_setclientid_confirm_maxsz)
 586#define NFS4_dec_setclientid_confirm_sz \
 587                                (compound_decode_hdr_maxsz + \
 588                                decode_setclientid_confirm_maxsz)
 589#define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
 590                                encode_sequence_maxsz + \
 591                                encode_putfh_maxsz + \
 592                                encode_lock_maxsz)
 593#define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
 594                                decode_sequence_maxsz + \
 595                                decode_putfh_maxsz + \
 596                                decode_lock_maxsz)
 597#define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
 598                                encode_sequence_maxsz + \
 599                                encode_putfh_maxsz + \
 600                                encode_lockt_maxsz)
 601#define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
 602                                 decode_sequence_maxsz + \
 603                                 decode_putfh_maxsz + \
 604                                 decode_lockt_maxsz)
 605#define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
 606                                encode_sequence_maxsz + \
 607                                encode_putfh_maxsz + \
 608                                encode_locku_maxsz)
 609#define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
 610                                decode_sequence_maxsz + \
 611                                decode_putfh_maxsz + \
 612                                decode_locku_maxsz)
 613#define NFS4_enc_release_lockowner_sz \
 614                                (compound_encode_hdr_maxsz + \
 615                                 encode_lockowner_maxsz)
 616#define NFS4_dec_release_lockowner_sz \
 617                                (compound_decode_hdr_maxsz + \
 618                                 decode_lockowner_maxsz)
 619#define NFS4_enc_access_sz      (compound_encode_hdr_maxsz + \
 620                                encode_sequence_maxsz + \
 621                                encode_putfh_maxsz + \
 622                                encode_access_maxsz + \
 623                                encode_getattr_maxsz)
 624#define NFS4_dec_access_sz      (compound_decode_hdr_maxsz + \
 625                                decode_sequence_maxsz + \
 626                                decode_putfh_maxsz + \
 627                                decode_access_maxsz + \
 628                                decode_getattr_maxsz)
 629#define NFS4_enc_getattr_sz     (compound_encode_hdr_maxsz + \
 630                                encode_sequence_maxsz + \
 631                                encode_putfh_maxsz + \
 632                                encode_getattr_maxsz + \
 633                                encode_renew_maxsz)
 634#define NFS4_dec_getattr_sz     (compound_decode_hdr_maxsz + \
 635                                decode_sequence_maxsz + \
 636                                decode_putfh_maxsz + \
 637                                decode_getattr_maxsz + \
 638                                decode_renew_maxsz)
 639#define NFS4_enc_lookup_sz      (compound_encode_hdr_maxsz + \
 640                                encode_sequence_maxsz + \
 641                                encode_putfh_maxsz + \
 642                                encode_lookup_maxsz + \
 643                                encode_getattr_maxsz + \
 644                                encode_getfh_maxsz)
 645#define NFS4_dec_lookup_sz      (compound_decode_hdr_maxsz + \
 646                                decode_sequence_maxsz + \
 647                                decode_putfh_maxsz + \
 648                                decode_lookup_maxsz + \
 649                                decode_getattr_maxsz + \
 650                                decode_getfh_maxsz)
 651#define NFS4_enc_lookupp_sz     (compound_encode_hdr_maxsz + \
 652                                encode_sequence_maxsz + \
 653                                encode_putfh_maxsz + \
 654                                encode_lookupp_maxsz + \
 655                                encode_getattr_maxsz + \
 656                                encode_getfh_maxsz)
 657#define NFS4_dec_lookupp_sz     (compound_decode_hdr_maxsz + \
 658                                decode_sequence_maxsz + \
 659                                decode_putfh_maxsz + \
 660                                decode_lookupp_maxsz + \
 661                                decode_getattr_maxsz + \
 662                                decode_getfh_maxsz)
 663#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
 664                                encode_sequence_maxsz + \
 665                                encode_putrootfh_maxsz + \
 666                                encode_getattr_maxsz + \
 667                                encode_getfh_maxsz)
 668#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
 669                                decode_sequence_maxsz + \
 670                                decode_putrootfh_maxsz + \
 671                                decode_getattr_maxsz + \
 672                                decode_getfh_maxsz)
 673#define NFS4_enc_remove_sz      (compound_encode_hdr_maxsz + \
 674                                encode_sequence_maxsz + \
 675                                encode_putfh_maxsz + \
 676                                encode_remove_maxsz)
 677#define NFS4_dec_remove_sz      (compound_decode_hdr_maxsz + \
 678                                decode_sequence_maxsz + \
 679                                decode_putfh_maxsz + \
 680                                decode_remove_maxsz)
 681#define NFS4_enc_rename_sz      (compound_encode_hdr_maxsz + \
 682                                encode_sequence_maxsz + \
 683                                encode_putfh_maxsz + \
 684                                encode_savefh_maxsz + \
 685                                encode_putfh_maxsz + \
 686                                encode_rename_maxsz)
 687#define NFS4_dec_rename_sz      (compound_decode_hdr_maxsz + \
 688                                decode_sequence_maxsz + \
 689                                decode_putfh_maxsz + \
 690                                decode_savefh_maxsz + \
 691                                decode_putfh_maxsz + \
 692                                decode_rename_maxsz)
 693#define NFS4_enc_link_sz        (compound_encode_hdr_maxsz + \
 694                                encode_sequence_maxsz + \
 695                                encode_putfh_maxsz + \
 696                                encode_savefh_maxsz + \
 697                                encode_putfh_maxsz + \
 698                                encode_link_maxsz + \
 699                                encode_restorefh_maxsz + \
 700                                encode_getattr_maxsz)
 701#define NFS4_dec_link_sz        (compound_decode_hdr_maxsz + \
 702                                decode_sequence_maxsz + \
 703                                decode_putfh_maxsz + \
 704                                decode_savefh_maxsz + \
 705                                decode_putfh_maxsz + \
 706                                decode_link_maxsz + \
 707                                decode_restorefh_maxsz + \
 708                                decode_getattr_maxsz)
 709#define NFS4_enc_symlink_sz     (compound_encode_hdr_maxsz + \
 710                                encode_sequence_maxsz + \
 711                                encode_putfh_maxsz + \
 712                                encode_symlink_maxsz + \
 713                                encode_getattr_maxsz + \
 714                                encode_getfh_maxsz)
 715#define NFS4_dec_symlink_sz     (compound_decode_hdr_maxsz + \
 716                                decode_sequence_maxsz + \
 717                                decode_putfh_maxsz + \
 718                                decode_symlink_maxsz + \
 719                                decode_getattr_maxsz + \
 720                                decode_getfh_maxsz)
 721#define NFS4_enc_create_sz      (compound_encode_hdr_maxsz + \
 722                                encode_sequence_maxsz + \
 723                                encode_putfh_maxsz + \
 724                                encode_create_maxsz + \
 725                                encode_getfh_maxsz + \
 726                                encode_getattr_maxsz)
 727#define NFS4_dec_create_sz      (compound_decode_hdr_maxsz + \
 728                                decode_sequence_maxsz + \
 729                                decode_putfh_maxsz + \
 730                                decode_create_maxsz + \
 731                                decode_getfh_maxsz + \
 732                                decode_getattr_maxsz)
 733#define NFS4_enc_pathconf_sz    (compound_encode_hdr_maxsz + \
 734                                encode_sequence_maxsz + \
 735                                encode_putfh_maxsz + \
 736                                encode_getattr_maxsz)
 737#define NFS4_dec_pathconf_sz    (compound_decode_hdr_maxsz + \
 738                                decode_sequence_maxsz + \
 739                                decode_putfh_maxsz + \
 740                                decode_getattr_maxsz)
 741#define NFS4_enc_statfs_sz      (compound_encode_hdr_maxsz + \
 742                                encode_sequence_maxsz + \
 743                                encode_putfh_maxsz + \
 744                                encode_statfs_maxsz)
 745#define NFS4_dec_statfs_sz      (compound_decode_hdr_maxsz + \
 746                                decode_sequence_maxsz + \
 747                                decode_putfh_maxsz + \
 748                                decode_statfs_maxsz)
 749#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
 750                                encode_sequence_maxsz + \
 751                                encode_putfh_maxsz + \
 752                                encode_getattr_maxsz)
 753#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
 754                                decode_sequence_maxsz + \
 755                                decode_putfh_maxsz + \
 756                                decode_getattr_maxsz)
 757#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
 758                                encode_sequence_maxsz + \
 759                                encode_putfh_maxsz + \
 760                                encode_layoutreturn_maxsz + \
 761                                encode_delegreturn_maxsz + \
 762                                encode_getattr_maxsz)
 763#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
 764                                decode_sequence_maxsz + \
 765                                decode_putfh_maxsz + \
 766                                decode_layoutreturn_maxsz + \
 767                                decode_delegreturn_maxsz + \
 768                                decode_getattr_maxsz)
 769#define NFS4_enc_getacl_sz      (compound_encode_hdr_maxsz + \
 770                                encode_sequence_maxsz + \
 771                                encode_putfh_maxsz + \
 772                                encode_getacl_maxsz)
 773#define NFS4_dec_getacl_sz      (compound_decode_hdr_maxsz + \
 774                                decode_sequence_maxsz + \
 775                                decode_putfh_maxsz + \
 776                                decode_getacl_maxsz)
 777#define NFS4_enc_setacl_sz      (compound_encode_hdr_maxsz + \
 778                                encode_sequence_maxsz + \
 779                                encode_putfh_maxsz + \
 780                                encode_setacl_maxsz)
 781#define NFS4_dec_setacl_sz      (compound_decode_hdr_maxsz + \
 782                                decode_sequence_maxsz + \
 783                                decode_putfh_maxsz + \
 784                                decode_setacl_maxsz)
 785#define NFS4_enc_fs_locations_sz \
 786                                (compound_encode_hdr_maxsz + \
 787                                 encode_sequence_maxsz + \
 788                                 encode_putfh_maxsz + \
 789                                 encode_lookup_maxsz + \
 790                                 encode_fs_locations_maxsz + \
 791                                 encode_renew_maxsz)
 792#define NFS4_dec_fs_locations_sz \
 793                                (compound_decode_hdr_maxsz + \
 794                                 decode_sequence_maxsz + \
 795                                 decode_putfh_maxsz + \
 796                                 decode_lookup_maxsz + \
 797                                 decode_fs_locations_maxsz + \
 798                                 decode_renew_maxsz)
 799#define NFS4_enc_secinfo_sz     (compound_encode_hdr_maxsz + \
 800                                encode_sequence_maxsz + \
 801                                encode_putfh_maxsz + \
 802                                encode_secinfo_maxsz)
 803#define NFS4_dec_secinfo_sz     (compound_decode_hdr_maxsz + \
 804                                decode_sequence_maxsz + \
 805                                decode_putfh_maxsz + \
 806                                decode_secinfo_maxsz)
 807#define NFS4_enc_fsid_present_sz \
 808                                (compound_encode_hdr_maxsz + \
 809                                 encode_sequence_maxsz + \
 810                                 encode_putfh_maxsz + \
 811                                 encode_getfh_maxsz + \
 812                                 encode_renew_maxsz)
 813#define NFS4_dec_fsid_present_sz \
 814                                (compound_decode_hdr_maxsz + \
 815                                 decode_sequence_maxsz + \
 816                                 decode_putfh_maxsz + \
 817                                 decode_getfh_maxsz + \
 818                                 decode_renew_maxsz)
 819#if defined(CONFIG_NFS_V4_1)
 820#define NFS4_enc_bind_conn_to_session_sz \
 821                                (compound_encode_hdr_maxsz + \
 822                                 encode_bind_conn_to_session_maxsz)
 823#define NFS4_dec_bind_conn_to_session_sz \
 824                                (compound_decode_hdr_maxsz + \
 825                                 decode_bind_conn_to_session_maxsz)
 826#define NFS4_enc_exchange_id_sz \
 827                                (compound_encode_hdr_maxsz + \
 828                                 encode_exchange_id_maxsz)
 829#define NFS4_dec_exchange_id_sz \
 830                                (compound_decode_hdr_maxsz + \
 831                                 decode_exchange_id_maxsz)
 832#define NFS4_enc_create_session_sz \
 833                                (compound_encode_hdr_maxsz + \
 834                                 encode_create_session_maxsz)
 835#define NFS4_dec_create_session_sz \
 836                                (compound_decode_hdr_maxsz + \
 837                                 decode_create_session_maxsz)
 838#define NFS4_enc_destroy_session_sz     (compound_encode_hdr_maxsz + \
 839                                         encode_destroy_session_maxsz)
 840#define NFS4_dec_destroy_session_sz     (compound_decode_hdr_maxsz + \
 841                                         decode_destroy_session_maxsz)
 842#define NFS4_enc_destroy_clientid_sz    (compound_encode_hdr_maxsz + \
 843                                         encode_destroy_clientid_maxsz)
 844#define NFS4_dec_destroy_clientid_sz    (compound_decode_hdr_maxsz + \
 845                                         decode_destroy_clientid_maxsz)
 846#define NFS4_enc_sequence_sz \
 847                                (compound_decode_hdr_maxsz + \
 848                                 encode_sequence_maxsz)
 849#define NFS4_dec_sequence_sz \
 850                                (compound_decode_hdr_maxsz + \
 851                                 decode_sequence_maxsz)
 852#endif
 853#define NFS4_enc_get_lease_time_sz      (compound_encode_hdr_maxsz + \
 854                                         encode_sequence_maxsz + \
 855                                         encode_putrootfh_maxsz + \
 856                                         encode_fsinfo_maxsz)
 857#define NFS4_dec_get_lease_time_sz      (compound_decode_hdr_maxsz + \
 858                                         decode_sequence_maxsz + \
 859                                         decode_putrootfh_maxsz + \
 860                                         decode_fsinfo_maxsz)
 861#if defined(CONFIG_NFS_V4_1)
 862#define NFS4_enc_reclaim_complete_sz    (compound_encode_hdr_maxsz + \
 863                                         encode_sequence_maxsz + \
 864                                         encode_reclaim_complete_maxsz)
 865#define NFS4_dec_reclaim_complete_sz    (compound_decode_hdr_maxsz + \
 866                                         decode_sequence_maxsz + \
 867                                         decode_reclaim_complete_maxsz)
 868#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
 869                                encode_sequence_maxsz +\
 870                                encode_getdeviceinfo_maxsz)
 871#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
 872                                decode_sequence_maxsz + \
 873                                decode_getdeviceinfo_maxsz)
 874#define NFS4_enc_layoutget_sz   (compound_encode_hdr_maxsz + \
 875                                encode_sequence_maxsz + \
 876                                encode_putfh_maxsz +        \
 877                                encode_layoutget_maxsz)
 878#define NFS4_dec_layoutget_sz   (compound_decode_hdr_maxsz + \
 879                                decode_sequence_maxsz + \
 880                                decode_putfh_maxsz +        \
 881                                decode_layoutget_maxsz)
 882#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
 883                                encode_sequence_maxsz +\
 884                                encode_putfh_maxsz + \
 885                                encode_layoutcommit_maxsz + \
 886                                encode_getattr_maxsz)
 887#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
 888                                decode_sequence_maxsz + \
 889                                decode_putfh_maxsz + \
 890                                decode_layoutcommit_maxsz + \
 891                                decode_getattr_maxsz)
 892#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
 893                                encode_sequence_maxsz + \
 894                                encode_putfh_maxsz + \
 895                                encode_layoutreturn_maxsz)
 896#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
 897                                decode_sequence_maxsz + \
 898                                decode_putfh_maxsz + \
 899                                decode_layoutreturn_maxsz)
 900#define NFS4_enc_secinfo_no_name_sz     (compound_encode_hdr_maxsz + \
 901                                        encode_sequence_maxsz + \
 902                                        encode_putrootfh_maxsz +\
 903                                        encode_secinfo_no_name_maxsz)
 904#define NFS4_dec_secinfo_no_name_sz     (compound_decode_hdr_maxsz + \
 905                                        decode_sequence_maxsz + \
 906                                        decode_putrootfh_maxsz + \
 907                                        decode_secinfo_no_name_maxsz)
 908#define NFS4_enc_test_stateid_sz        (compound_encode_hdr_maxsz + \
 909                                         encode_sequence_maxsz + \
 910                                         encode_test_stateid_maxsz)
 911#define NFS4_dec_test_stateid_sz        (compound_decode_hdr_maxsz + \
 912                                         decode_sequence_maxsz + \
 913                                         decode_test_stateid_maxsz)
 914#define NFS4_enc_free_stateid_sz        (compound_encode_hdr_maxsz + \
 915                                         encode_sequence_maxsz + \
 916                                         encode_free_stateid_maxsz)
 917#define NFS4_dec_free_stateid_sz        (compound_decode_hdr_maxsz + \
 918                                         decode_sequence_maxsz + \
 919                                         decode_free_stateid_maxsz)
 920
 921const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
 922                                      compound_encode_hdr_maxsz +
 923                                      encode_sequence_maxsz +
 924                                      encode_putfh_maxsz +
 925                                      encode_getattr_maxsz) *
 926                                     XDR_UNIT);
 927
 928const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
 929                                     compound_decode_hdr_maxsz +
 930                                     decode_sequence_maxsz +
 931                                     decode_putfh_maxsz) *
 932                                    XDR_UNIT);
 933
 934const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
 935                                           compound_decode_hdr_maxsz +
 936                                           decode_sequence_maxsz) *
 937                                          XDR_UNIT);
 938EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
 939#endif /* CONFIG_NFS_V4_1 */
 940
 941static const umode_t nfs_type2fmt[] = {
 942        [NF4BAD] = 0,
 943        [NF4REG] = S_IFREG,
 944        [NF4DIR] = S_IFDIR,
 945        [NF4BLK] = S_IFBLK,
 946        [NF4CHR] = S_IFCHR,
 947        [NF4LNK] = S_IFLNK,
 948        [NF4SOCK] = S_IFSOCK,
 949        [NF4FIFO] = S_IFIFO,
 950        [NF4ATTRDIR] = 0,
 951        [NF4NAMEDATTR] = 0,
 952};
 953
 954struct compound_hdr {
 955        int32_t         status;
 956        uint32_t        nops;
 957        __be32 *        nops_p;
 958        uint32_t        taglen;
 959        char *          tag;
 960        uint32_t        replen;         /* expected reply words */
 961        u32             minorversion;
 962};
 963
 964static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
 965{
 966        __be32 *p = xdr_reserve_space(xdr, nbytes);
 967        BUG_ON(!p);
 968        return p;
 969}
 970
 971static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
 972{
 973        WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
 974}
 975
 976static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
 977{
 978        WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
 979}
 980
 981static void encode_uint32(struct xdr_stream *xdr, u32 n)
 982{
 983        WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
 984}
 985
 986static void encode_uint64(struct xdr_stream *xdr, u64 n)
 987{
 988        WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
 989}
 990
 991static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
 992                const __u32 *bitmap, size_t len)
 993{
 994        ssize_t ret;
 995
 996        /* Trim empty words */
 997        while (len > 0 && bitmap[len-1] == 0)
 998                len--;
 999        ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
1000        if (WARN_ON_ONCE(ret < 0))
1001                return ret;
1002        return len;
1003}
1004
1005static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
1006                __u32 *res, size_t len)
1007{
1008        size_t i;
1009        __u32 tmp;
1010
1011        while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
1012                len--;
1013        for (i = len; i-- > 0;) {
1014                tmp = bitmap[i] & mask[i];
1015                res[i] = tmp;
1016        }
1017        return len;
1018}
1019
1020static void encode_nfs4_seqid(struct xdr_stream *xdr,
1021                const struct nfs_seqid *seqid)
1022{
1023        if (seqid != NULL)
1024                encode_uint32(xdr, seqid->sequence->counter);
1025        else
1026                encode_uint32(xdr, 0);
1027}
1028
1029static void encode_compound_hdr(struct xdr_stream *xdr,
1030                                struct rpc_rqst *req,
1031                                struct compound_hdr *hdr)
1032{
1033        __be32 *p;
1034
1035        /* initialize running count of expected bytes in reply.
1036         * NOTE: the replied tag SHOULD be the same is the one sent,
1037         * but this is not required as a MUST for the server to do so. */
1038        hdr->replen = 3 + hdr->taglen;
1039
1040        WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
1041        encode_string(xdr, hdr->taglen, hdr->tag);
1042        p = reserve_space(xdr, 8);
1043        *p++ = cpu_to_be32(hdr->minorversion);
1044        hdr->nops_p = p;
1045        *p = cpu_to_be32(hdr->nops);
1046}
1047
1048static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1049                uint32_t replen,
1050                struct compound_hdr *hdr)
1051{
1052        encode_uint32(xdr, op);
1053        hdr->nops++;
1054        hdr->replen += replen;
1055}
1056
1057static void encode_nops(struct compound_hdr *hdr)
1058{
1059        WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
1060        *hdr->nops_p = htonl(hdr->nops);
1061}
1062
1063static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1064{
1065        encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1066}
1067
1068static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1069{
1070        encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1071}
1072
1073static __be32 *
1074xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
1075{
1076        p = xdr_encode_hyper(p, t->tv_sec);
1077        *p++ = cpu_to_be32(t->tv_nsec);
1078        return p;
1079}
1080
1081static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1082                                const struct nfs4_label *label,
1083                                const umode_t *umask,
1084                                const struct nfs_server *server,
1085                                const uint32_t attrmask[])
1086{
1087        char owner_name[IDMAP_NAMESZ];
1088        char owner_group[IDMAP_NAMESZ];
1089        int owner_namelen = 0;
1090        int owner_grouplen = 0;
1091        __be32 *p;
1092        uint32_t len = 0;
1093        uint32_t bmval[3] = { 0 };
1094
1095        /*
1096         * We reserve enough space to write the entire attribute buffer at once.
1097         */
1098        if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
1099                bmval[0] |= FATTR4_WORD0_SIZE;
1100                len += 8;
1101        }
1102        if (iap->ia_valid & ATTR_MODE) {
1103                if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
1104                        bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1105                        len += 8;
1106                } else if (attrmask[1] & FATTR4_WORD1_MODE) {
1107                        bmval[1] |= FATTR4_WORD1_MODE;
1108                        len += 4;
1109                }
1110        }
1111        if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
1112                owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1113                if (owner_namelen < 0) {
1114                        dprintk("nfs: couldn't resolve uid %d to string\n",
1115                                        from_kuid(&init_user_ns, iap->ia_uid));
1116                        /* XXX */
1117                        strcpy(owner_name, "nobody");
1118                        owner_namelen = sizeof("nobody") - 1;
1119                        /* goto out; */
1120                }
1121                bmval[1] |= FATTR4_WORD1_OWNER;
1122                len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1123        }
1124        if ((iap->ia_valid & ATTR_GID) &&
1125           (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
1126                owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1127                if (owner_grouplen < 0) {
1128                        dprintk("nfs: couldn't resolve gid %d to string\n",
1129                                        from_kgid(&init_user_ns, iap->ia_gid));
1130                        strcpy(owner_group, "nobody");
1131                        owner_grouplen = sizeof("nobody") - 1;
1132                        /* goto out; */
1133                }
1134                bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1135                len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1136        }
1137        if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1138                if (iap->ia_valid & ATTR_ATIME_SET) {
1139                        bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1140                        len += 4 + (nfstime4_maxsz << 2);
1141                } else if (iap->ia_valid & ATTR_ATIME) {
1142                        bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1143                        len += 4;
1144                }
1145        }
1146        if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1147                if (iap->ia_valid & ATTR_MTIME_SET) {
1148                        bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1149                        len += 4 + (nfstime4_maxsz << 2);
1150                } else if (iap->ia_valid & ATTR_MTIME) {
1151                        bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1152                        len += 4;
1153                }
1154        }
1155
1156        if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1157                len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1158                bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1159        }
1160
1161        xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1162        xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
1163
1164        if (bmval[0] & FATTR4_WORD0_SIZE)
1165                p = xdr_encode_hyper(p, iap->ia_size);
1166        if (bmval[1] & FATTR4_WORD1_MODE)
1167                *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1168        if (bmval[1] & FATTR4_WORD1_OWNER)
1169                p = xdr_encode_opaque(p, owner_name, owner_namelen);
1170        if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1171                p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1172        if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1173                if (iap->ia_valid & ATTR_ATIME_SET) {
1174                        *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1175                        p = xdr_encode_nfstime4(p, &iap->ia_atime);
1176                } else
1177                        *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1178        }
1179        if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1180                if (iap->ia_valid & ATTR_MTIME_SET) {
1181                        *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1182                        p = xdr_encode_nfstime4(p, &iap->ia_mtime);
1183                } else
1184                        *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1185        }
1186        if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1187                *p++ = cpu_to_be32(label->lfs);
1188                *p++ = cpu_to_be32(label->pi);
1189                *p++ = cpu_to_be32(label->len);
1190                p = xdr_encode_opaque_fixed(p, label->label, label->len);
1191        }
1192        if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1193                *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1194                *p++ = cpu_to_be32(*umask);
1195        }
1196
1197/* out: */
1198}
1199
1200static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1201{
1202        encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1203        encode_uint32(xdr, access);
1204}
1205
1206static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1207{
1208        encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1209        encode_nfs4_seqid(xdr, arg->seqid);
1210        encode_nfs4_stateid(xdr, &arg->stateid);
1211}
1212
1213static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1214{
1215        __be32 *p;
1216
1217        encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1218        p = reserve_space(xdr, 12);
1219        p = xdr_encode_hyper(p, args->offset);
1220        *p = cpu_to_be32(args->count);
1221}
1222
1223static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1224{
1225        __be32 *p;
1226
1227        encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1228        encode_uint32(xdr, create->ftype);
1229
1230        switch (create->ftype) {
1231        case NF4LNK:
1232                p = reserve_space(xdr, 4);
1233                *p = cpu_to_be32(create->u.symlink.len);
1234                xdr_write_pages(xdr, create->u.symlink.pages, 0,
1235                                create->u.symlink.len);
1236                xdr->buf->flags |= XDRBUF_WRITE;
1237                break;
1238
1239        case NF4BLK: case NF4CHR:
1240                p = reserve_space(xdr, 8);
1241                *p++ = cpu_to_be32(create->u.device.specdata1);
1242                *p = cpu_to_be32(create->u.device.specdata2);
1243                break;
1244
1245        default:
1246                break;
1247        }
1248
1249        encode_string(xdr, create->name->len, create->name->name);
1250        encode_attrs(xdr, create->attrs, create->label, &create->umask,
1251                        create->server, create->server->attr_bitmask);
1252}
1253
1254static void encode_getattr(struct xdr_stream *xdr,
1255                const __u32 *bitmap, const __u32 *mask, size_t len,
1256                struct compound_hdr *hdr)
1257{
1258        __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
1259
1260        encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1261        if (mask) {
1262                if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1263                        len = ARRAY_SIZE(masked_bitmap);
1264                len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1265                bitmap = masked_bitmap;
1266        }
1267        xdr_encode_bitmap4(xdr, bitmap, len);
1268}
1269
1270static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1271{
1272        encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1273                        ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
1274}
1275
1276static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1277                                 const u32 *open_bitmap,
1278                                 struct compound_hdr *hdr)
1279{
1280        encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
1281}
1282
1283static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1284{
1285        encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1286                        ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
1287}
1288
1289static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1290{
1291        encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1292                        ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
1293}
1294
1295static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1296{
1297        encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1298}
1299
1300static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1301{
1302        encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1303        encode_string(xdr, name->len, name->name);
1304}
1305
1306static inline int nfs4_lock_type(struct file_lock *fl, int block)
1307{
1308        if (fl->fl_type == F_RDLCK)
1309                return block ? NFS4_READW_LT : NFS4_READ_LT;
1310        return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1311}
1312
1313static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1314{
1315        if (fl->fl_end == OFFSET_MAX)
1316                return ~(uint64_t)0;
1317        return fl->fl_end - fl->fl_start + 1;
1318}
1319
1320static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1321{
1322        __be32 *p;
1323
1324        p = reserve_space(xdr, 32);
1325        p = xdr_encode_hyper(p, lowner->clientid);
1326        *p++ = cpu_to_be32(20);
1327        p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1328        *p++ = cpu_to_be32(lowner->s_dev);
1329        xdr_encode_hyper(p, lowner->id);
1330}
1331
1332/*
1333 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1334 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1335 */
1336static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1337{
1338        __be32 *p;
1339
1340        encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1341        p = reserve_space(xdr, 28);
1342        *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1343        *p++ = cpu_to_be32(args->reclaim);
1344        p = xdr_encode_hyper(p, args->fl->fl_start);
1345        p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1346        *p = cpu_to_be32(args->new_lock_owner);
1347        if (args->new_lock_owner){
1348                encode_nfs4_seqid(xdr, args->open_seqid);
1349                encode_nfs4_stateid(xdr, &args->open_stateid);
1350                encode_nfs4_seqid(xdr, args->lock_seqid);
1351                encode_lockowner(xdr, &args->lock_owner);
1352        }
1353        else {
1354                encode_nfs4_stateid(xdr, &args->lock_stateid);
1355                encode_nfs4_seqid(xdr, args->lock_seqid);
1356        }
1357}
1358
1359static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1360{
1361        __be32 *p;
1362
1363        encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1364        p = reserve_space(xdr, 20);
1365        *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1366        p = xdr_encode_hyper(p, args->fl->fl_start);
1367        p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1368        encode_lockowner(xdr, &args->lock_owner);
1369}
1370
1371static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1372{
1373        __be32 *p;
1374
1375        encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1376        encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1377        encode_nfs4_seqid(xdr, args->seqid);
1378        encode_nfs4_stateid(xdr, &args->stateid);
1379        p = reserve_space(xdr, 16);
1380        p = xdr_encode_hyper(p, args->fl->fl_start);
1381        xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1382}
1383
1384static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1385{
1386        encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1387        encode_lockowner(xdr, lowner);
1388}
1389
1390static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1391{
1392        encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1393        encode_string(xdr, name->len, name->name);
1394}
1395
1396static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1397{
1398        encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1399}
1400
1401static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
1402{
1403        __be32 *p;
1404
1405        p = reserve_space(xdr, 8);
1406        *p++ = cpu_to_be32(share_access);
1407        *p = cpu_to_be32(0);            /* for linux, share_deny = 0 always */
1408}
1409
1410static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1411{
1412        __be32 *p;
1413 /*
1414 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1415 * owner 4 = 32
1416 */
1417        encode_nfs4_seqid(xdr, arg->seqid);
1418        encode_share_access(xdr, arg->share_access);
1419        p = reserve_space(xdr, 36);
1420        p = xdr_encode_hyper(p, arg->clientid);
1421        *p++ = cpu_to_be32(24);
1422        p = xdr_encode_opaque_fixed(p, "open id:", 8);
1423        *p++ = cpu_to_be32(arg->server->s_dev);
1424        *p++ = cpu_to_be32(arg->id.uniquifier);
1425        xdr_encode_hyper(p, arg->id.create_time);
1426}
1427
1428static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1429{
1430        __be32 *p;
1431
1432        p = reserve_space(xdr, 4);
1433        switch(arg->createmode) {
1434        case NFS4_CREATE_UNCHECKED:
1435                *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1436                encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1437                                arg->server, arg->server->attr_bitmask);
1438                break;
1439        case NFS4_CREATE_GUARDED:
1440                *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1441                encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1442                                arg->server, arg->server->attr_bitmask);
1443                break;
1444        case NFS4_CREATE_EXCLUSIVE:
1445                *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1446                encode_nfs4_verifier(xdr, &arg->u.verifier);
1447                break;
1448        case NFS4_CREATE_EXCLUSIVE4_1:
1449                *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1450                encode_nfs4_verifier(xdr, &arg->u.verifier);
1451                encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1452                                arg->server, arg->server->exclcreat_bitmask);
1453        }
1454}
1455
1456static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1457{
1458        __be32 *p;
1459
1460        p = reserve_space(xdr, 4);
1461        switch (arg->open_flags & O_CREAT) {
1462        case 0:
1463                *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1464                break;
1465        default:
1466                *p = cpu_to_be32(NFS4_OPEN_CREATE);
1467                encode_createmode(xdr, arg);
1468        }
1469}
1470
1471static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1472{
1473        __be32 *p;
1474
1475        p = reserve_space(xdr, 4);
1476        switch (delegation_type) {
1477        case 0:
1478                *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1479                break;
1480        case FMODE_READ:
1481                *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1482                break;
1483        case FMODE_WRITE|FMODE_READ:
1484                *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1485                break;
1486        default:
1487                BUG();
1488        }
1489}
1490
1491static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1492{
1493        __be32 *p;
1494
1495        p = reserve_space(xdr, 4);
1496        *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1497        encode_string(xdr, name->len, name->name);
1498}
1499
1500static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1501{
1502        __be32 *p;
1503
1504        p = reserve_space(xdr, 4);
1505        *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1506        encode_delegation_type(xdr, type);
1507}
1508
1509static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1510{
1511        __be32 *p;
1512
1513        p = reserve_space(xdr, 4);
1514        *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1515        encode_nfs4_stateid(xdr, stateid);
1516        encode_string(xdr, name->len, name->name);
1517}
1518
1519static inline void encode_claim_fh(struct xdr_stream *xdr)
1520{
1521        __be32 *p;
1522
1523        p = reserve_space(xdr, 4);
1524        *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1525}
1526
1527static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1528{
1529        __be32 *p;
1530
1531        p = reserve_space(xdr, 4);
1532        *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1533        encode_nfs4_stateid(xdr, stateid);
1534}
1535
1536static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1537{
1538        encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1539        encode_openhdr(xdr, arg);
1540        encode_opentype(xdr, arg);
1541        switch (arg->claim) {
1542        case NFS4_OPEN_CLAIM_NULL:
1543                encode_claim_null(xdr, arg->name);
1544                break;
1545        case NFS4_OPEN_CLAIM_PREVIOUS:
1546                encode_claim_previous(xdr, arg->u.delegation_type);
1547                break;
1548        case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1549                encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1550                break;
1551        case NFS4_OPEN_CLAIM_FH:
1552                encode_claim_fh(xdr);
1553                break;
1554        case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1555                encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1556                break;
1557        default:
1558                BUG();
1559        }
1560}
1561
1562static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1563{
1564        encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1565        encode_nfs4_stateid(xdr, arg->stateid);
1566        encode_nfs4_seqid(xdr, arg->seqid);
1567}
1568
1569static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1570{
1571        encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1572        encode_nfs4_stateid(xdr, &arg->stateid);
1573        encode_nfs4_seqid(xdr, arg->seqid);
1574        encode_share_access(xdr, arg->share_access);
1575}
1576
1577static void
1578encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1579{
1580        encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1581        encode_string(xdr, fh->size, fh->data);
1582}
1583
1584static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1585{
1586        encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1587}
1588
1589static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1590                        struct compound_hdr *hdr)
1591{
1592        __be32 *p;
1593
1594        encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1595        encode_nfs4_stateid(xdr, &args->stateid);
1596
1597        p = reserve_space(xdr, 12);
1598        p = xdr_encode_hyper(p, args->offset);
1599        *p = cpu_to_be32(args->count);
1600}
1601
1602static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1603{
1604        uint32_t attrs[3] = {
1605                FATTR4_WORD0_RDATTR_ERROR,
1606                FATTR4_WORD1_MOUNTED_ON_FILEID,
1607        };
1608        uint32_t dircount = readdir->count >> 1;
1609        __be32 *p, verf[2];
1610        uint32_t attrlen = 0;
1611        unsigned int i;
1612
1613        if (readdir->plus) {
1614                attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1615                        FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1616                attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1617                        FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1618                        FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1619                        FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1620                attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1621                dircount >>= 1;
1622        }
1623        /* Use mounted_on_fileid only if the server supports it */
1624        if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1625                attrs[0] |= FATTR4_WORD0_FILEID;
1626        for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1627                attrs[i] &= readdir->bitmask[i];
1628                if (attrs[i] != 0)
1629                        attrlen = i+1;
1630        }
1631
1632        encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1633        encode_uint64(xdr, readdir->cookie);
1634        encode_nfs4_verifier(xdr, &readdir->verifier);
1635        p = reserve_space(xdr, 12 + (attrlen << 2));
1636        *p++ = cpu_to_be32(dircount);
1637        *p++ = cpu_to_be32(readdir->count);
1638        *p++ = cpu_to_be32(attrlen);
1639        for (i = 0; i < attrlen; i++)
1640                *p++ = cpu_to_be32(attrs[i]);
1641        memcpy(verf, readdir->verifier.data, sizeof(verf));
1642
1643        dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1644                        __func__,
1645                        (unsigned long long)readdir->cookie,
1646                        verf[0], verf[1],
1647                        attrs[0] & readdir->bitmask[0],
1648                        attrs[1] & readdir->bitmask[1],
1649                        attrs[2] & readdir->bitmask[2]);
1650}
1651
1652static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1653{
1654        encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1655}
1656
1657static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1658{
1659        encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1660        encode_string(xdr, name->len, name->name);
1661}
1662
1663static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1664{
1665        encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1666        encode_string(xdr, oldname->len, oldname->name);
1667        encode_string(xdr, newname->len, newname->name);
1668}
1669
1670static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1671                         struct compound_hdr *hdr)
1672{
1673        encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1674        encode_uint64(xdr, clid);
1675}
1676
1677static void
1678encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1679{
1680        encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1681}
1682
1683static void
1684encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1685                struct compound_hdr *hdr)
1686{
1687        __be32 *p;
1688
1689        encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1690        encode_nfs4_stateid(xdr, &zero_stateid);
1691        p = reserve_space(xdr, 2*4);
1692        *p++ = cpu_to_be32(1);
1693        *p = cpu_to_be32(FATTR4_WORD0_ACL);
1694        p = reserve_space(xdr, 4);
1695        *p = cpu_to_be32(arg->acl_len);
1696        xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
1697}
1698
1699static void
1700encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1701{
1702        encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1703}
1704
1705static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1706{
1707        encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1708        encode_nfs4_stateid(xdr, &arg->stateid);
1709        encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1710                        server->attr_bitmask);
1711}
1712
1713static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1714{
1715        __be32 *p;
1716
1717        encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1718        encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1719
1720        encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1721                        setclientid->sc_clnt->cl_owner_id);
1722        p = reserve_space(xdr, 4);
1723        *p = cpu_to_be32(setclientid->sc_prog);
1724        encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1725        encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1726        p = reserve_space(xdr, 4);
1727        *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
1728}
1729
1730static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1731{
1732        encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1733                        decode_setclientid_confirm_maxsz, hdr);
1734        encode_uint64(xdr, arg->clientid);
1735        encode_nfs4_verifier(xdr, &arg->confirm);
1736}
1737
1738static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1739                         struct compound_hdr *hdr)
1740{
1741        __be32 *p;
1742
1743        encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1744        encode_nfs4_stateid(xdr, &args->stateid);
1745
1746        p = reserve_space(xdr, 16);
1747        p = xdr_encode_hyper(p, args->offset);
1748        *p++ = cpu_to_be32(args->stable);
1749        *p = cpu_to_be32(args->count);
1750
1751        xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1752}
1753
1754static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1755{
1756        encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1757        encode_nfs4_stateid(xdr, stateid);
1758}
1759
1760static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1761{
1762        encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1763        encode_string(xdr, name->len, name->name);
1764}
1765
1766#if defined(CONFIG_NFS_V4_1)
1767/* NFSv4.1 operations */
1768static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1769                                   const struct nfs41_bind_conn_to_session_args *args,
1770                                   struct compound_hdr *hdr)
1771{
1772        __be32 *p;
1773
1774        encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1775                decode_bind_conn_to_session_maxsz, hdr);
1776        encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1777        p = xdr_reserve_space(xdr, 8);
1778        *p++ = cpu_to_be32(args->dir);
1779        *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
1780}
1781
1782static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
1783{
1784        unsigned int i;
1785        encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1786        for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1787                encode_uint32(xdr, op_map->u.words[i]);
1788}
1789
1790static void encode_exchange_id(struct xdr_stream *xdr,
1791                               const struct nfs41_exchange_id_args *args,
1792                               struct compound_hdr *hdr)
1793{
1794        __be32 *p;
1795        char impl_name[IMPL_NAME_LIMIT];
1796        int len = 0;
1797
1798        encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1799        encode_nfs4_verifier(xdr, &args->verifier);
1800
1801        encode_string(xdr, strlen(args->client->cl_owner_id),
1802                        args->client->cl_owner_id);
1803
1804        encode_uint32(xdr, args->flags);
1805        encode_uint32(xdr, args->state_protect.how);
1806
1807        switch (args->state_protect.how) {
1808        case SP4_NONE:
1809                break;
1810        case SP4_MACH_CRED:
1811                encode_op_map(xdr, &args->state_protect.enforce);
1812                encode_op_map(xdr, &args->state_protect.allow);
1813                break;
1814        default:
1815                WARN_ON_ONCE(1);
1816                break;
1817        }
1818
1819        if (send_implementation_id &&
1820            sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1821            sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1822                <= sizeof(impl_name) + 1)
1823                len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1824                               utsname()->sysname, utsname()->release,
1825                               utsname()->version, utsname()->machine);
1826
1827        if (len > 0) {
1828                encode_uint32(xdr, 1);  /* implementation id array length=1 */
1829
1830                encode_string(xdr,
1831                        sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1832                        CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1833                encode_string(xdr, len, impl_name);
1834                /* just send zeros for nii_date - the date is in nii_name */
1835                p = reserve_space(xdr, 12);
1836                p = xdr_encode_hyper(p, 0);
1837                *p = cpu_to_be32(0);
1838        } else
1839                encode_uint32(xdr, 0);  /* implementation id array length=0 */
1840}
1841
1842static void encode_create_session(struct xdr_stream *xdr,
1843                                  const struct nfs41_create_session_args *args,
1844                                  struct compound_hdr *hdr)
1845{
1846        __be32 *p;
1847        struct nfs_client *clp = args->client;
1848        struct rpc_clnt *clnt = clp->cl_rpcclient;
1849        struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1850        u32 max_resp_sz_cached;
1851
1852        /*
1853         * Assumes OPEN is the biggest non-idempotent compound.
1854         * 2 is the verifier.
1855         */
1856        max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1857                                * XDR_UNIT + RPC_MAX_AUTH_SIZE;
1858
1859        encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1860        p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
1861        p = xdr_encode_hyper(p, args->clientid);
1862        *p++ = cpu_to_be32(args->seqid);                        /*Sequence id */
1863        *p++ = cpu_to_be32(args->flags);                        /*flags */
1864
1865        /* Fore Channel */
1866        *p++ = cpu_to_be32(0);                          /* header padding size */
1867        *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1868        *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1869        *p++ = cpu_to_be32(max_resp_sz_cached);         /* Max resp sz cached */
1870        *p++ = cpu_to_be32(args->fc_attrs.max_ops);     /* max operations */
1871        *p++ = cpu_to_be32(args->fc_attrs.max_reqs);    /* max requests */
1872        *p++ = cpu_to_be32(0);                          /* rdmachannel_attrs */
1873
1874        /* Back Channel */
1875        *p++ = cpu_to_be32(0);                          /* header padding size */
1876        *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1877        *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1878        *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);  /* Max resp sz cached */
1879        *p++ = cpu_to_be32(args->bc_attrs.max_ops);     /* max operations */
1880        *p++ = cpu_to_be32(args->bc_attrs.max_reqs);    /* max requests */
1881        *p++ = cpu_to_be32(0);                          /* rdmachannel_attrs */
1882
1883        *p++ = cpu_to_be32(args->cb_program);           /* cb_program */
1884        *p++ = cpu_to_be32(1);
1885        *p++ = cpu_to_be32(RPC_AUTH_UNIX);                      /* auth_sys */
1886
1887        /* authsys_parms rfc1831 */
1888        *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
1889        p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1890        *p++ = cpu_to_be32(0);                          /* UID */
1891        *p++ = cpu_to_be32(0);                          /* GID */
1892        *p = cpu_to_be32(0);                            /* No more gids */
1893}
1894
1895static void encode_destroy_session(struct xdr_stream *xdr,
1896                                   const struct nfs4_session *session,
1897                                   struct compound_hdr *hdr)
1898{
1899        encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1900        encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1901}
1902
1903static void encode_destroy_clientid(struct xdr_stream *xdr,
1904                                   uint64_t clientid,
1905                                   struct compound_hdr *hdr)
1906{
1907        encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1908        encode_uint64(xdr, clientid);
1909}
1910
1911static void encode_reclaim_complete(struct xdr_stream *xdr,
1912                                    const struct nfs41_reclaim_complete_args *args,
1913                                    struct compound_hdr *hdr)
1914{
1915        encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1916        encode_uint32(xdr, args->one_fs);
1917}
1918#endif /* CONFIG_NFS_V4_1 */
1919
1920static void encode_sequence(struct xdr_stream *xdr,
1921                            const struct nfs4_sequence_args *args,
1922                            struct compound_hdr *hdr)
1923{
1924#if defined(CONFIG_NFS_V4_1)
1925        struct nfs4_session *session;
1926        struct nfs4_slot_table *tp;
1927        struct nfs4_slot *slot = args->sa_slot;
1928        __be32 *p;
1929
1930        tp = slot->table;
1931        session = tp->session;
1932        if (!session)
1933                return;
1934
1935        encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1936
1937        /*
1938         * Sessionid + seqid + slotid + max slotid + cache_this
1939         */
1940        dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1941                "max_slotid=%d cache_this=%d\n",
1942                __func__,
1943                ((u32 *)session->sess_id.data)[0],
1944                ((u32 *)session->sess_id.data)[1],
1945                ((u32 *)session->sess_id.data)[2],
1946                ((u32 *)session->sess_id.data)[3],
1947                slot->seq_nr, slot->slot_nr,
1948                tp->highest_used_slotid, args->sa_cache_this);
1949        p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1950        p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1951        *p++ = cpu_to_be32(slot->seq_nr);
1952        *p++ = cpu_to_be32(slot->slot_nr);
1953        *p++ = cpu_to_be32(tp->highest_used_slotid);
1954        *p = cpu_to_be32(args->sa_cache_this);
1955#endif /* CONFIG_NFS_V4_1 */
1956}
1957
1958#ifdef CONFIG_NFS_V4_1
1959static void
1960encode_getdeviceinfo(struct xdr_stream *xdr,
1961                     const struct nfs4_getdeviceinfo_args *args,
1962                     struct compound_hdr *hdr)
1963{
1964        __be32 *p;
1965
1966        encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1967        p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1968        p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1969                                    NFS4_DEVICEID4_SIZE);
1970        *p++ = cpu_to_be32(args->pdev->layout_type);
1971        *p++ = cpu_to_be32(args->pdev->maxcount);       /* gdia_maxcount */
1972
1973        p = reserve_space(xdr, 4 + 4);
1974        *p++ = cpu_to_be32(1);                  /* bitmap length */
1975        *p++ = cpu_to_be32(args->notify_types);
1976}
1977
1978static void
1979encode_layoutget(struct xdr_stream *xdr,
1980                      const struct nfs4_layoutget_args *args,
1981                      struct compound_hdr *hdr)
1982{
1983        __be32 *p;
1984
1985        encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1986        p = reserve_space(xdr, 36);
1987        *p++ = cpu_to_be32(0);     /* Signal layout available */
1988        *p++ = cpu_to_be32(args->type);
1989        *p++ = cpu_to_be32(args->range.iomode);
1990        p = xdr_encode_hyper(p, args->range.offset);
1991        p = xdr_encode_hyper(p, args->range.length);
1992        p = xdr_encode_hyper(p, args->minlength);
1993        encode_nfs4_stateid(xdr, &args->stateid);
1994        encode_uint32(xdr, args->maxcount);
1995
1996        dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1997                __func__,
1998                args->type,
1999                args->range.iomode,
2000                (unsigned long)args->range.offset,
2001                (unsigned long)args->range.length,
2002                args->maxcount);
2003}
2004
2005static int
2006encode_layoutcommit(struct xdr_stream *xdr,
2007                    struct inode *inode,
2008                    const struct nfs4_layoutcommit_args *args,
2009                    struct compound_hdr *hdr)
2010{
2011        __be32 *p;
2012
2013        dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2014                NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2015
2016        encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2017        p = reserve_space(xdr, 20);
2018        /* Only whole file layouts */
2019        p = xdr_encode_hyper(p, 0); /* offset */
2020        p = xdr_encode_hyper(p, args->lastbytewritten + 1);     /* length */
2021        *p = cpu_to_be32(0); /* reclaim */
2022        encode_nfs4_stateid(xdr, &args->stateid);
2023        if (args->lastbytewritten != U64_MAX) {
2024                p = reserve_space(xdr, 20);
2025                *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2026                p = xdr_encode_hyper(p, args->lastbytewritten);
2027        } else {
2028                p = reserve_space(xdr, 12);
2029                *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2030        }
2031        *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2032        *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2033
2034        encode_uint32(xdr, args->layoutupdate_len);
2035        if (args->layoutupdate_pages)
2036                xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2037                                args->layoutupdate_len);
2038
2039        return 0;
2040}
2041
2042static void
2043encode_layoutreturn(struct xdr_stream *xdr,
2044                    const struct nfs4_layoutreturn_args *args,
2045                    struct compound_hdr *hdr)
2046{
2047        __be32 *p;
2048
2049        encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2050        p = reserve_space(xdr, 16);
2051        *p++ = cpu_to_be32(0);          /* reclaim. always 0 for now */
2052        *p++ = cpu_to_be32(args->layout_type);
2053        *p++ = cpu_to_be32(args->range.iomode);
2054        *p = cpu_to_be32(RETURN_FILE);
2055        p = reserve_space(xdr, 16);
2056        p = xdr_encode_hyper(p, args->range.offset);
2057        p = xdr_encode_hyper(p, args->range.length);
2058        spin_lock(&args->inode->i_lock);
2059        encode_nfs4_stateid(xdr, &args->stateid);
2060        spin_unlock(&args->inode->i_lock);
2061        if (args->ld_private->ops && args->ld_private->ops->encode)
2062                args->ld_private->ops->encode(xdr, args, args->ld_private);
2063        else
2064                encode_uint32(xdr, 0);
2065}
2066
2067static int
2068encode_secinfo_no_name(struct xdr_stream *xdr,
2069                       const struct nfs41_secinfo_no_name_args *args,
2070                       struct compound_hdr *hdr)
2071{
2072        encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2073        encode_uint32(xdr, args->style);
2074        return 0;
2075}
2076
2077static void encode_test_stateid(struct xdr_stream *xdr,
2078                                const struct nfs41_test_stateid_args *args,
2079                                struct compound_hdr *hdr)
2080{
2081        encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2082        encode_uint32(xdr, 1);
2083        encode_nfs4_stateid(xdr, args->stateid);
2084}
2085
2086static void encode_free_stateid(struct xdr_stream *xdr,
2087                                const struct nfs41_free_stateid_args *args,
2088                                struct compound_hdr *hdr)
2089{
2090        encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2091        encode_nfs4_stateid(xdr, &args->stateid);
2092}
2093#else
2094static inline void
2095encode_layoutreturn(struct xdr_stream *xdr,
2096                    const struct nfs4_layoutreturn_args *args,
2097                    struct compound_hdr *hdr)
2098{
2099}
2100
2101static void
2102encode_layoutget(struct xdr_stream *xdr,
2103                      const struct nfs4_layoutget_args *args,
2104                      struct compound_hdr *hdr)
2105{
2106}
2107#endif /* CONFIG_NFS_V4_1 */
2108
2109/*
2110 * END OF "GENERIC" ENCODE ROUTINES.
2111 */
2112
2113static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2114{
2115#if defined(CONFIG_NFS_V4_1)
2116        struct nfs4_session *session = args->sa_slot->table->session;
2117        if (session)
2118                return session->clp->cl_mvops->minor_version;
2119#endif /* CONFIG_NFS_V4_1 */
2120        return 0;
2121}
2122
2123/*
2124 * Encode an ACCESS request
2125 */
2126static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2127                                const void *data)
2128{
2129        const struct nfs4_accessargs *args = data;
2130        struct compound_hdr hdr = {
2131                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2132        };
2133
2134        encode_compound_hdr(xdr, req, &hdr);
2135        encode_sequence(xdr, &args->seq_args, &hdr);
2136        encode_putfh(xdr, args->fh, &hdr);
2137        encode_access(xdr, args->access, &hdr);
2138        if (args->bitmask)
2139                encode_getfattr(xdr, args->bitmask, &hdr);
2140        encode_nops(&hdr);
2141}
2142
2143/*
2144 * Encode LOOKUP request
2145 */
2146static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2147                                const void *data)
2148{
2149        const struct nfs4_lookup_arg *args = data;
2150        struct compound_hdr hdr = {
2151                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2152        };
2153
2154        encode_compound_hdr(xdr, req, &hdr);
2155        encode_sequence(xdr, &args->seq_args, &hdr);
2156        encode_putfh(xdr, args->dir_fh, &hdr);
2157        encode_lookup(xdr, args->name, &hdr);
2158        encode_getfh(xdr, &hdr);
2159        encode_getfattr(xdr, args->bitmask, &hdr);
2160        encode_nops(&hdr);
2161}
2162
2163/*
2164 * Encode LOOKUPP request
2165 */
2166static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2167                const void *data)
2168{
2169        const struct nfs4_lookupp_arg *args = data;
2170        struct compound_hdr hdr = {
2171                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2172        };
2173
2174        encode_compound_hdr(xdr, req, &hdr);
2175        encode_sequence(xdr, &args->seq_args, &hdr);
2176        encode_putfh(xdr, args->fh, &hdr);
2177        encode_lookupp(xdr, &hdr);
2178        encode_getfh(xdr, &hdr);
2179        encode_getfattr(xdr, args->bitmask, &hdr);
2180        encode_nops(&hdr);
2181}
2182
2183/*
2184 * Encode LOOKUP_ROOT request
2185 */
2186static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2187                                     struct xdr_stream *xdr,
2188                                     const void *data)
2189{
2190        const struct nfs4_lookup_root_arg *args = data;
2191        struct compound_hdr hdr = {
2192                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2193        };
2194
2195        encode_compound_hdr(xdr, req, &hdr);
2196        encode_sequence(xdr, &args->seq_args, &hdr);
2197        encode_putrootfh(xdr, &hdr);
2198        encode_getfh(xdr, &hdr);
2199        encode_getfattr(xdr, args->bitmask, &hdr);
2200        encode_nops(&hdr);
2201}
2202
2203/*
2204 * Encode REMOVE request
2205 */
2206static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2207                                const void *data)
2208{
2209        const struct nfs_removeargs *args = data;
2210        struct compound_hdr hdr = {
2211                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2212        };
2213
2214        encode_compound_hdr(xdr, req, &hdr);
2215        encode_sequence(xdr, &args->seq_args, &hdr);
2216        encode_putfh(xdr, args->fh, &hdr);
2217        encode_remove(xdr, &args->name, &hdr);
2218        encode_nops(&hdr);
2219}
2220
2221/*
2222 * Encode RENAME request
2223 */
2224static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2225                                const void *data)
2226{
2227        const struct nfs_renameargs *args = data;
2228        struct compound_hdr hdr = {
2229                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2230        };
2231
2232        encode_compound_hdr(xdr, req, &hdr);
2233        encode_sequence(xdr, &args->seq_args, &hdr);
2234        encode_putfh(xdr, args->old_dir, &hdr);
2235        encode_savefh(xdr, &hdr);
2236        encode_putfh(xdr, args->new_dir, &hdr);
2237        encode_rename(xdr, args->old_name, args->new_name, &hdr);
2238        encode_nops(&hdr);
2239}
2240
2241/*
2242 * Encode LINK request
2243 */
2244static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2245                              const void *data)
2246{
2247        const struct nfs4_link_arg *args = data;
2248        struct compound_hdr hdr = {
2249                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2250        };
2251
2252        encode_compound_hdr(xdr, req, &hdr);
2253        encode_sequence(xdr, &args->seq_args, &hdr);
2254        encode_putfh(xdr, args->fh, &hdr);
2255        encode_savefh(xdr, &hdr);
2256        encode_putfh(xdr, args->dir_fh, &hdr);
2257        encode_link(xdr, args->name, &hdr);
2258        encode_restorefh(xdr, &hdr);
2259        encode_getfattr(xdr, args->bitmask, &hdr);
2260        encode_nops(&hdr);
2261}
2262
2263/*
2264 * Encode CREATE request
2265 */
2266static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2267                                const void *data)
2268{
2269        const struct nfs4_create_arg *args = data;
2270        struct compound_hdr hdr = {
2271                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2272        };
2273
2274        encode_compound_hdr(xdr, req, &hdr);
2275        encode_sequence(xdr, &args->seq_args, &hdr);
2276        encode_putfh(xdr, args->dir_fh, &hdr);
2277        encode_create(xdr, args, &hdr);
2278        encode_getfh(xdr, &hdr);
2279        encode_getfattr(xdr, args->bitmask, &hdr);
2280        encode_nops(&hdr);
2281}
2282
2283/*
2284 * Encode SYMLINK request
2285 */
2286static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2287                                 const void *data)
2288{
2289        const struct nfs4_create_arg *args = data;
2290
2291        nfs4_xdr_enc_create(req, xdr, args);
2292}
2293
2294/*
2295 * Encode GETATTR request
2296 */
2297static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2298                                 const void *data)
2299{
2300        const struct nfs4_getattr_arg *args = data;
2301        struct compound_hdr hdr = {
2302                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2303        };
2304
2305        encode_compound_hdr(xdr, req, &hdr);
2306        encode_sequence(xdr, &args->seq_args, &hdr);
2307        encode_putfh(xdr, args->fh, &hdr);
2308        encode_getfattr(xdr, args->bitmask, &hdr);
2309        encode_nops(&hdr);
2310}
2311
2312/*
2313 * Encode a CLOSE request
2314 */
2315static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2316                               const void *data)
2317{
2318        const struct nfs_closeargs *args = data;
2319        struct compound_hdr hdr = {
2320                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2321        };
2322
2323        encode_compound_hdr(xdr, req, &hdr);
2324        encode_sequence(xdr, &args->seq_args, &hdr);
2325        encode_putfh(xdr, args->fh, &hdr);
2326        if (args->lr_args)
2327                encode_layoutreturn(xdr, args->lr_args, &hdr);
2328        if (args->bitmask != NULL)
2329                encode_getfattr(xdr, args->bitmask, &hdr);
2330        encode_close(xdr, args, &hdr);
2331        encode_nops(&hdr);
2332}
2333
2334/*
2335 * Encode an OPEN request
2336 */
2337static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2338                              const void *data)
2339{
2340        const struct nfs_openargs *args = data;
2341        struct compound_hdr hdr = {
2342                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2343        };
2344
2345        encode_compound_hdr(xdr, req, &hdr);
2346        encode_sequence(xdr, &args->seq_args, &hdr);
2347        encode_putfh(xdr, args->fh, &hdr);
2348        encode_open(xdr, args, &hdr);
2349        encode_getfh(xdr, &hdr);
2350        if (args->access)
2351                encode_access(xdr, args->access, &hdr);
2352        encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2353        if (args->lg_args) {
2354                encode_layoutget(xdr, args->lg_args, &hdr);
2355                rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2356                                        args->lg_args->layout.pglen,
2357                                        hdr.replen - pagepad_maxsz);
2358        }
2359        encode_nops(&hdr);
2360}
2361
2362/*
2363 * Encode an OPEN_CONFIRM request
2364 */
2365static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2366                                      struct xdr_stream *xdr,
2367                                      const void *data)
2368{
2369        const struct nfs_open_confirmargs *args = data;
2370        struct compound_hdr hdr = {
2371                .nops   = 0,
2372        };
2373
2374        encode_compound_hdr(xdr, req, &hdr);
2375        encode_putfh(xdr, args->fh, &hdr);
2376        encode_open_confirm(xdr, args, &hdr);
2377        encode_nops(&hdr);
2378}
2379
2380/*
2381 * Encode an OPEN request with no attributes.
2382 */
2383static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2384                                     struct xdr_stream *xdr,
2385                                     const void *data)
2386{
2387        const struct nfs_openargs *args = data;
2388        struct compound_hdr hdr = {
2389                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2390        };
2391
2392        encode_compound_hdr(xdr, req, &hdr);
2393        encode_sequence(xdr, &args->seq_args, &hdr);
2394        encode_putfh(xdr, args->fh, &hdr);
2395        encode_open(xdr, args, &hdr);
2396        if (args->access)
2397                encode_access(xdr, args->access, &hdr);
2398        encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2399        if (args->lg_args) {
2400                encode_layoutget(xdr, args->lg_args, &hdr);
2401                rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2402                                        args->lg_args->layout.pglen,
2403                                        hdr.replen - pagepad_maxsz);
2404        }
2405        encode_nops(&hdr);
2406}
2407
2408/*
2409 * Encode an OPEN_DOWNGRADE request
2410 */
2411static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2412                                        struct xdr_stream *xdr,
2413                                        const void *data)
2414{
2415        const struct nfs_closeargs *args = data;
2416        struct compound_hdr hdr = {
2417                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2418        };
2419
2420        encode_compound_hdr(xdr, req, &hdr);
2421        encode_sequence(xdr, &args->seq_args, &hdr);
2422        encode_putfh(xdr, args->fh, &hdr);
2423        if (args->lr_args)
2424                encode_layoutreturn(xdr, args->lr_args, &hdr);
2425        encode_open_downgrade(xdr, args, &hdr);
2426        encode_nops(&hdr);
2427}
2428
2429/*
2430 * Encode a LOCK request
2431 */
2432static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2433                              const void *data)
2434{
2435        const struct nfs_lock_args *args = data;
2436        struct compound_hdr hdr = {
2437                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2438        };
2439
2440        encode_compound_hdr(xdr, req, &hdr);
2441        encode_sequence(xdr, &args->seq_args, &hdr);
2442        encode_putfh(xdr, args->fh, &hdr);
2443        encode_lock(xdr, args, &hdr);
2444        encode_nops(&hdr);
2445}
2446
2447/*
2448 * Encode a LOCKT request
2449 */
2450static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2451                               const void *data)
2452{
2453        const struct nfs_lockt_args *args = data;
2454        struct compound_hdr hdr = {
2455                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2456        };
2457
2458        encode_compound_hdr(xdr, req, &hdr);
2459        encode_sequence(xdr, &args->seq_args, &hdr);
2460        encode_putfh(xdr, args->fh, &hdr);
2461        encode_lockt(xdr, args, &hdr);
2462        encode_nops(&hdr);
2463}
2464
2465/*
2466 * Encode a LOCKU request
2467 */
2468static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2469                               const void *data)
2470{
2471        const struct nfs_locku_args *args = data;
2472        struct compound_hdr hdr = {
2473                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2474        };
2475
2476        encode_compound_hdr(xdr, req, &hdr);
2477        encode_sequence(xdr, &args->seq_args, &hdr);
2478        encode_putfh(xdr, args->fh, &hdr);
2479        encode_locku(xdr, args, &hdr);
2480        encode_nops(&hdr);
2481}
2482
2483static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2484                                           struct xdr_stream *xdr,
2485                                           const void *data)
2486{
2487        const struct nfs_release_lockowner_args *args = data;
2488        struct compound_hdr hdr = {
2489                .minorversion = 0,
2490        };
2491
2492        encode_compound_hdr(xdr, req, &hdr);
2493        encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2494        encode_nops(&hdr);
2495}
2496
2497/*
2498 * Encode a READLINK request
2499 */
2500static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2501                                  const void *data)
2502{
2503        const struct nfs4_readlink *args = data;
2504        struct compound_hdr hdr = {
2505                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2506        };
2507
2508        encode_compound_hdr(xdr, req, &hdr);
2509        encode_sequence(xdr, &args->seq_args, &hdr);
2510        encode_putfh(xdr, args->fh, &hdr);
2511        encode_readlink(xdr, args, req, &hdr);
2512
2513        rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2514                                args->pglen, hdr.replen - pagepad_maxsz);
2515        encode_nops(&hdr);
2516}
2517
2518/*
2519 * Encode a READDIR request
2520 */
2521static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2522                                 const void *data)
2523{
2524        const struct nfs4_readdir_arg *args = data;
2525        struct compound_hdr hdr = {
2526                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2527        };
2528
2529        encode_compound_hdr(xdr, req, &hdr);
2530        encode_sequence(xdr, &args->seq_args, &hdr);
2531        encode_putfh(xdr, args->fh, &hdr);
2532        encode_readdir(xdr, args, req, &hdr);
2533
2534        rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2535                                args->count, hdr.replen - pagepad_maxsz);
2536        encode_nops(&hdr);
2537}
2538
2539/*
2540 * Encode a READ request
2541 */
2542static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2543                              const void *data)
2544{
2545        const struct nfs_pgio_args *args = data;
2546        struct compound_hdr hdr = {
2547                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2548        };
2549
2550        encode_compound_hdr(xdr, req, &hdr);
2551        encode_sequence(xdr, &args->seq_args, &hdr);
2552        encode_putfh(xdr, args->fh, &hdr);
2553        encode_read(xdr, args, &hdr);
2554
2555        rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2556                                args->count, hdr.replen - pagepad_maxsz);
2557        req->rq_rcv_buf.flags |= XDRBUF_READ;
2558        encode_nops(&hdr);
2559}
2560
2561/*
2562 * Encode an SETATTR request
2563 */
2564static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2565                                 const void *data)
2566{
2567        const struct nfs_setattrargs *args = data;
2568        struct compound_hdr hdr = {
2569                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2570        };
2571
2572        encode_compound_hdr(xdr, req, &hdr);
2573        encode_sequence(xdr, &args->seq_args, &hdr);
2574        encode_putfh(xdr, args->fh, &hdr);
2575        encode_setattr(xdr, args, args->server, &hdr);
2576        encode_getfattr(xdr, args->bitmask, &hdr);
2577        encode_nops(&hdr);
2578}
2579
2580/*
2581 * Encode a GETACL request
2582 */
2583static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2584                                const void *data)
2585{
2586        const struct nfs_getaclargs *args = data;
2587        struct compound_hdr hdr = {
2588                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2589        };
2590        const __u32 nfs4_acl_bitmap[1] = {
2591                [0] = FATTR4_WORD0_ACL,
2592        };
2593        uint32_t replen;
2594
2595        encode_compound_hdr(xdr, req, &hdr);
2596        encode_sequence(xdr, &args->seq_args, &hdr);
2597        encode_putfh(xdr, args->fh, &hdr);
2598        replen = hdr.replen + op_decode_hdr_maxsz;
2599        encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2600                        ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
2601
2602        rpc_prepare_reply_pages(req, args->acl_pages, 0,
2603                                args->acl_len, replen);
2604        encode_nops(&hdr);
2605}
2606
2607/*
2608 * Encode a WRITE request
2609 */
2610static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2611                               const void *data)
2612{
2613        const struct nfs_pgio_args *args = data;
2614        struct compound_hdr hdr = {
2615                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2616        };
2617
2618        encode_compound_hdr(xdr, req, &hdr);
2619        encode_sequence(xdr, &args->seq_args, &hdr);
2620        encode_putfh(xdr, args->fh, &hdr);
2621        encode_write(xdr, args, &hdr);
2622        req->rq_snd_buf.flags |= XDRBUF_WRITE;
2623        if (args->bitmask)
2624                encode_getfattr(xdr, args->bitmask, &hdr);
2625        encode_nops(&hdr);
2626}
2627
2628/*
2629 *  a COMMIT request
2630 */
2631static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2632                                const void *data)
2633{
2634        const struct nfs_commitargs *args = data;
2635        struct compound_hdr hdr = {
2636                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2637        };
2638
2639        encode_compound_hdr(xdr, req, &hdr);
2640        encode_sequence(xdr, &args->seq_args, &hdr);
2641        encode_putfh(xdr, args->fh, &hdr);
2642        encode_commit(xdr, args, &hdr);
2643        encode_nops(&hdr);
2644}
2645
2646/*
2647 * FSINFO request
2648 */
2649static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2650                                const void *data)
2651{
2652        const struct nfs4_fsinfo_arg *args = data;
2653        struct compound_hdr hdr = {
2654                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2655        };
2656
2657        encode_compound_hdr(xdr, req, &hdr);
2658        encode_sequence(xdr, &args->seq_args, &hdr);
2659        encode_putfh(xdr, args->fh, &hdr);
2660        encode_fsinfo(xdr, args->bitmask, &hdr);
2661        encode_nops(&hdr);
2662}
2663
2664/*
2665 * a PATHCONF request
2666 */
2667static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2668                                  const void *data)
2669{
2670        const struct nfs4_pathconf_arg *args = data;
2671        struct compound_hdr hdr = {
2672                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2673        };
2674
2675        encode_compound_hdr(xdr, req, &hdr);
2676        encode_sequence(xdr, &args->seq_args, &hdr);
2677        encode_putfh(xdr, args->fh, &hdr);
2678        encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2679                        ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
2680        encode_nops(&hdr);
2681}
2682
2683/*
2684 * a STATFS request
2685 */
2686static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2687                                const void *data)
2688{
2689        const struct nfs4_statfs_arg *args = data;
2690        struct compound_hdr hdr = {
2691                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2692        };
2693
2694        encode_compound_hdr(xdr, req, &hdr);
2695        encode_sequence(xdr, &args->seq_args, &hdr);
2696        encode_putfh(xdr, args->fh, &hdr);
2697        encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2698                        ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
2699        encode_nops(&hdr);
2700}
2701
2702/*
2703 * GETATTR_BITMAP request
2704 */
2705static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2706                                     struct xdr_stream *xdr,
2707                                     const void *data)
2708{
2709        const struct nfs4_server_caps_arg *args = data;
2710        const u32 *bitmask = args->bitmask;
2711        struct compound_hdr hdr = {
2712                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2713        };
2714
2715        encode_compound_hdr(xdr, req, &hdr);
2716        encode_sequence(xdr, &args->seq_args, &hdr);
2717        encode_putfh(xdr, args->fhandle, &hdr);
2718        encode_getattr(xdr, bitmask, NULL, 3, &hdr);
2719        encode_nops(&hdr);
2720}
2721
2722/*
2723 * a RENEW request
2724 */
2725static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2726                               const void *data)
2727
2728{
2729        const struct nfs_client *clp = data;
2730        struct compound_hdr hdr = {
2731                .nops   = 0,
2732        };
2733
2734        encode_compound_hdr(xdr, req, &hdr);
2735        encode_renew(xdr, clp->cl_clientid, &hdr);
2736        encode_nops(&hdr);
2737}
2738
2739/*
2740 * a SETCLIENTID request
2741 */
2742static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2743                                     struct xdr_stream *xdr,
2744                                     const void *data)
2745{
2746        const struct nfs4_setclientid *sc = data;
2747        struct compound_hdr hdr = {
2748                .nops   = 0,
2749        };
2750
2751        encode_compound_hdr(xdr, req, &hdr);
2752        encode_setclientid(xdr, sc, &hdr);
2753        encode_nops(&hdr);
2754}
2755
2756/*
2757 * a SETCLIENTID_CONFIRM request
2758 */
2759static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2760                                             struct xdr_stream *xdr,
2761                                             const void *data)
2762{
2763        const struct nfs4_setclientid_res *arg = data;
2764        struct compound_hdr hdr = {
2765                .nops   = 0,
2766        };
2767
2768        encode_compound_hdr(xdr, req, &hdr);
2769        encode_setclientid_confirm(xdr, arg, &hdr);
2770        encode_nops(&hdr);
2771}
2772
2773/*
2774 * DELEGRETURN request
2775 */
2776static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2777                                     struct xdr_stream *xdr,
2778                                     const void *data)
2779{
2780        const struct nfs4_delegreturnargs *args = data;
2781        struct compound_hdr hdr = {
2782                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2783        };
2784
2785        encode_compound_hdr(xdr, req, &hdr);
2786        encode_sequence(xdr, &args->seq_args, &hdr);
2787        encode_putfh(xdr, args->fhandle, &hdr);
2788        if (args->lr_args)
2789                encode_layoutreturn(xdr, args->lr_args, &hdr);
2790        if (args->bitmask)
2791                encode_getfattr(xdr, args->bitmask, &hdr);
2792        encode_delegreturn(xdr, args->stateid, &hdr);
2793        encode_nops(&hdr);
2794}
2795
2796/*
2797 * Encode FS_LOCATIONS request
2798 */
2799static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2800                                      struct xdr_stream *xdr,
2801                                      const void *data)
2802{
2803        const struct nfs4_fs_locations_arg *args = data;
2804        struct compound_hdr hdr = {
2805                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2806        };
2807        uint32_t replen;
2808
2809        encode_compound_hdr(xdr, req, &hdr);
2810        encode_sequence(xdr, &args->seq_args, &hdr);
2811        if (args->migration) {
2812                encode_putfh(xdr, args->fh, &hdr);
2813                replen = hdr.replen;
2814                encode_fs_locations(xdr, args->bitmask, &hdr);
2815                if (args->renew)
2816                        encode_renew(xdr, args->clientid, &hdr);
2817        } else {
2818                encode_putfh(xdr, args->dir_fh, &hdr);
2819                encode_lookup(xdr, args->name, &hdr);
2820                replen = hdr.replen;
2821                encode_fs_locations(xdr, args->bitmask, &hdr);
2822        }
2823
2824        rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
2825                                PAGE_SIZE, replen);
2826        encode_nops(&hdr);
2827}
2828
2829/*
2830 * Encode SECINFO request
2831 */
2832static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2833                                struct xdr_stream *xdr,
2834                                const void *data)
2835{
2836        const struct nfs4_secinfo_arg *args = data;
2837        struct compound_hdr hdr = {
2838                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2839        };
2840
2841        encode_compound_hdr(xdr, req, &hdr);
2842        encode_sequence(xdr, &args->seq_args, &hdr);
2843        encode_putfh(xdr, args->dir_fh, &hdr);
2844        encode_secinfo(xdr, args->name, &hdr);
2845        encode_nops(&hdr);
2846}
2847
2848/*
2849 * Encode FSID_PRESENT request
2850 */
2851static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2852                                      struct xdr_stream *xdr,
2853                                      const void *data)
2854{
2855        const struct nfs4_fsid_present_arg *args = data;
2856        struct compound_hdr hdr = {
2857                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2858        };
2859
2860        encode_compound_hdr(xdr, req, &hdr);
2861        encode_sequence(xdr, &args->seq_args, &hdr);
2862        encode_putfh(xdr, args->fh, &hdr);
2863        encode_getfh(xdr, &hdr);
2864        if (args->renew)
2865                encode_renew(xdr, args->clientid, &hdr);
2866        encode_nops(&hdr);
2867}
2868
2869#if defined(CONFIG_NFS_V4_1)
2870/*
2871 * BIND_CONN_TO_SESSION request
2872 */
2873static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2874                                struct xdr_stream *xdr,
2875                                const void *data)
2876{
2877        const struct nfs41_bind_conn_to_session_args *args = data;
2878        struct compound_hdr hdr = {
2879                .minorversion = args->client->cl_mvops->minor_version,
2880        };
2881
2882        encode_compound_hdr(xdr, req, &hdr);
2883        encode_bind_conn_to_session(xdr, args, &hdr);
2884        encode_nops(&hdr);
2885}
2886
2887/*
2888 * EXCHANGE_ID request
2889 */
2890static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2891                                     struct xdr_stream *xdr,
2892                                     const void *data)
2893{
2894        const struct nfs41_exchange_id_args *args = data;
2895        struct compound_hdr hdr = {
2896                .minorversion = args->client->cl_mvops->minor_version,
2897        };
2898
2899        encode_compound_hdr(xdr, req, &hdr);
2900        encode_exchange_id(xdr, args, &hdr);
2901        encode_nops(&hdr);
2902}
2903
2904/*
2905 * a CREATE_SESSION request
2906 */
2907static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2908                                        struct xdr_stream *xdr,
2909                                        const void *data)
2910{
2911        const struct nfs41_create_session_args *args = data;
2912        struct compound_hdr hdr = {
2913                .minorversion = args->client->cl_mvops->minor_version,
2914        };
2915
2916        encode_compound_hdr(xdr, req, &hdr);
2917        encode_create_session(xdr, args, &hdr);
2918        encode_nops(&hdr);
2919}
2920
2921/*
2922 * a DESTROY_SESSION request
2923 */
2924static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2925                                         struct xdr_stream *xdr,
2926                                         const void *data)
2927{
2928        const struct nfs4_session *session = data;
2929        struct compound_hdr hdr = {
2930                .minorversion = session->clp->cl_mvops->minor_version,
2931        };
2932
2933        encode_compound_hdr(xdr, req, &hdr);
2934        encode_destroy_session(xdr, session, &hdr);
2935        encode_nops(&hdr);
2936}
2937
2938/*
2939 * a DESTROY_CLIENTID request
2940 */
2941static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2942                                         struct xdr_stream *xdr,
2943                                         const void *data)
2944{
2945        const struct nfs_client *clp = data;
2946        struct compound_hdr hdr = {
2947                .minorversion = clp->cl_mvops->minor_version,
2948        };
2949
2950        encode_compound_hdr(xdr, req, &hdr);
2951        encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2952        encode_nops(&hdr);
2953}
2954
2955/*
2956 * a SEQUENCE request
2957 */
2958static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2959                                  const void *data)
2960{
2961        const struct nfs4_sequence_args *args = data;
2962        struct compound_hdr hdr = {
2963                .minorversion = nfs4_xdr_minorversion(args),
2964        };
2965
2966        encode_compound_hdr(xdr, req, &hdr);
2967        encode_sequence(xdr, args, &hdr);
2968        encode_nops(&hdr);
2969}
2970
2971#endif
2972
2973/*
2974 * a GET_LEASE_TIME request
2975 */
2976static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2977                                        struct xdr_stream *xdr,
2978                                        const void *data)
2979{
2980        const struct nfs4_get_lease_time_args *args = data;
2981        struct compound_hdr hdr = {
2982                .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2983        };
2984        const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2985
2986        encode_compound_hdr(xdr, req, &hdr);
2987        encode_sequence(xdr, &args->la_seq_args, &hdr);
2988        encode_putrootfh(xdr, &hdr);
2989        encode_fsinfo(xdr, lease_bitmap, &hdr);
2990        encode_nops(&hdr);
2991}
2992
2993#ifdef CONFIG_NFS_V4_1
2994
2995/*
2996 * a RECLAIM_COMPLETE request
2997 */
2998static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2999                                          struct xdr_stream *xdr,
3000                                          const void *data)
3001{
3002        const struct nfs41_reclaim_complete_args *args = data;
3003        struct compound_hdr hdr = {
3004                .minorversion = nfs4_xdr_minorversion(&args->seq_args)
3005        };
3006
3007        encode_compound_hdr(xdr, req, &hdr);
3008        encode_sequence(xdr, &args->seq_args, &hdr);
3009        encode_reclaim_complete(xdr, args, &hdr);
3010        encode_nops(&hdr);
3011}
3012
3013/*
3014 * Encode GETDEVICEINFO request
3015 */
3016static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3017                                       struct xdr_stream *xdr,
3018                                       const void *data)
3019{
3020        const struct nfs4_getdeviceinfo_args *args = data;
3021        struct compound_hdr hdr = {
3022                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3023        };
3024        uint32_t replen;
3025
3026        encode_compound_hdr(xdr, req, &hdr);
3027        encode_sequence(xdr, &args->seq_args, &hdr);
3028
3029        replen = hdr.replen + op_decode_hdr_maxsz + 2;
3030
3031        encode_getdeviceinfo(xdr, args, &hdr);
3032
3033        /* set up reply kvec. device_addr4 opaque data is read into the
3034         * pages */
3035        rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
3036                                args->pdev->pglen, replen);
3037        encode_nops(&hdr);
3038}
3039
3040/*
3041 *  Encode LAYOUTGET request
3042 */
3043static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3044                                   struct xdr_stream *xdr,
3045                                   const void *data)
3046{
3047        const struct nfs4_layoutget_args *args = data;
3048        struct compound_hdr hdr = {
3049                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3050        };
3051
3052        encode_compound_hdr(xdr, req, &hdr);
3053        encode_sequence(xdr, &args->seq_args, &hdr);
3054        encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3055        encode_layoutget(xdr, args, &hdr);
3056
3057        rpc_prepare_reply_pages(req, args->layout.pages, 0,
3058                                args->layout.pglen, hdr.replen - pagepad_maxsz);
3059        encode_nops(&hdr);
3060}
3061
3062/*
3063 *  Encode LAYOUTCOMMIT request
3064 */
3065static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3066                                      struct xdr_stream *xdr,
3067                                      const void *priv)
3068{
3069        const struct nfs4_layoutcommit_args *args = priv;
3070        struct nfs4_layoutcommit_data *data =
3071                container_of(args, struct nfs4_layoutcommit_data, args);
3072        struct compound_hdr hdr = {
3073                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3074        };
3075
3076        encode_compound_hdr(xdr, req, &hdr);
3077        encode_sequence(xdr, &args->seq_args, &hdr);
3078        encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3079        encode_layoutcommit(xdr, data->args.inode, args, &hdr);
3080        encode_getfattr(xdr, args->bitmask, &hdr);
3081        encode_nops(&hdr);
3082}
3083
3084/*
3085 * Encode LAYOUTRETURN request
3086 */
3087static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3088                                      struct xdr_stream *xdr,
3089                                      const void *data)
3090{
3091        const struct nfs4_layoutreturn_args *args = data;
3092        struct compound_hdr hdr = {
3093                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3094        };
3095
3096        encode_compound_hdr(xdr, req, &hdr);
3097        encode_sequence(xdr, &args->seq_args, &hdr);
3098        encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3099        encode_layoutreturn(xdr, args, &hdr);
3100        encode_nops(&hdr);
3101}
3102
3103/*
3104 * Encode SECINFO_NO_NAME request
3105 */
3106static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3107                                        struct xdr_stream *xdr,
3108                                        const void *data)
3109{
3110        const struct nfs41_secinfo_no_name_args *args = data;
3111        struct compound_hdr hdr = {
3112                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3113        };
3114
3115        encode_compound_hdr(xdr, req, &hdr);
3116        encode_sequence(xdr, &args->seq_args, &hdr);
3117        encode_putrootfh(xdr, &hdr);
3118        encode_secinfo_no_name(xdr, args, &hdr);
3119        encode_nops(&hdr);
3120}
3121
3122/*
3123 *  Encode TEST_STATEID request
3124 */
3125static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3126                                      struct xdr_stream *xdr,
3127                                      const void *data)
3128{
3129        const struct nfs41_test_stateid_args *args = data;
3130        struct compound_hdr hdr = {
3131                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3132        };
3133
3134        encode_compound_hdr(xdr, req, &hdr);
3135        encode_sequence(xdr, &args->seq_args, &hdr);
3136        encode_test_stateid(xdr, args, &hdr);
3137        encode_nops(&hdr);
3138}
3139
3140/*
3141 *  Encode FREE_STATEID request
3142 */
3143static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3144                                     struct xdr_stream *xdr,
3145                                     const void *data)
3146{
3147        const struct nfs41_free_stateid_args *args = data;
3148        struct compound_hdr hdr = {
3149                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3150        };
3151
3152        encode_compound_hdr(xdr, req, &hdr);
3153        encode_sequence(xdr, &args->seq_args, &hdr);
3154        encode_free_stateid(xdr, args, &hdr);
3155        encode_nops(&hdr);
3156}
3157#endif /* CONFIG_NFS_V4_1 */
3158
3159static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3160{
3161        ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3162                        NFS4_OPAQUE_LIMIT);
3163        if (unlikely(ret < 0))
3164                return -EIO;
3165        *len = ret;
3166        return 0;
3167}
3168
3169static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3170{
3171        ssize_t ret;
3172        void *ptr;
3173        u32 tmp;
3174
3175        if (xdr_stream_decode_u32(xdr, &tmp) < 0)
3176                return -EIO;
3177        hdr->status = tmp;
3178
3179        ret = xdr_stream_decode_opaque_inline(xdr, &ptr, NFS4_OPAQUE_LIMIT);
3180        if (ret < 0)
3181                return -EIO;
3182        hdr->taglen = ret;
3183        hdr->tag = ptr;
3184
3185        if (xdr_stream_decode_u32(xdr, &tmp) < 0)
3186                return -EIO;
3187        hdr->nops = tmp;
3188        if (unlikely(hdr->nops < 1))
3189                return nfs4_stat_to_errno(hdr->status);
3190        return 0;
3191}
3192
3193static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3194                int *nfs_retval)
3195{
3196        __be32 *p;
3197        uint32_t opnum;
3198        int32_t nfserr;
3199
3200        p = xdr_inline_decode(xdr, 8);
3201        if (unlikely(!p))
3202                goto out_overflow;
3203        opnum = be32_to_cpup(p++);
3204        if (unlikely(opnum != expected))
3205                goto out_bad_operation;
3206        if (unlikely(*p != cpu_to_be32(NFS_OK)))
3207                goto out_status;
3208        *nfs_retval = 0;
3209        return true;
3210out_status:
3211        nfserr = be32_to_cpup(p);
3212        trace_nfs4_xdr_status(xdr, opnum, nfserr);
3213        *nfs_retval = nfs4_stat_to_errno(nfserr);
3214        return true;
3215out_bad_operation:
3216        trace_nfs4_xdr_bad_operation(xdr, opnum, expected);
3217        *nfs_retval = -EREMOTEIO;
3218        return false;
3219out_overflow:
3220        *nfs_retval = -EIO;
3221        return false;
3222}
3223
3224static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3225{
3226        int retval;
3227
3228        __decode_op_hdr(xdr, expected, &retval);
3229        return retval;
3230}
3231
3232/* Dummy routine */
3233static int decode_ace(struct xdr_stream *xdr, void *ace)
3234{
3235        __be32 *p;
3236        unsigned int strlen;
3237        char *str;
3238
3239        p = xdr_inline_decode(xdr, 12);
3240        if (unlikely(!p))
3241                return -EIO;
3242        return decode_opaque_inline(xdr, &strlen, &str);
3243}
3244
3245static ssize_t
3246decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
3247{
3248        ssize_t ret;
3249
3250        ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3251        if (likely(ret >= 0))
3252                return ret;
3253        if (ret != -EMSGSIZE)
3254                return -EIO;
3255        return sz;
3256}
3257
3258static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3259{
3260        ssize_t ret;
3261        ret = decode_bitmap4(xdr, bitmap, 3);
3262        return ret < 0 ? ret : 0;
3263}
3264
3265static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3266{
3267        __be32 *p;
3268
3269        p = xdr_inline_decode(xdr, 4);
3270        if (unlikely(!p))
3271                return -EIO;
3272        *attrlen = be32_to_cpup(p);
3273        *savep = xdr_stream_pos(xdr);
3274        return 0;
3275}
3276
3277static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3278{
3279        if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3280                int ret;
3281                ret = decode_attr_bitmap(xdr, bitmask);
3282                if (unlikely(ret < 0))
3283                        return ret;
3284                bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3285        } else
3286                bitmask[0] = bitmask[1] = bitmask[2] = 0;
3287        dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3288                bitmask[0], bitmask[1], bitmask[2]);
3289        return 0;
3290}
3291
3292static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3293{
3294        __be32 *p;
3295        int ret = 0;
3296
3297        *type = 0;
3298        if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3299                return -EIO;
3300        if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3301                p = xdr_inline_decode(xdr, 4);
3302                if (unlikely(!p))
3303                        return -EIO;
3304                *type = be32_to_cpup(p);
3305                if (*type < NF4REG || *type > NF4NAMEDATTR) {
3306                        dprintk("%s: bad type %d\n", __func__, *type);
3307                        return -EIO;
3308                }
3309                bitmap[0] &= ~FATTR4_WORD0_TYPE;
3310                ret = NFS_ATTR_FATTR_TYPE;
3311        }
3312        dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3313        return ret;
3314}
3315
3316static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3317                                      uint32_t *bitmap, uint32_t *type)
3318{
3319        __be32 *p;
3320
3321        *type = 0;
3322        if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3323                return -EIO;
3324        if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3325                p = xdr_inline_decode(xdr, 4);
3326                if (unlikely(!p))
3327                        return -EIO;
3328                *type = be32_to_cpup(p);
3329                bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3330        }
3331        dprintk("%s: expire type=0x%x\n", __func__, *type);
3332        return 0;
3333}
3334
3335static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3336{
3337        __be32 *p;
3338        int ret = 0;
3339
3340        *change = 0;
3341        if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3342                return -EIO;
3343        if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3344                p = xdr_inline_decode(xdr, 8);
3345                if (unlikely(!p))
3346                        return -EIO;
3347                xdr_decode_hyper(p, change);
3348                bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3349                ret = NFS_ATTR_FATTR_CHANGE;
3350        }
3351        dprintk("%s: change attribute=%Lu\n", __func__,
3352                        (unsigned long long)*change);
3353        return ret;
3354}
3355
3356static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3357{
3358        __be32 *p;
3359        int ret = 0;
3360
3361        *size = 0;
3362        if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3363                return -EIO;
3364        if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3365                p = xdr_inline_decode(xdr, 8);
3366                if (unlikely(!p))
3367                        return -EIO;
3368                xdr_decode_hyper(p, size);
3369                bitmap[0] &= ~FATTR4_WORD0_SIZE;
3370                ret = NFS_ATTR_FATTR_SIZE;
3371        }
3372        dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3373        return ret;
3374}
3375
3376static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3377{
3378        __be32 *p;
3379
3380        *res = 0;
3381        if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3382                return -EIO;
3383        if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3384                p = xdr_inline_decode(xdr, 4);
3385                if (unlikely(!p))
3386                        return -EIO;
3387                *res = be32_to_cpup(p);
3388                bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3389        }
3390        dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3391        return 0;
3392}
3393
3394static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3395{
3396        __be32 *p;
3397
3398        *res = 0;
3399        if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3400                return -EIO;
3401        if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3402                p = xdr_inline_decode(xdr, 4);
3403                if (unlikely(!p))
3404                        return -EIO;
3405                *res = be32_to_cpup(p);
3406                bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3407        }
3408        dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3409        return 0;
3410}
3411
3412static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3413{
3414        __be32 *p;
3415        int ret = 0;
3416
3417        fsid->major = 0;
3418        fsid->minor = 0;
3419        if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3420                return -EIO;
3421        if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3422                p = xdr_inline_decode(xdr, 16);
3423                if (unlikely(!p))
3424                        return -EIO;
3425                p = xdr_decode_hyper(p, &fsid->major);
3426                xdr_decode_hyper(p, &fsid->minor);
3427                bitmap[0] &= ~FATTR4_WORD0_FSID;
3428                ret = NFS_ATTR_FATTR_FSID;
3429        }
3430        dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3431                        (unsigned long long)fsid->major,
3432                        (unsigned long long)fsid->minor);
3433        return ret;
3434}
3435
3436static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3437{
3438        __be32 *p;
3439
3440        *res = 60;
3441        if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3442                return -EIO;
3443        if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3444                p = xdr_inline_decode(xdr, 4);
3445                if (unlikely(!p))
3446                        return -EIO;
3447                *res = be32_to_cpup(p);
3448                bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3449        }
3450        dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
3451        return 0;
3452}
3453
3454static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3455{
3456        __be32 *p;
3457
3458        if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3459                return -EIO;
3460        if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3461                p = xdr_inline_decode(xdr, 4);
3462                if (unlikely(!p))
3463                        return -EIO;
3464                bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3465                *res = -be32_to_cpup(p);
3466        }
3467        return 0;
3468}
3469
3470static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3471                                 uint32_t *bitmap, uint32_t *bitmask)
3472{
3473        if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3474                int ret;
3475                ret = decode_attr_bitmap(xdr, bitmask);
3476                if (unlikely(ret < 0))
3477                        return ret;
3478                bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3479        } else
3480                bitmask[0] = bitmask[1] = bitmask[2] = 0;
3481        dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3482                bitmask[0], bitmask[1], bitmask[2]);
3483        return 0;
3484}
3485
3486static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3487{
3488        __be32 *p;
3489        u32 len;
3490
3491        if (fh != NULL)
3492                memset(fh, 0, sizeof(*fh));
3493
3494        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3495                return -EIO;
3496        if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3497                p = xdr_inline_decode(xdr, 4);
3498                if (unlikely(!p))
3499                        return -EIO;
3500                len = be32_to_cpup(p);
3501                if (len > NFS4_FHSIZE || len == 0) {
3502                        trace_nfs4_xdr_bad_filehandle(xdr, OP_READDIR,
3503                                                      NFS4ERR_BADHANDLE);
3504                        return -EREMOTEIO;
3505                }
3506                p = xdr_inline_decode(xdr, len);
3507                if (unlikely(!p))
3508                        return -EIO;
3509                if (fh != NULL) {
3510                        memcpy(fh->data, p, len);
3511                        fh->size = len;
3512                }
3513                bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3514        }
3515        return 0;
3516}
3517
3518static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3519{
3520        __be32 *p;
3521
3522        *res = 0;
3523        if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3524                return -EIO;
3525        if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3526                p = xdr_inline_decode(xdr, 4);
3527                if (unlikely(!p))
3528                        return -EIO;
3529                *res = be32_to_cpup(p);
3530                bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3531        }
3532        dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3533        return 0;
3534}
3535
3536static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3537{
3538        __be32 *p;
3539        int ret = 0;
3540
3541        *fileid = 0;
3542        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3543                return -EIO;
3544        if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3545                p = xdr_inline_decode(xdr, 8);
3546                if (unlikely(!p))
3547                        return -EIO;
3548                xdr_decode_hyper(p, fileid);
3549                bitmap[0] &= ~FATTR4_WORD0_FILEID;
3550                ret = NFS_ATTR_FATTR_FILEID;
3551        }
3552        dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3553        return ret;
3554}
3555
3556static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3557{
3558        __be32 *p;
3559        int ret = 0;
3560
3561        *fileid = 0;
3562        if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3563                return -EIO;
3564        if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3565                p = xdr_inline_decode(xdr, 8);
3566                if (unlikely(!p))
3567                        return -EIO;
3568                xdr_decode_hyper(p, fileid);
3569                bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3570                ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3571        }
3572        dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3573        return ret;
3574}
3575
3576static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3577{
3578        __be32 *p;
3579        int status = 0;
3580
3581        *res = 0;
3582        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3583                return -EIO;
3584        if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3585                p = xdr_inline_decode(xdr, 8);
3586                if (unlikely(!p))
3587                        return -EIO;
3588                xdr_decode_hyper(p, res);
3589                bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3590        }
3591        dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3592        return status;
3593}
3594
3595static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3596{
3597        __be32 *p;
3598        int status = 0;
3599
3600        *res = 0;
3601        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3602                return -EIO;
3603        if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3604                p = xdr_inline_decode(xdr, 8);
3605                if (unlikely(!p))
3606                        return -EIO;
3607                xdr_decode_hyper(p, res);
3608                bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3609        }
3610        dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3611        return status;
3612}
3613
3614static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3615{
3616        __be32 *p;
3617        int status = 0;
3618
3619        *res = 0;
3620        if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3621                return -EIO;
3622        if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3623                p = xdr_inline_decode(xdr, 8);
3624                if (unlikely(!p))
3625                        return -EIO;
3626                xdr_decode_hyper(p, res);
3627                bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3628        }
3629        dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3630        return status;
3631}
3632
3633static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3634{
3635        u32 n;
3636        __be32 *p;
3637        int status = 0;
3638
3639        p = xdr_inline_decode(xdr, 4);
3640        if (unlikely(!p))
3641                return -EIO;
3642        n = be32_to_cpup(p);
3643        if (n == 0)
3644                goto root_path;
3645        dprintk("pathname4: ");
3646        if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3647                dprintk("cannot parse %d components in path\n", n);
3648                goto out_eio;
3649        }
3650        for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3651                struct nfs4_string *component = &path->components[path->ncomponents];
3652                status = decode_opaque_inline(xdr, &component->len, &component->data);
3653                if (unlikely(status != 0))
3654                        goto out_eio;
3655                ifdebug (XDR)
3656                        pr_cont("%s%.*s ",
3657                                (path->ncomponents != n ? "/ " : ""),
3658                                component->len, component->data);
3659        }
3660out:
3661        return status;
3662root_path:
3663/* a root pathname is sent as a zero component4 */
3664        path->ncomponents = 1;
3665        path->components[0].len=0;
3666        path->components[0].data=NULL;
3667        dprintk("pathname4: /\n");
3668        goto out;
3669out_eio:
3670        dprintk(" status %d", status);
3671        status = -EIO;
3672        goto out;
3673}
3674
3675static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3676{
3677        int n;
3678        __be32 *p;
3679        int status = -EIO;
3680
3681        if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3682                goto out;
3683        status = 0;
3684        if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3685                goto out;
3686        bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
3687        status = -EIO;
3688        /* Ignore borken servers that return unrequested attrs */
3689        if (unlikely(res == NULL))
3690                goto out;
3691        dprintk("%s: fsroot:\n", __func__);
3692        status = decode_pathname(xdr, &res->fs_path);
3693        if (unlikely(status != 0))
3694                goto out;
3695        p = xdr_inline_decode(xdr, 4);
3696        if (unlikely(!p))
3697                goto out_eio;
3698        n = be32_to_cpup(p);
3699        if (n <= 0)
3700                goto out_eio;
3701        for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3702                u32 m;
3703                struct nfs4_fs_location *loc;
3704
3705                if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3706                        break;
3707                loc = &res->locations[res->nlocations];
3708                p = xdr_inline_decode(xdr, 4);
3709                if (unlikely(!p))
3710                        goto out_eio;
3711                m = be32_to_cpup(p);
3712
3713                dprintk("%s: servers:\n", __func__);
3714                for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3715                        struct nfs4_string *server;
3716
3717                        if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3718                                unsigned int i;
3719                                dprintk("%s: using first %u of %u servers "
3720                                        "returned for location %u\n",
3721                                                __func__,
3722                                                NFS4_FS_LOCATION_MAXSERVERS,
3723                                                m, res->nlocations);
3724                                for (i = loc->nservers; i < m; i++) {
3725                                        unsigned int len;
3726                                        char *data;
3727                                        status = decode_opaque_inline(xdr, &len, &data);
3728                                        if (unlikely(status != 0))
3729                                                goto out_eio;
3730                                }
3731                                break;
3732                        }
3733                        server = &loc->servers[loc->nservers];
3734                        status = decode_opaque_inline(xdr, &server->len, &server->data);
3735                        if (unlikely(status != 0))
3736                                goto out_eio;
3737                        dprintk("%s ", server->data);
3738                }
3739                status = decode_pathname(xdr, &loc->rootpath);
3740                if (unlikely(status != 0))
3741                        goto out_eio;
3742        }
3743        if (res->nlocations != 0)
3744                status = NFS_ATTR_FATTR_V4_LOCATIONS;
3745out:
3746        dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3747        return status;
3748out_eio:
3749        status = -EIO;
3750        goto out;
3751}
3752
3753static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3754{
3755        __be32 *p;
3756        int status = 0;
3757
3758        *res = 0;
3759        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3760                return -EIO;
3761        if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3762                p = xdr_inline_decode(xdr, 8);
3763                if (unlikely(!p))
3764                        return -EIO;
3765                xdr_decode_hyper(p, res);
3766                bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3767        }
3768        dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3769        return status;
3770}
3771
3772static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3773{
3774        __be32 *p;
3775        int status = 0;
3776
3777        *maxlink = 1;
3778        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3779                return -EIO;
3780        if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3781                p = xdr_inline_decode(xdr, 4);
3782                if (unlikely(!p))
3783                        return -EIO;
3784                *maxlink = be32_to_cpup(p);
3785                bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3786        }
3787        dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3788        return status;
3789}
3790
3791static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3792{
3793        __be32 *p;
3794        int status = 0;
3795
3796        *maxname = 1024;
3797        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3798                return -EIO;
3799        if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3800                p = xdr_inline_decode(xdr, 4);
3801                if (unlikely(!p))
3802                        return -EIO;
3803                *maxname = be32_to_cpup(p);
3804                bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3805        }
3806        dprintk("%s: maxname=%u\n", __func__, *maxname);
3807        return status;
3808}
3809
3810static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3811{
3812        __be32 *p;
3813        int status = 0;
3814
3815        *res = 1024;
3816        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3817                return -EIO;
3818        if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3819                uint64_t maxread;
3820                p = xdr_inline_decode(xdr, 8);
3821                if (unlikely(!p))
3822                        return -EIO;
3823                xdr_decode_hyper(p, &maxread);
3824                if (maxread > 0x7FFFFFFF)
3825                        maxread = 0x7FFFFFFF;
3826                *res = (uint32_t)maxread;
3827                bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3828        }
3829        dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3830        return status;
3831}
3832
3833static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3834{
3835        __be32 *p;
3836        int status = 0;
3837
3838        *res = 1024;
3839        if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3840                return -EIO;
3841        if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3842                uint64_t maxwrite;
3843                p = xdr_inline_decode(xdr, 8);
3844                if (unlikely(!p))
3845                        return -EIO;
3846                xdr_decode_hyper(p, &maxwrite);
3847                if (maxwrite > 0x7FFFFFFF)
3848                        maxwrite = 0x7FFFFFFF;
3849                *res = (uint32_t)maxwrite;
3850                bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3851        }
3852        dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3853        return status;
3854}
3855
3856static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3857{
3858        uint32_t tmp;
3859        __be32 *p;
3860        int ret = 0;
3861
3862        *mode = 0;
3863        if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3864                return -EIO;
3865        if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3866                p = xdr_inline_decode(xdr, 4);
3867                if (unlikely(!p))
3868                        return -EIO;
3869                tmp = be32_to_cpup(p);
3870                *mode = tmp & ~S_IFMT;
3871                bitmap[1] &= ~FATTR4_WORD1_MODE;
3872                ret = NFS_ATTR_FATTR_MODE;
3873        }
3874        dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3875        return ret;
3876}
3877
3878static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3879{
3880        __be32 *p;
3881        int ret = 0;
3882
3883        *nlink = 1;
3884        if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3885                return -EIO;
3886        if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3887                p = xdr_inline_decode(xdr, 4);
3888                if (unlikely(!p))
3889                        return -EIO;
3890                *nlink = be32_to_cpup(p);
3891                bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3892                ret = NFS_ATTR_FATTR_NLINK;
3893        }
3894        dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3895        return ret;
3896}
3897
3898static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3899                struct nfs4_string *name, gfp_t gfp_flags)
3900{
3901        ssize_t ret;
3902
3903        ret = xdr_stream_decode_string_dup(xdr, &name->data,
3904                        XDR_MAX_NETOBJ, gfp_flags);
3905        name->len = 0;
3906        if (ret > 0)
3907                name->len = ret;
3908        return ret;
3909}
3910
3911static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3912                const struct nfs_server *server, kuid_t *uid,
3913                struct nfs4_string *owner_name)
3914{
3915        ssize_t len;
3916        char *p;
3917
3918        *uid = make_kuid(&init_user_ns, -2);
3919        if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3920                return -EIO;
3921        if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3922                return 0;
3923        bitmap[1] &= ~FATTR4_WORD1_OWNER;
3924
3925        if (owner_name != NULL) {
3926                len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
3927                if (len <= 0)
3928                        goto out;
3929                dprintk("%s: name=%s\n", __func__, owner_name->data);
3930                return NFS_ATTR_FATTR_OWNER_NAME;
3931        } else {
3932                len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3933                                XDR_MAX_NETOBJ);
3934                if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3935                        goto out;
3936                dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3937                return NFS_ATTR_FATTR_OWNER;
3938        }
3939out:
3940        if (len == -EBADMSG)
3941                return -EIO;
3942        return 0;
3943}
3944
3945static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3946                const struct nfs_server *server, kgid_t *gid,
3947                struct nfs4_string *group_name)
3948{
3949        ssize_t len;
3950        char *p;
3951
3952        *gid = make_kgid(&init_user_ns, -2);
3953        if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3954                return -EIO;
3955        if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3956                return 0;
3957        bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3958
3959        if (group_name != NULL) {
3960                len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
3961                if (len <= 0)
3962                        goto out;
3963                dprintk("%s: name=%s\n", __func__, group_name->data);
3964                return NFS_ATTR_FATTR_GROUP_NAME;
3965        } else {
3966                len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3967                                XDR_MAX_NETOBJ);
3968                if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3969                        goto out;
3970                dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3971                return NFS_ATTR_FATTR_GROUP;
3972        }
3973out:
3974        if (len == -EBADMSG)
3975                return -EIO;
3976        return 0;
3977}
3978
3979static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3980{
3981        uint32_t major = 0, minor = 0;
3982        __be32 *p;
3983        int ret = 0;
3984
3985        *rdev = MKDEV(0,0);
3986        if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3987                return -EIO;
3988        if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3989                dev_t tmp;
3990
3991                p = xdr_inline_decode(xdr, 8);
3992                if (unlikely(!p))
3993                        return -EIO;
3994                major = be32_to_cpup(p++);
3995                minor = be32_to_cpup(p);
3996                tmp = MKDEV(major, minor);
3997                if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3998                        *rdev = tmp;
3999                bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
4000                ret = NFS_ATTR_FATTR_RDEV;
4001        }
4002        dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
4003        return ret;
4004}
4005
4006static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4007{
4008        __be32 *p;
4009        int status = 0;
4010
4011        *res = 0;
4012        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4013                return -EIO;
4014        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4015                p = xdr_inline_decode(xdr, 8);
4016                if (unlikely(!p))
4017                        return -EIO;
4018                xdr_decode_hyper(p, res);
4019                bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4020        }
4021        dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
4022        return status;
4023}
4024
4025static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4026{
4027        __be32 *p;
4028        int status = 0;
4029
4030        *res = 0;
4031        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4032                return -EIO;
4033        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4034                p = xdr_inline_decode(xdr, 8);
4035                if (unlikely(!p))
4036                        return -EIO;
4037                xdr_decode_hyper(p, res);
4038                bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4039        }
4040        dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
4041        return status;
4042}
4043
4044static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4045{
4046        __be32 *p;
4047        int status = 0;
4048
4049        *res = 0;
4050        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4051                return -EIO;
4052        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4053                p = xdr_inline_decode(xdr, 8);
4054                if (unlikely(!p))
4055                        return -EIO;
4056                xdr_decode_hyper(p, res);
4057                bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4058        }
4059        dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4060        return status;
4061}
4062
4063static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4064{
4065        __be32 *p;
4066        int ret = 0;
4067
4068        *used = 0;
4069        if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4070                return -EIO;
4071        if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4072                p = xdr_inline_decode(xdr, 8);
4073                if (unlikely(!p))
4074                        return -EIO;
4075                xdr_decode_hyper(p, used);
4076                bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4077                ret = NFS_ATTR_FATTR_SPACE_USED;
4078        }
4079        dprintk("%s: space used=%Lu\n", __func__,
4080                        (unsigned long long)*used);
4081        return ret;
4082}
4083
4084static __be32 *
4085xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
4086{
4087        __u64 sec;
4088
4089        p = xdr_decode_hyper(p, &sec);
4090        t-> tv_sec = sec;
4091        t->tv_nsec = be32_to_cpup(p++);
4092        return p;
4093}
4094
4095static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
4096{
4097        __be32 *p;
4098
4099        p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
4100        if (unlikely(!p))
4101                return -EIO;
4102        xdr_decode_nfstime4(p, time);
4103        return 0;
4104}
4105
4106static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4107{
4108        int status = 0;
4109
4110        time->tv_sec = 0;
4111        time->tv_nsec = 0;
4112        if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4113                return -EIO;
4114        if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4115                status = decode_attr_time(xdr, time);
4116                if (status == 0)
4117                        status = NFS_ATTR_FATTR_ATIME;
4118                bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4119        }
4120        dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
4121        return status;
4122}
4123
4124static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4125{
4126        int status = 0;
4127
4128        time->tv_sec = 0;
4129        time->tv_nsec = 0;
4130        if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4131                return -EIO;
4132        if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4133                status = decode_attr_time(xdr, time);
4134                if (status == 0)
4135                        status = NFS_ATTR_FATTR_CTIME;
4136                bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4137        }
4138        dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
4139        return status;
4140}
4141
4142static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4143                                  struct timespec64 *time)
4144{
4145        int status = 0;
4146
4147        time->tv_sec = 0;
4148        time->tv_nsec = 0;
4149        if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4150                return -EIO;
4151        if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4152                status = decode_attr_time(xdr, time);
4153                bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4154        }
4155        dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4156                time->tv_nsec);
4157        return status;
4158}
4159
4160static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4161                                        struct nfs4_label *label)
4162{
4163        uint32_t pi = 0;
4164        uint32_t lfs = 0;
4165        __u32 len;
4166        __be32 *p;
4167        int status = 0;
4168
4169        if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4170                return -EIO;
4171        if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4172                p = xdr_inline_decode(xdr, 4);
4173                if (unlikely(!p))
4174                        return -EIO;
4175                lfs = be32_to_cpup(p++);
4176                p = xdr_inline_decode(xdr, 4);
4177                if (unlikely(!p))
4178                        return -EIO;
4179                pi = be32_to_cpup(p++);
4180                p = xdr_inline_decode(xdr, 4);
4181                if (unlikely(!p))
4182                        return -EIO;
4183                len = be32_to_cpup(p++);
4184                p = xdr_inline_decode(xdr, len);
4185                if (unlikely(!p))
4186                        return -EIO;
4187                if (len < NFS4_MAXLABELLEN) {
4188                        if (label) {
4189                                if (label->len) {
4190                                        if (label->len < len)
4191                                                return -ERANGE;
4192                                        memcpy(label->label, p, len);
4193                                }
4194                                label->len = len;
4195                                label->pi = pi;
4196                                label->lfs = lfs;
4197                                status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4198                        }
4199                        bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4200                } else
4201                        printk(KERN_WARNING "%s: label too long (%u)!\n",
4202                                        __func__, len);
4203        }
4204        if (label && label->label)
4205                dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4206                        (char *)label->label, label->len, label->pi, label->lfs);
4207        return status;
4208}
4209
4210static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4211{
4212        int status = 0;
4213
4214        time->tv_sec = 0;
4215        time->tv_nsec = 0;
4216        if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4217                return -EIO;
4218        if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4219                status = decode_attr_time(xdr, time);
4220                if (status == 0)
4221                        status = NFS_ATTR_FATTR_MTIME;
4222                bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4223        }
4224        dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
4225        return status;
4226}
4227
4228static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
4229                                    uint32_t *res)
4230{
4231        __be32 *p;
4232
4233        *res = 0;
4234        if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
4235                return -EIO;
4236        if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
4237                p = xdr_inline_decode(xdr, 4);
4238                if (unlikely(!p))
4239                        return -EIO;
4240                *res = be32_to_cpup(p);
4241                bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
4242        }
4243        dprintk("%s: XATTR support=%s\n", __func__,
4244                *res == 0 ? "false" : "true");
4245        return 0;
4246}
4247
4248static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4249{
4250        unsigned int attrwords = XDR_QUADLEN(attrlen);
4251        unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4252
4253        if (unlikely(attrwords != nwords)) {
4254                dprintk("%s: server returned incorrect attribute length: "
4255                        "%u %c %u\n",
4256                                __func__,
4257                                attrwords << 2,
4258                                (attrwords < nwords) ? '<' : '>',
4259                                nwords << 2);
4260                return -EIO;
4261        }
4262        return 0;
4263}
4264
4265static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4266{
4267        __be32 *p;
4268
4269        p = xdr_inline_decode(xdr, 20);
4270        if (unlikely(!p))
4271                return -EIO;
4272        cinfo->atomic = be32_to_cpup(p++);
4273        p = xdr_decode_hyper(p, &cinfo->before);
4274        xdr_decode_hyper(p, &cinfo->after);
4275        return 0;
4276}
4277
4278static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4279{
4280        __be32 *p;
4281        uint32_t supp, acc;
4282        int status;
4283
4284        status = decode_op_hdr(xdr, OP_ACCESS);
4285        if (status)
4286                return status;
4287        p = xdr_inline_decode(xdr, 8);
4288        if (unlikely(!p))
4289                return -EIO;
4290        supp = be32_to_cpup(p++);
4291        acc = be32_to_cpup(p);
4292        *supported = supp;
4293        *access = acc;
4294        return 0;
4295}
4296
4297static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4298{
4299        ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4300        if (unlikely(ret < 0))
4301                return -EIO;
4302        return 0;
4303}
4304
4305static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4306{
4307        return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4308}
4309
4310static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4311{
4312        stateid->type = NFS4_OPEN_STATEID_TYPE;
4313        return decode_stateid(xdr, stateid);
4314}
4315
4316static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4317{
4318        stateid->type = NFS4_LOCK_STATEID_TYPE;
4319        return decode_stateid(xdr, stateid);
4320}
4321
4322static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4323{
4324        stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4325        return decode_stateid(xdr, stateid);
4326}
4327
4328static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4329{
4330        nfs4_stateid dummy;
4331
4332        nfs4_stateid_copy(stateid, &invalid_stateid);
4333        return decode_stateid(xdr, &dummy);
4334}
4335
4336static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4337{
4338        int status;
4339
4340        status = decode_op_hdr(xdr, OP_CLOSE);
4341        if (status != -EIO)
4342                nfs_increment_open_seqid(status, res->seqid);
4343        if (!status)
4344                status = decode_invalid_stateid(xdr, &res->stateid);
4345        return status;
4346}
4347
4348static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4349{
4350        return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4351}
4352
4353static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4354{
4355        return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4356}
4357
4358static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4359{
4360        struct nfs_writeverf *verf = res->verf;
4361        int status;
4362
4363        status = decode_op_hdr(xdr, OP_COMMIT);
4364        if (!status)
4365                status = decode_write_verifier(xdr, &verf->verifier);
4366        if (!status)
4367                verf->committed = NFS_FILE_SYNC;
4368        return status;
4369}
4370
4371static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4372{
4373        __be32 *p;
4374        uint32_t bmlen;
4375        int status;
4376
4377        status = decode_op_hdr(xdr, OP_CREATE);
4378        if (status)
4379                return status;
4380        if ((status = decode_change_info(xdr, cinfo)))
4381                return status;
4382        p = xdr_inline_decode(xdr, 4);
4383        if (unlikely(!p))
4384                return -EIO;
4385        bmlen = be32_to_cpup(p);
4386        p = xdr_inline_decode(xdr, bmlen << 2);
4387        if (likely(p))
4388                return 0;
4389        return -EIO;
4390}
4391
4392static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4393{
4394        unsigned int savep;
4395        uint32_t attrlen, bitmap[3] = {0};
4396        int status;
4397
4398        if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4399                goto xdr_error;
4400        if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4401                goto xdr_error;
4402        if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4403                goto xdr_error;
4404        if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4405                goto xdr_error;
4406        if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4407                                                 &res->fh_expire_type)) != 0)
4408                goto xdr_error;
4409        if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4410                goto xdr_error;
4411        if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4412                goto xdr_error;
4413        if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4414                goto xdr_error;
4415        if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4416                                res->exclcreat_bitmask)) != 0)
4417                goto xdr_error;
4418        status = verify_attr_len(xdr, savep, attrlen);
4419xdr_error:
4420        dprintk("%s: xdr returned %d!\n", __func__, -status);
4421        return status;
4422}
4423
4424static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4425{
4426        unsigned int savep;
4427        uint32_t attrlen, bitmap[3] = {0};
4428        int status;
4429
4430        if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4431                goto xdr_error;
4432        if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4433                goto xdr_error;
4434        if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4435                goto xdr_error;
4436
4437        if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4438                goto xdr_error;
4439        if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4440                goto xdr_error;
4441        if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4442                goto xdr_error;
4443
4444        status = -EIO;
4445        if (unlikely(bitmap[0]))
4446                goto xdr_error;
4447
4448        if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4449                goto xdr_error;
4450        if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4451                goto xdr_error;
4452        if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4453                goto xdr_error;
4454
4455        status = verify_attr_len(xdr, savep, attrlen);
4456xdr_error:
4457        dprintk("%s: xdr returned %d!\n", __func__, -status);
4458        return status;
4459}
4460
4461static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4462{
4463        unsigned int savep;
4464        uint32_t attrlen, bitmap[3] = {0};
4465        int status;
4466
4467        if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4468                goto xdr_error;
4469        if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4470                goto xdr_error;
4471        if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4472                goto xdr_error;
4473
4474        if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4475                goto xdr_error;
4476        if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4477                goto xdr_error;
4478
4479        status = verify_attr_len(xdr, savep, attrlen);
4480xdr_error:
4481        dprintk("%s: xdr returned %d!\n", __func__, -status);
4482        return status;
4483}
4484
4485static int decode_threshold_hint(struct xdr_stream *xdr,
4486                                  uint32_t *bitmap,
4487                                  uint64_t *res,
4488                                  uint32_t hint_bit)
4489{
4490        __be32 *p;
4491
4492        *res = 0;
4493        if (likely(bitmap[0] & hint_bit)) {
4494                p = xdr_inline_decode(xdr, 8);
4495                if (unlikely(!p))
4496                        return -EIO;
4497                xdr_decode_hyper(p, res);
4498        }
4499        return 0;
4500}
4501
4502static int decode_first_threshold_item4(struct xdr_stream *xdr,
4503                                        struct nfs4_threshold *res)
4504{
4505        __be32 *p;
4506        unsigned int savep;
4507        uint32_t bitmap[3] = {0,}, attrlen;
4508        int status;
4509
4510        /* layout type */
4511        p = xdr_inline_decode(xdr, 4);
4512        if (unlikely(!p))
4513                return -EIO;
4514        res->l_type = be32_to_cpup(p);
4515
4516        /* thi_hintset bitmap */
4517        status = decode_attr_bitmap(xdr, bitmap);
4518        if (status < 0)
4519                goto xdr_error;
4520
4521        /* thi_hintlist length */
4522        status = decode_attr_length(xdr, &attrlen, &savep);
4523        if (status < 0)
4524                goto xdr_error;
4525        /* thi_hintlist */
4526        status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4527        if (status < 0)
4528                goto xdr_error;
4529        status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4530        if (status < 0)
4531                goto xdr_error;
4532        status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4533                                       THRESHOLD_RD_IO);
4534        if (status < 0)
4535                goto xdr_error;
4536        status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4537                                       THRESHOLD_WR_IO);
4538        if (status < 0)
4539                goto xdr_error;
4540
4541        status = verify_attr_len(xdr, savep, attrlen);
4542        res->bm = bitmap[0];
4543
4544        dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4545                 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4546                res->wr_io_sz);
4547xdr_error:
4548        dprintk("%s ret=%d!\n", __func__, status);
4549        return status;
4550}
4551
4552/*
4553 * Thresholds on pNFS direct I/O vrs MDS I/O
4554 */
4555static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4556                                    uint32_t *bitmap,
4557                                    struct nfs4_threshold *res)
4558{
4559        __be32 *p;
4560        int status = 0;
4561        uint32_t num;
4562
4563        if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4564                return -EIO;
4565        if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4566                /* Did the server return an unrequested attribute? */
4567                if (unlikely(res == NULL))
4568                        return -EREMOTEIO;
4569                p = xdr_inline_decode(xdr, 4);
4570                if (unlikely(!p))
4571                        return -EIO;
4572                num = be32_to_cpup(p);
4573                if (num == 0)
4574                        return 0;
4575                if (num > 1)
4576                        printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4577                                "drivers per filesystem not supported\n",
4578                                __func__);
4579
4580                status = decode_first_threshold_item4(xdr, res);
4581                bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4582        }
4583        return status;
4584}
4585
4586static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4587                struct nfs_fattr *fattr, struct nfs_fh *fh,
4588                struct nfs4_fs_locations *fs_loc, const struct nfs_server *server)
4589{
4590        int status;
4591        umode_t fmode = 0;
4592        uint32_t type;
4593        int32_t err;
4594
4595        status = decode_attr_type(xdr, bitmap, &type);
4596        if (status < 0)
4597                goto xdr_error;
4598        fattr->mode = 0;
4599        if (status != 0) {
4600                fattr->mode |= nfs_type2fmt[type];
4601                fattr->valid |= status;
4602        }
4603
4604        status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4605        if (status < 0)
4606                goto xdr_error;
4607        fattr->valid |= status;
4608
4609        status = decode_attr_size(xdr, bitmap, &fattr->size);
4610        if (status < 0)
4611                goto xdr_error;
4612        fattr->valid |= status;
4613
4614        status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4615        if (status < 0)
4616                goto xdr_error;
4617        fattr->valid |= status;
4618
4619        err = 0;
4620        status = decode_attr_error(xdr, bitmap, &err);
4621        if (status < 0)
4622                goto xdr_error;
4623
4624        status = decode_attr_filehandle(xdr, bitmap, fh);
4625        if (status < 0)
4626                goto xdr_error;
4627
4628        status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4629        if (status < 0)
4630                goto xdr_error;
4631        fattr->valid |= status;
4632
4633        status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4634        if (status < 0)
4635                goto xdr_error;
4636        fattr->valid |= status;
4637
4638        status = -EIO;
4639        if (unlikely(bitmap[0]))
4640                goto xdr_error;
4641
4642        status = decode_attr_mode(xdr, bitmap, &fmode);
4643        if (status < 0)
4644                goto xdr_error;
4645        if (status != 0) {
4646                fattr->mode |= fmode;
4647                fattr->valid |= status;
4648        }
4649
4650        status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4651        if (status < 0)
4652                goto xdr_error;
4653        fattr->valid |= status;
4654
4655        status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4656        if (status < 0)
4657                goto xdr_error;
4658        fattr->valid |= status;
4659
4660        status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4661        if (status < 0)
4662                goto xdr_error;
4663        fattr->valid |= status;
4664
4665        status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4666        if (status < 0)
4667                goto xdr_error;
4668        fattr->valid |= status;
4669
4670        status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4671        if (status < 0)
4672                goto xdr_error;
4673        fattr->valid |= status;
4674
4675        status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4676        if (status < 0)
4677                goto xdr_error;
4678        fattr->valid |= status;
4679
4680        status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4681        if (status < 0)
4682                goto xdr_error;
4683        fattr->valid |= status;
4684
4685        status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4686        if (status < 0)
4687                goto xdr_error;
4688        fattr->valid |= status;
4689
4690        status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4691        if (status < 0)
4692                goto xdr_error;
4693        fattr->valid |= status;
4694
4695        status = -EIO;
4696        if (unlikely(bitmap[1]))
4697                goto xdr_error;
4698
4699        status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4700        if (status < 0)
4701                goto xdr_error;
4702
4703        if (fattr->label) {
4704                status = decode_attr_security_label(xdr, bitmap, fattr->label);
4705                if (status < 0)
4706                        goto xdr_error;
4707                fattr->valid |= status;
4708        }
4709
4710xdr_error:
4711        dprintk("%s: xdr returned %d\n", __func__, -status);
4712        return status;
4713}
4714
4715static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4716                struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4717                const struct nfs_server *server)
4718{
4719        unsigned int savep;
4720        uint32_t attrlen,
4721                 bitmap[3] = {0};
4722        int status;
4723
4724        status = decode_op_hdr(xdr, OP_GETATTR);
4725        if (status < 0)
4726                goto xdr_error;
4727
4728        status = decode_attr_bitmap(xdr, bitmap);
4729        if (status < 0)
4730                goto xdr_error;
4731
4732        status = decode_attr_length(xdr, &attrlen, &savep);
4733        if (status < 0)
4734                goto xdr_error;
4735
4736        status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4737        if (status < 0)
4738                goto xdr_error;
4739
4740        status = verify_attr_len(xdr, savep, attrlen);
4741xdr_error:
4742        dprintk("%s: xdr returned %d\n", __func__, -status);
4743        return status;
4744}
4745
4746static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4747                const struct nfs_server *server)
4748{
4749        return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4750}
4751
4752/*
4753 * Decode potentially multiple layout types.
4754 */
4755static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4756                                    struct nfs_fsinfo *fsinfo)
4757{
4758        __be32 *p;
4759        uint32_t i;
4760
4761        p = xdr_inline_decode(xdr, 4);
4762        if (unlikely(!p))
4763                return -EIO;
4764        fsinfo->nlayouttypes = be32_to_cpup(p);
4765
4766        /* pNFS is not supported by the underlying file system */
4767        if (fsinfo->nlayouttypes == 0)
4768                return 0;
4769
4770        /* Decode and set first layout type, move xdr->p past unused types */
4771        p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4772        if (unlikely(!p))
4773                return -EIO;
4774
4775        /* If we get too many, then just cap it at the max */
4776        if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4777                printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4778                        __func__, fsinfo->nlayouttypes);
4779                fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4780        }
4781
4782        for(i = 0; i < fsinfo->nlayouttypes; ++i)
4783                fsinfo->layouttype[i] = be32_to_cpup(p++);
4784        return 0;
4785}
4786
4787/*
4788 * The type of file system exported.
4789 * Note we must ensure that layouttype is set in any non-error case.
4790 */
4791static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4792                                struct nfs_fsinfo *fsinfo)
4793{
4794        int status = 0;
4795
4796        dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4797        if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4798                return -EIO;
4799        if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4800                status = decode_pnfs_layout_types(xdr, fsinfo);
4801                bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4802        }
4803        return status;
4804}
4805
4806/*
4807 * The prefered block size for layout directed io
4808 */
4809static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4810                                      uint32_t *res)
4811{
4812        __be32 *p;
4813
4814        dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4815        *res = 0;
4816        if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4817                p = xdr_inline_decode(xdr, 4);
4818                if (unlikely(!p))
4819                        return -EIO;
4820                *res = be32_to_cpup(p);
4821                bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4822        }
4823        return 0;
4824}
4825
4826/*
4827 * The granularity of a CLONE operation.
4828 */
4829static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4830                                     uint32_t *res)
4831{
4832        __be32 *p;
4833
4834        dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4835        *res = 0;
4836        if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4837                p = xdr_inline_decode(xdr, 4);
4838                if (unlikely(!p))
4839                        return -EIO;
4840                *res = be32_to_cpup(p);
4841                bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4842        }
4843        return 0;
4844}
4845
4846static int decode_attr_change_attr_type(struct xdr_stream *xdr,
4847                                        uint32_t *bitmap,
4848                                        enum nfs4_change_attr_type *res)
4849{
4850        u32 tmp = NFS4_CHANGE_TYPE_IS_UNDEFINED;
4851
4852        dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4853        if (bitmap[2] & FATTR4_WORD2_CHANGE_ATTR_TYPE) {
4854                if (xdr_stream_decode_u32(xdr, &tmp))
4855                        return -EIO;
4856                bitmap[2] &= ~FATTR4_WORD2_CHANGE_ATTR_TYPE;
4857        }
4858
4859        switch(tmp) {
4860        case NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR:
4861        case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER:
4862        case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS:
4863        case NFS4_CHANGE_TYPE_IS_TIME_METADATA:
4864                *res = tmp;
4865                break;
4866        default:
4867                *res = NFS4_CHANGE_TYPE_IS_UNDEFINED;
4868        }
4869        return 0;
4870}
4871
4872static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4873{
4874        unsigned int savep;
4875        uint32_t attrlen, bitmap[3];
4876        int status;
4877
4878        if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4879                goto xdr_error;
4880        if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4881                goto xdr_error;
4882        if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4883                goto xdr_error;
4884
4885        fsinfo->rtmult = fsinfo->wtmult = 512;  /* ??? */
4886
4887        if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4888                goto xdr_error;
4889        if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4890                goto xdr_error;
4891        if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4892                goto xdr_error;
4893        fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4894        if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4895                goto xdr_error;
4896        fsinfo->wtpref = fsinfo->wtmax;
4897
4898        status = -EIO;
4899        if (unlikely(bitmap[0]))
4900                goto xdr_error;
4901
4902        status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4903        if (status != 0)
4904                goto xdr_error;
4905        status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4906        if (status != 0)
4907                goto xdr_error;
4908
4909        status = -EIO;
4910        if (unlikely(bitmap[1]))
4911                goto xdr_error;
4912
4913        status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4914        if (status)
4915                goto xdr_error;
4916        status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4917        if (status)
4918                goto xdr_error;
4919
4920        status = decode_attr_change_attr_type(xdr, bitmap,
4921                                              &fsinfo->change_attr_type);
4922        if (status)
4923                goto xdr_error;
4924
4925        status = decode_attr_xattrsupport(xdr, bitmap,
4926                                          &fsinfo->xattr_support);
4927        if (status)
4928                goto xdr_error;
4929
4930        status = verify_attr_len(xdr, savep, attrlen);
4931xdr_error:
4932        dprintk("%s: xdr returned %d!\n", __func__, -status);
4933        return status;
4934}
4935
4936static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4937{
4938        __be32 *p;
4939        uint32_t len;
4940        int status;
4941
4942        /* Zero handle first to allow comparisons */
4943        memset(fh, 0, sizeof(*fh));
4944
4945        status = decode_op_hdr(xdr, OP_GETFH);
4946        if (status)
4947                return status;
4948
4949        p = xdr_inline_decode(xdr, 4);
4950        if (unlikely(!p))
4951                return -EIO;
4952        len = be32_to_cpup(p);
4953        if (len > NFS4_FHSIZE || len == 0) {
4954                trace_nfs4_xdr_bad_filehandle(xdr, OP_GETFH, NFS4ERR_BADHANDLE);
4955                return -EREMOTEIO;
4956        }
4957        fh->size = len;
4958        p = xdr_inline_decode(xdr, len);
4959        if (unlikely(!p))
4960                return -EIO;
4961        memcpy(fh->data, p, len);
4962        return 0;
4963}
4964
4965static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4966{
4967        int status;
4968
4969        status = decode_op_hdr(xdr, OP_LINK);
4970        if (status)
4971                return status;
4972        return decode_change_info(xdr, cinfo);
4973}
4974
4975/*
4976 * We create the owner, so we know a proper owner.id length is 4.
4977 */
4978static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4979{
4980        uint64_t offset, length, clientid;
4981        __be32 *p;
4982        uint32_t namelen, type;
4983
4984        p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4985        if (unlikely(!p))
4986                return -EIO;
4987        p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4988        p = xdr_decode_hyper(p, &length);
4989        type = be32_to_cpup(p++); /* 4 byte read */
4990        if (fl != NULL) { /* manipulate file lock */
4991                fl->fl_start = (loff_t)offset;
4992                fl->fl_end = fl->fl_start + (loff_t)length - 1;
4993                if (length == ~(uint64_t)0)
4994                        fl->fl_end = OFFSET_MAX;
4995                fl->fl_type = F_WRLCK;
4996                if (type & 1)
4997                        fl->fl_type = F_RDLCK;
4998                fl->fl_pid = 0;
4999        }
5000        p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5001        namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
5002        p = xdr_inline_decode(xdr, namelen); /* variable size field */
5003        if (likely(!p))
5004                return -EIO;
5005        return -NFS4ERR_DENIED;
5006}
5007
5008static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
5009{
5010        int status;
5011
5012        status = decode_op_hdr(xdr, OP_LOCK);
5013        if (status == -EIO)
5014                goto out;
5015        if (status == 0) {
5016                status = decode_lock_stateid(xdr, &res->stateid);
5017                if (unlikely(status))
5018                        goto out;
5019        } else if (status == -NFS4ERR_DENIED)
5020                status = decode_lock_denied(xdr, NULL);
5021        if (res->open_seqid != NULL)
5022                nfs_increment_open_seqid(status, res->open_seqid);
5023        nfs_increment_lock_seqid(status, res->lock_seqid);
5024out:
5025        return status;
5026}
5027
5028static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
5029{
5030        int status;
5031        status = decode_op_hdr(xdr, OP_LOCKT);
5032        if (status == -NFS4ERR_DENIED)
5033                return decode_lock_denied(xdr, res->denied);
5034        return status;
5035}
5036
5037static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
5038{
5039        int status;
5040
5041        status = decode_op_hdr(xdr, OP_LOCKU);
5042        if (status != -EIO)
5043                nfs_increment_lock_seqid(status, res->seqid);
5044        if (status == 0)
5045                status = decode_lock_stateid(xdr, &res->stateid);
5046        return status;
5047}
5048
5049static int decode_release_lockowner(struct xdr_stream *xdr)
5050{
5051        return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5052}
5053
5054static int decode_lookup(struct xdr_stream *xdr)
5055{
5056        return decode_op_hdr(xdr, OP_LOOKUP);
5057}
5058
5059static int decode_lookupp(struct xdr_stream *xdr)
5060{
5061        return decode_op_hdr(xdr, OP_LOOKUPP);
5062}
5063
5064/* This is too sick! */
5065static int decode_space_limit(struct xdr_stream *xdr,
5066                unsigned long *pagemod_limit)
5067{
5068        __be32 *p;
5069        uint32_t limit_type, nblocks, blocksize;
5070        u64 maxsize = 0;
5071
5072        p = xdr_inline_decode(xdr, 12);
5073        if (unlikely(!p))
5074                return -EIO;
5075        limit_type = be32_to_cpup(p++);
5076        switch (limit_type) {
5077        case NFS4_LIMIT_SIZE:
5078                xdr_decode_hyper(p, &maxsize);
5079                break;
5080        case NFS4_LIMIT_BLOCKS:
5081                nblocks = be32_to_cpup(p++);
5082                blocksize = be32_to_cpup(p);
5083                maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
5084        }
5085        maxsize >>= PAGE_SHIFT;
5086        *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
5087        return 0;
5088}
5089
5090static int decode_rw_delegation(struct xdr_stream *xdr,
5091                uint32_t delegation_type,
5092                struct nfs_openres *res)
5093{
5094        __be32 *p;
5095        int status;
5096
5097        status = decode_delegation_stateid(xdr, &res->delegation);
5098        if (unlikely(status))
5099                return status;
5100        p = xdr_inline_decode(xdr, 4);
5101        if (unlikely(!p))
5102                return -EIO;
5103        res->do_recall = be32_to_cpup(p);
5104
5105        switch (delegation_type) {
5106        case NFS4_OPEN_DELEGATE_READ:
5107                res->delegation_type = FMODE_READ;
5108                break;
5109        case NFS4_OPEN_DELEGATE_WRITE:
5110                res->delegation_type = FMODE_WRITE|FMODE_READ;
5111                if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
5112                                return -EIO;
5113        }
5114        return decode_ace(xdr, NULL);
5115}
5116
5117static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5118{
5119        __be32 *p;
5120        uint32_t why_no_delegation;
5121
5122        p = xdr_inline_decode(xdr, 4);
5123        if (unlikely(!p))
5124                return -EIO;
5125        why_no_delegation = be32_to_cpup(p);
5126        switch (why_no_delegation) {
5127                case WND4_CONTENTION:
5128                case WND4_RESOURCE:
5129                        xdr_inline_decode(xdr, 4);
5130                        /* Ignore for now */
5131        }
5132        return 0;
5133}
5134
5135static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5136{
5137        __be32 *p;
5138        uint32_t delegation_type;
5139
5140        p = xdr_inline_decode(xdr, 4);
5141        if (unlikely(!p))
5142                return -EIO;
5143        delegation_type = be32_to_cpup(p);
5144        res->delegation_type = 0;
5145        switch (delegation_type) {
5146        case NFS4_OPEN_DELEGATE_NONE:
5147                return 0;
5148        case NFS4_OPEN_DELEGATE_READ:
5149        case NFS4_OPEN_DELEGATE_WRITE:
5150                return decode_rw_delegation(xdr, delegation_type, res);
5151        case NFS4_OPEN_DELEGATE_NONE_EXT:
5152                return decode_no_delegation(xdr, res);
5153        }
5154        return -EIO;
5155}
5156
5157static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5158{
5159        __be32 *p;
5160        uint32_t savewords, bmlen, i;
5161        int status;
5162
5163        if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5164                return status;
5165        nfs_increment_open_seqid(status, res->seqid);
5166        if (status)
5167                return status;
5168        status = decode_open_stateid(xdr, &res->stateid);
5169        if (unlikely(status))
5170                return status;
5171
5172        decode_change_info(xdr, &res->cinfo);
5173
5174        p = xdr_inline_decode(xdr, 8);
5175        if (unlikely(!p))
5176                return -EIO;
5177        res->rflags = be32_to_cpup(p++);
5178        bmlen = be32_to_cpup(p);
5179        if (bmlen > 10)
5180                goto xdr_error;
5181
5182        p = xdr_inline_decode(xdr, bmlen << 2);
5183        if (unlikely(!p))
5184                return -EIO;
5185        savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5186        for (i = 0; i < savewords; ++i)
5187                res->attrset[i] = be32_to_cpup(p++);
5188        for (; i < NFS4_BITMAP_SIZE; i++)
5189                res->attrset[i] = 0;
5190
5191        return decode_delegation(xdr, res);
5192xdr_error:
5193        dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5194        return -EIO;
5195}
5196
5197static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5198{
5199        int status;
5200
5201        status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5202        if (status != -EIO)
5203                nfs_increment_open_seqid(status, res->seqid);
5204        if (!status)
5205                status = decode_open_stateid(xdr, &res->stateid);
5206        return status;
5207}
5208
5209static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5210{
5211        int status;
5212
5213        status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5214        if (status != -EIO)
5215                nfs_increment_open_seqid(status, res->seqid);
5216        if (!status)
5217                status = decode_open_stateid(xdr, &res->stateid);
5218        return status;
5219}
5220
5221static int decode_putfh(struct xdr_stream *xdr)
5222{
5223        return decode_op_hdr(xdr, OP_PUTFH);
5224}
5225
5226static int decode_putrootfh(struct xdr_stream *xdr)
5227{
5228        return decode_op_hdr(xdr, OP_PUTROOTFH);
5229}
5230
5231static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5232                       struct nfs_pgio_res *res)
5233{
5234        __be32 *p;
5235        uint32_t count, eof, recvd;
5236        int status;
5237
5238        status = decode_op_hdr(xdr, OP_READ);
5239        if (status)
5240                return status;
5241        p = xdr_inline_decode(xdr, 8);
5242        if (unlikely(!p))
5243                return -EIO;
5244        eof = be32_to_cpup(p++);
5245        count = be32_to_cpup(p);
5246        recvd = xdr_read_pages(xdr, count);
5247        if (count > recvd) {
5248                dprintk("NFS: server cheating in read reply: "
5249                                "count %u > recvd %u\n", count, recvd);
5250                count = recvd;
5251                eof = 0;
5252        }
5253        res->eof = eof;
5254        res->count = count;
5255        return 0;
5256}
5257
5258static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5259{
5260        int             status;
5261        __be32          verf[2];
5262
5263        status = decode_op_hdr(xdr, OP_READDIR);
5264        if (!status)
5265                status = decode_verifier(xdr, readdir->verifier.data);
5266        if (unlikely(status))
5267                return status;
5268        memcpy(verf, readdir->verifier.data, sizeof(verf));
5269        dprintk("%s: verifier = %08x:%08x\n",
5270                        __func__, verf[0], verf[1]);
5271        return xdr_read_pages(xdr, xdr->buf->page_len);
5272}
5273
5274static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5275{
5276        struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5277        u32 len, recvd;
5278        __be32 *p;
5279        int status;
5280
5281        status = decode_op_hdr(xdr, OP_READLINK);
5282        if (status)
5283                return status;
5284
5285        /* Convert length of symlink */
5286        p = xdr_inline_decode(xdr, 4);
5287        if (unlikely(!p))
5288                return -EIO;
5289        len = be32_to_cpup(p);
5290        if (len >= rcvbuf->page_len || len <= 0) {
5291                dprintk("nfs: server returned giant symlink!\n");
5292                return -ENAMETOOLONG;
5293        }
5294        recvd = xdr_read_pages(xdr, len);
5295        if (recvd < len) {
5296                dprintk("NFS: server cheating in readlink reply: "
5297                                "count %u > recvd %u\n", len, recvd);
5298                return -EIO;
5299        }
5300        /*
5301         * The XDR encode routine has set things up so that
5302         * the link text will be copied directly into the
5303         * buffer.  We just have to do overflow-checking,
5304         * and null-terminate the text (the VFS expects
5305         * null-termination).
5306         */
5307        xdr_terminate_string(rcvbuf, len);
5308        return 0;
5309}
5310
5311static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5312{
5313        int status;
5314
5315        status = decode_op_hdr(xdr, OP_REMOVE);
5316        if (status)
5317                goto out;
5318        status = decode_change_info(xdr, cinfo);
5319out:
5320        return status;
5321}
5322
5323static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5324              struct nfs4_change_info *new_cinfo)
5325{
5326        int status;
5327
5328        status = decode_op_hdr(xdr, OP_RENAME);
5329        if (status)
5330                goto out;
5331        if ((status = decode_change_info(xdr, old_cinfo)))
5332                goto out;
5333        status = decode_change_info(xdr, new_cinfo);
5334out:
5335        return status;
5336}
5337
5338static int decode_renew(struct xdr_stream *xdr)
5339{
5340        return decode_op_hdr(xdr, OP_RENEW);
5341}
5342
5343static int
5344decode_restorefh(struct xdr_stream *xdr)
5345{
5346        return decode_op_hdr(xdr, OP_RESTOREFH);
5347}
5348
5349static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5350                         struct nfs_getaclres *res)
5351{
5352        unsigned int savep;
5353        uint32_t attrlen,
5354                 bitmap[3] = {0};
5355        int status;
5356
5357        res->acl_len = 0;
5358        if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5359                goto out;
5360
5361        xdr_enter_page(xdr, xdr->buf->page_len);
5362
5363        if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5364                goto out;
5365        if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5366                goto out;
5367
5368        if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5369                return -EIO;
5370        if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5371
5372                /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5373                 * are stored with the acl data to handle the problem of
5374                 * variable length bitmaps.*/
5375                res->acl_data_offset = xdr_page_pos(xdr);
5376                res->acl_len = attrlen;
5377
5378                /* Check for receive buffer overflow */
5379                if (res->acl_len > xdr_stream_remaining(xdr) ||
5380                    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5381                        res->acl_flags |= NFS4_ACL_TRUNC;
5382                        dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
5383                                attrlen, xdr_stream_remaining(xdr));
5384                }
5385        } else
5386                status = -EOPNOTSUPP;
5387
5388out:
5389        return status;
5390}
5391
5392static int
5393decode_savefh(struct xdr_stream *xdr)
5394{
5395        return decode_op_hdr(xdr, OP_SAVEFH);
5396}
5397
5398static int decode_setattr(struct xdr_stream *xdr)
5399{
5400        int status;
5401
5402        status = decode_op_hdr(xdr, OP_SETATTR);
5403        if (status)
5404                return status;
5405        if (decode_bitmap4(xdr, NULL, 0) >= 0)
5406                return 0;
5407        return -EIO;
5408}
5409
5410static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5411{
5412        __be32 *p;
5413        uint32_t opnum;
5414        int32_t nfserr;
5415
5416        p = xdr_inline_decode(xdr, 8);
5417        if (unlikely(!p))
5418                return -EIO;
5419        opnum = be32_to_cpup(p++);
5420        if (opnum != OP_SETCLIENTID) {
5421                dprintk("nfs: decode_setclientid: Server returned operation"
5422                        " %d\n", opnum);
5423                return -EIO;
5424        }
5425        nfserr = be32_to_cpup(p);
5426        if (nfserr == NFS_OK) {
5427                p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5428                if (unlikely(!p))
5429                        return -EIO;
5430                p = xdr_decode_hyper(p, &res->clientid);
5431                memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5432        } else if (nfserr == NFSERR_CLID_INUSE) {
5433                uint32_t len;
5434
5435                /* skip netid string */
5436                p = xdr_inline_decode(xdr, 4);
5437                if (unlikely(!p))
5438                        return -EIO;
5439                len = be32_to_cpup(p);
5440                p = xdr_inline_decode(xdr, len);
5441                if (unlikely(!p))
5442                        return -EIO;
5443
5444                /* skip uaddr string */
5445                p = xdr_inline_decode(xdr, 4);
5446                if (unlikely(!p))
5447                        return -EIO;
5448                len = be32_to_cpup(p);
5449                p = xdr_inline_decode(xdr, len);
5450                if (unlikely(!p))
5451                        return -EIO;
5452                return -NFSERR_CLID_INUSE;
5453        } else
5454                return nfs4_stat_to_errno(nfserr);
5455
5456        return 0;
5457}
5458
5459static int decode_setclientid_confirm(struct xdr_stream *xdr)
5460{
5461        return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5462}
5463
5464static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5465{
5466        __be32 *p;
5467        int status;
5468
5469        status = decode_op_hdr(xdr, OP_WRITE);
5470        if (status)
5471                return status;
5472
5473        p = xdr_inline_decode(xdr, 8);
5474        if (unlikely(!p))
5475                return -EIO;
5476        res->count = be32_to_cpup(p++);
5477        res->verf->committed = be32_to_cpup(p++);
5478        return decode_write_verifier(xdr, &res->verf->verifier);
5479}
5480
5481static int decode_delegreturn(struct xdr_stream *xdr)
5482{
5483        return decode_op_hdr(xdr, OP_DELEGRETURN);
5484}
5485
5486static int decode_secinfo_gss(struct xdr_stream *xdr,
5487                              struct nfs4_secinfo4 *flavor)
5488{
5489        u32 oid_len;
5490        __be32 *p;
5491
5492        p = xdr_inline_decode(xdr, 4);
5493        if (unlikely(!p))
5494                return -EIO;
5495        oid_len = be32_to_cpup(p);
5496        if (oid_len > GSS_OID_MAX_LEN)
5497                return -EINVAL;
5498
5499        p = xdr_inline_decode(xdr, oid_len);
5500        if (unlikely(!p))
5501                return -EIO;
5502        memcpy(flavor->flavor_info.oid.data, p, oid_len);
5503        flavor->flavor_info.oid.len = oid_len;
5504
5505        p = xdr_inline_decode(xdr, 8);
5506        if (unlikely(!p))
5507                return -EIO;
5508        flavor->flavor_info.qop = be32_to_cpup(p++);
5509        flavor->flavor_info.service = be32_to_cpup(p);
5510
5511        return 0;
5512}
5513
5514static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5515{
5516        struct nfs4_secinfo4 *sec_flavor;
5517        unsigned int i, num_flavors;
5518        int status;
5519        __be32 *p;
5520
5521        p = xdr_inline_decode(xdr, 4);
5522        if (unlikely(!p))
5523                return -EIO;
5524
5525        res->flavors->num_flavors = 0;
5526        num_flavors = be32_to_cpup(p);
5527
5528        for (i = 0; i < num_flavors; i++) {
5529                sec_flavor = &res->flavors->flavors[i];
5530                if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5531                        break;
5532
5533                p = xdr_inline_decode(xdr, 4);
5534                if (unlikely(!p))
5535                        return -EIO;
5536                sec_flavor->flavor = be32_to_cpup(p);
5537
5538                if (sec_flavor->flavor == RPC_AUTH_GSS) {
5539                        status = decode_secinfo_gss(xdr, sec_flavor);
5540                        if (status)
5541                                goto out;
5542                }
5543                res->flavors->num_flavors++;
5544        }
5545
5546        status = 0;
5547out:
5548        return status;
5549}
5550
5551static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5552{
5553        int status = decode_op_hdr(xdr, OP_SECINFO);
5554        if (status)
5555                return status;
5556        return decode_secinfo_common(xdr, res);
5557}
5558
5559#if defined(CONFIG_NFS_V4_1)
5560static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5561{
5562        int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5563        if (status)
5564                return status;
5565        return decode_secinfo_common(xdr, res);
5566}
5567
5568static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5569{
5570        if (xdr_stream_decode_uint32_array(xdr, op_map->u.words,
5571                                           ARRAY_SIZE(op_map->u.words)) < 0)
5572                return -EIO;
5573        return 0;
5574}
5575
5576static int decode_exchange_id(struct xdr_stream *xdr,
5577                              struct nfs41_exchange_id_res *res)
5578{
5579        __be32 *p;
5580        uint32_t dummy;
5581        char *dummy_str;
5582        int status;
5583        uint32_t impl_id_count;
5584
5585        status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5586        if (status)
5587                return status;
5588
5589        p = xdr_inline_decode(xdr, 8);
5590        if (unlikely(!p))
5591                return -EIO;
5592        xdr_decode_hyper(p, &res->clientid);
5593        p = xdr_inline_decode(xdr, 12);
5594        if (unlikely(!p))
5595                return -EIO;
5596        res->seqid = be32_to_cpup(p++);
5597        res->flags = be32_to_cpup(p++);
5598
5599        res->state_protect.how = be32_to_cpup(p);
5600        switch (res->state_protect.how) {
5601        case SP4_NONE:
5602                break;
5603        case SP4_MACH_CRED:
5604                status = decode_op_map(xdr, &res->state_protect.enforce);
5605                if (status)
5606                        return status;
5607                status = decode_op_map(xdr, &res->state_protect.allow);
5608                if (status)
5609                        return status;
5610                break;
5611        default:
5612                WARN_ON_ONCE(1);
5613                return -EIO;
5614        }
5615
5616        /* server_owner4.so_minor_id */
5617        p = xdr_inline_decode(xdr, 8);
5618        if (unlikely(!p))
5619                return -EIO;
5620        p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5621
5622        /* server_owner4.so_major_id */
5623        status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5624        if (unlikely(status))
5625                return status;
5626        memcpy(res->server_owner->major_id, dummy_str, dummy);
5627        res->server_owner->major_id_sz = dummy;
5628
5629        /* server_scope4 */
5630        status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5631        if (unlikely(status))
5632                return status;
5633        memcpy(res->server_scope->server_scope, dummy_str, dummy);
5634        res->server_scope->server_scope_sz = dummy;
5635
5636        /* Implementation Id */
5637        p = xdr_inline_decode(xdr, 4);
5638        if (unlikely(!p))
5639                return -EIO;
5640        impl_id_count = be32_to_cpup(p++);
5641
5642        if (impl_id_count) {
5643                /* nii_domain */
5644                status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5645                if (unlikely(status))
5646                        return status;
5647                memcpy(res->impl_id->domain, dummy_str, dummy);
5648
5649                /* nii_name */
5650                status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5651                if (unlikely(status))
5652                        return status;
5653                memcpy(res->impl_id->name, dummy_str, dummy);
5654
5655                /* nii_date */
5656                p = xdr_inline_decode(xdr, 12);
5657                if (unlikely(!p))
5658                        return -EIO;
5659                p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5660                res->impl_id->date.nseconds = be32_to_cpup(p);
5661
5662                /* if there's more than one entry, ignore the rest */
5663        }
5664        return 0;
5665}
5666
5667static int decode_chan_attrs(struct xdr_stream *xdr,
5668                             struct nfs4_channel_attrs *attrs)
5669{
5670        __be32 *p;
5671        u32 nr_attrs, val;
5672
5673        p = xdr_inline_decode(xdr, 28);
5674        if (unlikely(!p))
5675                return -EIO;
5676        val = be32_to_cpup(p++);        /* headerpadsz */
5677        if (val)
5678                return -EINVAL;         /* no support for header padding yet */
5679        attrs->max_rqst_sz = be32_to_cpup(p++);
5680        attrs->max_resp_sz = be32_to_cpup(p++);
5681        attrs->max_resp_sz_cached = be32_to_cpup(p++);
5682        attrs->max_ops = be32_to_cpup(p++);
5683        attrs->max_reqs = be32_to_cpup(p++);
5684        nr_attrs = be32_to_cpup(p);
5685        if (unlikely(nr_attrs > 1)) {
5686                printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5687                        "count %u\n", __func__, nr_attrs);
5688                return -EINVAL;
5689        }
5690        if (nr_attrs == 1) {
5691                p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5692                if (unlikely(!p))
5693                        return -EIO;
5694        }
5695        return 0;
5696}
5697
5698static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5699{
5700        return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5701}
5702
5703static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5704                                struct nfs41_bind_conn_to_session_res *res)
5705{
5706        __be32 *p;
5707        int status;
5708
5709        status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5710        if (!status)
5711                status = decode_sessionid(xdr, &res->sessionid);
5712        if (unlikely(status))
5713                return status;
5714
5715        /* dir flags, rdma mode bool */
5716        p = xdr_inline_decode(xdr, 8);
5717        if (unlikely(!p))
5718                return -EIO;
5719
5720        res->dir = be32_to_cpup(p++);
5721        if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5722                return -EIO;
5723        if (be32_to_cpup(p) == 0)
5724                res->use_conn_in_rdma_mode = false;
5725        else
5726                res->use_conn_in_rdma_mode = true;
5727
5728        return 0;
5729}
5730
5731static int decode_create_session(struct xdr_stream *xdr,
5732                                 struct nfs41_create_session_res *res)
5733{
5734        __be32 *p;
5735        int status;
5736
5737        status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5738        if (!status)
5739                status = decode_sessionid(xdr, &res->sessionid);
5740        if (unlikely(status))
5741                return status;
5742
5743        /* seqid, flags */
5744        p = xdr_inline_decode(xdr, 8);
5745        if (unlikely(!p))
5746                return -EIO;
5747        res->seqid = be32_to_cpup(p++);
5748        res->flags = be32_to_cpup(p);
5749
5750        /* Channel attributes */
5751        status = decode_chan_attrs(xdr, &res->fc_attrs);
5752        if (!status)
5753                status = decode_chan_attrs(xdr, &res->bc_attrs);
5754        return status;
5755}
5756
5757static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5758{
5759        return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5760}
5761
5762static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5763{
5764        return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5765}
5766
5767static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5768{
5769        return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5770}
5771#endif /* CONFIG_NFS_V4_1 */
5772
5773static int decode_sequence(struct xdr_stream *xdr,
5774                           struct nfs4_sequence_res *res,
5775                           struct rpc_rqst *rqstp)
5776{
5777#if defined(CONFIG_NFS_V4_1)
5778        struct nfs4_session *session;
5779        struct nfs4_sessionid id;
5780        u32 dummy;
5781        int status;
5782        __be32 *p;
5783
5784        if (res->sr_slot == NULL)
5785                return 0;
5786        if (!res->sr_slot->table->session)
5787                return 0;
5788
5789        status = decode_op_hdr(xdr, OP_SEQUENCE);
5790        if (!status)
5791                status = decode_sessionid(xdr, &id);
5792        if (unlikely(status))
5793                goto out_err;
5794
5795        /*
5796         * If the server returns different values for sessionID, slotID or
5797         * sequence number, the server is looney tunes.
5798         */
5799        status = -EREMOTEIO;
5800        session = res->sr_slot->table->session;
5801
5802        if (memcmp(id.data, session->sess_id.data,
5803                   NFS4_MAX_SESSIONID_LEN)) {
5804                dprintk("%s Invalid session id\n", __func__);
5805                goto out_err;
5806        }
5807
5808        p = xdr_inline_decode(xdr, 20);
5809        if (unlikely(!p))
5810                goto out_overflow;
5811
5812        /* seqid */
5813        dummy = be32_to_cpup(p++);
5814        if (dummy != res->sr_slot->seq_nr) {
5815                dprintk("%s Invalid sequence number\n", __func__);
5816                goto out_err;
5817        }
5818        /* slot id */
5819        dummy = be32_to_cpup(p++);
5820        if (dummy != res->sr_slot->slot_nr) {
5821                dprintk("%s Invalid slot id\n", __func__);
5822                goto out_err;
5823        }
5824        /* highest slot id */
5825        res->sr_highest_slotid = be32_to_cpup(p++);
5826        /* target highest slot id */
5827        res->sr_target_highest_slotid = be32_to_cpup(p++);
5828        /* result flags */
5829        res->sr_status_flags = be32_to_cpup(p);
5830        status = 0;
5831out_err:
5832        res->sr_status = status;
5833        return status;
5834out_overflow:
5835        status = -EIO;
5836        goto out_err;
5837#else  /* CONFIG_NFS_V4_1 */
5838        return 0;
5839#endif /* CONFIG_NFS_V4_1 */
5840}
5841
5842#if defined(CONFIG_NFS_V4_1)
5843static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5844{
5845        stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5846        return decode_stateid(xdr, stateid);
5847}
5848
5849static int decode_getdeviceinfo(struct xdr_stream *xdr,
5850                                struct nfs4_getdeviceinfo_res *res)
5851{
5852        struct pnfs_device *pdev = res->pdev;
5853        __be32 *p;
5854        uint32_t len, type;
5855        int status;
5856
5857        status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5858        if (status) {
5859                if (status == -ETOOSMALL) {
5860                        p = xdr_inline_decode(xdr, 4);
5861                        if (unlikely(!p))
5862                                return -EIO;
5863                        pdev->mincount = be32_to_cpup(p);
5864                        dprintk("%s: Min count too small. mincnt = %u\n",
5865                                __func__, pdev->mincount);
5866                }
5867                return status;
5868        }
5869
5870        p = xdr_inline_decode(xdr, 8);
5871        if (unlikely(!p))
5872                return -EIO;
5873        type = be32_to_cpup(p++);
5874        if (type != pdev->layout_type) {
5875                dprintk("%s: layout mismatch req: %u pdev: %u\n",
5876                        __func__, pdev->layout_type, type);
5877                return -EINVAL;
5878        }
5879        /*
5880         * Get the length of the opaque device_addr4. xdr_read_pages places
5881         * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5882         * and places the remaining xdr data in xdr_buf->tail
5883         */
5884        pdev->mincount = be32_to_cpup(p);
5885        if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5886                return -EIO;
5887
5888        /* Parse notification bitmap, verifying that it is zero. */
5889        p = xdr_inline_decode(xdr, 4);
5890        if (unlikely(!p))
5891                return -EIO;
5892        len = be32_to_cpup(p);
5893        if (len) {
5894                uint32_t i;
5895
5896                p = xdr_inline_decode(xdr, 4 * len);
5897                if (unlikely(!p))
5898                        return -EIO;
5899
5900                res->notification = be32_to_cpup(p++);
5901                for (i = 1; i < len; i++) {
5902                        if (be32_to_cpup(p++)) {
5903                                dprintk("%s: unsupported notification\n",
5904                                        __func__);
5905                                return -EIO;
5906                        }
5907                }
5908        }
5909        return 0;
5910}
5911
5912static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5913                            struct nfs4_layoutget_res *res)
5914{
5915        __be32 *p;
5916        int status;
5917        u32 layout_count;
5918        u32 recvd;
5919
5920        status = decode_op_hdr(xdr, OP_LAYOUTGET);
5921        if (status)
5922                goto out;
5923        p = xdr_inline_decode(xdr, 4);
5924        if (unlikely(!p))
5925                goto out_overflow;
5926        res->return_on_close = be32_to_cpup(p);
5927        decode_layout_stateid(xdr, &res->stateid);
5928        p = xdr_inline_decode(xdr, 4);
5929        if (unlikely(!p))
5930                goto out_overflow;
5931        layout_count = be32_to_cpup(p);
5932        if (!layout_count) {
5933                dprintk("%s: server responded with empty layout array\n",
5934                        __func__);
5935                status = -EINVAL;
5936                goto out;
5937        }
5938
5939        p = xdr_inline_decode(xdr, 28);
5940        if (unlikely(!p))
5941                goto out_overflow;
5942        p = xdr_decode_hyper(p, &res->range.offset);
5943        p = xdr_decode_hyper(p, &res->range.length);
5944        res->range.iomode = be32_to_cpup(p++);
5945        res->type = be32_to_cpup(p++);
5946        res->layoutp->len = be32_to_cpup(p);
5947
5948        dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5949                __func__,
5950                (unsigned long)res->range.offset,
5951                (unsigned long)res->range.length,
5952                res->range.iomode,
5953                res->type,
5954                res->layoutp->len);
5955
5956        recvd = xdr_read_pages(xdr, res->layoutp->len);
5957        if (res->layoutp->len > recvd) {
5958                dprintk("NFS: server cheating in layoutget reply: "
5959                                "layout len %u > recvd %u\n",
5960                                res->layoutp->len, recvd);
5961                status = -EINVAL;
5962                goto out;
5963        }
5964
5965        if (layout_count > 1) {
5966                /* We only handle a length one array at the moment.  Any
5967                 * further entries are just ignored.  Note that this means
5968                 * the client may see a response that is less than the
5969                 * minimum it requested.
5970                 */
5971                dprintk("%s: server responded with %d layouts, dropping tail\n",
5972                        __func__, layout_count);
5973        }
5974
5975out:
5976        res->status = status;
5977        return status;
5978out_overflow:
5979        status = -EIO;
5980        goto out;
5981}
5982
5983static int decode_layoutreturn(struct xdr_stream *xdr,
5984                               struct nfs4_layoutreturn_res *res)
5985{
5986        __be32 *p;
5987        int status;
5988
5989        status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5990        if (status)
5991                return status;
5992        p = xdr_inline_decode(xdr, 4);
5993        if (unlikely(!p))
5994                return -EIO;
5995        res->lrs_present = be32_to_cpup(p);
5996        if (res->lrs_present)
5997                status = decode_layout_stateid(xdr, &res->stateid);
5998        else
5999                nfs4_stateid_copy(&res->stateid, &invalid_stateid);
6000        return status;
6001}
6002
6003static int decode_layoutcommit(struct xdr_stream *xdr,
6004                               struct rpc_rqst *req,
6005                               struct nfs4_layoutcommit_res *res)
6006{
6007        __be32 *p;
6008        __u32 sizechanged;
6009        int status;
6010
6011        status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
6012        res->status = status;
6013        if (status)
6014                return status;
6015
6016        p = xdr_inline_decode(xdr, 4);
6017        if (unlikely(!p))
6018                return -EIO;
6019        sizechanged = be32_to_cpup(p);
6020
6021        if (sizechanged) {
6022                /* throw away new size */
6023                p = xdr_inline_decode(xdr, 8);
6024                if (unlikely(!p))
6025                        return -EIO;
6026        }
6027        return 0;
6028}
6029
6030static int decode_test_stateid(struct xdr_stream *xdr,
6031                               struct nfs41_test_stateid_res *res)
6032{
6033        __be32 *p;
6034        int status;
6035        int num_res;
6036
6037        status = decode_op_hdr(xdr, OP_TEST_STATEID);
6038        if (status)
6039                return status;
6040
6041        p = xdr_inline_decode(xdr, 4);
6042        if (unlikely(!p))
6043                return -EIO;
6044        num_res = be32_to_cpup(p++);
6045        if (num_res != 1)
6046                return -EIO;
6047
6048        p = xdr_inline_decode(xdr, 4);
6049        if (unlikely(!p))
6050                return -EIO;
6051        res->status = be32_to_cpup(p++);
6052
6053        return status;
6054}
6055
6056static int decode_free_stateid(struct xdr_stream *xdr,
6057                               struct nfs41_free_stateid_res *res)
6058{
6059        res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
6060        return res->status;
6061}
6062#else
6063static inline
6064int decode_layoutreturn(struct xdr_stream *xdr,
6065                               struct nfs4_layoutreturn_res *res)
6066{
6067        return 0;
6068}
6069
6070static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6071                            struct nfs4_layoutget_res *res)
6072{
6073        return 0;
6074}
6075
6076#endif /* CONFIG_NFS_V4_1 */
6077
6078/*
6079 * END OF "GENERIC" DECODE ROUTINES.
6080 */
6081
6082/*
6083 * Decode OPEN_DOWNGRADE response
6084 */
6085static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6086                                       struct xdr_stream *xdr,
6087                                       void *data)
6088{
6089        struct nfs_closeres *res = data;
6090        struct compound_hdr hdr;
6091        int status;
6092
6093        status = decode_compound_hdr(xdr, &hdr);
6094        if (status)
6095                goto out;
6096        status = decode_sequence(xdr, &res->seq_res, rqstp);
6097        if (status)
6098                goto out;
6099        status = decode_putfh(xdr);
6100        if (status)
6101                goto out;
6102        if (res->lr_res) {
6103                status = decode_layoutreturn(xdr, res->lr_res);
6104                res->lr_ret = status;
6105                if (status)
6106                        goto out;
6107        }
6108        status = decode_open_downgrade(xdr, res);
6109out:
6110        return status;
6111}
6112
6113/*
6114 * Decode ACCESS response
6115 */
6116static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6117                               void *data)
6118{
6119        struct nfs4_accessres *res = data;
6120        struct compound_hdr hdr;
6121        int status;
6122
6123        status = decode_compound_hdr(xdr, &hdr);
6124        if (status)
6125                goto out;
6126        status = decode_sequence(xdr, &res->seq_res, rqstp);
6127        if (status)
6128                goto out;
6129        status = decode_putfh(xdr);
6130        if (status != 0)
6131                goto out;
6132        status = decode_access(xdr, &res->supported, &res->access);
6133        if (status != 0)
6134                goto out;
6135        if (res->fattr)
6136                decode_getfattr(xdr, res->fattr, res->server);
6137out:
6138        return status;
6139}
6140
6141/*
6142 * Decode LOOKUP response
6143 */
6144static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6145                               void *data)
6146{
6147        struct nfs4_lookup_res *res = data;
6148        struct compound_hdr hdr;
6149        int status;
6150
6151        status = decode_compound_hdr(xdr, &hdr);
6152        if (status)
6153                goto out;
6154        status = decode_sequence(xdr, &res->seq_res, rqstp);
6155        if (status)
6156                goto out;
6157        status = decode_putfh(xdr);
6158        if (status)
6159                goto out;
6160        status = decode_lookup(xdr);
6161        if (status)
6162                goto out;
6163        status = decode_getfh(xdr, res->fh);
6164        if (status)
6165                goto out;
6166        status = decode_getfattr(xdr, res->fattr, res->server);
6167out:
6168        return status;
6169}
6170
6171/*
6172 * Decode LOOKUPP response
6173 */
6174static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6175                void *data)
6176{
6177        struct nfs4_lookupp_res *res = data;
6178        struct compound_hdr hdr;
6179        int status;
6180
6181        status = decode_compound_hdr(xdr, &hdr);
6182        if (status)
6183                goto out;
6184        status = decode_sequence(xdr, &res->seq_res, rqstp);
6185        if (status)
6186                goto out;
6187        status = decode_putfh(xdr);
6188        if (status)
6189                goto out;
6190        status = decode_lookupp(xdr);
6191        if (status)
6192                goto out;
6193        status = decode_getfh(xdr, res->fh);
6194        if (status)
6195                goto out;
6196        status = decode_getfattr(xdr, res->fattr, res->server);
6197out:
6198        return status;
6199}
6200
6201/*
6202 * Decode LOOKUP_ROOT response
6203 */
6204static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6205                                    struct xdr_stream *xdr,
6206                                    void *data)
6207{
6208        struct nfs4_lookup_res *res = data;
6209        struct compound_hdr hdr;
6210        int status;
6211
6212        status = decode_compound_hdr(xdr, &hdr);
6213        if (status)
6214                goto out;
6215        status = decode_sequence(xdr, &res->seq_res, rqstp);
6216        if (status)
6217                goto out;
6218        status = decode_putrootfh(xdr);
6219        if (status)
6220                goto out;
6221        status = decode_getfh(xdr, res->fh);
6222        if (status == 0)
6223                status = decode_getfattr(xdr, res->fattr, res->server);
6224out:
6225        return status;
6226}
6227
6228/*
6229 * Decode REMOVE response
6230 */
6231static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6232                               void *data)
6233{
6234        struct nfs_removeres *res = data;
6235        struct compound_hdr hdr;
6236        int status;
6237
6238        status = decode_compound_hdr(xdr, &hdr);
6239        if (status)
6240                goto out;
6241        status = decode_sequence(xdr, &res->seq_res, rqstp);
6242        if (status)
6243                goto out;
6244        status = decode_putfh(xdr);
6245        if (status)
6246                goto out;
6247        status = decode_remove(xdr, &res->cinfo);
6248out:
6249        return status;
6250}
6251
6252/*
6253 * Decode RENAME response
6254 */
6255static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6256                               void *data)
6257{
6258        struct nfs_renameres *res = data;
6259        struct compound_hdr hdr;
6260        int status;
6261
6262        status = decode_compound_hdr(xdr, &hdr);
6263        if (status)
6264                goto out;
6265        status = decode_sequence(xdr, &res->seq_res, rqstp);
6266        if (status)
6267                goto out;
6268        status = decode_putfh(xdr);
6269        if (status)
6270                goto out;
6271        status = decode_savefh(xdr);
6272        if (status)
6273                goto out;
6274        status = decode_putfh(xdr);
6275        if (status)
6276                goto out;
6277        status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6278out:
6279        return status;
6280}
6281
6282/*
6283 * Decode LINK response
6284 */
6285static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6286                             void *data)
6287{
6288        struct nfs4_link_res *res = data;
6289        struct compound_hdr hdr;
6290        int status;
6291
6292        status = decode_compound_hdr(xdr, &hdr);
6293        if (status)
6294                goto out;
6295        status = decode_sequence(xdr, &res->seq_res, rqstp);
6296        if (status)
6297                goto out;
6298        status = decode_putfh(xdr);
6299        if (status)
6300                goto out;
6301        status = decode_savefh(xdr);
6302        if (status)
6303                goto out;
6304        status = decode_putfh(xdr);
6305        if (status)
6306                goto out;
6307        status = decode_link(xdr, &res->cinfo);
6308        if (status)
6309                goto out;
6310        /*
6311         * Note order: OP_LINK leaves the directory as the current
6312         *             filehandle.
6313         */
6314        status = decode_restorefh(xdr);
6315        if (status)
6316                goto out;
6317        decode_getfattr(xdr, res->fattr, res->server);
6318out:
6319        return status;
6320}
6321
6322/*
6323 * Decode CREATE response
6324 */
6325static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6326                               void *data)
6327{
6328        struct nfs4_create_res *res = data;
6329        struct compound_hdr hdr;
6330        int status;
6331
6332        status = decode_compound_hdr(xdr, &hdr);
6333        if (status)
6334                goto out;
6335        status = decode_sequence(xdr, &res->seq_res, rqstp);
6336        if (status)
6337                goto out;
6338        status = decode_putfh(xdr);
6339        if (status)
6340                goto out;
6341        status = decode_create(xdr, &res->dir_cinfo);
6342        if (status)
6343                goto out;
6344        status = decode_getfh(xdr, res->fh);
6345        if (status)
6346                goto out;
6347        decode_getfattr(xdr, res->fattr, res->server);
6348out:
6349        return status;
6350}
6351
6352/*
6353 * Decode SYMLINK response
6354 */
6355static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356                                void *res)
6357{
6358        return nfs4_xdr_dec_create(rqstp, xdr, res);
6359}
6360
6361/*
6362 * Decode GETATTR response
6363 */
6364static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6365                                void *data)
6366{
6367        struct nfs4_getattr_res *res = data;
6368        struct compound_hdr hdr;
6369        int status;
6370
6371        status = decode_compound_hdr(xdr, &hdr);
6372        if (status)
6373                goto out;
6374        status = decode_sequence(xdr, &res->seq_res, rqstp);
6375        if (status)
6376                goto out;
6377        status = decode_putfh(xdr);
6378        if (status)
6379                goto out;
6380        status = decode_getfattr(xdr, res->fattr, res->server);
6381out:
6382        return status;
6383}
6384
6385/*
6386 * Encode an SETACL request
6387 */
6388static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6389                                const void *data)
6390{
6391        const struct nfs_setaclargs *args = data;
6392        struct compound_hdr hdr = {
6393                .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6394        };
6395
6396        encode_compound_hdr(xdr, req, &hdr);
6397        encode_sequence(xdr, &args->seq_args, &hdr);
6398        encode_putfh(xdr, args->fh, &hdr);
6399        encode_setacl(xdr, args, &hdr);
6400        encode_nops(&hdr);
6401}
6402
6403/*
6404 * Decode SETACL response
6405 */
6406static int
6407nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6408                    void *data)
6409{
6410        struct nfs_setaclres *res = data;
6411        struct compound_hdr hdr;
6412        int status;
6413
6414        status = decode_compound_hdr(xdr, &hdr);
6415        if (status)
6416                goto out;
6417        status = decode_sequence(xdr, &res->seq_res, rqstp);
6418        if (status)
6419                goto out;
6420        status = decode_putfh(xdr);
6421        if (status)
6422                goto out;
6423        status = decode_setattr(xdr);
6424out:
6425        return status;
6426}
6427
6428/*
6429 * Decode GETACL response
6430 */
6431static int
6432nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6433                    void *data)
6434{
6435        struct nfs_getaclres *res = data;
6436        struct compound_hdr hdr;
6437        int status;
6438
6439        if (res->acl_scratch != NULL)
6440                xdr_set_scratch_page(xdr, res->acl_scratch);
6441        status = decode_compound_hdr(xdr, &hdr);
6442        if (status)
6443                goto out;
6444        status = decode_sequence(xdr, &res->seq_res, rqstp);
6445        if (status)
6446                goto out;
6447        status = decode_putfh(xdr);
6448        if (status)
6449                goto out;
6450        status = decode_getacl(xdr, rqstp, res);
6451
6452out:
6453        return status;
6454}
6455
6456/*
6457 * Decode CLOSE response
6458 */
6459static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6460                              void *data)
6461{
6462        struct nfs_closeres *res = data;
6463        struct compound_hdr hdr;
6464        int status;
6465
6466        status = decode_compound_hdr(xdr, &hdr);
6467        if (status)
6468                goto out;
6469        status = decode_sequence(xdr, &res->seq_res, rqstp);
6470        if (status)
6471                goto out;
6472        status = decode_putfh(xdr);
6473        if (status)
6474                goto out;
6475        if (res->lr_res) {
6476                status = decode_layoutreturn(xdr, res->lr_res);
6477                res->lr_ret = status;
6478                if (status)
6479                        goto out;
6480        }
6481        if (res->fattr != NULL) {
6482                status = decode_getfattr(xdr, res->fattr, res->server);
6483                if (status != 0)
6484                        goto out;
6485        }
6486        status = decode_close(xdr, res);
6487out:
6488        return status;
6489}
6490
6491/*
6492 * Decode OPEN response
6493 */
6494static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6495                             void *data)
6496{
6497        struct nfs_openres *res = data;
6498        struct compound_hdr hdr;
6499        int status;
6500
6501        status = decode_compound_hdr(xdr, &hdr);
6502        if (status)
6503                goto out;
6504        status = decode_sequence(xdr, &res->seq_res, rqstp);
6505        if (status)
6506                goto out;
6507        status = decode_putfh(xdr);
6508        if (status)
6509                goto out;
6510        status = decode_open(xdr, res);
6511        if (status)
6512                goto out;
6513        status = decode_getfh(xdr, &res->fh);
6514        if (status)
6515                goto out;
6516        if (res->access_request)
6517                decode_access(xdr, &res->access_supported, &res->access_result);
6518        decode_getfattr(xdr, res->f_attr, res->server);
6519        if (res->lg_res)
6520                decode_layoutget(xdr, rqstp, res->lg_res);
6521out:
6522        return status;
6523}
6524
6525/*
6526 * Decode OPEN_CONFIRM response
6527 */
6528static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6529                                     struct xdr_stream *xdr,
6530                                     void *data)
6531{
6532        struct nfs_open_confirmres *res = data;
6533        struct compound_hdr hdr;
6534        int status;
6535
6536        status = decode_compound_hdr(xdr, &hdr);
6537        if (status)
6538                goto out;
6539        status = decode_putfh(xdr);
6540        if (status)
6541                goto out;
6542        status = decode_open_confirm(xdr, res);
6543out:
6544        return status;
6545}
6546
6547/*
6548 * Decode OPEN response
6549 */
6550static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6551                                    struct xdr_stream *xdr,
6552                                    void *data)
6553{
6554        struct nfs_openres *res = data;
6555        struct compound_hdr hdr;
6556        int status;
6557
6558        status = decode_compound_hdr(xdr, &hdr);
6559        if (status)
6560                goto out;
6561        status = decode_sequence(xdr, &res->seq_res, rqstp);
6562        if (status)
6563                goto out;
6564        status = decode_putfh(xdr);
6565        if (status)
6566                goto out;
6567        status = decode_open(xdr, res);
6568        if (status)
6569                goto out;
6570        if (res->access_request)
6571                decode_access(xdr, &res->access_supported, &res->access_result);
6572        decode_getfattr(xdr, res->f_attr, res->server);
6573        if (res->lg_res)
6574                decode_layoutget(xdr, rqstp, res->lg_res);
6575out:
6576        return status;
6577}
6578
6579/*
6580 * Decode SETATTR response
6581 */
6582static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6583                                struct xdr_stream *xdr,
6584                                void *data)
6585{
6586        struct nfs_setattrres *res = data;
6587        struct compound_hdr hdr;
6588        int status;
6589
6590        status = decode_compound_hdr(xdr, &hdr);
6591        if (status)
6592                goto out;
6593        status = decode_sequence(xdr, &res->seq_res, rqstp);
6594        if (status)
6595                goto out;
6596        status = decode_putfh(xdr);
6597        if (status)
6598                goto out;
6599        status = decode_setattr(xdr);
6600        if (status)
6601                goto out;
6602        decode_getfattr(xdr, res->fattr, res->server);
6603out:
6604        return status;
6605}
6606
6607/*
6608 * Decode LOCK response
6609 */
6610static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6611                             void *data)
6612{
6613        struct nfs_lock_res *res = data;
6614        struct compound_hdr hdr;
6615        int status;
6616
6617        status = decode_compound_hdr(xdr, &hdr);
6618        if (status)
6619                goto out;
6620        status = decode_sequence(xdr, &res->seq_res, rqstp);
6621        if (status)
6622                goto out;
6623        status = decode_putfh(xdr);
6624        if (status)
6625                goto out;
6626        status = decode_lock(xdr, res);
6627out:
6628        return status;
6629}
6630
6631/*
6632 * Decode LOCKT response
6633 */
6634static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6635                              void *data)
6636{
6637        struct nfs_lockt_res *res = data;
6638        struct compound_hdr hdr;
6639        int status;
6640
6641        status = decode_compound_hdr(xdr, &hdr);
6642        if (status)
6643                goto out;
6644        status = decode_sequence(xdr, &res->seq_res, rqstp);
6645        if (status)
6646                goto out;
6647        status = decode_putfh(xdr);
6648        if (status)
6649                goto out;
6650        status = decode_lockt(xdr, res);
6651out:
6652        return status;
6653}
6654
6655/*
6656 * Decode LOCKU response
6657 */
6658static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6659                              void *data)
6660{
6661        struct nfs_locku_res *res = data;
6662        struct compound_hdr hdr;
6663        int status;
6664
6665        status = decode_compound_hdr(xdr, &hdr);
6666        if (status)
6667                goto out;
6668        status = decode_sequence(xdr, &res->seq_res, rqstp);
6669        if (status)
6670                goto out;
6671        status = decode_putfh(xdr);
6672        if (status)
6673                goto out;
6674        status = decode_locku(xdr, res);
6675out:
6676        return status;
6677}
6678
6679static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6680                                          struct xdr_stream *xdr, void *dummy)
6681{
6682        struct compound_hdr hdr;
6683        int status;
6684
6685        status = decode_compound_hdr(xdr, &hdr);
6686        if (!status)
6687                status = decode_release_lockowner(xdr);
6688        return status;
6689}
6690
6691/*
6692 * Decode READLINK response
6693 */
6694static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6695                                 struct xdr_stream *xdr,
6696                                 void *data)
6697{
6698        struct nfs4_readlink_res *res = data;
6699        struct compound_hdr hdr;
6700        int status;
6701
6702        status = decode_compound_hdr(xdr, &hdr);
6703        if (status)
6704                goto out;
6705        status = decode_sequence(xdr, &res->seq_res, rqstp);
6706        if (status)
6707                goto out;
6708        status = decode_putfh(xdr);
6709        if (status)
6710                goto out;
6711        status = decode_readlink(xdr, rqstp);
6712out:
6713        return status;
6714}
6715
6716/*
6717 * Decode READDIR response
6718 */
6719static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6720                                void *data)
6721{
6722        struct nfs4_readdir_res *res = data;
6723        struct compound_hdr hdr;
6724        int status;
6725
6726        status = decode_compound_hdr(xdr, &hdr);
6727        if (status)
6728                goto out;
6729        status = decode_sequence(xdr, &res->seq_res, rqstp);
6730        if (status)
6731                goto out;
6732        status = decode_putfh(xdr);
6733        if (status)
6734                goto out;
6735        status = decode_readdir(xdr, rqstp, res);
6736out:
6737        return status;
6738}
6739
6740/*
6741 * Decode Read response
6742 */
6743static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6744                             void *data)
6745{
6746        struct nfs_pgio_res *res = data;
6747        struct compound_hdr hdr;
6748        int status;
6749
6750        status = decode_compound_hdr(xdr, &hdr);
6751        res->op_status = hdr.status;
6752        if (status)
6753                goto out;
6754        status = decode_sequence(xdr, &res->seq_res, rqstp);
6755        if (status)
6756                goto out;
6757        status = decode_putfh(xdr);
6758        if (status)
6759                goto out;
6760        status = decode_read(xdr, rqstp, res);
6761        if (!status)
6762                status = res->count;
6763out:
6764        return status;
6765}
6766
6767/*
6768 * Decode WRITE response
6769 */
6770static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6771                              void *data)
6772{
6773        struct nfs_pgio_res *res = data;
6774        struct compound_hdr hdr;
6775        int status;
6776
6777        status = decode_compound_hdr(xdr, &hdr);
6778        res->op_status = hdr.status;
6779        if (status)
6780                goto out;
6781        status = decode_sequence(xdr, &res->seq_res, rqstp);
6782        if (status)
6783                goto out;
6784        status = decode_putfh(xdr);
6785        if (status)
6786                goto out;
6787        status = decode_write(xdr, res);
6788        if (status)
6789                goto out;
6790        if (res->fattr)
6791                decode_getfattr(xdr, res->fattr, res->server);
6792        if (!status)
6793                status = res->count;
6794out:
6795        return status;
6796}
6797
6798/*
6799 * Decode COMMIT response
6800 */
6801static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6802                               void *data)
6803{
6804        struct nfs_commitres *res = data;
6805        struct compound_hdr hdr;
6806        int status;
6807
6808        status = decode_compound_hdr(xdr, &hdr);
6809        res->op_status = hdr.status;
6810        if (status)
6811                goto out;
6812        status = decode_sequence(xdr, &res->seq_res, rqstp);
6813        if (status)
6814                goto out;
6815        status = decode_putfh(xdr);
6816        if (status)
6817                goto out;
6818        status = decode_commit(xdr, res);
6819out:
6820        return status;
6821}
6822
6823/*
6824 * Decode FSINFO response
6825 */
6826static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6827                               void *data)
6828{
6829        struct nfs4_fsinfo_res *res = data;
6830        struct compound_hdr hdr;
6831        int status;
6832
6833        status = decode_compound_hdr(xdr, &hdr);
6834        if (!status)
6835                status = decode_sequence(xdr, &res->seq_res, req);
6836        if (!status)
6837                status = decode_putfh(xdr);
6838        if (!status)
6839                status = decode_fsinfo(xdr, res->fsinfo);
6840        return status;
6841}
6842
6843/*
6844 * Decode PATHCONF response
6845 */
6846static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6847                                 void *data)
6848{
6849        struct nfs4_pathconf_res *res = data;
6850        struct compound_hdr hdr;
6851        int status;
6852
6853        status = decode_compound_hdr(xdr, &hdr);
6854        if (!status)
6855                status = decode_sequence(xdr, &res->seq_res, req);
6856        if (!status)
6857                status = decode_putfh(xdr);
6858        if (!status)
6859                status = decode_pathconf(xdr, res->pathconf);
6860        return status;
6861}
6862
6863/*
6864 * Decode STATFS response
6865 */
6866static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6867                               void *data)
6868{
6869        struct nfs4_statfs_res *res = data;
6870        struct compound_hdr hdr;
6871        int status;
6872
6873        status = decode_compound_hdr(xdr, &hdr);
6874        if (!status)
6875                status = decode_sequence(xdr, &res->seq_res, req);
6876        if (!status)
6877                status = decode_putfh(xdr);
6878        if (!status)
6879                status = decode_statfs(xdr, res->fsstat);
6880        return status;
6881}
6882
6883/*
6884 * Decode GETATTR_BITMAP response
6885 */
6886static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6887                                    struct xdr_stream *xdr,
6888                                    void *data)
6889{
6890        struct nfs4_server_caps_res *res = data;
6891        struct compound_hdr hdr;
6892        int status;
6893
6894        status = decode_compound_hdr(xdr, &hdr);
6895        if (status)
6896                goto out;
6897        status = decode_sequence(xdr, &res->seq_res, req);
6898        if (status)
6899                goto out;
6900        status = decode_putfh(xdr);
6901        if (status)
6902                goto out;
6903        status = decode_server_caps(xdr, res);
6904out:
6905        return status;
6906}
6907
6908/*
6909 * Decode RENEW response
6910 */
6911static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6912                              void *__unused)
6913{
6914        struct compound_hdr hdr;
6915        int status;
6916
6917        status = decode_compound_hdr(xdr, &hdr);
6918        if (!status)
6919                status = decode_renew(xdr);
6920        return status;
6921}
6922
6923/*
6924 * Decode SETCLIENTID response
6925 */
6926static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6927                                    struct xdr_stream *xdr,
6928                                    void *data)
6929{
6930        struct nfs4_setclientid_res *res = data;
6931        struct compound_hdr hdr;
6932        int status;
6933
6934        status = decode_compound_hdr(xdr, &hdr);
6935        if (!status)
6936                status = decode_setclientid(xdr, res);
6937        return status;
6938}
6939
6940/*
6941 * Decode SETCLIENTID_CONFIRM response
6942 */
6943static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6944                                            struct xdr_stream *xdr,
6945                                            void *data)
6946{
6947        struct compound_hdr hdr;
6948        int status;
6949
6950        status = decode_compound_hdr(xdr, &hdr);
6951        if (!status)
6952                status = decode_setclientid_confirm(xdr);
6953        return status;
6954}
6955
6956/*
6957 * Decode DELEGRETURN response
6958 */
6959static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6960                                    struct xdr_stream *xdr,
6961                                    void *data)
6962{
6963        struct nfs4_delegreturnres *res = data;
6964        struct compound_hdr hdr;
6965        int status;
6966
6967        status = decode_compound_hdr(xdr, &hdr);
6968        if (status)
6969                goto out;
6970        status = decode_sequence(xdr, &res->seq_res, rqstp);
6971        if (status)
6972                goto out;
6973        status = decode_putfh(xdr);
6974        if (status != 0)
6975                goto out;
6976        if (res->lr_res) {
6977                status = decode_layoutreturn(xdr, res->lr_res);
6978                res->lr_ret = status;
6979                if (status)
6980                        goto out;
6981        }
6982        if (res->fattr) {
6983                status = decode_getfattr(xdr, res->fattr, res->server);
6984                if (status != 0)
6985                        goto out;
6986        }
6987        status = decode_delegreturn(xdr);
6988out:
6989        return status;
6990}
6991
6992/*
6993 * Decode FS_LOCATIONS response
6994 */
6995static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6996                                     struct xdr_stream *xdr,
6997                                     void *data)
6998{
6999        struct nfs4_fs_locations_res *res = data;
7000        struct compound_hdr hdr;
7001        int status;
7002
7003        status = decode_compound_hdr(xdr, &hdr);
7004        if (status)
7005                goto out;
7006        status = decode_sequence(xdr, &res->seq_res, req);
7007        if (status)
7008                goto out;
7009        status = decode_putfh(xdr);
7010        if (status)
7011                goto out;
7012        if (res->migration) {
7013                xdr_enter_page(xdr, PAGE_SIZE);
7014                status = decode_getfattr_generic(xdr,
7015                                        &res->fs_locations->fattr,
7016                                         NULL, res->fs_locations,
7017                                         res->fs_locations->server);
7018                if (status)
7019                        goto out;
7020                if (res->renew)
7021                        status = decode_renew(xdr);
7022        } else {
7023                status = decode_lookup(xdr);
7024                if (status)
7025                        goto out;
7026                xdr_enter_page(xdr, PAGE_SIZE);
7027                status = decode_getfattr_generic(xdr,
7028                                        &res->fs_locations->fattr,
7029                                         NULL, res->fs_locations,
7030                                         res->fs_locations->server);
7031        }
7032out:
7033        return status;
7034}
7035
7036/*
7037 * Decode SECINFO response
7038 */
7039static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7040                                struct xdr_stream *xdr,
7041                                void *data)
7042{
7043        struct nfs4_secinfo_res *res = data;
7044        struct compound_hdr hdr;
7045        int status;
7046
7047        status = decode_compound_hdr(xdr, &hdr);
7048        if (status)
7049                goto out;
7050        status = decode_sequence(xdr, &res->seq_res, rqstp);
7051        if (status)
7052                goto out;
7053        status = decode_putfh(xdr);
7054        if (status)
7055                goto out;
7056        status = decode_secinfo(xdr, res);
7057out:
7058        return status;
7059}
7060
7061/*
7062 * Decode FSID_PRESENT response
7063 */
7064static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7065                                     struct xdr_stream *xdr,
7066                                     void *data)
7067{
7068        struct nfs4_fsid_present_res *res = data;
7069        struct compound_hdr hdr;
7070        int status;
7071
7072        status = decode_compound_hdr(xdr, &hdr);
7073        if (status)
7074                goto out;
7075        status = decode_sequence(xdr, &res->seq_res, rqstp);
7076        if (status)
7077                goto out;
7078        status = decode_putfh(xdr);
7079        if (status)
7080                goto out;
7081        status = decode_getfh(xdr, res->fh);
7082        if (status)
7083                goto out;
7084        if (res->renew)
7085                status = decode_renew(xdr);
7086out:
7087        return status;
7088}
7089
7090#if defined(CONFIG_NFS_V4_1)
7091/*
7092 * Decode BIND_CONN_TO_SESSION response
7093 */
7094static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7095                                        struct xdr_stream *xdr,
7096                                        void *res)
7097{
7098        struct compound_hdr hdr;
7099        int status;
7100
7101        status = decode_compound_hdr(xdr, &hdr);
7102        if (!status)
7103                status = decode_bind_conn_to_session(xdr, res);
7104        return status;
7105}
7106
7107/*
7108 * Decode EXCHANGE_ID response
7109 */
7110static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7111                                    struct xdr_stream *xdr,
7112                                    void *res)
7113{
7114        struct compound_hdr hdr;
7115        int status;
7116
7117        status = decode_compound_hdr(xdr, &hdr);
7118        if (!status)
7119                status = decode_exchange_id(xdr, res);
7120        return status;
7121}
7122
7123/*
7124 * Decode CREATE_SESSION response
7125 */
7126static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7127                                       struct xdr_stream *xdr,
7128                                       void *res)
7129{
7130        struct compound_hdr hdr;
7131        int status;
7132
7133        status = decode_compound_hdr(xdr, &hdr);
7134        if (!status)
7135                status = decode_create_session(xdr, res);
7136        return status;
7137}
7138
7139/*
7140 * Decode DESTROY_SESSION response
7141 */
7142static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7143                                        struct xdr_stream *xdr,
7144                                        void *res)
7145{
7146        struct compound_hdr hdr;
7147        int status;
7148
7149        status = decode_compound_hdr(xdr, &hdr);
7150        if (!status)
7151                status = decode_destroy_session(xdr, res);
7152        return status;
7153}
7154
7155/*
7156 * Decode DESTROY_CLIENTID response
7157 */
7158static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7159                                        struct xdr_stream *xdr,
7160                                        void *res)
7161{
7162        struct compound_hdr hdr;
7163        int status;
7164
7165        status = decode_compound_hdr(xdr, &hdr);
7166        if (!status)
7167                status = decode_destroy_clientid(xdr, res);
7168        return status;
7169}
7170
7171/*
7172 * Decode SEQUENCE response
7173 */
7174static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7175                                 struct xdr_stream *xdr,
7176                                 void *res)
7177{
7178        struct compound_hdr hdr;
7179        int status;
7180
7181        status = decode_compound_hdr(xdr, &hdr);
7182        if (!status)
7183                status = decode_sequence(xdr, res, rqstp);
7184        return status;
7185}
7186
7187#endif
7188
7189/*
7190 * Decode GET_LEASE_TIME response
7191 */
7192static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7193                                       struct xdr_stream *xdr,
7194                                       void *data)
7195{
7196        struct nfs4_get_lease_time_res *res = data;
7197        struct compound_hdr hdr;
7198        int status;
7199
7200        status = decode_compound_hdr(xdr, &hdr);
7201        if (!status)
7202                status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
7203        if (!status)
7204                status = decode_putrootfh(xdr);
7205        if (!status)
7206                status = decode_fsinfo(xdr, res->lr_fsinfo);
7207        return status;
7208}
7209
7210#ifdef CONFIG_NFS_V4_1
7211
7212/*
7213 * Decode RECLAIM_COMPLETE response
7214 */
7215static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7216                                         struct xdr_stream *xdr,
7217                                         void *data)
7218{
7219        struct nfs41_reclaim_complete_res *res = data;
7220        struct compound_hdr hdr;
7221        int status;
7222
7223        status = decode_compound_hdr(xdr, &hdr);
7224        if (!status)
7225                status = decode_sequence(xdr, &res->seq_res, rqstp);
7226        if (!status)
7227                status = decode_reclaim_complete(xdr, NULL);
7228        return status;
7229}
7230
7231/*
7232 * Decode GETDEVINFO response
7233 */
7234static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7235                                      struct xdr_stream *xdr,
7236                                      void *data)
7237{
7238        struct nfs4_getdeviceinfo_res *res = data;
7239        struct compound_hdr hdr;
7240        int status;
7241
7242        status = decode_compound_hdr(xdr, &hdr);
7243        if (status != 0)
7244                goto out;
7245        status = decode_sequence(xdr, &res->seq_res, rqstp);
7246        if (status != 0)
7247                goto out;
7248        status = decode_getdeviceinfo(xdr, res);
7249out:
7250        return status;
7251}
7252
7253/*
7254 * Decode LAYOUTGET response
7255 */
7256static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7257                                  struct xdr_stream *xdr,
7258                                  void *data)
7259{
7260        struct nfs4_layoutget_res *res = data;
7261        struct compound_hdr hdr;
7262        int status;
7263
7264        status = decode_compound_hdr(xdr, &hdr);
7265        if (status)
7266                goto out;
7267        status = decode_sequence(xdr, &res->seq_res, rqstp);
7268        if (status)
7269                goto out;
7270        status = decode_putfh(xdr);
7271        if (status)
7272                goto out;
7273        status = decode_layoutget(xdr, rqstp, res);
7274out:
7275        return status;
7276}
7277
7278/*
7279 * Decode LAYOUTRETURN response
7280 */
7281static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7282                                     struct xdr_stream *xdr,
7283                                     void *data)
7284{
7285        struct nfs4_layoutreturn_res *res = data;
7286        struct compound_hdr hdr;
7287        int status;
7288
7289        status = decode_compound_hdr(xdr, &hdr);
7290        if (status)
7291                goto out;
7292        status = decode_sequence(xdr, &res->seq_res, rqstp);
7293        if (status)
7294                goto out;
7295        status = decode_putfh(xdr);
7296        if (status)
7297                goto out;
7298        status = decode_layoutreturn(xdr, res);
7299out:
7300        return status;
7301}
7302
7303/*
7304 * Decode LAYOUTCOMMIT response
7305 */
7306static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7307                                     struct xdr_stream *xdr,
7308                                     void *data)
7309{
7310        struct nfs4_layoutcommit_res *res = data;
7311        struct compound_hdr hdr;
7312        int status;
7313
7314        status = decode_compound_hdr(xdr, &hdr);
7315        if (status)
7316                goto out;
7317        status = decode_sequence(xdr, &res->seq_res, rqstp);
7318        if (status)
7319                goto out;
7320        status = decode_putfh(xdr);
7321        if (status)
7322                goto out;
7323        status = decode_layoutcommit(xdr, rqstp, res);
7324        if (status)
7325                goto out;
7326        decode_getfattr(xdr, res->fattr, res->server);
7327out:
7328        return status;
7329}
7330
7331/*
7332 * Decode SECINFO_NO_NAME response
7333 */
7334static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7335                                        struct xdr_stream *xdr,
7336                                        void *data)
7337{
7338        struct nfs4_secinfo_res *res = data;
7339        struct compound_hdr hdr;
7340        int status;
7341
7342        status = decode_compound_hdr(xdr, &hdr);
7343        if (status)
7344                goto out;
7345        status = decode_sequence(xdr, &res->seq_res, rqstp);
7346        if (status)
7347                goto out;
7348        status = decode_putrootfh(xdr);
7349        if (status)
7350                goto out;
7351        status = decode_secinfo_no_name(xdr, res);
7352out:
7353        return status;
7354}
7355
7356/*
7357 * Decode TEST_STATEID response
7358 */
7359static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7360                                     struct xdr_stream *xdr,
7361                                     void *data)
7362{
7363        struct nfs41_test_stateid_res *res = data;
7364        struct compound_hdr hdr;
7365        int status;
7366
7367        status = decode_compound_hdr(xdr, &hdr);
7368        if (status)
7369                goto out;
7370        status = decode_sequence(xdr, &res->seq_res, rqstp);
7371        if (status)
7372                goto out;
7373        status = decode_test_stateid(xdr, res);
7374out:
7375        return status;
7376}
7377
7378/*
7379 * Decode FREE_STATEID response
7380 */
7381static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7382                                     struct xdr_stream *xdr,
7383                                     void *data)
7384{
7385        struct nfs41_free_stateid_res *res = data;
7386        struct compound_hdr hdr;
7387        int status;
7388
7389        status = decode_compound_hdr(xdr, &hdr);
7390        if (status)
7391                goto out;
7392        status = decode_sequence(xdr, &res->seq_res, rqstp);
7393        if (status)
7394                goto out;
7395        status = decode_free_stateid(xdr, res);
7396out:
7397        return status;
7398}
7399#endif /* CONFIG_NFS_V4_1 */
7400
7401/**
7402 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7403 *                      the local page cache.
7404 * @xdr: XDR stream where entry resides
7405 * @entry: buffer to fill in with entry data
7406 * @plus: boolean indicating whether this should be a readdirplus entry
7407 *
7408 * Returns zero if successful, otherwise a negative errno value is
7409 * returned.
7410 *
7411 * This function is not invoked during READDIR reply decoding, but
7412 * rather whenever an application invokes the getdents(2) system call
7413 * on a directory already in our cache.
7414 */
7415int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7416                       bool plus)
7417{
7418        unsigned int savep;
7419        uint32_t bitmap[3] = {0};
7420        uint32_t len;
7421        uint64_t new_cookie;
7422        __be32 *p = xdr_inline_decode(xdr, 4);
7423        if (unlikely(!p))
7424                return -EAGAIN;
7425        if (*p == xdr_zero) {
7426                p = xdr_inline_decode(xdr, 4);
7427                if (unlikely(!p))
7428                        return -EAGAIN;
7429                if (*p == xdr_zero)
7430                        return -EAGAIN;
7431                entry->eof = 1;
7432                return -EBADCOOKIE;
7433        }
7434
7435        p = xdr_inline_decode(xdr, 12);
7436        if (unlikely(!p))
7437                return -EAGAIN;
7438        p = xdr_decode_hyper(p, &new_cookie);
7439        entry->len = be32_to_cpup(p);
7440
7441        p = xdr_inline_decode(xdr, entry->len);
7442        if (unlikely(!p))
7443                return -EAGAIN;
7444        entry->name = (const char *) p;
7445
7446        /*
7447         * In case the server doesn't return an inode number,
7448         * we fake one here.  (We don't use inode number 0,
7449         * since glibc seems to choke on it...)
7450         */
7451        entry->ino = 1;
7452        entry->fattr->valid = 0;
7453
7454        if (decode_attr_bitmap(xdr, bitmap) < 0)
7455                return -EAGAIN;
7456
7457        if (decode_attr_length(xdr, &len, &savep) < 0)
7458                return -EAGAIN;
7459
7460        if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7461                        NULL, entry->server) < 0)
7462                return -EAGAIN;
7463        if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7464                entry->ino = entry->fattr->mounted_on_fileid;
7465        else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7466                entry->ino = entry->fattr->fileid;
7467
7468        entry->d_type = DT_UNKNOWN;
7469        if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7470                entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7471
7472        entry->prev_cookie = entry->cookie;
7473        entry->cookie = new_cookie;
7474
7475        return 0;
7476}
7477
7478/*
7479 * We need to translate between nfs status return values and
7480 * the local errno values which may not be the same.
7481 */
7482static struct {
7483        int stat;
7484        int errno;
7485} nfs_errtbl[] = {
7486        { NFS4_OK,              0               },
7487        { NFS4ERR_PERM,         -EPERM          },
7488        { NFS4ERR_NOENT,        -ENOENT         },
7489        { NFS4ERR_IO,           -errno_NFSERR_IO},
7490        { NFS4ERR_NXIO,         -ENXIO          },
7491        { NFS4ERR_ACCESS,       -EACCES         },
7492        { NFS4ERR_EXIST,        -EEXIST         },
7493        { NFS4ERR_XDEV,         -EXDEV          },
7494        { NFS4ERR_NOTDIR,       -ENOTDIR        },
7495        { NFS4ERR_ISDIR,        -EISDIR         },
7496        { NFS4ERR_INVAL,        -EINVAL         },
7497        { NFS4ERR_FBIG,         -EFBIG          },
7498        { NFS4ERR_NOSPC,        -ENOSPC         },
7499        { NFS4ERR_ROFS,         -EROFS          },
7500        { NFS4ERR_MLINK,        -EMLINK         },
7501        { NFS4ERR_NAMETOOLONG,  -ENAMETOOLONG   },
7502        { NFS4ERR_NOTEMPTY,     -ENOTEMPTY      },
7503        { NFS4ERR_DQUOT,        -EDQUOT         },
7504        { NFS4ERR_STALE,        -ESTALE         },
7505        { NFS4ERR_BADHANDLE,    -EBADHANDLE     },
7506        { NFS4ERR_BAD_COOKIE,   -EBADCOOKIE     },
7507        { NFS4ERR_NOTSUPP,      -ENOTSUPP       },
7508        { NFS4ERR_TOOSMALL,     -ETOOSMALL      },
7509        { NFS4ERR_SERVERFAULT,  -EREMOTEIO      },
7510        { NFS4ERR_BADTYPE,      -EBADTYPE       },
7511        { NFS4ERR_LOCKED,       -EAGAIN         },
7512        { NFS4ERR_SYMLINK,      -ELOOP          },
7513        { NFS4ERR_OP_ILLEGAL,   -EOPNOTSUPP     },
7514        { NFS4ERR_DEADLOCK,     -EDEADLK        },
7515        { NFS4ERR_NOXATTR,      -ENODATA        },
7516        { NFS4ERR_XATTR2BIG,    -E2BIG          },
7517        { -1,                   -EIO            }
7518};
7519
7520/*
7521 * Convert an NFS error code to a local one.
7522 * This one is used jointly by NFSv2 and NFSv3.
7523 */
7524static int
7525nfs4_stat_to_errno(int stat)
7526{
7527        int i;
7528        for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7529                if (nfs_errtbl[i].stat == stat)
7530                        return nfs_errtbl[i].errno;
7531        }
7532        if (stat <= 10000 || stat > 10100) {
7533                /* The server is looney tunes. */
7534                return -EREMOTEIO;
7535        }
7536        /* If we cannot translate the error, the recovery routines should
7537         * handle it.
7538         * Note: remaining NFSv4 error codes have values > 10000, so should
7539         * not conflict with native Linux error codes.
7540         */
7541        return -stat;
7542}
7543
7544#ifdef CONFIG_NFS_V4_2
7545#include "nfs42xdr.c"
7546#endif /* CONFIG_NFS_V4_2 */
7547
7548#define PROC(proc, argtype, restype)                            \
7549[NFSPROC4_CLNT_##proc] = {                                      \
7550        .p_proc   = NFSPROC4_COMPOUND,                          \
7551        .p_encode = nfs4_xdr_##argtype,                         \
7552        .p_decode = nfs4_xdr_##restype,                         \
7553        .p_arglen = NFS4_##argtype##_sz,                        \
7554        .p_replen = NFS4_##restype##_sz,                        \
7555        .p_statidx = NFSPROC4_CLNT_##proc,                      \
7556        .p_name   = #proc,                                      \
7557}
7558
7559#define STUB(proc)              \
7560[NFSPROC4_CLNT_##proc] = {      \
7561        .p_name = #proc,        \
7562}
7563
7564#if defined(CONFIG_NFS_V4_1)
7565#define PROC41(proc, argtype, restype)                          \
7566        PROC(proc, argtype, restype)
7567#else
7568#define PROC41(proc, argtype, restype)                          \
7569        STUB(proc)
7570#endif
7571
7572#if defined(CONFIG_NFS_V4_2)
7573#define PROC42(proc, argtype, restype)                          \
7574        PROC(proc, argtype, restype)
7575#else
7576#define PROC42(proc, argtype, restype)                          \
7577        STUB(proc)
7578#endif
7579
7580const struct rpc_procinfo nfs4_procedures[] = {
7581        PROC(READ,              enc_read,               dec_read),
7582        PROC(WRITE,             enc_write,              dec_write),
7583        PROC(COMMIT,            enc_commit,             dec_commit),
7584        PROC(OPEN,              enc_open,               dec_open),
7585        PROC(OPEN_CONFIRM,      enc_open_confirm,       dec_open_confirm),
7586        PROC(OPEN_NOATTR,       enc_open_noattr,        dec_open_noattr),
7587        PROC(OPEN_DOWNGRADE,    enc_open_downgrade,     dec_open_downgrade),
7588        PROC(CLOSE,             enc_close,              dec_close),
7589        PROC(SETATTR,           enc_setattr,            dec_setattr),
7590        PROC(FSINFO,            enc_fsinfo,             dec_fsinfo),
7591        PROC(RENEW,             enc_renew,              dec_renew),
7592        PROC(SETCLIENTID,       enc_setclientid,        dec_setclientid),
7593        PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7594        PROC(LOCK,              enc_lock,               dec_lock),
7595        PROC(LOCKT,             enc_lockt,              dec_lockt),
7596        PROC(LOCKU,             enc_locku,              dec_locku),
7597        PROC(ACCESS,            enc_access,             dec_access),
7598        PROC(GETATTR,           enc_getattr,            dec_getattr),
7599        PROC(LOOKUP,            enc_lookup,             dec_lookup),
7600        PROC(LOOKUP_ROOT,       enc_lookup_root,        dec_lookup_root),
7601        PROC(REMOVE,            enc_remove,             dec_remove),
7602        PROC(RENAME,            enc_rename,             dec_rename),
7603        PROC(LINK,              enc_link,               dec_link),
7604        PROC(SYMLINK,           enc_symlink,            dec_symlink),
7605        PROC(CREATE,            enc_create,             dec_create),
7606        PROC(PATHCONF,          enc_pathconf,           dec_pathconf),
7607        PROC(STATFS,            enc_statfs,             dec_statfs),
7608        PROC(READLINK,          enc_readlink,           dec_readlink),
7609        PROC(READDIR,           enc_readdir,            dec_readdir),
7610        PROC(SERVER_CAPS,       enc_server_caps,        dec_server_caps),
7611        PROC(DELEGRETURN,       enc_delegreturn,        dec_delegreturn),
7612        PROC(GETACL,            enc_getacl,             dec_getacl),
7613        PROC(SETACL,            enc_setacl,             dec_setacl),
7614        PROC(FS_LOCATIONS,      enc_fs_locations,       dec_fs_locations),
7615        PROC(RELEASE_LOCKOWNER, enc_release_lockowner,  dec_release_lockowner),
7616        PROC(SECINFO,           enc_secinfo,            dec_secinfo),
7617        PROC(FSID_PRESENT,      enc_fsid_present,       dec_fsid_present),
7618        PROC41(EXCHANGE_ID,     enc_exchange_id,        dec_exchange_id),
7619        PROC41(CREATE_SESSION,  enc_create_session,     dec_create_session),
7620        PROC41(DESTROY_SESSION, enc_destroy_session,    dec_destroy_session),
7621        PROC41(SEQUENCE,        enc_sequence,           dec_sequence),
7622        PROC(GET_LEASE_TIME,    enc_get_lease_time,     dec_get_lease_time),
7623        PROC41(RECLAIM_COMPLETE,enc_reclaim_complete,   dec_reclaim_complete),
7624        PROC41(GETDEVICEINFO,   enc_getdeviceinfo,      dec_getdeviceinfo),
7625        PROC41(LAYOUTGET,       enc_layoutget,          dec_layoutget),
7626        PROC41(LAYOUTCOMMIT,    enc_layoutcommit,       dec_layoutcommit),
7627        PROC41(LAYOUTRETURN,    enc_layoutreturn,       dec_layoutreturn),
7628        PROC41(SECINFO_NO_NAME, enc_secinfo_no_name,    dec_secinfo_no_name),
7629        PROC41(TEST_STATEID,    enc_test_stateid,       dec_test_stateid),
7630        PROC41(FREE_STATEID,    enc_free_stateid,       dec_free_stateid),
7631        STUB(GETDEVICELIST),
7632        PROC41(BIND_CONN_TO_SESSION,
7633                        enc_bind_conn_to_session, dec_bind_conn_to_session),
7634        PROC41(DESTROY_CLIENTID,enc_destroy_clientid,   dec_destroy_clientid),
7635        PROC42(SEEK,            enc_seek,               dec_seek),
7636        PROC42(ALLOCATE,        enc_allocate,           dec_allocate),
7637        PROC42(DEALLOCATE,      enc_deallocate,         dec_deallocate),
7638        PROC42(LAYOUTSTATS,     enc_layoutstats,        dec_layoutstats),
7639        PROC42(CLONE,           enc_clone,              dec_clone),
7640        PROC42(COPY,            enc_copy,               dec_copy),
7641        PROC42(OFFLOAD_CANCEL,  enc_offload_cancel,     dec_offload_cancel),
7642        PROC42(COPY_NOTIFY,     enc_copy_notify,        dec_copy_notify),
7643        PROC(LOOKUPP,           enc_lookupp,            dec_lookupp),
7644        PROC42(LAYOUTERROR,     enc_layouterror,        dec_layouterror),
7645        PROC42(GETXATTR,        enc_getxattr,           dec_getxattr),
7646        PROC42(SETXATTR,        enc_setxattr,           dec_setxattr),
7647        PROC42(LISTXATTRS,      enc_listxattrs,         dec_listxattrs),
7648        PROC42(REMOVEXATTR,     enc_removexattr,        dec_removexattr),
7649        PROC42(READ_PLUS,       enc_read_plus,          dec_read_plus),
7650};
7651
7652static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
7653const struct rpc_version nfs_version4 = {
7654        .number                 = 4,
7655        .nrprocs                = ARRAY_SIZE(nfs4_procedures),
7656        .procs                  = nfs4_procedures,
7657        .counts                 = nfs_version4_counts,
7658};
7659