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 */ 7795b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2) 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 + \ 629a9f6991bSTrond Myklebust encode_getattr_maxsz + \ 63091ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 631a9f6991bSTrond Myklebust encode_getattr_maxsz) 6321da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6339b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6341da177e4SLinus Torvalds decode_putfh_maxsz + \ 6351da177e4SLinus Torvalds decode_savefh_maxsz + \ 6361da177e4SLinus Torvalds decode_putfh_maxsz + \ 63791ba2eeeSTrond Myklebust decode_link_maxsz + \ 63891ba2eeeSTrond Myklebust decode_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 912ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 913ff2eb681STrond Myklebust { 914ff2eb681STrond Myklebust __be32 *p; 915ff2eb681STrond Myklebust 916ff2eb681STrond Myklebust p = reserve_space(xdr, 8); 917ff2eb681STrond Myklebust xdr_encode_hyper(p, n); 918ff2eb681STrond Myklebust } 919ff2eb681STrond Myklebust 9204ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9214ade9821STrond Myklebust const struct nfs_seqid *seqid) 9224ade9821STrond Myklebust { 9234ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 9244ade9821STrond Myklebust } 9254ade9821STrond Myklebust 9260c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9270c4e8c18SBenny Halevy struct rpc_rqst *req, 9280c4e8c18SBenny Halevy struct compound_hdr *hdr) 9291da177e4SLinus Torvalds { 9308687b63aSAl Viro __be32 *p; 931a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9320c4e8c18SBenny Halevy 9330c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9340c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9350c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9360c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9371da177e4SLinus Torvalds 9381da177e4SLinus Torvalds BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 9396fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9406fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 941e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 942d017931cSAndy Adamson hdr->nops_p = p; 94334558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 944d017931cSAndy Adamson } 945d017931cSAndy Adamson 946ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 947ab19b481STrond Myklebust uint32_t replen, 948ab19b481STrond Myklebust struct compound_hdr *hdr) 949ab19b481STrond Myklebust { 950ab19b481STrond Myklebust encode_uint32(xdr, op); 951ab19b481STrond Myklebust hdr->nops++; 952ab19b481STrond Myklebust hdr->replen += replen; 953ab19b481STrond Myklebust } 954ab19b481STrond Myklebust 955d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 956d017931cSAndy Adamson { 957fc931582SAndy Adamson BUG_ON(hdr->nops > NFS4_MAX_OPS); 958d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 9591da177e4SLinus Torvalds } 9601da177e4SLinus Torvalds 961ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 962ea9d23f5STrond Myklebust { 9632d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 964ea9d23f5STrond Myklebust } 965ea9d23f5STrond Myklebust 9661da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 9671da177e4SLinus Torvalds { 968cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 9691da177e4SLinus Torvalds } 9701da177e4SLinus Torvalds 971cf8cdbe5SAndy Adamson static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) 9721da177e4SLinus Torvalds { 9731da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 9741da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 9751da177e4SLinus Torvalds int owner_namelen = 0; 9761da177e4SLinus Torvalds int owner_grouplen = 0; 9778687b63aSAl Viro __be32 *p; 9788687b63aSAl Viro __be32 *q; 9791da177e4SLinus Torvalds int len; 9801da177e4SLinus Torvalds uint32_t bmval0 = 0; 9811da177e4SLinus Torvalds uint32_t bmval1 = 0; 9821da177e4SLinus Torvalds 9831da177e4SLinus Torvalds /* 9841da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 9851da177e4SLinus Torvalds * In the worst-case, this would be 9861da177e4SLinus Torvalds * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 9871da177e4SLinus Torvalds * = 36 bytes, plus any contribution from variable-length fields 98823ec6965SJ. Bruce Fields * such as owner/group. 9891da177e4SLinus Torvalds */ 9901da177e4SLinus Torvalds len = 16; 9911da177e4SLinus Torvalds 9921da177e4SLinus Torvalds /* Sigh */ 9931da177e4SLinus Torvalds if (iap->ia_valid & ATTR_SIZE) 9941da177e4SLinus Torvalds len += 8; 9951da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MODE) 9961da177e4SLinus Torvalds len += 4; 9971da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 998e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 9991da177e4SLinus Torvalds if (owner_namelen < 0) { 1000fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 10011da177e4SLinus Torvalds iap->ia_uid); 10021da177e4SLinus Torvalds /* XXX */ 10031da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10041da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10051da177e4SLinus Torvalds /* goto out; */ 10061da177e4SLinus Torvalds } 10071da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10081da177e4SLinus Torvalds } 10091da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 1010e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10111da177e4SLinus Torvalds if (owner_grouplen < 0) { 1012fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 10131da177e4SLinus Torvalds iap->ia_gid); 10141da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10151da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10161da177e4SLinus Torvalds /* goto out; */ 10171da177e4SLinus Torvalds } 10181da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10191da177e4SLinus Torvalds } 10201da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) 10211da177e4SLinus Torvalds len += 16; 10221da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_ATIME) 10231da177e4SLinus Torvalds len += 4; 10241da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) 10251da177e4SLinus Torvalds len += 16; 10261da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_MTIME) 10271da177e4SLinus Torvalds len += 4; 102813c65ce9SBenny Halevy p = reserve_space(xdr, len); 10291da177e4SLinus Torvalds 10301da177e4SLinus Torvalds /* 10311da177e4SLinus Torvalds * We write the bitmap length now, but leave the bitmap and the attribute 10321da177e4SLinus Torvalds * buffer length to be backfilled at the end of this routine. 10331da177e4SLinus Torvalds */ 1034e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 10351da177e4SLinus Torvalds q = p; 10361da177e4SLinus Torvalds p += 3; 10371da177e4SLinus Torvalds 10381da177e4SLinus Torvalds if (iap->ia_valid & ATTR_SIZE) { 10391da177e4SLinus Torvalds bmval0 |= FATTR4_WORD0_SIZE; 1040b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 10411da177e4SLinus Torvalds } 10421da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MODE) { 10431da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_MODE; 1044e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 10451da177e4SLinus Torvalds } 10461da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 10471da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_OWNER; 1048811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 10511da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_OWNER_GROUP; 1052811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 10531da177e4SLinus Torvalds } 10541da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 10551da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 1056e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1057e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 1058d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_sec); 1059d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 10601da177e4SLinus Torvalds } 10611da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_ATIME) { 10621da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET; 1063e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 10641da177e4SLinus Torvalds } 10651da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 10661da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 1067e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1068e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 1069e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_sec); 1070e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 10711da177e4SLinus Torvalds } 10721da177e4SLinus Torvalds else if (iap->ia_valid & ATTR_MTIME) { 10731da177e4SLinus Torvalds bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET; 1074e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 10751da177e4SLinus Torvalds } 10761da177e4SLinus Torvalds 10771da177e4SLinus Torvalds /* 10781da177e4SLinus Torvalds * Now we backfill the bitmap and the attribute buffer length. 10791da177e4SLinus Torvalds */ 10801da177e4SLinus Torvalds if (len != ((char *)p - (char *)q) + 4) { 1081f9fd2d9cSWeston Andros Adamson printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n", 10821da177e4SLinus Torvalds len, ((char *)p - (char *)q) + 4); 10831da177e4SLinus Torvalds BUG(); 10841da177e4SLinus Torvalds } 10851da177e4SLinus Torvalds len = (char *)p - (char *)q - 12; 10861da177e4SLinus Torvalds *q++ = htonl(bmval0); 10871da177e4SLinus Torvalds *q++ = htonl(bmval1); 108834558513SBenny Halevy *q = htonl(len); 10891da177e4SLinus Torvalds 10901da177e4SLinus Torvalds /* out: */ 10911da177e4SLinus Torvalds } 10921da177e4SLinus Torvalds 1093cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 10941da177e4SLinus Torvalds { 1095475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1096475d4ba0STrond Myklebust encode_uint32(xdr, access); 10971da177e4SLinus Torvalds } 10981da177e4SLinus Torvalds 1099cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11001da177e4SLinus Torvalds { 1101ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11024ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1103ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 11041da177e4SLinus Torvalds } 11051da177e4SLinus Torvalds 11060b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11071da177e4SLinus Torvalds { 11088687b63aSAl Viro __be32 *p; 11091da177e4SLinus Torvalds 1110475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1111475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1112b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 111334558513SBenny Halevy *p = cpu_to_be32(args->count); 11141da177e4SLinus Torvalds } 11151da177e4SLinus Torvalds 1116cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11171da177e4SLinus Torvalds { 11188687b63aSAl Viro __be32 *p; 11191da177e4SLinus Torvalds 1120475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1121475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11221da177e4SLinus Torvalds 11231da177e4SLinus Torvalds switch (create->ftype) { 11241da177e4SLinus Torvalds case NF4LNK: 112513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 112634558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 112794a6d753SChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 11281da177e4SLinus Torvalds break; 11291da177e4SLinus Torvalds 11301da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 113113c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1132e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 113334558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11341da177e4SLinus Torvalds break; 11351da177e4SLinus Torvalds 11361da177e4SLinus Torvalds default: 11371da177e4SLinus Torvalds break; 11381da177e4SLinus Torvalds } 11391da177e4SLinus Torvalds 1140811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 1141cf8cdbe5SAndy Adamson encode_attrs(xdr, create->attrs, create->server); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds 1144cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11451da177e4SLinus Torvalds { 11468687b63aSAl Viro __be32 *p; 11471da177e4SLinus Torvalds 1148475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1149475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1150e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 115134558513SBenny Halevy *p = cpu_to_be32(bitmap); 11521da177e4SLinus Torvalds } 11531da177e4SLinus Torvalds 1154cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 11551da177e4SLinus Torvalds { 11568687b63aSAl Viro __be32 *p; 11571da177e4SLinus Torvalds 1158475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1159475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1160e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1161e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 116234558513SBenny Halevy *p = cpu_to_be32(bm1); 11631da177e4SLinus Torvalds } 11641da177e4SLinus Torvalds 1165dae100c2SFred Isaman static void 1166dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1167dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1168dae100c2SFred Isaman struct compound_hdr *hdr) 1169dae100c2SFred Isaman { 1170dae100c2SFred Isaman __be32 *p; 1171dae100c2SFred Isaman 1172ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1173dae100c2SFred Isaman if (bm2) { 1174dae100c2SFred Isaman p = reserve_space(xdr, 16); 1175dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1176dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1177dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1178dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1179dae100c2SFred Isaman } else if (bm1) { 1180dae100c2SFred Isaman p = reserve_space(xdr, 12); 1181dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1182dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1183dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1184dae100c2SFred Isaman } else { 1185dae100c2SFred Isaman p = reserve_space(xdr, 8); 1186dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1187dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1188dae100c2SFred Isaman } 1189dae100c2SFred Isaman } 1190dae100c2SFred Isaman 1191cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 11921da177e4SLinus Torvalds { 1193cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1194d017931cSAndy Adamson bitmask[1] & nfs4_fattr_bitmap[1], hdr); 11951da177e4SLinus Torvalds } 11961da177e4SLinus Torvalds 1197cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 11981da177e4SLinus Torvalds { 1199dae100c2SFred Isaman encode_getattr_three(xdr, 1200dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1201dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1202dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1203dae100c2SFred Isaman hdr); 12041da177e4SLinus Torvalds } 12051da177e4SLinus Torvalds 1206cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1207830b8e33SManoj Naik { 1208cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1209cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1210830b8e33SManoj Naik } 1211830b8e33SManoj Naik 1212cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12131da177e4SLinus Torvalds { 1214ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12151da177e4SLinus Torvalds } 12161da177e4SLinus Torvalds 1217cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12181da177e4SLinus Torvalds { 1219ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12206fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12211da177e4SLinus Torvalds } 12221da177e4SLinus Torvalds 1223911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1224911d1aafSTrond Myklebust { 1225911d1aafSTrond Myklebust if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK) 1226911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1227911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1228911d1aafSTrond Myklebust } 1229911d1aafSTrond Myklebust 1230911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1231911d1aafSTrond Myklebust { 1232911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1233911d1aafSTrond Myklebust return ~(uint64_t)0; 1234911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1235911d1aafSTrond Myklebust } 1236911d1aafSTrond Myklebust 1237daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1238daccbdedSTrond Myklebust { 1239daccbdedSTrond Myklebust __be32 *p; 1240daccbdedSTrond Myklebust 1241d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1242daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1243d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1244daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1245d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1246daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1247daccbdedSTrond Myklebust } 1248daccbdedSTrond Myklebust 12491da177e4SLinus Torvalds /* 12501da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 12511da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 12521da177e4SLinus Torvalds */ 1253cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 12541da177e4SLinus Torvalds { 12558687b63aSAl Viro __be32 *p; 12561da177e4SLinus Torvalds 1257475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1258475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1259e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1260e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1261b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1262b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 126334558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1264911d1aafSTrond Myklebust if (args->new_lock_owner){ 12654ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1266ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->open_stateid); 12674ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1268daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12691da177e4SLinus Torvalds } 12701da177e4SLinus Torvalds else { 1271ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->lock_stateid); 12724ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 12731da177e4SLinus Torvalds } 12741da177e4SLinus Torvalds } 12751da177e4SLinus Torvalds 1276cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 12771da177e4SLinus Torvalds { 12788687b63aSAl Viro __be32 *p; 12791da177e4SLinus Torvalds 1280475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1281475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1282e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1283b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1284b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1285daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 12861da177e4SLinus Torvalds } 12871da177e4SLinus Torvalds 1288cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 12891da177e4SLinus Torvalds { 12908687b63aSAl Viro __be32 *p; 12911da177e4SLinus Torvalds 1292475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1293475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 12944ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1295ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 1296ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1297b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 129834558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 12991da177e4SLinus Torvalds } 13001da177e4SLinus Torvalds 1301d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1302d3c7b7ccSTrond Myklebust { 1303ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1304d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1305d3c7b7ccSTrond Myklebust } 1306d3c7b7ccSTrond Myklebust 1307cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13081da177e4SLinus Torvalds { 1309ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13106fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13111da177e4SLinus Torvalds } 13121da177e4SLinus Torvalds 1313dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 13141da177e4SLinus Torvalds { 13158687b63aSAl Viro __be32 *p; 13161da177e4SLinus Torvalds 131713c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1318dc0b027dSTrond Myklebust switch (fmode & (FMODE_READ|FMODE_WRITE)) { 13191da177e4SLinus Torvalds case FMODE_READ: 1320e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 13211da177e4SLinus Torvalds break; 13221da177e4SLinus Torvalds case FMODE_WRITE: 1323e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 13241da177e4SLinus Torvalds break; 13251da177e4SLinus Torvalds case FMODE_READ|FMODE_WRITE: 1326e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 13271da177e4SLinus Torvalds break; 13281da177e4SLinus Torvalds default: 1329e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 13301da177e4SLinus Torvalds } 133134558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13321da177e4SLinus Torvalds } 13331da177e4SLinus Torvalds 13341da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13351da177e4SLinus Torvalds { 13368687b63aSAl Viro __be32 *p; 13371da177e4SLinus Torvalds /* 13381da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13391da177e4SLinus Torvalds * owner 4 = 32 13401da177e4SLinus Torvalds */ 13414ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1342dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 134395b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1344b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 134595b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 134693f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1347d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 134895b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 134995b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 13501da177e4SLinus Torvalds } 13511da177e4SLinus Torvalds 13521da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13531da177e4SLinus Torvalds { 13548687b63aSAl Viro __be32 *p; 13554882ef72SAlexandros Batsakis struct nfs_client *clp; 13561da177e4SLinus Torvalds 135713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13581da177e4SLinus Torvalds switch(arg->open_flags & O_EXCL) { 13591da177e4SLinus Torvalds case 0: 136034558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 13611da177e4SLinus Torvalds encode_attrs(xdr, arg->u.attrs, arg->server); 13621da177e4SLinus Torvalds break; 13631da177e4SLinus Torvalds default: 13644882ef72SAlexandros Batsakis clp = arg->server->nfs_client; 1365a4432345STrond Myklebust if (clp->cl_mvops->minor_version > 0) { 13664882ef72SAlexandros Batsakis if (nfs4_has_persistent_session(clp)) { 13674882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 13684882ef72SAlexandros Batsakis encode_attrs(xdr, arg->u.attrs, arg->server); 13694882ef72SAlexandros Batsakis } else { 13704882ef72SAlexandros Batsakis struct iattr dummy; 13714882ef72SAlexandros Batsakis 13724882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 13734882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 13744882ef72SAlexandros Batsakis dummy.ia_valid = 0; 13754882ef72SAlexandros Batsakis encode_attrs(xdr, &dummy, arg->server); 13764882ef72SAlexandros Batsakis } 13774882ef72SAlexandros Batsakis } else { 137834558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 13791da177e4SLinus Torvalds encode_nfs4_verifier(xdr, &arg->u.verifier); 13801da177e4SLinus Torvalds } 13811da177e4SLinus Torvalds } 13824882ef72SAlexandros Batsakis } 13831da177e4SLinus Torvalds 13841da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13851da177e4SLinus Torvalds { 13868687b63aSAl Viro __be32 *p; 13871da177e4SLinus Torvalds 138813c65ce9SBenny Halevy p = reserve_space(xdr, 4); 13891da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 13901da177e4SLinus Torvalds case 0: 139134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 13921da177e4SLinus Torvalds break; 13931da177e4SLinus Torvalds default: 13941da177e4SLinus Torvalds BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 139534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 13961da177e4SLinus Torvalds encode_createmode(xdr, arg); 13971da177e4SLinus Torvalds } 13981da177e4SLinus Torvalds } 13991da177e4SLinus Torvalds 1400bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14011da177e4SLinus Torvalds { 14028687b63aSAl Viro __be32 *p; 14031da177e4SLinus Torvalds 140413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14051da177e4SLinus Torvalds switch (delegation_type) { 14061da177e4SLinus Torvalds case 0: 140734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14081da177e4SLinus Torvalds break; 14091da177e4SLinus Torvalds case FMODE_READ: 141034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14111da177e4SLinus Torvalds break; 14121da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 141334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14141da177e4SLinus Torvalds break; 14151da177e4SLinus Torvalds default: 14161da177e4SLinus Torvalds BUG(); 14171da177e4SLinus Torvalds } 14181da177e4SLinus Torvalds } 14191da177e4SLinus Torvalds 14201da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14211da177e4SLinus Torvalds { 14228687b63aSAl Viro __be32 *p; 14231da177e4SLinus Torvalds 142413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 142534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14261da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14271da177e4SLinus Torvalds } 14281da177e4SLinus Torvalds 1429bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14301da177e4SLinus Torvalds { 14318687b63aSAl Viro __be32 *p; 14321da177e4SLinus Torvalds 143313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 143434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14351da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14361da177e4SLinus Torvalds } 14371da177e4SLinus Torvalds 14381da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14391da177e4SLinus Torvalds { 14408687b63aSAl Viro __be32 *p; 14411da177e4SLinus Torvalds 1442ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1443ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1444ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14451da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14461da177e4SLinus Torvalds } 14471da177e4SLinus Torvalds 1448cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 14491da177e4SLinus Torvalds { 1450ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 14511da177e4SLinus Torvalds encode_openhdr(xdr, arg); 14521da177e4SLinus Torvalds encode_opentype(xdr, arg); 14531da177e4SLinus Torvalds switch (arg->claim) { 14541da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 14551da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 14561da177e4SLinus Torvalds break; 14571da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 14581da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 14591da177e4SLinus Torvalds break; 14601da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 14611da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 14621da177e4SLinus Torvalds break; 14631da177e4SLinus Torvalds default: 14641da177e4SLinus Torvalds BUG(); 14651da177e4SLinus Torvalds } 14661da177e4SLinus Torvalds } 14671da177e4SLinus Torvalds 1468cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 14691da177e4SLinus Torvalds { 1470ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1471ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14724ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14731da177e4SLinus Torvalds } 14741da177e4SLinus Torvalds 1475cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 14761da177e4SLinus Torvalds { 1477ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1478ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 14794ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1480dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 14811da177e4SLinus Torvalds } 14821da177e4SLinus Torvalds 1483cf8cdbe5SAndy Adamson static void 1484d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 14851da177e4SLinus Torvalds { 1486ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 14876fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 14881da177e4SLinus Torvalds } 14891da177e4SLinus Torvalds 1490cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 14911da177e4SLinus Torvalds { 1492ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 14931da177e4SLinus Torvalds } 14941da177e4SLinus Torvalds 14954fc8796dSTrond Myklebust static void encode_open_stateid(struct xdr_stream *xdr, 14964fc8796dSTrond Myklebust const struct nfs_open_context *ctx, 14974fc8796dSTrond Myklebust const struct nfs_lock_context *l_ctx, 14984fc8796dSTrond Myklebust fmode_t fmode, 14994fc8796dSTrond Myklebust int zero_seqid) 15001da177e4SLinus Torvalds { 15011da177e4SLinus Torvalds nfs4_stateid stateid; 15021da177e4SLinus Torvalds 15031da177e4SLinus Torvalds if (ctx->state != NULL) { 15044fc8796dSTrond Myklebust nfs4_select_rw_stateid(&stateid, ctx->state, 15054fc8796dSTrond Myklebust fmode, l_ctx->lockowner, l_ctx->pid); 150689d1ea65SAndy Adamson if (zero_seqid) 15072d2f24adSTrond Myklebust stateid.seqid = 0; 1508ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &stateid); 15091da177e4SLinus Torvalds } else 1510ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 15111da177e4SLinus Torvalds } 15121da177e4SLinus Torvalds 1513cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 15141da177e4SLinus Torvalds { 15158687b63aSAl Viro __be32 *p; 15161da177e4SLinus Torvalds 1517ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 1518d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 15194fc8796dSTrond Myklebust FMODE_READ, hdr->minorversion); 15201da177e4SLinus Torvalds 152113c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1522b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 152334558513SBenny Halevy *p = cpu_to_be32(args->count); 15241da177e4SLinus Torvalds } 15251da177e4SLinus Torvalds 1526cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15271da177e4SLinus Torvalds { 152828331a46STrond Myklebust uint32_t attrs[2] = { 152928331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 153028331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 153128331a46STrond Myklebust }; 15326f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1533cd93710eSChuck Lever __be32 *p, verf[2]; 15341da177e4SLinus Torvalds 153582f2e547SBryan Schumaker if (readdir->plus) { 153682f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 153728331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 153882f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 153982f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 154082f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 154182f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 15426f7a35bdSTrond Myklebust dircount >>= 1; 154382f2e547SBryan Schumaker } 154428331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 154528331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 154628331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 15476f7a35bdSTrond Myklebust 1548475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1549ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1550cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1551cd93710eSChuck Lever p = reserve_space(xdr, 20); 15526f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 15536f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 15546f7a35bdSTrond Myklebust *p++ = cpu_to_be32(2); 155582f2e547SBryan Schumaker 1556e75bc1c8SBenny Halevy *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 155734558513SBenny Halevy *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1558cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 155944109241SFred Isaman dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 156044109241SFred Isaman __func__, 1561eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1562cd93710eSChuck Lever verf[0], verf[1], 1563eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1564eadf4598STrond Myklebust attrs[1] & readdir->bitmask[1]); 15651da177e4SLinus Torvalds } 15661da177e4SLinus Torvalds 1567cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 15681da177e4SLinus Torvalds { 1569ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 15701da177e4SLinus Torvalds } 15711da177e4SLinus Torvalds 1572cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 15731da177e4SLinus Torvalds { 1574ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 15756fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 15761da177e4SLinus Torvalds } 15771da177e4SLinus Torvalds 1578cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 15791da177e4SLinus Torvalds { 1580ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1581811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1582811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 15831da177e4SLinus Torvalds } 15841da177e4SLinus Torvalds 1585bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1586bb4dae5eSChuck Lever struct compound_hdr *hdr) 15871da177e4SLinus Torvalds { 1588475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1589ff2eb681STrond Myklebust encode_uint64(xdr, clid); 15901da177e4SLinus Torvalds } 15911da177e4SLinus Torvalds 1592cf8cdbe5SAndy Adamson static void 1593d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 159456ae19f3STrond Myklebust { 1595ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 159656ae19f3STrond Myklebust } 159756ae19f3STrond Myklebust 15989f06c719SChuck Lever static void 1599d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 160023ec6965SJ. Bruce Fields { 16018687b63aSAl Viro __be32 *p; 160223ec6965SJ. Bruce Fields 1603ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1604ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 160513c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1606e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 160734558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 16089f06c719SChuck Lever BUG_ON(arg->acl_len % 4); 160913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 161034558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 161123ec6965SJ. Bruce Fields xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 161223ec6965SJ. Bruce Fields } 161323ec6965SJ. Bruce Fields 1614cf8cdbe5SAndy Adamson static void 1615d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16161da177e4SLinus Torvalds { 1617ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16181da177e4SLinus Torvalds } 16191da177e4SLinus Torvalds 1620cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16211da177e4SLinus Torvalds { 1622ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1623ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1624cf8cdbe5SAndy Adamson encode_attrs(xdr, arg->iap, server); 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds 1627cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16281da177e4SLinus Torvalds { 16298687b63aSAl Viro __be32 *p; 16301da177e4SLinus Torvalds 163170019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1632cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16331da177e4SLinus Torvalds 16341da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 163513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 163634558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16371da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16381da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 163913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 164034558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_cb_ident); 16411da177e4SLinus Torvalds } 16421da177e4SLinus Torvalds 1643bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16441da177e4SLinus Torvalds { 1645475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1646475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1647ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1648cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 16491da177e4SLinus Torvalds } 16501da177e4SLinus Torvalds 1651cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 16521da177e4SLinus Torvalds { 16538687b63aSAl Viro __be32 *p; 16541da177e4SLinus Torvalds 1655ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 1656d0b496d2STrond Myklebust encode_open_stateid(xdr, args->context, args->lock_context, 16574fc8796dSTrond Myklebust FMODE_WRITE, hdr->minorversion); 16581da177e4SLinus Torvalds 165913c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1660b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1661e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 166234558513SBenny Halevy *p = cpu_to_be32(args->count); 16631da177e4SLinus Torvalds 16641da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 16651da177e4SLinus Torvalds } 16661da177e4SLinus Torvalds 1667cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 16681da177e4SLinus Torvalds { 1669ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1670ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 16711da177e4SLinus Torvalds } 16729b7b9fccSAndy Adamson 16735a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16745a5ea0d4SBryan Schumaker { 1675ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 16766fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16775a5ea0d4SBryan Schumaker } 16785a5ea0d4SBryan Schumaker 167999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 16809b7b9fccSAndy Adamson /* NFSv4.1 operations */ 168199fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 168299fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 168399fe60d0SBenny Halevy struct compound_hdr *hdr) 168499fe60d0SBenny Halevy { 168599fe60d0SBenny Halevy __be32 *p; 1686db8ac8baSWeston Andros Adamson char impl_name[NFS4_OPAQUE_LIMIT]; 1687db8ac8baSWeston Andros Adamson int len = 0; 168899fe60d0SBenny Halevy 168970019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1690cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 169199fe60d0SBenny Halevy 169299fe60d0SBenny Halevy encode_string(xdr, args->id_len, args->id); 169399fe60d0SBenny Halevy 169413c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1695e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); 1696e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1697db8ac8baSWeston Andros Adamson 1698db8ac8baSWeston Andros Adamson if (send_implementation_id && 1699db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1700db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1701db8ac8baSWeston Andros Adamson <= NFS4_OPAQUE_LIMIT + 1) 1702db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1703db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1704db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1705db8ac8baSWeston Andros Adamson 1706db8ac8baSWeston Andros Adamson if (len > 0) { 1707db8ac8baSWeston Andros Adamson *p = cpu_to_be32(1); /* implementation id array length=1 */ 1708db8ac8baSWeston Andros Adamson 1709db8ac8baSWeston Andros Adamson encode_string(xdr, 1710db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1711db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1712db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1713db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1714db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1715db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1716db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1717db8ac8baSWeston Andros Adamson } else 1718db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); /* implementation id array length=0 */ 171999fe60d0SBenny Halevy } 1720fc931582SAndy Adamson 1721fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1722fc931582SAndy Adamson struct nfs41_create_session_args *args, 1723fc931582SAndy Adamson struct compound_hdr *hdr) 1724fc931582SAndy Adamson { 1725fc931582SAndy Adamson __be32 *p; 1726fc931582SAndy Adamson char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1727fc931582SAndy Adamson uint32_t len; 1728fc931582SAndy Adamson struct nfs_client *clp = args->client; 17298e0d46e1SMike Sager u32 max_resp_sz_cached; 17308e0d46e1SMike Sager 17318e0d46e1SMike Sager /* 17328e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 17338e0d46e1SMike Sager * 2 is the verifier. 17348e0d46e1SMike Sager */ 17358e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 17368e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1737fc931582SAndy Adamson 1738fc931582SAndy Adamson len = scnprintf(machine_name, sizeof(machine_name), "%s", 1739fc931582SAndy Adamson clp->cl_ipaddr); 174042edd698SBenny Halevy 1741475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 1742475d4ba0STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12); 1743114f64b5SAndy Adamson p = xdr_encode_hyper(p, clp->cl_clientid); 1744e75bc1c8SBenny Halevy *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1745e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1746fc931582SAndy Adamson 1747fc931582SAndy Adamson /* Fore Channel */ 1748c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1749e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1750e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 17518e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1752e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1753e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1754e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1755fc931582SAndy Adamson 1756fc931582SAndy Adamson /* Back Channel */ 1757c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1758e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1759e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1760e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1761e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1762e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1763e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1764fc931582SAndy Adamson 1765e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1766e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1767e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1768fc931582SAndy Adamson 1769fc931582SAndy Adamson /* authsys_parms rfc1831 */ 1770e75bc1c8SBenny Halevy *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */ 1771811652bdSBenny Halevy p = xdr_encode_opaque(p, machine_name, len); 1772e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1773e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 177434558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1775fc931582SAndy Adamson } 17760f3e66c6SAndy Adamson 17770f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 17780f3e66c6SAndy Adamson struct nfs4_session *session, 17790f3e66c6SAndy Adamson struct compound_hdr *hdr) 17800f3e66c6SAndy Adamson { 1781475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1782475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 17830f3e66c6SAndy Adamson } 178418019753SRicardo Labiaga 178518019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 178618019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 178718019753SRicardo Labiaga struct compound_hdr *hdr) 178818019753SRicardo Labiaga { 1789475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1790475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 179118019753SRicardo Labiaga } 179299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 179399fe60d0SBenny Halevy 17949b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 17959b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 17969b7b9fccSAndy Adamson struct compound_hdr *hdr) 17979b7b9fccSAndy Adamson { 17989b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 17999b7b9fccSAndy Adamson struct nfs4_session *session = args->sa_session; 1800fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 1801fc01cea9SAndy Adamson struct nfs4_slot *slot; 1802fc01cea9SAndy Adamson __be32 *p; 18039b7b9fccSAndy Adamson 18049b7b9fccSAndy Adamson if (!session) 18059b7b9fccSAndy Adamson return; 18069b7b9fccSAndy Adamson 1807fc01cea9SAndy Adamson tp = &session->fc_slot_table; 1808fc01cea9SAndy Adamson 1809fc01cea9SAndy Adamson WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1810fc01cea9SAndy Adamson slot = tp->slots + args->sa_slotid; 1811fc01cea9SAndy Adamson 1812475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1813fc01cea9SAndy Adamson 1814fc01cea9SAndy Adamson /* 1815fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1816fc01cea9SAndy Adamson */ 1817fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1818fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1819fc01cea9SAndy Adamson __func__, 1820fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1821fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1822fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1823fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 1824fc01cea9SAndy Adamson slot->seq_nr, args->sa_slotid, 1825fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1826475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 182793f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1828e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 1829e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->sa_slotid); 1830e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 183134558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 18329b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 18339b7b9fccSAndy Adamson } 18349b7b9fccSAndy Adamson 1835b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1836b1f69b75SAndy Adamson static void 18377f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr, 18387f11d8d3SAndy Adamson const struct nfs4_getdevicelist_args *args, 18397f11d8d3SAndy Adamson struct compound_hdr *hdr) 18407f11d8d3SAndy Adamson { 18417f11d8d3SAndy Adamson __be32 *p; 18427f11d8d3SAndy Adamson nfs4_verifier dummy = { 18437f11d8d3SAndy Adamson .data = "dummmmmy", 18447f11d8d3SAndy Adamson }; 18457f11d8d3SAndy Adamson 1846475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr); 1847475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 18487f11d8d3SAndy Adamson *p++ = cpu_to_be32(args->layoutclass); 18497f11d8d3SAndy Adamson *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 18507f11d8d3SAndy Adamson xdr_encode_hyper(p, 0ULL); /* cookie */ 18517f11d8d3SAndy Adamson encode_nfs4_verifier(xdr, &dummy); 18527f11d8d3SAndy Adamson } 18537f11d8d3SAndy Adamson 18547f11d8d3SAndy Adamson static void 1855b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1856b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1857b1f69b75SAndy Adamson struct compound_hdr *hdr) 1858b1f69b75SAndy Adamson { 1859b1f69b75SAndy Adamson __be32 *p; 1860b1f69b75SAndy Adamson 1861475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 1862475d4ba0STrond Myklebust p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE); 1863b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1864b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1865b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1866b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ 1867b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1868b1f69b75SAndy Adamson } 1869b1f69b75SAndy Adamson 1870b1f69b75SAndy Adamson static void 1871b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1872b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1873b1f69b75SAndy Adamson struct compound_hdr *hdr) 1874b1f69b75SAndy Adamson { 1875b1f69b75SAndy Adamson __be32 *p; 1876b1f69b75SAndy Adamson 1877475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1878475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1879b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1880b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1881b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1882b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1883b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1884b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1885ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1886475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1887b1f69b75SAndy Adamson 1888b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1889b1f69b75SAndy Adamson __func__, 1890b1f69b75SAndy Adamson args->type, 1891b1f69b75SAndy Adamson args->range.iomode, 1892b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1893b1f69b75SAndy Adamson (unsigned long)args->range.length, 1894b1f69b75SAndy Adamson args->maxcount); 1895b1f69b75SAndy Adamson } 1896863a3c6cSAndy Adamson 1897863a3c6cSAndy Adamson static int 1898863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1899ac7db726SBenny Halevy struct inode *inode, 1900863a3c6cSAndy Adamson const struct nfs4_layoutcommit_args *args, 1901863a3c6cSAndy Adamson struct compound_hdr *hdr) 1902863a3c6cSAndy Adamson { 1903863a3c6cSAndy Adamson __be32 *p; 1904863a3c6cSAndy Adamson 1905863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1906863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1907863a3c6cSAndy Adamson 1908475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1909475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1910863a3c6cSAndy Adamson /* Only whole file layouts */ 1911863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19123557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1913ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1914ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1915ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1916863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1917863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 1918863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1919863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 1920ac7db726SBenny Halevy 1921ac7db726SBenny Halevy if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 1922ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1923ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 1924475d4ba0STrond Myklebust else 1925475d4ba0STrond Myklebust encode_uint32(xdr, 0); /* no layout-type payload */ 1926863a3c6cSAndy Adamson 1927863a3c6cSAndy Adamson return 0; 1928863a3c6cSAndy Adamson } 1929cbe82603SBenny Halevy 1930cbe82603SBenny Halevy static void 1931cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 1932cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 1933cbe82603SBenny Halevy struct compound_hdr *hdr) 1934cbe82603SBenny Halevy { 1935cbe82603SBenny Halevy __be32 *p; 1936cbe82603SBenny Halevy 1937475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 1938475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 1939cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 1940cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 1941cbe82603SBenny Halevy *p++ = cpu_to_be32(IOMODE_ANY); 1942cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 1943ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1944cbe82603SBenny Halevy p = xdr_encode_hyper(p, 0); 1945cbe82603SBenny Halevy p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 1946cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 1947ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1948cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 194904a55549SAndy Adamson if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 195004a55549SAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 195104a55549SAndy Adamson NFS_I(args->inode)->layout, xdr, args); 1952475d4ba0STrond Myklebust } else 1953475d4ba0STrond Myklebust encode_uint32(xdr, 0); 1954cbe82603SBenny Halevy } 1955fca78d6dSBryan Schumaker 1956fca78d6dSBryan Schumaker static int 1957fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 1958fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 1959fca78d6dSBryan Schumaker struct compound_hdr *hdr) 1960fca78d6dSBryan Schumaker { 1961475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 1962475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 1963fca78d6dSBryan Schumaker return 0; 1964fca78d6dSBryan Schumaker } 19657d974794SBryan Schumaker 19667d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 19677d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 19687d974794SBryan Schumaker struct compound_hdr *hdr) 19697d974794SBryan Schumaker { 1970475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 1971475d4ba0STrond Myklebust encode_uint32(xdr, 1); 1972ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 19737d974794SBryan Schumaker } 19749aeda35fSBryan Schumaker 19759aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 19769aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 19779aeda35fSBryan Schumaker struct compound_hdr *hdr) 19789aeda35fSBryan Schumaker { 1979ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 1980ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 19819aeda35fSBryan Schumaker } 1982b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 1983b1f69b75SAndy Adamson 19841da177e4SLinus Torvalds /* 19851da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 19861da177e4SLinus Torvalds */ 19871da177e4SLinus Torvalds 198866cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 198966cc0429SBenny Halevy { 199066cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 199166cc0429SBenny Halevy if (args->sa_session) 1992a4432345STrond Myklebust return args->sa_session->clp->cl_mvops->minor_version; 199366cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 199466cc0429SBenny Halevy return 0; 199566cc0429SBenny Halevy } 199666cc0429SBenny Halevy 19971da177e4SLinus Torvalds /* 19981da177e4SLinus Torvalds * Encode an ACCESS request 19991da177e4SLinus Torvalds */ 20009f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 20019f06c719SChuck Lever const struct nfs4_accessargs *args) 20021da177e4SLinus Torvalds { 20031da177e4SLinus Torvalds struct compound_hdr hdr = { 200466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20051da177e4SLinus Torvalds }; 20061da177e4SLinus Torvalds 20079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20089f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20099f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20109f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 20119f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2012d017931cSAndy Adamson encode_nops(&hdr); 20131da177e4SLinus Torvalds } 20141da177e4SLinus Torvalds 20151da177e4SLinus Torvalds /* 20161da177e4SLinus Torvalds * Encode LOOKUP request 20171da177e4SLinus Torvalds */ 20189f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 20199f06c719SChuck Lever const struct nfs4_lookup_arg *args) 20201da177e4SLinus Torvalds { 20211da177e4SLinus Torvalds struct compound_hdr hdr = { 202266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20231da177e4SLinus Torvalds }; 20241da177e4SLinus Torvalds 20259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20279f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 20289f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 20299f06c719SChuck Lever encode_getfh(xdr, &hdr); 20309f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2031d017931cSAndy Adamson encode_nops(&hdr); 20321da177e4SLinus Torvalds } 20331da177e4SLinus Torvalds 20341da177e4SLinus Torvalds /* 20351da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 20361da177e4SLinus Torvalds */ 20379f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 20389f06c719SChuck Lever struct xdr_stream *xdr, 20399f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 20401da177e4SLinus Torvalds { 20411da177e4SLinus Torvalds struct compound_hdr hdr = { 204266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20431da177e4SLinus Torvalds }; 20441da177e4SLinus Torvalds 20459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20479f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 20489f06c719SChuck Lever encode_getfh(xdr, &hdr); 20499f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2050d017931cSAndy Adamson encode_nops(&hdr); 20511da177e4SLinus Torvalds } 20521da177e4SLinus Torvalds 20531da177e4SLinus Torvalds /* 20541da177e4SLinus Torvalds * Encode REMOVE request 20551da177e4SLinus Torvalds */ 20569f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 20579f06c719SChuck Lever const struct nfs_removeargs *args) 20581da177e4SLinus Torvalds { 20591da177e4SLinus Torvalds struct compound_hdr hdr = { 206066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20611da177e4SLinus Torvalds }; 20621da177e4SLinus Torvalds 20639f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20649f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20659f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20669f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 20679f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2068d017931cSAndy Adamson encode_nops(&hdr); 20691da177e4SLinus Torvalds } 20701da177e4SLinus Torvalds 20711da177e4SLinus Torvalds /* 20721da177e4SLinus Torvalds * Encode RENAME request 20731da177e4SLinus Torvalds */ 20749f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 20759f06c719SChuck Lever const struct nfs_renameargs *args) 20761da177e4SLinus Torvalds { 20771da177e4SLinus Torvalds struct compound_hdr hdr = { 207866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20791da177e4SLinus Torvalds }; 20801da177e4SLinus Torvalds 20819f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20829f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20839f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 20849f06c719SChuck Lever encode_savefh(xdr, &hdr); 20859f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 20869f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 20879f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 20889f06c719SChuck Lever encode_restorefh(xdr, &hdr); 20899f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2090d017931cSAndy Adamson encode_nops(&hdr); 20911da177e4SLinus Torvalds } 20921da177e4SLinus Torvalds 20931da177e4SLinus Torvalds /* 20941da177e4SLinus Torvalds * Encode LINK request 20951da177e4SLinus Torvalds */ 20969f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 20979f06c719SChuck Lever const struct nfs4_link_arg *args) 20981da177e4SLinus Torvalds { 20991da177e4SLinus Torvalds struct compound_hdr hdr = { 210066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21011da177e4SLinus Torvalds }; 21021da177e4SLinus Torvalds 21039f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21049f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21059f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21069f06c719SChuck Lever encode_savefh(xdr, &hdr); 21079f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21089f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 21099f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21109f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21119f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2112d017931cSAndy Adamson encode_nops(&hdr); 21131da177e4SLinus Torvalds } 21141da177e4SLinus Torvalds 21151da177e4SLinus Torvalds /* 21161da177e4SLinus Torvalds * Encode CREATE request 21171da177e4SLinus Torvalds */ 21189f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 21199f06c719SChuck Lever const struct nfs4_create_arg *args) 21201da177e4SLinus Torvalds { 21211da177e4SLinus Torvalds struct compound_hdr hdr = { 212266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21231da177e4SLinus Torvalds }; 21241da177e4SLinus Torvalds 21259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21279f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21289f06c719SChuck Lever encode_savefh(xdr, &hdr); 21299f06c719SChuck Lever encode_create(xdr, args, &hdr); 21309f06c719SChuck Lever encode_getfh(xdr, &hdr); 21319f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21329f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21339f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2134d017931cSAndy Adamson encode_nops(&hdr); 21351da177e4SLinus Torvalds } 21361da177e4SLinus Torvalds 21371da177e4SLinus Torvalds /* 21381da177e4SLinus Torvalds * Encode SYMLINK request 21391da177e4SLinus Torvalds */ 21409f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 21419f06c719SChuck Lever const struct nfs4_create_arg *args) 21421da177e4SLinus Torvalds { 21439f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 21441da177e4SLinus Torvalds } 21451da177e4SLinus Torvalds 21461da177e4SLinus Torvalds /* 21471da177e4SLinus Torvalds * Encode GETATTR request 21481da177e4SLinus Torvalds */ 21499f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 21509f06c719SChuck Lever const struct nfs4_getattr_arg *args) 21511da177e4SLinus Torvalds { 21521da177e4SLinus Torvalds struct compound_hdr hdr = { 215366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21541da177e4SLinus Torvalds }; 21551da177e4SLinus Torvalds 21569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21579f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21589f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21599f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2160d017931cSAndy Adamson encode_nops(&hdr); 21611da177e4SLinus Torvalds } 21621da177e4SLinus Torvalds 21631da177e4SLinus Torvalds /* 21641da177e4SLinus Torvalds * Encode a CLOSE request 21651da177e4SLinus Torvalds */ 21669f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 21679f06c719SChuck Lever struct nfs_closeargs *args) 21681da177e4SLinus Torvalds { 21691da177e4SLinus Torvalds struct compound_hdr hdr = { 217066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21711da177e4SLinus Torvalds }; 21721da177e4SLinus Torvalds 21739f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21749f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21759f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21769f06c719SChuck Lever encode_close(xdr, args, &hdr); 21779f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2178d017931cSAndy Adamson encode_nops(&hdr); 21791da177e4SLinus Torvalds } 21801da177e4SLinus Torvalds 21811da177e4SLinus Torvalds /* 21821da177e4SLinus Torvalds * Encode an OPEN request 21831da177e4SLinus Torvalds */ 21849f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 21859f06c719SChuck Lever struct nfs_openargs *args) 21861da177e4SLinus Torvalds { 21871da177e4SLinus Torvalds struct compound_hdr hdr = { 218866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21891da177e4SLinus Torvalds }; 21901da177e4SLinus Torvalds 21919f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21929f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21939f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21949f06c719SChuck Lever encode_savefh(xdr, &hdr); 21959f06c719SChuck Lever encode_open(xdr, args, &hdr); 21969f06c719SChuck Lever encode_getfh(xdr, &hdr); 21979f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 21989f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21996926afd1STrond Myklebust encode_getfattr(xdr, args->dir_bitmask, &hdr); 2200d017931cSAndy Adamson encode_nops(&hdr); 22011da177e4SLinus Torvalds } 22021da177e4SLinus Torvalds 22031da177e4SLinus Torvalds /* 22041da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 22051da177e4SLinus Torvalds */ 22069f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22079f06c719SChuck Lever struct xdr_stream *xdr, 22089f06c719SChuck Lever struct nfs_open_confirmargs *args) 22091da177e4SLinus Torvalds { 22101da177e4SLinus Torvalds struct compound_hdr hdr = { 2211d017931cSAndy Adamson .nops = 0, 22121da177e4SLinus Torvalds }; 22131da177e4SLinus Torvalds 22149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22159f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22169f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2217d017931cSAndy Adamson encode_nops(&hdr); 22181da177e4SLinus Torvalds } 22191da177e4SLinus Torvalds 22201da177e4SLinus Torvalds /* 22211da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 22221da177e4SLinus Torvalds */ 22239f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 22249f06c719SChuck Lever struct xdr_stream *xdr, 22259f06c719SChuck Lever struct nfs_openargs *args) 22261da177e4SLinus Torvalds { 22271da177e4SLinus Torvalds struct compound_hdr hdr = { 222866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22291da177e4SLinus Torvalds }; 22301da177e4SLinus Torvalds 22319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22339f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22349f06c719SChuck Lever encode_open(xdr, args, &hdr); 22359f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2236d017931cSAndy Adamson encode_nops(&hdr); 22371da177e4SLinus Torvalds } 22381da177e4SLinus Torvalds 22391da177e4SLinus Torvalds /* 22401da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 22411da177e4SLinus Torvalds */ 22429f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 22439f06c719SChuck Lever struct xdr_stream *xdr, 22449f06c719SChuck Lever struct nfs_closeargs *args) 22451da177e4SLinus Torvalds { 22461da177e4SLinus Torvalds struct compound_hdr hdr = { 224766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22481da177e4SLinus Torvalds }; 22491da177e4SLinus Torvalds 22509f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22519f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22529f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22539f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 22549f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2255d017931cSAndy Adamson encode_nops(&hdr); 22561da177e4SLinus Torvalds } 22571da177e4SLinus Torvalds 22581da177e4SLinus Torvalds /* 22591da177e4SLinus Torvalds * Encode a LOCK request 22601da177e4SLinus Torvalds */ 22619f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 22629f06c719SChuck Lever struct nfs_lock_args *args) 22631da177e4SLinus Torvalds { 22641da177e4SLinus Torvalds struct compound_hdr hdr = { 226566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22661da177e4SLinus Torvalds }; 22671da177e4SLinus Torvalds 22689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22709f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22719f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2272d017931cSAndy Adamson encode_nops(&hdr); 22731da177e4SLinus Torvalds } 22741da177e4SLinus Torvalds 22751da177e4SLinus Torvalds /* 22761da177e4SLinus Torvalds * Encode a LOCKT request 22771da177e4SLinus Torvalds */ 22789f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 22799f06c719SChuck Lever struct nfs_lockt_args *args) 22801da177e4SLinus Torvalds { 22811da177e4SLinus Torvalds struct compound_hdr hdr = { 228266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22831da177e4SLinus Torvalds }; 22841da177e4SLinus Torvalds 22859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22869f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22879f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22889f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2289d017931cSAndy Adamson encode_nops(&hdr); 22901da177e4SLinus Torvalds } 22911da177e4SLinus Torvalds 22921da177e4SLinus Torvalds /* 22931da177e4SLinus Torvalds * Encode a LOCKU request 22941da177e4SLinus Torvalds */ 22959f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 22969f06c719SChuck Lever struct nfs_locku_args *args) 22971da177e4SLinus Torvalds { 22981da177e4SLinus Torvalds struct compound_hdr hdr = { 229966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23001da177e4SLinus Torvalds }; 23011da177e4SLinus Torvalds 23029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23049f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23059f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2306d017931cSAndy Adamson encode_nops(&hdr); 23071da177e4SLinus Torvalds } 23081da177e4SLinus Torvalds 23099f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 23109f06c719SChuck Lever struct xdr_stream *xdr, 23119f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2312d3c7b7ccSTrond Myklebust { 2313d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2314d3c7b7ccSTrond Myklebust .minorversion = 0, 2315d3c7b7ccSTrond Myklebust }; 2316d3c7b7ccSTrond Myklebust 23179f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23189f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2319d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2320d3c7b7ccSTrond Myklebust } 2321d3c7b7ccSTrond Myklebust 23221da177e4SLinus Torvalds /* 23231da177e4SLinus Torvalds * Encode a READLINK request 23241da177e4SLinus Torvalds */ 23259f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 23269f06c719SChuck Lever const struct nfs4_readlink *args) 23271da177e4SLinus Torvalds { 23281da177e4SLinus Torvalds struct compound_hdr hdr = { 232966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23301da177e4SLinus Torvalds }; 23311da177e4SLinus Torvalds 23329f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23339f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23349f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23359f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2336e3a535e1STrond Myklebust 233728f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2338e3a535e1STrond Myklebust args->pgbase, args->pglen); 2339d017931cSAndy Adamson encode_nops(&hdr); 23401da177e4SLinus Torvalds } 23411da177e4SLinus Torvalds 23421da177e4SLinus Torvalds /* 23431da177e4SLinus Torvalds * Encode a READDIR request 23441da177e4SLinus Torvalds */ 23459f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 23469f06c719SChuck Lever const struct nfs4_readdir_arg *args) 23471da177e4SLinus Torvalds { 23481da177e4SLinus Torvalds struct compound_hdr hdr = { 234966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23501da177e4SLinus Torvalds }; 23511da177e4SLinus Torvalds 23529f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23539f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23549f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23559f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2356d6ac02dfSTrond Myklebust 235728f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2358d6ac02dfSTrond Myklebust args->pgbase, args->count); 2359d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 236028f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2361d6ac02dfSTrond Myklebust args->pgbase, args->count); 2362d017931cSAndy Adamson encode_nops(&hdr); 23631da177e4SLinus Torvalds } 23641da177e4SLinus Torvalds 23651da177e4SLinus Torvalds /* 23661da177e4SLinus Torvalds * Encode a READ request 23671da177e4SLinus Torvalds */ 23689f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 23699f06c719SChuck Lever struct nfs_readargs *args) 23701da177e4SLinus Torvalds { 23711da177e4SLinus Torvalds struct compound_hdr hdr = { 237266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23731da177e4SLinus Torvalds }; 23741da177e4SLinus Torvalds 23759f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23769f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23779f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23789f06c719SChuck Lever encode_read(xdr, args, &hdr); 23791da177e4SLinus Torvalds 238028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 23811da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 23824f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2383d017931cSAndy Adamson encode_nops(&hdr); 23841da177e4SLinus Torvalds } 23851da177e4SLinus Torvalds 23861da177e4SLinus Torvalds /* 23871da177e4SLinus Torvalds * Encode an SETATTR request 23881da177e4SLinus Torvalds */ 23899f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 23909f06c719SChuck Lever struct nfs_setattrargs *args) 23911da177e4SLinus Torvalds { 23921da177e4SLinus Torvalds struct compound_hdr hdr = { 239366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23941da177e4SLinus Torvalds }; 23951da177e4SLinus Torvalds 23969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23999f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 24009f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2401d017931cSAndy Adamson encode_nops(&hdr); 24021da177e4SLinus Torvalds } 24031da177e4SLinus Torvalds 24041da177e4SLinus Torvalds /* 2405029d105eSJ. Bruce Fields * Encode a GETACL request 2406029d105eSJ. Bruce Fields */ 24079f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2408029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2409029d105eSJ. Bruce Fields { 2410029d105eSJ. Bruce Fields struct compound_hdr hdr = { 241166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2412029d105eSJ. Bruce Fields }; 241328f56694SBenny Halevy uint32_t replen; 2414029d105eSJ. Bruce Fields 24159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24169f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24179f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2418bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 24199f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2420cf8cdbe5SAndy Adamson 242128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2422029d105eSJ. Bruce Fields args->acl_pages, args->acl_pgbase, args->acl_len); 2423bf118a34SAndy Adamson 2424d017931cSAndy Adamson encode_nops(&hdr); 2425029d105eSJ. Bruce Fields } 2426029d105eSJ. Bruce Fields 2427029d105eSJ. Bruce Fields /* 24281da177e4SLinus Torvalds * Encode a WRITE request 24291da177e4SLinus Torvalds */ 24309f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 24319f06c719SChuck Lever struct nfs_writeargs *args) 24321da177e4SLinus Torvalds { 24331da177e4SLinus Torvalds struct compound_hdr hdr = { 243466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24351da177e4SLinus Torvalds }; 24361da177e4SLinus Torvalds 24379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24389f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24399f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24409f06c719SChuck Lever encode_write(xdr, args, &hdr); 24414f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 24427ffd1064SFred Isaman if (args->bitmask) 24439f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2444d017931cSAndy Adamson encode_nops(&hdr); 24451da177e4SLinus Torvalds } 24461da177e4SLinus Torvalds 24471da177e4SLinus Torvalds /* 24481da177e4SLinus Torvalds * a COMMIT request 24491da177e4SLinus Torvalds */ 24509f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 24510b7c0153SFred Isaman struct nfs_commitargs *args) 24521da177e4SLinus Torvalds { 24531da177e4SLinus Torvalds struct compound_hdr hdr = { 245466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24551da177e4SLinus Torvalds }; 24561da177e4SLinus Torvalds 24579f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24589f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24599f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24609f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2461988b6dceSFred Isaman if (args->bitmask) 24629f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2463d017931cSAndy Adamson encode_nops(&hdr); 24641da177e4SLinus Torvalds } 24651da177e4SLinus Torvalds 24661da177e4SLinus Torvalds /* 24671da177e4SLinus Torvalds * FSINFO request 24681da177e4SLinus Torvalds */ 24699f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 24709f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 24711da177e4SLinus Torvalds { 24721da177e4SLinus Torvalds struct compound_hdr hdr = { 247366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24741da177e4SLinus Torvalds }; 24751da177e4SLinus Torvalds 24769f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24779f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24789f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24799f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2480d017931cSAndy Adamson encode_nops(&hdr); 24811da177e4SLinus Torvalds } 24821da177e4SLinus Torvalds 24831da177e4SLinus Torvalds /* 24841da177e4SLinus Torvalds * a PATHCONF request 24851da177e4SLinus Torvalds */ 24869f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 24879f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 24881da177e4SLinus Torvalds { 24891da177e4SLinus Torvalds struct compound_hdr hdr = { 249066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24911da177e4SLinus Torvalds }; 24921da177e4SLinus Torvalds 24939f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24949f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24959f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24969f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2497d017931cSAndy Adamson &hdr); 2498d017931cSAndy Adamson encode_nops(&hdr); 24991da177e4SLinus Torvalds } 25001da177e4SLinus Torvalds 25011da177e4SLinus Torvalds /* 25021da177e4SLinus Torvalds * a STATFS request 25031da177e4SLinus Torvalds */ 25049f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 25059f06c719SChuck Lever const struct nfs4_statfs_arg *args) 25061da177e4SLinus Torvalds { 25071da177e4SLinus Torvalds struct compound_hdr hdr = { 250866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25091da177e4SLinus Torvalds }; 25101da177e4SLinus Torvalds 25119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25139f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25149f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2515d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2516d017931cSAndy Adamson encode_nops(&hdr); 25171da177e4SLinus Torvalds } 25181da177e4SLinus Torvalds 25191da177e4SLinus Torvalds /* 25201da177e4SLinus Torvalds * GETATTR_BITMAP request 25211da177e4SLinus Torvalds */ 25229f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 25239f06c719SChuck Lever struct xdr_stream *xdr, 252443652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 25251da177e4SLinus Torvalds { 25261da177e4SLinus Torvalds struct compound_hdr hdr = { 252766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25281da177e4SLinus Torvalds }; 25291da177e4SLinus Torvalds 25309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25329f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 25339f06c719SChuck Lever encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2534264e6351SChuck Lever FATTR4_WORD0_FH_EXPIRE_TYPE| 25351da177e4SLinus Torvalds FATTR4_WORD0_LINK_SUPPORT| 25361da177e4SLinus Torvalds FATTR4_WORD0_SYMLINK_SUPPORT| 2537d017931cSAndy Adamson FATTR4_WORD0_ACLSUPPORT, &hdr); 2538d017931cSAndy Adamson encode_nops(&hdr); 25391da177e4SLinus Torvalds } 25401da177e4SLinus Torvalds 25411da177e4SLinus Torvalds /* 25421da177e4SLinus Torvalds * a RENEW request 25431da177e4SLinus Torvalds */ 25449f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 25459f06c719SChuck Lever struct nfs_client *clp) 25461da177e4SLinus Torvalds { 25471da177e4SLinus Torvalds struct compound_hdr hdr = { 2548d017931cSAndy Adamson .nops = 0, 25491da177e4SLinus Torvalds }; 25501da177e4SLinus Torvalds 25519f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2552bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2553d017931cSAndy Adamson encode_nops(&hdr); 25541da177e4SLinus Torvalds } 25551da177e4SLinus Torvalds 25561da177e4SLinus Torvalds /* 25571da177e4SLinus Torvalds * a SETCLIENTID request 25581da177e4SLinus Torvalds */ 25599f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 25609f06c719SChuck Lever struct xdr_stream *xdr, 25619f06c719SChuck Lever struct nfs4_setclientid *sc) 25621da177e4SLinus Torvalds { 25631da177e4SLinus Torvalds struct compound_hdr hdr = { 2564d017931cSAndy Adamson .nops = 0, 25651da177e4SLinus Torvalds }; 25661da177e4SLinus Torvalds 25679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25689f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2569d017931cSAndy Adamson encode_nops(&hdr); 25701da177e4SLinus Torvalds } 25711da177e4SLinus Torvalds 25721da177e4SLinus Torvalds /* 25731da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 25741da177e4SLinus Torvalds */ 25759f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 25769f06c719SChuck Lever struct xdr_stream *xdr, 25779f06c719SChuck Lever struct nfs4_setclientid_res *arg) 25781da177e4SLinus Torvalds { 25791da177e4SLinus Torvalds struct compound_hdr hdr = { 2580d017931cSAndy Adamson .nops = 0, 25811da177e4SLinus Torvalds }; 2582dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 25831da177e4SLinus Torvalds 25849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25859f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 25869f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 25879f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 2588d017931cSAndy Adamson encode_nops(&hdr); 25891da177e4SLinus Torvalds } 25901da177e4SLinus Torvalds 25911da177e4SLinus Torvalds /* 25921da177e4SLinus Torvalds * DELEGRETURN request 25931da177e4SLinus Torvalds */ 25949f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 25959f06c719SChuck Lever struct xdr_stream *xdr, 25969f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 25971da177e4SLinus Torvalds { 25981da177e4SLinus Torvalds struct compound_hdr hdr = { 259966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26001da177e4SLinus Torvalds }; 26011da177e4SLinus Torvalds 26029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26049f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26059f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2606e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2607d017931cSAndy Adamson encode_nops(&hdr); 26081da177e4SLinus Torvalds } 26091da177e4SLinus Torvalds 26101da177e4SLinus Torvalds /* 2611683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2612683b57b4STrond Myklebust */ 26139f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 26149f06c719SChuck Lever struct xdr_stream *xdr, 26159f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2616683b57b4STrond Myklebust { 2617683b57b4STrond Myklebust struct compound_hdr hdr = { 261866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2619683b57b4STrond Myklebust }; 262028f56694SBenny Halevy uint32_t replen; 2621683b57b4STrond Myklebust 26229f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26239f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26249f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 26259f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 262628f56694SBenny Halevy replen = hdr.replen; /* get the attribute into args->page */ 26279f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2628cf8cdbe5SAndy Adamson 262928f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2630683b57b4STrond Myklebust 0, PAGE_SIZE); 2631d017931cSAndy Adamson encode_nops(&hdr); 2632683b57b4STrond Myklebust } 2633683b57b4STrond Myklebust 26345a5ea0d4SBryan Schumaker /* 26355a5ea0d4SBryan Schumaker * Encode SECINFO request 26365a5ea0d4SBryan Schumaker */ 26375a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 26385a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 26395a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 26405a5ea0d4SBryan Schumaker { 26415a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 26425a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26435a5ea0d4SBryan Schumaker }; 26445a5ea0d4SBryan Schumaker 26455a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 26465a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 26475a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 26485a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 26495a5ea0d4SBryan Schumaker encode_nops(&hdr); 26505a5ea0d4SBryan Schumaker } 26515a5ea0d4SBryan Schumaker 265299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 265399fe60d0SBenny Halevy /* 265499fe60d0SBenny Halevy * EXCHANGE_ID request 265599fe60d0SBenny Halevy */ 26569f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 26579f06c719SChuck Lever struct xdr_stream *xdr, 265899fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 265999fe60d0SBenny Halevy { 266099fe60d0SBenny Halevy struct compound_hdr hdr = { 2661a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 266299fe60d0SBenny Halevy }; 266399fe60d0SBenny Halevy 26649f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26659f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 266699fe60d0SBenny Halevy encode_nops(&hdr); 266799fe60d0SBenny Halevy } 26682050f0ccSAndy Adamson 26692050f0ccSAndy Adamson /* 2670fc931582SAndy Adamson * a CREATE_SESSION request 2671fc931582SAndy Adamson */ 26729f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 26739f06c719SChuck Lever struct xdr_stream *xdr, 2674fc931582SAndy Adamson struct nfs41_create_session_args *args) 2675fc931582SAndy Adamson { 2676fc931582SAndy Adamson struct compound_hdr hdr = { 2677a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2678fc931582SAndy Adamson }; 2679fc931582SAndy Adamson 26809f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26819f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2682fc931582SAndy Adamson encode_nops(&hdr); 2683fc931582SAndy Adamson } 2684fc931582SAndy Adamson 2685fc931582SAndy Adamson /* 26860f3e66c6SAndy Adamson * a DESTROY_SESSION request 26870f3e66c6SAndy Adamson */ 26889f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 26899f06c719SChuck Lever struct xdr_stream *xdr, 26900f3e66c6SAndy Adamson struct nfs4_session *session) 26910f3e66c6SAndy Adamson { 26920f3e66c6SAndy Adamson struct compound_hdr hdr = { 2693a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 26940f3e66c6SAndy Adamson }; 26950f3e66c6SAndy Adamson 26969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26979f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 26980f3e66c6SAndy Adamson encode_nops(&hdr); 26990f3e66c6SAndy Adamson } 27000f3e66c6SAndy Adamson 27010f3e66c6SAndy Adamson /* 2702fc01cea9SAndy Adamson * a SEQUENCE request 2703fc01cea9SAndy Adamson */ 27049f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2705fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2706fc01cea9SAndy Adamson { 2707fc01cea9SAndy Adamson struct compound_hdr hdr = { 2708fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2709fc01cea9SAndy Adamson }; 2710fc01cea9SAndy Adamson 27119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27129f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2713fc01cea9SAndy Adamson encode_nops(&hdr); 2714fc01cea9SAndy Adamson } 2715fc01cea9SAndy Adamson 2716fc01cea9SAndy Adamson /* 27172050f0ccSAndy Adamson * a GET_LEASE_TIME request 27182050f0ccSAndy Adamson */ 27199f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 27209f06c719SChuck Lever struct xdr_stream *xdr, 27212050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 27222050f0ccSAndy Adamson { 27232050f0ccSAndy Adamson struct compound_hdr hdr = { 27242050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 27252050f0ccSAndy Adamson }; 2726dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 27272050f0ccSAndy Adamson 27289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27299f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 27309f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 27319f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 27322050f0ccSAndy Adamson encode_nops(&hdr); 27332050f0ccSAndy Adamson } 273418019753SRicardo Labiaga 273518019753SRicardo Labiaga /* 273618019753SRicardo Labiaga * a RECLAIM_COMPLETE request 273718019753SRicardo Labiaga */ 27389f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 27399f06c719SChuck Lever struct xdr_stream *xdr, 274018019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 274118019753SRicardo Labiaga { 274218019753SRicardo Labiaga struct compound_hdr hdr = { 274318019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 274418019753SRicardo Labiaga }; 274518019753SRicardo Labiaga 27469f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27479f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27489f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 274918019753SRicardo Labiaga encode_nops(&hdr); 275018019753SRicardo Labiaga } 275118019753SRicardo Labiaga 2752b1f69b75SAndy Adamson /* 27537f11d8d3SAndy Adamson * Encode GETDEVICELIST request 27547f11d8d3SAndy Adamson */ 27557f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req, 27567f11d8d3SAndy Adamson struct xdr_stream *xdr, 27577f11d8d3SAndy Adamson struct nfs4_getdevicelist_args *args) 27587f11d8d3SAndy Adamson { 27597f11d8d3SAndy Adamson struct compound_hdr hdr = { 27607f11d8d3SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27617f11d8d3SAndy Adamson }; 27627f11d8d3SAndy Adamson 27637f11d8d3SAndy Adamson encode_compound_hdr(xdr, req, &hdr); 27647f11d8d3SAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 27657f11d8d3SAndy Adamson encode_putfh(xdr, args->fh, &hdr); 27667f11d8d3SAndy Adamson encode_getdevicelist(xdr, args, &hdr); 27677f11d8d3SAndy Adamson encode_nops(&hdr); 27687f11d8d3SAndy Adamson } 27697f11d8d3SAndy Adamson 27707f11d8d3SAndy Adamson /* 2771b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2772b1f69b75SAndy Adamson */ 27739f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 27749f06c719SChuck Lever struct xdr_stream *xdr, 2775b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2776b1f69b75SAndy Adamson { 2777b1f69b75SAndy Adamson struct compound_hdr hdr = { 2778b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2779b1f69b75SAndy Adamson }; 2780b1f69b75SAndy Adamson 27819f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27829f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27839f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2784b1f69b75SAndy Adamson 2785b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2786b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2787b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2788b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2789b1f69b75SAndy Adamson args->pdev->pglen); 2790b1f69b75SAndy Adamson 2791b1f69b75SAndy Adamson encode_nops(&hdr); 2792b1f69b75SAndy Adamson } 2793b1f69b75SAndy Adamson 2794b1f69b75SAndy Adamson /* 2795b1f69b75SAndy Adamson * Encode LAYOUTGET request 2796b1f69b75SAndy Adamson */ 27979f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 27989f06c719SChuck Lever struct xdr_stream *xdr, 2799b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2800b1f69b75SAndy Adamson { 2801b1f69b75SAndy Adamson struct compound_hdr hdr = { 2802b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2803b1f69b75SAndy Adamson }; 2804b1f69b75SAndy Adamson 28059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28079f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 28089f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 280935124a09SWeston Andros Adamson 281035124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 281135124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 281235124a09SWeston Andros Adamson 2813b1f69b75SAndy Adamson encode_nops(&hdr); 2814b1f69b75SAndy Adamson } 2815863a3c6cSAndy Adamson 2816863a3c6cSAndy Adamson /* 2817863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2818863a3c6cSAndy Adamson */ 2819cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2820863a3c6cSAndy Adamson struct xdr_stream *xdr, 2821863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2822863a3c6cSAndy Adamson { 2823ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2824ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2825863a3c6cSAndy Adamson struct compound_hdr hdr = { 2826863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2827863a3c6cSAndy Adamson }; 2828863a3c6cSAndy Adamson 2829863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2830863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2831863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2832ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2833863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2834863a3c6cSAndy Adamson encode_nops(&hdr); 2835cbe82603SBenny Halevy } 2836cbe82603SBenny Halevy 2837cbe82603SBenny Halevy /* 2838cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2839cbe82603SBenny Halevy */ 2840cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2841cbe82603SBenny Halevy struct xdr_stream *xdr, 2842cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2843cbe82603SBenny Halevy { 2844cbe82603SBenny Halevy struct compound_hdr hdr = { 2845cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2846cbe82603SBenny Halevy }; 2847cbe82603SBenny Halevy 2848cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2849cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2850cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2851cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2852cbe82603SBenny Halevy encode_nops(&hdr); 2853863a3c6cSAndy Adamson } 2854fca78d6dSBryan Schumaker 2855fca78d6dSBryan Schumaker /* 2856fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2857fca78d6dSBryan Schumaker */ 2858fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2859fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2860fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2861fca78d6dSBryan Schumaker { 2862fca78d6dSBryan Schumaker struct compound_hdr hdr = { 2863fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2864fca78d6dSBryan Schumaker }; 2865fca78d6dSBryan Schumaker 2866fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 2867fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 2868fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 2869fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 2870fca78d6dSBryan Schumaker encode_nops(&hdr); 2871fca78d6dSBryan Schumaker return 0; 2872fca78d6dSBryan Schumaker } 28737d974794SBryan Schumaker 28747d974794SBryan Schumaker /* 28757d974794SBryan Schumaker * Encode TEST_STATEID request 28767d974794SBryan Schumaker */ 28777d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 28787d974794SBryan Schumaker struct xdr_stream *xdr, 28797d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 28807d974794SBryan Schumaker { 28817d974794SBryan Schumaker struct compound_hdr hdr = { 28827d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28837d974794SBryan Schumaker }; 28847d974794SBryan Schumaker 28857d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 28867d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 28877d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 28887d974794SBryan Schumaker encode_nops(&hdr); 28897d974794SBryan Schumaker } 28909aeda35fSBryan Schumaker 28919aeda35fSBryan Schumaker /* 28929aeda35fSBryan Schumaker * Encode FREE_STATEID request 28939aeda35fSBryan Schumaker */ 28949aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 28959aeda35fSBryan Schumaker struct xdr_stream *xdr, 28969aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 28979aeda35fSBryan Schumaker { 28989aeda35fSBryan Schumaker struct compound_hdr hdr = { 28999aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29009aeda35fSBryan Schumaker }; 29019aeda35fSBryan Schumaker 29029aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29039aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29049aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 29059aeda35fSBryan Schumaker encode_nops(&hdr); 29069aeda35fSBryan Schumaker } 290799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 290899fe60d0SBenny Halevy 2909686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 2910686841b3SBenny Halevy { 2911686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 2912686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 2913686841b3SBenny Halevy func, xdr->end - xdr->p); 2914686841b3SBenny Halevy } 29151da177e4SLinus Torvalds 2916683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 29171da177e4SLinus Torvalds { 29188687b63aSAl Viro __be32 *p; 29191da177e4SLinus Torvalds 2920c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 2921c0eae66eSBenny Halevy if (unlikely(!p)) 2922c0eae66eSBenny Halevy goto out_overflow; 2923cccddf4fSBenny Halevy *len = be32_to_cpup(p); 2924c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 2925c0eae66eSBenny Halevy if (unlikely(!p)) 2926c0eae66eSBenny Halevy goto out_overflow; 29271da177e4SLinus Torvalds *string = (char *)p; 29281da177e4SLinus Torvalds return 0; 2929c0eae66eSBenny Halevy out_overflow: 2930c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2931c0eae66eSBenny Halevy return -EIO; 29321da177e4SLinus Torvalds } 29331da177e4SLinus Torvalds 29341da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 29351da177e4SLinus Torvalds { 29368687b63aSAl Viro __be32 *p; 29371da177e4SLinus Torvalds 2938c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 2939c0eae66eSBenny Halevy if (unlikely(!p)) 2940c0eae66eSBenny Halevy goto out_overflow; 29416f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 2942cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 29431da177e4SLinus Torvalds 2944c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 2945c0eae66eSBenny Halevy if (unlikely(!p)) 2946c0eae66eSBenny Halevy goto out_overflow; 29471da177e4SLinus Torvalds hdr->tag = (char *)p; 29481da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 2949cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 2950aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 2951aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 29521da177e4SLinus Torvalds return 0; 2953c0eae66eSBenny Halevy out_overflow: 2954c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2955c0eae66eSBenny Halevy return -EIO; 29561da177e4SLinus Torvalds } 29571da177e4SLinus Torvalds 29581da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 29591da177e4SLinus Torvalds { 29608687b63aSAl Viro __be32 *p; 29611da177e4SLinus Torvalds uint32_t opnum; 29621da177e4SLinus Torvalds int32_t nfserr; 29631da177e4SLinus Torvalds 2964c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 2965c0eae66eSBenny Halevy if (unlikely(!p)) 2966c0eae66eSBenny Halevy goto out_overflow; 29676f723f77SBenny Halevy opnum = be32_to_cpup(p++); 29681da177e4SLinus Torvalds if (opnum != expected) { 2969fe82a183SChuck Lever dprintk("nfs: Server returned operation" 29701da177e4SLinus Torvalds " %d but we issued a request for %d\n", 29711da177e4SLinus Torvalds opnum, expected); 29721da177e4SLinus Torvalds return -EIO; 29731da177e4SLinus Torvalds } 2974cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 29751da177e4SLinus Torvalds if (nfserr != NFS_OK) 2976856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 29771da177e4SLinus Torvalds return 0; 2978c0eae66eSBenny Halevy out_overflow: 2979c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2980c0eae66eSBenny Halevy return -EIO; 29811da177e4SLinus Torvalds } 29821da177e4SLinus Torvalds 29831da177e4SLinus Torvalds /* Dummy routine */ 2984adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 29851da177e4SLinus Torvalds { 29868687b63aSAl Viro __be32 *p; 2987683b57b4STrond Myklebust unsigned int strlen; 29881da177e4SLinus Torvalds char *str; 29891da177e4SLinus Torvalds 2990c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 2991c0eae66eSBenny Halevy if (likely(p)) 29921da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 2993c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 2994c0eae66eSBenny Halevy return -EIO; 29951da177e4SLinus Torvalds } 29961da177e4SLinus Torvalds 29971da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 29981da177e4SLinus Torvalds { 29998687b63aSAl Viro uint32_t bmlen; 30008687b63aSAl Viro __be32 *p; 30011da177e4SLinus Torvalds 3002c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3003c0eae66eSBenny Halevy if (unlikely(!p)) 3004c0eae66eSBenny Halevy goto out_overflow; 3005cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 30061da177e4SLinus Torvalds 3007dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3008c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3009c0eae66eSBenny Halevy if (unlikely(!p)) 3010c0eae66eSBenny Halevy goto out_overflow; 30111da177e4SLinus Torvalds if (bmlen > 0) { 30126f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3013dae100c2SFred Isaman if (bmlen > 1) { 3014dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3015dae100c2SFred Isaman if (bmlen > 2) 3016dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3017dae100c2SFred Isaman } 30181da177e4SLinus Torvalds } 30191da177e4SLinus Torvalds return 0; 3020c0eae66eSBenny Halevy out_overflow: 3021c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3022c0eae66eSBenny Halevy return -EIO; 30231da177e4SLinus Torvalds } 30241da177e4SLinus Torvalds 30258687b63aSAl Viro static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep) 30261da177e4SLinus Torvalds { 30278687b63aSAl Viro __be32 *p; 30281da177e4SLinus Torvalds 3029c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3030c0eae66eSBenny Halevy if (unlikely(!p)) 3031c0eae66eSBenny Halevy goto out_overflow; 3032cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 30331da177e4SLinus Torvalds *savep = xdr->p; 30341da177e4SLinus Torvalds return 0; 3035c0eae66eSBenny Halevy out_overflow: 3036c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3037c0eae66eSBenny Halevy return -EIO; 30381da177e4SLinus Torvalds } 30391da177e4SLinus Torvalds 30401da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 30411da177e4SLinus Torvalds { 30421da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 30433388bff5SRoman Borisov int ret; 30443388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 30453388bff5SRoman Borisov if (unlikely(ret < 0)) 30463388bff5SRoman Borisov return ret; 30471da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 30481da177e4SLinus Torvalds } else 3049dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3050dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3051dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 30521da177e4SLinus Torvalds return 0; 30531da177e4SLinus Torvalds } 30541da177e4SLinus Torvalds 30551da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 30561da177e4SLinus Torvalds { 30578687b63aSAl Viro __be32 *p; 3058409924e4STrond Myklebust int ret = 0; 30591da177e4SLinus Torvalds 30601da177e4SLinus Torvalds *type = 0; 30611da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 30621da177e4SLinus Torvalds return -EIO; 30631da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3064c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3065c0eae66eSBenny Halevy if (unlikely(!p)) 3066c0eae66eSBenny Halevy goto out_overflow; 3067cccddf4fSBenny Halevy *type = be32_to_cpup(p); 30681da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 30693110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 30701da177e4SLinus Torvalds return -EIO; 30711da177e4SLinus Torvalds } 30721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3073409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 30741da177e4SLinus Torvalds } 3075bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3076409924e4STrond Myklebust return ret; 3077c0eae66eSBenny Halevy out_overflow: 3078c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3079c0eae66eSBenny Halevy return -EIO; 30801da177e4SLinus Torvalds } 30811da177e4SLinus Torvalds 3082264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3083264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3084264e6351SChuck Lever { 3085264e6351SChuck Lever __be32 *p; 3086264e6351SChuck Lever 3087264e6351SChuck Lever *type = 0; 3088264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3089264e6351SChuck Lever return -EIO; 3090264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3091264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3092264e6351SChuck Lever if (unlikely(!p)) 3093264e6351SChuck Lever goto out_overflow; 3094264e6351SChuck Lever *type = be32_to_cpup(p); 3095264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3096264e6351SChuck Lever } 3097264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3098264e6351SChuck Lever return 0; 3099264e6351SChuck Lever out_overflow: 3100264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3101264e6351SChuck Lever return -EIO; 3102264e6351SChuck Lever } 3103264e6351SChuck Lever 31041da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 31051da177e4SLinus Torvalds { 31068687b63aSAl Viro __be32 *p; 3107409924e4STrond Myklebust int ret = 0; 31081da177e4SLinus Torvalds 31091da177e4SLinus Torvalds *change = 0; 31101da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 31111da177e4SLinus Torvalds return -EIO; 31121da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3113c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3114c0eae66eSBenny Halevy if (unlikely(!p)) 3115c0eae66eSBenny Halevy goto out_overflow; 3116cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 31171da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3118409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 31191da177e4SLinus Torvalds } 31203110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 31211da177e4SLinus Torvalds (unsigned long long)*change); 3122409924e4STrond Myklebust return ret; 3123c0eae66eSBenny Halevy out_overflow: 3124c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3125c0eae66eSBenny Halevy return -EIO; 31261da177e4SLinus Torvalds } 31271da177e4SLinus Torvalds 31281da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 31291da177e4SLinus Torvalds { 31308687b63aSAl Viro __be32 *p; 3131409924e4STrond Myklebust int ret = 0; 31321da177e4SLinus Torvalds 31331da177e4SLinus Torvalds *size = 0; 31341da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 31351da177e4SLinus Torvalds return -EIO; 31361da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3137c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3138c0eae66eSBenny Halevy if (unlikely(!p)) 3139c0eae66eSBenny Halevy goto out_overflow; 3140cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 31411da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3142409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 31431da177e4SLinus Torvalds } 31443110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3145409924e4STrond Myklebust return ret; 3146c0eae66eSBenny Halevy out_overflow: 3147c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3148c0eae66eSBenny Halevy return -EIO; 31491da177e4SLinus Torvalds } 31501da177e4SLinus Torvalds 31511da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 31521da177e4SLinus Torvalds { 31538687b63aSAl Viro __be32 *p; 31541da177e4SLinus Torvalds 31551da177e4SLinus Torvalds *res = 0; 31561da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 31571da177e4SLinus Torvalds return -EIO; 31581da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3159c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3160c0eae66eSBenny Halevy if (unlikely(!p)) 3161c0eae66eSBenny Halevy goto out_overflow; 3162cccddf4fSBenny Halevy *res = be32_to_cpup(p); 31631da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 31641da177e4SLinus Torvalds } 31653110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 31661da177e4SLinus Torvalds return 0; 3167c0eae66eSBenny Halevy out_overflow: 3168c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3169c0eae66eSBenny Halevy return -EIO; 31701da177e4SLinus Torvalds } 31711da177e4SLinus Torvalds 31721da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 31731da177e4SLinus Torvalds { 31748687b63aSAl Viro __be32 *p; 31751da177e4SLinus Torvalds 31761da177e4SLinus Torvalds *res = 0; 31771da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 31781da177e4SLinus Torvalds return -EIO; 31791da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3180c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3181c0eae66eSBenny Halevy if (unlikely(!p)) 3182c0eae66eSBenny Halevy goto out_overflow; 3183cccddf4fSBenny Halevy *res = be32_to_cpup(p); 31841da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 31851da177e4SLinus Torvalds } 31863110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 31871da177e4SLinus Torvalds return 0; 3188c0eae66eSBenny Halevy out_overflow: 3189c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3190c0eae66eSBenny Halevy return -EIO; 31911da177e4SLinus Torvalds } 31921da177e4SLinus Torvalds 31938b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 31941da177e4SLinus Torvalds { 31958687b63aSAl Viro __be32 *p; 3196409924e4STrond Myklebust int ret = 0; 31971da177e4SLinus Torvalds 31981da177e4SLinus Torvalds fsid->major = 0; 31991da177e4SLinus Torvalds fsid->minor = 0; 32001da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 32011da177e4SLinus Torvalds return -EIO; 32021da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3203c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3204c0eae66eSBenny Halevy if (unlikely(!p)) 3205c0eae66eSBenny Halevy goto out_overflow; 32063ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3207cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 32081da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3209409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 32101da177e4SLinus Torvalds } 32113110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 32121da177e4SLinus Torvalds (unsigned long long)fsid->major, 32131da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3214409924e4STrond Myklebust return ret; 3215c0eae66eSBenny Halevy out_overflow: 3216c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3217c0eae66eSBenny Halevy return -EIO; 32181da177e4SLinus Torvalds } 32191da177e4SLinus Torvalds 32201da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32211da177e4SLinus Torvalds { 32228687b63aSAl Viro __be32 *p; 32231da177e4SLinus Torvalds 32241da177e4SLinus Torvalds *res = 60; 32251da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 32261da177e4SLinus Torvalds return -EIO; 32271da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3228c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3229c0eae66eSBenny Halevy if (unlikely(!p)) 3230c0eae66eSBenny Halevy goto out_overflow; 3231cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32321da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 32331da177e4SLinus Torvalds } 32343110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 32351da177e4SLinus Torvalds return 0; 3236c0eae66eSBenny Halevy out_overflow: 3237c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3238c0eae66eSBenny Halevy return -EIO; 32391da177e4SLinus Torvalds } 32401da177e4SLinus Torvalds 3241ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3242ae42c70aSBryan Schumaker { 3243ae42c70aSBryan Schumaker __be32 *p; 3244ae42c70aSBryan Schumaker 3245ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3246ae42c70aSBryan Schumaker return -EIO; 3247ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3248ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3249ae42c70aSBryan Schumaker if (unlikely(!p)) 3250ae42c70aSBryan Schumaker goto out_overflow; 3251ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3252ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3253ae42c70aSBryan Schumaker } 3254ae42c70aSBryan Schumaker return 0; 3255ae42c70aSBryan Schumaker out_overflow: 3256ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3257ae42c70aSBryan Schumaker return -EIO; 3258ae42c70aSBryan Schumaker } 3259ae42c70aSBryan Schumaker 3260ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3261ae42c70aSBryan Schumaker { 3262ae42c70aSBryan Schumaker __be32 *p; 3263ae42c70aSBryan Schumaker int len; 3264ae42c70aSBryan Schumaker 32657ad07353STrond Myklebust if (fh != NULL) 3266ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3267ae42c70aSBryan Schumaker 3268ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3269ae42c70aSBryan Schumaker return -EIO; 3270ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3271ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3272ae42c70aSBryan Schumaker if (unlikely(!p)) 3273ae42c70aSBryan Schumaker goto out_overflow; 3274ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3275ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3276ae42c70aSBryan Schumaker return -EIO; 3277ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3278ae42c70aSBryan Schumaker if (unlikely(!p)) 3279ae42c70aSBryan Schumaker goto out_overflow; 32807ad07353STrond Myklebust if (fh != NULL) { 3281ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 32827ad07353STrond Myklebust fh->size = len; 32837ad07353STrond Myklebust } 3284ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3285ae42c70aSBryan Schumaker } 3286ae42c70aSBryan Schumaker return 0; 3287ae42c70aSBryan Schumaker out_overflow: 3288ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3289ae42c70aSBryan Schumaker return -EIO; 3290ae42c70aSBryan Schumaker } 3291ae42c70aSBryan Schumaker 32921da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32931da177e4SLinus Torvalds { 32948687b63aSAl Viro __be32 *p; 32951da177e4SLinus Torvalds 32961da177e4SLinus Torvalds *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 32971da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 32981da177e4SLinus Torvalds return -EIO; 32991da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3300c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3301c0eae66eSBenny Halevy if (unlikely(!p)) 3302c0eae66eSBenny Halevy goto out_overflow; 3303cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33041da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 33051da177e4SLinus Torvalds } 33063110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 33071da177e4SLinus Torvalds return 0; 3308c0eae66eSBenny Halevy out_overflow: 3309c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3310c0eae66eSBenny Halevy return -EIO; 33111da177e4SLinus Torvalds } 33121da177e4SLinus Torvalds 33131da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 33141da177e4SLinus Torvalds { 33158687b63aSAl Viro __be32 *p; 3316409924e4STrond Myklebust int ret = 0; 33171da177e4SLinus Torvalds 33181da177e4SLinus Torvalds *fileid = 0; 33191da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 33201da177e4SLinus Torvalds return -EIO; 33211da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3322c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3323c0eae66eSBenny Halevy if (unlikely(!p)) 3324c0eae66eSBenny Halevy goto out_overflow; 3325cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 33261da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3327409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 33281da177e4SLinus Torvalds } 33293110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3330409924e4STrond Myklebust return ret; 3331c0eae66eSBenny Halevy out_overflow: 3332c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3333c0eae66eSBenny Halevy return -EIO; 33341da177e4SLinus Torvalds } 33351da177e4SLinus Torvalds 333699baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 333799baf625SManoj Naik { 33388687b63aSAl Viro __be32 *p; 3339409924e4STrond Myklebust int ret = 0; 334099baf625SManoj Naik 334199baf625SManoj Naik *fileid = 0; 334299baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 334399baf625SManoj Naik return -EIO; 334499baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3345c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3346c0eae66eSBenny Halevy if (unlikely(!p)) 3347c0eae66eSBenny Halevy goto out_overflow; 3348cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 334999baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 335028331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 335199baf625SManoj Naik } 33523110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3353409924e4STrond Myklebust return ret; 3354c0eae66eSBenny Halevy out_overflow: 3355c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3356c0eae66eSBenny Halevy return -EIO; 335799baf625SManoj Naik } 335899baf625SManoj Naik 33591da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 33601da177e4SLinus Torvalds { 33618687b63aSAl Viro __be32 *p; 33621da177e4SLinus Torvalds int status = 0; 33631da177e4SLinus Torvalds 33641da177e4SLinus Torvalds *res = 0; 33651da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 33661da177e4SLinus Torvalds return -EIO; 33671da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3368c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3369c0eae66eSBenny Halevy if (unlikely(!p)) 3370c0eae66eSBenny Halevy goto out_overflow; 3371cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 33721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 33731da177e4SLinus Torvalds } 33743110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 33751da177e4SLinus Torvalds return status; 3376c0eae66eSBenny Halevy out_overflow: 3377c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3378c0eae66eSBenny Halevy return -EIO; 33791da177e4SLinus Torvalds } 33801da177e4SLinus Torvalds 33811da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 33821da177e4SLinus Torvalds { 33838687b63aSAl Viro __be32 *p; 33841da177e4SLinus Torvalds int status = 0; 33851da177e4SLinus Torvalds 33861da177e4SLinus Torvalds *res = 0; 33871da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 33881da177e4SLinus Torvalds return -EIO; 33891da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3390c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3391c0eae66eSBenny Halevy if (unlikely(!p)) 3392c0eae66eSBenny Halevy goto out_overflow; 3393cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 33941da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 33951da177e4SLinus Torvalds } 33963110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 33971da177e4SLinus Torvalds return status; 3398c0eae66eSBenny Halevy out_overflow: 3399c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3400c0eae66eSBenny Halevy return -EIO; 34011da177e4SLinus Torvalds } 34021da177e4SLinus Torvalds 34031da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34041da177e4SLinus Torvalds { 34058687b63aSAl Viro __be32 *p; 34061da177e4SLinus Torvalds int status = 0; 34071da177e4SLinus Torvalds 34081da177e4SLinus Torvalds *res = 0; 34091da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 34101da177e4SLinus Torvalds return -EIO; 34111da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3412c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3413c0eae66eSBenny Halevy if (unlikely(!p)) 3414c0eae66eSBenny Halevy goto out_overflow; 3415cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34161da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 34171da177e4SLinus Torvalds } 34183110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 34191da177e4SLinus Torvalds return status; 3420c0eae66eSBenny Halevy out_overflow: 3421c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3422c0eae66eSBenny Halevy return -EIO; 34231da177e4SLinus Torvalds } 34241da177e4SLinus Torvalds 34257aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 34267aaa0b3bSManoj Naik { 3427464ad6b1SChuck Lever u32 n; 34288687b63aSAl Viro __be32 *p; 34297aaa0b3bSManoj Naik int status = 0; 34307aaa0b3bSManoj Naik 3431c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3432c0eae66eSBenny Halevy if (unlikely(!p)) 3433c0eae66eSBenny Halevy goto out_overflow; 3434cccddf4fSBenny Halevy n = be32_to_cpup(p); 343533a43f28SAndy Adamson if (n == 0) 343633a43f28SAndy Adamson goto root_path; 343702a2976cSChuck Lever dprintk("pathname4: "); 34387aaa0b3bSManoj Naik path->ncomponents = 0; 34397aaa0b3bSManoj Naik while (path->ncomponents < n) { 34407aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 34417aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 34427aaa0b3bSManoj Naik if (unlikely(status != 0)) 34437aaa0b3bSManoj Naik goto out_eio; 344495a13f7bSTrond Myklebust ifdebug (XDR) 344502a2976cSChuck Lever pr_cont("%s%.*s ", 344602a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 344702a2976cSChuck Lever component->len, component->data); 34487aaa0b3bSManoj Naik if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 34497aaa0b3bSManoj Naik path->ncomponents++; 34507aaa0b3bSManoj Naik else { 34517aaa0b3bSManoj Naik dprintk("cannot parse %d components in path\n", n); 34527aaa0b3bSManoj Naik goto out_eio; 34537aaa0b3bSManoj Naik } 34547aaa0b3bSManoj Naik } 34557aaa0b3bSManoj Naik out: 34567aaa0b3bSManoj Naik return status; 345733a43f28SAndy Adamson root_path: 345833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 345933a43f28SAndy Adamson path->ncomponents = 1; 346033a43f28SAndy Adamson path->components[0].len=0; 346133a43f28SAndy Adamson path->components[0].data=NULL; 346202a2976cSChuck Lever dprintk("pathname4: /\n"); 346333a43f28SAndy Adamson goto out; 34647aaa0b3bSManoj Naik out_eio: 34657aaa0b3bSManoj Naik dprintk(" status %d", status); 34667aaa0b3bSManoj Naik status = -EIO; 34677aaa0b3bSManoj Naik goto out; 3468c0eae66eSBenny Halevy out_overflow: 3469c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3470c0eae66eSBenny Halevy return -EIO; 34717aaa0b3bSManoj Naik } 34727aaa0b3bSManoj Naik 34737aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3474683b57b4STrond Myklebust { 3475683b57b4STrond Myklebust int n; 34768687b63aSAl Viro __be32 *p; 3477683b57b4STrond Myklebust int status = -EIO; 3478683b57b4STrond Myklebust 3479683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3480683b57b4STrond Myklebust goto out; 3481683b57b4STrond Myklebust status = 0; 3482683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3483683b57b4STrond Myklebust goto out; 34848b7e3f49STrond Myklebust status = -EIO; 34858b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 34868b7e3f49STrond Myklebust if (unlikely(res == NULL)) 34878b7e3f49STrond Myklebust goto out; 348802a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 34897aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3490683b57b4STrond Myklebust if (unlikely(status != 0)) 3491683b57b4STrond Myklebust goto out; 3492c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3493c0eae66eSBenny Halevy if (unlikely(!p)) 3494c0eae66eSBenny Halevy goto out_overflow; 3495cccddf4fSBenny Halevy n = be32_to_cpup(p); 3496683b57b4STrond Myklebust if (n <= 0) 3497683b57b4STrond Myklebust goto out_eio; 3498683b57b4STrond Myklebust res->nlocations = 0; 3499683b57b4STrond Myklebust while (res->nlocations < n) { 3500464ad6b1SChuck Lever u32 m; 35017aaa0b3bSManoj Naik struct nfs4_fs_location *loc = &res->locations[res->nlocations]; 3502683b57b4STrond Myklebust 3503c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3504c0eae66eSBenny Halevy if (unlikely(!p)) 3505c0eae66eSBenny Halevy goto out_overflow; 3506cccddf4fSBenny Halevy m = be32_to_cpup(p); 35077aaa0b3bSManoj Naik 35087aaa0b3bSManoj Naik loc->nservers = 0; 350902a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 35107aaa0b3bSManoj Naik while (loc->nservers < m) { 35117aaa0b3bSManoj Naik struct nfs4_string *server = &loc->servers[loc->nservers]; 35127aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &server->len, &server->data); 3513683b57b4STrond Myklebust if (unlikely(status != 0)) 3514683b57b4STrond Myklebust goto out_eio; 35157aaa0b3bSManoj Naik dprintk("%s ", server->data); 35167aaa0b3bSManoj Naik if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS) 35177aaa0b3bSManoj Naik loc->nservers++; 35187aaa0b3bSManoj Naik else { 3519464ad6b1SChuck Lever unsigned int i; 3520464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3521464ad6b1SChuck Lever "returned for location %u\n", 35223110ff80SHarvey Harrison __func__, 3523464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3524464ad6b1SChuck Lever m, res->nlocations); 35257aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 35262e42c3e2STrond Myklebust unsigned int len; 35277aaa0b3bSManoj Naik char *data; 35287aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3529683b57b4STrond Myklebust if (unlikely(status != 0)) 3530683b57b4STrond Myklebust goto out_eio; 35317aaa0b3bSManoj Naik } 35327aaa0b3bSManoj Naik } 35337aaa0b3bSManoj Naik } 35347aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 35357aaa0b3bSManoj Naik if (unlikely(status != 0)) 35367aaa0b3bSManoj Naik goto out_eio; 35377aaa0b3bSManoj Naik if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES) 3538683b57b4STrond Myklebust res->nlocations++; 3539683b57b4STrond Myklebust } 3540409924e4STrond Myklebust if (res->nlocations != 0) 354181934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3542683b57b4STrond Myklebust out: 35433110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3544683b57b4STrond Myklebust return status; 3545c0eae66eSBenny Halevy out_overflow: 3546c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3547683b57b4STrond Myklebust out_eio: 3548683b57b4STrond Myklebust status = -EIO; 3549683b57b4STrond Myklebust goto out; 3550683b57b4STrond Myklebust } 3551683b57b4STrond Myklebust 35521da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35531da177e4SLinus Torvalds { 35548687b63aSAl Viro __be32 *p; 35551da177e4SLinus Torvalds int status = 0; 35561da177e4SLinus Torvalds 35571da177e4SLinus Torvalds *res = 0; 35581da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 35591da177e4SLinus Torvalds return -EIO; 35601da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3561c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3562c0eae66eSBenny Halevy if (unlikely(!p)) 3563c0eae66eSBenny Halevy goto out_overflow; 3564cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35651da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 35661da177e4SLinus Torvalds } 35673110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 35681da177e4SLinus Torvalds return status; 3569c0eae66eSBenny Halevy out_overflow: 3570c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3571c0eae66eSBenny Halevy return -EIO; 35721da177e4SLinus Torvalds } 35731da177e4SLinus Torvalds 35741da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 35751da177e4SLinus Torvalds { 35768687b63aSAl Viro __be32 *p; 35771da177e4SLinus Torvalds int status = 0; 35781da177e4SLinus Torvalds 35791da177e4SLinus Torvalds *maxlink = 1; 35801da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 35811da177e4SLinus Torvalds return -EIO; 35821da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3583c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3584c0eae66eSBenny Halevy if (unlikely(!p)) 3585c0eae66eSBenny Halevy goto out_overflow; 3586cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 35871da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 35881da177e4SLinus Torvalds } 35893110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 35901da177e4SLinus Torvalds return status; 3591c0eae66eSBenny Halevy out_overflow: 3592c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3593c0eae66eSBenny Halevy return -EIO; 35941da177e4SLinus Torvalds } 35951da177e4SLinus Torvalds 35961da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 35971da177e4SLinus Torvalds { 35988687b63aSAl Viro __be32 *p; 35991da177e4SLinus Torvalds int status = 0; 36001da177e4SLinus Torvalds 36011da177e4SLinus Torvalds *maxname = 1024; 36021da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 36031da177e4SLinus Torvalds return -EIO; 36041da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3605c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3606c0eae66eSBenny Halevy if (unlikely(!p)) 3607c0eae66eSBenny Halevy goto out_overflow; 3608cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 36091da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 36101da177e4SLinus Torvalds } 36113110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 36121da177e4SLinus Torvalds return status; 3613c0eae66eSBenny Halevy out_overflow: 3614c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3615c0eae66eSBenny Halevy return -EIO; 36161da177e4SLinus Torvalds } 36171da177e4SLinus Torvalds 36181da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36191da177e4SLinus Torvalds { 36208687b63aSAl Viro __be32 *p; 36211da177e4SLinus Torvalds int status = 0; 36221da177e4SLinus Torvalds 36231da177e4SLinus Torvalds *res = 1024; 36241da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 36251da177e4SLinus Torvalds return -EIO; 36261da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 36271da177e4SLinus Torvalds uint64_t maxread; 3628c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3629c0eae66eSBenny Halevy if (unlikely(!p)) 3630c0eae66eSBenny Halevy goto out_overflow; 3631cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 36321da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 36331da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 36341da177e4SLinus Torvalds *res = (uint32_t)maxread; 36351da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 36361da177e4SLinus Torvalds } 36373110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 36381da177e4SLinus Torvalds return status; 3639c0eae66eSBenny Halevy out_overflow: 3640c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3641c0eae66eSBenny Halevy return -EIO; 36421da177e4SLinus Torvalds } 36431da177e4SLinus Torvalds 36441da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 36451da177e4SLinus Torvalds { 36468687b63aSAl Viro __be32 *p; 36471da177e4SLinus Torvalds int status = 0; 36481da177e4SLinus Torvalds 36491da177e4SLinus Torvalds *res = 1024; 36501da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 36511da177e4SLinus Torvalds return -EIO; 36521da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 36531da177e4SLinus Torvalds uint64_t maxwrite; 3654c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3655c0eae66eSBenny Halevy if (unlikely(!p)) 3656c0eae66eSBenny Halevy goto out_overflow; 3657cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 36581da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 36591da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 36601da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 36611da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 36621da177e4SLinus Torvalds } 36633110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 36641da177e4SLinus Torvalds return status; 3665c0eae66eSBenny Halevy out_overflow: 3666c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3667c0eae66eSBenny Halevy return -EIO; 36681da177e4SLinus Torvalds } 36691da177e4SLinus Torvalds 3670bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 36711da177e4SLinus Torvalds { 3672bca79478STrond Myklebust uint32_t tmp; 36738687b63aSAl Viro __be32 *p; 3674409924e4STrond Myklebust int ret = 0; 36751da177e4SLinus Torvalds 36761da177e4SLinus Torvalds *mode = 0; 36771da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 36781da177e4SLinus Torvalds return -EIO; 36791da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3680c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3681c0eae66eSBenny Halevy if (unlikely(!p)) 3682c0eae66eSBenny Halevy goto out_overflow; 3683cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3684bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 36851da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3686409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 36871da177e4SLinus Torvalds } 36883110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3689409924e4STrond Myklebust return ret; 3690c0eae66eSBenny Halevy out_overflow: 3691c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3692c0eae66eSBenny Halevy return -EIO; 36931da177e4SLinus Torvalds } 36941da177e4SLinus Torvalds 36951da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 36961da177e4SLinus Torvalds { 36978687b63aSAl Viro __be32 *p; 3698409924e4STrond Myklebust int ret = 0; 36991da177e4SLinus Torvalds 37001da177e4SLinus Torvalds *nlink = 1; 37011da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 37021da177e4SLinus Torvalds return -EIO; 37031da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3704c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3705c0eae66eSBenny Halevy if (unlikely(!p)) 3706c0eae66eSBenny Halevy goto out_overflow; 3707cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 37081da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3709409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 37101da177e4SLinus Torvalds } 37113110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3712409924e4STrond Myklebust return ret; 3713c0eae66eSBenny Halevy out_overflow: 3714c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3715c0eae66eSBenny Halevy return -EIO; 37161da177e4SLinus Torvalds } 37171da177e4SLinus Torvalds 371880e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 37196926afd1STrond Myklebust const struct nfs_server *server, uint32_t *uid, 37206926afd1STrond Myklebust struct nfs4_string *owner_name) 37211da177e4SLinus Torvalds { 37228687b63aSAl Viro uint32_t len; 37238687b63aSAl Viro __be32 *p; 3724409924e4STrond Myklebust int ret = 0; 37251da177e4SLinus Torvalds 37261da177e4SLinus Torvalds *uid = -2; 37271da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 37281da177e4SLinus Torvalds return -EIO; 37291da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3730c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3731c0eae66eSBenny Halevy if (unlikely(!p)) 3732c0eae66eSBenny Halevy goto out_overflow; 3733cccddf4fSBenny Halevy len = be32_to_cpup(p); 3734c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3735c0eae66eSBenny Halevy if (unlikely(!p)) 3736c0eae66eSBenny Halevy goto out_overflow; 37376926afd1STrond Myklebust if (owner_name != NULL) { 37386926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 37396926afd1STrond Myklebust if (owner_name->data != NULL) { 37406926afd1STrond Myklebust owner_name->len = len; 37416926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 37426926afd1STrond Myklebust } 374380e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3744e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3745409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3746409924e4STrond Myklebust else 37471da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 37483110ff80SHarvey Harrison __func__); 37491da177e4SLinus Torvalds } else 3750fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 37513110ff80SHarvey Harrison __func__, len); 37521da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 37531da177e4SLinus Torvalds } 37543110ff80SHarvey Harrison dprintk("%s: uid=%d\n", __func__, (int)*uid); 3755409924e4STrond Myklebust return ret; 3756c0eae66eSBenny Halevy out_overflow: 3757c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3758c0eae66eSBenny Halevy return -EIO; 37591da177e4SLinus Torvalds } 37601da177e4SLinus Torvalds 376180e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 37626926afd1STrond Myklebust const struct nfs_server *server, uint32_t *gid, 37636926afd1STrond Myklebust struct nfs4_string *group_name) 37641da177e4SLinus Torvalds { 37658687b63aSAl Viro uint32_t len; 37668687b63aSAl Viro __be32 *p; 3767409924e4STrond Myklebust int ret = 0; 37681da177e4SLinus Torvalds 37691da177e4SLinus Torvalds *gid = -2; 37701da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 37711da177e4SLinus Torvalds return -EIO; 37721da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3773c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3774c0eae66eSBenny Halevy if (unlikely(!p)) 3775c0eae66eSBenny Halevy goto out_overflow; 3776cccddf4fSBenny Halevy len = be32_to_cpup(p); 3777c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3778c0eae66eSBenny Halevy if (unlikely(!p)) 3779c0eae66eSBenny Halevy goto out_overflow; 37806926afd1STrond Myklebust if (group_name != NULL) { 37816926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 37826926afd1STrond Myklebust if (group_name->data != NULL) { 37836926afd1STrond Myklebust group_name->len = len; 37846926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 37856926afd1STrond Myklebust } 378680e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3787e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3788409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3789409924e4STrond Myklebust else 37901da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 37913110ff80SHarvey Harrison __func__); 37921da177e4SLinus Torvalds } else 3793fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 37943110ff80SHarvey Harrison __func__, len); 37951da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 37961da177e4SLinus Torvalds } 37973110ff80SHarvey Harrison dprintk("%s: gid=%d\n", __func__, (int)*gid); 3798409924e4STrond Myklebust return ret; 3799c0eae66eSBenny Halevy out_overflow: 3800c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3801c0eae66eSBenny Halevy return -EIO; 38021da177e4SLinus Torvalds } 38031da177e4SLinus Torvalds 38041da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 38051da177e4SLinus Torvalds { 38068687b63aSAl Viro uint32_t major = 0, minor = 0; 38078687b63aSAl Viro __be32 *p; 3808409924e4STrond Myklebust int ret = 0; 38091da177e4SLinus Torvalds 38101da177e4SLinus Torvalds *rdev = MKDEV(0,0); 38111da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 38121da177e4SLinus Torvalds return -EIO; 38131da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 38141da177e4SLinus Torvalds dev_t tmp; 38151da177e4SLinus Torvalds 3816c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3817c0eae66eSBenny Halevy if (unlikely(!p)) 3818c0eae66eSBenny Halevy goto out_overflow; 38196f723f77SBenny Halevy major = be32_to_cpup(p++); 3820cccddf4fSBenny Halevy minor = be32_to_cpup(p); 38211da177e4SLinus Torvalds tmp = MKDEV(major, minor); 38221da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 38231da177e4SLinus Torvalds *rdev = tmp; 38241da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3825409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 38261da177e4SLinus Torvalds } 38273110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3828409924e4STrond Myklebust return ret; 3829c0eae66eSBenny Halevy out_overflow: 3830c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3831c0eae66eSBenny Halevy return -EIO; 38321da177e4SLinus Torvalds } 38331da177e4SLinus Torvalds 38341da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38351da177e4SLinus Torvalds { 38368687b63aSAl Viro __be32 *p; 38371da177e4SLinus Torvalds int status = 0; 38381da177e4SLinus Torvalds 38391da177e4SLinus Torvalds *res = 0; 38401da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 38411da177e4SLinus Torvalds return -EIO; 38421da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3843c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3844c0eae66eSBenny Halevy if (unlikely(!p)) 3845c0eae66eSBenny Halevy goto out_overflow; 3846cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38471da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 38481da177e4SLinus Torvalds } 38493110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 38501da177e4SLinus Torvalds return status; 3851c0eae66eSBenny Halevy out_overflow: 3852c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3853c0eae66eSBenny Halevy return -EIO; 38541da177e4SLinus Torvalds } 38551da177e4SLinus Torvalds 38561da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38571da177e4SLinus Torvalds { 38588687b63aSAl Viro __be32 *p; 38591da177e4SLinus Torvalds int status = 0; 38601da177e4SLinus Torvalds 38611da177e4SLinus Torvalds *res = 0; 38621da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 38631da177e4SLinus Torvalds return -EIO; 38641da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3865c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3866c0eae66eSBenny Halevy if (unlikely(!p)) 3867c0eae66eSBenny Halevy goto out_overflow; 3868cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38691da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 38701da177e4SLinus Torvalds } 38713110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 38721da177e4SLinus Torvalds return status; 3873c0eae66eSBenny Halevy out_overflow: 3874c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3875c0eae66eSBenny Halevy return -EIO; 38761da177e4SLinus Torvalds } 38771da177e4SLinus Torvalds 38781da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38791da177e4SLinus Torvalds { 38808687b63aSAl Viro __be32 *p; 38811da177e4SLinus Torvalds int status = 0; 38821da177e4SLinus Torvalds 38831da177e4SLinus Torvalds *res = 0; 38841da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 38851da177e4SLinus Torvalds return -EIO; 38861da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 3887c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3888c0eae66eSBenny Halevy if (unlikely(!p)) 3889c0eae66eSBenny Halevy goto out_overflow; 3890cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38911da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 38921da177e4SLinus Torvalds } 38933110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 38941da177e4SLinus Torvalds return status; 3895c0eae66eSBenny Halevy out_overflow: 3896c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3897c0eae66eSBenny Halevy return -EIO; 38981da177e4SLinus Torvalds } 38991da177e4SLinus Torvalds 39001da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 39011da177e4SLinus Torvalds { 39028687b63aSAl Viro __be32 *p; 3903409924e4STrond Myklebust int ret = 0; 39041da177e4SLinus Torvalds 39051da177e4SLinus Torvalds *used = 0; 39061da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 39071da177e4SLinus Torvalds return -EIO; 39081da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 3909c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3910c0eae66eSBenny Halevy if (unlikely(!p)) 3911c0eae66eSBenny Halevy goto out_overflow; 3912cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 39131da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 3914409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 39151da177e4SLinus Torvalds } 39163110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 39171da177e4SLinus Torvalds (unsigned long long)*used); 3918409924e4STrond Myklebust return ret; 3919c0eae66eSBenny Halevy out_overflow: 3920c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3921c0eae66eSBenny Halevy return -EIO; 39221da177e4SLinus Torvalds } 39231da177e4SLinus Torvalds 39241da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 39251da177e4SLinus Torvalds { 39268687b63aSAl Viro __be32 *p; 39271da177e4SLinus Torvalds uint64_t sec; 39281da177e4SLinus Torvalds uint32_t nsec; 39291da177e4SLinus Torvalds 3930c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3931c0eae66eSBenny Halevy if (unlikely(!p)) 3932c0eae66eSBenny Halevy goto out_overflow; 39333ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 3934cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 39351da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 39361da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 39371da177e4SLinus Torvalds return 0; 3938c0eae66eSBenny Halevy out_overflow: 3939c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3940c0eae66eSBenny Halevy return -EIO; 39411da177e4SLinus Torvalds } 39421da177e4SLinus Torvalds 39431da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39441da177e4SLinus Torvalds { 39451da177e4SLinus Torvalds int status = 0; 39461da177e4SLinus Torvalds 39471da177e4SLinus Torvalds time->tv_sec = 0; 39481da177e4SLinus Torvalds time->tv_nsec = 0; 39491da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 39501da177e4SLinus Torvalds return -EIO; 39511da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 39521da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 3953409924e4STrond Myklebust if (status == 0) 3954409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 39551da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 39561da177e4SLinus Torvalds } 39573110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 39581da177e4SLinus Torvalds return status; 39591da177e4SLinus Torvalds } 39601da177e4SLinus Torvalds 39611da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39621da177e4SLinus Torvalds { 39631da177e4SLinus Torvalds int status = 0; 39641da177e4SLinus Torvalds 39651da177e4SLinus Torvalds time->tv_sec = 0; 39661da177e4SLinus Torvalds time->tv_nsec = 0; 39671da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 39681da177e4SLinus Torvalds return -EIO; 39691da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 39701da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 3971409924e4STrond Myklebust if (status == 0) 3972409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 39731da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 39741da177e4SLinus Torvalds } 39753110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 39761da177e4SLinus Torvalds return status; 39771da177e4SLinus Torvalds } 39781da177e4SLinus Torvalds 397955b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 398055b6e774SRicardo Labiaga struct timespec *time) 398155b6e774SRicardo Labiaga { 398255b6e774SRicardo Labiaga int status = 0; 398355b6e774SRicardo Labiaga 398455b6e774SRicardo Labiaga time->tv_sec = 0; 398555b6e774SRicardo Labiaga time->tv_nsec = 0; 398655b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 398755b6e774SRicardo Labiaga return -EIO; 398855b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 398955b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 399055b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 399155b6e774SRicardo Labiaga } 399255b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 399355b6e774SRicardo Labiaga (long)time->tv_nsec); 399455b6e774SRicardo Labiaga return status; 399555b6e774SRicardo Labiaga } 399655b6e774SRicardo Labiaga 39971da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 39981da177e4SLinus Torvalds { 39991da177e4SLinus Torvalds int status = 0; 40001da177e4SLinus Torvalds 40011da177e4SLinus Torvalds time->tv_sec = 0; 40021da177e4SLinus Torvalds time->tv_nsec = 0; 40031da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 40041da177e4SLinus Torvalds return -EIO; 40051da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 40061da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4007409924e4STrond Myklebust if (status == 0) 4008409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 40091da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 40101da177e4SLinus Torvalds } 40113110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 40121da177e4SLinus Torvalds return status; 40131da177e4SLinus Torvalds } 40141da177e4SLinus Torvalds 40158687b63aSAl Viro static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen) 40161da177e4SLinus Torvalds { 40171da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 40181da177e4SLinus Torvalds unsigned int nwords = xdr->p - savep; 40191da177e4SLinus Torvalds 40201da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4021fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4022fe82a183SChuck Lever "%u %c %u\n", 40233110ff80SHarvey Harrison __func__, 40241da177e4SLinus Torvalds attrwords << 2, 40251da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 40261da177e4SLinus Torvalds nwords << 2); 40271da177e4SLinus Torvalds return -EIO; 40281da177e4SLinus Torvalds } 40291da177e4SLinus Torvalds return 0; 40301da177e4SLinus Torvalds } 40311da177e4SLinus Torvalds 40321da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 40331da177e4SLinus Torvalds { 40348687b63aSAl Viro __be32 *p; 40351da177e4SLinus Torvalds 4036c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4037c0eae66eSBenny Halevy if (unlikely(!p)) 4038c0eae66eSBenny Halevy goto out_overflow; 40396f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 40403ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4041cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 40421da177e4SLinus Torvalds return 0; 4043c0eae66eSBenny Halevy out_overflow: 4044c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4045c0eae66eSBenny Halevy return -EIO; 40461da177e4SLinus Torvalds } 40471da177e4SLinus Torvalds 40481da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access) 40491da177e4SLinus Torvalds { 40508687b63aSAl Viro __be32 *p; 40511da177e4SLinus Torvalds uint32_t supp, acc; 40521da177e4SLinus Torvalds int status; 40531da177e4SLinus Torvalds 40541da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 40551da177e4SLinus Torvalds if (status) 40561da177e4SLinus Torvalds return status; 4057c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4058c0eae66eSBenny Halevy if (unlikely(!p)) 4059c0eae66eSBenny Halevy goto out_overflow; 40606f723f77SBenny Halevy supp = be32_to_cpup(p++); 4061cccddf4fSBenny Halevy acc = be32_to_cpup(p); 40621da177e4SLinus Torvalds access->supported = supp; 40631da177e4SLinus Torvalds access->access = acc; 40641da177e4SLinus Torvalds return 0; 4065c0eae66eSBenny Halevy out_overflow: 4066c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4067c0eae66eSBenny Halevy return -EIO; 40681da177e4SLinus Torvalds } 40691da177e4SLinus Torvalds 407007d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 40711da177e4SLinus Torvalds { 40728687b63aSAl Viro __be32 *p; 407307d30434SBenny Halevy 407407d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 407507d30434SBenny Halevy if (likely(p)) { 407607d30434SBenny Halevy memcpy(buf, p, len); 407707d30434SBenny Halevy return 0; 407807d30434SBenny Halevy } 407907d30434SBenny Halevy print_overflow_msg(__func__, xdr); 408007d30434SBenny Halevy return -EIO; 408107d30434SBenny Halevy } 408207d30434SBenny Halevy 408307d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 408407d30434SBenny Halevy { 40852d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 40861da177e4SLinus Torvalds } 40871da177e4SLinus Torvalds 40881da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 40891da177e4SLinus Torvalds { 40901da177e4SLinus Torvalds int status; 40911da177e4SLinus Torvalds 40921da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4093c1d51931STrond Myklebust if (status != -EIO) 4094c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 409507d30434SBenny Halevy if (!status) 409607d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 40971da177e4SLinus Torvalds return status; 40981da177e4SLinus Torvalds } 40991da177e4SLinus Torvalds 4100db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4101db942bbdSBenny Halevy { 4102cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 41031da177e4SLinus Torvalds } 41041da177e4SLinus Torvalds 41050b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 41061da177e4SLinus Torvalds { 41071da177e4SLinus Torvalds int status; 41081da177e4SLinus Torvalds 41091da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4110db942bbdSBenny Halevy if (!status) 4111db942bbdSBenny Halevy status = decode_verifier(xdr, res->verf->verifier); 41121da177e4SLinus Torvalds return status; 41131da177e4SLinus Torvalds } 41141da177e4SLinus Torvalds 41151da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 41161da177e4SLinus Torvalds { 41178687b63aSAl Viro __be32 *p; 41181da177e4SLinus Torvalds uint32_t bmlen; 41191da177e4SLinus Torvalds int status; 41201da177e4SLinus Torvalds 41211da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 41221da177e4SLinus Torvalds if (status) 41231da177e4SLinus Torvalds return status; 41241da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 41251da177e4SLinus Torvalds return status; 4126c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4127c0eae66eSBenny Halevy if (unlikely(!p)) 4128c0eae66eSBenny Halevy goto out_overflow; 4129cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4130c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4131c0eae66eSBenny Halevy if (likely(p)) 41321da177e4SLinus Torvalds return 0; 4133c0eae66eSBenny Halevy out_overflow: 4134c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4135c0eae66eSBenny Halevy return -EIO; 41361da177e4SLinus Torvalds } 41371da177e4SLinus Torvalds 41381da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 41391da177e4SLinus Torvalds { 41408687b63aSAl Viro __be32 *savep; 4141dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41421da177e4SLinus Torvalds int status; 41431da177e4SLinus Torvalds 41441da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 41451da177e4SLinus Torvalds goto xdr_error; 41461da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 41471da177e4SLinus Torvalds goto xdr_error; 41481da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 41491da177e4SLinus Torvalds goto xdr_error; 41501da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 41511da177e4SLinus Torvalds goto xdr_error; 4152264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4153264e6351SChuck Lever &res->fh_expire_type)) != 0) 4154264e6351SChuck Lever goto xdr_error; 41551da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 41561da177e4SLinus Torvalds goto xdr_error; 41571da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 41581da177e4SLinus Torvalds goto xdr_error; 41591da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 41601da177e4SLinus Torvalds goto xdr_error; 41611da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 41621da177e4SLinus Torvalds xdr_error: 41633110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 41641da177e4SLinus Torvalds return status; 41651da177e4SLinus Torvalds } 41661da177e4SLinus Torvalds 41671da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 41681da177e4SLinus Torvalds { 41698687b63aSAl Viro __be32 *savep; 4170dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 41711da177e4SLinus Torvalds int status; 41721da177e4SLinus Torvalds 41731da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 41741da177e4SLinus Torvalds goto xdr_error; 41751da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 41761da177e4SLinus Torvalds goto xdr_error; 41771da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 41781da177e4SLinus Torvalds goto xdr_error; 41791da177e4SLinus Torvalds 41801da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 41811da177e4SLinus Torvalds goto xdr_error; 41821da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 41831da177e4SLinus Torvalds goto xdr_error; 41841da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 41851da177e4SLinus Torvalds goto xdr_error; 41861da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 41871da177e4SLinus Torvalds goto xdr_error; 41881da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 41891da177e4SLinus Torvalds goto xdr_error; 41901da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 41911da177e4SLinus Torvalds goto xdr_error; 41921da177e4SLinus Torvalds 41931da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 41941da177e4SLinus Torvalds xdr_error: 41953110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 41961da177e4SLinus Torvalds return status; 41971da177e4SLinus Torvalds } 41981da177e4SLinus Torvalds 41991da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 42001da177e4SLinus Torvalds { 42018687b63aSAl Viro __be32 *savep; 4202dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 42031da177e4SLinus Torvalds int status; 42041da177e4SLinus Torvalds 42051da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 42061da177e4SLinus Torvalds goto xdr_error; 42071da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 42081da177e4SLinus Torvalds goto xdr_error; 42091da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 42101da177e4SLinus Torvalds goto xdr_error; 42111da177e4SLinus Torvalds 42121da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 42131da177e4SLinus Torvalds goto xdr_error; 42141da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 42151da177e4SLinus Torvalds goto xdr_error; 42161da177e4SLinus Torvalds 42171da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 42181da177e4SLinus Torvalds xdr_error: 42193110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 42201da177e4SLinus Torvalds return status; 42211da177e4SLinus Torvalds } 42221da177e4SLinus Torvalds 4223ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4224ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 42258b7e3f49STrond Myklebust struct nfs4_fs_locations *fs_loc, 42266926afd1STrond Myklebust const struct nfs_server *server) 42271da177e4SLinus Torvalds { 4228bca79478STrond Myklebust int status; 4229bca79478STrond Myklebust umode_t fmode = 0; 4230ae42c70aSBryan Schumaker uint32_t type; 4231ee7b75fcSTrond Myklebust int32_t err; 42321da177e4SLinus Torvalds 4233f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4234f26c7a78STrond Myklebust if (status < 0) 42351da177e4SLinus Torvalds goto xdr_error; 4236409924e4STrond Myklebust fattr->mode = 0; 4237409924e4STrond Myklebust if (status != 0) { 4238409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4239409924e4STrond Myklebust fattr->valid |= status; 4240409924e4STrond Myklebust } 42411da177e4SLinus Torvalds 4242f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4243f26c7a78STrond Myklebust if (status < 0) 42441da177e4SLinus Torvalds goto xdr_error; 4245409924e4STrond Myklebust fattr->valid |= status; 4246f26c7a78STrond Myklebust 4247f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4248f26c7a78STrond Myklebust if (status < 0) 42491da177e4SLinus Torvalds goto xdr_error; 4250409924e4STrond Myklebust fattr->valid |= status; 4251f26c7a78STrond Myklebust 4252f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4253f26c7a78STrond Myklebust if (status < 0) 42541da177e4SLinus Torvalds goto xdr_error; 4255409924e4STrond Myklebust fattr->valid |= status; 4256f26c7a78STrond Myklebust 4257ee7b75fcSTrond Myklebust err = 0; 4258ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4259ae42c70aSBryan Schumaker if (status < 0) 4260ae42c70aSBryan Schumaker goto xdr_error; 4261ae42c70aSBryan Schumaker 4262ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4263ae42c70aSBryan Schumaker if (status < 0) 4264ae42c70aSBryan Schumaker goto xdr_error; 4265ae42c70aSBryan Schumaker 4266f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4267f26c7a78STrond Myklebust if (status < 0) 42681da177e4SLinus Torvalds goto xdr_error; 4269409924e4STrond Myklebust fattr->valid |= status; 4270f26c7a78STrond Myklebust 42718b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4272f26c7a78STrond Myklebust if (status < 0) 4273683b57b4STrond Myklebust goto xdr_error; 4274409924e4STrond Myklebust fattr->valid |= status; 4275f26c7a78STrond Myklebust 4276f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4277f26c7a78STrond Myklebust if (status < 0) 42781da177e4SLinus Torvalds goto xdr_error; 4279409924e4STrond Myklebust if (status != 0) { 42801da177e4SLinus Torvalds fattr->mode |= fmode; 4281409924e4STrond Myklebust fattr->valid |= status; 4282409924e4STrond Myklebust } 4283f26c7a78STrond Myklebust 4284f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4285f26c7a78STrond Myklebust if (status < 0) 42861da177e4SLinus Torvalds goto xdr_error; 4287409924e4STrond Myklebust fattr->valid |= status; 4288f26c7a78STrond Myklebust 42896926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4290f26c7a78STrond Myklebust if (status < 0) 42911da177e4SLinus Torvalds goto xdr_error; 4292409924e4STrond Myklebust fattr->valid |= status; 4293f26c7a78STrond Myklebust 42946926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4295f26c7a78STrond Myklebust if (status < 0) 42961da177e4SLinus Torvalds goto xdr_error; 4297409924e4STrond Myklebust fattr->valid |= status; 4298f26c7a78STrond Myklebust 4299f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4300f26c7a78STrond Myklebust if (status < 0) 43011da177e4SLinus Torvalds goto xdr_error; 4302409924e4STrond Myklebust fattr->valid |= status; 4303f26c7a78STrond Myklebust 4304f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4305f26c7a78STrond Myklebust if (status < 0) 43061da177e4SLinus Torvalds goto xdr_error; 4307409924e4STrond Myklebust fattr->valid |= status; 4308f26c7a78STrond Myklebust 4309f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4310f26c7a78STrond Myklebust if (status < 0) 43111da177e4SLinus Torvalds goto xdr_error; 4312409924e4STrond Myklebust fattr->valid |= status; 4313f26c7a78STrond Myklebust 4314f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4315f26c7a78STrond Myklebust if (status < 0) 43161da177e4SLinus Torvalds goto xdr_error; 4317409924e4STrond Myklebust fattr->valid |= status; 4318f26c7a78STrond Myklebust 4319f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4320f26c7a78STrond Myklebust if (status < 0) 43211da177e4SLinus Torvalds goto xdr_error; 4322409924e4STrond Myklebust fattr->valid |= status; 4323f26c7a78STrond Myklebust 432428331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4325f26c7a78STrond Myklebust if (status < 0) 432699baf625SManoj Naik goto xdr_error; 4327409924e4STrond Myklebust fattr->valid |= status; 4328f26c7a78STrond Myklebust 4329ae42c70aSBryan Schumaker xdr_error: 4330ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4331ae42c70aSBryan Schumaker return status; 4332ae42c70aSBryan Schumaker } 4333ae42c70aSBryan Schumaker 4334ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 43358b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 43368b7e3f49STrond Myklebust const struct nfs_server *server) 4337ae42c70aSBryan Schumaker { 4338ae42c70aSBryan Schumaker __be32 *savep; 4339ae42c70aSBryan Schumaker uint32_t attrlen, 4340dae100c2SFred Isaman bitmap[3] = {0}; 4341ae42c70aSBryan Schumaker int status; 4342ae42c70aSBryan Schumaker 4343ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4344ae42c70aSBryan Schumaker if (status < 0) 4345ae42c70aSBryan Schumaker goto xdr_error; 4346ae42c70aSBryan Schumaker 4347ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4348ae42c70aSBryan Schumaker if (status < 0) 4349ae42c70aSBryan Schumaker goto xdr_error; 4350ae42c70aSBryan Schumaker 4351ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4352ae42c70aSBryan Schumaker if (status < 0) 4353ae42c70aSBryan Schumaker goto xdr_error; 4354ae42c70aSBryan Schumaker 43558b7e3f49STrond Myklebust status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server); 4356ae42c70aSBryan Schumaker if (status < 0) 4357ae42c70aSBryan Schumaker goto xdr_error; 4358ae42c70aSBryan Schumaker 4359f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 43601da177e4SLinus Torvalds xdr_error: 43613110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 43621da177e4SLinus Torvalds return status; 43631da177e4SLinus Torvalds } 43641da177e4SLinus Torvalds 4365ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 43666926afd1STrond Myklebust const struct nfs_server *server) 4367ae42c70aSBryan Schumaker { 43688b7e3f49STrond Myklebust return decode_getfattr_generic(xdr, fattr, NULL, NULL, server); 4369ae42c70aSBryan Schumaker } 43701da177e4SLinus Torvalds 4371504913fbSAndy Adamson /* 4372504913fbSAndy Adamson * Decode potentially multiple layout types. Currently we only support 4373504913fbSAndy Adamson * one layout driver per file system. 4374504913fbSAndy Adamson */ 4375504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, 4376504913fbSAndy Adamson uint32_t *layouttype) 4377504913fbSAndy Adamson { 4378504913fbSAndy Adamson uint32_t *p; 4379504913fbSAndy Adamson int num; 4380504913fbSAndy Adamson 4381504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4382504913fbSAndy Adamson if (unlikely(!p)) 4383504913fbSAndy Adamson goto out_overflow; 4384504913fbSAndy Adamson num = be32_to_cpup(p); 4385504913fbSAndy Adamson 4386504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4387504913fbSAndy Adamson if (num == 0) { 4388504913fbSAndy Adamson *layouttype = 0; 4389504913fbSAndy Adamson return 0; 4390504913fbSAndy Adamson } 4391504913fbSAndy Adamson if (num > 1) 4392a030889aSWeston Andros Adamson printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout " 4393a030889aSWeston Andros Adamson "drivers per filesystem not supported\n", __func__); 4394504913fbSAndy Adamson 4395504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4396504913fbSAndy Adamson p = xdr_inline_decode(xdr, num * 4); 4397504913fbSAndy Adamson if (unlikely(!p)) 4398504913fbSAndy Adamson goto out_overflow; 4399504913fbSAndy Adamson *layouttype = be32_to_cpup(p); 4400504913fbSAndy Adamson return 0; 4401504913fbSAndy Adamson out_overflow: 4402504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4403504913fbSAndy Adamson return -EIO; 4404504913fbSAndy Adamson } 4405504913fbSAndy Adamson 4406504913fbSAndy Adamson /* 4407504913fbSAndy Adamson * The type of file system exported. 4408504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4409504913fbSAndy Adamson */ 4410504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4411504913fbSAndy Adamson uint32_t *layouttype) 4412504913fbSAndy Adamson { 4413504913fbSAndy Adamson int status = 0; 4414504913fbSAndy Adamson 4415504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4416504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4417504913fbSAndy Adamson return -EIO; 4418504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4419504913fbSAndy Adamson status = decode_first_pnfs_layout_type(xdr, layouttype); 4420504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 4421504913fbSAndy Adamson } else 4422504913fbSAndy Adamson *layouttype = 0; 4423504913fbSAndy Adamson return status; 4424504913fbSAndy Adamson } 4425504913fbSAndy Adamson 4426dae100c2SFred Isaman /* 4427dae100c2SFred Isaman * The prefered block size for layout directed io 4428dae100c2SFred Isaman */ 4429dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4430dae100c2SFred Isaman uint32_t *res) 4431dae100c2SFred Isaman { 4432dae100c2SFred Isaman __be32 *p; 4433dae100c2SFred Isaman 4434dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4435dae100c2SFred Isaman *res = 0; 4436dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4437dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4438dae100c2SFred Isaman if (unlikely(!p)) { 4439dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4440dae100c2SFred Isaman return -EIO; 4441dae100c2SFred Isaman } 4442dae100c2SFred Isaman *res = be32_to_cpup(p); 4443dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4444dae100c2SFred Isaman } 4445dae100c2SFred Isaman return 0; 4446dae100c2SFred Isaman } 4447dae100c2SFred Isaman 44481da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 44491da177e4SLinus Torvalds { 44508687b63aSAl Viro __be32 *savep; 4451dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 44521da177e4SLinus Torvalds int status; 44531da177e4SLinus Torvalds 44541da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44551da177e4SLinus Torvalds goto xdr_error; 44561da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44571da177e4SLinus Torvalds goto xdr_error; 44581da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44591da177e4SLinus Torvalds goto xdr_error; 44601da177e4SLinus Torvalds 44611da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 44621da177e4SLinus Torvalds 44631da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 44641da177e4SLinus Torvalds goto xdr_error; 44651da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 44661da177e4SLinus Torvalds goto xdr_error; 44671da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 44681da177e4SLinus Torvalds goto xdr_error; 44691da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 44701da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 44711da177e4SLinus Torvalds goto xdr_error; 44721da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 447355b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 447455b6e774SRicardo Labiaga if (status != 0) 447555b6e774SRicardo Labiaga goto xdr_error; 4476504913fbSAndy Adamson status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); 4477504913fbSAndy Adamson if (status != 0) 4478504913fbSAndy Adamson goto xdr_error; 4479dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4480dae100c2SFred Isaman if (status) 4481dae100c2SFred Isaman goto xdr_error; 44821da177e4SLinus Torvalds 44831da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44841da177e4SLinus Torvalds xdr_error: 44853110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44861da177e4SLinus Torvalds return status; 44871da177e4SLinus Torvalds } 44881da177e4SLinus Torvalds 44891da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 44901da177e4SLinus Torvalds { 44918687b63aSAl Viro __be32 *p; 44921da177e4SLinus Torvalds uint32_t len; 44931da177e4SLinus Torvalds int status; 44941da177e4SLinus Torvalds 44959936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 44969936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 44979936781dSTrond Myklebust 44981da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 44991da177e4SLinus Torvalds if (status) 45001da177e4SLinus Torvalds return status; 45011da177e4SLinus Torvalds 4502c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4503c0eae66eSBenny Halevy if (unlikely(!p)) 4504c0eae66eSBenny Halevy goto out_overflow; 4505cccddf4fSBenny Halevy len = be32_to_cpup(p); 45061da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 45071da177e4SLinus Torvalds return -EIO; 45081da177e4SLinus Torvalds fh->size = len; 4509c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4510c0eae66eSBenny Halevy if (unlikely(!p)) 4511c0eae66eSBenny Halevy goto out_overflow; 451299398d06SBenny Halevy memcpy(fh->data, p, len); 45131da177e4SLinus Torvalds return 0; 4514c0eae66eSBenny Halevy out_overflow: 4515c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4516c0eae66eSBenny Halevy return -EIO; 45171da177e4SLinus Torvalds } 45181da177e4SLinus Torvalds 45191da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 45201da177e4SLinus Torvalds { 45211da177e4SLinus Torvalds int status; 45221da177e4SLinus Torvalds 45231da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 45241da177e4SLinus Torvalds if (status) 45251da177e4SLinus Torvalds return status; 45261da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 45271da177e4SLinus Torvalds } 45281da177e4SLinus Torvalds 45291da177e4SLinus Torvalds /* 45301da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 45311da177e4SLinus Torvalds */ 4532911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 45331da177e4SLinus Torvalds { 4534911d1aafSTrond Myklebust uint64_t offset, length, clientid; 45358687b63aSAl Viro __be32 *p; 4536911d1aafSTrond Myklebust uint32_t namelen, type; 45371da177e4SLinus Torvalds 4538babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4539c0eae66eSBenny Halevy if (unlikely(!p)) 4540c0eae66eSBenny Halevy goto out_overflow; 4541babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 45423ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4543babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4544babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4545911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4546911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4547911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4548911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4549911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4550911d1aafSTrond Myklebust if (type & 1) 4551911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4552911d1aafSTrond Myklebust fl->fl_pid = 0; 4553911d1aafSTrond Myklebust } 4554babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4555babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4556babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4557c0eae66eSBenny Halevy if (likely(p)) 45581da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4559c0eae66eSBenny Halevy out_overflow: 4560c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4561c0eae66eSBenny Halevy return -EIO; 45621da177e4SLinus Torvalds } 45631da177e4SLinus Torvalds 4564911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 45651da177e4SLinus Torvalds { 45661da177e4SLinus Torvalds int status; 45671da177e4SLinus Torvalds 45681da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4569c1d51931STrond Myklebust if (status == -EIO) 4570c1d51931STrond Myklebust goto out; 45711da177e4SLinus Torvalds if (status == 0) { 457207d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 457307d30434SBenny Halevy if (unlikely(status)) 457407d30434SBenny Halevy goto out; 45751da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4576c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4577c1d51931STrond Myklebust if (res->open_seqid != NULL) 4578c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4579c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4580c1d51931STrond Myklebust out: 45811da177e4SLinus Torvalds return status; 45821da177e4SLinus Torvalds } 45831da177e4SLinus Torvalds 4584911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 45851da177e4SLinus Torvalds { 45861da177e4SLinus Torvalds int status; 45871da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 45881da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4589911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 45901da177e4SLinus Torvalds return status; 45911da177e4SLinus Torvalds } 45921da177e4SLinus Torvalds 4593911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 45941da177e4SLinus Torvalds { 45951da177e4SLinus Torvalds int status; 45961da177e4SLinus Torvalds 45971da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4598c1d51931STrond Myklebust if (status != -EIO) 4599c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 460007d30434SBenny Halevy if (status == 0) 460107d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 46021da177e4SLinus Torvalds return status; 46031da177e4SLinus Torvalds } 46041da177e4SLinus Torvalds 4605d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4606d3c7b7ccSTrond Myklebust { 4607d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4608d3c7b7ccSTrond Myklebust } 4609d3c7b7ccSTrond Myklebust 46101da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 46111da177e4SLinus Torvalds { 46121da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 46131da177e4SLinus Torvalds } 46141da177e4SLinus Torvalds 46151da177e4SLinus Torvalds /* This is too sick! */ 46161da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 46171da177e4SLinus Torvalds { 46188687b63aSAl Viro __be32 *p; 46191da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 46201da177e4SLinus Torvalds 4621c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4622c0eae66eSBenny Halevy if (unlikely(!p)) 4623c0eae66eSBenny Halevy goto out_overflow; 46246f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 46251da177e4SLinus Torvalds switch (limit_type) { 46261da177e4SLinus Torvalds case 1: 4627cccddf4fSBenny Halevy xdr_decode_hyper(p, maxsize); 46281da177e4SLinus Torvalds break; 46291da177e4SLinus Torvalds case 2: 46306f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 4631cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 46321da177e4SLinus Torvalds *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 46331da177e4SLinus Torvalds } 46341da177e4SLinus Torvalds return 0; 4635c0eae66eSBenny Halevy out_overflow: 4636c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4637c0eae66eSBenny Halevy return -EIO; 46381da177e4SLinus Torvalds } 46391da177e4SLinus Torvalds 46401da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 46411da177e4SLinus Torvalds { 46428687b63aSAl Viro __be32 *p; 46431da177e4SLinus Torvalds uint32_t delegation_type; 464407d30434SBenny Halevy int status; 46451da177e4SLinus Torvalds 4646c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4647c0eae66eSBenny Halevy if (unlikely(!p)) 4648c0eae66eSBenny Halevy goto out_overflow; 4649cccddf4fSBenny Halevy delegation_type = be32_to_cpup(p); 46501da177e4SLinus Torvalds if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 46511da177e4SLinus Torvalds res->delegation_type = 0; 46521da177e4SLinus Torvalds return 0; 46531da177e4SLinus Torvalds } 465407d30434SBenny Halevy status = decode_stateid(xdr, &res->delegation); 465507d30434SBenny Halevy if (unlikely(status)) 465607d30434SBenny Halevy return status; 4657c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4658c0eae66eSBenny Halevy if (unlikely(!p)) 4659c0eae66eSBenny Halevy goto out_overflow; 4660cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 466105d564feSAndy Adamson 46621da177e4SLinus Torvalds switch (delegation_type) { 46631da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 46641da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 46651da177e4SLinus Torvalds break; 46661da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 46671da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 46681da177e4SLinus Torvalds if (decode_space_limit(xdr, &res->maxsize) < 0) 46691da177e4SLinus Torvalds return -EIO; 46701da177e4SLinus Torvalds } 46717539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 4672c0eae66eSBenny Halevy out_overflow: 4673c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4674c0eae66eSBenny Halevy return -EIO; 46751da177e4SLinus Torvalds } 46761da177e4SLinus Torvalds 46771da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 46781da177e4SLinus Torvalds { 46798687b63aSAl Viro __be32 *p; 4680aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 46811da177e4SLinus Torvalds int status; 46821da177e4SLinus Torvalds 46831da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN); 4684c1d51931STrond Myklebust if (status != -EIO) 4685c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 468607d30434SBenny Halevy if (!status) 468707d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 468807d30434SBenny Halevy if (unlikely(status)) 46891da177e4SLinus Torvalds return status; 46901da177e4SLinus Torvalds 46911da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 46921da177e4SLinus Torvalds 4693c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4694c0eae66eSBenny Halevy if (unlikely(!p)) 4695c0eae66eSBenny Halevy goto out_overflow; 46966f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 4697cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 46981da177e4SLinus Torvalds if (bmlen > 10) 46991da177e4SLinus Torvalds goto xdr_error; 47001da177e4SLinus Torvalds 4701c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4702c0eae66eSBenny Halevy if (unlikely(!p)) 4703c0eae66eSBenny Halevy goto out_overflow; 4704aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 4705aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 47066f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 4707aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 4708aa53ed54SJeff Layton res->attrset[i] = 0; 4709aa53ed54SJeff Layton 47101da177e4SLinus Torvalds return decode_delegation(xdr, res); 47111da177e4SLinus Torvalds xdr_error: 47123110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 47131da177e4SLinus Torvalds return -EIO; 4714c0eae66eSBenny Halevy out_overflow: 4715c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4716c0eae66eSBenny Halevy return -EIO; 47171da177e4SLinus Torvalds } 47181da177e4SLinus Torvalds 47191da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 47201da177e4SLinus Torvalds { 47211da177e4SLinus Torvalds int status; 47221da177e4SLinus Torvalds 47231da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 4724c1d51931STrond Myklebust if (status != -EIO) 4725c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 472607d30434SBenny Halevy if (!status) 472707d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 47281da177e4SLinus Torvalds return status; 47291da177e4SLinus Torvalds } 47301da177e4SLinus Torvalds 47311da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 47321da177e4SLinus Torvalds { 47331da177e4SLinus Torvalds int status; 47341da177e4SLinus Torvalds 47351da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 4736c1d51931STrond Myklebust if (status != -EIO) 4737c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 473807d30434SBenny Halevy if (!status) 473907d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 47401da177e4SLinus Torvalds return status; 47411da177e4SLinus Torvalds } 47421da177e4SLinus Torvalds 47431da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 47441da177e4SLinus Torvalds { 47451da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 47461da177e4SLinus Torvalds } 47471da177e4SLinus Torvalds 47481da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 47491da177e4SLinus Torvalds { 47501da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 47511da177e4SLinus Torvalds } 47521da177e4SLinus Torvalds 47531da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 47541da177e4SLinus Torvalds { 47551da177e4SLinus Torvalds struct kvec *iov = req->rq_rcv_buf.head; 47568687b63aSAl Viro __be32 *p; 47571da177e4SLinus Torvalds uint32_t count, eof, recvd, hdrlen; 47581da177e4SLinus Torvalds int status; 47591da177e4SLinus Torvalds 47601da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 47611da177e4SLinus Torvalds if (status) 47621da177e4SLinus Torvalds return status; 4763c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4764c0eae66eSBenny Halevy if (unlikely(!p)) 4765c0eae66eSBenny Halevy goto out_overflow; 47666f723f77SBenny Halevy eof = be32_to_cpup(p++); 4767cccddf4fSBenny Halevy count = be32_to_cpup(p); 47688111f373SChuck Lever hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 47691da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 47701da177e4SLinus Torvalds if (count > recvd) { 4771fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 47721da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 47731da177e4SLinus Torvalds count = recvd; 47741da177e4SLinus Torvalds eof = 0; 47751da177e4SLinus Torvalds } 47761da177e4SLinus Torvalds xdr_read_pages(xdr, count); 47771da177e4SLinus Torvalds res->eof = eof; 47781da177e4SLinus Torvalds res->count = count; 47791da177e4SLinus Torvalds return 0; 4780c0eae66eSBenny Halevy out_overflow: 4781c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4782c0eae66eSBenny Halevy return -EIO; 47831da177e4SLinus Torvalds } 47841da177e4SLinus Torvalds 47851da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 47861da177e4SLinus Torvalds { 47871da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 47881da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4789bcecff77SChuck Lever size_t hdrlen; 4790bcecff77SChuck Lever u32 recvd, pglen = rcvbuf->page_len; 4791bcecff77SChuck Lever int status; 4792cd93710eSChuck Lever __be32 verf[2]; 47931da177e4SLinus Torvalds 47941da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 4795db942bbdSBenny Halevy if (!status) 4796db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 4797db942bbdSBenny Halevy if (unlikely(status)) 47981da177e4SLinus Torvalds return status; 4799cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 480044109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 4801cd93710eSChuck Lever __func__, verf[0], verf[1]); 48021da177e4SLinus Torvalds 4803db942bbdSBenny Halevy hdrlen = (char *) xdr->p - (char *) iov->iov_base; 48041da177e4SLinus Torvalds recvd = rcvbuf->len - hdrlen; 48051da177e4SLinus Torvalds if (pglen > recvd) 48061da177e4SLinus Torvalds pglen = recvd; 48071da177e4SLinus Torvalds xdr_read_pages(xdr, pglen); 48081da177e4SLinus Torvalds 48097bda2cdfSJeff Layton 4810ac396128STrond Myklebust return pglen; 48111da177e4SLinus Torvalds } 48121da177e4SLinus Torvalds 48131da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 48141da177e4SLinus Torvalds { 48151da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 48161da177e4SLinus Torvalds struct kvec *iov = rcvbuf->head; 4817bcecff77SChuck Lever size_t hdrlen; 4818bcecff77SChuck Lever u32 len, recvd; 48198687b63aSAl Viro __be32 *p; 48201da177e4SLinus Torvalds int status; 48211da177e4SLinus Torvalds 48221da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 48231da177e4SLinus Torvalds if (status) 48241da177e4SLinus Torvalds return status; 48251da177e4SLinus Torvalds 48261da177e4SLinus Torvalds /* Convert length of symlink */ 4827c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4828c0eae66eSBenny Halevy if (unlikely(!p)) 4829c0eae66eSBenny Halevy goto out_overflow; 4830cccddf4fSBenny Halevy len = be32_to_cpup(p); 48311da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 4832fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 48331da177e4SLinus Torvalds return -ENAMETOOLONG; 48341da177e4SLinus Torvalds } 48351da177e4SLinus Torvalds hdrlen = (char *) xdr->p - (char *) iov->iov_base; 48361da177e4SLinus Torvalds recvd = req->rq_rcv_buf.len - hdrlen; 48371da177e4SLinus Torvalds if (recvd < len) { 4838fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 48391da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 48401da177e4SLinus Torvalds return -EIO; 48411da177e4SLinus Torvalds } 48421da177e4SLinus Torvalds xdr_read_pages(xdr, len); 48431da177e4SLinus Torvalds /* 48441da177e4SLinus Torvalds * The XDR encode routine has set things up so that 48451da177e4SLinus Torvalds * the link text will be copied directly into the 48461da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 48471da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 48481da177e4SLinus Torvalds * null-termination). 48491da177e4SLinus Torvalds */ 4850b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 48511da177e4SLinus Torvalds return 0; 4852c0eae66eSBenny Halevy out_overflow: 4853c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4854c0eae66eSBenny Halevy return -EIO; 48551da177e4SLinus Torvalds } 48561da177e4SLinus Torvalds 48571da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 48581da177e4SLinus Torvalds { 48591da177e4SLinus Torvalds int status; 48601da177e4SLinus Torvalds 48611da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 48621da177e4SLinus Torvalds if (status) 48631da177e4SLinus Torvalds goto out; 48641da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 48651da177e4SLinus Torvalds out: 48661da177e4SLinus Torvalds return status; 48671da177e4SLinus Torvalds } 48681da177e4SLinus Torvalds 48691da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 48701da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 48711da177e4SLinus Torvalds { 48721da177e4SLinus Torvalds int status; 48731da177e4SLinus Torvalds 48741da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 48751da177e4SLinus Torvalds if (status) 48761da177e4SLinus Torvalds goto out; 48771da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 48781da177e4SLinus Torvalds goto out; 48791da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 48801da177e4SLinus Torvalds out: 48811da177e4SLinus Torvalds return status; 48821da177e4SLinus Torvalds } 48831da177e4SLinus Torvalds 48841da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 48851da177e4SLinus Torvalds { 48861da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 48871da177e4SLinus Torvalds } 48881da177e4SLinus Torvalds 488956ae19f3STrond Myklebust static int 489056ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 489156ae19f3STrond Myklebust { 489256ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 489356ae19f3STrond Myklebust } 489456ae19f3STrond Myklebust 4895029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 4896bf118a34SAndy Adamson struct nfs_getaclres *res) 4897029d105eSJ. Bruce Fields { 4898bf118a34SAndy Adamson __be32 *savep, *bm_p; 4899029d105eSJ. Bruce Fields uint32_t attrlen, 4900dae100c2SFred Isaman bitmap[3] = {0}; 4901029d105eSJ. Bruce Fields struct kvec *iov = req->rq_rcv_buf.head; 4902029d105eSJ. Bruce Fields int status; 49035a006899SSachin Prabhu size_t page_len = xdr->buf->page_len; 4904029d105eSJ. Bruce Fields 4905bf118a34SAndy Adamson res->acl_len = 0; 4906029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 4907029d105eSJ. Bruce Fields goto out; 49085a006899SSachin Prabhu 4909bf118a34SAndy Adamson bm_p = xdr->p; 49105a006899SSachin Prabhu res->acl_data_offset = be32_to_cpup(bm_p) + 2; 49115a006899SSachin Prabhu res->acl_data_offset <<= 2; 49125a006899SSachin Prabhu /* Check if the acl data starts beyond the allocated buffer */ 49135a006899SSachin Prabhu if (res->acl_data_offset > page_len) 49145a006899SSachin Prabhu return -ERANGE; 49155a006899SSachin Prabhu 4916029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 4917029d105eSJ. Bruce Fields goto out; 4918029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 4919029d105eSJ. Bruce Fields goto out; 4920029d105eSJ. Bruce Fields 4921029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 4922029d105eSJ. Bruce Fields return -EIO; 4923029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 4924bcecff77SChuck Lever size_t hdrlen; 4925029d105eSJ. Bruce Fields 4926bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 4927bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 4928bf118a34SAndy Adamson * variable length bitmaps.*/ 4929bf118a34SAndy Adamson xdr->p = bm_p; 4930bf118a34SAndy Adamson 4931029d105eSJ. Bruce Fields /* We ignore &savep and don't do consistency checks on 4932029d105eSJ. Bruce Fields * the attr length. Let userspace figure it out.... */ 4933029d105eSJ. Bruce Fields hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base; 4934bf118a34SAndy Adamson attrlen += res->acl_data_offset; 49355a006899SSachin Prabhu if (attrlen > page_len) { 4936bf118a34SAndy Adamson if (res->acl_flags & NFS4_ACL_LEN_REQUEST) { 4937bf118a34SAndy Adamson /* getxattr interface called with a NULL buf */ 4938bf118a34SAndy Adamson res->acl_len = attrlen; 4939bf118a34SAndy Adamson goto out; 4940bf118a34SAndy Adamson } 49415794d21eSSachin Prabhu dprintk("NFS: acl reply: attrlen %u > page_len %zu\n", 49425a006899SSachin Prabhu attrlen, page_len); 4943029d105eSJ. Bruce Fields return -EINVAL; 4944029d105eSJ. Bruce Fields } 4945029d105eSJ. Bruce Fields xdr_read_pages(xdr, attrlen); 4946bf118a34SAndy Adamson res->acl_len = attrlen; 49478c233cf9SJ. Bruce Fields } else 49488c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 4949029d105eSJ. Bruce Fields 4950029d105eSJ. Bruce Fields out: 4951029d105eSJ. Bruce Fields return status; 4952029d105eSJ. Bruce Fields } 4953029d105eSJ. Bruce Fields 49541da177e4SLinus Torvalds static int 49551da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 49561da177e4SLinus Torvalds { 49571da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 49581da177e4SLinus Torvalds } 49591da177e4SLinus Torvalds 49609e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 49611da177e4SLinus Torvalds { 49628687b63aSAl Viro __be32 *p; 49631da177e4SLinus Torvalds uint32_t bmlen; 49641da177e4SLinus Torvalds int status; 49651da177e4SLinus Torvalds 49661da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 49671da177e4SLinus Torvalds if (status) 49681da177e4SLinus Torvalds return status; 4969c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4970c0eae66eSBenny Halevy if (unlikely(!p)) 4971c0eae66eSBenny Halevy goto out_overflow; 4972cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4973c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4974c0eae66eSBenny Halevy if (likely(p)) 49751da177e4SLinus Torvalds return 0; 4976c0eae66eSBenny Halevy out_overflow: 4977c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4978c0eae66eSBenny Halevy return -EIO; 49791da177e4SLinus Torvalds } 49801da177e4SLinus Torvalds 4981bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 49821da177e4SLinus Torvalds { 49838687b63aSAl Viro __be32 *p; 49841da177e4SLinus Torvalds uint32_t opnum; 49851da177e4SLinus Torvalds int32_t nfserr; 49861da177e4SLinus Torvalds 4987c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4988c0eae66eSBenny Halevy if (unlikely(!p)) 4989c0eae66eSBenny Halevy goto out_overflow; 49906f723f77SBenny Halevy opnum = be32_to_cpup(p++); 49911da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 4992fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 49931da177e4SLinus Torvalds " %d\n", opnum); 49941da177e4SLinus Torvalds return -EIO; 49951da177e4SLinus Torvalds } 4996cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 49971da177e4SLinus Torvalds if (nfserr == NFS_OK) { 4998c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 4999c0eae66eSBenny Halevy if (unlikely(!p)) 5000c0eae66eSBenny Halevy goto out_overflow; 5001bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5002bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 50031da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 50041da177e4SLinus Torvalds uint32_t len; 50051da177e4SLinus Torvalds 50061da177e4SLinus Torvalds /* skip netid 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 50151da177e4SLinus Torvalds /* skip uaddr string */ 5016c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5017c0eae66eSBenny Halevy if (unlikely(!p)) 5018c0eae66eSBenny Halevy goto out_overflow; 5019cccddf4fSBenny Halevy len = be32_to_cpup(p); 5020c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5021c0eae66eSBenny Halevy if (unlikely(!p)) 5022c0eae66eSBenny Halevy goto out_overflow; 50231da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 50241da177e4SLinus Torvalds } else 5025856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 50261da177e4SLinus Torvalds 50271da177e4SLinus Torvalds return 0; 5028c0eae66eSBenny Halevy out_overflow: 5029c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5030c0eae66eSBenny Halevy return -EIO; 50311da177e4SLinus Torvalds } 50321da177e4SLinus Torvalds 50331da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 50341da177e4SLinus Torvalds { 50351da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 50361da177e4SLinus Torvalds } 50371da177e4SLinus Torvalds 50381da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 50391da177e4SLinus Torvalds { 50408687b63aSAl Viro __be32 *p; 50411da177e4SLinus Torvalds int status; 50421da177e4SLinus Torvalds 50431da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 50441da177e4SLinus Torvalds if (status) 50451da177e4SLinus Torvalds return status; 50461da177e4SLinus Torvalds 5047c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 5048c0eae66eSBenny Halevy if (unlikely(!p)) 5049c0eae66eSBenny Halevy goto out_overflow; 50506f723f77SBenny Halevy res->count = be32_to_cpup(p++); 50516f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 5052cd93710eSChuck Lever memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE); 50531da177e4SLinus Torvalds return 0; 5054c0eae66eSBenny Halevy out_overflow: 5055c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5056c0eae66eSBenny Halevy return -EIO; 50571da177e4SLinus Torvalds } 50581da177e4SLinus Torvalds 50591da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 50601da177e4SLinus Torvalds { 50611da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 50621da177e4SLinus Torvalds } 50631da177e4SLinus Torvalds 50645a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor) 50655a5ea0d4SBryan Schumaker { 50665a5ea0d4SBryan Schumaker __be32 *p; 50675a5ea0d4SBryan Schumaker 50685a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 50695a5ea0d4SBryan Schumaker if (unlikely(!p)) 50705a5ea0d4SBryan Schumaker goto out_overflow; 50715a5ea0d4SBryan Schumaker flavor->gss.sec_oid4.len = be32_to_cpup(p); 50725a5ea0d4SBryan Schumaker if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN) 50735a5ea0d4SBryan Schumaker goto out_err; 50745a5ea0d4SBryan Schumaker 50755a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len); 50765a5ea0d4SBryan Schumaker if (unlikely(!p)) 50775a5ea0d4SBryan Schumaker goto out_overflow; 50785a5ea0d4SBryan Schumaker memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len); 50795a5ea0d4SBryan Schumaker 50805a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 50815a5ea0d4SBryan Schumaker if (unlikely(!p)) 50825a5ea0d4SBryan Schumaker goto out_overflow; 50835a5ea0d4SBryan Schumaker flavor->gss.qop4 = be32_to_cpup(p++); 50845a5ea0d4SBryan Schumaker flavor->gss.service = be32_to_cpup(p); 50855a5ea0d4SBryan Schumaker 50865a5ea0d4SBryan Schumaker return 0; 50875a5ea0d4SBryan Schumaker 50885a5ea0d4SBryan Schumaker out_overflow: 50895a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 50905a5ea0d4SBryan Schumaker return -EIO; 50915a5ea0d4SBryan Schumaker out_err: 50925a5ea0d4SBryan Schumaker return -EINVAL; 50935a5ea0d4SBryan Schumaker } 50945a5ea0d4SBryan Schumaker 509531e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 50965a5ea0d4SBryan Schumaker { 50975a5ea0d4SBryan Schumaker struct nfs4_secinfo_flavor *sec_flavor; 50985a5ea0d4SBryan Schumaker int status; 50995a5ea0d4SBryan Schumaker __be32 *p; 5100c3dfc280SBryan Schumaker int i, num_flavors; 51015a5ea0d4SBryan Schumaker 51025a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 51035a5ea0d4SBryan Schumaker if (unlikely(!p)) 51045a5ea0d4SBryan Schumaker goto out_overflow; 51055a5ea0d4SBryan Schumaker 5106c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5107c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5108c3dfc280SBryan Schumaker 5109c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 51105a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5111c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 51125a5ea0d4SBryan Schumaker break; 51135a5ea0d4SBryan Schumaker 51145a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 51155a5ea0d4SBryan Schumaker if (unlikely(!p)) 51165a5ea0d4SBryan Schumaker goto out_overflow; 51175a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 51185a5ea0d4SBryan Schumaker 51195a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5120613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5121613e901eSBryan Schumaker if (status) 5122613e901eSBryan Schumaker goto out; 51235a5ea0d4SBryan Schumaker } 5124c3dfc280SBryan Schumaker res->flavors->num_flavors++; 51255a5ea0d4SBryan Schumaker } 51265a5ea0d4SBryan Schumaker 512731e4dda4SBryan Schumaker status = 0; 5128613e901eSBryan Schumaker out: 5129613e901eSBryan Schumaker return status; 51305a5ea0d4SBryan Schumaker out_overflow: 51315a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 51325a5ea0d4SBryan Schumaker return -EIO; 51335a5ea0d4SBryan Schumaker } 51345a5ea0d4SBryan Schumaker 513531e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 513631e4dda4SBryan Schumaker { 513731e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 513831e4dda4SBryan Schumaker if (status) 513931e4dda4SBryan Schumaker return status; 514031e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 514131e4dda4SBryan Schumaker } 514231e4dda4SBryan Schumaker 514399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 514431e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 514531e4dda4SBryan Schumaker { 514631e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 514731e4dda4SBryan Schumaker if (status) 514831e4dda4SBryan Schumaker return status; 514931e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 515031e4dda4SBryan Schumaker } 515131e4dda4SBryan Schumaker 515299fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 515399fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 515499fe60d0SBenny Halevy { 515599fe60d0SBenny Halevy __be32 *p; 515699fe60d0SBenny Halevy uint32_t dummy; 51572460ba57SBenny Halevy char *dummy_str; 515899fe60d0SBenny Halevy int status; 515999fe60d0SBenny Halevy struct nfs_client *clp = res->client; 51607d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 516199fe60d0SBenny Halevy 516299fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 516399fe60d0SBenny Halevy if (status) 516499fe60d0SBenny Halevy return status; 516599fe60d0SBenny Halevy 5166c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5167c0eae66eSBenny Halevy if (unlikely(!p)) 5168c0eae66eSBenny Halevy goto out_overflow; 5169114f64b5SAndy Adamson xdr_decode_hyper(p, &clp->cl_clientid); 5170c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5171c0eae66eSBenny Halevy if (unlikely(!p)) 5172c0eae66eSBenny Halevy goto out_overflow; 51736f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 51746f723f77SBenny Halevy clp->cl_exchange_flags = be32_to_cpup(p++); 517599fe60d0SBenny Halevy 517699fe60d0SBenny Halevy /* We ask for SP4_NONE */ 5177cccddf4fSBenny Halevy dummy = be32_to_cpup(p); 517899fe60d0SBenny Halevy if (dummy != SP4_NONE) 517999fe60d0SBenny Halevy return -EIO; 518099fe60d0SBenny Halevy 518199fe60d0SBenny Halevy /* Throw away minor_id */ 5182c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5183c0eae66eSBenny Halevy if (unlikely(!p)) 5184c0eae66eSBenny Halevy goto out_overflow; 518599fe60d0SBenny Halevy 518699fe60d0SBenny Halevy /* Throw away Major id */ 51872460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 51882460ba57SBenny Halevy if (unlikely(status)) 51892460ba57SBenny Halevy return status; 519099fe60d0SBenny Halevy 519178fe0f41SWeston Andros Adamson /* Save server_scope */ 51922460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 51932460ba57SBenny Halevy if (unlikely(status)) 51942460ba57SBenny Halevy return status; 519599fe60d0SBenny Halevy 519678fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 519778fe0f41SWeston Andros Adamson return -EIO; 519878fe0f41SWeston Andros Adamson 519978fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 520078fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 520178fe0f41SWeston Andros Adamson 52027d2ed9acSWeston Andros Adamson /* Implementation Id */ 52037d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 52047d2ed9acSWeston Andros Adamson if (unlikely(!p)) 52057d2ed9acSWeston Andros Adamson goto out_overflow; 52067d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 52077d2ed9acSWeston Andros Adamson 52087d2ed9acSWeston Andros Adamson if (impl_id_count) { 52097d2ed9acSWeston Andros Adamson /* nii_domain */ 52102460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 52112460ba57SBenny Halevy if (unlikely(status)) 52122460ba57SBenny Halevy return status; 52137d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 52147d2ed9acSWeston Andros Adamson return -EIO; 52157d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 521699fe60d0SBenny Halevy 52177d2ed9acSWeston Andros Adamson /* nii_name */ 52187d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 52197d2ed9acSWeston Andros Adamson if (unlikely(status)) 52207d2ed9acSWeston Andros Adamson return status; 52217d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 52227d2ed9acSWeston Andros Adamson return -EIO; 52237d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 52247d2ed9acSWeston Andros Adamson 52257d2ed9acSWeston Andros Adamson /* nii_date */ 52267d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 52277d2ed9acSWeston Andros Adamson if (unlikely(!p)) 52287d2ed9acSWeston Andros Adamson goto out_overflow; 52297d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 52307d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 52317d2ed9acSWeston Andros Adamson 52327d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 52337d2ed9acSWeston Andros Adamson } 523499fe60d0SBenny Halevy return 0; 5235c0eae66eSBenny Halevy out_overflow: 5236c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5237c0eae66eSBenny Halevy return -EIO; 523899fe60d0SBenny Halevy } 5239fc931582SAndy Adamson 5240fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5241fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5242fc931582SAndy Adamson { 5243fc931582SAndy Adamson __be32 *p; 5244c9c30dd5SBenny Halevy u32 nr_attrs, val; 5245fc931582SAndy Adamson 5246c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5247c0eae66eSBenny Halevy if (unlikely(!p)) 5248c0eae66eSBenny Halevy goto out_overflow; 5249c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5250c9c30dd5SBenny Halevy if (val) 5251c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 52526f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 52536f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 52546f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 52556f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 52566f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5257cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5258fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5259a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5260a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5261fc931582SAndy Adamson return -EINVAL; 5262fc931582SAndy Adamson } 5263c0eae66eSBenny Halevy if (nr_attrs == 1) { 5264c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5265c0eae66eSBenny Halevy if (unlikely(!p)) 5266c0eae66eSBenny Halevy goto out_overflow; 5267c0eae66eSBenny Halevy } 5268fc931582SAndy Adamson return 0; 5269c0eae66eSBenny Halevy out_overflow: 5270c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5271c0eae66eSBenny Halevy return -EIO; 5272fc931582SAndy Adamson } 5273fc931582SAndy Adamson 5274e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5275e78291e4SBenny Halevy { 5276e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5277fc931582SAndy Adamson } 5278fc931582SAndy Adamson 5279fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5280fc931582SAndy Adamson struct nfs41_create_session_res *res) 5281fc931582SAndy Adamson { 5282fc931582SAndy Adamson __be32 *p; 5283fc931582SAndy Adamson int status; 5284fc931582SAndy Adamson struct nfs_client *clp = res->client; 5285fc931582SAndy Adamson struct nfs4_session *session = clp->cl_session; 5286fc931582SAndy Adamson 5287fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5288e78291e4SBenny Halevy if (!status) 5289e78291e4SBenny Halevy status = decode_sessionid(xdr, &session->sess_id); 5290e78291e4SBenny Halevy if (unlikely(status)) 5291fc931582SAndy Adamson return status; 5292fc931582SAndy Adamson 5293fc931582SAndy Adamson /* seqid, flags */ 5294c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5295c0eae66eSBenny Halevy if (unlikely(!p)) 5296c0eae66eSBenny Halevy goto out_overflow; 52976f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 5298cccddf4fSBenny Halevy session->flags = be32_to_cpup(p); 5299fc931582SAndy Adamson 5300fc931582SAndy Adamson /* Channel attributes */ 5301fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->fc_attrs); 5302fc931582SAndy Adamson if (!status) 5303fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->bc_attrs); 5304fc931582SAndy Adamson return status; 5305c0eae66eSBenny Halevy out_overflow: 5306c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5307c0eae66eSBenny Halevy return -EIO; 5308fc931582SAndy Adamson } 53090f3e66c6SAndy Adamson 53100f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 53110f3e66c6SAndy Adamson { 53120f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 53130f3e66c6SAndy Adamson } 531418019753SRicardo Labiaga 531518019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 531618019753SRicardo Labiaga { 531718019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 531818019753SRicardo Labiaga } 531999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 532099fe60d0SBenny Halevy 53219b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 53229b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 53239b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 53249b7b9fccSAndy Adamson { 53259b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5326fc01cea9SAndy Adamson struct nfs4_sessionid id; 5327fc01cea9SAndy Adamson u32 dummy; 5328fc01cea9SAndy Adamson int status; 5329fc01cea9SAndy Adamson __be32 *p; 5330fc01cea9SAndy Adamson 53319b7b9fccSAndy Adamson if (!res->sr_session) 53329b7b9fccSAndy Adamson return 0; 53339b7b9fccSAndy Adamson 5334fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5335e78291e4SBenny Halevy if (!status) 5336e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5337e78291e4SBenny Halevy if (unlikely(status)) 5338fc01cea9SAndy Adamson goto out_err; 53399b7b9fccSAndy Adamson 5340fc01cea9SAndy Adamson /* 5341fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5342fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5343fc01cea9SAndy Adamson */ 5344fdcb4577STrond Myklebust status = -EREMOTEIO; 5345fc01cea9SAndy Adamson 5346fc01cea9SAndy Adamson if (memcmp(id.data, res->sr_session->sess_id.data, 5347fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5348fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5349fc01cea9SAndy Adamson goto out_err; 5350fc01cea9SAndy Adamson } 5351e78291e4SBenny Halevy 5352c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5353c0eae66eSBenny Halevy if (unlikely(!p)) 5354c0eae66eSBenny Halevy goto out_overflow; 5355e78291e4SBenny Halevy 5356fc01cea9SAndy Adamson /* seqid */ 53576f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5358dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5359fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5360fc01cea9SAndy Adamson goto out_err; 5361fc01cea9SAndy Adamson } 5362fc01cea9SAndy Adamson /* slot id */ 53636f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5364dfb4f309SBenny Halevy if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) { 5365fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5366fc01cea9SAndy Adamson goto out_err; 5367fc01cea9SAndy Adamson } 5368fc01cea9SAndy Adamson /* highest slot id - currently not processed */ 53696f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5370fc01cea9SAndy Adamson /* target highest slot id - currently not processed */ 53716f723f77SBenny Halevy dummy = be32_to_cpup(p++); 53720629e370SAlexandros Batsakis /* result flags */ 53730629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5374fc01cea9SAndy Adamson status = 0; 5375fc01cea9SAndy Adamson out_err: 5376fc01cea9SAndy Adamson res->sr_status = status; 5377fc01cea9SAndy Adamson return status; 5378c0eae66eSBenny Halevy out_overflow: 5379c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5380c0eae66eSBenny Halevy status = -EIO; 5381c0eae66eSBenny Halevy goto out_err; 5382fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 53839b7b9fccSAndy Adamson return 0; 5384fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 53859b7b9fccSAndy Adamson } 53869b7b9fccSAndy Adamson 5387b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 53887f11d8d3SAndy Adamson /* 53897f11d8d3SAndy Adamson * TODO: Need to handle case when EOF != true; 53907f11d8d3SAndy Adamson */ 53917f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr, 53927f11d8d3SAndy Adamson struct pnfs_devicelist *res) 53937f11d8d3SAndy Adamson { 53947f11d8d3SAndy Adamson __be32 *p; 53957f11d8d3SAndy Adamson int status, i; 53967f11d8d3SAndy Adamson struct nfs_writeverf verftemp; 53977f11d8d3SAndy Adamson 53987f11d8d3SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICELIST); 53997f11d8d3SAndy Adamson if (status) 54007f11d8d3SAndy Adamson return status; 54017f11d8d3SAndy Adamson 54027f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 8 + 8 + 4); 54037f11d8d3SAndy Adamson if (unlikely(!p)) 54047f11d8d3SAndy Adamson goto out_overflow; 54057f11d8d3SAndy Adamson 54067f11d8d3SAndy Adamson /* TODO: Skip cookie for now */ 54077f11d8d3SAndy Adamson p += 2; 54087f11d8d3SAndy Adamson 54097f11d8d3SAndy Adamson /* Read verifier */ 5410cd93710eSChuck Lever p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE); 54117f11d8d3SAndy Adamson 54127f11d8d3SAndy Adamson res->num_devs = be32_to_cpup(p); 54137f11d8d3SAndy Adamson 54147f11d8d3SAndy Adamson dprintk("%s: num_dev %d\n", __func__, res->num_devs); 54157f11d8d3SAndy Adamson 54167f11d8d3SAndy Adamson if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5417a030889aSWeston Andros Adamson printk(KERN_ERR "NFS: %s too many result dev_num %u\n", 54187f11d8d3SAndy Adamson __func__, res->num_devs); 54197f11d8d3SAndy Adamson return -EIO; 54207f11d8d3SAndy Adamson } 54217f11d8d3SAndy Adamson 54227f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 54237f11d8d3SAndy Adamson res->num_devs * NFS4_DEVICEID4_SIZE + 4); 54247f11d8d3SAndy Adamson if (unlikely(!p)) 54257f11d8d3SAndy Adamson goto out_overflow; 54267f11d8d3SAndy Adamson for (i = 0; i < res->num_devs; i++) 54277f11d8d3SAndy Adamson p = xdr_decode_opaque_fixed(p, res->dev_id[i].data, 54287f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE); 54297f11d8d3SAndy Adamson res->eof = be32_to_cpup(p); 54307f11d8d3SAndy Adamson return 0; 54317f11d8d3SAndy Adamson out_overflow: 54327f11d8d3SAndy Adamson print_overflow_msg(__func__, xdr); 54337f11d8d3SAndy Adamson return -EIO; 54347f11d8d3SAndy Adamson } 5435b1f69b75SAndy Adamson 5436b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 5437b1f69b75SAndy Adamson struct pnfs_device *pdev) 5438b1f69b75SAndy Adamson { 5439b1f69b75SAndy Adamson __be32 *p; 5440b1f69b75SAndy Adamson uint32_t len, type; 5441b1f69b75SAndy Adamson int status; 5442b1f69b75SAndy Adamson 5443b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5444b1f69b75SAndy Adamson if (status) { 5445b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5446b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5447b1f69b75SAndy Adamson if (unlikely(!p)) 5448b1f69b75SAndy Adamson goto out_overflow; 5449b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5450b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5451b1f69b75SAndy Adamson __func__, pdev->mincount); 5452b1f69b75SAndy Adamson } 5453b1f69b75SAndy Adamson return status; 5454b1f69b75SAndy Adamson } 5455b1f69b75SAndy Adamson 5456b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5457b1f69b75SAndy Adamson if (unlikely(!p)) 5458b1f69b75SAndy Adamson goto out_overflow; 5459b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5460b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5461b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5462b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5463b1f69b75SAndy Adamson return -EINVAL; 5464b1f69b75SAndy Adamson } 5465b1f69b75SAndy Adamson /* 5466b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5467b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5468b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5469b1f69b75SAndy Adamson */ 5470b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5471b1f69b75SAndy Adamson xdr_read_pages(xdr, pdev->mincount); /* include space for the length */ 5472b1f69b75SAndy Adamson 5473b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5474b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5475b1f69b75SAndy Adamson if (unlikely(!p)) 5476b1f69b75SAndy Adamson goto out_overflow; 5477b1f69b75SAndy Adamson len = be32_to_cpup(p); 5478b1f69b75SAndy Adamson if (len) { 5479ead00597SChuck Lever uint32_t i; 5480b1f69b75SAndy Adamson 5481b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5482b1f69b75SAndy Adamson if (unlikely(!p)) 5483b1f69b75SAndy Adamson goto out_overflow; 5484b1f69b75SAndy Adamson for (i = 0; i < len; i++, p++) { 5485b1f69b75SAndy Adamson if (be32_to_cpup(p)) { 5486b1f69b75SAndy Adamson dprintk("%s: notifications not supported\n", 5487b1f69b75SAndy Adamson __func__); 5488b1f69b75SAndy Adamson return -EIO; 5489b1f69b75SAndy Adamson } 5490b1f69b75SAndy Adamson } 5491b1f69b75SAndy Adamson } 5492b1f69b75SAndy Adamson return 0; 5493b1f69b75SAndy Adamson out_overflow: 5494b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5495b1f69b75SAndy Adamson return -EIO; 5496b1f69b75SAndy Adamson } 5497b1f69b75SAndy Adamson 5498b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5499b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5500b1f69b75SAndy Adamson { 5501b1f69b75SAndy Adamson __be32 *p; 5502b1f69b75SAndy Adamson int status; 5503b1f69b75SAndy Adamson u32 layout_count; 550435124a09SWeston Andros Adamson struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 550535124a09SWeston Andros Adamson struct kvec *iov = rcvbuf->head; 550635124a09SWeston Andros Adamson u32 hdrlen, recvd; 5507b1f69b75SAndy Adamson 5508b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5509b1f69b75SAndy Adamson if (status) 5510b1f69b75SAndy Adamson return status; 5511ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5512b1f69b75SAndy Adamson if (unlikely(!p)) 5513b1f69b75SAndy Adamson goto out_overflow; 5514ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 5515ea9d23f5STrond Myklebust decode_stateid(xdr, &res->stateid); 5516ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5517ea9d23f5STrond Myklebust if (unlikely(!p)) 5518ea9d23f5STrond Myklebust goto out_overflow; 5519b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5520b1f69b75SAndy Adamson if (!layout_count) { 5521b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5522b1f69b75SAndy Adamson __func__); 5523b1f69b75SAndy Adamson return -EINVAL; 5524b1f69b75SAndy Adamson } 5525b1f69b75SAndy Adamson 552635124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5527b1f69b75SAndy Adamson if (unlikely(!p)) 5528b1f69b75SAndy Adamson goto out_overflow; 5529b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5530b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5531b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5532b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 553335124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5534b1f69b75SAndy Adamson 5535b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5536b1f69b75SAndy Adamson __func__, 5537b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5538b1f69b75SAndy Adamson (unsigned long)res->range.length, 5539b1f69b75SAndy Adamson res->range.iomode, 5540b1f69b75SAndy Adamson res->type, 554135124a09SWeston Andros Adamson res->layoutp->len); 5542b1f69b75SAndy Adamson 554335124a09SWeston Andros Adamson hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; 554435124a09SWeston Andros Adamson recvd = req->rq_rcv_buf.len - hdrlen; 554535124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 554635124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 554735124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 554835124a09SWeston Andros Adamson res->layoutp->len, recvd); 554935124a09SWeston Andros Adamson return -EINVAL; 555035124a09SWeston Andros Adamson } 555135124a09SWeston Andros Adamson 555235124a09SWeston Andros Adamson xdr_read_pages(xdr, res->layoutp->len); 5553b1f69b75SAndy Adamson 5554b1f69b75SAndy Adamson if (layout_count > 1) { 5555b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5556b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5557b1f69b75SAndy Adamson * the client may see a response that is less than the 5558b1f69b75SAndy Adamson * minimum it requested. 5559b1f69b75SAndy Adamson */ 5560b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5561b1f69b75SAndy Adamson __func__, layout_count); 5562b1f69b75SAndy Adamson } 5563b1f69b75SAndy Adamson 5564b1f69b75SAndy Adamson return 0; 5565b1f69b75SAndy Adamson out_overflow: 5566b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5567b1f69b75SAndy Adamson return -EIO; 5568b1f69b75SAndy Adamson } 5569863a3c6cSAndy Adamson 5570cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5571cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5572cbe82603SBenny Halevy { 5573cbe82603SBenny Halevy __be32 *p; 5574cbe82603SBenny Halevy int status; 5575cbe82603SBenny Halevy 5576cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5577cbe82603SBenny Halevy if (status) 5578cbe82603SBenny Halevy return status; 5579cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5580cbe82603SBenny Halevy if (unlikely(!p)) 5581cbe82603SBenny Halevy goto out_overflow; 5582cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5583cbe82603SBenny Halevy if (res->lrs_present) 5584cbe82603SBenny Halevy status = decode_stateid(xdr, &res->stateid); 5585cbe82603SBenny Halevy return status; 5586cbe82603SBenny Halevy out_overflow: 5587cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 5588cbe82603SBenny Halevy return -EIO; 5589cbe82603SBenny Halevy } 5590cbe82603SBenny Halevy 5591863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5592863a3c6cSAndy Adamson struct rpc_rqst *req, 5593863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5594863a3c6cSAndy Adamson { 5595863a3c6cSAndy Adamson __be32 *p; 5596863a3c6cSAndy Adamson __u32 sizechanged; 5597863a3c6cSAndy Adamson int status; 5598863a3c6cSAndy Adamson 5599863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5600db29c089SAndy Adamson res->status = status; 5601863a3c6cSAndy Adamson if (status) 5602863a3c6cSAndy Adamson return status; 5603863a3c6cSAndy Adamson 5604863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5605863a3c6cSAndy Adamson if (unlikely(!p)) 5606863a3c6cSAndy Adamson goto out_overflow; 5607863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5608863a3c6cSAndy Adamson 5609863a3c6cSAndy Adamson if (sizechanged) { 5610863a3c6cSAndy Adamson /* throw away new size */ 5611863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5612863a3c6cSAndy Adamson if (unlikely(!p)) 5613863a3c6cSAndy Adamson goto out_overflow; 5614863a3c6cSAndy Adamson } 5615863a3c6cSAndy Adamson return 0; 5616863a3c6cSAndy Adamson out_overflow: 5617863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 5618863a3c6cSAndy Adamson return -EIO; 5619863a3c6cSAndy Adamson } 56207d974794SBryan Schumaker 56217d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 56227d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 56237d974794SBryan Schumaker { 56247d974794SBryan Schumaker __be32 *p; 56257d974794SBryan Schumaker int status; 56267d974794SBryan Schumaker int num_res; 56277d974794SBryan Schumaker 56287d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 56297d974794SBryan Schumaker if (status) 56307d974794SBryan Schumaker return status; 56317d974794SBryan Schumaker 56327d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56337d974794SBryan Schumaker if (unlikely(!p)) 56347d974794SBryan Schumaker goto out_overflow; 56357d974794SBryan Schumaker num_res = be32_to_cpup(p++); 56367d974794SBryan Schumaker if (num_res != 1) 56377d974794SBryan Schumaker goto out; 56387d974794SBryan Schumaker 56397d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56407d974794SBryan Schumaker if (unlikely(!p)) 56417d974794SBryan Schumaker goto out_overflow; 56427d974794SBryan Schumaker res->status = be32_to_cpup(p++); 56431cab0652SBryan Schumaker 56441cab0652SBryan Schumaker return status; 56457d974794SBryan Schumaker out_overflow: 56467d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 56477d974794SBryan Schumaker out: 56487d974794SBryan Schumaker return -EIO; 56497d974794SBryan Schumaker } 56509aeda35fSBryan Schumaker 56519aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 56529aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 56539aeda35fSBryan Schumaker { 56549aeda35fSBryan Schumaker __be32 *p; 56559aeda35fSBryan Schumaker int status; 56569aeda35fSBryan Schumaker 56579aeda35fSBryan Schumaker status = decode_op_hdr(xdr, OP_FREE_STATEID); 56589aeda35fSBryan Schumaker if (status) 56599aeda35fSBryan Schumaker return status; 56609aeda35fSBryan Schumaker 56619aeda35fSBryan Schumaker p = xdr_inline_decode(xdr, 4); 56629aeda35fSBryan Schumaker if (unlikely(!p)) 56639aeda35fSBryan Schumaker goto out_overflow; 56649aeda35fSBryan Schumaker res->status = be32_to_cpup(p++); 56659aeda35fSBryan Schumaker return res->status; 56669aeda35fSBryan Schumaker out_overflow: 56679aeda35fSBryan Schumaker print_overflow_msg(__func__, xdr); 56689aeda35fSBryan Schumaker return -EIO; 56699aeda35fSBryan Schumaker } 5670b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 5671b1f69b75SAndy Adamson 56721da177e4SLinus Torvalds /* 567349c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 567449c2559eSBenny Halevy */ 567549c2559eSBenny Halevy 567649c2559eSBenny Halevy /* 56771da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 56781da177e4SLinus Torvalds */ 5679bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 5680bf269551SChuck Lever struct xdr_stream *xdr, 5681bf269551SChuck Lever struct nfs_closeres *res) 56821da177e4SLinus Torvalds { 56831da177e4SLinus Torvalds struct compound_hdr hdr; 56841da177e4SLinus Torvalds int status; 56851da177e4SLinus Torvalds 5686bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 56871da177e4SLinus Torvalds if (status) 56881da177e4SLinus Torvalds goto out; 5689bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 56909b7b9fccSAndy Adamson if (status) 56919b7b9fccSAndy Adamson goto out; 5692bf269551SChuck Lever status = decode_putfh(xdr); 56931da177e4SLinus Torvalds if (status) 56941da177e4SLinus Torvalds goto out; 5695bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 5696516a6af6STrond Myklebust if (status != 0) 5697516a6af6STrond Myklebust goto out; 56986926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 56991da177e4SLinus Torvalds out: 57001da177e4SLinus Torvalds return status; 57011da177e4SLinus Torvalds } 57021da177e4SLinus Torvalds 57031da177e4SLinus Torvalds /* 57041da177e4SLinus Torvalds * Decode ACCESS response 57051da177e4SLinus Torvalds */ 5706bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5707bf269551SChuck Lever struct nfs4_accessres *res) 57081da177e4SLinus Torvalds { 57091da177e4SLinus Torvalds struct compound_hdr hdr; 57101da177e4SLinus Torvalds int status; 57111da177e4SLinus Torvalds 5712bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57139b7b9fccSAndy Adamson if (status) 57149b7b9fccSAndy Adamson goto out; 5715bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57169b7b9fccSAndy Adamson if (status) 57171da177e4SLinus Torvalds goto out; 5718bf269551SChuck Lever status = decode_putfh(xdr); 571976b32999STrond Myklebust if (status != 0) 572076b32999STrond Myklebust goto out; 5721bf269551SChuck Lever status = decode_access(xdr, res); 572276b32999STrond Myklebust if (status != 0) 572376b32999STrond Myklebust goto out; 57246926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 57251da177e4SLinus Torvalds out: 57261da177e4SLinus Torvalds return status; 57271da177e4SLinus Torvalds } 57281da177e4SLinus Torvalds 57291da177e4SLinus Torvalds /* 57301da177e4SLinus Torvalds * Decode LOOKUP response 57311da177e4SLinus Torvalds */ 5732bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5733bf269551SChuck Lever struct nfs4_lookup_res *res) 57341da177e4SLinus Torvalds { 57351da177e4SLinus Torvalds struct compound_hdr hdr; 57361da177e4SLinus Torvalds int status; 57371da177e4SLinus Torvalds 5738bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57399b7b9fccSAndy Adamson if (status) 57409b7b9fccSAndy Adamson goto out; 5741bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57429b7b9fccSAndy Adamson if (status) 57431da177e4SLinus Torvalds goto out; 5744bf269551SChuck Lever status = decode_putfh(xdr); 5745bf269551SChuck Lever if (status) 57461da177e4SLinus Torvalds goto out; 5747bf269551SChuck Lever status = decode_lookup(xdr); 5748bf269551SChuck Lever if (status) 57491da177e4SLinus Torvalds goto out; 5750bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5751bf269551SChuck Lever if (status) 57521da177e4SLinus Torvalds goto out; 57536926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 57541da177e4SLinus Torvalds out: 57551da177e4SLinus Torvalds return status; 57561da177e4SLinus Torvalds } 57571da177e4SLinus Torvalds 57581da177e4SLinus Torvalds /* 57591da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 57601da177e4SLinus Torvalds */ 5761bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 5762bf269551SChuck Lever struct xdr_stream *xdr, 5763bf269551SChuck Lever struct nfs4_lookup_res *res) 57641da177e4SLinus Torvalds { 57651da177e4SLinus Torvalds struct compound_hdr hdr; 57661da177e4SLinus Torvalds int status; 57671da177e4SLinus Torvalds 5768bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57699b7b9fccSAndy Adamson if (status) 57709b7b9fccSAndy Adamson goto out; 5771bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57729b7b9fccSAndy Adamson if (status) 57731da177e4SLinus Torvalds goto out; 5774bf269551SChuck Lever status = decode_putrootfh(xdr); 5775bf269551SChuck Lever if (status) 57761da177e4SLinus Torvalds goto out; 5777bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5778bf269551SChuck Lever if (status == 0) 57796926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 57801da177e4SLinus Torvalds out: 57811da177e4SLinus Torvalds return status; 57821da177e4SLinus Torvalds } 57831da177e4SLinus Torvalds 57841da177e4SLinus Torvalds /* 57851da177e4SLinus Torvalds * Decode REMOVE response 57861da177e4SLinus Torvalds */ 5787bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5788bf269551SChuck Lever struct nfs_removeres *res) 57891da177e4SLinus Torvalds { 57901da177e4SLinus Torvalds struct compound_hdr hdr; 57911da177e4SLinus Torvalds int status; 57921da177e4SLinus Torvalds 5793bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 57949b7b9fccSAndy Adamson if (status) 57959b7b9fccSAndy Adamson goto out; 5796bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 57979b7b9fccSAndy Adamson if (status) 57981da177e4SLinus Torvalds goto out; 5799bf269551SChuck Lever status = decode_putfh(xdr); 5800bf269551SChuck Lever if (status) 580116e42959STrond Myklebust goto out; 5802bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 5803bf269551SChuck Lever if (status) 580416e42959STrond Myklebust goto out; 58056926afd1STrond Myklebust decode_getfattr(xdr, res->dir_attr, res->server); 58061da177e4SLinus Torvalds out: 58071da177e4SLinus Torvalds return status; 58081da177e4SLinus Torvalds } 58091da177e4SLinus Torvalds 58101da177e4SLinus Torvalds /* 58111da177e4SLinus Torvalds * Decode RENAME response 58121da177e4SLinus Torvalds */ 5813bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5814bf269551SChuck Lever struct nfs_renameres *res) 58151da177e4SLinus Torvalds { 58161da177e4SLinus Torvalds struct compound_hdr hdr; 58171da177e4SLinus Torvalds int status; 58181da177e4SLinus Torvalds 5819bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58209b7b9fccSAndy Adamson if (status) 58219b7b9fccSAndy Adamson goto out; 5822bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58239b7b9fccSAndy Adamson if (status) 58241da177e4SLinus Torvalds goto out; 5825bf269551SChuck Lever status = decode_putfh(xdr); 5826bf269551SChuck Lever if (status) 58271da177e4SLinus Torvalds goto out; 5828bf269551SChuck Lever status = decode_savefh(xdr); 5829bf269551SChuck Lever if (status) 58301da177e4SLinus Torvalds goto out; 5831bf269551SChuck Lever status = decode_putfh(xdr); 5832bf269551SChuck Lever if (status) 58331da177e4SLinus Torvalds goto out; 5834bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 5835bf269551SChuck Lever if (status) 58366caf2c82STrond Myklebust goto out; 58376caf2c82STrond Myklebust /* Current FH is target directory */ 58386926afd1STrond Myklebust if (decode_getfattr(xdr, res->new_fattr, res->server)) 58396caf2c82STrond Myklebust goto out; 5840bf269551SChuck Lever status = decode_restorefh(xdr); 5841bf269551SChuck Lever if (status) 58426caf2c82STrond Myklebust goto out; 58436926afd1STrond Myklebust decode_getfattr(xdr, res->old_fattr, res->server); 58441da177e4SLinus Torvalds out: 58451da177e4SLinus Torvalds return status; 58461da177e4SLinus Torvalds } 58471da177e4SLinus Torvalds 58481da177e4SLinus Torvalds /* 58491da177e4SLinus Torvalds * Decode LINK response 58501da177e4SLinus Torvalds */ 5851bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5852bf269551SChuck Lever struct nfs4_link_res *res) 58531da177e4SLinus Torvalds { 58541da177e4SLinus Torvalds struct compound_hdr hdr; 58551da177e4SLinus Torvalds int status; 58561da177e4SLinus Torvalds 5857bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58589b7b9fccSAndy Adamson if (status) 58599b7b9fccSAndy Adamson goto out; 5860bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 58619b7b9fccSAndy Adamson if (status) 58621da177e4SLinus Torvalds goto out; 5863bf269551SChuck Lever status = decode_putfh(xdr); 5864bf269551SChuck Lever if (status) 58651da177e4SLinus Torvalds goto out; 5866bf269551SChuck Lever status = decode_savefh(xdr); 5867bf269551SChuck Lever if (status) 58681da177e4SLinus Torvalds goto out; 5869bf269551SChuck Lever status = decode_putfh(xdr); 5870bf269551SChuck Lever if (status) 58711da177e4SLinus Torvalds goto out; 5872bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 5873bf269551SChuck Lever if (status) 587491ba2eeeSTrond Myklebust goto out; 587591ba2eeeSTrond Myklebust /* 587691ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 587791ba2eeeSTrond Myklebust * filehandle. 587891ba2eeeSTrond Myklebust */ 58796926afd1STrond Myklebust if (decode_getfattr(xdr, res->dir_attr, res->server)) 588091ba2eeeSTrond Myklebust goto out; 5881bf269551SChuck Lever status = decode_restorefh(xdr); 5882bf269551SChuck Lever if (status) 588391ba2eeeSTrond Myklebust goto out; 58846926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 58851da177e4SLinus Torvalds out: 58861da177e4SLinus Torvalds return status; 58871da177e4SLinus Torvalds } 58881da177e4SLinus Torvalds 58891da177e4SLinus Torvalds /* 58901da177e4SLinus Torvalds * Decode CREATE response 58911da177e4SLinus Torvalds */ 5892bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5893bf269551SChuck Lever struct nfs4_create_res *res) 58941da177e4SLinus Torvalds { 58951da177e4SLinus Torvalds struct compound_hdr hdr; 58961da177e4SLinus Torvalds int status; 58971da177e4SLinus Torvalds 5898bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 58999b7b9fccSAndy Adamson if (status) 59009b7b9fccSAndy Adamson goto out; 5901bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59029b7b9fccSAndy Adamson if (status) 59031da177e4SLinus Torvalds goto out; 5904bf269551SChuck Lever status = decode_putfh(xdr); 5905bf269551SChuck Lever if (status) 59061da177e4SLinus Torvalds goto out; 5907bf269551SChuck Lever status = decode_savefh(xdr); 5908bf269551SChuck Lever if (status) 590956ae19f3STrond Myklebust goto out; 5910bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 5911bf269551SChuck Lever if (status) 59121da177e4SLinus Torvalds goto out; 5913bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 5914bf269551SChuck Lever if (status) 59151da177e4SLinus Torvalds goto out; 59166926afd1STrond Myklebust if (decode_getfattr(xdr, res->fattr, res->server)) 591756ae19f3STrond Myklebust goto out; 5918bf269551SChuck Lever status = decode_restorefh(xdr); 5919bf269551SChuck Lever if (status) 592056ae19f3STrond Myklebust goto out; 59216926afd1STrond Myklebust decode_getfattr(xdr, res->dir_fattr, res->server); 59221da177e4SLinus Torvalds out: 59231da177e4SLinus Torvalds return status; 59241da177e4SLinus Torvalds } 59251da177e4SLinus Torvalds 59261da177e4SLinus Torvalds /* 59271da177e4SLinus Torvalds * Decode SYMLINK response 59281da177e4SLinus Torvalds */ 5929bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5930bf269551SChuck Lever struct nfs4_create_res *res) 59311da177e4SLinus Torvalds { 5932bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 59331da177e4SLinus Torvalds } 59341da177e4SLinus Torvalds 59351da177e4SLinus Torvalds /* 59361da177e4SLinus Torvalds * Decode GETATTR response 59371da177e4SLinus Torvalds */ 5938bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5939bf269551SChuck Lever struct nfs4_getattr_res *res) 59401da177e4SLinus Torvalds { 59411da177e4SLinus Torvalds struct compound_hdr hdr; 59421da177e4SLinus Torvalds int status; 59431da177e4SLinus Torvalds 5944bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59451da177e4SLinus Torvalds if (status) 59461da177e4SLinus Torvalds goto out; 5947bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59489b7b9fccSAndy Adamson if (status) 59499b7b9fccSAndy Adamson goto out; 5950bf269551SChuck Lever status = decode_putfh(xdr); 59511da177e4SLinus Torvalds if (status) 59521da177e4SLinus Torvalds goto out; 59536926afd1STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 59541da177e4SLinus Torvalds out: 59551da177e4SLinus Torvalds return status; 59561da177e4SLinus Torvalds } 59571da177e4SLinus Torvalds 595823ec6965SJ. Bruce Fields /* 595923ec6965SJ. Bruce Fields * Encode an SETACL request 596023ec6965SJ. Bruce Fields */ 59619f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 59629f06c719SChuck Lever struct nfs_setaclargs *args) 596323ec6965SJ. Bruce Fields { 596423ec6965SJ. Bruce Fields struct compound_hdr hdr = { 596566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 596623ec6965SJ. Bruce Fields }; 596723ec6965SJ. Bruce Fields 59689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 59699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 59709f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 59719f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 5972d017931cSAndy Adamson encode_nops(&hdr); 597323ec6965SJ. Bruce Fields } 597405d564feSAndy Adamson 597523ec6965SJ. Bruce Fields /* 597623ec6965SJ. Bruce Fields * Decode SETACL response 597723ec6965SJ. Bruce Fields */ 597823ec6965SJ. Bruce Fields static int 5979bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 598073c403a9SBenny Halevy struct nfs_setaclres *res) 598123ec6965SJ. Bruce Fields { 598223ec6965SJ. Bruce Fields struct compound_hdr hdr; 598323ec6965SJ. Bruce Fields int status; 598423ec6965SJ. Bruce Fields 5985bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 598623ec6965SJ. Bruce Fields if (status) 598723ec6965SJ. Bruce Fields goto out; 5988bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59899b7b9fccSAndy Adamson if (status) 59909b7b9fccSAndy Adamson goto out; 5991bf269551SChuck Lever status = decode_putfh(xdr); 599223ec6965SJ. Bruce Fields if (status) 599323ec6965SJ. Bruce Fields goto out; 5994bf269551SChuck Lever status = decode_setattr(xdr); 599523ec6965SJ. Bruce Fields out: 599623ec6965SJ. Bruce Fields return status; 599723ec6965SJ. Bruce Fields } 59981da177e4SLinus Torvalds 59991da177e4SLinus Torvalds /* 6000029d105eSJ. Bruce Fields * Decode GETACL response 6001029d105eSJ. Bruce Fields */ 6002029d105eSJ. Bruce Fields static int 6003bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6004663c79b3SBenny Halevy struct nfs_getaclres *res) 6005029d105eSJ. Bruce Fields { 6006029d105eSJ. Bruce Fields struct compound_hdr hdr; 6007029d105eSJ. Bruce Fields int status; 6008029d105eSJ. Bruce Fields 6009331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6010331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6011331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6012331818f1STrond Myklebust } 6013bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6014029d105eSJ. Bruce Fields if (status) 6015029d105eSJ. Bruce Fields goto out; 6016bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60179b7b9fccSAndy Adamson if (status) 60189b7b9fccSAndy Adamson goto out; 6019bf269551SChuck Lever status = decode_putfh(xdr); 6020029d105eSJ. Bruce Fields if (status) 6021029d105eSJ. Bruce Fields goto out; 6022bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6023029d105eSJ. Bruce Fields 6024029d105eSJ. Bruce Fields out: 6025029d105eSJ. Bruce Fields return status; 6026029d105eSJ. Bruce Fields } 6027029d105eSJ. Bruce Fields 6028029d105eSJ. Bruce Fields /* 60291da177e4SLinus Torvalds * Decode CLOSE response 60301da177e4SLinus Torvalds */ 6031bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6032bf269551SChuck Lever struct nfs_closeres *res) 60331da177e4SLinus Torvalds { 60341da177e4SLinus Torvalds struct compound_hdr hdr; 60351da177e4SLinus Torvalds int status; 60361da177e4SLinus Torvalds 6037bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60381da177e4SLinus Torvalds if (status) 60391da177e4SLinus Torvalds goto out; 6040bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60419b7b9fccSAndy Adamson if (status) 60429b7b9fccSAndy Adamson goto out; 6043bf269551SChuck Lever status = decode_putfh(xdr); 60441da177e4SLinus Torvalds if (status) 60451da177e4SLinus Torvalds goto out; 6046bf269551SChuck Lever status = decode_close(xdr, res); 6047516a6af6STrond Myklebust if (status != 0) 6048516a6af6STrond Myklebust goto out; 6049516a6af6STrond Myklebust /* 6050516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6051516a6af6STrond Myklebust * in which case the getattr call will fail with 6052516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6053516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6054516a6af6STrond Myklebust */ 60556926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60561da177e4SLinus Torvalds out: 60571da177e4SLinus Torvalds return status; 60581da177e4SLinus Torvalds } 60591da177e4SLinus Torvalds 60601da177e4SLinus Torvalds /* 60611da177e4SLinus Torvalds * Decode OPEN response 60621da177e4SLinus Torvalds */ 6063bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6064bf269551SChuck Lever struct nfs_openres *res) 60651da177e4SLinus Torvalds { 60661da177e4SLinus Torvalds struct compound_hdr hdr; 60671da177e4SLinus Torvalds int status; 60681da177e4SLinus Torvalds 6069bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60701da177e4SLinus Torvalds if (status) 60711da177e4SLinus Torvalds goto out; 6072bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60739b7b9fccSAndy Adamson if (status) 60749b7b9fccSAndy Adamson goto out; 6075bf269551SChuck Lever status = decode_putfh(xdr); 60761da177e4SLinus Torvalds if (status) 60771da177e4SLinus Torvalds goto out; 6078bf269551SChuck Lever status = decode_savefh(xdr); 607956ae19f3STrond Myklebust if (status) 608056ae19f3STrond Myklebust goto out; 6081bf269551SChuck Lever status = decode_open(xdr, res); 60821da177e4SLinus Torvalds if (status) 60831da177e4SLinus Torvalds goto out; 6084bf269551SChuck Lever if (decode_getfh(xdr, &res->fh) != 0) 60851da177e4SLinus Torvalds goto out; 60866926afd1STrond Myklebust if (decode_getfattr(xdr, res->f_attr, res->server) != 0) 608756ae19f3STrond Myklebust goto out; 6088bf269551SChuck Lever if (decode_restorefh(xdr) != 0) 608956ae19f3STrond Myklebust goto out; 60906926afd1STrond Myklebust decode_getfattr(xdr, res->dir_attr, res->server); 60911da177e4SLinus Torvalds out: 60921da177e4SLinus Torvalds return status; 60931da177e4SLinus Torvalds } 60941da177e4SLinus Torvalds 60951da177e4SLinus Torvalds /* 60961da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 60971da177e4SLinus Torvalds */ 6098bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6099bf269551SChuck Lever struct xdr_stream *xdr, 6100bf269551SChuck Lever struct nfs_open_confirmres *res) 61011da177e4SLinus Torvalds { 61021da177e4SLinus Torvalds struct compound_hdr hdr; 61031da177e4SLinus Torvalds int status; 61041da177e4SLinus Torvalds 6105bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61061da177e4SLinus Torvalds if (status) 61071da177e4SLinus Torvalds goto out; 6108bf269551SChuck Lever status = decode_putfh(xdr); 61091da177e4SLinus Torvalds if (status) 61101da177e4SLinus Torvalds goto out; 6111bf269551SChuck Lever status = decode_open_confirm(xdr, res); 61121da177e4SLinus Torvalds out: 61131da177e4SLinus Torvalds return status; 61141da177e4SLinus Torvalds } 61151da177e4SLinus Torvalds 61161da177e4SLinus Torvalds /* 61171da177e4SLinus Torvalds * Decode OPEN response 61181da177e4SLinus Torvalds */ 6119bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6120bf269551SChuck Lever struct xdr_stream *xdr, 6121bf269551SChuck Lever struct nfs_openres *res) 61221da177e4SLinus Torvalds { 61231da177e4SLinus Torvalds struct compound_hdr hdr; 61241da177e4SLinus Torvalds int status; 61251da177e4SLinus Torvalds 6126bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61271da177e4SLinus Torvalds if (status) 61281da177e4SLinus Torvalds goto out; 6129bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61309b7b9fccSAndy Adamson if (status) 61319b7b9fccSAndy Adamson goto out; 6132bf269551SChuck Lever status = decode_putfh(xdr); 61331da177e4SLinus Torvalds if (status) 61341da177e4SLinus Torvalds goto out; 6135bf269551SChuck Lever status = decode_open(xdr, res); 6136864472e9STrond Myklebust if (status) 6137864472e9STrond Myklebust goto out; 61386926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 61391da177e4SLinus Torvalds out: 61401da177e4SLinus Torvalds return status; 61411da177e4SLinus Torvalds } 61421da177e4SLinus Torvalds 61431da177e4SLinus Torvalds /* 61441da177e4SLinus Torvalds * Decode SETATTR response 61451da177e4SLinus Torvalds */ 6146bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6147bf269551SChuck Lever struct xdr_stream *xdr, 6148bf269551SChuck Lever struct nfs_setattrres *res) 61491da177e4SLinus Torvalds { 61501da177e4SLinus Torvalds struct compound_hdr hdr; 61511da177e4SLinus Torvalds int status; 61521da177e4SLinus Torvalds 6153bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61541da177e4SLinus Torvalds if (status) 61551da177e4SLinus Torvalds goto out; 6156bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61579b7b9fccSAndy Adamson if (status) 61589b7b9fccSAndy Adamson goto out; 6159bf269551SChuck Lever status = decode_putfh(xdr); 61601da177e4SLinus Torvalds if (status) 61611da177e4SLinus Torvalds goto out; 6162bf269551SChuck Lever status = decode_setattr(xdr); 61631da177e4SLinus Torvalds if (status) 61641da177e4SLinus Torvalds goto out; 61656926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 61661da177e4SLinus Torvalds out: 61671da177e4SLinus Torvalds return status; 61681da177e4SLinus Torvalds } 61691da177e4SLinus Torvalds 61701da177e4SLinus Torvalds /* 61711da177e4SLinus Torvalds * Decode LOCK response 61721da177e4SLinus Torvalds */ 6173bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6174bf269551SChuck Lever struct nfs_lock_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_lock(xdr, res); 61891da177e4SLinus Torvalds out: 61901da177e4SLinus Torvalds return status; 61911da177e4SLinus Torvalds } 61921da177e4SLinus Torvalds 61931da177e4SLinus Torvalds /* 61941da177e4SLinus Torvalds * Decode LOCKT response 61951da177e4SLinus Torvalds */ 6196bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6197bf269551SChuck Lever struct nfs_lockt_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_lockt(xdr, res); 62121da177e4SLinus Torvalds out: 62131da177e4SLinus Torvalds return status; 62141da177e4SLinus Torvalds } 62151da177e4SLinus Torvalds 62161da177e4SLinus Torvalds /* 62171da177e4SLinus Torvalds * Decode LOCKU response 62181da177e4SLinus Torvalds */ 6219bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6220bf269551SChuck Lever struct nfs_locku_res *res) 62211da177e4SLinus Torvalds { 62221da177e4SLinus Torvalds struct compound_hdr hdr; 62231da177e4SLinus Torvalds int status; 62241da177e4SLinus Torvalds 6225bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62261da177e4SLinus Torvalds if (status) 62271da177e4SLinus Torvalds goto out; 6228bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62299b7b9fccSAndy Adamson if (status) 62309b7b9fccSAndy Adamson goto out; 6231bf269551SChuck Lever status = decode_putfh(xdr); 62321da177e4SLinus Torvalds if (status) 62331da177e4SLinus Torvalds goto out; 6234bf269551SChuck Lever status = decode_locku(xdr, res); 62351da177e4SLinus Torvalds out: 62361da177e4SLinus Torvalds return status; 62371da177e4SLinus Torvalds } 62381da177e4SLinus Torvalds 6239bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6240bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6241d3c7b7ccSTrond Myklebust { 6242d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6243d3c7b7ccSTrond Myklebust int status; 6244d3c7b7ccSTrond Myklebust 6245bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6246d3c7b7ccSTrond Myklebust if (!status) 6247bf269551SChuck Lever status = decode_release_lockowner(xdr); 6248d3c7b7ccSTrond Myklebust return status; 6249d3c7b7ccSTrond Myklebust } 6250d3c7b7ccSTrond Myklebust 62511da177e4SLinus Torvalds /* 62521da177e4SLinus Torvalds * Decode READLINK response 62531da177e4SLinus Torvalds */ 6254bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6255bf269551SChuck Lever struct xdr_stream *xdr, 6256f50c7000SBenny Halevy struct nfs4_readlink_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_readlink(xdr, rqstp); 62711da177e4SLinus Torvalds out: 62721da177e4SLinus Torvalds return status; 62731da177e4SLinus Torvalds } 62741da177e4SLinus Torvalds 62751da177e4SLinus Torvalds /* 62761da177e4SLinus Torvalds * Decode READDIR response 62771da177e4SLinus Torvalds */ 6278bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6279bf269551SChuck Lever struct nfs4_readdir_res *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_readdir(xdr, rqstp, res); 62941da177e4SLinus Torvalds out: 62951da177e4SLinus Torvalds return status; 62961da177e4SLinus Torvalds } 62971da177e4SLinus Torvalds 62981da177e4SLinus Torvalds /* 62991da177e4SLinus Torvalds * Decode Read response 63001da177e4SLinus Torvalds */ 6301bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6302bf269551SChuck Lever struct nfs_readres *res) 63031da177e4SLinus Torvalds { 63041da177e4SLinus Torvalds struct compound_hdr hdr; 63051da177e4SLinus Torvalds int status; 63061da177e4SLinus Torvalds 6307bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63081da177e4SLinus Torvalds if (status) 63091da177e4SLinus Torvalds goto out; 6310bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63119b7b9fccSAndy Adamson if (status) 63129b7b9fccSAndy Adamson goto out; 6313bf269551SChuck Lever status = decode_putfh(xdr); 63141da177e4SLinus Torvalds if (status) 63151da177e4SLinus Torvalds goto out; 6316bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 63171da177e4SLinus Torvalds if (!status) 63181da177e4SLinus Torvalds status = res->count; 63191da177e4SLinus Torvalds out: 63201da177e4SLinus Torvalds return status; 63211da177e4SLinus Torvalds } 63221da177e4SLinus Torvalds 63231da177e4SLinus Torvalds /* 63241da177e4SLinus Torvalds * Decode WRITE response 63251da177e4SLinus Torvalds */ 6326bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6327bf269551SChuck Lever struct nfs_writeres *res) 63281da177e4SLinus Torvalds { 63291da177e4SLinus Torvalds struct compound_hdr hdr; 63301da177e4SLinus Torvalds int status; 63311da177e4SLinus Torvalds 6332bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63331da177e4SLinus Torvalds if (status) 63341da177e4SLinus Torvalds goto out; 6335bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63369b7b9fccSAndy Adamson if (status) 63379b7b9fccSAndy Adamson goto out; 6338bf269551SChuck Lever status = decode_putfh(xdr); 63391da177e4SLinus Torvalds if (status) 63401da177e4SLinus Torvalds goto out; 6341bf269551SChuck Lever status = decode_write(xdr, res); 63424f9838c7STrond Myklebust if (status) 63434f9838c7STrond Myklebust goto out; 63447ffd1064SFred Isaman if (res->fattr) 63456926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63461da177e4SLinus Torvalds if (!status) 63471da177e4SLinus Torvalds status = res->count; 63481da177e4SLinus Torvalds out: 63491da177e4SLinus Torvalds return status; 63501da177e4SLinus Torvalds } 63511da177e4SLinus Torvalds 63521da177e4SLinus Torvalds /* 63531da177e4SLinus Torvalds * Decode COMMIT response 63541da177e4SLinus Torvalds */ 6355bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 63560b7c0153SFred Isaman struct nfs_commitres *res) 63571da177e4SLinus Torvalds { 63581da177e4SLinus Torvalds struct compound_hdr hdr; 63591da177e4SLinus Torvalds int status; 63601da177e4SLinus Torvalds 6361bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63621da177e4SLinus Torvalds if (status) 63631da177e4SLinus Torvalds goto out; 6364bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63659b7b9fccSAndy Adamson if (status) 63669b7b9fccSAndy Adamson goto out; 6367bf269551SChuck Lever status = decode_putfh(xdr); 63681da177e4SLinus Torvalds if (status) 63691da177e4SLinus Torvalds goto out; 6370bf269551SChuck Lever status = decode_commit(xdr, res); 63714f9838c7STrond Myklebust if (status) 63724f9838c7STrond Myklebust goto out; 6373988b6dceSFred Isaman if (res->fattr) 63746926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63751da177e4SLinus Torvalds out: 63761da177e4SLinus Torvalds return status; 63771da177e4SLinus Torvalds } 63781da177e4SLinus Torvalds 63791da177e4SLinus Torvalds /* 63808b173218SRicardo Labiaga * Decode FSINFO response 63811da177e4SLinus Torvalds */ 6382bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 63833dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 63841da177e4SLinus Torvalds { 63851da177e4SLinus Torvalds struct compound_hdr hdr; 63861da177e4SLinus Torvalds int status; 63871da177e4SLinus Torvalds 6388bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63891da177e4SLinus Torvalds if (!status) 6390bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 63919b7b9fccSAndy Adamson if (!status) 6392bf269551SChuck Lever status = decode_putfh(xdr); 63931da177e4SLinus Torvalds if (!status) 6394bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 63951da177e4SLinus Torvalds return status; 63961da177e4SLinus Torvalds } 63971da177e4SLinus Torvalds 63981da177e4SLinus Torvalds /* 63998b173218SRicardo Labiaga * Decode PATHCONF response 64001da177e4SLinus Torvalds */ 6401bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6402d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 64031da177e4SLinus Torvalds { 64041da177e4SLinus Torvalds struct compound_hdr hdr; 64051da177e4SLinus Torvalds int status; 64061da177e4SLinus Torvalds 6407bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64081da177e4SLinus Torvalds if (!status) 6409bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64109b7b9fccSAndy Adamson if (!status) 6411bf269551SChuck Lever status = decode_putfh(xdr); 64121da177e4SLinus Torvalds if (!status) 6413bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 64141da177e4SLinus Torvalds return status; 64151da177e4SLinus Torvalds } 64161da177e4SLinus Torvalds 64171da177e4SLinus Torvalds /* 64188b173218SRicardo Labiaga * Decode STATFS response 64191da177e4SLinus Torvalds */ 6420bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 642124ad148aSBenny Halevy struct nfs4_statfs_res *res) 64221da177e4SLinus Torvalds { 64231da177e4SLinus Torvalds struct compound_hdr hdr; 64241da177e4SLinus Torvalds int status; 64251da177e4SLinus Torvalds 6426bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64271da177e4SLinus Torvalds if (!status) 6428bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64299b7b9fccSAndy Adamson if (!status) 6430bf269551SChuck Lever status = decode_putfh(xdr); 64311da177e4SLinus Torvalds if (!status) 6432bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 64331da177e4SLinus Torvalds return status; 64341da177e4SLinus Torvalds } 64351da177e4SLinus Torvalds 64361da177e4SLinus Torvalds /* 64378b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 64381da177e4SLinus Torvalds */ 6439bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6440bf269551SChuck Lever struct xdr_stream *xdr, 6441bf269551SChuck Lever struct nfs4_server_caps_res *res) 64421da177e4SLinus Torvalds { 64431da177e4SLinus Torvalds struct compound_hdr hdr; 64441da177e4SLinus Torvalds int status; 64451da177e4SLinus Torvalds 6446bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64479b7b9fccSAndy Adamson if (status) 64489b7b9fccSAndy Adamson goto out; 6449bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 64509b7b9fccSAndy Adamson if (status) 64511da177e4SLinus Torvalds goto out; 6452bf269551SChuck Lever status = decode_putfh(xdr); 6453bf269551SChuck Lever if (status) 64541da177e4SLinus Torvalds goto out; 6455bf269551SChuck Lever status = decode_server_caps(xdr, res); 64561da177e4SLinus Torvalds out: 64571da177e4SLinus Torvalds return status; 64581da177e4SLinus Torvalds } 64591da177e4SLinus Torvalds 64601da177e4SLinus Torvalds /* 64611da177e4SLinus Torvalds * Decode RENEW response 64621da177e4SLinus Torvalds */ 6463bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6464bf269551SChuck Lever void *__unused) 64651da177e4SLinus Torvalds { 64661da177e4SLinus Torvalds struct compound_hdr hdr; 64671da177e4SLinus Torvalds int status; 64681da177e4SLinus Torvalds 6469bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64701da177e4SLinus Torvalds if (!status) 6471bf269551SChuck Lever status = decode_renew(xdr); 64721da177e4SLinus Torvalds return status; 64731da177e4SLinus Torvalds } 64741da177e4SLinus Torvalds 64751da177e4SLinus Torvalds /* 64768b173218SRicardo Labiaga * Decode SETCLIENTID response 64771da177e4SLinus Torvalds */ 6478bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6479bf269551SChuck Lever struct xdr_stream *xdr, 6480bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 64811da177e4SLinus Torvalds { 64821da177e4SLinus Torvalds struct compound_hdr hdr; 64831da177e4SLinus Torvalds int status; 64841da177e4SLinus Torvalds 6485bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64861da177e4SLinus Torvalds if (!status) 6487bf269551SChuck Lever status = decode_setclientid(xdr, res); 64881da177e4SLinus Torvalds return status; 64891da177e4SLinus Torvalds } 64901da177e4SLinus Torvalds 64911da177e4SLinus Torvalds /* 64928b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 64931da177e4SLinus Torvalds */ 6494bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 6495bf269551SChuck Lever struct xdr_stream *xdr, 6496bf269551SChuck Lever struct nfs_fsinfo *fsinfo) 64971da177e4SLinus Torvalds { 64981da177e4SLinus Torvalds struct compound_hdr hdr; 64991da177e4SLinus Torvalds int status; 65001da177e4SLinus Torvalds 6501bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65021da177e4SLinus Torvalds if (!status) 6503bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 65041da177e4SLinus Torvalds if (!status) 6505bf269551SChuck Lever status = decode_putrootfh(xdr); 65061da177e4SLinus Torvalds if (!status) 6507bf269551SChuck Lever status = decode_fsinfo(xdr, fsinfo); 65081da177e4SLinus Torvalds return status; 65091da177e4SLinus Torvalds } 65101da177e4SLinus Torvalds 65111da177e4SLinus Torvalds /* 65128b173218SRicardo Labiaga * Decode DELEGRETURN response 65131da177e4SLinus Torvalds */ 6514bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6515bf269551SChuck Lever struct xdr_stream *xdr, 6516bf269551SChuck Lever struct nfs4_delegreturnres *res) 65171da177e4SLinus Torvalds { 65181da177e4SLinus Torvalds struct compound_hdr hdr; 65191da177e4SLinus Torvalds int status; 65201da177e4SLinus Torvalds 6521bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65229b7b9fccSAndy Adamson if (status) 65239b7b9fccSAndy Adamson goto out; 6524bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65259b7b9fccSAndy Adamson if (status) 6526fa178f29STrond Myklebust goto out; 6527bf269551SChuck Lever status = decode_putfh(xdr); 6528fa178f29STrond Myklebust if (status != 0) 6529fa178f29STrond Myklebust goto out; 6530e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6531556ae3bbSJeff Layton if (status != 0) 6532556ae3bbSJeff Layton goto out; 6533e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6534fa178f29STrond Myklebust out: 65351da177e4SLinus Torvalds return status; 65361da177e4SLinus Torvalds } 65371da177e4SLinus Torvalds 6538683b57b4STrond Myklebust /* 65398b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6540683b57b4STrond Myklebust */ 6541bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6542bf269551SChuck Lever struct xdr_stream *xdr, 654322958463SBenny Halevy struct nfs4_fs_locations_res *res) 6544683b57b4STrond Myklebust { 6545683b57b4STrond Myklebust struct compound_hdr hdr; 6546683b57b4STrond Myklebust int status; 6547683b57b4STrond Myklebust 6548bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65499b7b9fccSAndy Adamson if (status) 65509b7b9fccSAndy Adamson goto out; 6551bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 65529b7b9fccSAndy Adamson if (status) 6553683b57b4STrond Myklebust goto out; 6554bf269551SChuck Lever status = decode_putfh(xdr); 6555bf269551SChuck Lever if (status) 6556683b57b4STrond Myklebust goto out; 6557bf269551SChuck Lever status = decode_lookup(xdr); 6558bf269551SChuck Lever if (status) 6559683b57b4STrond Myklebust goto out; 6560bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 65618b7e3f49STrond Myklebust status = decode_getfattr_generic(xdr, &res->fs_locations->fattr, 65628b7e3f49STrond Myklebust NULL, res->fs_locations, 65636926afd1STrond Myklebust res->fs_locations->server); 6564683b57b4STrond Myklebust out: 6565683b57b4STrond Myklebust return status; 6566683b57b4STrond Myklebust } 6567683b57b4STrond Myklebust 65685a5ea0d4SBryan Schumaker /* 65695a5ea0d4SBryan Schumaker * Decode SECINFO response 65705a5ea0d4SBryan Schumaker */ 65715a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 65725a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 65735a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 65745a5ea0d4SBryan Schumaker { 65755a5ea0d4SBryan Schumaker struct compound_hdr hdr; 65765a5ea0d4SBryan Schumaker int status; 65775a5ea0d4SBryan Schumaker 65785a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 65795a5ea0d4SBryan Schumaker if (status) 65805a5ea0d4SBryan Schumaker goto out; 65815a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 65825a5ea0d4SBryan Schumaker if (status) 65835a5ea0d4SBryan Schumaker goto out; 65845a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 65855a5ea0d4SBryan Schumaker if (status) 65865a5ea0d4SBryan Schumaker goto out; 65875a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 65885a5ea0d4SBryan Schumaker out: 65895a5ea0d4SBryan Schumaker return status; 65905a5ea0d4SBryan Schumaker } 65915a5ea0d4SBryan Schumaker 659299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 659399fe60d0SBenny Halevy /* 65948b173218SRicardo Labiaga * Decode EXCHANGE_ID response 659599fe60d0SBenny Halevy */ 6596bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 6597bf269551SChuck Lever struct xdr_stream *xdr, 659899fe60d0SBenny Halevy void *res) 659999fe60d0SBenny Halevy { 660099fe60d0SBenny Halevy struct compound_hdr hdr; 660199fe60d0SBenny Halevy int status; 660299fe60d0SBenny Halevy 6603bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 660499fe60d0SBenny Halevy if (!status) 6605bf269551SChuck Lever status = decode_exchange_id(xdr, res); 660699fe60d0SBenny Halevy return status; 660799fe60d0SBenny Halevy } 66082050f0ccSAndy Adamson 66092050f0ccSAndy Adamson /* 66108b173218SRicardo Labiaga * Decode CREATE_SESSION response 6611fc931582SAndy Adamson */ 6612bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 6613bf269551SChuck Lever struct xdr_stream *xdr, 6614fc931582SAndy Adamson struct nfs41_create_session_res *res) 6615fc931582SAndy Adamson { 6616fc931582SAndy Adamson struct compound_hdr hdr; 6617fc931582SAndy Adamson int status; 6618fc931582SAndy Adamson 6619bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6620fc931582SAndy Adamson if (!status) 6621bf269551SChuck Lever status = decode_create_session(xdr, res); 6622fc931582SAndy Adamson return status; 6623fc931582SAndy Adamson } 6624fc931582SAndy Adamson 6625fc931582SAndy Adamson /* 66268b173218SRicardo Labiaga * Decode DESTROY_SESSION response 66270f3e66c6SAndy Adamson */ 6628bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 6629bf269551SChuck Lever struct xdr_stream *xdr, 6630bf269551SChuck Lever void *res) 66310f3e66c6SAndy Adamson { 66320f3e66c6SAndy Adamson struct compound_hdr hdr; 66330f3e66c6SAndy Adamson int status; 66340f3e66c6SAndy Adamson 6635bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66360f3e66c6SAndy Adamson if (!status) 6637bf269551SChuck Lever status = decode_destroy_session(xdr, res); 66380f3e66c6SAndy Adamson return status; 66390f3e66c6SAndy Adamson } 66400f3e66c6SAndy Adamson 66410f3e66c6SAndy Adamson /* 66428b173218SRicardo Labiaga * Decode SEQUENCE response 6643fc01cea9SAndy Adamson */ 6644bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 6645bf269551SChuck Lever struct xdr_stream *xdr, 6646fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 6647fc01cea9SAndy Adamson { 6648fc01cea9SAndy Adamson struct compound_hdr hdr; 6649fc01cea9SAndy Adamson int status; 6650fc01cea9SAndy Adamson 6651bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6652fc01cea9SAndy Adamson if (!status) 6653bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 6654fc01cea9SAndy Adamson return status; 6655fc01cea9SAndy Adamson } 6656fc01cea9SAndy Adamson 6657fc01cea9SAndy Adamson /* 66588b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 66592050f0ccSAndy Adamson */ 6660bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 6661bf269551SChuck Lever struct xdr_stream *xdr, 66622050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 66632050f0ccSAndy Adamson { 66642050f0ccSAndy Adamson struct compound_hdr hdr; 66652050f0ccSAndy Adamson int status; 66662050f0ccSAndy Adamson 6667bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66682050f0ccSAndy Adamson if (!status) 6669bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 66702050f0ccSAndy Adamson if (!status) 6671bf269551SChuck Lever status = decode_putrootfh(xdr); 66722050f0ccSAndy Adamson if (!status) 6673bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 66742050f0ccSAndy Adamson return status; 66752050f0ccSAndy Adamson } 667618019753SRicardo Labiaga 667718019753SRicardo Labiaga /* 667818019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 667918019753SRicardo Labiaga */ 6680bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 6681bf269551SChuck Lever struct xdr_stream *xdr, 668218019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 668318019753SRicardo Labiaga { 668418019753SRicardo Labiaga struct compound_hdr hdr; 668518019753SRicardo Labiaga int status; 668618019753SRicardo Labiaga 6687bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 668818019753SRicardo Labiaga if (!status) 6689bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 669018019753SRicardo Labiaga if (!status) 6691bf269551SChuck Lever status = decode_reclaim_complete(xdr, (void *)NULL); 669218019753SRicardo Labiaga return status; 669318019753SRicardo Labiaga } 6694b1f69b75SAndy Adamson 6695b1f69b75SAndy Adamson /* 66967f11d8d3SAndy Adamson * Decode GETDEVICELIST response 66977f11d8d3SAndy Adamson */ 66987f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp, 66997f11d8d3SAndy Adamson struct xdr_stream *xdr, 67007f11d8d3SAndy Adamson struct nfs4_getdevicelist_res *res) 67017f11d8d3SAndy Adamson { 67027f11d8d3SAndy Adamson struct compound_hdr hdr; 67037f11d8d3SAndy Adamson int status; 67047f11d8d3SAndy Adamson 67057f11d8d3SAndy Adamson dprintk("encoding getdevicelist!\n"); 67067f11d8d3SAndy Adamson 67077f11d8d3SAndy Adamson status = decode_compound_hdr(xdr, &hdr); 67087f11d8d3SAndy Adamson if (status != 0) 67097f11d8d3SAndy Adamson goto out; 67107f11d8d3SAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 67117f11d8d3SAndy Adamson if (status != 0) 67127f11d8d3SAndy Adamson goto out; 67137f11d8d3SAndy Adamson status = decode_putfh(xdr); 67147f11d8d3SAndy Adamson if (status != 0) 67157f11d8d3SAndy Adamson goto out; 67167f11d8d3SAndy Adamson status = decode_getdevicelist(xdr, res->devlist); 67177f11d8d3SAndy Adamson out: 67187f11d8d3SAndy Adamson return status; 67197f11d8d3SAndy Adamson } 67207f11d8d3SAndy Adamson 67217f11d8d3SAndy Adamson /* 6722b1f69b75SAndy Adamson * Decode GETDEVINFO response 6723b1f69b75SAndy Adamson */ 6724bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 6725bf269551SChuck Lever struct xdr_stream *xdr, 6726b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 6727b1f69b75SAndy Adamson { 6728b1f69b75SAndy Adamson struct compound_hdr hdr; 6729b1f69b75SAndy Adamson int status; 6730b1f69b75SAndy Adamson 6731bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6732b1f69b75SAndy Adamson if (status != 0) 6733b1f69b75SAndy Adamson goto out; 6734bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6735b1f69b75SAndy Adamson if (status != 0) 6736b1f69b75SAndy Adamson goto out; 6737bf269551SChuck Lever status = decode_getdeviceinfo(xdr, res->pdev); 6738b1f69b75SAndy Adamson out: 6739b1f69b75SAndy Adamson return status; 6740b1f69b75SAndy Adamson } 6741b1f69b75SAndy Adamson 6742b1f69b75SAndy Adamson /* 6743b1f69b75SAndy Adamson * Decode LAYOUTGET response 6744b1f69b75SAndy Adamson */ 6745bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 6746bf269551SChuck Lever struct xdr_stream *xdr, 6747b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6748b1f69b75SAndy Adamson { 6749b1f69b75SAndy Adamson struct compound_hdr hdr; 6750b1f69b75SAndy Adamson int status; 6751b1f69b75SAndy Adamson 6752bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6753b1f69b75SAndy Adamson if (status) 6754b1f69b75SAndy Adamson goto out; 6755bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 6756b1f69b75SAndy Adamson if (status) 6757b1f69b75SAndy Adamson goto out; 6758bf269551SChuck Lever status = decode_putfh(xdr); 6759b1f69b75SAndy Adamson if (status) 6760b1f69b75SAndy Adamson goto out; 6761bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 6762b1f69b75SAndy Adamson out: 6763b1f69b75SAndy Adamson return status; 6764b1f69b75SAndy Adamson } 6765863a3c6cSAndy Adamson 6766863a3c6cSAndy Adamson /* 6767cbe82603SBenny Halevy * Decode LAYOUTRETURN response 6768cbe82603SBenny Halevy */ 6769cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 6770cbe82603SBenny Halevy struct xdr_stream *xdr, 6771cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6772cbe82603SBenny Halevy { 6773cbe82603SBenny Halevy struct compound_hdr hdr; 6774cbe82603SBenny Halevy int status; 6775cbe82603SBenny Halevy 6776cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 6777cbe82603SBenny Halevy if (status) 6778cbe82603SBenny Halevy goto out; 6779cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 6780cbe82603SBenny Halevy if (status) 6781cbe82603SBenny Halevy goto out; 6782cbe82603SBenny Halevy status = decode_putfh(xdr); 6783cbe82603SBenny Halevy if (status) 6784cbe82603SBenny Halevy goto out; 6785cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 6786cbe82603SBenny Halevy out: 6787cbe82603SBenny Halevy return status; 6788cbe82603SBenny Halevy } 6789cbe82603SBenny Halevy 6790cbe82603SBenny Halevy /* 6791863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 6792863a3c6cSAndy Adamson */ 6793863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 6794863a3c6cSAndy Adamson struct xdr_stream *xdr, 6795863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6796863a3c6cSAndy Adamson { 6797863a3c6cSAndy Adamson struct compound_hdr hdr; 6798863a3c6cSAndy Adamson int status; 6799863a3c6cSAndy Adamson 6800863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 6801863a3c6cSAndy Adamson if (status) 6802863a3c6cSAndy Adamson goto out; 6803863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 6804863a3c6cSAndy Adamson if (status) 6805863a3c6cSAndy Adamson goto out; 6806863a3c6cSAndy Adamson status = decode_putfh(xdr); 6807863a3c6cSAndy Adamson if (status) 6808863a3c6cSAndy Adamson goto out; 6809863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 6810863a3c6cSAndy Adamson if (status) 6811863a3c6cSAndy Adamson goto out; 68126926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 6813863a3c6cSAndy Adamson out: 6814863a3c6cSAndy Adamson return status; 6815863a3c6cSAndy Adamson } 6816fca78d6dSBryan Schumaker 6817fca78d6dSBryan Schumaker /* 6818fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 6819fca78d6dSBryan Schumaker */ 6820fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 6821fca78d6dSBryan Schumaker struct xdr_stream *xdr, 6822fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 6823fca78d6dSBryan Schumaker { 6824fca78d6dSBryan Schumaker struct compound_hdr hdr; 6825fca78d6dSBryan Schumaker int status; 6826fca78d6dSBryan Schumaker 6827fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 6828fca78d6dSBryan Schumaker if (status) 6829fca78d6dSBryan Schumaker goto out; 6830fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 6831fca78d6dSBryan Schumaker if (status) 6832fca78d6dSBryan Schumaker goto out; 6833fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 6834fca78d6dSBryan Schumaker if (status) 6835fca78d6dSBryan Schumaker goto out; 683631e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 6837fca78d6dSBryan Schumaker out: 6838fca78d6dSBryan Schumaker return status; 6839fca78d6dSBryan Schumaker } 68407d974794SBryan Schumaker 68417d974794SBryan Schumaker /* 68427d974794SBryan Schumaker * Decode TEST_STATEID response 68437d974794SBryan Schumaker */ 68447d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 68457d974794SBryan Schumaker struct xdr_stream *xdr, 68467d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 68477d974794SBryan Schumaker { 68487d974794SBryan Schumaker struct compound_hdr hdr; 68497d974794SBryan Schumaker int status; 68507d974794SBryan Schumaker 68517d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 68527d974794SBryan Schumaker if (status) 68537d974794SBryan Schumaker goto out; 68547d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 68557d974794SBryan Schumaker if (status) 68567d974794SBryan Schumaker goto out; 68577d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 68587d974794SBryan Schumaker out: 68597d974794SBryan Schumaker return status; 68607d974794SBryan Schumaker } 68619aeda35fSBryan Schumaker 68629aeda35fSBryan Schumaker /* 68639aeda35fSBryan Schumaker * Decode FREE_STATEID response 68649aeda35fSBryan Schumaker */ 68659aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 68669aeda35fSBryan Schumaker struct xdr_stream *xdr, 68679aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 68689aeda35fSBryan Schumaker { 68699aeda35fSBryan Schumaker struct compound_hdr hdr; 68709aeda35fSBryan Schumaker int status; 68719aeda35fSBryan Schumaker 68729aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 68739aeda35fSBryan Schumaker if (status) 68749aeda35fSBryan Schumaker goto out; 68759aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 68769aeda35fSBryan Schumaker if (status) 68779aeda35fSBryan Schumaker goto out; 68789aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 68799aeda35fSBryan Schumaker out: 68809aeda35fSBryan Schumaker return status; 68819aeda35fSBryan Schumaker } 688299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 688399fe60d0SBenny Halevy 6884573c4e1eSChuck Lever /** 6885573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 6886573c4e1eSChuck Lever * the local page cache. 6887573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 6888573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 6889573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 6890573c4e1eSChuck Lever * 6891573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 6892573c4e1eSChuck Lever * returned. 6893573c4e1eSChuck Lever * 6894573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 6895573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 6896573c4e1eSChuck Lever * on a directory already in our cache. 6897573c4e1eSChuck Lever */ 6898573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 6899573c4e1eSChuck Lever int plus) 69001da177e4SLinus Torvalds { 6901dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 69021da177e4SLinus Torvalds uint32_t len; 6903babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 6904babddc72SBryan Schumaker if (unlikely(!p)) 6905babddc72SBryan Schumaker goto out_overflow; 6906c08e76d0SChuck Lever if (*p == xdr_zero) { 6907babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 6908babddc72SBryan Schumaker if (unlikely(!p)) 6909babddc72SBryan Schumaker goto out_overflow; 6910c08e76d0SChuck Lever if (*p == xdr_zero) 6911573c4e1eSChuck Lever return -EAGAIN; 69121da177e4SLinus Torvalds entry->eof = 1; 6913573c4e1eSChuck Lever return -EBADCOOKIE; 69141da177e4SLinus Torvalds } 69151da177e4SLinus Torvalds 6916babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 6917babddc72SBryan Schumaker if (unlikely(!p)) 6918babddc72SBryan Schumaker goto out_overflow; 69191da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 69201da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 6921c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 6922babddc72SBryan Schumaker 69239af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 6924babddc72SBryan Schumaker if (unlikely(!p)) 6925babddc72SBryan Schumaker goto out_overflow; 69261da177e4SLinus Torvalds entry->name = (const char *) p; 69271da177e4SLinus Torvalds 69281da177e4SLinus Torvalds /* 69291da177e4SLinus Torvalds * In case the server doesn't return an inode number, 69301da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 69311da177e4SLinus Torvalds * since glibc seems to choke on it...) 69321da177e4SLinus Torvalds */ 69331da177e4SLinus Torvalds entry->ino = 1; 69344f082222STrond Myklebust entry->fattr->valid = 0; 69351da177e4SLinus Torvalds 69369af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 6937babddc72SBryan Schumaker goto out_overflow; 69389af8c222STrond Myklebust 69399af8c222STrond Myklebust if (decode_attr_length(xdr, &len, &p) < 0) 6940babddc72SBryan Schumaker goto out_overflow; 69419af8c222STrond Myklebust 6942573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 69438b7e3f49STrond Myklebust NULL, entry->server) < 0) 6944babddc72SBryan Schumaker goto out_overflow; 694528331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 694628331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 694728331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 694882f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 69499af8c222STrond Myklebust 69500b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 69510b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 69520b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 69530b26a0bfSTrond Myklebust 6954573c4e1eSChuck Lever return 0; 6955babddc72SBryan Schumaker 6956babddc72SBryan Schumaker out_overflow: 6957babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 6958573c4e1eSChuck Lever return -EAGAIN; 69591da177e4SLinus Torvalds } 69601da177e4SLinus Torvalds 69611da177e4SLinus Torvalds /* 69621da177e4SLinus Torvalds * We need to translate between nfs status return values and 69631da177e4SLinus Torvalds * the local errno values which may not be the same. 69641da177e4SLinus Torvalds */ 69651da177e4SLinus Torvalds static struct { 69661da177e4SLinus Torvalds int stat; 69671da177e4SLinus Torvalds int errno; 69681da177e4SLinus Torvalds } nfs_errtbl[] = { 69691da177e4SLinus Torvalds { NFS4_OK, 0 }, 6970856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 6971856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 6972856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 6973856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 6974856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 6975856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 6976856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 6977856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 6978856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 6979856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 6980856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 6981856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 6982856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 6983856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 6984856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 6985856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 6986856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 6987856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 6988856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 6989856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 6990856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 6991856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 6992fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 6993856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 6994856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 6995856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 6996856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 6997856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 6998856dff3dSBenny Halevy { -1, -EIO } 69991da177e4SLinus Torvalds }; 70001da177e4SLinus Torvalds 70011da177e4SLinus Torvalds /* 70021da177e4SLinus Torvalds * Convert an NFS error code to a local one. 70031da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 70041da177e4SLinus Torvalds */ 70051da177e4SLinus Torvalds static int 70060a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 70071da177e4SLinus Torvalds { 70081da177e4SLinus Torvalds int i; 70091da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 70101da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 70111da177e4SLinus Torvalds return nfs_errtbl[i].errno; 70121da177e4SLinus Torvalds } 70131da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 70141da177e4SLinus Torvalds /* The server is looney tunes. */ 7015fdcb4577STrond Myklebust return -EREMOTEIO; 70161da177e4SLinus Torvalds } 70171da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 70181da177e4SLinus Torvalds * handle it. 70191da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 70201da177e4SLinus Torvalds * not conflict with native Linux error codes. 70211da177e4SLinus Torvalds */ 7022856dff3dSBenny Halevy return -stat; 70231da177e4SLinus Torvalds } 70241da177e4SLinus Torvalds 70251da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 70261da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 70271da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 70289f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7029bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 70302bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 70312bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7032cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7033cc0175c1SChuck Lever .p_name = #proc, \ 70341da177e4SLinus Torvalds } 70351da177e4SLinus Torvalds 70361da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 70371da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 70381da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 70391da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 70401da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 70411da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 70421da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 70431da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 70441da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 70451da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 70461da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 70471da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 70481da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 70491da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 70501da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 70511da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 70521da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 70531da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 70541da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 70551da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 70561da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 70571da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 70581da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 70591da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 70601da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 70611da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 70621da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 70631da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 70641da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 70651da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 70661da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 70671da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7068029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 706923ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7070683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7071d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 70725a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 707399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 707499fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7075fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 70760f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7077fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 70782050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 707918019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7080b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7081b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7082863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7083cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7084fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 70857d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 70869aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 70877f11d8d3SAndy Adamson PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist), 708899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 70891da177e4SLinus Torvalds }; 70901da177e4SLinus Torvalds 7091a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 70921da177e4SLinus Torvalds .number = 4, 7093e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 70941da177e4SLinus Torvalds .procs = nfs4_procedures 70951da177e4SLinus Torvalds }; 70961da177e4SLinus Torvalds 70971da177e4SLinus Torvalds /* 70981da177e4SLinus Torvalds * Local variables: 70991da177e4SLinus Torvalds * c-basic-offset: 8 71001da177e4SLinus Torvalds * End: 71011da177e4SLinus Torvalds */ 7102