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> 55f092075dSChuck Lever 564ce79717STrond Myklebust #include "nfs4_fs.h" 574882ef72SAlexandros Batsakis #include "internal.h" 5840c64c26SAnna Schumaker #include "nfs4idmap.h" 5976e697baSTrond Myklebust #include "nfs4session.h" 60b1f69b75SAndy Adamson #include "pnfs.h" 61f092075dSChuck Lever #include "netns.h" 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 661da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 671da177e4SLinus Torvalds 6856f487f8SFred Isaman struct compound_hdr; 690a8ea437SDavid Howells static int nfs4_stat_to_errno(int); 7056f487f8SFred Isaman static void encode_layoutget(struct xdr_stream *xdr, 7156f487f8SFred Isaman const struct nfs4_layoutget_args *args, 7256f487f8SFred Isaman struct compound_hdr *hdr); 7356f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 7456f487f8SFred Isaman struct nfs4_layoutget_res *res); 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 771da177e4SLinus Torvalds #ifdef DEBUG 781da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20 791da177e4SLinus Torvalds #else 801da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0 811da177e4SLinus Torvalds #endif 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds /* lock,open owner id: 849f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 851da177e4SLinus Torvalds */ 8695b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2) 87d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4) 889104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 891da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 901da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 911da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1) 921da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2) 939104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 949104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 959104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 969104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 971da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 981da177e4SLinus Torvalds (NFS4_FHSIZE >> 2)) 991da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz) 1001da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 1011da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 1021da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz) 1031da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 1041da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2)) 105e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4 10696928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 10736b3743fSTrond Myklebust #define nfstime4_maxsz (3) 1081da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 1091da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 110bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 111bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 112aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL 113aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */ 114aa9c2669SDavid Quigley #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN)) 115aa9c2669SDavid Quigley #else 116aa9c2669SDavid Quigley #define nfs4_label_maxsz 0 117aa9c2669SDavid Quigley #endif 11888034c3dSAndy Adamson /* We support only one layout type per file system */ 11988034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8) 12096928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */ 12196928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 12236b3743fSTrond Myklebust 3*nfstime4_maxsz + \ 12336b3743fSTrond Myklebust nfs4_owner_maxsz + \ 124aa9c2669SDavid Quigley nfs4_group_maxsz + nfs4_label_maxsz + \ 125aa9c2669SDavid Quigley decode_mdsthreshold_maxsz)) 12696928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 12796928206SJ. Bruce Fields nfs4_fattr_value_maxsz) 12896928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 1299104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 1309104a55dSTrond Myklebust 1 + 2 + 1 + \ 1319104a55dSTrond Myklebust nfs4_owner_maxsz + \ 1329104a55dSTrond Myklebust nfs4_group_maxsz + \ 133aa9c2669SDavid Quigley nfs4_label_maxsz + \ 13436b3743fSTrond Myklebust 1 + nfstime4_maxsz + \ 13536b3743fSTrond Myklebust 1 + nfstime4_maxsz) 1361da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz) 1371da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz) 13856ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 13956ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 1402f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz) 141dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three 142dae100c2SFred Isaman * layout types will be returned. 143dae100c2SFred Isaman */ 144dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 145dae100c2SFred Isaman nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 1461da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 1471da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz) 1481da177e4SLinus Torvalds #define encode_setclientid_maxsz \ 1491da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 150cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 151b8fb2f59SJeff Layton /* client name */ \ 152b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 153cc38bac3SChuck Lever 1 /* sc_prog */ + \ 1546dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1556dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 156cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1571da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1581da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1596dd3436bSChuck Lever 2 /* clientid */ + \ 1606dd3436bSChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 1616dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1626dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) 1631da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \ 1641da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 1651da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2)) 1661da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \ 1671da177e4SLinus Torvalds (op_decode_hdr_maxsz) 168e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 169e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz) 1705b5faaf6SJeff Layton #define encode_lookupp_maxsz (op_encode_hdr_maxsz) 1715b5faaf6SJeff Layton #define decode_lookupp_maxsz (op_decode_hdr_maxsz) 1722cebf828STrond Myklebust #define encode_share_access_maxsz \ 1732cebf828STrond Myklebust (2) 1744882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1752cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1762cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1772cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1782cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1792cebf828STrond Myklebust open_owner_id_maxsz + \ 1802cebf828STrond Myklebust encode_opentype_maxsz + \ 1812cebf828STrond Myklebust encode_claim_null_maxsz) 1825a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz (3) 1832cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1849104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1855a1f6d9eSTrond Myklebust decode_space_limit_maxsz + \ 1862cebf828STrond Myklebust decode_ace_maxsz) 1872cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1882cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1899104a55dSTrond Myklebust decode_stateid_maxsz + \ 1902cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1912cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1922cebf828STrond Myklebust decode_delegation_maxsz) 1939104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1949104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1959104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1969104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1979104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1989104a55dSTrond Myklebust decode_stateid_maxsz) 1999104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 2009104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 2019104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 2029104a55dSTrond Myklebust encode_share_access_maxsz) 2039104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 2049104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 2059104a55dSTrond Myklebust decode_stateid_maxsz) 2069104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 2079104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 2089104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 2099104a55dSTrond Myklebust decode_stateid_maxsz) 2109104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 2119104a55dSTrond Myklebust encode_stateid_maxsz + \ 2129104a55dSTrond Myklebust encode_attrs_maxsz) 2139104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 2149104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 2159104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 2169104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2179104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 2189104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 219aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \ 220aa9c2669SDavid Quigley nfs4_label_maxsz) 2219104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 222a7697f6fSChuck Lever decode_verifier_maxsz) 2239104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 2249104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 2259104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2269104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2279104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2289104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2299104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2309104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2319104a55dSTrond Myklebust decode_verifier_maxsz) 2321da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2331da177e4SLinus Torvalds nfs4_name_maxsz) 2346ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2356ce18391SBenny Halevy decode_change_info_maxsz) 2361da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2371da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2386ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2396ce18391SBenny Halevy decode_change_info_maxsz + \ 2406ce18391SBenny Halevy decode_change_info_maxsz) 2411da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2421da177e4SLinus Torvalds nfs4_name_maxsz) 2436ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 244daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2459104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2469104a55dSTrond Myklebust 7 + \ 247daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 248daccbdedSTrond Myklebust encode_lockowner_maxsz) 2499104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2509104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2519104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2529104a55dSTrond Myklebust decode_lock_denied_maxsz) 253daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 254daccbdedSTrond Myklebust encode_lockowner_maxsz) 2559104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2569104a55dSTrond Myklebust decode_lock_denied_maxsz) 2579104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2589104a55dSTrond Myklebust encode_stateid_maxsz + \ 2599104a55dSTrond Myklebust 4) 2609104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2619104a55dSTrond Myklebust decode_stateid_maxsz) 262d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 263d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 264d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 265d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 266d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2679104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2689104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2691da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2701da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 27194a6d753SChuck Lever 1 + \ 27296928206SJ. Bruce Fields nfs4_fattr_maxsz) 2731da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2741da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2759104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2769104a55dSTrond Myklebust encode_attrs_maxsz) 2772cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2782cebf828STrond Myklebust decode_change_info_maxsz + \ 2792cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2809104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2819104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2821da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2831da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2849104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2859104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2869104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2879104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2889104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2899104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 290e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 291e6889620STrond Myklebust (encode_getattr_maxsz) 292e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 293e6889620STrond Myklebust (0) 2945a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2951650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2969b7b9fccSAndy Adamson 2979b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 298fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 299d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 300d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 301fc931582SAndy Adamson 30299fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 30399fe60d0SBenny Halevy encode_verifier_maxsz + \ 30499fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 305b8fb2f59SJeff Layton /* eia_clientowner */ \ 306b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 30799fe60d0SBenny Halevy 1 /* flags */ + \ 30899fe60d0SBenny Halevy 1 /* spa_how */ + \ 3092031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3102031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3112031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 312db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 313db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 314db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 315db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 316d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 317db8ac8baSWeston Andros Adamson 3 /* nii_date */) 31899fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 31999fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 32099fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 32199fe60d0SBenny Halevy 1 /* eir_flags */ + \ 32299fe60d0SBenny Halevy 1 /* spr_how */ + \ 3232031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3242031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3252031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 32699fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 32799fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 32899fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 32999fe60d0SBenny Halevy /* eir_server_scope<> */ \ 33099fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 33199fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 3327d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3337d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3347d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3357d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3367d2ed9acSWeston Andros Adamson 3 /* nii_date */) 337fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 338fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 339fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 340fc931582SAndy Adamson 1 /* ca_rdma_ird */) 341fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 342fc931582SAndy Adamson 2 /* csa_clientid */ + \ 343fc931582SAndy Adamson 1 /* csa_sequence */ + \ 344fc931582SAndy Adamson 1 /* csa_flags */ + \ 345fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 346fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 347fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 348fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 349fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 350fc931582SAndy Adamson 1 /* stamp */ + \ 351fc931582SAndy Adamson 1 /* machinename.len */ + \ 352fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 353fc931582SAndy Adamson 1 /* uid */ + \ 354fc931582SAndy Adamson 1 /* gid */ + \ 355fc931582SAndy Adamson 1 /* gids.len (0) */) 356fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 357fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 358fc931582SAndy Adamson 1 /* csr_sequence */ + \ 359fc931582SAndy Adamson 1 /* csr_flags */ + \ 360fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 361fc931582SAndy Adamson decode_channel_attrs_maxsz) 3627c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3637c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3647c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3657c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3667c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3677c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3687c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3697c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3707c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3717c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3720f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3730f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 37466245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 37566245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 376fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 377fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 378fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 379fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 38018019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 38118019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 38284c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \ 38384c9dee3SChristoph Hellwig XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 38484c9dee3SChristoph Hellwig 1 /* layout type */ + \ 38584c9dee3SChristoph Hellwig 1 /* maxcount */ + \ 38684c9dee3SChristoph Hellwig 1 /* bitmap size */ + \ 38784c9dee3SChristoph Hellwig 1 /* notification bitmap length */ + \ 38884c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 389b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 390b1f69b75SAndy Adamson 1 /* layout type */ + \ 391b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 392b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 393b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 39484c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 395b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 396b1f69b75SAndy Adamson encode_stateid_maxsz) 397b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 398b1f69b75SAndy Adamson decode_stateid_maxsz + \ 399b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 400863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 401863a3c6cSAndy Adamson 2 /* offset */ + \ 402863a3c6cSAndy Adamson 2 /* length */ + \ 403863a3c6cSAndy Adamson 1 /* reclaim */ + \ 404863a3c6cSAndy Adamson encode_stateid_maxsz + \ 405863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 406863a3c6cSAndy Adamson 2 /* last byte written */ + \ 407863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 408863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 4095f919c9fSChristoph Hellwig 1 /* layoutupdate4 opaqueue len */) 4105f919c9fSChristoph Hellwig /* the actual content of layoutupdate4 should 4115f919c9fSChristoph Hellwig be allocated by drivers and spliced in 4125f919c9fSChristoph Hellwig using xdr_write_pages */ 413863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 414cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 415cbe82603SBenny Halevy encode_stateid_maxsz + \ 4166669cb8bSTrond Myklebust 1 + \ 4176669cb8bSTrond Myklebust XDR_QUADLEN(NFS4_OPAQUE_LIMIT)) 418cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 419cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 420fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 421fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 4227d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 4237d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4247d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 4259aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 4269aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4279f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 4289b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 4299b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 4309b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 431cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0 432cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0 43356f487f8SFred Isaman #define encode_layoutget_maxsz 0 43456f487f8SFred Isaman #define decode_layoutget_maxsz 0 4359b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4369b7b9fccSAndy Adamson 4371da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4381da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4391da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4409b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4411da177e4SLinus Torvalds encode_putfh_maxsz + \ 4429104a55dSTrond Myklebust encode_read_maxsz) 4431da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4449b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4451da177e4SLinus Torvalds decode_putfh_maxsz + \ 4469104a55dSTrond Myklebust decode_read_maxsz) 4471da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4489b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4491da177e4SLinus Torvalds encode_putfh_maxsz + \ 4509104a55dSTrond Myklebust encode_readlink_maxsz) 4511da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4529b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4531da177e4SLinus Torvalds decode_putfh_maxsz + \ 4549104a55dSTrond Myklebust decode_readlink_maxsz) 4551da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4569b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4571da177e4SLinus Torvalds encode_putfh_maxsz + \ 4589104a55dSTrond Myklebust encode_readdir_maxsz) 4591da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4609b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4611da177e4SLinus Torvalds decode_putfh_maxsz + \ 4629104a55dSTrond Myklebust decode_readdir_maxsz) 4631da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4649b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4651da177e4SLinus Torvalds encode_putfh_maxsz + \ 4669104a55dSTrond Myklebust encode_write_maxsz + \ 4674f9838c7STrond Myklebust encode_getattr_maxsz) 4681da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4699b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4701da177e4SLinus Torvalds decode_putfh_maxsz + \ 4719104a55dSTrond Myklebust decode_write_maxsz + \ 4724f9838c7STrond Myklebust decode_getattr_maxsz) 4731da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4749b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4751da177e4SLinus Torvalds encode_putfh_maxsz + \ 4768582715eSTrond Myklebust encode_commit_maxsz) 4771da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4789b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4791da177e4SLinus Torvalds decode_putfh_maxsz + \ 4808582715eSTrond Myklebust decode_commit_maxsz) 4811da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4829b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4831da177e4SLinus Torvalds encode_putfh_maxsz + \ 4842cebf828STrond Myklebust encode_open_maxsz + \ 4856168f62cSWeston Andros Adamson encode_access_maxsz + \ 4862cebf828STrond Myklebust encode_getfh_maxsz + \ 48756f487f8SFred Isaman encode_getattr_maxsz + \ 48856f487f8SFred Isaman encode_layoutget_maxsz) 4891da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4909b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4911da177e4SLinus Torvalds decode_putfh_maxsz + \ 4922cebf828STrond Myklebust decode_open_maxsz + \ 4936168f62cSWeston Andros Adamson decode_access_maxsz + \ 4942cebf828STrond Myklebust decode_getfh_maxsz + \ 49556f487f8SFred Isaman decode_getattr_maxsz + \ 49656f487f8SFred Isaman decode_layoutget_maxsz) 4971da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4981da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4991da177e4SLinus Torvalds encode_putfh_maxsz + \ 5009104a55dSTrond Myklebust encode_open_confirm_maxsz) 5019104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 5029104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 5031da177e4SLinus Torvalds decode_putfh_maxsz + \ 5049104a55dSTrond Myklebust decode_open_confirm_maxsz) 5051da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 5069b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5071da177e4SLinus Torvalds encode_putfh_maxsz + \ 5082cebf828STrond Myklebust encode_open_maxsz + \ 5096168f62cSWeston Andros Adamson encode_access_maxsz + \ 51056f487f8SFred Isaman encode_getattr_maxsz + \ 51156f487f8SFred Isaman encode_layoutget_maxsz) 5121da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 5139b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5141da177e4SLinus Torvalds decode_putfh_maxsz + \ 5152cebf828STrond Myklebust decode_open_maxsz + \ 5166168f62cSWeston Andros Adamson decode_access_maxsz + \ 51756f487f8SFred Isaman decode_getattr_maxsz + \ 51856f487f8SFred Isaman decode_layoutget_maxsz) 5191da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 5201da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5219b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5221da177e4SLinus Torvalds encode_putfh_maxsz + \ 523b6808145STrond Myklebust encode_layoutreturn_maxsz + \ 5243947b74dSTrond Myklebust encode_open_downgrade_maxsz) 5251da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 5261da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5279b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5281da177e4SLinus Torvalds decode_putfh_maxsz + \ 529b6808145STrond Myklebust decode_layoutreturn_maxsz + \ 5303947b74dSTrond Myklebust decode_open_downgrade_maxsz) 5311da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 5329b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5331da177e4SLinus Torvalds encode_putfh_maxsz + \ 534cf805165STrond Myklebust encode_layoutreturn_maxsz + \ 5359104a55dSTrond Myklebust encode_close_maxsz + \ 536516a6af6STrond Myklebust encode_getattr_maxsz) 5371da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 5389b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5391da177e4SLinus Torvalds decode_putfh_maxsz + \ 540cf805165STrond Myklebust decode_layoutreturn_maxsz + \ 5419104a55dSTrond Myklebust decode_close_maxsz + \ 542516a6af6STrond Myklebust decode_getattr_maxsz) 5431da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 5449b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5451da177e4SLinus Torvalds encode_putfh_maxsz + \ 5469104a55dSTrond Myklebust encode_setattr_maxsz + \ 5471da177e4SLinus Torvalds encode_getattr_maxsz) 5481da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5499b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5501da177e4SLinus Torvalds decode_putfh_maxsz + \ 5519104a55dSTrond Myklebust decode_setattr_maxsz + \ 5529104a55dSTrond Myklebust decode_getattr_maxsz) 5531da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5549b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5551da177e4SLinus Torvalds encode_putfh_maxsz + \ 5561da177e4SLinus Torvalds encode_fsinfo_maxsz) 5571da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5589b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5591da177e4SLinus Torvalds decode_putfh_maxsz + \ 5601da177e4SLinus Torvalds decode_fsinfo_maxsz) 5611da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5621da177e4SLinus Torvalds encode_renew_maxsz) 5631da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5641da177e4SLinus Torvalds decode_renew_maxsz) 5651da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5661da177e4SLinus Torvalds encode_setclientid_maxsz) 5671da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5681da177e4SLinus Torvalds decode_setclientid_maxsz) 5691da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5701da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 57183ca7f5aSChuck Lever encode_setclientid_confirm_maxsz) 5721da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5731da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 57483ca7f5aSChuck Lever decode_setclientid_confirm_maxsz) 5751da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5769b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5771da177e4SLinus Torvalds encode_putfh_maxsz + \ 5789104a55dSTrond Myklebust encode_lock_maxsz) 5791da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5809b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5811da177e4SLinus Torvalds decode_putfh_maxsz + \ 5829104a55dSTrond Myklebust decode_lock_maxsz) 5831da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5849b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5851da177e4SLinus Torvalds encode_putfh_maxsz + \ 5869104a55dSTrond Myklebust encode_lockt_maxsz) 5879104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5889b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5899104a55dSTrond Myklebust decode_putfh_maxsz + \ 5909104a55dSTrond Myklebust decode_lockt_maxsz) 5911da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5929b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5931da177e4SLinus Torvalds encode_putfh_maxsz + \ 5949104a55dSTrond Myklebust encode_locku_maxsz) 5951da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5969b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5971da177e4SLinus Torvalds decode_putfh_maxsz + \ 5989104a55dSTrond Myklebust decode_locku_maxsz) 599d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 600d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 601d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 602d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 603d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 604d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 6051da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 6069b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6071da177e4SLinus Torvalds encode_putfh_maxsz + \ 60876b32999STrond Myklebust encode_access_maxsz + \ 60976b32999STrond Myklebust encode_getattr_maxsz) 6101da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 6119b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6121da177e4SLinus Torvalds decode_putfh_maxsz + \ 61376b32999STrond Myklebust decode_access_maxsz + \ 61476b32999STrond Myklebust decode_getattr_maxsz) 6151da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 6169b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6171da177e4SLinus Torvalds encode_putfh_maxsz + \ 61844c99933SChuck Lever encode_getattr_maxsz + \ 61944c99933SChuck Lever encode_renew_maxsz) 6201da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 6219b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6221da177e4SLinus Torvalds decode_putfh_maxsz + \ 62344c99933SChuck Lever decode_getattr_maxsz + \ 62444c99933SChuck Lever decode_renew_maxsz) 6251da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 6269b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6271da177e4SLinus Torvalds encode_putfh_maxsz + \ 6281da177e4SLinus Torvalds encode_lookup_maxsz + \ 6291da177e4SLinus Torvalds encode_getattr_maxsz + \ 6301da177e4SLinus Torvalds encode_getfh_maxsz) 6311da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 6329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6331da177e4SLinus Torvalds decode_putfh_maxsz + \ 634e6889620STrond Myklebust decode_lookup_maxsz + \ 6351da177e4SLinus Torvalds decode_getattr_maxsz + \ 6361da177e4SLinus Torvalds decode_getfh_maxsz) 6375b5faaf6SJeff Layton #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \ 6385b5faaf6SJeff Layton encode_sequence_maxsz + \ 6395b5faaf6SJeff Layton encode_putfh_maxsz + \ 6405b5faaf6SJeff Layton encode_lookupp_maxsz + \ 6415b5faaf6SJeff Layton encode_getattr_maxsz + \ 6425b5faaf6SJeff Layton encode_getfh_maxsz) 6435b5faaf6SJeff Layton #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \ 6445b5faaf6SJeff Layton decode_sequence_maxsz + \ 6455b5faaf6SJeff Layton decode_putfh_maxsz + \ 6465b5faaf6SJeff Layton decode_lookupp_maxsz + \ 6475b5faaf6SJeff Layton decode_getattr_maxsz + \ 6485b5faaf6SJeff Layton decode_getfh_maxsz) 6491da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 6509b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6511da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 6521da177e4SLinus Torvalds encode_getattr_maxsz + \ 6531da177e4SLinus Torvalds encode_getfh_maxsz) 6541da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6559b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6561da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6571da177e4SLinus Torvalds decode_getattr_maxsz + \ 6581da177e4SLinus Torvalds decode_getfh_maxsz) 6591da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6609b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6611da177e4SLinus Torvalds encode_putfh_maxsz + \ 662778d2817STrond Myklebust encode_remove_maxsz) 6631da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6649b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6651da177e4SLinus Torvalds decode_putfh_maxsz + \ 666778d2817STrond Myklebust decode_remove_maxsz) 6671da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6689b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6691da177e4SLinus Torvalds encode_putfh_maxsz + \ 6701da177e4SLinus Torvalds encode_savefh_maxsz + \ 6711da177e4SLinus Torvalds encode_putfh_maxsz + \ 672778d2817STrond Myklebust encode_rename_maxsz) 6731da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6749b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6751da177e4SLinus Torvalds decode_putfh_maxsz + \ 6761da177e4SLinus Torvalds decode_savefh_maxsz + \ 6771da177e4SLinus Torvalds decode_putfh_maxsz + \ 678778d2817STrond Myklebust decode_rename_maxsz) 6791da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6809b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6811da177e4SLinus Torvalds encode_putfh_maxsz + \ 6821da177e4SLinus Torvalds encode_savefh_maxsz + \ 6831da177e4SLinus Torvalds encode_putfh_maxsz + \ 68491ba2eeeSTrond Myklebust encode_link_maxsz + \ 68591ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 686a9f6991bSTrond Myklebust encode_getattr_maxsz) 6871da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6889b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6891da177e4SLinus Torvalds decode_putfh_maxsz + \ 6901da177e4SLinus Torvalds decode_savefh_maxsz + \ 6911da177e4SLinus Torvalds decode_putfh_maxsz + \ 69291ba2eeeSTrond Myklebust decode_link_maxsz + \ 69391ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 69491ba2eeeSTrond Myklebust decode_getattr_maxsz) 6951da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6969b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6971da177e4SLinus Torvalds encode_putfh_maxsz + \ 6981da177e4SLinus Torvalds encode_symlink_maxsz + \ 6991da177e4SLinus Torvalds encode_getattr_maxsz + \ 7001da177e4SLinus Torvalds encode_getfh_maxsz) 7011da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 7029b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7031da177e4SLinus Torvalds decode_putfh_maxsz + \ 7041da177e4SLinus Torvalds decode_symlink_maxsz + \ 7051da177e4SLinus Torvalds decode_getattr_maxsz + \ 7061da177e4SLinus Torvalds decode_getfh_maxsz) 7071da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 7089b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7091da177e4SLinus Torvalds encode_putfh_maxsz + \ 7101da177e4SLinus Torvalds encode_create_maxsz + \ 71156ae19f3STrond Myklebust encode_getfh_maxsz + \ 71256ae19f3STrond Myklebust encode_getattr_maxsz) 7131da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 7149b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7151da177e4SLinus Torvalds decode_putfh_maxsz + \ 7161da177e4SLinus Torvalds decode_create_maxsz + \ 71756ae19f3STrond Myklebust decode_getfh_maxsz + \ 71856ae19f3STrond Myklebust decode_getattr_maxsz) 7191da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 7209b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7211da177e4SLinus Torvalds encode_putfh_maxsz + \ 7221da177e4SLinus Torvalds encode_getattr_maxsz) 7231da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 7249b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7251da177e4SLinus Torvalds decode_putfh_maxsz + \ 7261da177e4SLinus Torvalds decode_getattr_maxsz) 7271da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 7289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7291da177e4SLinus Torvalds encode_putfh_maxsz + \ 7309104a55dSTrond Myklebust encode_statfs_maxsz) 7311da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 7329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7331da177e4SLinus Torvalds decode_putfh_maxsz + \ 7349104a55dSTrond Myklebust decode_statfs_maxsz) 7351da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 7369b7b9fccSAndy Adamson encode_sequence_maxsz + \ 737ab91f264STrond Myklebust encode_putfh_maxsz + \ 7381da177e4SLinus Torvalds encode_getattr_maxsz) 7391da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 7409b7b9fccSAndy Adamson decode_sequence_maxsz + \ 741ab91f264STrond Myklebust decode_putfh_maxsz + \ 7421da177e4SLinus Torvalds decode_getattr_maxsz) 7431da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 7449b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7451da177e4SLinus Torvalds encode_putfh_maxsz + \ 746586f1c39STrond Myklebust encode_layoutreturn_maxsz + \ 747fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 748fa178f29STrond Myklebust encode_getattr_maxsz) 7491da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7509b7b9fccSAndy Adamson decode_sequence_maxsz + \ 751d8434d4cSTrond Myklebust decode_putfh_maxsz + \ 752586f1c39STrond Myklebust decode_layoutreturn_maxsz + \ 753fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 754fa178f29STrond Myklebust decode_getattr_maxsz) 755029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7569b7b9fccSAndy Adamson encode_sequence_maxsz + \ 757029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7589104a55dSTrond Myklebust encode_getacl_maxsz) 759029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7609b7b9fccSAndy Adamson decode_sequence_maxsz + \ 761029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7629104a55dSTrond Myklebust decode_getacl_maxsz) 76323ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7649b7b9fccSAndy Adamson encode_sequence_maxsz + \ 76523ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7669104a55dSTrond Myklebust encode_setacl_maxsz) 76723ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7689b7b9fccSAndy Adamson decode_sequence_maxsz + \ 76923ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7709104a55dSTrond Myklebust decode_setacl_maxsz) 771683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 772683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7739b7b9fccSAndy Adamson encode_sequence_maxsz + \ 774683b57b4STrond Myklebust encode_putfh_maxsz + \ 775e6889620STrond Myklebust encode_lookup_maxsz + \ 776b03d735bSChuck Lever encode_fs_locations_maxsz + \ 777b03d735bSChuck Lever encode_renew_maxsz) 778683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 779683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7809b7b9fccSAndy Adamson decode_sequence_maxsz + \ 781683b57b4STrond Myklebust decode_putfh_maxsz + \ 782e6889620STrond Myklebust decode_lookup_maxsz + \ 783b03d735bSChuck Lever decode_fs_locations_maxsz + \ 784b03d735bSChuck Lever decode_renew_maxsz) 7855a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7865a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7875a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7885a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7895a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7905a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7915a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7925a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 79344c99933SChuck Lever #define NFS4_enc_fsid_present_sz \ 79444c99933SChuck Lever (compound_encode_hdr_maxsz + \ 79544c99933SChuck Lever encode_sequence_maxsz + \ 79644c99933SChuck Lever encode_putfh_maxsz + \ 79744c99933SChuck Lever encode_getfh_maxsz + \ 79844c99933SChuck Lever encode_renew_maxsz) 79944c99933SChuck Lever #define NFS4_dec_fsid_present_sz \ 80044c99933SChuck Lever (compound_decode_hdr_maxsz + \ 80144c99933SChuck Lever decode_sequence_maxsz + \ 80244c99933SChuck Lever decode_putfh_maxsz + \ 80344c99933SChuck Lever decode_getfh_maxsz + \ 80444c99933SChuck Lever decode_renew_maxsz) 80599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 8067c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 8077c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 8087c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 8097c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 8107c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 8117c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 81299fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 81399fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 81499fe60d0SBenny Halevy encode_exchange_id_maxsz) 81599fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 81699fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 81799fe60d0SBenny Halevy decode_exchange_id_maxsz) 818fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 819fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 820fc931582SAndy Adamson encode_create_session_maxsz) 821fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 822fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 823fc931582SAndy Adamson decode_create_session_maxsz) 8240f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 8250f3e66c6SAndy Adamson encode_destroy_session_maxsz) 8260f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 8270f3e66c6SAndy Adamson decode_destroy_session_maxsz) 82866245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 82966245539STrond Myklebust encode_destroy_clientid_maxsz) 83066245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 83166245539STrond Myklebust decode_destroy_clientid_maxsz) 832fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 833fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 834fc01cea9SAndy Adamson encode_sequence_maxsz) 835fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 836fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 837fc01cea9SAndy Adamson decode_sequence_maxsz) 8382050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 8392050f0ccSAndy Adamson encode_sequence_maxsz + \ 8402050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 8412050f0ccSAndy Adamson encode_fsinfo_maxsz) 8422050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 8432050f0ccSAndy Adamson decode_sequence_maxsz + \ 8442050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 8452050f0ccSAndy Adamson decode_fsinfo_maxsz) 84618019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 84718019753SRicardo Labiaga encode_sequence_maxsz + \ 84818019753SRicardo Labiaga encode_reclaim_complete_maxsz) 84918019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 85018019753SRicardo Labiaga decode_sequence_maxsz + \ 85118019753SRicardo Labiaga decode_reclaim_complete_maxsz) 852b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 853b1f69b75SAndy Adamson encode_sequence_maxsz +\ 854b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 855b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 856b1f69b75SAndy Adamson decode_sequence_maxsz + \ 857b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 858b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 859b1f69b75SAndy Adamson encode_sequence_maxsz + \ 860b1f69b75SAndy Adamson encode_putfh_maxsz + \ 861b1f69b75SAndy Adamson encode_layoutget_maxsz) 862b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 863b1f69b75SAndy Adamson decode_sequence_maxsz + \ 864b1f69b75SAndy Adamson decode_putfh_maxsz + \ 865b1f69b75SAndy Adamson decode_layoutget_maxsz) 866863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 867863a3c6cSAndy Adamson encode_sequence_maxsz +\ 868863a3c6cSAndy Adamson encode_putfh_maxsz + \ 869863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 870863a3c6cSAndy Adamson encode_getattr_maxsz) 871863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 872863a3c6cSAndy Adamson decode_sequence_maxsz + \ 873863a3c6cSAndy Adamson decode_putfh_maxsz + \ 874863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 875863a3c6cSAndy Adamson decode_getattr_maxsz) 876cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 877cbe82603SBenny Halevy encode_sequence_maxsz + \ 878cbe82603SBenny Halevy encode_putfh_maxsz + \ 879cbe82603SBenny Halevy encode_layoutreturn_maxsz) 880cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 881cbe82603SBenny Halevy decode_sequence_maxsz + \ 882cbe82603SBenny Halevy decode_putfh_maxsz + \ 883cbe82603SBenny Halevy decode_layoutreturn_maxsz) 884fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 885fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 886fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 887fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 888fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 889fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 890fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 891fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8927d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8937d974794SBryan Schumaker encode_sequence_maxsz + \ 8947d974794SBryan Schumaker encode_test_stateid_maxsz) 8957d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8967d974794SBryan Schumaker decode_sequence_maxsz + \ 8977d974794SBryan Schumaker decode_test_stateid_maxsz) 8989aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8999aeda35fSBryan Schumaker encode_sequence_maxsz + \ 9009aeda35fSBryan Schumaker encode_free_stateid_maxsz) 9019aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 9029aeda35fSBryan Schumaker decode_sequence_maxsz + \ 9039aeda35fSBryan Schumaker decode_free_stateid_maxsz) 9042449ea2eSAlexandros Batsakis 9052449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 9062449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 9072449ea2eSAlexandros Batsakis encode_sequence_maxsz + 9082449ea2eSAlexandros Batsakis encode_putfh_maxsz + 9092449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 9102449ea2eSAlexandros Batsakis XDR_UNIT); 9112449ea2eSAlexandros Batsakis 9122449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 9132449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 9142449ea2eSAlexandros Batsakis decode_sequence_maxsz + 9152449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 9162449ea2eSAlexandros Batsakis XDR_UNIT); 917f1c097beSAndy Adamson 918f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH + 919f1c097beSAndy Adamson compound_decode_hdr_maxsz + 920f1c097beSAndy Adamson decode_sequence_maxsz) * 921f1c097beSAndy Adamson XDR_UNIT); 922f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 92399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 9241da177e4SLinus Torvalds 925bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 926bca79478STrond Myklebust [NF4BAD] = 0, 927bca79478STrond Myklebust [NF4REG] = S_IFREG, 928bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 929bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 930bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 931bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 932bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 933bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 934bca79478STrond Myklebust [NF4ATTRDIR] = 0, 935bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 9361da177e4SLinus Torvalds }; 9371da177e4SLinus Torvalds 9381da177e4SLinus Torvalds struct compound_hdr { 9391da177e4SLinus Torvalds int32_t status; 9401da177e4SLinus Torvalds uint32_t nops; 941d017931cSAndy Adamson __be32 * nops_p; 9421da177e4SLinus Torvalds uint32_t taglen; 9431da177e4SLinus Torvalds char * tag; 9440c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 94566cc0429SBenny Halevy u32 minorversion; 9461da177e4SLinus Torvalds }; 9471da177e4SLinus Torvalds 94813c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 94913c65ce9SBenny Halevy { 95013c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 95113c65ce9SBenny Halevy BUG_ON(!p); 95213c65ce9SBenny Halevy return p; 95313c65ce9SBenny Halevy } 9541da177e4SLinus Torvalds 955cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 956cb17e556STrond Myklebust { 957ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); 958cb17e556STrond Myklebust } 959cb17e556STrond Myklebust 9601da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 9611da177e4SLinus Torvalds { 962ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0); 9631da177e4SLinus Torvalds } 9641da177e4SLinus Torvalds 9654ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9664ade9821STrond Myklebust { 967ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0); 9684ade9821STrond Myklebust } 9694ade9821STrond Myklebust 970ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 971ff2eb681STrond Myklebust { 972ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0); 973ff2eb681STrond Myklebust } 974ff2eb681STrond Myklebust 97537c88763STrond Myklebust static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr, 97637c88763STrond Myklebust const __u32 *bitmap, size_t len) 97737c88763STrond Myklebust { 97837c88763STrond Myklebust ssize_t ret; 97937c88763STrond Myklebust 98037c88763STrond Myklebust /* Trim empty words */ 98137c88763STrond Myklebust while (len > 0 && bitmap[len-1] == 0) 98237c88763STrond Myklebust len--; 98337c88763STrond Myklebust ret = xdr_stream_encode_uint32_array(xdr, bitmap, len); 98437c88763STrond Myklebust if (WARN_ON_ONCE(ret < 0)) 98537c88763STrond Myklebust return ret; 98637c88763STrond Myklebust return len; 98737c88763STrond Myklebust } 98837c88763STrond Myklebust 98937c88763STrond Myklebust static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask, 99037c88763STrond Myklebust __u32 *res, size_t len) 99137c88763STrond Myklebust { 99237c88763STrond Myklebust size_t i; 99337c88763STrond Myklebust __u32 tmp; 99437c88763STrond Myklebust 99537c88763STrond Myklebust while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0)) 99637c88763STrond Myklebust len--; 99737c88763STrond Myklebust for (i = len; i-- > 0;) { 99837c88763STrond Myklebust tmp = bitmap[i] & mask[i]; 99937c88763STrond Myklebust res[i] = tmp; 100037c88763STrond Myklebust } 100137c88763STrond Myklebust return len; 100237c88763STrond Myklebust } 100337c88763STrond Myklebust 10044ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 10054ade9821STrond Myklebust const struct nfs_seqid *seqid) 10064ade9821STrond Myklebust { 1007a6796419STrond Myklebust if (seqid != NULL) 10084ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 1009a6796419STrond Myklebust else 1010a6796419STrond Myklebust encode_uint32(xdr, 0); 10114ade9821STrond Myklebust } 10124ade9821STrond Myklebust 10130c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 10140c4e8c18SBenny Halevy struct rpc_rqst *req, 10150c4e8c18SBenny Halevy struct compound_hdr *hdr) 10161da177e4SLinus Torvalds { 10178687b63aSAl Viro __be32 *p; 1018a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 10190c4e8c18SBenny Halevy 10200c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 10210c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 10220c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 10230c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 10241da177e4SLinus Torvalds 10257fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 10266fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 10276fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 1028e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 1029d017931cSAndy Adamson hdr->nops_p = p; 103034558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 1031d017931cSAndy Adamson } 1032d017931cSAndy Adamson 1033ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 1034ab19b481STrond Myklebust uint32_t replen, 1035ab19b481STrond Myklebust struct compound_hdr *hdr) 1036ab19b481STrond Myklebust { 1037ab19b481STrond Myklebust encode_uint32(xdr, op); 1038ab19b481STrond Myklebust hdr->nops++; 1039ab19b481STrond Myklebust hdr->replen += replen; 1040ab19b481STrond Myklebust } 1041ab19b481STrond Myklebust 1042d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 1043d017931cSAndy Adamson { 10447fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 1045d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 10461da177e4SLinus Torvalds } 10471da177e4SLinus Torvalds 1048ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1049ea9d23f5STrond Myklebust { 10502d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 1051ea9d23f5STrond Myklebust } 1052ea9d23f5STrond Myklebust 10531da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 10541da177e4SLinus Torvalds { 1055cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 10561da177e4SLinus Torvalds } 10571da177e4SLinus Torvalds 105836b3743fSTrond Myklebust static __be32 * 105936b3743fSTrond Myklebust xdr_encode_nfstime4(__be32 *p, const struct timespec *t) 106036b3743fSTrond Myklebust { 106136b3743fSTrond Myklebust p = xdr_encode_hyper(p, (__s64)t->tv_sec); 106236b3743fSTrond Myklebust *p++ = cpu_to_be32(t->tv_nsec); 106336b3743fSTrond Myklebust return p; 106436b3743fSTrond Myklebust } 106536b3743fSTrond Myklebust 1066aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1067aa9c2669SDavid Quigley const struct nfs4_label *label, 106828cf22d0STrond Myklebust const umode_t *umask, 10695334c5bdSKinglong Mee const struct nfs_server *server, 107028cf22d0STrond Myklebust const uint32_t attrmask[]) 10711da177e4SLinus Torvalds { 10721da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10731da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10741da177e4SLinus Torvalds int owner_namelen = 0; 10751da177e4SLinus Torvalds int owner_grouplen = 0; 10768687b63aSAl Viro __be32 *p; 1077d7067b2dSTrond Myklebust uint32_t len = 0; 1078d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10791da177e4SLinus Torvalds 10801da177e4SLinus Torvalds /* 10811da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10821da177e4SLinus Torvalds */ 108328cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) { 1084d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10851da177e4SLinus Torvalds len += 8; 1086d7067b2dSTrond Myklebust } 1087d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 108828cf22d0STrond Myklebust if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) { 1089dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK; 1090dff25ddbSAndreas Gruenbacher len += 8; 109128cf22d0STrond Myklebust } else if (attrmask[1] & FATTR4_WORD1_MODE) { 1092d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10931da177e4SLinus Torvalds len += 4; 1094d7067b2dSTrond Myklebust } 1095dff25ddbSAndreas Gruenbacher } 109628cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) { 1097e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10981da177e4SLinus Torvalds if (owner_namelen < 0) { 1099fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1100e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 11011da177e4SLinus Torvalds /* XXX */ 11021da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 11031da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 11041da177e4SLinus Torvalds /* goto out; */ 11051da177e4SLinus Torvalds } 1106d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 11071da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 11081da177e4SLinus Torvalds } 110928cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_GID) && 111028cf22d0STrond Myklebust (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) { 1111e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 11121da177e4SLinus Torvalds if (owner_grouplen < 0) { 1113fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1114e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 11151da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 11161da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 11171da177e4SLinus Torvalds /* goto out; */ 11181da177e4SLinus Torvalds } 1119d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 11201da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 11211da177e4SLinus Torvalds } 112228cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 1123d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1124d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 112536b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2); 1126d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1127d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 11281da177e4SLinus Torvalds len += 4; 1129d7067b2dSTrond Myklebust } 113028cf22d0STrond Myklebust } 113128cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 1132d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1133d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 113436b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2); 1135d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1136d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 11371da177e4SLinus Torvalds len += 4; 1138d7067b2dSTrond Myklebust } 11395334c5bdSKinglong Mee } 11405334c5bdSKinglong Mee 114128cf22d0STrond Myklebust if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) { 1142b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1143d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1144d7067b2dSTrond Myklebust } 1145d7067b2dSTrond Myklebust 114640a3426cSTrond Myklebust xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval)); 114740a3426cSTrond Myklebust xdr_stream_encode_opaque_inline(xdr, (void **)&p, len); 11481da177e4SLinus Torvalds 1149d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1150b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1151d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1152e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1153d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1154811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1155d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1156811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1157d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11581da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1159e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 116036b3743fSTrond Myklebust p = xdr_encode_nfstime4(p, &iap->ia_atime); 1161d7067b2dSTrond Myklebust } else 1162e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11631da177e4SLinus Torvalds } 1164d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11651da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1166e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 116736b3743fSTrond Myklebust p = xdr_encode_nfstime4(p, &iap->ia_mtime); 1168d7067b2dSTrond Myklebust } else 1169e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11701da177e4SLinus Torvalds } 1171d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1172aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1173aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1174aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1175aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1176aa9c2669SDavid Quigley } 1177dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1178dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1179dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask); 1180dff25ddbSAndreas Gruenbacher } 11811da177e4SLinus Torvalds 11821da177e4SLinus Torvalds /* out: */ 11831da177e4SLinus Torvalds } 11841da177e4SLinus Torvalds 1185cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11861da177e4SLinus Torvalds { 1187475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1188475d4ba0STrond Myklebust encode_uint32(xdr, access); 11891da177e4SLinus Torvalds } 11901da177e4SLinus Torvalds 1191cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11921da177e4SLinus Torvalds { 1193ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11944ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1195566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11961da177e4SLinus Torvalds } 11971da177e4SLinus Torvalds 11980b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11991da177e4SLinus Torvalds { 12008687b63aSAl Viro __be32 *p; 12011da177e4SLinus Torvalds 1202475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1203475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1204b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 120534558513SBenny Halevy *p = cpu_to_be32(args->count); 12061da177e4SLinus Torvalds } 12071da177e4SLinus Torvalds 1208cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 12091da177e4SLinus Torvalds { 12108687b63aSAl Viro __be32 *p; 12111da177e4SLinus Torvalds 1212475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1213475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 12141da177e4SLinus Torvalds 12151da177e4SLinus Torvalds switch (create->ftype) { 12161da177e4SLinus Torvalds case NF4LNK: 121713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 121834558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 12192fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 12202fcc213aSChuck Lever create->u.symlink.len); 12212fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 12221da177e4SLinus Torvalds break; 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 122513c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1226e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 122734558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 12281da177e4SLinus Torvalds break; 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvalds default: 12311da177e4SLinus Torvalds break; 12321da177e4SLinus Torvalds } 12331da177e4SLinus Torvalds 1234811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 123528cf22d0STrond Myklebust encode_attrs(xdr, create->attrs, create->label, &create->umask, 123628cf22d0STrond Myklebust create->server, create->server->attr_bitmask); 12371da177e4SLinus Torvalds } 12381da177e4SLinus Torvalds 123937c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr, 124037c88763STrond Myklebust const __u32 *bitmap, const __u32 *mask, size_t len, 1241dae100c2SFred Isaman struct compound_hdr *hdr) 1242dae100c2SFred Isaman { 124337c88763STrond Myklebust __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz]; 1244dae100c2SFred Isaman 1245ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 124637c88763STrond Myklebust if (mask) { 124737c88763STrond Myklebust if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap))) 124837c88763STrond Myklebust len = ARRAY_SIZE(masked_bitmap); 124937c88763STrond Myklebust len = mask_bitmap4(bitmap, mask, masked_bitmap, len); 125037c88763STrond Myklebust bitmap = masked_bitmap; 1251dae100c2SFred Isaman } 125237c88763STrond Myklebust xdr_encode_bitmap4(xdr, bitmap, len); 1253dae100c2SFred Isaman } 1254dae100c2SFred Isaman 1255cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12561da177e4SLinus Torvalds { 125737c88763STrond Myklebust encode_getattr(xdr, nfs4_fattr_bitmap, bitmask, 125837c88763STrond Myklebust ARRAY_SIZE(nfs4_fattr_bitmap), hdr); 12591da177e4SLinus Torvalds } 12601da177e4SLinus Torvalds 126188034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12621549210fSTrond Myklebust const u32 *open_bitmap, 126388034c3dSAndy Adamson struct compound_hdr *hdr) 126488034c3dSAndy Adamson { 126537c88763STrond Myklebust encode_getattr(xdr, open_bitmap, bitmask, 3, hdr); 126688034c3dSAndy Adamson } 126788034c3dSAndy Adamson 1268cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12691da177e4SLinus Torvalds { 127037c88763STrond Myklebust encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask, 127137c88763STrond Myklebust ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr); 12721da177e4SLinus Torvalds } 12731da177e4SLinus Torvalds 1274cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1275830b8e33SManoj Naik { 127637c88763STrond Myklebust encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask, 127737c88763STrond Myklebust ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr); 1278830b8e33SManoj Naik } 1279830b8e33SManoj Naik 1280cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12811da177e4SLinus Torvalds { 1282ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12831da177e4SLinus Torvalds } 12841da177e4SLinus Torvalds 1285cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12861da177e4SLinus Torvalds { 1287ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12886fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12891da177e4SLinus Torvalds } 12901da177e4SLinus Torvalds 1291911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1292911d1aafSTrond Myklebust { 1293f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1294911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1295911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1296911d1aafSTrond Myklebust } 1297911d1aafSTrond Myklebust 1298911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1299911d1aafSTrond Myklebust { 1300911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1301911d1aafSTrond Myklebust return ~(uint64_t)0; 1302911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1303911d1aafSTrond Myklebust } 1304911d1aafSTrond Myklebust 1305daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1306daccbdedSTrond Myklebust { 1307daccbdedSTrond Myklebust __be32 *p; 1308daccbdedSTrond Myklebust 1309d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1310daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1311d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1312daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1313d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1314daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1315daccbdedSTrond Myklebust } 1316daccbdedSTrond Myklebust 13171da177e4SLinus Torvalds /* 13181da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13191da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13201da177e4SLinus Torvalds */ 1321cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13221da177e4SLinus Torvalds { 13238687b63aSAl Viro __be32 *p; 13241da177e4SLinus Torvalds 1325475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1326475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1327e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1328e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1329b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1330b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 133134558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1332911d1aafSTrond Myklebust if (args->new_lock_owner){ 13334ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1334425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13354ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1336daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13371da177e4SLinus Torvalds } 13381da177e4SLinus Torvalds else { 1339425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13404ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds } 13431da177e4SLinus Torvalds 1344cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13451da177e4SLinus Torvalds { 13468687b63aSAl Viro __be32 *p; 13471da177e4SLinus Torvalds 1348475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1349475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1350e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1351b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1352b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1353daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13541da177e4SLinus Torvalds } 13551da177e4SLinus Torvalds 1356cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13571da177e4SLinus Torvalds { 13588687b63aSAl Viro __be32 *p; 13591da177e4SLinus Torvalds 1360475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1361475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13624ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1363425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1364ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1365b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 136634558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds 1369d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1370d3c7b7ccSTrond Myklebust { 1371ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1372d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1373d3c7b7ccSTrond Myklebust } 1374d3c7b7ccSTrond Myklebust 1375cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13761da177e4SLinus Torvalds { 1377ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13786fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13791da177e4SLinus Torvalds } 13801da177e4SLinus Torvalds 13815b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr) 13825b5faaf6SJeff Layton { 13835b5faaf6SJeff Layton encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr); 13845b5faaf6SJeff Layton } 13855b5faaf6SJeff Layton 13866ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13871da177e4SLinus Torvalds { 13888687b63aSAl Viro __be32 *p; 13891da177e4SLinus Torvalds 139013c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13916ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 139234558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13931da177e4SLinus Torvalds } 13941da177e4SLinus Torvalds 13951da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13961da177e4SLinus Torvalds { 13978687b63aSAl Viro __be32 *p; 13981da177e4SLinus Torvalds /* 13991da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 14001da177e4SLinus Torvalds * owner 4 = 32 14011da177e4SLinus Torvalds */ 14024ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14036ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 140495b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1405b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 140695b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 140793f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1408d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 140995b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 141095b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 14111da177e4SLinus Torvalds } 14121da177e4SLinus Torvalds 14131da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14141da177e4SLinus Torvalds { 14158687b63aSAl Viro __be32 *p; 14161da177e4SLinus Torvalds 141713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1418549b19ccSTrond Myklebust switch(arg->createmode) { 1419549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 142034558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 142128cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 142228cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 14231da177e4SLinus Torvalds break; 1424549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14254882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 142628cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 142728cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 1428549b19ccSTrond Myklebust break; 1429549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1430549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1431549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1432549b19ccSTrond Myklebust break; 1433549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14344882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14354882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 143628cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 143728cf22d0STrond Myklebust arg->server, arg->server->exclcreat_bitmask); 14384882ef72SAlexandros Batsakis } 14394882ef72SAlexandros Batsakis } 14401da177e4SLinus Torvalds 14411da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14421da177e4SLinus Torvalds { 14438687b63aSAl Viro __be32 *p; 14441da177e4SLinus Torvalds 144513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14461da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14471da177e4SLinus Torvalds case 0: 144834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14491da177e4SLinus Torvalds break; 14501da177e4SLinus Torvalds default: 145134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14521da177e4SLinus Torvalds encode_createmode(xdr, arg); 14531da177e4SLinus Torvalds } 14541da177e4SLinus Torvalds } 14551da177e4SLinus Torvalds 1456bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14571da177e4SLinus Torvalds { 14588687b63aSAl Viro __be32 *p; 14591da177e4SLinus Torvalds 146013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14611da177e4SLinus Torvalds switch (delegation_type) { 14621da177e4SLinus Torvalds case 0: 146334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14641da177e4SLinus Torvalds break; 14651da177e4SLinus Torvalds case FMODE_READ: 146634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14671da177e4SLinus Torvalds break; 14681da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 146934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14701da177e4SLinus Torvalds break; 14711da177e4SLinus Torvalds default: 14721da177e4SLinus Torvalds BUG(); 14731da177e4SLinus Torvalds } 14741da177e4SLinus Torvalds } 14751da177e4SLinus Torvalds 14761da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14771da177e4SLinus Torvalds { 14788687b63aSAl Viro __be32 *p; 14791da177e4SLinus Torvalds 148013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 148134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14821da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14831da177e4SLinus Torvalds } 14841da177e4SLinus Torvalds 1485bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14861da177e4SLinus Torvalds { 14878687b63aSAl Viro __be32 *p; 14881da177e4SLinus Torvalds 148913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 149034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14911da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14921da177e4SLinus Torvalds } 14931da177e4SLinus Torvalds 14941da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14951da177e4SLinus Torvalds { 14968687b63aSAl Viro __be32 *p; 14971da177e4SLinus Torvalds 1498ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1499ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1500ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 15011da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 15021da177e4SLinus Torvalds } 15031da177e4SLinus Torvalds 1504d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1505d9fc6619STrond Myklebust { 1506d9fc6619STrond Myklebust __be32 *p; 1507d9fc6619STrond Myklebust 1508d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1509d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1510d9fc6619STrond Myklebust } 1511d9fc6619STrond Myklebust 1512d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1513d9fc6619STrond Myklebust { 1514d9fc6619STrond Myklebust __be32 *p; 1515d9fc6619STrond Myklebust 1516d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1517d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1518d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1519d9fc6619STrond Myklebust } 1520d9fc6619STrond Myklebust 1521cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15221da177e4SLinus Torvalds { 1523ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15241da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15251da177e4SLinus Torvalds encode_opentype(xdr, arg); 15261da177e4SLinus Torvalds switch (arg->claim) { 15271da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15281da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15291da177e4SLinus Torvalds break; 15301da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15311da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15321da177e4SLinus Torvalds break; 15331da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15341da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15351da177e4SLinus Torvalds break; 1536d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1537d9fc6619STrond Myklebust encode_claim_fh(xdr); 1538d9fc6619STrond Myklebust break; 1539d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1540d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1541d9fc6619STrond Myklebust break; 15421da177e4SLinus Torvalds default: 15431da177e4SLinus Torvalds BUG(); 15441da177e4SLinus Torvalds } 15451da177e4SLinus Torvalds } 15461da177e4SLinus Torvalds 1547cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15481da177e4SLinus Torvalds { 1549ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1550ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15514ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15521da177e4SLinus Torvalds } 15531da177e4SLinus Torvalds 1554cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15551da177e4SLinus Torvalds { 1556ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1557566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15584ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15596ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15601da177e4SLinus Torvalds } 15611da177e4SLinus Torvalds 1562cf8cdbe5SAndy Adamson static void 1563d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15641da177e4SLinus Torvalds { 1565ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15666fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15671da177e4SLinus Torvalds } 15681da177e4SLinus Torvalds 1569cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15701da177e4SLinus Torvalds { 1571ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds 15743c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15753c6b899cSAnna Schumaker struct compound_hdr *hdr) 15761da177e4SLinus Torvalds { 15778687b63aSAl Viro __be32 *p; 15781da177e4SLinus Torvalds 1579ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15809b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15811da177e4SLinus Torvalds 158213c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1583b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 158434558513SBenny Halevy *p = cpu_to_be32(args->count); 15851da177e4SLinus Torvalds } 15861da177e4SLinus Torvalds 1587cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15881da177e4SLinus Torvalds { 1589aa9c2669SDavid Quigley uint32_t attrs[3] = { 159028331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 159128331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 159228331a46STrond Myklebust }; 15936f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1594cd93710eSChuck Lever __be32 *p, verf[2]; 1595d204c5d2STrond Myklebust uint32_t attrlen = 0; 1596d204c5d2STrond Myklebust unsigned int i; 15971da177e4SLinus Torvalds 159882f2e547SBryan Schumaker if (readdir->plus) { 159982f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 160028331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 160182f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 160282f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 160382f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 160482f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1605d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 16066f7a35bdSTrond Myklebust dircount >>= 1; 160782f2e547SBryan Schumaker } 160828331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 160928331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 161028331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1611d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1612d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1613d204c5d2STrond Myklebust if (attrs[i] != 0) 1614d204c5d2STrond Myklebust attrlen = i+1; 1615d204c5d2STrond Myklebust } 16166f7a35bdSTrond Myklebust 1617475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1618ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1619cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1620d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16216f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16226f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1623d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1624d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1625d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1626cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1627aa9c2669SDavid Quigley 1628aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 162944109241SFred Isaman __func__, 1630eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1631cd93710eSChuck Lever verf[0], verf[1], 1632eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1633aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1634aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16351da177e4SLinus Torvalds } 16361da177e4SLinus Torvalds 1637cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16381da177e4SLinus Torvalds { 1639ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16401da177e4SLinus Torvalds } 16411da177e4SLinus Torvalds 1642cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16431da177e4SLinus Torvalds { 1644ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16456fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16461da177e4SLinus Torvalds } 16471da177e4SLinus Torvalds 1648cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16491da177e4SLinus Torvalds { 1650ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1651811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1652811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16531da177e4SLinus Torvalds } 16541da177e4SLinus Torvalds 1655bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1656bb4dae5eSChuck Lever struct compound_hdr *hdr) 16571da177e4SLinus Torvalds { 1658475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1659ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16601da177e4SLinus Torvalds } 16611da177e4SLinus Torvalds 1662cf8cdbe5SAndy Adamson static void 1663d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 166456ae19f3STrond Myklebust { 1665ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 166656ae19f3STrond Myklebust } 166756ae19f3STrond Myklebust 16689f06c719SChuck Lever static void 1669fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg, 1670fcc85819SChristoph Hellwig struct compound_hdr *hdr) 167123ec6965SJ. Bruce Fields { 16728687b63aSAl Viro __be32 *p; 167323ec6965SJ. Bruce Fields 1674ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1675ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 167613c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1677e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 167834558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 167913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 168034558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16818fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 168223ec6965SJ. Bruce Fields } 168323ec6965SJ. Bruce Fields 1684cf8cdbe5SAndy Adamson static void 1685d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16861da177e4SLinus Torvalds { 1687ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16881da177e4SLinus Torvalds } 16891da177e4SLinus Torvalds 1690cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16911da177e4SLinus Torvalds { 1692ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1693ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 169428cf22d0STrond Myklebust encode_attrs(xdr, arg->iap, arg->label, NULL, server, 169528cf22d0STrond Myklebust server->attr_bitmask); 16961da177e4SLinus Torvalds } 16971da177e4SLinus Torvalds 1698cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16991da177e4SLinus Torvalds { 17008687b63aSAl Viro __be32 *p; 17011da177e4SLinus Torvalds 170270019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1703cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 17041da177e4SLinus Torvalds 17053a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 17063a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 170713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 170834558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 17091da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 17101da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 171113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 17123a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 17131da177e4SLinus Torvalds } 17141da177e4SLinus Torvalds 1715bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 17161da177e4SLinus Torvalds { 1717475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1718475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1719ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1720cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17211da177e4SLinus Torvalds } 17221da177e4SLinus Torvalds 17233c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17243c6b899cSAnna Schumaker struct compound_hdr *hdr) 17251da177e4SLinus Torvalds { 17268687b63aSAl Viro __be32 *p; 17271da177e4SLinus Torvalds 1728ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17299b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17301da177e4SLinus Torvalds 173113c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1732b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1733e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 173434558513SBenny Halevy *p = cpu_to_be32(args->count); 17351da177e4SLinus Torvalds 17361da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17371da177e4SLinus Torvalds } 17381da177e4SLinus Torvalds 1739cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17401da177e4SLinus Torvalds { 1741ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1742ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17431da177e4SLinus Torvalds } 17449b7b9fccSAndy Adamson 17455a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17465a5ea0d4SBryan Schumaker { 1747ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17486fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17495a5ea0d4SBryan Schumaker } 17505a5ea0d4SBryan Schumaker 175199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17529b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17537c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 1754fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args, 17557c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17567c44f1aeSWeston Andros Adamson { 17577c44f1aeSWeston Andros Adamson __be32 *p; 17587c44f1aeSWeston Andros Adamson 17597c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17607c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 176171a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17627c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 176371a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 176471a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17657c44f1aeSWeston Andros Adamson } 17667c44f1aeSWeston Andros Adamson 1767fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map) 17682031cd1aSWeston Andros Adamson { 17692031cd1aSWeston Andros Adamson unsigned int i; 17702031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17712031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17722031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17732031cd1aSWeston Andros Adamson } 17742031cd1aSWeston Andros Adamson 177599fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 1776fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args, 177799fe60d0SBenny Halevy struct compound_hdr *hdr) 177899fe60d0SBenny Halevy { 177999fe60d0SBenny Halevy __be32 *p; 1780d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1781db8ac8baSWeston Andros Adamson int len = 0; 178299fe60d0SBenny Halevy 178370019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1784fd40559cSTrond Myklebust encode_nfs4_verifier(xdr, &args->verifier); 178599fe60d0SBenny Halevy 17863a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17873a6bb738SJeff Layton args->client->cl_owner_id); 178899fe60d0SBenny Halevy 17892031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17902031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17912031cd1aSWeston Andros Adamson 17922031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17932031cd1aSWeston Andros Adamson case SP4_NONE: 17942031cd1aSWeston Andros Adamson break; 17952031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17962031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 17972031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 17982031cd1aSWeston Andros Adamson break; 17992031cd1aSWeston Andros Adamson default: 18002031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 18012031cd1aSWeston Andros Adamson break; 18022031cd1aSWeston Andros Adamson } 1803db8ac8baSWeston Andros Adamson 1804db8ac8baSWeston Andros Adamson if (send_implementation_id && 1805db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1806db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1807d751f748SJim Rees <= sizeof(impl_name) + 1) 1808db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1809db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1810db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1811db8ac8baSWeston Andros Adamson 1812db8ac8baSWeston Andros Adamson if (len > 0) { 18132031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1814db8ac8baSWeston Andros Adamson 1815db8ac8baSWeston Andros Adamson encode_string(xdr, 1816db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1817db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1818db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1819db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1820db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1821db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1822db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1823db8ac8baSWeston Andros Adamson } else 18242031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 182599fe60d0SBenny Halevy } 1826fc931582SAndy Adamson 1827fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1828fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args, 1829fc931582SAndy Adamson struct compound_hdr *hdr) 1830fc931582SAndy Adamson { 1831fc931582SAndy Adamson __be32 *p; 1832fc931582SAndy Adamson struct nfs_client *clp = args->client; 183389f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1834f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18358e0d46e1SMike Sager u32 max_resp_sz_cached; 18368e0d46e1SMike Sager 18378e0d46e1SMike Sager /* 18388e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18398e0d46e1SMike Sager * 2 is the verifier. 18408e0d46e1SMike Sager */ 184135c036efSJ. Bruce Fields max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2) 184235c036efSJ. Bruce Fields * XDR_UNIT + RPC_MAX_AUTH_SIZE; 1843fc931582SAndy Adamson 1844475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 184589f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 184679969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 184779969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1848e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1849fc931582SAndy Adamson 1850fc931582SAndy Adamson /* Fore Channel */ 1851c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1852e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1853e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18548e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1856e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1857e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1858fc931582SAndy Adamson 1859fc931582SAndy Adamson /* Back Channel */ 1860c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1861e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1862e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1863e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1864e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1865e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1866e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1867fc931582SAndy Adamson 1868e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1869e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1870e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1871fc931582SAndy Adamson 1872fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18732f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 187489f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1875e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1876e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 187734558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1878fc931582SAndy Adamson } 18790f3e66c6SAndy Adamson 18800f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 1881fcc85819SChristoph Hellwig const struct nfs4_session *session, 18820f3e66c6SAndy Adamson struct compound_hdr *hdr) 18830f3e66c6SAndy Adamson { 1884475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1885475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18860f3e66c6SAndy Adamson } 188718019753SRicardo Labiaga 188866245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 188966245539STrond Myklebust uint64_t clientid, 189066245539STrond Myklebust struct compound_hdr *hdr) 189166245539STrond Myklebust { 189266245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 189366245539STrond Myklebust encode_uint64(xdr, clientid); 189466245539STrond Myklebust } 189566245539STrond Myklebust 189618019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 1897fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args, 189818019753SRicardo Labiaga struct compound_hdr *hdr) 189918019753SRicardo Labiaga { 1900475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1901475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 190218019753SRicardo Labiaga } 190399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 190499fe60d0SBenny Halevy 19059b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 19069b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 19079b7b9fccSAndy Adamson struct compound_hdr *hdr) 19089b7b9fccSAndy Adamson { 19099b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 19102b2fa717STrond Myklebust struct nfs4_session *session; 1911fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 19122b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1913fc01cea9SAndy Adamson __be32 *p; 19149b7b9fccSAndy Adamson 19152b2fa717STrond Myklebust tp = slot->table; 19162b2fa717STrond Myklebust session = tp->session; 19173bd2384aSChuck Lever if (!session) 19183bd2384aSChuck Lever return; 1919fc01cea9SAndy Adamson 1920475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1921fc01cea9SAndy Adamson 1922fc01cea9SAndy Adamson /* 1923fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1924fc01cea9SAndy Adamson */ 1925fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1926fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1927fc01cea9SAndy Adamson __func__, 1928fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1929fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1930fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1931fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19322b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1933fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1934475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 193593f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1936e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19372b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1938e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 193934558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19409b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19419b7b9fccSAndy Adamson } 19429b7b9fccSAndy Adamson 1943b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1944b1f69b75SAndy Adamson static void 1945b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1946b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1947b1f69b75SAndy Adamson struct compound_hdr *hdr) 1948b1f69b75SAndy Adamson { 1949b1f69b75SAndy Adamson __be32 *p; 1950b1f69b75SAndy Adamson 1951475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 195284c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1953b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1954b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1955b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1956f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 195784c9dee3SChristoph Hellwig 195884c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 195984c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19604e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1961b1f69b75SAndy Adamson } 1962b1f69b75SAndy Adamson 1963b1f69b75SAndy Adamson static void 1964b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1965b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1966b1f69b75SAndy Adamson struct compound_hdr *hdr) 1967b1f69b75SAndy Adamson { 1968b1f69b75SAndy Adamson __be32 *p; 1969b1f69b75SAndy Adamson 1970475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1971475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1972b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1973b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1974b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1975b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1976b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1977b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1978ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1979475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1980b1f69b75SAndy Adamson 1981b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1982b1f69b75SAndy Adamson __func__, 1983b1f69b75SAndy Adamson args->type, 1984b1f69b75SAndy Adamson args->range.iomode, 1985b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1986b1f69b75SAndy Adamson (unsigned long)args->range.length, 1987b1f69b75SAndy Adamson args->maxcount); 1988b1f69b75SAndy Adamson } 1989863a3c6cSAndy Adamson 1990863a3c6cSAndy Adamson static int 1991863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1992ac7db726SBenny Halevy struct inode *inode, 1993fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args, 1994863a3c6cSAndy Adamson struct compound_hdr *hdr) 1995863a3c6cSAndy Adamson { 1996863a3c6cSAndy Adamson __be32 *p; 1997863a3c6cSAndy Adamson 1998863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1999863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 2000863a3c6cSAndy Adamson 2001475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 2002475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 2003863a3c6cSAndy Adamson /* Only whole file layouts */ 2004863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 20053557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 2006ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 2007ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20082e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 2009ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 2010863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 2011863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 20122e18d4d8STrond Myklebust } else { 20132e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 20142e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 20152e18d4d8STrond Myklebust } 2016863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2017863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2018ac7db726SBenny Halevy 20195f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 202073504740STrond Myklebust if (args->layoutupdate_pages) 20215f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20225f919c9fSChristoph Hellwig args->layoutupdate_len); 2023863a3c6cSAndy Adamson 2024863a3c6cSAndy Adamson return 0; 2025863a3c6cSAndy Adamson } 2026cbe82603SBenny Halevy 2027cbe82603SBenny Halevy static void 2028cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2029cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2030cbe82603SBenny Halevy struct compound_hdr *hdr) 2031cbe82603SBenny Halevy { 2032cbe82603SBenny Halevy __be32 *p; 2033cbe82603SBenny Halevy 2034475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2035475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2036cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2037cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 203815eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2039cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2040ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 204115eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 204215eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2043cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2044ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2045cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20464d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20474d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 204894e5c571STrond Myklebust else 2049475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2050cbe82603SBenny Halevy } 2051fca78d6dSBryan Schumaker 2052fca78d6dSBryan Schumaker static int 2053fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2054fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2055fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2056fca78d6dSBryan Schumaker { 2057475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2058475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2059fca78d6dSBryan Schumaker return 0; 2060fca78d6dSBryan Schumaker } 20617d974794SBryan Schumaker 20627d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 2063fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args, 20647d974794SBryan Schumaker struct compound_hdr *hdr) 20657d974794SBryan Schumaker { 2066475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2067475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2068ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20697d974794SBryan Schumaker } 20709aeda35fSBryan Schumaker 20719aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 2072fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args, 20739aeda35fSBryan Schumaker struct compound_hdr *hdr) 20749aeda35fSBryan Schumaker { 2075ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20767c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20779aeda35fSBryan Schumaker } 2078cf805165STrond Myklebust #else 2079cf805165STrond Myklebust static inline void 2080cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2081cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2082cf805165STrond Myklebust struct compound_hdr *hdr) 2083cf805165STrond Myklebust { 2084cf805165STrond Myklebust } 208556f487f8SFred Isaman 208656f487f8SFred Isaman static void 208756f487f8SFred Isaman encode_layoutget(struct xdr_stream *xdr, 208856f487f8SFred Isaman const struct nfs4_layoutget_args *args, 208956f487f8SFred Isaman struct compound_hdr *hdr) 209056f487f8SFred Isaman { 209156f487f8SFred Isaman } 2092b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2093b1f69b75SAndy Adamson 20941da177e4SLinus Torvalds /* 20951da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20961da177e4SLinus Torvalds */ 20971da177e4SLinus Torvalds 209866cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 209966cc0429SBenny Halevy { 210066cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 21013bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 21023bd2384aSChuck Lever if (session) 21033bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 210466cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 210566cc0429SBenny Halevy return 0; 210666cc0429SBenny Halevy } 210766cc0429SBenny Halevy 21081da177e4SLinus Torvalds /* 21091da177e4SLinus Torvalds * Encode an ACCESS request 21101da177e4SLinus Torvalds */ 21119f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 2112fcc85819SChristoph Hellwig const void *data) 21131da177e4SLinus Torvalds { 2114fcc85819SChristoph Hellwig const struct nfs4_accessargs *args = data; 21151da177e4SLinus Torvalds struct compound_hdr hdr = { 211666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21171da177e4SLinus Torvalds }; 21181da177e4SLinus Torvalds 21199f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21209f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21219f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21229f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21238bcbe7d9STrond Myklebust if (args->bitmask) 21249f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2125d017931cSAndy Adamson encode_nops(&hdr); 21261da177e4SLinus Torvalds } 21271da177e4SLinus Torvalds 21281da177e4SLinus Torvalds /* 21291da177e4SLinus Torvalds * Encode LOOKUP request 21301da177e4SLinus Torvalds */ 21319f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 2132fcc85819SChristoph Hellwig const void *data) 21331da177e4SLinus Torvalds { 2134fcc85819SChristoph Hellwig const struct nfs4_lookup_arg *args = data; 21351da177e4SLinus Torvalds struct compound_hdr hdr = { 213666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21371da177e4SLinus Torvalds }; 21381da177e4SLinus Torvalds 21399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21419f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21429f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21439f06c719SChuck Lever encode_getfh(xdr, &hdr); 21449f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2145d017931cSAndy Adamson encode_nops(&hdr); 21461da177e4SLinus Torvalds } 21471da177e4SLinus Torvalds 21481da177e4SLinus Torvalds /* 21495b5faaf6SJeff Layton * Encode LOOKUPP request 21505b5faaf6SJeff Layton */ 21515b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr, 21525b5faaf6SJeff Layton const void *data) 21535b5faaf6SJeff Layton { 21545b5faaf6SJeff Layton const struct nfs4_lookupp_arg *args = data; 21555b5faaf6SJeff Layton struct compound_hdr hdr = { 21565b5faaf6SJeff Layton .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21575b5faaf6SJeff Layton }; 21585b5faaf6SJeff Layton 21595b5faaf6SJeff Layton encode_compound_hdr(xdr, req, &hdr); 21605b5faaf6SJeff Layton encode_sequence(xdr, &args->seq_args, &hdr); 21615b5faaf6SJeff Layton encode_putfh(xdr, args->fh, &hdr); 21625b5faaf6SJeff Layton encode_lookupp(xdr, &hdr); 21635b5faaf6SJeff Layton encode_getfh(xdr, &hdr); 21645b5faaf6SJeff Layton encode_getfattr(xdr, args->bitmask, &hdr); 21655b5faaf6SJeff Layton encode_nops(&hdr); 21665b5faaf6SJeff Layton } 21675b5faaf6SJeff Layton 21685b5faaf6SJeff Layton /* 21691da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21701da177e4SLinus Torvalds */ 21719f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21729f06c719SChuck Lever struct xdr_stream *xdr, 2173fcc85819SChristoph Hellwig const void *data) 21741da177e4SLinus Torvalds { 2175fcc85819SChristoph Hellwig const struct nfs4_lookup_root_arg *args = data; 21761da177e4SLinus Torvalds struct compound_hdr hdr = { 217766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21781da177e4SLinus Torvalds }; 21791da177e4SLinus Torvalds 21809f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21819f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21829f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21839f06c719SChuck Lever encode_getfh(xdr, &hdr); 21849f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2185d017931cSAndy Adamson encode_nops(&hdr); 21861da177e4SLinus Torvalds } 21871da177e4SLinus Torvalds 21881da177e4SLinus Torvalds /* 21891da177e4SLinus Torvalds * Encode REMOVE request 21901da177e4SLinus Torvalds */ 21919f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 2192fcc85819SChristoph Hellwig const void *data) 21931da177e4SLinus Torvalds { 2194fcc85819SChristoph Hellwig const struct nfs_removeargs *args = data; 21951da177e4SLinus Torvalds struct compound_hdr hdr = { 219666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21971da177e4SLinus Torvalds }; 21981da177e4SLinus Torvalds 21999f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22009f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22019f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22029f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2203d017931cSAndy Adamson encode_nops(&hdr); 22041da177e4SLinus Torvalds } 22051da177e4SLinus Torvalds 22061da177e4SLinus Torvalds /* 22071da177e4SLinus Torvalds * Encode RENAME request 22081da177e4SLinus Torvalds */ 22099f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 2210fcc85819SChristoph Hellwig const void *data) 22111da177e4SLinus Torvalds { 2212fcc85819SChristoph Hellwig const struct nfs_renameargs *args = data; 22131da177e4SLinus Torvalds struct compound_hdr hdr = { 221466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22151da177e4SLinus Torvalds }; 22161da177e4SLinus Torvalds 22179f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22189f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22199f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 22209f06c719SChuck Lever encode_savefh(xdr, &hdr); 22219f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 22229f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2223d017931cSAndy Adamson encode_nops(&hdr); 22241da177e4SLinus Torvalds } 22251da177e4SLinus Torvalds 22261da177e4SLinus Torvalds /* 22271da177e4SLinus Torvalds * Encode LINK request 22281da177e4SLinus Torvalds */ 22299f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 2230fcc85819SChristoph Hellwig const void *data) 22311da177e4SLinus Torvalds { 2232fcc85819SChristoph Hellwig const struct nfs4_link_arg *args = data; 22331da177e4SLinus Torvalds struct compound_hdr hdr = { 223466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22351da177e4SLinus Torvalds }; 22361da177e4SLinus Torvalds 22379f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22389f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22399f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22409f06c719SChuck Lever encode_savefh(xdr, &hdr); 22419f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22429f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22439f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22449f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2245d017931cSAndy Adamson encode_nops(&hdr); 22461da177e4SLinus Torvalds } 22471da177e4SLinus Torvalds 22481da177e4SLinus Torvalds /* 22491da177e4SLinus Torvalds * Encode CREATE request 22501da177e4SLinus Torvalds */ 22519f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 2252fcc85819SChristoph Hellwig const void *data) 22531da177e4SLinus Torvalds { 2254fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 22551da177e4SLinus Torvalds struct compound_hdr hdr = { 225666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22571da177e4SLinus Torvalds }; 22581da177e4SLinus Torvalds 22599f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22609f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22619f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22629f06c719SChuck Lever encode_create(xdr, args, &hdr); 22639f06c719SChuck Lever encode_getfh(xdr, &hdr); 22649f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2265d017931cSAndy Adamson encode_nops(&hdr); 22661da177e4SLinus Torvalds } 22671da177e4SLinus Torvalds 22681da177e4SLinus Torvalds /* 22691da177e4SLinus Torvalds * Encode SYMLINK request 22701da177e4SLinus Torvalds */ 22719f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2272fcc85819SChristoph Hellwig const void *data) 22731da177e4SLinus Torvalds { 2274fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 2275fcc85819SChristoph Hellwig 22769f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22771da177e4SLinus Torvalds } 22781da177e4SLinus Torvalds 22791da177e4SLinus Torvalds /* 22801da177e4SLinus Torvalds * Encode GETATTR request 22811da177e4SLinus Torvalds */ 22829f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2283fcc85819SChristoph Hellwig const void *data) 22841da177e4SLinus Torvalds { 2285fcc85819SChristoph Hellwig const struct nfs4_getattr_arg *args = data; 22861da177e4SLinus Torvalds struct compound_hdr hdr = { 228766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22881da177e4SLinus Torvalds }; 22891da177e4SLinus Torvalds 22909f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22919f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22929f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22939f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2294d017931cSAndy Adamson encode_nops(&hdr); 22951da177e4SLinus Torvalds } 22961da177e4SLinus Torvalds 22971da177e4SLinus Torvalds /* 22981da177e4SLinus Torvalds * Encode a CLOSE request 22991da177e4SLinus Torvalds */ 23009f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 2301fcc85819SChristoph Hellwig const void *data) 23021da177e4SLinus Torvalds { 2303fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 23041da177e4SLinus Torvalds struct compound_hdr hdr = { 230566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23061da177e4SLinus Torvalds }; 23071da177e4SLinus Torvalds 23089f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23099f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23109f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2311cf805165STrond Myklebust if (args->lr_args) 2312cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23133ecefc92STrond Myklebust if (args->bitmask != NULL) 23149f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2315d8d84983STrond Myklebust encode_close(xdr, args, &hdr); 2316d017931cSAndy Adamson encode_nops(&hdr); 23171da177e4SLinus Torvalds } 23181da177e4SLinus Torvalds 23191da177e4SLinus Torvalds /* 23201da177e4SLinus Torvalds * Encode an OPEN request 23211da177e4SLinus Torvalds */ 23229f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 2323fcc85819SChristoph Hellwig const void *data) 23241da177e4SLinus Torvalds { 2325fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23261da177e4SLinus Torvalds struct compound_hdr hdr = { 232766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23281da177e4SLinus Torvalds }; 23291da177e4SLinus Torvalds 23309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23329f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23339f06c719SChuck Lever encode_open(xdr, args, &hdr); 23349f06c719SChuck Lever encode_getfh(xdr, &hdr); 2335ae2bb032SWeston Andros Adamson if (args->access) 23366168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 23371549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 233856f487f8SFred Isaman if (args->lg_args) { 233956f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr); 234056f487f8SFred Isaman xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 234156f487f8SFred Isaman args->lg_args->layout.pages, 234256f487f8SFred Isaman 0, args->lg_args->layout.pglen); 234356f487f8SFred Isaman } 2344d017931cSAndy Adamson encode_nops(&hdr); 23451da177e4SLinus Torvalds } 23461da177e4SLinus Torvalds 23471da177e4SLinus Torvalds /* 23481da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 23491da177e4SLinus Torvalds */ 23509f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 23519f06c719SChuck Lever struct xdr_stream *xdr, 2352fcc85819SChristoph Hellwig const void *data) 23531da177e4SLinus Torvalds { 2354fcc85819SChristoph Hellwig const struct nfs_open_confirmargs *args = data; 23551da177e4SLinus Torvalds struct compound_hdr hdr = { 2356d017931cSAndy Adamson .nops = 0, 23571da177e4SLinus Torvalds }; 23581da177e4SLinus Torvalds 23599f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23609f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23619f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2362d017931cSAndy Adamson encode_nops(&hdr); 23631da177e4SLinus Torvalds } 23641da177e4SLinus Torvalds 23651da177e4SLinus Torvalds /* 23661da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23671da177e4SLinus Torvalds */ 23689f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23699f06c719SChuck Lever struct xdr_stream *xdr, 2370fcc85819SChristoph Hellwig const void *data) 23711da177e4SLinus Torvalds { 2372fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23731da177e4SLinus Torvalds struct compound_hdr hdr = { 237466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23751da177e4SLinus Torvalds }; 23761da177e4SLinus Torvalds 23779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23789f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23799f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23809f06c719SChuck Lever encode_open(xdr, args, &hdr); 2381ae2bb032SWeston Andros Adamson if (args->access) 23826168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2383e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 238456f487f8SFred Isaman if (args->lg_args) { 238556f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr); 238656f487f8SFred Isaman xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 238756f487f8SFred Isaman args->lg_args->layout.pages, 238856f487f8SFred Isaman 0, args->lg_args->layout.pglen); 238956f487f8SFred Isaman } 2390d017931cSAndy Adamson encode_nops(&hdr); 23911da177e4SLinus Torvalds } 23921da177e4SLinus Torvalds 23931da177e4SLinus Torvalds /* 23941da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23951da177e4SLinus Torvalds */ 23969f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23979f06c719SChuck Lever struct xdr_stream *xdr, 2398fcc85819SChristoph Hellwig const void *data) 23991da177e4SLinus Torvalds { 2400fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 24011da177e4SLinus Torvalds struct compound_hdr hdr = { 240266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24031da177e4SLinus Torvalds }; 24041da177e4SLinus Torvalds 24059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2408b6808145STrond Myklebust if (args->lr_args) 2409b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 24109f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2411d017931cSAndy Adamson encode_nops(&hdr); 24121da177e4SLinus Torvalds } 24131da177e4SLinus Torvalds 24141da177e4SLinus Torvalds /* 24151da177e4SLinus Torvalds * Encode a LOCK request 24161da177e4SLinus Torvalds */ 24179f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 2418fcc85819SChristoph Hellwig const void *data) 24191da177e4SLinus Torvalds { 2420fcc85819SChristoph Hellwig const struct nfs_lock_args *args = data; 24211da177e4SLinus Torvalds struct compound_hdr hdr = { 242266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24231da177e4SLinus Torvalds }; 24241da177e4SLinus Torvalds 24259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24279f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24289f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2429d017931cSAndy Adamson encode_nops(&hdr); 24301da177e4SLinus Torvalds } 24311da177e4SLinus Torvalds 24321da177e4SLinus Torvalds /* 24331da177e4SLinus Torvalds * Encode a LOCKT request 24341da177e4SLinus Torvalds */ 24359f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 2436fcc85819SChristoph Hellwig const void *data) 24371da177e4SLinus Torvalds { 2438fcc85819SChristoph Hellwig const struct nfs_lockt_args *args = data; 24391da177e4SLinus Torvalds struct compound_hdr hdr = { 244066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24411da177e4SLinus Torvalds }; 24421da177e4SLinus Torvalds 24439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24459f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24469f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2447d017931cSAndy Adamson encode_nops(&hdr); 24481da177e4SLinus Torvalds } 24491da177e4SLinus Torvalds 24501da177e4SLinus Torvalds /* 24511da177e4SLinus Torvalds * Encode a LOCKU request 24521da177e4SLinus Torvalds */ 24539f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 2454fcc85819SChristoph Hellwig const void *data) 24551da177e4SLinus Torvalds { 2456fcc85819SChristoph Hellwig const struct nfs_locku_args *args = data; 24571da177e4SLinus Torvalds struct compound_hdr hdr = { 245866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24591da177e4SLinus Torvalds }; 24601da177e4SLinus Torvalds 24619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24649f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2465d017931cSAndy Adamson encode_nops(&hdr); 24661da177e4SLinus Torvalds } 24671da177e4SLinus Torvalds 24689f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24699f06c719SChuck Lever struct xdr_stream *xdr, 2470fcc85819SChristoph Hellwig const void *data) 2471d3c7b7ccSTrond Myklebust { 2472fcc85819SChristoph Hellwig const struct nfs_release_lockowner_args *args = data; 2473d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2474d3c7b7ccSTrond Myklebust .minorversion = 0, 2475d3c7b7ccSTrond Myklebust }; 2476d3c7b7ccSTrond Myklebust 24779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24789f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2479d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2480d3c7b7ccSTrond Myklebust } 2481d3c7b7ccSTrond Myklebust 24821da177e4SLinus Torvalds /* 24831da177e4SLinus Torvalds * Encode a READLINK request 24841da177e4SLinus Torvalds */ 24859f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2486fcc85819SChristoph Hellwig const void *data) 24871da177e4SLinus Torvalds { 2488fcc85819SChristoph Hellwig const struct nfs4_readlink *args = data; 24891da177e4SLinus Torvalds struct compound_hdr hdr = { 249066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24911da177e4SLinus Torvalds }; 24921da177e4SLinus Torvalds 24939f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24949f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24959f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24969f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2497e3a535e1STrond Myklebust 249828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2499e3a535e1STrond Myklebust args->pgbase, args->pglen); 2500d017931cSAndy Adamson encode_nops(&hdr); 25011da177e4SLinus Torvalds } 25021da177e4SLinus Torvalds 25031da177e4SLinus Torvalds /* 25041da177e4SLinus Torvalds * Encode a READDIR request 25051da177e4SLinus Torvalds */ 25069f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 2507fcc85819SChristoph Hellwig const void *data) 25081da177e4SLinus Torvalds { 2509fcc85819SChristoph Hellwig const struct nfs4_readdir_arg *args = data; 25101da177e4SLinus Torvalds struct compound_hdr hdr = { 251166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25121da177e4SLinus Torvalds }; 25131da177e4SLinus Torvalds 25149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25169f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25179f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2518d6ac02dfSTrond Myklebust 251928f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2520d6ac02dfSTrond Myklebust args->pgbase, args->count); 2521d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 252228f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2523d6ac02dfSTrond Myklebust args->pgbase, args->count); 2524d017931cSAndy Adamson encode_nops(&hdr); 25251da177e4SLinus Torvalds } 25261da177e4SLinus Torvalds 25271da177e4SLinus Torvalds /* 25281da177e4SLinus Torvalds * Encode a READ request 25291da177e4SLinus Torvalds */ 25309f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 2531fcc85819SChristoph Hellwig const void *data) 25321da177e4SLinus Torvalds { 2533fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 25341da177e4SLinus Torvalds struct compound_hdr hdr = { 253566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25361da177e4SLinus Torvalds }; 25371da177e4SLinus Torvalds 25389f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25399f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25409f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25419f06c719SChuck Lever encode_read(xdr, args, &hdr); 25421da177e4SLinus Torvalds 254328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 25441da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 25454f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2546d017931cSAndy Adamson encode_nops(&hdr); 25471da177e4SLinus Torvalds } 25481da177e4SLinus Torvalds 25491da177e4SLinus Torvalds /* 25501da177e4SLinus Torvalds * Encode an SETATTR request 25511da177e4SLinus Torvalds */ 25529f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2553fcc85819SChristoph Hellwig const void *data) 25541da177e4SLinus Torvalds { 2555fcc85819SChristoph Hellwig const struct nfs_setattrargs *args = data; 25561da177e4SLinus Torvalds struct compound_hdr hdr = { 255766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25581da177e4SLinus Torvalds }; 25591da177e4SLinus Torvalds 25609f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25619f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25629f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25639f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 25649f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2565d017931cSAndy Adamson encode_nops(&hdr); 25661da177e4SLinus Torvalds } 25671da177e4SLinus Torvalds 25681da177e4SLinus Torvalds /* 2569029d105eSJ. Bruce Fields * Encode a GETACL request 2570029d105eSJ. Bruce Fields */ 25719f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2572fcc85819SChristoph Hellwig const void *data) 2573029d105eSJ. Bruce Fields { 2574fcc85819SChristoph Hellwig const struct nfs_getaclargs *args = data; 2575029d105eSJ. Bruce Fields struct compound_hdr hdr = { 257666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2577029d105eSJ. Bruce Fields }; 257837c88763STrond Myklebust const __u32 nfs4_acl_bitmap[1] = { 257937c88763STrond Myklebust [0] = FATTR4_WORD0_ACL, 258037c88763STrond Myklebust }; 258128f56694SBenny Halevy uint32_t replen; 2582029d105eSJ. Bruce Fields 25839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25849f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25859f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25866682c14bSJ. Bruce Fields replen = hdr.replen + op_decode_hdr_maxsz; 258737c88763STrond Myklebust encode_getattr(xdr, nfs4_acl_bitmap, NULL, 258837c88763STrond Myklebust ARRAY_SIZE(nfs4_acl_bitmap), &hdr); 2589cf8cdbe5SAndy Adamson 259028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 25918fbcf237SAndreas Gruenbacher args->acl_pages, 0, args->acl_len); 2592bf118a34SAndy Adamson 2593d017931cSAndy Adamson encode_nops(&hdr); 2594029d105eSJ. Bruce Fields } 2595029d105eSJ. Bruce Fields 2596029d105eSJ. Bruce Fields /* 25971da177e4SLinus Torvalds * Encode a WRITE request 25981da177e4SLinus Torvalds */ 25999f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 2600fcc85819SChristoph Hellwig const void *data) 26011da177e4SLinus Torvalds { 2602fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 26031da177e4SLinus Torvalds struct compound_hdr hdr = { 260466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26051da177e4SLinus Torvalds }; 26061da177e4SLinus Torvalds 26079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26089f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26099f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26109f06c719SChuck Lever encode_write(xdr, args, &hdr); 26114f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 26127ffd1064SFred Isaman if (args->bitmask) 26139f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2614d017931cSAndy Adamson encode_nops(&hdr); 26151da177e4SLinus Torvalds } 26161da177e4SLinus Torvalds 26171da177e4SLinus Torvalds /* 26181da177e4SLinus Torvalds * a COMMIT request 26191da177e4SLinus Torvalds */ 26209f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 2621fcc85819SChristoph Hellwig const void *data) 26221da177e4SLinus Torvalds { 2623fcc85819SChristoph Hellwig const struct nfs_commitargs *args = data; 26241da177e4SLinus Torvalds struct compound_hdr hdr = { 262566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26261da177e4SLinus Torvalds }; 26271da177e4SLinus Torvalds 26289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26299f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26309f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26319f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2632d017931cSAndy Adamson encode_nops(&hdr); 26331da177e4SLinus Torvalds } 26341da177e4SLinus Torvalds 26351da177e4SLinus Torvalds /* 26361da177e4SLinus Torvalds * FSINFO request 26371da177e4SLinus Torvalds */ 26389f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 2639fcc85819SChristoph Hellwig const void *data) 26401da177e4SLinus Torvalds { 2641fcc85819SChristoph Hellwig const struct nfs4_fsinfo_arg *args = data; 26421da177e4SLinus Torvalds struct compound_hdr hdr = { 264366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26441da177e4SLinus Torvalds }; 26451da177e4SLinus Torvalds 26469f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26479f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26489f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26499f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2650d017931cSAndy Adamson encode_nops(&hdr); 26511da177e4SLinus Torvalds } 26521da177e4SLinus Torvalds 26531da177e4SLinus Torvalds /* 26541da177e4SLinus Torvalds * a PATHCONF request 26551da177e4SLinus Torvalds */ 26569f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 2657fcc85819SChristoph Hellwig const void *data) 26581da177e4SLinus Torvalds { 2659fcc85819SChristoph Hellwig const struct nfs4_pathconf_arg *args = data; 26601da177e4SLinus Torvalds struct compound_hdr hdr = { 266166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26621da177e4SLinus Torvalds }; 26631da177e4SLinus Torvalds 26649f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26659f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26669f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 266737c88763STrond Myklebust encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask, 266837c88763STrond Myklebust ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr); 2669d017931cSAndy Adamson encode_nops(&hdr); 26701da177e4SLinus Torvalds } 26711da177e4SLinus Torvalds 26721da177e4SLinus Torvalds /* 26731da177e4SLinus Torvalds * a STATFS request 26741da177e4SLinus Torvalds */ 26759f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 2676fcc85819SChristoph Hellwig const void *data) 26771da177e4SLinus Torvalds { 2678fcc85819SChristoph Hellwig const struct nfs4_statfs_arg *args = data; 26791da177e4SLinus Torvalds struct compound_hdr hdr = { 268066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26811da177e4SLinus Torvalds }; 26821da177e4SLinus Torvalds 26839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26849f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26859f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 268637c88763STrond Myklebust encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask, 268737c88763STrond Myklebust ARRAY_SIZE(nfs4_statfs_bitmap), &hdr); 2688d017931cSAndy Adamson encode_nops(&hdr); 26891da177e4SLinus Torvalds } 26901da177e4SLinus Torvalds 26911da177e4SLinus Torvalds /* 26921da177e4SLinus Torvalds * GETATTR_BITMAP request 26931da177e4SLinus Torvalds */ 26949f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26959f06c719SChuck Lever struct xdr_stream *xdr, 2696fcc85819SChristoph Hellwig const void *data) 26971da177e4SLinus Torvalds { 2698fcc85819SChristoph Hellwig const struct nfs4_server_caps_arg *args = data; 26998c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 27001da177e4SLinus Torvalds struct compound_hdr hdr = { 270166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27021da177e4SLinus Torvalds }; 27031da177e4SLinus Torvalds 27049f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27059f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27069f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 270737c88763STrond Myklebust encode_getattr(xdr, bitmask, NULL, 3, &hdr); 2708d017931cSAndy Adamson encode_nops(&hdr); 27091da177e4SLinus Torvalds } 27101da177e4SLinus Torvalds 27111da177e4SLinus Torvalds /* 27121da177e4SLinus Torvalds * a RENEW request 27131da177e4SLinus Torvalds */ 27149f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 2715fcc85819SChristoph Hellwig const void *data) 2716fcc85819SChristoph Hellwig 27171da177e4SLinus Torvalds { 2718fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 27191da177e4SLinus Torvalds struct compound_hdr hdr = { 2720d017931cSAndy Adamson .nops = 0, 27211da177e4SLinus Torvalds }; 27221da177e4SLinus Torvalds 27239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2724bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2725d017931cSAndy Adamson encode_nops(&hdr); 27261da177e4SLinus Torvalds } 27271da177e4SLinus Torvalds 27281da177e4SLinus Torvalds /* 27291da177e4SLinus Torvalds * a SETCLIENTID request 27301da177e4SLinus Torvalds */ 27319f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 27329f06c719SChuck Lever struct xdr_stream *xdr, 2733fcc85819SChristoph Hellwig const void *data) 27341da177e4SLinus Torvalds { 2735fcc85819SChristoph Hellwig const struct nfs4_setclientid *sc = data; 27361da177e4SLinus Torvalds struct compound_hdr hdr = { 2737d017931cSAndy Adamson .nops = 0, 27381da177e4SLinus Torvalds }; 27391da177e4SLinus Torvalds 27409f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27419f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2742d017931cSAndy Adamson encode_nops(&hdr); 27431da177e4SLinus Torvalds } 27441da177e4SLinus Torvalds 27451da177e4SLinus Torvalds /* 27461da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 27471da177e4SLinus Torvalds */ 27489f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 27499f06c719SChuck Lever struct xdr_stream *xdr, 2750fcc85819SChristoph Hellwig const void *data) 27511da177e4SLinus Torvalds { 2752fcc85819SChristoph Hellwig const struct nfs4_setclientid_res *arg = data; 27531da177e4SLinus Torvalds struct compound_hdr hdr = { 2754d017931cSAndy Adamson .nops = 0, 27551da177e4SLinus Torvalds }; 27561da177e4SLinus Torvalds 27579f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27589f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2759d017931cSAndy Adamson encode_nops(&hdr); 27601da177e4SLinus Torvalds } 27611da177e4SLinus Torvalds 27621da177e4SLinus Torvalds /* 27631da177e4SLinus Torvalds * DELEGRETURN request 27641da177e4SLinus Torvalds */ 27659f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 27669f06c719SChuck Lever struct xdr_stream *xdr, 2767fcc85819SChristoph Hellwig const void *data) 27681da177e4SLinus Torvalds { 2769fcc85819SChristoph Hellwig const struct nfs4_delegreturnargs *args = data; 27701da177e4SLinus Torvalds struct compound_hdr hdr = { 277166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27721da177e4SLinus Torvalds }; 27731da177e4SLinus Torvalds 27749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27769f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2777586f1c39STrond Myklebust if (args->lr_args) 2778586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 27798ac2b422STrond Myklebust if (args->bitmask) 27809f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2781e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2782d017931cSAndy Adamson encode_nops(&hdr); 27831da177e4SLinus Torvalds } 27841da177e4SLinus Torvalds 27851da177e4SLinus Torvalds /* 2786683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2787683b57b4STrond Myklebust */ 27889f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27899f06c719SChuck Lever struct xdr_stream *xdr, 2790fcc85819SChristoph Hellwig const void *data) 2791683b57b4STrond Myklebust { 2792fcc85819SChristoph Hellwig const struct nfs4_fs_locations_arg *args = data; 2793683b57b4STrond Myklebust struct compound_hdr hdr = { 279466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2795683b57b4STrond Myklebust }; 279628f56694SBenny Halevy uint32_t replen; 2797683b57b4STrond Myklebust 27989f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27999f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2800b03d735bSChuck Lever if (args->migration) { 2801b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2802b03d735bSChuck Lever replen = hdr.replen; 2803b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2804b03d735bSChuck Lever if (args->renew) 2805b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2806b03d735bSChuck Lever } else { 28079f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 28089f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2809b03d735bSChuck Lever replen = hdr.replen; 28109f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2811b03d735bSChuck Lever } 2812cf8cdbe5SAndy Adamson 2813b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 2814fcc85819SChristoph Hellwig xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2815fcc85819SChristoph Hellwig (struct page **)&args->page, 0, PAGE_SIZE); 2816d017931cSAndy Adamson encode_nops(&hdr); 2817683b57b4STrond Myklebust } 2818683b57b4STrond Myklebust 28195a5ea0d4SBryan Schumaker /* 28205a5ea0d4SBryan Schumaker * Encode SECINFO request 28215a5ea0d4SBryan Schumaker */ 28225a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 28235a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 2824fcc85819SChristoph Hellwig const void *data) 28255a5ea0d4SBryan Schumaker { 2826fcc85819SChristoph Hellwig const struct nfs4_secinfo_arg *args = data; 28275a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 28285a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28295a5ea0d4SBryan Schumaker }; 28305a5ea0d4SBryan Schumaker 28315a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 28325a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 28335a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 28345a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 28355a5ea0d4SBryan Schumaker encode_nops(&hdr); 28365a5ea0d4SBryan Schumaker } 28375a5ea0d4SBryan Schumaker 283844c99933SChuck Lever /* 283944c99933SChuck Lever * Encode FSID_PRESENT request 284044c99933SChuck Lever */ 284144c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 284244c99933SChuck Lever struct xdr_stream *xdr, 2843fcc85819SChristoph Hellwig const void *data) 284444c99933SChuck Lever { 2845fcc85819SChristoph Hellwig const struct nfs4_fsid_present_arg *args = data; 284644c99933SChuck Lever struct compound_hdr hdr = { 284744c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 284844c99933SChuck Lever }; 284944c99933SChuck Lever 285044c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 285144c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 285244c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 285344c99933SChuck Lever encode_getfh(xdr, &hdr); 285444c99933SChuck Lever if (args->renew) 285544c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 285644c99933SChuck Lever encode_nops(&hdr); 285744c99933SChuck Lever } 285844c99933SChuck Lever 285999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 286099fe60d0SBenny Halevy /* 28617c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 28627c44f1aeSWeston Andros Adamson */ 28637c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 28647c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 2865fcc85819SChristoph Hellwig const void *data) 28667c44f1aeSWeston Andros Adamson { 2867fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args = data; 28687c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 286971a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 28707c44f1aeSWeston Andros Adamson }; 28717c44f1aeSWeston Andros Adamson 28727c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 287371a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 28747c44f1aeSWeston Andros Adamson encode_nops(&hdr); 28757c44f1aeSWeston Andros Adamson } 28767c44f1aeSWeston Andros Adamson 28777c44f1aeSWeston Andros Adamson /* 287899fe60d0SBenny Halevy * EXCHANGE_ID request 287999fe60d0SBenny Halevy */ 28809f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 28819f06c719SChuck Lever struct xdr_stream *xdr, 2882fcc85819SChristoph Hellwig const void *data) 288399fe60d0SBenny Halevy { 2884fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args = data; 288599fe60d0SBenny Halevy struct compound_hdr hdr = { 2886a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 288799fe60d0SBenny Halevy }; 288899fe60d0SBenny Halevy 28899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28909f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 289199fe60d0SBenny Halevy encode_nops(&hdr); 289299fe60d0SBenny Halevy } 28932050f0ccSAndy Adamson 28942050f0ccSAndy Adamson /* 2895fc931582SAndy Adamson * a CREATE_SESSION request 2896fc931582SAndy Adamson */ 28979f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28989f06c719SChuck Lever struct xdr_stream *xdr, 2899fcc85819SChristoph Hellwig const void *data) 2900fc931582SAndy Adamson { 2901fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args = data; 2902fc931582SAndy Adamson struct compound_hdr hdr = { 2903a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2904fc931582SAndy Adamson }; 2905fc931582SAndy Adamson 29069f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29079f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2908fc931582SAndy Adamson encode_nops(&hdr); 2909fc931582SAndy Adamson } 2910fc931582SAndy Adamson 2911fc931582SAndy Adamson /* 29120f3e66c6SAndy Adamson * a DESTROY_SESSION request 29130f3e66c6SAndy Adamson */ 29149f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 29159f06c719SChuck Lever struct xdr_stream *xdr, 2916fcc85819SChristoph Hellwig const void *data) 29170f3e66c6SAndy Adamson { 2918fcc85819SChristoph Hellwig const struct nfs4_session *session = data; 29190f3e66c6SAndy Adamson struct compound_hdr hdr = { 2920a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 29210f3e66c6SAndy Adamson }; 29220f3e66c6SAndy Adamson 29239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29249f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 29250f3e66c6SAndy Adamson encode_nops(&hdr); 29260f3e66c6SAndy Adamson } 29270f3e66c6SAndy Adamson 29280f3e66c6SAndy Adamson /* 292966245539STrond Myklebust * a DESTROY_CLIENTID request 293066245539STrond Myklebust */ 293166245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 293266245539STrond Myklebust struct xdr_stream *xdr, 2933fcc85819SChristoph Hellwig const void *data) 293466245539STrond Myklebust { 2935fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 293666245539STrond Myklebust struct compound_hdr hdr = { 293766245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 293866245539STrond Myklebust }; 293966245539STrond Myklebust 294066245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 294166245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 294266245539STrond Myklebust encode_nops(&hdr); 294366245539STrond Myklebust } 294466245539STrond Myklebust 294566245539STrond Myklebust /* 2946fc01cea9SAndy Adamson * a SEQUENCE request 2947fc01cea9SAndy Adamson */ 29489f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2949fcc85819SChristoph Hellwig const void *data) 2950fc01cea9SAndy Adamson { 2951fcc85819SChristoph Hellwig const struct nfs4_sequence_args *args = data; 2952fc01cea9SAndy Adamson struct compound_hdr hdr = { 2953fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2954fc01cea9SAndy Adamson }; 2955fc01cea9SAndy Adamson 29569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29579f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2958fc01cea9SAndy Adamson encode_nops(&hdr); 2959fc01cea9SAndy Adamson } 2960fc01cea9SAndy Adamson 2961fc01cea9SAndy Adamson /* 29622050f0ccSAndy Adamson * a GET_LEASE_TIME request 29632050f0ccSAndy Adamson */ 29649f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 29659f06c719SChuck Lever struct xdr_stream *xdr, 2966fcc85819SChristoph Hellwig const void *data) 29672050f0ccSAndy Adamson { 2968fcc85819SChristoph Hellwig const struct nfs4_get_lease_time_args *args = data; 29692050f0ccSAndy Adamson struct compound_hdr hdr = { 29702050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 29712050f0ccSAndy Adamson }; 2972dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 29732050f0ccSAndy Adamson 29749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29759f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 29769f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 29779f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 29782050f0ccSAndy Adamson encode_nops(&hdr); 29792050f0ccSAndy Adamson } 298018019753SRicardo Labiaga 298118019753SRicardo Labiaga /* 298218019753SRicardo Labiaga * a RECLAIM_COMPLETE request 298318019753SRicardo Labiaga */ 29849f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 29859f06c719SChuck Lever struct xdr_stream *xdr, 2986fcc85819SChristoph Hellwig const void *data) 298718019753SRicardo Labiaga { 2988fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args = data; 298918019753SRicardo Labiaga struct compound_hdr hdr = { 299018019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 299118019753SRicardo Labiaga }; 299218019753SRicardo Labiaga 29939f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29949f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29959f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 299618019753SRicardo Labiaga encode_nops(&hdr); 299718019753SRicardo Labiaga } 299818019753SRicardo Labiaga 2999b1f69b75SAndy Adamson /* 3000b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 3001b1f69b75SAndy Adamson */ 30029f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 30039f06c719SChuck Lever struct xdr_stream *xdr, 3004fcc85819SChristoph Hellwig const void *data) 3005b1f69b75SAndy Adamson { 3006fcc85819SChristoph Hellwig const struct nfs4_getdeviceinfo_args *args = data; 3007b1f69b75SAndy Adamson struct compound_hdr hdr = { 3008b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3009b1f69b75SAndy Adamson }; 3010b1f69b75SAndy Adamson 30119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 30129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 30139f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 3014b1f69b75SAndy Adamson 3015b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 3016b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 3017b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 3018b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 3019b1f69b75SAndy Adamson args->pdev->pglen); 3020b1f69b75SAndy Adamson 3021b1f69b75SAndy Adamson encode_nops(&hdr); 3022b1f69b75SAndy Adamson } 3023b1f69b75SAndy Adamson 3024b1f69b75SAndy Adamson /* 3025b1f69b75SAndy Adamson * Encode LAYOUTGET request 3026b1f69b75SAndy Adamson */ 30279f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 30289f06c719SChuck Lever struct xdr_stream *xdr, 3029fcc85819SChristoph Hellwig const void *data) 3030b1f69b75SAndy Adamson { 3031fcc85819SChristoph Hellwig const struct nfs4_layoutget_args *args = data; 3032b1f69b75SAndy Adamson struct compound_hdr hdr = { 3033b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3034b1f69b75SAndy Adamson }; 3035b1f69b75SAndy Adamson 30369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 30379f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 30389f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 30399f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 304035124a09SWeston Andros Adamson 304135124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 304235124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 304335124a09SWeston Andros Adamson 3044b1f69b75SAndy Adamson encode_nops(&hdr); 3045b1f69b75SAndy Adamson } 3046863a3c6cSAndy Adamson 3047863a3c6cSAndy Adamson /* 3048863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 3049863a3c6cSAndy Adamson */ 3050cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 3051863a3c6cSAndy Adamson struct xdr_stream *xdr, 3052fcc85819SChristoph Hellwig const void *priv) 3053863a3c6cSAndy Adamson { 3054fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args = priv; 3055ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 3056ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 3057863a3c6cSAndy Adamson struct compound_hdr hdr = { 3058863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3059863a3c6cSAndy Adamson }; 3060863a3c6cSAndy Adamson 3061863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 3062863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 3063863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3064ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 3065863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 3066863a3c6cSAndy Adamson encode_nops(&hdr); 3067cbe82603SBenny Halevy } 3068cbe82603SBenny Halevy 3069cbe82603SBenny Halevy /* 3070cbe82603SBenny Halevy * Encode LAYOUTRETURN request 3071cbe82603SBenny Halevy */ 3072cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 3073cbe82603SBenny Halevy struct xdr_stream *xdr, 3074fcc85819SChristoph Hellwig const void *data) 3075cbe82603SBenny Halevy { 3076fcc85819SChristoph Hellwig const struct nfs4_layoutreturn_args *args = data; 3077cbe82603SBenny Halevy struct compound_hdr hdr = { 3078cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3079cbe82603SBenny Halevy }; 3080cbe82603SBenny Halevy 3081cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 3082cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 3083cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3084cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 3085cbe82603SBenny Halevy encode_nops(&hdr); 3086863a3c6cSAndy Adamson } 3087fca78d6dSBryan Schumaker 3088fca78d6dSBryan Schumaker /* 3089fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 3090fca78d6dSBryan Schumaker */ 3091fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 3092fca78d6dSBryan Schumaker struct xdr_stream *xdr, 3093fcc85819SChristoph Hellwig const void *data) 3094fca78d6dSBryan Schumaker { 3095fcc85819SChristoph Hellwig const struct nfs41_secinfo_no_name_args *args = data; 3096fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3097fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3098fca78d6dSBryan Schumaker }; 3099fca78d6dSBryan Schumaker 3100fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3101fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3102fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3103fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3104fca78d6dSBryan Schumaker encode_nops(&hdr); 3105fca78d6dSBryan Schumaker } 31067d974794SBryan Schumaker 31077d974794SBryan Schumaker /* 31087d974794SBryan Schumaker * Encode TEST_STATEID request 31097d974794SBryan Schumaker */ 31107d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 31117d974794SBryan Schumaker struct xdr_stream *xdr, 3112fcc85819SChristoph Hellwig const void *data) 31137d974794SBryan Schumaker { 3114fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args = data; 31157d974794SBryan Schumaker struct compound_hdr hdr = { 31167d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 31177d974794SBryan Schumaker }; 31187d974794SBryan Schumaker 31197d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31207d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31217d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 31227d974794SBryan Schumaker encode_nops(&hdr); 31237d974794SBryan Schumaker } 31249aeda35fSBryan Schumaker 31259aeda35fSBryan Schumaker /* 31269aeda35fSBryan Schumaker * Encode FREE_STATEID request 31279aeda35fSBryan Schumaker */ 31289aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 31299aeda35fSBryan Schumaker struct xdr_stream *xdr, 3130fcc85819SChristoph Hellwig const void *data) 31319aeda35fSBryan Schumaker { 3132fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args = data; 31339aeda35fSBryan Schumaker struct compound_hdr hdr = { 31349aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 31359aeda35fSBryan Schumaker }; 31369aeda35fSBryan Schumaker 31379aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31389aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31399aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 31409aeda35fSBryan Schumaker encode_nops(&hdr); 31419aeda35fSBryan Schumaker } 314299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 314399fe60d0SBenny Halevy 3144686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3145686841b3SBenny Halevy { 3146686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3147686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3148686841b3SBenny Halevy func, xdr->end - xdr->p); 3149686841b3SBenny Halevy } 31501da177e4SLinus Torvalds 3151683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 31521da177e4SLinus Torvalds { 31536da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, 31546da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT); 31556da59ce2STrond Myklebust if (unlikely(ret < 0)) { 31566da59ce2STrond Myklebust if (ret == -EBADMSG) 3157c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3158c0eae66eSBenny Halevy return -EIO; 31591da177e4SLinus Torvalds } 31606da59ce2STrond Myklebust *len = ret; 31616da59ce2STrond Myklebust return 0; 31626da59ce2STrond Myklebust } 31631da177e4SLinus Torvalds 31641da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 31651da177e4SLinus Torvalds { 31668687b63aSAl Viro __be32 *p; 31671da177e4SLinus Torvalds 3168c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3169c0eae66eSBenny Halevy if (unlikely(!p)) 3170c0eae66eSBenny Halevy goto out_overflow; 31716f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3172cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 31731da177e4SLinus Torvalds 3174c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3175c0eae66eSBenny Halevy if (unlikely(!p)) 3176c0eae66eSBenny Halevy goto out_overflow; 31771da177e4SLinus Torvalds hdr->tag = (char *)p; 31781da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3179cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3180aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3181aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 31821da177e4SLinus Torvalds return 0; 3183c0eae66eSBenny Halevy out_overflow: 3184c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3185c0eae66eSBenny Halevy return -EIO; 31861da177e4SLinus Torvalds } 31871da177e4SLinus Torvalds 3188c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3189c7848f69STrond Myklebust int *nfs_retval) 31901da177e4SLinus Torvalds { 31918687b63aSAl Viro __be32 *p; 31921da177e4SLinus Torvalds uint32_t opnum; 31931da177e4SLinus Torvalds int32_t nfserr; 31941da177e4SLinus Torvalds 3195c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3196c0eae66eSBenny Halevy if (unlikely(!p)) 3197c0eae66eSBenny Halevy goto out_overflow; 31986f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3199c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3200c7848f69STrond Myklebust goto out_bad_operation; 3201c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3202c7848f69STrond Myklebust if (nfserr == NFS_OK) 3203c7848f69STrond Myklebust *nfs_retval = 0; 3204c7848f69STrond Myklebust else 3205c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3206c7848f69STrond Myklebust return true; 3207c7848f69STrond Myklebust out_bad_operation: 3208fe82a183SChuck Lever dprintk("nfs: Server returned operation" 32091da177e4SLinus Torvalds " %d but we issued a request for %d\n", 32101da177e4SLinus Torvalds opnum, expected); 3211c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3212c7848f69STrond Myklebust return false; 3213c0eae66eSBenny Halevy out_overflow: 3214c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3215c7848f69STrond Myklebust *nfs_retval = -EIO; 3216c7848f69STrond Myklebust return false; 3217c7848f69STrond Myklebust } 3218c7848f69STrond Myklebust 3219c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3220c7848f69STrond Myklebust { 3221c7848f69STrond Myklebust int retval; 3222c7848f69STrond Myklebust 3223c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3224c7848f69STrond Myklebust return retval; 32251da177e4SLinus Torvalds } 32261da177e4SLinus Torvalds 32271da177e4SLinus Torvalds /* Dummy routine */ 32281bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace) 32291da177e4SLinus Torvalds { 32308687b63aSAl Viro __be32 *p; 3231683b57b4STrond Myklebust unsigned int strlen; 32321da177e4SLinus Torvalds char *str; 32331da177e4SLinus Torvalds 3234c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3235c0eae66eSBenny Halevy if (likely(p)) 32361da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3237c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3238c0eae66eSBenny Halevy return -EIO; 32391da177e4SLinus Torvalds } 32401da177e4SLinus Torvalds 324137c88763STrond Myklebust static ssize_t 324237c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz) 32431da177e4SLinus Torvalds { 324437c88763STrond Myklebust ssize_t ret; 32451da177e4SLinus Torvalds 324637c88763STrond Myklebust ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz); 324737c88763STrond Myklebust if (likely(ret >= 0)) 324837c88763STrond Myklebust return ret; 324937c88763STrond Myklebust if (ret == -EMSGSIZE) 325037c88763STrond Myklebust return sz; 3251c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3252c0eae66eSBenny Halevy return -EIO; 32531da177e4SLinus Torvalds } 32541da177e4SLinus Torvalds 325537c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 325637c88763STrond Myklebust { 325737c88763STrond Myklebust ssize_t ret; 325837c88763STrond Myklebust ret = decode_bitmap4(xdr, bitmap, 3); 325937c88763STrond Myklebust return ret < 0 ? ret : 0; 326037c88763STrond Myklebust } 326137c88763STrond Myklebust 3262256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 32631da177e4SLinus Torvalds { 32648687b63aSAl Viro __be32 *p; 32651da177e4SLinus Torvalds 3266c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3267c0eae66eSBenny Halevy if (unlikely(!p)) 3268c0eae66eSBenny Halevy goto out_overflow; 3269cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3270256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 32711da177e4SLinus Torvalds return 0; 3272c0eae66eSBenny Halevy out_overflow: 3273c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3274c0eae66eSBenny Halevy return -EIO; 32751da177e4SLinus Torvalds } 32761da177e4SLinus Torvalds 32771da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 32781da177e4SLinus Torvalds { 32791da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 32803388bff5SRoman Borisov int ret; 32813388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 32823388bff5SRoman Borisov if (unlikely(ret < 0)) 32833388bff5SRoman Borisov return ret; 32841da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 32851da177e4SLinus Torvalds } else 3286dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3287dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3288dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 32891da177e4SLinus Torvalds return 0; 32901da177e4SLinus Torvalds } 32911da177e4SLinus Torvalds 32921da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32931da177e4SLinus Torvalds { 32948687b63aSAl Viro __be32 *p; 3295409924e4STrond Myklebust int ret = 0; 32961da177e4SLinus Torvalds 32971da177e4SLinus Torvalds *type = 0; 32981da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32991da177e4SLinus Torvalds return -EIO; 33001da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3301c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3302c0eae66eSBenny Halevy if (unlikely(!p)) 3303c0eae66eSBenny Halevy goto out_overflow; 3304cccddf4fSBenny Halevy *type = be32_to_cpup(p); 33051da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 33063110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 33071da177e4SLinus Torvalds return -EIO; 33081da177e4SLinus Torvalds } 33091da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3310409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 33111da177e4SLinus Torvalds } 3312bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3313409924e4STrond Myklebust return ret; 3314c0eae66eSBenny Halevy out_overflow: 3315c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3316c0eae66eSBenny Halevy return -EIO; 33171da177e4SLinus Torvalds } 33181da177e4SLinus Torvalds 3319264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3320264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3321264e6351SChuck Lever { 3322264e6351SChuck Lever __be32 *p; 3323264e6351SChuck Lever 3324264e6351SChuck Lever *type = 0; 3325264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3326264e6351SChuck Lever return -EIO; 3327264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3328264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3329264e6351SChuck Lever if (unlikely(!p)) 3330264e6351SChuck Lever goto out_overflow; 3331264e6351SChuck Lever *type = be32_to_cpup(p); 3332264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3333264e6351SChuck Lever } 3334264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3335264e6351SChuck Lever return 0; 3336264e6351SChuck Lever out_overflow: 3337264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3338264e6351SChuck Lever return -EIO; 3339264e6351SChuck Lever } 3340264e6351SChuck Lever 33411da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 33421da177e4SLinus Torvalds { 33438687b63aSAl Viro __be32 *p; 3344409924e4STrond Myklebust int ret = 0; 33451da177e4SLinus Torvalds 33461da177e4SLinus Torvalds *change = 0; 33471da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 33481da177e4SLinus Torvalds return -EIO; 33491da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3350c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3351c0eae66eSBenny Halevy if (unlikely(!p)) 3352c0eae66eSBenny Halevy goto out_overflow; 3353cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 33541da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3355409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 33561da177e4SLinus Torvalds } 33573110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 33581da177e4SLinus Torvalds (unsigned long long)*change); 3359409924e4STrond Myklebust return ret; 3360c0eae66eSBenny Halevy out_overflow: 3361c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3362c0eae66eSBenny Halevy return -EIO; 33631da177e4SLinus Torvalds } 33641da177e4SLinus Torvalds 33651da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 33661da177e4SLinus Torvalds { 33678687b63aSAl Viro __be32 *p; 3368409924e4STrond Myklebust int ret = 0; 33691da177e4SLinus Torvalds 33701da177e4SLinus Torvalds *size = 0; 33711da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 33721da177e4SLinus Torvalds return -EIO; 33731da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3374c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3375c0eae66eSBenny Halevy if (unlikely(!p)) 3376c0eae66eSBenny Halevy goto out_overflow; 3377cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 33781da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3379409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 33801da177e4SLinus Torvalds } 33813110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3382409924e4STrond Myklebust return ret; 3383c0eae66eSBenny Halevy out_overflow: 3384c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3385c0eae66eSBenny Halevy return -EIO; 33861da177e4SLinus Torvalds } 33871da177e4SLinus Torvalds 33881da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33891da177e4SLinus Torvalds { 33908687b63aSAl Viro __be32 *p; 33911da177e4SLinus Torvalds 33921da177e4SLinus Torvalds *res = 0; 33931da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33941da177e4SLinus Torvalds return -EIO; 33951da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3396c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3397c0eae66eSBenny Halevy if (unlikely(!p)) 3398c0eae66eSBenny Halevy goto out_overflow; 3399cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34001da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 34011da177e4SLinus Torvalds } 34023110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 34031da177e4SLinus Torvalds return 0; 3404c0eae66eSBenny Halevy out_overflow: 3405c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3406c0eae66eSBenny Halevy return -EIO; 34071da177e4SLinus Torvalds } 34081da177e4SLinus Torvalds 34091da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34101da177e4SLinus Torvalds { 34118687b63aSAl Viro __be32 *p; 34121da177e4SLinus Torvalds 34131da177e4SLinus Torvalds *res = 0; 34141da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 34151da177e4SLinus Torvalds return -EIO; 34161da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3417c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3418c0eae66eSBenny Halevy if (unlikely(!p)) 3419c0eae66eSBenny Halevy goto out_overflow; 3420cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34211da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 34221da177e4SLinus Torvalds } 34233110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 34241da177e4SLinus Torvalds return 0; 3425c0eae66eSBenny Halevy out_overflow: 3426c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3427c0eae66eSBenny Halevy return -EIO; 34281da177e4SLinus Torvalds } 34291da177e4SLinus Torvalds 34308b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 34311da177e4SLinus Torvalds { 34328687b63aSAl Viro __be32 *p; 3433409924e4STrond Myklebust int ret = 0; 34341da177e4SLinus Torvalds 34351da177e4SLinus Torvalds fsid->major = 0; 34361da177e4SLinus Torvalds fsid->minor = 0; 34371da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 34381da177e4SLinus Torvalds return -EIO; 34391da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3440c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3441c0eae66eSBenny Halevy if (unlikely(!p)) 3442c0eae66eSBenny Halevy goto out_overflow; 34433ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3444cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 34451da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3446409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 34471da177e4SLinus Torvalds } 34483110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 34491da177e4SLinus Torvalds (unsigned long long)fsid->major, 34501da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3451409924e4STrond Myklebust return ret; 3452c0eae66eSBenny Halevy out_overflow: 3453c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3454c0eae66eSBenny Halevy return -EIO; 34551da177e4SLinus Torvalds } 34561da177e4SLinus Torvalds 34571da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34581da177e4SLinus Torvalds { 34598687b63aSAl Viro __be32 *p; 34601da177e4SLinus Torvalds 34611da177e4SLinus Torvalds *res = 60; 34621da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 34631da177e4SLinus Torvalds return -EIO; 34641da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3465c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3466c0eae66eSBenny Halevy if (unlikely(!p)) 3467c0eae66eSBenny Halevy goto out_overflow; 3468cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34691da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 34701da177e4SLinus Torvalds } 34713110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 34721da177e4SLinus Torvalds return 0; 3473c0eae66eSBenny Halevy out_overflow: 3474c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3475c0eae66eSBenny Halevy return -EIO; 34761da177e4SLinus Torvalds } 34771da177e4SLinus Torvalds 3478ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3479ae42c70aSBryan Schumaker { 3480ae42c70aSBryan Schumaker __be32 *p; 3481ae42c70aSBryan Schumaker 3482ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3483ae42c70aSBryan Schumaker return -EIO; 3484ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3485ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3486ae42c70aSBryan Schumaker if (unlikely(!p)) 3487ae42c70aSBryan Schumaker goto out_overflow; 3488ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3489ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3490ae42c70aSBryan Schumaker } 3491ae42c70aSBryan Schumaker return 0; 3492ae42c70aSBryan Schumaker out_overflow: 3493ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3494ae42c70aSBryan Schumaker return -EIO; 3495ae42c70aSBryan Schumaker } 3496ae42c70aSBryan Schumaker 34978c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 34988c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 34998c61282fSKinglong Mee { 35008c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 35018c61282fSKinglong Mee int ret; 35028c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 35038c61282fSKinglong Mee if (unlikely(ret < 0)) 35048c61282fSKinglong Mee return ret; 35058c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 35068c61282fSKinglong Mee } else 35078c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 35088c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 35098c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 35108c61282fSKinglong Mee return 0; 35118c61282fSKinglong Mee } 35128c61282fSKinglong Mee 3513ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3514ae42c70aSBryan Schumaker { 3515ae42c70aSBryan Schumaker __be32 *p; 3516ae42c70aSBryan Schumaker int len; 3517ae42c70aSBryan Schumaker 35187ad07353STrond Myklebust if (fh != NULL) 3519ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3520ae42c70aSBryan Schumaker 3521ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3522ae42c70aSBryan Schumaker return -EIO; 3523ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3524ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3525ae42c70aSBryan Schumaker if (unlikely(!p)) 3526ae42c70aSBryan Schumaker goto out_overflow; 3527ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3528ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3529ae42c70aSBryan Schumaker return -EIO; 3530ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3531ae42c70aSBryan Schumaker if (unlikely(!p)) 3532ae42c70aSBryan Schumaker goto out_overflow; 35337ad07353STrond Myklebust if (fh != NULL) { 3534ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 35357ad07353STrond Myklebust fh->size = len; 35367ad07353STrond Myklebust } 3537ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3538ae42c70aSBryan Schumaker } 3539ae42c70aSBryan Schumaker return 0; 3540ae42c70aSBryan Schumaker out_overflow: 3541ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3542ae42c70aSBryan Schumaker return -EIO; 3543ae42c70aSBryan Schumaker } 3544ae42c70aSBryan Schumaker 35451da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 35461da177e4SLinus Torvalds { 35478687b63aSAl Viro __be32 *p; 35481da177e4SLinus Torvalds 3549a1800acaSMalahal Naineni *res = 0; 35501da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 35511da177e4SLinus Torvalds return -EIO; 35521da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3553c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3554c0eae66eSBenny Halevy if (unlikely(!p)) 3555c0eae66eSBenny Halevy goto out_overflow; 3556cccddf4fSBenny Halevy *res = be32_to_cpup(p); 35571da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 35581da177e4SLinus Torvalds } 35593110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 35601da177e4SLinus Torvalds return 0; 3561c0eae66eSBenny Halevy out_overflow: 3562c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3563c0eae66eSBenny Halevy return -EIO; 35641da177e4SLinus Torvalds } 35651da177e4SLinus Torvalds 35661da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 35671da177e4SLinus Torvalds { 35688687b63aSAl Viro __be32 *p; 3569409924e4STrond Myklebust int ret = 0; 35701da177e4SLinus Torvalds 35711da177e4SLinus Torvalds *fileid = 0; 35721da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 35731da177e4SLinus Torvalds return -EIO; 35741da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3575c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3576c0eae66eSBenny Halevy if (unlikely(!p)) 3577c0eae66eSBenny Halevy goto out_overflow; 3578cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 35791da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3580409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 35811da177e4SLinus Torvalds } 35823110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3583409924e4STrond Myklebust return ret; 3584c0eae66eSBenny Halevy out_overflow: 3585c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3586c0eae66eSBenny Halevy return -EIO; 35871da177e4SLinus Torvalds } 35881da177e4SLinus Torvalds 358999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 359099baf625SManoj Naik { 35918687b63aSAl Viro __be32 *p; 3592409924e4STrond Myklebust int ret = 0; 359399baf625SManoj Naik 359499baf625SManoj Naik *fileid = 0; 359599baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 359699baf625SManoj Naik return -EIO; 359799baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3598c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3599c0eae66eSBenny Halevy if (unlikely(!p)) 3600c0eae66eSBenny Halevy goto out_overflow; 3601cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 360299baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 360328331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 360499baf625SManoj Naik } 36053110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3606409924e4STrond Myklebust return ret; 3607c0eae66eSBenny Halevy out_overflow: 3608c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3609c0eae66eSBenny Halevy return -EIO; 361099baf625SManoj Naik } 361199baf625SManoj Naik 36121da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36131da177e4SLinus Torvalds { 36148687b63aSAl Viro __be32 *p; 36151da177e4SLinus Torvalds int status = 0; 36161da177e4SLinus Torvalds 36171da177e4SLinus Torvalds *res = 0; 36181da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 36191da177e4SLinus Torvalds return -EIO; 36201da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3621c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3622c0eae66eSBenny Halevy if (unlikely(!p)) 3623c0eae66eSBenny Halevy goto out_overflow; 3624cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36251da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 36261da177e4SLinus Torvalds } 36273110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 36281da177e4SLinus Torvalds return status; 3629c0eae66eSBenny Halevy out_overflow: 3630c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3631c0eae66eSBenny Halevy return -EIO; 36321da177e4SLinus Torvalds } 36331da177e4SLinus Torvalds 36341da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36351da177e4SLinus Torvalds { 36368687b63aSAl Viro __be32 *p; 36371da177e4SLinus Torvalds int status = 0; 36381da177e4SLinus Torvalds 36391da177e4SLinus Torvalds *res = 0; 36401da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 36411da177e4SLinus Torvalds return -EIO; 36421da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3643c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3644c0eae66eSBenny Halevy if (unlikely(!p)) 3645c0eae66eSBenny Halevy goto out_overflow; 3646cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36471da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 36481da177e4SLinus Torvalds } 36493110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 36501da177e4SLinus Torvalds return status; 3651c0eae66eSBenny Halevy out_overflow: 3652c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3653c0eae66eSBenny Halevy return -EIO; 36541da177e4SLinus Torvalds } 36551da177e4SLinus Torvalds 36561da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36571da177e4SLinus Torvalds { 36588687b63aSAl Viro __be32 *p; 36591da177e4SLinus Torvalds int status = 0; 36601da177e4SLinus Torvalds 36611da177e4SLinus Torvalds *res = 0; 36621da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 36631da177e4SLinus Torvalds return -EIO; 36641da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3665c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3666c0eae66eSBenny Halevy if (unlikely(!p)) 3667c0eae66eSBenny Halevy goto out_overflow; 3668cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36691da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 36701da177e4SLinus Torvalds } 36713110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 36721da177e4SLinus Torvalds return status; 3673c0eae66eSBenny Halevy out_overflow: 3674c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3675c0eae66eSBenny Halevy return -EIO; 36761da177e4SLinus Torvalds } 36771da177e4SLinus Torvalds 36787aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 36797aaa0b3bSManoj Naik { 3680464ad6b1SChuck Lever u32 n; 36818687b63aSAl Viro __be32 *p; 36827aaa0b3bSManoj Naik int status = 0; 36837aaa0b3bSManoj Naik 3684c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3685c0eae66eSBenny Halevy if (unlikely(!p)) 3686c0eae66eSBenny Halevy goto out_overflow; 3687cccddf4fSBenny Halevy n = be32_to_cpup(p); 368833a43f28SAndy Adamson if (n == 0) 368933a43f28SAndy Adamson goto root_path; 369002a2976cSChuck Lever dprintk("pathname4: "); 3691809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3692809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3693809b426cSTrond Myklebust goto out_eio; 3694809b426cSTrond Myklebust } 3695809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36967aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 36977aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 36987aaa0b3bSManoj Naik if (unlikely(status != 0)) 36997aaa0b3bSManoj Naik goto out_eio; 370095a13f7bSTrond Myklebust ifdebug (XDR) 370102a2976cSChuck Lever pr_cont("%s%.*s ", 370202a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 370302a2976cSChuck Lever component->len, component->data); 37047aaa0b3bSManoj Naik } 37057aaa0b3bSManoj Naik out: 37067aaa0b3bSManoj Naik return status; 370733a43f28SAndy Adamson root_path: 370833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 370933a43f28SAndy Adamson path->ncomponents = 1; 371033a43f28SAndy Adamson path->components[0].len=0; 371133a43f28SAndy Adamson path->components[0].data=NULL; 371202a2976cSChuck Lever dprintk("pathname4: /\n"); 371333a43f28SAndy Adamson goto out; 37147aaa0b3bSManoj Naik out_eio: 37157aaa0b3bSManoj Naik dprintk(" status %d", status); 37167aaa0b3bSManoj Naik status = -EIO; 37177aaa0b3bSManoj Naik goto out; 3718c0eae66eSBenny Halevy out_overflow: 3719c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3720c0eae66eSBenny Halevy return -EIO; 37217aaa0b3bSManoj Naik } 37227aaa0b3bSManoj Naik 37237aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3724683b57b4STrond Myklebust { 3725683b57b4STrond Myklebust int n; 37268687b63aSAl Viro __be32 *p; 3727683b57b4STrond Myklebust int status = -EIO; 3728683b57b4STrond Myklebust 3729683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3730683b57b4STrond Myklebust goto out; 3731683b57b4STrond Myklebust status = 0; 3732683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3733683b57b4STrond Myklebust goto out; 3734f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 37358b7e3f49STrond Myklebust status = -EIO; 37368b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 37378b7e3f49STrond Myklebust if (unlikely(res == NULL)) 37388b7e3f49STrond Myklebust goto out; 373902a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 37407aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3741683b57b4STrond Myklebust if (unlikely(status != 0)) 3742683b57b4STrond Myklebust goto out; 3743c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3744c0eae66eSBenny Halevy if (unlikely(!p)) 3745c0eae66eSBenny Halevy goto out_overflow; 3746cccddf4fSBenny Halevy n = be32_to_cpup(p); 3747683b57b4STrond Myklebust if (n <= 0) 3748683b57b4STrond Myklebust goto out_eio; 3749809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3750464ad6b1SChuck Lever u32 m; 3751809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3752683b57b4STrond Myklebust 3753809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3754809b426cSTrond Myklebust break; 3755809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3756c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3757c0eae66eSBenny Halevy if (unlikely(!p)) 3758c0eae66eSBenny Halevy goto out_overflow; 3759cccddf4fSBenny Halevy m = be32_to_cpup(p); 37607aaa0b3bSManoj Naik 376102a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3762809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3763809b426cSTrond Myklebust struct nfs4_string *server; 3764809b426cSTrond Myklebust 3765809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3766464ad6b1SChuck Lever unsigned int i; 3767464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3768464ad6b1SChuck Lever "returned for location %u\n", 37693110ff80SHarvey Harrison __func__, 3770464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3771464ad6b1SChuck Lever m, res->nlocations); 37727aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 37732e42c3e2STrond Myklebust unsigned int len; 37747aaa0b3bSManoj Naik char *data; 37757aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3776683b57b4STrond Myklebust if (unlikely(status != 0)) 3777683b57b4STrond Myklebust goto out_eio; 37787aaa0b3bSManoj Naik } 3779809b426cSTrond Myklebust break; 37807aaa0b3bSManoj Naik } 3781809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3782809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3783809b426cSTrond Myklebust if (unlikely(status != 0)) 3784809b426cSTrond Myklebust goto out_eio; 3785809b426cSTrond Myklebust dprintk("%s ", server->data); 37867aaa0b3bSManoj Naik } 37877aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 37887aaa0b3bSManoj Naik if (unlikely(status != 0)) 37897aaa0b3bSManoj Naik goto out_eio; 3790683b57b4STrond Myklebust } 3791409924e4STrond Myklebust if (res->nlocations != 0) 379281934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3793683b57b4STrond Myklebust out: 37943110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3795683b57b4STrond Myklebust return status; 3796c0eae66eSBenny Halevy out_overflow: 3797c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3798683b57b4STrond Myklebust out_eio: 3799683b57b4STrond Myklebust status = -EIO; 3800683b57b4STrond Myklebust goto out; 3801683b57b4STrond Myklebust } 3802683b57b4STrond Myklebust 38031da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38041da177e4SLinus Torvalds { 38058687b63aSAl Viro __be32 *p; 38061da177e4SLinus Torvalds int status = 0; 38071da177e4SLinus Torvalds 38081da177e4SLinus Torvalds *res = 0; 38091da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 38101da177e4SLinus Torvalds return -EIO; 38111da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3812c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3813c0eae66eSBenny Halevy if (unlikely(!p)) 3814c0eae66eSBenny Halevy goto out_overflow; 3815cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38161da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 38171da177e4SLinus Torvalds } 38183110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 38191da177e4SLinus Torvalds return status; 3820c0eae66eSBenny Halevy out_overflow: 3821c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3822c0eae66eSBenny Halevy return -EIO; 38231da177e4SLinus Torvalds } 38241da177e4SLinus Torvalds 38251da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 38261da177e4SLinus Torvalds { 38278687b63aSAl Viro __be32 *p; 38281da177e4SLinus Torvalds int status = 0; 38291da177e4SLinus Torvalds 38301da177e4SLinus Torvalds *maxlink = 1; 38311da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 38321da177e4SLinus Torvalds return -EIO; 38331da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3834c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3835c0eae66eSBenny Halevy if (unlikely(!p)) 3836c0eae66eSBenny Halevy goto out_overflow; 3837cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 38381da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 38391da177e4SLinus Torvalds } 38403110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 38411da177e4SLinus Torvalds return status; 3842c0eae66eSBenny Halevy out_overflow: 3843c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3844c0eae66eSBenny Halevy return -EIO; 38451da177e4SLinus Torvalds } 38461da177e4SLinus Torvalds 38471da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 38481da177e4SLinus Torvalds { 38498687b63aSAl Viro __be32 *p; 38501da177e4SLinus Torvalds int status = 0; 38511da177e4SLinus Torvalds 38521da177e4SLinus Torvalds *maxname = 1024; 38531da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 38541da177e4SLinus Torvalds return -EIO; 38551da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3856c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3857c0eae66eSBenny Halevy if (unlikely(!p)) 3858c0eae66eSBenny Halevy goto out_overflow; 3859cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 38601da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 38611da177e4SLinus Torvalds } 38623110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 38631da177e4SLinus Torvalds return status; 3864c0eae66eSBenny Halevy out_overflow: 3865c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3866c0eae66eSBenny Halevy return -EIO; 38671da177e4SLinus Torvalds } 38681da177e4SLinus Torvalds 38691da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38701da177e4SLinus Torvalds { 38718687b63aSAl Viro __be32 *p; 38721da177e4SLinus Torvalds int status = 0; 38731da177e4SLinus Torvalds 38741da177e4SLinus Torvalds *res = 1024; 38751da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 38761da177e4SLinus Torvalds return -EIO; 38771da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 38781da177e4SLinus Torvalds uint64_t maxread; 3879c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3880c0eae66eSBenny Halevy if (unlikely(!p)) 3881c0eae66eSBenny Halevy goto out_overflow; 3882cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 38831da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 38841da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 38851da177e4SLinus Torvalds *res = (uint32_t)maxread; 38861da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 38871da177e4SLinus Torvalds } 38883110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 38891da177e4SLinus Torvalds return status; 3890c0eae66eSBenny Halevy out_overflow: 3891c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3892c0eae66eSBenny Halevy return -EIO; 38931da177e4SLinus Torvalds } 38941da177e4SLinus Torvalds 38951da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38961da177e4SLinus Torvalds { 38978687b63aSAl Viro __be32 *p; 38981da177e4SLinus Torvalds int status = 0; 38991da177e4SLinus Torvalds 39001da177e4SLinus Torvalds *res = 1024; 39011da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 39021da177e4SLinus Torvalds return -EIO; 39031da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 39041da177e4SLinus Torvalds uint64_t maxwrite; 3905c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3906c0eae66eSBenny Halevy if (unlikely(!p)) 3907c0eae66eSBenny Halevy goto out_overflow; 3908cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 39091da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 39101da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 39111da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 39121da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 39131da177e4SLinus Torvalds } 39143110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 39151da177e4SLinus Torvalds return status; 3916c0eae66eSBenny Halevy out_overflow: 3917c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3918c0eae66eSBenny Halevy return -EIO; 39191da177e4SLinus Torvalds } 39201da177e4SLinus Torvalds 3921bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 39221da177e4SLinus Torvalds { 3923bca79478STrond Myklebust uint32_t tmp; 39248687b63aSAl Viro __be32 *p; 3925409924e4STrond Myklebust int ret = 0; 39261da177e4SLinus Torvalds 39271da177e4SLinus Torvalds *mode = 0; 39281da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 39291da177e4SLinus Torvalds return -EIO; 39301da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3931c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3932c0eae66eSBenny Halevy if (unlikely(!p)) 3933c0eae66eSBenny Halevy goto out_overflow; 3934cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3935bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 39361da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3937409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 39381da177e4SLinus Torvalds } 39393110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3940409924e4STrond Myklebust return ret; 3941c0eae66eSBenny Halevy out_overflow: 3942c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3943c0eae66eSBenny Halevy return -EIO; 39441da177e4SLinus Torvalds } 39451da177e4SLinus Torvalds 39461da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 39471da177e4SLinus Torvalds { 39488687b63aSAl Viro __be32 *p; 3949409924e4STrond Myklebust int ret = 0; 39501da177e4SLinus Torvalds 39511da177e4SLinus Torvalds *nlink = 1; 39521da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 39531da177e4SLinus Torvalds return -EIO; 39541da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3955c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3956c0eae66eSBenny Halevy if (unlikely(!p)) 3957c0eae66eSBenny Halevy goto out_overflow; 3958cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 39591da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3960409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 39611da177e4SLinus Torvalds } 39623110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3963409924e4STrond Myklebust return ret; 3964c0eae66eSBenny Halevy out_overflow: 3965c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3966c0eae66eSBenny Halevy return -EIO; 39671da177e4SLinus Torvalds } 39681da177e4SLinus Torvalds 3969686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr, 3970686a816aSTrond Myklebust struct nfs4_string *name, gfp_t gfp_flags) 3971686a816aSTrond Myklebust { 3972686a816aSTrond Myklebust ssize_t ret; 3973686a816aSTrond Myklebust 3974686a816aSTrond Myklebust ret = xdr_stream_decode_string_dup(xdr, &name->data, 3975686a816aSTrond Myklebust XDR_MAX_NETOBJ, gfp_flags); 3976686a816aSTrond Myklebust name->len = 0; 3977686a816aSTrond Myklebust if (ret > 0) 3978686a816aSTrond Myklebust name->len = ret; 3979686a816aSTrond Myklebust return ret; 3980686a816aSTrond Myklebust } 3981686a816aSTrond Myklebust 398280e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3983e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 39846926afd1STrond Myklebust struct nfs4_string *owner_name) 39851da177e4SLinus Torvalds { 3986686a816aSTrond Myklebust ssize_t len; 3987686a816aSTrond Myklebust char *p; 39881da177e4SLinus Torvalds 3989e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 39901da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 39911da177e4SLinus Torvalds return -EIO; 3992686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER)) 3993686a816aSTrond Myklebust return 0; 39941da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 3995686a816aSTrond Myklebust 3996686a816aSTrond Myklebust if (owner_name != NULL) { 3997e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, owner_name, GFP_NOIO); 3998686a816aSTrond Myklebust if (len <= 0) 3999686a816aSTrond Myklebust goto out; 4000686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, owner_name->data); 4001686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER_NAME; 4002686a816aSTrond Myklebust } else { 4003686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 4004686a816aSTrond Myklebust XDR_MAX_NETOBJ); 4005686a816aSTrond Myklebust if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0) 4006686a816aSTrond Myklebust goto out; 4007e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 4008686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER; 4009686a816aSTrond Myklebust } 4010686a816aSTrond Myklebust out: 4011686a816aSTrond Myklebust if (len != -EBADMSG) 4012686a816aSTrond Myklebust return 0; 4013c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4014c0eae66eSBenny Halevy return -EIO; 40151da177e4SLinus Torvalds } 40161da177e4SLinus Torvalds 401780e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 4018e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 40196926afd1STrond Myklebust struct nfs4_string *group_name) 40201da177e4SLinus Torvalds { 4021686a816aSTrond Myklebust ssize_t len; 4022686a816aSTrond Myklebust char *p; 40231da177e4SLinus Torvalds 4024e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 40251da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 40261da177e4SLinus Torvalds return -EIO; 4027686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) 4028686a816aSTrond Myklebust return 0; 40291da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 4030686a816aSTrond Myklebust 4031686a816aSTrond Myklebust if (group_name != NULL) { 4032e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, group_name, GFP_NOIO); 4033686a816aSTrond Myklebust if (len <= 0) 4034686a816aSTrond Myklebust goto out; 4035686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, group_name->data); 40366f1f6220SKinglong Mee return NFS_ATTR_FATTR_GROUP_NAME; 4037686a816aSTrond Myklebust } else { 4038686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 4039686a816aSTrond Myklebust XDR_MAX_NETOBJ); 4040686a816aSTrond Myklebust if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0) 4041686a816aSTrond Myklebust goto out; 4042e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 4043686a816aSTrond Myklebust return NFS_ATTR_FATTR_GROUP; 4044686a816aSTrond Myklebust } 4045686a816aSTrond Myklebust out: 4046686a816aSTrond Myklebust if (len != -EBADMSG) 4047686a816aSTrond Myklebust return 0; 4048c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4049c0eae66eSBenny Halevy return -EIO; 40501da177e4SLinus Torvalds } 40511da177e4SLinus Torvalds 40521da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 40531da177e4SLinus Torvalds { 40548687b63aSAl Viro uint32_t major = 0, minor = 0; 40558687b63aSAl Viro __be32 *p; 4056409924e4STrond Myklebust int ret = 0; 40571da177e4SLinus Torvalds 40581da177e4SLinus Torvalds *rdev = MKDEV(0,0); 40591da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 40601da177e4SLinus Torvalds return -EIO; 40611da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 40621da177e4SLinus Torvalds dev_t tmp; 40631da177e4SLinus Torvalds 4064c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4065c0eae66eSBenny Halevy if (unlikely(!p)) 4066c0eae66eSBenny Halevy goto out_overflow; 40676f723f77SBenny Halevy major = be32_to_cpup(p++); 4068cccddf4fSBenny Halevy minor = be32_to_cpup(p); 40691da177e4SLinus Torvalds tmp = MKDEV(major, minor); 40701da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 40711da177e4SLinus Torvalds *rdev = tmp; 40721da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 4073409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 40741da177e4SLinus Torvalds } 40753110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 4076409924e4STrond Myklebust return ret; 4077c0eae66eSBenny Halevy out_overflow: 4078c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4079c0eae66eSBenny Halevy return -EIO; 40801da177e4SLinus Torvalds } 40811da177e4SLinus Torvalds 40821da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40831da177e4SLinus Torvalds { 40848687b63aSAl Viro __be32 *p; 40851da177e4SLinus Torvalds int status = 0; 40861da177e4SLinus Torvalds 40871da177e4SLinus Torvalds *res = 0; 40881da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 40891da177e4SLinus Torvalds return -EIO; 40901da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 4091c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4092c0eae66eSBenny Halevy if (unlikely(!p)) 4093c0eae66eSBenny Halevy goto out_overflow; 4094cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40951da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40961da177e4SLinus Torvalds } 40973110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 40981da177e4SLinus Torvalds return status; 4099c0eae66eSBenny Halevy out_overflow: 4100c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4101c0eae66eSBenny Halevy return -EIO; 41021da177e4SLinus Torvalds } 41031da177e4SLinus Torvalds 41041da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 41051da177e4SLinus Torvalds { 41068687b63aSAl Viro __be32 *p; 41071da177e4SLinus Torvalds int status = 0; 41081da177e4SLinus Torvalds 41091da177e4SLinus Torvalds *res = 0; 41101da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 41111da177e4SLinus Torvalds return -EIO; 41121da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4113c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4114c0eae66eSBenny Halevy if (unlikely(!p)) 4115c0eae66eSBenny Halevy goto out_overflow; 4116cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 41171da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 41181da177e4SLinus Torvalds } 41193110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 41201da177e4SLinus Torvalds return status; 4121c0eae66eSBenny Halevy out_overflow: 4122c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4123c0eae66eSBenny Halevy return -EIO; 41241da177e4SLinus Torvalds } 41251da177e4SLinus Torvalds 41261da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 41271da177e4SLinus Torvalds { 41288687b63aSAl Viro __be32 *p; 41291da177e4SLinus Torvalds int status = 0; 41301da177e4SLinus Torvalds 41311da177e4SLinus Torvalds *res = 0; 41321da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 41331da177e4SLinus Torvalds return -EIO; 41341da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4135c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4136c0eae66eSBenny Halevy if (unlikely(!p)) 4137c0eae66eSBenny Halevy goto out_overflow; 4138cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 41391da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 41401da177e4SLinus Torvalds } 41413110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 41421da177e4SLinus Torvalds return status; 4143c0eae66eSBenny Halevy out_overflow: 4144c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4145c0eae66eSBenny Halevy return -EIO; 41461da177e4SLinus Torvalds } 41471da177e4SLinus Torvalds 41481da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 41491da177e4SLinus Torvalds { 41508687b63aSAl Viro __be32 *p; 4151409924e4STrond Myklebust int ret = 0; 41521da177e4SLinus Torvalds 41531da177e4SLinus Torvalds *used = 0; 41541da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 41551da177e4SLinus Torvalds return -EIO; 41561da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4157c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4158c0eae66eSBenny Halevy if (unlikely(!p)) 4159c0eae66eSBenny Halevy goto out_overflow; 4160cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 41611da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4162409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 41631da177e4SLinus Torvalds } 41643110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 41651da177e4SLinus Torvalds (unsigned long long)*used); 4166409924e4STrond Myklebust return ret; 4167c0eae66eSBenny Halevy out_overflow: 4168c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4169c0eae66eSBenny Halevy return -EIO; 41701da177e4SLinus Torvalds } 41711da177e4SLinus Torvalds 417236b3743fSTrond Myklebust static __be32 * 417336b3743fSTrond Myklebust xdr_decode_nfstime4(__be32 *p, struct timespec *t) 417436b3743fSTrond Myklebust { 417536b3743fSTrond Myklebust __u64 sec; 417636b3743fSTrond Myklebust 417736b3743fSTrond Myklebust p = xdr_decode_hyper(p, &sec); 417836b3743fSTrond Myklebust t-> tv_sec = (time_t)sec; 417936b3743fSTrond Myklebust t->tv_nsec = be32_to_cpup(p++); 418036b3743fSTrond Myklebust return p; 418136b3743fSTrond Myklebust } 418236b3743fSTrond Myklebust 41831da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 41841da177e4SLinus Torvalds { 41858687b63aSAl Viro __be32 *p; 41861da177e4SLinus Torvalds 418736b3743fSTrond Myklebust p = xdr_inline_decode(xdr, nfstime4_maxsz << 2); 4188c0eae66eSBenny Halevy if (unlikely(!p)) 4189c0eae66eSBenny Halevy goto out_overflow; 419036b3743fSTrond Myklebust xdr_decode_nfstime4(p, time); 41911da177e4SLinus Torvalds return 0; 4192c0eae66eSBenny Halevy out_overflow: 4193c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4194c0eae66eSBenny Halevy return -EIO; 41951da177e4SLinus Torvalds } 41961da177e4SLinus Torvalds 41971da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41981da177e4SLinus Torvalds { 41991da177e4SLinus Torvalds int status = 0; 42001da177e4SLinus Torvalds 42011da177e4SLinus Torvalds time->tv_sec = 0; 42021da177e4SLinus Torvalds time->tv_nsec = 0; 42031da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 42041da177e4SLinus Torvalds return -EIO; 42051da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 42061da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4207409924e4STrond Myklebust if (status == 0) 4208409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 42091da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 42101da177e4SLinus Torvalds } 42113110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 42121da177e4SLinus Torvalds return status; 42131da177e4SLinus Torvalds } 42141da177e4SLinus Torvalds 42151da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42161da177e4SLinus Torvalds { 42171da177e4SLinus Torvalds int status = 0; 42181da177e4SLinus Torvalds 42191da177e4SLinus Torvalds time->tv_sec = 0; 42201da177e4SLinus Torvalds time->tv_nsec = 0; 42211da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 42221da177e4SLinus Torvalds return -EIO; 42231da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 42241da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4225409924e4STrond Myklebust if (status == 0) 4226409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 42271da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 42281da177e4SLinus Torvalds } 42293110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 42301da177e4SLinus Torvalds return status; 42311da177e4SLinus Torvalds } 42321da177e4SLinus Torvalds 423355b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 423455b6e774SRicardo Labiaga struct timespec *time) 423555b6e774SRicardo Labiaga { 423655b6e774SRicardo Labiaga int status = 0; 423755b6e774SRicardo Labiaga 423855b6e774SRicardo Labiaga time->tv_sec = 0; 423955b6e774SRicardo Labiaga time->tv_nsec = 0; 424055b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 424155b6e774SRicardo Labiaga return -EIO; 424255b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 424355b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 424455b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 424555b6e774SRicardo Labiaga } 424655b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 424755b6e774SRicardo Labiaga (long)time->tv_nsec); 424855b6e774SRicardo Labiaga return status; 424955b6e774SRicardo Labiaga } 425055b6e774SRicardo Labiaga 4251aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4252aa9c2669SDavid Quigley struct nfs4_label *label) 4253aa9c2669SDavid Quigley { 4254aa9c2669SDavid Quigley uint32_t pi = 0; 4255aa9c2669SDavid Quigley uint32_t lfs = 0; 4256aa9c2669SDavid Quigley __u32 len; 4257aa9c2669SDavid Quigley __be32 *p; 4258aa9c2669SDavid Quigley int status = 0; 4259aa9c2669SDavid Quigley 4260aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4261aa9c2669SDavid Quigley return -EIO; 4262aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4263aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4264aa9c2669SDavid Quigley if (unlikely(!p)) 4265aa9c2669SDavid Quigley goto out_overflow; 4266aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4267aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4268aa9c2669SDavid Quigley if (unlikely(!p)) 4269aa9c2669SDavid Quigley goto out_overflow; 4270aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4271aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4272aa9c2669SDavid Quigley if (unlikely(!p)) 4273aa9c2669SDavid Quigley goto out_overflow; 4274aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4275aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4276aa9c2669SDavid Quigley if (unlikely(!p)) 4277aa9c2669SDavid Quigley goto out_overflow; 4278aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4279aa9c2669SDavid Quigley if (label) { 4280aa9c2669SDavid Quigley memcpy(label->label, p, len); 4281aa9c2669SDavid Quigley label->len = len; 4282aa9c2669SDavid Quigley label->pi = pi; 4283aa9c2669SDavid Quigley label->lfs = lfs; 4284aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4285aa9c2669SDavid Quigley } 4286aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4287aa9c2669SDavid Quigley } else 4288aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4289aa9c2669SDavid Quigley __func__, len); 4290aa9c2669SDavid Quigley } 4291aa9c2669SDavid Quigley if (label && label->label) 4292aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4293aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4294aa9c2669SDavid Quigley return status; 4295aa9c2669SDavid Quigley 4296aa9c2669SDavid Quigley out_overflow: 4297aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4298aa9c2669SDavid Quigley return -EIO; 4299aa9c2669SDavid Quigley } 4300aa9c2669SDavid Quigley 43011da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 43021da177e4SLinus Torvalds { 43031da177e4SLinus Torvalds int status = 0; 43041da177e4SLinus Torvalds 43051da177e4SLinus Torvalds time->tv_sec = 0; 43061da177e4SLinus Torvalds time->tv_nsec = 0; 43071da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 43081da177e4SLinus Torvalds return -EIO; 43091da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 43101da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4311409924e4STrond Myklebust if (status == 0) 4312409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 43131da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 43141da177e4SLinus Torvalds } 43153110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 43161da177e4SLinus Torvalds return status; 43171da177e4SLinus Torvalds } 43181da177e4SLinus Torvalds 4319256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 43201da177e4SLinus Torvalds { 43211da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4322256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 43231da177e4SLinus Torvalds 43241da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4325fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4326fe82a183SChuck Lever "%u %c %u\n", 43273110ff80SHarvey Harrison __func__, 43281da177e4SLinus Torvalds attrwords << 2, 43291da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 43301da177e4SLinus Torvalds nwords << 2); 43311da177e4SLinus Torvalds return -EIO; 43321da177e4SLinus Torvalds } 43331da177e4SLinus Torvalds return 0; 43341da177e4SLinus Torvalds } 43351da177e4SLinus Torvalds 43361da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43371da177e4SLinus Torvalds { 43388687b63aSAl Viro __be32 *p; 43391da177e4SLinus Torvalds 4340c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4341c0eae66eSBenny Halevy if (unlikely(!p)) 4342c0eae66eSBenny Halevy goto out_overflow; 43436f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 43443ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4345cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 43461da177e4SLinus Torvalds return 0; 4347c0eae66eSBenny Halevy out_overflow: 4348c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4349c0eae66eSBenny Halevy return -EIO; 43501da177e4SLinus Torvalds } 43511da177e4SLinus Torvalds 43526168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 43531da177e4SLinus Torvalds { 43548687b63aSAl Viro __be32 *p; 43551da177e4SLinus Torvalds uint32_t supp, acc; 43561da177e4SLinus Torvalds int status; 43571da177e4SLinus Torvalds 43581da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 43591da177e4SLinus Torvalds if (status) 43601da177e4SLinus Torvalds return status; 4361c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4362c0eae66eSBenny Halevy if (unlikely(!p)) 4363c0eae66eSBenny Halevy goto out_overflow; 43646f723f77SBenny Halevy supp = be32_to_cpup(p++); 4365cccddf4fSBenny Halevy acc = be32_to_cpup(p); 43666168f62cSWeston Andros Adamson *supported = supp; 43676168f62cSWeston Andros Adamson *access = acc; 43681da177e4SLinus Torvalds return 0; 4369c0eae66eSBenny Halevy out_overflow: 4370c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4371c0eae66eSBenny Halevy return -EIO; 43721da177e4SLinus Torvalds } 43731da177e4SLinus Torvalds 437407d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 43751da177e4SLinus Torvalds { 4376ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); 4377ab6e9aafSTrond Myklebust if (unlikely(ret < 0)) { 437807d30434SBenny Halevy print_overflow_msg(__func__, xdr); 437907d30434SBenny Halevy return -EIO; 438007d30434SBenny Halevy } 4381ab6e9aafSTrond Myklebust return 0; 4382ab6e9aafSTrond Myklebust } 438307d30434SBenny Halevy 438407d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 438507d30434SBenny Halevy { 43862d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 43871da177e4SLinus Torvalds } 43881da177e4SLinus Torvalds 438993b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 439093b717fdSTrond Myklebust { 439193b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 439293b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 439393b717fdSTrond Myklebust } 439493b717fdSTrond Myklebust 439593b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 439693b717fdSTrond Myklebust { 439793b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 439893b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 439993b717fdSTrond Myklebust } 440093b717fdSTrond Myklebust 440193b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 440293b717fdSTrond Myklebust { 440393b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 440493b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 440593b717fdSTrond Myklebust } 440693b717fdSTrond Myklebust 4407fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 4408fcd8843cSTrond Myklebust { 4409fcd8843cSTrond Myklebust nfs4_stateid dummy; 4410fcd8843cSTrond Myklebust 4411fcd8843cSTrond Myklebust nfs4_stateid_copy(stateid, &invalid_stateid); 4412fcd8843cSTrond Myklebust return decode_stateid(xdr, &dummy); 4413fcd8843cSTrond Myklebust } 4414fcd8843cSTrond Myklebust 44151da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 44161da177e4SLinus Torvalds { 44171da177e4SLinus Torvalds int status; 44181da177e4SLinus Torvalds 44191da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4420c1d51931STrond Myklebust if (status != -EIO) 4421c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 442207d30434SBenny Halevy if (!status) 4423fcd8843cSTrond Myklebust status = decode_invalid_stateid(xdr, &res->stateid); 44241da177e4SLinus Torvalds return status; 44251da177e4SLinus Torvalds } 44261da177e4SLinus Torvalds 4427db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4428db942bbdSBenny Halevy { 4429cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 44301da177e4SLinus Torvalds } 44311da177e4SLinus Torvalds 44322f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 44332f2c63bcSTrond Myklebust { 44342f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 44352f2c63bcSTrond Myklebust } 44362f2c63bcSTrond Myklebust 44370b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 44381da177e4SLinus Torvalds { 44391da177e4SLinus Torvalds int status; 44401da177e4SLinus Torvalds 44411da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4442db942bbdSBenny Halevy if (!status) 44432f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 44441da177e4SLinus Torvalds return status; 44451da177e4SLinus Torvalds } 44461da177e4SLinus Torvalds 44471da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 44481da177e4SLinus Torvalds { 44498687b63aSAl Viro __be32 *p; 44501da177e4SLinus Torvalds uint32_t bmlen; 44511da177e4SLinus Torvalds int status; 44521da177e4SLinus Torvalds 44531da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 44541da177e4SLinus Torvalds if (status) 44551da177e4SLinus Torvalds return status; 44561da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 44571da177e4SLinus Torvalds return status; 4458c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4459c0eae66eSBenny Halevy if (unlikely(!p)) 4460c0eae66eSBenny Halevy goto out_overflow; 4461cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4462c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4463c0eae66eSBenny Halevy if (likely(p)) 44641da177e4SLinus Torvalds return 0; 4465c0eae66eSBenny Halevy out_overflow: 4466c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4467c0eae66eSBenny Halevy return -EIO; 44681da177e4SLinus Torvalds } 44691da177e4SLinus Torvalds 44701da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 44711da177e4SLinus Torvalds { 4472256e48bbSTrond Myklebust unsigned int savep; 4473dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44741da177e4SLinus Torvalds int status; 44751da177e4SLinus Torvalds 44761da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44771da177e4SLinus Torvalds goto xdr_error; 44781da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44791da177e4SLinus Torvalds goto xdr_error; 44801da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44811da177e4SLinus Torvalds goto xdr_error; 44821da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 44831da177e4SLinus Torvalds goto xdr_error; 4484264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4485264e6351SChuck Lever &res->fh_expire_type)) != 0) 4486264e6351SChuck Lever goto xdr_error; 44871da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 44881da177e4SLinus Torvalds goto xdr_error; 44891da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 44901da177e4SLinus Torvalds goto xdr_error; 44911da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 44921da177e4SLinus Torvalds goto xdr_error; 44938c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 44948c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 44958c61282fSKinglong Mee goto xdr_error; 44961da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44971da177e4SLinus Torvalds xdr_error: 44983110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44991da177e4SLinus Torvalds return status; 45001da177e4SLinus Torvalds } 45011da177e4SLinus Torvalds 45021da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 45031da177e4SLinus Torvalds { 4504256e48bbSTrond Myklebust unsigned int savep; 4505dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 45061da177e4SLinus Torvalds int status; 45071da177e4SLinus Torvalds 45081da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45091da177e4SLinus Torvalds goto xdr_error; 45101da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45111da177e4SLinus Torvalds goto xdr_error; 45121da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45131da177e4SLinus Torvalds goto xdr_error; 45141da177e4SLinus Torvalds 45151da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 45161da177e4SLinus Torvalds goto xdr_error; 45171da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 45181da177e4SLinus Torvalds goto xdr_error; 45191da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 45201da177e4SLinus Torvalds goto xdr_error; 45211ca843a2SAndreas Gruenbacher 45221ca843a2SAndreas Gruenbacher status = -EIO; 45231ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 45241ca843a2SAndreas Gruenbacher goto xdr_error; 45251ca843a2SAndreas Gruenbacher 45261da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 45271da177e4SLinus Torvalds goto xdr_error; 45281da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 45291da177e4SLinus Torvalds goto xdr_error; 45301da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 45311da177e4SLinus Torvalds goto xdr_error; 45321da177e4SLinus Torvalds 45331da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45341da177e4SLinus Torvalds xdr_error: 45353110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45361da177e4SLinus Torvalds return status; 45371da177e4SLinus Torvalds } 45381da177e4SLinus Torvalds 45391da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 45401da177e4SLinus Torvalds { 4541256e48bbSTrond Myklebust unsigned int savep; 4542dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 45431da177e4SLinus Torvalds int status; 45441da177e4SLinus Torvalds 45451da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45461da177e4SLinus Torvalds goto xdr_error; 45471da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45481da177e4SLinus Torvalds goto xdr_error; 45491da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45501da177e4SLinus Torvalds goto xdr_error; 45511da177e4SLinus Torvalds 45521da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 45531da177e4SLinus Torvalds goto xdr_error; 45541da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 45551da177e4SLinus Torvalds goto xdr_error; 45561da177e4SLinus Torvalds 45571da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45581da177e4SLinus Torvalds xdr_error: 45593110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45601da177e4SLinus Torvalds return status; 45611da177e4SLinus Torvalds } 45621da177e4SLinus Torvalds 456388034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 456488034c3dSAndy Adamson uint32_t *bitmap, 456588034c3dSAndy Adamson uint64_t *res, 456688034c3dSAndy Adamson uint32_t hint_bit) 456788034c3dSAndy Adamson { 456888034c3dSAndy Adamson __be32 *p; 456988034c3dSAndy Adamson 457088034c3dSAndy Adamson *res = 0; 457188034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 457288034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 457388034c3dSAndy Adamson if (unlikely(!p)) 457488034c3dSAndy Adamson goto out_overflow; 457588034c3dSAndy Adamson xdr_decode_hyper(p, res); 457688034c3dSAndy Adamson } 457788034c3dSAndy Adamson return 0; 457888034c3dSAndy Adamson out_overflow: 457988034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 458088034c3dSAndy Adamson return -EIO; 458188034c3dSAndy Adamson } 458288034c3dSAndy Adamson 458388034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 458488034c3dSAndy Adamson struct nfs4_threshold *res) 458588034c3dSAndy Adamson { 4586256e48bbSTrond Myklebust __be32 *p; 4587256e48bbSTrond Myklebust unsigned int savep; 458888034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 458988034c3dSAndy Adamson int status; 459088034c3dSAndy Adamson 459188034c3dSAndy Adamson /* layout type */ 459288034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 459388034c3dSAndy Adamson if (unlikely(!p)) { 459488034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 459588034c3dSAndy Adamson return -EIO; 459688034c3dSAndy Adamson } 459788034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 459888034c3dSAndy Adamson 459988034c3dSAndy Adamson /* thi_hintset bitmap */ 460088034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 460188034c3dSAndy Adamson if (status < 0) 460288034c3dSAndy Adamson goto xdr_error; 460388034c3dSAndy Adamson 460488034c3dSAndy Adamson /* thi_hintlist length */ 460588034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 460688034c3dSAndy Adamson if (status < 0) 460788034c3dSAndy Adamson goto xdr_error; 460888034c3dSAndy Adamson /* thi_hintlist */ 460988034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 461088034c3dSAndy Adamson if (status < 0) 461188034c3dSAndy Adamson goto xdr_error; 461288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 461388034c3dSAndy Adamson if (status < 0) 461488034c3dSAndy Adamson goto xdr_error; 461588034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 461688034c3dSAndy Adamson THRESHOLD_RD_IO); 461788034c3dSAndy Adamson if (status < 0) 461888034c3dSAndy Adamson goto xdr_error; 461988034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 462088034c3dSAndy Adamson THRESHOLD_WR_IO); 462188034c3dSAndy Adamson if (status < 0) 462288034c3dSAndy Adamson goto xdr_error; 462388034c3dSAndy Adamson 462488034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 462588034c3dSAndy Adamson res->bm = bitmap[0]; 462688034c3dSAndy Adamson 462788034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 462888034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 462988034c3dSAndy Adamson res->wr_io_sz); 463088034c3dSAndy Adamson xdr_error: 463188034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 463288034c3dSAndy Adamson return status; 463388034c3dSAndy Adamson } 463488034c3dSAndy Adamson 463588034c3dSAndy Adamson /* 463688034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 463788034c3dSAndy Adamson */ 463888034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 463988034c3dSAndy Adamson uint32_t *bitmap, 464088034c3dSAndy Adamson struct nfs4_threshold *res) 464188034c3dSAndy Adamson { 464288034c3dSAndy Adamson __be32 *p; 464388034c3dSAndy Adamson int status = 0; 464488034c3dSAndy Adamson uint32_t num; 464588034c3dSAndy Adamson 464688034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 464788034c3dSAndy Adamson return -EIO; 4648029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 46491549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 46501549210fSTrond Myklebust if (unlikely(res == NULL)) 46511549210fSTrond Myklebust return -EREMOTEIO; 465288034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 465388034c3dSAndy Adamson if (unlikely(!p)) 465488034c3dSAndy Adamson goto out_overflow; 465588034c3dSAndy Adamson num = be32_to_cpup(p); 465688034c3dSAndy Adamson if (num == 0) 465788034c3dSAndy Adamson return 0; 465888034c3dSAndy Adamson if (num > 1) 465988034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 466088034c3dSAndy Adamson "drivers per filesystem not supported\n", 466188034c3dSAndy Adamson __func__); 466288034c3dSAndy Adamson 466388034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4664029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 466588034c3dSAndy Adamson } 466688034c3dSAndy Adamson return status; 466788034c3dSAndy Adamson out_overflow: 466888034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 466988034c3dSAndy Adamson return -EIO; 467088034c3dSAndy Adamson } 467188034c3dSAndy Adamson 4672ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4673ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4674aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 46756926afd1STrond Myklebust const struct nfs_server *server) 46761da177e4SLinus Torvalds { 4677bca79478STrond Myklebust int status; 4678bca79478STrond Myklebust umode_t fmode = 0; 4679ae42c70aSBryan Schumaker uint32_t type; 4680ee7b75fcSTrond Myklebust int32_t err; 46811da177e4SLinus Torvalds 4682f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4683f26c7a78STrond Myklebust if (status < 0) 46841da177e4SLinus Torvalds goto xdr_error; 4685409924e4STrond Myklebust fattr->mode = 0; 4686409924e4STrond Myklebust if (status != 0) { 4687409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4688409924e4STrond Myklebust fattr->valid |= status; 4689409924e4STrond Myklebust } 46901da177e4SLinus Torvalds 4691f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4692f26c7a78STrond Myklebust if (status < 0) 46931da177e4SLinus Torvalds goto xdr_error; 4694409924e4STrond Myklebust fattr->valid |= status; 4695f26c7a78STrond Myklebust 4696f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4697f26c7a78STrond Myklebust if (status < 0) 46981da177e4SLinus Torvalds goto xdr_error; 4699409924e4STrond Myklebust fattr->valid |= status; 4700f26c7a78STrond Myklebust 4701f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4702f26c7a78STrond Myklebust if (status < 0) 47031da177e4SLinus Torvalds goto xdr_error; 4704409924e4STrond Myklebust fattr->valid |= status; 4705f26c7a78STrond Myklebust 4706ee7b75fcSTrond Myklebust err = 0; 4707ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4708ae42c70aSBryan Schumaker if (status < 0) 4709ae42c70aSBryan Schumaker goto xdr_error; 4710ae42c70aSBryan Schumaker 4711ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4712ae42c70aSBryan Schumaker if (status < 0) 4713ae42c70aSBryan Schumaker goto xdr_error; 4714ae42c70aSBryan Schumaker 4715f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4716f26c7a78STrond Myklebust if (status < 0) 47171da177e4SLinus Torvalds goto xdr_error; 4718409924e4STrond Myklebust fattr->valid |= status; 4719f26c7a78STrond Myklebust 47208b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4721f26c7a78STrond Myklebust if (status < 0) 4722683b57b4STrond Myklebust goto xdr_error; 4723409924e4STrond Myklebust fattr->valid |= status; 4724f26c7a78STrond Myklebust 47251ca843a2SAndreas Gruenbacher status = -EIO; 47261ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 47271ca843a2SAndreas Gruenbacher goto xdr_error; 47281ca843a2SAndreas Gruenbacher 4729f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4730f26c7a78STrond Myklebust if (status < 0) 47311da177e4SLinus Torvalds goto xdr_error; 4732409924e4STrond Myklebust if (status != 0) { 47331da177e4SLinus Torvalds fattr->mode |= fmode; 4734409924e4STrond Myklebust fattr->valid |= status; 4735409924e4STrond Myklebust } 4736f26c7a78STrond Myklebust 4737f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4738f26c7a78STrond Myklebust if (status < 0) 47391da177e4SLinus Torvalds goto xdr_error; 4740409924e4STrond Myklebust fattr->valid |= status; 4741f26c7a78STrond Myklebust 47426926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4743f26c7a78STrond Myklebust if (status < 0) 47441da177e4SLinus Torvalds goto xdr_error; 4745409924e4STrond Myklebust fattr->valid |= status; 4746f26c7a78STrond Myklebust 47476926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4748f26c7a78STrond Myklebust if (status < 0) 47491da177e4SLinus Torvalds goto xdr_error; 4750409924e4STrond Myklebust fattr->valid |= status; 4751f26c7a78STrond Myklebust 4752f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4753f26c7a78STrond Myklebust if (status < 0) 47541da177e4SLinus Torvalds goto xdr_error; 4755409924e4STrond Myklebust fattr->valid |= status; 4756f26c7a78STrond Myklebust 4757f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4758f26c7a78STrond Myklebust if (status < 0) 47591da177e4SLinus Torvalds goto xdr_error; 4760409924e4STrond Myklebust fattr->valid |= status; 4761f26c7a78STrond Myklebust 4762f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4763f26c7a78STrond Myklebust if (status < 0) 47641da177e4SLinus Torvalds goto xdr_error; 4765409924e4STrond Myklebust fattr->valid |= status; 4766f26c7a78STrond Myklebust 4767f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4768f26c7a78STrond Myklebust if (status < 0) 47691da177e4SLinus Torvalds goto xdr_error; 4770409924e4STrond Myklebust fattr->valid |= status; 4771f26c7a78STrond Myklebust 4772f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4773f26c7a78STrond Myklebust if (status < 0) 47741da177e4SLinus Torvalds goto xdr_error; 4775409924e4STrond Myklebust fattr->valid |= status; 4776f26c7a78STrond Myklebust 477728331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4778f26c7a78STrond Myklebust if (status < 0) 477999baf625SManoj Naik goto xdr_error; 4780409924e4STrond Myklebust fattr->valid |= status; 4781f26c7a78STrond Myklebust 47821ca843a2SAndreas Gruenbacher status = -EIO; 47831ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 47841ca843a2SAndreas Gruenbacher goto xdr_error; 47851ca843a2SAndreas Gruenbacher 478688034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 478788034c3dSAndy Adamson if (status < 0) 478888034c3dSAndy Adamson goto xdr_error; 478988034c3dSAndy Adamson 4790aa9c2669SDavid Quigley if (label) { 4791aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4792aa9c2669SDavid Quigley if (status < 0) 4793aa9c2669SDavid Quigley goto xdr_error; 4794aa9c2669SDavid Quigley fattr->valid |= status; 4795aa9c2669SDavid Quigley } 4796aa9c2669SDavid Quigley 4797ae42c70aSBryan Schumaker xdr_error: 4798ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4799ae42c70aSBryan Schumaker return status; 4800ae42c70aSBryan Schumaker } 4801ae42c70aSBryan Schumaker 4802ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 48038b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4804aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4805ae42c70aSBryan Schumaker { 4806256e48bbSTrond Myklebust unsigned int savep; 4807ae42c70aSBryan Schumaker uint32_t attrlen, 4808dae100c2SFred Isaman bitmap[3] = {0}; 4809ae42c70aSBryan Schumaker int status; 4810ae42c70aSBryan Schumaker 4811ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4812ae42c70aSBryan Schumaker if (status < 0) 4813ae42c70aSBryan Schumaker goto xdr_error; 4814ae42c70aSBryan Schumaker 4815ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4816ae42c70aSBryan Schumaker if (status < 0) 4817ae42c70aSBryan Schumaker goto xdr_error; 4818ae42c70aSBryan Schumaker 4819ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4820ae42c70aSBryan Schumaker if (status < 0) 4821ae42c70aSBryan Schumaker goto xdr_error; 4822ae42c70aSBryan Schumaker 4823aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4824aa9c2669SDavid Quigley label, server); 4825ae42c70aSBryan Schumaker if (status < 0) 4826ae42c70aSBryan Schumaker goto xdr_error; 4827ae42c70aSBryan Schumaker 4828f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 48291da177e4SLinus Torvalds xdr_error: 48303110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 48311da177e4SLinus Torvalds return status; 48321da177e4SLinus Torvalds } 48331da177e4SLinus Torvalds 4834aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4835aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4836aa9c2669SDavid Quigley { 4837aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4838aa9c2669SDavid Quigley } 4839aa9c2669SDavid Quigley 4840ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 48416926afd1STrond Myklebust const struct nfs_server *server) 4842ae42c70aSBryan Schumaker { 4843aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4844ae42c70aSBryan Schumaker } 48451da177e4SLinus Torvalds 4846504913fbSAndy Adamson /* 48473132e49eSJeff Layton * Decode potentially multiple layout types. 4848504913fbSAndy Adamson */ 48493132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4850ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4851504913fbSAndy Adamson { 4852b8a8a0ddSTrond Myklebust __be32 *p; 4853ca440c38SJeff Layton uint32_t i; 4854504913fbSAndy Adamson 4855504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4856504913fbSAndy Adamson if (unlikely(!p)) 4857504913fbSAndy Adamson goto out_overflow; 4858ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4859504913fbSAndy Adamson 4860504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4861ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4862504913fbSAndy Adamson return 0; 4863504913fbSAndy Adamson 4864504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4865ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4866504913fbSAndy Adamson if (unlikely(!p)) 4867504913fbSAndy Adamson goto out_overflow; 4868ca440c38SJeff Layton 4869ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4870ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4871ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4872ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4873ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4874ca440c38SJeff Layton } 4875ca440c38SJeff Layton 4876ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4877ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4878504913fbSAndy Adamson return 0; 4879504913fbSAndy Adamson out_overflow: 4880504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4881504913fbSAndy Adamson return -EIO; 4882504913fbSAndy Adamson } 4883504913fbSAndy Adamson 4884504913fbSAndy Adamson /* 4885504913fbSAndy Adamson * The type of file system exported. 4886504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4887504913fbSAndy Adamson */ 4888504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4889ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4890504913fbSAndy Adamson { 4891504913fbSAndy Adamson int status = 0; 4892504913fbSAndy Adamson 4893504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4894504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4895504913fbSAndy Adamson return -EIO; 4896504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4897ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4898504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 48993132e49eSJeff Layton } 4900504913fbSAndy Adamson return status; 4901504913fbSAndy Adamson } 4902504913fbSAndy Adamson 4903dae100c2SFred Isaman /* 4904dae100c2SFred Isaman * The prefered block size for layout directed io 4905dae100c2SFred Isaman */ 4906dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4907dae100c2SFred Isaman uint32_t *res) 4908dae100c2SFred Isaman { 4909dae100c2SFred Isaman __be32 *p; 4910dae100c2SFred Isaman 4911dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4912dae100c2SFred Isaman *res = 0; 4913dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4914dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4915dae100c2SFred Isaman if (unlikely(!p)) { 4916dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4917dae100c2SFred Isaman return -EIO; 4918dae100c2SFred Isaman } 4919dae100c2SFred Isaman *res = be32_to_cpup(p); 4920dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4921dae100c2SFred Isaman } 4922dae100c2SFred Isaman return 0; 4923dae100c2SFred Isaman } 4924dae100c2SFred Isaman 49252a92ee92SPeng Tao /* 49262a92ee92SPeng Tao * The granularity of a CLONE operation. 49272a92ee92SPeng Tao */ 49282a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 49292a92ee92SPeng Tao uint32_t *res) 49302a92ee92SPeng Tao { 49312a92ee92SPeng Tao __be32 *p; 49322a92ee92SPeng Tao 49332a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 49342a92ee92SPeng Tao *res = 0; 49352a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 49362a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 49372a92ee92SPeng Tao if (unlikely(!p)) { 49382a92ee92SPeng Tao print_overflow_msg(__func__, xdr); 49392a92ee92SPeng Tao return -EIO; 49402a92ee92SPeng Tao } 49412a92ee92SPeng Tao *res = be32_to_cpup(p); 49422a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 49432a92ee92SPeng Tao } 49442a92ee92SPeng Tao return 0; 49452a92ee92SPeng Tao } 49462a92ee92SPeng Tao 49471da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 49481da177e4SLinus Torvalds { 4949256e48bbSTrond Myklebust unsigned int savep; 4950dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 49511da177e4SLinus Torvalds int status; 49521da177e4SLinus Torvalds 49531da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 49541da177e4SLinus Torvalds goto xdr_error; 49551da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 49561da177e4SLinus Torvalds goto xdr_error; 49571da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 49581da177e4SLinus Torvalds goto xdr_error; 49591da177e4SLinus Torvalds 49601da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 49611da177e4SLinus Torvalds 49621da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 49631da177e4SLinus Torvalds goto xdr_error; 49641da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 49651da177e4SLinus Torvalds goto xdr_error; 49661da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 49671da177e4SLinus Torvalds goto xdr_error; 49681da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 49691da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 49701da177e4SLinus Torvalds goto xdr_error; 49711da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 49721ca843a2SAndreas Gruenbacher 49731ca843a2SAndreas Gruenbacher status = -EIO; 49741ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 49751ca843a2SAndreas Gruenbacher goto xdr_error; 49761ca843a2SAndreas Gruenbacher 497755b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 497855b6e774SRicardo Labiaga if (status != 0) 497955b6e774SRicardo Labiaga goto xdr_error; 4980ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4981504913fbSAndy Adamson if (status != 0) 4982504913fbSAndy Adamson goto xdr_error; 49831ca843a2SAndreas Gruenbacher 49841ca843a2SAndreas Gruenbacher status = -EIO; 49851ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 49861ca843a2SAndreas Gruenbacher goto xdr_error; 49871ca843a2SAndreas Gruenbacher 4988dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4989dae100c2SFred Isaman if (status) 4990dae100c2SFred Isaman goto xdr_error; 49912a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 49922a92ee92SPeng Tao if (status) 49932a92ee92SPeng Tao goto xdr_error; 49941da177e4SLinus Torvalds 49951da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 49961da177e4SLinus Torvalds xdr_error: 49973110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 49981da177e4SLinus Torvalds return status; 49991da177e4SLinus Torvalds } 50001da177e4SLinus Torvalds 50011da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 50021da177e4SLinus Torvalds { 50038687b63aSAl Viro __be32 *p; 50041da177e4SLinus Torvalds uint32_t len; 50051da177e4SLinus Torvalds int status; 50061da177e4SLinus Torvalds 50079936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 50089936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 50099936781dSTrond Myklebust 50101da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 50111da177e4SLinus Torvalds if (status) 50121da177e4SLinus Torvalds return status; 50131da177e4SLinus Torvalds 5014c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5015c0eae66eSBenny Halevy if (unlikely(!p)) 5016c0eae66eSBenny Halevy goto out_overflow; 5017cccddf4fSBenny Halevy len = be32_to_cpup(p); 50181da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 50191da177e4SLinus Torvalds return -EIO; 50201da177e4SLinus Torvalds fh->size = len; 5021c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5022c0eae66eSBenny Halevy if (unlikely(!p)) 5023c0eae66eSBenny Halevy goto out_overflow; 502499398d06SBenny Halevy memcpy(fh->data, p, len); 50251da177e4SLinus Torvalds return 0; 5026c0eae66eSBenny Halevy out_overflow: 5027c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5028c0eae66eSBenny Halevy return -EIO; 50291da177e4SLinus Torvalds } 50301da177e4SLinus Torvalds 50311da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 50321da177e4SLinus Torvalds { 50331da177e4SLinus Torvalds int status; 50341da177e4SLinus Torvalds 50351da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 50361da177e4SLinus Torvalds if (status) 50371da177e4SLinus Torvalds return status; 50381da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 50391da177e4SLinus Torvalds } 50401da177e4SLinus Torvalds 50411da177e4SLinus Torvalds /* 50421da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 50431da177e4SLinus Torvalds */ 5044911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 50451da177e4SLinus Torvalds { 5046911d1aafSTrond Myklebust uint64_t offset, length, clientid; 50478687b63aSAl Viro __be32 *p; 5048911d1aafSTrond Myklebust uint32_t namelen, type; 50491da177e4SLinus Torvalds 5050babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 5051c0eae66eSBenny Halevy if (unlikely(!p)) 5052c0eae66eSBenny Halevy goto out_overflow; 5053babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 50543ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 5055babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 5056babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 5057911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 5058911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 5059911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 5060911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 5061911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 5062911d1aafSTrond Myklebust if (type & 1) 5063911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 5064911d1aafSTrond Myklebust fl->fl_pid = 0; 5065911d1aafSTrond Myklebust } 5066babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 5067babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 5068babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 5069c0eae66eSBenny Halevy if (likely(p)) 50701da177e4SLinus Torvalds return -NFS4ERR_DENIED; 5071c0eae66eSBenny Halevy out_overflow: 5072c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5073c0eae66eSBenny Halevy return -EIO; 50741da177e4SLinus Torvalds } 50751da177e4SLinus Torvalds 5076911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 50771da177e4SLinus Torvalds { 50781da177e4SLinus Torvalds int status; 50791da177e4SLinus Torvalds 50801da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 5081c1d51931STrond Myklebust if (status == -EIO) 5082c1d51931STrond Myklebust goto out; 50831da177e4SLinus Torvalds if (status == 0) { 508493b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 508507d30434SBenny Halevy if (unlikely(status)) 508607d30434SBenny Halevy goto out; 50871da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 5088c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 5089c1d51931STrond Myklebust if (res->open_seqid != NULL) 5090c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 5091c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 5092c1d51931STrond Myklebust out: 50931da177e4SLinus Torvalds return status; 50941da177e4SLinus Torvalds } 50951da177e4SLinus Torvalds 5096911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 50971da177e4SLinus Torvalds { 50981da177e4SLinus Torvalds int status; 50991da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 51001da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 5101911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 51021da177e4SLinus Torvalds return status; 51031da177e4SLinus Torvalds } 51041da177e4SLinus Torvalds 5105911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 51061da177e4SLinus Torvalds { 51071da177e4SLinus Torvalds int status; 51081da177e4SLinus Torvalds 51091da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 5110c1d51931STrond Myklebust if (status != -EIO) 5111c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 511207d30434SBenny Halevy if (status == 0) 511393b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 51141da177e4SLinus Torvalds return status; 51151da177e4SLinus Torvalds } 51161da177e4SLinus Torvalds 5117d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 5118d3c7b7ccSTrond Myklebust { 5119d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5120d3c7b7ccSTrond Myklebust } 5121d3c7b7ccSTrond Myklebust 51221da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 51231da177e4SLinus Torvalds { 51241da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 51251da177e4SLinus Torvalds } 51261da177e4SLinus Torvalds 51275b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr) 51285b5faaf6SJeff Layton { 51295b5faaf6SJeff Layton return decode_op_hdr(xdr, OP_LOOKUPP); 51305b5faaf6SJeff Layton } 51315b5faaf6SJeff Layton 51321da177e4SLinus Torvalds /* This is too sick! */ 51337d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 51347d160a6cSTrond Myklebust unsigned long *pagemod_limit) 51351da177e4SLinus Torvalds { 51368687b63aSAl Viro __be32 *p; 51371da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 51387d160a6cSTrond Myklebust u64 maxsize = 0; 51391da177e4SLinus Torvalds 5140c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5141c0eae66eSBenny Halevy if (unlikely(!p)) 5142c0eae66eSBenny Halevy goto out_overflow; 51436f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 51441da177e4SLinus Torvalds switch (limit_type) { 51457d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 51467d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 51471da177e4SLinus Torvalds break; 51487d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 51496f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5150cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 51517d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 51521da177e4SLinus Torvalds } 515309cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 51547d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 51551da177e4SLinus Torvalds return 0; 5156c0eae66eSBenny Halevy out_overflow: 5157c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5158c0eae66eSBenny Halevy return -EIO; 51591da177e4SLinus Torvalds } 51601da177e4SLinus Torvalds 51616ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 51626ae37339STrond Myklebust uint32_t delegation_type, 51636ae37339STrond Myklebust struct nfs_openres *res) 51641da177e4SLinus Torvalds { 51658687b63aSAl Viro __be32 *p; 516607d30434SBenny Halevy int status; 51671da177e4SLinus Torvalds 516893b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 516907d30434SBenny Halevy if (unlikely(status)) 517007d30434SBenny Halevy return status; 5171c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5172c0eae66eSBenny Halevy if (unlikely(!p)) 5173c0eae66eSBenny Halevy goto out_overflow; 5174cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 517505d564feSAndy Adamson 51761da177e4SLinus Torvalds switch (delegation_type) { 51771da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 51781da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 51791da177e4SLinus Torvalds break; 51801da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 51811da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 51827d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 51831da177e4SLinus Torvalds return -EIO; 51841da177e4SLinus Torvalds } 51851bbe60ffSTrond Myklebust return decode_ace(xdr, NULL); 5186c0eae66eSBenny Halevy out_overflow: 5187c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5188c0eae66eSBenny Halevy return -EIO; 51891da177e4SLinus Torvalds } 51901da177e4SLinus Torvalds 51916ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51926ae37339STrond Myklebust { 51936ae37339STrond Myklebust __be32 *p; 51946ae37339STrond Myklebust uint32_t why_no_delegation; 51956ae37339STrond Myklebust 51966ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51976ae37339STrond Myklebust if (unlikely(!p)) 51986ae37339STrond Myklebust goto out_overflow; 51996ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 52006ae37339STrond Myklebust switch (why_no_delegation) { 52016ae37339STrond Myklebust case WND4_CONTENTION: 52026ae37339STrond Myklebust case WND4_RESOURCE: 52036ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 52046ae37339STrond Myklebust /* Ignore for now */ 52056ae37339STrond Myklebust } 52066ae37339STrond Myklebust return 0; 52076ae37339STrond Myklebust out_overflow: 52086ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 52096ae37339STrond Myklebust return -EIO; 52106ae37339STrond Myklebust } 52116ae37339STrond Myklebust 52126ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 52136ae37339STrond Myklebust { 52146ae37339STrond Myklebust __be32 *p; 52156ae37339STrond Myklebust uint32_t delegation_type; 52166ae37339STrond Myklebust 52176ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 52186ae37339STrond Myklebust if (unlikely(!p)) 52196ae37339STrond Myklebust goto out_overflow; 52206ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 52216ae37339STrond Myklebust res->delegation_type = 0; 52226ae37339STrond Myklebust switch (delegation_type) { 52236ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 52246ae37339STrond Myklebust return 0; 52256ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 52266ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 52276ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 52286ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 52296ae37339STrond Myklebust return decode_no_delegation(xdr, res); 52306ae37339STrond Myklebust } 52316ae37339STrond Myklebust return -EIO; 52326ae37339STrond Myklebust out_overflow: 52336ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 52346ae37339STrond Myklebust return -EIO; 52356ae37339STrond Myklebust } 52366ae37339STrond Myklebust 52371da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 52381da177e4SLinus Torvalds { 52398687b63aSAl Viro __be32 *p; 5240aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 52411da177e4SLinus Torvalds int status; 52421da177e4SLinus Torvalds 5243c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5244c7848f69STrond Myklebust return status; 5245c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5246c7848f69STrond Myklebust if (status) 5247c7848f69STrond Myklebust return status; 524893b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 524907d30434SBenny Halevy if (unlikely(status)) 52501da177e4SLinus Torvalds return status; 52511da177e4SLinus Torvalds 52521da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 52531da177e4SLinus Torvalds 5254c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5255c0eae66eSBenny Halevy if (unlikely(!p)) 5256c0eae66eSBenny Halevy goto out_overflow; 52576f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5258cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 52591da177e4SLinus Torvalds if (bmlen > 10) 52601da177e4SLinus Torvalds goto xdr_error; 52611da177e4SLinus Torvalds 5262c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5263c0eae66eSBenny Halevy if (unlikely(!p)) 5264c0eae66eSBenny Halevy goto out_overflow; 5265aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5266aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 52676f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5268aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5269aa53ed54SJeff Layton res->attrset[i] = 0; 5270aa53ed54SJeff Layton 52711da177e4SLinus Torvalds return decode_delegation(xdr, res); 52721da177e4SLinus Torvalds xdr_error: 52733110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 52741da177e4SLinus Torvalds return -EIO; 5275c0eae66eSBenny Halevy out_overflow: 5276c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5277c0eae66eSBenny Halevy return -EIO; 52781da177e4SLinus Torvalds } 52791da177e4SLinus Torvalds 52801da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 52811da177e4SLinus Torvalds { 52821da177e4SLinus Torvalds int status; 52831da177e4SLinus Torvalds 52841da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5285c1d51931STrond Myklebust if (status != -EIO) 5286c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 528707d30434SBenny Halevy if (!status) 528893b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52891da177e4SLinus Torvalds return status; 52901da177e4SLinus Torvalds } 52911da177e4SLinus Torvalds 52921da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 52931da177e4SLinus Torvalds { 52941da177e4SLinus Torvalds int status; 52951da177e4SLinus Torvalds 52961da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5297c1d51931STrond Myklebust if (status != -EIO) 5298c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 529907d30434SBenny Halevy if (!status) 530093b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 53011da177e4SLinus Torvalds return status; 53021da177e4SLinus Torvalds } 53031da177e4SLinus Torvalds 53041da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 53051da177e4SLinus Torvalds { 53061da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 53071da177e4SLinus Torvalds } 53081da177e4SLinus Torvalds 53091da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 53101da177e4SLinus Torvalds { 53111da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 53121da177e4SLinus Torvalds } 53131da177e4SLinus Torvalds 53149137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 53159137bdf3SAnna Schumaker struct nfs_pgio_res *res) 53161da177e4SLinus Torvalds { 53178687b63aSAl Viro __be32 *p; 531864bd577eSTrond Myklebust uint32_t count, eof, recvd; 53191da177e4SLinus Torvalds int status; 53201da177e4SLinus Torvalds 53211da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 53221da177e4SLinus Torvalds if (status) 53231da177e4SLinus Torvalds return status; 5324c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5325c0eae66eSBenny Halevy if (unlikely(!p)) 5326c0eae66eSBenny Halevy goto out_overflow; 53276f723f77SBenny Halevy eof = be32_to_cpup(p++); 5328cccddf4fSBenny Halevy count = be32_to_cpup(p); 532964bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 53301da177e4SLinus Torvalds if (count > recvd) { 5331fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 53321da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 53331da177e4SLinus Torvalds count = recvd; 53341da177e4SLinus Torvalds eof = 0; 53351da177e4SLinus Torvalds } 53361da177e4SLinus Torvalds res->eof = eof; 53371da177e4SLinus Torvalds res->count = count; 53381da177e4SLinus Torvalds return 0; 5339c0eae66eSBenny Halevy out_overflow: 5340c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5341c0eae66eSBenny Halevy return -EIO; 53421da177e4SLinus Torvalds } 53431da177e4SLinus Torvalds 53441da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 53451da177e4SLinus Torvalds { 5346bcecff77SChuck Lever int status; 5347cd93710eSChuck Lever __be32 verf[2]; 53481da177e4SLinus Torvalds 53491da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5350db942bbdSBenny Halevy if (!status) 5351db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5352db942bbdSBenny Halevy if (unlikely(status)) 53531da177e4SLinus Torvalds return status; 5354cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 535544109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5356cd93710eSChuck Lever __func__, verf[0], verf[1]); 535764bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 53581da177e4SLinus Torvalds } 53591da177e4SLinus Torvalds 53601da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 53611da177e4SLinus Torvalds { 53621da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5363bcecff77SChuck Lever u32 len, recvd; 53648687b63aSAl Viro __be32 *p; 53651da177e4SLinus Torvalds int status; 53661da177e4SLinus Torvalds 53671da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 53681da177e4SLinus Torvalds if (status) 53691da177e4SLinus Torvalds return status; 53701da177e4SLinus Torvalds 53711da177e4SLinus Torvalds /* Convert length of symlink */ 5372c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5373c0eae66eSBenny Halevy if (unlikely(!p)) 5374c0eae66eSBenny Halevy goto out_overflow; 5375cccddf4fSBenny Halevy len = be32_to_cpup(p); 53761da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5377fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 53781da177e4SLinus Torvalds return -ENAMETOOLONG; 53791da177e4SLinus Torvalds } 538064bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 53811da177e4SLinus Torvalds if (recvd < len) { 5382fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 53831da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 53841da177e4SLinus Torvalds return -EIO; 53851da177e4SLinus Torvalds } 53861da177e4SLinus Torvalds /* 53871da177e4SLinus Torvalds * The XDR encode routine has set things up so that 53881da177e4SLinus Torvalds * the link text will be copied directly into the 53891da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 53901da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 53911da177e4SLinus Torvalds * null-termination). 53921da177e4SLinus Torvalds */ 5393b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 53941da177e4SLinus Torvalds return 0; 5395c0eae66eSBenny Halevy out_overflow: 5396c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5397c0eae66eSBenny Halevy return -EIO; 53981da177e4SLinus Torvalds } 53991da177e4SLinus Torvalds 54001da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 54011da177e4SLinus Torvalds { 54021da177e4SLinus Torvalds int status; 54031da177e4SLinus Torvalds 54041da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 54051da177e4SLinus Torvalds if (status) 54061da177e4SLinus Torvalds goto out; 54071da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 54081da177e4SLinus Torvalds out: 54091da177e4SLinus Torvalds return status; 54101da177e4SLinus Torvalds } 54111da177e4SLinus Torvalds 54121da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 54131da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 54141da177e4SLinus Torvalds { 54151da177e4SLinus Torvalds int status; 54161da177e4SLinus Torvalds 54171da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 54181da177e4SLinus Torvalds if (status) 54191da177e4SLinus Torvalds goto out; 54201da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 54211da177e4SLinus Torvalds goto out; 54221da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 54231da177e4SLinus Torvalds out: 54241da177e4SLinus Torvalds return status; 54251da177e4SLinus Torvalds } 54261da177e4SLinus Torvalds 54271da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 54281da177e4SLinus Torvalds { 54291da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 54301da177e4SLinus Torvalds } 54311da177e4SLinus Torvalds 543256ae19f3STrond Myklebust static int 543356ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 543456ae19f3STrond Myklebust { 543556ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 543656ae19f3STrond Myklebust } 543756ae19f3STrond Myklebust 5438029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5439bf118a34SAndy Adamson struct nfs_getaclres *res) 5440029d105eSJ. Bruce Fields { 5441256e48bbSTrond Myklebust unsigned int savep; 5442029d105eSJ. Bruce Fields uint32_t attrlen, 5443dae100c2SFred Isaman bitmap[3] = {0}; 5444029d105eSJ. Bruce Fields int status; 5445cff298c7STrond Myklebust unsigned int pg_offset; 5446029d105eSJ. Bruce Fields 5447bf118a34SAndy Adamson res->acl_len = 0; 5448029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5449029d105eSJ. Bruce Fields goto out; 54505a006899SSachin Prabhu 5451519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5452519d3959STrond Myklebust 5453cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5454cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 54555a006899SSachin Prabhu 5456029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5457029d105eSJ. Bruce Fields goto out; 5458029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5459029d105eSJ. Bruce Fields goto out; 5460029d105eSJ. Bruce Fields 5461029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5462029d105eSJ. Bruce Fields return -EIO; 5463029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5464029d105eSJ. Bruce Fields 5465bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5466bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5467bf118a34SAndy Adamson * variable length bitmaps.*/ 5468cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5469519d3959STrond Myklebust res->acl_len = attrlen; 54701f1ea6c2STrond Myklebust 54711f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 54721f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 54731f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 54741f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5475519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5476cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5477029d105eSJ. Bruce Fields } 54788c233cf9SJ. Bruce Fields } else 54798c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5480029d105eSJ. Bruce Fields 5481029d105eSJ. Bruce Fields out: 5482029d105eSJ. Bruce Fields return status; 5483029d105eSJ. Bruce Fields } 5484029d105eSJ. Bruce Fields 54851da177e4SLinus Torvalds static int 54861da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 54871da177e4SLinus Torvalds { 54881da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 54891da177e4SLinus Torvalds } 54901da177e4SLinus Torvalds 54919e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 54921da177e4SLinus Torvalds { 54931da177e4SLinus Torvalds int status; 54941da177e4SLinus Torvalds 54951da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 54961da177e4SLinus Torvalds if (status) 54971da177e4SLinus Torvalds return status; 549837c88763STrond Myklebust if (decode_bitmap4(xdr, NULL, 0) >= 0) 54991da177e4SLinus Torvalds return 0; 5500c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5501c0eae66eSBenny Halevy return -EIO; 55021da177e4SLinus Torvalds } 55031da177e4SLinus Torvalds 5504bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 55051da177e4SLinus Torvalds { 55068687b63aSAl Viro __be32 *p; 55071da177e4SLinus Torvalds uint32_t opnum; 55081da177e4SLinus Torvalds int32_t nfserr; 55091da177e4SLinus Torvalds 5510c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5511c0eae66eSBenny Halevy if (unlikely(!p)) 5512c0eae66eSBenny Halevy goto out_overflow; 55136f723f77SBenny Halevy opnum = be32_to_cpup(p++); 55141da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5515fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 55161da177e4SLinus Torvalds " %d\n", opnum); 55171da177e4SLinus Torvalds return -EIO; 55181da177e4SLinus Torvalds } 5519cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 55201da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5521c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5522c0eae66eSBenny Halevy if (unlikely(!p)) 5523c0eae66eSBenny Halevy goto out_overflow; 5524bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5525bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 55261da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 55271da177e4SLinus Torvalds uint32_t len; 55281da177e4SLinus Torvalds 55291da177e4SLinus Torvalds /* skip netid string */ 5530c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5531c0eae66eSBenny Halevy if (unlikely(!p)) 5532c0eae66eSBenny Halevy goto out_overflow; 5533cccddf4fSBenny Halevy len = be32_to_cpup(p); 5534c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5535c0eae66eSBenny Halevy if (unlikely(!p)) 5536c0eae66eSBenny Halevy goto out_overflow; 55371da177e4SLinus Torvalds 55381da177e4SLinus Torvalds /* skip uaddr string */ 5539c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5540c0eae66eSBenny Halevy if (unlikely(!p)) 5541c0eae66eSBenny Halevy goto out_overflow; 5542cccddf4fSBenny Halevy len = be32_to_cpup(p); 5543c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5544c0eae66eSBenny Halevy if (unlikely(!p)) 5545c0eae66eSBenny Halevy goto out_overflow; 55461da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 55471da177e4SLinus Torvalds } else 5548856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 55491da177e4SLinus Torvalds 55501da177e4SLinus Torvalds return 0; 5551c0eae66eSBenny Halevy out_overflow: 5552c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5553c0eae66eSBenny Halevy return -EIO; 55541da177e4SLinus Torvalds } 55551da177e4SLinus Torvalds 55561da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 55571da177e4SLinus Torvalds { 55581da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 55591da177e4SLinus Torvalds } 55601da177e4SLinus Torvalds 55619137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 55621da177e4SLinus Torvalds { 55638687b63aSAl Viro __be32 *p; 55641da177e4SLinus Torvalds int status; 55651da177e4SLinus Torvalds 55661da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 55671da177e4SLinus Torvalds if (status) 55681da177e4SLinus Torvalds return status; 55691da177e4SLinus Torvalds 55702f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5571c0eae66eSBenny Halevy if (unlikely(!p)) 5572c0eae66eSBenny Halevy goto out_overflow; 55736f723f77SBenny Halevy res->count = be32_to_cpup(p++); 55746f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 55752f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5576c0eae66eSBenny Halevy out_overflow: 5577c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5578c0eae66eSBenny Halevy return -EIO; 55791da177e4SLinus Torvalds } 55801da177e4SLinus Torvalds 55811da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 55821da177e4SLinus Torvalds { 55831da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 55841da177e4SLinus Torvalds } 55851da177e4SLinus Torvalds 5586fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5587fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 55885a5ea0d4SBryan Schumaker { 5589fb15b26fSChuck Lever u32 oid_len; 55905a5ea0d4SBryan Schumaker __be32 *p; 55915a5ea0d4SBryan Schumaker 55925a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55935a5ea0d4SBryan Schumaker if (unlikely(!p)) 55945a5ea0d4SBryan Schumaker goto out_overflow; 5595fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5596fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 55975a5ea0d4SBryan Schumaker goto out_err; 55985a5ea0d4SBryan Schumaker 5599fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 56005a5ea0d4SBryan Schumaker if (unlikely(!p)) 56015a5ea0d4SBryan Schumaker goto out_overflow; 5602fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5603fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 56045a5ea0d4SBryan Schumaker 56055a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 56065a5ea0d4SBryan Schumaker if (unlikely(!p)) 56075a5ea0d4SBryan Schumaker goto out_overflow; 5608fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5609fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 56105a5ea0d4SBryan Schumaker 56115a5ea0d4SBryan Schumaker return 0; 56125a5ea0d4SBryan Schumaker 56135a5ea0d4SBryan Schumaker out_overflow: 56145a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 56155a5ea0d4SBryan Schumaker return -EIO; 56165a5ea0d4SBryan Schumaker out_err: 56175a5ea0d4SBryan Schumaker return -EINVAL; 56185a5ea0d4SBryan Schumaker } 56195a5ea0d4SBryan Schumaker 562031e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 56215a5ea0d4SBryan Schumaker { 5622fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5623fb15b26fSChuck Lever unsigned int i, num_flavors; 56245a5ea0d4SBryan Schumaker int status; 56255a5ea0d4SBryan Schumaker __be32 *p; 56265a5ea0d4SBryan Schumaker 56275a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56285a5ea0d4SBryan Schumaker if (unlikely(!p)) 56295a5ea0d4SBryan Schumaker goto out_overflow; 56305a5ea0d4SBryan Schumaker 5631c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5632c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5633c3dfc280SBryan Schumaker 5634c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 56355a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5636c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 56375a5ea0d4SBryan Schumaker break; 56385a5ea0d4SBryan Schumaker 56395a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56405a5ea0d4SBryan Schumaker if (unlikely(!p)) 56415a5ea0d4SBryan Schumaker goto out_overflow; 56425a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 56435a5ea0d4SBryan Schumaker 56445a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5645613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5646613e901eSBryan Schumaker if (status) 5647613e901eSBryan Schumaker goto out; 56485a5ea0d4SBryan Schumaker } 5649c3dfc280SBryan Schumaker res->flavors->num_flavors++; 56505a5ea0d4SBryan Schumaker } 56515a5ea0d4SBryan Schumaker 565231e4dda4SBryan Schumaker status = 0; 5653613e901eSBryan Schumaker out: 5654613e901eSBryan Schumaker return status; 56555a5ea0d4SBryan Schumaker out_overflow: 56565a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 56575a5ea0d4SBryan Schumaker return -EIO; 56585a5ea0d4SBryan Schumaker } 56595a5ea0d4SBryan Schumaker 566031e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 566131e4dda4SBryan Schumaker { 566231e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 566331e4dda4SBryan Schumaker if (status) 566431e4dda4SBryan Schumaker return status; 566531e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 566631e4dda4SBryan Schumaker } 566731e4dda4SBryan Schumaker 566899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 566931e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 567031e4dda4SBryan Schumaker { 567131e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 567231e4dda4SBryan Schumaker if (status) 567331e4dda4SBryan Schumaker return status; 567431e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 567531e4dda4SBryan Schumaker } 567631e4dda4SBryan Schumaker 56772031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 56782031cd1aSWeston Andros Adamson { 56792031cd1aSWeston Andros Adamson __be32 *p; 56802031cd1aSWeston Andros Adamson uint32_t bitmap_words; 56812031cd1aSWeston Andros Adamson unsigned int i; 56822031cd1aSWeston Andros Adamson 56832031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56844edabfd7SPan Bian if (!p) 56854edabfd7SPan Bian return -EIO; 56862031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 56872031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 56882031cd1aSWeston Andros Adamson return -EIO; 56892031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 56902031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 56912031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 56922031cd1aSWeston Andros Adamson 56932031cd1aSWeston Andros Adamson return 0; 56942031cd1aSWeston Andros Adamson } 56952031cd1aSWeston Andros Adamson 569699fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 569799fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 569899fe60d0SBenny Halevy { 569999fe60d0SBenny Halevy __be32 *p; 570099fe60d0SBenny Halevy uint32_t dummy; 57012460ba57SBenny Halevy char *dummy_str; 570299fe60d0SBenny Halevy int status; 57037d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 570499fe60d0SBenny Halevy 570599fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 570699fe60d0SBenny Halevy if (status) 570799fe60d0SBenny Halevy return status; 570899fe60d0SBenny Halevy 5709c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5710c0eae66eSBenny Halevy if (unlikely(!p)) 5711c0eae66eSBenny Halevy goto out_overflow; 571232b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5713c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5714c0eae66eSBenny Halevy if (unlikely(!p)) 5715c0eae66eSBenny Halevy goto out_overflow; 571632b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 571732b01310STrond Myklebust res->flags = be32_to_cpup(p++); 571899fe60d0SBenny Halevy 57192031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 57202031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 57212031cd1aSWeston Andros Adamson case SP4_NONE: 57222031cd1aSWeston Andros Adamson break; 57232031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 57242031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 57252031cd1aSWeston Andros Adamson if (status) 57262031cd1aSWeston Andros Adamson return status; 57272031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 57282031cd1aSWeston Andros Adamson if (status) 57292031cd1aSWeston Andros Adamson return status; 57302031cd1aSWeston Andros Adamson break; 57312031cd1aSWeston Andros Adamson default: 57322031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 573399fe60d0SBenny Halevy return -EIO; 57342031cd1aSWeston Andros Adamson } 573599fe60d0SBenny Halevy 5736acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5737c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5738c0eae66eSBenny Halevy if (unlikely(!p)) 5739c0eae66eSBenny Halevy goto out_overflow; 5740acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 574199fe60d0SBenny Halevy 5742acdeb69dSChuck Lever /* server_owner4.so_major_id */ 57432460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57442460ba57SBenny Halevy if (unlikely(status)) 57452460ba57SBenny Halevy return status; 5746acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5747acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 574878fe0f41SWeston Andros Adamson 5749acdeb69dSChuck Lever /* server_scope4 */ 5750acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5751acdeb69dSChuck Lever if (unlikely(status)) 5752acdeb69dSChuck Lever return status; 575378fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 575478fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 575578fe0f41SWeston Andros Adamson 57567d2ed9acSWeston Andros Adamson /* Implementation Id */ 57577d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 57587d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57597d2ed9acSWeston Andros Adamson goto out_overflow; 57607d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 57617d2ed9acSWeston Andros Adamson 57627d2ed9acSWeston Andros Adamson if (impl_id_count) { 57637d2ed9acSWeston Andros Adamson /* nii_domain */ 57642460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57652460ba57SBenny Halevy if (unlikely(status)) 57662460ba57SBenny Halevy return status; 57677d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 576899fe60d0SBenny Halevy 57697d2ed9acSWeston Andros Adamson /* nii_name */ 57707d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57717d2ed9acSWeston Andros Adamson if (unlikely(status)) 57727d2ed9acSWeston Andros Adamson return status; 57737d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 57747d2ed9acSWeston Andros Adamson 57757d2ed9acSWeston Andros Adamson /* nii_date */ 57767d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 57777d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57787d2ed9acSWeston Andros Adamson goto out_overflow; 57797d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 57807d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 57817d2ed9acSWeston Andros Adamson 57827d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 57837d2ed9acSWeston Andros Adamson } 578499fe60d0SBenny Halevy return 0; 5785c0eae66eSBenny Halevy out_overflow: 5786c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5787c0eae66eSBenny Halevy return -EIO; 578899fe60d0SBenny Halevy } 5789fc931582SAndy Adamson 5790fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5791fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5792fc931582SAndy Adamson { 5793fc931582SAndy Adamson __be32 *p; 5794c9c30dd5SBenny Halevy u32 nr_attrs, val; 5795fc931582SAndy Adamson 5796c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5797c0eae66eSBenny Halevy if (unlikely(!p)) 5798c0eae66eSBenny Halevy goto out_overflow; 5799c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5800c9c30dd5SBenny Halevy if (val) 5801c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 58026f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 58036f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 58046f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 58056f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 58066f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5807cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5808fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5809a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5810a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5811fc931582SAndy Adamson return -EINVAL; 5812fc931582SAndy Adamson } 5813c0eae66eSBenny Halevy if (nr_attrs == 1) { 5814c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5815c0eae66eSBenny Halevy if (unlikely(!p)) 5816c0eae66eSBenny Halevy goto out_overflow; 5817c0eae66eSBenny Halevy } 5818fc931582SAndy Adamson return 0; 5819c0eae66eSBenny Halevy out_overflow: 5820c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5821c0eae66eSBenny Halevy return -EIO; 5822fc931582SAndy Adamson } 5823fc931582SAndy Adamson 5824e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5825e78291e4SBenny Halevy { 5826e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5827fc931582SAndy Adamson } 5828fc931582SAndy Adamson 58297c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 58307c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 58317c44f1aeSWeston Andros Adamson { 58327c44f1aeSWeston Andros Adamson __be32 *p; 58337c44f1aeSWeston Andros Adamson int status; 58347c44f1aeSWeston Andros Adamson 58357c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 58367c44f1aeSWeston Andros Adamson if (!status) 583771a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 58387c44f1aeSWeston Andros Adamson if (unlikely(status)) 58397c44f1aeSWeston Andros Adamson return status; 58407c44f1aeSWeston Andros Adamson 58417c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 58427c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 58437c44f1aeSWeston Andros Adamson if (unlikely(!p)) 58447c44f1aeSWeston Andros Adamson goto out_overflow; 58457c44f1aeSWeston Andros Adamson 58467c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 58477c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 58487c44f1aeSWeston Andros Adamson return -EIO; 58497c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 58507c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 58517c44f1aeSWeston Andros Adamson else 58527c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 58537c44f1aeSWeston Andros Adamson 58547c44f1aeSWeston Andros Adamson return 0; 58557c44f1aeSWeston Andros Adamson out_overflow: 58567c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 58577c44f1aeSWeston Andros Adamson return -EIO; 58587c44f1aeSWeston Andros Adamson } 58597c44f1aeSWeston Andros Adamson 5860fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5861fc931582SAndy Adamson struct nfs41_create_session_res *res) 5862fc931582SAndy Adamson { 5863fc931582SAndy Adamson __be32 *p; 5864fc931582SAndy Adamson int status; 5865fc931582SAndy Adamson 5866fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5867e78291e4SBenny Halevy if (!status) 586879969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5869e78291e4SBenny Halevy if (unlikely(status)) 5870fc931582SAndy Adamson return status; 5871fc931582SAndy Adamson 5872fc931582SAndy Adamson /* seqid, flags */ 5873c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5874c0eae66eSBenny Halevy if (unlikely(!p)) 5875c0eae66eSBenny Halevy goto out_overflow; 587679969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 587779969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5878fc931582SAndy Adamson 5879fc931582SAndy Adamson /* Channel attributes */ 588079969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5881fc931582SAndy Adamson if (!status) 588279969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5883fc931582SAndy Adamson return status; 5884c0eae66eSBenny Halevy out_overflow: 5885c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5886c0eae66eSBenny Halevy return -EIO; 5887fc931582SAndy Adamson } 58880f3e66c6SAndy Adamson 58890f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 58900f3e66c6SAndy Adamson { 58910f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 58920f3e66c6SAndy Adamson } 589318019753SRicardo Labiaga 589466245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 589566245539STrond Myklebust { 589666245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 589766245539STrond Myklebust } 589866245539STrond Myklebust 589918019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 590018019753SRicardo Labiaga { 590118019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 590218019753SRicardo Labiaga } 590399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 590499fe60d0SBenny Halevy 59059b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 59069b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 59079b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 59089b7b9fccSAndy Adamson { 59099b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5910e3725ec0STrond Myklebust struct nfs4_session *session; 5911fc01cea9SAndy Adamson struct nfs4_sessionid id; 5912fc01cea9SAndy Adamson u32 dummy; 5913fc01cea9SAndy Adamson int status; 5914fc01cea9SAndy Adamson __be32 *p; 5915fc01cea9SAndy Adamson 5916e3725ec0STrond Myklebust if (res->sr_slot == NULL) 59179b7b9fccSAndy Adamson return 0; 59183bd2384aSChuck Lever if (!res->sr_slot->table->session) 59193bd2384aSChuck Lever return 0; 59209b7b9fccSAndy Adamson 5921fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5922e78291e4SBenny Halevy if (!status) 5923e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5924e78291e4SBenny Halevy if (unlikely(status)) 5925fc01cea9SAndy Adamson goto out_err; 59269b7b9fccSAndy Adamson 5927fc01cea9SAndy Adamson /* 5928fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5929fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5930fc01cea9SAndy Adamson */ 5931fdcb4577STrond Myklebust status = -EREMOTEIO; 5932e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5933fc01cea9SAndy Adamson 5934e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5935fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5936fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5937fc01cea9SAndy Adamson goto out_err; 5938fc01cea9SAndy Adamson } 5939e78291e4SBenny Halevy 5940c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5941c0eae66eSBenny Halevy if (unlikely(!p)) 5942c0eae66eSBenny Halevy goto out_overflow; 5943e78291e4SBenny Halevy 5944fc01cea9SAndy Adamson /* seqid */ 59456f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5946dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5947fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5948fc01cea9SAndy Adamson goto out_err; 5949fc01cea9SAndy Adamson } 5950fc01cea9SAndy Adamson /* slot id */ 59516f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5952df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5953fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5954fc01cea9SAndy Adamson goto out_err; 5955fc01cea9SAndy Adamson } 5956da0507b7STrond Myklebust /* highest slot id */ 5957da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5958464ee9f9STrond Myklebust /* target highest slot id */ 5959464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 59600629e370SAlexandros Batsakis /* result flags */ 59610629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5962fc01cea9SAndy Adamson status = 0; 5963fc01cea9SAndy Adamson out_err: 5964fc01cea9SAndy Adamson res->sr_status = status; 5965fc01cea9SAndy Adamson return status; 5966c0eae66eSBenny Halevy out_overflow: 5967c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5968c0eae66eSBenny Halevy status = -EIO; 5969c0eae66eSBenny Halevy goto out_err; 5970fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 59719b7b9fccSAndy Adamson return 0; 5972fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 59739b7b9fccSAndy Adamson } 59749b7b9fccSAndy Adamson 5975b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 597693b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 597793b717fdSTrond Myklebust { 597893b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 597993b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 598093b717fdSTrond Myklebust } 598193b717fdSTrond Myklebust 5982b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 59834e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5984b1f69b75SAndy Adamson { 59854e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5986b1f69b75SAndy Adamson __be32 *p; 5987b1f69b75SAndy Adamson uint32_t len, type; 5988b1f69b75SAndy Adamson int status; 5989b1f69b75SAndy Adamson 5990b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5991b1f69b75SAndy Adamson if (status) { 5992b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5993b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5994b1f69b75SAndy Adamson if (unlikely(!p)) 5995b1f69b75SAndy Adamson goto out_overflow; 5996b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5997b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5998b1f69b75SAndy Adamson __func__, pdev->mincount); 5999b1f69b75SAndy Adamson } 6000b1f69b75SAndy Adamson return status; 6001b1f69b75SAndy Adamson } 6002b1f69b75SAndy Adamson 6003b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 6004b1f69b75SAndy Adamson if (unlikely(!p)) 6005b1f69b75SAndy Adamson goto out_overflow; 6006b1f69b75SAndy Adamson type = be32_to_cpup(p++); 6007b1f69b75SAndy Adamson if (type != pdev->layout_type) { 6008b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 6009b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 6010b1f69b75SAndy Adamson return -EINVAL; 6011b1f69b75SAndy Adamson } 6012b1f69b75SAndy Adamson /* 6013b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 6014b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 6015b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 6016b1f69b75SAndy Adamson */ 6017b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 601813fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 601913fe4ba1STrond Myklebust goto out_overflow; 6020b1f69b75SAndy Adamson 6021b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 6022b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 6023b1f69b75SAndy Adamson if (unlikely(!p)) 6024b1f69b75SAndy Adamson goto out_overflow; 6025b1f69b75SAndy Adamson len = be32_to_cpup(p); 6026b1f69b75SAndy Adamson if (len) { 6027ead00597SChuck Lever uint32_t i; 6028b1f69b75SAndy Adamson 6029b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 6030b1f69b75SAndy Adamson if (unlikely(!p)) 6031b1f69b75SAndy Adamson goto out_overflow; 603284c9dee3SChristoph Hellwig 60334e590803STrond Myklebust res->notification = be32_to_cpup(p++); 603484c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 603584c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 603684c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 6037b1f69b75SAndy Adamson __func__); 6038b1f69b75SAndy Adamson return -EIO; 6039b1f69b75SAndy Adamson } 6040b1f69b75SAndy Adamson } 6041b1f69b75SAndy Adamson } 6042b1f69b75SAndy Adamson return 0; 6043b1f69b75SAndy Adamson out_overflow: 6044b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6045b1f69b75SAndy Adamson return -EIO; 6046b1f69b75SAndy Adamson } 6047b1f69b75SAndy Adamson 6048b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 6049b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6050b1f69b75SAndy Adamson { 6051b1f69b75SAndy Adamson __be32 *p; 6052b1f69b75SAndy Adamson int status; 6053b1f69b75SAndy Adamson u32 layout_count; 605464bd577eSTrond Myklebust u32 recvd; 6055b1f69b75SAndy Adamson 6056b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 6057b1f69b75SAndy Adamson if (status) 6058808ba32aSFred Isaman goto out; 6059ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6060b1f69b75SAndy Adamson if (unlikely(!p)) 6061b1f69b75SAndy Adamson goto out_overflow; 6062ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 606393b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 6064ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6065ea9d23f5STrond Myklebust if (unlikely(!p)) 6066ea9d23f5STrond Myklebust goto out_overflow; 6067b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 6068b1f69b75SAndy Adamson if (!layout_count) { 6069b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 6070b1f69b75SAndy Adamson __func__); 6071808ba32aSFred Isaman status = -EINVAL; 6072808ba32aSFred Isaman goto out; 6073b1f69b75SAndy Adamson } 6074b1f69b75SAndy Adamson 607535124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 6076b1f69b75SAndy Adamson if (unlikely(!p)) 6077b1f69b75SAndy Adamson goto out_overflow; 6078b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 6079b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 6080b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 6081b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 608235124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 6083b1f69b75SAndy Adamson 6084b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 6085b1f69b75SAndy Adamson __func__, 6086b1f69b75SAndy Adamson (unsigned long)res->range.offset, 6087b1f69b75SAndy Adamson (unsigned long)res->range.length, 6088b1f69b75SAndy Adamson res->range.iomode, 6089b1f69b75SAndy Adamson res->type, 609035124a09SWeston Andros Adamson res->layoutp->len); 6091b1f69b75SAndy Adamson 609264bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 609335124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 609435124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 609535124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 609635124a09SWeston Andros Adamson res->layoutp->len, recvd); 6097808ba32aSFred Isaman status = -EINVAL; 6098808ba32aSFred Isaman goto out; 609935124a09SWeston Andros Adamson } 610035124a09SWeston Andros Adamson 6101b1f69b75SAndy Adamson if (layout_count > 1) { 6102b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 6103b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 6104b1f69b75SAndy Adamson * the client may see a response that is less than the 6105b1f69b75SAndy Adamson * minimum it requested. 6106b1f69b75SAndy Adamson */ 6107b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 6108b1f69b75SAndy Adamson __func__, layout_count); 6109b1f69b75SAndy Adamson } 6110b1f69b75SAndy Adamson 6111808ba32aSFred Isaman out: 6112808ba32aSFred Isaman res->status = status; 6113808ba32aSFred Isaman return status; 6114b1f69b75SAndy Adamson out_overflow: 6115b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6116808ba32aSFred Isaman status = -EIO; 6117808ba32aSFred Isaman goto out; 6118b1f69b75SAndy Adamson } 6119863a3c6cSAndy Adamson 6120cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 6121cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6122cbe82603SBenny Halevy { 6123cbe82603SBenny Halevy __be32 *p; 6124cbe82603SBenny Halevy int status; 6125cbe82603SBenny Halevy 6126cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 6127cbe82603SBenny Halevy if (status) 6128cbe82603SBenny Halevy return status; 6129cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 6130cbe82603SBenny Halevy if (unlikely(!p)) 6131cbe82603SBenny Halevy goto out_overflow; 6132cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 6133cbe82603SBenny Halevy if (res->lrs_present) 613493b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 6135fcd8843cSTrond Myklebust else 6136fcd8843cSTrond Myklebust nfs4_stateid_copy(&res->stateid, &invalid_stateid); 6137cbe82603SBenny Halevy return status; 6138cbe82603SBenny Halevy out_overflow: 6139cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 6140cbe82603SBenny Halevy return -EIO; 6141cbe82603SBenny Halevy } 6142cbe82603SBenny Halevy 6143863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 6144863a3c6cSAndy Adamson struct rpc_rqst *req, 6145863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6146863a3c6cSAndy Adamson { 6147863a3c6cSAndy Adamson __be32 *p; 6148863a3c6cSAndy Adamson __u32 sizechanged; 6149863a3c6cSAndy Adamson int status; 6150863a3c6cSAndy Adamson 6151863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 6152db29c089SAndy Adamson res->status = status; 6153863a3c6cSAndy Adamson if (status) 6154863a3c6cSAndy Adamson return status; 6155863a3c6cSAndy Adamson 6156863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 6157863a3c6cSAndy Adamson if (unlikely(!p)) 6158863a3c6cSAndy Adamson goto out_overflow; 6159863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 6160863a3c6cSAndy Adamson 6161863a3c6cSAndy Adamson if (sizechanged) { 6162863a3c6cSAndy Adamson /* throw away new size */ 6163863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 6164863a3c6cSAndy Adamson if (unlikely(!p)) 6165863a3c6cSAndy Adamson goto out_overflow; 6166863a3c6cSAndy Adamson } 6167863a3c6cSAndy Adamson return 0; 6168863a3c6cSAndy Adamson out_overflow: 6169863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 6170863a3c6cSAndy Adamson return -EIO; 6171863a3c6cSAndy Adamson } 61727d974794SBryan Schumaker 61737d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 61747d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 61757d974794SBryan Schumaker { 61767d974794SBryan Schumaker __be32 *p; 61777d974794SBryan Schumaker int status; 61787d974794SBryan Schumaker int num_res; 61797d974794SBryan Schumaker 61807d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 61817d974794SBryan Schumaker if (status) 61827d974794SBryan Schumaker return status; 61837d974794SBryan Schumaker 61847d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61857d974794SBryan Schumaker if (unlikely(!p)) 61867d974794SBryan Schumaker goto out_overflow; 61877d974794SBryan Schumaker num_res = be32_to_cpup(p++); 61887d974794SBryan Schumaker if (num_res != 1) 61897d974794SBryan Schumaker goto out; 61907d974794SBryan Schumaker 61917d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61927d974794SBryan Schumaker if (unlikely(!p)) 61937d974794SBryan Schumaker goto out_overflow; 61947d974794SBryan Schumaker res->status = be32_to_cpup(p++); 61951cab0652SBryan Schumaker 61961cab0652SBryan Schumaker return status; 61977d974794SBryan Schumaker out_overflow: 61987d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 61997d974794SBryan Schumaker out: 62007d974794SBryan Schumaker return -EIO; 62017d974794SBryan Schumaker } 62029aeda35fSBryan Schumaker 62039aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 62049aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 62059aeda35fSBryan Schumaker { 62069f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 62079aeda35fSBryan Schumaker return res->status; 62089aeda35fSBryan Schumaker } 6209cf805165STrond Myklebust #else 6210cf805165STrond Myklebust static inline 6211cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6212cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6213cf805165STrond Myklebust { 6214cf805165STrond Myklebust return 0; 6215cf805165STrond Myklebust } 621656f487f8SFred Isaman 621756f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 621856f487f8SFred Isaman struct nfs4_layoutget_res *res) 621956f487f8SFred Isaman { 622056f487f8SFred Isaman return 0; 622156f487f8SFred Isaman } 622256f487f8SFred Isaman 6223b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6224b1f69b75SAndy Adamson 62251da177e4SLinus Torvalds /* 622649c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 622749c2559eSBenny Halevy */ 622849c2559eSBenny Halevy 622949c2559eSBenny Halevy /* 62301da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 62311da177e4SLinus Torvalds */ 6232bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6233bf269551SChuck Lever struct xdr_stream *xdr, 6234fc016483SChristoph Hellwig void *data) 62351da177e4SLinus Torvalds { 6236fc016483SChristoph Hellwig struct nfs_closeres *res = data; 62371da177e4SLinus Torvalds struct compound_hdr hdr; 62381da177e4SLinus Torvalds int status; 62391da177e4SLinus Torvalds 6240bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62411da177e4SLinus Torvalds if (status) 62421da177e4SLinus Torvalds goto out; 6243bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62449b7b9fccSAndy Adamson if (status) 62459b7b9fccSAndy Adamson goto out; 6246bf269551SChuck Lever status = decode_putfh(xdr); 62471da177e4SLinus Torvalds if (status) 62481da177e4SLinus Torvalds goto out; 6249b6808145STrond Myklebust if (res->lr_res) { 6250b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6251b6808145STrond Myklebust res->lr_ret = status; 6252b6808145STrond Myklebust if (status) 6253b6808145STrond Myklebust goto out; 6254b6808145STrond Myklebust } 6255bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 62561da177e4SLinus Torvalds out: 62571da177e4SLinus Torvalds return status; 62581da177e4SLinus Torvalds } 62591da177e4SLinus Torvalds 62601da177e4SLinus Torvalds /* 62611da177e4SLinus Torvalds * Decode ACCESS response 62621da177e4SLinus Torvalds */ 6263bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6264fc016483SChristoph Hellwig void *data) 62651da177e4SLinus Torvalds { 6266fc016483SChristoph Hellwig struct nfs4_accessres *res = data; 62671da177e4SLinus Torvalds struct compound_hdr hdr; 62681da177e4SLinus Torvalds int status; 62691da177e4SLinus Torvalds 6270bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62719b7b9fccSAndy Adamson if (status) 62729b7b9fccSAndy Adamson goto out; 6273bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62749b7b9fccSAndy Adamson if (status) 62751da177e4SLinus Torvalds goto out; 6276bf269551SChuck Lever status = decode_putfh(xdr); 627776b32999STrond Myklebust if (status != 0) 627876b32999STrond Myklebust goto out; 62796168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 628076b32999STrond Myklebust if (status != 0) 628176b32999STrond Myklebust goto out; 62828bcbe7d9STrond Myklebust if (res->fattr) 62836926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62841da177e4SLinus Torvalds out: 62851da177e4SLinus Torvalds return status; 62861da177e4SLinus Torvalds } 62871da177e4SLinus Torvalds 62881da177e4SLinus Torvalds /* 62891da177e4SLinus Torvalds * Decode LOOKUP response 62901da177e4SLinus Torvalds */ 6291bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6292fc016483SChristoph Hellwig void *data) 62931da177e4SLinus Torvalds { 6294fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 62951da177e4SLinus Torvalds struct compound_hdr hdr; 62961da177e4SLinus Torvalds int status; 62971da177e4SLinus Torvalds 6298bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62999b7b9fccSAndy Adamson if (status) 63009b7b9fccSAndy Adamson goto out; 6301bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63029b7b9fccSAndy Adamson if (status) 63031da177e4SLinus Torvalds goto out; 6304bf269551SChuck Lever status = decode_putfh(xdr); 6305bf269551SChuck Lever if (status) 63061da177e4SLinus Torvalds goto out; 6307bf269551SChuck Lever status = decode_lookup(xdr); 6308bf269551SChuck Lever if (status) 63091da177e4SLinus Torvalds goto out; 6310bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6311bf269551SChuck Lever if (status) 63121da177e4SLinus Torvalds goto out; 6313aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63141da177e4SLinus Torvalds out: 63151da177e4SLinus Torvalds return status; 63161da177e4SLinus Torvalds } 63171da177e4SLinus Torvalds 63181da177e4SLinus Torvalds /* 63195b5faaf6SJeff Layton * Decode LOOKUPP response 63205b5faaf6SJeff Layton */ 63215b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 63225b5faaf6SJeff Layton void *data) 63235b5faaf6SJeff Layton { 63245b5faaf6SJeff Layton struct nfs4_lookupp_res *res = data; 63255b5faaf6SJeff Layton struct compound_hdr hdr; 63265b5faaf6SJeff Layton int status; 63275b5faaf6SJeff Layton 63285b5faaf6SJeff Layton status = decode_compound_hdr(xdr, &hdr); 63295b5faaf6SJeff Layton if (status) 63305b5faaf6SJeff Layton goto out; 63315b5faaf6SJeff Layton status = decode_sequence(xdr, &res->seq_res, rqstp); 63325b5faaf6SJeff Layton if (status) 63335b5faaf6SJeff Layton goto out; 63345b5faaf6SJeff Layton status = decode_putfh(xdr); 63355b5faaf6SJeff Layton if (status) 63365b5faaf6SJeff Layton goto out; 63375b5faaf6SJeff Layton status = decode_lookupp(xdr); 63385b5faaf6SJeff Layton if (status) 63395b5faaf6SJeff Layton goto out; 63405b5faaf6SJeff Layton status = decode_getfh(xdr, res->fh); 63415b5faaf6SJeff Layton if (status) 63425b5faaf6SJeff Layton goto out; 63435b5faaf6SJeff Layton status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63445b5faaf6SJeff Layton out: 63455b5faaf6SJeff Layton return status; 63465b5faaf6SJeff Layton } 63475b5faaf6SJeff Layton 63485b5faaf6SJeff Layton /* 63491da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 63501da177e4SLinus Torvalds */ 6351bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6352bf269551SChuck Lever struct xdr_stream *xdr, 6353fc016483SChristoph Hellwig void *data) 63541da177e4SLinus Torvalds { 6355fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 63561da177e4SLinus Torvalds struct compound_hdr hdr; 63571da177e4SLinus Torvalds int status; 63581da177e4SLinus Torvalds 6359bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63609b7b9fccSAndy Adamson if (status) 63619b7b9fccSAndy Adamson goto out; 6362bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63639b7b9fccSAndy Adamson if (status) 63641da177e4SLinus Torvalds goto out; 6365bf269551SChuck Lever status = decode_putrootfh(xdr); 6366bf269551SChuck Lever if (status) 63671da177e4SLinus Torvalds goto out; 6368bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6369bf269551SChuck Lever if (status == 0) 6370aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6371aa9c2669SDavid Quigley res->label, res->server); 63721da177e4SLinus Torvalds out: 63731da177e4SLinus Torvalds return status; 63741da177e4SLinus Torvalds } 63751da177e4SLinus Torvalds 63761da177e4SLinus Torvalds /* 63771da177e4SLinus Torvalds * Decode REMOVE response 63781da177e4SLinus Torvalds */ 6379bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6380fc016483SChristoph Hellwig void *data) 63811da177e4SLinus Torvalds { 6382fc016483SChristoph Hellwig struct nfs_removeres *res = data; 63831da177e4SLinus Torvalds struct compound_hdr hdr; 63841da177e4SLinus Torvalds int status; 63851da177e4SLinus Torvalds 6386bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63879b7b9fccSAndy Adamson if (status) 63889b7b9fccSAndy Adamson goto out; 6389bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63909b7b9fccSAndy Adamson if (status) 63911da177e4SLinus Torvalds goto out; 6392bf269551SChuck Lever status = decode_putfh(xdr); 6393bf269551SChuck Lever if (status) 639416e42959STrond Myklebust goto out; 6395bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 63961da177e4SLinus Torvalds out: 63971da177e4SLinus Torvalds return status; 63981da177e4SLinus Torvalds } 63991da177e4SLinus Torvalds 64001da177e4SLinus Torvalds /* 64011da177e4SLinus Torvalds * Decode RENAME response 64021da177e4SLinus Torvalds */ 6403bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6404fc016483SChristoph Hellwig void *data) 64051da177e4SLinus Torvalds { 6406fc016483SChristoph Hellwig struct nfs_renameres *res = data; 64071da177e4SLinus Torvalds struct compound_hdr hdr; 64081da177e4SLinus Torvalds int status; 64091da177e4SLinus Torvalds 6410bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64119b7b9fccSAndy Adamson if (status) 64129b7b9fccSAndy Adamson goto out; 6413bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64149b7b9fccSAndy Adamson if (status) 64151da177e4SLinus Torvalds goto out; 6416bf269551SChuck Lever status = decode_putfh(xdr); 6417bf269551SChuck Lever if (status) 64181da177e4SLinus Torvalds goto out; 6419bf269551SChuck Lever status = decode_savefh(xdr); 6420bf269551SChuck Lever if (status) 64211da177e4SLinus Torvalds goto out; 6422bf269551SChuck Lever status = decode_putfh(xdr); 6423bf269551SChuck Lever if (status) 64241da177e4SLinus Torvalds goto out; 6425bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 64261da177e4SLinus Torvalds out: 64271da177e4SLinus Torvalds return status; 64281da177e4SLinus Torvalds } 64291da177e4SLinus Torvalds 64301da177e4SLinus Torvalds /* 64311da177e4SLinus Torvalds * Decode LINK response 64321da177e4SLinus Torvalds */ 6433bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6434fc016483SChristoph Hellwig void *data) 64351da177e4SLinus Torvalds { 6436fc016483SChristoph Hellwig struct nfs4_link_res *res = data; 64371da177e4SLinus Torvalds struct compound_hdr hdr; 64381da177e4SLinus Torvalds int status; 64391da177e4SLinus Torvalds 6440bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64419b7b9fccSAndy Adamson if (status) 64429b7b9fccSAndy Adamson goto out; 6443bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64449b7b9fccSAndy Adamson if (status) 64451da177e4SLinus Torvalds goto out; 6446bf269551SChuck Lever status = decode_putfh(xdr); 6447bf269551SChuck Lever if (status) 64481da177e4SLinus Torvalds goto out; 6449bf269551SChuck Lever status = decode_savefh(xdr); 6450bf269551SChuck Lever if (status) 64511da177e4SLinus Torvalds goto out; 6452bf269551SChuck Lever status = decode_putfh(xdr); 6453bf269551SChuck Lever if (status) 64541da177e4SLinus Torvalds goto out; 6455bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6456bf269551SChuck Lever if (status) 645791ba2eeeSTrond Myklebust goto out; 645891ba2eeeSTrond Myklebust /* 645991ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 646091ba2eeeSTrond Myklebust * filehandle. 646191ba2eeeSTrond Myklebust */ 6462bf269551SChuck Lever status = decode_restorefh(xdr); 6463bf269551SChuck Lever if (status) 646491ba2eeeSTrond Myklebust goto out; 6465aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64661da177e4SLinus Torvalds out: 64671da177e4SLinus Torvalds return status; 64681da177e4SLinus Torvalds } 64691da177e4SLinus Torvalds 64701da177e4SLinus Torvalds /* 64711da177e4SLinus Torvalds * Decode CREATE response 64721da177e4SLinus Torvalds */ 6473bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6474fc016483SChristoph Hellwig void *data) 64751da177e4SLinus Torvalds { 6476fc016483SChristoph Hellwig struct nfs4_create_res *res = data; 64771da177e4SLinus Torvalds struct compound_hdr hdr; 64781da177e4SLinus Torvalds int status; 64791da177e4SLinus Torvalds 6480bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64819b7b9fccSAndy Adamson if (status) 64829b7b9fccSAndy Adamson goto out; 6483bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64849b7b9fccSAndy Adamson if (status) 64851da177e4SLinus Torvalds goto out; 6486bf269551SChuck Lever status = decode_putfh(xdr); 6487bf269551SChuck Lever if (status) 64881da177e4SLinus Torvalds goto out; 6489bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6490bf269551SChuck Lever if (status) 64911da177e4SLinus Torvalds goto out; 6492bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6493bf269551SChuck Lever if (status) 64941da177e4SLinus Torvalds goto out; 6495aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64961da177e4SLinus Torvalds out: 64971da177e4SLinus Torvalds return status; 64981da177e4SLinus Torvalds } 64991da177e4SLinus Torvalds 65001da177e4SLinus Torvalds /* 65011da177e4SLinus Torvalds * Decode SYMLINK response 65021da177e4SLinus Torvalds */ 6503bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6504fc016483SChristoph Hellwig void *res) 65051da177e4SLinus Torvalds { 6506bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 65071da177e4SLinus Torvalds } 65081da177e4SLinus Torvalds 65091da177e4SLinus Torvalds /* 65101da177e4SLinus Torvalds * Decode GETATTR response 65111da177e4SLinus Torvalds */ 6512bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6513fc016483SChristoph Hellwig void *data) 65141da177e4SLinus Torvalds { 6515fc016483SChristoph Hellwig struct nfs4_getattr_res *res = data; 65161da177e4SLinus Torvalds struct compound_hdr hdr; 65171da177e4SLinus Torvalds int status; 65181da177e4SLinus Torvalds 6519bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65201da177e4SLinus Torvalds if (status) 65211da177e4SLinus Torvalds goto out; 6522bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65239b7b9fccSAndy Adamson if (status) 65249b7b9fccSAndy Adamson goto out; 6525bf269551SChuck Lever status = decode_putfh(xdr); 65261da177e4SLinus Torvalds if (status) 65271da177e4SLinus Torvalds goto out; 6528aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 65291da177e4SLinus Torvalds out: 65301da177e4SLinus Torvalds return status; 65311da177e4SLinus Torvalds } 65321da177e4SLinus Torvalds 653323ec6965SJ. Bruce Fields /* 653423ec6965SJ. Bruce Fields * Encode an SETACL request 653523ec6965SJ. Bruce Fields */ 65369f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 6537fcc85819SChristoph Hellwig const void *data) 653823ec6965SJ. Bruce Fields { 6539fcc85819SChristoph Hellwig const struct nfs_setaclargs *args = data; 654023ec6965SJ. Bruce Fields struct compound_hdr hdr = { 654166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 654223ec6965SJ. Bruce Fields }; 654323ec6965SJ. Bruce Fields 65449f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 65459f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 65469f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 65479f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6548d017931cSAndy Adamson encode_nops(&hdr); 654923ec6965SJ. Bruce Fields } 655005d564feSAndy Adamson 655123ec6965SJ. Bruce Fields /* 655223ec6965SJ. Bruce Fields * Decode SETACL response 655323ec6965SJ. Bruce Fields */ 655423ec6965SJ. Bruce Fields static int 6555bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6556fc016483SChristoph Hellwig void *data) 655723ec6965SJ. Bruce Fields { 6558fc016483SChristoph Hellwig struct nfs_setaclres *res = data; 655923ec6965SJ. Bruce Fields struct compound_hdr hdr; 656023ec6965SJ. Bruce Fields int status; 656123ec6965SJ. Bruce Fields 6562bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 656323ec6965SJ. Bruce Fields if (status) 656423ec6965SJ. Bruce Fields goto out; 6565bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65669b7b9fccSAndy Adamson if (status) 65679b7b9fccSAndy Adamson goto out; 6568bf269551SChuck Lever status = decode_putfh(xdr); 656923ec6965SJ. Bruce Fields if (status) 657023ec6965SJ. Bruce Fields goto out; 6571bf269551SChuck Lever status = decode_setattr(xdr); 657223ec6965SJ. Bruce Fields out: 657323ec6965SJ. Bruce Fields return status; 657423ec6965SJ. Bruce Fields } 65751da177e4SLinus Torvalds 65761da177e4SLinus Torvalds /* 6577029d105eSJ. Bruce Fields * Decode GETACL response 6578029d105eSJ. Bruce Fields */ 6579029d105eSJ. Bruce Fields static int 6580bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6581fc016483SChristoph Hellwig void *data) 6582029d105eSJ. Bruce Fields { 6583fc016483SChristoph Hellwig struct nfs_getaclres *res = data; 6584029d105eSJ. Bruce Fields struct compound_hdr hdr; 6585029d105eSJ. Bruce Fields int status; 6586029d105eSJ. Bruce Fields 6587331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6588331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6589331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6590331818f1STrond Myklebust } 6591bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6592029d105eSJ. Bruce Fields if (status) 6593029d105eSJ. Bruce Fields goto out; 6594bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65959b7b9fccSAndy Adamson if (status) 65969b7b9fccSAndy Adamson goto out; 6597bf269551SChuck Lever status = decode_putfh(xdr); 6598029d105eSJ. Bruce Fields if (status) 6599029d105eSJ. Bruce Fields goto out; 6600bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6601029d105eSJ. Bruce Fields 6602029d105eSJ. Bruce Fields out: 6603029d105eSJ. Bruce Fields return status; 6604029d105eSJ. Bruce Fields } 6605029d105eSJ. Bruce Fields 6606029d105eSJ. Bruce Fields /* 66071da177e4SLinus Torvalds * Decode CLOSE response 66081da177e4SLinus Torvalds */ 6609bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6610fc016483SChristoph Hellwig void *data) 66111da177e4SLinus Torvalds { 6612fc016483SChristoph Hellwig struct nfs_closeres *res = data; 66131da177e4SLinus Torvalds struct compound_hdr hdr; 66141da177e4SLinus Torvalds int status; 66151da177e4SLinus Torvalds 6616bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66171da177e4SLinus Torvalds if (status) 66181da177e4SLinus Torvalds goto out; 6619bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66209b7b9fccSAndy Adamson if (status) 66219b7b9fccSAndy Adamson goto out; 6622bf269551SChuck Lever status = decode_putfh(xdr); 66231da177e4SLinus Torvalds if (status) 66241da177e4SLinus Torvalds goto out; 6625cf805165STrond Myklebust if (res->lr_res) { 6626cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6627cf805165STrond Myklebust res->lr_ret = status; 6628cf805165STrond Myklebust if (status) 6629cf805165STrond Myklebust goto out; 6630cf805165STrond Myklebust } 6631d8d84983STrond Myklebust if (res->fattr != NULL) { 6632d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6633516a6af6STrond Myklebust if (status != 0) 6634516a6af6STrond Myklebust goto out; 6635d8d84983STrond Myklebust } 6636d8d84983STrond Myklebust status = decode_close(xdr, res); 66371da177e4SLinus Torvalds out: 66381da177e4SLinus Torvalds return status; 66391da177e4SLinus Torvalds } 66401da177e4SLinus Torvalds 66411da177e4SLinus Torvalds /* 66421da177e4SLinus Torvalds * Decode OPEN response 66431da177e4SLinus Torvalds */ 6644bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6645fc016483SChristoph Hellwig void *data) 66461da177e4SLinus Torvalds { 6647fc016483SChristoph Hellwig struct nfs_openres *res = data; 66481da177e4SLinus Torvalds struct compound_hdr hdr; 66491da177e4SLinus Torvalds int status; 66501da177e4SLinus Torvalds 6651bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66521da177e4SLinus Torvalds if (status) 66531da177e4SLinus Torvalds goto out; 6654bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66559b7b9fccSAndy Adamson if (status) 66569b7b9fccSAndy Adamson goto out; 6657bf269551SChuck Lever status = decode_putfh(xdr); 66581da177e4SLinus Torvalds if (status) 66591da177e4SLinus Torvalds goto out; 6660bf269551SChuck Lever status = decode_open(xdr, res); 66611da177e4SLinus Torvalds if (status) 66621da177e4SLinus Torvalds goto out; 666301913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 666401913b49SWeston Andros Adamson if (status) 66651da177e4SLinus Torvalds goto out; 6666ae2bb032SWeston Andros Adamson if (res->access_request) 66676168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6668aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 666956f487f8SFred Isaman if (res->lg_res) 667056f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res); 66711da177e4SLinus Torvalds out: 66721da177e4SLinus Torvalds return status; 66731da177e4SLinus Torvalds } 66741da177e4SLinus Torvalds 66751da177e4SLinus Torvalds /* 66761da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 66771da177e4SLinus Torvalds */ 6678bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6679bf269551SChuck Lever struct xdr_stream *xdr, 6680fc016483SChristoph Hellwig void *data) 66811da177e4SLinus Torvalds { 6682fc016483SChristoph Hellwig struct nfs_open_confirmres *res = data; 66831da177e4SLinus Torvalds struct compound_hdr hdr; 66841da177e4SLinus Torvalds int status; 66851da177e4SLinus Torvalds 6686bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66871da177e4SLinus Torvalds if (status) 66881da177e4SLinus Torvalds goto out; 6689bf269551SChuck Lever status = decode_putfh(xdr); 66901da177e4SLinus Torvalds if (status) 66911da177e4SLinus Torvalds goto out; 6692bf269551SChuck Lever status = decode_open_confirm(xdr, res); 66931da177e4SLinus Torvalds out: 66941da177e4SLinus Torvalds return status; 66951da177e4SLinus Torvalds } 66961da177e4SLinus Torvalds 66971da177e4SLinus Torvalds /* 66981da177e4SLinus Torvalds * Decode OPEN response 66991da177e4SLinus Torvalds */ 6700bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6701bf269551SChuck Lever struct xdr_stream *xdr, 6702fc016483SChristoph Hellwig void *data) 67031da177e4SLinus Torvalds { 6704fc016483SChristoph Hellwig struct nfs_openres *res = data; 67051da177e4SLinus Torvalds struct compound_hdr hdr; 67061da177e4SLinus Torvalds int status; 67071da177e4SLinus Torvalds 6708bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67091da177e4SLinus Torvalds if (status) 67101da177e4SLinus Torvalds goto out; 6711bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67129b7b9fccSAndy Adamson if (status) 67139b7b9fccSAndy Adamson goto out; 6714bf269551SChuck Lever status = decode_putfh(xdr); 67151da177e4SLinus Torvalds if (status) 67161da177e4SLinus Torvalds goto out; 6717bf269551SChuck Lever status = decode_open(xdr, res); 6718864472e9STrond Myklebust if (status) 6719864472e9STrond Myklebust goto out; 6720ae2bb032SWeston Andros Adamson if (res->access_request) 67216168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 67226926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 672356f487f8SFred Isaman if (res->lg_res) 672456f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res); 67251da177e4SLinus Torvalds out: 67261da177e4SLinus Torvalds return status; 67271da177e4SLinus Torvalds } 67281da177e4SLinus Torvalds 67291da177e4SLinus Torvalds /* 67301da177e4SLinus Torvalds * Decode SETATTR response 67311da177e4SLinus Torvalds */ 6732bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6733bf269551SChuck Lever struct xdr_stream *xdr, 6734fc016483SChristoph Hellwig void *data) 67351da177e4SLinus Torvalds { 6736fc016483SChristoph Hellwig struct nfs_setattrres *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_setattr(xdr); 67501da177e4SLinus Torvalds if (status) 67511da177e4SLinus Torvalds goto out; 6752aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 67531da177e4SLinus Torvalds out: 67541da177e4SLinus Torvalds return status; 67551da177e4SLinus Torvalds } 67561da177e4SLinus Torvalds 67571da177e4SLinus Torvalds /* 67581da177e4SLinus Torvalds * Decode LOCK response 67591da177e4SLinus Torvalds */ 6760bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6761fc016483SChristoph Hellwig void *data) 67621da177e4SLinus Torvalds { 6763fc016483SChristoph Hellwig struct nfs_lock_res *res = data; 67641da177e4SLinus Torvalds struct compound_hdr hdr; 67651da177e4SLinus Torvalds int status; 67661da177e4SLinus Torvalds 6767bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67681da177e4SLinus Torvalds if (status) 67691da177e4SLinus Torvalds goto out; 6770bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67719b7b9fccSAndy Adamson if (status) 67729b7b9fccSAndy Adamson goto out; 6773bf269551SChuck Lever status = decode_putfh(xdr); 67741da177e4SLinus Torvalds if (status) 67751da177e4SLinus Torvalds goto out; 6776bf269551SChuck Lever status = decode_lock(xdr, res); 67771da177e4SLinus Torvalds out: 67781da177e4SLinus Torvalds return status; 67791da177e4SLinus Torvalds } 67801da177e4SLinus Torvalds 67811da177e4SLinus Torvalds /* 67821da177e4SLinus Torvalds * Decode LOCKT response 67831da177e4SLinus Torvalds */ 6784bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6785fc016483SChristoph Hellwig void *data) 67861da177e4SLinus Torvalds { 6787fc016483SChristoph Hellwig struct nfs_lockt_res *res = data; 67881da177e4SLinus Torvalds struct compound_hdr hdr; 67891da177e4SLinus Torvalds int status; 67901da177e4SLinus Torvalds 6791bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67921da177e4SLinus Torvalds if (status) 67931da177e4SLinus Torvalds goto out; 6794bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67959b7b9fccSAndy Adamson if (status) 67969b7b9fccSAndy Adamson goto out; 6797bf269551SChuck Lever status = decode_putfh(xdr); 67981da177e4SLinus Torvalds if (status) 67991da177e4SLinus Torvalds goto out; 6800bf269551SChuck Lever status = decode_lockt(xdr, res); 68011da177e4SLinus Torvalds out: 68021da177e4SLinus Torvalds return status; 68031da177e4SLinus Torvalds } 68041da177e4SLinus Torvalds 68051da177e4SLinus Torvalds /* 68061da177e4SLinus Torvalds * Decode LOCKU response 68071da177e4SLinus Torvalds */ 6808bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6809fc016483SChristoph Hellwig void *data) 68101da177e4SLinus Torvalds { 6811fc016483SChristoph Hellwig struct nfs_locku_res *res = data; 68121da177e4SLinus Torvalds struct compound_hdr hdr; 68131da177e4SLinus Torvalds int status; 68141da177e4SLinus Torvalds 6815bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68161da177e4SLinus Torvalds if (status) 68171da177e4SLinus Torvalds goto out; 6818bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68199b7b9fccSAndy Adamson if (status) 68209b7b9fccSAndy Adamson goto out; 6821bf269551SChuck Lever status = decode_putfh(xdr); 68221da177e4SLinus Torvalds if (status) 68231da177e4SLinus Torvalds goto out; 6824bf269551SChuck Lever status = decode_locku(xdr, res); 68251da177e4SLinus Torvalds out: 68261da177e4SLinus Torvalds return status; 68271da177e4SLinus Torvalds } 68281da177e4SLinus Torvalds 6829bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6830bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6831d3c7b7ccSTrond Myklebust { 6832d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6833d3c7b7ccSTrond Myklebust int status; 6834d3c7b7ccSTrond Myklebust 6835bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6836d3c7b7ccSTrond Myklebust if (!status) 6837bf269551SChuck Lever status = decode_release_lockowner(xdr); 6838d3c7b7ccSTrond Myklebust return status; 6839d3c7b7ccSTrond Myklebust } 6840d3c7b7ccSTrond Myklebust 68411da177e4SLinus Torvalds /* 68421da177e4SLinus Torvalds * Decode READLINK response 68431da177e4SLinus Torvalds */ 6844bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6845bf269551SChuck Lever struct xdr_stream *xdr, 6846fc016483SChristoph Hellwig void *data) 68471da177e4SLinus Torvalds { 6848fc016483SChristoph Hellwig struct nfs4_readlink_res *res = data; 68491da177e4SLinus Torvalds struct compound_hdr hdr; 68501da177e4SLinus Torvalds int status; 68511da177e4SLinus Torvalds 6852bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68531da177e4SLinus Torvalds if (status) 68541da177e4SLinus Torvalds goto out; 6855bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68569b7b9fccSAndy Adamson if (status) 68579b7b9fccSAndy Adamson goto out; 6858bf269551SChuck Lever status = decode_putfh(xdr); 68591da177e4SLinus Torvalds if (status) 68601da177e4SLinus Torvalds goto out; 6861bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 68621da177e4SLinus Torvalds out: 68631da177e4SLinus Torvalds return status; 68641da177e4SLinus Torvalds } 68651da177e4SLinus Torvalds 68661da177e4SLinus Torvalds /* 68671da177e4SLinus Torvalds * Decode READDIR response 68681da177e4SLinus Torvalds */ 6869bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6870fc016483SChristoph Hellwig void *data) 68711da177e4SLinus Torvalds { 6872fc016483SChristoph Hellwig struct nfs4_readdir_res *res = data; 68731da177e4SLinus Torvalds struct compound_hdr hdr; 68741da177e4SLinus Torvalds int status; 68751da177e4SLinus Torvalds 6876bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68771da177e4SLinus Torvalds if (status) 68781da177e4SLinus Torvalds goto out; 6879bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68809b7b9fccSAndy Adamson if (status) 68819b7b9fccSAndy Adamson goto out; 6882bf269551SChuck Lever status = decode_putfh(xdr); 68831da177e4SLinus Torvalds if (status) 68841da177e4SLinus Torvalds goto out; 6885bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 68861da177e4SLinus Torvalds out: 68871da177e4SLinus Torvalds return status; 68881da177e4SLinus Torvalds } 68891da177e4SLinus Torvalds 68901da177e4SLinus Torvalds /* 68911da177e4SLinus Torvalds * Decode Read response 68921da177e4SLinus Torvalds */ 6893bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6894fc016483SChristoph Hellwig void *data) 68951da177e4SLinus Torvalds { 6896fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 68971da177e4SLinus Torvalds struct compound_hdr hdr; 68981da177e4SLinus Torvalds int status; 68991da177e4SLinus Torvalds 6900bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6901aabff4ddSPeng Tao res->op_status = hdr.status; 69021da177e4SLinus Torvalds if (status) 69031da177e4SLinus Torvalds goto out; 6904bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69059b7b9fccSAndy Adamson if (status) 69069b7b9fccSAndy Adamson goto out; 6907bf269551SChuck Lever status = decode_putfh(xdr); 69081da177e4SLinus Torvalds if (status) 69091da177e4SLinus Torvalds goto out; 6910bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 69111da177e4SLinus Torvalds if (!status) 69121da177e4SLinus Torvalds status = res->count; 69131da177e4SLinus Torvalds out: 69141da177e4SLinus Torvalds return status; 69151da177e4SLinus Torvalds } 69161da177e4SLinus Torvalds 69171da177e4SLinus Torvalds /* 69181da177e4SLinus Torvalds * Decode WRITE response 69191da177e4SLinus Torvalds */ 6920bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6921fc016483SChristoph Hellwig void *data) 69221da177e4SLinus Torvalds { 6923fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 69241da177e4SLinus Torvalds struct compound_hdr hdr; 69251da177e4SLinus Torvalds int status; 69261da177e4SLinus Torvalds 6927bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6928aabff4ddSPeng Tao res->op_status = hdr.status; 69291da177e4SLinus Torvalds if (status) 69301da177e4SLinus Torvalds goto out; 6931bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69329b7b9fccSAndy Adamson if (status) 69339b7b9fccSAndy Adamson goto out; 6934bf269551SChuck Lever status = decode_putfh(xdr); 69351da177e4SLinus Torvalds if (status) 69361da177e4SLinus Torvalds goto out; 6937bf269551SChuck Lever status = decode_write(xdr, res); 69384f9838c7STrond Myklebust if (status) 69394f9838c7STrond Myklebust goto out; 69407ffd1064SFred Isaman if (res->fattr) 69416926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 69421da177e4SLinus Torvalds if (!status) 69431da177e4SLinus Torvalds status = res->count; 69441da177e4SLinus Torvalds out: 69451da177e4SLinus Torvalds return status; 69461da177e4SLinus Torvalds } 69471da177e4SLinus Torvalds 69481da177e4SLinus Torvalds /* 69491da177e4SLinus Torvalds * Decode COMMIT response 69501da177e4SLinus Torvalds */ 6951bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6952fc016483SChristoph Hellwig void *data) 69531da177e4SLinus Torvalds { 6954fc016483SChristoph Hellwig struct nfs_commitres *res = data; 69551da177e4SLinus Torvalds struct compound_hdr hdr; 69561da177e4SLinus Torvalds int status; 69571da177e4SLinus Torvalds 6958bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6959aabff4ddSPeng Tao res->op_status = hdr.status; 69601da177e4SLinus Torvalds if (status) 69611da177e4SLinus Torvalds goto out; 6962bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69639b7b9fccSAndy Adamson if (status) 69649b7b9fccSAndy Adamson goto out; 6965bf269551SChuck Lever status = decode_putfh(xdr); 69661da177e4SLinus Torvalds if (status) 69671da177e4SLinus Torvalds goto out; 6968bf269551SChuck Lever status = decode_commit(xdr, res); 69691da177e4SLinus Torvalds out: 69701da177e4SLinus Torvalds return status; 69711da177e4SLinus Torvalds } 69721da177e4SLinus Torvalds 69731da177e4SLinus Torvalds /* 69748b173218SRicardo Labiaga * Decode FSINFO response 69751da177e4SLinus Torvalds */ 6976bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 6977fc016483SChristoph Hellwig void *data) 69781da177e4SLinus Torvalds { 6979fc016483SChristoph Hellwig struct nfs4_fsinfo_res *res = data; 69801da177e4SLinus Torvalds struct compound_hdr hdr; 69811da177e4SLinus Torvalds int status; 69821da177e4SLinus Torvalds 6983bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69841da177e4SLinus Torvalds if (!status) 6985bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69869b7b9fccSAndy Adamson if (!status) 6987bf269551SChuck Lever status = decode_putfh(xdr); 69881da177e4SLinus Torvalds if (!status) 6989bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 69901da177e4SLinus Torvalds return status; 69911da177e4SLinus Torvalds } 69921da177e4SLinus Torvalds 69931da177e4SLinus Torvalds /* 69948b173218SRicardo Labiaga * Decode PATHCONF response 69951da177e4SLinus Torvalds */ 6996bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6997fc016483SChristoph Hellwig void *data) 69981da177e4SLinus Torvalds { 6999fc016483SChristoph Hellwig struct nfs4_pathconf_res *res = data; 70001da177e4SLinus Torvalds struct compound_hdr hdr; 70011da177e4SLinus Torvalds int status; 70021da177e4SLinus Torvalds 7003bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70041da177e4SLinus Torvalds if (!status) 7005bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70069b7b9fccSAndy Adamson if (!status) 7007bf269551SChuck Lever status = decode_putfh(xdr); 70081da177e4SLinus Torvalds if (!status) 7009bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 70101da177e4SLinus Torvalds return status; 70111da177e4SLinus Torvalds } 70121da177e4SLinus Torvalds 70131da177e4SLinus Torvalds /* 70148b173218SRicardo Labiaga * Decode STATFS response 70151da177e4SLinus Torvalds */ 7016bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 7017fc016483SChristoph Hellwig void *data) 70181da177e4SLinus Torvalds { 7019fc016483SChristoph Hellwig struct nfs4_statfs_res *res = data; 70201da177e4SLinus Torvalds struct compound_hdr hdr; 70211da177e4SLinus Torvalds int status; 70221da177e4SLinus Torvalds 7023bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70241da177e4SLinus Torvalds if (!status) 7025bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70269b7b9fccSAndy Adamson if (!status) 7027bf269551SChuck Lever status = decode_putfh(xdr); 70281da177e4SLinus Torvalds if (!status) 7029bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 70301da177e4SLinus Torvalds return status; 70311da177e4SLinus Torvalds } 70321da177e4SLinus Torvalds 70331da177e4SLinus Torvalds /* 70348b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 70351da177e4SLinus Torvalds */ 7036bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 7037bf269551SChuck Lever struct xdr_stream *xdr, 7038fc016483SChristoph Hellwig void *data) 70391da177e4SLinus Torvalds { 7040fc016483SChristoph Hellwig struct nfs4_server_caps_res *res = data; 70411da177e4SLinus Torvalds struct compound_hdr hdr; 70421da177e4SLinus Torvalds int status; 70431da177e4SLinus Torvalds 7044bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70459b7b9fccSAndy Adamson if (status) 70469b7b9fccSAndy Adamson goto out; 7047bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70489b7b9fccSAndy Adamson if (status) 70491da177e4SLinus Torvalds goto out; 7050bf269551SChuck Lever status = decode_putfh(xdr); 7051bf269551SChuck Lever if (status) 70521da177e4SLinus Torvalds goto out; 7053bf269551SChuck Lever status = decode_server_caps(xdr, res); 70541da177e4SLinus Torvalds out: 70551da177e4SLinus Torvalds return status; 70561da177e4SLinus Torvalds } 70571da177e4SLinus Torvalds 70581da177e4SLinus Torvalds /* 70591da177e4SLinus Torvalds * Decode RENEW response 70601da177e4SLinus Torvalds */ 7061bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 7062bf269551SChuck Lever void *__unused) 70631da177e4SLinus Torvalds { 70641da177e4SLinus Torvalds struct compound_hdr hdr; 70651da177e4SLinus Torvalds int status; 70661da177e4SLinus Torvalds 7067bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70681da177e4SLinus Torvalds if (!status) 7069bf269551SChuck Lever status = decode_renew(xdr); 70701da177e4SLinus Torvalds return status; 70711da177e4SLinus Torvalds } 70721da177e4SLinus Torvalds 70731da177e4SLinus Torvalds /* 70748b173218SRicardo Labiaga * Decode SETCLIENTID response 70751da177e4SLinus Torvalds */ 7076bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 7077bf269551SChuck Lever struct xdr_stream *xdr, 7078fc016483SChristoph Hellwig void *data) 70791da177e4SLinus Torvalds { 7080fc016483SChristoph Hellwig struct nfs4_setclientid_res *res = data; 70811da177e4SLinus Torvalds struct compound_hdr hdr; 70821da177e4SLinus Torvalds int status; 70831da177e4SLinus Torvalds 7084bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70851da177e4SLinus Torvalds if (!status) 7086bf269551SChuck Lever status = decode_setclientid(xdr, res); 70871da177e4SLinus Torvalds return status; 70881da177e4SLinus Torvalds } 70891da177e4SLinus Torvalds 70901da177e4SLinus Torvalds /* 70918b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 70921da177e4SLinus Torvalds */ 7093bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 7094fc016483SChristoph Hellwig struct xdr_stream *xdr, 7095fc016483SChristoph Hellwig void *data) 70961da177e4SLinus Torvalds { 70971da177e4SLinus Torvalds struct compound_hdr hdr; 70981da177e4SLinus Torvalds int status; 70991da177e4SLinus Torvalds 7100bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71011da177e4SLinus Torvalds if (!status) 7102bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 71031da177e4SLinus Torvalds return status; 71041da177e4SLinus Torvalds } 71051da177e4SLinus Torvalds 71061da177e4SLinus Torvalds /* 71078b173218SRicardo Labiaga * Decode DELEGRETURN response 71081da177e4SLinus Torvalds */ 7109bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 7110bf269551SChuck Lever struct xdr_stream *xdr, 7111fc016483SChristoph Hellwig void *data) 71121da177e4SLinus Torvalds { 7113fc016483SChristoph Hellwig struct nfs4_delegreturnres *res = data; 71141da177e4SLinus Torvalds struct compound_hdr hdr; 71151da177e4SLinus Torvalds int status; 71161da177e4SLinus Torvalds 7117bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71189b7b9fccSAndy Adamson if (status) 71199b7b9fccSAndy Adamson goto out; 7120bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 71219b7b9fccSAndy Adamson if (status) 7122fa178f29STrond Myklebust goto out; 7123bf269551SChuck Lever status = decode_putfh(xdr); 7124fa178f29STrond Myklebust if (status != 0) 7125fa178f29STrond Myklebust goto out; 7126586f1c39STrond Myklebust if (res->lr_res) { 7127586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 7128586f1c39STrond Myklebust res->lr_ret = status; 7129586f1c39STrond Myklebust if (status) 7130586f1c39STrond Myklebust goto out; 7131586f1c39STrond Myklebust } 71328ac2b422STrond Myklebust if (res->fattr) { 7133e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 7134556ae3bbSJeff Layton if (status != 0) 7135556ae3bbSJeff Layton goto out; 71368ac2b422STrond Myklebust } 7137e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 7138fa178f29STrond Myklebust out: 71391da177e4SLinus Torvalds return status; 71401da177e4SLinus Torvalds } 71411da177e4SLinus Torvalds 7142683b57b4STrond Myklebust /* 71438b173218SRicardo Labiaga * Decode FS_LOCATIONS response 7144683b57b4STrond Myklebust */ 7145bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 7146bf269551SChuck Lever struct xdr_stream *xdr, 7147fc016483SChristoph Hellwig void *data) 7148683b57b4STrond Myklebust { 7149fc016483SChristoph Hellwig struct nfs4_fs_locations_res *res = data; 7150683b57b4STrond Myklebust struct compound_hdr hdr; 7151683b57b4STrond Myklebust int status; 7152683b57b4STrond Myklebust 7153bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71549b7b9fccSAndy Adamson if (status) 71559b7b9fccSAndy Adamson goto out; 7156bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 71579b7b9fccSAndy Adamson if (status) 7158683b57b4STrond Myklebust goto out; 7159bf269551SChuck Lever status = decode_putfh(xdr); 7160bf269551SChuck Lever if (status) 7161683b57b4STrond Myklebust goto out; 7162b03d735bSChuck Lever if (res->migration) { 7163b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7164b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7165b03d735bSChuck Lever &res->fs_locations->fattr, 7166b03d735bSChuck Lever NULL, res->fs_locations, 7167b03d735bSChuck Lever NULL, res->fs_locations->server); 7168b03d735bSChuck Lever if (status) 7169b03d735bSChuck Lever goto out; 7170b03d735bSChuck Lever if (res->renew) 7171b03d735bSChuck Lever status = decode_renew(xdr); 7172b03d735bSChuck Lever } else { 7173bf269551SChuck Lever status = decode_lookup(xdr); 7174bf269551SChuck Lever if (status) 7175683b57b4STrond Myklebust goto out; 7176bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7177b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7178b03d735bSChuck Lever &res->fs_locations->fattr, 71798b7e3f49STrond Myklebust NULL, res->fs_locations, 7180aa9c2669SDavid Quigley NULL, res->fs_locations->server); 7181b03d735bSChuck Lever } 7182683b57b4STrond Myklebust out: 7183683b57b4STrond Myklebust return status; 7184683b57b4STrond Myklebust } 7185683b57b4STrond Myklebust 71865a5ea0d4SBryan Schumaker /* 71875a5ea0d4SBryan Schumaker * Decode SECINFO response 71885a5ea0d4SBryan Schumaker */ 71895a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 71905a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 7191fc016483SChristoph Hellwig void *data) 71925a5ea0d4SBryan Schumaker { 7193fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 71945a5ea0d4SBryan Schumaker struct compound_hdr hdr; 71955a5ea0d4SBryan Schumaker int status; 71965a5ea0d4SBryan Schumaker 71975a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 71985a5ea0d4SBryan Schumaker if (status) 71995a5ea0d4SBryan Schumaker goto out; 72005a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 72015a5ea0d4SBryan Schumaker if (status) 72025a5ea0d4SBryan Schumaker goto out; 72035a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 72045a5ea0d4SBryan Schumaker if (status) 72055a5ea0d4SBryan Schumaker goto out; 72065a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 72075a5ea0d4SBryan Schumaker out: 72085a5ea0d4SBryan Schumaker return status; 72095a5ea0d4SBryan Schumaker } 72105a5ea0d4SBryan Schumaker 721144c99933SChuck Lever /* 721244c99933SChuck Lever * Decode FSID_PRESENT response 721344c99933SChuck Lever */ 721444c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 721544c99933SChuck Lever struct xdr_stream *xdr, 7216fc016483SChristoph Hellwig void *data) 721744c99933SChuck Lever { 7218fc016483SChristoph Hellwig struct nfs4_fsid_present_res *res = data; 721944c99933SChuck Lever struct compound_hdr hdr; 722044c99933SChuck Lever int status; 722144c99933SChuck Lever 722244c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 722344c99933SChuck Lever if (status) 722444c99933SChuck Lever goto out; 722544c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 722644c99933SChuck Lever if (status) 722744c99933SChuck Lever goto out; 722844c99933SChuck Lever status = decode_putfh(xdr); 722944c99933SChuck Lever if (status) 723044c99933SChuck Lever goto out; 723144c99933SChuck Lever status = decode_getfh(xdr, res->fh); 723244c99933SChuck Lever if (status) 723344c99933SChuck Lever goto out; 723444c99933SChuck Lever if (res->renew) 723544c99933SChuck Lever status = decode_renew(xdr); 723644c99933SChuck Lever out: 723744c99933SChuck Lever return status; 723844c99933SChuck Lever } 723944c99933SChuck Lever 724099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 724199fe60d0SBenny Halevy /* 72427c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 72437c44f1aeSWeston Andros Adamson */ 72447c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 72457c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 72467c44f1aeSWeston Andros Adamson void *res) 72477c44f1aeSWeston Andros Adamson { 72487c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 72497c44f1aeSWeston Andros Adamson int status; 72507c44f1aeSWeston Andros Adamson 72517c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 72527c44f1aeSWeston Andros Adamson if (!status) 72537c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 72547c44f1aeSWeston Andros Adamson return status; 72557c44f1aeSWeston Andros Adamson } 72567c44f1aeSWeston Andros Adamson 72577c44f1aeSWeston Andros Adamson /* 72588b173218SRicardo Labiaga * Decode EXCHANGE_ID response 725999fe60d0SBenny Halevy */ 7260bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7261bf269551SChuck Lever struct xdr_stream *xdr, 726299fe60d0SBenny Halevy void *res) 726399fe60d0SBenny Halevy { 726499fe60d0SBenny Halevy struct compound_hdr hdr; 726599fe60d0SBenny Halevy int status; 726699fe60d0SBenny Halevy 7267bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 726899fe60d0SBenny Halevy if (!status) 7269bf269551SChuck Lever status = decode_exchange_id(xdr, res); 727099fe60d0SBenny Halevy return status; 727199fe60d0SBenny Halevy } 72722050f0ccSAndy Adamson 72732050f0ccSAndy Adamson /* 72748b173218SRicardo Labiaga * Decode CREATE_SESSION response 7275fc931582SAndy Adamson */ 7276bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7277bf269551SChuck Lever struct xdr_stream *xdr, 7278fc016483SChristoph Hellwig void *res) 7279fc931582SAndy Adamson { 7280fc931582SAndy Adamson struct compound_hdr hdr; 7281fc931582SAndy Adamson int status; 7282fc931582SAndy Adamson 7283bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7284fc931582SAndy Adamson if (!status) 7285bf269551SChuck Lever status = decode_create_session(xdr, res); 7286fc931582SAndy Adamson return status; 7287fc931582SAndy Adamson } 7288fc931582SAndy Adamson 7289fc931582SAndy Adamson /* 72908b173218SRicardo Labiaga * Decode DESTROY_SESSION response 72910f3e66c6SAndy Adamson */ 7292bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7293bf269551SChuck Lever struct xdr_stream *xdr, 7294bf269551SChuck Lever void *res) 72950f3e66c6SAndy Adamson { 72960f3e66c6SAndy Adamson struct compound_hdr hdr; 72970f3e66c6SAndy Adamson int status; 72980f3e66c6SAndy Adamson 7299bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 73000f3e66c6SAndy Adamson if (!status) 7301bf269551SChuck Lever status = decode_destroy_session(xdr, res); 73020f3e66c6SAndy Adamson return status; 73030f3e66c6SAndy Adamson } 73040f3e66c6SAndy Adamson 73050f3e66c6SAndy Adamson /* 730666245539STrond Myklebust * Decode DESTROY_CLIENTID response 730766245539STrond Myklebust */ 730866245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 730966245539STrond Myklebust struct xdr_stream *xdr, 731066245539STrond Myklebust void *res) 731166245539STrond Myklebust { 731266245539STrond Myklebust struct compound_hdr hdr; 731366245539STrond Myklebust int status; 731466245539STrond Myklebust 731566245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 731666245539STrond Myklebust if (!status) 731766245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 731866245539STrond Myklebust return status; 731966245539STrond Myklebust } 732066245539STrond Myklebust 732166245539STrond Myklebust /* 73228b173218SRicardo Labiaga * Decode SEQUENCE response 7323fc01cea9SAndy Adamson */ 7324bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7325bf269551SChuck Lever struct xdr_stream *xdr, 7326fc016483SChristoph Hellwig void *res) 7327fc01cea9SAndy Adamson { 7328fc01cea9SAndy Adamson struct compound_hdr hdr; 7329fc01cea9SAndy Adamson int status; 7330fc01cea9SAndy Adamson 7331bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7332fc01cea9SAndy Adamson if (!status) 7333bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7334fc01cea9SAndy Adamson return status; 7335fc01cea9SAndy Adamson } 7336fc01cea9SAndy Adamson 7337fc01cea9SAndy Adamson /* 73388b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 73392050f0ccSAndy Adamson */ 7340bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7341bf269551SChuck Lever struct xdr_stream *xdr, 7342fc016483SChristoph Hellwig void *data) 73432050f0ccSAndy Adamson { 7344fc016483SChristoph Hellwig struct nfs4_get_lease_time_res *res = data; 73452050f0ccSAndy Adamson struct compound_hdr hdr; 73462050f0ccSAndy Adamson int status; 73472050f0ccSAndy Adamson 7348bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 73492050f0ccSAndy Adamson if (!status) 7350bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 73512050f0ccSAndy Adamson if (!status) 7352bf269551SChuck Lever status = decode_putrootfh(xdr); 73532050f0ccSAndy Adamson if (!status) 7354bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 73552050f0ccSAndy Adamson return status; 73562050f0ccSAndy Adamson } 735718019753SRicardo Labiaga 735818019753SRicardo Labiaga /* 735918019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 736018019753SRicardo Labiaga */ 7361bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7362bf269551SChuck Lever struct xdr_stream *xdr, 7363fc016483SChristoph Hellwig void *data) 736418019753SRicardo Labiaga { 7365fc016483SChristoph Hellwig struct nfs41_reclaim_complete_res *res = data; 736618019753SRicardo Labiaga struct compound_hdr hdr; 736718019753SRicardo Labiaga int status; 736818019753SRicardo Labiaga 7369bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 737018019753SRicardo Labiaga if (!status) 7371bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 737218019753SRicardo Labiaga if (!status) 73738ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 737418019753SRicardo Labiaga return status; 737518019753SRicardo Labiaga } 7376b1f69b75SAndy Adamson 7377b1f69b75SAndy Adamson /* 7378b1f69b75SAndy Adamson * Decode GETDEVINFO response 7379b1f69b75SAndy Adamson */ 7380bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7381bf269551SChuck Lever struct xdr_stream *xdr, 7382fc016483SChristoph Hellwig void *data) 7383b1f69b75SAndy Adamson { 7384fc016483SChristoph Hellwig struct nfs4_getdeviceinfo_res *res = data; 7385b1f69b75SAndy Adamson struct compound_hdr hdr; 7386b1f69b75SAndy Adamson int status; 7387b1f69b75SAndy Adamson 7388bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7389b1f69b75SAndy Adamson if (status != 0) 7390b1f69b75SAndy Adamson goto out; 7391bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7392b1f69b75SAndy Adamson if (status != 0) 7393b1f69b75SAndy Adamson goto out; 73944e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7395b1f69b75SAndy Adamson out: 7396b1f69b75SAndy Adamson return status; 7397b1f69b75SAndy Adamson } 7398b1f69b75SAndy Adamson 7399b1f69b75SAndy Adamson /* 7400b1f69b75SAndy Adamson * Decode LAYOUTGET response 7401b1f69b75SAndy Adamson */ 7402bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7403bf269551SChuck Lever struct xdr_stream *xdr, 7404fc016483SChristoph Hellwig void *data) 7405b1f69b75SAndy Adamson { 7406fc016483SChristoph Hellwig struct nfs4_layoutget_res *res = data; 7407b1f69b75SAndy Adamson struct compound_hdr hdr; 7408b1f69b75SAndy Adamson int status; 7409b1f69b75SAndy Adamson 7410bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7411b1f69b75SAndy Adamson if (status) 7412b1f69b75SAndy Adamson goto out; 7413bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7414b1f69b75SAndy Adamson if (status) 7415b1f69b75SAndy Adamson goto out; 7416bf269551SChuck Lever status = decode_putfh(xdr); 7417b1f69b75SAndy Adamson if (status) 7418b1f69b75SAndy Adamson goto out; 7419bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7420b1f69b75SAndy Adamson out: 7421b1f69b75SAndy Adamson return status; 7422b1f69b75SAndy Adamson } 7423863a3c6cSAndy Adamson 7424863a3c6cSAndy Adamson /* 7425cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7426cbe82603SBenny Halevy */ 7427cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7428cbe82603SBenny Halevy struct xdr_stream *xdr, 7429fc016483SChristoph Hellwig void *data) 7430cbe82603SBenny Halevy { 7431fc016483SChristoph Hellwig struct nfs4_layoutreturn_res *res = data; 7432cbe82603SBenny Halevy struct compound_hdr hdr; 7433cbe82603SBenny Halevy int status; 7434cbe82603SBenny Halevy 7435cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7436cbe82603SBenny Halevy if (status) 7437cbe82603SBenny Halevy goto out; 7438cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7439cbe82603SBenny Halevy if (status) 7440cbe82603SBenny Halevy goto out; 7441cbe82603SBenny Halevy status = decode_putfh(xdr); 7442cbe82603SBenny Halevy if (status) 7443cbe82603SBenny Halevy goto out; 7444cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7445cbe82603SBenny Halevy out: 7446cbe82603SBenny Halevy return status; 7447cbe82603SBenny Halevy } 7448cbe82603SBenny Halevy 7449cbe82603SBenny Halevy /* 7450863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7451863a3c6cSAndy Adamson */ 7452863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7453863a3c6cSAndy Adamson struct xdr_stream *xdr, 7454fc016483SChristoph Hellwig void *data) 7455863a3c6cSAndy Adamson { 7456fc016483SChristoph Hellwig struct nfs4_layoutcommit_res *res = data; 7457863a3c6cSAndy Adamson struct compound_hdr hdr; 7458863a3c6cSAndy Adamson int status; 7459863a3c6cSAndy Adamson 7460863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7461863a3c6cSAndy Adamson if (status) 7462863a3c6cSAndy Adamson goto out; 7463863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7464863a3c6cSAndy Adamson if (status) 7465863a3c6cSAndy Adamson goto out; 7466863a3c6cSAndy Adamson status = decode_putfh(xdr); 7467863a3c6cSAndy Adamson if (status) 7468863a3c6cSAndy Adamson goto out; 7469863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7470863a3c6cSAndy Adamson if (status) 7471863a3c6cSAndy Adamson goto out; 74726926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7473863a3c6cSAndy Adamson out: 7474863a3c6cSAndy Adamson return status; 7475863a3c6cSAndy Adamson } 7476fca78d6dSBryan Schumaker 7477fca78d6dSBryan Schumaker /* 7478fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7479fca78d6dSBryan Schumaker */ 7480fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7481fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7482fc016483SChristoph Hellwig void *data) 7483fca78d6dSBryan Schumaker { 7484fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 7485fca78d6dSBryan Schumaker struct compound_hdr hdr; 7486fca78d6dSBryan Schumaker int status; 7487fca78d6dSBryan Schumaker 7488fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7489fca78d6dSBryan Schumaker if (status) 7490fca78d6dSBryan Schumaker goto out; 7491fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7492fca78d6dSBryan Schumaker if (status) 7493fca78d6dSBryan Schumaker goto out; 7494fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7495fca78d6dSBryan Schumaker if (status) 7496fca78d6dSBryan Schumaker goto out; 749731e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7498fca78d6dSBryan Schumaker out: 7499fca78d6dSBryan Schumaker return status; 7500fca78d6dSBryan Schumaker } 75017d974794SBryan Schumaker 75027d974794SBryan Schumaker /* 75037d974794SBryan Schumaker * Decode TEST_STATEID response 75047d974794SBryan Schumaker */ 75057d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 75067d974794SBryan Schumaker struct xdr_stream *xdr, 7507fc016483SChristoph Hellwig void *data) 75087d974794SBryan Schumaker { 7509fc016483SChristoph Hellwig struct nfs41_test_stateid_res *res = data; 75107d974794SBryan Schumaker struct compound_hdr hdr; 75117d974794SBryan Schumaker int status; 75127d974794SBryan Schumaker 75137d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 75147d974794SBryan Schumaker if (status) 75157d974794SBryan Schumaker goto out; 75167d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 75177d974794SBryan Schumaker if (status) 75187d974794SBryan Schumaker goto out; 75197d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 75207d974794SBryan Schumaker out: 75217d974794SBryan Schumaker return status; 75227d974794SBryan Schumaker } 75239aeda35fSBryan Schumaker 75249aeda35fSBryan Schumaker /* 75259aeda35fSBryan Schumaker * Decode FREE_STATEID response 75269aeda35fSBryan Schumaker */ 75279aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 75289aeda35fSBryan Schumaker struct xdr_stream *xdr, 7529fc016483SChristoph Hellwig void *data) 75309aeda35fSBryan Schumaker { 7531fc016483SChristoph Hellwig struct nfs41_free_stateid_res *res = data; 75329aeda35fSBryan Schumaker struct compound_hdr hdr; 75339aeda35fSBryan Schumaker int status; 75349aeda35fSBryan Schumaker 75359aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 75369aeda35fSBryan Schumaker if (status) 75379aeda35fSBryan Schumaker goto out; 75389aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 75399aeda35fSBryan Schumaker if (status) 75409aeda35fSBryan Schumaker goto out; 75419aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 75429aeda35fSBryan Schumaker out: 75439aeda35fSBryan Schumaker return status; 75449aeda35fSBryan Schumaker } 754599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 754699fe60d0SBenny Halevy 7547573c4e1eSChuck Lever /** 7548573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7549573c4e1eSChuck Lever * the local page cache. 7550573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7551573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7552573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7553573c4e1eSChuck Lever * 7554573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7555573c4e1eSChuck Lever * returned. 7556573c4e1eSChuck Lever * 7557573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7558573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7559573c4e1eSChuck Lever * on a directory already in our cache. 7560573c4e1eSChuck Lever */ 7561573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7562a7a3b1e9SBenjamin Coddington bool plus) 75631da177e4SLinus Torvalds { 7564256e48bbSTrond Myklebust unsigned int savep; 7565dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 75661da177e4SLinus Torvalds uint32_t len; 756798de9ce6SFrank Sorenson uint64_t new_cookie; 7568babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7569babddc72SBryan Schumaker if (unlikely(!p)) 7570babddc72SBryan Schumaker goto out_overflow; 7571c08e76d0SChuck Lever if (*p == xdr_zero) { 7572babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7573babddc72SBryan Schumaker if (unlikely(!p)) 7574babddc72SBryan Schumaker goto out_overflow; 7575c08e76d0SChuck Lever if (*p == xdr_zero) 7576573c4e1eSChuck Lever return -EAGAIN; 75771da177e4SLinus Torvalds entry->eof = 1; 7578573c4e1eSChuck Lever return -EBADCOOKIE; 75791da177e4SLinus Torvalds } 75801da177e4SLinus Torvalds 7581babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7582babddc72SBryan Schumaker if (unlikely(!p)) 7583babddc72SBryan Schumaker goto out_overflow; 758498de9ce6SFrank Sorenson p = xdr_decode_hyper(p, &new_cookie); 7585c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7586babddc72SBryan Schumaker 75879af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7588babddc72SBryan Schumaker if (unlikely(!p)) 7589babddc72SBryan Schumaker goto out_overflow; 75901da177e4SLinus Torvalds entry->name = (const char *) p; 75911da177e4SLinus Torvalds 75921da177e4SLinus Torvalds /* 75931da177e4SLinus Torvalds * In case the server doesn't return an inode number, 75941da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 75951da177e4SLinus Torvalds * since glibc seems to choke on it...) 75961da177e4SLinus Torvalds */ 75971da177e4SLinus Torvalds entry->ino = 1; 75984f082222STrond Myklebust entry->fattr->valid = 0; 75991da177e4SLinus Torvalds 76009af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7601babddc72SBryan Schumaker goto out_overflow; 76029af8c222STrond Myklebust 7603256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7604babddc72SBryan Schumaker goto out_overflow; 76059af8c222STrond Myklebust 7606573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7607aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7608babddc72SBryan Schumaker goto out_overflow; 760928331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 761028331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 761128331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 761282f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 76139af8c222STrond Myklebust 76140b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 76150b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 76160b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 76170b26a0bfSTrond Myklebust 761898de9ce6SFrank Sorenson entry->prev_cookie = entry->cookie; 761998de9ce6SFrank Sorenson entry->cookie = new_cookie; 762098de9ce6SFrank Sorenson 7621573c4e1eSChuck Lever return 0; 7622babddc72SBryan Schumaker 7623babddc72SBryan Schumaker out_overflow: 7624babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7625573c4e1eSChuck Lever return -EAGAIN; 76261da177e4SLinus Torvalds } 76271da177e4SLinus Torvalds 76281da177e4SLinus Torvalds /* 76291da177e4SLinus Torvalds * We need to translate between nfs status return values and 76301da177e4SLinus Torvalds * the local errno values which may not be the same. 76311da177e4SLinus Torvalds */ 76321da177e4SLinus Torvalds static struct { 76331da177e4SLinus Torvalds int stat; 76341da177e4SLinus Torvalds int errno; 76351da177e4SLinus Torvalds } nfs_errtbl[] = { 76361da177e4SLinus Torvalds { NFS4_OK, 0 }, 7637856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7638856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7639856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7640856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7641856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7642856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7643856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7644856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7645856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7646856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7647856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7648856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7649856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7650856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7651856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7652856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7653856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7654856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7655856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7656856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7657856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7658856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7659fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7660856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7661856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7662856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7663856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7664856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7665856dff3dSBenny Halevy { -1, -EIO } 76661da177e4SLinus Torvalds }; 76671da177e4SLinus Torvalds 76681da177e4SLinus Torvalds /* 76691da177e4SLinus Torvalds * Convert an NFS error code to a local one. 76701da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 76711da177e4SLinus Torvalds */ 76721da177e4SLinus Torvalds static int 76730a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 76741da177e4SLinus Torvalds { 76751da177e4SLinus Torvalds int i; 76761da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 76771da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 76781da177e4SLinus Torvalds return nfs_errtbl[i].errno; 76791da177e4SLinus Torvalds } 76801da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 76811da177e4SLinus Torvalds /* The server is looney tunes. */ 7682fdcb4577STrond Myklebust return -EREMOTEIO; 76831da177e4SLinus Torvalds } 76841da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 76851da177e4SLinus Torvalds * handle it. 76861da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 76871da177e4SLinus Torvalds * not conflict with native Linux error codes. 76881da177e4SLinus Torvalds */ 7689856dff3dSBenny Halevy return -stat; 76901da177e4SLinus Torvalds } 76911da177e4SLinus Torvalds 76921c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 76931c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 76941c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 76951c6dcbe5SAnna Schumaker 76961da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 76971da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 76981da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 7699fcc85819SChristoph Hellwig .p_encode = nfs4_xdr_##argtype, \ 7700fc016483SChristoph Hellwig .p_decode = nfs4_xdr_##restype, \ 77012bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 77022bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7703cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7704cc0175c1SChuck Lever .p_name = #proc, \ 77051da177e4SLinus Torvalds } 77061da177e4SLinus Torvalds 77077c61f0d3SAnna Schumaker #define STUB(proc) \ 77087c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 77097c61f0d3SAnna Schumaker .p_name = #proc, \ 77107c61f0d3SAnna Schumaker } 77117c61f0d3SAnna Schumaker 77128634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1) 77138634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 77148634ef5eSTrond Myklebust PROC(proc, argtype, restype) 77158634ef5eSTrond Myklebust #else 77168634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 77178634ef5eSTrond Myklebust STUB(proc) 77188634ef5eSTrond Myklebust #endif 77198634ef5eSTrond Myklebust 77208634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2) 77218634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 77228634ef5eSTrond Myklebust PROC(proc, argtype, restype) 77238634ef5eSTrond Myklebust #else 77248634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 77258634ef5eSTrond Myklebust STUB(proc) 77268634ef5eSTrond Myklebust #endif 77278634ef5eSTrond Myklebust 7728511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = { 77291da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 77301da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 77311da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 77321da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 77331da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 77341da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 77351da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 77361da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 77371da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 77381da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 77391da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 77401da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 77411da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 77421da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 77431da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 77441da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 77451da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 77461da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 77471da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 77481da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 77491da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 77501da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 77511da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 77521da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 77531da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 77541da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 77551da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 77561da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 77571da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 77581da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 77591da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7760029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 776123ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7762683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7763d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 77645a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 776544c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 77668634ef5eSTrond Myklebust PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 77678634ef5eSTrond Myklebust PROC41(CREATE_SESSION, enc_create_session, dec_create_session), 77688634ef5eSTrond Myklebust PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 77698634ef5eSTrond Myklebust PROC41(SEQUENCE, enc_sequence, dec_sequence), 77708634ef5eSTrond Myklebust PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 77718634ef5eSTrond Myklebust PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete), 77728634ef5eSTrond Myklebust PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 77738634ef5eSTrond Myklebust PROC41(LAYOUTGET, enc_layoutget, dec_layoutget), 77748634ef5eSTrond Myklebust PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 77758634ef5eSTrond Myklebust PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 77768634ef5eSTrond Myklebust PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 77778634ef5eSTrond Myklebust PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid), 77788634ef5eSTrond Myklebust PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid), 77797c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 77808634ef5eSTrond Myklebust PROC41(BIND_CONN_TO_SESSION, 7781ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 77828634ef5eSTrond Myklebust PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid), 77838634ef5eSTrond Myklebust PROC42(SEEK, enc_seek, dec_seek), 77848634ef5eSTrond Myklebust PROC42(ALLOCATE, enc_allocate, dec_allocate), 77858634ef5eSTrond Myklebust PROC42(DEALLOCATE, enc_deallocate, dec_deallocate), 77868634ef5eSTrond Myklebust PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 77878634ef5eSTrond Myklebust PROC42(CLONE, enc_clone, dec_clone), 77888634ef5eSTrond Myklebust PROC42(COPY, enc_copy, dec_copy), 77898634ef5eSTrond Myklebust PROC(LOOKUPP, enc_lookupp, dec_lookupp), 77901da177e4SLinus Torvalds }; 77911da177e4SLinus Torvalds 7792c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)]; 7793a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 77941da177e4SLinus Torvalds .number = 4, 7795e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 7796c551858aSChristoph Hellwig .procs = nfs4_procedures, 7797c551858aSChristoph Hellwig .counts = nfs_version4_counts, 77981da177e4SLinus Torvalds }; 77991da177e4SLinus Torvalds 78001da177e4SLinus Torvalds /* 78011da177e4SLinus Torvalds * Local variables: 78021da177e4SLinus Torvalds * c-basic-offset: 8 78031da177e4SLinus Torvalds * End: 78041da177e4SLinus Torvalds */ 7805