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 { 1087475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1088475d4ba0STrond Myklebust encode_uint32(xdr, access); 10891da177e4SLinus Torvalds } 10901da177e4SLinus Torvalds 1091cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 10921da177e4SLinus Torvalds { 1093ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 10944ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1095ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 10961da177e4SLinus Torvalds } 10971da177e4SLinus Torvalds 1098cf8cdbe5SAndy Adamson static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 10991da177e4SLinus Torvalds { 11008687b63aSAl Viro __be32 *p; 11011da177e4SLinus Torvalds 1102475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1103475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1104b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 110534558513SBenny Halevy *p = cpu_to_be32(args->count); 11061da177e4SLinus Torvalds } 11071da177e4SLinus Torvalds 1108cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11091da177e4SLinus Torvalds { 11108687b63aSAl Viro __be32 *p; 11111da177e4SLinus Torvalds 1112475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1113475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11141da177e4SLinus Torvalds 11151da177e4SLinus Torvalds switch (create->ftype) { 11161da177e4SLinus Torvalds case NF4LNK: 111713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 111834558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 111994a6d753SChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 11201da177e4SLinus Torvalds break; 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 112313c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1124e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 112534558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11261da177e4SLinus Torvalds break; 11271da177e4SLinus Torvalds 11281da177e4SLinus Torvalds default: 11291da177e4SLinus Torvalds break; 11301da177e4SLinus Torvalds } 11311da177e4SLinus Torvalds 1132811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 1133cf8cdbe5SAndy Adamson encode_attrs(xdr, create->attrs, create->server); 11341da177e4SLinus Torvalds } 11351da177e4SLinus Torvalds 1136cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11371da177e4SLinus Torvalds { 11388687b63aSAl Viro __be32 *p; 11391da177e4SLinus Torvalds 1140475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1141475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1142e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 114334558513SBenny Halevy *p = cpu_to_be32(bitmap); 11441da177e4SLinus Torvalds } 11451da177e4SLinus Torvalds 1146cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 11471da177e4SLinus Torvalds { 11488687b63aSAl Viro __be32 *p; 11491da177e4SLinus Torvalds 1150475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1151475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1152e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1153e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 115434558513SBenny Halevy *p = cpu_to_be32(bm1); 11551da177e4SLinus Torvalds } 11561da177e4SLinus Torvalds 1157dae100c2SFred Isaman static void 1158dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1159dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1160dae100c2SFred Isaman struct compound_hdr *hdr) 1161dae100c2SFred Isaman { 1162dae100c2SFred Isaman __be32 *p; 1163dae100c2SFred Isaman 1164ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1165dae100c2SFred Isaman if (bm2) { 1166dae100c2SFred Isaman p = reserve_space(xdr, 16); 1167dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1168dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1169dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1170dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1171dae100c2SFred Isaman } else if (bm1) { 1172dae100c2SFred Isaman p = reserve_space(xdr, 12); 1173dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1174dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1175dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1176dae100c2SFred Isaman } else { 1177dae100c2SFred Isaman p = reserve_space(xdr, 8); 1178dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1179dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1180dae100c2SFred Isaman } 1181dae100c2SFred Isaman } 1182dae100c2SFred Isaman 1183cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 11841da177e4SLinus Torvalds { 1185cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1186d017931cSAndy Adamson bitmask[1] & nfs4_fattr_bitmap[1], hdr); 11871da177e4SLinus Torvalds } 11881da177e4SLinus Torvalds 1189cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 11901da177e4SLinus Torvalds { 1191dae100c2SFred Isaman encode_getattr_three(xdr, 1192dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1193dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1194dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1195dae100c2SFred Isaman hdr); 11961da177e4SLinus Torvalds } 11971da177e4SLinus Torvalds 1198cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1199830b8e33SManoj Naik { 1200cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1201cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1202830b8e33SManoj Naik } 1203830b8e33SManoj Naik 1204cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12051da177e4SLinus Torvalds { 1206ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12071da177e4SLinus Torvalds } 12081da177e4SLinus Torvalds 1209cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12101da177e4SLinus Torvalds { 1211ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12126fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12131da177e4SLinus Torvalds } 12141da177e4SLinus Torvalds 1215911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1216911d1aafSTrond Myklebust { 1217911d1aafSTrond Myklebust if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) 1218911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1219911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1220911d1aafSTrond Myklebust } 1221911d1aafSTrond Myklebust 1222911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1223911d1aafSTrond Myklebust { 1224911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1225911d1aafSTrond Myklebust return ~(uint64_t)0; 1226911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1227911d1aafSTrond Myklebust } 1228911d1aafSTrond Myklebust 1229daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1230daccbdedSTrond Myklebust { 1231daccbdedSTrond Myklebust __be32 *p; 1232daccbdedSTrond Myklebust 1233d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1234daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1235d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1236daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1237d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1238daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1239daccbdedSTrond Myklebust } 1240daccbdedSTrond Myklebust 12411da177e4SLinus Torvalds /* 12421da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 12431da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 12441da177e4SLinus Torvalds */ 1245cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 12461da177e4SLinus Torvalds { 12478687b63aSAl Viro __be32 *p; 12481da177e4SLinus Torvalds 1249475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1250475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1251e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1252e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1253b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1254b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 125534558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1256911d1aafSTrond Myklebust if (args->new_lock_owner){ 12574ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1258ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->open_stateid); 12594ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1260daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12611da177e4SLinus Torvalds } 12621da177e4SLinus Torvalds else { 1263ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->lock_stateid); 12644ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 12651da177e4SLinus Torvalds } 12661da177e4SLinus Torvalds } 12671da177e4SLinus Torvalds 1268cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 12691da177e4SLinus Torvalds { 12708687b63aSAl Viro __be32 *p; 12711da177e4SLinus Torvalds 1272475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1273475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1274e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1275b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1276b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1277daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12781da177e4SLinus Torvalds } 12791da177e4SLinus Torvalds 1280cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 12811da177e4SLinus Torvalds { 12828687b63aSAl Viro __be32 *p; 12831da177e4SLinus Torvalds 1284475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1285475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 12864ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1287ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 1288ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1289b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 129034558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 12911da177e4SLinus Torvalds } 12921da177e4SLinus Torvalds 1293d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1294d3c7b7ccSTrond Myklebust { 1295ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1296d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1297d3c7b7ccSTrond Myklebust } 1298d3c7b7ccSTrond Myklebust 1299cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13001da177e4SLinus Torvalds { 1301ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13026fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13031da177e4SLinus Torvalds } 13041da177e4SLinus Torvalds 1305dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 13061da177e4SLinus Torvalds { 13078687b63aSAl Viro __be32 *p; 13081da177e4SLinus Torvalds 130913c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1310dc0b027dSTrond Myklebust switch (fmode & (FMODE_READ|FMODE_WRITE)) { 13111da177e4SLinus Torvalds case FMODE_READ: 1312e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 13131da177e4SLinus Torvalds break; 13141da177e4SLinus Torvalds case FMODE_WRITE: 1315e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 13161da177e4SLinus Torvalds break; 13171da177e4SLinus Torvalds case FMODE_READ|FMODE_WRITE: 1318e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 13191da177e4SLinus Torvalds break; 13201da177e4SLinus Torvalds default: 1321e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 13221da177e4SLinus Torvalds } 132334558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13241da177e4SLinus Torvalds } 13251da177e4SLinus Torvalds 13261da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13271da177e4SLinus Torvalds { 13288687b63aSAl Viro __be32 *p; 13291da177e4SLinus Torvalds /* 13301da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13311da177e4SLinus Torvalds * owner 4 = 32 13321da177e4SLinus Torvalds */ 13334ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1334dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 1335d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1336b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 1337d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 133893f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1339d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 134034558513SBenny Halevy xdr_encode_hyper(p, arg->id); 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds 13431da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13441da177e4SLinus Torvalds { 13458687b63aSAl Viro __be32 *p; 13464882ef72SAlexandros Batsakis struct nfs_client *clp; 13471da177e4SLinus Torvalds 134813c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13491da177e4SLinus Torvalds switch(arg->open_flags & O_EXCL) { 13501da177e4SLinus Torvalds case 0: 135134558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 13521da177e4SLinus Torvalds encode_attrs(xdr, arg->u.attrs, arg->server); 13531da177e4SLinus Torvalds break; 13541da177e4SLinus Torvalds default: 13554882ef72SAlexandros Batsakis clp = arg->server->nfs_client; 1356a4432345STrond Myklebust if (clp->cl_mvops->minor_version > 0) { 13574882ef72SAlexandros Batsakis if (nfs4_has_persistent_session(clp)) { 13584882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 13594882ef72SAlexandros Batsakis encode_attrs(xdr, arg->u.attrs, arg->server); 13604882ef72SAlexandros Batsakis } else { 13614882ef72SAlexandros Batsakis struct iattr dummy; 13624882ef72SAlexandros Batsakis 13634882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 13644882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 13654882ef72SAlexandros Batsakis dummy.ia_valid = 0; 13664882ef72SAlexandros Batsakis encode_attrs(xdr, &dummy, arg->server); 13674882ef72SAlexandros Batsakis } 13684882ef72SAlexandros Batsakis } else { 136934558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 13701da177e4SLinus Torvalds encode_nfs4_verifier(xdr, &arg->u.verifier); 13711da177e4SLinus Torvalds } 13721da177e4SLinus Torvalds } 13734882ef72SAlexandros Batsakis } 13741da177e4SLinus Torvalds 13751da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13761da177e4SLinus Torvalds { 13778687b63aSAl Viro __be32 *p; 13781da177e4SLinus Torvalds 137913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13801da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 13811da177e4SLinus Torvalds case 0: 138234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 13831da177e4SLinus Torvalds break; 13841da177e4SLinus Torvalds default: 13851da177e4SLinus Torvalds BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 138634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 13871da177e4SLinus Torvalds encode_createmode(xdr, arg); 13881da177e4SLinus Torvalds } 13891da177e4SLinus Torvalds } 13901da177e4SLinus Torvalds 1391bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 13921da177e4SLinus Torvalds { 13938687b63aSAl Viro __be32 *p; 13941da177e4SLinus Torvalds 139513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13961da177e4SLinus Torvalds switch (delegation_type) { 13971da177e4SLinus Torvalds case 0: 139834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 13991da177e4SLinus Torvalds break; 14001da177e4SLinus Torvalds case FMODE_READ: 140134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14021da177e4SLinus Torvalds break; 14031da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 140434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14051da177e4SLinus Torvalds break; 14061da177e4SLinus Torvalds default: 14071da177e4SLinus Torvalds BUG(); 14081da177e4SLinus Torvalds } 14091da177e4SLinus Torvalds } 14101da177e4SLinus Torvalds 14111da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14121da177e4SLinus Torvalds { 14138687b63aSAl Viro __be32 *p; 14141da177e4SLinus Torvalds 141513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 141634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14171da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14181da177e4SLinus Torvalds } 14191da177e4SLinus Torvalds 1420bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14211da177e4SLinus Torvalds { 14228687b63aSAl Viro __be32 *p; 14231da177e4SLinus Torvalds 142413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 142534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14261da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14271da177e4SLinus Torvalds } 14281da177e4SLinus Torvalds 14291da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14301da177e4SLinus Torvalds { 14318687b63aSAl Viro __be32 *p; 14321da177e4SLinus Torvalds 1433ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1434ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1435ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14361da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14371da177e4SLinus Torvalds } 14381da177e4SLinus Torvalds 1439cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 14401da177e4SLinus Torvalds { 1441ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 14421da177e4SLinus Torvalds encode_openhdr(xdr, arg); 14431da177e4SLinus Torvalds encode_opentype(xdr, arg); 14441da177e4SLinus Torvalds switch (arg->claim) { 14451da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 14461da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 14471da177e4SLinus Torvalds break; 14481da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 14491da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 14501da177e4SLinus Torvalds break; 14511da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 14521da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 14531da177e4SLinus Torvalds break; 14541da177e4SLinus Torvalds default: 14551da177e4SLinus Torvalds BUG(); 14561da177e4SLinus Torvalds } 14571da177e4SLinus Torvalds } 14581da177e4SLinus Torvalds 1459cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 14601da177e4SLinus Torvalds { 1461ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1462ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14634ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds 1466cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 14671da177e4SLinus Torvalds { 1468ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1469ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14704ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1471dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 14721da177e4SLinus Torvalds } 14731da177e4SLinus Torvalds 1474cf8cdbe5SAndy Adamson static void 1475d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 14761da177e4SLinus Torvalds { 1477ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 14786fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 14791da177e4SLinus Torvalds } 14801da177e4SLinus Torvalds 1481cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 14821da177e4SLinus Torvalds { 1483ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 14841da177e4SLinus Torvalds } 14851da177e4SLinus Torvalds 1486d0b496d2STrond 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) 14871da177e4SLinus Torvalds { 14881da177e4SLinus Torvalds nfs4_stateid stateid; 14891da177e4SLinus Torvalds 14901da177e4SLinus Torvalds if (ctx->state != NULL) { 14911e3987c3STrond Myklebust nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid); 149289d1ea65SAndy Adamson if (zero_seqid) 14932d2f24adSTrond Myklebust stateid.seqid = 0; 1494ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &stateid); 14951da177e4SLinus Torvalds } else 1496ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 14971da177e4SLinus Torvalds } 14981da177e4SLinus Torvalds 1499cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 15001da177e4SLinus Torvalds { 15018687b63aSAl Viro __be32 *p; 15021da177e4SLinus Torvalds 1503ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 1504d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 150589d1ea65SAndy Adamson hdr->minorversion); 15061da177e4SLinus Torvalds 150713c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1508b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 150934558513SBenny Halevy *p = cpu_to_be32(args->count); 15101da177e4SLinus Torvalds } 15111da177e4SLinus Torvalds 1512cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15131da177e4SLinus Torvalds { 151428331a46STrond Myklebust uint32_t attrs[2] = { 151528331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 151628331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 151728331a46STrond Myklebust }; 15186f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1519cd93710eSChuck Lever __be32 *p, verf[2]; 15201da177e4SLinus Torvalds 152182f2e547SBryan Schumaker if (readdir->plus) { 152282f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 152328331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 152482f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 152582f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 152682f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 152782f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 15286f7a35bdSTrond Myklebust dircount >>= 1; 152982f2e547SBryan Schumaker } 153028331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 153128331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 153228331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 15336f7a35bdSTrond Myklebust 1534475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1535475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 15366f7a35bdSTrond Myklebust p = xdr_encode_hyper(p, readdir->cookie); 1537cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1538cd93710eSChuck Lever p = reserve_space(xdr, 20); 15396f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 15406f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 15416f7a35bdSTrond Myklebust *p++ = cpu_to_be32(2); 154282f2e547SBryan Schumaker 1543e75bc1c8SBenny Halevy *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 154434558513SBenny Halevy *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1545cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 154644109241SFred Isaman dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 154744109241SFred Isaman __func__, 1548eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1549cd93710eSChuck Lever verf[0], verf[1], 1550eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1551eadf4598STrond Myklebust attrs[1] & readdir->bitmask[1]); 15521da177e4SLinus Torvalds } 15531da177e4SLinus Torvalds 1554cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 15551da177e4SLinus Torvalds { 1556ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 15571da177e4SLinus Torvalds } 15581da177e4SLinus Torvalds 1559cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 15601da177e4SLinus Torvalds { 1561ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 15626fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 15631da177e4SLinus Torvalds } 15641da177e4SLinus Torvalds 1565cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 15661da177e4SLinus Torvalds { 1567ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1568811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1569811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 15701da177e4SLinus Torvalds } 15711da177e4SLinus Torvalds 1572bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1573bb4dae5eSChuck Lever struct compound_hdr *hdr) 15741da177e4SLinus Torvalds { 15758687b63aSAl Viro __be32 *p; 15761da177e4SLinus Torvalds 1577475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1578475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1579bb4dae5eSChuck Lever xdr_encode_hyper(p, clid); 15801da177e4SLinus Torvalds } 15811da177e4SLinus Torvalds 1582cf8cdbe5SAndy Adamson static void 1583d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 158456ae19f3STrond Myklebust { 1585ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 158656ae19f3STrond Myklebust } 158756ae19f3STrond Myklebust 15889f06c719SChuck Lever static void 1589d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 159023ec6965SJ. Bruce Fields { 15918687b63aSAl Viro __be32 *p; 159223ec6965SJ. Bruce Fields 1593ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1594ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 159513c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1596e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 159734558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 15989f06c719SChuck Lever BUG_ON(arg->acl_len % 4); 159913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 160034558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 160123ec6965SJ. Bruce Fields xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 160223ec6965SJ. Bruce Fields } 160323ec6965SJ. Bruce Fields 1604cf8cdbe5SAndy Adamson static void 1605d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16061da177e4SLinus Torvalds { 1607ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16081da177e4SLinus Torvalds } 16091da177e4SLinus Torvalds 1610cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16111da177e4SLinus Torvalds { 1612ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1613ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1614cf8cdbe5SAndy Adamson encode_attrs(xdr, arg->iap, server); 16151da177e4SLinus Torvalds } 16161da177e4SLinus Torvalds 1617cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16181da177e4SLinus Torvalds { 16198687b63aSAl Viro __be32 *p; 16201da177e4SLinus Torvalds 162170019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1622cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16231da177e4SLinus Torvalds 16241da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 162513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 162634558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16271da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16281da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 162913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 163034558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_cb_ident); 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds 1633bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16341da177e4SLinus Torvalds { 16358687b63aSAl Viro __be32 *p; 16361da177e4SLinus Torvalds 1637475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1638475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1639475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1640bb8b27e5STrond Myklebust p = xdr_encode_hyper(p, arg->clientid); 1641cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 16421da177e4SLinus Torvalds } 16431da177e4SLinus Torvalds 1644cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 16451da177e4SLinus Torvalds { 16468687b63aSAl Viro __be32 *p; 16471da177e4SLinus Torvalds 1648ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 1649d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 165089d1ea65SAndy Adamson hdr->minorversion); 16511da177e4SLinus Torvalds 165213c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1653b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1654e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 165534558513SBenny Halevy *p = cpu_to_be32(args->count); 16561da177e4SLinus Torvalds 16571da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 16581da177e4SLinus Torvalds } 16591da177e4SLinus Torvalds 1660cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 16611da177e4SLinus Torvalds { 1662ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1663ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 16641da177e4SLinus Torvalds } 16659b7b9fccSAndy Adamson 16665a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16675a5ea0d4SBryan Schumaker { 1668ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 16696fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16705a5ea0d4SBryan Schumaker } 16715a5ea0d4SBryan Schumaker 167299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 16739b7b9fccSAndy Adamson /* NFSv4.1 operations */ 167499fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 167599fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 167699fe60d0SBenny Halevy struct compound_hdr *hdr) 167799fe60d0SBenny Halevy { 167899fe60d0SBenny Halevy __be32 *p; 1679db8ac8baSWeston Andros Adamson char impl_name[NFS4_OPAQUE_LIMIT]; 1680db8ac8baSWeston Andros Adamson int len = 0; 168199fe60d0SBenny Halevy 168270019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1683cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 168499fe60d0SBenny Halevy 168599fe60d0SBenny Halevy encode_string(xdr, args->id_len, args->id); 168699fe60d0SBenny Halevy 168713c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1688e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); 1689e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1690db8ac8baSWeston Andros Adamson 1691db8ac8baSWeston Andros Adamson if (send_implementation_id && 1692db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1693db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1694db8ac8baSWeston Andros Adamson <= NFS4_OPAQUE_LIMIT + 1) 1695db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1696db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1697db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1698db8ac8baSWeston Andros Adamson 1699db8ac8baSWeston Andros Adamson if (len > 0) { 1700db8ac8baSWeston Andros Adamson *p = cpu_to_be32(1); /* implementation id array length=1 */ 1701db8ac8baSWeston Andros Adamson 1702db8ac8baSWeston Andros Adamson encode_string(xdr, 1703db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1704db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1705db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1706db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1707db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1708db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1709db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1710db8ac8baSWeston Andros Adamson } else 1711db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); /* implementation id array length=0 */ 171299fe60d0SBenny Halevy } 1713fc931582SAndy Adamson 1714fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1715fc931582SAndy Adamson struct nfs41_create_session_args *args, 1716fc931582SAndy Adamson struct compound_hdr *hdr) 1717fc931582SAndy Adamson { 1718fc931582SAndy Adamson __be32 *p; 1719fc931582SAndy Adamson char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1720fc931582SAndy Adamson uint32_t len; 1721fc931582SAndy Adamson struct nfs_client *clp = args->client; 17228e0d46e1SMike Sager u32 max_resp_sz_cached; 17238e0d46e1SMike Sager 17248e0d46e1SMike Sager /* 17258e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 17268e0d46e1SMike Sager * 2 is the verifier. 17278e0d46e1SMike Sager */ 17288e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 17298e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1730fc931582SAndy Adamson 1731fc931582SAndy Adamson len = scnprintf(machine_name, sizeof(machine_name), "%s", 1732fc931582SAndy Adamson clp->cl_ipaddr); 173342edd698SBenny Halevy 1734475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 1735475d4ba0STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12); 1736114f64b5SAndy Adamson p = xdr_encode_hyper(p, clp->cl_clientid); 1737e75bc1c8SBenny Halevy *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1738e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1739fc931582SAndy Adamson 1740fc931582SAndy Adamson /* Fore Channel */ 1741c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1742e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1743e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 17448e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1745e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1746e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1747e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1748fc931582SAndy Adamson 1749fc931582SAndy Adamson /* Back Channel */ 1750c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1751e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1752e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1753e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1754e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1755e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1756e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1757fc931582SAndy Adamson 1758e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1759e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1760e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1761fc931582SAndy Adamson 1762fc931582SAndy Adamson /* authsys_parms rfc1831 */ 1763e75bc1c8SBenny Halevy *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ 1764811652bdSBenny Halevy p = xdr_encode_opaque(p, machine_name, len); 1765e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1766e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 176734558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1768fc931582SAndy Adamson } 17690f3e66c6SAndy Adamson 17700f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 17710f3e66c6SAndy Adamson struct nfs4_session *session, 17720f3e66c6SAndy Adamson struct compound_hdr *hdr) 17730f3e66c6SAndy Adamson { 1774475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1775475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 17760f3e66c6SAndy Adamson } 177718019753SRicardo Labiaga 177818019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 177918019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 178018019753SRicardo Labiaga struct compound_hdr *hdr) 178118019753SRicardo Labiaga { 1782475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1783475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 178418019753SRicardo Labiaga } 178599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 178699fe60d0SBenny Halevy 17879b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 17889b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 17899b7b9fccSAndy Adamson struct compound_hdr *hdr) 17909b7b9fccSAndy Adamson { 17919b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 17929b7b9fccSAndy Adamson struct nfs4_session *session = args->sa_session; 1793fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 1794fc01cea9SAndy Adamson struct nfs4_slot *slot; 1795fc01cea9SAndy Adamson __be32 *p; 17969b7b9fccSAndy Adamson 17979b7b9fccSAndy Adamson if (!session) 17989b7b9fccSAndy Adamson return; 17999b7b9fccSAndy Adamson 1800fc01cea9SAndy Adamson tp = &session->fc_slot_table; 1801fc01cea9SAndy Adamson 1802fc01cea9SAndy Adamson WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1803fc01cea9SAndy Adamson slot = tp->slots + args->sa_slotid; 1804fc01cea9SAndy Adamson 1805475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1806fc01cea9SAndy Adamson 1807fc01cea9SAndy Adamson /* 1808fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1809fc01cea9SAndy Adamson */ 1810fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1811fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1812fc01cea9SAndy Adamson __func__, 1813fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1814fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1815fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1816fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 1817fc01cea9SAndy Adamson slot->seq_nr, args->sa_slotid, 1818fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1819475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 182093f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1821e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 1822e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->sa_slotid); 1823e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 182434558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 18259b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 18269b7b9fccSAndy Adamson } 18279b7b9fccSAndy Adamson 1828b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1829b1f69b75SAndy Adamson static void 18307f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr, 18317f11d8d3SAndy Adamson const struct nfs4_getdevicelist_args *args, 18327f11d8d3SAndy Adamson struct compound_hdr *hdr) 18337f11d8d3SAndy Adamson { 18347f11d8d3SAndy Adamson __be32 *p; 18357f11d8d3SAndy Adamson nfs4_verifier dummy = { 18367f11d8d3SAndy Adamson .data = "dummmmmy", 18377f11d8d3SAndy Adamson }; 18387f11d8d3SAndy Adamson 1839475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr); 1840475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 18417f11d8d3SAndy Adamson *p++ = cpu_to_be32(args->layoutclass); 18427f11d8d3SAndy Adamson *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 18437f11d8d3SAndy Adamson xdr_encode_hyper(p, 0ULL); /* cookie */ 18447f11d8d3SAndy Adamson encode_nfs4_verifier(xdr, &dummy); 18457f11d8d3SAndy Adamson } 18467f11d8d3SAndy Adamson 18477f11d8d3SAndy Adamson static void 1848b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1849b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1850b1f69b75SAndy Adamson struct compound_hdr *hdr) 1851b1f69b75SAndy Adamson { 1852b1f69b75SAndy Adamson __be32 *p; 1853b1f69b75SAndy Adamson 1854475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 1855475d4ba0STrond Myklebust p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE); 1856b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1857b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1858b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1859b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ 1860b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1861b1f69b75SAndy Adamson } 1862b1f69b75SAndy Adamson 1863b1f69b75SAndy Adamson static void 1864b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1865b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1866b1f69b75SAndy Adamson struct compound_hdr *hdr) 1867b1f69b75SAndy Adamson { 1868b1f69b75SAndy Adamson __be32 *p; 1869b1f69b75SAndy Adamson 1870475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1871475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1872b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1873b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1874b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1875b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1876b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1877b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1878ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1879475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1880b1f69b75SAndy Adamson 1881b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1882b1f69b75SAndy Adamson __func__, 1883b1f69b75SAndy Adamson args->type, 1884b1f69b75SAndy Adamson args->range.iomode, 1885b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1886b1f69b75SAndy Adamson (unsigned long)args->range.length, 1887b1f69b75SAndy Adamson args->maxcount); 1888b1f69b75SAndy Adamson } 1889863a3c6cSAndy Adamson 1890863a3c6cSAndy Adamson static int 1891863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1892ac7db726SBenny Halevy struct inode *inode, 1893863a3c6cSAndy Adamson const struct nfs4_layoutcommit_args *args, 1894863a3c6cSAndy Adamson struct compound_hdr *hdr) 1895863a3c6cSAndy Adamson { 1896863a3c6cSAndy Adamson __be32 *p; 1897863a3c6cSAndy Adamson 1898863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1899863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1900863a3c6cSAndy Adamson 1901475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1902475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1903863a3c6cSAndy Adamson /* Only whole file layouts */ 1904863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19053557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1906ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1907ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1908ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1909863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1910863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 1911863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1912863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 1913ac7db726SBenny Halevy 1914ac7db726SBenny Halevy if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 1915ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1916ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 1917475d4ba0STrond Myklebust else 1918475d4ba0STrond Myklebust encode_uint32(xdr, 0); /* no layout-type payload */ 1919863a3c6cSAndy Adamson 1920863a3c6cSAndy Adamson return 0; 1921863a3c6cSAndy Adamson } 1922cbe82603SBenny Halevy 1923cbe82603SBenny Halevy static void 1924cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 1925cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 1926cbe82603SBenny Halevy struct compound_hdr *hdr) 1927cbe82603SBenny Halevy { 1928cbe82603SBenny Halevy __be32 *p; 1929cbe82603SBenny Halevy 1930475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 1931475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 1932cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 1933cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 1934cbe82603SBenny Halevy *p++ = cpu_to_be32(IOMODE_ANY); 1935cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 1936ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1937cbe82603SBenny Halevy p = xdr_encode_hyper(p, 0); 1938cbe82603SBenny Halevy p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 1939cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 1940ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1941cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 194204a55549SAndy Adamson if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 194304a55549SAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 194404a55549SAndy Adamson NFS_I(args->inode)->layout, xdr, args); 1945475d4ba0STrond Myklebust } else 1946475d4ba0STrond Myklebust encode_uint32(xdr, 0); 1947cbe82603SBenny Halevy } 1948fca78d6dSBryan Schumaker 1949fca78d6dSBryan Schumaker static int 1950fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 1951fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 1952fca78d6dSBryan Schumaker struct compound_hdr *hdr) 1953fca78d6dSBryan Schumaker { 1954475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 1955475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 1956fca78d6dSBryan Schumaker return 0; 1957fca78d6dSBryan Schumaker } 19587d974794SBryan Schumaker 19597d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 19607d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 19617d974794SBryan Schumaker struct compound_hdr *hdr) 19627d974794SBryan Schumaker { 1963475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 1964475d4ba0STrond Myklebust encode_uint32(xdr, 1); 1965ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 19667d974794SBryan Schumaker } 19679aeda35fSBryan Schumaker 19689aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 19699aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 19709aeda35fSBryan Schumaker struct compound_hdr *hdr) 19719aeda35fSBryan Schumaker { 1972ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 1973ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 19749aeda35fSBryan Schumaker } 1975b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 1976b1f69b75SAndy Adamson 19771da177e4SLinus Torvalds /* 19781da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 19791da177e4SLinus Torvalds */ 19801da177e4SLinus Torvalds 198166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 198266cc0429SBenny Halevy { 198366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 198466cc0429SBenny Halevy if (args->sa_session) 1985a4432345STrond Myklebust return args->sa_session->clp->cl_mvops->minor_version; 198666cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 198766cc0429SBenny Halevy return 0; 198866cc0429SBenny Halevy } 198966cc0429SBenny Halevy 19901da177e4SLinus Torvalds /* 19911da177e4SLinus Torvalds * Encode an ACCESS request 19921da177e4SLinus Torvalds */ 19939f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 19949f06c719SChuck Lever const struct nfs4_accessargs *args) 19951da177e4SLinus Torvalds { 19961da177e4SLinus Torvalds struct compound_hdr hdr = { 199766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 19981da177e4SLinus Torvalds }; 19991da177e4SLinus Torvalds 20009f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20019f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20029f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20039f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 20049f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2005d017931cSAndy Adamson encode_nops(&hdr); 20061da177e4SLinus Torvalds } 20071da177e4SLinus Torvalds 20081da177e4SLinus Torvalds /* 20091da177e4SLinus Torvalds * Encode LOOKUP request 20101da177e4SLinus Torvalds */ 20119f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 20129f06c719SChuck Lever const struct nfs4_lookup_arg *args) 20131da177e4SLinus Torvalds { 20141da177e4SLinus Torvalds struct compound_hdr hdr = { 201566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20161da177e4SLinus Torvalds }; 20171da177e4SLinus Torvalds 20189f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20199f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20209f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 20219f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 20229f06c719SChuck Lever encode_getfh(xdr, &hdr); 20239f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2024d017931cSAndy Adamson encode_nops(&hdr); 20251da177e4SLinus Torvalds } 20261da177e4SLinus Torvalds 20271da177e4SLinus Torvalds /* 20281da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 20291da177e4SLinus Torvalds */ 20309f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 20319f06c719SChuck Lever struct xdr_stream *xdr, 20329f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 20331da177e4SLinus Torvalds { 20341da177e4SLinus Torvalds struct compound_hdr hdr = { 203566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20361da177e4SLinus Torvalds }; 20371da177e4SLinus Torvalds 20389f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20399f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20409f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 20419f06c719SChuck Lever encode_getfh(xdr, &hdr); 20429f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2043d017931cSAndy Adamson encode_nops(&hdr); 20441da177e4SLinus Torvalds } 20451da177e4SLinus Torvalds 20461da177e4SLinus Torvalds /* 20471da177e4SLinus Torvalds * Encode REMOVE request 20481da177e4SLinus Torvalds */ 20499f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 20509f06c719SChuck Lever const struct nfs_removeargs *args) 20511da177e4SLinus Torvalds { 20521da177e4SLinus Torvalds struct compound_hdr hdr = { 205366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20541da177e4SLinus Torvalds }; 20551da177e4SLinus Torvalds 20569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20579f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20589f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20599f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 20609f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2061d017931cSAndy Adamson encode_nops(&hdr); 20621da177e4SLinus Torvalds } 20631da177e4SLinus Torvalds 20641da177e4SLinus Torvalds /* 20651da177e4SLinus Torvalds * Encode RENAME request 20661da177e4SLinus Torvalds */ 20679f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 20689f06c719SChuck Lever const struct nfs_renameargs *args) 20691da177e4SLinus Torvalds { 20701da177e4SLinus Torvalds struct compound_hdr hdr = { 207166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20721da177e4SLinus Torvalds }; 20731da177e4SLinus Torvalds 20749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20769f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 20779f06c719SChuck Lever encode_savefh(xdr, &hdr); 20789f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 20799f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 20809f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 20819f06c719SChuck Lever encode_restorefh(xdr, &hdr); 20829f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2083d017931cSAndy Adamson encode_nops(&hdr); 20841da177e4SLinus Torvalds } 20851da177e4SLinus Torvalds 20861da177e4SLinus Torvalds /* 20871da177e4SLinus Torvalds * Encode LINK request 20881da177e4SLinus Torvalds */ 20899f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 20909f06c719SChuck Lever const struct nfs4_link_arg *args) 20911da177e4SLinus Torvalds { 20921da177e4SLinus Torvalds struct compound_hdr hdr = { 209366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20941da177e4SLinus Torvalds }; 20951da177e4SLinus Torvalds 20969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20999f06c719SChuck Lever encode_savefh(xdr, &hdr); 21009f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21019f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 21029f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21039f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21049f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2105d017931cSAndy Adamson encode_nops(&hdr); 21061da177e4SLinus Torvalds } 21071da177e4SLinus Torvalds 21081da177e4SLinus Torvalds /* 21091da177e4SLinus Torvalds * Encode CREATE request 21101da177e4SLinus Torvalds */ 21119f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 21129f06c719SChuck Lever const struct nfs4_create_arg *args) 21131da177e4SLinus Torvalds { 21141da177e4SLinus Torvalds struct compound_hdr hdr = { 211566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21161da177e4SLinus Torvalds }; 21171da177e4SLinus Torvalds 21189f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21199f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21209f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21219f06c719SChuck Lever encode_savefh(xdr, &hdr); 21229f06c719SChuck Lever encode_create(xdr, args, &hdr); 21239f06c719SChuck Lever encode_getfh(xdr, &hdr); 21249f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21259f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21269f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2127d017931cSAndy Adamson encode_nops(&hdr); 21281da177e4SLinus Torvalds } 21291da177e4SLinus Torvalds 21301da177e4SLinus Torvalds /* 21311da177e4SLinus Torvalds * Encode SYMLINK request 21321da177e4SLinus Torvalds */ 21339f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 21349f06c719SChuck Lever const struct nfs4_create_arg *args) 21351da177e4SLinus Torvalds { 21369f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 21371da177e4SLinus Torvalds } 21381da177e4SLinus Torvalds 21391da177e4SLinus Torvalds /* 21401da177e4SLinus Torvalds * Encode GETATTR request 21411da177e4SLinus Torvalds */ 21429f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 21439f06c719SChuck Lever const struct nfs4_getattr_arg *args) 21441da177e4SLinus Torvalds { 21451da177e4SLinus Torvalds struct compound_hdr hdr = { 214666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21471da177e4SLinus Torvalds }; 21481da177e4SLinus Torvalds 21499f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21509f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21519f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21529f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2153d017931cSAndy Adamson encode_nops(&hdr); 21541da177e4SLinus Torvalds } 21551da177e4SLinus Torvalds 21561da177e4SLinus Torvalds /* 21571da177e4SLinus Torvalds * Encode a CLOSE request 21581da177e4SLinus Torvalds */ 21599f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 21609f06c719SChuck Lever struct nfs_closeargs *args) 21611da177e4SLinus Torvalds { 21621da177e4SLinus Torvalds struct compound_hdr hdr = { 216366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21641da177e4SLinus Torvalds }; 21651da177e4SLinus Torvalds 21669f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21679f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21689f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21699f06c719SChuck Lever encode_close(xdr, args, &hdr); 21709f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2171d017931cSAndy Adamson encode_nops(&hdr); 21721da177e4SLinus Torvalds } 21731da177e4SLinus Torvalds 21741da177e4SLinus Torvalds /* 21751da177e4SLinus Torvalds * Encode an OPEN request 21761da177e4SLinus Torvalds */ 21779f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 21789f06c719SChuck Lever struct nfs_openargs *args) 21791da177e4SLinus Torvalds { 21801da177e4SLinus Torvalds struct compound_hdr hdr = { 218166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21821da177e4SLinus Torvalds }; 21831da177e4SLinus Torvalds 21849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21859f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21869f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21879f06c719SChuck Lever encode_savefh(xdr, &hdr); 21889f06c719SChuck Lever encode_open(xdr, args, &hdr); 21899f06c719SChuck Lever encode_getfh(xdr, &hdr); 21909f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21919f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21926926afd1STrond Myklebust encode_getfattr(xdr, args->dir_bitmask, &hdr); 2193d017931cSAndy Adamson encode_nops(&hdr); 21941da177e4SLinus Torvalds } 21951da177e4SLinus Torvalds 21961da177e4SLinus Torvalds /* 21971da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 21981da177e4SLinus Torvalds */ 21999f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22009f06c719SChuck Lever struct xdr_stream *xdr, 22019f06c719SChuck Lever struct nfs_open_confirmargs *args) 22021da177e4SLinus Torvalds { 22031da177e4SLinus Torvalds struct compound_hdr hdr = { 2204d017931cSAndy Adamson .nops = 0, 22051da177e4SLinus Torvalds }; 22061da177e4SLinus Torvalds 22079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22089f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22099f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2210d017931cSAndy Adamson encode_nops(&hdr); 22111da177e4SLinus Torvalds } 22121da177e4SLinus Torvalds 22131da177e4SLinus Torvalds /* 22141da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 22151da177e4SLinus Torvalds */ 22169f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 22179f06c719SChuck Lever struct xdr_stream *xdr, 22189f06c719SChuck Lever struct nfs_openargs *args) 22191da177e4SLinus Torvalds { 22201da177e4SLinus Torvalds struct compound_hdr hdr = { 222166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22221da177e4SLinus Torvalds }; 22231da177e4SLinus Torvalds 22249f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22259f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22269f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22279f06c719SChuck Lever encode_open(xdr, args, &hdr); 22289f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2229d017931cSAndy Adamson encode_nops(&hdr); 22301da177e4SLinus Torvalds } 22311da177e4SLinus Torvalds 22321da177e4SLinus Torvalds /* 22331da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 22341da177e4SLinus Torvalds */ 22359f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 22369f06c719SChuck Lever struct xdr_stream *xdr, 22379f06c719SChuck Lever struct nfs_closeargs *args) 22381da177e4SLinus Torvalds { 22391da177e4SLinus Torvalds struct compound_hdr hdr = { 224066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22411da177e4SLinus Torvalds }; 22421da177e4SLinus Torvalds 22439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22459f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22469f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 22479f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2248d017931cSAndy Adamson encode_nops(&hdr); 22491da177e4SLinus Torvalds } 22501da177e4SLinus Torvalds 22511da177e4SLinus Torvalds /* 22521da177e4SLinus Torvalds * Encode a LOCK request 22531da177e4SLinus Torvalds */ 22549f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 22559f06c719SChuck Lever struct nfs_lock_args *args) 22561da177e4SLinus Torvalds { 22571da177e4SLinus Torvalds struct compound_hdr hdr = { 225866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22591da177e4SLinus Torvalds }; 22601da177e4SLinus Torvalds 22619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22649f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2265d017931cSAndy Adamson encode_nops(&hdr); 22661da177e4SLinus Torvalds } 22671da177e4SLinus Torvalds 22681da177e4SLinus Torvalds /* 22691da177e4SLinus Torvalds * Encode a LOCKT request 22701da177e4SLinus Torvalds */ 22719f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 22729f06c719SChuck Lever struct nfs_lockt_args *args) 22731da177e4SLinus Torvalds { 22741da177e4SLinus Torvalds struct compound_hdr hdr = { 227566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22761da177e4SLinus Torvalds }; 22771da177e4SLinus Torvalds 22789f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22799f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22809f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22819f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2282d017931cSAndy Adamson encode_nops(&hdr); 22831da177e4SLinus Torvalds } 22841da177e4SLinus Torvalds 22851da177e4SLinus Torvalds /* 22861da177e4SLinus Torvalds * Encode a LOCKU request 22871da177e4SLinus Torvalds */ 22889f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 22899f06c719SChuck Lever struct nfs_locku_args *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_locku(xdr, args, &hdr); 2299d017931cSAndy Adamson encode_nops(&hdr); 23001da177e4SLinus Torvalds } 23011da177e4SLinus Torvalds 23029f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 23039f06c719SChuck Lever struct xdr_stream *xdr, 23049f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2305d3c7b7ccSTrond Myklebust { 2306d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2307d3c7b7ccSTrond Myklebust .minorversion = 0, 2308d3c7b7ccSTrond Myklebust }; 2309d3c7b7ccSTrond Myklebust 23109f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23119f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2312d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2313d3c7b7ccSTrond Myklebust } 2314d3c7b7ccSTrond Myklebust 23151da177e4SLinus Torvalds /* 23161da177e4SLinus Torvalds * Encode a READLINK request 23171da177e4SLinus Torvalds */ 23189f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 23199f06c719SChuck Lever const struct nfs4_readlink *args) 23201da177e4SLinus Torvalds { 23211da177e4SLinus Torvalds struct compound_hdr hdr = { 232266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23231da177e4SLinus Torvalds }; 23241da177e4SLinus Torvalds 23259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23279f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23289f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2329e3a535e1STrond Myklebust 233028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2331e3a535e1STrond Myklebust args->pgbase, args->pglen); 2332d017931cSAndy Adamson encode_nops(&hdr); 23331da177e4SLinus Torvalds } 23341da177e4SLinus Torvalds 23351da177e4SLinus Torvalds /* 23361da177e4SLinus Torvalds * Encode a READDIR request 23371da177e4SLinus Torvalds */ 23389f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 23399f06c719SChuck Lever const struct nfs4_readdir_arg *args) 23401da177e4SLinus Torvalds { 23411da177e4SLinus Torvalds struct compound_hdr hdr = { 234266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23431da177e4SLinus Torvalds }; 23441da177e4SLinus Torvalds 23459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23479f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23489f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2349d6ac02dfSTrond Myklebust 235028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2351d6ac02dfSTrond Myklebust args->pgbase, args->count); 2352d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 235328f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2354d6ac02dfSTrond Myklebust args->pgbase, args->count); 2355d017931cSAndy Adamson encode_nops(&hdr); 23561da177e4SLinus Torvalds } 23571da177e4SLinus Torvalds 23581da177e4SLinus Torvalds /* 23591da177e4SLinus Torvalds * Encode a READ request 23601da177e4SLinus Torvalds */ 23619f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 23629f06c719SChuck Lever struct nfs_readargs *args) 23631da177e4SLinus Torvalds { 23641da177e4SLinus Torvalds struct compound_hdr hdr = { 236566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23661da177e4SLinus Torvalds }; 23671da177e4SLinus Torvalds 23689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23709f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23719f06c719SChuck Lever encode_read(xdr, args, &hdr); 23721da177e4SLinus Torvalds 237328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 23741da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 23754f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2376d017931cSAndy Adamson encode_nops(&hdr); 23771da177e4SLinus Torvalds } 23781da177e4SLinus Torvalds 23791da177e4SLinus Torvalds /* 23801da177e4SLinus Torvalds * Encode an SETATTR request 23811da177e4SLinus Torvalds */ 23829f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 23839f06c719SChuck Lever struct nfs_setattrargs *args) 23841da177e4SLinus Torvalds { 23851da177e4SLinus Torvalds struct compound_hdr hdr = { 238666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23871da177e4SLinus Torvalds }; 23881da177e4SLinus Torvalds 23899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23919f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23929f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 23939f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2394d017931cSAndy Adamson encode_nops(&hdr); 23951da177e4SLinus Torvalds } 23961da177e4SLinus Torvalds 23971da177e4SLinus Torvalds /* 2398029d105eSJ. Bruce Fields * Encode a GETACL request 2399029d105eSJ. Bruce Fields */ 24009f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2401029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2402029d105eSJ. Bruce Fields { 2403029d105eSJ. Bruce Fields struct compound_hdr hdr = { 240466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2405029d105eSJ. Bruce Fields }; 240628f56694SBenny Halevy uint32_t replen; 2407029d105eSJ. Bruce Fields 24089f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24099f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24109f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2411bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 24129f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2413cf8cdbe5SAndy Adamson 241428f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2415029d105eSJ. Bruce Fields args->acl_pages, args->acl_pgbase, args->acl_len); 2416bf118a34SAndy Adamson 2417d017931cSAndy Adamson encode_nops(&hdr); 2418029d105eSJ. Bruce Fields } 2419029d105eSJ. Bruce Fields 2420029d105eSJ. Bruce Fields /* 24211da177e4SLinus Torvalds * Encode a WRITE request 24221da177e4SLinus Torvalds */ 24239f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 24249f06c719SChuck Lever struct nfs_writeargs *args) 24251da177e4SLinus Torvalds { 24261da177e4SLinus Torvalds struct compound_hdr hdr = { 242766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24281da177e4SLinus Torvalds }; 24291da177e4SLinus Torvalds 24309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24329f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24339f06c719SChuck Lever encode_write(xdr, args, &hdr); 24344f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 24357ffd1064SFred Isaman if (args->bitmask) 24369f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2437d017931cSAndy Adamson encode_nops(&hdr); 24381da177e4SLinus Torvalds } 24391da177e4SLinus Torvalds 24401da177e4SLinus Torvalds /* 24411da177e4SLinus Torvalds * a COMMIT request 24421da177e4SLinus Torvalds */ 24439f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 24449f06c719SChuck Lever struct nfs_writeargs *args) 24451da177e4SLinus Torvalds { 24461da177e4SLinus Torvalds struct compound_hdr hdr = { 244766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24481da177e4SLinus Torvalds }; 24491da177e4SLinus Torvalds 24509f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24519f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24529f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24539f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2454988b6dceSFred Isaman if (args->bitmask) 24559f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2456d017931cSAndy Adamson encode_nops(&hdr); 24571da177e4SLinus Torvalds } 24581da177e4SLinus Torvalds 24591da177e4SLinus Torvalds /* 24601da177e4SLinus Torvalds * FSINFO request 24611da177e4SLinus Torvalds */ 24629f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 24639f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 24641da177e4SLinus Torvalds { 24651da177e4SLinus Torvalds struct compound_hdr hdr = { 246666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24671da177e4SLinus Torvalds }; 24681da177e4SLinus Torvalds 24699f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24709f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24719f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24729f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2473d017931cSAndy Adamson encode_nops(&hdr); 24741da177e4SLinus Torvalds } 24751da177e4SLinus Torvalds 24761da177e4SLinus Torvalds /* 24771da177e4SLinus Torvalds * a PATHCONF request 24781da177e4SLinus Torvalds */ 24799f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 24809f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 24811da177e4SLinus Torvalds { 24821da177e4SLinus Torvalds struct compound_hdr hdr = { 248366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24841da177e4SLinus Torvalds }; 24851da177e4SLinus Torvalds 24869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24889f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24899f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2490d017931cSAndy Adamson &hdr); 2491d017931cSAndy Adamson encode_nops(&hdr); 24921da177e4SLinus Torvalds } 24931da177e4SLinus Torvalds 24941da177e4SLinus Torvalds /* 24951da177e4SLinus Torvalds * a STATFS request 24961da177e4SLinus Torvalds */ 24979f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 24989f06c719SChuck Lever const struct nfs4_statfs_arg *args) 24991da177e4SLinus Torvalds { 25001da177e4SLinus Torvalds struct compound_hdr hdr = { 250166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25021da177e4SLinus Torvalds }; 25031da177e4SLinus Torvalds 25049f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25059f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25069f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25079f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2508d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2509d017931cSAndy Adamson encode_nops(&hdr); 25101da177e4SLinus Torvalds } 25111da177e4SLinus Torvalds 25121da177e4SLinus Torvalds /* 25131da177e4SLinus Torvalds * GETATTR_BITMAP request 25141da177e4SLinus Torvalds */ 25159f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 25169f06c719SChuck Lever struct xdr_stream *xdr, 251743652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 25181da177e4SLinus Torvalds { 25191da177e4SLinus Torvalds struct compound_hdr hdr = { 252066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25211da177e4SLinus Torvalds }; 25221da177e4SLinus Torvalds 25239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25249f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25259f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 25269f06c719SChuck Lever encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2527264e6351SChuck Lever FATTR4_WORD0_FH_EXPIRE_TYPE| 25281da177e4SLinus Torvalds FATTR4_WORD0_LINK_SUPPORT| 25291da177e4SLinus Torvalds FATTR4_WORD0_SYMLINK_SUPPORT| 2530d017931cSAndy Adamson FATTR4_WORD0_ACLSUPPORT, &hdr); 2531d017931cSAndy Adamson encode_nops(&hdr); 25321da177e4SLinus Torvalds } 25331da177e4SLinus Torvalds 25341da177e4SLinus Torvalds /* 25351da177e4SLinus Torvalds * a RENEW request 25361da177e4SLinus Torvalds */ 25379f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 25389f06c719SChuck Lever struct nfs_client *clp) 25391da177e4SLinus Torvalds { 25401da177e4SLinus Torvalds struct compound_hdr hdr = { 2541d017931cSAndy Adamson .nops = 0, 25421da177e4SLinus Torvalds }; 25431da177e4SLinus Torvalds 25449f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2545bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2546d017931cSAndy Adamson encode_nops(&hdr); 25471da177e4SLinus Torvalds } 25481da177e4SLinus Torvalds 25491da177e4SLinus Torvalds /* 25501da177e4SLinus Torvalds * a SETCLIENTID request 25511da177e4SLinus Torvalds */ 25529f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 25539f06c719SChuck Lever struct xdr_stream *xdr, 25549f06c719SChuck Lever struct nfs4_setclientid *sc) 25551da177e4SLinus Torvalds { 25561da177e4SLinus Torvalds struct compound_hdr hdr = { 2557d017931cSAndy Adamson .nops = 0, 25581da177e4SLinus Torvalds }; 25591da177e4SLinus Torvalds 25609f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25619f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2562d017931cSAndy Adamson encode_nops(&hdr); 25631da177e4SLinus Torvalds } 25641da177e4SLinus Torvalds 25651da177e4SLinus Torvalds /* 25661da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 25671da177e4SLinus Torvalds */ 25689f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 25699f06c719SChuck Lever struct xdr_stream *xdr, 25709f06c719SChuck Lever struct nfs4_setclientid_res *arg) 25711da177e4SLinus Torvalds { 25721da177e4SLinus Torvalds struct compound_hdr hdr = { 2573d017931cSAndy Adamson .nops = 0, 25741da177e4SLinus Torvalds }; 2575dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 25761da177e4SLinus Torvalds 25779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25789f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 25799f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 25809f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 2581d017931cSAndy Adamson encode_nops(&hdr); 25821da177e4SLinus Torvalds } 25831da177e4SLinus Torvalds 25841da177e4SLinus Torvalds /* 25851da177e4SLinus Torvalds * DELEGRETURN request 25861da177e4SLinus Torvalds */ 25879f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 25889f06c719SChuck Lever struct xdr_stream *xdr, 25899f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 25901da177e4SLinus Torvalds { 25911da177e4SLinus Torvalds struct compound_hdr hdr = { 259266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25931da177e4SLinus Torvalds }; 25941da177e4SLinus Torvalds 25959f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25969f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25979f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 25989f06c719SChuck Lever encode_delegreturn(xdr, args->stateid, &hdr); 25999f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2600d017931cSAndy Adamson encode_nops(&hdr); 26011da177e4SLinus Torvalds } 26021da177e4SLinus Torvalds 26031da177e4SLinus Torvalds /* 2604683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2605683b57b4STrond Myklebust */ 26069f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 26079f06c719SChuck Lever struct xdr_stream *xdr, 26089f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2609683b57b4STrond Myklebust { 2610683b57b4STrond Myklebust struct compound_hdr hdr = { 261166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2612683b57b4STrond Myklebust }; 261328f56694SBenny Halevy uint32_t replen; 2614683b57b4STrond Myklebust 26159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26169f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26179f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 26189f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 261928f56694SBenny Halevy replen = hdr.replen; /* get the attribute into args->page */ 26209f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2621cf8cdbe5SAndy Adamson 262228f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2623683b57b4STrond Myklebust 0, PAGE_SIZE); 2624d017931cSAndy Adamson encode_nops(&hdr); 2625683b57b4STrond Myklebust } 2626683b57b4STrond Myklebust 26275a5ea0d4SBryan Schumaker /* 26285a5ea0d4SBryan Schumaker * Encode SECINFO request 26295a5ea0d4SBryan Schumaker */ 26305a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 26315a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 26325a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 26335a5ea0d4SBryan Schumaker { 26345a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 26355a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26365a5ea0d4SBryan Schumaker }; 26375a5ea0d4SBryan Schumaker 26385a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 26395a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 26405a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 26415a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 26425a5ea0d4SBryan Schumaker encode_nops(&hdr); 26435a5ea0d4SBryan Schumaker } 26445a5ea0d4SBryan Schumaker 264599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 264699fe60d0SBenny Halevy /* 264799fe60d0SBenny Halevy * EXCHANGE_ID request 264899fe60d0SBenny Halevy */ 26499f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 26509f06c719SChuck Lever struct xdr_stream *xdr, 265199fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 265299fe60d0SBenny Halevy { 265399fe60d0SBenny Halevy struct compound_hdr hdr = { 2654a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 265599fe60d0SBenny Halevy }; 265699fe60d0SBenny Halevy 26579f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26589f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 265999fe60d0SBenny Halevy encode_nops(&hdr); 266099fe60d0SBenny Halevy } 26612050f0ccSAndy Adamson 26622050f0ccSAndy Adamson /* 2663fc931582SAndy Adamson * a CREATE_SESSION request 2664fc931582SAndy Adamson */ 26659f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 26669f06c719SChuck Lever struct xdr_stream *xdr, 2667fc931582SAndy Adamson struct nfs41_create_session_args *args) 2668fc931582SAndy Adamson { 2669fc931582SAndy Adamson struct compound_hdr hdr = { 2670a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2671fc931582SAndy Adamson }; 2672fc931582SAndy Adamson 26739f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26749f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2675fc931582SAndy Adamson encode_nops(&hdr); 2676fc931582SAndy Adamson } 2677fc931582SAndy Adamson 2678fc931582SAndy Adamson /* 26790f3e66c6SAndy Adamson * a DESTROY_SESSION request 26800f3e66c6SAndy Adamson */ 26819f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 26829f06c719SChuck Lever struct xdr_stream *xdr, 26830f3e66c6SAndy Adamson struct nfs4_session *session) 26840f3e66c6SAndy Adamson { 26850f3e66c6SAndy Adamson struct compound_hdr hdr = { 2686a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 26870f3e66c6SAndy Adamson }; 26880f3e66c6SAndy Adamson 26899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26909f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 26910f3e66c6SAndy Adamson encode_nops(&hdr); 26920f3e66c6SAndy Adamson } 26930f3e66c6SAndy Adamson 26940f3e66c6SAndy Adamson /* 2695fc01cea9SAndy Adamson * a SEQUENCE request 2696fc01cea9SAndy Adamson */ 26979f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2698fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2699fc01cea9SAndy Adamson { 2700fc01cea9SAndy Adamson struct compound_hdr hdr = { 2701fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2702fc01cea9SAndy Adamson }; 2703fc01cea9SAndy Adamson 27049f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27059f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2706fc01cea9SAndy Adamson encode_nops(&hdr); 2707fc01cea9SAndy Adamson } 2708fc01cea9SAndy Adamson 2709fc01cea9SAndy Adamson /* 27102050f0ccSAndy Adamson * a GET_LEASE_TIME request 27112050f0ccSAndy Adamson */ 27129f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 27139f06c719SChuck Lever struct xdr_stream *xdr, 27142050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 27152050f0ccSAndy Adamson { 27162050f0ccSAndy Adamson struct compound_hdr hdr = { 27172050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 27182050f0ccSAndy Adamson }; 2719dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 27202050f0ccSAndy Adamson 27219f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27229f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 27239f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 27249f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 27252050f0ccSAndy Adamson encode_nops(&hdr); 27262050f0ccSAndy Adamson } 272718019753SRicardo Labiaga 272818019753SRicardo Labiaga /* 272918019753SRicardo Labiaga * a RECLAIM_COMPLETE request 273018019753SRicardo Labiaga */ 27319f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 27329f06c719SChuck Lever struct xdr_stream *xdr, 273318019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 273418019753SRicardo Labiaga { 273518019753SRicardo Labiaga struct compound_hdr hdr = { 273618019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 273718019753SRicardo Labiaga }; 273818019753SRicardo Labiaga 27399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27419f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 274218019753SRicardo Labiaga encode_nops(&hdr); 274318019753SRicardo Labiaga } 274418019753SRicardo Labiaga 2745b1f69b75SAndy Adamson /* 27467f11d8d3SAndy Adamson * Encode GETDEVICELIST request 27477f11d8d3SAndy Adamson */ 27487f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req, 27497f11d8d3SAndy Adamson struct xdr_stream *xdr, 27507f11d8d3SAndy Adamson struct nfs4_getdevicelist_args *args) 27517f11d8d3SAndy Adamson { 27527f11d8d3SAndy Adamson struct compound_hdr hdr = { 27537f11d8d3SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27547f11d8d3SAndy Adamson }; 27557f11d8d3SAndy Adamson 27567f11d8d3SAndy Adamson encode_compound_hdr(xdr, req, &hdr); 27577f11d8d3SAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 27587f11d8d3SAndy Adamson encode_putfh(xdr, args->fh, &hdr); 27597f11d8d3SAndy Adamson encode_getdevicelist(xdr, args, &hdr); 27607f11d8d3SAndy Adamson encode_nops(&hdr); 27617f11d8d3SAndy Adamson } 27627f11d8d3SAndy Adamson 27637f11d8d3SAndy Adamson /* 2764b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2765b1f69b75SAndy Adamson */ 27669f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 27679f06c719SChuck Lever struct xdr_stream *xdr, 2768b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2769b1f69b75SAndy Adamson { 2770b1f69b75SAndy Adamson struct compound_hdr hdr = { 2771b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2772b1f69b75SAndy Adamson }; 2773b1f69b75SAndy Adamson 27749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27769f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2777b1f69b75SAndy Adamson 2778b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2779b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2780b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2781b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2782b1f69b75SAndy Adamson args->pdev->pglen); 2783b1f69b75SAndy Adamson 2784b1f69b75SAndy Adamson encode_nops(&hdr); 2785b1f69b75SAndy Adamson } 2786b1f69b75SAndy Adamson 2787b1f69b75SAndy Adamson /* 2788b1f69b75SAndy Adamson * Encode LAYOUTGET request 2789b1f69b75SAndy Adamson */ 27909f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 27919f06c719SChuck Lever struct xdr_stream *xdr, 2792b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2793b1f69b75SAndy Adamson { 2794b1f69b75SAndy Adamson struct compound_hdr hdr = { 2795b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2796b1f69b75SAndy Adamson }; 2797b1f69b75SAndy Adamson 27989f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27999f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28009f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 28019f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 280235124a09SWeston Andros Adamson 280335124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 280435124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 280535124a09SWeston Andros Adamson 2806b1f69b75SAndy Adamson encode_nops(&hdr); 2807b1f69b75SAndy Adamson } 2808863a3c6cSAndy Adamson 2809863a3c6cSAndy Adamson /* 2810863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2811863a3c6cSAndy Adamson */ 2812cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2813863a3c6cSAndy Adamson struct xdr_stream *xdr, 2814863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2815863a3c6cSAndy Adamson { 2816ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2817ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2818863a3c6cSAndy Adamson struct compound_hdr hdr = { 2819863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2820863a3c6cSAndy Adamson }; 2821863a3c6cSAndy Adamson 2822863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2823863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2824863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2825ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2826863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2827863a3c6cSAndy Adamson encode_nops(&hdr); 2828cbe82603SBenny Halevy } 2829cbe82603SBenny Halevy 2830cbe82603SBenny Halevy /* 2831cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2832cbe82603SBenny Halevy */ 2833cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2834cbe82603SBenny Halevy struct xdr_stream *xdr, 2835cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2836cbe82603SBenny Halevy { 2837cbe82603SBenny Halevy struct compound_hdr hdr = { 2838cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2839cbe82603SBenny Halevy }; 2840cbe82603SBenny Halevy 2841cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2842cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2843cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2844cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2845cbe82603SBenny Halevy encode_nops(&hdr); 2846863a3c6cSAndy Adamson } 2847fca78d6dSBryan Schumaker 2848fca78d6dSBryan Schumaker /* 2849fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2850fca78d6dSBryan Schumaker */ 2851fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2852fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2853fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2854fca78d6dSBryan Schumaker { 2855fca78d6dSBryan Schumaker struct compound_hdr hdr = { 2856fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2857fca78d6dSBryan Schumaker }; 2858fca78d6dSBryan Schumaker 2859fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 2860fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 2861fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 2862fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 2863fca78d6dSBryan Schumaker encode_nops(&hdr); 2864fca78d6dSBryan Schumaker return 0; 2865fca78d6dSBryan Schumaker } 28667d974794SBryan Schumaker 28677d974794SBryan Schumaker /* 28687d974794SBryan Schumaker * Encode TEST_STATEID request 28697d974794SBryan Schumaker */ 28707d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 28717d974794SBryan Schumaker struct xdr_stream *xdr, 28727d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 28737d974794SBryan Schumaker { 28747d974794SBryan Schumaker struct compound_hdr hdr = { 28757d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28767d974794SBryan Schumaker }; 28777d974794SBryan Schumaker 28787d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 28797d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 28807d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 28817d974794SBryan Schumaker encode_nops(&hdr); 28827d974794SBryan Schumaker } 28839aeda35fSBryan Schumaker 28849aeda35fSBryan Schumaker /* 28859aeda35fSBryan Schumaker * Encode FREE_STATEID request 28869aeda35fSBryan Schumaker */ 28879aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 28889aeda35fSBryan Schumaker struct xdr_stream *xdr, 28899aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 28909aeda35fSBryan Schumaker { 28919aeda35fSBryan Schumaker struct compound_hdr hdr = { 28929aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28939aeda35fSBryan Schumaker }; 28949aeda35fSBryan Schumaker 28959aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 28969aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 28979aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 28989aeda35fSBryan Schumaker encode_nops(&hdr); 28999aeda35fSBryan Schumaker } 290099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 290199fe60d0SBenny Halevy 2902686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 2903686841b3SBenny Halevy { 2904686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 2905686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 2906686841b3SBenny Halevy func, xdr->end - xdr->p); 2907686841b3SBenny Halevy } 29081da177e4SLinus Torvalds 2909683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 29101da177e4SLinus Torvalds { 29118687b63aSAl Viro __be32 *p; 29121da177e4SLinus Torvalds 2913c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 2914c0eae66eSBenny Halevy if (unlikely(!p)) 2915c0eae66eSBenny Halevy goto out_overflow; 2916cccddf4fSBenny Halevy *len = be32_to_cpup(p); 2917c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 2918c0eae66eSBenny Halevy if (unlikely(!p)) 2919c0eae66eSBenny Halevy goto out_overflow; 29201da177e4SLinus Torvalds *string = (char *)p; 29211da177e4SLinus Torvalds return 0; 2922c0eae66eSBenny Halevy out_overflow: 2923c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2924c0eae66eSBenny Halevy return -EIO; 29251da177e4SLinus Torvalds } 29261da177e4SLinus Torvalds 29271da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 29281da177e4SLinus Torvalds { 29298687b63aSAl Viro __be32 *p; 29301da177e4SLinus Torvalds 2931c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 2932c0eae66eSBenny Halevy if (unlikely(!p)) 2933c0eae66eSBenny Halevy goto out_overflow; 29346f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 2935cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 29361da177e4SLinus Torvalds 2937c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 2938c0eae66eSBenny Halevy if (unlikely(!p)) 2939c0eae66eSBenny Halevy goto out_overflow; 29401da177e4SLinus Torvalds hdr->tag = (char *)p; 29411da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 2942cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 2943aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 2944aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 29451da177e4SLinus Torvalds return 0; 2946c0eae66eSBenny Halevy out_overflow: 2947c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2948c0eae66eSBenny Halevy return -EIO; 29491da177e4SLinus Torvalds } 29501da177e4SLinus Torvalds 29511da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 29521da177e4SLinus Torvalds { 29538687b63aSAl Viro __be32 *p; 29541da177e4SLinus Torvalds uint32_t opnum; 29551da177e4SLinus Torvalds int32_t nfserr; 29561da177e4SLinus Torvalds 2957c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 2958c0eae66eSBenny Halevy if (unlikely(!p)) 2959c0eae66eSBenny Halevy goto out_overflow; 29606f723f77SBenny Halevy opnum = be32_to_cpup(p++); 29611da177e4SLinus Torvalds if (opnum != expected) { 2962fe82a183SChuck Lever dprintk("nfs: Server returned operation" 29631da177e4SLinus Torvalds " %d but we issued a request for %d\n", 29641da177e4SLinus Torvalds opnum, expected); 29651da177e4SLinus Torvalds return -EIO; 29661da177e4SLinus Torvalds } 2967cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 29681da177e4SLinus Torvalds if (nfserr != NFS_OK) 2969856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 29701da177e4SLinus Torvalds return 0; 2971c0eae66eSBenny Halevy out_overflow: 2972c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2973c0eae66eSBenny Halevy return -EIO; 29741da177e4SLinus Torvalds } 29751da177e4SLinus Torvalds 29761da177e4SLinus Torvalds /* Dummy routine */ 2977adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 29781da177e4SLinus Torvalds { 29798687b63aSAl Viro __be32 *p; 2980683b57b4STrond Myklebust unsigned int strlen; 29811da177e4SLinus Torvalds char *str; 29821da177e4SLinus Torvalds 2983c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 2984c0eae66eSBenny Halevy if (likely(p)) 29851da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 2986c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2987c0eae66eSBenny Halevy return -EIO; 29881da177e4SLinus Torvalds } 29891da177e4SLinus Torvalds 29901da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 29911da177e4SLinus Torvalds { 29928687b63aSAl Viro uint32_t bmlen; 29938687b63aSAl Viro __be32 *p; 29941da177e4SLinus Torvalds 2995c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 2996c0eae66eSBenny Halevy if (unlikely(!p)) 2997c0eae66eSBenny Halevy goto out_overflow; 2998cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 29991da177e4SLinus Torvalds 3000dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3001c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3002c0eae66eSBenny Halevy if (unlikely(!p)) 3003c0eae66eSBenny Halevy goto out_overflow; 30041da177e4SLinus Torvalds if (bmlen > 0) { 30056f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3006dae100c2SFred Isaman if (bmlen > 1) { 3007dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3008dae100c2SFred Isaman if (bmlen > 2) 3009dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3010dae100c2SFred Isaman } 30111da177e4SLinus Torvalds } 30121da177e4SLinus Torvalds return 0; 3013c0eae66eSBenny Halevy out_overflow: 3014c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3015c0eae66eSBenny Halevy return -EIO; 30161da177e4SLinus Torvalds } 30171da177e4SLinus Torvalds 30188687b63aSAl Viro static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) 30191da177e4SLinus Torvalds { 30208687b63aSAl Viro __be32 *p; 30211da177e4SLinus Torvalds 3022c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3023c0eae66eSBenny Halevy if (unlikely(!p)) 3024c0eae66eSBenny Halevy goto out_overflow; 3025cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 30261da177e4SLinus Torvalds *savep = xdr->p; 30271da177e4SLinus Torvalds return 0; 3028c0eae66eSBenny Halevy out_overflow: 3029c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3030c0eae66eSBenny Halevy return -EIO; 30311da177e4SLinus Torvalds } 30321da177e4SLinus Torvalds 30331da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 30341da177e4SLinus Torvalds { 30351da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 30363388bff5SRoman Borisov int ret; 30373388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 30383388bff5SRoman Borisov if (unlikely(ret < 0)) 30393388bff5SRoman Borisov return ret; 30401da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 30411da177e4SLinus Torvalds } else 3042dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3043dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3044dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 30451da177e4SLinus Torvalds return 0; 30461da177e4SLinus Torvalds } 30471da177e4SLinus Torvalds 30481da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 30491da177e4SLinus Torvalds { 30508687b63aSAl Viro __be32 *p; 3051409924e4STrond Myklebust int ret = 0; 30521da177e4SLinus Torvalds 30531da177e4SLinus Torvalds *type = 0; 30541da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 30551da177e4SLinus Torvalds return -EIO; 30561da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3057c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3058c0eae66eSBenny Halevy if (unlikely(!p)) 3059c0eae66eSBenny Halevy goto out_overflow; 3060cccddf4fSBenny Halevy *type = be32_to_cpup(p); 30611da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 30623110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 30631da177e4SLinus Torvalds return -EIO; 30641da177e4SLinus Torvalds } 30651da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3066409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 30671da177e4SLinus Torvalds } 3068bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3069409924e4STrond Myklebust return ret; 3070c0eae66eSBenny Halevy out_overflow: 3071c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3072c0eae66eSBenny Halevy return -EIO; 30731da177e4SLinus Torvalds } 30741da177e4SLinus Torvalds 3075264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3076264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3077264e6351SChuck Lever { 3078264e6351SChuck Lever __be32 *p; 3079264e6351SChuck Lever 3080264e6351SChuck Lever *type = 0; 3081264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3082264e6351SChuck Lever return -EIO; 3083264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3084264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3085264e6351SChuck Lever if (unlikely(!p)) 3086264e6351SChuck Lever goto out_overflow; 3087264e6351SChuck Lever *type = be32_to_cpup(p); 3088264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3089264e6351SChuck Lever } 3090264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3091264e6351SChuck Lever return 0; 3092264e6351SChuck Lever out_overflow: 3093264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3094264e6351SChuck Lever return -EIO; 3095264e6351SChuck Lever } 3096264e6351SChuck Lever 30971da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 30981da177e4SLinus Torvalds { 30998687b63aSAl Viro __be32 *p; 3100409924e4STrond Myklebust int ret = 0; 31011da177e4SLinus Torvalds 31021da177e4SLinus Torvalds *change = 0; 31031da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 31041da177e4SLinus Torvalds return -EIO; 31051da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3106c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3107c0eae66eSBenny Halevy if (unlikely(!p)) 3108c0eae66eSBenny Halevy goto out_overflow; 3109cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 31101da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3111409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 31121da177e4SLinus Torvalds } 31133110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 31141da177e4SLinus Torvalds (unsigned long long)*change); 3115409924e4STrond Myklebust return ret; 3116c0eae66eSBenny Halevy out_overflow: 3117c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3118c0eae66eSBenny Halevy return -EIO; 31191da177e4SLinus Torvalds } 31201da177e4SLinus Torvalds 31211da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 31221da177e4SLinus Torvalds { 31238687b63aSAl Viro __be32 *p; 3124409924e4STrond Myklebust int ret = 0; 31251da177e4SLinus Torvalds 31261da177e4SLinus Torvalds *size = 0; 31271da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 31281da177e4SLinus Torvalds return -EIO; 31291da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3130c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3131c0eae66eSBenny Halevy if (unlikely(!p)) 3132c0eae66eSBenny Halevy goto out_overflow; 3133cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 31341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3135409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 31361da177e4SLinus Torvalds } 31373110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3138409924e4STrond Myklebust return ret; 3139c0eae66eSBenny Halevy out_overflow: 3140c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3141c0eae66eSBenny Halevy return -EIO; 31421da177e4SLinus Torvalds } 31431da177e4SLinus Torvalds 31441da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 31451da177e4SLinus Torvalds { 31468687b63aSAl Viro __be32 *p; 31471da177e4SLinus Torvalds 31481da177e4SLinus Torvalds *res = 0; 31491da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 31501da177e4SLinus Torvalds return -EIO; 31511da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3152c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3153c0eae66eSBenny Halevy if (unlikely(!p)) 3154c0eae66eSBenny Halevy goto out_overflow; 3155cccddf4fSBenny Halevy *res = be32_to_cpup(p); 31561da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 31571da177e4SLinus Torvalds } 31583110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 31591da177e4SLinus Torvalds return 0; 3160c0eae66eSBenny Halevy out_overflow: 3161c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3162c0eae66eSBenny Halevy return -EIO; 31631da177e4SLinus Torvalds } 31641da177e4SLinus Torvalds 31651da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 31661da177e4SLinus Torvalds { 31678687b63aSAl Viro __be32 *p; 31681da177e4SLinus Torvalds 31691da177e4SLinus Torvalds *res = 0; 31701da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 31711da177e4SLinus Torvalds return -EIO; 31721da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3173c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3174c0eae66eSBenny Halevy if (unlikely(!p)) 3175c0eae66eSBenny Halevy goto out_overflow; 3176cccddf4fSBenny Halevy *res = be32_to_cpup(p); 31771da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 31781da177e4SLinus Torvalds } 31793110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 31801da177e4SLinus Torvalds return 0; 3181c0eae66eSBenny Halevy out_overflow: 3182c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3183c0eae66eSBenny Halevy return -EIO; 31841da177e4SLinus Torvalds } 31851da177e4SLinus Torvalds 31868b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 31871da177e4SLinus Torvalds { 31888687b63aSAl Viro __be32 *p; 3189409924e4STrond Myklebust int ret = 0; 31901da177e4SLinus Torvalds 31911da177e4SLinus Torvalds fsid->major = 0; 31921da177e4SLinus Torvalds fsid->minor = 0; 31931da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 31941da177e4SLinus Torvalds return -EIO; 31951da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3196c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3197c0eae66eSBenny Halevy if (unlikely(!p)) 3198c0eae66eSBenny Halevy goto out_overflow; 31993ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3200cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 32011da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3202409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 32031da177e4SLinus Torvalds } 32043110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 32051da177e4SLinus Torvalds (unsigned long long)fsid->major, 32061da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3207409924e4STrond Myklebust return ret; 3208c0eae66eSBenny Halevy out_overflow: 3209c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3210c0eae66eSBenny Halevy return -EIO; 32111da177e4SLinus Torvalds } 32121da177e4SLinus Torvalds 32131da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32141da177e4SLinus Torvalds { 32158687b63aSAl Viro __be32 *p; 32161da177e4SLinus Torvalds 32171da177e4SLinus Torvalds *res = 60; 32181da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 32191da177e4SLinus Torvalds return -EIO; 32201da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3221c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3222c0eae66eSBenny Halevy if (unlikely(!p)) 3223c0eae66eSBenny Halevy goto out_overflow; 3224cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32251da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 32261da177e4SLinus Torvalds } 32273110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 32281da177e4SLinus Torvalds return 0; 3229c0eae66eSBenny Halevy out_overflow: 3230c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3231c0eae66eSBenny Halevy return -EIO; 32321da177e4SLinus Torvalds } 32331da177e4SLinus Torvalds 3234ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3235ae42c70aSBryan Schumaker { 3236ae42c70aSBryan Schumaker __be32 *p; 3237ae42c70aSBryan Schumaker 3238ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3239ae42c70aSBryan Schumaker return -EIO; 3240ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3241ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3242ae42c70aSBryan Schumaker if (unlikely(!p)) 3243ae42c70aSBryan Schumaker goto out_overflow; 3244ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3245ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3246ae42c70aSBryan Schumaker } 3247ae42c70aSBryan Schumaker return 0; 3248ae42c70aSBryan Schumaker out_overflow: 3249ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3250ae42c70aSBryan Schumaker return -EIO; 3251ae42c70aSBryan Schumaker } 3252ae42c70aSBryan Schumaker 3253ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3254ae42c70aSBryan Schumaker { 3255ae42c70aSBryan Schumaker __be32 *p; 3256ae42c70aSBryan Schumaker int len; 3257ae42c70aSBryan Schumaker 32587ad07353STrond Myklebust if (fh != NULL) 3259ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3260ae42c70aSBryan Schumaker 3261ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3262ae42c70aSBryan Schumaker return -EIO; 3263ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3264ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3265ae42c70aSBryan Schumaker if (unlikely(!p)) 3266ae42c70aSBryan Schumaker goto out_overflow; 3267ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3268ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3269ae42c70aSBryan Schumaker return -EIO; 3270ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3271ae42c70aSBryan Schumaker if (unlikely(!p)) 3272ae42c70aSBryan Schumaker goto out_overflow; 32737ad07353STrond Myklebust if (fh != NULL) { 3274ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 32757ad07353STrond Myklebust fh->size = len; 32767ad07353STrond Myklebust } 3277ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3278ae42c70aSBryan Schumaker } 3279ae42c70aSBryan Schumaker return 0; 3280ae42c70aSBryan Schumaker out_overflow: 3281ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3282ae42c70aSBryan Schumaker return -EIO; 3283ae42c70aSBryan Schumaker } 3284ae42c70aSBryan Schumaker 32851da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32861da177e4SLinus Torvalds { 32878687b63aSAl Viro __be32 *p; 32881da177e4SLinus Torvalds 32891da177e4SLinus Torvalds *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 32901da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 32911da177e4SLinus Torvalds return -EIO; 32921da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3293c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3294c0eae66eSBenny Halevy if (unlikely(!p)) 3295c0eae66eSBenny Halevy goto out_overflow; 3296cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32971da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 32981da177e4SLinus Torvalds } 32993110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 33001da177e4SLinus Torvalds return 0; 3301c0eae66eSBenny Halevy out_overflow: 3302c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3303c0eae66eSBenny Halevy return -EIO; 33041da177e4SLinus Torvalds } 33051da177e4SLinus Torvalds 33061da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 33071da177e4SLinus Torvalds { 33088687b63aSAl Viro __be32 *p; 3309409924e4STrond Myklebust int ret = 0; 33101da177e4SLinus Torvalds 33111da177e4SLinus Torvalds *fileid = 0; 33121da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 33131da177e4SLinus Torvalds return -EIO; 33141da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3315c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3316c0eae66eSBenny Halevy if (unlikely(!p)) 3317c0eae66eSBenny Halevy goto out_overflow; 3318cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 33191da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3320409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 33211da177e4SLinus Torvalds } 33223110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3323409924e4STrond Myklebust return ret; 3324c0eae66eSBenny Halevy out_overflow: 3325c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3326c0eae66eSBenny Halevy return -EIO; 33271da177e4SLinus Torvalds } 33281da177e4SLinus Torvalds 332999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 333099baf625SManoj Naik { 33318687b63aSAl Viro __be32 *p; 3332409924e4STrond Myklebust int ret = 0; 333399baf625SManoj Naik 333499baf625SManoj Naik *fileid = 0; 333599baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 333699baf625SManoj Naik return -EIO; 333799baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3338c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3339c0eae66eSBenny Halevy if (unlikely(!p)) 3340c0eae66eSBenny Halevy goto out_overflow; 3341cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 334299baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 334328331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 334499baf625SManoj Naik } 33453110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3346409924e4STrond Myklebust return ret; 3347c0eae66eSBenny Halevy out_overflow: 3348c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3349c0eae66eSBenny Halevy return -EIO; 335099baf625SManoj Naik } 335199baf625SManoj Naik 33521da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 33531da177e4SLinus Torvalds { 33548687b63aSAl Viro __be32 *p; 33551da177e4SLinus Torvalds int status = 0; 33561da177e4SLinus Torvalds 33571da177e4SLinus Torvalds *res = 0; 33581da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 33591da177e4SLinus Torvalds return -EIO; 33601da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3361c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3362c0eae66eSBenny Halevy if (unlikely(!p)) 3363c0eae66eSBenny Halevy goto out_overflow; 3364cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 33651da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 33661da177e4SLinus Torvalds } 33673110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 33681da177e4SLinus Torvalds return status; 3369c0eae66eSBenny Halevy out_overflow: 3370c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3371c0eae66eSBenny Halevy return -EIO; 33721da177e4SLinus Torvalds } 33731da177e4SLinus Torvalds 33741da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 33751da177e4SLinus Torvalds { 33768687b63aSAl Viro __be32 *p; 33771da177e4SLinus Torvalds int status = 0; 33781da177e4SLinus Torvalds 33791da177e4SLinus Torvalds *res = 0; 33801da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 33811da177e4SLinus Torvalds return -EIO; 33821da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3383c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3384c0eae66eSBenny Halevy if (unlikely(!p)) 3385c0eae66eSBenny Halevy goto out_overflow; 3386cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 33871da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 33881da177e4SLinus Torvalds } 33893110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 33901da177e4SLinus Torvalds return status; 3391c0eae66eSBenny Halevy out_overflow: 3392c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3393c0eae66eSBenny Halevy return -EIO; 33941da177e4SLinus Torvalds } 33951da177e4SLinus Torvalds 33961da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 33971da177e4SLinus Torvalds { 33988687b63aSAl Viro __be32 *p; 33991da177e4SLinus Torvalds int status = 0; 34001da177e4SLinus Torvalds 34011da177e4SLinus Torvalds *res = 0; 34021da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 34031da177e4SLinus Torvalds return -EIO; 34041da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3405c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3406c0eae66eSBenny Halevy if (unlikely(!p)) 3407c0eae66eSBenny Halevy goto out_overflow; 3408cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34091da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 34101da177e4SLinus Torvalds } 34113110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 34121da177e4SLinus Torvalds return status; 3413c0eae66eSBenny Halevy out_overflow: 3414c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3415c0eae66eSBenny Halevy return -EIO; 34161da177e4SLinus Torvalds } 34171da177e4SLinus Torvalds 34187aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 34197aaa0b3bSManoj Naik { 3420464ad6b1SChuck Lever u32 n; 34218687b63aSAl Viro __be32 *p; 34227aaa0b3bSManoj Naik int status = 0; 34237aaa0b3bSManoj Naik 3424c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3425c0eae66eSBenny Halevy if (unlikely(!p)) 3426c0eae66eSBenny Halevy goto out_overflow; 3427cccddf4fSBenny Halevy n = be32_to_cpup(p); 342833a43f28SAndy Adamson if (n == 0) 342933a43f28SAndy Adamson goto root_path; 343002a2976cSChuck Lever dprintk("pathname4: "); 34317aaa0b3bSManoj Naik path->ncomponents = 0; 34327aaa0b3bSManoj Naik while (path->ncomponents < n) { 34337aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 34347aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 34357aaa0b3bSManoj Naik if (unlikely(status != 0)) 34367aaa0b3bSManoj Naik goto out_eio; 343702a2976cSChuck Lever if (unlikely(nfs_debug & NFSDBG_XDR)) 343802a2976cSChuck Lever pr_cont("%s%.*s ", 343902a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 344002a2976cSChuck Lever component->len, component->data); 34417aaa0b3bSManoj Naik if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 34427aaa0b3bSManoj Naik path->ncomponents++; 34437aaa0b3bSManoj Naik else { 34447aaa0b3bSManoj Naik dprintk("cannot parse %d components in path\n", n); 34457aaa0b3bSManoj Naik goto out_eio; 34467aaa0b3bSManoj Naik } 34477aaa0b3bSManoj Naik } 34487aaa0b3bSManoj Naik out: 34497aaa0b3bSManoj Naik return status; 345033a43f28SAndy Adamson root_path: 345133a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 345233a43f28SAndy Adamson path->ncomponents = 1; 345333a43f28SAndy Adamson path->components[0].len=0; 345433a43f28SAndy Adamson path->components[0].data=NULL; 345502a2976cSChuck Lever dprintk("pathname4: /\n"); 345633a43f28SAndy Adamson goto out; 34577aaa0b3bSManoj Naik out_eio: 34587aaa0b3bSManoj Naik dprintk(" status %d", status); 34597aaa0b3bSManoj Naik status = -EIO; 34607aaa0b3bSManoj Naik goto out; 3461c0eae66eSBenny Halevy out_overflow: 3462c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3463c0eae66eSBenny Halevy return -EIO; 34647aaa0b3bSManoj Naik } 34657aaa0b3bSManoj Naik 34667aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3467683b57b4STrond Myklebust { 3468683b57b4STrond Myklebust int n; 34698687b63aSAl Viro __be32 *p; 3470683b57b4STrond Myklebust int status = -EIO; 3471683b57b4STrond Myklebust 3472683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3473683b57b4STrond Myklebust goto out; 3474683b57b4STrond Myklebust status = 0; 3475683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3476683b57b4STrond Myklebust goto out; 34778b7e3f49STrond Myklebust status = -EIO; 34788b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 34798b7e3f49STrond Myklebust if (unlikely(res == NULL)) 34808b7e3f49STrond Myklebust goto out; 348102a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 34827aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3483683b57b4STrond Myklebust if (unlikely(status != 0)) 3484683b57b4STrond Myklebust goto out; 3485c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3486c0eae66eSBenny Halevy if (unlikely(!p)) 3487c0eae66eSBenny Halevy goto out_overflow; 3488cccddf4fSBenny Halevy n = be32_to_cpup(p); 3489683b57b4STrond Myklebust if (n <= 0) 3490683b57b4STrond Myklebust goto out_eio; 3491683b57b4STrond Myklebust res->nlocations = 0; 3492683b57b4STrond Myklebust while (res->nlocations < n) { 3493464ad6b1SChuck Lever u32 m; 34947aaa0b3bSManoj Naik struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 3495683b57b4STrond Myklebust 3496c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3497c0eae66eSBenny Halevy if (unlikely(!p)) 3498c0eae66eSBenny Halevy goto out_overflow; 3499cccddf4fSBenny Halevy m = be32_to_cpup(p); 35007aaa0b3bSManoj Naik 35017aaa0b3bSManoj Naik loc->nservers = 0; 350202a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 35037aaa0b3bSManoj Naik while (loc->nservers < m) { 35047aaa0b3bSManoj Naik struct nfs4_string *server = &loc->servers[loc->nservers]; 35057aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &server->len, &server->data); 3506683b57b4STrond Myklebust if (unlikely(status != 0)) 3507683b57b4STrond Myklebust goto out_eio; 35087aaa0b3bSManoj Naik dprintk("%s ", server->data); 35097aaa0b3bSManoj Naik if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) 35107aaa0b3bSManoj Naik loc->nservers++; 35117aaa0b3bSManoj Naik else { 3512464ad6b1SChuck Lever unsigned int i; 3513464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3514464ad6b1SChuck Lever "returned for location %u\n", 35153110ff80SHarvey Harrison __func__, 3516464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3517464ad6b1SChuck Lever m, res->nlocations); 35187aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 35192e42c3e2STrond Myklebust unsigned int len; 35207aaa0b3bSManoj Naik char *data; 35217aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3522683b57b4STrond Myklebust if (unlikely(status != 0)) 3523683b57b4STrond Myklebust goto out_eio; 35247aaa0b3bSManoj Naik } 35257aaa0b3bSManoj Naik } 35267aaa0b3bSManoj Naik } 35277aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 35287aaa0b3bSManoj Naik if (unlikely(status != 0)) 35297aaa0b3bSManoj Naik goto out_eio; 35307aaa0b3bSManoj Naik if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) 3531683b57b4STrond Myklebust res->nlocations++; 3532683b57b4STrond Myklebust } 3533409924e4STrond Myklebust if (res->nlocations != 0) 353481934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3535683b57b4STrond Myklebust out: 35363110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3537683b57b4STrond Myklebust return status; 3538c0eae66eSBenny Halevy out_overflow: 3539c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3540683b57b4STrond Myklebust out_eio: 3541683b57b4STrond Myklebust status = -EIO; 3542683b57b4STrond Myklebust goto out; 3543683b57b4STrond Myklebust } 3544683b57b4STrond Myklebust 35451da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35461da177e4SLinus Torvalds { 35478687b63aSAl Viro __be32 *p; 35481da177e4SLinus Torvalds int status = 0; 35491da177e4SLinus Torvalds 35501da177e4SLinus Torvalds *res = 0; 35511da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 35521da177e4SLinus Torvalds return -EIO; 35531da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3554c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3555c0eae66eSBenny Halevy if (unlikely(!p)) 3556c0eae66eSBenny Halevy goto out_overflow; 3557cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35581da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 35591da177e4SLinus Torvalds } 35603110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 35611da177e4SLinus Torvalds return status; 3562c0eae66eSBenny Halevy out_overflow: 3563c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3564c0eae66eSBenny Halevy return -EIO; 35651da177e4SLinus Torvalds } 35661da177e4SLinus Torvalds 35671da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 35681da177e4SLinus Torvalds { 35698687b63aSAl Viro __be32 *p; 35701da177e4SLinus Torvalds int status = 0; 35711da177e4SLinus Torvalds 35721da177e4SLinus Torvalds *maxlink = 1; 35731da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 35741da177e4SLinus Torvalds return -EIO; 35751da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3576c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3577c0eae66eSBenny Halevy if (unlikely(!p)) 3578c0eae66eSBenny Halevy goto out_overflow; 3579cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 35801da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 35811da177e4SLinus Torvalds } 35823110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 35831da177e4SLinus Torvalds return status; 3584c0eae66eSBenny Halevy out_overflow: 3585c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3586c0eae66eSBenny Halevy return -EIO; 35871da177e4SLinus Torvalds } 35881da177e4SLinus Torvalds 35891da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 35901da177e4SLinus Torvalds { 35918687b63aSAl Viro __be32 *p; 35921da177e4SLinus Torvalds int status = 0; 35931da177e4SLinus Torvalds 35941da177e4SLinus Torvalds *maxname = 1024; 35951da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 35961da177e4SLinus Torvalds return -EIO; 35971da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3598c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3599c0eae66eSBenny Halevy if (unlikely(!p)) 3600c0eae66eSBenny Halevy goto out_overflow; 3601cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 36021da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 36031da177e4SLinus Torvalds } 36043110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 36051da177e4SLinus Torvalds return status; 3606c0eae66eSBenny Halevy out_overflow: 3607c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3608c0eae66eSBenny Halevy return -EIO; 36091da177e4SLinus Torvalds } 36101da177e4SLinus Torvalds 36111da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36121da177e4SLinus Torvalds { 36138687b63aSAl Viro __be32 *p; 36141da177e4SLinus Torvalds int status = 0; 36151da177e4SLinus Torvalds 36161da177e4SLinus Torvalds *res = 1024; 36171da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 36181da177e4SLinus Torvalds return -EIO; 36191da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 36201da177e4SLinus Torvalds uint64_t maxread; 3621c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3622c0eae66eSBenny Halevy if (unlikely(!p)) 3623c0eae66eSBenny Halevy goto out_overflow; 3624cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 36251da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 36261da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 36271da177e4SLinus Torvalds *res = (uint32_t)maxread; 36281da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 36291da177e4SLinus Torvalds } 36303110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 36311da177e4SLinus Torvalds return status; 3632c0eae66eSBenny Halevy out_overflow: 3633c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3634c0eae66eSBenny Halevy return -EIO; 36351da177e4SLinus Torvalds } 36361da177e4SLinus Torvalds 36371da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36381da177e4SLinus Torvalds { 36398687b63aSAl Viro __be32 *p; 36401da177e4SLinus Torvalds int status = 0; 36411da177e4SLinus Torvalds 36421da177e4SLinus Torvalds *res = 1024; 36431da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 36441da177e4SLinus Torvalds return -EIO; 36451da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 36461da177e4SLinus Torvalds uint64_t maxwrite; 3647c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3648c0eae66eSBenny Halevy if (unlikely(!p)) 3649c0eae66eSBenny Halevy goto out_overflow; 3650cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 36511da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 36521da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 36531da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 36541da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 36551da177e4SLinus Torvalds } 36563110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 36571da177e4SLinus Torvalds return status; 3658c0eae66eSBenny Halevy out_overflow: 3659c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3660c0eae66eSBenny Halevy return -EIO; 36611da177e4SLinus Torvalds } 36621da177e4SLinus Torvalds 3663bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 36641da177e4SLinus Torvalds { 3665bca79478STrond Myklebust uint32_t tmp; 36668687b63aSAl Viro __be32 *p; 3667409924e4STrond Myklebust int ret = 0; 36681da177e4SLinus Torvalds 36691da177e4SLinus Torvalds *mode = 0; 36701da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 36711da177e4SLinus Torvalds return -EIO; 36721da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3673c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3674c0eae66eSBenny Halevy if (unlikely(!p)) 3675c0eae66eSBenny Halevy goto out_overflow; 3676cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3677bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 36781da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3679409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 36801da177e4SLinus Torvalds } 36813110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3682409924e4STrond Myklebust return ret; 3683c0eae66eSBenny Halevy out_overflow: 3684c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3685c0eae66eSBenny Halevy return -EIO; 36861da177e4SLinus Torvalds } 36871da177e4SLinus Torvalds 36881da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 36891da177e4SLinus Torvalds { 36908687b63aSAl Viro __be32 *p; 3691409924e4STrond Myklebust int ret = 0; 36921da177e4SLinus Torvalds 36931da177e4SLinus Torvalds *nlink = 1; 36941da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 36951da177e4SLinus Torvalds return -EIO; 36961da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3697c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3698c0eae66eSBenny Halevy if (unlikely(!p)) 3699c0eae66eSBenny Halevy goto out_overflow; 3700cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 37011da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3702409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 37031da177e4SLinus Torvalds } 37043110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3705409924e4STrond Myklebust return ret; 3706c0eae66eSBenny Halevy out_overflow: 3707c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3708c0eae66eSBenny Halevy return -EIO; 37091da177e4SLinus Torvalds } 37101da177e4SLinus Torvalds 371180e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 37126926afd1STrond Myklebust const struct nfs_server *server, uint32_t *uid, 37136926afd1STrond Myklebust struct nfs4_string *owner_name) 37141da177e4SLinus Torvalds { 37158687b63aSAl Viro uint32_t len; 37168687b63aSAl Viro __be32 *p; 3717409924e4STrond Myklebust int ret = 0; 37181da177e4SLinus Torvalds 37191da177e4SLinus Torvalds *uid = -2; 37201da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 37211da177e4SLinus Torvalds return -EIO; 37221da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3723c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3724c0eae66eSBenny Halevy if (unlikely(!p)) 3725c0eae66eSBenny Halevy goto out_overflow; 3726cccddf4fSBenny Halevy len = be32_to_cpup(p); 3727c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3728c0eae66eSBenny Halevy if (unlikely(!p)) 3729c0eae66eSBenny Halevy goto out_overflow; 37306926afd1STrond Myklebust if (owner_name != NULL) { 37316926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 37326926afd1STrond Myklebust if (owner_name->data != NULL) { 37336926afd1STrond Myklebust owner_name->len = len; 37346926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 37356926afd1STrond Myklebust } 373680e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3737e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3738409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3739409924e4STrond Myklebust else 37401da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 37413110ff80SHarvey Harrison __func__); 37421da177e4SLinus Torvalds } else 3743fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 37443110ff80SHarvey Harrison __func__, len); 37451da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 37461da177e4SLinus Torvalds } 37473110ff80SHarvey Harrison dprintk("%s: uid=%d\n", __func__, (int)*uid); 3748409924e4STrond Myklebust return ret; 3749c0eae66eSBenny Halevy out_overflow: 3750c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3751c0eae66eSBenny Halevy return -EIO; 37521da177e4SLinus Torvalds } 37531da177e4SLinus Torvalds 375480e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 37556926afd1STrond Myklebust const struct nfs_server *server, uint32_t *gid, 37566926afd1STrond Myklebust struct nfs4_string *group_name) 37571da177e4SLinus Torvalds { 37588687b63aSAl Viro uint32_t len; 37598687b63aSAl Viro __be32 *p; 3760409924e4STrond Myklebust int ret = 0; 37611da177e4SLinus Torvalds 37621da177e4SLinus Torvalds *gid = -2; 37631da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 37641da177e4SLinus Torvalds return -EIO; 37651da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3766c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3767c0eae66eSBenny Halevy if (unlikely(!p)) 3768c0eae66eSBenny Halevy goto out_overflow; 3769cccddf4fSBenny Halevy len = be32_to_cpup(p); 3770c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3771c0eae66eSBenny Halevy if (unlikely(!p)) 3772c0eae66eSBenny Halevy goto out_overflow; 37736926afd1STrond Myklebust if (group_name != NULL) { 37746926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 37756926afd1STrond Myklebust if (group_name->data != NULL) { 37766926afd1STrond Myklebust group_name->len = len; 37776926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 37786926afd1STrond Myklebust } 377980e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3780e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3781409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3782409924e4STrond Myklebust else 37831da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 37843110ff80SHarvey Harrison __func__); 37851da177e4SLinus Torvalds } else 3786fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 37873110ff80SHarvey Harrison __func__, len); 37881da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 37891da177e4SLinus Torvalds } 37903110ff80SHarvey Harrison dprintk("%s: gid=%d\n", __func__, (int)*gid); 3791409924e4STrond Myklebust return ret; 3792c0eae66eSBenny Halevy out_overflow: 3793c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3794c0eae66eSBenny Halevy return -EIO; 37951da177e4SLinus Torvalds } 37961da177e4SLinus Torvalds 37971da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 37981da177e4SLinus Torvalds { 37998687b63aSAl Viro uint32_t major = 0, minor = 0; 38008687b63aSAl Viro __be32 *p; 3801409924e4STrond Myklebust int ret = 0; 38021da177e4SLinus Torvalds 38031da177e4SLinus Torvalds *rdev = MKDEV(0,0); 38041da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 38051da177e4SLinus Torvalds return -EIO; 38061da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 38071da177e4SLinus Torvalds dev_t tmp; 38081da177e4SLinus Torvalds 3809c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3810c0eae66eSBenny Halevy if (unlikely(!p)) 3811c0eae66eSBenny Halevy goto out_overflow; 38126f723f77SBenny Halevy major = be32_to_cpup(p++); 3813cccddf4fSBenny Halevy minor = be32_to_cpup(p); 38141da177e4SLinus Torvalds tmp = MKDEV(major, minor); 38151da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 38161da177e4SLinus Torvalds *rdev = tmp; 38171da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3818409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 38191da177e4SLinus Torvalds } 38203110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3821409924e4STrond Myklebust return ret; 3822c0eae66eSBenny Halevy out_overflow: 3823c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3824c0eae66eSBenny Halevy return -EIO; 38251da177e4SLinus Torvalds } 38261da177e4SLinus Torvalds 38271da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38281da177e4SLinus Torvalds { 38298687b63aSAl Viro __be32 *p; 38301da177e4SLinus Torvalds int status = 0; 38311da177e4SLinus Torvalds 38321da177e4SLinus Torvalds *res = 0; 38331da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 38341da177e4SLinus Torvalds return -EIO; 38351da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3836c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3837c0eae66eSBenny Halevy if (unlikely(!p)) 3838c0eae66eSBenny Halevy goto out_overflow; 3839cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38401da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 38411da177e4SLinus Torvalds } 38423110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 38431da177e4SLinus Torvalds return status; 3844c0eae66eSBenny Halevy out_overflow: 3845c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3846c0eae66eSBenny Halevy return -EIO; 38471da177e4SLinus Torvalds } 38481da177e4SLinus Torvalds 38491da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38501da177e4SLinus Torvalds { 38518687b63aSAl Viro __be32 *p; 38521da177e4SLinus Torvalds int status = 0; 38531da177e4SLinus Torvalds 38541da177e4SLinus Torvalds *res = 0; 38551da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 38561da177e4SLinus Torvalds return -EIO; 38571da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3858c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3859c0eae66eSBenny Halevy if (unlikely(!p)) 3860c0eae66eSBenny Halevy goto out_overflow; 3861cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38621da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 38631da177e4SLinus Torvalds } 38643110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 38651da177e4SLinus Torvalds return status; 3866c0eae66eSBenny Halevy out_overflow: 3867c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3868c0eae66eSBenny Halevy return -EIO; 38691da177e4SLinus Torvalds } 38701da177e4SLinus Torvalds 38711da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38721da177e4SLinus Torvalds { 38738687b63aSAl Viro __be32 *p; 38741da177e4SLinus Torvalds int status = 0; 38751da177e4SLinus Torvalds 38761da177e4SLinus Torvalds *res = 0; 38771da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 38781da177e4SLinus Torvalds return -EIO; 38791da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 3880c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3881c0eae66eSBenny Halevy if (unlikely(!p)) 3882c0eae66eSBenny Halevy goto out_overflow; 3883cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38841da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 38851da177e4SLinus Torvalds } 38863110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 38871da177e4SLinus Torvalds return status; 3888c0eae66eSBenny Halevy out_overflow: 3889c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3890c0eae66eSBenny Halevy return -EIO; 38911da177e4SLinus Torvalds } 38921da177e4SLinus Torvalds 38931da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 38941da177e4SLinus Torvalds { 38958687b63aSAl Viro __be32 *p; 3896409924e4STrond Myklebust int ret = 0; 38971da177e4SLinus Torvalds 38981da177e4SLinus Torvalds *used = 0; 38991da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 39001da177e4SLinus Torvalds return -EIO; 39011da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 3902c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3903c0eae66eSBenny Halevy if (unlikely(!p)) 3904c0eae66eSBenny Halevy goto out_overflow; 3905cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 39061da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 3907409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 39081da177e4SLinus Torvalds } 39093110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 39101da177e4SLinus Torvalds (unsigned long long)*used); 3911409924e4STrond Myklebust return ret; 3912c0eae66eSBenny Halevy out_overflow: 3913c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3914c0eae66eSBenny Halevy return -EIO; 39151da177e4SLinus Torvalds } 39161da177e4SLinus Torvalds 39171da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 39181da177e4SLinus Torvalds { 39198687b63aSAl Viro __be32 *p; 39201da177e4SLinus Torvalds uint64_t sec; 39211da177e4SLinus Torvalds uint32_t nsec; 39221da177e4SLinus Torvalds 3923c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3924c0eae66eSBenny Halevy if (unlikely(!p)) 3925c0eae66eSBenny Halevy goto out_overflow; 39263ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 3927cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 39281da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 39291da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 39301da177e4SLinus Torvalds return 0; 3931c0eae66eSBenny Halevy out_overflow: 3932c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3933c0eae66eSBenny Halevy return -EIO; 39341da177e4SLinus Torvalds } 39351da177e4SLinus Torvalds 39361da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39371da177e4SLinus Torvalds { 39381da177e4SLinus Torvalds int status = 0; 39391da177e4SLinus Torvalds 39401da177e4SLinus Torvalds time->tv_sec = 0; 39411da177e4SLinus Torvalds time->tv_nsec = 0; 39421da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 39431da177e4SLinus Torvalds return -EIO; 39441da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 39451da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 3946409924e4STrond Myklebust if (status == 0) 3947409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 39481da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 39491da177e4SLinus Torvalds } 39503110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 39511da177e4SLinus Torvalds return status; 39521da177e4SLinus Torvalds } 39531da177e4SLinus Torvalds 39541da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39551da177e4SLinus Torvalds { 39561da177e4SLinus Torvalds int status = 0; 39571da177e4SLinus Torvalds 39581da177e4SLinus Torvalds time->tv_sec = 0; 39591da177e4SLinus Torvalds time->tv_nsec = 0; 39601da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 39611da177e4SLinus Torvalds return -EIO; 39621da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 39631da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 3964409924e4STrond Myklebust if (status == 0) 3965409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 39661da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 39671da177e4SLinus Torvalds } 39683110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 39691da177e4SLinus Torvalds return status; 39701da177e4SLinus Torvalds } 39711da177e4SLinus Torvalds 397255b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 397355b6e774SRicardo Labiaga struct timespec *time) 397455b6e774SRicardo Labiaga { 397555b6e774SRicardo Labiaga int status = 0; 397655b6e774SRicardo Labiaga 397755b6e774SRicardo Labiaga time->tv_sec = 0; 397855b6e774SRicardo Labiaga time->tv_nsec = 0; 397955b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 398055b6e774SRicardo Labiaga return -EIO; 398155b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 398255b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 398355b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 398455b6e774SRicardo Labiaga } 398555b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 398655b6e774SRicardo Labiaga (long)time->tv_nsec); 398755b6e774SRicardo Labiaga return status; 398855b6e774SRicardo Labiaga } 398955b6e774SRicardo Labiaga 39901da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39911da177e4SLinus Torvalds { 39921da177e4SLinus Torvalds int status = 0; 39931da177e4SLinus Torvalds 39941da177e4SLinus Torvalds time->tv_sec = 0; 39951da177e4SLinus Torvalds time->tv_nsec = 0; 39961da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 39971da177e4SLinus Torvalds return -EIO; 39981da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 39991da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4000409924e4STrond Myklebust if (status == 0) 4001409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 40021da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 40031da177e4SLinus Torvalds } 40043110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 40051da177e4SLinus Torvalds return status; 40061da177e4SLinus Torvalds } 40071da177e4SLinus Torvalds 40088687b63aSAl Viro static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) 40091da177e4SLinus Torvalds { 40101da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 40111da177e4SLinus Torvalds unsigned int nwords = xdr->p - savep; 40121da177e4SLinus Torvalds 40131da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4014fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4015fe82a183SChuck Lever "%u %c %u\n", 40163110ff80SHarvey Harrison __func__, 40171da177e4SLinus Torvalds attrwords << 2, 40181da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 40191da177e4SLinus Torvalds nwords << 2); 40201da177e4SLinus Torvalds return -EIO; 40211da177e4SLinus Torvalds } 40221da177e4SLinus Torvalds return 0; 40231da177e4SLinus Torvalds } 40241da177e4SLinus Torvalds 40251da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 40261da177e4SLinus Torvalds { 40278687b63aSAl Viro __be32 *p; 40281da177e4SLinus Torvalds 4029c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4030c0eae66eSBenny Halevy if (unlikely(!p)) 4031c0eae66eSBenny Halevy goto out_overflow; 40326f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 40333ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4034cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 40351da177e4SLinus Torvalds return 0; 4036c0eae66eSBenny Halevy out_overflow: 4037c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4038c0eae66eSBenny Halevy return -EIO; 40391da177e4SLinus Torvalds } 40401da177e4SLinus Torvalds 40411da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 40421da177e4SLinus Torvalds { 40438687b63aSAl Viro __be32 *p; 40441da177e4SLinus Torvalds uint32_t supp, acc; 40451da177e4SLinus Torvalds int status; 40461da177e4SLinus Torvalds 40471da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 40481da177e4SLinus Torvalds if (status) 40491da177e4SLinus Torvalds return status; 4050c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4051c0eae66eSBenny Halevy if (unlikely(!p)) 4052c0eae66eSBenny Halevy goto out_overflow; 40536f723f77SBenny Halevy supp = be32_to_cpup(p++); 4054cccddf4fSBenny Halevy acc = be32_to_cpup(p); 40551da177e4SLinus Torvalds access->supported = supp; 40561da177e4SLinus Torvalds access->access = acc; 40571da177e4SLinus Torvalds return 0; 4058c0eae66eSBenny Halevy out_overflow: 4059c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4060c0eae66eSBenny Halevy return -EIO; 40611da177e4SLinus Torvalds } 40621da177e4SLinus Torvalds 406307d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 40641da177e4SLinus Torvalds { 40658687b63aSAl Viro __be32 *p; 406607d30434SBenny Halevy 406707d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 406807d30434SBenny Halevy if (likely(p)) { 406907d30434SBenny Halevy memcpy(buf, p, len); 407007d30434SBenny Halevy return 0; 407107d30434SBenny Halevy } 407207d30434SBenny Halevy print_overflow_msg(__func__, xdr); 407307d30434SBenny Halevy return -EIO; 407407d30434SBenny Halevy } 407507d30434SBenny Halevy 407607d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 407707d30434SBenny Halevy { 40782d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 40791da177e4SLinus Torvalds } 40801da177e4SLinus Torvalds 40811da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 40821da177e4SLinus Torvalds { 40831da177e4SLinus Torvalds int status; 40841da177e4SLinus Torvalds 40851da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4086c1d51931STrond Myklebust if (status != -EIO) 4087c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 408807d30434SBenny Halevy if (!status) 408907d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 40901da177e4SLinus Torvalds return status; 40911da177e4SLinus Torvalds } 40921da177e4SLinus Torvalds 4093db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4094db942bbdSBenny Halevy { 4095cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 40961da177e4SLinus Torvalds } 40971da177e4SLinus Torvalds 40981da177e4SLinus Torvalds static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) 40991da177e4SLinus Torvalds { 41001da177e4SLinus Torvalds int status; 41011da177e4SLinus Torvalds 41021da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4103db942bbdSBenny Halevy if (!status) 4104db942bbdSBenny Halevy status = decode_verifier(xdr, res->verf->verifier); 41051da177e4SLinus Torvalds return status; 41061da177e4SLinus Torvalds } 41071da177e4SLinus Torvalds 41081da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 41091da177e4SLinus Torvalds { 41108687b63aSAl Viro __be32 *p; 41111da177e4SLinus Torvalds uint32_t bmlen; 41121da177e4SLinus Torvalds int status; 41131da177e4SLinus Torvalds 41141da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 41151da177e4SLinus Torvalds if (status) 41161da177e4SLinus Torvalds return status; 41171da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 41181da177e4SLinus Torvalds return status; 4119c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4120c0eae66eSBenny Halevy if (unlikely(!p)) 4121c0eae66eSBenny Halevy goto out_overflow; 4122cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4123c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4124c0eae66eSBenny Halevy if (likely(p)) 41251da177e4SLinus Torvalds return 0; 4126c0eae66eSBenny Halevy out_overflow: 4127c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4128c0eae66eSBenny Halevy return -EIO; 41291da177e4SLinus Torvalds } 41301da177e4SLinus Torvalds 41311da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 41321da177e4SLinus Torvalds { 41338687b63aSAl Viro __be32 *savep; 4134dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41351da177e4SLinus Torvalds int status; 41361da177e4SLinus Torvalds 41371da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 41381da177e4SLinus Torvalds goto xdr_error; 41391da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 41401da177e4SLinus Torvalds goto xdr_error; 41411da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 41421da177e4SLinus Torvalds goto xdr_error; 41431da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 41441da177e4SLinus Torvalds goto xdr_error; 4145264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4146264e6351SChuck Lever &res->fh_expire_type)) != 0) 4147264e6351SChuck Lever goto xdr_error; 41481da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 41491da177e4SLinus Torvalds goto xdr_error; 41501da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 41511da177e4SLinus Torvalds goto xdr_error; 41521da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 41531da177e4SLinus Torvalds goto xdr_error; 41541da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 41551da177e4SLinus Torvalds xdr_error: 41563110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 41571da177e4SLinus Torvalds return status; 41581da177e4SLinus Torvalds } 41591da177e4SLinus Torvalds 41601da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 41611da177e4SLinus Torvalds { 41628687b63aSAl Viro __be32 *savep; 4163dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41641da177e4SLinus Torvalds int status; 41651da177e4SLinus Torvalds 41661da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 41671da177e4SLinus Torvalds goto xdr_error; 41681da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 41691da177e4SLinus Torvalds goto xdr_error; 41701da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 41711da177e4SLinus Torvalds goto xdr_error; 41721da177e4SLinus Torvalds 41731da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 41741da177e4SLinus Torvalds goto xdr_error; 41751da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 41761da177e4SLinus Torvalds goto xdr_error; 41771da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 41781da177e4SLinus Torvalds goto xdr_error; 41791da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 41801da177e4SLinus Torvalds goto xdr_error; 41811da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 41821da177e4SLinus Torvalds goto xdr_error; 41831da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 41841da177e4SLinus Torvalds goto xdr_error; 41851da177e4SLinus Torvalds 41861da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 41871da177e4SLinus Torvalds xdr_error: 41883110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 41891da177e4SLinus Torvalds return status; 41901da177e4SLinus Torvalds } 41911da177e4SLinus Torvalds 41921da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 41931da177e4SLinus Torvalds { 41948687b63aSAl Viro __be32 *savep; 4195dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41961da177e4SLinus Torvalds int status; 41971da177e4SLinus Torvalds 41981da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 41991da177e4SLinus Torvalds goto xdr_error; 42001da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42011da177e4SLinus Torvalds goto xdr_error; 42021da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42031da177e4SLinus Torvalds goto xdr_error; 42041da177e4SLinus Torvalds 42051da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 42061da177e4SLinus Torvalds goto xdr_error; 42071da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 42081da177e4SLinus Torvalds goto xdr_error; 42091da177e4SLinus Torvalds 42101da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42111da177e4SLinus Torvalds xdr_error: 42123110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42131da177e4SLinus Torvalds return status; 42141da177e4SLinus Torvalds } 42151da177e4SLinus Torvalds 4216ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4217ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 42188b7e3f49STrond Myklebust struct nfs4_fs_locations *fs_loc, 42196926afd1STrond Myklebust const struct nfs_server *server) 42201da177e4SLinus Torvalds { 4221bca79478STrond Myklebust int status; 4222bca79478STrond Myklebust umode_t fmode = 0; 4223ae42c70aSBryan Schumaker uint32_t type; 4224ee7b75fcSTrond Myklebust int32_t err; 42251da177e4SLinus Torvalds 4226f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4227f26c7a78STrond Myklebust if (status < 0) 42281da177e4SLinus Torvalds goto xdr_error; 4229409924e4STrond Myklebust fattr->mode = 0; 4230409924e4STrond Myklebust if (status != 0) { 4231409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4232409924e4STrond Myklebust fattr->valid |= status; 4233409924e4STrond Myklebust } 42341da177e4SLinus Torvalds 4235f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4236f26c7a78STrond Myklebust if (status < 0) 42371da177e4SLinus Torvalds goto xdr_error; 4238409924e4STrond Myklebust fattr->valid |= status; 4239f26c7a78STrond Myklebust 4240f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4241f26c7a78STrond Myklebust if (status < 0) 42421da177e4SLinus Torvalds goto xdr_error; 4243409924e4STrond Myklebust fattr->valid |= status; 4244f26c7a78STrond Myklebust 4245f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4246f26c7a78STrond Myklebust if (status < 0) 42471da177e4SLinus Torvalds goto xdr_error; 4248409924e4STrond Myklebust fattr->valid |= status; 4249f26c7a78STrond Myklebust 4250ee7b75fcSTrond Myklebust err = 0; 4251ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4252ae42c70aSBryan Schumaker if (status < 0) 4253ae42c70aSBryan Schumaker goto xdr_error; 4254ee7b75fcSTrond Myklebust if (err == -NFS4ERR_WRONGSEC) 4255ee7b75fcSTrond Myklebust nfs_fixup_secinfo_attributes(fattr, fh); 4256ae42c70aSBryan Schumaker 4257ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4258ae42c70aSBryan Schumaker if (status < 0) 4259ae42c70aSBryan Schumaker goto xdr_error; 4260ae42c70aSBryan Schumaker 4261f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4262f26c7a78STrond Myklebust if (status < 0) 42631da177e4SLinus Torvalds goto xdr_error; 4264409924e4STrond Myklebust fattr->valid |= status; 4265f26c7a78STrond Myklebust 42668b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4267f26c7a78STrond Myklebust if (status < 0) 4268683b57b4STrond Myklebust goto xdr_error; 4269409924e4STrond Myklebust fattr->valid |= status; 4270f26c7a78STrond Myklebust 4271f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4272f26c7a78STrond Myklebust if (status < 0) 42731da177e4SLinus Torvalds goto xdr_error; 4274409924e4STrond Myklebust if (status != 0) { 42751da177e4SLinus Torvalds fattr->mode |= fmode; 4276409924e4STrond Myklebust fattr->valid |= status; 4277409924e4STrond Myklebust } 4278f26c7a78STrond Myklebust 4279f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4280f26c7a78STrond Myklebust if (status < 0) 42811da177e4SLinus Torvalds goto xdr_error; 4282409924e4STrond Myklebust fattr->valid |= status; 4283f26c7a78STrond Myklebust 42846926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4285f26c7a78STrond Myklebust if (status < 0) 42861da177e4SLinus Torvalds goto xdr_error; 4287409924e4STrond Myklebust fattr->valid |= status; 4288f26c7a78STrond Myklebust 42896926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4290f26c7a78STrond Myklebust if (status < 0) 42911da177e4SLinus Torvalds goto xdr_error; 4292409924e4STrond Myklebust fattr->valid |= status; 4293f26c7a78STrond Myklebust 4294f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4295f26c7a78STrond Myklebust if (status < 0) 42961da177e4SLinus Torvalds goto xdr_error; 4297409924e4STrond Myklebust fattr->valid |= status; 4298f26c7a78STrond Myklebust 4299f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4300f26c7a78STrond Myklebust if (status < 0) 43011da177e4SLinus Torvalds goto xdr_error; 4302409924e4STrond Myklebust fattr->valid |= status; 4303f26c7a78STrond Myklebust 4304f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4305f26c7a78STrond Myklebust if (status < 0) 43061da177e4SLinus Torvalds goto xdr_error; 4307409924e4STrond Myklebust fattr->valid |= status; 4308f26c7a78STrond Myklebust 4309f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4310f26c7a78STrond Myklebust if (status < 0) 43111da177e4SLinus Torvalds goto xdr_error; 4312409924e4STrond Myklebust fattr->valid |= status; 4313f26c7a78STrond Myklebust 4314f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4315f26c7a78STrond Myklebust if (status < 0) 43161da177e4SLinus Torvalds goto xdr_error; 4317409924e4STrond Myklebust fattr->valid |= status; 4318f26c7a78STrond Myklebust 431928331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4320f26c7a78STrond Myklebust if (status < 0) 432199baf625SManoj Naik goto xdr_error; 4322409924e4STrond Myklebust fattr->valid |= status; 4323f26c7a78STrond Myklebust 4324ae42c70aSBryan Schumaker xdr_error: 4325ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4326ae42c70aSBryan Schumaker return status; 4327ae42c70aSBryan Schumaker } 4328ae42c70aSBryan Schumaker 4329ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 43308b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 43318b7e3f49STrond Myklebust const struct nfs_server *server) 4332ae42c70aSBryan Schumaker { 4333ae42c70aSBryan Schumaker __be32 *savep; 4334ae42c70aSBryan Schumaker uint32_t attrlen, 4335dae100c2SFred Isaman bitmap[3] = {0}; 4336ae42c70aSBryan Schumaker int status; 4337ae42c70aSBryan Schumaker 4338ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4339ae42c70aSBryan Schumaker if (status < 0) 4340ae42c70aSBryan Schumaker goto xdr_error; 4341ae42c70aSBryan Schumaker 4342ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4343ae42c70aSBryan Schumaker if (status < 0) 4344ae42c70aSBryan Schumaker goto xdr_error; 4345ae42c70aSBryan Schumaker 4346ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4347ae42c70aSBryan Schumaker if (status < 0) 4348ae42c70aSBryan Schumaker goto xdr_error; 4349ae42c70aSBryan Schumaker 43508b7e3f49STrond Myklebust status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server); 4351ae42c70aSBryan Schumaker if (status < 0) 4352ae42c70aSBryan Schumaker goto xdr_error; 4353ae42c70aSBryan Schumaker 4354f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 43551da177e4SLinus Torvalds xdr_error: 43563110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 43571da177e4SLinus Torvalds return status; 43581da177e4SLinus Torvalds } 43591da177e4SLinus Torvalds 4360ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 43616926afd1STrond Myklebust const struct nfs_server *server) 4362ae42c70aSBryan Schumaker { 43638b7e3f49STrond Myklebust return decode_getfattr_generic(xdr, fattr, NULL, NULL, server); 4364ae42c70aSBryan Schumaker } 43651da177e4SLinus Torvalds 4366504913fbSAndy Adamson /* 4367504913fbSAndy Adamson * Decode potentially multiple layout types. Currently we only support 4368504913fbSAndy Adamson * one layout driver per file system. 4369504913fbSAndy Adamson */ 4370504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, 4371504913fbSAndy Adamson uint32_t *layouttype) 4372504913fbSAndy Adamson { 4373504913fbSAndy Adamson uint32_t *p; 4374504913fbSAndy Adamson int num; 4375504913fbSAndy Adamson 4376504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4377504913fbSAndy Adamson if (unlikely(!p)) 4378504913fbSAndy Adamson goto out_overflow; 4379504913fbSAndy Adamson num = be32_to_cpup(p); 4380504913fbSAndy Adamson 4381504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4382504913fbSAndy Adamson if (num == 0) { 4383504913fbSAndy Adamson *layouttype = 0; 4384504913fbSAndy Adamson return 0; 4385504913fbSAndy Adamson } 4386504913fbSAndy Adamson if (num > 1) 4387a030889aSWeston Andros Adamson printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout " 4388a030889aSWeston Andros Adamson "drivers per filesystem not supported\n", __func__); 4389504913fbSAndy Adamson 4390504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4391504913fbSAndy Adamson p = xdr_inline_decode(xdr, num * 4); 4392504913fbSAndy Adamson if (unlikely(!p)) 4393504913fbSAndy Adamson goto out_overflow; 4394504913fbSAndy Adamson *layouttype = be32_to_cpup(p); 4395504913fbSAndy Adamson return 0; 4396504913fbSAndy Adamson out_overflow: 4397504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4398504913fbSAndy Adamson return -EIO; 4399504913fbSAndy Adamson } 4400504913fbSAndy Adamson 4401504913fbSAndy Adamson /* 4402504913fbSAndy Adamson * The type of file system exported. 4403504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4404504913fbSAndy Adamson */ 4405504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4406504913fbSAndy Adamson uint32_t *layouttype) 4407504913fbSAndy Adamson { 4408504913fbSAndy Adamson int status = 0; 4409504913fbSAndy Adamson 4410504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4411504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4412504913fbSAndy Adamson return -EIO; 4413504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4414504913fbSAndy Adamson status = decode_first_pnfs_layout_type(xdr, layouttype); 4415504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 4416504913fbSAndy Adamson } else 4417504913fbSAndy Adamson *layouttype = 0; 4418504913fbSAndy Adamson return status; 4419504913fbSAndy Adamson } 4420504913fbSAndy Adamson 4421dae100c2SFred Isaman /* 4422dae100c2SFred Isaman * The prefered block size for layout directed io 4423dae100c2SFred Isaman */ 4424dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4425dae100c2SFred Isaman uint32_t *res) 4426dae100c2SFred Isaman { 4427dae100c2SFred Isaman __be32 *p; 4428dae100c2SFred Isaman 4429dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4430dae100c2SFred Isaman *res = 0; 4431dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4432dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4433dae100c2SFred Isaman if (unlikely(!p)) { 4434dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4435dae100c2SFred Isaman return -EIO; 4436dae100c2SFred Isaman } 4437dae100c2SFred Isaman *res = be32_to_cpup(p); 4438dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4439dae100c2SFred Isaman } 4440dae100c2SFred Isaman return 0; 4441dae100c2SFred Isaman } 4442dae100c2SFred Isaman 44431da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 44441da177e4SLinus Torvalds { 44458687b63aSAl Viro __be32 *savep; 4446dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 44471da177e4SLinus Torvalds int status; 44481da177e4SLinus Torvalds 44491da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44501da177e4SLinus Torvalds goto xdr_error; 44511da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44521da177e4SLinus Torvalds goto xdr_error; 44531da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44541da177e4SLinus Torvalds goto xdr_error; 44551da177e4SLinus Torvalds 44561da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 44571da177e4SLinus Torvalds 44581da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 44591da177e4SLinus Torvalds goto xdr_error; 44601da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 44611da177e4SLinus Torvalds goto xdr_error; 44621da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 44631da177e4SLinus Torvalds goto xdr_error; 44641da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 44651da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 44661da177e4SLinus Torvalds goto xdr_error; 44671da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 446855b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 446955b6e774SRicardo Labiaga if (status != 0) 447055b6e774SRicardo Labiaga goto xdr_error; 4471504913fbSAndy Adamson status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); 4472504913fbSAndy Adamson if (status != 0) 4473504913fbSAndy Adamson goto xdr_error; 4474dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4475dae100c2SFred Isaman if (status) 4476dae100c2SFred Isaman goto xdr_error; 44771da177e4SLinus Torvalds 44781da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44791da177e4SLinus Torvalds xdr_error: 44803110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44811da177e4SLinus Torvalds return status; 44821da177e4SLinus Torvalds } 44831da177e4SLinus Torvalds 44841da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 44851da177e4SLinus Torvalds { 44868687b63aSAl Viro __be32 *p; 44871da177e4SLinus Torvalds uint32_t len; 44881da177e4SLinus Torvalds int status; 44891da177e4SLinus Torvalds 44909936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 44919936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 44929936781dSTrond Myklebust 44931da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 44941da177e4SLinus Torvalds if (status) 44951da177e4SLinus Torvalds return status; 44961da177e4SLinus Torvalds 4497c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4498c0eae66eSBenny Halevy if (unlikely(!p)) 4499c0eae66eSBenny Halevy goto out_overflow; 4500cccddf4fSBenny Halevy len = be32_to_cpup(p); 45011da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 45021da177e4SLinus Torvalds return -EIO; 45031da177e4SLinus Torvalds fh->size = len; 4504c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4505c0eae66eSBenny Halevy if (unlikely(!p)) 4506c0eae66eSBenny Halevy goto out_overflow; 450799398d06SBenny Halevy memcpy(fh->data, p, len); 45081da177e4SLinus Torvalds return 0; 4509c0eae66eSBenny Halevy out_overflow: 4510c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4511c0eae66eSBenny Halevy return -EIO; 45121da177e4SLinus Torvalds } 45131da177e4SLinus Torvalds 45141da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 45151da177e4SLinus Torvalds { 45161da177e4SLinus Torvalds int status; 45171da177e4SLinus Torvalds 45181da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 45191da177e4SLinus Torvalds if (status) 45201da177e4SLinus Torvalds return status; 45211da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 45221da177e4SLinus Torvalds } 45231da177e4SLinus Torvalds 45241da177e4SLinus Torvalds /* 45251da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 45261da177e4SLinus Torvalds */ 4527911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 45281da177e4SLinus Torvalds { 4529911d1aafSTrond Myklebust uint64_t offset, length, clientid; 45308687b63aSAl Viro __be32 *p; 4531911d1aafSTrond Myklebust uint32_t namelen, type; 45321da177e4SLinus Torvalds 4533babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4534c0eae66eSBenny Halevy if (unlikely(!p)) 4535c0eae66eSBenny Halevy goto out_overflow; 4536babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 45373ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4538babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4539babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4540911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4541911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4542911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4543911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4544911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4545911d1aafSTrond Myklebust if (type & 1) 4546911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4547911d1aafSTrond Myklebust fl->fl_pid = 0; 4548911d1aafSTrond Myklebust } 4549babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4550babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4551babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4552c0eae66eSBenny Halevy if (likely(p)) 45531da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4554c0eae66eSBenny Halevy out_overflow: 4555c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4556c0eae66eSBenny Halevy return -EIO; 45571da177e4SLinus Torvalds } 45581da177e4SLinus Torvalds 4559911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 45601da177e4SLinus Torvalds { 45611da177e4SLinus Torvalds int status; 45621da177e4SLinus Torvalds 45631da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4564c1d51931STrond Myklebust if (status == -EIO) 4565c1d51931STrond Myklebust goto out; 45661da177e4SLinus Torvalds if (status == 0) { 456707d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 456807d30434SBenny Halevy if (unlikely(status)) 456907d30434SBenny Halevy goto out; 45701da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4571c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4572c1d51931STrond Myklebust if (res->open_seqid != NULL) 4573c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4574c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4575c1d51931STrond Myklebust out: 45761da177e4SLinus Torvalds return status; 45771da177e4SLinus Torvalds } 45781da177e4SLinus Torvalds 4579911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 45801da177e4SLinus Torvalds { 45811da177e4SLinus Torvalds int status; 45821da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 45831da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4584911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 45851da177e4SLinus Torvalds return status; 45861da177e4SLinus Torvalds } 45871da177e4SLinus Torvalds 4588911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 45891da177e4SLinus Torvalds { 45901da177e4SLinus Torvalds int status; 45911da177e4SLinus Torvalds 45921da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4593c1d51931STrond Myklebust if (status != -EIO) 4594c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 459507d30434SBenny Halevy if (status == 0) 459607d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 45971da177e4SLinus Torvalds return status; 45981da177e4SLinus Torvalds } 45991da177e4SLinus Torvalds 4600d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4601d3c7b7ccSTrond Myklebust { 4602d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4603d3c7b7ccSTrond Myklebust } 4604d3c7b7ccSTrond Myklebust 46051da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 46061da177e4SLinus Torvalds { 46071da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 46081da177e4SLinus Torvalds } 46091da177e4SLinus Torvalds 46101da177e4SLinus Torvalds /* This is too sick! */ 46111da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 46121da177e4SLinus Torvalds { 46138687b63aSAl Viro __be32 *p; 46141da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 46151da177e4SLinus Torvalds 4616c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4617c0eae66eSBenny Halevy if (unlikely(!p)) 4618c0eae66eSBenny Halevy goto out_overflow; 46196f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 46201da177e4SLinus Torvalds switch (limit_type) { 46211da177e4SLinus Torvalds case 1: 4622cccddf4fSBenny Halevy xdr_decode_hyper(p, maxsize); 46231da177e4SLinus Torvalds break; 46241da177e4SLinus Torvalds case 2: 46256f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 4626cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 46271da177e4SLinus Torvalds *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 46281da177e4SLinus Torvalds } 46291da177e4SLinus Torvalds return 0; 4630c0eae66eSBenny Halevy out_overflow: 4631c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4632c0eae66eSBenny Halevy return -EIO; 46331da177e4SLinus Torvalds } 46341da177e4SLinus Torvalds 46351da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 46361da177e4SLinus Torvalds { 46378687b63aSAl Viro __be32 *p; 46381da177e4SLinus Torvalds uint32_t delegation_type; 463907d30434SBenny Halevy int status; 46401da177e4SLinus Torvalds 4641c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4642c0eae66eSBenny Halevy if (unlikely(!p)) 4643c0eae66eSBenny Halevy goto out_overflow; 4644cccddf4fSBenny Halevy delegation_type = be32_to_cpup(p); 46451da177e4SLinus Torvalds if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 46461da177e4SLinus Torvalds res->delegation_type = 0; 46471da177e4SLinus Torvalds return 0; 46481da177e4SLinus Torvalds } 464907d30434SBenny Halevy status = decode_stateid(xdr, &res->delegation); 465007d30434SBenny Halevy if (unlikely(status)) 465107d30434SBenny Halevy return status; 4652c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4653c0eae66eSBenny Halevy if (unlikely(!p)) 4654c0eae66eSBenny Halevy goto out_overflow; 4655cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 465605d564feSAndy Adamson 46571da177e4SLinus Torvalds switch (delegation_type) { 46581da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 46591da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 46601da177e4SLinus Torvalds break; 46611da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 46621da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 46631da177e4SLinus Torvalds if (decode_space_limit(xdr, &res->maxsize) < 0) 46641da177e4SLinus Torvalds return -EIO; 46651da177e4SLinus Torvalds } 46667539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 4667c0eae66eSBenny Halevy out_overflow: 4668c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4669c0eae66eSBenny Halevy return -EIO; 46701da177e4SLinus Torvalds } 46711da177e4SLinus Torvalds 46721da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 46731da177e4SLinus Torvalds { 46748687b63aSAl Viro __be32 *p; 4675aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 46761da177e4SLinus Torvalds int status; 46771da177e4SLinus Torvalds 46781da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN); 4679c1d51931STrond Myklebust if (status != -EIO) 4680c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 468107d30434SBenny Halevy if (!status) 468207d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 468307d30434SBenny Halevy if (unlikely(status)) 46841da177e4SLinus Torvalds return status; 46851da177e4SLinus Torvalds 46861da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 46871da177e4SLinus Torvalds 4688c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4689c0eae66eSBenny Halevy if (unlikely(!p)) 4690c0eae66eSBenny Halevy goto out_overflow; 46916f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 4692cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 46931da177e4SLinus Torvalds if (bmlen > 10) 46941da177e4SLinus Torvalds goto xdr_error; 46951da177e4SLinus Torvalds 4696c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4697c0eae66eSBenny Halevy if (unlikely(!p)) 4698c0eae66eSBenny Halevy goto out_overflow; 4699aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 4700aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 47016f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 4702aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 4703aa53ed54SJeff Layton res->attrset[i] = 0; 4704aa53ed54SJeff Layton 47051da177e4SLinus Torvalds return decode_delegation(xdr, res); 47061da177e4SLinus Torvalds xdr_error: 47073110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 47081da177e4SLinus Torvalds return -EIO; 4709c0eae66eSBenny Halevy out_overflow: 4710c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4711c0eae66eSBenny Halevy return -EIO; 47121da177e4SLinus Torvalds } 47131da177e4SLinus Torvalds 47141da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 47151da177e4SLinus Torvalds { 47161da177e4SLinus Torvalds int status; 47171da177e4SLinus Torvalds 47181da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 4719c1d51931STrond Myklebust if (status != -EIO) 4720c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 472107d30434SBenny Halevy if (!status) 472207d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 47231da177e4SLinus Torvalds return status; 47241da177e4SLinus Torvalds } 47251da177e4SLinus Torvalds 47261da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 47271da177e4SLinus Torvalds { 47281da177e4SLinus Torvalds int status; 47291da177e4SLinus Torvalds 47301da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 4731c1d51931STrond Myklebust if (status != -EIO) 4732c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 473307d30434SBenny Halevy if (!status) 473407d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 47351da177e4SLinus Torvalds return status; 47361da177e4SLinus Torvalds } 47371da177e4SLinus Torvalds 47381da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 47391da177e4SLinus Torvalds { 47401da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 47411da177e4SLinus Torvalds } 47421da177e4SLinus Torvalds 47431da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 47441da177e4SLinus Torvalds { 47451da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 47461da177e4SLinus Torvalds } 47471da177e4SLinus Torvalds 47481da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 47491da177e4SLinus Torvalds { 47501da177e4SLinus Torvalds struct kvec *iov = req->rq_rcv_buf.head; 47518687b63aSAl Viro __be32 *p; 47521da177e4SLinus Torvalds uint32_t count, eof, recvd, hdrlen; 47531da177e4SLinus Torvalds int status; 47541da177e4SLinus Torvalds 47551da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 47561da177e4SLinus Torvalds if (status) 47571da177e4SLinus Torvalds return status; 4758c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4759c0eae66eSBenny Halevy if (unlikely(!p)) 4760c0eae66eSBenny Halevy goto out_overflow; 47616f723f77SBenny Halevy eof = be32_to_cpup(p++); 4762cccddf4fSBenny Halevy count = be32_to_cpup(p); 47638111f373SChuck Lever hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 47641da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 47651da177e4SLinus Torvalds if (count > recvd) { 4766fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 47671da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 47681da177e4SLinus Torvalds count = recvd; 47691da177e4SLinus Torvalds eof = 0; 47701da177e4SLinus Torvalds } 47711da177e4SLinus Torvalds xdr_read_pages(xdr, count); 47721da177e4SLinus Torvalds res->eof = eof; 47731da177e4SLinus Torvalds res->count = count; 47741da177e4SLinus Torvalds return 0; 4775c0eae66eSBenny Halevy out_overflow: 4776c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4777c0eae66eSBenny Halevy return -EIO; 47781da177e4SLinus Torvalds } 47791da177e4SLinus Torvalds 47801da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 47811da177e4SLinus Torvalds { 47821da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 47831da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4784bcecff77SChuck Lever size_t hdrlen; 4785bcecff77SChuck Lever u32 recvd, pglen = rcvbuf->page_len; 4786bcecff77SChuck Lever int status; 4787cd93710eSChuck Lever __be32 verf[2]; 47881da177e4SLinus Torvalds 47891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 4790db942bbdSBenny Halevy if (!status) 4791db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 4792db942bbdSBenny Halevy if (unlikely(status)) 47931da177e4SLinus Torvalds return status; 4794cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 479544109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 4796cd93710eSChuck Lever __func__, verf[0], verf[1]); 47971da177e4SLinus Torvalds 4798db942bbdSBenny Halevy hdrlen = (char *) xdr->p - (char *) iov->iov_base; 47991da177e4SLinus Torvalds recvd = rcvbuf->len - hdrlen; 48001da177e4SLinus Torvalds if (pglen > recvd) 48011da177e4SLinus Torvalds pglen = recvd; 48021da177e4SLinus Torvalds xdr_read_pages(xdr, pglen); 48031da177e4SLinus Torvalds 48047bda2cdfSJeff Layton 4805ac396128STrond Myklebust return pglen; 48061da177e4SLinus Torvalds } 48071da177e4SLinus Torvalds 48081da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 48091da177e4SLinus Torvalds { 48101da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 48111da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4812bcecff77SChuck Lever size_t hdrlen; 4813bcecff77SChuck Lever u32 len, recvd; 48148687b63aSAl Viro __be32 *p; 48151da177e4SLinus Torvalds int status; 48161da177e4SLinus Torvalds 48171da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 48181da177e4SLinus Torvalds if (status) 48191da177e4SLinus Torvalds return status; 48201da177e4SLinus Torvalds 48211da177e4SLinus Torvalds /* Convert length of symlink */ 4822c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4823c0eae66eSBenny Halevy if (unlikely(!p)) 4824c0eae66eSBenny Halevy goto out_overflow; 4825cccddf4fSBenny Halevy len = be32_to_cpup(p); 48261da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 4827fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 48281da177e4SLinus Torvalds return -ENAMETOOLONG; 48291da177e4SLinus Torvalds } 48301da177e4SLinus Torvalds hdrlen = (char *) xdr->p - (char *) iov->iov_base; 48311da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 48321da177e4SLinus Torvalds if (recvd < len) { 4833fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 48341da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 48351da177e4SLinus Torvalds return -EIO; 48361da177e4SLinus Torvalds } 48371da177e4SLinus Torvalds xdr_read_pages(xdr, len); 48381da177e4SLinus Torvalds /* 48391da177e4SLinus Torvalds * The XDR encode routine has set things up so that 48401da177e4SLinus Torvalds * the link text will be copied directly into the 48411da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 48421da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 48431da177e4SLinus Torvalds * null-termination). 48441da177e4SLinus Torvalds */ 4845b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 48461da177e4SLinus Torvalds return 0; 4847c0eae66eSBenny Halevy out_overflow: 4848c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4849c0eae66eSBenny Halevy return -EIO; 48501da177e4SLinus Torvalds } 48511da177e4SLinus Torvalds 48521da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 48531da177e4SLinus Torvalds { 48541da177e4SLinus Torvalds int status; 48551da177e4SLinus Torvalds 48561da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 48571da177e4SLinus Torvalds if (status) 48581da177e4SLinus Torvalds goto out; 48591da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 48601da177e4SLinus Torvalds out: 48611da177e4SLinus Torvalds return status; 48621da177e4SLinus Torvalds } 48631da177e4SLinus Torvalds 48641da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 48651da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 48661da177e4SLinus Torvalds { 48671da177e4SLinus Torvalds int status; 48681da177e4SLinus Torvalds 48691da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 48701da177e4SLinus Torvalds if (status) 48711da177e4SLinus Torvalds goto out; 48721da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 48731da177e4SLinus Torvalds goto out; 48741da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 48751da177e4SLinus Torvalds out: 48761da177e4SLinus Torvalds return status; 48771da177e4SLinus Torvalds } 48781da177e4SLinus Torvalds 48791da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 48801da177e4SLinus Torvalds { 48811da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 48821da177e4SLinus Torvalds } 48831da177e4SLinus Torvalds 488456ae19f3STrond Myklebust static int 488556ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 488656ae19f3STrond Myklebust { 488756ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 488856ae19f3STrond Myklebust } 488956ae19f3STrond Myklebust 4890029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 4891bf118a34SAndy Adamson struct nfs_getaclres *res) 4892029d105eSJ. Bruce Fields { 4893bf118a34SAndy Adamson __be32 *savep, *bm_p; 4894029d105eSJ. Bruce Fields uint32_t attrlen, 4895dae100c2SFred Isaman bitmap[3] = {0}; 4896029d105eSJ. Bruce Fields struct kvec *iov = req->rq_rcv_buf.head; 4897029d105eSJ. Bruce Fields int status; 4898029d105eSJ. Bruce Fields 4899bf118a34SAndy Adamson res->acl_len = 0; 4900029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 4901029d105eSJ. Bruce Fields goto out; 4902bf118a34SAndy Adamson bm_p = xdr->p; 4903029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 4904029d105eSJ. Bruce Fields goto out; 4905029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 4906029d105eSJ. Bruce Fields goto out; 4907029d105eSJ. Bruce Fields 4908029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 4909029d105eSJ. Bruce Fields return -EIO; 4910029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 4911bcecff77SChuck Lever size_t hdrlen; 4912bcecff77SChuck Lever u32 recvd; 4913029d105eSJ. Bruce Fields 4914bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 4915bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 4916bf118a34SAndy Adamson * variable length bitmaps.*/ 4917bf118a34SAndy Adamson xdr->p = bm_p; 4918bf118a34SAndy Adamson res->acl_data_offset = be32_to_cpup(bm_p) + 2; 4919bf118a34SAndy Adamson res->acl_data_offset <<= 2; 4920bf118a34SAndy Adamson 4921029d105eSJ. Bruce Fields /* We ignore &savep and don't do consistency checks on 4922029d105eSJ. Bruce Fields * the attr length. Let userspace figure it out.... */ 4923029d105eSJ. Bruce Fields hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; 4924bf118a34SAndy Adamson attrlen += res->acl_data_offset; 4925029d105eSJ. Bruce Fields recvd = req->rq_rcv_buf.len - hdrlen; 4926029d105eSJ. Bruce Fields if (attrlen > recvd) { 4927bf118a34SAndy Adamson if (res->acl_flags & NFS4_ACL_LEN_REQUEST) { 4928bf118a34SAndy Adamson /* getxattr interface called with a NULL buf */ 4929bf118a34SAndy Adamson res->acl_len = attrlen; 4930bf118a34SAndy Adamson goto out; 4931bf118a34SAndy Adamson } 4932bf118a34SAndy Adamson dprintk("NFS: acl reply: attrlen %u > recvd %u\n", 4933029d105eSJ. Bruce Fields attrlen, recvd); 4934029d105eSJ. Bruce Fields return -EINVAL; 4935029d105eSJ. Bruce Fields } 4936029d105eSJ. Bruce Fields xdr_read_pages(xdr, attrlen); 4937bf118a34SAndy Adamson res->acl_len = attrlen; 49388c233cf9SJ. Bruce Fields } else 49398c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 4940029d105eSJ. Bruce Fields 4941029d105eSJ. Bruce Fields out: 4942029d105eSJ. Bruce Fields return status; 4943029d105eSJ. Bruce Fields } 4944029d105eSJ. Bruce Fields 49451da177e4SLinus Torvalds static int 49461da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 49471da177e4SLinus Torvalds { 49481da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 49491da177e4SLinus Torvalds } 49501da177e4SLinus Torvalds 49519e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 49521da177e4SLinus Torvalds { 49538687b63aSAl Viro __be32 *p; 49541da177e4SLinus Torvalds uint32_t bmlen; 49551da177e4SLinus Torvalds int status; 49561da177e4SLinus Torvalds 49571da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 49581da177e4SLinus Torvalds if (status) 49591da177e4SLinus Torvalds return status; 4960c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4961c0eae66eSBenny Halevy if (unlikely(!p)) 4962c0eae66eSBenny Halevy goto out_overflow; 4963cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4964c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4965c0eae66eSBenny Halevy if (likely(p)) 49661da177e4SLinus Torvalds return 0; 4967c0eae66eSBenny Halevy out_overflow: 4968c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4969c0eae66eSBenny Halevy return -EIO; 49701da177e4SLinus Torvalds } 49711da177e4SLinus Torvalds 4972bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 49731da177e4SLinus Torvalds { 49748687b63aSAl Viro __be32 *p; 49751da177e4SLinus Torvalds uint32_t opnum; 49761da177e4SLinus Torvalds int32_t nfserr; 49771da177e4SLinus Torvalds 4978c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4979c0eae66eSBenny Halevy if (unlikely(!p)) 4980c0eae66eSBenny Halevy goto out_overflow; 49816f723f77SBenny Halevy opnum = be32_to_cpup(p++); 49821da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 4983fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 49841da177e4SLinus Torvalds " %d\n", opnum); 49851da177e4SLinus Torvalds return -EIO; 49861da177e4SLinus Torvalds } 4987cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 49881da177e4SLinus Torvalds if (nfserr == NFS_OK) { 4989c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 4990c0eae66eSBenny Halevy if (unlikely(!p)) 4991c0eae66eSBenny Halevy goto out_overflow; 4992bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 4993bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 49941da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 49951da177e4SLinus Torvalds uint32_t len; 49961da177e4SLinus Torvalds 49971da177e4SLinus Torvalds /* skip netid string */ 4998c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4999c0eae66eSBenny Halevy if (unlikely(!p)) 5000c0eae66eSBenny Halevy goto out_overflow; 5001cccddf4fSBenny Halevy len = be32_to_cpup(p); 5002c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5003c0eae66eSBenny Halevy if (unlikely(!p)) 5004c0eae66eSBenny Halevy goto out_overflow; 50051da177e4SLinus Torvalds 50061da177e4SLinus Torvalds /* skip uaddr string */ 5007c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5008c0eae66eSBenny Halevy if (unlikely(!p)) 5009c0eae66eSBenny Halevy goto out_overflow; 5010cccddf4fSBenny Halevy len = be32_to_cpup(p); 5011c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5012c0eae66eSBenny Halevy if (unlikely(!p)) 5013c0eae66eSBenny Halevy goto out_overflow; 50141da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 50151da177e4SLinus Torvalds } else 5016856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 50171da177e4SLinus Torvalds 50181da177e4SLinus Torvalds return 0; 5019c0eae66eSBenny Halevy out_overflow: 5020c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5021c0eae66eSBenny Halevy return -EIO; 50221da177e4SLinus Torvalds } 50231da177e4SLinus Torvalds 50241da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 50251da177e4SLinus Torvalds { 50261da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 50271da177e4SLinus Torvalds } 50281da177e4SLinus Torvalds 50291da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 50301da177e4SLinus Torvalds { 50318687b63aSAl Viro __be32 *p; 50321da177e4SLinus Torvalds int status; 50331da177e4SLinus Torvalds 50341da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 50351da177e4SLinus Torvalds if (status) 50361da177e4SLinus Torvalds return status; 50371da177e4SLinus Torvalds 5038c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 5039c0eae66eSBenny Halevy if (unlikely(!p)) 5040c0eae66eSBenny Halevy goto out_overflow; 50416f723f77SBenny Halevy res->count = be32_to_cpup(p++); 50426f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 5043cd93710eSChuck Lever memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE); 50441da177e4SLinus Torvalds return 0; 5045c0eae66eSBenny Halevy out_overflow: 5046c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5047c0eae66eSBenny Halevy return -EIO; 50481da177e4SLinus Torvalds } 50491da177e4SLinus Torvalds 50501da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 50511da177e4SLinus Torvalds { 50521da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 50531da177e4SLinus Torvalds } 50541da177e4SLinus Torvalds 50555a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor) 50565a5ea0d4SBryan Schumaker { 50575a5ea0d4SBryan Schumaker __be32 *p; 50585a5ea0d4SBryan Schumaker 50595a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 50605a5ea0d4SBryan Schumaker if (unlikely(!p)) 50615a5ea0d4SBryan Schumaker goto out_overflow; 50625a5ea0d4SBryan Schumaker flavor->gss.sec_oid4.len = be32_to_cpup(p); 50635a5ea0d4SBryan Schumaker if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN) 50645a5ea0d4SBryan Schumaker goto out_err; 50655a5ea0d4SBryan Schumaker 50665a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len); 50675a5ea0d4SBryan Schumaker if (unlikely(!p)) 50685a5ea0d4SBryan Schumaker goto out_overflow; 50695a5ea0d4SBryan Schumaker memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len); 50705a5ea0d4SBryan Schumaker 50715a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 50725a5ea0d4SBryan Schumaker if (unlikely(!p)) 50735a5ea0d4SBryan Schumaker goto out_overflow; 50745a5ea0d4SBryan Schumaker flavor->gss.qop4 = be32_to_cpup(p++); 50755a5ea0d4SBryan Schumaker flavor->gss.service = be32_to_cpup(p); 50765a5ea0d4SBryan Schumaker 50775a5ea0d4SBryan Schumaker return 0; 50785a5ea0d4SBryan Schumaker 50795a5ea0d4SBryan Schumaker out_overflow: 50805a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 50815a5ea0d4SBryan Schumaker return -EIO; 50825a5ea0d4SBryan Schumaker out_err: 50835a5ea0d4SBryan Schumaker return -EINVAL; 50845a5ea0d4SBryan Schumaker } 50855a5ea0d4SBryan Schumaker 50865a5ea0d4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 50875a5ea0d4SBryan Schumaker { 50885a5ea0d4SBryan Schumaker struct nfs4_secinfo_flavor *sec_flavor; 50895a5ea0d4SBryan Schumaker int status; 50905a5ea0d4SBryan Schumaker __be32 *p; 5091c3dfc280SBryan Schumaker int i, num_flavors; 50925a5ea0d4SBryan Schumaker 50935a5ea0d4SBryan Schumaker status = decode_op_hdr(xdr, OP_SECINFO); 5094613e901eSBryan Schumaker if (status) 5095613e901eSBryan Schumaker goto out; 50965a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 50975a5ea0d4SBryan Schumaker if (unlikely(!p)) 50985a5ea0d4SBryan Schumaker goto out_overflow; 50995a5ea0d4SBryan Schumaker 5100c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5101c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5102c3dfc280SBryan Schumaker 5103c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 51045a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5105c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 51065a5ea0d4SBryan Schumaker break; 51075a5ea0d4SBryan Schumaker 51085a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 51095a5ea0d4SBryan Schumaker if (unlikely(!p)) 51105a5ea0d4SBryan Schumaker goto out_overflow; 51115a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 51125a5ea0d4SBryan Schumaker 51135a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5114613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5115613e901eSBryan Schumaker if (status) 5116613e901eSBryan Schumaker goto out; 51175a5ea0d4SBryan Schumaker } 5118c3dfc280SBryan Schumaker res->flavors->num_flavors++; 51195a5ea0d4SBryan Schumaker } 51205a5ea0d4SBryan Schumaker 5121613e901eSBryan Schumaker out: 5122613e901eSBryan Schumaker return status; 51235a5ea0d4SBryan Schumaker out_overflow: 51245a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 51255a5ea0d4SBryan Schumaker return -EIO; 51265a5ea0d4SBryan Schumaker } 51275a5ea0d4SBryan Schumaker 512899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 512999fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 513099fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 513199fe60d0SBenny Halevy { 513299fe60d0SBenny Halevy __be32 *p; 513399fe60d0SBenny Halevy uint32_t dummy; 51342460ba57SBenny Halevy char *dummy_str; 513599fe60d0SBenny Halevy int status; 513699fe60d0SBenny Halevy struct nfs_client *clp = res->client; 51377d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 513899fe60d0SBenny Halevy 513999fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 514099fe60d0SBenny Halevy if (status) 514199fe60d0SBenny Halevy return status; 514299fe60d0SBenny Halevy 5143c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5144c0eae66eSBenny Halevy if (unlikely(!p)) 5145c0eae66eSBenny Halevy goto out_overflow; 5146114f64b5SAndy Adamson xdr_decode_hyper(p, &clp->cl_clientid); 5147c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5148c0eae66eSBenny Halevy if (unlikely(!p)) 5149c0eae66eSBenny Halevy goto out_overflow; 51506f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 51516f723f77SBenny Halevy clp->cl_exchange_flags = be32_to_cpup(p++); 515299fe60d0SBenny Halevy 515399fe60d0SBenny Halevy /* We ask for SP4_NONE */ 5154cccddf4fSBenny Halevy dummy = be32_to_cpup(p); 515599fe60d0SBenny Halevy if (dummy != SP4_NONE) 515699fe60d0SBenny Halevy return -EIO; 515799fe60d0SBenny Halevy 515899fe60d0SBenny Halevy /* Throw away minor_id */ 5159c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5160c0eae66eSBenny Halevy if (unlikely(!p)) 5161c0eae66eSBenny Halevy goto out_overflow; 516299fe60d0SBenny Halevy 516399fe60d0SBenny Halevy /* Throw away Major id */ 51642460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 51652460ba57SBenny Halevy if (unlikely(status)) 51662460ba57SBenny Halevy return status; 516799fe60d0SBenny Halevy 516878fe0f41SWeston Andros Adamson /* Save server_scope */ 51692460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 51702460ba57SBenny Halevy if (unlikely(status)) 51712460ba57SBenny Halevy return status; 517299fe60d0SBenny Halevy 517378fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 517478fe0f41SWeston Andros Adamson return -EIO; 517578fe0f41SWeston Andros Adamson 517678fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 517778fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 517878fe0f41SWeston Andros Adamson 51797d2ed9acSWeston Andros Adamson /* Implementation Id */ 51807d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 51817d2ed9acSWeston Andros Adamson if (unlikely(!p)) 51827d2ed9acSWeston Andros Adamson goto out_overflow; 51837d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 51847d2ed9acSWeston Andros Adamson 51857d2ed9acSWeston Andros Adamson if (impl_id_count) { 51867d2ed9acSWeston Andros Adamson /* nii_domain */ 51872460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 51882460ba57SBenny Halevy if (unlikely(status)) 51892460ba57SBenny Halevy return status; 51907d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 51917d2ed9acSWeston Andros Adamson return -EIO; 51927d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 519399fe60d0SBenny Halevy 51947d2ed9acSWeston Andros Adamson /* nii_name */ 51957d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 51967d2ed9acSWeston Andros Adamson if (unlikely(status)) 51977d2ed9acSWeston Andros Adamson return status; 51987d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 51997d2ed9acSWeston Andros Adamson return -EIO; 52007d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 52017d2ed9acSWeston Andros Adamson 52027d2ed9acSWeston Andros Adamson /* nii_date */ 52037d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 52047d2ed9acSWeston Andros Adamson if (unlikely(!p)) 52057d2ed9acSWeston Andros Adamson goto out_overflow; 52067d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 52077d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 52087d2ed9acSWeston Andros Adamson 52097d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 52107d2ed9acSWeston Andros Adamson } 521199fe60d0SBenny Halevy return 0; 5212c0eae66eSBenny Halevy out_overflow: 5213c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5214c0eae66eSBenny Halevy return -EIO; 521599fe60d0SBenny Halevy } 5216fc931582SAndy Adamson 5217fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5218fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5219fc931582SAndy Adamson { 5220fc931582SAndy Adamson __be32 *p; 5221c9c30dd5SBenny Halevy u32 nr_attrs, val; 5222fc931582SAndy Adamson 5223c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5224c0eae66eSBenny Halevy if (unlikely(!p)) 5225c0eae66eSBenny Halevy goto out_overflow; 5226c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5227c9c30dd5SBenny Halevy if (val) 5228c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 52296f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 52306f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 52316f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 52326f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 52336f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5234cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5235fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5236a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5237a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5238fc931582SAndy Adamson return -EINVAL; 5239fc931582SAndy Adamson } 5240c0eae66eSBenny Halevy if (nr_attrs == 1) { 5241c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5242c0eae66eSBenny Halevy if (unlikely(!p)) 5243c0eae66eSBenny Halevy goto out_overflow; 5244c0eae66eSBenny Halevy } 5245fc931582SAndy Adamson return 0; 5246c0eae66eSBenny Halevy out_overflow: 5247c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5248c0eae66eSBenny Halevy return -EIO; 5249fc931582SAndy Adamson } 5250fc931582SAndy Adamson 5251e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5252e78291e4SBenny Halevy { 5253e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5254fc931582SAndy Adamson } 5255fc931582SAndy Adamson 5256fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5257fc931582SAndy Adamson struct nfs41_create_session_res *res) 5258fc931582SAndy Adamson { 5259fc931582SAndy Adamson __be32 *p; 5260fc931582SAndy Adamson int status; 5261fc931582SAndy Adamson struct nfs_client *clp = res->client; 5262fc931582SAndy Adamson struct nfs4_session *session = clp->cl_session; 5263fc931582SAndy Adamson 5264fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5265e78291e4SBenny Halevy if (!status) 5266e78291e4SBenny Halevy status = decode_sessionid(xdr, &session->sess_id); 5267e78291e4SBenny Halevy if (unlikely(status)) 5268fc931582SAndy Adamson return status; 5269fc931582SAndy Adamson 5270fc931582SAndy Adamson /* seqid, flags */ 5271c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5272c0eae66eSBenny Halevy if (unlikely(!p)) 5273c0eae66eSBenny Halevy goto out_overflow; 52746f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 5275cccddf4fSBenny Halevy session->flags = be32_to_cpup(p); 5276fc931582SAndy Adamson 5277fc931582SAndy Adamson /* Channel attributes */ 5278fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->fc_attrs); 5279fc931582SAndy Adamson if (!status) 5280fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->bc_attrs); 5281fc931582SAndy Adamson return status; 5282c0eae66eSBenny Halevy out_overflow: 5283c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5284c0eae66eSBenny Halevy return -EIO; 5285fc931582SAndy Adamson } 52860f3e66c6SAndy Adamson 52870f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 52880f3e66c6SAndy Adamson { 52890f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 52900f3e66c6SAndy Adamson } 529118019753SRicardo Labiaga 529218019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 529318019753SRicardo Labiaga { 529418019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 529518019753SRicardo Labiaga } 529699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 529799fe60d0SBenny Halevy 52989b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 52999b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 53009b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 53019b7b9fccSAndy Adamson { 53029b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5303fc01cea9SAndy Adamson struct nfs4_sessionid id; 5304fc01cea9SAndy Adamson u32 dummy; 5305fc01cea9SAndy Adamson int status; 5306fc01cea9SAndy Adamson __be32 *p; 5307fc01cea9SAndy Adamson 53089b7b9fccSAndy Adamson if (!res->sr_session) 53099b7b9fccSAndy Adamson return 0; 53109b7b9fccSAndy Adamson 5311fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5312e78291e4SBenny Halevy if (!status) 5313e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5314e78291e4SBenny Halevy if (unlikely(status)) 5315fc01cea9SAndy Adamson goto out_err; 53169b7b9fccSAndy Adamson 5317fc01cea9SAndy Adamson /* 5318fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5319fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5320fc01cea9SAndy Adamson */ 5321fdcb4577STrond Myklebust status = -EREMOTEIO; 5322fc01cea9SAndy Adamson 5323fc01cea9SAndy Adamson if (memcmp(id.data, res->sr_session->sess_id.data, 5324fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5325fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5326fc01cea9SAndy Adamson goto out_err; 5327fc01cea9SAndy Adamson } 5328e78291e4SBenny Halevy 5329c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5330c0eae66eSBenny Halevy if (unlikely(!p)) 5331c0eae66eSBenny Halevy goto out_overflow; 5332e78291e4SBenny Halevy 5333fc01cea9SAndy Adamson /* seqid */ 53346f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5335dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5336fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5337fc01cea9SAndy Adamson goto out_err; 5338fc01cea9SAndy Adamson } 5339fc01cea9SAndy Adamson /* slot id */ 53406f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5341dfb4f309SBenny Halevy if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) { 5342fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5343fc01cea9SAndy Adamson goto out_err; 5344fc01cea9SAndy Adamson } 5345fc01cea9SAndy Adamson /* highest slot id - currently not processed */ 53466f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5347fc01cea9SAndy Adamson /* target highest slot id - currently not processed */ 53486f723f77SBenny Halevy dummy = be32_to_cpup(p++); 53490629e370SAlexandros Batsakis /* result flags */ 53500629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5351fc01cea9SAndy Adamson status = 0; 5352fc01cea9SAndy Adamson out_err: 5353fc01cea9SAndy Adamson res->sr_status = status; 5354fc01cea9SAndy Adamson return status; 5355c0eae66eSBenny Halevy out_overflow: 5356c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5357c0eae66eSBenny Halevy status = -EIO; 5358c0eae66eSBenny Halevy goto out_err; 5359fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 53609b7b9fccSAndy Adamson return 0; 5361fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 53629b7b9fccSAndy Adamson } 53639b7b9fccSAndy Adamson 5364b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 53657f11d8d3SAndy Adamson /* 53667f11d8d3SAndy Adamson * TODO: Need to handle case when EOF != true; 53677f11d8d3SAndy Adamson */ 53687f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr, 53697f11d8d3SAndy Adamson struct pnfs_devicelist *res) 53707f11d8d3SAndy Adamson { 53717f11d8d3SAndy Adamson __be32 *p; 53727f11d8d3SAndy Adamson int status, i; 53737f11d8d3SAndy Adamson struct nfs_writeverf verftemp; 53747f11d8d3SAndy Adamson 53757f11d8d3SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICELIST); 53767f11d8d3SAndy Adamson if (status) 53777f11d8d3SAndy Adamson return status; 53787f11d8d3SAndy Adamson 53797f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 8 + 8 + 4); 53807f11d8d3SAndy Adamson if (unlikely(!p)) 53817f11d8d3SAndy Adamson goto out_overflow; 53827f11d8d3SAndy Adamson 53837f11d8d3SAndy Adamson /* TODO: Skip cookie for now */ 53847f11d8d3SAndy Adamson p += 2; 53857f11d8d3SAndy Adamson 53867f11d8d3SAndy Adamson /* Read verifier */ 5387cd93710eSChuck Lever p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE); 53887f11d8d3SAndy Adamson 53897f11d8d3SAndy Adamson res->num_devs = be32_to_cpup(p); 53907f11d8d3SAndy Adamson 53917f11d8d3SAndy Adamson dprintk("%s: num_dev %d\n", __func__, res->num_devs); 53927f11d8d3SAndy Adamson 53937f11d8d3SAndy Adamson if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5394a030889aSWeston Andros Adamson printk(KERN_ERR "NFS: %s too many result dev_num %u\n", 53957f11d8d3SAndy Adamson __func__, res->num_devs); 53967f11d8d3SAndy Adamson return -EIO; 53977f11d8d3SAndy Adamson } 53987f11d8d3SAndy Adamson 53997f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 54007f11d8d3SAndy Adamson res->num_devs * NFS4_DEVICEID4_SIZE + 4); 54017f11d8d3SAndy Adamson if (unlikely(!p)) 54027f11d8d3SAndy Adamson goto out_overflow; 54037f11d8d3SAndy Adamson for (i = 0; i < res->num_devs; i++) 54047f11d8d3SAndy Adamson p = xdr_decode_opaque_fixed(p, res->dev_id[i].data, 54057f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE); 54067f11d8d3SAndy Adamson res->eof = be32_to_cpup(p); 54077f11d8d3SAndy Adamson return 0; 54087f11d8d3SAndy Adamson out_overflow: 54097f11d8d3SAndy Adamson print_overflow_msg(__func__, xdr); 54107f11d8d3SAndy Adamson return -EIO; 54117f11d8d3SAndy Adamson } 5412b1f69b75SAndy Adamson 5413b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 5414b1f69b75SAndy Adamson struct pnfs_device *pdev) 5415b1f69b75SAndy Adamson { 5416b1f69b75SAndy Adamson __be32 *p; 5417b1f69b75SAndy Adamson uint32_t len, type; 5418b1f69b75SAndy Adamson int status; 5419b1f69b75SAndy Adamson 5420b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5421b1f69b75SAndy Adamson if (status) { 5422b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5423b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5424b1f69b75SAndy Adamson if (unlikely(!p)) 5425b1f69b75SAndy Adamson goto out_overflow; 5426b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5427b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5428b1f69b75SAndy Adamson __func__, pdev->mincount); 5429b1f69b75SAndy Adamson } 5430b1f69b75SAndy Adamson return status; 5431b1f69b75SAndy Adamson } 5432b1f69b75SAndy Adamson 5433b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5434b1f69b75SAndy Adamson if (unlikely(!p)) 5435b1f69b75SAndy Adamson goto out_overflow; 5436b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5437b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5438b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5439b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5440b1f69b75SAndy Adamson return -EINVAL; 5441b1f69b75SAndy Adamson } 5442b1f69b75SAndy Adamson /* 5443b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5444b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5445b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5446b1f69b75SAndy Adamson */ 5447b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5448b1f69b75SAndy Adamson xdr_read_pages(xdr, pdev->mincount); /* include space for the length */ 5449b1f69b75SAndy Adamson 5450b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5451b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5452b1f69b75SAndy Adamson if (unlikely(!p)) 5453b1f69b75SAndy Adamson goto out_overflow; 5454b1f69b75SAndy Adamson len = be32_to_cpup(p); 5455b1f69b75SAndy Adamson if (len) { 5456ead00597SChuck Lever uint32_t i; 5457b1f69b75SAndy Adamson 5458b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5459b1f69b75SAndy Adamson if (unlikely(!p)) 5460b1f69b75SAndy Adamson goto out_overflow; 5461b1f69b75SAndy Adamson for (i = 0; i < len; i++, p++) { 5462b1f69b75SAndy Adamson if (be32_to_cpup(p)) { 5463b1f69b75SAndy Adamson dprintk("%s: notifications not supported\n", 5464b1f69b75SAndy Adamson __func__); 5465b1f69b75SAndy Adamson return -EIO; 5466b1f69b75SAndy Adamson } 5467b1f69b75SAndy Adamson } 5468b1f69b75SAndy Adamson } 5469b1f69b75SAndy Adamson return 0; 5470b1f69b75SAndy Adamson out_overflow: 5471b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5472b1f69b75SAndy Adamson return -EIO; 5473b1f69b75SAndy Adamson } 5474b1f69b75SAndy Adamson 5475b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5476b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5477b1f69b75SAndy Adamson { 5478b1f69b75SAndy Adamson __be32 *p; 5479b1f69b75SAndy Adamson int status; 5480b1f69b75SAndy Adamson u32 layout_count; 548135124a09SWeston Andros Adamson struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 548235124a09SWeston Andros Adamson struct kvec *iov = rcvbuf->head; 548335124a09SWeston Andros Adamson u32 hdrlen, recvd; 5484b1f69b75SAndy Adamson 5485b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5486b1f69b75SAndy Adamson if (status) 5487b1f69b75SAndy Adamson return status; 5488ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5489b1f69b75SAndy Adamson if (unlikely(!p)) 5490b1f69b75SAndy Adamson goto out_overflow; 5491ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 5492ea9d23f5STrond Myklebust decode_stateid(xdr, &res->stateid); 5493ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5494ea9d23f5STrond Myklebust if (unlikely(!p)) 5495ea9d23f5STrond Myklebust goto out_overflow; 5496b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5497b1f69b75SAndy Adamson if (!layout_count) { 5498b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5499b1f69b75SAndy Adamson __func__); 5500b1f69b75SAndy Adamson return -EINVAL; 5501b1f69b75SAndy Adamson } 5502b1f69b75SAndy Adamson 550335124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5504b1f69b75SAndy Adamson if (unlikely(!p)) 5505b1f69b75SAndy Adamson goto out_overflow; 5506b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5507b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5508b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5509b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 551035124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5511b1f69b75SAndy Adamson 5512b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5513b1f69b75SAndy Adamson __func__, 5514b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5515b1f69b75SAndy Adamson (unsigned long)res->range.length, 5516b1f69b75SAndy Adamson res->range.iomode, 5517b1f69b75SAndy Adamson res->type, 551835124a09SWeston Andros Adamson res->layoutp->len); 5519b1f69b75SAndy Adamson 552035124a09SWeston Andros Adamson hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 552135124a09SWeston Andros Adamson recvd = req->rq_rcv_buf.len - hdrlen; 552235124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 552335124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 552435124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 552535124a09SWeston Andros Adamson res->layoutp->len, recvd); 552635124a09SWeston Andros Adamson return -EINVAL; 552735124a09SWeston Andros Adamson } 552835124a09SWeston Andros Adamson 552935124a09SWeston Andros Adamson xdr_read_pages(xdr, res->layoutp->len); 5530b1f69b75SAndy Adamson 5531b1f69b75SAndy Adamson if (layout_count > 1) { 5532b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5533b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5534b1f69b75SAndy Adamson * the client may see a response that is less than the 5535b1f69b75SAndy Adamson * minimum it requested. 5536b1f69b75SAndy Adamson */ 5537b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5538b1f69b75SAndy Adamson __func__, layout_count); 5539b1f69b75SAndy Adamson } 5540b1f69b75SAndy Adamson 5541b1f69b75SAndy Adamson return 0; 5542b1f69b75SAndy Adamson out_overflow: 5543b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5544b1f69b75SAndy Adamson return -EIO; 5545b1f69b75SAndy Adamson } 5546863a3c6cSAndy Adamson 5547cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5548cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5549cbe82603SBenny Halevy { 5550cbe82603SBenny Halevy __be32 *p; 5551cbe82603SBenny Halevy int status; 5552cbe82603SBenny Halevy 5553cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5554cbe82603SBenny Halevy if (status) 5555cbe82603SBenny Halevy return status; 5556cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5557cbe82603SBenny Halevy if (unlikely(!p)) 5558cbe82603SBenny Halevy goto out_overflow; 5559cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5560cbe82603SBenny Halevy if (res->lrs_present) 5561cbe82603SBenny Halevy status = decode_stateid(xdr, &res->stateid); 5562cbe82603SBenny Halevy return status; 5563cbe82603SBenny Halevy out_overflow: 5564cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 5565cbe82603SBenny Halevy return -EIO; 5566cbe82603SBenny Halevy } 5567cbe82603SBenny Halevy 5568863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5569863a3c6cSAndy Adamson struct rpc_rqst *req, 5570863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5571863a3c6cSAndy Adamson { 5572863a3c6cSAndy Adamson __be32 *p; 5573863a3c6cSAndy Adamson __u32 sizechanged; 5574863a3c6cSAndy Adamson int status; 5575863a3c6cSAndy Adamson 5576863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5577db29c089SAndy Adamson res->status = status; 5578863a3c6cSAndy Adamson if (status) 5579863a3c6cSAndy Adamson return status; 5580863a3c6cSAndy Adamson 5581863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5582863a3c6cSAndy Adamson if (unlikely(!p)) 5583863a3c6cSAndy Adamson goto out_overflow; 5584863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5585863a3c6cSAndy Adamson 5586863a3c6cSAndy Adamson if (sizechanged) { 5587863a3c6cSAndy Adamson /* throw away new size */ 5588863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5589863a3c6cSAndy Adamson if (unlikely(!p)) 5590863a3c6cSAndy Adamson goto out_overflow; 5591863a3c6cSAndy Adamson } 5592863a3c6cSAndy Adamson return 0; 5593863a3c6cSAndy Adamson out_overflow: 5594863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 5595863a3c6cSAndy Adamson return -EIO; 5596863a3c6cSAndy Adamson } 55977d974794SBryan Schumaker 55987d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 55997d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 56007d974794SBryan Schumaker { 56017d974794SBryan Schumaker __be32 *p; 56027d974794SBryan Schumaker int status; 56037d974794SBryan Schumaker int num_res; 56047d974794SBryan Schumaker 56057d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 56067d974794SBryan Schumaker if (status) 56077d974794SBryan Schumaker return status; 56087d974794SBryan Schumaker 56097d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56107d974794SBryan Schumaker if (unlikely(!p)) 56117d974794SBryan Schumaker goto out_overflow; 56127d974794SBryan Schumaker num_res = be32_to_cpup(p++); 56137d974794SBryan Schumaker if (num_res != 1) 56147d974794SBryan Schumaker goto out; 56157d974794SBryan Schumaker 56167d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56177d974794SBryan Schumaker if (unlikely(!p)) 56187d974794SBryan Schumaker goto out_overflow; 56197d974794SBryan Schumaker res->status = be32_to_cpup(p++); 56201cab0652SBryan Schumaker 56211cab0652SBryan Schumaker return status; 56227d974794SBryan Schumaker out_overflow: 56237d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 56247d974794SBryan Schumaker out: 56257d974794SBryan Schumaker return -EIO; 56267d974794SBryan Schumaker } 56279aeda35fSBryan Schumaker 56289aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 56299aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 56309aeda35fSBryan Schumaker { 56319aeda35fSBryan Schumaker __be32 *p; 56329aeda35fSBryan Schumaker int status; 56339aeda35fSBryan Schumaker 56349aeda35fSBryan Schumaker status = decode_op_hdr(xdr, OP_FREE_STATEID); 56359aeda35fSBryan Schumaker if (status) 56369aeda35fSBryan Schumaker return status; 56379aeda35fSBryan Schumaker 56389aeda35fSBryan Schumaker p = xdr_inline_decode(xdr, 4); 56399aeda35fSBryan Schumaker if (unlikely(!p)) 56409aeda35fSBryan Schumaker goto out_overflow; 56419aeda35fSBryan Schumaker res->status = be32_to_cpup(p++); 56429aeda35fSBryan Schumaker return res->status; 56439aeda35fSBryan Schumaker out_overflow: 56449aeda35fSBryan Schumaker print_overflow_msg(__func__, xdr); 56459aeda35fSBryan Schumaker return -EIO; 56469aeda35fSBryan Schumaker } 5647b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 5648b1f69b75SAndy Adamson 56491da177e4SLinus Torvalds /* 565049c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 565149c2559eSBenny Halevy */ 565249c2559eSBenny Halevy 565349c2559eSBenny Halevy /* 56541da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 56551da177e4SLinus Torvalds */ 5656bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 5657bf269551SChuck Lever struct xdr_stream *xdr, 5658bf269551SChuck Lever struct nfs_closeres *res) 56591da177e4SLinus Torvalds { 56601da177e4SLinus Torvalds struct compound_hdr hdr; 56611da177e4SLinus Torvalds int status; 56621da177e4SLinus Torvalds 5663bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 56641da177e4SLinus Torvalds if (status) 56651da177e4SLinus Torvalds goto out; 5666bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 56679b7b9fccSAndy Adamson if (status) 56689b7b9fccSAndy Adamson goto out; 5669bf269551SChuck Lever status = decode_putfh(xdr); 56701da177e4SLinus Torvalds if (status) 56711da177e4SLinus Torvalds goto out; 5672bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 5673516a6af6STrond Myklebust if (status != 0) 5674516a6af6STrond Myklebust goto out; 56756926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 56761da177e4SLinus Torvalds out: 56771da177e4SLinus Torvalds return status; 56781da177e4SLinus Torvalds } 56791da177e4SLinus Torvalds 56801da177e4SLinus Torvalds /* 56811da177e4SLinus Torvalds * Decode ACCESS response 56821da177e4SLinus Torvalds */ 5683bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5684bf269551SChuck Lever struct nfs4_accessres *res) 56851da177e4SLinus Torvalds { 56861da177e4SLinus Torvalds struct compound_hdr hdr; 56871da177e4SLinus Torvalds int status; 56881da177e4SLinus Torvalds 5689bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 56909b7b9fccSAndy Adamson if (status) 56919b7b9fccSAndy Adamson goto out; 5692bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 56939b7b9fccSAndy Adamson if (status) 56941da177e4SLinus Torvalds goto out; 5695bf269551SChuck Lever status = decode_putfh(xdr); 569676b32999STrond Myklebust if (status != 0) 569776b32999STrond Myklebust goto out; 5698bf269551SChuck Lever status = decode_access(xdr, res); 569976b32999STrond Myklebust if (status != 0) 570076b32999STrond Myklebust goto out; 57016926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 57021da177e4SLinus Torvalds out: 57031da177e4SLinus Torvalds return status; 57041da177e4SLinus Torvalds } 57051da177e4SLinus Torvalds 57061da177e4SLinus Torvalds /* 57071da177e4SLinus Torvalds * Decode LOOKUP response 57081da177e4SLinus Torvalds */ 5709bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5710bf269551SChuck Lever struct nfs4_lookup_res *res) 57111da177e4SLinus Torvalds { 57121da177e4SLinus Torvalds struct compound_hdr hdr; 57131da177e4SLinus Torvalds int status; 57141da177e4SLinus Torvalds 5715bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57169b7b9fccSAndy Adamson if (status) 57179b7b9fccSAndy Adamson goto out; 5718bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57199b7b9fccSAndy Adamson if (status) 57201da177e4SLinus Torvalds goto out; 5721bf269551SChuck Lever status = decode_putfh(xdr); 5722bf269551SChuck Lever if (status) 57231da177e4SLinus Torvalds goto out; 5724bf269551SChuck Lever status = decode_lookup(xdr); 5725bf269551SChuck Lever if (status) 57261da177e4SLinus Torvalds goto out; 5727bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5728bf269551SChuck Lever if (status) 57291da177e4SLinus Torvalds goto out; 57306926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 57311da177e4SLinus Torvalds out: 57321da177e4SLinus Torvalds return status; 57331da177e4SLinus Torvalds } 57341da177e4SLinus Torvalds 57351da177e4SLinus Torvalds /* 57361da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 57371da177e4SLinus Torvalds */ 5738bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 5739bf269551SChuck Lever struct xdr_stream *xdr, 5740bf269551SChuck Lever struct nfs4_lookup_res *res) 57411da177e4SLinus Torvalds { 57421da177e4SLinus Torvalds struct compound_hdr hdr; 57431da177e4SLinus Torvalds int status; 57441da177e4SLinus Torvalds 5745bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57469b7b9fccSAndy Adamson if (status) 57479b7b9fccSAndy Adamson goto out; 5748bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57499b7b9fccSAndy Adamson if (status) 57501da177e4SLinus Torvalds goto out; 5751bf269551SChuck Lever status = decode_putrootfh(xdr); 5752bf269551SChuck Lever if (status) 57531da177e4SLinus Torvalds goto out; 5754bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5755bf269551SChuck Lever if (status == 0) 57566926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 57571da177e4SLinus Torvalds out: 57581da177e4SLinus Torvalds return status; 57591da177e4SLinus Torvalds } 57601da177e4SLinus Torvalds 57611da177e4SLinus Torvalds /* 57621da177e4SLinus Torvalds * Decode REMOVE response 57631da177e4SLinus Torvalds */ 5764bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5765bf269551SChuck Lever struct nfs_removeres *res) 57661da177e4SLinus Torvalds { 57671da177e4SLinus Torvalds struct compound_hdr hdr; 57681da177e4SLinus Torvalds int status; 57691da177e4SLinus Torvalds 5770bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57719b7b9fccSAndy Adamson if (status) 57729b7b9fccSAndy Adamson goto out; 5773bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57749b7b9fccSAndy Adamson if (status) 57751da177e4SLinus Torvalds goto out; 5776bf269551SChuck Lever status = decode_putfh(xdr); 5777bf269551SChuck Lever if (status) 577816e42959STrond Myklebust goto out; 5779bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 5780bf269551SChuck Lever if (status) 578116e42959STrond Myklebust goto out; 57826926afd1STrond Myklebust decode_getfattr(xdr, res->dir_attr, res->server); 57831da177e4SLinus Torvalds out: 57841da177e4SLinus Torvalds return status; 57851da177e4SLinus Torvalds } 57861da177e4SLinus Torvalds 57871da177e4SLinus Torvalds /* 57881da177e4SLinus Torvalds * Decode RENAME response 57891da177e4SLinus Torvalds */ 5790bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5791bf269551SChuck Lever struct nfs_renameres *res) 57921da177e4SLinus Torvalds { 57931da177e4SLinus Torvalds struct compound_hdr hdr; 57941da177e4SLinus Torvalds int status; 57951da177e4SLinus Torvalds 5796bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57979b7b9fccSAndy Adamson if (status) 57989b7b9fccSAndy Adamson goto out; 5799bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58009b7b9fccSAndy Adamson if (status) 58011da177e4SLinus Torvalds goto out; 5802bf269551SChuck Lever status = decode_putfh(xdr); 5803bf269551SChuck Lever if (status) 58041da177e4SLinus Torvalds goto out; 5805bf269551SChuck Lever status = decode_savefh(xdr); 5806bf269551SChuck Lever if (status) 58071da177e4SLinus Torvalds goto out; 5808bf269551SChuck Lever status = decode_putfh(xdr); 5809bf269551SChuck Lever if (status) 58101da177e4SLinus Torvalds goto out; 5811bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 5812bf269551SChuck Lever if (status) 58136caf2c82STrond Myklebust goto out; 58146caf2c82STrond Myklebust /* Current FH is target directory */ 58156926afd1STrond Myklebust if (decode_getfattr(xdr, res->new_fattr, res->server)) 58166caf2c82STrond Myklebust goto out; 5817bf269551SChuck Lever status = decode_restorefh(xdr); 5818bf269551SChuck Lever if (status) 58196caf2c82STrond Myklebust goto out; 58206926afd1STrond Myklebust decode_getfattr(xdr, res->old_fattr, res->server); 58211da177e4SLinus Torvalds out: 58221da177e4SLinus Torvalds return status; 58231da177e4SLinus Torvalds } 58241da177e4SLinus Torvalds 58251da177e4SLinus Torvalds /* 58261da177e4SLinus Torvalds * Decode LINK response 58271da177e4SLinus Torvalds */ 5828bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5829bf269551SChuck Lever struct nfs4_link_res *res) 58301da177e4SLinus Torvalds { 58311da177e4SLinus Torvalds struct compound_hdr hdr; 58321da177e4SLinus Torvalds int status; 58331da177e4SLinus Torvalds 5834bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58359b7b9fccSAndy Adamson if (status) 58369b7b9fccSAndy Adamson goto out; 5837bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58389b7b9fccSAndy Adamson if (status) 58391da177e4SLinus Torvalds goto out; 5840bf269551SChuck Lever status = decode_putfh(xdr); 5841bf269551SChuck Lever if (status) 58421da177e4SLinus Torvalds goto out; 5843bf269551SChuck Lever status = decode_savefh(xdr); 5844bf269551SChuck Lever if (status) 58451da177e4SLinus Torvalds goto out; 5846bf269551SChuck Lever status = decode_putfh(xdr); 5847bf269551SChuck Lever if (status) 58481da177e4SLinus Torvalds goto out; 5849bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 5850bf269551SChuck Lever if (status) 585191ba2eeeSTrond Myklebust goto out; 585291ba2eeeSTrond Myklebust /* 585391ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 585491ba2eeeSTrond Myklebust * filehandle. 585591ba2eeeSTrond Myklebust */ 58566926afd1STrond Myklebust if (decode_getfattr(xdr, res->dir_attr, res->server)) 585791ba2eeeSTrond Myklebust goto out; 5858bf269551SChuck Lever status = decode_restorefh(xdr); 5859bf269551SChuck Lever if (status) 586091ba2eeeSTrond Myklebust goto out; 58616926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 58621da177e4SLinus Torvalds out: 58631da177e4SLinus Torvalds return status; 58641da177e4SLinus Torvalds } 58651da177e4SLinus Torvalds 58661da177e4SLinus Torvalds /* 58671da177e4SLinus Torvalds * Decode CREATE response 58681da177e4SLinus Torvalds */ 5869bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5870bf269551SChuck Lever struct nfs4_create_res *res) 58711da177e4SLinus Torvalds { 58721da177e4SLinus Torvalds struct compound_hdr hdr; 58731da177e4SLinus Torvalds int status; 58741da177e4SLinus Torvalds 5875bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58769b7b9fccSAndy Adamson if (status) 58779b7b9fccSAndy Adamson goto out; 5878bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58799b7b9fccSAndy Adamson if (status) 58801da177e4SLinus Torvalds goto out; 5881bf269551SChuck Lever status = decode_putfh(xdr); 5882bf269551SChuck Lever if (status) 58831da177e4SLinus Torvalds goto out; 5884bf269551SChuck Lever status = decode_savefh(xdr); 5885bf269551SChuck Lever if (status) 588656ae19f3STrond Myklebust goto out; 5887bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 5888bf269551SChuck Lever if (status) 58891da177e4SLinus Torvalds goto out; 5890bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5891bf269551SChuck Lever if (status) 58921da177e4SLinus Torvalds goto out; 58936926afd1STrond Myklebust if (decode_getfattr(xdr, res->fattr, res->server)) 589456ae19f3STrond Myklebust goto out; 5895bf269551SChuck Lever status = decode_restorefh(xdr); 5896bf269551SChuck Lever if (status) 589756ae19f3STrond Myklebust goto out; 58986926afd1STrond Myklebust decode_getfattr(xdr, res->dir_fattr, res->server); 58991da177e4SLinus Torvalds out: 59001da177e4SLinus Torvalds return status; 59011da177e4SLinus Torvalds } 59021da177e4SLinus Torvalds 59031da177e4SLinus Torvalds /* 59041da177e4SLinus Torvalds * Decode SYMLINK response 59051da177e4SLinus Torvalds */ 5906bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5907bf269551SChuck Lever struct nfs4_create_res *res) 59081da177e4SLinus Torvalds { 5909bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 59101da177e4SLinus Torvalds } 59111da177e4SLinus Torvalds 59121da177e4SLinus Torvalds /* 59131da177e4SLinus Torvalds * Decode GETATTR response 59141da177e4SLinus Torvalds */ 5915bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5916bf269551SChuck Lever struct nfs4_getattr_res *res) 59171da177e4SLinus Torvalds { 59181da177e4SLinus Torvalds struct compound_hdr hdr; 59191da177e4SLinus Torvalds int status; 59201da177e4SLinus Torvalds 5921bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59221da177e4SLinus Torvalds if (status) 59231da177e4SLinus Torvalds goto out; 5924bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59259b7b9fccSAndy Adamson if (status) 59269b7b9fccSAndy Adamson goto out; 5927bf269551SChuck Lever status = decode_putfh(xdr); 59281da177e4SLinus Torvalds if (status) 59291da177e4SLinus Torvalds goto out; 59306926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 59311da177e4SLinus Torvalds out: 59321da177e4SLinus Torvalds return status; 59331da177e4SLinus Torvalds } 59341da177e4SLinus Torvalds 593523ec6965SJ. Bruce Fields /* 593623ec6965SJ. Bruce Fields * Encode an SETACL request 593723ec6965SJ. Bruce Fields */ 59389f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 59399f06c719SChuck Lever struct nfs_setaclargs *args) 594023ec6965SJ. Bruce Fields { 594123ec6965SJ. Bruce Fields struct compound_hdr hdr = { 594266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 594323ec6965SJ. Bruce Fields }; 594423ec6965SJ. Bruce Fields 59459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 59469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 59479f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 59489f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 5949d017931cSAndy Adamson encode_nops(&hdr); 595023ec6965SJ. Bruce Fields } 595105d564feSAndy Adamson 595223ec6965SJ. Bruce Fields /* 595323ec6965SJ. Bruce Fields * Decode SETACL response 595423ec6965SJ. Bruce Fields */ 595523ec6965SJ. Bruce Fields static int 5956bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 595773c403a9SBenny Halevy struct nfs_setaclres *res) 595823ec6965SJ. Bruce Fields { 595923ec6965SJ. Bruce Fields struct compound_hdr hdr; 596023ec6965SJ. Bruce Fields int status; 596123ec6965SJ. Bruce Fields 5962bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 596323ec6965SJ. Bruce Fields if (status) 596423ec6965SJ. Bruce Fields goto out; 5965bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59669b7b9fccSAndy Adamson if (status) 59679b7b9fccSAndy Adamson goto out; 5968bf269551SChuck Lever status = decode_putfh(xdr); 596923ec6965SJ. Bruce Fields if (status) 597023ec6965SJ. Bruce Fields goto out; 5971bf269551SChuck Lever status = decode_setattr(xdr); 597223ec6965SJ. Bruce Fields out: 597323ec6965SJ. Bruce Fields return status; 597423ec6965SJ. Bruce Fields } 59751da177e4SLinus Torvalds 59761da177e4SLinus Torvalds /* 5977029d105eSJ. Bruce Fields * Decode GETACL response 5978029d105eSJ. Bruce Fields */ 5979029d105eSJ. Bruce Fields static int 5980bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5981663c79b3SBenny Halevy struct nfs_getaclres *res) 5982029d105eSJ. Bruce Fields { 5983029d105eSJ. Bruce Fields struct compound_hdr hdr; 5984029d105eSJ. Bruce Fields int status; 5985029d105eSJ. Bruce Fields 5986331818f1STrond Myklebust if (res->acl_scratch != NULL) { 5987331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 5988331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 5989331818f1STrond Myklebust } 5990bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 5991029d105eSJ. Bruce Fields if (status) 5992029d105eSJ. Bruce Fields goto out; 5993bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59949b7b9fccSAndy Adamson if (status) 59959b7b9fccSAndy Adamson goto out; 5996bf269551SChuck Lever status = decode_putfh(xdr); 5997029d105eSJ. Bruce Fields if (status) 5998029d105eSJ. Bruce Fields goto out; 5999bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6000029d105eSJ. Bruce Fields 6001029d105eSJ. Bruce Fields out: 6002029d105eSJ. Bruce Fields return status; 6003029d105eSJ. Bruce Fields } 6004029d105eSJ. Bruce Fields 6005029d105eSJ. Bruce Fields /* 60061da177e4SLinus Torvalds * Decode CLOSE response 60071da177e4SLinus Torvalds */ 6008bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6009bf269551SChuck Lever struct nfs_closeres *res) 60101da177e4SLinus Torvalds { 60111da177e4SLinus Torvalds struct compound_hdr hdr; 60121da177e4SLinus Torvalds int status; 60131da177e4SLinus Torvalds 6014bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60151da177e4SLinus Torvalds if (status) 60161da177e4SLinus Torvalds goto out; 6017bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60189b7b9fccSAndy Adamson if (status) 60199b7b9fccSAndy Adamson goto out; 6020bf269551SChuck Lever status = decode_putfh(xdr); 60211da177e4SLinus Torvalds if (status) 60221da177e4SLinus Torvalds goto out; 6023bf269551SChuck Lever status = decode_close(xdr, res); 6024516a6af6STrond Myklebust if (status != 0) 6025516a6af6STrond Myklebust goto out; 6026516a6af6STrond Myklebust /* 6027516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6028516a6af6STrond Myklebust * in which case the getattr call will fail with 6029516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6030516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6031516a6af6STrond Myklebust */ 60326926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60331da177e4SLinus Torvalds out: 60341da177e4SLinus Torvalds return status; 60351da177e4SLinus Torvalds } 60361da177e4SLinus Torvalds 60371da177e4SLinus Torvalds /* 60381da177e4SLinus Torvalds * Decode OPEN response 60391da177e4SLinus Torvalds */ 6040bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6041bf269551SChuck Lever struct nfs_openres *res) 60421da177e4SLinus Torvalds { 60431da177e4SLinus Torvalds struct compound_hdr hdr; 60441da177e4SLinus Torvalds int status; 60451da177e4SLinus Torvalds 6046bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60471da177e4SLinus Torvalds if (status) 60481da177e4SLinus Torvalds goto out; 6049bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60509b7b9fccSAndy Adamson if (status) 60519b7b9fccSAndy Adamson goto out; 6052bf269551SChuck Lever status = decode_putfh(xdr); 60531da177e4SLinus Torvalds if (status) 60541da177e4SLinus Torvalds goto out; 6055bf269551SChuck Lever status = decode_savefh(xdr); 605656ae19f3STrond Myklebust if (status) 605756ae19f3STrond Myklebust goto out; 6058bf269551SChuck Lever status = decode_open(xdr, res); 60591da177e4SLinus Torvalds if (status) 60601da177e4SLinus Torvalds goto out; 6061bf269551SChuck Lever if (decode_getfh(xdr, &res->fh) != 0) 60621da177e4SLinus Torvalds goto out; 60636926afd1STrond Myklebust if (decode_getfattr(xdr, res->f_attr, res->server) != 0) 606456ae19f3STrond Myklebust goto out; 6065bf269551SChuck Lever if (decode_restorefh(xdr) != 0) 606656ae19f3STrond Myklebust goto out; 60676926afd1STrond Myklebust decode_getfattr(xdr, res->dir_attr, res->server); 60681da177e4SLinus Torvalds out: 60691da177e4SLinus Torvalds return status; 60701da177e4SLinus Torvalds } 60711da177e4SLinus Torvalds 60721da177e4SLinus Torvalds /* 60731da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 60741da177e4SLinus Torvalds */ 6075bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6076bf269551SChuck Lever struct xdr_stream *xdr, 6077bf269551SChuck Lever struct nfs_open_confirmres *res) 60781da177e4SLinus Torvalds { 60791da177e4SLinus Torvalds struct compound_hdr hdr; 60801da177e4SLinus Torvalds int status; 60811da177e4SLinus Torvalds 6082bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60831da177e4SLinus Torvalds if (status) 60841da177e4SLinus Torvalds goto out; 6085bf269551SChuck Lever status = decode_putfh(xdr); 60861da177e4SLinus Torvalds if (status) 60871da177e4SLinus Torvalds goto out; 6088bf269551SChuck Lever status = decode_open_confirm(xdr, res); 60891da177e4SLinus Torvalds out: 60901da177e4SLinus Torvalds return status; 60911da177e4SLinus Torvalds } 60921da177e4SLinus Torvalds 60931da177e4SLinus Torvalds /* 60941da177e4SLinus Torvalds * Decode OPEN response 60951da177e4SLinus Torvalds */ 6096bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6097bf269551SChuck Lever struct xdr_stream *xdr, 6098bf269551SChuck Lever struct nfs_openres *res) 60991da177e4SLinus Torvalds { 61001da177e4SLinus Torvalds struct compound_hdr hdr; 61011da177e4SLinus Torvalds int status; 61021da177e4SLinus Torvalds 6103bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61041da177e4SLinus Torvalds if (status) 61051da177e4SLinus Torvalds goto out; 6106bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61079b7b9fccSAndy Adamson if (status) 61089b7b9fccSAndy Adamson goto out; 6109bf269551SChuck Lever status = decode_putfh(xdr); 61101da177e4SLinus Torvalds if (status) 61111da177e4SLinus Torvalds goto out; 6112bf269551SChuck Lever status = decode_open(xdr, res); 6113864472e9STrond Myklebust if (status) 6114864472e9STrond Myklebust goto out; 61156926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 61161da177e4SLinus Torvalds out: 61171da177e4SLinus Torvalds return status; 61181da177e4SLinus Torvalds } 61191da177e4SLinus Torvalds 61201da177e4SLinus Torvalds /* 61211da177e4SLinus Torvalds * Decode SETATTR response 61221da177e4SLinus Torvalds */ 6123bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6124bf269551SChuck Lever struct xdr_stream *xdr, 6125bf269551SChuck Lever struct nfs_setattrres *res) 61261da177e4SLinus Torvalds { 61271da177e4SLinus Torvalds struct compound_hdr hdr; 61281da177e4SLinus Torvalds int status; 61291da177e4SLinus Torvalds 6130bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61311da177e4SLinus Torvalds if (status) 61321da177e4SLinus Torvalds goto out; 6133bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61349b7b9fccSAndy Adamson if (status) 61359b7b9fccSAndy Adamson goto out; 6136bf269551SChuck Lever status = decode_putfh(xdr); 61371da177e4SLinus Torvalds if (status) 61381da177e4SLinus Torvalds goto out; 6139bf269551SChuck Lever status = decode_setattr(xdr); 61401da177e4SLinus Torvalds if (status) 61411da177e4SLinus Torvalds goto out; 61426926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 61431da177e4SLinus Torvalds out: 61441da177e4SLinus Torvalds return status; 61451da177e4SLinus Torvalds } 61461da177e4SLinus Torvalds 61471da177e4SLinus Torvalds /* 61481da177e4SLinus Torvalds * Decode LOCK response 61491da177e4SLinus Torvalds */ 6150bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6151bf269551SChuck Lever struct nfs_lock_res *res) 61521da177e4SLinus Torvalds { 61531da177e4SLinus Torvalds struct compound_hdr hdr; 61541da177e4SLinus Torvalds int status; 61551da177e4SLinus Torvalds 6156bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61571da177e4SLinus Torvalds if (status) 61581da177e4SLinus Torvalds goto out; 6159bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61609b7b9fccSAndy Adamson if (status) 61619b7b9fccSAndy Adamson goto out; 6162bf269551SChuck Lever status = decode_putfh(xdr); 61631da177e4SLinus Torvalds if (status) 61641da177e4SLinus Torvalds goto out; 6165bf269551SChuck Lever status = decode_lock(xdr, res); 61661da177e4SLinus Torvalds out: 61671da177e4SLinus Torvalds return status; 61681da177e4SLinus Torvalds } 61691da177e4SLinus Torvalds 61701da177e4SLinus Torvalds /* 61711da177e4SLinus Torvalds * Decode LOCKT response 61721da177e4SLinus Torvalds */ 6173bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6174bf269551SChuck Lever struct nfs_lockt_res *res) 61751da177e4SLinus Torvalds { 61761da177e4SLinus Torvalds struct compound_hdr hdr; 61771da177e4SLinus Torvalds int status; 61781da177e4SLinus Torvalds 6179bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61801da177e4SLinus Torvalds if (status) 61811da177e4SLinus Torvalds goto out; 6182bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61839b7b9fccSAndy Adamson if (status) 61849b7b9fccSAndy Adamson goto out; 6185bf269551SChuck Lever status = decode_putfh(xdr); 61861da177e4SLinus Torvalds if (status) 61871da177e4SLinus Torvalds goto out; 6188bf269551SChuck Lever status = decode_lockt(xdr, res); 61891da177e4SLinus Torvalds out: 61901da177e4SLinus Torvalds return status; 61911da177e4SLinus Torvalds } 61921da177e4SLinus Torvalds 61931da177e4SLinus Torvalds /* 61941da177e4SLinus Torvalds * Decode LOCKU response 61951da177e4SLinus Torvalds */ 6196bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6197bf269551SChuck Lever struct nfs_locku_res *res) 61981da177e4SLinus Torvalds { 61991da177e4SLinus Torvalds struct compound_hdr hdr; 62001da177e4SLinus Torvalds int status; 62011da177e4SLinus Torvalds 6202bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62031da177e4SLinus Torvalds if (status) 62041da177e4SLinus Torvalds goto out; 6205bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62069b7b9fccSAndy Adamson if (status) 62079b7b9fccSAndy Adamson goto out; 6208bf269551SChuck Lever status = decode_putfh(xdr); 62091da177e4SLinus Torvalds if (status) 62101da177e4SLinus Torvalds goto out; 6211bf269551SChuck Lever status = decode_locku(xdr, res); 62121da177e4SLinus Torvalds out: 62131da177e4SLinus Torvalds return status; 62141da177e4SLinus Torvalds } 62151da177e4SLinus Torvalds 6216bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6217bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6218d3c7b7ccSTrond Myklebust { 6219d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6220d3c7b7ccSTrond Myklebust int status; 6221d3c7b7ccSTrond Myklebust 6222bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6223d3c7b7ccSTrond Myklebust if (!status) 6224bf269551SChuck Lever status = decode_release_lockowner(xdr); 6225d3c7b7ccSTrond Myklebust return status; 6226d3c7b7ccSTrond Myklebust } 6227d3c7b7ccSTrond Myklebust 62281da177e4SLinus Torvalds /* 62291da177e4SLinus Torvalds * Decode READLINK response 62301da177e4SLinus Torvalds */ 6231bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6232bf269551SChuck Lever struct xdr_stream *xdr, 6233f50c7000SBenny Halevy struct nfs4_readlink_res *res) 62341da177e4SLinus Torvalds { 62351da177e4SLinus Torvalds struct compound_hdr hdr; 62361da177e4SLinus Torvalds int status; 62371da177e4SLinus Torvalds 6238bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62391da177e4SLinus Torvalds if (status) 62401da177e4SLinus Torvalds goto out; 6241bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62429b7b9fccSAndy Adamson if (status) 62439b7b9fccSAndy Adamson goto out; 6244bf269551SChuck Lever status = decode_putfh(xdr); 62451da177e4SLinus Torvalds if (status) 62461da177e4SLinus Torvalds goto out; 6247bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 62481da177e4SLinus Torvalds out: 62491da177e4SLinus Torvalds return status; 62501da177e4SLinus Torvalds } 62511da177e4SLinus Torvalds 62521da177e4SLinus Torvalds /* 62531da177e4SLinus Torvalds * Decode READDIR response 62541da177e4SLinus Torvalds */ 6255bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6256bf269551SChuck Lever struct nfs4_readdir_res *res) 62571da177e4SLinus Torvalds { 62581da177e4SLinus Torvalds struct compound_hdr hdr; 62591da177e4SLinus Torvalds int status; 62601da177e4SLinus Torvalds 6261bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62621da177e4SLinus Torvalds if (status) 62631da177e4SLinus Torvalds goto out; 6264bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62659b7b9fccSAndy Adamson if (status) 62669b7b9fccSAndy Adamson goto out; 6267bf269551SChuck Lever status = decode_putfh(xdr); 62681da177e4SLinus Torvalds if (status) 62691da177e4SLinus Torvalds goto out; 6270bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 62711da177e4SLinus Torvalds out: 62721da177e4SLinus Torvalds return status; 62731da177e4SLinus Torvalds } 62741da177e4SLinus Torvalds 62751da177e4SLinus Torvalds /* 62761da177e4SLinus Torvalds * Decode Read response 62771da177e4SLinus Torvalds */ 6278bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6279bf269551SChuck Lever struct nfs_readres *res) 62801da177e4SLinus Torvalds { 62811da177e4SLinus Torvalds struct compound_hdr hdr; 62821da177e4SLinus Torvalds int status; 62831da177e4SLinus Torvalds 6284bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62851da177e4SLinus Torvalds if (status) 62861da177e4SLinus Torvalds goto out; 6287bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62889b7b9fccSAndy Adamson if (status) 62899b7b9fccSAndy Adamson goto out; 6290bf269551SChuck Lever status = decode_putfh(xdr); 62911da177e4SLinus Torvalds if (status) 62921da177e4SLinus Torvalds goto out; 6293bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 62941da177e4SLinus Torvalds if (!status) 62951da177e4SLinus Torvalds status = res->count; 62961da177e4SLinus Torvalds out: 62971da177e4SLinus Torvalds return status; 62981da177e4SLinus Torvalds } 62991da177e4SLinus Torvalds 63001da177e4SLinus Torvalds /* 63011da177e4SLinus Torvalds * Decode WRITE response 63021da177e4SLinus Torvalds */ 6303bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6304bf269551SChuck Lever struct nfs_writeres *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_write(xdr, res); 63194f9838c7STrond Myklebust if (status) 63204f9838c7STrond Myklebust goto out; 63217ffd1064SFred Isaman if (res->fattr) 63226926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63231da177e4SLinus Torvalds if (!status) 63241da177e4SLinus Torvalds status = res->count; 63251da177e4SLinus Torvalds out: 63261da177e4SLinus Torvalds return status; 63271da177e4SLinus Torvalds } 63281da177e4SLinus Torvalds 63291da177e4SLinus Torvalds /* 63301da177e4SLinus Torvalds * Decode COMMIT response 63311da177e4SLinus Torvalds */ 6332bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6333bf269551SChuck Lever struct nfs_writeres *res) 63341da177e4SLinus Torvalds { 63351da177e4SLinus Torvalds struct compound_hdr hdr; 63361da177e4SLinus Torvalds int status; 63371da177e4SLinus Torvalds 6338bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63391da177e4SLinus Torvalds if (status) 63401da177e4SLinus Torvalds goto out; 6341bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63429b7b9fccSAndy Adamson if (status) 63439b7b9fccSAndy Adamson goto out; 6344bf269551SChuck Lever status = decode_putfh(xdr); 63451da177e4SLinus Torvalds if (status) 63461da177e4SLinus Torvalds goto out; 6347bf269551SChuck Lever status = decode_commit(xdr, res); 63484f9838c7STrond Myklebust if (status) 63494f9838c7STrond Myklebust goto out; 6350988b6dceSFred Isaman if (res->fattr) 63516926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63521da177e4SLinus Torvalds out: 63531da177e4SLinus Torvalds return status; 63541da177e4SLinus Torvalds } 63551da177e4SLinus Torvalds 63561da177e4SLinus Torvalds /* 63578b173218SRicardo Labiaga * Decode FSINFO response 63581da177e4SLinus Torvalds */ 6359bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 63603dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 63611da177e4SLinus Torvalds { 63621da177e4SLinus Torvalds struct compound_hdr hdr; 63631da177e4SLinus Torvalds int status; 63641da177e4SLinus Torvalds 6365bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63661da177e4SLinus Torvalds if (!status) 6367bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 63689b7b9fccSAndy Adamson if (!status) 6369bf269551SChuck Lever status = decode_putfh(xdr); 63701da177e4SLinus Torvalds if (!status) 6371bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 63721da177e4SLinus Torvalds return status; 63731da177e4SLinus Torvalds } 63741da177e4SLinus Torvalds 63751da177e4SLinus Torvalds /* 63768b173218SRicardo Labiaga * Decode PATHCONF response 63771da177e4SLinus Torvalds */ 6378bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6379d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 63801da177e4SLinus Torvalds { 63811da177e4SLinus Torvalds struct compound_hdr hdr; 63821da177e4SLinus Torvalds int status; 63831da177e4SLinus Torvalds 6384bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63851da177e4SLinus Torvalds if (!status) 6386bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 63879b7b9fccSAndy Adamson if (!status) 6388bf269551SChuck Lever status = decode_putfh(xdr); 63891da177e4SLinus Torvalds if (!status) 6390bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 63911da177e4SLinus Torvalds return status; 63921da177e4SLinus Torvalds } 63931da177e4SLinus Torvalds 63941da177e4SLinus Torvalds /* 63958b173218SRicardo Labiaga * Decode STATFS response 63961da177e4SLinus Torvalds */ 6397bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 639824ad148aSBenny Halevy struct nfs4_statfs_res *res) 63991da177e4SLinus Torvalds { 64001da177e4SLinus Torvalds struct compound_hdr hdr; 64011da177e4SLinus Torvalds int status; 64021da177e4SLinus Torvalds 6403bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64041da177e4SLinus Torvalds if (!status) 6405bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64069b7b9fccSAndy Adamson if (!status) 6407bf269551SChuck Lever status = decode_putfh(xdr); 64081da177e4SLinus Torvalds if (!status) 6409bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 64101da177e4SLinus Torvalds return status; 64111da177e4SLinus Torvalds } 64121da177e4SLinus Torvalds 64131da177e4SLinus Torvalds /* 64148b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 64151da177e4SLinus Torvalds */ 6416bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6417bf269551SChuck Lever struct xdr_stream *xdr, 6418bf269551SChuck Lever struct nfs4_server_caps_res *res) 64191da177e4SLinus Torvalds { 64201da177e4SLinus Torvalds struct compound_hdr hdr; 64211da177e4SLinus Torvalds int status; 64221da177e4SLinus Torvalds 6423bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64249b7b9fccSAndy Adamson if (status) 64259b7b9fccSAndy Adamson goto out; 6426bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64279b7b9fccSAndy Adamson if (status) 64281da177e4SLinus Torvalds goto out; 6429bf269551SChuck Lever status = decode_putfh(xdr); 6430bf269551SChuck Lever if (status) 64311da177e4SLinus Torvalds goto out; 6432bf269551SChuck Lever status = decode_server_caps(xdr, res); 64331da177e4SLinus Torvalds out: 64341da177e4SLinus Torvalds return status; 64351da177e4SLinus Torvalds } 64361da177e4SLinus Torvalds 64371da177e4SLinus Torvalds /* 64381da177e4SLinus Torvalds * Decode RENEW response 64391da177e4SLinus Torvalds */ 6440bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6441bf269551SChuck Lever void *__unused) 64421da177e4SLinus Torvalds { 64431da177e4SLinus Torvalds struct compound_hdr hdr; 64441da177e4SLinus Torvalds int status; 64451da177e4SLinus Torvalds 6446bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64471da177e4SLinus Torvalds if (!status) 6448bf269551SChuck Lever status = decode_renew(xdr); 64491da177e4SLinus Torvalds return status; 64501da177e4SLinus Torvalds } 64511da177e4SLinus Torvalds 64521da177e4SLinus Torvalds /* 64538b173218SRicardo Labiaga * Decode SETCLIENTID response 64541da177e4SLinus Torvalds */ 6455bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6456bf269551SChuck Lever struct xdr_stream *xdr, 6457bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 64581da177e4SLinus Torvalds { 64591da177e4SLinus Torvalds struct compound_hdr hdr; 64601da177e4SLinus Torvalds int status; 64611da177e4SLinus Torvalds 6462bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64631da177e4SLinus Torvalds if (!status) 6464bf269551SChuck Lever status = decode_setclientid(xdr, res); 64651da177e4SLinus Torvalds return status; 64661da177e4SLinus Torvalds } 64671da177e4SLinus Torvalds 64681da177e4SLinus Torvalds /* 64698b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 64701da177e4SLinus Torvalds */ 6471bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 6472bf269551SChuck Lever struct xdr_stream *xdr, 6473bf269551SChuck Lever struct nfs_fsinfo *fsinfo) 64741da177e4SLinus Torvalds { 64751da177e4SLinus Torvalds struct compound_hdr hdr; 64761da177e4SLinus Torvalds int status; 64771da177e4SLinus Torvalds 6478bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64791da177e4SLinus Torvalds if (!status) 6480bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 64811da177e4SLinus Torvalds if (!status) 6482bf269551SChuck Lever status = decode_putrootfh(xdr); 64831da177e4SLinus Torvalds if (!status) 6484bf269551SChuck Lever status = decode_fsinfo(xdr, fsinfo); 64851da177e4SLinus Torvalds return status; 64861da177e4SLinus Torvalds } 64871da177e4SLinus Torvalds 64881da177e4SLinus Torvalds /* 64898b173218SRicardo Labiaga * Decode DELEGRETURN response 64901da177e4SLinus Torvalds */ 6491bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6492bf269551SChuck Lever struct xdr_stream *xdr, 6493bf269551SChuck Lever struct nfs4_delegreturnres *res) 64941da177e4SLinus Torvalds { 64951da177e4SLinus Torvalds struct compound_hdr hdr; 64961da177e4SLinus Torvalds int status; 64971da177e4SLinus Torvalds 6498bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64999b7b9fccSAndy Adamson if (status) 65009b7b9fccSAndy Adamson goto out; 6501bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65029b7b9fccSAndy Adamson if (status) 6503fa178f29STrond Myklebust goto out; 6504bf269551SChuck Lever status = decode_putfh(xdr); 6505fa178f29STrond Myklebust if (status != 0) 6506fa178f29STrond Myklebust goto out; 6507bf269551SChuck Lever status = decode_delegreturn(xdr); 6508556ae3bbSJeff Layton if (status != 0) 6509556ae3bbSJeff Layton goto out; 65106926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 6511fa178f29STrond Myklebust out: 65121da177e4SLinus Torvalds return status; 65131da177e4SLinus Torvalds } 65141da177e4SLinus Torvalds 6515683b57b4STrond Myklebust /* 65168b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6517683b57b4STrond Myklebust */ 6518bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6519bf269551SChuck Lever struct xdr_stream *xdr, 652022958463SBenny Halevy struct nfs4_fs_locations_res *res) 6521683b57b4STrond Myklebust { 6522683b57b4STrond Myklebust struct compound_hdr hdr; 6523683b57b4STrond Myklebust int status; 6524683b57b4STrond Myklebust 6525bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65269b7b9fccSAndy Adamson if (status) 65279b7b9fccSAndy Adamson goto out; 6528bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65299b7b9fccSAndy Adamson if (status) 6530683b57b4STrond Myklebust goto out; 6531bf269551SChuck Lever status = decode_putfh(xdr); 6532bf269551SChuck Lever if (status) 6533683b57b4STrond Myklebust goto out; 6534bf269551SChuck Lever status = decode_lookup(xdr); 6535bf269551SChuck Lever if (status) 6536683b57b4STrond Myklebust goto out; 6537bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 65388b7e3f49STrond Myklebust status = decode_getfattr_generic(xdr, &res->fs_locations->fattr, 65398b7e3f49STrond Myklebust NULL, res->fs_locations, 65406926afd1STrond Myklebust res->fs_locations->server); 6541683b57b4STrond Myklebust out: 6542683b57b4STrond Myklebust return status; 6543683b57b4STrond Myklebust } 6544683b57b4STrond Myklebust 65455a5ea0d4SBryan Schumaker /* 65465a5ea0d4SBryan Schumaker * Decode SECINFO response 65475a5ea0d4SBryan Schumaker */ 65485a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 65495a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 65505a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 65515a5ea0d4SBryan Schumaker { 65525a5ea0d4SBryan Schumaker struct compound_hdr hdr; 65535a5ea0d4SBryan Schumaker int status; 65545a5ea0d4SBryan Schumaker 65555a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 65565a5ea0d4SBryan Schumaker if (status) 65575a5ea0d4SBryan Schumaker goto out; 65585a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 65595a5ea0d4SBryan Schumaker if (status) 65605a5ea0d4SBryan Schumaker goto out; 65615a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 65625a5ea0d4SBryan Schumaker if (status) 65635a5ea0d4SBryan Schumaker goto out; 65645a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 65655a5ea0d4SBryan Schumaker out: 65665a5ea0d4SBryan Schumaker return status; 65675a5ea0d4SBryan Schumaker } 65685a5ea0d4SBryan Schumaker 656999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 657099fe60d0SBenny Halevy /* 65718b173218SRicardo Labiaga * Decode EXCHANGE_ID response 657299fe60d0SBenny Halevy */ 6573bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 6574bf269551SChuck Lever struct xdr_stream *xdr, 657599fe60d0SBenny Halevy void *res) 657699fe60d0SBenny Halevy { 657799fe60d0SBenny Halevy struct compound_hdr hdr; 657899fe60d0SBenny Halevy int status; 657999fe60d0SBenny Halevy 6580bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 658199fe60d0SBenny Halevy if (!status) 6582bf269551SChuck Lever status = decode_exchange_id(xdr, res); 658399fe60d0SBenny Halevy return status; 658499fe60d0SBenny Halevy } 65852050f0ccSAndy Adamson 65862050f0ccSAndy Adamson /* 65878b173218SRicardo Labiaga * Decode CREATE_SESSION response 6588fc931582SAndy Adamson */ 6589bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 6590bf269551SChuck Lever struct xdr_stream *xdr, 6591fc931582SAndy Adamson struct nfs41_create_session_res *res) 6592fc931582SAndy Adamson { 6593fc931582SAndy Adamson struct compound_hdr hdr; 6594fc931582SAndy Adamson int status; 6595fc931582SAndy Adamson 6596bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6597fc931582SAndy Adamson if (!status) 6598bf269551SChuck Lever status = decode_create_session(xdr, res); 6599fc931582SAndy Adamson return status; 6600fc931582SAndy Adamson } 6601fc931582SAndy Adamson 6602fc931582SAndy Adamson /* 66038b173218SRicardo Labiaga * Decode DESTROY_SESSION response 66040f3e66c6SAndy Adamson */ 6605bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 6606bf269551SChuck Lever struct xdr_stream *xdr, 6607bf269551SChuck Lever void *res) 66080f3e66c6SAndy Adamson { 66090f3e66c6SAndy Adamson struct compound_hdr hdr; 66100f3e66c6SAndy Adamson int status; 66110f3e66c6SAndy Adamson 6612bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66130f3e66c6SAndy Adamson if (!status) 6614bf269551SChuck Lever status = decode_destroy_session(xdr, res); 66150f3e66c6SAndy Adamson return status; 66160f3e66c6SAndy Adamson } 66170f3e66c6SAndy Adamson 66180f3e66c6SAndy Adamson /* 66198b173218SRicardo Labiaga * Decode SEQUENCE response 6620fc01cea9SAndy Adamson */ 6621bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 6622bf269551SChuck Lever struct xdr_stream *xdr, 6623fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 6624fc01cea9SAndy Adamson { 6625fc01cea9SAndy Adamson struct compound_hdr hdr; 6626fc01cea9SAndy Adamson int status; 6627fc01cea9SAndy Adamson 6628bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6629fc01cea9SAndy Adamson if (!status) 6630bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 6631fc01cea9SAndy Adamson return status; 6632fc01cea9SAndy Adamson } 6633fc01cea9SAndy Adamson 6634fc01cea9SAndy Adamson /* 66358b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 66362050f0ccSAndy Adamson */ 6637bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 6638bf269551SChuck Lever struct xdr_stream *xdr, 66392050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 66402050f0ccSAndy Adamson { 66412050f0ccSAndy Adamson struct compound_hdr hdr; 66422050f0ccSAndy Adamson int status; 66432050f0ccSAndy Adamson 6644bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66452050f0ccSAndy Adamson if (!status) 6646bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 66472050f0ccSAndy Adamson if (!status) 6648bf269551SChuck Lever status = decode_putrootfh(xdr); 66492050f0ccSAndy Adamson if (!status) 6650bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 66512050f0ccSAndy Adamson return status; 66522050f0ccSAndy Adamson } 665318019753SRicardo Labiaga 665418019753SRicardo Labiaga /* 665518019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 665618019753SRicardo Labiaga */ 6657bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 6658bf269551SChuck Lever struct xdr_stream *xdr, 665918019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 666018019753SRicardo Labiaga { 666118019753SRicardo Labiaga struct compound_hdr hdr; 666218019753SRicardo Labiaga int status; 666318019753SRicardo Labiaga 6664bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 666518019753SRicardo Labiaga if (!status) 6666bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 666718019753SRicardo Labiaga if (!status) 6668bf269551SChuck Lever status = decode_reclaim_complete(xdr, (void *)NULL); 666918019753SRicardo Labiaga return status; 667018019753SRicardo Labiaga } 6671b1f69b75SAndy Adamson 6672b1f69b75SAndy Adamson /* 66737f11d8d3SAndy Adamson * Decode GETDEVICELIST response 66747f11d8d3SAndy Adamson */ 66757f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp, 66767f11d8d3SAndy Adamson struct xdr_stream *xdr, 66777f11d8d3SAndy Adamson struct nfs4_getdevicelist_res *res) 66787f11d8d3SAndy Adamson { 66797f11d8d3SAndy Adamson struct compound_hdr hdr; 66807f11d8d3SAndy Adamson int status; 66817f11d8d3SAndy Adamson 66827f11d8d3SAndy Adamson dprintk("encoding getdevicelist!\n"); 66837f11d8d3SAndy Adamson 66847f11d8d3SAndy Adamson status = decode_compound_hdr(xdr, &hdr); 66857f11d8d3SAndy Adamson if (status != 0) 66867f11d8d3SAndy Adamson goto out; 66877f11d8d3SAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 66887f11d8d3SAndy Adamson if (status != 0) 66897f11d8d3SAndy Adamson goto out; 66907f11d8d3SAndy Adamson status = decode_putfh(xdr); 66917f11d8d3SAndy Adamson if (status != 0) 66927f11d8d3SAndy Adamson goto out; 66937f11d8d3SAndy Adamson status = decode_getdevicelist(xdr, res->devlist); 66947f11d8d3SAndy Adamson out: 66957f11d8d3SAndy Adamson return status; 66967f11d8d3SAndy Adamson } 66977f11d8d3SAndy Adamson 66987f11d8d3SAndy Adamson /* 6699b1f69b75SAndy Adamson * Decode GETDEVINFO response 6700b1f69b75SAndy Adamson */ 6701bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 6702bf269551SChuck Lever struct xdr_stream *xdr, 6703b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 6704b1f69b75SAndy Adamson { 6705b1f69b75SAndy Adamson struct compound_hdr hdr; 6706b1f69b75SAndy Adamson int status; 6707b1f69b75SAndy Adamson 6708bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6709b1f69b75SAndy Adamson if (status != 0) 6710b1f69b75SAndy Adamson goto out; 6711bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6712b1f69b75SAndy Adamson if (status != 0) 6713b1f69b75SAndy Adamson goto out; 6714bf269551SChuck Lever status = decode_getdeviceinfo(xdr, res->pdev); 6715b1f69b75SAndy Adamson out: 6716b1f69b75SAndy Adamson return status; 6717b1f69b75SAndy Adamson } 6718b1f69b75SAndy Adamson 6719b1f69b75SAndy Adamson /* 6720b1f69b75SAndy Adamson * Decode LAYOUTGET response 6721b1f69b75SAndy Adamson */ 6722bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 6723bf269551SChuck Lever struct xdr_stream *xdr, 6724b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6725b1f69b75SAndy Adamson { 6726b1f69b75SAndy Adamson struct compound_hdr hdr; 6727b1f69b75SAndy Adamson int status; 6728b1f69b75SAndy Adamson 6729bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6730b1f69b75SAndy Adamson if (status) 6731b1f69b75SAndy Adamson goto out; 6732bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6733b1f69b75SAndy Adamson if (status) 6734b1f69b75SAndy Adamson goto out; 6735bf269551SChuck Lever status = decode_putfh(xdr); 6736b1f69b75SAndy Adamson if (status) 6737b1f69b75SAndy Adamson goto out; 6738bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 6739b1f69b75SAndy Adamson out: 6740b1f69b75SAndy Adamson return status; 6741b1f69b75SAndy Adamson } 6742863a3c6cSAndy Adamson 6743863a3c6cSAndy Adamson /* 6744cbe82603SBenny Halevy * Decode LAYOUTRETURN response 6745cbe82603SBenny Halevy */ 6746cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 6747cbe82603SBenny Halevy struct xdr_stream *xdr, 6748cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6749cbe82603SBenny Halevy { 6750cbe82603SBenny Halevy struct compound_hdr hdr; 6751cbe82603SBenny Halevy int status; 6752cbe82603SBenny Halevy 6753cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 6754cbe82603SBenny Halevy if (status) 6755cbe82603SBenny Halevy goto out; 6756cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 6757cbe82603SBenny Halevy if (status) 6758cbe82603SBenny Halevy goto out; 6759cbe82603SBenny Halevy status = decode_putfh(xdr); 6760cbe82603SBenny Halevy if (status) 6761cbe82603SBenny Halevy goto out; 6762cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 6763cbe82603SBenny Halevy out: 6764cbe82603SBenny Halevy return status; 6765cbe82603SBenny Halevy } 6766cbe82603SBenny Halevy 6767cbe82603SBenny Halevy /* 6768863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 6769863a3c6cSAndy Adamson */ 6770863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 6771863a3c6cSAndy Adamson struct xdr_stream *xdr, 6772863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6773863a3c6cSAndy Adamson { 6774863a3c6cSAndy Adamson struct compound_hdr hdr; 6775863a3c6cSAndy Adamson int status; 6776863a3c6cSAndy Adamson 6777863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 6778863a3c6cSAndy Adamson if (status) 6779863a3c6cSAndy Adamson goto out; 6780863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 6781863a3c6cSAndy Adamson if (status) 6782863a3c6cSAndy Adamson goto out; 6783863a3c6cSAndy Adamson status = decode_putfh(xdr); 6784863a3c6cSAndy Adamson if (status) 6785863a3c6cSAndy Adamson goto out; 6786863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 6787863a3c6cSAndy Adamson if (status) 6788863a3c6cSAndy Adamson goto out; 67896926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 6790863a3c6cSAndy Adamson out: 6791863a3c6cSAndy Adamson return status; 6792863a3c6cSAndy Adamson } 6793fca78d6dSBryan Schumaker 6794fca78d6dSBryan Schumaker /* 6795fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 6796fca78d6dSBryan Schumaker */ 6797fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 6798fca78d6dSBryan Schumaker struct xdr_stream *xdr, 6799fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 6800fca78d6dSBryan Schumaker { 6801fca78d6dSBryan Schumaker struct compound_hdr hdr; 6802fca78d6dSBryan Schumaker int status; 6803fca78d6dSBryan Schumaker 6804fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 6805fca78d6dSBryan Schumaker if (status) 6806fca78d6dSBryan Schumaker goto out; 6807fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 6808fca78d6dSBryan Schumaker if (status) 6809fca78d6dSBryan Schumaker goto out; 6810fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 6811fca78d6dSBryan Schumaker if (status) 6812fca78d6dSBryan Schumaker goto out; 6813fca78d6dSBryan Schumaker status = decode_secinfo(xdr, res); 6814fca78d6dSBryan Schumaker out: 6815fca78d6dSBryan Schumaker return status; 6816fca78d6dSBryan Schumaker } 68177d974794SBryan Schumaker 68187d974794SBryan Schumaker /* 68197d974794SBryan Schumaker * Decode TEST_STATEID response 68207d974794SBryan Schumaker */ 68217d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 68227d974794SBryan Schumaker struct xdr_stream *xdr, 68237d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 68247d974794SBryan Schumaker { 68257d974794SBryan Schumaker struct compound_hdr hdr; 68267d974794SBryan Schumaker int status; 68277d974794SBryan Schumaker 68287d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 68297d974794SBryan Schumaker if (status) 68307d974794SBryan Schumaker goto out; 68317d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 68327d974794SBryan Schumaker if (status) 68337d974794SBryan Schumaker goto out; 68347d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 68357d974794SBryan Schumaker out: 68367d974794SBryan Schumaker return status; 68377d974794SBryan Schumaker } 68389aeda35fSBryan Schumaker 68399aeda35fSBryan Schumaker /* 68409aeda35fSBryan Schumaker * Decode FREE_STATEID response 68419aeda35fSBryan Schumaker */ 68429aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 68439aeda35fSBryan Schumaker struct xdr_stream *xdr, 68449aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 68459aeda35fSBryan Schumaker { 68469aeda35fSBryan Schumaker struct compound_hdr hdr; 68479aeda35fSBryan Schumaker int status; 68489aeda35fSBryan Schumaker 68499aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 68509aeda35fSBryan Schumaker if (status) 68519aeda35fSBryan Schumaker goto out; 68529aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 68539aeda35fSBryan Schumaker if (status) 68549aeda35fSBryan Schumaker goto out; 68559aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 68569aeda35fSBryan Schumaker out: 68579aeda35fSBryan Schumaker return status; 68589aeda35fSBryan Schumaker } 685999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 686099fe60d0SBenny Halevy 6861573c4e1eSChuck Lever /** 6862573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 6863573c4e1eSChuck Lever * the local page cache. 6864573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 6865573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 6866573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 6867573c4e1eSChuck Lever * 6868573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 6869573c4e1eSChuck Lever * returned. 6870573c4e1eSChuck Lever * 6871573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 6872573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 6873573c4e1eSChuck Lever * on a directory already in our cache. 6874573c4e1eSChuck Lever */ 6875573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 6876573c4e1eSChuck Lever int plus) 68771da177e4SLinus Torvalds { 6878dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 68791da177e4SLinus Torvalds uint32_t len; 6880babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 6881babddc72SBryan Schumaker if (unlikely(!p)) 6882babddc72SBryan Schumaker goto out_overflow; 6883c08e76d0SChuck Lever if (*p == xdr_zero) { 6884babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 6885babddc72SBryan Schumaker if (unlikely(!p)) 6886babddc72SBryan Schumaker goto out_overflow; 6887c08e76d0SChuck Lever if (*p == xdr_zero) 6888573c4e1eSChuck Lever return -EAGAIN; 68891da177e4SLinus Torvalds entry->eof = 1; 6890573c4e1eSChuck Lever return -EBADCOOKIE; 68911da177e4SLinus Torvalds } 68921da177e4SLinus Torvalds 6893babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 6894babddc72SBryan Schumaker if (unlikely(!p)) 6895babddc72SBryan Schumaker goto out_overflow; 68961da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 68971da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 6898c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 6899babddc72SBryan Schumaker 69009af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 6901babddc72SBryan Schumaker if (unlikely(!p)) 6902babddc72SBryan Schumaker goto out_overflow; 69031da177e4SLinus Torvalds entry->name = (const char *) p; 69041da177e4SLinus Torvalds 69051da177e4SLinus Torvalds /* 69061da177e4SLinus Torvalds * In case the server doesn't return an inode number, 69071da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 69081da177e4SLinus Torvalds * since glibc seems to choke on it...) 69091da177e4SLinus Torvalds */ 69101da177e4SLinus Torvalds entry->ino = 1; 69114f082222STrond Myklebust entry->fattr->valid = 0; 69121da177e4SLinus Torvalds 69139af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 6914babddc72SBryan Schumaker goto out_overflow; 69159af8c222STrond Myklebust 69169af8c222STrond Myklebust if (decode_attr_length(xdr, &len, &p) < 0) 6917babddc72SBryan Schumaker goto out_overflow; 69189af8c222STrond Myklebust 6919573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 69208b7e3f49STrond Myklebust NULL, entry->server) < 0) 6921babddc72SBryan Schumaker goto out_overflow; 692228331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 692328331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 692428331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 692582f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 69269af8c222STrond Myklebust 69270b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 69280b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 69290b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 69300b26a0bfSTrond Myklebust 6931573c4e1eSChuck Lever return 0; 6932babddc72SBryan Schumaker 6933babddc72SBryan Schumaker out_overflow: 6934babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 6935573c4e1eSChuck Lever return -EAGAIN; 69361da177e4SLinus Torvalds } 69371da177e4SLinus Torvalds 69381da177e4SLinus Torvalds /* 69391da177e4SLinus Torvalds * We need to translate between nfs status return values and 69401da177e4SLinus Torvalds * the local errno values which may not be the same. 69411da177e4SLinus Torvalds */ 69421da177e4SLinus Torvalds static struct { 69431da177e4SLinus Torvalds int stat; 69441da177e4SLinus Torvalds int errno; 69451da177e4SLinus Torvalds } nfs_errtbl[] = { 69461da177e4SLinus Torvalds { NFS4_OK, 0 }, 6947856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 6948856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 6949856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 6950856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 6951856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 6952856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 6953856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 6954856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 6955856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 6956856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 6957856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 6958856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 6959856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 6960856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 6961856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 6962856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 6963856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 6964856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 6965856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 6966856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 6967856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 6968856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 6969fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 6970856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 6971856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 6972856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 6973856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 6974856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 6975856dff3dSBenny Halevy { -1, -EIO } 69761da177e4SLinus Torvalds }; 69771da177e4SLinus Torvalds 69781da177e4SLinus Torvalds /* 69791da177e4SLinus Torvalds * Convert an NFS error code to a local one. 69801da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 69811da177e4SLinus Torvalds */ 69821da177e4SLinus Torvalds static int 69830a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 69841da177e4SLinus Torvalds { 69851da177e4SLinus Torvalds int i; 69861da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 69871da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 69881da177e4SLinus Torvalds return nfs_errtbl[i].errno; 69891da177e4SLinus Torvalds } 69901da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 69911da177e4SLinus Torvalds /* The server is looney tunes. */ 6992fdcb4577STrond Myklebust return -EREMOTEIO; 69931da177e4SLinus Torvalds } 69941da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 69951da177e4SLinus Torvalds * handle it. 69961da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 69971da177e4SLinus Torvalds * not conflict with native Linux error codes. 69981da177e4SLinus Torvalds */ 6999856dff3dSBenny Halevy return -stat; 70001da177e4SLinus Torvalds } 70011da177e4SLinus Torvalds 70021da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 70031da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 70041da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 70059f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7006bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 70072bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 70082bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7009cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7010cc0175c1SChuck Lever .p_name = #proc, \ 70111da177e4SLinus Torvalds } 70121da177e4SLinus Torvalds 70131da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 70141da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 70151da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 70161da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 70171da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 70181da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 70191da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 70201da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 70211da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 70221da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 70231da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 70241da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 70251da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 70261da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 70271da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 70281da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 70291da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 70301da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 70311da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 70321da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 70331da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 70341da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 70351da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 70361da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 70371da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 70381da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 70391da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 70401da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 70411da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 70421da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 70431da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 70441da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7045029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 704623ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7047683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7048d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 70495a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 705099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 705199fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7052fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 70530f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7054fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 70552050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 705618019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7057b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7058b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7059863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7060cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7061fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 70627d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 70639aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 70647f11d8d3SAndy Adamson PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist), 706599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 70661da177e4SLinus Torvalds }; 70671da177e4SLinus Torvalds 7068a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 70691da177e4SLinus Torvalds .number = 4, 7070e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 70711da177e4SLinus Torvalds .procs = nfs4_procedures 70721da177e4SLinus Torvalds }; 70731da177e4SLinus Torvalds 70741da177e4SLinus Torvalds /* 70751da177e4SLinus Torvalds * Local variables: 70761da177e4SLinus Torvalds * c-basic-offset: 8 70771da177e4SLinus Torvalds * End: 70781da177e4SLinus Torvalds */ 7079