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) 341fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 342fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 343fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 344fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 34518019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 34618019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 3477f11d8d3SAndy Adamson #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \ 3487f11d8d3SAndy Adamson encode_verifier_maxsz) 3497f11d8d3SAndy Adamson #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \ 3507f11d8d3SAndy Adamson 2 /* nfs_cookie4 gdlr_cookie */ + \ 3517f11d8d3SAndy Adamson decode_verifier_maxsz \ 3527f11d8d3SAndy Adamson /* verifier4 gdlr_verifier */ + \ 3537f11d8d3SAndy Adamson 1 /* gdlr_deviceid_list count */ + \ 3547f11d8d3SAndy Adamson XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \ 3557f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE) \ 3567f11d8d3SAndy Adamson /* gdlr_deviceid_list */ + \ 3577f11d8d3SAndy Adamson 1 /* bool gdlr_eof */) 358b1f69b75SAndy Adamson #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \ 359b1f69b75SAndy Adamson XDR_QUADLEN(NFS4_DEVICEID4_SIZE)) 360b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 361b1f69b75SAndy Adamson 1 /* layout type */ + \ 362b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 363b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 364b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 365b1f69b75SAndy Adamson 1 /* notification bitmap */) 366b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 367b1f69b75SAndy Adamson encode_stateid_maxsz) 368b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 369b1f69b75SAndy Adamson decode_stateid_maxsz + \ 370b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 371863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 372863a3c6cSAndy Adamson 2 /* offset */ + \ 373863a3c6cSAndy Adamson 2 /* length */ + \ 374863a3c6cSAndy Adamson 1 /* reclaim */ + \ 375863a3c6cSAndy Adamson encode_stateid_maxsz + \ 376863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 377863a3c6cSAndy Adamson 2 /* last byte written */ + \ 378863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 379863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 380863a3c6cSAndy Adamson 1 /* NULL filelayout layoutupdate4 payload */) 381863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 382cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 383cbe82603SBenny Halevy encode_stateid_maxsz + \ 384cbe82603SBenny Halevy 1 /* FIXME: opaque lrf_body always empty at the moment */) 385cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 386cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 387fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 388fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 3897d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 3907d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 3917d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 3929aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 3939aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 3949aeda35fSBryan Schumaker #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1) 3959b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 3969b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 3979b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 3989b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 3999b7b9fccSAndy Adamson 4001da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4011da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4021da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4039b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4041da177e4SLinus Torvalds encode_putfh_maxsz + \ 4059104a55dSTrond Myklebust encode_read_maxsz) 4061da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4079b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4081da177e4SLinus Torvalds decode_putfh_maxsz + \ 4099104a55dSTrond Myklebust decode_read_maxsz) 4101da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4119b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4121da177e4SLinus Torvalds encode_putfh_maxsz + \ 4139104a55dSTrond Myklebust encode_readlink_maxsz) 4141da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4159b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4161da177e4SLinus Torvalds decode_putfh_maxsz + \ 4179104a55dSTrond Myklebust decode_readlink_maxsz) 4181da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4199b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4201da177e4SLinus Torvalds encode_putfh_maxsz + \ 4219104a55dSTrond Myklebust encode_readdir_maxsz) 4221da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4239b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4241da177e4SLinus Torvalds decode_putfh_maxsz + \ 4259104a55dSTrond Myklebust decode_readdir_maxsz) 4261da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4279b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4281da177e4SLinus Torvalds encode_putfh_maxsz + \ 4299104a55dSTrond Myklebust encode_write_maxsz + \ 4304f9838c7STrond Myklebust encode_getattr_maxsz) 4311da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4331da177e4SLinus Torvalds decode_putfh_maxsz + \ 4349104a55dSTrond Myklebust decode_write_maxsz + \ 4354f9838c7STrond Myklebust decode_getattr_maxsz) 4361da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4379b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4381da177e4SLinus Torvalds encode_putfh_maxsz + \ 4398582715eSTrond Myklebust encode_commit_maxsz) 4401da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4419b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4421da177e4SLinus Torvalds decode_putfh_maxsz + \ 4438582715eSTrond Myklebust decode_commit_maxsz) 4441da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4459b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4461da177e4SLinus Torvalds encode_putfh_maxsz + \ 4472cebf828STrond Myklebust encode_open_maxsz + \ 4482cebf828STrond Myklebust encode_getfh_maxsz + \ 4492cebf828STrond Myklebust encode_getattr_maxsz) 4501da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4519b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4521da177e4SLinus Torvalds decode_putfh_maxsz + \ 4532cebf828STrond Myklebust decode_open_maxsz + \ 4542cebf828STrond Myklebust decode_getfh_maxsz + \ 4552cebf828STrond Myklebust decode_getattr_maxsz) 4561da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4571da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4581da177e4SLinus Torvalds encode_putfh_maxsz + \ 4599104a55dSTrond Myklebust encode_open_confirm_maxsz) 4609104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4619104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4621da177e4SLinus Torvalds decode_putfh_maxsz + \ 4639104a55dSTrond Myklebust decode_open_confirm_maxsz) 4641da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 4659b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4661da177e4SLinus Torvalds encode_putfh_maxsz + \ 4672cebf828STrond Myklebust encode_open_maxsz + \ 4682cebf828STrond Myklebust encode_getattr_maxsz) 4691da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 4709b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4711da177e4SLinus Torvalds decode_putfh_maxsz + \ 4722cebf828STrond Myklebust decode_open_maxsz + \ 4732cebf828STrond Myklebust decode_getattr_maxsz) 4741da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 4751da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4769b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4771da177e4SLinus Torvalds encode_putfh_maxsz + \ 4789104a55dSTrond Myklebust encode_open_downgrade_maxsz + \ 479516a6af6STrond Myklebust encode_getattr_maxsz) 4801da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 4811da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 4829b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4831da177e4SLinus Torvalds decode_putfh_maxsz + \ 4849104a55dSTrond Myklebust decode_open_downgrade_maxsz + \ 485516a6af6STrond Myklebust decode_getattr_maxsz) 4861da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 4879b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4881da177e4SLinus Torvalds encode_putfh_maxsz + \ 4899104a55dSTrond Myklebust encode_close_maxsz + \ 490516a6af6STrond Myklebust encode_getattr_maxsz) 4911da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 4929b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4931da177e4SLinus Torvalds decode_putfh_maxsz + \ 4949104a55dSTrond Myklebust decode_close_maxsz + \ 495516a6af6STrond Myklebust decode_getattr_maxsz) 4961da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 4979b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4981da177e4SLinus Torvalds encode_putfh_maxsz + \ 4999104a55dSTrond Myklebust encode_setattr_maxsz + \ 5001da177e4SLinus Torvalds encode_getattr_maxsz) 5011da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5029b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5031da177e4SLinus Torvalds decode_putfh_maxsz + \ 5049104a55dSTrond Myklebust decode_setattr_maxsz + \ 5059104a55dSTrond Myklebust decode_getattr_maxsz) 5061da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5079b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5081da177e4SLinus Torvalds encode_putfh_maxsz + \ 5091da177e4SLinus Torvalds encode_fsinfo_maxsz) 5101da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5119b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5121da177e4SLinus Torvalds decode_putfh_maxsz + \ 5131da177e4SLinus Torvalds decode_fsinfo_maxsz) 5141da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5151da177e4SLinus Torvalds encode_renew_maxsz) 5161da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5171da177e4SLinus Torvalds decode_renew_maxsz) 5181da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5191da177e4SLinus Torvalds encode_setclientid_maxsz) 5201da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5211da177e4SLinus Torvalds decode_setclientid_maxsz) 5221da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5231da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5241da177e4SLinus Torvalds encode_setclientid_confirm_maxsz + \ 5251da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 5261da177e4SLinus Torvalds encode_fsinfo_maxsz) 5271da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5281da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5291da177e4SLinus Torvalds decode_setclientid_confirm_maxsz + \ 5301da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 5311da177e4SLinus Torvalds decode_fsinfo_maxsz) 5321da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5339b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5341da177e4SLinus Torvalds encode_putfh_maxsz + \ 5359104a55dSTrond Myklebust encode_lock_maxsz) 5361da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5379b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5381da177e4SLinus Torvalds decode_putfh_maxsz + \ 5399104a55dSTrond Myklebust decode_lock_maxsz) 5401da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5419b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5421da177e4SLinus Torvalds encode_putfh_maxsz + \ 5439104a55dSTrond Myklebust encode_lockt_maxsz) 5449104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5459b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5469104a55dSTrond Myklebust decode_putfh_maxsz + \ 5479104a55dSTrond Myklebust decode_lockt_maxsz) 5481da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5499b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5501da177e4SLinus Torvalds encode_putfh_maxsz + \ 5519104a55dSTrond Myklebust encode_locku_maxsz) 5521da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5539b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5541da177e4SLinus Torvalds decode_putfh_maxsz + \ 5559104a55dSTrond Myklebust decode_locku_maxsz) 556d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 557d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 558d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 559d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 560d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 561d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5621da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5639b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5641da177e4SLinus Torvalds encode_putfh_maxsz + \ 56576b32999STrond Myklebust encode_access_maxsz + \ 56676b32999STrond Myklebust encode_getattr_maxsz) 5671da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5689b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5691da177e4SLinus Torvalds decode_putfh_maxsz + \ 57076b32999STrond Myklebust decode_access_maxsz + \ 57176b32999STrond Myklebust decode_getattr_maxsz) 5721da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 5739b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5741da177e4SLinus Torvalds encode_putfh_maxsz + \ 5751da177e4SLinus Torvalds encode_getattr_maxsz) 5761da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 5779b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5781da177e4SLinus Torvalds decode_putfh_maxsz + \ 5791da177e4SLinus Torvalds decode_getattr_maxsz) 5801da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 5819b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5821da177e4SLinus Torvalds encode_putfh_maxsz + \ 5831da177e4SLinus Torvalds encode_lookup_maxsz + \ 5841da177e4SLinus Torvalds encode_getattr_maxsz + \ 5851da177e4SLinus Torvalds encode_getfh_maxsz) 5861da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 5879b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5881da177e4SLinus Torvalds decode_putfh_maxsz + \ 589e6889620STrond Myklebust decode_lookup_maxsz + \ 5901da177e4SLinus Torvalds decode_getattr_maxsz + \ 5911da177e4SLinus Torvalds decode_getfh_maxsz) 5921da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 5939b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5941da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 5951da177e4SLinus Torvalds encode_getattr_maxsz + \ 5961da177e4SLinus Torvalds encode_getfh_maxsz) 5971da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 5989b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5991da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6001da177e4SLinus Torvalds decode_getattr_maxsz + \ 6011da177e4SLinus Torvalds decode_getfh_maxsz) 6021da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6039b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6041da177e4SLinus Torvalds encode_putfh_maxsz + \ 605778d2817STrond Myklebust encode_remove_maxsz) 6061da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6079b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6081da177e4SLinus Torvalds decode_putfh_maxsz + \ 609778d2817STrond Myklebust decode_remove_maxsz) 6101da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6119b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6121da177e4SLinus Torvalds encode_putfh_maxsz + \ 6131da177e4SLinus Torvalds encode_savefh_maxsz + \ 6141da177e4SLinus Torvalds encode_putfh_maxsz + \ 615778d2817STrond Myklebust encode_rename_maxsz) 6161da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6181da177e4SLinus Torvalds decode_putfh_maxsz + \ 6191da177e4SLinus Torvalds decode_savefh_maxsz + \ 6201da177e4SLinus Torvalds decode_putfh_maxsz + \ 621778d2817STrond Myklebust decode_rename_maxsz) 6221da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6239b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6241da177e4SLinus Torvalds encode_putfh_maxsz + \ 6251da177e4SLinus Torvalds encode_savefh_maxsz + \ 6261da177e4SLinus Torvalds encode_putfh_maxsz + \ 62791ba2eeeSTrond Myklebust encode_link_maxsz + \ 62891ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 629a9f6991bSTrond Myklebust encode_getattr_maxsz) 6301da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6319b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6321da177e4SLinus Torvalds decode_putfh_maxsz + \ 6331da177e4SLinus Torvalds decode_savefh_maxsz + \ 6341da177e4SLinus Torvalds decode_putfh_maxsz + \ 63591ba2eeeSTrond Myklebust decode_link_maxsz + \ 63691ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 63791ba2eeeSTrond Myklebust decode_getattr_maxsz) 6381da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6399b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6401da177e4SLinus Torvalds encode_putfh_maxsz + \ 6411da177e4SLinus Torvalds encode_symlink_maxsz + \ 6421da177e4SLinus Torvalds encode_getattr_maxsz + \ 6431da177e4SLinus Torvalds encode_getfh_maxsz) 6441da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6459b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6461da177e4SLinus Torvalds decode_putfh_maxsz + \ 6471da177e4SLinus Torvalds decode_symlink_maxsz + \ 6481da177e4SLinus Torvalds decode_getattr_maxsz + \ 6491da177e4SLinus Torvalds decode_getfh_maxsz) 6501da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6519b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6521da177e4SLinus Torvalds encode_putfh_maxsz + \ 6531da177e4SLinus Torvalds encode_create_maxsz + \ 65456ae19f3STrond Myklebust encode_getfh_maxsz + \ 65556ae19f3STrond Myklebust encode_getattr_maxsz) 6561da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 6579b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6581da177e4SLinus Torvalds decode_putfh_maxsz + \ 6591da177e4SLinus Torvalds decode_create_maxsz + \ 66056ae19f3STrond Myklebust decode_getfh_maxsz + \ 66156ae19f3STrond Myklebust decode_getattr_maxsz) 6621da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 6639b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6641da177e4SLinus Torvalds encode_putfh_maxsz + \ 6651da177e4SLinus Torvalds encode_getattr_maxsz) 6661da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 6679b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6681da177e4SLinus Torvalds decode_putfh_maxsz + \ 6691da177e4SLinus Torvalds decode_getattr_maxsz) 6701da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 6719b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6721da177e4SLinus Torvalds encode_putfh_maxsz + \ 6739104a55dSTrond Myklebust encode_statfs_maxsz) 6741da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 6759b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6761da177e4SLinus Torvalds decode_putfh_maxsz + \ 6779104a55dSTrond Myklebust decode_statfs_maxsz) 6781da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 6799b7b9fccSAndy Adamson encode_sequence_maxsz + \ 680ab91f264STrond Myklebust encode_putfh_maxsz + \ 6811da177e4SLinus Torvalds encode_getattr_maxsz) 6821da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 6839b7b9fccSAndy Adamson decode_sequence_maxsz + \ 684ab91f264STrond Myklebust decode_putfh_maxsz + \ 6851da177e4SLinus Torvalds decode_getattr_maxsz) 6861da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 6879b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6881da177e4SLinus Torvalds encode_putfh_maxsz + \ 689fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 690fa178f29STrond Myklebust encode_getattr_maxsz) 6911da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 6929b7b9fccSAndy Adamson decode_sequence_maxsz + \ 693fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 694fa178f29STrond Myklebust decode_getattr_maxsz) 695029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 6969b7b9fccSAndy Adamson encode_sequence_maxsz + \ 697029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 6989104a55dSTrond Myklebust encode_getacl_maxsz) 699029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7009b7b9fccSAndy Adamson decode_sequence_maxsz + \ 701029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7029104a55dSTrond Myklebust decode_getacl_maxsz) 70323ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7049b7b9fccSAndy Adamson encode_sequence_maxsz + \ 70523ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7069104a55dSTrond Myklebust encode_setacl_maxsz) 70723ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7089b7b9fccSAndy Adamson decode_sequence_maxsz + \ 70923ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7109104a55dSTrond Myklebust decode_setacl_maxsz) 711683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 712683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7139b7b9fccSAndy Adamson encode_sequence_maxsz + \ 714683b57b4STrond Myklebust encode_putfh_maxsz + \ 715e6889620STrond Myklebust encode_lookup_maxsz + \ 716e6889620STrond Myklebust encode_fs_locations_maxsz) 717683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 718683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7199b7b9fccSAndy Adamson decode_sequence_maxsz + \ 720683b57b4STrond Myklebust decode_putfh_maxsz + \ 721e6889620STrond Myklebust decode_lookup_maxsz + \ 722e6889620STrond Myklebust decode_fs_locations_maxsz) 7235a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7245a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7255a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7265a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7275a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7285a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7295a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7305a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 73199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 7327c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 7337c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 7347c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 7357c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 7367c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 7377c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 73899fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 73999fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 74099fe60d0SBenny Halevy encode_exchange_id_maxsz) 74199fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 74299fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 74399fe60d0SBenny Halevy decode_exchange_id_maxsz) 744fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 745fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 746fc931582SAndy Adamson encode_create_session_maxsz) 747fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 748fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 749fc931582SAndy Adamson decode_create_session_maxsz) 7500f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 7510f3e66c6SAndy Adamson encode_destroy_session_maxsz) 7520f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 7530f3e66c6SAndy Adamson decode_destroy_session_maxsz) 754fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 755fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 756fc01cea9SAndy Adamson encode_sequence_maxsz) 757fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 758fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 759fc01cea9SAndy Adamson decode_sequence_maxsz) 7602050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 7612050f0ccSAndy Adamson encode_sequence_maxsz + \ 7622050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 7632050f0ccSAndy Adamson encode_fsinfo_maxsz) 7642050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 7652050f0ccSAndy Adamson decode_sequence_maxsz + \ 7662050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 7672050f0ccSAndy Adamson decode_fsinfo_maxsz) 76818019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 76918019753SRicardo Labiaga encode_sequence_maxsz + \ 77018019753SRicardo Labiaga encode_reclaim_complete_maxsz) 77118019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 77218019753SRicardo Labiaga decode_sequence_maxsz + \ 77318019753SRicardo Labiaga decode_reclaim_complete_maxsz) 7747f11d8d3SAndy Adamson #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \ 7757f11d8d3SAndy Adamson encode_sequence_maxsz + \ 7767f11d8d3SAndy Adamson encode_putfh_maxsz + \ 7777f11d8d3SAndy Adamson encode_getdevicelist_maxsz) 7787f11d8d3SAndy Adamson #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \ 7797f11d8d3SAndy Adamson decode_sequence_maxsz + \ 7807f11d8d3SAndy Adamson decode_putfh_maxsz + \ 7817f11d8d3SAndy Adamson decode_getdevicelist_maxsz) 782b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 783b1f69b75SAndy Adamson encode_sequence_maxsz +\ 784b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 785b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 786b1f69b75SAndy Adamson decode_sequence_maxsz + \ 787b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 788b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 789b1f69b75SAndy Adamson encode_sequence_maxsz + \ 790b1f69b75SAndy Adamson encode_putfh_maxsz + \ 791b1f69b75SAndy Adamson encode_layoutget_maxsz) 792b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 793b1f69b75SAndy Adamson decode_sequence_maxsz + \ 794b1f69b75SAndy Adamson decode_putfh_maxsz + \ 795b1f69b75SAndy Adamson decode_layoutget_maxsz) 796863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 797863a3c6cSAndy Adamson encode_sequence_maxsz +\ 798863a3c6cSAndy Adamson encode_putfh_maxsz + \ 799863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 800863a3c6cSAndy Adamson encode_getattr_maxsz) 801863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 802863a3c6cSAndy Adamson decode_sequence_maxsz + \ 803863a3c6cSAndy Adamson decode_putfh_maxsz + \ 804863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 805863a3c6cSAndy Adamson decode_getattr_maxsz) 806cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 807cbe82603SBenny Halevy encode_sequence_maxsz + \ 808cbe82603SBenny Halevy encode_putfh_maxsz + \ 809cbe82603SBenny Halevy encode_layoutreturn_maxsz) 810cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 811cbe82603SBenny Halevy decode_sequence_maxsz + \ 812cbe82603SBenny Halevy decode_putfh_maxsz + \ 813cbe82603SBenny Halevy decode_layoutreturn_maxsz) 814fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 815fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 816fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 817fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 818fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 819fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 820fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 821fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8227d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8237d974794SBryan Schumaker encode_sequence_maxsz + \ 8247d974794SBryan Schumaker encode_test_stateid_maxsz) 8257d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8267d974794SBryan Schumaker decode_sequence_maxsz + \ 8277d974794SBryan Schumaker decode_test_stateid_maxsz) 8289aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8299aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8309aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8319aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8329aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8339aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8342449ea2eSAlexandros Batsakis 8352449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8362449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8372449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8382449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8392449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8402449ea2eSAlexandros Batsakis XDR_UNIT); 8412449ea2eSAlexandros Batsakis 8422449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8432449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 8442449ea2eSAlexandros Batsakis decode_sequence_maxsz + 8452449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 8462449ea2eSAlexandros Batsakis XDR_UNIT); 84799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 8481da177e4SLinus Torvalds 849db8ac8baSWeston Andros Adamson static unsigned short send_implementation_id = 1; 850db8ac8baSWeston Andros Adamson 851db8ac8baSWeston Andros Adamson module_param(send_implementation_id, ushort, 0644); 852db8ac8baSWeston Andros Adamson MODULE_PARM_DESC(send_implementation_id, 853db8ac8baSWeston Andros Adamson "Send implementation ID with NFSv4.1 exchange_id"); 854db8ac8baSWeston Andros Adamson 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, 119588034c3dSAndy Adamson struct compound_hdr *hdr) 119688034c3dSAndy Adamson { 119788034c3dSAndy Adamson encode_getattr_three(xdr, 119888034c3dSAndy Adamson bitmask[0] & nfs4_fattr_bitmap[0], 119988034c3dSAndy Adamson bitmask[1] & nfs4_fattr_bitmap[1], 120088034c3dSAndy Adamson bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD, 120188034c3dSAndy Adamson hdr); 120288034c3dSAndy Adamson } 120388034c3dSAndy Adamson 1204cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12051da177e4SLinus Torvalds { 1206dae100c2SFred Isaman encode_getattr_three(xdr, 1207dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1208dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1209dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1210dae100c2SFred Isaman hdr); 12111da177e4SLinus Torvalds } 12121da177e4SLinus Torvalds 1213cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1214830b8e33SManoj Naik { 1215cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1216cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1217830b8e33SManoj Naik } 1218830b8e33SManoj Naik 1219cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12201da177e4SLinus Torvalds { 1221ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12221da177e4SLinus Torvalds } 12231da177e4SLinus Torvalds 1224cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12251da177e4SLinus Torvalds { 1226ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12276fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12281da177e4SLinus Torvalds } 12291da177e4SLinus Torvalds 1230911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1231911d1aafSTrond Myklebust { 1232911d1aafSTrond Myklebust if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) 1233911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1234911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1235911d1aafSTrond Myklebust } 1236911d1aafSTrond Myklebust 1237911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1238911d1aafSTrond Myklebust { 1239911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1240911d1aafSTrond Myklebust return ~(uint64_t)0; 1241911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1242911d1aafSTrond Myklebust } 1243911d1aafSTrond Myklebust 1244daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1245daccbdedSTrond Myklebust { 1246daccbdedSTrond Myklebust __be32 *p; 1247daccbdedSTrond Myklebust 1248d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1249daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1250d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1251daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1252d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1253daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1254daccbdedSTrond Myklebust } 1255daccbdedSTrond Myklebust 12561da177e4SLinus Torvalds /* 12571da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 12581da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 12591da177e4SLinus Torvalds */ 1260cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 12611da177e4SLinus Torvalds { 12628687b63aSAl Viro __be32 *p; 12631da177e4SLinus Torvalds 1264475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1265475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1266e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1267e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1268b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1269b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 127034558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1271911d1aafSTrond Myklebust if (args->new_lock_owner){ 12724ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1273ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->open_stateid); 12744ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1275daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12761da177e4SLinus Torvalds } 12771da177e4SLinus Torvalds else { 1278ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->lock_stateid); 12794ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 12801da177e4SLinus Torvalds } 12811da177e4SLinus Torvalds } 12821da177e4SLinus Torvalds 1283cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 12841da177e4SLinus Torvalds { 12858687b63aSAl Viro __be32 *p; 12861da177e4SLinus Torvalds 1287475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1288475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1289e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1290b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1291b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1292daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12931da177e4SLinus Torvalds } 12941da177e4SLinus Torvalds 1295cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 12961da177e4SLinus Torvalds { 12978687b63aSAl Viro __be32 *p; 12981da177e4SLinus Torvalds 1299475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1300475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13014ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1302ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 1303ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1304b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 130534558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13061da177e4SLinus Torvalds } 13071da177e4SLinus Torvalds 1308d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1309d3c7b7ccSTrond Myklebust { 1310ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1311d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1312d3c7b7ccSTrond Myklebust } 1313d3c7b7ccSTrond Myklebust 1314cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13151da177e4SLinus Torvalds { 1316ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13176fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13181da177e4SLinus Torvalds } 13191da177e4SLinus Torvalds 1320dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 13211da177e4SLinus Torvalds { 13228687b63aSAl Viro __be32 *p; 13231da177e4SLinus Torvalds 132413c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1325dc0b027dSTrond Myklebust switch (fmode & (FMODE_READ|FMODE_WRITE)) { 13261da177e4SLinus Torvalds case FMODE_READ: 1327e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 13281da177e4SLinus Torvalds break; 13291da177e4SLinus Torvalds case FMODE_WRITE: 1330e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 13311da177e4SLinus Torvalds break; 13321da177e4SLinus Torvalds case FMODE_READ|FMODE_WRITE: 1333e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 13341da177e4SLinus Torvalds break; 13351da177e4SLinus Torvalds default: 1336e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 13371da177e4SLinus Torvalds } 133834558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13391da177e4SLinus Torvalds } 13401da177e4SLinus Torvalds 13411da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13421da177e4SLinus Torvalds { 13438687b63aSAl Viro __be32 *p; 13441da177e4SLinus Torvalds /* 13451da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13461da177e4SLinus Torvalds * owner 4 = 32 13471da177e4SLinus Torvalds */ 13484ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1349dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 135095b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1351b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 135295b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 135393f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1354d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 135595b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 135695b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 13571da177e4SLinus Torvalds } 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13601da177e4SLinus Torvalds { 13618687b63aSAl Viro __be32 *p; 13624882ef72SAlexandros Batsakis struct nfs_client *clp; 13631da177e4SLinus Torvalds 136413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13651da177e4SLinus Torvalds switch(arg->open_flags & O_EXCL) { 13661da177e4SLinus Torvalds case 0: 136734558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 13681da177e4SLinus Torvalds encode_attrs(xdr, arg->u.attrs, arg->server); 13691da177e4SLinus Torvalds break; 13701da177e4SLinus Torvalds default: 13714882ef72SAlexandros Batsakis clp = arg->server->nfs_client; 1372a4432345STrond Myklebust if (clp->cl_mvops->minor_version > 0) { 13734882ef72SAlexandros Batsakis if (nfs4_has_persistent_session(clp)) { 13744882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 13754882ef72SAlexandros Batsakis encode_attrs(xdr, arg->u.attrs, arg->server); 13764882ef72SAlexandros Batsakis } else { 13774882ef72SAlexandros Batsakis struct iattr dummy; 13784882ef72SAlexandros Batsakis 13794882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 13804882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 13814882ef72SAlexandros Batsakis dummy.ia_valid = 0; 13824882ef72SAlexandros Batsakis encode_attrs(xdr, &dummy, arg->server); 13834882ef72SAlexandros Batsakis } 13844882ef72SAlexandros Batsakis } else { 138534558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 13861da177e4SLinus Torvalds encode_nfs4_verifier(xdr, &arg->u.verifier); 13871da177e4SLinus Torvalds } 13881da177e4SLinus Torvalds } 13894882ef72SAlexandros Batsakis } 13901da177e4SLinus Torvalds 13911da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13921da177e4SLinus Torvalds { 13938687b63aSAl Viro __be32 *p; 13941da177e4SLinus Torvalds 139513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13961da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 13971da177e4SLinus Torvalds case 0: 139834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 13991da177e4SLinus Torvalds break; 14001da177e4SLinus Torvalds default: 14011da177e4SLinus Torvalds BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 140234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14031da177e4SLinus Torvalds encode_createmode(xdr, arg); 14041da177e4SLinus Torvalds } 14051da177e4SLinus Torvalds } 14061da177e4SLinus Torvalds 1407bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14081da177e4SLinus Torvalds { 14098687b63aSAl Viro __be32 *p; 14101da177e4SLinus Torvalds 141113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14121da177e4SLinus Torvalds switch (delegation_type) { 14131da177e4SLinus Torvalds case 0: 141434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14151da177e4SLinus Torvalds break; 14161da177e4SLinus Torvalds case FMODE_READ: 141734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14181da177e4SLinus Torvalds break; 14191da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 142034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14211da177e4SLinus Torvalds break; 14221da177e4SLinus Torvalds default: 14231da177e4SLinus Torvalds BUG(); 14241da177e4SLinus Torvalds } 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds 14271da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14281da177e4SLinus Torvalds { 14298687b63aSAl Viro __be32 *p; 14301da177e4SLinus Torvalds 143113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 143234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14331da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14341da177e4SLinus Torvalds } 14351da177e4SLinus Torvalds 1436bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14371da177e4SLinus Torvalds { 14388687b63aSAl Viro __be32 *p; 14391da177e4SLinus Torvalds 144013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 144134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14421da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14431da177e4SLinus Torvalds } 14441da177e4SLinus Torvalds 14451da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14461da177e4SLinus Torvalds { 14478687b63aSAl Viro __be32 *p; 14481da177e4SLinus Torvalds 1449ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1450ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1451ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14521da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14531da177e4SLinus Torvalds } 14541da177e4SLinus Torvalds 1455cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 14561da177e4SLinus Torvalds { 1457ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 14581da177e4SLinus Torvalds encode_openhdr(xdr, arg); 14591da177e4SLinus Torvalds encode_opentype(xdr, arg); 14601da177e4SLinus Torvalds switch (arg->claim) { 14611da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 14621da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 14631da177e4SLinus Torvalds break; 14641da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 14651da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 14661da177e4SLinus Torvalds break; 14671da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 14681da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 14691da177e4SLinus Torvalds break; 14701da177e4SLinus Torvalds default: 14711da177e4SLinus Torvalds BUG(); 14721da177e4SLinus Torvalds } 14731da177e4SLinus Torvalds } 14741da177e4SLinus Torvalds 1475cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 14761da177e4SLinus Torvalds { 1477ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1478ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14794ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14801da177e4SLinus Torvalds } 14811da177e4SLinus Torvalds 1482cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 14831da177e4SLinus Torvalds { 1484ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1485ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14864ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1487dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 14881da177e4SLinus Torvalds } 14891da177e4SLinus Torvalds 1490cf8cdbe5SAndy Adamson static void 1491d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 14921da177e4SLinus Torvalds { 1493ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 14946fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 14951da177e4SLinus Torvalds } 14961da177e4SLinus Torvalds 1497cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 14981da177e4SLinus Torvalds { 1499ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15001da177e4SLinus Torvalds } 15011da177e4SLinus Torvalds 15024fc8796dSTrond Myklebust static void encode_open_stateid(struct xdr_stream *xdr, 15034fc8796dSTrond Myklebust const struct nfs_open_context *ctx, 15044fc8796dSTrond Myklebust const struct nfs_lock_context *l_ctx, 15054fc8796dSTrond Myklebust fmode_t fmode, 15064fc8796dSTrond Myklebust int zero_seqid) 15071da177e4SLinus Torvalds { 15081da177e4SLinus Torvalds nfs4_stateid stateid; 15091da177e4SLinus Torvalds 15101da177e4SLinus Torvalds if (ctx->state != NULL) { 15114fc8796dSTrond Myklebust nfs4_select_rw_stateid(&stateid, ctx->state, 15124fc8796dSTrond Myklebust fmode, l_ctx->lockowner, l_ctx->pid); 151389d1ea65SAndy Adamson if (zero_seqid) 15142d2f24adSTrond Myklebust stateid.seqid = 0; 1515ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &stateid); 15161da177e4SLinus Torvalds } else 1517ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 15181da177e4SLinus Torvalds } 15191da177e4SLinus Torvalds 1520cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 15211da177e4SLinus Torvalds { 15228687b63aSAl Viro __be32 *p; 15231da177e4SLinus Torvalds 1524ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 1525d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 15264fc8796dSTrond Myklebust FMODE_READ, hdr->minorversion); 15271da177e4SLinus Torvalds 152813c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1529b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 153034558513SBenny Halevy *p = cpu_to_be32(args->count); 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds 1533cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15341da177e4SLinus Torvalds { 153528331a46STrond Myklebust uint32_t attrs[2] = { 153628331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 153728331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 153828331a46STrond Myklebust }; 15396f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1540cd93710eSChuck Lever __be32 *p, verf[2]; 15411da177e4SLinus Torvalds 154282f2e547SBryan Schumaker if (readdir->plus) { 154382f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 154428331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 154582f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 154682f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 154782f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 154882f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 15496f7a35bdSTrond Myklebust dircount >>= 1; 155082f2e547SBryan Schumaker } 155128331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 155228331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 155328331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 15546f7a35bdSTrond Myklebust 1555475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1556ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1557cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1558cd93710eSChuck Lever p = reserve_space(xdr, 20); 15596f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 15606f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 15616f7a35bdSTrond Myklebust *p++ = cpu_to_be32(2); 156282f2e547SBryan Schumaker 1563e75bc1c8SBenny Halevy *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 156434558513SBenny Halevy *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1565cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 156644109241SFred Isaman dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 156744109241SFred Isaman __func__, 1568eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1569cd93710eSChuck Lever verf[0], verf[1], 1570eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1571eadf4598STrond Myklebust attrs[1] & readdir->bitmask[1]); 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds 1574cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 15751da177e4SLinus Torvalds { 1576ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 15771da177e4SLinus Torvalds } 15781da177e4SLinus Torvalds 1579cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 15801da177e4SLinus Torvalds { 1581ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 15826fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 15831da177e4SLinus Torvalds } 15841da177e4SLinus Torvalds 1585cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 15861da177e4SLinus Torvalds { 1587ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1588811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1589811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 15901da177e4SLinus Torvalds } 15911da177e4SLinus Torvalds 1592bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1593bb4dae5eSChuck Lever struct compound_hdr *hdr) 15941da177e4SLinus Torvalds { 1595475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1596ff2eb681STrond Myklebust encode_uint64(xdr, clid); 15971da177e4SLinus Torvalds } 15981da177e4SLinus Torvalds 1599cf8cdbe5SAndy Adamson static void 1600d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 160156ae19f3STrond Myklebust { 1602ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 160356ae19f3STrond Myklebust } 160456ae19f3STrond Myklebust 16059f06c719SChuck Lever static void 1606d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 160723ec6965SJ. Bruce Fields { 16088687b63aSAl Viro __be32 *p; 160923ec6965SJ. Bruce Fields 1610ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1611ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 161213c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1613e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 161434558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 16159f06c719SChuck Lever BUG_ON(arg->acl_len % 4); 161613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 161734558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 161823ec6965SJ. Bruce Fields xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 161923ec6965SJ. Bruce Fields } 162023ec6965SJ. Bruce Fields 1621cf8cdbe5SAndy Adamson static void 1622d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16231da177e4SLinus Torvalds { 1624ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds 1627cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16281da177e4SLinus Torvalds { 1629ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1630ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1631cf8cdbe5SAndy Adamson encode_attrs(xdr, arg->iap, server); 16321da177e4SLinus Torvalds } 16331da177e4SLinus Torvalds 1634cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16351da177e4SLinus Torvalds { 16368687b63aSAl Viro __be32 *p; 16371da177e4SLinus Torvalds 163870019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1639cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16401da177e4SLinus Torvalds 16411da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 164213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 164334558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16441da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16451da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 164613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 164734558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_cb_ident); 16481da177e4SLinus Torvalds } 16491da177e4SLinus Torvalds 1650bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16511da177e4SLinus Torvalds { 1652475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1653475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1654ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1655cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 16561da177e4SLinus Torvalds } 16571da177e4SLinus Torvalds 1658cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 16591da177e4SLinus Torvalds { 16608687b63aSAl Viro __be32 *p; 16611da177e4SLinus Torvalds 1662ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 1663d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 16644fc8796dSTrond Myklebust FMODE_WRITE, hdr->minorversion); 16651da177e4SLinus Torvalds 166613c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1667b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1668e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 166934558513SBenny Halevy *p = cpu_to_be32(args->count); 16701da177e4SLinus Torvalds 16711da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 16721da177e4SLinus Torvalds } 16731da177e4SLinus Torvalds 1674cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 16751da177e4SLinus Torvalds { 1676ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1677ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 16781da177e4SLinus Torvalds } 16799b7b9fccSAndy Adamson 16805a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16815a5ea0d4SBryan Schumaker { 1682ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 16836fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16845a5ea0d4SBryan Schumaker } 16855a5ea0d4SBryan Schumaker 168699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 16879b7b9fccSAndy Adamson /* NFSv4.1 operations */ 16887c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 16897c44f1aeSWeston Andros Adamson struct nfs4_session *session, 16907c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 16917c44f1aeSWeston Andros Adamson { 16927c44f1aeSWeston Andros Adamson __be32 *p; 16937c44f1aeSWeston Andros Adamson 16947c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 16957c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 16967c44f1aeSWeston Andros Adamson encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 16977c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 16987c44f1aeSWeston Andros Adamson *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH); 16997c44f1aeSWeston Andros Adamson *p = 0; /* use_conn_in_rdma_mode = False */ 17007c44f1aeSWeston Andros Adamson } 17017c44f1aeSWeston Andros Adamson 170299fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 170399fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 170499fe60d0SBenny Halevy struct compound_hdr *hdr) 170599fe60d0SBenny Halevy { 170699fe60d0SBenny Halevy __be32 *p; 1707db8ac8baSWeston Andros Adamson char impl_name[NFS4_OPAQUE_LIMIT]; 1708db8ac8baSWeston Andros Adamson int len = 0; 170999fe60d0SBenny Halevy 171070019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1711cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 171299fe60d0SBenny Halevy 171399fe60d0SBenny Halevy encode_string(xdr, args->id_len, args->id); 171499fe60d0SBenny Halevy 171513c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1716e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); 1717e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1718db8ac8baSWeston Andros Adamson 1719db8ac8baSWeston Andros Adamson if (send_implementation_id && 1720db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1721db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1722db8ac8baSWeston Andros Adamson <= NFS4_OPAQUE_LIMIT + 1) 1723db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1724db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1725db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1726db8ac8baSWeston Andros Adamson 1727db8ac8baSWeston Andros Adamson if (len > 0) { 1728db8ac8baSWeston Andros Adamson *p = cpu_to_be32(1); /* implementation id array length=1 */ 1729db8ac8baSWeston Andros Adamson 1730db8ac8baSWeston Andros Adamson encode_string(xdr, 1731db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1732db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1733db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1734db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1735db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1736db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1737db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1738db8ac8baSWeston Andros Adamson } else 1739db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); /* implementation id array length=0 */ 174099fe60d0SBenny Halevy } 1741fc931582SAndy Adamson 1742fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1743fc931582SAndy Adamson struct nfs41_create_session_args *args, 1744fc931582SAndy Adamson struct compound_hdr *hdr) 1745fc931582SAndy Adamson { 1746fc931582SAndy Adamson __be32 *p; 1747fc931582SAndy Adamson char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1748fc931582SAndy Adamson uint32_t len; 1749fc931582SAndy Adamson struct nfs_client *clp = args->client; 1750f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 17518e0d46e1SMike Sager u32 max_resp_sz_cached; 17528e0d46e1SMike Sager 17538e0d46e1SMike Sager /* 17548e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 17558e0d46e1SMike Sager * 2 is the verifier. 17568e0d46e1SMike Sager */ 17578e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 17588e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1759fc931582SAndy Adamson 1760fc931582SAndy Adamson len = scnprintf(machine_name, sizeof(machine_name), "%s", 1761fc931582SAndy Adamson clp->cl_ipaddr); 176242edd698SBenny Halevy 1763475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 1764475d4ba0STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12); 1765114f64b5SAndy Adamson p = xdr_encode_hyper(p, clp->cl_clientid); 1766e75bc1c8SBenny Halevy *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1767e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1768fc931582SAndy Adamson 1769fc931582SAndy Adamson /* Fore Channel */ 1770c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1771e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1772e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 17738e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1774e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1775e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1776e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1777fc931582SAndy Adamson 1778fc931582SAndy Adamson /* Back Channel */ 1779c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1780e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1781e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1782e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1783e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1784e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1785e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1786fc931582SAndy Adamson 1787e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1788e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1789e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1790fc931582SAndy Adamson 1791fc931582SAndy Adamson /* authsys_parms rfc1831 */ 1792f092075dSChuck Lever *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */ 1793811652bdSBenny Halevy p = xdr_encode_opaque(p, machine_name, len); 1794e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1795e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 179634558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1797fc931582SAndy Adamson } 17980f3e66c6SAndy Adamson 17990f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 18000f3e66c6SAndy Adamson struct nfs4_session *session, 18010f3e66c6SAndy Adamson struct compound_hdr *hdr) 18020f3e66c6SAndy Adamson { 1803475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1804475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18050f3e66c6SAndy Adamson } 180618019753SRicardo Labiaga 180718019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 180818019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 180918019753SRicardo Labiaga struct compound_hdr *hdr) 181018019753SRicardo Labiaga { 1811475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1812475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 181318019753SRicardo Labiaga } 181499fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 181599fe60d0SBenny Halevy 18169b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18179b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18189b7b9fccSAndy Adamson struct compound_hdr *hdr) 18199b7b9fccSAndy Adamson { 18209b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18219b7b9fccSAndy Adamson struct nfs4_session *session = args->sa_session; 1822fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 1823fc01cea9SAndy Adamson struct nfs4_slot *slot; 1824fc01cea9SAndy Adamson __be32 *p; 18259b7b9fccSAndy Adamson 18269b7b9fccSAndy Adamson if (!session) 18279b7b9fccSAndy Adamson return; 18289b7b9fccSAndy Adamson 1829fc01cea9SAndy Adamson tp = &session->fc_slot_table; 1830fc01cea9SAndy Adamson 1831fc01cea9SAndy Adamson WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1832fc01cea9SAndy Adamson slot = tp->slots + args->sa_slotid; 1833fc01cea9SAndy Adamson 1834475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1835fc01cea9SAndy Adamson 1836fc01cea9SAndy Adamson /* 1837fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1838fc01cea9SAndy Adamson */ 1839fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1840fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1841fc01cea9SAndy Adamson __func__, 1842fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1843fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1844fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1845fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 1846fc01cea9SAndy Adamson slot->seq_nr, args->sa_slotid, 1847fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1848475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 184993f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1850e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 1851e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->sa_slotid); 1852e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 185334558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 18549b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 18559b7b9fccSAndy Adamson } 18569b7b9fccSAndy Adamson 1857b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1858b1f69b75SAndy Adamson static void 18597f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr, 18607f11d8d3SAndy Adamson const struct nfs4_getdevicelist_args *args, 18617f11d8d3SAndy Adamson struct compound_hdr *hdr) 18627f11d8d3SAndy Adamson { 18637f11d8d3SAndy Adamson __be32 *p; 18647f11d8d3SAndy Adamson nfs4_verifier dummy = { 18657f11d8d3SAndy Adamson .data = "dummmmmy", 18667f11d8d3SAndy Adamson }; 18677f11d8d3SAndy Adamson 1868475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr); 1869475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 18707f11d8d3SAndy Adamson *p++ = cpu_to_be32(args->layoutclass); 18717f11d8d3SAndy Adamson *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 18727f11d8d3SAndy Adamson xdr_encode_hyper(p, 0ULL); /* cookie */ 18737f11d8d3SAndy Adamson encode_nfs4_verifier(xdr, &dummy); 18747f11d8d3SAndy Adamson } 18757f11d8d3SAndy Adamson 18767f11d8d3SAndy Adamson static void 1877b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1878b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1879b1f69b75SAndy Adamson struct compound_hdr *hdr) 1880b1f69b75SAndy Adamson { 1881b1f69b75SAndy Adamson __be32 *p; 1882b1f69b75SAndy Adamson 1883475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 1884475d4ba0STrond Myklebust p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE); 1885b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1886b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1887b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1888b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ 1889b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1890b1f69b75SAndy Adamson } 1891b1f69b75SAndy Adamson 1892b1f69b75SAndy Adamson static void 1893b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1894b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1895b1f69b75SAndy Adamson struct compound_hdr *hdr) 1896b1f69b75SAndy Adamson { 1897b1f69b75SAndy Adamson __be32 *p; 1898b1f69b75SAndy Adamson 1899475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1900475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1901b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1902b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1903b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1904b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1905b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1906b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1907ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1908475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1909b1f69b75SAndy Adamson 1910b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1911b1f69b75SAndy Adamson __func__, 1912b1f69b75SAndy Adamson args->type, 1913b1f69b75SAndy Adamson args->range.iomode, 1914b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1915b1f69b75SAndy Adamson (unsigned long)args->range.length, 1916b1f69b75SAndy Adamson args->maxcount); 1917b1f69b75SAndy Adamson } 1918863a3c6cSAndy Adamson 1919863a3c6cSAndy Adamson static int 1920863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1921ac7db726SBenny Halevy struct inode *inode, 1922863a3c6cSAndy Adamson const struct nfs4_layoutcommit_args *args, 1923863a3c6cSAndy Adamson struct compound_hdr *hdr) 1924863a3c6cSAndy Adamson { 1925863a3c6cSAndy Adamson __be32 *p; 1926863a3c6cSAndy Adamson 1927863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1928863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1929863a3c6cSAndy Adamson 1930475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1931475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1932863a3c6cSAndy Adamson /* Only whole file layouts */ 1933863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19343557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1935ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1936ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1937ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1938863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1939863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 1940863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1941863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 1942ac7db726SBenny Halevy 1943ac7db726SBenny Halevy if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 1944ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1945ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 1946475d4ba0STrond Myklebust else 1947475d4ba0STrond Myklebust encode_uint32(xdr, 0); /* no layout-type payload */ 1948863a3c6cSAndy Adamson 1949863a3c6cSAndy Adamson return 0; 1950863a3c6cSAndy Adamson } 1951cbe82603SBenny Halevy 1952cbe82603SBenny Halevy static void 1953cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 1954cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 1955cbe82603SBenny Halevy struct compound_hdr *hdr) 1956cbe82603SBenny Halevy { 1957cbe82603SBenny Halevy __be32 *p; 1958cbe82603SBenny Halevy 1959475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 1960475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 1961cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 1962cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 1963cbe82603SBenny Halevy *p++ = cpu_to_be32(IOMODE_ANY); 1964cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 1965ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1966cbe82603SBenny Halevy p = xdr_encode_hyper(p, 0); 1967cbe82603SBenny Halevy p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 1968cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 1969ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1970cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 197104a55549SAndy Adamson if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 197204a55549SAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 197304a55549SAndy Adamson NFS_I(args->inode)->layout, xdr, args); 1974475d4ba0STrond Myklebust } else 1975475d4ba0STrond Myklebust encode_uint32(xdr, 0); 1976cbe82603SBenny Halevy } 1977fca78d6dSBryan Schumaker 1978fca78d6dSBryan Schumaker static int 1979fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 1980fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 1981fca78d6dSBryan Schumaker struct compound_hdr *hdr) 1982fca78d6dSBryan Schumaker { 1983475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 1984475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 1985fca78d6dSBryan Schumaker return 0; 1986fca78d6dSBryan Schumaker } 19877d974794SBryan Schumaker 19887d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 19897d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 19907d974794SBryan Schumaker struct compound_hdr *hdr) 19917d974794SBryan Schumaker { 1992475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 1993475d4ba0STrond Myklebust encode_uint32(xdr, 1); 1994ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 19957d974794SBryan Schumaker } 19969aeda35fSBryan Schumaker 19979aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 19989aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 19999aeda35fSBryan Schumaker struct compound_hdr *hdr) 20009aeda35fSBryan Schumaker { 2001ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 2002ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20039aeda35fSBryan Schumaker } 2004b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2005b1f69b75SAndy Adamson 20061da177e4SLinus Torvalds /* 20071da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20081da177e4SLinus Torvalds */ 20091da177e4SLinus Torvalds 201066cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 201166cc0429SBenny Halevy { 201266cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 201366cc0429SBenny Halevy if (args->sa_session) 2014a4432345STrond Myklebust return args->sa_session->clp->cl_mvops->minor_version; 201566cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 201666cc0429SBenny Halevy return 0; 201766cc0429SBenny Halevy } 201866cc0429SBenny Halevy 20191da177e4SLinus Torvalds /* 20201da177e4SLinus Torvalds * Encode an ACCESS request 20211da177e4SLinus Torvalds */ 20229f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 20239f06c719SChuck Lever const struct nfs4_accessargs *args) 20241da177e4SLinus Torvalds { 20251da177e4SLinus Torvalds struct compound_hdr hdr = { 202666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20271da177e4SLinus Torvalds }; 20281da177e4SLinus Torvalds 20299f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20309f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20319f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20329f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 20339f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2034d017931cSAndy Adamson encode_nops(&hdr); 20351da177e4SLinus Torvalds } 20361da177e4SLinus Torvalds 20371da177e4SLinus Torvalds /* 20381da177e4SLinus Torvalds * Encode LOOKUP request 20391da177e4SLinus Torvalds */ 20409f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 20419f06c719SChuck Lever const struct nfs4_lookup_arg *args) 20421da177e4SLinus Torvalds { 20431da177e4SLinus Torvalds struct compound_hdr hdr = { 204466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20451da177e4SLinus Torvalds }; 20461da177e4SLinus Torvalds 20479f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20489f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20499f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 20509f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 20519f06c719SChuck Lever encode_getfh(xdr, &hdr); 20529f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2053d017931cSAndy Adamson encode_nops(&hdr); 20541da177e4SLinus Torvalds } 20551da177e4SLinus Torvalds 20561da177e4SLinus Torvalds /* 20571da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 20581da177e4SLinus Torvalds */ 20599f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 20609f06c719SChuck Lever struct xdr_stream *xdr, 20619f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 20621da177e4SLinus Torvalds { 20631da177e4SLinus Torvalds struct compound_hdr hdr = { 206466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20651da177e4SLinus Torvalds }; 20661da177e4SLinus Torvalds 20679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20699f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 20709f06c719SChuck Lever encode_getfh(xdr, &hdr); 20719f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2072d017931cSAndy Adamson encode_nops(&hdr); 20731da177e4SLinus Torvalds } 20741da177e4SLinus Torvalds 20751da177e4SLinus Torvalds /* 20761da177e4SLinus Torvalds * Encode REMOVE request 20771da177e4SLinus Torvalds */ 20789f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 20799f06c719SChuck Lever const struct nfs_removeargs *args) 20801da177e4SLinus Torvalds { 20811da177e4SLinus Torvalds struct compound_hdr hdr = { 208266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20831da177e4SLinus Torvalds }; 20841da177e4SLinus Torvalds 20859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20869f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20879f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20889f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2089d017931cSAndy Adamson encode_nops(&hdr); 20901da177e4SLinus Torvalds } 20911da177e4SLinus Torvalds 20921da177e4SLinus Torvalds /* 20931da177e4SLinus Torvalds * Encode RENAME request 20941da177e4SLinus Torvalds */ 20959f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 20969f06c719SChuck Lever const struct nfs_renameargs *args) 20971da177e4SLinus Torvalds { 20981da177e4SLinus Torvalds struct compound_hdr hdr = { 209966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21001da177e4SLinus Torvalds }; 21011da177e4SLinus Torvalds 21029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21049f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21059f06c719SChuck Lever encode_savefh(xdr, &hdr); 21069f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21079f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2108d017931cSAndy Adamson encode_nops(&hdr); 21091da177e4SLinus Torvalds } 21101da177e4SLinus Torvalds 21111da177e4SLinus Torvalds /* 21121da177e4SLinus Torvalds * Encode LINK request 21131da177e4SLinus Torvalds */ 21149f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 21159f06c719SChuck Lever const struct nfs4_link_arg *args) 21161da177e4SLinus Torvalds { 21171da177e4SLinus Torvalds struct compound_hdr hdr = { 211866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21191da177e4SLinus Torvalds }; 21201da177e4SLinus Torvalds 21219f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21229f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21239f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21249f06c719SChuck Lever encode_savefh(xdr, &hdr); 21259f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21269f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 21279f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21289f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2129d017931cSAndy Adamson encode_nops(&hdr); 21301da177e4SLinus Torvalds } 21311da177e4SLinus Torvalds 21321da177e4SLinus Torvalds /* 21331da177e4SLinus Torvalds * Encode CREATE request 21341da177e4SLinus Torvalds */ 21359f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 21369f06c719SChuck Lever const struct nfs4_create_arg *args) 21371da177e4SLinus Torvalds { 21381da177e4SLinus Torvalds struct compound_hdr hdr = { 213966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21401da177e4SLinus Torvalds }; 21411da177e4SLinus Torvalds 21429f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21439f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21449f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21459f06c719SChuck Lever encode_create(xdr, args, &hdr); 21469f06c719SChuck Lever encode_getfh(xdr, &hdr); 21479f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2148d017931cSAndy Adamson encode_nops(&hdr); 21491da177e4SLinus Torvalds } 21501da177e4SLinus Torvalds 21511da177e4SLinus Torvalds /* 21521da177e4SLinus Torvalds * Encode SYMLINK request 21531da177e4SLinus Torvalds */ 21549f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 21559f06c719SChuck Lever const struct nfs4_create_arg *args) 21561da177e4SLinus Torvalds { 21579f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 21581da177e4SLinus Torvalds } 21591da177e4SLinus Torvalds 21601da177e4SLinus Torvalds /* 21611da177e4SLinus Torvalds * Encode GETATTR request 21621da177e4SLinus Torvalds */ 21639f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 21649f06c719SChuck Lever const struct nfs4_getattr_arg *args) 21651da177e4SLinus Torvalds { 21661da177e4SLinus Torvalds struct compound_hdr hdr = { 216766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21681da177e4SLinus Torvalds }; 21691da177e4SLinus Torvalds 21709f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21719f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21729f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21739f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2174d017931cSAndy Adamson encode_nops(&hdr); 21751da177e4SLinus Torvalds } 21761da177e4SLinus Torvalds 21771da177e4SLinus Torvalds /* 21781da177e4SLinus Torvalds * Encode a CLOSE request 21791da177e4SLinus Torvalds */ 21809f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 21819f06c719SChuck Lever struct nfs_closeargs *args) 21821da177e4SLinus Torvalds { 21831da177e4SLinus Torvalds struct compound_hdr hdr = { 218466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21851da177e4SLinus Torvalds }; 21861da177e4SLinus Torvalds 21879f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21889f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21899f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21909f06c719SChuck Lever encode_close(xdr, args, &hdr); 21919f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2192d017931cSAndy Adamson encode_nops(&hdr); 21931da177e4SLinus Torvalds } 21941da177e4SLinus Torvalds 21951da177e4SLinus Torvalds /* 21961da177e4SLinus Torvalds * Encode an OPEN request 21971da177e4SLinus Torvalds */ 21989f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 21999f06c719SChuck Lever struct nfs_openargs *args) 22001da177e4SLinus Torvalds { 22011da177e4SLinus Torvalds struct compound_hdr hdr = { 220266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22031da177e4SLinus Torvalds }; 22041da177e4SLinus Torvalds 22059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22089f06c719SChuck Lever encode_open(xdr, args, &hdr); 22099f06c719SChuck Lever encode_getfh(xdr, &hdr); 221088034c3dSAndy Adamson encode_getfattr_open(xdr, args->bitmask, &hdr); 2211d017931cSAndy Adamson encode_nops(&hdr); 22121da177e4SLinus Torvalds } 22131da177e4SLinus Torvalds 22141da177e4SLinus Torvalds /* 22151da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 22161da177e4SLinus Torvalds */ 22179f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22189f06c719SChuck Lever struct xdr_stream *xdr, 22199f06c719SChuck Lever struct nfs_open_confirmargs *args) 22201da177e4SLinus Torvalds { 22211da177e4SLinus Torvalds struct compound_hdr hdr = { 2222d017931cSAndy Adamson .nops = 0, 22231da177e4SLinus Torvalds }; 22241da177e4SLinus Torvalds 22259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22269f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22279f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2228d017931cSAndy Adamson encode_nops(&hdr); 22291da177e4SLinus Torvalds } 22301da177e4SLinus Torvalds 22311da177e4SLinus Torvalds /* 22321da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 22331da177e4SLinus Torvalds */ 22349f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 22359f06c719SChuck Lever struct xdr_stream *xdr, 22369f06c719SChuck Lever struct nfs_openargs *args) 22371da177e4SLinus Torvalds { 22381da177e4SLinus Torvalds struct compound_hdr hdr = { 223966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22401da177e4SLinus Torvalds }; 22411da177e4SLinus Torvalds 22429f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22439f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22449f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22459f06c719SChuck Lever encode_open(xdr, args, &hdr); 22469f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2247d017931cSAndy Adamson encode_nops(&hdr); 22481da177e4SLinus Torvalds } 22491da177e4SLinus Torvalds 22501da177e4SLinus Torvalds /* 22511da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 22521da177e4SLinus Torvalds */ 22539f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 22549f06c719SChuck Lever struct xdr_stream *xdr, 22559f06c719SChuck Lever struct nfs_closeargs *args) 22561da177e4SLinus Torvalds { 22571da177e4SLinus Torvalds struct compound_hdr hdr = { 225866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22591da177e4SLinus Torvalds }; 22601da177e4SLinus Torvalds 22619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22649f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 22659f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2266d017931cSAndy Adamson encode_nops(&hdr); 22671da177e4SLinus Torvalds } 22681da177e4SLinus Torvalds 22691da177e4SLinus Torvalds /* 22701da177e4SLinus Torvalds * Encode a LOCK request 22711da177e4SLinus Torvalds */ 22729f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 22739f06c719SChuck Lever struct nfs_lock_args *args) 22741da177e4SLinus Torvalds { 22751da177e4SLinus Torvalds struct compound_hdr hdr = { 227666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22771da177e4SLinus Torvalds }; 22781da177e4SLinus Torvalds 22799f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22809f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22819f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22829f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2283d017931cSAndy Adamson encode_nops(&hdr); 22841da177e4SLinus Torvalds } 22851da177e4SLinus Torvalds 22861da177e4SLinus Torvalds /* 22871da177e4SLinus Torvalds * Encode a LOCKT request 22881da177e4SLinus Torvalds */ 22899f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 22909f06c719SChuck Lever struct nfs_lockt_args *args) 22911da177e4SLinus Torvalds { 22921da177e4SLinus Torvalds struct compound_hdr hdr = { 229366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22941da177e4SLinus Torvalds }; 22951da177e4SLinus Torvalds 22969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22999f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2300d017931cSAndy Adamson encode_nops(&hdr); 23011da177e4SLinus Torvalds } 23021da177e4SLinus Torvalds 23031da177e4SLinus Torvalds /* 23041da177e4SLinus Torvalds * Encode a LOCKU request 23051da177e4SLinus Torvalds */ 23069f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 23079f06c719SChuck Lever struct nfs_locku_args *args) 23081da177e4SLinus Torvalds { 23091da177e4SLinus Torvalds struct compound_hdr hdr = { 231066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23111da177e4SLinus Torvalds }; 23121da177e4SLinus Torvalds 23139f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23149f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23159f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23169f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2317d017931cSAndy Adamson encode_nops(&hdr); 23181da177e4SLinus Torvalds } 23191da177e4SLinus Torvalds 23209f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 23219f06c719SChuck Lever struct xdr_stream *xdr, 23229f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2323d3c7b7ccSTrond Myklebust { 2324d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2325d3c7b7ccSTrond Myklebust .minorversion = 0, 2326d3c7b7ccSTrond Myklebust }; 2327d3c7b7ccSTrond Myklebust 23289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23299f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2330d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2331d3c7b7ccSTrond Myklebust } 2332d3c7b7ccSTrond Myklebust 23331da177e4SLinus Torvalds /* 23341da177e4SLinus Torvalds * Encode a READLINK request 23351da177e4SLinus Torvalds */ 23369f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 23379f06c719SChuck Lever const struct nfs4_readlink *args) 23381da177e4SLinus Torvalds { 23391da177e4SLinus Torvalds struct compound_hdr hdr = { 234066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23411da177e4SLinus Torvalds }; 23421da177e4SLinus Torvalds 23439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23459f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23469f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2347e3a535e1STrond Myklebust 234828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2349e3a535e1STrond Myklebust args->pgbase, args->pglen); 2350d017931cSAndy Adamson encode_nops(&hdr); 23511da177e4SLinus Torvalds } 23521da177e4SLinus Torvalds 23531da177e4SLinus Torvalds /* 23541da177e4SLinus Torvalds * Encode a READDIR request 23551da177e4SLinus Torvalds */ 23569f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 23579f06c719SChuck Lever const struct nfs4_readdir_arg *args) 23581da177e4SLinus Torvalds { 23591da177e4SLinus Torvalds struct compound_hdr hdr = { 236066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23611da177e4SLinus Torvalds }; 23621da177e4SLinus Torvalds 23639f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23649f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23659f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23669f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2367d6ac02dfSTrond Myklebust 236828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2369d6ac02dfSTrond Myklebust args->pgbase, args->count); 2370d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 237128f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2372d6ac02dfSTrond Myklebust args->pgbase, args->count); 2373d017931cSAndy Adamson encode_nops(&hdr); 23741da177e4SLinus Torvalds } 23751da177e4SLinus Torvalds 23761da177e4SLinus Torvalds /* 23771da177e4SLinus Torvalds * Encode a READ request 23781da177e4SLinus Torvalds */ 23799f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 23809f06c719SChuck Lever struct nfs_readargs *args) 23811da177e4SLinus Torvalds { 23821da177e4SLinus Torvalds struct compound_hdr hdr = { 238366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23841da177e4SLinus Torvalds }; 23851da177e4SLinus Torvalds 23869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23889f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23899f06c719SChuck Lever encode_read(xdr, args, &hdr); 23901da177e4SLinus Torvalds 239128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 23921da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 23934f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2394d017931cSAndy Adamson encode_nops(&hdr); 23951da177e4SLinus Torvalds } 23961da177e4SLinus Torvalds 23971da177e4SLinus Torvalds /* 23981da177e4SLinus Torvalds * Encode an SETATTR request 23991da177e4SLinus Torvalds */ 24009f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 24019f06c719SChuck Lever struct nfs_setattrargs *args) 24021da177e4SLinus Torvalds { 24031da177e4SLinus Torvalds struct compound_hdr hdr = { 240466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24051da177e4SLinus Torvalds }; 24061da177e4SLinus Torvalds 24079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24089f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24099f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24109f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 24119f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2412d017931cSAndy Adamson encode_nops(&hdr); 24131da177e4SLinus Torvalds } 24141da177e4SLinus Torvalds 24151da177e4SLinus Torvalds /* 2416029d105eSJ. Bruce Fields * Encode a GETACL request 2417029d105eSJ. Bruce Fields */ 24189f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2419029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2420029d105eSJ. Bruce Fields { 2421029d105eSJ. Bruce Fields struct compound_hdr hdr = { 242266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2423029d105eSJ. Bruce Fields }; 242428f56694SBenny Halevy uint32_t replen; 2425029d105eSJ. Bruce Fields 24269f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24279f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24289f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2429bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 24309f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2431cf8cdbe5SAndy Adamson 243228f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2433029d105eSJ. Bruce Fields args->acl_pages, args->acl_pgbase, args->acl_len); 2434bf118a34SAndy Adamson 2435d017931cSAndy Adamson encode_nops(&hdr); 2436029d105eSJ. Bruce Fields } 2437029d105eSJ. Bruce Fields 2438029d105eSJ. Bruce Fields /* 24391da177e4SLinus Torvalds * Encode a WRITE request 24401da177e4SLinus Torvalds */ 24419f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 24429f06c719SChuck Lever struct nfs_writeargs *args) 24431da177e4SLinus Torvalds { 24441da177e4SLinus Torvalds struct compound_hdr hdr = { 244566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24461da177e4SLinus Torvalds }; 24471da177e4SLinus Torvalds 24489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24499f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24509f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24519f06c719SChuck Lever encode_write(xdr, args, &hdr); 24524f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 24537ffd1064SFred Isaman if (args->bitmask) 24549f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2455d017931cSAndy Adamson encode_nops(&hdr); 24561da177e4SLinus Torvalds } 24571da177e4SLinus Torvalds 24581da177e4SLinus Torvalds /* 24591da177e4SLinus Torvalds * a COMMIT request 24601da177e4SLinus Torvalds */ 24619f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 24620b7c0153SFred Isaman struct nfs_commitargs *args) 24631da177e4SLinus Torvalds { 24641da177e4SLinus Torvalds struct compound_hdr hdr = { 246566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24661da177e4SLinus Torvalds }; 24671da177e4SLinus Torvalds 24689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24709f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24719f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2472d017931cSAndy Adamson encode_nops(&hdr); 24731da177e4SLinus Torvalds } 24741da177e4SLinus Torvalds 24751da177e4SLinus Torvalds /* 24761da177e4SLinus Torvalds * FSINFO request 24771da177e4SLinus Torvalds */ 24789f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 24799f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 24801da177e4SLinus Torvalds { 24811da177e4SLinus Torvalds struct compound_hdr hdr = { 248266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24831da177e4SLinus Torvalds }; 24841da177e4SLinus Torvalds 24859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24869f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24879f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24889f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2489d017931cSAndy Adamson encode_nops(&hdr); 24901da177e4SLinus Torvalds } 24911da177e4SLinus Torvalds 24921da177e4SLinus Torvalds /* 24931da177e4SLinus Torvalds * a PATHCONF request 24941da177e4SLinus Torvalds */ 24959f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 24969f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 24971da177e4SLinus Torvalds { 24981da177e4SLinus Torvalds struct compound_hdr hdr = { 249966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25001da177e4SLinus Torvalds }; 25011da177e4SLinus Torvalds 25029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25049f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25059f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2506d017931cSAndy Adamson &hdr); 2507d017931cSAndy Adamson encode_nops(&hdr); 25081da177e4SLinus Torvalds } 25091da177e4SLinus Torvalds 25101da177e4SLinus Torvalds /* 25111da177e4SLinus Torvalds * a STATFS request 25121da177e4SLinus Torvalds */ 25139f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 25149f06c719SChuck Lever const struct nfs4_statfs_arg *args) 25151da177e4SLinus Torvalds { 25161da177e4SLinus Torvalds struct compound_hdr hdr = { 251766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25181da177e4SLinus Torvalds }; 25191da177e4SLinus Torvalds 25209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25219f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25229f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25239f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2524d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2525d017931cSAndy Adamson encode_nops(&hdr); 25261da177e4SLinus Torvalds } 25271da177e4SLinus Torvalds 25281da177e4SLinus Torvalds /* 25291da177e4SLinus Torvalds * GETATTR_BITMAP request 25301da177e4SLinus Torvalds */ 25319f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 25329f06c719SChuck Lever struct xdr_stream *xdr, 253343652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 25341da177e4SLinus Torvalds { 25351da177e4SLinus Torvalds struct compound_hdr hdr = { 253666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25371da177e4SLinus Torvalds }; 25381da177e4SLinus Torvalds 25399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25419f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 25429f06c719SChuck Lever encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2543264e6351SChuck Lever FATTR4_WORD0_FH_EXPIRE_TYPE| 25441da177e4SLinus Torvalds FATTR4_WORD0_LINK_SUPPORT| 25451da177e4SLinus Torvalds FATTR4_WORD0_SYMLINK_SUPPORT| 2546d017931cSAndy Adamson FATTR4_WORD0_ACLSUPPORT, &hdr); 2547d017931cSAndy Adamson encode_nops(&hdr); 25481da177e4SLinus Torvalds } 25491da177e4SLinus Torvalds 25501da177e4SLinus Torvalds /* 25511da177e4SLinus Torvalds * a RENEW request 25521da177e4SLinus Torvalds */ 25539f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 25549f06c719SChuck Lever struct nfs_client *clp) 25551da177e4SLinus Torvalds { 25561da177e4SLinus Torvalds struct compound_hdr hdr = { 2557d017931cSAndy Adamson .nops = 0, 25581da177e4SLinus Torvalds }; 25591da177e4SLinus Torvalds 25609f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2561bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2562d017931cSAndy Adamson encode_nops(&hdr); 25631da177e4SLinus Torvalds } 25641da177e4SLinus Torvalds 25651da177e4SLinus Torvalds /* 25661da177e4SLinus Torvalds * a SETCLIENTID request 25671da177e4SLinus Torvalds */ 25689f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 25699f06c719SChuck Lever struct xdr_stream *xdr, 25709f06c719SChuck Lever struct nfs4_setclientid *sc) 25711da177e4SLinus Torvalds { 25721da177e4SLinus Torvalds struct compound_hdr hdr = { 2573d017931cSAndy Adamson .nops = 0, 25741da177e4SLinus Torvalds }; 25751da177e4SLinus Torvalds 25769f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25779f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2578d017931cSAndy Adamson encode_nops(&hdr); 25791da177e4SLinus Torvalds } 25801da177e4SLinus Torvalds 25811da177e4SLinus Torvalds /* 25821da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 25831da177e4SLinus Torvalds */ 25849f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 25859f06c719SChuck Lever struct xdr_stream *xdr, 25869f06c719SChuck Lever struct nfs4_setclientid_res *arg) 25871da177e4SLinus Torvalds { 25881da177e4SLinus Torvalds struct compound_hdr hdr = { 2589d017931cSAndy Adamson .nops = 0, 25901da177e4SLinus Torvalds }; 2591dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 25921da177e4SLinus Torvalds 25939f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25949f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 25959f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 25969f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 2597d017931cSAndy Adamson encode_nops(&hdr); 25981da177e4SLinus Torvalds } 25991da177e4SLinus Torvalds 26001da177e4SLinus Torvalds /* 26011da177e4SLinus Torvalds * DELEGRETURN request 26021da177e4SLinus Torvalds */ 26039f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 26049f06c719SChuck Lever struct xdr_stream *xdr, 26059f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 26061da177e4SLinus Torvalds { 26071da177e4SLinus Torvalds struct compound_hdr hdr = { 260866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26091da177e4SLinus Torvalds }; 26101da177e4SLinus Torvalds 26119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26139f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26149f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2615e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2616d017931cSAndy Adamson encode_nops(&hdr); 26171da177e4SLinus Torvalds } 26181da177e4SLinus Torvalds 26191da177e4SLinus Torvalds /* 2620683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2621683b57b4STrond Myklebust */ 26229f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 26239f06c719SChuck Lever struct xdr_stream *xdr, 26249f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2625683b57b4STrond Myklebust { 2626683b57b4STrond Myklebust struct compound_hdr hdr = { 262766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2628683b57b4STrond Myklebust }; 262928f56694SBenny Halevy uint32_t replen; 2630683b57b4STrond Myklebust 26319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26339f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 26349f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 263528f56694SBenny Halevy replen = hdr.replen; /* get the attribute into args->page */ 26369f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2637cf8cdbe5SAndy Adamson 263828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2639683b57b4STrond Myklebust 0, PAGE_SIZE); 2640d017931cSAndy Adamson encode_nops(&hdr); 2641683b57b4STrond Myklebust } 2642683b57b4STrond Myklebust 26435a5ea0d4SBryan Schumaker /* 26445a5ea0d4SBryan Schumaker * Encode SECINFO request 26455a5ea0d4SBryan Schumaker */ 26465a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 26475a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 26485a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 26495a5ea0d4SBryan Schumaker { 26505a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 26515a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26525a5ea0d4SBryan Schumaker }; 26535a5ea0d4SBryan Schumaker 26545a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 26555a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 26565a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 26575a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 26585a5ea0d4SBryan Schumaker encode_nops(&hdr); 26595a5ea0d4SBryan Schumaker } 26605a5ea0d4SBryan Schumaker 266199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 266299fe60d0SBenny Halevy /* 26637c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 26647c44f1aeSWeston Andros Adamson */ 26657c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 26667c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 26677c44f1aeSWeston Andros Adamson struct nfs_client *clp) 26687c44f1aeSWeston Andros Adamson { 26697c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 26707c44f1aeSWeston Andros Adamson .minorversion = clp->cl_mvops->minor_version, 26717c44f1aeSWeston Andros Adamson }; 26727c44f1aeSWeston Andros Adamson 26737c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 26747c44f1aeSWeston Andros Adamson encode_bind_conn_to_session(xdr, clp->cl_session, &hdr); 26757c44f1aeSWeston Andros Adamson encode_nops(&hdr); 26767c44f1aeSWeston Andros Adamson } 26777c44f1aeSWeston Andros Adamson 26787c44f1aeSWeston Andros Adamson /* 267999fe60d0SBenny Halevy * EXCHANGE_ID request 268099fe60d0SBenny Halevy */ 26819f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 26829f06c719SChuck Lever struct xdr_stream *xdr, 268399fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 268499fe60d0SBenny Halevy { 268599fe60d0SBenny Halevy struct compound_hdr hdr = { 2686a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 268799fe60d0SBenny Halevy }; 268899fe60d0SBenny Halevy 26899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26909f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 269199fe60d0SBenny Halevy encode_nops(&hdr); 269299fe60d0SBenny Halevy } 26932050f0ccSAndy Adamson 26942050f0ccSAndy Adamson /* 2695fc931582SAndy Adamson * a CREATE_SESSION request 2696fc931582SAndy Adamson */ 26979f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 26989f06c719SChuck Lever struct xdr_stream *xdr, 2699fc931582SAndy Adamson struct nfs41_create_session_args *args) 2700fc931582SAndy Adamson { 2701fc931582SAndy Adamson struct compound_hdr hdr = { 2702a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2703fc931582SAndy Adamson }; 2704fc931582SAndy Adamson 27059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27069f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2707fc931582SAndy Adamson encode_nops(&hdr); 2708fc931582SAndy Adamson } 2709fc931582SAndy Adamson 2710fc931582SAndy Adamson /* 27110f3e66c6SAndy Adamson * a DESTROY_SESSION request 27120f3e66c6SAndy Adamson */ 27139f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 27149f06c719SChuck Lever struct xdr_stream *xdr, 27150f3e66c6SAndy Adamson struct nfs4_session *session) 27160f3e66c6SAndy Adamson { 27170f3e66c6SAndy Adamson struct compound_hdr hdr = { 2718a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 27190f3e66c6SAndy Adamson }; 27200f3e66c6SAndy Adamson 27219f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27229f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 27230f3e66c6SAndy Adamson encode_nops(&hdr); 27240f3e66c6SAndy Adamson } 27250f3e66c6SAndy Adamson 27260f3e66c6SAndy Adamson /* 2727fc01cea9SAndy Adamson * a SEQUENCE request 2728fc01cea9SAndy Adamson */ 27299f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2730fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2731fc01cea9SAndy Adamson { 2732fc01cea9SAndy Adamson struct compound_hdr hdr = { 2733fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2734fc01cea9SAndy Adamson }; 2735fc01cea9SAndy Adamson 27369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27379f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2738fc01cea9SAndy Adamson encode_nops(&hdr); 2739fc01cea9SAndy Adamson } 2740fc01cea9SAndy Adamson 2741fc01cea9SAndy Adamson /* 27422050f0ccSAndy Adamson * a GET_LEASE_TIME request 27432050f0ccSAndy Adamson */ 27449f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 27459f06c719SChuck Lever struct xdr_stream *xdr, 27462050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 27472050f0ccSAndy Adamson { 27482050f0ccSAndy Adamson struct compound_hdr hdr = { 27492050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 27502050f0ccSAndy Adamson }; 2751dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 27522050f0ccSAndy Adamson 27539f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27549f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 27559f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 27569f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 27572050f0ccSAndy Adamson encode_nops(&hdr); 27582050f0ccSAndy Adamson } 275918019753SRicardo Labiaga 276018019753SRicardo Labiaga /* 276118019753SRicardo Labiaga * a RECLAIM_COMPLETE request 276218019753SRicardo Labiaga */ 27639f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 27649f06c719SChuck Lever struct xdr_stream *xdr, 276518019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 276618019753SRicardo Labiaga { 276718019753SRicardo Labiaga struct compound_hdr hdr = { 276818019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 276918019753SRicardo Labiaga }; 277018019753SRicardo Labiaga 27719f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27729f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27739f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 277418019753SRicardo Labiaga encode_nops(&hdr); 277518019753SRicardo Labiaga } 277618019753SRicardo Labiaga 2777b1f69b75SAndy Adamson /* 27787f11d8d3SAndy Adamson * Encode GETDEVICELIST request 27797f11d8d3SAndy Adamson */ 27807f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req, 27817f11d8d3SAndy Adamson struct xdr_stream *xdr, 27827f11d8d3SAndy Adamson struct nfs4_getdevicelist_args *args) 27837f11d8d3SAndy Adamson { 27847f11d8d3SAndy Adamson struct compound_hdr hdr = { 27857f11d8d3SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27867f11d8d3SAndy Adamson }; 27877f11d8d3SAndy Adamson 27887f11d8d3SAndy Adamson encode_compound_hdr(xdr, req, &hdr); 27897f11d8d3SAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 27907f11d8d3SAndy Adamson encode_putfh(xdr, args->fh, &hdr); 27917f11d8d3SAndy Adamson encode_getdevicelist(xdr, args, &hdr); 27927f11d8d3SAndy Adamson encode_nops(&hdr); 27937f11d8d3SAndy Adamson } 27947f11d8d3SAndy Adamson 27957f11d8d3SAndy Adamson /* 2796b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2797b1f69b75SAndy Adamson */ 27989f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 27999f06c719SChuck Lever struct xdr_stream *xdr, 2800b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2801b1f69b75SAndy Adamson { 2802b1f69b75SAndy Adamson struct compound_hdr hdr = { 2803b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2804b1f69b75SAndy Adamson }; 2805b1f69b75SAndy Adamson 28069f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28079f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28089f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2809b1f69b75SAndy Adamson 2810b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2811b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2812b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2813b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2814b1f69b75SAndy Adamson args->pdev->pglen); 2815b1f69b75SAndy Adamson 2816b1f69b75SAndy Adamson encode_nops(&hdr); 2817b1f69b75SAndy Adamson } 2818b1f69b75SAndy Adamson 2819b1f69b75SAndy Adamson /* 2820b1f69b75SAndy Adamson * Encode LAYOUTGET request 2821b1f69b75SAndy Adamson */ 28229f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 28239f06c719SChuck Lever struct xdr_stream *xdr, 2824b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2825b1f69b75SAndy Adamson { 2826b1f69b75SAndy Adamson struct compound_hdr hdr = { 2827b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2828b1f69b75SAndy Adamson }; 2829b1f69b75SAndy Adamson 28309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28329f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 28339f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 283435124a09SWeston Andros Adamson 283535124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 283635124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 283735124a09SWeston Andros Adamson 2838b1f69b75SAndy Adamson encode_nops(&hdr); 2839b1f69b75SAndy Adamson } 2840863a3c6cSAndy Adamson 2841863a3c6cSAndy Adamson /* 2842863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2843863a3c6cSAndy Adamson */ 2844cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2845863a3c6cSAndy Adamson struct xdr_stream *xdr, 2846863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2847863a3c6cSAndy Adamson { 2848ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2849ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2850863a3c6cSAndy Adamson struct compound_hdr hdr = { 2851863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2852863a3c6cSAndy Adamson }; 2853863a3c6cSAndy Adamson 2854863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2855863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2856863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2857ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2858863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2859863a3c6cSAndy Adamson encode_nops(&hdr); 2860cbe82603SBenny Halevy } 2861cbe82603SBenny Halevy 2862cbe82603SBenny Halevy /* 2863cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2864cbe82603SBenny Halevy */ 2865cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2866cbe82603SBenny Halevy struct xdr_stream *xdr, 2867cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2868cbe82603SBenny Halevy { 2869cbe82603SBenny Halevy struct compound_hdr hdr = { 2870cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2871cbe82603SBenny Halevy }; 2872cbe82603SBenny Halevy 2873cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2874cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2875cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2876cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2877cbe82603SBenny Halevy encode_nops(&hdr); 2878863a3c6cSAndy Adamson } 2879fca78d6dSBryan Schumaker 2880fca78d6dSBryan Schumaker /* 2881fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2882fca78d6dSBryan Schumaker */ 2883fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2884fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2885fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2886fca78d6dSBryan Schumaker { 2887fca78d6dSBryan Schumaker struct compound_hdr hdr = { 2888fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2889fca78d6dSBryan Schumaker }; 2890fca78d6dSBryan Schumaker 2891fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 2892fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 2893fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 2894fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 2895fca78d6dSBryan Schumaker encode_nops(&hdr); 2896fca78d6dSBryan Schumaker return 0; 2897fca78d6dSBryan Schumaker } 28987d974794SBryan Schumaker 28997d974794SBryan Schumaker /* 29007d974794SBryan Schumaker * Encode TEST_STATEID request 29017d974794SBryan Schumaker */ 29027d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 29037d974794SBryan Schumaker struct xdr_stream *xdr, 29047d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 29057d974794SBryan Schumaker { 29067d974794SBryan Schumaker struct compound_hdr hdr = { 29077d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29087d974794SBryan Schumaker }; 29097d974794SBryan Schumaker 29107d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29117d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29127d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 29137d974794SBryan Schumaker encode_nops(&hdr); 29147d974794SBryan Schumaker } 29159aeda35fSBryan Schumaker 29169aeda35fSBryan Schumaker /* 29179aeda35fSBryan Schumaker * Encode FREE_STATEID request 29189aeda35fSBryan Schumaker */ 29199aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 29209aeda35fSBryan Schumaker struct xdr_stream *xdr, 29219aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 29229aeda35fSBryan Schumaker { 29239aeda35fSBryan Schumaker struct compound_hdr hdr = { 29249aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29259aeda35fSBryan Schumaker }; 29269aeda35fSBryan Schumaker 29279aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29289aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29299aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 29309aeda35fSBryan Schumaker encode_nops(&hdr); 29319aeda35fSBryan Schumaker } 293299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 293399fe60d0SBenny Halevy 2934686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 2935686841b3SBenny Halevy { 2936686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 2937686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 2938686841b3SBenny Halevy func, xdr->end - xdr->p); 2939686841b3SBenny Halevy } 29401da177e4SLinus Torvalds 2941683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 29421da177e4SLinus Torvalds { 29438687b63aSAl Viro __be32 *p; 29441da177e4SLinus Torvalds 2945c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 2946c0eae66eSBenny Halevy if (unlikely(!p)) 2947c0eae66eSBenny Halevy goto out_overflow; 2948cccddf4fSBenny Halevy *len = be32_to_cpup(p); 2949c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 2950c0eae66eSBenny Halevy if (unlikely(!p)) 2951c0eae66eSBenny Halevy goto out_overflow; 29521da177e4SLinus Torvalds *string = (char *)p; 29531da177e4SLinus Torvalds return 0; 2954c0eae66eSBenny Halevy out_overflow: 2955c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2956c0eae66eSBenny Halevy return -EIO; 29571da177e4SLinus Torvalds } 29581da177e4SLinus Torvalds 29591da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 29601da177e4SLinus Torvalds { 29618687b63aSAl Viro __be32 *p; 29621da177e4SLinus Torvalds 2963c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 2964c0eae66eSBenny Halevy if (unlikely(!p)) 2965c0eae66eSBenny Halevy goto out_overflow; 29666f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 2967cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 29681da177e4SLinus Torvalds 2969c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 2970c0eae66eSBenny Halevy if (unlikely(!p)) 2971c0eae66eSBenny Halevy goto out_overflow; 29721da177e4SLinus Torvalds hdr->tag = (char *)p; 29731da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 2974cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 2975aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 2976aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 29771da177e4SLinus Torvalds return 0; 2978c0eae66eSBenny Halevy out_overflow: 2979c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2980c0eae66eSBenny Halevy return -EIO; 29811da177e4SLinus Torvalds } 29821da177e4SLinus Torvalds 29831da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 29841da177e4SLinus Torvalds { 29858687b63aSAl Viro __be32 *p; 29861da177e4SLinus Torvalds uint32_t opnum; 29871da177e4SLinus Torvalds int32_t nfserr; 29881da177e4SLinus Torvalds 2989c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 2990c0eae66eSBenny Halevy if (unlikely(!p)) 2991c0eae66eSBenny Halevy goto out_overflow; 29926f723f77SBenny Halevy opnum = be32_to_cpup(p++); 29931da177e4SLinus Torvalds if (opnum != expected) { 2994fe82a183SChuck Lever dprintk("nfs: Server returned operation" 29951da177e4SLinus Torvalds " %d but we issued a request for %d\n", 29961da177e4SLinus Torvalds opnum, expected); 29971da177e4SLinus Torvalds return -EIO; 29981da177e4SLinus Torvalds } 2999cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 30001da177e4SLinus Torvalds if (nfserr != NFS_OK) 3001856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 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 /* Dummy routine */ 3009adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 30101da177e4SLinus Torvalds { 30118687b63aSAl Viro __be32 *p; 3012683b57b4STrond Myklebust unsigned int strlen; 30131da177e4SLinus Torvalds char *str; 30141da177e4SLinus Torvalds 3015c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3016c0eae66eSBenny Halevy if (likely(p)) 30171da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3018c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3019c0eae66eSBenny Halevy return -EIO; 30201da177e4SLinus Torvalds } 30211da177e4SLinus Torvalds 30221da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 30231da177e4SLinus Torvalds { 30248687b63aSAl Viro uint32_t bmlen; 30258687b63aSAl Viro __be32 *p; 30261da177e4SLinus Torvalds 3027c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3028c0eae66eSBenny Halevy if (unlikely(!p)) 3029c0eae66eSBenny Halevy goto out_overflow; 3030cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 30311da177e4SLinus Torvalds 3032dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3033c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3034c0eae66eSBenny Halevy if (unlikely(!p)) 3035c0eae66eSBenny Halevy goto out_overflow; 30361da177e4SLinus Torvalds if (bmlen > 0) { 30376f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3038dae100c2SFred Isaman if (bmlen > 1) { 3039dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3040dae100c2SFred Isaman if (bmlen > 2) 3041dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3042dae100c2SFred Isaman } 30431da177e4SLinus Torvalds } 30441da177e4SLinus Torvalds return 0; 3045c0eae66eSBenny Halevy out_overflow: 3046c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3047c0eae66eSBenny Halevy return -EIO; 30481da177e4SLinus Torvalds } 30491da177e4SLinus Torvalds 30508687b63aSAl Viro static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) 30511da177e4SLinus Torvalds { 30528687b63aSAl Viro __be32 *p; 30531da177e4SLinus Torvalds 3054c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3055c0eae66eSBenny Halevy if (unlikely(!p)) 3056c0eae66eSBenny Halevy goto out_overflow; 3057cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 30581da177e4SLinus Torvalds *savep = xdr->p; 30591da177e4SLinus Torvalds return 0; 3060c0eae66eSBenny Halevy out_overflow: 3061c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3062c0eae66eSBenny Halevy return -EIO; 30631da177e4SLinus Torvalds } 30641da177e4SLinus Torvalds 30651da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 30661da177e4SLinus Torvalds { 30671da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 30683388bff5SRoman Borisov int ret; 30693388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 30703388bff5SRoman Borisov if (unlikely(ret < 0)) 30713388bff5SRoman Borisov return ret; 30721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 30731da177e4SLinus Torvalds } else 3074dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3075dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3076dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 30771da177e4SLinus Torvalds return 0; 30781da177e4SLinus Torvalds } 30791da177e4SLinus Torvalds 30801da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 30811da177e4SLinus Torvalds { 30828687b63aSAl Viro __be32 *p; 3083409924e4STrond Myklebust int ret = 0; 30841da177e4SLinus Torvalds 30851da177e4SLinus Torvalds *type = 0; 30861da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 30871da177e4SLinus Torvalds return -EIO; 30881da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3089c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3090c0eae66eSBenny Halevy if (unlikely(!p)) 3091c0eae66eSBenny Halevy goto out_overflow; 3092cccddf4fSBenny Halevy *type = be32_to_cpup(p); 30931da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 30943110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 30951da177e4SLinus Torvalds return -EIO; 30961da177e4SLinus Torvalds } 30971da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3098409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 30991da177e4SLinus Torvalds } 3100bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3101409924e4STrond Myklebust return ret; 3102c0eae66eSBenny Halevy out_overflow: 3103c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3104c0eae66eSBenny Halevy return -EIO; 31051da177e4SLinus Torvalds } 31061da177e4SLinus Torvalds 3107264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3108264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3109264e6351SChuck Lever { 3110264e6351SChuck Lever __be32 *p; 3111264e6351SChuck Lever 3112264e6351SChuck Lever *type = 0; 3113264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3114264e6351SChuck Lever return -EIO; 3115264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3116264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3117264e6351SChuck Lever if (unlikely(!p)) 3118264e6351SChuck Lever goto out_overflow; 3119264e6351SChuck Lever *type = be32_to_cpup(p); 3120264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3121264e6351SChuck Lever } 3122264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3123264e6351SChuck Lever return 0; 3124264e6351SChuck Lever out_overflow: 3125264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3126264e6351SChuck Lever return -EIO; 3127264e6351SChuck Lever } 3128264e6351SChuck Lever 31291da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 31301da177e4SLinus Torvalds { 31318687b63aSAl Viro __be32 *p; 3132409924e4STrond Myklebust int ret = 0; 31331da177e4SLinus Torvalds 31341da177e4SLinus Torvalds *change = 0; 31351da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 31361da177e4SLinus Torvalds return -EIO; 31371da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3138c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3139c0eae66eSBenny Halevy if (unlikely(!p)) 3140c0eae66eSBenny Halevy goto out_overflow; 3141cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 31421da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3143409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 31441da177e4SLinus Torvalds } 31453110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 31461da177e4SLinus Torvalds (unsigned long long)*change); 3147409924e4STrond Myklebust return ret; 3148c0eae66eSBenny Halevy out_overflow: 3149c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3150c0eae66eSBenny Halevy return -EIO; 31511da177e4SLinus Torvalds } 31521da177e4SLinus Torvalds 31531da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 31541da177e4SLinus Torvalds { 31558687b63aSAl Viro __be32 *p; 3156409924e4STrond Myklebust int ret = 0; 31571da177e4SLinus Torvalds 31581da177e4SLinus Torvalds *size = 0; 31591da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 31601da177e4SLinus Torvalds return -EIO; 31611da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3162c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3163c0eae66eSBenny Halevy if (unlikely(!p)) 3164c0eae66eSBenny Halevy goto out_overflow; 3165cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 31661da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3167409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 31681da177e4SLinus Torvalds } 31693110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3170409924e4STrond Myklebust return ret; 3171c0eae66eSBenny Halevy out_overflow: 3172c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3173c0eae66eSBenny Halevy return -EIO; 31741da177e4SLinus Torvalds } 31751da177e4SLinus Torvalds 31761da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 31771da177e4SLinus Torvalds { 31788687b63aSAl Viro __be32 *p; 31791da177e4SLinus Torvalds 31801da177e4SLinus Torvalds *res = 0; 31811da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 31821da177e4SLinus Torvalds return -EIO; 31831da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3184c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3185c0eae66eSBenny Halevy if (unlikely(!p)) 3186c0eae66eSBenny Halevy goto out_overflow; 3187cccddf4fSBenny Halevy *res = be32_to_cpup(p); 31881da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 31891da177e4SLinus Torvalds } 31903110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 31911da177e4SLinus Torvalds return 0; 3192c0eae66eSBenny Halevy out_overflow: 3193c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3194c0eae66eSBenny Halevy return -EIO; 31951da177e4SLinus Torvalds } 31961da177e4SLinus Torvalds 31971da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 31981da177e4SLinus Torvalds { 31998687b63aSAl Viro __be32 *p; 32001da177e4SLinus Torvalds 32011da177e4SLinus Torvalds *res = 0; 32021da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 32031da177e4SLinus Torvalds return -EIO; 32041da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3205c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3206c0eae66eSBenny Halevy if (unlikely(!p)) 3207c0eae66eSBenny Halevy goto out_overflow; 3208cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32091da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 32101da177e4SLinus Torvalds } 32113110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 32121da177e4SLinus Torvalds return 0; 3213c0eae66eSBenny Halevy out_overflow: 3214c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3215c0eae66eSBenny Halevy return -EIO; 32161da177e4SLinus Torvalds } 32171da177e4SLinus Torvalds 32188b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 32191da177e4SLinus Torvalds { 32208687b63aSAl Viro __be32 *p; 3221409924e4STrond Myklebust int ret = 0; 32221da177e4SLinus Torvalds 32231da177e4SLinus Torvalds fsid->major = 0; 32241da177e4SLinus Torvalds fsid->minor = 0; 32251da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 32261da177e4SLinus Torvalds return -EIO; 32271da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3228c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3229c0eae66eSBenny Halevy if (unlikely(!p)) 3230c0eae66eSBenny Halevy goto out_overflow; 32313ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3232cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 32331da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3234409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 32351da177e4SLinus Torvalds } 32363110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 32371da177e4SLinus Torvalds (unsigned long long)fsid->major, 32381da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3239409924e4STrond Myklebust return ret; 3240c0eae66eSBenny Halevy out_overflow: 3241c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3242c0eae66eSBenny Halevy return -EIO; 32431da177e4SLinus Torvalds } 32441da177e4SLinus Torvalds 32451da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32461da177e4SLinus Torvalds { 32478687b63aSAl Viro __be32 *p; 32481da177e4SLinus Torvalds 32491da177e4SLinus Torvalds *res = 60; 32501da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 32511da177e4SLinus Torvalds return -EIO; 32521da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3253c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3254c0eae66eSBenny Halevy if (unlikely(!p)) 3255c0eae66eSBenny Halevy goto out_overflow; 3256cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32571da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 32581da177e4SLinus Torvalds } 32593110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 32601da177e4SLinus Torvalds return 0; 3261c0eae66eSBenny Halevy out_overflow: 3262c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3263c0eae66eSBenny Halevy return -EIO; 32641da177e4SLinus Torvalds } 32651da177e4SLinus Torvalds 3266ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3267ae42c70aSBryan Schumaker { 3268ae42c70aSBryan Schumaker __be32 *p; 3269ae42c70aSBryan Schumaker 3270ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3271ae42c70aSBryan Schumaker return -EIO; 3272ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3273ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3274ae42c70aSBryan Schumaker if (unlikely(!p)) 3275ae42c70aSBryan Schumaker goto out_overflow; 3276ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3277ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3278ae42c70aSBryan Schumaker } 3279ae42c70aSBryan Schumaker return 0; 3280ae42c70aSBryan Schumaker out_overflow: 3281ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3282ae42c70aSBryan Schumaker return -EIO; 3283ae42c70aSBryan Schumaker } 3284ae42c70aSBryan Schumaker 3285ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3286ae42c70aSBryan Schumaker { 3287ae42c70aSBryan Schumaker __be32 *p; 3288ae42c70aSBryan Schumaker int len; 3289ae42c70aSBryan Schumaker 32907ad07353STrond Myklebust if (fh != NULL) 3291ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3292ae42c70aSBryan Schumaker 3293ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3294ae42c70aSBryan Schumaker return -EIO; 3295ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3296ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3297ae42c70aSBryan Schumaker if (unlikely(!p)) 3298ae42c70aSBryan Schumaker goto out_overflow; 3299ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3300ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3301ae42c70aSBryan Schumaker return -EIO; 3302ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3303ae42c70aSBryan Schumaker if (unlikely(!p)) 3304ae42c70aSBryan Schumaker goto out_overflow; 33057ad07353STrond Myklebust if (fh != NULL) { 3306ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 33077ad07353STrond Myklebust fh->size = len; 33087ad07353STrond Myklebust } 3309ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3310ae42c70aSBryan Schumaker } 3311ae42c70aSBryan Schumaker return 0; 3312ae42c70aSBryan Schumaker out_overflow: 3313ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3314ae42c70aSBryan Schumaker return -EIO; 3315ae42c70aSBryan Schumaker } 3316ae42c70aSBryan Schumaker 33171da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33181da177e4SLinus Torvalds { 33198687b63aSAl Viro __be32 *p; 33201da177e4SLinus Torvalds 33211da177e4SLinus Torvalds *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 33221da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 33231da177e4SLinus Torvalds return -EIO; 33241da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3325c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3326c0eae66eSBenny Halevy if (unlikely(!p)) 3327c0eae66eSBenny Halevy goto out_overflow; 3328cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33291da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 33301da177e4SLinus Torvalds } 33313110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 33321da177e4SLinus Torvalds return 0; 3333c0eae66eSBenny Halevy out_overflow: 3334c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3335c0eae66eSBenny Halevy return -EIO; 33361da177e4SLinus Torvalds } 33371da177e4SLinus Torvalds 33381da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 33391da177e4SLinus Torvalds { 33408687b63aSAl Viro __be32 *p; 3341409924e4STrond Myklebust int ret = 0; 33421da177e4SLinus Torvalds 33431da177e4SLinus Torvalds *fileid = 0; 33441da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 33451da177e4SLinus Torvalds return -EIO; 33461da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3347c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3348c0eae66eSBenny Halevy if (unlikely(!p)) 3349c0eae66eSBenny Halevy goto out_overflow; 3350cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 33511da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3352409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 33531da177e4SLinus Torvalds } 33543110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3355409924e4STrond Myklebust return ret; 3356c0eae66eSBenny Halevy out_overflow: 3357c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3358c0eae66eSBenny Halevy return -EIO; 33591da177e4SLinus Torvalds } 33601da177e4SLinus Torvalds 336199baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 336299baf625SManoj Naik { 33638687b63aSAl Viro __be32 *p; 3364409924e4STrond Myklebust int ret = 0; 336599baf625SManoj Naik 336699baf625SManoj Naik *fileid = 0; 336799baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 336899baf625SManoj Naik return -EIO; 336999baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3370c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3371c0eae66eSBenny Halevy if (unlikely(!p)) 3372c0eae66eSBenny Halevy goto out_overflow; 3373cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 337499baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 337528331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 337699baf625SManoj Naik } 33773110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3378409924e4STrond Myklebust return ret; 3379c0eae66eSBenny Halevy out_overflow: 3380c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3381c0eae66eSBenny Halevy return -EIO; 338299baf625SManoj Naik } 338399baf625SManoj Naik 33841da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 33851da177e4SLinus Torvalds { 33868687b63aSAl Viro __be32 *p; 33871da177e4SLinus Torvalds int status = 0; 33881da177e4SLinus Torvalds 33891da177e4SLinus Torvalds *res = 0; 33901da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 33911da177e4SLinus Torvalds return -EIO; 33921da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3393c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3394c0eae66eSBenny Halevy if (unlikely(!p)) 3395c0eae66eSBenny Halevy goto out_overflow; 3396cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 33971da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 33981da177e4SLinus Torvalds } 33993110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 34001da177e4SLinus Torvalds return status; 3401c0eae66eSBenny Halevy out_overflow: 3402c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3403c0eae66eSBenny Halevy return -EIO; 34041da177e4SLinus Torvalds } 34051da177e4SLinus Torvalds 34061da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34071da177e4SLinus Torvalds { 34088687b63aSAl Viro __be32 *p; 34091da177e4SLinus Torvalds int status = 0; 34101da177e4SLinus Torvalds 34111da177e4SLinus Torvalds *res = 0; 34121da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 34131da177e4SLinus Torvalds return -EIO; 34141da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3415c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3416c0eae66eSBenny Halevy if (unlikely(!p)) 3417c0eae66eSBenny Halevy goto out_overflow; 3418cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34191da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 34201da177e4SLinus Torvalds } 34213110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 34221da177e4SLinus Torvalds return status; 3423c0eae66eSBenny Halevy out_overflow: 3424c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3425c0eae66eSBenny Halevy return -EIO; 34261da177e4SLinus Torvalds } 34271da177e4SLinus Torvalds 34281da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34291da177e4SLinus Torvalds { 34308687b63aSAl Viro __be32 *p; 34311da177e4SLinus Torvalds int status = 0; 34321da177e4SLinus Torvalds 34331da177e4SLinus Torvalds *res = 0; 34341da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 34351da177e4SLinus Torvalds return -EIO; 34361da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3437c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3438c0eae66eSBenny Halevy if (unlikely(!p)) 3439c0eae66eSBenny Halevy goto out_overflow; 3440cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34411da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 34421da177e4SLinus Torvalds } 34433110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 34441da177e4SLinus Torvalds return status; 3445c0eae66eSBenny Halevy out_overflow: 3446c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3447c0eae66eSBenny Halevy return -EIO; 34481da177e4SLinus Torvalds } 34491da177e4SLinus Torvalds 34507aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 34517aaa0b3bSManoj Naik { 3452464ad6b1SChuck Lever u32 n; 34538687b63aSAl Viro __be32 *p; 34547aaa0b3bSManoj Naik int status = 0; 34557aaa0b3bSManoj Naik 3456c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3457c0eae66eSBenny Halevy if (unlikely(!p)) 3458c0eae66eSBenny Halevy goto out_overflow; 3459cccddf4fSBenny Halevy n = be32_to_cpup(p); 346033a43f28SAndy Adamson if (n == 0) 346133a43f28SAndy Adamson goto root_path; 346202a2976cSChuck Lever dprintk("pathname4: "); 34637aaa0b3bSManoj Naik path->ncomponents = 0; 34647aaa0b3bSManoj Naik while (path->ncomponents < n) { 34657aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 34667aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 34677aaa0b3bSManoj Naik if (unlikely(status != 0)) 34687aaa0b3bSManoj Naik goto out_eio; 346995a13f7bSTrond Myklebust ifdebug (XDR) 347002a2976cSChuck Lever pr_cont("%s%.*s ", 347102a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 347202a2976cSChuck Lever component->len, component->data); 34737aaa0b3bSManoj Naik if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 34747aaa0b3bSManoj Naik path->ncomponents++; 34757aaa0b3bSManoj Naik else { 34767aaa0b3bSManoj Naik dprintk("cannot parse %d components in path\n", n); 34777aaa0b3bSManoj Naik goto out_eio; 34787aaa0b3bSManoj Naik } 34797aaa0b3bSManoj Naik } 34807aaa0b3bSManoj Naik out: 34817aaa0b3bSManoj Naik return status; 348233a43f28SAndy Adamson root_path: 348333a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 348433a43f28SAndy Adamson path->ncomponents = 1; 348533a43f28SAndy Adamson path->components[0].len=0; 348633a43f28SAndy Adamson path->components[0].data=NULL; 348702a2976cSChuck Lever dprintk("pathname4: /\n"); 348833a43f28SAndy Adamson goto out; 34897aaa0b3bSManoj Naik out_eio: 34907aaa0b3bSManoj Naik dprintk(" status %d", status); 34917aaa0b3bSManoj Naik status = -EIO; 34927aaa0b3bSManoj Naik goto out; 3493c0eae66eSBenny Halevy out_overflow: 3494c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3495c0eae66eSBenny Halevy return -EIO; 34967aaa0b3bSManoj Naik } 34977aaa0b3bSManoj Naik 34987aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3499683b57b4STrond Myklebust { 3500683b57b4STrond Myklebust int n; 35018687b63aSAl Viro __be32 *p; 3502683b57b4STrond Myklebust int status = -EIO; 3503683b57b4STrond Myklebust 3504683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3505683b57b4STrond Myklebust goto out; 3506683b57b4STrond Myklebust status = 0; 3507683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3508683b57b4STrond Myklebust goto out; 35098b7e3f49STrond Myklebust status = -EIO; 35108b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 35118b7e3f49STrond Myklebust if (unlikely(res == NULL)) 35128b7e3f49STrond Myklebust goto out; 351302a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 35147aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3515683b57b4STrond Myklebust if (unlikely(status != 0)) 3516683b57b4STrond Myklebust goto out; 3517c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3518c0eae66eSBenny Halevy if (unlikely(!p)) 3519c0eae66eSBenny Halevy goto out_overflow; 3520cccddf4fSBenny Halevy n = be32_to_cpup(p); 3521683b57b4STrond Myklebust if (n <= 0) 3522683b57b4STrond Myklebust goto out_eio; 3523683b57b4STrond Myklebust res->nlocations = 0; 3524683b57b4STrond Myklebust while (res->nlocations < n) { 3525464ad6b1SChuck Lever u32 m; 35267aaa0b3bSManoj Naik struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 3527683b57b4STrond Myklebust 3528c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3529c0eae66eSBenny Halevy if (unlikely(!p)) 3530c0eae66eSBenny Halevy goto out_overflow; 3531cccddf4fSBenny Halevy m = be32_to_cpup(p); 35327aaa0b3bSManoj Naik 35337aaa0b3bSManoj Naik loc->nservers = 0; 353402a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 35357aaa0b3bSManoj Naik while (loc->nservers < m) { 35367aaa0b3bSManoj Naik struct nfs4_string *server = &loc->servers[loc->nservers]; 35377aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &server->len, &server->data); 3538683b57b4STrond Myklebust if (unlikely(status != 0)) 3539683b57b4STrond Myklebust goto out_eio; 35407aaa0b3bSManoj Naik dprintk("%s ", server->data); 35417aaa0b3bSManoj Naik if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) 35427aaa0b3bSManoj Naik loc->nservers++; 35437aaa0b3bSManoj Naik else { 3544464ad6b1SChuck Lever unsigned int i; 3545464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3546464ad6b1SChuck Lever "returned for location %u\n", 35473110ff80SHarvey Harrison __func__, 3548464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3549464ad6b1SChuck Lever m, res->nlocations); 35507aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 35512e42c3e2STrond Myklebust unsigned int len; 35527aaa0b3bSManoj Naik char *data; 35537aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3554683b57b4STrond Myklebust if (unlikely(status != 0)) 3555683b57b4STrond Myklebust goto out_eio; 35567aaa0b3bSManoj Naik } 35577aaa0b3bSManoj Naik } 35587aaa0b3bSManoj Naik } 35597aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 35607aaa0b3bSManoj Naik if (unlikely(status != 0)) 35617aaa0b3bSManoj Naik goto out_eio; 35627aaa0b3bSManoj Naik if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) 3563683b57b4STrond Myklebust res->nlocations++; 3564683b57b4STrond Myklebust } 3565409924e4STrond Myklebust if (res->nlocations != 0) 356681934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3567683b57b4STrond Myklebust out: 35683110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3569683b57b4STrond Myklebust return status; 3570c0eae66eSBenny Halevy out_overflow: 3571c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3572683b57b4STrond Myklebust out_eio: 3573683b57b4STrond Myklebust status = -EIO; 3574683b57b4STrond Myklebust goto out; 3575683b57b4STrond Myklebust } 3576683b57b4STrond Myklebust 35771da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35781da177e4SLinus Torvalds { 35798687b63aSAl Viro __be32 *p; 35801da177e4SLinus Torvalds int status = 0; 35811da177e4SLinus Torvalds 35821da177e4SLinus Torvalds *res = 0; 35831da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 35841da177e4SLinus Torvalds return -EIO; 35851da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3586c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3587c0eae66eSBenny Halevy if (unlikely(!p)) 3588c0eae66eSBenny Halevy goto out_overflow; 3589cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35901da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 35911da177e4SLinus Torvalds } 35923110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 35931da177e4SLinus Torvalds return status; 3594c0eae66eSBenny Halevy out_overflow: 3595c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3596c0eae66eSBenny Halevy return -EIO; 35971da177e4SLinus Torvalds } 35981da177e4SLinus Torvalds 35991da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 36001da177e4SLinus Torvalds { 36018687b63aSAl Viro __be32 *p; 36021da177e4SLinus Torvalds int status = 0; 36031da177e4SLinus Torvalds 36041da177e4SLinus Torvalds *maxlink = 1; 36051da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 36061da177e4SLinus Torvalds return -EIO; 36071da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3608c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3609c0eae66eSBenny Halevy if (unlikely(!p)) 3610c0eae66eSBenny Halevy goto out_overflow; 3611cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 36121da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 36131da177e4SLinus Torvalds } 36143110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 36151da177e4SLinus Torvalds return status; 3616c0eae66eSBenny Halevy out_overflow: 3617c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3618c0eae66eSBenny Halevy return -EIO; 36191da177e4SLinus Torvalds } 36201da177e4SLinus Torvalds 36211da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 36221da177e4SLinus Torvalds { 36238687b63aSAl Viro __be32 *p; 36241da177e4SLinus Torvalds int status = 0; 36251da177e4SLinus Torvalds 36261da177e4SLinus Torvalds *maxname = 1024; 36271da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 36281da177e4SLinus Torvalds return -EIO; 36291da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3630c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3631c0eae66eSBenny Halevy if (unlikely(!p)) 3632c0eae66eSBenny Halevy goto out_overflow; 3633cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 36341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 36351da177e4SLinus Torvalds } 36363110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 36371da177e4SLinus Torvalds return status; 3638c0eae66eSBenny Halevy out_overflow: 3639c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3640c0eae66eSBenny Halevy return -EIO; 36411da177e4SLinus Torvalds } 36421da177e4SLinus Torvalds 36431da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36441da177e4SLinus Torvalds { 36458687b63aSAl Viro __be32 *p; 36461da177e4SLinus Torvalds int status = 0; 36471da177e4SLinus Torvalds 36481da177e4SLinus Torvalds *res = 1024; 36491da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 36501da177e4SLinus Torvalds return -EIO; 36511da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 36521da177e4SLinus Torvalds uint64_t maxread; 3653c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3654c0eae66eSBenny Halevy if (unlikely(!p)) 3655c0eae66eSBenny Halevy goto out_overflow; 3656cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 36571da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 36581da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 36591da177e4SLinus Torvalds *res = (uint32_t)maxread; 36601da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 36611da177e4SLinus Torvalds } 36623110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 36631da177e4SLinus Torvalds return status; 3664c0eae66eSBenny Halevy out_overflow: 3665c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3666c0eae66eSBenny Halevy return -EIO; 36671da177e4SLinus Torvalds } 36681da177e4SLinus Torvalds 36691da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36701da177e4SLinus Torvalds { 36718687b63aSAl Viro __be32 *p; 36721da177e4SLinus Torvalds int status = 0; 36731da177e4SLinus Torvalds 36741da177e4SLinus Torvalds *res = 1024; 36751da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 36761da177e4SLinus Torvalds return -EIO; 36771da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 36781da177e4SLinus Torvalds uint64_t maxwrite; 3679c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3680c0eae66eSBenny Halevy if (unlikely(!p)) 3681c0eae66eSBenny Halevy goto out_overflow; 3682cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 36831da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 36841da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 36851da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 36861da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 36871da177e4SLinus Torvalds } 36883110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 36891da177e4SLinus Torvalds return status; 3690c0eae66eSBenny Halevy out_overflow: 3691c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3692c0eae66eSBenny Halevy return -EIO; 36931da177e4SLinus Torvalds } 36941da177e4SLinus Torvalds 3695bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 36961da177e4SLinus Torvalds { 3697bca79478STrond Myklebust uint32_t tmp; 36988687b63aSAl Viro __be32 *p; 3699409924e4STrond Myklebust int ret = 0; 37001da177e4SLinus Torvalds 37011da177e4SLinus Torvalds *mode = 0; 37021da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 37031da177e4SLinus Torvalds return -EIO; 37041da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3705c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3706c0eae66eSBenny Halevy if (unlikely(!p)) 3707c0eae66eSBenny Halevy goto out_overflow; 3708cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3709bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 37101da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3711409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 37121da177e4SLinus Torvalds } 37133110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3714409924e4STrond Myklebust return ret; 3715c0eae66eSBenny Halevy out_overflow: 3716c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3717c0eae66eSBenny Halevy return -EIO; 37181da177e4SLinus Torvalds } 37191da177e4SLinus Torvalds 37201da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 37211da177e4SLinus Torvalds { 37228687b63aSAl Viro __be32 *p; 3723409924e4STrond Myklebust int ret = 0; 37241da177e4SLinus Torvalds 37251da177e4SLinus Torvalds *nlink = 1; 37261da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 37271da177e4SLinus Torvalds return -EIO; 37281da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3729c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3730c0eae66eSBenny Halevy if (unlikely(!p)) 3731c0eae66eSBenny Halevy goto out_overflow; 3732cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 37331da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3734409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 37351da177e4SLinus Torvalds } 37363110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3737409924e4STrond Myklebust return ret; 3738c0eae66eSBenny Halevy out_overflow: 3739c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3740c0eae66eSBenny Halevy return -EIO; 37411da177e4SLinus Torvalds } 37421da177e4SLinus Torvalds 374380e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 37446926afd1STrond Myklebust const struct nfs_server *server, uint32_t *uid, 37456926afd1STrond Myklebust struct nfs4_string *owner_name) 37461da177e4SLinus Torvalds { 37478687b63aSAl Viro uint32_t len; 37488687b63aSAl Viro __be32 *p; 3749409924e4STrond Myklebust int ret = 0; 37501da177e4SLinus Torvalds 37511da177e4SLinus Torvalds *uid = -2; 37521da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 37531da177e4SLinus Torvalds return -EIO; 37541da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3755c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3756c0eae66eSBenny Halevy if (unlikely(!p)) 3757c0eae66eSBenny Halevy goto out_overflow; 3758cccddf4fSBenny Halevy len = be32_to_cpup(p); 3759c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3760c0eae66eSBenny Halevy if (unlikely(!p)) 3761c0eae66eSBenny Halevy goto out_overflow; 37626926afd1STrond Myklebust if (owner_name != NULL) { 37636926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 37646926afd1STrond Myklebust if (owner_name->data != NULL) { 37656926afd1STrond Myklebust owner_name->len = len; 37666926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 37676926afd1STrond Myklebust } 376880e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3769e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3770409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3771409924e4STrond Myklebust else 37721da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 37733110ff80SHarvey Harrison __func__); 37741da177e4SLinus Torvalds } else 3775fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 37763110ff80SHarvey Harrison __func__, len); 37771da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 37781da177e4SLinus Torvalds } 37793110ff80SHarvey Harrison dprintk("%s: uid=%d\n", __func__, (int)*uid); 3780409924e4STrond Myklebust return ret; 3781c0eae66eSBenny Halevy out_overflow: 3782c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3783c0eae66eSBenny Halevy return -EIO; 37841da177e4SLinus Torvalds } 37851da177e4SLinus Torvalds 378680e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 37876926afd1STrond Myklebust const struct nfs_server *server, uint32_t *gid, 37886926afd1STrond Myklebust struct nfs4_string *group_name) 37891da177e4SLinus Torvalds { 37908687b63aSAl Viro uint32_t len; 37918687b63aSAl Viro __be32 *p; 3792409924e4STrond Myklebust int ret = 0; 37931da177e4SLinus Torvalds 37941da177e4SLinus Torvalds *gid = -2; 37951da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 37961da177e4SLinus Torvalds return -EIO; 37971da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3798c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3799c0eae66eSBenny Halevy if (unlikely(!p)) 3800c0eae66eSBenny Halevy goto out_overflow; 3801cccddf4fSBenny Halevy len = be32_to_cpup(p); 3802c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3803c0eae66eSBenny Halevy if (unlikely(!p)) 3804c0eae66eSBenny Halevy goto out_overflow; 38056926afd1STrond Myklebust if (group_name != NULL) { 38066926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 38076926afd1STrond Myklebust if (group_name->data != NULL) { 38086926afd1STrond Myklebust group_name->len = len; 38096926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 38106926afd1STrond Myklebust } 381180e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3812e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3813409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3814409924e4STrond Myklebust else 38151da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 38163110ff80SHarvey Harrison __func__); 38171da177e4SLinus Torvalds } else 3818fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 38193110ff80SHarvey Harrison __func__, len); 38201da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 38211da177e4SLinus Torvalds } 38223110ff80SHarvey Harrison dprintk("%s: gid=%d\n", __func__, (int)*gid); 3823409924e4STrond Myklebust return ret; 3824c0eae66eSBenny Halevy out_overflow: 3825c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3826c0eae66eSBenny Halevy return -EIO; 38271da177e4SLinus Torvalds } 38281da177e4SLinus Torvalds 38291da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 38301da177e4SLinus Torvalds { 38318687b63aSAl Viro uint32_t major = 0, minor = 0; 38328687b63aSAl Viro __be32 *p; 3833409924e4STrond Myklebust int ret = 0; 38341da177e4SLinus Torvalds 38351da177e4SLinus Torvalds *rdev = MKDEV(0,0); 38361da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 38371da177e4SLinus Torvalds return -EIO; 38381da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 38391da177e4SLinus Torvalds dev_t tmp; 38401da177e4SLinus Torvalds 3841c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3842c0eae66eSBenny Halevy if (unlikely(!p)) 3843c0eae66eSBenny Halevy goto out_overflow; 38446f723f77SBenny Halevy major = be32_to_cpup(p++); 3845cccddf4fSBenny Halevy minor = be32_to_cpup(p); 38461da177e4SLinus Torvalds tmp = MKDEV(major, minor); 38471da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 38481da177e4SLinus Torvalds *rdev = tmp; 38491da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3850409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 38511da177e4SLinus Torvalds } 38523110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3853409924e4STrond Myklebust return ret; 3854c0eae66eSBenny Halevy out_overflow: 3855c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3856c0eae66eSBenny Halevy return -EIO; 38571da177e4SLinus Torvalds } 38581da177e4SLinus Torvalds 38591da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38601da177e4SLinus Torvalds { 38618687b63aSAl Viro __be32 *p; 38621da177e4SLinus Torvalds int status = 0; 38631da177e4SLinus Torvalds 38641da177e4SLinus Torvalds *res = 0; 38651da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 38661da177e4SLinus Torvalds return -EIO; 38671da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3868c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3869c0eae66eSBenny Halevy if (unlikely(!p)) 3870c0eae66eSBenny Halevy goto out_overflow; 3871cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38721da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 38731da177e4SLinus Torvalds } 38743110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 38751da177e4SLinus Torvalds return status; 3876c0eae66eSBenny Halevy out_overflow: 3877c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3878c0eae66eSBenny Halevy return -EIO; 38791da177e4SLinus Torvalds } 38801da177e4SLinus Torvalds 38811da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38821da177e4SLinus Torvalds { 38838687b63aSAl Viro __be32 *p; 38841da177e4SLinus Torvalds int status = 0; 38851da177e4SLinus Torvalds 38861da177e4SLinus Torvalds *res = 0; 38871da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 38881da177e4SLinus Torvalds return -EIO; 38891da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3890c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3891c0eae66eSBenny Halevy if (unlikely(!p)) 3892c0eae66eSBenny Halevy goto out_overflow; 3893cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38941da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 38951da177e4SLinus Torvalds } 38963110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 38971da177e4SLinus Torvalds return status; 3898c0eae66eSBenny Halevy out_overflow: 3899c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3900c0eae66eSBenny Halevy return -EIO; 39011da177e4SLinus Torvalds } 39021da177e4SLinus Torvalds 39031da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39041da177e4SLinus Torvalds { 39058687b63aSAl Viro __be32 *p; 39061da177e4SLinus Torvalds int status = 0; 39071da177e4SLinus Torvalds 39081da177e4SLinus Torvalds *res = 0; 39091da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 39101da177e4SLinus Torvalds return -EIO; 39111da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 3912c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3913c0eae66eSBenny Halevy if (unlikely(!p)) 3914c0eae66eSBenny Halevy goto out_overflow; 3915cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39161da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 39171da177e4SLinus Torvalds } 39183110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 39191da177e4SLinus Torvalds return status; 3920c0eae66eSBenny Halevy out_overflow: 3921c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3922c0eae66eSBenny Halevy return -EIO; 39231da177e4SLinus Torvalds } 39241da177e4SLinus Torvalds 39251da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 39261da177e4SLinus Torvalds { 39278687b63aSAl Viro __be32 *p; 3928409924e4STrond Myklebust int ret = 0; 39291da177e4SLinus Torvalds 39301da177e4SLinus Torvalds *used = 0; 39311da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 39321da177e4SLinus Torvalds return -EIO; 39331da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 3934c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3935c0eae66eSBenny Halevy if (unlikely(!p)) 3936c0eae66eSBenny Halevy goto out_overflow; 3937cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 39381da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 3939409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 39401da177e4SLinus Torvalds } 39413110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 39421da177e4SLinus Torvalds (unsigned long long)*used); 3943409924e4STrond Myklebust return ret; 3944c0eae66eSBenny Halevy out_overflow: 3945c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3946c0eae66eSBenny Halevy return -EIO; 39471da177e4SLinus Torvalds } 39481da177e4SLinus Torvalds 39491da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 39501da177e4SLinus Torvalds { 39518687b63aSAl Viro __be32 *p; 39521da177e4SLinus Torvalds uint64_t sec; 39531da177e4SLinus Torvalds uint32_t nsec; 39541da177e4SLinus Torvalds 3955c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3956c0eae66eSBenny Halevy if (unlikely(!p)) 3957c0eae66eSBenny Halevy goto out_overflow; 39583ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 3959cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 39601da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 39611da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 39621da177e4SLinus Torvalds return 0; 3963c0eae66eSBenny Halevy out_overflow: 3964c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3965c0eae66eSBenny Halevy return -EIO; 39661da177e4SLinus Torvalds } 39671da177e4SLinus Torvalds 39681da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39691da177e4SLinus Torvalds { 39701da177e4SLinus Torvalds int status = 0; 39711da177e4SLinus Torvalds 39721da177e4SLinus Torvalds time->tv_sec = 0; 39731da177e4SLinus Torvalds time->tv_nsec = 0; 39741da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 39751da177e4SLinus Torvalds return -EIO; 39761da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 39771da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 3978409924e4STrond Myklebust if (status == 0) 3979409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 39801da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 39811da177e4SLinus Torvalds } 39823110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 39831da177e4SLinus Torvalds return status; 39841da177e4SLinus Torvalds } 39851da177e4SLinus Torvalds 39861da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39871da177e4SLinus Torvalds { 39881da177e4SLinus Torvalds int status = 0; 39891da177e4SLinus Torvalds 39901da177e4SLinus Torvalds time->tv_sec = 0; 39911da177e4SLinus Torvalds time->tv_nsec = 0; 39921da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 39931da177e4SLinus Torvalds return -EIO; 39941da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 39951da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 3996409924e4STrond Myklebust if (status == 0) 3997409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 39981da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 39991da177e4SLinus Torvalds } 40003110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 40011da177e4SLinus Torvalds return status; 40021da177e4SLinus Torvalds } 40031da177e4SLinus Torvalds 400455b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 400555b6e774SRicardo Labiaga struct timespec *time) 400655b6e774SRicardo Labiaga { 400755b6e774SRicardo Labiaga int status = 0; 400855b6e774SRicardo Labiaga 400955b6e774SRicardo Labiaga time->tv_sec = 0; 401055b6e774SRicardo Labiaga time->tv_nsec = 0; 401155b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 401255b6e774SRicardo Labiaga return -EIO; 401355b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 401455b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 401555b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 401655b6e774SRicardo Labiaga } 401755b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 401855b6e774SRicardo Labiaga (long)time->tv_nsec); 401955b6e774SRicardo Labiaga return status; 402055b6e774SRicardo Labiaga } 402155b6e774SRicardo Labiaga 40221da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40231da177e4SLinus Torvalds { 40241da177e4SLinus Torvalds int status = 0; 40251da177e4SLinus Torvalds 40261da177e4SLinus Torvalds time->tv_sec = 0; 40271da177e4SLinus Torvalds time->tv_nsec = 0; 40281da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 40291da177e4SLinus Torvalds return -EIO; 40301da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 40311da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4032409924e4STrond Myklebust if (status == 0) 4033409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 40341da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 40351da177e4SLinus Torvalds } 40363110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 40371da177e4SLinus Torvalds return status; 40381da177e4SLinus Torvalds } 40391da177e4SLinus Torvalds 40408687b63aSAl Viro static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) 40411da177e4SLinus Torvalds { 40421da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 40431da177e4SLinus Torvalds unsigned int nwords = xdr->p - savep; 40441da177e4SLinus Torvalds 40451da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4046fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4047fe82a183SChuck Lever "%u %c %u\n", 40483110ff80SHarvey Harrison __func__, 40491da177e4SLinus Torvalds attrwords << 2, 40501da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 40511da177e4SLinus Torvalds nwords << 2); 40521da177e4SLinus Torvalds return -EIO; 40531da177e4SLinus Torvalds } 40541da177e4SLinus Torvalds return 0; 40551da177e4SLinus Torvalds } 40561da177e4SLinus Torvalds 40571da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 40581da177e4SLinus Torvalds { 40598687b63aSAl Viro __be32 *p; 40601da177e4SLinus Torvalds 4061c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4062c0eae66eSBenny Halevy if (unlikely(!p)) 4063c0eae66eSBenny Halevy goto out_overflow; 40646f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 40653ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4066cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 40671da177e4SLinus Torvalds return 0; 4068c0eae66eSBenny Halevy out_overflow: 4069c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4070c0eae66eSBenny Halevy return -EIO; 40711da177e4SLinus Torvalds } 40721da177e4SLinus Torvalds 40731da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 40741da177e4SLinus Torvalds { 40758687b63aSAl Viro __be32 *p; 40761da177e4SLinus Torvalds uint32_t supp, acc; 40771da177e4SLinus Torvalds int status; 40781da177e4SLinus Torvalds 40791da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 40801da177e4SLinus Torvalds if (status) 40811da177e4SLinus Torvalds return status; 4082c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4083c0eae66eSBenny Halevy if (unlikely(!p)) 4084c0eae66eSBenny Halevy goto out_overflow; 40856f723f77SBenny Halevy supp = be32_to_cpup(p++); 4086cccddf4fSBenny Halevy acc = be32_to_cpup(p); 40871da177e4SLinus Torvalds access->supported = supp; 40881da177e4SLinus Torvalds access->access = acc; 40891da177e4SLinus Torvalds return 0; 4090c0eae66eSBenny Halevy out_overflow: 4091c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4092c0eae66eSBenny Halevy return -EIO; 40931da177e4SLinus Torvalds } 40941da177e4SLinus Torvalds 409507d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 40961da177e4SLinus Torvalds { 40978687b63aSAl Viro __be32 *p; 409807d30434SBenny Halevy 409907d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 410007d30434SBenny Halevy if (likely(p)) { 410107d30434SBenny Halevy memcpy(buf, p, len); 410207d30434SBenny Halevy return 0; 410307d30434SBenny Halevy } 410407d30434SBenny Halevy print_overflow_msg(__func__, xdr); 410507d30434SBenny Halevy return -EIO; 410607d30434SBenny Halevy } 410707d30434SBenny Halevy 410807d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 410907d30434SBenny Halevy { 41102d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 41111da177e4SLinus Torvalds } 41121da177e4SLinus Torvalds 41131da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 41141da177e4SLinus Torvalds { 41151da177e4SLinus Torvalds int status; 41161da177e4SLinus Torvalds 41171da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4118c1d51931STrond Myklebust if (status != -EIO) 4119c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 412007d30434SBenny Halevy if (!status) 412107d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 41221da177e4SLinus Torvalds return status; 41231da177e4SLinus Torvalds } 41241da177e4SLinus Torvalds 4125db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4126db942bbdSBenny Halevy { 4127cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 41281da177e4SLinus Torvalds } 41291da177e4SLinus Torvalds 41300b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 41311da177e4SLinus Torvalds { 41321da177e4SLinus Torvalds int status; 41331da177e4SLinus Torvalds 41341da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4135db942bbdSBenny Halevy if (!status) 4136db942bbdSBenny Halevy status = decode_verifier(xdr, res->verf->verifier); 41371da177e4SLinus Torvalds return status; 41381da177e4SLinus Torvalds } 41391da177e4SLinus Torvalds 41401da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 41411da177e4SLinus Torvalds { 41428687b63aSAl Viro __be32 *p; 41431da177e4SLinus Torvalds uint32_t bmlen; 41441da177e4SLinus Torvalds int status; 41451da177e4SLinus Torvalds 41461da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 41471da177e4SLinus Torvalds if (status) 41481da177e4SLinus Torvalds return status; 41491da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 41501da177e4SLinus Torvalds return status; 4151c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4152c0eae66eSBenny Halevy if (unlikely(!p)) 4153c0eae66eSBenny Halevy goto out_overflow; 4154cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4155c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4156c0eae66eSBenny Halevy if (likely(p)) 41571da177e4SLinus Torvalds return 0; 4158c0eae66eSBenny Halevy out_overflow: 4159c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4160c0eae66eSBenny Halevy return -EIO; 41611da177e4SLinus Torvalds } 41621da177e4SLinus Torvalds 41631da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 41641da177e4SLinus Torvalds { 41658687b63aSAl Viro __be32 *savep; 4166dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41671da177e4SLinus Torvalds int status; 41681da177e4SLinus Torvalds 41691da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 41701da177e4SLinus Torvalds goto xdr_error; 41711da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 41721da177e4SLinus Torvalds goto xdr_error; 41731da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 41741da177e4SLinus Torvalds goto xdr_error; 41751da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 41761da177e4SLinus Torvalds goto xdr_error; 4177264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4178264e6351SChuck Lever &res->fh_expire_type)) != 0) 4179264e6351SChuck Lever goto xdr_error; 41801da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 41811da177e4SLinus Torvalds goto xdr_error; 41821da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 41831da177e4SLinus Torvalds goto xdr_error; 41841da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 41851da177e4SLinus Torvalds goto xdr_error; 41861da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 41871da177e4SLinus Torvalds xdr_error: 41883110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 41891da177e4SLinus Torvalds return status; 41901da177e4SLinus Torvalds } 41911da177e4SLinus Torvalds 41921da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 41931da177e4SLinus Torvalds { 41948687b63aSAl Viro __be32 *savep; 4195dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41961da177e4SLinus Torvalds int status; 41971da177e4SLinus Torvalds 41981da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 41991da177e4SLinus Torvalds goto xdr_error; 42001da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42011da177e4SLinus Torvalds goto xdr_error; 42021da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42031da177e4SLinus Torvalds goto xdr_error; 42041da177e4SLinus Torvalds 42051da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 42061da177e4SLinus Torvalds goto xdr_error; 42071da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 42081da177e4SLinus Torvalds goto xdr_error; 42091da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 42101da177e4SLinus Torvalds goto xdr_error; 42111da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 42121da177e4SLinus Torvalds goto xdr_error; 42131da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 42141da177e4SLinus Torvalds goto xdr_error; 42151da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 42161da177e4SLinus Torvalds goto xdr_error; 42171da177e4SLinus Torvalds 42181da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42191da177e4SLinus Torvalds xdr_error: 42203110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42211da177e4SLinus Torvalds return status; 42221da177e4SLinus Torvalds } 42231da177e4SLinus Torvalds 42241da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 42251da177e4SLinus Torvalds { 42268687b63aSAl Viro __be32 *savep; 4227dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 42281da177e4SLinus Torvalds int status; 42291da177e4SLinus Torvalds 42301da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42311da177e4SLinus Torvalds goto xdr_error; 42321da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42331da177e4SLinus Torvalds goto xdr_error; 42341da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42351da177e4SLinus Torvalds goto xdr_error; 42361da177e4SLinus Torvalds 42371da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 42381da177e4SLinus Torvalds goto xdr_error; 42391da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 42401da177e4SLinus Torvalds goto xdr_error; 42411da177e4SLinus Torvalds 42421da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42431da177e4SLinus Torvalds xdr_error: 42443110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42451da177e4SLinus Torvalds return status; 42461da177e4SLinus Torvalds } 42471da177e4SLinus Torvalds 424888034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 424988034c3dSAndy Adamson uint32_t *bitmap, 425088034c3dSAndy Adamson uint64_t *res, 425188034c3dSAndy Adamson uint32_t hint_bit) 425288034c3dSAndy Adamson { 425388034c3dSAndy Adamson __be32 *p; 425488034c3dSAndy Adamson 425588034c3dSAndy Adamson *res = 0; 425688034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 425788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 425888034c3dSAndy Adamson if (unlikely(!p)) 425988034c3dSAndy Adamson goto out_overflow; 426088034c3dSAndy Adamson xdr_decode_hyper(p, res); 426188034c3dSAndy Adamson } 426288034c3dSAndy Adamson return 0; 426388034c3dSAndy Adamson out_overflow: 426488034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 426588034c3dSAndy Adamson return -EIO; 426688034c3dSAndy Adamson } 426788034c3dSAndy Adamson 426888034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 426988034c3dSAndy Adamson struct nfs4_threshold *res) 427088034c3dSAndy Adamson { 427188034c3dSAndy Adamson __be32 *p, *savep; 427288034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 427388034c3dSAndy Adamson int status; 427488034c3dSAndy Adamson 427588034c3dSAndy Adamson /* layout type */ 427688034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 427788034c3dSAndy Adamson if (unlikely(!p)) { 427888034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 427988034c3dSAndy Adamson return -EIO; 428088034c3dSAndy Adamson } 428188034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 428288034c3dSAndy Adamson 428388034c3dSAndy Adamson /* thi_hintset bitmap */ 428488034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 428588034c3dSAndy Adamson if (status < 0) 428688034c3dSAndy Adamson goto xdr_error; 428788034c3dSAndy Adamson 428888034c3dSAndy Adamson /* thi_hintlist length */ 428988034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 429088034c3dSAndy Adamson if (status < 0) 429188034c3dSAndy Adamson goto xdr_error; 429288034c3dSAndy Adamson /* thi_hintlist */ 429388034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 429488034c3dSAndy Adamson if (status < 0) 429588034c3dSAndy Adamson goto xdr_error; 429688034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 429788034c3dSAndy Adamson if (status < 0) 429888034c3dSAndy Adamson goto xdr_error; 429988034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 430088034c3dSAndy Adamson THRESHOLD_RD_IO); 430188034c3dSAndy Adamson if (status < 0) 430288034c3dSAndy Adamson goto xdr_error; 430388034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 430488034c3dSAndy Adamson THRESHOLD_WR_IO); 430588034c3dSAndy Adamson if (status < 0) 430688034c3dSAndy Adamson goto xdr_error; 430788034c3dSAndy Adamson 430888034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 430988034c3dSAndy Adamson res->bm = bitmap[0]; 431088034c3dSAndy Adamson 431188034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 431288034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 431388034c3dSAndy Adamson res->wr_io_sz); 431488034c3dSAndy Adamson xdr_error: 431588034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 431688034c3dSAndy Adamson return status; 431788034c3dSAndy Adamson } 431888034c3dSAndy Adamson 431988034c3dSAndy Adamson /* 432088034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 432188034c3dSAndy Adamson */ 432288034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 432388034c3dSAndy Adamson uint32_t *bitmap, 432488034c3dSAndy Adamson struct nfs4_threshold *res) 432588034c3dSAndy Adamson { 432688034c3dSAndy Adamson __be32 *p; 432788034c3dSAndy Adamson int status = 0; 432888034c3dSAndy Adamson uint32_t num; 432988034c3dSAndy Adamson 433088034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 433188034c3dSAndy Adamson return -EIO; 433288034c3dSAndy Adamson if (likely(bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD)) { 433388034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 433488034c3dSAndy Adamson if (unlikely(!p)) 433588034c3dSAndy Adamson goto out_overflow; 433688034c3dSAndy Adamson num = be32_to_cpup(p); 433788034c3dSAndy Adamson if (num == 0) 433888034c3dSAndy Adamson return 0; 433988034c3dSAndy Adamson if (num > 1) 434088034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 434188034c3dSAndy Adamson "drivers per filesystem not supported\n", 434288034c3dSAndy Adamson __func__); 434388034c3dSAndy Adamson 434488034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 434588034c3dSAndy Adamson } 434688034c3dSAndy Adamson return status; 434788034c3dSAndy Adamson out_overflow: 434888034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 434988034c3dSAndy Adamson return -EIO; 435088034c3dSAndy Adamson } 435188034c3dSAndy Adamson 4352ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4353ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 43548b7e3f49STrond Myklebust struct nfs4_fs_locations *fs_loc, 43556926afd1STrond Myklebust const struct nfs_server *server) 43561da177e4SLinus Torvalds { 4357bca79478STrond Myklebust int status; 4358bca79478STrond Myklebust umode_t fmode = 0; 4359ae42c70aSBryan Schumaker uint32_t type; 4360ee7b75fcSTrond Myklebust int32_t err; 43611da177e4SLinus Torvalds 4362f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4363f26c7a78STrond Myklebust if (status < 0) 43641da177e4SLinus Torvalds goto xdr_error; 4365409924e4STrond Myklebust fattr->mode = 0; 4366409924e4STrond Myklebust if (status != 0) { 4367409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4368409924e4STrond Myklebust fattr->valid |= status; 4369409924e4STrond Myklebust } 43701da177e4SLinus Torvalds 4371f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4372f26c7a78STrond Myklebust if (status < 0) 43731da177e4SLinus Torvalds goto xdr_error; 4374409924e4STrond Myklebust fattr->valid |= status; 4375f26c7a78STrond Myklebust 4376f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4377f26c7a78STrond Myklebust if (status < 0) 43781da177e4SLinus Torvalds goto xdr_error; 4379409924e4STrond Myklebust fattr->valid |= status; 4380f26c7a78STrond Myklebust 4381f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4382f26c7a78STrond Myklebust if (status < 0) 43831da177e4SLinus Torvalds goto xdr_error; 4384409924e4STrond Myklebust fattr->valid |= status; 4385f26c7a78STrond Myklebust 4386ee7b75fcSTrond Myklebust err = 0; 4387ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4388ae42c70aSBryan Schumaker if (status < 0) 4389ae42c70aSBryan Schumaker goto xdr_error; 4390ae42c70aSBryan Schumaker 4391ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4392ae42c70aSBryan Schumaker if (status < 0) 4393ae42c70aSBryan Schumaker goto xdr_error; 4394ae42c70aSBryan Schumaker 4395f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4396f26c7a78STrond Myklebust if (status < 0) 43971da177e4SLinus Torvalds goto xdr_error; 4398409924e4STrond Myklebust fattr->valid |= status; 4399f26c7a78STrond Myklebust 44008b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4401f26c7a78STrond Myklebust if (status < 0) 4402683b57b4STrond Myklebust goto xdr_error; 4403409924e4STrond Myklebust fattr->valid |= status; 4404f26c7a78STrond Myklebust 4405f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4406f26c7a78STrond Myklebust if (status < 0) 44071da177e4SLinus Torvalds goto xdr_error; 4408409924e4STrond Myklebust if (status != 0) { 44091da177e4SLinus Torvalds fattr->mode |= fmode; 4410409924e4STrond Myklebust fattr->valid |= status; 4411409924e4STrond Myklebust } 4412f26c7a78STrond Myklebust 4413f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4414f26c7a78STrond Myklebust if (status < 0) 44151da177e4SLinus Torvalds goto xdr_error; 4416409924e4STrond Myklebust fattr->valid |= status; 4417f26c7a78STrond Myklebust 44186926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4419f26c7a78STrond Myklebust if (status < 0) 44201da177e4SLinus Torvalds goto xdr_error; 4421409924e4STrond Myklebust fattr->valid |= status; 4422f26c7a78STrond Myklebust 44236926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4424f26c7a78STrond Myklebust if (status < 0) 44251da177e4SLinus Torvalds goto xdr_error; 4426409924e4STrond Myklebust fattr->valid |= status; 4427f26c7a78STrond Myklebust 4428f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4429f26c7a78STrond Myklebust if (status < 0) 44301da177e4SLinus Torvalds goto xdr_error; 4431409924e4STrond Myklebust fattr->valid |= status; 4432f26c7a78STrond Myklebust 4433f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4434f26c7a78STrond Myklebust if (status < 0) 44351da177e4SLinus Torvalds goto xdr_error; 4436409924e4STrond Myklebust fattr->valid |= status; 4437f26c7a78STrond Myklebust 4438f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4439f26c7a78STrond Myklebust if (status < 0) 44401da177e4SLinus Torvalds goto xdr_error; 4441409924e4STrond Myklebust fattr->valid |= status; 4442f26c7a78STrond Myklebust 4443f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4444f26c7a78STrond Myklebust if (status < 0) 44451da177e4SLinus Torvalds goto xdr_error; 4446409924e4STrond Myklebust fattr->valid |= status; 4447f26c7a78STrond Myklebust 4448f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4449f26c7a78STrond Myklebust if (status < 0) 44501da177e4SLinus Torvalds goto xdr_error; 4451409924e4STrond Myklebust fattr->valid |= status; 4452f26c7a78STrond Myklebust 445328331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4454f26c7a78STrond Myklebust if (status < 0) 445599baf625SManoj Naik goto xdr_error; 4456409924e4STrond Myklebust fattr->valid |= status; 4457f26c7a78STrond Myklebust 445888034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 445988034c3dSAndy Adamson if (status < 0) 446088034c3dSAndy Adamson goto xdr_error; 446188034c3dSAndy Adamson 4462ae42c70aSBryan Schumaker xdr_error: 4463ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4464ae42c70aSBryan Schumaker return status; 4465ae42c70aSBryan Schumaker } 4466ae42c70aSBryan Schumaker 4467ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 44688b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 44698b7e3f49STrond Myklebust const struct nfs_server *server) 4470ae42c70aSBryan Schumaker { 4471ae42c70aSBryan Schumaker __be32 *savep; 4472ae42c70aSBryan Schumaker uint32_t attrlen, 4473dae100c2SFred Isaman bitmap[3] = {0}; 4474ae42c70aSBryan Schumaker int status; 4475ae42c70aSBryan Schumaker 4476ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4477ae42c70aSBryan Schumaker if (status < 0) 4478ae42c70aSBryan Schumaker goto xdr_error; 4479ae42c70aSBryan Schumaker 4480ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4481ae42c70aSBryan Schumaker if (status < 0) 4482ae42c70aSBryan Schumaker goto xdr_error; 4483ae42c70aSBryan Schumaker 4484ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4485ae42c70aSBryan Schumaker if (status < 0) 4486ae42c70aSBryan Schumaker goto xdr_error; 4487ae42c70aSBryan Schumaker 44888b7e3f49STrond Myklebust status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server); 4489ae42c70aSBryan Schumaker if (status < 0) 4490ae42c70aSBryan Schumaker goto xdr_error; 4491ae42c70aSBryan Schumaker 4492f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 44931da177e4SLinus Torvalds xdr_error: 44943110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 44951da177e4SLinus Torvalds return status; 44961da177e4SLinus Torvalds } 44971da177e4SLinus Torvalds 4498ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 44996926afd1STrond Myklebust const struct nfs_server *server) 4500ae42c70aSBryan Schumaker { 45018b7e3f49STrond Myklebust return decode_getfattr_generic(xdr, fattr, NULL, NULL, server); 4502ae42c70aSBryan Schumaker } 45031da177e4SLinus Torvalds 4504504913fbSAndy Adamson /* 4505504913fbSAndy Adamson * Decode potentially multiple layout types. Currently we only support 4506504913fbSAndy Adamson * one layout driver per file system. 4507504913fbSAndy Adamson */ 4508504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, 4509504913fbSAndy Adamson uint32_t *layouttype) 4510504913fbSAndy Adamson { 4511504913fbSAndy Adamson uint32_t *p; 4512504913fbSAndy Adamson int num; 4513504913fbSAndy Adamson 4514504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4515504913fbSAndy Adamson if (unlikely(!p)) 4516504913fbSAndy Adamson goto out_overflow; 4517504913fbSAndy Adamson num = be32_to_cpup(p); 4518504913fbSAndy Adamson 4519504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4520504913fbSAndy Adamson if (num == 0) { 4521504913fbSAndy Adamson *layouttype = 0; 4522504913fbSAndy Adamson return 0; 4523504913fbSAndy Adamson } 4524504913fbSAndy Adamson if (num > 1) 4525a030889aSWeston Andros Adamson printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout " 4526a030889aSWeston Andros Adamson "drivers per filesystem not supported\n", __func__); 4527504913fbSAndy Adamson 4528504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4529504913fbSAndy Adamson p = xdr_inline_decode(xdr, num * 4); 4530504913fbSAndy Adamson if (unlikely(!p)) 4531504913fbSAndy Adamson goto out_overflow; 4532504913fbSAndy Adamson *layouttype = be32_to_cpup(p); 4533504913fbSAndy Adamson return 0; 4534504913fbSAndy Adamson out_overflow: 4535504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4536504913fbSAndy Adamson return -EIO; 4537504913fbSAndy Adamson } 4538504913fbSAndy Adamson 4539504913fbSAndy Adamson /* 4540504913fbSAndy Adamson * The type of file system exported. 4541504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4542504913fbSAndy Adamson */ 4543504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4544504913fbSAndy Adamson uint32_t *layouttype) 4545504913fbSAndy Adamson { 4546504913fbSAndy Adamson int status = 0; 4547504913fbSAndy Adamson 4548504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4549504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4550504913fbSAndy Adamson return -EIO; 4551504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4552504913fbSAndy Adamson status = decode_first_pnfs_layout_type(xdr, layouttype); 4553504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 4554504913fbSAndy Adamson } else 4555504913fbSAndy Adamson *layouttype = 0; 4556504913fbSAndy Adamson return status; 4557504913fbSAndy Adamson } 4558504913fbSAndy Adamson 4559dae100c2SFred Isaman /* 4560dae100c2SFred Isaman * The prefered block size for layout directed io 4561dae100c2SFred Isaman */ 4562dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4563dae100c2SFred Isaman uint32_t *res) 4564dae100c2SFred Isaman { 4565dae100c2SFred Isaman __be32 *p; 4566dae100c2SFred Isaman 4567dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4568dae100c2SFred Isaman *res = 0; 4569dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4570dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4571dae100c2SFred Isaman if (unlikely(!p)) { 4572dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4573dae100c2SFred Isaman return -EIO; 4574dae100c2SFred Isaman } 4575dae100c2SFred Isaman *res = be32_to_cpup(p); 4576dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4577dae100c2SFred Isaman } 4578dae100c2SFred Isaman return 0; 4579dae100c2SFred Isaman } 4580dae100c2SFred Isaman 45811da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 45821da177e4SLinus Torvalds { 45838687b63aSAl Viro __be32 *savep; 4584dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 45851da177e4SLinus Torvalds int status; 45861da177e4SLinus Torvalds 45871da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45881da177e4SLinus Torvalds goto xdr_error; 45891da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45901da177e4SLinus Torvalds goto xdr_error; 45911da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45921da177e4SLinus Torvalds goto xdr_error; 45931da177e4SLinus Torvalds 45941da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 45951da177e4SLinus Torvalds 45961da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 45971da177e4SLinus Torvalds goto xdr_error; 45981da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 45991da177e4SLinus Torvalds goto xdr_error; 46001da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 46011da177e4SLinus Torvalds goto xdr_error; 46021da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 46031da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 46041da177e4SLinus Torvalds goto xdr_error; 46051da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 460655b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 460755b6e774SRicardo Labiaga if (status != 0) 460855b6e774SRicardo Labiaga goto xdr_error; 4609504913fbSAndy Adamson status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); 4610504913fbSAndy Adamson if (status != 0) 4611504913fbSAndy Adamson goto xdr_error; 4612dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4613dae100c2SFred Isaman if (status) 4614dae100c2SFred Isaman goto xdr_error; 46151da177e4SLinus Torvalds 46161da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 46171da177e4SLinus Torvalds xdr_error: 46183110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 46191da177e4SLinus Torvalds return status; 46201da177e4SLinus Torvalds } 46211da177e4SLinus Torvalds 46221da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 46231da177e4SLinus Torvalds { 46248687b63aSAl Viro __be32 *p; 46251da177e4SLinus Torvalds uint32_t len; 46261da177e4SLinus Torvalds int status; 46271da177e4SLinus Torvalds 46289936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 46299936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 46309936781dSTrond Myklebust 46311da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 46321da177e4SLinus Torvalds if (status) 46331da177e4SLinus Torvalds return status; 46341da177e4SLinus Torvalds 4635c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4636c0eae66eSBenny Halevy if (unlikely(!p)) 4637c0eae66eSBenny Halevy goto out_overflow; 4638cccddf4fSBenny Halevy len = be32_to_cpup(p); 46391da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 46401da177e4SLinus Torvalds return -EIO; 46411da177e4SLinus Torvalds fh->size = len; 4642c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4643c0eae66eSBenny Halevy if (unlikely(!p)) 4644c0eae66eSBenny Halevy goto out_overflow; 464599398d06SBenny Halevy memcpy(fh->data, p, len); 46461da177e4SLinus Torvalds return 0; 4647c0eae66eSBenny Halevy out_overflow: 4648c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4649c0eae66eSBenny Halevy return -EIO; 46501da177e4SLinus Torvalds } 46511da177e4SLinus Torvalds 46521da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 46531da177e4SLinus Torvalds { 46541da177e4SLinus Torvalds int status; 46551da177e4SLinus Torvalds 46561da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 46571da177e4SLinus Torvalds if (status) 46581da177e4SLinus Torvalds return status; 46591da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 46601da177e4SLinus Torvalds } 46611da177e4SLinus Torvalds 46621da177e4SLinus Torvalds /* 46631da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 46641da177e4SLinus Torvalds */ 4665911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 46661da177e4SLinus Torvalds { 4667911d1aafSTrond Myklebust uint64_t offset, length, clientid; 46688687b63aSAl Viro __be32 *p; 4669911d1aafSTrond Myklebust uint32_t namelen, type; 46701da177e4SLinus Torvalds 4671babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4672c0eae66eSBenny Halevy if (unlikely(!p)) 4673c0eae66eSBenny Halevy goto out_overflow; 4674babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 46753ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4676babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4677babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4678911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4679911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4680911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4681911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4682911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4683911d1aafSTrond Myklebust if (type & 1) 4684911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4685911d1aafSTrond Myklebust fl->fl_pid = 0; 4686911d1aafSTrond Myklebust } 4687babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4688babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4689babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4690c0eae66eSBenny Halevy if (likely(p)) 46911da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4692c0eae66eSBenny Halevy out_overflow: 4693c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4694c0eae66eSBenny Halevy return -EIO; 46951da177e4SLinus Torvalds } 46961da177e4SLinus Torvalds 4697911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 46981da177e4SLinus Torvalds { 46991da177e4SLinus Torvalds int status; 47001da177e4SLinus Torvalds 47011da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4702c1d51931STrond Myklebust if (status == -EIO) 4703c1d51931STrond Myklebust goto out; 47041da177e4SLinus Torvalds if (status == 0) { 470507d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 470607d30434SBenny Halevy if (unlikely(status)) 470707d30434SBenny Halevy goto out; 47081da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4709c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4710c1d51931STrond Myklebust if (res->open_seqid != NULL) 4711c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4712c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4713c1d51931STrond Myklebust out: 47141da177e4SLinus Torvalds return status; 47151da177e4SLinus Torvalds } 47161da177e4SLinus Torvalds 4717911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 47181da177e4SLinus Torvalds { 47191da177e4SLinus Torvalds int status; 47201da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 47211da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4722911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 47231da177e4SLinus Torvalds return status; 47241da177e4SLinus Torvalds } 47251da177e4SLinus Torvalds 4726911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 47271da177e4SLinus Torvalds { 47281da177e4SLinus Torvalds int status; 47291da177e4SLinus Torvalds 47301da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4731c1d51931STrond Myklebust if (status != -EIO) 4732c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 473307d30434SBenny Halevy if (status == 0) 473407d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 47351da177e4SLinus Torvalds return status; 47361da177e4SLinus Torvalds } 47371da177e4SLinus Torvalds 4738d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4739d3c7b7ccSTrond Myklebust { 4740d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4741d3c7b7ccSTrond Myklebust } 4742d3c7b7ccSTrond Myklebust 47431da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 47441da177e4SLinus Torvalds { 47451da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 47461da177e4SLinus Torvalds } 47471da177e4SLinus Torvalds 47481da177e4SLinus Torvalds /* This is too sick! */ 47491da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 47501da177e4SLinus Torvalds { 47518687b63aSAl Viro __be32 *p; 47521da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 47531da177e4SLinus Torvalds 4754c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4755c0eae66eSBenny Halevy if (unlikely(!p)) 4756c0eae66eSBenny Halevy goto out_overflow; 47576f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 47581da177e4SLinus Torvalds switch (limit_type) { 47591da177e4SLinus Torvalds case 1: 4760cccddf4fSBenny Halevy xdr_decode_hyper(p, maxsize); 47611da177e4SLinus Torvalds break; 47621da177e4SLinus Torvalds case 2: 47636f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 4764cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 47651da177e4SLinus Torvalds *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 47661da177e4SLinus Torvalds } 47671da177e4SLinus Torvalds return 0; 4768c0eae66eSBenny Halevy out_overflow: 4769c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4770c0eae66eSBenny Halevy return -EIO; 47711da177e4SLinus Torvalds } 47721da177e4SLinus Torvalds 47731da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 47741da177e4SLinus Torvalds { 47758687b63aSAl Viro __be32 *p; 47761da177e4SLinus Torvalds uint32_t delegation_type; 477707d30434SBenny Halevy int status; 47781da177e4SLinus Torvalds 4779c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4780c0eae66eSBenny Halevy if (unlikely(!p)) 4781c0eae66eSBenny Halevy goto out_overflow; 4782cccddf4fSBenny Halevy delegation_type = be32_to_cpup(p); 47831da177e4SLinus Torvalds if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 47841da177e4SLinus Torvalds res->delegation_type = 0; 47851da177e4SLinus Torvalds return 0; 47861da177e4SLinus Torvalds } 478707d30434SBenny Halevy status = decode_stateid(xdr, &res->delegation); 478807d30434SBenny Halevy if (unlikely(status)) 478907d30434SBenny Halevy return status; 4790c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4791c0eae66eSBenny Halevy if (unlikely(!p)) 4792c0eae66eSBenny Halevy goto out_overflow; 4793cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 479405d564feSAndy Adamson 47951da177e4SLinus Torvalds switch (delegation_type) { 47961da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 47971da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 47981da177e4SLinus Torvalds break; 47991da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 48001da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 48011da177e4SLinus Torvalds if (decode_space_limit(xdr, &res->maxsize) < 0) 48021da177e4SLinus Torvalds return -EIO; 48031da177e4SLinus Torvalds } 48047539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 4805c0eae66eSBenny Halevy out_overflow: 4806c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4807c0eae66eSBenny Halevy return -EIO; 48081da177e4SLinus Torvalds } 48091da177e4SLinus Torvalds 48101da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 48111da177e4SLinus Torvalds { 48128687b63aSAl Viro __be32 *p; 4813aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 48141da177e4SLinus Torvalds int status; 48151da177e4SLinus Torvalds 48161da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN); 4817c1d51931STrond Myklebust if (status != -EIO) 4818c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 481907d30434SBenny Halevy if (!status) 482007d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 482107d30434SBenny Halevy if (unlikely(status)) 48221da177e4SLinus Torvalds return status; 48231da177e4SLinus Torvalds 48241da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 48251da177e4SLinus Torvalds 4826c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4827c0eae66eSBenny Halevy if (unlikely(!p)) 4828c0eae66eSBenny Halevy goto out_overflow; 48296f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 4830cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 48311da177e4SLinus Torvalds if (bmlen > 10) 48321da177e4SLinus Torvalds goto xdr_error; 48331da177e4SLinus Torvalds 4834c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4835c0eae66eSBenny Halevy if (unlikely(!p)) 4836c0eae66eSBenny Halevy goto out_overflow; 4837aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 4838aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 48396f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 4840aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 4841aa53ed54SJeff Layton res->attrset[i] = 0; 4842aa53ed54SJeff Layton 48431da177e4SLinus Torvalds return decode_delegation(xdr, res); 48441da177e4SLinus Torvalds xdr_error: 48453110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 48461da177e4SLinus Torvalds return -EIO; 4847c0eae66eSBenny Halevy out_overflow: 4848c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4849c0eae66eSBenny Halevy return -EIO; 48501da177e4SLinus Torvalds } 48511da177e4SLinus Torvalds 48521da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 48531da177e4SLinus Torvalds { 48541da177e4SLinus Torvalds int status; 48551da177e4SLinus Torvalds 48561da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 4857c1d51931STrond Myklebust if (status != -EIO) 4858c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 485907d30434SBenny Halevy if (!status) 486007d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 48611da177e4SLinus Torvalds return status; 48621da177e4SLinus Torvalds } 48631da177e4SLinus Torvalds 48641da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 48651da177e4SLinus Torvalds { 48661da177e4SLinus Torvalds int status; 48671da177e4SLinus Torvalds 48681da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 4869c1d51931STrond Myklebust if (status != -EIO) 4870c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 487107d30434SBenny Halevy if (!status) 487207d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 48731da177e4SLinus Torvalds return status; 48741da177e4SLinus Torvalds } 48751da177e4SLinus Torvalds 48761da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 48771da177e4SLinus Torvalds { 48781da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 48791da177e4SLinus Torvalds } 48801da177e4SLinus Torvalds 48811da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 48821da177e4SLinus Torvalds { 48831da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 48841da177e4SLinus Torvalds } 48851da177e4SLinus Torvalds 48861da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 48871da177e4SLinus Torvalds { 48881da177e4SLinus Torvalds struct kvec *iov = req->rq_rcv_buf.head; 48898687b63aSAl Viro __be32 *p; 48901da177e4SLinus Torvalds uint32_t count, eof, recvd, hdrlen; 48911da177e4SLinus Torvalds int status; 48921da177e4SLinus Torvalds 48931da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 48941da177e4SLinus Torvalds if (status) 48951da177e4SLinus Torvalds return status; 4896c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4897c0eae66eSBenny Halevy if (unlikely(!p)) 4898c0eae66eSBenny Halevy goto out_overflow; 48996f723f77SBenny Halevy eof = be32_to_cpup(p++); 4900cccddf4fSBenny Halevy count = be32_to_cpup(p); 49018111f373SChuck Lever hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 49021da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 49031da177e4SLinus Torvalds if (count > recvd) { 4904fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 49051da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 49061da177e4SLinus Torvalds count = recvd; 49071da177e4SLinus Torvalds eof = 0; 49081da177e4SLinus Torvalds } 49091da177e4SLinus Torvalds xdr_read_pages(xdr, count); 49101da177e4SLinus Torvalds res->eof = eof; 49111da177e4SLinus Torvalds res->count = count; 49121da177e4SLinus Torvalds return 0; 4913c0eae66eSBenny Halevy out_overflow: 4914c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4915c0eae66eSBenny Halevy return -EIO; 49161da177e4SLinus Torvalds } 49171da177e4SLinus Torvalds 49181da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 49191da177e4SLinus Torvalds { 49201da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 49211da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4922bcecff77SChuck Lever size_t hdrlen; 4923bcecff77SChuck Lever u32 recvd, pglen = rcvbuf->page_len; 4924bcecff77SChuck Lever int status; 4925cd93710eSChuck Lever __be32 verf[2]; 49261da177e4SLinus Torvalds 49271da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 4928db942bbdSBenny Halevy if (!status) 4929db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 4930db942bbdSBenny Halevy if (unlikely(status)) 49311da177e4SLinus Torvalds return status; 4932cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 493344109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 4934cd93710eSChuck Lever __func__, verf[0], verf[1]); 49351da177e4SLinus Torvalds 4936db942bbdSBenny Halevy hdrlen = (char *) xdr->p - (char *) iov->iov_base; 49371da177e4SLinus Torvalds recvd = rcvbuf->len - hdrlen; 49381da177e4SLinus Torvalds if (pglen > recvd) 49391da177e4SLinus Torvalds pglen = recvd; 49401da177e4SLinus Torvalds xdr_read_pages(xdr, pglen); 49411da177e4SLinus Torvalds 49427bda2cdfSJeff Layton 4943ac396128STrond Myklebust return pglen; 49441da177e4SLinus Torvalds } 49451da177e4SLinus Torvalds 49461da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 49471da177e4SLinus Torvalds { 49481da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 49491da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4950bcecff77SChuck Lever size_t hdrlen; 4951bcecff77SChuck Lever u32 len, recvd; 49528687b63aSAl Viro __be32 *p; 49531da177e4SLinus Torvalds int status; 49541da177e4SLinus Torvalds 49551da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 49561da177e4SLinus Torvalds if (status) 49571da177e4SLinus Torvalds return status; 49581da177e4SLinus Torvalds 49591da177e4SLinus Torvalds /* Convert length of symlink */ 4960c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4961c0eae66eSBenny Halevy if (unlikely(!p)) 4962c0eae66eSBenny Halevy goto out_overflow; 4963cccddf4fSBenny Halevy len = be32_to_cpup(p); 49641da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 4965fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 49661da177e4SLinus Torvalds return -ENAMETOOLONG; 49671da177e4SLinus Torvalds } 49681da177e4SLinus Torvalds hdrlen = (char *) xdr->p - (char *) iov->iov_base; 49691da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 49701da177e4SLinus Torvalds if (recvd < len) { 4971fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 49721da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 49731da177e4SLinus Torvalds return -EIO; 49741da177e4SLinus Torvalds } 49751da177e4SLinus Torvalds xdr_read_pages(xdr, len); 49761da177e4SLinus Torvalds /* 49771da177e4SLinus Torvalds * The XDR encode routine has set things up so that 49781da177e4SLinus Torvalds * the link text will be copied directly into the 49791da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 49801da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 49811da177e4SLinus Torvalds * null-termination). 49821da177e4SLinus Torvalds */ 4983b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 49841da177e4SLinus Torvalds return 0; 4985c0eae66eSBenny Halevy out_overflow: 4986c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4987c0eae66eSBenny Halevy return -EIO; 49881da177e4SLinus Torvalds } 49891da177e4SLinus Torvalds 49901da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 49911da177e4SLinus Torvalds { 49921da177e4SLinus Torvalds int status; 49931da177e4SLinus Torvalds 49941da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 49951da177e4SLinus Torvalds if (status) 49961da177e4SLinus Torvalds goto out; 49971da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 49981da177e4SLinus Torvalds out: 49991da177e4SLinus Torvalds return status; 50001da177e4SLinus Torvalds } 50011da177e4SLinus Torvalds 50021da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 50031da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 50041da177e4SLinus Torvalds { 50051da177e4SLinus Torvalds int status; 50061da177e4SLinus Torvalds 50071da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 50081da177e4SLinus Torvalds if (status) 50091da177e4SLinus Torvalds goto out; 50101da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 50111da177e4SLinus Torvalds goto out; 50121da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 50131da177e4SLinus Torvalds out: 50141da177e4SLinus Torvalds return status; 50151da177e4SLinus Torvalds } 50161da177e4SLinus Torvalds 50171da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 50181da177e4SLinus Torvalds { 50191da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 50201da177e4SLinus Torvalds } 50211da177e4SLinus Torvalds 502256ae19f3STrond Myklebust static int 502356ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 502456ae19f3STrond Myklebust { 502556ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 502656ae19f3STrond Myklebust } 502756ae19f3STrond Myklebust 5028029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5029bf118a34SAndy Adamson struct nfs_getaclres *res) 5030029d105eSJ. Bruce Fields { 5031bf118a34SAndy Adamson __be32 *savep, *bm_p; 5032029d105eSJ. Bruce Fields uint32_t attrlen, 5033dae100c2SFred Isaman bitmap[3] = {0}; 5034029d105eSJ. Bruce Fields struct kvec *iov = req->rq_rcv_buf.head; 5035029d105eSJ. Bruce Fields int status; 50365a006899SSachin Prabhu size_t page_len = xdr->buf->page_len; 5037029d105eSJ. Bruce Fields 5038bf118a34SAndy Adamson res->acl_len = 0; 5039029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5040029d105eSJ. Bruce Fields goto out; 50415a006899SSachin Prabhu 5042bf118a34SAndy Adamson bm_p = xdr->p; 50435a006899SSachin Prabhu res->acl_data_offset = be32_to_cpup(bm_p) + 2; 50445a006899SSachin Prabhu res->acl_data_offset <<= 2; 50455a006899SSachin Prabhu /* Check if the acl data starts beyond the allocated buffer */ 50465a006899SSachin Prabhu if (res->acl_data_offset > page_len) 50475a006899SSachin Prabhu return -ERANGE; 50485a006899SSachin Prabhu 5049029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5050029d105eSJ. Bruce Fields goto out; 5051029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5052029d105eSJ. Bruce Fields goto out; 5053029d105eSJ. Bruce Fields 5054029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5055029d105eSJ. Bruce Fields return -EIO; 5056029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5057bcecff77SChuck Lever size_t hdrlen; 5058029d105eSJ. Bruce Fields 5059bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5060bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5061bf118a34SAndy Adamson * variable length bitmaps.*/ 5062bf118a34SAndy Adamson xdr->p = bm_p; 5063bf118a34SAndy Adamson 5064029d105eSJ. Bruce Fields /* We ignore &savep and don't do consistency checks on 5065029d105eSJ. Bruce Fields * the attr length. Let userspace figure it out.... */ 5066029d105eSJ. Bruce Fields hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; 5067bf118a34SAndy Adamson attrlen += res->acl_data_offset; 50685a006899SSachin Prabhu if (attrlen > page_len) { 5069bf118a34SAndy Adamson if (res->acl_flags & NFS4_ACL_LEN_REQUEST) { 5070bf118a34SAndy Adamson /* getxattr interface called with a NULL buf */ 5071bf118a34SAndy Adamson res->acl_len = attrlen; 5072bf118a34SAndy Adamson goto out; 5073bf118a34SAndy Adamson } 50745794d21eSSachin Prabhu dprintk("NFS: acl reply: attrlen %u > page_len %zu\n", 50755a006899SSachin Prabhu attrlen, page_len); 5076029d105eSJ. Bruce Fields return -EINVAL; 5077029d105eSJ. Bruce Fields } 5078029d105eSJ. Bruce Fields xdr_read_pages(xdr, attrlen); 5079bf118a34SAndy Adamson res->acl_len = attrlen; 50808c233cf9SJ. Bruce Fields } else 50818c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5082029d105eSJ. Bruce Fields 5083029d105eSJ. Bruce Fields out: 5084029d105eSJ. Bruce Fields return status; 5085029d105eSJ. Bruce Fields } 5086029d105eSJ. Bruce Fields 50871da177e4SLinus Torvalds static int 50881da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 50891da177e4SLinus Torvalds { 50901da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 50911da177e4SLinus Torvalds } 50921da177e4SLinus Torvalds 50939e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 50941da177e4SLinus Torvalds { 50958687b63aSAl Viro __be32 *p; 50961da177e4SLinus Torvalds uint32_t bmlen; 50971da177e4SLinus Torvalds int status; 50981da177e4SLinus Torvalds 50991da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 51001da177e4SLinus Torvalds if (status) 51011da177e4SLinus Torvalds return status; 5102c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5103c0eae66eSBenny Halevy if (unlikely(!p)) 5104c0eae66eSBenny Halevy goto out_overflow; 5105cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5106c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5107c0eae66eSBenny Halevy if (likely(p)) 51081da177e4SLinus Torvalds return 0; 5109c0eae66eSBenny Halevy out_overflow: 5110c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5111c0eae66eSBenny Halevy return -EIO; 51121da177e4SLinus Torvalds } 51131da177e4SLinus Torvalds 5114bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 51151da177e4SLinus Torvalds { 51168687b63aSAl Viro __be32 *p; 51171da177e4SLinus Torvalds uint32_t opnum; 51181da177e4SLinus Torvalds int32_t nfserr; 51191da177e4SLinus Torvalds 5120c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5121c0eae66eSBenny Halevy if (unlikely(!p)) 5122c0eae66eSBenny Halevy goto out_overflow; 51236f723f77SBenny Halevy opnum = be32_to_cpup(p++); 51241da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5125fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 51261da177e4SLinus Torvalds " %d\n", opnum); 51271da177e4SLinus Torvalds return -EIO; 51281da177e4SLinus Torvalds } 5129cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 51301da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5131c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5132c0eae66eSBenny Halevy if (unlikely(!p)) 5133c0eae66eSBenny Halevy goto out_overflow; 5134bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5135bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 51361da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 51371da177e4SLinus Torvalds uint32_t len; 51381da177e4SLinus Torvalds 51391da177e4SLinus Torvalds /* skip netid string */ 5140c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5141c0eae66eSBenny Halevy if (unlikely(!p)) 5142c0eae66eSBenny Halevy goto out_overflow; 5143cccddf4fSBenny Halevy len = be32_to_cpup(p); 5144c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5145c0eae66eSBenny Halevy if (unlikely(!p)) 5146c0eae66eSBenny Halevy goto out_overflow; 51471da177e4SLinus Torvalds 51481da177e4SLinus Torvalds /* skip uaddr string */ 5149c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5150c0eae66eSBenny Halevy if (unlikely(!p)) 5151c0eae66eSBenny Halevy goto out_overflow; 5152cccddf4fSBenny Halevy len = be32_to_cpup(p); 5153c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5154c0eae66eSBenny Halevy if (unlikely(!p)) 5155c0eae66eSBenny Halevy goto out_overflow; 51561da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 51571da177e4SLinus Torvalds } else 5158856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 51591da177e4SLinus Torvalds 51601da177e4SLinus Torvalds return 0; 5161c0eae66eSBenny Halevy out_overflow: 5162c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5163c0eae66eSBenny Halevy return -EIO; 51641da177e4SLinus Torvalds } 51651da177e4SLinus Torvalds 51661da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 51671da177e4SLinus Torvalds { 51681da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 51691da177e4SLinus Torvalds } 51701da177e4SLinus Torvalds 51711da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 51721da177e4SLinus Torvalds { 51738687b63aSAl Viro __be32 *p; 51741da177e4SLinus Torvalds int status; 51751da177e4SLinus Torvalds 51761da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 51771da177e4SLinus Torvalds if (status) 51781da177e4SLinus Torvalds return status; 51791da177e4SLinus Torvalds 5180c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 5181c0eae66eSBenny Halevy if (unlikely(!p)) 5182c0eae66eSBenny Halevy goto out_overflow; 51836f723f77SBenny Halevy res->count = be32_to_cpup(p++); 51846f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 5185cd93710eSChuck Lever memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE); 51861da177e4SLinus Torvalds return 0; 5187c0eae66eSBenny Halevy out_overflow: 5188c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5189c0eae66eSBenny Halevy return -EIO; 51901da177e4SLinus Torvalds } 51911da177e4SLinus Torvalds 51921da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 51931da177e4SLinus Torvalds { 51941da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 51951da177e4SLinus Torvalds } 51961da177e4SLinus Torvalds 51975a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor) 51985a5ea0d4SBryan Schumaker { 51995a5ea0d4SBryan Schumaker __be32 *p; 52005a5ea0d4SBryan Schumaker 52015a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 52025a5ea0d4SBryan Schumaker if (unlikely(!p)) 52035a5ea0d4SBryan Schumaker goto out_overflow; 52045a5ea0d4SBryan Schumaker flavor->gss.sec_oid4.len = be32_to_cpup(p); 52055a5ea0d4SBryan Schumaker if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN) 52065a5ea0d4SBryan Schumaker goto out_err; 52075a5ea0d4SBryan Schumaker 52085a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len); 52095a5ea0d4SBryan Schumaker if (unlikely(!p)) 52105a5ea0d4SBryan Schumaker goto out_overflow; 52115a5ea0d4SBryan Schumaker memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len); 52125a5ea0d4SBryan Schumaker 52135a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 52145a5ea0d4SBryan Schumaker if (unlikely(!p)) 52155a5ea0d4SBryan Schumaker goto out_overflow; 52165a5ea0d4SBryan Schumaker flavor->gss.qop4 = be32_to_cpup(p++); 52175a5ea0d4SBryan Schumaker flavor->gss.service = be32_to_cpup(p); 52185a5ea0d4SBryan Schumaker 52195a5ea0d4SBryan Schumaker return 0; 52205a5ea0d4SBryan Schumaker 52215a5ea0d4SBryan Schumaker out_overflow: 52225a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 52235a5ea0d4SBryan Schumaker return -EIO; 52245a5ea0d4SBryan Schumaker out_err: 52255a5ea0d4SBryan Schumaker return -EINVAL; 52265a5ea0d4SBryan Schumaker } 52275a5ea0d4SBryan Schumaker 522831e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 52295a5ea0d4SBryan Schumaker { 52305a5ea0d4SBryan Schumaker struct nfs4_secinfo_flavor *sec_flavor; 52315a5ea0d4SBryan Schumaker int status; 52325a5ea0d4SBryan Schumaker __be32 *p; 5233c3dfc280SBryan Schumaker int i, num_flavors; 52345a5ea0d4SBryan Schumaker 52355a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 52365a5ea0d4SBryan Schumaker if (unlikely(!p)) 52375a5ea0d4SBryan Schumaker goto out_overflow; 52385a5ea0d4SBryan Schumaker 5239c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5240c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5241c3dfc280SBryan Schumaker 5242c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 52435a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5244c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 52455a5ea0d4SBryan Schumaker break; 52465a5ea0d4SBryan Schumaker 52475a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 52485a5ea0d4SBryan Schumaker if (unlikely(!p)) 52495a5ea0d4SBryan Schumaker goto out_overflow; 52505a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 52515a5ea0d4SBryan Schumaker 52525a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5253613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5254613e901eSBryan Schumaker if (status) 5255613e901eSBryan Schumaker goto out; 52565a5ea0d4SBryan Schumaker } 5257c3dfc280SBryan Schumaker res->flavors->num_flavors++; 52585a5ea0d4SBryan Schumaker } 52595a5ea0d4SBryan Schumaker 526031e4dda4SBryan Schumaker status = 0; 5261613e901eSBryan Schumaker out: 5262613e901eSBryan Schumaker return status; 52635a5ea0d4SBryan Schumaker out_overflow: 52645a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 52655a5ea0d4SBryan Schumaker return -EIO; 52665a5ea0d4SBryan Schumaker } 52675a5ea0d4SBryan Schumaker 526831e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 526931e4dda4SBryan Schumaker { 527031e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 527131e4dda4SBryan Schumaker if (status) 527231e4dda4SBryan Schumaker return status; 527331e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 527431e4dda4SBryan Schumaker } 527531e4dda4SBryan Schumaker 527699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 527731e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 527831e4dda4SBryan Schumaker { 527931e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 528031e4dda4SBryan Schumaker if (status) 528131e4dda4SBryan Schumaker return status; 528231e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 528331e4dda4SBryan Schumaker } 528431e4dda4SBryan Schumaker 528599fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 528699fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 528799fe60d0SBenny Halevy { 528899fe60d0SBenny Halevy __be32 *p; 528999fe60d0SBenny Halevy uint32_t dummy; 52902460ba57SBenny Halevy char *dummy_str; 529199fe60d0SBenny Halevy int status; 529299fe60d0SBenny Halevy struct nfs_client *clp = res->client; 52937d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 529499fe60d0SBenny Halevy 529599fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 529699fe60d0SBenny Halevy if (status) 529799fe60d0SBenny Halevy return status; 529899fe60d0SBenny Halevy 5299c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5300c0eae66eSBenny Halevy if (unlikely(!p)) 5301c0eae66eSBenny Halevy goto out_overflow; 5302114f64b5SAndy Adamson xdr_decode_hyper(p, &clp->cl_clientid); 5303c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5304c0eae66eSBenny Halevy if (unlikely(!p)) 5305c0eae66eSBenny Halevy goto out_overflow; 53066f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 53076f723f77SBenny Halevy clp->cl_exchange_flags = be32_to_cpup(p++); 530899fe60d0SBenny Halevy 530999fe60d0SBenny Halevy /* We ask for SP4_NONE */ 5310cccddf4fSBenny Halevy dummy = be32_to_cpup(p); 531199fe60d0SBenny Halevy if (dummy != SP4_NONE) 531299fe60d0SBenny Halevy return -EIO; 531399fe60d0SBenny Halevy 5314acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5315c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5316c0eae66eSBenny Halevy if (unlikely(!p)) 5317c0eae66eSBenny Halevy goto out_overflow; 5318acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 531999fe60d0SBenny Halevy 5320acdeb69dSChuck Lever /* server_owner4.so_major_id */ 53212460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 53222460ba57SBenny Halevy if (unlikely(status)) 53232460ba57SBenny Halevy return status; 532478fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 532578fe0f41SWeston Andros Adamson return -EIO; 5326acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5327acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 532878fe0f41SWeston Andros Adamson 5329acdeb69dSChuck Lever /* server_scope4 */ 5330acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5331acdeb69dSChuck Lever if (unlikely(status)) 5332acdeb69dSChuck Lever return status; 5333acdeb69dSChuck Lever if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 5334acdeb69dSChuck Lever return -EIO; 533578fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 533678fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 533778fe0f41SWeston Andros Adamson 53387d2ed9acSWeston Andros Adamson /* Implementation Id */ 53397d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 53407d2ed9acSWeston Andros Adamson if (unlikely(!p)) 53417d2ed9acSWeston Andros Adamson goto out_overflow; 53427d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 53437d2ed9acSWeston Andros Adamson 53447d2ed9acSWeston Andros Adamson if (impl_id_count) { 53457d2ed9acSWeston Andros Adamson /* nii_domain */ 53462460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 53472460ba57SBenny Halevy if (unlikely(status)) 53482460ba57SBenny Halevy return status; 53497d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 53507d2ed9acSWeston Andros Adamson return -EIO; 53517d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 535299fe60d0SBenny Halevy 53537d2ed9acSWeston Andros Adamson /* nii_name */ 53547d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 53557d2ed9acSWeston Andros Adamson if (unlikely(status)) 53567d2ed9acSWeston Andros Adamson return status; 53577d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 53587d2ed9acSWeston Andros Adamson return -EIO; 53597d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 53607d2ed9acSWeston Andros Adamson 53617d2ed9acSWeston Andros Adamson /* nii_date */ 53627d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 53637d2ed9acSWeston Andros Adamson if (unlikely(!p)) 53647d2ed9acSWeston Andros Adamson goto out_overflow; 53657d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 53667d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 53677d2ed9acSWeston Andros Adamson 53687d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 53697d2ed9acSWeston Andros Adamson } 537099fe60d0SBenny Halevy return 0; 5371c0eae66eSBenny Halevy out_overflow: 5372c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5373c0eae66eSBenny Halevy return -EIO; 537499fe60d0SBenny Halevy } 5375fc931582SAndy Adamson 5376fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5377fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5378fc931582SAndy Adamson { 5379fc931582SAndy Adamson __be32 *p; 5380c9c30dd5SBenny Halevy u32 nr_attrs, val; 5381fc931582SAndy Adamson 5382c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5383c0eae66eSBenny Halevy if (unlikely(!p)) 5384c0eae66eSBenny Halevy goto out_overflow; 5385c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5386c9c30dd5SBenny Halevy if (val) 5387c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 53886f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 53896f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 53906f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 53916f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 53926f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5393cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5394fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5395a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5396a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5397fc931582SAndy Adamson return -EINVAL; 5398fc931582SAndy Adamson } 5399c0eae66eSBenny Halevy if (nr_attrs == 1) { 5400c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5401c0eae66eSBenny Halevy if (unlikely(!p)) 5402c0eae66eSBenny Halevy goto out_overflow; 5403c0eae66eSBenny Halevy } 5404fc931582SAndy Adamson return 0; 5405c0eae66eSBenny Halevy out_overflow: 5406c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5407c0eae66eSBenny Halevy return -EIO; 5408fc931582SAndy Adamson } 5409fc931582SAndy Adamson 5410e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5411e78291e4SBenny Halevy { 5412e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5413fc931582SAndy Adamson } 5414fc931582SAndy Adamson 54157c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 54167c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 54177c44f1aeSWeston Andros Adamson { 54187c44f1aeSWeston Andros Adamson __be32 *p; 54197c44f1aeSWeston Andros Adamson int status; 54207c44f1aeSWeston Andros Adamson 54217c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 54227c44f1aeSWeston Andros Adamson if (!status) 54237c44f1aeSWeston Andros Adamson status = decode_sessionid(xdr, &res->session->sess_id); 54247c44f1aeSWeston Andros Adamson if (unlikely(status)) 54257c44f1aeSWeston Andros Adamson return status; 54267c44f1aeSWeston Andros Adamson 54277c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 54287c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 54297c44f1aeSWeston Andros Adamson if (unlikely(!p)) 54307c44f1aeSWeston Andros Adamson goto out_overflow; 54317c44f1aeSWeston Andros Adamson 54327c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 54337c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 54347c44f1aeSWeston Andros Adamson return -EIO; 54357c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 54367c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 54377c44f1aeSWeston Andros Adamson else 54387c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 54397c44f1aeSWeston Andros Adamson 54407c44f1aeSWeston Andros Adamson return 0; 54417c44f1aeSWeston Andros Adamson out_overflow: 54427c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 54437c44f1aeSWeston Andros Adamson return -EIO; 54447c44f1aeSWeston Andros Adamson } 54457c44f1aeSWeston Andros Adamson 5446fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5447fc931582SAndy Adamson struct nfs41_create_session_res *res) 5448fc931582SAndy Adamson { 5449fc931582SAndy Adamson __be32 *p; 5450fc931582SAndy Adamson int status; 5451fc931582SAndy Adamson struct nfs_client *clp = res->client; 5452fc931582SAndy Adamson struct nfs4_session *session = clp->cl_session; 5453fc931582SAndy Adamson 5454fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5455e78291e4SBenny Halevy if (!status) 5456e78291e4SBenny Halevy status = decode_sessionid(xdr, &session->sess_id); 5457e78291e4SBenny Halevy if (unlikely(status)) 5458fc931582SAndy Adamson return status; 5459fc931582SAndy Adamson 5460fc931582SAndy Adamson /* seqid, flags */ 5461c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5462c0eae66eSBenny Halevy if (unlikely(!p)) 5463c0eae66eSBenny Halevy goto out_overflow; 54646f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 5465cccddf4fSBenny Halevy session->flags = be32_to_cpup(p); 5466fc931582SAndy Adamson 5467fc931582SAndy Adamson /* Channel attributes */ 5468fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->fc_attrs); 5469fc931582SAndy Adamson if (!status) 5470fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->bc_attrs); 5471fc931582SAndy Adamson return status; 5472c0eae66eSBenny Halevy out_overflow: 5473c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5474c0eae66eSBenny Halevy return -EIO; 5475fc931582SAndy Adamson } 54760f3e66c6SAndy Adamson 54770f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 54780f3e66c6SAndy Adamson { 54790f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 54800f3e66c6SAndy Adamson } 548118019753SRicardo Labiaga 548218019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 548318019753SRicardo Labiaga { 548418019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 548518019753SRicardo Labiaga } 548699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 548799fe60d0SBenny Halevy 54889b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 54899b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 54909b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 54919b7b9fccSAndy Adamson { 54929b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5493fc01cea9SAndy Adamson struct nfs4_sessionid id; 5494fc01cea9SAndy Adamson u32 dummy; 5495fc01cea9SAndy Adamson int status; 5496fc01cea9SAndy Adamson __be32 *p; 5497fc01cea9SAndy Adamson 54989b7b9fccSAndy Adamson if (!res->sr_session) 54999b7b9fccSAndy Adamson return 0; 55009b7b9fccSAndy Adamson 5501fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5502e78291e4SBenny Halevy if (!status) 5503e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5504e78291e4SBenny Halevy if (unlikely(status)) 5505fc01cea9SAndy Adamson goto out_err; 55069b7b9fccSAndy Adamson 5507fc01cea9SAndy Adamson /* 5508fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5509fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5510fc01cea9SAndy Adamson */ 5511fdcb4577STrond Myklebust status = -EREMOTEIO; 5512fc01cea9SAndy Adamson 5513fc01cea9SAndy Adamson if (memcmp(id.data, res->sr_session->sess_id.data, 5514fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5515fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5516fc01cea9SAndy Adamson goto out_err; 5517fc01cea9SAndy Adamson } 5518e78291e4SBenny Halevy 5519c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5520c0eae66eSBenny Halevy if (unlikely(!p)) 5521c0eae66eSBenny Halevy goto out_overflow; 5522e78291e4SBenny Halevy 5523fc01cea9SAndy Adamson /* seqid */ 55246f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5525dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5526fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5527fc01cea9SAndy Adamson goto out_err; 5528fc01cea9SAndy Adamson } 5529fc01cea9SAndy Adamson /* slot id */ 55306f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5531dfb4f309SBenny Halevy if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) { 5532fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5533fc01cea9SAndy Adamson goto out_err; 5534fc01cea9SAndy Adamson } 5535fc01cea9SAndy Adamson /* highest slot id - currently not processed */ 55366f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5537fc01cea9SAndy Adamson /* target highest slot id - currently not processed */ 55386f723f77SBenny Halevy dummy = be32_to_cpup(p++); 55390629e370SAlexandros Batsakis /* result flags */ 55400629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5541fc01cea9SAndy Adamson status = 0; 5542fc01cea9SAndy Adamson out_err: 5543fc01cea9SAndy Adamson res->sr_status = status; 5544fc01cea9SAndy Adamson return status; 5545c0eae66eSBenny Halevy out_overflow: 5546c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5547c0eae66eSBenny Halevy status = -EIO; 5548c0eae66eSBenny Halevy goto out_err; 5549fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 55509b7b9fccSAndy Adamson return 0; 5551fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 55529b7b9fccSAndy Adamson } 55539b7b9fccSAndy Adamson 5554b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 55557f11d8d3SAndy Adamson /* 55567f11d8d3SAndy Adamson * TODO: Need to handle case when EOF != true; 55577f11d8d3SAndy Adamson */ 55587f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr, 55597f11d8d3SAndy Adamson struct pnfs_devicelist *res) 55607f11d8d3SAndy Adamson { 55617f11d8d3SAndy Adamson __be32 *p; 55627f11d8d3SAndy Adamson int status, i; 55637f11d8d3SAndy Adamson struct nfs_writeverf verftemp; 55647f11d8d3SAndy Adamson 55657f11d8d3SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICELIST); 55667f11d8d3SAndy Adamson if (status) 55677f11d8d3SAndy Adamson return status; 55687f11d8d3SAndy Adamson 55697f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 8 + 8 + 4); 55707f11d8d3SAndy Adamson if (unlikely(!p)) 55717f11d8d3SAndy Adamson goto out_overflow; 55727f11d8d3SAndy Adamson 55737f11d8d3SAndy Adamson /* TODO: Skip cookie for now */ 55747f11d8d3SAndy Adamson p += 2; 55757f11d8d3SAndy Adamson 55767f11d8d3SAndy Adamson /* Read verifier */ 5577cd93710eSChuck Lever p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE); 55787f11d8d3SAndy Adamson 55797f11d8d3SAndy Adamson res->num_devs = be32_to_cpup(p); 55807f11d8d3SAndy Adamson 55817f11d8d3SAndy Adamson dprintk("%s: num_dev %d\n", __func__, res->num_devs); 55827f11d8d3SAndy Adamson 55837f11d8d3SAndy Adamson if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5584a030889aSWeston Andros Adamson printk(KERN_ERR "NFS: %s too many result dev_num %u\n", 55857f11d8d3SAndy Adamson __func__, res->num_devs); 55867f11d8d3SAndy Adamson return -EIO; 55877f11d8d3SAndy Adamson } 55887f11d8d3SAndy Adamson 55897f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 55907f11d8d3SAndy Adamson res->num_devs * NFS4_DEVICEID4_SIZE + 4); 55917f11d8d3SAndy Adamson if (unlikely(!p)) 55927f11d8d3SAndy Adamson goto out_overflow; 55937f11d8d3SAndy Adamson for (i = 0; i < res->num_devs; i++) 55947f11d8d3SAndy Adamson p = xdr_decode_opaque_fixed(p, res->dev_id[i].data, 55957f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE); 55967f11d8d3SAndy Adamson res->eof = be32_to_cpup(p); 55977f11d8d3SAndy Adamson return 0; 55987f11d8d3SAndy Adamson out_overflow: 55997f11d8d3SAndy Adamson print_overflow_msg(__func__, xdr); 56007f11d8d3SAndy Adamson return -EIO; 56017f11d8d3SAndy Adamson } 5602b1f69b75SAndy Adamson 5603b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 5604b1f69b75SAndy Adamson struct pnfs_device *pdev) 5605b1f69b75SAndy Adamson { 5606b1f69b75SAndy Adamson __be32 *p; 5607b1f69b75SAndy Adamson uint32_t len, type; 5608b1f69b75SAndy Adamson int status; 5609b1f69b75SAndy Adamson 5610b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5611b1f69b75SAndy Adamson if (status) { 5612b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5613b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5614b1f69b75SAndy Adamson if (unlikely(!p)) 5615b1f69b75SAndy Adamson goto out_overflow; 5616b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5617b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5618b1f69b75SAndy Adamson __func__, pdev->mincount); 5619b1f69b75SAndy Adamson } 5620b1f69b75SAndy Adamson return status; 5621b1f69b75SAndy Adamson } 5622b1f69b75SAndy Adamson 5623b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5624b1f69b75SAndy Adamson if (unlikely(!p)) 5625b1f69b75SAndy Adamson goto out_overflow; 5626b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5627b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5628b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5629b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5630b1f69b75SAndy Adamson return -EINVAL; 5631b1f69b75SAndy Adamson } 5632b1f69b75SAndy Adamson /* 5633b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5634b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5635b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5636b1f69b75SAndy Adamson */ 5637b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5638b1f69b75SAndy Adamson xdr_read_pages(xdr, pdev->mincount); /* include space for the length */ 5639b1f69b75SAndy Adamson 5640b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5641b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5642b1f69b75SAndy Adamson if (unlikely(!p)) 5643b1f69b75SAndy Adamson goto out_overflow; 5644b1f69b75SAndy Adamson len = be32_to_cpup(p); 5645b1f69b75SAndy Adamson if (len) { 5646ead00597SChuck Lever uint32_t i; 5647b1f69b75SAndy Adamson 5648b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5649b1f69b75SAndy Adamson if (unlikely(!p)) 5650b1f69b75SAndy Adamson goto out_overflow; 5651b1f69b75SAndy Adamson for (i = 0; i < len; i++, p++) { 5652b1f69b75SAndy Adamson if (be32_to_cpup(p)) { 5653b1f69b75SAndy Adamson dprintk("%s: notifications not supported\n", 5654b1f69b75SAndy Adamson __func__); 5655b1f69b75SAndy Adamson return -EIO; 5656b1f69b75SAndy Adamson } 5657b1f69b75SAndy Adamson } 5658b1f69b75SAndy Adamson } 5659b1f69b75SAndy Adamson return 0; 5660b1f69b75SAndy Adamson out_overflow: 5661b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5662b1f69b75SAndy Adamson return -EIO; 5663b1f69b75SAndy Adamson } 5664b1f69b75SAndy Adamson 5665b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5666b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5667b1f69b75SAndy Adamson { 5668b1f69b75SAndy Adamson __be32 *p; 5669b1f69b75SAndy Adamson int status; 5670b1f69b75SAndy Adamson u32 layout_count; 567135124a09SWeston Andros Adamson struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 567235124a09SWeston Andros Adamson struct kvec *iov = rcvbuf->head; 567335124a09SWeston Andros Adamson u32 hdrlen, recvd; 5674b1f69b75SAndy Adamson 5675b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5676b1f69b75SAndy Adamson if (status) 5677b1f69b75SAndy Adamson return status; 5678ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5679b1f69b75SAndy Adamson if (unlikely(!p)) 5680b1f69b75SAndy Adamson goto out_overflow; 5681ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 5682ea9d23f5STrond Myklebust decode_stateid(xdr, &res->stateid); 5683ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5684ea9d23f5STrond Myklebust if (unlikely(!p)) 5685ea9d23f5STrond Myklebust goto out_overflow; 5686b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5687b1f69b75SAndy Adamson if (!layout_count) { 5688b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5689b1f69b75SAndy Adamson __func__); 5690b1f69b75SAndy Adamson return -EINVAL; 5691b1f69b75SAndy Adamson } 5692b1f69b75SAndy Adamson 569335124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5694b1f69b75SAndy Adamson if (unlikely(!p)) 5695b1f69b75SAndy Adamson goto out_overflow; 5696b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5697b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5698b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5699b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 570035124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5701b1f69b75SAndy Adamson 5702b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5703b1f69b75SAndy Adamson __func__, 5704b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5705b1f69b75SAndy Adamson (unsigned long)res->range.length, 5706b1f69b75SAndy Adamson res->range.iomode, 5707b1f69b75SAndy Adamson res->type, 570835124a09SWeston Andros Adamson res->layoutp->len); 5709b1f69b75SAndy Adamson 571035124a09SWeston Andros Adamson hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 571135124a09SWeston Andros Adamson recvd = req->rq_rcv_buf.len - hdrlen; 571235124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 571335124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 571435124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 571535124a09SWeston Andros Adamson res->layoutp->len, recvd); 571635124a09SWeston Andros Adamson return -EINVAL; 571735124a09SWeston Andros Adamson } 571835124a09SWeston Andros Adamson 571935124a09SWeston Andros Adamson xdr_read_pages(xdr, res->layoutp->len); 5720b1f69b75SAndy Adamson 5721b1f69b75SAndy Adamson if (layout_count > 1) { 5722b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5723b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5724b1f69b75SAndy Adamson * the client may see a response that is less than the 5725b1f69b75SAndy Adamson * minimum it requested. 5726b1f69b75SAndy Adamson */ 5727b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5728b1f69b75SAndy Adamson __func__, layout_count); 5729b1f69b75SAndy Adamson } 5730b1f69b75SAndy Adamson 5731b1f69b75SAndy Adamson return 0; 5732b1f69b75SAndy Adamson out_overflow: 5733b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5734b1f69b75SAndy Adamson return -EIO; 5735b1f69b75SAndy Adamson } 5736863a3c6cSAndy Adamson 5737cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5738cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5739cbe82603SBenny Halevy { 5740cbe82603SBenny Halevy __be32 *p; 5741cbe82603SBenny Halevy int status; 5742cbe82603SBenny Halevy 5743cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5744cbe82603SBenny Halevy if (status) 5745cbe82603SBenny Halevy return status; 5746cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5747cbe82603SBenny Halevy if (unlikely(!p)) 5748cbe82603SBenny Halevy goto out_overflow; 5749cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5750cbe82603SBenny Halevy if (res->lrs_present) 5751cbe82603SBenny Halevy status = decode_stateid(xdr, &res->stateid); 5752cbe82603SBenny Halevy return status; 5753cbe82603SBenny Halevy out_overflow: 5754cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 5755cbe82603SBenny Halevy return -EIO; 5756cbe82603SBenny Halevy } 5757cbe82603SBenny Halevy 5758863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5759863a3c6cSAndy Adamson struct rpc_rqst *req, 5760863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5761863a3c6cSAndy Adamson { 5762863a3c6cSAndy Adamson __be32 *p; 5763863a3c6cSAndy Adamson __u32 sizechanged; 5764863a3c6cSAndy Adamson int status; 5765863a3c6cSAndy Adamson 5766863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5767db29c089SAndy Adamson res->status = status; 5768863a3c6cSAndy Adamson if (status) 5769863a3c6cSAndy Adamson return status; 5770863a3c6cSAndy Adamson 5771863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5772863a3c6cSAndy Adamson if (unlikely(!p)) 5773863a3c6cSAndy Adamson goto out_overflow; 5774863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5775863a3c6cSAndy Adamson 5776863a3c6cSAndy Adamson if (sizechanged) { 5777863a3c6cSAndy Adamson /* throw away new size */ 5778863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5779863a3c6cSAndy Adamson if (unlikely(!p)) 5780863a3c6cSAndy Adamson goto out_overflow; 5781863a3c6cSAndy Adamson } 5782863a3c6cSAndy Adamson return 0; 5783863a3c6cSAndy Adamson out_overflow: 5784863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 5785863a3c6cSAndy Adamson return -EIO; 5786863a3c6cSAndy Adamson } 57877d974794SBryan Schumaker 57887d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 57897d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 57907d974794SBryan Schumaker { 57917d974794SBryan Schumaker __be32 *p; 57927d974794SBryan Schumaker int status; 57937d974794SBryan Schumaker int num_res; 57947d974794SBryan Schumaker 57957d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 57967d974794SBryan Schumaker if (status) 57977d974794SBryan Schumaker return status; 57987d974794SBryan Schumaker 57997d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 58007d974794SBryan Schumaker if (unlikely(!p)) 58017d974794SBryan Schumaker goto out_overflow; 58027d974794SBryan Schumaker num_res = be32_to_cpup(p++); 58037d974794SBryan Schumaker if (num_res != 1) 58047d974794SBryan Schumaker goto out; 58057d974794SBryan Schumaker 58067d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 58077d974794SBryan Schumaker if (unlikely(!p)) 58087d974794SBryan Schumaker goto out_overflow; 58097d974794SBryan Schumaker res->status = be32_to_cpup(p++); 58101cab0652SBryan Schumaker 58111cab0652SBryan Schumaker return status; 58127d974794SBryan Schumaker out_overflow: 58137d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 58147d974794SBryan Schumaker out: 58157d974794SBryan Schumaker return -EIO; 58167d974794SBryan Schumaker } 58179aeda35fSBryan Schumaker 58189aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 58199aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 58209aeda35fSBryan Schumaker { 58219aeda35fSBryan Schumaker __be32 *p; 58229aeda35fSBryan Schumaker int status; 58239aeda35fSBryan Schumaker 58249aeda35fSBryan Schumaker status = decode_op_hdr(xdr, OP_FREE_STATEID); 58259aeda35fSBryan Schumaker if (status) 58269aeda35fSBryan Schumaker return status; 58279aeda35fSBryan Schumaker 58289aeda35fSBryan Schumaker p = xdr_inline_decode(xdr, 4); 58299aeda35fSBryan Schumaker if (unlikely(!p)) 58309aeda35fSBryan Schumaker goto out_overflow; 58319aeda35fSBryan Schumaker res->status = be32_to_cpup(p++); 58329aeda35fSBryan Schumaker return res->status; 58339aeda35fSBryan Schumaker out_overflow: 58349aeda35fSBryan Schumaker print_overflow_msg(__func__, xdr); 58359aeda35fSBryan Schumaker return -EIO; 58369aeda35fSBryan Schumaker } 5837b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 5838b1f69b75SAndy Adamson 58391da177e4SLinus Torvalds /* 584049c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 584149c2559eSBenny Halevy */ 584249c2559eSBenny Halevy 584349c2559eSBenny Halevy /* 58441da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 58451da177e4SLinus Torvalds */ 5846bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 5847bf269551SChuck Lever struct xdr_stream *xdr, 5848bf269551SChuck Lever struct nfs_closeres *res) 58491da177e4SLinus Torvalds { 58501da177e4SLinus Torvalds struct compound_hdr hdr; 58511da177e4SLinus Torvalds int status; 58521da177e4SLinus Torvalds 5853bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58541da177e4SLinus Torvalds if (status) 58551da177e4SLinus Torvalds goto out; 5856bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58579b7b9fccSAndy Adamson if (status) 58589b7b9fccSAndy Adamson goto out; 5859bf269551SChuck Lever status = decode_putfh(xdr); 58601da177e4SLinus Torvalds if (status) 58611da177e4SLinus Torvalds goto out; 5862bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 5863516a6af6STrond Myklebust if (status != 0) 5864516a6af6STrond Myklebust goto out; 58656926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 58661da177e4SLinus Torvalds out: 58671da177e4SLinus Torvalds return status; 58681da177e4SLinus Torvalds } 58691da177e4SLinus Torvalds 58701da177e4SLinus Torvalds /* 58711da177e4SLinus Torvalds * Decode ACCESS response 58721da177e4SLinus Torvalds */ 5873bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5874bf269551SChuck Lever struct nfs4_accessres *res) 58751da177e4SLinus Torvalds { 58761da177e4SLinus Torvalds struct compound_hdr hdr; 58771da177e4SLinus Torvalds int status; 58781da177e4SLinus Torvalds 5879bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58809b7b9fccSAndy Adamson if (status) 58819b7b9fccSAndy Adamson goto out; 5882bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58839b7b9fccSAndy Adamson if (status) 58841da177e4SLinus Torvalds goto out; 5885bf269551SChuck Lever status = decode_putfh(xdr); 588676b32999STrond Myklebust if (status != 0) 588776b32999STrond Myklebust goto out; 5888bf269551SChuck Lever status = decode_access(xdr, res); 588976b32999STrond Myklebust if (status != 0) 589076b32999STrond Myklebust goto out; 58916926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 58921da177e4SLinus Torvalds out: 58931da177e4SLinus Torvalds return status; 58941da177e4SLinus Torvalds } 58951da177e4SLinus Torvalds 58961da177e4SLinus Torvalds /* 58971da177e4SLinus Torvalds * Decode LOOKUP response 58981da177e4SLinus Torvalds */ 5899bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5900bf269551SChuck Lever struct nfs4_lookup_res *res) 59011da177e4SLinus Torvalds { 59021da177e4SLinus Torvalds struct compound_hdr hdr; 59031da177e4SLinus Torvalds int status; 59041da177e4SLinus Torvalds 5905bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59069b7b9fccSAndy Adamson if (status) 59079b7b9fccSAndy Adamson goto out; 5908bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59099b7b9fccSAndy Adamson if (status) 59101da177e4SLinus Torvalds goto out; 5911bf269551SChuck Lever status = decode_putfh(xdr); 5912bf269551SChuck Lever if (status) 59131da177e4SLinus Torvalds goto out; 5914bf269551SChuck Lever status = decode_lookup(xdr); 5915bf269551SChuck Lever if (status) 59161da177e4SLinus Torvalds goto out; 5917bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5918bf269551SChuck Lever if (status) 59191da177e4SLinus Torvalds goto out; 59206926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 59211da177e4SLinus Torvalds out: 59221da177e4SLinus Torvalds return status; 59231da177e4SLinus Torvalds } 59241da177e4SLinus Torvalds 59251da177e4SLinus Torvalds /* 59261da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 59271da177e4SLinus Torvalds */ 5928bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 5929bf269551SChuck Lever struct xdr_stream *xdr, 5930bf269551SChuck Lever struct nfs4_lookup_res *res) 59311da177e4SLinus Torvalds { 59321da177e4SLinus Torvalds struct compound_hdr hdr; 59331da177e4SLinus Torvalds int status; 59341da177e4SLinus Torvalds 5935bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59369b7b9fccSAndy Adamson if (status) 59379b7b9fccSAndy Adamson goto out; 5938bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59399b7b9fccSAndy Adamson if (status) 59401da177e4SLinus Torvalds goto out; 5941bf269551SChuck Lever status = decode_putrootfh(xdr); 5942bf269551SChuck Lever if (status) 59431da177e4SLinus Torvalds goto out; 5944bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5945bf269551SChuck Lever if (status == 0) 59466926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 59471da177e4SLinus Torvalds out: 59481da177e4SLinus Torvalds return status; 59491da177e4SLinus Torvalds } 59501da177e4SLinus Torvalds 59511da177e4SLinus Torvalds /* 59521da177e4SLinus Torvalds * Decode REMOVE response 59531da177e4SLinus Torvalds */ 5954bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5955bf269551SChuck Lever struct nfs_removeres *res) 59561da177e4SLinus Torvalds { 59571da177e4SLinus Torvalds struct compound_hdr hdr; 59581da177e4SLinus Torvalds int status; 59591da177e4SLinus Torvalds 5960bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59619b7b9fccSAndy Adamson if (status) 59629b7b9fccSAndy Adamson goto out; 5963bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59649b7b9fccSAndy Adamson if (status) 59651da177e4SLinus Torvalds goto out; 5966bf269551SChuck Lever status = decode_putfh(xdr); 5967bf269551SChuck Lever if (status) 596816e42959STrond Myklebust goto out; 5969bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 59701da177e4SLinus Torvalds out: 59711da177e4SLinus Torvalds return status; 59721da177e4SLinus Torvalds } 59731da177e4SLinus Torvalds 59741da177e4SLinus Torvalds /* 59751da177e4SLinus Torvalds * Decode RENAME response 59761da177e4SLinus Torvalds */ 5977bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5978bf269551SChuck Lever struct nfs_renameres *res) 59791da177e4SLinus Torvalds { 59801da177e4SLinus Torvalds struct compound_hdr hdr; 59811da177e4SLinus Torvalds int status; 59821da177e4SLinus Torvalds 5983bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59849b7b9fccSAndy Adamson if (status) 59859b7b9fccSAndy Adamson goto out; 5986bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59879b7b9fccSAndy Adamson if (status) 59881da177e4SLinus Torvalds goto out; 5989bf269551SChuck Lever status = decode_putfh(xdr); 5990bf269551SChuck Lever if (status) 59911da177e4SLinus Torvalds goto out; 5992bf269551SChuck Lever status = decode_savefh(xdr); 5993bf269551SChuck Lever if (status) 59941da177e4SLinus Torvalds goto out; 5995bf269551SChuck Lever status = decode_putfh(xdr); 5996bf269551SChuck Lever if (status) 59971da177e4SLinus Torvalds goto out; 5998bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 59991da177e4SLinus Torvalds out: 60001da177e4SLinus Torvalds return status; 60011da177e4SLinus Torvalds } 60021da177e4SLinus Torvalds 60031da177e4SLinus Torvalds /* 60041da177e4SLinus Torvalds * Decode LINK response 60051da177e4SLinus Torvalds */ 6006bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6007bf269551SChuck Lever struct nfs4_link_res *res) 60081da177e4SLinus Torvalds { 60091da177e4SLinus Torvalds struct compound_hdr hdr; 60101da177e4SLinus Torvalds int status; 60111da177e4SLinus Torvalds 6012bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60139b7b9fccSAndy Adamson if (status) 60149b7b9fccSAndy Adamson goto out; 6015bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60169b7b9fccSAndy Adamson if (status) 60171da177e4SLinus Torvalds goto out; 6018bf269551SChuck Lever status = decode_putfh(xdr); 6019bf269551SChuck Lever if (status) 60201da177e4SLinus Torvalds goto out; 6021bf269551SChuck Lever status = decode_savefh(xdr); 6022bf269551SChuck Lever if (status) 60231da177e4SLinus Torvalds goto out; 6024bf269551SChuck Lever status = decode_putfh(xdr); 6025bf269551SChuck Lever if (status) 60261da177e4SLinus Torvalds goto out; 6027bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6028bf269551SChuck Lever if (status) 602991ba2eeeSTrond Myklebust goto out; 603091ba2eeeSTrond Myklebust /* 603191ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 603291ba2eeeSTrond Myklebust * filehandle. 603391ba2eeeSTrond Myklebust */ 6034bf269551SChuck Lever status = decode_restorefh(xdr); 6035bf269551SChuck Lever if (status) 603691ba2eeeSTrond Myklebust goto out; 60376926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60381da177e4SLinus Torvalds out: 60391da177e4SLinus Torvalds return status; 60401da177e4SLinus Torvalds } 60411da177e4SLinus Torvalds 60421da177e4SLinus Torvalds /* 60431da177e4SLinus Torvalds * Decode CREATE response 60441da177e4SLinus Torvalds */ 6045bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6046bf269551SChuck Lever struct nfs4_create_res *res) 60471da177e4SLinus Torvalds { 60481da177e4SLinus Torvalds struct compound_hdr hdr; 60491da177e4SLinus Torvalds int status; 60501da177e4SLinus Torvalds 6051bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60529b7b9fccSAndy Adamson if (status) 60539b7b9fccSAndy Adamson goto out; 6054bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60559b7b9fccSAndy Adamson if (status) 60561da177e4SLinus Torvalds goto out; 6057bf269551SChuck Lever status = decode_putfh(xdr); 6058bf269551SChuck Lever if (status) 60591da177e4SLinus Torvalds goto out; 6060bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6061bf269551SChuck Lever if (status) 60621da177e4SLinus Torvalds goto out; 6063bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6064bf269551SChuck Lever if (status) 60651da177e4SLinus Torvalds goto out; 60667c317fcfSTrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60671da177e4SLinus Torvalds out: 60681da177e4SLinus Torvalds return status; 60691da177e4SLinus Torvalds } 60701da177e4SLinus Torvalds 60711da177e4SLinus Torvalds /* 60721da177e4SLinus Torvalds * Decode SYMLINK response 60731da177e4SLinus Torvalds */ 6074bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6075bf269551SChuck Lever struct nfs4_create_res *res) 60761da177e4SLinus Torvalds { 6077bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 60781da177e4SLinus Torvalds } 60791da177e4SLinus Torvalds 60801da177e4SLinus Torvalds /* 60811da177e4SLinus Torvalds * Decode GETATTR response 60821da177e4SLinus Torvalds */ 6083bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6084bf269551SChuck Lever struct nfs4_getattr_res *res) 60851da177e4SLinus Torvalds { 60861da177e4SLinus Torvalds struct compound_hdr hdr; 60871da177e4SLinus Torvalds int status; 60881da177e4SLinus Torvalds 6089bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60901da177e4SLinus Torvalds if (status) 60911da177e4SLinus Torvalds goto out; 6092bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60939b7b9fccSAndy Adamson if (status) 60949b7b9fccSAndy Adamson goto out; 6095bf269551SChuck Lever status = decode_putfh(xdr); 60961da177e4SLinus Torvalds if (status) 60971da177e4SLinus Torvalds goto out; 60986926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 60991da177e4SLinus Torvalds out: 61001da177e4SLinus Torvalds return status; 61011da177e4SLinus Torvalds } 61021da177e4SLinus Torvalds 610323ec6965SJ. Bruce Fields /* 610423ec6965SJ. Bruce Fields * Encode an SETACL request 610523ec6965SJ. Bruce Fields */ 61069f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 61079f06c719SChuck Lever struct nfs_setaclargs *args) 610823ec6965SJ. Bruce Fields { 610923ec6965SJ. Bruce Fields struct compound_hdr hdr = { 611066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 611123ec6965SJ. Bruce Fields }; 611223ec6965SJ. Bruce Fields 61139f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 61149f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 61159f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 61169f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6117d017931cSAndy Adamson encode_nops(&hdr); 611823ec6965SJ. Bruce Fields } 611905d564feSAndy Adamson 612023ec6965SJ. Bruce Fields /* 612123ec6965SJ. Bruce Fields * Decode SETACL response 612223ec6965SJ. Bruce Fields */ 612323ec6965SJ. Bruce Fields static int 6124bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 612573c403a9SBenny Halevy struct nfs_setaclres *res) 612623ec6965SJ. Bruce Fields { 612723ec6965SJ. Bruce Fields struct compound_hdr hdr; 612823ec6965SJ. Bruce Fields int status; 612923ec6965SJ. Bruce Fields 6130bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 613123ec6965SJ. Bruce Fields if (status) 613223ec6965SJ. Bruce Fields goto out; 6133bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61349b7b9fccSAndy Adamson if (status) 61359b7b9fccSAndy Adamson goto out; 6136bf269551SChuck Lever status = decode_putfh(xdr); 613723ec6965SJ. Bruce Fields if (status) 613823ec6965SJ. Bruce Fields goto out; 6139bf269551SChuck Lever status = decode_setattr(xdr); 614023ec6965SJ. Bruce Fields out: 614123ec6965SJ. Bruce Fields return status; 614223ec6965SJ. Bruce Fields } 61431da177e4SLinus Torvalds 61441da177e4SLinus Torvalds /* 6145029d105eSJ. Bruce Fields * Decode GETACL response 6146029d105eSJ. Bruce Fields */ 6147029d105eSJ. Bruce Fields static int 6148bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6149663c79b3SBenny Halevy struct nfs_getaclres *res) 6150029d105eSJ. Bruce Fields { 6151029d105eSJ. Bruce Fields struct compound_hdr hdr; 6152029d105eSJ. Bruce Fields int status; 6153029d105eSJ. Bruce Fields 6154331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6155331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6156331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6157331818f1STrond Myklebust } 6158bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6159029d105eSJ. Bruce Fields if (status) 6160029d105eSJ. Bruce Fields goto out; 6161bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61629b7b9fccSAndy Adamson if (status) 61639b7b9fccSAndy Adamson goto out; 6164bf269551SChuck Lever status = decode_putfh(xdr); 6165029d105eSJ. Bruce Fields if (status) 6166029d105eSJ. Bruce Fields goto out; 6167bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6168029d105eSJ. Bruce Fields 6169029d105eSJ. Bruce Fields out: 6170029d105eSJ. Bruce Fields return status; 6171029d105eSJ. Bruce Fields } 6172029d105eSJ. Bruce Fields 6173029d105eSJ. Bruce Fields /* 61741da177e4SLinus Torvalds * Decode CLOSE response 61751da177e4SLinus Torvalds */ 6176bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6177bf269551SChuck Lever struct nfs_closeres *res) 61781da177e4SLinus Torvalds { 61791da177e4SLinus Torvalds struct compound_hdr hdr; 61801da177e4SLinus Torvalds int status; 61811da177e4SLinus Torvalds 6182bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61831da177e4SLinus Torvalds if (status) 61841da177e4SLinus Torvalds goto out; 6185bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61869b7b9fccSAndy Adamson if (status) 61879b7b9fccSAndy Adamson goto out; 6188bf269551SChuck Lever status = decode_putfh(xdr); 61891da177e4SLinus Torvalds if (status) 61901da177e4SLinus Torvalds goto out; 6191bf269551SChuck Lever status = decode_close(xdr, res); 6192516a6af6STrond Myklebust if (status != 0) 6193516a6af6STrond Myklebust goto out; 6194516a6af6STrond Myklebust /* 6195516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6196516a6af6STrond Myklebust * in which case the getattr call will fail with 6197516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6198516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6199516a6af6STrond Myklebust */ 62006926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62011da177e4SLinus Torvalds out: 62021da177e4SLinus Torvalds return status; 62031da177e4SLinus Torvalds } 62041da177e4SLinus Torvalds 62051da177e4SLinus Torvalds /* 62061da177e4SLinus Torvalds * Decode OPEN response 62071da177e4SLinus Torvalds */ 6208bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6209bf269551SChuck Lever struct nfs_openres *res) 62101da177e4SLinus Torvalds { 62111da177e4SLinus Torvalds struct compound_hdr hdr; 62121da177e4SLinus Torvalds int status; 62131da177e4SLinus Torvalds 6214bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62151da177e4SLinus Torvalds if (status) 62161da177e4SLinus Torvalds goto out; 6217bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62189b7b9fccSAndy Adamson if (status) 62199b7b9fccSAndy Adamson goto out; 6220bf269551SChuck Lever status = decode_putfh(xdr); 62211da177e4SLinus Torvalds if (status) 62221da177e4SLinus Torvalds goto out; 6223bf269551SChuck Lever status = decode_open(xdr, res); 62241da177e4SLinus Torvalds if (status) 62251da177e4SLinus Torvalds goto out; 6226bf269551SChuck Lever if (decode_getfh(xdr, &res->fh) != 0) 62271da177e4SLinus Torvalds goto out; 622890ff0c54STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 62291da177e4SLinus Torvalds out: 62301da177e4SLinus Torvalds return status; 62311da177e4SLinus Torvalds } 62321da177e4SLinus Torvalds 62331da177e4SLinus Torvalds /* 62341da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 62351da177e4SLinus Torvalds */ 6236bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6237bf269551SChuck Lever struct xdr_stream *xdr, 6238bf269551SChuck Lever struct nfs_open_confirmres *res) 62391da177e4SLinus Torvalds { 62401da177e4SLinus Torvalds struct compound_hdr hdr; 62411da177e4SLinus Torvalds int status; 62421da177e4SLinus Torvalds 6243bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62441da177e4SLinus Torvalds if (status) 62451da177e4SLinus Torvalds goto out; 6246bf269551SChuck Lever status = decode_putfh(xdr); 62471da177e4SLinus Torvalds if (status) 62481da177e4SLinus Torvalds goto out; 6249bf269551SChuck Lever status = decode_open_confirm(xdr, res); 62501da177e4SLinus Torvalds out: 62511da177e4SLinus Torvalds return status; 62521da177e4SLinus Torvalds } 62531da177e4SLinus Torvalds 62541da177e4SLinus Torvalds /* 62551da177e4SLinus Torvalds * Decode OPEN response 62561da177e4SLinus Torvalds */ 6257bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6258bf269551SChuck Lever struct xdr_stream *xdr, 6259bf269551SChuck Lever struct nfs_openres *res) 62601da177e4SLinus Torvalds { 62611da177e4SLinus Torvalds struct compound_hdr hdr; 62621da177e4SLinus Torvalds int status; 62631da177e4SLinus Torvalds 6264bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62651da177e4SLinus Torvalds if (status) 62661da177e4SLinus Torvalds goto out; 6267bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62689b7b9fccSAndy Adamson if (status) 62699b7b9fccSAndy Adamson goto out; 6270bf269551SChuck Lever status = decode_putfh(xdr); 62711da177e4SLinus Torvalds if (status) 62721da177e4SLinus Torvalds goto out; 6273bf269551SChuck Lever status = decode_open(xdr, res); 6274864472e9STrond Myklebust if (status) 6275864472e9STrond Myklebust goto out; 62766926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 62771da177e4SLinus Torvalds out: 62781da177e4SLinus Torvalds return status; 62791da177e4SLinus Torvalds } 62801da177e4SLinus Torvalds 62811da177e4SLinus Torvalds /* 62821da177e4SLinus Torvalds * Decode SETATTR response 62831da177e4SLinus Torvalds */ 6284bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6285bf269551SChuck Lever struct xdr_stream *xdr, 6286bf269551SChuck Lever struct nfs_setattrres *res) 62871da177e4SLinus Torvalds { 62881da177e4SLinus Torvalds struct compound_hdr hdr; 62891da177e4SLinus Torvalds int status; 62901da177e4SLinus Torvalds 6291bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62921da177e4SLinus Torvalds if (status) 62931da177e4SLinus Torvalds goto out; 6294bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62959b7b9fccSAndy Adamson if (status) 62969b7b9fccSAndy Adamson goto out; 6297bf269551SChuck Lever status = decode_putfh(xdr); 62981da177e4SLinus Torvalds if (status) 62991da177e4SLinus Torvalds goto out; 6300bf269551SChuck Lever status = decode_setattr(xdr); 63011da177e4SLinus Torvalds if (status) 63021da177e4SLinus Torvalds goto out; 63036926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63041da177e4SLinus Torvalds out: 63051da177e4SLinus Torvalds return status; 63061da177e4SLinus Torvalds } 63071da177e4SLinus Torvalds 63081da177e4SLinus Torvalds /* 63091da177e4SLinus Torvalds * Decode LOCK response 63101da177e4SLinus Torvalds */ 6311bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6312bf269551SChuck Lever struct nfs_lock_res *res) 63131da177e4SLinus Torvalds { 63141da177e4SLinus Torvalds struct compound_hdr hdr; 63151da177e4SLinus Torvalds int status; 63161da177e4SLinus Torvalds 6317bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63181da177e4SLinus Torvalds if (status) 63191da177e4SLinus Torvalds goto out; 6320bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63219b7b9fccSAndy Adamson if (status) 63229b7b9fccSAndy Adamson goto out; 6323bf269551SChuck Lever status = decode_putfh(xdr); 63241da177e4SLinus Torvalds if (status) 63251da177e4SLinus Torvalds goto out; 6326bf269551SChuck Lever status = decode_lock(xdr, res); 63271da177e4SLinus Torvalds out: 63281da177e4SLinus Torvalds return status; 63291da177e4SLinus Torvalds } 63301da177e4SLinus Torvalds 63311da177e4SLinus Torvalds /* 63321da177e4SLinus Torvalds * Decode LOCKT response 63331da177e4SLinus Torvalds */ 6334bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6335bf269551SChuck Lever struct nfs_lockt_res *res) 63361da177e4SLinus Torvalds { 63371da177e4SLinus Torvalds struct compound_hdr hdr; 63381da177e4SLinus Torvalds int status; 63391da177e4SLinus Torvalds 6340bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63411da177e4SLinus Torvalds if (status) 63421da177e4SLinus Torvalds goto out; 6343bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63449b7b9fccSAndy Adamson if (status) 63459b7b9fccSAndy Adamson goto out; 6346bf269551SChuck Lever status = decode_putfh(xdr); 63471da177e4SLinus Torvalds if (status) 63481da177e4SLinus Torvalds goto out; 6349bf269551SChuck Lever status = decode_lockt(xdr, res); 63501da177e4SLinus Torvalds out: 63511da177e4SLinus Torvalds return status; 63521da177e4SLinus Torvalds } 63531da177e4SLinus Torvalds 63541da177e4SLinus Torvalds /* 63551da177e4SLinus Torvalds * Decode LOCKU response 63561da177e4SLinus Torvalds */ 6357bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6358bf269551SChuck Lever struct nfs_locku_res *res) 63591da177e4SLinus Torvalds { 63601da177e4SLinus Torvalds struct compound_hdr hdr; 63611da177e4SLinus Torvalds int status; 63621da177e4SLinus Torvalds 6363bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63641da177e4SLinus Torvalds if (status) 63651da177e4SLinus Torvalds goto out; 6366bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63679b7b9fccSAndy Adamson if (status) 63689b7b9fccSAndy Adamson goto out; 6369bf269551SChuck Lever status = decode_putfh(xdr); 63701da177e4SLinus Torvalds if (status) 63711da177e4SLinus Torvalds goto out; 6372bf269551SChuck Lever status = decode_locku(xdr, res); 63731da177e4SLinus Torvalds out: 63741da177e4SLinus Torvalds return status; 63751da177e4SLinus Torvalds } 63761da177e4SLinus Torvalds 6377bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6378bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6379d3c7b7ccSTrond Myklebust { 6380d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6381d3c7b7ccSTrond Myklebust int status; 6382d3c7b7ccSTrond Myklebust 6383bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6384d3c7b7ccSTrond Myklebust if (!status) 6385bf269551SChuck Lever status = decode_release_lockowner(xdr); 6386d3c7b7ccSTrond Myklebust return status; 6387d3c7b7ccSTrond Myklebust } 6388d3c7b7ccSTrond Myklebust 63891da177e4SLinus Torvalds /* 63901da177e4SLinus Torvalds * Decode READLINK response 63911da177e4SLinus Torvalds */ 6392bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6393bf269551SChuck Lever struct xdr_stream *xdr, 6394f50c7000SBenny Halevy struct nfs4_readlink_res *res) 63951da177e4SLinus Torvalds { 63961da177e4SLinus Torvalds struct compound_hdr hdr; 63971da177e4SLinus Torvalds int status; 63981da177e4SLinus Torvalds 6399bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64001da177e4SLinus Torvalds if (status) 64011da177e4SLinus Torvalds goto out; 6402bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64039b7b9fccSAndy Adamson if (status) 64049b7b9fccSAndy Adamson goto out; 6405bf269551SChuck Lever status = decode_putfh(xdr); 64061da177e4SLinus Torvalds if (status) 64071da177e4SLinus Torvalds goto out; 6408bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 64091da177e4SLinus Torvalds out: 64101da177e4SLinus Torvalds return status; 64111da177e4SLinus Torvalds } 64121da177e4SLinus Torvalds 64131da177e4SLinus Torvalds /* 64141da177e4SLinus Torvalds * Decode READDIR response 64151da177e4SLinus Torvalds */ 6416bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6417bf269551SChuck Lever struct nfs4_readdir_res *res) 64181da177e4SLinus Torvalds { 64191da177e4SLinus Torvalds struct compound_hdr hdr; 64201da177e4SLinus Torvalds int status; 64211da177e4SLinus Torvalds 6422bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64231da177e4SLinus Torvalds if (status) 64241da177e4SLinus Torvalds goto out; 6425bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64269b7b9fccSAndy Adamson if (status) 64279b7b9fccSAndy Adamson goto out; 6428bf269551SChuck Lever status = decode_putfh(xdr); 64291da177e4SLinus Torvalds if (status) 64301da177e4SLinus Torvalds goto out; 6431bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 64321da177e4SLinus Torvalds out: 64331da177e4SLinus Torvalds return status; 64341da177e4SLinus Torvalds } 64351da177e4SLinus Torvalds 64361da177e4SLinus Torvalds /* 64371da177e4SLinus Torvalds * Decode Read response 64381da177e4SLinus Torvalds */ 6439bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6440bf269551SChuck Lever struct nfs_readres *res) 64411da177e4SLinus Torvalds { 64421da177e4SLinus Torvalds struct compound_hdr hdr; 64431da177e4SLinus Torvalds int status; 64441da177e4SLinus Torvalds 6445bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64461da177e4SLinus Torvalds if (status) 64471da177e4SLinus Torvalds goto out; 6448bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64499b7b9fccSAndy Adamson if (status) 64509b7b9fccSAndy Adamson goto out; 6451bf269551SChuck Lever status = decode_putfh(xdr); 64521da177e4SLinus Torvalds if (status) 64531da177e4SLinus Torvalds goto out; 6454bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 64551da177e4SLinus Torvalds if (!status) 64561da177e4SLinus Torvalds status = res->count; 64571da177e4SLinus Torvalds out: 64581da177e4SLinus Torvalds return status; 64591da177e4SLinus Torvalds } 64601da177e4SLinus Torvalds 64611da177e4SLinus Torvalds /* 64621da177e4SLinus Torvalds * Decode WRITE response 64631da177e4SLinus Torvalds */ 6464bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6465bf269551SChuck Lever struct nfs_writeres *res) 64661da177e4SLinus Torvalds { 64671da177e4SLinus Torvalds struct compound_hdr hdr; 64681da177e4SLinus Torvalds int status; 64691da177e4SLinus Torvalds 6470bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64711da177e4SLinus Torvalds if (status) 64721da177e4SLinus Torvalds goto out; 6473bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64749b7b9fccSAndy Adamson if (status) 64759b7b9fccSAndy Adamson goto out; 6476bf269551SChuck Lever status = decode_putfh(xdr); 64771da177e4SLinus Torvalds if (status) 64781da177e4SLinus Torvalds goto out; 6479bf269551SChuck Lever status = decode_write(xdr, res); 64804f9838c7STrond Myklebust if (status) 64814f9838c7STrond Myklebust goto out; 64827ffd1064SFred Isaman if (res->fattr) 64836926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 64841da177e4SLinus Torvalds if (!status) 64851da177e4SLinus Torvalds status = res->count; 64861da177e4SLinus Torvalds out: 64871da177e4SLinus Torvalds return status; 64881da177e4SLinus Torvalds } 64891da177e4SLinus Torvalds 64901da177e4SLinus Torvalds /* 64911da177e4SLinus Torvalds * Decode COMMIT response 64921da177e4SLinus Torvalds */ 6493bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 64940b7c0153SFred Isaman struct nfs_commitres *res) 64951da177e4SLinus Torvalds { 64961da177e4SLinus Torvalds struct compound_hdr hdr; 64971da177e4SLinus Torvalds int status; 64981da177e4SLinus Torvalds 6499bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65001da177e4SLinus Torvalds if (status) 65011da177e4SLinus Torvalds goto out; 6502bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65039b7b9fccSAndy Adamson if (status) 65049b7b9fccSAndy Adamson goto out; 6505bf269551SChuck Lever status = decode_putfh(xdr); 65061da177e4SLinus Torvalds if (status) 65071da177e4SLinus Torvalds goto out; 6508bf269551SChuck Lever status = decode_commit(xdr, res); 65091da177e4SLinus Torvalds out: 65101da177e4SLinus Torvalds return status; 65111da177e4SLinus Torvalds } 65121da177e4SLinus Torvalds 65131da177e4SLinus Torvalds /* 65148b173218SRicardo Labiaga * Decode FSINFO response 65151da177e4SLinus Torvalds */ 6516bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 65173dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 65181da177e4SLinus Torvalds { 65191da177e4SLinus Torvalds struct compound_hdr hdr; 65201da177e4SLinus Torvalds int status; 65211da177e4SLinus Torvalds 6522bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65231da177e4SLinus Torvalds if (!status) 6524bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65259b7b9fccSAndy Adamson if (!status) 6526bf269551SChuck Lever status = decode_putfh(xdr); 65271da177e4SLinus Torvalds if (!status) 6528bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 65291da177e4SLinus Torvalds return status; 65301da177e4SLinus Torvalds } 65311da177e4SLinus Torvalds 65321da177e4SLinus Torvalds /* 65338b173218SRicardo Labiaga * Decode PATHCONF response 65341da177e4SLinus Torvalds */ 6535bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6536d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 65371da177e4SLinus Torvalds { 65381da177e4SLinus Torvalds struct compound_hdr hdr; 65391da177e4SLinus Torvalds int status; 65401da177e4SLinus Torvalds 6541bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65421da177e4SLinus Torvalds if (!status) 6543bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65449b7b9fccSAndy Adamson if (!status) 6545bf269551SChuck Lever status = decode_putfh(xdr); 65461da177e4SLinus Torvalds if (!status) 6547bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 65481da177e4SLinus Torvalds return status; 65491da177e4SLinus Torvalds } 65501da177e4SLinus Torvalds 65511da177e4SLinus Torvalds /* 65528b173218SRicardo Labiaga * Decode STATFS response 65531da177e4SLinus Torvalds */ 6554bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 655524ad148aSBenny Halevy struct nfs4_statfs_res *res) 65561da177e4SLinus Torvalds { 65571da177e4SLinus Torvalds struct compound_hdr hdr; 65581da177e4SLinus Torvalds int status; 65591da177e4SLinus Torvalds 6560bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65611da177e4SLinus Torvalds if (!status) 6562bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65639b7b9fccSAndy Adamson if (!status) 6564bf269551SChuck Lever status = decode_putfh(xdr); 65651da177e4SLinus Torvalds if (!status) 6566bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 65671da177e4SLinus Torvalds return status; 65681da177e4SLinus Torvalds } 65691da177e4SLinus Torvalds 65701da177e4SLinus Torvalds /* 65718b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 65721da177e4SLinus Torvalds */ 6573bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6574bf269551SChuck Lever struct xdr_stream *xdr, 6575bf269551SChuck Lever struct nfs4_server_caps_res *res) 65761da177e4SLinus Torvalds { 65771da177e4SLinus Torvalds struct compound_hdr hdr; 65781da177e4SLinus Torvalds int status; 65791da177e4SLinus Torvalds 6580bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65819b7b9fccSAndy Adamson if (status) 65829b7b9fccSAndy Adamson goto out; 6583bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65849b7b9fccSAndy Adamson if (status) 65851da177e4SLinus Torvalds goto out; 6586bf269551SChuck Lever status = decode_putfh(xdr); 6587bf269551SChuck Lever if (status) 65881da177e4SLinus Torvalds goto out; 6589bf269551SChuck Lever status = decode_server_caps(xdr, res); 65901da177e4SLinus Torvalds out: 65911da177e4SLinus Torvalds return status; 65921da177e4SLinus Torvalds } 65931da177e4SLinus Torvalds 65941da177e4SLinus Torvalds /* 65951da177e4SLinus Torvalds * Decode RENEW response 65961da177e4SLinus Torvalds */ 6597bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6598bf269551SChuck Lever void *__unused) 65991da177e4SLinus Torvalds { 66001da177e4SLinus Torvalds struct compound_hdr hdr; 66011da177e4SLinus Torvalds int status; 66021da177e4SLinus Torvalds 6603bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66041da177e4SLinus Torvalds if (!status) 6605bf269551SChuck Lever status = decode_renew(xdr); 66061da177e4SLinus Torvalds return status; 66071da177e4SLinus Torvalds } 66081da177e4SLinus Torvalds 66091da177e4SLinus Torvalds /* 66108b173218SRicardo Labiaga * Decode SETCLIENTID response 66111da177e4SLinus Torvalds */ 6612bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6613bf269551SChuck Lever struct xdr_stream *xdr, 6614bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 66151da177e4SLinus Torvalds { 66161da177e4SLinus Torvalds struct compound_hdr hdr; 66171da177e4SLinus Torvalds int status; 66181da177e4SLinus Torvalds 6619bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66201da177e4SLinus Torvalds if (!status) 6621bf269551SChuck Lever status = decode_setclientid(xdr, res); 66221da177e4SLinus Torvalds return status; 66231da177e4SLinus Torvalds } 66241da177e4SLinus Torvalds 66251da177e4SLinus Torvalds /* 66268b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 66271da177e4SLinus Torvalds */ 6628bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 6629bf269551SChuck Lever struct xdr_stream *xdr, 6630bf269551SChuck Lever struct nfs_fsinfo *fsinfo) 66311da177e4SLinus Torvalds { 66321da177e4SLinus Torvalds struct compound_hdr hdr; 66331da177e4SLinus Torvalds int status; 66341da177e4SLinus Torvalds 6635bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66361da177e4SLinus Torvalds if (!status) 6637bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 66381da177e4SLinus Torvalds if (!status) 6639bf269551SChuck Lever status = decode_putrootfh(xdr); 66401da177e4SLinus Torvalds if (!status) 6641bf269551SChuck Lever status = decode_fsinfo(xdr, fsinfo); 66421da177e4SLinus Torvalds return status; 66431da177e4SLinus Torvalds } 66441da177e4SLinus Torvalds 66451da177e4SLinus Torvalds /* 66468b173218SRicardo Labiaga * Decode DELEGRETURN response 66471da177e4SLinus Torvalds */ 6648bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6649bf269551SChuck Lever struct xdr_stream *xdr, 6650bf269551SChuck Lever struct nfs4_delegreturnres *res) 66511da177e4SLinus Torvalds { 66521da177e4SLinus Torvalds struct compound_hdr hdr; 66531da177e4SLinus Torvalds int status; 66541da177e4SLinus Torvalds 6655bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66569b7b9fccSAndy Adamson if (status) 66579b7b9fccSAndy Adamson goto out; 6658bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66599b7b9fccSAndy Adamson if (status) 6660fa178f29STrond Myklebust goto out; 6661bf269551SChuck Lever status = decode_putfh(xdr); 6662fa178f29STrond Myklebust if (status != 0) 6663fa178f29STrond Myklebust goto out; 6664e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6665556ae3bbSJeff Layton if (status != 0) 6666556ae3bbSJeff Layton goto out; 6667e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6668fa178f29STrond Myklebust out: 66691da177e4SLinus Torvalds return status; 66701da177e4SLinus Torvalds } 66711da177e4SLinus Torvalds 6672683b57b4STrond Myklebust /* 66738b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6674683b57b4STrond Myklebust */ 6675bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6676bf269551SChuck Lever struct xdr_stream *xdr, 667722958463SBenny Halevy struct nfs4_fs_locations_res *res) 6678683b57b4STrond Myklebust { 6679683b57b4STrond Myklebust struct compound_hdr hdr; 6680683b57b4STrond Myklebust int status; 6681683b57b4STrond Myklebust 6682bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66839b7b9fccSAndy Adamson if (status) 66849b7b9fccSAndy Adamson goto out; 6685bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 66869b7b9fccSAndy Adamson if (status) 6687683b57b4STrond Myklebust goto out; 6688bf269551SChuck Lever status = decode_putfh(xdr); 6689bf269551SChuck Lever if (status) 6690683b57b4STrond Myklebust goto out; 6691bf269551SChuck Lever status = decode_lookup(xdr); 6692bf269551SChuck Lever if (status) 6693683b57b4STrond Myklebust goto out; 6694bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 66958b7e3f49STrond Myklebust status = decode_getfattr_generic(xdr, &res->fs_locations->fattr, 66968b7e3f49STrond Myklebust NULL, res->fs_locations, 66976926afd1STrond Myklebust res->fs_locations->server); 6698683b57b4STrond Myklebust out: 6699683b57b4STrond Myklebust return status; 6700683b57b4STrond Myklebust } 6701683b57b4STrond Myklebust 67025a5ea0d4SBryan Schumaker /* 67035a5ea0d4SBryan Schumaker * Decode SECINFO response 67045a5ea0d4SBryan Schumaker */ 67055a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 67065a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 67075a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 67085a5ea0d4SBryan Schumaker { 67095a5ea0d4SBryan Schumaker struct compound_hdr hdr; 67105a5ea0d4SBryan Schumaker int status; 67115a5ea0d4SBryan Schumaker 67125a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 67135a5ea0d4SBryan Schumaker if (status) 67145a5ea0d4SBryan Schumaker goto out; 67155a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 67165a5ea0d4SBryan Schumaker if (status) 67175a5ea0d4SBryan Schumaker goto out; 67185a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 67195a5ea0d4SBryan Schumaker if (status) 67205a5ea0d4SBryan Schumaker goto out; 67215a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 67225a5ea0d4SBryan Schumaker out: 67235a5ea0d4SBryan Schumaker return status; 67245a5ea0d4SBryan Schumaker } 67255a5ea0d4SBryan Schumaker 672699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 672799fe60d0SBenny Halevy /* 67287c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 67297c44f1aeSWeston Andros Adamson */ 67307c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 67317c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 67327c44f1aeSWeston Andros Adamson void *res) 67337c44f1aeSWeston Andros Adamson { 67347c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 67357c44f1aeSWeston Andros Adamson int status; 67367c44f1aeSWeston Andros Adamson 67377c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 67387c44f1aeSWeston Andros Adamson if (!status) 67397c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 67407c44f1aeSWeston Andros Adamson return status; 67417c44f1aeSWeston Andros Adamson } 67427c44f1aeSWeston Andros Adamson 67437c44f1aeSWeston Andros Adamson /* 67448b173218SRicardo Labiaga * Decode EXCHANGE_ID response 674599fe60d0SBenny Halevy */ 6746bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 6747bf269551SChuck Lever struct xdr_stream *xdr, 674899fe60d0SBenny Halevy void *res) 674999fe60d0SBenny Halevy { 675099fe60d0SBenny Halevy struct compound_hdr hdr; 675199fe60d0SBenny Halevy int status; 675299fe60d0SBenny Halevy 6753bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 675499fe60d0SBenny Halevy if (!status) 6755bf269551SChuck Lever status = decode_exchange_id(xdr, res); 675699fe60d0SBenny Halevy return status; 675799fe60d0SBenny Halevy } 67582050f0ccSAndy Adamson 67592050f0ccSAndy Adamson /* 67608b173218SRicardo Labiaga * Decode CREATE_SESSION response 6761fc931582SAndy Adamson */ 6762bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 6763bf269551SChuck Lever struct xdr_stream *xdr, 6764fc931582SAndy Adamson struct nfs41_create_session_res *res) 6765fc931582SAndy Adamson { 6766fc931582SAndy Adamson struct compound_hdr hdr; 6767fc931582SAndy Adamson int status; 6768fc931582SAndy Adamson 6769bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6770fc931582SAndy Adamson if (!status) 6771bf269551SChuck Lever status = decode_create_session(xdr, res); 6772fc931582SAndy Adamson return status; 6773fc931582SAndy Adamson } 6774fc931582SAndy Adamson 6775fc931582SAndy Adamson /* 67768b173218SRicardo Labiaga * Decode DESTROY_SESSION response 67770f3e66c6SAndy Adamson */ 6778bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 6779bf269551SChuck Lever struct xdr_stream *xdr, 6780bf269551SChuck Lever void *res) 67810f3e66c6SAndy Adamson { 67820f3e66c6SAndy Adamson struct compound_hdr hdr; 67830f3e66c6SAndy Adamson int status; 67840f3e66c6SAndy Adamson 6785bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67860f3e66c6SAndy Adamson if (!status) 6787bf269551SChuck Lever status = decode_destroy_session(xdr, res); 67880f3e66c6SAndy Adamson return status; 67890f3e66c6SAndy Adamson } 67900f3e66c6SAndy Adamson 67910f3e66c6SAndy Adamson /* 67928b173218SRicardo Labiaga * Decode SEQUENCE response 6793fc01cea9SAndy Adamson */ 6794bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 6795bf269551SChuck Lever struct xdr_stream *xdr, 6796fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 6797fc01cea9SAndy Adamson { 6798fc01cea9SAndy Adamson struct compound_hdr hdr; 6799fc01cea9SAndy Adamson int status; 6800fc01cea9SAndy Adamson 6801bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6802fc01cea9SAndy Adamson if (!status) 6803bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 6804fc01cea9SAndy Adamson return status; 6805fc01cea9SAndy Adamson } 6806fc01cea9SAndy Adamson 6807fc01cea9SAndy Adamson /* 68088b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 68092050f0ccSAndy Adamson */ 6810bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 6811bf269551SChuck Lever struct xdr_stream *xdr, 68122050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 68132050f0ccSAndy Adamson { 68142050f0ccSAndy Adamson struct compound_hdr hdr; 68152050f0ccSAndy Adamson int status; 68162050f0ccSAndy Adamson 6817bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68182050f0ccSAndy Adamson if (!status) 6819bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 68202050f0ccSAndy Adamson if (!status) 6821bf269551SChuck Lever status = decode_putrootfh(xdr); 68222050f0ccSAndy Adamson if (!status) 6823bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 68242050f0ccSAndy Adamson return status; 68252050f0ccSAndy Adamson } 682618019753SRicardo Labiaga 682718019753SRicardo Labiaga /* 682818019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 682918019753SRicardo Labiaga */ 6830bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 6831bf269551SChuck Lever struct xdr_stream *xdr, 683218019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 683318019753SRicardo Labiaga { 683418019753SRicardo Labiaga struct compound_hdr hdr; 683518019753SRicardo Labiaga int status; 683618019753SRicardo Labiaga 6837bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 683818019753SRicardo Labiaga if (!status) 6839bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 684018019753SRicardo Labiaga if (!status) 6841bf269551SChuck Lever status = decode_reclaim_complete(xdr, (void *)NULL); 684218019753SRicardo Labiaga return status; 684318019753SRicardo Labiaga } 6844b1f69b75SAndy Adamson 6845b1f69b75SAndy Adamson /* 68467f11d8d3SAndy Adamson * Decode GETDEVICELIST response 68477f11d8d3SAndy Adamson */ 68487f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp, 68497f11d8d3SAndy Adamson struct xdr_stream *xdr, 68507f11d8d3SAndy Adamson struct nfs4_getdevicelist_res *res) 68517f11d8d3SAndy Adamson { 68527f11d8d3SAndy Adamson struct compound_hdr hdr; 68537f11d8d3SAndy Adamson int status; 68547f11d8d3SAndy Adamson 68557f11d8d3SAndy Adamson dprintk("encoding getdevicelist!\n"); 68567f11d8d3SAndy Adamson 68577f11d8d3SAndy Adamson status = decode_compound_hdr(xdr, &hdr); 68587f11d8d3SAndy Adamson if (status != 0) 68597f11d8d3SAndy Adamson goto out; 68607f11d8d3SAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 68617f11d8d3SAndy Adamson if (status != 0) 68627f11d8d3SAndy Adamson goto out; 68637f11d8d3SAndy Adamson status = decode_putfh(xdr); 68647f11d8d3SAndy Adamson if (status != 0) 68657f11d8d3SAndy Adamson goto out; 68667f11d8d3SAndy Adamson status = decode_getdevicelist(xdr, res->devlist); 68677f11d8d3SAndy Adamson out: 68687f11d8d3SAndy Adamson return status; 68697f11d8d3SAndy Adamson } 68707f11d8d3SAndy Adamson 68717f11d8d3SAndy Adamson /* 6872b1f69b75SAndy Adamson * Decode GETDEVINFO response 6873b1f69b75SAndy Adamson */ 6874bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 6875bf269551SChuck Lever struct xdr_stream *xdr, 6876b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 6877b1f69b75SAndy Adamson { 6878b1f69b75SAndy Adamson struct compound_hdr hdr; 6879b1f69b75SAndy Adamson int status; 6880b1f69b75SAndy Adamson 6881bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6882b1f69b75SAndy Adamson if (status != 0) 6883b1f69b75SAndy Adamson goto out; 6884bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6885b1f69b75SAndy Adamson if (status != 0) 6886b1f69b75SAndy Adamson goto out; 6887bf269551SChuck Lever status = decode_getdeviceinfo(xdr, res->pdev); 6888b1f69b75SAndy Adamson out: 6889b1f69b75SAndy Adamson return status; 6890b1f69b75SAndy Adamson } 6891b1f69b75SAndy Adamson 6892b1f69b75SAndy Adamson /* 6893b1f69b75SAndy Adamson * Decode LAYOUTGET response 6894b1f69b75SAndy Adamson */ 6895bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 6896bf269551SChuck Lever struct xdr_stream *xdr, 6897b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6898b1f69b75SAndy Adamson { 6899b1f69b75SAndy Adamson struct compound_hdr hdr; 6900b1f69b75SAndy Adamson int status; 6901b1f69b75SAndy Adamson 6902bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6903b1f69b75SAndy Adamson if (status) 6904b1f69b75SAndy Adamson goto out; 6905bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6906b1f69b75SAndy Adamson if (status) 6907b1f69b75SAndy Adamson goto out; 6908bf269551SChuck Lever status = decode_putfh(xdr); 6909b1f69b75SAndy Adamson if (status) 6910b1f69b75SAndy Adamson goto out; 6911bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 6912b1f69b75SAndy Adamson out: 6913b1f69b75SAndy Adamson return status; 6914b1f69b75SAndy Adamson } 6915863a3c6cSAndy Adamson 6916863a3c6cSAndy Adamson /* 6917cbe82603SBenny Halevy * Decode LAYOUTRETURN response 6918cbe82603SBenny Halevy */ 6919cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 6920cbe82603SBenny Halevy struct xdr_stream *xdr, 6921cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6922cbe82603SBenny Halevy { 6923cbe82603SBenny Halevy struct compound_hdr hdr; 6924cbe82603SBenny Halevy int status; 6925cbe82603SBenny Halevy 6926cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 6927cbe82603SBenny Halevy if (status) 6928cbe82603SBenny Halevy goto out; 6929cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 6930cbe82603SBenny Halevy if (status) 6931cbe82603SBenny Halevy goto out; 6932cbe82603SBenny Halevy status = decode_putfh(xdr); 6933cbe82603SBenny Halevy if (status) 6934cbe82603SBenny Halevy goto out; 6935cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 6936cbe82603SBenny Halevy out: 6937cbe82603SBenny Halevy return status; 6938cbe82603SBenny Halevy } 6939cbe82603SBenny Halevy 6940cbe82603SBenny Halevy /* 6941863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 6942863a3c6cSAndy Adamson */ 6943863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 6944863a3c6cSAndy Adamson struct xdr_stream *xdr, 6945863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6946863a3c6cSAndy Adamson { 6947863a3c6cSAndy Adamson struct compound_hdr hdr; 6948863a3c6cSAndy Adamson int status; 6949863a3c6cSAndy Adamson 6950863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 6951863a3c6cSAndy Adamson if (status) 6952863a3c6cSAndy Adamson goto out; 6953863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 6954863a3c6cSAndy Adamson if (status) 6955863a3c6cSAndy Adamson goto out; 6956863a3c6cSAndy Adamson status = decode_putfh(xdr); 6957863a3c6cSAndy Adamson if (status) 6958863a3c6cSAndy Adamson goto out; 6959863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 6960863a3c6cSAndy Adamson if (status) 6961863a3c6cSAndy Adamson goto out; 69626926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 6963863a3c6cSAndy Adamson out: 6964863a3c6cSAndy Adamson return status; 6965863a3c6cSAndy Adamson } 6966fca78d6dSBryan Schumaker 6967fca78d6dSBryan Schumaker /* 6968fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 6969fca78d6dSBryan Schumaker */ 6970fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 6971fca78d6dSBryan Schumaker struct xdr_stream *xdr, 6972fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 6973fca78d6dSBryan Schumaker { 6974fca78d6dSBryan Schumaker struct compound_hdr hdr; 6975fca78d6dSBryan Schumaker int status; 6976fca78d6dSBryan Schumaker 6977fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 6978fca78d6dSBryan Schumaker if (status) 6979fca78d6dSBryan Schumaker goto out; 6980fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 6981fca78d6dSBryan Schumaker if (status) 6982fca78d6dSBryan Schumaker goto out; 6983fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 6984fca78d6dSBryan Schumaker if (status) 6985fca78d6dSBryan Schumaker goto out; 698631e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 6987fca78d6dSBryan Schumaker out: 6988fca78d6dSBryan Schumaker return status; 6989fca78d6dSBryan Schumaker } 69907d974794SBryan Schumaker 69917d974794SBryan Schumaker /* 69927d974794SBryan Schumaker * Decode TEST_STATEID response 69937d974794SBryan Schumaker */ 69947d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 69957d974794SBryan Schumaker struct xdr_stream *xdr, 69967d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 69977d974794SBryan Schumaker { 69987d974794SBryan Schumaker struct compound_hdr hdr; 69997d974794SBryan Schumaker int status; 70007d974794SBryan Schumaker 70017d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 70027d974794SBryan Schumaker if (status) 70037d974794SBryan Schumaker goto out; 70047d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 70057d974794SBryan Schumaker if (status) 70067d974794SBryan Schumaker goto out; 70077d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 70087d974794SBryan Schumaker out: 70097d974794SBryan Schumaker return status; 70107d974794SBryan Schumaker } 70119aeda35fSBryan Schumaker 70129aeda35fSBryan Schumaker /* 70139aeda35fSBryan Schumaker * Decode FREE_STATEID response 70149aeda35fSBryan Schumaker */ 70159aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 70169aeda35fSBryan Schumaker struct xdr_stream *xdr, 70179aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 70189aeda35fSBryan Schumaker { 70199aeda35fSBryan Schumaker struct compound_hdr hdr; 70209aeda35fSBryan Schumaker int status; 70219aeda35fSBryan Schumaker 70229aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 70239aeda35fSBryan Schumaker if (status) 70249aeda35fSBryan Schumaker goto out; 70259aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 70269aeda35fSBryan Schumaker if (status) 70279aeda35fSBryan Schumaker goto out; 70289aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 70299aeda35fSBryan Schumaker out: 70309aeda35fSBryan Schumaker return status; 70319aeda35fSBryan Schumaker } 703299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 703399fe60d0SBenny Halevy 7034573c4e1eSChuck Lever /** 7035573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7036573c4e1eSChuck Lever * the local page cache. 7037573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7038573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7039573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7040573c4e1eSChuck Lever * 7041573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7042573c4e1eSChuck Lever * returned. 7043573c4e1eSChuck Lever * 7044573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7045573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7046573c4e1eSChuck Lever * on a directory already in our cache. 7047573c4e1eSChuck Lever */ 7048573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7049573c4e1eSChuck Lever int plus) 70501da177e4SLinus Torvalds { 7051dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 70521da177e4SLinus Torvalds uint32_t len; 7053babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7054babddc72SBryan Schumaker if (unlikely(!p)) 7055babddc72SBryan Schumaker goto out_overflow; 7056c08e76d0SChuck Lever if (*p == xdr_zero) { 7057babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7058babddc72SBryan Schumaker if (unlikely(!p)) 7059babddc72SBryan Schumaker goto out_overflow; 7060c08e76d0SChuck Lever if (*p == xdr_zero) 7061573c4e1eSChuck Lever return -EAGAIN; 70621da177e4SLinus Torvalds entry->eof = 1; 7063573c4e1eSChuck Lever return -EBADCOOKIE; 70641da177e4SLinus Torvalds } 70651da177e4SLinus Torvalds 7066babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7067babddc72SBryan Schumaker if (unlikely(!p)) 7068babddc72SBryan Schumaker goto out_overflow; 70691da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 70701da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7071c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7072babddc72SBryan Schumaker 70739af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7074babddc72SBryan Schumaker if (unlikely(!p)) 7075babddc72SBryan Schumaker goto out_overflow; 70761da177e4SLinus Torvalds entry->name = (const char *) p; 70771da177e4SLinus Torvalds 70781da177e4SLinus Torvalds /* 70791da177e4SLinus Torvalds * In case the server doesn't return an inode number, 70801da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 70811da177e4SLinus Torvalds * since glibc seems to choke on it...) 70821da177e4SLinus Torvalds */ 70831da177e4SLinus Torvalds entry->ino = 1; 70844f082222STrond Myklebust entry->fattr->valid = 0; 70851da177e4SLinus Torvalds 70869af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7087babddc72SBryan Schumaker goto out_overflow; 70889af8c222STrond Myklebust 70899af8c222STrond Myklebust if (decode_attr_length(xdr, &len, &p) < 0) 7090babddc72SBryan Schumaker goto out_overflow; 70919af8c222STrond Myklebust 7092573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 70938b7e3f49STrond Myklebust NULL, entry->server) < 0) 7094babddc72SBryan Schumaker goto out_overflow; 709528331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 709628331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 709728331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 709882f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 70999af8c222STrond Myklebust 71000b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 71010b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 71020b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 71030b26a0bfSTrond Myklebust 7104573c4e1eSChuck Lever return 0; 7105babddc72SBryan Schumaker 7106babddc72SBryan Schumaker out_overflow: 7107babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7108573c4e1eSChuck Lever return -EAGAIN; 71091da177e4SLinus Torvalds } 71101da177e4SLinus Torvalds 71111da177e4SLinus Torvalds /* 71121da177e4SLinus Torvalds * We need to translate between nfs status return values and 71131da177e4SLinus Torvalds * the local errno values which may not be the same. 71141da177e4SLinus Torvalds */ 71151da177e4SLinus Torvalds static struct { 71161da177e4SLinus Torvalds int stat; 71171da177e4SLinus Torvalds int errno; 71181da177e4SLinus Torvalds } nfs_errtbl[] = { 71191da177e4SLinus Torvalds { NFS4_OK, 0 }, 7120856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7121856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7122856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7123856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7124856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7125856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7126856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7127856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7128856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7129856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7130856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7131856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7132856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7133856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7134856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7135856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7136856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7137856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7138856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7139856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7140856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7141856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7142fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7143856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7144856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7145856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7146856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7147856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7148856dff3dSBenny Halevy { -1, -EIO } 71491da177e4SLinus Torvalds }; 71501da177e4SLinus Torvalds 71511da177e4SLinus Torvalds /* 71521da177e4SLinus Torvalds * Convert an NFS error code to a local one. 71531da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 71541da177e4SLinus Torvalds */ 71551da177e4SLinus Torvalds static int 71560a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 71571da177e4SLinus Torvalds { 71581da177e4SLinus Torvalds int i; 71591da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 71601da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 71611da177e4SLinus Torvalds return nfs_errtbl[i].errno; 71621da177e4SLinus Torvalds } 71631da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 71641da177e4SLinus Torvalds /* The server is looney tunes. */ 7165fdcb4577STrond Myklebust return -EREMOTEIO; 71661da177e4SLinus Torvalds } 71671da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 71681da177e4SLinus Torvalds * handle it. 71691da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 71701da177e4SLinus Torvalds * not conflict with native Linux error codes. 71711da177e4SLinus Torvalds */ 7172856dff3dSBenny Halevy return -stat; 71731da177e4SLinus Torvalds } 71741da177e4SLinus Torvalds 71751da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 71761da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 71771da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 71789f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7179bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 71802bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 71812bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7182cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7183cc0175c1SChuck Lever .p_name = #proc, \ 71841da177e4SLinus Torvalds } 71851da177e4SLinus Torvalds 71861da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 71871da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 71881da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 71891da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 71901da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 71911da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 71921da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 71931da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 71941da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 71951da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 71961da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 71971da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 71981da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 71991da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 72001da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 72011da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 72021da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 72031da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 72041da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 72051da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 72061da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 72071da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 72081da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 72091da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 72101da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 72111da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 72121da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 72131da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 72141da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 72151da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 72161da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 72171da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7218029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 721923ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7220683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7221d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 72225a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 722399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 72247c44f1aeSWeston Andros Adamson PROC(BIND_CONN_TO_SESSION, 72257c44f1aeSWeston Andros Adamson enc_bind_conn_to_session, dec_bind_conn_to_session), 722699fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7227fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 72280f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7229fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 72302050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 723118019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7232b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7233b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7234863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7235cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7236fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 72377d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 72389aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 72397f11d8d3SAndy Adamson PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist), 724099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 72411da177e4SLinus Torvalds }; 72421da177e4SLinus Torvalds 7243a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 72441da177e4SLinus Torvalds .number = 4, 7245e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 72461da177e4SLinus Torvalds .procs = nfs4_procedures 72471da177e4SLinus Torvalds }; 72481da177e4SLinus Torvalds 72491da177e4SLinus Torvalds /* 72501da177e4SLinus Torvalds * Local variables: 72511da177e4SLinus Torvalds * c-basic-offset: 8 72521da177e4SLinus Torvalds * End: 72531da177e4SLinus Torvalds */ 7254