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> 55dff25ddbSAndreas Gruenbacher #include <linux/fs_struct.h> 56f092075dSChuck Lever 574ce79717STrond Myklebust #include "nfs4_fs.h" 584882ef72SAlexandros Batsakis #include "internal.h" 5940c64c26SAnna Schumaker #include "nfs4idmap.h" 6076e697baSTrond Myklebust #include "nfs4session.h" 61b1f69b75SAndy Adamson #include "pnfs.h" 62f092075dSChuck Lever #include "netns.h" 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 671da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 681da177e4SLinus Torvalds 690a8ea437SDavid Howells static int nfs4_stat_to_errno(int); 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 721da177e4SLinus Torvalds #ifdef DEBUG 731da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20 741da177e4SLinus Torvalds #else 751da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0 761da177e4SLinus Torvalds #endif 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* lock,open owner id: 799f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 801da177e4SLinus Torvalds */ 8195b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2) 82d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4) 839104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 841da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 851da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 861da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1) 871da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2) 889104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 899104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 909104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 919104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 921da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 931da177e4SLinus Torvalds (NFS4_FHSIZE >> 2)) 941da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz) 951da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 961da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 971da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz) 981da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 991da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2)) 100e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4 10196928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 1021da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 1031da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 104bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 105bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 106aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL 107aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */ 108aa9c2669SDavid Quigley #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN)) 109aa9c2669SDavid Quigley #else 110aa9c2669SDavid Quigley #define nfs4_label_maxsz 0 111aa9c2669SDavid Quigley #endif 11288034c3dSAndy Adamson /* We support only one layout type per file system */ 11388034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8) 11496928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */ 11596928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 11688034c3dSAndy Adamson 3 + 3 + 3 + nfs4_owner_maxsz + \ 117aa9c2669SDavid Quigley nfs4_group_maxsz + nfs4_label_maxsz + \ 118aa9c2669SDavid Quigley decode_mdsthreshold_maxsz)) 11996928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 12096928206SJ. Bruce Fields nfs4_fattr_value_maxsz) 12196928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 1229104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 1239104a55dSTrond Myklebust 1 + 2 + 1 + \ 1249104a55dSTrond Myklebust nfs4_owner_maxsz + \ 1259104a55dSTrond Myklebust nfs4_group_maxsz + \ 126aa9c2669SDavid Quigley nfs4_label_maxsz + \ 1279104a55dSTrond Myklebust 4 + 4) 1281da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz) 1291da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz) 13056ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 13156ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 1322f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz) 133dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three 134dae100c2SFred Isaman * layout types will be returned. 135dae100c2SFred Isaman */ 136dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 137dae100c2SFred Isaman nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 1381da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 1391da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz) 1401da177e4SLinus Torvalds #define encode_setclientid_maxsz \ 1411da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 142cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 143b8fb2f59SJeff Layton /* client name */ \ 144b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 145cc38bac3SChuck Lever 1 /* sc_prog */ + \ 1466dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1476dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 148cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1491da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1501da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1516dd3436bSChuck Lever 2 /* clientid */ + \ 1526dd3436bSChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 1536dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1546dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) 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) 1625b5faaf6SJeff Layton #define encode_lookupp_maxsz (op_encode_hdr_maxsz) 1635b5faaf6SJeff Layton #define decode_lookupp_maxsz (op_decode_hdr_maxsz) 1642cebf828STrond Myklebust #define encode_share_access_maxsz \ 1652cebf828STrond Myklebust (2) 1664882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1672cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1682cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1692cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1702cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1712cebf828STrond Myklebust open_owner_id_maxsz + \ 1722cebf828STrond Myklebust encode_opentype_maxsz + \ 1732cebf828STrond Myklebust encode_claim_null_maxsz) 1745a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz (3) 1752cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1769104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1775a1f6d9eSTrond Myklebust decode_space_limit_maxsz + \ 1782cebf828STrond Myklebust decode_ace_maxsz) 1792cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1802cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1819104a55dSTrond Myklebust decode_stateid_maxsz + \ 1822cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1832cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1842cebf828STrond Myklebust decode_delegation_maxsz) 1859104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1869104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1879104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1889104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1899104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1909104a55dSTrond Myklebust decode_stateid_maxsz) 1919104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 1929104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1939104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 1949104a55dSTrond Myklebust encode_share_access_maxsz) 1959104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 1969104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1979104a55dSTrond Myklebust decode_stateid_maxsz) 1989104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 1999104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 2009104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 2019104a55dSTrond Myklebust decode_stateid_maxsz) 2029104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 2039104a55dSTrond Myklebust encode_stateid_maxsz + \ 2049104a55dSTrond Myklebust encode_attrs_maxsz) 2059104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 2069104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 2079104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 2089104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2099104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 2109104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 211aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \ 212aa9c2669SDavid Quigley nfs4_label_maxsz) 2139104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 214a7697f6fSChuck Lever decode_verifier_maxsz) 2159104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 2169104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 2179104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2189104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2199104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2209104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2219104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2229104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2239104a55dSTrond Myklebust decode_verifier_maxsz) 2241da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2251da177e4SLinus Torvalds nfs4_name_maxsz) 2266ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2276ce18391SBenny Halevy decode_change_info_maxsz) 2281da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2291da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2306ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2316ce18391SBenny Halevy decode_change_info_maxsz + \ 2326ce18391SBenny Halevy decode_change_info_maxsz) 2331da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2341da177e4SLinus Torvalds nfs4_name_maxsz) 2356ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 236daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2379104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2389104a55dSTrond Myklebust 7 + \ 239daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 240daccbdedSTrond Myklebust encode_lockowner_maxsz) 2419104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2429104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2439104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2449104a55dSTrond Myklebust decode_lock_denied_maxsz) 245daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 246daccbdedSTrond Myklebust encode_lockowner_maxsz) 2479104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2489104a55dSTrond Myklebust decode_lock_denied_maxsz) 2499104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2509104a55dSTrond Myklebust encode_stateid_maxsz + \ 2519104a55dSTrond Myklebust 4) 2529104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2539104a55dSTrond Myklebust decode_stateid_maxsz) 254d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 255d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 256d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 257d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 258d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2599104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2609104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2611da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2621da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 26394a6d753SChuck Lever 1 + \ 26496928206SJ. Bruce Fields nfs4_fattr_maxsz) 2651da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2661da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2679104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2689104a55dSTrond Myklebust encode_attrs_maxsz) 2692cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2702cebf828STrond Myklebust decode_change_info_maxsz + \ 2712cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2729104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2739104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2741da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2751da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2769104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2779104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2789104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2799104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2809104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2819104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 282e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 283e6889620STrond Myklebust (encode_getattr_maxsz) 284e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 285e6889620STrond Myklebust (0) 2865a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2871650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2889b7b9fccSAndy Adamson 2899b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 290fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 291d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 292d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 293fc931582SAndy Adamson 29499fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 29599fe60d0SBenny Halevy encode_verifier_maxsz + \ 29699fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 297b8fb2f59SJeff Layton /* eia_clientowner */ \ 298b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 29999fe60d0SBenny Halevy 1 /* flags */ + \ 30099fe60d0SBenny Halevy 1 /* spa_how */ + \ 3012031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3022031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3032031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 304db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 305db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 306db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 307db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 308d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 309db8ac8baSWeston Andros Adamson 3 /* nii_date */) 31099fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 31199fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 31299fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 31399fe60d0SBenny Halevy 1 /* eir_flags */ + \ 31499fe60d0SBenny Halevy 1 /* spr_how */ + \ 3152031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3162031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3172031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 31899fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 31999fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 32099fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 32199fe60d0SBenny Halevy /* eir_server_scope<> */ \ 32299fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 32399fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 3247d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3257d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3267d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3277d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3287d2ed9acSWeston Andros Adamson 3 /* nii_date */) 329fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 330fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 331fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 332fc931582SAndy Adamson 1 /* ca_rdma_ird */) 333fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 334fc931582SAndy Adamson 2 /* csa_clientid */ + \ 335fc931582SAndy Adamson 1 /* csa_sequence */ + \ 336fc931582SAndy Adamson 1 /* csa_flags */ + \ 337fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 338fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 339fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 340fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 341fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 342fc931582SAndy Adamson 1 /* stamp */ + \ 343fc931582SAndy Adamson 1 /* machinename.len */ + \ 344fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 345fc931582SAndy Adamson 1 /* uid */ + \ 346fc931582SAndy Adamson 1 /* gid */ + \ 347fc931582SAndy Adamson 1 /* gids.len (0) */) 348fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 349fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 350fc931582SAndy Adamson 1 /* csr_sequence */ + \ 351fc931582SAndy Adamson 1 /* csr_flags */ + \ 352fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 353fc931582SAndy Adamson decode_channel_attrs_maxsz) 3547c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3557c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3567c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3577c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3587c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3597c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3607c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3617c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3627c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3637c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3640f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3650f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 36666245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 36766245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 368fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 369fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 370fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 371fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 37218019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 37318019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 37484c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \ 37584c9dee3SChristoph Hellwig XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 37684c9dee3SChristoph Hellwig 1 /* layout type */ + \ 37784c9dee3SChristoph Hellwig 1 /* maxcount */ + \ 37884c9dee3SChristoph Hellwig 1 /* bitmap size */ + \ 37984c9dee3SChristoph Hellwig 1 /* notification bitmap length */ + \ 38084c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 381b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 382b1f69b75SAndy Adamson 1 /* layout type */ + \ 383b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 384b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 385b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 38684c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 387b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 388b1f69b75SAndy Adamson encode_stateid_maxsz) 389b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 390b1f69b75SAndy Adamson decode_stateid_maxsz + \ 391b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 392863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 393863a3c6cSAndy Adamson 2 /* offset */ + \ 394863a3c6cSAndy Adamson 2 /* length */ + \ 395863a3c6cSAndy Adamson 1 /* reclaim */ + \ 396863a3c6cSAndy Adamson encode_stateid_maxsz + \ 397863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 398863a3c6cSAndy Adamson 2 /* last byte written */ + \ 399863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 400863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 4015f919c9fSChristoph Hellwig 1 /* layoutupdate4 opaqueue len */) 4025f919c9fSChristoph Hellwig /* the actual content of layoutupdate4 should 4035f919c9fSChristoph Hellwig be allocated by drivers and spliced in 4045f919c9fSChristoph Hellwig using xdr_write_pages */ 405863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 406cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 407cbe82603SBenny Halevy encode_stateid_maxsz + \ 4086669cb8bSTrond Myklebust 1 + \ 4096669cb8bSTrond Myklebust XDR_QUADLEN(NFS4_OPAQUE_LIMIT)) 410cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 411cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 412fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 413fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 4147d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 4157d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4167d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 4179aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 4189aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4199f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 4209b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 4219b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 4229b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 423cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0 424cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0 4259b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4269b7b9fccSAndy Adamson 4271da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4281da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4291da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4309b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4311da177e4SLinus Torvalds encode_putfh_maxsz + \ 4329104a55dSTrond Myklebust encode_read_maxsz) 4331da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4349b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4351da177e4SLinus Torvalds decode_putfh_maxsz + \ 4369104a55dSTrond Myklebust decode_read_maxsz) 4371da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4389b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4391da177e4SLinus Torvalds encode_putfh_maxsz + \ 4409104a55dSTrond Myklebust encode_readlink_maxsz) 4411da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4429b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4431da177e4SLinus Torvalds decode_putfh_maxsz + \ 4449104a55dSTrond Myklebust decode_readlink_maxsz) 4451da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4469b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4471da177e4SLinus Torvalds encode_putfh_maxsz + \ 4489104a55dSTrond Myklebust encode_readdir_maxsz) 4491da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4509b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4511da177e4SLinus Torvalds decode_putfh_maxsz + \ 4529104a55dSTrond Myklebust decode_readdir_maxsz) 4531da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4549b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4551da177e4SLinus Torvalds encode_putfh_maxsz + \ 4569104a55dSTrond Myklebust encode_write_maxsz + \ 4574f9838c7STrond Myklebust encode_getattr_maxsz) 4581da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4599b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4601da177e4SLinus Torvalds decode_putfh_maxsz + \ 4619104a55dSTrond Myklebust decode_write_maxsz + \ 4624f9838c7STrond Myklebust decode_getattr_maxsz) 4631da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4649b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4651da177e4SLinus Torvalds encode_putfh_maxsz + \ 4668582715eSTrond Myklebust encode_commit_maxsz) 4671da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4689b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4691da177e4SLinus Torvalds decode_putfh_maxsz + \ 4708582715eSTrond Myklebust decode_commit_maxsz) 4711da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4729b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4731da177e4SLinus Torvalds encode_putfh_maxsz + \ 4742cebf828STrond Myklebust encode_open_maxsz + \ 4756168f62cSWeston Andros Adamson encode_access_maxsz + \ 4762cebf828STrond Myklebust encode_getfh_maxsz + \ 4772cebf828STrond Myklebust encode_getattr_maxsz) 4781da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4799b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4801da177e4SLinus Torvalds decode_putfh_maxsz + \ 4812cebf828STrond Myklebust decode_open_maxsz + \ 4826168f62cSWeston Andros Adamson decode_access_maxsz + \ 4832cebf828STrond Myklebust decode_getfh_maxsz + \ 4842cebf828STrond Myklebust decode_getattr_maxsz) 4851da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4861da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4871da177e4SLinus Torvalds encode_putfh_maxsz + \ 4889104a55dSTrond Myklebust encode_open_confirm_maxsz) 4899104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4909104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4911da177e4SLinus Torvalds decode_putfh_maxsz + \ 4929104a55dSTrond Myklebust decode_open_confirm_maxsz) 4931da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 4949b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4951da177e4SLinus Torvalds encode_putfh_maxsz + \ 4962cebf828STrond Myklebust encode_open_maxsz + \ 4976168f62cSWeston Andros Adamson encode_access_maxsz + \ 4982cebf828STrond Myklebust encode_getattr_maxsz) 4991da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 5009b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5011da177e4SLinus Torvalds decode_putfh_maxsz + \ 5022cebf828STrond Myklebust decode_open_maxsz + \ 5036168f62cSWeston Andros Adamson decode_access_maxsz + \ 5042cebf828STrond Myklebust decode_getattr_maxsz) 5051da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 5061da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5079b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5081da177e4SLinus Torvalds encode_putfh_maxsz + \ 509b6808145STrond Myklebust encode_layoutreturn_maxsz + \ 5103947b74dSTrond Myklebust encode_open_downgrade_maxsz) 5111da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 5121da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5139b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5141da177e4SLinus Torvalds decode_putfh_maxsz + \ 515b6808145STrond Myklebust decode_layoutreturn_maxsz + \ 5163947b74dSTrond Myklebust decode_open_downgrade_maxsz) 5171da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 5189b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5191da177e4SLinus Torvalds encode_putfh_maxsz + \ 520cf805165STrond Myklebust encode_layoutreturn_maxsz + \ 5219104a55dSTrond Myklebust encode_close_maxsz + \ 522516a6af6STrond Myklebust encode_getattr_maxsz) 5231da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 5249b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5251da177e4SLinus Torvalds decode_putfh_maxsz + \ 526cf805165STrond Myklebust decode_layoutreturn_maxsz + \ 5279104a55dSTrond Myklebust decode_close_maxsz + \ 528516a6af6STrond Myklebust decode_getattr_maxsz) 5291da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 5309b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5311da177e4SLinus Torvalds encode_putfh_maxsz + \ 5329104a55dSTrond Myklebust encode_setattr_maxsz + \ 5331da177e4SLinus Torvalds encode_getattr_maxsz) 5341da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5359b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5361da177e4SLinus Torvalds decode_putfh_maxsz + \ 5379104a55dSTrond Myklebust decode_setattr_maxsz + \ 5389104a55dSTrond Myklebust decode_getattr_maxsz) 5391da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5409b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5411da177e4SLinus Torvalds encode_putfh_maxsz + \ 5421da177e4SLinus Torvalds encode_fsinfo_maxsz) 5431da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5449b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5451da177e4SLinus Torvalds decode_putfh_maxsz + \ 5461da177e4SLinus Torvalds decode_fsinfo_maxsz) 5471da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5481da177e4SLinus Torvalds encode_renew_maxsz) 5491da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5501da177e4SLinus Torvalds decode_renew_maxsz) 5511da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5521da177e4SLinus Torvalds encode_setclientid_maxsz) 5531da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5541da177e4SLinus Torvalds decode_setclientid_maxsz) 5551da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5561da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 55783ca7f5aSChuck Lever encode_setclientid_confirm_maxsz) 5581da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5591da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 56083ca7f5aSChuck Lever decode_setclientid_confirm_maxsz) 5611da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5629b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5631da177e4SLinus Torvalds encode_putfh_maxsz + \ 5649104a55dSTrond Myklebust encode_lock_maxsz) 5651da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5669b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5671da177e4SLinus Torvalds decode_putfh_maxsz + \ 5689104a55dSTrond Myklebust decode_lock_maxsz) 5691da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5709b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5711da177e4SLinus Torvalds encode_putfh_maxsz + \ 5729104a55dSTrond Myklebust encode_lockt_maxsz) 5739104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5749b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5759104a55dSTrond Myklebust decode_putfh_maxsz + \ 5769104a55dSTrond Myklebust decode_lockt_maxsz) 5771da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5789b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5791da177e4SLinus Torvalds encode_putfh_maxsz + \ 5809104a55dSTrond Myklebust encode_locku_maxsz) 5811da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5829b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5831da177e4SLinus Torvalds decode_putfh_maxsz + \ 5849104a55dSTrond Myklebust decode_locku_maxsz) 585d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 586d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 587d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 588d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 589d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 590d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5911da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5929b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5931da177e4SLinus Torvalds encode_putfh_maxsz + \ 59476b32999STrond Myklebust encode_access_maxsz + \ 59576b32999STrond Myklebust encode_getattr_maxsz) 5961da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5979b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5981da177e4SLinus Torvalds decode_putfh_maxsz + \ 59976b32999STrond Myklebust decode_access_maxsz + \ 60076b32999STrond Myklebust decode_getattr_maxsz) 6011da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 6029b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6031da177e4SLinus Torvalds encode_putfh_maxsz + \ 60444c99933SChuck Lever encode_getattr_maxsz + \ 60544c99933SChuck Lever encode_renew_maxsz) 6061da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 6079b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6081da177e4SLinus Torvalds decode_putfh_maxsz + \ 60944c99933SChuck Lever decode_getattr_maxsz + \ 61044c99933SChuck Lever decode_renew_maxsz) 6111da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 6129b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6131da177e4SLinus Torvalds encode_putfh_maxsz + \ 6141da177e4SLinus Torvalds encode_lookup_maxsz + \ 6151da177e4SLinus Torvalds encode_getattr_maxsz + \ 6161da177e4SLinus Torvalds encode_getfh_maxsz) 6171da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 6189b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6191da177e4SLinus Torvalds decode_putfh_maxsz + \ 620e6889620STrond Myklebust decode_lookup_maxsz + \ 6211da177e4SLinus Torvalds decode_getattr_maxsz + \ 6221da177e4SLinus Torvalds decode_getfh_maxsz) 6235b5faaf6SJeff Layton #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \ 6245b5faaf6SJeff Layton encode_sequence_maxsz + \ 6255b5faaf6SJeff Layton encode_putfh_maxsz + \ 6265b5faaf6SJeff Layton encode_lookupp_maxsz + \ 6275b5faaf6SJeff Layton encode_getattr_maxsz + \ 6285b5faaf6SJeff Layton encode_getfh_maxsz) 6295b5faaf6SJeff Layton #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \ 6305b5faaf6SJeff Layton decode_sequence_maxsz + \ 6315b5faaf6SJeff Layton decode_putfh_maxsz + \ 6325b5faaf6SJeff Layton decode_lookupp_maxsz + \ 6335b5faaf6SJeff Layton decode_getattr_maxsz + \ 6345b5faaf6SJeff Layton decode_getfh_maxsz) 6351da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 6369b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6371da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 6381da177e4SLinus Torvalds encode_getattr_maxsz + \ 6391da177e4SLinus Torvalds encode_getfh_maxsz) 6401da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6419b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6421da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6431da177e4SLinus Torvalds decode_getattr_maxsz + \ 6441da177e4SLinus Torvalds decode_getfh_maxsz) 6451da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6469b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6471da177e4SLinus Torvalds encode_putfh_maxsz + \ 648778d2817STrond Myklebust encode_remove_maxsz) 6491da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6509b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6511da177e4SLinus Torvalds decode_putfh_maxsz + \ 652778d2817STrond Myklebust decode_remove_maxsz) 6531da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6549b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6551da177e4SLinus Torvalds encode_putfh_maxsz + \ 6561da177e4SLinus Torvalds encode_savefh_maxsz + \ 6571da177e4SLinus Torvalds encode_putfh_maxsz + \ 658778d2817STrond Myklebust encode_rename_maxsz) 6591da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6609b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6611da177e4SLinus Torvalds decode_putfh_maxsz + \ 6621da177e4SLinus Torvalds decode_savefh_maxsz + \ 6631da177e4SLinus Torvalds decode_putfh_maxsz + \ 664778d2817STrond Myklebust decode_rename_maxsz) 6651da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6669b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6671da177e4SLinus Torvalds encode_putfh_maxsz + \ 6681da177e4SLinus Torvalds encode_savefh_maxsz + \ 6691da177e4SLinus Torvalds encode_putfh_maxsz + \ 67091ba2eeeSTrond Myklebust encode_link_maxsz + \ 67191ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 672a9f6991bSTrond Myklebust encode_getattr_maxsz) 6731da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6749b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6751da177e4SLinus Torvalds decode_putfh_maxsz + \ 6761da177e4SLinus Torvalds decode_savefh_maxsz + \ 6771da177e4SLinus Torvalds decode_putfh_maxsz + \ 67891ba2eeeSTrond Myklebust decode_link_maxsz + \ 67991ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 68091ba2eeeSTrond Myklebust decode_getattr_maxsz) 6811da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6829b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6831da177e4SLinus Torvalds encode_putfh_maxsz + \ 6841da177e4SLinus Torvalds encode_symlink_maxsz + \ 6851da177e4SLinus Torvalds encode_getattr_maxsz + \ 6861da177e4SLinus Torvalds encode_getfh_maxsz) 6871da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6889b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6891da177e4SLinus Torvalds decode_putfh_maxsz + \ 6901da177e4SLinus Torvalds decode_symlink_maxsz + \ 6911da177e4SLinus Torvalds decode_getattr_maxsz + \ 6921da177e4SLinus Torvalds decode_getfh_maxsz) 6931da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6949b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6951da177e4SLinus Torvalds encode_putfh_maxsz + \ 6961da177e4SLinus Torvalds encode_create_maxsz + \ 69756ae19f3STrond Myklebust encode_getfh_maxsz + \ 69856ae19f3STrond Myklebust encode_getattr_maxsz) 6991da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 7009b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7011da177e4SLinus Torvalds decode_putfh_maxsz + \ 7021da177e4SLinus Torvalds decode_create_maxsz + \ 70356ae19f3STrond Myklebust decode_getfh_maxsz + \ 70456ae19f3STrond Myklebust decode_getattr_maxsz) 7051da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 7069b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7071da177e4SLinus Torvalds encode_putfh_maxsz + \ 7081da177e4SLinus Torvalds encode_getattr_maxsz) 7091da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 7109b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7111da177e4SLinus Torvalds decode_putfh_maxsz + \ 7121da177e4SLinus Torvalds decode_getattr_maxsz) 7131da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 7149b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7151da177e4SLinus Torvalds encode_putfh_maxsz + \ 7169104a55dSTrond Myklebust encode_statfs_maxsz) 7171da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 7189b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7191da177e4SLinus Torvalds decode_putfh_maxsz + \ 7209104a55dSTrond Myklebust decode_statfs_maxsz) 7211da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 7229b7b9fccSAndy Adamson encode_sequence_maxsz + \ 723ab91f264STrond Myklebust encode_putfh_maxsz + \ 7241da177e4SLinus Torvalds encode_getattr_maxsz) 7251da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 7269b7b9fccSAndy Adamson decode_sequence_maxsz + \ 727ab91f264STrond Myklebust decode_putfh_maxsz + \ 7281da177e4SLinus Torvalds decode_getattr_maxsz) 7291da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 7309b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7311da177e4SLinus Torvalds encode_putfh_maxsz + \ 732586f1c39STrond Myklebust encode_layoutreturn_maxsz + \ 733fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 734fa178f29STrond Myklebust encode_getattr_maxsz) 7351da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7369b7b9fccSAndy Adamson decode_sequence_maxsz + \ 737d8434d4cSTrond Myklebust decode_putfh_maxsz + \ 738586f1c39STrond Myklebust decode_layoutreturn_maxsz + \ 739fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 740fa178f29STrond Myklebust decode_getattr_maxsz) 741029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7429b7b9fccSAndy Adamson encode_sequence_maxsz + \ 743029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7449104a55dSTrond Myklebust encode_getacl_maxsz) 745029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7469b7b9fccSAndy Adamson decode_sequence_maxsz + \ 747029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7489104a55dSTrond Myklebust decode_getacl_maxsz) 74923ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7509b7b9fccSAndy Adamson encode_sequence_maxsz + \ 75123ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7529104a55dSTrond Myklebust encode_setacl_maxsz) 75323ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7549b7b9fccSAndy Adamson decode_sequence_maxsz + \ 75523ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7569104a55dSTrond Myklebust decode_setacl_maxsz) 757683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 758683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7599b7b9fccSAndy Adamson encode_sequence_maxsz + \ 760683b57b4STrond Myklebust encode_putfh_maxsz + \ 761e6889620STrond Myklebust encode_lookup_maxsz + \ 762b03d735bSChuck Lever encode_fs_locations_maxsz + \ 763b03d735bSChuck Lever encode_renew_maxsz) 764683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 765683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7669b7b9fccSAndy Adamson decode_sequence_maxsz + \ 767683b57b4STrond Myklebust decode_putfh_maxsz + \ 768e6889620STrond Myklebust decode_lookup_maxsz + \ 769b03d735bSChuck Lever decode_fs_locations_maxsz + \ 770b03d735bSChuck Lever decode_renew_maxsz) 7715a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7725a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7735a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7745a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7755a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7765a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7775a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7785a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 77944c99933SChuck Lever #define NFS4_enc_fsid_present_sz \ 78044c99933SChuck Lever (compound_encode_hdr_maxsz + \ 78144c99933SChuck Lever encode_sequence_maxsz + \ 78244c99933SChuck Lever encode_putfh_maxsz + \ 78344c99933SChuck Lever encode_getfh_maxsz + \ 78444c99933SChuck Lever encode_renew_maxsz) 78544c99933SChuck Lever #define NFS4_dec_fsid_present_sz \ 78644c99933SChuck Lever (compound_decode_hdr_maxsz + \ 78744c99933SChuck Lever decode_sequence_maxsz + \ 78844c99933SChuck Lever decode_putfh_maxsz + \ 78944c99933SChuck Lever decode_getfh_maxsz + \ 79044c99933SChuck Lever decode_renew_maxsz) 79199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 7927c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 7937c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 7947c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 7957c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 7967c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 7977c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 79899fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 79999fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 80099fe60d0SBenny Halevy encode_exchange_id_maxsz) 80199fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 80299fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 80399fe60d0SBenny Halevy decode_exchange_id_maxsz) 804fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 805fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 806fc931582SAndy Adamson encode_create_session_maxsz) 807fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 808fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 809fc931582SAndy Adamson decode_create_session_maxsz) 8100f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 8110f3e66c6SAndy Adamson encode_destroy_session_maxsz) 8120f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 8130f3e66c6SAndy Adamson decode_destroy_session_maxsz) 81466245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 81566245539STrond Myklebust encode_destroy_clientid_maxsz) 81666245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 81766245539STrond Myklebust decode_destroy_clientid_maxsz) 818fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 819fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 820fc01cea9SAndy Adamson encode_sequence_maxsz) 821fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 822fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 823fc01cea9SAndy Adamson decode_sequence_maxsz) 8242050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 8252050f0ccSAndy Adamson encode_sequence_maxsz + \ 8262050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 8272050f0ccSAndy Adamson encode_fsinfo_maxsz) 8282050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 8292050f0ccSAndy Adamson decode_sequence_maxsz + \ 8302050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 8312050f0ccSAndy Adamson decode_fsinfo_maxsz) 83218019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 83318019753SRicardo Labiaga encode_sequence_maxsz + \ 83418019753SRicardo Labiaga encode_reclaim_complete_maxsz) 83518019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 83618019753SRicardo Labiaga decode_sequence_maxsz + \ 83718019753SRicardo Labiaga decode_reclaim_complete_maxsz) 838b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 839b1f69b75SAndy Adamson encode_sequence_maxsz +\ 840b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 841b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 842b1f69b75SAndy Adamson decode_sequence_maxsz + \ 843b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 844b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 845b1f69b75SAndy Adamson encode_sequence_maxsz + \ 846b1f69b75SAndy Adamson encode_putfh_maxsz + \ 847b1f69b75SAndy Adamson encode_layoutget_maxsz) 848b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 849b1f69b75SAndy Adamson decode_sequence_maxsz + \ 850b1f69b75SAndy Adamson decode_putfh_maxsz + \ 851b1f69b75SAndy Adamson decode_layoutget_maxsz) 852863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 853863a3c6cSAndy Adamson encode_sequence_maxsz +\ 854863a3c6cSAndy Adamson encode_putfh_maxsz + \ 855863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 856863a3c6cSAndy Adamson encode_getattr_maxsz) 857863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 858863a3c6cSAndy Adamson decode_sequence_maxsz + \ 859863a3c6cSAndy Adamson decode_putfh_maxsz + \ 860863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 861863a3c6cSAndy Adamson decode_getattr_maxsz) 862cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 863cbe82603SBenny Halevy encode_sequence_maxsz + \ 864cbe82603SBenny Halevy encode_putfh_maxsz + \ 865cbe82603SBenny Halevy encode_layoutreturn_maxsz) 866cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 867cbe82603SBenny Halevy decode_sequence_maxsz + \ 868cbe82603SBenny Halevy decode_putfh_maxsz + \ 869cbe82603SBenny Halevy decode_layoutreturn_maxsz) 870fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 871fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 872fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 873fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 874fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 875fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 876fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 877fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8787d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8797d974794SBryan Schumaker encode_sequence_maxsz + \ 8807d974794SBryan Schumaker encode_test_stateid_maxsz) 8817d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8827d974794SBryan Schumaker decode_sequence_maxsz + \ 8837d974794SBryan Schumaker decode_test_stateid_maxsz) 8849aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8859aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8869aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8879aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8889aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8899aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8902449ea2eSAlexandros Batsakis 8912449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8922449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8932449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8942449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8952449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8962449ea2eSAlexandros Batsakis XDR_UNIT); 8972449ea2eSAlexandros Batsakis 8982449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8992449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 9002449ea2eSAlexandros Batsakis decode_sequence_maxsz + 9012449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 9022449ea2eSAlexandros Batsakis XDR_UNIT); 903f1c097beSAndy Adamson 904f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH + 905f1c097beSAndy Adamson compound_decode_hdr_maxsz + 906f1c097beSAndy Adamson decode_sequence_maxsz) * 907f1c097beSAndy Adamson XDR_UNIT); 908f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 90999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 9101da177e4SLinus Torvalds 911bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 912bca79478STrond Myklebust [NF4BAD] = 0, 913bca79478STrond Myklebust [NF4REG] = S_IFREG, 914bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 915bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 916bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 917bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 918bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 919bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 920bca79478STrond Myklebust [NF4ATTRDIR] = 0, 921bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 9221da177e4SLinus Torvalds }; 9231da177e4SLinus Torvalds 9241da177e4SLinus Torvalds struct compound_hdr { 9251da177e4SLinus Torvalds int32_t status; 9261da177e4SLinus Torvalds uint32_t nops; 927d017931cSAndy Adamson __be32 * nops_p; 9281da177e4SLinus Torvalds uint32_t taglen; 9291da177e4SLinus Torvalds char * tag; 9300c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 93166cc0429SBenny Halevy u32 minorversion; 9321da177e4SLinus Torvalds }; 9331da177e4SLinus Torvalds 93413c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 93513c65ce9SBenny Halevy { 93613c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 93713c65ce9SBenny Halevy BUG_ON(!p); 93813c65ce9SBenny Halevy return p; 93913c65ce9SBenny Halevy } 9401da177e4SLinus Torvalds 941cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 942cb17e556STrond Myklebust { 943ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); 944cb17e556STrond Myklebust } 945cb17e556STrond Myklebust 9461da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 9471da177e4SLinus Torvalds { 948ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0); 9491da177e4SLinus Torvalds } 9501da177e4SLinus Torvalds 9514ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9524ade9821STrond Myklebust { 953ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0); 9544ade9821STrond Myklebust } 9554ade9821STrond Myklebust 956ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 957ff2eb681STrond Myklebust { 958ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0); 959ff2eb681STrond Myklebust } 960ff2eb681STrond Myklebust 96137c88763STrond Myklebust static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr, 96237c88763STrond Myklebust const __u32 *bitmap, size_t len) 96337c88763STrond Myklebust { 96437c88763STrond Myklebust ssize_t ret; 96537c88763STrond Myklebust 96637c88763STrond Myklebust /* Trim empty words */ 96737c88763STrond Myklebust while (len > 0 && bitmap[len-1] == 0) 96837c88763STrond Myklebust len--; 96937c88763STrond Myklebust ret = xdr_stream_encode_uint32_array(xdr, bitmap, len); 97037c88763STrond Myklebust if (WARN_ON_ONCE(ret < 0)) 97137c88763STrond Myklebust return ret; 97237c88763STrond Myklebust return len; 97337c88763STrond Myklebust } 97437c88763STrond Myklebust 97537c88763STrond Myklebust static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask, 97637c88763STrond Myklebust __u32 *res, size_t len) 97737c88763STrond Myklebust { 97837c88763STrond Myklebust size_t i; 97937c88763STrond Myklebust __u32 tmp; 98037c88763STrond Myklebust 98137c88763STrond Myklebust while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0)) 98237c88763STrond Myklebust len--; 98337c88763STrond Myklebust for (i = len; i-- > 0;) { 98437c88763STrond Myklebust tmp = bitmap[i] & mask[i]; 98537c88763STrond Myklebust res[i] = tmp; 98637c88763STrond Myklebust } 98737c88763STrond Myklebust return len; 98837c88763STrond Myklebust } 98937c88763STrond Myklebust 9904ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9914ade9821STrond Myklebust const struct nfs_seqid *seqid) 9924ade9821STrond Myklebust { 993a6796419STrond Myklebust if (seqid != NULL) 9944ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 995a6796419STrond Myklebust else 996a6796419STrond Myklebust encode_uint32(xdr, 0); 9974ade9821STrond Myklebust } 9984ade9821STrond Myklebust 9990c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 10000c4e8c18SBenny Halevy struct rpc_rqst *req, 10010c4e8c18SBenny Halevy struct compound_hdr *hdr) 10021da177e4SLinus Torvalds { 10038687b63aSAl Viro __be32 *p; 1004a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 10050c4e8c18SBenny Halevy 10060c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 10070c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 10080c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 10090c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 10101da177e4SLinus Torvalds 10117fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 10126fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 10136fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 1014e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 1015d017931cSAndy Adamson hdr->nops_p = p; 101634558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 1017d017931cSAndy Adamson } 1018d017931cSAndy Adamson 1019ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 1020ab19b481STrond Myklebust uint32_t replen, 1021ab19b481STrond Myklebust struct compound_hdr *hdr) 1022ab19b481STrond Myklebust { 1023ab19b481STrond Myklebust encode_uint32(xdr, op); 1024ab19b481STrond Myklebust hdr->nops++; 1025ab19b481STrond Myklebust hdr->replen += replen; 1026ab19b481STrond Myklebust } 1027ab19b481STrond Myklebust 1028d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 1029d017931cSAndy Adamson { 10307fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 1031d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 10321da177e4SLinus Torvalds } 10331da177e4SLinus Torvalds 1034ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1035ea9d23f5STrond Myklebust { 10362d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 1037ea9d23f5STrond Myklebust } 1038ea9d23f5STrond Myklebust 10391da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 10401da177e4SLinus Torvalds { 1041cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 10421da177e4SLinus Torvalds } 10431da177e4SLinus Torvalds 1044aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1045aa9c2669SDavid Quigley const struct nfs4_label *label, 104628cf22d0STrond Myklebust const umode_t *umask, 10475334c5bdSKinglong Mee const struct nfs_server *server, 104828cf22d0STrond Myklebust const uint32_t attrmask[]) 10491da177e4SLinus Torvalds { 10501da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10511da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10521da177e4SLinus Torvalds int owner_namelen = 0; 10531da177e4SLinus Torvalds int owner_grouplen = 0; 10548687b63aSAl Viro __be32 *p; 1055d7067b2dSTrond Myklebust uint32_t len = 0; 1056d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10571da177e4SLinus Torvalds 10581da177e4SLinus Torvalds /* 10591da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10601da177e4SLinus Torvalds */ 106128cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) { 1062d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10631da177e4SLinus Torvalds len += 8; 1064d7067b2dSTrond Myklebust } 1065d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 106628cf22d0STrond Myklebust if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) { 1067dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK; 1068dff25ddbSAndreas Gruenbacher len += 8; 106928cf22d0STrond Myklebust } else if (attrmask[1] & FATTR4_WORD1_MODE) { 1070d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10711da177e4SLinus Torvalds len += 4; 1072d7067b2dSTrond Myklebust } 1073dff25ddbSAndreas Gruenbacher } 107428cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) { 1075e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10761da177e4SLinus Torvalds if (owner_namelen < 0) { 1077fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1078e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 10791da177e4SLinus Torvalds /* XXX */ 10801da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10811da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10821da177e4SLinus Torvalds /* goto out; */ 10831da177e4SLinus Torvalds } 1084d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 10851da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10861da177e4SLinus Torvalds } 108728cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_GID) && 108828cf22d0STrond Myklebust (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) { 1089e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10901da177e4SLinus Torvalds if (owner_grouplen < 0) { 1091fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1092e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 10931da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10941da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10951da177e4SLinus Torvalds /* goto out; */ 10961da177e4SLinus Torvalds } 1097d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 10981da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10991da177e4SLinus Torvalds } 110028cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 1101d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1102d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 11031da177e4SLinus Torvalds len += 16; 1104d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1105d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 11061da177e4SLinus Torvalds len += 4; 1107d7067b2dSTrond Myklebust } 110828cf22d0STrond Myklebust } 110928cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 1110d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1111d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 11121da177e4SLinus Torvalds len += 16; 1113d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1114d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 11151da177e4SLinus Torvalds len += 4; 1116d7067b2dSTrond Myklebust } 11175334c5bdSKinglong Mee } 11185334c5bdSKinglong Mee 111928cf22d0STrond Myklebust if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) { 1120b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1121d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1122d7067b2dSTrond Myklebust } 1123d7067b2dSTrond Myklebust 112440a3426cSTrond Myklebust xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval)); 112540a3426cSTrond Myklebust xdr_stream_encode_opaque_inline(xdr, (void **)&p, len); 11261da177e4SLinus Torvalds 1127d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1128b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1129d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1130e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1131d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1132811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1133d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1134811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1135d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11361da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1137e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1138042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec); 1139d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 1140d7067b2dSTrond Myklebust } else 1141e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11421da177e4SLinus Torvalds } 1143d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11441da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1145e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1146042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec); 1147e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 1148d7067b2dSTrond Myklebust } else 1149e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11501da177e4SLinus Torvalds } 1151d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1152aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1153aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1154aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1155aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1156aa9c2669SDavid Quigley } 1157dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1158dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1159dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask); 1160dff25ddbSAndreas Gruenbacher } 11611da177e4SLinus Torvalds 11621da177e4SLinus Torvalds /* out: */ 11631da177e4SLinus Torvalds } 11641da177e4SLinus Torvalds 1165cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11661da177e4SLinus Torvalds { 1167475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1168475d4ba0STrond Myklebust encode_uint32(xdr, access); 11691da177e4SLinus Torvalds } 11701da177e4SLinus Torvalds 1171cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11721da177e4SLinus Torvalds { 1173ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11744ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1175566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11761da177e4SLinus Torvalds } 11771da177e4SLinus Torvalds 11780b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11791da177e4SLinus Torvalds { 11808687b63aSAl Viro __be32 *p; 11811da177e4SLinus Torvalds 1182475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1183475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1184b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 118534558513SBenny Halevy *p = cpu_to_be32(args->count); 11861da177e4SLinus Torvalds } 11871da177e4SLinus Torvalds 1188cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11891da177e4SLinus Torvalds { 11908687b63aSAl Viro __be32 *p; 11911da177e4SLinus Torvalds 1192475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1193475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11941da177e4SLinus Torvalds 11951da177e4SLinus Torvalds switch (create->ftype) { 11961da177e4SLinus Torvalds case NF4LNK: 119713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 119834558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 11992fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 12002fcc213aSChuck Lever create->u.symlink.len); 12012fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 12021da177e4SLinus Torvalds break; 12031da177e4SLinus Torvalds 12041da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 120513c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1206e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 120734558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 12081da177e4SLinus Torvalds break; 12091da177e4SLinus Torvalds 12101da177e4SLinus Torvalds default: 12111da177e4SLinus Torvalds break; 12121da177e4SLinus Torvalds } 12131da177e4SLinus Torvalds 1214811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 121528cf22d0STrond Myklebust encode_attrs(xdr, create->attrs, create->label, &create->umask, 121628cf22d0STrond Myklebust create->server, create->server->attr_bitmask); 12171da177e4SLinus Torvalds } 12181da177e4SLinus Torvalds 121937c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr, 122037c88763STrond Myklebust const __u32 *bitmap, const __u32 *mask, size_t len, 1221dae100c2SFred Isaman struct compound_hdr *hdr) 1222dae100c2SFred Isaman { 122337c88763STrond Myklebust __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz]; 1224dae100c2SFred Isaman 1225ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 122637c88763STrond Myklebust if (mask) { 122737c88763STrond Myklebust if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap))) 122837c88763STrond Myklebust len = ARRAY_SIZE(masked_bitmap); 122937c88763STrond Myklebust len = mask_bitmap4(bitmap, mask, masked_bitmap, len); 123037c88763STrond Myklebust bitmap = masked_bitmap; 1231dae100c2SFred Isaman } 123237c88763STrond Myklebust xdr_encode_bitmap4(xdr, bitmap, len); 1233dae100c2SFred Isaman } 1234dae100c2SFred Isaman 1235cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12361da177e4SLinus Torvalds { 123737c88763STrond Myklebust encode_getattr(xdr, nfs4_fattr_bitmap, bitmask, 123837c88763STrond Myklebust ARRAY_SIZE(nfs4_fattr_bitmap), hdr); 12391da177e4SLinus Torvalds } 12401da177e4SLinus Torvalds 124188034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12421549210fSTrond Myklebust const u32 *open_bitmap, 124388034c3dSAndy Adamson struct compound_hdr *hdr) 124488034c3dSAndy Adamson { 124537c88763STrond Myklebust encode_getattr(xdr, open_bitmap, bitmask, 3, hdr); 124688034c3dSAndy Adamson } 124788034c3dSAndy Adamson 1248cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12491da177e4SLinus Torvalds { 125037c88763STrond Myklebust encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask, 125137c88763STrond Myklebust ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr); 12521da177e4SLinus Torvalds } 12531da177e4SLinus Torvalds 1254cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1255830b8e33SManoj Naik { 125637c88763STrond Myklebust encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask, 125737c88763STrond Myklebust ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr); 1258830b8e33SManoj Naik } 1259830b8e33SManoj Naik 1260cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12611da177e4SLinus Torvalds { 1262ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12631da177e4SLinus Torvalds } 12641da177e4SLinus Torvalds 1265cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12661da177e4SLinus Torvalds { 1267ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12686fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12691da177e4SLinus Torvalds } 12701da177e4SLinus Torvalds 1271911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1272911d1aafSTrond Myklebust { 1273f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1274911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1275911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1276911d1aafSTrond Myklebust } 1277911d1aafSTrond Myklebust 1278911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1279911d1aafSTrond Myklebust { 1280911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1281911d1aafSTrond Myklebust return ~(uint64_t)0; 1282911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1283911d1aafSTrond Myklebust } 1284911d1aafSTrond Myklebust 1285daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1286daccbdedSTrond Myklebust { 1287daccbdedSTrond Myklebust __be32 *p; 1288daccbdedSTrond Myklebust 1289d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1290daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1291d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1292daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1293d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1294daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1295daccbdedSTrond Myklebust } 1296daccbdedSTrond Myklebust 12971da177e4SLinus Torvalds /* 12981da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 12991da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13001da177e4SLinus Torvalds */ 1301cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13021da177e4SLinus Torvalds { 13038687b63aSAl Viro __be32 *p; 13041da177e4SLinus Torvalds 1305475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1306475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1307e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1308e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1309b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1310b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 131134558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1312911d1aafSTrond Myklebust if (args->new_lock_owner){ 13134ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1314425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13154ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1316daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13171da177e4SLinus Torvalds } 13181da177e4SLinus Torvalds else { 1319425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13204ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13211da177e4SLinus Torvalds } 13221da177e4SLinus Torvalds } 13231da177e4SLinus Torvalds 1324cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13251da177e4SLinus Torvalds { 13268687b63aSAl Viro __be32 *p; 13271da177e4SLinus Torvalds 1328475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1329475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1330e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1331b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1332b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1333daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13341da177e4SLinus Torvalds } 13351da177e4SLinus Torvalds 1336cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13371da177e4SLinus Torvalds { 13388687b63aSAl Viro __be32 *p; 13391da177e4SLinus Torvalds 1340475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1341475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13424ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1343425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1344ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1345b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 134634558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13471da177e4SLinus Torvalds } 13481da177e4SLinus Torvalds 1349d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1350d3c7b7ccSTrond Myklebust { 1351ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1352d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1353d3c7b7ccSTrond Myklebust } 1354d3c7b7ccSTrond Myklebust 1355cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13561da177e4SLinus Torvalds { 1357ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13586fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13591da177e4SLinus Torvalds } 13601da177e4SLinus Torvalds 13615b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr) 13625b5faaf6SJeff Layton { 13635b5faaf6SJeff Layton encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr); 13645b5faaf6SJeff Layton } 13655b5faaf6SJeff Layton 13666ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13671da177e4SLinus Torvalds { 13688687b63aSAl Viro __be32 *p; 13691da177e4SLinus Torvalds 137013c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13716ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 137234558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13731da177e4SLinus Torvalds } 13741da177e4SLinus Torvalds 13751da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13761da177e4SLinus Torvalds { 13778687b63aSAl Viro __be32 *p; 13781da177e4SLinus Torvalds /* 13791da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13801da177e4SLinus Torvalds * owner 4 = 32 13811da177e4SLinus Torvalds */ 13824ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 13836ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 138495b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1385b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 138695b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 138793f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1388d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 138995b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 139095b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 13911da177e4SLinus Torvalds } 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13941da177e4SLinus Torvalds { 13958687b63aSAl Viro __be32 *p; 13961da177e4SLinus Torvalds 139713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1398549b19ccSTrond Myklebust switch(arg->createmode) { 1399549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 140034558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 140128cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 140228cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 14031da177e4SLinus Torvalds break; 1404549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14054882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 140628cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 140728cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 1408549b19ccSTrond Myklebust break; 1409549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1410549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1411549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1412549b19ccSTrond Myklebust break; 1413549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14144882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14154882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 141628cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 141728cf22d0STrond Myklebust arg->server, arg->server->exclcreat_bitmask); 14184882ef72SAlexandros Batsakis } 14194882ef72SAlexandros Batsakis } 14201da177e4SLinus Torvalds 14211da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14221da177e4SLinus Torvalds { 14238687b63aSAl Viro __be32 *p; 14241da177e4SLinus Torvalds 142513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14261da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14271da177e4SLinus Torvalds case 0: 142834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14291da177e4SLinus Torvalds break; 14301da177e4SLinus Torvalds default: 143134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14321da177e4SLinus Torvalds encode_createmode(xdr, arg); 14331da177e4SLinus Torvalds } 14341da177e4SLinus Torvalds } 14351da177e4SLinus Torvalds 1436bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14371da177e4SLinus Torvalds { 14388687b63aSAl Viro __be32 *p; 14391da177e4SLinus Torvalds 144013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14411da177e4SLinus Torvalds switch (delegation_type) { 14421da177e4SLinus Torvalds case 0: 144334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14441da177e4SLinus Torvalds break; 14451da177e4SLinus Torvalds case FMODE_READ: 144634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14471da177e4SLinus Torvalds break; 14481da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 144934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14501da177e4SLinus Torvalds break; 14511da177e4SLinus Torvalds default: 14521da177e4SLinus Torvalds BUG(); 14531da177e4SLinus Torvalds } 14541da177e4SLinus Torvalds } 14551da177e4SLinus Torvalds 14561da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14571da177e4SLinus Torvalds { 14588687b63aSAl Viro __be32 *p; 14591da177e4SLinus Torvalds 146013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 146134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14621da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14631da177e4SLinus Torvalds } 14641da177e4SLinus Torvalds 1465bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14661da177e4SLinus Torvalds { 14678687b63aSAl Viro __be32 *p; 14681da177e4SLinus Torvalds 146913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 147034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14711da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14721da177e4SLinus Torvalds } 14731da177e4SLinus Torvalds 14741da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14751da177e4SLinus Torvalds { 14768687b63aSAl Viro __be32 *p; 14771da177e4SLinus Torvalds 1478ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1479ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1480ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14811da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14821da177e4SLinus Torvalds } 14831da177e4SLinus Torvalds 1484d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1485d9fc6619STrond Myklebust { 1486d9fc6619STrond Myklebust __be32 *p; 1487d9fc6619STrond Myklebust 1488d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1489d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1490d9fc6619STrond Myklebust } 1491d9fc6619STrond Myklebust 1492d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1493d9fc6619STrond Myklebust { 1494d9fc6619STrond Myklebust __be32 *p; 1495d9fc6619STrond Myklebust 1496d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1497d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1498d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1499d9fc6619STrond Myklebust } 1500d9fc6619STrond Myklebust 1501cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15021da177e4SLinus Torvalds { 1503ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15041da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15051da177e4SLinus Torvalds encode_opentype(xdr, arg); 15061da177e4SLinus Torvalds switch (arg->claim) { 15071da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15081da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15091da177e4SLinus Torvalds break; 15101da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15111da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15121da177e4SLinus Torvalds break; 15131da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15141da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15151da177e4SLinus Torvalds break; 1516d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1517d9fc6619STrond Myklebust encode_claim_fh(xdr); 1518d9fc6619STrond Myklebust break; 1519d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1520d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1521d9fc6619STrond Myklebust break; 15221da177e4SLinus Torvalds default: 15231da177e4SLinus Torvalds BUG(); 15241da177e4SLinus Torvalds } 15251da177e4SLinus Torvalds } 15261da177e4SLinus Torvalds 1527cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15281da177e4SLinus Torvalds { 1529ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1530ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15314ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15321da177e4SLinus Torvalds } 15331da177e4SLinus Torvalds 1534cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15351da177e4SLinus Torvalds { 1536ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1537566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15384ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15396ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15401da177e4SLinus Torvalds } 15411da177e4SLinus Torvalds 1542cf8cdbe5SAndy Adamson static void 1543d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15441da177e4SLinus Torvalds { 1545ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15466fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15471da177e4SLinus Torvalds } 15481da177e4SLinus Torvalds 1549cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15501da177e4SLinus Torvalds { 1551ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15521da177e4SLinus Torvalds } 15531da177e4SLinus Torvalds 15543c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15553c6b899cSAnna Schumaker struct compound_hdr *hdr) 15561da177e4SLinus Torvalds { 15578687b63aSAl Viro __be32 *p; 15581da177e4SLinus Torvalds 1559ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15609b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15611da177e4SLinus Torvalds 156213c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1563b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 156434558513SBenny Halevy *p = cpu_to_be32(args->count); 15651da177e4SLinus Torvalds } 15661da177e4SLinus Torvalds 1567cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15681da177e4SLinus Torvalds { 1569aa9c2669SDavid Quigley uint32_t attrs[3] = { 157028331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 157128331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 157228331a46STrond Myklebust }; 15736f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1574cd93710eSChuck Lever __be32 *p, verf[2]; 1575d204c5d2STrond Myklebust uint32_t attrlen = 0; 1576d204c5d2STrond Myklebust unsigned int i; 15771da177e4SLinus Torvalds 157882f2e547SBryan Schumaker if (readdir->plus) { 157982f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 158028331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 158182f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 158282f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 158382f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 158482f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1585d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 15866f7a35bdSTrond Myklebust dircount >>= 1; 158782f2e547SBryan Schumaker } 158828331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 158928331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 159028331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1591d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1592d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1593d204c5d2STrond Myklebust if (attrs[i] != 0) 1594d204c5d2STrond Myklebust attrlen = i+1; 1595d204c5d2STrond Myklebust } 15966f7a35bdSTrond Myklebust 1597475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1598ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1599cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1600d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16016f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16026f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1603d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1604d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1605d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1606cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1607aa9c2669SDavid Quigley 1608aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 160944109241SFred Isaman __func__, 1610eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1611cd93710eSChuck Lever verf[0], verf[1], 1612eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1613aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1614aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16151da177e4SLinus Torvalds } 16161da177e4SLinus Torvalds 1617cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16181da177e4SLinus Torvalds { 1619ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16201da177e4SLinus Torvalds } 16211da177e4SLinus Torvalds 1622cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16231da177e4SLinus Torvalds { 1624ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16256fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16261da177e4SLinus Torvalds } 16271da177e4SLinus Torvalds 1628cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16291da177e4SLinus Torvalds { 1630ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1631811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1632811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16331da177e4SLinus Torvalds } 16341da177e4SLinus Torvalds 1635bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1636bb4dae5eSChuck Lever struct compound_hdr *hdr) 16371da177e4SLinus Torvalds { 1638475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1639ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16401da177e4SLinus Torvalds } 16411da177e4SLinus Torvalds 1642cf8cdbe5SAndy Adamson static void 1643d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 164456ae19f3STrond Myklebust { 1645ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 164656ae19f3STrond Myklebust } 164756ae19f3STrond Myklebust 16489f06c719SChuck Lever static void 1649fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg, 1650fcc85819SChristoph Hellwig struct compound_hdr *hdr) 165123ec6965SJ. Bruce Fields { 16528687b63aSAl Viro __be32 *p; 165323ec6965SJ. Bruce Fields 1654ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1655ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 165613c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1657e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 165834558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 165913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 166034558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16618fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 166223ec6965SJ. Bruce Fields } 166323ec6965SJ. Bruce Fields 1664cf8cdbe5SAndy Adamson static void 1665d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16661da177e4SLinus Torvalds { 1667ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16681da177e4SLinus Torvalds } 16691da177e4SLinus Torvalds 1670cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16711da177e4SLinus Torvalds { 1672ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1673ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 167428cf22d0STrond Myklebust encode_attrs(xdr, arg->iap, arg->label, NULL, server, 167528cf22d0STrond Myklebust server->attr_bitmask); 16761da177e4SLinus Torvalds } 16771da177e4SLinus Torvalds 1678cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16791da177e4SLinus Torvalds { 16808687b63aSAl Viro __be32 *p; 16811da177e4SLinus Torvalds 168270019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1683cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16841da177e4SLinus Torvalds 16853a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 16863a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 168713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 168834558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16891da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16901da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 169113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 16923a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 16931da177e4SLinus Torvalds } 16941da177e4SLinus Torvalds 1695bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16961da177e4SLinus Torvalds { 1697475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1698475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1699ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1700cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17011da177e4SLinus Torvalds } 17021da177e4SLinus Torvalds 17033c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17043c6b899cSAnna Schumaker struct compound_hdr *hdr) 17051da177e4SLinus Torvalds { 17068687b63aSAl Viro __be32 *p; 17071da177e4SLinus Torvalds 1708ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17099b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17101da177e4SLinus Torvalds 171113c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1712b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1713e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 171434558513SBenny Halevy *p = cpu_to_be32(args->count); 17151da177e4SLinus Torvalds 17161da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17171da177e4SLinus Torvalds } 17181da177e4SLinus Torvalds 1719cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17201da177e4SLinus Torvalds { 1721ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1722ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17231da177e4SLinus Torvalds } 17249b7b9fccSAndy Adamson 17255a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17265a5ea0d4SBryan Schumaker { 1727ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17286fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17295a5ea0d4SBryan Schumaker } 17305a5ea0d4SBryan Schumaker 173199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17329b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17337c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 1734fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args, 17357c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17367c44f1aeSWeston Andros Adamson { 17377c44f1aeSWeston Andros Adamson __be32 *p; 17387c44f1aeSWeston Andros Adamson 17397c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17407c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 174171a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17427c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 174371a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 174471a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17457c44f1aeSWeston Andros Adamson } 17467c44f1aeSWeston Andros Adamson 1747fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map) 17482031cd1aSWeston Andros Adamson { 17492031cd1aSWeston Andros Adamson unsigned int i; 17502031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17512031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17522031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17532031cd1aSWeston Andros Adamson } 17542031cd1aSWeston Andros Adamson 175599fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 1756fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args, 175799fe60d0SBenny Halevy struct compound_hdr *hdr) 175899fe60d0SBenny Halevy { 175999fe60d0SBenny Halevy __be32 *p; 1760d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1761db8ac8baSWeston Andros Adamson int len = 0; 176299fe60d0SBenny Halevy 176370019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1764fd40559cSTrond Myklebust encode_nfs4_verifier(xdr, &args->verifier); 176599fe60d0SBenny Halevy 17663a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17673a6bb738SJeff Layton args->client->cl_owner_id); 176899fe60d0SBenny Halevy 17692031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17702031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17712031cd1aSWeston Andros Adamson 17722031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17732031cd1aSWeston Andros Adamson case SP4_NONE: 17742031cd1aSWeston Andros Adamson break; 17752031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17762031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 17772031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 17782031cd1aSWeston Andros Adamson break; 17792031cd1aSWeston Andros Adamson default: 17802031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 17812031cd1aSWeston Andros Adamson break; 17822031cd1aSWeston Andros Adamson } 1783db8ac8baSWeston Andros Adamson 1784db8ac8baSWeston Andros Adamson if (send_implementation_id && 1785db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1786db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1787d751f748SJim Rees <= sizeof(impl_name) + 1) 1788db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1789db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1790db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1791db8ac8baSWeston Andros Adamson 1792db8ac8baSWeston Andros Adamson if (len > 0) { 17932031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1794db8ac8baSWeston Andros Adamson 1795db8ac8baSWeston Andros Adamson encode_string(xdr, 1796db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1797db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1798db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1799db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1800db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1801db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1802db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1803db8ac8baSWeston Andros Adamson } else 18042031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 180599fe60d0SBenny Halevy } 1806fc931582SAndy Adamson 1807fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1808fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args, 1809fc931582SAndy Adamson struct compound_hdr *hdr) 1810fc931582SAndy Adamson { 1811fc931582SAndy Adamson __be32 *p; 1812fc931582SAndy Adamson struct nfs_client *clp = args->client; 181389f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1814f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18158e0d46e1SMike Sager u32 max_resp_sz_cached; 18168e0d46e1SMike Sager 18178e0d46e1SMike Sager /* 18188e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18198e0d46e1SMike Sager * 2 is the verifier. 18208e0d46e1SMike Sager */ 182135c036efSJ. Bruce Fields max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2) 182235c036efSJ. Bruce Fields * XDR_UNIT + RPC_MAX_AUTH_SIZE; 1823fc931582SAndy Adamson 1824475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 182589f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 182679969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 182779969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1828e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1829fc931582SAndy Adamson 1830fc931582SAndy Adamson /* Fore Channel */ 1831c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1832e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1833e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18348e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1835e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1836e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1837e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1838fc931582SAndy Adamson 1839fc931582SAndy Adamson /* Back Channel */ 1840c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1841e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1842e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1843e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1844e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1845e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1846e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1847fc931582SAndy Adamson 1848e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1849e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1850e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1851fc931582SAndy Adamson 1852fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18532f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 185489f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1856e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 185734558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1858fc931582SAndy Adamson } 18590f3e66c6SAndy Adamson 18600f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 1861fcc85819SChristoph Hellwig const struct nfs4_session *session, 18620f3e66c6SAndy Adamson struct compound_hdr *hdr) 18630f3e66c6SAndy Adamson { 1864475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1865475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18660f3e66c6SAndy Adamson } 186718019753SRicardo Labiaga 186866245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 186966245539STrond Myklebust uint64_t clientid, 187066245539STrond Myklebust struct compound_hdr *hdr) 187166245539STrond Myklebust { 187266245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 187366245539STrond Myklebust encode_uint64(xdr, clientid); 187466245539STrond Myklebust } 187566245539STrond Myklebust 187618019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 1877fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args, 187818019753SRicardo Labiaga struct compound_hdr *hdr) 187918019753SRicardo Labiaga { 1880475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1881475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 188218019753SRicardo Labiaga } 188399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 188499fe60d0SBenny Halevy 18859b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18869b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18879b7b9fccSAndy Adamson struct compound_hdr *hdr) 18889b7b9fccSAndy Adamson { 18899b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18902b2fa717STrond Myklebust struct nfs4_session *session; 1891fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 18922b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1893fc01cea9SAndy Adamson __be32 *p; 18949b7b9fccSAndy Adamson 18952b2fa717STrond Myklebust tp = slot->table; 18962b2fa717STrond Myklebust session = tp->session; 18973bd2384aSChuck Lever if (!session) 18983bd2384aSChuck Lever return; 1899fc01cea9SAndy Adamson 1900475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1901fc01cea9SAndy Adamson 1902fc01cea9SAndy Adamson /* 1903fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1904fc01cea9SAndy Adamson */ 1905fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1906fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1907fc01cea9SAndy Adamson __func__, 1908fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1909fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1910fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1911fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19122b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1913fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1914475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 191593f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1916e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19172b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1918e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 191934558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19209b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19219b7b9fccSAndy Adamson } 19229b7b9fccSAndy Adamson 1923b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1924b1f69b75SAndy Adamson static void 1925b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1926b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1927b1f69b75SAndy Adamson struct compound_hdr *hdr) 1928b1f69b75SAndy Adamson { 1929b1f69b75SAndy Adamson __be32 *p; 1930b1f69b75SAndy Adamson 1931475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 193284c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1933b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1934b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1935b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1936f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 193784c9dee3SChristoph Hellwig 193884c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 193984c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19404e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1941b1f69b75SAndy Adamson } 1942b1f69b75SAndy Adamson 1943b1f69b75SAndy Adamson static void 1944b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1945b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1946b1f69b75SAndy Adamson struct compound_hdr *hdr) 1947b1f69b75SAndy Adamson { 1948b1f69b75SAndy Adamson __be32 *p; 1949b1f69b75SAndy Adamson 1950475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1951475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1952b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1953b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1954b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1955b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1956b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1957b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1958ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1959475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1960b1f69b75SAndy Adamson 1961b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1962b1f69b75SAndy Adamson __func__, 1963b1f69b75SAndy Adamson args->type, 1964b1f69b75SAndy Adamson args->range.iomode, 1965b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1966b1f69b75SAndy Adamson (unsigned long)args->range.length, 1967b1f69b75SAndy Adamson args->maxcount); 1968b1f69b75SAndy Adamson } 1969863a3c6cSAndy Adamson 1970863a3c6cSAndy Adamson static int 1971863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1972ac7db726SBenny Halevy struct inode *inode, 1973fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args, 1974863a3c6cSAndy Adamson struct compound_hdr *hdr) 1975863a3c6cSAndy Adamson { 1976863a3c6cSAndy Adamson __be32 *p; 1977863a3c6cSAndy Adamson 1978863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1979863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1980863a3c6cSAndy Adamson 1981475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1982475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1983863a3c6cSAndy Adamson /* Only whole file layouts */ 1984863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19853557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1986ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1987ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 19882e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 1989ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1990863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1991863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 19922e18d4d8STrond Myklebust } else { 19932e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 19942e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 19952e18d4d8STrond Myklebust } 1996863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1997863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 1998ac7db726SBenny Halevy 19995f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 200073504740STrond Myklebust if (args->layoutupdate_pages) 20015f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20025f919c9fSChristoph Hellwig args->layoutupdate_len); 2003863a3c6cSAndy Adamson 2004863a3c6cSAndy Adamson return 0; 2005863a3c6cSAndy Adamson } 2006cbe82603SBenny Halevy 2007cbe82603SBenny Halevy static void 2008cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2009cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2010cbe82603SBenny Halevy struct compound_hdr *hdr) 2011cbe82603SBenny Halevy { 2012cbe82603SBenny Halevy __be32 *p; 2013cbe82603SBenny Halevy 2014475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2015475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2016cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2017cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 201815eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2019cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2020ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 202115eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 202215eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2023cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2024ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2025cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20264d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20274d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 202894e5c571STrond Myklebust else 2029475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2030cbe82603SBenny Halevy } 2031fca78d6dSBryan Schumaker 2032fca78d6dSBryan Schumaker static int 2033fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2034fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2035fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2036fca78d6dSBryan Schumaker { 2037475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2038475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2039fca78d6dSBryan Schumaker return 0; 2040fca78d6dSBryan Schumaker } 20417d974794SBryan Schumaker 20427d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 2043fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args, 20447d974794SBryan Schumaker struct compound_hdr *hdr) 20457d974794SBryan Schumaker { 2046475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2047475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2048ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20497d974794SBryan Schumaker } 20509aeda35fSBryan Schumaker 20519aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 2052fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args, 20539aeda35fSBryan Schumaker struct compound_hdr *hdr) 20549aeda35fSBryan Schumaker { 2055ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20567c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20579aeda35fSBryan Schumaker } 2058cf805165STrond Myklebust #else 2059cf805165STrond Myklebust static inline void 2060cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2061cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2062cf805165STrond Myklebust struct compound_hdr *hdr) 2063cf805165STrond Myklebust { 2064cf805165STrond Myklebust } 2065b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2066b1f69b75SAndy Adamson 20671da177e4SLinus Torvalds /* 20681da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20691da177e4SLinus Torvalds */ 20701da177e4SLinus Torvalds 207166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 207266cc0429SBenny Halevy { 207366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 20743bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 20753bd2384aSChuck Lever if (session) 20763bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 207766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 207866cc0429SBenny Halevy return 0; 207966cc0429SBenny Halevy } 208066cc0429SBenny Halevy 20811da177e4SLinus Torvalds /* 20821da177e4SLinus Torvalds * Encode an ACCESS request 20831da177e4SLinus Torvalds */ 20849f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 2085fcc85819SChristoph Hellwig const void *data) 20861da177e4SLinus Torvalds { 2087fcc85819SChristoph Hellwig const struct nfs4_accessargs *args = data; 20881da177e4SLinus Torvalds struct compound_hdr hdr = { 208966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20901da177e4SLinus Torvalds }; 20911da177e4SLinus Torvalds 20929f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20939f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20949f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20959f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 20969f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2097d017931cSAndy Adamson encode_nops(&hdr); 20981da177e4SLinus Torvalds } 20991da177e4SLinus Torvalds 21001da177e4SLinus Torvalds /* 21011da177e4SLinus Torvalds * Encode LOOKUP request 21021da177e4SLinus Torvalds */ 21039f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 2104fcc85819SChristoph Hellwig const void *data) 21051da177e4SLinus Torvalds { 2106fcc85819SChristoph Hellwig const struct nfs4_lookup_arg *args = data; 21071da177e4SLinus Torvalds struct compound_hdr hdr = { 210866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21091da177e4SLinus Torvalds }; 21101da177e4SLinus Torvalds 21119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21139f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21149f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21159f06c719SChuck Lever encode_getfh(xdr, &hdr); 21169f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2117d017931cSAndy Adamson encode_nops(&hdr); 21181da177e4SLinus Torvalds } 21191da177e4SLinus Torvalds 21201da177e4SLinus Torvalds /* 21215b5faaf6SJeff Layton * Encode LOOKUPP request 21225b5faaf6SJeff Layton */ 21235b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr, 21245b5faaf6SJeff Layton const void *data) 21255b5faaf6SJeff Layton { 21265b5faaf6SJeff Layton const struct nfs4_lookupp_arg *args = data; 21275b5faaf6SJeff Layton struct compound_hdr hdr = { 21285b5faaf6SJeff Layton .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21295b5faaf6SJeff Layton }; 21305b5faaf6SJeff Layton 21315b5faaf6SJeff Layton encode_compound_hdr(xdr, req, &hdr); 21325b5faaf6SJeff Layton encode_sequence(xdr, &args->seq_args, &hdr); 21335b5faaf6SJeff Layton encode_putfh(xdr, args->fh, &hdr); 21345b5faaf6SJeff Layton encode_lookupp(xdr, &hdr); 21355b5faaf6SJeff Layton encode_getfh(xdr, &hdr); 21365b5faaf6SJeff Layton encode_getfattr(xdr, args->bitmask, &hdr); 21375b5faaf6SJeff Layton encode_nops(&hdr); 21385b5faaf6SJeff Layton } 21395b5faaf6SJeff Layton 21405b5faaf6SJeff Layton /* 21411da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21421da177e4SLinus Torvalds */ 21439f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21449f06c719SChuck Lever struct xdr_stream *xdr, 2145fcc85819SChristoph Hellwig const void *data) 21461da177e4SLinus Torvalds { 2147fcc85819SChristoph Hellwig const struct nfs4_lookup_root_arg *args = data; 21481da177e4SLinus Torvalds struct compound_hdr hdr = { 214966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21501da177e4SLinus Torvalds }; 21511da177e4SLinus Torvalds 21529f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21539f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21549f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21559f06c719SChuck Lever encode_getfh(xdr, &hdr); 21569f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2157d017931cSAndy Adamson encode_nops(&hdr); 21581da177e4SLinus Torvalds } 21591da177e4SLinus Torvalds 21601da177e4SLinus Torvalds /* 21611da177e4SLinus Torvalds * Encode REMOVE request 21621da177e4SLinus Torvalds */ 21639f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 2164fcc85819SChristoph Hellwig const void *data) 21651da177e4SLinus Torvalds { 2166fcc85819SChristoph Hellwig const struct nfs_removeargs *args = data; 21671da177e4SLinus Torvalds struct compound_hdr hdr = { 216866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21691da177e4SLinus Torvalds }; 21701da177e4SLinus Torvalds 21719f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21729f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21739f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21749f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2175d017931cSAndy Adamson encode_nops(&hdr); 21761da177e4SLinus Torvalds } 21771da177e4SLinus Torvalds 21781da177e4SLinus Torvalds /* 21791da177e4SLinus Torvalds * Encode RENAME request 21801da177e4SLinus Torvalds */ 21819f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 2182fcc85819SChristoph Hellwig const void *data) 21831da177e4SLinus Torvalds { 2184fcc85819SChristoph Hellwig const struct nfs_renameargs *args = data; 21851da177e4SLinus Torvalds struct compound_hdr hdr = { 218666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21871da177e4SLinus Torvalds }; 21881da177e4SLinus Torvalds 21899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21919f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21929f06c719SChuck Lever encode_savefh(xdr, &hdr); 21939f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21949f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2195d017931cSAndy Adamson encode_nops(&hdr); 21961da177e4SLinus Torvalds } 21971da177e4SLinus Torvalds 21981da177e4SLinus Torvalds /* 21991da177e4SLinus Torvalds * Encode LINK request 22001da177e4SLinus Torvalds */ 22019f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 2202fcc85819SChristoph Hellwig const void *data) 22031da177e4SLinus Torvalds { 2204fcc85819SChristoph Hellwig const struct nfs4_link_arg *args = data; 22051da177e4SLinus Torvalds struct compound_hdr hdr = { 220666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22071da177e4SLinus Torvalds }; 22081da177e4SLinus Torvalds 22099f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22109f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22119f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22129f06c719SChuck Lever encode_savefh(xdr, &hdr); 22139f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22149f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22159f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22169f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2217d017931cSAndy Adamson encode_nops(&hdr); 22181da177e4SLinus Torvalds } 22191da177e4SLinus Torvalds 22201da177e4SLinus Torvalds /* 22211da177e4SLinus Torvalds * Encode CREATE request 22221da177e4SLinus Torvalds */ 22239f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 2224fcc85819SChristoph Hellwig const void *data) 22251da177e4SLinus Torvalds { 2226fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 22271da177e4SLinus Torvalds struct compound_hdr hdr = { 222866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22291da177e4SLinus Torvalds }; 22301da177e4SLinus Torvalds 22319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22339f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22349f06c719SChuck Lever encode_create(xdr, args, &hdr); 22359f06c719SChuck Lever encode_getfh(xdr, &hdr); 22369f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2237d017931cSAndy Adamson encode_nops(&hdr); 22381da177e4SLinus Torvalds } 22391da177e4SLinus Torvalds 22401da177e4SLinus Torvalds /* 22411da177e4SLinus Torvalds * Encode SYMLINK request 22421da177e4SLinus Torvalds */ 22439f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2244fcc85819SChristoph Hellwig const void *data) 22451da177e4SLinus Torvalds { 2246fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 2247fcc85819SChristoph Hellwig 22489f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22491da177e4SLinus Torvalds } 22501da177e4SLinus Torvalds 22511da177e4SLinus Torvalds /* 22521da177e4SLinus Torvalds * Encode GETATTR request 22531da177e4SLinus Torvalds */ 22549f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2255fcc85819SChristoph Hellwig const void *data) 22561da177e4SLinus Torvalds { 2257fcc85819SChristoph Hellwig const struct nfs4_getattr_arg *args = data; 22581da177e4SLinus Torvalds struct compound_hdr hdr = { 225966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22601da177e4SLinus Torvalds }; 22611da177e4SLinus Torvalds 22629f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22639f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22649f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22659f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2266d017931cSAndy Adamson encode_nops(&hdr); 22671da177e4SLinus Torvalds } 22681da177e4SLinus Torvalds 22691da177e4SLinus Torvalds /* 22701da177e4SLinus Torvalds * Encode a CLOSE request 22711da177e4SLinus Torvalds */ 22729f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 2273fcc85819SChristoph Hellwig const void *data) 22741da177e4SLinus Torvalds { 2275fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 22761da177e4SLinus Torvalds struct compound_hdr hdr = { 227766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22781da177e4SLinus Torvalds }; 22791da177e4SLinus Torvalds 22809f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22819f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22829f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2283cf805165STrond Myklebust if (args->lr_args) 2284cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 22853ecefc92STrond Myklebust if (args->bitmask != NULL) 22869f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2287d8d84983STrond Myklebust encode_close(xdr, args, &hdr); 2288d017931cSAndy Adamson encode_nops(&hdr); 22891da177e4SLinus Torvalds } 22901da177e4SLinus Torvalds 22911da177e4SLinus Torvalds /* 22921da177e4SLinus Torvalds * Encode an OPEN request 22931da177e4SLinus Torvalds */ 22949f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 2295fcc85819SChristoph Hellwig const void *data) 22961da177e4SLinus Torvalds { 2297fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 22981da177e4SLinus Torvalds struct compound_hdr hdr = { 229966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23001da177e4SLinus Torvalds }; 23011da177e4SLinus Torvalds 23029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23049f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23059f06c719SChuck Lever encode_open(xdr, args, &hdr); 23069f06c719SChuck Lever encode_getfh(xdr, &hdr); 2307ae2bb032SWeston Andros Adamson if (args->access) 23086168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 23091549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2310d017931cSAndy Adamson encode_nops(&hdr); 23111da177e4SLinus Torvalds } 23121da177e4SLinus Torvalds 23131da177e4SLinus Torvalds /* 23141da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 23151da177e4SLinus Torvalds */ 23169f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 23179f06c719SChuck Lever struct xdr_stream *xdr, 2318fcc85819SChristoph Hellwig const void *data) 23191da177e4SLinus Torvalds { 2320fcc85819SChristoph Hellwig const struct nfs_open_confirmargs *args = data; 23211da177e4SLinus Torvalds struct compound_hdr hdr = { 2322d017931cSAndy Adamson .nops = 0, 23231da177e4SLinus Torvalds }; 23241da177e4SLinus Torvalds 23259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23269f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23279f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2328d017931cSAndy Adamson encode_nops(&hdr); 23291da177e4SLinus Torvalds } 23301da177e4SLinus Torvalds 23311da177e4SLinus Torvalds /* 23321da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23331da177e4SLinus Torvalds */ 23349f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23359f06c719SChuck Lever struct xdr_stream *xdr, 2336fcc85819SChristoph Hellwig const void *data) 23371da177e4SLinus Torvalds { 2338fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23391da177e4SLinus Torvalds struct compound_hdr hdr = { 234066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23411da177e4SLinus Torvalds }; 23421da177e4SLinus Torvalds 23439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23459f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23469f06c719SChuck Lever encode_open(xdr, args, &hdr); 2347ae2bb032SWeston Andros Adamson if (args->access) 23486168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2349e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2350d017931cSAndy Adamson encode_nops(&hdr); 23511da177e4SLinus Torvalds } 23521da177e4SLinus Torvalds 23531da177e4SLinus Torvalds /* 23541da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23551da177e4SLinus Torvalds */ 23569f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23579f06c719SChuck Lever struct xdr_stream *xdr, 2358fcc85819SChristoph Hellwig const void *data) 23591da177e4SLinus Torvalds { 2360fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 23611da177e4SLinus Torvalds struct compound_hdr hdr = { 236266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23631da177e4SLinus Torvalds }; 23641da177e4SLinus Torvalds 23659f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23669f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23679f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2368b6808145STrond Myklebust if (args->lr_args) 2369b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23709f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2371d017931cSAndy Adamson encode_nops(&hdr); 23721da177e4SLinus Torvalds } 23731da177e4SLinus Torvalds 23741da177e4SLinus Torvalds /* 23751da177e4SLinus Torvalds * Encode a LOCK request 23761da177e4SLinus Torvalds */ 23779f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 2378fcc85819SChristoph Hellwig const void *data) 23791da177e4SLinus Torvalds { 2380fcc85819SChristoph Hellwig const struct nfs_lock_args *args = data; 23811da177e4SLinus Torvalds struct compound_hdr hdr = { 238266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23831da177e4SLinus Torvalds }; 23841da177e4SLinus Torvalds 23859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23869f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23879f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23889f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2389d017931cSAndy Adamson encode_nops(&hdr); 23901da177e4SLinus Torvalds } 23911da177e4SLinus Torvalds 23921da177e4SLinus Torvalds /* 23931da177e4SLinus Torvalds * Encode a LOCKT request 23941da177e4SLinus Torvalds */ 23959f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 2396fcc85819SChristoph Hellwig const void *data) 23971da177e4SLinus Torvalds { 2398fcc85819SChristoph Hellwig const struct nfs_lockt_args *args = data; 23991da177e4SLinus Torvalds struct compound_hdr hdr = { 240066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24011da177e4SLinus Torvalds }; 24021da177e4SLinus Torvalds 24039f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24049f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24059f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24069f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2407d017931cSAndy Adamson encode_nops(&hdr); 24081da177e4SLinus Torvalds } 24091da177e4SLinus Torvalds 24101da177e4SLinus Torvalds /* 24111da177e4SLinus Torvalds * Encode a LOCKU request 24121da177e4SLinus Torvalds */ 24139f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 2414fcc85819SChristoph Hellwig const void *data) 24151da177e4SLinus Torvalds { 2416fcc85819SChristoph Hellwig const struct nfs_locku_args *args = data; 24171da177e4SLinus Torvalds struct compound_hdr hdr = { 241866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24191da177e4SLinus Torvalds }; 24201da177e4SLinus Torvalds 24219f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24229f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24239f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24249f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2425d017931cSAndy Adamson encode_nops(&hdr); 24261da177e4SLinus Torvalds } 24271da177e4SLinus Torvalds 24289f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24299f06c719SChuck Lever struct xdr_stream *xdr, 2430fcc85819SChristoph Hellwig const void *data) 2431d3c7b7ccSTrond Myklebust { 2432fcc85819SChristoph Hellwig const struct nfs_release_lockowner_args *args = data; 2433d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2434d3c7b7ccSTrond Myklebust .minorversion = 0, 2435d3c7b7ccSTrond Myklebust }; 2436d3c7b7ccSTrond Myklebust 24379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24389f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2439d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2440d3c7b7ccSTrond Myklebust } 2441d3c7b7ccSTrond Myklebust 24421da177e4SLinus Torvalds /* 24431da177e4SLinus Torvalds * Encode a READLINK request 24441da177e4SLinus Torvalds */ 24459f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2446fcc85819SChristoph Hellwig const void *data) 24471da177e4SLinus Torvalds { 2448fcc85819SChristoph Hellwig const struct nfs4_readlink *args = data; 24491da177e4SLinus Torvalds struct compound_hdr hdr = { 245066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24511da177e4SLinus Torvalds }; 24521da177e4SLinus Torvalds 24539f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24549f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24559f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24569f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2457e3a535e1STrond Myklebust 245828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2459e3a535e1STrond Myklebust args->pgbase, args->pglen); 2460d017931cSAndy Adamson encode_nops(&hdr); 24611da177e4SLinus Torvalds } 24621da177e4SLinus Torvalds 24631da177e4SLinus Torvalds /* 24641da177e4SLinus Torvalds * Encode a READDIR request 24651da177e4SLinus Torvalds */ 24669f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 2467fcc85819SChristoph Hellwig const void *data) 24681da177e4SLinus Torvalds { 2469fcc85819SChristoph Hellwig const struct nfs4_readdir_arg *args = data; 24701da177e4SLinus Torvalds struct compound_hdr hdr = { 247166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24721da177e4SLinus Torvalds }; 24731da177e4SLinus Torvalds 24749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24769f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24779f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2478d6ac02dfSTrond Myklebust 247928f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2480d6ac02dfSTrond Myklebust args->pgbase, args->count); 2481d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 248228f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2483d6ac02dfSTrond Myklebust args->pgbase, args->count); 2484d017931cSAndy Adamson encode_nops(&hdr); 24851da177e4SLinus Torvalds } 24861da177e4SLinus Torvalds 24871da177e4SLinus Torvalds /* 24881da177e4SLinus Torvalds * Encode a READ request 24891da177e4SLinus Torvalds */ 24909f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 2491fcc85819SChristoph Hellwig const void *data) 24921da177e4SLinus Torvalds { 2493fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 24941da177e4SLinus Torvalds struct compound_hdr hdr = { 249566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24961da177e4SLinus Torvalds }; 24971da177e4SLinus Torvalds 24989f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24999f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25009f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25019f06c719SChuck Lever encode_read(xdr, args, &hdr); 25021da177e4SLinus Torvalds 250328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 25041da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 25054f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2506d017931cSAndy Adamson encode_nops(&hdr); 25071da177e4SLinus Torvalds } 25081da177e4SLinus Torvalds 25091da177e4SLinus Torvalds /* 25101da177e4SLinus Torvalds * Encode an SETATTR request 25111da177e4SLinus Torvalds */ 25129f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2513fcc85819SChristoph Hellwig const void *data) 25141da177e4SLinus Torvalds { 2515fcc85819SChristoph Hellwig const struct nfs_setattrargs *args = data; 25161da177e4SLinus Torvalds struct compound_hdr hdr = { 251766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25181da177e4SLinus Torvalds }; 25191da177e4SLinus Torvalds 25209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25219f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25229f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25239f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 25249f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2525d017931cSAndy Adamson encode_nops(&hdr); 25261da177e4SLinus Torvalds } 25271da177e4SLinus Torvalds 25281da177e4SLinus Torvalds /* 2529029d105eSJ. Bruce Fields * Encode a GETACL request 2530029d105eSJ. Bruce Fields */ 25319f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2532fcc85819SChristoph Hellwig const void *data) 2533029d105eSJ. Bruce Fields { 2534fcc85819SChristoph Hellwig const struct nfs_getaclargs *args = data; 2535029d105eSJ. Bruce Fields struct compound_hdr hdr = { 253666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2537029d105eSJ. Bruce Fields }; 253837c88763STrond Myklebust const __u32 nfs4_acl_bitmap[1] = { 253937c88763STrond Myklebust [0] = FATTR4_WORD0_ACL, 254037c88763STrond Myklebust }; 254128f56694SBenny Halevy uint32_t replen; 2542029d105eSJ. Bruce Fields 25439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25459f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25466682c14bSJ. Bruce Fields replen = hdr.replen + op_decode_hdr_maxsz; 254737c88763STrond Myklebust encode_getattr(xdr, nfs4_acl_bitmap, NULL, 254837c88763STrond Myklebust ARRAY_SIZE(nfs4_acl_bitmap), &hdr); 2549cf8cdbe5SAndy Adamson 255028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 25518fbcf237SAndreas Gruenbacher args->acl_pages, 0, args->acl_len); 2552bf118a34SAndy Adamson 2553d017931cSAndy Adamson encode_nops(&hdr); 2554029d105eSJ. Bruce Fields } 2555029d105eSJ. Bruce Fields 2556029d105eSJ. Bruce Fields /* 25571da177e4SLinus Torvalds * Encode a WRITE request 25581da177e4SLinus Torvalds */ 25599f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 2560fcc85819SChristoph Hellwig const void *data) 25611da177e4SLinus Torvalds { 2562fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 25631da177e4SLinus Torvalds struct compound_hdr hdr = { 256466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25651da177e4SLinus Torvalds }; 25661da177e4SLinus Torvalds 25679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25699f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25709f06c719SChuck Lever encode_write(xdr, args, &hdr); 25714f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25727ffd1064SFred Isaman if (args->bitmask) 25739f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2574d017931cSAndy Adamson encode_nops(&hdr); 25751da177e4SLinus Torvalds } 25761da177e4SLinus Torvalds 25771da177e4SLinus Torvalds /* 25781da177e4SLinus Torvalds * a COMMIT request 25791da177e4SLinus Torvalds */ 25809f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 2581fcc85819SChristoph Hellwig const void *data) 25821da177e4SLinus Torvalds { 2583fcc85819SChristoph Hellwig const struct nfs_commitargs *args = data; 25841da177e4SLinus Torvalds struct compound_hdr hdr = { 258566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25861da177e4SLinus Torvalds }; 25871da177e4SLinus Torvalds 25889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25899f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25909f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25919f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2592d017931cSAndy Adamson encode_nops(&hdr); 25931da177e4SLinus Torvalds } 25941da177e4SLinus Torvalds 25951da177e4SLinus Torvalds /* 25961da177e4SLinus Torvalds * FSINFO request 25971da177e4SLinus Torvalds */ 25989f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 2599fcc85819SChristoph Hellwig const void *data) 26001da177e4SLinus Torvalds { 2601fcc85819SChristoph Hellwig const struct nfs4_fsinfo_arg *args = data; 26021da177e4SLinus Torvalds struct compound_hdr hdr = { 260366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26041da177e4SLinus Torvalds }; 26051da177e4SLinus Torvalds 26069f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26079f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26089f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26099f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2610d017931cSAndy Adamson encode_nops(&hdr); 26111da177e4SLinus Torvalds } 26121da177e4SLinus Torvalds 26131da177e4SLinus Torvalds /* 26141da177e4SLinus Torvalds * a PATHCONF request 26151da177e4SLinus Torvalds */ 26169f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 2617fcc85819SChristoph Hellwig const void *data) 26181da177e4SLinus Torvalds { 2619fcc85819SChristoph Hellwig const struct nfs4_pathconf_arg *args = data; 26201da177e4SLinus Torvalds struct compound_hdr hdr = { 262166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26221da177e4SLinus Torvalds }; 26231da177e4SLinus Torvalds 26249f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26259f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26269f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 262737c88763STrond Myklebust encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask, 262837c88763STrond Myklebust ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr); 2629d017931cSAndy Adamson encode_nops(&hdr); 26301da177e4SLinus Torvalds } 26311da177e4SLinus Torvalds 26321da177e4SLinus Torvalds /* 26331da177e4SLinus Torvalds * a STATFS request 26341da177e4SLinus Torvalds */ 26359f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 2636fcc85819SChristoph Hellwig const void *data) 26371da177e4SLinus Torvalds { 2638fcc85819SChristoph Hellwig const struct nfs4_statfs_arg *args = data; 26391da177e4SLinus Torvalds struct compound_hdr hdr = { 264066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26411da177e4SLinus Torvalds }; 26421da177e4SLinus Torvalds 26439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26459f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 264637c88763STrond Myklebust encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask, 264737c88763STrond Myklebust ARRAY_SIZE(nfs4_statfs_bitmap), &hdr); 2648d017931cSAndy Adamson encode_nops(&hdr); 26491da177e4SLinus Torvalds } 26501da177e4SLinus Torvalds 26511da177e4SLinus Torvalds /* 26521da177e4SLinus Torvalds * GETATTR_BITMAP request 26531da177e4SLinus Torvalds */ 26549f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26559f06c719SChuck Lever struct xdr_stream *xdr, 2656fcc85819SChristoph Hellwig const void *data) 26571da177e4SLinus Torvalds { 2658fcc85819SChristoph Hellwig const struct nfs4_server_caps_arg *args = data; 26598c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 26601da177e4SLinus Torvalds struct compound_hdr hdr = { 266166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26621da177e4SLinus Torvalds }; 26631da177e4SLinus Torvalds 26649f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26659f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26669f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 266737c88763STrond Myklebust encode_getattr(xdr, bitmask, NULL, 3, &hdr); 2668d017931cSAndy Adamson encode_nops(&hdr); 26691da177e4SLinus Torvalds } 26701da177e4SLinus Torvalds 26711da177e4SLinus Torvalds /* 26721da177e4SLinus Torvalds * a RENEW request 26731da177e4SLinus Torvalds */ 26749f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 2675fcc85819SChristoph Hellwig const void *data) 2676fcc85819SChristoph Hellwig 26771da177e4SLinus Torvalds { 2678fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 26791da177e4SLinus Torvalds struct compound_hdr hdr = { 2680d017931cSAndy Adamson .nops = 0, 26811da177e4SLinus Torvalds }; 26821da177e4SLinus Torvalds 26839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2684bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2685d017931cSAndy Adamson encode_nops(&hdr); 26861da177e4SLinus Torvalds } 26871da177e4SLinus Torvalds 26881da177e4SLinus Torvalds /* 26891da177e4SLinus Torvalds * a SETCLIENTID request 26901da177e4SLinus Torvalds */ 26919f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 26929f06c719SChuck Lever struct xdr_stream *xdr, 2693fcc85819SChristoph Hellwig const void *data) 26941da177e4SLinus Torvalds { 2695fcc85819SChristoph Hellwig const struct nfs4_setclientid *sc = data; 26961da177e4SLinus Torvalds struct compound_hdr hdr = { 2697d017931cSAndy Adamson .nops = 0, 26981da177e4SLinus Torvalds }; 26991da177e4SLinus Torvalds 27009f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27019f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2702d017931cSAndy Adamson encode_nops(&hdr); 27031da177e4SLinus Torvalds } 27041da177e4SLinus Torvalds 27051da177e4SLinus Torvalds /* 27061da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 27071da177e4SLinus Torvalds */ 27089f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 27099f06c719SChuck Lever struct xdr_stream *xdr, 2710fcc85819SChristoph Hellwig const void *data) 27111da177e4SLinus Torvalds { 2712fcc85819SChristoph Hellwig const struct nfs4_setclientid_res *arg = data; 27131da177e4SLinus Torvalds struct compound_hdr hdr = { 2714d017931cSAndy Adamson .nops = 0, 27151da177e4SLinus Torvalds }; 27161da177e4SLinus Torvalds 27179f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27189f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2719d017931cSAndy Adamson encode_nops(&hdr); 27201da177e4SLinus Torvalds } 27211da177e4SLinus Torvalds 27221da177e4SLinus Torvalds /* 27231da177e4SLinus Torvalds * DELEGRETURN request 27241da177e4SLinus Torvalds */ 27259f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 27269f06c719SChuck Lever struct xdr_stream *xdr, 2727fcc85819SChristoph Hellwig const void *data) 27281da177e4SLinus Torvalds { 2729fcc85819SChristoph Hellwig const struct nfs4_delegreturnargs *args = data; 27301da177e4SLinus Torvalds struct compound_hdr hdr = { 273166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27321da177e4SLinus Torvalds }; 27331da177e4SLinus Torvalds 27349f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27359f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27369f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2737586f1c39STrond Myklebust if (args->lr_args) 2738586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 27398ac2b422STrond Myklebust if (args->bitmask) 27409f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2741e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2742d017931cSAndy Adamson encode_nops(&hdr); 27431da177e4SLinus Torvalds } 27441da177e4SLinus Torvalds 27451da177e4SLinus Torvalds /* 2746683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2747683b57b4STrond Myklebust */ 27489f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27499f06c719SChuck Lever struct xdr_stream *xdr, 2750fcc85819SChristoph Hellwig const void *data) 2751683b57b4STrond Myklebust { 2752fcc85819SChristoph Hellwig const struct nfs4_fs_locations_arg *args = data; 2753683b57b4STrond Myklebust struct compound_hdr hdr = { 275466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2755683b57b4STrond Myklebust }; 275628f56694SBenny Halevy uint32_t replen; 2757683b57b4STrond Myklebust 27589f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27599f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2760b03d735bSChuck Lever if (args->migration) { 2761b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2762b03d735bSChuck Lever replen = hdr.replen; 2763b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2764b03d735bSChuck Lever if (args->renew) 2765b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2766b03d735bSChuck Lever } else { 27679f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 27689f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2769b03d735bSChuck Lever replen = hdr.replen; 27709f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2771b03d735bSChuck Lever } 2772cf8cdbe5SAndy Adamson 2773b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 2774fcc85819SChristoph Hellwig xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2775fcc85819SChristoph Hellwig (struct page **)&args->page, 0, PAGE_SIZE); 2776d017931cSAndy Adamson encode_nops(&hdr); 2777683b57b4STrond Myklebust } 2778683b57b4STrond Myklebust 27795a5ea0d4SBryan Schumaker /* 27805a5ea0d4SBryan Schumaker * Encode SECINFO request 27815a5ea0d4SBryan Schumaker */ 27825a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 27835a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 2784fcc85819SChristoph Hellwig const void *data) 27855a5ea0d4SBryan Schumaker { 2786fcc85819SChristoph Hellwig const struct nfs4_secinfo_arg *args = data; 27875a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 27885a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27895a5ea0d4SBryan Schumaker }; 27905a5ea0d4SBryan Schumaker 27915a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 27925a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 27935a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 27945a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 27955a5ea0d4SBryan Schumaker encode_nops(&hdr); 27965a5ea0d4SBryan Schumaker } 27975a5ea0d4SBryan Schumaker 279844c99933SChuck Lever /* 279944c99933SChuck Lever * Encode FSID_PRESENT request 280044c99933SChuck Lever */ 280144c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 280244c99933SChuck Lever struct xdr_stream *xdr, 2803fcc85819SChristoph Hellwig const void *data) 280444c99933SChuck Lever { 2805fcc85819SChristoph Hellwig const struct nfs4_fsid_present_arg *args = data; 280644c99933SChuck Lever struct compound_hdr hdr = { 280744c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 280844c99933SChuck Lever }; 280944c99933SChuck Lever 281044c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 281144c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 281244c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 281344c99933SChuck Lever encode_getfh(xdr, &hdr); 281444c99933SChuck Lever if (args->renew) 281544c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 281644c99933SChuck Lever encode_nops(&hdr); 281744c99933SChuck Lever } 281844c99933SChuck Lever 281999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 282099fe60d0SBenny Halevy /* 28217c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 28227c44f1aeSWeston Andros Adamson */ 28237c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 28247c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 2825fcc85819SChristoph Hellwig const void *data) 28267c44f1aeSWeston Andros Adamson { 2827fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args = data; 28287c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 282971a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 28307c44f1aeSWeston Andros Adamson }; 28317c44f1aeSWeston Andros Adamson 28327c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 283371a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 28347c44f1aeSWeston Andros Adamson encode_nops(&hdr); 28357c44f1aeSWeston Andros Adamson } 28367c44f1aeSWeston Andros Adamson 28377c44f1aeSWeston Andros Adamson /* 283899fe60d0SBenny Halevy * EXCHANGE_ID request 283999fe60d0SBenny Halevy */ 28409f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 28419f06c719SChuck Lever struct xdr_stream *xdr, 2842fcc85819SChristoph Hellwig const void *data) 284399fe60d0SBenny Halevy { 2844fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args = data; 284599fe60d0SBenny Halevy struct compound_hdr hdr = { 2846a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 284799fe60d0SBenny Halevy }; 284899fe60d0SBenny Halevy 28499f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28509f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 285199fe60d0SBenny Halevy encode_nops(&hdr); 285299fe60d0SBenny Halevy } 28532050f0ccSAndy Adamson 28542050f0ccSAndy Adamson /* 2855fc931582SAndy Adamson * a CREATE_SESSION request 2856fc931582SAndy Adamson */ 28579f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28589f06c719SChuck Lever struct xdr_stream *xdr, 2859fcc85819SChristoph Hellwig const void *data) 2860fc931582SAndy Adamson { 2861fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args = data; 2862fc931582SAndy Adamson struct compound_hdr hdr = { 2863a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2864fc931582SAndy Adamson }; 2865fc931582SAndy Adamson 28669f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28679f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2868fc931582SAndy Adamson encode_nops(&hdr); 2869fc931582SAndy Adamson } 2870fc931582SAndy Adamson 2871fc931582SAndy Adamson /* 28720f3e66c6SAndy Adamson * a DESTROY_SESSION request 28730f3e66c6SAndy Adamson */ 28749f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 28759f06c719SChuck Lever struct xdr_stream *xdr, 2876fcc85819SChristoph Hellwig const void *data) 28770f3e66c6SAndy Adamson { 2878fcc85819SChristoph Hellwig const struct nfs4_session *session = data; 28790f3e66c6SAndy Adamson struct compound_hdr hdr = { 2880a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 28810f3e66c6SAndy Adamson }; 28820f3e66c6SAndy Adamson 28839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28849f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 28850f3e66c6SAndy Adamson encode_nops(&hdr); 28860f3e66c6SAndy Adamson } 28870f3e66c6SAndy Adamson 28880f3e66c6SAndy Adamson /* 288966245539STrond Myklebust * a DESTROY_CLIENTID request 289066245539STrond Myklebust */ 289166245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 289266245539STrond Myklebust struct xdr_stream *xdr, 2893fcc85819SChristoph Hellwig const void *data) 289466245539STrond Myklebust { 2895fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 289666245539STrond Myklebust struct compound_hdr hdr = { 289766245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 289866245539STrond Myklebust }; 289966245539STrond Myklebust 290066245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 290166245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 290266245539STrond Myklebust encode_nops(&hdr); 290366245539STrond Myklebust } 290466245539STrond Myklebust 290566245539STrond Myklebust /* 2906fc01cea9SAndy Adamson * a SEQUENCE request 2907fc01cea9SAndy Adamson */ 29089f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2909fcc85819SChristoph Hellwig const void *data) 2910fc01cea9SAndy Adamson { 2911fcc85819SChristoph Hellwig const struct nfs4_sequence_args *args = data; 2912fc01cea9SAndy Adamson struct compound_hdr hdr = { 2913fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2914fc01cea9SAndy Adamson }; 2915fc01cea9SAndy Adamson 29169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29179f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2918fc01cea9SAndy Adamson encode_nops(&hdr); 2919fc01cea9SAndy Adamson } 2920fc01cea9SAndy Adamson 2921fc01cea9SAndy Adamson /* 29222050f0ccSAndy Adamson * a GET_LEASE_TIME request 29232050f0ccSAndy Adamson */ 29249f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 29259f06c719SChuck Lever struct xdr_stream *xdr, 2926fcc85819SChristoph Hellwig const void *data) 29272050f0ccSAndy Adamson { 2928fcc85819SChristoph Hellwig const struct nfs4_get_lease_time_args *args = data; 29292050f0ccSAndy Adamson struct compound_hdr hdr = { 29302050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 29312050f0ccSAndy Adamson }; 2932dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 29332050f0ccSAndy Adamson 29349f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29359f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 29369f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 29379f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 29382050f0ccSAndy Adamson encode_nops(&hdr); 29392050f0ccSAndy Adamson } 294018019753SRicardo Labiaga 294118019753SRicardo Labiaga /* 294218019753SRicardo Labiaga * a RECLAIM_COMPLETE request 294318019753SRicardo Labiaga */ 29449f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 29459f06c719SChuck Lever struct xdr_stream *xdr, 2946fcc85819SChristoph Hellwig const void *data) 294718019753SRicardo Labiaga { 2948fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args = data; 294918019753SRicardo Labiaga struct compound_hdr hdr = { 295018019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 295118019753SRicardo Labiaga }; 295218019753SRicardo Labiaga 29539f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29549f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29559f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 295618019753SRicardo Labiaga encode_nops(&hdr); 295718019753SRicardo Labiaga } 295818019753SRicardo Labiaga 2959b1f69b75SAndy Adamson /* 2960b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2961b1f69b75SAndy Adamson */ 29629f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 29639f06c719SChuck Lever struct xdr_stream *xdr, 2964fcc85819SChristoph Hellwig const void *data) 2965b1f69b75SAndy Adamson { 2966fcc85819SChristoph Hellwig const struct nfs4_getdeviceinfo_args *args = data; 2967b1f69b75SAndy Adamson struct compound_hdr hdr = { 2968b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2969b1f69b75SAndy Adamson }; 2970b1f69b75SAndy Adamson 29719f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29729f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29739f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2974b1f69b75SAndy Adamson 2975b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2976b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2977b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2978b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2979b1f69b75SAndy Adamson args->pdev->pglen); 2980b1f69b75SAndy Adamson 2981b1f69b75SAndy Adamson encode_nops(&hdr); 2982b1f69b75SAndy Adamson } 2983b1f69b75SAndy Adamson 2984b1f69b75SAndy Adamson /* 2985b1f69b75SAndy Adamson * Encode LAYOUTGET request 2986b1f69b75SAndy Adamson */ 29879f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 29889f06c719SChuck Lever struct xdr_stream *xdr, 2989fcc85819SChristoph Hellwig const void *data) 2990b1f69b75SAndy Adamson { 2991fcc85819SChristoph Hellwig const struct nfs4_layoutget_args *args = data; 2992b1f69b75SAndy Adamson struct compound_hdr hdr = { 2993b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2994b1f69b75SAndy Adamson }; 2995b1f69b75SAndy Adamson 29969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29989f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 29999f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 300035124a09SWeston Andros Adamson 300135124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 300235124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 300335124a09SWeston Andros Adamson 3004b1f69b75SAndy Adamson encode_nops(&hdr); 3005b1f69b75SAndy Adamson } 3006863a3c6cSAndy Adamson 3007863a3c6cSAndy Adamson /* 3008863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 3009863a3c6cSAndy Adamson */ 3010cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 3011863a3c6cSAndy Adamson struct xdr_stream *xdr, 3012fcc85819SChristoph Hellwig const void *priv) 3013863a3c6cSAndy Adamson { 3014fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args = priv; 3015ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 3016ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 3017863a3c6cSAndy Adamson struct compound_hdr hdr = { 3018863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3019863a3c6cSAndy Adamson }; 3020863a3c6cSAndy Adamson 3021863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 3022863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 3023863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3024ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 3025863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 3026863a3c6cSAndy Adamson encode_nops(&hdr); 3027cbe82603SBenny Halevy } 3028cbe82603SBenny Halevy 3029cbe82603SBenny Halevy /* 3030cbe82603SBenny Halevy * Encode LAYOUTRETURN request 3031cbe82603SBenny Halevy */ 3032cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 3033cbe82603SBenny Halevy struct xdr_stream *xdr, 3034fcc85819SChristoph Hellwig const void *data) 3035cbe82603SBenny Halevy { 3036fcc85819SChristoph Hellwig const struct nfs4_layoutreturn_args *args = data; 3037cbe82603SBenny Halevy struct compound_hdr hdr = { 3038cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3039cbe82603SBenny Halevy }; 3040cbe82603SBenny Halevy 3041cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 3042cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 3043cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3044cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 3045cbe82603SBenny Halevy encode_nops(&hdr); 3046863a3c6cSAndy Adamson } 3047fca78d6dSBryan Schumaker 3048fca78d6dSBryan Schumaker /* 3049fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 3050fca78d6dSBryan Schumaker */ 3051fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 3052fca78d6dSBryan Schumaker struct xdr_stream *xdr, 3053fcc85819SChristoph Hellwig const void *data) 3054fca78d6dSBryan Schumaker { 3055fcc85819SChristoph Hellwig const struct nfs41_secinfo_no_name_args *args = data; 3056fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3057fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3058fca78d6dSBryan Schumaker }; 3059fca78d6dSBryan Schumaker 3060fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3061fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3062fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3063fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3064fca78d6dSBryan Schumaker encode_nops(&hdr); 3065fca78d6dSBryan Schumaker } 30667d974794SBryan Schumaker 30677d974794SBryan Schumaker /* 30687d974794SBryan Schumaker * Encode TEST_STATEID request 30697d974794SBryan Schumaker */ 30707d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 30717d974794SBryan Schumaker struct xdr_stream *xdr, 3072fcc85819SChristoph Hellwig const void *data) 30737d974794SBryan Schumaker { 3074fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args = data; 30757d974794SBryan Schumaker struct compound_hdr hdr = { 30767d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30777d974794SBryan Schumaker }; 30787d974794SBryan Schumaker 30797d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30807d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30817d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 30827d974794SBryan Schumaker encode_nops(&hdr); 30837d974794SBryan Schumaker } 30849aeda35fSBryan Schumaker 30859aeda35fSBryan Schumaker /* 30869aeda35fSBryan Schumaker * Encode FREE_STATEID request 30879aeda35fSBryan Schumaker */ 30889aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 30899aeda35fSBryan Schumaker struct xdr_stream *xdr, 3090fcc85819SChristoph Hellwig const void *data) 30919aeda35fSBryan Schumaker { 3092fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args = data; 30939aeda35fSBryan Schumaker struct compound_hdr hdr = { 30949aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30959aeda35fSBryan Schumaker }; 30969aeda35fSBryan Schumaker 30979aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30989aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30999aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 31009aeda35fSBryan Schumaker encode_nops(&hdr); 31019aeda35fSBryan Schumaker } 310299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 310399fe60d0SBenny Halevy 3104686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3105686841b3SBenny Halevy { 3106686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3107686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3108686841b3SBenny Halevy func, xdr->end - xdr->p); 3109686841b3SBenny Halevy } 31101da177e4SLinus Torvalds 3111683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 31121da177e4SLinus Torvalds { 31136da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, 31146da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT); 31156da59ce2STrond Myklebust if (unlikely(ret < 0)) { 31166da59ce2STrond Myklebust if (ret == -EBADMSG) 3117c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3118c0eae66eSBenny Halevy return -EIO; 31191da177e4SLinus Torvalds } 31206da59ce2STrond Myklebust *len = ret; 31216da59ce2STrond Myklebust return 0; 31226da59ce2STrond Myklebust } 31231da177e4SLinus Torvalds 31241da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 31251da177e4SLinus Torvalds { 31268687b63aSAl Viro __be32 *p; 31271da177e4SLinus Torvalds 3128c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3129c0eae66eSBenny Halevy if (unlikely(!p)) 3130c0eae66eSBenny Halevy goto out_overflow; 31316f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3132cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 31331da177e4SLinus Torvalds 3134c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3135c0eae66eSBenny Halevy if (unlikely(!p)) 3136c0eae66eSBenny Halevy goto out_overflow; 31371da177e4SLinus Torvalds hdr->tag = (char *)p; 31381da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3139cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3140aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3141aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 31421da177e4SLinus Torvalds return 0; 3143c0eae66eSBenny Halevy out_overflow: 3144c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3145c0eae66eSBenny Halevy return -EIO; 31461da177e4SLinus Torvalds } 31471da177e4SLinus Torvalds 3148c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3149c7848f69STrond Myklebust int *nfs_retval) 31501da177e4SLinus Torvalds { 31518687b63aSAl Viro __be32 *p; 31521da177e4SLinus Torvalds uint32_t opnum; 31531da177e4SLinus Torvalds int32_t nfserr; 31541da177e4SLinus Torvalds 3155c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3156c0eae66eSBenny Halevy if (unlikely(!p)) 3157c0eae66eSBenny Halevy goto out_overflow; 31586f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3159c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3160c7848f69STrond Myklebust goto out_bad_operation; 3161c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3162c7848f69STrond Myklebust if (nfserr == NFS_OK) 3163c7848f69STrond Myklebust *nfs_retval = 0; 3164c7848f69STrond Myklebust else 3165c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3166c7848f69STrond Myklebust return true; 3167c7848f69STrond Myklebust out_bad_operation: 3168fe82a183SChuck Lever dprintk("nfs: Server returned operation" 31691da177e4SLinus Torvalds " %d but we issued a request for %d\n", 31701da177e4SLinus Torvalds opnum, expected); 3171c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3172c7848f69STrond Myklebust return false; 3173c0eae66eSBenny Halevy out_overflow: 3174c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3175c7848f69STrond Myklebust *nfs_retval = -EIO; 3176c7848f69STrond Myklebust return false; 3177c7848f69STrond Myklebust } 3178c7848f69STrond Myklebust 3179c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3180c7848f69STrond Myklebust { 3181c7848f69STrond Myklebust int retval; 3182c7848f69STrond Myklebust 3183c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3184c7848f69STrond Myklebust return retval; 31851da177e4SLinus Torvalds } 31861da177e4SLinus Torvalds 31871da177e4SLinus Torvalds /* Dummy routine */ 31881bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace) 31891da177e4SLinus Torvalds { 31908687b63aSAl Viro __be32 *p; 3191683b57b4STrond Myklebust unsigned int strlen; 31921da177e4SLinus Torvalds char *str; 31931da177e4SLinus Torvalds 3194c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3195c0eae66eSBenny Halevy if (likely(p)) 31961da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3197c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3198c0eae66eSBenny Halevy return -EIO; 31991da177e4SLinus Torvalds } 32001da177e4SLinus Torvalds 320137c88763STrond Myklebust static ssize_t 320237c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz) 32031da177e4SLinus Torvalds { 320437c88763STrond Myklebust ssize_t ret; 32051da177e4SLinus Torvalds 320637c88763STrond Myklebust ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz); 320737c88763STrond Myklebust if (likely(ret >= 0)) 320837c88763STrond Myklebust return ret; 320937c88763STrond Myklebust if (ret == -EMSGSIZE) 321037c88763STrond Myklebust return sz; 3211c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3212c0eae66eSBenny Halevy return -EIO; 32131da177e4SLinus Torvalds } 32141da177e4SLinus Torvalds 321537c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 321637c88763STrond Myklebust { 321737c88763STrond Myklebust ssize_t ret; 321837c88763STrond Myklebust ret = decode_bitmap4(xdr, bitmap, 3); 321937c88763STrond Myklebust return ret < 0 ? ret : 0; 322037c88763STrond Myklebust } 322137c88763STrond Myklebust 3222256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 32231da177e4SLinus Torvalds { 32248687b63aSAl Viro __be32 *p; 32251da177e4SLinus Torvalds 3226c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3227c0eae66eSBenny Halevy if (unlikely(!p)) 3228c0eae66eSBenny Halevy goto out_overflow; 3229cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3230256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 32311da177e4SLinus Torvalds return 0; 3232c0eae66eSBenny Halevy out_overflow: 3233c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3234c0eae66eSBenny Halevy return -EIO; 32351da177e4SLinus Torvalds } 32361da177e4SLinus Torvalds 32371da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 32381da177e4SLinus Torvalds { 32391da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 32403388bff5SRoman Borisov int ret; 32413388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 32423388bff5SRoman Borisov if (unlikely(ret < 0)) 32433388bff5SRoman Borisov return ret; 32441da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 32451da177e4SLinus Torvalds } else 3246dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3247dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3248dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 32491da177e4SLinus Torvalds return 0; 32501da177e4SLinus Torvalds } 32511da177e4SLinus Torvalds 32521da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32531da177e4SLinus Torvalds { 32548687b63aSAl Viro __be32 *p; 3255409924e4STrond Myklebust int ret = 0; 32561da177e4SLinus Torvalds 32571da177e4SLinus Torvalds *type = 0; 32581da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32591da177e4SLinus Torvalds return -EIO; 32601da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3261c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3262c0eae66eSBenny Halevy if (unlikely(!p)) 3263c0eae66eSBenny Halevy goto out_overflow; 3264cccddf4fSBenny Halevy *type = be32_to_cpup(p); 32651da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 32663110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 32671da177e4SLinus Torvalds return -EIO; 32681da177e4SLinus Torvalds } 32691da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3270409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 32711da177e4SLinus Torvalds } 3272bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3273409924e4STrond Myklebust return ret; 3274c0eae66eSBenny Halevy out_overflow: 3275c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3276c0eae66eSBenny Halevy return -EIO; 32771da177e4SLinus Torvalds } 32781da177e4SLinus Torvalds 3279264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3280264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3281264e6351SChuck Lever { 3282264e6351SChuck Lever __be32 *p; 3283264e6351SChuck Lever 3284264e6351SChuck Lever *type = 0; 3285264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3286264e6351SChuck Lever return -EIO; 3287264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3288264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3289264e6351SChuck Lever if (unlikely(!p)) 3290264e6351SChuck Lever goto out_overflow; 3291264e6351SChuck Lever *type = be32_to_cpup(p); 3292264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3293264e6351SChuck Lever } 3294264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3295264e6351SChuck Lever return 0; 3296264e6351SChuck Lever out_overflow: 3297264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3298264e6351SChuck Lever return -EIO; 3299264e6351SChuck Lever } 3300264e6351SChuck Lever 33011da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 33021da177e4SLinus Torvalds { 33038687b63aSAl Viro __be32 *p; 3304409924e4STrond Myklebust int ret = 0; 33051da177e4SLinus Torvalds 33061da177e4SLinus Torvalds *change = 0; 33071da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 33081da177e4SLinus Torvalds return -EIO; 33091da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3310c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3311c0eae66eSBenny Halevy if (unlikely(!p)) 3312c0eae66eSBenny Halevy goto out_overflow; 3313cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 33141da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3315409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 33161da177e4SLinus Torvalds } 33173110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 33181da177e4SLinus Torvalds (unsigned long long)*change); 3319409924e4STrond Myklebust return ret; 3320c0eae66eSBenny Halevy out_overflow: 3321c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3322c0eae66eSBenny Halevy return -EIO; 33231da177e4SLinus Torvalds } 33241da177e4SLinus Torvalds 33251da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 33261da177e4SLinus Torvalds { 33278687b63aSAl Viro __be32 *p; 3328409924e4STrond Myklebust int ret = 0; 33291da177e4SLinus Torvalds 33301da177e4SLinus Torvalds *size = 0; 33311da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 33321da177e4SLinus Torvalds return -EIO; 33331da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3334c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3335c0eae66eSBenny Halevy if (unlikely(!p)) 3336c0eae66eSBenny Halevy goto out_overflow; 3337cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 33381da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3339409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 33401da177e4SLinus Torvalds } 33413110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3342409924e4STrond Myklebust return ret; 3343c0eae66eSBenny Halevy out_overflow: 3344c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3345c0eae66eSBenny Halevy return -EIO; 33461da177e4SLinus Torvalds } 33471da177e4SLinus Torvalds 33481da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33491da177e4SLinus Torvalds { 33508687b63aSAl Viro __be32 *p; 33511da177e4SLinus Torvalds 33521da177e4SLinus Torvalds *res = 0; 33531da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33541da177e4SLinus Torvalds return -EIO; 33551da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3356c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3357c0eae66eSBenny Halevy if (unlikely(!p)) 3358c0eae66eSBenny Halevy goto out_overflow; 3359cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33601da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 33611da177e4SLinus Torvalds } 33623110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 33631da177e4SLinus Torvalds return 0; 3364c0eae66eSBenny Halevy out_overflow: 3365c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3366c0eae66eSBenny Halevy return -EIO; 33671da177e4SLinus Torvalds } 33681da177e4SLinus Torvalds 33691da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33701da177e4SLinus Torvalds { 33718687b63aSAl Viro __be32 *p; 33721da177e4SLinus Torvalds 33731da177e4SLinus Torvalds *res = 0; 33741da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 33751da177e4SLinus Torvalds return -EIO; 33761da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3377c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3378c0eae66eSBenny Halevy if (unlikely(!p)) 3379c0eae66eSBenny Halevy goto out_overflow; 3380cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33811da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 33821da177e4SLinus Torvalds } 33833110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 33841da177e4SLinus Torvalds return 0; 3385c0eae66eSBenny Halevy out_overflow: 3386c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3387c0eae66eSBenny Halevy return -EIO; 33881da177e4SLinus Torvalds } 33891da177e4SLinus Torvalds 33908b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 33911da177e4SLinus Torvalds { 33928687b63aSAl Viro __be32 *p; 3393409924e4STrond Myklebust int ret = 0; 33941da177e4SLinus Torvalds 33951da177e4SLinus Torvalds fsid->major = 0; 33961da177e4SLinus Torvalds fsid->minor = 0; 33971da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 33981da177e4SLinus Torvalds return -EIO; 33991da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3400c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3401c0eae66eSBenny Halevy if (unlikely(!p)) 3402c0eae66eSBenny Halevy goto out_overflow; 34033ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3404cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 34051da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3406409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 34071da177e4SLinus Torvalds } 34083110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 34091da177e4SLinus Torvalds (unsigned long long)fsid->major, 34101da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3411409924e4STrond Myklebust return ret; 3412c0eae66eSBenny Halevy out_overflow: 3413c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3414c0eae66eSBenny Halevy return -EIO; 34151da177e4SLinus Torvalds } 34161da177e4SLinus Torvalds 34171da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34181da177e4SLinus Torvalds { 34198687b63aSAl Viro __be32 *p; 34201da177e4SLinus Torvalds 34211da177e4SLinus Torvalds *res = 60; 34221da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 34231da177e4SLinus Torvalds return -EIO; 34241da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3425c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3426c0eae66eSBenny Halevy if (unlikely(!p)) 3427c0eae66eSBenny Halevy goto out_overflow; 3428cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34291da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 34301da177e4SLinus Torvalds } 34313110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 34321da177e4SLinus Torvalds return 0; 3433c0eae66eSBenny Halevy out_overflow: 3434c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3435c0eae66eSBenny Halevy return -EIO; 34361da177e4SLinus Torvalds } 34371da177e4SLinus Torvalds 3438ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3439ae42c70aSBryan Schumaker { 3440ae42c70aSBryan Schumaker __be32 *p; 3441ae42c70aSBryan Schumaker 3442ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3443ae42c70aSBryan Schumaker return -EIO; 3444ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3445ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3446ae42c70aSBryan Schumaker if (unlikely(!p)) 3447ae42c70aSBryan Schumaker goto out_overflow; 3448ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3449ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3450ae42c70aSBryan Schumaker } 3451ae42c70aSBryan Schumaker return 0; 3452ae42c70aSBryan Schumaker out_overflow: 3453ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3454ae42c70aSBryan Schumaker return -EIO; 3455ae42c70aSBryan Schumaker } 3456ae42c70aSBryan Schumaker 34578c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 34588c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 34598c61282fSKinglong Mee { 34608c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 34618c61282fSKinglong Mee int ret; 34628c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 34638c61282fSKinglong Mee if (unlikely(ret < 0)) 34648c61282fSKinglong Mee return ret; 34658c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 34668c61282fSKinglong Mee } else 34678c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 34688c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 34698c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 34708c61282fSKinglong Mee return 0; 34718c61282fSKinglong Mee } 34728c61282fSKinglong Mee 3473ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3474ae42c70aSBryan Schumaker { 3475ae42c70aSBryan Schumaker __be32 *p; 3476ae42c70aSBryan Schumaker int len; 3477ae42c70aSBryan Schumaker 34787ad07353STrond Myklebust if (fh != NULL) 3479ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3480ae42c70aSBryan Schumaker 3481ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3482ae42c70aSBryan Schumaker return -EIO; 3483ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3484ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3485ae42c70aSBryan Schumaker if (unlikely(!p)) 3486ae42c70aSBryan Schumaker goto out_overflow; 3487ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3488ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3489ae42c70aSBryan Schumaker return -EIO; 3490ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3491ae42c70aSBryan Schumaker if (unlikely(!p)) 3492ae42c70aSBryan Schumaker goto out_overflow; 34937ad07353STrond Myklebust if (fh != NULL) { 3494ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 34957ad07353STrond Myklebust fh->size = len; 34967ad07353STrond Myklebust } 3497ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3498ae42c70aSBryan Schumaker } 3499ae42c70aSBryan Schumaker return 0; 3500ae42c70aSBryan Schumaker out_overflow: 3501ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3502ae42c70aSBryan Schumaker return -EIO; 3503ae42c70aSBryan Schumaker } 3504ae42c70aSBryan Schumaker 35051da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 35061da177e4SLinus Torvalds { 35078687b63aSAl Viro __be32 *p; 35081da177e4SLinus Torvalds 3509a1800acaSMalahal Naineni *res = 0; 35101da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 35111da177e4SLinus Torvalds return -EIO; 35121da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3513c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3514c0eae66eSBenny Halevy if (unlikely(!p)) 3515c0eae66eSBenny Halevy goto out_overflow; 3516cccddf4fSBenny Halevy *res = be32_to_cpup(p); 35171da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 35181da177e4SLinus Torvalds } 35193110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 35201da177e4SLinus Torvalds return 0; 3521c0eae66eSBenny Halevy out_overflow: 3522c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3523c0eae66eSBenny Halevy return -EIO; 35241da177e4SLinus Torvalds } 35251da177e4SLinus Torvalds 35261da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 35271da177e4SLinus Torvalds { 35288687b63aSAl Viro __be32 *p; 3529409924e4STrond Myklebust int ret = 0; 35301da177e4SLinus Torvalds 35311da177e4SLinus Torvalds *fileid = 0; 35321da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 35331da177e4SLinus Torvalds return -EIO; 35341da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3535c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3536c0eae66eSBenny Halevy if (unlikely(!p)) 3537c0eae66eSBenny Halevy goto out_overflow; 3538cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 35391da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3540409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 35411da177e4SLinus Torvalds } 35423110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3543409924e4STrond Myklebust return ret; 3544c0eae66eSBenny Halevy out_overflow: 3545c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3546c0eae66eSBenny Halevy return -EIO; 35471da177e4SLinus Torvalds } 35481da177e4SLinus Torvalds 354999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 355099baf625SManoj Naik { 35518687b63aSAl Viro __be32 *p; 3552409924e4STrond Myklebust int ret = 0; 355399baf625SManoj Naik 355499baf625SManoj Naik *fileid = 0; 355599baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 355699baf625SManoj Naik return -EIO; 355799baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3558c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3559c0eae66eSBenny Halevy if (unlikely(!p)) 3560c0eae66eSBenny Halevy goto out_overflow; 3561cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 356299baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 356328331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 356499baf625SManoj Naik } 35653110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3566409924e4STrond Myklebust return ret; 3567c0eae66eSBenny Halevy out_overflow: 3568c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3569c0eae66eSBenny Halevy return -EIO; 357099baf625SManoj Naik } 357199baf625SManoj Naik 35721da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35731da177e4SLinus Torvalds { 35748687b63aSAl Viro __be32 *p; 35751da177e4SLinus Torvalds int status = 0; 35761da177e4SLinus Torvalds 35771da177e4SLinus Torvalds *res = 0; 35781da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 35791da177e4SLinus Torvalds return -EIO; 35801da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3581c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3582c0eae66eSBenny Halevy if (unlikely(!p)) 3583c0eae66eSBenny Halevy goto out_overflow; 3584cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35851da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 35861da177e4SLinus Torvalds } 35873110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 35881da177e4SLinus Torvalds return status; 3589c0eae66eSBenny Halevy out_overflow: 3590c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3591c0eae66eSBenny Halevy return -EIO; 35921da177e4SLinus Torvalds } 35931da177e4SLinus Torvalds 35941da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35951da177e4SLinus Torvalds { 35968687b63aSAl Viro __be32 *p; 35971da177e4SLinus Torvalds int status = 0; 35981da177e4SLinus Torvalds 35991da177e4SLinus Torvalds *res = 0; 36001da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 36011da177e4SLinus Torvalds return -EIO; 36021da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3603c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3604c0eae66eSBenny Halevy if (unlikely(!p)) 3605c0eae66eSBenny Halevy goto out_overflow; 3606cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36071da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 36081da177e4SLinus Torvalds } 36093110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 36101da177e4SLinus Torvalds return status; 3611c0eae66eSBenny Halevy out_overflow: 3612c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3613c0eae66eSBenny Halevy return -EIO; 36141da177e4SLinus Torvalds } 36151da177e4SLinus Torvalds 36161da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36171da177e4SLinus Torvalds { 36188687b63aSAl Viro __be32 *p; 36191da177e4SLinus Torvalds int status = 0; 36201da177e4SLinus Torvalds 36211da177e4SLinus Torvalds *res = 0; 36221da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 36231da177e4SLinus Torvalds return -EIO; 36241da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3625c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3626c0eae66eSBenny Halevy if (unlikely(!p)) 3627c0eae66eSBenny Halevy goto out_overflow; 3628cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36291da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 36301da177e4SLinus Torvalds } 36313110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 36321da177e4SLinus Torvalds return status; 3633c0eae66eSBenny Halevy out_overflow: 3634c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3635c0eae66eSBenny Halevy return -EIO; 36361da177e4SLinus Torvalds } 36371da177e4SLinus Torvalds 36387aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 36397aaa0b3bSManoj Naik { 3640464ad6b1SChuck Lever u32 n; 36418687b63aSAl Viro __be32 *p; 36427aaa0b3bSManoj Naik int status = 0; 36437aaa0b3bSManoj Naik 3644c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3645c0eae66eSBenny Halevy if (unlikely(!p)) 3646c0eae66eSBenny Halevy goto out_overflow; 3647cccddf4fSBenny Halevy n = be32_to_cpup(p); 364833a43f28SAndy Adamson if (n == 0) 364933a43f28SAndy Adamson goto root_path; 365002a2976cSChuck Lever dprintk("pathname4: "); 3651809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3652809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3653809b426cSTrond Myklebust goto out_eio; 3654809b426cSTrond Myklebust } 3655809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36567aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 36577aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 36587aaa0b3bSManoj Naik if (unlikely(status != 0)) 36597aaa0b3bSManoj Naik goto out_eio; 366095a13f7bSTrond Myklebust ifdebug (XDR) 366102a2976cSChuck Lever pr_cont("%s%.*s ", 366202a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 366302a2976cSChuck Lever component->len, component->data); 36647aaa0b3bSManoj Naik } 36657aaa0b3bSManoj Naik out: 36667aaa0b3bSManoj Naik return status; 366733a43f28SAndy Adamson root_path: 366833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 366933a43f28SAndy Adamson path->ncomponents = 1; 367033a43f28SAndy Adamson path->components[0].len=0; 367133a43f28SAndy Adamson path->components[0].data=NULL; 367202a2976cSChuck Lever dprintk("pathname4: /\n"); 367333a43f28SAndy Adamson goto out; 36747aaa0b3bSManoj Naik out_eio: 36757aaa0b3bSManoj Naik dprintk(" status %d", status); 36767aaa0b3bSManoj Naik status = -EIO; 36777aaa0b3bSManoj Naik goto out; 3678c0eae66eSBenny Halevy out_overflow: 3679c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3680c0eae66eSBenny Halevy return -EIO; 36817aaa0b3bSManoj Naik } 36827aaa0b3bSManoj Naik 36837aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3684683b57b4STrond Myklebust { 3685683b57b4STrond Myklebust int n; 36868687b63aSAl Viro __be32 *p; 3687683b57b4STrond Myklebust int status = -EIO; 3688683b57b4STrond Myklebust 3689683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3690683b57b4STrond Myklebust goto out; 3691683b57b4STrond Myklebust status = 0; 3692683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3693683b57b4STrond Myklebust goto out; 3694f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 36958b7e3f49STrond Myklebust status = -EIO; 36968b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 36978b7e3f49STrond Myklebust if (unlikely(res == NULL)) 36988b7e3f49STrond Myklebust goto out; 369902a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 37007aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3701683b57b4STrond Myklebust if (unlikely(status != 0)) 3702683b57b4STrond Myklebust goto out; 3703c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3704c0eae66eSBenny Halevy if (unlikely(!p)) 3705c0eae66eSBenny Halevy goto out_overflow; 3706cccddf4fSBenny Halevy n = be32_to_cpup(p); 3707683b57b4STrond Myklebust if (n <= 0) 3708683b57b4STrond Myklebust goto out_eio; 3709809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3710464ad6b1SChuck Lever u32 m; 3711809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3712683b57b4STrond Myklebust 3713809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3714809b426cSTrond Myklebust break; 3715809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3716c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3717c0eae66eSBenny Halevy if (unlikely(!p)) 3718c0eae66eSBenny Halevy goto out_overflow; 3719cccddf4fSBenny Halevy m = be32_to_cpup(p); 37207aaa0b3bSManoj Naik 372102a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3722809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3723809b426cSTrond Myklebust struct nfs4_string *server; 3724809b426cSTrond Myklebust 3725809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3726464ad6b1SChuck Lever unsigned int i; 3727464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3728464ad6b1SChuck Lever "returned for location %u\n", 37293110ff80SHarvey Harrison __func__, 3730464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3731464ad6b1SChuck Lever m, res->nlocations); 37327aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 37332e42c3e2STrond Myklebust unsigned int len; 37347aaa0b3bSManoj Naik char *data; 37357aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3736683b57b4STrond Myklebust if (unlikely(status != 0)) 3737683b57b4STrond Myklebust goto out_eio; 37387aaa0b3bSManoj Naik } 3739809b426cSTrond Myklebust break; 37407aaa0b3bSManoj Naik } 3741809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3742809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3743809b426cSTrond Myklebust if (unlikely(status != 0)) 3744809b426cSTrond Myklebust goto out_eio; 3745809b426cSTrond Myklebust dprintk("%s ", server->data); 37467aaa0b3bSManoj Naik } 37477aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 37487aaa0b3bSManoj Naik if (unlikely(status != 0)) 37497aaa0b3bSManoj Naik goto out_eio; 3750683b57b4STrond Myklebust } 3751409924e4STrond Myklebust if (res->nlocations != 0) 375281934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3753683b57b4STrond Myklebust out: 37543110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3755683b57b4STrond Myklebust return status; 3756c0eae66eSBenny Halevy out_overflow: 3757c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3758683b57b4STrond Myklebust out_eio: 3759683b57b4STrond Myklebust status = -EIO; 3760683b57b4STrond Myklebust goto out; 3761683b57b4STrond Myklebust } 3762683b57b4STrond Myklebust 37631da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 37641da177e4SLinus Torvalds { 37658687b63aSAl Viro __be32 *p; 37661da177e4SLinus Torvalds int status = 0; 37671da177e4SLinus Torvalds 37681da177e4SLinus Torvalds *res = 0; 37691da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 37701da177e4SLinus Torvalds return -EIO; 37711da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3772c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3773c0eae66eSBenny Halevy if (unlikely(!p)) 3774c0eae66eSBenny Halevy goto out_overflow; 3775cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 37761da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 37771da177e4SLinus Torvalds } 37783110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 37791da177e4SLinus Torvalds return status; 3780c0eae66eSBenny Halevy out_overflow: 3781c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3782c0eae66eSBenny Halevy return -EIO; 37831da177e4SLinus Torvalds } 37841da177e4SLinus Torvalds 37851da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 37861da177e4SLinus Torvalds { 37878687b63aSAl Viro __be32 *p; 37881da177e4SLinus Torvalds int status = 0; 37891da177e4SLinus Torvalds 37901da177e4SLinus Torvalds *maxlink = 1; 37911da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 37921da177e4SLinus Torvalds return -EIO; 37931da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3794c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3795c0eae66eSBenny Halevy if (unlikely(!p)) 3796c0eae66eSBenny Halevy goto out_overflow; 3797cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 37981da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 37991da177e4SLinus Torvalds } 38003110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 38011da177e4SLinus Torvalds return status; 3802c0eae66eSBenny Halevy out_overflow: 3803c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3804c0eae66eSBenny Halevy return -EIO; 38051da177e4SLinus Torvalds } 38061da177e4SLinus Torvalds 38071da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 38081da177e4SLinus Torvalds { 38098687b63aSAl Viro __be32 *p; 38101da177e4SLinus Torvalds int status = 0; 38111da177e4SLinus Torvalds 38121da177e4SLinus Torvalds *maxname = 1024; 38131da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 38141da177e4SLinus Torvalds return -EIO; 38151da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3816c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3817c0eae66eSBenny Halevy if (unlikely(!p)) 3818c0eae66eSBenny Halevy goto out_overflow; 3819cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 38201da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 38211da177e4SLinus Torvalds } 38223110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 38231da177e4SLinus Torvalds return status; 3824c0eae66eSBenny Halevy out_overflow: 3825c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3826c0eae66eSBenny Halevy return -EIO; 38271da177e4SLinus Torvalds } 38281da177e4SLinus Torvalds 38291da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38301da177e4SLinus Torvalds { 38318687b63aSAl Viro __be32 *p; 38321da177e4SLinus Torvalds int status = 0; 38331da177e4SLinus Torvalds 38341da177e4SLinus Torvalds *res = 1024; 38351da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 38361da177e4SLinus Torvalds return -EIO; 38371da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 38381da177e4SLinus Torvalds uint64_t maxread; 3839c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3840c0eae66eSBenny Halevy if (unlikely(!p)) 3841c0eae66eSBenny Halevy goto out_overflow; 3842cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 38431da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 38441da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 38451da177e4SLinus Torvalds *res = (uint32_t)maxread; 38461da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 38471da177e4SLinus Torvalds } 38483110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 38491da177e4SLinus Torvalds return status; 3850c0eae66eSBenny Halevy out_overflow: 3851c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3852c0eae66eSBenny Halevy return -EIO; 38531da177e4SLinus Torvalds } 38541da177e4SLinus Torvalds 38551da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38561da177e4SLinus Torvalds { 38578687b63aSAl Viro __be32 *p; 38581da177e4SLinus Torvalds int status = 0; 38591da177e4SLinus Torvalds 38601da177e4SLinus Torvalds *res = 1024; 38611da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 38621da177e4SLinus Torvalds return -EIO; 38631da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 38641da177e4SLinus Torvalds uint64_t maxwrite; 3865c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3866c0eae66eSBenny Halevy if (unlikely(!p)) 3867c0eae66eSBenny Halevy goto out_overflow; 3868cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 38691da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 38701da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 38711da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 38721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 38731da177e4SLinus Torvalds } 38743110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 38751da177e4SLinus Torvalds return status; 3876c0eae66eSBenny Halevy out_overflow: 3877c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3878c0eae66eSBenny Halevy return -EIO; 38791da177e4SLinus Torvalds } 38801da177e4SLinus Torvalds 3881bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 38821da177e4SLinus Torvalds { 3883bca79478STrond Myklebust uint32_t tmp; 38848687b63aSAl Viro __be32 *p; 3885409924e4STrond Myklebust int ret = 0; 38861da177e4SLinus Torvalds 38871da177e4SLinus Torvalds *mode = 0; 38881da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 38891da177e4SLinus Torvalds return -EIO; 38901da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3891c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3892c0eae66eSBenny Halevy if (unlikely(!p)) 3893c0eae66eSBenny Halevy goto out_overflow; 3894cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3895bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 38961da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3897409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 38981da177e4SLinus Torvalds } 38993110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3900409924e4STrond Myklebust return ret; 3901c0eae66eSBenny Halevy out_overflow: 3902c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3903c0eae66eSBenny Halevy return -EIO; 39041da177e4SLinus Torvalds } 39051da177e4SLinus Torvalds 39061da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 39071da177e4SLinus Torvalds { 39088687b63aSAl Viro __be32 *p; 3909409924e4STrond Myklebust int ret = 0; 39101da177e4SLinus Torvalds 39111da177e4SLinus Torvalds *nlink = 1; 39121da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 39131da177e4SLinus Torvalds return -EIO; 39141da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3915c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3916c0eae66eSBenny Halevy if (unlikely(!p)) 3917c0eae66eSBenny Halevy goto out_overflow; 3918cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 39191da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3920409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 39211da177e4SLinus Torvalds } 39223110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3923409924e4STrond Myklebust return ret; 3924c0eae66eSBenny Halevy out_overflow: 3925c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3926c0eae66eSBenny Halevy return -EIO; 39271da177e4SLinus Torvalds } 39281da177e4SLinus Torvalds 3929686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr, 3930686a816aSTrond Myklebust struct nfs4_string *name, gfp_t gfp_flags) 3931686a816aSTrond Myklebust { 3932686a816aSTrond Myklebust ssize_t ret; 3933686a816aSTrond Myklebust 3934686a816aSTrond Myklebust ret = xdr_stream_decode_string_dup(xdr, &name->data, 3935686a816aSTrond Myklebust XDR_MAX_NETOBJ, gfp_flags); 3936686a816aSTrond Myklebust name->len = 0; 3937686a816aSTrond Myklebust if (ret > 0) 3938686a816aSTrond Myklebust name->len = ret; 3939686a816aSTrond Myklebust return ret; 3940686a816aSTrond Myklebust } 3941686a816aSTrond Myklebust 394280e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3943e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 39446926afd1STrond Myklebust struct nfs4_string *owner_name) 39451da177e4SLinus Torvalds { 3946686a816aSTrond Myklebust ssize_t len; 3947686a816aSTrond Myklebust char *p; 39481da177e4SLinus Torvalds 3949e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 39501da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 39511da177e4SLinus Torvalds return -EIO; 3952686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER)) 3953686a816aSTrond Myklebust return 0; 39541da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 3955686a816aSTrond Myklebust 3956686a816aSTrond Myklebust if (owner_name != NULL) { 3957e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, owner_name, GFP_NOIO); 3958686a816aSTrond Myklebust if (len <= 0) 3959686a816aSTrond Myklebust goto out; 3960686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, owner_name->data); 3961686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER_NAME; 3962686a816aSTrond Myklebust } else { 3963686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 3964686a816aSTrond Myklebust XDR_MAX_NETOBJ); 3965686a816aSTrond Myklebust if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0) 3966686a816aSTrond Myklebust goto out; 3967e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3968686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER; 3969686a816aSTrond Myklebust } 3970686a816aSTrond Myklebust out: 3971686a816aSTrond Myklebust if (len != -EBADMSG) 3972686a816aSTrond Myklebust return 0; 3973c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3974c0eae66eSBenny Halevy return -EIO; 39751da177e4SLinus Torvalds } 39761da177e4SLinus Torvalds 397780e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3978e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 39796926afd1STrond Myklebust struct nfs4_string *group_name) 39801da177e4SLinus Torvalds { 3981686a816aSTrond Myklebust ssize_t len; 3982686a816aSTrond Myklebust char *p; 39831da177e4SLinus Torvalds 3984e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 39851da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 39861da177e4SLinus Torvalds return -EIO; 3987686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) 3988686a816aSTrond Myklebust return 0; 39891da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 3990686a816aSTrond Myklebust 3991686a816aSTrond Myklebust if (group_name != NULL) { 3992e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, group_name, GFP_NOIO); 3993686a816aSTrond Myklebust if (len <= 0) 3994686a816aSTrond Myklebust goto out; 3995686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, group_name->data); 39966f1f6220SKinglong Mee return NFS_ATTR_FATTR_GROUP_NAME; 3997686a816aSTrond Myklebust } else { 3998686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 3999686a816aSTrond Myklebust XDR_MAX_NETOBJ); 4000686a816aSTrond Myklebust if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0) 4001686a816aSTrond Myklebust goto out; 4002e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 4003686a816aSTrond Myklebust return NFS_ATTR_FATTR_GROUP; 4004686a816aSTrond Myklebust } 4005686a816aSTrond Myklebust out: 4006686a816aSTrond Myklebust if (len != -EBADMSG) 4007686a816aSTrond Myklebust return 0; 4008c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4009c0eae66eSBenny Halevy return -EIO; 40101da177e4SLinus Torvalds } 40111da177e4SLinus Torvalds 40121da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 40131da177e4SLinus Torvalds { 40148687b63aSAl Viro uint32_t major = 0, minor = 0; 40158687b63aSAl Viro __be32 *p; 4016409924e4STrond Myklebust int ret = 0; 40171da177e4SLinus Torvalds 40181da177e4SLinus Torvalds *rdev = MKDEV(0,0); 40191da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 40201da177e4SLinus Torvalds return -EIO; 40211da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 40221da177e4SLinus Torvalds dev_t tmp; 40231da177e4SLinus Torvalds 4024c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4025c0eae66eSBenny Halevy if (unlikely(!p)) 4026c0eae66eSBenny Halevy goto out_overflow; 40276f723f77SBenny Halevy major = be32_to_cpup(p++); 4028cccddf4fSBenny Halevy minor = be32_to_cpup(p); 40291da177e4SLinus Torvalds tmp = MKDEV(major, minor); 40301da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 40311da177e4SLinus Torvalds *rdev = tmp; 40321da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 4033409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 40341da177e4SLinus Torvalds } 40353110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 4036409924e4STrond Myklebust return ret; 4037c0eae66eSBenny Halevy out_overflow: 4038c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4039c0eae66eSBenny Halevy return -EIO; 40401da177e4SLinus Torvalds } 40411da177e4SLinus Torvalds 40421da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40431da177e4SLinus Torvalds { 40448687b63aSAl Viro __be32 *p; 40451da177e4SLinus Torvalds int status = 0; 40461da177e4SLinus Torvalds 40471da177e4SLinus Torvalds *res = 0; 40481da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 40491da177e4SLinus Torvalds return -EIO; 40501da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 4051c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4052c0eae66eSBenny Halevy if (unlikely(!p)) 4053c0eae66eSBenny Halevy goto out_overflow; 4054cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40551da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40561da177e4SLinus Torvalds } 40573110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 40581da177e4SLinus Torvalds return status; 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_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40651da177e4SLinus Torvalds { 40668687b63aSAl Viro __be32 *p; 40671da177e4SLinus Torvalds int status = 0; 40681da177e4SLinus Torvalds 40691da177e4SLinus Torvalds *res = 0; 40701da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 40711da177e4SLinus Torvalds return -EIO; 40721da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4073c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4074c0eae66eSBenny Halevy if (unlikely(!p)) 4075c0eae66eSBenny Halevy goto out_overflow; 4076cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40771da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 40781da177e4SLinus Torvalds } 40793110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 40801da177e4SLinus Torvalds return status; 4081c0eae66eSBenny Halevy out_overflow: 4082c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4083c0eae66eSBenny Halevy return -EIO; 40841da177e4SLinus Torvalds } 40851da177e4SLinus Torvalds 40861da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40871da177e4SLinus Torvalds { 40888687b63aSAl Viro __be32 *p; 40891da177e4SLinus Torvalds int status = 0; 40901da177e4SLinus Torvalds 40911da177e4SLinus Torvalds *res = 0; 40921da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 40931da177e4SLinus Torvalds return -EIO; 40941da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4095c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4096c0eae66eSBenny Halevy if (unlikely(!p)) 4097c0eae66eSBenny Halevy goto out_overflow; 4098cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40991da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 41001da177e4SLinus Torvalds } 41013110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 41021da177e4SLinus Torvalds return status; 4103c0eae66eSBenny Halevy out_overflow: 4104c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4105c0eae66eSBenny Halevy return -EIO; 41061da177e4SLinus Torvalds } 41071da177e4SLinus Torvalds 41081da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 41091da177e4SLinus Torvalds { 41108687b63aSAl Viro __be32 *p; 4111409924e4STrond Myklebust int ret = 0; 41121da177e4SLinus Torvalds 41131da177e4SLinus Torvalds *used = 0; 41141da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 41151da177e4SLinus Torvalds return -EIO; 41161da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4117c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4118c0eae66eSBenny Halevy if (unlikely(!p)) 4119c0eae66eSBenny Halevy goto out_overflow; 4120cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 41211da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4122409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 41231da177e4SLinus Torvalds } 41243110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 41251da177e4SLinus Torvalds (unsigned long long)*used); 4126409924e4STrond Myklebust return ret; 4127c0eae66eSBenny Halevy out_overflow: 4128c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4129c0eae66eSBenny Halevy return -EIO; 41301da177e4SLinus Torvalds } 41311da177e4SLinus Torvalds 41321da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 41331da177e4SLinus Torvalds { 41348687b63aSAl Viro __be32 *p; 41351da177e4SLinus Torvalds uint64_t sec; 41361da177e4SLinus Torvalds uint32_t nsec; 41371da177e4SLinus Torvalds 4138c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4139c0eae66eSBenny Halevy if (unlikely(!p)) 4140c0eae66eSBenny Halevy goto out_overflow; 41413ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 4142cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 41431da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 41441da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 41451da177e4SLinus Torvalds return 0; 4146c0eae66eSBenny Halevy out_overflow: 4147c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4148c0eae66eSBenny Halevy return -EIO; 41491da177e4SLinus Torvalds } 41501da177e4SLinus Torvalds 41511da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41521da177e4SLinus Torvalds { 41531da177e4SLinus Torvalds int status = 0; 41541da177e4SLinus Torvalds 41551da177e4SLinus Torvalds time->tv_sec = 0; 41561da177e4SLinus Torvalds time->tv_nsec = 0; 41571da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 41581da177e4SLinus Torvalds return -EIO; 41591da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 41601da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4161409924e4STrond Myklebust if (status == 0) 4162409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 41631da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 41641da177e4SLinus Torvalds } 41653110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 41661da177e4SLinus Torvalds return status; 41671da177e4SLinus Torvalds } 41681da177e4SLinus Torvalds 41691da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41701da177e4SLinus Torvalds { 41711da177e4SLinus Torvalds int status = 0; 41721da177e4SLinus Torvalds 41731da177e4SLinus Torvalds time->tv_sec = 0; 41741da177e4SLinus Torvalds time->tv_nsec = 0; 41751da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 41761da177e4SLinus Torvalds return -EIO; 41771da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 41781da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4179409924e4STrond Myklebust if (status == 0) 4180409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 41811da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 41821da177e4SLinus Torvalds } 41833110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 41841da177e4SLinus Torvalds return status; 41851da177e4SLinus Torvalds } 41861da177e4SLinus Torvalds 418755b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 418855b6e774SRicardo Labiaga struct timespec *time) 418955b6e774SRicardo Labiaga { 419055b6e774SRicardo Labiaga int status = 0; 419155b6e774SRicardo Labiaga 419255b6e774SRicardo Labiaga time->tv_sec = 0; 419355b6e774SRicardo Labiaga time->tv_nsec = 0; 419455b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 419555b6e774SRicardo Labiaga return -EIO; 419655b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 419755b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 419855b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 419955b6e774SRicardo Labiaga } 420055b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 420155b6e774SRicardo Labiaga (long)time->tv_nsec); 420255b6e774SRicardo Labiaga return status; 420355b6e774SRicardo Labiaga } 420455b6e774SRicardo Labiaga 4205aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4206aa9c2669SDavid Quigley struct nfs4_label *label) 4207aa9c2669SDavid Quigley { 4208aa9c2669SDavid Quigley uint32_t pi = 0; 4209aa9c2669SDavid Quigley uint32_t lfs = 0; 4210aa9c2669SDavid Quigley __u32 len; 4211aa9c2669SDavid Quigley __be32 *p; 4212aa9c2669SDavid Quigley int status = 0; 4213aa9c2669SDavid Quigley 4214aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4215aa9c2669SDavid Quigley return -EIO; 4216aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4217aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4218aa9c2669SDavid Quigley if (unlikely(!p)) 4219aa9c2669SDavid Quigley goto out_overflow; 4220aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4221aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4222aa9c2669SDavid Quigley if (unlikely(!p)) 4223aa9c2669SDavid Quigley goto out_overflow; 4224aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4225aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4226aa9c2669SDavid Quigley if (unlikely(!p)) 4227aa9c2669SDavid Quigley goto out_overflow; 4228aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4229aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4230aa9c2669SDavid Quigley if (unlikely(!p)) 4231aa9c2669SDavid Quigley goto out_overflow; 4232aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4233aa9c2669SDavid Quigley if (label) { 4234aa9c2669SDavid Quigley memcpy(label->label, p, len); 4235aa9c2669SDavid Quigley label->len = len; 4236aa9c2669SDavid Quigley label->pi = pi; 4237aa9c2669SDavid Quigley label->lfs = lfs; 4238aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4239aa9c2669SDavid Quigley } 4240aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4241aa9c2669SDavid Quigley } else 4242aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4243aa9c2669SDavid Quigley __func__, len); 4244aa9c2669SDavid Quigley } 4245aa9c2669SDavid Quigley if (label && label->label) 4246aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4247aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4248aa9c2669SDavid Quigley return status; 4249aa9c2669SDavid Quigley 4250aa9c2669SDavid Quigley out_overflow: 4251aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4252aa9c2669SDavid Quigley return -EIO; 4253aa9c2669SDavid Quigley } 4254aa9c2669SDavid Quigley 42551da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42561da177e4SLinus Torvalds { 42571da177e4SLinus Torvalds int status = 0; 42581da177e4SLinus Torvalds 42591da177e4SLinus Torvalds time->tv_sec = 0; 42601da177e4SLinus Torvalds time->tv_nsec = 0; 42611da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 42621da177e4SLinus Torvalds return -EIO; 42631da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 42641da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4265409924e4STrond Myklebust if (status == 0) 4266409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 42671da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 42681da177e4SLinus Torvalds } 42693110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 42701da177e4SLinus Torvalds return status; 42711da177e4SLinus Torvalds } 42721da177e4SLinus Torvalds 4273256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 42741da177e4SLinus Torvalds { 42751da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4276256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 42771da177e4SLinus Torvalds 42781da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4279fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4280fe82a183SChuck Lever "%u %c %u\n", 42813110ff80SHarvey Harrison __func__, 42821da177e4SLinus Torvalds attrwords << 2, 42831da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 42841da177e4SLinus Torvalds nwords << 2); 42851da177e4SLinus Torvalds return -EIO; 42861da177e4SLinus Torvalds } 42871da177e4SLinus Torvalds return 0; 42881da177e4SLinus Torvalds } 42891da177e4SLinus Torvalds 42901da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42911da177e4SLinus Torvalds { 42928687b63aSAl Viro __be32 *p; 42931da177e4SLinus Torvalds 4294c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4295c0eae66eSBenny Halevy if (unlikely(!p)) 4296c0eae66eSBenny Halevy goto out_overflow; 42976f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 42983ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4299cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 43001da177e4SLinus Torvalds return 0; 4301c0eae66eSBenny Halevy out_overflow: 4302c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4303c0eae66eSBenny Halevy return -EIO; 43041da177e4SLinus Torvalds } 43051da177e4SLinus Torvalds 43066168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 43071da177e4SLinus Torvalds { 43088687b63aSAl Viro __be32 *p; 43091da177e4SLinus Torvalds uint32_t supp, acc; 43101da177e4SLinus Torvalds int status; 43111da177e4SLinus Torvalds 43121da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 43131da177e4SLinus Torvalds if (status) 43141da177e4SLinus Torvalds return status; 4315c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4316c0eae66eSBenny Halevy if (unlikely(!p)) 4317c0eae66eSBenny Halevy goto out_overflow; 43186f723f77SBenny Halevy supp = be32_to_cpup(p++); 4319cccddf4fSBenny Halevy acc = be32_to_cpup(p); 43206168f62cSWeston Andros Adamson *supported = supp; 43216168f62cSWeston Andros Adamson *access = acc; 43221da177e4SLinus Torvalds return 0; 4323c0eae66eSBenny Halevy out_overflow: 4324c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4325c0eae66eSBenny Halevy return -EIO; 43261da177e4SLinus Torvalds } 43271da177e4SLinus Torvalds 432807d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 43291da177e4SLinus Torvalds { 4330ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); 4331ab6e9aafSTrond Myklebust if (unlikely(ret < 0)) { 433207d30434SBenny Halevy print_overflow_msg(__func__, xdr); 433307d30434SBenny Halevy return -EIO; 433407d30434SBenny Halevy } 4335ab6e9aafSTrond Myklebust return 0; 4336ab6e9aafSTrond Myklebust } 433707d30434SBenny Halevy 433807d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 433907d30434SBenny Halevy { 43402d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 43411da177e4SLinus Torvalds } 43421da177e4SLinus Torvalds 434393b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 434493b717fdSTrond Myklebust { 434593b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 434693b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 434793b717fdSTrond Myklebust } 434893b717fdSTrond Myklebust 434993b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 435093b717fdSTrond Myklebust { 435193b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 435293b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 435393b717fdSTrond Myklebust } 435493b717fdSTrond Myklebust 435593b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 435693b717fdSTrond Myklebust { 435793b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 435893b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 435993b717fdSTrond Myklebust } 436093b717fdSTrond Myklebust 4361fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 4362fcd8843cSTrond Myklebust { 4363fcd8843cSTrond Myklebust nfs4_stateid dummy; 4364fcd8843cSTrond Myklebust 4365fcd8843cSTrond Myklebust nfs4_stateid_copy(stateid, &invalid_stateid); 4366fcd8843cSTrond Myklebust return decode_stateid(xdr, &dummy); 4367fcd8843cSTrond Myklebust } 4368fcd8843cSTrond Myklebust 43691da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 43701da177e4SLinus Torvalds { 43711da177e4SLinus Torvalds int status; 43721da177e4SLinus Torvalds 43731da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4374c1d51931STrond Myklebust if (status != -EIO) 4375c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 437607d30434SBenny Halevy if (!status) 4377fcd8843cSTrond Myklebust status = decode_invalid_stateid(xdr, &res->stateid); 43781da177e4SLinus Torvalds return status; 43791da177e4SLinus Torvalds } 43801da177e4SLinus Torvalds 4381db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4382db942bbdSBenny Halevy { 4383cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 43841da177e4SLinus Torvalds } 43851da177e4SLinus Torvalds 43862f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 43872f2c63bcSTrond Myklebust { 43882f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 43892f2c63bcSTrond Myklebust } 43902f2c63bcSTrond Myklebust 43910b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 43921da177e4SLinus Torvalds { 43931da177e4SLinus Torvalds int status; 43941da177e4SLinus Torvalds 43951da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4396db942bbdSBenny Halevy if (!status) 43972f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 43981da177e4SLinus Torvalds return status; 43991da177e4SLinus Torvalds } 44001da177e4SLinus Torvalds 44011da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 44021da177e4SLinus Torvalds { 44038687b63aSAl Viro __be32 *p; 44041da177e4SLinus Torvalds uint32_t bmlen; 44051da177e4SLinus Torvalds int status; 44061da177e4SLinus Torvalds 44071da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 44081da177e4SLinus Torvalds if (status) 44091da177e4SLinus Torvalds return status; 44101da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 44111da177e4SLinus Torvalds return status; 4412c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4413c0eae66eSBenny Halevy if (unlikely(!p)) 4414c0eae66eSBenny Halevy goto out_overflow; 4415cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4416c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4417c0eae66eSBenny Halevy if (likely(p)) 44181da177e4SLinus Torvalds return 0; 4419c0eae66eSBenny Halevy out_overflow: 4420c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4421c0eae66eSBenny Halevy return -EIO; 44221da177e4SLinus Torvalds } 44231da177e4SLinus Torvalds 44241da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 44251da177e4SLinus Torvalds { 4426256e48bbSTrond Myklebust unsigned int savep; 4427dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44281da177e4SLinus Torvalds int status; 44291da177e4SLinus Torvalds 44301da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44311da177e4SLinus Torvalds goto xdr_error; 44321da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44331da177e4SLinus Torvalds goto xdr_error; 44341da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44351da177e4SLinus Torvalds goto xdr_error; 44361da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 44371da177e4SLinus Torvalds goto xdr_error; 4438264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4439264e6351SChuck Lever &res->fh_expire_type)) != 0) 4440264e6351SChuck Lever goto xdr_error; 44411da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 44421da177e4SLinus Torvalds goto xdr_error; 44431da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 44441da177e4SLinus Torvalds goto xdr_error; 44451da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 44461da177e4SLinus Torvalds goto xdr_error; 44478c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 44488c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 44498c61282fSKinglong Mee goto xdr_error; 44501da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44511da177e4SLinus Torvalds xdr_error: 44523110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44531da177e4SLinus Torvalds return status; 44541da177e4SLinus Torvalds } 44551da177e4SLinus Torvalds 44561da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 44571da177e4SLinus Torvalds { 4458256e48bbSTrond Myklebust unsigned int savep; 4459dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44601da177e4SLinus Torvalds int status; 44611da177e4SLinus Torvalds 44621da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44631da177e4SLinus Torvalds goto xdr_error; 44641da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44651da177e4SLinus Torvalds goto xdr_error; 44661da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44671da177e4SLinus Torvalds goto xdr_error; 44681da177e4SLinus Torvalds 44691da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 44701da177e4SLinus Torvalds goto xdr_error; 44711da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 44721da177e4SLinus Torvalds goto xdr_error; 44731da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 44741da177e4SLinus Torvalds goto xdr_error; 44751ca843a2SAndreas Gruenbacher 44761ca843a2SAndreas Gruenbacher status = -EIO; 44771ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 44781ca843a2SAndreas Gruenbacher goto xdr_error; 44791ca843a2SAndreas Gruenbacher 44801da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 44811da177e4SLinus Torvalds goto xdr_error; 44821da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 44831da177e4SLinus Torvalds goto xdr_error; 44841da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 44851da177e4SLinus Torvalds goto xdr_error; 44861da177e4SLinus Torvalds 44871da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44881da177e4SLinus Torvalds xdr_error: 44893110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44901da177e4SLinus Torvalds return status; 44911da177e4SLinus Torvalds } 44921da177e4SLinus Torvalds 44931da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 44941da177e4SLinus Torvalds { 4495256e48bbSTrond Myklebust unsigned int savep; 4496dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44971da177e4SLinus Torvalds int status; 44981da177e4SLinus Torvalds 44991da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45001da177e4SLinus Torvalds goto xdr_error; 45011da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45021da177e4SLinus Torvalds goto xdr_error; 45031da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45041da177e4SLinus Torvalds goto xdr_error; 45051da177e4SLinus Torvalds 45061da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 45071da177e4SLinus Torvalds goto xdr_error; 45081da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 45091da177e4SLinus Torvalds goto xdr_error; 45101da177e4SLinus Torvalds 45111da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45121da177e4SLinus Torvalds xdr_error: 45133110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45141da177e4SLinus Torvalds return status; 45151da177e4SLinus Torvalds } 45161da177e4SLinus Torvalds 451788034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 451888034c3dSAndy Adamson uint32_t *bitmap, 451988034c3dSAndy Adamson uint64_t *res, 452088034c3dSAndy Adamson uint32_t hint_bit) 452188034c3dSAndy Adamson { 452288034c3dSAndy Adamson __be32 *p; 452388034c3dSAndy Adamson 452488034c3dSAndy Adamson *res = 0; 452588034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 452688034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 452788034c3dSAndy Adamson if (unlikely(!p)) 452888034c3dSAndy Adamson goto out_overflow; 452988034c3dSAndy Adamson xdr_decode_hyper(p, res); 453088034c3dSAndy Adamson } 453188034c3dSAndy Adamson return 0; 453288034c3dSAndy Adamson out_overflow: 453388034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 453488034c3dSAndy Adamson return -EIO; 453588034c3dSAndy Adamson } 453688034c3dSAndy Adamson 453788034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 453888034c3dSAndy Adamson struct nfs4_threshold *res) 453988034c3dSAndy Adamson { 4540256e48bbSTrond Myklebust __be32 *p; 4541256e48bbSTrond Myklebust unsigned int savep; 454288034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 454388034c3dSAndy Adamson int status; 454488034c3dSAndy Adamson 454588034c3dSAndy Adamson /* layout type */ 454688034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 454788034c3dSAndy Adamson if (unlikely(!p)) { 454888034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 454988034c3dSAndy Adamson return -EIO; 455088034c3dSAndy Adamson } 455188034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 455288034c3dSAndy Adamson 455388034c3dSAndy Adamson /* thi_hintset bitmap */ 455488034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 455588034c3dSAndy Adamson if (status < 0) 455688034c3dSAndy Adamson goto xdr_error; 455788034c3dSAndy Adamson 455888034c3dSAndy Adamson /* thi_hintlist length */ 455988034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 456088034c3dSAndy Adamson if (status < 0) 456188034c3dSAndy Adamson goto xdr_error; 456288034c3dSAndy Adamson /* thi_hintlist */ 456388034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 456488034c3dSAndy Adamson if (status < 0) 456588034c3dSAndy Adamson goto xdr_error; 456688034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 456788034c3dSAndy Adamson if (status < 0) 456888034c3dSAndy Adamson goto xdr_error; 456988034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 457088034c3dSAndy Adamson THRESHOLD_RD_IO); 457188034c3dSAndy Adamson if (status < 0) 457288034c3dSAndy Adamson goto xdr_error; 457388034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 457488034c3dSAndy Adamson THRESHOLD_WR_IO); 457588034c3dSAndy Adamson if (status < 0) 457688034c3dSAndy Adamson goto xdr_error; 457788034c3dSAndy Adamson 457888034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 457988034c3dSAndy Adamson res->bm = bitmap[0]; 458088034c3dSAndy Adamson 458188034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 458288034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 458388034c3dSAndy Adamson res->wr_io_sz); 458488034c3dSAndy Adamson xdr_error: 458588034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 458688034c3dSAndy Adamson return status; 458788034c3dSAndy Adamson } 458888034c3dSAndy Adamson 458988034c3dSAndy Adamson /* 459088034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 459188034c3dSAndy Adamson */ 459288034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 459388034c3dSAndy Adamson uint32_t *bitmap, 459488034c3dSAndy Adamson struct nfs4_threshold *res) 459588034c3dSAndy Adamson { 459688034c3dSAndy Adamson __be32 *p; 459788034c3dSAndy Adamson int status = 0; 459888034c3dSAndy Adamson uint32_t num; 459988034c3dSAndy Adamson 460088034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 460188034c3dSAndy Adamson return -EIO; 4602029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 46031549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 46041549210fSTrond Myklebust if (unlikely(res == NULL)) 46051549210fSTrond Myklebust return -EREMOTEIO; 460688034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 460788034c3dSAndy Adamson if (unlikely(!p)) 460888034c3dSAndy Adamson goto out_overflow; 460988034c3dSAndy Adamson num = be32_to_cpup(p); 461088034c3dSAndy Adamson if (num == 0) 461188034c3dSAndy Adamson return 0; 461288034c3dSAndy Adamson if (num > 1) 461388034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 461488034c3dSAndy Adamson "drivers per filesystem not supported\n", 461588034c3dSAndy Adamson __func__); 461688034c3dSAndy Adamson 461788034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4618029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 461988034c3dSAndy Adamson } 462088034c3dSAndy Adamson return status; 462188034c3dSAndy Adamson out_overflow: 462288034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 462388034c3dSAndy Adamson return -EIO; 462488034c3dSAndy Adamson } 462588034c3dSAndy Adamson 4626ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4627ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4628aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 46296926afd1STrond Myklebust const struct nfs_server *server) 46301da177e4SLinus Torvalds { 4631bca79478STrond Myklebust int status; 4632bca79478STrond Myklebust umode_t fmode = 0; 4633ae42c70aSBryan Schumaker uint32_t type; 4634ee7b75fcSTrond Myklebust int32_t err; 46351da177e4SLinus Torvalds 4636f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4637f26c7a78STrond Myklebust if (status < 0) 46381da177e4SLinus Torvalds goto xdr_error; 4639409924e4STrond Myklebust fattr->mode = 0; 4640409924e4STrond Myklebust if (status != 0) { 4641409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4642409924e4STrond Myklebust fattr->valid |= status; 4643409924e4STrond Myklebust } 46441da177e4SLinus Torvalds 4645f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4646f26c7a78STrond Myklebust if (status < 0) 46471da177e4SLinus Torvalds goto xdr_error; 4648409924e4STrond Myklebust fattr->valid |= status; 4649f26c7a78STrond Myklebust 4650f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4651f26c7a78STrond Myklebust if (status < 0) 46521da177e4SLinus Torvalds goto xdr_error; 4653409924e4STrond Myklebust fattr->valid |= status; 4654f26c7a78STrond Myklebust 4655f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4656f26c7a78STrond Myklebust if (status < 0) 46571da177e4SLinus Torvalds goto xdr_error; 4658409924e4STrond Myklebust fattr->valid |= status; 4659f26c7a78STrond Myklebust 4660ee7b75fcSTrond Myklebust err = 0; 4661ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4662ae42c70aSBryan Schumaker if (status < 0) 4663ae42c70aSBryan Schumaker goto xdr_error; 4664ae42c70aSBryan Schumaker 4665ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4666ae42c70aSBryan Schumaker if (status < 0) 4667ae42c70aSBryan Schumaker goto xdr_error; 4668ae42c70aSBryan Schumaker 4669f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4670f26c7a78STrond Myklebust if (status < 0) 46711da177e4SLinus Torvalds goto xdr_error; 4672409924e4STrond Myklebust fattr->valid |= status; 4673f26c7a78STrond Myklebust 46748b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4675f26c7a78STrond Myklebust if (status < 0) 4676683b57b4STrond Myklebust goto xdr_error; 4677409924e4STrond Myklebust fattr->valid |= status; 4678f26c7a78STrond Myklebust 46791ca843a2SAndreas Gruenbacher status = -EIO; 46801ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 46811ca843a2SAndreas Gruenbacher goto xdr_error; 46821ca843a2SAndreas Gruenbacher 4683f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4684f26c7a78STrond Myklebust if (status < 0) 46851da177e4SLinus Torvalds goto xdr_error; 4686409924e4STrond Myklebust if (status != 0) { 46871da177e4SLinus Torvalds fattr->mode |= fmode; 4688409924e4STrond Myklebust fattr->valid |= status; 4689409924e4STrond Myklebust } 4690f26c7a78STrond Myklebust 4691f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4692f26c7a78STrond Myklebust if (status < 0) 46931da177e4SLinus Torvalds goto xdr_error; 4694409924e4STrond Myklebust fattr->valid |= status; 4695f26c7a78STrond Myklebust 46966926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4697f26c7a78STrond Myklebust if (status < 0) 46981da177e4SLinus Torvalds goto xdr_error; 4699409924e4STrond Myklebust fattr->valid |= status; 4700f26c7a78STrond Myklebust 47016926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4702f26c7a78STrond Myklebust if (status < 0) 47031da177e4SLinus Torvalds goto xdr_error; 4704409924e4STrond Myklebust fattr->valid |= status; 4705f26c7a78STrond Myklebust 4706f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4707f26c7a78STrond Myklebust if (status < 0) 47081da177e4SLinus Torvalds goto xdr_error; 4709409924e4STrond Myklebust fattr->valid |= status; 4710f26c7a78STrond Myklebust 4711f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4712f26c7a78STrond Myklebust if (status < 0) 47131da177e4SLinus Torvalds goto xdr_error; 4714409924e4STrond Myklebust fattr->valid |= status; 4715f26c7a78STrond Myklebust 4716f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4717f26c7a78STrond Myklebust if (status < 0) 47181da177e4SLinus Torvalds goto xdr_error; 4719409924e4STrond Myklebust fattr->valid |= status; 4720f26c7a78STrond Myklebust 4721f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4722f26c7a78STrond Myklebust if (status < 0) 47231da177e4SLinus Torvalds goto xdr_error; 4724409924e4STrond Myklebust fattr->valid |= status; 4725f26c7a78STrond Myklebust 4726f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4727f26c7a78STrond Myklebust if (status < 0) 47281da177e4SLinus Torvalds goto xdr_error; 4729409924e4STrond Myklebust fattr->valid |= status; 4730f26c7a78STrond Myklebust 473128331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4732f26c7a78STrond Myklebust if (status < 0) 473399baf625SManoj Naik goto xdr_error; 4734409924e4STrond Myklebust fattr->valid |= status; 4735f26c7a78STrond Myklebust 47361ca843a2SAndreas Gruenbacher status = -EIO; 47371ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 47381ca843a2SAndreas Gruenbacher goto xdr_error; 47391ca843a2SAndreas Gruenbacher 474088034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 474188034c3dSAndy Adamson if (status < 0) 474288034c3dSAndy Adamson goto xdr_error; 474388034c3dSAndy Adamson 4744aa9c2669SDavid Quigley if (label) { 4745aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4746aa9c2669SDavid Quigley if (status < 0) 4747aa9c2669SDavid Quigley goto xdr_error; 4748aa9c2669SDavid Quigley fattr->valid |= status; 4749aa9c2669SDavid Quigley } 4750aa9c2669SDavid Quigley 4751ae42c70aSBryan Schumaker xdr_error: 4752ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4753ae42c70aSBryan Schumaker return status; 4754ae42c70aSBryan Schumaker } 4755ae42c70aSBryan Schumaker 4756ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47578b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4758aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4759ae42c70aSBryan Schumaker { 4760256e48bbSTrond Myklebust unsigned int savep; 4761ae42c70aSBryan Schumaker uint32_t attrlen, 4762dae100c2SFred Isaman bitmap[3] = {0}; 4763ae42c70aSBryan Schumaker int status; 4764ae42c70aSBryan Schumaker 4765ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4766ae42c70aSBryan Schumaker if (status < 0) 4767ae42c70aSBryan Schumaker goto xdr_error; 4768ae42c70aSBryan Schumaker 4769ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4770ae42c70aSBryan Schumaker if (status < 0) 4771ae42c70aSBryan Schumaker goto xdr_error; 4772ae42c70aSBryan Schumaker 4773ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4774ae42c70aSBryan Schumaker if (status < 0) 4775ae42c70aSBryan Schumaker goto xdr_error; 4776ae42c70aSBryan Schumaker 4777aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4778aa9c2669SDavid Quigley label, server); 4779ae42c70aSBryan Schumaker if (status < 0) 4780ae42c70aSBryan Schumaker goto xdr_error; 4781ae42c70aSBryan Schumaker 4782f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 47831da177e4SLinus Torvalds xdr_error: 47843110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 47851da177e4SLinus Torvalds return status; 47861da177e4SLinus Torvalds } 47871da177e4SLinus Torvalds 4788aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4789aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4790aa9c2669SDavid Quigley { 4791aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4792aa9c2669SDavid Quigley } 4793aa9c2669SDavid Quigley 4794ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47956926afd1STrond Myklebust const struct nfs_server *server) 4796ae42c70aSBryan Schumaker { 4797aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4798ae42c70aSBryan Schumaker } 47991da177e4SLinus Torvalds 4800504913fbSAndy Adamson /* 48013132e49eSJeff Layton * Decode potentially multiple layout types. 4802504913fbSAndy Adamson */ 48033132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4804ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4805504913fbSAndy Adamson { 4806b8a8a0ddSTrond Myklebust __be32 *p; 4807ca440c38SJeff Layton uint32_t i; 4808504913fbSAndy Adamson 4809504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4810504913fbSAndy Adamson if (unlikely(!p)) 4811504913fbSAndy Adamson goto out_overflow; 4812ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4813504913fbSAndy Adamson 4814504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4815ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4816504913fbSAndy Adamson return 0; 4817504913fbSAndy Adamson 4818504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4819ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4820504913fbSAndy Adamson if (unlikely(!p)) 4821504913fbSAndy Adamson goto out_overflow; 4822ca440c38SJeff Layton 4823ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4824ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4825ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4826ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4827ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4828ca440c38SJeff Layton } 4829ca440c38SJeff Layton 4830ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4831ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4832504913fbSAndy Adamson return 0; 4833504913fbSAndy Adamson out_overflow: 4834504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4835504913fbSAndy Adamson return -EIO; 4836504913fbSAndy Adamson } 4837504913fbSAndy Adamson 4838504913fbSAndy Adamson /* 4839504913fbSAndy Adamson * The type of file system exported. 4840504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4841504913fbSAndy Adamson */ 4842504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4843ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4844504913fbSAndy Adamson { 4845504913fbSAndy Adamson int status = 0; 4846504913fbSAndy Adamson 4847504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4848504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4849504913fbSAndy Adamson return -EIO; 4850504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4851ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4852504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 48533132e49eSJeff Layton } 4854504913fbSAndy Adamson return status; 4855504913fbSAndy Adamson } 4856504913fbSAndy Adamson 4857dae100c2SFred Isaman /* 4858dae100c2SFred Isaman * The prefered block size for layout directed io 4859dae100c2SFred Isaman */ 4860dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4861dae100c2SFred Isaman uint32_t *res) 4862dae100c2SFred Isaman { 4863dae100c2SFred Isaman __be32 *p; 4864dae100c2SFred Isaman 4865dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4866dae100c2SFred Isaman *res = 0; 4867dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4868dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4869dae100c2SFred Isaman if (unlikely(!p)) { 4870dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4871dae100c2SFred Isaman return -EIO; 4872dae100c2SFred Isaman } 4873dae100c2SFred Isaman *res = be32_to_cpup(p); 4874dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4875dae100c2SFred Isaman } 4876dae100c2SFred Isaman return 0; 4877dae100c2SFred Isaman } 4878dae100c2SFred Isaman 48792a92ee92SPeng Tao /* 48802a92ee92SPeng Tao * The granularity of a CLONE operation. 48812a92ee92SPeng Tao */ 48822a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 48832a92ee92SPeng Tao uint32_t *res) 48842a92ee92SPeng Tao { 48852a92ee92SPeng Tao __be32 *p; 48862a92ee92SPeng Tao 48872a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 48882a92ee92SPeng Tao *res = 0; 48892a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 48902a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 48912a92ee92SPeng Tao if (unlikely(!p)) { 48922a92ee92SPeng Tao print_overflow_msg(__func__, xdr); 48932a92ee92SPeng Tao return -EIO; 48942a92ee92SPeng Tao } 48952a92ee92SPeng Tao *res = be32_to_cpup(p); 48962a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 48972a92ee92SPeng Tao } 48982a92ee92SPeng Tao return 0; 48992a92ee92SPeng Tao } 49002a92ee92SPeng Tao 49011da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 49021da177e4SLinus Torvalds { 4903256e48bbSTrond Myklebust unsigned int savep; 4904dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 49051da177e4SLinus Torvalds int status; 49061da177e4SLinus Torvalds 49071da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 49081da177e4SLinus Torvalds goto xdr_error; 49091da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 49101da177e4SLinus Torvalds goto xdr_error; 49111da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 49121da177e4SLinus Torvalds goto xdr_error; 49131da177e4SLinus Torvalds 49141da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 49151da177e4SLinus Torvalds 49161da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 49171da177e4SLinus Torvalds goto xdr_error; 49181da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 49191da177e4SLinus Torvalds goto xdr_error; 49201da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 49211da177e4SLinus Torvalds goto xdr_error; 49221da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 49231da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 49241da177e4SLinus Torvalds goto xdr_error; 49251da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 49261ca843a2SAndreas Gruenbacher 49271ca843a2SAndreas Gruenbacher status = -EIO; 49281ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 49291ca843a2SAndreas Gruenbacher goto xdr_error; 49301ca843a2SAndreas Gruenbacher 493155b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 493255b6e774SRicardo Labiaga if (status != 0) 493355b6e774SRicardo Labiaga goto xdr_error; 4934ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4935504913fbSAndy Adamson if (status != 0) 4936504913fbSAndy Adamson goto xdr_error; 49371ca843a2SAndreas Gruenbacher 49381ca843a2SAndreas Gruenbacher status = -EIO; 49391ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 49401ca843a2SAndreas Gruenbacher goto xdr_error; 49411ca843a2SAndreas Gruenbacher 4942dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4943dae100c2SFred Isaman if (status) 4944dae100c2SFred Isaman goto xdr_error; 49452a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 49462a92ee92SPeng Tao if (status) 49472a92ee92SPeng Tao goto xdr_error; 49481da177e4SLinus Torvalds 49491da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 49501da177e4SLinus Torvalds xdr_error: 49513110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 49521da177e4SLinus Torvalds return status; 49531da177e4SLinus Torvalds } 49541da177e4SLinus Torvalds 49551da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 49561da177e4SLinus Torvalds { 49578687b63aSAl Viro __be32 *p; 49581da177e4SLinus Torvalds uint32_t len; 49591da177e4SLinus Torvalds int status; 49601da177e4SLinus Torvalds 49619936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 49629936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 49639936781dSTrond Myklebust 49641da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 49651da177e4SLinus Torvalds if (status) 49661da177e4SLinus Torvalds return status; 49671da177e4SLinus Torvalds 4968c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4969c0eae66eSBenny Halevy if (unlikely(!p)) 4970c0eae66eSBenny Halevy goto out_overflow; 4971cccddf4fSBenny Halevy len = be32_to_cpup(p); 49721da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 49731da177e4SLinus Torvalds return -EIO; 49741da177e4SLinus Torvalds fh->size = len; 4975c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4976c0eae66eSBenny Halevy if (unlikely(!p)) 4977c0eae66eSBenny Halevy goto out_overflow; 497899398d06SBenny Halevy memcpy(fh->data, p, len); 49791da177e4SLinus Torvalds return 0; 4980c0eae66eSBenny Halevy out_overflow: 4981c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4982c0eae66eSBenny Halevy return -EIO; 49831da177e4SLinus Torvalds } 49841da177e4SLinus Torvalds 49851da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 49861da177e4SLinus Torvalds { 49871da177e4SLinus Torvalds int status; 49881da177e4SLinus Torvalds 49891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 49901da177e4SLinus Torvalds if (status) 49911da177e4SLinus Torvalds return status; 49921da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 49931da177e4SLinus Torvalds } 49941da177e4SLinus Torvalds 49951da177e4SLinus Torvalds /* 49961da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 49971da177e4SLinus Torvalds */ 4998911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 49991da177e4SLinus Torvalds { 5000911d1aafSTrond Myklebust uint64_t offset, length, clientid; 50018687b63aSAl Viro __be32 *p; 5002911d1aafSTrond Myklebust uint32_t namelen, type; 50031da177e4SLinus Torvalds 5004babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 5005c0eae66eSBenny Halevy if (unlikely(!p)) 5006c0eae66eSBenny Halevy goto out_overflow; 5007babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 50083ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 5009babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 5010babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 5011911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 5012911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 5013911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 5014911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 5015911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 5016911d1aafSTrond Myklebust if (type & 1) 5017911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 5018911d1aafSTrond Myklebust fl->fl_pid = 0; 5019911d1aafSTrond Myklebust } 5020babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 5021babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 5022babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 5023c0eae66eSBenny Halevy if (likely(p)) 50241da177e4SLinus Torvalds return -NFS4ERR_DENIED; 5025c0eae66eSBenny Halevy out_overflow: 5026c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5027c0eae66eSBenny Halevy return -EIO; 50281da177e4SLinus Torvalds } 50291da177e4SLinus Torvalds 5030911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 50311da177e4SLinus Torvalds { 50321da177e4SLinus Torvalds int status; 50331da177e4SLinus Torvalds 50341da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 5035c1d51931STrond Myklebust if (status == -EIO) 5036c1d51931STrond Myklebust goto out; 50371da177e4SLinus Torvalds if (status == 0) { 503893b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 503907d30434SBenny Halevy if (unlikely(status)) 504007d30434SBenny Halevy goto out; 50411da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 5042c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 5043c1d51931STrond Myklebust if (res->open_seqid != NULL) 5044c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 5045c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 5046c1d51931STrond Myklebust out: 50471da177e4SLinus Torvalds return status; 50481da177e4SLinus Torvalds } 50491da177e4SLinus Torvalds 5050911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 50511da177e4SLinus Torvalds { 50521da177e4SLinus Torvalds int status; 50531da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 50541da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 5055911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 50561da177e4SLinus Torvalds return status; 50571da177e4SLinus Torvalds } 50581da177e4SLinus Torvalds 5059911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 50601da177e4SLinus Torvalds { 50611da177e4SLinus Torvalds int status; 50621da177e4SLinus Torvalds 50631da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 5064c1d51931STrond Myklebust if (status != -EIO) 5065c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 506607d30434SBenny Halevy if (status == 0) 506793b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 50681da177e4SLinus Torvalds return status; 50691da177e4SLinus Torvalds } 50701da177e4SLinus Torvalds 5071d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 5072d3c7b7ccSTrond Myklebust { 5073d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5074d3c7b7ccSTrond Myklebust } 5075d3c7b7ccSTrond Myklebust 50761da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 50771da177e4SLinus Torvalds { 50781da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 50791da177e4SLinus Torvalds } 50801da177e4SLinus Torvalds 50815b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr) 50825b5faaf6SJeff Layton { 50835b5faaf6SJeff Layton return decode_op_hdr(xdr, OP_LOOKUPP); 50845b5faaf6SJeff Layton } 50855b5faaf6SJeff Layton 50861da177e4SLinus Torvalds /* This is too sick! */ 50877d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 50887d160a6cSTrond Myklebust unsigned long *pagemod_limit) 50891da177e4SLinus Torvalds { 50908687b63aSAl Viro __be32 *p; 50911da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 50927d160a6cSTrond Myklebust u64 maxsize = 0; 50931da177e4SLinus Torvalds 5094c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5095c0eae66eSBenny Halevy if (unlikely(!p)) 5096c0eae66eSBenny Halevy goto out_overflow; 50976f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 50981da177e4SLinus Torvalds switch (limit_type) { 50997d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 51007d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 51011da177e4SLinus Torvalds break; 51027d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 51036f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5104cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 51057d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 51061da177e4SLinus Torvalds } 510709cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 51087d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 51091da177e4SLinus Torvalds return 0; 5110c0eae66eSBenny Halevy out_overflow: 5111c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5112c0eae66eSBenny Halevy return -EIO; 51131da177e4SLinus Torvalds } 51141da177e4SLinus Torvalds 51156ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 51166ae37339STrond Myklebust uint32_t delegation_type, 51176ae37339STrond Myklebust struct nfs_openres *res) 51181da177e4SLinus Torvalds { 51198687b63aSAl Viro __be32 *p; 512007d30434SBenny Halevy int status; 51211da177e4SLinus Torvalds 512293b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 512307d30434SBenny Halevy if (unlikely(status)) 512407d30434SBenny Halevy return status; 5125c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5126c0eae66eSBenny Halevy if (unlikely(!p)) 5127c0eae66eSBenny Halevy goto out_overflow; 5128cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 512905d564feSAndy Adamson 51301da177e4SLinus Torvalds switch (delegation_type) { 51311da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 51321da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 51331da177e4SLinus Torvalds break; 51341da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 51351da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 51367d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 51371da177e4SLinus Torvalds return -EIO; 51381da177e4SLinus Torvalds } 51391bbe60ffSTrond Myklebust return decode_ace(xdr, NULL); 5140c0eae66eSBenny Halevy out_overflow: 5141c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5142c0eae66eSBenny Halevy return -EIO; 51431da177e4SLinus Torvalds } 51441da177e4SLinus Torvalds 51456ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51466ae37339STrond Myklebust { 51476ae37339STrond Myklebust __be32 *p; 51486ae37339STrond Myklebust uint32_t why_no_delegation; 51496ae37339STrond Myklebust 51506ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51516ae37339STrond Myklebust if (unlikely(!p)) 51526ae37339STrond Myklebust goto out_overflow; 51536ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 51546ae37339STrond Myklebust switch (why_no_delegation) { 51556ae37339STrond Myklebust case WND4_CONTENTION: 51566ae37339STrond Myklebust case WND4_RESOURCE: 51576ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 51586ae37339STrond Myklebust /* Ignore for now */ 51596ae37339STrond Myklebust } 51606ae37339STrond Myklebust return 0; 51616ae37339STrond Myklebust out_overflow: 51626ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51636ae37339STrond Myklebust return -EIO; 51646ae37339STrond Myklebust } 51656ae37339STrond Myklebust 51666ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51676ae37339STrond Myklebust { 51686ae37339STrond Myklebust __be32 *p; 51696ae37339STrond Myklebust uint32_t delegation_type; 51706ae37339STrond Myklebust 51716ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51726ae37339STrond Myklebust if (unlikely(!p)) 51736ae37339STrond Myklebust goto out_overflow; 51746ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 51756ae37339STrond Myklebust res->delegation_type = 0; 51766ae37339STrond Myklebust switch (delegation_type) { 51776ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 51786ae37339STrond Myklebust return 0; 51796ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 51806ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 51816ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 51826ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 51836ae37339STrond Myklebust return decode_no_delegation(xdr, res); 51846ae37339STrond Myklebust } 51856ae37339STrond Myklebust return -EIO; 51866ae37339STrond Myklebust out_overflow: 51876ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51886ae37339STrond Myklebust return -EIO; 51896ae37339STrond Myklebust } 51906ae37339STrond Myklebust 51911da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 51921da177e4SLinus Torvalds { 51938687b63aSAl Viro __be32 *p; 5194aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 51951da177e4SLinus Torvalds int status; 51961da177e4SLinus Torvalds 5197c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5198c7848f69STrond Myklebust return status; 5199c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5200c7848f69STrond Myklebust if (status) 5201c7848f69STrond Myklebust return status; 520293b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 520307d30434SBenny Halevy if (unlikely(status)) 52041da177e4SLinus Torvalds return status; 52051da177e4SLinus Torvalds 52061da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 52071da177e4SLinus Torvalds 5208c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5209c0eae66eSBenny Halevy if (unlikely(!p)) 5210c0eae66eSBenny Halevy goto out_overflow; 52116f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5212cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 52131da177e4SLinus Torvalds if (bmlen > 10) 52141da177e4SLinus Torvalds goto xdr_error; 52151da177e4SLinus Torvalds 5216c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5217c0eae66eSBenny Halevy if (unlikely(!p)) 5218c0eae66eSBenny Halevy goto out_overflow; 5219aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5220aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 52216f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5222aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5223aa53ed54SJeff Layton res->attrset[i] = 0; 5224aa53ed54SJeff Layton 52251da177e4SLinus Torvalds return decode_delegation(xdr, res); 52261da177e4SLinus Torvalds xdr_error: 52273110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 52281da177e4SLinus Torvalds return -EIO; 5229c0eae66eSBenny Halevy out_overflow: 5230c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5231c0eae66eSBenny Halevy return -EIO; 52321da177e4SLinus Torvalds } 52331da177e4SLinus Torvalds 52341da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 52351da177e4SLinus Torvalds { 52361da177e4SLinus Torvalds int status; 52371da177e4SLinus Torvalds 52381da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5239c1d51931STrond Myklebust if (status != -EIO) 5240c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 524107d30434SBenny Halevy if (!status) 524293b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52431da177e4SLinus Torvalds return status; 52441da177e4SLinus Torvalds } 52451da177e4SLinus Torvalds 52461da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 52471da177e4SLinus Torvalds { 52481da177e4SLinus Torvalds int status; 52491da177e4SLinus Torvalds 52501da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5251c1d51931STrond Myklebust if (status != -EIO) 5252c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 525307d30434SBenny Halevy if (!status) 525493b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52551da177e4SLinus Torvalds return status; 52561da177e4SLinus Torvalds } 52571da177e4SLinus Torvalds 52581da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 52591da177e4SLinus Torvalds { 52601da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 52611da177e4SLinus Torvalds } 52621da177e4SLinus Torvalds 52631da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 52641da177e4SLinus Torvalds { 52651da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 52661da177e4SLinus Torvalds } 52671da177e4SLinus Torvalds 52689137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 52699137bdf3SAnna Schumaker struct nfs_pgio_res *res) 52701da177e4SLinus Torvalds { 52718687b63aSAl Viro __be32 *p; 527264bd577eSTrond Myklebust uint32_t count, eof, recvd; 52731da177e4SLinus Torvalds int status; 52741da177e4SLinus Torvalds 52751da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 52761da177e4SLinus Torvalds if (status) 52771da177e4SLinus Torvalds return status; 5278c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5279c0eae66eSBenny Halevy if (unlikely(!p)) 5280c0eae66eSBenny Halevy goto out_overflow; 52816f723f77SBenny Halevy eof = be32_to_cpup(p++); 5282cccddf4fSBenny Halevy count = be32_to_cpup(p); 528364bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 52841da177e4SLinus Torvalds if (count > recvd) { 5285fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 52861da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 52871da177e4SLinus Torvalds count = recvd; 52881da177e4SLinus Torvalds eof = 0; 52891da177e4SLinus Torvalds } 52901da177e4SLinus Torvalds res->eof = eof; 52911da177e4SLinus Torvalds res->count = count; 52921da177e4SLinus Torvalds return 0; 5293c0eae66eSBenny Halevy out_overflow: 5294c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5295c0eae66eSBenny Halevy return -EIO; 52961da177e4SLinus Torvalds } 52971da177e4SLinus Torvalds 52981da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 52991da177e4SLinus Torvalds { 5300bcecff77SChuck Lever int status; 5301cd93710eSChuck Lever __be32 verf[2]; 53021da177e4SLinus Torvalds 53031da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5304db942bbdSBenny Halevy if (!status) 5305db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5306db942bbdSBenny Halevy if (unlikely(status)) 53071da177e4SLinus Torvalds return status; 5308cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 530944109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5310cd93710eSChuck Lever __func__, verf[0], verf[1]); 531164bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 53121da177e4SLinus Torvalds } 53131da177e4SLinus Torvalds 53141da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 53151da177e4SLinus Torvalds { 53161da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5317bcecff77SChuck Lever u32 len, recvd; 53188687b63aSAl Viro __be32 *p; 53191da177e4SLinus Torvalds int status; 53201da177e4SLinus Torvalds 53211da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 53221da177e4SLinus Torvalds if (status) 53231da177e4SLinus Torvalds return status; 53241da177e4SLinus Torvalds 53251da177e4SLinus Torvalds /* Convert length of symlink */ 5326c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5327c0eae66eSBenny Halevy if (unlikely(!p)) 5328c0eae66eSBenny Halevy goto out_overflow; 5329cccddf4fSBenny Halevy len = be32_to_cpup(p); 53301da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5331fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 53321da177e4SLinus Torvalds return -ENAMETOOLONG; 53331da177e4SLinus Torvalds } 533464bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 53351da177e4SLinus Torvalds if (recvd < len) { 5336fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 53371da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 53381da177e4SLinus Torvalds return -EIO; 53391da177e4SLinus Torvalds } 53401da177e4SLinus Torvalds /* 53411da177e4SLinus Torvalds * The XDR encode routine has set things up so that 53421da177e4SLinus Torvalds * the link text will be copied directly into the 53431da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 53441da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 53451da177e4SLinus Torvalds * null-termination). 53461da177e4SLinus Torvalds */ 5347b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 53481da177e4SLinus Torvalds return 0; 5349c0eae66eSBenny Halevy out_overflow: 5350c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5351c0eae66eSBenny Halevy return -EIO; 53521da177e4SLinus Torvalds } 53531da177e4SLinus Torvalds 53541da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 53551da177e4SLinus Torvalds { 53561da177e4SLinus Torvalds int status; 53571da177e4SLinus Torvalds 53581da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 53591da177e4SLinus Torvalds if (status) 53601da177e4SLinus Torvalds goto out; 53611da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 53621da177e4SLinus Torvalds out: 53631da177e4SLinus Torvalds return status; 53641da177e4SLinus Torvalds } 53651da177e4SLinus Torvalds 53661da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 53671da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 53681da177e4SLinus Torvalds { 53691da177e4SLinus Torvalds int status; 53701da177e4SLinus Torvalds 53711da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 53721da177e4SLinus Torvalds if (status) 53731da177e4SLinus Torvalds goto out; 53741da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 53751da177e4SLinus Torvalds goto out; 53761da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 53771da177e4SLinus Torvalds out: 53781da177e4SLinus Torvalds return status; 53791da177e4SLinus Torvalds } 53801da177e4SLinus Torvalds 53811da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 53821da177e4SLinus Torvalds { 53831da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 53841da177e4SLinus Torvalds } 53851da177e4SLinus Torvalds 538656ae19f3STrond Myklebust static int 538756ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 538856ae19f3STrond Myklebust { 538956ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 539056ae19f3STrond Myklebust } 539156ae19f3STrond Myklebust 5392029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5393bf118a34SAndy Adamson struct nfs_getaclres *res) 5394029d105eSJ. Bruce Fields { 5395256e48bbSTrond Myklebust unsigned int savep; 5396029d105eSJ. Bruce Fields uint32_t attrlen, 5397dae100c2SFred Isaman bitmap[3] = {0}; 5398029d105eSJ. Bruce Fields int status; 5399cff298c7STrond Myklebust unsigned int pg_offset; 5400029d105eSJ. Bruce Fields 5401bf118a34SAndy Adamson res->acl_len = 0; 5402029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5403029d105eSJ. Bruce Fields goto out; 54045a006899SSachin Prabhu 5405519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5406519d3959STrond Myklebust 5407cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5408cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 54095a006899SSachin Prabhu 5410029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5411029d105eSJ. Bruce Fields goto out; 5412029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5413029d105eSJ. Bruce Fields goto out; 5414029d105eSJ. Bruce Fields 5415029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5416029d105eSJ. Bruce Fields return -EIO; 5417029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5418029d105eSJ. Bruce Fields 5419bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5420bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5421bf118a34SAndy Adamson * variable length bitmaps.*/ 5422cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5423519d3959STrond Myklebust res->acl_len = attrlen; 54241f1ea6c2STrond Myklebust 54251f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 54261f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 54271f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 54281f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5429519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5430cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5431029d105eSJ. Bruce Fields } 54328c233cf9SJ. Bruce Fields } else 54338c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5434029d105eSJ. Bruce Fields 5435029d105eSJ. Bruce Fields out: 5436029d105eSJ. Bruce Fields return status; 5437029d105eSJ. Bruce Fields } 5438029d105eSJ. Bruce Fields 54391da177e4SLinus Torvalds static int 54401da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 54411da177e4SLinus Torvalds { 54421da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 54431da177e4SLinus Torvalds } 54441da177e4SLinus Torvalds 54459e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 54461da177e4SLinus Torvalds { 54471da177e4SLinus Torvalds int status; 54481da177e4SLinus Torvalds 54491da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 54501da177e4SLinus Torvalds if (status) 54511da177e4SLinus Torvalds return status; 545237c88763STrond Myklebust if (decode_bitmap4(xdr, NULL, 0) >= 0) 54531da177e4SLinus Torvalds return 0; 5454c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5455c0eae66eSBenny Halevy return -EIO; 54561da177e4SLinus Torvalds } 54571da177e4SLinus Torvalds 5458bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 54591da177e4SLinus Torvalds { 54608687b63aSAl Viro __be32 *p; 54611da177e4SLinus Torvalds uint32_t opnum; 54621da177e4SLinus Torvalds int32_t nfserr; 54631da177e4SLinus Torvalds 5464c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5465c0eae66eSBenny Halevy if (unlikely(!p)) 5466c0eae66eSBenny Halevy goto out_overflow; 54676f723f77SBenny Halevy opnum = be32_to_cpup(p++); 54681da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5469fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 54701da177e4SLinus Torvalds " %d\n", opnum); 54711da177e4SLinus Torvalds return -EIO; 54721da177e4SLinus Torvalds } 5473cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 54741da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5475c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5476c0eae66eSBenny Halevy if (unlikely(!p)) 5477c0eae66eSBenny Halevy goto out_overflow; 5478bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5479bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 54801da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 54811da177e4SLinus Torvalds uint32_t len; 54821da177e4SLinus Torvalds 54831da177e4SLinus Torvalds /* skip netid string */ 5484c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5485c0eae66eSBenny Halevy if (unlikely(!p)) 5486c0eae66eSBenny Halevy goto out_overflow; 5487cccddf4fSBenny Halevy len = be32_to_cpup(p); 5488c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5489c0eae66eSBenny Halevy if (unlikely(!p)) 5490c0eae66eSBenny Halevy goto out_overflow; 54911da177e4SLinus Torvalds 54921da177e4SLinus Torvalds /* skip uaddr string */ 5493c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5494c0eae66eSBenny Halevy if (unlikely(!p)) 5495c0eae66eSBenny Halevy goto out_overflow; 5496cccddf4fSBenny Halevy len = be32_to_cpup(p); 5497c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5498c0eae66eSBenny Halevy if (unlikely(!p)) 5499c0eae66eSBenny Halevy goto out_overflow; 55001da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 55011da177e4SLinus Torvalds } else 5502856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 55031da177e4SLinus Torvalds 55041da177e4SLinus Torvalds return 0; 5505c0eae66eSBenny Halevy out_overflow: 5506c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5507c0eae66eSBenny Halevy return -EIO; 55081da177e4SLinus Torvalds } 55091da177e4SLinus Torvalds 55101da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 55111da177e4SLinus Torvalds { 55121da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 55131da177e4SLinus Torvalds } 55141da177e4SLinus Torvalds 55159137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 55161da177e4SLinus Torvalds { 55178687b63aSAl Viro __be32 *p; 55181da177e4SLinus Torvalds int status; 55191da177e4SLinus Torvalds 55201da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 55211da177e4SLinus Torvalds if (status) 55221da177e4SLinus Torvalds return status; 55231da177e4SLinus Torvalds 55242f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5525c0eae66eSBenny Halevy if (unlikely(!p)) 5526c0eae66eSBenny Halevy goto out_overflow; 55276f723f77SBenny Halevy res->count = be32_to_cpup(p++); 55286f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 55292f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5530c0eae66eSBenny Halevy out_overflow: 5531c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5532c0eae66eSBenny Halevy return -EIO; 55331da177e4SLinus Torvalds } 55341da177e4SLinus Torvalds 55351da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 55361da177e4SLinus Torvalds { 55371da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 55381da177e4SLinus Torvalds } 55391da177e4SLinus Torvalds 5540fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5541fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 55425a5ea0d4SBryan Schumaker { 5543fb15b26fSChuck Lever u32 oid_len; 55445a5ea0d4SBryan Schumaker __be32 *p; 55455a5ea0d4SBryan Schumaker 55465a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55475a5ea0d4SBryan Schumaker if (unlikely(!p)) 55485a5ea0d4SBryan Schumaker goto out_overflow; 5549fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5550fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 55515a5ea0d4SBryan Schumaker goto out_err; 55525a5ea0d4SBryan Schumaker 5553fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 55545a5ea0d4SBryan Schumaker if (unlikely(!p)) 55555a5ea0d4SBryan Schumaker goto out_overflow; 5556fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5557fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 55585a5ea0d4SBryan Schumaker 55595a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 55605a5ea0d4SBryan Schumaker if (unlikely(!p)) 55615a5ea0d4SBryan Schumaker goto out_overflow; 5562fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5563fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 55645a5ea0d4SBryan Schumaker 55655a5ea0d4SBryan Schumaker return 0; 55665a5ea0d4SBryan Schumaker 55675a5ea0d4SBryan Schumaker out_overflow: 55685a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55695a5ea0d4SBryan Schumaker return -EIO; 55705a5ea0d4SBryan Schumaker out_err: 55715a5ea0d4SBryan Schumaker return -EINVAL; 55725a5ea0d4SBryan Schumaker } 55735a5ea0d4SBryan Schumaker 557431e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 55755a5ea0d4SBryan Schumaker { 5576fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5577fb15b26fSChuck Lever unsigned int i, num_flavors; 55785a5ea0d4SBryan Schumaker int status; 55795a5ea0d4SBryan Schumaker __be32 *p; 55805a5ea0d4SBryan Schumaker 55815a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55825a5ea0d4SBryan Schumaker if (unlikely(!p)) 55835a5ea0d4SBryan Schumaker goto out_overflow; 55845a5ea0d4SBryan Schumaker 5585c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5586c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5587c3dfc280SBryan Schumaker 5588c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 55895a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5590c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 55915a5ea0d4SBryan Schumaker break; 55925a5ea0d4SBryan Schumaker 55935a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55945a5ea0d4SBryan Schumaker if (unlikely(!p)) 55955a5ea0d4SBryan Schumaker goto out_overflow; 55965a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 55975a5ea0d4SBryan Schumaker 55985a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5599613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5600613e901eSBryan Schumaker if (status) 5601613e901eSBryan Schumaker goto out; 56025a5ea0d4SBryan Schumaker } 5603c3dfc280SBryan Schumaker res->flavors->num_flavors++; 56045a5ea0d4SBryan Schumaker } 56055a5ea0d4SBryan Schumaker 560631e4dda4SBryan Schumaker status = 0; 5607613e901eSBryan Schumaker out: 5608613e901eSBryan Schumaker return status; 56095a5ea0d4SBryan Schumaker out_overflow: 56105a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 56115a5ea0d4SBryan Schumaker return -EIO; 56125a5ea0d4SBryan Schumaker } 56135a5ea0d4SBryan Schumaker 561431e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 561531e4dda4SBryan Schumaker { 561631e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 561731e4dda4SBryan Schumaker if (status) 561831e4dda4SBryan Schumaker return status; 561931e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 562031e4dda4SBryan Schumaker } 562131e4dda4SBryan Schumaker 562299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 562331e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 562431e4dda4SBryan Schumaker { 562531e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 562631e4dda4SBryan Schumaker if (status) 562731e4dda4SBryan Schumaker return status; 562831e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 562931e4dda4SBryan Schumaker } 563031e4dda4SBryan Schumaker 56312031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 56322031cd1aSWeston Andros Adamson { 56332031cd1aSWeston Andros Adamson __be32 *p; 56342031cd1aSWeston Andros Adamson uint32_t bitmap_words; 56352031cd1aSWeston Andros Adamson unsigned int i; 56362031cd1aSWeston Andros Adamson 56372031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56384edabfd7SPan Bian if (!p) 56394edabfd7SPan Bian return -EIO; 56402031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 56412031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 56422031cd1aSWeston Andros Adamson return -EIO; 56432031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 56442031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 56452031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 56462031cd1aSWeston Andros Adamson 56472031cd1aSWeston Andros Adamson return 0; 56482031cd1aSWeston Andros Adamson } 56492031cd1aSWeston Andros Adamson 565099fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 565199fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 565299fe60d0SBenny Halevy { 565399fe60d0SBenny Halevy __be32 *p; 565499fe60d0SBenny Halevy uint32_t dummy; 56552460ba57SBenny Halevy char *dummy_str; 565699fe60d0SBenny Halevy int status; 56577d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 565899fe60d0SBenny Halevy 565999fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 566099fe60d0SBenny Halevy if (status) 566199fe60d0SBenny Halevy return status; 566299fe60d0SBenny Halevy 5663c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5664c0eae66eSBenny Halevy if (unlikely(!p)) 5665c0eae66eSBenny Halevy goto out_overflow; 566632b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5667c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5668c0eae66eSBenny Halevy if (unlikely(!p)) 5669c0eae66eSBenny Halevy goto out_overflow; 567032b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 567132b01310STrond Myklebust res->flags = be32_to_cpup(p++); 567299fe60d0SBenny Halevy 56732031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 56742031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 56752031cd1aSWeston Andros Adamson case SP4_NONE: 56762031cd1aSWeston Andros Adamson break; 56772031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 56782031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 56792031cd1aSWeston Andros Adamson if (status) 56802031cd1aSWeston Andros Adamson return status; 56812031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 56822031cd1aSWeston Andros Adamson if (status) 56832031cd1aSWeston Andros Adamson return status; 56842031cd1aSWeston Andros Adamson break; 56852031cd1aSWeston Andros Adamson default: 56862031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 568799fe60d0SBenny Halevy return -EIO; 56882031cd1aSWeston Andros Adamson } 568999fe60d0SBenny Halevy 5690acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5691c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5692c0eae66eSBenny Halevy if (unlikely(!p)) 5693c0eae66eSBenny Halevy goto out_overflow; 5694acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 569599fe60d0SBenny Halevy 5696acdeb69dSChuck Lever /* server_owner4.so_major_id */ 56972460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56982460ba57SBenny Halevy if (unlikely(status)) 56992460ba57SBenny Halevy return status; 5700acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5701acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 570278fe0f41SWeston Andros Adamson 5703acdeb69dSChuck Lever /* server_scope4 */ 5704acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5705acdeb69dSChuck Lever if (unlikely(status)) 5706acdeb69dSChuck Lever return status; 570778fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 570878fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 570978fe0f41SWeston Andros Adamson 57107d2ed9acSWeston Andros Adamson /* Implementation Id */ 57117d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 57127d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57137d2ed9acSWeston Andros Adamson goto out_overflow; 57147d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 57157d2ed9acSWeston Andros Adamson 57167d2ed9acSWeston Andros Adamson if (impl_id_count) { 57177d2ed9acSWeston Andros Adamson /* nii_domain */ 57182460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57192460ba57SBenny Halevy if (unlikely(status)) 57202460ba57SBenny Halevy return status; 57217d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 572299fe60d0SBenny Halevy 57237d2ed9acSWeston Andros Adamson /* nii_name */ 57247d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57257d2ed9acSWeston Andros Adamson if (unlikely(status)) 57267d2ed9acSWeston Andros Adamson return status; 57277d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 57287d2ed9acSWeston Andros Adamson 57297d2ed9acSWeston Andros Adamson /* nii_date */ 57307d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 57317d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57327d2ed9acSWeston Andros Adamson goto out_overflow; 57337d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 57347d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 57357d2ed9acSWeston Andros Adamson 57367d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 57377d2ed9acSWeston Andros Adamson } 573899fe60d0SBenny Halevy return 0; 5739c0eae66eSBenny Halevy out_overflow: 5740c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5741c0eae66eSBenny Halevy return -EIO; 574299fe60d0SBenny Halevy } 5743fc931582SAndy Adamson 5744fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5745fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5746fc931582SAndy Adamson { 5747fc931582SAndy Adamson __be32 *p; 5748c9c30dd5SBenny Halevy u32 nr_attrs, val; 5749fc931582SAndy Adamson 5750c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5751c0eae66eSBenny Halevy if (unlikely(!p)) 5752c0eae66eSBenny Halevy goto out_overflow; 5753c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5754c9c30dd5SBenny Halevy if (val) 5755c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 57566f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 57576f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 57586f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 57596f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 57606f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5761cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5762fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5763a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5764a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5765fc931582SAndy Adamson return -EINVAL; 5766fc931582SAndy Adamson } 5767c0eae66eSBenny Halevy if (nr_attrs == 1) { 5768c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5769c0eae66eSBenny Halevy if (unlikely(!p)) 5770c0eae66eSBenny Halevy goto out_overflow; 5771c0eae66eSBenny Halevy } 5772fc931582SAndy Adamson return 0; 5773c0eae66eSBenny Halevy out_overflow: 5774c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5775c0eae66eSBenny Halevy return -EIO; 5776fc931582SAndy Adamson } 5777fc931582SAndy Adamson 5778e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5779e78291e4SBenny Halevy { 5780e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5781fc931582SAndy Adamson } 5782fc931582SAndy Adamson 57837c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 57847c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 57857c44f1aeSWeston Andros Adamson { 57867c44f1aeSWeston Andros Adamson __be32 *p; 57877c44f1aeSWeston Andros Adamson int status; 57887c44f1aeSWeston Andros Adamson 57897c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 57907c44f1aeSWeston Andros Adamson if (!status) 579171a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 57927c44f1aeSWeston Andros Adamson if (unlikely(status)) 57937c44f1aeSWeston Andros Adamson return status; 57947c44f1aeSWeston Andros Adamson 57957c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 57967c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 57977c44f1aeSWeston Andros Adamson if (unlikely(!p)) 57987c44f1aeSWeston Andros Adamson goto out_overflow; 57997c44f1aeSWeston Andros Adamson 58007c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 58017c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 58027c44f1aeSWeston Andros Adamson return -EIO; 58037c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 58047c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 58057c44f1aeSWeston Andros Adamson else 58067c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 58077c44f1aeSWeston Andros Adamson 58087c44f1aeSWeston Andros Adamson return 0; 58097c44f1aeSWeston Andros Adamson out_overflow: 58107c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 58117c44f1aeSWeston Andros Adamson return -EIO; 58127c44f1aeSWeston Andros Adamson } 58137c44f1aeSWeston Andros Adamson 5814fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5815fc931582SAndy Adamson struct nfs41_create_session_res *res) 5816fc931582SAndy Adamson { 5817fc931582SAndy Adamson __be32 *p; 5818fc931582SAndy Adamson int status; 5819fc931582SAndy Adamson 5820fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5821e78291e4SBenny Halevy if (!status) 582279969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5823e78291e4SBenny Halevy if (unlikely(status)) 5824fc931582SAndy Adamson return status; 5825fc931582SAndy Adamson 5826fc931582SAndy Adamson /* seqid, flags */ 5827c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5828c0eae66eSBenny Halevy if (unlikely(!p)) 5829c0eae66eSBenny Halevy goto out_overflow; 583079969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 583179969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5832fc931582SAndy Adamson 5833fc931582SAndy Adamson /* Channel attributes */ 583479969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5835fc931582SAndy Adamson if (!status) 583679969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5837fc931582SAndy Adamson return status; 5838c0eae66eSBenny Halevy out_overflow: 5839c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5840c0eae66eSBenny Halevy return -EIO; 5841fc931582SAndy Adamson } 58420f3e66c6SAndy Adamson 58430f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 58440f3e66c6SAndy Adamson { 58450f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 58460f3e66c6SAndy Adamson } 584718019753SRicardo Labiaga 584866245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 584966245539STrond Myklebust { 585066245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 585166245539STrond Myklebust } 585266245539STrond Myklebust 585318019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 585418019753SRicardo Labiaga { 585518019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 585618019753SRicardo Labiaga } 585799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 585899fe60d0SBenny Halevy 58599b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 58609b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 58619b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 58629b7b9fccSAndy Adamson { 58639b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5864e3725ec0STrond Myklebust struct nfs4_session *session; 5865fc01cea9SAndy Adamson struct nfs4_sessionid id; 5866fc01cea9SAndy Adamson u32 dummy; 5867fc01cea9SAndy Adamson int status; 5868fc01cea9SAndy Adamson __be32 *p; 5869fc01cea9SAndy Adamson 5870e3725ec0STrond Myklebust if (res->sr_slot == NULL) 58719b7b9fccSAndy Adamson return 0; 58723bd2384aSChuck Lever if (!res->sr_slot->table->session) 58733bd2384aSChuck Lever return 0; 58749b7b9fccSAndy Adamson 5875fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5876e78291e4SBenny Halevy if (!status) 5877e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5878e78291e4SBenny Halevy if (unlikely(status)) 5879fc01cea9SAndy Adamson goto out_err; 58809b7b9fccSAndy Adamson 5881fc01cea9SAndy Adamson /* 5882fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5883fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5884fc01cea9SAndy Adamson */ 5885fdcb4577STrond Myklebust status = -EREMOTEIO; 5886e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5887fc01cea9SAndy Adamson 5888e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5889fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5890fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5891fc01cea9SAndy Adamson goto out_err; 5892fc01cea9SAndy Adamson } 5893e78291e4SBenny Halevy 5894c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5895c0eae66eSBenny Halevy if (unlikely(!p)) 5896c0eae66eSBenny Halevy goto out_overflow; 5897e78291e4SBenny Halevy 5898fc01cea9SAndy Adamson /* seqid */ 58996f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5900dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5901fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5902fc01cea9SAndy Adamson goto out_err; 5903fc01cea9SAndy Adamson } 5904fc01cea9SAndy Adamson /* slot id */ 59056f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5906df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5907fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5908fc01cea9SAndy Adamson goto out_err; 5909fc01cea9SAndy Adamson } 5910da0507b7STrond Myklebust /* highest slot id */ 5911da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5912464ee9f9STrond Myklebust /* target highest slot id */ 5913464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 59140629e370SAlexandros Batsakis /* result flags */ 59150629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5916fc01cea9SAndy Adamson status = 0; 5917fc01cea9SAndy Adamson out_err: 5918fc01cea9SAndy Adamson res->sr_status = status; 5919fc01cea9SAndy Adamson return status; 5920c0eae66eSBenny Halevy out_overflow: 5921c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5922c0eae66eSBenny Halevy status = -EIO; 5923c0eae66eSBenny Halevy goto out_err; 5924fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 59259b7b9fccSAndy Adamson return 0; 5926fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 59279b7b9fccSAndy Adamson } 59289b7b9fccSAndy Adamson 5929b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 593093b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 593193b717fdSTrond Myklebust { 593293b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 593393b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 593493b717fdSTrond Myklebust } 593593b717fdSTrond Myklebust 5936b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 59374e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5938b1f69b75SAndy Adamson { 59394e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5940b1f69b75SAndy Adamson __be32 *p; 5941b1f69b75SAndy Adamson uint32_t len, type; 5942b1f69b75SAndy Adamson int status; 5943b1f69b75SAndy Adamson 5944b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5945b1f69b75SAndy Adamson if (status) { 5946b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5947b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5948b1f69b75SAndy Adamson if (unlikely(!p)) 5949b1f69b75SAndy Adamson goto out_overflow; 5950b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5951b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5952b1f69b75SAndy Adamson __func__, pdev->mincount); 5953b1f69b75SAndy Adamson } 5954b1f69b75SAndy Adamson return status; 5955b1f69b75SAndy Adamson } 5956b1f69b75SAndy Adamson 5957b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5958b1f69b75SAndy Adamson if (unlikely(!p)) 5959b1f69b75SAndy Adamson goto out_overflow; 5960b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5961b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5962b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5963b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5964b1f69b75SAndy Adamson return -EINVAL; 5965b1f69b75SAndy Adamson } 5966b1f69b75SAndy Adamson /* 5967b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5968b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5969b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5970b1f69b75SAndy Adamson */ 5971b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 597213fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 597313fe4ba1STrond Myklebust goto out_overflow; 5974b1f69b75SAndy Adamson 5975b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5976b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5977b1f69b75SAndy Adamson if (unlikely(!p)) 5978b1f69b75SAndy Adamson goto out_overflow; 5979b1f69b75SAndy Adamson len = be32_to_cpup(p); 5980b1f69b75SAndy Adamson if (len) { 5981ead00597SChuck Lever uint32_t i; 5982b1f69b75SAndy Adamson 5983b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5984b1f69b75SAndy Adamson if (unlikely(!p)) 5985b1f69b75SAndy Adamson goto out_overflow; 598684c9dee3SChristoph Hellwig 59874e590803STrond Myklebust res->notification = be32_to_cpup(p++); 598884c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 598984c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 599084c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 5991b1f69b75SAndy Adamson __func__); 5992b1f69b75SAndy Adamson return -EIO; 5993b1f69b75SAndy Adamson } 5994b1f69b75SAndy Adamson } 5995b1f69b75SAndy Adamson } 5996b1f69b75SAndy Adamson return 0; 5997b1f69b75SAndy Adamson out_overflow: 5998b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5999b1f69b75SAndy Adamson return -EIO; 6000b1f69b75SAndy Adamson } 6001b1f69b75SAndy Adamson 6002b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 6003b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6004b1f69b75SAndy Adamson { 6005b1f69b75SAndy Adamson __be32 *p; 6006b1f69b75SAndy Adamson int status; 6007b1f69b75SAndy Adamson u32 layout_count; 600864bd577eSTrond Myklebust u32 recvd; 6009b1f69b75SAndy Adamson 6010b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 6011b1f69b75SAndy Adamson if (status) 6012b1f69b75SAndy Adamson return status; 6013ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6014b1f69b75SAndy Adamson if (unlikely(!p)) 6015b1f69b75SAndy Adamson goto out_overflow; 6016ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 601793b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 6018ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6019ea9d23f5STrond Myklebust if (unlikely(!p)) 6020ea9d23f5STrond Myklebust goto out_overflow; 6021b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 6022b1f69b75SAndy Adamson if (!layout_count) { 6023b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 6024b1f69b75SAndy Adamson __func__); 6025b1f69b75SAndy Adamson return -EINVAL; 6026b1f69b75SAndy Adamson } 6027b1f69b75SAndy Adamson 602835124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 6029b1f69b75SAndy Adamson if (unlikely(!p)) 6030b1f69b75SAndy Adamson goto out_overflow; 6031b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 6032b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 6033b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 6034b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 603535124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 6036b1f69b75SAndy Adamson 6037b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 6038b1f69b75SAndy Adamson __func__, 6039b1f69b75SAndy Adamson (unsigned long)res->range.offset, 6040b1f69b75SAndy Adamson (unsigned long)res->range.length, 6041b1f69b75SAndy Adamson res->range.iomode, 6042b1f69b75SAndy Adamson res->type, 604335124a09SWeston Andros Adamson res->layoutp->len); 6044b1f69b75SAndy Adamson 604564bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 604635124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 604735124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 604835124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 604935124a09SWeston Andros Adamson res->layoutp->len, recvd); 605035124a09SWeston Andros Adamson return -EINVAL; 605135124a09SWeston Andros Adamson } 605235124a09SWeston Andros Adamson 6053b1f69b75SAndy Adamson if (layout_count > 1) { 6054b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 6055b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 6056b1f69b75SAndy Adamson * the client may see a response that is less than the 6057b1f69b75SAndy Adamson * minimum it requested. 6058b1f69b75SAndy Adamson */ 6059b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 6060b1f69b75SAndy Adamson __func__, layout_count); 6061b1f69b75SAndy Adamson } 6062b1f69b75SAndy Adamson 6063b1f69b75SAndy Adamson return 0; 6064b1f69b75SAndy Adamson out_overflow: 6065b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6066b1f69b75SAndy Adamson return -EIO; 6067b1f69b75SAndy Adamson } 6068863a3c6cSAndy Adamson 6069cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 6070cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6071cbe82603SBenny Halevy { 6072cbe82603SBenny Halevy __be32 *p; 6073cbe82603SBenny Halevy int status; 6074cbe82603SBenny Halevy 6075cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 6076cbe82603SBenny Halevy if (status) 6077cbe82603SBenny Halevy return status; 6078cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 6079cbe82603SBenny Halevy if (unlikely(!p)) 6080cbe82603SBenny Halevy goto out_overflow; 6081cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 6082cbe82603SBenny Halevy if (res->lrs_present) 608393b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 6084fcd8843cSTrond Myklebust else 6085fcd8843cSTrond Myklebust nfs4_stateid_copy(&res->stateid, &invalid_stateid); 6086cbe82603SBenny Halevy return status; 6087cbe82603SBenny Halevy out_overflow: 6088cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 6089cbe82603SBenny Halevy return -EIO; 6090cbe82603SBenny Halevy } 6091cbe82603SBenny Halevy 6092863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 6093863a3c6cSAndy Adamson struct rpc_rqst *req, 6094863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6095863a3c6cSAndy Adamson { 6096863a3c6cSAndy Adamson __be32 *p; 6097863a3c6cSAndy Adamson __u32 sizechanged; 6098863a3c6cSAndy Adamson int status; 6099863a3c6cSAndy Adamson 6100863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 6101db29c089SAndy Adamson res->status = status; 6102863a3c6cSAndy Adamson if (status) 6103863a3c6cSAndy Adamson return status; 6104863a3c6cSAndy Adamson 6105863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 6106863a3c6cSAndy Adamson if (unlikely(!p)) 6107863a3c6cSAndy Adamson goto out_overflow; 6108863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 6109863a3c6cSAndy Adamson 6110863a3c6cSAndy Adamson if (sizechanged) { 6111863a3c6cSAndy Adamson /* throw away new size */ 6112863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 6113863a3c6cSAndy Adamson if (unlikely(!p)) 6114863a3c6cSAndy Adamson goto out_overflow; 6115863a3c6cSAndy Adamson } 6116863a3c6cSAndy Adamson return 0; 6117863a3c6cSAndy Adamson out_overflow: 6118863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 6119863a3c6cSAndy Adamson return -EIO; 6120863a3c6cSAndy Adamson } 61217d974794SBryan Schumaker 61227d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 61237d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 61247d974794SBryan Schumaker { 61257d974794SBryan Schumaker __be32 *p; 61267d974794SBryan Schumaker int status; 61277d974794SBryan Schumaker int num_res; 61287d974794SBryan Schumaker 61297d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 61307d974794SBryan Schumaker if (status) 61317d974794SBryan Schumaker return status; 61327d974794SBryan Schumaker 61337d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61347d974794SBryan Schumaker if (unlikely(!p)) 61357d974794SBryan Schumaker goto out_overflow; 61367d974794SBryan Schumaker num_res = be32_to_cpup(p++); 61377d974794SBryan Schumaker if (num_res != 1) 61387d974794SBryan Schumaker goto out; 61397d974794SBryan Schumaker 61407d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61417d974794SBryan Schumaker if (unlikely(!p)) 61427d974794SBryan Schumaker goto out_overflow; 61437d974794SBryan Schumaker res->status = be32_to_cpup(p++); 61441cab0652SBryan Schumaker 61451cab0652SBryan Schumaker return status; 61467d974794SBryan Schumaker out_overflow: 61477d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 61487d974794SBryan Schumaker out: 61497d974794SBryan Schumaker return -EIO; 61507d974794SBryan Schumaker } 61519aeda35fSBryan Schumaker 61529aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 61539aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 61549aeda35fSBryan Schumaker { 61559f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 61569aeda35fSBryan Schumaker return res->status; 61579aeda35fSBryan Schumaker } 6158cf805165STrond Myklebust #else 6159cf805165STrond Myklebust static inline 6160cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6161cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6162cf805165STrond Myklebust { 6163cf805165STrond Myklebust return 0; 6164cf805165STrond Myklebust } 6165b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6166b1f69b75SAndy Adamson 61671da177e4SLinus Torvalds /* 616849c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 616949c2559eSBenny Halevy */ 617049c2559eSBenny Halevy 617149c2559eSBenny Halevy /* 61721da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 61731da177e4SLinus Torvalds */ 6174bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6175bf269551SChuck Lever struct xdr_stream *xdr, 6176fc016483SChristoph Hellwig void *data) 61771da177e4SLinus Torvalds { 6178fc016483SChristoph Hellwig struct nfs_closeres *res = data; 61791da177e4SLinus Torvalds struct compound_hdr hdr; 61801da177e4SLinus Torvalds int status; 61811da177e4SLinus Torvalds 6182bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61831da177e4SLinus Torvalds if (status) 61841da177e4SLinus Torvalds goto out; 6185bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61869b7b9fccSAndy Adamson if (status) 61879b7b9fccSAndy Adamson goto out; 6188bf269551SChuck Lever status = decode_putfh(xdr); 61891da177e4SLinus Torvalds if (status) 61901da177e4SLinus Torvalds goto out; 6191b6808145STrond Myklebust if (res->lr_res) { 6192b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6193b6808145STrond Myklebust res->lr_ret = status; 6194b6808145STrond Myklebust if (status) 6195b6808145STrond Myklebust goto out; 6196b6808145STrond Myklebust } 6197bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 61981da177e4SLinus Torvalds out: 61991da177e4SLinus Torvalds return status; 62001da177e4SLinus Torvalds } 62011da177e4SLinus Torvalds 62021da177e4SLinus Torvalds /* 62031da177e4SLinus Torvalds * Decode ACCESS response 62041da177e4SLinus Torvalds */ 6205bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6206fc016483SChristoph Hellwig void *data) 62071da177e4SLinus Torvalds { 6208fc016483SChristoph Hellwig struct nfs4_accessres *res = data; 62091da177e4SLinus Torvalds struct compound_hdr hdr; 62101da177e4SLinus Torvalds int status; 62111da177e4SLinus Torvalds 6212bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62139b7b9fccSAndy Adamson if (status) 62149b7b9fccSAndy Adamson goto out; 6215bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62169b7b9fccSAndy Adamson if (status) 62171da177e4SLinus Torvalds goto out; 6218bf269551SChuck Lever status = decode_putfh(xdr); 621976b32999STrond Myklebust if (status != 0) 622076b32999STrond Myklebust goto out; 62216168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 622276b32999STrond Myklebust if (status != 0) 622376b32999STrond Myklebust goto out; 62246926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62251da177e4SLinus Torvalds out: 62261da177e4SLinus Torvalds return status; 62271da177e4SLinus Torvalds } 62281da177e4SLinus Torvalds 62291da177e4SLinus Torvalds /* 62301da177e4SLinus Torvalds * Decode LOOKUP response 62311da177e4SLinus Torvalds */ 6232bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6233fc016483SChristoph Hellwig void *data) 62341da177e4SLinus Torvalds { 6235fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 62361da177e4SLinus Torvalds struct compound_hdr hdr; 62371da177e4SLinus Torvalds int status; 62381da177e4SLinus Torvalds 6239bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62409b7b9fccSAndy Adamson if (status) 62419b7b9fccSAndy Adamson goto out; 6242bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62439b7b9fccSAndy Adamson if (status) 62441da177e4SLinus Torvalds goto out; 6245bf269551SChuck Lever status = decode_putfh(xdr); 6246bf269551SChuck Lever if (status) 62471da177e4SLinus Torvalds goto out; 6248bf269551SChuck Lever status = decode_lookup(xdr); 6249bf269551SChuck Lever if (status) 62501da177e4SLinus Torvalds goto out; 6251bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6252bf269551SChuck Lever if (status) 62531da177e4SLinus Torvalds goto out; 6254aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62551da177e4SLinus Torvalds out: 62561da177e4SLinus Torvalds return status; 62571da177e4SLinus Torvalds } 62581da177e4SLinus Torvalds 62591da177e4SLinus Torvalds /* 62605b5faaf6SJeff Layton * Decode LOOKUPP response 62615b5faaf6SJeff Layton */ 62625b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 62635b5faaf6SJeff Layton void *data) 62645b5faaf6SJeff Layton { 62655b5faaf6SJeff Layton struct nfs4_lookupp_res *res = data; 62665b5faaf6SJeff Layton struct compound_hdr hdr; 62675b5faaf6SJeff Layton int status; 62685b5faaf6SJeff Layton 62695b5faaf6SJeff Layton status = decode_compound_hdr(xdr, &hdr); 62705b5faaf6SJeff Layton if (status) 62715b5faaf6SJeff Layton goto out; 62725b5faaf6SJeff Layton status = decode_sequence(xdr, &res->seq_res, rqstp); 62735b5faaf6SJeff Layton if (status) 62745b5faaf6SJeff Layton goto out; 62755b5faaf6SJeff Layton status = decode_putfh(xdr); 62765b5faaf6SJeff Layton if (status) 62775b5faaf6SJeff Layton goto out; 62785b5faaf6SJeff Layton status = decode_lookupp(xdr); 62795b5faaf6SJeff Layton if (status) 62805b5faaf6SJeff Layton goto out; 62815b5faaf6SJeff Layton status = decode_getfh(xdr, res->fh); 62825b5faaf6SJeff Layton if (status) 62835b5faaf6SJeff Layton goto out; 62845b5faaf6SJeff Layton status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62855b5faaf6SJeff Layton out: 62865b5faaf6SJeff Layton return status; 62875b5faaf6SJeff Layton } 62885b5faaf6SJeff Layton 62895b5faaf6SJeff Layton /* 62901da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 62911da177e4SLinus Torvalds */ 6292bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6293bf269551SChuck Lever struct xdr_stream *xdr, 6294fc016483SChristoph Hellwig void *data) 62951da177e4SLinus Torvalds { 6296fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 62971da177e4SLinus Torvalds struct compound_hdr hdr; 62981da177e4SLinus Torvalds int status; 62991da177e4SLinus Torvalds 6300bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63019b7b9fccSAndy Adamson if (status) 63029b7b9fccSAndy Adamson goto out; 6303bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63049b7b9fccSAndy Adamson if (status) 63051da177e4SLinus Torvalds goto out; 6306bf269551SChuck Lever status = decode_putrootfh(xdr); 6307bf269551SChuck Lever if (status) 63081da177e4SLinus Torvalds goto out; 6309bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6310bf269551SChuck Lever if (status == 0) 6311aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6312aa9c2669SDavid Quigley res->label, res->server); 63131da177e4SLinus Torvalds out: 63141da177e4SLinus Torvalds return status; 63151da177e4SLinus Torvalds } 63161da177e4SLinus Torvalds 63171da177e4SLinus Torvalds /* 63181da177e4SLinus Torvalds * Decode REMOVE response 63191da177e4SLinus Torvalds */ 6320bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6321fc016483SChristoph Hellwig void *data) 63221da177e4SLinus Torvalds { 6323fc016483SChristoph Hellwig struct nfs_removeres *res = data; 63241da177e4SLinus Torvalds struct compound_hdr hdr; 63251da177e4SLinus Torvalds int status; 63261da177e4SLinus Torvalds 6327bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63289b7b9fccSAndy Adamson if (status) 63299b7b9fccSAndy Adamson goto out; 6330bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63319b7b9fccSAndy Adamson if (status) 63321da177e4SLinus Torvalds goto out; 6333bf269551SChuck Lever status = decode_putfh(xdr); 6334bf269551SChuck Lever if (status) 633516e42959STrond Myklebust goto out; 6336bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 63371da177e4SLinus Torvalds out: 63381da177e4SLinus Torvalds return status; 63391da177e4SLinus Torvalds } 63401da177e4SLinus Torvalds 63411da177e4SLinus Torvalds /* 63421da177e4SLinus Torvalds * Decode RENAME response 63431da177e4SLinus Torvalds */ 6344bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6345fc016483SChristoph Hellwig void *data) 63461da177e4SLinus Torvalds { 6347fc016483SChristoph Hellwig struct nfs_renameres *res = data; 63481da177e4SLinus Torvalds struct compound_hdr hdr; 63491da177e4SLinus Torvalds int status; 63501da177e4SLinus Torvalds 6351bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63529b7b9fccSAndy Adamson if (status) 63539b7b9fccSAndy Adamson goto out; 6354bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63559b7b9fccSAndy Adamson if (status) 63561da177e4SLinus Torvalds goto out; 6357bf269551SChuck Lever status = decode_putfh(xdr); 6358bf269551SChuck Lever if (status) 63591da177e4SLinus Torvalds goto out; 6360bf269551SChuck Lever status = decode_savefh(xdr); 6361bf269551SChuck Lever if (status) 63621da177e4SLinus Torvalds goto out; 6363bf269551SChuck Lever status = decode_putfh(xdr); 6364bf269551SChuck Lever if (status) 63651da177e4SLinus Torvalds goto out; 6366bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 63671da177e4SLinus Torvalds out: 63681da177e4SLinus Torvalds return status; 63691da177e4SLinus Torvalds } 63701da177e4SLinus Torvalds 63711da177e4SLinus Torvalds /* 63721da177e4SLinus Torvalds * Decode LINK response 63731da177e4SLinus Torvalds */ 6374bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6375fc016483SChristoph Hellwig void *data) 63761da177e4SLinus Torvalds { 6377fc016483SChristoph Hellwig struct nfs4_link_res *res = data; 63781da177e4SLinus Torvalds struct compound_hdr hdr; 63791da177e4SLinus Torvalds int status; 63801da177e4SLinus Torvalds 6381bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63829b7b9fccSAndy Adamson if (status) 63839b7b9fccSAndy Adamson goto out; 6384bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63859b7b9fccSAndy Adamson if (status) 63861da177e4SLinus Torvalds goto out; 6387bf269551SChuck Lever status = decode_putfh(xdr); 6388bf269551SChuck Lever if (status) 63891da177e4SLinus Torvalds goto out; 6390bf269551SChuck Lever status = decode_savefh(xdr); 6391bf269551SChuck Lever if (status) 63921da177e4SLinus Torvalds goto out; 6393bf269551SChuck Lever status = decode_putfh(xdr); 6394bf269551SChuck Lever if (status) 63951da177e4SLinus Torvalds goto out; 6396bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6397bf269551SChuck Lever if (status) 639891ba2eeeSTrond Myklebust goto out; 639991ba2eeeSTrond Myklebust /* 640091ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 640191ba2eeeSTrond Myklebust * filehandle. 640291ba2eeeSTrond Myklebust */ 6403bf269551SChuck Lever status = decode_restorefh(xdr); 6404bf269551SChuck Lever if (status) 640591ba2eeeSTrond Myklebust goto out; 6406aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64071da177e4SLinus Torvalds out: 64081da177e4SLinus Torvalds return status; 64091da177e4SLinus Torvalds } 64101da177e4SLinus Torvalds 64111da177e4SLinus Torvalds /* 64121da177e4SLinus Torvalds * Decode CREATE response 64131da177e4SLinus Torvalds */ 6414bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6415fc016483SChristoph Hellwig void *data) 64161da177e4SLinus Torvalds { 6417fc016483SChristoph Hellwig struct nfs4_create_res *res = data; 64181da177e4SLinus Torvalds struct compound_hdr hdr; 64191da177e4SLinus Torvalds int status; 64201da177e4SLinus Torvalds 6421bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64229b7b9fccSAndy Adamson if (status) 64239b7b9fccSAndy Adamson goto out; 6424bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64259b7b9fccSAndy Adamson if (status) 64261da177e4SLinus Torvalds goto out; 6427bf269551SChuck Lever status = decode_putfh(xdr); 6428bf269551SChuck Lever if (status) 64291da177e4SLinus Torvalds goto out; 6430bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6431bf269551SChuck Lever if (status) 64321da177e4SLinus Torvalds goto out; 6433bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6434bf269551SChuck Lever if (status) 64351da177e4SLinus Torvalds goto out; 6436aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64371da177e4SLinus Torvalds out: 64381da177e4SLinus Torvalds return status; 64391da177e4SLinus Torvalds } 64401da177e4SLinus Torvalds 64411da177e4SLinus Torvalds /* 64421da177e4SLinus Torvalds * Decode SYMLINK response 64431da177e4SLinus Torvalds */ 6444bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6445fc016483SChristoph Hellwig void *res) 64461da177e4SLinus Torvalds { 6447bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 64481da177e4SLinus Torvalds } 64491da177e4SLinus Torvalds 64501da177e4SLinus Torvalds /* 64511da177e4SLinus Torvalds * Decode GETATTR response 64521da177e4SLinus Torvalds */ 6453bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6454fc016483SChristoph Hellwig void *data) 64551da177e4SLinus Torvalds { 6456fc016483SChristoph Hellwig struct nfs4_getattr_res *res = data; 64571da177e4SLinus Torvalds struct compound_hdr hdr; 64581da177e4SLinus Torvalds int status; 64591da177e4SLinus Torvalds 6460bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64611da177e4SLinus Torvalds if (status) 64621da177e4SLinus Torvalds goto out; 6463bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64649b7b9fccSAndy Adamson if (status) 64659b7b9fccSAndy Adamson goto out; 6466bf269551SChuck Lever status = decode_putfh(xdr); 64671da177e4SLinus Torvalds if (status) 64681da177e4SLinus Torvalds goto out; 6469aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64701da177e4SLinus Torvalds out: 64711da177e4SLinus Torvalds return status; 64721da177e4SLinus Torvalds } 64731da177e4SLinus Torvalds 647423ec6965SJ. Bruce Fields /* 647523ec6965SJ. Bruce Fields * Encode an SETACL request 647623ec6965SJ. Bruce Fields */ 64779f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 6478fcc85819SChristoph Hellwig const void *data) 647923ec6965SJ. Bruce Fields { 6480fcc85819SChristoph Hellwig const struct nfs_setaclargs *args = data; 648123ec6965SJ. Bruce Fields struct compound_hdr hdr = { 648266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 648323ec6965SJ. Bruce Fields }; 648423ec6965SJ. Bruce Fields 64859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 64869f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 64879f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 64889f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6489d017931cSAndy Adamson encode_nops(&hdr); 649023ec6965SJ. Bruce Fields } 649105d564feSAndy Adamson 649223ec6965SJ. Bruce Fields /* 649323ec6965SJ. Bruce Fields * Decode SETACL response 649423ec6965SJ. Bruce Fields */ 649523ec6965SJ. Bruce Fields static int 6496bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6497fc016483SChristoph Hellwig void *data) 649823ec6965SJ. Bruce Fields { 6499fc016483SChristoph Hellwig struct nfs_setaclres *res = data; 650023ec6965SJ. Bruce Fields struct compound_hdr hdr; 650123ec6965SJ. Bruce Fields int status; 650223ec6965SJ. Bruce Fields 6503bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 650423ec6965SJ. Bruce Fields if (status) 650523ec6965SJ. Bruce Fields 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); 651023ec6965SJ. Bruce Fields if (status) 651123ec6965SJ. Bruce Fields goto out; 6512bf269551SChuck Lever status = decode_setattr(xdr); 651323ec6965SJ. Bruce Fields out: 651423ec6965SJ. Bruce Fields return status; 651523ec6965SJ. Bruce Fields } 65161da177e4SLinus Torvalds 65171da177e4SLinus Torvalds /* 6518029d105eSJ. Bruce Fields * Decode GETACL response 6519029d105eSJ. Bruce Fields */ 6520029d105eSJ. Bruce Fields static int 6521bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6522fc016483SChristoph Hellwig void *data) 6523029d105eSJ. Bruce Fields { 6524fc016483SChristoph Hellwig struct nfs_getaclres *res = data; 6525029d105eSJ. Bruce Fields struct compound_hdr hdr; 6526029d105eSJ. Bruce Fields int status; 6527029d105eSJ. Bruce Fields 6528331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6529331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6530331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6531331818f1STrond Myklebust } 6532bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6533029d105eSJ. Bruce Fields if (status) 6534029d105eSJ. Bruce Fields goto out; 6535bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65369b7b9fccSAndy Adamson if (status) 65379b7b9fccSAndy Adamson goto out; 6538bf269551SChuck Lever status = decode_putfh(xdr); 6539029d105eSJ. Bruce Fields if (status) 6540029d105eSJ. Bruce Fields goto out; 6541bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6542029d105eSJ. Bruce Fields 6543029d105eSJ. Bruce Fields out: 6544029d105eSJ. Bruce Fields return status; 6545029d105eSJ. Bruce Fields } 6546029d105eSJ. Bruce Fields 6547029d105eSJ. Bruce Fields /* 65481da177e4SLinus Torvalds * Decode CLOSE response 65491da177e4SLinus Torvalds */ 6550bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6551fc016483SChristoph Hellwig void *data) 65521da177e4SLinus Torvalds { 6553fc016483SChristoph Hellwig struct nfs_closeres *res = data; 65541da177e4SLinus Torvalds struct compound_hdr hdr; 65551da177e4SLinus Torvalds int status; 65561da177e4SLinus Torvalds 6557bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65581da177e4SLinus Torvalds if (status) 65591da177e4SLinus Torvalds goto out; 6560bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65619b7b9fccSAndy Adamson if (status) 65629b7b9fccSAndy Adamson goto out; 6563bf269551SChuck Lever status = decode_putfh(xdr); 65641da177e4SLinus Torvalds if (status) 65651da177e4SLinus Torvalds goto out; 6566cf805165STrond Myklebust if (res->lr_res) { 6567cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6568cf805165STrond Myklebust res->lr_ret = status; 6569cf805165STrond Myklebust if (status) 6570cf805165STrond Myklebust goto out; 6571cf805165STrond Myklebust } 6572d8d84983STrond Myklebust if (res->fattr != NULL) { 6573d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6574516a6af6STrond Myklebust if (status != 0) 6575516a6af6STrond Myklebust goto out; 6576d8d84983STrond Myklebust } 6577d8d84983STrond Myklebust status = decode_close(xdr, res); 65781da177e4SLinus Torvalds out: 65791da177e4SLinus Torvalds return status; 65801da177e4SLinus Torvalds } 65811da177e4SLinus Torvalds 65821da177e4SLinus Torvalds /* 65831da177e4SLinus Torvalds * Decode OPEN response 65841da177e4SLinus Torvalds */ 6585bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6586fc016483SChristoph Hellwig void *data) 65871da177e4SLinus Torvalds { 6588fc016483SChristoph Hellwig struct nfs_openres *res = data; 65891da177e4SLinus Torvalds struct compound_hdr hdr; 65901da177e4SLinus Torvalds int status; 65911da177e4SLinus Torvalds 6592bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65931da177e4SLinus Torvalds if (status) 65941da177e4SLinus Torvalds goto out; 6595bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65969b7b9fccSAndy Adamson if (status) 65979b7b9fccSAndy Adamson goto out; 6598bf269551SChuck Lever status = decode_putfh(xdr); 65991da177e4SLinus Torvalds if (status) 66001da177e4SLinus Torvalds goto out; 6601bf269551SChuck Lever status = decode_open(xdr, res); 66021da177e4SLinus Torvalds if (status) 66031da177e4SLinus Torvalds goto out; 660401913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 660501913b49SWeston Andros Adamson if (status) 66061da177e4SLinus Torvalds goto out; 6607ae2bb032SWeston Andros Adamson if (res->access_request) 66086168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6609aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 66101da177e4SLinus Torvalds out: 66111da177e4SLinus Torvalds return status; 66121da177e4SLinus Torvalds } 66131da177e4SLinus Torvalds 66141da177e4SLinus Torvalds /* 66151da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 66161da177e4SLinus Torvalds */ 6617bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6618bf269551SChuck Lever struct xdr_stream *xdr, 6619fc016483SChristoph Hellwig void *data) 66201da177e4SLinus Torvalds { 6621fc016483SChristoph Hellwig struct nfs_open_confirmres *res = data; 66221da177e4SLinus Torvalds struct compound_hdr hdr; 66231da177e4SLinus Torvalds int status; 66241da177e4SLinus Torvalds 6625bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66261da177e4SLinus Torvalds if (status) 66271da177e4SLinus Torvalds goto out; 6628bf269551SChuck Lever status = decode_putfh(xdr); 66291da177e4SLinus Torvalds if (status) 66301da177e4SLinus Torvalds goto out; 6631bf269551SChuck Lever status = decode_open_confirm(xdr, res); 66321da177e4SLinus Torvalds out: 66331da177e4SLinus Torvalds return status; 66341da177e4SLinus Torvalds } 66351da177e4SLinus Torvalds 66361da177e4SLinus Torvalds /* 66371da177e4SLinus Torvalds * Decode OPEN response 66381da177e4SLinus Torvalds */ 6639bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6640bf269551SChuck Lever struct xdr_stream *xdr, 6641fc016483SChristoph Hellwig void *data) 66421da177e4SLinus Torvalds { 6643fc016483SChristoph Hellwig struct nfs_openres *res = data; 66441da177e4SLinus Torvalds struct compound_hdr hdr; 66451da177e4SLinus Torvalds int status; 66461da177e4SLinus Torvalds 6647bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66481da177e4SLinus Torvalds if (status) 66491da177e4SLinus Torvalds goto out; 6650bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66519b7b9fccSAndy Adamson if (status) 66529b7b9fccSAndy Adamson goto out; 6653bf269551SChuck Lever status = decode_putfh(xdr); 66541da177e4SLinus Torvalds if (status) 66551da177e4SLinus Torvalds goto out; 6656bf269551SChuck Lever status = decode_open(xdr, res); 6657864472e9STrond Myklebust if (status) 6658864472e9STrond Myklebust goto out; 6659ae2bb032SWeston Andros Adamson if (res->access_request) 66606168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 66616926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 66621da177e4SLinus Torvalds out: 66631da177e4SLinus Torvalds return status; 66641da177e4SLinus Torvalds } 66651da177e4SLinus Torvalds 66661da177e4SLinus Torvalds /* 66671da177e4SLinus Torvalds * Decode SETATTR response 66681da177e4SLinus Torvalds */ 6669bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6670bf269551SChuck Lever struct xdr_stream *xdr, 6671fc016483SChristoph Hellwig void *data) 66721da177e4SLinus Torvalds { 6673fc016483SChristoph Hellwig struct nfs_setattrres *res = data; 66741da177e4SLinus Torvalds struct compound_hdr hdr; 66751da177e4SLinus Torvalds int status; 66761da177e4SLinus Torvalds 6677bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66781da177e4SLinus Torvalds if (status) 66791da177e4SLinus Torvalds goto out; 6680bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66819b7b9fccSAndy Adamson if (status) 66829b7b9fccSAndy Adamson goto out; 6683bf269551SChuck Lever status = decode_putfh(xdr); 66841da177e4SLinus Torvalds if (status) 66851da177e4SLinus Torvalds goto out; 6686bf269551SChuck Lever status = decode_setattr(xdr); 66871da177e4SLinus Torvalds if (status) 66881da177e4SLinus Torvalds goto out; 6689aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 66901da177e4SLinus Torvalds out: 66911da177e4SLinus Torvalds return status; 66921da177e4SLinus Torvalds } 66931da177e4SLinus Torvalds 66941da177e4SLinus Torvalds /* 66951da177e4SLinus Torvalds * Decode LOCK response 66961da177e4SLinus Torvalds */ 6697bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6698fc016483SChristoph Hellwig void *data) 66991da177e4SLinus Torvalds { 6700fc016483SChristoph Hellwig struct nfs_lock_res *res = data; 67011da177e4SLinus Torvalds struct compound_hdr hdr; 67021da177e4SLinus Torvalds int status; 67031da177e4SLinus Torvalds 6704bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67051da177e4SLinus Torvalds if (status) 67061da177e4SLinus Torvalds goto out; 6707bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67089b7b9fccSAndy Adamson if (status) 67099b7b9fccSAndy Adamson goto out; 6710bf269551SChuck Lever status = decode_putfh(xdr); 67111da177e4SLinus Torvalds if (status) 67121da177e4SLinus Torvalds goto out; 6713bf269551SChuck Lever status = decode_lock(xdr, res); 67141da177e4SLinus Torvalds out: 67151da177e4SLinus Torvalds return status; 67161da177e4SLinus Torvalds } 67171da177e4SLinus Torvalds 67181da177e4SLinus Torvalds /* 67191da177e4SLinus Torvalds * Decode LOCKT response 67201da177e4SLinus Torvalds */ 6721bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6722fc016483SChristoph Hellwig void *data) 67231da177e4SLinus Torvalds { 6724fc016483SChristoph Hellwig struct nfs_lockt_res *res = data; 67251da177e4SLinus Torvalds struct compound_hdr hdr; 67261da177e4SLinus Torvalds int status; 67271da177e4SLinus Torvalds 6728bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67291da177e4SLinus Torvalds if (status) 67301da177e4SLinus Torvalds goto out; 6731bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67329b7b9fccSAndy Adamson if (status) 67339b7b9fccSAndy Adamson goto out; 6734bf269551SChuck Lever status = decode_putfh(xdr); 67351da177e4SLinus Torvalds if (status) 67361da177e4SLinus Torvalds goto out; 6737bf269551SChuck Lever status = decode_lockt(xdr, res); 67381da177e4SLinus Torvalds out: 67391da177e4SLinus Torvalds return status; 67401da177e4SLinus Torvalds } 67411da177e4SLinus Torvalds 67421da177e4SLinus Torvalds /* 67431da177e4SLinus Torvalds * Decode LOCKU response 67441da177e4SLinus Torvalds */ 6745bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6746fc016483SChristoph Hellwig void *data) 67471da177e4SLinus Torvalds { 6748fc016483SChristoph Hellwig struct nfs_locku_res *res = data; 67491da177e4SLinus Torvalds struct compound_hdr hdr; 67501da177e4SLinus Torvalds int status; 67511da177e4SLinus Torvalds 6752bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67531da177e4SLinus Torvalds if (status) 67541da177e4SLinus Torvalds goto out; 6755bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67569b7b9fccSAndy Adamson if (status) 67579b7b9fccSAndy Adamson goto out; 6758bf269551SChuck Lever status = decode_putfh(xdr); 67591da177e4SLinus Torvalds if (status) 67601da177e4SLinus Torvalds goto out; 6761bf269551SChuck Lever status = decode_locku(xdr, res); 67621da177e4SLinus Torvalds out: 67631da177e4SLinus Torvalds return status; 67641da177e4SLinus Torvalds } 67651da177e4SLinus Torvalds 6766bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6767bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6768d3c7b7ccSTrond Myklebust { 6769d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6770d3c7b7ccSTrond Myklebust int status; 6771d3c7b7ccSTrond Myklebust 6772bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6773d3c7b7ccSTrond Myklebust if (!status) 6774bf269551SChuck Lever status = decode_release_lockowner(xdr); 6775d3c7b7ccSTrond Myklebust return status; 6776d3c7b7ccSTrond Myklebust } 6777d3c7b7ccSTrond Myklebust 67781da177e4SLinus Torvalds /* 67791da177e4SLinus Torvalds * Decode READLINK response 67801da177e4SLinus Torvalds */ 6781bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6782bf269551SChuck Lever struct xdr_stream *xdr, 6783fc016483SChristoph Hellwig void *data) 67841da177e4SLinus Torvalds { 6785fc016483SChristoph Hellwig struct nfs4_readlink_res *res = data; 67861da177e4SLinus Torvalds struct compound_hdr hdr; 67871da177e4SLinus Torvalds int status; 67881da177e4SLinus Torvalds 6789bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67901da177e4SLinus Torvalds if (status) 67911da177e4SLinus Torvalds goto out; 6792bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67939b7b9fccSAndy Adamson if (status) 67949b7b9fccSAndy Adamson goto out; 6795bf269551SChuck Lever status = decode_putfh(xdr); 67961da177e4SLinus Torvalds if (status) 67971da177e4SLinus Torvalds goto out; 6798bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 67991da177e4SLinus Torvalds out: 68001da177e4SLinus Torvalds return status; 68011da177e4SLinus Torvalds } 68021da177e4SLinus Torvalds 68031da177e4SLinus Torvalds /* 68041da177e4SLinus Torvalds * Decode READDIR response 68051da177e4SLinus Torvalds */ 6806bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6807fc016483SChristoph Hellwig void *data) 68081da177e4SLinus Torvalds { 6809fc016483SChristoph Hellwig struct nfs4_readdir_res *res = data; 68101da177e4SLinus Torvalds struct compound_hdr hdr; 68111da177e4SLinus Torvalds int status; 68121da177e4SLinus Torvalds 6813bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68141da177e4SLinus Torvalds if (status) 68151da177e4SLinus Torvalds goto out; 6816bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68179b7b9fccSAndy Adamson if (status) 68189b7b9fccSAndy Adamson goto out; 6819bf269551SChuck Lever status = decode_putfh(xdr); 68201da177e4SLinus Torvalds if (status) 68211da177e4SLinus Torvalds goto out; 6822bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 68231da177e4SLinus Torvalds out: 68241da177e4SLinus Torvalds return status; 68251da177e4SLinus Torvalds } 68261da177e4SLinus Torvalds 68271da177e4SLinus Torvalds /* 68281da177e4SLinus Torvalds * Decode Read response 68291da177e4SLinus Torvalds */ 6830bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6831fc016483SChristoph Hellwig void *data) 68321da177e4SLinus Torvalds { 6833fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 68341da177e4SLinus Torvalds struct compound_hdr hdr; 68351da177e4SLinus Torvalds int status; 68361da177e4SLinus Torvalds 6837bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6838aabff4ddSPeng Tao res->op_status = hdr.status; 68391da177e4SLinus Torvalds if (status) 68401da177e4SLinus Torvalds goto out; 6841bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68429b7b9fccSAndy Adamson if (status) 68439b7b9fccSAndy Adamson goto out; 6844bf269551SChuck Lever status = decode_putfh(xdr); 68451da177e4SLinus Torvalds if (status) 68461da177e4SLinus Torvalds goto out; 6847bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 68481da177e4SLinus Torvalds if (!status) 68491da177e4SLinus Torvalds status = res->count; 68501da177e4SLinus Torvalds out: 68511da177e4SLinus Torvalds return status; 68521da177e4SLinus Torvalds } 68531da177e4SLinus Torvalds 68541da177e4SLinus Torvalds /* 68551da177e4SLinus Torvalds * Decode WRITE response 68561da177e4SLinus Torvalds */ 6857bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6858fc016483SChristoph Hellwig void *data) 68591da177e4SLinus Torvalds { 6860fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 68611da177e4SLinus Torvalds struct compound_hdr hdr; 68621da177e4SLinus Torvalds int status; 68631da177e4SLinus Torvalds 6864bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6865aabff4ddSPeng Tao res->op_status = hdr.status; 68661da177e4SLinus Torvalds if (status) 68671da177e4SLinus Torvalds goto out; 6868bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68699b7b9fccSAndy Adamson if (status) 68709b7b9fccSAndy Adamson goto out; 6871bf269551SChuck Lever status = decode_putfh(xdr); 68721da177e4SLinus Torvalds if (status) 68731da177e4SLinus Torvalds goto out; 6874bf269551SChuck Lever status = decode_write(xdr, res); 68754f9838c7STrond Myklebust if (status) 68764f9838c7STrond Myklebust goto out; 68777ffd1064SFred Isaman if (res->fattr) 68786926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 68791da177e4SLinus Torvalds if (!status) 68801da177e4SLinus Torvalds status = res->count; 68811da177e4SLinus Torvalds out: 68821da177e4SLinus Torvalds return status; 68831da177e4SLinus Torvalds } 68841da177e4SLinus Torvalds 68851da177e4SLinus Torvalds /* 68861da177e4SLinus Torvalds * Decode COMMIT response 68871da177e4SLinus Torvalds */ 6888bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6889fc016483SChristoph Hellwig void *data) 68901da177e4SLinus Torvalds { 6891fc016483SChristoph Hellwig struct nfs_commitres *res = data; 68921da177e4SLinus Torvalds struct compound_hdr hdr; 68931da177e4SLinus Torvalds int status; 68941da177e4SLinus Torvalds 6895bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6896aabff4ddSPeng Tao res->op_status = hdr.status; 68971da177e4SLinus Torvalds if (status) 68981da177e4SLinus Torvalds goto out; 6899bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69009b7b9fccSAndy Adamson if (status) 69019b7b9fccSAndy Adamson goto out; 6902bf269551SChuck Lever status = decode_putfh(xdr); 69031da177e4SLinus Torvalds if (status) 69041da177e4SLinus Torvalds goto out; 6905bf269551SChuck Lever status = decode_commit(xdr, res); 69061da177e4SLinus Torvalds out: 69071da177e4SLinus Torvalds return status; 69081da177e4SLinus Torvalds } 69091da177e4SLinus Torvalds 69101da177e4SLinus Torvalds /* 69118b173218SRicardo Labiaga * Decode FSINFO response 69121da177e4SLinus Torvalds */ 6913bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 6914fc016483SChristoph Hellwig void *data) 69151da177e4SLinus Torvalds { 6916fc016483SChristoph Hellwig struct nfs4_fsinfo_res *res = data; 69171da177e4SLinus Torvalds struct compound_hdr hdr; 69181da177e4SLinus Torvalds int status; 69191da177e4SLinus Torvalds 6920bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69211da177e4SLinus Torvalds if (!status) 6922bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69239b7b9fccSAndy Adamson if (!status) 6924bf269551SChuck Lever status = decode_putfh(xdr); 69251da177e4SLinus Torvalds if (!status) 6926bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 69271da177e4SLinus Torvalds return status; 69281da177e4SLinus Torvalds } 69291da177e4SLinus Torvalds 69301da177e4SLinus Torvalds /* 69318b173218SRicardo Labiaga * Decode PATHCONF response 69321da177e4SLinus Torvalds */ 6933bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6934fc016483SChristoph Hellwig void *data) 69351da177e4SLinus Torvalds { 6936fc016483SChristoph Hellwig struct nfs4_pathconf_res *res = data; 69371da177e4SLinus Torvalds struct compound_hdr hdr; 69381da177e4SLinus Torvalds int status; 69391da177e4SLinus Torvalds 6940bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69411da177e4SLinus Torvalds if (!status) 6942bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69439b7b9fccSAndy Adamson if (!status) 6944bf269551SChuck Lever status = decode_putfh(xdr); 69451da177e4SLinus Torvalds if (!status) 6946bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 69471da177e4SLinus Torvalds return status; 69481da177e4SLinus Torvalds } 69491da177e4SLinus Torvalds 69501da177e4SLinus Torvalds /* 69518b173218SRicardo Labiaga * Decode STATFS response 69521da177e4SLinus Torvalds */ 6953bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 6954fc016483SChristoph Hellwig void *data) 69551da177e4SLinus Torvalds { 6956fc016483SChristoph Hellwig struct nfs4_statfs_res *res = data; 69571da177e4SLinus Torvalds struct compound_hdr hdr; 69581da177e4SLinus Torvalds int status; 69591da177e4SLinus Torvalds 6960bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69611da177e4SLinus Torvalds if (!status) 6962bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69639b7b9fccSAndy Adamson if (!status) 6964bf269551SChuck Lever status = decode_putfh(xdr); 69651da177e4SLinus Torvalds if (!status) 6966bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 69671da177e4SLinus Torvalds return status; 69681da177e4SLinus Torvalds } 69691da177e4SLinus Torvalds 69701da177e4SLinus Torvalds /* 69718b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 69721da177e4SLinus Torvalds */ 6973bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6974bf269551SChuck Lever struct xdr_stream *xdr, 6975fc016483SChristoph Hellwig void *data) 69761da177e4SLinus Torvalds { 6977fc016483SChristoph Hellwig struct nfs4_server_caps_res *res = data; 69781da177e4SLinus Torvalds struct compound_hdr hdr; 69791da177e4SLinus Torvalds int status; 69801da177e4SLinus Torvalds 6981bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69829b7b9fccSAndy Adamson if (status) 69839b7b9fccSAndy Adamson goto out; 6984bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69859b7b9fccSAndy Adamson if (status) 69861da177e4SLinus Torvalds goto out; 6987bf269551SChuck Lever status = decode_putfh(xdr); 6988bf269551SChuck Lever if (status) 69891da177e4SLinus Torvalds goto out; 6990bf269551SChuck Lever status = decode_server_caps(xdr, res); 69911da177e4SLinus Torvalds out: 69921da177e4SLinus Torvalds return status; 69931da177e4SLinus Torvalds } 69941da177e4SLinus Torvalds 69951da177e4SLinus Torvalds /* 69961da177e4SLinus Torvalds * Decode RENEW response 69971da177e4SLinus Torvalds */ 6998bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6999bf269551SChuck Lever void *__unused) 70001da177e4SLinus Torvalds { 70011da177e4SLinus Torvalds struct compound_hdr hdr; 70021da177e4SLinus Torvalds int status; 70031da177e4SLinus Torvalds 7004bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70051da177e4SLinus Torvalds if (!status) 7006bf269551SChuck Lever status = decode_renew(xdr); 70071da177e4SLinus Torvalds return status; 70081da177e4SLinus Torvalds } 70091da177e4SLinus Torvalds 70101da177e4SLinus Torvalds /* 70118b173218SRicardo Labiaga * Decode SETCLIENTID response 70121da177e4SLinus Torvalds */ 7013bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 7014bf269551SChuck Lever struct xdr_stream *xdr, 7015fc016483SChristoph Hellwig void *data) 70161da177e4SLinus Torvalds { 7017fc016483SChristoph Hellwig struct nfs4_setclientid_res *res = data; 70181da177e4SLinus Torvalds struct compound_hdr hdr; 70191da177e4SLinus Torvalds int status; 70201da177e4SLinus Torvalds 7021bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70221da177e4SLinus Torvalds if (!status) 7023bf269551SChuck Lever status = decode_setclientid(xdr, res); 70241da177e4SLinus Torvalds return status; 70251da177e4SLinus Torvalds } 70261da177e4SLinus Torvalds 70271da177e4SLinus Torvalds /* 70288b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 70291da177e4SLinus Torvalds */ 7030bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 7031fc016483SChristoph Hellwig struct xdr_stream *xdr, 7032fc016483SChristoph Hellwig void *data) 70331da177e4SLinus Torvalds { 70341da177e4SLinus Torvalds struct compound_hdr hdr; 70351da177e4SLinus Torvalds int status; 70361da177e4SLinus Torvalds 7037bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70381da177e4SLinus Torvalds if (!status) 7039bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 70401da177e4SLinus Torvalds return status; 70411da177e4SLinus Torvalds } 70421da177e4SLinus Torvalds 70431da177e4SLinus Torvalds /* 70448b173218SRicardo Labiaga * Decode DELEGRETURN response 70451da177e4SLinus Torvalds */ 7046bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 7047bf269551SChuck Lever struct xdr_stream *xdr, 7048fc016483SChristoph Hellwig void *data) 70491da177e4SLinus Torvalds { 7050fc016483SChristoph Hellwig struct nfs4_delegreturnres *res = data; 70511da177e4SLinus Torvalds struct compound_hdr hdr; 70521da177e4SLinus Torvalds int status; 70531da177e4SLinus Torvalds 7054bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70559b7b9fccSAndy Adamson if (status) 70569b7b9fccSAndy Adamson goto out; 7057bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 70589b7b9fccSAndy Adamson if (status) 7059fa178f29STrond Myklebust goto out; 7060bf269551SChuck Lever status = decode_putfh(xdr); 7061fa178f29STrond Myklebust if (status != 0) 7062fa178f29STrond Myklebust goto out; 7063586f1c39STrond Myklebust if (res->lr_res) { 7064586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 7065586f1c39STrond Myklebust res->lr_ret = status; 7066586f1c39STrond Myklebust if (status) 7067586f1c39STrond Myklebust goto out; 7068586f1c39STrond Myklebust } 70698ac2b422STrond Myklebust if (res->fattr) { 7070e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 7071556ae3bbSJeff Layton if (status != 0) 7072556ae3bbSJeff Layton goto out; 70738ac2b422STrond Myklebust } 7074e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 7075fa178f29STrond Myklebust out: 70761da177e4SLinus Torvalds return status; 70771da177e4SLinus Torvalds } 70781da177e4SLinus Torvalds 7079683b57b4STrond Myklebust /* 70808b173218SRicardo Labiaga * Decode FS_LOCATIONS response 7081683b57b4STrond Myklebust */ 7082bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 7083bf269551SChuck Lever struct xdr_stream *xdr, 7084fc016483SChristoph Hellwig void *data) 7085683b57b4STrond Myklebust { 7086fc016483SChristoph Hellwig struct nfs4_fs_locations_res *res = data; 7087683b57b4STrond Myklebust struct compound_hdr hdr; 7088683b57b4STrond Myklebust int status; 7089683b57b4STrond Myklebust 7090bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70919b7b9fccSAndy Adamson if (status) 70929b7b9fccSAndy Adamson goto out; 7093bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70949b7b9fccSAndy Adamson if (status) 7095683b57b4STrond Myklebust goto out; 7096bf269551SChuck Lever status = decode_putfh(xdr); 7097bf269551SChuck Lever if (status) 7098683b57b4STrond Myklebust goto out; 7099b03d735bSChuck Lever if (res->migration) { 7100b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7101b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7102b03d735bSChuck Lever &res->fs_locations->fattr, 7103b03d735bSChuck Lever NULL, res->fs_locations, 7104b03d735bSChuck Lever NULL, res->fs_locations->server); 7105b03d735bSChuck Lever if (status) 7106b03d735bSChuck Lever goto out; 7107b03d735bSChuck Lever if (res->renew) 7108b03d735bSChuck Lever status = decode_renew(xdr); 7109b03d735bSChuck Lever } else { 7110bf269551SChuck Lever status = decode_lookup(xdr); 7111bf269551SChuck Lever if (status) 7112683b57b4STrond Myklebust goto out; 7113bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7114b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7115b03d735bSChuck Lever &res->fs_locations->fattr, 71168b7e3f49STrond Myklebust NULL, res->fs_locations, 7117aa9c2669SDavid Quigley NULL, res->fs_locations->server); 7118b03d735bSChuck Lever } 7119683b57b4STrond Myklebust out: 7120683b57b4STrond Myklebust return status; 7121683b57b4STrond Myklebust } 7122683b57b4STrond Myklebust 71235a5ea0d4SBryan Schumaker /* 71245a5ea0d4SBryan Schumaker * Decode SECINFO response 71255a5ea0d4SBryan Schumaker */ 71265a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 71275a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 7128fc016483SChristoph Hellwig void *data) 71295a5ea0d4SBryan Schumaker { 7130fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 71315a5ea0d4SBryan Schumaker struct compound_hdr hdr; 71325a5ea0d4SBryan Schumaker int status; 71335a5ea0d4SBryan Schumaker 71345a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 71355a5ea0d4SBryan Schumaker if (status) 71365a5ea0d4SBryan Schumaker goto out; 71375a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 71385a5ea0d4SBryan Schumaker if (status) 71395a5ea0d4SBryan Schumaker goto out; 71405a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 71415a5ea0d4SBryan Schumaker if (status) 71425a5ea0d4SBryan Schumaker goto out; 71435a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 71445a5ea0d4SBryan Schumaker out: 71455a5ea0d4SBryan Schumaker return status; 71465a5ea0d4SBryan Schumaker } 71475a5ea0d4SBryan Schumaker 714844c99933SChuck Lever /* 714944c99933SChuck Lever * Decode FSID_PRESENT response 715044c99933SChuck Lever */ 715144c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 715244c99933SChuck Lever struct xdr_stream *xdr, 7153fc016483SChristoph Hellwig void *data) 715444c99933SChuck Lever { 7155fc016483SChristoph Hellwig struct nfs4_fsid_present_res *res = data; 715644c99933SChuck Lever struct compound_hdr hdr; 715744c99933SChuck Lever int status; 715844c99933SChuck Lever 715944c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 716044c99933SChuck Lever if (status) 716144c99933SChuck Lever goto out; 716244c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 716344c99933SChuck Lever if (status) 716444c99933SChuck Lever goto out; 716544c99933SChuck Lever status = decode_putfh(xdr); 716644c99933SChuck Lever if (status) 716744c99933SChuck Lever goto out; 716844c99933SChuck Lever status = decode_getfh(xdr, res->fh); 716944c99933SChuck Lever if (status) 717044c99933SChuck Lever goto out; 717144c99933SChuck Lever if (res->renew) 717244c99933SChuck Lever status = decode_renew(xdr); 717344c99933SChuck Lever out: 717444c99933SChuck Lever return status; 717544c99933SChuck Lever } 717644c99933SChuck Lever 717799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 717899fe60d0SBenny Halevy /* 71797c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 71807c44f1aeSWeston Andros Adamson */ 71817c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 71827c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 71837c44f1aeSWeston Andros Adamson void *res) 71847c44f1aeSWeston Andros Adamson { 71857c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 71867c44f1aeSWeston Andros Adamson int status; 71877c44f1aeSWeston Andros Adamson 71887c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 71897c44f1aeSWeston Andros Adamson if (!status) 71907c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 71917c44f1aeSWeston Andros Adamson return status; 71927c44f1aeSWeston Andros Adamson } 71937c44f1aeSWeston Andros Adamson 71947c44f1aeSWeston Andros Adamson /* 71958b173218SRicardo Labiaga * Decode EXCHANGE_ID response 719699fe60d0SBenny Halevy */ 7197bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7198bf269551SChuck Lever struct xdr_stream *xdr, 719999fe60d0SBenny Halevy void *res) 720099fe60d0SBenny Halevy { 720199fe60d0SBenny Halevy struct compound_hdr hdr; 720299fe60d0SBenny Halevy int status; 720399fe60d0SBenny Halevy 7204bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 720599fe60d0SBenny Halevy if (!status) 7206bf269551SChuck Lever status = decode_exchange_id(xdr, res); 720799fe60d0SBenny Halevy return status; 720899fe60d0SBenny Halevy } 72092050f0ccSAndy Adamson 72102050f0ccSAndy Adamson /* 72118b173218SRicardo Labiaga * Decode CREATE_SESSION response 7212fc931582SAndy Adamson */ 7213bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7214bf269551SChuck Lever struct xdr_stream *xdr, 7215fc016483SChristoph Hellwig void *res) 7216fc931582SAndy Adamson { 7217fc931582SAndy Adamson struct compound_hdr hdr; 7218fc931582SAndy Adamson int status; 7219fc931582SAndy Adamson 7220bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7221fc931582SAndy Adamson if (!status) 7222bf269551SChuck Lever status = decode_create_session(xdr, res); 7223fc931582SAndy Adamson return status; 7224fc931582SAndy Adamson } 7225fc931582SAndy Adamson 7226fc931582SAndy Adamson /* 72278b173218SRicardo Labiaga * Decode DESTROY_SESSION response 72280f3e66c6SAndy Adamson */ 7229bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7230bf269551SChuck Lever struct xdr_stream *xdr, 7231bf269551SChuck Lever void *res) 72320f3e66c6SAndy Adamson { 72330f3e66c6SAndy Adamson struct compound_hdr hdr; 72340f3e66c6SAndy Adamson int status; 72350f3e66c6SAndy Adamson 7236bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 72370f3e66c6SAndy Adamson if (!status) 7238bf269551SChuck Lever status = decode_destroy_session(xdr, res); 72390f3e66c6SAndy Adamson return status; 72400f3e66c6SAndy Adamson } 72410f3e66c6SAndy Adamson 72420f3e66c6SAndy Adamson /* 724366245539STrond Myklebust * Decode DESTROY_CLIENTID response 724466245539STrond Myklebust */ 724566245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 724666245539STrond Myklebust struct xdr_stream *xdr, 724766245539STrond Myklebust void *res) 724866245539STrond Myklebust { 724966245539STrond Myklebust struct compound_hdr hdr; 725066245539STrond Myklebust int status; 725166245539STrond Myklebust 725266245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 725366245539STrond Myklebust if (!status) 725466245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 725566245539STrond Myklebust return status; 725666245539STrond Myklebust } 725766245539STrond Myklebust 725866245539STrond Myklebust /* 72598b173218SRicardo Labiaga * Decode SEQUENCE response 7260fc01cea9SAndy Adamson */ 7261bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7262bf269551SChuck Lever struct xdr_stream *xdr, 7263fc016483SChristoph Hellwig void *res) 7264fc01cea9SAndy Adamson { 7265fc01cea9SAndy Adamson struct compound_hdr hdr; 7266fc01cea9SAndy Adamson int status; 7267fc01cea9SAndy Adamson 7268bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7269fc01cea9SAndy Adamson if (!status) 7270bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7271fc01cea9SAndy Adamson return status; 7272fc01cea9SAndy Adamson } 7273fc01cea9SAndy Adamson 7274fc01cea9SAndy Adamson /* 72758b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 72762050f0ccSAndy Adamson */ 7277bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7278bf269551SChuck Lever struct xdr_stream *xdr, 7279fc016483SChristoph Hellwig void *data) 72802050f0ccSAndy Adamson { 7281fc016483SChristoph Hellwig struct nfs4_get_lease_time_res *res = data; 72822050f0ccSAndy Adamson struct compound_hdr hdr; 72832050f0ccSAndy Adamson int status; 72842050f0ccSAndy Adamson 7285bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 72862050f0ccSAndy Adamson if (!status) 7287bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 72882050f0ccSAndy Adamson if (!status) 7289bf269551SChuck Lever status = decode_putrootfh(xdr); 72902050f0ccSAndy Adamson if (!status) 7291bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 72922050f0ccSAndy Adamson return status; 72932050f0ccSAndy Adamson } 729418019753SRicardo Labiaga 729518019753SRicardo Labiaga /* 729618019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 729718019753SRicardo Labiaga */ 7298bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7299bf269551SChuck Lever struct xdr_stream *xdr, 7300fc016483SChristoph Hellwig void *data) 730118019753SRicardo Labiaga { 7302fc016483SChristoph Hellwig struct nfs41_reclaim_complete_res *res = data; 730318019753SRicardo Labiaga struct compound_hdr hdr; 730418019753SRicardo Labiaga int status; 730518019753SRicardo Labiaga 7306bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 730718019753SRicardo Labiaga if (!status) 7308bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 730918019753SRicardo Labiaga if (!status) 73108ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 731118019753SRicardo Labiaga return status; 731218019753SRicardo Labiaga } 7313b1f69b75SAndy Adamson 7314b1f69b75SAndy Adamson /* 7315b1f69b75SAndy Adamson * Decode GETDEVINFO response 7316b1f69b75SAndy Adamson */ 7317bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7318bf269551SChuck Lever struct xdr_stream *xdr, 7319fc016483SChristoph Hellwig void *data) 7320b1f69b75SAndy Adamson { 7321fc016483SChristoph Hellwig struct nfs4_getdeviceinfo_res *res = data; 7322b1f69b75SAndy Adamson struct compound_hdr hdr; 7323b1f69b75SAndy Adamson int status; 7324b1f69b75SAndy Adamson 7325bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7326b1f69b75SAndy Adamson if (status != 0) 7327b1f69b75SAndy Adamson goto out; 7328bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7329b1f69b75SAndy Adamson if (status != 0) 7330b1f69b75SAndy Adamson goto out; 73314e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7332b1f69b75SAndy Adamson out: 7333b1f69b75SAndy Adamson return status; 7334b1f69b75SAndy Adamson } 7335b1f69b75SAndy Adamson 7336b1f69b75SAndy Adamson /* 7337b1f69b75SAndy Adamson * Decode LAYOUTGET response 7338b1f69b75SAndy Adamson */ 7339bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7340bf269551SChuck Lever struct xdr_stream *xdr, 7341fc016483SChristoph Hellwig void *data) 7342b1f69b75SAndy Adamson { 7343fc016483SChristoph Hellwig struct nfs4_layoutget_res *res = data; 7344b1f69b75SAndy Adamson struct compound_hdr hdr; 7345b1f69b75SAndy Adamson int status; 7346b1f69b75SAndy Adamson 7347bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7348b1f69b75SAndy Adamson if (status) 7349b1f69b75SAndy Adamson goto out; 7350bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7351b1f69b75SAndy Adamson if (status) 7352b1f69b75SAndy Adamson goto out; 7353bf269551SChuck Lever status = decode_putfh(xdr); 7354b1f69b75SAndy Adamson if (status) 7355b1f69b75SAndy Adamson goto out; 7356bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7357b1f69b75SAndy Adamson out: 7358b1f69b75SAndy Adamson return status; 7359b1f69b75SAndy Adamson } 7360863a3c6cSAndy Adamson 7361863a3c6cSAndy Adamson /* 7362cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7363cbe82603SBenny Halevy */ 7364cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7365cbe82603SBenny Halevy struct xdr_stream *xdr, 7366fc016483SChristoph Hellwig void *data) 7367cbe82603SBenny Halevy { 7368fc016483SChristoph Hellwig struct nfs4_layoutreturn_res *res = data; 7369cbe82603SBenny Halevy struct compound_hdr hdr; 7370cbe82603SBenny Halevy int status; 7371cbe82603SBenny Halevy 7372cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7373cbe82603SBenny Halevy if (status) 7374cbe82603SBenny Halevy goto out; 7375cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7376cbe82603SBenny Halevy if (status) 7377cbe82603SBenny Halevy goto out; 7378cbe82603SBenny Halevy status = decode_putfh(xdr); 7379cbe82603SBenny Halevy if (status) 7380cbe82603SBenny Halevy goto out; 7381cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7382cbe82603SBenny Halevy out: 7383cbe82603SBenny Halevy return status; 7384cbe82603SBenny Halevy } 7385cbe82603SBenny Halevy 7386cbe82603SBenny Halevy /* 7387863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7388863a3c6cSAndy Adamson */ 7389863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7390863a3c6cSAndy Adamson struct xdr_stream *xdr, 7391fc016483SChristoph Hellwig void *data) 7392863a3c6cSAndy Adamson { 7393fc016483SChristoph Hellwig struct nfs4_layoutcommit_res *res = data; 7394863a3c6cSAndy Adamson struct compound_hdr hdr; 7395863a3c6cSAndy Adamson int status; 7396863a3c6cSAndy Adamson 7397863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7398863a3c6cSAndy Adamson if (status) 7399863a3c6cSAndy Adamson goto out; 7400863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7401863a3c6cSAndy Adamson if (status) 7402863a3c6cSAndy Adamson goto out; 7403863a3c6cSAndy Adamson status = decode_putfh(xdr); 7404863a3c6cSAndy Adamson if (status) 7405863a3c6cSAndy Adamson goto out; 7406863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7407863a3c6cSAndy Adamson if (status) 7408863a3c6cSAndy Adamson goto out; 74096926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7410863a3c6cSAndy Adamson out: 7411863a3c6cSAndy Adamson return status; 7412863a3c6cSAndy Adamson } 7413fca78d6dSBryan Schumaker 7414fca78d6dSBryan Schumaker /* 7415fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7416fca78d6dSBryan Schumaker */ 7417fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7418fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7419fc016483SChristoph Hellwig void *data) 7420fca78d6dSBryan Schumaker { 7421fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 7422fca78d6dSBryan Schumaker struct compound_hdr hdr; 7423fca78d6dSBryan Schumaker int status; 7424fca78d6dSBryan Schumaker 7425fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7426fca78d6dSBryan Schumaker if (status) 7427fca78d6dSBryan Schumaker goto out; 7428fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7429fca78d6dSBryan Schumaker if (status) 7430fca78d6dSBryan Schumaker goto out; 7431fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7432fca78d6dSBryan Schumaker if (status) 7433fca78d6dSBryan Schumaker goto out; 743431e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7435fca78d6dSBryan Schumaker out: 7436fca78d6dSBryan Schumaker return status; 7437fca78d6dSBryan Schumaker } 74387d974794SBryan Schumaker 74397d974794SBryan Schumaker /* 74407d974794SBryan Schumaker * Decode TEST_STATEID response 74417d974794SBryan Schumaker */ 74427d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 74437d974794SBryan Schumaker struct xdr_stream *xdr, 7444fc016483SChristoph Hellwig void *data) 74457d974794SBryan Schumaker { 7446fc016483SChristoph Hellwig struct nfs41_test_stateid_res *res = data; 74477d974794SBryan Schumaker struct compound_hdr hdr; 74487d974794SBryan Schumaker int status; 74497d974794SBryan Schumaker 74507d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 74517d974794SBryan Schumaker if (status) 74527d974794SBryan Schumaker goto out; 74537d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 74547d974794SBryan Schumaker if (status) 74557d974794SBryan Schumaker goto out; 74567d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 74577d974794SBryan Schumaker out: 74587d974794SBryan Schumaker return status; 74597d974794SBryan Schumaker } 74609aeda35fSBryan Schumaker 74619aeda35fSBryan Schumaker /* 74629aeda35fSBryan Schumaker * Decode FREE_STATEID response 74639aeda35fSBryan Schumaker */ 74649aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 74659aeda35fSBryan Schumaker struct xdr_stream *xdr, 7466fc016483SChristoph Hellwig void *data) 74679aeda35fSBryan Schumaker { 7468fc016483SChristoph Hellwig struct nfs41_free_stateid_res *res = data; 74699aeda35fSBryan Schumaker struct compound_hdr hdr; 74709aeda35fSBryan Schumaker int status; 74719aeda35fSBryan Schumaker 74729aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 74739aeda35fSBryan Schumaker if (status) 74749aeda35fSBryan Schumaker goto out; 74759aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 74769aeda35fSBryan Schumaker if (status) 74779aeda35fSBryan Schumaker goto out; 74789aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 74799aeda35fSBryan Schumaker out: 74809aeda35fSBryan Schumaker return status; 74819aeda35fSBryan Schumaker } 748299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 748399fe60d0SBenny Halevy 7484573c4e1eSChuck Lever /** 7485573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7486573c4e1eSChuck Lever * the local page cache. 7487573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7488573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7489573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7490573c4e1eSChuck Lever * 7491573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7492573c4e1eSChuck Lever * returned. 7493573c4e1eSChuck Lever * 7494573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7495573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7496573c4e1eSChuck Lever * on a directory already in our cache. 7497573c4e1eSChuck Lever */ 7498573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7499a7a3b1e9SBenjamin Coddington bool plus) 75001da177e4SLinus Torvalds { 7501256e48bbSTrond Myklebust unsigned int savep; 7502dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 75031da177e4SLinus Torvalds uint32_t len; 7504babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7505babddc72SBryan Schumaker if (unlikely(!p)) 7506babddc72SBryan Schumaker goto out_overflow; 7507c08e76d0SChuck Lever if (*p == xdr_zero) { 7508babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7509babddc72SBryan Schumaker if (unlikely(!p)) 7510babddc72SBryan Schumaker goto out_overflow; 7511c08e76d0SChuck Lever if (*p == xdr_zero) 7512573c4e1eSChuck Lever return -EAGAIN; 75131da177e4SLinus Torvalds entry->eof = 1; 7514573c4e1eSChuck Lever return -EBADCOOKIE; 75151da177e4SLinus Torvalds } 75161da177e4SLinus Torvalds 7517babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7518babddc72SBryan Schumaker if (unlikely(!p)) 7519babddc72SBryan Schumaker goto out_overflow; 75201da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 75211da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7522c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7523babddc72SBryan Schumaker 75249af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7525babddc72SBryan Schumaker if (unlikely(!p)) 7526babddc72SBryan Schumaker goto out_overflow; 75271da177e4SLinus Torvalds entry->name = (const char *) p; 75281da177e4SLinus Torvalds 75291da177e4SLinus Torvalds /* 75301da177e4SLinus Torvalds * In case the server doesn't return an inode number, 75311da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 75321da177e4SLinus Torvalds * since glibc seems to choke on it...) 75331da177e4SLinus Torvalds */ 75341da177e4SLinus Torvalds entry->ino = 1; 75354f082222STrond Myklebust entry->fattr->valid = 0; 75361da177e4SLinus Torvalds 75379af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7538babddc72SBryan Schumaker goto out_overflow; 75399af8c222STrond Myklebust 7540256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7541babddc72SBryan Schumaker goto out_overflow; 75429af8c222STrond Myklebust 7543573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7544aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7545babddc72SBryan Schumaker goto out_overflow; 754628331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 754728331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 754828331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 754982f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 75509af8c222STrond Myklebust 75510b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 75520b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 75530b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 75540b26a0bfSTrond Myklebust 7555573c4e1eSChuck Lever return 0; 7556babddc72SBryan Schumaker 7557babddc72SBryan Schumaker out_overflow: 7558babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7559573c4e1eSChuck Lever return -EAGAIN; 75601da177e4SLinus Torvalds } 75611da177e4SLinus Torvalds 75621da177e4SLinus Torvalds /* 75631da177e4SLinus Torvalds * We need to translate between nfs status return values and 75641da177e4SLinus Torvalds * the local errno values which may not be the same. 75651da177e4SLinus Torvalds */ 75661da177e4SLinus Torvalds static struct { 75671da177e4SLinus Torvalds int stat; 75681da177e4SLinus Torvalds int errno; 75691da177e4SLinus Torvalds } nfs_errtbl[] = { 75701da177e4SLinus Torvalds { NFS4_OK, 0 }, 7571856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7572856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7573856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7574856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7575856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7576856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7577856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7578856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7579856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7580856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7581856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7582856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7583856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7584856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7585856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7586856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7587856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7588856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7589856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7590856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7591856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7592856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7593fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7594856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7595856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7596856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7597856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7598856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7599856dff3dSBenny Halevy { -1, -EIO } 76001da177e4SLinus Torvalds }; 76011da177e4SLinus Torvalds 76021da177e4SLinus Torvalds /* 76031da177e4SLinus Torvalds * Convert an NFS error code to a local one. 76041da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 76051da177e4SLinus Torvalds */ 76061da177e4SLinus Torvalds static int 76070a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 76081da177e4SLinus Torvalds { 76091da177e4SLinus Torvalds int i; 76101da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 76111da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 76121da177e4SLinus Torvalds return nfs_errtbl[i].errno; 76131da177e4SLinus Torvalds } 76141da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 76151da177e4SLinus Torvalds /* The server is looney tunes. */ 7616fdcb4577STrond Myklebust return -EREMOTEIO; 76171da177e4SLinus Torvalds } 76181da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 76191da177e4SLinus Torvalds * handle it. 76201da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 76211da177e4SLinus Torvalds * not conflict with native Linux error codes. 76221da177e4SLinus Torvalds */ 7623856dff3dSBenny Halevy return -stat; 76241da177e4SLinus Torvalds } 76251da177e4SLinus Torvalds 76261c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 76271c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 76281c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 76291c6dcbe5SAnna Schumaker 76301da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 76311da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 76321da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 7633fcc85819SChristoph Hellwig .p_encode = nfs4_xdr_##argtype, \ 7634fc016483SChristoph Hellwig .p_decode = nfs4_xdr_##restype, \ 76352bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 76362bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7637cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7638cc0175c1SChuck Lever .p_name = #proc, \ 76391da177e4SLinus Torvalds } 76401da177e4SLinus Torvalds 76417c61f0d3SAnna Schumaker #define STUB(proc) \ 76427c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 76437c61f0d3SAnna Schumaker .p_name = #proc, \ 76447c61f0d3SAnna Schumaker } 76457c61f0d3SAnna Schumaker 76468634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1) 76478634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 76488634ef5eSTrond Myklebust PROC(proc, argtype, restype) 76498634ef5eSTrond Myklebust #else 76508634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 76518634ef5eSTrond Myklebust STUB(proc) 76528634ef5eSTrond Myklebust #endif 76538634ef5eSTrond Myklebust 76548634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2) 76558634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 76568634ef5eSTrond Myklebust PROC(proc, argtype, restype) 76578634ef5eSTrond Myklebust #else 76588634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 76598634ef5eSTrond Myklebust STUB(proc) 76608634ef5eSTrond Myklebust #endif 76618634ef5eSTrond Myklebust 7662511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = { 76631da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 76641da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 76651da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 76661da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 76671da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 76681da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 76691da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 76701da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 76711da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 76721da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 76731da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 76741da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 76751da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 76761da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 76771da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 76781da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 76791da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 76801da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 76811da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 76821da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 76831da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 76841da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 76851da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 76861da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 76871da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 76881da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 76891da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 76901da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 76911da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 76921da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 76931da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7694029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 769523ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7696683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7697d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 76985a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 769944c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 77008634ef5eSTrond Myklebust PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 77018634ef5eSTrond Myklebust PROC41(CREATE_SESSION, enc_create_session, dec_create_session), 77028634ef5eSTrond Myklebust PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 77038634ef5eSTrond Myklebust PROC41(SEQUENCE, enc_sequence, dec_sequence), 77048634ef5eSTrond Myklebust PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 77058634ef5eSTrond Myklebust PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete), 77068634ef5eSTrond Myklebust PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 77078634ef5eSTrond Myklebust PROC41(LAYOUTGET, enc_layoutget, dec_layoutget), 77088634ef5eSTrond Myklebust PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 77098634ef5eSTrond Myklebust PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 77108634ef5eSTrond Myklebust PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 77118634ef5eSTrond Myklebust PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid), 77128634ef5eSTrond Myklebust PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid), 77137c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 77148634ef5eSTrond Myklebust PROC41(BIND_CONN_TO_SESSION, 7715ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 77168634ef5eSTrond Myklebust PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid), 77178634ef5eSTrond Myklebust PROC42(SEEK, enc_seek, dec_seek), 77188634ef5eSTrond Myklebust PROC42(ALLOCATE, enc_allocate, dec_allocate), 77198634ef5eSTrond Myklebust PROC42(DEALLOCATE, enc_deallocate, dec_deallocate), 77208634ef5eSTrond Myklebust PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 77218634ef5eSTrond Myklebust PROC42(CLONE, enc_clone, dec_clone), 77228634ef5eSTrond Myklebust PROC42(COPY, enc_copy, dec_copy), 77238634ef5eSTrond Myklebust PROC(LOOKUPP, enc_lookupp, dec_lookupp), 77241da177e4SLinus Torvalds }; 77251da177e4SLinus Torvalds 7726c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)]; 7727a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 77281da177e4SLinus Torvalds .number = 4, 7729e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 7730c551858aSChristoph Hellwig .procs = nfs4_procedures, 7731c551858aSChristoph Hellwig .counts = nfs_version4_counts, 77321da177e4SLinus Torvalds }; 77331da177e4SLinus Torvalds 77341da177e4SLinus Torvalds /* 77351da177e4SLinus Torvalds * Local variables: 77361da177e4SLinus Torvalds * c-basic-offset: 8 77371da177e4SLinus Torvalds * End: 77381da177e4SLinus Torvalds */ 7739