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, 100328cf22d0STrond Myklebust const umode_t *umask, 10045334c5bdSKinglong Mee const struct nfs_server *server, 100528cf22d0STrond Myklebust const uint32_t attrmask[]) 10061da177e4SLinus Torvalds { 10071da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10081da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10091da177e4SLinus Torvalds int owner_namelen = 0; 10101da177e4SLinus Torvalds int owner_grouplen = 0; 10118687b63aSAl Viro __be32 *p; 1012d7067b2dSTrond Myklebust unsigned i; 1013d7067b2dSTrond Myklebust uint32_t len = 0; 1014d7067b2dSTrond Myklebust uint32_t bmval_len; 1015d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds /* 10181da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10191da177e4SLinus Torvalds */ 102028cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) { 1021d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10221da177e4SLinus Torvalds len += 8; 1023d7067b2dSTrond Myklebust } 1024d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 102528cf22d0STrond Myklebust if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) { 1026dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK; 1027dff25ddbSAndreas Gruenbacher len += 8; 102828cf22d0STrond Myklebust } else if (attrmask[1] & FATTR4_WORD1_MODE) { 1029d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10301da177e4SLinus Torvalds len += 4; 1031d7067b2dSTrond Myklebust } 1032dff25ddbSAndreas Gruenbacher } 103328cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) { 1034e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10351da177e4SLinus Torvalds if (owner_namelen < 0) { 1036fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1037e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 10381da177e4SLinus Torvalds /* XXX */ 10391da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10401da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10411da177e4SLinus Torvalds /* goto out; */ 10421da177e4SLinus Torvalds } 1043d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 10441da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10451da177e4SLinus Torvalds } 104628cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_GID) && 104728cf22d0STrond Myklebust (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) { 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 } 105928cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 1060d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1061d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10621da177e4SLinus Torvalds len += 16; 1063d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1064d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10651da177e4SLinus Torvalds len += 4; 1066d7067b2dSTrond Myklebust } 106728cf22d0STrond Myklebust } 106828cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 1069d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1070d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10711da177e4SLinus Torvalds len += 16; 1072d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1073d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10741da177e4SLinus Torvalds len += 4; 1075d7067b2dSTrond Myklebust } 10765334c5bdSKinglong Mee } 10775334c5bdSKinglong Mee 107828cf22d0STrond Myklebust if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) { 1079b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1080d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1081d7067b2dSTrond Myklebust } 1082d7067b2dSTrond Myklebust 1083d7067b2dSTrond Myklebust if (bmval[2] != 0) 1084b4a2cf76STrond Myklebust bmval_len = 3; 1085d7067b2dSTrond Myklebust else if (bmval[1] != 0) 1086d7067b2dSTrond Myklebust bmval_len = 2; 1087d7067b2dSTrond Myklebust else 1088d7067b2dSTrond Myklebust bmval_len = 1; 1089b4a2cf76STrond Myklebust 1090d7067b2dSTrond Myklebust p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len); 10911da177e4SLinus Torvalds 1092b4a2cf76STrond Myklebust *p++ = cpu_to_be32(bmval_len); 1093d7067b2dSTrond Myklebust for (i = 0; i < bmval_len; i++) 1094d7067b2dSTrond Myklebust *p++ = cpu_to_be32(bmval[i]); 1095d7067b2dSTrond Myklebust *p++ = cpu_to_be32(len); 10961da177e4SLinus Torvalds 1097d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1098b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1099d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1100e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1101d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1102811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1103d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1104811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1105d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11061da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1107e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1108042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec); 1109d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 1110d7067b2dSTrond Myklebust } else 1111e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11121da177e4SLinus Torvalds } 1113d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11141da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1115e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1116042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec); 1117e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 1118d7067b2dSTrond Myklebust } else 1119e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11201da177e4SLinus Torvalds } 1121d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1122aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1123aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1124aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1125aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1126aa9c2669SDavid Quigley } 1127dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1128dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1129dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask); 1130dff25ddbSAndreas Gruenbacher } 11311da177e4SLinus Torvalds 11321da177e4SLinus Torvalds /* out: */ 11331da177e4SLinus Torvalds } 11341da177e4SLinus Torvalds 1135cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11361da177e4SLinus Torvalds { 1137475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1138475d4ba0STrond Myklebust encode_uint32(xdr, access); 11391da177e4SLinus Torvalds } 11401da177e4SLinus Torvalds 1141cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11421da177e4SLinus Torvalds { 1143ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11444ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1145566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11461da177e4SLinus Torvalds } 11471da177e4SLinus Torvalds 11480b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11491da177e4SLinus Torvalds { 11508687b63aSAl Viro __be32 *p; 11511da177e4SLinus Torvalds 1152475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1153475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1154b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 115534558513SBenny Halevy *p = cpu_to_be32(args->count); 11561da177e4SLinus Torvalds } 11571da177e4SLinus Torvalds 1158cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11591da177e4SLinus Torvalds { 11608687b63aSAl Viro __be32 *p; 11611da177e4SLinus Torvalds 1162475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1163475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11641da177e4SLinus Torvalds 11651da177e4SLinus Torvalds switch (create->ftype) { 11661da177e4SLinus Torvalds case NF4LNK: 116713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 116834558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 11692fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 11702fcc213aSChuck Lever create->u.symlink.len); 11712fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 11721da177e4SLinus Torvalds break; 11731da177e4SLinus Torvalds 11741da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 117513c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1176e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 117734558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11781da177e4SLinus Torvalds break; 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds default: 11811da177e4SLinus Torvalds break; 11821da177e4SLinus Torvalds } 11831da177e4SLinus Torvalds 1184811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 118528cf22d0STrond Myklebust encode_attrs(xdr, create->attrs, create->label, &create->umask, 118628cf22d0STrond Myklebust create->server, create->server->attr_bitmask); 11871da177e4SLinus Torvalds } 11881da177e4SLinus Torvalds 1189cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11901da177e4SLinus Torvalds { 11918687b63aSAl Viro __be32 *p; 11921da177e4SLinus Torvalds 1193475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1194475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1195e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 119634558513SBenny Halevy *p = cpu_to_be32(bitmap); 11971da177e4SLinus Torvalds } 11981da177e4SLinus Torvalds 1199cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 12001da177e4SLinus Torvalds { 12018687b63aSAl Viro __be32 *p; 12021da177e4SLinus Torvalds 1203475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1204475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1205e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1206e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 120734558513SBenny Halevy *p = cpu_to_be32(bm1); 12081da177e4SLinus Torvalds } 12091da177e4SLinus Torvalds 1210dae100c2SFred Isaman static void 1211dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1212dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1213dae100c2SFred Isaman struct compound_hdr *hdr) 1214dae100c2SFred Isaman { 1215dae100c2SFred Isaman __be32 *p; 1216dae100c2SFred Isaman 1217ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1218dae100c2SFred Isaman if (bm2) { 1219dae100c2SFred Isaman p = reserve_space(xdr, 16); 1220dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1221dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1222dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1223dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1224dae100c2SFred Isaman } else if (bm1) { 1225dae100c2SFred Isaman p = reserve_space(xdr, 12); 1226dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1227dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1228dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1229dae100c2SFred Isaman } else { 1230dae100c2SFred Isaman p = reserve_space(xdr, 8); 1231dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1232dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1233dae100c2SFred Isaman } 1234dae100c2SFred Isaman } 1235dae100c2SFred Isaman 1236cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12371da177e4SLinus Torvalds { 1238a09df2caSDavid Quigley encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1239a09df2caSDavid Quigley bitmask[1] & nfs4_fattr_bitmap[1], 1240a09df2caSDavid Quigley bitmask[2] & nfs4_fattr_bitmap[2], 1241a09df2caSDavid Quigley hdr); 12421da177e4SLinus Torvalds } 12431da177e4SLinus Torvalds 124488034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12451549210fSTrond Myklebust const u32 *open_bitmap, 124688034c3dSAndy Adamson struct compound_hdr *hdr) 124788034c3dSAndy Adamson { 124888034c3dSAndy Adamson encode_getattr_three(xdr, 12491549210fSTrond Myklebust bitmask[0] & open_bitmap[0], 12501549210fSTrond Myklebust bitmask[1] & open_bitmap[1], 12511549210fSTrond Myklebust bitmask[2] & open_bitmap[2], 125288034c3dSAndy Adamson hdr); 125388034c3dSAndy Adamson } 125488034c3dSAndy Adamson 1255cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12561da177e4SLinus Torvalds { 1257dae100c2SFred Isaman encode_getattr_three(xdr, 1258dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1259dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1260dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1261dae100c2SFred Isaman hdr); 12621da177e4SLinus Torvalds } 12631da177e4SLinus Torvalds 1264cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1265830b8e33SManoj Naik { 1266cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1267cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1268830b8e33SManoj Naik } 1269830b8e33SManoj Naik 1270cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12711da177e4SLinus Torvalds { 1272ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12731da177e4SLinus Torvalds } 12741da177e4SLinus Torvalds 1275cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12761da177e4SLinus Torvalds { 1277ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12786fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12791da177e4SLinus Torvalds } 12801da177e4SLinus Torvalds 1281911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1282911d1aafSTrond Myklebust { 1283f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1284911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1285911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1286911d1aafSTrond Myklebust } 1287911d1aafSTrond Myklebust 1288911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1289911d1aafSTrond Myklebust { 1290911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1291911d1aafSTrond Myklebust return ~(uint64_t)0; 1292911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1293911d1aafSTrond Myklebust } 1294911d1aafSTrond Myklebust 1295daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1296daccbdedSTrond Myklebust { 1297daccbdedSTrond Myklebust __be32 *p; 1298daccbdedSTrond Myklebust 1299d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1300daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1301d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1302daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1303d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1304daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1305daccbdedSTrond Myklebust } 1306daccbdedSTrond Myklebust 13071da177e4SLinus Torvalds /* 13081da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13091da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13101da177e4SLinus Torvalds */ 1311cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13121da177e4SLinus Torvalds { 13138687b63aSAl Viro __be32 *p; 13141da177e4SLinus Torvalds 1315475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1316475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1317e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1318e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1319b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1320b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 132134558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1322911d1aafSTrond Myklebust if (args->new_lock_owner){ 13234ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1324425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13254ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1326daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13271da177e4SLinus Torvalds } 13281da177e4SLinus Torvalds else { 1329425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13304ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13311da177e4SLinus Torvalds } 13321da177e4SLinus Torvalds } 13331da177e4SLinus Torvalds 1334cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13351da177e4SLinus Torvalds { 13368687b63aSAl Viro __be32 *p; 13371da177e4SLinus Torvalds 1338475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1339475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1340e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1341b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1342b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1343daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13441da177e4SLinus Torvalds } 13451da177e4SLinus Torvalds 1346cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13471da177e4SLinus Torvalds { 13488687b63aSAl Viro __be32 *p; 13491da177e4SLinus Torvalds 1350475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1351475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13524ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1353425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1354ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1355b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 135634558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13571da177e4SLinus Torvalds } 13581da177e4SLinus Torvalds 1359d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1360d3c7b7ccSTrond Myklebust { 1361ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1362d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1363d3c7b7ccSTrond Myklebust } 1364d3c7b7ccSTrond Myklebust 1365cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13661da177e4SLinus Torvalds { 1367ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13686fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13691da177e4SLinus Torvalds } 13701da177e4SLinus Torvalds 13716ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13721da177e4SLinus Torvalds { 13738687b63aSAl Viro __be32 *p; 13741da177e4SLinus Torvalds 137513c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13766ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 137734558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13781da177e4SLinus Torvalds } 13791da177e4SLinus Torvalds 13801da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13811da177e4SLinus Torvalds { 13828687b63aSAl Viro __be32 *p; 13831da177e4SLinus Torvalds /* 13841da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13851da177e4SLinus Torvalds * owner 4 = 32 13861da177e4SLinus Torvalds */ 13874ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 13886ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 138995b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1390b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 139195b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 139293f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1393d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 139495b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 139595b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 13961da177e4SLinus Torvalds } 13971da177e4SLinus Torvalds 13981da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13991da177e4SLinus Torvalds { 14008687b63aSAl Viro __be32 *p; 14011da177e4SLinus Torvalds 140213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1403549b19ccSTrond Myklebust switch(arg->createmode) { 1404549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 140534558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 140628cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 140728cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 14081da177e4SLinus Torvalds break; 1409549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14104882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 141128cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 141228cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 1413549b19ccSTrond Myklebust break; 1414549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1415549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1416549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1417549b19ccSTrond Myklebust break; 1418549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14194882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14204882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 142128cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 142228cf22d0STrond Myklebust arg->server, arg->server->exclcreat_bitmask); 14234882ef72SAlexandros Batsakis } 14244882ef72SAlexandros Batsakis } 14251da177e4SLinus Torvalds 14261da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14271da177e4SLinus Torvalds { 14288687b63aSAl Viro __be32 *p; 14291da177e4SLinus Torvalds 143013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14311da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14321da177e4SLinus Torvalds case 0: 143334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14341da177e4SLinus Torvalds break; 14351da177e4SLinus Torvalds default: 143634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14371da177e4SLinus Torvalds encode_createmode(xdr, arg); 14381da177e4SLinus Torvalds } 14391da177e4SLinus Torvalds } 14401da177e4SLinus Torvalds 1441bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14421da177e4SLinus Torvalds { 14438687b63aSAl Viro __be32 *p; 14441da177e4SLinus Torvalds 144513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14461da177e4SLinus Torvalds switch (delegation_type) { 14471da177e4SLinus Torvalds case 0: 144834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14491da177e4SLinus Torvalds break; 14501da177e4SLinus Torvalds case FMODE_READ: 145134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14521da177e4SLinus Torvalds break; 14531da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 145434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14551da177e4SLinus Torvalds break; 14561da177e4SLinus Torvalds default: 14571da177e4SLinus Torvalds BUG(); 14581da177e4SLinus Torvalds } 14591da177e4SLinus Torvalds } 14601da177e4SLinus Torvalds 14611da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14621da177e4SLinus Torvalds { 14638687b63aSAl Viro __be32 *p; 14641da177e4SLinus Torvalds 146513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 146634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14671da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14681da177e4SLinus Torvalds } 14691da177e4SLinus Torvalds 1470bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14711da177e4SLinus Torvalds { 14728687b63aSAl Viro __be32 *p; 14731da177e4SLinus Torvalds 147413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 147534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14761da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14771da177e4SLinus Torvalds } 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14801da177e4SLinus Torvalds { 14818687b63aSAl Viro __be32 *p; 14821da177e4SLinus Torvalds 1483ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1484ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1485ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14861da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14871da177e4SLinus Torvalds } 14881da177e4SLinus Torvalds 1489d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1490d9fc6619STrond Myklebust { 1491d9fc6619STrond Myklebust __be32 *p; 1492d9fc6619STrond Myklebust 1493d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1494d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1495d9fc6619STrond Myklebust } 1496d9fc6619STrond Myklebust 1497d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1498d9fc6619STrond Myklebust { 1499d9fc6619STrond Myklebust __be32 *p; 1500d9fc6619STrond Myklebust 1501d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1502d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1503d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1504d9fc6619STrond Myklebust } 1505d9fc6619STrond Myklebust 1506cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15071da177e4SLinus Torvalds { 1508ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15091da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15101da177e4SLinus Torvalds encode_opentype(xdr, arg); 15111da177e4SLinus Torvalds switch (arg->claim) { 15121da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15131da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15141da177e4SLinus Torvalds break; 15151da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15161da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15171da177e4SLinus Torvalds break; 15181da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15191da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15201da177e4SLinus Torvalds break; 1521d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1522d9fc6619STrond Myklebust encode_claim_fh(xdr); 1523d9fc6619STrond Myklebust break; 1524d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1525d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1526d9fc6619STrond Myklebust break; 15271da177e4SLinus Torvalds default: 15281da177e4SLinus Torvalds BUG(); 15291da177e4SLinus Torvalds } 15301da177e4SLinus Torvalds } 15311da177e4SLinus Torvalds 1532cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15331da177e4SLinus Torvalds { 1534ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1535ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15364ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15371da177e4SLinus Torvalds } 15381da177e4SLinus Torvalds 1539cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15401da177e4SLinus Torvalds { 1541ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1542566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15434ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15446ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15451da177e4SLinus Torvalds } 15461da177e4SLinus Torvalds 1547cf8cdbe5SAndy Adamson static void 1548d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15491da177e4SLinus Torvalds { 1550ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15516fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15521da177e4SLinus Torvalds } 15531da177e4SLinus Torvalds 1554cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15551da177e4SLinus Torvalds { 1556ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15571da177e4SLinus Torvalds } 15581da177e4SLinus Torvalds 15593c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15603c6b899cSAnna Schumaker struct compound_hdr *hdr) 15611da177e4SLinus Torvalds { 15628687b63aSAl Viro __be32 *p; 15631da177e4SLinus Torvalds 1564ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15659b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15661da177e4SLinus Torvalds 156713c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1568b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 156934558513SBenny Halevy *p = cpu_to_be32(args->count); 15701da177e4SLinus Torvalds } 15711da177e4SLinus Torvalds 1572cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15731da177e4SLinus Torvalds { 1574aa9c2669SDavid Quigley uint32_t attrs[3] = { 157528331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 157628331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 157728331a46STrond Myklebust }; 15786f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1579cd93710eSChuck Lever __be32 *p, verf[2]; 1580d204c5d2STrond Myklebust uint32_t attrlen = 0; 1581d204c5d2STrond Myklebust unsigned int i; 15821da177e4SLinus Torvalds 158382f2e547SBryan Schumaker if (readdir->plus) { 158482f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 158528331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 158682f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 158782f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 158882f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 158982f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1590d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 15916f7a35bdSTrond Myklebust dircount >>= 1; 159282f2e547SBryan Schumaker } 159328331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 159428331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 159528331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1596d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1597d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1598d204c5d2STrond Myklebust if (attrs[i] != 0) 1599d204c5d2STrond Myklebust attrlen = i+1; 1600d204c5d2STrond Myklebust } 16016f7a35bdSTrond Myklebust 1602475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1603ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1604cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1605d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16066f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16076f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1608d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1609d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1610d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1611cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1612aa9c2669SDavid Quigley 1613aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 161444109241SFred Isaman __func__, 1615eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1616cd93710eSChuck Lever verf[0], verf[1], 1617eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1618aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1619aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16201da177e4SLinus Torvalds } 16211da177e4SLinus Torvalds 1622cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16231da177e4SLinus Torvalds { 1624ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds 1627cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16281da177e4SLinus Torvalds { 1629ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16306fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds 1633cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16341da177e4SLinus Torvalds { 1635ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1636811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1637811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16381da177e4SLinus Torvalds } 16391da177e4SLinus Torvalds 1640bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1641bb4dae5eSChuck Lever struct compound_hdr *hdr) 16421da177e4SLinus Torvalds { 1643475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1644ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16451da177e4SLinus Torvalds } 16461da177e4SLinus Torvalds 1647cf8cdbe5SAndy Adamson static void 1648d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 164956ae19f3STrond Myklebust { 1650ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 165156ae19f3STrond Myklebust } 165256ae19f3STrond Myklebust 16539f06c719SChuck Lever static void 1654fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg, 1655fcc85819SChristoph Hellwig struct compound_hdr *hdr) 165623ec6965SJ. Bruce Fields { 16578687b63aSAl Viro __be32 *p; 165823ec6965SJ. Bruce Fields 1659ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1660ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 166113c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1662e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 166334558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 166413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 166534558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16668fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 166723ec6965SJ. Bruce Fields } 166823ec6965SJ. Bruce Fields 1669cf8cdbe5SAndy Adamson static void 1670d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16711da177e4SLinus Torvalds { 1672ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16731da177e4SLinus Torvalds } 16741da177e4SLinus Torvalds 1675cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16761da177e4SLinus Torvalds { 1677ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1678ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 167928cf22d0STrond Myklebust encode_attrs(xdr, arg->iap, arg->label, NULL, server, 168028cf22d0STrond Myklebust server->attr_bitmask); 16811da177e4SLinus Torvalds } 16821da177e4SLinus Torvalds 1683cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16841da177e4SLinus Torvalds { 16858687b63aSAl Viro __be32 *p; 16861da177e4SLinus Torvalds 168770019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1688cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16891da177e4SLinus Torvalds 16903a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 16913a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 169213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 169334558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16941da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16951da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 169613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 16973a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 16981da177e4SLinus Torvalds } 16991da177e4SLinus Torvalds 1700bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 17011da177e4SLinus Torvalds { 1702475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1703475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1704ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1705cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17061da177e4SLinus Torvalds } 17071da177e4SLinus Torvalds 17083c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17093c6b899cSAnna Schumaker struct compound_hdr *hdr) 17101da177e4SLinus Torvalds { 17118687b63aSAl Viro __be32 *p; 17121da177e4SLinus Torvalds 1713ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17149b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17151da177e4SLinus Torvalds 171613c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1717b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1718e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 171934558513SBenny Halevy *p = cpu_to_be32(args->count); 17201da177e4SLinus Torvalds 17211da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17221da177e4SLinus Torvalds } 17231da177e4SLinus Torvalds 1724cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17251da177e4SLinus Torvalds { 1726ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1727ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17281da177e4SLinus Torvalds } 17299b7b9fccSAndy Adamson 17305a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17315a5ea0d4SBryan Schumaker { 1732ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17336fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17345a5ea0d4SBryan Schumaker } 17355a5ea0d4SBryan Schumaker 173699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17379b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17387c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 1739fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args, 17407c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17417c44f1aeSWeston Andros Adamson { 17427c44f1aeSWeston Andros Adamson __be32 *p; 17437c44f1aeSWeston Andros Adamson 17447c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17457c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 174671a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17477c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 174871a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 174971a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17507c44f1aeSWeston Andros Adamson } 17517c44f1aeSWeston Andros Adamson 1752fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map) 17532031cd1aSWeston Andros Adamson { 17542031cd1aSWeston Andros Adamson unsigned int i; 17552031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17562031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17572031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17582031cd1aSWeston Andros Adamson } 17592031cd1aSWeston Andros Adamson 176099fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 1761fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args, 176299fe60d0SBenny Halevy struct compound_hdr *hdr) 176399fe60d0SBenny Halevy { 176499fe60d0SBenny Halevy __be32 *p; 1765d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1766db8ac8baSWeston Andros Adamson int len = 0; 176799fe60d0SBenny Halevy 176870019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1769cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 177099fe60d0SBenny Halevy 17713a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17723a6bb738SJeff Layton args->client->cl_owner_id); 177399fe60d0SBenny Halevy 17742031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17752031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17762031cd1aSWeston Andros Adamson 17772031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17782031cd1aSWeston Andros Adamson case SP4_NONE: 17792031cd1aSWeston Andros Adamson break; 17802031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17812031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 17822031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 17832031cd1aSWeston Andros Adamson break; 17842031cd1aSWeston Andros Adamson default: 17852031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 17862031cd1aSWeston Andros Adamson break; 17872031cd1aSWeston Andros Adamson } 1788db8ac8baSWeston Andros Adamson 1789db8ac8baSWeston Andros Adamson if (send_implementation_id && 1790db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1791db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1792d751f748SJim Rees <= sizeof(impl_name) + 1) 1793db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1794db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1795db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1796db8ac8baSWeston Andros Adamson 1797db8ac8baSWeston Andros Adamson if (len > 0) { 17982031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1799db8ac8baSWeston Andros Adamson 1800db8ac8baSWeston Andros Adamson encode_string(xdr, 1801db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1802db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1803db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1804db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1805db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1806db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1807db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1808db8ac8baSWeston Andros Adamson } else 18092031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 181099fe60d0SBenny Halevy } 1811fc931582SAndy Adamson 1812fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1813fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args, 1814fc931582SAndy Adamson struct compound_hdr *hdr) 1815fc931582SAndy Adamson { 1816fc931582SAndy Adamson __be32 *p; 1817fc931582SAndy Adamson struct nfs_client *clp = args->client; 181889f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1819f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18208e0d46e1SMike Sager u32 max_resp_sz_cached; 18218e0d46e1SMike Sager 18228e0d46e1SMike Sager /* 18238e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18248e0d46e1SMike Sager * 2 is the verifier. 18258e0d46e1SMike Sager */ 18268e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 18278e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1828fc931582SAndy Adamson 1829475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 183089f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 183179969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 183279969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1833e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1834fc931582SAndy Adamson 1835fc931582SAndy Adamson /* Fore Channel */ 1836c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1837e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1838e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18398e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1840e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1841e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1842e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1843fc931582SAndy Adamson 1844fc931582SAndy Adamson /* Back Channel */ 1845c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1846e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1847e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1848e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1849e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1850e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1851e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1852fc931582SAndy Adamson 1853e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1854e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1856fc931582SAndy Adamson 1857fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18582f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 185989f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1860e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1861e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 186234558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1863fc931582SAndy Adamson } 18640f3e66c6SAndy Adamson 18650f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 1866fcc85819SChristoph Hellwig const struct nfs4_session *session, 18670f3e66c6SAndy Adamson struct compound_hdr *hdr) 18680f3e66c6SAndy Adamson { 1869475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1870475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18710f3e66c6SAndy Adamson } 187218019753SRicardo Labiaga 187366245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 187466245539STrond Myklebust uint64_t clientid, 187566245539STrond Myklebust struct compound_hdr *hdr) 187666245539STrond Myklebust { 187766245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 187866245539STrond Myklebust encode_uint64(xdr, clientid); 187966245539STrond Myklebust } 188066245539STrond Myklebust 188118019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 1882fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args, 188318019753SRicardo Labiaga struct compound_hdr *hdr) 188418019753SRicardo Labiaga { 1885475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1886475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 188718019753SRicardo Labiaga } 188899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 188999fe60d0SBenny Halevy 18909b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18919b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18929b7b9fccSAndy Adamson struct compound_hdr *hdr) 18939b7b9fccSAndy Adamson { 18949b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18952b2fa717STrond Myklebust struct nfs4_session *session; 1896fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 18972b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1898fc01cea9SAndy Adamson __be32 *p; 18999b7b9fccSAndy Adamson 19002b2fa717STrond Myklebust tp = slot->table; 19012b2fa717STrond Myklebust session = tp->session; 19023bd2384aSChuck Lever if (!session) 19033bd2384aSChuck Lever return; 1904fc01cea9SAndy Adamson 1905475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1906fc01cea9SAndy Adamson 1907fc01cea9SAndy Adamson /* 1908fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1909fc01cea9SAndy Adamson */ 1910fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1911fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1912fc01cea9SAndy Adamson __func__, 1913fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1914fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1915fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1916fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19172b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1918fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1919475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 192093f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1921e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19222b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1923e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 192434558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19259b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19269b7b9fccSAndy Adamson } 19279b7b9fccSAndy Adamson 1928b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1929b1f69b75SAndy Adamson static void 1930b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1931b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1932b1f69b75SAndy Adamson struct compound_hdr *hdr) 1933b1f69b75SAndy Adamson { 1934b1f69b75SAndy Adamson __be32 *p; 1935b1f69b75SAndy Adamson 1936475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 193784c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1938b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1939b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1940b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1941f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 194284c9dee3SChristoph Hellwig 194384c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 194484c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19454e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1946b1f69b75SAndy Adamson } 1947b1f69b75SAndy Adamson 1948b1f69b75SAndy Adamson static void 1949b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1950b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1951b1f69b75SAndy Adamson struct compound_hdr *hdr) 1952b1f69b75SAndy Adamson { 1953b1f69b75SAndy Adamson __be32 *p; 1954b1f69b75SAndy Adamson 1955475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1956475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1957b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1958b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1959b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1960b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1961b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1962b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1963ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1964475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1965b1f69b75SAndy Adamson 1966b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1967b1f69b75SAndy Adamson __func__, 1968b1f69b75SAndy Adamson args->type, 1969b1f69b75SAndy Adamson args->range.iomode, 1970b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1971b1f69b75SAndy Adamson (unsigned long)args->range.length, 1972b1f69b75SAndy Adamson args->maxcount); 1973b1f69b75SAndy Adamson } 1974863a3c6cSAndy Adamson 1975863a3c6cSAndy Adamson static int 1976863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1977ac7db726SBenny Halevy struct inode *inode, 1978fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args, 1979863a3c6cSAndy Adamson struct compound_hdr *hdr) 1980863a3c6cSAndy Adamson { 1981863a3c6cSAndy Adamson __be32 *p; 1982863a3c6cSAndy Adamson 1983863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1984863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1985863a3c6cSAndy Adamson 1986475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1987475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1988863a3c6cSAndy Adamson /* Only whole file layouts */ 1989863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19903557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1991ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1992ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 19932e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 1994ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1995863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1996863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 19972e18d4d8STrond Myklebust } else { 19982e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 19992e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 20002e18d4d8STrond Myklebust } 2001863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2002863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2003ac7db726SBenny Halevy 20045f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 200573504740STrond Myklebust if (args->layoutupdate_pages) 20065f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20075f919c9fSChristoph Hellwig args->layoutupdate_len); 2008863a3c6cSAndy Adamson 2009863a3c6cSAndy Adamson return 0; 2010863a3c6cSAndy Adamson } 2011cbe82603SBenny Halevy 2012cbe82603SBenny Halevy static void 2013cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2014cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2015cbe82603SBenny Halevy struct compound_hdr *hdr) 2016cbe82603SBenny Halevy { 2017cbe82603SBenny Halevy __be32 *p; 2018cbe82603SBenny Halevy 2019475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2020475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2021cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2022cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 202315eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2024cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2025ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 202615eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 202715eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2028cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2029ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2030cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20314d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20324d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 203394e5c571STrond Myklebust else 2034475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2035cbe82603SBenny Halevy } 2036fca78d6dSBryan Schumaker 2037fca78d6dSBryan Schumaker static int 2038fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2039fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2040fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2041fca78d6dSBryan Schumaker { 2042475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2043475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2044fca78d6dSBryan Schumaker return 0; 2045fca78d6dSBryan Schumaker } 20467d974794SBryan Schumaker 20477d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 2048fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args, 20497d974794SBryan Schumaker struct compound_hdr *hdr) 20507d974794SBryan Schumaker { 2051475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2052475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2053ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20547d974794SBryan Schumaker } 20559aeda35fSBryan Schumaker 20569aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 2057fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args, 20589aeda35fSBryan Schumaker struct compound_hdr *hdr) 20599aeda35fSBryan Schumaker { 2060ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20617c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20629aeda35fSBryan Schumaker } 2063cf805165STrond Myklebust #else 2064cf805165STrond Myklebust static inline void 2065cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2066cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2067cf805165STrond Myklebust struct compound_hdr *hdr) 2068cf805165STrond Myklebust { 2069cf805165STrond Myklebust } 2070b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2071b1f69b75SAndy Adamson 20721da177e4SLinus Torvalds /* 20731da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20741da177e4SLinus Torvalds */ 20751da177e4SLinus Torvalds 207666cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 207766cc0429SBenny Halevy { 207866cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 20793bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 20803bd2384aSChuck Lever if (session) 20813bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 208266cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 208366cc0429SBenny Halevy return 0; 208466cc0429SBenny Halevy } 208566cc0429SBenny Halevy 20861da177e4SLinus Torvalds /* 20871da177e4SLinus Torvalds * Encode an ACCESS request 20881da177e4SLinus Torvalds */ 20899f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 2090fcc85819SChristoph Hellwig const void *data) 20911da177e4SLinus Torvalds { 2092fcc85819SChristoph Hellwig const struct nfs4_accessargs *args = data; 20931da177e4SLinus Torvalds struct compound_hdr hdr = { 209466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20951da177e4SLinus Torvalds }; 20961da177e4SLinus Torvalds 20979f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20989f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20999f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21009f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21019f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2102d017931cSAndy Adamson encode_nops(&hdr); 21031da177e4SLinus Torvalds } 21041da177e4SLinus Torvalds 21051da177e4SLinus Torvalds /* 21061da177e4SLinus Torvalds * Encode LOOKUP request 21071da177e4SLinus Torvalds */ 21089f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 2109fcc85819SChristoph Hellwig const void *data) 21101da177e4SLinus Torvalds { 2111fcc85819SChristoph Hellwig const struct nfs4_lookup_arg *args = data; 21121da177e4SLinus Torvalds struct compound_hdr hdr = { 211366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21141da177e4SLinus Torvalds }; 21151da177e4SLinus Torvalds 21169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21189f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21199f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21209f06c719SChuck Lever encode_getfh(xdr, &hdr); 21219f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2122d017931cSAndy Adamson encode_nops(&hdr); 21231da177e4SLinus Torvalds } 21241da177e4SLinus Torvalds 21251da177e4SLinus Torvalds /* 21261da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21271da177e4SLinus Torvalds */ 21289f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21299f06c719SChuck Lever struct xdr_stream *xdr, 2130fcc85819SChristoph Hellwig const void *data) 21311da177e4SLinus Torvalds { 2132fcc85819SChristoph Hellwig const struct nfs4_lookup_root_arg *args = data; 21331da177e4SLinus Torvalds struct compound_hdr hdr = { 213466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21351da177e4SLinus Torvalds }; 21361da177e4SLinus Torvalds 21379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21389f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21399f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21409f06c719SChuck Lever encode_getfh(xdr, &hdr); 21419f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2142d017931cSAndy Adamson encode_nops(&hdr); 21431da177e4SLinus Torvalds } 21441da177e4SLinus Torvalds 21451da177e4SLinus Torvalds /* 21461da177e4SLinus Torvalds * Encode REMOVE request 21471da177e4SLinus Torvalds */ 21489f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 2149fcc85819SChristoph Hellwig const void *data) 21501da177e4SLinus Torvalds { 2151fcc85819SChristoph Hellwig const struct nfs_removeargs *args = data; 21521da177e4SLinus Torvalds struct compound_hdr hdr = { 215366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21541da177e4SLinus Torvalds }; 21551da177e4SLinus Torvalds 21569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21579f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21589f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21599f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2160d017931cSAndy Adamson encode_nops(&hdr); 21611da177e4SLinus Torvalds } 21621da177e4SLinus Torvalds 21631da177e4SLinus Torvalds /* 21641da177e4SLinus Torvalds * Encode RENAME request 21651da177e4SLinus Torvalds */ 21669f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 2167fcc85819SChristoph Hellwig const void *data) 21681da177e4SLinus Torvalds { 2169fcc85819SChristoph Hellwig const struct nfs_renameargs *args = data; 21701da177e4SLinus Torvalds struct compound_hdr hdr = { 217166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21721da177e4SLinus Torvalds }; 21731da177e4SLinus Torvalds 21749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21769f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21779f06c719SChuck Lever encode_savefh(xdr, &hdr); 21789f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21799f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2180d017931cSAndy Adamson encode_nops(&hdr); 21811da177e4SLinus Torvalds } 21821da177e4SLinus Torvalds 21831da177e4SLinus Torvalds /* 21841da177e4SLinus Torvalds * Encode LINK request 21851da177e4SLinus Torvalds */ 21869f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 2187fcc85819SChristoph Hellwig const void *data) 21881da177e4SLinus Torvalds { 2189fcc85819SChristoph Hellwig const struct nfs4_link_arg *args = data; 21901da177e4SLinus Torvalds struct compound_hdr hdr = { 219166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21921da177e4SLinus Torvalds }; 21931da177e4SLinus Torvalds 21949f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21959f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21969f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21979f06c719SChuck Lever encode_savefh(xdr, &hdr); 21989f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21999f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22009f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22019f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2202d017931cSAndy Adamson encode_nops(&hdr); 22031da177e4SLinus Torvalds } 22041da177e4SLinus Torvalds 22051da177e4SLinus Torvalds /* 22061da177e4SLinus Torvalds * Encode CREATE request 22071da177e4SLinus Torvalds */ 22089f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 2209fcc85819SChristoph Hellwig const void *data) 22101da177e4SLinus Torvalds { 2211fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 22121da177e4SLinus Torvalds struct compound_hdr hdr = { 221366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22141da177e4SLinus Torvalds }; 22151da177e4SLinus Torvalds 22169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22189f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22199f06c719SChuck Lever encode_create(xdr, args, &hdr); 22209f06c719SChuck Lever encode_getfh(xdr, &hdr); 22219f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2222d017931cSAndy Adamson encode_nops(&hdr); 22231da177e4SLinus Torvalds } 22241da177e4SLinus Torvalds 22251da177e4SLinus Torvalds /* 22261da177e4SLinus Torvalds * Encode SYMLINK request 22271da177e4SLinus Torvalds */ 22289f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2229fcc85819SChristoph Hellwig const void *data) 22301da177e4SLinus Torvalds { 2231fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 2232fcc85819SChristoph Hellwig 22339f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22341da177e4SLinus Torvalds } 22351da177e4SLinus Torvalds 22361da177e4SLinus Torvalds /* 22371da177e4SLinus Torvalds * Encode GETATTR request 22381da177e4SLinus Torvalds */ 22399f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2240fcc85819SChristoph Hellwig const void *data) 22411da177e4SLinus Torvalds { 2242fcc85819SChristoph Hellwig const struct nfs4_getattr_arg *args = data; 22431da177e4SLinus Torvalds struct compound_hdr hdr = { 224466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22451da177e4SLinus Torvalds }; 22461da177e4SLinus Torvalds 22479f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22489f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22499f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22509f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2251d017931cSAndy Adamson encode_nops(&hdr); 22521da177e4SLinus Torvalds } 22531da177e4SLinus Torvalds 22541da177e4SLinus Torvalds /* 22551da177e4SLinus Torvalds * Encode a CLOSE request 22561da177e4SLinus Torvalds */ 22579f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 2258fcc85819SChristoph Hellwig const void *data) 22591da177e4SLinus Torvalds { 2260fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 22611da177e4SLinus Torvalds struct compound_hdr hdr = { 226266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22631da177e4SLinus Torvalds }; 22641da177e4SLinus Torvalds 22659f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22669f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22679f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2268cf805165STrond Myklebust if (args->lr_args) 2269cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 22703ecefc92STrond Myklebust if (args->bitmask != NULL) 22719f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2272d8d84983STrond Myklebust encode_close(xdr, args, &hdr); 2273d017931cSAndy Adamson encode_nops(&hdr); 22741da177e4SLinus Torvalds } 22751da177e4SLinus Torvalds 22761da177e4SLinus Torvalds /* 22771da177e4SLinus Torvalds * Encode an OPEN request 22781da177e4SLinus Torvalds */ 22799f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 2280fcc85819SChristoph Hellwig const void *data) 22811da177e4SLinus Torvalds { 2282fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 22831da177e4SLinus Torvalds struct compound_hdr hdr = { 228466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22851da177e4SLinus Torvalds }; 22861da177e4SLinus Torvalds 22879f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22889f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22899f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22909f06c719SChuck Lever encode_open(xdr, args, &hdr); 22919f06c719SChuck Lever encode_getfh(xdr, &hdr); 2292ae2bb032SWeston Andros Adamson if (args->access) 22936168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 22941549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2295d017931cSAndy Adamson encode_nops(&hdr); 22961da177e4SLinus Torvalds } 22971da177e4SLinus Torvalds 22981da177e4SLinus Torvalds /* 22991da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 23001da177e4SLinus Torvalds */ 23019f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 23029f06c719SChuck Lever struct xdr_stream *xdr, 2303fcc85819SChristoph Hellwig const void *data) 23041da177e4SLinus Torvalds { 2305fcc85819SChristoph Hellwig const struct nfs_open_confirmargs *args = data; 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, 2321fcc85819SChristoph Hellwig const void *data) 23221da177e4SLinus Torvalds { 2323fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23241da177e4SLinus Torvalds struct compound_hdr hdr = { 232566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23261da177e4SLinus Torvalds }; 23271da177e4SLinus Torvalds 23289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23299f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23309f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23319f06c719SChuck Lever encode_open(xdr, args, &hdr); 2332ae2bb032SWeston Andros Adamson if (args->access) 23336168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2334e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2335d017931cSAndy Adamson encode_nops(&hdr); 23361da177e4SLinus Torvalds } 23371da177e4SLinus Torvalds 23381da177e4SLinus Torvalds /* 23391da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23401da177e4SLinus Torvalds */ 23419f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23429f06c719SChuck Lever struct xdr_stream *xdr, 2343fcc85819SChristoph Hellwig const void *data) 23441da177e4SLinus Torvalds { 2345fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 23461da177e4SLinus Torvalds struct compound_hdr hdr = { 234766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23481da177e4SLinus Torvalds }; 23491da177e4SLinus Torvalds 23509f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23519f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23529f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2353b6808145STrond Myklebust if (args->lr_args) 2354b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23559f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2356d017931cSAndy Adamson encode_nops(&hdr); 23571da177e4SLinus Torvalds } 23581da177e4SLinus Torvalds 23591da177e4SLinus Torvalds /* 23601da177e4SLinus Torvalds * Encode a LOCK request 23611da177e4SLinus Torvalds */ 23629f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 2363fcc85819SChristoph Hellwig const void *data) 23641da177e4SLinus Torvalds { 2365fcc85819SChristoph Hellwig const struct nfs_lock_args *args = data; 23661da177e4SLinus Torvalds struct compound_hdr hdr = { 236766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23681da177e4SLinus Torvalds }; 23691da177e4SLinus Torvalds 23709f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23719f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23729f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23739f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2374d017931cSAndy Adamson encode_nops(&hdr); 23751da177e4SLinus Torvalds } 23761da177e4SLinus Torvalds 23771da177e4SLinus Torvalds /* 23781da177e4SLinus Torvalds * Encode a LOCKT request 23791da177e4SLinus Torvalds */ 23809f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 2381fcc85819SChristoph Hellwig const void *data) 23821da177e4SLinus Torvalds { 2383fcc85819SChristoph Hellwig const struct nfs_lockt_args *args = data; 23841da177e4SLinus Torvalds struct compound_hdr hdr = { 238566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23861da177e4SLinus Torvalds }; 23871da177e4SLinus Torvalds 23889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23899f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23909f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23919f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2392d017931cSAndy Adamson encode_nops(&hdr); 23931da177e4SLinus Torvalds } 23941da177e4SLinus Torvalds 23951da177e4SLinus Torvalds /* 23961da177e4SLinus Torvalds * Encode a LOCKU request 23971da177e4SLinus Torvalds */ 23989f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 2399fcc85819SChristoph Hellwig const void *data) 24001da177e4SLinus Torvalds { 2401fcc85819SChristoph Hellwig const struct nfs_locku_args *args = data; 24021da177e4SLinus Torvalds struct compound_hdr hdr = { 240366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24041da177e4SLinus Torvalds }; 24051da177e4SLinus Torvalds 24069f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24079f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24089f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24099f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2410d017931cSAndy Adamson encode_nops(&hdr); 24111da177e4SLinus Torvalds } 24121da177e4SLinus Torvalds 24139f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24149f06c719SChuck Lever struct xdr_stream *xdr, 2415fcc85819SChristoph Hellwig const void *data) 2416d3c7b7ccSTrond Myklebust { 2417fcc85819SChristoph Hellwig const struct nfs_release_lockowner_args *args = data; 2418d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2419d3c7b7ccSTrond Myklebust .minorversion = 0, 2420d3c7b7ccSTrond Myklebust }; 2421d3c7b7ccSTrond Myklebust 24229f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24239f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2424d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2425d3c7b7ccSTrond Myklebust } 2426d3c7b7ccSTrond Myklebust 24271da177e4SLinus Torvalds /* 24281da177e4SLinus Torvalds * Encode a READLINK request 24291da177e4SLinus Torvalds */ 24309f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2431fcc85819SChristoph Hellwig const void *data) 24321da177e4SLinus Torvalds { 2433fcc85819SChristoph Hellwig const struct nfs4_readlink *args = data; 24341da177e4SLinus Torvalds struct compound_hdr hdr = { 243566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24361da177e4SLinus Torvalds }; 24371da177e4SLinus Torvalds 24389f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24399f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24409f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24419f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2442e3a535e1STrond Myklebust 244328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2444e3a535e1STrond Myklebust args->pgbase, args->pglen); 2445d017931cSAndy Adamson encode_nops(&hdr); 24461da177e4SLinus Torvalds } 24471da177e4SLinus Torvalds 24481da177e4SLinus Torvalds /* 24491da177e4SLinus Torvalds * Encode a READDIR request 24501da177e4SLinus Torvalds */ 24519f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 2452fcc85819SChristoph Hellwig const void *data) 24531da177e4SLinus Torvalds { 2454fcc85819SChristoph Hellwig const struct nfs4_readdir_arg *args = data; 24551da177e4SLinus Torvalds struct compound_hdr hdr = { 245666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24571da177e4SLinus Torvalds }; 24581da177e4SLinus Torvalds 24599f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24609f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24619f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24629f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2463d6ac02dfSTrond Myklebust 246428f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2465d6ac02dfSTrond Myklebust args->pgbase, args->count); 2466d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 246728f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2468d6ac02dfSTrond Myklebust args->pgbase, args->count); 2469d017931cSAndy Adamson encode_nops(&hdr); 24701da177e4SLinus Torvalds } 24711da177e4SLinus Torvalds 24721da177e4SLinus Torvalds /* 24731da177e4SLinus Torvalds * Encode a READ request 24741da177e4SLinus Torvalds */ 24759f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 2476fcc85819SChristoph Hellwig const void *data) 24771da177e4SLinus Torvalds { 2478fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 24791da177e4SLinus Torvalds struct compound_hdr hdr = { 248066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24811da177e4SLinus Torvalds }; 24821da177e4SLinus Torvalds 24839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24849f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24859f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24869f06c719SChuck Lever encode_read(xdr, args, &hdr); 24871da177e4SLinus Torvalds 248828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 24891da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 24904f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2491d017931cSAndy Adamson encode_nops(&hdr); 24921da177e4SLinus Torvalds } 24931da177e4SLinus Torvalds 24941da177e4SLinus Torvalds /* 24951da177e4SLinus Torvalds * Encode an SETATTR request 24961da177e4SLinus Torvalds */ 24979f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2498fcc85819SChristoph Hellwig const void *data) 24991da177e4SLinus Torvalds { 2500fcc85819SChristoph Hellwig const struct nfs_setattrargs *args = data; 25011da177e4SLinus Torvalds struct compound_hdr hdr = { 250266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25031da177e4SLinus Torvalds }; 25041da177e4SLinus Torvalds 25059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25089f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 25099f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2510d017931cSAndy Adamson encode_nops(&hdr); 25111da177e4SLinus Torvalds } 25121da177e4SLinus Torvalds 25131da177e4SLinus Torvalds /* 2514029d105eSJ. Bruce Fields * Encode a GETACL request 2515029d105eSJ. Bruce Fields */ 25169f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2517fcc85819SChristoph Hellwig const void *data) 2518029d105eSJ. Bruce Fields { 2519fcc85819SChristoph Hellwig const struct nfs_getaclargs *args = data; 2520029d105eSJ. Bruce Fields struct compound_hdr hdr = { 252166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2522029d105eSJ. Bruce Fields }; 252328f56694SBenny Halevy uint32_t replen; 2524029d105eSJ. Bruce Fields 25259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25279f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25286682c14bSJ. Bruce Fields replen = hdr.replen + op_decode_hdr_maxsz; 25299f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2530cf8cdbe5SAndy Adamson 253128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 25328fbcf237SAndreas Gruenbacher args->acl_pages, 0, args->acl_len); 2533bf118a34SAndy Adamson 2534d017931cSAndy Adamson encode_nops(&hdr); 2535029d105eSJ. Bruce Fields } 2536029d105eSJ. Bruce Fields 2537029d105eSJ. Bruce Fields /* 25381da177e4SLinus Torvalds * Encode a WRITE request 25391da177e4SLinus Torvalds */ 25409f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 2541fcc85819SChristoph Hellwig const void *data) 25421da177e4SLinus Torvalds { 2543fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 25441da177e4SLinus Torvalds struct compound_hdr hdr = { 254566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25461da177e4SLinus Torvalds }; 25471da177e4SLinus Torvalds 25489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25499f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25509f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25519f06c719SChuck Lever encode_write(xdr, args, &hdr); 25524f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25537ffd1064SFred Isaman if (args->bitmask) 25549f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2555d017931cSAndy Adamson encode_nops(&hdr); 25561da177e4SLinus Torvalds } 25571da177e4SLinus Torvalds 25581da177e4SLinus Torvalds /* 25591da177e4SLinus Torvalds * a COMMIT request 25601da177e4SLinus Torvalds */ 25619f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 2562fcc85819SChristoph Hellwig const void *data) 25631da177e4SLinus Torvalds { 2564fcc85819SChristoph Hellwig const struct nfs_commitargs *args = data; 25651da177e4SLinus Torvalds struct compound_hdr hdr = { 256666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25671da177e4SLinus Torvalds }; 25681da177e4SLinus Torvalds 25699f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25709f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25719f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25729f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2573d017931cSAndy Adamson encode_nops(&hdr); 25741da177e4SLinus Torvalds } 25751da177e4SLinus Torvalds 25761da177e4SLinus Torvalds /* 25771da177e4SLinus Torvalds * FSINFO request 25781da177e4SLinus Torvalds */ 25799f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 2580fcc85819SChristoph Hellwig const void *data) 25811da177e4SLinus Torvalds { 2582fcc85819SChristoph Hellwig const struct nfs4_fsinfo_arg *args = data; 25831da177e4SLinus Torvalds struct compound_hdr hdr = { 258466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25851da177e4SLinus Torvalds }; 25861da177e4SLinus Torvalds 25879f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25889f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25899f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25909f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2591d017931cSAndy Adamson encode_nops(&hdr); 25921da177e4SLinus Torvalds } 25931da177e4SLinus Torvalds 25941da177e4SLinus Torvalds /* 25951da177e4SLinus Torvalds * a PATHCONF request 25961da177e4SLinus Torvalds */ 25979f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 2598fcc85819SChristoph Hellwig const void *data) 25991da177e4SLinus Torvalds { 2600fcc85819SChristoph Hellwig const struct nfs4_pathconf_arg *args = data; 26011da177e4SLinus Torvalds struct compound_hdr hdr = { 260266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26031da177e4SLinus Torvalds }; 26041da177e4SLinus Torvalds 26059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26089f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2609d017931cSAndy Adamson &hdr); 2610d017931cSAndy Adamson encode_nops(&hdr); 26111da177e4SLinus Torvalds } 26121da177e4SLinus Torvalds 26131da177e4SLinus Torvalds /* 26141da177e4SLinus Torvalds * a STATFS request 26151da177e4SLinus Torvalds */ 26169f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 2617fcc85819SChristoph Hellwig const void *data) 26181da177e4SLinus Torvalds { 2619fcc85819SChristoph Hellwig const struct nfs4_statfs_arg *args = data; 26201da177e4SLinus Torvalds struct compound_hdr hdr = { 262166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26221da177e4SLinus Torvalds }; 26231da177e4SLinus Torvalds 26249f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26259f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26269f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26279f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2628d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2629d017931cSAndy Adamson encode_nops(&hdr); 26301da177e4SLinus Torvalds } 26311da177e4SLinus Torvalds 26321da177e4SLinus Torvalds /* 26331da177e4SLinus Torvalds * GETATTR_BITMAP request 26341da177e4SLinus Torvalds */ 26359f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26369f06c719SChuck Lever struct xdr_stream *xdr, 2637fcc85819SChristoph Hellwig const void *data) 26381da177e4SLinus Torvalds { 2639fcc85819SChristoph Hellwig const struct nfs4_server_caps_arg *args = data; 26408c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 26411da177e4SLinus Torvalds struct compound_hdr hdr = { 264266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26431da177e4SLinus Torvalds }; 26441da177e4SLinus Torvalds 26459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26479f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26488c61282fSKinglong Mee encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr); 2649d017931cSAndy Adamson encode_nops(&hdr); 26501da177e4SLinus Torvalds } 26511da177e4SLinus Torvalds 26521da177e4SLinus Torvalds /* 26531da177e4SLinus Torvalds * a RENEW request 26541da177e4SLinus Torvalds */ 26559f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 2656fcc85819SChristoph Hellwig const void *data) 2657fcc85819SChristoph Hellwig 26581da177e4SLinus Torvalds { 2659fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 26601da177e4SLinus Torvalds struct compound_hdr hdr = { 2661d017931cSAndy Adamson .nops = 0, 26621da177e4SLinus Torvalds }; 26631da177e4SLinus Torvalds 26649f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2665bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2666d017931cSAndy Adamson encode_nops(&hdr); 26671da177e4SLinus Torvalds } 26681da177e4SLinus Torvalds 26691da177e4SLinus Torvalds /* 26701da177e4SLinus Torvalds * a SETCLIENTID request 26711da177e4SLinus Torvalds */ 26729f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 26739f06c719SChuck Lever struct xdr_stream *xdr, 2674fcc85819SChristoph Hellwig const void *data) 26751da177e4SLinus Torvalds { 2676fcc85819SChristoph Hellwig const struct nfs4_setclientid *sc = data; 26771da177e4SLinus Torvalds struct compound_hdr hdr = { 2678d017931cSAndy Adamson .nops = 0, 26791da177e4SLinus Torvalds }; 26801da177e4SLinus Torvalds 26819f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26829f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2683d017931cSAndy Adamson encode_nops(&hdr); 26841da177e4SLinus Torvalds } 26851da177e4SLinus Torvalds 26861da177e4SLinus Torvalds /* 26871da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 26881da177e4SLinus Torvalds */ 26899f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 26909f06c719SChuck Lever struct xdr_stream *xdr, 2691fcc85819SChristoph Hellwig const void *data) 26921da177e4SLinus Torvalds { 2693fcc85819SChristoph Hellwig const struct nfs4_setclientid_res *arg = data; 26941da177e4SLinus Torvalds struct compound_hdr hdr = { 2695d017931cSAndy Adamson .nops = 0, 26961da177e4SLinus Torvalds }; 26971da177e4SLinus Torvalds 26989f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26999f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2700d017931cSAndy Adamson encode_nops(&hdr); 27011da177e4SLinus Torvalds } 27021da177e4SLinus Torvalds 27031da177e4SLinus Torvalds /* 27041da177e4SLinus Torvalds * DELEGRETURN request 27051da177e4SLinus Torvalds */ 27069f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 27079f06c719SChuck Lever struct xdr_stream *xdr, 2708fcc85819SChristoph Hellwig const void *data) 27091da177e4SLinus Torvalds { 2710fcc85819SChristoph Hellwig const struct nfs4_delegreturnargs *args = data; 27111da177e4SLinus Torvalds struct compound_hdr hdr = { 271266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27131da177e4SLinus Torvalds }; 27141da177e4SLinus Torvalds 27159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27169f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27179f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2718586f1c39STrond Myklebust if (args->lr_args) 2719586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 27208ac2b422STrond Myklebust if (args->bitmask) 27219f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2722e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2723d017931cSAndy Adamson encode_nops(&hdr); 27241da177e4SLinus Torvalds } 27251da177e4SLinus Torvalds 27261da177e4SLinus Torvalds /* 2727683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2728683b57b4STrond Myklebust */ 27299f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27309f06c719SChuck Lever struct xdr_stream *xdr, 2731fcc85819SChristoph Hellwig const void *data) 2732683b57b4STrond Myklebust { 2733fcc85819SChristoph Hellwig const struct nfs4_fs_locations_arg *args = data; 2734683b57b4STrond Myklebust struct compound_hdr hdr = { 273566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2736683b57b4STrond Myklebust }; 273728f56694SBenny Halevy uint32_t replen; 2738683b57b4STrond Myklebust 27399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2741b03d735bSChuck Lever if (args->migration) { 2742b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2743b03d735bSChuck Lever replen = hdr.replen; 2744b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2745b03d735bSChuck Lever if (args->renew) 2746b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2747b03d735bSChuck Lever } else { 27489f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 27499f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2750b03d735bSChuck Lever replen = hdr.replen; 27519f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2752b03d735bSChuck Lever } 2753cf8cdbe5SAndy Adamson 2754b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 2755fcc85819SChristoph Hellwig xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2756fcc85819SChristoph Hellwig (struct page **)&args->page, 0, PAGE_SIZE); 2757d017931cSAndy Adamson encode_nops(&hdr); 2758683b57b4STrond Myklebust } 2759683b57b4STrond Myklebust 27605a5ea0d4SBryan Schumaker /* 27615a5ea0d4SBryan Schumaker * Encode SECINFO request 27625a5ea0d4SBryan Schumaker */ 27635a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 27645a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 2765fcc85819SChristoph Hellwig const void *data) 27665a5ea0d4SBryan Schumaker { 2767fcc85819SChristoph Hellwig const struct nfs4_secinfo_arg *args = data; 27685a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 27695a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27705a5ea0d4SBryan Schumaker }; 27715a5ea0d4SBryan Schumaker 27725a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 27735a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 27745a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 27755a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 27765a5ea0d4SBryan Schumaker encode_nops(&hdr); 27775a5ea0d4SBryan Schumaker } 27785a5ea0d4SBryan Schumaker 277944c99933SChuck Lever /* 278044c99933SChuck Lever * Encode FSID_PRESENT request 278144c99933SChuck Lever */ 278244c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 278344c99933SChuck Lever struct xdr_stream *xdr, 2784fcc85819SChristoph Hellwig const void *data) 278544c99933SChuck Lever { 2786fcc85819SChristoph Hellwig const struct nfs4_fsid_present_arg *args = data; 278744c99933SChuck Lever struct compound_hdr hdr = { 278844c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 278944c99933SChuck Lever }; 279044c99933SChuck Lever 279144c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 279244c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 279344c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 279444c99933SChuck Lever encode_getfh(xdr, &hdr); 279544c99933SChuck Lever if (args->renew) 279644c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 279744c99933SChuck Lever encode_nops(&hdr); 279844c99933SChuck Lever } 279944c99933SChuck Lever 280099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 280199fe60d0SBenny Halevy /* 28027c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 28037c44f1aeSWeston Andros Adamson */ 28047c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 28057c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 2806fcc85819SChristoph Hellwig const void *data) 28077c44f1aeSWeston Andros Adamson { 2808fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args = data; 28097c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 281071a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 28117c44f1aeSWeston Andros Adamson }; 28127c44f1aeSWeston Andros Adamson 28137c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 281471a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 28157c44f1aeSWeston Andros Adamson encode_nops(&hdr); 28167c44f1aeSWeston Andros Adamson } 28177c44f1aeSWeston Andros Adamson 28187c44f1aeSWeston Andros Adamson /* 281999fe60d0SBenny Halevy * EXCHANGE_ID request 282099fe60d0SBenny Halevy */ 28219f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 28229f06c719SChuck Lever struct xdr_stream *xdr, 2823fcc85819SChristoph Hellwig const void *data) 282499fe60d0SBenny Halevy { 2825fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args = data; 282699fe60d0SBenny Halevy struct compound_hdr hdr = { 2827a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 282899fe60d0SBenny Halevy }; 282999fe60d0SBenny Halevy 28309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28319f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 283299fe60d0SBenny Halevy encode_nops(&hdr); 283399fe60d0SBenny Halevy } 28342050f0ccSAndy Adamson 28352050f0ccSAndy Adamson /* 2836fc931582SAndy Adamson * a CREATE_SESSION request 2837fc931582SAndy Adamson */ 28389f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28399f06c719SChuck Lever struct xdr_stream *xdr, 2840fcc85819SChristoph Hellwig const void *data) 2841fc931582SAndy Adamson { 2842fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args = data; 2843fc931582SAndy Adamson struct compound_hdr hdr = { 2844a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2845fc931582SAndy Adamson }; 2846fc931582SAndy Adamson 28479f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28489f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2849fc931582SAndy Adamson encode_nops(&hdr); 2850fc931582SAndy Adamson } 2851fc931582SAndy Adamson 2852fc931582SAndy Adamson /* 28530f3e66c6SAndy Adamson * a DESTROY_SESSION request 28540f3e66c6SAndy Adamson */ 28559f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 28569f06c719SChuck Lever struct xdr_stream *xdr, 2857fcc85819SChristoph Hellwig const void *data) 28580f3e66c6SAndy Adamson { 2859fcc85819SChristoph Hellwig const struct nfs4_session *session = data; 28600f3e66c6SAndy Adamson struct compound_hdr hdr = { 2861a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 28620f3e66c6SAndy Adamson }; 28630f3e66c6SAndy Adamson 28649f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28659f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 28660f3e66c6SAndy Adamson encode_nops(&hdr); 28670f3e66c6SAndy Adamson } 28680f3e66c6SAndy Adamson 28690f3e66c6SAndy Adamson /* 287066245539STrond Myklebust * a DESTROY_CLIENTID request 287166245539STrond Myklebust */ 287266245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 287366245539STrond Myklebust struct xdr_stream *xdr, 2874fcc85819SChristoph Hellwig const void *data) 287566245539STrond Myklebust { 2876fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 287766245539STrond Myklebust struct compound_hdr hdr = { 287866245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 287966245539STrond Myklebust }; 288066245539STrond Myklebust 288166245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 288266245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 288366245539STrond Myklebust encode_nops(&hdr); 288466245539STrond Myklebust } 288566245539STrond Myklebust 288666245539STrond Myklebust /* 2887fc01cea9SAndy Adamson * a SEQUENCE request 2888fc01cea9SAndy Adamson */ 28899f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2890fcc85819SChristoph Hellwig const void *data) 2891fc01cea9SAndy Adamson { 2892fcc85819SChristoph Hellwig const struct nfs4_sequence_args *args = data; 2893fc01cea9SAndy Adamson struct compound_hdr hdr = { 2894fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2895fc01cea9SAndy Adamson }; 2896fc01cea9SAndy Adamson 28979f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28989f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2899fc01cea9SAndy Adamson encode_nops(&hdr); 2900fc01cea9SAndy Adamson } 2901fc01cea9SAndy Adamson 2902fc01cea9SAndy Adamson /* 29032050f0ccSAndy Adamson * a GET_LEASE_TIME request 29042050f0ccSAndy Adamson */ 29059f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 29069f06c719SChuck Lever struct xdr_stream *xdr, 2907fcc85819SChristoph Hellwig const void *data) 29082050f0ccSAndy Adamson { 2909fcc85819SChristoph Hellwig const struct nfs4_get_lease_time_args *args = data; 29102050f0ccSAndy Adamson struct compound_hdr hdr = { 29112050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 29122050f0ccSAndy Adamson }; 2913dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 29142050f0ccSAndy Adamson 29159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29169f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 29179f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 29189f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 29192050f0ccSAndy Adamson encode_nops(&hdr); 29202050f0ccSAndy Adamson } 292118019753SRicardo Labiaga 292218019753SRicardo Labiaga /* 292318019753SRicardo Labiaga * a RECLAIM_COMPLETE request 292418019753SRicardo Labiaga */ 29259f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 29269f06c719SChuck Lever struct xdr_stream *xdr, 2927fcc85819SChristoph Hellwig const void *data) 292818019753SRicardo Labiaga { 2929fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args = data; 293018019753SRicardo Labiaga struct compound_hdr hdr = { 293118019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 293218019753SRicardo Labiaga }; 293318019753SRicardo Labiaga 29349f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29359f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29369f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 293718019753SRicardo Labiaga encode_nops(&hdr); 293818019753SRicardo Labiaga } 293918019753SRicardo Labiaga 2940b1f69b75SAndy Adamson /* 2941b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2942b1f69b75SAndy Adamson */ 29439f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 29449f06c719SChuck Lever struct xdr_stream *xdr, 2945fcc85819SChristoph Hellwig const void *data) 2946b1f69b75SAndy Adamson { 2947fcc85819SChristoph Hellwig const struct nfs4_getdeviceinfo_args *args = data; 2948b1f69b75SAndy Adamson struct compound_hdr hdr = { 2949b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2950b1f69b75SAndy Adamson }; 2951b1f69b75SAndy Adamson 29529f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29539f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29549f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2955b1f69b75SAndy Adamson 2956b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2957b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2958b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2959b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2960b1f69b75SAndy Adamson args->pdev->pglen); 2961b1f69b75SAndy Adamson 2962b1f69b75SAndy Adamson encode_nops(&hdr); 2963b1f69b75SAndy Adamson } 2964b1f69b75SAndy Adamson 2965b1f69b75SAndy Adamson /* 2966b1f69b75SAndy Adamson * Encode LAYOUTGET request 2967b1f69b75SAndy Adamson */ 29689f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 29699f06c719SChuck Lever struct xdr_stream *xdr, 2970fcc85819SChristoph Hellwig const void *data) 2971b1f69b75SAndy Adamson { 2972fcc85819SChristoph Hellwig const struct nfs4_layoutget_args *args = data; 2973b1f69b75SAndy Adamson struct compound_hdr hdr = { 2974b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2975b1f69b75SAndy Adamson }; 2976b1f69b75SAndy Adamson 29779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29789f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29799f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 29809f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 298135124a09SWeston Andros Adamson 298235124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 298335124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 298435124a09SWeston Andros Adamson 2985b1f69b75SAndy Adamson encode_nops(&hdr); 2986b1f69b75SAndy Adamson } 2987863a3c6cSAndy Adamson 2988863a3c6cSAndy Adamson /* 2989863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2990863a3c6cSAndy Adamson */ 2991cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2992863a3c6cSAndy Adamson struct xdr_stream *xdr, 2993fcc85819SChristoph Hellwig const void *priv) 2994863a3c6cSAndy Adamson { 2995fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args = priv; 2996ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2997ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2998863a3c6cSAndy Adamson struct compound_hdr hdr = { 2999863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3000863a3c6cSAndy Adamson }; 3001863a3c6cSAndy Adamson 3002863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 3003863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 3004863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3005ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 3006863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 3007863a3c6cSAndy Adamson encode_nops(&hdr); 3008cbe82603SBenny Halevy } 3009cbe82603SBenny Halevy 3010cbe82603SBenny Halevy /* 3011cbe82603SBenny Halevy * Encode LAYOUTRETURN request 3012cbe82603SBenny Halevy */ 3013cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 3014cbe82603SBenny Halevy struct xdr_stream *xdr, 3015fcc85819SChristoph Hellwig const void *data) 3016cbe82603SBenny Halevy { 3017fcc85819SChristoph Hellwig const struct nfs4_layoutreturn_args *args = data; 3018cbe82603SBenny Halevy struct compound_hdr hdr = { 3019cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3020cbe82603SBenny Halevy }; 3021cbe82603SBenny Halevy 3022cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 3023cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 3024cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3025cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 3026cbe82603SBenny Halevy encode_nops(&hdr); 3027863a3c6cSAndy Adamson } 3028fca78d6dSBryan Schumaker 3029fca78d6dSBryan Schumaker /* 3030fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 3031fca78d6dSBryan Schumaker */ 3032fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 3033fca78d6dSBryan Schumaker struct xdr_stream *xdr, 3034fcc85819SChristoph Hellwig const void *data) 3035fca78d6dSBryan Schumaker { 3036fcc85819SChristoph Hellwig const struct nfs41_secinfo_no_name_args *args = data; 3037fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3038fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3039fca78d6dSBryan Schumaker }; 3040fca78d6dSBryan Schumaker 3041fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3042fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3043fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3044fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3045fca78d6dSBryan Schumaker encode_nops(&hdr); 3046fca78d6dSBryan Schumaker } 30477d974794SBryan Schumaker 30487d974794SBryan Schumaker /* 30497d974794SBryan Schumaker * Encode TEST_STATEID request 30507d974794SBryan Schumaker */ 30517d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 30527d974794SBryan Schumaker struct xdr_stream *xdr, 3053fcc85819SChristoph Hellwig const void *data) 30547d974794SBryan Schumaker { 3055fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args = data; 30567d974794SBryan Schumaker struct compound_hdr hdr = { 30577d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30587d974794SBryan Schumaker }; 30597d974794SBryan Schumaker 30607d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30617d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30627d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 30637d974794SBryan Schumaker encode_nops(&hdr); 30647d974794SBryan Schumaker } 30659aeda35fSBryan Schumaker 30669aeda35fSBryan Schumaker /* 30679aeda35fSBryan Schumaker * Encode FREE_STATEID request 30689aeda35fSBryan Schumaker */ 30699aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 30709aeda35fSBryan Schumaker struct xdr_stream *xdr, 3071fcc85819SChristoph Hellwig const void *data) 30729aeda35fSBryan Schumaker { 3073fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args = data; 30749aeda35fSBryan Schumaker struct compound_hdr hdr = { 30759aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30769aeda35fSBryan Schumaker }; 30779aeda35fSBryan Schumaker 30789aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30799aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30809aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 30819aeda35fSBryan Schumaker encode_nops(&hdr); 30829aeda35fSBryan Schumaker } 308399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 308499fe60d0SBenny Halevy 3085686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3086686841b3SBenny Halevy { 3087686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3088686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3089686841b3SBenny Halevy func, xdr->end - xdr->p); 3090686841b3SBenny Halevy } 30911da177e4SLinus Torvalds 3092683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 30931da177e4SLinus Torvalds { 30946da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, 30956da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT); 30966da59ce2STrond Myklebust if (unlikely(ret < 0)) { 30976da59ce2STrond Myklebust if (ret == -EBADMSG) 3098c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3099c0eae66eSBenny Halevy return -EIO; 31001da177e4SLinus Torvalds } 31016da59ce2STrond Myklebust *len = ret; 31026da59ce2STrond Myklebust return 0; 31036da59ce2STrond Myklebust } 31041da177e4SLinus Torvalds 31051da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 31061da177e4SLinus Torvalds { 31078687b63aSAl Viro __be32 *p; 31081da177e4SLinus Torvalds 3109c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3110c0eae66eSBenny Halevy if (unlikely(!p)) 3111c0eae66eSBenny Halevy goto out_overflow; 31126f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3113cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 31141da177e4SLinus Torvalds 3115c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3116c0eae66eSBenny Halevy if (unlikely(!p)) 3117c0eae66eSBenny Halevy goto out_overflow; 31181da177e4SLinus Torvalds hdr->tag = (char *)p; 31191da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3120cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3121aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3122aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 31231da177e4SLinus Torvalds return 0; 3124c0eae66eSBenny Halevy out_overflow: 3125c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3126c0eae66eSBenny Halevy return -EIO; 31271da177e4SLinus Torvalds } 31281da177e4SLinus Torvalds 3129c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3130c7848f69STrond Myklebust int *nfs_retval) 31311da177e4SLinus Torvalds { 31328687b63aSAl Viro __be32 *p; 31331da177e4SLinus Torvalds uint32_t opnum; 31341da177e4SLinus Torvalds int32_t nfserr; 31351da177e4SLinus Torvalds 3136c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3137c0eae66eSBenny Halevy if (unlikely(!p)) 3138c0eae66eSBenny Halevy goto out_overflow; 31396f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3140c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3141c7848f69STrond Myklebust goto out_bad_operation; 3142c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3143c7848f69STrond Myklebust if (nfserr == NFS_OK) 3144c7848f69STrond Myklebust *nfs_retval = 0; 3145c7848f69STrond Myklebust else 3146c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3147c7848f69STrond Myklebust return true; 3148c7848f69STrond Myklebust out_bad_operation: 3149fe82a183SChuck Lever dprintk("nfs: Server returned operation" 31501da177e4SLinus Torvalds " %d but we issued a request for %d\n", 31511da177e4SLinus Torvalds opnum, expected); 3152c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3153c7848f69STrond Myklebust return false; 3154c0eae66eSBenny Halevy out_overflow: 3155c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3156c7848f69STrond Myklebust *nfs_retval = -EIO; 3157c7848f69STrond Myklebust return false; 3158c7848f69STrond Myklebust } 3159c7848f69STrond Myklebust 3160c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3161c7848f69STrond Myklebust { 3162c7848f69STrond Myklebust int retval; 3163c7848f69STrond Myklebust 3164c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3165c7848f69STrond Myklebust return retval; 31661da177e4SLinus Torvalds } 31671da177e4SLinus Torvalds 31681da177e4SLinus Torvalds /* Dummy routine */ 31691bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace) 31701da177e4SLinus Torvalds { 31718687b63aSAl Viro __be32 *p; 3172683b57b4STrond Myklebust unsigned int strlen; 31731da177e4SLinus Torvalds char *str; 31741da177e4SLinus Torvalds 3175c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3176c0eae66eSBenny Halevy if (likely(p)) 31771da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3178c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3179c0eae66eSBenny Halevy return -EIO; 31801da177e4SLinus Torvalds } 31811da177e4SLinus Torvalds 31821da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 31831da177e4SLinus Torvalds { 31848687b63aSAl Viro uint32_t bmlen; 31858687b63aSAl Viro __be32 *p; 31861da177e4SLinus Torvalds 3187c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3188c0eae66eSBenny Halevy if (unlikely(!p)) 3189c0eae66eSBenny Halevy goto out_overflow; 3190cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 31911da177e4SLinus Torvalds 3192dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3193c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3194c0eae66eSBenny Halevy if (unlikely(!p)) 3195c0eae66eSBenny Halevy goto out_overflow; 31961da177e4SLinus Torvalds if (bmlen > 0) { 31976f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3198dae100c2SFred Isaman if (bmlen > 1) { 3199dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3200dae100c2SFred Isaman if (bmlen > 2) 3201dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3202dae100c2SFred Isaman } 32031da177e4SLinus Torvalds } 32041da177e4SLinus Torvalds return 0; 3205c0eae66eSBenny Halevy out_overflow: 3206c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3207c0eae66eSBenny Halevy return -EIO; 32081da177e4SLinus Torvalds } 32091da177e4SLinus Torvalds 3210256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 32111da177e4SLinus Torvalds { 32128687b63aSAl Viro __be32 *p; 32131da177e4SLinus Torvalds 3214c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3215c0eae66eSBenny Halevy if (unlikely(!p)) 3216c0eae66eSBenny Halevy goto out_overflow; 3217cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3218256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 32191da177e4SLinus Torvalds return 0; 3220c0eae66eSBenny Halevy out_overflow: 3221c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3222c0eae66eSBenny Halevy return -EIO; 32231da177e4SLinus Torvalds } 32241da177e4SLinus Torvalds 32251da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 32261da177e4SLinus Torvalds { 32271da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 32283388bff5SRoman Borisov int ret; 32293388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 32303388bff5SRoman Borisov if (unlikely(ret < 0)) 32313388bff5SRoman Borisov return ret; 32321da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 32331da177e4SLinus Torvalds } else 3234dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3235dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3236dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 32371da177e4SLinus Torvalds return 0; 32381da177e4SLinus Torvalds } 32391da177e4SLinus Torvalds 32401da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32411da177e4SLinus Torvalds { 32428687b63aSAl Viro __be32 *p; 3243409924e4STrond Myklebust int ret = 0; 32441da177e4SLinus Torvalds 32451da177e4SLinus Torvalds *type = 0; 32461da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32471da177e4SLinus Torvalds return -EIO; 32481da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3249c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3250c0eae66eSBenny Halevy if (unlikely(!p)) 3251c0eae66eSBenny Halevy goto out_overflow; 3252cccddf4fSBenny Halevy *type = be32_to_cpup(p); 32531da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 32543110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 32551da177e4SLinus Torvalds return -EIO; 32561da177e4SLinus Torvalds } 32571da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3258409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 32591da177e4SLinus Torvalds } 3260bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3261409924e4STrond Myklebust return ret; 3262c0eae66eSBenny Halevy out_overflow: 3263c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3264c0eae66eSBenny Halevy return -EIO; 32651da177e4SLinus Torvalds } 32661da177e4SLinus Torvalds 3267264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3268264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3269264e6351SChuck Lever { 3270264e6351SChuck Lever __be32 *p; 3271264e6351SChuck Lever 3272264e6351SChuck Lever *type = 0; 3273264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3274264e6351SChuck Lever return -EIO; 3275264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3276264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3277264e6351SChuck Lever if (unlikely(!p)) 3278264e6351SChuck Lever goto out_overflow; 3279264e6351SChuck Lever *type = be32_to_cpup(p); 3280264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3281264e6351SChuck Lever } 3282264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3283264e6351SChuck Lever return 0; 3284264e6351SChuck Lever out_overflow: 3285264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3286264e6351SChuck Lever return -EIO; 3287264e6351SChuck Lever } 3288264e6351SChuck Lever 32891da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 32901da177e4SLinus Torvalds { 32918687b63aSAl Viro __be32 *p; 3292409924e4STrond Myklebust int ret = 0; 32931da177e4SLinus Torvalds 32941da177e4SLinus Torvalds *change = 0; 32951da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 32961da177e4SLinus Torvalds return -EIO; 32971da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3298c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3299c0eae66eSBenny Halevy if (unlikely(!p)) 3300c0eae66eSBenny Halevy goto out_overflow; 3301cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 33021da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3303409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 33041da177e4SLinus Torvalds } 33053110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 33061da177e4SLinus Torvalds (unsigned long long)*change); 3307409924e4STrond Myklebust return ret; 3308c0eae66eSBenny Halevy out_overflow: 3309c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3310c0eae66eSBenny Halevy return -EIO; 33111da177e4SLinus Torvalds } 33121da177e4SLinus Torvalds 33131da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 33141da177e4SLinus Torvalds { 33158687b63aSAl Viro __be32 *p; 3316409924e4STrond Myklebust int ret = 0; 33171da177e4SLinus Torvalds 33181da177e4SLinus Torvalds *size = 0; 33191da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 33201da177e4SLinus Torvalds return -EIO; 33211da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3322c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3323c0eae66eSBenny Halevy if (unlikely(!p)) 3324c0eae66eSBenny Halevy goto out_overflow; 3325cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 33261da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3327409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 33281da177e4SLinus Torvalds } 33293110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3330409924e4STrond Myklebust return ret; 3331c0eae66eSBenny Halevy out_overflow: 3332c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3333c0eae66eSBenny Halevy return -EIO; 33341da177e4SLinus Torvalds } 33351da177e4SLinus Torvalds 33361da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33371da177e4SLinus Torvalds { 33388687b63aSAl Viro __be32 *p; 33391da177e4SLinus Torvalds 33401da177e4SLinus Torvalds *res = 0; 33411da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33421da177e4SLinus Torvalds return -EIO; 33431da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3344c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3345c0eae66eSBenny Halevy if (unlikely(!p)) 3346c0eae66eSBenny Halevy goto out_overflow; 3347cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33481da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 33491da177e4SLinus Torvalds } 33503110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 33511da177e4SLinus Torvalds return 0; 3352c0eae66eSBenny Halevy out_overflow: 3353c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3354c0eae66eSBenny Halevy return -EIO; 33551da177e4SLinus Torvalds } 33561da177e4SLinus Torvalds 33571da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33581da177e4SLinus Torvalds { 33598687b63aSAl Viro __be32 *p; 33601da177e4SLinus Torvalds 33611da177e4SLinus Torvalds *res = 0; 33621da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 33631da177e4SLinus Torvalds return -EIO; 33641da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3365c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3366c0eae66eSBenny Halevy if (unlikely(!p)) 3367c0eae66eSBenny Halevy goto out_overflow; 3368cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33691da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 33701da177e4SLinus Torvalds } 33713110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 33721da177e4SLinus Torvalds return 0; 3373c0eae66eSBenny Halevy out_overflow: 3374c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3375c0eae66eSBenny Halevy return -EIO; 33761da177e4SLinus Torvalds } 33771da177e4SLinus Torvalds 33788b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 33791da177e4SLinus Torvalds { 33808687b63aSAl Viro __be32 *p; 3381409924e4STrond Myklebust int ret = 0; 33821da177e4SLinus Torvalds 33831da177e4SLinus Torvalds fsid->major = 0; 33841da177e4SLinus Torvalds fsid->minor = 0; 33851da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 33861da177e4SLinus Torvalds return -EIO; 33871da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3388c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3389c0eae66eSBenny Halevy if (unlikely(!p)) 3390c0eae66eSBenny Halevy goto out_overflow; 33913ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3392cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 33931da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3394409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 33951da177e4SLinus Torvalds } 33963110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 33971da177e4SLinus Torvalds (unsigned long long)fsid->major, 33981da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3399409924e4STrond Myklebust return ret; 3400c0eae66eSBenny Halevy out_overflow: 3401c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3402c0eae66eSBenny Halevy return -EIO; 34031da177e4SLinus Torvalds } 34041da177e4SLinus Torvalds 34051da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34061da177e4SLinus Torvalds { 34078687b63aSAl Viro __be32 *p; 34081da177e4SLinus Torvalds 34091da177e4SLinus Torvalds *res = 60; 34101da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 34111da177e4SLinus Torvalds return -EIO; 34121da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3413c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3414c0eae66eSBenny Halevy if (unlikely(!p)) 3415c0eae66eSBenny Halevy goto out_overflow; 3416cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34171da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 34181da177e4SLinus Torvalds } 34193110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 34201da177e4SLinus Torvalds return 0; 3421c0eae66eSBenny Halevy out_overflow: 3422c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3423c0eae66eSBenny Halevy return -EIO; 34241da177e4SLinus Torvalds } 34251da177e4SLinus Torvalds 3426ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3427ae42c70aSBryan Schumaker { 3428ae42c70aSBryan Schumaker __be32 *p; 3429ae42c70aSBryan Schumaker 3430ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3431ae42c70aSBryan Schumaker return -EIO; 3432ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3433ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3434ae42c70aSBryan Schumaker if (unlikely(!p)) 3435ae42c70aSBryan Schumaker goto out_overflow; 3436ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3437ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3438ae42c70aSBryan Schumaker } 3439ae42c70aSBryan Schumaker return 0; 3440ae42c70aSBryan Schumaker out_overflow: 3441ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3442ae42c70aSBryan Schumaker return -EIO; 3443ae42c70aSBryan Schumaker } 3444ae42c70aSBryan Schumaker 34458c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 34468c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 34478c61282fSKinglong Mee { 34488c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 34498c61282fSKinglong Mee int ret; 34508c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 34518c61282fSKinglong Mee if (unlikely(ret < 0)) 34528c61282fSKinglong Mee return ret; 34538c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 34548c61282fSKinglong Mee } else 34558c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 34568c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 34578c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 34588c61282fSKinglong Mee return 0; 34598c61282fSKinglong Mee } 34608c61282fSKinglong Mee 3461ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3462ae42c70aSBryan Schumaker { 3463ae42c70aSBryan Schumaker __be32 *p; 3464ae42c70aSBryan Schumaker int len; 3465ae42c70aSBryan Schumaker 34667ad07353STrond Myklebust if (fh != NULL) 3467ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3468ae42c70aSBryan Schumaker 3469ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3470ae42c70aSBryan Schumaker return -EIO; 3471ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3472ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3473ae42c70aSBryan Schumaker if (unlikely(!p)) 3474ae42c70aSBryan Schumaker goto out_overflow; 3475ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3476ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3477ae42c70aSBryan Schumaker return -EIO; 3478ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3479ae42c70aSBryan Schumaker if (unlikely(!p)) 3480ae42c70aSBryan Schumaker goto out_overflow; 34817ad07353STrond Myklebust if (fh != NULL) { 3482ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 34837ad07353STrond Myklebust fh->size = len; 34847ad07353STrond Myklebust } 3485ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3486ae42c70aSBryan Schumaker } 3487ae42c70aSBryan Schumaker return 0; 3488ae42c70aSBryan Schumaker out_overflow: 3489ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3490ae42c70aSBryan Schumaker return -EIO; 3491ae42c70aSBryan Schumaker } 3492ae42c70aSBryan Schumaker 34931da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34941da177e4SLinus Torvalds { 34958687b63aSAl Viro __be32 *p; 34961da177e4SLinus Torvalds 3497a1800acaSMalahal Naineni *res = 0; 34981da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 34991da177e4SLinus Torvalds return -EIO; 35001da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3501c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3502c0eae66eSBenny Halevy if (unlikely(!p)) 3503c0eae66eSBenny Halevy goto out_overflow; 3504cccddf4fSBenny Halevy *res = be32_to_cpup(p); 35051da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 35061da177e4SLinus Torvalds } 35073110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 35081da177e4SLinus Torvalds return 0; 3509c0eae66eSBenny Halevy out_overflow: 3510c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3511c0eae66eSBenny Halevy return -EIO; 35121da177e4SLinus Torvalds } 35131da177e4SLinus Torvalds 35141da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 35151da177e4SLinus Torvalds { 35168687b63aSAl Viro __be32 *p; 3517409924e4STrond Myklebust int ret = 0; 35181da177e4SLinus Torvalds 35191da177e4SLinus Torvalds *fileid = 0; 35201da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 35211da177e4SLinus Torvalds return -EIO; 35221da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3523c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3524c0eae66eSBenny Halevy if (unlikely(!p)) 3525c0eae66eSBenny Halevy goto out_overflow; 3526cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 35271da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3528409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 35291da177e4SLinus Torvalds } 35303110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3531409924e4STrond Myklebust return ret; 3532c0eae66eSBenny Halevy out_overflow: 3533c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3534c0eae66eSBenny Halevy return -EIO; 35351da177e4SLinus Torvalds } 35361da177e4SLinus Torvalds 353799baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 353899baf625SManoj Naik { 35398687b63aSAl Viro __be32 *p; 3540409924e4STrond Myklebust int ret = 0; 354199baf625SManoj Naik 354299baf625SManoj Naik *fileid = 0; 354399baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 354499baf625SManoj Naik return -EIO; 354599baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3546c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3547c0eae66eSBenny Halevy if (unlikely(!p)) 3548c0eae66eSBenny Halevy goto out_overflow; 3549cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 355099baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 355128331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 355299baf625SManoj Naik } 35533110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3554409924e4STrond Myklebust return ret; 3555c0eae66eSBenny Halevy out_overflow: 3556c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3557c0eae66eSBenny Halevy return -EIO; 355899baf625SManoj Naik } 355999baf625SManoj Naik 35601da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35611da177e4SLinus Torvalds { 35628687b63aSAl Viro __be32 *p; 35631da177e4SLinus Torvalds int status = 0; 35641da177e4SLinus Torvalds 35651da177e4SLinus Torvalds *res = 0; 35661da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 35671da177e4SLinus Torvalds return -EIO; 35681da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3569c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3570c0eae66eSBenny Halevy if (unlikely(!p)) 3571c0eae66eSBenny Halevy goto out_overflow; 3572cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35731da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 35741da177e4SLinus Torvalds } 35753110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 35761da177e4SLinus Torvalds return status; 3577c0eae66eSBenny Halevy out_overflow: 3578c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3579c0eae66eSBenny Halevy return -EIO; 35801da177e4SLinus Torvalds } 35811da177e4SLinus Torvalds 35821da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35831da177e4SLinus Torvalds { 35848687b63aSAl Viro __be32 *p; 35851da177e4SLinus Torvalds int status = 0; 35861da177e4SLinus Torvalds 35871da177e4SLinus Torvalds *res = 0; 35881da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 35891da177e4SLinus Torvalds return -EIO; 35901da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3591c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3592c0eae66eSBenny Halevy if (unlikely(!p)) 3593c0eae66eSBenny Halevy goto out_overflow; 3594cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35951da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 35961da177e4SLinus Torvalds } 35973110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 35981da177e4SLinus Torvalds return status; 3599c0eae66eSBenny Halevy out_overflow: 3600c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3601c0eae66eSBenny Halevy return -EIO; 36021da177e4SLinus Torvalds } 36031da177e4SLinus Torvalds 36041da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36051da177e4SLinus Torvalds { 36068687b63aSAl Viro __be32 *p; 36071da177e4SLinus Torvalds int status = 0; 36081da177e4SLinus Torvalds 36091da177e4SLinus Torvalds *res = 0; 36101da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 36111da177e4SLinus Torvalds return -EIO; 36121da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3613c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3614c0eae66eSBenny Halevy if (unlikely(!p)) 3615c0eae66eSBenny Halevy goto out_overflow; 3616cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36171da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 36181da177e4SLinus Torvalds } 36193110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 36201da177e4SLinus Torvalds return status; 3621c0eae66eSBenny Halevy out_overflow: 3622c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3623c0eae66eSBenny Halevy return -EIO; 36241da177e4SLinus Torvalds } 36251da177e4SLinus Torvalds 36267aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 36277aaa0b3bSManoj Naik { 3628464ad6b1SChuck Lever u32 n; 36298687b63aSAl Viro __be32 *p; 36307aaa0b3bSManoj Naik int status = 0; 36317aaa0b3bSManoj Naik 3632c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3633c0eae66eSBenny Halevy if (unlikely(!p)) 3634c0eae66eSBenny Halevy goto out_overflow; 3635cccddf4fSBenny Halevy n = be32_to_cpup(p); 363633a43f28SAndy Adamson if (n == 0) 363733a43f28SAndy Adamson goto root_path; 363802a2976cSChuck Lever dprintk("pathname4: "); 3639809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3640809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3641809b426cSTrond Myklebust goto out_eio; 3642809b426cSTrond Myklebust } 3643809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36447aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 36457aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 36467aaa0b3bSManoj Naik if (unlikely(status != 0)) 36477aaa0b3bSManoj Naik goto out_eio; 364895a13f7bSTrond Myklebust ifdebug (XDR) 364902a2976cSChuck Lever pr_cont("%s%.*s ", 365002a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 365102a2976cSChuck Lever component->len, component->data); 36527aaa0b3bSManoj Naik } 36537aaa0b3bSManoj Naik out: 36547aaa0b3bSManoj Naik return status; 365533a43f28SAndy Adamson root_path: 365633a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 365733a43f28SAndy Adamson path->ncomponents = 1; 365833a43f28SAndy Adamson path->components[0].len=0; 365933a43f28SAndy Adamson path->components[0].data=NULL; 366002a2976cSChuck Lever dprintk("pathname4: /\n"); 366133a43f28SAndy Adamson goto out; 36627aaa0b3bSManoj Naik out_eio: 36637aaa0b3bSManoj Naik dprintk(" status %d", status); 36647aaa0b3bSManoj Naik status = -EIO; 36657aaa0b3bSManoj Naik goto out; 3666c0eae66eSBenny Halevy out_overflow: 3667c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3668c0eae66eSBenny Halevy return -EIO; 36697aaa0b3bSManoj Naik } 36707aaa0b3bSManoj Naik 36717aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3672683b57b4STrond Myklebust { 3673683b57b4STrond Myklebust int n; 36748687b63aSAl Viro __be32 *p; 3675683b57b4STrond Myklebust int status = -EIO; 3676683b57b4STrond Myklebust 3677683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3678683b57b4STrond Myklebust goto out; 3679683b57b4STrond Myklebust status = 0; 3680683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3681683b57b4STrond Myklebust goto out; 3682f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 36838b7e3f49STrond Myklebust status = -EIO; 36848b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 36858b7e3f49STrond Myklebust if (unlikely(res == NULL)) 36868b7e3f49STrond Myklebust goto out; 368702a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 36887aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3689683b57b4STrond Myklebust if (unlikely(status != 0)) 3690683b57b4STrond Myklebust goto out; 3691c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3692c0eae66eSBenny Halevy if (unlikely(!p)) 3693c0eae66eSBenny Halevy goto out_overflow; 3694cccddf4fSBenny Halevy n = be32_to_cpup(p); 3695683b57b4STrond Myklebust if (n <= 0) 3696683b57b4STrond Myklebust goto out_eio; 3697809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3698464ad6b1SChuck Lever u32 m; 3699809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3700683b57b4STrond Myklebust 3701809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3702809b426cSTrond Myklebust break; 3703809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3704c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3705c0eae66eSBenny Halevy if (unlikely(!p)) 3706c0eae66eSBenny Halevy goto out_overflow; 3707cccddf4fSBenny Halevy m = be32_to_cpup(p); 37087aaa0b3bSManoj Naik 370902a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3710809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3711809b426cSTrond Myklebust struct nfs4_string *server; 3712809b426cSTrond Myklebust 3713809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3714464ad6b1SChuck Lever unsigned int i; 3715464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3716464ad6b1SChuck Lever "returned for location %u\n", 37173110ff80SHarvey Harrison __func__, 3718464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3719464ad6b1SChuck Lever m, res->nlocations); 37207aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 37212e42c3e2STrond Myklebust unsigned int len; 37227aaa0b3bSManoj Naik char *data; 37237aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3724683b57b4STrond Myklebust if (unlikely(status != 0)) 3725683b57b4STrond Myklebust goto out_eio; 37267aaa0b3bSManoj Naik } 3727809b426cSTrond Myklebust break; 37287aaa0b3bSManoj Naik } 3729809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3730809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3731809b426cSTrond Myklebust if (unlikely(status != 0)) 3732809b426cSTrond Myklebust goto out_eio; 3733809b426cSTrond Myklebust dprintk("%s ", server->data); 37347aaa0b3bSManoj Naik } 37357aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 37367aaa0b3bSManoj Naik if (unlikely(status != 0)) 37377aaa0b3bSManoj Naik goto out_eio; 3738683b57b4STrond Myklebust } 3739409924e4STrond Myklebust if (res->nlocations != 0) 374081934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3741683b57b4STrond Myklebust out: 37423110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3743683b57b4STrond Myklebust return status; 3744c0eae66eSBenny Halevy out_overflow: 3745c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3746683b57b4STrond Myklebust out_eio: 3747683b57b4STrond Myklebust status = -EIO; 3748683b57b4STrond Myklebust goto out; 3749683b57b4STrond Myklebust } 3750683b57b4STrond Myklebust 37511da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 37521da177e4SLinus Torvalds { 37538687b63aSAl Viro __be32 *p; 37541da177e4SLinus Torvalds int status = 0; 37551da177e4SLinus Torvalds 37561da177e4SLinus Torvalds *res = 0; 37571da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 37581da177e4SLinus Torvalds return -EIO; 37591da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3760c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3761c0eae66eSBenny Halevy if (unlikely(!p)) 3762c0eae66eSBenny Halevy goto out_overflow; 3763cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 37641da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 37651da177e4SLinus Torvalds } 37663110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 37671da177e4SLinus Torvalds return status; 3768c0eae66eSBenny Halevy out_overflow: 3769c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3770c0eae66eSBenny Halevy return -EIO; 37711da177e4SLinus Torvalds } 37721da177e4SLinus Torvalds 37731da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 37741da177e4SLinus Torvalds { 37758687b63aSAl Viro __be32 *p; 37761da177e4SLinus Torvalds int status = 0; 37771da177e4SLinus Torvalds 37781da177e4SLinus Torvalds *maxlink = 1; 37791da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 37801da177e4SLinus Torvalds return -EIO; 37811da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3782c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3783c0eae66eSBenny Halevy if (unlikely(!p)) 3784c0eae66eSBenny Halevy goto out_overflow; 3785cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 37861da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 37871da177e4SLinus Torvalds } 37883110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 37891da177e4SLinus Torvalds return status; 3790c0eae66eSBenny Halevy out_overflow: 3791c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3792c0eae66eSBenny Halevy return -EIO; 37931da177e4SLinus Torvalds } 37941da177e4SLinus Torvalds 37951da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 37961da177e4SLinus Torvalds { 37978687b63aSAl Viro __be32 *p; 37981da177e4SLinus Torvalds int status = 0; 37991da177e4SLinus Torvalds 38001da177e4SLinus Torvalds *maxname = 1024; 38011da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 38021da177e4SLinus Torvalds return -EIO; 38031da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3804c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3805c0eae66eSBenny Halevy if (unlikely(!p)) 3806c0eae66eSBenny Halevy goto out_overflow; 3807cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 38081da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 38091da177e4SLinus Torvalds } 38103110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 38111da177e4SLinus Torvalds return status; 3812c0eae66eSBenny Halevy out_overflow: 3813c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3814c0eae66eSBenny Halevy return -EIO; 38151da177e4SLinus Torvalds } 38161da177e4SLinus Torvalds 38171da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38181da177e4SLinus Torvalds { 38198687b63aSAl Viro __be32 *p; 38201da177e4SLinus Torvalds int status = 0; 38211da177e4SLinus Torvalds 38221da177e4SLinus Torvalds *res = 1024; 38231da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 38241da177e4SLinus Torvalds return -EIO; 38251da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 38261da177e4SLinus Torvalds uint64_t maxread; 3827c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3828c0eae66eSBenny Halevy if (unlikely(!p)) 3829c0eae66eSBenny Halevy goto out_overflow; 3830cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 38311da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 38321da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 38331da177e4SLinus Torvalds *res = (uint32_t)maxread; 38341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 38351da177e4SLinus Torvalds } 38363110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 38371da177e4SLinus Torvalds return status; 3838c0eae66eSBenny Halevy out_overflow: 3839c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3840c0eae66eSBenny Halevy return -EIO; 38411da177e4SLinus Torvalds } 38421da177e4SLinus Torvalds 38431da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38441da177e4SLinus Torvalds { 38458687b63aSAl Viro __be32 *p; 38461da177e4SLinus Torvalds int status = 0; 38471da177e4SLinus Torvalds 38481da177e4SLinus Torvalds *res = 1024; 38491da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 38501da177e4SLinus Torvalds return -EIO; 38511da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 38521da177e4SLinus Torvalds uint64_t maxwrite; 3853c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3854c0eae66eSBenny Halevy if (unlikely(!p)) 3855c0eae66eSBenny Halevy goto out_overflow; 3856cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 38571da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 38581da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 38591da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 38601da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 38611da177e4SLinus Torvalds } 38623110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 38631da177e4SLinus Torvalds return status; 3864c0eae66eSBenny Halevy out_overflow: 3865c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3866c0eae66eSBenny Halevy return -EIO; 38671da177e4SLinus Torvalds } 38681da177e4SLinus Torvalds 3869bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 38701da177e4SLinus Torvalds { 3871bca79478STrond Myklebust uint32_t tmp; 38728687b63aSAl Viro __be32 *p; 3873409924e4STrond Myklebust int ret = 0; 38741da177e4SLinus Torvalds 38751da177e4SLinus Torvalds *mode = 0; 38761da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 38771da177e4SLinus Torvalds return -EIO; 38781da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3879c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3880c0eae66eSBenny Halevy if (unlikely(!p)) 3881c0eae66eSBenny Halevy goto out_overflow; 3882cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3883bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 38841da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3885409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 38861da177e4SLinus Torvalds } 38873110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3888409924e4STrond Myklebust return ret; 3889c0eae66eSBenny Halevy out_overflow: 3890c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3891c0eae66eSBenny Halevy return -EIO; 38921da177e4SLinus Torvalds } 38931da177e4SLinus Torvalds 38941da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 38951da177e4SLinus Torvalds { 38968687b63aSAl Viro __be32 *p; 3897409924e4STrond Myklebust int ret = 0; 38981da177e4SLinus Torvalds 38991da177e4SLinus Torvalds *nlink = 1; 39001da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 39011da177e4SLinus Torvalds return -EIO; 39021da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3903c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3904c0eae66eSBenny Halevy if (unlikely(!p)) 3905c0eae66eSBenny Halevy goto out_overflow; 3906cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 39071da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3908409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 39091da177e4SLinus Torvalds } 39103110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3911409924e4STrond Myklebust return ret; 3912c0eae66eSBenny Halevy out_overflow: 3913c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3914c0eae66eSBenny Halevy return -EIO; 39151da177e4SLinus Torvalds } 39161da177e4SLinus Torvalds 3917686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr, 3918686a816aSTrond Myklebust struct nfs4_string *name, gfp_t gfp_flags) 3919686a816aSTrond Myklebust { 3920686a816aSTrond Myklebust ssize_t ret; 3921686a816aSTrond Myklebust 3922686a816aSTrond Myklebust ret = xdr_stream_decode_string_dup(xdr, &name->data, 3923686a816aSTrond Myklebust XDR_MAX_NETOBJ, gfp_flags); 3924686a816aSTrond Myklebust name->len = 0; 3925686a816aSTrond Myklebust if (ret > 0) 3926686a816aSTrond Myklebust name->len = ret; 3927686a816aSTrond Myklebust return ret; 3928686a816aSTrond Myklebust } 3929686a816aSTrond Myklebust 393080e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3931e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 39326926afd1STrond Myklebust struct nfs4_string *owner_name) 39331da177e4SLinus Torvalds { 3934686a816aSTrond Myklebust ssize_t len; 3935686a816aSTrond Myklebust char *p; 39361da177e4SLinus Torvalds 3937e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 39381da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 39391da177e4SLinus Torvalds return -EIO; 3940686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER)) 3941686a816aSTrond Myklebust return 0; 39421da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 3943686a816aSTrond Myklebust 3944686a816aSTrond Myklebust if (owner_name != NULL) { 3945686a816aSTrond Myklebust len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT); 3946686a816aSTrond Myklebust if (len <= 0) 3947686a816aSTrond Myklebust goto out; 3948686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, owner_name->data); 3949686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER_NAME; 3950686a816aSTrond Myklebust } else { 3951686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 3952686a816aSTrond Myklebust XDR_MAX_NETOBJ); 3953686a816aSTrond Myklebust if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0) 3954686a816aSTrond Myklebust goto out; 3955e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3956686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER; 3957686a816aSTrond Myklebust } 3958686a816aSTrond Myklebust out: 3959686a816aSTrond Myklebust if (len != -EBADMSG) 3960686a816aSTrond Myklebust return 0; 3961c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3962c0eae66eSBenny Halevy return -EIO; 39631da177e4SLinus Torvalds } 39641da177e4SLinus Torvalds 396580e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3966e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 39676926afd1STrond Myklebust struct nfs4_string *group_name) 39681da177e4SLinus Torvalds { 3969686a816aSTrond Myklebust ssize_t len; 3970686a816aSTrond Myklebust char *p; 39711da177e4SLinus Torvalds 3972e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 39731da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 39741da177e4SLinus Torvalds return -EIO; 3975686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) 3976686a816aSTrond Myklebust return 0; 39771da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 3978686a816aSTrond Myklebust 3979686a816aSTrond Myklebust if (group_name != NULL) { 3980686a816aSTrond Myklebust len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT); 3981686a816aSTrond Myklebust if (len <= 0) 3982686a816aSTrond Myklebust goto out; 3983686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, group_name->data); 39846f1f6220SKinglong Mee return NFS_ATTR_FATTR_GROUP_NAME; 3985686a816aSTrond Myklebust } else { 3986686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 3987686a816aSTrond Myklebust XDR_MAX_NETOBJ); 3988686a816aSTrond Myklebust if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0) 3989686a816aSTrond Myklebust goto out; 3990e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 3991686a816aSTrond Myklebust return NFS_ATTR_FATTR_GROUP; 3992686a816aSTrond Myklebust } 3993686a816aSTrond Myklebust out: 3994686a816aSTrond Myklebust if (len != -EBADMSG) 3995686a816aSTrond Myklebust return 0; 3996c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3997c0eae66eSBenny Halevy return -EIO; 39981da177e4SLinus Torvalds } 39991da177e4SLinus Torvalds 40001da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 40011da177e4SLinus Torvalds { 40028687b63aSAl Viro uint32_t major = 0, minor = 0; 40038687b63aSAl Viro __be32 *p; 4004409924e4STrond Myklebust int ret = 0; 40051da177e4SLinus Torvalds 40061da177e4SLinus Torvalds *rdev = MKDEV(0,0); 40071da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 40081da177e4SLinus Torvalds return -EIO; 40091da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 40101da177e4SLinus Torvalds dev_t tmp; 40111da177e4SLinus Torvalds 4012c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4013c0eae66eSBenny Halevy if (unlikely(!p)) 4014c0eae66eSBenny Halevy goto out_overflow; 40156f723f77SBenny Halevy major = be32_to_cpup(p++); 4016cccddf4fSBenny Halevy minor = be32_to_cpup(p); 40171da177e4SLinus Torvalds tmp = MKDEV(major, minor); 40181da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 40191da177e4SLinus Torvalds *rdev = tmp; 40201da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 4021409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 40221da177e4SLinus Torvalds } 40233110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 4024409924e4STrond Myklebust return ret; 4025c0eae66eSBenny Halevy out_overflow: 4026c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4027c0eae66eSBenny Halevy return -EIO; 40281da177e4SLinus Torvalds } 40291da177e4SLinus Torvalds 40301da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40311da177e4SLinus Torvalds { 40328687b63aSAl Viro __be32 *p; 40331da177e4SLinus Torvalds int status = 0; 40341da177e4SLinus Torvalds 40351da177e4SLinus Torvalds *res = 0; 40361da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 40371da177e4SLinus Torvalds return -EIO; 40381da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 4039c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4040c0eae66eSBenny Halevy if (unlikely(!p)) 4041c0eae66eSBenny Halevy goto out_overflow; 4042cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40431da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40441da177e4SLinus Torvalds } 40453110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 40461da177e4SLinus Torvalds return status; 4047c0eae66eSBenny Halevy out_overflow: 4048c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4049c0eae66eSBenny Halevy return -EIO; 40501da177e4SLinus Torvalds } 40511da177e4SLinus Torvalds 40521da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40531da177e4SLinus Torvalds { 40548687b63aSAl Viro __be32 *p; 40551da177e4SLinus Torvalds int status = 0; 40561da177e4SLinus Torvalds 40571da177e4SLinus Torvalds *res = 0; 40581da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 40591da177e4SLinus Torvalds return -EIO; 40601da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4061c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4062c0eae66eSBenny Halevy if (unlikely(!p)) 4063c0eae66eSBenny Halevy goto out_overflow; 4064cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40651da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 40661da177e4SLinus Torvalds } 40673110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 40681da177e4SLinus Torvalds return status; 4069c0eae66eSBenny Halevy out_overflow: 4070c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4071c0eae66eSBenny Halevy return -EIO; 40721da177e4SLinus Torvalds } 40731da177e4SLinus Torvalds 40741da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40751da177e4SLinus Torvalds { 40768687b63aSAl Viro __be32 *p; 40771da177e4SLinus Torvalds int status = 0; 40781da177e4SLinus Torvalds 40791da177e4SLinus Torvalds *res = 0; 40801da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 40811da177e4SLinus Torvalds return -EIO; 40821da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4083c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4084c0eae66eSBenny Halevy if (unlikely(!p)) 4085c0eae66eSBenny Halevy goto out_overflow; 4086cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40871da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 40881da177e4SLinus Torvalds } 40893110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 40901da177e4SLinus Torvalds return status; 4091c0eae66eSBenny Halevy out_overflow: 4092c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4093c0eae66eSBenny Halevy return -EIO; 40941da177e4SLinus Torvalds } 40951da177e4SLinus Torvalds 40961da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 40971da177e4SLinus Torvalds { 40988687b63aSAl Viro __be32 *p; 4099409924e4STrond Myklebust int ret = 0; 41001da177e4SLinus Torvalds 41011da177e4SLinus Torvalds *used = 0; 41021da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 41031da177e4SLinus Torvalds return -EIO; 41041da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4105c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4106c0eae66eSBenny Halevy if (unlikely(!p)) 4107c0eae66eSBenny Halevy goto out_overflow; 4108cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 41091da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4110409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 41111da177e4SLinus Torvalds } 41123110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 41131da177e4SLinus Torvalds (unsigned long long)*used); 4114409924e4STrond Myklebust return ret; 4115c0eae66eSBenny Halevy out_overflow: 4116c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4117c0eae66eSBenny Halevy return -EIO; 41181da177e4SLinus Torvalds } 41191da177e4SLinus Torvalds 41201da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 41211da177e4SLinus Torvalds { 41228687b63aSAl Viro __be32 *p; 41231da177e4SLinus Torvalds uint64_t sec; 41241da177e4SLinus Torvalds uint32_t nsec; 41251da177e4SLinus Torvalds 4126c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4127c0eae66eSBenny Halevy if (unlikely(!p)) 4128c0eae66eSBenny Halevy goto out_overflow; 41293ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 4130cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 41311da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 41321da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 41331da177e4SLinus Torvalds return 0; 4134c0eae66eSBenny Halevy out_overflow: 4135c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4136c0eae66eSBenny Halevy return -EIO; 41371da177e4SLinus Torvalds } 41381da177e4SLinus Torvalds 41391da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41401da177e4SLinus Torvalds { 41411da177e4SLinus Torvalds int status = 0; 41421da177e4SLinus Torvalds 41431da177e4SLinus Torvalds time->tv_sec = 0; 41441da177e4SLinus Torvalds time->tv_nsec = 0; 41451da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 41461da177e4SLinus Torvalds return -EIO; 41471da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 41481da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4149409924e4STrond Myklebust if (status == 0) 4150409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 41511da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 41521da177e4SLinus Torvalds } 41533110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 41541da177e4SLinus Torvalds return status; 41551da177e4SLinus Torvalds } 41561da177e4SLinus Torvalds 41571da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41581da177e4SLinus Torvalds { 41591da177e4SLinus Torvalds int status = 0; 41601da177e4SLinus Torvalds 41611da177e4SLinus Torvalds time->tv_sec = 0; 41621da177e4SLinus Torvalds time->tv_nsec = 0; 41631da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 41641da177e4SLinus Torvalds return -EIO; 41651da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 41661da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4167409924e4STrond Myklebust if (status == 0) 4168409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 41691da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 41701da177e4SLinus Torvalds } 41713110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 41721da177e4SLinus Torvalds return status; 41731da177e4SLinus Torvalds } 41741da177e4SLinus Torvalds 417555b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 417655b6e774SRicardo Labiaga struct timespec *time) 417755b6e774SRicardo Labiaga { 417855b6e774SRicardo Labiaga int status = 0; 417955b6e774SRicardo Labiaga 418055b6e774SRicardo Labiaga time->tv_sec = 0; 418155b6e774SRicardo Labiaga time->tv_nsec = 0; 418255b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 418355b6e774SRicardo Labiaga return -EIO; 418455b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 418555b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 418655b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 418755b6e774SRicardo Labiaga } 418855b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 418955b6e774SRicardo Labiaga (long)time->tv_nsec); 419055b6e774SRicardo Labiaga return status; 419155b6e774SRicardo Labiaga } 419255b6e774SRicardo Labiaga 4193aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4194aa9c2669SDavid Quigley struct nfs4_label *label) 4195aa9c2669SDavid Quigley { 4196aa9c2669SDavid Quigley uint32_t pi = 0; 4197aa9c2669SDavid Quigley uint32_t lfs = 0; 4198aa9c2669SDavid Quigley __u32 len; 4199aa9c2669SDavid Quigley __be32 *p; 4200aa9c2669SDavid Quigley int status = 0; 4201aa9c2669SDavid Quigley 4202aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4203aa9c2669SDavid Quigley return -EIO; 4204aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4205aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4206aa9c2669SDavid Quigley if (unlikely(!p)) 4207aa9c2669SDavid Quigley goto out_overflow; 4208aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4209aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4210aa9c2669SDavid Quigley if (unlikely(!p)) 4211aa9c2669SDavid Quigley goto out_overflow; 4212aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4213aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4214aa9c2669SDavid Quigley if (unlikely(!p)) 4215aa9c2669SDavid Quigley goto out_overflow; 4216aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4217aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4218aa9c2669SDavid Quigley if (unlikely(!p)) 4219aa9c2669SDavid Quigley goto out_overflow; 4220aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4221aa9c2669SDavid Quigley if (label) { 4222aa9c2669SDavid Quigley memcpy(label->label, p, len); 4223aa9c2669SDavid Quigley label->len = len; 4224aa9c2669SDavid Quigley label->pi = pi; 4225aa9c2669SDavid Quigley label->lfs = lfs; 4226aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4227aa9c2669SDavid Quigley } 4228aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4229aa9c2669SDavid Quigley } else 4230aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4231aa9c2669SDavid Quigley __func__, len); 4232aa9c2669SDavid Quigley } 4233aa9c2669SDavid Quigley if (label && label->label) 4234aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4235aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4236aa9c2669SDavid Quigley return status; 4237aa9c2669SDavid Quigley 4238aa9c2669SDavid Quigley out_overflow: 4239aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4240aa9c2669SDavid Quigley return -EIO; 4241aa9c2669SDavid Quigley } 4242aa9c2669SDavid Quigley 42431da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42441da177e4SLinus Torvalds { 42451da177e4SLinus Torvalds int status = 0; 42461da177e4SLinus Torvalds 42471da177e4SLinus Torvalds time->tv_sec = 0; 42481da177e4SLinus Torvalds time->tv_nsec = 0; 42491da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 42501da177e4SLinus Torvalds return -EIO; 42511da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 42521da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4253409924e4STrond Myklebust if (status == 0) 4254409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 42551da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 42561da177e4SLinus Torvalds } 42573110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 42581da177e4SLinus Torvalds return status; 42591da177e4SLinus Torvalds } 42601da177e4SLinus Torvalds 4261256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 42621da177e4SLinus Torvalds { 42631da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4264256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 42651da177e4SLinus Torvalds 42661da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4267fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4268fe82a183SChuck Lever "%u %c %u\n", 42693110ff80SHarvey Harrison __func__, 42701da177e4SLinus Torvalds attrwords << 2, 42711da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 42721da177e4SLinus Torvalds nwords << 2); 42731da177e4SLinus Torvalds return -EIO; 42741da177e4SLinus Torvalds } 42751da177e4SLinus Torvalds return 0; 42761da177e4SLinus Torvalds } 42771da177e4SLinus Torvalds 42781da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42791da177e4SLinus Torvalds { 42808687b63aSAl Viro __be32 *p; 42811da177e4SLinus Torvalds 4282c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4283c0eae66eSBenny Halevy if (unlikely(!p)) 4284c0eae66eSBenny Halevy goto out_overflow; 42856f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 42863ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4287cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 42881da177e4SLinus Torvalds return 0; 4289c0eae66eSBenny Halevy out_overflow: 4290c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4291c0eae66eSBenny Halevy return -EIO; 42921da177e4SLinus Torvalds } 42931da177e4SLinus Torvalds 42946168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 42951da177e4SLinus Torvalds { 42968687b63aSAl Viro __be32 *p; 42971da177e4SLinus Torvalds uint32_t supp, acc; 42981da177e4SLinus Torvalds int status; 42991da177e4SLinus Torvalds 43001da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 43011da177e4SLinus Torvalds if (status) 43021da177e4SLinus Torvalds return status; 4303c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4304c0eae66eSBenny Halevy if (unlikely(!p)) 4305c0eae66eSBenny Halevy goto out_overflow; 43066f723f77SBenny Halevy supp = be32_to_cpup(p++); 4307cccddf4fSBenny Halevy acc = be32_to_cpup(p); 43086168f62cSWeston Andros Adamson *supported = supp; 43096168f62cSWeston Andros Adamson *access = acc; 43101da177e4SLinus Torvalds return 0; 4311c0eae66eSBenny Halevy out_overflow: 4312c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4313c0eae66eSBenny Halevy return -EIO; 43141da177e4SLinus Torvalds } 43151da177e4SLinus Torvalds 431607d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 43171da177e4SLinus Torvalds { 4318ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); 4319ab6e9aafSTrond Myklebust if (unlikely(ret < 0)) { 432007d30434SBenny Halevy print_overflow_msg(__func__, xdr); 432107d30434SBenny Halevy return -EIO; 432207d30434SBenny Halevy } 4323ab6e9aafSTrond Myklebust return 0; 4324ab6e9aafSTrond Myklebust } 432507d30434SBenny Halevy 432607d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 432707d30434SBenny Halevy { 43282d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 43291da177e4SLinus Torvalds } 43301da177e4SLinus Torvalds 433193b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 433293b717fdSTrond Myklebust { 433393b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 433493b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 433593b717fdSTrond Myklebust } 433693b717fdSTrond Myklebust 433793b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 433893b717fdSTrond Myklebust { 433993b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 434093b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 434193b717fdSTrond Myklebust } 434293b717fdSTrond Myklebust 434393b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 434493b717fdSTrond Myklebust { 434593b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 434693b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 434793b717fdSTrond Myklebust } 434893b717fdSTrond Myklebust 43491da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 43501da177e4SLinus Torvalds { 43511da177e4SLinus Torvalds int status; 43521da177e4SLinus Torvalds 43531da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4354c1d51931STrond Myklebust if (status != -EIO) 4355c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 435607d30434SBenny Halevy if (!status) 435793b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 43581da177e4SLinus Torvalds return status; 43591da177e4SLinus Torvalds } 43601da177e4SLinus Torvalds 4361db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4362db942bbdSBenny Halevy { 4363cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 43641da177e4SLinus Torvalds } 43651da177e4SLinus Torvalds 43662f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 43672f2c63bcSTrond Myklebust { 43682f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 43692f2c63bcSTrond Myklebust } 43702f2c63bcSTrond Myklebust 43710b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 43721da177e4SLinus Torvalds { 43731da177e4SLinus Torvalds int status; 43741da177e4SLinus Torvalds 43751da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4376db942bbdSBenny Halevy if (!status) 43772f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 43781da177e4SLinus Torvalds return status; 43791da177e4SLinus Torvalds } 43801da177e4SLinus Torvalds 43811da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43821da177e4SLinus Torvalds { 43838687b63aSAl Viro __be32 *p; 43841da177e4SLinus Torvalds uint32_t bmlen; 43851da177e4SLinus Torvalds int status; 43861da177e4SLinus Torvalds 43871da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 43881da177e4SLinus Torvalds if (status) 43891da177e4SLinus Torvalds return status; 43901da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 43911da177e4SLinus Torvalds return status; 4392c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4393c0eae66eSBenny Halevy if (unlikely(!p)) 4394c0eae66eSBenny Halevy goto out_overflow; 4395cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4396c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4397c0eae66eSBenny Halevy if (likely(p)) 43981da177e4SLinus Torvalds return 0; 4399c0eae66eSBenny Halevy out_overflow: 4400c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4401c0eae66eSBenny Halevy return -EIO; 44021da177e4SLinus Torvalds } 44031da177e4SLinus Torvalds 44041da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 44051da177e4SLinus Torvalds { 4406256e48bbSTrond Myklebust unsigned int savep; 4407dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44081da177e4SLinus Torvalds int status; 44091da177e4SLinus Torvalds 44101da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44111da177e4SLinus Torvalds goto xdr_error; 44121da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44131da177e4SLinus Torvalds goto xdr_error; 44141da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44151da177e4SLinus Torvalds goto xdr_error; 44161da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 44171da177e4SLinus Torvalds goto xdr_error; 4418264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4419264e6351SChuck Lever &res->fh_expire_type)) != 0) 4420264e6351SChuck Lever goto xdr_error; 44211da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 44221da177e4SLinus Torvalds goto xdr_error; 44231da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 44241da177e4SLinus Torvalds goto xdr_error; 44251da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 44261da177e4SLinus Torvalds goto xdr_error; 44278c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 44288c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 44298c61282fSKinglong Mee goto xdr_error; 44301da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44311da177e4SLinus Torvalds xdr_error: 44323110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44331da177e4SLinus Torvalds return status; 44341da177e4SLinus Torvalds } 44351da177e4SLinus Torvalds 44361da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 44371da177e4SLinus Torvalds { 4438256e48bbSTrond Myklebust unsigned int savep; 4439dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44401da177e4SLinus Torvalds int status; 44411da177e4SLinus Torvalds 44421da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44431da177e4SLinus Torvalds goto xdr_error; 44441da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44451da177e4SLinus Torvalds goto xdr_error; 44461da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44471da177e4SLinus Torvalds goto xdr_error; 44481da177e4SLinus Torvalds 44491da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 44501da177e4SLinus Torvalds goto xdr_error; 44511da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 44521da177e4SLinus Torvalds goto xdr_error; 44531da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 44541da177e4SLinus Torvalds goto xdr_error; 44551ca843a2SAndreas Gruenbacher 44561ca843a2SAndreas Gruenbacher status = -EIO; 44571ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 44581ca843a2SAndreas Gruenbacher goto xdr_error; 44591ca843a2SAndreas Gruenbacher 44601da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 44611da177e4SLinus Torvalds goto xdr_error; 44621da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 44631da177e4SLinus Torvalds goto xdr_error; 44641da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 44651da177e4SLinus Torvalds goto xdr_error; 44661da177e4SLinus Torvalds 44671da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44681da177e4SLinus Torvalds xdr_error: 44693110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44701da177e4SLinus Torvalds return status; 44711da177e4SLinus Torvalds } 44721da177e4SLinus Torvalds 44731da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 44741da177e4SLinus Torvalds { 4475256e48bbSTrond Myklebust unsigned int savep; 4476dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44771da177e4SLinus Torvalds int status; 44781da177e4SLinus Torvalds 44791da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44801da177e4SLinus Torvalds goto xdr_error; 44811da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44821da177e4SLinus Torvalds goto xdr_error; 44831da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44841da177e4SLinus Torvalds goto xdr_error; 44851da177e4SLinus Torvalds 44861da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 44871da177e4SLinus Torvalds goto xdr_error; 44881da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 44891da177e4SLinus Torvalds goto xdr_error; 44901da177e4SLinus Torvalds 44911da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44921da177e4SLinus Torvalds xdr_error: 44933110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44941da177e4SLinus Torvalds return status; 44951da177e4SLinus Torvalds } 44961da177e4SLinus Torvalds 449788034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 449888034c3dSAndy Adamson uint32_t *bitmap, 449988034c3dSAndy Adamson uint64_t *res, 450088034c3dSAndy Adamson uint32_t hint_bit) 450188034c3dSAndy Adamson { 450288034c3dSAndy Adamson __be32 *p; 450388034c3dSAndy Adamson 450488034c3dSAndy Adamson *res = 0; 450588034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 450688034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 450788034c3dSAndy Adamson if (unlikely(!p)) 450888034c3dSAndy Adamson goto out_overflow; 450988034c3dSAndy Adamson xdr_decode_hyper(p, res); 451088034c3dSAndy Adamson } 451188034c3dSAndy Adamson return 0; 451288034c3dSAndy Adamson out_overflow: 451388034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 451488034c3dSAndy Adamson return -EIO; 451588034c3dSAndy Adamson } 451688034c3dSAndy Adamson 451788034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 451888034c3dSAndy Adamson struct nfs4_threshold *res) 451988034c3dSAndy Adamson { 4520256e48bbSTrond Myklebust __be32 *p; 4521256e48bbSTrond Myklebust unsigned int savep; 452288034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 452388034c3dSAndy Adamson int status; 452488034c3dSAndy Adamson 452588034c3dSAndy Adamson /* layout type */ 452688034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 452788034c3dSAndy Adamson if (unlikely(!p)) { 452888034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 452988034c3dSAndy Adamson return -EIO; 453088034c3dSAndy Adamson } 453188034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 453288034c3dSAndy Adamson 453388034c3dSAndy Adamson /* thi_hintset bitmap */ 453488034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 453588034c3dSAndy Adamson if (status < 0) 453688034c3dSAndy Adamson goto xdr_error; 453788034c3dSAndy Adamson 453888034c3dSAndy Adamson /* thi_hintlist length */ 453988034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 454088034c3dSAndy Adamson if (status < 0) 454188034c3dSAndy Adamson goto xdr_error; 454288034c3dSAndy Adamson /* thi_hintlist */ 454388034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 454488034c3dSAndy Adamson if (status < 0) 454588034c3dSAndy Adamson goto xdr_error; 454688034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 454788034c3dSAndy Adamson if (status < 0) 454888034c3dSAndy Adamson goto xdr_error; 454988034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 455088034c3dSAndy Adamson THRESHOLD_RD_IO); 455188034c3dSAndy Adamson if (status < 0) 455288034c3dSAndy Adamson goto xdr_error; 455388034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 455488034c3dSAndy Adamson THRESHOLD_WR_IO); 455588034c3dSAndy Adamson if (status < 0) 455688034c3dSAndy Adamson goto xdr_error; 455788034c3dSAndy Adamson 455888034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 455988034c3dSAndy Adamson res->bm = bitmap[0]; 456088034c3dSAndy Adamson 456188034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 456288034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 456388034c3dSAndy Adamson res->wr_io_sz); 456488034c3dSAndy Adamson xdr_error: 456588034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 456688034c3dSAndy Adamson return status; 456788034c3dSAndy Adamson } 456888034c3dSAndy Adamson 456988034c3dSAndy Adamson /* 457088034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 457188034c3dSAndy Adamson */ 457288034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 457388034c3dSAndy Adamson uint32_t *bitmap, 457488034c3dSAndy Adamson struct nfs4_threshold *res) 457588034c3dSAndy Adamson { 457688034c3dSAndy Adamson __be32 *p; 457788034c3dSAndy Adamson int status = 0; 457888034c3dSAndy Adamson uint32_t num; 457988034c3dSAndy Adamson 458088034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 458188034c3dSAndy Adamson return -EIO; 4582029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 45831549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 45841549210fSTrond Myklebust if (unlikely(res == NULL)) 45851549210fSTrond Myklebust return -EREMOTEIO; 458688034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 458788034c3dSAndy Adamson if (unlikely(!p)) 458888034c3dSAndy Adamson goto out_overflow; 458988034c3dSAndy Adamson num = be32_to_cpup(p); 459088034c3dSAndy Adamson if (num == 0) 459188034c3dSAndy Adamson return 0; 459288034c3dSAndy Adamson if (num > 1) 459388034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 459488034c3dSAndy Adamson "drivers per filesystem not supported\n", 459588034c3dSAndy Adamson __func__); 459688034c3dSAndy Adamson 459788034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4598029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 459988034c3dSAndy Adamson } 460088034c3dSAndy Adamson return status; 460188034c3dSAndy Adamson out_overflow: 460288034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 460388034c3dSAndy Adamson return -EIO; 460488034c3dSAndy Adamson } 460588034c3dSAndy Adamson 4606ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4607ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4608aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 46096926afd1STrond Myklebust const struct nfs_server *server) 46101da177e4SLinus Torvalds { 4611bca79478STrond Myklebust int status; 4612bca79478STrond Myklebust umode_t fmode = 0; 4613ae42c70aSBryan Schumaker uint32_t type; 4614ee7b75fcSTrond Myklebust int32_t err; 46151da177e4SLinus Torvalds 4616f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4617f26c7a78STrond Myklebust if (status < 0) 46181da177e4SLinus Torvalds goto xdr_error; 4619409924e4STrond Myklebust fattr->mode = 0; 4620409924e4STrond Myklebust if (status != 0) { 4621409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4622409924e4STrond Myklebust fattr->valid |= status; 4623409924e4STrond Myklebust } 46241da177e4SLinus Torvalds 4625f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4626f26c7a78STrond Myklebust if (status < 0) 46271da177e4SLinus Torvalds goto xdr_error; 4628409924e4STrond Myklebust fattr->valid |= status; 4629f26c7a78STrond Myklebust 4630f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4631f26c7a78STrond Myklebust if (status < 0) 46321da177e4SLinus Torvalds goto xdr_error; 4633409924e4STrond Myklebust fattr->valid |= status; 4634f26c7a78STrond Myklebust 4635f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4636f26c7a78STrond Myklebust if (status < 0) 46371da177e4SLinus Torvalds goto xdr_error; 4638409924e4STrond Myklebust fattr->valid |= status; 4639f26c7a78STrond Myklebust 4640ee7b75fcSTrond Myklebust err = 0; 4641ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4642ae42c70aSBryan Schumaker if (status < 0) 4643ae42c70aSBryan Schumaker goto xdr_error; 4644ae42c70aSBryan Schumaker 4645ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4646ae42c70aSBryan Schumaker if (status < 0) 4647ae42c70aSBryan Schumaker goto xdr_error; 4648ae42c70aSBryan Schumaker 4649f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4650f26c7a78STrond Myklebust if (status < 0) 46511da177e4SLinus Torvalds goto xdr_error; 4652409924e4STrond Myklebust fattr->valid |= status; 4653f26c7a78STrond Myklebust 46548b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4655f26c7a78STrond Myklebust if (status < 0) 4656683b57b4STrond Myklebust goto xdr_error; 4657409924e4STrond Myklebust fattr->valid |= status; 4658f26c7a78STrond Myklebust 46591ca843a2SAndreas Gruenbacher status = -EIO; 46601ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 46611ca843a2SAndreas Gruenbacher goto xdr_error; 46621ca843a2SAndreas Gruenbacher 4663f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4664f26c7a78STrond Myklebust if (status < 0) 46651da177e4SLinus Torvalds goto xdr_error; 4666409924e4STrond Myklebust if (status != 0) { 46671da177e4SLinus Torvalds fattr->mode |= fmode; 4668409924e4STrond Myklebust fattr->valid |= status; 4669409924e4STrond Myklebust } 4670f26c7a78STrond Myklebust 4671f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4672f26c7a78STrond Myklebust if (status < 0) 46731da177e4SLinus Torvalds goto xdr_error; 4674409924e4STrond Myklebust fattr->valid |= status; 4675f26c7a78STrond Myklebust 46766926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4677f26c7a78STrond Myklebust if (status < 0) 46781da177e4SLinus Torvalds goto xdr_error; 4679409924e4STrond Myklebust fattr->valid |= status; 4680f26c7a78STrond Myklebust 46816926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4682f26c7a78STrond Myklebust if (status < 0) 46831da177e4SLinus Torvalds goto xdr_error; 4684409924e4STrond Myklebust fattr->valid |= status; 4685f26c7a78STrond Myklebust 4686f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4687f26c7a78STrond Myklebust if (status < 0) 46881da177e4SLinus Torvalds goto xdr_error; 4689409924e4STrond Myklebust fattr->valid |= status; 4690f26c7a78STrond Myklebust 4691f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4692f26c7a78STrond Myklebust if (status < 0) 46931da177e4SLinus Torvalds goto xdr_error; 4694409924e4STrond Myklebust fattr->valid |= status; 4695f26c7a78STrond Myklebust 4696f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4697f26c7a78STrond Myklebust if (status < 0) 46981da177e4SLinus Torvalds goto xdr_error; 4699409924e4STrond Myklebust fattr->valid |= status; 4700f26c7a78STrond Myklebust 4701f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4702f26c7a78STrond Myklebust if (status < 0) 47031da177e4SLinus Torvalds goto xdr_error; 4704409924e4STrond Myklebust fattr->valid |= status; 4705f26c7a78STrond Myklebust 4706f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4707f26c7a78STrond Myklebust if (status < 0) 47081da177e4SLinus Torvalds goto xdr_error; 4709409924e4STrond Myklebust fattr->valid |= status; 4710f26c7a78STrond Myklebust 471128331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4712f26c7a78STrond Myklebust if (status < 0) 471399baf625SManoj Naik goto xdr_error; 4714409924e4STrond Myklebust fattr->valid |= status; 4715f26c7a78STrond Myklebust 47161ca843a2SAndreas Gruenbacher status = -EIO; 47171ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 47181ca843a2SAndreas Gruenbacher goto xdr_error; 47191ca843a2SAndreas Gruenbacher 472088034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 472188034c3dSAndy Adamson if (status < 0) 472288034c3dSAndy Adamson goto xdr_error; 472388034c3dSAndy Adamson 4724aa9c2669SDavid Quigley if (label) { 4725aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4726aa9c2669SDavid Quigley if (status < 0) 4727aa9c2669SDavid Quigley goto xdr_error; 4728aa9c2669SDavid Quigley fattr->valid |= status; 4729aa9c2669SDavid Quigley } 4730aa9c2669SDavid Quigley 4731ae42c70aSBryan Schumaker xdr_error: 4732ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4733ae42c70aSBryan Schumaker return status; 4734ae42c70aSBryan Schumaker } 4735ae42c70aSBryan Schumaker 4736ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47378b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4738aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4739ae42c70aSBryan Schumaker { 4740256e48bbSTrond Myklebust unsigned int savep; 4741ae42c70aSBryan Schumaker uint32_t attrlen, 4742dae100c2SFred Isaman bitmap[3] = {0}; 4743ae42c70aSBryan Schumaker int status; 4744ae42c70aSBryan Schumaker 4745ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4746ae42c70aSBryan Schumaker if (status < 0) 4747ae42c70aSBryan Schumaker goto xdr_error; 4748ae42c70aSBryan Schumaker 4749ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4750ae42c70aSBryan Schumaker if (status < 0) 4751ae42c70aSBryan Schumaker goto xdr_error; 4752ae42c70aSBryan Schumaker 4753ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4754ae42c70aSBryan Schumaker if (status < 0) 4755ae42c70aSBryan Schumaker goto xdr_error; 4756ae42c70aSBryan Schumaker 4757aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4758aa9c2669SDavid Quigley label, server); 4759ae42c70aSBryan Schumaker if (status < 0) 4760ae42c70aSBryan Schumaker goto xdr_error; 4761ae42c70aSBryan Schumaker 4762f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 47631da177e4SLinus Torvalds xdr_error: 47643110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 47651da177e4SLinus Torvalds return status; 47661da177e4SLinus Torvalds } 47671da177e4SLinus Torvalds 4768aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4769aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4770aa9c2669SDavid Quigley { 4771aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4772aa9c2669SDavid Quigley } 4773aa9c2669SDavid Quigley 4774ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47756926afd1STrond Myklebust const struct nfs_server *server) 4776ae42c70aSBryan Schumaker { 4777aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4778ae42c70aSBryan Schumaker } 47791da177e4SLinus Torvalds 4780504913fbSAndy Adamson /* 47813132e49eSJeff Layton * Decode potentially multiple layout types. 4782504913fbSAndy Adamson */ 47833132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4784ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4785504913fbSAndy Adamson { 4786b8a8a0ddSTrond Myklebust __be32 *p; 4787ca440c38SJeff Layton uint32_t i; 4788504913fbSAndy Adamson 4789504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4790504913fbSAndy Adamson if (unlikely(!p)) 4791504913fbSAndy Adamson goto out_overflow; 4792ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4793504913fbSAndy Adamson 4794504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4795ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4796504913fbSAndy Adamson return 0; 4797504913fbSAndy Adamson 4798504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4799ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4800504913fbSAndy Adamson if (unlikely(!p)) 4801504913fbSAndy Adamson goto out_overflow; 4802ca440c38SJeff Layton 4803ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4804ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4805ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4806ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4807ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4808ca440c38SJeff Layton } 4809ca440c38SJeff Layton 4810ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4811ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4812504913fbSAndy Adamson return 0; 4813504913fbSAndy Adamson out_overflow: 4814504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4815504913fbSAndy Adamson return -EIO; 4816504913fbSAndy Adamson } 4817504913fbSAndy Adamson 4818504913fbSAndy Adamson /* 4819504913fbSAndy Adamson * The type of file system exported. 4820504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4821504913fbSAndy Adamson */ 4822504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4823ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4824504913fbSAndy Adamson { 4825504913fbSAndy Adamson int status = 0; 4826504913fbSAndy Adamson 4827504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4828504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4829504913fbSAndy Adamson return -EIO; 4830504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4831ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4832504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 48333132e49eSJeff Layton } 4834504913fbSAndy Adamson return status; 4835504913fbSAndy Adamson } 4836504913fbSAndy Adamson 4837dae100c2SFred Isaman /* 4838dae100c2SFred Isaman * The prefered block size for layout directed io 4839dae100c2SFred Isaman */ 4840dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4841dae100c2SFred Isaman uint32_t *res) 4842dae100c2SFred Isaman { 4843dae100c2SFred Isaman __be32 *p; 4844dae100c2SFred Isaman 4845dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4846dae100c2SFred Isaman *res = 0; 4847dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4848dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4849dae100c2SFred Isaman if (unlikely(!p)) { 4850dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4851dae100c2SFred Isaman return -EIO; 4852dae100c2SFred Isaman } 4853dae100c2SFred Isaman *res = be32_to_cpup(p); 4854dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4855dae100c2SFred Isaman } 4856dae100c2SFred Isaman return 0; 4857dae100c2SFred Isaman } 4858dae100c2SFred Isaman 48592a92ee92SPeng Tao /* 48602a92ee92SPeng Tao * The granularity of a CLONE operation. 48612a92ee92SPeng Tao */ 48622a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 48632a92ee92SPeng Tao uint32_t *res) 48642a92ee92SPeng Tao { 48652a92ee92SPeng Tao __be32 *p; 48662a92ee92SPeng Tao 48672a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 48682a92ee92SPeng Tao *res = 0; 48692a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 48702a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 48712a92ee92SPeng Tao if (unlikely(!p)) { 48722a92ee92SPeng Tao print_overflow_msg(__func__, xdr); 48732a92ee92SPeng Tao return -EIO; 48742a92ee92SPeng Tao } 48752a92ee92SPeng Tao *res = be32_to_cpup(p); 48762a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 48772a92ee92SPeng Tao } 48782a92ee92SPeng Tao return 0; 48792a92ee92SPeng Tao } 48802a92ee92SPeng Tao 48811da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 48821da177e4SLinus Torvalds { 4883256e48bbSTrond Myklebust unsigned int savep; 4884dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 48851da177e4SLinus Torvalds int status; 48861da177e4SLinus Torvalds 48871da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 48881da177e4SLinus Torvalds goto xdr_error; 48891da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 48901da177e4SLinus Torvalds goto xdr_error; 48911da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 48921da177e4SLinus Torvalds goto xdr_error; 48931da177e4SLinus Torvalds 48941da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 48951da177e4SLinus Torvalds 48961da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 48971da177e4SLinus Torvalds goto xdr_error; 48981da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 48991da177e4SLinus Torvalds goto xdr_error; 49001da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 49011da177e4SLinus Torvalds goto xdr_error; 49021da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 49031da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 49041da177e4SLinus Torvalds goto xdr_error; 49051da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 49061ca843a2SAndreas Gruenbacher 49071ca843a2SAndreas Gruenbacher status = -EIO; 49081ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 49091ca843a2SAndreas Gruenbacher goto xdr_error; 49101ca843a2SAndreas Gruenbacher 491155b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 491255b6e774SRicardo Labiaga if (status != 0) 491355b6e774SRicardo Labiaga goto xdr_error; 4914ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4915504913fbSAndy Adamson if (status != 0) 4916504913fbSAndy Adamson goto xdr_error; 49171ca843a2SAndreas Gruenbacher 49181ca843a2SAndreas Gruenbacher status = -EIO; 49191ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 49201ca843a2SAndreas Gruenbacher goto xdr_error; 49211ca843a2SAndreas Gruenbacher 4922dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4923dae100c2SFred Isaman if (status) 4924dae100c2SFred Isaman goto xdr_error; 49252a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 49262a92ee92SPeng Tao if (status) 49272a92ee92SPeng Tao goto xdr_error; 49281da177e4SLinus Torvalds 49291da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 49301da177e4SLinus Torvalds xdr_error: 49313110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 49321da177e4SLinus Torvalds return status; 49331da177e4SLinus Torvalds } 49341da177e4SLinus Torvalds 49351da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 49361da177e4SLinus Torvalds { 49378687b63aSAl Viro __be32 *p; 49381da177e4SLinus Torvalds uint32_t len; 49391da177e4SLinus Torvalds int status; 49401da177e4SLinus Torvalds 49419936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 49429936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 49439936781dSTrond Myklebust 49441da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 49451da177e4SLinus Torvalds if (status) 49461da177e4SLinus Torvalds return status; 49471da177e4SLinus Torvalds 4948c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4949c0eae66eSBenny Halevy if (unlikely(!p)) 4950c0eae66eSBenny Halevy goto out_overflow; 4951cccddf4fSBenny Halevy len = be32_to_cpup(p); 49521da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 49531da177e4SLinus Torvalds return -EIO; 49541da177e4SLinus Torvalds fh->size = len; 4955c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4956c0eae66eSBenny Halevy if (unlikely(!p)) 4957c0eae66eSBenny Halevy goto out_overflow; 495899398d06SBenny Halevy memcpy(fh->data, p, len); 49591da177e4SLinus Torvalds return 0; 4960c0eae66eSBenny Halevy out_overflow: 4961c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4962c0eae66eSBenny Halevy return -EIO; 49631da177e4SLinus Torvalds } 49641da177e4SLinus Torvalds 49651da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 49661da177e4SLinus Torvalds { 49671da177e4SLinus Torvalds int status; 49681da177e4SLinus Torvalds 49691da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 49701da177e4SLinus Torvalds if (status) 49711da177e4SLinus Torvalds return status; 49721da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 49731da177e4SLinus Torvalds } 49741da177e4SLinus Torvalds 49751da177e4SLinus Torvalds /* 49761da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 49771da177e4SLinus Torvalds */ 4978911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 49791da177e4SLinus Torvalds { 4980911d1aafSTrond Myklebust uint64_t offset, length, clientid; 49818687b63aSAl Viro __be32 *p; 4982911d1aafSTrond Myklebust uint32_t namelen, type; 49831da177e4SLinus Torvalds 4984babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4985c0eae66eSBenny Halevy if (unlikely(!p)) 4986c0eae66eSBenny Halevy goto out_overflow; 4987babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 49883ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4989babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4990babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4991911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4992911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4993911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4994911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4995911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4996911d1aafSTrond Myklebust if (type & 1) 4997911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4998911d1aafSTrond Myklebust fl->fl_pid = 0; 4999911d1aafSTrond Myklebust } 5000babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 5001babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 5002babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 5003c0eae66eSBenny Halevy if (likely(p)) 50041da177e4SLinus Torvalds return -NFS4ERR_DENIED; 5005c0eae66eSBenny Halevy out_overflow: 5006c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5007c0eae66eSBenny Halevy return -EIO; 50081da177e4SLinus Torvalds } 50091da177e4SLinus Torvalds 5010911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 50111da177e4SLinus Torvalds { 50121da177e4SLinus Torvalds int status; 50131da177e4SLinus Torvalds 50141da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 5015c1d51931STrond Myklebust if (status == -EIO) 5016c1d51931STrond Myklebust goto out; 50171da177e4SLinus Torvalds if (status == 0) { 501893b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 501907d30434SBenny Halevy if (unlikely(status)) 502007d30434SBenny Halevy goto out; 50211da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 5022c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 5023c1d51931STrond Myklebust if (res->open_seqid != NULL) 5024c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 5025c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 5026c1d51931STrond Myklebust out: 50271da177e4SLinus Torvalds return status; 50281da177e4SLinus Torvalds } 50291da177e4SLinus Torvalds 5030911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 50311da177e4SLinus Torvalds { 50321da177e4SLinus Torvalds int status; 50331da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 50341da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 5035911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 50361da177e4SLinus Torvalds return status; 50371da177e4SLinus Torvalds } 50381da177e4SLinus Torvalds 5039911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 50401da177e4SLinus Torvalds { 50411da177e4SLinus Torvalds int status; 50421da177e4SLinus Torvalds 50431da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 5044c1d51931STrond Myklebust if (status != -EIO) 5045c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 504607d30434SBenny Halevy if (status == 0) 504793b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 50481da177e4SLinus Torvalds return status; 50491da177e4SLinus Torvalds } 50501da177e4SLinus Torvalds 5051d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 5052d3c7b7ccSTrond Myklebust { 5053d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5054d3c7b7ccSTrond Myklebust } 5055d3c7b7ccSTrond Myklebust 50561da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 50571da177e4SLinus Torvalds { 50581da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 50591da177e4SLinus Torvalds } 50601da177e4SLinus Torvalds 50611da177e4SLinus Torvalds /* This is too sick! */ 50627d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 50637d160a6cSTrond Myklebust unsigned long *pagemod_limit) 50641da177e4SLinus Torvalds { 50658687b63aSAl Viro __be32 *p; 50661da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 50677d160a6cSTrond Myklebust u64 maxsize = 0; 50681da177e4SLinus Torvalds 5069c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5070c0eae66eSBenny Halevy if (unlikely(!p)) 5071c0eae66eSBenny Halevy goto out_overflow; 50726f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 50731da177e4SLinus Torvalds switch (limit_type) { 50747d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 50757d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 50761da177e4SLinus Torvalds break; 50777d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 50786f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5079cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 50807d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 50811da177e4SLinus Torvalds } 508209cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 50837d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 50841da177e4SLinus Torvalds return 0; 5085c0eae66eSBenny Halevy out_overflow: 5086c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5087c0eae66eSBenny Halevy return -EIO; 50881da177e4SLinus Torvalds } 50891da177e4SLinus Torvalds 50906ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 50916ae37339STrond Myklebust uint32_t delegation_type, 50926ae37339STrond Myklebust struct nfs_openres *res) 50931da177e4SLinus Torvalds { 50948687b63aSAl Viro __be32 *p; 509507d30434SBenny Halevy int status; 50961da177e4SLinus Torvalds 509793b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 509807d30434SBenny Halevy if (unlikely(status)) 509907d30434SBenny Halevy return status; 5100c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5101c0eae66eSBenny Halevy if (unlikely(!p)) 5102c0eae66eSBenny Halevy goto out_overflow; 5103cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 510405d564feSAndy Adamson 51051da177e4SLinus Torvalds switch (delegation_type) { 51061da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 51071da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 51081da177e4SLinus Torvalds break; 51091da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 51101da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 51117d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 51121da177e4SLinus Torvalds return -EIO; 51131da177e4SLinus Torvalds } 51141bbe60ffSTrond Myklebust return decode_ace(xdr, NULL); 5115c0eae66eSBenny Halevy out_overflow: 5116c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5117c0eae66eSBenny Halevy return -EIO; 51181da177e4SLinus Torvalds } 51191da177e4SLinus Torvalds 51206ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51216ae37339STrond Myklebust { 51226ae37339STrond Myklebust __be32 *p; 51236ae37339STrond Myklebust uint32_t why_no_delegation; 51246ae37339STrond Myklebust 51256ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51266ae37339STrond Myklebust if (unlikely(!p)) 51276ae37339STrond Myklebust goto out_overflow; 51286ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 51296ae37339STrond Myklebust switch (why_no_delegation) { 51306ae37339STrond Myklebust case WND4_CONTENTION: 51316ae37339STrond Myklebust case WND4_RESOURCE: 51326ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 51336ae37339STrond Myklebust /* Ignore for now */ 51346ae37339STrond Myklebust } 51356ae37339STrond Myklebust return 0; 51366ae37339STrond Myklebust out_overflow: 51376ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51386ae37339STrond Myklebust return -EIO; 51396ae37339STrond Myklebust } 51406ae37339STrond Myklebust 51416ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51426ae37339STrond Myklebust { 51436ae37339STrond Myklebust __be32 *p; 51446ae37339STrond Myklebust uint32_t delegation_type; 51456ae37339STrond Myklebust 51466ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51476ae37339STrond Myklebust if (unlikely(!p)) 51486ae37339STrond Myklebust goto out_overflow; 51496ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 51506ae37339STrond Myklebust res->delegation_type = 0; 51516ae37339STrond Myklebust switch (delegation_type) { 51526ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 51536ae37339STrond Myklebust return 0; 51546ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 51556ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 51566ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 51576ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 51586ae37339STrond Myklebust return decode_no_delegation(xdr, res); 51596ae37339STrond Myklebust } 51606ae37339STrond Myklebust return -EIO; 51616ae37339STrond Myklebust out_overflow: 51626ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51636ae37339STrond Myklebust return -EIO; 51646ae37339STrond Myklebust } 51656ae37339STrond Myklebust 51661da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 51671da177e4SLinus Torvalds { 51688687b63aSAl Viro __be32 *p; 5169aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 51701da177e4SLinus Torvalds int status; 51711da177e4SLinus Torvalds 5172c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5173c7848f69STrond Myklebust return status; 5174c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5175c7848f69STrond Myklebust if (status) 5176c7848f69STrond Myklebust return status; 517793b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 517807d30434SBenny Halevy if (unlikely(status)) 51791da177e4SLinus Torvalds return status; 51801da177e4SLinus Torvalds 51811da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 51821da177e4SLinus Torvalds 5183c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5184c0eae66eSBenny Halevy if (unlikely(!p)) 5185c0eae66eSBenny Halevy goto out_overflow; 51866f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5187cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 51881da177e4SLinus Torvalds if (bmlen > 10) 51891da177e4SLinus Torvalds goto xdr_error; 51901da177e4SLinus Torvalds 5191c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5192c0eae66eSBenny Halevy if (unlikely(!p)) 5193c0eae66eSBenny Halevy goto out_overflow; 5194aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5195aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 51966f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5197aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5198aa53ed54SJeff Layton res->attrset[i] = 0; 5199aa53ed54SJeff Layton 52001da177e4SLinus Torvalds return decode_delegation(xdr, res); 52011da177e4SLinus Torvalds xdr_error: 52023110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 52031da177e4SLinus Torvalds return -EIO; 5204c0eae66eSBenny Halevy out_overflow: 5205c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5206c0eae66eSBenny Halevy return -EIO; 52071da177e4SLinus Torvalds } 52081da177e4SLinus Torvalds 52091da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 52101da177e4SLinus Torvalds { 52111da177e4SLinus Torvalds int status; 52121da177e4SLinus Torvalds 52131da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5214c1d51931STrond Myklebust if (status != -EIO) 5215c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 521607d30434SBenny Halevy if (!status) 521793b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52181da177e4SLinus Torvalds return status; 52191da177e4SLinus Torvalds } 52201da177e4SLinus Torvalds 52211da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 52221da177e4SLinus Torvalds { 52231da177e4SLinus Torvalds int status; 52241da177e4SLinus Torvalds 52251da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5226c1d51931STrond Myklebust if (status != -EIO) 5227c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 522807d30434SBenny Halevy if (!status) 522993b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52301da177e4SLinus Torvalds return status; 52311da177e4SLinus Torvalds } 52321da177e4SLinus Torvalds 52331da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 52341da177e4SLinus Torvalds { 52351da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 52361da177e4SLinus Torvalds } 52371da177e4SLinus Torvalds 52381da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 52391da177e4SLinus Torvalds { 52401da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 52411da177e4SLinus Torvalds } 52421da177e4SLinus Torvalds 52439137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 52449137bdf3SAnna Schumaker struct nfs_pgio_res *res) 52451da177e4SLinus Torvalds { 52468687b63aSAl Viro __be32 *p; 524764bd577eSTrond Myklebust uint32_t count, eof, recvd; 52481da177e4SLinus Torvalds int status; 52491da177e4SLinus Torvalds 52501da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 52511da177e4SLinus Torvalds if (status) 52521da177e4SLinus Torvalds return status; 5253c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5254c0eae66eSBenny Halevy if (unlikely(!p)) 5255c0eae66eSBenny Halevy goto out_overflow; 52566f723f77SBenny Halevy eof = be32_to_cpup(p++); 5257cccddf4fSBenny Halevy count = be32_to_cpup(p); 525864bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 52591da177e4SLinus Torvalds if (count > recvd) { 5260fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 52611da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 52621da177e4SLinus Torvalds count = recvd; 52631da177e4SLinus Torvalds eof = 0; 52641da177e4SLinus Torvalds } 52651da177e4SLinus Torvalds res->eof = eof; 52661da177e4SLinus Torvalds res->count = count; 52671da177e4SLinus Torvalds return 0; 5268c0eae66eSBenny Halevy out_overflow: 5269c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5270c0eae66eSBenny Halevy return -EIO; 52711da177e4SLinus Torvalds } 52721da177e4SLinus Torvalds 52731da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 52741da177e4SLinus Torvalds { 5275bcecff77SChuck Lever int status; 5276cd93710eSChuck Lever __be32 verf[2]; 52771da177e4SLinus Torvalds 52781da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5279db942bbdSBenny Halevy if (!status) 5280db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5281db942bbdSBenny Halevy if (unlikely(status)) 52821da177e4SLinus Torvalds return status; 5283cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 528444109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5285cd93710eSChuck Lever __func__, verf[0], verf[1]); 528664bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 52871da177e4SLinus Torvalds } 52881da177e4SLinus Torvalds 52891da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 52901da177e4SLinus Torvalds { 52911da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5292bcecff77SChuck Lever u32 len, recvd; 52938687b63aSAl Viro __be32 *p; 52941da177e4SLinus Torvalds int status; 52951da177e4SLinus Torvalds 52961da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 52971da177e4SLinus Torvalds if (status) 52981da177e4SLinus Torvalds return status; 52991da177e4SLinus Torvalds 53001da177e4SLinus Torvalds /* Convert length of symlink */ 5301c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5302c0eae66eSBenny Halevy if (unlikely(!p)) 5303c0eae66eSBenny Halevy goto out_overflow; 5304cccddf4fSBenny Halevy len = be32_to_cpup(p); 53051da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5306fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 53071da177e4SLinus Torvalds return -ENAMETOOLONG; 53081da177e4SLinus Torvalds } 530964bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 53101da177e4SLinus Torvalds if (recvd < len) { 5311fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 53121da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 53131da177e4SLinus Torvalds return -EIO; 53141da177e4SLinus Torvalds } 53151da177e4SLinus Torvalds /* 53161da177e4SLinus Torvalds * The XDR encode routine has set things up so that 53171da177e4SLinus Torvalds * the link text will be copied directly into the 53181da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 53191da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 53201da177e4SLinus Torvalds * null-termination). 53211da177e4SLinus Torvalds */ 5322b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 53231da177e4SLinus Torvalds return 0; 5324c0eae66eSBenny Halevy out_overflow: 5325c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5326c0eae66eSBenny Halevy return -EIO; 53271da177e4SLinus Torvalds } 53281da177e4SLinus Torvalds 53291da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 53301da177e4SLinus Torvalds { 53311da177e4SLinus Torvalds int status; 53321da177e4SLinus Torvalds 53331da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 53341da177e4SLinus Torvalds if (status) 53351da177e4SLinus Torvalds goto out; 53361da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 53371da177e4SLinus Torvalds out: 53381da177e4SLinus Torvalds return status; 53391da177e4SLinus Torvalds } 53401da177e4SLinus Torvalds 53411da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 53421da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 53431da177e4SLinus Torvalds { 53441da177e4SLinus Torvalds int status; 53451da177e4SLinus Torvalds 53461da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 53471da177e4SLinus Torvalds if (status) 53481da177e4SLinus Torvalds goto out; 53491da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 53501da177e4SLinus Torvalds goto out; 53511da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 53521da177e4SLinus Torvalds out: 53531da177e4SLinus Torvalds return status; 53541da177e4SLinus Torvalds } 53551da177e4SLinus Torvalds 53561da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 53571da177e4SLinus Torvalds { 53581da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 53591da177e4SLinus Torvalds } 53601da177e4SLinus Torvalds 536156ae19f3STrond Myklebust static int 536256ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 536356ae19f3STrond Myklebust { 536456ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 536556ae19f3STrond Myklebust } 536656ae19f3STrond Myklebust 5367029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5368bf118a34SAndy Adamson struct nfs_getaclres *res) 5369029d105eSJ. Bruce Fields { 5370256e48bbSTrond Myklebust unsigned int savep; 5371029d105eSJ. Bruce Fields uint32_t attrlen, 5372dae100c2SFred Isaman bitmap[3] = {0}; 5373029d105eSJ. Bruce Fields int status; 5374cff298c7STrond Myklebust unsigned int pg_offset; 5375029d105eSJ. Bruce Fields 5376bf118a34SAndy Adamson res->acl_len = 0; 5377029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5378029d105eSJ. Bruce Fields goto out; 53795a006899SSachin Prabhu 5380519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5381519d3959STrond Myklebust 5382cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5383cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 53845a006899SSachin Prabhu 5385029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5386029d105eSJ. Bruce Fields goto out; 5387029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5388029d105eSJ. Bruce Fields goto out; 5389029d105eSJ. Bruce Fields 5390029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5391029d105eSJ. Bruce Fields return -EIO; 5392029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5393029d105eSJ. Bruce Fields 5394bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5395bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5396bf118a34SAndy Adamson * variable length bitmaps.*/ 5397cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5398519d3959STrond Myklebust res->acl_len = attrlen; 53991f1ea6c2STrond Myklebust 54001f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 54011f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 54021f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 54031f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5404519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5405cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5406029d105eSJ. Bruce Fields } 54078c233cf9SJ. Bruce Fields } else 54088c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5409029d105eSJ. Bruce Fields 5410029d105eSJ. Bruce Fields out: 5411029d105eSJ. Bruce Fields return status; 5412029d105eSJ. Bruce Fields } 5413029d105eSJ. Bruce Fields 54141da177e4SLinus Torvalds static int 54151da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 54161da177e4SLinus Torvalds { 54171da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 54181da177e4SLinus Torvalds } 54191da177e4SLinus Torvalds 54209e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 54211da177e4SLinus Torvalds { 54228687b63aSAl Viro __be32 *p; 54231da177e4SLinus Torvalds uint32_t bmlen; 54241da177e4SLinus Torvalds int status; 54251da177e4SLinus Torvalds 54261da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 54271da177e4SLinus Torvalds if (status) 54281da177e4SLinus Torvalds return status; 5429c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5430c0eae66eSBenny Halevy if (unlikely(!p)) 5431c0eae66eSBenny Halevy goto out_overflow; 5432cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5433c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5434c0eae66eSBenny Halevy if (likely(p)) 54351da177e4SLinus Torvalds return 0; 5436c0eae66eSBenny Halevy out_overflow: 5437c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5438c0eae66eSBenny Halevy return -EIO; 54391da177e4SLinus Torvalds } 54401da177e4SLinus Torvalds 5441bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 54421da177e4SLinus Torvalds { 54438687b63aSAl Viro __be32 *p; 54441da177e4SLinus Torvalds uint32_t opnum; 54451da177e4SLinus Torvalds int32_t nfserr; 54461da177e4SLinus Torvalds 5447c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5448c0eae66eSBenny Halevy if (unlikely(!p)) 5449c0eae66eSBenny Halevy goto out_overflow; 54506f723f77SBenny Halevy opnum = be32_to_cpup(p++); 54511da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5452fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 54531da177e4SLinus Torvalds " %d\n", opnum); 54541da177e4SLinus Torvalds return -EIO; 54551da177e4SLinus Torvalds } 5456cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 54571da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5458c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5459c0eae66eSBenny Halevy if (unlikely(!p)) 5460c0eae66eSBenny Halevy goto out_overflow; 5461bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5462bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 54631da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 54641da177e4SLinus Torvalds uint32_t len; 54651da177e4SLinus Torvalds 54661da177e4SLinus Torvalds /* skip netid string */ 5467c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5468c0eae66eSBenny Halevy if (unlikely(!p)) 5469c0eae66eSBenny Halevy goto out_overflow; 5470cccddf4fSBenny Halevy len = be32_to_cpup(p); 5471c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5472c0eae66eSBenny Halevy if (unlikely(!p)) 5473c0eae66eSBenny Halevy goto out_overflow; 54741da177e4SLinus Torvalds 54751da177e4SLinus Torvalds /* skip uaddr string */ 5476c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5477c0eae66eSBenny Halevy if (unlikely(!p)) 5478c0eae66eSBenny Halevy goto out_overflow; 5479cccddf4fSBenny Halevy len = be32_to_cpup(p); 5480c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5481c0eae66eSBenny Halevy if (unlikely(!p)) 5482c0eae66eSBenny Halevy goto out_overflow; 54831da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 54841da177e4SLinus Torvalds } else 5485856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 54861da177e4SLinus Torvalds 54871da177e4SLinus Torvalds return 0; 5488c0eae66eSBenny Halevy out_overflow: 5489c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5490c0eae66eSBenny Halevy return -EIO; 54911da177e4SLinus Torvalds } 54921da177e4SLinus Torvalds 54931da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 54941da177e4SLinus Torvalds { 54951da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 54961da177e4SLinus Torvalds } 54971da177e4SLinus Torvalds 54989137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 54991da177e4SLinus Torvalds { 55008687b63aSAl Viro __be32 *p; 55011da177e4SLinus Torvalds int status; 55021da177e4SLinus Torvalds 55031da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 55041da177e4SLinus Torvalds if (status) 55051da177e4SLinus Torvalds return status; 55061da177e4SLinus Torvalds 55072f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5508c0eae66eSBenny Halevy if (unlikely(!p)) 5509c0eae66eSBenny Halevy goto out_overflow; 55106f723f77SBenny Halevy res->count = be32_to_cpup(p++); 55116f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 55122f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5513c0eae66eSBenny Halevy out_overflow: 5514c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5515c0eae66eSBenny Halevy return -EIO; 55161da177e4SLinus Torvalds } 55171da177e4SLinus Torvalds 55181da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 55191da177e4SLinus Torvalds { 55201da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 55211da177e4SLinus Torvalds } 55221da177e4SLinus Torvalds 5523fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5524fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 55255a5ea0d4SBryan Schumaker { 5526fb15b26fSChuck Lever u32 oid_len; 55275a5ea0d4SBryan Schumaker __be32 *p; 55285a5ea0d4SBryan Schumaker 55295a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55305a5ea0d4SBryan Schumaker if (unlikely(!p)) 55315a5ea0d4SBryan Schumaker goto out_overflow; 5532fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5533fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 55345a5ea0d4SBryan Schumaker goto out_err; 55355a5ea0d4SBryan Schumaker 5536fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 55375a5ea0d4SBryan Schumaker if (unlikely(!p)) 55385a5ea0d4SBryan Schumaker goto out_overflow; 5539fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5540fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 55415a5ea0d4SBryan Schumaker 55425a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 55435a5ea0d4SBryan Schumaker if (unlikely(!p)) 55445a5ea0d4SBryan Schumaker goto out_overflow; 5545fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5546fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 55475a5ea0d4SBryan Schumaker 55485a5ea0d4SBryan Schumaker return 0; 55495a5ea0d4SBryan Schumaker 55505a5ea0d4SBryan Schumaker out_overflow: 55515a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55525a5ea0d4SBryan Schumaker return -EIO; 55535a5ea0d4SBryan Schumaker out_err: 55545a5ea0d4SBryan Schumaker return -EINVAL; 55555a5ea0d4SBryan Schumaker } 55565a5ea0d4SBryan Schumaker 555731e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 55585a5ea0d4SBryan Schumaker { 5559fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5560fb15b26fSChuck Lever unsigned int i, num_flavors; 55615a5ea0d4SBryan Schumaker int status; 55625a5ea0d4SBryan Schumaker __be32 *p; 55635a5ea0d4SBryan Schumaker 55645a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55655a5ea0d4SBryan Schumaker if (unlikely(!p)) 55665a5ea0d4SBryan Schumaker goto out_overflow; 55675a5ea0d4SBryan Schumaker 5568c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5569c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5570c3dfc280SBryan Schumaker 5571c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 55725a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5573c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 55745a5ea0d4SBryan Schumaker break; 55755a5ea0d4SBryan Schumaker 55765a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55775a5ea0d4SBryan Schumaker if (unlikely(!p)) 55785a5ea0d4SBryan Schumaker goto out_overflow; 55795a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 55805a5ea0d4SBryan Schumaker 55815a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5582613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5583613e901eSBryan Schumaker if (status) 5584613e901eSBryan Schumaker goto out; 55855a5ea0d4SBryan Schumaker } 5586c3dfc280SBryan Schumaker res->flavors->num_flavors++; 55875a5ea0d4SBryan Schumaker } 55885a5ea0d4SBryan Schumaker 558931e4dda4SBryan Schumaker status = 0; 5590613e901eSBryan Schumaker out: 5591613e901eSBryan Schumaker return status; 55925a5ea0d4SBryan Schumaker out_overflow: 55935a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55945a5ea0d4SBryan Schumaker return -EIO; 55955a5ea0d4SBryan Schumaker } 55965a5ea0d4SBryan Schumaker 559731e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 559831e4dda4SBryan Schumaker { 559931e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 560031e4dda4SBryan Schumaker if (status) 560131e4dda4SBryan Schumaker return status; 560231e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 560331e4dda4SBryan Schumaker } 560431e4dda4SBryan Schumaker 560599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 560631e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 560731e4dda4SBryan Schumaker { 560831e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 560931e4dda4SBryan Schumaker if (status) 561031e4dda4SBryan Schumaker return status; 561131e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 561231e4dda4SBryan Schumaker } 561331e4dda4SBryan Schumaker 56142031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 56152031cd1aSWeston Andros Adamson { 56162031cd1aSWeston Andros Adamson __be32 *p; 56172031cd1aSWeston Andros Adamson uint32_t bitmap_words; 56182031cd1aSWeston Andros Adamson unsigned int i; 56192031cd1aSWeston Andros Adamson 56202031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56214edabfd7SPan Bian if (!p) 56224edabfd7SPan Bian return -EIO; 56232031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 56242031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 56252031cd1aSWeston Andros Adamson return -EIO; 56262031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 56272031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 56282031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 56292031cd1aSWeston Andros Adamson 56302031cd1aSWeston Andros Adamson return 0; 56312031cd1aSWeston Andros Adamson } 56322031cd1aSWeston Andros Adamson 563399fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 563499fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 563599fe60d0SBenny Halevy { 563699fe60d0SBenny Halevy __be32 *p; 563799fe60d0SBenny Halevy uint32_t dummy; 56382460ba57SBenny Halevy char *dummy_str; 563999fe60d0SBenny Halevy int status; 56407d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 564199fe60d0SBenny Halevy 564299fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 564399fe60d0SBenny Halevy if (status) 564499fe60d0SBenny Halevy return status; 564599fe60d0SBenny Halevy 5646c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5647c0eae66eSBenny Halevy if (unlikely(!p)) 5648c0eae66eSBenny Halevy goto out_overflow; 564932b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5650c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5651c0eae66eSBenny Halevy if (unlikely(!p)) 5652c0eae66eSBenny Halevy goto out_overflow; 565332b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 565432b01310STrond Myklebust res->flags = be32_to_cpup(p++); 565599fe60d0SBenny Halevy 56562031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 56572031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 56582031cd1aSWeston Andros Adamson case SP4_NONE: 56592031cd1aSWeston Andros Adamson break; 56602031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 56612031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 56622031cd1aSWeston Andros Adamson if (status) 56632031cd1aSWeston Andros Adamson return status; 56642031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 56652031cd1aSWeston Andros Adamson if (status) 56662031cd1aSWeston Andros Adamson return status; 56672031cd1aSWeston Andros Adamson break; 56682031cd1aSWeston Andros Adamson default: 56692031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 567099fe60d0SBenny Halevy return -EIO; 56712031cd1aSWeston Andros Adamson } 567299fe60d0SBenny Halevy 5673acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5674c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5675c0eae66eSBenny Halevy if (unlikely(!p)) 5676c0eae66eSBenny Halevy goto out_overflow; 5677acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 567899fe60d0SBenny Halevy 5679acdeb69dSChuck Lever /* server_owner4.so_major_id */ 56802460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56812460ba57SBenny Halevy if (unlikely(status)) 56822460ba57SBenny Halevy return status; 5683acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5684acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 568578fe0f41SWeston Andros Adamson 5686acdeb69dSChuck Lever /* server_scope4 */ 5687acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5688acdeb69dSChuck Lever if (unlikely(status)) 5689acdeb69dSChuck Lever return status; 569078fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 569178fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 569278fe0f41SWeston Andros Adamson 56937d2ed9acSWeston Andros Adamson /* Implementation Id */ 56947d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56957d2ed9acSWeston Andros Adamson if (unlikely(!p)) 56967d2ed9acSWeston Andros Adamson goto out_overflow; 56977d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 56987d2ed9acSWeston Andros Adamson 56997d2ed9acSWeston Andros Adamson if (impl_id_count) { 57007d2ed9acSWeston Andros Adamson /* nii_domain */ 57012460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57022460ba57SBenny Halevy if (unlikely(status)) 57032460ba57SBenny Halevy return status; 57047d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 570599fe60d0SBenny Halevy 57067d2ed9acSWeston Andros Adamson /* nii_name */ 57077d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57087d2ed9acSWeston Andros Adamson if (unlikely(status)) 57097d2ed9acSWeston Andros Adamson return status; 57107d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 57117d2ed9acSWeston Andros Adamson 57127d2ed9acSWeston Andros Adamson /* nii_date */ 57137d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 57147d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57157d2ed9acSWeston Andros Adamson goto out_overflow; 57167d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 57177d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 57187d2ed9acSWeston Andros Adamson 57197d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 57207d2ed9acSWeston Andros Adamson } 572199fe60d0SBenny Halevy return 0; 5722c0eae66eSBenny Halevy out_overflow: 5723c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5724c0eae66eSBenny Halevy return -EIO; 572599fe60d0SBenny Halevy } 5726fc931582SAndy Adamson 5727fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5728fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5729fc931582SAndy Adamson { 5730fc931582SAndy Adamson __be32 *p; 5731c9c30dd5SBenny Halevy u32 nr_attrs, val; 5732fc931582SAndy Adamson 5733c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5734c0eae66eSBenny Halevy if (unlikely(!p)) 5735c0eae66eSBenny Halevy goto out_overflow; 5736c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5737c9c30dd5SBenny Halevy if (val) 5738c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 57396f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 57406f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 57416f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 57426f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 57436f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5744cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5745fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5746a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5747a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5748fc931582SAndy Adamson return -EINVAL; 5749fc931582SAndy Adamson } 5750c0eae66eSBenny Halevy if (nr_attrs == 1) { 5751c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5752c0eae66eSBenny Halevy if (unlikely(!p)) 5753c0eae66eSBenny Halevy goto out_overflow; 5754c0eae66eSBenny Halevy } 5755fc931582SAndy Adamson return 0; 5756c0eae66eSBenny Halevy out_overflow: 5757c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5758c0eae66eSBenny Halevy return -EIO; 5759fc931582SAndy Adamson } 5760fc931582SAndy Adamson 5761e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5762e78291e4SBenny Halevy { 5763e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5764fc931582SAndy Adamson } 5765fc931582SAndy Adamson 57667c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 57677c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 57687c44f1aeSWeston Andros Adamson { 57697c44f1aeSWeston Andros Adamson __be32 *p; 57707c44f1aeSWeston Andros Adamson int status; 57717c44f1aeSWeston Andros Adamson 57727c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 57737c44f1aeSWeston Andros Adamson if (!status) 577471a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 57757c44f1aeSWeston Andros Adamson if (unlikely(status)) 57767c44f1aeSWeston Andros Adamson return status; 57777c44f1aeSWeston Andros Adamson 57787c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 57797c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 57807c44f1aeSWeston Andros Adamson if (unlikely(!p)) 57817c44f1aeSWeston Andros Adamson goto out_overflow; 57827c44f1aeSWeston Andros Adamson 57837c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 57847c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 57857c44f1aeSWeston Andros Adamson return -EIO; 57867c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 57877c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 57887c44f1aeSWeston Andros Adamson else 57897c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 57907c44f1aeSWeston Andros Adamson 57917c44f1aeSWeston Andros Adamson return 0; 57927c44f1aeSWeston Andros Adamson out_overflow: 57937c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 57947c44f1aeSWeston Andros Adamson return -EIO; 57957c44f1aeSWeston Andros Adamson } 57967c44f1aeSWeston Andros Adamson 5797fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5798fc931582SAndy Adamson struct nfs41_create_session_res *res) 5799fc931582SAndy Adamson { 5800fc931582SAndy Adamson __be32 *p; 5801fc931582SAndy Adamson int status; 5802fc931582SAndy Adamson 5803fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5804e78291e4SBenny Halevy if (!status) 580579969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5806e78291e4SBenny Halevy if (unlikely(status)) 5807fc931582SAndy Adamson return status; 5808fc931582SAndy Adamson 5809fc931582SAndy Adamson /* seqid, flags */ 5810c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5811c0eae66eSBenny Halevy if (unlikely(!p)) 5812c0eae66eSBenny Halevy goto out_overflow; 581379969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 581479969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5815fc931582SAndy Adamson 5816fc931582SAndy Adamson /* Channel attributes */ 581779969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5818fc931582SAndy Adamson if (!status) 581979969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5820fc931582SAndy Adamson return status; 5821c0eae66eSBenny Halevy out_overflow: 5822c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5823c0eae66eSBenny Halevy return -EIO; 5824fc931582SAndy Adamson } 58250f3e66c6SAndy Adamson 58260f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 58270f3e66c6SAndy Adamson { 58280f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 58290f3e66c6SAndy Adamson } 583018019753SRicardo Labiaga 583166245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 583266245539STrond Myklebust { 583366245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 583466245539STrond Myklebust } 583566245539STrond Myklebust 583618019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 583718019753SRicardo Labiaga { 583818019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 583918019753SRicardo Labiaga } 584099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 584199fe60d0SBenny Halevy 58429b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 58439b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 58449b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 58459b7b9fccSAndy Adamson { 58469b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5847e3725ec0STrond Myklebust struct nfs4_session *session; 5848fc01cea9SAndy Adamson struct nfs4_sessionid id; 5849fc01cea9SAndy Adamson u32 dummy; 5850fc01cea9SAndy Adamson int status; 5851fc01cea9SAndy Adamson __be32 *p; 5852fc01cea9SAndy Adamson 5853e3725ec0STrond Myklebust if (res->sr_slot == NULL) 58549b7b9fccSAndy Adamson return 0; 58553bd2384aSChuck Lever if (!res->sr_slot->table->session) 58563bd2384aSChuck Lever return 0; 58579b7b9fccSAndy Adamson 5858fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5859e78291e4SBenny Halevy if (!status) 5860e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5861e78291e4SBenny Halevy if (unlikely(status)) 5862fc01cea9SAndy Adamson goto out_err; 58639b7b9fccSAndy Adamson 5864fc01cea9SAndy Adamson /* 5865fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5866fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5867fc01cea9SAndy Adamson */ 5868fdcb4577STrond Myklebust status = -EREMOTEIO; 5869e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5870fc01cea9SAndy Adamson 5871e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5872fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5873fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5874fc01cea9SAndy Adamson goto out_err; 5875fc01cea9SAndy Adamson } 5876e78291e4SBenny Halevy 5877c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5878c0eae66eSBenny Halevy if (unlikely(!p)) 5879c0eae66eSBenny Halevy goto out_overflow; 5880e78291e4SBenny Halevy 5881fc01cea9SAndy Adamson /* seqid */ 58826f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5883dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5884fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5885fc01cea9SAndy Adamson goto out_err; 5886fc01cea9SAndy Adamson } 5887fc01cea9SAndy Adamson /* slot id */ 58886f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5889df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5890fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5891fc01cea9SAndy Adamson goto out_err; 5892fc01cea9SAndy Adamson } 5893da0507b7STrond Myklebust /* highest slot id */ 5894da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5895464ee9f9STrond Myklebust /* target highest slot id */ 5896464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 58970629e370SAlexandros Batsakis /* result flags */ 58980629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5899fc01cea9SAndy Adamson status = 0; 5900fc01cea9SAndy Adamson out_err: 5901fc01cea9SAndy Adamson res->sr_status = status; 5902fc01cea9SAndy Adamson return status; 5903c0eae66eSBenny Halevy out_overflow: 5904c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5905c0eae66eSBenny Halevy status = -EIO; 5906c0eae66eSBenny Halevy goto out_err; 5907fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 59089b7b9fccSAndy Adamson return 0; 5909fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 59109b7b9fccSAndy Adamson } 59119b7b9fccSAndy Adamson 5912b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 591393b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 591493b717fdSTrond Myklebust { 591593b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 591693b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 591793b717fdSTrond Myklebust } 591893b717fdSTrond Myklebust 5919b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 59204e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5921b1f69b75SAndy Adamson { 59224e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5923b1f69b75SAndy Adamson __be32 *p; 5924b1f69b75SAndy Adamson uint32_t len, type; 5925b1f69b75SAndy Adamson int status; 5926b1f69b75SAndy Adamson 5927b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5928b1f69b75SAndy Adamson if (status) { 5929b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5930b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5931b1f69b75SAndy Adamson if (unlikely(!p)) 5932b1f69b75SAndy Adamson goto out_overflow; 5933b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5934b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5935b1f69b75SAndy Adamson __func__, pdev->mincount); 5936b1f69b75SAndy Adamson } 5937b1f69b75SAndy Adamson return status; 5938b1f69b75SAndy Adamson } 5939b1f69b75SAndy Adamson 5940b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5941b1f69b75SAndy Adamson if (unlikely(!p)) 5942b1f69b75SAndy Adamson goto out_overflow; 5943b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5944b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5945b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5946b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5947b1f69b75SAndy Adamson return -EINVAL; 5948b1f69b75SAndy Adamson } 5949b1f69b75SAndy Adamson /* 5950b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5951b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5952b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5953b1f69b75SAndy Adamson */ 5954b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 595513fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 595613fe4ba1STrond Myklebust goto out_overflow; 5957b1f69b75SAndy Adamson 5958b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5959b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5960b1f69b75SAndy Adamson if (unlikely(!p)) 5961b1f69b75SAndy Adamson goto out_overflow; 5962b1f69b75SAndy Adamson len = be32_to_cpup(p); 5963b1f69b75SAndy Adamson if (len) { 5964ead00597SChuck Lever uint32_t i; 5965b1f69b75SAndy Adamson 5966b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5967b1f69b75SAndy Adamson if (unlikely(!p)) 5968b1f69b75SAndy Adamson goto out_overflow; 596984c9dee3SChristoph Hellwig 59704e590803STrond Myklebust res->notification = be32_to_cpup(p++); 597184c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 597284c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 597384c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 5974b1f69b75SAndy Adamson __func__); 5975b1f69b75SAndy Adamson return -EIO; 5976b1f69b75SAndy Adamson } 5977b1f69b75SAndy Adamson } 5978b1f69b75SAndy Adamson } 5979b1f69b75SAndy Adamson return 0; 5980b1f69b75SAndy Adamson out_overflow: 5981b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5982b1f69b75SAndy Adamson return -EIO; 5983b1f69b75SAndy Adamson } 5984b1f69b75SAndy Adamson 5985b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5986b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5987b1f69b75SAndy Adamson { 5988b1f69b75SAndy Adamson __be32 *p; 5989b1f69b75SAndy Adamson int status; 5990b1f69b75SAndy Adamson u32 layout_count; 599164bd577eSTrond Myklebust u32 recvd; 5992b1f69b75SAndy Adamson 5993b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5994b1f69b75SAndy Adamson if (status) 5995b1f69b75SAndy Adamson return status; 5996ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5997b1f69b75SAndy Adamson if (unlikely(!p)) 5998b1f69b75SAndy Adamson goto out_overflow; 5999ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 600093b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 6001ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6002ea9d23f5STrond Myklebust if (unlikely(!p)) 6003ea9d23f5STrond Myklebust goto out_overflow; 6004b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 6005b1f69b75SAndy Adamson if (!layout_count) { 6006b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 6007b1f69b75SAndy Adamson __func__); 6008b1f69b75SAndy Adamson return -EINVAL; 6009b1f69b75SAndy Adamson } 6010b1f69b75SAndy Adamson 601135124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 6012b1f69b75SAndy Adamson if (unlikely(!p)) 6013b1f69b75SAndy Adamson goto out_overflow; 6014b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 6015b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 6016b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 6017b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 601835124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 6019b1f69b75SAndy Adamson 6020b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 6021b1f69b75SAndy Adamson __func__, 6022b1f69b75SAndy Adamson (unsigned long)res->range.offset, 6023b1f69b75SAndy Adamson (unsigned long)res->range.length, 6024b1f69b75SAndy Adamson res->range.iomode, 6025b1f69b75SAndy Adamson res->type, 602635124a09SWeston Andros Adamson res->layoutp->len); 6027b1f69b75SAndy Adamson 602864bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 602935124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 603035124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 603135124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 603235124a09SWeston Andros Adamson res->layoutp->len, recvd); 603335124a09SWeston Andros Adamson return -EINVAL; 603435124a09SWeston Andros Adamson } 603535124a09SWeston Andros Adamson 6036b1f69b75SAndy Adamson if (layout_count > 1) { 6037b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 6038b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 6039b1f69b75SAndy Adamson * the client may see a response that is less than the 6040b1f69b75SAndy Adamson * minimum it requested. 6041b1f69b75SAndy Adamson */ 6042b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 6043b1f69b75SAndy Adamson __func__, layout_count); 6044b1f69b75SAndy Adamson } 6045b1f69b75SAndy Adamson 6046b1f69b75SAndy Adamson return 0; 6047b1f69b75SAndy Adamson out_overflow: 6048b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6049b1f69b75SAndy Adamson return -EIO; 6050b1f69b75SAndy Adamson } 6051863a3c6cSAndy Adamson 6052cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 6053cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6054cbe82603SBenny Halevy { 6055cbe82603SBenny Halevy __be32 *p; 6056cbe82603SBenny Halevy int status; 6057cbe82603SBenny Halevy 6058cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 6059cbe82603SBenny Halevy if (status) 6060cbe82603SBenny Halevy return status; 6061cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 6062cbe82603SBenny Halevy if (unlikely(!p)) 6063cbe82603SBenny Halevy goto out_overflow; 6064cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 6065cbe82603SBenny Halevy if (res->lrs_present) 606693b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 6067cbe82603SBenny Halevy return status; 6068cbe82603SBenny Halevy out_overflow: 6069cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 6070cbe82603SBenny Halevy return -EIO; 6071cbe82603SBenny Halevy } 6072cbe82603SBenny Halevy 6073863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 6074863a3c6cSAndy Adamson struct rpc_rqst *req, 6075863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6076863a3c6cSAndy Adamson { 6077863a3c6cSAndy Adamson __be32 *p; 6078863a3c6cSAndy Adamson __u32 sizechanged; 6079863a3c6cSAndy Adamson int status; 6080863a3c6cSAndy Adamson 6081863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 6082db29c089SAndy Adamson res->status = status; 6083863a3c6cSAndy Adamson if (status) 6084863a3c6cSAndy Adamson return status; 6085863a3c6cSAndy Adamson 6086863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 6087863a3c6cSAndy Adamson if (unlikely(!p)) 6088863a3c6cSAndy Adamson goto out_overflow; 6089863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 6090863a3c6cSAndy Adamson 6091863a3c6cSAndy Adamson if (sizechanged) { 6092863a3c6cSAndy Adamson /* throw away new size */ 6093863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 6094863a3c6cSAndy Adamson if (unlikely(!p)) 6095863a3c6cSAndy Adamson goto out_overflow; 6096863a3c6cSAndy Adamson } 6097863a3c6cSAndy Adamson return 0; 6098863a3c6cSAndy Adamson out_overflow: 6099863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 6100863a3c6cSAndy Adamson return -EIO; 6101863a3c6cSAndy Adamson } 61027d974794SBryan Schumaker 61037d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 61047d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 61057d974794SBryan Schumaker { 61067d974794SBryan Schumaker __be32 *p; 61077d974794SBryan Schumaker int status; 61087d974794SBryan Schumaker int num_res; 61097d974794SBryan Schumaker 61107d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 61117d974794SBryan Schumaker if (status) 61127d974794SBryan Schumaker return status; 61137d974794SBryan Schumaker 61147d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61157d974794SBryan Schumaker if (unlikely(!p)) 61167d974794SBryan Schumaker goto out_overflow; 61177d974794SBryan Schumaker num_res = be32_to_cpup(p++); 61187d974794SBryan Schumaker if (num_res != 1) 61197d974794SBryan Schumaker goto out; 61207d974794SBryan Schumaker 61217d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61227d974794SBryan Schumaker if (unlikely(!p)) 61237d974794SBryan Schumaker goto out_overflow; 61247d974794SBryan Schumaker res->status = be32_to_cpup(p++); 61251cab0652SBryan Schumaker 61261cab0652SBryan Schumaker return status; 61277d974794SBryan Schumaker out_overflow: 61287d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 61297d974794SBryan Schumaker out: 61307d974794SBryan Schumaker return -EIO; 61317d974794SBryan Schumaker } 61329aeda35fSBryan Schumaker 61339aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 61349aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 61359aeda35fSBryan Schumaker { 61369f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 61379aeda35fSBryan Schumaker return res->status; 61389aeda35fSBryan Schumaker } 6139cf805165STrond Myklebust #else 6140cf805165STrond Myklebust static inline 6141cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6142cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6143cf805165STrond Myklebust { 6144cf805165STrond Myklebust return 0; 6145cf805165STrond Myklebust } 6146b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6147b1f69b75SAndy Adamson 61481da177e4SLinus Torvalds /* 614949c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 615049c2559eSBenny Halevy */ 615149c2559eSBenny Halevy 615249c2559eSBenny Halevy /* 61531da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 61541da177e4SLinus Torvalds */ 6155bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6156bf269551SChuck Lever struct xdr_stream *xdr, 6157fc016483SChristoph Hellwig void *data) 61581da177e4SLinus Torvalds { 6159fc016483SChristoph Hellwig struct nfs_closeres *res = data; 61601da177e4SLinus Torvalds struct compound_hdr hdr; 61611da177e4SLinus Torvalds int status; 61621da177e4SLinus Torvalds 6163bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61641da177e4SLinus Torvalds if (status) 61651da177e4SLinus Torvalds goto out; 6166bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61679b7b9fccSAndy Adamson if (status) 61689b7b9fccSAndy Adamson goto out; 6169bf269551SChuck Lever status = decode_putfh(xdr); 61701da177e4SLinus Torvalds if (status) 61711da177e4SLinus Torvalds goto out; 6172b6808145STrond Myklebust if (res->lr_res) { 6173b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6174b6808145STrond Myklebust res->lr_ret = status; 6175b6808145STrond Myklebust if (status) 6176b6808145STrond Myklebust goto out; 6177b6808145STrond Myklebust } 6178bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 61791da177e4SLinus Torvalds out: 61801da177e4SLinus Torvalds return status; 61811da177e4SLinus Torvalds } 61821da177e4SLinus Torvalds 61831da177e4SLinus Torvalds /* 61841da177e4SLinus Torvalds * Decode ACCESS response 61851da177e4SLinus Torvalds */ 6186bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6187fc016483SChristoph Hellwig void *data) 61881da177e4SLinus Torvalds { 6189fc016483SChristoph Hellwig struct nfs4_accessres *res = data; 61901da177e4SLinus Torvalds struct compound_hdr hdr; 61911da177e4SLinus Torvalds int status; 61921da177e4SLinus Torvalds 6193bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61949b7b9fccSAndy Adamson if (status) 61959b7b9fccSAndy Adamson goto out; 6196bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61979b7b9fccSAndy Adamson if (status) 61981da177e4SLinus Torvalds goto out; 6199bf269551SChuck Lever status = decode_putfh(xdr); 620076b32999STrond Myklebust if (status != 0) 620176b32999STrond Myklebust goto out; 62026168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 620376b32999STrond Myklebust if (status != 0) 620476b32999STrond Myklebust goto out; 62056926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62061da177e4SLinus Torvalds out: 62071da177e4SLinus Torvalds return status; 62081da177e4SLinus Torvalds } 62091da177e4SLinus Torvalds 62101da177e4SLinus Torvalds /* 62111da177e4SLinus Torvalds * Decode LOOKUP response 62121da177e4SLinus Torvalds */ 6213bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6214fc016483SChristoph Hellwig void *data) 62151da177e4SLinus Torvalds { 6216fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 62171da177e4SLinus Torvalds struct compound_hdr hdr; 62181da177e4SLinus Torvalds int status; 62191da177e4SLinus Torvalds 6220bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62219b7b9fccSAndy Adamson if (status) 62229b7b9fccSAndy Adamson goto out; 6223bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62249b7b9fccSAndy Adamson if (status) 62251da177e4SLinus Torvalds goto out; 6226bf269551SChuck Lever status = decode_putfh(xdr); 6227bf269551SChuck Lever if (status) 62281da177e4SLinus Torvalds goto out; 6229bf269551SChuck Lever status = decode_lookup(xdr); 6230bf269551SChuck Lever if (status) 62311da177e4SLinus Torvalds goto out; 6232bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6233bf269551SChuck Lever if (status) 62341da177e4SLinus Torvalds goto out; 6235aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62361da177e4SLinus Torvalds out: 62371da177e4SLinus Torvalds return status; 62381da177e4SLinus Torvalds } 62391da177e4SLinus Torvalds 62401da177e4SLinus Torvalds /* 62411da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 62421da177e4SLinus Torvalds */ 6243bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6244bf269551SChuck Lever struct xdr_stream *xdr, 6245fc016483SChristoph Hellwig void *data) 62461da177e4SLinus Torvalds { 6247fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 62481da177e4SLinus Torvalds struct compound_hdr hdr; 62491da177e4SLinus Torvalds int status; 62501da177e4SLinus Torvalds 6251bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62529b7b9fccSAndy Adamson if (status) 62539b7b9fccSAndy Adamson goto out; 6254bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62559b7b9fccSAndy Adamson if (status) 62561da177e4SLinus Torvalds goto out; 6257bf269551SChuck Lever status = decode_putrootfh(xdr); 6258bf269551SChuck Lever if (status) 62591da177e4SLinus Torvalds goto out; 6260bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6261bf269551SChuck Lever if (status == 0) 6262aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6263aa9c2669SDavid Quigley res->label, res->server); 62641da177e4SLinus Torvalds out: 62651da177e4SLinus Torvalds return status; 62661da177e4SLinus Torvalds } 62671da177e4SLinus Torvalds 62681da177e4SLinus Torvalds /* 62691da177e4SLinus Torvalds * Decode REMOVE response 62701da177e4SLinus Torvalds */ 6271bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6272fc016483SChristoph Hellwig void *data) 62731da177e4SLinus Torvalds { 6274fc016483SChristoph Hellwig struct nfs_removeres *res = data; 62751da177e4SLinus Torvalds struct compound_hdr hdr; 62761da177e4SLinus Torvalds int status; 62771da177e4SLinus Torvalds 6278bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62799b7b9fccSAndy Adamson if (status) 62809b7b9fccSAndy Adamson goto out; 6281bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62829b7b9fccSAndy Adamson if (status) 62831da177e4SLinus Torvalds goto out; 6284bf269551SChuck Lever status = decode_putfh(xdr); 6285bf269551SChuck Lever if (status) 628616e42959STrond Myklebust goto out; 6287bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 62881da177e4SLinus Torvalds out: 62891da177e4SLinus Torvalds return status; 62901da177e4SLinus Torvalds } 62911da177e4SLinus Torvalds 62921da177e4SLinus Torvalds /* 62931da177e4SLinus Torvalds * Decode RENAME response 62941da177e4SLinus Torvalds */ 6295bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6296fc016483SChristoph Hellwig void *data) 62971da177e4SLinus Torvalds { 6298fc016483SChristoph Hellwig struct nfs_renameres *res = data; 62991da177e4SLinus Torvalds struct compound_hdr hdr; 63001da177e4SLinus Torvalds int status; 63011da177e4SLinus Torvalds 6302bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63039b7b9fccSAndy Adamson if (status) 63049b7b9fccSAndy Adamson goto out; 6305bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63069b7b9fccSAndy Adamson if (status) 63071da177e4SLinus Torvalds goto out; 6308bf269551SChuck Lever status = decode_putfh(xdr); 6309bf269551SChuck Lever if (status) 63101da177e4SLinus Torvalds goto out; 6311bf269551SChuck Lever status = decode_savefh(xdr); 6312bf269551SChuck Lever if (status) 63131da177e4SLinus Torvalds goto out; 6314bf269551SChuck Lever status = decode_putfh(xdr); 6315bf269551SChuck Lever if (status) 63161da177e4SLinus Torvalds goto out; 6317bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 63181da177e4SLinus Torvalds out: 63191da177e4SLinus Torvalds return status; 63201da177e4SLinus Torvalds } 63211da177e4SLinus Torvalds 63221da177e4SLinus Torvalds /* 63231da177e4SLinus Torvalds * Decode LINK response 63241da177e4SLinus Torvalds */ 6325bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6326fc016483SChristoph Hellwig void *data) 63271da177e4SLinus Torvalds { 6328fc016483SChristoph Hellwig struct nfs4_link_res *res = data; 63291da177e4SLinus Torvalds struct compound_hdr hdr; 63301da177e4SLinus Torvalds int status; 63311da177e4SLinus Torvalds 6332bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63339b7b9fccSAndy Adamson if (status) 63349b7b9fccSAndy Adamson goto out; 6335bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63369b7b9fccSAndy Adamson if (status) 63371da177e4SLinus Torvalds goto out; 6338bf269551SChuck Lever status = decode_putfh(xdr); 6339bf269551SChuck Lever if (status) 63401da177e4SLinus Torvalds goto out; 6341bf269551SChuck Lever status = decode_savefh(xdr); 6342bf269551SChuck Lever if (status) 63431da177e4SLinus Torvalds goto out; 6344bf269551SChuck Lever status = decode_putfh(xdr); 6345bf269551SChuck Lever if (status) 63461da177e4SLinus Torvalds goto out; 6347bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6348bf269551SChuck Lever if (status) 634991ba2eeeSTrond Myklebust goto out; 635091ba2eeeSTrond Myklebust /* 635191ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 635291ba2eeeSTrond Myklebust * filehandle. 635391ba2eeeSTrond Myklebust */ 6354bf269551SChuck Lever status = decode_restorefh(xdr); 6355bf269551SChuck Lever if (status) 635691ba2eeeSTrond Myklebust goto out; 6357aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63581da177e4SLinus Torvalds out: 63591da177e4SLinus Torvalds return status; 63601da177e4SLinus Torvalds } 63611da177e4SLinus Torvalds 63621da177e4SLinus Torvalds /* 63631da177e4SLinus Torvalds * Decode CREATE response 63641da177e4SLinus Torvalds */ 6365bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6366fc016483SChristoph Hellwig void *data) 63671da177e4SLinus Torvalds { 6368fc016483SChristoph Hellwig struct nfs4_create_res *res = data; 63691da177e4SLinus Torvalds struct compound_hdr hdr; 63701da177e4SLinus Torvalds int status; 63711da177e4SLinus Torvalds 6372bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63739b7b9fccSAndy Adamson if (status) 63749b7b9fccSAndy Adamson goto out; 6375bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63769b7b9fccSAndy Adamson if (status) 63771da177e4SLinus Torvalds goto out; 6378bf269551SChuck Lever status = decode_putfh(xdr); 6379bf269551SChuck Lever if (status) 63801da177e4SLinus Torvalds goto out; 6381bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6382bf269551SChuck Lever if (status) 63831da177e4SLinus Torvalds goto out; 6384bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6385bf269551SChuck Lever if (status) 63861da177e4SLinus Torvalds goto out; 6387aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63881da177e4SLinus Torvalds out: 63891da177e4SLinus Torvalds return status; 63901da177e4SLinus Torvalds } 63911da177e4SLinus Torvalds 63921da177e4SLinus Torvalds /* 63931da177e4SLinus Torvalds * Decode SYMLINK response 63941da177e4SLinus Torvalds */ 6395bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6396fc016483SChristoph Hellwig void *res) 63971da177e4SLinus Torvalds { 6398bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 63991da177e4SLinus Torvalds } 64001da177e4SLinus Torvalds 64011da177e4SLinus Torvalds /* 64021da177e4SLinus Torvalds * Decode GETATTR response 64031da177e4SLinus Torvalds */ 6404bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6405fc016483SChristoph Hellwig void *data) 64061da177e4SLinus Torvalds { 6407fc016483SChristoph Hellwig struct nfs4_getattr_res *res = data; 64081da177e4SLinus Torvalds struct compound_hdr hdr; 64091da177e4SLinus Torvalds int status; 64101da177e4SLinus Torvalds 6411bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64121da177e4SLinus Torvalds if (status) 64131da177e4SLinus Torvalds goto out; 6414bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64159b7b9fccSAndy Adamson if (status) 64169b7b9fccSAndy Adamson goto out; 6417bf269551SChuck Lever status = decode_putfh(xdr); 64181da177e4SLinus Torvalds if (status) 64191da177e4SLinus Torvalds goto out; 6420aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64211da177e4SLinus Torvalds out: 64221da177e4SLinus Torvalds return status; 64231da177e4SLinus Torvalds } 64241da177e4SLinus Torvalds 642523ec6965SJ. Bruce Fields /* 642623ec6965SJ. Bruce Fields * Encode an SETACL request 642723ec6965SJ. Bruce Fields */ 64289f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 6429fcc85819SChristoph Hellwig const void *data) 643023ec6965SJ. Bruce Fields { 6431fcc85819SChristoph Hellwig const struct nfs_setaclargs *args = data; 643223ec6965SJ. Bruce Fields struct compound_hdr hdr = { 643366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 643423ec6965SJ. Bruce Fields }; 643523ec6965SJ. Bruce Fields 64369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 64379f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 64389f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 64399f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6440d017931cSAndy Adamson encode_nops(&hdr); 644123ec6965SJ. Bruce Fields } 644205d564feSAndy Adamson 644323ec6965SJ. Bruce Fields /* 644423ec6965SJ. Bruce Fields * Decode SETACL response 644523ec6965SJ. Bruce Fields */ 644623ec6965SJ. Bruce Fields static int 6447bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6448fc016483SChristoph Hellwig void *data) 644923ec6965SJ. Bruce Fields { 6450fc016483SChristoph Hellwig struct nfs_setaclres *res = data; 645123ec6965SJ. Bruce Fields struct compound_hdr hdr; 645223ec6965SJ. Bruce Fields int status; 645323ec6965SJ. Bruce Fields 6454bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 645523ec6965SJ. Bruce Fields if (status) 645623ec6965SJ. Bruce Fields goto out; 6457bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64589b7b9fccSAndy Adamson if (status) 64599b7b9fccSAndy Adamson goto out; 6460bf269551SChuck Lever status = decode_putfh(xdr); 646123ec6965SJ. Bruce Fields if (status) 646223ec6965SJ. Bruce Fields goto out; 6463bf269551SChuck Lever status = decode_setattr(xdr); 646423ec6965SJ. Bruce Fields out: 646523ec6965SJ. Bruce Fields return status; 646623ec6965SJ. Bruce Fields } 64671da177e4SLinus Torvalds 64681da177e4SLinus Torvalds /* 6469029d105eSJ. Bruce Fields * Decode GETACL response 6470029d105eSJ. Bruce Fields */ 6471029d105eSJ. Bruce Fields static int 6472bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6473fc016483SChristoph Hellwig void *data) 6474029d105eSJ. Bruce Fields { 6475fc016483SChristoph Hellwig struct nfs_getaclres *res = data; 6476029d105eSJ. Bruce Fields struct compound_hdr hdr; 6477029d105eSJ. Bruce Fields int status; 6478029d105eSJ. Bruce Fields 6479331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6480331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6481331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6482331818f1STrond Myklebust } 6483bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6484029d105eSJ. Bruce Fields if (status) 6485029d105eSJ. Bruce Fields goto out; 6486bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64879b7b9fccSAndy Adamson if (status) 64889b7b9fccSAndy Adamson goto out; 6489bf269551SChuck Lever status = decode_putfh(xdr); 6490029d105eSJ. Bruce Fields if (status) 6491029d105eSJ. Bruce Fields goto out; 6492bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6493029d105eSJ. Bruce Fields 6494029d105eSJ. Bruce Fields out: 6495029d105eSJ. Bruce Fields return status; 6496029d105eSJ. Bruce Fields } 6497029d105eSJ. Bruce Fields 6498029d105eSJ. Bruce Fields /* 64991da177e4SLinus Torvalds * Decode CLOSE response 65001da177e4SLinus Torvalds */ 6501bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6502fc016483SChristoph Hellwig void *data) 65031da177e4SLinus Torvalds { 6504fc016483SChristoph Hellwig struct nfs_closeres *res = data; 65051da177e4SLinus Torvalds struct compound_hdr hdr; 65061da177e4SLinus Torvalds int status; 65071da177e4SLinus Torvalds 6508bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65091da177e4SLinus Torvalds if (status) 65101da177e4SLinus Torvalds goto out; 6511bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65129b7b9fccSAndy Adamson if (status) 65139b7b9fccSAndy Adamson goto out; 6514bf269551SChuck Lever status = decode_putfh(xdr); 65151da177e4SLinus Torvalds if (status) 65161da177e4SLinus Torvalds goto out; 6517cf805165STrond Myklebust if (res->lr_res) { 6518cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6519cf805165STrond Myklebust res->lr_ret = status; 6520cf805165STrond Myklebust if (status) 6521cf805165STrond Myklebust goto out; 6522cf805165STrond Myklebust } 6523d8d84983STrond Myklebust if (res->fattr != NULL) { 6524d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6525516a6af6STrond Myklebust if (status != 0) 6526516a6af6STrond Myklebust goto out; 6527d8d84983STrond Myklebust } 6528d8d84983STrond Myklebust status = decode_close(xdr, res); 65291da177e4SLinus Torvalds out: 65301da177e4SLinus Torvalds return status; 65311da177e4SLinus Torvalds } 65321da177e4SLinus Torvalds 65331da177e4SLinus Torvalds /* 65341da177e4SLinus Torvalds * Decode OPEN response 65351da177e4SLinus Torvalds */ 6536bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6537fc016483SChristoph Hellwig void *data) 65381da177e4SLinus Torvalds { 6539fc016483SChristoph Hellwig struct nfs_openres *res = data; 65401da177e4SLinus Torvalds struct compound_hdr hdr; 65411da177e4SLinus Torvalds int status; 65421da177e4SLinus Torvalds 6543bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65441da177e4SLinus Torvalds if (status) 65451da177e4SLinus Torvalds goto out; 6546bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65479b7b9fccSAndy Adamson if (status) 65489b7b9fccSAndy Adamson goto out; 6549bf269551SChuck Lever status = decode_putfh(xdr); 65501da177e4SLinus Torvalds if (status) 65511da177e4SLinus Torvalds goto out; 6552bf269551SChuck Lever status = decode_open(xdr, res); 65531da177e4SLinus Torvalds if (status) 65541da177e4SLinus Torvalds goto out; 655501913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 655601913b49SWeston Andros Adamson if (status) 65571da177e4SLinus Torvalds goto out; 6558ae2bb032SWeston Andros Adamson if (res->access_request) 65596168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6560aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 65611da177e4SLinus Torvalds out: 65621da177e4SLinus Torvalds return status; 65631da177e4SLinus Torvalds } 65641da177e4SLinus Torvalds 65651da177e4SLinus Torvalds /* 65661da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 65671da177e4SLinus Torvalds */ 6568bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6569bf269551SChuck Lever struct xdr_stream *xdr, 6570fc016483SChristoph Hellwig void *data) 65711da177e4SLinus Torvalds { 6572fc016483SChristoph Hellwig struct nfs_open_confirmres *res = data; 65731da177e4SLinus Torvalds struct compound_hdr hdr; 65741da177e4SLinus Torvalds int status; 65751da177e4SLinus Torvalds 6576bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65771da177e4SLinus Torvalds if (status) 65781da177e4SLinus Torvalds goto out; 6579bf269551SChuck Lever status = decode_putfh(xdr); 65801da177e4SLinus Torvalds if (status) 65811da177e4SLinus Torvalds goto out; 6582bf269551SChuck Lever status = decode_open_confirm(xdr, res); 65831da177e4SLinus Torvalds out: 65841da177e4SLinus Torvalds return status; 65851da177e4SLinus Torvalds } 65861da177e4SLinus Torvalds 65871da177e4SLinus Torvalds /* 65881da177e4SLinus Torvalds * Decode OPEN response 65891da177e4SLinus Torvalds */ 6590bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6591bf269551SChuck Lever struct xdr_stream *xdr, 6592fc016483SChristoph Hellwig void *data) 65931da177e4SLinus Torvalds { 6594fc016483SChristoph Hellwig struct nfs_openres *res = data; 65951da177e4SLinus Torvalds struct compound_hdr hdr; 65961da177e4SLinus Torvalds int status; 65971da177e4SLinus Torvalds 6598bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65991da177e4SLinus Torvalds if (status) 66001da177e4SLinus Torvalds goto out; 6601bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66029b7b9fccSAndy Adamson if (status) 66039b7b9fccSAndy Adamson goto out; 6604bf269551SChuck Lever status = decode_putfh(xdr); 66051da177e4SLinus Torvalds if (status) 66061da177e4SLinus Torvalds goto out; 6607bf269551SChuck Lever status = decode_open(xdr, res); 6608864472e9STrond Myklebust if (status) 6609864472e9STrond Myklebust goto out; 6610ae2bb032SWeston Andros Adamson if (res->access_request) 66116168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 66126926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 66131da177e4SLinus Torvalds out: 66141da177e4SLinus Torvalds return status; 66151da177e4SLinus Torvalds } 66161da177e4SLinus Torvalds 66171da177e4SLinus Torvalds /* 66181da177e4SLinus Torvalds * Decode SETATTR response 66191da177e4SLinus Torvalds */ 6620bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6621bf269551SChuck Lever struct xdr_stream *xdr, 6622fc016483SChristoph Hellwig void *data) 66231da177e4SLinus Torvalds { 6624fc016483SChristoph Hellwig struct nfs_setattrres *res = data; 66251da177e4SLinus Torvalds struct compound_hdr hdr; 66261da177e4SLinus Torvalds int status; 66271da177e4SLinus Torvalds 6628bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66291da177e4SLinus Torvalds if (status) 66301da177e4SLinus Torvalds goto out; 6631bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66329b7b9fccSAndy Adamson if (status) 66339b7b9fccSAndy Adamson goto out; 6634bf269551SChuck Lever status = decode_putfh(xdr); 66351da177e4SLinus Torvalds if (status) 66361da177e4SLinus Torvalds goto out; 6637bf269551SChuck Lever status = decode_setattr(xdr); 66381da177e4SLinus Torvalds if (status) 66391da177e4SLinus Torvalds goto out; 6640aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 66411da177e4SLinus Torvalds out: 66421da177e4SLinus Torvalds return status; 66431da177e4SLinus Torvalds } 66441da177e4SLinus Torvalds 66451da177e4SLinus Torvalds /* 66461da177e4SLinus Torvalds * Decode LOCK response 66471da177e4SLinus Torvalds */ 6648bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6649fc016483SChristoph Hellwig void *data) 66501da177e4SLinus Torvalds { 6651fc016483SChristoph Hellwig struct nfs_lock_res *res = data; 66521da177e4SLinus Torvalds struct compound_hdr hdr; 66531da177e4SLinus Torvalds int status; 66541da177e4SLinus Torvalds 6655bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66561da177e4SLinus Torvalds if (status) 66571da177e4SLinus Torvalds goto out; 6658bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66599b7b9fccSAndy Adamson if (status) 66609b7b9fccSAndy Adamson goto out; 6661bf269551SChuck Lever status = decode_putfh(xdr); 66621da177e4SLinus Torvalds if (status) 66631da177e4SLinus Torvalds goto out; 6664bf269551SChuck Lever status = decode_lock(xdr, res); 66651da177e4SLinus Torvalds out: 66661da177e4SLinus Torvalds return status; 66671da177e4SLinus Torvalds } 66681da177e4SLinus Torvalds 66691da177e4SLinus Torvalds /* 66701da177e4SLinus Torvalds * Decode LOCKT response 66711da177e4SLinus Torvalds */ 6672bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6673fc016483SChristoph Hellwig void *data) 66741da177e4SLinus Torvalds { 6675fc016483SChristoph Hellwig struct nfs_lockt_res *res = data; 66761da177e4SLinus Torvalds struct compound_hdr hdr; 66771da177e4SLinus Torvalds int status; 66781da177e4SLinus Torvalds 6679bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66801da177e4SLinus Torvalds if (status) 66811da177e4SLinus Torvalds goto out; 6682bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66839b7b9fccSAndy Adamson if (status) 66849b7b9fccSAndy Adamson goto out; 6685bf269551SChuck Lever status = decode_putfh(xdr); 66861da177e4SLinus Torvalds if (status) 66871da177e4SLinus Torvalds goto out; 6688bf269551SChuck Lever status = decode_lockt(xdr, res); 66891da177e4SLinus Torvalds out: 66901da177e4SLinus Torvalds return status; 66911da177e4SLinus Torvalds } 66921da177e4SLinus Torvalds 66931da177e4SLinus Torvalds /* 66941da177e4SLinus Torvalds * Decode LOCKU response 66951da177e4SLinus Torvalds */ 6696bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6697fc016483SChristoph Hellwig void *data) 66981da177e4SLinus Torvalds { 6699fc016483SChristoph Hellwig struct nfs_locku_res *res = data; 67001da177e4SLinus Torvalds struct compound_hdr hdr; 67011da177e4SLinus Torvalds int status; 67021da177e4SLinus Torvalds 6703bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67041da177e4SLinus Torvalds if (status) 67051da177e4SLinus Torvalds goto out; 6706bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67079b7b9fccSAndy Adamson if (status) 67089b7b9fccSAndy Adamson goto out; 6709bf269551SChuck Lever status = decode_putfh(xdr); 67101da177e4SLinus Torvalds if (status) 67111da177e4SLinus Torvalds goto out; 6712bf269551SChuck Lever status = decode_locku(xdr, res); 67131da177e4SLinus Torvalds out: 67141da177e4SLinus Torvalds return status; 67151da177e4SLinus Torvalds } 67161da177e4SLinus Torvalds 6717bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6718bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6719d3c7b7ccSTrond Myklebust { 6720d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6721d3c7b7ccSTrond Myklebust int status; 6722d3c7b7ccSTrond Myklebust 6723bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6724d3c7b7ccSTrond Myklebust if (!status) 6725bf269551SChuck Lever status = decode_release_lockowner(xdr); 6726d3c7b7ccSTrond Myklebust return status; 6727d3c7b7ccSTrond Myklebust } 6728d3c7b7ccSTrond Myklebust 67291da177e4SLinus Torvalds /* 67301da177e4SLinus Torvalds * Decode READLINK response 67311da177e4SLinus Torvalds */ 6732bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6733bf269551SChuck Lever struct xdr_stream *xdr, 6734fc016483SChristoph Hellwig void *data) 67351da177e4SLinus Torvalds { 6736fc016483SChristoph Hellwig struct nfs4_readlink_res *res = data; 67371da177e4SLinus Torvalds struct compound_hdr hdr; 67381da177e4SLinus Torvalds int status; 67391da177e4SLinus Torvalds 6740bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67411da177e4SLinus Torvalds if (status) 67421da177e4SLinus Torvalds goto out; 6743bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67449b7b9fccSAndy Adamson if (status) 67459b7b9fccSAndy Adamson goto out; 6746bf269551SChuck Lever status = decode_putfh(xdr); 67471da177e4SLinus Torvalds if (status) 67481da177e4SLinus Torvalds goto out; 6749bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 67501da177e4SLinus Torvalds out: 67511da177e4SLinus Torvalds return status; 67521da177e4SLinus Torvalds } 67531da177e4SLinus Torvalds 67541da177e4SLinus Torvalds /* 67551da177e4SLinus Torvalds * Decode READDIR response 67561da177e4SLinus Torvalds */ 6757bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6758fc016483SChristoph Hellwig void *data) 67591da177e4SLinus Torvalds { 6760fc016483SChristoph Hellwig struct nfs4_readdir_res *res = data; 67611da177e4SLinus Torvalds struct compound_hdr hdr; 67621da177e4SLinus Torvalds int status; 67631da177e4SLinus Torvalds 6764bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67651da177e4SLinus Torvalds if (status) 67661da177e4SLinus Torvalds goto out; 6767bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67689b7b9fccSAndy Adamson if (status) 67699b7b9fccSAndy Adamson goto out; 6770bf269551SChuck Lever status = decode_putfh(xdr); 67711da177e4SLinus Torvalds if (status) 67721da177e4SLinus Torvalds goto out; 6773bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 67741da177e4SLinus Torvalds out: 67751da177e4SLinus Torvalds return status; 67761da177e4SLinus Torvalds } 67771da177e4SLinus Torvalds 67781da177e4SLinus Torvalds /* 67791da177e4SLinus Torvalds * Decode Read response 67801da177e4SLinus Torvalds */ 6781bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6782fc016483SChristoph Hellwig void *data) 67831da177e4SLinus Torvalds { 6784fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 67851da177e4SLinus Torvalds struct compound_hdr hdr; 67861da177e4SLinus Torvalds int status; 67871da177e4SLinus Torvalds 6788bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6789aabff4ddSPeng Tao res->op_status = hdr.status; 67901da177e4SLinus Torvalds if (status) 67911da177e4SLinus Torvalds goto out; 6792bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67939b7b9fccSAndy Adamson if (status) 67949b7b9fccSAndy Adamson goto out; 6795bf269551SChuck Lever status = decode_putfh(xdr); 67961da177e4SLinus Torvalds if (status) 67971da177e4SLinus Torvalds goto out; 6798bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 67991da177e4SLinus Torvalds if (!status) 68001da177e4SLinus Torvalds status = res->count; 68011da177e4SLinus Torvalds out: 68021da177e4SLinus Torvalds return status; 68031da177e4SLinus Torvalds } 68041da177e4SLinus Torvalds 68051da177e4SLinus Torvalds /* 68061da177e4SLinus Torvalds * Decode WRITE response 68071da177e4SLinus Torvalds */ 6808bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6809fc016483SChristoph Hellwig void *data) 68101da177e4SLinus Torvalds { 6811fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 68121da177e4SLinus Torvalds struct compound_hdr hdr; 68131da177e4SLinus Torvalds int status; 68141da177e4SLinus Torvalds 6815bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6816aabff4ddSPeng Tao res->op_status = hdr.status; 68171da177e4SLinus Torvalds if (status) 68181da177e4SLinus Torvalds goto out; 6819bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68209b7b9fccSAndy Adamson if (status) 68219b7b9fccSAndy Adamson goto out; 6822bf269551SChuck Lever status = decode_putfh(xdr); 68231da177e4SLinus Torvalds if (status) 68241da177e4SLinus Torvalds goto out; 6825bf269551SChuck Lever status = decode_write(xdr, res); 68264f9838c7STrond Myklebust if (status) 68274f9838c7STrond Myklebust goto out; 68287ffd1064SFred Isaman if (res->fattr) 68296926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 68301da177e4SLinus Torvalds if (!status) 68311da177e4SLinus Torvalds status = res->count; 68321da177e4SLinus Torvalds out: 68331da177e4SLinus Torvalds return status; 68341da177e4SLinus Torvalds } 68351da177e4SLinus Torvalds 68361da177e4SLinus Torvalds /* 68371da177e4SLinus Torvalds * Decode COMMIT response 68381da177e4SLinus Torvalds */ 6839bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6840fc016483SChristoph Hellwig void *data) 68411da177e4SLinus Torvalds { 6842fc016483SChristoph Hellwig struct nfs_commitres *res = data; 68431da177e4SLinus Torvalds struct compound_hdr hdr; 68441da177e4SLinus Torvalds int status; 68451da177e4SLinus Torvalds 6846bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6847aabff4ddSPeng Tao res->op_status = hdr.status; 68481da177e4SLinus Torvalds if (status) 68491da177e4SLinus Torvalds goto out; 6850bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68519b7b9fccSAndy Adamson if (status) 68529b7b9fccSAndy Adamson goto out; 6853bf269551SChuck Lever status = decode_putfh(xdr); 68541da177e4SLinus Torvalds if (status) 68551da177e4SLinus Torvalds goto out; 6856bf269551SChuck Lever status = decode_commit(xdr, res); 68571da177e4SLinus Torvalds out: 68581da177e4SLinus Torvalds return status; 68591da177e4SLinus Torvalds } 68601da177e4SLinus Torvalds 68611da177e4SLinus Torvalds /* 68628b173218SRicardo Labiaga * Decode FSINFO response 68631da177e4SLinus Torvalds */ 6864bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 6865fc016483SChristoph Hellwig void *data) 68661da177e4SLinus Torvalds { 6867fc016483SChristoph Hellwig struct nfs4_fsinfo_res *res = data; 68681da177e4SLinus Torvalds struct compound_hdr hdr; 68691da177e4SLinus Torvalds int status; 68701da177e4SLinus Torvalds 6871bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68721da177e4SLinus Torvalds if (!status) 6873bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68749b7b9fccSAndy Adamson if (!status) 6875bf269551SChuck Lever status = decode_putfh(xdr); 68761da177e4SLinus Torvalds if (!status) 6877bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 68781da177e4SLinus Torvalds return status; 68791da177e4SLinus Torvalds } 68801da177e4SLinus Torvalds 68811da177e4SLinus Torvalds /* 68828b173218SRicardo Labiaga * Decode PATHCONF response 68831da177e4SLinus Torvalds */ 6884bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6885fc016483SChristoph Hellwig void *data) 68861da177e4SLinus Torvalds { 6887fc016483SChristoph Hellwig struct nfs4_pathconf_res *res = data; 68881da177e4SLinus Torvalds struct compound_hdr hdr; 68891da177e4SLinus Torvalds int status; 68901da177e4SLinus Torvalds 6891bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68921da177e4SLinus Torvalds if (!status) 6893bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68949b7b9fccSAndy Adamson if (!status) 6895bf269551SChuck Lever status = decode_putfh(xdr); 68961da177e4SLinus Torvalds if (!status) 6897bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 68981da177e4SLinus Torvalds return status; 68991da177e4SLinus Torvalds } 69001da177e4SLinus Torvalds 69011da177e4SLinus Torvalds /* 69028b173218SRicardo Labiaga * Decode STATFS response 69031da177e4SLinus Torvalds */ 6904bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 6905fc016483SChristoph Hellwig void *data) 69061da177e4SLinus Torvalds { 6907fc016483SChristoph Hellwig struct nfs4_statfs_res *res = data; 69081da177e4SLinus Torvalds struct compound_hdr hdr; 69091da177e4SLinus Torvalds int status; 69101da177e4SLinus Torvalds 6911bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69121da177e4SLinus Torvalds if (!status) 6913bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69149b7b9fccSAndy Adamson if (!status) 6915bf269551SChuck Lever status = decode_putfh(xdr); 69161da177e4SLinus Torvalds if (!status) 6917bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 69181da177e4SLinus Torvalds return status; 69191da177e4SLinus Torvalds } 69201da177e4SLinus Torvalds 69211da177e4SLinus Torvalds /* 69228b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 69231da177e4SLinus Torvalds */ 6924bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6925bf269551SChuck Lever struct xdr_stream *xdr, 6926fc016483SChristoph Hellwig void *data) 69271da177e4SLinus Torvalds { 6928fc016483SChristoph Hellwig struct nfs4_server_caps_res *res = data; 69291da177e4SLinus Torvalds struct compound_hdr hdr; 69301da177e4SLinus Torvalds int status; 69311da177e4SLinus Torvalds 6932bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69339b7b9fccSAndy Adamson if (status) 69349b7b9fccSAndy Adamson goto out; 6935bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69369b7b9fccSAndy Adamson if (status) 69371da177e4SLinus Torvalds goto out; 6938bf269551SChuck Lever status = decode_putfh(xdr); 6939bf269551SChuck Lever if (status) 69401da177e4SLinus Torvalds goto out; 6941bf269551SChuck Lever status = decode_server_caps(xdr, res); 69421da177e4SLinus Torvalds out: 69431da177e4SLinus Torvalds return status; 69441da177e4SLinus Torvalds } 69451da177e4SLinus Torvalds 69461da177e4SLinus Torvalds /* 69471da177e4SLinus Torvalds * Decode RENEW response 69481da177e4SLinus Torvalds */ 6949bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6950bf269551SChuck Lever void *__unused) 69511da177e4SLinus Torvalds { 69521da177e4SLinus Torvalds struct compound_hdr hdr; 69531da177e4SLinus Torvalds int status; 69541da177e4SLinus Torvalds 6955bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69561da177e4SLinus Torvalds if (!status) 6957bf269551SChuck Lever status = decode_renew(xdr); 69581da177e4SLinus Torvalds return status; 69591da177e4SLinus Torvalds } 69601da177e4SLinus Torvalds 69611da177e4SLinus Torvalds /* 69628b173218SRicardo Labiaga * Decode SETCLIENTID response 69631da177e4SLinus Torvalds */ 6964bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6965bf269551SChuck Lever struct xdr_stream *xdr, 6966fc016483SChristoph Hellwig void *data) 69671da177e4SLinus Torvalds { 6968fc016483SChristoph Hellwig struct nfs4_setclientid_res *res = data; 69691da177e4SLinus Torvalds struct compound_hdr hdr; 69701da177e4SLinus Torvalds int status; 69711da177e4SLinus Torvalds 6972bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69731da177e4SLinus Torvalds if (!status) 6974bf269551SChuck Lever status = decode_setclientid(xdr, res); 69751da177e4SLinus Torvalds return status; 69761da177e4SLinus Torvalds } 69771da177e4SLinus Torvalds 69781da177e4SLinus Torvalds /* 69798b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 69801da177e4SLinus Torvalds */ 6981bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 6982fc016483SChristoph Hellwig struct xdr_stream *xdr, 6983fc016483SChristoph Hellwig void *data) 69841da177e4SLinus Torvalds { 69851da177e4SLinus Torvalds struct compound_hdr hdr; 69861da177e4SLinus Torvalds int status; 69871da177e4SLinus Torvalds 6988bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69891da177e4SLinus Torvalds if (!status) 6990bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 69911da177e4SLinus Torvalds return status; 69921da177e4SLinus Torvalds } 69931da177e4SLinus Torvalds 69941da177e4SLinus Torvalds /* 69958b173218SRicardo Labiaga * Decode DELEGRETURN response 69961da177e4SLinus Torvalds */ 6997bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6998bf269551SChuck Lever struct xdr_stream *xdr, 6999fc016483SChristoph Hellwig void *data) 70001da177e4SLinus Torvalds { 7001fc016483SChristoph Hellwig struct nfs4_delegreturnres *res = data; 70021da177e4SLinus Torvalds struct compound_hdr hdr; 70031da177e4SLinus Torvalds int status; 70041da177e4SLinus Torvalds 7005bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70069b7b9fccSAndy Adamson if (status) 70079b7b9fccSAndy Adamson goto out; 7008bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 70099b7b9fccSAndy Adamson if (status) 7010fa178f29STrond Myklebust goto out; 7011bf269551SChuck Lever status = decode_putfh(xdr); 7012fa178f29STrond Myklebust if (status != 0) 7013fa178f29STrond Myklebust goto out; 7014586f1c39STrond Myklebust if (res->lr_res) { 7015586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 7016586f1c39STrond Myklebust res->lr_ret = status; 7017586f1c39STrond Myklebust if (status) 7018586f1c39STrond Myklebust goto out; 7019586f1c39STrond Myklebust } 70208ac2b422STrond Myklebust if (res->fattr) { 7021e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 7022556ae3bbSJeff Layton if (status != 0) 7023556ae3bbSJeff Layton goto out; 70248ac2b422STrond Myklebust } 7025e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 7026fa178f29STrond Myklebust out: 70271da177e4SLinus Torvalds return status; 70281da177e4SLinus Torvalds } 70291da177e4SLinus Torvalds 7030683b57b4STrond Myklebust /* 70318b173218SRicardo Labiaga * Decode FS_LOCATIONS response 7032683b57b4STrond Myklebust */ 7033bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 7034bf269551SChuck Lever struct xdr_stream *xdr, 7035fc016483SChristoph Hellwig void *data) 7036683b57b4STrond Myklebust { 7037fc016483SChristoph Hellwig struct nfs4_fs_locations_res *res = data; 7038683b57b4STrond Myklebust struct compound_hdr hdr; 7039683b57b4STrond Myklebust int status; 7040683b57b4STrond Myklebust 7041bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70429b7b9fccSAndy Adamson if (status) 70439b7b9fccSAndy Adamson goto out; 7044bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70459b7b9fccSAndy Adamson if (status) 7046683b57b4STrond Myklebust goto out; 7047bf269551SChuck Lever status = decode_putfh(xdr); 7048bf269551SChuck Lever if (status) 7049683b57b4STrond Myklebust goto out; 7050b03d735bSChuck Lever if (res->migration) { 7051b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7052b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7053b03d735bSChuck Lever &res->fs_locations->fattr, 7054b03d735bSChuck Lever NULL, res->fs_locations, 7055b03d735bSChuck Lever NULL, res->fs_locations->server); 7056b03d735bSChuck Lever if (status) 7057b03d735bSChuck Lever goto out; 7058b03d735bSChuck Lever if (res->renew) 7059b03d735bSChuck Lever status = decode_renew(xdr); 7060b03d735bSChuck Lever } else { 7061bf269551SChuck Lever status = decode_lookup(xdr); 7062bf269551SChuck Lever if (status) 7063683b57b4STrond Myklebust goto out; 7064bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7065b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7066b03d735bSChuck Lever &res->fs_locations->fattr, 70678b7e3f49STrond Myklebust NULL, res->fs_locations, 7068aa9c2669SDavid Quigley NULL, res->fs_locations->server); 7069b03d735bSChuck Lever } 7070683b57b4STrond Myklebust out: 7071683b57b4STrond Myklebust return status; 7072683b57b4STrond Myklebust } 7073683b57b4STrond Myklebust 70745a5ea0d4SBryan Schumaker /* 70755a5ea0d4SBryan Schumaker * Decode SECINFO response 70765a5ea0d4SBryan Schumaker */ 70775a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 70785a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 7079fc016483SChristoph Hellwig void *data) 70805a5ea0d4SBryan Schumaker { 7081fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 70825a5ea0d4SBryan Schumaker struct compound_hdr hdr; 70835a5ea0d4SBryan Schumaker int status; 70845a5ea0d4SBryan Schumaker 70855a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 70865a5ea0d4SBryan Schumaker if (status) 70875a5ea0d4SBryan Schumaker goto out; 70885a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 70895a5ea0d4SBryan Schumaker if (status) 70905a5ea0d4SBryan Schumaker goto out; 70915a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 70925a5ea0d4SBryan Schumaker if (status) 70935a5ea0d4SBryan Schumaker goto out; 70945a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 70955a5ea0d4SBryan Schumaker out: 70965a5ea0d4SBryan Schumaker return status; 70975a5ea0d4SBryan Schumaker } 70985a5ea0d4SBryan Schumaker 709944c99933SChuck Lever /* 710044c99933SChuck Lever * Decode FSID_PRESENT response 710144c99933SChuck Lever */ 710244c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 710344c99933SChuck Lever struct xdr_stream *xdr, 7104fc016483SChristoph Hellwig void *data) 710544c99933SChuck Lever { 7106fc016483SChristoph Hellwig struct nfs4_fsid_present_res *res = data; 710744c99933SChuck Lever struct compound_hdr hdr; 710844c99933SChuck Lever int status; 710944c99933SChuck Lever 711044c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 711144c99933SChuck Lever if (status) 711244c99933SChuck Lever goto out; 711344c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 711444c99933SChuck Lever if (status) 711544c99933SChuck Lever goto out; 711644c99933SChuck Lever status = decode_putfh(xdr); 711744c99933SChuck Lever if (status) 711844c99933SChuck Lever goto out; 711944c99933SChuck Lever status = decode_getfh(xdr, res->fh); 712044c99933SChuck Lever if (status) 712144c99933SChuck Lever goto out; 712244c99933SChuck Lever if (res->renew) 712344c99933SChuck Lever status = decode_renew(xdr); 712444c99933SChuck Lever out: 712544c99933SChuck Lever return status; 712644c99933SChuck Lever } 712744c99933SChuck Lever 712899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 712999fe60d0SBenny Halevy /* 71307c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 71317c44f1aeSWeston Andros Adamson */ 71327c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 71337c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 71347c44f1aeSWeston Andros Adamson void *res) 71357c44f1aeSWeston Andros Adamson { 71367c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 71377c44f1aeSWeston Andros Adamson int status; 71387c44f1aeSWeston Andros Adamson 71397c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 71407c44f1aeSWeston Andros Adamson if (!status) 71417c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 71427c44f1aeSWeston Andros Adamson return status; 71437c44f1aeSWeston Andros Adamson } 71447c44f1aeSWeston Andros Adamson 71457c44f1aeSWeston Andros Adamson /* 71468b173218SRicardo Labiaga * Decode EXCHANGE_ID response 714799fe60d0SBenny Halevy */ 7148bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7149bf269551SChuck Lever struct xdr_stream *xdr, 715099fe60d0SBenny Halevy void *res) 715199fe60d0SBenny Halevy { 715299fe60d0SBenny Halevy struct compound_hdr hdr; 715399fe60d0SBenny Halevy int status; 715499fe60d0SBenny Halevy 7155bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 715699fe60d0SBenny Halevy if (!status) 7157bf269551SChuck Lever status = decode_exchange_id(xdr, res); 715899fe60d0SBenny Halevy return status; 715999fe60d0SBenny Halevy } 71602050f0ccSAndy Adamson 71612050f0ccSAndy Adamson /* 71628b173218SRicardo Labiaga * Decode CREATE_SESSION response 7163fc931582SAndy Adamson */ 7164bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7165bf269551SChuck Lever struct xdr_stream *xdr, 7166fc016483SChristoph Hellwig void *res) 7167fc931582SAndy Adamson { 7168fc931582SAndy Adamson struct compound_hdr hdr; 7169fc931582SAndy Adamson int status; 7170fc931582SAndy Adamson 7171bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7172fc931582SAndy Adamson if (!status) 7173bf269551SChuck Lever status = decode_create_session(xdr, res); 7174fc931582SAndy Adamson return status; 7175fc931582SAndy Adamson } 7176fc931582SAndy Adamson 7177fc931582SAndy Adamson /* 71788b173218SRicardo Labiaga * Decode DESTROY_SESSION response 71790f3e66c6SAndy Adamson */ 7180bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7181bf269551SChuck Lever struct xdr_stream *xdr, 7182bf269551SChuck Lever void *res) 71830f3e66c6SAndy Adamson { 71840f3e66c6SAndy Adamson struct compound_hdr hdr; 71850f3e66c6SAndy Adamson int status; 71860f3e66c6SAndy Adamson 7187bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71880f3e66c6SAndy Adamson if (!status) 7189bf269551SChuck Lever status = decode_destroy_session(xdr, res); 71900f3e66c6SAndy Adamson return status; 71910f3e66c6SAndy Adamson } 71920f3e66c6SAndy Adamson 71930f3e66c6SAndy Adamson /* 719466245539STrond Myklebust * Decode DESTROY_CLIENTID response 719566245539STrond Myklebust */ 719666245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 719766245539STrond Myklebust struct xdr_stream *xdr, 719866245539STrond Myklebust void *res) 719966245539STrond Myklebust { 720066245539STrond Myklebust struct compound_hdr hdr; 720166245539STrond Myklebust int status; 720266245539STrond Myklebust 720366245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 720466245539STrond Myklebust if (!status) 720566245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 720666245539STrond Myklebust return status; 720766245539STrond Myklebust } 720866245539STrond Myklebust 720966245539STrond Myklebust /* 72108b173218SRicardo Labiaga * Decode SEQUENCE response 7211fc01cea9SAndy Adamson */ 7212bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7213bf269551SChuck Lever struct xdr_stream *xdr, 7214fc016483SChristoph Hellwig void *res) 7215fc01cea9SAndy Adamson { 7216fc01cea9SAndy Adamson struct compound_hdr hdr; 7217fc01cea9SAndy Adamson int status; 7218fc01cea9SAndy Adamson 7219bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7220fc01cea9SAndy Adamson if (!status) 7221bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7222fc01cea9SAndy Adamson return status; 7223fc01cea9SAndy Adamson } 7224fc01cea9SAndy Adamson 7225fc01cea9SAndy Adamson /* 72268b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 72272050f0ccSAndy Adamson */ 7228bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7229bf269551SChuck Lever struct xdr_stream *xdr, 7230fc016483SChristoph Hellwig void *data) 72312050f0ccSAndy Adamson { 7232fc016483SChristoph Hellwig struct nfs4_get_lease_time_res *res = data; 72332050f0ccSAndy Adamson struct compound_hdr hdr; 72342050f0ccSAndy Adamson int status; 72352050f0ccSAndy Adamson 7236bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 72372050f0ccSAndy Adamson if (!status) 7238bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 72392050f0ccSAndy Adamson if (!status) 7240bf269551SChuck Lever status = decode_putrootfh(xdr); 72412050f0ccSAndy Adamson if (!status) 7242bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 72432050f0ccSAndy Adamson return status; 72442050f0ccSAndy Adamson } 724518019753SRicardo Labiaga 724618019753SRicardo Labiaga /* 724718019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 724818019753SRicardo Labiaga */ 7249bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7250bf269551SChuck Lever struct xdr_stream *xdr, 7251fc016483SChristoph Hellwig void *data) 725218019753SRicardo Labiaga { 7253fc016483SChristoph Hellwig struct nfs41_reclaim_complete_res *res = data; 725418019753SRicardo Labiaga struct compound_hdr hdr; 725518019753SRicardo Labiaga int status; 725618019753SRicardo Labiaga 7257bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 725818019753SRicardo Labiaga if (!status) 7259bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 726018019753SRicardo Labiaga if (!status) 72618ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 726218019753SRicardo Labiaga return status; 726318019753SRicardo Labiaga } 7264b1f69b75SAndy Adamson 7265b1f69b75SAndy Adamson /* 7266b1f69b75SAndy Adamson * Decode GETDEVINFO response 7267b1f69b75SAndy Adamson */ 7268bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7269bf269551SChuck Lever struct xdr_stream *xdr, 7270fc016483SChristoph Hellwig void *data) 7271b1f69b75SAndy Adamson { 7272fc016483SChristoph Hellwig struct nfs4_getdeviceinfo_res *res = data; 7273b1f69b75SAndy Adamson struct compound_hdr hdr; 7274b1f69b75SAndy Adamson int status; 7275b1f69b75SAndy Adamson 7276bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7277b1f69b75SAndy Adamson if (status != 0) 7278b1f69b75SAndy Adamson goto out; 7279bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7280b1f69b75SAndy Adamson if (status != 0) 7281b1f69b75SAndy Adamson goto out; 72824e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7283b1f69b75SAndy Adamson out: 7284b1f69b75SAndy Adamson return status; 7285b1f69b75SAndy Adamson } 7286b1f69b75SAndy Adamson 7287b1f69b75SAndy Adamson /* 7288b1f69b75SAndy Adamson * Decode LAYOUTGET response 7289b1f69b75SAndy Adamson */ 7290bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7291bf269551SChuck Lever struct xdr_stream *xdr, 7292fc016483SChristoph Hellwig void *data) 7293b1f69b75SAndy Adamson { 7294fc016483SChristoph Hellwig struct nfs4_layoutget_res *res = data; 7295b1f69b75SAndy Adamson struct compound_hdr hdr; 7296b1f69b75SAndy Adamson int status; 7297b1f69b75SAndy Adamson 7298bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7299b1f69b75SAndy Adamson if (status) 7300b1f69b75SAndy Adamson goto out; 7301bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7302b1f69b75SAndy Adamson if (status) 7303b1f69b75SAndy Adamson goto out; 7304bf269551SChuck Lever status = decode_putfh(xdr); 7305b1f69b75SAndy Adamson if (status) 7306b1f69b75SAndy Adamson goto out; 7307bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7308b1f69b75SAndy Adamson out: 7309b1f69b75SAndy Adamson return status; 7310b1f69b75SAndy Adamson } 7311863a3c6cSAndy Adamson 7312863a3c6cSAndy Adamson /* 7313cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7314cbe82603SBenny Halevy */ 7315cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7316cbe82603SBenny Halevy struct xdr_stream *xdr, 7317fc016483SChristoph Hellwig void *data) 7318cbe82603SBenny Halevy { 7319fc016483SChristoph Hellwig struct nfs4_layoutreturn_res *res = data; 7320cbe82603SBenny Halevy struct compound_hdr hdr; 7321cbe82603SBenny Halevy int status; 7322cbe82603SBenny Halevy 7323cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7324cbe82603SBenny Halevy if (status) 7325cbe82603SBenny Halevy goto out; 7326cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7327cbe82603SBenny Halevy if (status) 7328cbe82603SBenny Halevy goto out; 7329cbe82603SBenny Halevy status = decode_putfh(xdr); 7330cbe82603SBenny Halevy if (status) 7331cbe82603SBenny Halevy goto out; 7332cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7333cbe82603SBenny Halevy out: 7334cbe82603SBenny Halevy return status; 7335cbe82603SBenny Halevy } 7336cbe82603SBenny Halevy 7337cbe82603SBenny Halevy /* 7338863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7339863a3c6cSAndy Adamson */ 7340863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7341863a3c6cSAndy Adamson struct xdr_stream *xdr, 7342fc016483SChristoph Hellwig void *data) 7343863a3c6cSAndy Adamson { 7344fc016483SChristoph Hellwig struct nfs4_layoutcommit_res *res = data; 7345863a3c6cSAndy Adamson struct compound_hdr hdr; 7346863a3c6cSAndy Adamson int status; 7347863a3c6cSAndy Adamson 7348863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7349863a3c6cSAndy Adamson if (status) 7350863a3c6cSAndy Adamson goto out; 7351863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7352863a3c6cSAndy Adamson if (status) 7353863a3c6cSAndy Adamson goto out; 7354863a3c6cSAndy Adamson status = decode_putfh(xdr); 7355863a3c6cSAndy Adamson if (status) 7356863a3c6cSAndy Adamson goto out; 7357863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7358863a3c6cSAndy Adamson if (status) 7359863a3c6cSAndy Adamson goto out; 73606926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7361863a3c6cSAndy Adamson out: 7362863a3c6cSAndy Adamson return status; 7363863a3c6cSAndy Adamson } 7364fca78d6dSBryan Schumaker 7365fca78d6dSBryan Schumaker /* 7366fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7367fca78d6dSBryan Schumaker */ 7368fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7369fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7370fc016483SChristoph Hellwig void *data) 7371fca78d6dSBryan Schumaker { 7372fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 7373fca78d6dSBryan Schumaker struct compound_hdr hdr; 7374fca78d6dSBryan Schumaker int status; 7375fca78d6dSBryan Schumaker 7376fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7377fca78d6dSBryan Schumaker if (status) 7378fca78d6dSBryan Schumaker goto out; 7379fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7380fca78d6dSBryan Schumaker if (status) 7381fca78d6dSBryan Schumaker goto out; 7382fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7383fca78d6dSBryan Schumaker if (status) 7384fca78d6dSBryan Schumaker goto out; 738531e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7386fca78d6dSBryan Schumaker out: 7387fca78d6dSBryan Schumaker return status; 7388fca78d6dSBryan Schumaker } 73897d974794SBryan Schumaker 73907d974794SBryan Schumaker /* 73917d974794SBryan Schumaker * Decode TEST_STATEID response 73927d974794SBryan Schumaker */ 73937d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 73947d974794SBryan Schumaker struct xdr_stream *xdr, 7395fc016483SChristoph Hellwig void *data) 73967d974794SBryan Schumaker { 7397fc016483SChristoph Hellwig struct nfs41_test_stateid_res *res = data; 73987d974794SBryan Schumaker struct compound_hdr hdr; 73997d974794SBryan Schumaker int status; 74007d974794SBryan Schumaker 74017d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 74027d974794SBryan Schumaker if (status) 74037d974794SBryan Schumaker goto out; 74047d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 74057d974794SBryan Schumaker if (status) 74067d974794SBryan Schumaker goto out; 74077d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 74087d974794SBryan Schumaker out: 74097d974794SBryan Schumaker return status; 74107d974794SBryan Schumaker } 74119aeda35fSBryan Schumaker 74129aeda35fSBryan Schumaker /* 74139aeda35fSBryan Schumaker * Decode FREE_STATEID response 74149aeda35fSBryan Schumaker */ 74159aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 74169aeda35fSBryan Schumaker struct xdr_stream *xdr, 7417fc016483SChristoph Hellwig void *data) 74189aeda35fSBryan Schumaker { 7419fc016483SChristoph Hellwig struct nfs41_free_stateid_res *res = data; 74209aeda35fSBryan Schumaker struct compound_hdr hdr; 74219aeda35fSBryan Schumaker int status; 74229aeda35fSBryan Schumaker 74239aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 74249aeda35fSBryan Schumaker if (status) 74259aeda35fSBryan Schumaker goto out; 74269aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 74279aeda35fSBryan Schumaker if (status) 74289aeda35fSBryan Schumaker goto out; 74299aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 74309aeda35fSBryan Schumaker out: 74319aeda35fSBryan Schumaker return status; 74329aeda35fSBryan Schumaker } 743399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 743499fe60d0SBenny Halevy 7435573c4e1eSChuck Lever /** 7436573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7437573c4e1eSChuck Lever * the local page cache. 7438573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7439573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7440573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7441573c4e1eSChuck Lever * 7442573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7443573c4e1eSChuck Lever * returned. 7444573c4e1eSChuck Lever * 7445573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7446573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7447573c4e1eSChuck Lever * on a directory already in our cache. 7448573c4e1eSChuck Lever */ 7449573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7450573c4e1eSChuck Lever int plus) 74511da177e4SLinus Torvalds { 7452256e48bbSTrond Myklebust unsigned int savep; 7453dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 74541da177e4SLinus Torvalds uint32_t len; 7455babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7456babddc72SBryan Schumaker if (unlikely(!p)) 7457babddc72SBryan Schumaker goto out_overflow; 7458c08e76d0SChuck Lever if (*p == xdr_zero) { 7459babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7460babddc72SBryan Schumaker if (unlikely(!p)) 7461babddc72SBryan Schumaker goto out_overflow; 7462c08e76d0SChuck Lever if (*p == xdr_zero) 7463573c4e1eSChuck Lever return -EAGAIN; 74641da177e4SLinus Torvalds entry->eof = 1; 7465573c4e1eSChuck Lever return -EBADCOOKIE; 74661da177e4SLinus Torvalds } 74671da177e4SLinus Torvalds 7468babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7469babddc72SBryan Schumaker if (unlikely(!p)) 7470babddc72SBryan Schumaker goto out_overflow; 74711da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 74721da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7473c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7474babddc72SBryan Schumaker 74759af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7476babddc72SBryan Schumaker if (unlikely(!p)) 7477babddc72SBryan Schumaker goto out_overflow; 74781da177e4SLinus Torvalds entry->name = (const char *) p; 74791da177e4SLinus Torvalds 74801da177e4SLinus Torvalds /* 74811da177e4SLinus Torvalds * In case the server doesn't return an inode number, 74821da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 74831da177e4SLinus Torvalds * since glibc seems to choke on it...) 74841da177e4SLinus Torvalds */ 74851da177e4SLinus Torvalds entry->ino = 1; 74864f082222STrond Myklebust entry->fattr->valid = 0; 74871da177e4SLinus Torvalds 74889af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7489babddc72SBryan Schumaker goto out_overflow; 74909af8c222STrond Myklebust 7491256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7492babddc72SBryan Schumaker goto out_overflow; 74939af8c222STrond Myklebust 7494573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7495aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7496babddc72SBryan Schumaker goto out_overflow; 749728331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 749828331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 749928331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 750082f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 75019af8c222STrond Myklebust 75020b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 75030b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 75040b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 75050b26a0bfSTrond Myklebust 7506573c4e1eSChuck Lever return 0; 7507babddc72SBryan Schumaker 7508babddc72SBryan Schumaker out_overflow: 7509babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7510573c4e1eSChuck Lever return -EAGAIN; 75111da177e4SLinus Torvalds } 75121da177e4SLinus Torvalds 75131da177e4SLinus Torvalds /* 75141da177e4SLinus Torvalds * We need to translate between nfs status return values and 75151da177e4SLinus Torvalds * the local errno values which may not be the same. 75161da177e4SLinus Torvalds */ 75171da177e4SLinus Torvalds static struct { 75181da177e4SLinus Torvalds int stat; 75191da177e4SLinus Torvalds int errno; 75201da177e4SLinus Torvalds } nfs_errtbl[] = { 75211da177e4SLinus Torvalds { NFS4_OK, 0 }, 7522856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7523856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7524856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7525856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7526856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7527856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7528856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7529856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7530856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7531856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7532856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7533856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7534856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7535856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7536856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7537856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7538856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7539856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7540856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7541856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7542856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7543856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7544fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7545856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7546856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7547856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7548856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7549856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7550856dff3dSBenny Halevy { -1, -EIO } 75511da177e4SLinus Torvalds }; 75521da177e4SLinus Torvalds 75531da177e4SLinus Torvalds /* 75541da177e4SLinus Torvalds * Convert an NFS error code to a local one. 75551da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 75561da177e4SLinus Torvalds */ 75571da177e4SLinus Torvalds static int 75580a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 75591da177e4SLinus Torvalds { 75601da177e4SLinus Torvalds int i; 75611da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 75621da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 75631da177e4SLinus Torvalds return nfs_errtbl[i].errno; 75641da177e4SLinus Torvalds } 75651da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 75661da177e4SLinus Torvalds /* The server is looney tunes. */ 7567fdcb4577STrond Myklebust return -EREMOTEIO; 75681da177e4SLinus Torvalds } 75691da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 75701da177e4SLinus Torvalds * handle it. 75711da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 75721da177e4SLinus Torvalds * not conflict with native Linux error codes. 75731da177e4SLinus Torvalds */ 7574856dff3dSBenny Halevy return -stat; 75751da177e4SLinus Torvalds } 75761da177e4SLinus Torvalds 75771c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 75781c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 75791c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 75801c6dcbe5SAnna Schumaker 75811da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 75821da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 75831da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 7584fcc85819SChristoph Hellwig .p_encode = nfs4_xdr_##argtype, \ 7585fc016483SChristoph Hellwig .p_decode = nfs4_xdr_##restype, \ 75862bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 75872bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7588cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7589cc0175c1SChuck Lever .p_name = #proc, \ 75901da177e4SLinus Torvalds } 75911da177e4SLinus Torvalds 75927c61f0d3SAnna Schumaker #define STUB(proc) \ 75937c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 75947c61f0d3SAnna Schumaker .p_name = #proc, \ 75957c61f0d3SAnna Schumaker } 75967c61f0d3SAnna Schumaker 75971da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 75981da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 75991da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 76001da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 76011da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 76021da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 76031da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 76041da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 76051da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 76061da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 76071da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 76081da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 76091da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 76101da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 76111da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 76121da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 76131da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 76141da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 76151da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 76161da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 76171da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 76181da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 76191da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 76201da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 76211da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 76221da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 76231da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 76241da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 76251da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 76261da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 76271da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 76281da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7629029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 763023ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7631683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7632d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 76335a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 763444c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 763599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 763699fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7637fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 76380f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7639fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 76402050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 764118019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7642b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7643b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7644863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7645cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7646fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 76477d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 76489aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 76497c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 7650ad24ecfbSTrond Myklebust PROC(BIND_CONN_TO_SESSION, 7651ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 765266245539STrond Myklebust PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 765399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 76541c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 76551c6dcbe5SAnna Schumaker PROC(SEEK, enc_seek, dec_seek), 7656f4ac1674SAnna Schumaker PROC(ALLOCATE, enc_allocate, dec_allocate), 7657624bd5b7SAnna Schumaker PROC(DEALLOCATE, enc_deallocate, dec_deallocate), 7658be3a5d23STrond Myklebust PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 765936022770SPeng Tao PROC(CLONE, enc_clone, dec_clone), 76602e72448bSAnna Schumaker PROC(COPY, enc_copy, dec_copy), 76611c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 76621da177e4SLinus Torvalds }; 76631da177e4SLinus Torvalds 7664a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 76651da177e4SLinus Torvalds .number = 4, 7666e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 76671da177e4SLinus Torvalds .procs = nfs4_procedures 76681da177e4SLinus Torvalds }; 76691da177e4SLinus Torvalds 76701da177e4SLinus Torvalds /* 76711da177e4SLinus Torvalds * Local variables: 76721da177e4SLinus Torvalds * c-basic-offset: 8 76731da177e4SLinus Torvalds * End: 76741da177e4SLinus Torvalds */ 7675