11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * fs/nfs/nfs4xdr.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Client-side XDR for NFSv4. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (c) 2002 The Regents of the University of Michigan. 71da177e4SLinus Torvalds * All rights reserved. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Kendrick Smith <kmsmith@umich.edu> 101da177e4SLinus Torvalds * Andy Adamson <andros@umich.edu> 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without 131da177e4SLinus Torvalds * modification, are permitted provided that the following conditions 141da177e4SLinus Torvalds * are met: 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright 171da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer. 181da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce the above copyright 191da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer in the 201da177e4SLinus Torvalds * documentation and/or other materials provided with the distribution. 211da177e4SLinus Torvalds * 3. Neither the name of the University nor the names of its 221da177e4SLinus Torvalds * contributors may be used to endorse or promote products derived 231da177e4SLinus Torvalds * from this software without specific prior written permission. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 261da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 271da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 281da177e4SLinus Torvalds * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291da177e4SLinus Torvalds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301da177e4SLinus Torvalds * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311da177e4SLinus Torvalds * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 321da177e4SLinus Torvalds * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 331da177e4SLinus Torvalds * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 341da177e4SLinus Torvalds * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 351da177e4SLinus Torvalds * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 361da177e4SLinus Torvalds */ 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #include <linux/param.h> 391da177e4SLinus Torvalds #include <linux/time.h> 401da177e4SLinus Torvalds #include <linux/mm.h> 411da177e4SLinus Torvalds #include <linux/errno.h> 421da177e4SLinus Torvalds #include <linux/string.h> 431da177e4SLinus Torvalds #include <linux/in.h> 441da177e4SLinus Torvalds #include <linux/pagemap.h> 451da177e4SLinus Torvalds #include <linux/proc_fs.h> 461da177e4SLinus Torvalds #include <linux/kdev_t.h> 47db8ac8baSWeston Andros Adamson #include <linux/module.h> 48db8ac8baSWeston Andros Adamson #include <linux/utsname.h> 491da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h> 502449ea2eSAlexandros Batsakis #include <linux/sunrpc/msg_prot.h> 515a5ea0d4SBryan Schumaker #include <linux/sunrpc/gss_api.h> 521da177e4SLinus Torvalds #include <linux/nfs.h> 531da177e4SLinus Torvalds #include <linux/nfs4.h> 541da177e4SLinus Torvalds #include <linux/nfs_fs.h> 551da177e4SLinus Torvalds #include <linux/nfs_idmap.h> 56f092075dSChuck Lever 574ce79717STrond Myklebust #include "nfs4_fs.h" 584882ef72SAlexandros Batsakis #include "internal.h" 59b1f69b75SAndy Adamson #include "pnfs.h" 60f092075dSChuck Lever #include "netns.h" 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 651da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 661da177e4SLinus Torvalds 670a8ea437SDavid Howells static int nfs4_stat_to_errno(int); 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 701da177e4SLinus Torvalds #ifdef DEBUG 711da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20 721da177e4SLinus Torvalds #else 731da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0 741da177e4SLinus Torvalds #endif 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds /* lock,open owner id: 779f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 781da177e4SLinus Torvalds */ 7995b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2) 80d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4) 819104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 821da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 831da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 841da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1) 851da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2) 869104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 879104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 889104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 899104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 901da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 911da177e4SLinus Torvalds (NFS4_FHSIZE >> 2)) 921da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz) 931da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 941da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 951da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz) 961da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 971da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2)) 98e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4 9996928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 1001da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 1011da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 102bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 103bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 10488034c3dSAndy Adamson /* We support only one layout type per file system */ 10588034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8) 10696928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */ 10796928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 10888034c3dSAndy Adamson 3 + 3 + 3 + nfs4_owner_maxsz + \ 10988034c3dSAndy Adamson nfs4_group_maxsz + decode_mdsthreshold_maxsz)) 11096928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 11196928206SJ. Bruce Fields nfs4_fattr_value_maxsz) 11296928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 1139104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 1149104a55dSTrond Myklebust 1 + 2 + 1 + \ 1159104a55dSTrond Myklebust nfs4_owner_maxsz + \ 1169104a55dSTrond Myklebust nfs4_group_maxsz + \ 1179104a55dSTrond Myklebust 4 + 4) 1181da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz) 1191da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz) 12056ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 12156ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 1222f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz) 123dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three 124dae100c2SFred Isaman * layout types will be returned. 125dae100c2SFred Isaman */ 126dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 127dae100c2SFred Isaman nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 1281da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 1291da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz) 1301da177e4SLinus Torvalds #define encode_setclientid_maxsz \ 1311da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 132cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 133cc38bac3SChuck Lever XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ 134cc38bac3SChuck Lever 1 /* sc_prog */ + \ 135cc38bac3SChuck Lever XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 136cc38bac3SChuck Lever XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 137cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1381da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1391da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1401da177e4SLinus Torvalds 2 + \ 1411da177e4SLinus Torvalds 1024) /* large value for CLID_INUSE */ 1421da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \ 1431da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 1441da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2)) 1451da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \ 1461da177e4SLinus Torvalds (op_decode_hdr_maxsz) 147e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 148e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz) 1492cebf828STrond Myklebust #define encode_share_access_maxsz \ 1502cebf828STrond Myklebust (2) 1514882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1522cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1532cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1542cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1552cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1562cebf828STrond Myklebust open_owner_id_maxsz + \ 1572cebf828STrond Myklebust encode_opentype_maxsz + \ 1582cebf828STrond Myklebust encode_claim_null_maxsz) 1592cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1609104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1612cebf828STrond Myklebust decode_ace_maxsz) 1622cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1632cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1649104a55dSTrond Myklebust decode_stateid_maxsz + \ 1652cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1662cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1672cebf828STrond Myklebust decode_delegation_maxsz) 1689104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1699104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1709104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1719104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1729104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1739104a55dSTrond Myklebust decode_stateid_maxsz) 1749104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 1759104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1769104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 1779104a55dSTrond Myklebust encode_share_access_maxsz) 1789104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 1799104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1809104a55dSTrond Myklebust decode_stateid_maxsz) 1819104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 1829104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 1839104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 1849104a55dSTrond Myklebust decode_stateid_maxsz) 1859104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 1869104a55dSTrond Myklebust encode_stateid_maxsz + \ 1879104a55dSTrond Myklebust encode_attrs_maxsz) 1889104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 1899104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 1909104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 1919104a55dSTrond Myklebust encode_stateid_maxsz + 3) 1929104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 1939104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 1949104a55dSTrond Myklebust 2 + encode_verifier_maxsz + 5) 1959104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 1969104a55dSTrond Myklebust decode_verifier_maxsz) 1979104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 1989104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 1999104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2009104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2019104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2029104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2039104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2049104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2059104a55dSTrond Myklebust decode_verifier_maxsz) 2061da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2071da177e4SLinus Torvalds nfs4_name_maxsz) 2086ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2096ce18391SBenny Halevy decode_change_info_maxsz) 2101da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2111da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2126ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2136ce18391SBenny Halevy decode_change_info_maxsz + \ 2146ce18391SBenny Halevy decode_change_info_maxsz) 2151da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2161da177e4SLinus Torvalds nfs4_name_maxsz) 2176ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 218daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2199104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2209104a55dSTrond Myklebust 7 + \ 221daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 222daccbdedSTrond Myklebust encode_lockowner_maxsz) 2239104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2249104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2259104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2269104a55dSTrond Myklebust decode_lock_denied_maxsz) 227daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 228daccbdedSTrond Myklebust encode_lockowner_maxsz) 2299104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2309104a55dSTrond Myklebust decode_lock_denied_maxsz) 2319104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2329104a55dSTrond Myklebust encode_stateid_maxsz + \ 2339104a55dSTrond Myklebust 4) 2349104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2359104a55dSTrond Myklebust decode_stateid_maxsz) 236d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 237d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 238d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 239d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 240d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2419104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2429104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2431da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2441da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 24594a6d753SChuck Lever 1 + \ 24696928206SJ. Bruce Fields nfs4_fattr_maxsz) 2471da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2481da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2499104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2509104a55dSTrond Myklebust encode_attrs_maxsz) 2512cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2522cebf828STrond Myklebust decode_change_info_maxsz + \ 2532cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2549104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2559104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2561da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2571da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2589104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2599104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2609104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2619104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2629104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2639104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 264e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 265e6889620STrond Myklebust (encode_getattr_maxsz) 266e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 267e6889620STrond Myklebust (0) 2685a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2691650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2709b7b9fccSAndy Adamson 2719b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 272fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 273fc931582SAndy Adamson 27499fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 27599fe60d0SBenny Halevy encode_verifier_maxsz + \ 27699fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 27799fe60d0SBenny Halevy XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ 27899fe60d0SBenny Halevy 1 /* flags */ + \ 27999fe60d0SBenny Halevy 1 /* spa_how */ + \ 28099fe60d0SBenny Halevy 0 /* SP4_NONE (for now) */ + \ 281db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 282db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 283db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 284db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 285db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 286db8ac8baSWeston Andros Adamson 3 /* nii_date */) 28799fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 28899fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 28999fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 29099fe60d0SBenny Halevy 1 /* eir_flags */ + \ 29199fe60d0SBenny Halevy 1 /* spr_how */ + \ 29299fe60d0SBenny Halevy 0 /* SP4_NONE (for now) */ + \ 29399fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 29499fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 29599fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 29699fe60d0SBenny Halevy /* eir_server_scope<> */ \ 29799fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 29899fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 2997d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3007d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3017d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3027d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3037d2ed9acSWeston Andros Adamson 3 /* nii_date */) 304fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 305fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 306fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 307fc931582SAndy Adamson 1 /* ca_rdma_ird */) 308fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 309fc931582SAndy Adamson 2 /* csa_clientid */ + \ 310fc931582SAndy Adamson 1 /* csa_sequence */ + \ 311fc931582SAndy Adamson 1 /* csa_flags */ + \ 312fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 313fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 314fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 315fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 316fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 317fc931582SAndy Adamson 1 /* stamp */ + \ 318fc931582SAndy Adamson 1 /* machinename.len */ + \ 319fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 320fc931582SAndy Adamson 1 /* uid */ + \ 321fc931582SAndy Adamson 1 /* gid */ + \ 322fc931582SAndy Adamson 1 /* gids.len (0) */) 323fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 324fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 325fc931582SAndy Adamson 1 /* csr_sequence */ + \ 326fc931582SAndy Adamson 1 /* csr_flags */ + \ 327fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 328fc931582SAndy Adamson decode_channel_attrs_maxsz) 3297c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3307c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3317c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3327c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3337c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3347c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3357c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3367c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3377c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3387c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3390f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3400f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 34166245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 34266245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 343fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 344fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 345fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 346fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 34718019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 34818019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 3497f11d8d3SAndy Adamson #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \ 3507f11d8d3SAndy Adamson encode_verifier_maxsz) 3517f11d8d3SAndy Adamson #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \ 3527f11d8d3SAndy Adamson 2 /* nfs_cookie4 gdlr_cookie */ + \ 3537f11d8d3SAndy Adamson decode_verifier_maxsz \ 3547f11d8d3SAndy Adamson /* verifier4 gdlr_verifier */ + \ 3557f11d8d3SAndy Adamson 1 /* gdlr_deviceid_list count */ + \ 3567f11d8d3SAndy Adamson XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \ 3577f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE) \ 3587f11d8d3SAndy Adamson /* gdlr_deviceid_list */ + \ 3597f11d8d3SAndy Adamson 1 /* bool gdlr_eof */) 360b1f69b75SAndy Adamson #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \ 361b1f69b75SAndy Adamson XDR_QUADLEN(NFS4_DEVICEID4_SIZE)) 362b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 363b1f69b75SAndy Adamson 1 /* layout type */ + \ 364b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 365b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 366b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 367b1f69b75SAndy Adamson 1 /* notification bitmap */) 368b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 369b1f69b75SAndy Adamson encode_stateid_maxsz) 370b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 371b1f69b75SAndy Adamson decode_stateid_maxsz + \ 372b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 373863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 374863a3c6cSAndy Adamson 2 /* offset */ + \ 375863a3c6cSAndy Adamson 2 /* length */ + \ 376863a3c6cSAndy Adamson 1 /* reclaim */ + \ 377863a3c6cSAndy Adamson encode_stateid_maxsz + \ 378863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 379863a3c6cSAndy Adamson 2 /* last byte written */ + \ 380863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 381863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 382863a3c6cSAndy Adamson 1 /* NULL filelayout layoutupdate4 payload */) 383863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 384cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 385cbe82603SBenny Halevy encode_stateid_maxsz + \ 386cbe82603SBenny Halevy 1 /* FIXME: opaque lrf_body always empty at the moment */) 387cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 388cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 389fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 390fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 3917d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 3927d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 3937d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 3949aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 3959aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 3969aeda35fSBryan Schumaker #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1) 3979b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 3989b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 3999b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 4009b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4019b7b9fccSAndy Adamson 4021da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4031da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4041da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4059b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4061da177e4SLinus Torvalds encode_putfh_maxsz + \ 4079104a55dSTrond Myklebust encode_read_maxsz) 4081da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4099b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4101da177e4SLinus Torvalds decode_putfh_maxsz + \ 4119104a55dSTrond Myklebust decode_read_maxsz) 4121da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4139b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4141da177e4SLinus Torvalds encode_putfh_maxsz + \ 4159104a55dSTrond Myklebust encode_readlink_maxsz) 4161da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4181da177e4SLinus Torvalds decode_putfh_maxsz + \ 4199104a55dSTrond Myklebust decode_readlink_maxsz) 4201da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4219b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4221da177e4SLinus Torvalds encode_putfh_maxsz + \ 4239104a55dSTrond Myklebust encode_readdir_maxsz) 4241da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4259b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4261da177e4SLinus Torvalds decode_putfh_maxsz + \ 4279104a55dSTrond Myklebust decode_readdir_maxsz) 4281da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4299b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4301da177e4SLinus Torvalds encode_putfh_maxsz + \ 4319104a55dSTrond Myklebust encode_write_maxsz + \ 4324f9838c7STrond Myklebust encode_getattr_maxsz) 4331da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4349b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4351da177e4SLinus Torvalds decode_putfh_maxsz + \ 4369104a55dSTrond Myklebust decode_write_maxsz + \ 4374f9838c7STrond Myklebust decode_getattr_maxsz) 4381da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4399b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4401da177e4SLinus Torvalds encode_putfh_maxsz + \ 4418582715eSTrond Myklebust encode_commit_maxsz) 4421da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4439b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4441da177e4SLinus Torvalds decode_putfh_maxsz + \ 4458582715eSTrond Myklebust decode_commit_maxsz) 4461da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4479b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4481da177e4SLinus Torvalds encode_putfh_maxsz + \ 4492cebf828STrond Myklebust encode_open_maxsz + \ 4502cebf828STrond Myklebust encode_getfh_maxsz + \ 4512cebf828STrond Myklebust encode_getattr_maxsz) 4521da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4539b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4541da177e4SLinus Torvalds decode_putfh_maxsz + \ 4552cebf828STrond Myklebust decode_open_maxsz + \ 4562cebf828STrond Myklebust decode_getfh_maxsz + \ 4572cebf828STrond Myklebust decode_getattr_maxsz) 4581da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4591da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4601da177e4SLinus Torvalds encode_putfh_maxsz + \ 4619104a55dSTrond Myklebust encode_open_confirm_maxsz) 4629104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4639104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4641da177e4SLinus Torvalds decode_putfh_maxsz + \ 4659104a55dSTrond Myklebust decode_open_confirm_maxsz) 4661da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 4679b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4681da177e4SLinus Torvalds encode_putfh_maxsz + \ 4692cebf828STrond Myklebust encode_open_maxsz + \ 4702cebf828STrond Myklebust encode_getattr_maxsz) 4711da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 4729b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4731da177e4SLinus Torvalds decode_putfh_maxsz + \ 4742cebf828STrond Myklebust decode_open_maxsz + \ 4752cebf828STrond Myklebust decode_getattr_maxsz) 4761da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 4771da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4789b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4791da177e4SLinus Torvalds encode_putfh_maxsz + \ 4809104a55dSTrond Myklebust encode_open_downgrade_maxsz + \ 481516a6af6STrond Myklebust encode_getattr_maxsz) 4821da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 4831da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 4849b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4851da177e4SLinus Torvalds decode_putfh_maxsz + \ 4869104a55dSTrond Myklebust decode_open_downgrade_maxsz + \ 487516a6af6STrond Myklebust decode_getattr_maxsz) 4881da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 4899b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4901da177e4SLinus Torvalds encode_putfh_maxsz + \ 4919104a55dSTrond Myklebust encode_close_maxsz + \ 492516a6af6STrond Myklebust encode_getattr_maxsz) 4931da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 4949b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4951da177e4SLinus Torvalds decode_putfh_maxsz + \ 4969104a55dSTrond Myklebust decode_close_maxsz + \ 497516a6af6STrond Myklebust decode_getattr_maxsz) 4981da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 4999b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5001da177e4SLinus Torvalds encode_putfh_maxsz + \ 5019104a55dSTrond Myklebust encode_setattr_maxsz + \ 5021da177e4SLinus Torvalds encode_getattr_maxsz) 5031da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5049b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5051da177e4SLinus Torvalds decode_putfh_maxsz + \ 5069104a55dSTrond Myklebust decode_setattr_maxsz + \ 5079104a55dSTrond Myklebust decode_getattr_maxsz) 5081da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5099b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5101da177e4SLinus Torvalds encode_putfh_maxsz + \ 5111da177e4SLinus Torvalds encode_fsinfo_maxsz) 5121da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5139b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5141da177e4SLinus Torvalds decode_putfh_maxsz + \ 5151da177e4SLinus Torvalds decode_fsinfo_maxsz) 5161da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5171da177e4SLinus Torvalds encode_renew_maxsz) 5181da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5191da177e4SLinus Torvalds decode_renew_maxsz) 5201da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5211da177e4SLinus Torvalds encode_setclientid_maxsz) 5221da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5231da177e4SLinus Torvalds decode_setclientid_maxsz) 5241da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5251da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5261da177e4SLinus Torvalds encode_setclientid_confirm_maxsz + \ 5271da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 5281da177e4SLinus Torvalds encode_fsinfo_maxsz) 5291da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5301da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5311da177e4SLinus Torvalds decode_setclientid_confirm_maxsz + \ 5321da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 5331da177e4SLinus Torvalds decode_fsinfo_maxsz) 5341da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5359b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5361da177e4SLinus Torvalds encode_putfh_maxsz + \ 5379104a55dSTrond Myklebust encode_lock_maxsz) 5381da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5399b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5401da177e4SLinus Torvalds decode_putfh_maxsz + \ 5419104a55dSTrond Myklebust decode_lock_maxsz) 5421da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5439b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5441da177e4SLinus Torvalds encode_putfh_maxsz + \ 5459104a55dSTrond Myklebust encode_lockt_maxsz) 5469104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5479b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5489104a55dSTrond Myklebust decode_putfh_maxsz + \ 5499104a55dSTrond Myklebust decode_lockt_maxsz) 5501da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5519b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5521da177e4SLinus Torvalds encode_putfh_maxsz + \ 5539104a55dSTrond Myklebust encode_locku_maxsz) 5541da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5559b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5561da177e4SLinus Torvalds decode_putfh_maxsz + \ 5579104a55dSTrond Myklebust decode_locku_maxsz) 558d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 559d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 560d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 561d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 562d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 563d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5641da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5659b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5661da177e4SLinus Torvalds encode_putfh_maxsz + \ 56776b32999STrond Myklebust encode_access_maxsz + \ 56876b32999STrond Myklebust encode_getattr_maxsz) 5691da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5709b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5711da177e4SLinus Torvalds decode_putfh_maxsz + \ 57276b32999STrond Myklebust decode_access_maxsz + \ 57376b32999STrond Myklebust decode_getattr_maxsz) 5741da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 5759b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5761da177e4SLinus Torvalds encode_putfh_maxsz + \ 5771da177e4SLinus Torvalds encode_getattr_maxsz) 5781da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 5799b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5801da177e4SLinus Torvalds decode_putfh_maxsz + \ 5811da177e4SLinus Torvalds decode_getattr_maxsz) 5821da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 5839b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5841da177e4SLinus Torvalds encode_putfh_maxsz + \ 5851da177e4SLinus Torvalds encode_lookup_maxsz + \ 5861da177e4SLinus Torvalds encode_getattr_maxsz + \ 5871da177e4SLinus Torvalds encode_getfh_maxsz) 5881da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 5899b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5901da177e4SLinus Torvalds decode_putfh_maxsz + \ 591e6889620STrond Myklebust decode_lookup_maxsz + \ 5921da177e4SLinus Torvalds decode_getattr_maxsz + \ 5931da177e4SLinus Torvalds decode_getfh_maxsz) 5941da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 5959b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5961da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 5971da177e4SLinus Torvalds encode_getattr_maxsz + \ 5981da177e4SLinus Torvalds encode_getfh_maxsz) 5991da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6009b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6011da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6021da177e4SLinus Torvalds decode_getattr_maxsz + \ 6031da177e4SLinus Torvalds decode_getfh_maxsz) 6041da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6059b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6061da177e4SLinus Torvalds encode_putfh_maxsz + \ 607778d2817STrond Myklebust encode_remove_maxsz) 6081da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6099b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6101da177e4SLinus Torvalds decode_putfh_maxsz + \ 611778d2817STrond Myklebust decode_remove_maxsz) 6121da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6139b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6141da177e4SLinus Torvalds encode_putfh_maxsz + \ 6151da177e4SLinus Torvalds encode_savefh_maxsz + \ 6161da177e4SLinus Torvalds encode_putfh_maxsz + \ 617778d2817STrond Myklebust encode_rename_maxsz) 6181da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6199b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6201da177e4SLinus Torvalds decode_putfh_maxsz + \ 6211da177e4SLinus Torvalds decode_savefh_maxsz + \ 6221da177e4SLinus Torvalds decode_putfh_maxsz + \ 623778d2817STrond Myklebust decode_rename_maxsz) 6241da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6259b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6261da177e4SLinus Torvalds encode_putfh_maxsz + \ 6271da177e4SLinus Torvalds encode_savefh_maxsz + \ 6281da177e4SLinus Torvalds encode_putfh_maxsz + \ 62991ba2eeeSTrond Myklebust encode_link_maxsz + \ 63091ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 631a9f6991bSTrond Myklebust encode_getattr_maxsz) 6321da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6339b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6341da177e4SLinus Torvalds decode_putfh_maxsz + \ 6351da177e4SLinus Torvalds decode_savefh_maxsz + \ 6361da177e4SLinus Torvalds decode_putfh_maxsz + \ 63791ba2eeeSTrond Myklebust decode_link_maxsz + \ 63891ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 63991ba2eeeSTrond Myklebust decode_getattr_maxsz) 6401da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6419b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6421da177e4SLinus Torvalds encode_putfh_maxsz + \ 6431da177e4SLinus Torvalds encode_symlink_maxsz + \ 6441da177e4SLinus Torvalds encode_getattr_maxsz + \ 6451da177e4SLinus Torvalds encode_getfh_maxsz) 6461da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6479b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6481da177e4SLinus Torvalds decode_putfh_maxsz + \ 6491da177e4SLinus Torvalds decode_symlink_maxsz + \ 6501da177e4SLinus Torvalds decode_getattr_maxsz + \ 6511da177e4SLinus Torvalds decode_getfh_maxsz) 6521da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6539b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6541da177e4SLinus Torvalds encode_putfh_maxsz + \ 6551da177e4SLinus Torvalds encode_create_maxsz + \ 65656ae19f3STrond Myklebust encode_getfh_maxsz + \ 65756ae19f3STrond Myklebust encode_getattr_maxsz) 6581da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 6599b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6601da177e4SLinus Torvalds decode_putfh_maxsz + \ 6611da177e4SLinus Torvalds decode_create_maxsz + \ 66256ae19f3STrond Myklebust decode_getfh_maxsz + \ 66356ae19f3STrond Myklebust decode_getattr_maxsz) 6641da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 6659b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6661da177e4SLinus Torvalds encode_putfh_maxsz + \ 6671da177e4SLinus Torvalds encode_getattr_maxsz) 6681da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 6699b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6701da177e4SLinus Torvalds decode_putfh_maxsz + \ 6711da177e4SLinus Torvalds decode_getattr_maxsz) 6721da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 6739b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6741da177e4SLinus Torvalds encode_putfh_maxsz + \ 6759104a55dSTrond Myklebust encode_statfs_maxsz) 6761da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 6779b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6781da177e4SLinus Torvalds decode_putfh_maxsz + \ 6799104a55dSTrond Myklebust decode_statfs_maxsz) 6801da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 6819b7b9fccSAndy Adamson encode_sequence_maxsz + \ 682ab91f264STrond Myklebust encode_putfh_maxsz + \ 6831da177e4SLinus Torvalds encode_getattr_maxsz) 6841da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 6859b7b9fccSAndy Adamson decode_sequence_maxsz + \ 686ab91f264STrond Myklebust decode_putfh_maxsz + \ 6871da177e4SLinus Torvalds decode_getattr_maxsz) 6881da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 6899b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6901da177e4SLinus Torvalds encode_putfh_maxsz + \ 691fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 692fa178f29STrond Myklebust encode_getattr_maxsz) 6931da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 6949b7b9fccSAndy Adamson decode_sequence_maxsz + \ 695fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 696fa178f29STrond Myklebust decode_getattr_maxsz) 697029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 6989b7b9fccSAndy Adamson encode_sequence_maxsz + \ 699029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7009104a55dSTrond Myklebust encode_getacl_maxsz) 701029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7029b7b9fccSAndy Adamson decode_sequence_maxsz + \ 703029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7049104a55dSTrond Myklebust decode_getacl_maxsz) 70523ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7069b7b9fccSAndy Adamson encode_sequence_maxsz + \ 70723ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7089104a55dSTrond Myklebust encode_setacl_maxsz) 70923ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7109b7b9fccSAndy Adamson decode_sequence_maxsz + \ 71123ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7129104a55dSTrond Myklebust decode_setacl_maxsz) 713683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 714683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7159b7b9fccSAndy Adamson encode_sequence_maxsz + \ 716683b57b4STrond Myklebust encode_putfh_maxsz + \ 717e6889620STrond Myklebust encode_lookup_maxsz + \ 718e6889620STrond Myklebust encode_fs_locations_maxsz) 719683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 720683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7219b7b9fccSAndy Adamson decode_sequence_maxsz + \ 722683b57b4STrond Myklebust decode_putfh_maxsz + \ 723e6889620STrond Myklebust decode_lookup_maxsz + \ 724e6889620STrond Myklebust decode_fs_locations_maxsz) 7255a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7265a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7275a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7285a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7295a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7305a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7315a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7325a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 73399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 7347c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 7357c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 7367c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 7377c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 7387c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 7397c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 74099fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 74199fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 74299fe60d0SBenny Halevy encode_exchange_id_maxsz) 74399fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 74499fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 74599fe60d0SBenny Halevy decode_exchange_id_maxsz) 746fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 747fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 748fc931582SAndy Adamson encode_create_session_maxsz) 749fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 750fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 751fc931582SAndy Adamson decode_create_session_maxsz) 7520f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 7530f3e66c6SAndy Adamson encode_destroy_session_maxsz) 7540f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 7550f3e66c6SAndy Adamson decode_destroy_session_maxsz) 75666245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 75766245539STrond Myklebust encode_destroy_clientid_maxsz) 75866245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 75966245539STrond Myklebust decode_destroy_clientid_maxsz) 760fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 761fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 762fc01cea9SAndy Adamson encode_sequence_maxsz) 763fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 764fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 765fc01cea9SAndy Adamson decode_sequence_maxsz) 7662050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 7672050f0ccSAndy Adamson encode_sequence_maxsz + \ 7682050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 7692050f0ccSAndy Adamson encode_fsinfo_maxsz) 7702050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 7712050f0ccSAndy Adamson decode_sequence_maxsz + \ 7722050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 7732050f0ccSAndy Adamson decode_fsinfo_maxsz) 77418019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 77518019753SRicardo Labiaga encode_sequence_maxsz + \ 77618019753SRicardo Labiaga encode_reclaim_complete_maxsz) 77718019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 77818019753SRicardo Labiaga decode_sequence_maxsz + \ 77918019753SRicardo Labiaga decode_reclaim_complete_maxsz) 7807f11d8d3SAndy Adamson #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \ 7817f11d8d3SAndy Adamson encode_sequence_maxsz + \ 7827f11d8d3SAndy Adamson encode_putfh_maxsz + \ 7837f11d8d3SAndy Adamson encode_getdevicelist_maxsz) 7847f11d8d3SAndy Adamson #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \ 7857f11d8d3SAndy Adamson decode_sequence_maxsz + \ 7867f11d8d3SAndy Adamson decode_putfh_maxsz + \ 7877f11d8d3SAndy Adamson decode_getdevicelist_maxsz) 788b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 789b1f69b75SAndy Adamson encode_sequence_maxsz +\ 790b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 791b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 792b1f69b75SAndy Adamson decode_sequence_maxsz + \ 793b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 794b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 795b1f69b75SAndy Adamson encode_sequence_maxsz + \ 796b1f69b75SAndy Adamson encode_putfh_maxsz + \ 797b1f69b75SAndy Adamson encode_layoutget_maxsz) 798b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 799b1f69b75SAndy Adamson decode_sequence_maxsz + \ 800b1f69b75SAndy Adamson decode_putfh_maxsz + \ 801b1f69b75SAndy Adamson decode_layoutget_maxsz) 802863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 803863a3c6cSAndy Adamson encode_sequence_maxsz +\ 804863a3c6cSAndy Adamson encode_putfh_maxsz + \ 805863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 806863a3c6cSAndy Adamson encode_getattr_maxsz) 807863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 808863a3c6cSAndy Adamson decode_sequence_maxsz + \ 809863a3c6cSAndy Adamson decode_putfh_maxsz + \ 810863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 811863a3c6cSAndy Adamson decode_getattr_maxsz) 812cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 813cbe82603SBenny Halevy encode_sequence_maxsz + \ 814cbe82603SBenny Halevy encode_putfh_maxsz + \ 815cbe82603SBenny Halevy encode_layoutreturn_maxsz) 816cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 817cbe82603SBenny Halevy decode_sequence_maxsz + \ 818cbe82603SBenny Halevy decode_putfh_maxsz + \ 819cbe82603SBenny Halevy decode_layoutreturn_maxsz) 820fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 821fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 822fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 823fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 824fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 825fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 826fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 827fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8287d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8297d974794SBryan Schumaker encode_sequence_maxsz + \ 8307d974794SBryan Schumaker encode_test_stateid_maxsz) 8317d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8327d974794SBryan Schumaker decode_sequence_maxsz + \ 8337d974794SBryan Schumaker decode_test_stateid_maxsz) 8349aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8359aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8369aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8379aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8389aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8399aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8402449ea2eSAlexandros Batsakis 8412449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8422449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8432449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8442449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8452449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8462449ea2eSAlexandros Batsakis XDR_UNIT); 8472449ea2eSAlexandros Batsakis 8482449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8492449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 8502449ea2eSAlexandros Batsakis decode_sequence_maxsz + 8512449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 8522449ea2eSAlexandros Batsakis XDR_UNIT); 85399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 8541da177e4SLinus Torvalds 855bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 856bca79478STrond Myklebust [NF4BAD] = 0, 857bca79478STrond Myklebust [NF4REG] = S_IFREG, 858bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 859bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 860bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 861bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 862bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 863bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 864bca79478STrond Myklebust [NF4ATTRDIR] = 0, 865bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 8661da177e4SLinus Torvalds }; 8671da177e4SLinus Torvalds 8681da177e4SLinus Torvalds struct compound_hdr { 8691da177e4SLinus Torvalds int32_t status; 8701da177e4SLinus Torvalds uint32_t nops; 871d017931cSAndy Adamson __be32 * nops_p; 8721da177e4SLinus Torvalds uint32_t taglen; 8731da177e4SLinus Torvalds char * tag; 8740c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 87566cc0429SBenny Halevy u32 minorversion; 8761da177e4SLinus Torvalds }; 8771da177e4SLinus Torvalds 87813c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 87913c65ce9SBenny Halevy { 88013c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 88113c65ce9SBenny Halevy BUG_ON(!p); 88213c65ce9SBenny Halevy return p; 88313c65ce9SBenny Halevy } 8841da177e4SLinus Torvalds 885cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 886cb17e556STrond Myklebust { 887cb17e556STrond Myklebust __be32 *p; 888cb17e556STrond Myklebust 889cb17e556STrond Myklebust p = xdr_reserve_space(xdr, len); 890cb17e556STrond Myklebust xdr_encode_opaque_fixed(p, buf, len); 891cb17e556STrond Myklebust } 892cb17e556STrond Myklebust 8931da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 8941da177e4SLinus Torvalds { 8958687b63aSAl Viro __be32 *p; 8961da177e4SLinus Torvalds 8976fdfb0bcSTrond Myklebust p = reserve_space(xdr, 4 + len); 8981da177e4SLinus Torvalds xdr_encode_opaque(p, str, len); 8991da177e4SLinus Torvalds } 9001da177e4SLinus Torvalds 9014ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9024ade9821STrond Myklebust { 9034ade9821STrond Myklebust __be32 *p; 9044ade9821STrond Myklebust 9054ade9821STrond Myklebust p = reserve_space(xdr, 4); 9064ade9821STrond Myklebust *p = cpu_to_be32(n); 9074ade9821STrond Myklebust } 9084ade9821STrond Myklebust 909ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 910ff2eb681STrond Myklebust { 911ff2eb681STrond Myklebust __be32 *p; 912ff2eb681STrond Myklebust 913ff2eb681STrond Myklebust p = reserve_space(xdr, 8); 914ff2eb681STrond Myklebust xdr_encode_hyper(p, n); 915ff2eb681STrond Myklebust } 916ff2eb681STrond Myklebust 9174ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9184ade9821STrond Myklebust const struct nfs_seqid *seqid) 9194ade9821STrond Myklebust { 9204ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 9214ade9821STrond Myklebust } 9224ade9821STrond Myklebust 9230c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9240c4e8c18SBenny Halevy struct rpc_rqst *req, 9250c4e8c18SBenny Halevy struct compound_hdr *hdr) 9261da177e4SLinus Torvalds { 9278687b63aSAl Viro __be32 *p; 928a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9290c4e8c18SBenny Halevy 9300c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9310c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9320c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9330c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9341da177e4SLinus Torvalds 9351da177e4SLinus Torvalds BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 9366fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9376fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 938e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 939d017931cSAndy Adamson hdr->nops_p = p; 94034558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 941d017931cSAndy Adamson } 942d017931cSAndy Adamson 943ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 944ab19b481STrond Myklebust uint32_t replen, 945ab19b481STrond Myklebust struct compound_hdr *hdr) 946ab19b481STrond Myklebust { 947ab19b481STrond Myklebust encode_uint32(xdr, op); 948ab19b481STrond Myklebust hdr->nops++; 949ab19b481STrond Myklebust hdr->replen += replen; 950ab19b481STrond Myklebust } 951ab19b481STrond Myklebust 952d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 953d017931cSAndy Adamson { 954fc931582SAndy Adamson BUG_ON(hdr->nops > NFS4_MAX_OPS); 955d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 9561da177e4SLinus Torvalds } 9571da177e4SLinus Torvalds 958ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 959ea9d23f5STrond Myklebust { 9602d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 961ea9d23f5STrond Myklebust } 962ea9d23f5STrond Myklebust 9631da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 9641da177e4SLinus Torvalds { 965cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 9661da177e4SLinus Torvalds } 9671da177e4SLinus Torvalds 968cf8cdbe5SAndy Adamson static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) 9691da177e4SLinus Torvalds { 9701da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 9711da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 9721da177e4SLinus Torvalds int owner_namelen = 0; 9731da177e4SLinus Torvalds int owner_grouplen = 0; 9748687b63aSAl Viro __be32 *p; 9758687b63aSAl Viro __be32 *q; 9761da177e4SLinus Torvalds int len; 9771da177e4SLinus Torvalds uint32_t bmval0 = 0; 9781da177e4SLinus Torvalds uint32_t bmval1 = 0; 9791da177e4SLinus Torvalds 9801da177e4SLinus Torvalds /* 9811da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 9821da177e4SLinus Torvalds * In the worst-case, this would be 9831da177e4SLinus Torvalds * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 9841da177e4SLinus Torvalds * = 36 bytes, plus any contribution from variable-length fields 98523ec6965SJ. Bruce Fields * such as owner/group. 9861da177e4SLinus Torvalds */ 9871da177e4SLinus Torvalds len = 16; 9881da177e4SLinus Torvalds 9891da177e4SLinus Torvalds /* Sigh */ 9901da177e4SLinus Torvalds if (iap->ia_valid & ATTR_SIZE) 9911da177e4SLinus Torvalds len += 8; 9921da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MODE) 9931da177e4SLinus Torvalds len += 4; 9941da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 995e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 9961da177e4SLinus Torvalds if (owner_namelen < 0) { 997fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 9981da177e4SLinus Torvalds iap->ia_uid); 9991da177e4SLinus Torvalds /* XXX */ 10001da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10011da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10021da177e4SLinus Torvalds /* goto out; */ 10031da177e4SLinus Torvalds } 10041da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10051da177e4SLinus Torvalds } 10061da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 1007e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10081da177e4SLinus Torvalds if (owner_grouplen < 0) { 1009fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 10101da177e4SLinus Torvalds iap->ia_gid); 10111da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10121da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10131da177e4SLinus Torvalds /* goto out; */ 10141da177e4SLinus Torvalds } 10151da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10161da177e4SLinus Torvalds } 10171da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) 10181da177e4SLinus Torvalds len += 16; 10191da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_ATIME) 10201da177e4SLinus Torvalds len += 4; 10211da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) 10221da177e4SLinus Torvalds len += 16; 10231da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_MTIME) 10241da177e4SLinus Torvalds len += 4; 102513c65ce9SBenny Halevy p = reserve_space(xdr, len); 10261da177e4SLinus Torvalds 10271da177e4SLinus Torvalds /* 10281da177e4SLinus Torvalds * We write the bitmap length now, but leave the bitmap and the attribute 10291da177e4SLinus Torvalds * buffer length to be backfilled at the end of this routine. 10301da177e4SLinus Torvalds */ 1031e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 10321da177e4SLinus Torvalds q = p; 10331da177e4SLinus Torvalds p += 3; 10341da177e4SLinus Torvalds 10351da177e4SLinus Torvalds if (iap->ia_valid & ATTR_SIZE) { 10361da177e4SLinus Torvalds bmval0 |= FATTR4_WORD0_SIZE; 1037b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 10381da177e4SLinus Torvalds } 10391da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MODE) { 10401da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_MODE; 1041e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 10421da177e4SLinus Torvalds } 10431da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 10441da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_OWNER; 1045811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 10461da177e4SLinus Torvalds } 10471da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 10481da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_OWNER_GROUP; 1049811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 10501da177e4SLinus Torvalds } 10511da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 10521da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 1053e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1054e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 1055d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_sec); 1056d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 10571da177e4SLinus Torvalds } 10581da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_ATIME) { 10591da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 1060e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 10611da177e4SLinus Torvalds } 10621da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 10631da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 1064e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1065e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 1066e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_sec); 1067e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 10681da177e4SLinus Torvalds } 10691da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_MTIME) { 10701da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 1071e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 10721da177e4SLinus Torvalds } 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds /* 10751da177e4SLinus Torvalds * Now we backfill the bitmap and the attribute buffer length. 10761da177e4SLinus Torvalds */ 10771da177e4SLinus Torvalds if (len != ((char *)p - (char *)q) + 4) { 1078f9fd2d9cSWeston Andros Adamson printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n", 10791da177e4SLinus Torvalds len, ((char *)p - (char *)q) + 4); 10801da177e4SLinus Torvalds BUG(); 10811da177e4SLinus Torvalds } 10821da177e4SLinus Torvalds len = (char *)p - (char *)q - 12; 10831da177e4SLinus Torvalds *q++ = htonl(bmval0); 10841da177e4SLinus Torvalds *q++ = htonl(bmval1); 108534558513SBenny Halevy *q = htonl(len); 10861da177e4SLinus Torvalds 10871da177e4SLinus Torvalds /* out: */ 10881da177e4SLinus Torvalds } 10891da177e4SLinus Torvalds 1090cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 10911da177e4SLinus Torvalds { 1092475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1093475d4ba0STrond Myklebust encode_uint32(xdr, access); 10941da177e4SLinus Torvalds } 10951da177e4SLinus Torvalds 1096cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 10971da177e4SLinus Torvalds { 1098ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 10994ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1100ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 11011da177e4SLinus Torvalds } 11021da177e4SLinus Torvalds 11030b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11041da177e4SLinus Torvalds { 11058687b63aSAl Viro __be32 *p; 11061da177e4SLinus Torvalds 1107475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1108475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1109b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 111034558513SBenny Halevy *p = cpu_to_be32(args->count); 11111da177e4SLinus Torvalds } 11121da177e4SLinus Torvalds 1113cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11141da177e4SLinus Torvalds { 11158687b63aSAl Viro __be32 *p; 11161da177e4SLinus Torvalds 1117475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1118475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11191da177e4SLinus Torvalds 11201da177e4SLinus Torvalds switch (create->ftype) { 11211da177e4SLinus Torvalds case NF4LNK: 112213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 112334558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 112494a6d753SChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 11251da177e4SLinus Torvalds break; 11261da177e4SLinus Torvalds 11271da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 112813c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1129e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 113034558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11311da177e4SLinus Torvalds break; 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds default: 11341da177e4SLinus Torvalds break; 11351da177e4SLinus Torvalds } 11361da177e4SLinus Torvalds 1137811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 1138cf8cdbe5SAndy Adamson encode_attrs(xdr, create->attrs, create->server); 11391da177e4SLinus Torvalds } 11401da177e4SLinus Torvalds 1141cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11421da177e4SLinus Torvalds { 11438687b63aSAl Viro __be32 *p; 11441da177e4SLinus Torvalds 1145475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1146475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1147e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 114834558513SBenny Halevy *p = cpu_to_be32(bitmap); 11491da177e4SLinus Torvalds } 11501da177e4SLinus Torvalds 1151cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 11521da177e4SLinus Torvalds { 11538687b63aSAl Viro __be32 *p; 11541da177e4SLinus Torvalds 1155475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1156475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1157e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1158e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 115934558513SBenny Halevy *p = cpu_to_be32(bm1); 11601da177e4SLinus Torvalds } 11611da177e4SLinus Torvalds 1162dae100c2SFred Isaman static void 1163dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1164dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1165dae100c2SFred Isaman struct compound_hdr *hdr) 1166dae100c2SFred Isaman { 1167dae100c2SFred Isaman __be32 *p; 1168dae100c2SFred Isaman 1169ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1170dae100c2SFred Isaman if (bm2) { 1171dae100c2SFred Isaman p = reserve_space(xdr, 16); 1172dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1173dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1174dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1175dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1176dae100c2SFred Isaman } else if (bm1) { 1177dae100c2SFred Isaman p = reserve_space(xdr, 12); 1178dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1179dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1180dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1181dae100c2SFred Isaman } else { 1182dae100c2SFred Isaman p = reserve_space(xdr, 8); 1183dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1184dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1185dae100c2SFred Isaman } 1186dae100c2SFred Isaman } 1187dae100c2SFred Isaman 1188cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 11891da177e4SLinus Torvalds { 1190cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1191d017931cSAndy Adamson bitmask[1] & nfs4_fattr_bitmap[1], hdr); 11921da177e4SLinus Torvalds } 11931da177e4SLinus Torvalds 119488034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 11951549210fSTrond Myklebust const u32 *open_bitmap, 119688034c3dSAndy Adamson struct compound_hdr *hdr) 119788034c3dSAndy Adamson { 119888034c3dSAndy Adamson encode_getattr_three(xdr, 11991549210fSTrond Myklebust bitmask[0] & open_bitmap[0], 12001549210fSTrond Myklebust bitmask[1] & open_bitmap[1], 12011549210fSTrond Myklebust bitmask[2] & open_bitmap[2], 120288034c3dSAndy Adamson hdr); 120388034c3dSAndy Adamson } 120488034c3dSAndy Adamson 1205cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12061da177e4SLinus Torvalds { 1207dae100c2SFred Isaman encode_getattr_three(xdr, 1208dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1209dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1210dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1211dae100c2SFred Isaman hdr); 12121da177e4SLinus Torvalds } 12131da177e4SLinus Torvalds 1214cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1215830b8e33SManoj Naik { 1216cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1217cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1218830b8e33SManoj Naik } 1219830b8e33SManoj Naik 1220cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12211da177e4SLinus Torvalds { 1222ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12231da177e4SLinus Torvalds } 12241da177e4SLinus Torvalds 1225cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12261da177e4SLinus Torvalds { 1227ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12286fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12291da177e4SLinus Torvalds } 12301da177e4SLinus Torvalds 1231911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1232911d1aafSTrond Myklebust { 1233f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1234911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1235911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1236911d1aafSTrond Myklebust } 1237911d1aafSTrond Myklebust 1238911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1239911d1aafSTrond Myklebust { 1240911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1241911d1aafSTrond Myklebust return ~(uint64_t)0; 1242911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1243911d1aafSTrond Myklebust } 1244911d1aafSTrond Myklebust 1245daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1246daccbdedSTrond Myklebust { 1247daccbdedSTrond Myklebust __be32 *p; 1248daccbdedSTrond Myklebust 1249d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1250daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1251d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1252daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1253d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1254daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1255daccbdedSTrond Myklebust } 1256daccbdedSTrond Myklebust 12571da177e4SLinus Torvalds /* 12581da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 12591da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 12601da177e4SLinus Torvalds */ 1261cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 12621da177e4SLinus Torvalds { 12638687b63aSAl Viro __be32 *p; 12641da177e4SLinus Torvalds 1265475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1266475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1267e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1268e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1269b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1270b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 127134558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1272911d1aafSTrond Myklebust if (args->new_lock_owner){ 12734ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1274ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->open_stateid); 12754ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1276daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12771da177e4SLinus Torvalds } 12781da177e4SLinus Torvalds else { 1279ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->lock_stateid); 12804ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 12811da177e4SLinus Torvalds } 12821da177e4SLinus Torvalds } 12831da177e4SLinus Torvalds 1284cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 12851da177e4SLinus Torvalds { 12868687b63aSAl Viro __be32 *p; 12871da177e4SLinus Torvalds 1288475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1289475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1290e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1291b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1292b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1293daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12941da177e4SLinus Torvalds } 12951da177e4SLinus Torvalds 1296cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 12971da177e4SLinus Torvalds { 12988687b63aSAl Viro __be32 *p; 12991da177e4SLinus Torvalds 1300475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1301475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13024ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1303ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 1304ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1305b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 130634558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13071da177e4SLinus Torvalds } 13081da177e4SLinus Torvalds 1309d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1310d3c7b7ccSTrond Myklebust { 1311ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1312d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1313d3c7b7ccSTrond Myklebust } 1314d3c7b7ccSTrond Myklebust 1315cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13161da177e4SLinus Torvalds { 1317ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13186fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13191da177e4SLinus Torvalds } 13201da177e4SLinus Torvalds 1321dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 13221da177e4SLinus Torvalds { 13238687b63aSAl Viro __be32 *p; 13241da177e4SLinus Torvalds 132513c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1326dc0b027dSTrond Myklebust switch (fmode & (FMODE_READ|FMODE_WRITE)) { 13271da177e4SLinus Torvalds case FMODE_READ: 1328e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 13291da177e4SLinus Torvalds break; 13301da177e4SLinus Torvalds case FMODE_WRITE: 1331e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 13321da177e4SLinus Torvalds break; 13331da177e4SLinus Torvalds case FMODE_READ|FMODE_WRITE: 1334e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 13351da177e4SLinus Torvalds break; 13361da177e4SLinus Torvalds default: 1337e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 13381da177e4SLinus Torvalds } 133934558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13401da177e4SLinus Torvalds } 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13431da177e4SLinus Torvalds { 13448687b63aSAl Viro __be32 *p; 13451da177e4SLinus Torvalds /* 13461da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13471da177e4SLinus Torvalds * owner 4 = 32 13481da177e4SLinus Torvalds */ 13494ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1350dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 135195b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1352b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 135395b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 135493f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1355d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 135695b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 135795b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 13581da177e4SLinus Torvalds } 13591da177e4SLinus Torvalds 13601da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13611da177e4SLinus Torvalds { 13628687b63aSAl Viro __be32 *p; 13634882ef72SAlexandros Batsakis struct nfs_client *clp; 13641da177e4SLinus Torvalds 136513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13661da177e4SLinus Torvalds switch(arg->open_flags & O_EXCL) { 13671da177e4SLinus Torvalds case 0: 136834558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 13691da177e4SLinus Torvalds encode_attrs(xdr, arg->u.attrs, arg->server); 13701da177e4SLinus Torvalds break; 13711da177e4SLinus Torvalds default: 13724882ef72SAlexandros Batsakis clp = arg->server->nfs_client; 1373a4432345STrond Myklebust if (clp->cl_mvops->minor_version > 0) { 13744882ef72SAlexandros Batsakis if (nfs4_has_persistent_session(clp)) { 13754882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 13764882ef72SAlexandros Batsakis encode_attrs(xdr, arg->u.attrs, arg->server); 13774882ef72SAlexandros Batsakis } else { 13784882ef72SAlexandros Batsakis struct iattr dummy; 13794882ef72SAlexandros Batsakis 13804882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 13814882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 13824882ef72SAlexandros Batsakis dummy.ia_valid = 0; 13834882ef72SAlexandros Batsakis encode_attrs(xdr, &dummy, arg->server); 13844882ef72SAlexandros Batsakis } 13854882ef72SAlexandros Batsakis } else { 138634558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 13871da177e4SLinus Torvalds encode_nfs4_verifier(xdr, &arg->u.verifier); 13881da177e4SLinus Torvalds } 13891da177e4SLinus Torvalds } 13904882ef72SAlexandros Batsakis } 13911da177e4SLinus Torvalds 13921da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13931da177e4SLinus Torvalds { 13948687b63aSAl Viro __be32 *p; 13951da177e4SLinus Torvalds 139613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13971da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 13981da177e4SLinus Torvalds case 0: 139934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14001da177e4SLinus Torvalds break; 14011da177e4SLinus Torvalds default: 14021da177e4SLinus Torvalds BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 140334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14041da177e4SLinus Torvalds encode_createmode(xdr, arg); 14051da177e4SLinus Torvalds } 14061da177e4SLinus Torvalds } 14071da177e4SLinus Torvalds 1408bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14091da177e4SLinus Torvalds { 14108687b63aSAl Viro __be32 *p; 14111da177e4SLinus Torvalds 141213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14131da177e4SLinus Torvalds switch (delegation_type) { 14141da177e4SLinus Torvalds case 0: 141534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14161da177e4SLinus Torvalds break; 14171da177e4SLinus Torvalds case FMODE_READ: 141834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14191da177e4SLinus Torvalds break; 14201da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 142134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14221da177e4SLinus Torvalds break; 14231da177e4SLinus Torvalds default: 14241da177e4SLinus Torvalds BUG(); 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds } 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14291da177e4SLinus Torvalds { 14308687b63aSAl Viro __be32 *p; 14311da177e4SLinus Torvalds 143213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 143334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14341da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14351da177e4SLinus Torvalds } 14361da177e4SLinus Torvalds 1437bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14381da177e4SLinus Torvalds { 14398687b63aSAl Viro __be32 *p; 14401da177e4SLinus Torvalds 144113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 144234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14431da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14441da177e4SLinus Torvalds } 14451da177e4SLinus Torvalds 14461da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14471da177e4SLinus Torvalds { 14488687b63aSAl Viro __be32 *p; 14491da177e4SLinus Torvalds 1450ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1451ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1452ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14531da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14541da177e4SLinus Torvalds } 14551da177e4SLinus Torvalds 1456cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 14571da177e4SLinus Torvalds { 1458ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 14591da177e4SLinus Torvalds encode_openhdr(xdr, arg); 14601da177e4SLinus Torvalds encode_opentype(xdr, arg); 14611da177e4SLinus Torvalds switch (arg->claim) { 14621da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 14631da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 14641da177e4SLinus Torvalds break; 14651da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 14661da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 14671da177e4SLinus Torvalds break; 14681da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 14691da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 14701da177e4SLinus Torvalds break; 14711da177e4SLinus Torvalds default: 14721da177e4SLinus Torvalds BUG(); 14731da177e4SLinus Torvalds } 14741da177e4SLinus Torvalds } 14751da177e4SLinus Torvalds 1476cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 14771da177e4SLinus Torvalds { 1478ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1479ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14804ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14811da177e4SLinus Torvalds } 14821da177e4SLinus Torvalds 1483cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 14841da177e4SLinus Torvalds { 1485ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1486ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14874ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1488dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 14891da177e4SLinus Torvalds } 14901da177e4SLinus Torvalds 1491cf8cdbe5SAndy Adamson static void 1492d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 14931da177e4SLinus Torvalds { 1494ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 14956fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 14961da177e4SLinus Torvalds } 14971da177e4SLinus Torvalds 1498cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 14991da177e4SLinus Torvalds { 1500ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15011da177e4SLinus Torvalds } 15021da177e4SLinus Torvalds 15034fc8796dSTrond Myklebust static void encode_open_stateid(struct xdr_stream *xdr, 15044fc8796dSTrond Myklebust const struct nfs_open_context *ctx, 15054fc8796dSTrond Myklebust const struct nfs_lock_context *l_ctx, 15064fc8796dSTrond Myklebust fmode_t fmode, 15074fc8796dSTrond Myklebust int zero_seqid) 15081da177e4SLinus Torvalds { 15091da177e4SLinus Torvalds nfs4_stateid stateid; 15101da177e4SLinus Torvalds 15111da177e4SLinus Torvalds if (ctx->state != NULL) { 15124fc8796dSTrond Myklebust nfs4_select_rw_stateid(&stateid, ctx->state, 15134fc8796dSTrond Myklebust fmode, l_ctx->lockowner, l_ctx->pid); 151489d1ea65SAndy Adamson if (zero_seqid) 15152d2f24adSTrond Myklebust stateid.seqid = 0; 1516ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &stateid); 15171da177e4SLinus Torvalds } else 1518ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 15191da177e4SLinus Torvalds } 15201da177e4SLinus Torvalds 1521cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 15221da177e4SLinus Torvalds { 15238687b63aSAl Viro __be32 *p; 15241da177e4SLinus Torvalds 1525ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 1526d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 15274fc8796dSTrond Myklebust FMODE_READ, hdr->minorversion); 15281da177e4SLinus Torvalds 152913c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1530b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 153134558513SBenny Halevy *p = cpu_to_be32(args->count); 15321da177e4SLinus Torvalds } 15331da177e4SLinus Torvalds 1534cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15351da177e4SLinus Torvalds { 153628331a46STrond Myklebust uint32_t attrs[2] = { 153728331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 153828331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 153928331a46STrond Myklebust }; 15406f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1541cd93710eSChuck Lever __be32 *p, verf[2]; 15421da177e4SLinus Torvalds 154382f2e547SBryan Schumaker if (readdir->plus) { 154482f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 154528331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 154682f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 154782f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 154882f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 154982f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 15506f7a35bdSTrond Myklebust dircount >>= 1; 155182f2e547SBryan Schumaker } 155228331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 155328331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 155428331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 15556f7a35bdSTrond Myklebust 1556475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1557ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1558cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1559cd93710eSChuck Lever p = reserve_space(xdr, 20); 15606f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 15616f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 15626f7a35bdSTrond Myklebust *p++ = cpu_to_be32(2); 156382f2e547SBryan Schumaker 1564e75bc1c8SBenny Halevy *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 156534558513SBenny Halevy *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1566cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 156744109241SFred Isaman dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 156844109241SFred Isaman __func__, 1569eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1570cd93710eSChuck Lever verf[0], verf[1], 1571eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1572eadf4598STrond Myklebust attrs[1] & readdir->bitmask[1]); 15731da177e4SLinus Torvalds } 15741da177e4SLinus Torvalds 1575cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 15761da177e4SLinus Torvalds { 1577ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 15781da177e4SLinus Torvalds } 15791da177e4SLinus Torvalds 1580cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 15811da177e4SLinus Torvalds { 1582ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 15836fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 15841da177e4SLinus Torvalds } 15851da177e4SLinus Torvalds 1586cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 15871da177e4SLinus Torvalds { 1588ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1589811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1590811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 15911da177e4SLinus Torvalds } 15921da177e4SLinus Torvalds 1593bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1594bb4dae5eSChuck Lever struct compound_hdr *hdr) 15951da177e4SLinus Torvalds { 1596475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1597ff2eb681STrond Myklebust encode_uint64(xdr, clid); 15981da177e4SLinus Torvalds } 15991da177e4SLinus Torvalds 1600cf8cdbe5SAndy Adamson static void 1601d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 160256ae19f3STrond Myklebust { 1603ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 160456ae19f3STrond Myklebust } 160556ae19f3STrond Myklebust 16069f06c719SChuck Lever static void 1607d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 160823ec6965SJ. Bruce Fields { 16098687b63aSAl Viro __be32 *p; 161023ec6965SJ. Bruce Fields 1611ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1612ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 161313c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1614e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 161534558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 16169f06c719SChuck Lever BUG_ON(arg->acl_len % 4); 161713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 161834558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 161923ec6965SJ. Bruce Fields xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 162023ec6965SJ. Bruce Fields } 162123ec6965SJ. Bruce Fields 1622cf8cdbe5SAndy Adamson static void 1623d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16241da177e4SLinus Torvalds { 1625ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16261da177e4SLinus Torvalds } 16271da177e4SLinus Torvalds 1628cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16291da177e4SLinus Torvalds { 1630ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1631ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1632cf8cdbe5SAndy Adamson encode_attrs(xdr, arg->iap, server); 16331da177e4SLinus Torvalds } 16341da177e4SLinus Torvalds 1635cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16361da177e4SLinus Torvalds { 16378687b63aSAl Viro __be32 *p; 16381da177e4SLinus Torvalds 163970019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1640cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16411da177e4SLinus Torvalds 16421da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 164313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 164434558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16451da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16461da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 164713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 164834558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_cb_ident); 16491da177e4SLinus Torvalds } 16501da177e4SLinus Torvalds 1651bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16521da177e4SLinus Torvalds { 1653475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1654475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1655ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1656cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 16571da177e4SLinus Torvalds } 16581da177e4SLinus Torvalds 1659cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 16601da177e4SLinus Torvalds { 16618687b63aSAl Viro __be32 *p; 16621da177e4SLinus Torvalds 1663ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 1664d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 16654fc8796dSTrond Myklebust FMODE_WRITE, hdr->minorversion); 16661da177e4SLinus Torvalds 166713c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1668b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1669e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 167034558513SBenny Halevy *p = cpu_to_be32(args->count); 16711da177e4SLinus Torvalds 16721da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 16731da177e4SLinus Torvalds } 16741da177e4SLinus Torvalds 1675cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 16761da177e4SLinus Torvalds { 1677ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1678ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 16791da177e4SLinus Torvalds } 16809b7b9fccSAndy Adamson 16815a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16825a5ea0d4SBryan Schumaker { 1683ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 16846fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16855a5ea0d4SBryan Schumaker } 16865a5ea0d4SBryan Schumaker 168799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 16889b7b9fccSAndy Adamson /* NFSv4.1 operations */ 16897c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 16907c44f1aeSWeston Andros Adamson struct nfs4_session *session, 16917c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 16927c44f1aeSWeston Andros Adamson { 16937c44f1aeSWeston Andros Adamson __be32 *p; 16947c44f1aeSWeston Andros Adamson 16957c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 16967c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 16977c44f1aeSWeston Andros Adamson encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 16987c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 16997c44f1aeSWeston Andros Adamson *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH); 17007c44f1aeSWeston Andros Adamson *p = 0; /* use_conn_in_rdma_mode = False */ 17017c44f1aeSWeston Andros Adamson } 17027c44f1aeSWeston Andros Adamson 170399fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 170499fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 170599fe60d0SBenny Halevy struct compound_hdr *hdr) 170699fe60d0SBenny Halevy { 170799fe60d0SBenny Halevy __be32 *p; 1708db8ac8baSWeston Andros Adamson char impl_name[NFS4_OPAQUE_LIMIT]; 1709db8ac8baSWeston Andros Adamson int len = 0; 171099fe60d0SBenny Halevy 171170019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1712cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 171399fe60d0SBenny Halevy 171499fe60d0SBenny Halevy encode_string(xdr, args->id_len, args->id); 171599fe60d0SBenny Halevy 171613c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1717e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); 1718e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1719db8ac8baSWeston Andros Adamson 1720db8ac8baSWeston Andros Adamson if (send_implementation_id && 1721db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1722db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1723db8ac8baSWeston Andros Adamson <= NFS4_OPAQUE_LIMIT + 1) 1724db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1725db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1726db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1727db8ac8baSWeston Andros Adamson 1728db8ac8baSWeston Andros Adamson if (len > 0) { 1729db8ac8baSWeston Andros Adamson *p = cpu_to_be32(1); /* implementation id array length=1 */ 1730db8ac8baSWeston Andros Adamson 1731db8ac8baSWeston Andros Adamson encode_string(xdr, 1732db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1733db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1734db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1735db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1736db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1737db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1738db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1739db8ac8baSWeston Andros Adamson } else 1740db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); /* implementation id array length=0 */ 174199fe60d0SBenny Halevy } 1742fc931582SAndy Adamson 1743fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1744fc931582SAndy Adamson struct nfs41_create_session_args *args, 1745fc931582SAndy Adamson struct compound_hdr *hdr) 1746fc931582SAndy Adamson { 1747fc931582SAndy Adamson __be32 *p; 1748fc931582SAndy Adamson char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1749fc931582SAndy Adamson uint32_t len; 1750fc931582SAndy Adamson struct nfs_client *clp = args->client; 1751f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 17528e0d46e1SMike Sager u32 max_resp_sz_cached; 17538e0d46e1SMike Sager 17548e0d46e1SMike Sager /* 17558e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 17568e0d46e1SMike Sager * 2 is the verifier. 17578e0d46e1SMike Sager */ 17588e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 17598e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1760fc931582SAndy Adamson 1761fc931582SAndy Adamson len = scnprintf(machine_name, sizeof(machine_name), "%s", 1762fc931582SAndy Adamson clp->cl_ipaddr); 176342edd698SBenny Halevy 1764475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 1765475d4ba0STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12); 1766114f64b5SAndy Adamson p = xdr_encode_hyper(p, clp->cl_clientid); 1767e75bc1c8SBenny Halevy *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1768e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1769fc931582SAndy Adamson 1770fc931582SAndy Adamson /* Fore Channel */ 1771c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1772e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1773e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 17748e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1775e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1776e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1777e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1778fc931582SAndy Adamson 1779fc931582SAndy Adamson /* Back Channel */ 1780c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1781e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1782e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1783e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1784e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1785e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1786e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1787fc931582SAndy Adamson 1788e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1789e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1790e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1791fc931582SAndy Adamson 1792fc931582SAndy Adamson /* authsys_parms rfc1831 */ 1793f092075dSChuck Lever *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */ 1794811652bdSBenny Halevy p = xdr_encode_opaque(p, machine_name, len); 1795e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1796e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 179734558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1798fc931582SAndy Adamson } 17990f3e66c6SAndy Adamson 18000f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 18010f3e66c6SAndy Adamson struct nfs4_session *session, 18020f3e66c6SAndy Adamson struct compound_hdr *hdr) 18030f3e66c6SAndy Adamson { 1804475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1805475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18060f3e66c6SAndy Adamson } 180718019753SRicardo Labiaga 180866245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 180966245539STrond Myklebust uint64_t clientid, 181066245539STrond Myklebust struct compound_hdr *hdr) 181166245539STrond Myklebust { 181266245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 181366245539STrond Myklebust encode_uint64(xdr, clientid); 181466245539STrond Myklebust } 181566245539STrond Myklebust 181618019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 181718019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 181818019753SRicardo Labiaga struct compound_hdr *hdr) 181918019753SRicardo Labiaga { 1820475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1821475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 182218019753SRicardo Labiaga } 182399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 182499fe60d0SBenny Halevy 18259b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18269b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18279b7b9fccSAndy Adamson struct compound_hdr *hdr) 18289b7b9fccSAndy Adamson { 18299b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18309b7b9fccSAndy Adamson struct nfs4_session *session = args->sa_session; 1831fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 1832fc01cea9SAndy Adamson struct nfs4_slot *slot; 1833fc01cea9SAndy Adamson __be32 *p; 18349b7b9fccSAndy Adamson 18359b7b9fccSAndy Adamson if (!session) 18369b7b9fccSAndy Adamson return; 18379b7b9fccSAndy Adamson 1838fc01cea9SAndy Adamson tp = &session->fc_slot_table; 1839fc01cea9SAndy Adamson 1840fc01cea9SAndy Adamson WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1841fc01cea9SAndy Adamson slot = tp->slots + args->sa_slotid; 1842fc01cea9SAndy Adamson 1843475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1844fc01cea9SAndy Adamson 1845fc01cea9SAndy Adamson /* 1846fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1847fc01cea9SAndy Adamson */ 1848fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1849fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1850fc01cea9SAndy Adamson __func__, 1851fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1852fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1853fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1854fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 1855fc01cea9SAndy Adamson slot->seq_nr, args->sa_slotid, 1856fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1857475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 185893f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1859e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 1860e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->sa_slotid); 1861e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 186234558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 18639b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 18649b7b9fccSAndy Adamson } 18659b7b9fccSAndy Adamson 1866b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1867b1f69b75SAndy Adamson static void 18687f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr, 18697f11d8d3SAndy Adamson const struct nfs4_getdevicelist_args *args, 18707f11d8d3SAndy Adamson struct compound_hdr *hdr) 18717f11d8d3SAndy Adamson { 18727f11d8d3SAndy Adamson __be32 *p; 18737f11d8d3SAndy Adamson nfs4_verifier dummy = { 18747f11d8d3SAndy Adamson .data = "dummmmmy", 18757f11d8d3SAndy Adamson }; 18767f11d8d3SAndy Adamson 1877475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr); 1878475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 18797f11d8d3SAndy Adamson *p++ = cpu_to_be32(args->layoutclass); 18807f11d8d3SAndy Adamson *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 18817f11d8d3SAndy Adamson xdr_encode_hyper(p, 0ULL); /* cookie */ 18827f11d8d3SAndy Adamson encode_nfs4_verifier(xdr, &dummy); 18837f11d8d3SAndy Adamson } 18847f11d8d3SAndy Adamson 18857f11d8d3SAndy Adamson static void 1886b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1887b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1888b1f69b75SAndy Adamson struct compound_hdr *hdr) 1889b1f69b75SAndy Adamson { 1890b1f69b75SAndy Adamson __be32 *p; 1891b1f69b75SAndy Adamson 1892475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 1893475d4ba0STrond Myklebust p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE); 1894b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1895b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1896b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1897b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ 1898b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1899b1f69b75SAndy Adamson } 1900b1f69b75SAndy Adamson 1901b1f69b75SAndy Adamson static void 1902b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1903b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1904b1f69b75SAndy Adamson struct compound_hdr *hdr) 1905b1f69b75SAndy Adamson { 1906b1f69b75SAndy Adamson __be32 *p; 1907b1f69b75SAndy Adamson 1908475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1909475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1910b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1911b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1912b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1913b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1914b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1915b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1916ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1917475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1918b1f69b75SAndy Adamson 1919b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1920b1f69b75SAndy Adamson __func__, 1921b1f69b75SAndy Adamson args->type, 1922b1f69b75SAndy Adamson args->range.iomode, 1923b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1924b1f69b75SAndy Adamson (unsigned long)args->range.length, 1925b1f69b75SAndy Adamson args->maxcount); 1926b1f69b75SAndy Adamson } 1927863a3c6cSAndy Adamson 1928863a3c6cSAndy Adamson static int 1929863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1930ac7db726SBenny Halevy struct inode *inode, 1931863a3c6cSAndy Adamson const struct nfs4_layoutcommit_args *args, 1932863a3c6cSAndy Adamson struct compound_hdr *hdr) 1933863a3c6cSAndy Adamson { 1934863a3c6cSAndy Adamson __be32 *p; 1935863a3c6cSAndy Adamson 1936863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1937863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1938863a3c6cSAndy Adamson 1939475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1940475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1941863a3c6cSAndy Adamson /* Only whole file layouts */ 1942863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19433557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1944ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1945ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1946ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1947863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1948863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 1949863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1950863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 1951ac7db726SBenny Halevy 1952ac7db726SBenny Halevy if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 1953ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1954ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 1955475d4ba0STrond Myklebust else 1956475d4ba0STrond Myklebust encode_uint32(xdr, 0); /* no layout-type payload */ 1957863a3c6cSAndy Adamson 1958863a3c6cSAndy Adamson return 0; 1959863a3c6cSAndy Adamson } 1960cbe82603SBenny Halevy 1961cbe82603SBenny Halevy static void 1962cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 1963cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 1964cbe82603SBenny Halevy struct compound_hdr *hdr) 1965cbe82603SBenny Halevy { 1966cbe82603SBenny Halevy __be32 *p; 1967cbe82603SBenny Halevy 1968475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 1969475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 1970cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 1971cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 1972cbe82603SBenny Halevy *p++ = cpu_to_be32(IOMODE_ANY); 1973cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 1974ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1975cbe82603SBenny Halevy p = xdr_encode_hyper(p, 0); 1976cbe82603SBenny Halevy p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 1977cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 1978ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1979cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 198004a55549SAndy Adamson if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 198104a55549SAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 198204a55549SAndy Adamson NFS_I(args->inode)->layout, xdr, args); 1983475d4ba0STrond Myklebust } else 1984475d4ba0STrond Myklebust encode_uint32(xdr, 0); 1985cbe82603SBenny Halevy } 1986fca78d6dSBryan Schumaker 1987fca78d6dSBryan Schumaker static int 1988fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 1989fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 1990fca78d6dSBryan Schumaker struct compound_hdr *hdr) 1991fca78d6dSBryan Schumaker { 1992475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 1993475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 1994fca78d6dSBryan Schumaker return 0; 1995fca78d6dSBryan Schumaker } 19967d974794SBryan Schumaker 19977d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 19987d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 19997d974794SBryan Schumaker struct compound_hdr *hdr) 20007d974794SBryan Schumaker { 2001475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2002475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2003ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20047d974794SBryan Schumaker } 20059aeda35fSBryan Schumaker 20069aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 20079aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 20089aeda35fSBryan Schumaker struct compound_hdr *hdr) 20099aeda35fSBryan Schumaker { 2010ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 2011ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20129aeda35fSBryan Schumaker } 2013b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2014b1f69b75SAndy Adamson 20151da177e4SLinus Torvalds /* 20161da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20171da177e4SLinus Torvalds */ 20181da177e4SLinus Torvalds 201966cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 202066cc0429SBenny Halevy { 202166cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 202266cc0429SBenny Halevy if (args->sa_session) 2023a4432345STrond Myklebust return args->sa_session->clp->cl_mvops->minor_version; 202466cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 202566cc0429SBenny Halevy return 0; 202666cc0429SBenny Halevy } 202766cc0429SBenny Halevy 20281da177e4SLinus Torvalds /* 20291da177e4SLinus Torvalds * Encode an ACCESS request 20301da177e4SLinus Torvalds */ 20319f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 20329f06c719SChuck Lever const struct nfs4_accessargs *args) 20331da177e4SLinus Torvalds { 20341da177e4SLinus Torvalds struct compound_hdr hdr = { 203566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20361da177e4SLinus Torvalds }; 20371da177e4SLinus Torvalds 20389f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20399f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20409f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20419f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 20429f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2043d017931cSAndy Adamson encode_nops(&hdr); 20441da177e4SLinus Torvalds } 20451da177e4SLinus Torvalds 20461da177e4SLinus Torvalds /* 20471da177e4SLinus Torvalds * Encode LOOKUP request 20481da177e4SLinus Torvalds */ 20499f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 20509f06c719SChuck Lever const struct nfs4_lookup_arg *args) 20511da177e4SLinus Torvalds { 20521da177e4SLinus Torvalds struct compound_hdr hdr = { 205366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20541da177e4SLinus Torvalds }; 20551da177e4SLinus Torvalds 20569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20579f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20589f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 20599f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 20609f06c719SChuck Lever encode_getfh(xdr, &hdr); 20619f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2062d017931cSAndy Adamson encode_nops(&hdr); 20631da177e4SLinus Torvalds } 20641da177e4SLinus Torvalds 20651da177e4SLinus Torvalds /* 20661da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 20671da177e4SLinus Torvalds */ 20689f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 20699f06c719SChuck Lever struct xdr_stream *xdr, 20709f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 20711da177e4SLinus Torvalds { 20721da177e4SLinus Torvalds struct compound_hdr hdr = { 207366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20741da177e4SLinus Torvalds }; 20751da177e4SLinus Torvalds 20769f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20779f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20789f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 20799f06c719SChuck Lever encode_getfh(xdr, &hdr); 20809f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2081d017931cSAndy Adamson encode_nops(&hdr); 20821da177e4SLinus Torvalds } 20831da177e4SLinus Torvalds 20841da177e4SLinus Torvalds /* 20851da177e4SLinus Torvalds * Encode REMOVE request 20861da177e4SLinus Torvalds */ 20879f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 20889f06c719SChuck Lever const struct nfs_removeargs *args) 20891da177e4SLinus Torvalds { 20901da177e4SLinus Torvalds struct compound_hdr hdr = { 209166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20921da177e4SLinus Torvalds }; 20931da177e4SLinus Torvalds 20949f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20959f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20969f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20979f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2098d017931cSAndy Adamson encode_nops(&hdr); 20991da177e4SLinus Torvalds } 21001da177e4SLinus Torvalds 21011da177e4SLinus Torvalds /* 21021da177e4SLinus Torvalds * Encode RENAME request 21031da177e4SLinus Torvalds */ 21049f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 21059f06c719SChuck Lever const struct nfs_renameargs *args) 21061da177e4SLinus Torvalds { 21071da177e4SLinus Torvalds struct compound_hdr hdr = { 210866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21091da177e4SLinus Torvalds }; 21101da177e4SLinus Torvalds 21119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21139f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21149f06c719SChuck Lever encode_savefh(xdr, &hdr); 21159f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21169f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2117d017931cSAndy Adamson encode_nops(&hdr); 21181da177e4SLinus Torvalds } 21191da177e4SLinus Torvalds 21201da177e4SLinus Torvalds /* 21211da177e4SLinus Torvalds * Encode LINK request 21221da177e4SLinus Torvalds */ 21239f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 21249f06c719SChuck Lever const struct nfs4_link_arg *args) 21251da177e4SLinus Torvalds { 21261da177e4SLinus Torvalds struct compound_hdr hdr = { 212766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21281da177e4SLinus Torvalds }; 21291da177e4SLinus Torvalds 21309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21329f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21339f06c719SChuck Lever encode_savefh(xdr, &hdr); 21349f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21359f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 21369f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21379f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2138d017931cSAndy Adamson encode_nops(&hdr); 21391da177e4SLinus Torvalds } 21401da177e4SLinus Torvalds 21411da177e4SLinus Torvalds /* 21421da177e4SLinus Torvalds * Encode CREATE request 21431da177e4SLinus Torvalds */ 21449f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 21459f06c719SChuck Lever const struct nfs4_create_arg *args) 21461da177e4SLinus Torvalds { 21471da177e4SLinus Torvalds struct compound_hdr hdr = { 214866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21491da177e4SLinus Torvalds }; 21501da177e4SLinus Torvalds 21519f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21529f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21539f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21549f06c719SChuck Lever encode_create(xdr, args, &hdr); 21559f06c719SChuck Lever encode_getfh(xdr, &hdr); 21569f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2157d017931cSAndy Adamson encode_nops(&hdr); 21581da177e4SLinus Torvalds } 21591da177e4SLinus Torvalds 21601da177e4SLinus Torvalds /* 21611da177e4SLinus Torvalds * Encode SYMLINK request 21621da177e4SLinus Torvalds */ 21639f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 21649f06c719SChuck Lever const struct nfs4_create_arg *args) 21651da177e4SLinus Torvalds { 21669f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 21671da177e4SLinus Torvalds } 21681da177e4SLinus Torvalds 21691da177e4SLinus Torvalds /* 21701da177e4SLinus Torvalds * Encode GETATTR request 21711da177e4SLinus Torvalds */ 21729f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 21739f06c719SChuck Lever const struct nfs4_getattr_arg *args) 21741da177e4SLinus Torvalds { 21751da177e4SLinus Torvalds struct compound_hdr hdr = { 217666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21771da177e4SLinus Torvalds }; 21781da177e4SLinus Torvalds 21799f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21809f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21819f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21829f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2183d017931cSAndy Adamson encode_nops(&hdr); 21841da177e4SLinus Torvalds } 21851da177e4SLinus Torvalds 21861da177e4SLinus Torvalds /* 21871da177e4SLinus Torvalds * Encode a CLOSE request 21881da177e4SLinus Torvalds */ 21899f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 21909f06c719SChuck Lever struct nfs_closeargs *args) 21911da177e4SLinus Torvalds { 21921da177e4SLinus Torvalds struct compound_hdr hdr = { 219366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21941da177e4SLinus Torvalds }; 21951da177e4SLinus Torvalds 21969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21999f06c719SChuck Lever encode_close(xdr, args, &hdr); 22009f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2201d017931cSAndy Adamson encode_nops(&hdr); 22021da177e4SLinus Torvalds } 22031da177e4SLinus Torvalds 22041da177e4SLinus Torvalds /* 22051da177e4SLinus Torvalds * Encode an OPEN request 22061da177e4SLinus Torvalds */ 22079f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 22089f06c719SChuck Lever struct nfs_openargs *args) 22091da177e4SLinus Torvalds { 22101da177e4SLinus Torvalds struct compound_hdr hdr = { 221166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22121da177e4SLinus Torvalds }; 22131da177e4SLinus Torvalds 22149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22169f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22179f06c719SChuck Lever encode_open(xdr, args, &hdr); 22189f06c719SChuck Lever encode_getfh(xdr, &hdr); 22191549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2220d017931cSAndy Adamson encode_nops(&hdr); 22211da177e4SLinus Torvalds } 22221da177e4SLinus Torvalds 22231da177e4SLinus Torvalds /* 22241da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 22251da177e4SLinus Torvalds */ 22269f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22279f06c719SChuck Lever struct xdr_stream *xdr, 22289f06c719SChuck Lever struct nfs_open_confirmargs *args) 22291da177e4SLinus Torvalds { 22301da177e4SLinus Torvalds struct compound_hdr hdr = { 2231d017931cSAndy Adamson .nops = 0, 22321da177e4SLinus Torvalds }; 22331da177e4SLinus Torvalds 22349f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22359f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22369f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2237d017931cSAndy Adamson encode_nops(&hdr); 22381da177e4SLinus Torvalds } 22391da177e4SLinus Torvalds 22401da177e4SLinus Torvalds /* 22411da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 22421da177e4SLinus Torvalds */ 22439f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 22449f06c719SChuck Lever struct xdr_stream *xdr, 22459f06c719SChuck Lever struct nfs_openargs *args) 22461da177e4SLinus Torvalds { 22471da177e4SLinus Torvalds struct compound_hdr hdr = { 224866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22491da177e4SLinus Torvalds }; 22501da177e4SLinus Torvalds 22519f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22529f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22539f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22549f06c719SChuck Lever encode_open(xdr, args, &hdr); 22559f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2256d017931cSAndy Adamson encode_nops(&hdr); 22571da177e4SLinus Torvalds } 22581da177e4SLinus Torvalds 22591da177e4SLinus Torvalds /* 22601da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 22611da177e4SLinus Torvalds */ 22629f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 22639f06c719SChuck Lever struct xdr_stream *xdr, 22649f06c719SChuck Lever struct nfs_closeargs *args) 22651da177e4SLinus Torvalds { 22661da177e4SLinus Torvalds struct compound_hdr hdr = { 226766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22681da177e4SLinus Torvalds }; 22691da177e4SLinus Torvalds 22709f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22719f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22729f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22739f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 22749f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2275d017931cSAndy Adamson encode_nops(&hdr); 22761da177e4SLinus Torvalds } 22771da177e4SLinus Torvalds 22781da177e4SLinus Torvalds /* 22791da177e4SLinus Torvalds * Encode a LOCK request 22801da177e4SLinus Torvalds */ 22819f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 22829f06c719SChuck Lever struct nfs_lock_args *args) 22831da177e4SLinus Torvalds { 22841da177e4SLinus Torvalds struct compound_hdr hdr = { 228566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22861da177e4SLinus Torvalds }; 22871da177e4SLinus Torvalds 22889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22899f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22909f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22919f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2292d017931cSAndy Adamson encode_nops(&hdr); 22931da177e4SLinus Torvalds } 22941da177e4SLinus Torvalds 22951da177e4SLinus Torvalds /* 22961da177e4SLinus Torvalds * Encode a LOCKT request 22971da177e4SLinus Torvalds */ 22989f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 22999f06c719SChuck Lever struct nfs_lockt_args *args) 23001da177e4SLinus Torvalds { 23011da177e4SLinus Torvalds struct compound_hdr hdr = { 230266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23031da177e4SLinus Torvalds }; 23041da177e4SLinus Torvalds 23059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23089f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2309d017931cSAndy Adamson encode_nops(&hdr); 23101da177e4SLinus Torvalds } 23111da177e4SLinus Torvalds 23121da177e4SLinus Torvalds /* 23131da177e4SLinus Torvalds * Encode a LOCKU request 23141da177e4SLinus Torvalds */ 23159f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 23169f06c719SChuck Lever struct nfs_locku_args *args) 23171da177e4SLinus Torvalds { 23181da177e4SLinus Torvalds struct compound_hdr hdr = { 231966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23201da177e4SLinus Torvalds }; 23211da177e4SLinus Torvalds 23229f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23239f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23249f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23259f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2326d017931cSAndy Adamson encode_nops(&hdr); 23271da177e4SLinus Torvalds } 23281da177e4SLinus Torvalds 23299f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 23309f06c719SChuck Lever struct xdr_stream *xdr, 23319f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2332d3c7b7ccSTrond Myklebust { 2333d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2334d3c7b7ccSTrond Myklebust .minorversion = 0, 2335d3c7b7ccSTrond Myklebust }; 2336d3c7b7ccSTrond Myklebust 23379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23389f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2339d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2340d3c7b7ccSTrond Myklebust } 2341d3c7b7ccSTrond Myklebust 23421da177e4SLinus Torvalds /* 23431da177e4SLinus Torvalds * Encode a READLINK request 23441da177e4SLinus Torvalds */ 23459f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 23469f06c719SChuck Lever const struct nfs4_readlink *args) 23471da177e4SLinus Torvalds { 23481da177e4SLinus Torvalds struct compound_hdr hdr = { 234966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23501da177e4SLinus Torvalds }; 23511da177e4SLinus Torvalds 23529f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23539f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23549f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23559f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2356e3a535e1STrond Myklebust 235728f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2358e3a535e1STrond Myklebust args->pgbase, args->pglen); 2359d017931cSAndy Adamson encode_nops(&hdr); 23601da177e4SLinus Torvalds } 23611da177e4SLinus Torvalds 23621da177e4SLinus Torvalds /* 23631da177e4SLinus Torvalds * Encode a READDIR request 23641da177e4SLinus Torvalds */ 23659f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 23669f06c719SChuck Lever const struct nfs4_readdir_arg *args) 23671da177e4SLinus Torvalds { 23681da177e4SLinus Torvalds struct compound_hdr hdr = { 236966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23701da177e4SLinus Torvalds }; 23711da177e4SLinus Torvalds 23729f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23739f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23749f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23759f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2376d6ac02dfSTrond Myklebust 237728f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2378d6ac02dfSTrond Myklebust args->pgbase, args->count); 2379d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 238028f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2381d6ac02dfSTrond Myklebust args->pgbase, args->count); 2382d017931cSAndy Adamson encode_nops(&hdr); 23831da177e4SLinus Torvalds } 23841da177e4SLinus Torvalds 23851da177e4SLinus Torvalds /* 23861da177e4SLinus Torvalds * Encode a READ request 23871da177e4SLinus Torvalds */ 23889f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 23899f06c719SChuck Lever struct nfs_readargs *args) 23901da177e4SLinus Torvalds { 23911da177e4SLinus Torvalds struct compound_hdr hdr = { 239266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23931da177e4SLinus Torvalds }; 23941da177e4SLinus Torvalds 23959f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23969f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23979f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23989f06c719SChuck Lever encode_read(xdr, args, &hdr); 23991da177e4SLinus Torvalds 240028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 24011da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 24024f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2403d017931cSAndy Adamson encode_nops(&hdr); 24041da177e4SLinus Torvalds } 24051da177e4SLinus Torvalds 24061da177e4SLinus Torvalds /* 24071da177e4SLinus Torvalds * Encode an SETATTR request 24081da177e4SLinus Torvalds */ 24099f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 24109f06c719SChuck Lever struct nfs_setattrargs *args) 24111da177e4SLinus Torvalds { 24121da177e4SLinus Torvalds struct compound_hdr hdr = { 241366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24141da177e4SLinus Torvalds }; 24151da177e4SLinus Torvalds 24169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24189f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24199f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 24209f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2421d017931cSAndy Adamson encode_nops(&hdr); 24221da177e4SLinus Torvalds } 24231da177e4SLinus Torvalds 24241da177e4SLinus Torvalds /* 2425029d105eSJ. Bruce Fields * Encode a GETACL request 2426029d105eSJ. Bruce Fields */ 24279f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2428029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2429029d105eSJ. Bruce Fields { 2430029d105eSJ. Bruce Fields struct compound_hdr hdr = { 243166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2432029d105eSJ. Bruce Fields }; 243328f56694SBenny Halevy uint32_t replen; 2434029d105eSJ. Bruce Fields 24359f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24369f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24379f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2438bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 24399f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2440cf8cdbe5SAndy Adamson 244128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2442029d105eSJ. Bruce Fields args->acl_pages, args->acl_pgbase, args->acl_len); 2443bf118a34SAndy Adamson 2444d017931cSAndy Adamson encode_nops(&hdr); 2445029d105eSJ. Bruce Fields } 2446029d105eSJ. Bruce Fields 2447029d105eSJ. Bruce Fields /* 24481da177e4SLinus Torvalds * Encode a WRITE request 24491da177e4SLinus Torvalds */ 24509f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 24519f06c719SChuck Lever struct nfs_writeargs *args) 24521da177e4SLinus Torvalds { 24531da177e4SLinus Torvalds struct compound_hdr hdr = { 245466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24551da177e4SLinus Torvalds }; 24561da177e4SLinus Torvalds 24579f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24589f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24599f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24609f06c719SChuck Lever encode_write(xdr, args, &hdr); 24614f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 24627ffd1064SFred Isaman if (args->bitmask) 24639f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2464d017931cSAndy Adamson encode_nops(&hdr); 24651da177e4SLinus Torvalds } 24661da177e4SLinus Torvalds 24671da177e4SLinus Torvalds /* 24681da177e4SLinus Torvalds * a COMMIT request 24691da177e4SLinus Torvalds */ 24709f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 24710b7c0153SFred Isaman struct nfs_commitargs *args) 24721da177e4SLinus Torvalds { 24731da177e4SLinus Torvalds struct compound_hdr hdr = { 247466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24751da177e4SLinus Torvalds }; 24761da177e4SLinus Torvalds 24779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24789f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24799f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24809f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2481d017931cSAndy Adamson encode_nops(&hdr); 24821da177e4SLinus Torvalds } 24831da177e4SLinus Torvalds 24841da177e4SLinus Torvalds /* 24851da177e4SLinus Torvalds * FSINFO request 24861da177e4SLinus Torvalds */ 24879f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 24889f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 24891da177e4SLinus Torvalds { 24901da177e4SLinus Torvalds struct compound_hdr hdr = { 249166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24921da177e4SLinus Torvalds }; 24931da177e4SLinus Torvalds 24949f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24959f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24969f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24979f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2498d017931cSAndy Adamson encode_nops(&hdr); 24991da177e4SLinus Torvalds } 25001da177e4SLinus Torvalds 25011da177e4SLinus Torvalds /* 25021da177e4SLinus Torvalds * a PATHCONF request 25031da177e4SLinus Torvalds */ 25049f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 25059f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 25061da177e4SLinus Torvalds { 25071da177e4SLinus Torvalds struct compound_hdr hdr = { 250866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25091da177e4SLinus Torvalds }; 25101da177e4SLinus Torvalds 25119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25139f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25149f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2515d017931cSAndy Adamson &hdr); 2516d017931cSAndy Adamson encode_nops(&hdr); 25171da177e4SLinus Torvalds } 25181da177e4SLinus Torvalds 25191da177e4SLinus Torvalds /* 25201da177e4SLinus Torvalds * a STATFS request 25211da177e4SLinus Torvalds */ 25229f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 25239f06c719SChuck Lever const struct nfs4_statfs_arg *args) 25241da177e4SLinus Torvalds { 25251da177e4SLinus Torvalds struct compound_hdr hdr = { 252666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25271da177e4SLinus Torvalds }; 25281da177e4SLinus Torvalds 25299f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25309f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25319f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25329f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2533d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2534d017931cSAndy Adamson encode_nops(&hdr); 25351da177e4SLinus Torvalds } 25361da177e4SLinus Torvalds 25371da177e4SLinus Torvalds /* 25381da177e4SLinus Torvalds * GETATTR_BITMAP request 25391da177e4SLinus Torvalds */ 25409f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 25419f06c719SChuck Lever struct xdr_stream *xdr, 254243652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 25431da177e4SLinus Torvalds { 25441da177e4SLinus Torvalds struct compound_hdr hdr = { 254566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25461da177e4SLinus Torvalds }; 25471da177e4SLinus Torvalds 25489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25499f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25509f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 25519f06c719SChuck Lever encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2552264e6351SChuck Lever FATTR4_WORD0_FH_EXPIRE_TYPE| 25531da177e4SLinus Torvalds FATTR4_WORD0_LINK_SUPPORT| 25541da177e4SLinus Torvalds FATTR4_WORD0_SYMLINK_SUPPORT| 2555d017931cSAndy Adamson FATTR4_WORD0_ACLSUPPORT, &hdr); 2556d017931cSAndy Adamson encode_nops(&hdr); 25571da177e4SLinus Torvalds } 25581da177e4SLinus Torvalds 25591da177e4SLinus Torvalds /* 25601da177e4SLinus Torvalds * a RENEW request 25611da177e4SLinus Torvalds */ 25629f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 25639f06c719SChuck Lever struct nfs_client *clp) 25641da177e4SLinus Torvalds { 25651da177e4SLinus Torvalds struct compound_hdr hdr = { 2566d017931cSAndy Adamson .nops = 0, 25671da177e4SLinus Torvalds }; 25681da177e4SLinus Torvalds 25699f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2570bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2571d017931cSAndy Adamson encode_nops(&hdr); 25721da177e4SLinus Torvalds } 25731da177e4SLinus Torvalds 25741da177e4SLinus Torvalds /* 25751da177e4SLinus Torvalds * a SETCLIENTID request 25761da177e4SLinus Torvalds */ 25779f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 25789f06c719SChuck Lever struct xdr_stream *xdr, 25799f06c719SChuck Lever struct nfs4_setclientid *sc) 25801da177e4SLinus Torvalds { 25811da177e4SLinus Torvalds struct compound_hdr hdr = { 2582d017931cSAndy Adamson .nops = 0, 25831da177e4SLinus Torvalds }; 25841da177e4SLinus Torvalds 25859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25869f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2587d017931cSAndy Adamson encode_nops(&hdr); 25881da177e4SLinus Torvalds } 25891da177e4SLinus Torvalds 25901da177e4SLinus Torvalds /* 25911da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 25921da177e4SLinus Torvalds */ 25939f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 25949f06c719SChuck Lever struct xdr_stream *xdr, 25959f06c719SChuck Lever struct nfs4_setclientid_res *arg) 25961da177e4SLinus Torvalds { 25971da177e4SLinus Torvalds struct compound_hdr hdr = { 2598d017931cSAndy Adamson .nops = 0, 25991da177e4SLinus Torvalds }; 2600dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 26011da177e4SLinus Torvalds 26029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26039f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 26049f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 26059f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 2606d017931cSAndy Adamson encode_nops(&hdr); 26071da177e4SLinus Torvalds } 26081da177e4SLinus Torvalds 26091da177e4SLinus Torvalds /* 26101da177e4SLinus Torvalds * DELEGRETURN request 26111da177e4SLinus Torvalds */ 26129f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 26139f06c719SChuck Lever struct xdr_stream *xdr, 26149f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 26151da177e4SLinus Torvalds { 26161da177e4SLinus Torvalds struct compound_hdr hdr = { 261766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26181da177e4SLinus Torvalds }; 26191da177e4SLinus Torvalds 26209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26219f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26229f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26239f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2624e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2625d017931cSAndy Adamson encode_nops(&hdr); 26261da177e4SLinus Torvalds } 26271da177e4SLinus Torvalds 26281da177e4SLinus Torvalds /* 2629683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2630683b57b4STrond Myklebust */ 26319f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 26329f06c719SChuck Lever struct xdr_stream *xdr, 26339f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2634683b57b4STrond Myklebust { 2635683b57b4STrond Myklebust struct compound_hdr hdr = { 263666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2637683b57b4STrond Myklebust }; 263828f56694SBenny Halevy uint32_t replen; 2639683b57b4STrond Myklebust 26409f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26419f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26429f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 26439f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 264428f56694SBenny Halevy replen = hdr.replen; /* get the attribute into args->page */ 26459f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2646cf8cdbe5SAndy Adamson 264728f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2648683b57b4STrond Myklebust 0, PAGE_SIZE); 2649d017931cSAndy Adamson encode_nops(&hdr); 2650683b57b4STrond Myklebust } 2651683b57b4STrond Myklebust 26525a5ea0d4SBryan Schumaker /* 26535a5ea0d4SBryan Schumaker * Encode SECINFO request 26545a5ea0d4SBryan Schumaker */ 26555a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 26565a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 26575a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 26585a5ea0d4SBryan Schumaker { 26595a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 26605a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26615a5ea0d4SBryan Schumaker }; 26625a5ea0d4SBryan Schumaker 26635a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 26645a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 26655a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 26665a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 26675a5ea0d4SBryan Schumaker encode_nops(&hdr); 26685a5ea0d4SBryan Schumaker } 26695a5ea0d4SBryan Schumaker 267099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 267199fe60d0SBenny Halevy /* 26727c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 26737c44f1aeSWeston Andros Adamson */ 26747c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 26757c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 26767c44f1aeSWeston Andros Adamson struct nfs_client *clp) 26777c44f1aeSWeston Andros Adamson { 26787c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 26797c44f1aeSWeston Andros Adamson .minorversion = clp->cl_mvops->minor_version, 26807c44f1aeSWeston Andros Adamson }; 26817c44f1aeSWeston Andros Adamson 26827c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 26837c44f1aeSWeston Andros Adamson encode_bind_conn_to_session(xdr, clp->cl_session, &hdr); 26847c44f1aeSWeston Andros Adamson encode_nops(&hdr); 26857c44f1aeSWeston Andros Adamson } 26867c44f1aeSWeston Andros Adamson 26877c44f1aeSWeston Andros Adamson /* 268899fe60d0SBenny Halevy * EXCHANGE_ID request 268999fe60d0SBenny Halevy */ 26909f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 26919f06c719SChuck Lever struct xdr_stream *xdr, 269299fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 269399fe60d0SBenny Halevy { 269499fe60d0SBenny Halevy struct compound_hdr hdr = { 2695a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 269699fe60d0SBenny Halevy }; 269799fe60d0SBenny Halevy 26989f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26999f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 270099fe60d0SBenny Halevy encode_nops(&hdr); 270199fe60d0SBenny Halevy } 27022050f0ccSAndy Adamson 27032050f0ccSAndy Adamson /* 2704fc931582SAndy Adamson * a CREATE_SESSION request 2705fc931582SAndy Adamson */ 27069f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 27079f06c719SChuck Lever struct xdr_stream *xdr, 2708fc931582SAndy Adamson struct nfs41_create_session_args *args) 2709fc931582SAndy Adamson { 2710fc931582SAndy Adamson struct compound_hdr hdr = { 2711a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2712fc931582SAndy Adamson }; 2713fc931582SAndy Adamson 27149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27159f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2716fc931582SAndy Adamson encode_nops(&hdr); 2717fc931582SAndy Adamson } 2718fc931582SAndy Adamson 2719fc931582SAndy Adamson /* 27200f3e66c6SAndy Adamson * a DESTROY_SESSION request 27210f3e66c6SAndy Adamson */ 27229f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 27239f06c719SChuck Lever struct xdr_stream *xdr, 27240f3e66c6SAndy Adamson struct nfs4_session *session) 27250f3e66c6SAndy Adamson { 27260f3e66c6SAndy Adamson struct compound_hdr hdr = { 2727a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 27280f3e66c6SAndy Adamson }; 27290f3e66c6SAndy Adamson 27309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27319f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 27320f3e66c6SAndy Adamson encode_nops(&hdr); 27330f3e66c6SAndy Adamson } 27340f3e66c6SAndy Adamson 27350f3e66c6SAndy Adamson /* 273666245539STrond Myklebust * a DESTROY_CLIENTID request 273766245539STrond Myklebust */ 273866245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 273966245539STrond Myklebust struct xdr_stream *xdr, 274066245539STrond Myklebust struct nfs_client *clp) 274166245539STrond Myklebust { 274266245539STrond Myklebust struct compound_hdr hdr = { 274366245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 274466245539STrond Myklebust }; 274566245539STrond Myklebust 274666245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 274766245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 274866245539STrond Myklebust encode_nops(&hdr); 274966245539STrond Myklebust } 275066245539STrond Myklebust 275166245539STrond Myklebust /* 2752fc01cea9SAndy Adamson * a SEQUENCE request 2753fc01cea9SAndy Adamson */ 27549f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2755fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2756fc01cea9SAndy Adamson { 2757fc01cea9SAndy Adamson struct compound_hdr hdr = { 2758fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2759fc01cea9SAndy Adamson }; 2760fc01cea9SAndy Adamson 27619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27629f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2763fc01cea9SAndy Adamson encode_nops(&hdr); 2764fc01cea9SAndy Adamson } 2765fc01cea9SAndy Adamson 2766fc01cea9SAndy Adamson /* 27672050f0ccSAndy Adamson * a GET_LEASE_TIME request 27682050f0ccSAndy Adamson */ 27699f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 27709f06c719SChuck Lever struct xdr_stream *xdr, 27712050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 27722050f0ccSAndy Adamson { 27732050f0ccSAndy Adamson struct compound_hdr hdr = { 27742050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 27752050f0ccSAndy Adamson }; 2776dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 27772050f0ccSAndy Adamson 27789f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27799f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 27809f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 27819f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 27822050f0ccSAndy Adamson encode_nops(&hdr); 27832050f0ccSAndy Adamson } 278418019753SRicardo Labiaga 278518019753SRicardo Labiaga /* 278618019753SRicardo Labiaga * a RECLAIM_COMPLETE request 278718019753SRicardo Labiaga */ 27889f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 27899f06c719SChuck Lever struct xdr_stream *xdr, 279018019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 279118019753SRicardo Labiaga { 279218019753SRicardo Labiaga struct compound_hdr hdr = { 279318019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 279418019753SRicardo Labiaga }; 279518019753SRicardo Labiaga 27969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27989f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 279918019753SRicardo Labiaga encode_nops(&hdr); 280018019753SRicardo Labiaga } 280118019753SRicardo Labiaga 2802b1f69b75SAndy Adamson /* 28037f11d8d3SAndy Adamson * Encode GETDEVICELIST request 28047f11d8d3SAndy Adamson */ 28057f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req, 28067f11d8d3SAndy Adamson struct xdr_stream *xdr, 28077f11d8d3SAndy Adamson struct nfs4_getdevicelist_args *args) 28087f11d8d3SAndy Adamson { 28097f11d8d3SAndy Adamson struct compound_hdr hdr = { 28107f11d8d3SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28117f11d8d3SAndy Adamson }; 28127f11d8d3SAndy Adamson 28137f11d8d3SAndy Adamson encode_compound_hdr(xdr, req, &hdr); 28147f11d8d3SAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 28157f11d8d3SAndy Adamson encode_putfh(xdr, args->fh, &hdr); 28167f11d8d3SAndy Adamson encode_getdevicelist(xdr, args, &hdr); 28177f11d8d3SAndy Adamson encode_nops(&hdr); 28187f11d8d3SAndy Adamson } 28197f11d8d3SAndy Adamson 28207f11d8d3SAndy Adamson /* 2821b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2822b1f69b75SAndy Adamson */ 28239f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 28249f06c719SChuck Lever struct xdr_stream *xdr, 2825b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2826b1f69b75SAndy Adamson { 2827b1f69b75SAndy Adamson struct compound_hdr hdr = { 2828b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2829b1f69b75SAndy Adamson }; 2830b1f69b75SAndy Adamson 28319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28339f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2834b1f69b75SAndy Adamson 2835b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2836b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2837b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2838b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2839b1f69b75SAndy Adamson args->pdev->pglen); 2840b1f69b75SAndy Adamson 2841b1f69b75SAndy Adamson encode_nops(&hdr); 2842b1f69b75SAndy Adamson } 2843b1f69b75SAndy Adamson 2844b1f69b75SAndy Adamson /* 2845b1f69b75SAndy Adamson * Encode LAYOUTGET request 2846b1f69b75SAndy Adamson */ 28479f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 28489f06c719SChuck Lever struct xdr_stream *xdr, 2849b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2850b1f69b75SAndy Adamson { 2851b1f69b75SAndy Adamson struct compound_hdr hdr = { 2852b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2853b1f69b75SAndy Adamson }; 2854b1f69b75SAndy Adamson 28559f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28569f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28579f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 28589f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 285935124a09SWeston Andros Adamson 286035124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 286135124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 286235124a09SWeston Andros Adamson 2863b1f69b75SAndy Adamson encode_nops(&hdr); 2864b1f69b75SAndy Adamson } 2865863a3c6cSAndy Adamson 2866863a3c6cSAndy Adamson /* 2867863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2868863a3c6cSAndy Adamson */ 2869cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2870863a3c6cSAndy Adamson struct xdr_stream *xdr, 2871863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2872863a3c6cSAndy Adamson { 2873ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2874ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2875863a3c6cSAndy Adamson struct compound_hdr hdr = { 2876863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2877863a3c6cSAndy Adamson }; 2878863a3c6cSAndy Adamson 2879863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2880863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2881863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2882ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2883863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2884863a3c6cSAndy Adamson encode_nops(&hdr); 2885cbe82603SBenny Halevy } 2886cbe82603SBenny Halevy 2887cbe82603SBenny Halevy /* 2888cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2889cbe82603SBenny Halevy */ 2890cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2891cbe82603SBenny Halevy struct xdr_stream *xdr, 2892cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2893cbe82603SBenny Halevy { 2894cbe82603SBenny Halevy struct compound_hdr hdr = { 2895cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2896cbe82603SBenny Halevy }; 2897cbe82603SBenny Halevy 2898cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2899cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2900cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2901cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2902cbe82603SBenny Halevy encode_nops(&hdr); 2903863a3c6cSAndy Adamson } 2904fca78d6dSBryan Schumaker 2905fca78d6dSBryan Schumaker /* 2906fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2907fca78d6dSBryan Schumaker */ 2908fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2909fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2910fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2911fca78d6dSBryan Schumaker { 2912fca78d6dSBryan Schumaker struct compound_hdr hdr = { 2913fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2914fca78d6dSBryan Schumaker }; 2915fca78d6dSBryan Schumaker 2916fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 2917fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 2918fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 2919fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 2920fca78d6dSBryan Schumaker encode_nops(&hdr); 2921fca78d6dSBryan Schumaker return 0; 2922fca78d6dSBryan Schumaker } 29237d974794SBryan Schumaker 29247d974794SBryan Schumaker /* 29257d974794SBryan Schumaker * Encode TEST_STATEID request 29267d974794SBryan Schumaker */ 29277d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 29287d974794SBryan Schumaker struct xdr_stream *xdr, 29297d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 29307d974794SBryan Schumaker { 29317d974794SBryan Schumaker struct compound_hdr hdr = { 29327d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29337d974794SBryan Schumaker }; 29347d974794SBryan Schumaker 29357d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29367d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29377d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 29387d974794SBryan Schumaker encode_nops(&hdr); 29397d974794SBryan Schumaker } 29409aeda35fSBryan Schumaker 29419aeda35fSBryan Schumaker /* 29429aeda35fSBryan Schumaker * Encode FREE_STATEID request 29439aeda35fSBryan Schumaker */ 29449aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 29459aeda35fSBryan Schumaker struct xdr_stream *xdr, 29469aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 29479aeda35fSBryan Schumaker { 29489aeda35fSBryan Schumaker struct compound_hdr hdr = { 29499aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29509aeda35fSBryan Schumaker }; 29519aeda35fSBryan Schumaker 29529aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29539aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29549aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 29559aeda35fSBryan Schumaker encode_nops(&hdr); 29569aeda35fSBryan Schumaker } 295799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 295899fe60d0SBenny Halevy 2959686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 2960686841b3SBenny Halevy { 2961686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 2962686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 2963686841b3SBenny Halevy func, xdr->end - xdr->p); 2964686841b3SBenny Halevy } 29651da177e4SLinus Torvalds 2966683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 29671da177e4SLinus Torvalds { 29688687b63aSAl Viro __be32 *p; 29691da177e4SLinus Torvalds 2970c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 2971c0eae66eSBenny Halevy if (unlikely(!p)) 2972c0eae66eSBenny Halevy goto out_overflow; 2973cccddf4fSBenny Halevy *len = be32_to_cpup(p); 2974c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 2975c0eae66eSBenny Halevy if (unlikely(!p)) 2976c0eae66eSBenny Halevy goto out_overflow; 29771da177e4SLinus Torvalds *string = (char *)p; 29781da177e4SLinus Torvalds return 0; 2979c0eae66eSBenny Halevy out_overflow: 2980c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2981c0eae66eSBenny Halevy return -EIO; 29821da177e4SLinus Torvalds } 29831da177e4SLinus Torvalds 29841da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 29851da177e4SLinus Torvalds { 29868687b63aSAl Viro __be32 *p; 29871da177e4SLinus Torvalds 2988c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 2989c0eae66eSBenny Halevy if (unlikely(!p)) 2990c0eae66eSBenny Halevy goto out_overflow; 29916f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 2992cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 29931da177e4SLinus Torvalds 2994c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 2995c0eae66eSBenny Halevy if (unlikely(!p)) 2996c0eae66eSBenny Halevy goto out_overflow; 29971da177e4SLinus Torvalds hdr->tag = (char *)p; 29981da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 2999cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3000aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3001aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 30021da177e4SLinus Torvalds return 0; 3003c0eae66eSBenny Halevy out_overflow: 3004c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3005c0eae66eSBenny Halevy return -EIO; 30061da177e4SLinus Torvalds } 30071da177e4SLinus Torvalds 30081da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 30091da177e4SLinus Torvalds { 30108687b63aSAl Viro __be32 *p; 30111da177e4SLinus Torvalds uint32_t opnum; 30121da177e4SLinus Torvalds int32_t nfserr; 30131da177e4SLinus Torvalds 3014c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3015c0eae66eSBenny Halevy if (unlikely(!p)) 3016c0eae66eSBenny Halevy goto out_overflow; 30176f723f77SBenny Halevy opnum = be32_to_cpup(p++); 30181da177e4SLinus Torvalds if (opnum != expected) { 3019fe82a183SChuck Lever dprintk("nfs: Server returned operation" 30201da177e4SLinus Torvalds " %d but we issued a request for %d\n", 30211da177e4SLinus Torvalds opnum, expected); 30221da177e4SLinus Torvalds return -EIO; 30231da177e4SLinus Torvalds } 3024cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 30251da177e4SLinus Torvalds if (nfserr != NFS_OK) 3026856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 30271da177e4SLinus Torvalds return 0; 3028c0eae66eSBenny Halevy out_overflow: 3029c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3030c0eae66eSBenny Halevy return -EIO; 30311da177e4SLinus Torvalds } 30321da177e4SLinus Torvalds 30331da177e4SLinus Torvalds /* Dummy routine */ 3034adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 30351da177e4SLinus Torvalds { 30368687b63aSAl Viro __be32 *p; 3037683b57b4STrond Myklebust unsigned int strlen; 30381da177e4SLinus Torvalds char *str; 30391da177e4SLinus Torvalds 3040c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3041c0eae66eSBenny Halevy if (likely(p)) 30421da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3043c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3044c0eae66eSBenny Halevy return -EIO; 30451da177e4SLinus Torvalds } 30461da177e4SLinus Torvalds 30471da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 30481da177e4SLinus Torvalds { 30498687b63aSAl Viro uint32_t bmlen; 30508687b63aSAl Viro __be32 *p; 30511da177e4SLinus Torvalds 3052c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3053c0eae66eSBenny Halevy if (unlikely(!p)) 3054c0eae66eSBenny Halevy goto out_overflow; 3055cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 30561da177e4SLinus Torvalds 3057dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3058c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3059c0eae66eSBenny Halevy if (unlikely(!p)) 3060c0eae66eSBenny Halevy goto out_overflow; 30611da177e4SLinus Torvalds if (bmlen > 0) { 30626f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3063dae100c2SFred Isaman if (bmlen > 1) { 3064dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3065dae100c2SFred Isaman if (bmlen > 2) 3066dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3067dae100c2SFred Isaman } 30681da177e4SLinus Torvalds } 30691da177e4SLinus Torvalds return 0; 3070c0eae66eSBenny Halevy out_overflow: 3071c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3072c0eae66eSBenny Halevy return -EIO; 30731da177e4SLinus Torvalds } 30741da177e4SLinus Torvalds 3075256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 30761da177e4SLinus Torvalds { 30778687b63aSAl Viro __be32 *p; 30781da177e4SLinus Torvalds 3079c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3080c0eae66eSBenny Halevy if (unlikely(!p)) 3081c0eae66eSBenny Halevy goto out_overflow; 3082cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3083256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 30841da177e4SLinus Torvalds return 0; 3085c0eae66eSBenny Halevy out_overflow: 3086c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3087c0eae66eSBenny Halevy return -EIO; 30881da177e4SLinus Torvalds } 30891da177e4SLinus Torvalds 30901da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 30911da177e4SLinus Torvalds { 30921da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 30933388bff5SRoman Borisov int ret; 30943388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 30953388bff5SRoman Borisov if (unlikely(ret < 0)) 30963388bff5SRoman Borisov return ret; 30971da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 30981da177e4SLinus Torvalds } else 3099dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3100dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3101dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 31021da177e4SLinus Torvalds return 0; 31031da177e4SLinus Torvalds } 31041da177e4SLinus Torvalds 31051da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 31061da177e4SLinus Torvalds { 31078687b63aSAl Viro __be32 *p; 3108409924e4STrond Myklebust int ret = 0; 31091da177e4SLinus Torvalds 31101da177e4SLinus Torvalds *type = 0; 31111da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 31121da177e4SLinus Torvalds return -EIO; 31131da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3114c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3115c0eae66eSBenny Halevy if (unlikely(!p)) 3116c0eae66eSBenny Halevy goto out_overflow; 3117cccddf4fSBenny Halevy *type = be32_to_cpup(p); 31181da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 31193110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 31201da177e4SLinus Torvalds return -EIO; 31211da177e4SLinus Torvalds } 31221da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3123409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 31241da177e4SLinus Torvalds } 3125bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3126409924e4STrond Myklebust return ret; 3127c0eae66eSBenny Halevy out_overflow: 3128c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3129c0eae66eSBenny Halevy return -EIO; 31301da177e4SLinus Torvalds } 31311da177e4SLinus Torvalds 3132264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3133264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3134264e6351SChuck Lever { 3135264e6351SChuck Lever __be32 *p; 3136264e6351SChuck Lever 3137264e6351SChuck Lever *type = 0; 3138264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3139264e6351SChuck Lever return -EIO; 3140264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3141264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3142264e6351SChuck Lever if (unlikely(!p)) 3143264e6351SChuck Lever goto out_overflow; 3144264e6351SChuck Lever *type = be32_to_cpup(p); 3145264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3146264e6351SChuck Lever } 3147264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3148264e6351SChuck Lever return 0; 3149264e6351SChuck Lever out_overflow: 3150264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3151264e6351SChuck Lever return -EIO; 3152264e6351SChuck Lever } 3153264e6351SChuck Lever 31541da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 31551da177e4SLinus Torvalds { 31568687b63aSAl Viro __be32 *p; 3157409924e4STrond Myklebust int ret = 0; 31581da177e4SLinus Torvalds 31591da177e4SLinus Torvalds *change = 0; 31601da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 31611da177e4SLinus Torvalds return -EIO; 31621da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3163c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3164c0eae66eSBenny Halevy if (unlikely(!p)) 3165c0eae66eSBenny Halevy goto out_overflow; 3166cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 31671da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3168409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 31691da177e4SLinus Torvalds } 31703110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 31711da177e4SLinus Torvalds (unsigned long long)*change); 3172409924e4STrond Myklebust return ret; 3173c0eae66eSBenny Halevy out_overflow: 3174c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3175c0eae66eSBenny Halevy return -EIO; 31761da177e4SLinus Torvalds } 31771da177e4SLinus Torvalds 31781da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 31791da177e4SLinus Torvalds { 31808687b63aSAl Viro __be32 *p; 3181409924e4STrond Myklebust int ret = 0; 31821da177e4SLinus Torvalds 31831da177e4SLinus Torvalds *size = 0; 31841da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 31851da177e4SLinus Torvalds return -EIO; 31861da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3187c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3188c0eae66eSBenny Halevy if (unlikely(!p)) 3189c0eae66eSBenny Halevy goto out_overflow; 3190cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 31911da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3192409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 31931da177e4SLinus Torvalds } 31943110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3195409924e4STrond Myklebust return ret; 3196c0eae66eSBenny Halevy out_overflow: 3197c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3198c0eae66eSBenny Halevy return -EIO; 31991da177e4SLinus Torvalds } 32001da177e4SLinus Torvalds 32011da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32021da177e4SLinus Torvalds { 32038687b63aSAl Viro __be32 *p; 32041da177e4SLinus Torvalds 32051da177e4SLinus Torvalds *res = 0; 32061da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 32071da177e4SLinus Torvalds return -EIO; 32081da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3209c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3210c0eae66eSBenny Halevy if (unlikely(!p)) 3211c0eae66eSBenny Halevy goto out_overflow; 3212cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32131da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 32141da177e4SLinus Torvalds } 32153110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 32161da177e4SLinus Torvalds return 0; 3217c0eae66eSBenny Halevy out_overflow: 3218c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3219c0eae66eSBenny Halevy return -EIO; 32201da177e4SLinus Torvalds } 32211da177e4SLinus Torvalds 32221da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32231da177e4SLinus Torvalds { 32248687b63aSAl Viro __be32 *p; 32251da177e4SLinus Torvalds 32261da177e4SLinus Torvalds *res = 0; 32271da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 32281da177e4SLinus Torvalds return -EIO; 32291da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3230c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3231c0eae66eSBenny Halevy if (unlikely(!p)) 3232c0eae66eSBenny Halevy goto out_overflow; 3233cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 32351da177e4SLinus Torvalds } 32363110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 32371da177e4SLinus Torvalds return 0; 3238c0eae66eSBenny Halevy out_overflow: 3239c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3240c0eae66eSBenny Halevy return -EIO; 32411da177e4SLinus Torvalds } 32421da177e4SLinus Torvalds 32438b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 32441da177e4SLinus Torvalds { 32458687b63aSAl Viro __be32 *p; 3246409924e4STrond Myklebust int ret = 0; 32471da177e4SLinus Torvalds 32481da177e4SLinus Torvalds fsid->major = 0; 32491da177e4SLinus Torvalds fsid->minor = 0; 32501da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 32511da177e4SLinus Torvalds return -EIO; 32521da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3253c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3254c0eae66eSBenny Halevy if (unlikely(!p)) 3255c0eae66eSBenny Halevy goto out_overflow; 32563ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3257cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 32581da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3259409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 32601da177e4SLinus Torvalds } 32613110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 32621da177e4SLinus Torvalds (unsigned long long)fsid->major, 32631da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3264409924e4STrond Myklebust return ret; 3265c0eae66eSBenny Halevy out_overflow: 3266c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3267c0eae66eSBenny Halevy return -EIO; 32681da177e4SLinus Torvalds } 32691da177e4SLinus Torvalds 32701da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32711da177e4SLinus Torvalds { 32728687b63aSAl Viro __be32 *p; 32731da177e4SLinus Torvalds 32741da177e4SLinus Torvalds *res = 60; 32751da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 32761da177e4SLinus Torvalds return -EIO; 32771da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3278c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3279c0eae66eSBenny Halevy if (unlikely(!p)) 3280c0eae66eSBenny Halevy goto out_overflow; 3281cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32821da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 32831da177e4SLinus Torvalds } 32843110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 32851da177e4SLinus Torvalds return 0; 3286c0eae66eSBenny Halevy out_overflow: 3287c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3288c0eae66eSBenny Halevy return -EIO; 32891da177e4SLinus Torvalds } 32901da177e4SLinus Torvalds 3291ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3292ae42c70aSBryan Schumaker { 3293ae42c70aSBryan Schumaker __be32 *p; 3294ae42c70aSBryan Schumaker 3295ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3296ae42c70aSBryan Schumaker return -EIO; 3297ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3298ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3299ae42c70aSBryan Schumaker if (unlikely(!p)) 3300ae42c70aSBryan Schumaker goto out_overflow; 3301ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3302ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3303ae42c70aSBryan Schumaker } 3304ae42c70aSBryan Schumaker return 0; 3305ae42c70aSBryan Schumaker out_overflow: 3306ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3307ae42c70aSBryan Schumaker return -EIO; 3308ae42c70aSBryan Schumaker } 3309ae42c70aSBryan Schumaker 3310ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3311ae42c70aSBryan Schumaker { 3312ae42c70aSBryan Schumaker __be32 *p; 3313ae42c70aSBryan Schumaker int len; 3314ae42c70aSBryan Schumaker 33157ad07353STrond Myklebust if (fh != NULL) 3316ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3317ae42c70aSBryan Schumaker 3318ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3319ae42c70aSBryan Schumaker return -EIO; 3320ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3321ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3322ae42c70aSBryan Schumaker if (unlikely(!p)) 3323ae42c70aSBryan Schumaker goto out_overflow; 3324ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3325ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3326ae42c70aSBryan Schumaker return -EIO; 3327ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3328ae42c70aSBryan Schumaker if (unlikely(!p)) 3329ae42c70aSBryan Schumaker goto out_overflow; 33307ad07353STrond Myklebust if (fh != NULL) { 3331ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 33327ad07353STrond Myklebust fh->size = len; 33337ad07353STrond Myklebust } 3334ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3335ae42c70aSBryan Schumaker } 3336ae42c70aSBryan Schumaker return 0; 3337ae42c70aSBryan Schumaker out_overflow: 3338ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3339ae42c70aSBryan Schumaker return -EIO; 3340ae42c70aSBryan Schumaker } 3341ae42c70aSBryan Schumaker 33421da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33431da177e4SLinus Torvalds { 33448687b63aSAl Viro __be32 *p; 33451da177e4SLinus Torvalds 33461da177e4SLinus Torvalds *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 33471da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 33481da177e4SLinus Torvalds return -EIO; 33491da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3350c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3351c0eae66eSBenny Halevy if (unlikely(!p)) 3352c0eae66eSBenny Halevy goto out_overflow; 3353cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33541da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 33551da177e4SLinus Torvalds } 33563110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 33571da177e4SLinus Torvalds return 0; 3358c0eae66eSBenny Halevy out_overflow: 3359c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3360c0eae66eSBenny Halevy return -EIO; 33611da177e4SLinus Torvalds } 33621da177e4SLinus Torvalds 33631da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 33641da177e4SLinus Torvalds { 33658687b63aSAl Viro __be32 *p; 3366409924e4STrond Myklebust int ret = 0; 33671da177e4SLinus Torvalds 33681da177e4SLinus Torvalds *fileid = 0; 33691da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 33701da177e4SLinus Torvalds return -EIO; 33711da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3372c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3373c0eae66eSBenny Halevy if (unlikely(!p)) 3374c0eae66eSBenny Halevy goto out_overflow; 3375cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 33761da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3377409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 33781da177e4SLinus Torvalds } 33793110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3380409924e4STrond Myklebust return ret; 3381c0eae66eSBenny Halevy out_overflow: 3382c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3383c0eae66eSBenny Halevy return -EIO; 33841da177e4SLinus Torvalds } 33851da177e4SLinus Torvalds 338699baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 338799baf625SManoj Naik { 33888687b63aSAl Viro __be32 *p; 3389409924e4STrond Myklebust int ret = 0; 339099baf625SManoj Naik 339199baf625SManoj Naik *fileid = 0; 339299baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 339399baf625SManoj Naik return -EIO; 339499baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3395c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3396c0eae66eSBenny Halevy if (unlikely(!p)) 3397c0eae66eSBenny Halevy goto out_overflow; 3398cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 339999baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 340028331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 340199baf625SManoj Naik } 34023110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3403409924e4STrond Myklebust return ret; 3404c0eae66eSBenny Halevy out_overflow: 3405c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3406c0eae66eSBenny Halevy return -EIO; 340799baf625SManoj Naik } 340899baf625SManoj Naik 34091da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34101da177e4SLinus Torvalds { 34118687b63aSAl Viro __be32 *p; 34121da177e4SLinus Torvalds int status = 0; 34131da177e4SLinus Torvalds 34141da177e4SLinus Torvalds *res = 0; 34151da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 34161da177e4SLinus Torvalds return -EIO; 34171da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3418c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3419c0eae66eSBenny Halevy if (unlikely(!p)) 3420c0eae66eSBenny Halevy goto out_overflow; 3421cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34221da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 34231da177e4SLinus Torvalds } 34243110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 34251da177e4SLinus Torvalds return status; 3426c0eae66eSBenny Halevy out_overflow: 3427c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3428c0eae66eSBenny Halevy return -EIO; 34291da177e4SLinus Torvalds } 34301da177e4SLinus Torvalds 34311da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34321da177e4SLinus Torvalds { 34338687b63aSAl Viro __be32 *p; 34341da177e4SLinus Torvalds int status = 0; 34351da177e4SLinus Torvalds 34361da177e4SLinus Torvalds *res = 0; 34371da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 34381da177e4SLinus Torvalds return -EIO; 34391da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3440c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3441c0eae66eSBenny Halevy if (unlikely(!p)) 3442c0eae66eSBenny Halevy goto out_overflow; 3443cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34441da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 34451da177e4SLinus Torvalds } 34463110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 34471da177e4SLinus Torvalds return status; 3448c0eae66eSBenny Halevy out_overflow: 3449c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3450c0eae66eSBenny Halevy return -EIO; 34511da177e4SLinus Torvalds } 34521da177e4SLinus Torvalds 34531da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34541da177e4SLinus Torvalds { 34558687b63aSAl Viro __be32 *p; 34561da177e4SLinus Torvalds int status = 0; 34571da177e4SLinus Torvalds 34581da177e4SLinus Torvalds *res = 0; 34591da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 34601da177e4SLinus Torvalds return -EIO; 34611da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3462c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3463c0eae66eSBenny Halevy if (unlikely(!p)) 3464c0eae66eSBenny Halevy goto out_overflow; 3465cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34661da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 34671da177e4SLinus Torvalds } 34683110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 34691da177e4SLinus Torvalds return status; 3470c0eae66eSBenny Halevy out_overflow: 3471c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3472c0eae66eSBenny Halevy return -EIO; 34731da177e4SLinus Torvalds } 34741da177e4SLinus Torvalds 34757aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 34767aaa0b3bSManoj Naik { 3477464ad6b1SChuck Lever u32 n; 34788687b63aSAl Viro __be32 *p; 34797aaa0b3bSManoj Naik int status = 0; 34807aaa0b3bSManoj Naik 3481c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3482c0eae66eSBenny Halevy if (unlikely(!p)) 3483c0eae66eSBenny Halevy goto out_overflow; 3484cccddf4fSBenny Halevy n = be32_to_cpup(p); 348533a43f28SAndy Adamson if (n == 0) 348633a43f28SAndy Adamson goto root_path; 348702a2976cSChuck Lever dprintk("pathname4: "); 34887aaa0b3bSManoj Naik path->ncomponents = 0; 34897aaa0b3bSManoj Naik while (path->ncomponents < n) { 34907aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 34917aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 34927aaa0b3bSManoj Naik if (unlikely(status != 0)) 34937aaa0b3bSManoj Naik goto out_eio; 349495a13f7bSTrond Myklebust ifdebug (XDR) 349502a2976cSChuck Lever pr_cont("%s%.*s ", 349602a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 349702a2976cSChuck Lever component->len, component->data); 34987aaa0b3bSManoj Naik if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 34997aaa0b3bSManoj Naik path->ncomponents++; 35007aaa0b3bSManoj Naik else { 35017aaa0b3bSManoj Naik dprintk("cannot parse %d components in path\n", n); 35027aaa0b3bSManoj Naik goto out_eio; 35037aaa0b3bSManoj Naik } 35047aaa0b3bSManoj Naik } 35057aaa0b3bSManoj Naik out: 35067aaa0b3bSManoj Naik return status; 350733a43f28SAndy Adamson root_path: 350833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 350933a43f28SAndy Adamson path->ncomponents = 1; 351033a43f28SAndy Adamson path->components[0].len=0; 351133a43f28SAndy Adamson path->components[0].data=NULL; 351202a2976cSChuck Lever dprintk("pathname4: /\n"); 351333a43f28SAndy Adamson goto out; 35147aaa0b3bSManoj Naik out_eio: 35157aaa0b3bSManoj Naik dprintk(" status %d", status); 35167aaa0b3bSManoj Naik status = -EIO; 35177aaa0b3bSManoj Naik goto out; 3518c0eae66eSBenny Halevy out_overflow: 3519c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3520c0eae66eSBenny Halevy return -EIO; 35217aaa0b3bSManoj Naik } 35227aaa0b3bSManoj Naik 35237aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3524683b57b4STrond Myklebust { 3525683b57b4STrond Myklebust int n; 35268687b63aSAl Viro __be32 *p; 3527683b57b4STrond Myklebust int status = -EIO; 3528683b57b4STrond Myklebust 3529683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3530683b57b4STrond Myklebust goto out; 3531683b57b4STrond Myklebust status = 0; 3532683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3533683b57b4STrond Myklebust goto out; 35348b7e3f49STrond Myklebust status = -EIO; 35358b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 35368b7e3f49STrond Myklebust if (unlikely(res == NULL)) 35378b7e3f49STrond Myklebust goto out; 353802a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 35397aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3540683b57b4STrond Myklebust if (unlikely(status != 0)) 3541683b57b4STrond Myklebust goto out; 3542c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3543c0eae66eSBenny Halevy if (unlikely(!p)) 3544c0eae66eSBenny Halevy goto out_overflow; 3545cccddf4fSBenny Halevy n = be32_to_cpup(p); 3546683b57b4STrond Myklebust if (n <= 0) 3547683b57b4STrond Myklebust goto out_eio; 3548683b57b4STrond Myklebust res->nlocations = 0; 3549683b57b4STrond Myklebust while (res->nlocations < n) { 3550464ad6b1SChuck Lever u32 m; 35517aaa0b3bSManoj Naik struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 3552683b57b4STrond Myklebust 3553c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3554c0eae66eSBenny Halevy if (unlikely(!p)) 3555c0eae66eSBenny Halevy goto out_overflow; 3556cccddf4fSBenny Halevy m = be32_to_cpup(p); 35577aaa0b3bSManoj Naik 35587aaa0b3bSManoj Naik loc->nservers = 0; 355902a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 35607aaa0b3bSManoj Naik while (loc->nservers < m) { 35617aaa0b3bSManoj Naik struct nfs4_string *server = &loc->servers[loc->nservers]; 35627aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &server->len, &server->data); 3563683b57b4STrond Myklebust if (unlikely(status != 0)) 3564683b57b4STrond Myklebust goto out_eio; 35657aaa0b3bSManoj Naik dprintk("%s ", server->data); 35667aaa0b3bSManoj Naik if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) 35677aaa0b3bSManoj Naik loc->nservers++; 35687aaa0b3bSManoj Naik else { 3569464ad6b1SChuck Lever unsigned int i; 3570464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3571464ad6b1SChuck Lever "returned for location %u\n", 35723110ff80SHarvey Harrison __func__, 3573464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3574464ad6b1SChuck Lever m, res->nlocations); 35757aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 35762e42c3e2STrond Myklebust unsigned int len; 35777aaa0b3bSManoj Naik char *data; 35787aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3579683b57b4STrond Myklebust if (unlikely(status != 0)) 3580683b57b4STrond Myklebust goto out_eio; 35817aaa0b3bSManoj Naik } 35827aaa0b3bSManoj Naik } 35837aaa0b3bSManoj Naik } 35847aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 35857aaa0b3bSManoj Naik if (unlikely(status != 0)) 35867aaa0b3bSManoj Naik goto out_eio; 35877aaa0b3bSManoj Naik if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) 3588683b57b4STrond Myklebust res->nlocations++; 3589683b57b4STrond Myklebust } 3590409924e4STrond Myklebust if (res->nlocations != 0) 359181934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3592683b57b4STrond Myklebust out: 35933110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3594683b57b4STrond Myklebust return status; 3595c0eae66eSBenny Halevy out_overflow: 3596c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3597683b57b4STrond Myklebust out_eio: 3598683b57b4STrond Myklebust status = -EIO; 3599683b57b4STrond Myklebust goto out; 3600683b57b4STrond Myklebust } 3601683b57b4STrond Myklebust 36021da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36031da177e4SLinus Torvalds { 36048687b63aSAl Viro __be32 *p; 36051da177e4SLinus Torvalds int status = 0; 36061da177e4SLinus Torvalds 36071da177e4SLinus Torvalds *res = 0; 36081da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 36091da177e4SLinus Torvalds return -EIO; 36101da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3611c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3612c0eae66eSBenny Halevy if (unlikely(!p)) 3613c0eae66eSBenny Halevy goto out_overflow; 3614cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36151da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 36161da177e4SLinus Torvalds } 36173110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 36181da177e4SLinus Torvalds return status; 3619c0eae66eSBenny Halevy out_overflow: 3620c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3621c0eae66eSBenny Halevy return -EIO; 36221da177e4SLinus Torvalds } 36231da177e4SLinus Torvalds 36241da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 36251da177e4SLinus Torvalds { 36268687b63aSAl Viro __be32 *p; 36271da177e4SLinus Torvalds int status = 0; 36281da177e4SLinus Torvalds 36291da177e4SLinus Torvalds *maxlink = 1; 36301da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 36311da177e4SLinus Torvalds return -EIO; 36321da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3633c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3634c0eae66eSBenny Halevy if (unlikely(!p)) 3635c0eae66eSBenny Halevy goto out_overflow; 3636cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 36371da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 36381da177e4SLinus Torvalds } 36393110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 36401da177e4SLinus Torvalds return status; 3641c0eae66eSBenny Halevy out_overflow: 3642c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3643c0eae66eSBenny Halevy return -EIO; 36441da177e4SLinus Torvalds } 36451da177e4SLinus Torvalds 36461da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 36471da177e4SLinus Torvalds { 36488687b63aSAl Viro __be32 *p; 36491da177e4SLinus Torvalds int status = 0; 36501da177e4SLinus Torvalds 36511da177e4SLinus Torvalds *maxname = 1024; 36521da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 36531da177e4SLinus Torvalds return -EIO; 36541da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3655c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3656c0eae66eSBenny Halevy if (unlikely(!p)) 3657c0eae66eSBenny Halevy goto out_overflow; 3658cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 36591da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 36601da177e4SLinus Torvalds } 36613110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 36621da177e4SLinus Torvalds return status; 3663c0eae66eSBenny Halevy out_overflow: 3664c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3665c0eae66eSBenny Halevy return -EIO; 36661da177e4SLinus Torvalds } 36671da177e4SLinus Torvalds 36681da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36691da177e4SLinus Torvalds { 36708687b63aSAl Viro __be32 *p; 36711da177e4SLinus Torvalds int status = 0; 36721da177e4SLinus Torvalds 36731da177e4SLinus Torvalds *res = 1024; 36741da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 36751da177e4SLinus Torvalds return -EIO; 36761da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 36771da177e4SLinus Torvalds uint64_t maxread; 3678c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3679c0eae66eSBenny Halevy if (unlikely(!p)) 3680c0eae66eSBenny Halevy goto out_overflow; 3681cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 36821da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 36831da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 36841da177e4SLinus Torvalds *res = (uint32_t)maxread; 36851da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 36861da177e4SLinus Torvalds } 36873110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 36881da177e4SLinus Torvalds return status; 3689c0eae66eSBenny Halevy out_overflow: 3690c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3691c0eae66eSBenny Halevy return -EIO; 36921da177e4SLinus Torvalds } 36931da177e4SLinus Torvalds 36941da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36951da177e4SLinus Torvalds { 36968687b63aSAl Viro __be32 *p; 36971da177e4SLinus Torvalds int status = 0; 36981da177e4SLinus Torvalds 36991da177e4SLinus Torvalds *res = 1024; 37001da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 37011da177e4SLinus Torvalds return -EIO; 37021da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 37031da177e4SLinus Torvalds uint64_t maxwrite; 3704c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3705c0eae66eSBenny Halevy if (unlikely(!p)) 3706c0eae66eSBenny Halevy goto out_overflow; 3707cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 37081da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 37091da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 37101da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 37111da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 37121da177e4SLinus Torvalds } 37133110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 37141da177e4SLinus Torvalds return status; 3715c0eae66eSBenny Halevy out_overflow: 3716c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3717c0eae66eSBenny Halevy return -EIO; 37181da177e4SLinus Torvalds } 37191da177e4SLinus Torvalds 3720bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 37211da177e4SLinus Torvalds { 3722bca79478STrond Myklebust uint32_t tmp; 37238687b63aSAl Viro __be32 *p; 3724409924e4STrond Myklebust int ret = 0; 37251da177e4SLinus Torvalds 37261da177e4SLinus Torvalds *mode = 0; 37271da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 37281da177e4SLinus Torvalds return -EIO; 37291da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3730c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3731c0eae66eSBenny Halevy if (unlikely(!p)) 3732c0eae66eSBenny Halevy goto out_overflow; 3733cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3734bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 37351da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3736409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 37371da177e4SLinus Torvalds } 37383110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3739409924e4STrond Myklebust return ret; 3740c0eae66eSBenny Halevy out_overflow: 3741c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3742c0eae66eSBenny Halevy return -EIO; 37431da177e4SLinus Torvalds } 37441da177e4SLinus Torvalds 37451da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 37461da177e4SLinus Torvalds { 37478687b63aSAl Viro __be32 *p; 3748409924e4STrond Myklebust int ret = 0; 37491da177e4SLinus Torvalds 37501da177e4SLinus Torvalds *nlink = 1; 37511da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 37521da177e4SLinus Torvalds return -EIO; 37531da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3754c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3755c0eae66eSBenny Halevy if (unlikely(!p)) 3756c0eae66eSBenny Halevy goto out_overflow; 3757cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 37581da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3759409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 37601da177e4SLinus Torvalds } 37613110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3762409924e4STrond Myklebust return ret; 3763c0eae66eSBenny Halevy out_overflow: 3764c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3765c0eae66eSBenny Halevy return -EIO; 37661da177e4SLinus Torvalds } 37671da177e4SLinus Torvalds 376880e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 37696926afd1STrond Myklebust const struct nfs_server *server, uint32_t *uid, 37706926afd1STrond Myklebust struct nfs4_string *owner_name) 37711da177e4SLinus Torvalds { 37728687b63aSAl Viro uint32_t len; 37738687b63aSAl Viro __be32 *p; 3774409924e4STrond Myklebust int ret = 0; 37751da177e4SLinus Torvalds 37761da177e4SLinus Torvalds *uid = -2; 37771da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 37781da177e4SLinus Torvalds return -EIO; 37791da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3780c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3781c0eae66eSBenny Halevy if (unlikely(!p)) 3782c0eae66eSBenny Halevy goto out_overflow; 3783cccddf4fSBenny Halevy len = be32_to_cpup(p); 3784c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3785c0eae66eSBenny Halevy if (unlikely(!p)) 3786c0eae66eSBenny Halevy goto out_overflow; 37876926afd1STrond Myklebust if (owner_name != NULL) { 37886926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 37896926afd1STrond Myklebust if (owner_name->data != NULL) { 37906926afd1STrond Myklebust owner_name->len = len; 37916926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 37926926afd1STrond Myklebust } 379380e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3794e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3795409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3796409924e4STrond Myklebust else 37971da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 37983110ff80SHarvey Harrison __func__); 37991da177e4SLinus Torvalds } else 3800fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 38013110ff80SHarvey Harrison __func__, len); 38021da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 38031da177e4SLinus Torvalds } 38043110ff80SHarvey Harrison dprintk("%s: uid=%d\n", __func__, (int)*uid); 3805409924e4STrond Myklebust return ret; 3806c0eae66eSBenny Halevy out_overflow: 3807c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3808c0eae66eSBenny Halevy return -EIO; 38091da177e4SLinus Torvalds } 38101da177e4SLinus Torvalds 381180e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 38126926afd1STrond Myklebust const struct nfs_server *server, uint32_t *gid, 38136926afd1STrond Myklebust struct nfs4_string *group_name) 38141da177e4SLinus Torvalds { 38158687b63aSAl Viro uint32_t len; 38168687b63aSAl Viro __be32 *p; 3817409924e4STrond Myklebust int ret = 0; 38181da177e4SLinus Torvalds 38191da177e4SLinus Torvalds *gid = -2; 38201da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 38211da177e4SLinus Torvalds return -EIO; 38221da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3823c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3824c0eae66eSBenny Halevy if (unlikely(!p)) 3825c0eae66eSBenny Halevy goto out_overflow; 3826cccddf4fSBenny Halevy len = be32_to_cpup(p); 3827c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3828c0eae66eSBenny Halevy if (unlikely(!p)) 3829c0eae66eSBenny Halevy goto out_overflow; 38306926afd1STrond Myklebust if (group_name != NULL) { 38316926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 38326926afd1STrond Myklebust if (group_name->data != NULL) { 38336926afd1STrond Myklebust group_name->len = len; 38346926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 38356926afd1STrond Myklebust } 383680e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3837e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3838409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3839409924e4STrond Myklebust else 38401da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 38413110ff80SHarvey Harrison __func__); 38421da177e4SLinus Torvalds } else 3843fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 38443110ff80SHarvey Harrison __func__, len); 38451da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 38461da177e4SLinus Torvalds } 38473110ff80SHarvey Harrison dprintk("%s: gid=%d\n", __func__, (int)*gid); 3848409924e4STrond Myklebust return ret; 3849c0eae66eSBenny Halevy out_overflow: 3850c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3851c0eae66eSBenny Halevy return -EIO; 38521da177e4SLinus Torvalds } 38531da177e4SLinus Torvalds 38541da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 38551da177e4SLinus Torvalds { 38568687b63aSAl Viro uint32_t major = 0, minor = 0; 38578687b63aSAl Viro __be32 *p; 3858409924e4STrond Myklebust int ret = 0; 38591da177e4SLinus Torvalds 38601da177e4SLinus Torvalds *rdev = MKDEV(0,0); 38611da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 38621da177e4SLinus Torvalds return -EIO; 38631da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 38641da177e4SLinus Torvalds dev_t tmp; 38651da177e4SLinus Torvalds 3866c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3867c0eae66eSBenny Halevy if (unlikely(!p)) 3868c0eae66eSBenny Halevy goto out_overflow; 38696f723f77SBenny Halevy major = be32_to_cpup(p++); 3870cccddf4fSBenny Halevy minor = be32_to_cpup(p); 38711da177e4SLinus Torvalds tmp = MKDEV(major, minor); 38721da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 38731da177e4SLinus Torvalds *rdev = tmp; 38741da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3875409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 38761da177e4SLinus Torvalds } 38773110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3878409924e4STrond Myklebust return ret; 3879c0eae66eSBenny Halevy out_overflow: 3880c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3881c0eae66eSBenny Halevy return -EIO; 38821da177e4SLinus Torvalds } 38831da177e4SLinus Torvalds 38841da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38851da177e4SLinus Torvalds { 38868687b63aSAl Viro __be32 *p; 38871da177e4SLinus Torvalds int status = 0; 38881da177e4SLinus Torvalds 38891da177e4SLinus Torvalds *res = 0; 38901da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 38911da177e4SLinus Torvalds return -EIO; 38921da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3893c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3894c0eae66eSBenny Halevy if (unlikely(!p)) 3895c0eae66eSBenny Halevy goto out_overflow; 3896cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38971da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 38981da177e4SLinus Torvalds } 38993110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 39001da177e4SLinus Torvalds return status; 3901c0eae66eSBenny Halevy out_overflow: 3902c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3903c0eae66eSBenny Halevy return -EIO; 39041da177e4SLinus Torvalds } 39051da177e4SLinus Torvalds 39061da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39071da177e4SLinus Torvalds { 39088687b63aSAl Viro __be32 *p; 39091da177e4SLinus Torvalds int status = 0; 39101da177e4SLinus Torvalds 39111da177e4SLinus Torvalds *res = 0; 39121da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 39131da177e4SLinus Torvalds return -EIO; 39141da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3915c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3916c0eae66eSBenny Halevy if (unlikely(!p)) 3917c0eae66eSBenny Halevy goto out_overflow; 3918cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39191da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 39201da177e4SLinus Torvalds } 39213110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 39221da177e4SLinus Torvalds return status; 3923c0eae66eSBenny Halevy out_overflow: 3924c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3925c0eae66eSBenny Halevy return -EIO; 39261da177e4SLinus Torvalds } 39271da177e4SLinus Torvalds 39281da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39291da177e4SLinus Torvalds { 39308687b63aSAl Viro __be32 *p; 39311da177e4SLinus Torvalds int status = 0; 39321da177e4SLinus Torvalds 39331da177e4SLinus Torvalds *res = 0; 39341da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 39351da177e4SLinus Torvalds return -EIO; 39361da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 3937c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3938c0eae66eSBenny Halevy if (unlikely(!p)) 3939c0eae66eSBenny Halevy goto out_overflow; 3940cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39411da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 39421da177e4SLinus Torvalds } 39433110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 39441da177e4SLinus Torvalds return status; 3945c0eae66eSBenny Halevy out_overflow: 3946c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3947c0eae66eSBenny Halevy return -EIO; 39481da177e4SLinus Torvalds } 39491da177e4SLinus Torvalds 39501da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 39511da177e4SLinus Torvalds { 39528687b63aSAl Viro __be32 *p; 3953409924e4STrond Myklebust int ret = 0; 39541da177e4SLinus Torvalds 39551da177e4SLinus Torvalds *used = 0; 39561da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 39571da177e4SLinus Torvalds return -EIO; 39581da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 3959c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3960c0eae66eSBenny Halevy if (unlikely(!p)) 3961c0eae66eSBenny Halevy goto out_overflow; 3962cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 39631da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 3964409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 39651da177e4SLinus Torvalds } 39663110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 39671da177e4SLinus Torvalds (unsigned long long)*used); 3968409924e4STrond Myklebust return ret; 3969c0eae66eSBenny Halevy out_overflow: 3970c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3971c0eae66eSBenny Halevy return -EIO; 39721da177e4SLinus Torvalds } 39731da177e4SLinus Torvalds 39741da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 39751da177e4SLinus Torvalds { 39768687b63aSAl Viro __be32 *p; 39771da177e4SLinus Torvalds uint64_t sec; 39781da177e4SLinus Torvalds uint32_t nsec; 39791da177e4SLinus Torvalds 3980c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3981c0eae66eSBenny Halevy if (unlikely(!p)) 3982c0eae66eSBenny Halevy goto out_overflow; 39833ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 3984cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 39851da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 39861da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 39871da177e4SLinus Torvalds return 0; 3988c0eae66eSBenny Halevy out_overflow: 3989c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3990c0eae66eSBenny Halevy return -EIO; 39911da177e4SLinus Torvalds } 39921da177e4SLinus Torvalds 39931da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39941da177e4SLinus Torvalds { 39951da177e4SLinus Torvalds int status = 0; 39961da177e4SLinus Torvalds 39971da177e4SLinus Torvalds time->tv_sec = 0; 39981da177e4SLinus Torvalds time->tv_nsec = 0; 39991da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 40001da177e4SLinus Torvalds return -EIO; 40011da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 40021da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4003409924e4STrond Myklebust if (status == 0) 4004409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 40051da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 40061da177e4SLinus Torvalds } 40073110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 40081da177e4SLinus Torvalds return status; 40091da177e4SLinus Torvalds } 40101da177e4SLinus Torvalds 40111da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40121da177e4SLinus Torvalds { 40131da177e4SLinus Torvalds int status = 0; 40141da177e4SLinus Torvalds 40151da177e4SLinus Torvalds time->tv_sec = 0; 40161da177e4SLinus Torvalds time->tv_nsec = 0; 40171da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 40181da177e4SLinus Torvalds return -EIO; 40191da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 40201da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4021409924e4STrond Myklebust if (status == 0) 4022409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 40231da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 40241da177e4SLinus Torvalds } 40253110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 40261da177e4SLinus Torvalds return status; 40271da177e4SLinus Torvalds } 40281da177e4SLinus Torvalds 402955b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 403055b6e774SRicardo Labiaga struct timespec *time) 403155b6e774SRicardo Labiaga { 403255b6e774SRicardo Labiaga int status = 0; 403355b6e774SRicardo Labiaga 403455b6e774SRicardo Labiaga time->tv_sec = 0; 403555b6e774SRicardo Labiaga time->tv_nsec = 0; 403655b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 403755b6e774SRicardo Labiaga return -EIO; 403855b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 403955b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 404055b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 404155b6e774SRicardo Labiaga } 404255b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 404355b6e774SRicardo Labiaga (long)time->tv_nsec); 404455b6e774SRicardo Labiaga return status; 404555b6e774SRicardo Labiaga } 404655b6e774SRicardo Labiaga 40471da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40481da177e4SLinus Torvalds { 40491da177e4SLinus Torvalds int status = 0; 40501da177e4SLinus Torvalds 40511da177e4SLinus Torvalds time->tv_sec = 0; 40521da177e4SLinus Torvalds time->tv_nsec = 0; 40531da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 40541da177e4SLinus Torvalds return -EIO; 40551da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 40561da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4057409924e4STrond Myklebust if (status == 0) 4058409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 40591da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 40601da177e4SLinus Torvalds } 40613110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 40621da177e4SLinus Torvalds return status; 40631da177e4SLinus Torvalds } 40641da177e4SLinus Torvalds 4065256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 40661da177e4SLinus Torvalds { 40671da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4068256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 40691da177e4SLinus Torvalds 40701da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4071fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4072fe82a183SChuck Lever "%u %c %u\n", 40733110ff80SHarvey Harrison __func__, 40741da177e4SLinus Torvalds attrwords << 2, 40751da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 40761da177e4SLinus Torvalds nwords << 2); 40771da177e4SLinus Torvalds return -EIO; 40781da177e4SLinus Torvalds } 40791da177e4SLinus Torvalds return 0; 40801da177e4SLinus Torvalds } 40811da177e4SLinus Torvalds 40821da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 40831da177e4SLinus Torvalds { 40848687b63aSAl Viro __be32 *p; 40851da177e4SLinus Torvalds 4086c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4087c0eae66eSBenny Halevy if (unlikely(!p)) 4088c0eae66eSBenny Halevy goto out_overflow; 40896f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 40903ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4091cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 40921da177e4SLinus Torvalds return 0; 4093c0eae66eSBenny Halevy out_overflow: 4094c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4095c0eae66eSBenny Halevy return -EIO; 40961da177e4SLinus Torvalds } 40971da177e4SLinus Torvalds 40981da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 40991da177e4SLinus Torvalds { 41008687b63aSAl Viro __be32 *p; 41011da177e4SLinus Torvalds uint32_t supp, acc; 41021da177e4SLinus Torvalds int status; 41031da177e4SLinus Torvalds 41041da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 41051da177e4SLinus Torvalds if (status) 41061da177e4SLinus Torvalds return status; 4107c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4108c0eae66eSBenny Halevy if (unlikely(!p)) 4109c0eae66eSBenny Halevy goto out_overflow; 41106f723f77SBenny Halevy supp = be32_to_cpup(p++); 4111cccddf4fSBenny Halevy acc = be32_to_cpup(p); 41121da177e4SLinus Torvalds access->supported = supp; 41131da177e4SLinus Torvalds access->access = acc; 41141da177e4SLinus Torvalds return 0; 4115c0eae66eSBenny Halevy out_overflow: 4116c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4117c0eae66eSBenny Halevy return -EIO; 41181da177e4SLinus Torvalds } 41191da177e4SLinus Torvalds 412007d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 41211da177e4SLinus Torvalds { 41228687b63aSAl Viro __be32 *p; 412307d30434SBenny Halevy 412407d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 412507d30434SBenny Halevy if (likely(p)) { 412607d30434SBenny Halevy memcpy(buf, p, len); 412707d30434SBenny Halevy return 0; 412807d30434SBenny Halevy } 412907d30434SBenny Halevy print_overflow_msg(__func__, xdr); 413007d30434SBenny Halevy return -EIO; 413107d30434SBenny Halevy } 413207d30434SBenny Halevy 413307d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 413407d30434SBenny Halevy { 41352d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 41361da177e4SLinus Torvalds } 41371da177e4SLinus Torvalds 41381da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 41391da177e4SLinus Torvalds { 41401da177e4SLinus Torvalds int status; 41411da177e4SLinus Torvalds 41421da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4143c1d51931STrond Myklebust if (status != -EIO) 4144c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 414507d30434SBenny Halevy if (!status) 414607d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 41471da177e4SLinus Torvalds return status; 41481da177e4SLinus Torvalds } 41491da177e4SLinus Torvalds 4150db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4151db942bbdSBenny Halevy { 4152cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 41531da177e4SLinus Torvalds } 41541da177e4SLinus Torvalds 41552f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 41562f2c63bcSTrond Myklebust { 41572f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 41582f2c63bcSTrond Myklebust } 41592f2c63bcSTrond Myklebust 41600b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 41611da177e4SLinus Torvalds { 41621da177e4SLinus Torvalds int status; 41631da177e4SLinus Torvalds 41641da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4165db942bbdSBenny Halevy if (!status) 41662f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 41671da177e4SLinus Torvalds return status; 41681da177e4SLinus Torvalds } 41691da177e4SLinus Torvalds 41701da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 41711da177e4SLinus Torvalds { 41728687b63aSAl Viro __be32 *p; 41731da177e4SLinus Torvalds uint32_t bmlen; 41741da177e4SLinus Torvalds int status; 41751da177e4SLinus Torvalds 41761da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 41771da177e4SLinus Torvalds if (status) 41781da177e4SLinus Torvalds return status; 41791da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 41801da177e4SLinus Torvalds return status; 4181c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4182c0eae66eSBenny Halevy if (unlikely(!p)) 4183c0eae66eSBenny Halevy goto out_overflow; 4184cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4185c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4186c0eae66eSBenny Halevy if (likely(p)) 41871da177e4SLinus Torvalds return 0; 4188c0eae66eSBenny Halevy out_overflow: 4189c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4190c0eae66eSBenny Halevy return -EIO; 41911da177e4SLinus Torvalds } 41921da177e4SLinus Torvalds 41931da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 41941da177e4SLinus Torvalds { 4195256e48bbSTrond Myklebust unsigned int savep; 4196dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41971da177e4SLinus Torvalds int status; 41981da177e4SLinus Torvalds 41991da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42001da177e4SLinus Torvalds goto xdr_error; 42011da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42021da177e4SLinus Torvalds goto xdr_error; 42031da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42041da177e4SLinus Torvalds goto xdr_error; 42051da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 42061da177e4SLinus Torvalds goto xdr_error; 4207264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4208264e6351SChuck Lever &res->fh_expire_type)) != 0) 4209264e6351SChuck Lever goto xdr_error; 42101da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 42111da177e4SLinus Torvalds goto xdr_error; 42121da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 42131da177e4SLinus Torvalds goto xdr_error; 42141da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 42151da177e4SLinus Torvalds goto xdr_error; 42161da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42171da177e4SLinus Torvalds xdr_error: 42183110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42191da177e4SLinus Torvalds return status; 42201da177e4SLinus Torvalds } 42211da177e4SLinus Torvalds 42221da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 42231da177e4SLinus Torvalds { 4224256e48bbSTrond Myklebust unsigned int savep; 4225dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 42261da177e4SLinus Torvalds int status; 42271da177e4SLinus Torvalds 42281da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42291da177e4SLinus Torvalds goto xdr_error; 42301da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42311da177e4SLinus Torvalds goto xdr_error; 42321da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42331da177e4SLinus Torvalds goto xdr_error; 42341da177e4SLinus Torvalds 42351da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 42361da177e4SLinus Torvalds goto xdr_error; 42371da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 42381da177e4SLinus Torvalds goto xdr_error; 42391da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 42401da177e4SLinus Torvalds goto xdr_error; 42411da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 42421da177e4SLinus Torvalds goto xdr_error; 42431da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 42441da177e4SLinus Torvalds goto xdr_error; 42451da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 42461da177e4SLinus Torvalds goto xdr_error; 42471da177e4SLinus Torvalds 42481da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42491da177e4SLinus Torvalds xdr_error: 42503110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42511da177e4SLinus Torvalds return status; 42521da177e4SLinus Torvalds } 42531da177e4SLinus Torvalds 42541da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 42551da177e4SLinus Torvalds { 4256256e48bbSTrond Myklebust unsigned int savep; 4257dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 42581da177e4SLinus Torvalds int status; 42591da177e4SLinus Torvalds 42601da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42611da177e4SLinus Torvalds goto xdr_error; 42621da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42631da177e4SLinus Torvalds goto xdr_error; 42641da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42651da177e4SLinus Torvalds goto xdr_error; 42661da177e4SLinus Torvalds 42671da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 42681da177e4SLinus Torvalds goto xdr_error; 42691da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 42701da177e4SLinus Torvalds goto xdr_error; 42711da177e4SLinus Torvalds 42721da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42731da177e4SLinus Torvalds xdr_error: 42743110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42751da177e4SLinus Torvalds return status; 42761da177e4SLinus Torvalds } 42771da177e4SLinus Torvalds 427888034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 427988034c3dSAndy Adamson uint32_t *bitmap, 428088034c3dSAndy Adamson uint64_t *res, 428188034c3dSAndy Adamson uint32_t hint_bit) 428288034c3dSAndy Adamson { 428388034c3dSAndy Adamson __be32 *p; 428488034c3dSAndy Adamson 428588034c3dSAndy Adamson *res = 0; 428688034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 428788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 428888034c3dSAndy Adamson if (unlikely(!p)) 428988034c3dSAndy Adamson goto out_overflow; 429088034c3dSAndy Adamson xdr_decode_hyper(p, res); 429188034c3dSAndy Adamson } 429288034c3dSAndy Adamson return 0; 429388034c3dSAndy Adamson out_overflow: 429488034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 429588034c3dSAndy Adamson return -EIO; 429688034c3dSAndy Adamson } 429788034c3dSAndy Adamson 429888034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 429988034c3dSAndy Adamson struct nfs4_threshold *res) 430088034c3dSAndy Adamson { 4301256e48bbSTrond Myklebust __be32 *p; 4302256e48bbSTrond Myklebust unsigned int savep; 430388034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 430488034c3dSAndy Adamson int status; 430588034c3dSAndy Adamson 430688034c3dSAndy Adamson /* layout type */ 430788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 430888034c3dSAndy Adamson if (unlikely(!p)) { 430988034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 431088034c3dSAndy Adamson return -EIO; 431188034c3dSAndy Adamson } 431288034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 431388034c3dSAndy Adamson 431488034c3dSAndy Adamson /* thi_hintset bitmap */ 431588034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 431688034c3dSAndy Adamson if (status < 0) 431788034c3dSAndy Adamson goto xdr_error; 431888034c3dSAndy Adamson 431988034c3dSAndy Adamson /* thi_hintlist length */ 432088034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 432188034c3dSAndy Adamson if (status < 0) 432288034c3dSAndy Adamson goto xdr_error; 432388034c3dSAndy Adamson /* thi_hintlist */ 432488034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 432588034c3dSAndy Adamson if (status < 0) 432688034c3dSAndy Adamson goto xdr_error; 432788034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 432888034c3dSAndy Adamson if (status < 0) 432988034c3dSAndy Adamson goto xdr_error; 433088034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 433188034c3dSAndy Adamson THRESHOLD_RD_IO); 433288034c3dSAndy Adamson if (status < 0) 433388034c3dSAndy Adamson goto xdr_error; 433488034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 433588034c3dSAndy Adamson THRESHOLD_WR_IO); 433688034c3dSAndy Adamson if (status < 0) 433788034c3dSAndy Adamson goto xdr_error; 433888034c3dSAndy Adamson 433988034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 434088034c3dSAndy Adamson res->bm = bitmap[0]; 434188034c3dSAndy Adamson 434288034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 434388034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 434488034c3dSAndy Adamson res->wr_io_sz); 434588034c3dSAndy Adamson xdr_error: 434688034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 434788034c3dSAndy Adamson return status; 434888034c3dSAndy Adamson } 434988034c3dSAndy Adamson 435088034c3dSAndy Adamson /* 435188034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 435288034c3dSAndy Adamson */ 435388034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 435488034c3dSAndy Adamson uint32_t *bitmap, 435588034c3dSAndy Adamson struct nfs4_threshold *res) 435688034c3dSAndy Adamson { 435788034c3dSAndy Adamson __be32 *p; 435888034c3dSAndy Adamson int status = 0; 435988034c3dSAndy Adamson uint32_t num; 436088034c3dSAndy Adamson 436188034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 436288034c3dSAndy Adamson return -EIO; 4363029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 43641549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 43651549210fSTrond Myklebust if (unlikely(res == NULL)) 43661549210fSTrond Myklebust return -EREMOTEIO; 436788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 436888034c3dSAndy Adamson if (unlikely(!p)) 436988034c3dSAndy Adamson goto out_overflow; 437088034c3dSAndy Adamson num = be32_to_cpup(p); 437188034c3dSAndy Adamson if (num == 0) 437288034c3dSAndy Adamson return 0; 437388034c3dSAndy Adamson if (num > 1) 437488034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 437588034c3dSAndy Adamson "drivers per filesystem not supported\n", 437688034c3dSAndy Adamson __func__); 437788034c3dSAndy Adamson 437888034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4379029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 438088034c3dSAndy Adamson } 438188034c3dSAndy Adamson return status; 438288034c3dSAndy Adamson out_overflow: 438388034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 438488034c3dSAndy Adamson return -EIO; 438588034c3dSAndy Adamson } 438688034c3dSAndy Adamson 4387ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4388ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 43898b7e3f49STrond Myklebust struct nfs4_fs_locations *fs_loc, 43906926afd1STrond Myklebust const struct nfs_server *server) 43911da177e4SLinus Torvalds { 4392bca79478STrond Myklebust int status; 4393bca79478STrond Myklebust umode_t fmode = 0; 4394ae42c70aSBryan Schumaker uint32_t type; 4395ee7b75fcSTrond Myklebust int32_t err; 43961da177e4SLinus Torvalds 4397f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4398f26c7a78STrond Myklebust if (status < 0) 43991da177e4SLinus Torvalds goto xdr_error; 4400409924e4STrond Myklebust fattr->mode = 0; 4401409924e4STrond Myklebust if (status != 0) { 4402409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4403409924e4STrond Myklebust fattr->valid |= status; 4404409924e4STrond Myklebust } 44051da177e4SLinus Torvalds 4406f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4407f26c7a78STrond Myklebust if (status < 0) 44081da177e4SLinus Torvalds goto xdr_error; 4409409924e4STrond Myklebust fattr->valid |= status; 4410f26c7a78STrond Myklebust 4411f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4412f26c7a78STrond Myklebust if (status < 0) 44131da177e4SLinus Torvalds goto xdr_error; 4414409924e4STrond Myklebust fattr->valid |= status; 4415f26c7a78STrond Myklebust 4416f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4417f26c7a78STrond Myklebust if (status < 0) 44181da177e4SLinus Torvalds goto xdr_error; 4419409924e4STrond Myklebust fattr->valid |= status; 4420f26c7a78STrond Myklebust 4421ee7b75fcSTrond Myklebust err = 0; 4422ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4423ae42c70aSBryan Schumaker if (status < 0) 4424ae42c70aSBryan Schumaker goto xdr_error; 4425ae42c70aSBryan Schumaker 4426ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4427ae42c70aSBryan Schumaker if (status < 0) 4428ae42c70aSBryan Schumaker goto xdr_error; 4429ae42c70aSBryan Schumaker 4430f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4431f26c7a78STrond Myklebust if (status < 0) 44321da177e4SLinus Torvalds goto xdr_error; 4433409924e4STrond Myklebust fattr->valid |= status; 4434f26c7a78STrond Myklebust 44358b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4436f26c7a78STrond Myklebust if (status < 0) 4437683b57b4STrond Myklebust goto xdr_error; 4438409924e4STrond Myklebust fattr->valid |= status; 4439f26c7a78STrond Myklebust 4440f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4441f26c7a78STrond Myklebust if (status < 0) 44421da177e4SLinus Torvalds goto xdr_error; 4443409924e4STrond Myklebust if (status != 0) { 44441da177e4SLinus Torvalds fattr->mode |= fmode; 4445409924e4STrond Myklebust fattr->valid |= status; 4446409924e4STrond Myklebust } 4447f26c7a78STrond Myklebust 4448f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4449f26c7a78STrond Myklebust if (status < 0) 44501da177e4SLinus Torvalds goto xdr_error; 4451409924e4STrond Myklebust fattr->valid |= status; 4452f26c7a78STrond Myklebust 44536926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4454f26c7a78STrond Myklebust if (status < 0) 44551da177e4SLinus Torvalds goto xdr_error; 4456409924e4STrond Myklebust fattr->valid |= status; 4457f26c7a78STrond Myklebust 44586926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4459f26c7a78STrond Myklebust if (status < 0) 44601da177e4SLinus Torvalds goto xdr_error; 4461409924e4STrond Myklebust fattr->valid |= status; 4462f26c7a78STrond Myklebust 4463f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4464f26c7a78STrond Myklebust if (status < 0) 44651da177e4SLinus Torvalds goto xdr_error; 4466409924e4STrond Myklebust fattr->valid |= status; 4467f26c7a78STrond Myklebust 4468f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4469f26c7a78STrond Myklebust if (status < 0) 44701da177e4SLinus Torvalds goto xdr_error; 4471409924e4STrond Myklebust fattr->valid |= status; 4472f26c7a78STrond Myklebust 4473f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4474f26c7a78STrond Myklebust if (status < 0) 44751da177e4SLinus Torvalds goto xdr_error; 4476409924e4STrond Myklebust fattr->valid |= status; 4477f26c7a78STrond Myklebust 4478f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4479f26c7a78STrond Myklebust if (status < 0) 44801da177e4SLinus Torvalds goto xdr_error; 4481409924e4STrond Myklebust fattr->valid |= status; 4482f26c7a78STrond Myklebust 4483f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4484f26c7a78STrond Myklebust if (status < 0) 44851da177e4SLinus Torvalds goto xdr_error; 4486409924e4STrond Myklebust fattr->valid |= status; 4487f26c7a78STrond Myklebust 448828331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4489f26c7a78STrond Myklebust if (status < 0) 449099baf625SManoj Naik goto xdr_error; 4491409924e4STrond Myklebust fattr->valid |= status; 4492f26c7a78STrond Myklebust 449388034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 449488034c3dSAndy Adamson if (status < 0) 449588034c3dSAndy Adamson goto xdr_error; 449688034c3dSAndy Adamson 4497ae42c70aSBryan Schumaker xdr_error: 4498ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4499ae42c70aSBryan Schumaker return status; 4500ae42c70aSBryan Schumaker } 4501ae42c70aSBryan Schumaker 4502ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 45038b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 45048b7e3f49STrond Myklebust const struct nfs_server *server) 4505ae42c70aSBryan Schumaker { 4506256e48bbSTrond Myklebust unsigned int savep; 4507ae42c70aSBryan Schumaker uint32_t attrlen, 4508dae100c2SFred Isaman bitmap[3] = {0}; 4509ae42c70aSBryan Schumaker int status; 4510ae42c70aSBryan Schumaker 4511ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4512ae42c70aSBryan Schumaker if (status < 0) 4513ae42c70aSBryan Schumaker goto xdr_error; 4514ae42c70aSBryan Schumaker 4515ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4516ae42c70aSBryan Schumaker if (status < 0) 4517ae42c70aSBryan Schumaker goto xdr_error; 4518ae42c70aSBryan Schumaker 4519ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4520ae42c70aSBryan Schumaker if (status < 0) 4521ae42c70aSBryan Schumaker goto xdr_error; 4522ae42c70aSBryan Schumaker 45238b7e3f49STrond Myklebust status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server); 4524ae42c70aSBryan Schumaker if (status < 0) 4525ae42c70aSBryan Schumaker goto xdr_error; 4526ae42c70aSBryan Schumaker 4527f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 45281da177e4SLinus Torvalds xdr_error: 45293110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 45301da177e4SLinus Torvalds return status; 45311da177e4SLinus Torvalds } 45321da177e4SLinus Torvalds 4533ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 45346926afd1STrond Myklebust const struct nfs_server *server) 4535ae42c70aSBryan Schumaker { 45368b7e3f49STrond Myklebust return decode_getfattr_generic(xdr, fattr, NULL, NULL, server); 4537ae42c70aSBryan Schumaker } 45381da177e4SLinus Torvalds 4539504913fbSAndy Adamson /* 4540504913fbSAndy Adamson * Decode potentially multiple layout types. Currently we only support 4541504913fbSAndy Adamson * one layout driver per file system. 4542504913fbSAndy Adamson */ 4543504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, 4544504913fbSAndy Adamson uint32_t *layouttype) 4545504913fbSAndy Adamson { 4546504913fbSAndy Adamson uint32_t *p; 4547504913fbSAndy Adamson int num; 4548504913fbSAndy Adamson 4549504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4550504913fbSAndy Adamson if (unlikely(!p)) 4551504913fbSAndy Adamson goto out_overflow; 4552504913fbSAndy Adamson num = be32_to_cpup(p); 4553504913fbSAndy Adamson 4554504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4555504913fbSAndy Adamson if (num == 0) { 4556504913fbSAndy Adamson *layouttype = 0; 4557504913fbSAndy Adamson return 0; 4558504913fbSAndy Adamson } 4559504913fbSAndy Adamson if (num > 1) 4560a030889aSWeston Andros Adamson printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout " 4561a030889aSWeston Andros Adamson "drivers per filesystem not supported\n", __func__); 4562504913fbSAndy Adamson 4563504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4564504913fbSAndy Adamson p = xdr_inline_decode(xdr, num * 4); 4565504913fbSAndy Adamson if (unlikely(!p)) 4566504913fbSAndy Adamson goto out_overflow; 4567504913fbSAndy Adamson *layouttype = be32_to_cpup(p); 4568504913fbSAndy Adamson return 0; 4569504913fbSAndy Adamson out_overflow: 4570504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4571504913fbSAndy Adamson return -EIO; 4572504913fbSAndy Adamson } 4573504913fbSAndy Adamson 4574504913fbSAndy Adamson /* 4575504913fbSAndy Adamson * The type of file system exported. 4576504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4577504913fbSAndy Adamson */ 4578504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4579504913fbSAndy Adamson uint32_t *layouttype) 4580504913fbSAndy Adamson { 4581504913fbSAndy Adamson int status = 0; 4582504913fbSAndy Adamson 4583504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4584504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4585504913fbSAndy Adamson return -EIO; 4586504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4587504913fbSAndy Adamson status = decode_first_pnfs_layout_type(xdr, layouttype); 4588504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 4589504913fbSAndy Adamson } else 4590504913fbSAndy Adamson *layouttype = 0; 4591504913fbSAndy Adamson return status; 4592504913fbSAndy Adamson } 4593504913fbSAndy Adamson 4594dae100c2SFred Isaman /* 4595dae100c2SFred Isaman * The prefered block size for layout directed io 4596dae100c2SFred Isaman */ 4597dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4598dae100c2SFred Isaman uint32_t *res) 4599dae100c2SFred Isaman { 4600dae100c2SFred Isaman __be32 *p; 4601dae100c2SFred Isaman 4602dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4603dae100c2SFred Isaman *res = 0; 4604dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4605dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4606dae100c2SFred Isaman if (unlikely(!p)) { 4607dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4608dae100c2SFred Isaman return -EIO; 4609dae100c2SFred Isaman } 4610dae100c2SFred Isaman *res = be32_to_cpup(p); 4611dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4612dae100c2SFred Isaman } 4613dae100c2SFred Isaman return 0; 4614dae100c2SFred Isaman } 4615dae100c2SFred Isaman 46161da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 46171da177e4SLinus Torvalds { 4618256e48bbSTrond Myklebust unsigned int savep; 4619dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 46201da177e4SLinus Torvalds int status; 46211da177e4SLinus Torvalds 46221da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 46231da177e4SLinus Torvalds goto xdr_error; 46241da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 46251da177e4SLinus Torvalds goto xdr_error; 46261da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 46271da177e4SLinus Torvalds goto xdr_error; 46281da177e4SLinus Torvalds 46291da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 46301da177e4SLinus Torvalds 46311da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 46321da177e4SLinus Torvalds goto xdr_error; 46331da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 46341da177e4SLinus Torvalds goto xdr_error; 46351da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 46361da177e4SLinus Torvalds goto xdr_error; 46371da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 46381da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 46391da177e4SLinus Torvalds goto xdr_error; 46401da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 464155b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 464255b6e774SRicardo Labiaga if (status != 0) 464355b6e774SRicardo Labiaga goto xdr_error; 4644504913fbSAndy Adamson status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); 4645504913fbSAndy Adamson if (status != 0) 4646504913fbSAndy Adamson goto xdr_error; 4647dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4648dae100c2SFred Isaman if (status) 4649dae100c2SFred Isaman goto xdr_error; 46501da177e4SLinus Torvalds 46511da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 46521da177e4SLinus Torvalds xdr_error: 46533110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 46541da177e4SLinus Torvalds return status; 46551da177e4SLinus Torvalds } 46561da177e4SLinus Torvalds 46571da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 46581da177e4SLinus Torvalds { 46598687b63aSAl Viro __be32 *p; 46601da177e4SLinus Torvalds uint32_t len; 46611da177e4SLinus Torvalds int status; 46621da177e4SLinus Torvalds 46639936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 46649936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 46659936781dSTrond Myklebust 46661da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 46671da177e4SLinus Torvalds if (status) 46681da177e4SLinus Torvalds return status; 46691da177e4SLinus Torvalds 4670c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4671c0eae66eSBenny Halevy if (unlikely(!p)) 4672c0eae66eSBenny Halevy goto out_overflow; 4673cccddf4fSBenny Halevy len = be32_to_cpup(p); 46741da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 46751da177e4SLinus Torvalds return -EIO; 46761da177e4SLinus Torvalds fh->size = len; 4677c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4678c0eae66eSBenny Halevy if (unlikely(!p)) 4679c0eae66eSBenny Halevy goto out_overflow; 468099398d06SBenny Halevy memcpy(fh->data, p, len); 46811da177e4SLinus Torvalds return 0; 4682c0eae66eSBenny Halevy out_overflow: 4683c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4684c0eae66eSBenny Halevy return -EIO; 46851da177e4SLinus Torvalds } 46861da177e4SLinus Torvalds 46871da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 46881da177e4SLinus Torvalds { 46891da177e4SLinus Torvalds int status; 46901da177e4SLinus Torvalds 46911da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 46921da177e4SLinus Torvalds if (status) 46931da177e4SLinus Torvalds return status; 46941da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 46951da177e4SLinus Torvalds } 46961da177e4SLinus Torvalds 46971da177e4SLinus Torvalds /* 46981da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 46991da177e4SLinus Torvalds */ 4700911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 47011da177e4SLinus Torvalds { 4702911d1aafSTrond Myklebust uint64_t offset, length, clientid; 47038687b63aSAl Viro __be32 *p; 4704911d1aafSTrond Myklebust uint32_t namelen, type; 47051da177e4SLinus Torvalds 4706babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4707c0eae66eSBenny Halevy if (unlikely(!p)) 4708c0eae66eSBenny Halevy goto out_overflow; 4709babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 47103ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4711babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4712babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4713911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4714911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4715911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4716911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4717911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4718911d1aafSTrond Myklebust if (type & 1) 4719911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4720911d1aafSTrond Myklebust fl->fl_pid = 0; 4721911d1aafSTrond Myklebust } 4722babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4723babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4724babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4725c0eae66eSBenny Halevy if (likely(p)) 47261da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4727c0eae66eSBenny Halevy out_overflow: 4728c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4729c0eae66eSBenny Halevy return -EIO; 47301da177e4SLinus Torvalds } 47311da177e4SLinus Torvalds 4732911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 47331da177e4SLinus Torvalds { 47341da177e4SLinus Torvalds int status; 47351da177e4SLinus Torvalds 47361da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4737c1d51931STrond Myklebust if (status == -EIO) 4738c1d51931STrond Myklebust goto out; 47391da177e4SLinus Torvalds if (status == 0) { 474007d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 474107d30434SBenny Halevy if (unlikely(status)) 474207d30434SBenny Halevy goto out; 47431da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4744c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4745c1d51931STrond Myklebust if (res->open_seqid != NULL) 4746c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4747c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4748c1d51931STrond Myklebust out: 47491da177e4SLinus Torvalds return status; 47501da177e4SLinus Torvalds } 47511da177e4SLinus Torvalds 4752911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 47531da177e4SLinus Torvalds { 47541da177e4SLinus Torvalds int status; 47551da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 47561da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4757911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 47581da177e4SLinus Torvalds return status; 47591da177e4SLinus Torvalds } 47601da177e4SLinus Torvalds 4761911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 47621da177e4SLinus Torvalds { 47631da177e4SLinus Torvalds int status; 47641da177e4SLinus Torvalds 47651da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4766c1d51931STrond Myklebust if (status != -EIO) 4767c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 476807d30434SBenny Halevy if (status == 0) 476907d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 47701da177e4SLinus Torvalds return status; 47711da177e4SLinus Torvalds } 47721da177e4SLinus Torvalds 4773d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4774d3c7b7ccSTrond Myklebust { 4775d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4776d3c7b7ccSTrond Myklebust } 4777d3c7b7ccSTrond Myklebust 47781da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 47791da177e4SLinus Torvalds { 47801da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 47811da177e4SLinus Torvalds } 47821da177e4SLinus Torvalds 47831da177e4SLinus Torvalds /* This is too sick! */ 47841da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 47851da177e4SLinus Torvalds { 47868687b63aSAl Viro __be32 *p; 47871da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 47881da177e4SLinus Torvalds 4789c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4790c0eae66eSBenny Halevy if (unlikely(!p)) 4791c0eae66eSBenny Halevy goto out_overflow; 47926f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 47931da177e4SLinus Torvalds switch (limit_type) { 47941da177e4SLinus Torvalds case 1: 4795cccddf4fSBenny Halevy xdr_decode_hyper(p, maxsize); 47961da177e4SLinus Torvalds break; 47971da177e4SLinus Torvalds case 2: 47986f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 4799cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 48001da177e4SLinus Torvalds *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 48011da177e4SLinus Torvalds } 48021da177e4SLinus Torvalds return 0; 4803c0eae66eSBenny Halevy out_overflow: 4804c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4805c0eae66eSBenny Halevy return -EIO; 48061da177e4SLinus Torvalds } 48071da177e4SLinus Torvalds 48081da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 48091da177e4SLinus Torvalds { 48108687b63aSAl Viro __be32 *p; 48111da177e4SLinus Torvalds uint32_t delegation_type; 481207d30434SBenny Halevy int status; 48131da177e4SLinus Torvalds 4814c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4815c0eae66eSBenny Halevy if (unlikely(!p)) 4816c0eae66eSBenny Halevy goto out_overflow; 4817cccddf4fSBenny Halevy delegation_type = be32_to_cpup(p); 48181da177e4SLinus Torvalds if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 48191da177e4SLinus Torvalds res->delegation_type = 0; 48201da177e4SLinus Torvalds return 0; 48211da177e4SLinus Torvalds } 482207d30434SBenny Halevy status = decode_stateid(xdr, &res->delegation); 482307d30434SBenny Halevy if (unlikely(status)) 482407d30434SBenny Halevy return status; 4825c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4826c0eae66eSBenny Halevy if (unlikely(!p)) 4827c0eae66eSBenny Halevy goto out_overflow; 4828cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 482905d564feSAndy Adamson 48301da177e4SLinus Torvalds switch (delegation_type) { 48311da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 48321da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 48331da177e4SLinus Torvalds break; 48341da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 48351da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 48361da177e4SLinus Torvalds if (decode_space_limit(xdr, &res->maxsize) < 0) 48371da177e4SLinus Torvalds return -EIO; 48381da177e4SLinus Torvalds } 48397539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 4840c0eae66eSBenny Halevy out_overflow: 4841c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4842c0eae66eSBenny Halevy return -EIO; 48431da177e4SLinus Torvalds } 48441da177e4SLinus Torvalds 48451da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 48461da177e4SLinus Torvalds { 48478687b63aSAl Viro __be32 *p; 4848aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 48491da177e4SLinus Torvalds int status; 48501da177e4SLinus Torvalds 48511da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN); 4852c1d51931STrond Myklebust if (status != -EIO) 4853c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 485407d30434SBenny Halevy if (!status) 485507d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 485607d30434SBenny Halevy if (unlikely(status)) 48571da177e4SLinus Torvalds return status; 48581da177e4SLinus Torvalds 48591da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 48601da177e4SLinus Torvalds 4861c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4862c0eae66eSBenny Halevy if (unlikely(!p)) 4863c0eae66eSBenny Halevy goto out_overflow; 48646f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 4865cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 48661da177e4SLinus Torvalds if (bmlen > 10) 48671da177e4SLinus Torvalds goto xdr_error; 48681da177e4SLinus Torvalds 4869c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4870c0eae66eSBenny Halevy if (unlikely(!p)) 4871c0eae66eSBenny Halevy goto out_overflow; 4872aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 4873aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 48746f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 4875aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 4876aa53ed54SJeff Layton res->attrset[i] = 0; 4877aa53ed54SJeff Layton 48781da177e4SLinus Torvalds return decode_delegation(xdr, res); 48791da177e4SLinus Torvalds xdr_error: 48803110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 48811da177e4SLinus Torvalds return -EIO; 4882c0eae66eSBenny Halevy out_overflow: 4883c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4884c0eae66eSBenny Halevy return -EIO; 48851da177e4SLinus Torvalds } 48861da177e4SLinus Torvalds 48871da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 48881da177e4SLinus Torvalds { 48891da177e4SLinus Torvalds int status; 48901da177e4SLinus Torvalds 48911da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 4892c1d51931STrond Myklebust if (status != -EIO) 4893c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 489407d30434SBenny Halevy if (!status) 489507d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 48961da177e4SLinus Torvalds return status; 48971da177e4SLinus Torvalds } 48981da177e4SLinus Torvalds 48991da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 49001da177e4SLinus Torvalds { 49011da177e4SLinus Torvalds int status; 49021da177e4SLinus Torvalds 49031da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 4904c1d51931STrond Myklebust if (status != -EIO) 4905c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 490607d30434SBenny Halevy if (!status) 490707d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 49081da177e4SLinus Torvalds return status; 49091da177e4SLinus Torvalds } 49101da177e4SLinus Torvalds 49111da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 49121da177e4SLinus Torvalds { 49131da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 49141da177e4SLinus Torvalds } 49151da177e4SLinus Torvalds 49161da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 49171da177e4SLinus Torvalds { 49181da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 49191da177e4SLinus Torvalds } 49201da177e4SLinus Torvalds 49211da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 49221da177e4SLinus Torvalds { 49238687b63aSAl Viro __be32 *p; 492464bd577eSTrond Myklebust uint32_t count, eof, recvd; 49251da177e4SLinus Torvalds int status; 49261da177e4SLinus Torvalds 49271da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 49281da177e4SLinus Torvalds if (status) 49291da177e4SLinus Torvalds return status; 4930c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4931c0eae66eSBenny Halevy if (unlikely(!p)) 4932c0eae66eSBenny Halevy goto out_overflow; 49336f723f77SBenny Halevy eof = be32_to_cpup(p++); 4934cccddf4fSBenny Halevy count = be32_to_cpup(p); 493564bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 49361da177e4SLinus Torvalds if (count > recvd) { 4937fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 49381da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 49391da177e4SLinus Torvalds count = recvd; 49401da177e4SLinus Torvalds eof = 0; 49411da177e4SLinus Torvalds } 49421da177e4SLinus Torvalds res->eof = eof; 49431da177e4SLinus Torvalds res->count = count; 49441da177e4SLinus Torvalds return 0; 4945c0eae66eSBenny Halevy out_overflow: 4946c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4947c0eae66eSBenny Halevy return -EIO; 49481da177e4SLinus Torvalds } 49491da177e4SLinus Torvalds 49501da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 49511da177e4SLinus Torvalds { 4952bcecff77SChuck Lever int status; 4953cd93710eSChuck Lever __be32 verf[2]; 49541da177e4SLinus Torvalds 49551da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 4956db942bbdSBenny Halevy if (!status) 4957db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 4958db942bbdSBenny Halevy if (unlikely(status)) 49591da177e4SLinus Torvalds return status; 4960cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 496144109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 4962cd93710eSChuck Lever __func__, verf[0], verf[1]); 496364bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 49641da177e4SLinus Torvalds } 49651da177e4SLinus Torvalds 49661da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 49671da177e4SLinus Torvalds { 49681da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 4969bcecff77SChuck Lever u32 len, recvd; 49708687b63aSAl Viro __be32 *p; 49711da177e4SLinus Torvalds int status; 49721da177e4SLinus Torvalds 49731da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 49741da177e4SLinus Torvalds if (status) 49751da177e4SLinus Torvalds return status; 49761da177e4SLinus Torvalds 49771da177e4SLinus Torvalds /* Convert length of symlink */ 4978c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4979c0eae66eSBenny Halevy if (unlikely(!p)) 4980c0eae66eSBenny Halevy goto out_overflow; 4981cccddf4fSBenny Halevy len = be32_to_cpup(p); 49821da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 4983fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 49841da177e4SLinus Torvalds return -ENAMETOOLONG; 49851da177e4SLinus Torvalds } 498664bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 49871da177e4SLinus Torvalds if (recvd < len) { 4988fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 49891da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 49901da177e4SLinus Torvalds return -EIO; 49911da177e4SLinus Torvalds } 49921da177e4SLinus Torvalds /* 49931da177e4SLinus Torvalds * The XDR encode routine has set things up so that 49941da177e4SLinus Torvalds * the link text will be copied directly into the 49951da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 49961da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 49971da177e4SLinus Torvalds * null-termination). 49981da177e4SLinus Torvalds */ 4999b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 50001da177e4SLinus Torvalds return 0; 5001c0eae66eSBenny Halevy out_overflow: 5002c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5003c0eae66eSBenny Halevy return -EIO; 50041da177e4SLinus Torvalds } 50051da177e4SLinus Torvalds 50061da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 50071da177e4SLinus Torvalds { 50081da177e4SLinus Torvalds int status; 50091da177e4SLinus Torvalds 50101da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 50111da177e4SLinus Torvalds if (status) 50121da177e4SLinus Torvalds goto out; 50131da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 50141da177e4SLinus Torvalds out: 50151da177e4SLinus Torvalds return status; 50161da177e4SLinus Torvalds } 50171da177e4SLinus Torvalds 50181da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 50191da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 50201da177e4SLinus Torvalds { 50211da177e4SLinus Torvalds int status; 50221da177e4SLinus Torvalds 50231da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 50241da177e4SLinus Torvalds if (status) 50251da177e4SLinus Torvalds goto out; 50261da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 50271da177e4SLinus Torvalds goto out; 50281da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 50291da177e4SLinus Torvalds out: 50301da177e4SLinus Torvalds return status; 50311da177e4SLinus Torvalds } 50321da177e4SLinus Torvalds 50331da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 50341da177e4SLinus Torvalds { 50351da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 50361da177e4SLinus Torvalds } 50371da177e4SLinus Torvalds 503856ae19f3STrond Myklebust static int 503956ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 504056ae19f3STrond Myklebust { 504156ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 504256ae19f3STrond Myklebust } 504356ae19f3STrond Myklebust 5044029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5045bf118a34SAndy Adamson struct nfs_getaclres *res) 5046029d105eSJ. Bruce Fields { 5047256e48bbSTrond Myklebust unsigned int savep; 5048029d105eSJ. Bruce Fields uint32_t attrlen, 5049dae100c2SFred Isaman bitmap[3] = {0}; 5050029d105eSJ. Bruce Fields int status; 5051cff298c7STrond Myklebust unsigned int pg_offset; 5052029d105eSJ. Bruce Fields 5053bf118a34SAndy Adamson res->acl_len = 0; 5054029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5055029d105eSJ. Bruce Fields goto out; 50565a006899SSachin Prabhu 5057519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5058519d3959STrond Myklebust 5059cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5060cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 50615a006899SSachin Prabhu 5062029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5063029d105eSJ. Bruce Fields goto out; 5064029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5065029d105eSJ. Bruce Fields goto out; 5066029d105eSJ. Bruce Fields 5067029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5068029d105eSJ. Bruce Fields return -EIO; 5069029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5070029d105eSJ. Bruce Fields 5071bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5072bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5073bf118a34SAndy Adamson * variable length bitmaps.*/ 5074cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5075519d3959STrond Myklebust res->acl_len = attrlen; 50761f1ea6c2STrond Myklebust 50771f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 50781f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 50791f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 50801f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5081519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5082cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5083029d105eSJ. Bruce Fields } 50848c233cf9SJ. Bruce Fields } else 50858c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5086029d105eSJ. Bruce Fields 5087029d105eSJ. Bruce Fields out: 5088029d105eSJ. Bruce Fields return status; 5089029d105eSJ. Bruce Fields } 5090029d105eSJ. Bruce Fields 50911da177e4SLinus Torvalds static int 50921da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 50931da177e4SLinus Torvalds { 50941da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 50951da177e4SLinus Torvalds } 50961da177e4SLinus Torvalds 50979e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 50981da177e4SLinus Torvalds { 50998687b63aSAl Viro __be32 *p; 51001da177e4SLinus Torvalds uint32_t bmlen; 51011da177e4SLinus Torvalds int status; 51021da177e4SLinus Torvalds 51031da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 51041da177e4SLinus Torvalds if (status) 51051da177e4SLinus Torvalds return status; 5106c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5107c0eae66eSBenny Halevy if (unlikely(!p)) 5108c0eae66eSBenny Halevy goto out_overflow; 5109cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5110c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5111c0eae66eSBenny Halevy if (likely(p)) 51121da177e4SLinus Torvalds return 0; 5113c0eae66eSBenny Halevy out_overflow: 5114c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5115c0eae66eSBenny Halevy return -EIO; 51161da177e4SLinus Torvalds } 51171da177e4SLinus Torvalds 5118bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 51191da177e4SLinus Torvalds { 51208687b63aSAl Viro __be32 *p; 51211da177e4SLinus Torvalds uint32_t opnum; 51221da177e4SLinus Torvalds int32_t nfserr; 51231da177e4SLinus Torvalds 5124c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5125c0eae66eSBenny Halevy if (unlikely(!p)) 5126c0eae66eSBenny Halevy goto out_overflow; 51276f723f77SBenny Halevy opnum = be32_to_cpup(p++); 51281da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5129fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 51301da177e4SLinus Torvalds " %d\n", opnum); 51311da177e4SLinus Torvalds return -EIO; 51321da177e4SLinus Torvalds } 5133cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 51341da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5135c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5136c0eae66eSBenny Halevy if (unlikely(!p)) 5137c0eae66eSBenny Halevy goto out_overflow; 5138bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5139bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 51401da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 51411da177e4SLinus Torvalds uint32_t len; 51421da177e4SLinus Torvalds 51431da177e4SLinus Torvalds /* skip netid string */ 5144c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5145c0eae66eSBenny Halevy if (unlikely(!p)) 5146c0eae66eSBenny Halevy goto out_overflow; 5147cccddf4fSBenny Halevy len = be32_to_cpup(p); 5148c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5149c0eae66eSBenny Halevy if (unlikely(!p)) 5150c0eae66eSBenny Halevy goto out_overflow; 51511da177e4SLinus Torvalds 51521da177e4SLinus Torvalds /* skip uaddr string */ 5153c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5154c0eae66eSBenny Halevy if (unlikely(!p)) 5155c0eae66eSBenny Halevy goto out_overflow; 5156cccddf4fSBenny Halevy len = be32_to_cpup(p); 5157c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5158c0eae66eSBenny Halevy if (unlikely(!p)) 5159c0eae66eSBenny Halevy goto out_overflow; 51601da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 51611da177e4SLinus Torvalds } else 5162856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 51631da177e4SLinus Torvalds 51641da177e4SLinus Torvalds return 0; 5165c0eae66eSBenny Halevy out_overflow: 5166c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5167c0eae66eSBenny Halevy return -EIO; 51681da177e4SLinus Torvalds } 51691da177e4SLinus Torvalds 51701da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 51711da177e4SLinus Torvalds { 51721da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 51731da177e4SLinus Torvalds } 51741da177e4SLinus Torvalds 51751da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 51761da177e4SLinus Torvalds { 51778687b63aSAl Viro __be32 *p; 51781da177e4SLinus Torvalds int status; 51791da177e4SLinus Torvalds 51801da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 51811da177e4SLinus Torvalds if (status) 51821da177e4SLinus Torvalds return status; 51831da177e4SLinus Torvalds 51842f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5185c0eae66eSBenny Halevy if (unlikely(!p)) 5186c0eae66eSBenny Halevy goto out_overflow; 51876f723f77SBenny Halevy res->count = be32_to_cpup(p++); 51886f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 51892f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5190c0eae66eSBenny Halevy out_overflow: 5191c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5192c0eae66eSBenny Halevy return -EIO; 51931da177e4SLinus Torvalds } 51941da177e4SLinus Torvalds 51951da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 51961da177e4SLinus Torvalds { 51971da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 51981da177e4SLinus Torvalds } 51991da177e4SLinus Torvalds 52005a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor) 52015a5ea0d4SBryan Schumaker { 52025a5ea0d4SBryan Schumaker __be32 *p; 52035a5ea0d4SBryan Schumaker 52045a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 52055a5ea0d4SBryan Schumaker if (unlikely(!p)) 52065a5ea0d4SBryan Schumaker goto out_overflow; 52075a5ea0d4SBryan Schumaker flavor->gss.sec_oid4.len = be32_to_cpup(p); 52085a5ea0d4SBryan Schumaker if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN) 52095a5ea0d4SBryan Schumaker goto out_err; 52105a5ea0d4SBryan Schumaker 52115a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len); 52125a5ea0d4SBryan Schumaker if (unlikely(!p)) 52135a5ea0d4SBryan Schumaker goto out_overflow; 52145a5ea0d4SBryan Schumaker memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len); 52155a5ea0d4SBryan Schumaker 52165a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 52175a5ea0d4SBryan Schumaker if (unlikely(!p)) 52185a5ea0d4SBryan Schumaker goto out_overflow; 52195a5ea0d4SBryan Schumaker flavor->gss.qop4 = be32_to_cpup(p++); 52205a5ea0d4SBryan Schumaker flavor->gss.service = be32_to_cpup(p); 52215a5ea0d4SBryan Schumaker 52225a5ea0d4SBryan Schumaker return 0; 52235a5ea0d4SBryan Schumaker 52245a5ea0d4SBryan Schumaker out_overflow: 52255a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 52265a5ea0d4SBryan Schumaker return -EIO; 52275a5ea0d4SBryan Schumaker out_err: 52285a5ea0d4SBryan Schumaker return -EINVAL; 52295a5ea0d4SBryan Schumaker } 52305a5ea0d4SBryan Schumaker 523131e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 52325a5ea0d4SBryan Schumaker { 52335a5ea0d4SBryan Schumaker struct nfs4_secinfo_flavor *sec_flavor; 52345a5ea0d4SBryan Schumaker int status; 52355a5ea0d4SBryan Schumaker __be32 *p; 5236c3dfc280SBryan Schumaker int i, num_flavors; 52375a5ea0d4SBryan Schumaker 52385a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 52395a5ea0d4SBryan Schumaker if (unlikely(!p)) 52405a5ea0d4SBryan Schumaker goto out_overflow; 52415a5ea0d4SBryan Schumaker 5242c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5243c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5244c3dfc280SBryan Schumaker 5245c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 52465a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5247c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 52485a5ea0d4SBryan Schumaker break; 52495a5ea0d4SBryan Schumaker 52505a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 52515a5ea0d4SBryan Schumaker if (unlikely(!p)) 52525a5ea0d4SBryan Schumaker goto out_overflow; 52535a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 52545a5ea0d4SBryan Schumaker 52555a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5256613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5257613e901eSBryan Schumaker if (status) 5258613e901eSBryan Schumaker goto out; 52595a5ea0d4SBryan Schumaker } 5260c3dfc280SBryan Schumaker res->flavors->num_flavors++; 52615a5ea0d4SBryan Schumaker } 52625a5ea0d4SBryan Schumaker 526331e4dda4SBryan Schumaker status = 0; 5264613e901eSBryan Schumaker out: 5265613e901eSBryan Schumaker return status; 52665a5ea0d4SBryan Schumaker out_overflow: 52675a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 52685a5ea0d4SBryan Schumaker return -EIO; 52695a5ea0d4SBryan Schumaker } 52705a5ea0d4SBryan Schumaker 527131e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 527231e4dda4SBryan Schumaker { 527331e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 527431e4dda4SBryan Schumaker if (status) 527531e4dda4SBryan Schumaker return status; 527631e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 527731e4dda4SBryan Schumaker } 527831e4dda4SBryan Schumaker 527999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 528031e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 528131e4dda4SBryan Schumaker { 528231e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 528331e4dda4SBryan Schumaker if (status) 528431e4dda4SBryan Schumaker return status; 528531e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 528631e4dda4SBryan Schumaker } 528731e4dda4SBryan Schumaker 528899fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 528999fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 529099fe60d0SBenny Halevy { 529199fe60d0SBenny Halevy __be32 *p; 529299fe60d0SBenny Halevy uint32_t dummy; 52932460ba57SBenny Halevy char *dummy_str; 529499fe60d0SBenny Halevy int status; 52957d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 529699fe60d0SBenny Halevy 529799fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 529899fe60d0SBenny Halevy if (status) 529999fe60d0SBenny Halevy return status; 530099fe60d0SBenny Halevy 5301c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5302c0eae66eSBenny Halevy if (unlikely(!p)) 5303c0eae66eSBenny Halevy goto out_overflow; 530432b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5305c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5306c0eae66eSBenny Halevy if (unlikely(!p)) 5307c0eae66eSBenny Halevy goto out_overflow; 530832b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 530932b01310STrond Myklebust res->flags = be32_to_cpup(p++); 531099fe60d0SBenny Halevy 531199fe60d0SBenny Halevy /* We ask for SP4_NONE */ 5312cccddf4fSBenny Halevy dummy = be32_to_cpup(p); 531399fe60d0SBenny Halevy if (dummy != SP4_NONE) 531499fe60d0SBenny Halevy return -EIO; 531599fe60d0SBenny Halevy 5316acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5317c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5318c0eae66eSBenny Halevy if (unlikely(!p)) 5319c0eae66eSBenny Halevy goto out_overflow; 5320acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 532199fe60d0SBenny Halevy 5322acdeb69dSChuck Lever /* server_owner4.so_major_id */ 53232460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 53242460ba57SBenny Halevy if (unlikely(status)) 53252460ba57SBenny Halevy return status; 532678fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 532778fe0f41SWeston Andros Adamson return -EIO; 5328acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5329acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 533078fe0f41SWeston Andros Adamson 5331acdeb69dSChuck Lever /* server_scope4 */ 5332acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5333acdeb69dSChuck Lever if (unlikely(status)) 5334acdeb69dSChuck Lever return status; 5335acdeb69dSChuck Lever if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 5336acdeb69dSChuck Lever return -EIO; 533778fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 533878fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 533978fe0f41SWeston Andros Adamson 53407d2ed9acSWeston Andros Adamson /* Implementation Id */ 53417d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 53427d2ed9acSWeston Andros Adamson if (unlikely(!p)) 53437d2ed9acSWeston Andros Adamson goto out_overflow; 53447d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 53457d2ed9acSWeston Andros Adamson 53467d2ed9acSWeston Andros Adamson if (impl_id_count) { 53477d2ed9acSWeston Andros Adamson /* nii_domain */ 53482460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 53492460ba57SBenny Halevy if (unlikely(status)) 53502460ba57SBenny Halevy return status; 53517d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 53527d2ed9acSWeston Andros Adamson return -EIO; 53537d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 535499fe60d0SBenny Halevy 53557d2ed9acSWeston Andros Adamson /* nii_name */ 53567d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 53577d2ed9acSWeston Andros Adamson if (unlikely(status)) 53587d2ed9acSWeston Andros Adamson return status; 53597d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 53607d2ed9acSWeston Andros Adamson return -EIO; 53617d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 53627d2ed9acSWeston Andros Adamson 53637d2ed9acSWeston Andros Adamson /* nii_date */ 53647d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 53657d2ed9acSWeston Andros Adamson if (unlikely(!p)) 53667d2ed9acSWeston Andros Adamson goto out_overflow; 53677d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 53687d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 53697d2ed9acSWeston Andros Adamson 53707d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 53717d2ed9acSWeston Andros Adamson } 537299fe60d0SBenny Halevy return 0; 5373c0eae66eSBenny Halevy out_overflow: 5374c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5375c0eae66eSBenny Halevy return -EIO; 537699fe60d0SBenny Halevy } 5377fc931582SAndy Adamson 5378fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5379fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5380fc931582SAndy Adamson { 5381fc931582SAndy Adamson __be32 *p; 5382c9c30dd5SBenny Halevy u32 nr_attrs, val; 5383fc931582SAndy Adamson 5384c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5385c0eae66eSBenny Halevy if (unlikely(!p)) 5386c0eae66eSBenny Halevy goto out_overflow; 5387c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5388c9c30dd5SBenny Halevy if (val) 5389c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 53906f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 53916f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 53926f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 53936f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 53946f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5395cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5396fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5397a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5398a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5399fc931582SAndy Adamson return -EINVAL; 5400fc931582SAndy Adamson } 5401c0eae66eSBenny Halevy if (nr_attrs == 1) { 5402c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5403c0eae66eSBenny Halevy if (unlikely(!p)) 5404c0eae66eSBenny Halevy goto out_overflow; 5405c0eae66eSBenny Halevy } 5406fc931582SAndy Adamson return 0; 5407c0eae66eSBenny Halevy out_overflow: 5408c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5409c0eae66eSBenny Halevy return -EIO; 5410fc931582SAndy Adamson } 5411fc931582SAndy Adamson 5412e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5413e78291e4SBenny Halevy { 5414e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5415fc931582SAndy Adamson } 5416fc931582SAndy Adamson 54177c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 54187c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 54197c44f1aeSWeston Andros Adamson { 54207c44f1aeSWeston Andros Adamson __be32 *p; 54217c44f1aeSWeston Andros Adamson int status; 54227c44f1aeSWeston Andros Adamson 54237c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 54247c44f1aeSWeston Andros Adamson if (!status) 54257c44f1aeSWeston Andros Adamson status = decode_sessionid(xdr, &res->session->sess_id); 54267c44f1aeSWeston Andros Adamson if (unlikely(status)) 54277c44f1aeSWeston Andros Adamson return status; 54287c44f1aeSWeston Andros Adamson 54297c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 54307c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 54317c44f1aeSWeston Andros Adamson if (unlikely(!p)) 54327c44f1aeSWeston Andros Adamson goto out_overflow; 54337c44f1aeSWeston Andros Adamson 54347c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 54357c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 54367c44f1aeSWeston Andros Adamson return -EIO; 54377c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 54387c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 54397c44f1aeSWeston Andros Adamson else 54407c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 54417c44f1aeSWeston Andros Adamson 54427c44f1aeSWeston Andros Adamson return 0; 54437c44f1aeSWeston Andros Adamson out_overflow: 54447c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 54457c44f1aeSWeston Andros Adamson return -EIO; 54467c44f1aeSWeston Andros Adamson } 54477c44f1aeSWeston Andros Adamson 5448fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5449fc931582SAndy Adamson struct nfs41_create_session_res *res) 5450fc931582SAndy Adamson { 5451fc931582SAndy Adamson __be32 *p; 5452fc931582SAndy Adamson int status; 5453fc931582SAndy Adamson struct nfs_client *clp = res->client; 5454fc931582SAndy Adamson struct nfs4_session *session = clp->cl_session; 5455fc931582SAndy Adamson 5456fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5457e78291e4SBenny Halevy if (!status) 5458e78291e4SBenny Halevy status = decode_sessionid(xdr, &session->sess_id); 5459e78291e4SBenny Halevy if (unlikely(status)) 5460fc931582SAndy Adamson return status; 5461fc931582SAndy Adamson 5462fc931582SAndy Adamson /* seqid, flags */ 5463c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5464c0eae66eSBenny Halevy if (unlikely(!p)) 5465c0eae66eSBenny Halevy goto out_overflow; 54666f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 5467cccddf4fSBenny Halevy session->flags = be32_to_cpup(p); 5468fc931582SAndy Adamson 5469fc931582SAndy Adamson /* Channel attributes */ 5470fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->fc_attrs); 5471fc931582SAndy Adamson if (!status) 5472fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->bc_attrs); 5473fc931582SAndy Adamson return status; 5474c0eae66eSBenny Halevy out_overflow: 5475c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5476c0eae66eSBenny Halevy return -EIO; 5477fc931582SAndy Adamson } 54780f3e66c6SAndy Adamson 54790f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 54800f3e66c6SAndy Adamson { 54810f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 54820f3e66c6SAndy Adamson } 548318019753SRicardo Labiaga 548466245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 548566245539STrond Myklebust { 548666245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 548766245539STrond Myklebust } 548866245539STrond Myklebust 548918019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 549018019753SRicardo Labiaga { 549118019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 549218019753SRicardo Labiaga } 549399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 549499fe60d0SBenny Halevy 54959b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 54969b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 54979b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 54989b7b9fccSAndy Adamson { 54999b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5500fc01cea9SAndy Adamson struct nfs4_sessionid id; 5501fc01cea9SAndy Adamson u32 dummy; 5502fc01cea9SAndy Adamson int status; 5503fc01cea9SAndy Adamson __be32 *p; 5504fc01cea9SAndy Adamson 55059b7b9fccSAndy Adamson if (!res->sr_session) 55069b7b9fccSAndy Adamson return 0; 55079b7b9fccSAndy Adamson 5508fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5509e78291e4SBenny Halevy if (!status) 5510e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5511e78291e4SBenny Halevy if (unlikely(status)) 5512fc01cea9SAndy Adamson goto out_err; 55139b7b9fccSAndy Adamson 5514fc01cea9SAndy Adamson /* 5515fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5516fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5517fc01cea9SAndy Adamson */ 5518fdcb4577STrond Myklebust status = -EREMOTEIO; 5519fc01cea9SAndy Adamson 5520fc01cea9SAndy Adamson if (memcmp(id.data, res->sr_session->sess_id.data, 5521fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5522fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5523fc01cea9SAndy Adamson goto out_err; 5524fc01cea9SAndy Adamson } 5525e78291e4SBenny Halevy 5526c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5527c0eae66eSBenny Halevy if (unlikely(!p)) 5528c0eae66eSBenny Halevy goto out_overflow; 5529e78291e4SBenny Halevy 5530fc01cea9SAndy Adamson /* seqid */ 55316f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5532dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5533fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5534fc01cea9SAndy Adamson goto out_err; 5535fc01cea9SAndy Adamson } 5536fc01cea9SAndy Adamson /* slot id */ 55376f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5538dfb4f309SBenny Halevy if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) { 5539fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5540fc01cea9SAndy Adamson goto out_err; 5541fc01cea9SAndy Adamson } 5542fc01cea9SAndy Adamson /* highest slot id - currently not processed */ 55436f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5544fc01cea9SAndy Adamson /* target highest slot id - currently not processed */ 55456f723f77SBenny Halevy dummy = be32_to_cpup(p++); 55460629e370SAlexandros Batsakis /* result flags */ 55470629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5548fc01cea9SAndy Adamson status = 0; 5549fc01cea9SAndy Adamson out_err: 5550fc01cea9SAndy Adamson res->sr_status = status; 5551fc01cea9SAndy Adamson return status; 5552c0eae66eSBenny Halevy out_overflow: 5553c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5554c0eae66eSBenny Halevy status = -EIO; 5555c0eae66eSBenny Halevy goto out_err; 5556fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 55579b7b9fccSAndy Adamson return 0; 5558fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 55599b7b9fccSAndy Adamson } 55609b7b9fccSAndy Adamson 5561b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 55627f11d8d3SAndy Adamson /* 55637f11d8d3SAndy Adamson * TODO: Need to handle case when EOF != true; 55647f11d8d3SAndy Adamson */ 55657f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr, 55667f11d8d3SAndy Adamson struct pnfs_devicelist *res) 55677f11d8d3SAndy Adamson { 55687f11d8d3SAndy Adamson __be32 *p; 55697f11d8d3SAndy Adamson int status, i; 557098d94524STrond Myklebust nfs4_verifier verftemp; 55717f11d8d3SAndy Adamson 55727f11d8d3SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICELIST); 55737f11d8d3SAndy Adamson if (status) 55747f11d8d3SAndy Adamson return status; 55757f11d8d3SAndy Adamson 55767f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 8 + 8 + 4); 55777f11d8d3SAndy Adamson if (unlikely(!p)) 55787f11d8d3SAndy Adamson goto out_overflow; 55797f11d8d3SAndy Adamson 55807f11d8d3SAndy Adamson /* TODO: Skip cookie for now */ 55817f11d8d3SAndy Adamson p += 2; 55827f11d8d3SAndy Adamson 55837f11d8d3SAndy Adamson /* Read verifier */ 558498d94524STrond Myklebust p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE); 55857f11d8d3SAndy Adamson 55867f11d8d3SAndy Adamson res->num_devs = be32_to_cpup(p); 55877f11d8d3SAndy Adamson 55887f11d8d3SAndy Adamson dprintk("%s: num_dev %d\n", __func__, res->num_devs); 55897f11d8d3SAndy Adamson 55907f11d8d3SAndy Adamson if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5591a030889aSWeston Andros Adamson printk(KERN_ERR "NFS: %s too many result dev_num %u\n", 55927f11d8d3SAndy Adamson __func__, res->num_devs); 55937f11d8d3SAndy Adamson return -EIO; 55947f11d8d3SAndy Adamson } 55957f11d8d3SAndy Adamson 55967f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 55977f11d8d3SAndy Adamson res->num_devs * NFS4_DEVICEID4_SIZE + 4); 55987f11d8d3SAndy Adamson if (unlikely(!p)) 55997f11d8d3SAndy Adamson goto out_overflow; 56007f11d8d3SAndy Adamson for (i = 0; i < res->num_devs; i++) 56017f11d8d3SAndy Adamson p = xdr_decode_opaque_fixed(p, res->dev_id[i].data, 56027f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE); 56037f11d8d3SAndy Adamson res->eof = be32_to_cpup(p); 56047f11d8d3SAndy Adamson return 0; 56057f11d8d3SAndy Adamson out_overflow: 56067f11d8d3SAndy Adamson print_overflow_msg(__func__, xdr); 56077f11d8d3SAndy Adamson return -EIO; 56087f11d8d3SAndy Adamson } 5609b1f69b75SAndy Adamson 5610b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 5611b1f69b75SAndy Adamson struct pnfs_device *pdev) 5612b1f69b75SAndy Adamson { 5613b1f69b75SAndy Adamson __be32 *p; 5614b1f69b75SAndy Adamson uint32_t len, type; 5615b1f69b75SAndy Adamson int status; 5616b1f69b75SAndy Adamson 5617b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5618b1f69b75SAndy Adamson if (status) { 5619b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5620b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5621b1f69b75SAndy Adamson if (unlikely(!p)) 5622b1f69b75SAndy Adamson goto out_overflow; 5623b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5624b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5625b1f69b75SAndy Adamson __func__, pdev->mincount); 5626b1f69b75SAndy Adamson } 5627b1f69b75SAndy Adamson return status; 5628b1f69b75SAndy Adamson } 5629b1f69b75SAndy Adamson 5630b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5631b1f69b75SAndy Adamson if (unlikely(!p)) 5632b1f69b75SAndy Adamson goto out_overflow; 5633b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5634b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5635b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5636b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5637b1f69b75SAndy Adamson return -EINVAL; 5638b1f69b75SAndy Adamson } 5639b1f69b75SAndy Adamson /* 5640b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5641b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5642b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5643b1f69b75SAndy Adamson */ 5644b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5645b1f69b75SAndy Adamson xdr_read_pages(xdr, pdev->mincount); /* include space for the length */ 5646b1f69b75SAndy Adamson 5647b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5648b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5649b1f69b75SAndy Adamson if (unlikely(!p)) 5650b1f69b75SAndy Adamson goto out_overflow; 5651b1f69b75SAndy Adamson len = be32_to_cpup(p); 5652b1f69b75SAndy Adamson if (len) { 5653ead00597SChuck Lever uint32_t i; 5654b1f69b75SAndy Adamson 5655b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5656b1f69b75SAndy Adamson if (unlikely(!p)) 5657b1f69b75SAndy Adamson goto out_overflow; 5658b1f69b75SAndy Adamson for (i = 0; i < len; i++, p++) { 5659b1f69b75SAndy Adamson if (be32_to_cpup(p)) { 5660b1f69b75SAndy Adamson dprintk("%s: notifications not supported\n", 5661b1f69b75SAndy Adamson __func__); 5662b1f69b75SAndy Adamson return -EIO; 5663b1f69b75SAndy Adamson } 5664b1f69b75SAndy Adamson } 5665b1f69b75SAndy Adamson } 5666b1f69b75SAndy Adamson return 0; 5667b1f69b75SAndy Adamson out_overflow: 5668b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5669b1f69b75SAndy Adamson return -EIO; 5670b1f69b75SAndy Adamson } 5671b1f69b75SAndy Adamson 5672b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5673b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5674b1f69b75SAndy Adamson { 5675b1f69b75SAndy Adamson __be32 *p; 5676b1f69b75SAndy Adamson int status; 5677b1f69b75SAndy Adamson u32 layout_count; 567864bd577eSTrond Myklebust u32 recvd; 5679b1f69b75SAndy Adamson 5680b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5681b1f69b75SAndy Adamson if (status) 5682b1f69b75SAndy Adamson return status; 5683ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5684b1f69b75SAndy Adamson if (unlikely(!p)) 5685b1f69b75SAndy Adamson goto out_overflow; 5686ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 5687ea9d23f5STrond Myklebust decode_stateid(xdr, &res->stateid); 5688ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5689ea9d23f5STrond Myklebust if (unlikely(!p)) 5690ea9d23f5STrond Myklebust goto out_overflow; 5691b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5692b1f69b75SAndy Adamson if (!layout_count) { 5693b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5694b1f69b75SAndy Adamson __func__); 5695b1f69b75SAndy Adamson return -EINVAL; 5696b1f69b75SAndy Adamson } 5697b1f69b75SAndy Adamson 569835124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5699b1f69b75SAndy Adamson if (unlikely(!p)) 5700b1f69b75SAndy Adamson goto out_overflow; 5701b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5702b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5703b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5704b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 570535124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5706b1f69b75SAndy Adamson 5707b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5708b1f69b75SAndy Adamson __func__, 5709b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5710b1f69b75SAndy Adamson (unsigned long)res->range.length, 5711b1f69b75SAndy Adamson res->range.iomode, 5712b1f69b75SAndy Adamson res->type, 571335124a09SWeston Andros Adamson res->layoutp->len); 5714b1f69b75SAndy Adamson 571564bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 571635124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 571735124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 571835124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 571935124a09SWeston Andros Adamson res->layoutp->len, recvd); 572035124a09SWeston Andros Adamson return -EINVAL; 572135124a09SWeston Andros Adamson } 572235124a09SWeston Andros Adamson 5723b1f69b75SAndy Adamson if (layout_count > 1) { 5724b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5725b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5726b1f69b75SAndy Adamson * the client may see a response that is less than the 5727b1f69b75SAndy Adamson * minimum it requested. 5728b1f69b75SAndy Adamson */ 5729b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5730b1f69b75SAndy Adamson __func__, layout_count); 5731b1f69b75SAndy Adamson } 5732b1f69b75SAndy Adamson 5733b1f69b75SAndy Adamson return 0; 5734b1f69b75SAndy Adamson out_overflow: 5735b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5736b1f69b75SAndy Adamson return -EIO; 5737b1f69b75SAndy Adamson } 5738863a3c6cSAndy Adamson 5739cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5740cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5741cbe82603SBenny Halevy { 5742cbe82603SBenny Halevy __be32 *p; 5743cbe82603SBenny Halevy int status; 5744cbe82603SBenny Halevy 5745cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5746cbe82603SBenny Halevy if (status) 5747cbe82603SBenny Halevy return status; 5748cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5749cbe82603SBenny Halevy if (unlikely(!p)) 5750cbe82603SBenny Halevy goto out_overflow; 5751cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5752cbe82603SBenny Halevy if (res->lrs_present) 5753cbe82603SBenny Halevy status = decode_stateid(xdr, &res->stateid); 5754cbe82603SBenny Halevy return status; 5755cbe82603SBenny Halevy out_overflow: 5756cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 5757cbe82603SBenny Halevy return -EIO; 5758cbe82603SBenny Halevy } 5759cbe82603SBenny Halevy 5760863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5761863a3c6cSAndy Adamson struct rpc_rqst *req, 5762863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5763863a3c6cSAndy Adamson { 5764863a3c6cSAndy Adamson __be32 *p; 5765863a3c6cSAndy Adamson __u32 sizechanged; 5766863a3c6cSAndy Adamson int status; 5767863a3c6cSAndy Adamson 5768863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5769db29c089SAndy Adamson res->status = status; 5770863a3c6cSAndy Adamson if (status) 5771863a3c6cSAndy Adamson return status; 5772863a3c6cSAndy Adamson 5773863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5774863a3c6cSAndy Adamson if (unlikely(!p)) 5775863a3c6cSAndy Adamson goto out_overflow; 5776863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5777863a3c6cSAndy Adamson 5778863a3c6cSAndy Adamson if (sizechanged) { 5779863a3c6cSAndy Adamson /* throw away new size */ 5780863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5781863a3c6cSAndy Adamson if (unlikely(!p)) 5782863a3c6cSAndy Adamson goto out_overflow; 5783863a3c6cSAndy Adamson } 5784863a3c6cSAndy Adamson return 0; 5785863a3c6cSAndy Adamson out_overflow: 5786863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 5787863a3c6cSAndy Adamson return -EIO; 5788863a3c6cSAndy Adamson } 57897d974794SBryan Schumaker 57907d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 57917d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 57927d974794SBryan Schumaker { 57937d974794SBryan Schumaker __be32 *p; 57947d974794SBryan Schumaker int status; 57957d974794SBryan Schumaker int num_res; 57967d974794SBryan Schumaker 57977d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 57987d974794SBryan Schumaker if (status) 57997d974794SBryan Schumaker return status; 58007d974794SBryan Schumaker 58017d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 58027d974794SBryan Schumaker if (unlikely(!p)) 58037d974794SBryan Schumaker goto out_overflow; 58047d974794SBryan Schumaker num_res = be32_to_cpup(p++); 58057d974794SBryan Schumaker if (num_res != 1) 58067d974794SBryan Schumaker goto out; 58077d974794SBryan Schumaker 58087d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 58097d974794SBryan Schumaker if (unlikely(!p)) 58107d974794SBryan Schumaker goto out_overflow; 58117d974794SBryan Schumaker res->status = be32_to_cpup(p++); 58121cab0652SBryan Schumaker 58131cab0652SBryan Schumaker return status; 58147d974794SBryan Schumaker out_overflow: 58157d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 58167d974794SBryan Schumaker out: 58177d974794SBryan Schumaker return -EIO; 58187d974794SBryan Schumaker } 58199aeda35fSBryan Schumaker 58209aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 58219aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 58229aeda35fSBryan Schumaker { 58239aeda35fSBryan Schumaker __be32 *p; 58249aeda35fSBryan Schumaker int status; 58259aeda35fSBryan Schumaker 58269aeda35fSBryan Schumaker status = decode_op_hdr(xdr, OP_FREE_STATEID); 58279aeda35fSBryan Schumaker if (status) 58289aeda35fSBryan Schumaker return status; 58299aeda35fSBryan Schumaker 58309aeda35fSBryan Schumaker p = xdr_inline_decode(xdr, 4); 58319aeda35fSBryan Schumaker if (unlikely(!p)) 58329aeda35fSBryan Schumaker goto out_overflow; 58339aeda35fSBryan Schumaker res->status = be32_to_cpup(p++); 58349aeda35fSBryan Schumaker return res->status; 58359aeda35fSBryan Schumaker out_overflow: 58369aeda35fSBryan Schumaker print_overflow_msg(__func__, xdr); 58379aeda35fSBryan Schumaker return -EIO; 58389aeda35fSBryan Schumaker } 5839b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 5840b1f69b75SAndy Adamson 58411da177e4SLinus Torvalds /* 584249c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 584349c2559eSBenny Halevy */ 584449c2559eSBenny Halevy 584549c2559eSBenny Halevy /* 58461da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 58471da177e4SLinus Torvalds */ 5848bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 5849bf269551SChuck Lever struct xdr_stream *xdr, 5850bf269551SChuck Lever struct nfs_closeres *res) 58511da177e4SLinus Torvalds { 58521da177e4SLinus Torvalds struct compound_hdr hdr; 58531da177e4SLinus Torvalds int status; 58541da177e4SLinus Torvalds 5855bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58561da177e4SLinus Torvalds if (status) 58571da177e4SLinus Torvalds goto out; 5858bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58599b7b9fccSAndy Adamson if (status) 58609b7b9fccSAndy Adamson goto out; 5861bf269551SChuck Lever status = decode_putfh(xdr); 58621da177e4SLinus Torvalds if (status) 58631da177e4SLinus Torvalds goto out; 5864bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 5865516a6af6STrond Myklebust if (status != 0) 5866516a6af6STrond Myklebust goto out; 58676926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 58681da177e4SLinus Torvalds out: 58691da177e4SLinus Torvalds return status; 58701da177e4SLinus Torvalds } 58711da177e4SLinus Torvalds 58721da177e4SLinus Torvalds /* 58731da177e4SLinus Torvalds * Decode ACCESS response 58741da177e4SLinus Torvalds */ 5875bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5876bf269551SChuck Lever struct nfs4_accessres *res) 58771da177e4SLinus Torvalds { 58781da177e4SLinus Torvalds struct compound_hdr hdr; 58791da177e4SLinus Torvalds int status; 58801da177e4SLinus Torvalds 5881bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58829b7b9fccSAndy Adamson if (status) 58839b7b9fccSAndy Adamson goto out; 5884bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58859b7b9fccSAndy Adamson if (status) 58861da177e4SLinus Torvalds goto out; 5887bf269551SChuck Lever status = decode_putfh(xdr); 588876b32999STrond Myklebust if (status != 0) 588976b32999STrond Myklebust goto out; 5890bf269551SChuck Lever status = decode_access(xdr, res); 589176b32999STrond Myklebust if (status != 0) 589276b32999STrond Myklebust goto out; 58936926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 58941da177e4SLinus Torvalds out: 58951da177e4SLinus Torvalds return status; 58961da177e4SLinus Torvalds } 58971da177e4SLinus Torvalds 58981da177e4SLinus Torvalds /* 58991da177e4SLinus Torvalds * Decode LOOKUP response 59001da177e4SLinus Torvalds */ 5901bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5902bf269551SChuck Lever struct nfs4_lookup_res *res) 59031da177e4SLinus Torvalds { 59041da177e4SLinus Torvalds struct compound_hdr hdr; 59051da177e4SLinus Torvalds int status; 59061da177e4SLinus Torvalds 5907bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59089b7b9fccSAndy Adamson if (status) 59099b7b9fccSAndy Adamson goto out; 5910bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59119b7b9fccSAndy Adamson if (status) 59121da177e4SLinus Torvalds goto out; 5913bf269551SChuck Lever status = decode_putfh(xdr); 5914bf269551SChuck Lever if (status) 59151da177e4SLinus Torvalds goto out; 5916bf269551SChuck Lever status = decode_lookup(xdr); 5917bf269551SChuck Lever if (status) 59181da177e4SLinus Torvalds goto out; 5919bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5920bf269551SChuck Lever if (status) 59211da177e4SLinus Torvalds goto out; 59226926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 59231da177e4SLinus Torvalds out: 59241da177e4SLinus Torvalds return status; 59251da177e4SLinus Torvalds } 59261da177e4SLinus Torvalds 59271da177e4SLinus Torvalds /* 59281da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 59291da177e4SLinus Torvalds */ 5930bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 5931bf269551SChuck Lever struct xdr_stream *xdr, 5932bf269551SChuck Lever struct nfs4_lookup_res *res) 59331da177e4SLinus Torvalds { 59341da177e4SLinus Torvalds struct compound_hdr hdr; 59351da177e4SLinus Torvalds int status; 59361da177e4SLinus Torvalds 5937bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59389b7b9fccSAndy Adamson if (status) 59399b7b9fccSAndy Adamson goto out; 5940bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59419b7b9fccSAndy Adamson if (status) 59421da177e4SLinus Torvalds goto out; 5943bf269551SChuck Lever status = decode_putrootfh(xdr); 5944bf269551SChuck Lever if (status) 59451da177e4SLinus Torvalds goto out; 5946bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5947bf269551SChuck Lever if (status == 0) 59486926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 59491da177e4SLinus Torvalds out: 59501da177e4SLinus Torvalds return status; 59511da177e4SLinus Torvalds } 59521da177e4SLinus Torvalds 59531da177e4SLinus Torvalds /* 59541da177e4SLinus Torvalds * Decode REMOVE response 59551da177e4SLinus Torvalds */ 5956bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5957bf269551SChuck Lever struct nfs_removeres *res) 59581da177e4SLinus Torvalds { 59591da177e4SLinus Torvalds struct compound_hdr hdr; 59601da177e4SLinus Torvalds int status; 59611da177e4SLinus Torvalds 5962bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59639b7b9fccSAndy Adamson if (status) 59649b7b9fccSAndy Adamson goto out; 5965bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59669b7b9fccSAndy Adamson if (status) 59671da177e4SLinus Torvalds goto out; 5968bf269551SChuck Lever status = decode_putfh(xdr); 5969bf269551SChuck Lever if (status) 597016e42959STrond Myklebust goto out; 5971bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 59721da177e4SLinus Torvalds out: 59731da177e4SLinus Torvalds return status; 59741da177e4SLinus Torvalds } 59751da177e4SLinus Torvalds 59761da177e4SLinus Torvalds /* 59771da177e4SLinus Torvalds * Decode RENAME response 59781da177e4SLinus Torvalds */ 5979bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5980bf269551SChuck Lever struct nfs_renameres *res) 59811da177e4SLinus Torvalds { 59821da177e4SLinus Torvalds struct compound_hdr hdr; 59831da177e4SLinus Torvalds int status; 59841da177e4SLinus Torvalds 5985bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59869b7b9fccSAndy Adamson if (status) 59879b7b9fccSAndy Adamson goto out; 5988bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59899b7b9fccSAndy Adamson if (status) 59901da177e4SLinus Torvalds goto out; 5991bf269551SChuck Lever status = decode_putfh(xdr); 5992bf269551SChuck Lever if (status) 59931da177e4SLinus Torvalds goto out; 5994bf269551SChuck Lever status = decode_savefh(xdr); 5995bf269551SChuck Lever if (status) 59961da177e4SLinus Torvalds goto out; 5997bf269551SChuck Lever status = decode_putfh(xdr); 5998bf269551SChuck Lever if (status) 59991da177e4SLinus Torvalds goto out; 6000bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 60011da177e4SLinus Torvalds out: 60021da177e4SLinus Torvalds return status; 60031da177e4SLinus Torvalds } 60041da177e4SLinus Torvalds 60051da177e4SLinus Torvalds /* 60061da177e4SLinus Torvalds * Decode LINK response 60071da177e4SLinus Torvalds */ 6008bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6009bf269551SChuck Lever struct nfs4_link_res *res) 60101da177e4SLinus Torvalds { 60111da177e4SLinus Torvalds struct compound_hdr hdr; 60121da177e4SLinus Torvalds int status; 60131da177e4SLinus Torvalds 6014bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60159b7b9fccSAndy Adamson if (status) 60169b7b9fccSAndy Adamson goto out; 6017bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60189b7b9fccSAndy Adamson if (status) 60191da177e4SLinus Torvalds goto out; 6020bf269551SChuck Lever status = decode_putfh(xdr); 6021bf269551SChuck Lever if (status) 60221da177e4SLinus Torvalds goto out; 6023bf269551SChuck Lever status = decode_savefh(xdr); 6024bf269551SChuck Lever if (status) 60251da177e4SLinus Torvalds goto out; 6026bf269551SChuck Lever status = decode_putfh(xdr); 6027bf269551SChuck Lever if (status) 60281da177e4SLinus Torvalds goto out; 6029bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6030bf269551SChuck Lever if (status) 603191ba2eeeSTrond Myklebust goto out; 603291ba2eeeSTrond Myklebust /* 603391ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 603491ba2eeeSTrond Myklebust * filehandle. 603591ba2eeeSTrond Myklebust */ 6036bf269551SChuck Lever status = decode_restorefh(xdr); 6037bf269551SChuck Lever if (status) 603891ba2eeeSTrond Myklebust goto out; 60396926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60401da177e4SLinus Torvalds out: 60411da177e4SLinus Torvalds return status; 60421da177e4SLinus Torvalds } 60431da177e4SLinus Torvalds 60441da177e4SLinus Torvalds /* 60451da177e4SLinus Torvalds * Decode CREATE response 60461da177e4SLinus Torvalds */ 6047bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6048bf269551SChuck Lever struct nfs4_create_res *res) 60491da177e4SLinus Torvalds { 60501da177e4SLinus Torvalds struct compound_hdr hdr; 60511da177e4SLinus Torvalds int status; 60521da177e4SLinus Torvalds 6053bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60549b7b9fccSAndy Adamson if (status) 60559b7b9fccSAndy Adamson goto out; 6056bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60579b7b9fccSAndy Adamson if (status) 60581da177e4SLinus Torvalds goto out; 6059bf269551SChuck Lever status = decode_putfh(xdr); 6060bf269551SChuck Lever if (status) 60611da177e4SLinus Torvalds goto out; 6062bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6063bf269551SChuck Lever if (status) 60641da177e4SLinus Torvalds goto out; 6065bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6066bf269551SChuck Lever if (status) 60671da177e4SLinus Torvalds goto out; 60687c317fcfSTrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60691da177e4SLinus Torvalds out: 60701da177e4SLinus Torvalds return status; 60711da177e4SLinus Torvalds } 60721da177e4SLinus Torvalds 60731da177e4SLinus Torvalds /* 60741da177e4SLinus Torvalds * Decode SYMLINK response 60751da177e4SLinus Torvalds */ 6076bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6077bf269551SChuck Lever struct nfs4_create_res *res) 60781da177e4SLinus Torvalds { 6079bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 60801da177e4SLinus Torvalds } 60811da177e4SLinus Torvalds 60821da177e4SLinus Torvalds /* 60831da177e4SLinus Torvalds * Decode GETATTR response 60841da177e4SLinus Torvalds */ 6085bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6086bf269551SChuck Lever struct nfs4_getattr_res *res) 60871da177e4SLinus Torvalds { 60881da177e4SLinus Torvalds struct compound_hdr hdr; 60891da177e4SLinus Torvalds int status; 60901da177e4SLinus Torvalds 6091bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60921da177e4SLinus Torvalds if (status) 60931da177e4SLinus Torvalds goto out; 6094bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60959b7b9fccSAndy Adamson if (status) 60969b7b9fccSAndy Adamson goto out; 6097bf269551SChuck Lever status = decode_putfh(xdr); 60981da177e4SLinus Torvalds if (status) 60991da177e4SLinus Torvalds goto out; 61006926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 61011da177e4SLinus Torvalds out: 61021da177e4SLinus Torvalds return status; 61031da177e4SLinus Torvalds } 61041da177e4SLinus Torvalds 610523ec6965SJ. Bruce Fields /* 610623ec6965SJ. Bruce Fields * Encode an SETACL request 610723ec6965SJ. Bruce Fields */ 61089f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 61099f06c719SChuck Lever struct nfs_setaclargs *args) 611023ec6965SJ. Bruce Fields { 611123ec6965SJ. Bruce Fields struct compound_hdr hdr = { 611266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 611323ec6965SJ. Bruce Fields }; 611423ec6965SJ. Bruce Fields 61159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 61169f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 61179f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 61189f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6119d017931cSAndy Adamson encode_nops(&hdr); 612023ec6965SJ. Bruce Fields } 612105d564feSAndy Adamson 612223ec6965SJ. Bruce Fields /* 612323ec6965SJ. Bruce Fields * Decode SETACL response 612423ec6965SJ. Bruce Fields */ 612523ec6965SJ. Bruce Fields static int 6126bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 612773c403a9SBenny Halevy struct nfs_setaclres *res) 612823ec6965SJ. Bruce Fields { 612923ec6965SJ. Bruce Fields struct compound_hdr hdr; 613023ec6965SJ. Bruce Fields int status; 613123ec6965SJ. Bruce Fields 6132bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 613323ec6965SJ. Bruce Fields if (status) 613423ec6965SJ. Bruce Fields goto out; 6135bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61369b7b9fccSAndy Adamson if (status) 61379b7b9fccSAndy Adamson goto out; 6138bf269551SChuck Lever status = decode_putfh(xdr); 613923ec6965SJ. Bruce Fields if (status) 614023ec6965SJ. Bruce Fields goto out; 6141bf269551SChuck Lever status = decode_setattr(xdr); 614223ec6965SJ. Bruce Fields out: 614323ec6965SJ. Bruce Fields return status; 614423ec6965SJ. Bruce Fields } 61451da177e4SLinus Torvalds 61461da177e4SLinus Torvalds /* 6147029d105eSJ. Bruce Fields * Decode GETACL response 6148029d105eSJ. Bruce Fields */ 6149029d105eSJ. Bruce Fields static int 6150bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6151663c79b3SBenny Halevy struct nfs_getaclres *res) 6152029d105eSJ. Bruce Fields { 6153029d105eSJ. Bruce Fields struct compound_hdr hdr; 6154029d105eSJ. Bruce Fields int status; 6155029d105eSJ. Bruce Fields 6156331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6157331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6158331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6159331818f1STrond Myklebust } 6160bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6161029d105eSJ. Bruce Fields if (status) 6162029d105eSJ. Bruce Fields goto out; 6163bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61649b7b9fccSAndy Adamson if (status) 61659b7b9fccSAndy Adamson goto out; 6166bf269551SChuck Lever status = decode_putfh(xdr); 6167029d105eSJ. Bruce Fields if (status) 6168029d105eSJ. Bruce Fields goto out; 6169bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6170029d105eSJ. Bruce Fields 6171029d105eSJ. Bruce Fields out: 6172029d105eSJ. Bruce Fields return status; 6173029d105eSJ. Bruce Fields } 6174029d105eSJ. Bruce Fields 6175029d105eSJ. Bruce Fields /* 61761da177e4SLinus Torvalds * Decode CLOSE response 61771da177e4SLinus Torvalds */ 6178bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6179bf269551SChuck Lever struct nfs_closeres *res) 61801da177e4SLinus Torvalds { 61811da177e4SLinus Torvalds struct compound_hdr hdr; 61821da177e4SLinus Torvalds int status; 61831da177e4SLinus Torvalds 6184bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61851da177e4SLinus Torvalds if (status) 61861da177e4SLinus Torvalds goto out; 6187bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61889b7b9fccSAndy Adamson if (status) 61899b7b9fccSAndy Adamson goto out; 6190bf269551SChuck Lever status = decode_putfh(xdr); 61911da177e4SLinus Torvalds if (status) 61921da177e4SLinus Torvalds goto out; 6193bf269551SChuck Lever status = decode_close(xdr, res); 6194516a6af6STrond Myklebust if (status != 0) 6195516a6af6STrond Myklebust goto out; 6196516a6af6STrond Myklebust /* 6197516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6198516a6af6STrond Myklebust * in which case the getattr call will fail with 6199516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6200516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6201516a6af6STrond Myklebust */ 62026926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62031da177e4SLinus Torvalds out: 62041da177e4SLinus Torvalds return status; 62051da177e4SLinus Torvalds } 62061da177e4SLinus Torvalds 62071da177e4SLinus Torvalds /* 62081da177e4SLinus Torvalds * Decode OPEN response 62091da177e4SLinus Torvalds */ 6210bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6211bf269551SChuck Lever struct nfs_openres *res) 62121da177e4SLinus Torvalds { 62131da177e4SLinus Torvalds struct compound_hdr hdr; 62141da177e4SLinus Torvalds int status; 62151da177e4SLinus Torvalds 6216bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62171da177e4SLinus Torvalds if (status) 62181da177e4SLinus Torvalds goto out; 6219bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62209b7b9fccSAndy Adamson if (status) 62219b7b9fccSAndy Adamson goto out; 6222bf269551SChuck Lever status = decode_putfh(xdr); 62231da177e4SLinus Torvalds if (status) 62241da177e4SLinus Torvalds goto out; 6225bf269551SChuck Lever status = decode_open(xdr, res); 62261da177e4SLinus Torvalds if (status) 62271da177e4SLinus Torvalds goto out; 6228bf269551SChuck Lever if (decode_getfh(xdr, &res->fh) != 0) 62291da177e4SLinus Torvalds goto out; 623090ff0c54STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 62311da177e4SLinus Torvalds out: 62321da177e4SLinus Torvalds return status; 62331da177e4SLinus Torvalds } 62341da177e4SLinus Torvalds 62351da177e4SLinus Torvalds /* 62361da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 62371da177e4SLinus Torvalds */ 6238bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6239bf269551SChuck Lever struct xdr_stream *xdr, 6240bf269551SChuck Lever struct nfs_open_confirmres *res) 62411da177e4SLinus Torvalds { 62421da177e4SLinus Torvalds struct compound_hdr hdr; 62431da177e4SLinus Torvalds int status; 62441da177e4SLinus Torvalds 6245bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62461da177e4SLinus Torvalds if (status) 62471da177e4SLinus Torvalds goto out; 6248bf269551SChuck Lever status = decode_putfh(xdr); 62491da177e4SLinus Torvalds if (status) 62501da177e4SLinus Torvalds goto out; 6251bf269551SChuck Lever status = decode_open_confirm(xdr, res); 62521da177e4SLinus Torvalds out: 62531da177e4SLinus Torvalds return status; 62541da177e4SLinus Torvalds } 62551da177e4SLinus Torvalds 62561da177e4SLinus Torvalds /* 62571da177e4SLinus Torvalds * Decode OPEN response 62581da177e4SLinus Torvalds */ 6259bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6260bf269551SChuck Lever struct xdr_stream *xdr, 6261bf269551SChuck Lever struct nfs_openres *res) 62621da177e4SLinus Torvalds { 62631da177e4SLinus Torvalds struct compound_hdr hdr; 62641da177e4SLinus Torvalds int status; 62651da177e4SLinus Torvalds 6266bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62671da177e4SLinus Torvalds if (status) 62681da177e4SLinus Torvalds goto out; 6269bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62709b7b9fccSAndy Adamson if (status) 62719b7b9fccSAndy Adamson goto out; 6272bf269551SChuck Lever status = decode_putfh(xdr); 62731da177e4SLinus Torvalds if (status) 62741da177e4SLinus Torvalds goto out; 6275bf269551SChuck Lever status = decode_open(xdr, res); 6276864472e9STrond Myklebust if (status) 6277864472e9STrond Myklebust goto out; 62786926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 62791da177e4SLinus Torvalds out: 62801da177e4SLinus Torvalds return status; 62811da177e4SLinus Torvalds } 62821da177e4SLinus Torvalds 62831da177e4SLinus Torvalds /* 62841da177e4SLinus Torvalds * Decode SETATTR response 62851da177e4SLinus Torvalds */ 6286bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6287bf269551SChuck Lever struct xdr_stream *xdr, 6288bf269551SChuck Lever struct nfs_setattrres *res) 62891da177e4SLinus Torvalds { 62901da177e4SLinus Torvalds struct compound_hdr hdr; 62911da177e4SLinus Torvalds int status; 62921da177e4SLinus Torvalds 6293bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62941da177e4SLinus Torvalds if (status) 62951da177e4SLinus Torvalds goto out; 6296bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62979b7b9fccSAndy Adamson if (status) 62989b7b9fccSAndy Adamson goto out; 6299bf269551SChuck Lever status = decode_putfh(xdr); 63001da177e4SLinus Torvalds if (status) 63011da177e4SLinus Torvalds goto out; 6302bf269551SChuck Lever status = decode_setattr(xdr); 63031da177e4SLinus Torvalds if (status) 63041da177e4SLinus Torvalds goto out; 63056926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63061da177e4SLinus Torvalds out: 63071da177e4SLinus Torvalds return status; 63081da177e4SLinus Torvalds } 63091da177e4SLinus Torvalds 63101da177e4SLinus Torvalds /* 63111da177e4SLinus Torvalds * Decode LOCK response 63121da177e4SLinus Torvalds */ 6313bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6314bf269551SChuck Lever struct nfs_lock_res *res) 63151da177e4SLinus Torvalds { 63161da177e4SLinus Torvalds struct compound_hdr hdr; 63171da177e4SLinus Torvalds int status; 63181da177e4SLinus Torvalds 6319bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63201da177e4SLinus Torvalds if (status) 63211da177e4SLinus Torvalds goto out; 6322bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63239b7b9fccSAndy Adamson if (status) 63249b7b9fccSAndy Adamson goto out; 6325bf269551SChuck Lever status = decode_putfh(xdr); 63261da177e4SLinus Torvalds if (status) 63271da177e4SLinus Torvalds goto out; 6328bf269551SChuck Lever status = decode_lock(xdr, res); 63291da177e4SLinus Torvalds out: 63301da177e4SLinus Torvalds return status; 63311da177e4SLinus Torvalds } 63321da177e4SLinus Torvalds 63331da177e4SLinus Torvalds /* 63341da177e4SLinus Torvalds * Decode LOCKT response 63351da177e4SLinus Torvalds */ 6336bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6337bf269551SChuck Lever struct nfs_lockt_res *res) 63381da177e4SLinus Torvalds { 63391da177e4SLinus Torvalds struct compound_hdr hdr; 63401da177e4SLinus Torvalds int status; 63411da177e4SLinus Torvalds 6342bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63431da177e4SLinus Torvalds if (status) 63441da177e4SLinus Torvalds goto out; 6345bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63469b7b9fccSAndy Adamson if (status) 63479b7b9fccSAndy Adamson goto out; 6348bf269551SChuck Lever status = decode_putfh(xdr); 63491da177e4SLinus Torvalds if (status) 63501da177e4SLinus Torvalds goto out; 6351bf269551SChuck Lever status = decode_lockt(xdr, res); 63521da177e4SLinus Torvalds out: 63531da177e4SLinus Torvalds return status; 63541da177e4SLinus Torvalds } 63551da177e4SLinus Torvalds 63561da177e4SLinus Torvalds /* 63571da177e4SLinus Torvalds * Decode LOCKU response 63581da177e4SLinus Torvalds */ 6359bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6360bf269551SChuck Lever struct nfs_locku_res *res) 63611da177e4SLinus Torvalds { 63621da177e4SLinus Torvalds struct compound_hdr hdr; 63631da177e4SLinus Torvalds int status; 63641da177e4SLinus Torvalds 6365bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63661da177e4SLinus Torvalds if (status) 63671da177e4SLinus Torvalds goto out; 6368bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63699b7b9fccSAndy Adamson if (status) 63709b7b9fccSAndy Adamson goto out; 6371bf269551SChuck Lever status = decode_putfh(xdr); 63721da177e4SLinus Torvalds if (status) 63731da177e4SLinus Torvalds goto out; 6374bf269551SChuck Lever status = decode_locku(xdr, res); 63751da177e4SLinus Torvalds out: 63761da177e4SLinus Torvalds return status; 63771da177e4SLinus Torvalds } 63781da177e4SLinus Torvalds 6379bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6380bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6381d3c7b7ccSTrond Myklebust { 6382d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6383d3c7b7ccSTrond Myklebust int status; 6384d3c7b7ccSTrond Myklebust 6385bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6386d3c7b7ccSTrond Myklebust if (!status) 6387bf269551SChuck Lever status = decode_release_lockowner(xdr); 6388d3c7b7ccSTrond Myklebust return status; 6389d3c7b7ccSTrond Myklebust } 6390d3c7b7ccSTrond Myklebust 63911da177e4SLinus Torvalds /* 63921da177e4SLinus Torvalds * Decode READLINK response 63931da177e4SLinus Torvalds */ 6394bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6395bf269551SChuck Lever struct xdr_stream *xdr, 6396f50c7000SBenny Halevy struct nfs4_readlink_res *res) 63971da177e4SLinus Torvalds { 63981da177e4SLinus Torvalds struct compound_hdr hdr; 63991da177e4SLinus Torvalds int status; 64001da177e4SLinus Torvalds 6401bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64021da177e4SLinus Torvalds if (status) 64031da177e4SLinus Torvalds goto out; 6404bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64059b7b9fccSAndy Adamson if (status) 64069b7b9fccSAndy Adamson goto out; 6407bf269551SChuck Lever status = decode_putfh(xdr); 64081da177e4SLinus Torvalds if (status) 64091da177e4SLinus Torvalds goto out; 6410bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 64111da177e4SLinus Torvalds out: 64121da177e4SLinus Torvalds return status; 64131da177e4SLinus Torvalds } 64141da177e4SLinus Torvalds 64151da177e4SLinus Torvalds /* 64161da177e4SLinus Torvalds * Decode READDIR response 64171da177e4SLinus Torvalds */ 6418bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6419bf269551SChuck Lever struct nfs4_readdir_res *res) 64201da177e4SLinus Torvalds { 64211da177e4SLinus Torvalds struct compound_hdr hdr; 64221da177e4SLinus Torvalds int status; 64231da177e4SLinus Torvalds 6424bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64251da177e4SLinus Torvalds if (status) 64261da177e4SLinus Torvalds goto out; 6427bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64289b7b9fccSAndy Adamson if (status) 64299b7b9fccSAndy Adamson goto out; 6430bf269551SChuck Lever status = decode_putfh(xdr); 64311da177e4SLinus Torvalds if (status) 64321da177e4SLinus Torvalds goto out; 6433bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 64341da177e4SLinus Torvalds out: 64351da177e4SLinus Torvalds return status; 64361da177e4SLinus Torvalds } 64371da177e4SLinus Torvalds 64381da177e4SLinus Torvalds /* 64391da177e4SLinus Torvalds * Decode Read response 64401da177e4SLinus Torvalds */ 6441bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6442bf269551SChuck Lever struct nfs_readres *res) 64431da177e4SLinus Torvalds { 64441da177e4SLinus Torvalds struct compound_hdr hdr; 64451da177e4SLinus Torvalds int status; 64461da177e4SLinus Torvalds 6447bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64481da177e4SLinus Torvalds if (status) 64491da177e4SLinus Torvalds goto out; 6450bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64519b7b9fccSAndy Adamson if (status) 64529b7b9fccSAndy Adamson goto out; 6453bf269551SChuck Lever status = decode_putfh(xdr); 64541da177e4SLinus Torvalds if (status) 64551da177e4SLinus Torvalds goto out; 6456bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 64571da177e4SLinus Torvalds if (!status) 64581da177e4SLinus Torvalds status = res->count; 64591da177e4SLinus Torvalds out: 64601da177e4SLinus Torvalds return status; 64611da177e4SLinus Torvalds } 64621da177e4SLinus Torvalds 64631da177e4SLinus Torvalds /* 64641da177e4SLinus Torvalds * Decode WRITE response 64651da177e4SLinus Torvalds */ 6466bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6467bf269551SChuck Lever struct nfs_writeres *res) 64681da177e4SLinus Torvalds { 64691da177e4SLinus Torvalds struct compound_hdr hdr; 64701da177e4SLinus Torvalds int status; 64711da177e4SLinus Torvalds 6472bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64731da177e4SLinus Torvalds if (status) 64741da177e4SLinus Torvalds goto out; 6475bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64769b7b9fccSAndy Adamson if (status) 64779b7b9fccSAndy Adamson goto out; 6478bf269551SChuck Lever status = decode_putfh(xdr); 64791da177e4SLinus Torvalds if (status) 64801da177e4SLinus Torvalds goto out; 6481bf269551SChuck Lever status = decode_write(xdr, res); 64824f9838c7STrond Myklebust if (status) 64834f9838c7STrond Myklebust goto out; 64847ffd1064SFred Isaman if (res->fattr) 64856926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 64861da177e4SLinus Torvalds if (!status) 64871da177e4SLinus Torvalds status = res->count; 64881da177e4SLinus Torvalds out: 64891da177e4SLinus Torvalds return status; 64901da177e4SLinus Torvalds } 64911da177e4SLinus Torvalds 64921da177e4SLinus Torvalds /* 64931da177e4SLinus Torvalds * Decode COMMIT response 64941da177e4SLinus Torvalds */ 6495bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 64960b7c0153SFred Isaman struct nfs_commitres *res) 64971da177e4SLinus Torvalds { 64981da177e4SLinus Torvalds struct compound_hdr hdr; 64991da177e4SLinus Torvalds int status; 65001da177e4SLinus Torvalds 6501bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65021da177e4SLinus Torvalds if (status) 65031da177e4SLinus Torvalds goto out; 6504bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65059b7b9fccSAndy Adamson if (status) 65069b7b9fccSAndy Adamson goto out; 6507bf269551SChuck Lever status = decode_putfh(xdr); 65081da177e4SLinus Torvalds if (status) 65091da177e4SLinus Torvalds goto out; 6510bf269551SChuck Lever status = decode_commit(xdr, res); 65111da177e4SLinus Torvalds out: 65121da177e4SLinus Torvalds return status; 65131da177e4SLinus Torvalds } 65141da177e4SLinus Torvalds 65151da177e4SLinus Torvalds /* 65168b173218SRicardo Labiaga * Decode FSINFO response 65171da177e4SLinus Torvalds */ 6518bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 65193dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 65201da177e4SLinus Torvalds { 65211da177e4SLinus Torvalds struct compound_hdr hdr; 65221da177e4SLinus Torvalds int status; 65231da177e4SLinus Torvalds 6524bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65251da177e4SLinus Torvalds if (!status) 6526bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65279b7b9fccSAndy Adamson if (!status) 6528bf269551SChuck Lever status = decode_putfh(xdr); 65291da177e4SLinus Torvalds if (!status) 6530bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 65311da177e4SLinus Torvalds return status; 65321da177e4SLinus Torvalds } 65331da177e4SLinus Torvalds 65341da177e4SLinus Torvalds /* 65358b173218SRicardo Labiaga * Decode PATHCONF response 65361da177e4SLinus Torvalds */ 6537bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6538d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 65391da177e4SLinus Torvalds { 65401da177e4SLinus Torvalds struct compound_hdr hdr; 65411da177e4SLinus Torvalds int status; 65421da177e4SLinus Torvalds 6543bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65441da177e4SLinus Torvalds if (!status) 6545bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65469b7b9fccSAndy Adamson if (!status) 6547bf269551SChuck Lever status = decode_putfh(xdr); 65481da177e4SLinus Torvalds if (!status) 6549bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 65501da177e4SLinus Torvalds return status; 65511da177e4SLinus Torvalds } 65521da177e4SLinus Torvalds 65531da177e4SLinus Torvalds /* 65548b173218SRicardo Labiaga * Decode STATFS response 65551da177e4SLinus Torvalds */ 6556bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 655724ad148aSBenny Halevy struct nfs4_statfs_res *res) 65581da177e4SLinus Torvalds { 65591da177e4SLinus Torvalds struct compound_hdr hdr; 65601da177e4SLinus Torvalds int status; 65611da177e4SLinus Torvalds 6562bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65631da177e4SLinus Torvalds if (!status) 6564bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65659b7b9fccSAndy Adamson if (!status) 6566bf269551SChuck Lever status = decode_putfh(xdr); 65671da177e4SLinus Torvalds if (!status) 6568bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 65691da177e4SLinus Torvalds return status; 65701da177e4SLinus Torvalds } 65711da177e4SLinus Torvalds 65721da177e4SLinus Torvalds /* 65738b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 65741da177e4SLinus Torvalds */ 6575bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6576bf269551SChuck Lever struct xdr_stream *xdr, 6577bf269551SChuck Lever struct nfs4_server_caps_res *res) 65781da177e4SLinus Torvalds { 65791da177e4SLinus Torvalds struct compound_hdr hdr; 65801da177e4SLinus Torvalds int status; 65811da177e4SLinus Torvalds 6582bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65839b7b9fccSAndy Adamson if (status) 65849b7b9fccSAndy Adamson goto out; 6585bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65869b7b9fccSAndy Adamson if (status) 65871da177e4SLinus Torvalds goto out; 6588bf269551SChuck Lever status = decode_putfh(xdr); 6589bf269551SChuck Lever if (status) 65901da177e4SLinus Torvalds goto out; 6591bf269551SChuck Lever status = decode_server_caps(xdr, res); 65921da177e4SLinus Torvalds out: 65931da177e4SLinus Torvalds return status; 65941da177e4SLinus Torvalds } 65951da177e4SLinus Torvalds 65961da177e4SLinus Torvalds /* 65971da177e4SLinus Torvalds * Decode RENEW response 65981da177e4SLinus Torvalds */ 6599bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6600bf269551SChuck Lever void *__unused) 66011da177e4SLinus Torvalds { 66021da177e4SLinus Torvalds struct compound_hdr hdr; 66031da177e4SLinus Torvalds int status; 66041da177e4SLinus Torvalds 6605bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66061da177e4SLinus Torvalds if (!status) 6607bf269551SChuck Lever status = decode_renew(xdr); 66081da177e4SLinus Torvalds return status; 66091da177e4SLinus Torvalds } 66101da177e4SLinus Torvalds 66111da177e4SLinus Torvalds /* 66128b173218SRicardo Labiaga * Decode SETCLIENTID response 66131da177e4SLinus Torvalds */ 6614bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6615bf269551SChuck Lever struct xdr_stream *xdr, 6616bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 66171da177e4SLinus Torvalds { 66181da177e4SLinus Torvalds struct compound_hdr hdr; 66191da177e4SLinus Torvalds int status; 66201da177e4SLinus Torvalds 6621bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66221da177e4SLinus Torvalds if (!status) 6623bf269551SChuck Lever status = decode_setclientid(xdr, res); 66241da177e4SLinus Torvalds return status; 66251da177e4SLinus Torvalds } 66261da177e4SLinus Torvalds 66271da177e4SLinus Torvalds /* 66288b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 66291da177e4SLinus Torvalds */ 6630bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 6631bf269551SChuck Lever struct xdr_stream *xdr, 6632bf269551SChuck Lever struct nfs_fsinfo *fsinfo) 66331da177e4SLinus Torvalds { 66341da177e4SLinus Torvalds struct compound_hdr hdr; 66351da177e4SLinus Torvalds int status; 66361da177e4SLinus Torvalds 6637bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66381da177e4SLinus Torvalds if (!status) 6639bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 66401da177e4SLinus Torvalds if (!status) 6641bf269551SChuck Lever status = decode_putrootfh(xdr); 66421da177e4SLinus Torvalds if (!status) 6643bf269551SChuck Lever status = decode_fsinfo(xdr, fsinfo); 66441da177e4SLinus Torvalds return status; 66451da177e4SLinus Torvalds } 66461da177e4SLinus Torvalds 66471da177e4SLinus Torvalds /* 66488b173218SRicardo Labiaga * Decode DELEGRETURN response 66491da177e4SLinus Torvalds */ 6650bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6651bf269551SChuck Lever struct xdr_stream *xdr, 6652bf269551SChuck Lever struct nfs4_delegreturnres *res) 66531da177e4SLinus Torvalds { 66541da177e4SLinus Torvalds struct compound_hdr hdr; 66551da177e4SLinus Torvalds int status; 66561da177e4SLinus Torvalds 6657bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66589b7b9fccSAndy Adamson if (status) 66599b7b9fccSAndy Adamson goto out; 6660bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66619b7b9fccSAndy Adamson if (status) 6662fa178f29STrond Myklebust goto out; 6663bf269551SChuck Lever status = decode_putfh(xdr); 6664fa178f29STrond Myklebust if (status != 0) 6665fa178f29STrond Myklebust goto out; 6666e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6667556ae3bbSJeff Layton if (status != 0) 6668556ae3bbSJeff Layton goto out; 6669e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6670fa178f29STrond Myklebust out: 66711da177e4SLinus Torvalds return status; 66721da177e4SLinus Torvalds } 66731da177e4SLinus Torvalds 6674683b57b4STrond Myklebust /* 66758b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6676683b57b4STrond Myklebust */ 6677bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6678bf269551SChuck Lever struct xdr_stream *xdr, 667922958463SBenny Halevy struct nfs4_fs_locations_res *res) 6680683b57b4STrond Myklebust { 6681683b57b4STrond Myklebust struct compound_hdr hdr; 6682683b57b4STrond Myklebust int status; 6683683b57b4STrond Myklebust 6684bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66859b7b9fccSAndy Adamson if (status) 66869b7b9fccSAndy Adamson goto out; 6687bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 66889b7b9fccSAndy Adamson if (status) 6689683b57b4STrond Myklebust goto out; 6690bf269551SChuck Lever status = decode_putfh(xdr); 6691bf269551SChuck Lever if (status) 6692683b57b4STrond Myklebust goto out; 6693bf269551SChuck Lever status = decode_lookup(xdr); 6694bf269551SChuck Lever if (status) 6695683b57b4STrond Myklebust goto out; 6696bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 66978b7e3f49STrond Myklebust status = decode_getfattr_generic(xdr, &res->fs_locations->fattr, 66988b7e3f49STrond Myklebust NULL, res->fs_locations, 66996926afd1STrond Myklebust res->fs_locations->server); 6700683b57b4STrond Myklebust out: 6701683b57b4STrond Myklebust return status; 6702683b57b4STrond Myklebust } 6703683b57b4STrond Myklebust 67045a5ea0d4SBryan Schumaker /* 67055a5ea0d4SBryan Schumaker * Decode SECINFO response 67065a5ea0d4SBryan Schumaker */ 67075a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 67085a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 67095a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 67105a5ea0d4SBryan Schumaker { 67115a5ea0d4SBryan Schumaker struct compound_hdr hdr; 67125a5ea0d4SBryan Schumaker int status; 67135a5ea0d4SBryan Schumaker 67145a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 67155a5ea0d4SBryan Schumaker if (status) 67165a5ea0d4SBryan Schumaker goto out; 67175a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 67185a5ea0d4SBryan Schumaker if (status) 67195a5ea0d4SBryan Schumaker goto out; 67205a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 67215a5ea0d4SBryan Schumaker if (status) 67225a5ea0d4SBryan Schumaker goto out; 67235a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 67245a5ea0d4SBryan Schumaker out: 67255a5ea0d4SBryan Schumaker return status; 67265a5ea0d4SBryan Schumaker } 67275a5ea0d4SBryan Schumaker 672899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 672999fe60d0SBenny Halevy /* 67307c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 67317c44f1aeSWeston Andros Adamson */ 67327c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 67337c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 67347c44f1aeSWeston Andros Adamson void *res) 67357c44f1aeSWeston Andros Adamson { 67367c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 67377c44f1aeSWeston Andros Adamson int status; 67387c44f1aeSWeston Andros Adamson 67397c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 67407c44f1aeSWeston Andros Adamson if (!status) 67417c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 67427c44f1aeSWeston Andros Adamson return status; 67437c44f1aeSWeston Andros Adamson } 67447c44f1aeSWeston Andros Adamson 67457c44f1aeSWeston Andros Adamson /* 67468b173218SRicardo Labiaga * Decode EXCHANGE_ID response 674799fe60d0SBenny Halevy */ 6748bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 6749bf269551SChuck Lever struct xdr_stream *xdr, 675099fe60d0SBenny Halevy void *res) 675199fe60d0SBenny Halevy { 675299fe60d0SBenny Halevy struct compound_hdr hdr; 675399fe60d0SBenny Halevy int status; 675499fe60d0SBenny Halevy 6755bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 675699fe60d0SBenny Halevy if (!status) 6757bf269551SChuck Lever status = decode_exchange_id(xdr, res); 675899fe60d0SBenny Halevy return status; 675999fe60d0SBenny Halevy } 67602050f0ccSAndy Adamson 67612050f0ccSAndy Adamson /* 67628b173218SRicardo Labiaga * Decode CREATE_SESSION response 6763fc931582SAndy Adamson */ 6764bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 6765bf269551SChuck Lever struct xdr_stream *xdr, 6766fc931582SAndy Adamson struct nfs41_create_session_res *res) 6767fc931582SAndy Adamson { 6768fc931582SAndy Adamson struct compound_hdr hdr; 6769fc931582SAndy Adamson int status; 6770fc931582SAndy Adamson 6771bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6772fc931582SAndy Adamson if (!status) 6773bf269551SChuck Lever status = decode_create_session(xdr, res); 6774fc931582SAndy Adamson return status; 6775fc931582SAndy Adamson } 6776fc931582SAndy Adamson 6777fc931582SAndy Adamson /* 67788b173218SRicardo Labiaga * Decode DESTROY_SESSION response 67790f3e66c6SAndy Adamson */ 6780bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 6781bf269551SChuck Lever struct xdr_stream *xdr, 6782bf269551SChuck Lever void *res) 67830f3e66c6SAndy Adamson { 67840f3e66c6SAndy Adamson struct compound_hdr hdr; 67850f3e66c6SAndy Adamson int status; 67860f3e66c6SAndy Adamson 6787bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67880f3e66c6SAndy Adamson if (!status) 6789bf269551SChuck Lever status = decode_destroy_session(xdr, res); 67900f3e66c6SAndy Adamson return status; 67910f3e66c6SAndy Adamson } 67920f3e66c6SAndy Adamson 67930f3e66c6SAndy Adamson /* 679466245539STrond Myklebust * Decode DESTROY_CLIENTID response 679566245539STrond Myklebust */ 679666245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 679766245539STrond Myklebust struct xdr_stream *xdr, 679866245539STrond Myklebust void *res) 679966245539STrond Myklebust { 680066245539STrond Myklebust struct compound_hdr hdr; 680166245539STrond Myklebust int status; 680266245539STrond Myklebust 680366245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 680466245539STrond Myklebust if (!status) 680566245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 680666245539STrond Myklebust return status; 680766245539STrond Myklebust } 680866245539STrond Myklebust 680966245539STrond Myklebust /* 68108b173218SRicardo Labiaga * Decode SEQUENCE response 6811fc01cea9SAndy Adamson */ 6812bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 6813bf269551SChuck Lever struct xdr_stream *xdr, 6814fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 6815fc01cea9SAndy Adamson { 6816fc01cea9SAndy Adamson struct compound_hdr hdr; 6817fc01cea9SAndy Adamson int status; 6818fc01cea9SAndy Adamson 6819bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6820fc01cea9SAndy Adamson if (!status) 6821bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 6822fc01cea9SAndy Adamson return status; 6823fc01cea9SAndy Adamson } 6824fc01cea9SAndy Adamson 6825fc01cea9SAndy Adamson /* 68268b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 68272050f0ccSAndy Adamson */ 6828bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 6829bf269551SChuck Lever struct xdr_stream *xdr, 68302050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 68312050f0ccSAndy Adamson { 68322050f0ccSAndy Adamson struct compound_hdr hdr; 68332050f0ccSAndy Adamson int status; 68342050f0ccSAndy Adamson 6835bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68362050f0ccSAndy Adamson if (!status) 6837bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 68382050f0ccSAndy Adamson if (!status) 6839bf269551SChuck Lever status = decode_putrootfh(xdr); 68402050f0ccSAndy Adamson if (!status) 6841bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 68422050f0ccSAndy Adamson return status; 68432050f0ccSAndy Adamson } 684418019753SRicardo Labiaga 684518019753SRicardo Labiaga /* 684618019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 684718019753SRicardo Labiaga */ 6848bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 6849bf269551SChuck Lever struct xdr_stream *xdr, 685018019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 685118019753SRicardo Labiaga { 685218019753SRicardo Labiaga struct compound_hdr hdr; 685318019753SRicardo Labiaga int status; 685418019753SRicardo Labiaga 6855bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 685618019753SRicardo Labiaga if (!status) 6857bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 685818019753SRicardo Labiaga if (!status) 6859bf269551SChuck Lever status = decode_reclaim_complete(xdr, (void *)NULL); 686018019753SRicardo Labiaga return status; 686118019753SRicardo Labiaga } 6862b1f69b75SAndy Adamson 6863b1f69b75SAndy Adamson /* 68647f11d8d3SAndy Adamson * Decode GETDEVICELIST response 68657f11d8d3SAndy Adamson */ 68667f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp, 68677f11d8d3SAndy Adamson struct xdr_stream *xdr, 68687f11d8d3SAndy Adamson struct nfs4_getdevicelist_res *res) 68697f11d8d3SAndy Adamson { 68707f11d8d3SAndy Adamson struct compound_hdr hdr; 68717f11d8d3SAndy Adamson int status; 68727f11d8d3SAndy Adamson 68737f11d8d3SAndy Adamson dprintk("encoding getdevicelist!\n"); 68747f11d8d3SAndy Adamson 68757f11d8d3SAndy Adamson status = decode_compound_hdr(xdr, &hdr); 68767f11d8d3SAndy Adamson if (status != 0) 68777f11d8d3SAndy Adamson goto out; 68787f11d8d3SAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 68797f11d8d3SAndy Adamson if (status != 0) 68807f11d8d3SAndy Adamson goto out; 68817f11d8d3SAndy Adamson status = decode_putfh(xdr); 68827f11d8d3SAndy Adamson if (status != 0) 68837f11d8d3SAndy Adamson goto out; 68847f11d8d3SAndy Adamson status = decode_getdevicelist(xdr, res->devlist); 68857f11d8d3SAndy Adamson out: 68867f11d8d3SAndy Adamson return status; 68877f11d8d3SAndy Adamson } 68887f11d8d3SAndy Adamson 68897f11d8d3SAndy Adamson /* 6890b1f69b75SAndy Adamson * Decode GETDEVINFO response 6891b1f69b75SAndy Adamson */ 6892bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 6893bf269551SChuck Lever struct xdr_stream *xdr, 6894b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 6895b1f69b75SAndy Adamson { 6896b1f69b75SAndy Adamson struct compound_hdr hdr; 6897b1f69b75SAndy Adamson int status; 6898b1f69b75SAndy Adamson 6899bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6900b1f69b75SAndy Adamson if (status != 0) 6901b1f69b75SAndy Adamson goto out; 6902bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6903b1f69b75SAndy Adamson if (status != 0) 6904b1f69b75SAndy Adamson goto out; 6905bf269551SChuck Lever status = decode_getdeviceinfo(xdr, res->pdev); 6906b1f69b75SAndy Adamson out: 6907b1f69b75SAndy Adamson return status; 6908b1f69b75SAndy Adamson } 6909b1f69b75SAndy Adamson 6910b1f69b75SAndy Adamson /* 6911b1f69b75SAndy Adamson * Decode LAYOUTGET response 6912b1f69b75SAndy Adamson */ 6913bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 6914bf269551SChuck Lever struct xdr_stream *xdr, 6915b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6916b1f69b75SAndy Adamson { 6917b1f69b75SAndy Adamson struct compound_hdr hdr; 6918b1f69b75SAndy Adamson int status; 6919b1f69b75SAndy Adamson 6920bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6921b1f69b75SAndy Adamson if (status) 6922b1f69b75SAndy Adamson goto out; 6923bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6924b1f69b75SAndy Adamson if (status) 6925b1f69b75SAndy Adamson goto out; 6926bf269551SChuck Lever status = decode_putfh(xdr); 6927b1f69b75SAndy Adamson if (status) 6928b1f69b75SAndy Adamson goto out; 6929bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 6930b1f69b75SAndy Adamson out: 6931b1f69b75SAndy Adamson return status; 6932b1f69b75SAndy Adamson } 6933863a3c6cSAndy Adamson 6934863a3c6cSAndy Adamson /* 6935cbe82603SBenny Halevy * Decode LAYOUTRETURN response 6936cbe82603SBenny Halevy */ 6937cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 6938cbe82603SBenny Halevy struct xdr_stream *xdr, 6939cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6940cbe82603SBenny Halevy { 6941cbe82603SBenny Halevy struct compound_hdr hdr; 6942cbe82603SBenny Halevy int status; 6943cbe82603SBenny Halevy 6944cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 6945cbe82603SBenny Halevy if (status) 6946cbe82603SBenny Halevy goto out; 6947cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 6948cbe82603SBenny Halevy if (status) 6949cbe82603SBenny Halevy goto out; 6950cbe82603SBenny Halevy status = decode_putfh(xdr); 6951cbe82603SBenny Halevy if (status) 6952cbe82603SBenny Halevy goto out; 6953cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 6954cbe82603SBenny Halevy out: 6955cbe82603SBenny Halevy return status; 6956cbe82603SBenny Halevy } 6957cbe82603SBenny Halevy 6958cbe82603SBenny Halevy /* 6959863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 6960863a3c6cSAndy Adamson */ 6961863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 6962863a3c6cSAndy Adamson struct xdr_stream *xdr, 6963863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6964863a3c6cSAndy Adamson { 6965863a3c6cSAndy Adamson struct compound_hdr hdr; 6966863a3c6cSAndy Adamson int status; 6967863a3c6cSAndy Adamson 6968863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 6969863a3c6cSAndy Adamson if (status) 6970863a3c6cSAndy Adamson goto out; 6971863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 6972863a3c6cSAndy Adamson if (status) 6973863a3c6cSAndy Adamson goto out; 6974863a3c6cSAndy Adamson status = decode_putfh(xdr); 6975863a3c6cSAndy Adamson if (status) 6976863a3c6cSAndy Adamson goto out; 6977863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 6978863a3c6cSAndy Adamson if (status) 6979863a3c6cSAndy Adamson goto out; 69806926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 6981863a3c6cSAndy Adamson out: 6982863a3c6cSAndy Adamson return status; 6983863a3c6cSAndy Adamson } 6984fca78d6dSBryan Schumaker 6985fca78d6dSBryan Schumaker /* 6986fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 6987fca78d6dSBryan Schumaker */ 6988fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 6989fca78d6dSBryan Schumaker struct xdr_stream *xdr, 6990fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 6991fca78d6dSBryan Schumaker { 6992fca78d6dSBryan Schumaker struct compound_hdr hdr; 6993fca78d6dSBryan Schumaker int status; 6994fca78d6dSBryan Schumaker 6995fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 6996fca78d6dSBryan Schumaker if (status) 6997fca78d6dSBryan Schumaker goto out; 6998fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 6999fca78d6dSBryan Schumaker if (status) 7000fca78d6dSBryan Schumaker goto out; 7001fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7002fca78d6dSBryan Schumaker if (status) 7003fca78d6dSBryan Schumaker goto out; 700431e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7005fca78d6dSBryan Schumaker out: 7006fca78d6dSBryan Schumaker return status; 7007fca78d6dSBryan Schumaker } 70087d974794SBryan Schumaker 70097d974794SBryan Schumaker /* 70107d974794SBryan Schumaker * Decode TEST_STATEID response 70117d974794SBryan Schumaker */ 70127d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 70137d974794SBryan Schumaker struct xdr_stream *xdr, 70147d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 70157d974794SBryan Schumaker { 70167d974794SBryan Schumaker struct compound_hdr hdr; 70177d974794SBryan Schumaker int status; 70187d974794SBryan Schumaker 70197d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 70207d974794SBryan Schumaker if (status) 70217d974794SBryan Schumaker goto out; 70227d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 70237d974794SBryan Schumaker if (status) 70247d974794SBryan Schumaker goto out; 70257d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 70267d974794SBryan Schumaker out: 70277d974794SBryan Schumaker return status; 70287d974794SBryan Schumaker } 70299aeda35fSBryan Schumaker 70309aeda35fSBryan Schumaker /* 70319aeda35fSBryan Schumaker * Decode FREE_STATEID response 70329aeda35fSBryan Schumaker */ 70339aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 70349aeda35fSBryan Schumaker struct xdr_stream *xdr, 70359aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 70369aeda35fSBryan Schumaker { 70379aeda35fSBryan Schumaker struct compound_hdr hdr; 70389aeda35fSBryan Schumaker int status; 70399aeda35fSBryan Schumaker 70409aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 70419aeda35fSBryan Schumaker if (status) 70429aeda35fSBryan Schumaker goto out; 70439aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 70449aeda35fSBryan Schumaker if (status) 70459aeda35fSBryan Schumaker goto out; 70469aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 70479aeda35fSBryan Schumaker out: 70489aeda35fSBryan Schumaker return status; 70499aeda35fSBryan Schumaker } 705099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 705199fe60d0SBenny Halevy 7052573c4e1eSChuck Lever /** 7053573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7054573c4e1eSChuck Lever * the local page cache. 7055573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7056573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7057573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7058573c4e1eSChuck Lever * 7059573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7060573c4e1eSChuck Lever * returned. 7061573c4e1eSChuck Lever * 7062573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7063573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7064573c4e1eSChuck Lever * on a directory already in our cache. 7065573c4e1eSChuck Lever */ 7066573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7067573c4e1eSChuck Lever int plus) 70681da177e4SLinus Torvalds { 7069256e48bbSTrond Myklebust unsigned int savep; 7070dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 70711da177e4SLinus Torvalds uint32_t len; 7072babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7073babddc72SBryan Schumaker if (unlikely(!p)) 7074babddc72SBryan Schumaker goto out_overflow; 7075c08e76d0SChuck Lever if (*p == xdr_zero) { 7076babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7077babddc72SBryan Schumaker if (unlikely(!p)) 7078babddc72SBryan Schumaker goto out_overflow; 7079c08e76d0SChuck Lever if (*p == xdr_zero) 7080573c4e1eSChuck Lever return -EAGAIN; 70811da177e4SLinus Torvalds entry->eof = 1; 7082573c4e1eSChuck Lever return -EBADCOOKIE; 70831da177e4SLinus Torvalds } 70841da177e4SLinus Torvalds 7085babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7086babddc72SBryan Schumaker if (unlikely(!p)) 7087babddc72SBryan Schumaker goto out_overflow; 70881da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 70891da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7090c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7091babddc72SBryan Schumaker 70929af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7093babddc72SBryan Schumaker if (unlikely(!p)) 7094babddc72SBryan Schumaker goto out_overflow; 70951da177e4SLinus Torvalds entry->name = (const char *) p; 70961da177e4SLinus Torvalds 70971da177e4SLinus Torvalds /* 70981da177e4SLinus Torvalds * In case the server doesn't return an inode number, 70991da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 71001da177e4SLinus Torvalds * since glibc seems to choke on it...) 71011da177e4SLinus Torvalds */ 71021da177e4SLinus Torvalds entry->ino = 1; 71034f082222STrond Myklebust entry->fattr->valid = 0; 71041da177e4SLinus Torvalds 71059af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7106babddc72SBryan Schumaker goto out_overflow; 71079af8c222STrond Myklebust 7108256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7109babddc72SBryan Schumaker goto out_overflow; 71109af8c222STrond Myklebust 7111573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 71128b7e3f49STrond Myklebust NULL, entry->server) < 0) 7113babddc72SBryan Schumaker goto out_overflow; 711428331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 711528331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 711628331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 711782f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 71189af8c222STrond Myklebust 71190b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 71200b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 71210b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 71220b26a0bfSTrond Myklebust 7123573c4e1eSChuck Lever return 0; 7124babddc72SBryan Schumaker 7125babddc72SBryan Schumaker out_overflow: 7126babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7127573c4e1eSChuck Lever return -EAGAIN; 71281da177e4SLinus Torvalds } 71291da177e4SLinus Torvalds 71301da177e4SLinus Torvalds /* 71311da177e4SLinus Torvalds * We need to translate between nfs status return values and 71321da177e4SLinus Torvalds * the local errno values which may not be the same. 71331da177e4SLinus Torvalds */ 71341da177e4SLinus Torvalds static struct { 71351da177e4SLinus Torvalds int stat; 71361da177e4SLinus Torvalds int errno; 71371da177e4SLinus Torvalds } nfs_errtbl[] = { 71381da177e4SLinus Torvalds { NFS4_OK, 0 }, 7139856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7140856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7141856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7142856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7143856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7144856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7145856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7146856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7147856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7148856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7149856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7150856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7151856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7152856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7153856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7154856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7155856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7156856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7157856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7158856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7159856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7160856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7161fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7162856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7163856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7164856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7165856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7166856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7167856dff3dSBenny Halevy { -1, -EIO } 71681da177e4SLinus Torvalds }; 71691da177e4SLinus Torvalds 71701da177e4SLinus Torvalds /* 71711da177e4SLinus Torvalds * Convert an NFS error code to a local one. 71721da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 71731da177e4SLinus Torvalds */ 71741da177e4SLinus Torvalds static int 71750a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 71761da177e4SLinus Torvalds { 71771da177e4SLinus Torvalds int i; 71781da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 71791da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 71801da177e4SLinus Torvalds return nfs_errtbl[i].errno; 71811da177e4SLinus Torvalds } 71821da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 71831da177e4SLinus Torvalds /* The server is looney tunes. */ 7184fdcb4577STrond Myklebust return -EREMOTEIO; 71851da177e4SLinus Torvalds } 71861da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 71871da177e4SLinus Torvalds * handle it. 71881da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 71891da177e4SLinus Torvalds * not conflict with native Linux error codes. 71901da177e4SLinus Torvalds */ 7191856dff3dSBenny Halevy return -stat; 71921da177e4SLinus Torvalds } 71931da177e4SLinus Torvalds 71941da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 71951da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 71961da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 71979f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7198bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 71992bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 72002bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7201cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7202cc0175c1SChuck Lever .p_name = #proc, \ 72031da177e4SLinus Torvalds } 72041da177e4SLinus Torvalds 72051da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 72061da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 72071da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 72081da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 72091da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 72101da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 72111da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 72121da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 72131da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 72141da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 72151da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 72161da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 72171da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 72181da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 72191da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 72201da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 72211da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 72221da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 72231da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 72241da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 72251da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 72261da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 72271da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 72281da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 72291da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 72301da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 72311da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 72321da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 72331da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 72341da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 72351da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 72361da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7237029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 723823ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7239683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7240d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 72415a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 724299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 724399fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7244fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 72450f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7246fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 72472050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 724818019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7249b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7250b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7251863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7252cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7253fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 72547d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 72559aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 72567f11d8d3SAndy Adamson PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist), 7257ad24ecfbSTrond Myklebust PROC(BIND_CONN_TO_SESSION, 7258ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 725966245539STrond Myklebust PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 726099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 72611da177e4SLinus Torvalds }; 72621da177e4SLinus Torvalds 7263a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 72641da177e4SLinus Torvalds .number = 4, 7265e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 72661da177e4SLinus Torvalds .procs = nfs4_procedures 72671da177e4SLinus Torvalds }; 72681da177e4SLinus Torvalds 72691da177e4SLinus Torvalds /* 72701da177e4SLinus Torvalds * Local variables: 72711da177e4SLinus Torvalds * c-basic-offset: 8 72721da177e4SLinus Torvalds * End: 72731da177e4SLinus Torvalds */ 7274