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> 564ce79717STrond Myklebust #include "nfs4_fs.h" 574882ef72SAlexandros Batsakis #include "internal.h" 58b1f69b75SAndy Adamson #include "pnfs.h" 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 631da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 641da177e4SLinus Torvalds 650a8ea437SDavid Howells static int nfs4_stat_to_errno(int); 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 681da177e4SLinus Torvalds #ifdef DEBUG 691da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20 701da177e4SLinus Torvalds #else 711da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0 721da177e4SLinus Torvalds #endif 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds /* lock,open owner id: 759f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 761da177e4SLinus Torvalds */ 77d035c36cSTrond Myklebust #define open_owner_id_maxsz (1 + 1 + 4) 78d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4) 799104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 801da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 811da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 821da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1) 831da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2) 849104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 859104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 869104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 879104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 881da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 891da177e4SLinus Torvalds (NFS4_FHSIZE >> 2)) 901da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz) 911da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 921da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 931da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz) 941da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 951da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2)) 96e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4 9796928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 981da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 991da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 100bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 101bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 10296928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */ 10396928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 104bd625ba8STrond Myklebust 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz)) 10596928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 10696928206SJ. Bruce Fields nfs4_fattr_value_maxsz) 10796928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 1089104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 1099104a55dSTrond Myklebust 1 + 2 + 1 + \ 1109104a55dSTrond Myklebust nfs4_owner_maxsz + \ 1119104a55dSTrond Myklebust nfs4_group_maxsz + \ 1129104a55dSTrond Myklebust 4 + 4) 1131da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz) 1141da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz) 11556ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 11656ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 1172f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz) 118dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three 119dae100c2SFred Isaman * layout types will be returned. 120dae100c2SFred Isaman */ 121dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 122dae100c2SFred Isaman nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 1231da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 1241da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz) 1251da177e4SLinus Torvalds #define encode_setclientid_maxsz \ 1261da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 127cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 128cc38bac3SChuck Lever XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ 129cc38bac3SChuck Lever 1 /* sc_prog */ + \ 130cc38bac3SChuck Lever XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 131cc38bac3SChuck Lever XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 132cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1331da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1341da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1351da177e4SLinus Torvalds 2 + \ 1361da177e4SLinus Torvalds 1024) /* large value for CLID_INUSE */ 1371da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \ 1381da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 1391da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2)) 1401da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \ 1411da177e4SLinus Torvalds (op_decode_hdr_maxsz) 142e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 143e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz) 1442cebf828STrond Myklebust #define encode_share_access_maxsz \ 1452cebf828STrond Myklebust (2) 1464882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1472cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1482cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1492cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1502cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1512cebf828STrond Myklebust open_owner_id_maxsz + \ 1522cebf828STrond Myklebust encode_opentype_maxsz + \ 1532cebf828STrond Myklebust encode_claim_null_maxsz) 1542cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1559104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1562cebf828STrond Myklebust decode_ace_maxsz) 1572cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1582cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1599104a55dSTrond Myklebust decode_stateid_maxsz + \ 1602cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1612cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1622cebf828STrond Myklebust decode_delegation_maxsz) 1639104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1649104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1659104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1669104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1679104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1689104a55dSTrond Myklebust decode_stateid_maxsz) 1699104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 1709104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1719104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 1729104a55dSTrond Myklebust encode_share_access_maxsz) 1739104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 1749104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1759104a55dSTrond Myklebust decode_stateid_maxsz) 1769104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 1779104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 1789104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 1799104a55dSTrond Myklebust decode_stateid_maxsz) 1809104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 1819104a55dSTrond Myklebust encode_stateid_maxsz + \ 1829104a55dSTrond Myklebust encode_attrs_maxsz) 1839104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 1849104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 1859104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 1869104a55dSTrond Myklebust encode_stateid_maxsz + 3) 1879104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 1889104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 1899104a55dSTrond Myklebust 2 + encode_verifier_maxsz + 5) 1909104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 1919104a55dSTrond Myklebust decode_verifier_maxsz) 1929104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 1939104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 1949104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 1959104a55dSTrond Myklebust encode_stateid_maxsz + 4) 1969104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 1979104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 1989104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 1999104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2009104a55dSTrond Myklebust decode_verifier_maxsz) 2011da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2021da177e4SLinus Torvalds nfs4_name_maxsz) 2036ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2046ce18391SBenny Halevy decode_change_info_maxsz) 2051da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2061da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2076ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2086ce18391SBenny Halevy decode_change_info_maxsz + \ 2096ce18391SBenny Halevy decode_change_info_maxsz) 2101da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2111da177e4SLinus Torvalds nfs4_name_maxsz) 2126ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 213daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2149104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2159104a55dSTrond Myklebust 7 + \ 216daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 217daccbdedSTrond Myklebust encode_lockowner_maxsz) 2189104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2199104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2209104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2219104a55dSTrond Myklebust decode_lock_denied_maxsz) 222daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 223daccbdedSTrond Myklebust encode_lockowner_maxsz) 2249104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2259104a55dSTrond Myklebust decode_lock_denied_maxsz) 2269104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2279104a55dSTrond Myklebust encode_stateid_maxsz + \ 2289104a55dSTrond Myklebust 4) 2299104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2309104a55dSTrond Myklebust decode_stateid_maxsz) 231d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 232d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 233d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 234d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 235d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2369104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2379104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2381da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2391da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 24094a6d753SChuck Lever 1 + \ 24196928206SJ. Bruce Fields nfs4_fattr_maxsz) 2421da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2431da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2449104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2459104a55dSTrond Myklebust encode_attrs_maxsz) 2462cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2472cebf828STrond Myklebust decode_change_info_maxsz + \ 2482cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2499104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2509104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2511da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2521da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2539104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2549104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2559104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2569104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2579104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2589104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 259e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 260e6889620STrond Myklebust (encode_getattr_maxsz) 261e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 262e6889620STrond Myklebust (0) 2635a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2641650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2659b7b9fccSAndy Adamson 2669b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 267fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 268fc931582SAndy Adamson 26999fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 27099fe60d0SBenny Halevy encode_verifier_maxsz + \ 27199fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 27299fe60d0SBenny Halevy XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ 27399fe60d0SBenny Halevy 1 /* flags */ + \ 27499fe60d0SBenny Halevy 1 /* spa_how */ + \ 27599fe60d0SBenny Halevy 0 /* SP4_NONE (for now) */ + \ 276db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 277db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 278db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 279db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 280db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 281db8ac8baSWeston Andros Adamson 3 /* nii_date */) 28299fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 28399fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 28499fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 28599fe60d0SBenny Halevy 1 /* eir_flags */ + \ 28699fe60d0SBenny Halevy 1 /* spr_how */ + \ 28799fe60d0SBenny Halevy 0 /* SP4_NONE (for now) */ + \ 28899fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 28999fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 29099fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 29199fe60d0SBenny Halevy /* eir_server_scope<> */ \ 29299fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 29399fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 2947d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 2957d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 2967d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 2977d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 2987d2ed9acSWeston Andros Adamson 3 /* nii_date */) 299fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 300fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 301fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 302fc931582SAndy Adamson 1 /* ca_rdma_ird */) 303fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 304fc931582SAndy Adamson 2 /* csa_clientid */ + \ 305fc931582SAndy Adamson 1 /* csa_sequence */ + \ 306fc931582SAndy Adamson 1 /* csa_flags */ + \ 307fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 308fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 309fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 310fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 311fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 312fc931582SAndy Adamson 1 /* stamp */ + \ 313fc931582SAndy Adamson 1 /* machinename.len */ + \ 314fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 315fc931582SAndy Adamson 1 /* uid */ + \ 316fc931582SAndy Adamson 1 /* gid */ + \ 317fc931582SAndy Adamson 1 /* gids.len (0) */) 318fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 319fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 320fc931582SAndy Adamson 1 /* csr_sequence */ + \ 321fc931582SAndy Adamson 1 /* csr_flags */ + \ 322fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 323fc931582SAndy Adamson decode_channel_attrs_maxsz) 3240f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3250f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 326fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 327fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 328fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 329fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 33018019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 33118019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 3327f11d8d3SAndy Adamson #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \ 3337f11d8d3SAndy Adamson encode_verifier_maxsz) 3347f11d8d3SAndy Adamson #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \ 3357f11d8d3SAndy Adamson 2 /* nfs_cookie4 gdlr_cookie */ + \ 3367f11d8d3SAndy Adamson decode_verifier_maxsz \ 3377f11d8d3SAndy Adamson /* verifier4 gdlr_verifier */ + \ 3387f11d8d3SAndy Adamson 1 /* gdlr_deviceid_list count */ + \ 3397f11d8d3SAndy Adamson XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \ 3407f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE) \ 3417f11d8d3SAndy Adamson /* gdlr_deviceid_list */ + \ 3427f11d8d3SAndy Adamson 1 /* bool gdlr_eof */) 343b1f69b75SAndy Adamson #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \ 344b1f69b75SAndy Adamson XDR_QUADLEN(NFS4_DEVICEID4_SIZE)) 345b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 346b1f69b75SAndy Adamson 1 /* layout type */ + \ 347b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 348b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 349b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 350b1f69b75SAndy Adamson 1 /* notification bitmap */) 351b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 352b1f69b75SAndy Adamson encode_stateid_maxsz) 353b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 354b1f69b75SAndy Adamson decode_stateid_maxsz + \ 355b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 356863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 357863a3c6cSAndy Adamson 2 /* offset */ + \ 358863a3c6cSAndy Adamson 2 /* length */ + \ 359863a3c6cSAndy Adamson 1 /* reclaim */ + \ 360863a3c6cSAndy Adamson encode_stateid_maxsz + \ 361863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 362863a3c6cSAndy Adamson 2 /* last byte written */ + \ 363863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 364863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 365863a3c6cSAndy Adamson 1 /* NULL filelayout layoutupdate4 payload */) 366863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 367cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 368cbe82603SBenny Halevy encode_stateid_maxsz + \ 369cbe82603SBenny Halevy 1 /* FIXME: opaque lrf_body always empty at the moment */) 370cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 371cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 372fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 373fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 3747d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 3757d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 3767d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 3779aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 3789aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 3799aeda35fSBryan Schumaker #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1) 3809b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 3819b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 3829b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 3839b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 3849b7b9fccSAndy Adamson 3851da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 3861da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 3871da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 3889b7b9fccSAndy Adamson encode_sequence_maxsz + \ 3891da177e4SLinus Torvalds encode_putfh_maxsz + \ 3909104a55dSTrond Myklebust encode_read_maxsz) 3911da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 3929b7b9fccSAndy Adamson decode_sequence_maxsz + \ 3931da177e4SLinus Torvalds decode_putfh_maxsz + \ 3949104a55dSTrond Myklebust decode_read_maxsz) 3951da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 3969b7b9fccSAndy Adamson encode_sequence_maxsz + \ 3971da177e4SLinus Torvalds encode_putfh_maxsz + \ 3989104a55dSTrond Myklebust encode_readlink_maxsz) 3991da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4009b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4011da177e4SLinus Torvalds decode_putfh_maxsz + \ 4029104a55dSTrond Myklebust decode_readlink_maxsz) 4031da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4049b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4051da177e4SLinus Torvalds encode_putfh_maxsz + \ 4069104a55dSTrond Myklebust encode_readdir_maxsz) 4071da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4089b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4091da177e4SLinus Torvalds decode_putfh_maxsz + \ 4109104a55dSTrond Myklebust decode_readdir_maxsz) 4111da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4129b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4131da177e4SLinus Torvalds encode_putfh_maxsz + \ 4149104a55dSTrond Myklebust encode_write_maxsz + \ 4154f9838c7STrond Myklebust encode_getattr_maxsz) 4161da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4181da177e4SLinus Torvalds decode_putfh_maxsz + \ 4199104a55dSTrond Myklebust decode_write_maxsz + \ 4204f9838c7STrond Myklebust decode_getattr_maxsz) 4211da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4229b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4231da177e4SLinus Torvalds encode_putfh_maxsz + \ 4249104a55dSTrond Myklebust encode_commit_maxsz + \ 4254f9838c7STrond Myklebust encode_getattr_maxsz) 4261da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4279b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4281da177e4SLinus Torvalds decode_putfh_maxsz + \ 4299104a55dSTrond Myklebust decode_commit_maxsz + \ 4304f9838c7STrond Myklebust decode_getattr_maxsz) 4311da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4329b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4331da177e4SLinus Torvalds encode_putfh_maxsz + \ 4342cebf828STrond Myklebust encode_savefh_maxsz + \ 4352cebf828STrond Myklebust encode_open_maxsz + \ 4362cebf828STrond Myklebust encode_getfh_maxsz + \ 4371da177e4SLinus Torvalds encode_getattr_maxsz + \ 4382cebf828STrond Myklebust encode_restorefh_maxsz + \ 4392cebf828STrond Myklebust encode_getattr_maxsz) 4401da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4419b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4421da177e4SLinus Torvalds decode_putfh_maxsz + \ 4432cebf828STrond Myklebust decode_savefh_maxsz + \ 4442cebf828STrond Myklebust decode_open_maxsz + \ 4452cebf828STrond Myklebust decode_getfh_maxsz + \ 4461da177e4SLinus Torvalds decode_getattr_maxsz + \ 4472cebf828STrond Myklebust decode_restorefh_maxsz + \ 4482cebf828STrond Myklebust decode_getattr_maxsz) 4491da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4501da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4511da177e4SLinus Torvalds encode_putfh_maxsz + \ 4529104a55dSTrond Myklebust encode_open_confirm_maxsz) 4539104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4549104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4551da177e4SLinus Torvalds decode_putfh_maxsz + \ 4569104a55dSTrond Myklebust decode_open_confirm_maxsz) 4571da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 4589b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4591da177e4SLinus Torvalds encode_putfh_maxsz + \ 4602cebf828STrond Myklebust encode_open_maxsz + \ 4612cebf828STrond Myklebust encode_getattr_maxsz) 4621da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 4639b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4641da177e4SLinus Torvalds decode_putfh_maxsz + \ 4652cebf828STrond Myklebust decode_open_maxsz + \ 4662cebf828STrond Myklebust decode_getattr_maxsz) 4671da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 4681da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4699b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4701da177e4SLinus Torvalds encode_putfh_maxsz + \ 4719104a55dSTrond Myklebust encode_open_downgrade_maxsz + \ 472516a6af6STrond Myklebust encode_getattr_maxsz) 4731da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 4741da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 4759b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4761da177e4SLinus Torvalds decode_putfh_maxsz + \ 4779104a55dSTrond Myklebust decode_open_downgrade_maxsz + \ 478516a6af6STrond Myklebust decode_getattr_maxsz) 4791da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 4809b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4811da177e4SLinus Torvalds encode_putfh_maxsz + \ 4829104a55dSTrond Myklebust encode_close_maxsz + \ 483516a6af6STrond Myklebust encode_getattr_maxsz) 4841da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 4859b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4861da177e4SLinus Torvalds decode_putfh_maxsz + \ 4879104a55dSTrond Myklebust decode_close_maxsz + \ 488516a6af6STrond Myklebust decode_getattr_maxsz) 4891da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 4909b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4911da177e4SLinus Torvalds encode_putfh_maxsz + \ 4929104a55dSTrond Myklebust encode_setattr_maxsz + \ 4931da177e4SLinus Torvalds encode_getattr_maxsz) 4941da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 4959b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4961da177e4SLinus Torvalds decode_putfh_maxsz + \ 4979104a55dSTrond Myklebust decode_setattr_maxsz + \ 4989104a55dSTrond Myklebust decode_getattr_maxsz) 4991da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5009b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5011da177e4SLinus Torvalds encode_putfh_maxsz + \ 5021da177e4SLinus Torvalds encode_fsinfo_maxsz) 5031da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5049b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5051da177e4SLinus Torvalds decode_putfh_maxsz + \ 5061da177e4SLinus Torvalds decode_fsinfo_maxsz) 5071da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5081da177e4SLinus Torvalds encode_renew_maxsz) 5091da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5101da177e4SLinus Torvalds decode_renew_maxsz) 5111da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5121da177e4SLinus Torvalds encode_setclientid_maxsz) 5131da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5141da177e4SLinus Torvalds decode_setclientid_maxsz) 5151da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5161da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5171da177e4SLinus Torvalds encode_setclientid_confirm_maxsz + \ 5181da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 5191da177e4SLinus Torvalds encode_fsinfo_maxsz) 5201da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5211da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5221da177e4SLinus Torvalds decode_setclientid_confirm_maxsz + \ 5231da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 5241da177e4SLinus Torvalds decode_fsinfo_maxsz) 5251da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5269b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5271da177e4SLinus Torvalds encode_putfh_maxsz + \ 5289104a55dSTrond Myklebust encode_lock_maxsz) 5291da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5309b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5311da177e4SLinus Torvalds decode_putfh_maxsz + \ 5329104a55dSTrond Myklebust decode_lock_maxsz) 5331da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5349b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5351da177e4SLinus Torvalds encode_putfh_maxsz + \ 5369104a55dSTrond Myklebust encode_lockt_maxsz) 5379104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5389b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5399104a55dSTrond Myklebust decode_putfh_maxsz + \ 5409104a55dSTrond Myklebust decode_lockt_maxsz) 5411da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5429b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5431da177e4SLinus Torvalds encode_putfh_maxsz + \ 5449104a55dSTrond Myklebust encode_locku_maxsz) 5451da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5469b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5471da177e4SLinus Torvalds decode_putfh_maxsz + \ 5489104a55dSTrond Myklebust decode_locku_maxsz) 549d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 550d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 551d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 552d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 553d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 554d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5551da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5569b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5571da177e4SLinus Torvalds encode_putfh_maxsz + \ 55876b32999STrond Myklebust encode_access_maxsz + \ 55976b32999STrond Myklebust encode_getattr_maxsz) 5601da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5619b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5621da177e4SLinus Torvalds decode_putfh_maxsz + \ 56376b32999STrond Myklebust decode_access_maxsz + \ 56476b32999STrond Myklebust decode_getattr_maxsz) 5651da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 5669b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5671da177e4SLinus Torvalds encode_putfh_maxsz + \ 5681da177e4SLinus Torvalds encode_getattr_maxsz) 5691da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 5709b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5711da177e4SLinus Torvalds decode_putfh_maxsz + \ 5721da177e4SLinus Torvalds decode_getattr_maxsz) 5731da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 5749b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5751da177e4SLinus Torvalds encode_putfh_maxsz + \ 5761da177e4SLinus Torvalds encode_lookup_maxsz + \ 5771da177e4SLinus Torvalds encode_getattr_maxsz + \ 5781da177e4SLinus Torvalds encode_getfh_maxsz) 5791da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 5809b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5811da177e4SLinus Torvalds decode_putfh_maxsz + \ 582e6889620STrond Myklebust decode_lookup_maxsz + \ 5831da177e4SLinus Torvalds decode_getattr_maxsz + \ 5841da177e4SLinus Torvalds decode_getfh_maxsz) 5851da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 5869b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5871da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 5881da177e4SLinus Torvalds encode_getattr_maxsz + \ 5891da177e4SLinus Torvalds encode_getfh_maxsz) 5901da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 5919b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5921da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 5931da177e4SLinus Torvalds decode_getattr_maxsz + \ 5941da177e4SLinus Torvalds decode_getfh_maxsz) 5951da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 5969b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5971da177e4SLinus Torvalds encode_putfh_maxsz + \ 59816e42959STrond Myklebust encode_remove_maxsz + \ 59916e42959STrond Myklebust encode_getattr_maxsz) 6001da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6019b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6021da177e4SLinus Torvalds decode_putfh_maxsz + \ 6036ce18391SBenny Halevy decode_remove_maxsz + \ 60416e42959STrond Myklebust decode_getattr_maxsz) 6051da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6069b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6071da177e4SLinus Torvalds encode_putfh_maxsz + \ 6081da177e4SLinus Torvalds encode_savefh_maxsz + \ 6091da177e4SLinus Torvalds encode_putfh_maxsz + \ 6106caf2c82STrond Myklebust encode_rename_maxsz + \ 6116caf2c82STrond Myklebust encode_getattr_maxsz + \ 6126caf2c82STrond Myklebust encode_restorefh_maxsz + \ 6136caf2c82STrond Myklebust encode_getattr_maxsz) 6141da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6159b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6161da177e4SLinus Torvalds decode_putfh_maxsz + \ 6171da177e4SLinus Torvalds decode_savefh_maxsz + \ 6181da177e4SLinus Torvalds decode_putfh_maxsz + \ 6196caf2c82STrond Myklebust decode_rename_maxsz + \ 6206caf2c82STrond Myklebust decode_getattr_maxsz + \ 6216caf2c82STrond Myklebust decode_restorefh_maxsz + \ 6226caf2c82STrond Myklebust decode_getattr_maxsz) 6231da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6249b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6251da177e4SLinus Torvalds encode_putfh_maxsz + \ 6261da177e4SLinus Torvalds encode_savefh_maxsz + \ 6271da177e4SLinus Torvalds encode_putfh_maxsz + \ 62891ba2eeeSTrond Myklebust encode_link_maxsz + \ 62991ba2eeeSTrond Myklebust decode_getattr_maxsz + \ 63091ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 63191ba2eeeSTrond Myklebust decode_getattr_maxsz) 6321da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6339b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6341da177e4SLinus Torvalds decode_putfh_maxsz + \ 6351da177e4SLinus Torvalds decode_savefh_maxsz + \ 6361da177e4SLinus Torvalds decode_putfh_maxsz + \ 63791ba2eeeSTrond Myklebust decode_link_maxsz + \ 63891ba2eeeSTrond Myklebust decode_getattr_maxsz + \ 63991ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 64091ba2eeeSTrond Myklebust decode_getattr_maxsz) 6411da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6429b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6431da177e4SLinus Torvalds encode_putfh_maxsz + \ 6441da177e4SLinus Torvalds encode_symlink_maxsz + \ 6451da177e4SLinus Torvalds encode_getattr_maxsz + \ 6461da177e4SLinus Torvalds encode_getfh_maxsz) 6471da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6489b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6491da177e4SLinus Torvalds decode_putfh_maxsz + \ 6501da177e4SLinus Torvalds decode_symlink_maxsz + \ 6511da177e4SLinus Torvalds decode_getattr_maxsz + \ 6521da177e4SLinus Torvalds decode_getfh_maxsz) 6531da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6549b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6551da177e4SLinus Torvalds encode_putfh_maxsz + \ 65656ae19f3STrond Myklebust encode_savefh_maxsz + \ 6571da177e4SLinus Torvalds encode_create_maxsz + \ 65856ae19f3STrond Myklebust encode_getfh_maxsz + \ 6591da177e4SLinus Torvalds encode_getattr_maxsz + \ 66056ae19f3STrond Myklebust encode_restorefh_maxsz + \ 66156ae19f3STrond Myklebust encode_getattr_maxsz) 6621da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 6639b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6641da177e4SLinus Torvalds decode_putfh_maxsz + \ 66556ae19f3STrond Myklebust decode_savefh_maxsz + \ 6661da177e4SLinus Torvalds decode_create_maxsz + \ 66756ae19f3STrond Myklebust decode_getfh_maxsz + \ 6681da177e4SLinus Torvalds decode_getattr_maxsz + \ 66956ae19f3STrond Myklebust decode_restorefh_maxsz + \ 67056ae19f3STrond Myklebust decode_getattr_maxsz) 6711da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 6729b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6731da177e4SLinus Torvalds encode_putfh_maxsz + \ 6741da177e4SLinus Torvalds encode_getattr_maxsz) 6751da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 6769b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6771da177e4SLinus Torvalds decode_putfh_maxsz + \ 6781da177e4SLinus Torvalds decode_getattr_maxsz) 6791da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 6809b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6811da177e4SLinus Torvalds encode_putfh_maxsz + \ 6829104a55dSTrond Myklebust encode_statfs_maxsz) 6831da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 6849b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6851da177e4SLinus Torvalds decode_putfh_maxsz + \ 6869104a55dSTrond Myklebust decode_statfs_maxsz) 6871da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 6889b7b9fccSAndy Adamson encode_sequence_maxsz + \ 689ab91f264STrond Myklebust encode_putfh_maxsz + \ 6901da177e4SLinus Torvalds encode_getattr_maxsz) 6911da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 6929b7b9fccSAndy Adamson decode_sequence_maxsz + \ 693ab91f264STrond Myklebust decode_putfh_maxsz + \ 6941da177e4SLinus Torvalds decode_getattr_maxsz) 6951da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 6969b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6971da177e4SLinus Torvalds encode_putfh_maxsz + \ 698fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 699fa178f29STrond Myklebust encode_getattr_maxsz) 7001da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7019b7b9fccSAndy Adamson decode_sequence_maxsz + \ 702fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 703fa178f29STrond Myklebust decode_getattr_maxsz) 704029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7059b7b9fccSAndy Adamson encode_sequence_maxsz + \ 706029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7079104a55dSTrond Myklebust encode_getacl_maxsz) 708029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7099b7b9fccSAndy Adamson decode_sequence_maxsz + \ 710029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7119104a55dSTrond Myklebust decode_getacl_maxsz) 71223ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7139b7b9fccSAndy Adamson encode_sequence_maxsz + \ 71423ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7159104a55dSTrond Myklebust encode_setacl_maxsz) 71623ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 71823ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7199104a55dSTrond Myklebust decode_setacl_maxsz) 720683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 721683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7229b7b9fccSAndy Adamson encode_sequence_maxsz + \ 723683b57b4STrond Myklebust encode_putfh_maxsz + \ 724e6889620STrond Myklebust encode_lookup_maxsz + \ 725e6889620STrond Myklebust encode_fs_locations_maxsz) 726683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 727683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7289b7b9fccSAndy Adamson decode_sequence_maxsz + \ 729683b57b4STrond Myklebust decode_putfh_maxsz + \ 730e6889620STrond Myklebust decode_lookup_maxsz + \ 731e6889620STrond Myklebust decode_fs_locations_maxsz) 7325a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7335a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7345a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7355a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7365a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7375a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7385a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7395a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 74099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 74199fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 74299fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 74399fe60d0SBenny Halevy encode_exchange_id_maxsz) 74499fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 74599fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 74699fe60d0SBenny Halevy decode_exchange_id_maxsz) 747fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 748fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 749fc931582SAndy Adamson encode_create_session_maxsz) 750fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 751fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 752fc931582SAndy Adamson decode_create_session_maxsz) 7530f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 7540f3e66c6SAndy Adamson encode_destroy_session_maxsz) 7550f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 7560f3e66c6SAndy Adamson decode_destroy_session_maxsz) 757fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 758fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 759fc01cea9SAndy Adamson encode_sequence_maxsz) 760fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 761fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 762fc01cea9SAndy Adamson decode_sequence_maxsz) 7632050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 7642050f0ccSAndy Adamson encode_sequence_maxsz + \ 7652050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 7662050f0ccSAndy Adamson encode_fsinfo_maxsz) 7672050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 7682050f0ccSAndy Adamson decode_sequence_maxsz + \ 7692050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 7702050f0ccSAndy Adamson decode_fsinfo_maxsz) 77118019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 77218019753SRicardo Labiaga encode_sequence_maxsz + \ 77318019753SRicardo Labiaga encode_reclaim_complete_maxsz) 77418019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 77518019753SRicardo Labiaga decode_sequence_maxsz + \ 77618019753SRicardo Labiaga decode_reclaim_complete_maxsz) 7777f11d8d3SAndy Adamson #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \ 7787f11d8d3SAndy Adamson encode_sequence_maxsz + \ 7797f11d8d3SAndy Adamson encode_putfh_maxsz + \ 7807f11d8d3SAndy Adamson encode_getdevicelist_maxsz) 7817f11d8d3SAndy Adamson #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \ 7827f11d8d3SAndy Adamson decode_sequence_maxsz + \ 7837f11d8d3SAndy Adamson decode_putfh_maxsz + \ 7847f11d8d3SAndy Adamson decode_getdevicelist_maxsz) 785b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 786b1f69b75SAndy Adamson encode_sequence_maxsz +\ 787b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 788b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 789b1f69b75SAndy Adamson decode_sequence_maxsz + \ 790b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 791b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 792b1f69b75SAndy Adamson encode_sequence_maxsz + \ 793b1f69b75SAndy Adamson encode_putfh_maxsz + \ 794b1f69b75SAndy Adamson encode_layoutget_maxsz) 795b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 796b1f69b75SAndy Adamson decode_sequence_maxsz + \ 797b1f69b75SAndy Adamson decode_putfh_maxsz + \ 798b1f69b75SAndy Adamson decode_layoutget_maxsz) 799863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 800863a3c6cSAndy Adamson encode_sequence_maxsz +\ 801863a3c6cSAndy Adamson encode_putfh_maxsz + \ 802863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 803863a3c6cSAndy Adamson encode_getattr_maxsz) 804863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 805863a3c6cSAndy Adamson decode_sequence_maxsz + \ 806863a3c6cSAndy Adamson decode_putfh_maxsz + \ 807863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 808863a3c6cSAndy Adamson decode_getattr_maxsz) 809cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 810cbe82603SBenny Halevy encode_sequence_maxsz + \ 811cbe82603SBenny Halevy encode_putfh_maxsz + \ 812cbe82603SBenny Halevy encode_layoutreturn_maxsz) 813cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 814cbe82603SBenny Halevy decode_sequence_maxsz + \ 815cbe82603SBenny Halevy decode_putfh_maxsz + \ 816cbe82603SBenny Halevy decode_layoutreturn_maxsz) 817fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 818fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 819fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 820fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 821fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 822fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 823fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 824fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8257d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8267d974794SBryan Schumaker encode_sequence_maxsz + \ 8277d974794SBryan Schumaker encode_test_stateid_maxsz) 8287d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8297d974794SBryan Schumaker decode_sequence_maxsz + \ 8307d974794SBryan Schumaker decode_test_stateid_maxsz) 8319aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8329aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8339aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8349aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8359aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8369aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8372449ea2eSAlexandros Batsakis 8382449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8392449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8402449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8412449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8422449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8432449ea2eSAlexandros Batsakis XDR_UNIT); 8442449ea2eSAlexandros Batsakis 8452449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8462449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 8472449ea2eSAlexandros Batsakis decode_sequence_maxsz + 8482449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 8492449ea2eSAlexandros Batsakis XDR_UNIT); 85099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 8511da177e4SLinus Torvalds 852db8ac8baSWeston Andros Adamson static unsigned short send_implementation_id = 1; 853db8ac8baSWeston Andros Adamson 854db8ac8baSWeston Andros Adamson module_param(send_implementation_id, ushort, 0644); 855db8ac8baSWeston Andros Adamson MODULE_PARM_DESC(send_implementation_id, 856db8ac8baSWeston Andros Adamson "Send implementation ID with NFSv4.1 exchange_id"); 857db8ac8baSWeston Andros Adamson 858bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 859bca79478STrond Myklebust [NF4BAD] = 0, 860bca79478STrond Myklebust [NF4REG] = S_IFREG, 861bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 862bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 863bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 864bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 865bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 866bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 867bca79478STrond Myklebust [NF4ATTRDIR] = 0, 868bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 8691da177e4SLinus Torvalds }; 8701da177e4SLinus Torvalds 8711da177e4SLinus Torvalds struct compound_hdr { 8721da177e4SLinus Torvalds int32_t status; 8731da177e4SLinus Torvalds uint32_t nops; 874d017931cSAndy Adamson __be32 * nops_p; 8751da177e4SLinus Torvalds uint32_t taglen; 8761da177e4SLinus Torvalds char * tag; 8770c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 87866cc0429SBenny Halevy u32 minorversion; 8791da177e4SLinus Torvalds }; 8801da177e4SLinus Torvalds 88113c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 88213c65ce9SBenny Halevy { 88313c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 88413c65ce9SBenny Halevy BUG_ON(!p); 88513c65ce9SBenny Halevy return p; 88613c65ce9SBenny Halevy } 8871da177e4SLinus Torvalds 888cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 889cb17e556STrond Myklebust { 890cb17e556STrond Myklebust __be32 *p; 891cb17e556STrond Myklebust 892cb17e556STrond Myklebust p = xdr_reserve_space(xdr, len); 893cb17e556STrond Myklebust xdr_encode_opaque_fixed(p, buf, len); 894cb17e556STrond Myklebust } 895cb17e556STrond Myklebust 8961da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 8971da177e4SLinus Torvalds { 8988687b63aSAl Viro __be32 *p; 8991da177e4SLinus Torvalds 9006fdfb0bcSTrond Myklebust p = reserve_space(xdr, 4 + len); 9011da177e4SLinus Torvalds xdr_encode_opaque(p, str, len); 9021da177e4SLinus Torvalds } 9031da177e4SLinus Torvalds 9044ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9054ade9821STrond Myklebust { 9064ade9821STrond Myklebust __be32 *p; 9074ade9821STrond Myklebust 9084ade9821STrond Myklebust p = reserve_space(xdr, 4); 9094ade9821STrond Myklebust *p = cpu_to_be32(n); 9104ade9821STrond Myklebust } 9114ade9821STrond Myklebust 9124ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9134ade9821STrond Myklebust const struct nfs_seqid *seqid) 9144ade9821STrond Myklebust { 9154ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 9164ade9821STrond Myklebust } 9174ade9821STrond Myklebust 9180c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9190c4e8c18SBenny Halevy struct rpc_rqst *req, 9200c4e8c18SBenny Halevy struct compound_hdr *hdr) 9211da177e4SLinus Torvalds { 9228687b63aSAl Viro __be32 *p; 923a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9240c4e8c18SBenny Halevy 9250c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9260c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9270c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9280c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9291da177e4SLinus Torvalds 9301da177e4SLinus Torvalds BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 9316fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9326fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 933e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 934d017931cSAndy Adamson hdr->nops_p = p; 93534558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 936d017931cSAndy Adamson } 937d017931cSAndy Adamson 938ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 939ab19b481STrond Myklebust uint32_t replen, 940ab19b481STrond Myklebust struct compound_hdr *hdr) 941ab19b481STrond Myklebust { 942ab19b481STrond Myklebust encode_uint32(xdr, op); 943ab19b481STrond Myklebust hdr->nops++; 944ab19b481STrond Myklebust hdr->replen += replen; 945ab19b481STrond Myklebust } 946ab19b481STrond Myklebust 947d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 948d017931cSAndy Adamson { 949fc931582SAndy Adamson BUG_ON(hdr->nops > NFS4_MAX_OPS); 950d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 9511da177e4SLinus Torvalds } 9521da177e4SLinus Torvalds 953ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 954ea9d23f5STrond Myklebust { 9552d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 956ea9d23f5STrond Myklebust } 957ea9d23f5STrond Myklebust 9581da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 9591da177e4SLinus Torvalds { 960cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 9611da177e4SLinus Torvalds } 9621da177e4SLinus Torvalds 963cf8cdbe5SAndy Adamson static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) 9641da177e4SLinus Torvalds { 9651da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 9661da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 9671da177e4SLinus Torvalds int owner_namelen = 0; 9681da177e4SLinus Torvalds int owner_grouplen = 0; 9698687b63aSAl Viro __be32 *p; 9708687b63aSAl Viro __be32 *q; 9711da177e4SLinus Torvalds int len; 9721da177e4SLinus Torvalds uint32_t bmval0 = 0; 9731da177e4SLinus Torvalds uint32_t bmval1 = 0; 9741da177e4SLinus Torvalds 9751da177e4SLinus Torvalds /* 9761da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 9771da177e4SLinus Torvalds * In the worst-case, this would be 9781da177e4SLinus Torvalds * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 9791da177e4SLinus Torvalds * = 36 bytes, plus any contribution from variable-length fields 98023ec6965SJ. Bruce Fields * such as owner/group. 9811da177e4SLinus Torvalds */ 9821da177e4SLinus Torvalds len = 16; 9831da177e4SLinus Torvalds 9841da177e4SLinus Torvalds /* Sigh */ 9851da177e4SLinus Torvalds if (iap->ia_valid & ATTR_SIZE) 9861da177e4SLinus Torvalds len += 8; 9871da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MODE) 9881da177e4SLinus Torvalds len += 4; 9891da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 990e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 9911da177e4SLinus Torvalds if (owner_namelen < 0) { 992fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 9931da177e4SLinus Torvalds iap->ia_uid); 9941da177e4SLinus Torvalds /* XXX */ 9951da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 9961da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 9971da177e4SLinus Torvalds /* goto out; */ 9981da177e4SLinus Torvalds } 9991da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10001da177e4SLinus Torvalds } 10011da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 1002e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10031da177e4SLinus Torvalds if (owner_grouplen < 0) { 1004fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 10051da177e4SLinus Torvalds iap->ia_gid); 10061da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10071da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10081da177e4SLinus Torvalds /* goto out; */ 10091da177e4SLinus Torvalds } 10101da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10111da177e4SLinus Torvalds } 10121da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) 10131da177e4SLinus Torvalds len += 16; 10141da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_ATIME) 10151da177e4SLinus Torvalds len += 4; 10161da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) 10171da177e4SLinus Torvalds len += 16; 10181da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_MTIME) 10191da177e4SLinus Torvalds len += 4; 102013c65ce9SBenny Halevy p = reserve_space(xdr, len); 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds /* 10231da177e4SLinus Torvalds * We write the bitmap length now, but leave the bitmap and the attribute 10241da177e4SLinus Torvalds * buffer length to be backfilled at the end of this routine. 10251da177e4SLinus Torvalds */ 1026e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 10271da177e4SLinus Torvalds q = p; 10281da177e4SLinus Torvalds p += 3; 10291da177e4SLinus Torvalds 10301da177e4SLinus Torvalds if (iap->ia_valid & ATTR_SIZE) { 10311da177e4SLinus Torvalds bmval0 |= FATTR4_WORD0_SIZE; 1032b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 10331da177e4SLinus Torvalds } 10341da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MODE) { 10351da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_MODE; 1036e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 10371da177e4SLinus Torvalds } 10381da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 10391da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_OWNER; 1040811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 10411da177e4SLinus Torvalds } 10421da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 10431da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_OWNER_GROUP; 1044811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 10451da177e4SLinus Torvalds } 10461da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 10471da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 1048e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1049e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 1050d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_sec); 1051d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 10521da177e4SLinus Torvalds } 10531da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_ATIME) { 10541da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 1055e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 10561da177e4SLinus Torvalds } 10571da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 10581da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 1059e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1060e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 1061e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_sec); 1062e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 10631da177e4SLinus Torvalds } 10641da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_MTIME) { 10651da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 1066e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 10671da177e4SLinus Torvalds } 10681da177e4SLinus Torvalds 10691da177e4SLinus Torvalds /* 10701da177e4SLinus Torvalds * Now we backfill the bitmap and the attribute buffer length. 10711da177e4SLinus Torvalds */ 10721da177e4SLinus Torvalds if (len != ((char *)p - (char *)q) + 4) { 1073f9fd2d9cSWeston Andros Adamson printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n", 10741da177e4SLinus Torvalds len, ((char *)p - (char *)q) + 4); 10751da177e4SLinus Torvalds BUG(); 10761da177e4SLinus Torvalds } 10771da177e4SLinus Torvalds len = (char *)p - (char *)q - 12; 10781da177e4SLinus Torvalds *q++ = htonl(bmval0); 10791da177e4SLinus Torvalds *q++ = htonl(bmval1); 108034558513SBenny Halevy *q = htonl(len); 10811da177e4SLinus Torvalds 10821da177e4SLinus Torvalds /* out: */ 10831da177e4SLinus Torvalds } 10841da177e4SLinus Torvalds 1085cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 10861da177e4SLinus Torvalds { 10878687b63aSAl Viro __be32 *p; 10881da177e4SLinus Torvalds 108913c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1090e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_ACCESS); 109134558513SBenny Halevy *p = cpu_to_be32(access); 1092d017931cSAndy Adamson hdr->nops++; 1093dadf0c27SBenny Halevy hdr->replen += decode_access_maxsz; 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 1103cf8cdbe5SAndy Adamson static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 11041da177e4SLinus Torvalds { 11058687b63aSAl Viro __be32 *p; 11061da177e4SLinus Torvalds 110713c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1108e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_COMMIT); 1109b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 111034558513SBenny Halevy *p = cpu_to_be32(args->count); 1111d017931cSAndy Adamson hdr->nops++; 1112dadf0c27SBenny Halevy hdr->replen += decode_commit_maxsz; 11131da177e4SLinus Torvalds } 11141da177e4SLinus Torvalds 1115cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11161da177e4SLinus Torvalds { 11178687b63aSAl Viro __be32 *p; 11181da177e4SLinus Torvalds 111913c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1120e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_CREATE); 112134558513SBenny Halevy *p = cpu_to_be32(create->ftype); 11221da177e4SLinus Torvalds 11231da177e4SLinus Torvalds switch (create->ftype) { 11241da177e4SLinus Torvalds case NF4LNK: 112513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 112634558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 112794a6d753SChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 11281da177e4SLinus Torvalds break; 11291da177e4SLinus Torvalds 11301da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 113113c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1132e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 113334558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11341da177e4SLinus Torvalds break; 11351da177e4SLinus Torvalds 11361da177e4SLinus Torvalds default: 11371da177e4SLinus Torvalds break; 11381da177e4SLinus Torvalds } 11391da177e4SLinus Torvalds 1140811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 1141d017931cSAndy Adamson hdr->nops++; 1142dadf0c27SBenny Halevy hdr->replen += decode_create_maxsz; 11431da177e4SLinus Torvalds 1144cf8cdbe5SAndy Adamson encode_attrs(xdr, create->attrs, create->server); 11451da177e4SLinus Torvalds } 11461da177e4SLinus Torvalds 1147cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11481da177e4SLinus Torvalds { 11498687b63aSAl Viro __be32 *p; 11501da177e4SLinus Torvalds 115113c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1152e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_GETATTR); 1153e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 115434558513SBenny Halevy *p = cpu_to_be32(bitmap); 1155d017931cSAndy Adamson hdr->nops++; 1156dadf0c27SBenny Halevy hdr->replen += decode_getattr_maxsz; 11571da177e4SLinus Torvalds } 11581da177e4SLinus Torvalds 1159cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 11601da177e4SLinus Torvalds { 11618687b63aSAl Viro __be32 *p; 11621da177e4SLinus Torvalds 116313c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1164e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_GETATTR); 1165e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1166e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 116734558513SBenny Halevy *p = cpu_to_be32(bm1); 1168d017931cSAndy Adamson hdr->nops++; 1169dadf0c27SBenny Halevy hdr->replen += decode_getattr_maxsz; 11701da177e4SLinus Torvalds } 11711da177e4SLinus Torvalds 1172dae100c2SFred Isaman static void 1173dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1174dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1175dae100c2SFred Isaman struct compound_hdr *hdr) 1176dae100c2SFred Isaman { 1177dae100c2SFred Isaman __be32 *p; 1178dae100c2SFred Isaman 1179ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1180dae100c2SFred Isaman if (bm2) { 1181dae100c2SFred Isaman p = reserve_space(xdr, 16); 1182dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1183dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1184dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1185dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1186dae100c2SFred Isaman } else if (bm1) { 1187dae100c2SFred Isaman p = reserve_space(xdr, 12); 1188dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1189dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1190dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1191dae100c2SFred Isaman } else { 1192dae100c2SFred Isaman p = reserve_space(xdr, 8); 1193dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1194dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1195dae100c2SFred Isaman } 1196dae100c2SFred Isaman } 1197dae100c2SFred Isaman 1198cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 11991da177e4SLinus Torvalds { 1200cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1201d017931cSAndy Adamson bitmask[1] & nfs4_fattr_bitmap[1], hdr); 12021da177e4SLinus Torvalds } 12031da177e4SLinus Torvalds 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 126413c65ce9SBenny Halevy p = reserve_space(xdr, 32); 1265e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_LOCK); 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 } 1281d017931cSAndy Adamson hdr->nops++; 1282dadf0c27SBenny Halevy hdr->replen += decode_lock_maxsz; 12831da177e4SLinus Torvalds } 12841da177e4SLinus Torvalds 1285cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 12861da177e4SLinus Torvalds { 12878687b63aSAl Viro __be32 *p; 12881da177e4SLinus Torvalds 1289daccbdedSTrond Myklebust p = reserve_space(xdr, 24); 1290e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_LOCKT); 1291e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1292b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1293b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1294daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 1295d017931cSAndy Adamson hdr->nops++; 1296dadf0c27SBenny Halevy hdr->replen += decode_lockt_maxsz; 12971da177e4SLinus Torvalds } 12981da177e4SLinus Torvalds 1299cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13001da177e4SLinus Torvalds { 13018687b63aSAl Viro __be32 *p; 13021da177e4SLinus Torvalds 13034ade9821STrond Myklebust p = reserve_space(xdr, 8); 1304e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_LOCKU); 13054ade9821STrond Myklebust *p = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 13064ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1307ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 1308ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1309b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 131034558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1311d017931cSAndy Adamson hdr->nops++; 1312dadf0c27SBenny Halevy hdr->replen += decode_locku_maxsz; 13131da177e4SLinus Torvalds } 13141da177e4SLinus Torvalds 1315d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1316d3c7b7ccSTrond Myklebust { 1317ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1318d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1319d3c7b7ccSTrond Myklebust } 1320d3c7b7ccSTrond Myklebust 1321cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13221da177e4SLinus Torvalds { 1323ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13246fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13251da177e4SLinus Torvalds } 13261da177e4SLinus Torvalds 1327dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 13281da177e4SLinus Torvalds { 13298687b63aSAl Viro __be32 *p; 13301da177e4SLinus Torvalds 133113c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1332dc0b027dSTrond Myklebust switch (fmode & (FMODE_READ|FMODE_WRITE)) { 13331da177e4SLinus Torvalds case FMODE_READ: 1334e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 13351da177e4SLinus Torvalds break; 13361da177e4SLinus Torvalds case FMODE_WRITE: 1337e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 13381da177e4SLinus Torvalds break; 13391da177e4SLinus Torvalds case FMODE_READ|FMODE_WRITE: 1340e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 13411da177e4SLinus Torvalds break; 13421da177e4SLinus Torvalds default: 1343e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 13441da177e4SLinus Torvalds } 134534558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13461da177e4SLinus Torvalds } 13471da177e4SLinus Torvalds 13481da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13491da177e4SLinus Torvalds { 13508687b63aSAl Viro __be32 *p; 13511da177e4SLinus Torvalds /* 13521da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13531da177e4SLinus Torvalds * owner 4 = 32 13541da177e4SLinus Torvalds */ 13554ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1356dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 1357d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1358b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 1359d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 136093f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1361d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 136234558513SBenny Halevy xdr_encode_hyper(p, arg->id); 13631da177e4SLinus Torvalds } 13641da177e4SLinus Torvalds 13651da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13661da177e4SLinus Torvalds { 13678687b63aSAl Viro __be32 *p; 13684882ef72SAlexandros Batsakis struct nfs_client *clp; 13691da177e4SLinus Torvalds 137013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13711da177e4SLinus Torvalds switch(arg->open_flags & O_EXCL) { 13721da177e4SLinus Torvalds case 0: 137334558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 13741da177e4SLinus Torvalds encode_attrs(xdr, arg->u.attrs, arg->server); 13751da177e4SLinus Torvalds break; 13761da177e4SLinus Torvalds default: 13774882ef72SAlexandros Batsakis clp = arg->server->nfs_client; 1378a4432345STrond Myklebust if (clp->cl_mvops->minor_version > 0) { 13794882ef72SAlexandros Batsakis if (nfs4_has_persistent_session(clp)) { 13804882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 13814882ef72SAlexandros Batsakis encode_attrs(xdr, arg->u.attrs, arg->server); 13824882ef72SAlexandros Batsakis } else { 13834882ef72SAlexandros Batsakis struct iattr dummy; 13844882ef72SAlexandros Batsakis 13854882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 13864882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 13874882ef72SAlexandros Batsakis dummy.ia_valid = 0; 13884882ef72SAlexandros Batsakis encode_attrs(xdr, &dummy, arg->server); 13894882ef72SAlexandros Batsakis } 13904882ef72SAlexandros Batsakis } else { 139134558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 13921da177e4SLinus Torvalds encode_nfs4_verifier(xdr, &arg->u.verifier); 13931da177e4SLinus Torvalds } 13941da177e4SLinus Torvalds } 13954882ef72SAlexandros Batsakis } 13961da177e4SLinus Torvalds 13971da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13981da177e4SLinus Torvalds { 13998687b63aSAl Viro __be32 *p; 14001da177e4SLinus Torvalds 140113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14021da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14031da177e4SLinus Torvalds case 0: 140434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14051da177e4SLinus Torvalds break; 14061da177e4SLinus Torvalds default: 14071da177e4SLinus Torvalds BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 140834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14091da177e4SLinus Torvalds encode_createmode(xdr, arg); 14101da177e4SLinus Torvalds } 14111da177e4SLinus Torvalds } 14121da177e4SLinus Torvalds 1413bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14141da177e4SLinus Torvalds { 14158687b63aSAl Viro __be32 *p; 14161da177e4SLinus Torvalds 141713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14181da177e4SLinus Torvalds switch (delegation_type) { 14191da177e4SLinus Torvalds case 0: 142034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14211da177e4SLinus Torvalds break; 14221da177e4SLinus Torvalds case FMODE_READ: 142334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14241da177e4SLinus Torvalds break; 14251da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 142634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14271da177e4SLinus Torvalds break; 14281da177e4SLinus Torvalds default: 14291da177e4SLinus Torvalds BUG(); 14301da177e4SLinus Torvalds } 14311da177e4SLinus Torvalds } 14321da177e4SLinus Torvalds 14331da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14341da177e4SLinus Torvalds { 14358687b63aSAl Viro __be32 *p; 14361da177e4SLinus Torvalds 143713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 143834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14391da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14401da177e4SLinus Torvalds } 14411da177e4SLinus Torvalds 1442bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14431da177e4SLinus Torvalds { 14448687b63aSAl Viro __be32 *p; 14451da177e4SLinus Torvalds 144613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 144734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14481da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14491da177e4SLinus Torvalds } 14501da177e4SLinus Torvalds 14511da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14521da177e4SLinus Torvalds { 14538687b63aSAl Viro __be32 *p; 14541da177e4SLinus Torvalds 1455ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1456ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1457ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14581da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14591da177e4SLinus Torvalds } 14601da177e4SLinus Torvalds 1461cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 14621da177e4SLinus Torvalds { 1463ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 14641da177e4SLinus Torvalds encode_openhdr(xdr, arg); 14651da177e4SLinus Torvalds encode_opentype(xdr, arg); 14661da177e4SLinus Torvalds switch (arg->claim) { 14671da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 14681da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 14691da177e4SLinus Torvalds break; 14701da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 14711da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 14721da177e4SLinus Torvalds break; 14731da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 14741da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 14751da177e4SLinus Torvalds break; 14761da177e4SLinus Torvalds default: 14771da177e4SLinus Torvalds BUG(); 14781da177e4SLinus Torvalds } 14791da177e4SLinus Torvalds } 14801da177e4SLinus Torvalds 1481cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 14821da177e4SLinus Torvalds { 1483ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1484ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14854ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14861da177e4SLinus Torvalds } 14871da177e4SLinus Torvalds 1488cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 14891da177e4SLinus Torvalds { 1490ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1491ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14924ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1493dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 14941da177e4SLinus Torvalds } 14951da177e4SLinus Torvalds 1496cf8cdbe5SAndy Adamson static void 1497d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 14981da177e4SLinus Torvalds { 1499ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15006fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15011da177e4SLinus Torvalds } 15021da177e4SLinus Torvalds 1503cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15041da177e4SLinus Torvalds { 1505ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds 1508d0b496d2STrond Myklebust static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid) 15091da177e4SLinus Torvalds { 15101da177e4SLinus Torvalds nfs4_stateid stateid; 15111da177e4SLinus Torvalds 15121da177e4SLinus Torvalds if (ctx->state != NULL) { 15131e3987c3STrond Myklebust nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid); 151489d1ea65SAndy Adamson if (zero_seqid) 15152d2f24adSTrond Myklebust stateid.seqid = 0; 1516ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &stateid); 15171da177e4SLinus Torvalds } else 1518ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 15191da177e4SLinus Torvalds } 15201da177e4SLinus Torvalds 1521cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 15221da177e4SLinus Torvalds { 15238687b63aSAl Viro __be32 *p; 15241da177e4SLinus Torvalds 1525ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 1526d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 152789d1ea65SAndy Adamson hdr->minorversion); 15281da177e4SLinus Torvalds 152913c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1530b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 153134558513SBenny Halevy *p = cpu_to_be32(args->count); 15321da177e4SLinus Torvalds } 15331da177e4SLinus Torvalds 1534cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15351da177e4SLinus Torvalds { 153628331a46STrond Myklebust uint32_t attrs[2] = { 153728331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 153828331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 153928331a46STrond Myklebust }; 15406f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1541cd93710eSChuck Lever __be32 *p, verf[2]; 15421da177e4SLinus Torvalds 154382f2e547SBryan Schumaker if (readdir->plus) { 154482f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 154528331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 154682f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 154782f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 154882f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 154982f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 15506f7a35bdSTrond Myklebust dircount >>= 1; 155182f2e547SBryan Schumaker } 155228331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 155328331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 155428331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 15556f7a35bdSTrond Myklebust 1556cd93710eSChuck Lever p = reserve_space(xdr, 12); 15576f7a35bdSTrond Myklebust *p++ = cpu_to_be32(OP_READDIR); 15586f7a35bdSTrond Myklebust p = xdr_encode_hyper(p, readdir->cookie); 1559cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1560cd93710eSChuck Lever p = reserve_space(xdr, 20); 15616f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 15626f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 15636f7a35bdSTrond Myklebust *p++ = cpu_to_be32(2); 156482f2e547SBryan Schumaker 1565e75bc1c8SBenny Halevy *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 156634558513SBenny Halevy *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1567d017931cSAndy Adamson hdr->nops++; 1568dadf0c27SBenny Halevy hdr->replen += decode_readdir_maxsz; 1569cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 157044109241SFred Isaman dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 157144109241SFred Isaman __func__, 1572eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1573cd93710eSChuck Lever verf[0], verf[1], 1574eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1575eadf4598STrond Myklebust attrs[1] & readdir->bitmask[1]); 15761da177e4SLinus Torvalds } 15771da177e4SLinus Torvalds 1578cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 15791da177e4SLinus Torvalds { 1580ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 15811da177e4SLinus Torvalds } 15821da177e4SLinus Torvalds 1583cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 15841da177e4SLinus Torvalds { 1585ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 15866fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 15871da177e4SLinus Torvalds } 15881da177e4SLinus Torvalds 1589cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 15901da177e4SLinus Torvalds { 1591ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1592811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1593811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 15941da177e4SLinus Torvalds } 15951da177e4SLinus Torvalds 1596bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1597bb4dae5eSChuck Lever struct compound_hdr *hdr) 15981da177e4SLinus Torvalds { 15998687b63aSAl Viro __be32 *p; 16001da177e4SLinus Torvalds 160113c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1602e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_RENEW); 1603bb4dae5eSChuck Lever xdr_encode_hyper(p, clid); 1604d017931cSAndy Adamson hdr->nops++; 1605dadf0c27SBenny Halevy hdr->replen += decode_renew_maxsz; 16061da177e4SLinus Torvalds } 16071da177e4SLinus Torvalds 1608cf8cdbe5SAndy Adamson static void 1609d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 161056ae19f3STrond Myklebust { 1611ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 161256ae19f3STrond Myklebust } 161356ae19f3STrond Myklebust 16149f06c719SChuck Lever static void 1615d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 161623ec6965SJ. Bruce Fields { 16178687b63aSAl Viro __be32 *p; 161823ec6965SJ. Bruce Fields 1619ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1620ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 162113c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1622e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 162334558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 16249f06c719SChuck Lever BUG_ON(arg->acl_len % 4); 162513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 162634558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 162723ec6965SJ. Bruce Fields xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 162823ec6965SJ. Bruce Fields } 162923ec6965SJ. Bruce Fields 1630cf8cdbe5SAndy Adamson static void 1631d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16321da177e4SLinus Torvalds { 1633ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16341da177e4SLinus Torvalds } 16351da177e4SLinus Torvalds 1636cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16371da177e4SLinus Torvalds { 1638ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1639ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1640cf8cdbe5SAndy Adamson encode_attrs(xdr, arg->iap, server); 16411da177e4SLinus Torvalds } 16421da177e4SLinus Torvalds 1643cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16441da177e4SLinus Torvalds { 16458687b63aSAl Viro __be32 *p; 16461da177e4SLinus Torvalds 1647cd93710eSChuck Lever p = reserve_space(xdr, 4); 1648cd93710eSChuck Lever *p = cpu_to_be32(OP_SETCLIENTID); 1649cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16501da177e4SLinus Torvalds 16511da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 165213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 165334558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16541da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16551da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 165613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 165734558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_cb_ident); 1658d017931cSAndy Adamson hdr->nops++; 1659dadf0c27SBenny Halevy hdr->replen += decode_setclientid_maxsz; 16601da177e4SLinus Torvalds } 16611da177e4SLinus Torvalds 1662bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16631da177e4SLinus Torvalds { 16648687b63aSAl Viro __be32 *p; 16651da177e4SLinus Torvalds 1666cd93710eSChuck Lever p = reserve_space(xdr, 12); 1667e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM); 1668bb8b27e5STrond Myklebust p = xdr_encode_hyper(p, arg->clientid); 1669cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 1670d017931cSAndy Adamson hdr->nops++; 1671dadf0c27SBenny Halevy hdr->replen += decode_setclientid_confirm_maxsz; 16721da177e4SLinus Torvalds } 16731da177e4SLinus Torvalds 1674cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 16751da177e4SLinus Torvalds { 16768687b63aSAl Viro __be32 *p; 16771da177e4SLinus Torvalds 1678ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 1679d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 168089d1ea65SAndy Adamson hdr->minorversion); 16811da177e4SLinus Torvalds 168213c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1683b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1684e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 168534558513SBenny Halevy *p = cpu_to_be32(args->count); 16861da177e4SLinus Torvalds 16871da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 16881da177e4SLinus Torvalds } 16891da177e4SLinus Torvalds 1690cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 16911da177e4SLinus Torvalds { 1692ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1693ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 16941da177e4SLinus Torvalds } 16959b7b9fccSAndy Adamson 16965a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16975a5ea0d4SBryan Schumaker { 1698ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 16996fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17005a5ea0d4SBryan Schumaker } 17015a5ea0d4SBryan Schumaker 170299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17039b7b9fccSAndy Adamson /* NFSv4.1 operations */ 170499fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 170599fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 170699fe60d0SBenny Halevy struct compound_hdr *hdr) 170799fe60d0SBenny Halevy { 170899fe60d0SBenny Halevy __be32 *p; 1709db8ac8baSWeston Andros Adamson char impl_name[NFS4_OPAQUE_LIMIT]; 1710db8ac8baSWeston Andros Adamson int len = 0; 171199fe60d0SBenny Halevy 1712cd93710eSChuck Lever p = reserve_space(xdr, 4); 1713cd93710eSChuck Lever *p = cpu_to_be32(OP_EXCHANGE_ID); 1714cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 171599fe60d0SBenny Halevy 171699fe60d0SBenny Halevy encode_string(xdr, args->id_len, args->id); 171799fe60d0SBenny Halevy 171813c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1719e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); 1720e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1721db8ac8baSWeston Andros Adamson 1722db8ac8baSWeston Andros Adamson if (send_implementation_id && 1723db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1724db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1725db8ac8baSWeston Andros Adamson <= NFS4_OPAQUE_LIMIT + 1) 1726db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1727db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1728db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1729db8ac8baSWeston Andros Adamson 1730db8ac8baSWeston Andros Adamson if (len > 0) { 1731db8ac8baSWeston Andros Adamson *p = cpu_to_be32(1); /* implementation id array length=1 */ 1732db8ac8baSWeston Andros Adamson 1733db8ac8baSWeston Andros Adamson encode_string(xdr, 1734db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1735db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1736db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1737db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1738db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1739db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1740db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1741db8ac8baSWeston Andros Adamson } else 1742db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); /* implementation id array length=0 */ 1743db8ac8baSWeston Andros Adamson 174499fe60d0SBenny Halevy hdr->nops++; 174599fe60d0SBenny Halevy hdr->replen += decode_exchange_id_maxsz; 174699fe60d0SBenny Halevy } 1747fc931582SAndy Adamson 1748fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1749fc931582SAndy Adamson struct nfs41_create_session_args *args, 1750fc931582SAndy Adamson struct compound_hdr *hdr) 1751fc931582SAndy Adamson { 1752fc931582SAndy Adamson __be32 *p; 1753fc931582SAndy Adamson char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1754fc931582SAndy Adamson uint32_t len; 1755fc931582SAndy Adamson struct nfs_client *clp = args->client; 17568e0d46e1SMike Sager u32 max_resp_sz_cached; 17578e0d46e1SMike Sager 17588e0d46e1SMike Sager /* 17598e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 17608e0d46e1SMike Sager * 2 is the verifier. 17618e0d46e1SMike Sager */ 17628e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 17638e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1764fc931582SAndy Adamson 1765fc931582SAndy Adamson len = scnprintf(machine_name, sizeof(machine_name), "%s", 1766fc931582SAndy Adamson clp->cl_ipaddr); 176742edd698SBenny Halevy 176813c65ce9SBenny Halevy p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12); 1769e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_CREATE_SESSION); 1770114f64b5SAndy Adamson p = xdr_encode_hyper(p, clp->cl_clientid); 1771e75bc1c8SBenny Halevy *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1772e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1773fc931582SAndy Adamson 1774fc931582SAndy Adamson /* Fore Channel */ 1775c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1776e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1777e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 17788e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1779e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1780e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1781e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1782fc931582SAndy Adamson 1783fc931582SAndy Adamson /* Back Channel */ 1784c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1785e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1786e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1787e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1788e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1789e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1790e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1791fc931582SAndy Adamson 1792e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1793e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1794e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1795fc931582SAndy Adamson 1796fc931582SAndy Adamson /* authsys_parms rfc1831 */ 1797e75bc1c8SBenny Halevy *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ 1798811652bdSBenny Halevy p = xdr_encode_opaque(p, machine_name, len); 1799e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1800e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 180134558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1802fc931582SAndy Adamson hdr->nops++; 1803fc931582SAndy Adamson hdr->replen += decode_create_session_maxsz; 1804fc931582SAndy Adamson } 18050f3e66c6SAndy Adamson 18060f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 18070f3e66c6SAndy Adamson struct nfs4_session *session, 18080f3e66c6SAndy Adamson struct compound_hdr *hdr) 18090f3e66c6SAndy Adamson { 18100f3e66c6SAndy Adamson __be32 *p; 181113c65ce9SBenny Halevy p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN); 1812e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_DESTROY_SESSION); 181334558513SBenny Halevy xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18140f3e66c6SAndy Adamson hdr->nops++; 18150f3e66c6SAndy Adamson hdr->replen += decode_destroy_session_maxsz; 18160f3e66c6SAndy Adamson } 181718019753SRicardo Labiaga 181818019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 181918019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 182018019753SRicardo Labiaga struct compound_hdr *hdr) 182118019753SRicardo Labiaga { 182218019753SRicardo Labiaga __be32 *p; 182318019753SRicardo Labiaga 182418019753SRicardo Labiaga p = reserve_space(xdr, 8); 182518019753SRicardo Labiaga *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE); 182618019753SRicardo Labiaga *p++ = cpu_to_be32(args->one_fs); 182718019753SRicardo Labiaga hdr->nops++; 182818019753SRicardo Labiaga hdr->replen += decode_reclaim_complete_maxsz; 182918019753SRicardo Labiaga } 183099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 183199fe60d0SBenny Halevy 18329b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18339b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18349b7b9fccSAndy Adamson struct compound_hdr *hdr) 18359b7b9fccSAndy Adamson { 18369b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18379b7b9fccSAndy Adamson struct nfs4_session *session = args->sa_session; 1838fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 1839fc01cea9SAndy Adamson struct nfs4_slot *slot; 1840fc01cea9SAndy Adamson __be32 *p; 18419b7b9fccSAndy Adamson 18429b7b9fccSAndy Adamson if (!session) 18439b7b9fccSAndy Adamson return; 18449b7b9fccSAndy Adamson 1845fc01cea9SAndy Adamson tp = &session->fc_slot_table; 1846fc01cea9SAndy Adamson 1847fc01cea9SAndy Adamson WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1848fc01cea9SAndy Adamson slot = tp->slots + args->sa_slotid; 1849fc01cea9SAndy Adamson 185013c65ce9SBenny Halevy p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16); 1851e75bc1c8SBenny Halevy *p++ = cpu_to_be32(OP_SEQUENCE); 1852fc01cea9SAndy Adamson 1853fc01cea9SAndy Adamson /* 1854fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1855fc01cea9SAndy Adamson */ 1856fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1857fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1858fc01cea9SAndy Adamson __func__, 1859fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1860fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1861fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1862fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 1863fc01cea9SAndy Adamson slot->seq_nr, args->sa_slotid, 1864fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 186593f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1866e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 1867e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->sa_slotid); 1868e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 186934558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 18709b7b9fccSAndy Adamson hdr->nops++; 18719b7b9fccSAndy Adamson hdr->replen += decode_sequence_maxsz; 18729b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 18739b7b9fccSAndy Adamson } 18749b7b9fccSAndy Adamson 1875b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1876b1f69b75SAndy Adamson static void 18777f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr, 18787f11d8d3SAndy Adamson const struct nfs4_getdevicelist_args *args, 18797f11d8d3SAndy Adamson struct compound_hdr *hdr) 18807f11d8d3SAndy Adamson { 18817f11d8d3SAndy Adamson __be32 *p; 18827f11d8d3SAndy Adamson nfs4_verifier dummy = { 18837f11d8d3SAndy Adamson .data = "dummmmmy", 18847f11d8d3SAndy Adamson }; 18857f11d8d3SAndy Adamson 18867f11d8d3SAndy Adamson p = reserve_space(xdr, 20); 18877f11d8d3SAndy Adamson *p++ = cpu_to_be32(OP_GETDEVICELIST); 18887f11d8d3SAndy Adamson *p++ = cpu_to_be32(args->layoutclass); 18897f11d8d3SAndy Adamson *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 18907f11d8d3SAndy Adamson xdr_encode_hyper(p, 0ULL); /* cookie */ 18917f11d8d3SAndy Adamson encode_nfs4_verifier(xdr, &dummy); 18927f11d8d3SAndy Adamson hdr->nops++; 18937f11d8d3SAndy Adamson hdr->replen += decode_getdevicelist_maxsz; 18947f11d8d3SAndy Adamson } 18957f11d8d3SAndy Adamson 18967f11d8d3SAndy Adamson static void 1897b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1898b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1899b1f69b75SAndy Adamson struct compound_hdr *hdr) 1900b1f69b75SAndy Adamson { 1901b1f69b75SAndy Adamson __be32 *p; 1902b1f69b75SAndy Adamson 1903b1f69b75SAndy Adamson p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE); 1904b1f69b75SAndy Adamson *p++ = cpu_to_be32(OP_GETDEVICEINFO); 1905b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1906b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1907b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1908b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ 1909b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1910b1f69b75SAndy Adamson hdr->nops++; 1911b1f69b75SAndy Adamson hdr->replen += decode_getdeviceinfo_maxsz; 1912b1f69b75SAndy Adamson } 1913b1f69b75SAndy Adamson 1914b1f69b75SAndy Adamson static void 1915b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1916b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1917b1f69b75SAndy Adamson struct compound_hdr *hdr) 1918b1f69b75SAndy Adamson { 1919b1f69b75SAndy Adamson __be32 *p; 1920b1f69b75SAndy Adamson 1921ea9d23f5STrond Myklebust p = reserve_space(xdr, 40); 1922b1f69b75SAndy Adamson *p++ = cpu_to_be32(OP_LAYOUTGET); 1923b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1924b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1925b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1926b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1927b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1928b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1929ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1930ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1931b1f69b75SAndy Adamson *p = cpu_to_be32(args->maxcount); 1932b1f69b75SAndy Adamson 1933b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1934b1f69b75SAndy Adamson __func__, 1935b1f69b75SAndy Adamson args->type, 1936b1f69b75SAndy Adamson args->range.iomode, 1937b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1938b1f69b75SAndy Adamson (unsigned long)args->range.length, 1939b1f69b75SAndy Adamson args->maxcount); 1940b1f69b75SAndy Adamson hdr->nops++; 1941b1f69b75SAndy Adamson hdr->replen += decode_layoutget_maxsz; 1942b1f69b75SAndy Adamson } 1943863a3c6cSAndy Adamson 1944863a3c6cSAndy Adamson static int 1945863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1946ac7db726SBenny Halevy struct inode *inode, 1947863a3c6cSAndy Adamson const struct nfs4_layoutcommit_args *args, 1948863a3c6cSAndy Adamson struct compound_hdr *hdr) 1949863a3c6cSAndy Adamson { 1950863a3c6cSAndy Adamson __be32 *p; 1951863a3c6cSAndy Adamson 1952863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1953863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1954863a3c6cSAndy Adamson 1955ea9d23f5STrond Myklebust p = reserve_space(xdr, 24); 1956863a3c6cSAndy Adamson *p++ = cpu_to_be32(OP_LAYOUTCOMMIT); 1957863a3c6cSAndy Adamson /* Only whole file layouts */ 1958863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19593557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1960ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1961ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1962ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1963863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1964863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 1965863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1966863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 1967ac7db726SBenny Halevy 1968ac7db726SBenny Halevy if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 1969ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1970ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 1971ac7db726SBenny Halevy else { 1972ac7db726SBenny Halevy p = reserve_space(xdr, 4); 1973ac7db726SBenny Halevy *p = cpu_to_be32(0); /* no layout-type payload */ 1974ac7db726SBenny Halevy } 1975863a3c6cSAndy Adamson 1976863a3c6cSAndy Adamson hdr->nops++; 1977863a3c6cSAndy Adamson hdr->replen += decode_layoutcommit_maxsz; 1978863a3c6cSAndy Adamson return 0; 1979863a3c6cSAndy Adamson } 1980cbe82603SBenny Halevy 1981cbe82603SBenny Halevy static void 1982cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 1983cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 1984cbe82603SBenny Halevy struct compound_hdr *hdr) 1985cbe82603SBenny Halevy { 1986cbe82603SBenny Halevy __be32 *p; 1987cbe82603SBenny Halevy 1988cbe82603SBenny Halevy p = reserve_space(xdr, 20); 1989cbe82603SBenny Halevy *p++ = cpu_to_be32(OP_LAYOUTRETURN); 1990cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 1991cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 1992cbe82603SBenny Halevy *p++ = cpu_to_be32(IOMODE_ANY); 1993cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 1994ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1995cbe82603SBenny Halevy p = xdr_encode_hyper(p, 0); 1996cbe82603SBenny Halevy p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 1997cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 1998ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1999cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 200004a55549SAndy Adamson if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 200104a55549SAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 200204a55549SAndy Adamson NFS_I(args->inode)->layout, xdr, args); 200304a55549SAndy Adamson } else { 2004cbe82603SBenny Halevy p = reserve_space(xdr, 4); 2005cbe82603SBenny Halevy *p = cpu_to_be32(0); 200604a55549SAndy Adamson } 2007cbe82603SBenny Halevy hdr->nops++; 2008cbe82603SBenny Halevy hdr->replen += decode_layoutreturn_maxsz; 2009cbe82603SBenny Halevy } 2010fca78d6dSBryan Schumaker 2011fca78d6dSBryan Schumaker static int 2012fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2013fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2014fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2015fca78d6dSBryan Schumaker { 2016fca78d6dSBryan Schumaker __be32 *p; 2017fca78d6dSBryan Schumaker p = reserve_space(xdr, 8); 2018fca78d6dSBryan Schumaker *p++ = cpu_to_be32(OP_SECINFO_NO_NAME); 2019fca78d6dSBryan Schumaker *p++ = cpu_to_be32(args->style); 2020fca78d6dSBryan Schumaker hdr->nops++; 2021fca78d6dSBryan Schumaker hdr->replen += decode_secinfo_no_name_maxsz; 2022fca78d6dSBryan Schumaker return 0; 2023fca78d6dSBryan Schumaker } 20247d974794SBryan Schumaker 20257d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 20267d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 20277d974794SBryan Schumaker struct compound_hdr *hdr) 20287d974794SBryan Schumaker { 20297d974794SBryan Schumaker __be32 *p; 20307d974794SBryan Schumaker 2031ea9d23f5STrond Myklebust p = reserve_space(xdr, 8); 20327d974794SBryan Schumaker *p++ = cpu_to_be32(OP_TEST_STATEID); 2033ea9d23f5STrond Myklebust *p = cpu_to_be32(1); 2034ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20357d974794SBryan Schumaker hdr->nops++; 20367d974794SBryan Schumaker hdr->replen += decode_test_stateid_maxsz; 20377d974794SBryan Schumaker } 20389aeda35fSBryan Schumaker 20399aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 20409aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 20419aeda35fSBryan Schumaker struct compound_hdr *hdr) 20429aeda35fSBryan Schumaker { 2043ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 2044ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20459aeda35fSBryan Schumaker } 2046b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2047b1f69b75SAndy Adamson 20481da177e4SLinus Torvalds /* 20491da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20501da177e4SLinus Torvalds */ 20511da177e4SLinus Torvalds 205266cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 205366cc0429SBenny Halevy { 205466cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 205566cc0429SBenny Halevy if (args->sa_session) 2056a4432345STrond Myklebust return args->sa_session->clp->cl_mvops->minor_version; 205766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 205866cc0429SBenny Halevy return 0; 205966cc0429SBenny Halevy } 206066cc0429SBenny Halevy 20611da177e4SLinus Torvalds /* 20621da177e4SLinus Torvalds * Encode an ACCESS request 20631da177e4SLinus Torvalds */ 20649f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 20659f06c719SChuck Lever const struct nfs4_accessargs *args) 20661da177e4SLinus Torvalds { 20671da177e4SLinus Torvalds struct compound_hdr hdr = { 206866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20691da177e4SLinus Torvalds }; 20701da177e4SLinus Torvalds 20719f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20729f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20739f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20749f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 20759f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2076d017931cSAndy Adamson encode_nops(&hdr); 20771da177e4SLinus Torvalds } 20781da177e4SLinus Torvalds 20791da177e4SLinus Torvalds /* 20801da177e4SLinus Torvalds * Encode LOOKUP request 20811da177e4SLinus Torvalds */ 20829f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 20839f06c719SChuck Lever const struct nfs4_lookup_arg *args) 20841da177e4SLinus Torvalds { 20851da177e4SLinus Torvalds struct compound_hdr hdr = { 208666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20871da177e4SLinus Torvalds }; 20881da177e4SLinus Torvalds 20899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20919f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 20929f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 20939f06c719SChuck Lever encode_getfh(xdr, &hdr); 20949f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2095d017931cSAndy Adamson encode_nops(&hdr); 20961da177e4SLinus Torvalds } 20971da177e4SLinus Torvalds 20981da177e4SLinus Torvalds /* 20991da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21001da177e4SLinus Torvalds */ 21019f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21029f06c719SChuck Lever struct xdr_stream *xdr, 21039f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 21041da177e4SLinus Torvalds { 21051da177e4SLinus Torvalds struct compound_hdr hdr = { 210666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21071da177e4SLinus Torvalds }; 21081da177e4SLinus Torvalds 21099f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21109f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21119f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21129f06c719SChuck Lever encode_getfh(xdr, &hdr); 21139f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2114d017931cSAndy Adamson encode_nops(&hdr); 21151da177e4SLinus Torvalds } 21161da177e4SLinus Torvalds 21171da177e4SLinus Torvalds /* 21181da177e4SLinus Torvalds * Encode REMOVE request 21191da177e4SLinus Torvalds */ 21209f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 21219f06c719SChuck Lever const struct nfs_removeargs *args) 21221da177e4SLinus Torvalds { 21231da177e4SLinus Torvalds struct compound_hdr hdr = { 212466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21251da177e4SLinus Torvalds }; 21261da177e4SLinus Torvalds 21279f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21289f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21299f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21309f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 21319f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2132d017931cSAndy Adamson encode_nops(&hdr); 21331da177e4SLinus Torvalds } 21341da177e4SLinus Torvalds 21351da177e4SLinus Torvalds /* 21361da177e4SLinus Torvalds * Encode RENAME request 21371da177e4SLinus Torvalds */ 21389f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 21399f06c719SChuck Lever const struct nfs_renameargs *args) 21401da177e4SLinus Torvalds { 21411da177e4SLinus Torvalds struct compound_hdr hdr = { 214266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21431da177e4SLinus Torvalds }; 21441da177e4SLinus Torvalds 21459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21479f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21489f06c719SChuck Lever encode_savefh(xdr, &hdr); 21499f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21509f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 21519f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21529f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21539f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2154d017931cSAndy Adamson encode_nops(&hdr); 21551da177e4SLinus Torvalds } 21561da177e4SLinus Torvalds 21571da177e4SLinus Torvalds /* 21581da177e4SLinus Torvalds * Encode LINK request 21591da177e4SLinus Torvalds */ 21609f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 21619f06c719SChuck Lever const struct nfs4_link_arg *args) 21621da177e4SLinus Torvalds { 21631da177e4SLinus Torvalds struct compound_hdr hdr = { 216466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21651da177e4SLinus Torvalds }; 21661da177e4SLinus Torvalds 21679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21699f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21709f06c719SChuck Lever encode_savefh(xdr, &hdr); 21719f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21729f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 21739f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21749f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21759f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2176d017931cSAndy Adamson encode_nops(&hdr); 21771da177e4SLinus Torvalds } 21781da177e4SLinus Torvalds 21791da177e4SLinus Torvalds /* 21801da177e4SLinus Torvalds * Encode CREATE request 21811da177e4SLinus Torvalds */ 21829f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 21839f06c719SChuck Lever const struct nfs4_create_arg *args) 21841da177e4SLinus Torvalds { 21851da177e4SLinus Torvalds struct compound_hdr hdr = { 218666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21871da177e4SLinus Torvalds }; 21881da177e4SLinus Torvalds 21899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21919f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21929f06c719SChuck Lever encode_savefh(xdr, &hdr); 21939f06c719SChuck Lever encode_create(xdr, args, &hdr); 21949f06c719SChuck Lever encode_getfh(xdr, &hdr); 21959f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21969f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21979f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2198d017931cSAndy Adamson encode_nops(&hdr); 21991da177e4SLinus Torvalds } 22001da177e4SLinus Torvalds 22011da177e4SLinus Torvalds /* 22021da177e4SLinus Torvalds * Encode SYMLINK request 22031da177e4SLinus Torvalds */ 22049f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 22059f06c719SChuck Lever const struct nfs4_create_arg *args) 22061da177e4SLinus Torvalds { 22079f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22081da177e4SLinus Torvalds } 22091da177e4SLinus Torvalds 22101da177e4SLinus Torvalds /* 22111da177e4SLinus Torvalds * Encode GETATTR request 22121da177e4SLinus Torvalds */ 22139f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 22149f06c719SChuck Lever const struct nfs4_getattr_arg *args) 22151da177e4SLinus Torvalds { 22161da177e4SLinus Torvalds struct compound_hdr hdr = { 221766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22181da177e4SLinus Torvalds }; 22191da177e4SLinus Torvalds 22209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22219f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22229f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22239f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2224d017931cSAndy Adamson encode_nops(&hdr); 22251da177e4SLinus Torvalds } 22261da177e4SLinus Torvalds 22271da177e4SLinus Torvalds /* 22281da177e4SLinus Torvalds * Encode a CLOSE request 22291da177e4SLinus Torvalds */ 22309f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 22319f06c719SChuck Lever struct nfs_closeargs *args) 22321da177e4SLinus Torvalds { 22331da177e4SLinus Torvalds struct compound_hdr hdr = { 223466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22351da177e4SLinus Torvalds }; 22361da177e4SLinus Torvalds 22379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22389f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22399f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22409f06c719SChuck Lever encode_close(xdr, args, &hdr); 22419f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2242d017931cSAndy Adamson encode_nops(&hdr); 22431da177e4SLinus Torvalds } 22441da177e4SLinus Torvalds 22451da177e4SLinus Torvalds /* 22461da177e4SLinus Torvalds * Encode an OPEN request 22471da177e4SLinus Torvalds */ 22489f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 22499f06c719SChuck Lever struct nfs_openargs *args) 22501da177e4SLinus Torvalds { 22511da177e4SLinus Torvalds struct compound_hdr hdr = { 225266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22531da177e4SLinus Torvalds }; 22541da177e4SLinus Torvalds 22559f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22569f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22579f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22589f06c719SChuck Lever encode_savefh(xdr, &hdr); 22599f06c719SChuck Lever encode_open(xdr, args, &hdr); 22609f06c719SChuck Lever encode_getfh(xdr, &hdr); 22619f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 22629f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22636926afd1STrond Myklebust encode_getfattr(xdr, args->dir_bitmask, &hdr); 2264d017931cSAndy Adamson encode_nops(&hdr); 22651da177e4SLinus Torvalds } 22661da177e4SLinus Torvalds 22671da177e4SLinus Torvalds /* 22681da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 22691da177e4SLinus Torvalds */ 22709f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22719f06c719SChuck Lever struct xdr_stream *xdr, 22729f06c719SChuck Lever struct nfs_open_confirmargs *args) 22731da177e4SLinus Torvalds { 22741da177e4SLinus Torvalds struct compound_hdr hdr = { 2275d017931cSAndy Adamson .nops = 0, 22761da177e4SLinus Torvalds }; 22771da177e4SLinus Torvalds 22789f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22799f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22809f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2281d017931cSAndy Adamson encode_nops(&hdr); 22821da177e4SLinus Torvalds } 22831da177e4SLinus Torvalds 22841da177e4SLinus Torvalds /* 22851da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 22861da177e4SLinus Torvalds */ 22879f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 22889f06c719SChuck Lever struct xdr_stream *xdr, 22899f06c719SChuck Lever struct nfs_openargs *args) 22901da177e4SLinus Torvalds { 22911da177e4SLinus Torvalds struct compound_hdr hdr = { 229266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22931da177e4SLinus Torvalds }; 22941da177e4SLinus Torvalds 22959f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22969f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22979f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22989f06c719SChuck Lever encode_open(xdr, args, &hdr); 22999f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2300d017931cSAndy Adamson encode_nops(&hdr); 23011da177e4SLinus Torvalds } 23021da177e4SLinus Torvalds 23031da177e4SLinus Torvalds /* 23041da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23051da177e4SLinus Torvalds */ 23069f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23079f06c719SChuck Lever struct xdr_stream *xdr, 23089f06c719SChuck Lever struct nfs_closeargs *args) 23091da177e4SLinus Torvalds { 23101da177e4SLinus Torvalds struct compound_hdr hdr = { 231166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23121da177e4SLinus Torvalds }; 23131da177e4SLinus Torvalds 23149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23169f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23179f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 23189f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2319d017931cSAndy Adamson encode_nops(&hdr); 23201da177e4SLinus Torvalds } 23211da177e4SLinus Torvalds 23221da177e4SLinus Torvalds /* 23231da177e4SLinus Torvalds * Encode a LOCK request 23241da177e4SLinus Torvalds */ 23259f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 23269f06c719SChuck Lever struct nfs_lock_args *args) 23271da177e4SLinus Torvalds { 23281da177e4SLinus Torvalds struct compound_hdr hdr = { 232966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23301da177e4SLinus Torvalds }; 23311da177e4SLinus Torvalds 23329f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23339f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23349f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23359f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2336d017931cSAndy Adamson encode_nops(&hdr); 23371da177e4SLinus Torvalds } 23381da177e4SLinus Torvalds 23391da177e4SLinus Torvalds /* 23401da177e4SLinus Torvalds * Encode a LOCKT request 23411da177e4SLinus Torvalds */ 23429f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 23439f06c719SChuck Lever struct nfs_lockt_args *args) 23441da177e4SLinus Torvalds { 23451da177e4SLinus Torvalds struct compound_hdr hdr = { 234666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23471da177e4SLinus Torvalds }; 23481da177e4SLinus Torvalds 23499f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23509f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23519f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23529f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2353d017931cSAndy Adamson encode_nops(&hdr); 23541da177e4SLinus Torvalds } 23551da177e4SLinus Torvalds 23561da177e4SLinus Torvalds /* 23571da177e4SLinus Torvalds * Encode a LOCKU request 23581da177e4SLinus Torvalds */ 23599f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 23609f06c719SChuck Lever struct nfs_locku_args *args) 23611da177e4SLinus Torvalds { 23621da177e4SLinus Torvalds struct compound_hdr hdr = { 236366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23641da177e4SLinus Torvalds }; 23651da177e4SLinus Torvalds 23669f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23679f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23689f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23699f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2370d017931cSAndy Adamson encode_nops(&hdr); 23711da177e4SLinus Torvalds } 23721da177e4SLinus Torvalds 23739f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 23749f06c719SChuck Lever struct xdr_stream *xdr, 23759f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2376d3c7b7ccSTrond Myklebust { 2377d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2378d3c7b7ccSTrond Myklebust .minorversion = 0, 2379d3c7b7ccSTrond Myklebust }; 2380d3c7b7ccSTrond Myklebust 23819f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23829f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2383d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2384d3c7b7ccSTrond Myklebust } 2385d3c7b7ccSTrond Myklebust 23861da177e4SLinus Torvalds /* 23871da177e4SLinus Torvalds * Encode a READLINK request 23881da177e4SLinus Torvalds */ 23899f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 23909f06c719SChuck Lever const struct nfs4_readlink *args) 23911da177e4SLinus Torvalds { 23921da177e4SLinus Torvalds struct compound_hdr hdr = { 239366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23941da177e4SLinus Torvalds }; 23951da177e4SLinus Torvalds 23969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23999f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2400e3a535e1STrond Myklebust 240128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2402e3a535e1STrond Myklebust args->pgbase, args->pglen); 2403d017931cSAndy Adamson encode_nops(&hdr); 24041da177e4SLinus Torvalds } 24051da177e4SLinus Torvalds 24061da177e4SLinus Torvalds /* 24071da177e4SLinus Torvalds * Encode a READDIR request 24081da177e4SLinus Torvalds */ 24099f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 24109f06c719SChuck Lever const struct nfs4_readdir_arg *args) 24111da177e4SLinus Torvalds { 24121da177e4SLinus Torvalds struct compound_hdr hdr = { 241366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24141da177e4SLinus Torvalds }; 24151da177e4SLinus Torvalds 24169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24189f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24199f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2420d6ac02dfSTrond Myklebust 242128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2422d6ac02dfSTrond Myklebust args->pgbase, args->count); 2423d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 242428f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2425d6ac02dfSTrond Myklebust args->pgbase, args->count); 2426d017931cSAndy Adamson encode_nops(&hdr); 24271da177e4SLinus Torvalds } 24281da177e4SLinus Torvalds 24291da177e4SLinus Torvalds /* 24301da177e4SLinus Torvalds * Encode a READ request 24311da177e4SLinus Torvalds */ 24329f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 24339f06c719SChuck Lever struct nfs_readargs *args) 24341da177e4SLinus Torvalds { 24351da177e4SLinus Torvalds struct compound_hdr hdr = { 243666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24371da177e4SLinus Torvalds }; 24381da177e4SLinus Torvalds 24399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24419f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24429f06c719SChuck Lever encode_read(xdr, args, &hdr); 24431da177e4SLinus Torvalds 244428f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 24451da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 24464f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2447d017931cSAndy Adamson encode_nops(&hdr); 24481da177e4SLinus Torvalds } 24491da177e4SLinus Torvalds 24501da177e4SLinus Torvalds /* 24511da177e4SLinus Torvalds * Encode an SETATTR request 24521da177e4SLinus Torvalds */ 24539f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 24549f06c719SChuck Lever struct nfs_setattrargs *args) 24551da177e4SLinus Torvalds { 24561da177e4SLinus Torvalds struct compound_hdr hdr = { 245766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24581da177e4SLinus Torvalds }; 24591da177e4SLinus Torvalds 24609f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24619f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24629f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24639f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 24649f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2465d017931cSAndy Adamson encode_nops(&hdr); 24661da177e4SLinus Torvalds } 24671da177e4SLinus Torvalds 24681da177e4SLinus Torvalds /* 2469029d105eSJ. Bruce Fields * Encode a GETACL request 2470029d105eSJ. Bruce Fields */ 24719f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2472029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2473029d105eSJ. Bruce Fields { 2474029d105eSJ. Bruce Fields struct compound_hdr hdr = { 247566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2476029d105eSJ. Bruce Fields }; 247728f56694SBenny Halevy uint32_t replen; 2478029d105eSJ. Bruce Fields 24799f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24809f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24819f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2482bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 24839f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2484cf8cdbe5SAndy Adamson 248528f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2486029d105eSJ. Bruce Fields args->acl_pages, args->acl_pgbase, args->acl_len); 2487bf118a34SAndy Adamson 2488d017931cSAndy Adamson encode_nops(&hdr); 2489029d105eSJ. Bruce Fields } 2490029d105eSJ. Bruce Fields 2491029d105eSJ. Bruce Fields /* 24921da177e4SLinus Torvalds * Encode a WRITE request 24931da177e4SLinus Torvalds */ 24949f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 24959f06c719SChuck Lever struct nfs_writeargs *args) 24961da177e4SLinus Torvalds { 24971da177e4SLinus Torvalds struct compound_hdr hdr = { 249866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24991da177e4SLinus Torvalds }; 25001da177e4SLinus Torvalds 25019f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25029f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25039f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25049f06c719SChuck Lever encode_write(xdr, args, &hdr); 25054f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25067ffd1064SFred Isaman if (args->bitmask) 25079f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2508d017931cSAndy Adamson encode_nops(&hdr); 25091da177e4SLinus Torvalds } 25101da177e4SLinus Torvalds 25111da177e4SLinus Torvalds /* 25121da177e4SLinus Torvalds * a COMMIT request 25131da177e4SLinus Torvalds */ 25149f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 25159f06c719SChuck Lever struct nfs_writeargs *args) 25161da177e4SLinus Torvalds { 25171da177e4SLinus Torvalds struct compound_hdr hdr = { 251866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25191da177e4SLinus Torvalds }; 25201da177e4SLinus Torvalds 25219f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25229f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25239f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25249f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2525988b6dceSFred Isaman if (args->bitmask) 25269f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2527d017931cSAndy Adamson encode_nops(&hdr); 25281da177e4SLinus Torvalds } 25291da177e4SLinus Torvalds 25301da177e4SLinus Torvalds /* 25311da177e4SLinus Torvalds * FSINFO request 25321da177e4SLinus Torvalds */ 25339f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 25349f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 25351da177e4SLinus Torvalds { 25361da177e4SLinus Torvalds struct compound_hdr hdr = { 253766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25381da177e4SLinus Torvalds }; 25391da177e4SLinus Torvalds 25409f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25419f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25429f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25439f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2544d017931cSAndy Adamson encode_nops(&hdr); 25451da177e4SLinus Torvalds } 25461da177e4SLinus Torvalds 25471da177e4SLinus Torvalds /* 25481da177e4SLinus Torvalds * a PATHCONF request 25491da177e4SLinus Torvalds */ 25509f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 25519f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 25521da177e4SLinus Torvalds { 25531da177e4SLinus Torvalds struct compound_hdr hdr = { 255466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25551da177e4SLinus Torvalds }; 25561da177e4SLinus Torvalds 25579f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25589f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25599f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25609f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2561d017931cSAndy Adamson &hdr); 2562d017931cSAndy Adamson encode_nops(&hdr); 25631da177e4SLinus Torvalds } 25641da177e4SLinus Torvalds 25651da177e4SLinus Torvalds /* 25661da177e4SLinus Torvalds * a STATFS request 25671da177e4SLinus Torvalds */ 25689f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 25699f06c719SChuck Lever const struct nfs4_statfs_arg *args) 25701da177e4SLinus Torvalds { 25711da177e4SLinus Torvalds struct compound_hdr hdr = { 257266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25731da177e4SLinus Torvalds }; 25741da177e4SLinus Torvalds 25759f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25769f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25779f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25789f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2579d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2580d017931cSAndy Adamson encode_nops(&hdr); 25811da177e4SLinus Torvalds } 25821da177e4SLinus Torvalds 25831da177e4SLinus Torvalds /* 25841da177e4SLinus Torvalds * GETATTR_BITMAP request 25851da177e4SLinus Torvalds */ 25869f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 25879f06c719SChuck Lever struct xdr_stream *xdr, 258843652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 25891da177e4SLinus Torvalds { 25901da177e4SLinus Torvalds struct compound_hdr hdr = { 259166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25921da177e4SLinus Torvalds }; 25931da177e4SLinus Torvalds 25949f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25959f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25969f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 25979f06c719SChuck Lever encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2598264e6351SChuck Lever FATTR4_WORD0_FH_EXPIRE_TYPE| 25991da177e4SLinus Torvalds FATTR4_WORD0_LINK_SUPPORT| 26001da177e4SLinus Torvalds FATTR4_WORD0_SYMLINK_SUPPORT| 2601d017931cSAndy Adamson FATTR4_WORD0_ACLSUPPORT, &hdr); 2602d017931cSAndy Adamson encode_nops(&hdr); 26031da177e4SLinus Torvalds } 26041da177e4SLinus Torvalds 26051da177e4SLinus Torvalds /* 26061da177e4SLinus Torvalds * a RENEW request 26071da177e4SLinus Torvalds */ 26089f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 26099f06c719SChuck Lever struct nfs_client *clp) 26101da177e4SLinus Torvalds { 26111da177e4SLinus Torvalds struct compound_hdr hdr = { 2612d017931cSAndy Adamson .nops = 0, 26131da177e4SLinus Torvalds }; 26141da177e4SLinus Torvalds 26159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2616bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2617d017931cSAndy Adamson encode_nops(&hdr); 26181da177e4SLinus Torvalds } 26191da177e4SLinus Torvalds 26201da177e4SLinus Torvalds /* 26211da177e4SLinus Torvalds * a SETCLIENTID request 26221da177e4SLinus Torvalds */ 26239f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 26249f06c719SChuck Lever struct xdr_stream *xdr, 26259f06c719SChuck Lever struct nfs4_setclientid *sc) 26261da177e4SLinus Torvalds { 26271da177e4SLinus Torvalds struct compound_hdr hdr = { 2628d017931cSAndy Adamson .nops = 0, 26291da177e4SLinus Torvalds }; 26301da177e4SLinus Torvalds 26319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26329f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2633d017931cSAndy Adamson encode_nops(&hdr); 26341da177e4SLinus Torvalds } 26351da177e4SLinus Torvalds 26361da177e4SLinus Torvalds /* 26371da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 26381da177e4SLinus Torvalds */ 26399f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 26409f06c719SChuck Lever struct xdr_stream *xdr, 26419f06c719SChuck Lever struct nfs4_setclientid_res *arg) 26421da177e4SLinus Torvalds { 26431da177e4SLinus Torvalds struct compound_hdr hdr = { 2644d017931cSAndy Adamson .nops = 0, 26451da177e4SLinus Torvalds }; 2646dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 26471da177e4SLinus Torvalds 26489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26499f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 26509f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 26519f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 2652d017931cSAndy Adamson encode_nops(&hdr); 26531da177e4SLinus Torvalds } 26541da177e4SLinus Torvalds 26551da177e4SLinus Torvalds /* 26561da177e4SLinus Torvalds * DELEGRETURN request 26571da177e4SLinus Torvalds */ 26589f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 26599f06c719SChuck Lever struct xdr_stream *xdr, 26609f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 26611da177e4SLinus Torvalds { 26621da177e4SLinus Torvalds struct compound_hdr hdr = { 266366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26641da177e4SLinus Torvalds }; 26651da177e4SLinus Torvalds 26669f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26679f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26689f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26699f06c719SChuck Lever encode_delegreturn(xdr, args->stateid, &hdr); 26709f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2671d017931cSAndy Adamson encode_nops(&hdr); 26721da177e4SLinus Torvalds } 26731da177e4SLinus Torvalds 26741da177e4SLinus Torvalds /* 2675683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2676683b57b4STrond Myklebust */ 26779f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 26789f06c719SChuck Lever struct xdr_stream *xdr, 26799f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2680683b57b4STrond Myklebust { 2681683b57b4STrond Myklebust struct compound_hdr hdr = { 268266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2683683b57b4STrond Myklebust }; 268428f56694SBenny Halevy uint32_t replen; 2685683b57b4STrond Myklebust 26869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26889f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 26899f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 269028f56694SBenny Halevy replen = hdr.replen; /* get the attribute into args->page */ 26919f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2692cf8cdbe5SAndy Adamson 269328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2694683b57b4STrond Myklebust 0, PAGE_SIZE); 2695d017931cSAndy Adamson encode_nops(&hdr); 2696683b57b4STrond Myklebust } 2697683b57b4STrond Myklebust 26985a5ea0d4SBryan Schumaker /* 26995a5ea0d4SBryan Schumaker * Encode SECINFO request 27005a5ea0d4SBryan Schumaker */ 27015a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 27025a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 27035a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 27045a5ea0d4SBryan Schumaker { 27055a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 27065a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27075a5ea0d4SBryan Schumaker }; 27085a5ea0d4SBryan Schumaker 27095a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 27105a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 27115a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 27125a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 27135a5ea0d4SBryan Schumaker encode_nops(&hdr); 27145a5ea0d4SBryan Schumaker } 27155a5ea0d4SBryan Schumaker 271699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 271799fe60d0SBenny Halevy /* 271899fe60d0SBenny Halevy * EXCHANGE_ID request 271999fe60d0SBenny Halevy */ 27209f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 27219f06c719SChuck Lever struct xdr_stream *xdr, 272299fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 272399fe60d0SBenny Halevy { 272499fe60d0SBenny Halevy struct compound_hdr hdr = { 2725a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 272699fe60d0SBenny Halevy }; 272799fe60d0SBenny Halevy 27289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27299f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 273099fe60d0SBenny Halevy encode_nops(&hdr); 273199fe60d0SBenny Halevy } 27322050f0ccSAndy Adamson 27332050f0ccSAndy Adamson /* 2734fc931582SAndy Adamson * a CREATE_SESSION request 2735fc931582SAndy Adamson */ 27369f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 27379f06c719SChuck Lever struct xdr_stream *xdr, 2738fc931582SAndy Adamson struct nfs41_create_session_args *args) 2739fc931582SAndy Adamson { 2740fc931582SAndy Adamson struct compound_hdr hdr = { 2741a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2742fc931582SAndy Adamson }; 2743fc931582SAndy Adamson 27449f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27459f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2746fc931582SAndy Adamson encode_nops(&hdr); 2747fc931582SAndy Adamson } 2748fc931582SAndy Adamson 2749fc931582SAndy Adamson /* 27500f3e66c6SAndy Adamson * a DESTROY_SESSION request 27510f3e66c6SAndy Adamson */ 27529f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 27539f06c719SChuck Lever struct xdr_stream *xdr, 27540f3e66c6SAndy Adamson struct nfs4_session *session) 27550f3e66c6SAndy Adamson { 27560f3e66c6SAndy Adamson struct compound_hdr hdr = { 2757a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 27580f3e66c6SAndy Adamson }; 27590f3e66c6SAndy Adamson 27609f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27619f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 27620f3e66c6SAndy Adamson encode_nops(&hdr); 27630f3e66c6SAndy Adamson } 27640f3e66c6SAndy Adamson 27650f3e66c6SAndy Adamson /* 2766fc01cea9SAndy Adamson * a SEQUENCE request 2767fc01cea9SAndy Adamson */ 27689f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2769fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2770fc01cea9SAndy Adamson { 2771fc01cea9SAndy Adamson struct compound_hdr hdr = { 2772fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2773fc01cea9SAndy Adamson }; 2774fc01cea9SAndy Adamson 27759f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27769f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2777fc01cea9SAndy Adamson encode_nops(&hdr); 2778fc01cea9SAndy Adamson } 2779fc01cea9SAndy Adamson 2780fc01cea9SAndy Adamson /* 27812050f0ccSAndy Adamson * a GET_LEASE_TIME request 27822050f0ccSAndy Adamson */ 27839f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 27849f06c719SChuck Lever struct xdr_stream *xdr, 27852050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 27862050f0ccSAndy Adamson { 27872050f0ccSAndy Adamson struct compound_hdr hdr = { 27882050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 27892050f0ccSAndy Adamson }; 2790dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 27912050f0ccSAndy Adamson 27929f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27939f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 27949f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 27959f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 27962050f0ccSAndy Adamson encode_nops(&hdr); 27972050f0ccSAndy Adamson } 279818019753SRicardo Labiaga 279918019753SRicardo Labiaga /* 280018019753SRicardo Labiaga * a RECLAIM_COMPLETE request 280118019753SRicardo Labiaga */ 28029f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 28039f06c719SChuck Lever struct xdr_stream *xdr, 280418019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 280518019753SRicardo Labiaga { 280618019753SRicardo Labiaga struct compound_hdr hdr = { 280718019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 280818019753SRicardo Labiaga }; 280918019753SRicardo Labiaga 28109f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28119f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28129f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 281318019753SRicardo Labiaga encode_nops(&hdr); 281418019753SRicardo Labiaga } 281518019753SRicardo Labiaga 2816b1f69b75SAndy Adamson /* 28177f11d8d3SAndy Adamson * Encode GETDEVICELIST request 28187f11d8d3SAndy Adamson */ 28197f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req, 28207f11d8d3SAndy Adamson struct xdr_stream *xdr, 28217f11d8d3SAndy Adamson struct nfs4_getdevicelist_args *args) 28227f11d8d3SAndy Adamson { 28237f11d8d3SAndy Adamson struct compound_hdr hdr = { 28247f11d8d3SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28257f11d8d3SAndy Adamson }; 28267f11d8d3SAndy Adamson 28277f11d8d3SAndy Adamson encode_compound_hdr(xdr, req, &hdr); 28287f11d8d3SAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 28297f11d8d3SAndy Adamson encode_putfh(xdr, args->fh, &hdr); 28307f11d8d3SAndy Adamson encode_getdevicelist(xdr, args, &hdr); 28317f11d8d3SAndy Adamson encode_nops(&hdr); 28327f11d8d3SAndy Adamson } 28337f11d8d3SAndy Adamson 28347f11d8d3SAndy Adamson /* 2835b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2836b1f69b75SAndy Adamson */ 28379f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 28389f06c719SChuck Lever struct xdr_stream *xdr, 2839b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2840b1f69b75SAndy Adamson { 2841b1f69b75SAndy Adamson struct compound_hdr hdr = { 2842b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2843b1f69b75SAndy Adamson }; 2844b1f69b75SAndy Adamson 28459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28479f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2848b1f69b75SAndy Adamson 2849b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2850b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2851b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2852b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2853b1f69b75SAndy Adamson args->pdev->pglen); 2854b1f69b75SAndy Adamson 2855b1f69b75SAndy Adamson encode_nops(&hdr); 2856b1f69b75SAndy Adamson } 2857b1f69b75SAndy Adamson 2858b1f69b75SAndy Adamson /* 2859b1f69b75SAndy Adamson * Encode LAYOUTGET request 2860b1f69b75SAndy Adamson */ 28619f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 28629f06c719SChuck Lever struct xdr_stream *xdr, 2863b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2864b1f69b75SAndy Adamson { 2865b1f69b75SAndy Adamson struct compound_hdr hdr = { 2866b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2867b1f69b75SAndy Adamson }; 2868b1f69b75SAndy Adamson 28699f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28709f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28719f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 28729f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 287335124a09SWeston Andros Adamson 287435124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 287535124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 287635124a09SWeston Andros Adamson 2877b1f69b75SAndy Adamson encode_nops(&hdr); 2878b1f69b75SAndy Adamson } 2879863a3c6cSAndy Adamson 2880863a3c6cSAndy Adamson /* 2881863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2882863a3c6cSAndy Adamson */ 2883cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2884863a3c6cSAndy Adamson struct xdr_stream *xdr, 2885863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2886863a3c6cSAndy Adamson { 2887ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2888ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2889863a3c6cSAndy Adamson struct compound_hdr hdr = { 2890863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2891863a3c6cSAndy Adamson }; 2892863a3c6cSAndy Adamson 2893863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2894863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2895863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2896ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2897863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2898863a3c6cSAndy Adamson encode_nops(&hdr); 2899cbe82603SBenny Halevy } 2900cbe82603SBenny Halevy 2901cbe82603SBenny Halevy /* 2902cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2903cbe82603SBenny Halevy */ 2904cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2905cbe82603SBenny Halevy struct xdr_stream *xdr, 2906cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2907cbe82603SBenny Halevy { 2908cbe82603SBenny Halevy struct compound_hdr hdr = { 2909cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2910cbe82603SBenny Halevy }; 2911cbe82603SBenny Halevy 2912cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2913cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2914cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2915cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2916cbe82603SBenny Halevy encode_nops(&hdr); 2917863a3c6cSAndy Adamson } 2918fca78d6dSBryan Schumaker 2919fca78d6dSBryan Schumaker /* 2920fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2921fca78d6dSBryan Schumaker */ 2922fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2923fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2924fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2925fca78d6dSBryan Schumaker { 2926fca78d6dSBryan Schumaker struct compound_hdr hdr = { 2927fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2928fca78d6dSBryan Schumaker }; 2929fca78d6dSBryan Schumaker 2930fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 2931fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 2932fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 2933fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 2934fca78d6dSBryan Schumaker encode_nops(&hdr); 2935fca78d6dSBryan Schumaker return 0; 2936fca78d6dSBryan Schumaker } 29377d974794SBryan Schumaker 29387d974794SBryan Schumaker /* 29397d974794SBryan Schumaker * Encode TEST_STATEID request 29407d974794SBryan Schumaker */ 29417d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 29427d974794SBryan Schumaker struct xdr_stream *xdr, 29437d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 29447d974794SBryan Schumaker { 29457d974794SBryan Schumaker struct compound_hdr hdr = { 29467d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29477d974794SBryan Schumaker }; 29487d974794SBryan Schumaker 29497d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29507d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29517d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 29527d974794SBryan Schumaker encode_nops(&hdr); 29537d974794SBryan Schumaker } 29549aeda35fSBryan Schumaker 29559aeda35fSBryan Schumaker /* 29569aeda35fSBryan Schumaker * Encode FREE_STATEID request 29579aeda35fSBryan Schumaker */ 29589aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 29599aeda35fSBryan Schumaker struct xdr_stream *xdr, 29609aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 29619aeda35fSBryan Schumaker { 29629aeda35fSBryan Schumaker struct compound_hdr hdr = { 29639aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29649aeda35fSBryan Schumaker }; 29659aeda35fSBryan Schumaker 29669aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29679aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29689aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 29699aeda35fSBryan Schumaker encode_nops(&hdr); 29709aeda35fSBryan Schumaker } 297199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 297299fe60d0SBenny Halevy 2973686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 2974686841b3SBenny Halevy { 2975686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 2976686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 2977686841b3SBenny Halevy func, xdr->end - xdr->p); 2978686841b3SBenny Halevy } 29791da177e4SLinus Torvalds 2980683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 29811da177e4SLinus Torvalds { 29828687b63aSAl Viro __be32 *p; 29831da177e4SLinus Torvalds 2984c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 2985c0eae66eSBenny Halevy if (unlikely(!p)) 2986c0eae66eSBenny Halevy goto out_overflow; 2987cccddf4fSBenny Halevy *len = be32_to_cpup(p); 2988c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 2989c0eae66eSBenny Halevy if (unlikely(!p)) 2990c0eae66eSBenny Halevy goto out_overflow; 29911da177e4SLinus Torvalds *string = (char *)p; 29921da177e4SLinus Torvalds return 0; 2993c0eae66eSBenny Halevy out_overflow: 2994c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2995c0eae66eSBenny Halevy return -EIO; 29961da177e4SLinus Torvalds } 29971da177e4SLinus Torvalds 29981da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 29991da177e4SLinus Torvalds { 30008687b63aSAl Viro __be32 *p; 30011da177e4SLinus Torvalds 3002c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3003c0eae66eSBenny Halevy if (unlikely(!p)) 3004c0eae66eSBenny Halevy goto out_overflow; 30056f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3006cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 30071da177e4SLinus Torvalds 3008c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3009c0eae66eSBenny Halevy if (unlikely(!p)) 3010c0eae66eSBenny Halevy goto out_overflow; 30111da177e4SLinus Torvalds hdr->tag = (char *)p; 30121da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3013cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3014aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3015aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 30161da177e4SLinus Torvalds return 0; 3017c0eae66eSBenny Halevy out_overflow: 3018c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3019c0eae66eSBenny Halevy return -EIO; 30201da177e4SLinus Torvalds } 30211da177e4SLinus Torvalds 30221da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 30231da177e4SLinus Torvalds { 30248687b63aSAl Viro __be32 *p; 30251da177e4SLinus Torvalds uint32_t opnum; 30261da177e4SLinus Torvalds int32_t nfserr; 30271da177e4SLinus Torvalds 3028c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3029c0eae66eSBenny Halevy if (unlikely(!p)) 3030c0eae66eSBenny Halevy goto out_overflow; 30316f723f77SBenny Halevy opnum = be32_to_cpup(p++); 30321da177e4SLinus Torvalds if (opnum != expected) { 3033fe82a183SChuck Lever dprintk("nfs: Server returned operation" 30341da177e4SLinus Torvalds " %d but we issued a request for %d\n", 30351da177e4SLinus Torvalds opnum, expected); 30361da177e4SLinus Torvalds return -EIO; 30371da177e4SLinus Torvalds } 3038cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 30391da177e4SLinus Torvalds if (nfserr != NFS_OK) 3040856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 30411da177e4SLinus Torvalds return 0; 3042c0eae66eSBenny Halevy out_overflow: 3043c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3044c0eae66eSBenny Halevy return -EIO; 30451da177e4SLinus Torvalds } 30461da177e4SLinus Torvalds 30471da177e4SLinus Torvalds /* Dummy routine */ 3048adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 30491da177e4SLinus Torvalds { 30508687b63aSAl Viro __be32 *p; 3051683b57b4STrond Myklebust unsigned int strlen; 30521da177e4SLinus Torvalds char *str; 30531da177e4SLinus Torvalds 3054c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3055c0eae66eSBenny Halevy if (likely(p)) 30561da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3057c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3058c0eae66eSBenny Halevy return -EIO; 30591da177e4SLinus Torvalds } 30601da177e4SLinus Torvalds 30611da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 30621da177e4SLinus Torvalds { 30638687b63aSAl Viro uint32_t bmlen; 30648687b63aSAl Viro __be32 *p; 30651da177e4SLinus Torvalds 3066c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3067c0eae66eSBenny Halevy if (unlikely(!p)) 3068c0eae66eSBenny Halevy goto out_overflow; 3069cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 30701da177e4SLinus Torvalds 3071dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3072c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3073c0eae66eSBenny Halevy if (unlikely(!p)) 3074c0eae66eSBenny Halevy goto out_overflow; 30751da177e4SLinus Torvalds if (bmlen > 0) { 30766f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3077dae100c2SFred Isaman if (bmlen > 1) { 3078dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3079dae100c2SFred Isaman if (bmlen > 2) 3080dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3081dae100c2SFred Isaman } 30821da177e4SLinus Torvalds } 30831da177e4SLinus Torvalds return 0; 3084c0eae66eSBenny Halevy out_overflow: 3085c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3086c0eae66eSBenny Halevy return -EIO; 30871da177e4SLinus Torvalds } 30881da177e4SLinus Torvalds 30898687b63aSAl Viro static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) 30901da177e4SLinus Torvalds { 30918687b63aSAl Viro __be32 *p; 30921da177e4SLinus Torvalds 3093c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3094c0eae66eSBenny Halevy if (unlikely(!p)) 3095c0eae66eSBenny Halevy goto out_overflow; 3096cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 30971da177e4SLinus Torvalds *savep = xdr->p; 30981da177e4SLinus Torvalds return 0; 3099c0eae66eSBenny Halevy out_overflow: 3100c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3101c0eae66eSBenny Halevy return -EIO; 31021da177e4SLinus Torvalds } 31031da177e4SLinus Torvalds 31041da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 31051da177e4SLinus Torvalds { 31061da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 31073388bff5SRoman Borisov int ret; 31083388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 31093388bff5SRoman Borisov if (unlikely(ret < 0)) 31103388bff5SRoman Borisov return ret; 31111da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 31121da177e4SLinus Torvalds } else 3113dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3114dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3115dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 31161da177e4SLinus Torvalds return 0; 31171da177e4SLinus Torvalds } 31181da177e4SLinus Torvalds 31191da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 31201da177e4SLinus Torvalds { 31218687b63aSAl Viro __be32 *p; 3122409924e4STrond Myklebust int ret = 0; 31231da177e4SLinus Torvalds 31241da177e4SLinus Torvalds *type = 0; 31251da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 31261da177e4SLinus Torvalds return -EIO; 31271da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3128c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3129c0eae66eSBenny Halevy if (unlikely(!p)) 3130c0eae66eSBenny Halevy goto out_overflow; 3131cccddf4fSBenny Halevy *type = be32_to_cpup(p); 31321da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 31333110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 31341da177e4SLinus Torvalds return -EIO; 31351da177e4SLinus Torvalds } 31361da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3137409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 31381da177e4SLinus Torvalds } 3139bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3140409924e4STrond Myklebust return ret; 3141c0eae66eSBenny Halevy out_overflow: 3142c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3143c0eae66eSBenny Halevy return -EIO; 31441da177e4SLinus Torvalds } 31451da177e4SLinus Torvalds 3146264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3147264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3148264e6351SChuck Lever { 3149264e6351SChuck Lever __be32 *p; 3150264e6351SChuck Lever 3151264e6351SChuck Lever *type = 0; 3152264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3153264e6351SChuck Lever return -EIO; 3154264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3155264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3156264e6351SChuck Lever if (unlikely(!p)) 3157264e6351SChuck Lever goto out_overflow; 3158264e6351SChuck Lever *type = be32_to_cpup(p); 3159264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3160264e6351SChuck Lever } 3161264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3162264e6351SChuck Lever return 0; 3163264e6351SChuck Lever out_overflow: 3164264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3165264e6351SChuck Lever return -EIO; 3166264e6351SChuck Lever } 3167264e6351SChuck Lever 31681da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 31691da177e4SLinus Torvalds { 31708687b63aSAl Viro __be32 *p; 3171409924e4STrond Myklebust int ret = 0; 31721da177e4SLinus Torvalds 31731da177e4SLinus Torvalds *change = 0; 31741da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 31751da177e4SLinus Torvalds return -EIO; 31761da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3177c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3178c0eae66eSBenny Halevy if (unlikely(!p)) 3179c0eae66eSBenny Halevy goto out_overflow; 3180cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 31811da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3182409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 31831da177e4SLinus Torvalds } 31843110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 31851da177e4SLinus Torvalds (unsigned long long)*change); 3186409924e4STrond Myklebust return ret; 3187c0eae66eSBenny Halevy out_overflow: 3188c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3189c0eae66eSBenny Halevy return -EIO; 31901da177e4SLinus Torvalds } 31911da177e4SLinus Torvalds 31921da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 31931da177e4SLinus Torvalds { 31948687b63aSAl Viro __be32 *p; 3195409924e4STrond Myklebust int ret = 0; 31961da177e4SLinus Torvalds 31971da177e4SLinus Torvalds *size = 0; 31981da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 31991da177e4SLinus Torvalds return -EIO; 32001da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3201c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3202c0eae66eSBenny Halevy if (unlikely(!p)) 3203c0eae66eSBenny Halevy goto out_overflow; 3204cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 32051da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3206409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 32071da177e4SLinus Torvalds } 32083110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3209409924e4STrond Myklebust return ret; 3210c0eae66eSBenny Halevy out_overflow: 3211c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3212c0eae66eSBenny Halevy return -EIO; 32131da177e4SLinus Torvalds } 32141da177e4SLinus Torvalds 32151da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32161da177e4SLinus Torvalds { 32178687b63aSAl Viro __be32 *p; 32181da177e4SLinus Torvalds 32191da177e4SLinus Torvalds *res = 0; 32201da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 32211da177e4SLinus Torvalds return -EIO; 32221da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3223c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3224c0eae66eSBenny Halevy if (unlikely(!p)) 3225c0eae66eSBenny Halevy goto out_overflow; 3226cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32271da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 32281da177e4SLinus Torvalds } 32293110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 32301da177e4SLinus Torvalds return 0; 3231c0eae66eSBenny Halevy out_overflow: 3232c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3233c0eae66eSBenny Halevy return -EIO; 32341da177e4SLinus Torvalds } 32351da177e4SLinus Torvalds 32361da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32371da177e4SLinus Torvalds { 32388687b63aSAl Viro __be32 *p; 32391da177e4SLinus Torvalds 32401da177e4SLinus Torvalds *res = 0; 32411da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 32421da177e4SLinus Torvalds return -EIO; 32431da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3244c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3245c0eae66eSBenny Halevy if (unlikely(!p)) 3246c0eae66eSBenny Halevy goto out_overflow; 3247cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32481da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 32491da177e4SLinus Torvalds } 32503110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 32511da177e4SLinus Torvalds return 0; 3252c0eae66eSBenny Halevy out_overflow: 3253c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3254c0eae66eSBenny Halevy return -EIO; 32551da177e4SLinus Torvalds } 32561da177e4SLinus Torvalds 32578b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 32581da177e4SLinus Torvalds { 32598687b63aSAl Viro __be32 *p; 3260409924e4STrond Myklebust int ret = 0; 32611da177e4SLinus Torvalds 32621da177e4SLinus Torvalds fsid->major = 0; 32631da177e4SLinus Torvalds fsid->minor = 0; 32641da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 32651da177e4SLinus Torvalds return -EIO; 32661da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3267c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3268c0eae66eSBenny Halevy if (unlikely(!p)) 3269c0eae66eSBenny Halevy goto out_overflow; 32703ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3271cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 32721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3273409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 32741da177e4SLinus Torvalds } 32753110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 32761da177e4SLinus Torvalds (unsigned long long)fsid->major, 32771da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3278409924e4STrond Myklebust return ret; 3279c0eae66eSBenny Halevy out_overflow: 3280c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3281c0eae66eSBenny Halevy return -EIO; 32821da177e4SLinus Torvalds } 32831da177e4SLinus Torvalds 32841da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32851da177e4SLinus Torvalds { 32868687b63aSAl Viro __be32 *p; 32871da177e4SLinus Torvalds 32881da177e4SLinus Torvalds *res = 60; 32891da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 32901da177e4SLinus Torvalds return -EIO; 32911da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3292c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3293c0eae66eSBenny Halevy if (unlikely(!p)) 3294c0eae66eSBenny Halevy goto out_overflow; 3295cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32961da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 32971da177e4SLinus Torvalds } 32983110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 32991da177e4SLinus Torvalds return 0; 3300c0eae66eSBenny Halevy out_overflow: 3301c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3302c0eae66eSBenny Halevy return -EIO; 33031da177e4SLinus Torvalds } 33041da177e4SLinus Torvalds 3305ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3306ae42c70aSBryan Schumaker { 3307ae42c70aSBryan Schumaker __be32 *p; 3308ae42c70aSBryan Schumaker 3309ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3310ae42c70aSBryan Schumaker return -EIO; 3311ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3312ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3313ae42c70aSBryan Schumaker if (unlikely(!p)) 3314ae42c70aSBryan Schumaker goto out_overflow; 3315ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3316ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3317ae42c70aSBryan Schumaker } 3318ae42c70aSBryan Schumaker return 0; 3319ae42c70aSBryan Schumaker out_overflow: 3320ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3321ae42c70aSBryan Schumaker return -EIO; 3322ae42c70aSBryan Schumaker } 3323ae42c70aSBryan Schumaker 3324ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3325ae42c70aSBryan Schumaker { 3326ae42c70aSBryan Schumaker __be32 *p; 3327ae42c70aSBryan Schumaker int len; 3328ae42c70aSBryan Schumaker 33297ad07353STrond Myklebust if (fh != NULL) 3330ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3331ae42c70aSBryan Schumaker 3332ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3333ae42c70aSBryan Schumaker return -EIO; 3334ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3335ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3336ae42c70aSBryan Schumaker if (unlikely(!p)) 3337ae42c70aSBryan Schumaker goto out_overflow; 3338ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3339ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3340ae42c70aSBryan Schumaker return -EIO; 3341ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3342ae42c70aSBryan Schumaker if (unlikely(!p)) 3343ae42c70aSBryan Schumaker goto out_overflow; 33447ad07353STrond Myklebust if (fh != NULL) { 3345ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 33467ad07353STrond Myklebust fh->size = len; 33477ad07353STrond Myklebust } 3348ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3349ae42c70aSBryan Schumaker } 3350ae42c70aSBryan Schumaker return 0; 3351ae42c70aSBryan Schumaker out_overflow: 3352ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3353ae42c70aSBryan Schumaker return -EIO; 3354ae42c70aSBryan Schumaker } 3355ae42c70aSBryan Schumaker 33561da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33571da177e4SLinus Torvalds { 33588687b63aSAl Viro __be32 *p; 33591da177e4SLinus Torvalds 33601da177e4SLinus Torvalds *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 33611da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 33621da177e4SLinus Torvalds return -EIO; 33631da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3364c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3365c0eae66eSBenny Halevy if (unlikely(!p)) 3366c0eae66eSBenny Halevy goto out_overflow; 3367cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33681da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 33691da177e4SLinus Torvalds } 33703110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 33711da177e4SLinus Torvalds return 0; 3372c0eae66eSBenny Halevy out_overflow: 3373c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3374c0eae66eSBenny Halevy return -EIO; 33751da177e4SLinus Torvalds } 33761da177e4SLinus Torvalds 33771da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 33781da177e4SLinus Torvalds { 33798687b63aSAl Viro __be32 *p; 3380409924e4STrond Myklebust int ret = 0; 33811da177e4SLinus Torvalds 33821da177e4SLinus Torvalds *fileid = 0; 33831da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 33841da177e4SLinus Torvalds return -EIO; 33851da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3386c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3387c0eae66eSBenny Halevy if (unlikely(!p)) 3388c0eae66eSBenny Halevy goto out_overflow; 3389cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 33901da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3391409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 33921da177e4SLinus Torvalds } 33933110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3394409924e4STrond Myklebust return ret; 3395c0eae66eSBenny Halevy out_overflow: 3396c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3397c0eae66eSBenny Halevy return -EIO; 33981da177e4SLinus Torvalds } 33991da177e4SLinus Torvalds 340099baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 340199baf625SManoj Naik { 34028687b63aSAl Viro __be32 *p; 3403409924e4STrond Myklebust int ret = 0; 340499baf625SManoj Naik 340599baf625SManoj Naik *fileid = 0; 340699baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 340799baf625SManoj Naik return -EIO; 340899baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3409c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3410c0eae66eSBenny Halevy if (unlikely(!p)) 3411c0eae66eSBenny Halevy goto out_overflow; 3412cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 341399baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 341428331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 341599baf625SManoj Naik } 34163110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3417409924e4STrond Myklebust return ret; 3418c0eae66eSBenny Halevy out_overflow: 3419c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3420c0eae66eSBenny Halevy return -EIO; 342199baf625SManoj Naik } 342299baf625SManoj Naik 34231da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34241da177e4SLinus Torvalds { 34258687b63aSAl Viro __be32 *p; 34261da177e4SLinus Torvalds int status = 0; 34271da177e4SLinus Torvalds 34281da177e4SLinus Torvalds *res = 0; 34291da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 34301da177e4SLinus Torvalds return -EIO; 34311da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3432c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3433c0eae66eSBenny Halevy if (unlikely(!p)) 3434c0eae66eSBenny Halevy goto out_overflow; 3435cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34361da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 34371da177e4SLinus Torvalds } 34383110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 34391da177e4SLinus Torvalds return status; 3440c0eae66eSBenny Halevy out_overflow: 3441c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3442c0eae66eSBenny Halevy return -EIO; 34431da177e4SLinus Torvalds } 34441da177e4SLinus Torvalds 34451da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34461da177e4SLinus Torvalds { 34478687b63aSAl Viro __be32 *p; 34481da177e4SLinus Torvalds int status = 0; 34491da177e4SLinus Torvalds 34501da177e4SLinus Torvalds *res = 0; 34511da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 34521da177e4SLinus Torvalds return -EIO; 34531da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3454c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3455c0eae66eSBenny Halevy if (unlikely(!p)) 3456c0eae66eSBenny Halevy goto out_overflow; 3457cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34581da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 34591da177e4SLinus Torvalds } 34603110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 34611da177e4SLinus Torvalds return status; 3462c0eae66eSBenny Halevy out_overflow: 3463c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3464c0eae66eSBenny Halevy return -EIO; 34651da177e4SLinus Torvalds } 34661da177e4SLinus Torvalds 34671da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34681da177e4SLinus Torvalds { 34698687b63aSAl Viro __be32 *p; 34701da177e4SLinus Torvalds int status = 0; 34711da177e4SLinus Torvalds 34721da177e4SLinus Torvalds *res = 0; 34731da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 34741da177e4SLinus Torvalds return -EIO; 34751da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3476c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3477c0eae66eSBenny Halevy if (unlikely(!p)) 3478c0eae66eSBenny Halevy goto out_overflow; 3479cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34801da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 34811da177e4SLinus Torvalds } 34823110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 34831da177e4SLinus Torvalds return status; 3484c0eae66eSBenny Halevy out_overflow: 3485c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3486c0eae66eSBenny Halevy return -EIO; 34871da177e4SLinus Torvalds } 34881da177e4SLinus Torvalds 34897aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 34907aaa0b3bSManoj Naik { 3491464ad6b1SChuck Lever u32 n; 34928687b63aSAl Viro __be32 *p; 34937aaa0b3bSManoj Naik int status = 0; 34947aaa0b3bSManoj Naik 3495c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3496c0eae66eSBenny Halevy if (unlikely(!p)) 3497c0eae66eSBenny Halevy goto out_overflow; 3498cccddf4fSBenny Halevy n = be32_to_cpup(p); 349933a43f28SAndy Adamson if (n == 0) 350033a43f28SAndy Adamson goto root_path; 350102a2976cSChuck Lever dprintk("pathname4: "); 35027aaa0b3bSManoj Naik path->ncomponents = 0; 35037aaa0b3bSManoj Naik while (path->ncomponents < n) { 35047aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 35057aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 35067aaa0b3bSManoj Naik if (unlikely(status != 0)) 35077aaa0b3bSManoj Naik goto out_eio; 350802a2976cSChuck Lever if (unlikely(nfs_debug & NFSDBG_XDR)) 350902a2976cSChuck Lever pr_cont("%s%.*s ", 351002a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 351102a2976cSChuck Lever component->len, component->data); 35127aaa0b3bSManoj Naik if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 35137aaa0b3bSManoj Naik path->ncomponents++; 35147aaa0b3bSManoj Naik else { 35157aaa0b3bSManoj Naik dprintk("cannot parse %d components in path\n", n); 35167aaa0b3bSManoj Naik goto out_eio; 35177aaa0b3bSManoj Naik } 35187aaa0b3bSManoj Naik } 35197aaa0b3bSManoj Naik out: 35207aaa0b3bSManoj Naik return status; 352133a43f28SAndy Adamson root_path: 352233a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 352333a43f28SAndy Adamson path->ncomponents = 1; 352433a43f28SAndy Adamson path->components[0].len=0; 352533a43f28SAndy Adamson path->components[0].data=NULL; 352602a2976cSChuck Lever dprintk("pathname4: /\n"); 352733a43f28SAndy Adamson goto out; 35287aaa0b3bSManoj Naik out_eio: 35297aaa0b3bSManoj Naik dprintk(" status %d", status); 35307aaa0b3bSManoj Naik status = -EIO; 35317aaa0b3bSManoj Naik goto out; 3532c0eae66eSBenny Halevy out_overflow: 3533c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3534c0eae66eSBenny Halevy return -EIO; 35357aaa0b3bSManoj Naik } 35367aaa0b3bSManoj Naik 35377aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3538683b57b4STrond Myklebust { 3539683b57b4STrond Myklebust int n; 35408687b63aSAl Viro __be32 *p; 3541683b57b4STrond Myklebust int status = -EIO; 3542683b57b4STrond Myklebust 3543683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3544683b57b4STrond Myklebust goto out; 3545683b57b4STrond Myklebust status = 0; 3546683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3547683b57b4STrond Myklebust goto out; 35488b7e3f49STrond Myklebust status = -EIO; 35498b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 35508b7e3f49STrond Myklebust if (unlikely(res == NULL)) 35518b7e3f49STrond Myklebust goto out; 355202a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 35537aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3554683b57b4STrond Myklebust if (unlikely(status != 0)) 3555683b57b4STrond Myklebust goto out; 3556c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3557c0eae66eSBenny Halevy if (unlikely(!p)) 3558c0eae66eSBenny Halevy goto out_overflow; 3559cccddf4fSBenny Halevy n = be32_to_cpup(p); 3560683b57b4STrond Myklebust if (n <= 0) 3561683b57b4STrond Myklebust goto out_eio; 3562683b57b4STrond Myklebust res->nlocations = 0; 3563683b57b4STrond Myklebust while (res->nlocations < n) { 3564464ad6b1SChuck Lever u32 m; 35657aaa0b3bSManoj Naik struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 3566683b57b4STrond Myklebust 3567c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3568c0eae66eSBenny Halevy if (unlikely(!p)) 3569c0eae66eSBenny Halevy goto out_overflow; 3570cccddf4fSBenny Halevy m = be32_to_cpup(p); 35717aaa0b3bSManoj Naik 35727aaa0b3bSManoj Naik loc->nservers = 0; 357302a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 35747aaa0b3bSManoj Naik while (loc->nservers < m) { 35757aaa0b3bSManoj Naik struct nfs4_string *server = &loc->servers[loc->nservers]; 35767aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &server->len, &server->data); 3577683b57b4STrond Myklebust if (unlikely(status != 0)) 3578683b57b4STrond Myklebust goto out_eio; 35797aaa0b3bSManoj Naik dprintk("%s ", server->data); 35807aaa0b3bSManoj Naik if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) 35817aaa0b3bSManoj Naik loc->nservers++; 35827aaa0b3bSManoj Naik else { 3583464ad6b1SChuck Lever unsigned int i; 3584464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3585464ad6b1SChuck Lever "returned for location %u\n", 35863110ff80SHarvey Harrison __func__, 3587464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3588464ad6b1SChuck Lever m, res->nlocations); 35897aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 35902e42c3e2STrond Myklebust unsigned int len; 35917aaa0b3bSManoj Naik char *data; 35927aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3593683b57b4STrond Myklebust if (unlikely(status != 0)) 3594683b57b4STrond Myklebust goto out_eio; 35957aaa0b3bSManoj Naik } 35967aaa0b3bSManoj Naik } 35977aaa0b3bSManoj Naik } 35987aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 35997aaa0b3bSManoj Naik if (unlikely(status != 0)) 36007aaa0b3bSManoj Naik goto out_eio; 36017aaa0b3bSManoj Naik if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) 3602683b57b4STrond Myklebust res->nlocations++; 3603683b57b4STrond Myklebust } 3604409924e4STrond Myklebust if (res->nlocations != 0) 360581934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3606683b57b4STrond Myklebust out: 36073110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3608683b57b4STrond Myklebust return status; 3609c0eae66eSBenny Halevy out_overflow: 3610c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3611683b57b4STrond Myklebust out_eio: 3612683b57b4STrond Myklebust status = -EIO; 3613683b57b4STrond Myklebust goto out; 3614683b57b4STrond Myklebust } 3615683b57b4STrond Myklebust 36161da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36171da177e4SLinus Torvalds { 36188687b63aSAl Viro __be32 *p; 36191da177e4SLinus Torvalds int status = 0; 36201da177e4SLinus Torvalds 36211da177e4SLinus Torvalds *res = 0; 36221da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 36231da177e4SLinus Torvalds return -EIO; 36241da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3625c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3626c0eae66eSBenny Halevy if (unlikely(!p)) 3627c0eae66eSBenny Halevy goto out_overflow; 3628cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36291da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 36301da177e4SLinus Torvalds } 36313110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 36321da177e4SLinus Torvalds return status; 3633c0eae66eSBenny Halevy out_overflow: 3634c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3635c0eae66eSBenny Halevy return -EIO; 36361da177e4SLinus Torvalds } 36371da177e4SLinus Torvalds 36381da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 36391da177e4SLinus Torvalds { 36408687b63aSAl Viro __be32 *p; 36411da177e4SLinus Torvalds int status = 0; 36421da177e4SLinus Torvalds 36431da177e4SLinus Torvalds *maxlink = 1; 36441da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 36451da177e4SLinus Torvalds return -EIO; 36461da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3647c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3648c0eae66eSBenny Halevy if (unlikely(!p)) 3649c0eae66eSBenny Halevy goto out_overflow; 3650cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 36511da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 36521da177e4SLinus Torvalds } 36533110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 36541da177e4SLinus Torvalds return status; 3655c0eae66eSBenny Halevy out_overflow: 3656c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3657c0eae66eSBenny Halevy return -EIO; 36581da177e4SLinus Torvalds } 36591da177e4SLinus Torvalds 36601da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 36611da177e4SLinus Torvalds { 36628687b63aSAl Viro __be32 *p; 36631da177e4SLinus Torvalds int status = 0; 36641da177e4SLinus Torvalds 36651da177e4SLinus Torvalds *maxname = 1024; 36661da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 36671da177e4SLinus Torvalds return -EIO; 36681da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3669c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3670c0eae66eSBenny Halevy if (unlikely(!p)) 3671c0eae66eSBenny Halevy goto out_overflow; 3672cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 36731da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 36741da177e4SLinus Torvalds } 36753110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 36761da177e4SLinus Torvalds return status; 3677c0eae66eSBenny Halevy out_overflow: 3678c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3679c0eae66eSBenny Halevy return -EIO; 36801da177e4SLinus Torvalds } 36811da177e4SLinus Torvalds 36821da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36831da177e4SLinus Torvalds { 36848687b63aSAl Viro __be32 *p; 36851da177e4SLinus Torvalds int status = 0; 36861da177e4SLinus Torvalds 36871da177e4SLinus Torvalds *res = 1024; 36881da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 36891da177e4SLinus Torvalds return -EIO; 36901da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 36911da177e4SLinus Torvalds uint64_t maxread; 3692c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3693c0eae66eSBenny Halevy if (unlikely(!p)) 3694c0eae66eSBenny Halevy goto out_overflow; 3695cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 36961da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 36971da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 36981da177e4SLinus Torvalds *res = (uint32_t)maxread; 36991da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 37001da177e4SLinus Torvalds } 37013110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 37021da177e4SLinus Torvalds return status; 3703c0eae66eSBenny Halevy out_overflow: 3704c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3705c0eae66eSBenny Halevy return -EIO; 37061da177e4SLinus Torvalds } 37071da177e4SLinus Torvalds 37081da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37091da177e4SLinus Torvalds { 37108687b63aSAl Viro __be32 *p; 37111da177e4SLinus Torvalds int status = 0; 37121da177e4SLinus Torvalds 37131da177e4SLinus Torvalds *res = 1024; 37141da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 37151da177e4SLinus Torvalds return -EIO; 37161da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 37171da177e4SLinus Torvalds uint64_t maxwrite; 3718c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3719c0eae66eSBenny Halevy if (unlikely(!p)) 3720c0eae66eSBenny Halevy goto out_overflow; 3721cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 37221da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 37231da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 37241da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 37251da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 37261da177e4SLinus Torvalds } 37273110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 37281da177e4SLinus Torvalds return status; 3729c0eae66eSBenny Halevy out_overflow: 3730c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3731c0eae66eSBenny Halevy return -EIO; 37321da177e4SLinus Torvalds } 37331da177e4SLinus Torvalds 3734bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 37351da177e4SLinus Torvalds { 3736bca79478STrond Myklebust uint32_t tmp; 37378687b63aSAl Viro __be32 *p; 3738409924e4STrond Myklebust int ret = 0; 37391da177e4SLinus Torvalds 37401da177e4SLinus Torvalds *mode = 0; 37411da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 37421da177e4SLinus Torvalds return -EIO; 37431da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3744c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3745c0eae66eSBenny Halevy if (unlikely(!p)) 3746c0eae66eSBenny Halevy goto out_overflow; 3747cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3748bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 37491da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3750409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 37511da177e4SLinus Torvalds } 37523110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3753409924e4STrond Myklebust return ret; 3754c0eae66eSBenny Halevy out_overflow: 3755c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3756c0eae66eSBenny Halevy return -EIO; 37571da177e4SLinus Torvalds } 37581da177e4SLinus Torvalds 37591da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 37601da177e4SLinus Torvalds { 37618687b63aSAl Viro __be32 *p; 3762409924e4STrond Myklebust int ret = 0; 37631da177e4SLinus Torvalds 37641da177e4SLinus Torvalds *nlink = 1; 37651da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 37661da177e4SLinus Torvalds return -EIO; 37671da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3768c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3769c0eae66eSBenny Halevy if (unlikely(!p)) 3770c0eae66eSBenny Halevy goto out_overflow; 3771cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 37721da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3773409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 37741da177e4SLinus Torvalds } 37753110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3776409924e4STrond Myklebust return ret; 3777c0eae66eSBenny Halevy out_overflow: 3778c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3779c0eae66eSBenny Halevy return -EIO; 37801da177e4SLinus Torvalds } 37811da177e4SLinus Torvalds 378280e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 37836926afd1STrond Myklebust const struct nfs_server *server, uint32_t *uid, 37846926afd1STrond Myklebust struct nfs4_string *owner_name) 37851da177e4SLinus Torvalds { 37868687b63aSAl Viro uint32_t len; 37878687b63aSAl Viro __be32 *p; 3788409924e4STrond Myklebust int ret = 0; 37891da177e4SLinus Torvalds 37901da177e4SLinus Torvalds *uid = -2; 37911da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 37921da177e4SLinus Torvalds return -EIO; 37931da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3794c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3795c0eae66eSBenny Halevy if (unlikely(!p)) 3796c0eae66eSBenny Halevy goto out_overflow; 3797cccddf4fSBenny Halevy len = be32_to_cpup(p); 3798c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3799c0eae66eSBenny Halevy if (unlikely(!p)) 3800c0eae66eSBenny Halevy goto out_overflow; 38016926afd1STrond Myklebust if (owner_name != NULL) { 38026926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 38036926afd1STrond Myklebust if (owner_name->data != NULL) { 38046926afd1STrond Myklebust owner_name->len = len; 38056926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 38066926afd1STrond Myklebust } 380780e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3808e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3809409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3810409924e4STrond Myklebust else 38111da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 38123110ff80SHarvey Harrison __func__); 38131da177e4SLinus Torvalds } else 3814fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 38153110ff80SHarvey Harrison __func__, len); 38161da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 38171da177e4SLinus Torvalds } 38183110ff80SHarvey Harrison dprintk("%s: uid=%d\n", __func__, (int)*uid); 3819409924e4STrond Myklebust return ret; 3820c0eae66eSBenny Halevy out_overflow: 3821c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3822c0eae66eSBenny Halevy return -EIO; 38231da177e4SLinus Torvalds } 38241da177e4SLinus Torvalds 382580e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 38266926afd1STrond Myklebust const struct nfs_server *server, uint32_t *gid, 38276926afd1STrond Myklebust struct nfs4_string *group_name) 38281da177e4SLinus Torvalds { 38298687b63aSAl Viro uint32_t len; 38308687b63aSAl Viro __be32 *p; 3831409924e4STrond Myklebust int ret = 0; 38321da177e4SLinus Torvalds 38331da177e4SLinus Torvalds *gid = -2; 38341da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 38351da177e4SLinus Torvalds return -EIO; 38361da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3837c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3838c0eae66eSBenny Halevy if (unlikely(!p)) 3839c0eae66eSBenny Halevy goto out_overflow; 3840cccddf4fSBenny Halevy len = be32_to_cpup(p); 3841c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3842c0eae66eSBenny Halevy if (unlikely(!p)) 3843c0eae66eSBenny Halevy goto out_overflow; 38446926afd1STrond Myklebust if (group_name != NULL) { 38456926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 38466926afd1STrond Myklebust if (group_name->data != NULL) { 38476926afd1STrond Myklebust group_name->len = len; 38486926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 38496926afd1STrond Myklebust } 385080e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3851e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3852409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3853409924e4STrond Myklebust else 38541da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 38553110ff80SHarvey Harrison __func__); 38561da177e4SLinus Torvalds } else 3857fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 38583110ff80SHarvey Harrison __func__, len); 38591da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 38601da177e4SLinus Torvalds } 38613110ff80SHarvey Harrison dprintk("%s: gid=%d\n", __func__, (int)*gid); 3862409924e4STrond Myklebust return ret; 3863c0eae66eSBenny Halevy out_overflow: 3864c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3865c0eae66eSBenny Halevy return -EIO; 38661da177e4SLinus Torvalds } 38671da177e4SLinus Torvalds 38681da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 38691da177e4SLinus Torvalds { 38708687b63aSAl Viro uint32_t major = 0, minor = 0; 38718687b63aSAl Viro __be32 *p; 3872409924e4STrond Myklebust int ret = 0; 38731da177e4SLinus Torvalds 38741da177e4SLinus Torvalds *rdev = MKDEV(0,0); 38751da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 38761da177e4SLinus Torvalds return -EIO; 38771da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 38781da177e4SLinus Torvalds dev_t tmp; 38791da177e4SLinus Torvalds 3880c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3881c0eae66eSBenny Halevy if (unlikely(!p)) 3882c0eae66eSBenny Halevy goto out_overflow; 38836f723f77SBenny Halevy major = be32_to_cpup(p++); 3884cccddf4fSBenny Halevy minor = be32_to_cpup(p); 38851da177e4SLinus Torvalds tmp = MKDEV(major, minor); 38861da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 38871da177e4SLinus Torvalds *rdev = tmp; 38881da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3889409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 38901da177e4SLinus Torvalds } 38913110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3892409924e4STrond Myklebust return ret; 3893c0eae66eSBenny Halevy out_overflow: 3894c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3895c0eae66eSBenny Halevy return -EIO; 38961da177e4SLinus Torvalds } 38971da177e4SLinus Torvalds 38981da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38991da177e4SLinus Torvalds { 39008687b63aSAl Viro __be32 *p; 39011da177e4SLinus Torvalds int status = 0; 39021da177e4SLinus Torvalds 39031da177e4SLinus Torvalds *res = 0; 39041da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 39051da177e4SLinus Torvalds return -EIO; 39061da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3907c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3908c0eae66eSBenny Halevy if (unlikely(!p)) 3909c0eae66eSBenny Halevy goto out_overflow; 3910cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39111da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 39121da177e4SLinus Torvalds } 39133110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 39141da177e4SLinus Torvalds return status; 3915c0eae66eSBenny Halevy out_overflow: 3916c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3917c0eae66eSBenny Halevy return -EIO; 39181da177e4SLinus Torvalds } 39191da177e4SLinus Torvalds 39201da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39211da177e4SLinus Torvalds { 39228687b63aSAl Viro __be32 *p; 39231da177e4SLinus Torvalds int status = 0; 39241da177e4SLinus Torvalds 39251da177e4SLinus Torvalds *res = 0; 39261da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 39271da177e4SLinus Torvalds return -EIO; 39281da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3929c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3930c0eae66eSBenny Halevy if (unlikely(!p)) 3931c0eae66eSBenny Halevy goto out_overflow; 3932cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39331da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 39341da177e4SLinus Torvalds } 39353110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 39361da177e4SLinus Torvalds return status; 3937c0eae66eSBenny Halevy out_overflow: 3938c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3939c0eae66eSBenny Halevy return -EIO; 39401da177e4SLinus Torvalds } 39411da177e4SLinus Torvalds 39421da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39431da177e4SLinus Torvalds { 39448687b63aSAl Viro __be32 *p; 39451da177e4SLinus Torvalds int status = 0; 39461da177e4SLinus Torvalds 39471da177e4SLinus Torvalds *res = 0; 39481da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 39491da177e4SLinus Torvalds return -EIO; 39501da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 3951c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3952c0eae66eSBenny Halevy if (unlikely(!p)) 3953c0eae66eSBenny Halevy goto out_overflow; 3954cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39551da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 39561da177e4SLinus Torvalds } 39573110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 39581da177e4SLinus Torvalds return status; 3959c0eae66eSBenny Halevy out_overflow: 3960c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3961c0eae66eSBenny Halevy return -EIO; 39621da177e4SLinus Torvalds } 39631da177e4SLinus Torvalds 39641da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 39651da177e4SLinus Torvalds { 39668687b63aSAl Viro __be32 *p; 3967409924e4STrond Myklebust int ret = 0; 39681da177e4SLinus Torvalds 39691da177e4SLinus Torvalds *used = 0; 39701da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 39711da177e4SLinus Torvalds return -EIO; 39721da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 3973c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3974c0eae66eSBenny Halevy if (unlikely(!p)) 3975c0eae66eSBenny Halevy goto out_overflow; 3976cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 39771da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 3978409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 39791da177e4SLinus Torvalds } 39803110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 39811da177e4SLinus Torvalds (unsigned long long)*used); 3982409924e4STrond Myklebust return ret; 3983c0eae66eSBenny Halevy out_overflow: 3984c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3985c0eae66eSBenny Halevy return -EIO; 39861da177e4SLinus Torvalds } 39871da177e4SLinus Torvalds 39881da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 39891da177e4SLinus Torvalds { 39908687b63aSAl Viro __be32 *p; 39911da177e4SLinus Torvalds uint64_t sec; 39921da177e4SLinus Torvalds uint32_t nsec; 39931da177e4SLinus Torvalds 3994c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3995c0eae66eSBenny Halevy if (unlikely(!p)) 3996c0eae66eSBenny Halevy goto out_overflow; 39973ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 3998cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 39991da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 40001da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 40011da177e4SLinus Torvalds return 0; 4002c0eae66eSBenny Halevy out_overflow: 4003c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4004c0eae66eSBenny Halevy return -EIO; 40051da177e4SLinus Torvalds } 40061da177e4SLinus Torvalds 40071da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40081da177e4SLinus Torvalds { 40091da177e4SLinus Torvalds int status = 0; 40101da177e4SLinus Torvalds 40111da177e4SLinus Torvalds time->tv_sec = 0; 40121da177e4SLinus Torvalds time->tv_nsec = 0; 40131da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 40141da177e4SLinus Torvalds return -EIO; 40151da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 40161da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4017409924e4STrond Myklebust if (status == 0) 4018409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 40191da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 40201da177e4SLinus Torvalds } 40213110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 40221da177e4SLinus Torvalds return status; 40231da177e4SLinus Torvalds } 40241da177e4SLinus Torvalds 40251da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40261da177e4SLinus Torvalds { 40271da177e4SLinus Torvalds int status = 0; 40281da177e4SLinus Torvalds 40291da177e4SLinus Torvalds time->tv_sec = 0; 40301da177e4SLinus Torvalds time->tv_nsec = 0; 40311da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 40321da177e4SLinus Torvalds return -EIO; 40331da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 40341da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4035409924e4STrond Myklebust if (status == 0) 4036409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 40371da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 40381da177e4SLinus Torvalds } 40393110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 40401da177e4SLinus Torvalds return status; 40411da177e4SLinus Torvalds } 40421da177e4SLinus Torvalds 404355b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 404455b6e774SRicardo Labiaga struct timespec *time) 404555b6e774SRicardo Labiaga { 404655b6e774SRicardo Labiaga int status = 0; 404755b6e774SRicardo Labiaga 404855b6e774SRicardo Labiaga time->tv_sec = 0; 404955b6e774SRicardo Labiaga time->tv_nsec = 0; 405055b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 405155b6e774SRicardo Labiaga return -EIO; 405255b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 405355b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 405455b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 405555b6e774SRicardo Labiaga } 405655b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 405755b6e774SRicardo Labiaga (long)time->tv_nsec); 405855b6e774SRicardo Labiaga return status; 405955b6e774SRicardo Labiaga } 406055b6e774SRicardo Labiaga 40611da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40621da177e4SLinus Torvalds { 40631da177e4SLinus Torvalds int status = 0; 40641da177e4SLinus Torvalds 40651da177e4SLinus Torvalds time->tv_sec = 0; 40661da177e4SLinus Torvalds time->tv_nsec = 0; 40671da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 40681da177e4SLinus Torvalds return -EIO; 40691da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 40701da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4071409924e4STrond Myklebust if (status == 0) 4072409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 40731da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 40741da177e4SLinus Torvalds } 40753110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 40761da177e4SLinus Torvalds return status; 40771da177e4SLinus Torvalds } 40781da177e4SLinus Torvalds 40798687b63aSAl Viro static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) 40801da177e4SLinus Torvalds { 40811da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 40821da177e4SLinus Torvalds unsigned int nwords = xdr->p - savep; 40831da177e4SLinus Torvalds 40841da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4085fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4086fe82a183SChuck Lever "%u %c %u\n", 40873110ff80SHarvey Harrison __func__, 40881da177e4SLinus Torvalds attrwords << 2, 40891da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 40901da177e4SLinus Torvalds nwords << 2); 40911da177e4SLinus Torvalds return -EIO; 40921da177e4SLinus Torvalds } 40931da177e4SLinus Torvalds return 0; 40941da177e4SLinus Torvalds } 40951da177e4SLinus Torvalds 40961da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 40971da177e4SLinus Torvalds { 40988687b63aSAl Viro __be32 *p; 40991da177e4SLinus Torvalds 4100c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4101c0eae66eSBenny Halevy if (unlikely(!p)) 4102c0eae66eSBenny Halevy goto out_overflow; 41036f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 41043ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4105cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 41061da177e4SLinus Torvalds return 0; 4107c0eae66eSBenny Halevy out_overflow: 4108c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4109c0eae66eSBenny Halevy return -EIO; 41101da177e4SLinus Torvalds } 41111da177e4SLinus Torvalds 41121da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 41131da177e4SLinus Torvalds { 41148687b63aSAl Viro __be32 *p; 41151da177e4SLinus Torvalds uint32_t supp, acc; 41161da177e4SLinus Torvalds int status; 41171da177e4SLinus Torvalds 41181da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 41191da177e4SLinus Torvalds if (status) 41201da177e4SLinus Torvalds return status; 4121c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4122c0eae66eSBenny Halevy if (unlikely(!p)) 4123c0eae66eSBenny Halevy goto out_overflow; 41246f723f77SBenny Halevy supp = be32_to_cpup(p++); 4125cccddf4fSBenny Halevy acc = be32_to_cpup(p); 41261da177e4SLinus Torvalds access->supported = supp; 41271da177e4SLinus Torvalds access->access = acc; 41281da177e4SLinus Torvalds return 0; 4129c0eae66eSBenny Halevy out_overflow: 4130c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4131c0eae66eSBenny Halevy return -EIO; 41321da177e4SLinus Torvalds } 41331da177e4SLinus Torvalds 413407d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 41351da177e4SLinus Torvalds { 41368687b63aSAl Viro __be32 *p; 413707d30434SBenny Halevy 413807d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 413907d30434SBenny Halevy if (likely(p)) { 414007d30434SBenny Halevy memcpy(buf, p, len); 414107d30434SBenny Halevy return 0; 414207d30434SBenny Halevy } 414307d30434SBenny Halevy print_overflow_msg(__func__, xdr); 414407d30434SBenny Halevy return -EIO; 414507d30434SBenny Halevy } 414607d30434SBenny Halevy 414707d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 414807d30434SBenny Halevy { 41492d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 41501da177e4SLinus Torvalds } 41511da177e4SLinus Torvalds 41521da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 41531da177e4SLinus Torvalds { 41541da177e4SLinus Torvalds int status; 41551da177e4SLinus Torvalds 41561da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4157c1d51931STrond Myklebust if (status != -EIO) 4158c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 415907d30434SBenny Halevy if (!status) 416007d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 41611da177e4SLinus Torvalds return status; 41621da177e4SLinus Torvalds } 41631da177e4SLinus Torvalds 4164db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4165db942bbdSBenny Halevy { 4166cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 41671da177e4SLinus Torvalds } 41681da177e4SLinus Torvalds 41691da177e4SLinus Torvalds static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) 41701da177e4SLinus Torvalds { 41711da177e4SLinus Torvalds int status; 41721da177e4SLinus Torvalds 41731da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4174db942bbdSBenny Halevy if (!status) 4175db942bbdSBenny Halevy status = decode_verifier(xdr, res->verf->verifier); 41761da177e4SLinus Torvalds return status; 41771da177e4SLinus Torvalds } 41781da177e4SLinus Torvalds 41791da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 41801da177e4SLinus Torvalds { 41818687b63aSAl Viro __be32 *p; 41821da177e4SLinus Torvalds uint32_t bmlen; 41831da177e4SLinus Torvalds int status; 41841da177e4SLinus Torvalds 41851da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 41861da177e4SLinus Torvalds if (status) 41871da177e4SLinus Torvalds return status; 41881da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 41891da177e4SLinus Torvalds return status; 4190c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4191c0eae66eSBenny Halevy if (unlikely(!p)) 4192c0eae66eSBenny Halevy goto out_overflow; 4193cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4194c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4195c0eae66eSBenny Halevy if (likely(p)) 41961da177e4SLinus Torvalds return 0; 4197c0eae66eSBenny Halevy out_overflow: 4198c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4199c0eae66eSBenny Halevy return -EIO; 42001da177e4SLinus Torvalds } 42011da177e4SLinus Torvalds 42021da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 42031da177e4SLinus Torvalds { 42048687b63aSAl Viro __be32 *savep; 4205dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 42061da177e4SLinus Torvalds int status; 42071da177e4SLinus Torvalds 42081da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42091da177e4SLinus Torvalds goto xdr_error; 42101da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42111da177e4SLinus Torvalds goto xdr_error; 42121da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42131da177e4SLinus Torvalds goto xdr_error; 42141da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 42151da177e4SLinus Torvalds goto xdr_error; 4216264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4217264e6351SChuck Lever &res->fh_expire_type)) != 0) 4218264e6351SChuck Lever goto xdr_error; 42191da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 42201da177e4SLinus Torvalds goto xdr_error; 42211da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 42221da177e4SLinus Torvalds goto xdr_error; 42231da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 42241da177e4SLinus Torvalds goto xdr_error; 42251da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42261da177e4SLinus Torvalds xdr_error: 42273110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42281da177e4SLinus Torvalds return status; 42291da177e4SLinus Torvalds } 42301da177e4SLinus Torvalds 42311da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 42321da177e4SLinus Torvalds { 42338687b63aSAl Viro __be32 *savep; 4234dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 42351da177e4SLinus Torvalds int status; 42361da177e4SLinus Torvalds 42371da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42381da177e4SLinus Torvalds goto xdr_error; 42391da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42401da177e4SLinus Torvalds goto xdr_error; 42411da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42421da177e4SLinus Torvalds goto xdr_error; 42431da177e4SLinus Torvalds 42441da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 42451da177e4SLinus Torvalds goto xdr_error; 42461da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 42471da177e4SLinus Torvalds goto xdr_error; 42481da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 42491da177e4SLinus Torvalds goto xdr_error; 42501da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 42511da177e4SLinus Torvalds goto xdr_error; 42521da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 42531da177e4SLinus Torvalds goto xdr_error; 42541da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 42551da177e4SLinus Torvalds goto xdr_error; 42561da177e4SLinus Torvalds 42571da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42581da177e4SLinus Torvalds xdr_error: 42593110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42601da177e4SLinus Torvalds return status; 42611da177e4SLinus Torvalds } 42621da177e4SLinus Torvalds 42631da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 42641da177e4SLinus Torvalds { 42658687b63aSAl Viro __be32 *savep; 4266dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 42671da177e4SLinus Torvalds int status; 42681da177e4SLinus Torvalds 42691da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42701da177e4SLinus Torvalds goto xdr_error; 42711da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42721da177e4SLinus Torvalds goto xdr_error; 42731da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42741da177e4SLinus Torvalds goto xdr_error; 42751da177e4SLinus Torvalds 42761da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 42771da177e4SLinus Torvalds goto xdr_error; 42781da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 42791da177e4SLinus Torvalds goto xdr_error; 42801da177e4SLinus Torvalds 42811da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42821da177e4SLinus Torvalds xdr_error: 42833110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42841da177e4SLinus Torvalds return status; 42851da177e4SLinus Torvalds } 42861da177e4SLinus Torvalds 4287ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4288ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 42898b7e3f49STrond Myklebust struct nfs4_fs_locations *fs_loc, 42906926afd1STrond Myklebust const struct nfs_server *server) 42911da177e4SLinus Torvalds { 4292bca79478STrond Myklebust int status; 4293bca79478STrond Myklebust umode_t fmode = 0; 4294ae42c70aSBryan Schumaker uint32_t type; 4295ee7b75fcSTrond Myklebust int32_t err; 42961da177e4SLinus Torvalds 4297f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4298f26c7a78STrond Myklebust if (status < 0) 42991da177e4SLinus Torvalds goto xdr_error; 4300409924e4STrond Myklebust fattr->mode = 0; 4301409924e4STrond Myklebust if (status != 0) { 4302409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4303409924e4STrond Myklebust fattr->valid |= status; 4304409924e4STrond Myklebust } 43051da177e4SLinus Torvalds 4306f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4307f26c7a78STrond Myklebust if (status < 0) 43081da177e4SLinus Torvalds goto xdr_error; 4309409924e4STrond Myklebust fattr->valid |= status; 4310f26c7a78STrond Myklebust 4311f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4312f26c7a78STrond Myklebust if (status < 0) 43131da177e4SLinus Torvalds goto xdr_error; 4314409924e4STrond Myklebust fattr->valid |= status; 4315f26c7a78STrond Myklebust 4316f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4317f26c7a78STrond Myklebust if (status < 0) 43181da177e4SLinus Torvalds goto xdr_error; 4319409924e4STrond Myklebust fattr->valid |= status; 4320f26c7a78STrond Myklebust 4321ee7b75fcSTrond Myklebust err = 0; 4322ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4323ae42c70aSBryan Schumaker if (status < 0) 4324ae42c70aSBryan Schumaker goto xdr_error; 4325ee7b75fcSTrond Myklebust if (err == -NFS4ERR_WRONGSEC) 4326ee7b75fcSTrond Myklebust nfs_fixup_secinfo_attributes(fattr, fh); 4327ae42c70aSBryan Schumaker 4328ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4329ae42c70aSBryan Schumaker if (status < 0) 4330ae42c70aSBryan Schumaker goto xdr_error; 4331ae42c70aSBryan Schumaker 4332f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4333f26c7a78STrond Myklebust if (status < 0) 43341da177e4SLinus Torvalds goto xdr_error; 4335409924e4STrond Myklebust fattr->valid |= status; 4336f26c7a78STrond Myklebust 43378b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4338f26c7a78STrond Myklebust if (status < 0) 4339683b57b4STrond Myklebust goto xdr_error; 4340409924e4STrond Myklebust fattr->valid |= status; 4341f26c7a78STrond Myklebust 4342f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4343f26c7a78STrond Myklebust if (status < 0) 43441da177e4SLinus Torvalds goto xdr_error; 4345409924e4STrond Myklebust if (status != 0) { 43461da177e4SLinus Torvalds fattr->mode |= fmode; 4347409924e4STrond Myklebust fattr->valid |= status; 4348409924e4STrond Myklebust } 4349f26c7a78STrond Myklebust 4350f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4351f26c7a78STrond Myklebust if (status < 0) 43521da177e4SLinus Torvalds goto xdr_error; 4353409924e4STrond Myklebust fattr->valid |= status; 4354f26c7a78STrond Myklebust 43556926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4356f26c7a78STrond Myklebust if (status < 0) 43571da177e4SLinus Torvalds goto xdr_error; 4358409924e4STrond Myklebust fattr->valid |= status; 4359f26c7a78STrond Myklebust 43606926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4361f26c7a78STrond Myklebust if (status < 0) 43621da177e4SLinus Torvalds goto xdr_error; 4363409924e4STrond Myklebust fattr->valid |= status; 4364f26c7a78STrond Myklebust 4365f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4366f26c7a78STrond Myklebust if (status < 0) 43671da177e4SLinus Torvalds goto xdr_error; 4368409924e4STrond Myklebust fattr->valid |= status; 4369f26c7a78STrond Myklebust 4370f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4371f26c7a78STrond Myklebust if (status < 0) 43721da177e4SLinus Torvalds goto xdr_error; 4373409924e4STrond Myklebust fattr->valid |= status; 4374f26c7a78STrond Myklebust 4375f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4376f26c7a78STrond Myklebust if (status < 0) 43771da177e4SLinus Torvalds goto xdr_error; 4378409924e4STrond Myklebust fattr->valid |= status; 4379f26c7a78STrond Myklebust 4380f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4381f26c7a78STrond Myklebust if (status < 0) 43821da177e4SLinus Torvalds goto xdr_error; 4383409924e4STrond Myklebust fattr->valid |= status; 4384f26c7a78STrond Myklebust 4385f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4386f26c7a78STrond Myklebust if (status < 0) 43871da177e4SLinus Torvalds goto xdr_error; 4388409924e4STrond Myklebust fattr->valid |= status; 4389f26c7a78STrond Myklebust 439028331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4391f26c7a78STrond Myklebust if (status < 0) 439299baf625SManoj Naik goto xdr_error; 4393409924e4STrond Myklebust fattr->valid |= status; 4394f26c7a78STrond Myklebust 4395ae42c70aSBryan Schumaker xdr_error: 4396ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4397ae42c70aSBryan Schumaker return status; 4398ae42c70aSBryan Schumaker } 4399ae42c70aSBryan Schumaker 4400ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 44018b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 44028b7e3f49STrond Myklebust const struct nfs_server *server) 4403ae42c70aSBryan Schumaker { 4404ae42c70aSBryan Schumaker __be32 *savep; 4405ae42c70aSBryan Schumaker uint32_t attrlen, 4406dae100c2SFred Isaman bitmap[3] = {0}; 4407ae42c70aSBryan Schumaker int status; 4408ae42c70aSBryan Schumaker 4409ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4410ae42c70aSBryan Schumaker if (status < 0) 4411ae42c70aSBryan Schumaker goto xdr_error; 4412ae42c70aSBryan Schumaker 4413ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4414ae42c70aSBryan Schumaker if (status < 0) 4415ae42c70aSBryan Schumaker goto xdr_error; 4416ae42c70aSBryan Schumaker 4417ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4418ae42c70aSBryan Schumaker if (status < 0) 4419ae42c70aSBryan Schumaker goto xdr_error; 4420ae42c70aSBryan Schumaker 44218b7e3f49STrond Myklebust status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server); 4422ae42c70aSBryan Schumaker if (status < 0) 4423ae42c70aSBryan Schumaker goto xdr_error; 4424ae42c70aSBryan Schumaker 4425f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 44261da177e4SLinus Torvalds xdr_error: 44273110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 44281da177e4SLinus Torvalds return status; 44291da177e4SLinus Torvalds } 44301da177e4SLinus Torvalds 4431ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 44326926afd1STrond Myklebust const struct nfs_server *server) 4433ae42c70aSBryan Schumaker { 44348b7e3f49STrond Myklebust return decode_getfattr_generic(xdr, fattr, NULL, NULL, server); 4435ae42c70aSBryan Schumaker } 44361da177e4SLinus Torvalds 4437504913fbSAndy Adamson /* 4438504913fbSAndy Adamson * Decode potentially multiple layout types. Currently we only support 4439504913fbSAndy Adamson * one layout driver per file system. 4440504913fbSAndy Adamson */ 4441504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, 4442504913fbSAndy Adamson uint32_t *layouttype) 4443504913fbSAndy Adamson { 4444504913fbSAndy Adamson uint32_t *p; 4445504913fbSAndy Adamson int num; 4446504913fbSAndy Adamson 4447504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4448504913fbSAndy Adamson if (unlikely(!p)) 4449504913fbSAndy Adamson goto out_overflow; 4450504913fbSAndy Adamson num = be32_to_cpup(p); 4451504913fbSAndy Adamson 4452504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4453504913fbSAndy Adamson if (num == 0) { 4454504913fbSAndy Adamson *layouttype = 0; 4455504913fbSAndy Adamson return 0; 4456504913fbSAndy Adamson } 4457504913fbSAndy Adamson if (num > 1) 4458a030889aSWeston Andros Adamson printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout " 4459a030889aSWeston Andros Adamson "drivers per filesystem not supported\n", __func__); 4460504913fbSAndy Adamson 4461504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4462504913fbSAndy Adamson p = xdr_inline_decode(xdr, num * 4); 4463504913fbSAndy Adamson if (unlikely(!p)) 4464504913fbSAndy Adamson goto out_overflow; 4465504913fbSAndy Adamson *layouttype = be32_to_cpup(p); 4466504913fbSAndy Adamson return 0; 4467504913fbSAndy Adamson out_overflow: 4468504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4469504913fbSAndy Adamson return -EIO; 4470504913fbSAndy Adamson } 4471504913fbSAndy Adamson 4472504913fbSAndy Adamson /* 4473504913fbSAndy Adamson * The type of file system exported. 4474504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4475504913fbSAndy Adamson */ 4476504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4477504913fbSAndy Adamson uint32_t *layouttype) 4478504913fbSAndy Adamson { 4479504913fbSAndy Adamson int status = 0; 4480504913fbSAndy Adamson 4481504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4482504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4483504913fbSAndy Adamson return -EIO; 4484504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4485504913fbSAndy Adamson status = decode_first_pnfs_layout_type(xdr, layouttype); 4486504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 4487504913fbSAndy Adamson } else 4488504913fbSAndy Adamson *layouttype = 0; 4489504913fbSAndy Adamson return status; 4490504913fbSAndy Adamson } 4491504913fbSAndy Adamson 4492dae100c2SFred Isaman /* 4493dae100c2SFred Isaman * The prefered block size for layout directed io 4494dae100c2SFred Isaman */ 4495dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4496dae100c2SFred Isaman uint32_t *res) 4497dae100c2SFred Isaman { 4498dae100c2SFred Isaman __be32 *p; 4499dae100c2SFred Isaman 4500dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4501dae100c2SFred Isaman *res = 0; 4502dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4503dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4504dae100c2SFred Isaman if (unlikely(!p)) { 4505dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4506dae100c2SFred Isaman return -EIO; 4507dae100c2SFred Isaman } 4508dae100c2SFred Isaman *res = be32_to_cpup(p); 4509dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4510dae100c2SFred Isaman } 4511dae100c2SFred Isaman return 0; 4512dae100c2SFred Isaman } 4513dae100c2SFred Isaman 45141da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 45151da177e4SLinus Torvalds { 45168687b63aSAl Viro __be32 *savep; 4517dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 45181da177e4SLinus Torvalds int status; 45191da177e4SLinus Torvalds 45201da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45211da177e4SLinus Torvalds goto xdr_error; 45221da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45231da177e4SLinus Torvalds goto xdr_error; 45241da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45251da177e4SLinus Torvalds goto xdr_error; 45261da177e4SLinus Torvalds 45271da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 45281da177e4SLinus Torvalds 45291da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 45301da177e4SLinus Torvalds goto xdr_error; 45311da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 45321da177e4SLinus Torvalds goto xdr_error; 45331da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 45341da177e4SLinus Torvalds goto xdr_error; 45351da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 45361da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 45371da177e4SLinus Torvalds goto xdr_error; 45381da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 453955b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 454055b6e774SRicardo Labiaga if (status != 0) 454155b6e774SRicardo Labiaga goto xdr_error; 4542504913fbSAndy Adamson status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); 4543504913fbSAndy Adamson if (status != 0) 4544504913fbSAndy Adamson goto xdr_error; 4545dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4546dae100c2SFred Isaman if (status) 4547dae100c2SFred Isaman goto xdr_error; 45481da177e4SLinus Torvalds 45491da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45501da177e4SLinus Torvalds xdr_error: 45513110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45521da177e4SLinus Torvalds return status; 45531da177e4SLinus Torvalds } 45541da177e4SLinus Torvalds 45551da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 45561da177e4SLinus Torvalds { 45578687b63aSAl Viro __be32 *p; 45581da177e4SLinus Torvalds uint32_t len; 45591da177e4SLinus Torvalds int status; 45601da177e4SLinus Torvalds 45619936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 45629936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 45639936781dSTrond Myklebust 45641da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 45651da177e4SLinus Torvalds if (status) 45661da177e4SLinus Torvalds return status; 45671da177e4SLinus Torvalds 4568c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4569c0eae66eSBenny Halevy if (unlikely(!p)) 4570c0eae66eSBenny Halevy goto out_overflow; 4571cccddf4fSBenny Halevy len = be32_to_cpup(p); 45721da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 45731da177e4SLinus Torvalds return -EIO; 45741da177e4SLinus Torvalds fh->size = len; 4575c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4576c0eae66eSBenny Halevy if (unlikely(!p)) 4577c0eae66eSBenny Halevy goto out_overflow; 457899398d06SBenny Halevy memcpy(fh->data, p, len); 45791da177e4SLinus Torvalds return 0; 4580c0eae66eSBenny Halevy out_overflow: 4581c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4582c0eae66eSBenny Halevy return -EIO; 45831da177e4SLinus Torvalds } 45841da177e4SLinus Torvalds 45851da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 45861da177e4SLinus Torvalds { 45871da177e4SLinus Torvalds int status; 45881da177e4SLinus Torvalds 45891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 45901da177e4SLinus Torvalds if (status) 45911da177e4SLinus Torvalds return status; 45921da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 45931da177e4SLinus Torvalds } 45941da177e4SLinus Torvalds 45951da177e4SLinus Torvalds /* 45961da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 45971da177e4SLinus Torvalds */ 4598911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 45991da177e4SLinus Torvalds { 4600911d1aafSTrond Myklebust uint64_t offset, length, clientid; 46018687b63aSAl Viro __be32 *p; 4602911d1aafSTrond Myklebust uint32_t namelen, type; 46031da177e4SLinus Torvalds 4604babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4605c0eae66eSBenny Halevy if (unlikely(!p)) 4606c0eae66eSBenny Halevy goto out_overflow; 4607babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 46083ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4609babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4610babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4611911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4612911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4613911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4614911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4615911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4616911d1aafSTrond Myklebust if (type & 1) 4617911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4618911d1aafSTrond Myklebust fl->fl_pid = 0; 4619911d1aafSTrond Myklebust } 4620babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4621babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4622babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4623c0eae66eSBenny Halevy if (likely(p)) 46241da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4625c0eae66eSBenny Halevy out_overflow: 4626c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4627c0eae66eSBenny Halevy return -EIO; 46281da177e4SLinus Torvalds } 46291da177e4SLinus Torvalds 4630911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 46311da177e4SLinus Torvalds { 46321da177e4SLinus Torvalds int status; 46331da177e4SLinus Torvalds 46341da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4635c1d51931STrond Myklebust if (status == -EIO) 4636c1d51931STrond Myklebust goto out; 46371da177e4SLinus Torvalds if (status == 0) { 463807d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 463907d30434SBenny Halevy if (unlikely(status)) 464007d30434SBenny Halevy goto out; 46411da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4642c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4643c1d51931STrond Myklebust if (res->open_seqid != NULL) 4644c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4645c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4646c1d51931STrond Myklebust out: 46471da177e4SLinus Torvalds return status; 46481da177e4SLinus Torvalds } 46491da177e4SLinus Torvalds 4650911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 46511da177e4SLinus Torvalds { 46521da177e4SLinus Torvalds int status; 46531da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 46541da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4655911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 46561da177e4SLinus Torvalds return status; 46571da177e4SLinus Torvalds } 46581da177e4SLinus Torvalds 4659911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 46601da177e4SLinus Torvalds { 46611da177e4SLinus Torvalds int status; 46621da177e4SLinus Torvalds 46631da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4664c1d51931STrond Myklebust if (status != -EIO) 4665c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 466607d30434SBenny Halevy if (status == 0) 466707d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 46681da177e4SLinus Torvalds return status; 46691da177e4SLinus Torvalds } 46701da177e4SLinus Torvalds 4671d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4672d3c7b7ccSTrond Myklebust { 4673d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4674d3c7b7ccSTrond Myklebust } 4675d3c7b7ccSTrond Myklebust 46761da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 46771da177e4SLinus Torvalds { 46781da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 46791da177e4SLinus Torvalds } 46801da177e4SLinus Torvalds 46811da177e4SLinus Torvalds /* This is too sick! */ 46821da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 46831da177e4SLinus Torvalds { 46848687b63aSAl Viro __be32 *p; 46851da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 46861da177e4SLinus Torvalds 4687c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4688c0eae66eSBenny Halevy if (unlikely(!p)) 4689c0eae66eSBenny Halevy goto out_overflow; 46906f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 46911da177e4SLinus Torvalds switch (limit_type) { 46921da177e4SLinus Torvalds case 1: 4693cccddf4fSBenny Halevy xdr_decode_hyper(p, maxsize); 46941da177e4SLinus Torvalds break; 46951da177e4SLinus Torvalds case 2: 46966f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 4697cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 46981da177e4SLinus Torvalds *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 46991da177e4SLinus Torvalds } 47001da177e4SLinus Torvalds return 0; 4701c0eae66eSBenny Halevy out_overflow: 4702c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4703c0eae66eSBenny Halevy return -EIO; 47041da177e4SLinus Torvalds } 47051da177e4SLinus Torvalds 47061da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 47071da177e4SLinus Torvalds { 47088687b63aSAl Viro __be32 *p; 47091da177e4SLinus Torvalds uint32_t delegation_type; 471007d30434SBenny Halevy int status; 47111da177e4SLinus Torvalds 4712c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4713c0eae66eSBenny Halevy if (unlikely(!p)) 4714c0eae66eSBenny Halevy goto out_overflow; 4715cccddf4fSBenny Halevy delegation_type = be32_to_cpup(p); 47161da177e4SLinus Torvalds if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 47171da177e4SLinus Torvalds res->delegation_type = 0; 47181da177e4SLinus Torvalds return 0; 47191da177e4SLinus Torvalds } 472007d30434SBenny Halevy status = decode_stateid(xdr, &res->delegation); 472107d30434SBenny Halevy if (unlikely(status)) 472207d30434SBenny Halevy return status; 4723c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4724c0eae66eSBenny Halevy if (unlikely(!p)) 4725c0eae66eSBenny Halevy goto out_overflow; 4726cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 472705d564feSAndy Adamson 47281da177e4SLinus Torvalds switch (delegation_type) { 47291da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 47301da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 47311da177e4SLinus Torvalds break; 47321da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 47331da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 47341da177e4SLinus Torvalds if (decode_space_limit(xdr, &res->maxsize) < 0) 47351da177e4SLinus Torvalds return -EIO; 47361da177e4SLinus Torvalds } 47377539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 4738c0eae66eSBenny Halevy out_overflow: 4739c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4740c0eae66eSBenny Halevy return -EIO; 47411da177e4SLinus Torvalds } 47421da177e4SLinus Torvalds 47431da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 47441da177e4SLinus Torvalds { 47458687b63aSAl Viro __be32 *p; 4746aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 47471da177e4SLinus Torvalds int status; 47481da177e4SLinus Torvalds 47491da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN); 4750c1d51931STrond Myklebust if (status != -EIO) 4751c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 475207d30434SBenny Halevy if (!status) 475307d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 475407d30434SBenny Halevy if (unlikely(status)) 47551da177e4SLinus Torvalds return status; 47561da177e4SLinus Torvalds 47571da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 47581da177e4SLinus Torvalds 4759c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4760c0eae66eSBenny Halevy if (unlikely(!p)) 4761c0eae66eSBenny Halevy goto out_overflow; 47626f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 4763cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 47641da177e4SLinus Torvalds if (bmlen > 10) 47651da177e4SLinus Torvalds goto xdr_error; 47661da177e4SLinus Torvalds 4767c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4768c0eae66eSBenny Halevy if (unlikely(!p)) 4769c0eae66eSBenny Halevy goto out_overflow; 4770aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 4771aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 47726f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 4773aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 4774aa53ed54SJeff Layton res->attrset[i] = 0; 4775aa53ed54SJeff Layton 47761da177e4SLinus Torvalds return decode_delegation(xdr, res); 47771da177e4SLinus Torvalds xdr_error: 47783110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 47791da177e4SLinus Torvalds return -EIO; 4780c0eae66eSBenny Halevy out_overflow: 4781c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4782c0eae66eSBenny Halevy return -EIO; 47831da177e4SLinus Torvalds } 47841da177e4SLinus Torvalds 47851da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 47861da177e4SLinus Torvalds { 47871da177e4SLinus Torvalds int status; 47881da177e4SLinus Torvalds 47891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 4790c1d51931STrond Myklebust if (status != -EIO) 4791c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 479207d30434SBenny Halevy if (!status) 479307d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 47941da177e4SLinus Torvalds return status; 47951da177e4SLinus Torvalds } 47961da177e4SLinus Torvalds 47971da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 47981da177e4SLinus Torvalds { 47991da177e4SLinus Torvalds int status; 48001da177e4SLinus Torvalds 48011da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 4802c1d51931STrond Myklebust if (status != -EIO) 4803c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 480407d30434SBenny Halevy if (!status) 480507d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 48061da177e4SLinus Torvalds return status; 48071da177e4SLinus Torvalds } 48081da177e4SLinus Torvalds 48091da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 48101da177e4SLinus Torvalds { 48111da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 48121da177e4SLinus Torvalds } 48131da177e4SLinus Torvalds 48141da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 48151da177e4SLinus Torvalds { 48161da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 48171da177e4SLinus Torvalds } 48181da177e4SLinus Torvalds 48191da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 48201da177e4SLinus Torvalds { 48211da177e4SLinus Torvalds struct kvec *iov = req->rq_rcv_buf.head; 48228687b63aSAl Viro __be32 *p; 48231da177e4SLinus Torvalds uint32_t count, eof, recvd, hdrlen; 48241da177e4SLinus Torvalds int status; 48251da177e4SLinus Torvalds 48261da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 48271da177e4SLinus Torvalds if (status) 48281da177e4SLinus Torvalds return status; 4829c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4830c0eae66eSBenny Halevy if (unlikely(!p)) 4831c0eae66eSBenny Halevy goto out_overflow; 48326f723f77SBenny Halevy eof = be32_to_cpup(p++); 4833cccddf4fSBenny Halevy count = be32_to_cpup(p); 48348111f373SChuck Lever hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 48351da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 48361da177e4SLinus Torvalds if (count > recvd) { 4837fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 48381da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 48391da177e4SLinus Torvalds count = recvd; 48401da177e4SLinus Torvalds eof = 0; 48411da177e4SLinus Torvalds } 48421da177e4SLinus Torvalds xdr_read_pages(xdr, count); 48431da177e4SLinus Torvalds res->eof = eof; 48441da177e4SLinus Torvalds res->count = count; 48451da177e4SLinus Torvalds return 0; 4846c0eae66eSBenny Halevy out_overflow: 4847c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4848c0eae66eSBenny Halevy return -EIO; 48491da177e4SLinus Torvalds } 48501da177e4SLinus Torvalds 48511da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 48521da177e4SLinus Torvalds { 48531da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 48541da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4855bcecff77SChuck Lever size_t hdrlen; 4856bcecff77SChuck Lever u32 recvd, pglen = rcvbuf->page_len; 4857bcecff77SChuck Lever int status; 4858cd93710eSChuck Lever __be32 verf[2]; 48591da177e4SLinus Torvalds 48601da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 4861db942bbdSBenny Halevy if (!status) 4862db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 4863db942bbdSBenny Halevy if (unlikely(status)) 48641da177e4SLinus Torvalds return status; 4865cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 486644109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 4867cd93710eSChuck Lever __func__, verf[0], verf[1]); 48681da177e4SLinus Torvalds 4869db942bbdSBenny Halevy hdrlen = (char *) xdr->p - (char *) iov->iov_base; 48701da177e4SLinus Torvalds recvd = rcvbuf->len - hdrlen; 48711da177e4SLinus Torvalds if (pglen > recvd) 48721da177e4SLinus Torvalds pglen = recvd; 48731da177e4SLinus Torvalds xdr_read_pages(xdr, pglen); 48741da177e4SLinus Torvalds 48757bda2cdfSJeff Layton 4876ac396128STrond Myklebust return pglen; 48771da177e4SLinus Torvalds } 48781da177e4SLinus Torvalds 48791da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 48801da177e4SLinus Torvalds { 48811da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 48821da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4883bcecff77SChuck Lever size_t hdrlen; 4884bcecff77SChuck Lever u32 len, recvd; 48858687b63aSAl Viro __be32 *p; 48861da177e4SLinus Torvalds int status; 48871da177e4SLinus Torvalds 48881da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 48891da177e4SLinus Torvalds if (status) 48901da177e4SLinus Torvalds return status; 48911da177e4SLinus Torvalds 48921da177e4SLinus Torvalds /* Convert length of symlink */ 4893c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4894c0eae66eSBenny Halevy if (unlikely(!p)) 4895c0eae66eSBenny Halevy goto out_overflow; 4896cccddf4fSBenny Halevy len = be32_to_cpup(p); 48971da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 4898fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 48991da177e4SLinus Torvalds return -ENAMETOOLONG; 49001da177e4SLinus Torvalds } 49011da177e4SLinus Torvalds hdrlen = (char *) xdr->p - (char *) iov->iov_base; 49021da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 49031da177e4SLinus Torvalds if (recvd < len) { 4904fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 49051da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 49061da177e4SLinus Torvalds return -EIO; 49071da177e4SLinus Torvalds } 49081da177e4SLinus Torvalds xdr_read_pages(xdr, len); 49091da177e4SLinus Torvalds /* 49101da177e4SLinus Torvalds * The XDR encode routine has set things up so that 49111da177e4SLinus Torvalds * the link text will be copied directly into the 49121da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 49131da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 49141da177e4SLinus Torvalds * null-termination). 49151da177e4SLinus Torvalds */ 4916b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 49171da177e4SLinus Torvalds return 0; 4918c0eae66eSBenny Halevy out_overflow: 4919c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4920c0eae66eSBenny Halevy return -EIO; 49211da177e4SLinus Torvalds } 49221da177e4SLinus Torvalds 49231da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 49241da177e4SLinus Torvalds { 49251da177e4SLinus Torvalds int status; 49261da177e4SLinus Torvalds 49271da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 49281da177e4SLinus Torvalds if (status) 49291da177e4SLinus Torvalds goto out; 49301da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 49311da177e4SLinus Torvalds out: 49321da177e4SLinus Torvalds return status; 49331da177e4SLinus Torvalds } 49341da177e4SLinus Torvalds 49351da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 49361da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 49371da177e4SLinus Torvalds { 49381da177e4SLinus Torvalds int status; 49391da177e4SLinus Torvalds 49401da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 49411da177e4SLinus Torvalds if (status) 49421da177e4SLinus Torvalds goto out; 49431da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 49441da177e4SLinus Torvalds goto out; 49451da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 49461da177e4SLinus Torvalds out: 49471da177e4SLinus Torvalds return status; 49481da177e4SLinus Torvalds } 49491da177e4SLinus Torvalds 49501da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 49511da177e4SLinus Torvalds { 49521da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 49531da177e4SLinus Torvalds } 49541da177e4SLinus Torvalds 495556ae19f3STrond Myklebust static int 495656ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 495756ae19f3STrond Myklebust { 495856ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 495956ae19f3STrond Myklebust } 496056ae19f3STrond Myklebust 4961029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 4962bf118a34SAndy Adamson struct nfs_getaclres *res) 4963029d105eSJ. Bruce Fields { 4964bf118a34SAndy Adamson __be32 *savep, *bm_p; 4965029d105eSJ. Bruce Fields uint32_t attrlen, 4966dae100c2SFred Isaman bitmap[3] = {0}; 4967029d105eSJ. Bruce Fields struct kvec *iov = req->rq_rcv_buf.head; 4968029d105eSJ. Bruce Fields int status; 4969029d105eSJ. Bruce Fields 4970bf118a34SAndy Adamson res->acl_len = 0; 4971029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 4972029d105eSJ. Bruce Fields goto out; 4973bf118a34SAndy Adamson bm_p = xdr->p; 4974029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 4975029d105eSJ. Bruce Fields goto out; 4976029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 4977029d105eSJ. Bruce Fields goto out; 4978029d105eSJ. Bruce Fields 4979029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 4980029d105eSJ. Bruce Fields return -EIO; 4981029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 4982bcecff77SChuck Lever size_t hdrlen; 4983bcecff77SChuck Lever u32 recvd; 4984029d105eSJ. Bruce Fields 4985bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 4986bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 4987bf118a34SAndy Adamson * variable length bitmaps.*/ 4988bf118a34SAndy Adamson xdr->p = bm_p; 4989bf118a34SAndy Adamson res->acl_data_offset = be32_to_cpup(bm_p) + 2; 4990bf118a34SAndy Adamson res->acl_data_offset <<= 2; 4991bf118a34SAndy Adamson 4992029d105eSJ. Bruce Fields /* We ignore &savep and don't do consistency checks on 4993029d105eSJ. Bruce Fields * the attr length. Let userspace figure it out.... */ 4994029d105eSJ. Bruce Fields hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; 4995bf118a34SAndy Adamson attrlen += res->acl_data_offset; 4996029d105eSJ. Bruce Fields recvd = req->rq_rcv_buf.len - hdrlen; 4997029d105eSJ. Bruce Fields if (attrlen > recvd) { 4998bf118a34SAndy Adamson if (res->acl_flags & NFS4_ACL_LEN_REQUEST) { 4999bf118a34SAndy Adamson /* getxattr interface called with a NULL buf */ 5000bf118a34SAndy Adamson res->acl_len = attrlen; 5001bf118a34SAndy Adamson goto out; 5002bf118a34SAndy Adamson } 5003bf118a34SAndy Adamson dprintk("NFS: acl reply: attrlen %u > recvd %u\n", 5004029d105eSJ. Bruce Fields attrlen, recvd); 5005029d105eSJ. Bruce Fields return -EINVAL; 5006029d105eSJ. Bruce Fields } 5007029d105eSJ. Bruce Fields xdr_read_pages(xdr, attrlen); 5008bf118a34SAndy Adamson res->acl_len = attrlen; 50098c233cf9SJ. Bruce Fields } else 50108c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5011029d105eSJ. Bruce Fields 5012029d105eSJ. Bruce Fields out: 5013029d105eSJ. Bruce Fields return status; 5014029d105eSJ. Bruce Fields } 5015029d105eSJ. Bruce Fields 50161da177e4SLinus Torvalds static int 50171da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 50181da177e4SLinus Torvalds { 50191da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 50201da177e4SLinus Torvalds } 50211da177e4SLinus Torvalds 50229e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 50231da177e4SLinus Torvalds { 50248687b63aSAl Viro __be32 *p; 50251da177e4SLinus Torvalds uint32_t bmlen; 50261da177e4SLinus Torvalds int status; 50271da177e4SLinus Torvalds 50281da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 50291da177e4SLinus Torvalds if (status) 50301da177e4SLinus Torvalds return status; 5031c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5032c0eae66eSBenny Halevy if (unlikely(!p)) 5033c0eae66eSBenny Halevy goto out_overflow; 5034cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5035c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5036c0eae66eSBenny Halevy if (likely(p)) 50371da177e4SLinus Torvalds return 0; 5038c0eae66eSBenny Halevy out_overflow: 5039c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5040c0eae66eSBenny Halevy return -EIO; 50411da177e4SLinus Torvalds } 50421da177e4SLinus Torvalds 5043bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 50441da177e4SLinus Torvalds { 50458687b63aSAl Viro __be32 *p; 50461da177e4SLinus Torvalds uint32_t opnum; 50471da177e4SLinus Torvalds int32_t nfserr; 50481da177e4SLinus Torvalds 5049c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5050c0eae66eSBenny Halevy if (unlikely(!p)) 5051c0eae66eSBenny Halevy goto out_overflow; 50526f723f77SBenny Halevy opnum = be32_to_cpup(p++); 50531da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5054fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 50551da177e4SLinus Torvalds " %d\n", opnum); 50561da177e4SLinus Torvalds return -EIO; 50571da177e4SLinus Torvalds } 5058cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 50591da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5060c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5061c0eae66eSBenny Halevy if (unlikely(!p)) 5062c0eae66eSBenny Halevy goto out_overflow; 5063bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5064bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 50651da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 50661da177e4SLinus Torvalds uint32_t len; 50671da177e4SLinus Torvalds 50681da177e4SLinus Torvalds /* skip netid string */ 5069c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5070c0eae66eSBenny Halevy if (unlikely(!p)) 5071c0eae66eSBenny Halevy goto out_overflow; 5072cccddf4fSBenny Halevy len = be32_to_cpup(p); 5073c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5074c0eae66eSBenny Halevy if (unlikely(!p)) 5075c0eae66eSBenny Halevy goto out_overflow; 50761da177e4SLinus Torvalds 50771da177e4SLinus Torvalds /* skip uaddr string */ 5078c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5079c0eae66eSBenny Halevy if (unlikely(!p)) 5080c0eae66eSBenny Halevy goto out_overflow; 5081cccddf4fSBenny Halevy len = be32_to_cpup(p); 5082c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5083c0eae66eSBenny Halevy if (unlikely(!p)) 5084c0eae66eSBenny Halevy goto out_overflow; 50851da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 50861da177e4SLinus Torvalds } else 5087856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 50881da177e4SLinus Torvalds 50891da177e4SLinus Torvalds return 0; 5090c0eae66eSBenny Halevy out_overflow: 5091c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5092c0eae66eSBenny Halevy return -EIO; 50931da177e4SLinus Torvalds } 50941da177e4SLinus Torvalds 50951da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 50961da177e4SLinus Torvalds { 50971da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 50981da177e4SLinus Torvalds } 50991da177e4SLinus Torvalds 51001da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 51011da177e4SLinus Torvalds { 51028687b63aSAl Viro __be32 *p; 51031da177e4SLinus Torvalds int status; 51041da177e4SLinus Torvalds 51051da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 51061da177e4SLinus Torvalds if (status) 51071da177e4SLinus Torvalds return status; 51081da177e4SLinus Torvalds 5109c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 5110c0eae66eSBenny Halevy if (unlikely(!p)) 5111c0eae66eSBenny Halevy goto out_overflow; 51126f723f77SBenny Halevy res->count = be32_to_cpup(p++); 51136f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 5114cd93710eSChuck Lever memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE); 51151da177e4SLinus Torvalds return 0; 5116c0eae66eSBenny Halevy out_overflow: 5117c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5118c0eae66eSBenny Halevy return -EIO; 51191da177e4SLinus Torvalds } 51201da177e4SLinus Torvalds 51211da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 51221da177e4SLinus Torvalds { 51231da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 51241da177e4SLinus Torvalds } 51251da177e4SLinus Torvalds 51265a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor) 51275a5ea0d4SBryan Schumaker { 51285a5ea0d4SBryan Schumaker __be32 *p; 51295a5ea0d4SBryan Schumaker 51305a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 51315a5ea0d4SBryan Schumaker if (unlikely(!p)) 51325a5ea0d4SBryan Schumaker goto out_overflow; 51335a5ea0d4SBryan Schumaker flavor->gss.sec_oid4.len = be32_to_cpup(p); 51345a5ea0d4SBryan Schumaker if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN) 51355a5ea0d4SBryan Schumaker goto out_err; 51365a5ea0d4SBryan Schumaker 51375a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len); 51385a5ea0d4SBryan Schumaker if (unlikely(!p)) 51395a5ea0d4SBryan Schumaker goto out_overflow; 51405a5ea0d4SBryan Schumaker memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len); 51415a5ea0d4SBryan Schumaker 51425a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 51435a5ea0d4SBryan Schumaker if (unlikely(!p)) 51445a5ea0d4SBryan Schumaker goto out_overflow; 51455a5ea0d4SBryan Schumaker flavor->gss.qop4 = be32_to_cpup(p++); 51465a5ea0d4SBryan Schumaker flavor->gss.service = be32_to_cpup(p); 51475a5ea0d4SBryan Schumaker 51485a5ea0d4SBryan Schumaker return 0; 51495a5ea0d4SBryan Schumaker 51505a5ea0d4SBryan Schumaker out_overflow: 51515a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 51525a5ea0d4SBryan Schumaker return -EIO; 51535a5ea0d4SBryan Schumaker out_err: 51545a5ea0d4SBryan Schumaker return -EINVAL; 51555a5ea0d4SBryan Schumaker } 51565a5ea0d4SBryan Schumaker 51575a5ea0d4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 51585a5ea0d4SBryan Schumaker { 51595a5ea0d4SBryan Schumaker struct nfs4_secinfo_flavor *sec_flavor; 51605a5ea0d4SBryan Schumaker int status; 51615a5ea0d4SBryan Schumaker __be32 *p; 5162c3dfc280SBryan Schumaker int i, num_flavors; 51635a5ea0d4SBryan Schumaker 51645a5ea0d4SBryan Schumaker status = decode_op_hdr(xdr, OP_SECINFO); 5165613e901eSBryan Schumaker if (status) 5166613e901eSBryan Schumaker goto out; 51675a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 51685a5ea0d4SBryan Schumaker if (unlikely(!p)) 51695a5ea0d4SBryan Schumaker goto out_overflow; 51705a5ea0d4SBryan Schumaker 5171c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5172c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5173c3dfc280SBryan Schumaker 5174c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 51755a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5176c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 51775a5ea0d4SBryan Schumaker break; 51785a5ea0d4SBryan Schumaker 51795a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 51805a5ea0d4SBryan Schumaker if (unlikely(!p)) 51815a5ea0d4SBryan Schumaker goto out_overflow; 51825a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 51835a5ea0d4SBryan Schumaker 51845a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5185613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5186613e901eSBryan Schumaker if (status) 5187613e901eSBryan Schumaker goto out; 51885a5ea0d4SBryan Schumaker } 5189c3dfc280SBryan Schumaker res->flavors->num_flavors++; 51905a5ea0d4SBryan Schumaker } 51915a5ea0d4SBryan Schumaker 5192613e901eSBryan Schumaker out: 5193613e901eSBryan Schumaker return status; 51945a5ea0d4SBryan Schumaker out_overflow: 51955a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 51965a5ea0d4SBryan Schumaker return -EIO; 51975a5ea0d4SBryan Schumaker } 51985a5ea0d4SBryan Schumaker 519999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 520099fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 520199fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 520299fe60d0SBenny Halevy { 520399fe60d0SBenny Halevy __be32 *p; 520499fe60d0SBenny Halevy uint32_t dummy; 52052460ba57SBenny Halevy char *dummy_str; 520699fe60d0SBenny Halevy int status; 520799fe60d0SBenny Halevy struct nfs_client *clp = res->client; 52087d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 520999fe60d0SBenny Halevy 521099fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 521199fe60d0SBenny Halevy if (status) 521299fe60d0SBenny Halevy return status; 521399fe60d0SBenny Halevy 5214c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5215c0eae66eSBenny Halevy if (unlikely(!p)) 5216c0eae66eSBenny Halevy goto out_overflow; 5217114f64b5SAndy Adamson xdr_decode_hyper(p, &clp->cl_clientid); 5218c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5219c0eae66eSBenny Halevy if (unlikely(!p)) 5220c0eae66eSBenny Halevy goto out_overflow; 52216f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 52226f723f77SBenny Halevy clp->cl_exchange_flags = be32_to_cpup(p++); 522399fe60d0SBenny Halevy 522499fe60d0SBenny Halevy /* We ask for SP4_NONE */ 5225cccddf4fSBenny Halevy dummy = be32_to_cpup(p); 522699fe60d0SBenny Halevy if (dummy != SP4_NONE) 522799fe60d0SBenny Halevy return -EIO; 522899fe60d0SBenny Halevy 522999fe60d0SBenny Halevy /* Throw away minor_id */ 5230c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5231c0eae66eSBenny Halevy if (unlikely(!p)) 5232c0eae66eSBenny Halevy goto out_overflow; 523399fe60d0SBenny Halevy 523499fe60d0SBenny Halevy /* Throw away Major id */ 52352460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 52362460ba57SBenny Halevy if (unlikely(status)) 52372460ba57SBenny Halevy return status; 523899fe60d0SBenny Halevy 523978fe0f41SWeston Andros Adamson /* Save server_scope */ 52402460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 52412460ba57SBenny Halevy if (unlikely(status)) 52422460ba57SBenny Halevy return status; 524399fe60d0SBenny Halevy 524478fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 524578fe0f41SWeston Andros Adamson return -EIO; 524678fe0f41SWeston Andros Adamson 524778fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 524878fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 524978fe0f41SWeston Andros Adamson 52507d2ed9acSWeston Andros Adamson /* Implementation Id */ 52517d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 52527d2ed9acSWeston Andros Adamson if (unlikely(!p)) 52537d2ed9acSWeston Andros Adamson goto out_overflow; 52547d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 52557d2ed9acSWeston Andros Adamson 52567d2ed9acSWeston Andros Adamson if (impl_id_count) { 52577d2ed9acSWeston Andros Adamson /* nii_domain */ 52582460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 52592460ba57SBenny Halevy if (unlikely(status)) 52602460ba57SBenny Halevy return status; 52617d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 52627d2ed9acSWeston Andros Adamson return -EIO; 52637d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 526499fe60d0SBenny Halevy 52657d2ed9acSWeston Andros Adamson /* nii_name */ 52667d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 52677d2ed9acSWeston Andros Adamson if (unlikely(status)) 52687d2ed9acSWeston Andros Adamson return status; 52697d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 52707d2ed9acSWeston Andros Adamson return -EIO; 52717d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 52727d2ed9acSWeston Andros Adamson 52737d2ed9acSWeston Andros Adamson /* nii_date */ 52747d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 52757d2ed9acSWeston Andros Adamson if (unlikely(!p)) 52767d2ed9acSWeston Andros Adamson goto out_overflow; 52777d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 52787d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 52797d2ed9acSWeston Andros Adamson 52807d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 52817d2ed9acSWeston Andros Adamson } 528299fe60d0SBenny Halevy return 0; 5283c0eae66eSBenny Halevy out_overflow: 5284c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5285c0eae66eSBenny Halevy return -EIO; 528699fe60d0SBenny Halevy } 5287fc931582SAndy Adamson 5288fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5289fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5290fc931582SAndy Adamson { 5291fc931582SAndy Adamson __be32 *p; 5292c9c30dd5SBenny Halevy u32 nr_attrs, val; 5293fc931582SAndy Adamson 5294c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5295c0eae66eSBenny Halevy if (unlikely(!p)) 5296c0eae66eSBenny Halevy goto out_overflow; 5297c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5298c9c30dd5SBenny Halevy if (val) 5299c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 53006f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 53016f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 53026f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 53036f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 53046f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5305cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5306fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5307a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5308a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5309fc931582SAndy Adamson return -EINVAL; 5310fc931582SAndy Adamson } 5311c0eae66eSBenny Halevy if (nr_attrs == 1) { 5312c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5313c0eae66eSBenny Halevy if (unlikely(!p)) 5314c0eae66eSBenny Halevy goto out_overflow; 5315c0eae66eSBenny Halevy } 5316fc931582SAndy Adamson return 0; 5317c0eae66eSBenny Halevy out_overflow: 5318c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5319c0eae66eSBenny Halevy return -EIO; 5320fc931582SAndy Adamson } 5321fc931582SAndy Adamson 5322e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5323e78291e4SBenny Halevy { 5324e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5325fc931582SAndy Adamson } 5326fc931582SAndy Adamson 5327fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5328fc931582SAndy Adamson struct nfs41_create_session_res *res) 5329fc931582SAndy Adamson { 5330fc931582SAndy Adamson __be32 *p; 5331fc931582SAndy Adamson int status; 5332fc931582SAndy Adamson struct nfs_client *clp = res->client; 5333fc931582SAndy Adamson struct nfs4_session *session = clp->cl_session; 5334fc931582SAndy Adamson 5335fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5336e78291e4SBenny Halevy if (!status) 5337e78291e4SBenny Halevy status = decode_sessionid(xdr, &session->sess_id); 5338e78291e4SBenny Halevy if (unlikely(status)) 5339fc931582SAndy Adamson return status; 5340fc931582SAndy Adamson 5341fc931582SAndy Adamson /* seqid, flags */ 5342c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5343c0eae66eSBenny Halevy if (unlikely(!p)) 5344c0eae66eSBenny Halevy goto out_overflow; 53456f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 5346cccddf4fSBenny Halevy session->flags = be32_to_cpup(p); 5347fc931582SAndy Adamson 5348fc931582SAndy Adamson /* Channel attributes */ 5349fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->fc_attrs); 5350fc931582SAndy Adamson if (!status) 5351fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->bc_attrs); 5352fc931582SAndy Adamson return status; 5353c0eae66eSBenny Halevy out_overflow: 5354c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5355c0eae66eSBenny Halevy return -EIO; 5356fc931582SAndy Adamson } 53570f3e66c6SAndy Adamson 53580f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 53590f3e66c6SAndy Adamson { 53600f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 53610f3e66c6SAndy Adamson } 536218019753SRicardo Labiaga 536318019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 536418019753SRicardo Labiaga { 536518019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 536618019753SRicardo Labiaga } 536799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 536899fe60d0SBenny Halevy 53699b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 53709b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 53719b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 53729b7b9fccSAndy Adamson { 53739b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5374fc01cea9SAndy Adamson struct nfs4_sessionid id; 5375fc01cea9SAndy Adamson u32 dummy; 5376fc01cea9SAndy Adamson int status; 5377fc01cea9SAndy Adamson __be32 *p; 5378fc01cea9SAndy Adamson 53799b7b9fccSAndy Adamson if (!res->sr_session) 53809b7b9fccSAndy Adamson return 0; 53819b7b9fccSAndy Adamson 5382fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5383e78291e4SBenny Halevy if (!status) 5384e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5385e78291e4SBenny Halevy if (unlikely(status)) 5386fc01cea9SAndy Adamson goto out_err; 53879b7b9fccSAndy Adamson 5388fc01cea9SAndy Adamson /* 5389fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5390fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5391fc01cea9SAndy Adamson */ 5392fdcb4577STrond Myklebust status = -EREMOTEIO; 5393fc01cea9SAndy Adamson 5394fc01cea9SAndy Adamson if (memcmp(id.data, res->sr_session->sess_id.data, 5395fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5396fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5397fc01cea9SAndy Adamson goto out_err; 5398fc01cea9SAndy Adamson } 5399e78291e4SBenny Halevy 5400c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5401c0eae66eSBenny Halevy if (unlikely(!p)) 5402c0eae66eSBenny Halevy goto out_overflow; 5403e78291e4SBenny Halevy 5404fc01cea9SAndy Adamson /* seqid */ 54056f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5406dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5407fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5408fc01cea9SAndy Adamson goto out_err; 5409fc01cea9SAndy Adamson } 5410fc01cea9SAndy Adamson /* slot id */ 54116f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5412dfb4f309SBenny Halevy if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) { 5413fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5414fc01cea9SAndy Adamson goto out_err; 5415fc01cea9SAndy Adamson } 5416fc01cea9SAndy Adamson /* highest slot id - currently not processed */ 54176f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5418fc01cea9SAndy Adamson /* target highest slot id - currently not processed */ 54196f723f77SBenny Halevy dummy = be32_to_cpup(p++); 54200629e370SAlexandros Batsakis /* result flags */ 54210629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5422fc01cea9SAndy Adamson status = 0; 5423fc01cea9SAndy Adamson out_err: 5424fc01cea9SAndy Adamson res->sr_status = status; 5425fc01cea9SAndy Adamson return status; 5426c0eae66eSBenny Halevy out_overflow: 5427c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5428c0eae66eSBenny Halevy status = -EIO; 5429c0eae66eSBenny Halevy goto out_err; 5430fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 54319b7b9fccSAndy Adamson return 0; 5432fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 54339b7b9fccSAndy Adamson } 54349b7b9fccSAndy Adamson 5435b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 54367f11d8d3SAndy Adamson /* 54377f11d8d3SAndy Adamson * TODO: Need to handle case when EOF != true; 54387f11d8d3SAndy Adamson */ 54397f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr, 54407f11d8d3SAndy Adamson struct pnfs_devicelist *res) 54417f11d8d3SAndy Adamson { 54427f11d8d3SAndy Adamson __be32 *p; 54437f11d8d3SAndy Adamson int status, i; 54447f11d8d3SAndy Adamson struct nfs_writeverf verftemp; 54457f11d8d3SAndy Adamson 54467f11d8d3SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICELIST); 54477f11d8d3SAndy Adamson if (status) 54487f11d8d3SAndy Adamson return status; 54497f11d8d3SAndy Adamson 54507f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 8 + 8 + 4); 54517f11d8d3SAndy Adamson if (unlikely(!p)) 54527f11d8d3SAndy Adamson goto out_overflow; 54537f11d8d3SAndy Adamson 54547f11d8d3SAndy Adamson /* TODO: Skip cookie for now */ 54557f11d8d3SAndy Adamson p += 2; 54567f11d8d3SAndy Adamson 54577f11d8d3SAndy Adamson /* Read verifier */ 5458cd93710eSChuck Lever p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE); 54597f11d8d3SAndy Adamson 54607f11d8d3SAndy Adamson res->num_devs = be32_to_cpup(p); 54617f11d8d3SAndy Adamson 54627f11d8d3SAndy Adamson dprintk("%s: num_dev %d\n", __func__, res->num_devs); 54637f11d8d3SAndy Adamson 54647f11d8d3SAndy Adamson if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5465a030889aSWeston Andros Adamson printk(KERN_ERR "NFS: %s too many result dev_num %u\n", 54667f11d8d3SAndy Adamson __func__, res->num_devs); 54677f11d8d3SAndy Adamson return -EIO; 54687f11d8d3SAndy Adamson } 54697f11d8d3SAndy Adamson 54707f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 54717f11d8d3SAndy Adamson res->num_devs * NFS4_DEVICEID4_SIZE + 4); 54727f11d8d3SAndy Adamson if (unlikely(!p)) 54737f11d8d3SAndy Adamson goto out_overflow; 54747f11d8d3SAndy Adamson for (i = 0; i < res->num_devs; i++) 54757f11d8d3SAndy Adamson p = xdr_decode_opaque_fixed(p, res->dev_id[i].data, 54767f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE); 54777f11d8d3SAndy Adamson res->eof = be32_to_cpup(p); 54787f11d8d3SAndy Adamson return 0; 54797f11d8d3SAndy Adamson out_overflow: 54807f11d8d3SAndy Adamson print_overflow_msg(__func__, xdr); 54817f11d8d3SAndy Adamson return -EIO; 54827f11d8d3SAndy Adamson } 5483b1f69b75SAndy Adamson 5484b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 5485b1f69b75SAndy Adamson struct pnfs_device *pdev) 5486b1f69b75SAndy Adamson { 5487b1f69b75SAndy Adamson __be32 *p; 5488b1f69b75SAndy Adamson uint32_t len, type; 5489b1f69b75SAndy Adamson int status; 5490b1f69b75SAndy Adamson 5491b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5492b1f69b75SAndy Adamson if (status) { 5493b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5494b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5495b1f69b75SAndy Adamson if (unlikely(!p)) 5496b1f69b75SAndy Adamson goto out_overflow; 5497b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5498b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5499b1f69b75SAndy Adamson __func__, pdev->mincount); 5500b1f69b75SAndy Adamson } 5501b1f69b75SAndy Adamson return status; 5502b1f69b75SAndy Adamson } 5503b1f69b75SAndy Adamson 5504b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5505b1f69b75SAndy Adamson if (unlikely(!p)) 5506b1f69b75SAndy Adamson goto out_overflow; 5507b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5508b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5509b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5510b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5511b1f69b75SAndy Adamson return -EINVAL; 5512b1f69b75SAndy Adamson } 5513b1f69b75SAndy Adamson /* 5514b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5515b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5516b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5517b1f69b75SAndy Adamson */ 5518b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5519b1f69b75SAndy Adamson xdr_read_pages(xdr, pdev->mincount); /* include space for the length */ 5520b1f69b75SAndy Adamson 5521b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5522b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5523b1f69b75SAndy Adamson if (unlikely(!p)) 5524b1f69b75SAndy Adamson goto out_overflow; 5525b1f69b75SAndy Adamson len = be32_to_cpup(p); 5526b1f69b75SAndy Adamson if (len) { 5527ead00597SChuck Lever uint32_t i; 5528b1f69b75SAndy Adamson 5529b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5530b1f69b75SAndy Adamson if (unlikely(!p)) 5531b1f69b75SAndy Adamson goto out_overflow; 5532b1f69b75SAndy Adamson for (i = 0; i < len; i++, p++) { 5533b1f69b75SAndy Adamson if (be32_to_cpup(p)) { 5534b1f69b75SAndy Adamson dprintk("%s: notifications not supported\n", 5535b1f69b75SAndy Adamson __func__); 5536b1f69b75SAndy Adamson return -EIO; 5537b1f69b75SAndy Adamson } 5538b1f69b75SAndy Adamson } 5539b1f69b75SAndy Adamson } 5540b1f69b75SAndy Adamson return 0; 5541b1f69b75SAndy Adamson out_overflow: 5542b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5543b1f69b75SAndy Adamson return -EIO; 5544b1f69b75SAndy Adamson } 5545b1f69b75SAndy Adamson 5546b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5547b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5548b1f69b75SAndy Adamson { 5549b1f69b75SAndy Adamson __be32 *p; 5550b1f69b75SAndy Adamson int status; 5551b1f69b75SAndy Adamson u32 layout_count; 555235124a09SWeston Andros Adamson struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 555335124a09SWeston Andros Adamson struct kvec *iov = rcvbuf->head; 555435124a09SWeston Andros Adamson u32 hdrlen, recvd; 5555b1f69b75SAndy Adamson 5556b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5557b1f69b75SAndy Adamson if (status) 5558b1f69b75SAndy Adamson return status; 5559ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5560b1f69b75SAndy Adamson if (unlikely(!p)) 5561b1f69b75SAndy Adamson goto out_overflow; 5562ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 5563ea9d23f5STrond Myklebust decode_stateid(xdr, &res->stateid); 5564ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5565ea9d23f5STrond Myklebust if (unlikely(!p)) 5566ea9d23f5STrond Myklebust goto out_overflow; 5567b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5568b1f69b75SAndy Adamson if (!layout_count) { 5569b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5570b1f69b75SAndy Adamson __func__); 5571b1f69b75SAndy Adamson return -EINVAL; 5572b1f69b75SAndy Adamson } 5573b1f69b75SAndy Adamson 557435124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5575b1f69b75SAndy Adamson if (unlikely(!p)) 5576b1f69b75SAndy Adamson goto out_overflow; 5577b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5578b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5579b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5580b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 558135124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5582b1f69b75SAndy Adamson 5583b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5584b1f69b75SAndy Adamson __func__, 5585b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5586b1f69b75SAndy Adamson (unsigned long)res->range.length, 5587b1f69b75SAndy Adamson res->range.iomode, 5588b1f69b75SAndy Adamson res->type, 558935124a09SWeston Andros Adamson res->layoutp->len); 5590b1f69b75SAndy Adamson 559135124a09SWeston Andros Adamson hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 559235124a09SWeston Andros Adamson recvd = req->rq_rcv_buf.len - hdrlen; 559335124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 559435124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 559535124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 559635124a09SWeston Andros Adamson res->layoutp->len, recvd); 559735124a09SWeston Andros Adamson return -EINVAL; 559835124a09SWeston Andros Adamson } 559935124a09SWeston Andros Adamson 560035124a09SWeston Andros Adamson xdr_read_pages(xdr, res->layoutp->len); 5601b1f69b75SAndy Adamson 5602b1f69b75SAndy Adamson if (layout_count > 1) { 5603b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5604b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5605b1f69b75SAndy Adamson * the client may see a response that is less than the 5606b1f69b75SAndy Adamson * minimum it requested. 5607b1f69b75SAndy Adamson */ 5608b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5609b1f69b75SAndy Adamson __func__, layout_count); 5610b1f69b75SAndy Adamson } 5611b1f69b75SAndy Adamson 5612b1f69b75SAndy Adamson return 0; 5613b1f69b75SAndy Adamson out_overflow: 5614b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5615b1f69b75SAndy Adamson return -EIO; 5616b1f69b75SAndy Adamson } 5617863a3c6cSAndy Adamson 5618cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5619cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5620cbe82603SBenny Halevy { 5621cbe82603SBenny Halevy __be32 *p; 5622cbe82603SBenny Halevy int status; 5623cbe82603SBenny Halevy 5624cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5625cbe82603SBenny Halevy if (status) 5626cbe82603SBenny Halevy return status; 5627cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5628cbe82603SBenny Halevy if (unlikely(!p)) 5629cbe82603SBenny Halevy goto out_overflow; 5630cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5631cbe82603SBenny Halevy if (res->lrs_present) 5632cbe82603SBenny Halevy status = decode_stateid(xdr, &res->stateid); 5633cbe82603SBenny Halevy return status; 5634cbe82603SBenny Halevy out_overflow: 5635cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 5636cbe82603SBenny Halevy return -EIO; 5637cbe82603SBenny Halevy } 5638cbe82603SBenny Halevy 5639863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5640863a3c6cSAndy Adamson struct rpc_rqst *req, 5641863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5642863a3c6cSAndy Adamson { 5643863a3c6cSAndy Adamson __be32 *p; 5644863a3c6cSAndy Adamson __u32 sizechanged; 5645863a3c6cSAndy Adamson int status; 5646863a3c6cSAndy Adamson 5647863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5648db29c089SAndy Adamson res->status = status; 5649863a3c6cSAndy Adamson if (status) 5650863a3c6cSAndy Adamson return status; 5651863a3c6cSAndy Adamson 5652863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5653863a3c6cSAndy Adamson if (unlikely(!p)) 5654863a3c6cSAndy Adamson goto out_overflow; 5655863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5656863a3c6cSAndy Adamson 5657863a3c6cSAndy Adamson if (sizechanged) { 5658863a3c6cSAndy Adamson /* throw away new size */ 5659863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5660863a3c6cSAndy Adamson if (unlikely(!p)) 5661863a3c6cSAndy Adamson goto out_overflow; 5662863a3c6cSAndy Adamson } 5663863a3c6cSAndy Adamson return 0; 5664863a3c6cSAndy Adamson out_overflow: 5665863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 5666863a3c6cSAndy Adamson return -EIO; 5667863a3c6cSAndy Adamson } 56687d974794SBryan Schumaker 56697d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 56707d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 56717d974794SBryan Schumaker { 56727d974794SBryan Schumaker __be32 *p; 56737d974794SBryan Schumaker int status; 56747d974794SBryan Schumaker int num_res; 56757d974794SBryan Schumaker 56767d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 56777d974794SBryan Schumaker if (status) 56787d974794SBryan Schumaker return status; 56797d974794SBryan Schumaker 56807d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56817d974794SBryan Schumaker if (unlikely(!p)) 56827d974794SBryan Schumaker goto out_overflow; 56837d974794SBryan Schumaker num_res = be32_to_cpup(p++); 56847d974794SBryan Schumaker if (num_res != 1) 56857d974794SBryan Schumaker goto out; 56867d974794SBryan Schumaker 56877d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56887d974794SBryan Schumaker if (unlikely(!p)) 56897d974794SBryan Schumaker goto out_overflow; 56907d974794SBryan Schumaker res->status = be32_to_cpup(p++); 56911cab0652SBryan Schumaker 56921cab0652SBryan Schumaker return status; 56937d974794SBryan Schumaker out_overflow: 56947d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 56957d974794SBryan Schumaker out: 56967d974794SBryan Schumaker return -EIO; 56977d974794SBryan Schumaker } 56989aeda35fSBryan Schumaker 56999aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 57009aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 57019aeda35fSBryan Schumaker { 57029aeda35fSBryan Schumaker __be32 *p; 57039aeda35fSBryan Schumaker int status; 57049aeda35fSBryan Schumaker 57059aeda35fSBryan Schumaker status = decode_op_hdr(xdr, OP_FREE_STATEID); 57069aeda35fSBryan Schumaker if (status) 57079aeda35fSBryan Schumaker return status; 57089aeda35fSBryan Schumaker 57099aeda35fSBryan Schumaker p = xdr_inline_decode(xdr, 4); 57109aeda35fSBryan Schumaker if (unlikely(!p)) 57119aeda35fSBryan Schumaker goto out_overflow; 57129aeda35fSBryan Schumaker res->status = be32_to_cpup(p++); 57139aeda35fSBryan Schumaker return res->status; 57149aeda35fSBryan Schumaker out_overflow: 57159aeda35fSBryan Schumaker print_overflow_msg(__func__, xdr); 57169aeda35fSBryan Schumaker return -EIO; 57179aeda35fSBryan Schumaker } 5718b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 5719b1f69b75SAndy Adamson 57201da177e4SLinus Torvalds /* 572149c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 572249c2559eSBenny Halevy */ 572349c2559eSBenny Halevy 572449c2559eSBenny Halevy /* 57251da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 57261da177e4SLinus Torvalds */ 5727bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 5728bf269551SChuck Lever struct xdr_stream *xdr, 5729bf269551SChuck Lever struct nfs_closeres *res) 57301da177e4SLinus Torvalds { 57311da177e4SLinus Torvalds struct compound_hdr hdr; 57321da177e4SLinus Torvalds int status; 57331da177e4SLinus Torvalds 5734bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57351da177e4SLinus Torvalds if (status) 57361da177e4SLinus Torvalds goto out; 5737bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57389b7b9fccSAndy Adamson if (status) 57399b7b9fccSAndy Adamson goto out; 5740bf269551SChuck Lever status = decode_putfh(xdr); 57411da177e4SLinus Torvalds if (status) 57421da177e4SLinus Torvalds goto out; 5743bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 5744516a6af6STrond Myklebust if (status != 0) 5745516a6af6STrond Myklebust goto out; 57466926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 57471da177e4SLinus Torvalds out: 57481da177e4SLinus Torvalds return status; 57491da177e4SLinus Torvalds } 57501da177e4SLinus Torvalds 57511da177e4SLinus Torvalds /* 57521da177e4SLinus Torvalds * Decode ACCESS response 57531da177e4SLinus Torvalds */ 5754bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5755bf269551SChuck Lever struct nfs4_accessres *res) 57561da177e4SLinus Torvalds { 57571da177e4SLinus Torvalds struct compound_hdr hdr; 57581da177e4SLinus Torvalds int status; 57591da177e4SLinus Torvalds 5760bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57619b7b9fccSAndy Adamson if (status) 57629b7b9fccSAndy Adamson goto out; 5763bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57649b7b9fccSAndy Adamson if (status) 57651da177e4SLinus Torvalds goto out; 5766bf269551SChuck Lever status = decode_putfh(xdr); 576776b32999STrond Myklebust if (status != 0) 576876b32999STrond Myklebust goto out; 5769bf269551SChuck Lever status = decode_access(xdr, res); 577076b32999STrond Myklebust if (status != 0) 577176b32999STrond Myklebust goto out; 57726926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 57731da177e4SLinus Torvalds out: 57741da177e4SLinus Torvalds return status; 57751da177e4SLinus Torvalds } 57761da177e4SLinus Torvalds 57771da177e4SLinus Torvalds /* 57781da177e4SLinus Torvalds * Decode LOOKUP response 57791da177e4SLinus Torvalds */ 5780bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5781bf269551SChuck Lever struct nfs4_lookup_res *res) 57821da177e4SLinus Torvalds { 57831da177e4SLinus Torvalds struct compound_hdr hdr; 57841da177e4SLinus Torvalds int status; 57851da177e4SLinus Torvalds 5786bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57879b7b9fccSAndy Adamson if (status) 57889b7b9fccSAndy Adamson goto out; 5789bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57909b7b9fccSAndy Adamson if (status) 57911da177e4SLinus Torvalds goto out; 5792bf269551SChuck Lever status = decode_putfh(xdr); 5793bf269551SChuck Lever if (status) 57941da177e4SLinus Torvalds goto out; 5795bf269551SChuck Lever status = decode_lookup(xdr); 5796bf269551SChuck Lever if (status) 57971da177e4SLinus Torvalds goto out; 5798bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5799bf269551SChuck Lever if (status) 58001da177e4SLinus Torvalds goto out; 58016926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 58021da177e4SLinus Torvalds out: 58031da177e4SLinus Torvalds return status; 58041da177e4SLinus Torvalds } 58051da177e4SLinus Torvalds 58061da177e4SLinus Torvalds /* 58071da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 58081da177e4SLinus Torvalds */ 5809bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 5810bf269551SChuck Lever struct xdr_stream *xdr, 5811bf269551SChuck Lever struct nfs4_lookup_res *res) 58121da177e4SLinus Torvalds { 58131da177e4SLinus Torvalds struct compound_hdr hdr; 58141da177e4SLinus Torvalds int status; 58151da177e4SLinus Torvalds 5816bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58179b7b9fccSAndy Adamson if (status) 58189b7b9fccSAndy Adamson goto out; 5819bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58209b7b9fccSAndy Adamson if (status) 58211da177e4SLinus Torvalds goto out; 5822bf269551SChuck Lever status = decode_putrootfh(xdr); 5823bf269551SChuck Lever if (status) 58241da177e4SLinus Torvalds goto out; 5825bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5826bf269551SChuck Lever if (status == 0) 58276926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 58281da177e4SLinus Torvalds out: 58291da177e4SLinus Torvalds return status; 58301da177e4SLinus Torvalds } 58311da177e4SLinus Torvalds 58321da177e4SLinus Torvalds /* 58331da177e4SLinus Torvalds * Decode REMOVE response 58341da177e4SLinus Torvalds */ 5835bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5836bf269551SChuck Lever struct nfs_removeres *res) 58371da177e4SLinus Torvalds { 58381da177e4SLinus Torvalds struct compound_hdr hdr; 58391da177e4SLinus Torvalds int status; 58401da177e4SLinus Torvalds 5841bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58429b7b9fccSAndy Adamson if (status) 58439b7b9fccSAndy Adamson goto out; 5844bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58459b7b9fccSAndy Adamson if (status) 58461da177e4SLinus Torvalds goto out; 5847bf269551SChuck Lever status = decode_putfh(xdr); 5848bf269551SChuck Lever if (status) 584916e42959STrond Myklebust goto out; 5850bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 5851bf269551SChuck Lever if (status) 585216e42959STrond Myklebust goto out; 58536926afd1STrond Myklebust decode_getfattr(xdr, res->dir_attr, res->server); 58541da177e4SLinus Torvalds out: 58551da177e4SLinus Torvalds return status; 58561da177e4SLinus Torvalds } 58571da177e4SLinus Torvalds 58581da177e4SLinus Torvalds /* 58591da177e4SLinus Torvalds * Decode RENAME response 58601da177e4SLinus Torvalds */ 5861bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5862bf269551SChuck Lever struct nfs_renameres *res) 58631da177e4SLinus Torvalds { 58641da177e4SLinus Torvalds struct compound_hdr hdr; 58651da177e4SLinus Torvalds int status; 58661da177e4SLinus Torvalds 5867bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58689b7b9fccSAndy Adamson if (status) 58699b7b9fccSAndy Adamson goto out; 5870bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58719b7b9fccSAndy Adamson if (status) 58721da177e4SLinus Torvalds goto out; 5873bf269551SChuck Lever status = decode_putfh(xdr); 5874bf269551SChuck Lever if (status) 58751da177e4SLinus Torvalds goto out; 5876bf269551SChuck Lever status = decode_savefh(xdr); 5877bf269551SChuck Lever if (status) 58781da177e4SLinus Torvalds goto out; 5879bf269551SChuck Lever status = decode_putfh(xdr); 5880bf269551SChuck Lever if (status) 58811da177e4SLinus Torvalds goto out; 5882bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 5883bf269551SChuck Lever if (status) 58846caf2c82STrond Myklebust goto out; 58856caf2c82STrond Myklebust /* Current FH is target directory */ 58866926afd1STrond Myklebust if (decode_getfattr(xdr, res->new_fattr, res->server)) 58876caf2c82STrond Myklebust goto out; 5888bf269551SChuck Lever status = decode_restorefh(xdr); 5889bf269551SChuck Lever if (status) 58906caf2c82STrond Myklebust goto out; 58916926afd1STrond Myklebust decode_getfattr(xdr, res->old_fattr, res->server); 58921da177e4SLinus Torvalds out: 58931da177e4SLinus Torvalds return status; 58941da177e4SLinus Torvalds } 58951da177e4SLinus Torvalds 58961da177e4SLinus Torvalds /* 58971da177e4SLinus Torvalds * Decode LINK response 58981da177e4SLinus Torvalds */ 5899bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5900bf269551SChuck Lever struct nfs4_link_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_savefh(xdr); 5915bf269551SChuck Lever if (status) 59161da177e4SLinus Torvalds goto out; 5917bf269551SChuck Lever status = decode_putfh(xdr); 5918bf269551SChuck Lever if (status) 59191da177e4SLinus Torvalds goto out; 5920bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 5921bf269551SChuck Lever if (status) 592291ba2eeeSTrond Myklebust goto out; 592391ba2eeeSTrond Myklebust /* 592491ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 592591ba2eeeSTrond Myklebust * filehandle. 592691ba2eeeSTrond Myklebust */ 59276926afd1STrond Myklebust if (decode_getfattr(xdr, res->dir_attr, res->server)) 592891ba2eeeSTrond Myklebust goto out; 5929bf269551SChuck Lever status = decode_restorefh(xdr); 5930bf269551SChuck Lever if (status) 593191ba2eeeSTrond Myklebust goto out; 59326926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 59331da177e4SLinus Torvalds out: 59341da177e4SLinus Torvalds return status; 59351da177e4SLinus Torvalds } 59361da177e4SLinus Torvalds 59371da177e4SLinus Torvalds /* 59381da177e4SLinus Torvalds * Decode CREATE response 59391da177e4SLinus Torvalds */ 5940bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5941bf269551SChuck Lever struct nfs4_create_res *res) 59421da177e4SLinus Torvalds { 59431da177e4SLinus Torvalds struct compound_hdr hdr; 59441da177e4SLinus Torvalds int status; 59451da177e4SLinus Torvalds 5946bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59479b7b9fccSAndy Adamson if (status) 59489b7b9fccSAndy Adamson goto out; 5949bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59509b7b9fccSAndy Adamson if (status) 59511da177e4SLinus Torvalds goto out; 5952bf269551SChuck Lever status = decode_putfh(xdr); 5953bf269551SChuck Lever if (status) 59541da177e4SLinus Torvalds goto out; 5955bf269551SChuck Lever status = decode_savefh(xdr); 5956bf269551SChuck Lever if (status) 595756ae19f3STrond Myklebust goto out; 5958bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 5959bf269551SChuck Lever if (status) 59601da177e4SLinus Torvalds goto out; 5961bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5962bf269551SChuck Lever if (status) 59631da177e4SLinus Torvalds goto out; 59646926afd1STrond Myklebust if (decode_getfattr(xdr, res->fattr, res->server)) 596556ae19f3STrond Myklebust goto out; 5966bf269551SChuck Lever status = decode_restorefh(xdr); 5967bf269551SChuck Lever if (status) 596856ae19f3STrond Myklebust goto out; 59696926afd1STrond Myklebust decode_getfattr(xdr, res->dir_fattr, res->server); 59701da177e4SLinus Torvalds out: 59711da177e4SLinus Torvalds return status; 59721da177e4SLinus Torvalds } 59731da177e4SLinus Torvalds 59741da177e4SLinus Torvalds /* 59751da177e4SLinus Torvalds * Decode SYMLINK response 59761da177e4SLinus Torvalds */ 5977bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5978bf269551SChuck Lever struct nfs4_create_res *res) 59791da177e4SLinus Torvalds { 5980bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 59811da177e4SLinus Torvalds } 59821da177e4SLinus Torvalds 59831da177e4SLinus Torvalds /* 59841da177e4SLinus Torvalds * Decode GETATTR response 59851da177e4SLinus Torvalds */ 5986bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5987bf269551SChuck Lever struct nfs4_getattr_res *res) 59881da177e4SLinus Torvalds { 59891da177e4SLinus Torvalds struct compound_hdr hdr; 59901da177e4SLinus Torvalds int status; 59911da177e4SLinus Torvalds 5992bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59931da177e4SLinus Torvalds if (status) 59941da177e4SLinus Torvalds goto out; 5995bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59969b7b9fccSAndy Adamson if (status) 59979b7b9fccSAndy Adamson goto out; 5998bf269551SChuck Lever status = decode_putfh(xdr); 59991da177e4SLinus Torvalds if (status) 60001da177e4SLinus Torvalds goto out; 60016926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 60021da177e4SLinus Torvalds out: 60031da177e4SLinus Torvalds return status; 60041da177e4SLinus Torvalds } 60051da177e4SLinus Torvalds 600623ec6965SJ. Bruce Fields /* 600723ec6965SJ. Bruce Fields * Encode an SETACL request 600823ec6965SJ. Bruce Fields */ 60099f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 60109f06c719SChuck Lever struct nfs_setaclargs *args) 601123ec6965SJ. Bruce Fields { 601223ec6965SJ. Bruce Fields struct compound_hdr hdr = { 601366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 601423ec6965SJ. Bruce Fields }; 601523ec6965SJ. Bruce Fields 60169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 60179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 60189f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 60199f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6020d017931cSAndy Adamson encode_nops(&hdr); 602123ec6965SJ. Bruce Fields } 602205d564feSAndy Adamson 602323ec6965SJ. Bruce Fields /* 602423ec6965SJ. Bruce Fields * Decode SETACL response 602523ec6965SJ. Bruce Fields */ 602623ec6965SJ. Bruce Fields static int 6027bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 602873c403a9SBenny Halevy struct nfs_setaclres *res) 602923ec6965SJ. Bruce Fields { 603023ec6965SJ. Bruce Fields struct compound_hdr hdr; 603123ec6965SJ. Bruce Fields int status; 603223ec6965SJ. Bruce Fields 6033bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 603423ec6965SJ. Bruce Fields if (status) 603523ec6965SJ. Bruce Fields goto out; 6036bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60379b7b9fccSAndy Adamson if (status) 60389b7b9fccSAndy Adamson goto out; 6039bf269551SChuck Lever status = decode_putfh(xdr); 604023ec6965SJ. Bruce Fields if (status) 604123ec6965SJ. Bruce Fields goto out; 6042bf269551SChuck Lever status = decode_setattr(xdr); 604323ec6965SJ. Bruce Fields out: 604423ec6965SJ. Bruce Fields return status; 604523ec6965SJ. Bruce Fields } 60461da177e4SLinus Torvalds 60471da177e4SLinus Torvalds /* 6048029d105eSJ. Bruce Fields * Decode GETACL response 6049029d105eSJ. Bruce Fields */ 6050029d105eSJ. Bruce Fields static int 6051bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6052663c79b3SBenny Halevy struct nfs_getaclres *res) 6053029d105eSJ. Bruce Fields { 6054029d105eSJ. Bruce Fields struct compound_hdr hdr; 6055029d105eSJ. Bruce Fields int status; 6056029d105eSJ. Bruce Fields 6057331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6058331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6059331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6060331818f1STrond Myklebust } 6061bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6062029d105eSJ. Bruce Fields if (status) 6063029d105eSJ. Bruce Fields goto out; 6064bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60659b7b9fccSAndy Adamson if (status) 60669b7b9fccSAndy Adamson goto out; 6067bf269551SChuck Lever status = decode_putfh(xdr); 6068029d105eSJ. Bruce Fields if (status) 6069029d105eSJ. Bruce Fields goto out; 6070bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6071029d105eSJ. Bruce Fields 6072029d105eSJ. Bruce Fields out: 6073029d105eSJ. Bruce Fields return status; 6074029d105eSJ. Bruce Fields } 6075029d105eSJ. Bruce Fields 6076029d105eSJ. Bruce Fields /* 60771da177e4SLinus Torvalds * Decode CLOSE response 60781da177e4SLinus Torvalds */ 6079bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6080bf269551SChuck Lever struct nfs_closeres *res) 60811da177e4SLinus Torvalds { 60821da177e4SLinus Torvalds struct compound_hdr hdr; 60831da177e4SLinus Torvalds int status; 60841da177e4SLinus Torvalds 6085bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60861da177e4SLinus Torvalds if (status) 60871da177e4SLinus Torvalds goto out; 6088bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60899b7b9fccSAndy Adamson if (status) 60909b7b9fccSAndy Adamson goto out; 6091bf269551SChuck Lever status = decode_putfh(xdr); 60921da177e4SLinus Torvalds if (status) 60931da177e4SLinus Torvalds goto out; 6094bf269551SChuck Lever status = decode_close(xdr, res); 6095516a6af6STrond Myklebust if (status != 0) 6096516a6af6STrond Myklebust goto out; 6097516a6af6STrond Myklebust /* 6098516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6099516a6af6STrond Myklebust * in which case the getattr call will fail with 6100516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6101516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6102516a6af6STrond Myklebust */ 61036926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 61041da177e4SLinus Torvalds out: 61051da177e4SLinus Torvalds return status; 61061da177e4SLinus Torvalds } 61071da177e4SLinus Torvalds 61081da177e4SLinus Torvalds /* 61091da177e4SLinus Torvalds * Decode OPEN response 61101da177e4SLinus Torvalds */ 6111bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6112bf269551SChuck Lever struct nfs_openres *res) 61131da177e4SLinus Torvalds { 61141da177e4SLinus Torvalds struct compound_hdr hdr; 61151da177e4SLinus Torvalds int status; 61161da177e4SLinus Torvalds 6117bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61181da177e4SLinus Torvalds if (status) 61191da177e4SLinus Torvalds goto out; 6120bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61219b7b9fccSAndy Adamson if (status) 61229b7b9fccSAndy Adamson goto out; 6123bf269551SChuck Lever status = decode_putfh(xdr); 61241da177e4SLinus Torvalds if (status) 61251da177e4SLinus Torvalds goto out; 6126bf269551SChuck Lever status = decode_savefh(xdr); 612756ae19f3STrond Myklebust if (status) 612856ae19f3STrond Myklebust goto out; 6129bf269551SChuck Lever status = decode_open(xdr, res); 61301da177e4SLinus Torvalds if (status) 61311da177e4SLinus Torvalds goto out; 6132bf269551SChuck Lever if (decode_getfh(xdr, &res->fh) != 0) 61331da177e4SLinus Torvalds goto out; 61346926afd1STrond Myklebust if (decode_getfattr(xdr, res->f_attr, res->server) != 0) 613556ae19f3STrond Myklebust goto out; 6136bf269551SChuck Lever if (decode_restorefh(xdr) != 0) 613756ae19f3STrond Myklebust goto out; 61386926afd1STrond Myklebust decode_getfattr(xdr, res->dir_attr, res->server); 61391da177e4SLinus Torvalds out: 61401da177e4SLinus Torvalds return status; 61411da177e4SLinus Torvalds } 61421da177e4SLinus Torvalds 61431da177e4SLinus Torvalds /* 61441da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 61451da177e4SLinus Torvalds */ 6146bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6147bf269551SChuck Lever struct xdr_stream *xdr, 6148bf269551SChuck Lever struct nfs_open_confirmres *res) 61491da177e4SLinus Torvalds { 61501da177e4SLinus Torvalds struct compound_hdr hdr; 61511da177e4SLinus Torvalds int status; 61521da177e4SLinus Torvalds 6153bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61541da177e4SLinus Torvalds if (status) 61551da177e4SLinus Torvalds goto out; 6156bf269551SChuck Lever status = decode_putfh(xdr); 61571da177e4SLinus Torvalds if (status) 61581da177e4SLinus Torvalds goto out; 6159bf269551SChuck Lever status = decode_open_confirm(xdr, res); 61601da177e4SLinus Torvalds out: 61611da177e4SLinus Torvalds return status; 61621da177e4SLinus Torvalds } 61631da177e4SLinus Torvalds 61641da177e4SLinus Torvalds /* 61651da177e4SLinus Torvalds * Decode OPEN response 61661da177e4SLinus Torvalds */ 6167bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6168bf269551SChuck Lever struct xdr_stream *xdr, 6169bf269551SChuck Lever struct nfs_openres *res) 61701da177e4SLinus Torvalds { 61711da177e4SLinus Torvalds struct compound_hdr hdr; 61721da177e4SLinus Torvalds int status; 61731da177e4SLinus Torvalds 6174bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61751da177e4SLinus Torvalds if (status) 61761da177e4SLinus Torvalds goto out; 6177bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61789b7b9fccSAndy Adamson if (status) 61799b7b9fccSAndy Adamson goto out; 6180bf269551SChuck Lever status = decode_putfh(xdr); 61811da177e4SLinus Torvalds if (status) 61821da177e4SLinus Torvalds goto out; 6183bf269551SChuck Lever status = decode_open(xdr, res); 6184864472e9STrond Myklebust if (status) 6185864472e9STrond Myklebust goto out; 61866926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 61871da177e4SLinus Torvalds out: 61881da177e4SLinus Torvalds return status; 61891da177e4SLinus Torvalds } 61901da177e4SLinus Torvalds 61911da177e4SLinus Torvalds /* 61921da177e4SLinus Torvalds * Decode SETATTR response 61931da177e4SLinus Torvalds */ 6194bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6195bf269551SChuck Lever struct xdr_stream *xdr, 6196bf269551SChuck Lever struct nfs_setattrres *res) 61971da177e4SLinus Torvalds { 61981da177e4SLinus Torvalds struct compound_hdr hdr; 61991da177e4SLinus Torvalds int status; 62001da177e4SLinus Torvalds 6201bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62021da177e4SLinus Torvalds if (status) 62031da177e4SLinus Torvalds goto out; 6204bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62059b7b9fccSAndy Adamson if (status) 62069b7b9fccSAndy Adamson goto out; 6207bf269551SChuck Lever status = decode_putfh(xdr); 62081da177e4SLinus Torvalds if (status) 62091da177e4SLinus Torvalds goto out; 6210bf269551SChuck Lever status = decode_setattr(xdr); 62111da177e4SLinus Torvalds if (status) 62121da177e4SLinus Torvalds goto out; 62136926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62141da177e4SLinus Torvalds out: 62151da177e4SLinus Torvalds return status; 62161da177e4SLinus Torvalds } 62171da177e4SLinus Torvalds 62181da177e4SLinus Torvalds /* 62191da177e4SLinus Torvalds * Decode LOCK response 62201da177e4SLinus Torvalds */ 6221bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6222bf269551SChuck Lever struct nfs_lock_res *res) 62231da177e4SLinus Torvalds { 62241da177e4SLinus Torvalds struct compound_hdr hdr; 62251da177e4SLinus Torvalds int status; 62261da177e4SLinus Torvalds 6227bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62281da177e4SLinus Torvalds if (status) 62291da177e4SLinus Torvalds goto out; 6230bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62319b7b9fccSAndy Adamson if (status) 62329b7b9fccSAndy Adamson goto out; 6233bf269551SChuck Lever status = decode_putfh(xdr); 62341da177e4SLinus Torvalds if (status) 62351da177e4SLinus Torvalds goto out; 6236bf269551SChuck Lever status = decode_lock(xdr, res); 62371da177e4SLinus Torvalds out: 62381da177e4SLinus Torvalds return status; 62391da177e4SLinus Torvalds } 62401da177e4SLinus Torvalds 62411da177e4SLinus Torvalds /* 62421da177e4SLinus Torvalds * Decode LOCKT response 62431da177e4SLinus Torvalds */ 6244bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6245bf269551SChuck Lever struct nfs_lockt_res *res) 62461da177e4SLinus Torvalds { 62471da177e4SLinus Torvalds struct compound_hdr hdr; 62481da177e4SLinus Torvalds int status; 62491da177e4SLinus Torvalds 6250bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62511da177e4SLinus Torvalds if (status) 62521da177e4SLinus Torvalds goto out; 6253bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62549b7b9fccSAndy Adamson if (status) 62559b7b9fccSAndy Adamson goto out; 6256bf269551SChuck Lever status = decode_putfh(xdr); 62571da177e4SLinus Torvalds if (status) 62581da177e4SLinus Torvalds goto out; 6259bf269551SChuck Lever status = decode_lockt(xdr, res); 62601da177e4SLinus Torvalds out: 62611da177e4SLinus Torvalds return status; 62621da177e4SLinus Torvalds } 62631da177e4SLinus Torvalds 62641da177e4SLinus Torvalds /* 62651da177e4SLinus Torvalds * Decode LOCKU response 62661da177e4SLinus Torvalds */ 6267bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6268bf269551SChuck Lever struct nfs_locku_res *res) 62691da177e4SLinus Torvalds { 62701da177e4SLinus Torvalds struct compound_hdr hdr; 62711da177e4SLinus Torvalds int status; 62721da177e4SLinus Torvalds 6273bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62741da177e4SLinus Torvalds if (status) 62751da177e4SLinus Torvalds goto out; 6276bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62779b7b9fccSAndy Adamson if (status) 62789b7b9fccSAndy Adamson goto out; 6279bf269551SChuck Lever status = decode_putfh(xdr); 62801da177e4SLinus Torvalds if (status) 62811da177e4SLinus Torvalds goto out; 6282bf269551SChuck Lever status = decode_locku(xdr, res); 62831da177e4SLinus Torvalds out: 62841da177e4SLinus Torvalds return status; 62851da177e4SLinus Torvalds } 62861da177e4SLinus Torvalds 6287bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6288bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6289d3c7b7ccSTrond Myklebust { 6290d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6291d3c7b7ccSTrond Myklebust int status; 6292d3c7b7ccSTrond Myklebust 6293bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6294d3c7b7ccSTrond Myklebust if (!status) 6295bf269551SChuck Lever status = decode_release_lockowner(xdr); 6296d3c7b7ccSTrond Myklebust return status; 6297d3c7b7ccSTrond Myklebust } 6298d3c7b7ccSTrond Myklebust 62991da177e4SLinus Torvalds /* 63001da177e4SLinus Torvalds * Decode READLINK response 63011da177e4SLinus Torvalds */ 6302bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6303bf269551SChuck Lever struct xdr_stream *xdr, 6304f50c7000SBenny Halevy struct nfs4_readlink_res *res) 63051da177e4SLinus Torvalds { 63061da177e4SLinus Torvalds struct compound_hdr hdr; 63071da177e4SLinus Torvalds int status; 63081da177e4SLinus Torvalds 6309bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63101da177e4SLinus Torvalds if (status) 63111da177e4SLinus Torvalds goto out; 6312bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63139b7b9fccSAndy Adamson if (status) 63149b7b9fccSAndy Adamson goto out; 6315bf269551SChuck Lever status = decode_putfh(xdr); 63161da177e4SLinus Torvalds if (status) 63171da177e4SLinus Torvalds goto out; 6318bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 63191da177e4SLinus Torvalds out: 63201da177e4SLinus Torvalds return status; 63211da177e4SLinus Torvalds } 63221da177e4SLinus Torvalds 63231da177e4SLinus Torvalds /* 63241da177e4SLinus Torvalds * Decode READDIR response 63251da177e4SLinus Torvalds */ 6326bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6327bf269551SChuck Lever struct nfs4_readdir_res *res) 63281da177e4SLinus Torvalds { 63291da177e4SLinus Torvalds struct compound_hdr hdr; 63301da177e4SLinus Torvalds int status; 63311da177e4SLinus Torvalds 6332bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63331da177e4SLinus Torvalds if (status) 63341da177e4SLinus Torvalds goto out; 6335bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63369b7b9fccSAndy Adamson if (status) 63379b7b9fccSAndy Adamson goto out; 6338bf269551SChuck Lever status = decode_putfh(xdr); 63391da177e4SLinus Torvalds if (status) 63401da177e4SLinus Torvalds goto out; 6341bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 63421da177e4SLinus Torvalds out: 63431da177e4SLinus Torvalds return status; 63441da177e4SLinus Torvalds } 63451da177e4SLinus Torvalds 63461da177e4SLinus Torvalds /* 63471da177e4SLinus Torvalds * Decode Read response 63481da177e4SLinus Torvalds */ 6349bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6350bf269551SChuck Lever struct nfs_readres *res) 63511da177e4SLinus Torvalds { 63521da177e4SLinus Torvalds struct compound_hdr hdr; 63531da177e4SLinus Torvalds int status; 63541da177e4SLinus Torvalds 6355bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63561da177e4SLinus Torvalds if (status) 63571da177e4SLinus Torvalds goto out; 6358bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63599b7b9fccSAndy Adamson if (status) 63609b7b9fccSAndy Adamson goto out; 6361bf269551SChuck Lever status = decode_putfh(xdr); 63621da177e4SLinus Torvalds if (status) 63631da177e4SLinus Torvalds goto out; 6364bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 63651da177e4SLinus Torvalds if (!status) 63661da177e4SLinus Torvalds status = res->count; 63671da177e4SLinus Torvalds out: 63681da177e4SLinus Torvalds return status; 63691da177e4SLinus Torvalds } 63701da177e4SLinus Torvalds 63711da177e4SLinus Torvalds /* 63721da177e4SLinus Torvalds * Decode WRITE response 63731da177e4SLinus Torvalds */ 6374bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6375bf269551SChuck Lever struct nfs_writeres *res) 63761da177e4SLinus Torvalds { 63771da177e4SLinus Torvalds struct compound_hdr hdr; 63781da177e4SLinus Torvalds int status; 63791da177e4SLinus Torvalds 6380bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63811da177e4SLinus Torvalds if (status) 63821da177e4SLinus Torvalds goto out; 6383bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63849b7b9fccSAndy Adamson if (status) 63859b7b9fccSAndy Adamson goto out; 6386bf269551SChuck Lever status = decode_putfh(xdr); 63871da177e4SLinus Torvalds if (status) 63881da177e4SLinus Torvalds goto out; 6389bf269551SChuck Lever status = decode_write(xdr, res); 63904f9838c7STrond Myklebust if (status) 63914f9838c7STrond Myklebust goto out; 63927ffd1064SFred Isaman if (res->fattr) 63936926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63941da177e4SLinus Torvalds if (!status) 63951da177e4SLinus Torvalds status = res->count; 63961da177e4SLinus Torvalds out: 63971da177e4SLinus Torvalds return status; 63981da177e4SLinus Torvalds } 63991da177e4SLinus Torvalds 64001da177e4SLinus Torvalds /* 64011da177e4SLinus Torvalds * Decode COMMIT response 64021da177e4SLinus Torvalds */ 6403bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6404bf269551SChuck Lever struct nfs_writeres *res) 64051da177e4SLinus Torvalds { 64061da177e4SLinus Torvalds struct compound_hdr hdr; 64071da177e4SLinus Torvalds int status; 64081da177e4SLinus Torvalds 6409bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64101da177e4SLinus Torvalds if (status) 64111da177e4SLinus Torvalds goto out; 6412bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64139b7b9fccSAndy Adamson if (status) 64149b7b9fccSAndy Adamson goto out; 6415bf269551SChuck Lever status = decode_putfh(xdr); 64161da177e4SLinus Torvalds if (status) 64171da177e4SLinus Torvalds goto out; 6418bf269551SChuck Lever status = decode_commit(xdr, res); 64194f9838c7STrond Myklebust if (status) 64204f9838c7STrond Myklebust goto out; 6421988b6dceSFred Isaman if (res->fattr) 64226926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 64231da177e4SLinus Torvalds out: 64241da177e4SLinus Torvalds return status; 64251da177e4SLinus Torvalds } 64261da177e4SLinus Torvalds 64271da177e4SLinus Torvalds /* 64288b173218SRicardo Labiaga * Decode FSINFO response 64291da177e4SLinus Torvalds */ 6430bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 64313dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 64321da177e4SLinus Torvalds { 64331da177e4SLinus Torvalds struct compound_hdr hdr; 64341da177e4SLinus Torvalds int status; 64351da177e4SLinus Torvalds 6436bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64371da177e4SLinus Torvalds if (!status) 6438bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64399b7b9fccSAndy Adamson if (!status) 6440bf269551SChuck Lever status = decode_putfh(xdr); 64411da177e4SLinus Torvalds if (!status) 6442bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 64431da177e4SLinus Torvalds return status; 64441da177e4SLinus Torvalds } 64451da177e4SLinus Torvalds 64461da177e4SLinus Torvalds /* 64478b173218SRicardo Labiaga * Decode PATHCONF response 64481da177e4SLinus Torvalds */ 6449bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6450d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 64511da177e4SLinus Torvalds { 64521da177e4SLinus Torvalds struct compound_hdr hdr; 64531da177e4SLinus Torvalds int status; 64541da177e4SLinus Torvalds 6455bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64561da177e4SLinus Torvalds if (!status) 6457bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64589b7b9fccSAndy Adamson if (!status) 6459bf269551SChuck Lever status = decode_putfh(xdr); 64601da177e4SLinus Torvalds if (!status) 6461bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 64621da177e4SLinus Torvalds return status; 64631da177e4SLinus Torvalds } 64641da177e4SLinus Torvalds 64651da177e4SLinus Torvalds /* 64668b173218SRicardo Labiaga * Decode STATFS response 64671da177e4SLinus Torvalds */ 6468bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 646924ad148aSBenny Halevy struct nfs4_statfs_res *res) 64701da177e4SLinus Torvalds { 64711da177e4SLinus Torvalds struct compound_hdr hdr; 64721da177e4SLinus Torvalds int status; 64731da177e4SLinus Torvalds 6474bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64751da177e4SLinus Torvalds if (!status) 6476bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64779b7b9fccSAndy Adamson if (!status) 6478bf269551SChuck Lever status = decode_putfh(xdr); 64791da177e4SLinus Torvalds if (!status) 6480bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 64811da177e4SLinus Torvalds return status; 64821da177e4SLinus Torvalds } 64831da177e4SLinus Torvalds 64841da177e4SLinus Torvalds /* 64858b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 64861da177e4SLinus Torvalds */ 6487bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6488bf269551SChuck Lever struct xdr_stream *xdr, 6489bf269551SChuck Lever struct nfs4_server_caps_res *res) 64901da177e4SLinus Torvalds { 64911da177e4SLinus Torvalds struct compound_hdr hdr; 64921da177e4SLinus Torvalds int status; 64931da177e4SLinus Torvalds 6494bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64959b7b9fccSAndy Adamson if (status) 64969b7b9fccSAndy Adamson goto out; 6497bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64989b7b9fccSAndy Adamson if (status) 64991da177e4SLinus Torvalds goto out; 6500bf269551SChuck Lever status = decode_putfh(xdr); 6501bf269551SChuck Lever if (status) 65021da177e4SLinus Torvalds goto out; 6503bf269551SChuck Lever status = decode_server_caps(xdr, res); 65041da177e4SLinus Torvalds out: 65051da177e4SLinus Torvalds return status; 65061da177e4SLinus Torvalds } 65071da177e4SLinus Torvalds 65081da177e4SLinus Torvalds /* 65091da177e4SLinus Torvalds * Decode RENEW response 65101da177e4SLinus Torvalds */ 6511bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6512bf269551SChuck Lever void *__unused) 65131da177e4SLinus Torvalds { 65141da177e4SLinus Torvalds struct compound_hdr hdr; 65151da177e4SLinus Torvalds int status; 65161da177e4SLinus Torvalds 6517bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65181da177e4SLinus Torvalds if (!status) 6519bf269551SChuck Lever status = decode_renew(xdr); 65201da177e4SLinus Torvalds return status; 65211da177e4SLinus Torvalds } 65221da177e4SLinus Torvalds 65231da177e4SLinus Torvalds /* 65248b173218SRicardo Labiaga * Decode SETCLIENTID response 65251da177e4SLinus Torvalds */ 6526bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6527bf269551SChuck Lever struct xdr_stream *xdr, 6528bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 65291da177e4SLinus Torvalds { 65301da177e4SLinus Torvalds struct compound_hdr hdr; 65311da177e4SLinus Torvalds int status; 65321da177e4SLinus Torvalds 6533bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65341da177e4SLinus Torvalds if (!status) 6535bf269551SChuck Lever status = decode_setclientid(xdr, res); 65361da177e4SLinus Torvalds return status; 65371da177e4SLinus Torvalds } 65381da177e4SLinus Torvalds 65391da177e4SLinus Torvalds /* 65408b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 65411da177e4SLinus Torvalds */ 6542bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 6543bf269551SChuck Lever struct xdr_stream *xdr, 6544bf269551SChuck Lever struct nfs_fsinfo *fsinfo) 65451da177e4SLinus Torvalds { 65461da177e4SLinus Torvalds struct compound_hdr hdr; 65471da177e4SLinus Torvalds int status; 65481da177e4SLinus Torvalds 6549bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65501da177e4SLinus Torvalds if (!status) 6551bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 65521da177e4SLinus Torvalds if (!status) 6553bf269551SChuck Lever status = decode_putrootfh(xdr); 65541da177e4SLinus Torvalds if (!status) 6555bf269551SChuck Lever status = decode_fsinfo(xdr, fsinfo); 65561da177e4SLinus Torvalds return status; 65571da177e4SLinus Torvalds } 65581da177e4SLinus Torvalds 65591da177e4SLinus Torvalds /* 65608b173218SRicardo Labiaga * Decode DELEGRETURN response 65611da177e4SLinus Torvalds */ 6562bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6563bf269551SChuck Lever struct xdr_stream *xdr, 6564bf269551SChuck Lever struct nfs4_delegreturnres *res) 65651da177e4SLinus Torvalds { 65661da177e4SLinus Torvalds struct compound_hdr hdr; 65671da177e4SLinus Torvalds int status; 65681da177e4SLinus Torvalds 6569bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65709b7b9fccSAndy Adamson if (status) 65719b7b9fccSAndy Adamson goto out; 6572bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65739b7b9fccSAndy Adamson if (status) 6574fa178f29STrond Myklebust goto out; 6575bf269551SChuck Lever status = decode_putfh(xdr); 6576fa178f29STrond Myklebust if (status != 0) 6577fa178f29STrond Myklebust goto out; 6578bf269551SChuck Lever status = decode_delegreturn(xdr); 6579556ae3bbSJeff Layton if (status != 0) 6580556ae3bbSJeff Layton goto out; 65816926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 6582fa178f29STrond Myklebust out: 65831da177e4SLinus Torvalds return status; 65841da177e4SLinus Torvalds } 65851da177e4SLinus Torvalds 6586683b57b4STrond Myklebust /* 65878b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6588683b57b4STrond Myklebust */ 6589bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6590bf269551SChuck Lever struct xdr_stream *xdr, 659122958463SBenny Halevy struct nfs4_fs_locations_res *res) 6592683b57b4STrond Myklebust { 6593683b57b4STrond Myklebust struct compound_hdr hdr; 6594683b57b4STrond Myklebust int status; 6595683b57b4STrond Myklebust 6596bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65979b7b9fccSAndy Adamson if (status) 65989b7b9fccSAndy Adamson goto out; 6599bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 66009b7b9fccSAndy Adamson if (status) 6601683b57b4STrond Myklebust goto out; 6602bf269551SChuck Lever status = decode_putfh(xdr); 6603bf269551SChuck Lever if (status) 6604683b57b4STrond Myklebust goto out; 6605bf269551SChuck Lever status = decode_lookup(xdr); 6606bf269551SChuck Lever if (status) 6607683b57b4STrond Myklebust goto out; 6608bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 66098b7e3f49STrond Myklebust status = decode_getfattr_generic(xdr, &res->fs_locations->fattr, 66108b7e3f49STrond Myklebust NULL, res->fs_locations, 66116926afd1STrond Myklebust res->fs_locations->server); 6612683b57b4STrond Myklebust out: 6613683b57b4STrond Myklebust return status; 6614683b57b4STrond Myklebust } 6615683b57b4STrond Myklebust 66165a5ea0d4SBryan Schumaker /* 66175a5ea0d4SBryan Schumaker * Decode SECINFO response 66185a5ea0d4SBryan Schumaker */ 66195a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 66205a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 66215a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 66225a5ea0d4SBryan Schumaker { 66235a5ea0d4SBryan Schumaker struct compound_hdr hdr; 66245a5ea0d4SBryan Schumaker int status; 66255a5ea0d4SBryan Schumaker 66265a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 66275a5ea0d4SBryan Schumaker if (status) 66285a5ea0d4SBryan Schumaker goto out; 66295a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 66305a5ea0d4SBryan Schumaker if (status) 66315a5ea0d4SBryan Schumaker goto out; 66325a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 66335a5ea0d4SBryan Schumaker if (status) 66345a5ea0d4SBryan Schumaker goto out; 66355a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 66365a5ea0d4SBryan Schumaker out: 66375a5ea0d4SBryan Schumaker return status; 66385a5ea0d4SBryan Schumaker } 66395a5ea0d4SBryan Schumaker 664099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 664199fe60d0SBenny Halevy /* 66428b173218SRicardo Labiaga * Decode EXCHANGE_ID response 664399fe60d0SBenny Halevy */ 6644bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 6645bf269551SChuck Lever struct xdr_stream *xdr, 664699fe60d0SBenny Halevy void *res) 664799fe60d0SBenny Halevy { 664899fe60d0SBenny Halevy struct compound_hdr hdr; 664999fe60d0SBenny Halevy int status; 665099fe60d0SBenny Halevy 6651bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 665299fe60d0SBenny Halevy if (!status) 6653bf269551SChuck Lever status = decode_exchange_id(xdr, res); 665499fe60d0SBenny Halevy return status; 665599fe60d0SBenny Halevy } 66562050f0ccSAndy Adamson 66572050f0ccSAndy Adamson /* 66588b173218SRicardo Labiaga * Decode CREATE_SESSION response 6659fc931582SAndy Adamson */ 6660bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 6661bf269551SChuck Lever struct xdr_stream *xdr, 6662fc931582SAndy Adamson struct nfs41_create_session_res *res) 6663fc931582SAndy Adamson { 6664fc931582SAndy Adamson struct compound_hdr hdr; 6665fc931582SAndy Adamson int status; 6666fc931582SAndy Adamson 6667bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6668fc931582SAndy Adamson if (!status) 6669bf269551SChuck Lever status = decode_create_session(xdr, res); 6670fc931582SAndy Adamson return status; 6671fc931582SAndy Adamson } 6672fc931582SAndy Adamson 6673fc931582SAndy Adamson /* 66748b173218SRicardo Labiaga * Decode DESTROY_SESSION response 66750f3e66c6SAndy Adamson */ 6676bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 6677bf269551SChuck Lever struct xdr_stream *xdr, 6678bf269551SChuck Lever void *res) 66790f3e66c6SAndy Adamson { 66800f3e66c6SAndy Adamson struct compound_hdr hdr; 66810f3e66c6SAndy Adamson int status; 66820f3e66c6SAndy Adamson 6683bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66840f3e66c6SAndy Adamson if (!status) 6685bf269551SChuck Lever status = decode_destroy_session(xdr, res); 66860f3e66c6SAndy Adamson return status; 66870f3e66c6SAndy Adamson } 66880f3e66c6SAndy Adamson 66890f3e66c6SAndy Adamson /* 66908b173218SRicardo Labiaga * Decode SEQUENCE response 6691fc01cea9SAndy Adamson */ 6692bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 6693bf269551SChuck Lever struct xdr_stream *xdr, 6694fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 6695fc01cea9SAndy Adamson { 6696fc01cea9SAndy Adamson struct compound_hdr hdr; 6697fc01cea9SAndy Adamson int status; 6698fc01cea9SAndy Adamson 6699bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6700fc01cea9SAndy Adamson if (!status) 6701bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 6702fc01cea9SAndy Adamson return status; 6703fc01cea9SAndy Adamson } 6704fc01cea9SAndy Adamson 6705fc01cea9SAndy Adamson /* 67068b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 67072050f0ccSAndy Adamson */ 6708bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 6709bf269551SChuck Lever struct xdr_stream *xdr, 67102050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 67112050f0ccSAndy Adamson { 67122050f0ccSAndy Adamson struct compound_hdr hdr; 67132050f0ccSAndy Adamson int status; 67142050f0ccSAndy Adamson 6715bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67162050f0ccSAndy Adamson if (!status) 6717bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 67182050f0ccSAndy Adamson if (!status) 6719bf269551SChuck Lever status = decode_putrootfh(xdr); 67202050f0ccSAndy Adamson if (!status) 6721bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 67222050f0ccSAndy Adamson return status; 67232050f0ccSAndy Adamson } 672418019753SRicardo Labiaga 672518019753SRicardo Labiaga /* 672618019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 672718019753SRicardo Labiaga */ 6728bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 6729bf269551SChuck Lever struct xdr_stream *xdr, 673018019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 673118019753SRicardo Labiaga { 673218019753SRicardo Labiaga struct compound_hdr hdr; 673318019753SRicardo Labiaga int status; 673418019753SRicardo Labiaga 6735bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 673618019753SRicardo Labiaga if (!status) 6737bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 673818019753SRicardo Labiaga if (!status) 6739bf269551SChuck Lever status = decode_reclaim_complete(xdr, (void *)NULL); 674018019753SRicardo Labiaga return status; 674118019753SRicardo Labiaga } 6742b1f69b75SAndy Adamson 6743b1f69b75SAndy Adamson /* 67447f11d8d3SAndy Adamson * Decode GETDEVICELIST response 67457f11d8d3SAndy Adamson */ 67467f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp, 67477f11d8d3SAndy Adamson struct xdr_stream *xdr, 67487f11d8d3SAndy Adamson struct nfs4_getdevicelist_res *res) 67497f11d8d3SAndy Adamson { 67507f11d8d3SAndy Adamson struct compound_hdr hdr; 67517f11d8d3SAndy Adamson int status; 67527f11d8d3SAndy Adamson 67537f11d8d3SAndy Adamson dprintk("encoding getdevicelist!\n"); 67547f11d8d3SAndy Adamson 67557f11d8d3SAndy Adamson status = decode_compound_hdr(xdr, &hdr); 67567f11d8d3SAndy Adamson if (status != 0) 67577f11d8d3SAndy Adamson goto out; 67587f11d8d3SAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 67597f11d8d3SAndy Adamson if (status != 0) 67607f11d8d3SAndy Adamson goto out; 67617f11d8d3SAndy Adamson status = decode_putfh(xdr); 67627f11d8d3SAndy Adamson if (status != 0) 67637f11d8d3SAndy Adamson goto out; 67647f11d8d3SAndy Adamson status = decode_getdevicelist(xdr, res->devlist); 67657f11d8d3SAndy Adamson out: 67667f11d8d3SAndy Adamson return status; 67677f11d8d3SAndy Adamson } 67687f11d8d3SAndy Adamson 67697f11d8d3SAndy Adamson /* 6770b1f69b75SAndy Adamson * Decode GETDEVINFO response 6771b1f69b75SAndy Adamson */ 6772bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 6773bf269551SChuck Lever struct xdr_stream *xdr, 6774b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 6775b1f69b75SAndy Adamson { 6776b1f69b75SAndy Adamson struct compound_hdr hdr; 6777b1f69b75SAndy Adamson int status; 6778b1f69b75SAndy Adamson 6779bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6780b1f69b75SAndy Adamson if (status != 0) 6781b1f69b75SAndy Adamson goto out; 6782bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6783b1f69b75SAndy Adamson if (status != 0) 6784b1f69b75SAndy Adamson goto out; 6785bf269551SChuck Lever status = decode_getdeviceinfo(xdr, res->pdev); 6786b1f69b75SAndy Adamson out: 6787b1f69b75SAndy Adamson return status; 6788b1f69b75SAndy Adamson } 6789b1f69b75SAndy Adamson 6790b1f69b75SAndy Adamson /* 6791b1f69b75SAndy Adamson * Decode LAYOUTGET response 6792b1f69b75SAndy Adamson */ 6793bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 6794bf269551SChuck Lever struct xdr_stream *xdr, 6795b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6796b1f69b75SAndy Adamson { 6797b1f69b75SAndy Adamson struct compound_hdr hdr; 6798b1f69b75SAndy Adamson int status; 6799b1f69b75SAndy Adamson 6800bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6801b1f69b75SAndy Adamson if (status) 6802b1f69b75SAndy Adamson goto out; 6803bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6804b1f69b75SAndy Adamson if (status) 6805b1f69b75SAndy Adamson goto out; 6806bf269551SChuck Lever status = decode_putfh(xdr); 6807b1f69b75SAndy Adamson if (status) 6808b1f69b75SAndy Adamson goto out; 6809bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 6810b1f69b75SAndy Adamson out: 6811b1f69b75SAndy Adamson return status; 6812b1f69b75SAndy Adamson } 6813863a3c6cSAndy Adamson 6814863a3c6cSAndy Adamson /* 6815cbe82603SBenny Halevy * Decode LAYOUTRETURN response 6816cbe82603SBenny Halevy */ 6817cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 6818cbe82603SBenny Halevy struct xdr_stream *xdr, 6819cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6820cbe82603SBenny Halevy { 6821cbe82603SBenny Halevy struct compound_hdr hdr; 6822cbe82603SBenny Halevy int status; 6823cbe82603SBenny Halevy 6824cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 6825cbe82603SBenny Halevy if (status) 6826cbe82603SBenny Halevy goto out; 6827cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 6828cbe82603SBenny Halevy if (status) 6829cbe82603SBenny Halevy goto out; 6830cbe82603SBenny Halevy status = decode_putfh(xdr); 6831cbe82603SBenny Halevy if (status) 6832cbe82603SBenny Halevy goto out; 6833cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 6834cbe82603SBenny Halevy out: 6835cbe82603SBenny Halevy return status; 6836cbe82603SBenny Halevy } 6837cbe82603SBenny Halevy 6838cbe82603SBenny Halevy /* 6839863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 6840863a3c6cSAndy Adamson */ 6841863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 6842863a3c6cSAndy Adamson struct xdr_stream *xdr, 6843863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6844863a3c6cSAndy Adamson { 6845863a3c6cSAndy Adamson struct compound_hdr hdr; 6846863a3c6cSAndy Adamson int status; 6847863a3c6cSAndy Adamson 6848863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 6849863a3c6cSAndy Adamson if (status) 6850863a3c6cSAndy Adamson goto out; 6851863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 6852863a3c6cSAndy Adamson if (status) 6853863a3c6cSAndy Adamson goto out; 6854863a3c6cSAndy Adamson status = decode_putfh(xdr); 6855863a3c6cSAndy Adamson if (status) 6856863a3c6cSAndy Adamson goto out; 6857863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 6858863a3c6cSAndy Adamson if (status) 6859863a3c6cSAndy Adamson goto out; 68606926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 6861863a3c6cSAndy Adamson out: 6862863a3c6cSAndy Adamson return status; 6863863a3c6cSAndy Adamson } 6864fca78d6dSBryan Schumaker 6865fca78d6dSBryan Schumaker /* 6866fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 6867fca78d6dSBryan Schumaker */ 6868fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 6869fca78d6dSBryan Schumaker struct xdr_stream *xdr, 6870fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 6871fca78d6dSBryan Schumaker { 6872fca78d6dSBryan Schumaker struct compound_hdr hdr; 6873fca78d6dSBryan Schumaker int status; 6874fca78d6dSBryan Schumaker 6875fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 6876fca78d6dSBryan Schumaker if (status) 6877fca78d6dSBryan Schumaker goto out; 6878fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 6879fca78d6dSBryan Schumaker if (status) 6880fca78d6dSBryan Schumaker goto out; 6881fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 6882fca78d6dSBryan Schumaker if (status) 6883fca78d6dSBryan Schumaker goto out; 6884fca78d6dSBryan Schumaker status = decode_secinfo(xdr, res); 6885fca78d6dSBryan Schumaker out: 6886fca78d6dSBryan Schumaker return status; 6887fca78d6dSBryan Schumaker } 68887d974794SBryan Schumaker 68897d974794SBryan Schumaker /* 68907d974794SBryan Schumaker * Decode TEST_STATEID response 68917d974794SBryan Schumaker */ 68927d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 68937d974794SBryan Schumaker struct xdr_stream *xdr, 68947d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 68957d974794SBryan Schumaker { 68967d974794SBryan Schumaker struct compound_hdr hdr; 68977d974794SBryan Schumaker int status; 68987d974794SBryan Schumaker 68997d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 69007d974794SBryan Schumaker if (status) 69017d974794SBryan Schumaker goto out; 69027d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 69037d974794SBryan Schumaker if (status) 69047d974794SBryan Schumaker goto out; 69057d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 69067d974794SBryan Schumaker out: 69077d974794SBryan Schumaker return status; 69087d974794SBryan Schumaker } 69099aeda35fSBryan Schumaker 69109aeda35fSBryan Schumaker /* 69119aeda35fSBryan Schumaker * Decode FREE_STATEID response 69129aeda35fSBryan Schumaker */ 69139aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 69149aeda35fSBryan Schumaker struct xdr_stream *xdr, 69159aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 69169aeda35fSBryan Schumaker { 69179aeda35fSBryan Schumaker struct compound_hdr hdr; 69189aeda35fSBryan Schumaker int status; 69199aeda35fSBryan Schumaker 69209aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 69219aeda35fSBryan Schumaker if (status) 69229aeda35fSBryan Schumaker goto out; 69239aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 69249aeda35fSBryan Schumaker if (status) 69259aeda35fSBryan Schumaker goto out; 69269aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 69279aeda35fSBryan Schumaker out: 69289aeda35fSBryan Schumaker return status; 69299aeda35fSBryan Schumaker } 693099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 693199fe60d0SBenny Halevy 6932573c4e1eSChuck Lever /** 6933573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 6934573c4e1eSChuck Lever * the local page cache. 6935573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 6936573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 6937573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 6938573c4e1eSChuck Lever * 6939573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 6940573c4e1eSChuck Lever * returned. 6941573c4e1eSChuck Lever * 6942573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 6943573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 6944573c4e1eSChuck Lever * on a directory already in our cache. 6945573c4e1eSChuck Lever */ 6946573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 6947573c4e1eSChuck Lever int plus) 69481da177e4SLinus Torvalds { 6949dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 69501da177e4SLinus Torvalds uint32_t len; 6951babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 6952babddc72SBryan Schumaker if (unlikely(!p)) 6953babddc72SBryan Schumaker goto out_overflow; 6954c08e76d0SChuck Lever if (*p == xdr_zero) { 6955babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 6956babddc72SBryan Schumaker if (unlikely(!p)) 6957babddc72SBryan Schumaker goto out_overflow; 6958c08e76d0SChuck Lever if (*p == xdr_zero) 6959573c4e1eSChuck Lever return -EAGAIN; 69601da177e4SLinus Torvalds entry->eof = 1; 6961573c4e1eSChuck Lever return -EBADCOOKIE; 69621da177e4SLinus Torvalds } 69631da177e4SLinus Torvalds 6964babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 6965babddc72SBryan Schumaker if (unlikely(!p)) 6966babddc72SBryan Schumaker goto out_overflow; 69671da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 69681da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 6969c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 6970babddc72SBryan Schumaker 69719af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 6972babddc72SBryan Schumaker if (unlikely(!p)) 6973babddc72SBryan Schumaker goto out_overflow; 69741da177e4SLinus Torvalds entry->name = (const char *) p; 69751da177e4SLinus Torvalds 69761da177e4SLinus Torvalds /* 69771da177e4SLinus Torvalds * In case the server doesn't return an inode number, 69781da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 69791da177e4SLinus Torvalds * since glibc seems to choke on it...) 69801da177e4SLinus Torvalds */ 69811da177e4SLinus Torvalds entry->ino = 1; 69824f082222STrond Myklebust entry->fattr->valid = 0; 69831da177e4SLinus Torvalds 69849af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 6985babddc72SBryan Schumaker goto out_overflow; 69869af8c222STrond Myklebust 69879af8c222STrond Myklebust if (decode_attr_length(xdr, &len, &p) < 0) 6988babddc72SBryan Schumaker goto out_overflow; 69899af8c222STrond Myklebust 6990573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 69918b7e3f49STrond Myklebust NULL, entry->server) < 0) 6992babddc72SBryan Schumaker goto out_overflow; 699328331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 699428331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 699528331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 699682f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 69979af8c222STrond Myklebust 69980b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 69990b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 70000b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 70010b26a0bfSTrond Myklebust 7002573c4e1eSChuck Lever return 0; 7003babddc72SBryan Schumaker 7004babddc72SBryan Schumaker out_overflow: 7005babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7006573c4e1eSChuck Lever return -EAGAIN; 70071da177e4SLinus Torvalds } 70081da177e4SLinus Torvalds 70091da177e4SLinus Torvalds /* 70101da177e4SLinus Torvalds * We need to translate between nfs status return values and 70111da177e4SLinus Torvalds * the local errno values which may not be the same. 70121da177e4SLinus Torvalds */ 70131da177e4SLinus Torvalds static struct { 70141da177e4SLinus Torvalds int stat; 70151da177e4SLinus Torvalds int errno; 70161da177e4SLinus Torvalds } nfs_errtbl[] = { 70171da177e4SLinus Torvalds { NFS4_OK, 0 }, 7018856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7019856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7020856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7021856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7022856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7023856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7024856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7025856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7026856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7027856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7028856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7029856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7030856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7031856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7032856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7033856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7034856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7035856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7036856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7037856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7038856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7039856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7040fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7041856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7042856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7043856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7044856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7045856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7046856dff3dSBenny Halevy { -1, -EIO } 70471da177e4SLinus Torvalds }; 70481da177e4SLinus Torvalds 70491da177e4SLinus Torvalds /* 70501da177e4SLinus Torvalds * Convert an NFS error code to a local one. 70511da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 70521da177e4SLinus Torvalds */ 70531da177e4SLinus Torvalds static int 70540a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 70551da177e4SLinus Torvalds { 70561da177e4SLinus Torvalds int i; 70571da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 70581da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 70591da177e4SLinus Torvalds return nfs_errtbl[i].errno; 70601da177e4SLinus Torvalds } 70611da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 70621da177e4SLinus Torvalds /* The server is looney tunes. */ 7063fdcb4577STrond Myklebust return -EREMOTEIO; 70641da177e4SLinus Torvalds } 70651da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 70661da177e4SLinus Torvalds * handle it. 70671da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 70681da177e4SLinus Torvalds * not conflict with native Linux error codes. 70691da177e4SLinus Torvalds */ 7070856dff3dSBenny Halevy return -stat; 70711da177e4SLinus Torvalds } 70721da177e4SLinus Torvalds 70731da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 70741da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 70751da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 70769f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7077bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 70782bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 70792bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7080cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7081cc0175c1SChuck Lever .p_name = #proc, \ 70821da177e4SLinus Torvalds } 70831da177e4SLinus Torvalds 70841da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 70851da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 70861da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 70871da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 70881da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 70891da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 70901da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 70911da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 70921da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 70931da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 70941da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 70951da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 70961da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 70971da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 70981da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 70991da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 71001da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 71011da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 71021da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 71031da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 71041da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 71051da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 71061da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 71071da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 71081da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 71091da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 71101da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 71111da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 71121da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 71131da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 71141da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 71151da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7116029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 711723ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7118683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7119d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 71205a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 712199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 712299fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7123fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 71240f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7125fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 71262050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 712718019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7128b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7129b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7130863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7131cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7132fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 71337d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 71349aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 71357f11d8d3SAndy Adamson PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist), 713699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 71371da177e4SLinus Torvalds }; 71381da177e4SLinus Torvalds 7139a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 71401da177e4SLinus Torvalds .number = 4, 7141e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 71421da177e4SLinus Torvalds .procs = nfs4_procedures 71431da177e4SLinus Torvalds }; 71441da177e4SLinus Torvalds 71451da177e4SLinus Torvalds /* 71461da177e4SLinus Torvalds * Local variables: 71471da177e4SLinus Torvalds * c-basic-offset: 8 71481da177e4SLinus Torvalds * End: 71491da177e4SLinus Torvalds */ 7150