11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * fs/nfs/nfs4xdr.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Client-side XDR for NFSv4. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (c) 2002 The Regents of the University of Michigan. 71da177e4SLinus Torvalds * All rights reserved. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Kendrick Smith <kmsmith@umich.edu> 101da177e4SLinus Torvalds * Andy Adamson <andros@umich.edu> 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without 131da177e4SLinus Torvalds * modification, are permitted provided that the following conditions 141da177e4SLinus Torvalds * are met: 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright 171da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer. 181da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce the above copyright 191da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer in the 201da177e4SLinus Torvalds * documentation and/or other materials provided with the distribution. 211da177e4SLinus Torvalds * 3. Neither the name of the University nor the names of its 221da177e4SLinus Torvalds * contributors may be used to endorse or promote products derived 231da177e4SLinus Torvalds * from this software without specific prior written permission. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 261da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 271da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 281da177e4SLinus Torvalds * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291da177e4SLinus Torvalds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301da177e4SLinus Torvalds * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311da177e4SLinus Torvalds * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 321da177e4SLinus Torvalds * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 331da177e4SLinus Torvalds * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 341da177e4SLinus Torvalds * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 351da177e4SLinus Torvalds * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 361da177e4SLinus Torvalds */ 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #include <linux/param.h> 391da177e4SLinus Torvalds #include <linux/time.h> 401da177e4SLinus Torvalds #include <linux/mm.h> 411da177e4SLinus Torvalds #include <linux/errno.h> 421da177e4SLinus Torvalds #include <linux/string.h> 431da177e4SLinus Torvalds #include <linux/in.h> 441da177e4SLinus Torvalds #include <linux/pagemap.h> 451da177e4SLinus Torvalds #include <linux/proc_fs.h> 461da177e4SLinus Torvalds #include <linux/kdev_t.h> 47db8ac8baSWeston Andros Adamson #include <linux/module.h> 48db8ac8baSWeston Andros Adamson #include <linux/utsname.h> 491da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h> 502449ea2eSAlexandros Batsakis #include <linux/sunrpc/msg_prot.h> 515a5ea0d4SBryan Schumaker #include <linux/sunrpc/gss_api.h> 521da177e4SLinus Torvalds #include <linux/nfs.h> 531da177e4SLinus Torvalds #include <linux/nfs4.h> 541da177e4SLinus Torvalds #include <linux/nfs_fs.h> 551da177e4SLinus Torvalds #include <linux/nfs_idmap.h> 56f092075dSChuck Lever 574ce79717STrond Myklebust #include "nfs4_fs.h" 584882ef72SAlexandros Batsakis #include "internal.h" 5976e697baSTrond Myklebust #include "nfs4session.h" 60b1f69b75SAndy Adamson #include "pnfs.h" 61f092075dSChuck Lever #include "netns.h" 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 661da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 671da177e4SLinus Torvalds 680a8ea437SDavid Howells static int nfs4_stat_to_errno(int); 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 711da177e4SLinus Torvalds #ifdef DEBUG 721da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20 731da177e4SLinus Torvalds #else 741da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0 751da177e4SLinus Torvalds #endif 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* lock,open owner id: 789f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 791da177e4SLinus Torvalds */ 8095b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2) 81d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4) 829104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 831da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 841da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 851da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1) 861da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2) 879104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 889104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 899104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 909104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 911da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 921da177e4SLinus Torvalds (NFS4_FHSIZE >> 2)) 931da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz) 941da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 951da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 961da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz) 971da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 981da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2)) 99e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4 10096928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 1011da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 1021da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 103bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 104bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 105aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL 106aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */ 107aa9c2669SDavid Quigley #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN)) 108aa9c2669SDavid Quigley #define encode_readdir_space 24 109aa9c2669SDavid Quigley #define encode_readdir_bitmask_sz 3 110aa9c2669SDavid Quigley #else 111aa9c2669SDavid Quigley #define nfs4_label_maxsz 0 112aa9c2669SDavid Quigley #define encode_readdir_space 20 113aa9c2669SDavid Quigley #define encode_readdir_bitmask_sz 2 114aa9c2669SDavid Quigley #endif 11588034c3dSAndy Adamson /* We support only one layout type per file system */ 11688034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8) 11796928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */ 11896928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 11988034c3dSAndy Adamson 3 + 3 + 3 + nfs4_owner_maxsz + \ 120aa9c2669SDavid Quigley nfs4_group_maxsz + nfs4_label_maxsz + \ 121aa9c2669SDavid Quigley decode_mdsthreshold_maxsz)) 12296928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 12396928206SJ. Bruce Fields nfs4_fattr_value_maxsz) 12496928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 1259104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 1269104a55dSTrond Myklebust 1 + 2 + 1 + \ 1279104a55dSTrond Myklebust nfs4_owner_maxsz + \ 1289104a55dSTrond Myklebust nfs4_group_maxsz + \ 129aa9c2669SDavid Quigley nfs4_label_maxsz + \ 1309104a55dSTrond Myklebust 4 + 4) 1311da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz) 1321da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz) 13356ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 13456ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 1352f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz) 136dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three 137dae100c2SFred Isaman * layout types will be returned. 138dae100c2SFred Isaman */ 139dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 140dae100c2SFred Isaman nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 1411da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 1421da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz) 1431da177e4SLinus Torvalds #define encode_setclientid_maxsz \ 1441da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 145cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 146cc38bac3SChuck Lever XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ 147cc38bac3SChuck Lever 1 /* sc_prog */ + \ 148cc38bac3SChuck Lever XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 149cc38bac3SChuck Lever XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 150cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1511da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1521da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1531da177e4SLinus Torvalds 2 + \ 1541da177e4SLinus Torvalds 1024) /* large value for CLID_INUSE */ 1551da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \ 1561da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 1571da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2)) 1581da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \ 1591da177e4SLinus Torvalds (op_decode_hdr_maxsz) 160e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 161e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz) 1622cebf828STrond Myklebust #define encode_share_access_maxsz \ 1632cebf828STrond Myklebust (2) 1644882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1652cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1662cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1672cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1682cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1692cebf828STrond Myklebust open_owner_id_maxsz + \ 1702cebf828STrond Myklebust encode_opentype_maxsz + \ 1712cebf828STrond Myklebust encode_claim_null_maxsz) 1722cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1739104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1742cebf828STrond Myklebust decode_ace_maxsz) 1752cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1762cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1779104a55dSTrond Myklebust decode_stateid_maxsz + \ 1782cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1792cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1802cebf828STrond Myklebust decode_delegation_maxsz) 1819104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1829104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1839104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1849104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1859104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1869104a55dSTrond Myklebust decode_stateid_maxsz) 1879104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 1889104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1899104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 1909104a55dSTrond Myklebust encode_share_access_maxsz) 1919104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 1929104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1939104a55dSTrond Myklebust decode_stateid_maxsz) 1949104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 1959104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 1969104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 1979104a55dSTrond Myklebust decode_stateid_maxsz) 1989104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 1999104a55dSTrond Myklebust encode_stateid_maxsz + \ 2009104a55dSTrond Myklebust encode_attrs_maxsz) 2019104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 2029104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 2039104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 2049104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2059104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 2069104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 207aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \ 208aa9c2669SDavid Quigley nfs4_label_maxsz) 2099104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 210aa9c2669SDavid Quigley decode_verifier_maxsz + \ 211aa9c2669SDavid Quigley nfs4_label_maxsz + nfs4_fattr_maxsz) 2129104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 2139104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 2149104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2159104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2169104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2179104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2189104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2199104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2209104a55dSTrond Myklebust decode_verifier_maxsz) 2211da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2221da177e4SLinus Torvalds nfs4_name_maxsz) 2236ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2246ce18391SBenny Halevy decode_change_info_maxsz) 2251da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2261da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2276ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2286ce18391SBenny Halevy decode_change_info_maxsz + \ 2296ce18391SBenny Halevy decode_change_info_maxsz) 2301da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2311da177e4SLinus Torvalds nfs4_name_maxsz) 2326ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 233daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2349104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2359104a55dSTrond Myklebust 7 + \ 236daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 237daccbdedSTrond Myklebust encode_lockowner_maxsz) 2389104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2399104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2409104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2419104a55dSTrond Myklebust decode_lock_denied_maxsz) 242daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 243daccbdedSTrond Myklebust encode_lockowner_maxsz) 2449104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2459104a55dSTrond Myklebust decode_lock_denied_maxsz) 2469104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2479104a55dSTrond Myklebust encode_stateid_maxsz + \ 2489104a55dSTrond Myklebust 4) 2499104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2509104a55dSTrond Myklebust decode_stateid_maxsz) 251d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 252d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 253d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 254d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 255d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2569104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2579104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2581da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2591da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 26094a6d753SChuck Lever 1 + \ 26196928206SJ. Bruce Fields nfs4_fattr_maxsz) 2621da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2631da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2649104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2659104a55dSTrond Myklebust encode_attrs_maxsz) 2662cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2672cebf828STrond Myklebust decode_change_info_maxsz + \ 2682cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2699104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2709104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2711da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2721da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2739104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2749104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2759104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2769104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2779104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2789104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 279e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 280e6889620STrond Myklebust (encode_getattr_maxsz) 281e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 282e6889620STrond Myklebust (0) 2835a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2841650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2859b7b9fccSAndy Adamson 2869b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 287fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 288d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 289d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 290fc931582SAndy Adamson 29199fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 29299fe60d0SBenny Halevy encode_verifier_maxsz + \ 29399fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 29499fe60d0SBenny Halevy XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ 29599fe60d0SBenny Halevy 1 /* flags */ + \ 29699fe60d0SBenny Halevy 1 /* spa_how */ + \ 2972031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 2982031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 2992031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 300db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 301db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 302db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 303db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 304d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 305db8ac8baSWeston Andros Adamson 3 /* nii_date */) 30699fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 30799fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 30899fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 30999fe60d0SBenny Halevy 1 /* eir_flags */ + \ 31099fe60d0SBenny Halevy 1 /* spr_how */ + \ 3112031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3122031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3132031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 31499fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 31599fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 31699fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 31799fe60d0SBenny Halevy /* eir_server_scope<> */ \ 31899fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 31999fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 3207d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3217d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3227d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3237d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3247d2ed9acSWeston Andros Adamson 3 /* nii_date */) 325fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 326fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 327fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 328fc931582SAndy Adamson 1 /* ca_rdma_ird */) 329fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 330fc931582SAndy Adamson 2 /* csa_clientid */ + \ 331fc931582SAndy Adamson 1 /* csa_sequence */ + \ 332fc931582SAndy Adamson 1 /* csa_flags */ + \ 333fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 334fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 335fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 336fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 337fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 338fc931582SAndy Adamson 1 /* stamp */ + \ 339fc931582SAndy Adamson 1 /* machinename.len */ + \ 340fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 341fc931582SAndy Adamson 1 /* uid */ + \ 342fc931582SAndy Adamson 1 /* gid */ + \ 343fc931582SAndy Adamson 1 /* gids.len (0) */) 344fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 345fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 346fc931582SAndy Adamson 1 /* csr_sequence */ + \ 347fc931582SAndy Adamson 1 /* csr_flags */ + \ 348fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 349fc931582SAndy Adamson decode_channel_attrs_maxsz) 3507c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3517c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3527c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3537c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3547c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3557c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3567c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3577c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3587c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3597c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3600f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3610f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 36266245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 36366245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 364fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 365fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 366fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 367fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 36818019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 36918019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 3707f11d8d3SAndy Adamson #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \ 3717f11d8d3SAndy Adamson encode_verifier_maxsz) 3727f11d8d3SAndy Adamson #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \ 3737f11d8d3SAndy Adamson 2 /* nfs_cookie4 gdlr_cookie */ + \ 3747f11d8d3SAndy Adamson decode_verifier_maxsz \ 3757f11d8d3SAndy Adamson /* verifier4 gdlr_verifier */ + \ 3767f11d8d3SAndy Adamson 1 /* gdlr_deviceid_list count */ + \ 3777f11d8d3SAndy Adamson XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \ 3787f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE) \ 3797f11d8d3SAndy Adamson /* gdlr_deviceid_list */ + \ 3807f11d8d3SAndy Adamson 1 /* bool gdlr_eof */) 381b1f69b75SAndy Adamson #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \ 382b1f69b75SAndy Adamson XDR_QUADLEN(NFS4_DEVICEID4_SIZE)) 383b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 384b1f69b75SAndy Adamson 1 /* layout type */ + \ 385b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 386b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 387b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 388b1f69b75SAndy Adamson 1 /* notification bitmap */) 389b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 390b1f69b75SAndy Adamson encode_stateid_maxsz) 391b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 392b1f69b75SAndy Adamson decode_stateid_maxsz + \ 393b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 394863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 395863a3c6cSAndy Adamson 2 /* offset */ + \ 396863a3c6cSAndy Adamson 2 /* length */ + \ 397863a3c6cSAndy Adamson 1 /* reclaim */ + \ 398863a3c6cSAndy Adamson encode_stateid_maxsz + \ 399863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 400863a3c6cSAndy Adamson 2 /* last byte written */ + \ 401863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 402863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 403863a3c6cSAndy Adamson 1 /* NULL filelayout layoutupdate4 payload */) 404863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 405cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 406cbe82603SBenny Halevy encode_stateid_maxsz + \ 407cbe82603SBenny Halevy 1 /* FIXME: opaque lrf_body always empty at the moment */) 408cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 409cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 410fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 411fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 4127d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 4137d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4147d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 4159aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 4169aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4179f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 4189b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 4199b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 4209b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 4219b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4229b7b9fccSAndy Adamson 4231da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4241da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4251da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4269b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4271da177e4SLinus Torvalds encode_putfh_maxsz + \ 4289104a55dSTrond Myklebust encode_read_maxsz) 4291da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4309b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4311da177e4SLinus Torvalds decode_putfh_maxsz + \ 4329104a55dSTrond Myklebust decode_read_maxsz) 4331da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4349b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4351da177e4SLinus Torvalds encode_putfh_maxsz + \ 4369104a55dSTrond Myklebust encode_readlink_maxsz) 4371da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4389b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4391da177e4SLinus Torvalds decode_putfh_maxsz + \ 4409104a55dSTrond Myklebust decode_readlink_maxsz) 4411da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4429b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4431da177e4SLinus Torvalds encode_putfh_maxsz + \ 4449104a55dSTrond Myklebust encode_readdir_maxsz) 4451da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4469b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4471da177e4SLinus Torvalds decode_putfh_maxsz + \ 4489104a55dSTrond Myklebust decode_readdir_maxsz) 4491da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4509b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4511da177e4SLinus Torvalds encode_putfh_maxsz + \ 4529104a55dSTrond Myklebust encode_write_maxsz + \ 4534f9838c7STrond Myklebust encode_getattr_maxsz) 4541da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4559b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4561da177e4SLinus Torvalds decode_putfh_maxsz + \ 4579104a55dSTrond Myklebust decode_write_maxsz + \ 4584f9838c7STrond Myklebust decode_getattr_maxsz) 4591da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4609b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4611da177e4SLinus Torvalds encode_putfh_maxsz + \ 4628582715eSTrond Myklebust encode_commit_maxsz) 4631da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4649b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4651da177e4SLinus Torvalds decode_putfh_maxsz + \ 4668582715eSTrond Myklebust decode_commit_maxsz) 4671da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4689b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4691da177e4SLinus Torvalds encode_putfh_maxsz + \ 4702cebf828STrond Myklebust encode_open_maxsz + \ 4716168f62cSWeston Andros Adamson encode_access_maxsz + \ 4722cebf828STrond Myklebust encode_getfh_maxsz + \ 4732cebf828STrond Myklebust encode_getattr_maxsz) 4741da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4759b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4761da177e4SLinus Torvalds decode_putfh_maxsz + \ 4772cebf828STrond Myklebust decode_open_maxsz + \ 4786168f62cSWeston Andros Adamson decode_access_maxsz + \ 4792cebf828STrond Myklebust decode_getfh_maxsz + \ 4802cebf828STrond Myklebust decode_getattr_maxsz) 4811da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4821da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4831da177e4SLinus Torvalds encode_putfh_maxsz + \ 4849104a55dSTrond Myklebust encode_open_confirm_maxsz) 4859104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4869104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4871da177e4SLinus Torvalds decode_putfh_maxsz + \ 4889104a55dSTrond Myklebust decode_open_confirm_maxsz) 4891da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 4909b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4911da177e4SLinus Torvalds encode_putfh_maxsz + \ 4922cebf828STrond Myklebust encode_open_maxsz + \ 4936168f62cSWeston Andros Adamson encode_access_maxsz + \ 4942cebf828STrond Myklebust encode_getattr_maxsz) 4951da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 4969b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4971da177e4SLinus Torvalds decode_putfh_maxsz + \ 4982cebf828STrond Myklebust decode_open_maxsz + \ 4996168f62cSWeston Andros Adamson decode_access_maxsz + \ 5002cebf828STrond Myklebust decode_getattr_maxsz) 5011da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 5021da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5039b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5041da177e4SLinus Torvalds encode_putfh_maxsz + \ 5059104a55dSTrond Myklebust encode_open_downgrade_maxsz + \ 506516a6af6STrond Myklebust encode_getattr_maxsz) 5071da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 5081da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5099b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5101da177e4SLinus Torvalds decode_putfh_maxsz + \ 5119104a55dSTrond Myklebust decode_open_downgrade_maxsz + \ 512516a6af6STrond Myklebust decode_getattr_maxsz) 5131da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 5149b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5151da177e4SLinus Torvalds encode_putfh_maxsz + \ 5169104a55dSTrond Myklebust encode_close_maxsz + \ 517516a6af6STrond Myklebust encode_getattr_maxsz) 5181da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 5199b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5201da177e4SLinus Torvalds decode_putfh_maxsz + \ 5219104a55dSTrond Myklebust decode_close_maxsz + \ 522516a6af6STrond Myklebust decode_getattr_maxsz) 5231da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 5249b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5251da177e4SLinus Torvalds encode_putfh_maxsz + \ 5269104a55dSTrond Myklebust encode_setattr_maxsz + \ 5271da177e4SLinus Torvalds encode_getattr_maxsz) 5281da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5299b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5301da177e4SLinus Torvalds decode_putfh_maxsz + \ 5319104a55dSTrond Myklebust decode_setattr_maxsz + \ 5329104a55dSTrond Myklebust decode_getattr_maxsz) 5331da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5349b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5351da177e4SLinus Torvalds encode_putfh_maxsz + \ 5361da177e4SLinus Torvalds encode_fsinfo_maxsz) 5371da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5389b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5391da177e4SLinus Torvalds decode_putfh_maxsz + \ 5401da177e4SLinus Torvalds decode_fsinfo_maxsz) 5411da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5421da177e4SLinus Torvalds encode_renew_maxsz) 5431da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5441da177e4SLinus Torvalds decode_renew_maxsz) 5451da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5461da177e4SLinus Torvalds encode_setclientid_maxsz) 5471da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5481da177e4SLinus Torvalds decode_setclientid_maxsz) 5491da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5501da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 55183ca7f5aSChuck Lever encode_setclientid_confirm_maxsz) 5521da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5531da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 55483ca7f5aSChuck Lever decode_setclientid_confirm_maxsz) 5551da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5569b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5571da177e4SLinus Torvalds encode_putfh_maxsz + \ 5589104a55dSTrond Myklebust encode_lock_maxsz) 5591da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5609b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5611da177e4SLinus Torvalds decode_putfh_maxsz + \ 5629104a55dSTrond Myklebust decode_lock_maxsz) 5631da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5649b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5651da177e4SLinus Torvalds encode_putfh_maxsz + \ 5669104a55dSTrond Myklebust encode_lockt_maxsz) 5679104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5689b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5699104a55dSTrond Myklebust decode_putfh_maxsz + \ 5709104a55dSTrond Myklebust decode_lockt_maxsz) 5711da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5729b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5731da177e4SLinus Torvalds encode_putfh_maxsz + \ 5749104a55dSTrond Myklebust encode_locku_maxsz) 5751da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5769b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5771da177e4SLinus Torvalds decode_putfh_maxsz + \ 5789104a55dSTrond Myklebust decode_locku_maxsz) 579d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 580d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 581d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 582d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 583d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 584d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5851da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5869b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5871da177e4SLinus Torvalds encode_putfh_maxsz + \ 58876b32999STrond Myklebust encode_access_maxsz + \ 58976b32999STrond Myklebust encode_getattr_maxsz) 5901da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5919b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5921da177e4SLinus Torvalds decode_putfh_maxsz + \ 59376b32999STrond Myklebust decode_access_maxsz + \ 59476b32999STrond Myklebust decode_getattr_maxsz) 5951da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 5969b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5971da177e4SLinus Torvalds encode_putfh_maxsz + \ 59844c99933SChuck Lever encode_getattr_maxsz + \ 59944c99933SChuck Lever encode_renew_maxsz) 6001da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 6019b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6021da177e4SLinus Torvalds decode_putfh_maxsz + \ 60344c99933SChuck Lever decode_getattr_maxsz + \ 60444c99933SChuck Lever decode_renew_maxsz) 6051da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 6069b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6071da177e4SLinus Torvalds encode_putfh_maxsz + \ 6081da177e4SLinus Torvalds encode_lookup_maxsz + \ 6091da177e4SLinus Torvalds encode_getattr_maxsz + \ 6101da177e4SLinus Torvalds encode_getfh_maxsz) 6111da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 6129b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6131da177e4SLinus Torvalds decode_putfh_maxsz + \ 614e6889620STrond Myklebust decode_lookup_maxsz + \ 6151da177e4SLinus Torvalds decode_getattr_maxsz + \ 6161da177e4SLinus Torvalds decode_getfh_maxsz) 6171da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 6189b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6191da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 6201da177e4SLinus Torvalds encode_getattr_maxsz + \ 6211da177e4SLinus Torvalds encode_getfh_maxsz) 6221da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6239b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6241da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6251da177e4SLinus Torvalds decode_getattr_maxsz + \ 6261da177e4SLinus Torvalds decode_getfh_maxsz) 6271da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6291da177e4SLinus Torvalds encode_putfh_maxsz + \ 630778d2817STrond Myklebust encode_remove_maxsz) 6311da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6331da177e4SLinus Torvalds decode_putfh_maxsz + \ 634778d2817STrond Myklebust decode_remove_maxsz) 6351da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6369b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6371da177e4SLinus Torvalds encode_putfh_maxsz + \ 6381da177e4SLinus Torvalds encode_savefh_maxsz + \ 6391da177e4SLinus Torvalds encode_putfh_maxsz + \ 640778d2817STrond Myklebust encode_rename_maxsz) 6411da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6429b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6431da177e4SLinus Torvalds decode_putfh_maxsz + \ 6441da177e4SLinus Torvalds decode_savefh_maxsz + \ 6451da177e4SLinus Torvalds decode_putfh_maxsz + \ 646778d2817STrond Myklebust decode_rename_maxsz) 6471da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6489b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6491da177e4SLinus Torvalds encode_putfh_maxsz + \ 6501da177e4SLinus Torvalds encode_savefh_maxsz + \ 6511da177e4SLinus Torvalds encode_putfh_maxsz + \ 65291ba2eeeSTrond Myklebust encode_link_maxsz + \ 65391ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 654a9f6991bSTrond Myklebust encode_getattr_maxsz) 6551da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6569b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6571da177e4SLinus Torvalds decode_putfh_maxsz + \ 6581da177e4SLinus Torvalds decode_savefh_maxsz + \ 6591da177e4SLinus Torvalds decode_putfh_maxsz + \ 66091ba2eeeSTrond Myklebust decode_link_maxsz + \ 66191ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 66291ba2eeeSTrond Myklebust decode_getattr_maxsz) 6631da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6649b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6651da177e4SLinus Torvalds encode_putfh_maxsz + \ 6661da177e4SLinus Torvalds encode_symlink_maxsz + \ 6671da177e4SLinus Torvalds encode_getattr_maxsz + \ 6681da177e4SLinus Torvalds encode_getfh_maxsz) 6691da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6709b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6711da177e4SLinus Torvalds decode_putfh_maxsz + \ 6721da177e4SLinus Torvalds decode_symlink_maxsz + \ 6731da177e4SLinus Torvalds decode_getattr_maxsz + \ 6741da177e4SLinus Torvalds decode_getfh_maxsz) 6751da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6769b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6771da177e4SLinus Torvalds encode_putfh_maxsz + \ 6781da177e4SLinus Torvalds encode_create_maxsz + \ 67956ae19f3STrond Myklebust encode_getfh_maxsz + \ 68056ae19f3STrond Myklebust encode_getattr_maxsz) 6811da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 6829b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6831da177e4SLinus Torvalds decode_putfh_maxsz + \ 6841da177e4SLinus Torvalds decode_create_maxsz + \ 68556ae19f3STrond Myklebust decode_getfh_maxsz + \ 68656ae19f3STrond Myklebust decode_getattr_maxsz) 6871da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 6889b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6891da177e4SLinus Torvalds encode_putfh_maxsz + \ 6901da177e4SLinus Torvalds encode_getattr_maxsz) 6911da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 6929b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6931da177e4SLinus Torvalds decode_putfh_maxsz + \ 6941da177e4SLinus Torvalds decode_getattr_maxsz) 6951da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 6969b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6971da177e4SLinus Torvalds encode_putfh_maxsz + \ 6989104a55dSTrond Myklebust encode_statfs_maxsz) 6991da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 7009b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7011da177e4SLinus Torvalds decode_putfh_maxsz + \ 7029104a55dSTrond Myklebust decode_statfs_maxsz) 7031da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 7049b7b9fccSAndy Adamson encode_sequence_maxsz + \ 705ab91f264STrond Myklebust encode_putfh_maxsz + \ 7061da177e4SLinus Torvalds encode_getattr_maxsz) 7071da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 7089b7b9fccSAndy Adamson decode_sequence_maxsz + \ 709ab91f264STrond Myklebust decode_putfh_maxsz + \ 7101da177e4SLinus Torvalds decode_getattr_maxsz) 7111da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 7129b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7131da177e4SLinus Torvalds encode_putfh_maxsz + \ 714fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 715fa178f29STrond Myklebust encode_getattr_maxsz) 7161da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 718fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 719fa178f29STrond Myklebust decode_getattr_maxsz) 720029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7219b7b9fccSAndy Adamson encode_sequence_maxsz + \ 722029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7239104a55dSTrond Myklebust encode_getacl_maxsz) 724029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7259b7b9fccSAndy Adamson decode_sequence_maxsz + \ 726029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7279104a55dSTrond Myklebust decode_getacl_maxsz) 72823ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7299b7b9fccSAndy Adamson encode_sequence_maxsz + \ 73023ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7319104a55dSTrond Myklebust encode_setacl_maxsz) 73223ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7339b7b9fccSAndy Adamson decode_sequence_maxsz + \ 73423ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7359104a55dSTrond Myklebust decode_setacl_maxsz) 736683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 737683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7389b7b9fccSAndy Adamson encode_sequence_maxsz + \ 739683b57b4STrond Myklebust encode_putfh_maxsz + \ 740e6889620STrond Myklebust encode_lookup_maxsz + \ 741b03d735bSChuck Lever encode_fs_locations_maxsz + \ 742b03d735bSChuck Lever encode_renew_maxsz) 743683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 744683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7459b7b9fccSAndy Adamson decode_sequence_maxsz + \ 746683b57b4STrond Myklebust decode_putfh_maxsz + \ 747e6889620STrond Myklebust decode_lookup_maxsz + \ 748b03d735bSChuck Lever decode_fs_locations_maxsz + \ 749b03d735bSChuck Lever decode_renew_maxsz) 7505a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7515a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7525a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7535a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7545a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7555a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7565a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7575a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 75844c99933SChuck Lever #define NFS4_enc_fsid_present_sz \ 75944c99933SChuck Lever (compound_encode_hdr_maxsz + \ 76044c99933SChuck Lever encode_sequence_maxsz + \ 76144c99933SChuck Lever encode_putfh_maxsz + \ 76244c99933SChuck Lever encode_getfh_maxsz + \ 76344c99933SChuck Lever encode_renew_maxsz) 76444c99933SChuck Lever #define NFS4_dec_fsid_present_sz \ 76544c99933SChuck Lever (compound_decode_hdr_maxsz + \ 76644c99933SChuck Lever decode_sequence_maxsz + \ 76744c99933SChuck Lever decode_putfh_maxsz + \ 76844c99933SChuck Lever decode_getfh_maxsz + \ 76944c99933SChuck Lever decode_renew_maxsz) 77099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 7717c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 7727c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 7737c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 7747c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 7757c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 7767c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 77799fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 77899fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 77999fe60d0SBenny Halevy encode_exchange_id_maxsz) 78099fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 78199fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 78299fe60d0SBenny Halevy decode_exchange_id_maxsz) 783fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 784fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 785fc931582SAndy Adamson encode_create_session_maxsz) 786fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 787fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 788fc931582SAndy Adamson decode_create_session_maxsz) 7890f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 7900f3e66c6SAndy Adamson encode_destroy_session_maxsz) 7910f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 7920f3e66c6SAndy Adamson decode_destroy_session_maxsz) 79366245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 79466245539STrond Myklebust encode_destroy_clientid_maxsz) 79566245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 79666245539STrond Myklebust decode_destroy_clientid_maxsz) 797fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 798fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 799fc01cea9SAndy Adamson encode_sequence_maxsz) 800fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 801fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 802fc01cea9SAndy Adamson decode_sequence_maxsz) 8032050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 8042050f0ccSAndy Adamson encode_sequence_maxsz + \ 8052050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 8062050f0ccSAndy Adamson encode_fsinfo_maxsz) 8072050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 8082050f0ccSAndy Adamson decode_sequence_maxsz + \ 8092050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 8102050f0ccSAndy Adamson decode_fsinfo_maxsz) 81118019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 81218019753SRicardo Labiaga encode_sequence_maxsz + \ 81318019753SRicardo Labiaga encode_reclaim_complete_maxsz) 81418019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 81518019753SRicardo Labiaga decode_sequence_maxsz + \ 81618019753SRicardo Labiaga decode_reclaim_complete_maxsz) 8177f11d8d3SAndy Adamson #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \ 8187f11d8d3SAndy Adamson encode_sequence_maxsz + \ 8197f11d8d3SAndy Adamson encode_putfh_maxsz + \ 8207f11d8d3SAndy Adamson encode_getdevicelist_maxsz) 8217f11d8d3SAndy Adamson #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \ 8227f11d8d3SAndy Adamson decode_sequence_maxsz + \ 8237f11d8d3SAndy Adamson decode_putfh_maxsz + \ 8247f11d8d3SAndy Adamson decode_getdevicelist_maxsz) 825b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 826b1f69b75SAndy Adamson encode_sequence_maxsz +\ 827b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 828b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 829b1f69b75SAndy Adamson decode_sequence_maxsz + \ 830b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 831b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 832b1f69b75SAndy Adamson encode_sequence_maxsz + \ 833b1f69b75SAndy Adamson encode_putfh_maxsz + \ 834b1f69b75SAndy Adamson encode_layoutget_maxsz) 835b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 836b1f69b75SAndy Adamson decode_sequence_maxsz + \ 837b1f69b75SAndy Adamson decode_putfh_maxsz + \ 838b1f69b75SAndy Adamson decode_layoutget_maxsz) 839863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 840863a3c6cSAndy Adamson encode_sequence_maxsz +\ 841863a3c6cSAndy Adamson encode_putfh_maxsz + \ 842863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 843863a3c6cSAndy Adamson encode_getattr_maxsz) 844863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 845863a3c6cSAndy Adamson decode_sequence_maxsz + \ 846863a3c6cSAndy Adamson decode_putfh_maxsz + \ 847863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 848863a3c6cSAndy Adamson decode_getattr_maxsz) 849cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 850cbe82603SBenny Halevy encode_sequence_maxsz + \ 851cbe82603SBenny Halevy encode_putfh_maxsz + \ 852cbe82603SBenny Halevy encode_layoutreturn_maxsz) 853cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 854cbe82603SBenny Halevy decode_sequence_maxsz + \ 855cbe82603SBenny Halevy decode_putfh_maxsz + \ 856cbe82603SBenny Halevy decode_layoutreturn_maxsz) 857fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 858fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 859fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 860fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 861fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 862fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 863fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 864fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8657d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8667d974794SBryan Schumaker encode_sequence_maxsz + \ 8677d974794SBryan Schumaker encode_test_stateid_maxsz) 8687d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8697d974794SBryan Schumaker decode_sequence_maxsz + \ 8707d974794SBryan Schumaker decode_test_stateid_maxsz) 8719aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8729aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8739aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8749aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8759aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8769aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8772449ea2eSAlexandros Batsakis 8782449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8792449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8802449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8812449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8822449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8832449ea2eSAlexandros Batsakis XDR_UNIT); 8842449ea2eSAlexandros Batsakis 8852449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8862449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 8872449ea2eSAlexandros Batsakis decode_sequence_maxsz + 8882449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 8892449ea2eSAlexandros Batsakis XDR_UNIT); 890f1c097beSAndy Adamson 891f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH + 892f1c097beSAndy Adamson compound_decode_hdr_maxsz + 893f1c097beSAndy Adamson decode_sequence_maxsz) * 894f1c097beSAndy Adamson XDR_UNIT); 895f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 89699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 8971da177e4SLinus Torvalds 898bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 899bca79478STrond Myklebust [NF4BAD] = 0, 900bca79478STrond Myklebust [NF4REG] = S_IFREG, 901bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 902bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 903bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 904bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 905bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 906bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 907bca79478STrond Myklebust [NF4ATTRDIR] = 0, 908bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 9091da177e4SLinus Torvalds }; 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds struct compound_hdr { 9121da177e4SLinus Torvalds int32_t status; 9131da177e4SLinus Torvalds uint32_t nops; 914d017931cSAndy Adamson __be32 * nops_p; 9151da177e4SLinus Torvalds uint32_t taglen; 9161da177e4SLinus Torvalds char * tag; 9170c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 91866cc0429SBenny Halevy u32 minorversion; 9191da177e4SLinus Torvalds }; 9201da177e4SLinus Torvalds 92113c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 92213c65ce9SBenny Halevy { 92313c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 92413c65ce9SBenny Halevy BUG_ON(!p); 92513c65ce9SBenny Halevy return p; 92613c65ce9SBenny Halevy } 9271da177e4SLinus Torvalds 928cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 929cb17e556STrond Myklebust { 930cb17e556STrond Myklebust __be32 *p; 931cb17e556STrond Myklebust 932cb17e556STrond Myklebust p = xdr_reserve_space(xdr, len); 933cb17e556STrond Myklebust xdr_encode_opaque_fixed(p, buf, len); 934cb17e556STrond Myklebust } 935cb17e556STrond Myklebust 9361da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 9371da177e4SLinus Torvalds { 9388687b63aSAl Viro __be32 *p; 9391da177e4SLinus Torvalds 9406fdfb0bcSTrond Myklebust p = reserve_space(xdr, 4 + len); 9411da177e4SLinus Torvalds xdr_encode_opaque(p, str, len); 9421da177e4SLinus Torvalds } 9431da177e4SLinus Torvalds 9444ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9454ade9821STrond Myklebust { 9464ade9821STrond Myklebust __be32 *p; 9474ade9821STrond Myklebust 9484ade9821STrond Myklebust p = reserve_space(xdr, 4); 9494ade9821STrond Myklebust *p = cpu_to_be32(n); 9504ade9821STrond Myklebust } 9514ade9821STrond Myklebust 952ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 953ff2eb681STrond Myklebust { 954ff2eb681STrond Myklebust __be32 *p; 955ff2eb681STrond Myklebust 956ff2eb681STrond Myklebust p = reserve_space(xdr, 8); 957ff2eb681STrond Myklebust xdr_encode_hyper(p, n); 958ff2eb681STrond Myklebust } 959ff2eb681STrond Myklebust 9604ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9614ade9821STrond Myklebust const struct nfs_seqid *seqid) 9624ade9821STrond Myklebust { 9634ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 9644ade9821STrond Myklebust } 9654ade9821STrond Myklebust 9660c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9670c4e8c18SBenny Halevy struct rpc_rqst *req, 9680c4e8c18SBenny Halevy struct compound_hdr *hdr) 9691da177e4SLinus Torvalds { 9708687b63aSAl Viro __be32 *p; 971a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9720c4e8c18SBenny Halevy 9730c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9740c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9750c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9760c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9771da177e4SLinus Torvalds 9787fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 9796fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9806fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 981e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 982d017931cSAndy Adamson hdr->nops_p = p; 98334558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 984d017931cSAndy Adamson } 985d017931cSAndy Adamson 986ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 987ab19b481STrond Myklebust uint32_t replen, 988ab19b481STrond Myklebust struct compound_hdr *hdr) 989ab19b481STrond Myklebust { 990ab19b481STrond Myklebust encode_uint32(xdr, op); 991ab19b481STrond Myklebust hdr->nops++; 992ab19b481STrond Myklebust hdr->replen += replen; 993ab19b481STrond Myklebust } 994ab19b481STrond Myklebust 995d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 996d017931cSAndy Adamson { 9977fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 998d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 1001ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1002ea9d23f5STrond Myklebust { 10032d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 1004ea9d23f5STrond Myklebust } 1005ea9d23f5STrond Myklebust 10061da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 10071da177e4SLinus Torvalds { 1008cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 10091da177e4SLinus Torvalds } 10101da177e4SLinus Torvalds 1011aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1012aa9c2669SDavid Quigley const struct nfs4_label *label, 1013aa9c2669SDavid Quigley const struct nfs_server *server) 10141da177e4SLinus Torvalds { 10151da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10161da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10171da177e4SLinus Torvalds int owner_namelen = 0; 10181da177e4SLinus Torvalds int owner_grouplen = 0; 10198687b63aSAl Viro __be32 *p; 1020d7067b2dSTrond Myklebust unsigned i; 1021d7067b2dSTrond Myklebust uint32_t len = 0; 1022d7067b2dSTrond Myklebust uint32_t bmval_len; 1023d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10241da177e4SLinus Torvalds 10251da177e4SLinus Torvalds /* 10261da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10271da177e4SLinus Torvalds * In the worst-case, this would be 1028a09df2caSDavid Quigley * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 1029a09df2caSDavid Quigley * = 40 bytes, plus any contribution from variable-length fields 103023ec6965SJ. Bruce Fields * such as owner/group. 10311da177e4SLinus Torvalds */ 1032d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_SIZE) { 1033d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10341da177e4SLinus Torvalds len += 8; 1035d7067b2dSTrond Myklebust } 1036d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 1037d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10381da177e4SLinus Torvalds len += 4; 1039d7067b2dSTrond Myklebust } 10401da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 1041e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10421da177e4SLinus Torvalds if (owner_namelen < 0) { 1043fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1044e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 10451da177e4SLinus Torvalds /* XXX */ 10461da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10471da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10481da177e4SLinus Torvalds /* goto out; */ 10491da177e4SLinus Torvalds } 1050d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 10511da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10521da177e4SLinus Torvalds } 10531da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 1054e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10551da177e4SLinus Torvalds if (owner_grouplen < 0) { 1056fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1057e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 10581da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10591da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10601da177e4SLinus Torvalds /* goto out; */ 10611da177e4SLinus Torvalds } 1062d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 10631da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10641da177e4SLinus Torvalds } 1065d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1066d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10671da177e4SLinus Torvalds len += 16; 1068d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1069d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10701da177e4SLinus Torvalds len += 4; 1071d7067b2dSTrond Myklebust } 1072d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1073d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10741da177e4SLinus Torvalds len += 16; 1075d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1076d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10771da177e4SLinus Torvalds len += 4; 1078d7067b2dSTrond Myklebust } 1079b4a2cf76STrond Myklebust if (label) { 1080b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1081d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1082d7067b2dSTrond Myklebust } 1083d7067b2dSTrond Myklebust 1084d7067b2dSTrond Myklebust if (bmval[2] != 0) 1085b4a2cf76STrond Myklebust bmval_len = 3; 1086d7067b2dSTrond Myklebust else if (bmval[1] != 0) 1087d7067b2dSTrond Myklebust bmval_len = 2; 1088d7067b2dSTrond Myklebust else 1089d7067b2dSTrond Myklebust bmval_len = 1; 1090b4a2cf76STrond Myklebust 1091d7067b2dSTrond Myklebust p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len); 10921da177e4SLinus Torvalds 1093b4a2cf76STrond Myklebust *p++ = cpu_to_be32(bmval_len); 1094d7067b2dSTrond Myklebust for (i = 0; i < bmval_len; i++) 1095d7067b2dSTrond Myklebust *p++ = cpu_to_be32(bmval[i]); 1096d7067b2dSTrond Myklebust *p++ = cpu_to_be32(len); 10971da177e4SLinus Torvalds 1098d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1099b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1100d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1101e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1102d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1103811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1104d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1105811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1106d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11071da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1108e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1109042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec); 1110d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 1111d7067b2dSTrond Myklebust } else 1112e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11131da177e4SLinus Torvalds } 1114d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11151da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1116e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1117042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec); 1118e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 1119d7067b2dSTrond Myklebust } else 1120e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11211da177e4SLinus Torvalds } 1122d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1123aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1124aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1125aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1126aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1127aa9c2669SDavid Quigley } 11281da177e4SLinus Torvalds 11291da177e4SLinus Torvalds /* out: */ 11301da177e4SLinus Torvalds } 11311da177e4SLinus Torvalds 1132cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11331da177e4SLinus Torvalds { 1134475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1135475d4ba0STrond Myklebust encode_uint32(xdr, access); 11361da177e4SLinus Torvalds } 11371da177e4SLinus Torvalds 1138cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11391da177e4SLinus Torvalds { 1140ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11414ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1142ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 11431da177e4SLinus Torvalds } 11441da177e4SLinus Torvalds 11450b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11461da177e4SLinus Torvalds { 11478687b63aSAl Viro __be32 *p; 11481da177e4SLinus Torvalds 1149475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1150475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1151b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 115234558513SBenny Halevy *p = cpu_to_be32(args->count); 11531da177e4SLinus Torvalds } 11541da177e4SLinus Torvalds 1155cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11561da177e4SLinus Torvalds { 11578687b63aSAl Viro __be32 *p; 11581da177e4SLinus Torvalds 1159475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1160475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11611da177e4SLinus Torvalds 11621da177e4SLinus Torvalds switch (create->ftype) { 11631da177e4SLinus Torvalds case NF4LNK: 116413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 116534558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 116694a6d753SChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 11671da177e4SLinus Torvalds break; 11681da177e4SLinus Torvalds 11691da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 117013c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1171e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 117234558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11731da177e4SLinus Torvalds break; 11741da177e4SLinus Torvalds 11751da177e4SLinus Torvalds default: 11761da177e4SLinus Torvalds break; 11771da177e4SLinus Torvalds } 11781da177e4SLinus Torvalds 1179811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 1180aa9c2669SDavid Quigley encode_attrs(xdr, create->attrs, create->label, create->server); 11811da177e4SLinus Torvalds } 11821da177e4SLinus Torvalds 1183cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11841da177e4SLinus Torvalds { 11858687b63aSAl Viro __be32 *p; 11861da177e4SLinus Torvalds 1187475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1188475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1189e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 119034558513SBenny Halevy *p = cpu_to_be32(bitmap); 11911da177e4SLinus Torvalds } 11921da177e4SLinus Torvalds 1193cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 11941da177e4SLinus Torvalds { 11958687b63aSAl Viro __be32 *p; 11961da177e4SLinus Torvalds 1197475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1198475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1199e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1200e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 120134558513SBenny Halevy *p = cpu_to_be32(bm1); 12021da177e4SLinus Torvalds } 12031da177e4SLinus Torvalds 1204dae100c2SFred Isaman static void 1205dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1206dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1207dae100c2SFred Isaman struct compound_hdr *hdr) 1208dae100c2SFred Isaman { 1209dae100c2SFred Isaman __be32 *p; 1210dae100c2SFred Isaman 1211ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1212dae100c2SFred Isaman if (bm2) { 1213dae100c2SFred Isaman p = reserve_space(xdr, 16); 1214dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1215dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1216dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1217dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1218dae100c2SFred Isaman } else if (bm1) { 1219dae100c2SFred Isaman p = reserve_space(xdr, 12); 1220dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1221dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1222dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1223dae100c2SFred Isaman } else { 1224dae100c2SFred Isaman p = reserve_space(xdr, 8); 1225dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1226dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1227dae100c2SFred Isaman } 1228dae100c2SFred Isaman } 1229dae100c2SFred Isaman 1230cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12311da177e4SLinus Torvalds { 1232a09df2caSDavid Quigley encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1233a09df2caSDavid Quigley bitmask[1] & nfs4_fattr_bitmap[1], 1234a09df2caSDavid Quigley bitmask[2] & nfs4_fattr_bitmap[2], 1235a09df2caSDavid Quigley hdr); 12361da177e4SLinus Torvalds } 12371da177e4SLinus Torvalds 123888034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12391549210fSTrond Myklebust const u32 *open_bitmap, 124088034c3dSAndy Adamson struct compound_hdr *hdr) 124188034c3dSAndy Adamson { 124288034c3dSAndy Adamson encode_getattr_three(xdr, 12431549210fSTrond Myklebust bitmask[0] & open_bitmap[0], 12441549210fSTrond Myklebust bitmask[1] & open_bitmap[1], 12451549210fSTrond Myklebust bitmask[2] & open_bitmap[2], 124688034c3dSAndy Adamson hdr); 124788034c3dSAndy Adamson } 124888034c3dSAndy Adamson 1249cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12501da177e4SLinus Torvalds { 1251dae100c2SFred Isaman encode_getattr_three(xdr, 1252dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1253dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1254dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1255dae100c2SFred Isaman hdr); 12561da177e4SLinus Torvalds } 12571da177e4SLinus Torvalds 1258cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1259830b8e33SManoj Naik { 1260cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1261cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1262830b8e33SManoj Naik } 1263830b8e33SManoj Naik 1264cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12651da177e4SLinus Torvalds { 1266ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12671da177e4SLinus Torvalds } 12681da177e4SLinus Torvalds 1269cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12701da177e4SLinus Torvalds { 1271ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12726fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12731da177e4SLinus Torvalds } 12741da177e4SLinus Torvalds 1275911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1276911d1aafSTrond Myklebust { 1277f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1278911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1279911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1280911d1aafSTrond Myklebust } 1281911d1aafSTrond Myklebust 1282911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1283911d1aafSTrond Myklebust { 1284911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1285911d1aafSTrond Myklebust return ~(uint64_t)0; 1286911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1287911d1aafSTrond Myklebust } 1288911d1aafSTrond Myklebust 1289daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1290daccbdedSTrond Myklebust { 1291daccbdedSTrond Myklebust __be32 *p; 1292daccbdedSTrond Myklebust 1293d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1294daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1295d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1296daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1297d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1298daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1299daccbdedSTrond Myklebust } 1300daccbdedSTrond Myklebust 13011da177e4SLinus Torvalds /* 13021da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13031da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13041da177e4SLinus Torvalds */ 1305cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13061da177e4SLinus Torvalds { 13078687b63aSAl Viro __be32 *p; 13081da177e4SLinus Torvalds 1309475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1310475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1311e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1312e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1313b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1314b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 131534558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1316911d1aafSTrond Myklebust if (args->new_lock_owner){ 13174ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1318ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->open_stateid); 13194ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1320daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13211da177e4SLinus Torvalds } 13221da177e4SLinus Torvalds else { 1323ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->lock_stateid); 13244ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13251da177e4SLinus Torvalds } 13261da177e4SLinus Torvalds } 13271da177e4SLinus Torvalds 1328cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13291da177e4SLinus Torvalds { 13308687b63aSAl Viro __be32 *p; 13311da177e4SLinus Torvalds 1332475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1333475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1334e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1335b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1336b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1337daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13381da177e4SLinus Torvalds } 13391da177e4SLinus Torvalds 1340cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13411da177e4SLinus Torvalds { 13428687b63aSAl Viro __be32 *p; 13431da177e4SLinus Torvalds 1344475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1345475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13464ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1347ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 1348ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1349b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 135034558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13511da177e4SLinus Torvalds } 13521da177e4SLinus Torvalds 1353d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1354d3c7b7ccSTrond Myklebust { 1355ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1356d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1357d3c7b7ccSTrond Myklebust } 1358d3c7b7ccSTrond Myklebust 1359cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13601da177e4SLinus Torvalds { 1361ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13626fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13631da177e4SLinus Torvalds } 13641da177e4SLinus Torvalds 1365dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 13661da177e4SLinus Torvalds { 13678687b63aSAl Viro __be32 *p; 13681da177e4SLinus Torvalds 136913c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1370dc0b027dSTrond Myklebust switch (fmode & (FMODE_READ|FMODE_WRITE)) { 13711da177e4SLinus Torvalds case FMODE_READ: 1372e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 13731da177e4SLinus Torvalds break; 13741da177e4SLinus Torvalds case FMODE_WRITE: 1375e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 13761da177e4SLinus Torvalds break; 13771da177e4SLinus Torvalds case FMODE_READ|FMODE_WRITE: 1378e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 13791da177e4SLinus Torvalds break; 13801da177e4SLinus Torvalds default: 1381e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 13821da177e4SLinus Torvalds } 138334558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13841da177e4SLinus Torvalds } 13851da177e4SLinus Torvalds 13861da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13871da177e4SLinus Torvalds { 13888687b63aSAl Viro __be32 *p; 13891da177e4SLinus Torvalds /* 13901da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13911da177e4SLinus Torvalds * owner 4 = 32 13921da177e4SLinus Torvalds */ 13934ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1394dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 139595b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1396b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 139795b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 139893f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1399d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 140095b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 140195b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 14021da177e4SLinus Torvalds } 14031da177e4SLinus Torvalds 14041da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14051da177e4SLinus Torvalds { 1406549b19ccSTrond Myklebust struct iattr dummy; 14078687b63aSAl Viro __be32 *p; 14081da177e4SLinus Torvalds 140913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1410549b19ccSTrond Myklebust switch(arg->createmode) { 1411549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 141234558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 1413aa9c2669SDavid Quigley encode_attrs(xdr, arg->u.attrs, arg->label, arg->server); 14141da177e4SLinus Torvalds break; 1415549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14164882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 1417aa9c2669SDavid Quigley encode_attrs(xdr, arg->u.attrs, arg->label, arg->server); 1418549b19ccSTrond Myklebust break; 1419549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1420549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1421549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1422549b19ccSTrond Myklebust break; 1423549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14244882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14254882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 14264882ef72SAlexandros Batsakis dummy.ia_valid = 0; 1427aa9c2669SDavid Quigley encode_attrs(xdr, &dummy, arg->label, arg->server); 14284882ef72SAlexandros Batsakis } 14294882ef72SAlexandros Batsakis } 14301da177e4SLinus Torvalds 14311da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14321da177e4SLinus Torvalds { 14338687b63aSAl Viro __be32 *p; 14341da177e4SLinus Torvalds 143513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14361da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14371da177e4SLinus Torvalds case 0: 143834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14391da177e4SLinus Torvalds break; 14401da177e4SLinus Torvalds default: 144134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14421da177e4SLinus Torvalds encode_createmode(xdr, arg); 14431da177e4SLinus Torvalds } 14441da177e4SLinus Torvalds } 14451da177e4SLinus Torvalds 1446bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14471da177e4SLinus Torvalds { 14488687b63aSAl Viro __be32 *p; 14491da177e4SLinus Torvalds 145013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14511da177e4SLinus Torvalds switch (delegation_type) { 14521da177e4SLinus Torvalds case 0: 145334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14541da177e4SLinus Torvalds break; 14551da177e4SLinus Torvalds case FMODE_READ: 145634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14571da177e4SLinus Torvalds break; 14581da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 145934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14601da177e4SLinus Torvalds break; 14611da177e4SLinus Torvalds default: 14621da177e4SLinus Torvalds BUG(); 14631da177e4SLinus Torvalds } 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds 14661da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14671da177e4SLinus Torvalds { 14688687b63aSAl Viro __be32 *p; 14691da177e4SLinus Torvalds 147013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 147134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14721da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14731da177e4SLinus Torvalds } 14741da177e4SLinus Torvalds 1475bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14761da177e4SLinus Torvalds { 14778687b63aSAl Viro __be32 *p; 14781da177e4SLinus Torvalds 147913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 148034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14811da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14821da177e4SLinus Torvalds } 14831da177e4SLinus Torvalds 14841da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14851da177e4SLinus Torvalds { 14868687b63aSAl Viro __be32 *p; 14871da177e4SLinus Torvalds 1488ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1489ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1490ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14911da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14921da177e4SLinus Torvalds } 14931da177e4SLinus Torvalds 1494d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1495d9fc6619STrond Myklebust { 1496d9fc6619STrond Myklebust __be32 *p; 1497d9fc6619STrond Myklebust 1498d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1499d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1500d9fc6619STrond Myklebust } 1501d9fc6619STrond Myklebust 1502d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1503d9fc6619STrond Myklebust { 1504d9fc6619STrond Myklebust __be32 *p; 1505d9fc6619STrond Myklebust 1506d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1507d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1508d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1509d9fc6619STrond Myklebust } 1510d9fc6619STrond Myklebust 1511cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15121da177e4SLinus Torvalds { 1513ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15141da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15151da177e4SLinus Torvalds encode_opentype(xdr, arg); 15161da177e4SLinus Torvalds switch (arg->claim) { 15171da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15181da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15191da177e4SLinus Torvalds break; 15201da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15211da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15221da177e4SLinus Torvalds break; 15231da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15241da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15251da177e4SLinus Torvalds break; 1526d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1527d9fc6619STrond Myklebust encode_claim_fh(xdr); 1528d9fc6619STrond Myklebust break; 1529d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1530d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1531d9fc6619STrond Myklebust break; 15321da177e4SLinus Torvalds default: 15331da177e4SLinus Torvalds BUG(); 15341da177e4SLinus Torvalds } 15351da177e4SLinus Torvalds } 15361da177e4SLinus Torvalds 1537cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15381da177e4SLinus Torvalds { 1539ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1540ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15414ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15421da177e4SLinus Torvalds } 15431da177e4SLinus Torvalds 1544cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15451da177e4SLinus Torvalds { 1546ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1547ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15484ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1549dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 15501da177e4SLinus Torvalds } 15511da177e4SLinus Torvalds 1552cf8cdbe5SAndy Adamson static void 1553d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15541da177e4SLinus Torvalds { 1555ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15566fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15571da177e4SLinus Torvalds } 15581da177e4SLinus Torvalds 1559cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15601da177e4SLinus Torvalds { 1561ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15621da177e4SLinus Torvalds } 15631da177e4SLinus Torvalds 1564cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 15651da177e4SLinus Torvalds { 15668687b63aSAl Viro __be32 *p; 15671da177e4SLinus Torvalds 1568ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15699b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15701da177e4SLinus Torvalds 157113c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1572b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 157334558513SBenny Halevy *p = cpu_to_be32(args->count); 15741da177e4SLinus Torvalds } 15751da177e4SLinus Torvalds 1576cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15771da177e4SLinus Torvalds { 1578aa9c2669SDavid Quigley uint32_t attrs[3] = { 157928331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 158028331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 158128331a46STrond Myklebust }; 15826f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1583cd93710eSChuck Lever __be32 *p, verf[2]; 15841da177e4SLinus Torvalds 158582f2e547SBryan Schumaker if (readdir->plus) { 158682f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 158728331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 158882f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 158982f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 159082f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 159182f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 15926f7a35bdSTrond Myklebust dircount >>= 1; 159382f2e547SBryan Schumaker } 159428331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 159528331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 159628331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 15976f7a35bdSTrond Myklebust 1598475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1599ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1600cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1601aa9c2669SDavid Quigley p = reserve_space(xdr, encode_readdir_space); 16026f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16036f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1604aa9c2669SDavid Quigley *p++ = cpu_to_be32(encode_readdir_bitmask_sz); 1605e75bc1c8SBenny Halevy *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 160634558513SBenny Halevy *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1607aa9c2669SDavid Quigley if (encode_readdir_bitmask_sz > 2) { 1608aa9c2669SDavid Quigley if (hdr->minorversion > 1) 1609aa9c2669SDavid Quigley attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 1610aa9c2669SDavid Quigley p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]); 1611aa9c2669SDavid Quigley } 1612cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1613aa9c2669SDavid Quigley 1614aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 161544109241SFred Isaman __func__, 1616eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1617cd93710eSChuck Lever verf[0], verf[1], 1618eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1619aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1620aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16211da177e4SLinus Torvalds } 16221da177e4SLinus Torvalds 1623cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16241da177e4SLinus Torvalds { 1625ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16261da177e4SLinus Torvalds } 16271da177e4SLinus Torvalds 1628cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16291da177e4SLinus Torvalds { 1630ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16316fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16321da177e4SLinus Torvalds } 16331da177e4SLinus Torvalds 1634cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16351da177e4SLinus Torvalds { 1636ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1637811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1638811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16391da177e4SLinus Torvalds } 16401da177e4SLinus Torvalds 1641bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1642bb4dae5eSChuck Lever struct compound_hdr *hdr) 16431da177e4SLinus Torvalds { 1644475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1645ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16461da177e4SLinus Torvalds } 16471da177e4SLinus Torvalds 1648cf8cdbe5SAndy Adamson static void 1649d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 165056ae19f3STrond Myklebust { 1651ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 165256ae19f3STrond Myklebust } 165356ae19f3STrond Myklebust 16549f06c719SChuck Lever static void 1655d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 165623ec6965SJ. Bruce Fields { 16578687b63aSAl Viro __be32 *p; 165823ec6965SJ. Bruce Fields 1659ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1660ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 166113c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1662e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 166334558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 166413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 166534558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 166623ec6965SJ. Bruce Fields xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 166723ec6965SJ. Bruce Fields } 166823ec6965SJ. Bruce Fields 1669cf8cdbe5SAndy Adamson static void 1670d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16711da177e4SLinus Torvalds { 1672ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16731da177e4SLinus Torvalds } 16741da177e4SLinus Torvalds 1675cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16761da177e4SLinus Torvalds { 1677ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1678ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1679aa9c2669SDavid Quigley encode_attrs(xdr, arg->iap, arg->label, server); 16801da177e4SLinus Torvalds } 16811da177e4SLinus Torvalds 1682cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16831da177e4SLinus Torvalds { 16848687b63aSAl Viro __be32 *p; 16851da177e4SLinus Torvalds 168670019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1687cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16881da177e4SLinus Torvalds 16891da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 169013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 169134558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16921da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16931da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 169413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 169534558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_cb_ident); 16961da177e4SLinus Torvalds } 16971da177e4SLinus Torvalds 1698bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16991da177e4SLinus Torvalds { 1700475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1701475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1702ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1703cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17041da177e4SLinus Torvalds } 17051da177e4SLinus Torvalds 1706cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 17071da177e4SLinus Torvalds { 17088687b63aSAl Viro __be32 *p; 17091da177e4SLinus Torvalds 1710ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17119b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17121da177e4SLinus Torvalds 171313c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1714b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1715e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 171634558513SBenny Halevy *p = cpu_to_be32(args->count); 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17191da177e4SLinus Torvalds } 17201da177e4SLinus Torvalds 1721cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17221da177e4SLinus Torvalds { 1723ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1724ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17251da177e4SLinus Torvalds } 17269b7b9fccSAndy Adamson 17275a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17285a5ea0d4SBryan Schumaker { 1729ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17306fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17315a5ea0d4SBryan Schumaker } 17325a5ea0d4SBryan Schumaker 173399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17349b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17357c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 17367c44f1aeSWeston Andros Adamson struct nfs4_session *session, 17377c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17387c44f1aeSWeston Andros Adamson { 17397c44f1aeSWeston Andros Adamson __be32 *p; 17407c44f1aeSWeston Andros Adamson 17417c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17427c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 17437c44f1aeSWeston Andros Adamson encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 17447c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 17457c44f1aeSWeston Andros Adamson *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH); 17467c44f1aeSWeston Andros Adamson *p = 0; /* use_conn_in_rdma_mode = False */ 17477c44f1aeSWeston Andros Adamson } 17487c44f1aeSWeston Andros Adamson 17492031cd1aSWeston Andros Adamson static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 17502031cd1aSWeston Andros Adamson { 17512031cd1aSWeston Andros Adamson unsigned int i; 17522031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17532031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17542031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17552031cd1aSWeston Andros Adamson } 17562031cd1aSWeston Andros Adamson 175799fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 175899fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 175999fe60d0SBenny Halevy struct compound_hdr *hdr) 176099fe60d0SBenny Halevy { 176199fe60d0SBenny Halevy __be32 *p; 1762d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1763db8ac8baSWeston Andros Adamson int len = 0; 176499fe60d0SBenny Halevy 176570019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1766cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 176799fe60d0SBenny Halevy 176899fe60d0SBenny Halevy encode_string(xdr, args->id_len, args->id); 176999fe60d0SBenny Halevy 17702031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17712031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17722031cd1aSWeston Andros Adamson 17732031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17742031cd1aSWeston Andros Adamson case SP4_NONE: 17752031cd1aSWeston Andros Adamson break; 17762031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17772031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 17782031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 17792031cd1aSWeston Andros Adamson break; 17802031cd1aSWeston Andros Adamson default: 17812031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 17822031cd1aSWeston Andros Adamson break; 17832031cd1aSWeston Andros Adamson } 1784db8ac8baSWeston Andros Adamson 1785db8ac8baSWeston Andros Adamson if (send_implementation_id && 1786db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1787db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1788d751f748SJim Rees <= sizeof(impl_name) + 1) 1789db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1790db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1791db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1792db8ac8baSWeston Andros Adamson 1793db8ac8baSWeston Andros Adamson if (len > 0) { 17942031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1795db8ac8baSWeston Andros Adamson 1796db8ac8baSWeston Andros Adamson encode_string(xdr, 1797db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1798db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1799db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1800db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1801db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1802db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1803db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1804db8ac8baSWeston Andros Adamson } else 18052031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 180699fe60d0SBenny Halevy } 1807fc931582SAndy Adamson 1808fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1809fc931582SAndy Adamson struct nfs41_create_session_args *args, 1810fc931582SAndy Adamson struct compound_hdr *hdr) 1811fc931582SAndy Adamson { 1812fc931582SAndy Adamson __be32 *p; 1813fc931582SAndy Adamson char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1814fc931582SAndy Adamson uint32_t len; 1815fc931582SAndy Adamson struct nfs_client *clp = args->client; 1816f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18178e0d46e1SMike Sager u32 max_resp_sz_cached; 18188e0d46e1SMike Sager 18198e0d46e1SMike Sager /* 18208e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18218e0d46e1SMike Sager * 2 is the verifier. 18228e0d46e1SMike Sager */ 18238e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 18248e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1825fc931582SAndy Adamson 1826fc931582SAndy Adamson len = scnprintf(machine_name, sizeof(machine_name), "%s", 1827fc931582SAndy Adamson clp->cl_ipaddr); 182842edd698SBenny Halevy 1829475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 1830475d4ba0STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12); 1831114f64b5SAndy Adamson p = xdr_encode_hyper(p, clp->cl_clientid); 1832e75bc1c8SBenny Halevy *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1833e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1834fc931582SAndy Adamson 1835fc931582SAndy Adamson /* Fore Channel */ 1836c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1837e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1838e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18398e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1840e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1841e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1842e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1843fc931582SAndy Adamson 1844fc931582SAndy Adamson /* Back Channel */ 1845c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1846e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1847e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1848e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1849e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1850e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1851e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1852fc931582SAndy Adamson 1853e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1854e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1856fc931582SAndy Adamson 1857fc931582SAndy Adamson /* authsys_parms rfc1831 */ 185817f26b12STrond Myklebust *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */ 1859811652bdSBenny Halevy p = xdr_encode_opaque(p, machine_name, len); 1860e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1861e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 186234558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1863fc931582SAndy Adamson } 18640f3e66c6SAndy Adamson 18650f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 18660f3e66c6SAndy Adamson struct nfs4_session *session, 18670f3e66c6SAndy Adamson struct compound_hdr *hdr) 18680f3e66c6SAndy Adamson { 1869475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1870475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18710f3e66c6SAndy Adamson } 187218019753SRicardo Labiaga 187366245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 187466245539STrond Myklebust uint64_t clientid, 187566245539STrond Myklebust struct compound_hdr *hdr) 187666245539STrond Myklebust { 187766245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 187866245539STrond Myklebust encode_uint64(xdr, clientid); 187966245539STrond Myklebust } 188066245539STrond Myklebust 188118019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 188218019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 188318019753SRicardo Labiaga struct compound_hdr *hdr) 188418019753SRicardo Labiaga { 1885475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1886475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 188718019753SRicardo Labiaga } 188899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 188999fe60d0SBenny Halevy 18909b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18919b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18929b7b9fccSAndy Adamson struct compound_hdr *hdr) 18939b7b9fccSAndy Adamson { 18949b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18952b2fa717STrond Myklebust struct nfs4_session *session; 1896fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 18972b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1898fc01cea9SAndy Adamson __be32 *p; 18999b7b9fccSAndy Adamson 19002b2fa717STrond Myklebust tp = slot->table; 19012b2fa717STrond Myklebust session = tp->session; 19023bd2384aSChuck Lever if (!session) 19033bd2384aSChuck Lever return; 1904fc01cea9SAndy Adamson 1905475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1906fc01cea9SAndy Adamson 1907fc01cea9SAndy Adamson /* 1908fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1909fc01cea9SAndy Adamson */ 1910fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1911fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1912fc01cea9SAndy Adamson __func__, 1913fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1914fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1915fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1916fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19172b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1918fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1919475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 192093f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1921e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19222b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1923e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 192434558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19259b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19269b7b9fccSAndy Adamson } 19279b7b9fccSAndy Adamson 1928b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1929b1f69b75SAndy Adamson static void 19307f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr, 19317f11d8d3SAndy Adamson const struct nfs4_getdevicelist_args *args, 19327f11d8d3SAndy Adamson struct compound_hdr *hdr) 19337f11d8d3SAndy Adamson { 19347f11d8d3SAndy Adamson __be32 *p; 19357f11d8d3SAndy Adamson nfs4_verifier dummy = { 19367f11d8d3SAndy Adamson .data = "dummmmmy", 19377f11d8d3SAndy Adamson }; 19387f11d8d3SAndy Adamson 1939475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr); 1940475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 19417f11d8d3SAndy Adamson *p++ = cpu_to_be32(args->layoutclass); 19427f11d8d3SAndy Adamson *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 19437f11d8d3SAndy Adamson xdr_encode_hyper(p, 0ULL); /* cookie */ 19447f11d8d3SAndy Adamson encode_nfs4_verifier(xdr, &dummy); 19457f11d8d3SAndy Adamson } 19467f11d8d3SAndy Adamson 19477f11d8d3SAndy Adamson static void 1948b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1949b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1950b1f69b75SAndy Adamson struct compound_hdr *hdr) 1951b1f69b75SAndy Adamson { 1952b1f69b75SAndy Adamson __be32 *p; 1953b1f69b75SAndy Adamson 1954475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 1955475d4ba0STrond Myklebust p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE); 1956b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1957b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1958b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1959f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 1960b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1961b1f69b75SAndy Adamson } 1962b1f69b75SAndy Adamson 1963b1f69b75SAndy Adamson static void 1964b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1965b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1966b1f69b75SAndy Adamson struct compound_hdr *hdr) 1967b1f69b75SAndy Adamson { 1968b1f69b75SAndy Adamson __be32 *p; 1969b1f69b75SAndy Adamson 1970475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1971475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1972b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1973b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1974b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1975b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1976b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1977b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1978ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1979475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1980b1f69b75SAndy Adamson 1981b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1982b1f69b75SAndy Adamson __func__, 1983b1f69b75SAndy Adamson args->type, 1984b1f69b75SAndy Adamson args->range.iomode, 1985b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1986b1f69b75SAndy Adamson (unsigned long)args->range.length, 1987b1f69b75SAndy Adamson args->maxcount); 1988b1f69b75SAndy Adamson } 1989863a3c6cSAndy Adamson 1990863a3c6cSAndy Adamson static int 1991863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1992ac7db726SBenny Halevy struct inode *inode, 1993863a3c6cSAndy Adamson const struct nfs4_layoutcommit_args *args, 1994863a3c6cSAndy Adamson struct compound_hdr *hdr) 1995863a3c6cSAndy Adamson { 1996863a3c6cSAndy Adamson __be32 *p; 1997863a3c6cSAndy Adamson 1998863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1999863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 2000863a3c6cSAndy Adamson 2001475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 2002475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 2003863a3c6cSAndy Adamson /* Only whole file layouts */ 2004863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 20053557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 2006ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 2007ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2008ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 2009863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 2010863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 2011863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2012863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2013ac7db726SBenny Halevy 2014ac7db726SBenny Halevy if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 2015ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 2016ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 2017475d4ba0STrond Myklebust else 2018475d4ba0STrond Myklebust encode_uint32(xdr, 0); /* no layout-type payload */ 2019863a3c6cSAndy Adamson 2020863a3c6cSAndy Adamson return 0; 2021863a3c6cSAndy Adamson } 2022cbe82603SBenny Halevy 2023cbe82603SBenny Halevy static void 2024cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2025cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2026cbe82603SBenny Halevy struct compound_hdr *hdr) 2027cbe82603SBenny Halevy { 2028cbe82603SBenny Halevy __be32 *p; 2029cbe82603SBenny Halevy 2030475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2031475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2032cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2033cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 2034cbe82603SBenny Halevy *p++ = cpu_to_be32(IOMODE_ANY); 2035cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2036ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 2037cbe82603SBenny Halevy p = xdr_encode_hyper(p, 0); 2038cbe82603SBenny Halevy p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 2039cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2040ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2041cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 204204a55549SAndy Adamson if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 204304a55549SAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 204404a55549SAndy Adamson NFS_I(args->inode)->layout, xdr, args); 2045475d4ba0STrond Myklebust } else 2046475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2047cbe82603SBenny Halevy } 2048fca78d6dSBryan Schumaker 2049fca78d6dSBryan Schumaker static int 2050fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2051fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2052fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2053fca78d6dSBryan Schumaker { 2054475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2055475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2056fca78d6dSBryan Schumaker return 0; 2057fca78d6dSBryan Schumaker } 20587d974794SBryan Schumaker 20597d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 20607d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 20617d974794SBryan Schumaker struct compound_hdr *hdr) 20627d974794SBryan Schumaker { 2063475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2064475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2065ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20667d974794SBryan Schumaker } 20679aeda35fSBryan Schumaker 20689aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 20699aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 20709aeda35fSBryan Schumaker struct compound_hdr *hdr) 20719aeda35fSBryan Schumaker { 2072ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20737c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20749aeda35fSBryan Schumaker } 2075b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2076b1f69b75SAndy Adamson 20771da177e4SLinus Torvalds /* 20781da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20791da177e4SLinus Torvalds */ 20801da177e4SLinus Torvalds 208166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 208266cc0429SBenny Halevy { 208366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 20843bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 20853bd2384aSChuck Lever if (session) 20863bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 208766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 208866cc0429SBenny Halevy return 0; 208966cc0429SBenny Halevy } 209066cc0429SBenny Halevy 20911da177e4SLinus Torvalds /* 20921da177e4SLinus Torvalds * Encode an ACCESS request 20931da177e4SLinus Torvalds */ 20949f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 20959f06c719SChuck Lever const struct nfs4_accessargs *args) 20961da177e4SLinus Torvalds { 20971da177e4SLinus Torvalds struct compound_hdr hdr = { 209866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20991da177e4SLinus Torvalds }; 21001da177e4SLinus Torvalds 21019f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21029f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21039f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21049f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21059f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2106d017931cSAndy Adamson encode_nops(&hdr); 21071da177e4SLinus Torvalds } 21081da177e4SLinus Torvalds 21091da177e4SLinus Torvalds /* 21101da177e4SLinus Torvalds * Encode LOOKUP request 21111da177e4SLinus Torvalds */ 21129f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 21139f06c719SChuck Lever const struct nfs4_lookup_arg *args) 21141da177e4SLinus Torvalds { 21151da177e4SLinus Torvalds struct compound_hdr hdr = { 211666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21171da177e4SLinus Torvalds }; 21181da177e4SLinus Torvalds 21199f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21209f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21219f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21229f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21239f06c719SChuck Lever encode_getfh(xdr, &hdr); 21249f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2125d017931cSAndy Adamson encode_nops(&hdr); 21261da177e4SLinus Torvalds } 21271da177e4SLinus Torvalds 21281da177e4SLinus Torvalds /* 21291da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21301da177e4SLinus Torvalds */ 21319f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21329f06c719SChuck Lever struct xdr_stream *xdr, 21339f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 21341da177e4SLinus Torvalds { 21351da177e4SLinus Torvalds struct compound_hdr hdr = { 213666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21371da177e4SLinus Torvalds }; 21381da177e4SLinus Torvalds 21399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21419f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21429f06c719SChuck Lever encode_getfh(xdr, &hdr); 21439f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2144d017931cSAndy Adamson encode_nops(&hdr); 21451da177e4SLinus Torvalds } 21461da177e4SLinus Torvalds 21471da177e4SLinus Torvalds /* 21481da177e4SLinus Torvalds * Encode REMOVE request 21491da177e4SLinus Torvalds */ 21509f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 21519f06c719SChuck Lever const struct nfs_removeargs *args) 21521da177e4SLinus Torvalds { 21531da177e4SLinus Torvalds struct compound_hdr hdr = { 215466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21551da177e4SLinus Torvalds }; 21561da177e4SLinus Torvalds 21579f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21589f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21599f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21609f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2161d017931cSAndy Adamson encode_nops(&hdr); 21621da177e4SLinus Torvalds } 21631da177e4SLinus Torvalds 21641da177e4SLinus Torvalds /* 21651da177e4SLinus Torvalds * Encode RENAME request 21661da177e4SLinus Torvalds */ 21679f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 21689f06c719SChuck Lever const struct nfs_renameargs *args) 21691da177e4SLinus Torvalds { 21701da177e4SLinus Torvalds struct compound_hdr hdr = { 217166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21721da177e4SLinus Torvalds }; 21731da177e4SLinus Torvalds 21749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21769f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21779f06c719SChuck Lever encode_savefh(xdr, &hdr); 21789f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21799f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2180d017931cSAndy Adamson encode_nops(&hdr); 21811da177e4SLinus Torvalds } 21821da177e4SLinus Torvalds 21831da177e4SLinus Torvalds /* 21841da177e4SLinus Torvalds * Encode LINK request 21851da177e4SLinus Torvalds */ 21869f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 21879f06c719SChuck Lever const struct nfs4_link_arg *args) 21881da177e4SLinus Torvalds { 21891da177e4SLinus Torvalds struct compound_hdr hdr = { 219066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21911da177e4SLinus Torvalds }; 21921da177e4SLinus Torvalds 21939f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21949f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21959f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21969f06c719SChuck Lever encode_savefh(xdr, &hdr); 21979f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21989f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 21999f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22009f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2201d017931cSAndy Adamson encode_nops(&hdr); 22021da177e4SLinus Torvalds } 22031da177e4SLinus Torvalds 22041da177e4SLinus Torvalds /* 22051da177e4SLinus Torvalds * Encode CREATE request 22061da177e4SLinus Torvalds */ 22079f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 22089f06c719SChuck Lever const struct nfs4_create_arg *args) 22091da177e4SLinus Torvalds { 22101da177e4SLinus Torvalds struct compound_hdr hdr = { 221166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22121da177e4SLinus Torvalds }; 22131da177e4SLinus Torvalds 22149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22169f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22179f06c719SChuck Lever encode_create(xdr, args, &hdr); 22189f06c719SChuck Lever encode_getfh(xdr, &hdr); 22199f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2220d017931cSAndy Adamson encode_nops(&hdr); 22211da177e4SLinus Torvalds } 22221da177e4SLinus Torvalds 22231da177e4SLinus Torvalds /* 22241da177e4SLinus Torvalds * Encode SYMLINK request 22251da177e4SLinus Torvalds */ 22269f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 22279f06c719SChuck Lever const struct nfs4_create_arg *args) 22281da177e4SLinus Torvalds { 22299f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22301da177e4SLinus Torvalds } 22311da177e4SLinus Torvalds 22321da177e4SLinus Torvalds /* 22331da177e4SLinus Torvalds * Encode GETATTR request 22341da177e4SLinus Torvalds */ 22359f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 22369f06c719SChuck Lever const struct nfs4_getattr_arg *args) 22371da177e4SLinus Torvalds { 22381da177e4SLinus Torvalds struct compound_hdr hdr = { 223966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22401da177e4SLinus Torvalds }; 22411da177e4SLinus Torvalds 22429f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22439f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22449f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22459f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2246d017931cSAndy Adamson encode_nops(&hdr); 22471da177e4SLinus Torvalds } 22481da177e4SLinus Torvalds 22491da177e4SLinus Torvalds /* 22501da177e4SLinus Torvalds * Encode a CLOSE request 22511da177e4SLinus Torvalds */ 22529f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 22539f06c719SChuck Lever struct nfs_closeargs *args) 22541da177e4SLinus Torvalds { 22551da177e4SLinus Torvalds struct compound_hdr hdr = { 225666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22571da177e4SLinus Torvalds }; 22581da177e4SLinus Torvalds 22599f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22609f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22619f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22629f06c719SChuck Lever encode_close(xdr, args, &hdr); 22639f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2264d017931cSAndy Adamson encode_nops(&hdr); 22651da177e4SLinus Torvalds } 22661da177e4SLinus Torvalds 22671da177e4SLinus Torvalds /* 22681da177e4SLinus Torvalds * Encode an OPEN request 22691da177e4SLinus Torvalds */ 22709f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 22719f06c719SChuck Lever struct nfs_openargs *args) 22721da177e4SLinus Torvalds { 22731da177e4SLinus Torvalds struct compound_hdr hdr = { 227466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22751da177e4SLinus Torvalds }; 22761da177e4SLinus Torvalds 22779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22789f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22799f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22809f06c719SChuck Lever encode_open(xdr, args, &hdr); 22819f06c719SChuck Lever encode_getfh(xdr, &hdr); 2282ae2bb032SWeston Andros Adamson if (args->access) 22836168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 22841549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2285d017931cSAndy Adamson encode_nops(&hdr); 22861da177e4SLinus Torvalds } 22871da177e4SLinus Torvalds 22881da177e4SLinus Torvalds /* 22891da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 22901da177e4SLinus Torvalds */ 22919f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22929f06c719SChuck Lever struct xdr_stream *xdr, 22939f06c719SChuck Lever struct nfs_open_confirmargs *args) 22941da177e4SLinus Torvalds { 22951da177e4SLinus Torvalds struct compound_hdr hdr = { 2296d017931cSAndy Adamson .nops = 0, 22971da177e4SLinus Torvalds }; 22981da177e4SLinus Torvalds 22999f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23009f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23019f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2302d017931cSAndy Adamson encode_nops(&hdr); 23031da177e4SLinus Torvalds } 23041da177e4SLinus Torvalds 23051da177e4SLinus Torvalds /* 23061da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23071da177e4SLinus Torvalds */ 23089f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23099f06c719SChuck Lever struct xdr_stream *xdr, 23109f06c719SChuck Lever struct nfs_openargs *args) 23111da177e4SLinus Torvalds { 23121da177e4SLinus Torvalds struct compound_hdr hdr = { 231366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23141da177e4SLinus Torvalds }; 23151da177e4SLinus Torvalds 23169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23189f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23199f06c719SChuck Lever encode_open(xdr, args, &hdr); 2320ae2bb032SWeston Andros Adamson if (args->access) 23216168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2322e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2323d017931cSAndy Adamson encode_nops(&hdr); 23241da177e4SLinus Torvalds } 23251da177e4SLinus Torvalds 23261da177e4SLinus Torvalds /* 23271da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23281da177e4SLinus Torvalds */ 23299f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23309f06c719SChuck Lever struct xdr_stream *xdr, 23319f06c719SChuck Lever struct nfs_closeargs *args) 23321da177e4SLinus Torvalds { 23331da177e4SLinus Torvalds struct compound_hdr hdr = { 233466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23351da177e4SLinus Torvalds }; 23361da177e4SLinus Torvalds 23379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23389f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23399f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23409f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 23419f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2342d017931cSAndy Adamson encode_nops(&hdr); 23431da177e4SLinus Torvalds } 23441da177e4SLinus Torvalds 23451da177e4SLinus Torvalds /* 23461da177e4SLinus Torvalds * Encode a LOCK request 23471da177e4SLinus Torvalds */ 23489f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 23499f06c719SChuck Lever struct nfs_lock_args *args) 23501da177e4SLinus Torvalds { 23511da177e4SLinus Torvalds struct compound_hdr hdr = { 235266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23531da177e4SLinus Torvalds }; 23541da177e4SLinus Torvalds 23559f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23569f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23579f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23589f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2359d017931cSAndy Adamson encode_nops(&hdr); 23601da177e4SLinus Torvalds } 23611da177e4SLinus Torvalds 23621da177e4SLinus Torvalds /* 23631da177e4SLinus Torvalds * Encode a LOCKT request 23641da177e4SLinus Torvalds */ 23659f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 23669f06c719SChuck Lever struct nfs_lockt_args *args) 23671da177e4SLinus Torvalds { 23681da177e4SLinus Torvalds struct compound_hdr hdr = { 236966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23701da177e4SLinus Torvalds }; 23711da177e4SLinus Torvalds 23729f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23739f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23749f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23759f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2376d017931cSAndy Adamson encode_nops(&hdr); 23771da177e4SLinus Torvalds } 23781da177e4SLinus Torvalds 23791da177e4SLinus Torvalds /* 23801da177e4SLinus Torvalds * Encode a LOCKU request 23811da177e4SLinus Torvalds */ 23829f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 23839f06c719SChuck Lever struct nfs_locku_args *args) 23841da177e4SLinus Torvalds { 23851da177e4SLinus Torvalds struct compound_hdr hdr = { 238666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23871da177e4SLinus Torvalds }; 23881da177e4SLinus Torvalds 23899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23919f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23929f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2393d017931cSAndy Adamson encode_nops(&hdr); 23941da177e4SLinus Torvalds } 23951da177e4SLinus Torvalds 23969f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 23979f06c719SChuck Lever struct xdr_stream *xdr, 23989f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2399d3c7b7ccSTrond Myklebust { 2400d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2401d3c7b7ccSTrond Myklebust .minorversion = 0, 2402d3c7b7ccSTrond Myklebust }; 2403d3c7b7ccSTrond Myklebust 24049f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24059f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2406d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2407d3c7b7ccSTrond Myklebust } 2408d3c7b7ccSTrond Myklebust 24091da177e4SLinus Torvalds /* 24101da177e4SLinus Torvalds * Encode a READLINK request 24111da177e4SLinus Torvalds */ 24129f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 24139f06c719SChuck Lever const struct nfs4_readlink *args) 24141da177e4SLinus Torvalds { 24151da177e4SLinus Torvalds struct compound_hdr hdr = { 241666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24171da177e4SLinus Torvalds }; 24181da177e4SLinus Torvalds 24199f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24209f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24219f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24229f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2423e3a535e1STrond Myklebust 242428f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2425e3a535e1STrond Myklebust args->pgbase, args->pglen); 2426d017931cSAndy Adamson encode_nops(&hdr); 24271da177e4SLinus Torvalds } 24281da177e4SLinus Torvalds 24291da177e4SLinus Torvalds /* 24301da177e4SLinus Torvalds * Encode a READDIR request 24311da177e4SLinus Torvalds */ 24329f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 24339f06c719SChuck Lever const struct nfs4_readdir_arg *args) 24341da177e4SLinus Torvalds { 24351da177e4SLinus Torvalds struct compound_hdr hdr = { 243666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24371da177e4SLinus Torvalds }; 24381da177e4SLinus Torvalds 24399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24419f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24429f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2443d6ac02dfSTrond Myklebust 244428f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2445d6ac02dfSTrond Myklebust args->pgbase, args->count); 2446d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 244728f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2448d6ac02dfSTrond Myklebust args->pgbase, args->count); 2449d017931cSAndy Adamson encode_nops(&hdr); 24501da177e4SLinus Torvalds } 24511da177e4SLinus Torvalds 24521da177e4SLinus Torvalds /* 24531da177e4SLinus Torvalds * Encode a READ request 24541da177e4SLinus Torvalds */ 24559f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 24569f06c719SChuck Lever struct nfs_readargs *args) 24571da177e4SLinus Torvalds { 24581da177e4SLinus Torvalds struct compound_hdr hdr = { 245966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24601da177e4SLinus Torvalds }; 24611da177e4SLinus Torvalds 24629f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24639f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24649f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24659f06c719SChuck Lever encode_read(xdr, args, &hdr); 24661da177e4SLinus Torvalds 246728f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 24681da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 24694f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2470d017931cSAndy Adamson encode_nops(&hdr); 24711da177e4SLinus Torvalds } 24721da177e4SLinus Torvalds 24731da177e4SLinus Torvalds /* 24741da177e4SLinus Torvalds * Encode an SETATTR request 24751da177e4SLinus Torvalds */ 24769f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 24779f06c719SChuck Lever struct nfs_setattrargs *args) 24781da177e4SLinus Torvalds { 24791da177e4SLinus Torvalds struct compound_hdr hdr = { 248066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24811da177e4SLinus Torvalds }; 24821da177e4SLinus Torvalds 24839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24849f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24859f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24869f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 24879f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2488d017931cSAndy Adamson encode_nops(&hdr); 24891da177e4SLinus Torvalds } 24901da177e4SLinus Torvalds 24911da177e4SLinus Torvalds /* 2492029d105eSJ. Bruce Fields * Encode a GETACL request 2493029d105eSJ. Bruce Fields */ 24949f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2495029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2496029d105eSJ. Bruce Fields { 2497029d105eSJ. Bruce Fields struct compound_hdr hdr = { 249866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2499029d105eSJ. Bruce Fields }; 250028f56694SBenny Halevy uint32_t replen; 2501029d105eSJ. Bruce Fields 25029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25049f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2505bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 25069f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2507cf8cdbe5SAndy Adamson 250828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2509029d105eSJ. Bruce Fields args->acl_pages, args->acl_pgbase, args->acl_len); 2510bf118a34SAndy Adamson 2511d017931cSAndy Adamson encode_nops(&hdr); 2512029d105eSJ. Bruce Fields } 2513029d105eSJ. Bruce Fields 2514029d105eSJ. Bruce Fields /* 25151da177e4SLinus Torvalds * Encode a WRITE request 25161da177e4SLinus Torvalds */ 25179f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 25189f06c719SChuck Lever struct nfs_writeargs *args) 25191da177e4SLinus Torvalds { 25201da177e4SLinus Torvalds struct compound_hdr hdr = { 252166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25221da177e4SLinus Torvalds }; 25231da177e4SLinus Torvalds 25249f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25259f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25269f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25279f06c719SChuck Lever encode_write(xdr, args, &hdr); 25284f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25297ffd1064SFred Isaman if (args->bitmask) 25309f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2531d017931cSAndy Adamson encode_nops(&hdr); 25321da177e4SLinus Torvalds } 25331da177e4SLinus Torvalds 25341da177e4SLinus Torvalds /* 25351da177e4SLinus Torvalds * a COMMIT request 25361da177e4SLinus Torvalds */ 25379f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 25380b7c0153SFred Isaman struct nfs_commitargs *args) 25391da177e4SLinus Torvalds { 25401da177e4SLinus Torvalds struct compound_hdr hdr = { 254166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25421da177e4SLinus Torvalds }; 25431da177e4SLinus Torvalds 25449f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25459f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25469f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25479f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2548d017931cSAndy Adamson encode_nops(&hdr); 25491da177e4SLinus Torvalds } 25501da177e4SLinus Torvalds 25511da177e4SLinus Torvalds /* 25521da177e4SLinus Torvalds * FSINFO request 25531da177e4SLinus Torvalds */ 25549f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 25559f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 25561da177e4SLinus Torvalds { 25571da177e4SLinus Torvalds struct compound_hdr hdr = { 255866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25591da177e4SLinus Torvalds }; 25601da177e4SLinus Torvalds 25619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25649f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2565d017931cSAndy Adamson encode_nops(&hdr); 25661da177e4SLinus Torvalds } 25671da177e4SLinus Torvalds 25681da177e4SLinus Torvalds /* 25691da177e4SLinus Torvalds * a PATHCONF request 25701da177e4SLinus Torvalds */ 25719f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 25729f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 25731da177e4SLinus Torvalds { 25741da177e4SLinus Torvalds struct compound_hdr hdr = { 257566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25761da177e4SLinus Torvalds }; 25771da177e4SLinus Torvalds 25789f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25799f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25809f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25819f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2582d017931cSAndy Adamson &hdr); 2583d017931cSAndy Adamson encode_nops(&hdr); 25841da177e4SLinus Torvalds } 25851da177e4SLinus Torvalds 25861da177e4SLinus Torvalds /* 25871da177e4SLinus Torvalds * a STATFS request 25881da177e4SLinus Torvalds */ 25899f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 25909f06c719SChuck Lever const struct nfs4_statfs_arg *args) 25911da177e4SLinus Torvalds { 25921da177e4SLinus Torvalds struct compound_hdr hdr = { 259366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25941da177e4SLinus Torvalds }; 25951da177e4SLinus Torvalds 25969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25999f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2600d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2601d017931cSAndy Adamson encode_nops(&hdr); 26021da177e4SLinus Torvalds } 26031da177e4SLinus Torvalds 26041da177e4SLinus Torvalds /* 26051da177e4SLinus Torvalds * GETATTR_BITMAP request 26061da177e4SLinus Torvalds */ 26079f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26089f06c719SChuck Lever struct xdr_stream *xdr, 260943652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 26101da177e4SLinus Torvalds { 26111da177e4SLinus Torvalds struct compound_hdr hdr = { 261266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26131da177e4SLinus Torvalds }; 26141da177e4SLinus Torvalds 26159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26169f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26179f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26189f06c719SChuck Lever encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2619264e6351SChuck Lever FATTR4_WORD0_FH_EXPIRE_TYPE| 26201da177e4SLinus Torvalds FATTR4_WORD0_LINK_SUPPORT| 26211da177e4SLinus Torvalds FATTR4_WORD0_SYMLINK_SUPPORT| 2622d017931cSAndy Adamson FATTR4_WORD0_ACLSUPPORT, &hdr); 2623d017931cSAndy Adamson encode_nops(&hdr); 26241da177e4SLinus Torvalds } 26251da177e4SLinus Torvalds 26261da177e4SLinus Torvalds /* 26271da177e4SLinus Torvalds * a RENEW request 26281da177e4SLinus Torvalds */ 26299f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 26309f06c719SChuck Lever struct nfs_client *clp) 26311da177e4SLinus Torvalds { 26321da177e4SLinus Torvalds struct compound_hdr hdr = { 2633d017931cSAndy Adamson .nops = 0, 26341da177e4SLinus Torvalds }; 26351da177e4SLinus Torvalds 26369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2637bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2638d017931cSAndy Adamson encode_nops(&hdr); 26391da177e4SLinus Torvalds } 26401da177e4SLinus Torvalds 26411da177e4SLinus Torvalds /* 26421da177e4SLinus Torvalds * a SETCLIENTID request 26431da177e4SLinus Torvalds */ 26449f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 26459f06c719SChuck Lever struct xdr_stream *xdr, 26469f06c719SChuck Lever struct nfs4_setclientid *sc) 26471da177e4SLinus Torvalds { 26481da177e4SLinus Torvalds struct compound_hdr hdr = { 2649d017931cSAndy Adamson .nops = 0, 26501da177e4SLinus Torvalds }; 26511da177e4SLinus Torvalds 26529f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26539f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2654d017931cSAndy Adamson encode_nops(&hdr); 26551da177e4SLinus Torvalds } 26561da177e4SLinus Torvalds 26571da177e4SLinus Torvalds /* 26581da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 26591da177e4SLinus Torvalds */ 26609f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 26619f06c719SChuck Lever struct xdr_stream *xdr, 26629f06c719SChuck Lever struct nfs4_setclientid_res *arg) 26631da177e4SLinus Torvalds { 26641da177e4SLinus Torvalds struct compound_hdr hdr = { 2665d017931cSAndy Adamson .nops = 0, 26661da177e4SLinus Torvalds }; 26671da177e4SLinus Torvalds 26689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26699f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2670d017931cSAndy Adamson encode_nops(&hdr); 26711da177e4SLinus Torvalds } 26721da177e4SLinus Torvalds 26731da177e4SLinus Torvalds /* 26741da177e4SLinus Torvalds * DELEGRETURN request 26751da177e4SLinus Torvalds */ 26769f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 26779f06c719SChuck Lever struct xdr_stream *xdr, 26789f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 26791da177e4SLinus Torvalds { 26801da177e4SLinus Torvalds struct compound_hdr hdr = { 268166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26821da177e4SLinus Torvalds }; 26831da177e4SLinus Torvalds 26849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26859f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26869f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26879f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2688e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2689d017931cSAndy Adamson encode_nops(&hdr); 26901da177e4SLinus Torvalds } 26911da177e4SLinus Torvalds 26921da177e4SLinus Torvalds /* 2693683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2694683b57b4STrond Myklebust */ 26959f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 26969f06c719SChuck Lever struct xdr_stream *xdr, 26979f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2698683b57b4STrond Myklebust { 2699683b57b4STrond Myklebust struct compound_hdr hdr = { 270066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2701683b57b4STrond Myklebust }; 270228f56694SBenny Halevy uint32_t replen; 2703683b57b4STrond Myklebust 27049f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27059f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2706b03d735bSChuck Lever if (args->migration) { 2707b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2708b03d735bSChuck Lever replen = hdr.replen; 2709b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2710b03d735bSChuck Lever if (args->renew) 2711b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2712b03d735bSChuck Lever } else { 27139f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 27149f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2715b03d735bSChuck Lever replen = hdr.replen; 27169f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2717b03d735bSChuck Lever } 2718cf8cdbe5SAndy Adamson 2719b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 272028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2721683b57b4STrond Myklebust 0, PAGE_SIZE); 2722d017931cSAndy Adamson encode_nops(&hdr); 2723683b57b4STrond Myklebust } 2724683b57b4STrond Myklebust 27255a5ea0d4SBryan Schumaker /* 27265a5ea0d4SBryan Schumaker * Encode SECINFO request 27275a5ea0d4SBryan Schumaker */ 27285a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 27295a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 27305a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 27315a5ea0d4SBryan Schumaker { 27325a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 27335a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27345a5ea0d4SBryan Schumaker }; 27355a5ea0d4SBryan Schumaker 27365a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 27375a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 27385a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 27395a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 27405a5ea0d4SBryan Schumaker encode_nops(&hdr); 27415a5ea0d4SBryan Schumaker } 27425a5ea0d4SBryan Schumaker 274344c99933SChuck Lever /* 274444c99933SChuck Lever * Encode FSID_PRESENT request 274544c99933SChuck Lever */ 274644c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 274744c99933SChuck Lever struct xdr_stream *xdr, 274844c99933SChuck Lever struct nfs4_fsid_present_arg *args) 274944c99933SChuck Lever { 275044c99933SChuck Lever struct compound_hdr hdr = { 275144c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 275244c99933SChuck Lever }; 275344c99933SChuck Lever 275444c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 275544c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 275644c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 275744c99933SChuck Lever encode_getfh(xdr, &hdr); 275844c99933SChuck Lever if (args->renew) 275944c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 276044c99933SChuck Lever encode_nops(&hdr); 276144c99933SChuck Lever } 276244c99933SChuck Lever 276399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 276499fe60d0SBenny Halevy /* 27657c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 27667c44f1aeSWeston Andros Adamson */ 27677c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 27687c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 27697c44f1aeSWeston Andros Adamson struct nfs_client *clp) 27707c44f1aeSWeston Andros Adamson { 27717c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 27727c44f1aeSWeston Andros Adamson .minorversion = clp->cl_mvops->minor_version, 27737c44f1aeSWeston Andros Adamson }; 27747c44f1aeSWeston Andros Adamson 27757c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 27767c44f1aeSWeston Andros Adamson encode_bind_conn_to_session(xdr, clp->cl_session, &hdr); 27777c44f1aeSWeston Andros Adamson encode_nops(&hdr); 27787c44f1aeSWeston Andros Adamson } 27797c44f1aeSWeston Andros Adamson 27807c44f1aeSWeston Andros Adamson /* 278199fe60d0SBenny Halevy * EXCHANGE_ID request 278299fe60d0SBenny Halevy */ 27839f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 27849f06c719SChuck Lever struct xdr_stream *xdr, 278599fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 278699fe60d0SBenny Halevy { 278799fe60d0SBenny Halevy struct compound_hdr hdr = { 2788a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 278999fe60d0SBenny Halevy }; 279099fe60d0SBenny Halevy 27919f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27929f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 279399fe60d0SBenny Halevy encode_nops(&hdr); 279499fe60d0SBenny Halevy } 27952050f0ccSAndy Adamson 27962050f0ccSAndy Adamson /* 2797fc931582SAndy Adamson * a CREATE_SESSION request 2798fc931582SAndy Adamson */ 27999f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28009f06c719SChuck Lever struct xdr_stream *xdr, 2801fc931582SAndy Adamson struct nfs41_create_session_args *args) 2802fc931582SAndy Adamson { 2803fc931582SAndy Adamson struct compound_hdr hdr = { 2804a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2805fc931582SAndy Adamson }; 2806fc931582SAndy Adamson 28079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28089f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2809fc931582SAndy Adamson encode_nops(&hdr); 2810fc931582SAndy Adamson } 2811fc931582SAndy Adamson 2812fc931582SAndy Adamson /* 28130f3e66c6SAndy Adamson * a DESTROY_SESSION request 28140f3e66c6SAndy Adamson */ 28159f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 28169f06c719SChuck Lever struct xdr_stream *xdr, 28170f3e66c6SAndy Adamson struct nfs4_session *session) 28180f3e66c6SAndy Adamson { 28190f3e66c6SAndy Adamson struct compound_hdr hdr = { 2820a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 28210f3e66c6SAndy Adamson }; 28220f3e66c6SAndy Adamson 28239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28249f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 28250f3e66c6SAndy Adamson encode_nops(&hdr); 28260f3e66c6SAndy Adamson } 28270f3e66c6SAndy Adamson 28280f3e66c6SAndy Adamson /* 282966245539STrond Myklebust * a DESTROY_CLIENTID request 283066245539STrond Myklebust */ 283166245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 283266245539STrond Myklebust struct xdr_stream *xdr, 283366245539STrond Myklebust struct nfs_client *clp) 283466245539STrond Myklebust { 283566245539STrond Myklebust struct compound_hdr hdr = { 283666245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 283766245539STrond Myklebust }; 283866245539STrond Myklebust 283966245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 284066245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 284166245539STrond Myklebust encode_nops(&hdr); 284266245539STrond Myklebust } 284366245539STrond Myklebust 284466245539STrond Myklebust /* 2845fc01cea9SAndy Adamson * a SEQUENCE request 2846fc01cea9SAndy Adamson */ 28479f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2848fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2849fc01cea9SAndy Adamson { 2850fc01cea9SAndy Adamson struct compound_hdr hdr = { 2851fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2852fc01cea9SAndy Adamson }; 2853fc01cea9SAndy Adamson 28549f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28559f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2856fc01cea9SAndy Adamson encode_nops(&hdr); 2857fc01cea9SAndy Adamson } 2858fc01cea9SAndy Adamson 2859fc01cea9SAndy Adamson /* 28602050f0ccSAndy Adamson * a GET_LEASE_TIME request 28612050f0ccSAndy Adamson */ 28629f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 28639f06c719SChuck Lever struct xdr_stream *xdr, 28642050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 28652050f0ccSAndy Adamson { 28662050f0ccSAndy Adamson struct compound_hdr hdr = { 28672050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 28682050f0ccSAndy Adamson }; 2869dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 28702050f0ccSAndy Adamson 28719f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28729f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 28739f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 28749f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 28752050f0ccSAndy Adamson encode_nops(&hdr); 28762050f0ccSAndy Adamson } 287718019753SRicardo Labiaga 287818019753SRicardo Labiaga /* 287918019753SRicardo Labiaga * a RECLAIM_COMPLETE request 288018019753SRicardo Labiaga */ 28819f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 28829f06c719SChuck Lever struct xdr_stream *xdr, 288318019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 288418019753SRicardo Labiaga { 288518019753SRicardo Labiaga struct compound_hdr hdr = { 288618019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 288718019753SRicardo Labiaga }; 288818019753SRicardo Labiaga 28899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28919f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 289218019753SRicardo Labiaga encode_nops(&hdr); 289318019753SRicardo Labiaga } 289418019753SRicardo Labiaga 2895b1f69b75SAndy Adamson /* 28967f11d8d3SAndy Adamson * Encode GETDEVICELIST request 28977f11d8d3SAndy Adamson */ 28987f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req, 28997f11d8d3SAndy Adamson struct xdr_stream *xdr, 29007f11d8d3SAndy Adamson struct nfs4_getdevicelist_args *args) 29017f11d8d3SAndy Adamson { 29027f11d8d3SAndy Adamson struct compound_hdr hdr = { 29037f11d8d3SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29047f11d8d3SAndy Adamson }; 29057f11d8d3SAndy Adamson 29067f11d8d3SAndy Adamson encode_compound_hdr(xdr, req, &hdr); 29077f11d8d3SAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 29087f11d8d3SAndy Adamson encode_putfh(xdr, args->fh, &hdr); 29097f11d8d3SAndy Adamson encode_getdevicelist(xdr, args, &hdr); 29107f11d8d3SAndy Adamson encode_nops(&hdr); 29117f11d8d3SAndy Adamson } 29127f11d8d3SAndy Adamson 29137f11d8d3SAndy Adamson /* 2914b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2915b1f69b75SAndy Adamson */ 29169f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 29179f06c719SChuck Lever struct xdr_stream *xdr, 2918b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2919b1f69b75SAndy Adamson { 2920b1f69b75SAndy Adamson struct compound_hdr hdr = { 2921b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2922b1f69b75SAndy Adamson }; 2923b1f69b75SAndy Adamson 29249f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29259f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29269f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2927b1f69b75SAndy Adamson 2928b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2929b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2930b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2931b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2932b1f69b75SAndy Adamson args->pdev->pglen); 2933b1f69b75SAndy Adamson 2934b1f69b75SAndy Adamson encode_nops(&hdr); 2935b1f69b75SAndy Adamson } 2936b1f69b75SAndy Adamson 2937b1f69b75SAndy Adamson /* 2938b1f69b75SAndy Adamson * Encode LAYOUTGET request 2939b1f69b75SAndy Adamson */ 29409f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 29419f06c719SChuck Lever struct xdr_stream *xdr, 2942b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2943b1f69b75SAndy Adamson { 2944b1f69b75SAndy Adamson struct compound_hdr hdr = { 2945b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2946b1f69b75SAndy Adamson }; 2947b1f69b75SAndy Adamson 29489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29499f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29509f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 29519f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 295235124a09SWeston Andros Adamson 295335124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 295435124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 295535124a09SWeston Andros Adamson 2956b1f69b75SAndy Adamson encode_nops(&hdr); 2957b1f69b75SAndy Adamson } 2958863a3c6cSAndy Adamson 2959863a3c6cSAndy Adamson /* 2960863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2961863a3c6cSAndy Adamson */ 2962cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2963863a3c6cSAndy Adamson struct xdr_stream *xdr, 2964863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2965863a3c6cSAndy Adamson { 2966ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2967ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2968863a3c6cSAndy Adamson struct compound_hdr hdr = { 2969863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2970863a3c6cSAndy Adamson }; 2971863a3c6cSAndy Adamson 2972863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2973863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2974863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2975ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2976863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2977863a3c6cSAndy Adamson encode_nops(&hdr); 2978cbe82603SBenny Halevy } 2979cbe82603SBenny Halevy 2980cbe82603SBenny Halevy /* 2981cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2982cbe82603SBenny Halevy */ 2983cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2984cbe82603SBenny Halevy struct xdr_stream *xdr, 2985cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2986cbe82603SBenny Halevy { 2987cbe82603SBenny Halevy struct compound_hdr hdr = { 2988cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2989cbe82603SBenny Halevy }; 2990cbe82603SBenny Halevy 2991cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2992cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2993cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2994cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2995cbe82603SBenny Halevy encode_nops(&hdr); 2996863a3c6cSAndy Adamson } 2997fca78d6dSBryan Schumaker 2998fca78d6dSBryan Schumaker /* 2999fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 3000fca78d6dSBryan Schumaker */ 3001fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 3002fca78d6dSBryan Schumaker struct xdr_stream *xdr, 3003fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 3004fca78d6dSBryan Schumaker { 3005fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3006fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3007fca78d6dSBryan Schumaker }; 3008fca78d6dSBryan Schumaker 3009fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3010fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3011fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3012fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3013fca78d6dSBryan Schumaker encode_nops(&hdr); 3014fca78d6dSBryan Schumaker return 0; 3015fca78d6dSBryan Schumaker } 30167d974794SBryan Schumaker 30177d974794SBryan Schumaker /* 30187d974794SBryan Schumaker * Encode TEST_STATEID request 30197d974794SBryan Schumaker */ 30207d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 30217d974794SBryan Schumaker struct xdr_stream *xdr, 30227d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 30237d974794SBryan Schumaker { 30247d974794SBryan Schumaker struct compound_hdr hdr = { 30257d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30267d974794SBryan Schumaker }; 30277d974794SBryan Schumaker 30287d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30297d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30307d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 30317d974794SBryan Schumaker encode_nops(&hdr); 30327d974794SBryan Schumaker } 30339aeda35fSBryan Schumaker 30349aeda35fSBryan Schumaker /* 30359aeda35fSBryan Schumaker * Encode FREE_STATEID request 30369aeda35fSBryan Schumaker */ 30379aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 30389aeda35fSBryan Schumaker struct xdr_stream *xdr, 30399aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 30409aeda35fSBryan Schumaker { 30419aeda35fSBryan Schumaker struct compound_hdr hdr = { 30429aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30439aeda35fSBryan Schumaker }; 30449aeda35fSBryan Schumaker 30459aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30469aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30479aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 30489aeda35fSBryan Schumaker encode_nops(&hdr); 30499aeda35fSBryan Schumaker } 305099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 305199fe60d0SBenny Halevy 3052686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3053686841b3SBenny Halevy { 3054686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3055686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3056686841b3SBenny Halevy func, xdr->end - xdr->p); 3057686841b3SBenny Halevy } 30581da177e4SLinus Torvalds 3059683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 30601da177e4SLinus Torvalds { 30618687b63aSAl Viro __be32 *p; 30621da177e4SLinus Torvalds 3063c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3064c0eae66eSBenny Halevy if (unlikely(!p)) 3065c0eae66eSBenny Halevy goto out_overflow; 3066cccddf4fSBenny Halevy *len = be32_to_cpup(p); 3067c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 3068c0eae66eSBenny Halevy if (unlikely(!p)) 3069c0eae66eSBenny Halevy goto out_overflow; 30701da177e4SLinus Torvalds *string = (char *)p; 30711da177e4SLinus Torvalds return 0; 3072c0eae66eSBenny Halevy out_overflow: 3073c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3074c0eae66eSBenny Halevy return -EIO; 30751da177e4SLinus Torvalds } 30761da177e4SLinus Torvalds 30771da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 30781da177e4SLinus Torvalds { 30798687b63aSAl Viro __be32 *p; 30801da177e4SLinus Torvalds 3081c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3082c0eae66eSBenny Halevy if (unlikely(!p)) 3083c0eae66eSBenny Halevy goto out_overflow; 30846f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3085cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 30861da177e4SLinus Torvalds 3087c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3088c0eae66eSBenny Halevy if (unlikely(!p)) 3089c0eae66eSBenny Halevy goto out_overflow; 30901da177e4SLinus Torvalds hdr->tag = (char *)p; 30911da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3092cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3093aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3094aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 30951da177e4SLinus Torvalds return 0; 3096c0eae66eSBenny Halevy out_overflow: 3097c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3098c0eae66eSBenny Halevy return -EIO; 30991da177e4SLinus Torvalds } 31001da177e4SLinus Torvalds 31011da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 31021da177e4SLinus Torvalds { 31038687b63aSAl Viro __be32 *p; 31041da177e4SLinus Torvalds uint32_t opnum; 31051da177e4SLinus Torvalds int32_t nfserr; 31061da177e4SLinus Torvalds 3107c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3108c0eae66eSBenny Halevy if (unlikely(!p)) 3109c0eae66eSBenny Halevy goto out_overflow; 31106f723f77SBenny Halevy opnum = be32_to_cpup(p++); 31111da177e4SLinus Torvalds if (opnum != expected) { 3112fe82a183SChuck Lever dprintk("nfs: Server returned operation" 31131da177e4SLinus Torvalds " %d but we issued a request for %d\n", 31141da177e4SLinus Torvalds opnum, expected); 31151da177e4SLinus Torvalds return -EIO; 31161da177e4SLinus Torvalds } 3117cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 31181da177e4SLinus Torvalds if (nfserr != NFS_OK) 3119856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 31201da177e4SLinus Torvalds return 0; 3121c0eae66eSBenny Halevy out_overflow: 3122c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3123c0eae66eSBenny Halevy return -EIO; 31241da177e4SLinus Torvalds } 31251da177e4SLinus Torvalds 31261da177e4SLinus Torvalds /* Dummy routine */ 3127adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 31281da177e4SLinus Torvalds { 31298687b63aSAl Viro __be32 *p; 3130683b57b4STrond Myklebust unsigned int strlen; 31311da177e4SLinus Torvalds char *str; 31321da177e4SLinus Torvalds 3133c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3134c0eae66eSBenny Halevy if (likely(p)) 31351da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3136c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3137c0eae66eSBenny Halevy return -EIO; 31381da177e4SLinus Torvalds } 31391da177e4SLinus Torvalds 31401da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 31411da177e4SLinus Torvalds { 31428687b63aSAl Viro uint32_t bmlen; 31438687b63aSAl Viro __be32 *p; 31441da177e4SLinus Torvalds 3145c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3146c0eae66eSBenny Halevy if (unlikely(!p)) 3147c0eae66eSBenny Halevy goto out_overflow; 3148cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 31491da177e4SLinus Torvalds 3150dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3151c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3152c0eae66eSBenny Halevy if (unlikely(!p)) 3153c0eae66eSBenny Halevy goto out_overflow; 31541da177e4SLinus Torvalds if (bmlen > 0) { 31556f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3156dae100c2SFred Isaman if (bmlen > 1) { 3157dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3158dae100c2SFred Isaman if (bmlen > 2) 3159dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3160dae100c2SFred Isaman } 31611da177e4SLinus Torvalds } 31621da177e4SLinus Torvalds return 0; 3163c0eae66eSBenny Halevy out_overflow: 3164c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3165c0eae66eSBenny Halevy return -EIO; 31661da177e4SLinus Torvalds } 31671da177e4SLinus Torvalds 3168256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 31691da177e4SLinus Torvalds { 31708687b63aSAl Viro __be32 *p; 31711da177e4SLinus Torvalds 3172c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3173c0eae66eSBenny Halevy if (unlikely(!p)) 3174c0eae66eSBenny Halevy goto out_overflow; 3175cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3176256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 31771da177e4SLinus Torvalds return 0; 3178c0eae66eSBenny Halevy out_overflow: 3179c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3180c0eae66eSBenny Halevy return -EIO; 31811da177e4SLinus Torvalds } 31821da177e4SLinus Torvalds 31831da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 31841da177e4SLinus Torvalds { 31851da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 31863388bff5SRoman Borisov int ret; 31873388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 31883388bff5SRoman Borisov if (unlikely(ret < 0)) 31893388bff5SRoman Borisov return ret; 31901da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 31911da177e4SLinus Torvalds } else 3192dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3193dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3194dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 31951da177e4SLinus Torvalds return 0; 31961da177e4SLinus Torvalds } 31971da177e4SLinus Torvalds 31981da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 31991da177e4SLinus Torvalds { 32008687b63aSAl Viro __be32 *p; 3201409924e4STrond Myklebust int ret = 0; 32021da177e4SLinus Torvalds 32031da177e4SLinus Torvalds *type = 0; 32041da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32051da177e4SLinus Torvalds return -EIO; 32061da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3207c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3208c0eae66eSBenny Halevy if (unlikely(!p)) 3209c0eae66eSBenny Halevy goto out_overflow; 3210cccddf4fSBenny Halevy *type = be32_to_cpup(p); 32111da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 32123110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 32131da177e4SLinus Torvalds return -EIO; 32141da177e4SLinus Torvalds } 32151da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3216409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 32171da177e4SLinus Torvalds } 3218bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3219409924e4STrond Myklebust return ret; 3220c0eae66eSBenny Halevy out_overflow: 3221c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3222c0eae66eSBenny Halevy return -EIO; 32231da177e4SLinus Torvalds } 32241da177e4SLinus Torvalds 3225264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3226264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3227264e6351SChuck Lever { 3228264e6351SChuck Lever __be32 *p; 3229264e6351SChuck Lever 3230264e6351SChuck Lever *type = 0; 3231264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3232264e6351SChuck Lever return -EIO; 3233264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3234264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3235264e6351SChuck Lever if (unlikely(!p)) 3236264e6351SChuck Lever goto out_overflow; 3237264e6351SChuck Lever *type = be32_to_cpup(p); 3238264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3239264e6351SChuck Lever } 3240264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3241264e6351SChuck Lever return 0; 3242264e6351SChuck Lever out_overflow: 3243264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3244264e6351SChuck Lever return -EIO; 3245264e6351SChuck Lever } 3246264e6351SChuck Lever 32471da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 32481da177e4SLinus Torvalds { 32498687b63aSAl Viro __be32 *p; 3250409924e4STrond Myklebust int ret = 0; 32511da177e4SLinus Torvalds 32521da177e4SLinus Torvalds *change = 0; 32531da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 32541da177e4SLinus Torvalds return -EIO; 32551da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3256c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3257c0eae66eSBenny Halevy if (unlikely(!p)) 3258c0eae66eSBenny Halevy goto out_overflow; 3259cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 32601da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3261409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 32621da177e4SLinus Torvalds } 32633110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 32641da177e4SLinus Torvalds (unsigned long long)*change); 3265409924e4STrond Myklebust return ret; 3266c0eae66eSBenny Halevy out_overflow: 3267c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3268c0eae66eSBenny Halevy return -EIO; 32691da177e4SLinus Torvalds } 32701da177e4SLinus Torvalds 32711da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 32721da177e4SLinus Torvalds { 32738687b63aSAl Viro __be32 *p; 3274409924e4STrond Myklebust int ret = 0; 32751da177e4SLinus Torvalds 32761da177e4SLinus Torvalds *size = 0; 32771da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 32781da177e4SLinus Torvalds return -EIO; 32791da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3280c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3281c0eae66eSBenny Halevy if (unlikely(!p)) 3282c0eae66eSBenny Halevy goto out_overflow; 3283cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 32841da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3285409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 32861da177e4SLinus Torvalds } 32873110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3288409924e4STrond Myklebust return ret; 3289c0eae66eSBenny Halevy out_overflow: 3290c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3291c0eae66eSBenny Halevy return -EIO; 32921da177e4SLinus Torvalds } 32931da177e4SLinus Torvalds 32941da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32951da177e4SLinus Torvalds { 32968687b63aSAl Viro __be32 *p; 32971da177e4SLinus Torvalds 32981da177e4SLinus Torvalds *res = 0; 32991da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33001da177e4SLinus Torvalds return -EIO; 33011da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3302c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3303c0eae66eSBenny Halevy if (unlikely(!p)) 3304c0eae66eSBenny Halevy goto out_overflow; 3305cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33061da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 33071da177e4SLinus Torvalds } 33083110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 33091da177e4SLinus Torvalds return 0; 3310c0eae66eSBenny Halevy out_overflow: 3311c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3312c0eae66eSBenny Halevy return -EIO; 33131da177e4SLinus Torvalds } 33141da177e4SLinus Torvalds 33151da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33161da177e4SLinus Torvalds { 33178687b63aSAl Viro __be32 *p; 33181da177e4SLinus Torvalds 33191da177e4SLinus Torvalds *res = 0; 33201da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 33211da177e4SLinus Torvalds return -EIO; 33221da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3323c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3324c0eae66eSBenny Halevy if (unlikely(!p)) 3325c0eae66eSBenny Halevy goto out_overflow; 3326cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33271da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 33281da177e4SLinus Torvalds } 33293110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 33301da177e4SLinus Torvalds return 0; 3331c0eae66eSBenny Halevy out_overflow: 3332c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3333c0eae66eSBenny Halevy return -EIO; 33341da177e4SLinus Torvalds } 33351da177e4SLinus Torvalds 33368b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 33371da177e4SLinus Torvalds { 33388687b63aSAl Viro __be32 *p; 3339409924e4STrond Myklebust int ret = 0; 33401da177e4SLinus Torvalds 33411da177e4SLinus Torvalds fsid->major = 0; 33421da177e4SLinus Torvalds fsid->minor = 0; 33431da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 33441da177e4SLinus Torvalds return -EIO; 33451da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3346c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3347c0eae66eSBenny Halevy if (unlikely(!p)) 3348c0eae66eSBenny Halevy goto out_overflow; 33493ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3350cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 33511da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3352409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 33531da177e4SLinus Torvalds } 33543110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 33551da177e4SLinus Torvalds (unsigned long long)fsid->major, 33561da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3357409924e4STrond Myklebust return ret; 3358c0eae66eSBenny Halevy out_overflow: 3359c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3360c0eae66eSBenny Halevy return -EIO; 33611da177e4SLinus Torvalds } 33621da177e4SLinus Torvalds 33631da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33641da177e4SLinus Torvalds { 33658687b63aSAl Viro __be32 *p; 33661da177e4SLinus Torvalds 33671da177e4SLinus Torvalds *res = 60; 33681da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 33691da177e4SLinus Torvalds return -EIO; 33701da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3371c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3372c0eae66eSBenny Halevy if (unlikely(!p)) 3373c0eae66eSBenny Halevy goto out_overflow; 3374cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33751da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 33761da177e4SLinus Torvalds } 33773110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 33781da177e4SLinus Torvalds return 0; 3379c0eae66eSBenny Halevy out_overflow: 3380c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3381c0eae66eSBenny Halevy return -EIO; 33821da177e4SLinus Torvalds } 33831da177e4SLinus Torvalds 3384ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3385ae42c70aSBryan Schumaker { 3386ae42c70aSBryan Schumaker __be32 *p; 3387ae42c70aSBryan Schumaker 3388ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3389ae42c70aSBryan Schumaker return -EIO; 3390ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3391ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3392ae42c70aSBryan Schumaker if (unlikely(!p)) 3393ae42c70aSBryan Schumaker goto out_overflow; 3394ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3395ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3396ae42c70aSBryan Schumaker } 3397ae42c70aSBryan Schumaker return 0; 3398ae42c70aSBryan Schumaker out_overflow: 3399ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3400ae42c70aSBryan Schumaker return -EIO; 3401ae42c70aSBryan Schumaker } 3402ae42c70aSBryan Schumaker 3403ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3404ae42c70aSBryan Schumaker { 3405ae42c70aSBryan Schumaker __be32 *p; 3406ae42c70aSBryan Schumaker int len; 3407ae42c70aSBryan Schumaker 34087ad07353STrond Myklebust if (fh != NULL) 3409ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3410ae42c70aSBryan Schumaker 3411ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3412ae42c70aSBryan Schumaker return -EIO; 3413ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3414ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3415ae42c70aSBryan Schumaker if (unlikely(!p)) 3416ae42c70aSBryan Schumaker goto out_overflow; 3417ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3418ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3419ae42c70aSBryan Schumaker return -EIO; 3420ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3421ae42c70aSBryan Schumaker if (unlikely(!p)) 3422ae42c70aSBryan Schumaker goto out_overflow; 34237ad07353STrond Myklebust if (fh != NULL) { 3424ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 34257ad07353STrond Myklebust fh->size = len; 34267ad07353STrond Myklebust } 3427ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3428ae42c70aSBryan Schumaker } 3429ae42c70aSBryan Schumaker return 0; 3430ae42c70aSBryan Schumaker out_overflow: 3431ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3432ae42c70aSBryan Schumaker return -EIO; 3433ae42c70aSBryan Schumaker } 3434ae42c70aSBryan Schumaker 34351da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34361da177e4SLinus Torvalds { 34378687b63aSAl Viro __be32 *p; 34381da177e4SLinus Torvalds 34391da177e4SLinus Torvalds *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL; 34401da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 34411da177e4SLinus Torvalds return -EIO; 34421da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3443c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3444c0eae66eSBenny Halevy if (unlikely(!p)) 3445c0eae66eSBenny Halevy goto out_overflow; 3446cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34471da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 34481da177e4SLinus Torvalds } 34493110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 34501da177e4SLinus Torvalds return 0; 3451c0eae66eSBenny Halevy out_overflow: 3452c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3453c0eae66eSBenny Halevy return -EIO; 34541da177e4SLinus Torvalds } 34551da177e4SLinus Torvalds 34561da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 34571da177e4SLinus Torvalds { 34588687b63aSAl Viro __be32 *p; 3459409924e4STrond Myklebust int ret = 0; 34601da177e4SLinus Torvalds 34611da177e4SLinus Torvalds *fileid = 0; 34621da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 34631da177e4SLinus Torvalds return -EIO; 34641da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3465c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3466c0eae66eSBenny Halevy if (unlikely(!p)) 3467c0eae66eSBenny Halevy goto out_overflow; 3468cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 34691da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3470409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 34711da177e4SLinus Torvalds } 34723110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3473409924e4STrond Myklebust return ret; 3474c0eae66eSBenny Halevy out_overflow: 3475c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3476c0eae66eSBenny Halevy return -EIO; 34771da177e4SLinus Torvalds } 34781da177e4SLinus Torvalds 347999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 348099baf625SManoj Naik { 34818687b63aSAl Viro __be32 *p; 3482409924e4STrond Myklebust int ret = 0; 348399baf625SManoj Naik 348499baf625SManoj Naik *fileid = 0; 348599baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 348699baf625SManoj Naik return -EIO; 348799baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3488c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3489c0eae66eSBenny Halevy if (unlikely(!p)) 3490c0eae66eSBenny Halevy goto out_overflow; 3491cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 349299baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 349328331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 349499baf625SManoj Naik } 34953110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3496409924e4STrond Myklebust return ret; 3497c0eae66eSBenny Halevy out_overflow: 3498c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3499c0eae66eSBenny Halevy return -EIO; 350099baf625SManoj Naik } 350199baf625SManoj Naik 35021da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35031da177e4SLinus Torvalds { 35048687b63aSAl Viro __be32 *p; 35051da177e4SLinus Torvalds int status = 0; 35061da177e4SLinus Torvalds 35071da177e4SLinus Torvalds *res = 0; 35081da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 35091da177e4SLinus Torvalds return -EIO; 35101da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3511c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3512c0eae66eSBenny Halevy if (unlikely(!p)) 3513c0eae66eSBenny Halevy goto out_overflow; 3514cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35151da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 35161da177e4SLinus Torvalds } 35173110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 35181da177e4SLinus Torvalds return status; 3519c0eae66eSBenny Halevy out_overflow: 3520c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3521c0eae66eSBenny Halevy return -EIO; 35221da177e4SLinus Torvalds } 35231da177e4SLinus Torvalds 35241da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35251da177e4SLinus Torvalds { 35268687b63aSAl Viro __be32 *p; 35271da177e4SLinus Torvalds int status = 0; 35281da177e4SLinus Torvalds 35291da177e4SLinus Torvalds *res = 0; 35301da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 35311da177e4SLinus Torvalds return -EIO; 35321da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3533c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3534c0eae66eSBenny Halevy if (unlikely(!p)) 3535c0eae66eSBenny Halevy goto out_overflow; 3536cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35371da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 35381da177e4SLinus Torvalds } 35393110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 35401da177e4SLinus Torvalds return status; 3541c0eae66eSBenny Halevy out_overflow: 3542c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3543c0eae66eSBenny Halevy return -EIO; 35441da177e4SLinus Torvalds } 35451da177e4SLinus Torvalds 35461da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35471da177e4SLinus Torvalds { 35488687b63aSAl Viro __be32 *p; 35491da177e4SLinus Torvalds int status = 0; 35501da177e4SLinus Torvalds 35511da177e4SLinus Torvalds *res = 0; 35521da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 35531da177e4SLinus Torvalds return -EIO; 35541da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3555c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3556c0eae66eSBenny Halevy if (unlikely(!p)) 3557c0eae66eSBenny Halevy goto out_overflow; 3558cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35591da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 35601da177e4SLinus Torvalds } 35613110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 35621da177e4SLinus Torvalds return status; 3563c0eae66eSBenny Halevy out_overflow: 3564c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3565c0eae66eSBenny Halevy return -EIO; 35661da177e4SLinus Torvalds } 35671da177e4SLinus Torvalds 35687aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 35697aaa0b3bSManoj Naik { 3570464ad6b1SChuck Lever u32 n; 35718687b63aSAl Viro __be32 *p; 35727aaa0b3bSManoj Naik int status = 0; 35737aaa0b3bSManoj Naik 3574c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3575c0eae66eSBenny Halevy if (unlikely(!p)) 3576c0eae66eSBenny Halevy goto out_overflow; 3577cccddf4fSBenny Halevy n = be32_to_cpup(p); 357833a43f28SAndy Adamson if (n == 0) 357933a43f28SAndy Adamson goto root_path; 358002a2976cSChuck Lever dprintk("pathname4: "); 3581809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3582809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3583809b426cSTrond Myklebust goto out_eio; 3584809b426cSTrond Myklebust } 3585809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 35867aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 35877aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 35887aaa0b3bSManoj Naik if (unlikely(status != 0)) 35897aaa0b3bSManoj Naik goto out_eio; 359095a13f7bSTrond Myklebust ifdebug (XDR) 359102a2976cSChuck Lever pr_cont("%s%.*s ", 359202a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 359302a2976cSChuck Lever component->len, component->data); 35947aaa0b3bSManoj Naik } 35957aaa0b3bSManoj Naik out: 35967aaa0b3bSManoj Naik return status; 359733a43f28SAndy Adamson root_path: 359833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 359933a43f28SAndy Adamson path->ncomponents = 1; 360033a43f28SAndy Adamson path->components[0].len=0; 360133a43f28SAndy Adamson path->components[0].data=NULL; 360202a2976cSChuck Lever dprintk("pathname4: /\n"); 360333a43f28SAndy Adamson goto out; 36047aaa0b3bSManoj Naik out_eio: 36057aaa0b3bSManoj Naik dprintk(" status %d", status); 36067aaa0b3bSManoj Naik status = -EIO; 36077aaa0b3bSManoj Naik goto out; 3608c0eae66eSBenny Halevy out_overflow: 3609c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3610c0eae66eSBenny Halevy return -EIO; 36117aaa0b3bSManoj Naik } 36127aaa0b3bSManoj Naik 36137aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3614683b57b4STrond Myklebust { 3615683b57b4STrond Myklebust int n; 36168687b63aSAl Viro __be32 *p; 3617683b57b4STrond Myklebust int status = -EIO; 3618683b57b4STrond Myklebust 3619683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3620683b57b4STrond Myklebust goto out; 3621683b57b4STrond Myklebust status = 0; 3622683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3623683b57b4STrond Myklebust goto out; 36248b7e3f49STrond Myklebust status = -EIO; 36258b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 36268b7e3f49STrond Myklebust if (unlikely(res == NULL)) 36278b7e3f49STrond Myklebust goto out; 362802a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 36297aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3630683b57b4STrond Myklebust if (unlikely(status != 0)) 3631683b57b4STrond Myklebust goto out; 3632c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3633c0eae66eSBenny Halevy if (unlikely(!p)) 3634c0eae66eSBenny Halevy goto out_overflow; 3635cccddf4fSBenny Halevy n = be32_to_cpup(p); 3636683b57b4STrond Myklebust if (n <= 0) 3637683b57b4STrond Myklebust goto out_eio; 3638809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3639464ad6b1SChuck Lever u32 m; 3640809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3641683b57b4STrond Myklebust 3642809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3643809b426cSTrond Myklebust break; 3644809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3645c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3646c0eae66eSBenny Halevy if (unlikely(!p)) 3647c0eae66eSBenny Halevy goto out_overflow; 3648cccddf4fSBenny Halevy m = be32_to_cpup(p); 36497aaa0b3bSManoj Naik 365002a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3651809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3652809b426cSTrond Myklebust struct nfs4_string *server; 3653809b426cSTrond Myklebust 3654809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3655464ad6b1SChuck Lever unsigned int i; 3656464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3657464ad6b1SChuck Lever "returned for location %u\n", 36583110ff80SHarvey Harrison __func__, 3659464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3660464ad6b1SChuck Lever m, res->nlocations); 36617aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 36622e42c3e2STrond Myklebust unsigned int len; 36637aaa0b3bSManoj Naik char *data; 36647aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3665683b57b4STrond Myklebust if (unlikely(status != 0)) 3666683b57b4STrond Myklebust goto out_eio; 36677aaa0b3bSManoj Naik } 3668809b426cSTrond Myklebust break; 36697aaa0b3bSManoj Naik } 3670809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3671809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3672809b426cSTrond Myklebust if (unlikely(status != 0)) 3673809b426cSTrond Myklebust goto out_eio; 3674809b426cSTrond Myklebust dprintk("%s ", server->data); 36757aaa0b3bSManoj Naik } 36767aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 36777aaa0b3bSManoj Naik if (unlikely(status != 0)) 36787aaa0b3bSManoj Naik goto out_eio; 3679683b57b4STrond Myklebust } 3680409924e4STrond Myklebust if (res->nlocations != 0) 368181934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3682683b57b4STrond Myklebust out: 36833110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3684683b57b4STrond Myklebust return status; 3685c0eae66eSBenny Halevy out_overflow: 3686c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3687683b57b4STrond Myklebust out_eio: 3688683b57b4STrond Myklebust status = -EIO; 3689683b57b4STrond Myklebust goto out; 3690683b57b4STrond Myklebust } 3691683b57b4STrond Myklebust 36921da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36931da177e4SLinus Torvalds { 36948687b63aSAl Viro __be32 *p; 36951da177e4SLinus Torvalds int status = 0; 36961da177e4SLinus Torvalds 36971da177e4SLinus Torvalds *res = 0; 36981da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 36991da177e4SLinus Torvalds return -EIO; 37001da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3701c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3702c0eae66eSBenny Halevy if (unlikely(!p)) 3703c0eae66eSBenny Halevy goto out_overflow; 3704cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 37051da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 37061da177e4SLinus Torvalds } 37073110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 37081da177e4SLinus Torvalds return status; 3709c0eae66eSBenny Halevy out_overflow: 3710c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3711c0eae66eSBenny Halevy return -EIO; 37121da177e4SLinus Torvalds } 37131da177e4SLinus Torvalds 37141da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 37151da177e4SLinus Torvalds { 37168687b63aSAl Viro __be32 *p; 37171da177e4SLinus Torvalds int status = 0; 37181da177e4SLinus Torvalds 37191da177e4SLinus Torvalds *maxlink = 1; 37201da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 37211da177e4SLinus Torvalds return -EIO; 37221da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3723c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3724c0eae66eSBenny Halevy if (unlikely(!p)) 3725c0eae66eSBenny Halevy goto out_overflow; 3726cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 37271da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 37281da177e4SLinus Torvalds } 37293110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 37301da177e4SLinus Torvalds return status; 3731c0eae66eSBenny Halevy out_overflow: 3732c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3733c0eae66eSBenny Halevy return -EIO; 37341da177e4SLinus Torvalds } 37351da177e4SLinus Torvalds 37361da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 37371da177e4SLinus Torvalds { 37388687b63aSAl Viro __be32 *p; 37391da177e4SLinus Torvalds int status = 0; 37401da177e4SLinus Torvalds 37411da177e4SLinus Torvalds *maxname = 1024; 37421da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 37431da177e4SLinus Torvalds return -EIO; 37441da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3745c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3746c0eae66eSBenny Halevy if (unlikely(!p)) 3747c0eae66eSBenny Halevy goto out_overflow; 3748cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 37491da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 37501da177e4SLinus Torvalds } 37513110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 37521da177e4SLinus Torvalds return status; 3753c0eae66eSBenny Halevy out_overflow: 3754c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3755c0eae66eSBenny Halevy return -EIO; 37561da177e4SLinus Torvalds } 37571da177e4SLinus Torvalds 37581da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37591da177e4SLinus Torvalds { 37608687b63aSAl Viro __be32 *p; 37611da177e4SLinus Torvalds int status = 0; 37621da177e4SLinus Torvalds 37631da177e4SLinus Torvalds *res = 1024; 37641da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 37651da177e4SLinus Torvalds return -EIO; 37661da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 37671da177e4SLinus Torvalds uint64_t maxread; 3768c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3769c0eae66eSBenny Halevy if (unlikely(!p)) 3770c0eae66eSBenny Halevy goto out_overflow; 3771cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 37721da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 37731da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 37741da177e4SLinus Torvalds *res = (uint32_t)maxread; 37751da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 37761da177e4SLinus Torvalds } 37773110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 37781da177e4SLinus Torvalds return status; 3779c0eae66eSBenny Halevy out_overflow: 3780c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3781c0eae66eSBenny Halevy return -EIO; 37821da177e4SLinus Torvalds } 37831da177e4SLinus Torvalds 37841da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37851da177e4SLinus Torvalds { 37868687b63aSAl Viro __be32 *p; 37871da177e4SLinus Torvalds int status = 0; 37881da177e4SLinus Torvalds 37891da177e4SLinus Torvalds *res = 1024; 37901da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 37911da177e4SLinus Torvalds return -EIO; 37921da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 37931da177e4SLinus Torvalds uint64_t maxwrite; 3794c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3795c0eae66eSBenny Halevy if (unlikely(!p)) 3796c0eae66eSBenny Halevy goto out_overflow; 3797cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 37981da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 37991da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 38001da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 38011da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 38021da177e4SLinus Torvalds } 38033110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 38041da177e4SLinus Torvalds return status; 3805c0eae66eSBenny Halevy out_overflow: 3806c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3807c0eae66eSBenny Halevy return -EIO; 38081da177e4SLinus Torvalds } 38091da177e4SLinus Torvalds 3810bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 38111da177e4SLinus Torvalds { 3812bca79478STrond Myklebust uint32_t tmp; 38138687b63aSAl Viro __be32 *p; 3814409924e4STrond Myklebust int ret = 0; 38151da177e4SLinus Torvalds 38161da177e4SLinus Torvalds *mode = 0; 38171da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 38181da177e4SLinus Torvalds return -EIO; 38191da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3820c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3821c0eae66eSBenny Halevy if (unlikely(!p)) 3822c0eae66eSBenny Halevy goto out_overflow; 3823cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3824bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 38251da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3826409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 38271da177e4SLinus Torvalds } 38283110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3829409924e4STrond Myklebust return ret; 3830c0eae66eSBenny Halevy out_overflow: 3831c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3832c0eae66eSBenny Halevy return -EIO; 38331da177e4SLinus Torvalds } 38341da177e4SLinus Torvalds 38351da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 38361da177e4SLinus Torvalds { 38378687b63aSAl Viro __be32 *p; 3838409924e4STrond Myklebust int ret = 0; 38391da177e4SLinus Torvalds 38401da177e4SLinus Torvalds *nlink = 1; 38411da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 38421da177e4SLinus Torvalds return -EIO; 38431da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3844c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3845c0eae66eSBenny Halevy if (unlikely(!p)) 3846c0eae66eSBenny Halevy goto out_overflow; 3847cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 38481da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3849409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 38501da177e4SLinus Torvalds } 38513110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3852409924e4STrond Myklebust return ret; 3853c0eae66eSBenny Halevy out_overflow: 3854c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3855c0eae66eSBenny Halevy return -EIO; 38561da177e4SLinus Torvalds } 38571da177e4SLinus Torvalds 385880e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3859e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 38606926afd1STrond Myklebust struct nfs4_string *owner_name) 38611da177e4SLinus Torvalds { 38628687b63aSAl Viro uint32_t len; 38638687b63aSAl Viro __be32 *p; 3864409924e4STrond Myklebust int ret = 0; 38651da177e4SLinus Torvalds 3866e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 38671da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 38681da177e4SLinus Torvalds return -EIO; 38691da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3870c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3871c0eae66eSBenny Halevy if (unlikely(!p)) 3872c0eae66eSBenny Halevy goto out_overflow; 3873cccddf4fSBenny Halevy len = be32_to_cpup(p); 3874c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3875c0eae66eSBenny Halevy if (unlikely(!p)) 3876c0eae66eSBenny Halevy goto out_overflow; 38776926afd1STrond Myklebust if (owner_name != NULL) { 38786926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 38796926afd1STrond Myklebust if (owner_name->data != NULL) { 38806926afd1STrond Myklebust owner_name->len = len; 38816926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 38826926afd1STrond Myklebust } 388380e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3884e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3885409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3886409924e4STrond Myklebust else 38871da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 38883110ff80SHarvey Harrison __func__); 38891da177e4SLinus Torvalds } else 3890fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 38913110ff80SHarvey Harrison __func__, len); 38921da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 38931da177e4SLinus Torvalds } 3894e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3895409924e4STrond Myklebust return ret; 3896c0eae66eSBenny Halevy out_overflow: 3897c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3898c0eae66eSBenny Halevy return -EIO; 38991da177e4SLinus Torvalds } 39001da177e4SLinus Torvalds 390180e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3902e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 39036926afd1STrond Myklebust struct nfs4_string *group_name) 39041da177e4SLinus Torvalds { 39058687b63aSAl Viro uint32_t len; 39068687b63aSAl Viro __be32 *p; 3907409924e4STrond Myklebust int ret = 0; 39081da177e4SLinus Torvalds 3909e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 39101da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 39111da177e4SLinus Torvalds return -EIO; 39121da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3913c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3914c0eae66eSBenny Halevy if (unlikely(!p)) 3915c0eae66eSBenny Halevy goto out_overflow; 3916cccddf4fSBenny Halevy len = be32_to_cpup(p); 3917c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3918c0eae66eSBenny Halevy if (unlikely(!p)) 3919c0eae66eSBenny Halevy goto out_overflow; 39206926afd1STrond Myklebust if (group_name != NULL) { 39216926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 39226926afd1STrond Myklebust if (group_name->data != NULL) { 39236926afd1STrond Myklebust group_name->len = len; 39246926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 39256926afd1STrond Myklebust } 392680e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3927e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3928409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3929409924e4STrond Myklebust else 39301da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 39313110ff80SHarvey Harrison __func__); 39321da177e4SLinus Torvalds } else 3933fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 39343110ff80SHarvey Harrison __func__, len); 39351da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 39361da177e4SLinus Torvalds } 3937e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 3938409924e4STrond Myklebust return ret; 3939c0eae66eSBenny Halevy out_overflow: 3940c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3941c0eae66eSBenny Halevy return -EIO; 39421da177e4SLinus Torvalds } 39431da177e4SLinus Torvalds 39441da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 39451da177e4SLinus Torvalds { 39468687b63aSAl Viro uint32_t major = 0, minor = 0; 39478687b63aSAl Viro __be32 *p; 3948409924e4STrond Myklebust int ret = 0; 39491da177e4SLinus Torvalds 39501da177e4SLinus Torvalds *rdev = MKDEV(0,0); 39511da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 39521da177e4SLinus Torvalds return -EIO; 39531da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 39541da177e4SLinus Torvalds dev_t tmp; 39551da177e4SLinus Torvalds 3956c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3957c0eae66eSBenny Halevy if (unlikely(!p)) 3958c0eae66eSBenny Halevy goto out_overflow; 39596f723f77SBenny Halevy major = be32_to_cpup(p++); 3960cccddf4fSBenny Halevy minor = be32_to_cpup(p); 39611da177e4SLinus Torvalds tmp = MKDEV(major, minor); 39621da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 39631da177e4SLinus Torvalds *rdev = tmp; 39641da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3965409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 39661da177e4SLinus Torvalds } 39673110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3968409924e4STrond Myklebust return ret; 3969c0eae66eSBenny Halevy out_overflow: 3970c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3971c0eae66eSBenny Halevy return -EIO; 39721da177e4SLinus Torvalds } 39731da177e4SLinus Torvalds 39741da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39751da177e4SLinus Torvalds { 39768687b63aSAl Viro __be32 *p; 39771da177e4SLinus Torvalds int status = 0; 39781da177e4SLinus Torvalds 39791da177e4SLinus Torvalds *res = 0; 39801da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 39811da177e4SLinus Torvalds return -EIO; 39821da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3983c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3984c0eae66eSBenny Halevy if (unlikely(!p)) 3985c0eae66eSBenny Halevy goto out_overflow; 3986cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39871da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 39881da177e4SLinus Torvalds } 39893110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 39901da177e4SLinus Torvalds return status; 3991c0eae66eSBenny Halevy out_overflow: 3992c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3993c0eae66eSBenny Halevy return -EIO; 39941da177e4SLinus Torvalds } 39951da177e4SLinus Torvalds 39961da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39971da177e4SLinus Torvalds { 39988687b63aSAl Viro __be32 *p; 39991da177e4SLinus Torvalds int status = 0; 40001da177e4SLinus Torvalds 40011da177e4SLinus Torvalds *res = 0; 40021da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 40031da177e4SLinus Torvalds return -EIO; 40041da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4005c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4006c0eae66eSBenny Halevy if (unlikely(!p)) 4007c0eae66eSBenny Halevy goto out_overflow; 4008cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40091da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 40101da177e4SLinus Torvalds } 40113110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 40121da177e4SLinus Torvalds return status; 4013c0eae66eSBenny Halevy out_overflow: 4014c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4015c0eae66eSBenny Halevy return -EIO; 40161da177e4SLinus Torvalds } 40171da177e4SLinus Torvalds 40181da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40191da177e4SLinus Torvalds { 40208687b63aSAl Viro __be32 *p; 40211da177e4SLinus Torvalds int status = 0; 40221da177e4SLinus Torvalds 40231da177e4SLinus Torvalds *res = 0; 40241da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 40251da177e4SLinus Torvalds return -EIO; 40261da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4027c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4028c0eae66eSBenny Halevy if (unlikely(!p)) 4029c0eae66eSBenny Halevy goto out_overflow; 4030cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40311da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 40321da177e4SLinus Torvalds } 40333110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 40341da177e4SLinus Torvalds return status; 4035c0eae66eSBenny Halevy out_overflow: 4036c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4037c0eae66eSBenny Halevy return -EIO; 40381da177e4SLinus Torvalds } 40391da177e4SLinus Torvalds 40401da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 40411da177e4SLinus Torvalds { 40428687b63aSAl Viro __be32 *p; 4043409924e4STrond Myklebust int ret = 0; 40441da177e4SLinus Torvalds 40451da177e4SLinus Torvalds *used = 0; 40461da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 40471da177e4SLinus Torvalds return -EIO; 40481da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4049c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4050c0eae66eSBenny Halevy if (unlikely(!p)) 4051c0eae66eSBenny Halevy goto out_overflow; 4052cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 40531da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4054409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 40551da177e4SLinus Torvalds } 40563110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 40571da177e4SLinus Torvalds (unsigned long long)*used); 4058409924e4STrond Myklebust return ret; 4059c0eae66eSBenny Halevy out_overflow: 4060c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4061c0eae66eSBenny Halevy return -EIO; 40621da177e4SLinus Torvalds } 40631da177e4SLinus Torvalds 40641da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 40651da177e4SLinus Torvalds { 40668687b63aSAl Viro __be32 *p; 40671da177e4SLinus Torvalds uint64_t sec; 40681da177e4SLinus Torvalds uint32_t nsec; 40691da177e4SLinus Torvalds 4070c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4071c0eae66eSBenny Halevy if (unlikely(!p)) 4072c0eae66eSBenny Halevy goto out_overflow; 40733ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 4074cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 40751da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 40761da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 40771da177e4SLinus Torvalds return 0; 4078c0eae66eSBenny Halevy out_overflow: 4079c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4080c0eae66eSBenny Halevy return -EIO; 40811da177e4SLinus Torvalds } 40821da177e4SLinus Torvalds 40831da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40841da177e4SLinus Torvalds { 40851da177e4SLinus Torvalds int status = 0; 40861da177e4SLinus Torvalds 40871da177e4SLinus Torvalds time->tv_sec = 0; 40881da177e4SLinus Torvalds time->tv_nsec = 0; 40891da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 40901da177e4SLinus Torvalds return -EIO; 40911da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 40921da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4093409924e4STrond Myklebust if (status == 0) 4094409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 40951da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 40961da177e4SLinus Torvalds } 40973110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 40981da177e4SLinus Torvalds return status; 40991da177e4SLinus Torvalds } 41001da177e4SLinus Torvalds 41011da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41021da177e4SLinus Torvalds { 41031da177e4SLinus Torvalds int status = 0; 41041da177e4SLinus Torvalds 41051da177e4SLinus Torvalds time->tv_sec = 0; 41061da177e4SLinus Torvalds time->tv_nsec = 0; 41071da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 41081da177e4SLinus Torvalds return -EIO; 41091da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 41101da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4111409924e4STrond Myklebust if (status == 0) 4112409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 41131da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 41141da177e4SLinus Torvalds } 41153110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 41161da177e4SLinus Torvalds return status; 41171da177e4SLinus Torvalds } 41181da177e4SLinus Torvalds 411955b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 412055b6e774SRicardo Labiaga struct timespec *time) 412155b6e774SRicardo Labiaga { 412255b6e774SRicardo Labiaga int status = 0; 412355b6e774SRicardo Labiaga 412455b6e774SRicardo Labiaga time->tv_sec = 0; 412555b6e774SRicardo Labiaga time->tv_nsec = 0; 412655b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 412755b6e774SRicardo Labiaga return -EIO; 412855b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 412955b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 413055b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 413155b6e774SRicardo Labiaga } 413255b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 413355b6e774SRicardo Labiaga (long)time->tv_nsec); 413455b6e774SRicardo Labiaga return status; 413555b6e774SRicardo Labiaga } 413655b6e774SRicardo Labiaga 4137aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4138aa9c2669SDavid Quigley struct nfs4_label *label) 4139aa9c2669SDavid Quigley { 4140aa9c2669SDavid Quigley uint32_t pi = 0; 4141aa9c2669SDavid Quigley uint32_t lfs = 0; 4142aa9c2669SDavid Quigley __u32 len; 4143aa9c2669SDavid Quigley __be32 *p; 4144aa9c2669SDavid Quigley int status = 0; 4145aa9c2669SDavid Quigley 4146aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4147aa9c2669SDavid Quigley return -EIO; 4148aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4149aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4150aa9c2669SDavid Quigley if (unlikely(!p)) 4151aa9c2669SDavid Quigley goto out_overflow; 4152aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4153aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4154aa9c2669SDavid Quigley if (unlikely(!p)) 4155aa9c2669SDavid Quigley goto out_overflow; 4156aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4157aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4158aa9c2669SDavid Quigley if (unlikely(!p)) 4159aa9c2669SDavid Quigley goto out_overflow; 4160aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4161aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4162aa9c2669SDavid Quigley if (unlikely(!p)) 4163aa9c2669SDavid Quigley goto out_overflow; 4164aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4165aa9c2669SDavid Quigley if (label) { 4166aa9c2669SDavid Quigley memcpy(label->label, p, len); 4167aa9c2669SDavid Quigley label->len = len; 4168aa9c2669SDavid Quigley label->pi = pi; 4169aa9c2669SDavid Quigley label->lfs = lfs; 4170aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4171aa9c2669SDavid Quigley } 4172aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4173aa9c2669SDavid Quigley } else 4174aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4175aa9c2669SDavid Quigley __func__, len); 4176aa9c2669SDavid Quigley } 4177aa9c2669SDavid Quigley if (label && label->label) 4178aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4179aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4180aa9c2669SDavid Quigley return status; 4181aa9c2669SDavid Quigley 4182aa9c2669SDavid Quigley out_overflow: 4183aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4184aa9c2669SDavid Quigley return -EIO; 4185aa9c2669SDavid Quigley } 4186aa9c2669SDavid Quigley 41871da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41881da177e4SLinus Torvalds { 41891da177e4SLinus Torvalds int status = 0; 41901da177e4SLinus Torvalds 41911da177e4SLinus Torvalds time->tv_sec = 0; 41921da177e4SLinus Torvalds time->tv_nsec = 0; 41931da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 41941da177e4SLinus Torvalds return -EIO; 41951da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 41961da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4197409924e4STrond Myklebust if (status == 0) 4198409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 41991da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 42001da177e4SLinus Torvalds } 42013110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 42021da177e4SLinus Torvalds return status; 42031da177e4SLinus Torvalds } 42041da177e4SLinus Torvalds 4205256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 42061da177e4SLinus Torvalds { 42071da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4208256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 42091da177e4SLinus Torvalds 42101da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4211fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4212fe82a183SChuck Lever "%u %c %u\n", 42133110ff80SHarvey Harrison __func__, 42141da177e4SLinus Torvalds attrwords << 2, 42151da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 42161da177e4SLinus Torvalds nwords << 2); 42171da177e4SLinus Torvalds return -EIO; 42181da177e4SLinus Torvalds } 42191da177e4SLinus Torvalds return 0; 42201da177e4SLinus Torvalds } 42211da177e4SLinus Torvalds 42221da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42231da177e4SLinus Torvalds { 42248687b63aSAl Viro __be32 *p; 42251da177e4SLinus Torvalds 4226c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4227c0eae66eSBenny Halevy if (unlikely(!p)) 4228c0eae66eSBenny Halevy goto out_overflow; 42296f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 42303ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4231cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 42321da177e4SLinus Torvalds return 0; 4233c0eae66eSBenny Halevy out_overflow: 4234c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4235c0eae66eSBenny Halevy return -EIO; 42361da177e4SLinus Torvalds } 42371da177e4SLinus Torvalds 42386168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 42391da177e4SLinus Torvalds { 42408687b63aSAl Viro __be32 *p; 42411da177e4SLinus Torvalds uint32_t supp, acc; 42421da177e4SLinus Torvalds int status; 42431da177e4SLinus Torvalds 42441da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 42451da177e4SLinus Torvalds if (status) 42461da177e4SLinus Torvalds return status; 4247c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4248c0eae66eSBenny Halevy if (unlikely(!p)) 4249c0eae66eSBenny Halevy goto out_overflow; 42506f723f77SBenny Halevy supp = be32_to_cpup(p++); 4251cccddf4fSBenny Halevy acc = be32_to_cpup(p); 42526168f62cSWeston Andros Adamson *supported = supp; 42536168f62cSWeston Andros Adamson *access = acc; 42541da177e4SLinus Torvalds return 0; 4255c0eae66eSBenny Halevy out_overflow: 4256c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4257c0eae66eSBenny Halevy return -EIO; 42581da177e4SLinus Torvalds } 42591da177e4SLinus Torvalds 426007d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 42611da177e4SLinus Torvalds { 42628687b63aSAl Viro __be32 *p; 426307d30434SBenny Halevy 426407d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 426507d30434SBenny Halevy if (likely(p)) { 426607d30434SBenny Halevy memcpy(buf, p, len); 426707d30434SBenny Halevy return 0; 426807d30434SBenny Halevy } 426907d30434SBenny Halevy print_overflow_msg(__func__, xdr); 427007d30434SBenny Halevy return -EIO; 427107d30434SBenny Halevy } 427207d30434SBenny Halevy 427307d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 427407d30434SBenny Halevy { 42752d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 42761da177e4SLinus Torvalds } 42771da177e4SLinus Torvalds 42781da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 42791da177e4SLinus Torvalds { 42801da177e4SLinus Torvalds int status; 42811da177e4SLinus Torvalds 42821da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4283c1d51931STrond Myklebust if (status != -EIO) 4284c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 428507d30434SBenny Halevy if (!status) 428607d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 42871da177e4SLinus Torvalds return status; 42881da177e4SLinus Torvalds } 42891da177e4SLinus Torvalds 4290db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4291db942bbdSBenny Halevy { 4292cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 42931da177e4SLinus Torvalds } 42941da177e4SLinus Torvalds 42952f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 42962f2c63bcSTrond Myklebust { 42972f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 42982f2c63bcSTrond Myklebust } 42992f2c63bcSTrond Myklebust 43000b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 43011da177e4SLinus Torvalds { 43021da177e4SLinus Torvalds int status; 43031da177e4SLinus Torvalds 43041da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4305db942bbdSBenny Halevy if (!status) 43062f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 43071da177e4SLinus Torvalds return status; 43081da177e4SLinus Torvalds } 43091da177e4SLinus Torvalds 43101da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43111da177e4SLinus Torvalds { 43128687b63aSAl Viro __be32 *p; 43131da177e4SLinus Torvalds uint32_t bmlen; 43141da177e4SLinus Torvalds int status; 43151da177e4SLinus Torvalds 43161da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 43171da177e4SLinus Torvalds if (status) 43181da177e4SLinus Torvalds return status; 43191da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 43201da177e4SLinus Torvalds return status; 4321c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4322c0eae66eSBenny Halevy if (unlikely(!p)) 4323c0eae66eSBenny Halevy goto out_overflow; 4324cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4325c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4326c0eae66eSBenny Halevy if (likely(p)) 43271da177e4SLinus Torvalds return 0; 4328c0eae66eSBenny Halevy out_overflow: 4329c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4330c0eae66eSBenny Halevy return -EIO; 43311da177e4SLinus Torvalds } 43321da177e4SLinus Torvalds 43331da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 43341da177e4SLinus Torvalds { 4335256e48bbSTrond Myklebust unsigned int savep; 4336dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43371da177e4SLinus Torvalds int status; 43381da177e4SLinus Torvalds 43391da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43401da177e4SLinus Torvalds goto xdr_error; 43411da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43421da177e4SLinus Torvalds goto xdr_error; 43431da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43441da177e4SLinus Torvalds goto xdr_error; 43451da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 43461da177e4SLinus Torvalds goto xdr_error; 4347264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4348264e6351SChuck Lever &res->fh_expire_type)) != 0) 4349264e6351SChuck Lever goto xdr_error; 43501da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 43511da177e4SLinus Torvalds goto xdr_error; 43521da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 43531da177e4SLinus Torvalds goto xdr_error; 43541da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 43551da177e4SLinus Torvalds goto xdr_error; 43561da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43571da177e4SLinus Torvalds xdr_error: 43583110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43591da177e4SLinus Torvalds return status; 43601da177e4SLinus Torvalds } 43611da177e4SLinus Torvalds 43621da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 43631da177e4SLinus Torvalds { 4364256e48bbSTrond Myklebust unsigned int savep; 4365dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43661da177e4SLinus Torvalds int status; 43671da177e4SLinus Torvalds 43681da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43691da177e4SLinus Torvalds goto xdr_error; 43701da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43711da177e4SLinus Torvalds goto xdr_error; 43721da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43731da177e4SLinus Torvalds goto xdr_error; 43741da177e4SLinus Torvalds 43751da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 43761da177e4SLinus Torvalds goto xdr_error; 43771da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 43781da177e4SLinus Torvalds goto xdr_error; 43791da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 43801da177e4SLinus Torvalds goto xdr_error; 43811da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 43821da177e4SLinus Torvalds goto xdr_error; 43831da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 43841da177e4SLinus Torvalds goto xdr_error; 43851da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 43861da177e4SLinus Torvalds goto xdr_error; 43871da177e4SLinus Torvalds 43881da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43891da177e4SLinus Torvalds xdr_error: 43903110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43911da177e4SLinus Torvalds return status; 43921da177e4SLinus Torvalds } 43931da177e4SLinus Torvalds 43941da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 43951da177e4SLinus Torvalds { 4396256e48bbSTrond Myklebust unsigned int savep; 4397dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43981da177e4SLinus Torvalds int status; 43991da177e4SLinus Torvalds 44001da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44011da177e4SLinus Torvalds goto xdr_error; 44021da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44031da177e4SLinus Torvalds goto xdr_error; 44041da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44051da177e4SLinus Torvalds goto xdr_error; 44061da177e4SLinus Torvalds 44071da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 44081da177e4SLinus Torvalds goto xdr_error; 44091da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 44101da177e4SLinus Torvalds goto xdr_error; 44111da177e4SLinus Torvalds 44121da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44131da177e4SLinus Torvalds xdr_error: 44143110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44151da177e4SLinus Torvalds return status; 44161da177e4SLinus Torvalds } 44171da177e4SLinus Torvalds 441888034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 441988034c3dSAndy Adamson uint32_t *bitmap, 442088034c3dSAndy Adamson uint64_t *res, 442188034c3dSAndy Adamson uint32_t hint_bit) 442288034c3dSAndy Adamson { 442388034c3dSAndy Adamson __be32 *p; 442488034c3dSAndy Adamson 442588034c3dSAndy Adamson *res = 0; 442688034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 442788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 442888034c3dSAndy Adamson if (unlikely(!p)) 442988034c3dSAndy Adamson goto out_overflow; 443088034c3dSAndy Adamson xdr_decode_hyper(p, res); 443188034c3dSAndy Adamson } 443288034c3dSAndy Adamson return 0; 443388034c3dSAndy Adamson out_overflow: 443488034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 443588034c3dSAndy Adamson return -EIO; 443688034c3dSAndy Adamson } 443788034c3dSAndy Adamson 443888034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 443988034c3dSAndy Adamson struct nfs4_threshold *res) 444088034c3dSAndy Adamson { 4441256e48bbSTrond Myklebust __be32 *p; 4442256e48bbSTrond Myklebust unsigned int savep; 444388034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 444488034c3dSAndy Adamson int status; 444588034c3dSAndy Adamson 444688034c3dSAndy Adamson /* layout type */ 444788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 444888034c3dSAndy Adamson if (unlikely(!p)) { 444988034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 445088034c3dSAndy Adamson return -EIO; 445188034c3dSAndy Adamson } 445288034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 445388034c3dSAndy Adamson 445488034c3dSAndy Adamson /* thi_hintset bitmap */ 445588034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 445688034c3dSAndy Adamson if (status < 0) 445788034c3dSAndy Adamson goto xdr_error; 445888034c3dSAndy Adamson 445988034c3dSAndy Adamson /* thi_hintlist length */ 446088034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 446188034c3dSAndy Adamson if (status < 0) 446288034c3dSAndy Adamson goto xdr_error; 446388034c3dSAndy Adamson /* thi_hintlist */ 446488034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 446588034c3dSAndy Adamson if (status < 0) 446688034c3dSAndy Adamson goto xdr_error; 446788034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 446888034c3dSAndy Adamson if (status < 0) 446988034c3dSAndy Adamson goto xdr_error; 447088034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 447188034c3dSAndy Adamson THRESHOLD_RD_IO); 447288034c3dSAndy Adamson if (status < 0) 447388034c3dSAndy Adamson goto xdr_error; 447488034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 447588034c3dSAndy Adamson THRESHOLD_WR_IO); 447688034c3dSAndy Adamson if (status < 0) 447788034c3dSAndy Adamson goto xdr_error; 447888034c3dSAndy Adamson 447988034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 448088034c3dSAndy Adamson res->bm = bitmap[0]; 448188034c3dSAndy Adamson 448288034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 448388034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 448488034c3dSAndy Adamson res->wr_io_sz); 448588034c3dSAndy Adamson xdr_error: 448688034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 448788034c3dSAndy Adamson return status; 448888034c3dSAndy Adamson } 448988034c3dSAndy Adamson 449088034c3dSAndy Adamson /* 449188034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 449288034c3dSAndy Adamson */ 449388034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 449488034c3dSAndy Adamson uint32_t *bitmap, 449588034c3dSAndy Adamson struct nfs4_threshold *res) 449688034c3dSAndy Adamson { 449788034c3dSAndy Adamson __be32 *p; 449888034c3dSAndy Adamson int status = 0; 449988034c3dSAndy Adamson uint32_t num; 450088034c3dSAndy Adamson 450188034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 450288034c3dSAndy Adamson return -EIO; 4503029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 45041549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 45051549210fSTrond Myklebust if (unlikely(res == NULL)) 45061549210fSTrond Myklebust return -EREMOTEIO; 450788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 450888034c3dSAndy Adamson if (unlikely(!p)) 450988034c3dSAndy Adamson goto out_overflow; 451088034c3dSAndy Adamson num = be32_to_cpup(p); 451188034c3dSAndy Adamson if (num == 0) 451288034c3dSAndy Adamson return 0; 451388034c3dSAndy Adamson if (num > 1) 451488034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 451588034c3dSAndy Adamson "drivers per filesystem not supported\n", 451688034c3dSAndy Adamson __func__); 451788034c3dSAndy Adamson 451888034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4519029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 452088034c3dSAndy Adamson } 452188034c3dSAndy Adamson return status; 452288034c3dSAndy Adamson out_overflow: 452388034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 452488034c3dSAndy Adamson return -EIO; 452588034c3dSAndy Adamson } 452688034c3dSAndy Adamson 4527ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4528ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4529aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 45306926afd1STrond Myklebust const struct nfs_server *server) 45311da177e4SLinus Torvalds { 4532bca79478STrond Myklebust int status; 4533bca79478STrond Myklebust umode_t fmode = 0; 4534ae42c70aSBryan Schumaker uint32_t type; 4535ee7b75fcSTrond Myklebust int32_t err; 45361da177e4SLinus Torvalds 4537f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4538f26c7a78STrond Myklebust if (status < 0) 45391da177e4SLinus Torvalds goto xdr_error; 4540409924e4STrond Myklebust fattr->mode = 0; 4541409924e4STrond Myklebust if (status != 0) { 4542409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4543409924e4STrond Myklebust fattr->valid |= status; 4544409924e4STrond Myklebust } 45451da177e4SLinus Torvalds 4546f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4547f26c7a78STrond Myklebust if (status < 0) 45481da177e4SLinus Torvalds goto xdr_error; 4549409924e4STrond Myklebust fattr->valid |= status; 4550f26c7a78STrond Myklebust 4551f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4552f26c7a78STrond Myklebust if (status < 0) 45531da177e4SLinus Torvalds goto xdr_error; 4554409924e4STrond Myklebust fattr->valid |= status; 4555f26c7a78STrond Myklebust 4556f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4557f26c7a78STrond Myklebust if (status < 0) 45581da177e4SLinus Torvalds goto xdr_error; 4559409924e4STrond Myklebust fattr->valid |= status; 4560f26c7a78STrond Myklebust 4561ee7b75fcSTrond Myklebust err = 0; 4562ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4563ae42c70aSBryan Schumaker if (status < 0) 4564ae42c70aSBryan Schumaker goto xdr_error; 4565ae42c70aSBryan Schumaker 4566ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4567ae42c70aSBryan Schumaker if (status < 0) 4568ae42c70aSBryan Schumaker goto xdr_error; 4569ae42c70aSBryan Schumaker 4570f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4571f26c7a78STrond Myklebust if (status < 0) 45721da177e4SLinus Torvalds goto xdr_error; 4573409924e4STrond Myklebust fattr->valid |= status; 4574f26c7a78STrond Myklebust 45758b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4576f26c7a78STrond Myklebust if (status < 0) 4577683b57b4STrond Myklebust goto xdr_error; 4578409924e4STrond Myklebust fattr->valid |= status; 4579f26c7a78STrond Myklebust 4580f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4581f26c7a78STrond Myklebust if (status < 0) 45821da177e4SLinus Torvalds goto xdr_error; 4583409924e4STrond Myklebust if (status != 0) { 45841da177e4SLinus Torvalds fattr->mode |= fmode; 4585409924e4STrond Myklebust fattr->valid |= status; 4586409924e4STrond Myklebust } 4587f26c7a78STrond Myklebust 4588f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4589f26c7a78STrond Myklebust if (status < 0) 45901da177e4SLinus Torvalds goto xdr_error; 4591409924e4STrond Myklebust fattr->valid |= status; 4592f26c7a78STrond Myklebust 45936926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4594f26c7a78STrond Myklebust if (status < 0) 45951da177e4SLinus Torvalds goto xdr_error; 4596409924e4STrond Myklebust fattr->valid |= status; 4597f26c7a78STrond Myklebust 45986926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4599f26c7a78STrond Myklebust if (status < 0) 46001da177e4SLinus Torvalds goto xdr_error; 4601409924e4STrond Myklebust fattr->valid |= status; 4602f26c7a78STrond Myklebust 4603f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4604f26c7a78STrond Myklebust if (status < 0) 46051da177e4SLinus Torvalds goto xdr_error; 4606409924e4STrond Myklebust fattr->valid |= status; 4607f26c7a78STrond Myklebust 4608f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4609f26c7a78STrond Myklebust if (status < 0) 46101da177e4SLinus Torvalds goto xdr_error; 4611409924e4STrond Myklebust fattr->valid |= status; 4612f26c7a78STrond Myklebust 4613f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4614f26c7a78STrond Myklebust if (status < 0) 46151da177e4SLinus Torvalds goto xdr_error; 4616409924e4STrond Myklebust fattr->valid |= status; 4617f26c7a78STrond Myklebust 4618f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4619f26c7a78STrond Myklebust if (status < 0) 46201da177e4SLinus Torvalds goto xdr_error; 4621409924e4STrond Myklebust fattr->valid |= status; 4622f26c7a78STrond Myklebust 4623f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4624f26c7a78STrond Myklebust if (status < 0) 46251da177e4SLinus Torvalds goto xdr_error; 4626409924e4STrond Myklebust fattr->valid |= status; 4627f26c7a78STrond Myklebust 462828331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4629f26c7a78STrond Myklebust if (status < 0) 463099baf625SManoj Naik goto xdr_error; 4631409924e4STrond Myklebust fattr->valid |= status; 4632f26c7a78STrond Myklebust 463388034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 463488034c3dSAndy Adamson if (status < 0) 463588034c3dSAndy Adamson goto xdr_error; 463688034c3dSAndy Adamson 4637aa9c2669SDavid Quigley if (label) { 4638aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4639aa9c2669SDavid Quigley if (status < 0) 4640aa9c2669SDavid Quigley goto xdr_error; 4641aa9c2669SDavid Quigley fattr->valid |= status; 4642aa9c2669SDavid Quigley } 4643aa9c2669SDavid Quigley 4644ae42c70aSBryan Schumaker xdr_error: 4645ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4646ae42c70aSBryan Schumaker return status; 4647ae42c70aSBryan Schumaker } 4648ae42c70aSBryan Schumaker 4649ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 46508b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4651aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4652ae42c70aSBryan Schumaker { 4653256e48bbSTrond Myklebust unsigned int savep; 4654ae42c70aSBryan Schumaker uint32_t attrlen, 4655dae100c2SFred Isaman bitmap[3] = {0}; 4656ae42c70aSBryan Schumaker int status; 4657ae42c70aSBryan Schumaker 4658ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4659ae42c70aSBryan Schumaker if (status < 0) 4660ae42c70aSBryan Schumaker goto xdr_error; 4661ae42c70aSBryan Schumaker 4662ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4663ae42c70aSBryan Schumaker if (status < 0) 4664ae42c70aSBryan Schumaker goto xdr_error; 4665ae42c70aSBryan Schumaker 4666ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4667ae42c70aSBryan Schumaker if (status < 0) 4668ae42c70aSBryan Schumaker goto xdr_error; 4669ae42c70aSBryan Schumaker 4670aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4671aa9c2669SDavid Quigley label, server); 4672ae42c70aSBryan Schumaker if (status < 0) 4673ae42c70aSBryan Schumaker goto xdr_error; 4674ae42c70aSBryan Schumaker 4675f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 46761da177e4SLinus Torvalds xdr_error: 46773110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 46781da177e4SLinus Torvalds return status; 46791da177e4SLinus Torvalds } 46801da177e4SLinus Torvalds 4681aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4682aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4683aa9c2669SDavid Quigley { 4684aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4685aa9c2669SDavid Quigley } 4686aa9c2669SDavid Quigley 4687ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 46886926afd1STrond Myklebust const struct nfs_server *server) 4689ae42c70aSBryan Schumaker { 4690aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4691ae42c70aSBryan Schumaker } 46921da177e4SLinus Torvalds 4693504913fbSAndy Adamson /* 4694504913fbSAndy Adamson * Decode potentially multiple layout types. Currently we only support 4695504913fbSAndy Adamson * one layout driver per file system. 4696504913fbSAndy Adamson */ 4697504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, 4698504913fbSAndy Adamson uint32_t *layouttype) 4699504913fbSAndy Adamson { 4700b8a8a0ddSTrond Myklebust __be32 *p; 4701504913fbSAndy Adamson int num; 4702504913fbSAndy Adamson 4703504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4704504913fbSAndy Adamson if (unlikely(!p)) 4705504913fbSAndy Adamson goto out_overflow; 4706504913fbSAndy Adamson num = be32_to_cpup(p); 4707504913fbSAndy Adamson 4708504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4709504913fbSAndy Adamson if (num == 0) { 4710504913fbSAndy Adamson *layouttype = 0; 4711504913fbSAndy Adamson return 0; 4712504913fbSAndy Adamson } 4713504913fbSAndy Adamson if (num > 1) 4714a030889aSWeston Andros Adamson printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout " 4715a030889aSWeston Andros Adamson "drivers per filesystem not supported\n", __func__); 4716504913fbSAndy Adamson 4717504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4718504913fbSAndy Adamson p = xdr_inline_decode(xdr, num * 4); 4719504913fbSAndy Adamson if (unlikely(!p)) 4720504913fbSAndy Adamson goto out_overflow; 4721504913fbSAndy Adamson *layouttype = be32_to_cpup(p); 4722504913fbSAndy Adamson return 0; 4723504913fbSAndy Adamson out_overflow: 4724504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4725504913fbSAndy Adamson return -EIO; 4726504913fbSAndy Adamson } 4727504913fbSAndy Adamson 4728504913fbSAndy Adamson /* 4729504913fbSAndy Adamson * The type of file system exported. 4730504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4731504913fbSAndy Adamson */ 4732504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4733504913fbSAndy Adamson uint32_t *layouttype) 4734504913fbSAndy Adamson { 4735504913fbSAndy Adamson int status = 0; 4736504913fbSAndy Adamson 4737504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4738504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4739504913fbSAndy Adamson return -EIO; 4740504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4741504913fbSAndy Adamson status = decode_first_pnfs_layout_type(xdr, layouttype); 4742504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 4743504913fbSAndy Adamson } else 4744504913fbSAndy Adamson *layouttype = 0; 4745504913fbSAndy Adamson return status; 4746504913fbSAndy Adamson } 4747504913fbSAndy Adamson 4748dae100c2SFred Isaman /* 4749dae100c2SFred Isaman * The prefered block size for layout directed io 4750dae100c2SFred Isaman */ 4751dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4752dae100c2SFred Isaman uint32_t *res) 4753dae100c2SFred Isaman { 4754dae100c2SFred Isaman __be32 *p; 4755dae100c2SFred Isaman 4756dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4757dae100c2SFred Isaman *res = 0; 4758dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4759dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4760dae100c2SFred Isaman if (unlikely(!p)) { 4761dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4762dae100c2SFred Isaman return -EIO; 4763dae100c2SFred Isaman } 4764dae100c2SFred Isaman *res = be32_to_cpup(p); 4765dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4766dae100c2SFred Isaman } 4767dae100c2SFred Isaman return 0; 4768dae100c2SFred Isaman } 4769dae100c2SFred Isaman 47701da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 47711da177e4SLinus Torvalds { 4772256e48bbSTrond Myklebust unsigned int savep; 4773dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 47741da177e4SLinus Torvalds int status; 47751da177e4SLinus Torvalds 47761da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 47771da177e4SLinus Torvalds goto xdr_error; 47781da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 47791da177e4SLinus Torvalds goto xdr_error; 47801da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 47811da177e4SLinus Torvalds goto xdr_error; 47821da177e4SLinus Torvalds 47831da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 47841da177e4SLinus Torvalds 47851da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 47861da177e4SLinus Torvalds goto xdr_error; 47871da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 47881da177e4SLinus Torvalds goto xdr_error; 47891da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 47901da177e4SLinus Torvalds goto xdr_error; 47911da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 47921da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 47931da177e4SLinus Torvalds goto xdr_error; 47941da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 479555b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 479655b6e774SRicardo Labiaga if (status != 0) 479755b6e774SRicardo Labiaga goto xdr_error; 4798504913fbSAndy Adamson status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); 4799504913fbSAndy Adamson if (status != 0) 4800504913fbSAndy Adamson goto xdr_error; 4801dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4802dae100c2SFred Isaman if (status) 4803dae100c2SFred Isaman goto xdr_error; 48041da177e4SLinus Torvalds 48051da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 48061da177e4SLinus Torvalds xdr_error: 48073110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 48081da177e4SLinus Torvalds return status; 48091da177e4SLinus Torvalds } 48101da177e4SLinus Torvalds 48111da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 48121da177e4SLinus Torvalds { 48138687b63aSAl Viro __be32 *p; 48141da177e4SLinus Torvalds uint32_t len; 48151da177e4SLinus Torvalds int status; 48161da177e4SLinus Torvalds 48179936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 48189936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 48199936781dSTrond Myklebust 48201da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 48211da177e4SLinus Torvalds if (status) 48221da177e4SLinus Torvalds return status; 48231da177e4SLinus Torvalds 4824c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4825c0eae66eSBenny Halevy if (unlikely(!p)) 4826c0eae66eSBenny Halevy goto out_overflow; 4827cccddf4fSBenny Halevy len = be32_to_cpup(p); 48281da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 48291da177e4SLinus Torvalds return -EIO; 48301da177e4SLinus Torvalds fh->size = len; 4831c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4832c0eae66eSBenny Halevy if (unlikely(!p)) 4833c0eae66eSBenny Halevy goto out_overflow; 483499398d06SBenny Halevy memcpy(fh->data, p, len); 48351da177e4SLinus Torvalds return 0; 4836c0eae66eSBenny Halevy out_overflow: 4837c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4838c0eae66eSBenny Halevy return -EIO; 48391da177e4SLinus Torvalds } 48401da177e4SLinus Torvalds 48411da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 48421da177e4SLinus Torvalds { 48431da177e4SLinus Torvalds int status; 48441da177e4SLinus Torvalds 48451da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 48461da177e4SLinus Torvalds if (status) 48471da177e4SLinus Torvalds return status; 48481da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 48491da177e4SLinus Torvalds } 48501da177e4SLinus Torvalds 48511da177e4SLinus Torvalds /* 48521da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 48531da177e4SLinus Torvalds */ 4854911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 48551da177e4SLinus Torvalds { 4856911d1aafSTrond Myklebust uint64_t offset, length, clientid; 48578687b63aSAl Viro __be32 *p; 4858911d1aafSTrond Myklebust uint32_t namelen, type; 48591da177e4SLinus Torvalds 4860babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4861c0eae66eSBenny Halevy if (unlikely(!p)) 4862c0eae66eSBenny Halevy goto out_overflow; 4863babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 48643ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4865babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4866babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4867911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4868911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4869911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4870911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4871911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4872911d1aafSTrond Myklebust if (type & 1) 4873911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4874911d1aafSTrond Myklebust fl->fl_pid = 0; 4875911d1aafSTrond Myklebust } 4876babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4877babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4878babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4879c0eae66eSBenny Halevy if (likely(p)) 48801da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4881c0eae66eSBenny Halevy out_overflow: 4882c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4883c0eae66eSBenny Halevy return -EIO; 48841da177e4SLinus Torvalds } 48851da177e4SLinus Torvalds 4886911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 48871da177e4SLinus Torvalds { 48881da177e4SLinus Torvalds int status; 48891da177e4SLinus Torvalds 48901da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4891c1d51931STrond Myklebust if (status == -EIO) 4892c1d51931STrond Myklebust goto out; 48931da177e4SLinus Torvalds if (status == 0) { 489407d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 489507d30434SBenny Halevy if (unlikely(status)) 489607d30434SBenny Halevy goto out; 48971da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4898c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4899c1d51931STrond Myklebust if (res->open_seqid != NULL) 4900c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4901c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4902c1d51931STrond Myklebust out: 49031da177e4SLinus Torvalds return status; 49041da177e4SLinus Torvalds } 49051da177e4SLinus Torvalds 4906911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 49071da177e4SLinus Torvalds { 49081da177e4SLinus Torvalds int status; 49091da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 49101da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4911911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 49121da177e4SLinus Torvalds return status; 49131da177e4SLinus Torvalds } 49141da177e4SLinus Torvalds 4915911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 49161da177e4SLinus Torvalds { 49171da177e4SLinus Torvalds int status; 49181da177e4SLinus Torvalds 49191da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4920c1d51931STrond Myklebust if (status != -EIO) 4921c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 492207d30434SBenny Halevy if (status == 0) 492307d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 49241da177e4SLinus Torvalds return status; 49251da177e4SLinus Torvalds } 49261da177e4SLinus Torvalds 4927d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4928d3c7b7ccSTrond Myklebust { 4929d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4930d3c7b7ccSTrond Myklebust } 4931d3c7b7ccSTrond Myklebust 49321da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 49331da177e4SLinus Torvalds { 49341da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 49351da177e4SLinus Torvalds } 49361da177e4SLinus Torvalds 49371da177e4SLinus Torvalds /* This is too sick! */ 49381da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 49391da177e4SLinus Torvalds { 49408687b63aSAl Viro __be32 *p; 49411da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 49421da177e4SLinus Torvalds 4943c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4944c0eae66eSBenny Halevy if (unlikely(!p)) 4945c0eae66eSBenny Halevy goto out_overflow; 49466f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 49471da177e4SLinus Torvalds switch (limit_type) { 49481da177e4SLinus Torvalds case 1: 4949cccddf4fSBenny Halevy xdr_decode_hyper(p, maxsize); 49501da177e4SLinus Torvalds break; 49511da177e4SLinus Torvalds case 2: 49526f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 4953cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 49541da177e4SLinus Torvalds *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 49551da177e4SLinus Torvalds } 49561da177e4SLinus Torvalds return 0; 4957c0eae66eSBenny Halevy out_overflow: 4958c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4959c0eae66eSBenny Halevy return -EIO; 49601da177e4SLinus Torvalds } 49611da177e4SLinus Torvalds 49621da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 49631da177e4SLinus Torvalds { 49648687b63aSAl Viro __be32 *p; 49651da177e4SLinus Torvalds uint32_t delegation_type; 496607d30434SBenny Halevy int status; 49671da177e4SLinus Torvalds 4968c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4969c0eae66eSBenny Halevy if (unlikely(!p)) 4970c0eae66eSBenny Halevy goto out_overflow; 4971cccddf4fSBenny Halevy delegation_type = be32_to_cpup(p); 49721da177e4SLinus Torvalds if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 49731da177e4SLinus Torvalds res->delegation_type = 0; 49741da177e4SLinus Torvalds return 0; 49751da177e4SLinus Torvalds } 497607d30434SBenny Halevy status = decode_stateid(xdr, &res->delegation); 497707d30434SBenny Halevy if (unlikely(status)) 497807d30434SBenny Halevy return status; 4979c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4980c0eae66eSBenny Halevy if (unlikely(!p)) 4981c0eae66eSBenny Halevy goto out_overflow; 4982cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 498305d564feSAndy Adamson 49841da177e4SLinus Torvalds switch (delegation_type) { 49851da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 49861da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 49871da177e4SLinus Torvalds break; 49881da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 49891da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 49901da177e4SLinus Torvalds if (decode_space_limit(xdr, &res->maxsize) < 0) 49911da177e4SLinus Torvalds return -EIO; 49921da177e4SLinus Torvalds } 49937539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 4994c0eae66eSBenny Halevy out_overflow: 4995c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4996c0eae66eSBenny Halevy return -EIO; 49971da177e4SLinus Torvalds } 49981da177e4SLinus Torvalds 49991da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 50001da177e4SLinus Torvalds { 50018687b63aSAl Viro __be32 *p; 5002aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 50031da177e4SLinus Torvalds int status; 50041da177e4SLinus Torvalds 50051da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN); 5006c1d51931STrond Myklebust if (status != -EIO) 5007c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 500807d30434SBenny Halevy if (!status) 500907d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 501007d30434SBenny Halevy if (unlikely(status)) 50111da177e4SLinus Torvalds return status; 50121da177e4SLinus Torvalds 50131da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 50141da177e4SLinus Torvalds 5015c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5016c0eae66eSBenny Halevy if (unlikely(!p)) 5017c0eae66eSBenny Halevy goto out_overflow; 50186f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5019cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 50201da177e4SLinus Torvalds if (bmlen > 10) 50211da177e4SLinus Torvalds goto xdr_error; 50221da177e4SLinus Torvalds 5023c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5024c0eae66eSBenny Halevy if (unlikely(!p)) 5025c0eae66eSBenny Halevy goto out_overflow; 5026aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5027aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 50286f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5029aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5030aa53ed54SJeff Layton res->attrset[i] = 0; 5031aa53ed54SJeff Layton 50321da177e4SLinus Torvalds return decode_delegation(xdr, res); 50331da177e4SLinus Torvalds xdr_error: 50343110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 50351da177e4SLinus Torvalds return -EIO; 5036c0eae66eSBenny Halevy out_overflow: 5037c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5038c0eae66eSBenny Halevy return -EIO; 50391da177e4SLinus Torvalds } 50401da177e4SLinus Torvalds 50411da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 50421da177e4SLinus Torvalds { 50431da177e4SLinus Torvalds int status; 50441da177e4SLinus Torvalds 50451da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5046c1d51931STrond Myklebust if (status != -EIO) 5047c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 504807d30434SBenny Halevy if (!status) 504907d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 50501da177e4SLinus Torvalds return status; 50511da177e4SLinus Torvalds } 50521da177e4SLinus Torvalds 50531da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 50541da177e4SLinus Torvalds { 50551da177e4SLinus Torvalds int status; 50561da177e4SLinus Torvalds 50571da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5058c1d51931STrond Myklebust if (status != -EIO) 5059c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 506007d30434SBenny Halevy if (!status) 506107d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 50621da177e4SLinus Torvalds return status; 50631da177e4SLinus Torvalds } 50641da177e4SLinus Torvalds 50651da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 50661da177e4SLinus Torvalds { 50671da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 50681da177e4SLinus Torvalds } 50691da177e4SLinus Torvalds 50701da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 50711da177e4SLinus Torvalds { 50721da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 50731da177e4SLinus Torvalds } 50741da177e4SLinus Torvalds 50751da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res) 50761da177e4SLinus Torvalds { 50778687b63aSAl Viro __be32 *p; 507864bd577eSTrond Myklebust uint32_t count, eof, recvd; 50791da177e4SLinus Torvalds int status; 50801da177e4SLinus Torvalds 50811da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 50821da177e4SLinus Torvalds if (status) 50831da177e4SLinus Torvalds return status; 5084c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5085c0eae66eSBenny Halevy if (unlikely(!p)) 5086c0eae66eSBenny Halevy goto out_overflow; 50876f723f77SBenny Halevy eof = be32_to_cpup(p++); 5088cccddf4fSBenny Halevy count = be32_to_cpup(p); 508964bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 50901da177e4SLinus Torvalds if (count > recvd) { 5091fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 50921da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 50931da177e4SLinus Torvalds count = recvd; 50941da177e4SLinus Torvalds eof = 0; 50951da177e4SLinus Torvalds } 50961da177e4SLinus Torvalds res->eof = eof; 50971da177e4SLinus Torvalds res->count = count; 50981da177e4SLinus Torvalds return 0; 5099c0eae66eSBenny Halevy out_overflow: 5100c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5101c0eae66eSBenny Halevy return -EIO; 51021da177e4SLinus Torvalds } 51031da177e4SLinus Torvalds 51041da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 51051da177e4SLinus Torvalds { 5106bcecff77SChuck Lever int status; 5107cd93710eSChuck Lever __be32 verf[2]; 51081da177e4SLinus Torvalds 51091da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5110db942bbdSBenny Halevy if (!status) 5111db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5112db942bbdSBenny Halevy if (unlikely(status)) 51131da177e4SLinus Torvalds return status; 5114cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 511544109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5116cd93710eSChuck Lever __func__, verf[0], verf[1]); 511764bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 51181da177e4SLinus Torvalds } 51191da177e4SLinus Torvalds 51201da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 51211da177e4SLinus Torvalds { 51221da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5123bcecff77SChuck Lever u32 len, recvd; 51248687b63aSAl Viro __be32 *p; 51251da177e4SLinus Torvalds int status; 51261da177e4SLinus Torvalds 51271da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 51281da177e4SLinus Torvalds if (status) 51291da177e4SLinus Torvalds return status; 51301da177e4SLinus Torvalds 51311da177e4SLinus Torvalds /* Convert length of symlink */ 5132c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5133c0eae66eSBenny Halevy if (unlikely(!p)) 5134c0eae66eSBenny Halevy goto out_overflow; 5135cccddf4fSBenny Halevy len = be32_to_cpup(p); 51361da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5137fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 51381da177e4SLinus Torvalds return -ENAMETOOLONG; 51391da177e4SLinus Torvalds } 514064bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 51411da177e4SLinus Torvalds if (recvd < len) { 5142fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 51431da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 51441da177e4SLinus Torvalds return -EIO; 51451da177e4SLinus Torvalds } 51461da177e4SLinus Torvalds /* 51471da177e4SLinus Torvalds * The XDR encode routine has set things up so that 51481da177e4SLinus Torvalds * the link text will be copied directly into the 51491da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 51501da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 51511da177e4SLinus Torvalds * null-termination). 51521da177e4SLinus Torvalds */ 5153b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 51541da177e4SLinus Torvalds return 0; 5155c0eae66eSBenny Halevy out_overflow: 5156c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5157c0eae66eSBenny Halevy return -EIO; 51581da177e4SLinus Torvalds } 51591da177e4SLinus Torvalds 51601da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 51611da177e4SLinus Torvalds { 51621da177e4SLinus Torvalds int status; 51631da177e4SLinus Torvalds 51641da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 51651da177e4SLinus Torvalds if (status) 51661da177e4SLinus Torvalds goto out; 51671da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 51681da177e4SLinus Torvalds out: 51691da177e4SLinus Torvalds return status; 51701da177e4SLinus Torvalds } 51711da177e4SLinus Torvalds 51721da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 51731da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 51741da177e4SLinus Torvalds { 51751da177e4SLinus Torvalds int status; 51761da177e4SLinus Torvalds 51771da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 51781da177e4SLinus Torvalds if (status) 51791da177e4SLinus Torvalds goto out; 51801da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 51811da177e4SLinus Torvalds goto out; 51821da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 51831da177e4SLinus Torvalds out: 51841da177e4SLinus Torvalds return status; 51851da177e4SLinus Torvalds } 51861da177e4SLinus Torvalds 51871da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 51881da177e4SLinus Torvalds { 51891da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 51901da177e4SLinus Torvalds } 51911da177e4SLinus Torvalds 519256ae19f3STrond Myklebust static int 519356ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 519456ae19f3STrond Myklebust { 519556ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 519656ae19f3STrond Myklebust } 519756ae19f3STrond Myklebust 5198029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5199bf118a34SAndy Adamson struct nfs_getaclres *res) 5200029d105eSJ. Bruce Fields { 5201256e48bbSTrond Myklebust unsigned int savep; 5202029d105eSJ. Bruce Fields uint32_t attrlen, 5203dae100c2SFred Isaman bitmap[3] = {0}; 5204029d105eSJ. Bruce Fields int status; 5205cff298c7STrond Myklebust unsigned int pg_offset; 5206029d105eSJ. Bruce Fields 5207bf118a34SAndy Adamson res->acl_len = 0; 5208029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5209029d105eSJ. Bruce Fields goto out; 52105a006899SSachin Prabhu 5211519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5212519d3959STrond Myklebust 5213cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5214cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 52155a006899SSachin Prabhu 5216029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5217029d105eSJ. Bruce Fields goto out; 5218029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5219029d105eSJ. Bruce Fields goto out; 5220029d105eSJ. Bruce Fields 5221029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5222029d105eSJ. Bruce Fields return -EIO; 5223029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5224029d105eSJ. Bruce Fields 5225bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5226bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5227bf118a34SAndy Adamson * variable length bitmaps.*/ 5228cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5229519d3959STrond Myklebust res->acl_len = attrlen; 52301f1ea6c2STrond Myklebust 52311f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 52321f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 52331f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 52341f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5235519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5236cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5237029d105eSJ. Bruce Fields } 52388c233cf9SJ. Bruce Fields } else 52398c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5240029d105eSJ. Bruce Fields 5241029d105eSJ. Bruce Fields out: 5242029d105eSJ. Bruce Fields return status; 5243029d105eSJ. Bruce Fields } 5244029d105eSJ. Bruce Fields 52451da177e4SLinus Torvalds static int 52461da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 52471da177e4SLinus Torvalds { 52481da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 52491da177e4SLinus Torvalds } 52501da177e4SLinus Torvalds 52519e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 52521da177e4SLinus Torvalds { 52538687b63aSAl Viro __be32 *p; 52541da177e4SLinus Torvalds uint32_t bmlen; 52551da177e4SLinus Torvalds int status; 52561da177e4SLinus Torvalds 52571da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 52581da177e4SLinus Torvalds if (status) 52591da177e4SLinus Torvalds return status; 5260c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5261c0eae66eSBenny Halevy if (unlikely(!p)) 5262c0eae66eSBenny Halevy goto out_overflow; 5263cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5264c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5265c0eae66eSBenny Halevy if (likely(p)) 52661da177e4SLinus Torvalds return 0; 5267c0eae66eSBenny Halevy out_overflow: 5268c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5269c0eae66eSBenny Halevy return -EIO; 52701da177e4SLinus Torvalds } 52711da177e4SLinus Torvalds 5272bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 52731da177e4SLinus Torvalds { 52748687b63aSAl Viro __be32 *p; 52751da177e4SLinus Torvalds uint32_t opnum; 52761da177e4SLinus Torvalds int32_t nfserr; 52771da177e4SLinus Torvalds 5278c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5279c0eae66eSBenny Halevy if (unlikely(!p)) 5280c0eae66eSBenny Halevy goto out_overflow; 52816f723f77SBenny Halevy opnum = be32_to_cpup(p++); 52821da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5283fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 52841da177e4SLinus Torvalds " %d\n", opnum); 52851da177e4SLinus Torvalds return -EIO; 52861da177e4SLinus Torvalds } 5287cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 52881da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5289c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5290c0eae66eSBenny Halevy if (unlikely(!p)) 5291c0eae66eSBenny Halevy goto out_overflow; 5292bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5293bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 52941da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 52951da177e4SLinus Torvalds uint32_t len; 52961da177e4SLinus Torvalds 52971da177e4SLinus Torvalds /* skip netid string */ 5298c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5299c0eae66eSBenny Halevy if (unlikely(!p)) 5300c0eae66eSBenny Halevy goto out_overflow; 5301cccddf4fSBenny Halevy len = be32_to_cpup(p); 5302c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5303c0eae66eSBenny Halevy if (unlikely(!p)) 5304c0eae66eSBenny Halevy goto out_overflow; 53051da177e4SLinus Torvalds 53061da177e4SLinus Torvalds /* skip uaddr string */ 5307c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5308c0eae66eSBenny Halevy if (unlikely(!p)) 5309c0eae66eSBenny Halevy goto out_overflow; 5310cccddf4fSBenny Halevy len = be32_to_cpup(p); 5311c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5312c0eae66eSBenny Halevy if (unlikely(!p)) 5313c0eae66eSBenny Halevy goto out_overflow; 53141da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 53151da177e4SLinus Torvalds } else 5316856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 53171da177e4SLinus Torvalds 53181da177e4SLinus Torvalds return 0; 5319c0eae66eSBenny Halevy out_overflow: 5320c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5321c0eae66eSBenny Halevy return -EIO; 53221da177e4SLinus Torvalds } 53231da177e4SLinus Torvalds 53241da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 53251da177e4SLinus Torvalds { 53261da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 53271da177e4SLinus Torvalds } 53281da177e4SLinus Torvalds 53291da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res) 53301da177e4SLinus Torvalds { 53318687b63aSAl Viro __be32 *p; 53321da177e4SLinus Torvalds int status; 53331da177e4SLinus Torvalds 53341da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 53351da177e4SLinus Torvalds if (status) 53361da177e4SLinus Torvalds return status; 53371da177e4SLinus Torvalds 53382f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5339c0eae66eSBenny Halevy if (unlikely(!p)) 5340c0eae66eSBenny Halevy goto out_overflow; 53416f723f77SBenny Halevy res->count = be32_to_cpup(p++); 53426f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 53432f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5344c0eae66eSBenny Halevy out_overflow: 5345c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5346c0eae66eSBenny Halevy return -EIO; 53471da177e4SLinus Torvalds } 53481da177e4SLinus Torvalds 53491da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 53501da177e4SLinus Torvalds { 53511da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 53521da177e4SLinus Torvalds } 53531da177e4SLinus Torvalds 5354fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5355fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 53565a5ea0d4SBryan Schumaker { 5357fb15b26fSChuck Lever u32 oid_len; 53585a5ea0d4SBryan Schumaker __be32 *p; 53595a5ea0d4SBryan Schumaker 53605a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 53615a5ea0d4SBryan Schumaker if (unlikely(!p)) 53625a5ea0d4SBryan Schumaker goto out_overflow; 5363fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5364fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 53655a5ea0d4SBryan Schumaker goto out_err; 53665a5ea0d4SBryan Schumaker 5367fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 53685a5ea0d4SBryan Schumaker if (unlikely(!p)) 53695a5ea0d4SBryan Schumaker goto out_overflow; 5370fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5371fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 53725a5ea0d4SBryan Schumaker 53735a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 53745a5ea0d4SBryan Schumaker if (unlikely(!p)) 53755a5ea0d4SBryan Schumaker goto out_overflow; 5376fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5377fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 53785a5ea0d4SBryan Schumaker 53795a5ea0d4SBryan Schumaker return 0; 53805a5ea0d4SBryan Schumaker 53815a5ea0d4SBryan Schumaker out_overflow: 53825a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 53835a5ea0d4SBryan Schumaker return -EIO; 53845a5ea0d4SBryan Schumaker out_err: 53855a5ea0d4SBryan Schumaker return -EINVAL; 53865a5ea0d4SBryan Schumaker } 53875a5ea0d4SBryan Schumaker 538831e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 53895a5ea0d4SBryan Schumaker { 5390fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5391fb15b26fSChuck Lever unsigned int i, num_flavors; 53925a5ea0d4SBryan Schumaker int status; 53935a5ea0d4SBryan Schumaker __be32 *p; 53945a5ea0d4SBryan Schumaker 53955a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 53965a5ea0d4SBryan Schumaker if (unlikely(!p)) 53975a5ea0d4SBryan Schumaker goto out_overflow; 53985a5ea0d4SBryan Schumaker 5399c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5400c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5401c3dfc280SBryan Schumaker 5402c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 54035a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5404c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 54055a5ea0d4SBryan Schumaker break; 54065a5ea0d4SBryan Schumaker 54075a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 54085a5ea0d4SBryan Schumaker if (unlikely(!p)) 54095a5ea0d4SBryan Schumaker goto out_overflow; 54105a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 54115a5ea0d4SBryan Schumaker 54125a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5413613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5414613e901eSBryan Schumaker if (status) 5415613e901eSBryan Schumaker goto out; 54165a5ea0d4SBryan Schumaker } 5417c3dfc280SBryan Schumaker res->flavors->num_flavors++; 54185a5ea0d4SBryan Schumaker } 54195a5ea0d4SBryan Schumaker 542031e4dda4SBryan Schumaker status = 0; 5421613e901eSBryan Schumaker out: 5422613e901eSBryan Schumaker return status; 54235a5ea0d4SBryan Schumaker out_overflow: 54245a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 54255a5ea0d4SBryan Schumaker return -EIO; 54265a5ea0d4SBryan Schumaker } 54275a5ea0d4SBryan Schumaker 542831e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 542931e4dda4SBryan Schumaker { 543031e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 543131e4dda4SBryan Schumaker if (status) 543231e4dda4SBryan Schumaker return status; 543331e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 543431e4dda4SBryan Schumaker } 543531e4dda4SBryan Schumaker 543699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 543731e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 543831e4dda4SBryan Schumaker { 543931e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 544031e4dda4SBryan Schumaker if (status) 544131e4dda4SBryan Schumaker return status; 544231e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 544331e4dda4SBryan Schumaker } 544431e4dda4SBryan Schumaker 54452031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 54462031cd1aSWeston Andros Adamson { 54472031cd1aSWeston Andros Adamson __be32 *p; 54482031cd1aSWeston Andros Adamson uint32_t bitmap_words; 54492031cd1aSWeston Andros Adamson unsigned int i; 54502031cd1aSWeston Andros Adamson 54512031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 54522031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 54532031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 54542031cd1aSWeston Andros Adamson return -EIO; 54552031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 54562031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 54572031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 54582031cd1aSWeston Andros Adamson 54592031cd1aSWeston Andros Adamson return 0; 54602031cd1aSWeston Andros Adamson } 54612031cd1aSWeston Andros Adamson 546299fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 546399fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 546499fe60d0SBenny Halevy { 546599fe60d0SBenny Halevy __be32 *p; 546699fe60d0SBenny Halevy uint32_t dummy; 54672460ba57SBenny Halevy char *dummy_str; 546899fe60d0SBenny Halevy int status; 54697d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 547099fe60d0SBenny Halevy 547199fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 547299fe60d0SBenny Halevy if (status) 547399fe60d0SBenny Halevy return status; 547499fe60d0SBenny Halevy 5475c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5476c0eae66eSBenny Halevy if (unlikely(!p)) 5477c0eae66eSBenny Halevy goto out_overflow; 547832b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5479c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5480c0eae66eSBenny Halevy if (unlikely(!p)) 5481c0eae66eSBenny Halevy goto out_overflow; 548232b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 548332b01310STrond Myklebust res->flags = be32_to_cpup(p++); 548499fe60d0SBenny Halevy 54852031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 54862031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 54872031cd1aSWeston Andros Adamson case SP4_NONE: 54882031cd1aSWeston Andros Adamson break; 54892031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 54902031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 54912031cd1aSWeston Andros Adamson if (status) 54922031cd1aSWeston Andros Adamson return status; 54932031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 54942031cd1aSWeston Andros Adamson if (status) 54952031cd1aSWeston Andros Adamson return status; 54962031cd1aSWeston Andros Adamson break; 54972031cd1aSWeston Andros Adamson default: 54982031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 549999fe60d0SBenny Halevy return -EIO; 55002031cd1aSWeston Andros Adamson } 550199fe60d0SBenny Halevy 5502acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5503c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5504c0eae66eSBenny Halevy if (unlikely(!p)) 5505c0eae66eSBenny Halevy goto out_overflow; 5506acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 550799fe60d0SBenny Halevy 5508acdeb69dSChuck Lever /* server_owner4.so_major_id */ 55092460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55102460ba57SBenny Halevy if (unlikely(status)) 55112460ba57SBenny Halevy return status; 551278fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 551378fe0f41SWeston Andros Adamson return -EIO; 5514acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5515acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 551678fe0f41SWeston Andros Adamson 5517acdeb69dSChuck Lever /* server_scope4 */ 5518acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5519acdeb69dSChuck Lever if (unlikely(status)) 5520acdeb69dSChuck Lever return status; 5521acdeb69dSChuck Lever if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 5522acdeb69dSChuck Lever return -EIO; 552378fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 552478fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 552578fe0f41SWeston Andros Adamson 55267d2ed9acSWeston Andros Adamson /* Implementation Id */ 55277d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 55287d2ed9acSWeston Andros Adamson if (unlikely(!p)) 55297d2ed9acSWeston Andros Adamson goto out_overflow; 55307d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 55317d2ed9acSWeston Andros Adamson 55327d2ed9acSWeston Andros Adamson if (impl_id_count) { 55337d2ed9acSWeston Andros Adamson /* nii_domain */ 55342460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55352460ba57SBenny Halevy if (unlikely(status)) 55362460ba57SBenny Halevy return status; 55377d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 55387d2ed9acSWeston Andros Adamson return -EIO; 55397d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 554099fe60d0SBenny Halevy 55417d2ed9acSWeston Andros Adamson /* nii_name */ 55427d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55437d2ed9acSWeston Andros Adamson if (unlikely(status)) 55447d2ed9acSWeston Andros Adamson return status; 55457d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 55467d2ed9acSWeston Andros Adamson return -EIO; 55477d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 55487d2ed9acSWeston Andros Adamson 55497d2ed9acSWeston Andros Adamson /* nii_date */ 55507d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 55517d2ed9acSWeston Andros Adamson if (unlikely(!p)) 55527d2ed9acSWeston Andros Adamson goto out_overflow; 55537d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 55547d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 55557d2ed9acSWeston Andros Adamson 55567d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 55577d2ed9acSWeston Andros Adamson } 555899fe60d0SBenny Halevy return 0; 5559c0eae66eSBenny Halevy out_overflow: 5560c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5561c0eae66eSBenny Halevy return -EIO; 556299fe60d0SBenny Halevy } 5563fc931582SAndy Adamson 5564fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5565fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5566fc931582SAndy Adamson { 5567fc931582SAndy Adamson __be32 *p; 5568c9c30dd5SBenny Halevy u32 nr_attrs, val; 5569fc931582SAndy Adamson 5570c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5571c0eae66eSBenny Halevy if (unlikely(!p)) 5572c0eae66eSBenny Halevy goto out_overflow; 5573c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5574c9c30dd5SBenny Halevy if (val) 5575c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 55766f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 55776f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 55786f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 55796f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 55806f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5581cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5582fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5583a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5584a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5585fc931582SAndy Adamson return -EINVAL; 5586fc931582SAndy Adamson } 5587c0eae66eSBenny Halevy if (nr_attrs == 1) { 5588c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5589c0eae66eSBenny Halevy if (unlikely(!p)) 5590c0eae66eSBenny Halevy goto out_overflow; 5591c0eae66eSBenny Halevy } 5592fc931582SAndy Adamson return 0; 5593c0eae66eSBenny Halevy out_overflow: 5594c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5595c0eae66eSBenny Halevy return -EIO; 5596fc931582SAndy Adamson } 5597fc931582SAndy Adamson 5598e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5599e78291e4SBenny Halevy { 5600e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5601fc931582SAndy Adamson } 5602fc931582SAndy Adamson 56037c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 56047c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 56057c44f1aeSWeston Andros Adamson { 56067c44f1aeSWeston Andros Adamson __be32 *p; 56077c44f1aeSWeston Andros Adamson int status; 56087c44f1aeSWeston Andros Adamson 56097c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 56107c44f1aeSWeston Andros Adamson if (!status) 56117c44f1aeSWeston Andros Adamson status = decode_sessionid(xdr, &res->session->sess_id); 56127c44f1aeSWeston Andros Adamson if (unlikely(status)) 56137c44f1aeSWeston Andros Adamson return status; 56147c44f1aeSWeston Andros Adamson 56157c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 56167c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 56177c44f1aeSWeston Andros Adamson if (unlikely(!p)) 56187c44f1aeSWeston Andros Adamson goto out_overflow; 56197c44f1aeSWeston Andros Adamson 56207c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 56217c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 56227c44f1aeSWeston Andros Adamson return -EIO; 56237c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 56247c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 56257c44f1aeSWeston Andros Adamson else 56267c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 56277c44f1aeSWeston Andros Adamson 56287c44f1aeSWeston Andros Adamson return 0; 56297c44f1aeSWeston Andros Adamson out_overflow: 56307c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 56317c44f1aeSWeston Andros Adamson return -EIO; 56327c44f1aeSWeston Andros Adamson } 56337c44f1aeSWeston Andros Adamson 5634fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5635fc931582SAndy Adamson struct nfs41_create_session_res *res) 5636fc931582SAndy Adamson { 5637fc931582SAndy Adamson __be32 *p; 5638fc931582SAndy Adamson int status; 5639fc931582SAndy Adamson struct nfs_client *clp = res->client; 5640fc931582SAndy Adamson struct nfs4_session *session = clp->cl_session; 5641fc931582SAndy Adamson 5642fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5643e78291e4SBenny Halevy if (!status) 5644e78291e4SBenny Halevy status = decode_sessionid(xdr, &session->sess_id); 5645e78291e4SBenny Halevy if (unlikely(status)) 5646fc931582SAndy Adamson return status; 5647fc931582SAndy Adamson 5648fc931582SAndy Adamson /* seqid, flags */ 5649c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5650c0eae66eSBenny Halevy if (unlikely(!p)) 5651c0eae66eSBenny Halevy goto out_overflow; 56526f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 5653cccddf4fSBenny Halevy session->flags = be32_to_cpup(p); 5654fc931582SAndy Adamson 5655fc931582SAndy Adamson /* Channel attributes */ 5656fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->fc_attrs); 5657fc931582SAndy Adamson if (!status) 5658fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->bc_attrs); 5659fc931582SAndy Adamson return status; 5660c0eae66eSBenny Halevy out_overflow: 5661c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5662c0eae66eSBenny Halevy return -EIO; 5663fc931582SAndy Adamson } 56640f3e66c6SAndy Adamson 56650f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 56660f3e66c6SAndy Adamson { 56670f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 56680f3e66c6SAndy Adamson } 566918019753SRicardo Labiaga 567066245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 567166245539STrond Myklebust { 567266245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 567366245539STrond Myklebust } 567466245539STrond Myklebust 567518019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 567618019753SRicardo Labiaga { 567718019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 567818019753SRicardo Labiaga } 567999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 568099fe60d0SBenny Halevy 56819b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 56829b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 56839b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 56849b7b9fccSAndy Adamson { 56859b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5686e3725ec0STrond Myklebust struct nfs4_session *session; 5687fc01cea9SAndy Adamson struct nfs4_sessionid id; 5688fc01cea9SAndy Adamson u32 dummy; 5689fc01cea9SAndy Adamson int status; 5690fc01cea9SAndy Adamson __be32 *p; 5691fc01cea9SAndy Adamson 5692e3725ec0STrond Myklebust if (res->sr_slot == NULL) 56939b7b9fccSAndy Adamson return 0; 56943bd2384aSChuck Lever if (!res->sr_slot->table->session) 56953bd2384aSChuck Lever return 0; 56969b7b9fccSAndy Adamson 5697fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5698e78291e4SBenny Halevy if (!status) 5699e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5700e78291e4SBenny Halevy if (unlikely(status)) 5701fc01cea9SAndy Adamson goto out_err; 57029b7b9fccSAndy Adamson 5703fc01cea9SAndy Adamson /* 5704fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5705fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5706fc01cea9SAndy Adamson */ 5707fdcb4577STrond Myklebust status = -EREMOTEIO; 5708e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5709fc01cea9SAndy Adamson 5710e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5711fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5712fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5713fc01cea9SAndy Adamson goto out_err; 5714fc01cea9SAndy Adamson } 5715e78291e4SBenny Halevy 5716c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5717c0eae66eSBenny Halevy if (unlikely(!p)) 5718c0eae66eSBenny Halevy goto out_overflow; 5719e78291e4SBenny Halevy 5720fc01cea9SAndy Adamson /* seqid */ 57216f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5722dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5723fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5724fc01cea9SAndy Adamson goto out_err; 5725fc01cea9SAndy Adamson } 5726fc01cea9SAndy Adamson /* slot id */ 57276f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5728df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5729fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5730fc01cea9SAndy Adamson goto out_err; 5731fc01cea9SAndy Adamson } 5732da0507b7STrond Myklebust /* highest slot id */ 5733da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5734464ee9f9STrond Myklebust /* target highest slot id */ 5735464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 57360629e370SAlexandros Batsakis /* result flags */ 57370629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5738fc01cea9SAndy Adamson status = 0; 5739fc01cea9SAndy Adamson out_err: 5740fc01cea9SAndy Adamson res->sr_status = status; 5741fc01cea9SAndy Adamson return status; 5742c0eae66eSBenny Halevy out_overflow: 5743c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5744c0eae66eSBenny Halevy status = -EIO; 5745c0eae66eSBenny Halevy goto out_err; 5746fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 57479b7b9fccSAndy Adamson return 0; 5748fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 57499b7b9fccSAndy Adamson } 57509b7b9fccSAndy Adamson 5751b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 57527f11d8d3SAndy Adamson /* 57537f11d8d3SAndy Adamson * TODO: Need to handle case when EOF != true; 57547f11d8d3SAndy Adamson */ 57557f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr, 57567f11d8d3SAndy Adamson struct pnfs_devicelist *res) 57577f11d8d3SAndy Adamson { 57587f11d8d3SAndy Adamson __be32 *p; 57597f11d8d3SAndy Adamson int status, i; 576098d94524STrond Myklebust nfs4_verifier verftemp; 57617f11d8d3SAndy Adamson 57627f11d8d3SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICELIST); 57637f11d8d3SAndy Adamson if (status) 57647f11d8d3SAndy Adamson return status; 57657f11d8d3SAndy Adamson 57667f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 8 + 8 + 4); 57677f11d8d3SAndy Adamson if (unlikely(!p)) 57687f11d8d3SAndy Adamson goto out_overflow; 57697f11d8d3SAndy Adamson 57707f11d8d3SAndy Adamson /* TODO: Skip cookie for now */ 57717f11d8d3SAndy Adamson p += 2; 57727f11d8d3SAndy Adamson 57737f11d8d3SAndy Adamson /* Read verifier */ 577498d94524STrond Myklebust p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE); 57757f11d8d3SAndy Adamson 57767f11d8d3SAndy Adamson res->num_devs = be32_to_cpup(p); 57777f11d8d3SAndy Adamson 57787f11d8d3SAndy Adamson dprintk("%s: num_dev %d\n", __func__, res->num_devs); 57797f11d8d3SAndy Adamson 57807f11d8d3SAndy Adamson if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5781a030889aSWeston Andros Adamson printk(KERN_ERR "NFS: %s too many result dev_num %u\n", 57827f11d8d3SAndy Adamson __func__, res->num_devs); 57837f11d8d3SAndy Adamson return -EIO; 57847f11d8d3SAndy Adamson } 57857f11d8d3SAndy Adamson 57867f11d8d3SAndy Adamson p = xdr_inline_decode(xdr, 57877f11d8d3SAndy Adamson res->num_devs * NFS4_DEVICEID4_SIZE + 4); 57887f11d8d3SAndy Adamson if (unlikely(!p)) 57897f11d8d3SAndy Adamson goto out_overflow; 57907f11d8d3SAndy Adamson for (i = 0; i < res->num_devs; i++) 57917f11d8d3SAndy Adamson p = xdr_decode_opaque_fixed(p, res->dev_id[i].data, 57927f11d8d3SAndy Adamson NFS4_DEVICEID4_SIZE); 57937f11d8d3SAndy Adamson res->eof = be32_to_cpup(p); 57947f11d8d3SAndy Adamson return 0; 57957f11d8d3SAndy Adamson out_overflow: 57967f11d8d3SAndy Adamson print_overflow_msg(__func__, xdr); 57977f11d8d3SAndy Adamson return -EIO; 57987f11d8d3SAndy Adamson } 5799b1f69b75SAndy Adamson 5800b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 5801b1f69b75SAndy Adamson struct pnfs_device *pdev) 5802b1f69b75SAndy Adamson { 5803b1f69b75SAndy Adamson __be32 *p; 5804b1f69b75SAndy Adamson uint32_t len, type; 5805b1f69b75SAndy Adamson int status; 5806b1f69b75SAndy Adamson 5807b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5808b1f69b75SAndy Adamson if (status) { 5809b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5810b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5811b1f69b75SAndy Adamson if (unlikely(!p)) 5812b1f69b75SAndy Adamson goto out_overflow; 5813b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5814b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5815b1f69b75SAndy Adamson __func__, pdev->mincount); 5816b1f69b75SAndy Adamson } 5817b1f69b75SAndy Adamson return status; 5818b1f69b75SAndy Adamson } 5819b1f69b75SAndy Adamson 5820b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5821b1f69b75SAndy Adamson if (unlikely(!p)) 5822b1f69b75SAndy Adamson goto out_overflow; 5823b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5824b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5825b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5826b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5827b1f69b75SAndy Adamson return -EINVAL; 5828b1f69b75SAndy Adamson } 5829b1f69b75SAndy Adamson /* 5830b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5831b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5832b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5833b1f69b75SAndy Adamson */ 5834b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 583513fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 583613fe4ba1STrond Myklebust goto out_overflow; 5837b1f69b75SAndy Adamson 5838b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5839b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5840b1f69b75SAndy Adamson if (unlikely(!p)) 5841b1f69b75SAndy Adamson goto out_overflow; 5842b1f69b75SAndy Adamson len = be32_to_cpup(p); 5843b1f69b75SAndy Adamson if (len) { 5844ead00597SChuck Lever uint32_t i; 5845b1f69b75SAndy Adamson 5846b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5847b1f69b75SAndy Adamson if (unlikely(!p)) 5848b1f69b75SAndy Adamson goto out_overflow; 5849b1f69b75SAndy Adamson for (i = 0; i < len; i++, p++) { 5850b1f69b75SAndy Adamson if (be32_to_cpup(p)) { 5851b1f69b75SAndy Adamson dprintk("%s: notifications not supported\n", 5852b1f69b75SAndy Adamson __func__); 5853b1f69b75SAndy Adamson return -EIO; 5854b1f69b75SAndy Adamson } 5855b1f69b75SAndy Adamson } 5856b1f69b75SAndy Adamson } 5857b1f69b75SAndy Adamson return 0; 5858b1f69b75SAndy Adamson out_overflow: 5859b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5860b1f69b75SAndy Adamson return -EIO; 5861b1f69b75SAndy Adamson } 5862b1f69b75SAndy Adamson 5863b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5864b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5865b1f69b75SAndy Adamson { 5866b1f69b75SAndy Adamson __be32 *p; 5867b1f69b75SAndy Adamson int status; 5868b1f69b75SAndy Adamson u32 layout_count; 586964bd577eSTrond Myklebust u32 recvd; 5870b1f69b75SAndy Adamson 5871b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5872b1f69b75SAndy Adamson if (status) 5873b1f69b75SAndy Adamson return status; 5874ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5875b1f69b75SAndy Adamson if (unlikely(!p)) 5876b1f69b75SAndy Adamson goto out_overflow; 5877ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 5878ea9d23f5STrond Myklebust decode_stateid(xdr, &res->stateid); 5879ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5880ea9d23f5STrond Myklebust if (unlikely(!p)) 5881ea9d23f5STrond Myklebust goto out_overflow; 5882b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5883b1f69b75SAndy Adamson if (!layout_count) { 5884b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5885b1f69b75SAndy Adamson __func__); 5886b1f69b75SAndy Adamson return -EINVAL; 5887b1f69b75SAndy Adamson } 5888b1f69b75SAndy Adamson 588935124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5890b1f69b75SAndy Adamson if (unlikely(!p)) 5891b1f69b75SAndy Adamson goto out_overflow; 5892b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5893b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5894b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5895b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 589635124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5897b1f69b75SAndy Adamson 5898b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5899b1f69b75SAndy Adamson __func__, 5900b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5901b1f69b75SAndy Adamson (unsigned long)res->range.length, 5902b1f69b75SAndy Adamson res->range.iomode, 5903b1f69b75SAndy Adamson res->type, 590435124a09SWeston Andros Adamson res->layoutp->len); 5905b1f69b75SAndy Adamson 590664bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 590735124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 590835124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 590935124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 591035124a09SWeston Andros Adamson res->layoutp->len, recvd); 591135124a09SWeston Andros Adamson return -EINVAL; 591235124a09SWeston Andros Adamson } 591335124a09SWeston Andros Adamson 5914b1f69b75SAndy Adamson if (layout_count > 1) { 5915b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5916b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5917b1f69b75SAndy Adamson * the client may see a response that is less than the 5918b1f69b75SAndy Adamson * minimum it requested. 5919b1f69b75SAndy Adamson */ 5920b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5921b1f69b75SAndy Adamson __func__, layout_count); 5922b1f69b75SAndy Adamson } 5923b1f69b75SAndy Adamson 5924b1f69b75SAndy Adamson return 0; 5925b1f69b75SAndy Adamson out_overflow: 5926b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5927b1f69b75SAndy Adamson return -EIO; 5928b1f69b75SAndy Adamson } 5929863a3c6cSAndy Adamson 5930cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5931cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5932cbe82603SBenny Halevy { 5933cbe82603SBenny Halevy __be32 *p; 5934cbe82603SBenny Halevy int status; 5935cbe82603SBenny Halevy 5936cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5937cbe82603SBenny Halevy if (status) 5938cbe82603SBenny Halevy return status; 5939cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5940cbe82603SBenny Halevy if (unlikely(!p)) 5941cbe82603SBenny Halevy goto out_overflow; 5942cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5943cbe82603SBenny Halevy if (res->lrs_present) 5944cbe82603SBenny Halevy status = decode_stateid(xdr, &res->stateid); 5945cbe82603SBenny Halevy return status; 5946cbe82603SBenny Halevy out_overflow: 5947cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 5948cbe82603SBenny Halevy return -EIO; 5949cbe82603SBenny Halevy } 5950cbe82603SBenny Halevy 5951863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5952863a3c6cSAndy Adamson struct rpc_rqst *req, 5953863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5954863a3c6cSAndy Adamson { 5955863a3c6cSAndy Adamson __be32 *p; 5956863a3c6cSAndy Adamson __u32 sizechanged; 5957863a3c6cSAndy Adamson int status; 5958863a3c6cSAndy Adamson 5959863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5960db29c089SAndy Adamson res->status = status; 5961863a3c6cSAndy Adamson if (status) 5962863a3c6cSAndy Adamson return status; 5963863a3c6cSAndy Adamson 5964863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5965863a3c6cSAndy Adamson if (unlikely(!p)) 5966863a3c6cSAndy Adamson goto out_overflow; 5967863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5968863a3c6cSAndy Adamson 5969863a3c6cSAndy Adamson if (sizechanged) { 5970863a3c6cSAndy Adamson /* throw away new size */ 5971863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5972863a3c6cSAndy Adamson if (unlikely(!p)) 5973863a3c6cSAndy Adamson goto out_overflow; 5974863a3c6cSAndy Adamson } 5975863a3c6cSAndy Adamson return 0; 5976863a3c6cSAndy Adamson out_overflow: 5977863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 5978863a3c6cSAndy Adamson return -EIO; 5979863a3c6cSAndy Adamson } 59807d974794SBryan Schumaker 59817d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 59827d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 59837d974794SBryan Schumaker { 59847d974794SBryan Schumaker __be32 *p; 59857d974794SBryan Schumaker int status; 59867d974794SBryan Schumaker int num_res; 59877d974794SBryan Schumaker 59887d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 59897d974794SBryan Schumaker if (status) 59907d974794SBryan Schumaker return status; 59917d974794SBryan Schumaker 59927d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 59937d974794SBryan Schumaker if (unlikely(!p)) 59947d974794SBryan Schumaker goto out_overflow; 59957d974794SBryan Schumaker num_res = be32_to_cpup(p++); 59967d974794SBryan Schumaker if (num_res != 1) 59977d974794SBryan Schumaker goto out; 59987d974794SBryan Schumaker 59997d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 60007d974794SBryan Schumaker if (unlikely(!p)) 60017d974794SBryan Schumaker goto out_overflow; 60027d974794SBryan Schumaker res->status = be32_to_cpup(p++); 60031cab0652SBryan Schumaker 60041cab0652SBryan Schumaker return status; 60057d974794SBryan Schumaker out_overflow: 60067d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 60077d974794SBryan Schumaker out: 60087d974794SBryan Schumaker return -EIO; 60097d974794SBryan Schumaker } 60109aeda35fSBryan Schumaker 60119aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 60129aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 60139aeda35fSBryan Schumaker { 60149f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 60159aeda35fSBryan Schumaker return res->status; 60169aeda35fSBryan Schumaker } 6017b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6018b1f69b75SAndy Adamson 60191da177e4SLinus Torvalds /* 602049c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 602149c2559eSBenny Halevy */ 602249c2559eSBenny Halevy 602349c2559eSBenny Halevy /* 60241da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 60251da177e4SLinus Torvalds */ 6026bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6027bf269551SChuck Lever struct xdr_stream *xdr, 6028bf269551SChuck Lever struct nfs_closeres *res) 60291da177e4SLinus Torvalds { 60301da177e4SLinus Torvalds struct compound_hdr hdr; 60311da177e4SLinus Torvalds int status; 60321da177e4SLinus Torvalds 6033bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60341da177e4SLinus Torvalds if (status) 60351da177e4SLinus Torvalds goto out; 6036bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60379b7b9fccSAndy Adamson if (status) 60389b7b9fccSAndy Adamson goto out; 6039bf269551SChuck Lever status = decode_putfh(xdr); 60401da177e4SLinus Torvalds if (status) 60411da177e4SLinus Torvalds goto out; 6042bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 6043516a6af6STrond Myklebust if (status != 0) 6044516a6af6STrond Myklebust goto out; 60456926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60461da177e4SLinus Torvalds out: 60471da177e4SLinus Torvalds return status; 60481da177e4SLinus Torvalds } 60491da177e4SLinus Torvalds 60501da177e4SLinus Torvalds /* 60511da177e4SLinus Torvalds * Decode ACCESS response 60521da177e4SLinus Torvalds */ 6053bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6054bf269551SChuck Lever struct nfs4_accessres *res) 60551da177e4SLinus Torvalds { 60561da177e4SLinus Torvalds struct compound_hdr hdr; 60571da177e4SLinus Torvalds int status; 60581da177e4SLinus Torvalds 6059bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60609b7b9fccSAndy Adamson if (status) 60619b7b9fccSAndy Adamson goto out; 6062bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60639b7b9fccSAndy Adamson if (status) 60641da177e4SLinus Torvalds goto out; 6065bf269551SChuck Lever status = decode_putfh(xdr); 606676b32999STrond Myklebust if (status != 0) 606776b32999STrond Myklebust goto out; 60686168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 606976b32999STrond Myklebust if (status != 0) 607076b32999STrond Myklebust goto out; 60716926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60721da177e4SLinus Torvalds out: 60731da177e4SLinus Torvalds return status; 60741da177e4SLinus Torvalds } 60751da177e4SLinus Torvalds 60761da177e4SLinus Torvalds /* 60771da177e4SLinus Torvalds * Decode LOOKUP response 60781da177e4SLinus Torvalds */ 6079bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6080bf269551SChuck Lever struct nfs4_lookup_res *res) 60811da177e4SLinus Torvalds { 60821da177e4SLinus Torvalds struct compound_hdr hdr; 60831da177e4SLinus Torvalds int status; 60841da177e4SLinus Torvalds 6085bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60869b7b9fccSAndy Adamson if (status) 60879b7b9fccSAndy Adamson goto out; 6088bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60899b7b9fccSAndy Adamson if (status) 60901da177e4SLinus Torvalds goto out; 6091bf269551SChuck Lever status = decode_putfh(xdr); 6092bf269551SChuck Lever if (status) 60931da177e4SLinus Torvalds goto out; 6094bf269551SChuck Lever status = decode_lookup(xdr); 6095bf269551SChuck Lever if (status) 60961da177e4SLinus Torvalds goto out; 6097bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6098bf269551SChuck Lever if (status) 60991da177e4SLinus Torvalds goto out; 6100aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 61011da177e4SLinus Torvalds out: 61021da177e4SLinus Torvalds return status; 61031da177e4SLinus Torvalds } 61041da177e4SLinus Torvalds 61051da177e4SLinus Torvalds /* 61061da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 61071da177e4SLinus Torvalds */ 6108bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6109bf269551SChuck Lever struct xdr_stream *xdr, 6110bf269551SChuck Lever struct nfs4_lookup_res *res) 61111da177e4SLinus Torvalds { 61121da177e4SLinus Torvalds struct compound_hdr hdr; 61131da177e4SLinus Torvalds int status; 61141da177e4SLinus Torvalds 6115bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61169b7b9fccSAndy Adamson if (status) 61179b7b9fccSAndy Adamson goto out; 6118bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61199b7b9fccSAndy Adamson if (status) 61201da177e4SLinus Torvalds goto out; 6121bf269551SChuck Lever status = decode_putrootfh(xdr); 6122bf269551SChuck Lever if (status) 61231da177e4SLinus Torvalds goto out; 6124bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6125bf269551SChuck Lever if (status == 0) 6126aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6127aa9c2669SDavid Quigley res->label, res->server); 61281da177e4SLinus Torvalds out: 61291da177e4SLinus Torvalds return status; 61301da177e4SLinus Torvalds } 61311da177e4SLinus Torvalds 61321da177e4SLinus Torvalds /* 61331da177e4SLinus Torvalds * Decode REMOVE response 61341da177e4SLinus Torvalds */ 6135bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6136bf269551SChuck Lever struct nfs_removeres *res) 61371da177e4SLinus Torvalds { 61381da177e4SLinus Torvalds struct compound_hdr hdr; 61391da177e4SLinus Torvalds int status; 61401da177e4SLinus Torvalds 6141bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61429b7b9fccSAndy Adamson if (status) 61439b7b9fccSAndy Adamson goto out; 6144bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61459b7b9fccSAndy Adamson if (status) 61461da177e4SLinus Torvalds goto out; 6147bf269551SChuck Lever status = decode_putfh(xdr); 6148bf269551SChuck Lever if (status) 614916e42959STrond Myklebust goto out; 6150bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 61511da177e4SLinus Torvalds out: 61521da177e4SLinus Torvalds return status; 61531da177e4SLinus Torvalds } 61541da177e4SLinus Torvalds 61551da177e4SLinus Torvalds /* 61561da177e4SLinus Torvalds * Decode RENAME response 61571da177e4SLinus Torvalds */ 6158bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6159bf269551SChuck Lever struct nfs_renameres *res) 61601da177e4SLinus Torvalds { 61611da177e4SLinus Torvalds struct compound_hdr hdr; 61621da177e4SLinus Torvalds int status; 61631da177e4SLinus Torvalds 6164bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61659b7b9fccSAndy Adamson if (status) 61669b7b9fccSAndy Adamson goto out; 6167bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61689b7b9fccSAndy Adamson if (status) 61691da177e4SLinus Torvalds goto out; 6170bf269551SChuck Lever status = decode_putfh(xdr); 6171bf269551SChuck Lever if (status) 61721da177e4SLinus Torvalds goto out; 6173bf269551SChuck Lever status = decode_savefh(xdr); 6174bf269551SChuck Lever if (status) 61751da177e4SLinus Torvalds goto out; 6176bf269551SChuck Lever status = decode_putfh(xdr); 6177bf269551SChuck Lever if (status) 61781da177e4SLinus Torvalds goto out; 6179bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 61801da177e4SLinus Torvalds out: 61811da177e4SLinus Torvalds return status; 61821da177e4SLinus Torvalds } 61831da177e4SLinus Torvalds 61841da177e4SLinus Torvalds /* 61851da177e4SLinus Torvalds * Decode LINK response 61861da177e4SLinus Torvalds */ 6187bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6188bf269551SChuck Lever struct nfs4_link_res *res) 61891da177e4SLinus Torvalds { 61901da177e4SLinus Torvalds struct compound_hdr hdr; 61911da177e4SLinus Torvalds int status; 61921da177e4SLinus Torvalds 6193bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61949b7b9fccSAndy Adamson if (status) 61959b7b9fccSAndy Adamson goto out; 6196bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61979b7b9fccSAndy Adamson if (status) 61981da177e4SLinus Torvalds goto out; 6199bf269551SChuck Lever status = decode_putfh(xdr); 6200bf269551SChuck Lever if (status) 62011da177e4SLinus Torvalds goto out; 6202bf269551SChuck Lever status = decode_savefh(xdr); 6203bf269551SChuck Lever if (status) 62041da177e4SLinus Torvalds goto out; 6205bf269551SChuck Lever status = decode_putfh(xdr); 6206bf269551SChuck Lever if (status) 62071da177e4SLinus Torvalds goto out; 6208bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6209bf269551SChuck Lever if (status) 621091ba2eeeSTrond Myklebust goto out; 621191ba2eeeSTrond Myklebust /* 621291ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 621391ba2eeeSTrond Myklebust * filehandle. 621491ba2eeeSTrond Myklebust */ 6215bf269551SChuck Lever status = decode_restorefh(xdr); 6216bf269551SChuck Lever if (status) 621791ba2eeeSTrond Myklebust goto out; 6218aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62191da177e4SLinus Torvalds out: 62201da177e4SLinus Torvalds return status; 62211da177e4SLinus Torvalds } 62221da177e4SLinus Torvalds 62231da177e4SLinus Torvalds /* 62241da177e4SLinus Torvalds * Decode CREATE response 62251da177e4SLinus Torvalds */ 6226bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6227bf269551SChuck Lever struct nfs4_create_res *res) 62281da177e4SLinus Torvalds { 62291da177e4SLinus Torvalds struct compound_hdr hdr; 62301da177e4SLinus Torvalds int status; 62311da177e4SLinus Torvalds 6232bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62339b7b9fccSAndy Adamson if (status) 62349b7b9fccSAndy Adamson goto out; 6235bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62369b7b9fccSAndy Adamson if (status) 62371da177e4SLinus Torvalds goto out; 6238bf269551SChuck Lever status = decode_putfh(xdr); 6239bf269551SChuck Lever if (status) 62401da177e4SLinus Torvalds goto out; 6241bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6242bf269551SChuck Lever if (status) 62431da177e4SLinus Torvalds goto out; 6244bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6245bf269551SChuck Lever if (status) 62461da177e4SLinus Torvalds goto out; 6247aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62481da177e4SLinus Torvalds out: 62491da177e4SLinus Torvalds return status; 62501da177e4SLinus Torvalds } 62511da177e4SLinus Torvalds 62521da177e4SLinus Torvalds /* 62531da177e4SLinus Torvalds * Decode SYMLINK response 62541da177e4SLinus Torvalds */ 6255bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6256bf269551SChuck Lever struct nfs4_create_res *res) 62571da177e4SLinus Torvalds { 6258bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 62591da177e4SLinus Torvalds } 62601da177e4SLinus Torvalds 62611da177e4SLinus Torvalds /* 62621da177e4SLinus Torvalds * Decode GETATTR response 62631da177e4SLinus Torvalds */ 6264bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6265bf269551SChuck Lever struct nfs4_getattr_res *res) 62661da177e4SLinus Torvalds { 62671da177e4SLinus Torvalds struct compound_hdr hdr; 62681da177e4SLinus Torvalds int status; 62691da177e4SLinus Torvalds 6270bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62711da177e4SLinus Torvalds if (status) 62721da177e4SLinus Torvalds goto out; 6273bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62749b7b9fccSAndy Adamson if (status) 62759b7b9fccSAndy Adamson goto out; 6276bf269551SChuck Lever status = decode_putfh(xdr); 62771da177e4SLinus Torvalds if (status) 62781da177e4SLinus Torvalds goto out; 6279aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62801da177e4SLinus Torvalds out: 62811da177e4SLinus Torvalds return status; 62821da177e4SLinus Torvalds } 62831da177e4SLinus Torvalds 628423ec6965SJ. Bruce Fields /* 628523ec6965SJ. Bruce Fields * Encode an SETACL request 628623ec6965SJ. Bruce Fields */ 62879f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 62889f06c719SChuck Lever struct nfs_setaclargs *args) 628923ec6965SJ. Bruce Fields { 629023ec6965SJ. Bruce Fields struct compound_hdr hdr = { 629166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 629223ec6965SJ. Bruce Fields }; 629323ec6965SJ. Bruce Fields 62949f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 62959f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 62969f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 62979f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6298d017931cSAndy Adamson encode_nops(&hdr); 629923ec6965SJ. Bruce Fields } 630005d564feSAndy Adamson 630123ec6965SJ. Bruce Fields /* 630223ec6965SJ. Bruce Fields * Decode SETACL response 630323ec6965SJ. Bruce Fields */ 630423ec6965SJ. Bruce Fields static int 6305bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 630673c403a9SBenny Halevy struct nfs_setaclres *res) 630723ec6965SJ. Bruce Fields { 630823ec6965SJ. Bruce Fields struct compound_hdr hdr; 630923ec6965SJ. Bruce Fields int status; 631023ec6965SJ. Bruce Fields 6311bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 631223ec6965SJ. Bruce Fields if (status) 631323ec6965SJ. Bruce Fields goto out; 6314bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63159b7b9fccSAndy Adamson if (status) 63169b7b9fccSAndy Adamson goto out; 6317bf269551SChuck Lever status = decode_putfh(xdr); 631823ec6965SJ. Bruce Fields if (status) 631923ec6965SJ. Bruce Fields goto out; 6320bf269551SChuck Lever status = decode_setattr(xdr); 632123ec6965SJ. Bruce Fields out: 632223ec6965SJ. Bruce Fields return status; 632323ec6965SJ. Bruce Fields } 63241da177e4SLinus Torvalds 63251da177e4SLinus Torvalds /* 6326029d105eSJ. Bruce Fields * Decode GETACL response 6327029d105eSJ. Bruce Fields */ 6328029d105eSJ. Bruce Fields static int 6329bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6330663c79b3SBenny Halevy struct nfs_getaclres *res) 6331029d105eSJ. Bruce Fields { 6332029d105eSJ. Bruce Fields struct compound_hdr hdr; 6333029d105eSJ. Bruce Fields int status; 6334029d105eSJ. Bruce Fields 6335331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6336331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6337331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6338331818f1STrond Myklebust } 6339bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6340029d105eSJ. Bruce Fields if (status) 6341029d105eSJ. Bruce Fields goto out; 6342bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63439b7b9fccSAndy Adamson if (status) 63449b7b9fccSAndy Adamson goto out; 6345bf269551SChuck Lever status = decode_putfh(xdr); 6346029d105eSJ. Bruce Fields if (status) 6347029d105eSJ. Bruce Fields goto out; 6348bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6349029d105eSJ. Bruce Fields 6350029d105eSJ. Bruce Fields out: 6351029d105eSJ. Bruce Fields return status; 6352029d105eSJ. Bruce Fields } 6353029d105eSJ. Bruce Fields 6354029d105eSJ. Bruce Fields /* 63551da177e4SLinus Torvalds * Decode CLOSE response 63561da177e4SLinus Torvalds */ 6357bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6358bf269551SChuck Lever struct nfs_closeres *res) 63591da177e4SLinus Torvalds { 63601da177e4SLinus Torvalds struct compound_hdr hdr; 63611da177e4SLinus Torvalds int status; 63621da177e4SLinus Torvalds 6363bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63641da177e4SLinus Torvalds if (status) 63651da177e4SLinus Torvalds goto out; 6366bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63679b7b9fccSAndy Adamson if (status) 63689b7b9fccSAndy Adamson goto out; 6369bf269551SChuck Lever status = decode_putfh(xdr); 63701da177e4SLinus Torvalds if (status) 63711da177e4SLinus Torvalds goto out; 6372bf269551SChuck Lever status = decode_close(xdr, res); 6373516a6af6STrond Myklebust if (status != 0) 6374516a6af6STrond Myklebust goto out; 6375516a6af6STrond Myklebust /* 6376516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6377516a6af6STrond Myklebust * in which case the getattr call will fail with 6378516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6379516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6380516a6af6STrond Myklebust */ 63816926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63821da177e4SLinus Torvalds out: 63831da177e4SLinus Torvalds return status; 63841da177e4SLinus Torvalds } 63851da177e4SLinus Torvalds 63861da177e4SLinus Torvalds /* 63871da177e4SLinus Torvalds * Decode OPEN response 63881da177e4SLinus Torvalds */ 6389bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6390bf269551SChuck Lever struct nfs_openres *res) 63911da177e4SLinus Torvalds { 63921da177e4SLinus Torvalds struct compound_hdr hdr; 63931da177e4SLinus Torvalds int status; 63941da177e4SLinus Torvalds 6395bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63961da177e4SLinus Torvalds if (status) 63971da177e4SLinus Torvalds goto out; 6398bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63999b7b9fccSAndy Adamson if (status) 64009b7b9fccSAndy Adamson goto out; 6401bf269551SChuck Lever status = decode_putfh(xdr); 64021da177e4SLinus Torvalds if (status) 64031da177e4SLinus Torvalds goto out; 6404bf269551SChuck Lever status = decode_open(xdr, res); 64051da177e4SLinus Torvalds if (status) 64061da177e4SLinus Torvalds goto out; 640701913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 640801913b49SWeston Andros Adamson if (status) 64091da177e4SLinus Torvalds goto out; 6410ae2bb032SWeston Andros Adamson if (res->access_request) 64116168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6412aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 64131da177e4SLinus Torvalds out: 64141da177e4SLinus Torvalds return status; 64151da177e4SLinus Torvalds } 64161da177e4SLinus Torvalds 64171da177e4SLinus Torvalds /* 64181da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 64191da177e4SLinus Torvalds */ 6420bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6421bf269551SChuck Lever struct xdr_stream *xdr, 6422bf269551SChuck Lever struct nfs_open_confirmres *res) 64231da177e4SLinus Torvalds { 64241da177e4SLinus Torvalds struct compound_hdr hdr; 64251da177e4SLinus Torvalds int status; 64261da177e4SLinus Torvalds 6427bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64281da177e4SLinus Torvalds if (status) 64291da177e4SLinus Torvalds goto out; 6430bf269551SChuck Lever status = decode_putfh(xdr); 64311da177e4SLinus Torvalds if (status) 64321da177e4SLinus Torvalds goto out; 6433bf269551SChuck Lever status = decode_open_confirm(xdr, res); 64341da177e4SLinus Torvalds out: 64351da177e4SLinus Torvalds return status; 64361da177e4SLinus Torvalds } 64371da177e4SLinus Torvalds 64381da177e4SLinus Torvalds /* 64391da177e4SLinus Torvalds * Decode OPEN response 64401da177e4SLinus Torvalds */ 6441bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6442bf269551SChuck Lever struct xdr_stream *xdr, 6443bf269551SChuck Lever struct nfs_openres *res) 64441da177e4SLinus Torvalds { 64451da177e4SLinus Torvalds struct compound_hdr hdr; 64461da177e4SLinus Torvalds int status; 64471da177e4SLinus Torvalds 6448bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64491da177e4SLinus Torvalds if (status) 64501da177e4SLinus Torvalds goto out; 6451bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64529b7b9fccSAndy Adamson if (status) 64539b7b9fccSAndy Adamson goto out; 6454bf269551SChuck Lever status = decode_putfh(xdr); 64551da177e4SLinus Torvalds if (status) 64561da177e4SLinus Torvalds goto out; 6457bf269551SChuck Lever status = decode_open(xdr, res); 6458864472e9STrond Myklebust if (status) 6459864472e9STrond Myklebust goto out; 6460ae2bb032SWeston Andros Adamson if (res->access_request) 64616168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 64626926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 64631da177e4SLinus Torvalds out: 64641da177e4SLinus Torvalds return status; 64651da177e4SLinus Torvalds } 64661da177e4SLinus Torvalds 64671da177e4SLinus Torvalds /* 64681da177e4SLinus Torvalds * Decode SETATTR response 64691da177e4SLinus Torvalds */ 6470bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6471bf269551SChuck Lever struct xdr_stream *xdr, 6472bf269551SChuck Lever struct nfs_setattrres *res) 64731da177e4SLinus Torvalds { 64741da177e4SLinus Torvalds struct compound_hdr hdr; 64751da177e4SLinus Torvalds int status; 64761da177e4SLinus Torvalds 6477bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64781da177e4SLinus Torvalds if (status) 64791da177e4SLinus Torvalds goto out; 6480bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64819b7b9fccSAndy Adamson if (status) 64829b7b9fccSAndy Adamson goto out; 6483bf269551SChuck Lever status = decode_putfh(xdr); 64841da177e4SLinus Torvalds if (status) 64851da177e4SLinus Torvalds goto out; 6486bf269551SChuck Lever status = decode_setattr(xdr); 64871da177e4SLinus Torvalds if (status) 64881da177e4SLinus Torvalds goto out; 6489aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64901da177e4SLinus Torvalds out: 64911da177e4SLinus Torvalds return status; 64921da177e4SLinus Torvalds } 64931da177e4SLinus Torvalds 64941da177e4SLinus Torvalds /* 64951da177e4SLinus Torvalds * Decode LOCK response 64961da177e4SLinus Torvalds */ 6497bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6498bf269551SChuck Lever struct nfs_lock_res *res) 64991da177e4SLinus Torvalds { 65001da177e4SLinus Torvalds struct compound_hdr hdr; 65011da177e4SLinus Torvalds int status; 65021da177e4SLinus Torvalds 6503bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65041da177e4SLinus Torvalds if (status) 65051da177e4SLinus Torvalds goto out; 6506bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65079b7b9fccSAndy Adamson if (status) 65089b7b9fccSAndy Adamson goto out; 6509bf269551SChuck Lever status = decode_putfh(xdr); 65101da177e4SLinus Torvalds if (status) 65111da177e4SLinus Torvalds goto out; 6512bf269551SChuck Lever status = decode_lock(xdr, res); 65131da177e4SLinus Torvalds out: 65141da177e4SLinus Torvalds return status; 65151da177e4SLinus Torvalds } 65161da177e4SLinus Torvalds 65171da177e4SLinus Torvalds /* 65181da177e4SLinus Torvalds * Decode LOCKT response 65191da177e4SLinus Torvalds */ 6520bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6521bf269551SChuck Lever struct nfs_lockt_res *res) 65221da177e4SLinus Torvalds { 65231da177e4SLinus Torvalds struct compound_hdr hdr; 65241da177e4SLinus Torvalds int status; 65251da177e4SLinus Torvalds 6526bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65271da177e4SLinus Torvalds if (status) 65281da177e4SLinus Torvalds goto out; 6529bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65309b7b9fccSAndy Adamson if (status) 65319b7b9fccSAndy Adamson goto out; 6532bf269551SChuck Lever status = decode_putfh(xdr); 65331da177e4SLinus Torvalds if (status) 65341da177e4SLinus Torvalds goto out; 6535bf269551SChuck Lever status = decode_lockt(xdr, res); 65361da177e4SLinus Torvalds out: 65371da177e4SLinus Torvalds return status; 65381da177e4SLinus Torvalds } 65391da177e4SLinus Torvalds 65401da177e4SLinus Torvalds /* 65411da177e4SLinus Torvalds * Decode LOCKU response 65421da177e4SLinus Torvalds */ 6543bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6544bf269551SChuck Lever struct nfs_locku_res *res) 65451da177e4SLinus Torvalds { 65461da177e4SLinus Torvalds struct compound_hdr hdr; 65471da177e4SLinus Torvalds int status; 65481da177e4SLinus Torvalds 6549bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65501da177e4SLinus Torvalds if (status) 65511da177e4SLinus Torvalds goto out; 6552bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65539b7b9fccSAndy Adamson if (status) 65549b7b9fccSAndy Adamson goto out; 6555bf269551SChuck Lever status = decode_putfh(xdr); 65561da177e4SLinus Torvalds if (status) 65571da177e4SLinus Torvalds goto out; 6558bf269551SChuck Lever status = decode_locku(xdr, res); 65591da177e4SLinus Torvalds out: 65601da177e4SLinus Torvalds return status; 65611da177e4SLinus Torvalds } 65621da177e4SLinus Torvalds 6563bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6564bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6565d3c7b7ccSTrond Myklebust { 6566d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6567d3c7b7ccSTrond Myklebust int status; 6568d3c7b7ccSTrond Myklebust 6569bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6570d3c7b7ccSTrond Myklebust if (!status) 6571bf269551SChuck Lever status = decode_release_lockowner(xdr); 6572d3c7b7ccSTrond Myklebust return status; 6573d3c7b7ccSTrond Myklebust } 6574d3c7b7ccSTrond Myklebust 65751da177e4SLinus Torvalds /* 65761da177e4SLinus Torvalds * Decode READLINK response 65771da177e4SLinus Torvalds */ 6578bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6579bf269551SChuck Lever struct xdr_stream *xdr, 6580f50c7000SBenny Halevy struct nfs4_readlink_res *res) 65811da177e4SLinus Torvalds { 65821da177e4SLinus Torvalds struct compound_hdr hdr; 65831da177e4SLinus Torvalds int status; 65841da177e4SLinus Torvalds 6585bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65861da177e4SLinus Torvalds if (status) 65871da177e4SLinus Torvalds goto out; 6588bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65899b7b9fccSAndy Adamson if (status) 65909b7b9fccSAndy Adamson goto out; 6591bf269551SChuck Lever status = decode_putfh(xdr); 65921da177e4SLinus Torvalds if (status) 65931da177e4SLinus Torvalds goto out; 6594bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 65951da177e4SLinus Torvalds out: 65961da177e4SLinus Torvalds return status; 65971da177e4SLinus Torvalds } 65981da177e4SLinus Torvalds 65991da177e4SLinus Torvalds /* 66001da177e4SLinus Torvalds * Decode READDIR response 66011da177e4SLinus Torvalds */ 6602bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6603bf269551SChuck Lever struct nfs4_readdir_res *res) 66041da177e4SLinus Torvalds { 66051da177e4SLinus Torvalds struct compound_hdr hdr; 66061da177e4SLinus Torvalds int status; 66071da177e4SLinus Torvalds 6608bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66091da177e4SLinus Torvalds if (status) 66101da177e4SLinus Torvalds goto out; 6611bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66129b7b9fccSAndy Adamson if (status) 66139b7b9fccSAndy Adamson goto out; 6614bf269551SChuck Lever status = decode_putfh(xdr); 66151da177e4SLinus Torvalds if (status) 66161da177e4SLinus Torvalds goto out; 6617bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 66181da177e4SLinus Torvalds out: 66191da177e4SLinus Torvalds return status; 66201da177e4SLinus Torvalds } 66211da177e4SLinus Torvalds 66221da177e4SLinus Torvalds /* 66231da177e4SLinus Torvalds * Decode Read response 66241da177e4SLinus Torvalds */ 6625bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6626bf269551SChuck Lever struct nfs_readres *res) 66271da177e4SLinus Torvalds { 66281da177e4SLinus Torvalds struct compound_hdr hdr; 66291da177e4SLinus Torvalds int status; 66301da177e4SLinus Torvalds 6631bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66321da177e4SLinus Torvalds if (status) 66331da177e4SLinus Torvalds goto out; 6634bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66359b7b9fccSAndy Adamson if (status) 66369b7b9fccSAndy Adamson goto out; 6637bf269551SChuck Lever status = decode_putfh(xdr); 66381da177e4SLinus Torvalds if (status) 66391da177e4SLinus Torvalds goto out; 6640bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 66411da177e4SLinus Torvalds if (!status) 66421da177e4SLinus Torvalds status = res->count; 66431da177e4SLinus Torvalds out: 66441da177e4SLinus Torvalds return status; 66451da177e4SLinus Torvalds } 66461da177e4SLinus Torvalds 66471da177e4SLinus Torvalds /* 66481da177e4SLinus Torvalds * Decode WRITE response 66491da177e4SLinus Torvalds */ 6650bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6651bf269551SChuck Lever struct nfs_writeres *res) 66521da177e4SLinus Torvalds { 66531da177e4SLinus Torvalds struct compound_hdr hdr; 66541da177e4SLinus Torvalds int status; 66551da177e4SLinus Torvalds 6656bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66571da177e4SLinus Torvalds if (status) 66581da177e4SLinus Torvalds goto out; 6659bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66609b7b9fccSAndy Adamson if (status) 66619b7b9fccSAndy Adamson goto out; 6662bf269551SChuck Lever status = decode_putfh(xdr); 66631da177e4SLinus Torvalds if (status) 66641da177e4SLinus Torvalds goto out; 6665bf269551SChuck Lever status = decode_write(xdr, res); 66664f9838c7STrond Myklebust if (status) 66674f9838c7STrond Myklebust goto out; 66687ffd1064SFred Isaman if (res->fattr) 66696926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 66701da177e4SLinus Torvalds if (!status) 66711da177e4SLinus Torvalds status = res->count; 66721da177e4SLinus Torvalds out: 66731da177e4SLinus Torvalds return status; 66741da177e4SLinus Torvalds } 66751da177e4SLinus Torvalds 66761da177e4SLinus Torvalds /* 66771da177e4SLinus Torvalds * Decode COMMIT response 66781da177e4SLinus Torvalds */ 6679bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 66800b7c0153SFred Isaman struct nfs_commitres *res) 66811da177e4SLinus Torvalds { 66821da177e4SLinus Torvalds struct compound_hdr hdr; 66831da177e4SLinus Torvalds int status; 66841da177e4SLinus Torvalds 6685bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66861da177e4SLinus Torvalds if (status) 66871da177e4SLinus Torvalds goto out; 6688bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66899b7b9fccSAndy Adamson if (status) 66909b7b9fccSAndy Adamson goto out; 6691bf269551SChuck Lever status = decode_putfh(xdr); 66921da177e4SLinus Torvalds if (status) 66931da177e4SLinus Torvalds goto out; 6694bf269551SChuck Lever status = decode_commit(xdr, res); 66951da177e4SLinus Torvalds out: 66961da177e4SLinus Torvalds return status; 66971da177e4SLinus Torvalds } 66981da177e4SLinus Torvalds 66991da177e4SLinus Torvalds /* 67008b173218SRicardo Labiaga * Decode FSINFO response 67011da177e4SLinus Torvalds */ 6702bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 67033dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 67041da177e4SLinus Torvalds { 67051da177e4SLinus Torvalds struct compound_hdr hdr; 67061da177e4SLinus Torvalds int status; 67071da177e4SLinus Torvalds 6708bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67091da177e4SLinus Torvalds if (!status) 6710bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 67119b7b9fccSAndy Adamson if (!status) 6712bf269551SChuck Lever status = decode_putfh(xdr); 67131da177e4SLinus Torvalds if (!status) 6714bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 67151da177e4SLinus Torvalds return status; 67161da177e4SLinus Torvalds } 67171da177e4SLinus Torvalds 67181da177e4SLinus Torvalds /* 67198b173218SRicardo Labiaga * Decode PATHCONF response 67201da177e4SLinus Torvalds */ 6721bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6722d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 67231da177e4SLinus Torvalds { 67241da177e4SLinus Torvalds struct compound_hdr hdr; 67251da177e4SLinus Torvalds int status; 67261da177e4SLinus Torvalds 6727bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67281da177e4SLinus Torvalds if (!status) 6729bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 67309b7b9fccSAndy Adamson if (!status) 6731bf269551SChuck Lever status = decode_putfh(xdr); 67321da177e4SLinus Torvalds if (!status) 6733bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 67341da177e4SLinus Torvalds return status; 67351da177e4SLinus Torvalds } 67361da177e4SLinus Torvalds 67371da177e4SLinus Torvalds /* 67388b173218SRicardo Labiaga * Decode STATFS response 67391da177e4SLinus Torvalds */ 6740bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 674124ad148aSBenny Halevy struct nfs4_statfs_res *res) 67421da177e4SLinus Torvalds { 67431da177e4SLinus Torvalds struct compound_hdr hdr; 67441da177e4SLinus Torvalds int status; 67451da177e4SLinus Torvalds 6746bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67471da177e4SLinus Torvalds if (!status) 6748bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 67499b7b9fccSAndy Adamson if (!status) 6750bf269551SChuck Lever status = decode_putfh(xdr); 67511da177e4SLinus Torvalds if (!status) 6752bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 67531da177e4SLinus Torvalds return status; 67541da177e4SLinus Torvalds } 67551da177e4SLinus Torvalds 67561da177e4SLinus Torvalds /* 67578b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 67581da177e4SLinus Torvalds */ 6759bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6760bf269551SChuck Lever struct xdr_stream *xdr, 6761bf269551SChuck Lever struct nfs4_server_caps_res *res) 67621da177e4SLinus Torvalds { 67631da177e4SLinus Torvalds struct compound_hdr hdr; 67641da177e4SLinus Torvalds int status; 67651da177e4SLinus Torvalds 6766bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67679b7b9fccSAndy Adamson if (status) 67689b7b9fccSAndy Adamson goto out; 6769bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 67709b7b9fccSAndy Adamson if (status) 67711da177e4SLinus Torvalds goto out; 6772bf269551SChuck Lever status = decode_putfh(xdr); 6773bf269551SChuck Lever if (status) 67741da177e4SLinus Torvalds goto out; 6775bf269551SChuck Lever status = decode_server_caps(xdr, res); 67761da177e4SLinus Torvalds out: 67771da177e4SLinus Torvalds return status; 67781da177e4SLinus Torvalds } 67791da177e4SLinus Torvalds 67801da177e4SLinus Torvalds /* 67811da177e4SLinus Torvalds * Decode RENEW response 67821da177e4SLinus Torvalds */ 6783bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6784bf269551SChuck Lever void *__unused) 67851da177e4SLinus Torvalds { 67861da177e4SLinus Torvalds struct compound_hdr hdr; 67871da177e4SLinus Torvalds int status; 67881da177e4SLinus Torvalds 6789bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67901da177e4SLinus Torvalds if (!status) 6791bf269551SChuck Lever status = decode_renew(xdr); 67921da177e4SLinus Torvalds return status; 67931da177e4SLinus Torvalds } 67941da177e4SLinus Torvalds 67951da177e4SLinus Torvalds /* 67968b173218SRicardo Labiaga * Decode SETCLIENTID response 67971da177e4SLinus Torvalds */ 6798bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6799bf269551SChuck Lever struct xdr_stream *xdr, 6800bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 68011da177e4SLinus Torvalds { 68021da177e4SLinus Torvalds struct compound_hdr hdr; 68031da177e4SLinus Torvalds int status; 68041da177e4SLinus Torvalds 6805bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68061da177e4SLinus Torvalds if (!status) 6807bf269551SChuck Lever status = decode_setclientid(xdr, res); 68081da177e4SLinus Torvalds return status; 68091da177e4SLinus Torvalds } 68101da177e4SLinus Torvalds 68111da177e4SLinus Torvalds /* 68128b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 68131da177e4SLinus Torvalds */ 6814bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 681583ca7f5aSChuck Lever struct xdr_stream *xdr) 68161da177e4SLinus Torvalds { 68171da177e4SLinus Torvalds struct compound_hdr hdr; 68181da177e4SLinus Torvalds int status; 68191da177e4SLinus Torvalds 6820bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68211da177e4SLinus Torvalds if (!status) 6822bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 68231da177e4SLinus Torvalds return status; 68241da177e4SLinus Torvalds } 68251da177e4SLinus Torvalds 68261da177e4SLinus Torvalds /* 68278b173218SRicardo Labiaga * Decode DELEGRETURN response 68281da177e4SLinus Torvalds */ 6829bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6830bf269551SChuck Lever struct xdr_stream *xdr, 6831bf269551SChuck Lever struct nfs4_delegreturnres *res) 68321da177e4SLinus Torvalds { 68331da177e4SLinus Torvalds struct compound_hdr hdr; 68341da177e4SLinus Torvalds int status; 68351da177e4SLinus Torvalds 6836bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68379b7b9fccSAndy Adamson if (status) 68389b7b9fccSAndy Adamson goto out; 6839bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68409b7b9fccSAndy Adamson if (status) 6841fa178f29STrond Myklebust goto out; 6842bf269551SChuck Lever status = decode_putfh(xdr); 6843fa178f29STrond Myklebust if (status != 0) 6844fa178f29STrond Myklebust goto out; 6845e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6846556ae3bbSJeff Layton if (status != 0) 6847556ae3bbSJeff Layton goto out; 6848e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6849fa178f29STrond Myklebust out: 68501da177e4SLinus Torvalds return status; 68511da177e4SLinus Torvalds } 68521da177e4SLinus Torvalds 6853683b57b4STrond Myklebust /* 68548b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6855683b57b4STrond Myklebust */ 6856bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6857bf269551SChuck Lever struct xdr_stream *xdr, 685822958463SBenny Halevy struct nfs4_fs_locations_res *res) 6859683b57b4STrond Myklebust { 6860683b57b4STrond Myklebust struct compound_hdr hdr; 6861683b57b4STrond Myklebust int status; 6862683b57b4STrond Myklebust 6863bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68649b7b9fccSAndy Adamson if (status) 68659b7b9fccSAndy Adamson goto out; 6866bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68679b7b9fccSAndy Adamson if (status) 6868683b57b4STrond Myklebust goto out; 6869bf269551SChuck Lever status = decode_putfh(xdr); 6870bf269551SChuck Lever if (status) 6871683b57b4STrond Myklebust goto out; 6872b03d735bSChuck Lever if (res->migration) { 6873b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6874b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6875b03d735bSChuck Lever &res->fs_locations->fattr, 6876b03d735bSChuck Lever NULL, res->fs_locations, 6877b03d735bSChuck Lever NULL, res->fs_locations->server); 6878b03d735bSChuck Lever if (status) 6879b03d735bSChuck Lever goto out; 6880b03d735bSChuck Lever if (res->renew) 6881b03d735bSChuck Lever status = decode_renew(xdr); 6882b03d735bSChuck Lever } else { 6883bf269551SChuck Lever status = decode_lookup(xdr); 6884bf269551SChuck Lever if (status) 6885683b57b4STrond Myklebust goto out; 6886bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6887b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6888b03d735bSChuck Lever &res->fs_locations->fattr, 68898b7e3f49STrond Myklebust NULL, res->fs_locations, 6890aa9c2669SDavid Quigley NULL, res->fs_locations->server); 6891b03d735bSChuck Lever } 6892683b57b4STrond Myklebust out: 6893683b57b4STrond Myklebust return status; 6894683b57b4STrond Myklebust } 6895683b57b4STrond Myklebust 68965a5ea0d4SBryan Schumaker /* 68975a5ea0d4SBryan Schumaker * Decode SECINFO response 68985a5ea0d4SBryan Schumaker */ 68995a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 69005a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 69015a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 69025a5ea0d4SBryan Schumaker { 69035a5ea0d4SBryan Schumaker struct compound_hdr hdr; 69045a5ea0d4SBryan Schumaker int status; 69055a5ea0d4SBryan Schumaker 69065a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 69075a5ea0d4SBryan Schumaker if (status) 69085a5ea0d4SBryan Schumaker goto out; 69095a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 69105a5ea0d4SBryan Schumaker if (status) 69115a5ea0d4SBryan Schumaker goto out; 69125a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 69135a5ea0d4SBryan Schumaker if (status) 69145a5ea0d4SBryan Schumaker goto out; 69155a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 69165a5ea0d4SBryan Schumaker out: 69175a5ea0d4SBryan Schumaker return status; 69185a5ea0d4SBryan Schumaker } 69195a5ea0d4SBryan Schumaker 692044c99933SChuck Lever /* 692144c99933SChuck Lever * Decode FSID_PRESENT response 692244c99933SChuck Lever */ 692344c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 692444c99933SChuck Lever struct xdr_stream *xdr, 692544c99933SChuck Lever struct nfs4_fsid_present_res *res) 692644c99933SChuck Lever { 692744c99933SChuck Lever struct compound_hdr hdr; 692844c99933SChuck Lever int status; 692944c99933SChuck Lever 693044c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 693144c99933SChuck Lever if (status) 693244c99933SChuck Lever goto out; 693344c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 693444c99933SChuck Lever if (status) 693544c99933SChuck Lever goto out; 693644c99933SChuck Lever status = decode_putfh(xdr); 693744c99933SChuck Lever if (status) 693844c99933SChuck Lever goto out; 693944c99933SChuck Lever status = decode_getfh(xdr, res->fh); 694044c99933SChuck Lever if (status) 694144c99933SChuck Lever goto out; 694244c99933SChuck Lever if (res->renew) 694344c99933SChuck Lever status = decode_renew(xdr); 694444c99933SChuck Lever out: 694544c99933SChuck Lever return status; 694644c99933SChuck Lever } 694744c99933SChuck Lever 694899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 694999fe60d0SBenny Halevy /* 69507c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 69517c44f1aeSWeston Andros Adamson */ 69527c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 69537c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 69547c44f1aeSWeston Andros Adamson void *res) 69557c44f1aeSWeston Andros Adamson { 69567c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 69577c44f1aeSWeston Andros Adamson int status; 69587c44f1aeSWeston Andros Adamson 69597c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 69607c44f1aeSWeston Andros Adamson if (!status) 69617c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 69627c44f1aeSWeston Andros Adamson return status; 69637c44f1aeSWeston Andros Adamson } 69647c44f1aeSWeston Andros Adamson 69657c44f1aeSWeston Andros Adamson /* 69668b173218SRicardo Labiaga * Decode EXCHANGE_ID response 696799fe60d0SBenny Halevy */ 6968bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 6969bf269551SChuck Lever struct xdr_stream *xdr, 697099fe60d0SBenny Halevy void *res) 697199fe60d0SBenny Halevy { 697299fe60d0SBenny Halevy struct compound_hdr hdr; 697399fe60d0SBenny Halevy int status; 697499fe60d0SBenny Halevy 6975bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 697699fe60d0SBenny Halevy if (!status) 6977bf269551SChuck Lever status = decode_exchange_id(xdr, res); 697899fe60d0SBenny Halevy return status; 697999fe60d0SBenny Halevy } 69802050f0ccSAndy Adamson 69812050f0ccSAndy Adamson /* 69828b173218SRicardo Labiaga * Decode CREATE_SESSION response 6983fc931582SAndy Adamson */ 6984bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 6985bf269551SChuck Lever struct xdr_stream *xdr, 6986fc931582SAndy Adamson struct nfs41_create_session_res *res) 6987fc931582SAndy Adamson { 6988fc931582SAndy Adamson struct compound_hdr hdr; 6989fc931582SAndy Adamson int status; 6990fc931582SAndy Adamson 6991bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6992fc931582SAndy Adamson if (!status) 6993bf269551SChuck Lever status = decode_create_session(xdr, res); 6994fc931582SAndy Adamson return status; 6995fc931582SAndy Adamson } 6996fc931582SAndy Adamson 6997fc931582SAndy Adamson /* 69988b173218SRicardo Labiaga * Decode DESTROY_SESSION response 69990f3e66c6SAndy Adamson */ 7000bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7001bf269551SChuck Lever struct xdr_stream *xdr, 7002bf269551SChuck Lever void *res) 70030f3e66c6SAndy Adamson { 70040f3e66c6SAndy Adamson struct compound_hdr hdr; 70050f3e66c6SAndy Adamson int status; 70060f3e66c6SAndy Adamson 7007bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70080f3e66c6SAndy Adamson if (!status) 7009bf269551SChuck Lever status = decode_destroy_session(xdr, res); 70100f3e66c6SAndy Adamson return status; 70110f3e66c6SAndy Adamson } 70120f3e66c6SAndy Adamson 70130f3e66c6SAndy Adamson /* 701466245539STrond Myklebust * Decode DESTROY_CLIENTID response 701566245539STrond Myklebust */ 701666245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 701766245539STrond Myklebust struct xdr_stream *xdr, 701866245539STrond Myklebust void *res) 701966245539STrond Myklebust { 702066245539STrond Myklebust struct compound_hdr hdr; 702166245539STrond Myklebust int status; 702266245539STrond Myklebust 702366245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 702466245539STrond Myklebust if (!status) 702566245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 702666245539STrond Myklebust return status; 702766245539STrond Myklebust } 702866245539STrond Myklebust 702966245539STrond Myklebust /* 70308b173218SRicardo Labiaga * Decode SEQUENCE response 7031fc01cea9SAndy Adamson */ 7032bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7033bf269551SChuck Lever struct xdr_stream *xdr, 7034fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 7035fc01cea9SAndy Adamson { 7036fc01cea9SAndy Adamson struct compound_hdr hdr; 7037fc01cea9SAndy Adamson int status; 7038fc01cea9SAndy Adamson 7039bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7040fc01cea9SAndy Adamson if (!status) 7041bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7042fc01cea9SAndy Adamson return status; 7043fc01cea9SAndy Adamson } 7044fc01cea9SAndy Adamson 7045fc01cea9SAndy Adamson /* 70468b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 70472050f0ccSAndy Adamson */ 7048bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7049bf269551SChuck Lever struct xdr_stream *xdr, 70502050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 70512050f0ccSAndy Adamson { 70522050f0ccSAndy Adamson struct compound_hdr hdr; 70532050f0ccSAndy Adamson int status; 70542050f0ccSAndy Adamson 7055bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70562050f0ccSAndy Adamson if (!status) 7057bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 70582050f0ccSAndy Adamson if (!status) 7059bf269551SChuck Lever status = decode_putrootfh(xdr); 70602050f0ccSAndy Adamson if (!status) 7061bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 70622050f0ccSAndy Adamson return status; 70632050f0ccSAndy Adamson } 706418019753SRicardo Labiaga 706518019753SRicardo Labiaga /* 706618019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 706718019753SRicardo Labiaga */ 7068bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7069bf269551SChuck Lever struct xdr_stream *xdr, 707018019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 707118019753SRicardo Labiaga { 707218019753SRicardo Labiaga struct compound_hdr hdr; 707318019753SRicardo Labiaga int status; 707418019753SRicardo Labiaga 7075bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 707618019753SRicardo Labiaga if (!status) 7077bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 707818019753SRicardo Labiaga if (!status) 7079bf269551SChuck Lever status = decode_reclaim_complete(xdr, (void *)NULL); 708018019753SRicardo Labiaga return status; 708118019753SRicardo Labiaga } 7082b1f69b75SAndy Adamson 7083b1f69b75SAndy Adamson /* 70847f11d8d3SAndy Adamson * Decode GETDEVICELIST response 70857f11d8d3SAndy Adamson */ 70867f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp, 70877f11d8d3SAndy Adamson struct xdr_stream *xdr, 70887f11d8d3SAndy Adamson struct nfs4_getdevicelist_res *res) 70897f11d8d3SAndy Adamson { 70907f11d8d3SAndy Adamson struct compound_hdr hdr; 70917f11d8d3SAndy Adamson int status; 70927f11d8d3SAndy Adamson 70937f11d8d3SAndy Adamson dprintk("encoding getdevicelist!\n"); 70947f11d8d3SAndy Adamson 70957f11d8d3SAndy Adamson status = decode_compound_hdr(xdr, &hdr); 70967f11d8d3SAndy Adamson if (status != 0) 70977f11d8d3SAndy Adamson goto out; 70987f11d8d3SAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 70997f11d8d3SAndy Adamson if (status != 0) 71007f11d8d3SAndy Adamson goto out; 71017f11d8d3SAndy Adamson status = decode_putfh(xdr); 71027f11d8d3SAndy Adamson if (status != 0) 71037f11d8d3SAndy Adamson goto out; 71047f11d8d3SAndy Adamson status = decode_getdevicelist(xdr, res->devlist); 71057f11d8d3SAndy Adamson out: 71067f11d8d3SAndy Adamson return status; 71077f11d8d3SAndy Adamson } 71087f11d8d3SAndy Adamson 71097f11d8d3SAndy Adamson /* 7110b1f69b75SAndy Adamson * Decode GETDEVINFO response 7111b1f69b75SAndy Adamson */ 7112bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7113bf269551SChuck Lever struct xdr_stream *xdr, 7114b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 7115b1f69b75SAndy Adamson { 7116b1f69b75SAndy Adamson struct compound_hdr hdr; 7117b1f69b75SAndy Adamson int status; 7118b1f69b75SAndy Adamson 7119bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7120b1f69b75SAndy Adamson if (status != 0) 7121b1f69b75SAndy Adamson goto out; 7122bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7123b1f69b75SAndy Adamson if (status != 0) 7124b1f69b75SAndy Adamson goto out; 7125bf269551SChuck Lever status = decode_getdeviceinfo(xdr, res->pdev); 7126b1f69b75SAndy Adamson out: 7127b1f69b75SAndy Adamson return status; 7128b1f69b75SAndy Adamson } 7129b1f69b75SAndy Adamson 7130b1f69b75SAndy Adamson /* 7131b1f69b75SAndy Adamson * Decode LAYOUTGET response 7132b1f69b75SAndy Adamson */ 7133bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7134bf269551SChuck Lever struct xdr_stream *xdr, 7135b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 7136b1f69b75SAndy Adamson { 7137b1f69b75SAndy Adamson struct compound_hdr hdr; 7138b1f69b75SAndy Adamson int status; 7139b1f69b75SAndy Adamson 7140bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7141b1f69b75SAndy Adamson if (status) 7142b1f69b75SAndy Adamson goto out; 7143bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7144b1f69b75SAndy Adamson if (status) 7145b1f69b75SAndy Adamson goto out; 7146bf269551SChuck Lever status = decode_putfh(xdr); 7147b1f69b75SAndy Adamson if (status) 7148b1f69b75SAndy Adamson goto out; 7149bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7150b1f69b75SAndy Adamson out: 7151b1f69b75SAndy Adamson return status; 7152b1f69b75SAndy Adamson } 7153863a3c6cSAndy Adamson 7154863a3c6cSAndy Adamson /* 7155cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7156cbe82603SBenny Halevy */ 7157cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7158cbe82603SBenny Halevy struct xdr_stream *xdr, 7159cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 7160cbe82603SBenny Halevy { 7161cbe82603SBenny Halevy struct compound_hdr hdr; 7162cbe82603SBenny Halevy int status; 7163cbe82603SBenny Halevy 7164cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7165cbe82603SBenny Halevy if (status) 7166cbe82603SBenny Halevy goto out; 7167cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7168cbe82603SBenny Halevy if (status) 7169cbe82603SBenny Halevy goto out; 7170cbe82603SBenny Halevy status = decode_putfh(xdr); 7171cbe82603SBenny Halevy if (status) 7172cbe82603SBenny Halevy goto out; 7173cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7174cbe82603SBenny Halevy out: 7175cbe82603SBenny Halevy return status; 7176cbe82603SBenny Halevy } 7177cbe82603SBenny Halevy 7178cbe82603SBenny Halevy /* 7179863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7180863a3c6cSAndy Adamson */ 7181863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7182863a3c6cSAndy Adamson struct xdr_stream *xdr, 7183863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 7184863a3c6cSAndy Adamson { 7185863a3c6cSAndy Adamson struct compound_hdr hdr; 7186863a3c6cSAndy Adamson int status; 7187863a3c6cSAndy Adamson 7188863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7189863a3c6cSAndy Adamson if (status) 7190863a3c6cSAndy Adamson goto out; 7191863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7192863a3c6cSAndy Adamson if (status) 7193863a3c6cSAndy Adamson goto out; 7194863a3c6cSAndy Adamson status = decode_putfh(xdr); 7195863a3c6cSAndy Adamson if (status) 7196863a3c6cSAndy Adamson goto out; 7197863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7198863a3c6cSAndy Adamson if (status) 7199863a3c6cSAndy Adamson goto out; 72006926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7201863a3c6cSAndy Adamson out: 7202863a3c6cSAndy Adamson return status; 7203863a3c6cSAndy Adamson } 7204fca78d6dSBryan Schumaker 7205fca78d6dSBryan Schumaker /* 7206fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7207fca78d6dSBryan Schumaker */ 7208fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7209fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7210fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 7211fca78d6dSBryan Schumaker { 7212fca78d6dSBryan Schumaker struct compound_hdr hdr; 7213fca78d6dSBryan Schumaker int status; 7214fca78d6dSBryan Schumaker 7215fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7216fca78d6dSBryan Schumaker if (status) 7217fca78d6dSBryan Schumaker goto out; 7218fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7219fca78d6dSBryan Schumaker if (status) 7220fca78d6dSBryan Schumaker goto out; 7221fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7222fca78d6dSBryan Schumaker if (status) 7223fca78d6dSBryan Schumaker goto out; 722431e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7225fca78d6dSBryan Schumaker out: 7226fca78d6dSBryan Schumaker return status; 7227fca78d6dSBryan Schumaker } 72287d974794SBryan Schumaker 72297d974794SBryan Schumaker /* 72307d974794SBryan Schumaker * Decode TEST_STATEID response 72317d974794SBryan Schumaker */ 72327d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 72337d974794SBryan Schumaker struct xdr_stream *xdr, 72347d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 72357d974794SBryan Schumaker { 72367d974794SBryan Schumaker struct compound_hdr hdr; 72377d974794SBryan Schumaker int status; 72387d974794SBryan Schumaker 72397d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 72407d974794SBryan Schumaker if (status) 72417d974794SBryan Schumaker goto out; 72427d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 72437d974794SBryan Schumaker if (status) 72447d974794SBryan Schumaker goto out; 72457d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 72467d974794SBryan Schumaker out: 72477d974794SBryan Schumaker return status; 72487d974794SBryan Schumaker } 72499aeda35fSBryan Schumaker 72509aeda35fSBryan Schumaker /* 72519aeda35fSBryan Schumaker * Decode FREE_STATEID response 72529aeda35fSBryan Schumaker */ 72539aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 72549aeda35fSBryan Schumaker struct xdr_stream *xdr, 72559aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 72569aeda35fSBryan Schumaker { 72579aeda35fSBryan Schumaker struct compound_hdr hdr; 72589aeda35fSBryan Schumaker int status; 72599aeda35fSBryan Schumaker 72609aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 72619aeda35fSBryan Schumaker if (status) 72629aeda35fSBryan Schumaker goto out; 72639aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 72649aeda35fSBryan Schumaker if (status) 72659aeda35fSBryan Schumaker goto out; 72669aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 72679aeda35fSBryan Schumaker out: 72689aeda35fSBryan Schumaker return status; 72699aeda35fSBryan Schumaker } 727099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 727199fe60d0SBenny Halevy 7272573c4e1eSChuck Lever /** 7273573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7274573c4e1eSChuck Lever * the local page cache. 7275573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7276573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7277573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7278573c4e1eSChuck Lever * 7279573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7280573c4e1eSChuck Lever * returned. 7281573c4e1eSChuck Lever * 7282573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7283573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7284573c4e1eSChuck Lever * on a directory already in our cache. 7285573c4e1eSChuck Lever */ 7286573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7287573c4e1eSChuck Lever int plus) 72881da177e4SLinus Torvalds { 7289256e48bbSTrond Myklebust unsigned int savep; 7290dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 72911da177e4SLinus Torvalds uint32_t len; 7292babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7293babddc72SBryan Schumaker if (unlikely(!p)) 7294babddc72SBryan Schumaker goto out_overflow; 7295c08e76d0SChuck Lever if (*p == xdr_zero) { 7296babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7297babddc72SBryan Schumaker if (unlikely(!p)) 7298babddc72SBryan Schumaker goto out_overflow; 7299c08e76d0SChuck Lever if (*p == xdr_zero) 7300573c4e1eSChuck Lever return -EAGAIN; 73011da177e4SLinus Torvalds entry->eof = 1; 7302573c4e1eSChuck Lever return -EBADCOOKIE; 73031da177e4SLinus Torvalds } 73041da177e4SLinus Torvalds 7305babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7306babddc72SBryan Schumaker if (unlikely(!p)) 7307babddc72SBryan Schumaker goto out_overflow; 73081da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 73091da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7310c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7311babddc72SBryan Schumaker 73129af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7313babddc72SBryan Schumaker if (unlikely(!p)) 7314babddc72SBryan Schumaker goto out_overflow; 73151da177e4SLinus Torvalds entry->name = (const char *) p; 73161da177e4SLinus Torvalds 73171da177e4SLinus Torvalds /* 73181da177e4SLinus Torvalds * In case the server doesn't return an inode number, 73191da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 73201da177e4SLinus Torvalds * since glibc seems to choke on it...) 73211da177e4SLinus Torvalds */ 73221da177e4SLinus Torvalds entry->ino = 1; 73234f082222STrond Myklebust entry->fattr->valid = 0; 73241da177e4SLinus Torvalds 73259af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7326babddc72SBryan Schumaker goto out_overflow; 73279af8c222STrond Myklebust 7328256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7329babddc72SBryan Schumaker goto out_overflow; 73309af8c222STrond Myklebust 7331573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7332aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7333babddc72SBryan Schumaker goto out_overflow; 733428331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 733528331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 733628331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 733782f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 73389af8c222STrond Myklebust 73390b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 73400b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 73410b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 73420b26a0bfSTrond Myklebust 7343573c4e1eSChuck Lever return 0; 7344babddc72SBryan Schumaker 7345babddc72SBryan Schumaker out_overflow: 7346babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7347573c4e1eSChuck Lever return -EAGAIN; 73481da177e4SLinus Torvalds } 73491da177e4SLinus Torvalds 73501da177e4SLinus Torvalds /* 73511da177e4SLinus Torvalds * We need to translate between nfs status return values and 73521da177e4SLinus Torvalds * the local errno values which may not be the same. 73531da177e4SLinus Torvalds */ 73541da177e4SLinus Torvalds static struct { 73551da177e4SLinus Torvalds int stat; 73561da177e4SLinus Torvalds int errno; 73571da177e4SLinus Torvalds } nfs_errtbl[] = { 73581da177e4SLinus Torvalds { NFS4_OK, 0 }, 7359856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7360856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7361856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7362856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7363856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7364856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7365856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7366856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7367856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7368856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7369856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7370856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7371856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7372856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7373856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7374856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7375856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7376856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7377856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7378856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7379856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7380856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7381fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7382856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7383856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7384856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7385856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7386856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7387856dff3dSBenny Halevy { -1, -EIO } 73881da177e4SLinus Torvalds }; 73891da177e4SLinus Torvalds 73901da177e4SLinus Torvalds /* 73911da177e4SLinus Torvalds * Convert an NFS error code to a local one. 73921da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 73931da177e4SLinus Torvalds */ 73941da177e4SLinus Torvalds static int 73950a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 73961da177e4SLinus Torvalds { 73971da177e4SLinus Torvalds int i; 73981da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 73991da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 74001da177e4SLinus Torvalds return nfs_errtbl[i].errno; 74011da177e4SLinus Torvalds } 74021da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 74031da177e4SLinus Torvalds /* The server is looney tunes. */ 7404fdcb4577STrond Myklebust return -EREMOTEIO; 74051da177e4SLinus Torvalds } 74061da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 74071da177e4SLinus Torvalds * handle it. 74081da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 74091da177e4SLinus Torvalds * not conflict with native Linux error codes. 74101da177e4SLinus Torvalds */ 7411856dff3dSBenny Halevy return -stat; 74121da177e4SLinus Torvalds } 74131da177e4SLinus Torvalds 74141da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 74151da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 74161da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 74179f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7418bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 74192bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 74202bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7421cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7422cc0175c1SChuck Lever .p_name = #proc, \ 74231da177e4SLinus Torvalds } 74241da177e4SLinus Torvalds 74251da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 74261da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 74271da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 74281da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 74291da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 74301da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 74311da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 74321da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 74331da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 74341da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 74351da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 74361da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 74371da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 74381da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 74391da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 74401da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 74411da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 74421da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 74431da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 74441da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 74451da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 74461da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 74471da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 74481da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 74491da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 74501da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 74511da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 74521da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 74531da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 74541da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 74551da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 74561da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7457029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 745823ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7459683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7460d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 74615a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 746244c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 746399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 746499fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7465fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 74660f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7467fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 74682050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 746918019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7470b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7471b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7472863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7473cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7474fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 74757d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 74769aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 74777f11d8d3SAndy Adamson PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist), 7478ad24ecfbSTrond Myklebust PROC(BIND_CONN_TO_SESSION, 7479ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 748066245539STrond Myklebust PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 748199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 74821da177e4SLinus Torvalds }; 74831da177e4SLinus Torvalds 7484a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 74851da177e4SLinus Torvalds .number = 4, 7486e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 74871da177e4SLinus Torvalds .procs = nfs4_procedures 74881da177e4SLinus Torvalds }; 74891da177e4SLinus Torvalds 74901da177e4SLinus Torvalds /* 74911da177e4SLinus Torvalds * Local variables: 74921da177e4SLinus Torvalds * c-basic-offset: 8 74931da177e4SLinus Torvalds * End: 74941da177e4SLinus Torvalds */ 7495