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) 1622cebf828STrond Myklebust #define encode_share_access_maxsz \ 1632cebf828STrond Myklebust (2) 1644882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1652cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1662cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1672cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1682cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1692cebf828STrond Myklebust open_owner_id_maxsz + \ 1702cebf828STrond Myklebust encode_opentype_maxsz + \ 1712cebf828STrond Myklebust encode_claim_null_maxsz) 1725a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz (3) 1732cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1749104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1755a1f6d9eSTrond Myklebust decode_space_limit_maxsz + \ 1762cebf828STrond Myklebust decode_ace_maxsz) 1772cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1782cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1799104a55dSTrond Myklebust decode_stateid_maxsz + \ 1802cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1812cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1822cebf828STrond Myklebust decode_delegation_maxsz) 1839104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1849104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1859104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1869104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1879104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1889104a55dSTrond Myklebust decode_stateid_maxsz) 1899104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 1909104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1919104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 1929104a55dSTrond Myklebust encode_share_access_maxsz) 1939104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 1949104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1959104a55dSTrond Myklebust decode_stateid_maxsz) 1969104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 1979104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 1989104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 1999104a55dSTrond Myklebust decode_stateid_maxsz) 2009104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 2019104a55dSTrond Myklebust encode_stateid_maxsz + \ 2029104a55dSTrond Myklebust encode_attrs_maxsz) 2039104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 2049104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 2059104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 2069104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2079104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 2089104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 209aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \ 210aa9c2669SDavid Quigley nfs4_label_maxsz) 2119104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 212a7697f6fSChuck Lever decode_verifier_maxsz) 2139104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 2149104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 2159104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2169104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2179104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2189104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2199104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2209104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2219104a55dSTrond Myklebust decode_verifier_maxsz) 2221da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2231da177e4SLinus Torvalds nfs4_name_maxsz) 2246ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2256ce18391SBenny Halevy decode_change_info_maxsz) 2261da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2271da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2286ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2296ce18391SBenny Halevy decode_change_info_maxsz + \ 2306ce18391SBenny Halevy decode_change_info_maxsz) 2311da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2321da177e4SLinus Torvalds nfs4_name_maxsz) 2336ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 234daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2359104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2369104a55dSTrond Myklebust 7 + \ 237daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 238daccbdedSTrond Myklebust encode_lockowner_maxsz) 2399104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2409104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2419104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2429104a55dSTrond Myklebust decode_lock_denied_maxsz) 243daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 244daccbdedSTrond Myklebust encode_lockowner_maxsz) 2459104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2469104a55dSTrond Myklebust decode_lock_denied_maxsz) 2479104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2489104a55dSTrond Myklebust encode_stateid_maxsz + \ 2499104a55dSTrond Myklebust 4) 2509104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2519104a55dSTrond Myklebust decode_stateid_maxsz) 252d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 253d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 254d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 255d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 256d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2579104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2589104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2591da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2601da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 26194a6d753SChuck Lever 1 + \ 26296928206SJ. Bruce Fields nfs4_fattr_maxsz) 2631da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2641da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2659104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2669104a55dSTrond Myklebust encode_attrs_maxsz) 2672cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2682cebf828STrond Myklebust decode_change_info_maxsz + \ 2692cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2709104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2719104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2721da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2731da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2749104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2759104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2769104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2779104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2789104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2799104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 280e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 281e6889620STrond Myklebust (encode_getattr_maxsz) 282e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 283e6889620STrond Myklebust (0) 2845a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2851650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2869b7b9fccSAndy Adamson 2879b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 288fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 289d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 290d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 291fc931582SAndy Adamson 29299fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 29399fe60d0SBenny Halevy encode_verifier_maxsz + \ 29499fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 295b8fb2f59SJeff Layton /* eia_clientowner */ \ 296b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 29799fe60d0SBenny Halevy 1 /* flags */ + \ 29899fe60d0SBenny Halevy 1 /* spa_how */ + \ 2992031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3002031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3012031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 302db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 303db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 304db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 305db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 306d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 307db8ac8baSWeston Andros Adamson 3 /* nii_date */) 30899fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 30999fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 31099fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 31199fe60d0SBenny Halevy 1 /* eir_flags */ + \ 31299fe60d0SBenny Halevy 1 /* spr_how */ + \ 3132031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3142031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3152031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 31699fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 31799fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 31899fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 31999fe60d0SBenny Halevy /* eir_server_scope<> */ \ 32099fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 32199fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 3227d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3237d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3247d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3257d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3267d2ed9acSWeston Andros Adamson 3 /* nii_date */) 327fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 328fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 329fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 330fc931582SAndy Adamson 1 /* ca_rdma_ird */) 331fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 332fc931582SAndy Adamson 2 /* csa_clientid */ + \ 333fc931582SAndy Adamson 1 /* csa_sequence */ + \ 334fc931582SAndy Adamson 1 /* csa_flags */ + \ 335fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 336fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 337fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 338fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 339fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 340fc931582SAndy Adamson 1 /* stamp */ + \ 341fc931582SAndy Adamson 1 /* machinename.len */ + \ 342fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 343fc931582SAndy Adamson 1 /* uid */ + \ 344fc931582SAndy Adamson 1 /* gid */ + \ 345fc931582SAndy Adamson 1 /* gids.len (0) */) 346fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 347fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 348fc931582SAndy Adamson 1 /* csr_sequence */ + \ 349fc931582SAndy Adamson 1 /* csr_flags */ + \ 350fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 351fc931582SAndy Adamson decode_channel_attrs_maxsz) 3527c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3537c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3547c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3557c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3567c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3577c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3587c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3597c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3607c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3617c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3620f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3630f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 36466245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 36566245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 366fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 367fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 368fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 369fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 37018019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 37118019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 37284c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \ 37384c9dee3SChristoph Hellwig XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 37484c9dee3SChristoph Hellwig 1 /* layout type */ + \ 37584c9dee3SChristoph Hellwig 1 /* maxcount */ + \ 37684c9dee3SChristoph Hellwig 1 /* bitmap size */ + \ 37784c9dee3SChristoph Hellwig 1 /* notification bitmap length */ + \ 37884c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 379b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 380b1f69b75SAndy Adamson 1 /* layout type */ + \ 381b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 382b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 383b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 38484c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 385b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 386b1f69b75SAndy Adamson encode_stateid_maxsz) 387b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 388b1f69b75SAndy Adamson decode_stateid_maxsz + \ 389b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 390863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 391863a3c6cSAndy Adamson 2 /* offset */ + \ 392863a3c6cSAndy Adamson 2 /* length */ + \ 393863a3c6cSAndy Adamson 1 /* reclaim */ + \ 394863a3c6cSAndy Adamson encode_stateid_maxsz + \ 395863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 396863a3c6cSAndy Adamson 2 /* last byte written */ + \ 397863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 398863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 3995f919c9fSChristoph Hellwig 1 /* layoutupdate4 opaqueue len */) 4005f919c9fSChristoph Hellwig /* the actual content of layoutupdate4 should 4015f919c9fSChristoph Hellwig be allocated by drivers and spliced in 4025f919c9fSChristoph Hellwig using xdr_write_pages */ 403863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 404cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 405cbe82603SBenny Halevy encode_stateid_maxsz + \ 4066669cb8bSTrond Myklebust 1 + \ 4076669cb8bSTrond Myklebust XDR_QUADLEN(NFS4_OPAQUE_LIMIT)) 408cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 409cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 410fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 411fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 4127d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 4137d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4147d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 4159aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 4169aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4179f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 4189b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 4199b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 4209b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 421cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0 422cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0 4239b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4249b7b9fccSAndy Adamson 4251da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4261da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4271da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4291da177e4SLinus Torvalds encode_putfh_maxsz + \ 4309104a55dSTrond Myklebust encode_read_maxsz) 4311da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4331da177e4SLinus Torvalds decode_putfh_maxsz + \ 4349104a55dSTrond Myklebust decode_read_maxsz) 4351da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4369b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4371da177e4SLinus Torvalds encode_putfh_maxsz + \ 4389104a55dSTrond Myklebust encode_readlink_maxsz) 4391da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4409b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4411da177e4SLinus Torvalds decode_putfh_maxsz + \ 4429104a55dSTrond Myklebust decode_readlink_maxsz) 4431da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4449b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4451da177e4SLinus Torvalds encode_putfh_maxsz + \ 4469104a55dSTrond Myklebust encode_readdir_maxsz) 4471da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4489b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4491da177e4SLinus Torvalds decode_putfh_maxsz + \ 4509104a55dSTrond Myklebust decode_readdir_maxsz) 4511da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4529b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4531da177e4SLinus Torvalds encode_putfh_maxsz + \ 4549104a55dSTrond Myklebust encode_write_maxsz + \ 4554f9838c7STrond Myklebust encode_getattr_maxsz) 4561da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4579b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4581da177e4SLinus Torvalds decode_putfh_maxsz + \ 4599104a55dSTrond Myklebust decode_write_maxsz + \ 4604f9838c7STrond Myklebust decode_getattr_maxsz) 4611da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4629b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4631da177e4SLinus Torvalds encode_putfh_maxsz + \ 4648582715eSTrond Myklebust encode_commit_maxsz) 4651da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4669b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4671da177e4SLinus Torvalds decode_putfh_maxsz + \ 4688582715eSTrond Myklebust decode_commit_maxsz) 4691da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4709b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4711da177e4SLinus Torvalds encode_putfh_maxsz + \ 4722cebf828STrond Myklebust encode_open_maxsz + \ 4736168f62cSWeston Andros Adamson encode_access_maxsz + \ 4742cebf828STrond Myklebust encode_getfh_maxsz + \ 4752cebf828STrond Myklebust encode_getattr_maxsz) 4761da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4779b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4781da177e4SLinus Torvalds decode_putfh_maxsz + \ 4792cebf828STrond Myklebust decode_open_maxsz + \ 4806168f62cSWeston Andros Adamson decode_access_maxsz + \ 4812cebf828STrond Myklebust decode_getfh_maxsz + \ 4822cebf828STrond Myklebust decode_getattr_maxsz) 4831da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4841da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4851da177e4SLinus Torvalds encode_putfh_maxsz + \ 4869104a55dSTrond Myklebust encode_open_confirm_maxsz) 4879104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4889104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4891da177e4SLinus Torvalds decode_putfh_maxsz + \ 4909104a55dSTrond Myklebust decode_open_confirm_maxsz) 4911da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 4929b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4931da177e4SLinus Torvalds encode_putfh_maxsz + \ 4942cebf828STrond Myklebust encode_open_maxsz + \ 4956168f62cSWeston Andros Adamson encode_access_maxsz + \ 4962cebf828STrond Myklebust encode_getattr_maxsz) 4971da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 4989b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4991da177e4SLinus Torvalds decode_putfh_maxsz + \ 5002cebf828STrond Myklebust decode_open_maxsz + \ 5016168f62cSWeston Andros Adamson decode_access_maxsz + \ 5022cebf828STrond Myklebust decode_getattr_maxsz) 5031da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 5041da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5059b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5061da177e4SLinus Torvalds encode_putfh_maxsz + \ 507b6808145STrond Myklebust encode_layoutreturn_maxsz + \ 5083947b74dSTrond Myklebust encode_open_downgrade_maxsz) 5091da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 5101da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5119b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5121da177e4SLinus Torvalds decode_putfh_maxsz + \ 513b6808145STrond Myklebust decode_layoutreturn_maxsz + \ 5143947b74dSTrond Myklebust decode_open_downgrade_maxsz) 5151da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 5169b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5171da177e4SLinus Torvalds encode_putfh_maxsz + \ 518cf805165STrond Myklebust encode_layoutreturn_maxsz + \ 5199104a55dSTrond Myklebust encode_close_maxsz + \ 520516a6af6STrond Myklebust encode_getattr_maxsz) 5211da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 5229b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5231da177e4SLinus Torvalds decode_putfh_maxsz + \ 524cf805165STrond Myklebust decode_layoutreturn_maxsz + \ 5259104a55dSTrond Myklebust decode_close_maxsz + \ 526516a6af6STrond Myklebust decode_getattr_maxsz) 5271da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 5289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5291da177e4SLinus Torvalds encode_putfh_maxsz + \ 5309104a55dSTrond Myklebust encode_setattr_maxsz + \ 5311da177e4SLinus Torvalds encode_getattr_maxsz) 5321da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5339b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5341da177e4SLinus Torvalds decode_putfh_maxsz + \ 5359104a55dSTrond Myklebust decode_setattr_maxsz + \ 5369104a55dSTrond Myklebust decode_getattr_maxsz) 5371da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5389b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5391da177e4SLinus Torvalds encode_putfh_maxsz + \ 5401da177e4SLinus Torvalds encode_fsinfo_maxsz) 5411da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5429b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5431da177e4SLinus Torvalds decode_putfh_maxsz + \ 5441da177e4SLinus Torvalds decode_fsinfo_maxsz) 5451da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5461da177e4SLinus Torvalds encode_renew_maxsz) 5471da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5481da177e4SLinus Torvalds decode_renew_maxsz) 5491da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5501da177e4SLinus Torvalds encode_setclientid_maxsz) 5511da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5521da177e4SLinus Torvalds decode_setclientid_maxsz) 5531da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5541da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 55583ca7f5aSChuck Lever encode_setclientid_confirm_maxsz) 5561da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5571da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 55883ca7f5aSChuck Lever decode_setclientid_confirm_maxsz) 5591da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5609b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5611da177e4SLinus Torvalds encode_putfh_maxsz + \ 5629104a55dSTrond Myklebust encode_lock_maxsz) 5631da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5649b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5651da177e4SLinus Torvalds decode_putfh_maxsz + \ 5669104a55dSTrond Myklebust decode_lock_maxsz) 5671da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5689b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5691da177e4SLinus Torvalds encode_putfh_maxsz + \ 5709104a55dSTrond Myklebust encode_lockt_maxsz) 5719104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5729b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5739104a55dSTrond Myklebust decode_putfh_maxsz + \ 5749104a55dSTrond Myklebust decode_lockt_maxsz) 5751da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5769b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5771da177e4SLinus Torvalds encode_putfh_maxsz + \ 5789104a55dSTrond Myklebust encode_locku_maxsz) 5791da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5809b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5811da177e4SLinus Torvalds decode_putfh_maxsz + \ 5829104a55dSTrond Myklebust decode_locku_maxsz) 583d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 584d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 585d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 586d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 587d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 588d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5891da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5909b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5911da177e4SLinus Torvalds encode_putfh_maxsz + \ 59276b32999STrond Myklebust encode_access_maxsz + \ 59376b32999STrond Myklebust encode_getattr_maxsz) 5941da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5959b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5961da177e4SLinus Torvalds decode_putfh_maxsz + \ 59776b32999STrond Myklebust decode_access_maxsz + \ 59876b32999STrond Myklebust decode_getattr_maxsz) 5991da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 6009b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6011da177e4SLinus Torvalds encode_putfh_maxsz + \ 60244c99933SChuck Lever encode_getattr_maxsz + \ 60344c99933SChuck Lever encode_renew_maxsz) 6041da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 6059b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6061da177e4SLinus Torvalds decode_putfh_maxsz + \ 60744c99933SChuck Lever decode_getattr_maxsz + \ 60844c99933SChuck Lever decode_renew_maxsz) 6091da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 6109b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6111da177e4SLinus Torvalds encode_putfh_maxsz + \ 6121da177e4SLinus Torvalds encode_lookup_maxsz + \ 6131da177e4SLinus Torvalds encode_getattr_maxsz + \ 6141da177e4SLinus Torvalds encode_getfh_maxsz) 6151da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 6169b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6171da177e4SLinus Torvalds decode_putfh_maxsz + \ 618e6889620STrond Myklebust decode_lookup_maxsz + \ 6191da177e4SLinus Torvalds decode_getattr_maxsz + \ 6201da177e4SLinus Torvalds decode_getfh_maxsz) 6211da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 6229b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6231da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 6241da177e4SLinus Torvalds encode_getattr_maxsz + \ 6251da177e4SLinus Torvalds encode_getfh_maxsz) 6261da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6279b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6281da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6291da177e4SLinus Torvalds decode_getattr_maxsz + \ 6301da177e4SLinus Torvalds decode_getfh_maxsz) 6311da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6329b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6331da177e4SLinus Torvalds encode_putfh_maxsz + \ 634778d2817STrond Myklebust encode_remove_maxsz) 6351da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6369b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6371da177e4SLinus Torvalds decode_putfh_maxsz + \ 638778d2817STrond Myklebust decode_remove_maxsz) 6391da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6409b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6411da177e4SLinus Torvalds encode_putfh_maxsz + \ 6421da177e4SLinus Torvalds encode_savefh_maxsz + \ 6431da177e4SLinus Torvalds encode_putfh_maxsz + \ 644778d2817STrond Myklebust encode_rename_maxsz) 6451da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6469b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6471da177e4SLinus Torvalds decode_putfh_maxsz + \ 6481da177e4SLinus Torvalds decode_savefh_maxsz + \ 6491da177e4SLinus Torvalds decode_putfh_maxsz + \ 650778d2817STrond Myklebust decode_rename_maxsz) 6511da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6529b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6531da177e4SLinus Torvalds encode_putfh_maxsz + \ 6541da177e4SLinus Torvalds encode_savefh_maxsz + \ 6551da177e4SLinus Torvalds encode_putfh_maxsz + \ 65691ba2eeeSTrond Myklebust encode_link_maxsz + \ 65791ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 658a9f6991bSTrond Myklebust encode_getattr_maxsz) 6591da177e4SLinus Torvalds #define NFS4_dec_link_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 + \ 66491ba2eeeSTrond Myklebust decode_link_maxsz + \ 66591ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 66691ba2eeeSTrond Myklebust decode_getattr_maxsz) 6671da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6689b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6691da177e4SLinus Torvalds encode_putfh_maxsz + \ 6701da177e4SLinus Torvalds encode_symlink_maxsz + \ 6711da177e4SLinus Torvalds encode_getattr_maxsz + \ 6721da177e4SLinus Torvalds encode_getfh_maxsz) 6731da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6749b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6751da177e4SLinus Torvalds decode_putfh_maxsz + \ 6761da177e4SLinus Torvalds decode_symlink_maxsz + \ 6771da177e4SLinus Torvalds decode_getattr_maxsz + \ 6781da177e4SLinus Torvalds decode_getfh_maxsz) 6791da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6809b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6811da177e4SLinus Torvalds encode_putfh_maxsz + \ 6821da177e4SLinus Torvalds encode_create_maxsz + \ 68356ae19f3STrond Myklebust encode_getfh_maxsz + \ 68456ae19f3STrond Myklebust encode_getattr_maxsz) 6851da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 6869b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6871da177e4SLinus Torvalds decode_putfh_maxsz + \ 6881da177e4SLinus Torvalds decode_create_maxsz + \ 68956ae19f3STrond Myklebust decode_getfh_maxsz + \ 69056ae19f3STrond Myklebust decode_getattr_maxsz) 6911da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 6929b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6931da177e4SLinus Torvalds encode_putfh_maxsz + \ 6941da177e4SLinus Torvalds encode_getattr_maxsz) 6951da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 6969b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6971da177e4SLinus Torvalds decode_putfh_maxsz + \ 6981da177e4SLinus Torvalds decode_getattr_maxsz) 6991da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 7009b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7011da177e4SLinus Torvalds encode_putfh_maxsz + \ 7029104a55dSTrond Myklebust encode_statfs_maxsz) 7031da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 7049b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7051da177e4SLinus Torvalds decode_putfh_maxsz + \ 7069104a55dSTrond Myklebust decode_statfs_maxsz) 7071da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 7089b7b9fccSAndy Adamson encode_sequence_maxsz + \ 709ab91f264STrond Myklebust encode_putfh_maxsz + \ 7101da177e4SLinus Torvalds encode_getattr_maxsz) 7111da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 7129b7b9fccSAndy Adamson decode_sequence_maxsz + \ 713ab91f264STrond Myklebust decode_putfh_maxsz + \ 7141da177e4SLinus Torvalds decode_getattr_maxsz) 7151da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 7169b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7171da177e4SLinus Torvalds encode_putfh_maxsz + \ 718586f1c39STrond Myklebust encode_layoutreturn_maxsz + \ 719fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 720fa178f29STrond Myklebust encode_getattr_maxsz) 7211da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7229b7b9fccSAndy Adamson decode_sequence_maxsz + \ 723d8434d4cSTrond Myklebust decode_putfh_maxsz + \ 724586f1c39STrond Myklebust decode_layoutreturn_maxsz + \ 725fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 726fa178f29STrond Myklebust decode_getattr_maxsz) 727029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 729029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7309104a55dSTrond Myklebust encode_getacl_maxsz) 731029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 733029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7349104a55dSTrond Myklebust decode_getacl_maxsz) 73523ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7369b7b9fccSAndy Adamson encode_sequence_maxsz + \ 73723ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7389104a55dSTrond Myklebust encode_setacl_maxsz) 73923ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7409b7b9fccSAndy Adamson decode_sequence_maxsz + \ 74123ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7429104a55dSTrond Myklebust decode_setacl_maxsz) 743683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 744683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7459b7b9fccSAndy Adamson encode_sequence_maxsz + \ 746683b57b4STrond Myklebust encode_putfh_maxsz + \ 747e6889620STrond Myklebust encode_lookup_maxsz + \ 748b03d735bSChuck Lever encode_fs_locations_maxsz + \ 749b03d735bSChuck Lever encode_renew_maxsz) 750683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 751683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7529b7b9fccSAndy Adamson decode_sequence_maxsz + \ 753683b57b4STrond Myklebust decode_putfh_maxsz + \ 754e6889620STrond Myklebust decode_lookup_maxsz + \ 755b03d735bSChuck Lever decode_fs_locations_maxsz + \ 756b03d735bSChuck Lever decode_renew_maxsz) 7575a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7585a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7595a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7605a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7615a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7625a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7635a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7645a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 76544c99933SChuck Lever #define NFS4_enc_fsid_present_sz \ 76644c99933SChuck Lever (compound_encode_hdr_maxsz + \ 76744c99933SChuck Lever encode_sequence_maxsz + \ 76844c99933SChuck Lever encode_putfh_maxsz + \ 76944c99933SChuck Lever encode_getfh_maxsz + \ 77044c99933SChuck Lever encode_renew_maxsz) 77144c99933SChuck Lever #define NFS4_dec_fsid_present_sz \ 77244c99933SChuck Lever (compound_decode_hdr_maxsz + \ 77344c99933SChuck Lever decode_sequence_maxsz + \ 77444c99933SChuck Lever decode_putfh_maxsz + \ 77544c99933SChuck Lever decode_getfh_maxsz + \ 77644c99933SChuck Lever decode_renew_maxsz) 77799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 7787c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 7797c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 7807c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 7817c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 7827c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 7837c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 78499fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 78599fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 78699fe60d0SBenny Halevy encode_exchange_id_maxsz) 78799fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 78899fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 78999fe60d0SBenny Halevy decode_exchange_id_maxsz) 790fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 791fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 792fc931582SAndy Adamson encode_create_session_maxsz) 793fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 794fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 795fc931582SAndy Adamson decode_create_session_maxsz) 7960f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 7970f3e66c6SAndy Adamson encode_destroy_session_maxsz) 7980f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 7990f3e66c6SAndy Adamson decode_destroy_session_maxsz) 80066245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 80166245539STrond Myklebust encode_destroy_clientid_maxsz) 80266245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 80366245539STrond Myklebust decode_destroy_clientid_maxsz) 804fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 805fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 806fc01cea9SAndy Adamson encode_sequence_maxsz) 807fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 808fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 809fc01cea9SAndy Adamson decode_sequence_maxsz) 8102050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 8112050f0ccSAndy Adamson encode_sequence_maxsz + \ 8122050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 8132050f0ccSAndy Adamson encode_fsinfo_maxsz) 8142050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 8152050f0ccSAndy Adamson decode_sequence_maxsz + \ 8162050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 8172050f0ccSAndy Adamson decode_fsinfo_maxsz) 81818019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 81918019753SRicardo Labiaga encode_sequence_maxsz + \ 82018019753SRicardo Labiaga encode_reclaim_complete_maxsz) 82118019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 82218019753SRicardo Labiaga decode_sequence_maxsz + \ 82318019753SRicardo Labiaga decode_reclaim_complete_maxsz) 824b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 825b1f69b75SAndy Adamson encode_sequence_maxsz +\ 826b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 827b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 828b1f69b75SAndy Adamson decode_sequence_maxsz + \ 829b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 830b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 831b1f69b75SAndy Adamson encode_sequence_maxsz + \ 832b1f69b75SAndy Adamson encode_putfh_maxsz + \ 833b1f69b75SAndy Adamson encode_layoutget_maxsz) 834b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 835b1f69b75SAndy Adamson decode_sequence_maxsz + \ 836b1f69b75SAndy Adamson decode_putfh_maxsz + \ 837b1f69b75SAndy Adamson decode_layoutget_maxsz) 838863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 839863a3c6cSAndy Adamson encode_sequence_maxsz +\ 840863a3c6cSAndy Adamson encode_putfh_maxsz + \ 841863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 842863a3c6cSAndy Adamson encode_getattr_maxsz) 843863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 844863a3c6cSAndy Adamson decode_sequence_maxsz + \ 845863a3c6cSAndy Adamson decode_putfh_maxsz + \ 846863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 847863a3c6cSAndy Adamson decode_getattr_maxsz) 848cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 849cbe82603SBenny Halevy encode_sequence_maxsz + \ 850cbe82603SBenny Halevy encode_putfh_maxsz + \ 851cbe82603SBenny Halevy encode_layoutreturn_maxsz) 852cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 853cbe82603SBenny Halevy decode_sequence_maxsz + \ 854cbe82603SBenny Halevy decode_putfh_maxsz + \ 855cbe82603SBenny Halevy decode_layoutreturn_maxsz) 856fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 857fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 858fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 859fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 860fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 861fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 862fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 863fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8647d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8657d974794SBryan Schumaker encode_sequence_maxsz + \ 8667d974794SBryan Schumaker encode_test_stateid_maxsz) 8677d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8687d974794SBryan Schumaker decode_sequence_maxsz + \ 8697d974794SBryan Schumaker decode_test_stateid_maxsz) 8709aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8719aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8729aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8739aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8749aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8759aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8762449ea2eSAlexandros Batsakis 8772449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8782449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8792449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8802449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8812449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8822449ea2eSAlexandros Batsakis XDR_UNIT); 8832449ea2eSAlexandros Batsakis 8842449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8852449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 8862449ea2eSAlexandros Batsakis decode_sequence_maxsz + 8872449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 8882449ea2eSAlexandros Batsakis XDR_UNIT); 889f1c097beSAndy Adamson 890f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH + 891f1c097beSAndy Adamson compound_decode_hdr_maxsz + 892f1c097beSAndy Adamson decode_sequence_maxsz) * 893f1c097beSAndy Adamson XDR_UNIT); 894f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 89599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 8961da177e4SLinus Torvalds 897bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 898bca79478STrond Myklebust [NF4BAD] = 0, 899bca79478STrond Myklebust [NF4REG] = S_IFREG, 900bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 901bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 902bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 903bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 904bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 905bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 906bca79478STrond Myklebust [NF4ATTRDIR] = 0, 907bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 9081da177e4SLinus Torvalds }; 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds struct compound_hdr { 9111da177e4SLinus Torvalds int32_t status; 9121da177e4SLinus Torvalds uint32_t nops; 913d017931cSAndy Adamson __be32 * nops_p; 9141da177e4SLinus Torvalds uint32_t taglen; 9151da177e4SLinus Torvalds char * tag; 9160c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 91766cc0429SBenny Halevy u32 minorversion; 9181da177e4SLinus Torvalds }; 9191da177e4SLinus Torvalds 92013c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 92113c65ce9SBenny Halevy { 92213c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 92313c65ce9SBenny Halevy BUG_ON(!p); 92413c65ce9SBenny Halevy return p; 92513c65ce9SBenny Halevy } 9261da177e4SLinus Torvalds 927cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 928cb17e556STrond Myklebust { 929ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); 930cb17e556STrond Myklebust } 931cb17e556STrond Myklebust 9321da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 9331da177e4SLinus Torvalds { 934ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0); 9351da177e4SLinus Torvalds } 9361da177e4SLinus Torvalds 9374ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9384ade9821STrond Myklebust { 939ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0); 9404ade9821STrond Myklebust } 9414ade9821STrond Myklebust 942ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 943ff2eb681STrond Myklebust { 944ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0); 945ff2eb681STrond Myklebust } 946ff2eb681STrond Myklebust 9474ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9484ade9821STrond Myklebust const struct nfs_seqid *seqid) 9494ade9821STrond Myklebust { 950a6796419STrond Myklebust if (seqid != NULL) 9514ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 952a6796419STrond Myklebust else 953a6796419STrond Myklebust encode_uint32(xdr, 0); 9544ade9821STrond Myklebust } 9554ade9821STrond Myklebust 9560c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9570c4e8c18SBenny Halevy struct rpc_rqst *req, 9580c4e8c18SBenny Halevy struct compound_hdr *hdr) 9591da177e4SLinus Torvalds { 9608687b63aSAl Viro __be32 *p; 961a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9620c4e8c18SBenny Halevy 9630c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9640c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9650c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9660c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9671da177e4SLinus Torvalds 9687fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 9696fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9706fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 971e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 972d017931cSAndy Adamson hdr->nops_p = p; 97334558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 974d017931cSAndy Adamson } 975d017931cSAndy Adamson 976ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 977ab19b481STrond Myklebust uint32_t replen, 978ab19b481STrond Myklebust struct compound_hdr *hdr) 979ab19b481STrond Myklebust { 980ab19b481STrond Myklebust encode_uint32(xdr, op); 981ab19b481STrond Myklebust hdr->nops++; 982ab19b481STrond Myklebust hdr->replen += replen; 983ab19b481STrond Myklebust } 984ab19b481STrond Myklebust 985d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 986d017931cSAndy Adamson { 9877fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 988d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 9891da177e4SLinus Torvalds } 9901da177e4SLinus Torvalds 991ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 992ea9d23f5STrond Myklebust { 9932d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 994ea9d23f5STrond Myklebust } 995ea9d23f5STrond Myklebust 9961da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 9971da177e4SLinus Torvalds { 998cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 1001aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1002aa9c2669SDavid Quigley const struct nfs4_label *label, 10035334c5bdSKinglong Mee const struct nfs_server *server, 1004dff25ddbSAndreas Gruenbacher bool excl_check, const umode_t *umask) 10051da177e4SLinus Torvalds { 10061da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10071da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10081da177e4SLinus Torvalds int owner_namelen = 0; 10091da177e4SLinus Torvalds int owner_grouplen = 0; 10108687b63aSAl Viro __be32 *p; 1011d7067b2dSTrond Myklebust unsigned i; 1012d7067b2dSTrond Myklebust uint32_t len = 0; 1013d7067b2dSTrond Myklebust uint32_t bmval_len; 1014d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds /* 10171da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10181da177e4SLinus Torvalds */ 1019d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_SIZE) { 1020d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10211da177e4SLinus Torvalds len += 8; 1022d7067b2dSTrond Myklebust } 1023dff25ddbSAndreas Gruenbacher if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) 1024dff25ddbSAndreas Gruenbacher umask = NULL; 1025d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 1026dff25ddbSAndreas Gruenbacher if (umask) { 1027dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK; 1028dff25ddbSAndreas Gruenbacher len += 8; 1029dff25ddbSAndreas Gruenbacher } else { 1030d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10311da177e4SLinus Torvalds len += 4; 1032d7067b2dSTrond Myklebust } 1033dff25ddbSAndreas Gruenbacher } 10341da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 1035e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10361da177e4SLinus Torvalds if (owner_namelen < 0) { 1037fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1038e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 10391da177e4SLinus Torvalds /* XXX */ 10401da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10411da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10421da177e4SLinus Torvalds /* goto out; */ 10431da177e4SLinus Torvalds } 1044d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 10451da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10461da177e4SLinus Torvalds } 10471da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 1048e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10491da177e4SLinus Torvalds if (owner_grouplen < 0) { 1050fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1051e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 10521da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10531da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10541da177e4SLinus Torvalds /* goto out; */ 10551da177e4SLinus Torvalds } 1056d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 10571da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10581da177e4SLinus Torvalds } 1059d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1060d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10611da177e4SLinus Torvalds len += 16; 1062d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1063d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10641da177e4SLinus Torvalds len += 4; 1065d7067b2dSTrond Myklebust } 1066d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1067d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10681da177e4SLinus Torvalds len += 16; 1069d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1070d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10711da177e4SLinus Torvalds len += 4; 1072d7067b2dSTrond Myklebust } 10735334c5bdSKinglong Mee 10745334c5bdSKinglong Mee if (excl_check) { 10755334c5bdSKinglong Mee const u32 *excl_bmval = server->exclcreat_bitmask; 10765334c5bdSKinglong Mee bmval[0] &= excl_bmval[0]; 10775334c5bdSKinglong Mee bmval[1] &= excl_bmval[1]; 10785334c5bdSKinglong Mee bmval[2] &= excl_bmval[2]; 10795334c5bdSKinglong Mee 10805334c5bdSKinglong Mee if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) 10815334c5bdSKinglong Mee label = NULL; 10825334c5bdSKinglong Mee } 10835334c5bdSKinglong Mee 1084b4a2cf76STrond Myklebust if (label) { 1085b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1086d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1087d7067b2dSTrond Myklebust } 1088d7067b2dSTrond Myklebust 1089d7067b2dSTrond Myklebust if (bmval[2] != 0) 1090b4a2cf76STrond Myklebust bmval_len = 3; 1091d7067b2dSTrond Myklebust else if (bmval[1] != 0) 1092d7067b2dSTrond Myklebust bmval_len = 2; 1093d7067b2dSTrond Myklebust else 1094d7067b2dSTrond Myklebust bmval_len = 1; 1095b4a2cf76STrond Myklebust 1096d7067b2dSTrond Myklebust p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len); 10971da177e4SLinus Torvalds 1098b4a2cf76STrond Myklebust *p++ = cpu_to_be32(bmval_len); 1099d7067b2dSTrond Myklebust for (i = 0; i < bmval_len; i++) 1100d7067b2dSTrond Myklebust *p++ = cpu_to_be32(bmval[i]); 1101d7067b2dSTrond Myklebust *p++ = cpu_to_be32(len); 11021da177e4SLinus Torvalds 1103d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1104b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1105d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1106e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1107d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1108811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1109d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1110811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1111d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11121da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1113e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1114042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec); 1115d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 1116d7067b2dSTrond Myklebust } else 1117e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11181da177e4SLinus Torvalds } 1119d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11201da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1121e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1122042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec); 1123e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 1124d7067b2dSTrond Myklebust } else 1125e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11261da177e4SLinus Torvalds } 1127d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1128aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1129aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1130aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1131aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1132aa9c2669SDavid Quigley } 1133dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1134dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1135dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask); 1136dff25ddbSAndreas Gruenbacher } 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds /* out: */ 11391da177e4SLinus Torvalds } 11401da177e4SLinus Torvalds 1141cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11421da177e4SLinus Torvalds { 1143475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1144475d4ba0STrond Myklebust encode_uint32(xdr, access); 11451da177e4SLinus Torvalds } 11461da177e4SLinus Torvalds 1147cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11481da177e4SLinus Torvalds { 1149ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11504ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1151566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11521da177e4SLinus Torvalds } 11531da177e4SLinus Torvalds 11540b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11551da177e4SLinus Torvalds { 11568687b63aSAl Viro __be32 *p; 11571da177e4SLinus Torvalds 1158475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1159475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1160b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 116134558513SBenny Halevy *p = cpu_to_be32(args->count); 11621da177e4SLinus Torvalds } 11631da177e4SLinus Torvalds 1164cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11651da177e4SLinus Torvalds { 11668687b63aSAl Viro __be32 *p; 11671da177e4SLinus Torvalds 1168475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1169475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11701da177e4SLinus Torvalds 11711da177e4SLinus Torvalds switch (create->ftype) { 11721da177e4SLinus Torvalds case NF4LNK: 117313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 117434558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 11752fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 11762fcc213aSChuck Lever create->u.symlink.len); 11772fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 11781da177e4SLinus Torvalds break; 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 118113c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1182e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 118334558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11841da177e4SLinus Torvalds break; 11851da177e4SLinus Torvalds 11861da177e4SLinus Torvalds default: 11871da177e4SLinus Torvalds break; 11881da177e4SLinus Torvalds } 11891da177e4SLinus Torvalds 1190811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 1191dff25ddbSAndreas Gruenbacher encode_attrs(xdr, create->attrs, create->label, create->server, false, 1192dff25ddbSAndreas Gruenbacher &create->umask); 11931da177e4SLinus Torvalds } 11941da177e4SLinus Torvalds 1195cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11961da177e4SLinus Torvalds { 11978687b63aSAl Viro __be32 *p; 11981da177e4SLinus Torvalds 1199475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1200475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1201e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 120234558513SBenny Halevy *p = cpu_to_be32(bitmap); 12031da177e4SLinus Torvalds } 12041da177e4SLinus Torvalds 1205cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 12061da177e4SLinus Torvalds { 12078687b63aSAl Viro __be32 *p; 12081da177e4SLinus Torvalds 1209475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1210475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1211e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1212e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 121334558513SBenny Halevy *p = cpu_to_be32(bm1); 12141da177e4SLinus Torvalds } 12151da177e4SLinus Torvalds 1216dae100c2SFred Isaman static void 1217dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1218dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1219dae100c2SFred Isaman struct compound_hdr *hdr) 1220dae100c2SFred Isaman { 1221dae100c2SFred Isaman __be32 *p; 1222dae100c2SFred Isaman 1223ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1224dae100c2SFred Isaman if (bm2) { 1225dae100c2SFred Isaman p = reserve_space(xdr, 16); 1226dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1227dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1228dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1229dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1230dae100c2SFred Isaman } else if (bm1) { 1231dae100c2SFred Isaman p = reserve_space(xdr, 12); 1232dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1233dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1234dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1235dae100c2SFred Isaman } else { 1236dae100c2SFred Isaman p = reserve_space(xdr, 8); 1237dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1238dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1239dae100c2SFred Isaman } 1240dae100c2SFred Isaman } 1241dae100c2SFred Isaman 1242cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12431da177e4SLinus Torvalds { 1244a09df2caSDavid Quigley encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1245a09df2caSDavid Quigley bitmask[1] & nfs4_fattr_bitmap[1], 1246a09df2caSDavid Quigley bitmask[2] & nfs4_fattr_bitmap[2], 1247a09df2caSDavid Quigley hdr); 12481da177e4SLinus Torvalds } 12491da177e4SLinus Torvalds 125088034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12511549210fSTrond Myklebust const u32 *open_bitmap, 125288034c3dSAndy Adamson struct compound_hdr *hdr) 125388034c3dSAndy Adamson { 125488034c3dSAndy Adamson encode_getattr_three(xdr, 12551549210fSTrond Myklebust bitmask[0] & open_bitmap[0], 12561549210fSTrond Myklebust bitmask[1] & open_bitmap[1], 12571549210fSTrond Myklebust bitmask[2] & open_bitmap[2], 125888034c3dSAndy Adamson hdr); 125988034c3dSAndy Adamson } 126088034c3dSAndy Adamson 1261cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12621da177e4SLinus Torvalds { 1263dae100c2SFred Isaman encode_getattr_three(xdr, 1264dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1265dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1266dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1267dae100c2SFred Isaman hdr); 12681da177e4SLinus Torvalds } 12691da177e4SLinus Torvalds 1270cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1271830b8e33SManoj Naik { 1272cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1273cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1274830b8e33SManoj Naik } 1275830b8e33SManoj Naik 1276cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12771da177e4SLinus Torvalds { 1278ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12791da177e4SLinus Torvalds } 12801da177e4SLinus Torvalds 1281cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12821da177e4SLinus Torvalds { 1283ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12846fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12851da177e4SLinus Torvalds } 12861da177e4SLinus Torvalds 1287911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1288911d1aafSTrond Myklebust { 1289f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1290911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1291911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1292911d1aafSTrond Myklebust } 1293911d1aafSTrond Myklebust 1294911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1295911d1aafSTrond Myklebust { 1296911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1297911d1aafSTrond Myklebust return ~(uint64_t)0; 1298911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1299911d1aafSTrond Myklebust } 1300911d1aafSTrond Myklebust 1301daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1302daccbdedSTrond Myklebust { 1303daccbdedSTrond Myklebust __be32 *p; 1304daccbdedSTrond Myklebust 1305d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1306daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1307d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1308daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1309d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1310daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1311daccbdedSTrond Myklebust } 1312daccbdedSTrond Myklebust 13131da177e4SLinus Torvalds /* 13141da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13151da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13161da177e4SLinus Torvalds */ 1317cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13181da177e4SLinus Torvalds { 13198687b63aSAl Viro __be32 *p; 13201da177e4SLinus Torvalds 1321475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1322475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1323e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1324e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1325b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1326b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 132734558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1328911d1aafSTrond Myklebust if (args->new_lock_owner){ 13294ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1330425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13314ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1332daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13331da177e4SLinus Torvalds } 13341da177e4SLinus Torvalds else { 1335425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13364ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13371da177e4SLinus Torvalds } 13381da177e4SLinus Torvalds } 13391da177e4SLinus Torvalds 1340cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13411da177e4SLinus Torvalds { 13428687b63aSAl Viro __be32 *p; 13431da177e4SLinus Torvalds 1344475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1345475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1346e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1347b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1348b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1349daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13501da177e4SLinus Torvalds } 13511da177e4SLinus Torvalds 1352cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13531da177e4SLinus Torvalds { 13548687b63aSAl Viro __be32 *p; 13551da177e4SLinus Torvalds 1356475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1357475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13584ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1359425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1360ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1361b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 136234558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13631da177e4SLinus Torvalds } 13641da177e4SLinus Torvalds 1365d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1366d3c7b7ccSTrond Myklebust { 1367ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1368d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1369d3c7b7ccSTrond Myklebust } 1370d3c7b7ccSTrond Myklebust 1371cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13721da177e4SLinus Torvalds { 1373ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13746fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13751da177e4SLinus Torvalds } 13761da177e4SLinus Torvalds 13776ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13781da177e4SLinus Torvalds { 13798687b63aSAl Viro __be32 *p; 13801da177e4SLinus Torvalds 138113c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13826ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 138334558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13841da177e4SLinus Torvalds } 13851da177e4SLinus Torvalds 13861da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13871da177e4SLinus Torvalds { 13888687b63aSAl Viro __be32 *p; 13891da177e4SLinus Torvalds /* 13901da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13911da177e4SLinus Torvalds * owner 4 = 32 13921da177e4SLinus Torvalds */ 13934ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 13946ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 139595b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1396b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 139795b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 139893f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1399d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 140095b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 140195b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 14021da177e4SLinus Torvalds } 14031da177e4SLinus Torvalds 14041da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14051da177e4SLinus Torvalds { 14068687b63aSAl Viro __be32 *p; 14071da177e4SLinus Torvalds 140813c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1409549b19ccSTrond Myklebust switch(arg->createmode) { 1410549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 141134558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 1412dff25ddbSAndreas Gruenbacher encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false, 1413dff25ddbSAndreas Gruenbacher &arg->umask); 14141da177e4SLinus Torvalds break; 1415549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14164882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 1417dff25ddbSAndreas Gruenbacher encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false, 1418dff25ddbSAndreas Gruenbacher &arg->umask); 1419549b19ccSTrond Myklebust break; 1420549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1421549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1422549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1423549b19ccSTrond Myklebust break; 1424549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14254882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14264882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 1427dff25ddbSAndreas Gruenbacher encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true, 1428dff25ddbSAndreas Gruenbacher &arg->umask); 14294882ef72SAlexandros Batsakis } 14304882ef72SAlexandros Batsakis } 14311da177e4SLinus Torvalds 14321da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14331da177e4SLinus Torvalds { 14348687b63aSAl Viro __be32 *p; 14351da177e4SLinus Torvalds 143613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14371da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14381da177e4SLinus Torvalds case 0: 143934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14401da177e4SLinus Torvalds break; 14411da177e4SLinus Torvalds default: 144234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14431da177e4SLinus Torvalds encode_createmode(xdr, arg); 14441da177e4SLinus Torvalds } 14451da177e4SLinus Torvalds } 14461da177e4SLinus Torvalds 1447bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14481da177e4SLinus Torvalds { 14498687b63aSAl Viro __be32 *p; 14501da177e4SLinus Torvalds 145113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14521da177e4SLinus Torvalds switch (delegation_type) { 14531da177e4SLinus Torvalds case 0: 145434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14551da177e4SLinus Torvalds break; 14561da177e4SLinus Torvalds case FMODE_READ: 145734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14581da177e4SLinus Torvalds break; 14591da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 146034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14611da177e4SLinus Torvalds break; 14621da177e4SLinus Torvalds default: 14631da177e4SLinus Torvalds BUG(); 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds } 14661da177e4SLinus Torvalds 14671da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14681da177e4SLinus Torvalds { 14698687b63aSAl Viro __be32 *p; 14701da177e4SLinus Torvalds 147113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 147234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14731da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14741da177e4SLinus Torvalds } 14751da177e4SLinus Torvalds 1476bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14771da177e4SLinus Torvalds { 14788687b63aSAl Viro __be32 *p; 14791da177e4SLinus Torvalds 148013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 148134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14821da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14831da177e4SLinus Torvalds } 14841da177e4SLinus Torvalds 14851da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14861da177e4SLinus Torvalds { 14878687b63aSAl Viro __be32 *p; 14881da177e4SLinus Torvalds 1489ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1490ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1491ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14921da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14931da177e4SLinus Torvalds } 14941da177e4SLinus Torvalds 1495d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1496d9fc6619STrond Myklebust { 1497d9fc6619STrond Myklebust __be32 *p; 1498d9fc6619STrond Myklebust 1499d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1500d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1501d9fc6619STrond Myklebust } 1502d9fc6619STrond Myklebust 1503d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1504d9fc6619STrond Myklebust { 1505d9fc6619STrond Myklebust __be32 *p; 1506d9fc6619STrond Myklebust 1507d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1508d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1509d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1510d9fc6619STrond Myklebust } 1511d9fc6619STrond Myklebust 1512cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15131da177e4SLinus Torvalds { 1514ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15151da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15161da177e4SLinus Torvalds encode_opentype(xdr, arg); 15171da177e4SLinus Torvalds switch (arg->claim) { 15181da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15191da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15201da177e4SLinus Torvalds break; 15211da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15221da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15231da177e4SLinus Torvalds break; 15241da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15251da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15261da177e4SLinus Torvalds break; 1527d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1528d9fc6619STrond Myklebust encode_claim_fh(xdr); 1529d9fc6619STrond Myklebust break; 1530d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1531d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1532d9fc6619STrond Myklebust break; 15331da177e4SLinus Torvalds default: 15341da177e4SLinus Torvalds BUG(); 15351da177e4SLinus Torvalds } 15361da177e4SLinus Torvalds } 15371da177e4SLinus Torvalds 1538cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15391da177e4SLinus Torvalds { 1540ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1541ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15424ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15431da177e4SLinus Torvalds } 15441da177e4SLinus Torvalds 1545cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15461da177e4SLinus Torvalds { 1547ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1548566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15494ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15506ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15511da177e4SLinus Torvalds } 15521da177e4SLinus Torvalds 1553cf8cdbe5SAndy Adamson static void 1554d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15551da177e4SLinus Torvalds { 1556ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15576fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15581da177e4SLinus Torvalds } 15591da177e4SLinus Torvalds 1560cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15611da177e4SLinus Torvalds { 1562ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15631da177e4SLinus Torvalds } 15641da177e4SLinus Torvalds 15653c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15663c6b899cSAnna Schumaker struct compound_hdr *hdr) 15671da177e4SLinus Torvalds { 15688687b63aSAl Viro __be32 *p; 15691da177e4SLinus Torvalds 1570ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15719b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15721da177e4SLinus Torvalds 157313c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1574b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 157534558513SBenny Halevy *p = cpu_to_be32(args->count); 15761da177e4SLinus Torvalds } 15771da177e4SLinus Torvalds 1578cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15791da177e4SLinus Torvalds { 1580aa9c2669SDavid Quigley uint32_t attrs[3] = { 158128331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 158228331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 158328331a46STrond Myklebust }; 15846f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1585cd93710eSChuck Lever __be32 *p, verf[2]; 1586d204c5d2STrond Myklebust uint32_t attrlen = 0; 1587d204c5d2STrond Myklebust unsigned int i; 15881da177e4SLinus Torvalds 158982f2e547SBryan Schumaker if (readdir->plus) { 159082f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 159128331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 159282f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 159382f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 159482f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 159582f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1596d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 15976f7a35bdSTrond Myklebust dircount >>= 1; 159882f2e547SBryan Schumaker } 159928331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 160028331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 160128331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1602d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1603d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1604d204c5d2STrond Myklebust if (attrs[i] != 0) 1605d204c5d2STrond Myklebust attrlen = i+1; 1606d204c5d2STrond Myklebust } 16076f7a35bdSTrond Myklebust 1608475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1609ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1610cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1611d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16126f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16136f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1614d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1615d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1616d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1617cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1618aa9c2669SDavid Quigley 1619aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 162044109241SFred Isaman __func__, 1621eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1622cd93710eSChuck Lever verf[0], verf[1], 1623eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1624aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1625aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16261da177e4SLinus Torvalds } 16271da177e4SLinus Torvalds 1628cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16291da177e4SLinus Torvalds { 1630ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds 1633cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16341da177e4SLinus Torvalds { 1635ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16366fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16371da177e4SLinus Torvalds } 16381da177e4SLinus Torvalds 1639cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16401da177e4SLinus Torvalds { 1641ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1642811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1643811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16441da177e4SLinus Torvalds } 16451da177e4SLinus Torvalds 1646bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1647bb4dae5eSChuck Lever struct compound_hdr *hdr) 16481da177e4SLinus Torvalds { 1649475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1650ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16511da177e4SLinus Torvalds } 16521da177e4SLinus Torvalds 1653cf8cdbe5SAndy Adamson static void 1654d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 165556ae19f3STrond Myklebust { 1656ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 165756ae19f3STrond Myklebust } 165856ae19f3STrond Myklebust 16599f06c719SChuck Lever static void 1660d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 166123ec6965SJ. Bruce Fields { 16628687b63aSAl Viro __be32 *p; 166323ec6965SJ. Bruce Fields 1664ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1665ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 166613c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1667e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 166834558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 166913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 167034558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16718fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 167223ec6965SJ. Bruce Fields } 167323ec6965SJ. Bruce Fields 1674cf8cdbe5SAndy Adamson static void 1675d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16761da177e4SLinus Torvalds { 1677ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16781da177e4SLinus Torvalds } 16791da177e4SLinus Torvalds 1680cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16811da177e4SLinus Torvalds { 1682ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1683ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1684dff25ddbSAndreas Gruenbacher encode_attrs(xdr, arg->iap, arg->label, server, false, NULL); 16851da177e4SLinus Torvalds } 16861da177e4SLinus Torvalds 1687cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16881da177e4SLinus Torvalds { 16898687b63aSAl Viro __be32 *p; 16901da177e4SLinus Torvalds 169170019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1692cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16931da177e4SLinus Torvalds 16943a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 16953a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 169613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 169734558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16981da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16991da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 170013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 17013a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 17021da177e4SLinus Torvalds } 17031da177e4SLinus Torvalds 1704bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 17051da177e4SLinus Torvalds { 1706475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1707475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1708ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1709cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17101da177e4SLinus Torvalds } 17111da177e4SLinus Torvalds 17123c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17133c6b899cSAnna Schumaker struct compound_hdr *hdr) 17141da177e4SLinus Torvalds { 17158687b63aSAl Viro __be32 *p; 17161da177e4SLinus Torvalds 1717ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17189b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17191da177e4SLinus Torvalds 172013c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1721b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1722e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 172334558513SBenny Halevy *p = cpu_to_be32(args->count); 17241da177e4SLinus Torvalds 17251da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17261da177e4SLinus Torvalds } 17271da177e4SLinus Torvalds 1728cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17291da177e4SLinus Torvalds { 1730ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1731ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17321da177e4SLinus Torvalds } 17339b7b9fccSAndy Adamson 17345a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17355a5ea0d4SBryan Schumaker { 1736ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17376fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17385a5ea0d4SBryan Schumaker } 17395a5ea0d4SBryan Schumaker 174099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17419b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17427c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 174371a097c6STrond Myklebust struct nfs41_bind_conn_to_session_args *args, 17447c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17457c44f1aeSWeston Andros Adamson { 17467c44f1aeSWeston Andros Adamson __be32 *p; 17477c44f1aeSWeston Andros Adamson 17487c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17497c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 175071a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17517c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 175271a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 175371a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17547c44f1aeSWeston Andros Adamson } 17557c44f1aeSWeston Andros Adamson 17562031cd1aSWeston Andros Adamson static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 17572031cd1aSWeston Andros Adamson { 17582031cd1aSWeston Andros Adamson unsigned int i; 17592031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17602031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17612031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17622031cd1aSWeston Andros Adamson } 17632031cd1aSWeston Andros Adamson 176499fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 176599fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 176699fe60d0SBenny Halevy struct compound_hdr *hdr) 176799fe60d0SBenny Halevy { 176899fe60d0SBenny Halevy __be32 *p; 1769d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1770db8ac8baSWeston Andros Adamson int len = 0; 177199fe60d0SBenny Halevy 177270019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1773cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 177499fe60d0SBenny Halevy 17753a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17763a6bb738SJeff Layton args->client->cl_owner_id); 177799fe60d0SBenny Halevy 17782031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17792031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17802031cd1aSWeston Andros Adamson 17812031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17822031cd1aSWeston Andros Adamson case SP4_NONE: 17832031cd1aSWeston Andros Adamson break; 17842031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17852031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 17862031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 17872031cd1aSWeston Andros Adamson break; 17882031cd1aSWeston Andros Adamson default: 17892031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 17902031cd1aSWeston Andros Adamson break; 17912031cd1aSWeston Andros Adamson } 1792db8ac8baSWeston Andros Adamson 1793db8ac8baSWeston Andros Adamson if (send_implementation_id && 1794db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1795db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1796d751f748SJim Rees <= sizeof(impl_name) + 1) 1797db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1798db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1799db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1800db8ac8baSWeston Andros Adamson 1801db8ac8baSWeston Andros Adamson if (len > 0) { 18022031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1803db8ac8baSWeston Andros Adamson 1804db8ac8baSWeston Andros Adamson encode_string(xdr, 1805db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1806db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1807db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1808db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1809db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1810db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1811db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1812db8ac8baSWeston Andros Adamson } else 18132031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 181499fe60d0SBenny Halevy } 1815fc931582SAndy Adamson 1816fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1817fc931582SAndy Adamson struct nfs41_create_session_args *args, 1818fc931582SAndy Adamson struct compound_hdr *hdr) 1819fc931582SAndy Adamson { 1820fc931582SAndy Adamson __be32 *p; 1821fc931582SAndy Adamson struct nfs_client *clp = args->client; 182289f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1823f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18248e0d46e1SMike Sager u32 max_resp_sz_cached; 18258e0d46e1SMike Sager 18268e0d46e1SMike Sager /* 18278e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18288e0d46e1SMike Sager * 2 is the verifier. 18298e0d46e1SMike Sager */ 18308e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 18318e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1832fc931582SAndy Adamson 1833475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 183489f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 183579969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 183679969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1837e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1838fc931582SAndy Adamson 1839fc931582SAndy Adamson /* Fore Channel */ 1840c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1841e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1842e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18438e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1844e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1845e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1846e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1847fc931582SAndy Adamson 1848fc931582SAndy Adamson /* Back Channel */ 1849c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1850e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1851e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1852e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1853e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1854e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1856fc931582SAndy Adamson 1857e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1858e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1859e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1860fc931582SAndy Adamson 1861fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18622f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 186389f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1864e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1865e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 186634558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1867fc931582SAndy Adamson } 18680f3e66c6SAndy Adamson 18690f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 18700f3e66c6SAndy Adamson struct nfs4_session *session, 18710f3e66c6SAndy Adamson struct compound_hdr *hdr) 18720f3e66c6SAndy Adamson { 1873475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1874475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18750f3e66c6SAndy Adamson } 187618019753SRicardo Labiaga 187766245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 187866245539STrond Myklebust uint64_t clientid, 187966245539STrond Myklebust struct compound_hdr *hdr) 188066245539STrond Myklebust { 188166245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 188266245539STrond Myklebust encode_uint64(xdr, clientid); 188366245539STrond Myklebust } 188466245539STrond Myklebust 188518019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 188618019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 188718019753SRicardo Labiaga struct compound_hdr *hdr) 188818019753SRicardo Labiaga { 1889475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1890475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 189118019753SRicardo Labiaga } 189299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 189399fe60d0SBenny Halevy 18949b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18959b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18969b7b9fccSAndy Adamson struct compound_hdr *hdr) 18979b7b9fccSAndy Adamson { 18989b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18992b2fa717STrond Myklebust struct nfs4_session *session; 1900fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 19012b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1902fc01cea9SAndy Adamson __be32 *p; 19039b7b9fccSAndy Adamson 19042b2fa717STrond Myklebust tp = slot->table; 19052b2fa717STrond Myklebust session = tp->session; 19063bd2384aSChuck Lever if (!session) 19073bd2384aSChuck Lever return; 1908fc01cea9SAndy Adamson 1909475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1910fc01cea9SAndy Adamson 1911fc01cea9SAndy Adamson /* 1912fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1913fc01cea9SAndy Adamson */ 1914fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1915fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1916fc01cea9SAndy Adamson __func__, 1917fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1918fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1919fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1920fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19212b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1922fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1923475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 192493f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1925e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19262b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1927e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 192834558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19299b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19309b7b9fccSAndy Adamson } 19319b7b9fccSAndy Adamson 1932b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1933b1f69b75SAndy Adamson static void 1934b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1935b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1936b1f69b75SAndy Adamson struct compound_hdr *hdr) 1937b1f69b75SAndy Adamson { 1938b1f69b75SAndy Adamson __be32 *p; 1939b1f69b75SAndy Adamson 1940475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 194184c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1942b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1943b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1944b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1945f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 194684c9dee3SChristoph Hellwig 194784c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 194884c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19494e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1950b1f69b75SAndy Adamson } 1951b1f69b75SAndy Adamson 1952b1f69b75SAndy Adamson static void 1953b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1954b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1955b1f69b75SAndy Adamson struct compound_hdr *hdr) 1956b1f69b75SAndy Adamson { 1957b1f69b75SAndy Adamson __be32 *p; 1958b1f69b75SAndy Adamson 1959475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1960475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1961b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1962b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1963b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1964b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1965b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1966b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1967ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1968475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1969b1f69b75SAndy Adamson 1970b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1971b1f69b75SAndy Adamson __func__, 1972b1f69b75SAndy Adamson args->type, 1973b1f69b75SAndy Adamson args->range.iomode, 1974b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1975b1f69b75SAndy Adamson (unsigned long)args->range.length, 1976b1f69b75SAndy Adamson args->maxcount); 1977b1f69b75SAndy Adamson } 1978863a3c6cSAndy Adamson 1979863a3c6cSAndy Adamson static int 1980863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1981ac7db726SBenny Halevy struct inode *inode, 19825f919c9fSChristoph Hellwig struct nfs4_layoutcommit_args *args, 1983863a3c6cSAndy Adamson struct compound_hdr *hdr) 1984863a3c6cSAndy Adamson { 1985863a3c6cSAndy Adamson __be32 *p; 1986863a3c6cSAndy Adamson 1987863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1988863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1989863a3c6cSAndy Adamson 1990475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1991475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1992863a3c6cSAndy Adamson /* Only whole file layouts */ 1993863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19943557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1995ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1996ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 19972e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 1998ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1999863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 2000863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 20012e18d4d8STrond Myklebust } else { 20022e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 20032e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 20042e18d4d8STrond Myklebust } 2005863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2006863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2007ac7db726SBenny Halevy 20085f919c9fSChristoph Hellwig if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) { 2009ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 2010ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 20115f919c9fSChristoph Hellwig } else { 20125f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 20135f919c9fSChristoph Hellwig if (args->layoutupdate_pages) { 20145f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20155f919c9fSChristoph Hellwig args->layoutupdate_len); 20165f919c9fSChristoph Hellwig } 20175f919c9fSChristoph Hellwig } 2018863a3c6cSAndy Adamson 2019863a3c6cSAndy Adamson return 0; 2020863a3c6cSAndy Adamson } 2021cbe82603SBenny Halevy 2022cbe82603SBenny Halevy static void 2023cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2024cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2025cbe82603SBenny Halevy struct compound_hdr *hdr) 2026cbe82603SBenny Halevy { 202794e5c571STrond Myklebust const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld; 2028cbe82603SBenny Halevy __be32 *p; 2029cbe82603SBenny Halevy 2030475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2031475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2032cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2033cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 203415eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2035cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2036ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 203715eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 203815eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2039cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2040ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2041cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20424d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20434d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 20444d796d75STrond Myklebust else if (lr_ops->encode_layoutreturn) 204594e5c571STrond Myklebust lr_ops->encode_layoutreturn(xdr, args); 204694e5c571STrond Myklebust else 2047475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2048cbe82603SBenny Halevy } 2049fca78d6dSBryan Schumaker 2050fca78d6dSBryan Schumaker static int 2051fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2052fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2053fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2054fca78d6dSBryan Schumaker { 2055475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2056475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2057fca78d6dSBryan Schumaker return 0; 2058fca78d6dSBryan Schumaker } 20597d974794SBryan Schumaker 20607d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 20617d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 20627d974794SBryan Schumaker struct compound_hdr *hdr) 20637d974794SBryan Schumaker { 2064475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2065475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2066ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20677d974794SBryan Schumaker } 20689aeda35fSBryan Schumaker 20699aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 20709aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 20719aeda35fSBryan Schumaker struct compound_hdr *hdr) 20729aeda35fSBryan Schumaker { 2073ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20747c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20759aeda35fSBryan Schumaker } 2076cf805165STrond Myklebust #else 2077cf805165STrond Myklebust static inline void 2078cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2079cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2080cf805165STrond Myklebust struct compound_hdr *hdr) 2081cf805165STrond Myklebust { 2082cf805165STrond Myklebust } 2083b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2084b1f69b75SAndy Adamson 20851da177e4SLinus Torvalds /* 20861da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20871da177e4SLinus Torvalds */ 20881da177e4SLinus Torvalds 208966cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 209066cc0429SBenny Halevy { 209166cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 20923bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 20933bd2384aSChuck Lever if (session) 20943bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 209566cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 209666cc0429SBenny Halevy return 0; 209766cc0429SBenny Halevy } 209866cc0429SBenny Halevy 20991da177e4SLinus Torvalds /* 21001da177e4SLinus Torvalds * Encode an ACCESS request 21011da177e4SLinus Torvalds */ 21029f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 21039f06c719SChuck Lever const struct nfs4_accessargs *args) 21041da177e4SLinus Torvalds { 21051da177e4SLinus Torvalds struct compound_hdr hdr = { 210666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21071da177e4SLinus Torvalds }; 21081da177e4SLinus Torvalds 21099f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21109f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21119f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21129f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21139f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2114d017931cSAndy Adamson encode_nops(&hdr); 21151da177e4SLinus Torvalds } 21161da177e4SLinus Torvalds 21171da177e4SLinus Torvalds /* 21181da177e4SLinus Torvalds * Encode LOOKUP request 21191da177e4SLinus Torvalds */ 21209f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 21219f06c719SChuck Lever const struct nfs4_lookup_arg *args) 21221da177e4SLinus Torvalds { 21231da177e4SLinus Torvalds struct compound_hdr hdr = { 212466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21251da177e4SLinus Torvalds }; 21261da177e4SLinus Torvalds 21279f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21289f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21299f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21309f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21319f06c719SChuck Lever encode_getfh(xdr, &hdr); 21329f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2133d017931cSAndy Adamson encode_nops(&hdr); 21341da177e4SLinus Torvalds } 21351da177e4SLinus Torvalds 21361da177e4SLinus Torvalds /* 21371da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21381da177e4SLinus Torvalds */ 21399f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21409f06c719SChuck Lever struct xdr_stream *xdr, 21419f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 21421da177e4SLinus Torvalds { 21431da177e4SLinus Torvalds struct compound_hdr hdr = { 214466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21451da177e4SLinus Torvalds }; 21461da177e4SLinus Torvalds 21479f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21489f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21499f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21509f06c719SChuck Lever encode_getfh(xdr, &hdr); 21519f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2152d017931cSAndy Adamson encode_nops(&hdr); 21531da177e4SLinus Torvalds } 21541da177e4SLinus Torvalds 21551da177e4SLinus Torvalds /* 21561da177e4SLinus Torvalds * Encode REMOVE request 21571da177e4SLinus Torvalds */ 21589f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 21599f06c719SChuck Lever const struct nfs_removeargs *args) 21601da177e4SLinus Torvalds { 21611da177e4SLinus Torvalds struct compound_hdr hdr = { 216266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21631da177e4SLinus Torvalds }; 21641da177e4SLinus Torvalds 21659f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21669f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21679f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21689f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2169d017931cSAndy Adamson encode_nops(&hdr); 21701da177e4SLinus Torvalds } 21711da177e4SLinus Torvalds 21721da177e4SLinus Torvalds /* 21731da177e4SLinus Torvalds * Encode RENAME request 21741da177e4SLinus Torvalds */ 21759f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 21769f06c719SChuck Lever const struct nfs_renameargs *args) 21771da177e4SLinus Torvalds { 21781da177e4SLinus Torvalds struct compound_hdr hdr = { 217966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21801da177e4SLinus Torvalds }; 21811da177e4SLinus Torvalds 21829f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21839f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21849f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21859f06c719SChuck Lever encode_savefh(xdr, &hdr); 21869f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21879f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2188d017931cSAndy Adamson encode_nops(&hdr); 21891da177e4SLinus Torvalds } 21901da177e4SLinus Torvalds 21911da177e4SLinus Torvalds /* 21921da177e4SLinus Torvalds * Encode LINK request 21931da177e4SLinus Torvalds */ 21949f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 21959f06c719SChuck Lever const struct nfs4_link_arg *args) 21961da177e4SLinus Torvalds { 21971da177e4SLinus Torvalds struct compound_hdr hdr = { 219866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21991da177e4SLinus Torvalds }; 22001da177e4SLinus Torvalds 22019f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22029f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22039f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22049f06c719SChuck Lever encode_savefh(xdr, &hdr); 22059f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22069f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22079f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22089f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2209d017931cSAndy Adamson encode_nops(&hdr); 22101da177e4SLinus Torvalds } 22111da177e4SLinus Torvalds 22121da177e4SLinus Torvalds /* 22131da177e4SLinus Torvalds * Encode CREATE request 22141da177e4SLinus Torvalds */ 22159f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 22169f06c719SChuck Lever const struct nfs4_create_arg *args) 22171da177e4SLinus Torvalds { 22181da177e4SLinus Torvalds struct compound_hdr hdr = { 221966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22201da177e4SLinus Torvalds }; 22211da177e4SLinus Torvalds 22229f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22239f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22249f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22259f06c719SChuck Lever encode_create(xdr, args, &hdr); 22269f06c719SChuck Lever encode_getfh(xdr, &hdr); 22279f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2228d017931cSAndy Adamson encode_nops(&hdr); 22291da177e4SLinus Torvalds } 22301da177e4SLinus Torvalds 22311da177e4SLinus Torvalds /* 22321da177e4SLinus Torvalds * Encode SYMLINK request 22331da177e4SLinus Torvalds */ 22349f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 22359f06c719SChuck Lever const struct nfs4_create_arg *args) 22361da177e4SLinus Torvalds { 22379f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22381da177e4SLinus Torvalds } 22391da177e4SLinus Torvalds 22401da177e4SLinus Torvalds /* 22411da177e4SLinus Torvalds * Encode GETATTR request 22421da177e4SLinus Torvalds */ 22439f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 22449f06c719SChuck Lever const struct nfs4_getattr_arg *args) 22451da177e4SLinus Torvalds { 22461da177e4SLinus Torvalds struct compound_hdr hdr = { 224766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22481da177e4SLinus Torvalds }; 22491da177e4SLinus Torvalds 22509f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22519f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22529f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22539f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2254d017931cSAndy Adamson encode_nops(&hdr); 22551da177e4SLinus Torvalds } 22561da177e4SLinus Torvalds 22571da177e4SLinus Torvalds /* 22581da177e4SLinus Torvalds * Encode a CLOSE request 22591da177e4SLinus Torvalds */ 22609f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 22619f06c719SChuck Lever struct nfs_closeargs *args) 22621da177e4SLinus Torvalds { 22631da177e4SLinus Torvalds struct compound_hdr hdr = { 226466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22651da177e4SLinus Torvalds }; 22661da177e4SLinus Torvalds 22679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22699f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2270cf805165STrond Myklebust if (args->lr_args) 2271cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 22723ecefc92STrond Myklebust if (args->bitmask != NULL) 22739f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2274d8d84983STrond Myklebust encode_close(xdr, args, &hdr); 2275d017931cSAndy Adamson encode_nops(&hdr); 22761da177e4SLinus Torvalds } 22771da177e4SLinus Torvalds 22781da177e4SLinus Torvalds /* 22791da177e4SLinus Torvalds * Encode an OPEN request 22801da177e4SLinus Torvalds */ 22819f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 22829f06c719SChuck Lever struct nfs_openargs *args) 22831da177e4SLinus Torvalds { 22841da177e4SLinus Torvalds struct compound_hdr hdr = { 228566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22861da177e4SLinus Torvalds }; 22871da177e4SLinus Torvalds 22889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22899f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22909f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22919f06c719SChuck Lever encode_open(xdr, args, &hdr); 22929f06c719SChuck Lever encode_getfh(xdr, &hdr); 2293ae2bb032SWeston Andros Adamson if (args->access) 22946168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 22951549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2296d017931cSAndy Adamson encode_nops(&hdr); 22971da177e4SLinus Torvalds } 22981da177e4SLinus Torvalds 22991da177e4SLinus Torvalds /* 23001da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 23011da177e4SLinus Torvalds */ 23029f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 23039f06c719SChuck Lever struct xdr_stream *xdr, 23049f06c719SChuck Lever struct nfs_open_confirmargs *args) 23051da177e4SLinus Torvalds { 23061da177e4SLinus Torvalds struct compound_hdr hdr = { 2307d017931cSAndy Adamson .nops = 0, 23081da177e4SLinus Torvalds }; 23091da177e4SLinus Torvalds 23109f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23119f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23129f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2313d017931cSAndy Adamson encode_nops(&hdr); 23141da177e4SLinus Torvalds } 23151da177e4SLinus Torvalds 23161da177e4SLinus Torvalds /* 23171da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23181da177e4SLinus Torvalds */ 23199f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23209f06c719SChuck Lever struct xdr_stream *xdr, 23219f06c719SChuck Lever struct nfs_openargs *args) 23221da177e4SLinus Torvalds { 23231da177e4SLinus Torvalds struct compound_hdr hdr = { 232466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23251da177e4SLinus Torvalds }; 23261da177e4SLinus Torvalds 23279f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23289f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23299f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23309f06c719SChuck Lever encode_open(xdr, args, &hdr); 2331ae2bb032SWeston Andros Adamson if (args->access) 23326168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2333e23008ecSAndy Adamson 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_DOWNGRADE request 23391da177e4SLinus Torvalds */ 23409f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23419f06c719SChuck Lever struct xdr_stream *xdr, 23429f06c719SChuck Lever struct nfs_closeargs *args) 23431da177e4SLinus Torvalds { 23441da177e4SLinus Torvalds struct compound_hdr hdr = { 234566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23461da177e4SLinus Torvalds }; 23471da177e4SLinus Torvalds 23489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23499f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23509f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2351b6808145STrond Myklebust if (args->lr_args) 2352b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23539f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2354d017931cSAndy Adamson encode_nops(&hdr); 23551da177e4SLinus Torvalds } 23561da177e4SLinus Torvalds 23571da177e4SLinus Torvalds /* 23581da177e4SLinus Torvalds * Encode a LOCK request 23591da177e4SLinus Torvalds */ 23609f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 23619f06c719SChuck Lever struct nfs_lock_args *args) 23621da177e4SLinus Torvalds { 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_lock(xdr, args, &hdr); 2371d017931cSAndy Adamson encode_nops(&hdr); 23721da177e4SLinus Torvalds } 23731da177e4SLinus Torvalds 23741da177e4SLinus Torvalds /* 23751da177e4SLinus Torvalds * Encode a LOCKT request 23761da177e4SLinus Torvalds */ 23779f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 23789f06c719SChuck Lever struct nfs_lockt_args *args) 23791da177e4SLinus Torvalds { 23801da177e4SLinus Torvalds struct compound_hdr hdr = { 238166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23821da177e4SLinus Torvalds }; 23831da177e4SLinus Torvalds 23849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23859f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23869f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23879f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2388d017931cSAndy Adamson encode_nops(&hdr); 23891da177e4SLinus Torvalds } 23901da177e4SLinus Torvalds 23911da177e4SLinus Torvalds /* 23921da177e4SLinus Torvalds * Encode a LOCKU request 23931da177e4SLinus Torvalds */ 23949f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 23959f06c719SChuck Lever struct nfs_locku_args *args) 23961da177e4SLinus Torvalds { 23971da177e4SLinus Torvalds struct compound_hdr hdr = { 239866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23991da177e4SLinus Torvalds }; 24001da177e4SLinus Torvalds 24019f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24029f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24039f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24049f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2405d017931cSAndy Adamson encode_nops(&hdr); 24061da177e4SLinus Torvalds } 24071da177e4SLinus Torvalds 24089f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24099f06c719SChuck Lever struct xdr_stream *xdr, 24109f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2411d3c7b7ccSTrond Myklebust { 2412d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2413d3c7b7ccSTrond Myklebust .minorversion = 0, 2414d3c7b7ccSTrond Myklebust }; 2415d3c7b7ccSTrond Myklebust 24169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24179f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2418d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2419d3c7b7ccSTrond Myklebust } 2420d3c7b7ccSTrond Myklebust 24211da177e4SLinus Torvalds /* 24221da177e4SLinus Torvalds * Encode a READLINK request 24231da177e4SLinus Torvalds */ 24249f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 24259f06c719SChuck Lever const struct nfs4_readlink *args) 24261da177e4SLinus Torvalds { 24271da177e4SLinus Torvalds struct compound_hdr hdr = { 242866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24291da177e4SLinus Torvalds }; 24301da177e4SLinus Torvalds 24319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24339f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24349f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2435e3a535e1STrond Myklebust 243628f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2437e3a535e1STrond Myklebust args->pgbase, args->pglen); 2438d017931cSAndy Adamson encode_nops(&hdr); 24391da177e4SLinus Torvalds } 24401da177e4SLinus Torvalds 24411da177e4SLinus Torvalds /* 24421da177e4SLinus Torvalds * Encode a READDIR request 24431da177e4SLinus Torvalds */ 24449f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 24459f06c719SChuck Lever const struct nfs4_readdir_arg *args) 24461da177e4SLinus Torvalds { 24471da177e4SLinus Torvalds struct compound_hdr hdr = { 244866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24491da177e4SLinus Torvalds }; 24501da177e4SLinus Torvalds 24519f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24529f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24539f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24549f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2455d6ac02dfSTrond Myklebust 245628f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2457d6ac02dfSTrond Myklebust args->pgbase, args->count); 2458d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 245928f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2460d6ac02dfSTrond Myklebust args->pgbase, args->count); 2461d017931cSAndy Adamson encode_nops(&hdr); 24621da177e4SLinus Torvalds } 24631da177e4SLinus Torvalds 24641da177e4SLinus Torvalds /* 24651da177e4SLinus Torvalds * Encode a READ request 24661da177e4SLinus Torvalds */ 24679f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 24683c6b899cSAnna Schumaker struct nfs_pgio_args *args) 24691da177e4SLinus Torvalds { 24701da177e4SLinus Torvalds struct compound_hdr hdr = { 247166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24721da177e4SLinus Torvalds }; 24731da177e4SLinus Torvalds 24749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24769f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24779f06c719SChuck Lever encode_read(xdr, args, &hdr); 24781da177e4SLinus Torvalds 247928f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 24801da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 24814f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2482d017931cSAndy Adamson encode_nops(&hdr); 24831da177e4SLinus Torvalds } 24841da177e4SLinus Torvalds 24851da177e4SLinus Torvalds /* 24861da177e4SLinus Torvalds * Encode an SETATTR request 24871da177e4SLinus Torvalds */ 24889f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 24899f06c719SChuck Lever struct nfs_setattrargs *args) 24901da177e4SLinus Torvalds { 24911da177e4SLinus Torvalds struct compound_hdr hdr = { 249266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24931da177e4SLinus Torvalds }; 24941da177e4SLinus Torvalds 24959f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24969f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24979f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24989f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 24999f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2500d017931cSAndy Adamson encode_nops(&hdr); 25011da177e4SLinus Torvalds } 25021da177e4SLinus Torvalds 25031da177e4SLinus Torvalds /* 2504029d105eSJ. Bruce Fields * Encode a GETACL request 2505029d105eSJ. Bruce Fields */ 25069f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2507029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2508029d105eSJ. Bruce Fields { 2509029d105eSJ. Bruce Fields struct compound_hdr hdr = { 251066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2511029d105eSJ. Bruce Fields }; 251228f56694SBenny Halevy uint32_t replen; 2513029d105eSJ. Bruce Fields 25149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25169f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2517bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 25189f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2519cf8cdbe5SAndy Adamson 252028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 25218fbcf237SAndreas Gruenbacher args->acl_pages, 0, args->acl_len); 2522bf118a34SAndy Adamson 2523d017931cSAndy Adamson encode_nops(&hdr); 2524029d105eSJ. Bruce Fields } 2525029d105eSJ. Bruce Fields 2526029d105eSJ. Bruce Fields /* 25271da177e4SLinus Torvalds * Encode a WRITE request 25281da177e4SLinus Torvalds */ 25299f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 25303c6b899cSAnna Schumaker struct nfs_pgio_args *args) 25311da177e4SLinus Torvalds { 25321da177e4SLinus Torvalds struct compound_hdr hdr = { 253366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25341da177e4SLinus Torvalds }; 25351da177e4SLinus Torvalds 25369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25379f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25389f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25399f06c719SChuck Lever encode_write(xdr, args, &hdr); 25404f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25417ffd1064SFred Isaman if (args->bitmask) 25429f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2543d017931cSAndy Adamson encode_nops(&hdr); 25441da177e4SLinus Torvalds } 25451da177e4SLinus Torvalds 25461da177e4SLinus Torvalds /* 25471da177e4SLinus Torvalds * a COMMIT request 25481da177e4SLinus Torvalds */ 25499f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 25500b7c0153SFred Isaman struct nfs_commitargs *args) 25511da177e4SLinus Torvalds { 25521da177e4SLinus Torvalds struct compound_hdr hdr = { 255366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25541da177e4SLinus Torvalds }; 25551da177e4SLinus Torvalds 25569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25579f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25589f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25599f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2560d017931cSAndy Adamson encode_nops(&hdr); 25611da177e4SLinus Torvalds } 25621da177e4SLinus Torvalds 25631da177e4SLinus Torvalds /* 25641da177e4SLinus Torvalds * FSINFO request 25651da177e4SLinus Torvalds */ 25669f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 25679f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 25681da177e4SLinus Torvalds { 25691da177e4SLinus Torvalds struct compound_hdr hdr = { 257066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25711da177e4SLinus Torvalds }; 25721da177e4SLinus Torvalds 25739f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25749f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25759f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25769f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2577d017931cSAndy Adamson encode_nops(&hdr); 25781da177e4SLinus Torvalds } 25791da177e4SLinus Torvalds 25801da177e4SLinus Torvalds /* 25811da177e4SLinus Torvalds * a PATHCONF request 25821da177e4SLinus Torvalds */ 25839f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 25849f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 25851da177e4SLinus Torvalds { 25861da177e4SLinus Torvalds struct compound_hdr hdr = { 258766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25881da177e4SLinus Torvalds }; 25891da177e4SLinus Torvalds 25909f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25919f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25929f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25939f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2594d017931cSAndy Adamson &hdr); 2595d017931cSAndy Adamson encode_nops(&hdr); 25961da177e4SLinus Torvalds } 25971da177e4SLinus Torvalds 25981da177e4SLinus Torvalds /* 25991da177e4SLinus Torvalds * a STATFS request 26001da177e4SLinus Torvalds */ 26019f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 26029f06c719SChuck Lever const struct nfs4_statfs_arg *args) 26031da177e4SLinus Torvalds { 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_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2612d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2613d017931cSAndy Adamson encode_nops(&hdr); 26141da177e4SLinus Torvalds } 26151da177e4SLinus Torvalds 26161da177e4SLinus Torvalds /* 26171da177e4SLinus Torvalds * GETATTR_BITMAP request 26181da177e4SLinus Torvalds */ 26199f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26209f06c719SChuck Lever struct xdr_stream *xdr, 262143652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 26221da177e4SLinus Torvalds { 26238c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 26241da177e4SLinus Torvalds struct compound_hdr hdr = { 262566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26261da177e4SLinus Torvalds }; 26271da177e4SLinus Torvalds 26289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26299f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26309f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26318c61282fSKinglong Mee encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr); 2632d017931cSAndy Adamson encode_nops(&hdr); 26331da177e4SLinus Torvalds } 26341da177e4SLinus Torvalds 26351da177e4SLinus Torvalds /* 26361da177e4SLinus Torvalds * a RENEW request 26371da177e4SLinus Torvalds */ 26389f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 26399f06c719SChuck Lever struct nfs_client *clp) 26401da177e4SLinus Torvalds { 26411da177e4SLinus Torvalds struct compound_hdr hdr = { 2642d017931cSAndy Adamson .nops = 0, 26431da177e4SLinus Torvalds }; 26441da177e4SLinus Torvalds 26459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2646bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2647d017931cSAndy Adamson encode_nops(&hdr); 26481da177e4SLinus Torvalds } 26491da177e4SLinus Torvalds 26501da177e4SLinus Torvalds /* 26511da177e4SLinus Torvalds * a SETCLIENTID request 26521da177e4SLinus Torvalds */ 26539f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 26549f06c719SChuck Lever struct xdr_stream *xdr, 26559f06c719SChuck Lever struct nfs4_setclientid *sc) 26561da177e4SLinus Torvalds { 26571da177e4SLinus Torvalds struct compound_hdr hdr = { 2658d017931cSAndy Adamson .nops = 0, 26591da177e4SLinus Torvalds }; 26601da177e4SLinus Torvalds 26619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26629f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2663d017931cSAndy Adamson encode_nops(&hdr); 26641da177e4SLinus Torvalds } 26651da177e4SLinus Torvalds 26661da177e4SLinus Torvalds /* 26671da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 26681da177e4SLinus Torvalds */ 26699f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 26709f06c719SChuck Lever struct xdr_stream *xdr, 26719f06c719SChuck Lever struct nfs4_setclientid_res *arg) 26721da177e4SLinus Torvalds { 26731da177e4SLinus Torvalds struct compound_hdr hdr = { 2674d017931cSAndy Adamson .nops = 0, 26751da177e4SLinus Torvalds }; 26761da177e4SLinus Torvalds 26779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26789f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2679d017931cSAndy Adamson encode_nops(&hdr); 26801da177e4SLinus Torvalds } 26811da177e4SLinus Torvalds 26821da177e4SLinus Torvalds /* 26831da177e4SLinus Torvalds * DELEGRETURN request 26841da177e4SLinus Torvalds */ 26859f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 26869f06c719SChuck Lever struct xdr_stream *xdr, 26879f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 26881da177e4SLinus Torvalds { 26891da177e4SLinus Torvalds struct compound_hdr hdr = { 269066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26911da177e4SLinus Torvalds }; 26921da177e4SLinus Torvalds 26939f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26949f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26959f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2696586f1c39STrond Myklebust if (args->lr_args) 2697586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 26988ac2b422STrond Myklebust if (args->bitmask) 26999f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2700e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2701d017931cSAndy Adamson encode_nops(&hdr); 27021da177e4SLinus Torvalds } 27031da177e4SLinus Torvalds 27041da177e4SLinus Torvalds /* 2705683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2706683b57b4STrond Myklebust */ 27079f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27089f06c719SChuck Lever struct xdr_stream *xdr, 27099f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2710683b57b4STrond Myklebust { 2711683b57b4STrond Myklebust struct compound_hdr hdr = { 271266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2713683b57b4STrond Myklebust }; 271428f56694SBenny Halevy uint32_t replen; 2715683b57b4STrond Myklebust 27169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2718b03d735bSChuck Lever if (args->migration) { 2719b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2720b03d735bSChuck Lever replen = hdr.replen; 2721b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2722b03d735bSChuck Lever if (args->renew) 2723b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2724b03d735bSChuck Lever } else { 27259f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 27269f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2727b03d735bSChuck Lever replen = hdr.replen; 27289f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2729b03d735bSChuck Lever } 2730cf8cdbe5SAndy Adamson 2731b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 273228f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2733683b57b4STrond Myklebust 0, PAGE_SIZE); 2734d017931cSAndy Adamson encode_nops(&hdr); 2735683b57b4STrond Myklebust } 2736683b57b4STrond Myklebust 27375a5ea0d4SBryan Schumaker /* 27385a5ea0d4SBryan Schumaker * Encode SECINFO request 27395a5ea0d4SBryan Schumaker */ 27405a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 27415a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 27425a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 27435a5ea0d4SBryan Schumaker { 27445a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 27455a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27465a5ea0d4SBryan Schumaker }; 27475a5ea0d4SBryan Schumaker 27485a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 27495a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 27505a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 27515a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 27525a5ea0d4SBryan Schumaker encode_nops(&hdr); 27535a5ea0d4SBryan Schumaker } 27545a5ea0d4SBryan Schumaker 275544c99933SChuck Lever /* 275644c99933SChuck Lever * Encode FSID_PRESENT request 275744c99933SChuck Lever */ 275844c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 275944c99933SChuck Lever struct xdr_stream *xdr, 276044c99933SChuck Lever struct nfs4_fsid_present_arg *args) 276144c99933SChuck Lever { 276244c99933SChuck Lever struct compound_hdr hdr = { 276344c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 276444c99933SChuck Lever }; 276544c99933SChuck Lever 276644c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 276744c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 276844c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 276944c99933SChuck Lever encode_getfh(xdr, &hdr); 277044c99933SChuck Lever if (args->renew) 277144c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 277244c99933SChuck Lever encode_nops(&hdr); 277344c99933SChuck Lever } 277444c99933SChuck Lever 277599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 277699fe60d0SBenny Halevy /* 27777c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 27787c44f1aeSWeston Andros Adamson */ 27797c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 27807c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 278171a097c6STrond Myklebust struct nfs41_bind_conn_to_session_args *args) 27827c44f1aeSWeston Andros Adamson { 27837c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 278471a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 27857c44f1aeSWeston Andros Adamson }; 27867c44f1aeSWeston Andros Adamson 27877c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 278871a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 27897c44f1aeSWeston Andros Adamson encode_nops(&hdr); 27907c44f1aeSWeston Andros Adamson } 27917c44f1aeSWeston Andros Adamson 27927c44f1aeSWeston Andros Adamson /* 279399fe60d0SBenny Halevy * EXCHANGE_ID request 279499fe60d0SBenny Halevy */ 27959f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 27969f06c719SChuck Lever struct xdr_stream *xdr, 279799fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 279899fe60d0SBenny Halevy { 279999fe60d0SBenny Halevy struct compound_hdr hdr = { 2800a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 280199fe60d0SBenny Halevy }; 280299fe60d0SBenny Halevy 28039f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28049f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 280599fe60d0SBenny Halevy encode_nops(&hdr); 280699fe60d0SBenny Halevy } 28072050f0ccSAndy Adamson 28082050f0ccSAndy Adamson /* 2809fc931582SAndy Adamson * a CREATE_SESSION request 2810fc931582SAndy Adamson */ 28119f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28129f06c719SChuck Lever struct xdr_stream *xdr, 2813fc931582SAndy Adamson struct nfs41_create_session_args *args) 2814fc931582SAndy Adamson { 2815fc931582SAndy Adamson struct compound_hdr hdr = { 2816a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2817fc931582SAndy Adamson }; 2818fc931582SAndy Adamson 28199f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28209f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2821fc931582SAndy Adamson encode_nops(&hdr); 2822fc931582SAndy Adamson } 2823fc931582SAndy Adamson 2824fc931582SAndy Adamson /* 28250f3e66c6SAndy Adamson * a DESTROY_SESSION request 28260f3e66c6SAndy Adamson */ 28279f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 28289f06c719SChuck Lever struct xdr_stream *xdr, 28290f3e66c6SAndy Adamson struct nfs4_session *session) 28300f3e66c6SAndy Adamson { 28310f3e66c6SAndy Adamson struct compound_hdr hdr = { 2832a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 28330f3e66c6SAndy Adamson }; 28340f3e66c6SAndy Adamson 28359f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28369f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 28370f3e66c6SAndy Adamson encode_nops(&hdr); 28380f3e66c6SAndy Adamson } 28390f3e66c6SAndy Adamson 28400f3e66c6SAndy Adamson /* 284166245539STrond Myklebust * a DESTROY_CLIENTID request 284266245539STrond Myklebust */ 284366245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 284466245539STrond Myklebust struct xdr_stream *xdr, 284566245539STrond Myklebust struct nfs_client *clp) 284666245539STrond Myklebust { 284766245539STrond Myklebust struct compound_hdr hdr = { 284866245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 284966245539STrond Myklebust }; 285066245539STrond Myklebust 285166245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 285266245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 285366245539STrond Myklebust encode_nops(&hdr); 285466245539STrond Myklebust } 285566245539STrond Myklebust 285666245539STrond Myklebust /* 2857fc01cea9SAndy Adamson * a SEQUENCE request 2858fc01cea9SAndy Adamson */ 28599f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2860fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2861fc01cea9SAndy Adamson { 2862fc01cea9SAndy Adamson struct compound_hdr hdr = { 2863fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2864fc01cea9SAndy Adamson }; 2865fc01cea9SAndy Adamson 28669f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28679f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2868fc01cea9SAndy Adamson encode_nops(&hdr); 2869fc01cea9SAndy Adamson } 2870fc01cea9SAndy Adamson 2871fc01cea9SAndy Adamson /* 28722050f0ccSAndy Adamson * a GET_LEASE_TIME request 28732050f0ccSAndy Adamson */ 28749f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 28759f06c719SChuck Lever struct xdr_stream *xdr, 28762050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 28772050f0ccSAndy Adamson { 28782050f0ccSAndy Adamson struct compound_hdr hdr = { 28792050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 28802050f0ccSAndy Adamson }; 2881dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 28822050f0ccSAndy Adamson 28839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28849f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 28859f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 28869f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 28872050f0ccSAndy Adamson encode_nops(&hdr); 28882050f0ccSAndy Adamson } 288918019753SRicardo Labiaga 289018019753SRicardo Labiaga /* 289118019753SRicardo Labiaga * a RECLAIM_COMPLETE request 289218019753SRicardo Labiaga */ 28939f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 28949f06c719SChuck Lever struct xdr_stream *xdr, 289518019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 289618019753SRicardo Labiaga { 289718019753SRicardo Labiaga struct compound_hdr hdr = { 289818019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 289918019753SRicardo Labiaga }; 290018019753SRicardo Labiaga 29019f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29029f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29039f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 290418019753SRicardo Labiaga encode_nops(&hdr); 290518019753SRicardo Labiaga } 290618019753SRicardo Labiaga 2907b1f69b75SAndy Adamson /* 2908b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2909b1f69b75SAndy Adamson */ 29109f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 29119f06c719SChuck Lever struct xdr_stream *xdr, 2912b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2913b1f69b75SAndy Adamson { 2914b1f69b75SAndy Adamson struct compound_hdr hdr = { 2915b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2916b1f69b75SAndy Adamson }; 2917b1f69b75SAndy Adamson 29189f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29199f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29209f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2921b1f69b75SAndy Adamson 2922b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2923b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2924b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2925b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2926b1f69b75SAndy Adamson args->pdev->pglen); 2927b1f69b75SAndy Adamson 2928b1f69b75SAndy Adamson encode_nops(&hdr); 2929b1f69b75SAndy Adamson } 2930b1f69b75SAndy Adamson 2931b1f69b75SAndy Adamson /* 2932b1f69b75SAndy Adamson * Encode LAYOUTGET request 2933b1f69b75SAndy Adamson */ 29349f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 29359f06c719SChuck Lever struct xdr_stream *xdr, 2936b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2937b1f69b75SAndy Adamson { 2938b1f69b75SAndy Adamson struct compound_hdr hdr = { 2939b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2940b1f69b75SAndy Adamson }; 2941b1f69b75SAndy Adamson 29429f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29439f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29449f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 29459f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 294635124a09SWeston Andros Adamson 294735124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 294835124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 294935124a09SWeston Andros Adamson 2950b1f69b75SAndy Adamson encode_nops(&hdr); 2951b1f69b75SAndy Adamson } 2952863a3c6cSAndy Adamson 2953863a3c6cSAndy Adamson /* 2954863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2955863a3c6cSAndy Adamson */ 2956cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2957863a3c6cSAndy Adamson struct xdr_stream *xdr, 2958863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2959863a3c6cSAndy Adamson { 2960ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2961ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2962863a3c6cSAndy Adamson struct compound_hdr hdr = { 2963863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2964863a3c6cSAndy Adamson }; 2965863a3c6cSAndy Adamson 2966863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2967863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2968863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2969ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2970863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2971863a3c6cSAndy Adamson encode_nops(&hdr); 2972cbe82603SBenny Halevy } 2973cbe82603SBenny Halevy 2974cbe82603SBenny Halevy /* 2975cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2976cbe82603SBenny Halevy */ 2977cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2978cbe82603SBenny Halevy struct xdr_stream *xdr, 2979cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2980cbe82603SBenny Halevy { 2981cbe82603SBenny Halevy struct compound_hdr hdr = { 2982cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2983cbe82603SBenny Halevy }; 2984cbe82603SBenny Halevy 2985cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2986cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2987cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2988cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2989cbe82603SBenny Halevy encode_nops(&hdr); 2990863a3c6cSAndy Adamson } 2991fca78d6dSBryan Schumaker 2992fca78d6dSBryan Schumaker /* 2993fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2994fca78d6dSBryan Schumaker */ 2995fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2996fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2997fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2998fca78d6dSBryan Schumaker { 2999fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3000fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3001fca78d6dSBryan Schumaker }; 3002fca78d6dSBryan Schumaker 3003fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3004fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3005fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3006fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3007fca78d6dSBryan Schumaker encode_nops(&hdr); 3008fca78d6dSBryan Schumaker return 0; 3009fca78d6dSBryan Schumaker } 30107d974794SBryan Schumaker 30117d974794SBryan Schumaker /* 30127d974794SBryan Schumaker * Encode TEST_STATEID request 30137d974794SBryan Schumaker */ 30147d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 30157d974794SBryan Schumaker struct xdr_stream *xdr, 30167d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 30177d974794SBryan Schumaker { 30187d974794SBryan Schumaker struct compound_hdr hdr = { 30197d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30207d974794SBryan Schumaker }; 30217d974794SBryan Schumaker 30227d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30237d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30247d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 30257d974794SBryan Schumaker encode_nops(&hdr); 30267d974794SBryan Schumaker } 30279aeda35fSBryan Schumaker 30289aeda35fSBryan Schumaker /* 30299aeda35fSBryan Schumaker * Encode FREE_STATEID request 30309aeda35fSBryan Schumaker */ 30319aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 30329aeda35fSBryan Schumaker struct xdr_stream *xdr, 30339aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 30349aeda35fSBryan Schumaker { 30359aeda35fSBryan Schumaker struct compound_hdr hdr = { 30369aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30379aeda35fSBryan Schumaker }; 30389aeda35fSBryan Schumaker 30399aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30409aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30419aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 30429aeda35fSBryan Schumaker encode_nops(&hdr); 30439aeda35fSBryan Schumaker } 304499fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 304599fe60d0SBenny Halevy 3046686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3047686841b3SBenny Halevy { 3048686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3049686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3050686841b3SBenny Halevy func, xdr->end - xdr->p); 3051686841b3SBenny Halevy } 30521da177e4SLinus Torvalds 3053683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 30541da177e4SLinus Torvalds { 30556da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, 30566da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT); 30576da59ce2STrond Myklebust if (unlikely(ret < 0)) { 30586da59ce2STrond Myklebust if (ret == -EBADMSG) 3059c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3060c0eae66eSBenny Halevy return -EIO; 30611da177e4SLinus Torvalds } 30626da59ce2STrond Myklebust *len = ret; 30636da59ce2STrond Myklebust return 0; 30646da59ce2STrond Myklebust } 30651da177e4SLinus Torvalds 30661da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 30671da177e4SLinus Torvalds { 30688687b63aSAl Viro __be32 *p; 30691da177e4SLinus Torvalds 3070c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3071c0eae66eSBenny Halevy if (unlikely(!p)) 3072c0eae66eSBenny Halevy goto out_overflow; 30736f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3074cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 30751da177e4SLinus Torvalds 3076c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3077c0eae66eSBenny Halevy if (unlikely(!p)) 3078c0eae66eSBenny Halevy goto out_overflow; 30791da177e4SLinus Torvalds hdr->tag = (char *)p; 30801da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3081cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3082aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3083aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 30841da177e4SLinus Torvalds return 0; 3085c0eae66eSBenny Halevy out_overflow: 3086c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3087c0eae66eSBenny Halevy return -EIO; 30881da177e4SLinus Torvalds } 30891da177e4SLinus Torvalds 3090c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3091c7848f69STrond Myklebust int *nfs_retval) 30921da177e4SLinus Torvalds { 30938687b63aSAl Viro __be32 *p; 30941da177e4SLinus Torvalds uint32_t opnum; 30951da177e4SLinus Torvalds int32_t nfserr; 30961da177e4SLinus Torvalds 3097c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3098c0eae66eSBenny Halevy if (unlikely(!p)) 3099c0eae66eSBenny Halevy goto out_overflow; 31006f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3101c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3102c7848f69STrond Myklebust goto out_bad_operation; 3103c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3104c7848f69STrond Myklebust if (nfserr == NFS_OK) 3105c7848f69STrond Myklebust *nfs_retval = 0; 3106c7848f69STrond Myklebust else 3107c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3108c7848f69STrond Myklebust return true; 3109c7848f69STrond Myklebust out_bad_operation: 3110fe82a183SChuck Lever dprintk("nfs: Server returned operation" 31111da177e4SLinus Torvalds " %d but we issued a request for %d\n", 31121da177e4SLinus Torvalds opnum, expected); 3113c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3114c7848f69STrond Myklebust return false; 3115c0eae66eSBenny Halevy out_overflow: 3116c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3117c7848f69STrond Myklebust *nfs_retval = -EIO; 3118c7848f69STrond Myklebust return false; 3119c7848f69STrond Myklebust } 3120c7848f69STrond Myklebust 3121c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3122c7848f69STrond Myklebust { 3123c7848f69STrond Myklebust int retval; 3124c7848f69STrond Myklebust 3125c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3126c7848f69STrond Myklebust return retval; 31271da177e4SLinus Torvalds } 31281da177e4SLinus Torvalds 31291da177e4SLinus Torvalds /* Dummy routine */ 3130adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 31311da177e4SLinus Torvalds { 31328687b63aSAl Viro __be32 *p; 3133683b57b4STrond Myklebust unsigned int strlen; 31341da177e4SLinus Torvalds char *str; 31351da177e4SLinus Torvalds 3136c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3137c0eae66eSBenny Halevy if (likely(p)) 31381da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3139c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3140c0eae66eSBenny Halevy return -EIO; 31411da177e4SLinus Torvalds } 31421da177e4SLinus Torvalds 31431da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 31441da177e4SLinus Torvalds { 31458687b63aSAl Viro uint32_t bmlen; 31468687b63aSAl Viro __be32 *p; 31471da177e4SLinus Torvalds 3148c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3149c0eae66eSBenny Halevy if (unlikely(!p)) 3150c0eae66eSBenny Halevy goto out_overflow; 3151cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 31521da177e4SLinus Torvalds 3153dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3154c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3155c0eae66eSBenny Halevy if (unlikely(!p)) 3156c0eae66eSBenny Halevy goto out_overflow; 31571da177e4SLinus Torvalds if (bmlen > 0) { 31586f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3159dae100c2SFred Isaman if (bmlen > 1) { 3160dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3161dae100c2SFred Isaman if (bmlen > 2) 3162dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3163dae100c2SFred Isaman } 31641da177e4SLinus Torvalds } 31651da177e4SLinus Torvalds return 0; 3166c0eae66eSBenny Halevy out_overflow: 3167c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3168c0eae66eSBenny Halevy return -EIO; 31691da177e4SLinus Torvalds } 31701da177e4SLinus Torvalds 3171256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 31721da177e4SLinus Torvalds { 31738687b63aSAl Viro __be32 *p; 31741da177e4SLinus Torvalds 3175c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3176c0eae66eSBenny Halevy if (unlikely(!p)) 3177c0eae66eSBenny Halevy goto out_overflow; 3178cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3179256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 31801da177e4SLinus Torvalds return 0; 3181c0eae66eSBenny Halevy out_overflow: 3182c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3183c0eae66eSBenny Halevy return -EIO; 31841da177e4SLinus Torvalds } 31851da177e4SLinus Torvalds 31861da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 31871da177e4SLinus Torvalds { 31881da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 31893388bff5SRoman Borisov int ret; 31903388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 31913388bff5SRoman Borisov if (unlikely(ret < 0)) 31923388bff5SRoman Borisov return ret; 31931da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 31941da177e4SLinus Torvalds } else 3195dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3196dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3197dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 31981da177e4SLinus Torvalds return 0; 31991da177e4SLinus Torvalds } 32001da177e4SLinus Torvalds 32011da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32021da177e4SLinus Torvalds { 32038687b63aSAl Viro __be32 *p; 3204409924e4STrond Myklebust int ret = 0; 32051da177e4SLinus Torvalds 32061da177e4SLinus Torvalds *type = 0; 32071da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32081da177e4SLinus Torvalds return -EIO; 32091da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3210c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3211c0eae66eSBenny Halevy if (unlikely(!p)) 3212c0eae66eSBenny Halevy goto out_overflow; 3213cccddf4fSBenny Halevy *type = be32_to_cpup(p); 32141da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 32153110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 32161da177e4SLinus Torvalds return -EIO; 32171da177e4SLinus Torvalds } 32181da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3219409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 32201da177e4SLinus Torvalds } 3221bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3222409924e4STrond Myklebust return ret; 3223c0eae66eSBenny Halevy out_overflow: 3224c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3225c0eae66eSBenny Halevy return -EIO; 32261da177e4SLinus Torvalds } 32271da177e4SLinus Torvalds 3228264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3229264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3230264e6351SChuck Lever { 3231264e6351SChuck Lever __be32 *p; 3232264e6351SChuck Lever 3233264e6351SChuck Lever *type = 0; 3234264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3235264e6351SChuck Lever return -EIO; 3236264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3237264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3238264e6351SChuck Lever if (unlikely(!p)) 3239264e6351SChuck Lever goto out_overflow; 3240264e6351SChuck Lever *type = be32_to_cpup(p); 3241264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3242264e6351SChuck Lever } 3243264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3244264e6351SChuck Lever return 0; 3245264e6351SChuck Lever out_overflow: 3246264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3247264e6351SChuck Lever return -EIO; 3248264e6351SChuck Lever } 3249264e6351SChuck Lever 32501da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 32511da177e4SLinus Torvalds { 32528687b63aSAl Viro __be32 *p; 3253409924e4STrond Myklebust int ret = 0; 32541da177e4SLinus Torvalds 32551da177e4SLinus Torvalds *change = 0; 32561da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 32571da177e4SLinus Torvalds return -EIO; 32581da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3259c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3260c0eae66eSBenny Halevy if (unlikely(!p)) 3261c0eae66eSBenny Halevy goto out_overflow; 3262cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 32631da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3264409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 32651da177e4SLinus Torvalds } 32663110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 32671da177e4SLinus Torvalds (unsigned long long)*change); 3268409924e4STrond Myklebust return ret; 3269c0eae66eSBenny Halevy out_overflow: 3270c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3271c0eae66eSBenny Halevy return -EIO; 32721da177e4SLinus Torvalds } 32731da177e4SLinus Torvalds 32741da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 32751da177e4SLinus Torvalds { 32768687b63aSAl Viro __be32 *p; 3277409924e4STrond Myklebust int ret = 0; 32781da177e4SLinus Torvalds 32791da177e4SLinus Torvalds *size = 0; 32801da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 32811da177e4SLinus Torvalds return -EIO; 32821da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3283c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3284c0eae66eSBenny Halevy if (unlikely(!p)) 3285c0eae66eSBenny Halevy goto out_overflow; 3286cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 32871da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3288409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 32891da177e4SLinus Torvalds } 32903110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3291409924e4STrond Myklebust return ret; 3292c0eae66eSBenny Halevy out_overflow: 3293c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3294c0eae66eSBenny Halevy return -EIO; 32951da177e4SLinus Torvalds } 32961da177e4SLinus Torvalds 32971da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32981da177e4SLinus Torvalds { 32998687b63aSAl Viro __be32 *p; 33001da177e4SLinus Torvalds 33011da177e4SLinus Torvalds *res = 0; 33021da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33031da177e4SLinus Torvalds return -EIO; 33041da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3305c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3306c0eae66eSBenny Halevy if (unlikely(!p)) 3307c0eae66eSBenny Halevy goto out_overflow; 3308cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33091da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 33101da177e4SLinus Torvalds } 33113110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 33121da177e4SLinus Torvalds return 0; 3313c0eae66eSBenny Halevy out_overflow: 3314c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3315c0eae66eSBenny Halevy return -EIO; 33161da177e4SLinus Torvalds } 33171da177e4SLinus Torvalds 33181da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33191da177e4SLinus Torvalds { 33208687b63aSAl Viro __be32 *p; 33211da177e4SLinus Torvalds 33221da177e4SLinus Torvalds *res = 0; 33231da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 33241da177e4SLinus Torvalds return -EIO; 33251da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3326c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3327c0eae66eSBenny Halevy if (unlikely(!p)) 3328c0eae66eSBenny Halevy goto out_overflow; 3329cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33301da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 33311da177e4SLinus Torvalds } 33323110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 33331da177e4SLinus Torvalds return 0; 3334c0eae66eSBenny Halevy out_overflow: 3335c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3336c0eae66eSBenny Halevy return -EIO; 33371da177e4SLinus Torvalds } 33381da177e4SLinus Torvalds 33398b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 33401da177e4SLinus Torvalds { 33418687b63aSAl Viro __be32 *p; 3342409924e4STrond Myklebust int ret = 0; 33431da177e4SLinus Torvalds 33441da177e4SLinus Torvalds fsid->major = 0; 33451da177e4SLinus Torvalds fsid->minor = 0; 33461da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 33471da177e4SLinus Torvalds return -EIO; 33481da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3349c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3350c0eae66eSBenny Halevy if (unlikely(!p)) 3351c0eae66eSBenny Halevy goto out_overflow; 33523ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3353cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 33541da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3355409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 33561da177e4SLinus Torvalds } 33573110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 33581da177e4SLinus Torvalds (unsigned long long)fsid->major, 33591da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3360409924e4STrond Myklebust return ret; 3361c0eae66eSBenny Halevy out_overflow: 3362c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3363c0eae66eSBenny Halevy return -EIO; 33641da177e4SLinus Torvalds } 33651da177e4SLinus Torvalds 33661da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33671da177e4SLinus Torvalds { 33688687b63aSAl Viro __be32 *p; 33691da177e4SLinus Torvalds 33701da177e4SLinus Torvalds *res = 60; 33711da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 33721da177e4SLinus Torvalds return -EIO; 33731da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3374c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3375c0eae66eSBenny Halevy if (unlikely(!p)) 3376c0eae66eSBenny Halevy goto out_overflow; 3377cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33781da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 33791da177e4SLinus Torvalds } 33803110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 33811da177e4SLinus Torvalds return 0; 3382c0eae66eSBenny Halevy out_overflow: 3383c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3384c0eae66eSBenny Halevy return -EIO; 33851da177e4SLinus Torvalds } 33861da177e4SLinus Torvalds 3387ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3388ae42c70aSBryan Schumaker { 3389ae42c70aSBryan Schumaker __be32 *p; 3390ae42c70aSBryan Schumaker 3391ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3392ae42c70aSBryan Schumaker return -EIO; 3393ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3394ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3395ae42c70aSBryan Schumaker if (unlikely(!p)) 3396ae42c70aSBryan Schumaker goto out_overflow; 3397ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3398ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3399ae42c70aSBryan Schumaker } 3400ae42c70aSBryan Schumaker return 0; 3401ae42c70aSBryan Schumaker out_overflow: 3402ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3403ae42c70aSBryan Schumaker return -EIO; 3404ae42c70aSBryan Schumaker } 3405ae42c70aSBryan Schumaker 34068c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 34078c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 34088c61282fSKinglong Mee { 34098c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 34108c61282fSKinglong Mee int ret; 34118c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 34128c61282fSKinglong Mee if (unlikely(ret < 0)) 34138c61282fSKinglong Mee return ret; 34148c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 34158c61282fSKinglong Mee } else 34168c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 34178c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 34188c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 34198c61282fSKinglong Mee return 0; 34208c61282fSKinglong Mee } 34218c61282fSKinglong Mee 3422ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3423ae42c70aSBryan Schumaker { 3424ae42c70aSBryan Schumaker __be32 *p; 3425ae42c70aSBryan Schumaker int len; 3426ae42c70aSBryan Schumaker 34277ad07353STrond Myklebust if (fh != NULL) 3428ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3429ae42c70aSBryan Schumaker 3430ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3431ae42c70aSBryan Schumaker return -EIO; 3432ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3433ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3434ae42c70aSBryan Schumaker if (unlikely(!p)) 3435ae42c70aSBryan Schumaker goto out_overflow; 3436ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3437ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3438ae42c70aSBryan Schumaker return -EIO; 3439ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3440ae42c70aSBryan Schumaker if (unlikely(!p)) 3441ae42c70aSBryan Schumaker goto out_overflow; 34427ad07353STrond Myklebust if (fh != NULL) { 3443ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 34447ad07353STrond Myklebust fh->size = len; 34457ad07353STrond Myklebust } 3446ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3447ae42c70aSBryan Schumaker } 3448ae42c70aSBryan Schumaker return 0; 3449ae42c70aSBryan Schumaker out_overflow: 3450ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3451ae42c70aSBryan Schumaker return -EIO; 3452ae42c70aSBryan Schumaker } 3453ae42c70aSBryan Schumaker 34541da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34551da177e4SLinus Torvalds { 34568687b63aSAl Viro __be32 *p; 34571da177e4SLinus Torvalds 3458a1800acaSMalahal Naineni *res = 0; 34591da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 34601da177e4SLinus Torvalds return -EIO; 34611da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3462c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3463c0eae66eSBenny Halevy if (unlikely(!p)) 3464c0eae66eSBenny Halevy goto out_overflow; 3465cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34661da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 34671da177e4SLinus Torvalds } 34683110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 34691da177e4SLinus Torvalds return 0; 3470c0eae66eSBenny Halevy out_overflow: 3471c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3472c0eae66eSBenny Halevy return -EIO; 34731da177e4SLinus Torvalds } 34741da177e4SLinus Torvalds 34751da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 34761da177e4SLinus Torvalds { 34778687b63aSAl Viro __be32 *p; 3478409924e4STrond Myklebust int ret = 0; 34791da177e4SLinus Torvalds 34801da177e4SLinus Torvalds *fileid = 0; 34811da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 34821da177e4SLinus Torvalds return -EIO; 34831da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3484c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3485c0eae66eSBenny Halevy if (unlikely(!p)) 3486c0eae66eSBenny Halevy goto out_overflow; 3487cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 34881da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3489409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 34901da177e4SLinus Torvalds } 34913110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3492409924e4STrond Myklebust return ret; 3493c0eae66eSBenny Halevy out_overflow: 3494c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3495c0eae66eSBenny Halevy return -EIO; 34961da177e4SLinus Torvalds } 34971da177e4SLinus Torvalds 349899baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 349999baf625SManoj Naik { 35008687b63aSAl Viro __be32 *p; 3501409924e4STrond Myklebust int ret = 0; 350299baf625SManoj Naik 350399baf625SManoj Naik *fileid = 0; 350499baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 350599baf625SManoj Naik return -EIO; 350699baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3507c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3508c0eae66eSBenny Halevy if (unlikely(!p)) 3509c0eae66eSBenny Halevy goto out_overflow; 3510cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 351199baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 351228331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 351399baf625SManoj Naik } 35143110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3515409924e4STrond Myklebust return ret; 3516c0eae66eSBenny Halevy out_overflow: 3517c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3518c0eae66eSBenny Halevy return -EIO; 351999baf625SManoj Naik } 352099baf625SManoj Naik 35211da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35221da177e4SLinus Torvalds { 35238687b63aSAl Viro __be32 *p; 35241da177e4SLinus Torvalds int status = 0; 35251da177e4SLinus Torvalds 35261da177e4SLinus Torvalds *res = 0; 35271da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 35281da177e4SLinus Torvalds return -EIO; 35291da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3530c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3531c0eae66eSBenny Halevy if (unlikely(!p)) 3532c0eae66eSBenny Halevy goto out_overflow; 3533cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 35351da177e4SLinus Torvalds } 35363110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 35371da177e4SLinus Torvalds return status; 3538c0eae66eSBenny Halevy out_overflow: 3539c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3540c0eae66eSBenny Halevy return -EIO; 35411da177e4SLinus Torvalds } 35421da177e4SLinus Torvalds 35431da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35441da177e4SLinus Torvalds { 35458687b63aSAl Viro __be32 *p; 35461da177e4SLinus Torvalds int status = 0; 35471da177e4SLinus Torvalds 35481da177e4SLinus Torvalds *res = 0; 35491da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 35501da177e4SLinus Torvalds return -EIO; 35511da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3552c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3553c0eae66eSBenny Halevy if (unlikely(!p)) 3554c0eae66eSBenny Halevy goto out_overflow; 3555cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35561da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 35571da177e4SLinus Torvalds } 35583110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 35591da177e4SLinus Torvalds return status; 3560c0eae66eSBenny Halevy out_overflow: 3561c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3562c0eae66eSBenny Halevy return -EIO; 35631da177e4SLinus Torvalds } 35641da177e4SLinus Torvalds 35651da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35661da177e4SLinus Torvalds { 35678687b63aSAl Viro __be32 *p; 35681da177e4SLinus Torvalds int status = 0; 35691da177e4SLinus Torvalds 35701da177e4SLinus Torvalds *res = 0; 35711da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 35721da177e4SLinus Torvalds return -EIO; 35731da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3574c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3575c0eae66eSBenny Halevy if (unlikely(!p)) 3576c0eae66eSBenny Halevy goto out_overflow; 3577cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35781da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 35791da177e4SLinus Torvalds } 35803110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 35811da177e4SLinus Torvalds return status; 3582c0eae66eSBenny Halevy out_overflow: 3583c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3584c0eae66eSBenny Halevy return -EIO; 35851da177e4SLinus Torvalds } 35861da177e4SLinus Torvalds 35877aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 35887aaa0b3bSManoj Naik { 3589464ad6b1SChuck Lever u32 n; 35908687b63aSAl Viro __be32 *p; 35917aaa0b3bSManoj Naik int status = 0; 35927aaa0b3bSManoj Naik 3593c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3594c0eae66eSBenny Halevy if (unlikely(!p)) 3595c0eae66eSBenny Halevy goto out_overflow; 3596cccddf4fSBenny Halevy n = be32_to_cpup(p); 359733a43f28SAndy Adamson if (n == 0) 359833a43f28SAndy Adamson goto root_path; 359902a2976cSChuck Lever dprintk("pathname4: "); 3600809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3601809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3602809b426cSTrond Myklebust goto out_eio; 3603809b426cSTrond Myklebust } 3604809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36057aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 36067aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 36077aaa0b3bSManoj Naik if (unlikely(status != 0)) 36087aaa0b3bSManoj Naik goto out_eio; 360995a13f7bSTrond Myklebust ifdebug (XDR) 361002a2976cSChuck Lever pr_cont("%s%.*s ", 361102a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 361202a2976cSChuck Lever component->len, component->data); 36137aaa0b3bSManoj Naik } 36147aaa0b3bSManoj Naik out: 36157aaa0b3bSManoj Naik return status; 361633a43f28SAndy Adamson root_path: 361733a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 361833a43f28SAndy Adamson path->ncomponents = 1; 361933a43f28SAndy Adamson path->components[0].len=0; 362033a43f28SAndy Adamson path->components[0].data=NULL; 362102a2976cSChuck Lever dprintk("pathname4: /\n"); 362233a43f28SAndy Adamson goto out; 36237aaa0b3bSManoj Naik out_eio: 36247aaa0b3bSManoj Naik dprintk(" status %d", status); 36257aaa0b3bSManoj Naik status = -EIO; 36267aaa0b3bSManoj Naik goto out; 3627c0eae66eSBenny Halevy out_overflow: 3628c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3629c0eae66eSBenny Halevy return -EIO; 36307aaa0b3bSManoj Naik } 36317aaa0b3bSManoj Naik 36327aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3633683b57b4STrond Myklebust { 3634683b57b4STrond Myklebust int n; 36358687b63aSAl Viro __be32 *p; 3636683b57b4STrond Myklebust int status = -EIO; 3637683b57b4STrond Myklebust 3638683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3639683b57b4STrond Myklebust goto out; 3640683b57b4STrond Myklebust status = 0; 3641683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3642683b57b4STrond Myklebust goto out; 3643f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 36448b7e3f49STrond Myklebust status = -EIO; 36458b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 36468b7e3f49STrond Myklebust if (unlikely(res == NULL)) 36478b7e3f49STrond Myklebust goto out; 364802a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 36497aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3650683b57b4STrond Myklebust if (unlikely(status != 0)) 3651683b57b4STrond Myklebust goto out; 3652c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3653c0eae66eSBenny Halevy if (unlikely(!p)) 3654c0eae66eSBenny Halevy goto out_overflow; 3655cccddf4fSBenny Halevy n = be32_to_cpup(p); 3656683b57b4STrond Myklebust if (n <= 0) 3657683b57b4STrond Myklebust goto out_eio; 3658809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3659464ad6b1SChuck Lever u32 m; 3660809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3661683b57b4STrond Myklebust 3662809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3663809b426cSTrond Myklebust break; 3664809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3665c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3666c0eae66eSBenny Halevy if (unlikely(!p)) 3667c0eae66eSBenny Halevy goto out_overflow; 3668cccddf4fSBenny Halevy m = be32_to_cpup(p); 36697aaa0b3bSManoj Naik 367002a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3671809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3672809b426cSTrond Myklebust struct nfs4_string *server; 3673809b426cSTrond Myklebust 3674809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3675464ad6b1SChuck Lever unsigned int i; 3676464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3677464ad6b1SChuck Lever "returned for location %u\n", 36783110ff80SHarvey Harrison __func__, 3679464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3680464ad6b1SChuck Lever m, res->nlocations); 36817aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 36822e42c3e2STrond Myklebust unsigned int len; 36837aaa0b3bSManoj Naik char *data; 36847aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3685683b57b4STrond Myklebust if (unlikely(status != 0)) 3686683b57b4STrond Myklebust goto out_eio; 36877aaa0b3bSManoj Naik } 3688809b426cSTrond Myklebust break; 36897aaa0b3bSManoj Naik } 3690809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3691809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3692809b426cSTrond Myklebust if (unlikely(status != 0)) 3693809b426cSTrond Myklebust goto out_eio; 3694809b426cSTrond Myklebust dprintk("%s ", server->data); 36957aaa0b3bSManoj Naik } 36967aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 36977aaa0b3bSManoj Naik if (unlikely(status != 0)) 36987aaa0b3bSManoj Naik goto out_eio; 3699683b57b4STrond Myklebust } 3700409924e4STrond Myklebust if (res->nlocations != 0) 370181934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3702683b57b4STrond Myklebust out: 37033110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3704683b57b4STrond Myklebust return status; 3705c0eae66eSBenny Halevy out_overflow: 3706c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3707683b57b4STrond Myklebust out_eio: 3708683b57b4STrond Myklebust status = -EIO; 3709683b57b4STrond Myklebust goto out; 3710683b57b4STrond Myklebust } 3711683b57b4STrond Myklebust 37121da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 37131da177e4SLinus Torvalds { 37148687b63aSAl Viro __be32 *p; 37151da177e4SLinus Torvalds int status = 0; 37161da177e4SLinus Torvalds 37171da177e4SLinus Torvalds *res = 0; 37181da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 37191da177e4SLinus Torvalds return -EIO; 37201da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3721c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3722c0eae66eSBenny Halevy if (unlikely(!p)) 3723c0eae66eSBenny Halevy goto out_overflow; 3724cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 37251da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 37261da177e4SLinus Torvalds } 37273110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 37281da177e4SLinus Torvalds return status; 3729c0eae66eSBenny Halevy out_overflow: 3730c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3731c0eae66eSBenny Halevy return -EIO; 37321da177e4SLinus Torvalds } 37331da177e4SLinus Torvalds 37341da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 37351da177e4SLinus Torvalds { 37368687b63aSAl Viro __be32 *p; 37371da177e4SLinus Torvalds int status = 0; 37381da177e4SLinus Torvalds 37391da177e4SLinus Torvalds *maxlink = 1; 37401da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 37411da177e4SLinus Torvalds return -EIO; 37421da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3743c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3744c0eae66eSBenny Halevy if (unlikely(!p)) 3745c0eae66eSBenny Halevy goto out_overflow; 3746cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 37471da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 37481da177e4SLinus Torvalds } 37493110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 37501da177e4SLinus Torvalds return status; 3751c0eae66eSBenny Halevy out_overflow: 3752c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3753c0eae66eSBenny Halevy return -EIO; 37541da177e4SLinus Torvalds } 37551da177e4SLinus Torvalds 37561da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 37571da177e4SLinus Torvalds { 37588687b63aSAl Viro __be32 *p; 37591da177e4SLinus Torvalds int status = 0; 37601da177e4SLinus Torvalds 37611da177e4SLinus Torvalds *maxname = 1024; 37621da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 37631da177e4SLinus Torvalds return -EIO; 37641da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3765c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3766c0eae66eSBenny Halevy if (unlikely(!p)) 3767c0eae66eSBenny Halevy goto out_overflow; 3768cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 37691da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 37701da177e4SLinus Torvalds } 37713110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 37721da177e4SLinus Torvalds return status; 3773c0eae66eSBenny Halevy out_overflow: 3774c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3775c0eae66eSBenny Halevy return -EIO; 37761da177e4SLinus Torvalds } 37771da177e4SLinus Torvalds 37781da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37791da177e4SLinus Torvalds { 37808687b63aSAl Viro __be32 *p; 37811da177e4SLinus Torvalds int status = 0; 37821da177e4SLinus Torvalds 37831da177e4SLinus Torvalds *res = 1024; 37841da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 37851da177e4SLinus Torvalds return -EIO; 37861da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 37871da177e4SLinus Torvalds uint64_t maxread; 3788c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3789c0eae66eSBenny Halevy if (unlikely(!p)) 3790c0eae66eSBenny Halevy goto out_overflow; 3791cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 37921da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 37931da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 37941da177e4SLinus Torvalds *res = (uint32_t)maxread; 37951da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 37961da177e4SLinus Torvalds } 37973110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 37981da177e4SLinus Torvalds return status; 3799c0eae66eSBenny Halevy out_overflow: 3800c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3801c0eae66eSBenny Halevy return -EIO; 38021da177e4SLinus Torvalds } 38031da177e4SLinus Torvalds 38041da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38051da177e4SLinus Torvalds { 38068687b63aSAl Viro __be32 *p; 38071da177e4SLinus Torvalds int status = 0; 38081da177e4SLinus Torvalds 38091da177e4SLinus Torvalds *res = 1024; 38101da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 38111da177e4SLinus Torvalds return -EIO; 38121da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 38131da177e4SLinus Torvalds uint64_t maxwrite; 3814c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3815c0eae66eSBenny Halevy if (unlikely(!p)) 3816c0eae66eSBenny Halevy goto out_overflow; 3817cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 38181da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 38191da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 38201da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 38211da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 38221da177e4SLinus Torvalds } 38233110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 38241da177e4SLinus Torvalds return status; 3825c0eae66eSBenny Halevy out_overflow: 3826c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3827c0eae66eSBenny Halevy return -EIO; 38281da177e4SLinus Torvalds } 38291da177e4SLinus Torvalds 3830bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 38311da177e4SLinus Torvalds { 3832bca79478STrond Myklebust uint32_t tmp; 38338687b63aSAl Viro __be32 *p; 3834409924e4STrond Myklebust int ret = 0; 38351da177e4SLinus Torvalds 38361da177e4SLinus Torvalds *mode = 0; 38371da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 38381da177e4SLinus Torvalds return -EIO; 38391da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3840c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3841c0eae66eSBenny Halevy if (unlikely(!p)) 3842c0eae66eSBenny Halevy goto out_overflow; 3843cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3844bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 38451da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3846409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 38471da177e4SLinus Torvalds } 38483110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3849409924e4STrond Myklebust return ret; 3850c0eae66eSBenny Halevy out_overflow: 3851c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3852c0eae66eSBenny Halevy return -EIO; 38531da177e4SLinus Torvalds } 38541da177e4SLinus Torvalds 38551da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 38561da177e4SLinus Torvalds { 38578687b63aSAl Viro __be32 *p; 3858409924e4STrond Myklebust int ret = 0; 38591da177e4SLinus Torvalds 38601da177e4SLinus Torvalds *nlink = 1; 38611da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 38621da177e4SLinus Torvalds return -EIO; 38631da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3864c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3865c0eae66eSBenny Halevy if (unlikely(!p)) 3866c0eae66eSBenny Halevy goto out_overflow; 3867cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 38681da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3869409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 38701da177e4SLinus Torvalds } 38713110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3872409924e4STrond Myklebust return ret; 3873c0eae66eSBenny Halevy out_overflow: 3874c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3875c0eae66eSBenny Halevy return -EIO; 38761da177e4SLinus Torvalds } 38771da177e4SLinus Torvalds 387880e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3879e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 38806926afd1STrond Myklebust struct nfs4_string *owner_name) 38811da177e4SLinus Torvalds { 38828687b63aSAl Viro uint32_t len; 38838687b63aSAl Viro __be32 *p; 3884409924e4STrond Myklebust int ret = 0; 38851da177e4SLinus Torvalds 3886e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 38871da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 38881da177e4SLinus Torvalds return -EIO; 38891da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3890c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3891c0eae66eSBenny Halevy if (unlikely(!p)) 3892c0eae66eSBenny Halevy goto out_overflow; 3893cccddf4fSBenny Halevy len = be32_to_cpup(p); 3894c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3895c0eae66eSBenny Halevy if (unlikely(!p)) 3896c0eae66eSBenny Halevy goto out_overflow; 38976926afd1STrond Myklebust if (owner_name != NULL) { 38986926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 38996926afd1STrond Myklebust if (owner_name->data != NULL) { 39006926afd1STrond Myklebust owner_name->len = len; 39016926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 39026926afd1STrond Myklebust } 390380e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3904e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3905409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3906409924e4STrond Myklebust else 39071da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 39083110ff80SHarvey Harrison __func__); 39091da177e4SLinus Torvalds } else 3910fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 39113110ff80SHarvey Harrison __func__, len); 39121da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 39131da177e4SLinus Torvalds } 3914e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3915409924e4STrond Myklebust return ret; 3916c0eae66eSBenny Halevy out_overflow: 3917c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3918c0eae66eSBenny Halevy return -EIO; 39191da177e4SLinus Torvalds } 39201da177e4SLinus Torvalds 392180e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3922e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 39236926afd1STrond Myklebust struct nfs4_string *group_name) 39241da177e4SLinus Torvalds { 39258687b63aSAl Viro uint32_t len; 39268687b63aSAl Viro __be32 *p; 3927409924e4STrond Myklebust int ret = 0; 39281da177e4SLinus Torvalds 3929e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 39301da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 39311da177e4SLinus Torvalds return -EIO; 39321da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3933c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3934c0eae66eSBenny Halevy if (unlikely(!p)) 3935c0eae66eSBenny Halevy goto out_overflow; 3936cccddf4fSBenny Halevy len = be32_to_cpup(p); 3937c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3938c0eae66eSBenny Halevy if (unlikely(!p)) 3939c0eae66eSBenny Halevy goto out_overflow; 39406926afd1STrond Myklebust if (group_name != NULL) { 39416926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 39426926afd1STrond Myklebust if (group_name->data != NULL) { 39436926afd1STrond Myklebust group_name->len = len; 39446926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 39456926afd1STrond Myklebust } 394680e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3947e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3948409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3949409924e4STrond Myklebust else 39501da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 39513110ff80SHarvey Harrison __func__); 39521da177e4SLinus Torvalds } else 3953fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 39543110ff80SHarvey Harrison __func__, len); 39551da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 39561da177e4SLinus Torvalds } 3957e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 3958409924e4STrond Myklebust return ret; 3959c0eae66eSBenny Halevy out_overflow: 3960c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3961c0eae66eSBenny Halevy return -EIO; 39621da177e4SLinus Torvalds } 39631da177e4SLinus Torvalds 39641da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 39651da177e4SLinus Torvalds { 39668687b63aSAl Viro uint32_t major = 0, minor = 0; 39678687b63aSAl Viro __be32 *p; 3968409924e4STrond Myklebust int ret = 0; 39691da177e4SLinus Torvalds 39701da177e4SLinus Torvalds *rdev = MKDEV(0,0); 39711da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 39721da177e4SLinus Torvalds return -EIO; 39731da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 39741da177e4SLinus Torvalds dev_t tmp; 39751da177e4SLinus Torvalds 3976c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3977c0eae66eSBenny Halevy if (unlikely(!p)) 3978c0eae66eSBenny Halevy goto out_overflow; 39796f723f77SBenny Halevy major = be32_to_cpup(p++); 3980cccddf4fSBenny Halevy minor = be32_to_cpup(p); 39811da177e4SLinus Torvalds tmp = MKDEV(major, minor); 39821da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 39831da177e4SLinus Torvalds *rdev = tmp; 39841da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3985409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 39861da177e4SLinus Torvalds } 39873110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3988409924e4STrond Myklebust return ret; 3989c0eae66eSBenny Halevy out_overflow: 3990c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3991c0eae66eSBenny Halevy return -EIO; 39921da177e4SLinus Torvalds } 39931da177e4SLinus Torvalds 39941da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39951da177e4SLinus Torvalds { 39968687b63aSAl Viro __be32 *p; 39971da177e4SLinus Torvalds int status = 0; 39981da177e4SLinus Torvalds 39991da177e4SLinus Torvalds *res = 0; 40001da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 40011da177e4SLinus Torvalds return -EIO; 40021da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 4003c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4004c0eae66eSBenny Halevy if (unlikely(!p)) 4005c0eae66eSBenny Halevy goto out_overflow; 4006cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40071da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40081da177e4SLinus Torvalds } 40093110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 40101da177e4SLinus Torvalds return status; 4011c0eae66eSBenny Halevy out_overflow: 4012c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4013c0eae66eSBenny Halevy return -EIO; 40141da177e4SLinus Torvalds } 40151da177e4SLinus Torvalds 40161da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40171da177e4SLinus Torvalds { 40188687b63aSAl Viro __be32 *p; 40191da177e4SLinus Torvalds int status = 0; 40201da177e4SLinus Torvalds 40211da177e4SLinus Torvalds *res = 0; 40221da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 40231da177e4SLinus Torvalds return -EIO; 40241da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4025c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4026c0eae66eSBenny Halevy if (unlikely(!p)) 4027c0eae66eSBenny Halevy goto out_overflow; 4028cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40291da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 40301da177e4SLinus Torvalds } 40313110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 40321da177e4SLinus Torvalds return status; 4033c0eae66eSBenny Halevy out_overflow: 4034c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4035c0eae66eSBenny Halevy return -EIO; 40361da177e4SLinus Torvalds } 40371da177e4SLinus Torvalds 40381da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40391da177e4SLinus Torvalds { 40408687b63aSAl Viro __be32 *p; 40411da177e4SLinus Torvalds int status = 0; 40421da177e4SLinus Torvalds 40431da177e4SLinus Torvalds *res = 0; 40441da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 40451da177e4SLinus Torvalds return -EIO; 40461da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4047c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4048c0eae66eSBenny Halevy if (unlikely(!p)) 4049c0eae66eSBenny Halevy goto out_overflow; 4050cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40511da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 40521da177e4SLinus Torvalds } 40533110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 40541da177e4SLinus Torvalds return status; 4055c0eae66eSBenny Halevy out_overflow: 4056c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4057c0eae66eSBenny Halevy return -EIO; 40581da177e4SLinus Torvalds } 40591da177e4SLinus Torvalds 40601da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 40611da177e4SLinus Torvalds { 40628687b63aSAl Viro __be32 *p; 4063409924e4STrond Myklebust int ret = 0; 40641da177e4SLinus Torvalds 40651da177e4SLinus Torvalds *used = 0; 40661da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 40671da177e4SLinus Torvalds return -EIO; 40681da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4069c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4070c0eae66eSBenny Halevy if (unlikely(!p)) 4071c0eae66eSBenny Halevy goto out_overflow; 4072cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 40731da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4074409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 40751da177e4SLinus Torvalds } 40763110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 40771da177e4SLinus Torvalds (unsigned long long)*used); 4078409924e4STrond Myklebust return ret; 4079c0eae66eSBenny Halevy out_overflow: 4080c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4081c0eae66eSBenny Halevy return -EIO; 40821da177e4SLinus Torvalds } 40831da177e4SLinus Torvalds 40841da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 40851da177e4SLinus Torvalds { 40868687b63aSAl Viro __be32 *p; 40871da177e4SLinus Torvalds uint64_t sec; 40881da177e4SLinus Torvalds uint32_t nsec; 40891da177e4SLinus Torvalds 4090c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4091c0eae66eSBenny Halevy if (unlikely(!p)) 4092c0eae66eSBenny Halevy goto out_overflow; 40933ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 4094cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 40951da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 40961da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 40971da177e4SLinus Torvalds return 0; 4098c0eae66eSBenny Halevy out_overflow: 4099c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4100c0eae66eSBenny Halevy return -EIO; 41011da177e4SLinus Torvalds } 41021da177e4SLinus Torvalds 41031da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41041da177e4SLinus Torvalds { 41051da177e4SLinus Torvalds int status = 0; 41061da177e4SLinus Torvalds 41071da177e4SLinus Torvalds time->tv_sec = 0; 41081da177e4SLinus Torvalds time->tv_nsec = 0; 41091da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 41101da177e4SLinus Torvalds return -EIO; 41111da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 41121da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4113409924e4STrond Myklebust if (status == 0) 4114409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 41151da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 41161da177e4SLinus Torvalds } 41173110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 41181da177e4SLinus Torvalds return status; 41191da177e4SLinus Torvalds } 41201da177e4SLinus Torvalds 41211da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41221da177e4SLinus Torvalds { 41231da177e4SLinus Torvalds int status = 0; 41241da177e4SLinus Torvalds 41251da177e4SLinus Torvalds time->tv_sec = 0; 41261da177e4SLinus Torvalds time->tv_nsec = 0; 41271da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 41281da177e4SLinus Torvalds return -EIO; 41291da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 41301da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4131409924e4STrond Myklebust if (status == 0) 4132409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 41331da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 41341da177e4SLinus Torvalds } 41353110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 41361da177e4SLinus Torvalds return status; 41371da177e4SLinus Torvalds } 41381da177e4SLinus Torvalds 413955b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 414055b6e774SRicardo Labiaga struct timespec *time) 414155b6e774SRicardo Labiaga { 414255b6e774SRicardo Labiaga int status = 0; 414355b6e774SRicardo Labiaga 414455b6e774SRicardo Labiaga time->tv_sec = 0; 414555b6e774SRicardo Labiaga time->tv_nsec = 0; 414655b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 414755b6e774SRicardo Labiaga return -EIO; 414855b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 414955b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 415055b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 415155b6e774SRicardo Labiaga } 415255b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 415355b6e774SRicardo Labiaga (long)time->tv_nsec); 415455b6e774SRicardo Labiaga return status; 415555b6e774SRicardo Labiaga } 415655b6e774SRicardo Labiaga 4157aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4158aa9c2669SDavid Quigley struct nfs4_label *label) 4159aa9c2669SDavid Quigley { 4160aa9c2669SDavid Quigley uint32_t pi = 0; 4161aa9c2669SDavid Quigley uint32_t lfs = 0; 4162aa9c2669SDavid Quigley __u32 len; 4163aa9c2669SDavid Quigley __be32 *p; 4164aa9c2669SDavid Quigley int status = 0; 4165aa9c2669SDavid Quigley 4166aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4167aa9c2669SDavid Quigley return -EIO; 4168aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4169aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4170aa9c2669SDavid Quigley if (unlikely(!p)) 4171aa9c2669SDavid Quigley goto out_overflow; 4172aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4173aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4174aa9c2669SDavid Quigley if (unlikely(!p)) 4175aa9c2669SDavid Quigley goto out_overflow; 4176aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4177aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4178aa9c2669SDavid Quigley if (unlikely(!p)) 4179aa9c2669SDavid Quigley goto out_overflow; 4180aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4181aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4182aa9c2669SDavid Quigley if (unlikely(!p)) 4183aa9c2669SDavid Quigley goto out_overflow; 4184aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4185aa9c2669SDavid Quigley if (label) { 4186aa9c2669SDavid Quigley memcpy(label->label, p, len); 4187aa9c2669SDavid Quigley label->len = len; 4188aa9c2669SDavid Quigley label->pi = pi; 4189aa9c2669SDavid Quigley label->lfs = lfs; 4190aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4191aa9c2669SDavid Quigley } 4192aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4193aa9c2669SDavid Quigley } else 4194aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4195aa9c2669SDavid Quigley __func__, len); 4196aa9c2669SDavid Quigley } 4197aa9c2669SDavid Quigley if (label && label->label) 4198aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4199aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4200aa9c2669SDavid Quigley return status; 4201aa9c2669SDavid Quigley 4202aa9c2669SDavid Quigley out_overflow: 4203aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4204aa9c2669SDavid Quigley return -EIO; 4205aa9c2669SDavid Quigley } 4206aa9c2669SDavid Quigley 42071da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42081da177e4SLinus Torvalds { 42091da177e4SLinus Torvalds int status = 0; 42101da177e4SLinus Torvalds 42111da177e4SLinus Torvalds time->tv_sec = 0; 42121da177e4SLinus Torvalds time->tv_nsec = 0; 42131da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 42141da177e4SLinus Torvalds return -EIO; 42151da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 42161da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4217409924e4STrond Myklebust if (status == 0) 4218409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 42191da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 42201da177e4SLinus Torvalds } 42213110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 42221da177e4SLinus Torvalds return status; 42231da177e4SLinus Torvalds } 42241da177e4SLinus Torvalds 4225256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 42261da177e4SLinus Torvalds { 42271da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4228256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 42291da177e4SLinus Torvalds 42301da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4231fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4232fe82a183SChuck Lever "%u %c %u\n", 42333110ff80SHarvey Harrison __func__, 42341da177e4SLinus Torvalds attrwords << 2, 42351da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 42361da177e4SLinus Torvalds nwords << 2); 42371da177e4SLinus Torvalds return -EIO; 42381da177e4SLinus Torvalds } 42391da177e4SLinus Torvalds return 0; 42401da177e4SLinus Torvalds } 42411da177e4SLinus Torvalds 42421da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42431da177e4SLinus Torvalds { 42448687b63aSAl Viro __be32 *p; 42451da177e4SLinus Torvalds 4246c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4247c0eae66eSBenny Halevy if (unlikely(!p)) 4248c0eae66eSBenny Halevy goto out_overflow; 42496f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 42503ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4251cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 42521da177e4SLinus Torvalds return 0; 4253c0eae66eSBenny Halevy out_overflow: 4254c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4255c0eae66eSBenny Halevy return -EIO; 42561da177e4SLinus Torvalds } 42571da177e4SLinus Torvalds 42586168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 42591da177e4SLinus Torvalds { 42608687b63aSAl Viro __be32 *p; 42611da177e4SLinus Torvalds uint32_t supp, acc; 42621da177e4SLinus Torvalds int status; 42631da177e4SLinus Torvalds 42641da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 42651da177e4SLinus Torvalds if (status) 42661da177e4SLinus Torvalds return status; 4267c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4268c0eae66eSBenny Halevy if (unlikely(!p)) 4269c0eae66eSBenny Halevy goto out_overflow; 42706f723f77SBenny Halevy supp = be32_to_cpup(p++); 4271cccddf4fSBenny Halevy acc = be32_to_cpup(p); 42726168f62cSWeston Andros Adamson *supported = supp; 42736168f62cSWeston Andros Adamson *access = acc; 42741da177e4SLinus Torvalds return 0; 4275c0eae66eSBenny Halevy out_overflow: 4276c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4277c0eae66eSBenny Halevy return -EIO; 42781da177e4SLinus Torvalds } 42791da177e4SLinus Torvalds 428007d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 42811da177e4SLinus Torvalds { 4282ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); 4283ab6e9aafSTrond Myklebust if (unlikely(ret < 0)) { 428407d30434SBenny Halevy print_overflow_msg(__func__, xdr); 428507d30434SBenny Halevy return -EIO; 428607d30434SBenny Halevy } 4287ab6e9aafSTrond Myklebust return 0; 4288ab6e9aafSTrond Myklebust } 428907d30434SBenny Halevy 429007d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 429107d30434SBenny Halevy { 42922d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 42931da177e4SLinus Torvalds } 42941da177e4SLinus Torvalds 429593b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 429693b717fdSTrond Myklebust { 429793b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 429893b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 429993b717fdSTrond Myklebust } 430093b717fdSTrond Myklebust 430193b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 430293b717fdSTrond Myklebust { 430393b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 430493b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 430593b717fdSTrond Myklebust } 430693b717fdSTrond Myklebust 430793b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 430893b717fdSTrond Myklebust { 430993b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 431093b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 431193b717fdSTrond Myklebust } 431293b717fdSTrond Myklebust 43131da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 43141da177e4SLinus Torvalds { 43151da177e4SLinus Torvalds int status; 43161da177e4SLinus Torvalds 43171da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4318c1d51931STrond Myklebust if (status != -EIO) 4319c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 432007d30434SBenny Halevy if (!status) 432193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 43221da177e4SLinus Torvalds return status; 43231da177e4SLinus Torvalds } 43241da177e4SLinus Torvalds 4325db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4326db942bbdSBenny Halevy { 4327cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 43281da177e4SLinus Torvalds } 43291da177e4SLinus Torvalds 43302f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 43312f2c63bcSTrond Myklebust { 43322f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 43332f2c63bcSTrond Myklebust } 43342f2c63bcSTrond Myklebust 43350b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 43361da177e4SLinus Torvalds { 43371da177e4SLinus Torvalds int status; 43381da177e4SLinus Torvalds 43391da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4340db942bbdSBenny Halevy if (!status) 43412f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 43421da177e4SLinus Torvalds return status; 43431da177e4SLinus Torvalds } 43441da177e4SLinus Torvalds 43451da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43461da177e4SLinus Torvalds { 43478687b63aSAl Viro __be32 *p; 43481da177e4SLinus Torvalds uint32_t bmlen; 43491da177e4SLinus Torvalds int status; 43501da177e4SLinus Torvalds 43511da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 43521da177e4SLinus Torvalds if (status) 43531da177e4SLinus Torvalds return status; 43541da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 43551da177e4SLinus Torvalds return status; 4356c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4357c0eae66eSBenny Halevy if (unlikely(!p)) 4358c0eae66eSBenny Halevy goto out_overflow; 4359cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4360c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4361c0eae66eSBenny Halevy if (likely(p)) 43621da177e4SLinus Torvalds return 0; 4363c0eae66eSBenny Halevy out_overflow: 4364c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4365c0eae66eSBenny Halevy return -EIO; 43661da177e4SLinus Torvalds } 43671da177e4SLinus Torvalds 43681da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 43691da177e4SLinus Torvalds { 4370256e48bbSTrond Myklebust unsigned int savep; 4371dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43721da177e4SLinus Torvalds int status; 43731da177e4SLinus Torvalds 43741da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43751da177e4SLinus Torvalds goto xdr_error; 43761da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43771da177e4SLinus Torvalds goto xdr_error; 43781da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43791da177e4SLinus Torvalds goto xdr_error; 43801da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 43811da177e4SLinus Torvalds goto xdr_error; 4382264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4383264e6351SChuck Lever &res->fh_expire_type)) != 0) 4384264e6351SChuck Lever goto xdr_error; 43851da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 43861da177e4SLinus Torvalds goto xdr_error; 43871da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 43881da177e4SLinus Torvalds goto xdr_error; 43891da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 43901da177e4SLinus Torvalds goto xdr_error; 43918c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 43928c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 43938c61282fSKinglong Mee goto xdr_error; 43941da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43951da177e4SLinus Torvalds xdr_error: 43963110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43971da177e4SLinus Torvalds return status; 43981da177e4SLinus Torvalds } 43991da177e4SLinus Torvalds 44001da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 44011da177e4SLinus Torvalds { 4402256e48bbSTrond Myklebust unsigned int savep; 4403dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44041da177e4SLinus Torvalds int status; 44051da177e4SLinus Torvalds 44061da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44071da177e4SLinus Torvalds goto xdr_error; 44081da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44091da177e4SLinus Torvalds goto xdr_error; 44101da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44111da177e4SLinus Torvalds goto xdr_error; 44121da177e4SLinus Torvalds 44131da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 44141da177e4SLinus Torvalds goto xdr_error; 44151da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 44161da177e4SLinus Torvalds goto xdr_error; 44171da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 44181da177e4SLinus Torvalds goto xdr_error; 44191ca843a2SAndreas Gruenbacher 44201ca843a2SAndreas Gruenbacher status = -EIO; 44211ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 44221ca843a2SAndreas Gruenbacher goto xdr_error; 44231ca843a2SAndreas Gruenbacher 44241da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 44251da177e4SLinus Torvalds goto xdr_error; 44261da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 44271da177e4SLinus Torvalds goto xdr_error; 44281da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 44291da177e4SLinus Torvalds goto xdr_error; 44301da177e4SLinus Torvalds 44311da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44321da177e4SLinus Torvalds xdr_error: 44333110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44341da177e4SLinus Torvalds return status; 44351da177e4SLinus Torvalds } 44361da177e4SLinus Torvalds 44371da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 44381da177e4SLinus Torvalds { 4439256e48bbSTrond Myklebust unsigned int savep; 4440dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44411da177e4SLinus Torvalds int status; 44421da177e4SLinus Torvalds 44431da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44441da177e4SLinus Torvalds goto xdr_error; 44451da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44461da177e4SLinus Torvalds goto xdr_error; 44471da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44481da177e4SLinus Torvalds goto xdr_error; 44491da177e4SLinus Torvalds 44501da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 44511da177e4SLinus Torvalds goto xdr_error; 44521da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 44531da177e4SLinus Torvalds goto xdr_error; 44541da177e4SLinus Torvalds 44551da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44561da177e4SLinus Torvalds xdr_error: 44573110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44581da177e4SLinus Torvalds return status; 44591da177e4SLinus Torvalds } 44601da177e4SLinus Torvalds 446188034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 446288034c3dSAndy Adamson uint32_t *bitmap, 446388034c3dSAndy Adamson uint64_t *res, 446488034c3dSAndy Adamson uint32_t hint_bit) 446588034c3dSAndy Adamson { 446688034c3dSAndy Adamson __be32 *p; 446788034c3dSAndy Adamson 446888034c3dSAndy Adamson *res = 0; 446988034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 447088034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 447188034c3dSAndy Adamson if (unlikely(!p)) 447288034c3dSAndy Adamson goto out_overflow; 447388034c3dSAndy Adamson xdr_decode_hyper(p, res); 447488034c3dSAndy Adamson } 447588034c3dSAndy Adamson return 0; 447688034c3dSAndy Adamson out_overflow: 447788034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 447888034c3dSAndy Adamson return -EIO; 447988034c3dSAndy Adamson } 448088034c3dSAndy Adamson 448188034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 448288034c3dSAndy Adamson struct nfs4_threshold *res) 448388034c3dSAndy Adamson { 4484256e48bbSTrond Myklebust __be32 *p; 4485256e48bbSTrond Myklebust unsigned int savep; 448688034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 448788034c3dSAndy Adamson int status; 448888034c3dSAndy Adamson 448988034c3dSAndy Adamson /* layout type */ 449088034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 449188034c3dSAndy Adamson if (unlikely(!p)) { 449288034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 449388034c3dSAndy Adamson return -EIO; 449488034c3dSAndy Adamson } 449588034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 449688034c3dSAndy Adamson 449788034c3dSAndy Adamson /* thi_hintset bitmap */ 449888034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 449988034c3dSAndy Adamson if (status < 0) 450088034c3dSAndy Adamson goto xdr_error; 450188034c3dSAndy Adamson 450288034c3dSAndy Adamson /* thi_hintlist length */ 450388034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 450488034c3dSAndy Adamson if (status < 0) 450588034c3dSAndy Adamson goto xdr_error; 450688034c3dSAndy Adamson /* thi_hintlist */ 450788034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 450888034c3dSAndy Adamson if (status < 0) 450988034c3dSAndy Adamson goto xdr_error; 451088034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 451188034c3dSAndy Adamson if (status < 0) 451288034c3dSAndy Adamson goto xdr_error; 451388034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 451488034c3dSAndy Adamson THRESHOLD_RD_IO); 451588034c3dSAndy Adamson if (status < 0) 451688034c3dSAndy Adamson goto xdr_error; 451788034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 451888034c3dSAndy Adamson THRESHOLD_WR_IO); 451988034c3dSAndy Adamson if (status < 0) 452088034c3dSAndy Adamson goto xdr_error; 452188034c3dSAndy Adamson 452288034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 452388034c3dSAndy Adamson res->bm = bitmap[0]; 452488034c3dSAndy Adamson 452588034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 452688034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 452788034c3dSAndy Adamson res->wr_io_sz); 452888034c3dSAndy Adamson xdr_error: 452988034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 453088034c3dSAndy Adamson return status; 453188034c3dSAndy Adamson } 453288034c3dSAndy Adamson 453388034c3dSAndy Adamson /* 453488034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 453588034c3dSAndy Adamson */ 453688034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 453788034c3dSAndy Adamson uint32_t *bitmap, 453888034c3dSAndy Adamson struct nfs4_threshold *res) 453988034c3dSAndy Adamson { 454088034c3dSAndy Adamson __be32 *p; 454188034c3dSAndy Adamson int status = 0; 454288034c3dSAndy Adamson uint32_t num; 454388034c3dSAndy Adamson 454488034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 454588034c3dSAndy Adamson return -EIO; 4546029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 45471549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 45481549210fSTrond Myklebust if (unlikely(res == NULL)) 45491549210fSTrond Myklebust return -EREMOTEIO; 455088034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 455188034c3dSAndy Adamson if (unlikely(!p)) 455288034c3dSAndy Adamson goto out_overflow; 455388034c3dSAndy Adamson num = be32_to_cpup(p); 455488034c3dSAndy Adamson if (num == 0) 455588034c3dSAndy Adamson return 0; 455688034c3dSAndy Adamson if (num > 1) 455788034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 455888034c3dSAndy Adamson "drivers per filesystem not supported\n", 455988034c3dSAndy Adamson __func__); 456088034c3dSAndy Adamson 456188034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4562029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 456388034c3dSAndy Adamson } 456488034c3dSAndy Adamson return status; 456588034c3dSAndy Adamson out_overflow: 456688034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 456788034c3dSAndy Adamson return -EIO; 456888034c3dSAndy Adamson } 456988034c3dSAndy Adamson 4570ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4571ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4572aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 45736926afd1STrond Myklebust const struct nfs_server *server) 45741da177e4SLinus Torvalds { 4575bca79478STrond Myklebust int status; 4576bca79478STrond Myklebust umode_t fmode = 0; 4577ae42c70aSBryan Schumaker uint32_t type; 4578ee7b75fcSTrond Myklebust int32_t err; 45791da177e4SLinus Torvalds 4580f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4581f26c7a78STrond Myklebust if (status < 0) 45821da177e4SLinus Torvalds goto xdr_error; 4583409924e4STrond Myklebust fattr->mode = 0; 4584409924e4STrond Myklebust if (status != 0) { 4585409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4586409924e4STrond Myklebust fattr->valid |= status; 4587409924e4STrond Myklebust } 45881da177e4SLinus Torvalds 4589f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4590f26c7a78STrond Myklebust if (status < 0) 45911da177e4SLinus Torvalds goto xdr_error; 4592409924e4STrond Myklebust fattr->valid |= status; 4593f26c7a78STrond Myklebust 4594f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4595f26c7a78STrond Myklebust if (status < 0) 45961da177e4SLinus Torvalds goto xdr_error; 4597409924e4STrond Myklebust fattr->valid |= status; 4598f26c7a78STrond Myklebust 4599f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4600f26c7a78STrond Myklebust if (status < 0) 46011da177e4SLinus Torvalds goto xdr_error; 4602409924e4STrond Myklebust fattr->valid |= status; 4603f26c7a78STrond Myklebust 4604ee7b75fcSTrond Myklebust err = 0; 4605ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4606ae42c70aSBryan Schumaker if (status < 0) 4607ae42c70aSBryan Schumaker goto xdr_error; 4608ae42c70aSBryan Schumaker 4609ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4610ae42c70aSBryan Schumaker if (status < 0) 4611ae42c70aSBryan Schumaker goto xdr_error; 4612ae42c70aSBryan Schumaker 4613f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4614f26c7a78STrond Myklebust if (status < 0) 46151da177e4SLinus Torvalds goto xdr_error; 4616409924e4STrond Myklebust fattr->valid |= status; 4617f26c7a78STrond Myklebust 46188b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4619f26c7a78STrond Myklebust if (status < 0) 4620683b57b4STrond Myklebust goto xdr_error; 4621409924e4STrond Myklebust fattr->valid |= status; 4622f26c7a78STrond Myklebust 46231ca843a2SAndreas Gruenbacher status = -EIO; 46241ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 46251ca843a2SAndreas Gruenbacher goto xdr_error; 46261ca843a2SAndreas Gruenbacher 4627f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4628f26c7a78STrond Myklebust if (status < 0) 46291da177e4SLinus Torvalds goto xdr_error; 4630409924e4STrond Myklebust if (status != 0) { 46311da177e4SLinus Torvalds fattr->mode |= fmode; 4632409924e4STrond Myklebust fattr->valid |= status; 4633409924e4STrond Myklebust } 4634f26c7a78STrond Myklebust 4635f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4636f26c7a78STrond Myklebust if (status < 0) 46371da177e4SLinus Torvalds goto xdr_error; 4638409924e4STrond Myklebust fattr->valid |= status; 4639f26c7a78STrond Myklebust 46406926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4641f26c7a78STrond Myklebust if (status < 0) 46421da177e4SLinus Torvalds goto xdr_error; 4643409924e4STrond Myklebust fattr->valid |= status; 4644f26c7a78STrond Myklebust 46456926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4646f26c7a78STrond Myklebust if (status < 0) 46471da177e4SLinus Torvalds goto xdr_error; 4648409924e4STrond Myklebust fattr->valid |= status; 4649f26c7a78STrond Myklebust 4650f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4651f26c7a78STrond Myklebust if (status < 0) 46521da177e4SLinus Torvalds goto xdr_error; 4653409924e4STrond Myklebust fattr->valid |= status; 4654f26c7a78STrond Myklebust 4655f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4656f26c7a78STrond Myklebust if (status < 0) 46571da177e4SLinus Torvalds goto xdr_error; 4658409924e4STrond Myklebust fattr->valid |= status; 4659f26c7a78STrond Myklebust 4660f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4661f26c7a78STrond Myklebust if (status < 0) 46621da177e4SLinus Torvalds goto xdr_error; 4663409924e4STrond Myklebust fattr->valid |= status; 4664f26c7a78STrond Myklebust 4665f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4666f26c7a78STrond Myklebust if (status < 0) 46671da177e4SLinus Torvalds goto xdr_error; 4668409924e4STrond Myklebust fattr->valid |= status; 4669f26c7a78STrond Myklebust 4670f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4671f26c7a78STrond Myklebust if (status < 0) 46721da177e4SLinus Torvalds goto xdr_error; 4673409924e4STrond Myklebust fattr->valid |= status; 4674f26c7a78STrond Myklebust 467528331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4676f26c7a78STrond Myklebust if (status < 0) 467799baf625SManoj Naik goto xdr_error; 4678409924e4STrond Myklebust fattr->valid |= status; 4679f26c7a78STrond Myklebust 46801ca843a2SAndreas Gruenbacher status = -EIO; 46811ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 46821ca843a2SAndreas Gruenbacher goto xdr_error; 46831ca843a2SAndreas Gruenbacher 468488034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 468588034c3dSAndy Adamson if (status < 0) 468688034c3dSAndy Adamson goto xdr_error; 468788034c3dSAndy Adamson 4688aa9c2669SDavid Quigley if (label) { 4689aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4690aa9c2669SDavid Quigley if (status < 0) 4691aa9c2669SDavid Quigley goto xdr_error; 4692aa9c2669SDavid Quigley fattr->valid |= status; 4693aa9c2669SDavid Quigley } 4694aa9c2669SDavid Quigley 4695ae42c70aSBryan Schumaker xdr_error: 4696ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4697ae42c70aSBryan Schumaker return status; 4698ae42c70aSBryan Schumaker } 4699ae42c70aSBryan Schumaker 4700ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47018b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4702aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4703ae42c70aSBryan Schumaker { 4704256e48bbSTrond Myklebust unsigned int savep; 4705ae42c70aSBryan Schumaker uint32_t attrlen, 4706dae100c2SFred Isaman bitmap[3] = {0}; 4707ae42c70aSBryan Schumaker int status; 4708ae42c70aSBryan Schumaker 4709ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4710ae42c70aSBryan Schumaker if (status < 0) 4711ae42c70aSBryan Schumaker goto xdr_error; 4712ae42c70aSBryan Schumaker 4713ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4714ae42c70aSBryan Schumaker if (status < 0) 4715ae42c70aSBryan Schumaker goto xdr_error; 4716ae42c70aSBryan Schumaker 4717ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4718ae42c70aSBryan Schumaker if (status < 0) 4719ae42c70aSBryan Schumaker goto xdr_error; 4720ae42c70aSBryan Schumaker 4721aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4722aa9c2669SDavid Quigley label, server); 4723ae42c70aSBryan Schumaker if (status < 0) 4724ae42c70aSBryan Schumaker goto xdr_error; 4725ae42c70aSBryan Schumaker 4726f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 47271da177e4SLinus Torvalds xdr_error: 47283110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 47291da177e4SLinus Torvalds return status; 47301da177e4SLinus Torvalds } 47311da177e4SLinus Torvalds 4732aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4733aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4734aa9c2669SDavid Quigley { 4735aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4736aa9c2669SDavid Quigley } 4737aa9c2669SDavid Quigley 4738ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47396926afd1STrond Myklebust const struct nfs_server *server) 4740ae42c70aSBryan Schumaker { 4741aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4742ae42c70aSBryan Schumaker } 47431da177e4SLinus Torvalds 4744504913fbSAndy Adamson /* 47453132e49eSJeff Layton * Decode potentially multiple layout types. 4746504913fbSAndy Adamson */ 47473132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4748ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4749504913fbSAndy Adamson { 4750b8a8a0ddSTrond Myklebust __be32 *p; 4751ca440c38SJeff Layton uint32_t i; 4752504913fbSAndy Adamson 4753504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4754504913fbSAndy Adamson if (unlikely(!p)) 4755504913fbSAndy Adamson goto out_overflow; 4756ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4757504913fbSAndy Adamson 4758504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4759ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4760504913fbSAndy Adamson return 0; 4761504913fbSAndy Adamson 4762504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4763ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4764504913fbSAndy Adamson if (unlikely(!p)) 4765504913fbSAndy Adamson goto out_overflow; 4766ca440c38SJeff Layton 4767ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4768ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4769ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4770ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4771ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4772ca440c38SJeff Layton } 4773ca440c38SJeff Layton 4774ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4775ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4776504913fbSAndy Adamson return 0; 4777504913fbSAndy Adamson out_overflow: 4778504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4779504913fbSAndy Adamson return -EIO; 4780504913fbSAndy Adamson } 4781504913fbSAndy Adamson 4782504913fbSAndy Adamson /* 4783504913fbSAndy Adamson * The type of file system exported. 4784504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4785504913fbSAndy Adamson */ 4786504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4787ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4788504913fbSAndy Adamson { 4789504913fbSAndy Adamson int status = 0; 4790504913fbSAndy Adamson 4791504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4792504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4793504913fbSAndy Adamson return -EIO; 4794504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4795ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4796504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 47973132e49eSJeff Layton } 4798504913fbSAndy Adamson return status; 4799504913fbSAndy Adamson } 4800504913fbSAndy Adamson 4801dae100c2SFred Isaman /* 4802dae100c2SFred Isaman * The prefered block size for layout directed io 4803dae100c2SFred Isaman */ 4804dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4805dae100c2SFred Isaman uint32_t *res) 4806dae100c2SFred Isaman { 4807dae100c2SFred Isaman __be32 *p; 4808dae100c2SFred Isaman 4809dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4810dae100c2SFred Isaman *res = 0; 4811dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4812dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4813dae100c2SFred Isaman if (unlikely(!p)) { 4814dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4815dae100c2SFred Isaman return -EIO; 4816dae100c2SFred Isaman } 4817dae100c2SFred Isaman *res = be32_to_cpup(p); 4818dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4819dae100c2SFred Isaman } 4820dae100c2SFred Isaman return 0; 4821dae100c2SFred Isaman } 4822dae100c2SFred Isaman 48232a92ee92SPeng Tao /* 48242a92ee92SPeng Tao * The granularity of a CLONE operation. 48252a92ee92SPeng Tao */ 48262a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 48272a92ee92SPeng Tao uint32_t *res) 48282a92ee92SPeng Tao { 48292a92ee92SPeng Tao __be32 *p; 48302a92ee92SPeng Tao 48312a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 48322a92ee92SPeng Tao *res = 0; 48332a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 48342a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 48352a92ee92SPeng Tao if (unlikely(!p)) { 48362a92ee92SPeng Tao print_overflow_msg(__func__, xdr); 48372a92ee92SPeng Tao return -EIO; 48382a92ee92SPeng Tao } 48392a92ee92SPeng Tao *res = be32_to_cpup(p); 48402a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 48412a92ee92SPeng Tao } 48422a92ee92SPeng Tao return 0; 48432a92ee92SPeng Tao } 48442a92ee92SPeng Tao 48451da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 48461da177e4SLinus Torvalds { 4847256e48bbSTrond Myklebust unsigned int savep; 4848dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 48491da177e4SLinus Torvalds int status; 48501da177e4SLinus Torvalds 48511da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 48521da177e4SLinus Torvalds goto xdr_error; 48531da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 48541da177e4SLinus Torvalds goto xdr_error; 48551da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 48561da177e4SLinus Torvalds goto xdr_error; 48571da177e4SLinus Torvalds 48581da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 48591da177e4SLinus Torvalds 48601da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 48611da177e4SLinus Torvalds goto xdr_error; 48621da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 48631da177e4SLinus Torvalds goto xdr_error; 48641da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 48651da177e4SLinus Torvalds goto xdr_error; 48661da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 48671da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 48681da177e4SLinus Torvalds goto xdr_error; 48691da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 48701ca843a2SAndreas Gruenbacher 48711ca843a2SAndreas Gruenbacher status = -EIO; 48721ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 48731ca843a2SAndreas Gruenbacher goto xdr_error; 48741ca843a2SAndreas Gruenbacher 487555b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 487655b6e774SRicardo Labiaga if (status != 0) 487755b6e774SRicardo Labiaga goto xdr_error; 4878ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4879504913fbSAndy Adamson if (status != 0) 4880504913fbSAndy Adamson goto xdr_error; 48811ca843a2SAndreas Gruenbacher 48821ca843a2SAndreas Gruenbacher status = -EIO; 48831ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 48841ca843a2SAndreas Gruenbacher goto xdr_error; 48851ca843a2SAndreas Gruenbacher 4886dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4887dae100c2SFred Isaman if (status) 4888dae100c2SFred Isaman goto xdr_error; 48892a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 48902a92ee92SPeng Tao if (status) 48912a92ee92SPeng Tao goto xdr_error; 48921da177e4SLinus Torvalds 48931da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 48941da177e4SLinus Torvalds xdr_error: 48953110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 48961da177e4SLinus Torvalds return status; 48971da177e4SLinus Torvalds } 48981da177e4SLinus Torvalds 48991da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 49001da177e4SLinus Torvalds { 49018687b63aSAl Viro __be32 *p; 49021da177e4SLinus Torvalds uint32_t len; 49031da177e4SLinus Torvalds int status; 49041da177e4SLinus Torvalds 49059936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 49069936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 49079936781dSTrond Myklebust 49081da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 49091da177e4SLinus Torvalds if (status) 49101da177e4SLinus Torvalds return status; 49111da177e4SLinus Torvalds 4912c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4913c0eae66eSBenny Halevy if (unlikely(!p)) 4914c0eae66eSBenny Halevy goto out_overflow; 4915cccddf4fSBenny Halevy len = be32_to_cpup(p); 49161da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 49171da177e4SLinus Torvalds return -EIO; 49181da177e4SLinus Torvalds fh->size = len; 4919c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4920c0eae66eSBenny Halevy if (unlikely(!p)) 4921c0eae66eSBenny Halevy goto out_overflow; 492299398d06SBenny Halevy memcpy(fh->data, p, len); 49231da177e4SLinus Torvalds return 0; 4924c0eae66eSBenny Halevy out_overflow: 4925c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4926c0eae66eSBenny Halevy return -EIO; 49271da177e4SLinus Torvalds } 49281da177e4SLinus Torvalds 49291da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 49301da177e4SLinus Torvalds { 49311da177e4SLinus Torvalds int status; 49321da177e4SLinus Torvalds 49331da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 49341da177e4SLinus Torvalds if (status) 49351da177e4SLinus Torvalds return status; 49361da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 49371da177e4SLinus Torvalds } 49381da177e4SLinus Torvalds 49391da177e4SLinus Torvalds /* 49401da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 49411da177e4SLinus Torvalds */ 4942911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 49431da177e4SLinus Torvalds { 4944911d1aafSTrond Myklebust uint64_t offset, length, clientid; 49458687b63aSAl Viro __be32 *p; 4946911d1aafSTrond Myklebust uint32_t namelen, type; 49471da177e4SLinus Torvalds 4948babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4949c0eae66eSBenny Halevy if (unlikely(!p)) 4950c0eae66eSBenny Halevy goto out_overflow; 4951babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 49523ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4953babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4954babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4955911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4956911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4957911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4958911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4959911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4960911d1aafSTrond Myklebust if (type & 1) 4961911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4962911d1aafSTrond Myklebust fl->fl_pid = 0; 4963911d1aafSTrond Myklebust } 4964babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4965babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4966babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4967c0eae66eSBenny Halevy if (likely(p)) 49681da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4969c0eae66eSBenny Halevy out_overflow: 4970c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4971c0eae66eSBenny Halevy return -EIO; 49721da177e4SLinus Torvalds } 49731da177e4SLinus Torvalds 4974911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 49751da177e4SLinus Torvalds { 49761da177e4SLinus Torvalds int status; 49771da177e4SLinus Torvalds 49781da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4979c1d51931STrond Myklebust if (status == -EIO) 4980c1d51931STrond Myklebust goto out; 49811da177e4SLinus Torvalds if (status == 0) { 498293b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 498307d30434SBenny Halevy if (unlikely(status)) 498407d30434SBenny Halevy goto out; 49851da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4986c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4987c1d51931STrond Myklebust if (res->open_seqid != NULL) 4988c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4989c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4990c1d51931STrond Myklebust out: 49911da177e4SLinus Torvalds return status; 49921da177e4SLinus Torvalds } 49931da177e4SLinus Torvalds 4994911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 49951da177e4SLinus Torvalds { 49961da177e4SLinus Torvalds int status; 49971da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 49981da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4999911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 50001da177e4SLinus Torvalds return status; 50011da177e4SLinus Torvalds } 50021da177e4SLinus Torvalds 5003911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 50041da177e4SLinus Torvalds { 50051da177e4SLinus Torvalds int status; 50061da177e4SLinus Torvalds 50071da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 5008c1d51931STrond Myklebust if (status != -EIO) 5009c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 501007d30434SBenny Halevy if (status == 0) 501193b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 50121da177e4SLinus Torvalds return status; 50131da177e4SLinus Torvalds } 50141da177e4SLinus Torvalds 5015d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 5016d3c7b7ccSTrond Myklebust { 5017d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5018d3c7b7ccSTrond Myklebust } 5019d3c7b7ccSTrond Myklebust 50201da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 50211da177e4SLinus Torvalds { 50221da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 50231da177e4SLinus Torvalds } 50241da177e4SLinus Torvalds 50251da177e4SLinus Torvalds /* This is too sick! */ 50267d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 50277d160a6cSTrond Myklebust unsigned long *pagemod_limit) 50281da177e4SLinus Torvalds { 50298687b63aSAl Viro __be32 *p; 50301da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 50317d160a6cSTrond Myklebust u64 maxsize = 0; 50321da177e4SLinus Torvalds 5033c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5034c0eae66eSBenny Halevy if (unlikely(!p)) 5035c0eae66eSBenny Halevy goto out_overflow; 50366f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 50371da177e4SLinus Torvalds switch (limit_type) { 50387d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 50397d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 50401da177e4SLinus Torvalds break; 50417d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 50426f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5043cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 50447d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 50451da177e4SLinus Torvalds } 504609cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 50477d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 50481da177e4SLinus Torvalds return 0; 5049c0eae66eSBenny Halevy out_overflow: 5050c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5051c0eae66eSBenny Halevy return -EIO; 50521da177e4SLinus Torvalds } 50531da177e4SLinus Torvalds 50546ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 50556ae37339STrond Myklebust uint32_t delegation_type, 50566ae37339STrond Myklebust struct nfs_openres *res) 50571da177e4SLinus Torvalds { 50588687b63aSAl Viro __be32 *p; 505907d30434SBenny Halevy int status; 50601da177e4SLinus Torvalds 506193b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 506207d30434SBenny Halevy if (unlikely(status)) 506307d30434SBenny Halevy return status; 5064c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5065c0eae66eSBenny Halevy if (unlikely(!p)) 5066c0eae66eSBenny Halevy goto out_overflow; 5067cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 506805d564feSAndy Adamson 50691da177e4SLinus Torvalds switch (delegation_type) { 50701da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 50711da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 50721da177e4SLinus Torvalds break; 50731da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 50741da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 50757d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 50761da177e4SLinus Torvalds return -EIO; 50771da177e4SLinus Torvalds } 50787539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 5079c0eae66eSBenny Halevy out_overflow: 5080c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5081c0eae66eSBenny Halevy return -EIO; 50821da177e4SLinus Torvalds } 50831da177e4SLinus Torvalds 50846ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 50856ae37339STrond Myklebust { 50866ae37339STrond Myklebust __be32 *p; 50876ae37339STrond Myklebust uint32_t why_no_delegation; 50886ae37339STrond Myklebust 50896ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 50906ae37339STrond Myklebust if (unlikely(!p)) 50916ae37339STrond Myklebust goto out_overflow; 50926ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 50936ae37339STrond Myklebust switch (why_no_delegation) { 50946ae37339STrond Myklebust case WND4_CONTENTION: 50956ae37339STrond Myklebust case WND4_RESOURCE: 50966ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 50976ae37339STrond Myklebust /* Ignore for now */ 50986ae37339STrond Myklebust } 50996ae37339STrond Myklebust return 0; 51006ae37339STrond Myklebust out_overflow: 51016ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51026ae37339STrond Myklebust return -EIO; 51036ae37339STrond Myklebust } 51046ae37339STrond Myklebust 51056ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51066ae37339STrond Myklebust { 51076ae37339STrond Myklebust __be32 *p; 51086ae37339STrond Myklebust uint32_t delegation_type; 51096ae37339STrond Myklebust 51106ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51116ae37339STrond Myklebust if (unlikely(!p)) 51126ae37339STrond Myklebust goto out_overflow; 51136ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 51146ae37339STrond Myklebust res->delegation_type = 0; 51156ae37339STrond Myklebust switch (delegation_type) { 51166ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 51176ae37339STrond Myklebust return 0; 51186ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 51196ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 51206ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 51216ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 51226ae37339STrond Myklebust return decode_no_delegation(xdr, res); 51236ae37339STrond Myklebust } 51246ae37339STrond Myklebust return -EIO; 51256ae37339STrond Myklebust out_overflow: 51266ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51276ae37339STrond Myklebust return -EIO; 51286ae37339STrond Myklebust } 51296ae37339STrond Myklebust 51301da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 51311da177e4SLinus Torvalds { 51328687b63aSAl Viro __be32 *p; 5133aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 51341da177e4SLinus Torvalds int status; 51351da177e4SLinus Torvalds 5136c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5137c7848f69STrond Myklebust return status; 5138c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5139c7848f69STrond Myklebust if (status) 5140c7848f69STrond Myklebust return status; 514193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 514207d30434SBenny Halevy if (unlikely(status)) 51431da177e4SLinus Torvalds return status; 51441da177e4SLinus Torvalds 51451da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 51461da177e4SLinus Torvalds 5147c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5148c0eae66eSBenny Halevy if (unlikely(!p)) 5149c0eae66eSBenny Halevy goto out_overflow; 51506f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5151cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 51521da177e4SLinus Torvalds if (bmlen > 10) 51531da177e4SLinus Torvalds goto xdr_error; 51541da177e4SLinus Torvalds 5155c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5156c0eae66eSBenny Halevy if (unlikely(!p)) 5157c0eae66eSBenny Halevy goto out_overflow; 5158aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5159aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 51606f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5161aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5162aa53ed54SJeff Layton res->attrset[i] = 0; 5163aa53ed54SJeff Layton 51641da177e4SLinus Torvalds return decode_delegation(xdr, res); 51651da177e4SLinus Torvalds xdr_error: 51663110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 51671da177e4SLinus Torvalds return -EIO; 5168c0eae66eSBenny Halevy out_overflow: 5169c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5170c0eae66eSBenny Halevy return -EIO; 51711da177e4SLinus Torvalds } 51721da177e4SLinus Torvalds 51731da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 51741da177e4SLinus Torvalds { 51751da177e4SLinus Torvalds int status; 51761da177e4SLinus Torvalds 51771da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5178c1d51931STrond Myklebust if (status != -EIO) 5179c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 518007d30434SBenny Halevy if (!status) 518193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 51821da177e4SLinus Torvalds return status; 51831da177e4SLinus Torvalds } 51841da177e4SLinus Torvalds 51851da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 51861da177e4SLinus Torvalds { 51871da177e4SLinus Torvalds int status; 51881da177e4SLinus Torvalds 51891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5190c1d51931STrond Myklebust if (status != -EIO) 5191c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 519207d30434SBenny Halevy if (!status) 519393b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 51941da177e4SLinus Torvalds return status; 51951da177e4SLinus Torvalds } 51961da177e4SLinus Torvalds 51971da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 51981da177e4SLinus Torvalds { 51991da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 52001da177e4SLinus Torvalds } 52011da177e4SLinus Torvalds 52021da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 52031da177e4SLinus Torvalds { 52041da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 52051da177e4SLinus Torvalds } 52061da177e4SLinus Torvalds 52079137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 52089137bdf3SAnna Schumaker struct nfs_pgio_res *res) 52091da177e4SLinus Torvalds { 52108687b63aSAl Viro __be32 *p; 521164bd577eSTrond Myklebust uint32_t count, eof, recvd; 52121da177e4SLinus Torvalds int status; 52131da177e4SLinus Torvalds 52141da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 52151da177e4SLinus Torvalds if (status) 52161da177e4SLinus Torvalds return status; 5217c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5218c0eae66eSBenny Halevy if (unlikely(!p)) 5219c0eae66eSBenny Halevy goto out_overflow; 52206f723f77SBenny Halevy eof = be32_to_cpup(p++); 5221cccddf4fSBenny Halevy count = be32_to_cpup(p); 522264bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 52231da177e4SLinus Torvalds if (count > recvd) { 5224fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 52251da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 52261da177e4SLinus Torvalds count = recvd; 52271da177e4SLinus Torvalds eof = 0; 52281da177e4SLinus Torvalds } 52291da177e4SLinus Torvalds res->eof = eof; 52301da177e4SLinus Torvalds res->count = count; 52311da177e4SLinus Torvalds return 0; 5232c0eae66eSBenny Halevy out_overflow: 5233c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5234c0eae66eSBenny Halevy return -EIO; 52351da177e4SLinus Torvalds } 52361da177e4SLinus Torvalds 52371da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 52381da177e4SLinus Torvalds { 5239bcecff77SChuck Lever int status; 5240cd93710eSChuck Lever __be32 verf[2]; 52411da177e4SLinus Torvalds 52421da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5243db942bbdSBenny Halevy if (!status) 5244db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5245db942bbdSBenny Halevy if (unlikely(status)) 52461da177e4SLinus Torvalds return status; 5247cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 524844109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5249cd93710eSChuck Lever __func__, verf[0], verf[1]); 525064bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 52511da177e4SLinus Torvalds } 52521da177e4SLinus Torvalds 52531da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 52541da177e4SLinus Torvalds { 52551da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5256bcecff77SChuck Lever u32 len, recvd; 52578687b63aSAl Viro __be32 *p; 52581da177e4SLinus Torvalds int status; 52591da177e4SLinus Torvalds 52601da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 52611da177e4SLinus Torvalds if (status) 52621da177e4SLinus Torvalds return status; 52631da177e4SLinus Torvalds 52641da177e4SLinus Torvalds /* Convert length of symlink */ 5265c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5266c0eae66eSBenny Halevy if (unlikely(!p)) 5267c0eae66eSBenny Halevy goto out_overflow; 5268cccddf4fSBenny Halevy len = be32_to_cpup(p); 52691da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5270fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 52711da177e4SLinus Torvalds return -ENAMETOOLONG; 52721da177e4SLinus Torvalds } 527364bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 52741da177e4SLinus Torvalds if (recvd < len) { 5275fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 52761da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 52771da177e4SLinus Torvalds return -EIO; 52781da177e4SLinus Torvalds } 52791da177e4SLinus Torvalds /* 52801da177e4SLinus Torvalds * The XDR encode routine has set things up so that 52811da177e4SLinus Torvalds * the link text will be copied directly into the 52821da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 52831da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 52841da177e4SLinus Torvalds * null-termination). 52851da177e4SLinus Torvalds */ 5286b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 52871da177e4SLinus Torvalds return 0; 5288c0eae66eSBenny Halevy out_overflow: 5289c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5290c0eae66eSBenny Halevy return -EIO; 52911da177e4SLinus Torvalds } 52921da177e4SLinus Torvalds 52931da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 52941da177e4SLinus Torvalds { 52951da177e4SLinus Torvalds int status; 52961da177e4SLinus Torvalds 52971da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 52981da177e4SLinus Torvalds if (status) 52991da177e4SLinus Torvalds goto out; 53001da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 53011da177e4SLinus Torvalds out: 53021da177e4SLinus Torvalds return status; 53031da177e4SLinus Torvalds } 53041da177e4SLinus Torvalds 53051da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 53061da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 53071da177e4SLinus Torvalds { 53081da177e4SLinus Torvalds int status; 53091da177e4SLinus Torvalds 53101da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 53111da177e4SLinus Torvalds if (status) 53121da177e4SLinus Torvalds goto out; 53131da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 53141da177e4SLinus Torvalds goto out; 53151da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 53161da177e4SLinus Torvalds out: 53171da177e4SLinus Torvalds return status; 53181da177e4SLinus Torvalds } 53191da177e4SLinus Torvalds 53201da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 53211da177e4SLinus Torvalds { 53221da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 53231da177e4SLinus Torvalds } 53241da177e4SLinus Torvalds 532556ae19f3STrond Myklebust static int 532656ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 532756ae19f3STrond Myklebust { 532856ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 532956ae19f3STrond Myklebust } 533056ae19f3STrond Myklebust 5331029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5332bf118a34SAndy Adamson struct nfs_getaclres *res) 5333029d105eSJ. Bruce Fields { 5334256e48bbSTrond Myklebust unsigned int savep; 5335029d105eSJ. Bruce Fields uint32_t attrlen, 5336dae100c2SFred Isaman bitmap[3] = {0}; 5337029d105eSJ. Bruce Fields int status; 5338cff298c7STrond Myklebust unsigned int pg_offset; 5339029d105eSJ. Bruce Fields 5340bf118a34SAndy Adamson res->acl_len = 0; 5341029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5342029d105eSJ. Bruce Fields goto out; 53435a006899SSachin Prabhu 5344519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5345519d3959STrond Myklebust 5346cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5347cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 53485a006899SSachin Prabhu 5349029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5350029d105eSJ. Bruce Fields goto out; 5351029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5352029d105eSJ. Bruce Fields goto out; 5353029d105eSJ. Bruce Fields 5354029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5355029d105eSJ. Bruce Fields return -EIO; 5356029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5357029d105eSJ. Bruce Fields 5358bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5359bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5360bf118a34SAndy Adamson * variable length bitmaps.*/ 5361cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5362519d3959STrond Myklebust res->acl_len = attrlen; 53631f1ea6c2STrond Myklebust 53641f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 53651f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 53661f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 53671f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5368519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5369cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5370029d105eSJ. Bruce Fields } 53718c233cf9SJ. Bruce Fields } else 53728c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5373029d105eSJ. Bruce Fields 5374029d105eSJ. Bruce Fields out: 5375029d105eSJ. Bruce Fields return status; 5376029d105eSJ. Bruce Fields } 5377029d105eSJ. Bruce Fields 53781da177e4SLinus Torvalds static int 53791da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 53801da177e4SLinus Torvalds { 53811da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 53821da177e4SLinus Torvalds } 53831da177e4SLinus Torvalds 53849e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 53851da177e4SLinus Torvalds { 53868687b63aSAl Viro __be32 *p; 53871da177e4SLinus Torvalds uint32_t bmlen; 53881da177e4SLinus Torvalds int status; 53891da177e4SLinus Torvalds 53901da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 53911da177e4SLinus Torvalds if (status) 53921da177e4SLinus Torvalds return status; 5393c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5394c0eae66eSBenny Halevy if (unlikely(!p)) 5395c0eae66eSBenny Halevy goto out_overflow; 5396cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5397c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5398c0eae66eSBenny Halevy if (likely(p)) 53991da177e4SLinus Torvalds return 0; 5400c0eae66eSBenny Halevy out_overflow: 5401c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5402c0eae66eSBenny Halevy return -EIO; 54031da177e4SLinus Torvalds } 54041da177e4SLinus Torvalds 5405bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 54061da177e4SLinus Torvalds { 54078687b63aSAl Viro __be32 *p; 54081da177e4SLinus Torvalds uint32_t opnum; 54091da177e4SLinus Torvalds int32_t nfserr; 54101da177e4SLinus Torvalds 5411c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5412c0eae66eSBenny Halevy if (unlikely(!p)) 5413c0eae66eSBenny Halevy goto out_overflow; 54146f723f77SBenny Halevy opnum = be32_to_cpup(p++); 54151da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5416fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 54171da177e4SLinus Torvalds " %d\n", opnum); 54181da177e4SLinus Torvalds return -EIO; 54191da177e4SLinus Torvalds } 5420cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 54211da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5422c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5423c0eae66eSBenny Halevy if (unlikely(!p)) 5424c0eae66eSBenny Halevy goto out_overflow; 5425bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5426bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 54271da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 54281da177e4SLinus Torvalds uint32_t len; 54291da177e4SLinus Torvalds 54301da177e4SLinus Torvalds /* skip netid string */ 5431c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5432c0eae66eSBenny Halevy if (unlikely(!p)) 5433c0eae66eSBenny Halevy goto out_overflow; 5434cccddf4fSBenny Halevy len = be32_to_cpup(p); 5435c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5436c0eae66eSBenny Halevy if (unlikely(!p)) 5437c0eae66eSBenny Halevy goto out_overflow; 54381da177e4SLinus Torvalds 54391da177e4SLinus Torvalds /* skip uaddr string */ 5440c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5441c0eae66eSBenny Halevy if (unlikely(!p)) 5442c0eae66eSBenny Halevy goto out_overflow; 5443cccddf4fSBenny Halevy len = be32_to_cpup(p); 5444c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5445c0eae66eSBenny Halevy if (unlikely(!p)) 5446c0eae66eSBenny Halevy goto out_overflow; 54471da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 54481da177e4SLinus Torvalds } else 5449856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 54501da177e4SLinus Torvalds 54511da177e4SLinus Torvalds return 0; 5452c0eae66eSBenny Halevy out_overflow: 5453c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5454c0eae66eSBenny Halevy return -EIO; 54551da177e4SLinus Torvalds } 54561da177e4SLinus Torvalds 54571da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 54581da177e4SLinus Torvalds { 54591da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 54601da177e4SLinus Torvalds } 54611da177e4SLinus Torvalds 54629137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 54631da177e4SLinus Torvalds { 54648687b63aSAl Viro __be32 *p; 54651da177e4SLinus Torvalds int status; 54661da177e4SLinus Torvalds 54671da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 54681da177e4SLinus Torvalds if (status) 54691da177e4SLinus Torvalds return status; 54701da177e4SLinus Torvalds 54712f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5472c0eae66eSBenny Halevy if (unlikely(!p)) 5473c0eae66eSBenny Halevy goto out_overflow; 54746f723f77SBenny Halevy res->count = be32_to_cpup(p++); 54756f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 54762f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5477c0eae66eSBenny Halevy out_overflow: 5478c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5479c0eae66eSBenny Halevy return -EIO; 54801da177e4SLinus Torvalds } 54811da177e4SLinus Torvalds 54821da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 54831da177e4SLinus Torvalds { 54841da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 54851da177e4SLinus Torvalds } 54861da177e4SLinus Torvalds 5487fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5488fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 54895a5ea0d4SBryan Schumaker { 5490fb15b26fSChuck Lever u32 oid_len; 54915a5ea0d4SBryan Schumaker __be32 *p; 54925a5ea0d4SBryan Schumaker 54935a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 54945a5ea0d4SBryan Schumaker if (unlikely(!p)) 54955a5ea0d4SBryan Schumaker goto out_overflow; 5496fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5497fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 54985a5ea0d4SBryan Schumaker goto out_err; 54995a5ea0d4SBryan Schumaker 5500fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 55015a5ea0d4SBryan Schumaker if (unlikely(!p)) 55025a5ea0d4SBryan Schumaker goto out_overflow; 5503fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5504fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 55055a5ea0d4SBryan Schumaker 55065a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 55075a5ea0d4SBryan Schumaker if (unlikely(!p)) 55085a5ea0d4SBryan Schumaker goto out_overflow; 5509fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5510fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 55115a5ea0d4SBryan Schumaker 55125a5ea0d4SBryan Schumaker return 0; 55135a5ea0d4SBryan Schumaker 55145a5ea0d4SBryan Schumaker out_overflow: 55155a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55165a5ea0d4SBryan Schumaker return -EIO; 55175a5ea0d4SBryan Schumaker out_err: 55185a5ea0d4SBryan Schumaker return -EINVAL; 55195a5ea0d4SBryan Schumaker } 55205a5ea0d4SBryan Schumaker 552131e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 55225a5ea0d4SBryan Schumaker { 5523fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5524fb15b26fSChuck Lever unsigned int i, num_flavors; 55255a5ea0d4SBryan Schumaker int status; 55265a5ea0d4SBryan Schumaker __be32 *p; 55275a5ea0d4SBryan Schumaker 55285a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55295a5ea0d4SBryan Schumaker if (unlikely(!p)) 55305a5ea0d4SBryan Schumaker goto out_overflow; 55315a5ea0d4SBryan Schumaker 5532c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5533c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5534c3dfc280SBryan Schumaker 5535c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 55365a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5537c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 55385a5ea0d4SBryan Schumaker break; 55395a5ea0d4SBryan Schumaker 55405a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55415a5ea0d4SBryan Schumaker if (unlikely(!p)) 55425a5ea0d4SBryan Schumaker goto out_overflow; 55435a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 55445a5ea0d4SBryan Schumaker 55455a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5546613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5547613e901eSBryan Schumaker if (status) 5548613e901eSBryan Schumaker goto out; 55495a5ea0d4SBryan Schumaker } 5550c3dfc280SBryan Schumaker res->flavors->num_flavors++; 55515a5ea0d4SBryan Schumaker } 55525a5ea0d4SBryan Schumaker 555331e4dda4SBryan Schumaker status = 0; 5554613e901eSBryan Schumaker out: 5555613e901eSBryan Schumaker return status; 55565a5ea0d4SBryan Schumaker out_overflow: 55575a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55585a5ea0d4SBryan Schumaker return -EIO; 55595a5ea0d4SBryan Schumaker } 55605a5ea0d4SBryan Schumaker 556131e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 556231e4dda4SBryan Schumaker { 556331e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 556431e4dda4SBryan Schumaker if (status) 556531e4dda4SBryan Schumaker return status; 556631e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 556731e4dda4SBryan Schumaker } 556831e4dda4SBryan Schumaker 556999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 557031e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 557131e4dda4SBryan Schumaker { 557231e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 557331e4dda4SBryan Schumaker if (status) 557431e4dda4SBryan Schumaker return status; 557531e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 557631e4dda4SBryan Schumaker } 557731e4dda4SBryan Schumaker 55782031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 55792031cd1aSWeston Andros Adamson { 55802031cd1aSWeston Andros Adamson __be32 *p; 55812031cd1aSWeston Andros Adamson uint32_t bitmap_words; 55822031cd1aSWeston Andros Adamson unsigned int i; 55832031cd1aSWeston Andros Adamson 55842031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 55852031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 55862031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 55872031cd1aSWeston Andros Adamson return -EIO; 55882031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 55892031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 55902031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 55912031cd1aSWeston Andros Adamson 55922031cd1aSWeston Andros Adamson return 0; 55932031cd1aSWeston Andros Adamson } 55942031cd1aSWeston Andros Adamson 559599fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 559699fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 559799fe60d0SBenny Halevy { 559899fe60d0SBenny Halevy __be32 *p; 559999fe60d0SBenny Halevy uint32_t dummy; 56002460ba57SBenny Halevy char *dummy_str; 560199fe60d0SBenny Halevy int status; 56027d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 560399fe60d0SBenny Halevy 560499fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 560599fe60d0SBenny Halevy if (status) 560699fe60d0SBenny Halevy return status; 560799fe60d0SBenny Halevy 5608c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5609c0eae66eSBenny Halevy if (unlikely(!p)) 5610c0eae66eSBenny Halevy goto out_overflow; 561132b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5612c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5613c0eae66eSBenny Halevy if (unlikely(!p)) 5614c0eae66eSBenny Halevy goto out_overflow; 561532b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 561632b01310STrond Myklebust res->flags = be32_to_cpup(p++); 561799fe60d0SBenny Halevy 56182031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 56192031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 56202031cd1aSWeston Andros Adamson case SP4_NONE: 56212031cd1aSWeston Andros Adamson break; 56222031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 56232031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 56242031cd1aSWeston Andros Adamson if (status) 56252031cd1aSWeston Andros Adamson return status; 56262031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 56272031cd1aSWeston Andros Adamson if (status) 56282031cd1aSWeston Andros Adamson return status; 56292031cd1aSWeston Andros Adamson break; 56302031cd1aSWeston Andros Adamson default: 56312031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 563299fe60d0SBenny Halevy return -EIO; 56332031cd1aSWeston Andros Adamson } 563499fe60d0SBenny Halevy 5635acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5636c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5637c0eae66eSBenny Halevy if (unlikely(!p)) 5638c0eae66eSBenny Halevy goto out_overflow; 5639acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 564099fe60d0SBenny Halevy 5641acdeb69dSChuck Lever /* server_owner4.so_major_id */ 56422460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56432460ba57SBenny Halevy if (unlikely(status)) 56442460ba57SBenny Halevy return status; 5645acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5646acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 564778fe0f41SWeston Andros Adamson 5648acdeb69dSChuck Lever /* server_scope4 */ 5649acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5650acdeb69dSChuck Lever if (unlikely(status)) 5651acdeb69dSChuck Lever return status; 565278fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 565378fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 565478fe0f41SWeston Andros Adamson 56557d2ed9acSWeston Andros Adamson /* Implementation Id */ 56567d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56577d2ed9acSWeston Andros Adamson if (unlikely(!p)) 56587d2ed9acSWeston Andros Adamson goto out_overflow; 56597d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 56607d2ed9acSWeston Andros Adamson 56617d2ed9acSWeston Andros Adamson if (impl_id_count) { 56627d2ed9acSWeston Andros Adamson /* nii_domain */ 56632460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56642460ba57SBenny Halevy if (unlikely(status)) 56652460ba57SBenny Halevy return status; 56667d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 566799fe60d0SBenny Halevy 56687d2ed9acSWeston Andros Adamson /* nii_name */ 56697d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56707d2ed9acSWeston Andros Adamson if (unlikely(status)) 56717d2ed9acSWeston Andros Adamson return status; 56727d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 56737d2ed9acSWeston Andros Adamson 56747d2ed9acSWeston Andros Adamson /* nii_date */ 56757d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 56767d2ed9acSWeston Andros Adamson if (unlikely(!p)) 56777d2ed9acSWeston Andros Adamson goto out_overflow; 56787d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 56797d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 56807d2ed9acSWeston Andros Adamson 56817d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 56827d2ed9acSWeston Andros Adamson } 568399fe60d0SBenny Halevy return 0; 5684c0eae66eSBenny Halevy out_overflow: 5685c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5686c0eae66eSBenny Halevy return -EIO; 568799fe60d0SBenny Halevy } 5688fc931582SAndy Adamson 5689fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5690fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5691fc931582SAndy Adamson { 5692fc931582SAndy Adamson __be32 *p; 5693c9c30dd5SBenny Halevy u32 nr_attrs, val; 5694fc931582SAndy Adamson 5695c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5696c0eae66eSBenny Halevy if (unlikely(!p)) 5697c0eae66eSBenny Halevy goto out_overflow; 5698c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5699c9c30dd5SBenny Halevy if (val) 5700c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 57016f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 57026f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 57036f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 57046f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 57056f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5706cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5707fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5708a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5709a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5710fc931582SAndy Adamson return -EINVAL; 5711fc931582SAndy Adamson } 5712c0eae66eSBenny Halevy if (nr_attrs == 1) { 5713c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5714c0eae66eSBenny Halevy if (unlikely(!p)) 5715c0eae66eSBenny Halevy goto out_overflow; 5716c0eae66eSBenny Halevy } 5717fc931582SAndy Adamson return 0; 5718c0eae66eSBenny Halevy out_overflow: 5719c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5720c0eae66eSBenny Halevy return -EIO; 5721fc931582SAndy Adamson } 5722fc931582SAndy Adamson 5723e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5724e78291e4SBenny Halevy { 5725e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5726fc931582SAndy Adamson } 5727fc931582SAndy Adamson 57287c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 57297c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 57307c44f1aeSWeston Andros Adamson { 57317c44f1aeSWeston Andros Adamson __be32 *p; 57327c44f1aeSWeston Andros Adamson int status; 57337c44f1aeSWeston Andros Adamson 57347c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 57357c44f1aeSWeston Andros Adamson if (!status) 573671a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 57377c44f1aeSWeston Andros Adamson if (unlikely(status)) 57387c44f1aeSWeston Andros Adamson return status; 57397c44f1aeSWeston Andros Adamson 57407c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 57417c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 57427c44f1aeSWeston Andros Adamson if (unlikely(!p)) 57437c44f1aeSWeston Andros Adamson goto out_overflow; 57447c44f1aeSWeston Andros Adamson 57457c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 57467c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 57477c44f1aeSWeston Andros Adamson return -EIO; 57487c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 57497c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 57507c44f1aeSWeston Andros Adamson else 57517c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 57527c44f1aeSWeston Andros Adamson 57537c44f1aeSWeston Andros Adamson return 0; 57547c44f1aeSWeston Andros Adamson out_overflow: 57557c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 57567c44f1aeSWeston Andros Adamson return -EIO; 57577c44f1aeSWeston Andros Adamson } 57587c44f1aeSWeston Andros Adamson 5759fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5760fc931582SAndy Adamson struct nfs41_create_session_res *res) 5761fc931582SAndy Adamson { 5762fc931582SAndy Adamson __be32 *p; 5763fc931582SAndy Adamson int status; 5764fc931582SAndy Adamson 5765fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5766e78291e4SBenny Halevy if (!status) 576779969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5768e78291e4SBenny Halevy if (unlikely(status)) 5769fc931582SAndy Adamson return status; 5770fc931582SAndy Adamson 5771fc931582SAndy Adamson /* seqid, flags */ 5772c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5773c0eae66eSBenny Halevy if (unlikely(!p)) 5774c0eae66eSBenny Halevy goto out_overflow; 577579969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 577679969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5777fc931582SAndy Adamson 5778fc931582SAndy Adamson /* Channel attributes */ 577979969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5780fc931582SAndy Adamson if (!status) 578179969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5782fc931582SAndy Adamson return status; 5783c0eae66eSBenny Halevy out_overflow: 5784c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5785c0eae66eSBenny Halevy return -EIO; 5786fc931582SAndy Adamson } 57870f3e66c6SAndy Adamson 57880f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 57890f3e66c6SAndy Adamson { 57900f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 57910f3e66c6SAndy Adamson } 579218019753SRicardo Labiaga 579366245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 579466245539STrond Myklebust { 579566245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 579666245539STrond Myklebust } 579766245539STrond Myklebust 579818019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 579918019753SRicardo Labiaga { 580018019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 580118019753SRicardo Labiaga } 580299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 580399fe60d0SBenny Halevy 58049b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 58059b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 58069b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 58079b7b9fccSAndy Adamson { 58089b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5809e3725ec0STrond Myklebust struct nfs4_session *session; 5810fc01cea9SAndy Adamson struct nfs4_sessionid id; 5811fc01cea9SAndy Adamson u32 dummy; 5812fc01cea9SAndy Adamson int status; 5813fc01cea9SAndy Adamson __be32 *p; 5814fc01cea9SAndy Adamson 5815e3725ec0STrond Myklebust if (res->sr_slot == NULL) 58169b7b9fccSAndy Adamson return 0; 58173bd2384aSChuck Lever if (!res->sr_slot->table->session) 58183bd2384aSChuck Lever return 0; 58199b7b9fccSAndy Adamson 5820fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5821e78291e4SBenny Halevy if (!status) 5822e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5823e78291e4SBenny Halevy if (unlikely(status)) 5824fc01cea9SAndy Adamson goto out_err; 58259b7b9fccSAndy Adamson 5826fc01cea9SAndy Adamson /* 5827fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5828fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5829fc01cea9SAndy Adamson */ 5830fdcb4577STrond Myklebust status = -EREMOTEIO; 5831e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5832fc01cea9SAndy Adamson 5833e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5834fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5835fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5836fc01cea9SAndy Adamson goto out_err; 5837fc01cea9SAndy Adamson } 5838e78291e4SBenny Halevy 5839c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5840c0eae66eSBenny Halevy if (unlikely(!p)) 5841c0eae66eSBenny Halevy goto out_overflow; 5842e78291e4SBenny Halevy 5843fc01cea9SAndy Adamson /* seqid */ 58446f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5845dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5846fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5847fc01cea9SAndy Adamson goto out_err; 5848fc01cea9SAndy Adamson } 5849fc01cea9SAndy Adamson /* slot id */ 58506f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5851df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5852fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5853fc01cea9SAndy Adamson goto out_err; 5854fc01cea9SAndy Adamson } 5855da0507b7STrond Myklebust /* highest slot id */ 5856da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5857464ee9f9STrond Myklebust /* target highest slot id */ 5858464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 58590629e370SAlexandros Batsakis /* result flags */ 58600629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5861fc01cea9SAndy Adamson status = 0; 5862fc01cea9SAndy Adamson out_err: 5863fc01cea9SAndy Adamson res->sr_status = status; 5864fc01cea9SAndy Adamson return status; 5865c0eae66eSBenny Halevy out_overflow: 5866c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5867c0eae66eSBenny Halevy status = -EIO; 5868c0eae66eSBenny Halevy goto out_err; 5869fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 58709b7b9fccSAndy Adamson return 0; 5871fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 58729b7b9fccSAndy Adamson } 58739b7b9fccSAndy Adamson 5874b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 587593b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 587693b717fdSTrond Myklebust { 587793b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 587893b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 587993b717fdSTrond Myklebust } 588093b717fdSTrond Myklebust 5881b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 58824e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5883b1f69b75SAndy Adamson { 58844e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5885b1f69b75SAndy Adamson __be32 *p; 5886b1f69b75SAndy Adamson uint32_t len, type; 5887b1f69b75SAndy Adamson int status; 5888b1f69b75SAndy Adamson 5889b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5890b1f69b75SAndy Adamson if (status) { 5891b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5892b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5893b1f69b75SAndy Adamson if (unlikely(!p)) 5894b1f69b75SAndy Adamson goto out_overflow; 5895b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5896b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5897b1f69b75SAndy Adamson __func__, pdev->mincount); 5898b1f69b75SAndy Adamson } 5899b1f69b75SAndy Adamson return status; 5900b1f69b75SAndy Adamson } 5901b1f69b75SAndy Adamson 5902b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5903b1f69b75SAndy Adamson if (unlikely(!p)) 5904b1f69b75SAndy Adamson goto out_overflow; 5905b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5906b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5907b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5908b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5909b1f69b75SAndy Adamson return -EINVAL; 5910b1f69b75SAndy Adamson } 5911b1f69b75SAndy Adamson /* 5912b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5913b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5914b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5915b1f69b75SAndy Adamson */ 5916b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 591713fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 591813fe4ba1STrond Myklebust goto out_overflow; 5919b1f69b75SAndy Adamson 5920b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5921b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5922b1f69b75SAndy Adamson if (unlikely(!p)) 5923b1f69b75SAndy Adamson goto out_overflow; 5924b1f69b75SAndy Adamson len = be32_to_cpup(p); 5925b1f69b75SAndy Adamson if (len) { 5926ead00597SChuck Lever uint32_t i; 5927b1f69b75SAndy Adamson 5928b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5929b1f69b75SAndy Adamson if (unlikely(!p)) 5930b1f69b75SAndy Adamson goto out_overflow; 593184c9dee3SChristoph Hellwig 59324e590803STrond Myklebust res->notification = be32_to_cpup(p++); 593384c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 593484c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 593584c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 5936b1f69b75SAndy Adamson __func__); 5937b1f69b75SAndy Adamson return -EIO; 5938b1f69b75SAndy Adamson } 5939b1f69b75SAndy Adamson } 5940b1f69b75SAndy Adamson } 5941b1f69b75SAndy Adamson return 0; 5942b1f69b75SAndy Adamson out_overflow: 5943b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5944b1f69b75SAndy Adamson return -EIO; 5945b1f69b75SAndy Adamson } 5946b1f69b75SAndy Adamson 5947b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5948b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5949b1f69b75SAndy Adamson { 5950b1f69b75SAndy Adamson __be32 *p; 5951b1f69b75SAndy Adamson int status; 5952b1f69b75SAndy Adamson u32 layout_count; 595364bd577eSTrond Myklebust u32 recvd; 5954b1f69b75SAndy Adamson 5955b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5956b1f69b75SAndy Adamson if (status) 5957b1f69b75SAndy Adamson return status; 5958ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5959b1f69b75SAndy Adamson if (unlikely(!p)) 5960b1f69b75SAndy Adamson goto out_overflow; 5961ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 596293b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 5963ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5964ea9d23f5STrond Myklebust if (unlikely(!p)) 5965ea9d23f5STrond Myklebust goto out_overflow; 5966b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5967b1f69b75SAndy Adamson if (!layout_count) { 5968b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5969b1f69b75SAndy Adamson __func__); 5970b1f69b75SAndy Adamson return -EINVAL; 5971b1f69b75SAndy Adamson } 5972b1f69b75SAndy Adamson 597335124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5974b1f69b75SAndy Adamson if (unlikely(!p)) 5975b1f69b75SAndy Adamson goto out_overflow; 5976b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5977b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5978b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5979b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 598035124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5981b1f69b75SAndy Adamson 5982b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5983b1f69b75SAndy Adamson __func__, 5984b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5985b1f69b75SAndy Adamson (unsigned long)res->range.length, 5986b1f69b75SAndy Adamson res->range.iomode, 5987b1f69b75SAndy Adamson res->type, 598835124a09SWeston Andros Adamson res->layoutp->len); 5989b1f69b75SAndy Adamson 599064bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 599135124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 599235124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 599335124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 599435124a09SWeston Andros Adamson res->layoutp->len, recvd); 599535124a09SWeston Andros Adamson return -EINVAL; 599635124a09SWeston Andros Adamson } 599735124a09SWeston Andros Adamson 5998b1f69b75SAndy Adamson if (layout_count > 1) { 5999b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 6000b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 6001b1f69b75SAndy Adamson * the client may see a response that is less than the 6002b1f69b75SAndy Adamson * minimum it requested. 6003b1f69b75SAndy Adamson */ 6004b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 6005b1f69b75SAndy Adamson __func__, layout_count); 6006b1f69b75SAndy Adamson } 6007b1f69b75SAndy Adamson 6008b1f69b75SAndy Adamson return 0; 6009b1f69b75SAndy Adamson out_overflow: 6010b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6011b1f69b75SAndy Adamson return -EIO; 6012b1f69b75SAndy Adamson } 6013863a3c6cSAndy Adamson 6014cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 6015cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6016cbe82603SBenny Halevy { 6017cbe82603SBenny Halevy __be32 *p; 6018cbe82603SBenny Halevy int status; 6019cbe82603SBenny Halevy 6020cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 6021cbe82603SBenny Halevy if (status) 6022cbe82603SBenny Halevy return status; 6023cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 6024cbe82603SBenny Halevy if (unlikely(!p)) 6025cbe82603SBenny Halevy goto out_overflow; 6026cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 6027cbe82603SBenny Halevy if (res->lrs_present) 602893b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 6029cbe82603SBenny Halevy return status; 6030cbe82603SBenny Halevy out_overflow: 6031cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 6032cbe82603SBenny Halevy return -EIO; 6033cbe82603SBenny Halevy } 6034cbe82603SBenny Halevy 6035863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 6036863a3c6cSAndy Adamson struct rpc_rqst *req, 6037863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6038863a3c6cSAndy Adamson { 6039863a3c6cSAndy Adamson __be32 *p; 6040863a3c6cSAndy Adamson __u32 sizechanged; 6041863a3c6cSAndy Adamson int status; 6042863a3c6cSAndy Adamson 6043863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 6044db29c089SAndy Adamson res->status = status; 6045863a3c6cSAndy Adamson if (status) 6046863a3c6cSAndy Adamson return status; 6047863a3c6cSAndy Adamson 6048863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 6049863a3c6cSAndy Adamson if (unlikely(!p)) 6050863a3c6cSAndy Adamson goto out_overflow; 6051863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 6052863a3c6cSAndy Adamson 6053863a3c6cSAndy Adamson if (sizechanged) { 6054863a3c6cSAndy Adamson /* throw away new size */ 6055863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 6056863a3c6cSAndy Adamson if (unlikely(!p)) 6057863a3c6cSAndy Adamson goto out_overflow; 6058863a3c6cSAndy Adamson } 6059863a3c6cSAndy Adamson return 0; 6060863a3c6cSAndy Adamson out_overflow: 6061863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 6062863a3c6cSAndy Adamson return -EIO; 6063863a3c6cSAndy Adamson } 60647d974794SBryan Schumaker 60657d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 60667d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 60677d974794SBryan Schumaker { 60687d974794SBryan Schumaker __be32 *p; 60697d974794SBryan Schumaker int status; 60707d974794SBryan Schumaker int num_res; 60717d974794SBryan Schumaker 60727d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 60737d974794SBryan Schumaker if (status) 60747d974794SBryan Schumaker return status; 60757d974794SBryan Schumaker 60767d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 60777d974794SBryan Schumaker if (unlikely(!p)) 60787d974794SBryan Schumaker goto out_overflow; 60797d974794SBryan Schumaker num_res = be32_to_cpup(p++); 60807d974794SBryan Schumaker if (num_res != 1) 60817d974794SBryan Schumaker goto out; 60827d974794SBryan Schumaker 60837d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 60847d974794SBryan Schumaker if (unlikely(!p)) 60857d974794SBryan Schumaker goto out_overflow; 60867d974794SBryan Schumaker res->status = be32_to_cpup(p++); 60871cab0652SBryan Schumaker 60881cab0652SBryan Schumaker return status; 60897d974794SBryan Schumaker out_overflow: 60907d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 60917d974794SBryan Schumaker out: 60927d974794SBryan Schumaker return -EIO; 60937d974794SBryan Schumaker } 60949aeda35fSBryan Schumaker 60959aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 60969aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 60979aeda35fSBryan Schumaker { 60989f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 60999aeda35fSBryan Schumaker return res->status; 61009aeda35fSBryan Schumaker } 6101cf805165STrond Myklebust #else 6102cf805165STrond Myklebust static inline 6103cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6104cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6105cf805165STrond Myklebust { 6106cf805165STrond Myklebust return 0; 6107cf805165STrond Myklebust } 6108b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6109b1f69b75SAndy Adamson 61101da177e4SLinus Torvalds /* 611149c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 611249c2559eSBenny Halevy */ 611349c2559eSBenny Halevy 611449c2559eSBenny Halevy /* 61151da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 61161da177e4SLinus Torvalds */ 6117bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6118bf269551SChuck Lever struct xdr_stream *xdr, 6119bf269551SChuck Lever struct nfs_closeres *res) 61201da177e4SLinus Torvalds { 61211da177e4SLinus Torvalds struct compound_hdr hdr; 61221da177e4SLinus Torvalds int status; 61231da177e4SLinus Torvalds 6124bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61251da177e4SLinus Torvalds if (status) 61261da177e4SLinus Torvalds goto out; 6127bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61289b7b9fccSAndy Adamson if (status) 61299b7b9fccSAndy Adamson goto out; 6130bf269551SChuck Lever status = decode_putfh(xdr); 61311da177e4SLinus Torvalds if (status) 61321da177e4SLinus Torvalds goto out; 6133b6808145STrond Myklebust if (res->lr_res) { 6134b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6135b6808145STrond Myklebust res->lr_ret = status; 6136b6808145STrond Myklebust if (status) 6137b6808145STrond Myklebust goto out; 6138b6808145STrond Myklebust } 6139bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 61401da177e4SLinus Torvalds out: 61411da177e4SLinus Torvalds return status; 61421da177e4SLinus Torvalds } 61431da177e4SLinus Torvalds 61441da177e4SLinus Torvalds /* 61451da177e4SLinus Torvalds * Decode ACCESS response 61461da177e4SLinus Torvalds */ 6147bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6148bf269551SChuck Lever struct nfs4_accessres *res) 61491da177e4SLinus Torvalds { 61501da177e4SLinus Torvalds struct compound_hdr hdr; 61511da177e4SLinus Torvalds int status; 61521da177e4SLinus Torvalds 6153bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61549b7b9fccSAndy Adamson if (status) 61559b7b9fccSAndy Adamson goto out; 6156bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61579b7b9fccSAndy Adamson if (status) 61581da177e4SLinus Torvalds goto out; 6159bf269551SChuck Lever status = decode_putfh(xdr); 616076b32999STrond Myklebust if (status != 0) 616176b32999STrond Myklebust goto out; 61626168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 616376b32999STrond Myklebust if (status != 0) 616476b32999STrond Myklebust goto out; 61656926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 61661da177e4SLinus Torvalds out: 61671da177e4SLinus Torvalds return status; 61681da177e4SLinus Torvalds } 61691da177e4SLinus Torvalds 61701da177e4SLinus Torvalds /* 61711da177e4SLinus Torvalds * Decode LOOKUP response 61721da177e4SLinus Torvalds */ 6173bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6174bf269551SChuck Lever struct nfs4_lookup_res *res) 61751da177e4SLinus Torvalds { 61761da177e4SLinus Torvalds struct compound_hdr hdr; 61771da177e4SLinus Torvalds int status; 61781da177e4SLinus Torvalds 6179bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61809b7b9fccSAndy Adamson if (status) 61819b7b9fccSAndy Adamson goto out; 6182bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61839b7b9fccSAndy Adamson if (status) 61841da177e4SLinus Torvalds goto out; 6185bf269551SChuck Lever status = decode_putfh(xdr); 6186bf269551SChuck Lever if (status) 61871da177e4SLinus Torvalds goto out; 6188bf269551SChuck Lever status = decode_lookup(xdr); 6189bf269551SChuck Lever if (status) 61901da177e4SLinus Torvalds goto out; 6191bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6192bf269551SChuck Lever if (status) 61931da177e4SLinus Torvalds goto out; 6194aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 61951da177e4SLinus Torvalds out: 61961da177e4SLinus Torvalds return status; 61971da177e4SLinus Torvalds } 61981da177e4SLinus Torvalds 61991da177e4SLinus Torvalds /* 62001da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 62011da177e4SLinus Torvalds */ 6202bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6203bf269551SChuck Lever struct xdr_stream *xdr, 6204bf269551SChuck Lever struct nfs4_lookup_res *res) 62051da177e4SLinus Torvalds { 62061da177e4SLinus Torvalds struct compound_hdr hdr; 62071da177e4SLinus Torvalds int status; 62081da177e4SLinus Torvalds 6209bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62109b7b9fccSAndy Adamson if (status) 62119b7b9fccSAndy Adamson goto out; 6212bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62139b7b9fccSAndy Adamson if (status) 62141da177e4SLinus Torvalds goto out; 6215bf269551SChuck Lever status = decode_putrootfh(xdr); 6216bf269551SChuck Lever if (status) 62171da177e4SLinus Torvalds goto out; 6218bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6219bf269551SChuck Lever if (status == 0) 6220aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6221aa9c2669SDavid Quigley res->label, res->server); 62221da177e4SLinus Torvalds out: 62231da177e4SLinus Torvalds return status; 62241da177e4SLinus Torvalds } 62251da177e4SLinus Torvalds 62261da177e4SLinus Torvalds /* 62271da177e4SLinus Torvalds * Decode REMOVE response 62281da177e4SLinus Torvalds */ 6229bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6230bf269551SChuck Lever struct nfs_removeres *res) 62311da177e4SLinus Torvalds { 62321da177e4SLinus Torvalds struct compound_hdr hdr; 62331da177e4SLinus Torvalds int status; 62341da177e4SLinus Torvalds 6235bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62369b7b9fccSAndy Adamson if (status) 62379b7b9fccSAndy Adamson goto out; 6238bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62399b7b9fccSAndy Adamson if (status) 62401da177e4SLinus Torvalds goto out; 6241bf269551SChuck Lever status = decode_putfh(xdr); 6242bf269551SChuck Lever if (status) 624316e42959STrond Myklebust goto out; 6244bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 62451da177e4SLinus Torvalds out: 62461da177e4SLinus Torvalds return status; 62471da177e4SLinus Torvalds } 62481da177e4SLinus Torvalds 62491da177e4SLinus Torvalds /* 62501da177e4SLinus Torvalds * Decode RENAME response 62511da177e4SLinus Torvalds */ 6252bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6253bf269551SChuck Lever struct nfs_renameres *res) 62541da177e4SLinus Torvalds { 62551da177e4SLinus Torvalds struct compound_hdr hdr; 62561da177e4SLinus Torvalds int status; 62571da177e4SLinus Torvalds 6258bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62599b7b9fccSAndy Adamson if (status) 62609b7b9fccSAndy Adamson goto out; 6261bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62629b7b9fccSAndy Adamson if (status) 62631da177e4SLinus Torvalds goto out; 6264bf269551SChuck Lever status = decode_putfh(xdr); 6265bf269551SChuck Lever if (status) 62661da177e4SLinus Torvalds goto out; 6267bf269551SChuck Lever status = decode_savefh(xdr); 6268bf269551SChuck Lever if (status) 62691da177e4SLinus Torvalds goto out; 6270bf269551SChuck Lever status = decode_putfh(xdr); 6271bf269551SChuck Lever if (status) 62721da177e4SLinus Torvalds goto out; 6273bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 62741da177e4SLinus Torvalds out: 62751da177e4SLinus Torvalds return status; 62761da177e4SLinus Torvalds } 62771da177e4SLinus Torvalds 62781da177e4SLinus Torvalds /* 62791da177e4SLinus Torvalds * Decode LINK response 62801da177e4SLinus Torvalds */ 6281bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6282bf269551SChuck Lever struct nfs4_link_res *res) 62831da177e4SLinus Torvalds { 62841da177e4SLinus Torvalds struct compound_hdr hdr; 62851da177e4SLinus Torvalds int status; 62861da177e4SLinus Torvalds 6287bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62889b7b9fccSAndy Adamson if (status) 62899b7b9fccSAndy Adamson goto out; 6290bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62919b7b9fccSAndy Adamson if (status) 62921da177e4SLinus Torvalds goto out; 6293bf269551SChuck Lever status = decode_putfh(xdr); 6294bf269551SChuck Lever if (status) 62951da177e4SLinus Torvalds goto out; 6296bf269551SChuck Lever status = decode_savefh(xdr); 6297bf269551SChuck Lever if (status) 62981da177e4SLinus Torvalds goto out; 6299bf269551SChuck Lever status = decode_putfh(xdr); 6300bf269551SChuck Lever if (status) 63011da177e4SLinus Torvalds goto out; 6302bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6303bf269551SChuck Lever if (status) 630491ba2eeeSTrond Myklebust goto out; 630591ba2eeeSTrond Myklebust /* 630691ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 630791ba2eeeSTrond Myklebust * filehandle. 630891ba2eeeSTrond Myklebust */ 6309bf269551SChuck Lever status = decode_restorefh(xdr); 6310bf269551SChuck Lever if (status) 631191ba2eeeSTrond Myklebust goto out; 6312aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63131da177e4SLinus Torvalds out: 63141da177e4SLinus Torvalds return status; 63151da177e4SLinus Torvalds } 63161da177e4SLinus Torvalds 63171da177e4SLinus Torvalds /* 63181da177e4SLinus Torvalds * Decode CREATE response 63191da177e4SLinus Torvalds */ 6320bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6321bf269551SChuck Lever struct nfs4_create_res *res) 63221da177e4SLinus Torvalds { 63231da177e4SLinus Torvalds struct compound_hdr hdr; 63241da177e4SLinus Torvalds int status; 63251da177e4SLinus Torvalds 6326bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63279b7b9fccSAndy Adamson if (status) 63289b7b9fccSAndy Adamson goto out; 6329bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63309b7b9fccSAndy Adamson if (status) 63311da177e4SLinus Torvalds goto out; 6332bf269551SChuck Lever status = decode_putfh(xdr); 6333bf269551SChuck Lever if (status) 63341da177e4SLinus Torvalds goto out; 6335bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6336bf269551SChuck Lever if (status) 63371da177e4SLinus Torvalds goto out; 6338bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6339bf269551SChuck Lever if (status) 63401da177e4SLinus Torvalds goto out; 6341aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63421da177e4SLinus Torvalds out: 63431da177e4SLinus Torvalds return status; 63441da177e4SLinus Torvalds } 63451da177e4SLinus Torvalds 63461da177e4SLinus Torvalds /* 63471da177e4SLinus Torvalds * Decode SYMLINK response 63481da177e4SLinus Torvalds */ 6349bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6350bf269551SChuck Lever struct nfs4_create_res *res) 63511da177e4SLinus Torvalds { 6352bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 63531da177e4SLinus Torvalds } 63541da177e4SLinus Torvalds 63551da177e4SLinus Torvalds /* 63561da177e4SLinus Torvalds * Decode GETATTR response 63571da177e4SLinus Torvalds */ 6358bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6359bf269551SChuck Lever struct nfs4_getattr_res *res) 63601da177e4SLinus Torvalds { 63611da177e4SLinus Torvalds struct compound_hdr hdr; 63621da177e4SLinus Torvalds int status; 63631da177e4SLinus Torvalds 6364bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63651da177e4SLinus Torvalds if (status) 63661da177e4SLinus Torvalds goto out; 6367bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63689b7b9fccSAndy Adamson if (status) 63699b7b9fccSAndy Adamson goto out; 6370bf269551SChuck Lever status = decode_putfh(xdr); 63711da177e4SLinus Torvalds if (status) 63721da177e4SLinus Torvalds goto out; 6373aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63741da177e4SLinus Torvalds out: 63751da177e4SLinus Torvalds return status; 63761da177e4SLinus Torvalds } 63771da177e4SLinus Torvalds 637823ec6965SJ. Bruce Fields /* 637923ec6965SJ. Bruce Fields * Encode an SETACL request 638023ec6965SJ. Bruce Fields */ 63819f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 63829f06c719SChuck Lever struct nfs_setaclargs *args) 638323ec6965SJ. Bruce Fields { 638423ec6965SJ. Bruce Fields struct compound_hdr hdr = { 638566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 638623ec6965SJ. Bruce Fields }; 638723ec6965SJ. Bruce Fields 63889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 63899f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 63909f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 63919f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6392d017931cSAndy Adamson encode_nops(&hdr); 639323ec6965SJ. Bruce Fields } 639405d564feSAndy Adamson 639523ec6965SJ. Bruce Fields /* 639623ec6965SJ. Bruce Fields * Decode SETACL response 639723ec6965SJ. Bruce Fields */ 639823ec6965SJ. Bruce Fields static int 6399bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 640073c403a9SBenny Halevy struct nfs_setaclres *res) 640123ec6965SJ. Bruce Fields { 640223ec6965SJ. Bruce Fields struct compound_hdr hdr; 640323ec6965SJ. Bruce Fields int status; 640423ec6965SJ. Bruce Fields 6405bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 640623ec6965SJ. Bruce Fields if (status) 640723ec6965SJ. Bruce Fields goto out; 6408bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64099b7b9fccSAndy Adamson if (status) 64109b7b9fccSAndy Adamson goto out; 6411bf269551SChuck Lever status = decode_putfh(xdr); 641223ec6965SJ. Bruce Fields if (status) 641323ec6965SJ. Bruce Fields goto out; 6414bf269551SChuck Lever status = decode_setattr(xdr); 641523ec6965SJ. Bruce Fields out: 641623ec6965SJ. Bruce Fields return status; 641723ec6965SJ. Bruce Fields } 64181da177e4SLinus Torvalds 64191da177e4SLinus Torvalds /* 6420029d105eSJ. Bruce Fields * Decode GETACL response 6421029d105eSJ. Bruce Fields */ 6422029d105eSJ. Bruce Fields static int 6423bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6424663c79b3SBenny Halevy struct nfs_getaclres *res) 6425029d105eSJ. Bruce Fields { 6426029d105eSJ. Bruce Fields struct compound_hdr hdr; 6427029d105eSJ. Bruce Fields int status; 6428029d105eSJ. Bruce Fields 6429331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6430331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6431331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6432331818f1STrond Myklebust } 6433bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6434029d105eSJ. Bruce Fields if (status) 6435029d105eSJ. Bruce Fields goto out; 6436bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64379b7b9fccSAndy Adamson if (status) 64389b7b9fccSAndy Adamson goto out; 6439bf269551SChuck Lever status = decode_putfh(xdr); 6440029d105eSJ. Bruce Fields if (status) 6441029d105eSJ. Bruce Fields goto out; 6442bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6443029d105eSJ. Bruce Fields 6444029d105eSJ. Bruce Fields out: 6445029d105eSJ. Bruce Fields return status; 6446029d105eSJ. Bruce Fields } 6447029d105eSJ. Bruce Fields 6448029d105eSJ. Bruce Fields /* 64491da177e4SLinus Torvalds * Decode CLOSE response 64501da177e4SLinus Torvalds */ 6451bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6452bf269551SChuck Lever struct nfs_closeres *res) 64531da177e4SLinus Torvalds { 64541da177e4SLinus Torvalds struct compound_hdr hdr; 64551da177e4SLinus Torvalds int status; 64561da177e4SLinus Torvalds 6457bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64581da177e4SLinus Torvalds if (status) 64591da177e4SLinus Torvalds goto out; 6460bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64619b7b9fccSAndy Adamson if (status) 64629b7b9fccSAndy Adamson goto out; 6463bf269551SChuck Lever status = decode_putfh(xdr); 64641da177e4SLinus Torvalds if (status) 64651da177e4SLinus Torvalds goto out; 6466cf805165STrond Myklebust if (res->lr_res) { 6467cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6468cf805165STrond Myklebust res->lr_ret = status; 6469cf805165STrond Myklebust if (status) 6470cf805165STrond Myklebust goto out; 6471cf805165STrond Myklebust } 6472d8d84983STrond Myklebust if (res->fattr != NULL) { 6473d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6474516a6af6STrond Myklebust if (status != 0) 6475516a6af6STrond Myklebust goto out; 6476d8d84983STrond Myklebust } 6477d8d84983STrond Myklebust status = decode_close(xdr, res); 64781da177e4SLinus Torvalds out: 64791da177e4SLinus Torvalds return status; 64801da177e4SLinus Torvalds } 64811da177e4SLinus Torvalds 64821da177e4SLinus Torvalds /* 64831da177e4SLinus Torvalds * Decode OPEN response 64841da177e4SLinus Torvalds */ 6485bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6486bf269551SChuck Lever struct nfs_openres *res) 64871da177e4SLinus Torvalds { 64881da177e4SLinus Torvalds struct compound_hdr hdr; 64891da177e4SLinus Torvalds int status; 64901da177e4SLinus Torvalds 6491bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64921da177e4SLinus Torvalds if (status) 64931da177e4SLinus Torvalds goto out; 6494bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64959b7b9fccSAndy Adamson if (status) 64969b7b9fccSAndy Adamson goto out; 6497bf269551SChuck Lever status = decode_putfh(xdr); 64981da177e4SLinus Torvalds if (status) 64991da177e4SLinus Torvalds goto out; 6500bf269551SChuck Lever status = decode_open(xdr, res); 65011da177e4SLinus Torvalds if (status) 65021da177e4SLinus Torvalds goto out; 650301913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 650401913b49SWeston Andros Adamson if (status) 65051da177e4SLinus Torvalds goto out; 6506ae2bb032SWeston Andros Adamson if (res->access_request) 65076168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6508aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 65091da177e4SLinus Torvalds out: 65101da177e4SLinus Torvalds return status; 65111da177e4SLinus Torvalds } 65121da177e4SLinus Torvalds 65131da177e4SLinus Torvalds /* 65141da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 65151da177e4SLinus Torvalds */ 6516bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6517bf269551SChuck Lever struct xdr_stream *xdr, 6518bf269551SChuck Lever struct nfs_open_confirmres *res) 65191da177e4SLinus Torvalds { 65201da177e4SLinus Torvalds struct compound_hdr hdr; 65211da177e4SLinus Torvalds int status; 65221da177e4SLinus Torvalds 6523bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65241da177e4SLinus Torvalds if (status) 65251da177e4SLinus Torvalds goto out; 6526bf269551SChuck Lever status = decode_putfh(xdr); 65271da177e4SLinus Torvalds if (status) 65281da177e4SLinus Torvalds goto out; 6529bf269551SChuck Lever status = decode_open_confirm(xdr, res); 65301da177e4SLinus Torvalds out: 65311da177e4SLinus Torvalds return status; 65321da177e4SLinus Torvalds } 65331da177e4SLinus Torvalds 65341da177e4SLinus Torvalds /* 65351da177e4SLinus Torvalds * Decode OPEN response 65361da177e4SLinus Torvalds */ 6537bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6538bf269551SChuck Lever struct xdr_stream *xdr, 6539bf269551SChuck Lever struct nfs_openres *res) 65401da177e4SLinus Torvalds { 65411da177e4SLinus Torvalds struct compound_hdr hdr; 65421da177e4SLinus Torvalds int status; 65431da177e4SLinus Torvalds 6544bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65451da177e4SLinus Torvalds if (status) 65461da177e4SLinus Torvalds goto out; 6547bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65489b7b9fccSAndy Adamson if (status) 65499b7b9fccSAndy Adamson goto out; 6550bf269551SChuck Lever status = decode_putfh(xdr); 65511da177e4SLinus Torvalds if (status) 65521da177e4SLinus Torvalds goto out; 6553bf269551SChuck Lever status = decode_open(xdr, res); 6554864472e9STrond Myklebust if (status) 6555864472e9STrond Myklebust goto out; 6556ae2bb032SWeston Andros Adamson if (res->access_request) 65576168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 65586926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 65591da177e4SLinus Torvalds out: 65601da177e4SLinus Torvalds return status; 65611da177e4SLinus Torvalds } 65621da177e4SLinus Torvalds 65631da177e4SLinus Torvalds /* 65641da177e4SLinus Torvalds * Decode SETATTR response 65651da177e4SLinus Torvalds */ 6566bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6567bf269551SChuck Lever struct xdr_stream *xdr, 6568bf269551SChuck Lever struct nfs_setattrres *res) 65691da177e4SLinus Torvalds { 65701da177e4SLinus Torvalds struct compound_hdr hdr; 65711da177e4SLinus Torvalds int status; 65721da177e4SLinus Torvalds 6573bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65741da177e4SLinus Torvalds if (status) 65751da177e4SLinus Torvalds goto out; 6576bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65779b7b9fccSAndy Adamson if (status) 65789b7b9fccSAndy Adamson goto out; 6579bf269551SChuck Lever status = decode_putfh(xdr); 65801da177e4SLinus Torvalds if (status) 65811da177e4SLinus Torvalds goto out; 6582bf269551SChuck Lever status = decode_setattr(xdr); 65831da177e4SLinus Torvalds if (status) 65841da177e4SLinus Torvalds goto out; 6585aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 65861da177e4SLinus Torvalds out: 65871da177e4SLinus Torvalds return status; 65881da177e4SLinus Torvalds } 65891da177e4SLinus Torvalds 65901da177e4SLinus Torvalds /* 65911da177e4SLinus Torvalds * Decode LOCK response 65921da177e4SLinus Torvalds */ 6593bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6594bf269551SChuck Lever struct nfs_lock_res *res) 65951da177e4SLinus Torvalds { 65961da177e4SLinus Torvalds struct compound_hdr hdr; 65971da177e4SLinus Torvalds int status; 65981da177e4SLinus Torvalds 6599bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66001da177e4SLinus Torvalds if (status) 66011da177e4SLinus Torvalds goto out; 6602bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66039b7b9fccSAndy Adamson if (status) 66049b7b9fccSAndy Adamson goto out; 6605bf269551SChuck Lever status = decode_putfh(xdr); 66061da177e4SLinus Torvalds if (status) 66071da177e4SLinus Torvalds goto out; 6608bf269551SChuck Lever status = decode_lock(xdr, res); 66091da177e4SLinus Torvalds out: 66101da177e4SLinus Torvalds return status; 66111da177e4SLinus Torvalds } 66121da177e4SLinus Torvalds 66131da177e4SLinus Torvalds /* 66141da177e4SLinus Torvalds * Decode LOCKT response 66151da177e4SLinus Torvalds */ 6616bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6617bf269551SChuck Lever struct nfs_lockt_res *res) 66181da177e4SLinus Torvalds { 66191da177e4SLinus Torvalds struct compound_hdr hdr; 66201da177e4SLinus Torvalds int status; 66211da177e4SLinus Torvalds 6622bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66231da177e4SLinus Torvalds if (status) 66241da177e4SLinus Torvalds goto out; 6625bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66269b7b9fccSAndy Adamson if (status) 66279b7b9fccSAndy Adamson goto out; 6628bf269551SChuck Lever status = decode_putfh(xdr); 66291da177e4SLinus Torvalds if (status) 66301da177e4SLinus Torvalds goto out; 6631bf269551SChuck Lever status = decode_lockt(xdr, res); 66321da177e4SLinus Torvalds out: 66331da177e4SLinus Torvalds return status; 66341da177e4SLinus Torvalds } 66351da177e4SLinus Torvalds 66361da177e4SLinus Torvalds /* 66371da177e4SLinus Torvalds * Decode LOCKU response 66381da177e4SLinus Torvalds */ 6639bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6640bf269551SChuck Lever struct nfs_locku_res *res) 66411da177e4SLinus Torvalds { 66421da177e4SLinus Torvalds struct compound_hdr hdr; 66431da177e4SLinus Torvalds int status; 66441da177e4SLinus Torvalds 6645bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66461da177e4SLinus Torvalds if (status) 66471da177e4SLinus Torvalds goto out; 6648bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66499b7b9fccSAndy Adamson if (status) 66509b7b9fccSAndy Adamson goto out; 6651bf269551SChuck Lever status = decode_putfh(xdr); 66521da177e4SLinus Torvalds if (status) 66531da177e4SLinus Torvalds goto out; 6654bf269551SChuck Lever status = decode_locku(xdr, res); 66551da177e4SLinus Torvalds out: 66561da177e4SLinus Torvalds return status; 66571da177e4SLinus Torvalds } 66581da177e4SLinus Torvalds 6659bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6660bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6661d3c7b7ccSTrond Myklebust { 6662d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6663d3c7b7ccSTrond Myklebust int status; 6664d3c7b7ccSTrond Myklebust 6665bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6666d3c7b7ccSTrond Myklebust if (!status) 6667bf269551SChuck Lever status = decode_release_lockowner(xdr); 6668d3c7b7ccSTrond Myklebust return status; 6669d3c7b7ccSTrond Myklebust } 6670d3c7b7ccSTrond Myklebust 66711da177e4SLinus Torvalds /* 66721da177e4SLinus Torvalds * Decode READLINK response 66731da177e4SLinus Torvalds */ 6674bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6675bf269551SChuck Lever struct xdr_stream *xdr, 6676f50c7000SBenny Halevy struct nfs4_readlink_res *res) 66771da177e4SLinus Torvalds { 66781da177e4SLinus Torvalds struct compound_hdr hdr; 66791da177e4SLinus Torvalds int status; 66801da177e4SLinus Torvalds 6681bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66821da177e4SLinus Torvalds if (status) 66831da177e4SLinus Torvalds goto out; 6684bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66859b7b9fccSAndy Adamson if (status) 66869b7b9fccSAndy Adamson goto out; 6687bf269551SChuck Lever status = decode_putfh(xdr); 66881da177e4SLinus Torvalds if (status) 66891da177e4SLinus Torvalds goto out; 6690bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 66911da177e4SLinus Torvalds out: 66921da177e4SLinus Torvalds return status; 66931da177e4SLinus Torvalds } 66941da177e4SLinus Torvalds 66951da177e4SLinus Torvalds /* 66961da177e4SLinus Torvalds * Decode READDIR response 66971da177e4SLinus Torvalds */ 6698bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6699bf269551SChuck Lever struct nfs4_readdir_res *res) 67001da177e4SLinus Torvalds { 67011da177e4SLinus Torvalds struct compound_hdr hdr; 67021da177e4SLinus Torvalds int status; 67031da177e4SLinus Torvalds 6704bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67051da177e4SLinus Torvalds if (status) 67061da177e4SLinus Torvalds goto out; 6707bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67089b7b9fccSAndy Adamson if (status) 67099b7b9fccSAndy Adamson goto out; 6710bf269551SChuck Lever status = decode_putfh(xdr); 67111da177e4SLinus Torvalds if (status) 67121da177e4SLinus Torvalds goto out; 6713bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 67141da177e4SLinus Torvalds out: 67151da177e4SLinus Torvalds return status; 67161da177e4SLinus Torvalds } 67171da177e4SLinus Torvalds 67181da177e4SLinus Torvalds /* 67191da177e4SLinus Torvalds * Decode Read response 67201da177e4SLinus Torvalds */ 6721bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 67229137bdf3SAnna Schumaker struct nfs_pgio_res *res) 67231da177e4SLinus Torvalds { 67241da177e4SLinus Torvalds struct compound_hdr hdr; 67251da177e4SLinus Torvalds int status; 67261da177e4SLinus Torvalds 6727bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6728aabff4ddSPeng Tao res->op_status = hdr.status; 67291da177e4SLinus Torvalds if (status) 67301da177e4SLinus Torvalds goto out; 6731bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67329b7b9fccSAndy Adamson if (status) 67339b7b9fccSAndy Adamson goto out; 6734bf269551SChuck Lever status = decode_putfh(xdr); 67351da177e4SLinus Torvalds if (status) 67361da177e4SLinus Torvalds goto out; 6737bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 67381da177e4SLinus Torvalds if (!status) 67391da177e4SLinus Torvalds status = res->count; 67401da177e4SLinus Torvalds out: 67411da177e4SLinus Torvalds return status; 67421da177e4SLinus Torvalds } 67431da177e4SLinus Torvalds 67441da177e4SLinus Torvalds /* 67451da177e4SLinus Torvalds * Decode WRITE response 67461da177e4SLinus Torvalds */ 6747bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 67489137bdf3SAnna Schumaker struct nfs_pgio_res *res) 67491da177e4SLinus Torvalds { 67501da177e4SLinus Torvalds struct compound_hdr hdr; 67511da177e4SLinus Torvalds int status; 67521da177e4SLinus Torvalds 6753bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6754aabff4ddSPeng Tao res->op_status = hdr.status; 67551da177e4SLinus Torvalds if (status) 67561da177e4SLinus Torvalds goto out; 6757bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67589b7b9fccSAndy Adamson if (status) 67599b7b9fccSAndy Adamson goto out; 6760bf269551SChuck Lever status = decode_putfh(xdr); 67611da177e4SLinus Torvalds if (status) 67621da177e4SLinus Torvalds goto out; 6763bf269551SChuck Lever status = decode_write(xdr, res); 67644f9838c7STrond Myklebust if (status) 67654f9838c7STrond Myklebust goto out; 67667ffd1064SFred Isaman if (res->fattr) 67676926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 67681da177e4SLinus Torvalds if (!status) 67691da177e4SLinus Torvalds status = res->count; 67701da177e4SLinus Torvalds out: 67711da177e4SLinus Torvalds return status; 67721da177e4SLinus Torvalds } 67731da177e4SLinus Torvalds 67741da177e4SLinus Torvalds /* 67751da177e4SLinus Torvalds * Decode COMMIT response 67761da177e4SLinus Torvalds */ 6777bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 67780b7c0153SFred Isaman struct nfs_commitres *res) 67791da177e4SLinus Torvalds { 67801da177e4SLinus Torvalds struct compound_hdr hdr; 67811da177e4SLinus Torvalds int status; 67821da177e4SLinus Torvalds 6783bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6784aabff4ddSPeng Tao res->op_status = hdr.status; 67851da177e4SLinus Torvalds if (status) 67861da177e4SLinus Torvalds goto out; 6787bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67889b7b9fccSAndy Adamson if (status) 67899b7b9fccSAndy Adamson goto out; 6790bf269551SChuck Lever status = decode_putfh(xdr); 67911da177e4SLinus Torvalds if (status) 67921da177e4SLinus Torvalds goto out; 6793bf269551SChuck Lever status = decode_commit(xdr, res); 67941da177e4SLinus Torvalds out: 67951da177e4SLinus Torvalds return status; 67961da177e4SLinus Torvalds } 67971da177e4SLinus Torvalds 67981da177e4SLinus Torvalds /* 67998b173218SRicardo Labiaga * Decode FSINFO response 68001da177e4SLinus Torvalds */ 6801bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 68023dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 68031da177e4SLinus Torvalds { 68041da177e4SLinus Torvalds struct compound_hdr hdr; 68051da177e4SLinus Torvalds int status; 68061da177e4SLinus Torvalds 6807bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68081da177e4SLinus Torvalds if (!status) 6809bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68109b7b9fccSAndy Adamson if (!status) 6811bf269551SChuck Lever status = decode_putfh(xdr); 68121da177e4SLinus Torvalds if (!status) 6813bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 68141da177e4SLinus Torvalds return status; 68151da177e4SLinus Torvalds } 68161da177e4SLinus Torvalds 68171da177e4SLinus Torvalds /* 68188b173218SRicardo Labiaga * Decode PATHCONF response 68191da177e4SLinus Torvalds */ 6820bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6821d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 68221da177e4SLinus Torvalds { 68231da177e4SLinus Torvalds struct compound_hdr hdr; 68241da177e4SLinus Torvalds int status; 68251da177e4SLinus Torvalds 6826bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68271da177e4SLinus Torvalds if (!status) 6828bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68299b7b9fccSAndy Adamson if (!status) 6830bf269551SChuck Lever status = decode_putfh(xdr); 68311da177e4SLinus Torvalds if (!status) 6832bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 68331da177e4SLinus Torvalds return status; 68341da177e4SLinus Torvalds } 68351da177e4SLinus Torvalds 68361da177e4SLinus Torvalds /* 68378b173218SRicardo Labiaga * Decode STATFS response 68381da177e4SLinus Torvalds */ 6839bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 684024ad148aSBenny Halevy struct nfs4_statfs_res *res) 68411da177e4SLinus Torvalds { 68421da177e4SLinus Torvalds struct compound_hdr hdr; 68431da177e4SLinus Torvalds int status; 68441da177e4SLinus Torvalds 6845bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68461da177e4SLinus Torvalds if (!status) 6847bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68489b7b9fccSAndy Adamson if (!status) 6849bf269551SChuck Lever status = decode_putfh(xdr); 68501da177e4SLinus Torvalds if (!status) 6851bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 68521da177e4SLinus Torvalds return status; 68531da177e4SLinus Torvalds } 68541da177e4SLinus Torvalds 68551da177e4SLinus Torvalds /* 68568b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 68571da177e4SLinus Torvalds */ 6858bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6859bf269551SChuck Lever struct xdr_stream *xdr, 6860bf269551SChuck Lever struct nfs4_server_caps_res *res) 68611da177e4SLinus Torvalds { 68621da177e4SLinus Torvalds struct compound_hdr hdr; 68631da177e4SLinus Torvalds int status; 68641da177e4SLinus Torvalds 6865bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68669b7b9fccSAndy Adamson if (status) 68679b7b9fccSAndy Adamson goto out; 6868bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68699b7b9fccSAndy Adamson if (status) 68701da177e4SLinus Torvalds goto out; 6871bf269551SChuck Lever status = decode_putfh(xdr); 6872bf269551SChuck Lever if (status) 68731da177e4SLinus Torvalds goto out; 6874bf269551SChuck Lever status = decode_server_caps(xdr, res); 68751da177e4SLinus Torvalds out: 68761da177e4SLinus Torvalds return status; 68771da177e4SLinus Torvalds } 68781da177e4SLinus Torvalds 68791da177e4SLinus Torvalds /* 68801da177e4SLinus Torvalds * Decode RENEW response 68811da177e4SLinus Torvalds */ 6882bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6883bf269551SChuck Lever void *__unused) 68841da177e4SLinus Torvalds { 68851da177e4SLinus Torvalds struct compound_hdr hdr; 68861da177e4SLinus Torvalds int status; 68871da177e4SLinus Torvalds 6888bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68891da177e4SLinus Torvalds if (!status) 6890bf269551SChuck Lever status = decode_renew(xdr); 68911da177e4SLinus Torvalds return status; 68921da177e4SLinus Torvalds } 68931da177e4SLinus Torvalds 68941da177e4SLinus Torvalds /* 68958b173218SRicardo Labiaga * Decode SETCLIENTID response 68961da177e4SLinus Torvalds */ 6897bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6898bf269551SChuck Lever struct xdr_stream *xdr, 6899bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 69001da177e4SLinus Torvalds { 69011da177e4SLinus Torvalds struct compound_hdr hdr; 69021da177e4SLinus Torvalds int status; 69031da177e4SLinus Torvalds 6904bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69051da177e4SLinus Torvalds if (!status) 6906bf269551SChuck Lever status = decode_setclientid(xdr, res); 69071da177e4SLinus Torvalds return status; 69081da177e4SLinus Torvalds } 69091da177e4SLinus Torvalds 69101da177e4SLinus Torvalds /* 69118b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 69121da177e4SLinus Torvalds */ 6913bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 691483ca7f5aSChuck Lever struct xdr_stream *xdr) 69151da177e4SLinus Torvalds { 69161da177e4SLinus Torvalds struct compound_hdr hdr; 69171da177e4SLinus Torvalds int status; 69181da177e4SLinus Torvalds 6919bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69201da177e4SLinus Torvalds if (!status) 6921bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 69221da177e4SLinus Torvalds return status; 69231da177e4SLinus Torvalds } 69241da177e4SLinus Torvalds 69251da177e4SLinus Torvalds /* 69268b173218SRicardo Labiaga * Decode DELEGRETURN response 69271da177e4SLinus Torvalds */ 6928bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6929bf269551SChuck Lever struct xdr_stream *xdr, 6930bf269551SChuck Lever struct nfs4_delegreturnres *res) 69311da177e4SLinus Torvalds { 69321da177e4SLinus Torvalds struct compound_hdr hdr; 69331da177e4SLinus Torvalds int status; 69341da177e4SLinus Torvalds 6935bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69369b7b9fccSAndy Adamson if (status) 69379b7b9fccSAndy Adamson goto out; 6938bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69399b7b9fccSAndy Adamson if (status) 6940fa178f29STrond Myklebust goto out; 6941bf269551SChuck Lever status = decode_putfh(xdr); 6942fa178f29STrond Myklebust if (status != 0) 6943fa178f29STrond Myklebust goto out; 6944586f1c39STrond Myklebust if (res->lr_res) { 6945586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6946586f1c39STrond Myklebust res->lr_ret = status; 6947586f1c39STrond Myklebust if (status) 6948586f1c39STrond Myklebust goto out; 6949586f1c39STrond Myklebust } 69508ac2b422STrond Myklebust if (res->fattr) { 6951e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6952556ae3bbSJeff Layton if (status != 0) 6953556ae3bbSJeff Layton goto out; 69548ac2b422STrond Myklebust } 6955e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6956fa178f29STrond Myklebust out: 69571da177e4SLinus Torvalds return status; 69581da177e4SLinus Torvalds } 69591da177e4SLinus Torvalds 6960683b57b4STrond Myklebust /* 69618b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6962683b57b4STrond Myklebust */ 6963bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6964bf269551SChuck Lever struct xdr_stream *xdr, 696522958463SBenny Halevy struct nfs4_fs_locations_res *res) 6966683b57b4STrond Myklebust { 6967683b57b4STrond Myklebust struct compound_hdr hdr; 6968683b57b4STrond Myklebust int status; 6969683b57b4STrond Myklebust 6970bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69719b7b9fccSAndy Adamson if (status) 69729b7b9fccSAndy Adamson goto out; 6973bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69749b7b9fccSAndy Adamson if (status) 6975683b57b4STrond Myklebust goto out; 6976bf269551SChuck Lever status = decode_putfh(xdr); 6977bf269551SChuck Lever if (status) 6978683b57b4STrond Myklebust goto out; 6979b03d735bSChuck Lever if (res->migration) { 6980b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6981b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6982b03d735bSChuck Lever &res->fs_locations->fattr, 6983b03d735bSChuck Lever NULL, res->fs_locations, 6984b03d735bSChuck Lever NULL, res->fs_locations->server); 6985b03d735bSChuck Lever if (status) 6986b03d735bSChuck Lever goto out; 6987b03d735bSChuck Lever if (res->renew) 6988b03d735bSChuck Lever status = decode_renew(xdr); 6989b03d735bSChuck Lever } else { 6990bf269551SChuck Lever status = decode_lookup(xdr); 6991bf269551SChuck Lever if (status) 6992683b57b4STrond Myklebust goto out; 6993bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6994b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6995b03d735bSChuck Lever &res->fs_locations->fattr, 69968b7e3f49STrond Myklebust NULL, res->fs_locations, 6997aa9c2669SDavid Quigley NULL, res->fs_locations->server); 6998b03d735bSChuck Lever } 6999683b57b4STrond Myklebust out: 7000683b57b4STrond Myklebust return status; 7001683b57b4STrond Myklebust } 7002683b57b4STrond Myklebust 70035a5ea0d4SBryan Schumaker /* 70045a5ea0d4SBryan Schumaker * Decode SECINFO response 70055a5ea0d4SBryan Schumaker */ 70065a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 70075a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 70085a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 70095a5ea0d4SBryan Schumaker { 70105a5ea0d4SBryan Schumaker struct compound_hdr hdr; 70115a5ea0d4SBryan Schumaker int status; 70125a5ea0d4SBryan Schumaker 70135a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 70145a5ea0d4SBryan Schumaker if (status) 70155a5ea0d4SBryan Schumaker goto out; 70165a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 70175a5ea0d4SBryan Schumaker if (status) 70185a5ea0d4SBryan Schumaker goto out; 70195a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 70205a5ea0d4SBryan Schumaker if (status) 70215a5ea0d4SBryan Schumaker goto out; 70225a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 70235a5ea0d4SBryan Schumaker out: 70245a5ea0d4SBryan Schumaker return status; 70255a5ea0d4SBryan Schumaker } 70265a5ea0d4SBryan Schumaker 702744c99933SChuck Lever /* 702844c99933SChuck Lever * Decode FSID_PRESENT response 702944c99933SChuck Lever */ 703044c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 703144c99933SChuck Lever struct xdr_stream *xdr, 703244c99933SChuck Lever struct nfs4_fsid_present_res *res) 703344c99933SChuck Lever { 703444c99933SChuck Lever struct compound_hdr hdr; 703544c99933SChuck Lever int status; 703644c99933SChuck Lever 703744c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 703844c99933SChuck Lever if (status) 703944c99933SChuck Lever goto out; 704044c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 704144c99933SChuck Lever if (status) 704244c99933SChuck Lever goto out; 704344c99933SChuck Lever status = decode_putfh(xdr); 704444c99933SChuck Lever if (status) 704544c99933SChuck Lever goto out; 704644c99933SChuck Lever status = decode_getfh(xdr, res->fh); 704744c99933SChuck Lever if (status) 704844c99933SChuck Lever goto out; 704944c99933SChuck Lever if (res->renew) 705044c99933SChuck Lever status = decode_renew(xdr); 705144c99933SChuck Lever out: 705244c99933SChuck Lever return status; 705344c99933SChuck Lever } 705444c99933SChuck Lever 705599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 705699fe60d0SBenny Halevy /* 70577c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 70587c44f1aeSWeston Andros Adamson */ 70597c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 70607c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 70617c44f1aeSWeston Andros Adamson void *res) 70627c44f1aeSWeston Andros Adamson { 70637c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 70647c44f1aeSWeston Andros Adamson int status; 70657c44f1aeSWeston Andros Adamson 70667c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 70677c44f1aeSWeston Andros Adamson if (!status) 70687c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 70697c44f1aeSWeston Andros Adamson return status; 70707c44f1aeSWeston Andros Adamson } 70717c44f1aeSWeston Andros Adamson 70727c44f1aeSWeston Andros Adamson /* 70738b173218SRicardo Labiaga * Decode EXCHANGE_ID response 707499fe60d0SBenny Halevy */ 7075bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7076bf269551SChuck Lever struct xdr_stream *xdr, 707799fe60d0SBenny Halevy void *res) 707899fe60d0SBenny Halevy { 707999fe60d0SBenny Halevy struct compound_hdr hdr; 708099fe60d0SBenny Halevy int status; 708199fe60d0SBenny Halevy 7082bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 708399fe60d0SBenny Halevy if (!status) 7084bf269551SChuck Lever status = decode_exchange_id(xdr, res); 708599fe60d0SBenny Halevy return status; 708699fe60d0SBenny Halevy } 70872050f0ccSAndy Adamson 70882050f0ccSAndy Adamson /* 70898b173218SRicardo Labiaga * Decode CREATE_SESSION response 7090fc931582SAndy Adamson */ 7091bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7092bf269551SChuck Lever struct xdr_stream *xdr, 7093fc931582SAndy Adamson struct nfs41_create_session_res *res) 7094fc931582SAndy Adamson { 7095fc931582SAndy Adamson struct compound_hdr hdr; 7096fc931582SAndy Adamson int status; 7097fc931582SAndy Adamson 7098bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7099fc931582SAndy Adamson if (!status) 7100bf269551SChuck Lever status = decode_create_session(xdr, res); 7101fc931582SAndy Adamson return status; 7102fc931582SAndy Adamson } 7103fc931582SAndy Adamson 7104fc931582SAndy Adamson /* 71058b173218SRicardo Labiaga * Decode DESTROY_SESSION response 71060f3e66c6SAndy Adamson */ 7107bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7108bf269551SChuck Lever struct xdr_stream *xdr, 7109bf269551SChuck Lever void *res) 71100f3e66c6SAndy Adamson { 71110f3e66c6SAndy Adamson struct compound_hdr hdr; 71120f3e66c6SAndy Adamson int status; 71130f3e66c6SAndy Adamson 7114bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71150f3e66c6SAndy Adamson if (!status) 7116bf269551SChuck Lever status = decode_destroy_session(xdr, res); 71170f3e66c6SAndy Adamson return status; 71180f3e66c6SAndy Adamson } 71190f3e66c6SAndy Adamson 71200f3e66c6SAndy Adamson /* 712166245539STrond Myklebust * Decode DESTROY_CLIENTID response 712266245539STrond Myklebust */ 712366245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 712466245539STrond Myklebust struct xdr_stream *xdr, 712566245539STrond Myklebust void *res) 712666245539STrond Myklebust { 712766245539STrond Myklebust struct compound_hdr hdr; 712866245539STrond Myklebust int status; 712966245539STrond Myklebust 713066245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 713166245539STrond Myklebust if (!status) 713266245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 713366245539STrond Myklebust return status; 713466245539STrond Myklebust } 713566245539STrond Myklebust 713666245539STrond Myklebust /* 71378b173218SRicardo Labiaga * Decode SEQUENCE response 7138fc01cea9SAndy Adamson */ 7139bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7140bf269551SChuck Lever struct xdr_stream *xdr, 7141fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 7142fc01cea9SAndy Adamson { 7143fc01cea9SAndy Adamson struct compound_hdr hdr; 7144fc01cea9SAndy Adamson int status; 7145fc01cea9SAndy Adamson 7146bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7147fc01cea9SAndy Adamson if (!status) 7148bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7149fc01cea9SAndy Adamson return status; 7150fc01cea9SAndy Adamson } 7151fc01cea9SAndy Adamson 7152fc01cea9SAndy Adamson /* 71538b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 71542050f0ccSAndy Adamson */ 7155bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7156bf269551SChuck Lever struct xdr_stream *xdr, 71572050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 71582050f0ccSAndy Adamson { 71592050f0ccSAndy Adamson struct compound_hdr hdr; 71602050f0ccSAndy Adamson int status; 71612050f0ccSAndy Adamson 7162bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71632050f0ccSAndy Adamson if (!status) 7164bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 71652050f0ccSAndy Adamson if (!status) 7166bf269551SChuck Lever status = decode_putrootfh(xdr); 71672050f0ccSAndy Adamson if (!status) 7168bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 71692050f0ccSAndy Adamson return status; 71702050f0ccSAndy Adamson } 717118019753SRicardo Labiaga 717218019753SRicardo Labiaga /* 717318019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 717418019753SRicardo Labiaga */ 7175bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7176bf269551SChuck Lever struct xdr_stream *xdr, 717718019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 717818019753SRicardo Labiaga { 717918019753SRicardo Labiaga struct compound_hdr hdr; 718018019753SRicardo Labiaga int status; 718118019753SRicardo Labiaga 7182bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 718318019753SRicardo Labiaga if (!status) 7184bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 718518019753SRicardo Labiaga if (!status) 71868ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 718718019753SRicardo Labiaga return status; 718818019753SRicardo Labiaga } 7189b1f69b75SAndy Adamson 7190b1f69b75SAndy Adamson /* 7191b1f69b75SAndy Adamson * Decode GETDEVINFO response 7192b1f69b75SAndy Adamson */ 7193bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7194bf269551SChuck Lever struct xdr_stream *xdr, 7195b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 7196b1f69b75SAndy Adamson { 7197b1f69b75SAndy Adamson struct compound_hdr hdr; 7198b1f69b75SAndy Adamson int status; 7199b1f69b75SAndy Adamson 7200bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7201b1f69b75SAndy Adamson if (status != 0) 7202b1f69b75SAndy Adamson goto out; 7203bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7204b1f69b75SAndy Adamson if (status != 0) 7205b1f69b75SAndy Adamson goto out; 72064e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7207b1f69b75SAndy Adamson out: 7208b1f69b75SAndy Adamson return status; 7209b1f69b75SAndy Adamson } 7210b1f69b75SAndy Adamson 7211b1f69b75SAndy Adamson /* 7212b1f69b75SAndy Adamson * Decode LAYOUTGET response 7213b1f69b75SAndy Adamson */ 7214bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7215bf269551SChuck Lever struct xdr_stream *xdr, 7216b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 7217b1f69b75SAndy Adamson { 7218b1f69b75SAndy Adamson struct compound_hdr hdr; 7219b1f69b75SAndy Adamson int status; 7220b1f69b75SAndy Adamson 7221bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7222b1f69b75SAndy Adamson if (status) 7223b1f69b75SAndy Adamson goto out; 7224bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7225b1f69b75SAndy Adamson if (status) 7226b1f69b75SAndy Adamson goto out; 7227bf269551SChuck Lever status = decode_putfh(xdr); 7228b1f69b75SAndy Adamson if (status) 7229b1f69b75SAndy Adamson goto out; 7230bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7231b1f69b75SAndy Adamson out: 7232b1f69b75SAndy Adamson return status; 7233b1f69b75SAndy Adamson } 7234863a3c6cSAndy Adamson 7235863a3c6cSAndy Adamson /* 7236cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7237cbe82603SBenny Halevy */ 7238cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7239cbe82603SBenny Halevy struct xdr_stream *xdr, 7240cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 7241cbe82603SBenny Halevy { 7242cbe82603SBenny Halevy struct compound_hdr hdr; 7243cbe82603SBenny Halevy int status; 7244cbe82603SBenny Halevy 7245cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7246cbe82603SBenny Halevy if (status) 7247cbe82603SBenny Halevy goto out; 7248cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7249cbe82603SBenny Halevy if (status) 7250cbe82603SBenny Halevy goto out; 7251cbe82603SBenny Halevy status = decode_putfh(xdr); 7252cbe82603SBenny Halevy if (status) 7253cbe82603SBenny Halevy goto out; 7254cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7255cbe82603SBenny Halevy out: 7256cbe82603SBenny Halevy return status; 7257cbe82603SBenny Halevy } 7258cbe82603SBenny Halevy 7259cbe82603SBenny Halevy /* 7260863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7261863a3c6cSAndy Adamson */ 7262863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7263863a3c6cSAndy Adamson struct xdr_stream *xdr, 7264863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 7265863a3c6cSAndy Adamson { 7266863a3c6cSAndy Adamson struct compound_hdr hdr; 7267863a3c6cSAndy Adamson int status; 7268863a3c6cSAndy Adamson 7269863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7270863a3c6cSAndy Adamson if (status) 7271863a3c6cSAndy Adamson goto out; 7272863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7273863a3c6cSAndy Adamson if (status) 7274863a3c6cSAndy Adamson goto out; 7275863a3c6cSAndy Adamson status = decode_putfh(xdr); 7276863a3c6cSAndy Adamson if (status) 7277863a3c6cSAndy Adamson goto out; 7278863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7279863a3c6cSAndy Adamson if (status) 7280863a3c6cSAndy Adamson goto out; 72816926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7282863a3c6cSAndy Adamson out: 7283863a3c6cSAndy Adamson return status; 7284863a3c6cSAndy Adamson } 7285fca78d6dSBryan Schumaker 7286fca78d6dSBryan Schumaker /* 7287fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7288fca78d6dSBryan Schumaker */ 7289fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7290fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7291fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 7292fca78d6dSBryan Schumaker { 7293fca78d6dSBryan Schumaker struct compound_hdr hdr; 7294fca78d6dSBryan Schumaker int status; 7295fca78d6dSBryan Schumaker 7296fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7297fca78d6dSBryan Schumaker if (status) 7298fca78d6dSBryan Schumaker goto out; 7299fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7300fca78d6dSBryan Schumaker if (status) 7301fca78d6dSBryan Schumaker goto out; 7302fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7303fca78d6dSBryan Schumaker if (status) 7304fca78d6dSBryan Schumaker goto out; 730531e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7306fca78d6dSBryan Schumaker out: 7307fca78d6dSBryan Schumaker return status; 7308fca78d6dSBryan Schumaker } 73097d974794SBryan Schumaker 73107d974794SBryan Schumaker /* 73117d974794SBryan Schumaker * Decode TEST_STATEID response 73127d974794SBryan Schumaker */ 73137d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 73147d974794SBryan Schumaker struct xdr_stream *xdr, 73157d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 73167d974794SBryan Schumaker { 73177d974794SBryan Schumaker struct compound_hdr hdr; 73187d974794SBryan Schumaker int status; 73197d974794SBryan Schumaker 73207d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 73217d974794SBryan Schumaker if (status) 73227d974794SBryan Schumaker goto out; 73237d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 73247d974794SBryan Schumaker if (status) 73257d974794SBryan Schumaker goto out; 73267d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 73277d974794SBryan Schumaker out: 73287d974794SBryan Schumaker return status; 73297d974794SBryan Schumaker } 73309aeda35fSBryan Schumaker 73319aeda35fSBryan Schumaker /* 73329aeda35fSBryan Schumaker * Decode FREE_STATEID response 73339aeda35fSBryan Schumaker */ 73349aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 73359aeda35fSBryan Schumaker struct xdr_stream *xdr, 73369aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 73379aeda35fSBryan Schumaker { 73389aeda35fSBryan Schumaker struct compound_hdr hdr; 73399aeda35fSBryan Schumaker int status; 73409aeda35fSBryan Schumaker 73419aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 73429aeda35fSBryan Schumaker if (status) 73439aeda35fSBryan Schumaker goto out; 73449aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 73459aeda35fSBryan Schumaker if (status) 73469aeda35fSBryan Schumaker goto out; 73479aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 73489aeda35fSBryan Schumaker out: 73499aeda35fSBryan Schumaker return status; 73509aeda35fSBryan Schumaker } 735199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 735299fe60d0SBenny Halevy 7353573c4e1eSChuck Lever /** 7354573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7355573c4e1eSChuck Lever * the local page cache. 7356573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7357573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7358573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7359573c4e1eSChuck Lever * 7360573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7361573c4e1eSChuck Lever * returned. 7362573c4e1eSChuck Lever * 7363573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7364573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7365573c4e1eSChuck Lever * on a directory already in our cache. 7366573c4e1eSChuck Lever */ 7367573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7368573c4e1eSChuck Lever int plus) 73691da177e4SLinus Torvalds { 7370256e48bbSTrond Myklebust unsigned int savep; 7371dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 73721da177e4SLinus Torvalds uint32_t len; 7373babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7374babddc72SBryan Schumaker if (unlikely(!p)) 7375babddc72SBryan Schumaker goto out_overflow; 7376c08e76d0SChuck Lever if (*p == xdr_zero) { 7377babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7378babddc72SBryan Schumaker if (unlikely(!p)) 7379babddc72SBryan Schumaker goto out_overflow; 7380c08e76d0SChuck Lever if (*p == xdr_zero) 7381573c4e1eSChuck Lever return -EAGAIN; 73821da177e4SLinus Torvalds entry->eof = 1; 7383573c4e1eSChuck Lever return -EBADCOOKIE; 73841da177e4SLinus Torvalds } 73851da177e4SLinus Torvalds 7386babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7387babddc72SBryan Schumaker if (unlikely(!p)) 7388babddc72SBryan Schumaker goto out_overflow; 73891da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 73901da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7391c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7392babddc72SBryan Schumaker 73939af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7394babddc72SBryan Schumaker if (unlikely(!p)) 7395babddc72SBryan Schumaker goto out_overflow; 73961da177e4SLinus Torvalds entry->name = (const char *) p; 73971da177e4SLinus Torvalds 73981da177e4SLinus Torvalds /* 73991da177e4SLinus Torvalds * In case the server doesn't return an inode number, 74001da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 74011da177e4SLinus Torvalds * since glibc seems to choke on it...) 74021da177e4SLinus Torvalds */ 74031da177e4SLinus Torvalds entry->ino = 1; 74044f082222STrond Myklebust entry->fattr->valid = 0; 74051da177e4SLinus Torvalds 74069af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7407babddc72SBryan Schumaker goto out_overflow; 74089af8c222STrond Myklebust 7409256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7410babddc72SBryan Schumaker goto out_overflow; 74119af8c222STrond Myklebust 7412573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7413aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7414babddc72SBryan Schumaker goto out_overflow; 741528331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 741628331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 741728331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 741882f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 74199af8c222STrond Myklebust 74200b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 74210b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 74220b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 74230b26a0bfSTrond Myklebust 7424573c4e1eSChuck Lever return 0; 7425babddc72SBryan Schumaker 7426babddc72SBryan Schumaker out_overflow: 7427babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7428573c4e1eSChuck Lever return -EAGAIN; 74291da177e4SLinus Torvalds } 74301da177e4SLinus Torvalds 74311da177e4SLinus Torvalds /* 74321da177e4SLinus Torvalds * We need to translate between nfs status return values and 74331da177e4SLinus Torvalds * the local errno values which may not be the same. 74341da177e4SLinus Torvalds */ 74351da177e4SLinus Torvalds static struct { 74361da177e4SLinus Torvalds int stat; 74371da177e4SLinus Torvalds int errno; 74381da177e4SLinus Torvalds } nfs_errtbl[] = { 74391da177e4SLinus Torvalds { NFS4_OK, 0 }, 7440856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7441856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7442856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7443856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7444856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7445856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7446856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7447856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7448856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7449856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7450856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7451856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7452856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7453856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7454856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7455856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7456856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7457856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7458856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7459856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7460856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7461856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7462fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7463856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7464856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7465856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7466856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7467856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7468856dff3dSBenny Halevy { -1, -EIO } 74691da177e4SLinus Torvalds }; 74701da177e4SLinus Torvalds 74711da177e4SLinus Torvalds /* 74721da177e4SLinus Torvalds * Convert an NFS error code to a local one. 74731da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 74741da177e4SLinus Torvalds */ 74751da177e4SLinus Torvalds static int 74760a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 74771da177e4SLinus Torvalds { 74781da177e4SLinus Torvalds int i; 74791da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 74801da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 74811da177e4SLinus Torvalds return nfs_errtbl[i].errno; 74821da177e4SLinus Torvalds } 74831da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 74841da177e4SLinus Torvalds /* The server is looney tunes. */ 7485fdcb4577STrond Myklebust return -EREMOTEIO; 74861da177e4SLinus Torvalds } 74871da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 74881da177e4SLinus Torvalds * handle it. 74891da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 74901da177e4SLinus Torvalds * not conflict with native Linux error codes. 74911da177e4SLinus Torvalds */ 7492856dff3dSBenny Halevy return -stat; 74931da177e4SLinus Torvalds } 74941da177e4SLinus Torvalds 74951c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 74961c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 74971c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 74981c6dcbe5SAnna Schumaker 74991da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 75001da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 75011da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 75029f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7503bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 75042bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 75052bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7506cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7507cc0175c1SChuck Lever .p_name = #proc, \ 75081da177e4SLinus Torvalds } 75091da177e4SLinus Torvalds 75107c61f0d3SAnna Schumaker #define STUB(proc) \ 75117c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 75127c61f0d3SAnna Schumaker .p_name = #proc, \ 75137c61f0d3SAnna Schumaker } 75147c61f0d3SAnna Schumaker 75151da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 75161da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 75171da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 75181da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 75191da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 75201da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 75211da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 75221da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 75231da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 75241da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 75251da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 75261da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 75271da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 75281da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 75291da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 75301da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 75311da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 75321da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 75331da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 75341da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 75351da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 75361da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 75371da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 75381da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 75391da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 75401da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 75411da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 75421da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 75431da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 75441da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 75451da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 75461da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7547029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 754823ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7549683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7550d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 75515a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 755244c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 755399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 755499fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7555fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 75560f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7557fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 75582050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 755918019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7560b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7561b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7562863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7563cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7564fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 75657d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 75669aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 75677c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 7568ad24ecfbSTrond Myklebust PROC(BIND_CONN_TO_SESSION, 7569ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 757066245539STrond Myklebust PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 757199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 75721c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 75731c6dcbe5SAnna Schumaker PROC(SEEK, enc_seek, dec_seek), 7574f4ac1674SAnna Schumaker PROC(ALLOCATE, enc_allocate, dec_allocate), 7575624bd5b7SAnna Schumaker PROC(DEALLOCATE, enc_deallocate, dec_deallocate), 7576be3a5d23STrond Myklebust PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 757736022770SPeng Tao PROC(CLONE, enc_clone, dec_clone), 75782e72448bSAnna Schumaker PROC(COPY, enc_copy, dec_copy), 75791c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 75801da177e4SLinus Torvalds }; 75811da177e4SLinus Torvalds 7582a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 75831da177e4SLinus Torvalds .number = 4, 7584e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 75851da177e4SLinus Torvalds .procs = nfs4_procedures 75861da177e4SLinus Torvalds }; 75871da177e4SLinus Torvalds 75881da177e4SLinus Torvalds /* 75891da177e4SLinus Torvalds * Local variables: 75901da177e4SLinus Torvalds * c-basic-offset: 8 75911da177e4SLinus Torvalds * End: 75921da177e4SLinus Torvalds */ 7593