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 9614ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9624ade9821STrond Myklebust const struct nfs_seqid *seqid) 9634ade9821STrond Myklebust { 964a6796419STrond Myklebust if (seqid != NULL) 9654ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 966a6796419STrond Myklebust else 967a6796419STrond Myklebust encode_uint32(xdr, 0); 9684ade9821STrond Myklebust } 9694ade9821STrond Myklebust 9700c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9710c4e8c18SBenny Halevy struct rpc_rqst *req, 9720c4e8c18SBenny Halevy struct compound_hdr *hdr) 9731da177e4SLinus Torvalds { 9748687b63aSAl Viro __be32 *p; 975a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9760c4e8c18SBenny Halevy 9770c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9780c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9790c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9800c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9811da177e4SLinus Torvalds 9827fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 9836fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9846fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 985e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 986d017931cSAndy Adamson hdr->nops_p = p; 98734558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 988d017931cSAndy Adamson } 989d017931cSAndy Adamson 990ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 991ab19b481STrond Myklebust uint32_t replen, 992ab19b481STrond Myklebust struct compound_hdr *hdr) 993ab19b481STrond Myklebust { 994ab19b481STrond Myklebust encode_uint32(xdr, op); 995ab19b481STrond Myklebust hdr->nops++; 996ab19b481STrond Myklebust hdr->replen += replen; 997ab19b481STrond Myklebust } 998ab19b481STrond Myklebust 999d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 1000d017931cSAndy Adamson { 10017fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 1002d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 10031da177e4SLinus Torvalds } 10041da177e4SLinus Torvalds 1005ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1006ea9d23f5STrond Myklebust { 10072d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 1008ea9d23f5STrond Myklebust } 1009ea9d23f5STrond Myklebust 10101da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 10111da177e4SLinus Torvalds { 1012cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 10131da177e4SLinus Torvalds } 10141da177e4SLinus Torvalds 1015aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1016aa9c2669SDavid Quigley const struct nfs4_label *label, 101728cf22d0STrond Myklebust const umode_t *umask, 10185334c5bdSKinglong Mee const struct nfs_server *server, 101928cf22d0STrond Myklebust const uint32_t attrmask[]) 10201da177e4SLinus Torvalds { 10211da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10221da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10231da177e4SLinus Torvalds int owner_namelen = 0; 10241da177e4SLinus Torvalds int owner_grouplen = 0; 10258687b63aSAl Viro __be32 *p; 1026d7067b2dSTrond Myklebust unsigned i; 1027d7067b2dSTrond Myklebust uint32_t len = 0; 1028d7067b2dSTrond Myklebust uint32_t bmval_len; 1029d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10301da177e4SLinus Torvalds 10311da177e4SLinus Torvalds /* 10321da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10331da177e4SLinus Torvalds */ 103428cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) { 1035d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10361da177e4SLinus Torvalds len += 8; 1037d7067b2dSTrond Myklebust } 1038d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 103928cf22d0STrond Myklebust if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) { 1040dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK; 1041dff25ddbSAndreas Gruenbacher len += 8; 104228cf22d0STrond Myklebust } else if (attrmask[1] & FATTR4_WORD1_MODE) { 1043d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10441da177e4SLinus Torvalds len += 4; 1045d7067b2dSTrond Myklebust } 1046dff25ddbSAndreas Gruenbacher } 104728cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) { 1048e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10491da177e4SLinus Torvalds if (owner_namelen < 0) { 1050fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1051e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 10521da177e4SLinus Torvalds /* XXX */ 10531da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10541da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10551da177e4SLinus Torvalds /* goto out; */ 10561da177e4SLinus Torvalds } 1057d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 10581da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10591da177e4SLinus Torvalds } 106028cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_GID) && 106128cf22d0STrond Myklebust (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) { 1062e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10631da177e4SLinus Torvalds if (owner_grouplen < 0) { 1064fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1065e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 10661da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10671da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10681da177e4SLinus Torvalds /* goto out; */ 10691da177e4SLinus Torvalds } 1070d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 10711da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10721da177e4SLinus Torvalds } 107328cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 1074d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1075d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10761da177e4SLinus Torvalds len += 16; 1077d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1078d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10791da177e4SLinus Torvalds len += 4; 1080d7067b2dSTrond Myklebust } 108128cf22d0STrond Myklebust } 108228cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 1083d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1084d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10851da177e4SLinus Torvalds len += 16; 1086d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1087d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10881da177e4SLinus Torvalds len += 4; 1089d7067b2dSTrond Myklebust } 10905334c5bdSKinglong Mee } 10915334c5bdSKinglong Mee 109228cf22d0STrond Myklebust if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) { 1093b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1094d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1095d7067b2dSTrond Myklebust } 1096d7067b2dSTrond Myklebust 1097d7067b2dSTrond Myklebust if (bmval[2] != 0) 1098b4a2cf76STrond Myklebust bmval_len = 3; 1099d7067b2dSTrond Myklebust else if (bmval[1] != 0) 1100d7067b2dSTrond Myklebust bmval_len = 2; 1101d7067b2dSTrond Myklebust else 1102d7067b2dSTrond Myklebust bmval_len = 1; 1103b4a2cf76STrond Myklebust 1104d7067b2dSTrond Myklebust p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len); 11051da177e4SLinus Torvalds 1106b4a2cf76STrond Myklebust *p++ = cpu_to_be32(bmval_len); 1107d7067b2dSTrond Myklebust for (i = 0; i < bmval_len; i++) 1108d7067b2dSTrond Myklebust *p++ = cpu_to_be32(bmval[i]); 1109d7067b2dSTrond Myklebust *p++ = cpu_to_be32(len); 11101da177e4SLinus Torvalds 1111d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1112b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1113d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1114e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1115d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1116811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1117d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1118811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1119d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11201da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1121e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1122042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec); 1123d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 1124d7067b2dSTrond Myklebust } else 1125e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11261da177e4SLinus Torvalds } 1127d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11281da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1129e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1130042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec); 1131e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 1132d7067b2dSTrond Myklebust } else 1133e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11341da177e4SLinus Torvalds } 1135d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1136aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1137aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1138aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1139aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1140aa9c2669SDavid Quigley } 1141dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1142dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1143dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask); 1144dff25ddbSAndreas Gruenbacher } 11451da177e4SLinus Torvalds 11461da177e4SLinus Torvalds /* out: */ 11471da177e4SLinus Torvalds } 11481da177e4SLinus Torvalds 1149cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11501da177e4SLinus Torvalds { 1151475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1152475d4ba0STrond Myklebust encode_uint32(xdr, access); 11531da177e4SLinus Torvalds } 11541da177e4SLinus Torvalds 1155cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11561da177e4SLinus Torvalds { 1157ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11584ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1159566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11601da177e4SLinus Torvalds } 11611da177e4SLinus Torvalds 11620b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11631da177e4SLinus Torvalds { 11648687b63aSAl Viro __be32 *p; 11651da177e4SLinus Torvalds 1166475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1167475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1168b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 116934558513SBenny Halevy *p = cpu_to_be32(args->count); 11701da177e4SLinus Torvalds } 11711da177e4SLinus Torvalds 1172cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11731da177e4SLinus Torvalds { 11748687b63aSAl Viro __be32 *p; 11751da177e4SLinus Torvalds 1176475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1177475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11781da177e4SLinus Torvalds 11791da177e4SLinus Torvalds switch (create->ftype) { 11801da177e4SLinus Torvalds case NF4LNK: 118113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 118234558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 11832fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 11842fcc213aSChuck Lever create->u.symlink.len); 11852fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 11861da177e4SLinus Torvalds break; 11871da177e4SLinus Torvalds 11881da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 118913c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1190e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 119134558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11921da177e4SLinus Torvalds break; 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds default: 11951da177e4SLinus Torvalds break; 11961da177e4SLinus Torvalds } 11971da177e4SLinus Torvalds 1198811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 119928cf22d0STrond Myklebust encode_attrs(xdr, create->attrs, create->label, &create->umask, 120028cf22d0STrond Myklebust create->server, create->server->attr_bitmask); 12011da177e4SLinus Torvalds } 12021da177e4SLinus Torvalds 1203cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 12041da177e4SLinus Torvalds { 12058687b63aSAl Viro __be32 *p; 12061da177e4SLinus Torvalds 1207475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1208475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1209e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 121034558513SBenny Halevy *p = cpu_to_be32(bitmap); 12111da177e4SLinus Torvalds } 12121da177e4SLinus Torvalds 1213cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 12141da177e4SLinus Torvalds { 12158687b63aSAl Viro __be32 *p; 12161da177e4SLinus Torvalds 1217475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1218475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1219e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1220e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 122134558513SBenny Halevy *p = cpu_to_be32(bm1); 12221da177e4SLinus Torvalds } 12231da177e4SLinus Torvalds 1224dae100c2SFred Isaman static void 1225dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1226dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1227dae100c2SFred Isaman struct compound_hdr *hdr) 1228dae100c2SFred Isaman { 1229dae100c2SFred Isaman __be32 *p; 1230dae100c2SFred Isaman 1231ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1232dae100c2SFred Isaman if (bm2) { 1233dae100c2SFred Isaman p = reserve_space(xdr, 16); 1234dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1235dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1236dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1237dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1238dae100c2SFred Isaman } else if (bm1) { 1239dae100c2SFred Isaman p = reserve_space(xdr, 12); 1240dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1241dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1242dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1243dae100c2SFred Isaman } else { 1244dae100c2SFred Isaman p = reserve_space(xdr, 8); 1245dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1246dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1247dae100c2SFred Isaman } 1248dae100c2SFred Isaman } 1249dae100c2SFred Isaman 1250cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12511da177e4SLinus Torvalds { 1252a09df2caSDavid Quigley encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1253a09df2caSDavid Quigley bitmask[1] & nfs4_fattr_bitmap[1], 1254a09df2caSDavid Quigley bitmask[2] & nfs4_fattr_bitmap[2], 1255a09df2caSDavid Quigley hdr); 12561da177e4SLinus Torvalds } 12571da177e4SLinus Torvalds 125888034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12591549210fSTrond Myklebust const u32 *open_bitmap, 126088034c3dSAndy Adamson struct compound_hdr *hdr) 126188034c3dSAndy Adamson { 126288034c3dSAndy Adamson encode_getattr_three(xdr, 12631549210fSTrond Myklebust bitmask[0] & open_bitmap[0], 12641549210fSTrond Myklebust bitmask[1] & open_bitmap[1], 12651549210fSTrond Myklebust bitmask[2] & open_bitmap[2], 126688034c3dSAndy Adamson hdr); 126788034c3dSAndy Adamson } 126888034c3dSAndy Adamson 1269cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12701da177e4SLinus Torvalds { 1271dae100c2SFred Isaman encode_getattr_three(xdr, 1272dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1273dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1274dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1275dae100c2SFred Isaman hdr); 12761da177e4SLinus Torvalds } 12771da177e4SLinus Torvalds 1278cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1279830b8e33SManoj Naik { 1280cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1281cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1282830b8e33SManoj Naik } 1283830b8e33SManoj Naik 1284cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12851da177e4SLinus Torvalds { 1286ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12871da177e4SLinus Torvalds } 12881da177e4SLinus Torvalds 1289cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12901da177e4SLinus Torvalds { 1291ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12926fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12931da177e4SLinus Torvalds } 12941da177e4SLinus Torvalds 1295911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1296911d1aafSTrond Myklebust { 1297f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1298911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1299911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1300911d1aafSTrond Myklebust } 1301911d1aafSTrond Myklebust 1302911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1303911d1aafSTrond Myklebust { 1304911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1305911d1aafSTrond Myklebust return ~(uint64_t)0; 1306911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1307911d1aafSTrond Myklebust } 1308911d1aafSTrond Myklebust 1309daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1310daccbdedSTrond Myklebust { 1311daccbdedSTrond Myklebust __be32 *p; 1312daccbdedSTrond Myklebust 1313d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1314daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1315d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1316daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1317d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1318daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1319daccbdedSTrond Myklebust } 1320daccbdedSTrond Myklebust 13211da177e4SLinus Torvalds /* 13221da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13231da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13241da177e4SLinus Torvalds */ 1325cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13261da177e4SLinus Torvalds { 13278687b63aSAl Viro __be32 *p; 13281da177e4SLinus Torvalds 1329475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1330475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1331e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1332e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1333b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1334b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 133534558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1336911d1aafSTrond Myklebust if (args->new_lock_owner){ 13374ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1338425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13394ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1340daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds else { 1343425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13444ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13451da177e4SLinus Torvalds } 13461da177e4SLinus Torvalds } 13471da177e4SLinus Torvalds 1348cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13491da177e4SLinus Torvalds { 13508687b63aSAl Viro __be32 *p; 13511da177e4SLinus Torvalds 1352475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1353475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1354e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1355b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1356b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1357daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13581da177e4SLinus Torvalds } 13591da177e4SLinus Torvalds 1360cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13611da177e4SLinus Torvalds { 13628687b63aSAl Viro __be32 *p; 13631da177e4SLinus Torvalds 1364475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1365475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13664ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1367425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1368ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1369b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 137034558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13711da177e4SLinus Torvalds } 13721da177e4SLinus Torvalds 1373d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1374d3c7b7ccSTrond Myklebust { 1375ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1376d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1377d3c7b7ccSTrond Myklebust } 1378d3c7b7ccSTrond Myklebust 1379cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13801da177e4SLinus Torvalds { 1381ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13826fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13831da177e4SLinus Torvalds } 13841da177e4SLinus Torvalds 13855b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr) 13865b5faaf6SJeff Layton { 13875b5faaf6SJeff Layton encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr); 13885b5faaf6SJeff Layton } 13895b5faaf6SJeff Layton 13906ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13911da177e4SLinus Torvalds { 13928687b63aSAl Viro __be32 *p; 13931da177e4SLinus Torvalds 139413c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13956ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 139634558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13971da177e4SLinus Torvalds } 13981da177e4SLinus Torvalds 13991da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14001da177e4SLinus Torvalds { 14018687b63aSAl Viro __be32 *p; 14021da177e4SLinus Torvalds /* 14031da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 14041da177e4SLinus Torvalds * owner 4 = 32 14051da177e4SLinus Torvalds */ 14064ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14076ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 140895b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1409b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 141095b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 141193f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1412d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 141395b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 141495b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 14151da177e4SLinus Torvalds } 14161da177e4SLinus Torvalds 14171da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14181da177e4SLinus Torvalds { 14198687b63aSAl Viro __be32 *p; 14201da177e4SLinus Torvalds 142113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1422549b19ccSTrond Myklebust switch(arg->createmode) { 1423549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 142434558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 142528cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 142628cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 14271da177e4SLinus Torvalds break; 1428549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14294882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 143028cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 143128cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 1432549b19ccSTrond Myklebust break; 1433549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1434549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1435549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1436549b19ccSTrond Myklebust break; 1437549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14384882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14394882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 144028cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 144128cf22d0STrond Myklebust arg->server, arg->server->exclcreat_bitmask); 14424882ef72SAlexandros Batsakis } 14434882ef72SAlexandros Batsakis } 14441da177e4SLinus Torvalds 14451da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14461da177e4SLinus Torvalds { 14478687b63aSAl Viro __be32 *p; 14481da177e4SLinus Torvalds 144913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14501da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14511da177e4SLinus Torvalds case 0: 145234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14531da177e4SLinus Torvalds break; 14541da177e4SLinus Torvalds default: 145534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14561da177e4SLinus Torvalds encode_createmode(xdr, arg); 14571da177e4SLinus Torvalds } 14581da177e4SLinus Torvalds } 14591da177e4SLinus Torvalds 1460bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14611da177e4SLinus Torvalds { 14628687b63aSAl Viro __be32 *p; 14631da177e4SLinus Torvalds 146413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14651da177e4SLinus Torvalds switch (delegation_type) { 14661da177e4SLinus Torvalds case 0: 146734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14681da177e4SLinus Torvalds break; 14691da177e4SLinus Torvalds case FMODE_READ: 147034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14711da177e4SLinus Torvalds break; 14721da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 147334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14741da177e4SLinus Torvalds break; 14751da177e4SLinus Torvalds default: 14761da177e4SLinus Torvalds BUG(); 14771da177e4SLinus Torvalds } 14781da177e4SLinus Torvalds } 14791da177e4SLinus Torvalds 14801da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14811da177e4SLinus Torvalds { 14828687b63aSAl Viro __be32 *p; 14831da177e4SLinus Torvalds 148413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 148534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14861da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14871da177e4SLinus Torvalds } 14881da177e4SLinus Torvalds 1489bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14901da177e4SLinus Torvalds { 14918687b63aSAl Viro __be32 *p; 14921da177e4SLinus Torvalds 149313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 149434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14951da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14961da177e4SLinus Torvalds } 14971da177e4SLinus Torvalds 14981da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14991da177e4SLinus Torvalds { 15008687b63aSAl Viro __be32 *p; 15011da177e4SLinus Torvalds 1502ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1503ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1504ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 15051da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds 1508d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1509d9fc6619STrond Myklebust { 1510d9fc6619STrond Myklebust __be32 *p; 1511d9fc6619STrond Myklebust 1512d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1513d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1514d9fc6619STrond Myklebust } 1515d9fc6619STrond Myklebust 1516d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1517d9fc6619STrond Myklebust { 1518d9fc6619STrond Myklebust __be32 *p; 1519d9fc6619STrond Myklebust 1520d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1521d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1522d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1523d9fc6619STrond Myklebust } 1524d9fc6619STrond Myklebust 1525cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15261da177e4SLinus Torvalds { 1527ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15281da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15291da177e4SLinus Torvalds encode_opentype(xdr, arg); 15301da177e4SLinus Torvalds switch (arg->claim) { 15311da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15321da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15331da177e4SLinus Torvalds break; 15341da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15351da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15361da177e4SLinus Torvalds break; 15371da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15381da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15391da177e4SLinus Torvalds break; 1540d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1541d9fc6619STrond Myklebust encode_claim_fh(xdr); 1542d9fc6619STrond Myklebust break; 1543d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1544d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1545d9fc6619STrond Myklebust break; 15461da177e4SLinus Torvalds default: 15471da177e4SLinus Torvalds BUG(); 15481da177e4SLinus Torvalds } 15491da177e4SLinus Torvalds } 15501da177e4SLinus Torvalds 1551cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15521da177e4SLinus Torvalds { 1553ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1554ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15554ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15561da177e4SLinus Torvalds } 15571da177e4SLinus Torvalds 1558cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15591da177e4SLinus Torvalds { 1560ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1561566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15624ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15636ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15641da177e4SLinus Torvalds } 15651da177e4SLinus Torvalds 1566cf8cdbe5SAndy Adamson static void 1567d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15681da177e4SLinus Torvalds { 1569ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15706fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15711da177e4SLinus Torvalds } 15721da177e4SLinus Torvalds 1573cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15741da177e4SLinus Torvalds { 1575ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15761da177e4SLinus Torvalds } 15771da177e4SLinus Torvalds 15783c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15793c6b899cSAnna Schumaker struct compound_hdr *hdr) 15801da177e4SLinus Torvalds { 15818687b63aSAl Viro __be32 *p; 15821da177e4SLinus Torvalds 1583ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15849b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15851da177e4SLinus Torvalds 158613c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1587b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 158834558513SBenny Halevy *p = cpu_to_be32(args->count); 15891da177e4SLinus Torvalds } 15901da177e4SLinus Torvalds 1591cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15921da177e4SLinus Torvalds { 1593aa9c2669SDavid Quigley uint32_t attrs[3] = { 159428331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 159528331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 159628331a46STrond Myklebust }; 15976f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1598cd93710eSChuck Lever __be32 *p, verf[2]; 1599d204c5d2STrond Myklebust uint32_t attrlen = 0; 1600d204c5d2STrond Myklebust unsigned int i; 16011da177e4SLinus Torvalds 160282f2e547SBryan Schumaker if (readdir->plus) { 160382f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 160428331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 160582f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 160682f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 160782f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 160882f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1609d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 16106f7a35bdSTrond Myklebust dircount >>= 1; 161182f2e547SBryan Schumaker } 161228331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 161328331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 161428331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1615d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1616d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1617d204c5d2STrond Myklebust if (attrs[i] != 0) 1618d204c5d2STrond Myklebust attrlen = i+1; 1619d204c5d2STrond Myklebust } 16206f7a35bdSTrond Myklebust 1621475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1622ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1623cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1624d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16256f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16266f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1627d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1628d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1629d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1630cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1631aa9c2669SDavid Quigley 1632aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 163344109241SFred Isaman __func__, 1634eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1635cd93710eSChuck Lever verf[0], verf[1], 1636eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1637aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1638aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16391da177e4SLinus Torvalds } 16401da177e4SLinus Torvalds 1641cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16421da177e4SLinus Torvalds { 1643ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16441da177e4SLinus Torvalds } 16451da177e4SLinus Torvalds 1646cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16471da177e4SLinus Torvalds { 1648ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16496fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16501da177e4SLinus Torvalds } 16511da177e4SLinus Torvalds 1652cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16531da177e4SLinus Torvalds { 1654ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1655811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1656811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16571da177e4SLinus Torvalds } 16581da177e4SLinus Torvalds 1659bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1660bb4dae5eSChuck Lever struct compound_hdr *hdr) 16611da177e4SLinus Torvalds { 1662475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1663ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16641da177e4SLinus Torvalds } 16651da177e4SLinus Torvalds 1666cf8cdbe5SAndy Adamson static void 1667d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 166856ae19f3STrond Myklebust { 1669ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 167056ae19f3STrond Myklebust } 167156ae19f3STrond Myklebust 16729f06c719SChuck Lever static void 1673fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg, 1674fcc85819SChristoph Hellwig struct compound_hdr *hdr) 167523ec6965SJ. Bruce Fields { 16768687b63aSAl Viro __be32 *p; 167723ec6965SJ. Bruce Fields 1678ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1679ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 168013c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1681e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 168234558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 168313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 168434558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16858fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 168623ec6965SJ. Bruce Fields } 168723ec6965SJ. Bruce Fields 1688cf8cdbe5SAndy Adamson static void 1689d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16901da177e4SLinus Torvalds { 1691ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16921da177e4SLinus Torvalds } 16931da177e4SLinus Torvalds 1694cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16951da177e4SLinus Torvalds { 1696ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1697ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 169828cf22d0STrond Myklebust encode_attrs(xdr, arg->iap, arg->label, NULL, server, 169928cf22d0STrond Myklebust server->attr_bitmask); 17001da177e4SLinus Torvalds } 17011da177e4SLinus Torvalds 1702cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 17031da177e4SLinus Torvalds { 17048687b63aSAl Viro __be32 *p; 17051da177e4SLinus Torvalds 170670019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1707cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 17081da177e4SLinus Torvalds 17093a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 17103a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 171113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 171234558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 17131da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 17141da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 171513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 17163a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 17171da177e4SLinus Torvalds } 17181da177e4SLinus Torvalds 1719bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 17201da177e4SLinus Torvalds { 1721475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1722475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1723ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1724cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17251da177e4SLinus Torvalds } 17261da177e4SLinus Torvalds 17273c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17283c6b899cSAnna Schumaker struct compound_hdr *hdr) 17291da177e4SLinus Torvalds { 17308687b63aSAl Viro __be32 *p; 17311da177e4SLinus Torvalds 1732ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17339b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17341da177e4SLinus Torvalds 173513c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1736b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1737e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 173834558513SBenny Halevy *p = cpu_to_be32(args->count); 17391da177e4SLinus Torvalds 17401da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17411da177e4SLinus Torvalds } 17421da177e4SLinus Torvalds 1743cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17441da177e4SLinus Torvalds { 1745ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1746ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17471da177e4SLinus Torvalds } 17489b7b9fccSAndy Adamson 17495a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17505a5ea0d4SBryan Schumaker { 1751ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17526fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17535a5ea0d4SBryan Schumaker } 17545a5ea0d4SBryan Schumaker 175599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17569b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17577c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 1758fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args, 17597c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17607c44f1aeSWeston Andros Adamson { 17617c44f1aeSWeston Andros Adamson __be32 *p; 17627c44f1aeSWeston Andros Adamson 17637c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17647c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 176571a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17667c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 176771a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 176871a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17697c44f1aeSWeston Andros Adamson } 17707c44f1aeSWeston Andros Adamson 1771fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map) 17722031cd1aSWeston Andros Adamson { 17732031cd1aSWeston Andros Adamson unsigned int i; 17742031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17752031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17762031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17772031cd1aSWeston Andros Adamson } 17782031cd1aSWeston Andros Adamson 177999fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 1780fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args, 178199fe60d0SBenny Halevy struct compound_hdr *hdr) 178299fe60d0SBenny Halevy { 178399fe60d0SBenny Halevy __be32 *p; 1784d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1785db8ac8baSWeston Andros Adamson int len = 0; 178699fe60d0SBenny Halevy 178770019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1788fd40559cSTrond Myklebust encode_nfs4_verifier(xdr, &args->verifier); 178999fe60d0SBenny Halevy 17903a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17913a6bb738SJeff Layton args->client->cl_owner_id); 179299fe60d0SBenny Halevy 17932031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17942031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17952031cd1aSWeston Andros Adamson 17962031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17972031cd1aSWeston Andros Adamson case SP4_NONE: 17982031cd1aSWeston Andros Adamson break; 17992031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 18002031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 18012031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 18022031cd1aSWeston Andros Adamson break; 18032031cd1aSWeston Andros Adamson default: 18042031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 18052031cd1aSWeston Andros Adamson break; 18062031cd1aSWeston Andros Adamson } 1807db8ac8baSWeston Andros Adamson 1808db8ac8baSWeston Andros Adamson if (send_implementation_id && 1809db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1810db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1811d751f748SJim Rees <= sizeof(impl_name) + 1) 1812db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1813db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1814db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1815db8ac8baSWeston Andros Adamson 1816db8ac8baSWeston Andros Adamson if (len > 0) { 18172031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1818db8ac8baSWeston Andros Adamson 1819db8ac8baSWeston Andros Adamson encode_string(xdr, 1820db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1821db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1822db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1823db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1824db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1825db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1826db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1827db8ac8baSWeston Andros Adamson } else 18282031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 182999fe60d0SBenny Halevy } 1830fc931582SAndy Adamson 1831fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1832fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args, 1833fc931582SAndy Adamson struct compound_hdr *hdr) 1834fc931582SAndy Adamson { 1835fc931582SAndy Adamson __be32 *p; 1836fc931582SAndy Adamson struct nfs_client *clp = args->client; 183789f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1838f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18398e0d46e1SMike Sager u32 max_resp_sz_cached; 18408e0d46e1SMike Sager 18418e0d46e1SMike Sager /* 18428e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18438e0d46e1SMike Sager * 2 is the verifier. 18448e0d46e1SMike Sager */ 184535c036efSJ. Bruce Fields max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2) 184635c036efSJ. Bruce Fields * XDR_UNIT + RPC_MAX_AUTH_SIZE; 1847fc931582SAndy Adamson 1848475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 184989f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 185079969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 185179969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1852e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1853fc931582SAndy Adamson 1854fc931582SAndy Adamson /* Fore Channel */ 1855c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1856e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1857e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18588e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1859e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1860e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1861e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1862fc931582SAndy Adamson 1863fc931582SAndy Adamson /* Back Channel */ 1864c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1865e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1866e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1867e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1868e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1869e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1870e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1871fc931582SAndy Adamson 1872e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1873e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1874e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1875fc931582SAndy Adamson 1876fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18772f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 187889f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1879e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1880e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 188134558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1882fc931582SAndy Adamson } 18830f3e66c6SAndy Adamson 18840f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 1885fcc85819SChristoph Hellwig const struct nfs4_session *session, 18860f3e66c6SAndy Adamson struct compound_hdr *hdr) 18870f3e66c6SAndy Adamson { 1888475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1889475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18900f3e66c6SAndy Adamson } 189118019753SRicardo Labiaga 189266245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 189366245539STrond Myklebust uint64_t clientid, 189466245539STrond Myklebust struct compound_hdr *hdr) 189566245539STrond Myklebust { 189666245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 189766245539STrond Myklebust encode_uint64(xdr, clientid); 189866245539STrond Myklebust } 189966245539STrond Myklebust 190018019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 1901fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args, 190218019753SRicardo Labiaga struct compound_hdr *hdr) 190318019753SRicardo Labiaga { 1904475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1905475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 190618019753SRicardo Labiaga } 190799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 190899fe60d0SBenny Halevy 19099b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 19109b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 19119b7b9fccSAndy Adamson struct compound_hdr *hdr) 19129b7b9fccSAndy Adamson { 19139b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 19142b2fa717STrond Myklebust struct nfs4_session *session; 1915fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 19162b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1917fc01cea9SAndy Adamson __be32 *p; 19189b7b9fccSAndy Adamson 19192b2fa717STrond Myklebust tp = slot->table; 19202b2fa717STrond Myklebust session = tp->session; 19213bd2384aSChuck Lever if (!session) 19223bd2384aSChuck Lever return; 1923fc01cea9SAndy Adamson 1924475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1925fc01cea9SAndy Adamson 1926fc01cea9SAndy Adamson /* 1927fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1928fc01cea9SAndy Adamson */ 1929fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1930fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1931fc01cea9SAndy Adamson __func__, 1932fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1933fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1934fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1935fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19362b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1937fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1938475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 193993f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1940e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19412b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1942e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 194334558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19449b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19459b7b9fccSAndy Adamson } 19469b7b9fccSAndy Adamson 1947b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1948b1f69b75SAndy Adamson static void 1949b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1950b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1951b1f69b75SAndy Adamson struct compound_hdr *hdr) 1952b1f69b75SAndy Adamson { 1953b1f69b75SAndy Adamson __be32 *p; 1954b1f69b75SAndy Adamson 1955475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 195684c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1957b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1958b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1959b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1960f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 196184c9dee3SChristoph Hellwig 196284c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 196384c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19644e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1965b1f69b75SAndy Adamson } 1966b1f69b75SAndy Adamson 1967b1f69b75SAndy Adamson static void 1968b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1969b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1970b1f69b75SAndy Adamson struct compound_hdr *hdr) 1971b1f69b75SAndy Adamson { 1972b1f69b75SAndy Adamson __be32 *p; 1973b1f69b75SAndy Adamson 1974475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1975475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1976b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1977b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1978b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1979b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1980b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1981b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1982ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1983475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1984b1f69b75SAndy Adamson 1985b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1986b1f69b75SAndy Adamson __func__, 1987b1f69b75SAndy Adamson args->type, 1988b1f69b75SAndy Adamson args->range.iomode, 1989b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1990b1f69b75SAndy Adamson (unsigned long)args->range.length, 1991b1f69b75SAndy Adamson args->maxcount); 1992b1f69b75SAndy Adamson } 1993863a3c6cSAndy Adamson 1994863a3c6cSAndy Adamson static int 1995863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1996ac7db726SBenny Halevy struct inode *inode, 1997fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args, 1998863a3c6cSAndy Adamson struct compound_hdr *hdr) 1999863a3c6cSAndy Adamson { 2000863a3c6cSAndy Adamson __be32 *p; 2001863a3c6cSAndy Adamson 2002863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 2003863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 2004863a3c6cSAndy Adamson 2005475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 2006475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 2007863a3c6cSAndy Adamson /* Only whole file layouts */ 2008863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 20093557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 2010ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 2011ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20122e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 2013ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 2014863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 2015863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 20162e18d4d8STrond Myklebust } else { 20172e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 20182e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 20192e18d4d8STrond Myklebust } 2020863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2021863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2022ac7db726SBenny Halevy 20235f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 202473504740STrond Myklebust if (args->layoutupdate_pages) 20255f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20265f919c9fSChristoph Hellwig args->layoutupdate_len); 2027863a3c6cSAndy Adamson 2028863a3c6cSAndy Adamson return 0; 2029863a3c6cSAndy Adamson } 2030cbe82603SBenny Halevy 2031cbe82603SBenny Halevy static void 2032cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2033cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2034cbe82603SBenny Halevy struct compound_hdr *hdr) 2035cbe82603SBenny Halevy { 2036cbe82603SBenny Halevy __be32 *p; 2037cbe82603SBenny Halevy 2038475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2039475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2040cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2041cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 204215eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2043cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2044ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 204515eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 204615eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2047cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2048ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2049cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20504d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20514d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 205294e5c571STrond Myklebust else 2053475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2054cbe82603SBenny Halevy } 2055fca78d6dSBryan Schumaker 2056fca78d6dSBryan Schumaker static int 2057fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2058fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2059fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2060fca78d6dSBryan Schumaker { 2061475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2062475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2063fca78d6dSBryan Schumaker return 0; 2064fca78d6dSBryan Schumaker } 20657d974794SBryan Schumaker 20667d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 2067fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args, 20687d974794SBryan Schumaker struct compound_hdr *hdr) 20697d974794SBryan Schumaker { 2070475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2071475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2072ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20737d974794SBryan Schumaker } 20749aeda35fSBryan Schumaker 20759aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 2076fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args, 20779aeda35fSBryan Schumaker struct compound_hdr *hdr) 20789aeda35fSBryan Schumaker { 2079ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20807c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20819aeda35fSBryan Schumaker } 2082cf805165STrond Myklebust #else 2083cf805165STrond Myklebust static inline void 2084cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2085cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2086cf805165STrond Myklebust struct compound_hdr *hdr) 2087cf805165STrond Myklebust { 2088cf805165STrond Myklebust } 2089b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2090b1f69b75SAndy Adamson 20911da177e4SLinus Torvalds /* 20921da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20931da177e4SLinus Torvalds */ 20941da177e4SLinus Torvalds 209566cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 209666cc0429SBenny Halevy { 209766cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 20983bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 20993bd2384aSChuck Lever if (session) 21003bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 210166cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 210266cc0429SBenny Halevy return 0; 210366cc0429SBenny Halevy } 210466cc0429SBenny Halevy 21051da177e4SLinus Torvalds /* 21061da177e4SLinus Torvalds * Encode an ACCESS request 21071da177e4SLinus Torvalds */ 21089f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 2109fcc85819SChristoph Hellwig const void *data) 21101da177e4SLinus Torvalds { 2111fcc85819SChristoph Hellwig const struct nfs4_accessargs *args = data; 21121da177e4SLinus Torvalds struct compound_hdr hdr = { 211366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21141da177e4SLinus Torvalds }; 21151da177e4SLinus Torvalds 21169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21189f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21199f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21209f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2121d017931cSAndy Adamson encode_nops(&hdr); 21221da177e4SLinus Torvalds } 21231da177e4SLinus Torvalds 21241da177e4SLinus Torvalds /* 21251da177e4SLinus Torvalds * Encode LOOKUP request 21261da177e4SLinus Torvalds */ 21279f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 2128fcc85819SChristoph Hellwig const void *data) 21291da177e4SLinus Torvalds { 2130fcc85819SChristoph Hellwig const struct nfs4_lookup_arg *args = data; 21311da177e4SLinus Torvalds struct compound_hdr hdr = { 213266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21331da177e4SLinus Torvalds }; 21341da177e4SLinus Torvalds 21359f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21369f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21379f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21389f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21399f06c719SChuck Lever encode_getfh(xdr, &hdr); 21409f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2141d017931cSAndy Adamson encode_nops(&hdr); 21421da177e4SLinus Torvalds } 21431da177e4SLinus Torvalds 21441da177e4SLinus Torvalds /* 21455b5faaf6SJeff Layton * Encode LOOKUPP request 21465b5faaf6SJeff Layton */ 21475b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr, 21485b5faaf6SJeff Layton const void *data) 21495b5faaf6SJeff Layton { 21505b5faaf6SJeff Layton const struct nfs4_lookupp_arg *args = data; 21515b5faaf6SJeff Layton struct compound_hdr hdr = { 21525b5faaf6SJeff Layton .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21535b5faaf6SJeff Layton }; 21545b5faaf6SJeff Layton 21555b5faaf6SJeff Layton encode_compound_hdr(xdr, req, &hdr); 21565b5faaf6SJeff Layton encode_sequence(xdr, &args->seq_args, &hdr); 21575b5faaf6SJeff Layton encode_putfh(xdr, args->fh, &hdr); 21585b5faaf6SJeff Layton encode_lookupp(xdr, &hdr); 21595b5faaf6SJeff Layton encode_getfh(xdr, &hdr); 21605b5faaf6SJeff Layton encode_getfattr(xdr, args->bitmask, &hdr); 21615b5faaf6SJeff Layton encode_nops(&hdr); 21625b5faaf6SJeff Layton } 21635b5faaf6SJeff Layton 21645b5faaf6SJeff Layton /* 21651da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21661da177e4SLinus Torvalds */ 21679f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21689f06c719SChuck Lever struct xdr_stream *xdr, 2169fcc85819SChristoph Hellwig const void *data) 21701da177e4SLinus Torvalds { 2171fcc85819SChristoph Hellwig const struct nfs4_lookup_root_arg *args = data; 21721da177e4SLinus Torvalds struct compound_hdr hdr = { 217366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21741da177e4SLinus Torvalds }; 21751da177e4SLinus Torvalds 21769f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21779f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21789f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21799f06c719SChuck Lever encode_getfh(xdr, &hdr); 21809f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2181d017931cSAndy Adamson encode_nops(&hdr); 21821da177e4SLinus Torvalds } 21831da177e4SLinus Torvalds 21841da177e4SLinus Torvalds /* 21851da177e4SLinus Torvalds * Encode REMOVE request 21861da177e4SLinus Torvalds */ 21879f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 2188fcc85819SChristoph Hellwig const void *data) 21891da177e4SLinus Torvalds { 2190fcc85819SChristoph Hellwig const struct nfs_removeargs *args = data; 21911da177e4SLinus Torvalds struct compound_hdr hdr = { 219266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21931da177e4SLinus Torvalds }; 21941da177e4SLinus Torvalds 21959f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21969f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21979f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21989f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2199d017931cSAndy Adamson encode_nops(&hdr); 22001da177e4SLinus Torvalds } 22011da177e4SLinus Torvalds 22021da177e4SLinus Torvalds /* 22031da177e4SLinus Torvalds * Encode RENAME request 22041da177e4SLinus Torvalds */ 22059f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 2206fcc85819SChristoph Hellwig const void *data) 22071da177e4SLinus Torvalds { 2208fcc85819SChristoph Hellwig const struct nfs_renameargs *args = data; 22091da177e4SLinus Torvalds struct compound_hdr hdr = { 221066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22111da177e4SLinus Torvalds }; 22121da177e4SLinus Torvalds 22139f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22149f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22159f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 22169f06c719SChuck Lever encode_savefh(xdr, &hdr); 22179f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 22189f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2219d017931cSAndy Adamson encode_nops(&hdr); 22201da177e4SLinus Torvalds } 22211da177e4SLinus Torvalds 22221da177e4SLinus Torvalds /* 22231da177e4SLinus Torvalds * Encode LINK request 22241da177e4SLinus Torvalds */ 22259f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 2226fcc85819SChristoph Hellwig const void *data) 22271da177e4SLinus Torvalds { 2228fcc85819SChristoph Hellwig const struct nfs4_link_arg *args = data; 22291da177e4SLinus Torvalds struct compound_hdr hdr = { 223066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22311da177e4SLinus Torvalds }; 22321da177e4SLinus Torvalds 22339f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22349f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22359f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22369f06c719SChuck Lever encode_savefh(xdr, &hdr); 22379f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22389f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22399f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22409f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2241d017931cSAndy Adamson encode_nops(&hdr); 22421da177e4SLinus Torvalds } 22431da177e4SLinus Torvalds 22441da177e4SLinus Torvalds /* 22451da177e4SLinus Torvalds * Encode CREATE request 22461da177e4SLinus Torvalds */ 22479f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 2248fcc85819SChristoph Hellwig const void *data) 22491da177e4SLinus Torvalds { 2250fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 22511da177e4SLinus Torvalds struct compound_hdr hdr = { 225266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22531da177e4SLinus Torvalds }; 22541da177e4SLinus Torvalds 22559f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22569f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22579f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22589f06c719SChuck Lever encode_create(xdr, args, &hdr); 22599f06c719SChuck Lever encode_getfh(xdr, &hdr); 22609f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2261d017931cSAndy Adamson encode_nops(&hdr); 22621da177e4SLinus Torvalds } 22631da177e4SLinus Torvalds 22641da177e4SLinus Torvalds /* 22651da177e4SLinus Torvalds * Encode SYMLINK request 22661da177e4SLinus Torvalds */ 22679f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2268fcc85819SChristoph Hellwig const void *data) 22691da177e4SLinus Torvalds { 2270fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 2271fcc85819SChristoph Hellwig 22729f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22731da177e4SLinus Torvalds } 22741da177e4SLinus Torvalds 22751da177e4SLinus Torvalds /* 22761da177e4SLinus Torvalds * Encode GETATTR request 22771da177e4SLinus Torvalds */ 22789f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2279fcc85819SChristoph Hellwig const void *data) 22801da177e4SLinus Torvalds { 2281fcc85819SChristoph Hellwig const struct nfs4_getattr_arg *args = data; 22821da177e4SLinus Torvalds struct compound_hdr hdr = { 228366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22841da177e4SLinus Torvalds }; 22851da177e4SLinus Torvalds 22869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22889f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22899f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2290d017931cSAndy Adamson encode_nops(&hdr); 22911da177e4SLinus Torvalds } 22921da177e4SLinus Torvalds 22931da177e4SLinus Torvalds /* 22941da177e4SLinus Torvalds * Encode a CLOSE request 22951da177e4SLinus Torvalds */ 22969f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 2297fcc85819SChristoph Hellwig const void *data) 22981da177e4SLinus Torvalds { 2299fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 23001da177e4SLinus Torvalds struct compound_hdr hdr = { 230166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23021da177e4SLinus Torvalds }; 23031da177e4SLinus Torvalds 23049f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23059f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23069f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2307cf805165STrond Myklebust if (args->lr_args) 2308cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23093ecefc92STrond Myklebust if (args->bitmask != NULL) 23109f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2311d8d84983STrond Myklebust encode_close(xdr, args, &hdr); 2312d017931cSAndy Adamson encode_nops(&hdr); 23131da177e4SLinus Torvalds } 23141da177e4SLinus Torvalds 23151da177e4SLinus Torvalds /* 23161da177e4SLinus Torvalds * Encode an OPEN request 23171da177e4SLinus Torvalds */ 23189f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 2319fcc85819SChristoph Hellwig const void *data) 23201da177e4SLinus Torvalds { 2321fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23221da177e4SLinus Torvalds struct compound_hdr hdr = { 232366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23241da177e4SLinus Torvalds }; 23251da177e4SLinus Torvalds 23269f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23279f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23289f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23299f06c719SChuck Lever encode_open(xdr, args, &hdr); 23309f06c719SChuck Lever encode_getfh(xdr, &hdr); 2331ae2bb032SWeston Andros Adamson if (args->access) 23326168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 23331549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2334d017931cSAndy Adamson encode_nops(&hdr); 23351da177e4SLinus Torvalds } 23361da177e4SLinus Torvalds 23371da177e4SLinus Torvalds /* 23381da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 23391da177e4SLinus Torvalds */ 23409f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 23419f06c719SChuck Lever struct xdr_stream *xdr, 2342fcc85819SChristoph Hellwig const void *data) 23431da177e4SLinus Torvalds { 2344fcc85819SChristoph Hellwig const struct nfs_open_confirmargs *args = data; 23451da177e4SLinus Torvalds struct compound_hdr hdr = { 2346d017931cSAndy Adamson .nops = 0, 23471da177e4SLinus Torvalds }; 23481da177e4SLinus Torvalds 23499f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23509f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23519f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2352d017931cSAndy Adamson encode_nops(&hdr); 23531da177e4SLinus Torvalds } 23541da177e4SLinus Torvalds 23551da177e4SLinus Torvalds /* 23561da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23571da177e4SLinus Torvalds */ 23589f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23599f06c719SChuck Lever struct xdr_stream *xdr, 2360fcc85819SChristoph Hellwig const void *data) 23611da177e4SLinus Torvalds { 2362fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23631da177e4SLinus Torvalds struct compound_hdr hdr = { 236466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23651da177e4SLinus Torvalds }; 23661da177e4SLinus Torvalds 23679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23699f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23709f06c719SChuck Lever encode_open(xdr, args, &hdr); 2371ae2bb032SWeston Andros Adamson if (args->access) 23726168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2373e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2374d017931cSAndy Adamson encode_nops(&hdr); 23751da177e4SLinus Torvalds } 23761da177e4SLinus Torvalds 23771da177e4SLinus Torvalds /* 23781da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23791da177e4SLinus Torvalds */ 23809f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23819f06c719SChuck Lever struct xdr_stream *xdr, 2382fcc85819SChristoph Hellwig const void *data) 23831da177e4SLinus Torvalds { 2384fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 23851da177e4SLinus Torvalds struct compound_hdr hdr = { 238666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23871da177e4SLinus Torvalds }; 23881da177e4SLinus Torvalds 23899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23919f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2392b6808145STrond Myklebust if (args->lr_args) 2393b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23949f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2395d017931cSAndy Adamson encode_nops(&hdr); 23961da177e4SLinus Torvalds } 23971da177e4SLinus Torvalds 23981da177e4SLinus Torvalds /* 23991da177e4SLinus Torvalds * Encode a LOCK request 24001da177e4SLinus Torvalds */ 24019f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 2402fcc85819SChristoph Hellwig const void *data) 24031da177e4SLinus Torvalds { 2404fcc85819SChristoph Hellwig const struct nfs_lock_args *args = data; 24051da177e4SLinus Torvalds struct compound_hdr hdr = { 240666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24071da177e4SLinus Torvalds }; 24081da177e4SLinus Torvalds 24099f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24109f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24119f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24129f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2413d017931cSAndy Adamson encode_nops(&hdr); 24141da177e4SLinus Torvalds } 24151da177e4SLinus Torvalds 24161da177e4SLinus Torvalds /* 24171da177e4SLinus Torvalds * Encode a LOCKT request 24181da177e4SLinus Torvalds */ 24199f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 2420fcc85819SChristoph Hellwig const void *data) 24211da177e4SLinus Torvalds { 2422fcc85819SChristoph Hellwig const struct nfs_lockt_args *args = data; 24231da177e4SLinus Torvalds struct compound_hdr hdr = { 242466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24251da177e4SLinus Torvalds }; 24261da177e4SLinus Torvalds 24279f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24289f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24299f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24309f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2431d017931cSAndy Adamson encode_nops(&hdr); 24321da177e4SLinus Torvalds } 24331da177e4SLinus Torvalds 24341da177e4SLinus Torvalds /* 24351da177e4SLinus Torvalds * Encode a LOCKU request 24361da177e4SLinus Torvalds */ 24379f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 2438fcc85819SChristoph Hellwig const void *data) 24391da177e4SLinus Torvalds { 2440fcc85819SChristoph Hellwig const struct nfs_locku_args *args = data; 24411da177e4SLinus Torvalds struct compound_hdr hdr = { 244266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24431da177e4SLinus Torvalds }; 24441da177e4SLinus Torvalds 24459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24479f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24489f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2449d017931cSAndy Adamson encode_nops(&hdr); 24501da177e4SLinus Torvalds } 24511da177e4SLinus Torvalds 24529f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24539f06c719SChuck Lever struct xdr_stream *xdr, 2454fcc85819SChristoph Hellwig const void *data) 2455d3c7b7ccSTrond Myklebust { 2456fcc85819SChristoph Hellwig const struct nfs_release_lockowner_args *args = data; 2457d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2458d3c7b7ccSTrond Myklebust .minorversion = 0, 2459d3c7b7ccSTrond Myklebust }; 2460d3c7b7ccSTrond Myklebust 24619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24629f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2463d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2464d3c7b7ccSTrond Myklebust } 2465d3c7b7ccSTrond Myklebust 24661da177e4SLinus Torvalds /* 24671da177e4SLinus Torvalds * Encode a READLINK request 24681da177e4SLinus Torvalds */ 24699f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2470fcc85819SChristoph Hellwig const void *data) 24711da177e4SLinus Torvalds { 2472fcc85819SChristoph Hellwig const struct nfs4_readlink *args = data; 24731da177e4SLinus Torvalds struct compound_hdr hdr = { 247466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24751da177e4SLinus Torvalds }; 24761da177e4SLinus Torvalds 24779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24789f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24799f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24809f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2481e3a535e1STrond Myklebust 248228f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2483e3a535e1STrond Myklebust args->pgbase, args->pglen); 2484d017931cSAndy Adamson encode_nops(&hdr); 24851da177e4SLinus Torvalds } 24861da177e4SLinus Torvalds 24871da177e4SLinus Torvalds /* 24881da177e4SLinus Torvalds * Encode a READDIR request 24891da177e4SLinus Torvalds */ 24909f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 2491fcc85819SChristoph Hellwig const void *data) 24921da177e4SLinus Torvalds { 2493fcc85819SChristoph Hellwig const struct nfs4_readdir_arg *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_readdir(xdr, args, req, &hdr); 2502d6ac02dfSTrond Myklebust 250328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2504d6ac02dfSTrond Myklebust args->pgbase, args->count); 2505d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 250628f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2507d6ac02dfSTrond Myklebust args->pgbase, args->count); 2508d017931cSAndy Adamson encode_nops(&hdr); 25091da177e4SLinus Torvalds } 25101da177e4SLinus Torvalds 25111da177e4SLinus Torvalds /* 25121da177e4SLinus Torvalds * Encode a READ request 25131da177e4SLinus Torvalds */ 25149f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 2515fcc85819SChristoph Hellwig const void *data) 25161da177e4SLinus Torvalds { 2517fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 25181da177e4SLinus Torvalds struct compound_hdr hdr = { 251966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25201da177e4SLinus Torvalds }; 25211da177e4SLinus Torvalds 25229f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25239f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25249f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25259f06c719SChuck Lever encode_read(xdr, args, &hdr); 25261da177e4SLinus Torvalds 252728f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 25281da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 25294f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2530d017931cSAndy Adamson encode_nops(&hdr); 25311da177e4SLinus Torvalds } 25321da177e4SLinus Torvalds 25331da177e4SLinus Torvalds /* 25341da177e4SLinus Torvalds * Encode an SETATTR request 25351da177e4SLinus Torvalds */ 25369f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2537fcc85819SChristoph Hellwig const void *data) 25381da177e4SLinus Torvalds { 2539fcc85819SChristoph Hellwig const struct nfs_setattrargs *args = data; 25401da177e4SLinus Torvalds struct compound_hdr hdr = { 254166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25421da177e4SLinus Torvalds }; 25431da177e4SLinus Torvalds 25449f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25459f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25469f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25479f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 25489f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2549d017931cSAndy Adamson encode_nops(&hdr); 25501da177e4SLinus Torvalds } 25511da177e4SLinus Torvalds 25521da177e4SLinus Torvalds /* 2553029d105eSJ. Bruce Fields * Encode a GETACL request 2554029d105eSJ. Bruce Fields */ 25559f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2556fcc85819SChristoph Hellwig const void *data) 2557029d105eSJ. Bruce Fields { 2558fcc85819SChristoph Hellwig const struct nfs_getaclargs *args = data; 2559029d105eSJ. Bruce Fields struct compound_hdr hdr = { 256066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2561029d105eSJ. Bruce Fields }; 256228f56694SBenny Halevy uint32_t replen; 2563029d105eSJ. Bruce Fields 25649f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25659f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25669f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25676682c14bSJ. Bruce Fields replen = hdr.replen + op_decode_hdr_maxsz; 25689f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2569cf8cdbe5SAndy Adamson 257028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 25718fbcf237SAndreas Gruenbacher args->acl_pages, 0, args->acl_len); 2572bf118a34SAndy Adamson 2573d017931cSAndy Adamson encode_nops(&hdr); 2574029d105eSJ. Bruce Fields } 2575029d105eSJ. Bruce Fields 2576029d105eSJ. Bruce Fields /* 25771da177e4SLinus Torvalds * Encode a WRITE request 25781da177e4SLinus Torvalds */ 25799f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 2580fcc85819SChristoph Hellwig const void *data) 25811da177e4SLinus Torvalds { 2582fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 25831da177e4SLinus Torvalds struct compound_hdr hdr = { 258466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25851da177e4SLinus Torvalds }; 25861da177e4SLinus Torvalds 25879f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25889f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25899f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25909f06c719SChuck Lever encode_write(xdr, args, &hdr); 25914f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25927ffd1064SFred Isaman if (args->bitmask) 25939f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2594d017931cSAndy Adamson encode_nops(&hdr); 25951da177e4SLinus Torvalds } 25961da177e4SLinus Torvalds 25971da177e4SLinus Torvalds /* 25981da177e4SLinus Torvalds * a COMMIT request 25991da177e4SLinus Torvalds */ 26009f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 2601fcc85819SChristoph Hellwig const void *data) 26021da177e4SLinus Torvalds { 2603fcc85819SChristoph Hellwig const struct nfs_commitargs *args = data; 26041da177e4SLinus Torvalds struct compound_hdr hdr = { 260566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26061da177e4SLinus Torvalds }; 26071da177e4SLinus Torvalds 26089f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26099f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26109f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26119f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2612d017931cSAndy Adamson encode_nops(&hdr); 26131da177e4SLinus Torvalds } 26141da177e4SLinus Torvalds 26151da177e4SLinus Torvalds /* 26161da177e4SLinus Torvalds * FSINFO request 26171da177e4SLinus Torvalds */ 26189f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 2619fcc85819SChristoph Hellwig const void *data) 26201da177e4SLinus Torvalds { 2621fcc85819SChristoph Hellwig const struct nfs4_fsinfo_arg *args = data; 26221da177e4SLinus Torvalds struct compound_hdr hdr = { 262366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26241da177e4SLinus Torvalds }; 26251da177e4SLinus Torvalds 26269f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26279f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26289f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26299f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2630d017931cSAndy Adamson encode_nops(&hdr); 26311da177e4SLinus Torvalds } 26321da177e4SLinus Torvalds 26331da177e4SLinus Torvalds /* 26341da177e4SLinus Torvalds * a PATHCONF request 26351da177e4SLinus Torvalds */ 26369f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 2637fcc85819SChristoph Hellwig const void *data) 26381da177e4SLinus Torvalds { 2639fcc85819SChristoph Hellwig const struct nfs4_pathconf_arg *args = data; 26401da177e4SLinus Torvalds struct compound_hdr hdr = { 264166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26421da177e4SLinus Torvalds }; 26431da177e4SLinus Torvalds 26449f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26459f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26469f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26479f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2648d017931cSAndy Adamson &hdr); 2649d017931cSAndy Adamson encode_nops(&hdr); 26501da177e4SLinus Torvalds } 26511da177e4SLinus Torvalds 26521da177e4SLinus Torvalds /* 26531da177e4SLinus Torvalds * a STATFS request 26541da177e4SLinus Torvalds */ 26559f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 2656fcc85819SChristoph Hellwig const void *data) 26571da177e4SLinus Torvalds { 2658fcc85819SChristoph Hellwig const struct nfs4_statfs_arg *args = data; 26591da177e4SLinus Torvalds struct compound_hdr hdr = { 266066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26611da177e4SLinus Torvalds }; 26621da177e4SLinus Torvalds 26639f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26649f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26659f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26669f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2667d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2668d017931cSAndy Adamson encode_nops(&hdr); 26691da177e4SLinus Torvalds } 26701da177e4SLinus Torvalds 26711da177e4SLinus Torvalds /* 26721da177e4SLinus Torvalds * GETATTR_BITMAP request 26731da177e4SLinus Torvalds */ 26749f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26759f06c719SChuck Lever struct xdr_stream *xdr, 2676fcc85819SChristoph Hellwig const void *data) 26771da177e4SLinus Torvalds { 2678fcc85819SChristoph Hellwig const struct nfs4_server_caps_arg *args = data; 26798c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 26801da177e4SLinus Torvalds struct compound_hdr hdr = { 268166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26821da177e4SLinus Torvalds }; 26831da177e4SLinus Torvalds 26849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26859f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26869f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26878c61282fSKinglong Mee encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr); 2688d017931cSAndy Adamson encode_nops(&hdr); 26891da177e4SLinus Torvalds } 26901da177e4SLinus Torvalds 26911da177e4SLinus Torvalds /* 26921da177e4SLinus Torvalds * a RENEW request 26931da177e4SLinus Torvalds */ 26949f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 2695fcc85819SChristoph Hellwig const void *data) 2696fcc85819SChristoph Hellwig 26971da177e4SLinus Torvalds { 2698fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 26991da177e4SLinus Torvalds struct compound_hdr hdr = { 2700d017931cSAndy Adamson .nops = 0, 27011da177e4SLinus Torvalds }; 27021da177e4SLinus Torvalds 27039f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2704bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2705d017931cSAndy Adamson encode_nops(&hdr); 27061da177e4SLinus Torvalds } 27071da177e4SLinus Torvalds 27081da177e4SLinus Torvalds /* 27091da177e4SLinus Torvalds * a SETCLIENTID request 27101da177e4SLinus Torvalds */ 27119f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 27129f06c719SChuck Lever struct xdr_stream *xdr, 2713fcc85819SChristoph Hellwig const void *data) 27141da177e4SLinus Torvalds { 2715fcc85819SChristoph Hellwig const struct nfs4_setclientid *sc = data; 27161da177e4SLinus Torvalds struct compound_hdr hdr = { 2717d017931cSAndy Adamson .nops = 0, 27181da177e4SLinus Torvalds }; 27191da177e4SLinus Torvalds 27209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27219f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2722d017931cSAndy Adamson encode_nops(&hdr); 27231da177e4SLinus Torvalds } 27241da177e4SLinus Torvalds 27251da177e4SLinus Torvalds /* 27261da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 27271da177e4SLinus Torvalds */ 27289f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 27299f06c719SChuck Lever struct xdr_stream *xdr, 2730fcc85819SChristoph Hellwig const void *data) 27311da177e4SLinus Torvalds { 2732fcc85819SChristoph Hellwig const struct nfs4_setclientid_res *arg = data; 27331da177e4SLinus Torvalds struct compound_hdr hdr = { 2734d017931cSAndy Adamson .nops = 0, 27351da177e4SLinus Torvalds }; 27361da177e4SLinus Torvalds 27379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27389f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2739d017931cSAndy Adamson encode_nops(&hdr); 27401da177e4SLinus Torvalds } 27411da177e4SLinus Torvalds 27421da177e4SLinus Torvalds /* 27431da177e4SLinus Torvalds * DELEGRETURN request 27441da177e4SLinus Torvalds */ 27459f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 27469f06c719SChuck Lever struct xdr_stream *xdr, 2747fcc85819SChristoph Hellwig const void *data) 27481da177e4SLinus Torvalds { 2749fcc85819SChristoph Hellwig const struct nfs4_delegreturnargs *args = data; 27501da177e4SLinus Torvalds struct compound_hdr hdr = { 275166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27521da177e4SLinus Torvalds }; 27531da177e4SLinus Torvalds 27549f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27559f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27569f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2757586f1c39STrond Myklebust if (args->lr_args) 2758586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 27598ac2b422STrond Myklebust if (args->bitmask) 27609f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2761e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2762d017931cSAndy Adamson encode_nops(&hdr); 27631da177e4SLinus Torvalds } 27641da177e4SLinus Torvalds 27651da177e4SLinus Torvalds /* 2766683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2767683b57b4STrond Myklebust */ 27689f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27699f06c719SChuck Lever struct xdr_stream *xdr, 2770fcc85819SChristoph Hellwig const void *data) 2771683b57b4STrond Myklebust { 2772fcc85819SChristoph Hellwig const struct nfs4_fs_locations_arg *args = data; 2773683b57b4STrond Myklebust struct compound_hdr hdr = { 277466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2775683b57b4STrond Myklebust }; 277628f56694SBenny Halevy uint32_t replen; 2777683b57b4STrond Myklebust 27789f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27799f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2780b03d735bSChuck Lever if (args->migration) { 2781b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2782b03d735bSChuck Lever replen = hdr.replen; 2783b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2784b03d735bSChuck Lever if (args->renew) 2785b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2786b03d735bSChuck Lever } else { 27879f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 27889f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2789b03d735bSChuck Lever replen = hdr.replen; 27909f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2791b03d735bSChuck Lever } 2792cf8cdbe5SAndy Adamson 2793b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 2794fcc85819SChristoph Hellwig xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2795fcc85819SChristoph Hellwig (struct page **)&args->page, 0, PAGE_SIZE); 2796d017931cSAndy Adamson encode_nops(&hdr); 2797683b57b4STrond Myklebust } 2798683b57b4STrond Myklebust 27995a5ea0d4SBryan Schumaker /* 28005a5ea0d4SBryan Schumaker * Encode SECINFO request 28015a5ea0d4SBryan Schumaker */ 28025a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 28035a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 2804fcc85819SChristoph Hellwig const void *data) 28055a5ea0d4SBryan Schumaker { 2806fcc85819SChristoph Hellwig const struct nfs4_secinfo_arg *args = data; 28075a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 28085a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28095a5ea0d4SBryan Schumaker }; 28105a5ea0d4SBryan Schumaker 28115a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 28125a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 28135a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 28145a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 28155a5ea0d4SBryan Schumaker encode_nops(&hdr); 28165a5ea0d4SBryan Schumaker } 28175a5ea0d4SBryan Schumaker 281844c99933SChuck Lever /* 281944c99933SChuck Lever * Encode FSID_PRESENT request 282044c99933SChuck Lever */ 282144c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 282244c99933SChuck Lever struct xdr_stream *xdr, 2823fcc85819SChristoph Hellwig const void *data) 282444c99933SChuck Lever { 2825fcc85819SChristoph Hellwig const struct nfs4_fsid_present_arg *args = data; 282644c99933SChuck Lever struct compound_hdr hdr = { 282744c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 282844c99933SChuck Lever }; 282944c99933SChuck Lever 283044c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 283144c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 283244c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 283344c99933SChuck Lever encode_getfh(xdr, &hdr); 283444c99933SChuck Lever if (args->renew) 283544c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 283644c99933SChuck Lever encode_nops(&hdr); 283744c99933SChuck Lever } 283844c99933SChuck Lever 283999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 284099fe60d0SBenny Halevy /* 28417c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 28427c44f1aeSWeston Andros Adamson */ 28437c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 28447c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 2845fcc85819SChristoph Hellwig const void *data) 28467c44f1aeSWeston Andros Adamson { 2847fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args = data; 28487c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 284971a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 28507c44f1aeSWeston Andros Adamson }; 28517c44f1aeSWeston Andros Adamson 28527c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 285371a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 28547c44f1aeSWeston Andros Adamson encode_nops(&hdr); 28557c44f1aeSWeston Andros Adamson } 28567c44f1aeSWeston Andros Adamson 28577c44f1aeSWeston Andros Adamson /* 285899fe60d0SBenny Halevy * EXCHANGE_ID request 285999fe60d0SBenny Halevy */ 28609f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 28619f06c719SChuck Lever struct xdr_stream *xdr, 2862fcc85819SChristoph Hellwig const void *data) 286399fe60d0SBenny Halevy { 2864fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args = data; 286599fe60d0SBenny Halevy struct compound_hdr hdr = { 2866a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 286799fe60d0SBenny Halevy }; 286899fe60d0SBenny Halevy 28699f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28709f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 287199fe60d0SBenny Halevy encode_nops(&hdr); 287299fe60d0SBenny Halevy } 28732050f0ccSAndy Adamson 28742050f0ccSAndy Adamson /* 2875fc931582SAndy Adamson * a CREATE_SESSION request 2876fc931582SAndy Adamson */ 28779f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28789f06c719SChuck Lever struct xdr_stream *xdr, 2879fcc85819SChristoph Hellwig const void *data) 2880fc931582SAndy Adamson { 2881fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args = data; 2882fc931582SAndy Adamson struct compound_hdr hdr = { 2883a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2884fc931582SAndy Adamson }; 2885fc931582SAndy Adamson 28869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28879f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2888fc931582SAndy Adamson encode_nops(&hdr); 2889fc931582SAndy Adamson } 2890fc931582SAndy Adamson 2891fc931582SAndy Adamson /* 28920f3e66c6SAndy Adamson * a DESTROY_SESSION request 28930f3e66c6SAndy Adamson */ 28949f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 28959f06c719SChuck Lever struct xdr_stream *xdr, 2896fcc85819SChristoph Hellwig const void *data) 28970f3e66c6SAndy Adamson { 2898fcc85819SChristoph Hellwig const struct nfs4_session *session = data; 28990f3e66c6SAndy Adamson struct compound_hdr hdr = { 2900a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 29010f3e66c6SAndy Adamson }; 29020f3e66c6SAndy Adamson 29039f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29049f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 29050f3e66c6SAndy Adamson encode_nops(&hdr); 29060f3e66c6SAndy Adamson } 29070f3e66c6SAndy Adamson 29080f3e66c6SAndy Adamson /* 290966245539STrond Myklebust * a DESTROY_CLIENTID request 291066245539STrond Myklebust */ 291166245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 291266245539STrond Myklebust struct xdr_stream *xdr, 2913fcc85819SChristoph Hellwig const void *data) 291466245539STrond Myklebust { 2915fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 291666245539STrond Myklebust struct compound_hdr hdr = { 291766245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 291866245539STrond Myklebust }; 291966245539STrond Myklebust 292066245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 292166245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 292266245539STrond Myklebust encode_nops(&hdr); 292366245539STrond Myklebust } 292466245539STrond Myklebust 292566245539STrond Myklebust /* 2926fc01cea9SAndy Adamson * a SEQUENCE request 2927fc01cea9SAndy Adamson */ 29289f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2929fcc85819SChristoph Hellwig const void *data) 2930fc01cea9SAndy Adamson { 2931fcc85819SChristoph Hellwig const struct nfs4_sequence_args *args = data; 2932fc01cea9SAndy Adamson struct compound_hdr hdr = { 2933fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2934fc01cea9SAndy Adamson }; 2935fc01cea9SAndy Adamson 29369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29379f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2938fc01cea9SAndy Adamson encode_nops(&hdr); 2939fc01cea9SAndy Adamson } 2940fc01cea9SAndy Adamson 2941fc01cea9SAndy Adamson /* 29422050f0ccSAndy Adamson * a GET_LEASE_TIME request 29432050f0ccSAndy Adamson */ 29449f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 29459f06c719SChuck Lever struct xdr_stream *xdr, 2946fcc85819SChristoph Hellwig const void *data) 29472050f0ccSAndy Adamson { 2948fcc85819SChristoph Hellwig const struct nfs4_get_lease_time_args *args = data; 29492050f0ccSAndy Adamson struct compound_hdr hdr = { 29502050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 29512050f0ccSAndy Adamson }; 2952dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 29532050f0ccSAndy Adamson 29549f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29559f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 29569f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 29579f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 29582050f0ccSAndy Adamson encode_nops(&hdr); 29592050f0ccSAndy Adamson } 296018019753SRicardo Labiaga 296118019753SRicardo Labiaga /* 296218019753SRicardo Labiaga * a RECLAIM_COMPLETE request 296318019753SRicardo Labiaga */ 29649f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 29659f06c719SChuck Lever struct xdr_stream *xdr, 2966fcc85819SChristoph Hellwig const void *data) 296718019753SRicardo Labiaga { 2968fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args = data; 296918019753SRicardo Labiaga struct compound_hdr hdr = { 297018019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 297118019753SRicardo Labiaga }; 297218019753SRicardo Labiaga 29739f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29749f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29759f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 297618019753SRicardo Labiaga encode_nops(&hdr); 297718019753SRicardo Labiaga } 297818019753SRicardo Labiaga 2979b1f69b75SAndy Adamson /* 2980b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2981b1f69b75SAndy Adamson */ 29829f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 29839f06c719SChuck Lever struct xdr_stream *xdr, 2984fcc85819SChristoph Hellwig const void *data) 2985b1f69b75SAndy Adamson { 2986fcc85819SChristoph Hellwig const struct nfs4_getdeviceinfo_args *args = data; 2987b1f69b75SAndy Adamson struct compound_hdr hdr = { 2988b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2989b1f69b75SAndy Adamson }; 2990b1f69b75SAndy Adamson 29919f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29929f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29939f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2994b1f69b75SAndy Adamson 2995b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2996b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2997b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2998b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2999b1f69b75SAndy Adamson args->pdev->pglen); 3000b1f69b75SAndy Adamson 3001b1f69b75SAndy Adamson encode_nops(&hdr); 3002b1f69b75SAndy Adamson } 3003b1f69b75SAndy Adamson 3004b1f69b75SAndy Adamson /* 3005b1f69b75SAndy Adamson * Encode LAYOUTGET request 3006b1f69b75SAndy Adamson */ 30079f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 30089f06c719SChuck Lever struct xdr_stream *xdr, 3009fcc85819SChristoph Hellwig const void *data) 3010b1f69b75SAndy Adamson { 3011fcc85819SChristoph Hellwig const struct nfs4_layoutget_args *args = data; 3012b1f69b75SAndy Adamson struct compound_hdr hdr = { 3013b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3014b1f69b75SAndy Adamson }; 3015b1f69b75SAndy Adamson 30169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 30179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 30189f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 30199f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 302035124a09SWeston Andros Adamson 302135124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 302235124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 302335124a09SWeston Andros Adamson 3024b1f69b75SAndy Adamson encode_nops(&hdr); 3025b1f69b75SAndy Adamson } 3026863a3c6cSAndy Adamson 3027863a3c6cSAndy Adamson /* 3028863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 3029863a3c6cSAndy Adamson */ 3030cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 3031863a3c6cSAndy Adamson struct xdr_stream *xdr, 3032fcc85819SChristoph Hellwig const void *priv) 3033863a3c6cSAndy Adamson { 3034fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args = priv; 3035ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 3036ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 3037863a3c6cSAndy Adamson struct compound_hdr hdr = { 3038863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3039863a3c6cSAndy Adamson }; 3040863a3c6cSAndy Adamson 3041863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 3042863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 3043863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3044ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 3045863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 3046863a3c6cSAndy Adamson encode_nops(&hdr); 3047cbe82603SBenny Halevy } 3048cbe82603SBenny Halevy 3049cbe82603SBenny Halevy /* 3050cbe82603SBenny Halevy * Encode LAYOUTRETURN request 3051cbe82603SBenny Halevy */ 3052cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 3053cbe82603SBenny Halevy struct xdr_stream *xdr, 3054fcc85819SChristoph Hellwig const void *data) 3055cbe82603SBenny Halevy { 3056fcc85819SChristoph Hellwig const struct nfs4_layoutreturn_args *args = data; 3057cbe82603SBenny Halevy struct compound_hdr hdr = { 3058cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3059cbe82603SBenny Halevy }; 3060cbe82603SBenny Halevy 3061cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 3062cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 3063cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3064cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 3065cbe82603SBenny Halevy encode_nops(&hdr); 3066863a3c6cSAndy Adamson } 3067fca78d6dSBryan Schumaker 3068fca78d6dSBryan Schumaker /* 3069fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 3070fca78d6dSBryan Schumaker */ 3071fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 3072fca78d6dSBryan Schumaker struct xdr_stream *xdr, 3073fcc85819SChristoph Hellwig const void *data) 3074fca78d6dSBryan Schumaker { 3075fcc85819SChristoph Hellwig const struct nfs41_secinfo_no_name_args *args = data; 3076fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3077fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3078fca78d6dSBryan Schumaker }; 3079fca78d6dSBryan Schumaker 3080fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3081fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3082fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3083fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3084fca78d6dSBryan Schumaker encode_nops(&hdr); 3085fca78d6dSBryan Schumaker } 30867d974794SBryan Schumaker 30877d974794SBryan Schumaker /* 30887d974794SBryan Schumaker * Encode TEST_STATEID request 30897d974794SBryan Schumaker */ 30907d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 30917d974794SBryan Schumaker struct xdr_stream *xdr, 3092fcc85819SChristoph Hellwig const void *data) 30937d974794SBryan Schumaker { 3094fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args = data; 30957d974794SBryan Schumaker struct compound_hdr hdr = { 30967d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30977d974794SBryan Schumaker }; 30987d974794SBryan Schumaker 30997d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31007d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31017d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 31027d974794SBryan Schumaker encode_nops(&hdr); 31037d974794SBryan Schumaker } 31049aeda35fSBryan Schumaker 31059aeda35fSBryan Schumaker /* 31069aeda35fSBryan Schumaker * Encode FREE_STATEID request 31079aeda35fSBryan Schumaker */ 31089aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 31099aeda35fSBryan Schumaker struct xdr_stream *xdr, 3110fcc85819SChristoph Hellwig const void *data) 31119aeda35fSBryan Schumaker { 3112fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args = data; 31139aeda35fSBryan Schumaker struct compound_hdr hdr = { 31149aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 31159aeda35fSBryan Schumaker }; 31169aeda35fSBryan Schumaker 31179aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31189aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31199aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 31209aeda35fSBryan Schumaker encode_nops(&hdr); 31219aeda35fSBryan Schumaker } 312299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 312399fe60d0SBenny Halevy 3124686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3125686841b3SBenny Halevy { 3126686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3127686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3128686841b3SBenny Halevy func, xdr->end - xdr->p); 3129686841b3SBenny Halevy } 31301da177e4SLinus Torvalds 3131683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 31321da177e4SLinus Torvalds { 31336da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, 31346da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT); 31356da59ce2STrond Myklebust if (unlikely(ret < 0)) { 31366da59ce2STrond Myklebust if (ret == -EBADMSG) 3137c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3138c0eae66eSBenny Halevy return -EIO; 31391da177e4SLinus Torvalds } 31406da59ce2STrond Myklebust *len = ret; 31416da59ce2STrond Myklebust return 0; 31426da59ce2STrond Myklebust } 31431da177e4SLinus Torvalds 31441da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 31451da177e4SLinus Torvalds { 31468687b63aSAl Viro __be32 *p; 31471da177e4SLinus Torvalds 3148c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3149c0eae66eSBenny Halevy if (unlikely(!p)) 3150c0eae66eSBenny Halevy goto out_overflow; 31516f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3152cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 31531da177e4SLinus Torvalds 3154c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3155c0eae66eSBenny Halevy if (unlikely(!p)) 3156c0eae66eSBenny Halevy goto out_overflow; 31571da177e4SLinus Torvalds hdr->tag = (char *)p; 31581da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3159cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3160aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3161aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 31621da177e4SLinus Torvalds return 0; 3163c0eae66eSBenny Halevy out_overflow: 3164c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3165c0eae66eSBenny Halevy return -EIO; 31661da177e4SLinus Torvalds } 31671da177e4SLinus Torvalds 3168c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3169c7848f69STrond Myklebust int *nfs_retval) 31701da177e4SLinus Torvalds { 31718687b63aSAl Viro __be32 *p; 31721da177e4SLinus Torvalds uint32_t opnum; 31731da177e4SLinus Torvalds int32_t nfserr; 31741da177e4SLinus Torvalds 3175c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3176c0eae66eSBenny Halevy if (unlikely(!p)) 3177c0eae66eSBenny Halevy goto out_overflow; 31786f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3179c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3180c7848f69STrond Myklebust goto out_bad_operation; 3181c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3182c7848f69STrond Myklebust if (nfserr == NFS_OK) 3183c7848f69STrond Myklebust *nfs_retval = 0; 3184c7848f69STrond Myklebust else 3185c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3186c7848f69STrond Myklebust return true; 3187c7848f69STrond Myklebust out_bad_operation: 3188fe82a183SChuck Lever dprintk("nfs: Server returned operation" 31891da177e4SLinus Torvalds " %d but we issued a request for %d\n", 31901da177e4SLinus Torvalds opnum, expected); 3191c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3192c7848f69STrond Myklebust return false; 3193c0eae66eSBenny Halevy out_overflow: 3194c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3195c7848f69STrond Myklebust *nfs_retval = -EIO; 3196c7848f69STrond Myklebust return false; 3197c7848f69STrond Myklebust } 3198c7848f69STrond Myklebust 3199c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3200c7848f69STrond Myklebust { 3201c7848f69STrond Myklebust int retval; 3202c7848f69STrond Myklebust 3203c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3204c7848f69STrond Myklebust return retval; 32051da177e4SLinus Torvalds } 32061da177e4SLinus Torvalds 32071da177e4SLinus Torvalds /* Dummy routine */ 32081bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace) 32091da177e4SLinus Torvalds { 32108687b63aSAl Viro __be32 *p; 3211683b57b4STrond Myklebust unsigned int strlen; 32121da177e4SLinus Torvalds char *str; 32131da177e4SLinus Torvalds 3214c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3215c0eae66eSBenny Halevy if (likely(p)) 32161da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3217c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3218c0eae66eSBenny Halevy return -EIO; 32191da177e4SLinus Torvalds } 32201da177e4SLinus Torvalds 32211da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 32221da177e4SLinus Torvalds { 32238687b63aSAl Viro uint32_t bmlen; 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 bmlen = be32_to_cpup(p); 32301da177e4SLinus Torvalds 3231dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3232c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3233c0eae66eSBenny Halevy if (unlikely(!p)) 3234c0eae66eSBenny Halevy goto out_overflow; 32351da177e4SLinus Torvalds if (bmlen > 0) { 32366f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3237dae100c2SFred Isaman if (bmlen > 1) { 3238dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3239dae100c2SFred Isaman if (bmlen > 2) 3240dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3241dae100c2SFred Isaman } 32421da177e4SLinus Torvalds } 32431da177e4SLinus Torvalds return 0; 3244c0eae66eSBenny Halevy out_overflow: 3245c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3246c0eae66eSBenny Halevy return -EIO; 32471da177e4SLinus Torvalds } 32481da177e4SLinus Torvalds 3249256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 32501da177e4SLinus Torvalds { 32518687b63aSAl Viro __be32 *p; 32521da177e4SLinus Torvalds 3253c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3254c0eae66eSBenny Halevy if (unlikely(!p)) 3255c0eae66eSBenny Halevy goto out_overflow; 3256cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3257256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 32581da177e4SLinus Torvalds return 0; 3259c0eae66eSBenny Halevy out_overflow: 3260c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3261c0eae66eSBenny Halevy return -EIO; 32621da177e4SLinus Torvalds } 32631da177e4SLinus Torvalds 32641da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 32651da177e4SLinus Torvalds { 32661da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 32673388bff5SRoman Borisov int ret; 32683388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 32693388bff5SRoman Borisov if (unlikely(ret < 0)) 32703388bff5SRoman Borisov return ret; 32711da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 32721da177e4SLinus Torvalds } else 3273dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3274dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3275dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 32761da177e4SLinus Torvalds return 0; 32771da177e4SLinus Torvalds } 32781da177e4SLinus Torvalds 32791da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32801da177e4SLinus Torvalds { 32818687b63aSAl Viro __be32 *p; 3282409924e4STrond Myklebust int ret = 0; 32831da177e4SLinus Torvalds 32841da177e4SLinus Torvalds *type = 0; 32851da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32861da177e4SLinus Torvalds return -EIO; 32871da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3288c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3289c0eae66eSBenny Halevy if (unlikely(!p)) 3290c0eae66eSBenny Halevy goto out_overflow; 3291cccddf4fSBenny Halevy *type = be32_to_cpup(p); 32921da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 32933110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 32941da177e4SLinus Torvalds return -EIO; 32951da177e4SLinus Torvalds } 32961da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3297409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 32981da177e4SLinus Torvalds } 3299bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3300409924e4STrond Myklebust return ret; 3301c0eae66eSBenny Halevy out_overflow: 3302c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3303c0eae66eSBenny Halevy return -EIO; 33041da177e4SLinus Torvalds } 33051da177e4SLinus Torvalds 3306264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3307264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3308264e6351SChuck Lever { 3309264e6351SChuck Lever __be32 *p; 3310264e6351SChuck Lever 3311264e6351SChuck Lever *type = 0; 3312264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3313264e6351SChuck Lever return -EIO; 3314264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3315264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3316264e6351SChuck Lever if (unlikely(!p)) 3317264e6351SChuck Lever goto out_overflow; 3318264e6351SChuck Lever *type = be32_to_cpup(p); 3319264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3320264e6351SChuck Lever } 3321264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3322264e6351SChuck Lever return 0; 3323264e6351SChuck Lever out_overflow: 3324264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3325264e6351SChuck Lever return -EIO; 3326264e6351SChuck Lever } 3327264e6351SChuck Lever 33281da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 33291da177e4SLinus Torvalds { 33308687b63aSAl Viro __be32 *p; 3331409924e4STrond Myklebust int ret = 0; 33321da177e4SLinus Torvalds 33331da177e4SLinus Torvalds *change = 0; 33341da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 33351da177e4SLinus Torvalds return -EIO; 33361da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3337c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3338c0eae66eSBenny Halevy if (unlikely(!p)) 3339c0eae66eSBenny Halevy goto out_overflow; 3340cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 33411da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3342409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 33431da177e4SLinus Torvalds } 33443110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 33451da177e4SLinus Torvalds (unsigned long long)*change); 3346409924e4STrond Myklebust return ret; 3347c0eae66eSBenny Halevy out_overflow: 3348c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3349c0eae66eSBenny Halevy return -EIO; 33501da177e4SLinus Torvalds } 33511da177e4SLinus Torvalds 33521da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 33531da177e4SLinus Torvalds { 33548687b63aSAl Viro __be32 *p; 3355409924e4STrond Myklebust int ret = 0; 33561da177e4SLinus Torvalds 33571da177e4SLinus Torvalds *size = 0; 33581da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 33591da177e4SLinus Torvalds return -EIO; 33601da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3361c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3362c0eae66eSBenny Halevy if (unlikely(!p)) 3363c0eae66eSBenny Halevy goto out_overflow; 3364cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 33651da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3366409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 33671da177e4SLinus Torvalds } 33683110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3369409924e4STrond Myklebust return ret; 3370c0eae66eSBenny Halevy out_overflow: 3371c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3372c0eae66eSBenny Halevy return -EIO; 33731da177e4SLinus Torvalds } 33741da177e4SLinus Torvalds 33751da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33761da177e4SLinus Torvalds { 33778687b63aSAl Viro __be32 *p; 33781da177e4SLinus Torvalds 33791da177e4SLinus Torvalds *res = 0; 33801da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33811da177e4SLinus Torvalds return -EIO; 33821da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3383c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3384c0eae66eSBenny Halevy if (unlikely(!p)) 3385c0eae66eSBenny Halevy goto out_overflow; 3386cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33871da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 33881da177e4SLinus Torvalds } 33893110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 33901da177e4SLinus Torvalds return 0; 3391c0eae66eSBenny Halevy out_overflow: 3392c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3393c0eae66eSBenny Halevy return -EIO; 33941da177e4SLinus Torvalds } 33951da177e4SLinus Torvalds 33961da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33971da177e4SLinus Torvalds { 33988687b63aSAl Viro __be32 *p; 33991da177e4SLinus Torvalds 34001da177e4SLinus Torvalds *res = 0; 34011da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 34021da177e4SLinus Torvalds return -EIO; 34031da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3404c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3405c0eae66eSBenny Halevy if (unlikely(!p)) 3406c0eae66eSBenny Halevy goto out_overflow; 3407cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34081da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 34091da177e4SLinus Torvalds } 34103110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 34111da177e4SLinus Torvalds return 0; 3412c0eae66eSBenny Halevy out_overflow: 3413c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3414c0eae66eSBenny Halevy return -EIO; 34151da177e4SLinus Torvalds } 34161da177e4SLinus Torvalds 34178b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 34181da177e4SLinus Torvalds { 34198687b63aSAl Viro __be32 *p; 3420409924e4STrond Myklebust int ret = 0; 34211da177e4SLinus Torvalds 34221da177e4SLinus Torvalds fsid->major = 0; 34231da177e4SLinus Torvalds fsid->minor = 0; 34241da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 34251da177e4SLinus Torvalds return -EIO; 34261da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3427c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3428c0eae66eSBenny Halevy if (unlikely(!p)) 3429c0eae66eSBenny Halevy goto out_overflow; 34303ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3431cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 34321da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3433409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 34341da177e4SLinus Torvalds } 34353110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 34361da177e4SLinus Torvalds (unsigned long long)fsid->major, 34371da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3438409924e4STrond Myklebust return ret; 3439c0eae66eSBenny Halevy out_overflow: 3440c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3441c0eae66eSBenny Halevy return -EIO; 34421da177e4SLinus Torvalds } 34431da177e4SLinus Torvalds 34441da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34451da177e4SLinus Torvalds { 34468687b63aSAl Viro __be32 *p; 34471da177e4SLinus Torvalds 34481da177e4SLinus Torvalds *res = 60; 34491da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 34501da177e4SLinus Torvalds return -EIO; 34511da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3452c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3453c0eae66eSBenny Halevy if (unlikely(!p)) 3454c0eae66eSBenny Halevy goto out_overflow; 3455cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34561da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 34571da177e4SLinus Torvalds } 34583110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 34591da177e4SLinus Torvalds return 0; 3460c0eae66eSBenny Halevy out_overflow: 3461c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3462c0eae66eSBenny Halevy return -EIO; 34631da177e4SLinus Torvalds } 34641da177e4SLinus Torvalds 3465ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3466ae42c70aSBryan Schumaker { 3467ae42c70aSBryan Schumaker __be32 *p; 3468ae42c70aSBryan Schumaker 3469ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3470ae42c70aSBryan Schumaker return -EIO; 3471ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3472ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3473ae42c70aSBryan Schumaker if (unlikely(!p)) 3474ae42c70aSBryan Schumaker goto out_overflow; 3475ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3476ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3477ae42c70aSBryan Schumaker } 3478ae42c70aSBryan Schumaker return 0; 3479ae42c70aSBryan Schumaker out_overflow: 3480ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3481ae42c70aSBryan Schumaker return -EIO; 3482ae42c70aSBryan Schumaker } 3483ae42c70aSBryan Schumaker 34848c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 34858c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 34868c61282fSKinglong Mee { 34878c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 34888c61282fSKinglong Mee int ret; 34898c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 34908c61282fSKinglong Mee if (unlikely(ret < 0)) 34918c61282fSKinglong Mee return ret; 34928c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 34938c61282fSKinglong Mee } else 34948c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 34958c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 34968c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 34978c61282fSKinglong Mee return 0; 34988c61282fSKinglong Mee } 34998c61282fSKinglong Mee 3500ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3501ae42c70aSBryan Schumaker { 3502ae42c70aSBryan Schumaker __be32 *p; 3503ae42c70aSBryan Schumaker int len; 3504ae42c70aSBryan Schumaker 35057ad07353STrond Myklebust if (fh != NULL) 3506ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3507ae42c70aSBryan Schumaker 3508ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3509ae42c70aSBryan Schumaker return -EIO; 3510ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3511ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3512ae42c70aSBryan Schumaker if (unlikely(!p)) 3513ae42c70aSBryan Schumaker goto out_overflow; 3514ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3515ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3516ae42c70aSBryan Schumaker return -EIO; 3517ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3518ae42c70aSBryan Schumaker if (unlikely(!p)) 3519ae42c70aSBryan Schumaker goto out_overflow; 35207ad07353STrond Myklebust if (fh != NULL) { 3521ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 35227ad07353STrond Myklebust fh->size = len; 35237ad07353STrond Myklebust } 3524ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3525ae42c70aSBryan Schumaker } 3526ae42c70aSBryan Schumaker return 0; 3527ae42c70aSBryan Schumaker out_overflow: 3528ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3529ae42c70aSBryan Schumaker return -EIO; 3530ae42c70aSBryan Schumaker } 3531ae42c70aSBryan Schumaker 35321da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 35331da177e4SLinus Torvalds { 35348687b63aSAl Viro __be32 *p; 35351da177e4SLinus Torvalds 3536a1800acaSMalahal Naineni *res = 0; 35371da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 35381da177e4SLinus Torvalds return -EIO; 35391da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3540c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3541c0eae66eSBenny Halevy if (unlikely(!p)) 3542c0eae66eSBenny Halevy goto out_overflow; 3543cccddf4fSBenny Halevy *res = be32_to_cpup(p); 35441da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 35451da177e4SLinus Torvalds } 35463110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 35471da177e4SLinus Torvalds return 0; 3548c0eae66eSBenny Halevy out_overflow: 3549c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3550c0eae66eSBenny Halevy return -EIO; 35511da177e4SLinus Torvalds } 35521da177e4SLinus Torvalds 35531da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 35541da177e4SLinus Torvalds { 35558687b63aSAl Viro __be32 *p; 3556409924e4STrond Myklebust int ret = 0; 35571da177e4SLinus Torvalds 35581da177e4SLinus Torvalds *fileid = 0; 35591da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 35601da177e4SLinus Torvalds return -EIO; 35611da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3562c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3563c0eae66eSBenny Halevy if (unlikely(!p)) 3564c0eae66eSBenny Halevy goto out_overflow; 3565cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 35661da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3567409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 35681da177e4SLinus Torvalds } 35693110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3570409924e4STrond Myklebust return ret; 3571c0eae66eSBenny Halevy out_overflow: 3572c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3573c0eae66eSBenny Halevy return -EIO; 35741da177e4SLinus Torvalds } 35751da177e4SLinus Torvalds 357699baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 357799baf625SManoj Naik { 35788687b63aSAl Viro __be32 *p; 3579409924e4STrond Myklebust int ret = 0; 358099baf625SManoj Naik 358199baf625SManoj Naik *fileid = 0; 358299baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 358399baf625SManoj Naik return -EIO; 358499baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3585c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3586c0eae66eSBenny Halevy if (unlikely(!p)) 3587c0eae66eSBenny Halevy goto out_overflow; 3588cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 358999baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 359028331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 359199baf625SManoj Naik } 35923110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3593409924e4STrond Myklebust return ret; 3594c0eae66eSBenny Halevy out_overflow: 3595c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3596c0eae66eSBenny Halevy return -EIO; 359799baf625SManoj Naik } 359899baf625SManoj Naik 35991da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36001da177e4SLinus Torvalds { 36018687b63aSAl Viro __be32 *p; 36021da177e4SLinus Torvalds int status = 0; 36031da177e4SLinus Torvalds 36041da177e4SLinus Torvalds *res = 0; 36051da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 36061da177e4SLinus Torvalds return -EIO; 36071da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3608c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3609c0eae66eSBenny Halevy if (unlikely(!p)) 3610c0eae66eSBenny Halevy goto out_overflow; 3611cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36121da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 36131da177e4SLinus Torvalds } 36143110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 36151da177e4SLinus Torvalds return status; 3616c0eae66eSBenny Halevy out_overflow: 3617c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3618c0eae66eSBenny Halevy return -EIO; 36191da177e4SLinus Torvalds } 36201da177e4SLinus Torvalds 36211da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36221da177e4SLinus Torvalds { 36238687b63aSAl Viro __be32 *p; 36241da177e4SLinus Torvalds int status = 0; 36251da177e4SLinus Torvalds 36261da177e4SLinus Torvalds *res = 0; 36271da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 36281da177e4SLinus Torvalds return -EIO; 36291da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3630c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3631c0eae66eSBenny Halevy if (unlikely(!p)) 3632c0eae66eSBenny Halevy goto out_overflow; 3633cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 36351da177e4SLinus Torvalds } 36363110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 36371da177e4SLinus Torvalds return status; 3638c0eae66eSBenny Halevy out_overflow: 3639c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3640c0eae66eSBenny Halevy return -EIO; 36411da177e4SLinus Torvalds } 36421da177e4SLinus Torvalds 36431da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36441da177e4SLinus Torvalds { 36458687b63aSAl Viro __be32 *p; 36461da177e4SLinus Torvalds int status = 0; 36471da177e4SLinus Torvalds 36481da177e4SLinus Torvalds *res = 0; 36491da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 36501da177e4SLinus Torvalds return -EIO; 36511da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3652c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3653c0eae66eSBenny Halevy if (unlikely(!p)) 3654c0eae66eSBenny Halevy goto out_overflow; 3655cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36561da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 36571da177e4SLinus Torvalds } 36583110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 36591da177e4SLinus Torvalds return status; 3660c0eae66eSBenny Halevy out_overflow: 3661c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3662c0eae66eSBenny Halevy return -EIO; 36631da177e4SLinus Torvalds } 36641da177e4SLinus Torvalds 36657aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 36667aaa0b3bSManoj Naik { 3667464ad6b1SChuck Lever u32 n; 36688687b63aSAl Viro __be32 *p; 36697aaa0b3bSManoj Naik int status = 0; 36707aaa0b3bSManoj Naik 3671c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3672c0eae66eSBenny Halevy if (unlikely(!p)) 3673c0eae66eSBenny Halevy goto out_overflow; 3674cccddf4fSBenny Halevy n = be32_to_cpup(p); 367533a43f28SAndy Adamson if (n == 0) 367633a43f28SAndy Adamson goto root_path; 367702a2976cSChuck Lever dprintk("pathname4: "); 3678809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3679809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3680809b426cSTrond Myklebust goto out_eio; 3681809b426cSTrond Myklebust } 3682809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36837aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 36847aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 36857aaa0b3bSManoj Naik if (unlikely(status != 0)) 36867aaa0b3bSManoj Naik goto out_eio; 368795a13f7bSTrond Myklebust ifdebug (XDR) 368802a2976cSChuck Lever pr_cont("%s%.*s ", 368902a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 369002a2976cSChuck Lever component->len, component->data); 36917aaa0b3bSManoj Naik } 36927aaa0b3bSManoj Naik out: 36937aaa0b3bSManoj Naik return status; 369433a43f28SAndy Adamson root_path: 369533a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 369633a43f28SAndy Adamson path->ncomponents = 1; 369733a43f28SAndy Adamson path->components[0].len=0; 369833a43f28SAndy Adamson path->components[0].data=NULL; 369902a2976cSChuck Lever dprintk("pathname4: /\n"); 370033a43f28SAndy Adamson goto out; 37017aaa0b3bSManoj Naik out_eio: 37027aaa0b3bSManoj Naik dprintk(" status %d", status); 37037aaa0b3bSManoj Naik status = -EIO; 37047aaa0b3bSManoj Naik goto out; 3705c0eae66eSBenny Halevy out_overflow: 3706c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3707c0eae66eSBenny Halevy return -EIO; 37087aaa0b3bSManoj Naik } 37097aaa0b3bSManoj Naik 37107aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3711683b57b4STrond Myklebust { 3712683b57b4STrond Myklebust int n; 37138687b63aSAl Viro __be32 *p; 3714683b57b4STrond Myklebust int status = -EIO; 3715683b57b4STrond Myklebust 3716683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3717683b57b4STrond Myklebust goto out; 3718683b57b4STrond Myklebust status = 0; 3719683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3720683b57b4STrond Myklebust goto out; 3721f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 37228b7e3f49STrond Myklebust status = -EIO; 37238b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 37248b7e3f49STrond Myklebust if (unlikely(res == NULL)) 37258b7e3f49STrond Myklebust goto out; 372602a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 37277aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3728683b57b4STrond Myklebust if (unlikely(status != 0)) 3729683b57b4STrond Myklebust goto out; 3730c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3731c0eae66eSBenny Halevy if (unlikely(!p)) 3732c0eae66eSBenny Halevy goto out_overflow; 3733cccddf4fSBenny Halevy n = be32_to_cpup(p); 3734683b57b4STrond Myklebust if (n <= 0) 3735683b57b4STrond Myklebust goto out_eio; 3736809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3737464ad6b1SChuck Lever u32 m; 3738809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3739683b57b4STrond Myklebust 3740809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3741809b426cSTrond Myklebust break; 3742809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3743c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3744c0eae66eSBenny Halevy if (unlikely(!p)) 3745c0eae66eSBenny Halevy goto out_overflow; 3746cccddf4fSBenny Halevy m = be32_to_cpup(p); 37477aaa0b3bSManoj Naik 374802a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3749809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3750809b426cSTrond Myklebust struct nfs4_string *server; 3751809b426cSTrond Myklebust 3752809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3753464ad6b1SChuck Lever unsigned int i; 3754464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3755464ad6b1SChuck Lever "returned for location %u\n", 37563110ff80SHarvey Harrison __func__, 3757464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3758464ad6b1SChuck Lever m, res->nlocations); 37597aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 37602e42c3e2STrond Myklebust unsigned int len; 37617aaa0b3bSManoj Naik char *data; 37627aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3763683b57b4STrond Myklebust if (unlikely(status != 0)) 3764683b57b4STrond Myklebust goto out_eio; 37657aaa0b3bSManoj Naik } 3766809b426cSTrond Myklebust break; 37677aaa0b3bSManoj Naik } 3768809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3769809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3770809b426cSTrond Myklebust if (unlikely(status != 0)) 3771809b426cSTrond Myklebust goto out_eio; 3772809b426cSTrond Myklebust dprintk("%s ", server->data); 37737aaa0b3bSManoj Naik } 37747aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 37757aaa0b3bSManoj Naik if (unlikely(status != 0)) 37767aaa0b3bSManoj Naik goto out_eio; 3777683b57b4STrond Myklebust } 3778409924e4STrond Myklebust if (res->nlocations != 0) 377981934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3780683b57b4STrond Myklebust out: 37813110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3782683b57b4STrond Myklebust return status; 3783c0eae66eSBenny Halevy out_overflow: 3784c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3785683b57b4STrond Myklebust out_eio: 3786683b57b4STrond Myklebust status = -EIO; 3787683b57b4STrond Myklebust goto out; 3788683b57b4STrond Myklebust } 3789683b57b4STrond Myklebust 37901da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 37911da177e4SLinus Torvalds { 37928687b63aSAl Viro __be32 *p; 37931da177e4SLinus Torvalds int status = 0; 37941da177e4SLinus Torvalds 37951da177e4SLinus Torvalds *res = 0; 37961da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 37971da177e4SLinus Torvalds return -EIO; 37981da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3799c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3800c0eae66eSBenny Halevy if (unlikely(!p)) 3801c0eae66eSBenny Halevy goto out_overflow; 3802cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38031da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 38041da177e4SLinus Torvalds } 38053110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 38061da177e4SLinus Torvalds return status; 3807c0eae66eSBenny Halevy out_overflow: 3808c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3809c0eae66eSBenny Halevy return -EIO; 38101da177e4SLinus Torvalds } 38111da177e4SLinus Torvalds 38121da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 38131da177e4SLinus Torvalds { 38148687b63aSAl Viro __be32 *p; 38151da177e4SLinus Torvalds int status = 0; 38161da177e4SLinus Torvalds 38171da177e4SLinus Torvalds *maxlink = 1; 38181da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 38191da177e4SLinus Torvalds return -EIO; 38201da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3821c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3822c0eae66eSBenny Halevy if (unlikely(!p)) 3823c0eae66eSBenny Halevy goto out_overflow; 3824cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 38251da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 38261da177e4SLinus Torvalds } 38273110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 38281da177e4SLinus Torvalds return status; 3829c0eae66eSBenny Halevy out_overflow: 3830c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3831c0eae66eSBenny Halevy return -EIO; 38321da177e4SLinus Torvalds } 38331da177e4SLinus Torvalds 38341da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 38351da177e4SLinus Torvalds { 38368687b63aSAl Viro __be32 *p; 38371da177e4SLinus Torvalds int status = 0; 38381da177e4SLinus Torvalds 38391da177e4SLinus Torvalds *maxname = 1024; 38401da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 38411da177e4SLinus Torvalds return -EIO; 38421da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3843c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3844c0eae66eSBenny Halevy if (unlikely(!p)) 3845c0eae66eSBenny Halevy goto out_overflow; 3846cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 38471da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 38481da177e4SLinus Torvalds } 38493110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 38501da177e4SLinus Torvalds return status; 3851c0eae66eSBenny Halevy out_overflow: 3852c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3853c0eae66eSBenny Halevy return -EIO; 38541da177e4SLinus Torvalds } 38551da177e4SLinus Torvalds 38561da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38571da177e4SLinus Torvalds { 38588687b63aSAl Viro __be32 *p; 38591da177e4SLinus Torvalds int status = 0; 38601da177e4SLinus Torvalds 38611da177e4SLinus Torvalds *res = 1024; 38621da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 38631da177e4SLinus Torvalds return -EIO; 38641da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 38651da177e4SLinus Torvalds uint64_t maxread; 3866c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3867c0eae66eSBenny Halevy if (unlikely(!p)) 3868c0eae66eSBenny Halevy goto out_overflow; 3869cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 38701da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 38711da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 38721da177e4SLinus Torvalds *res = (uint32_t)maxread; 38731da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 38741da177e4SLinus Torvalds } 38753110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 38761da177e4SLinus Torvalds return status; 3877c0eae66eSBenny Halevy out_overflow: 3878c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3879c0eae66eSBenny Halevy return -EIO; 38801da177e4SLinus Torvalds } 38811da177e4SLinus Torvalds 38821da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38831da177e4SLinus Torvalds { 38848687b63aSAl Viro __be32 *p; 38851da177e4SLinus Torvalds int status = 0; 38861da177e4SLinus Torvalds 38871da177e4SLinus Torvalds *res = 1024; 38881da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 38891da177e4SLinus Torvalds return -EIO; 38901da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 38911da177e4SLinus Torvalds uint64_t maxwrite; 3892c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3893c0eae66eSBenny Halevy if (unlikely(!p)) 3894c0eae66eSBenny Halevy goto out_overflow; 3895cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 38961da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 38971da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 38981da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 38991da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 39001da177e4SLinus Torvalds } 39013110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 39021da177e4SLinus Torvalds return status; 3903c0eae66eSBenny Halevy out_overflow: 3904c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3905c0eae66eSBenny Halevy return -EIO; 39061da177e4SLinus Torvalds } 39071da177e4SLinus Torvalds 3908bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 39091da177e4SLinus Torvalds { 3910bca79478STrond Myklebust uint32_t tmp; 39118687b63aSAl Viro __be32 *p; 3912409924e4STrond Myklebust int ret = 0; 39131da177e4SLinus Torvalds 39141da177e4SLinus Torvalds *mode = 0; 39151da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 39161da177e4SLinus Torvalds return -EIO; 39171da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3918c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3919c0eae66eSBenny Halevy if (unlikely(!p)) 3920c0eae66eSBenny Halevy goto out_overflow; 3921cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3922bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 39231da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3924409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 39251da177e4SLinus Torvalds } 39263110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3927409924e4STrond Myklebust return ret; 3928c0eae66eSBenny Halevy out_overflow: 3929c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3930c0eae66eSBenny Halevy return -EIO; 39311da177e4SLinus Torvalds } 39321da177e4SLinus Torvalds 39331da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 39341da177e4SLinus Torvalds { 39358687b63aSAl Viro __be32 *p; 3936409924e4STrond Myklebust int ret = 0; 39371da177e4SLinus Torvalds 39381da177e4SLinus Torvalds *nlink = 1; 39391da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 39401da177e4SLinus Torvalds return -EIO; 39411da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3942c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3943c0eae66eSBenny Halevy if (unlikely(!p)) 3944c0eae66eSBenny Halevy goto out_overflow; 3945cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 39461da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3947409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 39481da177e4SLinus Torvalds } 39493110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3950409924e4STrond Myklebust return ret; 3951c0eae66eSBenny Halevy out_overflow: 3952c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3953c0eae66eSBenny Halevy return -EIO; 39541da177e4SLinus Torvalds } 39551da177e4SLinus Torvalds 3956686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr, 3957686a816aSTrond Myklebust struct nfs4_string *name, gfp_t gfp_flags) 3958686a816aSTrond Myklebust { 3959686a816aSTrond Myklebust ssize_t ret; 3960686a816aSTrond Myklebust 3961686a816aSTrond Myklebust ret = xdr_stream_decode_string_dup(xdr, &name->data, 3962686a816aSTrond Myklebust XDR_MAX_NETOBJ, gfp_flags); 3963686a816aSTrond Myklebust name->len = 0; 3964686a816aSTrond Myklebust if (ret > 0) 3965686a816aSTrond Myklebust name->len = ret; 3966686a816aSTrond Myklebust return ret; 3967686a816aSTrond Myklebust } 3968686a816aSTrond Myklebust 396980e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3970e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 39716926afd1STrond Myklebust struct nfs4_string *owner_name) 39721da177e4SLinus Torvalds { 3973686a816aSTrond Myklebust ssize_t len; 3974686a816aSTrond Myklebust char *p; 39751da177e4SLinus Torvalds 3976e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 39771da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 39781da177e4SLinus Torvalds return -EIO; 3979686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER)) 3980686a816aSTrond Myklebust return 0; 39811da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 3982686a816aSTrond Myklebust 3983686a816aSTrond Myklebust if (owner_name != NULL) { 3984686a816aSTrond Myklebust len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT); 3985686a816aSTrond Myklebust if (len <= 0) 3986686a816aSTrond Myklebust goto out; 3987686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, owner_name->data); 3988686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER_NAME; 3989686a816aSTrond Myklebust } else { 3990686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 3991686a816aSTrond Myklebust XDR_MAX_NETOBJ); 3992686a816aSTrond Myklebust if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0) 3993686a816aSTrond Myklebust goto out; 3994e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3995686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER; 3996686a816aSTrond Myklebust } 3997686a816aSTrond Myklebust out: 3998686a816aSTrond Myklebust if (len != -EBADMSG) 3999686a816aSTrond Myklebust return 0; 4000c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4001c0eae66eSBenny Halevy return -EIO; 40021da177e4SLinus Torvalds } 40031da177e4SLinus Torvalds 400480e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 4005e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 40066926afd1STrond Myklebust struct nfs4_string *group_name) 40071da177e4SLinus Torvalds { 4008686a816aSTrond Myklebust ssize_t len; 4009686a816aSTrond Myklebust char *p; 40101da177e4SLinus Torvalds 4011e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 40121da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 40131da177e4SLinus Torvalds return -EIO; 4014686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) 4015686a816aSTrond Myklebust return 0; 40161da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 4017686a816aSTrond Myklebust 4018686a816aSTrond Myklebust if (group_name != NULL) { 4019686a816aSTrond Myklebust len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT); 4020686a816aSTrond Myklebust if (len <= 0) 4021686a816aSTrond Myklebust goto out; 4022686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, group_name->data); 40236f1f6220SKinglong Mee return NFS_ATTR_FATTR_GROUP_NAME; 4024686a816aSTrond Myklebust } else { 4025686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 4026686a816aSTrond Myklebust XDR_MAX_NETOBJ); 4027686a816aSTrond Myklebust if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0) 4028686a816aSTrond Myklebust goto out; 4029e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 4030686a816aSTrond Myklebust return NFS_ATTR_FATTR_GROUP; 4031686a816aSTrond Myklebust } 4032686a816aSTrond Myklebust out: 4033686a816aSTrond Myklebust if (len != -EBADMSG) 4034686a816aSTrond Myklebust return 0; 4035c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4036c0eae66eSBenny Halevy return -EIO; 40371da177e4SLinus Torvalds } 40381da177e4SLinus Torvalds 40391da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 40401da177e4SLinus Torvalds { 40418687b63aSAl Viro uint32_t major = 0, minor = 0; 40428687b63aSAl Viro __be32 *p; 4043409924e4STrond Myklebust int ret = 0; 40441da177e4SLinus Torvalds 40451da177e4SLinus Torvalds *rdev = MKDEV(0,0); 40461da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 40471da177e4SLinus Torvalds return -EIO; 40481da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 40491da177e4SLinus Torvalds dev_t tmp; 40501da177e4SLinus Torvalds 4051c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4052c0eae66eSBenny Halevy if (unlikely(!p)) 4053c0eae66eSBenny Halevy goto out_overflow; 40546f723f77SBenny Halevy major = be32_to_cpup(p++); 4055cccddf4fSBenny Halevy minor = be32_to_cpup(p); 40561da177e4SLinus Torvalds tmp = MKDEV(major, minor); 40571da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 40581da177e4SLinus Torvalds *rdev = tmp; 40591da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 4060409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 40611da177e4SLinus Torvalds } 40623110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 4063409924e4STrond Myklebust return ret; 4064c0eae66eSBenny Halevy out_overflow: 4065c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4066c0eae66eSBenny Halevy return -EIO; 40671da177e4SLinus Torvalds } 40681da177e4SLinus Torvalds 40691da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40701da177e4SLinus Torvalds { 40718687b63aSAl Viro __be32 *p; 40721da177e4SLinus Torvalds int status = 0; 40731da177e4SLinus Torvalds 40741da177e4SLinus Torvalds *res = 0; 40751da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 40761da177e4SLinus Torvalds return -EIO; 40771da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 4078c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4079c0eae66eSBenny Halevy if (unlikely(!p)) 4080c0eae66eSBenny Halevy goto out_overflow; 4081cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40821da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40831da177e4SLinus Torvalds } 40843110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 40851da177e4SLinus Torvalds return status; 4086c0eae66eSBenny Halevy out_overflow: 4087c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4088c0eae66eSBenny Halevy return -EIO; 40891da177e4SLinus Torvalds } 40901da177e4SLinus Torvalds 40911da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40921da177e4SLinus Torvalds { 40938687b63aSAl Viro __be32 *p; 40941da177e4SLinus Torvalds int status = 0; 40951da177e4SLinus Torvalds 40961da177e4SLinus Torvalds *res = 0; 40971da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 40981da177e4SLinus Torvalds return -EIO; 40991da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4100c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4101c0eae66eSBenny Halevy if (unlikely(!p)) 4102c0eae66eSBenny Halevy goto out_overflow; 4103cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 41041da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 41051da177e4SLinus Torvalds } 41063110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 41071da177e4SLinus Torvalds return status; 4108c0eae66eSBenny Halevy out_overflow: 4109c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4110c0eae66eSBenny Halevy return -EIO; 41111da177e4SLinus Torvalds } 41121da177e4SLinus Torvalds 41131da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 41141da177e4SLinus Torvalds { 41158687b63aSAl Viro __be32 *p; 41161da177e4SLinus Torvalds int status = 0; 41171da177e4SLinus Torvalds 41181da177e4SLinus Torvalds *res = 0; 41191da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 41201da177e4SLinus Torvalds return -EIO; 41211da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4122c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4123c0eae66eSBenny Halevy if (unlikely(!p)) 4124c0eae66eSBenny Halevy goto out_overflow; 4125cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 41261da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 41271da177e4SLinus Torvalds } 41283110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 41291da177e4SLinus Torvalds return status; 4130c0eae66eSBenny Halevy out_overflow: 4131c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4132c0eae66eSBenny Halevy return -EIO; 41331da177e4SLinus Torvalds } 41341da177e4SLinus Torvalds 41351da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 41361da177e4SLinus Torvalds { 41378687b63aSAl Viro __be32 *p; 4138409924e4STrond Myklebust int ret = 0; 41391da177e4SLinus Torvalds 41401da177e4SLinus Torvalds *used = 0; 41411da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 41421da177e4SLinus Torvalds return -EIO; 41431da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4144c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4145c0eae66eSBenny Halevy if (unlikely(!p)) 4146c0eae66eSBenny Halevy goto out_overflow; 4147cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 41481da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4149409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 41501da177e4SLinus Torvalds } 41513110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 41521da177e4SLinus Torvalds (unsigned long long)*used); 4153409924e4STrond Myklebust return ret; 4154c0eae66eSBenny Halevy out_overflow: 4155c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4156c0eae66eSBenny Halevy return -EIO; 41571da177e4SLinus Torvalds } 41581da177e4SLinus Torvalds 41591da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 41601da177e4SLinus Torvalds { 41618687b63aSAl Viro __be32 *p; 41621da177e4SLinus Torvalds uint64_t sec; 41631da177e4SLinus Torvalds uint32_t nsec; 41641da177e4SLinus Torvalds 4165c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4166c0eae66eSBenny Halevy if (unlikely(!p)) 4167c0eae66eSBenny Halevy goto out_overflow; 41683ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 4169cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 41701da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 41711da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 41721da177e4SLinus Torvalds return 0; 4173c0eae66eSBenny Halevy out_overflow: 4174c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4175c0eae66eSBenny Halevy return -EIO; 41761da177e4SLinus Torvalds } 41771da177e4SLinus Torvalds 41781da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41791da177e4SLinus Torvalds { 41801da177e4SLinus Torvalds int status = 0; 41811da177e4SLinus Torvalds 41821da177e4SLinus Torvalds time->tv_sec = 0; 41831da177e4SLinus Torvalds time->tv_nsec = 0; 41841da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 41851da177e4SLinus Torvalds return -EIO; 41861da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 41871da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4188409924e4STrond Myklebust if (status == 0) 4189409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 41901da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 41911da177e4SLinus Torvalds } 41923110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 41931da177e4SLinus Torvalds return status; 41941da177e4SLinus Torvalds } 41951da177e4SLinus Torvalds 41961da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41971da177e4SLinus Torvalds { 41981da177e4SLinus Torvalds int status = 0; 41991da177e4SLinus Torvalds 42001da177e4SLinus Torvalds time->tv_sec = 0; 42011da177e4SLinus Torvalds time->tv_nsec = 0; 42021da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 42031da177e4SLinus Torvalds return -EIO; 42041da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 42051da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4206409924e4STrond Myklebust if (status == 0) 4207409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 42081da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 42091da177e4SLinus Torvalds } 42103110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 42111da177e4SLinus Torvalds return status; 42121da177e4SLinus Torvalds } 42131da177e4SLinus Torvalds 421455b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 421555b6e774SRicardo Labiaga struct timespec *time) 421655b6e774SRicardo Labiaga { 421755b6e774SRicardo Labiaga int status = 0; 421855b6e774SRicardo Labiaga 421955b6e774SRicardo Labiaga time->tv_sec = 0; 422055b6e774SRicardo Labiaga time->tv_nsec = 0; 422155b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 422255b6e774SRicardo Labiaga return -EIO; 422355b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 422455b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 422555b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 422655b6e774SRicardo Labiaga } 422755b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 422855b6e774SRicardo Labiaga (long)time->tv_nsec); 422955b6e774SRicardo Labiaga return status; 423055b6e774SRicardo Labiaga } 423155b6e774SRicardo Labiaga 4232aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4233aa9c2669SDavid Quigley struct nfs4_label *label) 4234aa9c2669SDavid Quigley { 4235aa9c2669SDavid Quigley uint32_t pi = 0; 4236aa9c2669SDavid Quigley uint32_t lfs = 0; 4237aa9c2669SDavid Quigley __u32 len; 4238aa9c2669SDavid Quigley __be32 *p; 4239aa9c2669SDavid Quigley int status = 0; 4240aa9c2669SDavid Quigley 4241aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4242aa9c2669SDavid Quigley return -EIO; 4243aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4244aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4245aa9c2669SDavid Quigley if (unlikely(!p)) 4246aa9c2669SDavid Quigley goto out_overflow; 4247aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4248aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4249aa9c2669SDavid Quigley if (unlikely(!p)) 4250aa9c2669SDavid Quigley goto out_overflow; 4251aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4252aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4253aa9c2669SDavid Quigley if (unlikely(!p)) 4254aa9c2669SDavid Quigley goto out_overflow; 4255aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4256aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4257aa9c2669SDavid Quigley if (unlikely(!p)) 4258aa9c2669SDavid Quigley goto out_overflow; 4259aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4260aa9c2669SDavid Quigley if (label) { 4261aa9c2669SDavid Quigley memcpy(label->label, p, len); 4262aa9c2669SDavid Quigley label->len = len; 4263aa9c2669SDavid Quigley label->pi = pi; 4264aa9c2669SDavid Quigley label->lfs = lfs; 4265aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4266aa9c2669SDavid Quigley } 4267aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4268aa9c2669SDavid Quigley } else 4269aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4270aa9c2669SDavid Quigley __func__, len); 4271aa9c2669SDavid Quigley } 4272aa9c2669SDavid Quigley if (label && label->label) 4273aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4274aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4275aa9c2669SDavid Quigley return status; 4276aa9c2669SDavid Quigley 4277aa9c2669SDavid Quigley out_overflow: 4278aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4279aa9c2669SDavid Quigley return -EIO; 4280aa9c2669SDavid Quigley } 4281aa9c2669SDavid Quigley 42821da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42831da177e4SLinus Torvalds { 42841da177e4SLinus Torvalds int status = 0; 42851da177e4SLinus Torvalds 42861da177e4SLinus Torvalds time->tv_sec = 0; 42871da177e4SLinus Torvalds time->tv_nsec = 0; 42881da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 42891da177e4SLinus Torvalds return -EIO; 42901da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 42911da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4292409924e4STrond Myklebust if (status == 0) 4293409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 42941da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 42951da177e4SLinus Torvalds } 42963110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 42971da177e4SLinus Torvalds return status; 42981da177e4SLinus Torvalds } 42991da177e4SLinus Torvalds 4300256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 43011da177e4SLinus Torvalds { 43021da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4303256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 43041da177e4SLinus Torvalds 43051da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4306fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4307fe82a183SChuck Lever "%u %c %u\n", 43083110ff80SHarvey Harrison __func__, 43091da177e4SLinus Torvalds attrwords << 2, 43101da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 43111da177e4SLinus Torvalds nwords << 2); 43121da177e4SLinus Torvalds return -EIO; 43131da177e4SLinus Torvalds } 43141da177e4SLinus Torvalds return 0; 43151da177e4SLinus Torvalds } 43161da177e4SLinus Torvalds 43171da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43181da177e4SLinus Torvalds { 43198687b63aSAl Viro __be32 *p; 43201da177e4SLinus Torvalds 4321c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4322c0eae66eSBenny Halevy if (unlikely(!p)) 4323c0eae66eSBenny Halevy goto out_overflow; 43246f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 43253ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4326cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 43271da177e4SLinus Torvalds return 0; 4328c0eae66eSBenny Halevy out_overflow: 4329c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4330c0eae66eSBenny Halevy return -EIO; 43311da177e4SLinus Torvalds } 43321da177e4SLinus Torvalds 43336168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 43341da177e4SLinus Torvalds { 43358687b63aSAl Viro __be32 *p; 43361da177e4SLinus Torvalds uint32_t supp, acc; 43371da177e4SLinus Torvalds int status; 43381da177e4SLinus Torvalds 43391da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 43401da177e4SLinus Torvalds if (status) 43411da177e4SLinus Torvalds return status; 4342c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4343c0eae66eSBenny Halevy if (unlikely(!p)) 4344c0eae66eSBenny Halevy goto out_overflow; 43456f723f77SBenny Halevy supp = be32_to_cpup(p++); 4346cccddf4fSBenny Halevy acc = be32_to_cpup(p); 43476168f62cSWeston Andros Adamson *supported = supp; 43486168f62cSWeston Andros Adamson *access = acc; 43491da177e4SLinus Torvalds return 0; 4350c0eae66eSBenny Halevy out_overflow: 4351c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4352c0eae66eSBenny Halevy return -EIO; 43531da177e4SLinus Torvalds } 43541da177e4SLinus Torvalds 435507d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 43561da177e4SLinus Torvalds { 4357ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); 4358ab6e9aafSTrond Myklebust if (unlikely(ret < 0)) { 435907d30434SBenny Halevy print_overflow_msg(__func__, xdr); 436007d30434SBenny Halevy return -EIO; 436107d30434SBenny Halevy } 4362ab6e9aafSTrond Myklebust return 0; 4363ab6e9aafSTrond Myklebust } 436407d30434SBenny Halevy 436507d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 436607d30434SBenny Halevy { 43672d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 43681da177e4SLinus Torvalds } 43691da177e4SLinus Torvalds 437093b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 437193b717fdSTrond Myklebust { 437293b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 437393b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 437493b717fdSTrond Myklebust } 437593b717fdSTrond Myklebust 437693b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 437793b717fdSTrond Myklebust { 437893b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 437993b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 438093b717fdSTrond Myklebust } 438193b717fdSTrond Myklebust 438293b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 438393b717fdSTrond Myklebust { 438493b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 438593b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 438693b717fdSTrond Myklebust } 438793b717fdSTrond Myklebust 43881da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 43891da177e4SLinus Torvalds { 43901da177e4SLinus Torvalds int status; 43911da177e4SLinus Torvalds 43921da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4393c1d51931STrond Myklebust if (status != -EIO) 4394c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 439507d30434SBenny Halevy if (!status) 439693b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 43971da177e4SLinus Torvalds return status; 43981da177e4SLinus Torvalds } 43991da177e4SLinus Torvalds 4400db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4401db942bbdSBenny Halevy { 4402cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 44031da177e4SLinus Torvalds } 44041da177e4SLinus Torvalds 44052f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 44062f2c63bcSTrond Myklebust { 44072f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 44082f2c63bcSTrond Myklebust } 44092f2c63bcSTrond Myklebust 44100b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 44111da177e4SLinus Torvalds { 44121da177e4SLinus Torvalds int status; 44131da177e4SLinus Torvalds 44141da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4415db942bbdSBenny Halevy if (!status) 44162f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 44171da177e4SLinus Torvalds return status; 44181da177e4SLinus Torvalds } 44191da177e4SLinus Torvalds 44201da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 44211da177e4SLinus Torvalds { 44228687b63aSAl Viro __be32 *p; 44231da177e4SLinus Torvalds uint32_t bmlen; 44241da177e4SLinus Torvalds int status; 44251da177e4SLinus Torvalds 44261da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 44271da177e4SLinus Torvalds if (status) 44281da177e4SLinus Torvalds return status; 44291da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 44301da177e4SLinus Torvalds return status; 4431c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4432c0eae66eSBenny Halevy if (unlikely(!p)) 4433c0eae66eSBenny Halevy goto out_overflow; 4434cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4435c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4436c0eae66eSBenny Halevy if (likely(p)) 44371da177e4SLinus Torvalds return 0; 4438c0eae66eSBenny Halevy out_overflow: 4439c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4440c0eae66eSBenny Halevy return -EIO; 44411da177e4SLinus Torvalds } 44421da177e4SLinus Torvalds 44431da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 44441da177e4SLinus Torvalds { 4445256e48bbSTrond Myklebust unsigned int savep; 4446dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44471da177e4SLinus Torvalds int status; 44481da177e4SLinus Torvalds 44491da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44501da177e4SLinus Torvalds goto xdr_error; 44511da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44521da177e4SLinus Torvalds goto xdr_error; 44531da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44541da177e4SLinus Torvalds goto xdr_error; 44551da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 44561da177e4SLinus Torvalds goto xdr_error; 4457264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4458264e6351SChuck Lever &res->fh_expire_type)) != 0) 4459264e6351SChuck Lever goto xdr_error; 44601da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 44611da177e4SLinus Torvalds goto xdr_error; 44621da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 44631da177e4SLinus Torvalds goto xdr_error; 44641da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 44651da177e4SLinus Torvalds goto xdr_error; 44668c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 44678c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 44688c61282fSKinglong Mee goto xdr_error; 44691da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44701da177e4SLinus Torvalds xdr_error: 44713110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44721da177e4SLinus Torvalds return status; 44731da177e4SLinus Torvalds } 44741da177e4SLinus Torvalds 44751da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 44761da177e4SLinus Torvalds { 4477256e48bbSTrond Myklebust unsigned int savep; 4478dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44791da177e4SLinus Torvalds int status; 44801da177e4SLinus Torvalds 44811da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44821da177e4SLinus Torvalds goto xdr_error; 44831da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44841da177e4SLinus Torvalds goto xdr_error; 44851da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44861da177e4SLinus Torvalds goto xdr_error; 44871da177e4SLinus Torvalds 44881da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 44891da177e4SLinus Torvalds goto xdr_error; 44901da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 44911da177e4SLinus Torvalds goto xdr_error; 44921da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 44931da177e4SLinus Torvalds goto xdr_error; 44941ca843a2SAndreas Gruenbacher 44951ca843a2SAndreas Gruenbacher status = -EIO; 44961ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 44971ca843a2SAndreas Gruenbacher goto xdr_error; 44981ca843a2SAndreas Gruenbacher 44991da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 45001da177e4SLinus Torvalds goto xdr_error; 45011da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 45021da177e4SLinus Torvalds goto xdr_error; 45031da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 45041da177e4SLinus Torvalds goto xdr_error; 45051da177e4SLinus Torvalds 45061da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45071da177e4SLinus Torvalds xdr_error: 45083110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45091da177e4SLinus Torvalds return status; 45101da177e4SLinus Torvalds } 45111da177e4SLinus Torvalds 45121da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 45131da177e4SLinus Torvalds { 4514256e48bbSTrond Myklebust unsigned int savep; 4515dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 45161da177e4SLinus Torvalds int status; 45171da177e4SLinus Torvalds 45181da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45191da177e4SLinus Torvalds goto xdr_error; 45201da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45211da177e4SLinus Torvalds goto xdr_error; 45221da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45231da177e4SLinus Torvalds goto xdr_error; 45241da177e4SLinus Torvalds 45251da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 45261da177e4SLinus Torvalds goto xdr_error; 45271da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 45281da177e4SLinus Torvalds goto xdr_error; 45291da177e4SLinus Torvalds 45301da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45311da177e4SLinus Torvalds xdr_error: 45323110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45331da177e4SLinus Torvalds return status; 45341da177e4SLinus Torvalds } 45351da177e4SLinus Torvalds 453688034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 453788034c3dSAndy Adamson uint32_t *bitmap, 453888034c3dSAndy Adamson uint64_t *res, 453988034c3dSAndy Adamson uint32_t hint_bit) 454088034c3dSAndy Adamson { 454188034c3dSAndy Adamson __be32 *p; 454288034c3dSAndy Adamson 454388034c3dSAndy Adamson *res = 0; 454488034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 454588034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 454688034c3dSAndy Adamson if (unlikely(!p)) 454788034c3dSAndy Adamson goto out_overflow; 454888034c3dSAndy Adamson xdr_decode_hyper(p, res); 454988034c3dSAndy Adamson } 455088034c3dSAndy Adamson return 0; 455188034c3dSAndy Adamson out_overflow: 455288034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 455388034c3dSAndy Adamson return -EIO; 455488034c3dSAndy Adamson } 455588034c3dSAndy Adamson 455688034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 455788034c3dSAndy Adamson struct nfs4_threshold *res) 455888034c3dSAndy Adamson { 4559256e48bbSTrond Myklebust __be32 *p; 4560256e48bbSTrond Myklebust unsigned int savep; 456188034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 456288034c3dSAndy Adamson int status; 456388034c3dSAndy Adamson 456488034c3dSAndy Adamson /* layout type */ 456588034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 456688034c3dSAndy Adamson if (unlikely(!p)) { 456788034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 456888034c3dSAndy Adamson return -EIO; 456988034c3dSAndy Adamson } 457088034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 457188034c3dSAndy Adamson 457288034c3dSAndy Adamson /* thi_hintset bitmap */ 457388034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 457488034c3dSAndy Adamson if (status < 0) 457588034c3dSAndy Adamson goto xdr_error; 457688034c3dSAndy Adamson 457788034c3dSAndy Adamson /* thi_hintlist length */ 457888034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 457988034c3dSAndy Adamson if (status < 0) 458088034c3dSAndy Adamson goto xdr_error; 458188034c3dSAndy Adamson /* thi_hintlist */ 458288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 458388034c3dSAndy Adamson if (status < 0) 458488034c3dSAndy Adamson goto xdr_error; 458588034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 458688034c3dSAndy Adamson if (status < 0) 458788034c3dSAndy Adamson goto xdr_error; 458888034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 458988034c3dSAndy Adamson THRESHOLD_RD_IO); 459088034c3dSAndy Adamson if (status < 0) 459188034c3dSAndy Adamson goto xdr_error; 459288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 459388034c3dSAndy Adamson THRESHOLD_WR_IO); 459488034c3dSAndy Adamson if (status < 0) 459588034c3dSAndy Adamson goto xdr_error; 459688034c3dSAndy Adamson 459788034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 459888034c3dSAndy Adamson res->bm = bitmap[0]; 459988034c3dSAndy Adamson 460088034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 460188034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 460288034c3dSAndy Adamson res->wr_io_sz); 460388034c3dSAndy Adamson xdr_error: 460488034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 460588034c3dSAndy Adamson return status; 460688034c3dSAndy Adamson } 460788034c3dSAndy Adamson 460888034c3dSAndy Adamson /* 460988034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 461088034c3dSAndy Adamson */ 461188034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 461288034c3dSAndy Adamson uint32_t *bitmap, 461388034c3dSAndy Adamson struct nfs4_threshold *res) 461488034c3dSAndy Adamson { 461588034c3dSAndy Adamson __be32 *p; 461688034c3dSAndy Adamson int status = 0; 461788034c3dSAndy Adamson uint32_t num; 461888034c3dSAndy Adamson 461988034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 462088034c3dSAndy Adamson return -EIO; 4621029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 46221549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 46231549210fSTrond Myklebust if (unlikely(res == NULL)) 46241549210fSTrond Myklebust return -EREMOTEIO; 462588034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 462688034c3dSAndy Adamson if (unlikely(!p)) 462788034c3dSAndy Adamson goto out_overflow; 462888034c3dSAndy Adamson num = be32_to_cpup(p); 462988034c3dSAndy Adamson if (num == 0) 463088034c3dSAndy Adamson return 0; 463188034c3dSAndy Adamson if (num > 1) 463288034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 463388034c3dSAndy Adamson "drivers per filesystem not supported\n", 463488034c3dSAndy Adamson __func__); 463588034c3dSAndy Adamson 463688034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4637029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 463888034c3dSAndy Adamson } 463988034c3dSAndy Adamson return status; 464088034c3dSAndy Adamson out_overflow: 464188034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 464288034c3dSAndy Adamson return -EIO; 464388034c3dSAndy Adamson } 464488034c3dSAndy Adamson 4645ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4646ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4647aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 46486926afd1STrond Myklebust const struct nfs_server *server) 46491da177e4SLinus Torvalds { 4650bca79478STrond Myklebust int status; 4651bca79478STrond Myklebust umode_t fmode = 0; 4652ae42c70aSBryan Schumaker uint32_t type; 4653ee7b75fcSTrond Myklebust int32_t err; 46541da177e4SLinus Torvalds 4655f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4656f26c7a78STrond Myklebust if (status < 0) 46571da177e4SLinus Torvalds goto xdr_error; 4658409924e4STrond Myklebust fattr->mode = 0; 4659409924e4STrond Myklebust if (status != 0) { 4660409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4661409924e4STrond Myklebust fattr->valid |= status; 4662409924e4STrond Myklebust } 46631da177e4SLinus Torvalds 4664f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4665f26c7a78STrond Myklebust if (status < 0) 46661da177e4SLinus Torvalds goto xdr_error; 4667409924e4STrond Myklebust fattr->valid |= status; 4668f26c7a78STrond Myklebust 4669f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4670f26c7a78STrond Myklebust if (status < 0) 46711da177e4SLinus Torvalds goto xdr_error; 4672409924e4STrond Myklebust fattr->valid |= status; 4673f26c7a78STrond Myklebust 4674f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4675f26c7a78STrond Myklebust if (status < 0) 46761da177e4SLinus Torvalds goto xdr_error; 4677409924e4STrond Myklebust fattr->valid |= status; 4678f26c7a78STrond Myklebust 4679ee7b75fcSTrond Myklebust err = 0; 4680ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4681ae42c70aSBryan Schumaker if (status < 0) 4682ae42c70aSBryan Schumaker goto xdr_error; 4683ae42c70aSBryan Schumaker 4684ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4685ae42c70aSBryan Schumaker if (status < 0) 4686ae42c70aSBryan Schumaker goto xdr_error; 4687ae42c70aSBryan Schumaker 4688f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4689f26c7a78STrond Myklebust if (status < 0) 46901da177e4SLinus Torvalds goto xdr_error; 4691409924e4STrond Myklebust fattr->valid |= status; 4692f26c7a78STrond Myklebust 46938b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4694f26c7a78STrond Myklebust if (status < 0) 4695683b57b4STrond Myklebust goto xdr_error; 4696409924e4STrond Myklebust fattr->valid |= status; 4697f26c7a78STrond Myklebust 46981ca843a2SAndreas Gruenbacher status = -EIO; 46991ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 47001ca843a2SAndreas Gruenbacher goto xdr_error; 47011ca843a2SAndreas Gruenbacher 4702f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4703f26c7a78STrond Myklebust if (status < 0) 47041da177e4SLinus Torvalds goto xdr_error; 4705409924e4STrond Myklebust if (status != 0) { 47061da177e4SLinus Torvalds fattr->mode |= fmode; 4707409924e4STrond Myklebust fattr->valid |= status; 4708409924e4STrond Myklebust } 4709f26c7a78STrond Myklebust 4710f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4711f26c7a78STrond Myklebust if (status < 0) 47121da177e4SLinus Torvalds goto xdr_error; 4713409924e4STrond Myklebust fattr->valid |= status; 4714f26c7a78STrond Myklebust 47156926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4716f26c7a78STrond Myklebust if (status < 0) 47171da177e4SLinus Torvalds goto xdr_error; 4718409924e4STrond Myklebust fattr->valid |= status; 4719f26c7a78STrond Myklebust 47206926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4721f26c7a78STrond Myklebust if (status < 0) 47221da177e4SLinus Torvalds goto xdr_error; 4723409924e4STrond Myklebust fattr->valid |= status; 4724f26c7a78STrond Myklebust 4725f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4726f26c7a78STrond Myklebust if (status < 0) 47271da177e4SLinus Torvalds goto xdr_error; 4728409924e4STrond Myklebust fattr->valid |= status; 4729f26c7a78STrond Myklebust 4730f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4731f26c7a78STrond Myklebust if (status < 0) 47321da177e4SLinus Torvalds goto xdr_error; 4733409924e4STrond Myklebust fattr->valid |= status; 4734f26c7a78STrond Myklebust 4735f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4736f26c7a78STrond Myklebust if (status < 0) 47371da177e4SLinus Torvalds goto xdr_error; 4738409924e4STrond Myklebust fattr->valid |= status; 4739f26c7a78STrond Myklebust 4740f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4741f26c7a78STrond Myklebust if (status < 0) 47421da177e4SLinus Torvalds goto xdr_error; 4743409924e4STrond Myklebust fattr->valid |= status; 4744f26c7a78STrond Myklebust 4745f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4746f26c7a78STrond Myklebust if (status < 0) 47471da177e4SLinus Torvalds goto xdr_error; 4748409924e4STrond Myklebust fattr->valid |= status; 4749f26c7a78STrond Myklebust 475028331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4751f26c7a78STrond Myklebust if (status < 0) 475299baf625SManoj Naik goto xdr_error; 4753409924e4STrond Myklebust fattr->valid |= status; 4754f26c7a78STrond Myklebust 47551ca843a2SAndreas Gruenbacher status = -EIO; 47561ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 47571ca843a2SAndreas Gruenbacher goto xdr_error; 47581ca843a2SAndreas Gruenbacher 475988034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 476088034c3dSAndy Adamson if (status < 0) 476188034c3dSAndy Adamson goto xdr_error; 476288034c3dSAndy Adamson 4763aa9c2669SDavid Quigley if (label) { 4764aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4765aa9c2669SDavid Quigley if (status < 0) 4766aa9c2669SDavid Quigley goto xdr_error; 4767aa9c2669SDavid Quigley fattr->valid |= status; 4768aa9c2669SDavid Quigley } 4769aa9c2669SDavid Quigley 4770ae42c70aSBryan Schumaker xdr_error: 4771ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4772ae42c70aSBryan Schumaker return status; 4773ae42c70aSBryan Schumaker } 4774ae42c70aSBryan Schumaker 4775ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47768b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4777aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4778ae42c70aSBryan Schumaker { 4779256e48bbSTrond Myklebust unsigned int savep; 4780ae42c70aSBryan Schumaker uint32_t attrlen, 4781dae100c2SFred Isaman bitmap[3] = {0}; 4782ae42c70aSBryan Schumaker int status; 4783ae42c70aSBryan Schumaker 4784ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4785ae42c70aSBryan Schumaker if (status < 0) 4786ae42c70aSBryan Schumaker goto xdr_error; 4787ae42c70aSBryan Schumaker 4788ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4789ae42c70aSBryan Schumaker if (status < 0) 4790ae42c70aSBryan Schumaker goto xdr_error; 4791ae42c70aSBryan Schumaker 4792ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4793ae42c70aSBryan Schumaker if (status < 0) 4794ae42c70aSBryan Schumaker goto xdr_error; 4795ae42c70aSBryan Schumaker 4796aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4797aa9c2669SDavid Quigley label, server); 4798ae42c70aSBryan Schumaker if (status < 0) 4799ae42c70aSBryan Schumaker goto xdr_error; 4800ae42c70aSBryan Schumaker 4801f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 48021da177e4SLinus Torvalds xdr_error: 48033110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 48041da177e4SLinus Torvalds return status; 48051da177e4SLinus Torvalds } 48061da177e4SLinus Torvalds 4807aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4808aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4809aa9c2669SDavid Quigley { 4810aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4811aa9c2669SDavid Quigley } 4812aa9c2669SDavid Quigley 4813ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 48146926afd1STrond Myklebust const struct nfs_server *server) 4815ae42c70aSBryan Schumaker { 4816aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4817ae42c70aSBryan Schumaker } 48181da177e4SLinus Torvalds 4819504913fbSAndy Adamson /* 48203132e49eSJeff Layton * Decode potentially multiple layout types. 4821504913fbSAndy Adamson */ 48223132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4823ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4824504913fbSAndy Adamson { 4825b8a8a0ddSTrond Myklebust __be32 *p; 4826ca440c38SJeff Layton uint32_t i; 4827504913fbSAndy Adamson 4828504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4829504913fbSAndy Adamson if (unlikely(!p)) 4830504913fbSAndy Adamson goto out_overflow; 4831ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4832504913fbSAndy Adamson 4833504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4834ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4835504913fbSAndy Adamson return 0; 4836504913fbSAndy Adamson 4837504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4838ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4839504913fbSAndy Adamson if (unlikely(!p)) 4840504913fbSAndy Adamson goto out_overflow; 4841ca440c38SJeff Layton 4842ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4843ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4844ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4845ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4846ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4847ca440c38SJeff Layton } 4848ca440c38SJeff Layton 4849ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4850ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4851504913fbSAndy Adamson return 0; 4852504913fbSAndy Adamson out_overflow: 4853504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4854504913fbSAndy Adamson return -EIO; 4855504913fbSAndy Adamson } 4856504913fbSAndy Adamson 4857504913fbSAndy Adamson /* 4858504913fbSAndy Adamson * The type of file system exported. 4859504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4860504913fbSAndy Adamson */ 4861504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4862ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4863504913fbSAndy Adamson { 4864504913fbSAndy Adamson int status = 0; 4865504913fbSAndy Adamson 4866504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4867504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4868504913fbSAndy Adamson return -EIO; 4869504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4870ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4871504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 48723132e49eSJeff Layton } 4873504913fbSAndy Adamson return status; 4874504913fbSAndy Adamson } 4875504913fbSAndy Adamson 4876dae100c2SFred Isaman /* 4877dae100c2SFred Isaman * The prefered block size for layout directed io 4878dae100c2SFred Isaman */ 4879dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4880dae100c2SFred Isaman uint32_t *res) 4881dae100c2SFred Isaman { 4882dae100c2SFred Isaman __be32 *p; 4883dae100c2SFred Isaman 4884dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4885dae100c2SFred Isaman *res = 0; 4886dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4887dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4888dae100c2SFred Isaman if (unlikely(!p)) { 4889dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4890dae100c2SFred Isaman return -EIO; 4891dae100c2SFred Isaman } 4892dae100c2SFred Isaman *res = be32_to_cpup(p); 4893dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4894dae100c2SFred Isaman } 4895dae100c2SFred Isaman return 0; 4896dae100c2SFred Isaman } 4897dae100c2SFred Isaman 48982a92ee92SPeng Tao /* 48992a92ee92SPeng Tao * The granularity of a CLONE operation. 49002a92ee92SPeng Tao */ 49012a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 49022a92ee92SPeng Tao uint32_t *res) 49032a92ee92SPeng Tao { 49042a92ee92SPeng Tao __be32 *p; 49052a92ee92SPeng Tao 49062a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 49072a92ee92SPeng Tao *res = 0; 49082a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 49092a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 49102a92ee92SPeng Tao if (unlikely(!p)) { 49112a92ee92SPeng Tao print_overflow_msg(__func__, xdr); 49122a92ee92SPeng Tao return -EIO; 49132a92ee92SPeng Tao } 49142a92ee92SPeng Tao *res = be32_to_cpup(p); 49152a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 49162a92ee92SPeng Tao } 49172a92ee92SPeng Tao return 0; 49182a92ee92SPeng Tao } 49192a92ee92SPeng Tao 49201da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 49211da177e4SLinus Torvalds { 4922256e48bbSTrond Myklebust unsigned int savep; 4923dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 49241da177e4SLinus Torvalds int status; 49251da177e4SLinus Torvalds 49261da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 49271da177e4SLinus Torvalds goto xdr_error; 49281da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 49291da177e4SLinus Torvalds goto xdr_error; 49301da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 49311da177e4SLinus Torvalds goto xdr_error; 49321da177e4SLinus Torvalds 49331da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 49341da177e4SLinus Torvalds 49351da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 49361da177e4SLinus Torvalds goto xdr_error; 49371da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 49381da177e4SLinus Torvalds goto xdr_error; 49391da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 49401da177e4SLinus Torvalds goto xdr_error; 49411da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 49421da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 49431da177e4SLinus Torvalds goto xdr_error; 49441da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 49451ca843a2SAndreas Gruenbacher 49461ca843a2SAndreas Gruenbacher status = -EIO; 49471ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 49481ca843a2SAndreas Gruenbacher goto xdr_error; 49491ca843a2SAndreas Gruenbacher 495055b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 495155b6e774SRicardo Labiaga if (status != 0) 495255b6e774SRicardo Labiaga goto xdr_error; 4953ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4954504913fbSAndy Adamson if (status != 0) 4955504913fbSAndy Adamson goto xdr_error; 49561ca843a2SAndreas Gruenbacher 49571ca843a2SAndreas Gruenbacher status = -EIO; 49581ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 49591ca843a2SAndreas Gruenbacher goto xdr_error; 49601ca843a2SAndreas Gruenbacher 4961dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4962dae100c2SFred Isaman if (status) 4963dae100c2SFred Isaman goto xdr_error; 49642a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 49652a92ee92SPeng Tao if (status) 49662a92ee92SPeng Tao goto xdr_error; 49671da177e4SLinus Torvalds 49681da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 49691da177e4SLinus Torvalds xdr_error: 49703110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 49711da177e4SLinus Torvalds return status; 49721da177e4SLinus Torvalds } 49731da177e4SLinus Torvalds 49741da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 49751da177e4SLinus Torvalds { 49768687b63aSAl Viro __be32 *p; 49771da177e4SLinus Torvalds uint32_t len; 49781da177e4SLinus Torvalds int status; 49791da177e4SLinus Torvalds 49809936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 49819936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 49829936781dSTrond Myklebust 49831da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 49841da177e4SLinus Torvalds if (status) 49851da177e4SLinus Torvalds return status; 49861da177e4SLinus Torvalds 4987c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4988c0eae66eSBenny Halevy if (unlikely(!p)) 4989c0eae66eSBenny Halevy goto out_overflow; 4990cccddf4fSBenny Halevy len = be32_to_cpup(p); 49911da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 49921da177e4SLinus Torvalds return -EIO; 49931da177e4SLinus Torvalds fh->size = len; 4994c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4995c0eae66eSBenny Halevy if (unlikely(!p)) 4996c0eae66eSBenny Halevy goto out_overflow; 499799398d06SBenny Halevy memcpy(fh->data, p, len); 49981da177e4SLinus Torvalds return 0; 4999c0eae66eSBenny Halevy out_overflow: 5000c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5001c0eae66eSBenny Halevy return -EIO; 50021da177e4SLinus Torvalds } 50031da177e4SLinus Torvalds 50041da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 50051da177e4SLinus Torvalds { 50061da177e4SLinus Torvalds int status; 50071da177e4SLinus Torvalds 50081da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 50091da177e4SLinus Torvalds if (status) 50101da177e4SLinus Torvalds return status; 50111da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 50121da177e4SLinus Torvalds } 50131da177e4SLinus Torvalds 50141da177e4SLinus Torvalds /* 50151da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 50161da177e4SLinus Torvalds */ 5017911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 50181da177e4SLinus Torvalds { 5019911d1aafSTrond Myklebust uint64_t offset, length, clientid; 50208687b63aSAl Viro __be32 *p; 5021911d1aafSTrond Myklebust uint32_t namelen, type; 50221da177e4SLinus Torvalds 5023babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 5024c0eae66eSBenny Halevy if (unlikely(!p)) 5025c0eae66eSBenny Halevy goto out_overflow; 5026babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 50273ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 5028babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 5029babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 5030911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 5031911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 5032911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 5033911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 5034911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 5035911d1aafSTrond Myklebust if (type & 1) 5036911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 5037911d1aafSTrond Myklebust fl->fl_pid = 0; 5038911d1aafSTrond Myklebust } 5039babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 5040babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 5041babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 5042c0eae66eSBenny Halevy if (likely(p)) 50431da177e4SLinus Torvalds return -NFS4ERR_DENIED; 5044c0eae66eSBenny Halevy out_overflow: 5045c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5046c0eae66eSBenny Halevy return -EIO; 50471da177e4SLinus Torvalds } 50481da177e4SLinus Torvalds 5049911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 50501da177e4SLinus Torvalds { 50511da177e4SLinus Torvalds int status; 50521da177e4SLinus Torvalds 50531da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 5054c1d51931STrond Myklebust if (status == -EIO) 5055c1d51931STrond Myklebust goto out; 50561da177e4SLinus Torvalds if (status == 0) { 505793b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 505807d30434SBenny Halevy if (unlikely(status)) 505907d30434SBenny Halevy goto out; 50601da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 5061c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 5062c1d51931STrond Myklebust if (res->open_seqid != NULL) 5063c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 5064c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 5065c1d51931STrond Myklebust out: 50661da177e4SLinus Torvalds return status; 50671da177e4SLinus Torvalds } 50681da177e4SLinus Torvalds 5069911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 50701da177e4SLinus Torvalds { 50711da177e4SLinus Torvalds int status; 50721da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 50731da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 5074911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 50751da177e4SLinus Torvalds return status; 50761da177e4SLinus Torvalds } 50771da177e4SLinus Torvalds 5078911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 50791da177e4SLinus Torvalds { 50801da177e4SLinus Torvalds int status; 50811da177e4SLinus Torvalds 50821da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 5083c1d51931STrond Myklebust if (status != -EIO) 5084c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 508507d30434SBenny Halevy if (status == 0) 508693b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 50871da177e4SLinus Torvalds return status; 50881da177e4SLinus Torvalds } 50891da177e4SLinus Torvalds 5090d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 5091d3c7b7ccSTrond Myklebust { 5092d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5093d3c7b7ccSTrond Myklebust } 5094d3c7b7ccSTrond Myklebust 50951da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 50961da177e4SLinus Torvalds { 50971da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 50981da177e4SLinus Torvalds } 50991da177e4SLinus Torvalds 51005b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr) 51015b5faaf6SJeff Layton { 51025b5faaf6SJeff Layton return decode_op_hdr(xdr, OP_LOOKUPP); 51035b5faaf6SJeff Layton } 51045b5faaf6SJeff Layton 51051da177e4SLinus Torvalds /* This is too sick! */ 51067d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 51077d160a6cSTrond Myklebust unsigned long *pagemod_limit) 51081da177e4SLinus Torvalds { 51098687b63aSAl Viro __be32 *p; 51101da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 51117d160a6cSTrond Myklebust u64 maxsize = 0; 51121da177e4SLinus Torvalds 5113c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5114c0eae66eSBenny Halevy if (unlikely(!p)) 5115c0eae66eSBenny Halevy goto out_overflow; 51166f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 51171da177e4SLinus Torvalds switch (limit_type) { 51187d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 51197d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 51201da177e4SLinus Torvalds break; 51217d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 51226f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5123cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 51247d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 51251da177e4SLinus Torvalds } 512609cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 51277d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 51281da177e4SLinus Torvalds return 0; 5129c0eae66eSBenny Halevy out_overflow: 5130c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5131c0eae66eSBenny Halevy return -EIO; 51321da177e4SLinus Torvalds } 51331da177e4SLinus Torvalds 51346ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 51356ae37339STrond Myklebust uint32_t delegation_type, 51366ae37339STrond Myklebust struct nfs_openres *res) 51371da177e4SLinus Torvalds { 51388687b63aSAl Viro __be32 *p; 513907d30434SBenny Halevy int status; 51401da177e4SLinus Torvalds 514193b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 514207d30434SBenny Halevy if (unlikely(status)) 514307d30434SBenny Halevy return status; 5144c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5145c0eae66eSBenny Halevy if (unlikely(!p)) 5146c0eae66eSBenny Halevy goto out_overflow; 5147cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 514805d564feSAndy Adamson 51491da177e4SLinus Torvalds switch (delegation_type) { 51501da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 51511da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 51521da177e4SLinus Torvalds break; 51531da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 51541da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 51557d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 51561da177e4SLinus Torvalds return -EIO; 51571da177e4SLinus Torvalds } 51581bbe60ffSTrond Myklebust return decode_ace(xdr, NULL); 5159c0eae66eSBenny Halevy out_overflow: 5160c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5161c0eae66eSBenny Halevy return -EIO; 51621da177e4SLinus Torvalds } 51631da177e4SLinus Torvalds 51646ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51656ae37339STrond Myklebust { 51666ae37339STrond Myklebust __be32 *p; 51676ae37339STrond Myklebust uint32_t why_no_delegation; 51686ae37339STrond Myklebust 51696ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51706ae37339STrond Myklebust if (unlikely(!p)) 51716ae37339STrond Myklebust goto out_overflow; 51726ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 51736ae37339STrond Myklebust switch (why_no_delegation) { 51746ae37339STrond Myklebust case WND4_CONTENTION: 51756ae37339STrond Myklebust case WND4_RESOURCE: 51766ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 51776ae37339STrond Myklebust /* Ignore for now */ 51786ae37339STrond Myklebust } 51796ae37339STrond Myklebust return 0; 51806ae37339STrond Myklebust out_overflow: 51816ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51826ae37339STrond Myklebust return -EIO; 51836ae37339STrond Myklebust } 51846ae37339STrond Myklebust 51856ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51866ae37339STrond Myklebust { 51876ae37339STrond Myklebust __be32 *p; 51886ae37339STrond Myklebust uint32_t delegation_type; 51896ae37339STrond Myklebust 51906ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51916ae37339STrond Myklebust if (unlikely(!p)) 51926ae37339STrond Myklebust goto out_overflow; 51936ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 51946ae37339STrond Myklebust res->delegation_type = 0; 51956ae37339STrond Myklebust switch (delegation_type) { 51966ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 51976ae37339STrond Myklebust return 0; 51986ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 51996ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 52006ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 52016ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 52026ae37339STrond Myklebust return decode_no_delegation(xdr, res); 52036ae37339STrond Myklebust } 52046ae37339STrond Myklebust return -EIO; 52056ae37339STrond Myklebust out_overflow: 52066ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 52076ae37339STrond Myklebust return -EIO; 52086ae37339STrond Myklebust } 52096ae37339STrond Myklebust 52101da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 52111da177e4SLinus Torvalds { 52128687b63aSAl Viro __be32 *p; 5213aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 52141da177e4SLinus Torvalds int status; 52151da177e4SLinus Torvalds 5216c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5217c7848f69STrond Myklebust return status; 5218c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5219c7848f69STrond Myklebust if (status) 5220c7848f69STrond Myklebust return status; 522193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 522207d30434SBenny Halevy if (unlikely(status)) 52231da177e4SLinus Torvalds return status; 52241da177e4SLinus Torvalds 52251da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 52261da177e4SLinus Torvalds 5227c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5228c0eae66eSBenny Halevy if (unlikely(!p)) 5229c0eae66eSBenny Halevy goto out_overflow; 52306f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5231cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 52321da177e4SLinus Torvalds if (bmlen > 10) 52331da177e4SLinus Torvalds goto xdr_error; 52341da177e4SLinus Torvalds 5235c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5236c0eae66eSBenny Halevy if (unlikely(!p)) 5237c0eae66eSBenny Halevy goto out_overflow; 5238aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5239aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 52406f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5241aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5242aa53ed54SJeff Layton res->attrset[i] = 0; 5243aa53ed54SJeff Layton 52441da177e4SLinus Torvalds return decode_delegation(xdr, res); 52451da177e4SLinus Torvalds xdr_error: 52463110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 52471da177e4SLinus Torvalds return -EIO; 5248c0eae66eSBenny Halevy out_overflow: 5249c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5250c0eae66eSBenny Halevy return -EIO; 52511da177e4SLinus Torvalds } 52521da177e4SLinus Torvalds 52531da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 52541da177e4SLinus Torvalds { 52551da177e4SLinus Torvalds int status; 52561da177e4SLinus Torvalds 52571da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5258c1d51931STrond Myklebust if (status != -EIO) 5259c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 526007d30434SBenny Halevy if (!status) 526193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52621da177e4SLinus Torvalds return status; 52631da177e4SLinus Torvalds } 52641da177e4SLinus Torvalds 52651da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 52661da177e4SLinus Torvalds { 52671da177e4SLinus Torvalds int status; 52681da177e4SLinus Torvalds 52691da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5270c1d51931STrond Myklebust if (status != -EIO) 5271c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 527207d30434SBenny Halevy if (!status) 527393b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52741da177e4SLinus Torvalds return status; 52751da177e4SLinus Torvalds } 52761da177e4SLinus Torvalds 52771da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 52781da177e4SLinus Torvalds { 52791da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 52801da177e4SLinus Torvalds } 52811da177e4SLinus Torvalds 52821da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 52831da177e4SLinus Torvalds { 52841da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 52851da177e4SLinus Torvalds } 52861da177e4SLinus Torvalds 52879137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 52889137bdf3SAnna Schumaker struct nfs_pgio_res *res) 52891da177e4SLinus Torvalds { 52908687b63aSAl Viro __be32 *p; 529164bd577eSTrond Myklebust uint32_t count, eof, recvd; 52921da177e4SLinus Torvalds int status; 52931da177e4SLinus Torvalds 52941da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 52951da177e4SLinus Torvalds if (status) 52961da177e4SLinus Torvalds return status; 5297c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5298c0eae66eSBenny Halevy if (unlikely(!p)) 5299c0eae66eSBenny Halevy goto out_overflow; 53006f723f77SBenny Halevy eof = be32_to_cpup(p++); 5301cccddf4fSBenny Halevy count = be32_to_cpup(p); 530264bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 53031da177e4SLinus Torvalds if (count > recvd) { 5304fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 53051da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 53061da177e4SLinus Torvalds count = recvd; 53071da177e4SLinus Torvalds eof = 0; 53081da177e4SLinus Torvalds } 53091da177e4SLinus Torvalds res->eof = eof; 53101da177e4SLinus Torvalds res->count = count; 53111da177e4SLinus Torvalds return 0; 5312c0eae66eSBenny Halevy out_overflow: 5313c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5314c0eae66eSBenny Halevy return -EIO; 53151da177e4SLinus Torvalds } 53161da177e4SLinus Torvalds 53171da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 53181da177e4SLinus Torvalds { 5319bcecff77SChuck Lever int status; 5320cd93710eSChuck Lever __be32 verf[2]; 53211da177e4SLinus Torvalds 53221da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5323db942bbdSBenny Halevy if (!status) 5324db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5325db942bbdSBenny Halevy if (unlikely(status)) 53261da177e4SLinus Torvalds return status; 5327cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 532844109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5329cd93710eSChuck Lever __func__, verf[0], verf[1]); 533064bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 53311da177e4SLinus Torvalds } 53321da177e4SLinus Torvalds 53331da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 53341da177e4SLinus Torvalds { 53351da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5336bcecff77SChuck Lever u32 len, recvd; 53378687b63aSAl Viro __be32 *p; 53381da177e4SLinus Torvalds int status; 53391da177e4SLinus Torvalds 53401da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 53411da177e4SLinus Torvalds if (status) 53421da177e4SLinus Torvalds return status; 53431da177e4SLinus Torvalds 53441da177e4SLinus Torvalds /* Convert length of symlink */ 5345c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5346c0eae66eSBenny Halevy if (unlikely(!p)) 5347c0eae66eSBenny Halevy goto out_overflow; 5348cccddf4fSBenny Halevy len = be32_to_cpup(p); 53491da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5350fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 53511da177e4SLinus Torvalds return -ENAMETOOLONG; 53521da177e4SLinus Torvalds } 535364bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 53541da177e4SLinus Torvalds if (recvd < len) { 5355fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 53561da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 53571da177e4SLinus Torvalds return -EIO; 53581da177e4SLinus Torvalds } 53591da177e4SLinus Torvalds /* 53601da177e4SLinus Torvalds * The XDR encode routine has set things up so that 53611da177e4SLinus Torvalds * the link text will be copied directly into the 53621da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 53631da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 53641da177e4SLinus Torvalds * null-termination). 53651da177e4SLinus Torvalds */ 5366b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 53671da177e4SLinus Torvalds return 0; 5368c0eae66eSBenny Halevy out_overflow: 5369c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5370c0eae66eSBenny Halevy return -EIO; 53711da177e4SLinus Torvalds } 53721da177e4SLinus Torvalds 53731da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 53741da177e4SLinus Torvalds { 53751da177e4SLinus Torvalds int status; 53761da177e4SLinus Torvalds 53771da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 53781da177e4SLinus Torvalds if (status) 53791da177e4SLinus Torvalds goto out; 53801da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 53811da177e4SLinus Torvalds out: 53821da177e4SLinus Torvalds return status; 53831da177e4SLinus Torvalds } 53841da177e4SLinus Torvalds 53851da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 53861da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 53871da177e4SLinus Torvalds { 53881da177e4SLinus Torvalds int status; 53891da177e4SLinus Torvalds 53901da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 53911da177e4SLinus Torvalds if (status) 53921da177e4SLinus Torvalds goto out; 53931da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 53941da177e4SLinus Torvalds goto out; 53951da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 53961da177e4SLinus Torvalds out: 53971da177e4SLinus Torvalds return status; 53981da177e4SLinus Torvalds } 53991da177e4SLinus Torvalds 54001da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 54011da177e4SLinus Torvalds { 54021da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 54031da177e4SLinus Torvalds } 54041da177e4SLinus Torvalds 540556ae19f3STrond Myklebust static int 540656ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 540756ae19f3STrond Myklebust { 540856ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 540956ae19f3STrond Myklebust } 541056ae19f3STrond Myklebust 5411029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5412bf118a34SAndy Adamson struct nfs_getaclres *res) 5413029d105eSJ. Bruce Fields { 5414256e48bbSTrond Myklebust unsigned int savep; 5415029d105eSJ. Bruce Fields uint32_t attrlen, 5416dae100c2SFred Isaman bitmap[3] = {0}; 5417029d105eSJ. Bruce Fields int status; 5418cff298c7STrond Myklebust unsigned int pg_offset; 5419029d105eSJ. Bruce Fields 5420bf118a34SAndy Adamson res->acl_len = 0; 5421029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5422029d105eSJ. Bruce Fields goto out; 54235a006899SSachin Prabhu 5424519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5425519d3959STrond Myklebust 5426cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5427cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 54285a006899SSachin Prabhu 5429029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5430029d105eSJ. Bruce Fields goto out; 5431029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5432029d105eSJ. Bruce Fields goto out; 5433029d105eSJ. Bruce Fields 5434029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5435029d105eSJ. Bruce Fields return -EIO; 5436029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5437029d105eSJ. Bruce Fields 5438bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5439bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5440bf118a34SAndy Adamson * variable length bitmaps.*/ 5441cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5442519d3959STrond Myklebust res->acl_len = attrlen; 54431f1ea6c2STrond Myklebust 54441f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 54451f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 54461f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 54471f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5448519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5449cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5450029d105eSJ. Bruce Fields } 54518c233cf9SJ. Bruce Fields } else 54528c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5453029d105eSJ. Bruce Fields 5454029d105eSJ. Bruce Fields out: 5455029d105eSJ. Bruce Fields return status; 5456029d105eSJ. Bruce Fields } 5457029d105eSJ. Bruce Fields 54581da177e4SLinus Torvalds static int 54591da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 54601da177e4SLinus Torvalds { 54611da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 54621da177e4SLinus Torvalds } 54631da177e4SLinus Torvalds 54649e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 54651da177e4SLinus Torvalds { 54668687b63aSAl Viro __be32 *p; 54671da177e4SLinus Torvalds uint32_t bmlen; 54681da177e4SLinus Torvalds int status; 54691da177e4SLinus Torvalds 54701da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 54711da177e4SLinus Torvalds if (status) 54721da177e4SLinus Torvalds return status; 5473c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5474c0eae66eSBenny Halevy if (unlikely(!p)) 5475c0eae66eSBenny Halevy goto out_overflow; 5476cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5477c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5478c0eae66eSBenny Halevy if (likely(p)) 54791da177e4SLinus Torvalds return 0; 5480c0eae66eSBenny Halevy out_overflow: 5481c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5482c0eae66eSBenny Halevy return -EIO; 54831da177e4SLinus Torvalds } 54841da177e4SLinus Torvalds 5485bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 54861da177e4SLinus Torvalds { 54878687b63aSAl Viro __be32 *p; 54881da177e4SLinus Torvalds uint32_t opnum; 54891da177e4SLinus Torvalds int32_t nfserr; 54901da177e4SLinus Torvalds 5491c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5492c0eae66eSBenny Halevy if (unlikely(!p)) 5493c0eae66eSBenny Halevy goto out_overflow; 54946f723f77SBenny Halevy opnum = be32_to_cpup(p++); 54951da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5496fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 54971da177e4SLinus Torvalds " %d\n", opnum); 54981da177e4SLinus Torvalds return -EIO; 54991da177e4SLinus Torvalds } 5500cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 55011da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5502c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5503c0eae66eSBenny Halevy if (unlikely(!p)) 5504c0eae66eSBenny Halevy goto out_overflow; 5505bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5506bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 55071da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 55081da177e4SLinus Torvalds uint32_t len; 55091da177e4SLinus Torvalds 55101da177e4SLinus Torvalds /* skip netid string */ 5511c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5512c0eae66eSBenny Halevy if (unlikely(!p)) 5513c0eae66eSBenny Halevy goto out_overflow; 5514cccddf4fSBenny Halevy len = be32_to_cpup(p); 5515c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5516c0eae66eSBenny Halevy if (unlikely(!p)) 5517c0eae66eSBenny Halevy goto out_overflow; 55181da177e4SLinus Torvalds 55191da177e4SLinus Torvalds /* skip uaddr string */ 5520c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5521c0eae66eSBenny Halevy if (unlikely(!p)) 5522c0eae66eSBenny Halevy goto out_overflow; 5523cccddf4fSBenny Halevy len = be32_to_cpup(p); 5524c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5525c0eae66eSBenny Halevy if (unlikely(!p)) 5526c0eae66eSBenny Halevy goto out_overflow; 55271da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 55281da177e4SLinus Torvalds } else 5529856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 55301da177e4SLinus Torvalds 55311da177e4SLinus Torvalds return 0; 5532c0eae66eSBenny Halevy out_overflow: 5533c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5534c0eae66eSBenny Halevy return -EIO; 55351da177e4SLinus Torvalds } 55361da177e4SLinus Torvalds 55371da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 55381da177e4SLinus Torvalds { 55391da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 55401da177e4SLinus Torvalds } 55411da177e4SLinus Torvalds 55429137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 55431da177e4SLinus Torvalds { 55448687b63aSAl Viro __be32 *p; 55451da177e4SLinus Torvalds int status; 55461da177e4SLinus Torvalds 55471da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 55481da177e4SLinus Torvalds if (status) 55491da177e4SLinus Torvalds return status; 55501da177e4SLinus Torvalds 55512f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5552c0eae66eSBenny Halevy if (unlikely(!p)) 5553c0eae66eSBenny Halevy goto out_overflow; 55546f723f77SBenny Halevy res->count = be32_to_cpup(p++); 55556f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 55562f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5557c0eae66eSBenny Halevy out_overflow: 5558c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5559c0eae66eSBenny Halevy return -EIO; 55601da177e4SLinus Torvalds } 55611da177e4SLinus Torvalds 55621da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 55631da177e4SLinus Torvalds { 55641da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 55651da177e4SLinus Torvalds } 55661da177e4SLinus Torvalds 5567fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5568fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 55695a5ea0d4SBryan Schumaker { 5570fb15b26fSChuck Lever u32 oid_len; 55715a5ea0d4SBryan Schumaker __be32 *p; 55725a5ea0d4SBryan Schumaker 55735a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55745a5ea0d4SBryan Schumaker if (unlikely(!p)) 55755a5ea0d4SBryan Schumaker goto out_overflow; 5576fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5577fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 55785a5ea0d4SBryan Schumaker goto out_err; 55795a5ea0d4SBryan Schumaker 5580fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 55815a5ea0d4SBryan Schumaker if (unlikely(!p)) 55825a5ea0d4SBryan Schumaker goto out_overflow; 5583fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5584fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 55855a5ea0d4SBryan Schumaker 55865a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 55875a5ea0d4SBryan Schumaker if (unlikely(!p)) 55885a5ea0d4SBryan Schumaker goto out_overflow; 5589fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5590fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 55915a5ea0d4SBryan Schumaker 55925a5ea0d4SBryan Schumaker return 0; 55935a5ea0d4SBryan Schumaker 55945a5ea0d4SBryan Schumaker out_overflow: 55955a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55965a5ea0d4SBryan Schumaker return -EIO; 55975a5ea0d4SBryan Schumaker out_err: 55985a5ea0d4SBryan Schumaker return -EINVAL; 55995a5ea0d4SBryan Schumaker } 56005a5ea0d4SBryan Schumaker 560131e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 56025a5ea0d4SBryan Schumaker { 5603fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5604fb15b26fSChuck Lever unsigned int i, num_flavors; 56055a5ea0d4SBryan Schumaker int status; 56065a5ea0d4SBryan Schumaker __be32 *p; 56075a5ea0d4SBryan Schumaker 56085a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56095a5ea0d4SBryan Schumaker if (unlikely(!p)) 56105a5ea0d4SBryan Schumaker goto out_overflow; 56115a5ea0d4SBryan Schumaker 5612c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5613c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5614c3dfc280SBryan Schumaker 5615c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 56165a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5617c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 56185a5ea0d4SBryan Schumaker break; 56195a5ea0d4SBryan Schumaker 56205a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56215a5ea0d4SBryan Schumaker if (unlikely(!p)) 56225a5ea0d4SBryan Schumaker goto out_overflow; 56235a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 56245a5ea0d4SBryan Schumaker 56255a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5626613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5627613e901eSBryan Schumaker if (status) 5628613e901eSBryan Schumaker goto out; 56295a5ea0d4SBryan Schumaker } 5630c3dfc280SBryan Schumaker res->flavors->num_flavors++; 56315a5ea0d4SBryan Schumaker } 56325a5ea0d4SBryan Schumaker 563331e4dda4SBryan Schumaker status = 0; 5634613e901eSBryan Schumaker out: 5635613e901eSBryan Schumaker return status; 56365a5ea0d4SBryan Schumaker out_overflow: 56375a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 56385a5ea0d4SBryan Schumaker return -EIO; 56395a5ea0d4SBryan Schumaker } 56405a5ea0d4SBryan Schumaker 564131e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 564231e4dda4SBryan Schumaker { 564331e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 564431e4dda4SBryan Schumaker if (status) 564531e4dda4SBryan Schumaker return status; 564631e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 564731e4dda4SBryan Schumaker } 564831e4dda4SBryan Schumaker 564999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 565031e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 565131e4dda4SBryan Schumaker { 565231e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 565331e4dda4SBryan Schumaker if (status) 565431e4dda4SBryan Schumaker return status; 565531e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 565631e4dda4SBryan Schumaker } 565731e4dda4SBryan Schumaker 56582031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 56592031cd1aSWeston Andros Adamson { 56602031cd1aSWeston Andros Adamson __be32 *p; 56612031cd1aSWeston Andros Adamson uint32_t bitmap_words; 56622031cd1aSWeston Andros Adamson unsigned int i; 56632031cd1aSWeston Andros Adamson 56642031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56654edabfd7SPan Bian if (!p) 56664edabfd7SPan Bian return -EIO; 56672031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 56682031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 56692031cd1aSWeston Andros Adamson return -EIO; 56702031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 56712031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 56722031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 56732031cd1aSWeston Andros Adamson 56742031cd1aSWeston Andros Adamson return 0; 56752031cd1aSWeston Andros Adamson } 56762031cd1aSWeston Andros Adamson 567799fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 567899fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 567999fe60d0SBenny Halevy { 568099fe60d0SBenny Halevy __be32 *p; 568199fe60d0SBenny Halevy uint32_t dummy; 56822460ba57SBenny Halevy char *dummy_str; 568399fe60d0SBenny Halevy int status; 56847d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 568599fe60d0SBenny Halevy 568699fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 568799fe60d0SBenny Halevy if (status) 568899fe60d0SBenny Halevy return status; 568999fe60d0SBenny Halevy 5690c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5691c0eae66eSBenny Halevy if (unlikely(!p)) 5692c0eae66eSBenny Halevy goto out_overflow; 569332b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5694c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5695c0eae66eSBenny Halevy if (unlikely(!p)) 5696c0eae66eSBenny Halevy goto out_overflow; 569732b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 569832b01310STrond Myklebust res->flags = be32_to_cpup(p++); 569999fe60d0SBenny Halevy 57002031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 57012031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 57022031cd1aSWeston Andros Adamson case SP4_NONE: 57032031cd1aSWeston Andros Adamson break; 57042031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 57052031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 57062031cd1aSWeston Andros Adamson if (status) 57072031cd1aSWeston Andros Adamson return status; 57082031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 57092031cd1aSWeston Andros Adamson if (status) 57102031cd1aSWeston Andros Adamson return status; 57112031cd1aSWeston Andros Adamson break; 57122031cd1aSWeston Andros Adamson default: 57132031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 571499fe60d0SBenny Halevy return -EIO; 57152031cd1aSWeston Andros Adamson } 571699fe60d0SBenny Halevy 5717acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5718c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5719c0eae66eSBenny Halevy if (unlikely(!p)) 5720c0eae66eSBenny Halevy goto out_overflow; 5721acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 572299fe60d0SBenny Halevy 5723acdeb69dSChuck Lever /* server_owner4.so_major_id */ 57242460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57252460ba57SBenny Halevy if (unlikely(status)) 57262460ba57SBenny Halevy return status; 5727acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5728acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 572978fe0f41SWeston Andros Adamson 5730acdeb69dSChuck Lever /* server_scope4 */ 5731acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5732acdeb69dSChuck Lever if (unlikely(status)) 5733acdeb69dSChuck Lever return status; 573478fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 573578fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 573678fe0f41SWeston Andros Adamson 57377d2ed9acSWeston Andros Adamson /* Implementation Id */ 57387d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 57397d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57407d2ed9acSWeston Andros Adamson goto out_overflow; 57417d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 57427d2ed9acSWeston Andros Adamson 57437d2ed9acSWeston Andros Adamson if (impl_id_count) { 57447d2ed9acSWeston Andros Adamson /* nii_domain */ 57452460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57462460ba57SBenny Halevy if (unlikely(status)) 57472460ba57SBenny Halevy return status; 57487d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 574999fe60d0SBenny Halevy 57507d2ed9acSWeston Andros Adamson /* nii_name */ 57517d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57527d2ed9acSWeston Andros Adamson if (unlikely(status)) 57537d2ed9acSWeston Andros Adamson return status; 57547d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 57557d2ed9acSWeston Andros Adamson 57567d2ed9acSWeston Andros Adamson /* nii_date */ 57577d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 57587d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57597d2ed9acSWeston Andros Adamson goto out_overflow; 57607d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 57617d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 57627d2ed9acSWeston Andros Adamson 57637d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 57647d2ed9acSWeston Andros Adamson } 576599fe60d0SBenny Halevy return 0; 5766c0eae66eSBenny Halevy out_overflow: 5767c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5768c0eae66eSBenny Halevy return -EIO; 576999fe60d0SBenny Halevy } 5770fc931582SAndy Adamson 5771fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5772fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5773fc931582SAndy Adamson { 5774fc931582SAndy Adamson __be32 *p; 5775c9c30dd5SBenny Halevy u32 nr_attrs, val; 5776fc931582SAndy Adamson 5777c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5778c0eae66eSBenny Halevy if (unlikely(!p)) 5779c0eae66eSBenny Halevy goto out_overflow; 5780c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5781c9c30dd5SBenny Halevy if (val) 5782c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 57836f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 57846f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 57856f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 57866f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 57876f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5788cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5789fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5790a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5791a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5792fc931582SAndy Adamson return -EINVAL; 5793fc931582SAndy Adamson } 5794c0eae66eSBenny Halevy if (nr_attrs == 1) { 5795c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5796c0eae66eSBenny Halevy if (unlikely(!p)) 5797c0eae66eSBenny Halevy goto out_overflow; 5798c0eae66eSBenny Halevy } 5799fc931582SAndy Adamson return 0; 5800c0eae66eSBenny Halevy out_overflow: 5801c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5802c0eae66eSBenny Halevy return -EIO; 5803fc931582SAndy Adamson } 5804fc931582SAndy Adamson 5805e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5806e78291e4SBenny Halevy { 5807e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5808fc931582SAndy Adamson } 5809fc931582SAndy Adamson 58107c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 58117c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 58127c44f1aeSWeston Andros Adamson { 58137c44f1aeSWeston Andros Adamson __be32 *p; 58147c44f1aeSWeston Andros Adamson int status; 58157c44f1aeSWeston Andros Adamson 58167c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 58177c44f1aeSWeston Andros Adamson if (!status) 581871a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 58197c44f1aeSWeston Andros Adamson if (unlikely(status)) 58207c44f1aeSWeston Andros Adamson return status; 58217c44f1aeSWeston Andros Adamson 58227c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 58237c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 58247c44f1aeSWeston Andros Adamson if (unlikely(!p)) 58257c44f1aeSWeston Andros Adamson goto out_overflow; 58267c44f1aeSWeston Andros Adamson 58277c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 58287c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 58297c44f1aeSWeston Andros Adamson return -EIO; 58307c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 58317c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 58327c44f1aeSWeston Andros Adamson else 58337c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 58347c44f1aeSWeston Andros Adamson 58357c44f1aeSWeston Andros Adamson return 0; 58367c44f1aeSWeston Andros Adamson out_overflow: 58377c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 58387c44f1aeSWeston Andros Adamson return -EIO; 58397c44f1aeSWeston Andros Adamson } 58407c44f1aeSWeston Andros Adamson 5841fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5842fc931582SAndy Adamson struct nfs41_create_session_res *res) 5843fc931582SAndy Adamson { 5844fc931582SAndy Adamson __be32 *p; 5845fc931582SAndy Adamson int status; 5846fc931582SAndy Adamson 5847fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5848e78291e4SBenny Halevy if (!status) 584979969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5850e78291e4SBenny Halevy if (unlikely(status)) 5851fc931582SAndy Adamson return status; 5852fc931582SAndy Adamson 5853fc931582SAndy Adamson /* seqid, flags */ 5854c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5855c0eae66eSBenny Halevy if (unlikely(!p)) 5856c0eae66eSBenny Halevy goto out_overflow; 585779969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 585879969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5859fc931582SAndy Adamson 5860fc931582SAndy Adamson /* Channel attributes */ 586179969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5862fc931582SAndy Adamson if (!status) 586379969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5864fc931582SAndy Adamson return status; 5865c0eae66eSBenny Halevy out_overflow: 5866c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5867c0eae66eSBenny Halevy return -EIO; 5868fc931582SAndy Adamson } 58690f3e66c6SAndy Adamson 58700f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 58710f3e66c6SAndy Adamson { 58720f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 58730f3e66c6SAndy Adamson } 587418019753SRicardo Labiaga 587566245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 587666245539STrond Myklebust { 587766245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 587866245539STrond Myklebust } 587966245539STrond Myklebust 588018019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 588118019753SRicardo Labiaga { 588218019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 588318019753SRicardo Labiaga } 588499fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 588599fe60d0SBenny Halevy 58869b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 58879b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 58889b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 58899b7b9fccSAndy Adamson { 58909b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5891e3725ec0STrond Myklebust struct nfs4_session *session; 5892fc01cea9SAndy Adamson struct nfs4_sessionid id; 5893fc01cea9SAndy Adamson u32 dummy; 5894fc01cea9SAndy Adamson int status; 5895fc01cea9SAndy Adamson __be32 *p; 5896fc01cea9SAndy Adamson 5897e3725ec0STrond Myklebust if (res->sr_slot == NULL) 58989b7b9fccSAndy Adamson return 0; 58993bd2384aSChuck Lever if (!res->sr_slot->table->session) 59003bd2384aSChuck Lever return 0; 59019b7b9fccSAndy Adamson 5902fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5903e78291e4SBenny Halevy if (!status) 5904e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5905e78291e4SBenny Halevy if (unlikely(status)) 5906fc01cea9SAndy Adamson goto out_err; 59079b7b9fccSAndy Adamson 5908fc01cea9SAndy Adamson /* 5909fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5910fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5911fc01cea9SAndy Adamson */ 5912fdcb4577STrond Myklebust status = -EREMOTEIO; 5913e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5914fc01cea9SAndy Adamson 5915e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5916fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5917fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5918fc01cea9SAndy Adamson goto out_err; 5919fc01cea9SAndy Adamson } 5920e78291e4SBenny Halevy 5921c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5922c0eae66eSBenny Halevy if (unlikely(!p)) 5923c0eae66eSBenny Halevy goto out_overflow; 5924e78291e4SBenny Halevy 5925fc01cea9SAndy Adamson /* seqid */ 59266f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5927dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5928fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5929fc01cea9SAndy Adamson goto out_err; 5930fc01cea9SAndy Adamson } 5931fc01cea9SAndy Adamson /* slot id */ 59326f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5933df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5934fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5935fc01cea9SAndy Adamson goto out_err; 5936fc01cea9SAndy Adamson } 5937da0507b7STrond Myklebust /* highest slot id */ 5938da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5939464ee9f9STrond Myklebust /* target highest slot id */ 5940464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 59410629e370SAlexandros Batsakis /* result flags */ 59420629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5943fc01cea9SAndy Adamson status = 0; 5944fc01cea9SAndy Adamson out_err: 5945fc01cea9SAndy Adamson res->sr_status = status; 5946fc01cea9SAndy Adamson return status; 5947c0eae66eSBenny Halevy out_overflow: 5948c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5949c0eae66eSBenny Halevy status = -EIO; 5950c0eae66eSBenny Halevy goto out_err; 5951fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 59529b7b9fccSAndy Adamson return 0; 5953fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 59549b7b9fccSAndy Adamson } 59559b7b9fccSAndy Adamson 5956b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 595793b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 595893b717fdSTrond Myklebust { 595993b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 596093b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 596193b717fdSTrond Myklebust } 596293b717fdSTrond Myklebust 5963b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 59644e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5965b1f69b75SAndy Adamson { 59664e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5967b1f69b75SAndy Adamson __be32 *p; 5968b1f69b75SAndy Adamson uint32_t len, type; 5969b1f69b75SAndy Adamson int status; 5970b1f69b75SAndy Adamson 5971b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5972b1f69b75SAndy Adamson if (status) { 5973b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5974b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5975b1f69b75SAndy Adamson if (unlikely(!p)) 5976b1f69b75SAndy Adamson goto out_overflow; 5977b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5978b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5979b1f69b75SAndy Adamson __func__, pdev->mincount); 5980b1f69b75SAndy Adamson } 5981b1f69b75SAndy Adamson return status; 5982b1f69b75SAndy Adamson } 5983b1f69b75SAndy Adamson 5984b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5985b1f69b75SAndy Adamson if (unlikely(!p)) 5986b1f69b75SAndy Adamson goto out_overflow; 5987b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5988b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5989b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5990b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5991b1f69b75SAndy Adamson return -EINVAL; 5992b1f69b75SAndy Adamson } 5993b1f69b75SAndy Adamson /* 5994b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5995b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5996b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5997b1f69b75SAndy Adamson */ 5998b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 599913fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 600013fe4ba1STrond Myklebust goto out_overflow; 6001b1f69b75SAndy Adamson 6002b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 6003b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 6004b1f69b75SAndy Adamson if (unlikely(!p)) 6005b1f69b75SAndy Adamson goto out_overflow; 6006b1f69b75SAndy Adamson len = be32_to_cpup(p); 6007b1f69b75SAndy Adamson if (len) { 6008ead00597SChuck Lever uint32_t i; 6009b1f69b75SAndy Adamson 6010b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 6011b1f69b75SAndy Adamson if (unlikely(!p)) 6012b1f69b75SAndy Adamson goto out_overflow; 601384c9dee3SChristoph Hellwig 60144e590803STrond Myklebust res->notification = be32_to_cpup(p++); 601584c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 601684c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 601784c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 6018b1f69b75SAndy Adamson __func__); 6019b1f69b75SAndy Adamson return -EIO; 6020b1f69b75SAndy Adamson } 6021b1f69b75SAndy Adamson } 6022b1f69b75SAndy Adamson } 6023b1f69b75SAndy Adamson return 0; 6024b1f69b75SAndy Adamson out_overflow: 6025b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6026b1f69b75SAndy Adamson return -EIO; 6027b1f69b75SAndy Adamson } 6028b1f69b75SAndy Adamson 6029b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 6030b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6031b1f69b75SAndy Adamson { 6032b1f69b75SAndy Adamson __be32 *p; 6033b1f69b75SAndy Adamson int status; 6034b1f69b75SAndy Adamson u32 layout_count; 603564bd577eSTrond Myklebust u32 recvd; 6036b1f69b75SAndy Adamson 6037b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 6038b1f69b75SAndy Adamson if (status) 6039b1f69b75SAndy Adamson return status; 6040ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6041b1f69b75SAndy Adamson if (unlikely(!p)) 6042b1f69b75SAndy Adamson goto out_overflow; 6043ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 604493b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 6045ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6046ea9d23f5STrond Myklebust if (unlikely(!p)) 6047ea9d23f5STrond Myklebust goto out_overflow; 6048b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 6049b1f69b75SAndy Adamson if (!layout_count) { 6050b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 6051b1f69b75SAndy Adamson __func__); 6052b1f69b75SAndy Adamson return -EINVAL; 6053b1f69b75SAndy Adamson } 6054b1f69b75SAndy Adamson 605535124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 6056b1f69b75SAndy Adamson if (unlikely(!p)) 6057b1f69b75SAndy Adamson goto out_overflow; 6058b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 6059b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 6060b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 6061b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 606235124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 6063b1f69b75SAndy Adamson 6064b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 6065b1f69b75SAndy Adamson __func__, 6066b1f69b75SAndy Adamson (unsigned long)res->range.offset, 6067b1f69b75SAndy Adamson (unsigned long)res->range.length, 6068b1f69b75SAndy Adamson res->range.iomode, 6069b1f69b75SAndy Adamson res->type, 607035124a09SWeston Andros Adamson res->layoutp->len); 6071b1f69b75SAndy Adamson 607264bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 607335124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 607435124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 607535124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 607635124a09SWeston Andros Adamson res->layoutp->len, recvd); 607735124a09SWeston Andros Adamson return -EINVAL; 607835124a09SWeston Andros Adamson } 607935124a09SWeston Andros Adamson 6080b1f69b75SAndy Adamson if (layout_count > 1) { 6081b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 6082b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 6083b1f69b75SAndy Adamson * the client may see a response that is less than the 6084b1f69b75SAndy Adamson * minimum it requested. 6085b1f69b75SAndy Adamson */ 6086b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 6087b1f69b75SAndy Adamson __func__, layout_count); 6088b1f69b75SAndy Adamson } 6089b1f69b75SAndy Adamson 6090b1f69b75SAndy Adamson return 0; 6091b1f69b75SAndy Adamson out_overflow: 6092b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6093b1f69b75SAndy Adamson return -EIO; 6094b1f69b75SAndy Adamson } 6095863a3c6cSAndy Adamson 6096cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 6097cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6098cbe82603SBenny Halevy { 6099cbe82603SBenny Halevy __be32 *p; 6100cbe82603SBenny Halevy int status; 6101cbe82603SBenny Halevy 6102cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 6103cbe82603SBenny Halevy if (status) 6104cbe82603SBenny Halevy return status; 6105cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 6106cbe82603SBenny Halevy if (unlikely(!p)) 6107cbe82603SBenny Halevy goto out_overflow; 6108cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 6109cbe82603SBenny Halevy if (res->lrs_present) 611093b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 6111cbe82603SBenny Halevy return status; 6112cbe82603SBenny Halevy out_overflow: 6113cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 6114cbe82603SBenny Halevy return -EIO; 6115cbe82603SBenny Halevy } 6116cbe82603SBenny Halevy 6117863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 6118863a3c6cSAndy Adamson struct rpc_rqst *req, 6119863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6120863a3c6cSAndy Adamson { 6121863a3c6cSAndy Adamson __be32 *p; 6122863a3c6cSAndy Adamson __u32 sizechanged; 6123863a3c6cSAndy Adamson int status; 6124863a3c6cSAndy Adamson 6125863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 6126db29c089SAndy Adamson res->status = status; 6127863a3c6cSAndy Adamson if (status) 6128863a3c6cSAndy Adamson return status; 6129863a3c6cSAndy Adamson 6130863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 6131863a3c6cSAndy Adamson if (unlikely(!p)) 6132863a3c6cSAndy Adamson goto out_overflow; 6133863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 6134863a3c6cSAndy Adamson 6135863a3c6cSAndy Adamson if (sizechanged) { 6136863a3c6cSAndy Adamson /* throw away new size */ 6137863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 6138863a3c6cSAndy Adamson if (unlikely(!p)) 6139863a3c6cSAndy Adamson goto out_overflow; 6140863a3c6cSAndy Adamson } 6141863a3c6cSAndy Adamson return 0; 6142863a3c6cSAndy Adamson out_overflow: 6143863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 6144863a3c6cSAndy Adamson return -EIO; 6145863a3c6cSAndy Adamson } 61467d974794SBryan Schumaker 61477d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 61487d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 61497d974794SBryan Schumaker { 61507d974794SBryan Schumaker __be32 *p; 61517d974794SBryan Schumaker int status; 61527d974794SBryan Schumaker int num_res; 61537d974794SBryan Schumaker 61547d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 61557d974794SBryan Schumaker if (status) 61567d974794SBryan Schumaker return status; 61577d974794SBryan Schumaker 61587d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61597d974794SBryan Schumaker if (unlikely(!p)) 61607d974794SBryan Schumaker goto out_overflow; 61617d974794SBryan Schumaker num_res = be32_to_cpup(p++); 61627d974794SBryan Schumaker if (num_res != 1) 61637d974794SBryan Schumaker goto out; 61647d974794SBryan Schumaker 61657d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61667d974794SBryan Schumaker if (unlikely(!p)) 61677d974794SBryan Schumaker goto out_overflow; 61687d974794SBryan Schumaker res->status = be32_to_cpup(p++); 61691cab0652SBryan Schumaker 61701cab0652SBryan Schumaker return status; 61717d974794SBryan Schumaker out_overflow: 61727d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 61737d974794SBryan Schumaker out: 61747d974794SBryan Schumaker return -EIO; 61757d974794SBryan Schumaker } 61769aeda35fSBryan Schumaker 61779aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 61789aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 61799aeda35fSBryan Schumaker { 61809f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 61819aeda35fSBryan Schumaker return res->status; 61829aeda35fSBryan Schumaker } 6183cf805165STrond Myklebust #else 6184cf805165STrond Myklebust static inline 6185cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6186cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6187cf805165STrond Myklebust { 6188cf805165STrond Myklebust return 0; 6189cf805165STrond Myklebust } 6190b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6191b1f69b75SAndy Adamson 61921da177e4SLinus Torvalds /* 619349c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 619449c2559eSBenny Halevy */ 619549c2559eSBenny Halevy 619649c2559eSBenny Halevy /* 61971da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 61981da177e4SLinus Torvalds */ 6199bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6200bf269551SChuck Lever struct xdr_stream *xdr, 6201fc016483SChristoph Hellwig void *data) 62021da177e4SLinus Torvalds { 6203fc016483SChristoph Hellwig struct nfs_closeres *res = data; 62041da177e4SLinus Torvalds struct compound_hdr hdr; 62051da177e4SLinus Torvalds int status; 62061da177e4SLinus Torvalds 6207bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62081da177e4SLinus Torvalds if (status) 62091da177e4SLinus Torvalds goto out; 6210bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62119b7b9fccSAndy Adamson if (status) 62129b7b9fccSAndy Adamson goto out; 6213bf269551SChuck Lever status = decode_putfh(xdr); 62141da177e4SLinus Torvalds if (status) 62151da177e4SLinus Torvalds goto out; 6216b6808145STrond Myklebust if (res->lr_res) { 6217b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6218b6808145STrond Myklebust res->lr_ret = status; 6219b6808145STrond Myklebust if (status) 6220b6808145STrond Myklebust goto out; 6221b6808145STrond Myklebust } 6222bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 62231da177e4SLinus Torvalds out: 62241da177e4SLinus Torvalds return status; 62251da177e4SLinus Torvalds } 62261da177e4SLinus Torvalds 62271da177e4SLinus Torvalds /* 62281da177e4SLinus Torvalds * Decode ACCESS response 62291da177e4SLinus Torvalds */ 6230bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6231fc016483SChristoph Hellwig void *data) 62321da177e4SLinus Torvalds { 6233fc016483SChristoph Hellwig struct nfs4_accessres *res = data; 62341da177e4SLinus Torvalds struct compound_hdr hdr; 62351da177e4SLinus Torvalds int status; 62361da177e4SLinus Torvalds 6237bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62389b7b9fccSAndy Adamson if (status) 62399b7b9fccSAndy Adamson goto out; 6240bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62419b7b9fccSAndy Adamson if (status) 62421da177e4SLinus Torvalds goto out; 6243bf269551SChuck Lever status = decode_putfh(xdr); 624476b32999STrond Myklebust if (status != 0) 624576b32999STrond Myklebust goto out; 62466168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 624776b32999STrond Myklebust if (status != 0) 624876b32999STrond Myklebust goto out; 62496926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62501da177e4SLinus Torvalds out: 62511da177e4SLinus Torvalds return status; 62521da177e4SLinus Torvalds } 62531da177e4SLinus Torvalds 62541da177e4SLinus Torvalds /* 62551da177e4SLinus Torvalds * Decode LOOKUP response 62561da177e4SLinus Torvalds */ 6257bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6258fc016483SChristoph Hellwig void *data) 62591da177e4SLinus Torvalds { 6260fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 62611da177e4SLinus Torvalds struct compound_hdr hdr; 62621da177e4SLinus Torvalds int status; 62631da177e4SLinus Torvalds 6264bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62659b7b9fccSAndy Adamson if (status) 62669b7b9fccSAndy Adamson goto out; 6267bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62689b7b9fccSAndy Adamson if (status) 62691da177e4SLinus Torvalds goto out; 6270bf269551SChuck Lever status = decode_putfh(xdr); 6271bf269551SChuck Lever if (status) 62721da177e4SLinus Torvalds goto out; 6273bf269551SChuck Lever status = decode_lookup(xdr); 6274bf269551SChuck Lever if (status) 62751da177e4SLinus Torvalds goto out; 6276bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6277bf269551SChuck Lever if (status) 62781da177e4SLinus Torvalds goto out; 6279aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62801da177e4SLinus Torvalds out: 62811da177e4SLinus Torvalds return status; 62821da177e4SLinus Torvalds } 62831da177e4SLinus Torvalds 62841da177e4SLinus Torvalds /* 62855b5faaf6SJeff Layton * Decode LOOKUPP response 62865b5faaf6SJeff Layton */ 62875b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 62885b5faaf6SJeff Layton void *data) 62895b5faaf6SJeff Layton { 62905b5faaf6SJeff Layton struct nfs4_lookupp_res *res = data; 62915b5faaf6SJeff Layton struct compound_hdr hdr; 62925b5faaf6SJeff Layton int status; 62935b5faaf6SJeff Layton 62945b5faaf6SJeff Layton status = decode_compound_hdr(xdr, &hdr); 62955b5faaf6SJeff Layton if (status) 62965b5faaf6SJeff Layton goto out; 62975b5faaf6SJeff Layton status = decode_sequence(xdr, &res->seq_res, rqstp); 62985b5faaf6SJeff Layton if (status) 62995b5faaf6SJeff Layton goto out; 63005b5faaf6SJeff Layton status = decode_putfh(xdr); 63015b5faaf6SJeff Layton if (status) 63025b5faaf6SJeff Layton goto out; 63035b5faaf6SJeff Layton status = decode_lookupp(xdr); 63045b5faaf6SJeff Layton if (status) 63055b5faaf6SJeff Layton goto out; 63065b5faaf6SJeff Layton status = decode_getfh(xdr, res->fh); 63075b5faaf6SJeff Layton if (status) 63085b5faaf6SJeff Layton goto out; 63095b5faaf6SJeff Layton status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63105b5faaf6SJeff Layton out: 63115b5faaf6SJeff Layton return status; 63125b5faaf6SJeff Layton } 63135b5faaf6SJeff Layton 63145b5faaf6SJeff Layton /* 63151da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 63161da177e4SLinus Torvalds */ 6317bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6318bf269551SChuck Lever struct xdr_stream *xdr, 6319fc016483SChristoph Hellwig void *data) 63201da177e4SLinus Torvalds { 6321fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 63221da177e4SLinus Torvalds struct compound_hdr hdr; 63231da177e4SLinus Torvalds int status; 63241da177e4SLinus Torvalds 6325bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63269b7b9fccSAndy Adamson if (status) 63279b7b9fccSAndy Adamson goto out; 6328bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63299b7b9fccSAndy Adamson if (status) 63301da177e4SLinus Torvalds goto out; 6331bf269551SChuck Lever status = decode_putrootfh(xdr); 6332bf269551SChuck Lever if (status) 63331da177e4SLinus Torvalds goto out; 6334bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6335bf269551SChuck Lever if (status == 0) 6336aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6337aa9c2669SDavid Quigley res->label, res->server); 63381da177e4SLinus Torvalds out: 63391da177e4SLinus Torvalds return status; 63401da177e4SLinus Torvalds } 63411da177e4SLinus Torvalds 63421da177e4SLinus Torvalds /* 63431da177e4SLinus Torvalds * Decode REMOVE response 63441da177e4SLinus Torvalds */ 6345bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6346fc016483SChristoph Hellwig void *data) 63471da177e4SLinus Torvalds { 6348fc016483SChristoph Hellwig struct nfs_removeres *res = data; 63491da177e4SLinus Torvalds struct compound_hdr hdr; 63501da177e4SLinus Torvalds int status; 63511da177e4SLinus Torvalds 6352bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63539b7b9fccSAndy Adamson if (status) 63549b7b9fccSAndy Adamson goto out; 6355bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63569b7b9fccSAndy Adamson if (status) 63571da177e4SLinus Torvalds goto out; 6358bf269551SChuck Lever status = decode_putfh(xdr); 6359bf269551SChuck Lever if (status) 636016e42959STrond Myklebust goto out; 6361bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 63621da177e4SLinus Torvalds out: 63631da177e4SLinus Torvalds return status; 63641da177e4SLinus Torvalds } 63651da177e4SLinus Torvalds 63661da177e4SLinus Torvalds /* 63671da177e4SLinus Torvalds * Decode RENAME response 63681da177e4SLinus Torvalds */ 6369bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6370fc016483SChristoph Hellwig void *data) 63711da177e4SLinus Torvalds { 6372fc016483SChristoph Hellwig struct nfs_renameres *res = data; 63731da177e4SLinus Torvalds struct compound_hdr hdr; 63741da177e4SLinus Torvalds int status; 63751da177e4SLinus Torvalds 6376bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63779b7b9fccSAndy Adamson if (status) 63789b7b9fccSAndy Adamson goto out; 6379bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63809b7b9fccSAndy Adamson if (status) 63811da177e4SLinus Torvalds goto out; 6382bf269551SChuck Lever status = decode_putfh(xdr); 6383bf269551SChuck Lever if (status) 63841da177e4SLinus Torvalds goto out; 6385bf269551SChuck Lever status = decode_savefh(xdr); 6386bf269551SChuck Lever if (status) 63871da177e4SLinus Torvalds goto out; 6388bf269551SChuck Lever status = decode_putfh(xdr); 6389bf269551SChuck Lever if (status) 63901da177e4SLinus Torvalds goto out; 6391bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 63921da177e4SLinus Torvalds out: 63931da177e4SLinus Torvalds return status; 63941da177e4SLinus Torvalds } 63951da177e4SLinus Torvalds 63961da177e4SLinus Torvalds /* 63971da177e4SLinus Torvalds * Decode LINK response 63981da177e4SLinus Torvalds */ 6399bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6400fc016483SChristoph Hellwig void *data) 64011da177e4SLinus Torvalds { 6402fc016483SChristoph Hellwig struct nfs4_link_res *res = data; 64031da177e4SLinus Torvalds struct compound_hdr hdr; 64041da177e4SLinus Torvalds int status; 64051da177e4SLinus Torvalds 6406bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64079b7b9fccSAndy Adamson if (status) 64089b7b9fccSAndy Adamson goto out; 6409bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64109b7b9fccSAndy Adamson if (status) 64111da177e4SLinus Torvalds goto out; 6412bf269551SChuck Lever status = decode_putfh(xdr); 6413bf269551SChuck Lever if (status) 64141da177e4SLinus Torvalds goto out; 6415bf269551SChuck Lever status = decode_savefh(xdr); 6416bf269551SChuck Lever if (status) 64171da177e4SLinus Torvalds goto out; 6418bf269551SChuck Lever status = decode_putfh(xdr); 6419bf269551SChuck Lever if (status) 64201da177e4SLinus Torvalds goto out; 6421bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6422bf269551SChuck Lever if (status) 642391ba2eeeSTrond Myklebust goto out; 642491ba2eeeSTrond Myklebust /* 642591ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 642691ba2eeeSTrond Myklebust * filehandle. 642791ba2eeeSTrond Myklebust */ 6428bf269551SChuck Lever status = decode_restorefh(xdr); 6429bf269551SChuck Lever if (status) 643091ba2eeeSTrond Myklebust goto out; 6431aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64321da177e4SLinus Torvalds out: 64331da177e4SLinus Torvalds return status; 64341da177e4SLinus Torvalds } 64351da177e4SLinus Torvalds 64361da177e4SLinus Torvalds /* 64371da177e4SLinus Torvalds * Decode CREATE response 64381da177e4SLinus Torvalds */ 6439bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6440fc016483SChristoph Hellwig void *data) 64411da177e4SLinus Torvalds { 6442fc016483SChristoph Hellwig struct nfs4_create_res *res = data; 64431da177e4SLinus Torvalds struct compound_hdr hdr; 64441da177e4SLinus Torvalds int status; 64451da177e4SLinus Torvalds 6446bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64479b7b9fccSAndy Adamson if (status) 64489b7b9fccSAndy Adamson goto out; 6449bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64509b7b9fccSAndy Adamson if (status) 64511da177e4SLinus Torvalds goto out; 6452bf269551SChuck Lever status = decode_putfh(xdr); 6453bf269551SChuck Lever if (status) 64541da177e4SLinus Torvalds goto out; 6455bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6456bf269551SChuck Lever if (status) 64571da177e4SLinus Torvalds goto out; 6458bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6459bf269551SChuck Lever if (status) 64601da177e4SLinus Torvalds goto out; 6461aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64621da177e4SLinus Torvalds out: 64631da177e4SLinus Torvalds return status; 64641da177e4SLinus Torvalds } 64651da177e4SLinus Torvalds 64661da177e4SLinus Torvalds /* 64671da177e4SLinus Torvalds * Decode SYMLINK response 64681da177e4SLinus Torvalds */ 6469bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6470fc016483SChristoph Hellwig void *res) 64711da177e4SLinus Torvalds { 6472bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 64731da177e4SLinus Torvalds } 64741da177e4SLinus Torvalds 64751da177e4SLinus Torvalds /* 64761da177e4SLinus Torvalds * Decode GETATTR response 64771da177e4SLinus Torvalds */ 6478bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6479fc016483SChristoph Hellwig void *data) 64801da177e4SLinus Torvalds { 6481fc016483SChristoph Hellwig struct nfs4_getattr_res *res = data; 64821da177e4SLinus Torvalds struct compound_hdr hdr; 64831da177e4SLinus Torvalds int status; 64841da177e4SLinus Torvalds 6485bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64861da177e4SLinus Torvalds if (status) 64871da177e4SLinus Torvalds goto out; 6488bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64899b7b9fccSAndy Adamson if (status) 64909b7b9fccSAndy Adamson goto out; 6491bf269551SChuck Lever status = decode_putfh(xdr); 64921da177e4SLinus Torvalds if (status) 64931da177e4SLinus Torvalds goto out; 6494aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64951da177e4SLinus Torvalds out: 64961da177e4SLinus Torvalds return status; 64971da177e4SLinus Torvalds } 64981da177e4SLinus Torvalds 649923ec6965SJ. Bruce Fields /* 650023ec6965SJ. Bruce Fields * Encode an SETACL request 650123ec6965SJ. Bruce Fields */ 65029f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 6503fcc85819SChristoph Hellwig const void *data) 650423ec6965SJ. Bruce Fields { 6505fcc85819SChristoph Hellwig const struct nfs_setaclargs *args = data; 650623ec6965SJ. Bruce Fields struct compound_hdr hdr = { 650766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 650823ec6965SJ. Bruce Fields }; 650923ec6965SJ. Bruce Fields 65109f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 65119f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 65129f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 65139f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6514d017931cSAndy Adamson encode_nops(&hdr); 651523ec6965SJ. Bruce Fields } 651605d564feSAndy Adamson 651723ec6965SJ. Bruce Fields /* 651823ec6965SJ. Bruce Fields * Decode SETACL response 651923ec6965SJ. Bruce Fields */ 652023ec6965SJ. Bruce Fields static int 6521bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6522fc016483SChristoph Hellwig void *data) 652323ec6965SJ. Bruce Fields { 6524fc016483SChristoph Hellwig struct nfs_setaclres *res = data; 652523ec6965SJ. Bruce Fields struct compound_hdr hdr; 652623ec6965SJ. Bruce Fields int status; 652723ec6965SJ. Bruce Fields 6528bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 652923ec6965SJ. Bruce Fields if (status) 653023ec6965SJ. Bruce Fields goto out; 6531bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65329b7b9fccSAndy Adamson if (status) 65339b7b9fccSAndy Adamson goto out; 6534bf269551SChuck Lever status = decode_putfh(xdr); 653523ec6965SJ. Bruce Fields if (status) 653623ec6965SJ. Bruce Fields goto out; 6537bf269551SChuck Lever status = decode_setattr(xdr); 653823ec6965SJ. Bruce Fields out: 653923ec6965SJ. Bruce Fields return status; 654023ec6965SJ. Bruce Fields } 65411da177e4SLinus Torvalds 65421da177e4SLinus Torvalds /* 6543029d105eSJ. Bruce Fields * Decode GETACL response 6544029d105eSJ. Bruce Fields */ 6545029d105eSJ. Bruce Fields static int 6546bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6547fc016483SChristoph Hellwig void *data) 6548029d105eSJ. Bruce Fields { 6549fc016483SChristoph Hellwig struct nfs_getaclres *res = data; 6550029d105eSJ. Bruce Fields struct compound_hdr hdr; 6551029d105eSJ. Bruce Fields int status; 6552029d105eSJ. Bruce Fields 6553331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6554331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6555331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6556331818f1STrond Myklebust } 6557bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6558029d105eSJ. Bruce Fields if (status) 6559029d105eSJ. Bruce Fields 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); 6564029d105eSJ. Bruce Fields if (status) 6565029d105eSJ. Bruce Fields goto out; 6566bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6567029d105eSJ. Bruce Fields 6568029d105eSJ. Bruce Fields out: 6569029d105eSJ. Bruce Fields return status; 6570029d105eSJ. Bruce Fields } 6571029d105eSJ. Bruce Fields 6572029d105eSJ. Bruce Fields /* 65731da177e4SLinus Torvalds * Decode CLOSE response 65741da177e4SLinus Torvalds */ 6575bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6576fc016483SChristoph Hellwig void *data) 65771da177e4SLinus Torvalds { 6578fc016483SChristoph Hellwig struct nfs_closeres *res = data; 65791da177e4SLinus Torvalds struct compound_hdr hdr; 65801da177e4SLinus Torvalds int status; 65811da177e4SLinus Torvalds 6582bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65831da177e4SLinus Torvalds if (status) 65841da177e4SLinus Torvalds goto out; 6585bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65869b7b9fccSAndy Adamson if (status) 65879b7b9fccSAndy Adamson goto out; 6588bf269551SChuck Lever status = decode_putfh(xdr); 65891da177e4SLinus Torvalds if (status) 65901da177e4SLinus Torvalds goto out; 6591cf805165STrond Myklebust if (res->lr_res) { 6592cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6593cf805165STrond Myklebust res->lr_ret = status; 6594cf805165STrond Myklebust if (status) 6595cf805165STrond Myklebust goto out; 6596cf805165STrond Myklebust } 6597d8d84983STrond Myklebust if (res->fattr != NULL) { 6598d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6599516a6af6STrond Myklebust if (status != 0) 6600516a6af6STrond Myklebust goto out; 6601d8d84983STrond Myklebust } 6602d8d84983STrond Myklebust status = decode_close(xdr, res); 66031da177e4SLinus Torvalds out: 66041da177e4SLinus Torvalds return status; 66051da177e4SLinus Torvalds } 66061da177e4SLinus Torvalds 66071da177e4SLinus Torvalds /* 66081da177e4SLinus Torvalds * Decode OPEN response 66091da177e4SLinus Torvalds */ 6610bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6611fc016483SChristoph Hellwig void *data) 66121da177e4SLinus Torvalds { 6613fc016483SChristoph Hellwig struct nfs_openres *res = data; 66141da177e4SLinus Torvalds struct compound_hdr hdr; 66151da177e4SLinus Torvalds int status; 66161da177e4SLinus Torvalds 6617bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66181da177e4SLinus Torvalds if (status) 66191da177e4SLinus Torvalds goto out; 6620bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66219b7b9fccSAndy Adamson if (status) 66229b7b9fccSAndy Adamson goto out; 6623bf269551SChuck Lever status = decode_putfh(xdr); 66241da177e4SLinus Torvalds if (status) 66251da177e4SLinus Torvalds goto out; 6626bf269551SChuck Lever status = decode_open(xdr, res); 66271da177e4SLinus Torvalds if (status) 66281da177e4SLinus Torvalds goto out; 662901913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 663001913b49SWeston Andros Adamson if (status) 66311da177e4SLinus Torvalds goto out; 6632ae2bb032SWeston Andros Adamson if (res->access_request) 66336168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6634aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 66351da177e4SLinus Torvalds out: 66361da177e4SLinus Torvalds return status; 66371da177e4SLinus Torvalds } 66381da177e4SLinus Torvalds 66391da177e4SLinus Torvalds /* 66401da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 66411da177e4SLinus Torvalds */ 6642bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6643bf269551SChuck Lever struct xdr_stream *xdr, 6644fc016483SChristoph Hellwig void *data) 66451da177e4SLinus Torvalds { 6646fc016483SChristoph Hellwig struct nfs_open_confirmres *res = data; 66471da177e4SLinus Torvalds struct compound_hdr hdr; 66481da177e4SLinus Torvalds int status; 66491da177e4SLinus Torvalds 6650bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66511da177e4SLinus Torvalds if (status) 66521da177e4SLinus Torvalds goto out; 6653bf269551SChuck Lever status = decode_putfh(xdr); 66541da177e4SLinus Torvalds if (status) 66551da177e4SLinus Torvalds goto out; 6656bf269551SChuck Lever status = decode_open_confirm(xdr, res); 66571da177e4SLinus Torvalds out: 66581da177e4SLinus Torvalds return status; 66591da177e4SLinus Torvalds } 66601da177e4SLinus Torvalds 66611da177e4SLinus Torvalds /* 66621da177e4SLinus Torvalds * Decode OPEN response 66631da177e4SLinus Torvalds */ 6664bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6665bf269551SChuck Lever struct xdr_stream *xdr, 6666fc016483SChristoph Hellwig void *data) 66671da177e4SLinus Torvalds { 6668fc016483SChristoph Hellwig struct nfs_openres *res = data; 66691da177e4SLinus Torvalds struct compound_hdr hdr; 66701da177e4SLinus Torvalds int status; 66711da177e4SLinus Torvalds 6672bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66731da177e4SLinus Torvalds if (status) 66741da177e4SLinus Torvalds goto out; 6675bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66769b7b9fccSAndy Adamson if (status) 66779b7b9fccSAndy Adamson goto out; 6678bf269551SChuck Lever status = decode_putfh(xdr); 66791da177e4SLinus Torvalds if (status) 66801da177e4SLinus Torvalds goto out; 6681bf269551SChuck Lever status = decode_open(xdr, res); 6682864472e9STrond Myklebust if (status) 6683864472e9STrond Myklebust goto out; 6684ae2bb032SWeston Andros Adamson if (res->access_request) 66856168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 66866926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 66871da177e4SLinus Torvalds out: 66881da177e4SLinus Torvalds return status; 66891da177e4SLinus Torvalds } 66901da177e4SLinus Torvalds 66911da177e4SLinus Torvalds /* 66921da177e4SLinus Torvalds * Decode SETATTR response 66931da177e4SLinus Torvalds */ 6694bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6695bf269551SChuck Lever struct xdr_stream *xdr, 6696fc016483SChristoph Hellwig void *data) 66971da177e4SLinus Torvalds { 6698fc016483SChristoph Hellwig struct nfs_setattrres *res = data; 66991da177e4SLinus Torvalds struct compound_hdr hdr; 67001da177e4SLinus Torvalds int status; 67011da177e4SLinus Torvalds 6702bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67031da177e4SLinus Torvalds if (status) 67041da177e4SLinus Torvalds goto out; 6705bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67069b7b9fccSAndy Adamson if (status) 67079b7b9fccSAndy Adamson goto out; 6708bf269551SChuck Lever status = decode_putfh(xdr); 67091da177e4SLinus Torvalds if (status) 67101da177e4SLinus Torvalds goto out; 6711bf269551SChuck Lever status = decode_setattr(xdr); 67121da177e4SLinus Torvalds if (status) 67131da177e4SLinus Torvalds goto out; 6714aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 67151da177e4SLinus Torvalds out: 67161da177e4SLinus Torvalds return status; 67171da177e4SLinus Torvalds } 67181da177e4SLinus Torvalds 67191da177e4SLinus Torvalds /* 67201da177e4SLinus Torvalds * Decode LOCK response 67211da177e4SLinus Torvalds */ 6722bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6723fc016483SChristoph Hellwig void *data) 67241da177e4SLinus Torvalds { 6725fc016483SChristoph Hellwig struct nfs_lock_res *res = data; 67261da177e4SLinus Torvalds struct compound_hdr hdr; 67271da177e4SLinus Torvalds int status; 67281da177e4SLinus Torvalds 6729bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67301da177e4SLinus Torvalds if (status) 67311da177e4SLinus Torvalds goto out; 6732bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67339b7b9fccSAndy Adamson if (status) 67349b7b9fccSAndy Adamson goto out; 6735bf269551SChuck Lever status = decode_putfh(xdr); 67361da177e4SLinus Torvalds if (status) 67371da177e4SLinus Torvalds goto out; 6738bf269551SChuck Lever status = decode_lock(xdr, res); 67391da177e4SLinus Torvalds out: 67401da177e4SLinus Torvalds return status; 67411da177e4SLinus Torvalds } 67421da177e4SLinus Torvalds 67431da177e4SLinus Torvalds /* 67441da177e4SLinus Torvalds * Decode LOCKT response 67451da177e4SLinus Torvalds */ 6746bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6747fc016483SChristoph Hellwig void *data) 67481da177e4SLinus Torvalds { 6749fc016483SChristoph Hellwig struct nfs_lockt_res *res = data; 67501da177e4SLinus Torvalds struct compound_hdr hdr; 67511da177e4SLinus Torvalds int status; 67521da177e4SLinus Torvalds 6753bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67541da177e4SLinus Torvalds if (status) 67551da177e4SLinus Torvalds goto out; 6756bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67579b7b9fccSAndy Adamson if (status) 67589b7b9fccSAndy Adamson goto out; 6759bf269551SChuck Lever status = decode_putfh(xdr); 67601da177e4SLinus Torvalds if (status) 67611da177e4SLinus Torvalds goto out; 6762bf269551SChuck Lever status = decode_lockt(xdr, res); 67631da177e4SLinus Torvalds out: 67641da177e4SLinus Torvalds return status; 67651da177e4SLinus Torvalds } 67661da177e4SLinus Torvalds 67671da177e4SLinus Torvalds /* 67681da177e4SLinus Torvalds * Decode LOCKU response 67691da177e4SLinus Torvalds */ 6770bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6771fc016483SChristoph Hellwig void *data) 67721da177e4SLinus Torvalds { 6773fc016483SChristoph Hellwig struct nfs_locku_res *res = data; 67741da177e4SLinus Torvalds struct compound_hdr hdr; 67751da177e4SLinus Torvalds int status; 67761da177e4SLinus Torvalds 6777bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67781da177e4SLinus Torvalds if (status) 67791da177e4SLinus Torvalds goto out; 6780bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67819b7b9fccSAndy Adamson if (status) 67829b7b9fccSAndy Adamson goto out; 6783bf269551SChuck Lever status = decode_putfh(xdr); 67841da177e4SLinus Torvalds if (status) 67851da177e4SLinus Torvalds goto out; 6786bf269551SChuck Lever status = decode_locku(xdr, res); 67871da177e4SLinus Torvalds out: 67881da177e4SLinus Torvalds return status; 67891da177e4SLinus Torvalds } 67901da177e4SLinus Torvalds 6791bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6792bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6793d3c7b7ccSTrond Myklebust { 6794d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6795d3c7b7ccSTrond Myklebust int status; 6796d3c7b7ccSTrond Myklebust 6797bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6798d3c7b7ccSTrond Myklebust if (!status) 6799bf269551SChuck Lever status = decode_release_lockowner(xdr); 6800d3c7b7ccSTrond Myklebust return status; 6801d3c7b7ccSTrond Myklebust } 6802d3c7b7ccSTrond Myklebust 68031da177e4SLinus Torvalds /* 68041da177e4SLinus Torvalds * Decode READLINK response 68051da177e4SLinus Torvalds */ 6806bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6807bf269551SChuck Lever struct xdr_stream *xdr, 6808fc016483SChristoph Hellwig void *data) 68091da177e4SLinus Torvalds { 6810fc016483SChristoph Hellwig struct nfs4_readlink_res *res = data; 68111da177e4SLinus Torvalds struct compound_hdr hdr; 68121da177e4SLinus Torvalds int status; 68131da177e4SLinus Torvalds 6814bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68151da177e4SLinus Torvalds if (status) 68161da177e4SLinus Torvalds goto out; 6817bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68189b7b9fccSAndy Adamson if (status) 68199b7b9fccSAndy Adamson goto out; 6820bf269551SChuck Lever status = decode_putfh(xdr); 68211da177e4SLinus Torvalds if (status) 68221da177e4SLinus Torvalds goto out; 6823bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 68241da177e4SLinus Torvalds out: 68251da177e4SLinus Torvalds return status; 68261da177e4SLinus Torvalds } 68271da177e4SLinus Torvalds 68281da177e4SLinus Torvalds /* 68291da177e4SLinus Torvalds * Decode READDIR response 68301da177e4SLinus Torvalds */ 6831bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6832fc016483SChristoph Hellwig void *data) 68331da177e4SLinus Torvalds { 6834fc016483SChristoph Hellwig struct nfs4_readdir_res *res = data; 68351da177e4SLinus Torvalds struct compound_hdr hdr; 68361da177e4SLinus Torvalds int status; 68371da177e4SLinus Torvalds 6838bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 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_readdir(xdr, rqstp, res); 68481da177e4SLinus Torvalds out: 68491da177e4SLinus Torvalds return status; 68501da177e4SLinus Torvalds } 68511da177e4SLinus Torvalds 68521da177e4SLinus Torvalds /* 68531da177e4SLinus Torvalds * Decode Read response 68541da177e4SLinus Torvalds */ 6855bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6856fc016483SChristoph Hellwig void *data) 68571da177e4SLinus Torvalds { 6858fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 68591da177e4SLinus Torvalds struct compound_hdr hdr; 68601da177e4SLinus Torvalds int status; 68611da177e4SLinus Torvalds 6862bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6863aabff4ddSPeng Tao res->op_status = hdr.status; 68641da177e4SLinus Torvalds if (status) 68651da177e4SLinus Torvalds goto out; 6866bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68679b7b9fccSAndy Adamson if (status) 68689b7b9fccSAndy Adamson goto out; 6869bf269551SChuck Lever status = decode_putfh(xdr); 68701da177e4SLinus Torvalds if (status) 68711da177e4SLinus Torvalds goto out; 6872bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 68731da177e4SLinus Torvalds if (!status) 68741da177e4SLinus Torvalds status = res->count; 68751da177e4SLinus Torvalds out: 68761da177e4SLinus Torvalds return status; 68771da177e4SLinus Torvalds } 68781da177e4SLinus Torvalds 68791da177e4SLinus Torvalds /* 68801da177e4SLinus Torvalds * Decode WRITE response 68811da177e4SLinus Torvalds */ 6882bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6883fc016483SChristoph Hellwig void *data) 68841da177e4SLinus Torvalds { 6885fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 68861da177e4SLinus Torvalds struct compound_hdr hdr; 68871da177e4SLinus Torvalds int status; 68881da177e4SLinus Torvalds 6889bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6890aabff4ddSPeng Tao res->op_status = hdr.status; 68911da177e4SLinus Torvalds if (status) 68921da177e4SLinus Torvalds goto out; 6893bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68949b7b9fccSAndy Adamson if (status) 68959b7b9fccSAndy Adamson goto out; 6896bf269551SChuck Lever status = decode_putfh(xdr); 68971da177e4SLinus Torvalds if (status) 68981da177e4SLinus Torvalds goto out; 6899bf269551SChuck Lever status = decode_write(xdr, res); 69004f9838c7STrond Myklebust if (status) 69014f9838c7STrond Myklebust goto out; 69027ffd1064SFred Isaman if (res->fattr) 69036926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 69041da177e4SLinus Torvalds if (!status) 69051da177e4SLinus Torvalds status = res->count; 69061da177e4SLinus Torvalds out: 69071da177e4SLinus Torvalds return status; 69081da177e4SLinus Torvalds } 69091da177e4SLinus Torvalds 69101da177e4SLinus Torvalds /* 69111da177e4SLinus Torvalds * Decode COMMIT response 69121da177e4SLinus Torvalds */ 6913bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6914fc016483SChristoph Hellwig void *data) 69151da177e4SLinus Torvalds { 6916fc016483SChristoph Hellwig struct nfs_commitres *res = data; 69171da177e4SLinus Torvalds struct compound_hdr hdr; 69181da177e4SLinus Torvalds int status; 69191da177e4SLinus Torvalds 6920bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6921aabff4ddSPeng Tao res->op_status = hdr.status; 69221da177e4SLinus Torvalds if (status) 69231da177e4SLinus Torvalds goto out; 6924bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69259b7b9fccSAndy Adamson if (status) 69269b7b9fccSAndy Adamson goto out; 6927bf269551SChuck Lever status = decode_putfh(xdr); 69281da177e4SLinus Torvalds if (status) 69291da177e4SLinus Torvalds goto out; 6930bf269551SChuck Lever status = decode_commit(xdr, res); 69311da177e4SLinus Torvalds out: 69321da177e4SLinus Torvalds return status; 69331da177e4SLinus Torvalds } 69341da177e4SLinus Torvalds 69351da177e4SLinus Torvalds /* 69368b173218SRicardo Labiaga * Decode FSINFO response 69371da177e4SLinus Torvalds */ 6938bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 6939fc016483SChristoph Hellwig void *data) 69401da177e4SLinus Torvalds { 6941fc016483SChristoph Hellwig struct nfs4_fsinfo_res *res = data; 69421da177e4SLinus Torvalds struct compound_hdr hdr; 69431da177e4SLinus Torvalds int status; 69441da177e4SLinus Torvalds 6945bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69461da177e4SLinus Torvalds if (!status) 6947bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69489b7b9fccSAndy Adamson if (!status) 6949bf269551SChuck Lever status = decode_putfh(xdr); 69501da177e4SLinus Torvalds if (!status) 6951bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 69521da177e4SLinus Torvalds return status; 69531da177e4SLinus Torvalds } 69541da177e4SLinus Torvalds 69551da177e4SLinus Torvalds /* 69568b173218SRicardo Labiaga * Decode PATHCONF response 69571da177e4SLinus Torvalds */ 6958bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6959fc016483SChristoph Hellwig void *data) 69601da177e4SLinus Torvalds { 6961fc016483SChristoph Hellwig struct nfs4_pathconf_res *res = data; 69621da177e4SLinus Torvalds struct compound_hdr hdr; 69631da177e4SLinus Torvalds int status; 69641da177e4SLinus Torvalds 6965bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69661da177e4SLinus Torvalds if (!status) 6967bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69689b7b9fccSAndy Adamson if (!status) 6969bf269551SChuck Lever status = decode_putfh(xdr); 69701da177e4SLinus Torvalds if (!status) 6971bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 69721da177e4SLinus Torvalds return status; 69731da177e4SLinus Torvalds } 69741da177e4SLinus Torvalds 69751da177e4SLinus Torvalds /* 69768b173218SRicardo Labiaga * Decode STATFS response 69771da177e4SLinus Torvalds */ 6978bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 6979fc016483SChristoph Hellwig void *data) 69801da177e4SLinus Torvalds { 6981fc016483SChristoph Hellwig struct nfs4_statfs_res *res = data; 69821da177e4SLinus Torvalds struct compound_hdr hdr; 69831da177e4SLinus Torvalds int status; 69841da177e4SLinus Torvalds 6985bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69861da177e4SLinus Torvalds if (!status) 6987bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69889b7b9fccSAndy Adamson if (!status) 6989bf269551SChuck Lever status = decode_putfh(xdr); 69901da177e4SLinus Torvalds if (!status) 6991bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 69921da177e4SLinus Torvalds return status; 69931da177e4SLinus Torvalds } 69941da177e4SLinus Torvalds 69951da177e4SLinus Torvalds /* 69968b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 69971da177e4SLinus Torvalds */ 6998bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6999bf269551SChuck Lever struct xdr_stream *xdr, 7000fc016483SChristoph Hellwig void *data) 70011da177e4SLinus Torvalds { 7002fc016483SChristoph Hellwig struct nfs4_server_caps_res *res = data; 70031da177e4SLinus Torvalds struct compound_hdr hdr; 70041da177e4SLinus Torvalds int status; 70051da177e4SLinus Torvalds 7006bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70079b7b9fccSAndy Adamson if (status) 70089b7b9fccSAndy Adamson goto out; 7009bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70109b7b9fccSAndy Adamson if (status) 70111da177e4SLinus Torvalds goto out; 7012bf269551SChuck Lever status = decode_putfh(xdr); 7013bf269551SChuck Lever if (status) 70141da177e4SLinus Torvalds goto out; 7015bf269551SChuck Lever status = decode_server_caps(xdr, res); 70161da177e4SLinus Torvalds out: 70171da177e4SLinus Torvalds return status; 70181da177e4SLinus Torvalds } 70191da177e4SLinus Torvalds 70201da177e4SLinus Torvalds /* 70211da177e4SLinus Torvalds * Decode RENEW response 70221da177e4SLinus Torvalds */ 7023bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 7024bf269551SChuck Lever void *__unused) 70251da177e4SLinus Torvalds { 70261da177e4SLinus Torvalds struct compound_hdr hdr; 70271da177e4SLinus Torvalds int status; 70281da177e4SLinus Torvalds 7029bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70301da177e4SLinus Torvalds if (!status) 7031bf269551SChuck Lever status = decode_renew(xdr); 70321da177e4SLinus Torvalds return status; 70331da177e4SLinus Torvalds } 70341da177e4SLinus Torvalds 70351da177e4SLinus Torvalds /* 70368b173218SRicardo Labiaga * Decode SETCLIENTID response 70371da177e4SLinus Torvalds */ 7038bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 7039bf269551SChuck Lever struct xdr_stream *xdr, 7040fc016483SChristoph Hellwig void *data) 70411da177e4SLinus Torvalds { 7042fc016483SChristoph Hellwig struct nfs4_setclientid_res *res = data; 70431da177e4SLinus Torvalds struct compound_hdr hdr; 70441da177e4SLinus Torvalds int status; 70451da177e4SLinus Torvalds 7046bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70471da177e4SLinus Torvalds if (!status) 7048bf269551SChuck Lever status = decode_setclientid(xdr, res); 70491da177e4SLinus Torvalds return status; 70501da177e4SLinus Torvalds } 70511da177e4SLinus Torvalds 70521da177e4SLinus Torvalds /* 70538b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 70541da177e4SLinus Torvalds */ 7055bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 7056fc016483SChristoph Hellwig struct xdr_stream *xdr, 7057fc016483SChristoph Hellwig void *data) 70581da177e4SLinus Torvalds { 70591da177e4SLinus Torvalds struct compound_hdr hdr; 70601da177e4SLinus Torvalds int status; 70611da177e4SLinus Torvalds 7062bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70631da177e4SLinus Torvalds if (!status) 7064bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 70651da177e4SLinus Torvalds return status; 70661da177e4SLinus Torvalds } 70671da177e4SLinus Torvalds 70681da177e4SLinus Torvalds /* 70698b173218SRicardo Labiaga * Decode DELEGRETURN response 70701da177e4SLinus Torvalds */ 7071bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 7072bf269551SChuck Lever struct xdr_stream *xdr, 7073fc016483SChristoph Hellwig void *data) 70741da177e4SLinus Torvalds { 7075fc016483SChristoph Hellwig struct nfs4_delegreturnres *res = data; 70761da177e4SLinus Torvalds struct compound_hdr hdr; 70771da177e4SLinus Torvalds int status; 70781da177e4SLinus Torvalds 7079bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70809b7b9fccSAndy Adamson if (status) 70819b7b9fccSAndy Adamson goto out; 7082bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 70839b7b9fccSAndy Adamson if (status) 7084fa178f29STrond Myklebust goto out; 7085bf269551SChuck Lever status = decode_putfh(xdr); 7086fa178f29STrond Myklebust if (status != 0) 7087fa178f29STrond Myklebust goto out; 7088586f1c39STrond Myklebust if (res->lr_res) { 7089586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 7090586f1c39STrond Myklebust res->lr_ret = status; 7091586f1c39STrond Myklebust if (status) 7092586f1c39STrond Myklebust goto out; 7093586f1c39STrond Myklebust } 70948ac2b422STrond Myklebust if (res->fattr) { 7095e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 7096556ae3bbSJeff Layton if (status != 0) 7097556ae3bbSJeff Layton goto out; 70988ac2b422STrond Myklebust } 7099e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 7100fa178f29STrond Myklebust out: 71011da177e4SLinus Torvalds return status; 71021da177e4SLinus Torvalds } 71031da177e4SLinus Torvalds 7104683b57b4STrond Myklebust /* 71058b173218SRicardo Labiaga * Decode FS_LOCATIONS response 7106683b57b4STrond Myklebust */ 7107bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 7108bf269551SChuck Lever struct xdr_stream *xdr, 7109fc016483SChristoph Hellwig void *data) 7110683b57b4STrond Myklebust { 7111fc016483SChristoph Hellwig struct nfs4_fs_locations_res *res = data; 7112683b57b4STrond Myklebust struct compound_hdr hdr; 7113683b57b4STrond Myklebust int status; 7114683b57b4STrond Myklebust 7115bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71169b7b9fccSAndy Adamson if (status) 71179b7b9fccSAndy Adamson goto out; 7118bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 71199b7b9fccSAndy Adamson if (status) 7120683b57b4STrond Myklebust goto out; 7121bf269551SChuck Lever status = decode_putfh(xdr); 7122bf269551SChuck Lever if (status) 7123683b57b4STrond Myklebust goto out; 7124b03d735bSChuck Lever if (res->migration) { 7125b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7126b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7127b03d735bSChuck Lever &res->fs_locations->fattr, 7128b03d735bSChuck Lever NULL, res->fs_locations, 7129b03d735bSChuck Lever NULL, res->fs_locations->server); 7130b03d735bSChuck Lever if (status) 7131b03d735bSChuck Lever goto out; 7132b03d735bSChuck Lever if (res->renew) 7133b03d735bSChuck Lever status = decode_renew(xdr); 7134b03d735bSChuck Lever } else { 7135bf269551SChuck Lever status = decode_lookup(xdr); 7136bf269551SChuck Lever if (status) 7137683b57b4STrond Myklebust goto out; 7138bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7139b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7140b03d735bSChuck Lever &res->fs_locations->fattr, 71418b7e3f49STrond Myklebust NULL, res->fs_locations, 7142aa9c2669SDavid Quigley NULL, res->fs_locations->server); 7143b03d735bSChuck Lever } 7144683b57b4STrond Myklebust out: 7145683b57b4STrond Myklebust return status; 7146683b57b4STrond Myklebust } 7147683b57b4STrond Myklebust 71485a5ea0d4SBryan Schumaker /* 71495a5ea0d4SBryan Schumaker * Decode SECINFO response 71505a5ea0d4SBryan Schumaker */ 71515a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 71525a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 7153fc016483SChristoph Hellwig void *data) 71545a5ea0d4SBryan Schumaker { 7155fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 71565a5ea0d4SBryan Schumaker struct compound_hdr hdr; 71575a5ea0d4SBryan Schumaker int status; 71585a5ea0d4SBryan Schumaker 71595a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 71605a5ea0d4SBryan Schumaker if (status) 71615a5ea0d4SBryan Schumaker goto out; 71625a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 71635a5ea0d4SBryan Schumaker if (status) 71645a5ea0d4SBryan Schumaker goto out; 71655a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 71665a5ea0d4SBryan Schumaker if (status) 71675a5ea0d4SBryan Schumaker goto out; 71685a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 71695a5ea0d4SBryan Schumaker out: 71705a5ea0d4SBryan Schumaker return status; 71715a5ea0d4SBryan Schumaker } 71725a5ea0d4SBryan Schumaker 717344c99933SChuck Lever /* 717444c99933SChuck Lever * Decode FSID_PRESENT response 717544c99933SChuck Lever */ 717644c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 717744c99933SChuck Lever struct xdr_stream *xdr, 7178fc016483SChristoph Hellwig void *data) 717944c99933SChuck Lever { 7180fc016483SChristoph Hellwig struct nfs4_fsid_present_res *res = data; 718144c99933SChuck Lever struct compound_hdr hdr; 718244c99933SChuck Lever int status; 718344c99933SChuck Lever 718444c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 718544c99933SChuck Lever if (status) 718644c99933SChuck Lever goto out; 718744c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 718844c99933SChuck Lever if (status) 718944c99933SChuck Lever goto out; 719044c99933SChuck Lever status = decode_putfh(xdr); 719144c99933SChuck Lever if (status) 719244c99933SChuck Lever goto out; 719344c99933SChuck Lever status = decode_getfh(xdr, res->fh); 719444c99933SChuck Lever if (status) 719544c99933SChuck Lever goto out; 719644c99933SChuck Lever if (res->renew) 719744c99933SChuck Lever status = decode_renew(xdr); 719844c99933SChuck Lever out: 719944c99933SChuck Lever return status; 720044c99933SChuck Lever } 720144c99933SChuck Lever 720299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 720399fe60d0SBenny Halevy /* 72047c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 72057c44f1aeSWeston Andros Adamson */ 72067c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 72077c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 72087c44f1aeSWeston Andros Adamson void *res) 72097c44f1aeSWeston Andros Adamson { 72107c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 72117c44f1aeSWeston Andros Adamson int status; 72127c44f1aeSWeston Andros Adamson 72137c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 72147c44f1aeSWeston Andros Adamson if (!status) 72157c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 72167c44f1aeSWeston Andros Adamson return status; 72177c44f1aeSWeston Andros Adamson } 72187c44f1aeSWeston Andros Adamson 72197c44f1aeSWeston Andros Adamson /* 72208b173218SRicardo Labiaga * Decode EXCHANGE_ID response 722199fe60d0SBenny Halevy */ 7222bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7223bf269551SChuck Lever struct xdr_stream *xdr, 722499fe60d0SBenny Halevy void *res) 722599fe60d0SBenny Halevy { 722699fe60d0SBenny Halevy struct compound_hdr hdr; 722799fe60d0SBenny Halevy int status; 722899fe60d0SBenny Halevy 7229bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 723099fe60d0SBenny Halevy if (!status) 7231bf269551SChuck Lever status = decode_exchange_id(xdr, res); 723299fe60d0SBenny Halevy return status; 723399fe60d0SBenny Halevy } 72342050f0ccSAndy Adamson 72352050f0ccSAndy Adamson /* 72368b173218SRicardo Labiaga * Decode CREATE_SESSION response 7237fc931582SAndy Adamson */ 7238bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7239bf269551SChuck Lever struct xdr_stream *xdr, 7240fc016483SChristoph Hellwig void *res) 7241fc931582SAndy Adamson { 7242fc931582SAndy Adamson struct compound_hdr hdr; 7243fc931582SAndy Adamson int status; 7244fc931582SAndy Adamson 7245bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7246fc931582SAndy Adamson if (!status) 7247bf269551SChuck Lever status = decode_create_session(xdr, res); 7248fc931582SAndy Adamson return status; 7249fc931582SAndy Adamson } 7250fc931582SAndy Adamson 7251fc931582SAndy Adamson /* 72528b173218SRicardo Labiaga * Decode DESTROY_SESSION response 72530f3e66c6SAndy Adamson */ 7254bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7255bf269551SChuck Lever struct xdr_stream *xdr, 7256bf269551SChuck Lever void *res) 72570f3e66c6SAndy Adamson { 72580f3e66c6SAndy Adamson struct compound_hdr hdr; 72590f3e66c6SAndy Adamson int status; 72600f3e66c6SAndy Adamson 7261bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 72620f3e66c6SAndy Adamson if (!status) 7263bf269551SChuck Lever status = decode_destroy_session(xdr, res); 72640f3e66c6SAndy Adamson return status; 72650f3e66c6SAndy Adamson } 72660f3e66c6SAndy Adamson 72670f3e66c6SAndy Adamson /* 726866245539STrond Myklebust * Decode DESTROY_CLIENTID response 726966245539STrond Myklebust */ 727066245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 727166245539STrond Myklebust struct xdr_stream *xdr, 727266245539STrond Myklebust void *res) 727366245539STrond Myklebust { 727466245539STrond Myklebust struct compound_hdr hdr; 727566245539STrond Myklebust int status; 727666245539STrond Myklebust 727766245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 727866245539STrond Myklebust if (!status) 727966245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 728066245539STrond Myklebust return status; 728166245539STrond Myklebust } 728266245539STrond Myklebust 728366245539STrond Myklebust /* 72848b173218SRicardo Labiaga * Decode SEQUENCE response 7285fc01cea9SAndy Adamson */ 7286bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7287bf269551SChuck Lever struct xdr_stream *xdr, 7288fc016483SChristoph Hellwig void *res) 7289fc01cea9SAndy Adamson { 7290fc01cea9SAndy Adamson struct compound_hdr hdr; 7291fc01cea9SAndy Adamson int status; 7292fc01cea9SAndy Adamson 7293bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7294fc01cea9SAndy Adamson if (!status) 7295bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7296fc01cea9SAndy Adamson return status; 7297fc01cea9SAndy Adamson } 7298fc01cea9SAndy Adamson 7299fc01cea9SAndy Adamson /* 73008b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 73012050f0ccSAndy Adamson */ 7302bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7303bf269551SChuck Lever struct xdr_stream *xdr, 7304fc016483SChristoph Hellwig void *data) 73052050f0ccSAndy Adamson { 7306fc016483SChristoph Hellwig struct nfs4_get_lease_time_res *res = data; 73072050f0ccSAndy Adamson struct compound_hdr hdr; 73082050f0ccSAndy Adamson int status; 73092050f0ccSAndy Adamson 7310bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 73112050f0ccSAndy Adamson if (!status) 7312bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 73132050f0ccSAndy Adamson if (!status) 7314bf269551SChuck Lever status = decode_putrootfh(xdr); 73152050f0ccSAndy Adamson if (!status) 7316bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 73172050f0ccSAndy Adamson return status; 73182050f0ccSAndy Adamson } 731918019753SRicardo Labiaga 732018019753SRicardo Labiaga /* 732118019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 732218019753SRicardo Labiaga */ 7323bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7324bf269551SChuck Lever struct xdr_stream *xdr, 7325fc016483SChristoph Hellwig void *data) 732618019753SRicardo Labiaga { 7327fc016483SChristoph Hellwig struct nfs41_reclaim_complete_res *res = data; 732818019753SRicardo Labiaga struct compound_hdr hdr; 732918019753SRicardo Labiaga int status; 733018019753SRicardo Labiaga 7331bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 733218019753SRicardo Labiaga if (!status) 7333bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 733418019753SRicardo Labiaga if (!status) 73358ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 733618019753SRicardo Labiaga return status; 733718019753SRicardo Labiaga } 7338b1f69b75SAndy Adamson 7339b1f69b75SAndy Adamson /* 7340b1f69b75SAndy Adamson * Decode GETDEVINFO response 7341b1f69b75SAndy Adamson */ 7342bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7343bf269551SChuck Lever struct xdr_stream *xdr, 7344fc016483SChristoph Hellwig void *data) 7345b1f69b75SAndy Adamson { 7346fc016483SChristoph Hellwig struct nfs4_getdeviceinfo_res *res = data; 7347b1f69b75SAndy Adamson struct compound_hdr hdr; 7348b1f69b75SAndy Adamson int status; 7349b1f69b75SAndy Adamson 7350bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7351b1f69b75SAndy Adamson if (status != 0) 7352b1f69b75SAndy Adamson goto out; 7353bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7354b1f69b75SAndy Adamson if (status != 0) 7355b1f69b75SAndy Adamson goto out; 73564e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7357b1f69b75SAndy Adamson out: 7358b1f69b75SAndy Adamson return status; 7359b1f69b75SAndy Adamson } 7360b1f69b75SAndy Adamson 7361b1f69b75SAndy Adamson /* 7362b1f69b75SAndy Adamson * Decode LAYOUTGET response 7363b1f69b75SAndy Adamson */ 7364bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7365bf269551SChuck Lever struct xdr_stream *xdr, 7366fc016483SChristoph Hellwig void *data) 7367b1f69b75SAndy Adamson { 7368fc016483SChristoph Hellwig struct nfs4_layoutget_res *res = data; 7369b1f69b75SAndy Adamson struct compound_hdr hdr; 7370b1f69b75SAndy Adamson int status; 7371b1f69b75SAndy Adamson 7372bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7373b1f69b75SAndy Adamson if (status) 7374b1f69b75SAndy Adamson goto out; 7375bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7376b1f69b75SAndy Adamson if (status) 7377b1f69b75SAndy Adamson goto out; 7378bf269551SChuck Lever status = decode_putfh(xdr); 7379b1f69b75SAndy Adamson if (status) 7380b1f69b75SAndy Adamson goto out; 7381bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7382b1f69b75SAndy Adamson out: 7383b1f69b75SAndy Adamson return status; 7384b1f69b75SAndy Adamson } 7385863a3c6cSAndy Adamson 7386863a3c6cSAndy Adamson /* 7387cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7388cbe82603SBenny Halevy */ 7389cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7390cbe82603SBenny Halevy struct xdr_stream *xdr, 7391fc016483SChristoph Hellwig void *data) 7392cbe82603SBenny Halevy { 7393fc016483SChristoph Hellwig struct nfs4_layoutreturn_res *res = data; 7394cbe82603SBenny Halevy struct compound_hdr hdr; 7395cbe82603SBenny Halevy int status; 7396cbe82603SBenny Halevy 7397cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7398cbe82603SBenny Halevy if (status) 7399cbe82603SBenny Halevy goto out; 7400cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7401cbe82603SBenny Halevy if (status) 7402cbe82603SBenny Halevy goto out; 7403cbe82603SBenny Halevy status = decode_putfh(xdr); 7404cbe82603SBenny Halevy if (status) 7405cbe82603SBenny Halevy goto out; 7406cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7407cbe82603SBenny Halevy out: 7408cbe82603SBenny Halevy return status; 7409cbe82603SBenny Halevy } 7410cbe82603SBenny Halevy 7411cbe82603SBenny Halevy /* 7412863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7413863a3c6cSAndy Adamson */ 7414863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7415863a3c6cSAndy Adamson struct xdr_stream *xdr, 7416fc016483SChristoph Hellwig void *data) 7417863a3c6cSAndy Adamson { 7418fc016483SChristoph Hellwig struct nfs4_layoutcommit_res *res = data; 7419863a3c6cSAndy Adamson struct compound_hdr hdr; 7420863a3c6cSAndy Adamson int status; 7421863a3c6cSAndy Adamson 7422863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7423863a3c6cSAndy Adamson if (status) 7424863a3c6cSAndy Adamson goto out; 7425863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7426863a3c6cSAndy Adamson if (status) 7427863a3c6cSAndy Adamson goto out; 7428863a3c6cSAndy Adamson status = decode_putfh(xdr); 7429863a3c6cSAndy Adamson if (status) 7430863a3c6cSAndy Adamson goto out; 7431863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7432863a3c6cSAndy Adamson if (status) 7433863a3c6cSAndy Adamson goto out; 74346926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7435863a3c6cSAndy Adamson out: 7436863a3c6cSAndy Adamson return status; 7437863a3c6cSAndy Adamson } 7438fca78d6dSBryan Schumaker 7439fca78d6dSBryan Schumaker /* 7440fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7441fca78d6dSBryan Schumaker */ 7442fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7443fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7444fc016483SChristoph Hellwig void *data) 7445fca78d6dSBryan Schumaker { 7446fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 7447fca78d6dSBryan Schumaker struct compound_hdr hdr; 7448fca78d6dSBryan Schumaker int status; 7449fca78d6dSBryan Schumaker 7450fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7451fca78d6dSBryan Schumaker if (status) 7452fca78d6dSBryan Schumaker goto out; 7453fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7454fca78d6dSBryan Schumaker if (status) 7455fca78d6dSBryan Schumaker goto out; 7456fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7457fca78d6dSBryan Schumaker if (status) 7458fca78d6dSBryan Schumaker goto out; 745931e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7460fca78d6dSBryan Schumaker out: 7461fca78d6dSBryan Schumaker return status; 7462fca78d6dSBryan Schumaker } 74637d974794SBryan Schumaker 74647d974794SBryan Schumaker /* 74657d974794SBryan Schumaker * Decode TEST_STATEID response 74667d974794SBryan Schumaker */ 74677d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 74687d974794SBryan Schumaker struct xdr_stream *xdr, 7469fc016483SChristoph Hellwig void *data) 74707d974794SBryan Schumaker { 7471fc016483SChristoph Hellwig struct nfs41_test_stateid_res *res = data; 74727d974794SBryan Schumaker struct compound_hdr hdr; 74737d974794SBryan Schumaker int status; 74747d974794SBryan Schumaker 74757d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 74767d974794SBryan Schumaker if (status) 74777d974794SBryan Schumaker goto out; 74787d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 74797d974794SBryan Schumaker if (status) 74807d974794SBryan Schumaker goto out; 74817d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 74827d974794SBryan Schumaker out: 74837d974794SBryan Schumaker return status; 74847d974794SBryan Schumaker } 74859aeda35fSBryan Schumaker 74869aeda35fSBryan Schumaker /* 74879aeda35fSBryan Schumaker * Decode FREE_STATEID response 74889aeda35fSBryan Schumaker */ 74899aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 74909aeda35fSBryan Schumaker struct xdr_stream *xdr, 7491fc016483SChristoph Hellwig void *data) 74929aeda35fSBryan Schumaker { 7493fc016483SChristoph Hellwig struct nfs41_free_stateid_res *res = data; 74949aeda35fSBryan Schumaker struct compound_hdr hdr; 74959aeda35fSBryan Schumaker int status; 74969aeda35fSBryan Schumaker 74979aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 74989aeda35fSBryan Schumaker if (status) 74999aeda35fSBryan Schumaker goto out; 75009aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 75019aeda35fSBryan Schumaker if (status) 75029aeda35fSBryan Schumaker goto out; 75039aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 75049aeda35fSBryan Schumaker out: 75059aeda35fSBryan Schumaker return status; 75069aeda35fSBryan Schumaker } 750799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 750899fe60d0SBenny Halevy 7509573c4e1eSChuck Lever /** 7510573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7511573c4e1eSChuck Lever * the local page cache. 7512573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7513573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7514573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7515573c4e1eSChuck Lever * 7516573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7517573c4e1eSChuck Lever * returned. 7518573c4e1eSChuck Lever * 7519573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7520573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7521573c4e1eSChuck Lever * on a directory already in our cache. 7522573c4e1eSChuck Lever */ 7523573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7524a7a3b1e9SBenjamin Coddington bool plus) 75251da177e4SLinus Torvalds { 7526256e48bbSTrond Myklebust unsigned int savep; 7527dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 75281da177e4SLinus Torvalds uint32_t len; 7529babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7530babddc72SBryan Schumaker if (unlikely(!p)) 7531babddc72SBryan Schumaker goto out_overflow; 7532c08e76d0SChuck Lever if (*p == xdr_zero) { 7533babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7534babddc72SBryan Schumaker if (unlikely(!p)) 7535babddc72SBryan Schumaker goto out_overflow; 7536c08e76d0SChuck Lever if (*p == xdr_zero) 7537573c4e1eSChuck Lever return -EAGAIN; 75381da177e4SLinus Torvalds entry->eof = 1; 7539573c4e1eSChuck Lever return -EBADCOOKIE; 75401da177e4SLinus Torvalds } 75411da177e4SLinus Torvalds 7542babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7543babddc72SBryan Schumaker if (unlikely(!p)) 7544babddc72SBryan Schumaker goto out_overflow; 75451da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 75461da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7547c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7548babddc72SBryan Schumaker 75499af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7550babddc72SBryan Schumaker if (unlikely(!p)) 7551babddc72SBryan Schumaker goto out_overflow; 75521da177e4SLinus Torvalds entry->name = (const char *) p; 75531da177e4SLinus Torvalds 75541da177e4SLinus Torvalds /* 75551da177e4SLinus Torvalds * In case the server doesn't return an inode number, 75561da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 75571da177e4SLinus Torvalds * since glibc seems to choke on it...) 75581da177e4SLinus Torvalds */ 75591da177e4SLinus Torvalds entry->ino = 1; 75604f082222STrond Myklebust entry->fattr->valid = 0; 75611da177e4SLinus Torvalds 75629af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7563babddc72SBryan Schumaker goto out_overflow; 75649af8c222STrond Myklebust 7565256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7566babddc72SBryan Schumaker goto out_overflow; 75679af8c222STrond Myklebust 7568573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7569aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7570babddc72SBryan Schumaker goto out_overflow; 757128331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 757228331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 757328331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 757482f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 75759af8c222STrond Myklebust 75760b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 75770b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 75780b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 75790b26a0bfSTrond Myklebust 7580573c4e1eSChuck Lever return 0; 7581babddc72SBryan Schumaker 7582babddc72SBryan Schumaker out_overflow: 7583babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7584573c4e1eSChuck Lever return -EAGAIN; 75851da177e4SLinus Torvalds } 75861da177e4SLinus Torvalds 75871da177e4SLinus Torvalds /* 75881da177e4SLinus Torvalds * We need to translate between nfs status return values and 75891da177e4SLinus Torvalds * the local errno values which may not be the same. 75901da177e4SLinus Torvalds */ 75911da177e4SLinus Torvalds static struct { 75921da177e4SLinus Torvalds int stat; 75931da177e4SLinus Torvalds int errno; 75941da177e4SLinus Torvalds } nfs_errtbl[] = { 75951da177e4SLinus Torvalds { NFS4_OK, 0 }, 7596856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7597856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7598856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7599856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7600856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7601856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7602856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7603856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7604856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7605856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7606856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7607856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7608856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7609856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7610856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7611856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7612856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7613856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7614856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7615856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7616856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7617856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7618fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7619856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7620856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7621856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7622856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7623856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7624856dff3dSBenny Halevy { -1, -EIO } 76251da177e4SLinus Torvalds }; 76261da177e4SLinus Torvalds 76271da177e4SLinus Torvalds /* 76281da177e4SLinus Torvalds * Convert an NFS error code to a local one. 76291da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 76301da177e4SLinus Torvalds */ 76311da177e4SLinus Torvalds static int 76320a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 76331da177e4SLinus Torvalds { 76341da177e4SLinus Torvalds int i; 76351da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 76361da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 76371da177e4SLinus Torvalds return nfs_errtbl[i].errno; 76381da177e4SLinus Torvalds } 76391da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 76401da177e4SLinus Torvalds /* The server is looney tunes. */ 7641fdcb4577STrond Myklebust return -EREMOTEIO; 76421da177e4SLinus Torvalds } 76431da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 76441da177e4SLinus Torvalds * handle it. 76451da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 76461da177e4SLinus Torvalds * not conflict with native Linux error codes. 76471da177e4SLinus Torvalds */ 7648856dff3dSBenny Halevy return -stat; 76491da177e4SLinus Torvalds } 76501da177e4SLinus Torvalds 76511c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 76521c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 76531c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 76541c6dcbe5SAnna Schumaker 76551da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 76561da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 76571da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 7658fcc85819SChristoph Hellwig .p_encode = nfs4_xdr_##argtype, \ 7659fc016483SChristoph Hellwig .p_decode = nfs4_xdr_##restype, \ 76602bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 76612bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7662cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7663cc0175c1SChuck Lever .p_name = #proc, \ 76641da177e4SLinus Torvalds } 76651da177e4SLinus Torvalds 76667c61f0d3SAnna Schumaker #define STUB(proc) \ 76677c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 76687c61f0d3SAnna Schumaker .p_name = #proc, \ 76697c61f0d3SAnna Schumaker } 76707c61f0d3SAnna Schumaker 7671511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = { 76721da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 76731da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 76741da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 76751da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 76761da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 76771da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 76781da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 76791da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 76801da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 76811da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 76821da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 76831da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 76841da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 76851da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 76861da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 76871da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 76881da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 76891da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 76901da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 76915b5faaf6SJeff Layton PROC(LOOKUPP, enc_lookupp, dec_lookupp), 76921da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 76931da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 76941da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 76951da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 76961da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 76971da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 76981da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 76991da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 77001da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 77011da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 77021da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 77031da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7704029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 770523ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7706683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7707d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 77085a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 770944c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 771099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 771199fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7712fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 77130f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7714fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 77152050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 771618019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7717b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7718b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7719863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7720cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7721fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 77227d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 77239aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 77247c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 7725ad24ecfbSTrond Myklebust PROC(BIND_CONN_TO_SESSION, 7726ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 772766245539STrond Myklebust PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 772899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 77291c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 77301c6dcbe5SAnna Schumaker PROC(SEEK, enc_seek, dec_seek), 7731f4ac1674SAnna Schumaker PROC(ALLOCATE, enc_allocate, dec_allocate), 7732624bd5b7SAnna Schumaker PROC(DEALLOCATE, enc_deallocate, dec_deallocate), 7733be3a5d23STrond Myklebust PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 773436022770SPeng Tao PROC(CLONE, enc_clone, dec_clone), 77352e72448bSAnna Schumaker PROC(COPY, enc_copy, dec_copy), 77361c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 77371da177e4SLinus Torvalds }; 77381da177e4SLinus Torvalds 7739c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)]; 7740a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 77411da177e4SLinus Torvalds .number = 4, 7742e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 7743c551858aSChristoph Hellwig .procs = nfs4_procedures, 7744c551858aSChristoph Hellwig .counts = nfs_version4_counts, 77451da177e4SLinus Torvalds }; 77461da177e4SLinus Torvalds 77471da177e4SLinus Torvalds /* 77481da177e4SLinus Torvalds * Local variables: 77491da177e4SLinus Torvalds * c-basic-offset: 8 77501da177e4SLinus Torvalds * End: 77511da177e4SLinus Torvalds */ 7752