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 { 107295582b00SDeepa Dinamani struct timespec ts; 10731da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10741da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10751da177e4SLinus Torvalds int owner_namelen = 0; 10761da177e4SLinus Torvalds int owner_grouplen = 0; 10778687b63aSAl Viro __be32 *p; 1078d7067b2dSTrond Myklebust uint32_t len = 0; 1079d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10801da177e4SLinus Torvalds 10811da177e4SLinus Torvalds /* 10821da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10831da177e4SLinus Torvalds */ 108428cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) { 1085d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10861da177e4SLinus Torvalds len += 8; 1087d7067b2dSTrond Myklebust } 1088d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 108928cf22d0STrond Myklebust if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) { 1090dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK; 1091dff25ddbSAndreas Gruenbacher len += 8; 109228cf22d0STrond Myklebust } else if (attrmask[1] & FATTR4_WORD1_MODE) { 1093d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10941da177e4SLinus Torvalds len += 4; 1095d7067b2dSTrond Myklebust } 1096dff25ddbSAndreas Gruenbacher } 109728cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) { 1098e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10991da177e4SLinus Torvalds if (owner_namelen < 0) { 1100fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1101e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 11021da177e4SLinus Torvalds /* XXX */ 11031da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 11041da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 11051da177e4SLinus Torvalds /* goto out; */ 11061da177e4SLinus Torvalds } 1107d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 11081da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 11091da177e4SLinus Torvalds } 111028cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_GID) && 111128cf22d0STrond Myklebust (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) { 1112e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 11131da177e4SLinus Torvalds if (owner_grouplen < 0) { 1114fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1115e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 11161da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 11171da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 11181da177e4SLinus Torvalds /* goto out; */ 11191da177e4SLinus Torvalds } 1120d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 11211da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 11221da177e4SLinus Torvalds } 112328cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 1124d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1125d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 112636b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2); 1127d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1128d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 11291da177e4SLinus Torvalds len += 4; 1130d7067b2dSTrond Myklebust } 113128cf22d0STrond Myklebust } 113228cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 1133d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1134d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 113536b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2); 1136d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1137d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 11381da177e4SLinus Torvalds len += 4; 1139d7067b2dSTrond Myklebust } 11405334c5bdSKinglong Mee } 11415334c5bdSKinglong Mee 114228cf22d0STrond Myklebust if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) { 1143b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1144d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1145d7067b2dSTrond Myklebust } 1146d7067b2dSTrond Myklebust 114740a3426cSTrond Myklebust xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval)); 114840a3426cSTrond Myklebust xdr_stream_encode_opaque_inline(xdr, (void **)&p, len); 11491da177e4SLinus Torvalds 1150d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1151b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1152d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1153e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1154d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1155811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1156d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1157811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1158d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11591da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1160e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 116195582b00SDeepa Dinamani ts = timespec64_to_timespec(iap->ia_atime); 116295582b00SDeepa Dinamani p = xdr_encode_nfstime4(p, &ts); 1163d7067b2dSTrond Myklebust } else 1164e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11651da177e4SLinus Torvalds } 1166d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11671da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1168e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 116995582b00SDeepa Dinamani ts = timespec64_to_timespec(iap->ia_mtime); 117095582b00SDeepa Dinamani p = xdr_encode_nfstime4(p, &ts); 1171d7067b2dSTrond Myklebust } else 1172e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11731da177e4SLinus Torvalds } 1174d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1175aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1176aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1177aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1178aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1179aa9c2669SDavid Quigley } 1180dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1181dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1182dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask); 1183dff25ddbSAndreas Gruenbacher } 11841da177e4SLinus Torvalds 11851da177e4SLinus Torvalds /* out: */ 11861da177e4SLinus Torvalds } 11871da177e4SLinus Torvalds 1188cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11891da177e4SLinus Torvalds { 1190475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1191475d4ba0STrond Myklebust encode_uint32(xdr, access); 11921da177e4SLinus Torvalds } 11931da177e4SLinus Torvalds 1194cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11951da177e4SLinus Torvalds { 1196ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11974ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1198566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11991da177e4SLinus Torvalds } 12001da177e4SLinus Torvalds 12010b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 12021da177e4SLinus Torvalds { 12038687b63aSAl Viro __be32 *p; 12041da177e4SLinus Torvalds 1205475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1206475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1207b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 120834558513SBenny Halevy *p = cpu_to_be32(args->count); 12091da177e4SLinus Torvalds } 12101da177e4SLinus Torvalds 1211cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 12121da177e4SLinus Torvalds { 12138687b63aSAl Viro __be32 *p; 12141da177e4SLinus Torvalds 1215475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1216475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds switch (create->ftype) { 12191da177e4SLinus Torvalds case NF4LNK: 122013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 122134558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 12222fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 12232fcc213aSChuck Lever create->u.symlink.len); 12242fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 12251da177e4SLinus Torvalds break; 12261da177e4SLinus Torvalds 12271da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 122813c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1229e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 123034558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 12311da177e4SLinus Torvalds break; 12321da177e4SLinus Torvalds 12331da177e4SLinus Torvalds default: 12341da177e4SLinus Torvalds break; 12351da177e4SLinus Torvalds } 12361da177e4SLinus Torvalds 1237811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 123828cf22d0STrond Myklebust encode_attrs(xdr, create->attrs, create->label, &create->umask, 123928cf22d0STrond Myklebust create->server, create->server->attr_bitmask); 12401da177e4SLinus Torvalds } 12411da177e4SLinus Torvalds 124237c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr, 124337c88763STrond Myklebust const __u32 *bitmap, const __u32 *mask, size_t len, 1244dae100c2SFred Isaman struct compound_hdr *hdr) 1245dae100c2SFred Isaman { 124637c88763STrond Myklebust __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz]; 1247dae100c2SFred Isaman 1248ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 124937c88763STrond Myklebust if (mask) { 125037c88763STrond Myklebust if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap))) 125137c88763STrond Myklebust len = ARRAY_SIZE(masked_bitmap); 125237c88763STrond Myklebust len = mask_bitmap4(bitmap, mask, masked_bitmap, len); 125337c88763STrond Myklebust bitmap = masked_bitmap; 1254dae100c2SFred Isaman } 125537c88763STrond Myklebust xdr_encode_bitmap4(xdr, bitmap, len); 1256dae100c2SFred Isaman } 1257dae100c2SFred Isaman 1258cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12591da177e4SLinus Torvalds { 126037c88763STrond Myklebust encode_getattr(xdr, nfs4_fattr_bitmap, bitmask, 126137c88763STrond Myklebust ARRAY_SIZE(nfs4_fattr_bitmap), hdr); 12621da177e4SLinus Torvalds } 12631da177e4SLinus Torvalds 126488034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12651549210fSTrond Myklebust const u32 *open_bitmap, 126688034c3dSAndy Adamson struct compound_hdr *hdr) 126788034c3dSAndy Adamson { 126837c88763STrond Myklebust encode_getattr(xdr, open_bitmap, bitmask, 3, hdr); 126988034c3dSAndy Adamson } 127088034c3dSAndy Adamson 1271cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12721da177e4SLinus Torvalds { 127337c88763STrond Myklebust encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask, 127437c88763STrond Myklebust ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr); 12751da177e4SLinus Torvalds } 12761da177e4SLinus Torvalds 1277cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1278830b8e33SManoj Naik { 127937c88763STrond Myklebust encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask, 128037c88763STrond Myklebust ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr); 1281830b8e33SManoj Naik } 1282830b8e33SManoj Naik 1283cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12841da177e4SLinus Torvalds { 1285ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12861da177e4SLinus Torvalds } 12871da177e4SLinus Torvalds 1288cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12891da177e4SLinus Torvalds { 1290ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12916fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12921da177e4SLinus Torvalds } 12931da177e4SLinus Torvalds 1294911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1295911d1aafSTrond Myklebust { 1296f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1297911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1298911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1299911d1aafSTrond Myklebust } 1300911d1aafSTrond Myklebust 1301911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1302911d1aafSTrond Myklebust { 1303911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1304911d1aafSTrond Myklebust return ~(uint64_t)0; 1305911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1306911d1aafSTrond Myklebust } 1307911d1aafSTrond Myklebust 1308daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1309daccbdedSTrond Myklebust { 1310daccbdedSTrond Myklebust __be32 *p; 1311daccbdedSTrond Myklebust 1312d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1313daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1314d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1315daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1316d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1317daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1318daccbdedSTrond Myklebust } 1319daccbdedSTrond Myklebust 13201da177e4SLinus Torvalds /* 13211da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13221da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13231da177e4SLinus Torvalds */ 1324cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13251da177e4SLinus Torvalds { 13268687b63aSAl Viro __be32 *p; 13271da177e4SLinus Torvalds 1328475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1329475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1330e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1331e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1332b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1333b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 133434558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1335911d1aafSTrond Myklebust if (args->new_lock_owner){ 13364ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1337425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13384ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1339daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13401da177e4SLinus Torvalds } 13411da177e4SLinus Torvalds else { 1342425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13434ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13441da177e4SLinus Torvalds } 13451da177e4SLinus Torvalds } 13461da177e4SLinus Torvalds 1347cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13481da177e4SLinus Torvalds { 13498687b63aSAl Viro __be32 *p; 13501da177e4SLinus Torvalds 1351475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1352475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1353e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1354b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1355b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1356daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13571da177e4SLinus Torvalds } 13581da177e4SLinus Torvalds 1359cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13601da177e4SLinus Torvalds { 13618687b63aSAl Viro __be32 *p; 13621da177e4SLinus Torvalds 1363475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1364475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13654ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1366425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1367ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1368b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 136934558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13701da177e4SLinus Torvalds } 13711da177e4SLinus Torvalds 1372d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1373d3c7b7ccSTrond Myklebust { 1374ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1375d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1376d3c7b7ccSTrond Myklebust } 1377d3c7b7ccSTrond Myklebust 1378cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13791da177e4SLinus Torvalds { 1380ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13816fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13821da177e4SLinus Torvalds } 13831da177e4SLinus Torvalds 13845b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr) 13855b5faaf6SJeff Layton { 13865b5faaf6SJeff Layton encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr); 13875b5faaf6SJeff Layton } 13885b5faaf6SJeff Layton 13896ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13901da177e4SLinus Torvalds { 13918687b63aSAl Viro __be32 *p; 13921da177e4SLinus Torvalds 139313c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13946ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 139534558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13961da177e4SLinus Torvalds } 13971da177e4SLinus Torvalds 13981da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13991da177e4SLinus Torvalds { 14008687b63aSAl Viro __be32 *p; 14011da177e4SLinus Torvalds /* 14021da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 14031da177e4SLinus Torvalds * owner 4 = 32 14041da177e4SLinus Torvalds */ 14054ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14066ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 140795b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1408b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 140995b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 141093f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1411d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 141295b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 141395b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 14141da177e4SLinus Torvalds } 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14171da177e4SLinus Torvalds { 14188687b63aSAl Viro __be32 *p; 14191da177e4SLinus Torvalds 142013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1421549b19ccSTrond Myklebust switch(arg->createmode) { 1422549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 142334558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 142428cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 142528cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 14261da177e4SLinus Torvalds break; 1427549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14284882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 142928cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 143028cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 1431549b19ccSTrond Myklebust break; 1432549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1433549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1434549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1435549b19ccSTrond Myklebust break; 1436549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14374882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14384882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 143928cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 144028cf22d0STrond Myklebust arg->server, arg->server->exclcreat_bitmask); 14414882ef72SAlexandros Batsakis } 14424882ef72SAlexandros Batsakis } 14431da177e4SLinus Torvalds 14441da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14451da177e4SLinus Torvalds { 14468687b63aSAl Viro __be32 *p; 14471da177e4SLinus Torvalds 144813c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14491da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14501da177e4SLinus Torvalds case 0: 145134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14521da177e4SLinus Torvalds break; 14531da177e4SLinus Torvalds default: 145434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14551da177e4SLinus Torvalds encode_createmode(xdr, arg); 14561da177e4SLinus Torvalds } 14571da177e4SLinus Torvalds } 14581da177e4SLinus Torvalds 1459bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14601da177e4SLinus Torvalds { 14618687b63aSAl Viro __be32 *p; 14621da177e4SLinus Torvalds 146313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14641da177e4SLinus Torvalds switch (delegation_type) { 14651da177e4SLinus Torvalds case 0: 146634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14671da177e4SLinus Torvalds break; 14681da177e4SLinus Torvalds case FMODE_READ: 146934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14701da177e4SLinus Torvalds break; 14711da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 147234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14731da177e4SLinus Torvalds break; 14741da177e4SLinus Torvalds default: 14751da177e4SLinus Torvalds BUG(); 14761da177e4SLinus Torvalds } 14771da177e4SLinus Torvalds } 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14801da177e4SLinus Torvalds { 14818687b63aSAl Viro __be32 *p; 14821da177e4SLinus Torvalds 148313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 148434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14851da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14861da177e4SLinus Torvalds } 14871da177e4SLinus Torvalds 1488bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14891da177e4SLinus Torvalds { 14908687b63aSAl Viro __be32 *p; 14911da177e4SLinus Torvalds 149213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 149334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14941da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14951da177e4SLinus Torvalds } 14961da177e4SLinus Torvalds 14971da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14981da177e4SLinus Torvalds { 14998687b63aSAl Viro __be32 *p; 15001da177e4SLinus Torvalds 1501ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1502ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1503ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 15041da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 15051da177e4SLinus Torvalds } 15061da177e4SLinus Torvalds 1507d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1508d9fc6619STrond Myklebust { 1509d9fc6619STrond Myklebust __be32 *p; 1510d9fc6619STrond Myklebust 1511d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1512d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1513d9fc6619STrond Myklebust } 1514d9fc6619STrond Myklebust 1515d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1516d9fc6619STrond Myklebust { 1517d9fc6619STrond Myklebust __be32 *p; 1518d9fc6619STrond Myklebust 1519d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1520d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1521d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1522d9fc6619STrond Myklebust } 1523d9fc6619STrond Myklebust 1524cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15251da177e4SLinus Torvalds { 1526ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15271da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15281da177e4SLinus Torvalds encode_opentype(xdr, arg); 15291da177e4SLinus Torvalds switch (arg->claim) { 15301da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15311da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15321da177e4SLinus Torvalds break; 15331da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15341da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15351da177e4SLinus Torvalds break; 15361da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15371da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15381da177e4SLinus Torvalds break; 1539d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1540d9fc6619STrond Myklebust encode_claim_fh(xdr); 1541d9fc6619STrond Myklebust break; 1542d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1543d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1544d9fc6619STrond Myklebust break; 15451da177e4SLinus Torvalds default: 15461da177e4SLinus Torvalds BUG(); 15471da177e4SLinus Torvalds } 15481da177e4SLinus Torvalds } 15491da177e4SLinus Torvalds 1550cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15511da177e4SLinus Torvalds { 1552ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1553ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15544ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15551da177e4SLinus Torvalds } 15561da177e4SLinus Torvalds 1557cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15581da177e4SLinus Torvalds { 1559ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1560566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15614ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15626ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15631da177e4SLinus Torvalds } 15641da177e4SLinus Torvalds 1565cf8cdbe5SAndy Adamson static void 1566d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15671da177e4SLinus Torvalds { 1568ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15696fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15701da177e4SLinus Torvalds } 15711da177e4SLinus Torvalds 1572cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15731da177e4SLinus Torvalds { 1574ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15751da177e4SLinus Torvalds } 15761da177e4SLinus Torvalds 15773c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15783c6b899cSAnna Schumaker struct compound_hdr *hdr) 15791da177e4SLinus Torvalds { 15808687b63aSAl Viro __be32 *p; 15811da177e4SLinus Torvalds 1582ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15839b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15841da177e4SLinus Torvalds 158513c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1586b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 158734558513SBenny Halevy *p = cpu_to_be32(args->count); 15881da177e4SLinus Torvalds } 15891da177e4SLinus Torvalds 1590cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15911da177e4SLinus Torvalds { 1592aa9c2669SDavid Quigley uint32_t attrs[3] = { 159328331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 159428331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 159528331a46STrond Myklebust }; 15966f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1597cd93710eSChuck Lever __be32 *p, verf[2]; 1598d204c5d2STrond Myklebust uint32_t attrlen = 0; 1599d204c5d2STrond Myklebust unsigned int i; 16001da177e4SLinus Torvalds 160182f2e547SBryan Schumaker if (readdir->plus) { 160282f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 160328331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 160482f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 160582f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 160682f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 160782f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1608d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 16096f7a35bdSTrond Myklebust dircount >>= 1; 161082f2e547SBryan Schumaker } 161128331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 161228331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 161328331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1614d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1615d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1616d204c5d2STrond Myklebust if (attrs[i] != 0) 1617d204c5d2STrond Myklebust attrlen = i+1; 1618d204c5d2STrond Myklebust } 16196f7a35bdSTrond Myklebust 1620475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1621ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1622cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1623d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16246f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16256f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1626d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1627d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1628d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1629cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1630aa9c2669SDavid Quigley 1631aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 163244109241SFred Isaman __func__, 1633eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1634cd93710eSChuck Lever verf[0], verf[1], 1635eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1636aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1637aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16381da177e4SLinus Torvalds } 16391da177e4SLinus Torvalds 1640cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16411da177e4SLinus Torvalds { 1642ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16431da177e4SLinus Torvalds } 16441da177e4SLinus Torvalds 1645cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16461da177e4SLinus Torvalds { 1647ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16486fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16491da177e4SLinus Torvalds } 16501da177e4SLinus Torvalds 1651cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16521da177e4SLinus Torvalds { 1653ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1654811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1655811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16561da177e4SLinus Torvalds } 16571da177e4SLinus Torvalds 1658bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1659bb4dae5eSChuck Lever struct compound_hdr *hdr) 16601da177e4SLinus Torvalds { 1661475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1662ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16631da177e4SLinus Torvalds } 16641da177e4SLinus Torvalds 1665cf8cdbe5SAndy Adamson static void 1666d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 166756ae19f3STrond Myklebust { 1668ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 166956ae19f3STrond Myklebust } 167056ae19f3STrond Myklebust 16719f06c719SChuck Lever static void 1672fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg, 1673fcc85819SChristoph Hellwig struct compound_hdr *hdr) 167423ec6965SJ. Bruce Fields { 16758687b63aSAl Viro __be32 *p; 167623ec6965SJ. Bruce Fields 1677ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1678ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 167913c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1680e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 168134558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 168213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 168334558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16848fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 168523ec6965SJ. Bruce Fields } 168623ec6965SJ. Bruce Fields 1687cf8cdbe5SAndy Adamson static void 1688d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16891da177e4SLinus Torvalds { 1690ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16911da177e4SLinus Torvalds } 16921da177e4SLinus Torvalds 1693cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16941da177e4SLinus Torvalds { 1695ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1696ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 169728cf22d0STrond Myklebust encode_attrs(xdr, arg->iap, arg->label, NULL, server, 169828cf22d0STrond Myklebust server->attr_bitmask); 16991da177e4SLinus Torvalds } 17001da177e4SLinus Torvalds 1701cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 17021da177e4SLinus Torvalds { 17038687b63aSAl Viro __be32 *p; 17041da177e4SLinus Torvalds 170570019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1706cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 17071da177e4SLinus Torvalds 17083a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 17093a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 171013c65ce9SBenny Halevy p = reserve_space(xdr, 4); 171134558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 17121da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 17131da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 171413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 17153a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 17161da177e4SLinus Torvalds } 17171da177e4SLinus Torvalds 1718bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 17191da177e4SLinus Torvalds { 1720475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1721475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1722ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1723cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17241da177e4SLinus Torvalds } 17251da177e4SLinus Torvalds 17263c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17273c6b899cSAnna Schumaker struct compound_hdr *hdr) 17281da177e4SLinus Torvalds { 17298687b63aSAl Viro __be32 *p; 17301da177e4SLinus Torvalds 1731ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17329b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17331da177e4SLinus Torvalds 173413c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1735b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1736e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 173734558513SBenny Halevy *p = cpu_to_be32(args->count); 17381da177e4SLinus Torvalds 17391da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17401da177e4SLinus Torvalds } 17411da177e4SLinus Torvalds 1742cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17431da177e4SLinus Torvalds { 1744ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1745ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17461da177e4SLinus Torvalds } 17479b7b9fccSAndy Adamson 17485a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17495a5ea0d4SBryan Schumaker { 1750ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17516fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17525a5ea0d4SBryan Schumaker } 17535a5ea0d4SBryan Schumaker 175499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17559b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17567c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 1757fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args, 17587c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17597c44f1aeSWeston Andros Adamson { 17607c44f1aeSWeston Andros Adamson __be32 *p; 17617c44f1aeSWeston Andros Adamson 17627c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17637c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 176471a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17657c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 176671a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 176771a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17687c44f1aeSWeston Andros Adamson } 17697c44f1aeSWeston Andros Adamson 1770fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map) 17712031cd1aSWeston Andros Adamson { 17722031cd1aSWeston Andros Adamson unsigned int i; 17732031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17742031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17752031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17762031cd1aSWeston Andros Adamson } 17772031cd1aSWeston Andros Adamson 177899fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 1779fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args, 178099fe60d0SBenny Halevy struct compound_hdr *hdr) 178199fe60d0SBenny Halevy { 178299fe60d0SBenny Halevy __be32 *p; 1783d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1784db8ac8baSWeston Andros Adamson int len = 0; 178599fe60d0SBenny Halevy 178670019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1787fd40559cSTrond Myklebust encode_nfs4_verifier(xdr, &args->verifier); 178899fe60d0SBenny Halevy 17893a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17903a6bb738SJeff Layton args->client->cl_owner_id); 179199fe60d0SBenny Halevy 17922031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17932031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17942031cd1aSWeston Andros Adamson 17952031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17962031cd1aSWeston Andros Adamson case SP4_NONE: 17972031cd1aSWeston Andros Adamson break; 17982031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17992031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 18002031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 18012031cd1aSWeston Andros Adamson break; 18022031cd1aSWeston Andros Adamson default: 18032031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 18042031cd1aSWeston Andros Adamson break; 18052031cd1aSWeston Andros Adamson } 1806db8ac8baSWeston Andros Adamson 1807db8ac8baSWeston Andros Adamson if (send_implementation_id && 1808db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1809db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1810d751f748SJim Rees <= sizeof(impl_name) + 1) 1811db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1812db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1813db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1814db8ac8baSWeston Andros Adamson 1815db8ac8baSWeston Andros Adamson if (len > 0) { 18162031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1817db8ac8baSWeston Andros Adamson 1818db8ac8baSWeston Andros Adamson encode_string(xdr, 1819db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1820db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1821db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1822db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1823db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1824db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1825db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1826db8ac8baSWeston Andros Adamson } else 18272031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 182899fe60d0SBenny Halevy } 1829fc931582SAndy Adamson 1830fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1831fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args, 1832fc931582SAndy Adamson struct compound_hdr *hdr) 1833fc931582SAndy Adamson { 1834fc931582SAndy Adamson __be32 *p; 1835fc931582SAndy Adamson struct nfs_client *clp = args->client; 183689f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1837f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18388e0d46e1SMike Sager u32 max_resp_sz_cached; 18398e0d46e1SMike Sager 18408e0d46e1SMike Sager /* 18418e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18428e0d46e1SMike Sager * 2 is the verifier. 18438e0d46e1SMike Sager */ 184435c036efSJ. Bruce Fields max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2) 184535c036efSJ. Bruce Fields * XDR_UNIT + RPC_MAX_AUTH_SIZE; 1846fc931582SAndy Adamson 1847475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 184889f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 184979969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 185079969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1851e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1852fc931582SAndy Adamson 1853fc931582SAndy Adamson /* Fore Channel */ 1854c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1856e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18578e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1858e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1859e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1860e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1861fc931582SAndy Adamson 1862fc931582SAndy Adamson /* Back Channel */ 1863c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1864e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1865e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1866e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1867e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1868e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1869e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1870fc931582SAndy Adamson 1871e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1872e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1873e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1874fc931582SAndy Adamson 1875fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18762f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 187789f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1878e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1879e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 188034558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1881fc931582SAndy Adamson } 18820f3e66c6SAndy Adamson 18830f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 1884fcc85819SChristoph Hellwig const struct nfs4_session *session, 18850f3e66c6SAndy Adamson struct compound_hdr *hdr) 18860f3e66c6SAndy Adamson { 1887475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1888475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18890f3e66c6SAndy Adamson } 189018019753SRicardo Labiaga 189166245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 189266245539STrond Myklebust uint64_t clientid, 189366245539STrond Myklebust struct compound_hdr *hdr) 189466245539STrond Myklebust { 189566245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 189666245539STrond Myklebust encode_uint64(xdr, clientid); 189766245539STrond Myklebust } 189866245539STrond Myklebust 189918019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 1900fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args, 190118019753SRicardo Labiaga struct compound_hdr *hdr) 190218019753SRicardo Labiaga { 1903475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1904475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 190518019753SRicardo Labiaga } 190699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 190799fe60d0SBenny Halevy 19089b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 19099b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 19109b7b9fccSAndy Adamson struct compound_hdr *hdr) 19119b7b9fccSAndy Adamson { 19129b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 19132b2fa717STrond Myklebust struct nfs4_session *session; 1914fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 19152b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1916fc01cea9SAndy Adamson __be32 *p; 19179b7b9fccSAndy Adamson 19182b2fa717STrond Myklebust tp = slot->table; 19192b2fa717STrond Myklebust session = tp->session; 19203bd2384aSChuck Lever if (!session) 19213bd2384aSChuck Lever return; 1922fc01cea9SAndy Adamson 1923475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1924fc01cea9SAndy Adamson 1925fc01cea9SAndy Adamson /* 1926fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1927fc01cea9SAndy Adamson */ 1928fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1929fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1930fc01cea9SAndy Adamson __func__, 1931fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1932fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1933fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1934fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19352b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1936fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1937475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 193893f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1939e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19402b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1941e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 194234558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19439b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19449b7b9fccSAndy Adamson } 19459b7b9fccSAndy Adamson 1946b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1947b1f69b75SAndy Adamson static void 1948b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1949b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1950b1f69b75SAndy Adamson struct compound_hdr *hdr) 1951b1f69b75SAndy Adamson { 1952b1f69b75SAndy Adamson __be32 *p; 1953b1f69b75SAndy Adamson 1954475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 195584c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1956b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1957b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1958b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1959f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 196084c9dee3SChristoph Hellwig 196184c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 196284c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19634e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1964b1f69b75SAndy Adamson } 1965b1f69b75SAndy Adamson 1966b1f69b75SAndy Adamson static void 1967b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1968b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1969b1f69b75SAndy Adamson struct compound_hdr *hdr) 1970b1f69b75SAndy Adamson { 1971b1f69b75SAndy Adamson __be32 *p; 1972b1f69b75SAndy Adamson 1973475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1974475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1975b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1976b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1977b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1978b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1979b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1980b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1981ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1982475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1983b1f69b75SAndy Adamson 1984b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1985b1f69b75SAndy Adamson __func__, 1986b1f69b75SAndy Adamson args->type, 1987b1f69b75SAndy Adamson args->range.iomode, 1988b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1989b1f69b75SAndy Adamson (unsigned long)args->range.length, 1990b1f69b75SAndy Adamson args->maxcount); 1991b1f69b75SAndy Adamson } 1992863a3c6cSAndy Adamson 1993863a3c6cSAndy Adamson static int 1994863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1995ac7db726SBenny Halevy struct inode *inode, 1996fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args, 1997863a3c6cSAndy Adamson struct compound_hdr *hdr) 1998863a3c6cSAndy Adamson { 1999863a3c6cSAndy Adamson __be32 *p; 2000863a3c6cSAndy Adamson 2001863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 2002863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 2003863a3c6cSAndy Adamson 2004475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 2005475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 2006863a3c6cSAndy Adamson /* Only whole file layouts */ 2007863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 20083557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 2009ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 2010ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20112e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 2012ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 2013863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 2014863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 20152e18d4d8STrond Myklebust } else { 20162e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 20172e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 20182e18d4d8STrond Myklebust } 2019863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2020863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2021ac7db726SBenny Halevy 20225f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 202373504740STrond Myklebust if (args->layoutupdate_pages) 20245f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20255f919c9fSChristoph Hellwig args->layoutupdate_len); 2026863a3c6cSAndy Adamson 2027863a3c6cSAndy Adamson return 0; 2028863a3c6cSAndy Adamson } 2029cbe82603SBenny Halevy 2030cbe82603SBenny Halevy static void 2031cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2032cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2033cbe82603SBenny Halevy struct compound_hdr *hdr) 2034cbe82603SBenny Halevy { 2035cbe82603SBenny Halevy __be32 *p; 2036cbe82603SBenny Halevy 2037475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2038475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2039cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2040cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 204115eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2042cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2043ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 204415eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 204515eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2046cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2047ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2048cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20494d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20504d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 205194e5c571STrond Myklebust else 2052475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2053cbe82603SBenny Halevy } 2054fca78d6dSBryan Schumaker 2055fca78d6dSBryan Schumaker static int 2056fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2057fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2058fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2059fca78d6dSBryan Schumaker { 2060475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2061475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2062fca78d6dSBryan Schumaker return 0; 2063fca78d6dSBryan Schumaker } 20647d974794SBryan Schumaker 20657d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 2066fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args, 20677d974794SBryan Schumaker struct compound_hdr *hdr) 20687d974794SBryan Schumaker { 2069475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2070475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2071ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20727d974794SBryan Schumaker } 20739aeda35fSBryan Schumaker 20749aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 2075fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args, 20769aeda35fSBryan Schumaker struct compound_hdr *hdr) 20779aeda35fSBryan Schumaker { 2078ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20797c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20809aeda35fSBryan Schumaker } 2081cf805165STrond Myklebust #else 2082cf805165STrond Myklebust static inline void 2083cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2084cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2085cf805165STrond Myklebust struct compound_hdr *hdr) 2086cf805165STrond Myklebust { 2087cf805165STrond Myklebust } 208856f487f8SFred Isaman 208956f487f8SFred Isaman static void 209056f487f8SFred Isaman encode_layoutget(struct xdr_stream *xdr, 209156f487f8SFred Isaman const struct nfs4_layoutget_args *args, 209256f487f8SFred Isaman struct compound_hdr *hdr) 209356f487f8SFred Isaman { 209456f487f8SFred Isaman } 2095b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2096b1f69b75SAndy Adamson 20971da177e4SLinus Torvalds /* 20981da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20991da177e4SLinus Torvalds */ 21001da177e4SLinus Torvalds 210166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 210266cc0429SBenny Halevy { 210366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 21043bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 21053bd2384aSChuck Lever if (session) 21063bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 210766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 210866cc0429SBenny Halevy return 0; 210966cc0429SBenny Halevy } 211066cc0429SBenny Halevy 21111da177e4SLinus Torvalds /* 21121da177e4SLinus Torvalds * Encode an ACCESS request 21131da177e4SLinus Torvalds */ 21149f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 2115fcc85819SChristoph Hellwig const void *data) 21161da177e4SLinus Torvalds { 2117fcc85819SChristoph Hellwig const struct nfs4_accessargs *args = data; 21181da177e4SLinus Torvalds struct compound_hdr hdr = { 211966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21201da177e4SLinus Torvalds }; 21211da177e4SLinus Torvalds 21229f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21239f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21249f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21259f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21268bcbe7d9STrond Myklebust if (args->bitmask) 21279f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2128d017931cSAndy Adamson encode_nops(&hdr); 21291da177e4SLinus Torvalds } 21301da177e4SLinus Torvalds 21311da177e4SLinus Torvalds /* 21321da177e4SLinus Torvalds * Encode LOOKUP request 21331da177e4SLinus Torvalds */ 21349f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 2135fcc85819SChristoph Hellwig const void *data) 21361da177e4SLinus Torvalds { 2137fcc85819SChristoph Hellwig const struct nfs4_lookup_arg *args = data; 21381da177e4SLinus Torvalds struct compound_hdr hdr = { 213966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21401da177e4SLinus Torvalds }; 21411da177e4SLinus Torvalds 21429f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21439f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21449f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21459f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21469f06c719SChuck Lever encode_getfh(xdr, &hdr); 21479f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2148d017931cSAndy Adamson encode_nops(&hdr); 21491da177e4SLinus Torvalds } 21501da177e4SLinus Torvalds 21511da177e4SLinus Torvalds /* 21525b5faaf6SJeff Layton * Encode LOOKUPP request 21535b5faaf6SJeff Layton */ 21545b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr, 21555b5faaf6SJeff Layton const void *data) 21565b5faaf6SJeff Layton { 21575b5faaf6SJeff Layton const struct nfs4_lookupp_arg *args = data; 21585b5faaf6SJeff Layton struct compound_hdr hdr = { 21595b5faaf6SJeff Layton .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21605b5faaf6SJeff Layton }; 21615b5faaf6SJeff Layton 21625b5faaf6SJeff Layton encode_compound_hdr(xdr, req, &hdr); 21635b5faaf6SJeff Layton encode_sequence(xdr, &args->seq_args, &hdr); 21645b5faaf6SJeff Layton encode_putfh(xdr, args->fh, &hdr); 21655b5faaf6SJeff Layton encode_lookupp(xdr, &hdr); 21665b5faaf6SJeff Layton encode_getfh(xdr, &hdr); 21675b5faaf6SJeff Layton encode_getfattr(xdr, args->bitmask, &hdr); 21685b5faaf6SJeff Layton encode_nops(&hdr); 21695b5faaf6SJeff Layton } 21705b5faaf6SJeff Layton 21715b5faaf6SJeff Layton /* 21721da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21731da177e4SLinus Torvalds */ 21749f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21759f06c719SChuck Lever struct xdr_stream *xdr, 2176fcc85819SChristoph Hellwig const void *data) 21771da177e4SLinus Torvalds { 2178fcc85819SChristoph Hellwig const struct nfs4_lookup_root_arg *args = data; 21791da177e4SLinus Torvalds struct compound_hdr hdr = { 218066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21811da177e4SLinus Torvalds }; 21821da177e4SLinus Torvalds 21839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21849f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21859f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21869f06c719SChuck Lever encode_getfh(xdr, &hdr); 21879f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2188d017931cSAndy Adamson encode_nops(&hdr); 21891da177e4SLinus Torvalds } 21901da177e4SLinus Torvalds 21911da177e4SLinus Torvalds /* 21921da177e4SLinus Torvalds * Encode REMOVE request 21931da177e4SLinus Torvalds */ 21949f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 2195fcc85819SChristoph Hellwig const void *data) 21961da177e4SLinus Torvalds { 2197fcc85819SChristoph Hellwig const struct nfs_removeargs *args = data; 21981da177e4SLinus Torvalds struct compound_hdr hdr = { 219966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22001da177e4SLinus Torvalds }; 22011da177e4SLinus Torvalds 22029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22049f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22059f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2206d017931cSAndy Adamson encode_nops(&hdr); 22071da177e4SLinus Torvalds } 22081da177e4SLinus Torvalds 22091da177e4SLinus Torvalds /* 22101da177e4SLinus Torvalds * Encode RENAME request 22111da177e4SLinus Torvalds */ 22129f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 2213fcc85819SChristoph Hellwig const void *data) 22141da177e4SLinus Torvalds { 2215fcc85819SChristoph Hellwig const struct nfs_renameargs *args = data; 22161da177e4SLinus Torvalds struct compound_hdr hdr = { 221766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22181da177e4SLinus Torvalds }; 22191da177e4SLinus Torvalds 22209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22219f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22229f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 22239f06c719SChuck Lever encode_savefh(xdr, &hdr); 22249f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 22259f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2226d017931cSAndy Adamson encode_nops(&hdr); 22271da177e4SLinus Torvalds } 22281da177e4SLinus Torvalds 22291da177e4SLinus Torvalds /* 22301da177e4SLinus Torvalds * Encode LINK request 22311da177e4SLinus Torvalds */ 22329f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 2233fcc85819SChristoph Hellwig const void *data) 22341da177e4SLinus Torvalds { 2235fcc85819SChristoph Hellwig const struct nfs4_link_arg *args = data; 22361da177e4SLinus Torvalds struct compound_hdr hdr = { 223766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22381da177e4SLinus Torvalds }; 22391da177e4SLinus Torvalds 22409f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22419f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22429f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22439f06c719SChuck Lever encode_savefh(xdr, &hdr); 22449f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22459f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22469f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22479f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2248d017931cSAndy Adamson encode_nops(&hdr); 22491da177e4SLinus Torvalds } 22501da177e4SLinus Torvalds 22511da177e4SLinus Torvalds /* 22521da177e4SLinus Torvalds * Encode CREATE request 22531da177e4SLinus Torvalds */ 22549f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 2255fcc85819SChristoph Hellwig const void *data) 22561da177e4SLinus Torvalds { 2257fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 22581da177e4SLinus Torvalds struct compound_hdr hdr = { 225966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22601da177e4SLinus Torvalds }; 22611da177e4SLinus Torvalds 22629f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22639f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22649f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22659f06c719SChuck Lever encode_create(xdr, args, &hdr); 22669f06c719SChuck Lever encode_getfh(xdr, &hdr); 22679f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2268d017931cSAndy Adamson encode_nops(&hdr); 22691da177e4SLinus Torvalds } 22701da177e4SLinus Torvalds 22711da177e4SLinus Torvalds /* 22721da177e4SLinus Torvalds * Encode SYMLINK request 22731da177e4SLinus Torvalds */ 22749f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2275fcc85819SChristoph Hellwig const void *data) 22761da177e4SLinus Torvalds { 2277fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 2278fcc85819SChristoph Hellwig 22799f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22801da177e4SLinus Torvalds } 22811da177e4SLinus Torvalds 22821da177e4SLinus Torvalds /* 22831da177e4SLinus Torvalds * Encode GETATTR request 22841da177e4SLinus Torvalds */ 22859f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2286fcc85819SChristoph Hellwig const void *data) 22871da177e4SLinus Torvalds { 2288fcc85819SChristoph Hellwig const struct nfs4_getattr_arg *args = data; 22891da177e4SLinus Torvalds struct compound_hdr hdr = { 229066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22911da177e4SLinus Torvalds }; 22921da177e4SLinus Torvalds 22939f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22949f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22959f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22969f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2297d017931cSAndy Adamson encode_nops(&hdr); 22981da177e4SLinus Torvalds } 22991da177e4SLinus Torvalds 23001da177e4SLinus Torvalds /* 23011da177e4SLinus Torvalds * Encode a CLOSE request 23021da177e4SLinus Torvalds */ 23039f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 2304fcc85819SChristoph Hellwig const void *data) 23051da177e4SLinus Torvalds { 2306fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 23071da177e4SLinus Torvalds struct compound_hdr hdr = { 230866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23091da177e4SLinus Torvalds }; 23101da177e4SLinus Torvalds 23119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23139f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2314cf805165STrond Myklebust if (args->lr_args) 2315cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23163ecefc92STrond Myklebust if (args->bitmask != NULL) 23179f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2318d8d84983STrond Myklebust encode_close(xdr, args, &hdr); 2319d017931cSAndy Adamson encode_nops(&hdr); 23201da177e4SLinus Torvalds } 23211da177e4SLinus Torvalds 23221da177e4SLinus Torvalds /* 23231da177e4SLinus Torvalds * Encode an OPEN request 23241da177e4SLinus Torvalds */ 23259f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 2326fcc85819SChristoph Hellwig const void *data) 23271da177e4SLinus Torvalds { 2328fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23291da177e4SLinus Torvalds struct compound_hdr hdr = { 233066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23311da177e4SLinus Torvalds }; 23321da177e4SLinus Torvalds 23339f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23349f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23359f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23369f06c719SChuck Lever encode_open(xdr, args, &hdr); 23379f06c719SChuck Lever encode_getfh(xdr, &hdr); 2338ae2bb032SWeston Andros Adamson if (args->access) 23396168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 23401549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 234156f487f8SFred Isaman if (args->lg_args) { 234256f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr); 234356f487f8SFred Isaman xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 234456f487f8SFred Isaman args->lg_args->layout.pages, 234556f487f8SFred Isaman 0, args->lg_args->layout.pglen); 234656f487f8SFred Isaman } 2347d017931cSAndy Adamson encode_nops(&hdr); 23481da177e4SLinus Torvalds } 23491da177e4SLinus Torvalds 23501da177e4SLinus Torvalds /* 23511da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 23521da177e4SLinus Torvalds */ 23539f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 23549f06c719SChuck Lever struct xdr_stream *xdr, 2355fcc85819SChristoph Hellwig const void *data) 23561da177e4SLinus Torvalds { 2357fcc85819SChristoph Hellwig const struct nfs_open_confirmargs *args = data; 23581da177e4SLinus Torvalds struct compound_hdr hdr = { 2359d017931cSAndy Adamson .nops = 0, 23601da177e4SLinus Torvalds }; 23611da177e4SLinus Torvalds 23629f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23649f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2365d017931cSAndy Adamson encode_nops(&hdr); 23661da177e4SLinus Torvalds } 23671da177e4SLinus Torvalds 23681da177e4SLinus Torvalds /* 23691da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23701da177e4SLinus Torvalds */ 23719f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23729f06c719SChuck Lever struct xdr_stream *xdr, 2373fcc85819SChristoph Hellwig const void *data) 23741da177e4SLinus Torvalds { 2375fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23761da177e4SLinus Torvalds struct compound_hdr hdr = { 237766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23781da177e4SLinus Torvalds }; 23791da177e4SLinus Torvalds 23809f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23819f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23829f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23839f06c719SChuck Lever encode_open(xdr, args, &hdr); 2384ae2bb032SWeston Andros Adamson if (args->access) 23856168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2386e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 238756f487f8SFred Isaman if (args->lg_args) { 238856f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr); 238956f487f8SFred Isaman xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 239056f487f8SFred Isaman args->lg_args->layout.pages, 239156f487f8SFred Isaman 0, args->lg_args->layout.pglen); 239256f487f8SFred Isaman } 2393d017931cSAndy Adamson encode_nops(&hdr); 23941da177e4SLinus Torvalds } 23951da177e4SLinus Torvalds 23961da177e4SLinus Torvalds /* 23971da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23981da177e4SLinus Torvalds */ 23999f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 24009f06c719SChuck Lever struct xdr_stream *xdr, 2401fcc85819SChristoph Hellwig const void *data) 24021da177e4SLinus Torvalds { 2403fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 24041da177e4SLinus Torvalds struct compound_hdr hdr = { 240566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24061da177e4SLinus Torvalds }; 24071da177e4SLinus Torvalds 24089f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24099f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24109f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2411b6808145STrond Myklebust if (args->lr_args) 2412b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 24139f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2414d017931cSAndy Adamson encode_nops(&hdr); 24151da177e4SLinus Torvalds } 24161da177e4SLinus Torvalds 24171da177e4SLinus Torvalds /* 24181da177e4SLinus Torvalds * Encode a LOCK request 24191da177e4SLinus Torvalds */ 24209f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 2421fcc85819SChristoph Hellwig const void *data) 24221da177e4SLinus Torvalds { 2423fcc85819SChristoph Hellwig const struct nfs_lock_args *args = data; 24241da177e4SLinus Torvalds struct compound_hdr hdr = { 242566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24261da177e4SLinus Torvalds }; 24271da177e4SLinus Torvalds 24289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24299f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24309f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24319f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2432d017931cSAndy Adamson encode_nops(&hdr); 24331da177e4SLinus Torvalds } 24341da177e4SLinus Torvalds 24351da177e4SLinus Torvalds /* 24361da177e4SLinus Torvalds * Encode a LOCKT request 24371da177e4SLinus Torvalds */ 24389f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 2439fcc85819SChristoph Hellwig const void *data) 24401da177e4SLinus Torvalds { 2441fcc85819SChristoph Hellwig const struct nfs_lockt_args *args = data; 24421da177e4SLinus Torvalds struct compound_hdr hdr = { 244366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24441da177e4SLinus Torvalds }; 24451da177e4SLinus Torvalds 24469f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24479f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24489f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24499f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2450d017931cSAndy Adamson encode_nops(&hdr); 24511da177e4SLinus Torvalds } 24521da177e4SLinus Torvalds 24531da177e4SLinus Torvalds /* 24541da177e4SLinus Torvalds * Encode a LOCKU request 24551da177e4SLinus Torvalds */ 24569f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 2457fcc85819SChristoph Hellwig const void *data) 24581da177e4SLinus Torvalds { 2459fcc85819SChristoph Hellwig const struct nfs_locku_args *args = data; 24601da177e4SLinus Torvalds struct compound_hdr hdr = { 246166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24621da177e4SLinus Torvalds }; 24631da177e4SLinus Torvalds 24649f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24659f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24669f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24679f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2468d017931cSAndy Adamson encode_nops(&hdr); 24691da177e4SLinus Torvalds } 24701da177e4SLinus Torvalds 24719f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24729f06c719SChuck Lever struct xdr_stream *xdr, 2473fcc85819SChristoph Hellwig const void *data) 2474d3c7b7ccSTrond Myklebust { 2475fcc85819SChristoph Hellwig const struct nfs_release_lockowner_args *args = data; 2476d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2477d3c7b7ccSTrond Myklebust .minorversion = 0, 2478d3c7b7ccSTrond Myklebust }; 2479d3c7b7ccSTrond Myklebust 24809f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24819f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2482d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2483d3c7b7ccSTrond Myklebust } 2484d3c7b7ccSTrond Myklebust 24851da177e4SLinus Torvalds /* 24861da177e4SLinus Torvalds * Encode a READLINK request 24871da177e4SLinus Torvalds */ 24889f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2489fcc85819SChristoph Hellwig const void *data) 24901da177e4SLinus Torvalds { 2491fcc85819SChristoph Hellwig const struct nfs4_readlink *args = data; 24921da177e4SLinus Torvalds struct compound_hdr hdr = { 249366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24941da177e4SLinus Torvalds }; 24951da177e4SLinus Torvalds 24969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24999f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2500e3a535e1STrond Myklebust 250128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2502e3a535e1STrond Myklebust args->pgbase, args->pglen); 2503d017931cSAndy Adamson encode_nops(&hdr); 25041da177e4SLinus Torvalds } 25051da177e4SLinus Torvalds 25061da177e4SLinus Torvalds /* 25071da177e4SLinus Torvalds * Encode a READDIR request 25081da177e4SLinus Torvalds */ 25099f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 2510fcc85819SChristoph Hellwig const void *data) 25111da177e4SLinus Torvalds { 2512fcc85819SChristoph Hellwig const struct nfs4_readdir_arg *args = data; 25131da177e4SLinus Torvalds struct compound_hdr hdr = { 251466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25151da177e4SLinus Torvalds }; 25161da177e4SLinus Torvalds 25179f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25189f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25199f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25209f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2521d6ac02dfSTrond Myklebust 252228f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2523d6ac02dfSTrond Myklebust args->pgbase, args->count); 2524d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 252528f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2526d6ac02dfSTrond Myklebust args->pgbase, args->count); 2527d017931cSAndy Adamson encode_nops(&hdr); 25281da177e4SLinus Torvalds } 25291da177e4SLinus Torvalds 25301da177e4SLinus Torvalds /* 25311da177e4SLinus Torvalds * Encode a READ request 25321da177e4SLinus Torvalds */ 25339f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 2534fcc85819SChristoph Hellwig const void *data) 25351da177e4SLinus Torvalds { 2536fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 25371da177e4SLinus Torvalds struct compound_hdr hdr = { 253866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25391da177e4SLinus Torvalds }; 25401da177e4SLinus Torvalds 25419f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25429f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25439f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25449f06c719SChuck Lever encode_read(xdr, args, &hdr); 25451da177e4SLinus Torvalds 254628f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 25471da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 25484f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2549d017931cSAndy Adamson encode_nops(&hdr); 25501da177e4SLinus Torvalds } 25511da177e4SLinus Torvalds 25521da177e4SLinus Torvalds /* 25531da177e4SLinus Torvalds * Encode an SETATTR request 25541da177e4SLinus Torvalds */ 25559f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2556fcc85819SChristoph Hellwig const void *data) 25571da177e4SLinus Torvalds { 2558fcc85819SChristoph Hellwig const struct nfs_setattrargs *args = data; 25591da177e4SLinus Torvalds struct compound_hdr hdr = { 256066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25611da177e4SLinus Torvalds }; 25621da177e4SLinus Torvalds 25639f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25649f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25659f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25669f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 25679f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2568d017931cSAndy Adamson encode_nops(&hdr); 25691da177e4SLinus Torvalds } 25701da177e4SLinus Torvalds 25711da177e4SLinus Torvalds /* 2572029d105eSJ. Bruce Fields * Encode a GETACL request 2573029d105eSJ. Bruce Fields */ 25749f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2575fcc85819SChristoph Hellwig const void *data) 2576029d105eSJ. Bruce Fields { 2577fcc85819SChristoph Hellwig const struct nfs_getaclargs *args = data; 2578029d105eSJ. Bruce Fields struct compound_hdr hdr = { 257966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2580029d105eSJ. Bruce Fields }; 258137c88763STrond Myklebust const __u32 nfs4_acl_bitmap[1] = { 258237c88763STrond Myklebust [0] = FATTR4_WORD0_ACL, 258337c88763STrond Myklebust }; 258428f56694SBenny Halevy uint32_t replen; 2585029d105eSJ. Bruce Fields 25869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25889f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25896682c14bSJ. Bruce Fields replen = hdr.replen + op_decode_hdr_maxsz; 259037c88763STrond Myklebust encode_getattr(xdr, nfs4_acl_bitmap, NULL, 259137c88763STrond Myklebust ARRAY_SIZE(nfs4_acl_bitmap), &hdr); 2592cf8cdbe5SAndy Adamson 259328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 25948fbcf237SAndreas Gruenbacher args->acl_pages, 0, args->acl_len); 2595bf118a34SAndy Adamson 2596d017931cSAndy Adamson encode_nops(&hdr); 2597029d105eSJ. Bruce Fields } 2598029d105eSJ. Bruce Fields 2599029d105eSJ. Bruce Fields /* 26001da177e4SLinus Torvalds * Encode a WRITE request 26011da177e4SLinus Torvalds */ 26029f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 2603fcc85819SChristoph Hellwig const void *data) 26041da177e4SLinus Torvalds { 2605fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 26061da177e4SLinus Torvalds struct compound_hdr hdr = { 260766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26081da177e4SLinus Torvalds }; 26091da177e4SLinus Torvalds 26109f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26119f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26129f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26139f06c719SChuck Lever encode_write(xdr, args, &hdr); 26144f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 26157ffd1064SFred Isaman if (args->bitmask) 26169f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2617d017931cSAndy Adamson encode_nops(&hdr); 26181da177e4SLinus Torvalds } 26191da177e4SLinus Torvalds 26201da177e4SLinus Torvalds /* 26211da177e4SLinus Torvalds * a COMMIT request 26221da177e4SLinus Torvalds */ 26239f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 2624fcc85819SChristoph Hellwig const void *data) 26251da177e4SLinus Torvalds { 2626fcc85819SChristoph Hellwig const struct nfs_commitargs *args = data; 26271da177e4SLinus Torvalds struct compound_hdr hdr = { 262866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26291da177e4SLinus Torvalds }; 26301da177e4SLinus Torvalds 26319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26339f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26349f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2635d017931cSAndy Adamson encode_nops(&hdr); 26361da177e4SLinus Torvalds } 26371da177e4SLinus Torvalds 26381da177e4SLinus Torvalds /* 26391da177e4SLinus Torvalds * FSINFO request 26401da177e4SLinus Torvalds */ 26419f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 2642fcc85819SChristoph Hellwig const void *data) 26431da177e4SLinus Torvalds { 2644fcc85819SChristoph Hellwig const struct nfs4_fsinfo_arg *args = data; 26451da177e4SLinus Torvalds struct compound_hdr hdr = { 264666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26471da177e4SLinus Torvalds }; 26481da177e4SLinus Torvalds 26499f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26509f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26519f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26529f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2653d017931cSAndy Adamson encode_nops(&hdr); 26541da177e4SLinus Torvalds } 26551da177e4SLinus Torvalds 26561da177e4SLinus Torvalds /* 26571da177e4SLinus Torvalds * a PATHCONF request 26581da177e4SLinus Torvalds */ 26599f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 2660fcc85819SChristoph Hellwig const void *data) 26611da177e4SLinus Torvalds { 2662fcc85819SChristoph Hellwig const struct nfs4_pathconf_arg *args = data; 26631da177e4SLinus Torvalds struct compound_hdr hdr = { 266466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26651da177e4SLinus Torvalds }; 26661da177e4SLinus Torvalds 26679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26699f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 267037c88763STrond Myklebust encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask, 267137c88763STrond Myklebust ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr); 2672d017931cSAndy Adamson encode_nops(&hdr); 26731da177e4SLinus Torvalds } 26741da177e4SLinus Torvalds 26751da177e4SLinus Torvalds /* 26761da177e4SLinus Torvalds * a STATFS request 26771da177e4SLinus Torvalds */ 26789f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 2679fcc85819SChristoph Hellwig const void *data) 26801da177e4SLinus Torvalds { 2681fcc85819SChristoph Hellwig const struct nfs4_statfs_arg *args = data; 26821da177e4SLinus Torvalds struct compound_hdr hdr = { 268366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26841da177e4SLinus Torvalds }; 26851da177e4SLinus Torvalds 26869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26889f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 268937c88763STrond Myklebust encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask, 269037c88763STrond Myklebust ARRAY_SIZE(nfs4_statfs_bitmap), &hdr); 2691d017931cSAndy Adamson encode_nops(&hdr); 26921da177e4SLinus Torvalds } 26931da177e4SLinus Torvalds 26941da177e4SLinus Torvalds /* 26951da177e4SLinus Torvalds * GETATTR_BITMAP request 26961da177e4SLinus Torvalds */ 26979f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26989f06c719SChuck Lever struct xdr_stream *xdr, 2699fcc85819SChristoph Hellwig const void *data) 27001da177e4SLinus Torvalds { 2701fcc85819SChristoph Hellwig const struct nfs4_server_caps_arg *args = data; 27028c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 27031da177e4SLinus Torvalds struct compound_hdr hdr = { 270466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27051da177e4SLinus Torvalds }; 27061da177e4SLinus Torvalds 27079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27089f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27099f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 271037c88763STrond Myklebust encode_getattr(xdr, bitmask, NULL, 3, &hdr); 2711d017931cSAndy Adamson encode_nops(&hdr); 27121da177e4SLinus Torvalds } 27131da177e4SLinus Torvalds 27141da177e4SLinus Torvalds /* 27151da177e4SLinus Torvalds * a RENEW request 27161da177e4SLinus Torvalds */ 27179f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 2718fcc85819SChristoph Hellwig const void *data) 2719fcc85819SChristoph Hellwig 27201da177e4SLinus Torvalds { 2721fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 27221da177e4SLinus Torvalds struct compound_hdr hdr = { 2723d017931cSAndy Adamson .nops = 0, 27241da177e4SLinus Torvalds }; 27251da177e4SLinus Torvalds 27269f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2727bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2728d017931cSAndy Adamson encode_nops(&hdr); 27291da177e4SLinus Torvalds } 27301da177e4SLinus Torvalds 27311da177e4SLinus Torvalds /* 27321da177e4SLinus Torvalds * a SETCLIENTID request 27331da177e4SLinus Torvalds */ 27349f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 27359f06c719SChuck Lever struct xdr_stream *xdr, 2736fcc85819SChristoph Hellwig const void *data) 27371da177e4SLinus Torvalds { 2738fcc85819SChristoph Hellwig const struct nfs4_setclientid *sc = data; 27391da177e4SLinus Torvalds struct compound_hdr hdr = { 2740d017931cSAndy Adamson .nops = 0, 27411da177e4SLinus Torvalds }; 27421da177e4SLinus Torvalds 27439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27449f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2745d017931cSAndy Adamson encode_nops(&hdr); 27461da177e4SLinus Torvalds } 27471da177e4SLinus Torvalds 27481da177e4SLinus Torvalds /* 27491da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 27501da177e4SLinus Torvalds */ 27519f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 27529f06c719SChuck Lever struct xdr_stream *xdr, 2753fcc85819SChristoph Hellwig const void *data) 27541da177e4SLinus Torvalds { 2755fcc85819SChristoph Hellwig const struct nfs4_setclientid_res *arg = data; 27561da177e4SLinus Torvalds struct compound_hdr hdr = { 2757d017931cSAndy Adamson .nops = 0, 27581da177e4SLinus Torvalds }; 27591da177e4SLinus Torvalds 27609f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27619f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2762d017931cSAndy Adamson encode_nops(&hdr); 27631da177e4SLinus Torvalds } 27641da177e4SLinus Torvalds 27651da177e4SLinus Torvalds /* 27661da177e4SLinus Torvalds * DELEGRETURN request 27671da177e4SLinus Torvalds */ 27689f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 27699f06c719SChuck Lever struct xdr_stream *xdr, 2770fcc85819SChristoph Hellwig const void *data) 27711da177e4SLinus Torvalds { 2772fcc85819SChristoph Hellwig const struct nfs4_delegreturnargs *args = data; 27731da177e4SLinus Torvalds struct compound_hdr hdr = { 277466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27751da177e4SLinus Torvalds }; 27761da177e4SLinus Torvalds 27779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27789f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27799f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2780586f1c39STrond Myklebust if (args->lr_args) 2781586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 27828ac2b422STrond Myklebust if (args->bitmask) 27839f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2784e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2785d017931cSAndy Adamson encode_nops(&hdr); 27861da177e4SLinus Torvalds } 27871da177e4SLinus Torvalds 27881da177e4SLinus Torvalds /* 2789683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2790683b57b4STrond Myklebust */ 27919f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27929f06c719SChuck Lever struct xdr_stream *xdr, 2793fcc85819SChristoph Hellwig const void *data) 2794683b57b4STrond Myklebust { 2795fcc85819SChristoph Hellwig const struct nfs4_fs_locations_arg *args = data; 2796683b57b4STrond Myklebust struct compound_hdr hdr = { 279766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2798683b57b4STrond Myklebust }; 279928f56694SBenny Halevy uint32_t replen; 2800683b57b4STrond Myklebust 28019f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28029f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2803b03d735bSChuck Lever if (args->migration) { 2804b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2805b03d735bSChuck Lever replen = hdr.replen; 2806b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2807b03d735bSChuck Lever if (args->renew) 2808b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2809b03d735bSChuck Lever } else { 28109f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 28119f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2812b03d735bSChuck Lever replen = hdr.replen; 28139f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2814b03d735bSChuck Lever } 2815cf8cdbe5SAndy Adamson 2816b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 2817fcc85819SChristoph Hellwig xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2818fcc85819SChristoph Hellwig (struct page **)&args->page, 0, PAGE_SIZE); 2819d017931cSAndy Adamson encode_nops(&hdr); 2820683b57b4STrond Myklebust } 2821683b57b4STrond Myklebust 28225a5ea0d4SBryan Schumaker /* 28235a5ea0d4SBryan Schumaker * Encode SECINFO request 28245a5ea0d4SBryan Schumaker */ 28255a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 28265a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 2827fcc85819SChristoph Hellwig const void *data) 28285a5ea0d4SBryan Schumaker { 2829fcc85819SChristoph Hellwig const struct nfs4_secinfo_arg *args = data; 28305a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 28315a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28325a5ea0d4SBryan Schumaker }; 28335a5ea0d4SBryan Schumaker 28345a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 28355a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 28365a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 28375a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 28385a5ea0d4SBryan Schumaker encode_nops(&hdr); 28395a5ea0d4SBryan Schumaker } 28405a5ea0d4SBryan Schumaker 284144c99933SChuck Lever /* 284244c99933SChuck Lever * Encode FSID_PRESENT request 284344c99933SChuck Lever */ 284444c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 284544c99933SChuck Lever struct xdr_stream *xdr, 2846fcc85819SChristoph Hellwig const void *data) 284744c99933SChuck Lever { 2848fcc85819SChristoph Hellwig const struct nfs4_fsid_present_arg *args = data; 284944c99933SChuck Lever struct compound_hdr hdr = { 285044c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 285144c99933SChuck Lever }; 285244c99933SChuck Lever 285344c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 285444c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 285544c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 285644c99933SChuck Lever encode_getfh(xdr, &hdr); 285744c99933SChuck Lever if (args->renew) 285844c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 285944c99933SChuck Lever encode_nops(&hdr); 286044c99933SChuck Lever } 286144c99933SChuck Lever 286299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 286399fe60d0SBenny Halevy /* 28647c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 28657c44f1aeSWeston Andros Adamson */ 28667c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 28677c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 2868fcc85819SChristoph Hellwig const void *data) 28697c44f1aeSWeston Andros Adamson { 2870fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args = data; 28717c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 287271a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 28737c44f1aeSWeston Andros Adamson }; 28747c44f1aeSWeston Andros Adamson 28757c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 287671a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 28777c44f1aeSWeston Andros Adamson encode_nops(&hdr); 28787c44f1aeSWeston Andros Adamson } 28797c44f1aeSWeston Andros Adamson 28807c44f1aeSWeston Andros Adamson /* 288199fe60d0SBenny Halevy * EXCHANGE_ID request 288299fe60d0SBenny Halevy */ 28839f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 28849f06c719SChuck Lever struct xdr_stream *xdr, 2885fcc85819SChristoph Hellwig const void *data) 288699fe60d0SBenny Halevy { 2887fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args = data; 288899fe60d0SBenny Halevy struct compound_hdr hdr = { 2889a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 289099fe60d0SBenny Halevy }; 289199fe60d0SBenny Halevy 28929f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28939f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 289499fe60d0SBenny Halevy encode_nops(&hdr); 289599fe60d0SBenny Halevy } 28962050f0ccSAndy Adamson 28972050f0ccSAndy Adamson /* 2898fc931582SAndy Adamson * a CREATE_SESSION request 2899fc931582SAndy Adamson */ 29009f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 29019f06c719SChuck Lever struct xdr_stream *xdr, 2902fcc85819SChristoph Hellwig const void *data) 2903fc931582SAndy Adamson { 2904fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args = data; 2905fc931582SAndy Adamson struct compound_hdr hdr = { 2906a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2907fc931582SAndy Adamson }; 2908fc931582SAndy Adamson 29099f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29109f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2911fc931582SAndy Adamson encode_nops(&hdr); 2912fc931582SAndy Adamson } 2913fc931582SAndy Adamson 2914fc931582SAndy Adamson /* 29150f3e66c6SAndy Adamson * a DESTROY_SESSION request 29160f3e66c6SAndy Adamson */ 29179f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 29189f06c719SChuck Lever struct xdr_stream *xdr, 2919fcc85819SChristoph Hellwig const void *data) 29200f3e66c6SAndy Adamson { 2921fcc85819SChristoph Hellwig const struct nfs4_session *session = data; 29220f3e66c6SAndy Adamson struct compound_hdr hdr = { 2923a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 29240f3e66c6SAndy Adamson }; 29250f3e66c6SAndy Adamson 29269f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29279f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 29280f3e66c6SAndy Adamson encode_nops(&hdr); 29290f3e66c6SAndy Adamson } 29300f3e66c6SAndy Adamson 29310f3e66c6SAndy Adamson /* 293266245539STrond Myklebust * a DESTROY_CLIENTID request 293366245539STrond Myklebust */ 293466245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 293566245539STrond Myklebust struct xdr_stream *xdr, 2936fcc85819SChristoph Hellwig const void *data) 293766245539STrond Myklebust { 2938fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 293966245539STrond Myklebust struct compound_hdr hdr = { 294066245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 294166245539STrond Myklebust }; 294266245539STrond Myklebust 294366245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 294466245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 294566245539STrond Myklebust encode_nops(&hdr); 294666245539STrond Myklebust } 294766245539STrond Myklebust 294866245539STrond Myklebust /* 2949fc01cea9SAndy Adamson * a SEQUENCE request 2950fc01cea9SAndy Adamson */ 29519f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2952fcc85819SChristoph Hellwig const void *data) 2953fc01cea9SAndy Adamson { 2954fcc85819SChristoph Hellwig const struct nfs4_sequence_args *args = data; 2955fc01cea9SAndy Adamson struct compound_hdr hdr = { 2956fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2957fc01cea9SAndy Adamson }; 2958fc01cea9SAndy Adamson 29599f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29609f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2961fc01cea9SAndy Adamson encode_nops(&hdr); 2962fc01cea9SAndy Adamson } 2963fc01cea9SAndy Adamson 2964fc01cea9SAndy Adamson /* 29652050f0ccSAndy Adamson * a GET_LEASE_TIME request 29662050f0ccSAndy Adamson */ 29679f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 29689f06c719SChuck Lever struct xdr_stream *xdr, 2969fcc85819SChristoph Hellwig const void *data) 29702050f0ccSAndy Adamson { 2971fcc85819SChristoph Hellwig const struct nfs4_get_lease_time_args *args = data; 29722050f0ccSAndy Adamson struct compound_hdr hdr = { 29732050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 29742050f0ccSAndy Adamson }; 2975dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 29762050f0ccSAndy Adamson 29779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29789f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 29799f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 29809f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 29812050f0ccSAndy Adamson encode_nops(&hdr); 29822050f0ccSAndy Adamson } 298318019753SRicardo Labiaga 298418019753SRicardo Labiaga /* 298518019753SRicardo Labiaga * a RECLAIM_COMPLETE request 298618019753SRicardo Labiaga */ 29879f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 29889f06c719SChuck Lever struct xdr_stream *xdr, 2989fcc85819SChristoph Hellwig const void *data) 299018019753SRicardo Labiaga { 2991fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args = data; 299218019753SRicardo Labiaga struct compound_hdr hdr = { 299318019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 299418019753SRicardo Labiaga }; 299518019753SRicardo Labiaga 29969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29989f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 299918019753SRicardo Labiaga encode_nops(&hdr); 300018019753SRicardo Labiaga } 300118019753SRicardo Labiaga 3002b1f69b75SAndy Adamson /* 3003b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 3004b1f69b75SAndy Adamson */ 30059f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 30069f06c719SChuck Lever struct xdr_stream *xdr, 3007fcc85819SChristoph Hellwig const void *data) 3008b1f69b75SAndy Adamson { 3009fcc85819SChristoph Hellwig const struct nfs4_getdeviceinfo_args *args = data; 3010b1f69b75SAndy Adamson struct compound_hdr hdr = { 3011b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3012b1f69b75SAndy Adamson }; 3013b1f69b75SAndy Adamson 30149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 30159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 30169f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 3017b1f69b75SAndy Adamson 3018b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 3019b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 3020b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 3021b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 3022b1f69b75SAndy Adamson args->pdev->pglen); 3023b1f69b75SAndy Adamson 3024b1f69b75SAndy Adamson encode_nops(&hdr); 3025b1f69b75SAndy Adamson } 3026b1f69b75SAndy Adamson 3027b1f69b75SAndy Adamson /* 3028b1f69b75SAndy Adamson * Encode LAYOUTGET request 3029b1f69b75SAndy Adamson */ 30309f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 30319f06c719SChuck Lever struct xdr_stream *xdr, 3032fcc85819SChristoph Hellwig const void *data) 3033b1f69b75SAndy Adamson { 3034fcc85819SChristoph Hellwig const struct nfs4_layoutget_args *args = data; 3035b1f69b75SAndy Adamson struct compound_hdr hdr = { 3036b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3037b1f69b75SAndy Adamson }; 3038b1f69b75SAndy Adamson 30399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 30409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 30419f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 30429f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 304335124a09SWeston Andros Adamson 304435124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 304535124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 304635124a09SWeston Andros Adamson 3047b1f69b75SAndy Adamson encode_nops(&hdr); 3048b1f69b75SAndy Adamson } 3049863a3c6cSAndy Adamson 3050863a3c6cSAndy Adamson /* 3051863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 3052863a3c6cSAndy Adamson */ 3053cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 3054863a3c6cSAndy Adamson struct xdr_stream *xdr, 3055fcc85819SChristoph Hellwig const void *priv) 3056863a3c6cSAndy Adamson { 3057fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args = priv; 3058ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 3059ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 3060863a3c6cSAndy Adamson struct compound_hdr hdr = { 3061863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3062863a3c6cSAndy Adamson }; 3063863a3c6cSAndy Adamson 3064863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 3065863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 3066863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3067ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 3068863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 3069863a3c6cSAndy Adamson encode_nops(&hdr); 3070cbe82603SBenny Halevy } 3071cbe82603SBenny Halevy 3072cbe82603SBenny Halevy /* 3073cbe82603SBenny Halevy * Encode LAYOUTRETURN request 3074cbe82603SBenny Halevy */ 3075cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 3076cbe82603SBenny Halevy struct xdr_stream *xdr, 3077fcc85819SChristoph Hellwig const void *data) 3078cbe82603SBenny Halevy { 3079fcc85819SChristoph Hellwig const struct nfs4_layoutreturn_args *args = data; 3080cbe82603SBenny Halevy struct compound_hdr hdr = { 3081cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3082cbe82603SBenny Halevy }; 3083cbe82603SBenny Halevy 3084cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 3085cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 3086cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3087cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 3088cbe82603SBenny Halevy encode_nops(&hdr); 3089863a3c6cSAndy Adamson } 3090fca78d6dSBryan Schumaker 3091fca78d6dSBryan Schumaker /* 3092fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 3093fca78d6dSBryan Schumaker */ 3094fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 3095fca78d6dSBryan Schumaker struct xdr_stream *xdr, 3096fcc85819SChristoph Hellwig const void *data) 3097fca78d6dSBryan Schumaker { 3098fcc85819SChristoph Hellwig const struct nfs41_secinfo_no_name_args *args = data; 3099fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3100fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3101fca78d6dSBryan Schumaker }; 3102fca78d6dSBryan Schumaker 3103fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3104fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3105fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3106fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3107fca78d6dSBryan Schumaker encode_nops(&hdr); 3108fca78d6dSBryan Schumaker } 31097d974794SBryan Schumaker 31107d974794SBryan Schumaker /* 31117d974794SBryan Schumaker * Encode TEST_STATEID request 31127d974794SBryan Schumaker */ 31137d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 31147d974794SBryan Schumaker struct xdr_stream *xdr, 3115fcc85819SChristoph Hellwig const void *data) 31167d974794SBryan Schumaker { 3117fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args = data; 31187d974794SBryan Schumaker struct compound_hdr hdr = { 31197d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 31207d974794SBryan Schumaker }; 31217d974794SBryan Schumaker 31227d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31237d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31247d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 31257d974794SBryan Schumaker encode_nops(&hdr); 31267d974794SBryan Schumaker } 31279aeda35fSBryan Schumaker 31289aeda35fSBryan Schumaker /* 31299aeda35fSBryan Schumaker * Encode FREE_STATEID request 31309aeda35fSBryan Schumaker */ 31319aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 31329aeda35fSBryan Schumaker struct xdr_stream *xdr, 3133fcc85819SChristoph Hellwig const void *data) 31349aeda35fSBryan Schumaker { 3135fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args = data; 31369aeda35fSBryan Schumaker struct compound_hdr hdr = { 31379aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 31389aeda35fSBryan Schumaker }; 31399aeda35fSBryan Schumaker 31409aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31419aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31429aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 31439aeda35fSBryan Schumaker encode_nops(&hdr); 31449aeda35fSBryan Schumaker } 314599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 314699fe60d0SBenny Halevy 3147686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3148686841b3SBenny Halevy { 3149686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3150686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3151686841b3SBenny Halevy func, xdr->end - xdr->p); 3152686841b3SBenny Halevy } 31531da177e4SLinus Torvalds 3154683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 31551da177e4SLinus Torvalds { 31566da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, 31576da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT); 31586da59ce2STrond Myklebust if (unlikely(ret < 0)) { 31596da59ce2STrond Myklebust if (ret == -EBADMSG) 3160c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3161c0eae66eSBenny Halevy return -EIO; 31621da177e4SLinus Torvalds } 31636da59ce2STrond Myklebust *len = ret; 31646da59ce2STrond Myklebust return 0; 31656da59ce2STrond Myklebust } 31661da177e4SLinus Torvalds 31671da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 31681da177e4SLinus Torvalds { 31698687b63aSAl Viro __be32 *p; 31701da177e4SLinus Torvalds 3171c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3172c0eae66eSBenny Halevy if (unlikely(!p)) 3173c0eae66eSBenny Halevy goto out_overflow; 31746f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3175cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 31761da177e4SLinus Torvalds 3177c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3178c0eae66eSBenny Halevy if (unlikely(!p)) 3179c0eae66eSBenny Halevy goto out_overflow; 31801da177e4SLinus Torvalds hdr->tag = (char *)p; 31811da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3182cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3183aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3184aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 31851da177e4SLinus Torvalds return 0; 3186c0eae66eSBenny Halevy out_overflow: 3187c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3188c0eae66eSBenny Halevy return -EIO; 31891da177e4SLinus Torvalds } 31901da177e4SLinus Torvalds 3191c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3192c7848f69STrond Myklebust int *nfs_retval) 31931da177e4SLinus Torvalds { 31948687b63aSAl Viro __be32 *p; 31951da177e4SLinus Torvalds uint32_t opnum; 31961da177e4SLinus Torvalds int32_t nfserr; 31971da177e4SLinus Torvalds 3198c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3199c0eae66eSBenny Halevy if (unlikely(!p)) 3200c0eae66eSBenny Halevy goto out_overflow; 32016f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3202c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3203c7848f69STrond Myklebust goto out_bad_operation; 3204c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3205c7848f69STrond Myklebust if (nfserr == NFS_OK) 3206c7848f69STrond Myklebust *nfs_retval = 0; 3207c7848f69STrond Myklebust else 3208c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3209c7848f69STrond Myklebust return true; 3210c7848f69STrond Myklebust out_bad_operation: 3211fe82a183SChuck Lever dprintk("nfs: Server returned operation" 32121da177e4SLinus Torvalds " %d but we issued a request for %d\n", 32131da177e4SLinus Torvalds opnum, expected); 3214c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3215c7848f69STrond Myklebust return false; 3216c0eae66eSBenny Halevy out_overflow: 3217c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3218c7848f69STrond Myklebust *nfs_retval = -EIO; 3219c7848f69STrond Myklebust return false; 3220c7848f69STrond Myklebust } 3221c7848f69STrond Myklebust 3222c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3223c7848f69STrond Myklebust { 3224c7848f69STrond Myklebust int retval; 3225c7848f69STrond Myklebust 3226c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3227c7848f69STrond Myklebust return retval; 32281da177e4SLinus Torvalds } 32291da177e4SLinus Torvalds 32301da177e4SLinus Torvalds /* Dummy routine */ 32311bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace) 32321da177e4SLinus Torvalds { 32338687b63aSAl Viro __be32 *p; 3234683b57b4STrond Myklebust unsigned int strlen; 32351da177e4SLinus Torvalds char *str; 32361da177e4SLinus Torvalds 3237c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3238c0eae66eSBenny Halevy if (likely(p)) 32391da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3240c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3241c0eae66eSBenny Halevy return -EIO; 32421da177e4SLinus Torvalds } 32431da177e4SLinus Torvalds 324437c88763STrond Myklebust static ssize_t 324537c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz) 32461da177e4SLinus Torvalds { 324737c88763STrond Myklebust ssize_t ret; 32481da177e4SLinus Torvalds 324937c88763STrond Myklebust ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz); 325037c88763STrond Myklebust if (likely(ret >= 0)) 325137c88763STrond Myklebust return ret; 325237c88763STrond Myklebust if (ret == -EMSGSIZE) 325337c88763STrond Myklebust return sz; 3254c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3255c0eae66eSBenny Halevy return -EIO; 32561da177e4SLinus Torvalds } 32571da177e4SLinus Torvalds 325837c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 325937c88763STrond Myklebust { 326037c88763STrond Myklebust ssize_t ret; 326137c88763STrond Myklebust ret = decode_bitmap4(xdr, bitmap, 3); 326237c88763STrond Myklebust return ret < 0 ? ret : 0; 326337c88763STrond Myklebust } 326437c88763STrond Myklebust 3265256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 32661da177e4SLinus Torvalds { 32678687b63aSAl Viro __be32 *p; 32681da177e4SLinus Torvalds 3269c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3270c0eae66eSBenny Halevy if (unlikely(!p)) 3271c0eae66eSBenny Halevy goto out_overflow; 3272cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3273256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 32741da177e4SLinus Torvalds return 0; 3275c0eae66eSBenny Halevy out_overflow: 3276c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3277c0eae66eSBenny Halevy return -EIO; 32781da177e4SLinus Torvalds } 32791da177e4SLinus Torvalds 32801da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 32811da177e4SLinus Torvalds { 32821da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 32833388bff5SRoman Borisov int ret; 32843388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 32853388bff5SRoman Borisov if (unlikely(ret < 0)) 32863388bff5SRoman Borisov return ret; 32871da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 32881da177e4SLinus Torvalds } else 3289dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3290dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3291dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 32921da177e4SLinus Torvalds return 0; 32931da177e4SLinus Torvalds } 32941da177e4SLinus Torvalds 32951da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32961da177e4SLinus Torvalds { 32978687b63aSAl Viro __be32 *p; 3298409924e4STrond Myklebust int ret = 0; 32991da177e4SLinus Torvalds 33001da177e4SLinus Torvalds *type = 0; 33011da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 33021da177e4SLinus Torvalds return -EIO; 33031da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3304c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3305c0eae66eSBenny Halevy if (unlikely(!p)) 3306c0eae66eSBenny Halevy goto out_overflow; 3307cccddf4fSBenny Halevy *type = be32_to_cpup(p); 33081da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 33093110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 33101da177e4SLinus Torvalds return -EIO; 33111da177e4SLinus Torvalds } 33121da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3313409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 33141da177e4SLinus Torvalds } 3315bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3316409924e4STrond Myklebust return ret; 3317c0eae66eSBenny Halevy out_overflow: 3318c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3319c0eae66eSBenny Halevy return -EIO; 33201da177e4SLinus Torvalds } 33211da177e4SLinus Torvalds 3322264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3323264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3324264e6351SChuck Lever { 3325264e6351SChuck Lever __be32 *p; 3326264e6351SChuck Lever 3327264e6351SChuck Lever *type = 0; 3328264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3329264e6351SChuck Lever return -EIO; 3330264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3331264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3332264e6351SChuck Lever if (unlikely(!p)) 3333264e6351SChuck Lever goto out_overflow; 3334264e6351SChuck Lever *type = be32_to_cpup(p); 3335264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3336264e6351SChuck Lever } 3337264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3338264e6351SChuck Lever return 0; 3339264e6351SChuck Lever out_overflow: 3340264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3341264e6351SChuck Lever return -EIO; 3342264e6351SChuck Lever } 3343264e6351SChuck Lever 33441da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 33451da177e4SLinus Torvalds { 33468687b63aSAl Viro __be32 *p; 3347409924e4STrond Myklebust int ret = 0; 33481da177e4SLinus Torvalds 33491da177e4SLinus Torvalds *change = 0; 33501da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 33511da177e4SLinus Torvalds return -EIO; 33521da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3353c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3354c0eae66eSBenny Halevy if (unlikely(!p)) 3355c0eae66eSBenny Halevy goto out_overflow; 3356cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 33571da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3358409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 33591da177e4SLinus Torvalds } 33603110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 33611da177e4SLinus Torvalds (unsigned long long)*change); 3362409924e4STrond Myklebust return ret; 3363c0eae66eSBenny Halevy out_overflow: 3364c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3365c0eae66eSBenny Halevy return -EIO; 33661da177e4SLinus Torvalds } 33671da177e4SLinus Torvalds 33681da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 33691da177e4SLinus Torvalds { 33708687b63aSAl Viro __be32 *p; 3371409924e4STrond Myklebust int ret = 0; 33721da177e4SLinus Torvalds 33731da177e4SLinus Torvalds *size = 0; 33741da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 33751da177e4SLinus Torvalds return -EIO; 33761da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3377c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3378c0eae66eSBenny Halevy if (unlikely(!p)) 3379c0eae66eSBenny Halevy goto out_overflow; 3380cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 33811da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3382409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 33831da177e4SLinus Torvalds } 33843110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3385409924e4STrond Myklebust return ret; 3386c0eae66eSBenny Halevy out_overflow: 3387c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3388c0eae66eSBenny Halevy return -EIO; 33891da177e4SLinus Torvalds } 33901da177e4SLinus Torvalds 33911da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33921da177e4SLinus Torvalds { 33938687b63aSAl Viro __be32 *p; 33941da177e4SLinus Torvalds 33951da177e4SLinus Torvalds *res = 0; 33961da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33971da177e4SLinus Torvalds return -EIO; 33981da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3399c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3400c0eae66eSBenny Halevy if (unlikely(!p)) 3401c0eae66eSBenny Halevy goto out_overflow; 3402cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34031da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 34041da177e4SLinus Torvalds } 34053110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 34061da177e4SLinus Torvalds return 0; 3407c0eae66eSBenny Halevy out_overflow: 3408c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3409c0eae66eSBenny Halevy return -EIO; 34101da177e4SLinus Torvalds } 34111da177e4SLinus Torvalds 34121da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34131da177e4SLinus Torvalds { 34148687b63aSAl Viro __be32 *p; 34151da177e4SLinus Torvalds 34161da177e4SLinus Torvalds *res = 0; 34171da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 34181da177e4SLinus Torvalds return -EIO; 34191da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3420c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3421c0eae66eSBenny Halevy if (unlikely(!p)) 3422c0eae66eSBenny Halevy goto out_overflow; 3423cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34241da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 34251da177e4SLinus Torvalds } 34263110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 34271da177e4SLinus Torvalds return 0; 3428c0eae66eSBenny Halevy out_overflow: 3429c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3430c0eae66eSBenny Halevy return -EIO; 34311da177e4SLinus Torvalds } 34321da177e4SLinus Torvalds 34338b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 34341da177e4SLinus Torvalds { 34358687b63aSAl Viro __be32 *p; 3436409924e4STrond Myklebust int ret = 0; 34371da177e4SLinus Torvalds 34381da177e4SLinus Torvalds fsid->major = 0; 34391da177e4SLinus Torvalds fsid->minor = 0; 34401da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 34411da177e4SLinus Torvalds return -EIO; 34421da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3443c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3444c0eae66eSBenny Halevy if (unlikely(!p)) 3445c0eae66eSBenny Halevy goto out_overflow; 34463ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3447cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 34481da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3449409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 34501da177e4SLinus Torvalds } 34513110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 34521da177e4SLinus Torvalds (unsigned long long)fsid->major, 34531da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3454409924e4STrond Myklebust return ret; 3455c0eae66eSBenny Halevy out_overflow: 3456c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3457c0eae66eSBenny Halevy return -EIO; 34581da177e4SLinus Torvalds } 34591da177e4SLinus Torvalds 34601da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34611da177e4SLinus Torvalds { 34628687b63aSAl Viro __be32 *p; 34631da177e4SLinus Torvalds 34641da177e4SLinus Torvalds *res = 60; 34651da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 34661da177e4SLinus Torvalds return -EIO; 34671da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3468c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3469c0eae66eSBenny Halevy if (unlikely(!p)) 3470c0eae66eSBenny Halevy goto out_overflow; 3471cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 34731da177e4SLinus Torvalds } 34743110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 34751da177e4SLinus Torvalds return 0; 3476c0eae66eSBenny Halevy out_overflow: 3477c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3478c0eae66eSBenny Halevy return -EIO; 34791da177e4SLinus Torvalds } 34801da177e4SLinus Torvalds 3481ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3482ae42c70aSBryan Schumaker { 3483ae42c70aSBryan Schumaker __be32 *p; 3484ae42c70aSBryan Schumaker 3485ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3486ae42c70aSBryan Schumaker return -EIO; 3487ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3488ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3489ae42c70aSBryan Schumaker if (unlikely(!p)) 3490ae42c70aSBryan Schumaker goto out_overflow; 3491ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3492ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3493ae42c70aSBryan Schumaker } 3494ae42c70aSBryan Schumaker return 0; 3495ae42c70aSBryan Schumaker out_overflow: 3496ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3497ae42c70aSBryan Schumaker return -EIO; 3498ae42c70aSBryan Schumaker } 3499ae42c70aSBryan Schumaker 35008c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 35018c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 35028c61282fSKinglong Mee { 35038c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 35048c61282fSKinglong Mee int ret; 35058c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 35068c61282fSKinglong Mee if (unlikely(ret < 0)) 35078c61282fSKinglong Mee return ret; 35088c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 35098c61282fSKinglong Mee } else 35108c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 35118c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 35128c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 35138c61282fSKinglong Mee return 0; 35148c61282fSKinglong Mee } 35158c61282fSKinglong Mee 3516ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3517ae42c70aSBryan Schumaker { 3518ae42c70aSBryan Schumaker __be32 *p; 3519ae42c70aSBryan Schumaker int len; 3520ae42c70aSBryan Schumaker 35217ad07353STrond Myklebust if (fh != NULL) 3522ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3523ae42c70aSBryan Schumaker 3524ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3525ae42c70aSBryan Schumaker return -EIO; 3526ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3527ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3528ae42c70aSBryan Schumaker if (unlikely(!p)) 3529ae42c70aSBryan Schumaker goto out_overflow; 3530ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3531ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3532ae42c70aSBryan Schumaker return -EIO; 3533ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3534ae42c70aSBryan Schumaker if (unlikely(!p)) 3535ae42c70aSBryan Schumaker goto out_overflow; 35367ad07353STrond Myklebust if (fh != NULL) { 3537ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 35387ad07353STrond Myklebust fh->size = len; 35397ad07353STrond Myklebust } 3540ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3541ae42c70aSBryan Schumaker } 3542ae42c70aSBryan Schumaker return 0; 3543ae42c70aSBryan Schumaker out_overflow: 3544ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3545ae42c70aSBryan Schumaker return -EIO; 3546ae42c70aSBryan Schumaker } 3547ae42c70aSBryan Schumaker 35481da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 35491da177e4SLinus Torvalds { 35508687b63aSAl Viro __be32 *p; 35511da177e4SLinus Torvalds 3552a1800acaSMalahal Naineni *res = 0; 35531da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 35541da177e4SLinus Torvalds return -EIO; 35551da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3556c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3557c0eae66eSBenny Halevy if (unlikely(!p)) 3558c0eae66eSBenny Halevy goto out_overflow; 3559cccddf4fSBenny Halevy *res = be32_to_cpup(p); 35601da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 35611da177e4SLinus Torvalds } 35623110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 35631da177e4SLinus Torvalds return 0; 3564c0eae66eSBenny Halevy out_overflow: 3565c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3566c0eae66eSBenny Halevy return -EIO; 35671da177e4SLinus Torvalds } 35681da177e4SLinus Torvalds 35691da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 35701da177e4SLinus Torvalds { 35718687b63aSAl Viro __be32 *p; 3572409924e4STrond Myklebust int ret = 0; 35731da177e4SLinus Torvalds 35741da177e4SLinus Torvalds *fileid = 0; 35751da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 35761da177e4SLinus Torvalds return -EIO; 35771da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3578c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3579c0eae66eSBenny Halevy if (unlikely(!p)) 3580c0eae66eSBenny Halevy goto out_overflow; 3581cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 35821da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3583409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 35841da177e4SLinus Torvalds } 35853110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3586409924e4STrond Myklebust return ret; 3587c0eae66eSBenny Halevy out_overflow: 3588c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3589c0eae66eSBenny Halevy return -EIO; 35901da177e4SLinus Torvalds } 35911da177e4SLinus Torvalds 359299baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 359399baf625SManoj Naik { 35948687b63aSAl Viro __be32 *p; 3595409924e4STrond Myklebust int ret = 0; 359699baf625SManoj Naik 359799baf625SManoj Naik *fileid = 0; 359899baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 359999baf625SManoj Naik return -EIO; 360099baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3601c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3602c0eae66eSBenny Halevy if (unlikely(!p)) 3603c0eae66eSBenny Halevy goto out_overflow; 3604cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 360599baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 360628331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 360799baf625SManoj Naik } 36083110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3609409924e4STrond Myklebust return ret; 3610c0eae66eSBenny Halevy out_overflow: 3611c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3612c0eae66eSBenny Halevy return -EIO; 361399baf625SManoj Naik } 361499baf625SManoj Naik 36151da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36161da177e4SLinus Torvalds { 36178687b63aSAl Viro __be32 *p; 36181da177e4SLinus Torvalds int status = 0; 36191da177e4SLinus Torvalds 36201da177e4SLinus Torvalds *res = 0; 36211da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 36221da177e4SLinus Torvalds return -EIO; 36231da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3624c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3625c0eae66eSBenny Halevy if (unlikely(!p)) 3626c0eae66eSBenny Halevy goto out_overflow; 3627cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36281da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 36291da177e4SLinus Torvalds } 36303110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 36311da177e4SLinus Torvalds return status; 3632c0eae66eSBenny Halevy out_overflow: 3633c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3634c0eae66eSBenny Halevy return -EIO; 36351da177e4SLinus Torvalds } 36361da177e4SLinus Torvalds 36371da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36381da177e4SLinus Torvalds { 36398687b63aSAl Viro __be32 *p; 36401da177e4SLinus Torvalds int status = 0; 36411da177e4SLinus Torvalds 36421da177e4SLinus Torvalds *res = 0; 36431da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 36441da177e4SLinus Torvalds return -EIO; 36451da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3646c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3647c0eae66eSBenny Halevy if (unlikely(!p)) 3648c0eae66eSBenny Halevy goto out_overflow; 3649cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36501da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 36511da177e4SLinus Torvalds } 36523110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 36531da177e4SLinus Torvalds return status; 3654c0eae66eSBenny Halevy out_overflow: 3655c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3656c0eae66eSBenny Halevy return -EIO; 36571da177e4SLinus Torvalds } 36581da177e4SLinus Torvalds 36591da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36601da177e4SLinus Torvalds { 36618687b63aSAl Viro __be32 *p; 36621da177e4SLinus Torvalds int status = 0; 36631da177e4SLinus Torvalds 36641da177e4SLinus Torvalds *res = 0; 36651da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 36661da177e4SLinus Torvalds return -EIO; 36671da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3668c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3669c0eae66eSBenny Halevy if (unlikely(!p)) 3670c0eae66eSBenny Halevy goto out_overflow; 3671cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 36731da177e4SLinus Torvalds } 36743110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 36751da177e4SLinus Torvalds return status; 3676c0eae66eSBenny Halevy out_overflow: 3677c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3678c0eae66eSBenny Halevy return -EIO; 36791da177e4SLinus Torvalds } 36801da177e4SLinus Torvalds 36817aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 36827aaa0b3bSManoj Naik { 3683464ad6b1SChuck Lever u32 n; 36848687b63aSAl Viro __be32 *p; 36857aaa0b3bSManoj Naik int status = 0; 36867aaa0b3bSManoj Naik 3687c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3688c0eae66eSBenny Halevy if (unlikely(!p)) 3689c0eae66eSBenny Halevy goto out_overflow; 3690cccddf4fSBenny Halevy n = be32_to_cpup(p); 369133a43f28SAndy Adamson if (n == 0) 369233a43f28SAndy Adamson goto root_path; 369302a2976cSChuck Lever dprintk("pathname4: "); 3694809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3695809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3696809b426cSTrond Myklebust goto out_eio; 3697809b426cSTrond Myklebust } 3698809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36997aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 37007aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 37017aaa0b3bSManoj Naik if (unlikely(status != 0)) 37027aaa0b3bSManoj Naik goto out_eio; 370395a13f7bSTrond Myklebust ifdebug (XDR) 370402a2976cSChuck Lever pr_cont("%s%.*s ", 370502a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 370602a2976cSChuck Lever component->len, component->data); 37077aaa0b3bSManoj Naik } 37087aaa0b3bSManoj Naik out: 37097aaa0b3bSManoj Naik return status; 371033a43f28SAndy Adamson root_path: 371133a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 371233a43f28SAndy Adamson path->ncomponents = 1; 371333a43f28SAndy Adamson path->components[0].len=0; 371433a43f28SAndy Adamson path->components[0].data=NULL; 371502a2976cSChuck Lever dprintk("pathname4: /\n"); 371633a43f28SAndy Adamson goto out; 37177aaa0b3bSManoj Naik out_eio: 37187aaa0b3bSManoj Naik dprintk(" status %d", status); 37197aaa0b3bSManoj Naik status = -EIO; 37207aaa0b3bSManoj Naik goto out; 3721c0eae66eSBenny Halevy out_overflow: 3722c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3723c0eae66eSBenny Halevy return -EIO; 37247aaa0b3bSManoj Naik } 37257aaa0b3bSManoj Naik 37267aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3727683b57b4STrond Myklebust { 3728683b57b4STrond Myklebust int n; 37298687b63aSAl Viro __be32 *p; 3730683b57b4STrond Myklebust int status = -EIO; 3731683b57b4STrond Myklebust 3732683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3733683b57b4STrond Myklebust goto out; 3734683b57b4STrond Myklebust status = 0; 3735683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3736683b57b4STrond Myklebust goto out; 3737f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 37388b7e3f49STrond Myklebust status = -EIO; 37398b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 37408b7e3f49STrond Myklebust if (unlikely(res == NULL)) 37418b7e3f49STrond Myklebust goto out; 374202a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 37437aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3744683b57b4STrond Myklebust if (unlikely(status != 0)) 3745683b57b4STrond Myklebust goto out; 3746c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3747c0eae66eSBenny Halevy if (unlikely(!p)) 3748c0eae66eSBenny Halevy goto out_overflow; 3749cccddf4fSBenny Halevy n = be32_to_cpup(p); 3750683b57b4STrond Myklebust if (n <= 0) 3751683b57b4STrond Myklebust goto out_eio; 3752809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3753464ad6b1SChuck Lever u32 m; 3754809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3755683b57b4STrond Myklebust 3756809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3757809b426cSTrond Myklebust break; 3758809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3759c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3760c0eae66eSBenny Halevy if (unlikely(!p)) 3761c0eae66eSBenny Halevy goto out_overflow; 3762cccddf4fSBenny Halevy m = be32_to_cpup(p); 37637aaa0b3bSManoj Naik 376402a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3765809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3766809b426cSTrond Myklebust struct nfs4_string *server; 3767809b426cSTrond Myklebust 3768809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3769464ad6b1SChuck Lever unsigned int i; 3770464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3771464ad6b1SChuck Lever "returned for location %u\n", 37723110ff80SHarvey Harrison __func__, 3773464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3774464ad6b1SChuck Lever m, res->nlocations); 37757aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 37762e42c3e2STrond Myklebust unsigned int len; 37777aaa0b3bSManoj Naik char *data; 37787aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3779683b57b4STrond Myklebust if (unlikely(status != 0)) 3780683b57b4STrond Myklebust goto out_eio; 37817aaa0b3bSManoj Naik } 3782809b426cSTrond Myklebust break; 37837aaa0b3bSManoj Naik } 3784809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3785809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3786809b426cSTrond Myklebust if (unlikely(status != 0)) 3787809b426cSTrond Myklebust goto out_eio; 3788809b426cSTrond Myklebust dprintk("%s ", server->data); 37897aaa0b3bSManoj Naik } 37907aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 37917aaa0b3bSManoj Naik if (unlikely(status != 0)) 37927aaa0b3bSManoj Naik goto out_eio; 3793683b57b4STrond Myklebust } 3794409924e4STrond Myklebust if (res->nlocations != 0) 379581934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3796683b57b4STrond Myklebust out: 37973110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3798683b57b4STrond Myklebust return status; 3799c0eae66eSBenny Halevy out_overflow: 3800c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3801683b57b4STrond Myklebust out_eio: 3802683b57b4STrond Myklebust status = -EIO; 3803683b57b4STrond Myklebust goto out; 3804683b57b4STrond Myklebust } 3805683b57b4STrond Myklebust 38061da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 38071da177e4SLinus Torvalds { 38088687b63aSAl Viro __be32 *p; 38091da177e4SLinus Torvalds int status = 0; 38101da177e4SLinus Torvalds 38111da177e4SLinus Torvalds *res = 0; 38121da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 38131da177e4SLinus Torvalds return -EIO; 38141da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3815c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3816c0eae66eSBenny Halevy if (unlikely(!p)) 3817c0eae66eSBenny Halevy goto out_overflow; 3818cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 38191da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 38201da177e4SLinus Torvalds } 38213110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 38221da177e4SLinus Torvalds return status; 3823c0eae66eSBenny Halevy out_overflow: 3824c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3825c0eae66eSBenny Halevy return -EIO; 38261da177e4SLinus Torvalds } 38271da177e4SLinus Torvalds 38281da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 38291da177e4SLinus Torvalds { 38308687b63aSAl Viro __be32 *p; 38311da177e4SLinus Torvalds int status = 0; 38321da177e4SLinus Torvalds 38331da177e4SLinus Torvalds *maxlink = 1; 38341da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 38351da177e4SLinus Torvalds return -EIO; 38361da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3837c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3838c0eae66eSBenny Halevy if (unlikely(!p)) 3839c0eae66eSBenny Halevy goto out_overflow; 3840cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 38411da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 38421da177e4SLinus Torvalds } 38433110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 38441da177e4SLinus Torvalds return status; 3845c0eae66eSBenny Halevy out_overflow: 3846c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3847c0eae66eSBenny Halevy return -EIO; 38481da177e4SLinus Torvalds } 38491da177e4SLinus Torvalds 38501da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 38511da177e4SLinus Torvalds { 38528687b63aSAl Viro __be32 *p; 38531da177e4SLinus Torvalds int status = 0; 38541da177e4SLinus Torvalds 38551da177e4SLinus Torvalds *maxname = 1024; 38561da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 38571da177e4SLinus Torvalds return -EIO; 38581da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3859c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3860c0eae66eSBenny Halevy if (unlikely(!p)) 3861c0eae66eSBenny Halevy goto out_overflow; 3862cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 38631da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 38641da177e4SLinus Torvalds } 38653110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 38661da177e4SLinus Torvalds return status; 3867c0eae66eSBenny Halevy out_overflow: 3868c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3869c0eae66eSBenny Halevy return -EIO; 38701da177e4SLinus Torvalds } 38711da177e4SLinus Torvalds 38721da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38731da177e4SLinus Torvalds { 38748687b63aSAl Viro __be32 *p; 38751da177e4SLinus Torvalds int status = 0; 38761da177e4SLinus Torvalds 38771da177e4SLinus Torvalds *res = 1024; 38781da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 38791da177e4SLinus Torvalds return -EIO; 38801da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 38811da177e4SLinus Torvalds uint64_t maxread; 3882c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3883c0eae66eSBenny Halevy if (unlikely(!p)) 3884c0eae66eSBenny Halevy goto out_overflow; 3885cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 38861da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 38871da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 38881da177e4SLinus Torvalds *res = (uint32_t)maxread; 38891da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 38901da177e4SLinus Torvalds } 38913110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 38921da177e4SLinus Torvalds return status; 3893c0eae66eSBenny Halevy out_overflow: 3894c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3895c0eae66eSBenny Halevy return -EIO; 38961da177e4SLinus Torvalds } 38971da177e4SLinus Torvalds 38981da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38991da177e4SLinus Torvalds { 39008687b63aSAl Viro __be32 *p; 39011da177e4SLinus Torvalds int status = 0; 39021da177e4SLinus Torvalds 39031da177e4SLinus Torvalds *res = 1024; 39041da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 39051da177e4SLinus Torvalds return -EIO; 39061da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 39071da177e4SLinus Torvalds uint64_t maxwrite; 3908c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3909c0eae66eSBenny Halevy if (unlikely(!p)) 3910c0eae66eSBenny Halevy goto out_overflow; 3911cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 39121da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 39131da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 39141da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 39151da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 39161da177e4SLinus Torvalds } 39173110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 39181da177e4SLinus Torvalds return status; 3919c0eae66eSBenny Halevy out_overflow: 3920c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3921c0eae66eSBenny Halevy return -EIO; 39221da177e4SLinus Torvalds } 39231da177e4SLinus Torvalds 3924bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 39251da177e4SLinus Torvalds { 3926bca79478STrond Myklebust uint32_t tmp; 39278687b63aSAl Viro __be32 *p; 3928409924e4STrond Myklebust int ret = 0; 39291da177e4SLinus Torvalds 39301da177e4SLinus Torvalds *mode = 0; 39311da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 39321da177e4SLinus Torvalds return -EIO; 39331da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3934c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3935c0eae66eSBenny Halevy if (unlikely(!p)) 3936c0eae66eSBenny Halevy goto out_overflow; 3937cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3938bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 39391da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3940409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 39411da177e4SLinus Torvalds } 39423110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3943409924e4STrond Myklebust return ret; 3944c0eae66eSBenny Halevy out_overflow: 3945c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3946c0eae66eSBenny Halevy return -EIO; 39471da177e4SLinus Torvalds } 39481da177e4SLinus Torvalds 39491da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 39501da177e4SLinus Torvalds { 39518687b63aSAl Viro __be32 *p; 3952409924e4STrond Myklebust int ret = 0; 39531da177e4SLinus Torvalds 39541da177e4SLinus Torvalds *nlink = 1; 39551da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 39561da177e4SLinus Torvalds return -EIO; 39571da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3958c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3959c0eae66eSBenny Halevy if (unlikely(!p)) 3960c0eae66eSBenny Halevy goto out_overflow; 3961cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 39621da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3963409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 39641da177e4SLinus Torvalds } 39653110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3966409924e4STrond Myklebust return ret; 3967c0eae66eSBenny Halevy out_overflow: 3968c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3969c0eae66eSBenny Halevy return -EIO; 39701da177e4SLinus Torvalds } 39711da177e4SLinus Torvalds 3972686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr, 3973686a816aSTrond Myklebust struct nfs4_string *name, gfp_t gfp_flags) 3974686a816aSTrond Myklebust { 3975686a816aSTrond Myklebust ssize_t ret; 3976686a816aSTrond Myklebust 3977686a816aSTrond Myklebust ret = xdr_stream_decode_string_dup(xdr, &name->data, 3978686a816aSTrond Myklebust XDR_MAX_NETOBJ, gfp_flags); 3979686a816aSTrond Myklebust name->len = 0; 3980686a816aSTrond Myklebust if (ret > 0) 3981686a816aSTrond Myklebust name->len = ret; 3982686a816aSTrond Myklebust return ret; 3983686a816aSTrond Myklebust } 3984686a816aSTrond Myklebust 398580e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3986e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 39876926afd1STrond Myklebust struct nfs4_string *owner_name) 39881da177e4SLinus Torvalds { 3989686a816aSTrond Myklebust ssize_t len; 3990686a816aSTrond Myklebust char *p; 39911da177e4SLinus Torvalds 3992e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 39931da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 39941da177e4SLinus Torvalds return -EIO; 3995686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER)) 3996686a816aSTrond Myklebust return 0; 39971da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 3998686a816aSTrond Myklebust 3999686a816aSTrond Myklebust if (owner_name != NULL) { 4000e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, owner_name, GFP_NOIO); 4001686a816aSTrond Myklebust if (len <= 0) 4002686a816aSTrond Myklebust goto out; 4003686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, owner_name->data); 4004686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER_NAME; 4005686a816aSTrond Myklebust } else { 4006686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 4007686a816aSTrond Myklebust XDR_MAX_NETOBJ); 4008686a816aSTrond Myklebust if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0) 4009686a816aSTrond Myklebust goto out; 4010e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 4011686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER; 4012686a816aSTrond Myklebust } 4013686a816aSTrond Myklebust out: 4014686a816aSTrond Myklebust if (len != -EBADMSG) 4015686a816aSTrond Myklebust return 0; 4016c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4017c0eae66eSBenny Halevy return -EIO; 40181da177e4SLinus Torvalds } 40191da177e4SLinus Torvalds 402080e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 4021e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 40226926afd1STrond Myklebust struct nfs4_string *group_name) 40231da177e4SLinus Torvalds { 4024686a816aSTrond Myklebust ssize_t len; 4025686a816aSTrond Myklebust char *p; 40261da177e4SLinus Torvalds 4027e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 40281da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 40291da177e4SLinus Torvalds return -EIO; 4030686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) 4031686a816aSTrond Myklebust return 0; 40321da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 4033686a816aSTrond Myklebust 4034686a816aSTrond Myklebust if (group_name != NULL) { 4035e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, group_name, GFP_NOIO); 4036686a816aSTrond Myklebust if (len <= 0) 4037686a816aSTrond Myklebust goto out; 4038686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, group_name->data); 40396f1f6220SKinglong Mee return NFS_ATTR_FATTR_GROUP_NAME; 4040686a816aSTrond Myklebust } else { 4041686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 4042686a816aSTrond Myklebust XDR_MAX_NETOBJ); 4043686a816aSTrond Myklebust if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0) 4044686a816aSTrond Myklebust goto out; 4045e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 4046686a816aSTrond Myklebust return NFS_ATTR_FATTR_GROUP; 4047686a816aSTrond Myklebust } 4048686a816aSTrond Myklebust out: 4049686a816aSTrond Myklebust if (len != -EBADMSG) 4050686a816aSTrond Myklebust return 0; 4051c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4052c0eae66eSBenny Halevy return -EIO; 40531da177e4SLinus Torvalds } 40541da177e4SLinus Torvalds 40551da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 40561da177e4SLinus Torvalds { 40578687b63aSAl Viro uint32_t major = 0, minor = 0; 40588687b63aSAl Viro __be32 *p; 4059409924e4STrond Myklebust int ret = 0; 40601da177e4SLinus Torvalds 40611da177e4SLinus Torvalds *rdev = MKDEV(0,0); 40621da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 40631da177e4SLinus Torvalds return -EIO; 40641da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 40651da177e4SLinus Torvalds dev_t tmp; 40661da177e4SLinus Torvalds 4067c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4068c0eae66eSBenny Halevy if (unlikely(!p)) 4069c0eae66eSBenny Halevy goto out_overflow; 40706f723f77SBenny Halevy major = be32_to_cpup(p++); 4071cccddf4fSBenny Halevy minor = be32_to_cpup(p); 40721da177e4SLinus Torvalds tmp = MKDEV(major, minor); 40731da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 40741da177e4SLinus Torvalds *rdev = tmp; 40751da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 4076409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 40771da177e4SLinus Torvalds } 40783110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 4079409924e4STrond Myklebust return ret; 4080c0eae66eSBenny Halevy out_overflow: 4081c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4082c0eae66eSBenny Halevy return -EIO; 40831da177e4SLinus Torvalds } 40841da177e4SLinus Torvalds 40851da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40861da177e4SLinus Torvalds { 40878687b63aSAl Viro __be32 *p; 40881da177e4SLinus Torvalds int status = 0; 40891da177e4SLinus Torvalds 40901da177e4SLinus Torvalds *res = 0; 40911da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 40921da177e4SLinus Torvalds return -EIO; 40931da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 4094c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4095c0eae66eSBenny Halevy if (unlikely(!p)) 4096c0eae66eSBenny Halevy goto out_overflow; 4097cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40981da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40991da177e4SLinus Torvalds } 41003110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 41011da177e4SLinus Torvalds return status; 4102c0eae66eSBenny Halevy out_overflow: 4103c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4104c0eae66eSBenny Halevy return -EIO; 41051da177e4SLinus Torvalds } 41061da177e4SLinus Torvalds 41071da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 41081da177e4SLinus Torvalds { 41098687b63aSAl Viro __be32 *p; 41101da177e4SLinus Torvalds int status = 0; 41111da177e4SLinus Torvalds 41121da177e4SLinus Torvalds *res = 0; 41131da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 41141da177e4SLinus Torvalds return -EIO; 41151da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4116c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4117c0eae66eSBenny Halevy if (unlikely(!p)) 4118c0eae66eSBenny Halevy goto out_overflow; 4119cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 41201da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 41211da177e4SLinus Torvalds } 41223110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 41231da177e4SLinus Torvalds return status; 4124c0eae66eSBenny Halevy out_overflow: 4125c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4126c0eae66eSBenny Halevy return -EIO; 41271da177e4SLinus Torvalds } 41281da177e4SLinus Torvalds 41291da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 41301da177e4SLinus Torvalds { 41318687b63aSAl Viro __be32 *p; 41321da177e4SLinus Torvalds int status = 0; 41331da177e4SLinus Torvalds 41341da177e4SLinus Torvalds *res = 0; 41351da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 41361da177e4SLinus Torvalds return -EIO; 41371da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4138c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4139c0eae66eSBenny Halevy if (unlikely(!p)) 4140c0eae66eSBenny Halevy goto out_overflow; 4141cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 41421da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 41431da177e4SLinus Torvalds } 41443110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 41451da177e4SLinus Torvalds return status; 4146c0eae66eSBenny Halevy out_overflow: 4147c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4148c0eae66eSBenny Halevy return -EIO; 41491da177e4SLinus Torvalds } 41501da177e4SLinus Torvalds 41511da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 41521da177e4SLinus Torvalds { 41538687b63aSAl Viro __be32 *p; 4154409924e4STrond Myklebust int ret = 0; 41551da177e4SLinus Torvalds 41561da177e4SLinus Torvalds *used = 0; 41571da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 41581da177e4SLinus Torvalds return -EIO; 41591da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4160c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4161c0eae66eSBenny Halevy if (unlikely(!p)) 4162c0eae66eSBenny Halevy goto out_overflow; 4163cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 41641da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4165409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 41661da177e4SLinus Torvalds } 41673110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 41681da177e4SLinus Torvalds (unsigned long long)*used); 4169409924e4STrond Myklebust return ret; 4170c0eae66eSBenny Halevy out_overflow: 4171c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4172c0eae66eSBenny Halevy return -EIO; 41731da177e4SLinus Torvalds } 41741da177e4SLinus Torvalds 417536b3743fSTrond Myklebust static __be32 * 417636b3743fSTrond Myklebust xdr_decode_nfstime4(__be32 *p, struct timespec *t) 417736b3743fSTrond Myklebust { 417836b3743fSTrond Myklebust __u64 sec; 417936b3743fSTrond Myklebust 418036b3743fSTrond Myklebust p = xdr_decode_hyper(p, &sec); 418136b3743fSTrond Myklebust t-> tv_sec = (time_t)sec; 418236b3743fSTrond Myklebust t->tv_nsec = be32_to_cpup(p++); 418336b3743fSTrond Myklebust return p; 418436b3743fSTrond Myklebust } 418536b3743fSTrond Myklebust 41861da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 41871da177e4SLinus Torvalds { 41888687b63aSAl Viro __be32 *p; 41891da177e4SLinus Torvalds 419036b3743fSTrond Myklebust p = xdr_inline_decode(xdr, nfstime4_maxsz << 2); 4191c0eae66eSBenny Halevy if (unlikely(!p)) 4192c0eae66eSBenny Halevy goto out_overflow; 419336b3743fSTrond Myklebust xdr_decode_nfstime4(p, time); 41941da177e4SLinus Torvalds return 0; 4195c0eae66eSBenny Halevy out_overflow: 4196c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4197c0eae66eSBenny Halevy return -EIO; 41981da177e4SLinus Torvalds } 41991da177e4SLinus Torvalds 42001da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42011da177e4SLinus Torvalds { 42021da177e4SLinus Torvalds int status = 0; 42031da177e4SLinus Torvalds 42041da177e4SLinus Torvalds time->tv_sec = 0; 42051da177e4SLinus Torvalds time->tv_nsec = 0; 42061da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 42071da177e4SLinus Torvalds return -EIO; 42081da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 42091da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4210409924e4STrond Myklebust if (status == 0) 4211409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 42121da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 42131da177e4SLinus Torvalds } 42143110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 42151da177e4SLinus Torvalds return status; 42161da177e4SLinus Torvalds } 42171da177e4SLinus Torvalds 42181da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42191da177e4SLinus Torvalds { 42201da177e4SLinus Torvalds int status = 0; 42211da177e4SLinus Torvalds 42221da177e4SLinus Torvalds time->tv_sec = 0; 42231da177e4SLinus Torvalds time->tv_nsec = 0; 42241da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 42251da177e4SLinus Torvalds return -EIO; 42261da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 42271da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4228409924e4STrond Myklebust if (status == 0) 4229409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 42301da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 42311da177e4SLinus Torvalds } 42323110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 42331da177e4SLinus Torvalds return status; 42341da177e4SLinus Torvalds } 42351da177e4SLinus Torvalds 423655b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 423755b6e774SRicardo Labiaga struct timespec *time) 423855b6e774SRicardo Labiaga { 423955b6e774SRicardo Labiaga int status = 0; 424055b6e774SRicardo Labiaga 424155b6e774SRicardo Labiaga time->tv_sec = 0; 424255b6e774SRicardo Labiaga time->tv_nsec = 0; 424355b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 424455b6e774SRicardo Labiaga return -EIO; 424555b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 424655b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 424755b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 424855b6e774SRicardo Labiaga } 424955b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 425055b6e774SRicardo Labiaga (long)time->tv_nsec); 425155b6e774SRicardo Labiaga return status; 425255b6e774SRicardo Labiaga } 425355b6e774SRicardo Labiaga 4254aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4255aa9c2669SDavid Quigley struct nfs4_label *label) 4256aa9c2669SDavid Quigley { 4257aa9c2669SDavid Quigley uint32_t pi = 0; 4258aa9c2669SDavid Quigley uint32_t lfs = 0; 4259aa9c2669SDavid Quigley __u32 len; 4260aa9c2669SDavid Quigley __be32 *p; 4261aa9c2669SDavid Quigley int status = 0; 4262aa9c2669SDavid Quigley 4263aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4264aa9c2669SDavid Quigley return -EIO; 4265aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4266aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4267aa9c2669SDavid Quigley if (unlikely(!p)) 4268aa9c2669SDavid Quigley goto out_overflow; 4269aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4270aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4271aa9c2669SDavid Quigley if (unlikely(!p)) 4272aa9c2669SDavid Quigley goto out_overflow; 4273aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4274aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4275aa9c2669SDavid Quigley if (unlikely(!p)) 4276aa9c2669SDavid Quigley goto out_overflow; 4277aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4278aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4279aa9c2669SDavid Quigley if (unlikely(!p)) 4280aa9c2669SDavid Quigley goto out_overflow; 4281aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4282aa9c2669SDavid Quigley if (label) { 4283aa9c2669SDavid Quigley memcpy(label->label, p, len); 4284aa9c2669SDavid Quigley label->len = len; 4285aa9c2669SDavid Quigley label->pi = pi; 4286aa9c2669SDavid Quigley label->lfs = lfs; 4287aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4288aa9c2669SDavid Quigley } 4289aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4290aa9c2669SDavid Quigley } else 4291aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4292aa9c2669SDavid Quigley __func__, len); 4293aa9c2669SDavid Quigley } 4294aa9c2669SDavid Quigley if (label && label->label) 4295aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4296aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4297aa9c2669SDavid Quigley return status; 4298aa9c2669SDavid Quigley 4299aa9c2669SDavid Quigley out_overflow: 4300aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4301aa9c2669SDavid Quigley return -EIO; 4302aa9c2669SDavid Quigley } 4303aa9c2669SDavid Quigley 43041da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 43051da177e4SLinus Torvalds { 43061da177e4SLinus Torvalds int status = 0; 43071da177e4SLinus Torvalds 43081da177e4SLinus Torvalds time->tv_sec = 0; 43091da177e4SLinus Torvalds time->tv_nsec = 0; 43101da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 43111da177e4SLinus Torvalds return -EIO; 43121da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 43131da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4314409924e4STrond Myklebust if (status == 0) 4315409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 43161da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 43171da177e4SLinus Torvalds } 43183110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 43191da177e4SLinus Torvalds return status; 43201da177e4SLinus Torvalds } 43211da177e4SLinus Torvalds 4322256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 43231da177e4SLinus Torvalds { 43241da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4325256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 43261da177e4SLinus Torvalds 43271da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4328fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4329fe82a183SChuck Lever "%u %c %u\n", 43303110ff80SHarvey Harrison __func__, 43311da177e4SLinus Torvalds attrwords << 2, 43321da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 43331da177e4SLinus Torvalds nwords << 2); 43341da177e4SLinus Torvalds return -EIO; 43351da177e4SLinus Torvalds } 43361da177e4SLinus Torvalds return 0; 43371da177e4SLinus Torvalds } 43381da177e4SLinus Torvalds 43391da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43401da177e4SLinus Torvalds { 43418687b63aSAl Viro __be32 *p; 43421da177e4SLinus Torvalds 4343c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4344c0eae66eSBenny Halevy if (unlikely(!p)) 4345c0eae66eSBenny Halevy goto out_overflow; 43466f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 43473ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4348cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 43491da177e4SLinus Torvalds return 0; 4350c0eae66eSBenny Halevy out_overflow: 4351c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4352c0eae66eSBenny Halevy return -EIO; 43531da177e4SLinus Torvalds } 43541da177e4SLinus Torvalds 43556168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 43561da177e4SLinus Torvalds { 43578687b63aSAl Viro __be32 *p; 43581da177e4SLinus Torvalds uint32_t supp, acc; 43591da177e4SLinus Torvalds int status; 43601da177e4SLinus Torvalds 43611da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 43621da177e4SLinus Torvalds if (status) 43631da177e4SLinus Torvalds return status; 4364c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4365c0eae66eSBenny Halevy if (unlikely(!p)) 4366c0eae66eSBenny Halevy goto out_overflow; 43676f723f77SBenny Halevy supp = be32_to_cpup(p++); 4368cccddf4fSBenny Halevy acc = be32_to_cpup(p); 43696168f62cSWeston Andros Adamson *supported = supp; 43706168f62cSWeston Andros Adamson *access = acc; 43711da177e4SLinus Torvalds return 0; 4372c0eae66eSBenny Halevy out_overflow: 4373c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4374c0eae66eSBenny Halevy return -EIO; 43751da177e4SLinus Torvalds } 43761da177e4SLinus Torvalds 437707d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 43781da177e4SLinus Torvalds { 4379ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); 4380ab6e9aafSTrond Myklebust if (unlikely(ret < 0)) { 438107d30434SBenny Halevy print_overflow_msg(__func__, xdr); 438207d30434SBenny Halevy return -EIO; 438307d30434SBenny Halevy } 4384ab6e9aafSTrond Myklebust return 0; 4385ab6e9aafSTrond Myklebust } 438607d30434SBenny Halevy 438707d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 438807d30434SBenny Halevy { 43892d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 43901da177e4SLinus Torvalds } 43911da177e4SLinus Torvalds 439293b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 439393b717fdSTrond Myklebust { 439493b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 439593b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 439693b717fdSTrond Myklebust } 439793b717fdSTrond Myklebust 439893b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 439993b717fdSTrond Myklebust { 440093b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 440193b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 440293b717fdSTrond Myklebust } 440393b717fdSTrond Myklebust 440493b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 440593b717fdSTrond Myklebust { 440693b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 440793b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 440893b717fdSTrond Myklebust } 440993b717fdSTrond Myklebust 4410fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 4411fcd8843cSTrond Myklebust { 4412fcd8843cSTrond Myklebust nfs4_stateid dummy; 4413fcd8843cSTrond Myklebust 4414fcd8843cSTrond Myklebust nfs4_stateid_copy(stateid, &invalid_stateid); 4415fcd8843cSTrond Myklebust return decode_stateid(xdr, &dummy); 4416fcd8843cSTrond Myklebust } 4417fcd8843cSTrond Myklebust 44181da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 44191da177e4SLinus Torvalds { 44201da177e4SLinus Torvalds int status; 44211da177e4SLinus Torvalds 44221da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4423c1d51931STrond Myklebust if (status != -EIO) 4424c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 442507d30434SBenny Halevy if (!status) 4426fcd8843cSTrond Myklebust status = decode_invalid_stateid(xdr, &res->stateid); 44271da177e4SLinus Torvalds return status; 44281da177e4SLinus Torvalds } 44291da177e4SLinus Torvalds 4430db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4431db942bbdSBenny Halevy { 4432cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 44331da177e4SLinus Torvalds } 44341da177e4SLinus Torvalds 44352f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 44362f2c63bcSTrond Myklebust { 44372f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 44382f2c63bcSTrond Myklebust } 44392f2c63bcSTrond Myklebust 44400b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 44411da177e4SLinus Torvalds { 44421da177e4SLinus Torvalds int status; 44431da177e4SLinus Torvalds 44441da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4445db942bbdSBenny Halevy if (!status) 44462f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 44471da177e4SLinus Torvalds return status; 44481da177e4SLinus Torvalds } 44491da177e4SLinus Torvalds 44501da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 44511da177e4SLinus Torvalds { 44528687b63aSAl Viro __be32 *p; 44531da177e4SLinus Torvalds uint32_t bmlen; 44541da177e4SLinus Torvalds int status; 44551da177e4SLinus Torvalds 44561da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 44571da177e4SLinus Torvalds if (status) 44581da177e4SLinus Torvalds return status; 44591da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 44601da177e4SLinus Torvalds return status; 4461c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4462c0eae66eSBenny Halevy if (unlikely(!p)) 4463c0eae66eSBenny Halevy goto out_overflow; 4464cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4465c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4466c0eae66eSBenny Halevy if (likely(p)) 44671da177e4SLinus Torvalds return 0; 4468c0eae66eSBenny Halevy out_overflow: 4469c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4470c0eae66eSBenny Halevy return -EIO; 44711da177e4SLinus Torvalds } 44721da177e4SLinus Torvalds 44731da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 44741da177e4SLinus Torvalds { 4475256e48bbSTrond Myklebust unsigned int savep; 4476dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44771da177e4SLinus Torvalds int status; 44781da177e4SLinus Torvalds 44791da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44801da177e4SLinus Torvalds goto xdr_error; 44811da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44821da177e4SLinus Torvalds goto xdr_error; 44831da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44841da177e4SLinus Torvalds goto xdr_error; 44851da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 44861da177e4SLinus Torvalds goto xdr_error; 4487264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4488264e6351SChuck Lever &res->fh_expire_type)) != 0) 4489264e6351SChuck Lever goto xdr_error; 44901da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 44911da177e4SLinus Torvalds goto xdr_error; 44921da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 44931da177e4SLinus Torvalds goto xdr_error; 44941da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 44951da177e4SLinus Torvalds goto xdr_error; 44968c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 44978c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 44988c61282fSKinglong Mee goto xdr_error; 44991da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45001da177e4SLinus Torvalds xdr_error: 45013110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45021da177e4SLinus Torvalds return status; 45031da177e4SLinus Torvalds } 45041da177e4SLinus Torvalds 45051da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 45061da177e4SLinus Torvalds { 4507256e48bbSTrond Myklebust unsigned int savep; 4508dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 45091da177e4SLinus Torvalds int status; 45101da177e4SLinus Torvalds 45111da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45121da177e4SLinus Torvalds goto xdr_error; 45131da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45141da177e4SLinus Torvalds goto xdr_error; 45151da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45161da177e4SLinus Torvalds goto xdr_error; 45171da177e4SLinus Torvalds 45181da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 45191da177e4SLinus Torvalds goto xdr_error; 45201da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 45211da177e4SLinus Torvalds goto xdr_error; 45221da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 45231da177e4SLinus Torvalds goto xdr_error; 45241ca843a2SAndreas Gruenbacher 45251ca843a2SAndreas Gruenbacher status = -EIO; 45261ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 45271ca843a2SAndreas Gruenbacher goto xdr_error; 45281ca843a2SAndreas Gruenbacher 45291da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 45301da177e4SLinus Torvalds goto xdr_error; 45311da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 45321da177e4SLinus Torvalds goto xdr_error; 45331da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 45341da177e4SLinus Torvalds goto xdr_error; 45351da177e4SLinus Torvalds 45361da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45371da177e4SLinus Torvalds xdr_error: 45383110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45391da177e4SLinus Torvalds return status; 45401da177e4SLinus Torvalds } 45411da177e4SLinus Torvalds 45421da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 45431da177e4SLinus Torvalds { 4544256e48bbSTrond Myklebust unsigned int savep; 4545dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 45461da177e4SLinus Torvalds int status; 45471da177e4SLinus Torvalds 45481da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 45491da177e4SLinus Torvalds goto xdr_error; 45501da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 45511da177e4SLinus Torvalds goto xdr_error; 45521da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 45531da177e4SLinus Torvalds goto xdr_error; 45541da177e4SLinus Torvalds 45551da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 45561da177e4SLinus Torvalds goto xdr_error; 45571da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 45581da177e4SLinus Torvalds goto xdr_error; 45591da177e4SLinus Torvalds 45601da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 45611da177e4SLinus Torvalds xdr_error: 45623110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 45631da177e4SLinus Torvalds return status; 45641da177e4SLinus Torvalds } 45651da177e4SLinus Torvalds 456688034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 456788034c3dSAndy Adamson uint32_t *bitmap, 456888034c3dSAndy Adamson uint64_t *res, 456988034c3dSAndy Adamson uint32_t hint_bit) 457088034c3dSAndy Adamson { 457188034c3dSAndy Adamson __be32 *p; 457288034c3dSAndy Adamson 457388034c3dSAndy Adamson *res = 0; 457488034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 457588034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 457688034c3dSAndy Adamson if (unlikely(!p)) 457788034c3dSAndy Adamson goto out_overflow; 457888034c3dSAndy Adamson xdr_decode_hyper(p, res); 457988034c3dSAndy Adamson } 458088034c3dSAndy Adamson return 0; 458188034c3dSAndy Adamson out_overflow: 458288034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 458388034c3dSAndy Adamson return -EIO; 458488034c3dSAndy Adamson } 458588034c3dSAndy Adamson 458688034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 458788034c3dSAndy Adamson struct nfs4_threshold *res) 458888034c3dSAndy Adamson { 4589256e48bbSTrond Myklebust __be32 *p; 4590256e48bbSTrond Myklebust unsigned int savep; 459188034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 459288034c3dSAndy Adamson int status; 459388034c3dSAndy Adamson 459488034c3dSAndy Adamson /* layout type */ 459588034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 459688034c3dSAndy Adamson if (unlikely(!p)) { 459788034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 459888034c3dSAndy Adamson return -EIO; 459988034c3dSAndy Adamson } 460088034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 460188034c3dSAndy Adamson 460288034c3dSAndy Adamson /* thi_hintset bitmap */ 460388034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 460488034c3dSAndy Adamson if (status < 0) 460588034c3dSAndy Adamson goto xdr_error; 460688034c3dSAndy Adamson 460788034c3dSAndy Adamson /* thi_hintlist length */ 460888034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 460988034c3dSAndy Adamson if (status < 0) 461088034c3dSAndy Adamson goto xdr_error; 461188034c3dSAndy Adamson /* thi_hintlist */ 461288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 461388034c3dSAndy Adamson if (status < 0) 461488034c3dSAndy Adamson goto xdr_error; 461588034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 461688034c3dSAndy Adamson if (status < 0) 461788034c3dSAndy Adamson goto xdr_error; 461888034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 461988034c3dSAndy Adamson THRESHOLD_RD_IO); 462088034c3dSAndy Adamson if (status < 0) 462188034c3dSAndy Adamson goto xdr_error; 462288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 462388034c3dSAndy Adamson THRESHOLD_WR_IO); 462488034c3dSAndy Adamson if (status < 0) 462588034c3dSAndy Adamson goto xdr_error; 462688034c3dSAndy Adamson 462788034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 462888034c3dSAndy Adamson res->bm = bitmap[0]; 462988034c3dSAndy Adamson 463088034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 463188034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 463288034c3dSAndy Adamson res->wr_io_sz); 463388034c3dSAndy Adamson xdr_error: 463488034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 463588034c3dSAndy Adamson return status; 463688034c3dSAndy Adamson } 463788034c3dSAndy Adamson 463888034c3dSAndy Adamson /* 463988034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 464088034c3dSAndy Adamson */ 464188034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 464288034c3dSAndy Adamson uint32_t *bitmap, 464388034c3dSAndy Adamson struct nfs4_threshold *res) 464488034c3dSAndy Adamson { 464588034c3dSAndy Adamson __be32 *p; 464688034c3dSAndy Adamson int status = 0; 464788034c3dSAndy Adamson uint32_t num; 464888034c3dSAndy Adamson 464988034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 465088034c3dSAndy Adamson return -EIO; 4651029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 46521549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 46531549210fSTrond Myklebust if (unlikely(res == NULL)) 46541549210fSTrond Myklebust return -EREMOTEIO; 465588034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 465688034c3dSAndy Adamson if (unlikely(!p)) 465788034c3dSAndy Adamson goto out_overflow; 465888034c3dSAndy Adamson num = be32_to_cpup(p); 465988034c3dSAndy Adamson if (num == 0) 466088034c3dSAndy Adamson return 0; 466188034c3dSAndy Adamson if (num > 1) 466288034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 466388034c3dSAndy Adamson "drivers per filesystem not supported\n", 466488034c3dSAndy Adamson __func__); 466588034c3dSAndy Adamson 466688034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4667029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 466888034c3dSAndy Adamson } 466988034c3dSAndy Adamson return status; 467088034c3dSAndy Adamson out_overflow: 467188034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 467288034c3dSAndy Adamson return -EIO; 467388034c3dSAndy Adamson } 467488034c3dSAndy Adamson 4675ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4676ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4677aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 46786926afd1STrond Myklebust const struct nfs_server *server) 46791da177e4SLinus Torvalds { 4680bca79478STrond Myklebust int status; 4681bca79478STrond Myklebust umode_t fmode = 0; 4682ae42c70aSBryan Schumaker uint32_t type; 4683ee7b75fcSTrond Myklebust int32_t err; 46841da177e4SLinus Torvalds 4685f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4686f26c7a78STrond Myklebust if (status < 0) 46871da177e4SLinus Torvalds goto xdr_error; 4688409924e4STrond Myklebust fattr->mode = 0; 4689409924e4STrond Myklebust if (status != 0) { 4690409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4691409924e4STrond Myklebust fattr->valid |= status; 4692409924e4STrond Myklebust } 46931da177e4SLinus Torvalds 4694f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4695f26c7a78STrond Myklebust if (status < 0) 46961da177e4SLinus Torvalds goto xdr_error; 4697409924e4STrond Myklebust fattr->valid |= status; 4698f26c7a78STrond Myklebust 4699f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4700f26c7a78STrond Myklebust if (status < 0) 47011da177e4SLinus Torvalds goto xdr_error; 4702409924e4STrond Myklebust fattr->valid |= status; 4703f26c7a78STrond Myklebust 4704f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4705f26c7a78STrond Myklebust if (status < 0) 47061da177e4SLinus Torvalds goto xdr_error; 4707409924e4STrond Myklebust fattr->valid |= status; 4708f26c7a78STrond Myklebust 4709ee7b75fcSTrond Myklebust err = 0; 4710ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4711ae42c70aSBryan Schumaker if (status < 0) 4712ae42c70aSBryan Schumaker goto xdr_error; 4713ae42c70aSBryan Schumaker 4714ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4715ae42c70aSBryan Schumaker if (status < 0) 4716ae42c70aSBryan Schumaker goto xdr_error; 4717ae42c70aSBryan Schumaker 4718f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4719f26c7a78STrond Myklebust if (status < 0) 47201da177e4SLinus Torvalds goto xdr_error; 4721409924e4STrond Myklebust fattr->valid |= status; 4722f26c7a78STrond Myklebust 47238b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4724f26c7a78STrond Myklebust if (status < 0) 4725683b57b4STrond Myklebust goto xdr_error; 4726409924e4STrond Myklebust fattr->valid |= status; 4727f26c7a78STrond Myklebust 47281ca843a2SAndreas Gruenbacher status = -EIO; 47291ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 47301ca843a2SAndreas Gruenbacher goto xdr_error; 47311ca843a2SAndreas Gruenbacher 4732f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4733f26c7a78STrond Myklebust if (status < 0) 47341da177e4SLinus Torvalds goto xdr_error; 4735409924e4STrond Myklebust if (status != 0) { 47361da177e4SLinus Torvalds fattr->mode |= fmode; 4737409924e4STrond Myklebust fattr->valid |= status; 4738409924e4STrond Myklebust } 4739f26c7a78STrond Myklebust 4740f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4741f26c7a78STrond Myklebust if (status < 0) 47421da177e4SLinus Torvalds goto xdr_error; 4743409924e4STrond Myklebust fattr->valid |= status; 4744f26c7a78STrond Myklebust 47456926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4746f26c7a78STrond Myklebust if (status < 0) 47471da177e4SLinus Torvalds goto xdr_error; 4748409924e4STrond Myklebust fattr->valid |= status; 4749f26c7a78STrond Myklebust 47506926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4751f26c7a78STrond Myklebust if (status < 0) 47521da177e4SLinus Torvalds goto xdr_error; 4753409924e4STrond Myklebust fattr->valid |= status; 4754f26c7a78STrond Myklebust 4755f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4756f26c7a78STrond Myklebust if (status < 0) 47571da177e4SLinus Torvalds goto xdr_error; 4758409924e4STrond Myklebust fattr->valid |= status; 4759f26c7a78STrond Myklebust 4760f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4761f26c7a78STrond Myklebust if (status < 0) 47621da177e4SLinus Torvalds goto xdr_error; 4763409924e4STrond Myklebust fattr->valid |= status; 4764f26c7a78STrond Myklebust 4765f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4766f26c7a78STrond Myklebust if (status < 0) 47671da177e4SLinus Torvalds goto xdr_error; 4768409924e4STrond Myklebust fattr->valid |= status; 4769f26c7a78STrond Myklebust 4770f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4771f26c7a78STrond Myklebust if (status < 0) 47721da177e4SLinus Torvalds goto xdr_error; 4773409924e4STrond Myklebust fattr->valid |= status; 4774f26c7a78STrond Myklebust 4775f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4776f26c7a78STrond Myklebust if (status < 0) 47771da177e4SLinus Torvalds goto xdr_error; 4778409924e4STrond Myklebust fattr->valid |= status; 4779f26c7a78STrond Myklebust 478028331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4781f26c7a78STrond Myklebust if (status < 0) 478299baf625SManoj Naik goto xdr_error; 4783409924e4STrond Myklebust fattr->valid |= status; 4784f26c7a78STrond Myklebust 47851ca843a2SAndreas Gruenbacher status = -EIO; 47861ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 47871ca843a2SAndreas Gruenbacher goto xdr_error; 47881ca843a2SAndreas Gruenbacher 478988034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 479088034c3dSAndy Adamson if (status < 0) 479188034c3dSAndy Adamson goto xdr_error; 479288034c3dSAndy Adamson 4793aa9c2669SDavid Quigley if (label) { 4794aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4795aa9c2669SDavid Quigley if (status < 0) 4796aa9c2669SDavid Quigley goto xdr_error; 4797aa9c2669SDavid Quigley fattr->valid |= status; 4798aa9c2669SDavid Quigley } 4799aa9c2669SDavid Quigley 4800ae42c70aSBryan Schumaker xdr_error: 4801ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4802ae42c70aSBryan Schumaker return status; 4803ae42c70aSBryan Schumaker } 4804ae42c70aSBryan Schumaker 4805ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 48068b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4807aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4808ae42c70aSBryan Schumaker { 4809256e48bbSTrond Myklebust unsigned int savep; 4810ae42c70aSBryan Schumaker uint32_t attrlen, 4811dae100c2SFred Isaman bitmap[3] = {0}; 4812ae42c70aSBryan Schumaker int status; 4813ae42c70aSBryan Schumaker 4814ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4815ae42c70aSBryan Schumaker if (status < 0) 4816ae42c70aSBryan Schumaker goto xdr_error; 4817ae42c70aSBryan Schumaker 4818ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4819ae42c70aSBryan Schumaker if (status < 0) 4820ae42c70aSBryan Schumaker goto xdr_error; 4821ae42c70aSBryan Schumaker 4822ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4823ae42c70aSBryan Schumaker if (status < 0) 4824ae42c70aSBryan Schumaker goto xdr_error; 4825ae42c70aSBryan Schumaker 4826aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4827aa9c2669SDavid Quigley label, server); 4828ae42c70aSBryan Schumaker if (status < 0) 4829ae42c70aSBryan Schumaker goto xdr_error; 4830ae42c70aSBryan Schumaker 4831f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 48321da177e4SLinus Torvalds xdr_error: 48333110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 48341da177e4SLinus Torvalds return status; 48351da177e4SLinus Torvalds } 48361da177e4SLinus Torvalds 4837aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4838aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4839aa9c2669SDavid Quigley { 4840aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4841aa9c2669SDavid Quigley } 4842aa9c2669SDavid Quigley 4843ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 48446926afd1STrond Myklebust const struct nfs_server *server) 4845ae42c70aSBryan Schumaker { 4846aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4847ae42c70aSBryan Schumaker } 48481da177e4SLinus Torvalds 4849504913fbSAndy Adamson /* 48503132e49eSJeff Layton * Decode potentially multiple layout types. 4851504913fbSAndy Adamson */ 48523132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4853ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4854504913fbSAndy Adamson { 4855b8a8a0ddSTrond Myklebust __be32 *p; 4856ca440c38SJeff Layton uint32_t i; 4857504913fbSAndy Adamson 4858504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4859504913fbSAndy Adamson if (unlikely(!p)) 4860504913fbSAndy Adamson goto out_overflow; 4861ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4862504913fbSAndy Adamson 4863504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4864ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4865504913fbSAndy Adamson return 0; 4866504913fbSAndy Adamson 4867504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4868ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4869504913fbSAndy Adamson if (unlikely(!p)) 4870504913fbSAndy Adamson goto out_overflow; 4871ca440c38SJeff Layton 4872ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4873ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4874ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4875ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4876ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4877ca440c38SJeff Layton } 4878ca440c38SJeff Layton 4879ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4880ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4881504913fbSAndy Adamson return 0; 4882504913fbSAndy Adamson out_overflow: 4883504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4884504913fbSAndy Adamson return -EIO; 4885504913fbSAndy Adamson } 4886504913fbSAndy Adamson 4887504913fbSAndy Adamson /* 4888504913fbSAndy Adamson * The type of file system exported. 4889504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4890504913fbSAndy Adamson */ 4891504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4892ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4893504913fbSAndy Adamson { 4894504913fbSAndy Adamson int status = 0; 4895504913fbSAndy Adamson 4896504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4897504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4898504913fbSAndy Adamson return -EIO; 4899504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4900ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4901504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 49023132e49eSJeff Layton } 4903504913fbSAndy Adamson return status; 4904504913fbSAndy Adamson } 4905504913fbSAndy Adamson 4906dae100c2SFred Isaman /* 4907dae100c2SFred Isaman * The prefered block size for layout directed io 4908dae100c2SFred Isaman */ 4909dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4910dae100c2SFred Isaman uint32_t *res) 4911dae100c2SFred Isaman { 4912dae100c2SFred Isaman __be32 *p; 4913dae100c2SFred Isaman 4914dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4915dae100c2SFred Isaman *res = 0; 4916dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4917dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4918dae100c2SFred Isaman if (unlikely(!p)) { 4919dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4920dae100c2SFred Isaman return -EIO; 4921dae100c2SFred Isaman } 4922dae100c2SFred Isaman *res = be32_to_cpup(p); 4923dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4924dae100c2SFred Isaman } 4925dae100c2SFred Isaman return 0; 4926dae100c2SFred Isaman } 4927dae100c2SFred Isaman 49282a92ee92SPeng Tao /* 49292a92ee92SPeng Tao * The granularity of a CLONE operation. 49302a92ee92SPeng Tao */ 49312a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 49322a92ee92SPeng Tao uint32_t *res) 49332a92ee92SPeng Tao { 49342a92ee92SPeng Tao __be32 *p; 49352a92ee92SPeng Tao 49362a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 49372a92ee92SPeng Tao *res = 0; 49382a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 49392a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 49402a92ee92SPeng Tao if (unlikely(!p)) { 49412a92ee92SPeng Tao print_overflow_msg(__func__, xdr); 49422a92ee92SPeng Tao return -EIO; 49432a92ee92SPeng Tao } 49442a92ee92SPeng Tao *res = be32_to_cpup(p); 49452a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 49462a92ee92SPeng Tao } 49472a92ee92SPeng Tao return 0; 49482a92ee92SPeng Tao } 49492a92ee92SPeng Tao 49501da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 49511da177e4SLinus Torvalds { 4952256e48bbSTrond Myklebust unsigned int savep; 4953dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 49541da177e4SLinus Torvalds int status; 49551da177e4SLinus Torvalds 49561da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 49571da177e4SLinus Torvalds goto xdr_error; 49581da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 49591da177e4SLinus Torvalds goto xdr_error; 49601da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 49611da177e4SLinus Torvalds goto xdr_error; 49621da177e4SLinus Torvalds 49631da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 49641da177e4SLinus Torvalds 49651da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 49661da177e4SLinus Torvalds goto xdr_error; 49671da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 49681da177e4SLinus Torvalds goto xdr_error; 49691da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 49701da177e4SLinus Torvalds goto xdr_error; 49711da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 49721da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 49731da177e4SLinus Torvalds goto xdr_error; 49741da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 49751ca843a2SAndreas Gruenbacher 49761ca843a2SAndreas Gruenbacher status = -EIO; 49771ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 49781ca843a2SAndreas Gruenbacher goto xdr_error; 49791ca843a2SAndreas Gruenbacher 498055b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 498155b6e774SRicardo Labiaga if (status != 0) 498255b6e774SRicardo Labiaga goto xdr_error; 4983ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4984504913fbSAndy Adamson if (status != 0) 4985504913fbSAndy Adamson goto xdr_error; 49861ca843a2SAndreas Gruenbacher 49871ca843a2SAndreas Gruenbacher status = -EIO; 49881ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 49891ca843a2SAndreas Gruenbacher goto xdr_error; 49901ca843a2SAndreas Gruenbacher 4991dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4992dae100c2SFred Isaman if (status) 4993dae100c2SFred Isaman goto xdr_error; 49942a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 49952a92ee92SPeng Tao if (status) 49962a92ee92SPeng Tao goto xdr_error; 49971da177e4SLinus Torvalds 49981da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 49991da177e4SLinus Torvalds xdr_error: 50003110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 50011da177e4SLinus Torvalds return status; 50021da177e4SLinus Torvalds } 50031da177e4SLinus Torvalds 50041da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 50051da177e4SLinus Torvalds { 50068687b63aSAl Viro __be32 *p; 50071da177e4SLinus Torvalds uint32_t len; 50081da177e4SLinus Torvalds int status; 50091da177e4SLinus Torvalds 50109936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 50119936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 50129936781dSTrond Myklebust 50131da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 50141da177e4SLinus Torvalds if (status) 50151da177e4SLinus Torvalds return status; 50161da177e4SLinus Torvalds 5017c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5018c0eae66eSBenny Halevy if (unlikely(!p)) 5019c0eae66eSBenny Halevy goto out_overflow; 5020cccddf4fSBenny Halevy len = be32_to_cpup(p); 50211da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 50221da177e4SLinus Torvalds return -EIO; 50231da177e4SLinus Torvalds fh->size = len; 5024c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5025c0eae66eSBenny Halevy if (unlikely(!p)) 5026c0eae66eSBenny Halevy goto out_overflow; 502799398d06SBenny Halevy memcpy(fh->data, p, len); 50281da177e4SLinus Torvalds return 0; 5029c0eae66eSBenny Halevy out_overflow: 5030c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5031c0eae66eSBenny Halevy return -EIO; 50321da177e4SLinus Torvalds } 50331da177e4SLinus Torvalds 50341da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 50351da177e4SLinus Torvalds { 50361da177e4SLinus Torvalds int status; 50371da177e4SLinus Torvalds 50381da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 50391da177e4SLinus Torvalds if (status) 50401da177e4SLinus Torvalds return status; 50411da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 50421da177e4SLinus Torvalds } 50431da177e4SLinus Torvalds 50441da177e4SLinus Torvalds /* 50451da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 50461da177e4SLinus Torvalds */ 5047911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 50481da177e4SLinus Torvalds { 5049911d1aafSTrond Myklebust uint64_t offset, length, clientid; 50508687b63aSAl Viro __be32 *p; 5051911d1aafSTrond Myklebust uint32_t namelen, type; 50521da177e4SLinus Torvalds 5053babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 5054c0eae66eSBenny Halevy if (unlikely(!p)) 5055c0eae66eSBenny Halevy goto out_overflow; 5056babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 50573ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 5058babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 5059babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 5060911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 5061911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 5062911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 5063911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 5064911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 5065911d1aafSTrond Myklebust if (type & 1) 5066911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 5067911d1aafSTrond Myklebust fl->fl_pid = 0; 5068911d1aafSTrond Myklebust } 5069babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 5070babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 5071babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 5072c0eae66eSBenny Halevy if (likely(p)) 50731da177e4SLinus Torvalds return -NFS4ERR_DENIED; 5074c0eae66eSBenny Halevy out_overflow: 5075c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5076c0eae66eSBenny Halevy return -EIO; 50771da177e4SLinus Torvalds } 50781da177e4SLinus Torvalds 5079911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 50801da177e4SLinus Torvalds { 50811da177e4SLinus Torvalds int status; 50821da177e4SLinus Torvalds 50831da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 5084c1d51931STrond Myklebust if (status == -EIO) 5085c1d51931STrond Myklebust goto out; 50861da177e4SLinus Torvalds if (status == 0) { 508793b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 508807d30434SBenny Halevy if (unlikely(status)) 508907d30434SBenny Halevy goto out; 50901da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 5091c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 5092c1d51931STrond Myklebust if (res->open_seqid != NULL) 5093c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 5094c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 5095c1d51931STrond Myklebust out: 50961da177e4SLinus Torvalds return status; 50971da177e4SLinus Torvalds } 50981da177e4SLinus Torvalds 5099911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 51001da177e4SLinus Torvalds { 51011da177e4SLinus Torvalds int status; 51021da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 51031da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 5104911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 51051da177e4SLinus Torvalds return status; 51061da177e4SLinus Torvalds } 51071da177e4SLinus Torvalds 5108911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 51091da177e4SLinus Torvalds { 51101da177e4SLinus Torvalds int status; 51111da177e4SLinus Torvalds 51121da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 5113c1d51931STrond Myklebust if (status != -EIO) 5114c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 511507d30434SBenny Halevy if (status == 0) 511693b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 51171da177e4SLinus Torvalds return status; 51181da177e4SLinus Torvalds } 51191da177e4SLinus Torvalds 5120d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 5121d3c7b7ccSTrond Myklebust { 5122d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5123d3c7b7ccSTrond Myklebust } 5124d3c7b7ccSTrond Myklebust 51251da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 51261da177e4SLinus Torvalds { 51271da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 51281da177e4SLinus Torvalds } 51291da177e4SLinus Torvalds 51305b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr) 51315b5faaf6SJeff Layton { 51325b5faaf6SJeff Layton return decode_op_hdr(xdr, OP_LOOKUPP); 51335b5faaf6SJeff Layton } 51345b5faaf6SJeff Layton 51351da177e4SLinus Torvalds /* This is too sick! */ 51367d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 51377d160a6cSTrond Myklebust unsigned long *pagemod_limit) 51381da177e4SLinus Torvalds { 51398687b63aSAl Viro __be32 *p; 51401da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 51417d160a6cSTrond Myklebust u64 maxsize = 0; 51421da177e4SLinus Torvalds 5143c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5144c0eae66eSBenny Halevy if (unlikely(!p)) 5145c0eae66eSBenny Halevy goto out_overflow; 51466f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 51471da177e4SLinus Torvalds switch (limit_type) { 51487d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 51497d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 51501da177e4SLinus Torvalds break; 51517d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 51526f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5153cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 51547d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 51551da177e4SLinus Torvalds } 515609cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 51577d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 51581da177e4SLinus Torvalds return 0; 5159c0eae66eSBenny Halevy out_overflow: 5160c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5161c0eae66eSBenny Halevy return -EIO; 51621da177e4SLinus Torvalds } 51631da177e4SLinus Torvalds 51646ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 51656ae37339STrond Myklebust uint32_t delegation_type, 51666ae37339STrond Myklebust struct nfs_openres *res) 51671da177e4SLinus Torvalds { 51688687b63aSAl Viro __be32 *p; 516907d30434SBenny Halevy int status; 51701da177e4SLinus Torvalds 517193b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 517207d30434SBenny Halevy if (unlikely(status)) 517307d30434SBenny Halevy return status; 5174c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5175c0eae66eSBenny Halevy if (unlikely(!p)) 5176c0eae66eSBenny Halevy goto out_overflow; 5177cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 517805d564feSAndy Adamson 51791da177e4SLinus Torvalds switch (delegation_type) { 51801da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 51811da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 51821da177e4SLinus Torvalds break; 51831da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 51841da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 51857d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 51861da177e4SLinus Torvalds return -EIO; 51871da177e4SLinus Torvalds } 51881bbe60ffSTrond Myklebust return decode_ace(xdr, NULL); 5189c0eae66eSBenny Halevy out_overflow: 5190c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5191c0eae66eSBenny Halevy return -EIO; 51921da177e4SLinus Torvalds } 51931da177e4SLinus Torvalds 51946ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51956ae37339STrond Myklebust { 51966ae37339STrond Myklebust __be32 *p; 51976ae37339STrond Myklebust uint32_t why_no_delegation; 51986ae37339STrond Myklebust 51996ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 52006ae37339STrond Myklebust if (unlikely(!p)) 52016ae37339STrond Myklebust goto out_overflow; 52026ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 52036ae37339STrond Myklebust switch (why_no_delegation) { 52046ae37339STrond Myklebust case WND4_CONTENTION: 52056ae37339STrond Myklebust case WND4_RESOURCE: 52066ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 52076ae37339STrond Myklebust /* Ignore for now */ 52086ae37339STrond Myklebust } 52096ae37339STrond Myklebust return 0; 52106ae37339STrond Myklebust out_overflow: 52116ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 52126ae37339STrond Myklebust return -EIO; 52136ae37339STrond Myklebust } 52146ae37339STrond Myklebust 52156ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 52166ae37339STrond Myklebust { 52176ae37339STrond Myklebust __be32 *p; 52186ae37339STrond Myklebust uint32_t delegation_type; 52196ae37339STrond Myklebust 52206ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 52216ae37339STrond Myklebust if (unlikely(!p)) 52226ae37339STrond Myklebust goto out_overflow; 52236ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 52246ae37339STrond Myklebust res->delegation_type = 0; 52256ae37339STrond Myklebust switch (delegation_type) { 52266ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 52276ae37339STrond Myklebust return 0; 52286ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 52296ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 52306ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 52316ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 52326ae37339STrond Myklebust return decode_no_delegation(xdr, res); 52336ae37339STrond Myklebust } 52346ae37339STrond Myklebust return -EIO; 52356ae37339STrond Myklebust out_overflow: 52366ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 52376ae37339STrond Myklebust return -EIO; 52386ae37339STrond Myklebust } 52396ae37339STrond Myklebust 52401da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 52411da177e4SLinus Torvalds { 52428687b63aSAl Viro __be32 *p; 5243aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 52441da177e4SLinus Torvalds int status; 52451da177e4SLinus Torvalds 5246c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5247c7848f69STrond Myklebust return status; 5248c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5249c7848f69STrond Myklebust if (status) 5250c7848f69STrond Myklebust return status; 525193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 525207d30434SBenny Halevy if (unlikely(status)) 52531da177e4SLinus Torvalds return status; 52541da177e4SLinus Torvalds 52551da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 52561da177e4SLinus Torvalds 5257c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5258c0eae66eSBenny Halevy if (unlikely(!p)) 5259c0eae66eSBenny Halevy goto out_overflow; 52606f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5261cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 52621da177e4SLinus Torvalds if (bmlen > 10) 52631da177e4SLinus Torvalds goto xdr_error; 52641da177e4SLinus Torvalds 5265c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5266c0eae66eSBenny Halevy if (unlikely(!p)) 5267c0eae66eSBenny Halevy goto out_overflow; 5268aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5269aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 52706f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5271aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5272aa53ed54SJeff Layton res->attrset[i] = 0; 5273aa53ed54SJeff Layton 52741da177e4SLinus Torvalds return decode_delegation(xdr, res); 52751da177e4SLinus Torvalds xdr_error: 52763110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 52771da177e4SLinus Torvalds return -EIO; 5278c0eae66eSBenny Halevy out_overflow: 5279c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5280c0eae66eSBenny Halevy return -EIO; 52811da177e4SLinus Torvalds } 52821da177e4SLinus Torvalds 52831da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 52841da177e4SLinus Torvalds { 52851da177e4SLinus Torvalds int status; 52861da177e4SLinus Torvalds 52871da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5288c1d51931STrond Myklebust if (status != -EIO) 5289c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 529007d30434SBenny Halevy if (!status) 529193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 52921da177e4SLinus Torvalds return status; 52931da177e4SLinus Torvalds } 52941da177e4SLinus Torvalds 52951da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 52961da177e4SLinus Torvalds { 52971da177e4SLinus Torvalds int status; 52981da177e4SLinus Torvalds 52991da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5300c1d51931STrond Myklebust if (status != -EIO) 5301c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 530207d30434SBenny Halevy if (!status) 530393b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 53041da177e4SLinus Torvalds return status; 53051da177e4SLinus Torvalds } 53061da177e4SLinus Torvalds 53071da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 53081da177e4SLinus Torvalds { 53091da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 53101da177e4SLinus Torvalds } 53111da177e4SLinus Torvalds 53121da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 53131da177e4SLinus Torvalds { 53141da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 53151da177e4SLinus Torvalds } 53161da177e4SLinus Torvalds 53179137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 53189137bdf3SAnna Schumaker struct nfs_pgio_res *res) 53191da177e4SLinus Torvalds { 53208687b63aSAl Viro __be32 *p; 532164bd577eSTrond Myklebust uint32_t count, eof, recvd; 53221da177e4SLinus Torvalds int status; 53231da177e4SLinus Torvalds 53241da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 53251da177e4SLinus Torvalds if (status) 53261da177e4SLinus Torvalds return status; 5327c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5328c0eae66eSBenny Halevy if (unlikely(!p)) 5329c0eae66eSBenny Halevy goto out_overflow; 53306f723f77SBenny Halevy eof = be32_to_cpup(p++); 5331cccddf4fSBenny Halevy count = be32_to_cpup(p); 533264bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 53331da177e4SLinus Torvalds if (count > recvd) { 5334fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 53351da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 53361da177e4SLinus Torvalds count = recvd; 53371da177e4SLinus Torvalds eof = 0; 53381da177e4SLinus Torvalds } 53391da177e4SLinus Torvalds res->eof = eof; 53401da177e4SLinus Torvalds res->count = count; 53411da177e4SLinus Torvalds return 0; 5342c0eae66eSBenny Halevy out_overflow: 5343c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5344c0eae66eSBenny Halevy return -EIO; 53451da177e4SLinus Torvalds } 53461da177e4SLinus Torvalds 53471da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 53481da177e4SLinus Torvalds { 5349bcecff77SChuck Lever int status; 5350cd93710eSChuck Lever __be32 verf[2]; 53511da177e4SLinus Torvalds 53521da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5353db942bbdSBenny Halevy if (!status) 5354db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5355db942bbdSBenny Halevy if (unlikely(status)) 53561da177e4SLinus Torvalds return status; 5357cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 535844109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5359cd93710eSChuck Lever __func__, verf[0], verf[1]); 536064bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 53611da177e4SLinus Torvalds } 53621da177e4SLinus Torvalds 53631da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 53641da177e4SLinus Torvalds { 53651da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5366bcecff77SChuck Lever u32 len, recvd; 53678687b63aSAl Viro __be32 *p; 53681da177e4SLinus Torvalds int status; 53691da177e4SLinus Torvalds 53701da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 53711da177e4SLinus Torvalds if (status) 53721da177e4SLinus Torvalds return status; 53731da177e4SLinus Torvalds 53741da177e4SLinus Torvalds /* Convert length of symlink */ 5375c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5376c0eae66eSBenny Halevy if (unlikely(!p)) 5377c0eae66eSBenny Halevy goto out_overflow; 5378cccddf4fSBenny Halevy len = be32_to_cpup(p); 53791da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5380fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 53811da177e4SLinus Torvalds return -ENAMETOOLONG; 53821da177e4SLinus Torvalds } 538364bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 53841da177e4SLinus Torvalds if (recvd < len) { 5385fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 53861da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 53871da177e4SLinus Torvalds return -EIO; 53881da177e4SLinus Torvalds } 53891da177e4SLinus Torvalds /* 53901da177e4SLinus Torvalds * The XDR encode routine has set things up so that 53911da177e4SLinus Torvalds * the link text will be copied directly into the 53921da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 53931da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 53941da177e4SLinus Torvalds * null-termination). 53951da177e4SLinus Torvalds */ 5396b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 53971da177e4SLinus Torvalds return 0; 5398c0eae66eSBenny Halevy out_overflow: 5399c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5400c0eae66eSBenny Halevy return -EIO; 54011da177e4SLinus Torvalds } 54021da177e4SLinus Torvalds 54031da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 54041da177e4SLinus Torvalds { 54051da177e4SLinus Torvalds int status; 54061da177e4SLinus Torvalds 54071da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 54081da177e4SLinus Torvalds if (status) 54091da177e4SLinus Torvalds goto out; 54101da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 54111da177e4SLinus Torvalds out: 54121da177e4SLinus Torvalds return status; 54131da177e4SLinus Torvalds } 54141da177e4SLinus Torvalds 54151da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 54161da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 54171da177e4SLinus Torvalds { 54181da177e4SLinus Torvalds int status; 54191da177e4SLinus Torvalds 54201da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 54211da177e4SLinus Torvalds if (status) 54221da177e4SLinus Torvalds goto out; 54231da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 54241da177e4SLinus Torvalds goto out; 54251da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 54261da177e4SLinus Torvalds out: 54271da177e4SLinus Torvalds return status; 54281da177e4SLinus Torvalds } 54291da177e4SLinus Torvalds 54301da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 54311da177e4SLinus Torvalds { 54321da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 54331da177e4SLinus Torvalds } 54341da177e4SLinus Torvalds 543556ae19f3STrond Myklebust static int 543656ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 543756ae19f3STrond Myklebust { 543856ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 543956ae19f3STrond Myklebust } 544056ae19f3STrond Myklebust 5441029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5442bf118a34SAndy Adamson struct nfs_getaclres *res) 5443029d105eSJ. Bruce Fields { 5444256e48bbSTrond Myklebust unsigned int savep; 5445029d105eSJ. Bruce Fields uint32_t attrlen, 5446dae100c2SFred Isaman bitmap[3] = {0}; 5447029d105eSJ. Bruce Fields int status; 5448cff298c7STrond Myklebust unsigned int pg_offset; 5449029d105eSJ. Bruce Fields 5450bf118a34SAndy Adamson res->acl_len = 0; 5451029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5452029d105eSJ. Bruce Fields goto out; 54535a006899SSachin Prabhu 5454519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5455519d3959STrond Myklebust 5456cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5457cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 54585a006899SSachin Prabhu 5459029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5460029d105eSJ. Bruce Fields goto out; 5461029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5462029d105eSJ. Bruce Fields goto out; 5463029d105eSJ. Bruce Fields 5464029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5465029d105eSJ. Bruce Fields return -EIO; 5466029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5467029d105eSJ. Bruce Fields 5468bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5469bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5470bf118a34SAndy Adamson * variable length bitmaps.*/ 5471cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5472519d3959STrond Myklebust res->acl_len = attrlen; 54731f1ea6c2STrond Myklebust 54741f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 54751f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 54761f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 54771f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5478519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5479cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5480029d105eSJ. Bruce Fields } 54818c233cf9SJ. Bruce Fields } else 54828c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5483029d105eSJ. Bruce Fields 5484029d105eSJ. Bruce Fields out: 5485029d105eSJ. Bruce Fields return status; 5486029d105eSJ. Bruce Fields } 5487029d105eSJ. Bruce Fields 54881da177e4SLinus Torvalds static int 54891da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 54901da177e4SLinus Torvalds { 54911da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 54921da177e4SLinus Torvalds } 54931da177e4SLinus Torvalds 54949e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 54951da177e4SLinus Torvalds { 54961da177e4SLinus Torvalds int status; 54971da177e4SLinus Torvalds 54981da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 54991da177e4SLinus Torvalds if (status) 55001da177e4SLinus Torvalds return status; 550137c88763STrond Myklebust if (decode_bitmap4(xdr, NULL, 0) >= 0) 55021da177e4SLinus Torvalds return 0; 5503c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5504c0eae66eSBenny Halevy return -EIO; 55051da177e4SLinus Torvalds } 55061da177e4SLinus Torvalds 5507bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 55081da177e4SLinus Torvalds { 55098687b63aSAl Viro __be32 *p; 55101da177e4SLinus Torvalds uint32_t opnum; 55111da177e4SLinus Torvalds int32_t nfserr; 55121da177e4SLinus Torvalds 5513c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5514c0eae66eSBenny Halevy if (unlikely(!p)) 5515c0eae66eSBenny Halevy goto out_overflow; 55166f723f77SBenny Halevy opnum = be32_to_cpup(p++); 55171da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5518fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 55191da177e4SLinus Torvalds " %d\n", opnum); 55201da177e4SLinus Torvalds return -EIO; 55211da177e4SLinus Torvalds } 5522cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 55231da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5524c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5525c0eae66eSBenny Halevy if (unlikely(!p)) 5526c0eae66eSBenny Halevy goto out_overflow; 5527bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5528bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 55291da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 55301da177e4SLinus Torvalds uint32_t len; 55311da177e4SLinus Torvalds 55321da177e4SLinus Torvalds /* skip netid string */ 5533c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5534c0eae66eSBenny Halevy if (unlikely(!p)) 5535c0eae66eSBenny Halevy goto out_overflow; 5536cccddf4fSBenny Halevy len = be32_to_cpup(p); 5537c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5538c0eae66eSBenny Halevy if (unlikely(!p)) 5539c0eae66eSBenny Halevy goto out_overflow; 55401da177e4SLinus Torvalds 55411da177e4SLinus Torvalds /* skip uaddr string */ 5542c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5543c0eae66eSBenny Halevy if (unlikely(!p)) 5544c0eae66eSBenny Halevy goto out_overflow; 5545cccddf4fSBenny Halevy len = be32_to_cpup(p); 5546c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5547c0eae66eSBenny Halevy if (unlikely(!p)) 5548c0eae66eSBenny Halevy goto out_overflow; 55491da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 55501da177e4SLinus Torvalds } else 5551856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 55521da177e4SLinus Torvalds 55531da177e4SLinus Torvalds return 0; 5554c0eae66eSBenny Halevy out_overflow: 5555c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5556c0eae66eSBenny Halevy return -EIO; 55571da177e4SLinus Torvalds } 55581da177e4SLinus Torvalds 55591da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 55601da177e4SLinus Torvalds { 55611da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 55621da177e4SLinus Torvalds } 55631da177e4SLinus Torvalds 55649137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 55651da177e4SLinus Torvalds { 55668687b63aSAl Viro __be32 *p; 55671da177e4SLinus Torvalds int status; 55681da177e4SLinus Torvalds 55691da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 55701da177e4SLinus Torvalds if (status) 55711da177e4SLinus Torvalds return status; 55721da177e4SLinus Torvalds 55732f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5574c0eae66eSBenny Halevy if (unlikely(!p)) 5575c0eae66eSBenny Halevy goto out_overflow; 55766f723f77SBenny Halevy res->count = be32_to_cpup(p++); 55776f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 55782f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5579c0eae66eSBenny Halevy out_overflow: 5580c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5581c0eae66eSBenny Halevy return -EIO; 55821da177e4SLinus Torvalds } 55831da177e4SLinus Torvalds 55841da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 55851da177e4SLinus Torvalds { 55861da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 55871da177e4SLinus Torvalds } 55881da177e4SLinus Torvalds 5589fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5590fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 55915a5ea0d4SBryan Schumaker { 5592fb15b26fSChuck Lever u32 oid_len; 55935a5ea0d4SBryan Schumaker __be32 *p; 55945a5ea0d4SBryan Schumaker 55955a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55965a5ea0d4SBryan Schumaker if (unlikely(!p)) 55975a5ea0d4SBryan Schumaker goto out_overflow; 5598fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5599fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 56005a5ea0d4SBryan Schumaker goto out_err; 56015a5ea0d4SBryan Schumaker 5602fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 56035a5ea0d4SBryan Schumaker if (unlikely(!p)) 56045a5ea0d4SBryan Schumaker goto out_overflow; 5605fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5606fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 56075a5ea0d4SBryan Schumaker 56085a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 56095a5ea0d4SBryan Schumaker if (unlikely(!p)) 56105a5ea0d4SBryan Schumaker goto out_overflow; 5611fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5612fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 56135a5ea0d4SBryan Schumaker 56145a5ea0d4SBryan Schumaker return 0; 56155a5ea0d4SBryan Schumaker 56165a5ea0d4SBryan Schumaker out_overflow: 56175a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 56185a5ea0d4SBryan Schumaker return -EIO; 56195a5ea0d4SBryan Schumaker out_err: 56205a5ea0d4SBryan Schumaker return -EINVAL; 56215a5ea0d4SBryan Schumaker } 56225a5ea0d4SBryan Schumaker 562331e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 56245a5ea0d4SBryan Schumaker { 5625fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5626fb15b26fSChuck Lever unsigned int i, num_flavors; 56275a5ea0d4SBryan Schumaker int status; 56285a5ea0d4SBryan Schumaker __be32 *p; 56295a5ea0d4SBryan Schumaker 56305a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56315a5ea0d4SBryan Schumaker if (unlikely(!p)) 56325a5ea0d4SBryan Schumaker goto out_overflow; 56335a5ea0d4SBryan Schumaker 5634c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5635c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5636c3dfc280SBryan Schumaker 5637c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 56385a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5639c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 56405a5ea0d4SBryan Schumaker break; 56415a5ea0d4SBryan Schumaker 56425a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 56435a5ea0d4SBryan Schumaker if (unlikely(!p)) 56445a5ea0d4SBryan Schumaker goto out_overflow; 56455a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 56465a5ea0d4SBryan Schumaker 56475a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5648613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5649613e901eSBryan Schumaker if (status) 5650613e901eSBryan Schumaker goto out; 56515a5ea0d4SBryan Schumaker } 5652c3dfc280SBryan Schumaker res->flavors->num_flavors++; 56535a5ea0d4SBryan Schumaker } 56545a5ea0d4SBryan Schumaker 565531e4dda4SBryan Schumaker status = 0; 5656613e901eSBryan Schumaker out: 5657613e901eSBryan Schumaker return status; 56585a5ea0d4SBryan Schumaker out_overflow: 56595a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 56605a5ea0d4SBryan Schumaker return -EIO; 56615a5ea0d4SBryan Schumaker } 56625a5ea0d4SBryan Schumaker 566331e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 566431e4dda4SBryan Schumaker { 566531e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 566631e4dda4SBryan Schumaker if (status) 566731e4dda4SBryan Schumaker return status; 566831e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 566931e4dda4SBryan Schumaker } 567031e4dda4SBryan Schumaker 567199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 567231e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 567331e4dda4SBryan Schumaker { 567431e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 567531e4dda4SBryan Schumaker if (status) 567631e4dda4SBryan Schumaker return status; 567731e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 567831e4dda4SBryan Schumaker } 567931e4dda4SBryan Schumaker 56802031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 56812031cd1aSWeston Andros Adamson { 56822031cd1aSWeston Andros Adamson __be32 *p; 56832031cd1aSWeston Andros Adamson uint32_t bitmap_words; 56842031cd1aSWeston Andros Adamson unsigned int i; 56852031cd1aSWeston Andros Adamson 56862031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56874edabfd7SPan Bian if (!p) 56884edabfd7SPan Bian return -EIO; 56892031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 56902031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 56912031cd1aSWeston Andros Adamson return -EIO; 56922031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 56932031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 56942031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 56952031cd1aSWeston Andros Adamson 56962031cd1aSWeston Andros Adamson return 0; 56972031cd1aSWeston Andros Adamson } 56982031cd1aSWeston Andros Adamson 569999fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 570099fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 570199fe60d0SBenny Halevy { 570299fe60d0SBenny Halevy __be32 *p; 570399fe60d0SBenny Halevy uint32_t dummy; 57042460ba57SBenny Halevy char *dummy_str; 570599fe60d0SBenny Halevy int status; 57067d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 570799fe60d0SBenny Halevy 570899fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 570999fe60d0SBenny Halevy if (status) 571099fe60d0SBenny Halevy return status; 571199fe60d0SBenny Halevy 5712c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5713c0eae66eSBenny Halevy if (unlikely(!p)) 5714c0eae66eSBenny Halevy goto out_overflow; 571532b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5716c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5717c0eae66eSBenny Halevy if (unlikely(!p)) 5718c0eae66eSBenny Halevy goto out_overflow; 571932b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 572032b01310STrond Myklebust res->flags = be32_to_cpup(p++); 572199fe60d0SBenny Halevy 57222031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 57232031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 57242031cd1aSWeston Andros Adamson case SP4_NONE: 57252031cd1aSWeston Andros Adamson break; 57262031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 57272031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 57282031cd1aSWeston Andros Adamson if (status) 57292031cd1aSWeston Andros Adamson return status; 57302031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 57312031cd1aSWeston Andros Adamson if (status) 57322031cd1aSWeston Andros Adamson return status; 57332031cd1aSWeston Andros Adamson break; 57342031cd1aSWeston Andros Adamson default: 57352031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 573699fe60d0SBenny Halevy return -EIO; 57372031cd1aSWeston Andros Adamson } 573899fe60d0SBenny Halevy 5739acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5740c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5741c0eae66eSBenny Halevy if (unlikely(!p)) 5742c0eae66eSBenny Halevy goto out_overflow; 5743acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 574499fe60d0SBenny Halevy 5745acdeb69dSChuck Lever /* server_owner4.so_major_id */ 57462460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57472460ba57SBenny Halevy if (unlikely(status)) 57482460ba57SBenny Halevy return status; 5749acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5750acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 575178fe0f41SWeston Andros Adamson 5752acdeb69dSChuck Lever /* server_scope4 */ 5753acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5754acdeb69dSChuck Lever if (unlikely(status)) 5755acdeb69dSChuck Lever return status; 575678fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 575778fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 575878fe0f41SWeston Andros Adamson 57597d2ed9acSWeston Andros Adamson /* Implementation Id */ 57607d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 57617d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57627d2ed9acSWeston Andros Adamson goto out_overflow; 57637d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 57647d2ed9acSWeston Andros Adamson 57657d2ed9acSWeston Andros Adamson if (impl_id_count) { 57667d2ed9acSWeston Andros Adamson /* nii_domain */ 57672460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57682460ba57SBenny Halevy if (unlikely(status)) 57692460ba57SBenny Halevy return status; 57707d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 577199fe60d0SBenny Halevy 57727d2ed9acSWeston Andros Adamson /* nii_name */ 57737d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 57747d2ed9acSWeston Andros Adamson if (unlikely(status)) 57757d2ed9acSWeston Andros Adamson return status; 57767d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 57777d2ed9acSWeston Andros Adamson 57787d2ed9acSWeston Andros Adamson /* nii_date */ 57797d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 57807d2ed9acSWeston Andros Adamson if (unlikely(!p)) 57817d2ed9acSWeston Andros Adamson goto out_overflow; 57827d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 57837d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 57847d2ed9acSWeston Andros Adamson 57857d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 57867d2ed9acSWeston Andros Adamson } 578799fe60d0SBenny Halevy return 0; 5788c0eae66eSBenny Halevy out_overflow: 5789c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5790c0eae66eSBenny Halevy return -EIO; 579199fe60d0SBenny Halevy } 5792fc931582SAndy Adamson 5793fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5794fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5795fc931582SAndy Adamson { 5796fc931582SAndy Adamson __be32 *p; 5797c9c30dd5SBenny Halevy u32 nr_attrs, val; 5798fc931582SAndy Adamson 5799c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5800c0eae66eSBenny Halevy if (unlikely(!p)) 5801c0eae66eSBenny Halevy goto out_overflow; 5802c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5803c9c30dd5SBenny Halevy if (val) 5804c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 58056f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 58066f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 58076f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 58086f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 58096f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5810cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5811fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5812a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5813a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5814fc931582SAndy Adamson return -EINVAL; 5815fc931582SAndy Adamson } 5816c0eae66eSBenny Halevy if (nr_attrs == 1) { 5817c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5818c0eae66eSBenny Halevy if (unlikely(!p)) 5819c0eae66eSBenny Halevy goto out_overflow; 5820c0eae66eSBenny Halevy } 5821fc931582SAndy Adamson return 0; 5822c0eae66eSBenny Halevy out_overflow: 5823c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5824c0eae66eSBenny Halevy return -EIO; 5825fc931582SAndy Adamson } 5826fc931582SAndy Adamson 5827e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5828e78291e4SBenny Halevy { 5829e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5830fc931582SAndy Adamson } 5831fc931582SAndy Adamson 58327c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 58337c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 58347c44f1aeSWeston Andros Adamson { 58357c44f1aeSWeston Andros Adamson __be32 *p; 58367c44f1aeSWeston Andros Adamson int status; 58377c44f1aeSWeston Andros Adamson 58387c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 58397c44f1aeSWeston Andros Adamson if (!status) 584071a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 58417c44f1aeSWeston Andros Adamson if (unlikely(status)) 58427c44f1aeSWeston Andros Adamson return status; 58437c44f1aeSWeston Andros Adamson 58447c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 58457c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 58467c44f1aeSWeston Andros Adamson if (unlikely(!p)) 58477c44f1aeSWeston Andros Adamson goto out_overflow; 58487c44f1aeSWeston Andros Adamson 58497c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 58507c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 58517c44f1aeSWeston Andros Adamson return -EIO; 58527c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 58537c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 58547c44f1aeSWeston Andros Adamson else 58557c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 58567c44f1aeSWeston Andros Adamson 58577c44f1aeSWeston Andros Adamson return 0; 58587c44f1aeSWeston Andros Adamson out_overflow: 58597c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 58607c44f1aeSWeston Andros Adamson return -EIO; 58617c44f1aeSWeston Andros Adamson } 58627c44f1aeSWeston Andros Adamson 5863fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5864fc931582SAndy Adamson struct nfs41_create_session_res *res) 5865fc931582SAndy Adamson { 5866fc931582SAndy Adamson __be32 *p; 5867fc931582SAndy Adamson int status; 5868fc931582SAndy Adamson 5869fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5870e78291e4SBenny Halevy if (!status) 587179969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5872e78291e4SBenny Halevy if (unlikely(status)) 5873fc931582SAndy Adamson return status; 5874fc931582SAndy Adamson 5875fc931582SAndy Adamson /* seqid, flags */ 5876c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5877c0eae66eSBenny Halevy if (unlikely(!p)) 5878c0eae66eSBenny Halevy goto out_overflow; 587979969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 588079969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5881fc931582SAndy Adamson 5882fc931582SAndy Adamson /* Channel attributes */ 588379969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5884fc931582SAndy Adamson if (!status) 588579969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5886fc931582SAndy Adamson return status; 5887c0eae66eSBenny Halevy out_overflow: 5888c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5889c0eae66eSBenny Halevy return -EIO; 5890fc931582SAndy Adamson } 58910f3e66c6SAndy Adamson 58920f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 58930f3e66c6SAndy Adamson { 58940f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 58950f3e66c6SAndy Adamson } 589618019753SRicardo Labiaga 589766245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 589866245539STrond Myklebust { 589966245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 590066245539STrond Myklebust } 590166245539STrond Myklebust 590218019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 590318019753SRicardo Labiaga { 590418019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 590518019753SRicardo Labiaga } 590699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 590799fe60d0SBenny Halevy 59089b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 59099b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 59109b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 59119b7b9fccSAndy Adamson { 59129b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5913e3725ec0STrond Myklebust struct nfs4_session *session; 5914fc01cea9SAndy Adamson struct nfs4_sessionid id; 5915fc01cea9SAndy Adamson u32 dummy; 5916fc01cea9SAndy Adamson int status; 5917fc01cea9SAndy Adamson __be32 *p; 5918fc01cea9SAndy Adamson 5919e3725ec0STrond Myklebust if (res->sr_slot == NULL) 59209b7b9fccSAndy Adamson return 0; 59213bd2384aSChuck Lever if (!res->sr_slot->table->session) 59223bd2384aSChuck Lever return 0; 59239b7b9fccSAndy Adamson 5924fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5925e78291e4SBenny Halevy if (!status) 5926e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5927e78291e4SBenny Halevy if (unlikely(status)) 5928fc01cea9SAndy Adamson goto out_err; 59299b7b9fccSAndy Adamson 5930fc01cea9SAndy Adamson /* 5931fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5932fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5933fc01cea9SAndy Adamson */ 5934fdcb4577STrond Myklebust status = -EREMOTEIO; 5935e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5936fc01cea9SAndy Adamson 5937e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5938fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5939fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5940fc01cea9SAndy Adamson goto out_err; 5941fc01cea9SAndy Adamson } 5942e78291e4SBenny Halevy 5943c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5944c0eae66eSBenny Halevy if (unlikely(!p)) 5945c0eae66eSBenny Halevy goto out_overflow; 5946e78291e4SBenny Halevy 5947fc01cea9SAndy Adamson /* seqid */ 59486f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5949dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5950fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5951fc01cea9SAndy Adamson goto out_err; 5952fc01cea9SAndy Adamson } 5953fc01cea9SAndy Adamson /* slot id */ 59546f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5955df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5956fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5957fc01cea9SAndy Adamson goto out_err; 5958fc01cea9SAndy Adamson } 5959da0507b7STrond Myklebust /* highest slot id */ 5960da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5961464ee9f9STrond Myklebust /* target highest slot id */ 5962464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 59630629e370SAlexandros Batsakis /* result flags */ 59640629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5965fc01cea9SAndy Adamson status = 0; 5966fc01cea9SAndy Adamson out_err: 5967fc01cea9SAndy Adamson res->sr_status = status; 5968fc01cea9SAndy Adamson return status; 5969c0eae66eSBenny Halevy out_overflow: 5970c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5971c0eae66eSBenny Halevy status = -EIO; 5972c0eae66eSBenny Halevy goto out_err; 5973fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 59749b7b9fccSAndy Adamson return 0; 5975fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 59769b7b9fccSAndy Adamson } 59779b7b9fccSAndy Adamson 5978b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 597993b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 598093b717fdSTrond Myklebust { 598193b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 598293b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 598393b717fdSTrond Myklebust } 598493b717fdSTrond Myklebust 5985b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 59864e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5987b1f69b75SAndy Adamson { 59884e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5989b1f69b75SAndy Adamson __be32 *p; 5990b1f69b75SAndy Adamson uint32_t len, type; 5991b1f69b75SAndy Adamson int status; 5992b1f69b75SAndy Adamson 5993b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5994b1f69b75SAndy Adamson if (status) { 5995b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5996b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5997b1f69b75SAndy Adamson if (unlikely(!p)) 5998b1f69b75SAndy Adamson goto out_overflow; 5999b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 6000b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 6001b1f69b75SAndy Adamson __func__, pdev->mincount); 6002b1f69b75SAndy Adamson } 6003b1f69b75SAndy Adamson return status; 6004b1f69b75SAndy Adamson } 6005b1f69b75SAndy Adamson 6006b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 6007b1f69b75SAndy Adamson if (unlikely(!p)) 6008b1f69b75SAndy Adamson goto out_overflow; 6009b1f69b75SAndy Adamson type = be32_to_cpup(p++); 6010b1f69b75SAndy Adamson if (type != pdev->layout_type) { 6011b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 6012b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 6013b1f69b75SAndy Adamson return -EINVAL; 6014b1f69b75SAndy Adamson } 6015b1f69b75SAndy Adamson /* 6016b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 6017b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 6018b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 6019b1f69b75SAndy Adamson */ 6020b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 602113fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 602213fe4ba1STrond Myklebust goto out_overflow; 6023b1f69b75SAndy Adamson 6024b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 6025b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 6026b1f69b75SAndy Adamson if (unlikely(!p)) 6027b1f69b75SAndy Adamson goto out_overflow; 6028b1f69b75SAndy Adamson len = be32_to_cpup(p); 6029b1f69b75SAndy Adamson if (len) { 6030ead00597SChuck Lever uint32_t i; 6031b1f69b75SAndy Adamson 6032b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 6033b1f69b75SAndy Adamson if (unlikely(!p)) 6034b1f69b75SAndy Adamson goto out_overflow; 603584c9dee3SChristoph Hellwig 60364e590803STrond Myklebust res->notification = be32_to_cpup(p++); 603784c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 603884c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 603984c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 6040b1f69b75SAndy Adamson __func__); 6041b1f69b75SAndy Adamson return -EIO; 6042b1f69b75SAndy Adamson } 6043b1f69b75SAndy Adamson } 6044b1f69b75SAndy Adamson } 6045b1f69b75SAndy Adamson return 0; 6046b1f69b75SAndy Adamson out_overflow: 6047b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6048b1f69b75SAndy Adamson return -EIO; 6049b1f69b75SAndy Adamson } 6050b1f69b75SAndy Adamson 6051b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 6052b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 6053b1f69b75SAndy Adamson { 6054b1f69b75SAndy Adamson __be32 *p; 6055b1f69b75SAndy Adamson int status; 6056b1f69b75SAndy Adamson u32 layout_count; 605764bd577eSTrond Myklebust u32 recvd; 6058b1f69b75SAndy Adamson 6059b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 6060b1f69b75SAndy Adamson if (status) 6061808ba32aSFred Isaman goto out; 6062ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6063b1f69b75SAndy Adamson if (unlikely(!p)) 6064b1f69b75SAndy Adamson goto out_overflow; 6065ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 606693b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 6067ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 6068ea9d23f5STrond Myklebust if (unlikely(!p)) 6069ea9d23f5STrond Myklebust goto out_overflow; 6070b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 6071b1f69b75SAndy Adamson if (!layout_count) { 6072b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 6073b1f69b75SAndy Adamson __func__); 6074808ba32aSFred Isaman status = -EINVAL; 6075808ba32aSFred Isaman goto out; 6076b1f69b75SAndy Adamson } 6077b1f69b75SAndy Adamson 607835124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 6079b1f69b75SAndy Adamson if (unlikely(!p)) 6080b1f69b75SAndy Adamson goto out_overflow; 6081b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 6082b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 6083b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 6084b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 608535124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 6086b1f69b75SAndy Adamson 6087b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 6088b1f69b75SAndy Adamson __func__, 6089b1f69b75SAndy Adamson (unsigned long)res->range.offset, 6090b1f69b75SAndy Adamson (unsigned long)res->range.length, 6091b1f69b75SAndy Adamson res->range.iomode, 6092b1f69b75SAndy Adamson res->type, 609335124a09SWeston Andros Adamson res->layoutp->len); 6094b1f69b75SAndy Adamson 609564bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 609635124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 609735124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 609835124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 609935124a09SWeston Andros Adamson res->layoutp->len, recvd); 6100808ba32aSFred Isaman status = -EINVAL; 6101808ba32aSFred Isaman goto out; 610235124a09SWeston Andros Adamson } 610335124a09SWeston Andros Adamson 6104b1f69b75SAndy Adamson if (layout_count > 1) { 6105b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 6106b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 6107b1f69b75SAndy Adamson * the client may see a response that is less than the 6108b1f69b75SAndy Adamson * minimum it requested. 6109b1f69b75SAndy Adamson */ 6110b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 6111b1f69b75SAndy Adamson __func__, layout_count); 6112b1f69b75SAndy Adamson } 6113b1f69b75SAndy Adamson 6114808ba32aSFred Isaman out: 6115808ba32aSFred Isaman res->status = status; 6116808ba32aSFred Isaman return status; 6117b1f69b75SAndy Adamson out_overflow: 6118b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6119808ba32aSFred Isaman status = -EIO; 6120808ba32aSFred Isaman goto out; 6121b1f69b75SAndy Adamson } 6122863a3c6cSAndy Adamson 6123cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 6124cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6125cbe82603SBenny Halevy { 6126cbe82603SBenny Halevy __be32 *p; 6127cbe82603SBenny Halevy int status; 6128cbe82603SBenny Halevy 6129cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 6130cbe82603SBenny Halevy if (status) 6131cbe82603SBenny Halevy return status; 6132cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 6133cbe82603SBenny Halevy if (unlikely(!p)) 6134cbe82603SBenny Halevy goto out_overflow; 6135cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 6136cbe82603SBenny Halevy if (res->lrs_present) 613793b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 6138fcd8843cSTrond Myklebust else 6139fcd8843cSTrond Myklebust nfs4_stateid_copy(&res->stateid, &invalid_stateid); 6140cbe82603SBenny Halevy return status; 6141cbe82603SBenny Halevy out_overflow: 6142cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 6143cbe82603SBenny Halevy return -EIO; 6144cbe82603SBenny Halevy } 6145cbe82603SBenny Halevy 6146863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 6147863a3c6cSAndy Adamson struct rpc_rqst *req, 6148863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6149863a3c6cSAndy Adamson { 6150863a3c6cSAndy Adamson __be32 *p; 6151863a3c6cSAndy Adamson __u32 sizechanged; 6152863a3c6cSAndy Adamson int status; 6153863a3c6cSAndy Adamson 6154863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 6155db29c089SAndy Adamson res->status = status; 6156863a3c6cSAndy Adamson if (status) 6157863a3c6cSAndy Adamson return status; 6158863a3c6cSAndy Adamson 6159863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 6160863a3c6cSAndy Adamson if (unlikely(!p)) 6161863a3c6cSAndy Adamson goto out_overflow; 6162863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 6163863a3c6cSAndy Adamson 6164863a3c6cSAndy Adamson if (sizechanged) { 6165863a3c6cSAndy Adamson /* throw away new size */ 6166863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 6167863a3c6cSAndy Adamson if (unlikely(!p)) 6168863a3c6cSAndy Adamson goto out_overflow; 6169863a3c6cSAndy Adamson } 6170863a3c6cSAndy Adamson return 0; 6171863a3c6cSAndy Adamson out_overflow: 6172863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 6173863a3c6cSAndy Adamson return -EIO; 6174863a3c6cSAndy Adamson } 61757d974794SBryan Schumaker 61767d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 61777d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 61787d974794SBryan Schumaker { 61797d974794SBryan Schumaker __be32 *p; 61807d974794SBryan Schumaker int status; 61817d974794SBryan Schumaker int num_res; 61827d974794SBryan Schumaker 61837d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 61847d974794SBryan Schumaker if (status) 61857d974794SBryan Schumaker return status; 61867d974794SBryan Schumaker 61877d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61887d974794SBryan Schumaker if (unlikely(!p)) 61897d974794SBryan Schumaker goto out_overflow; 61907d974794SBryan Schumaker num_res = be32_to_cpup(p++); 61917d974794SBryan Schumaker if (num_res != 1) 61927d974794SBryan Schumaker goto out; 61937d974794SBryan Schumaker 61947d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 61957d974794SBryan Schumaker if (unlikely(!p)) 61967d974794SBryan Schumaker goto out_overflow; 61977d974794SBryan Schumaker res->status = be32_to_cpup(p++); 61981cab0652SBryan Schumaker 61991cab0652SBryan Schumaker return status; 62007d974794SBryan Schumaker out_overflow: 62017d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 62027d974794SBryan Schumaker out: 62037d974794SBryan Schumaker return -EIO; 62047d974794SBryan Schumaker } 62059aeda35fSBryan Schumaker 62069aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 62079aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 62089aeda35fSBryan Schumaker { 62099f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 62109aeda35fSBryan Schumaker return res->status; 62119aeda35fSBryan Schumaker } 6212cf805165STrond Myklebust #else 6213cf805165STrond Myklebust static inline 6214cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6215cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6216cf805165STrond Myklebust { 6217cf805165STrond Myklebust return 0; 6218cf805165STrond Myklebust } 621956f487f8SFred Isaman 622056f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 622156f487f8SFred Isaman struct nfs4_layoutget_res *res) 622256f487f8SFred Isaman { 622356f487f8SFred Isaman return 0; 622456f487f8SFred Isaman } 622556f487f8SFred Isaman 6226b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6227b1f69b75SAndy Adamson 62281da177e4SLinus Torvalds /* 622949c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 623049c2559eSBenny Halevy */ 623149c2559eSBenny Halevy 623249c2559eSBenny Halevy /* 62331da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 62341da177e4SLinus Torvalds */ 6235bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6236bf269551SChuck Lever struct xdr_stream *xdr, 6237fc016483SChristoph Hellwig void *data) 62381da177e4SLinus Torvalds { 6239fc016483SChristoph Hellwig struct nfs_closeres *res = data; 62401da177e4SLinus Torvalds struct compound_hdr hdr; 62411da177e4SLinus Torvalds int status; 62421da177e4SLinus Torvalds 6243bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62441da177e4SLinus Torvalds if (status) 62451da177e4SLinus Torvalds goto out; 6246bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62479b7b9fccSAndy Adamson if (status) 62489b7b9fccSAndy Adamson goto out; 6249bf269551SChuck Lever status = decode_putfh(xdr); 62501da177e4SLinus Torvalds if (status) 62511da177e4SLinus Torvalds goto out; 6252b6808145STrond Myklebust if (res->lr_res) { 6253b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6254b6808145STrond Myklebust res->lr_ret = status; 6255b6808145STrond Myklebust if (status) 6256b6808145STrond Myklebust goto out; 6257b6808145STrond Myklebust } 6258bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 62591da177e4SLinus Torvalds out: 62601da177e4SLinus Torvalds return status; 62611da177e4SLinus Torvalds } 62621da177e4SLinus Torvalds 62631da177e4SLinus Torvalds /* 62641da177e4SLinus Torvalds * Decode ACCESS response 62651da177e4SLinus Torvalds */ 6266bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6267fc016483SChristoph Hellwig void *data) 62681da177e4SLinus Torvalds { 6269fc016483SChristoph Hellwig struct nfs4_accessres *res = data; 62701da177e4SLinus Torvalds struct compound_hdr hdr; 62711da177e4SLinus Torvalds int status; 62721da177e4SLinus Torvalds 6273bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62749b7b9fccSAndy Adamson if (status) 62759b7b9fccSAndy Adamson goto out; 6276bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62779b7b9fccSAndy Adamson if (status) 62781da177e4SLinus Torvalds goto out; 6279bf269551SChuck Lever status = decode_putfh(xdr); 628076b32999STrond Myklebust if (status != 0) 628176b32999STrond Myklebust goto out; 62826168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 628376b32999STrond Myklebust if (status != 0) 628476b32999STrond Myklebust goto out; 62858bcbe7d9STrond Myklebust if (res->fattr) 62866926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 62871da177e4SLinus Torvalds out: 62881da177e4SLinus Torvalds return status; 62891da177e4SLinus Torvalds } 62901da177e4SLinus Torvalds 62911da177e4SLinus Torvalds /* 62921da177e4SLinus Torvalds * Decode LOOKUP response 62931da177e4SLinus Torvalds */ 6294bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6295fc016483SChristoph Hellwig void *data) 62961da177e4SLinus Torvalds { 6297fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 62981da177e4SLinus Torvalds struct compound_hdr hdr; 62991da177e4SLinus Torvalds int status; 63001da177e4SLinus Torvalds 6301bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63029b7b9fccSAndy Adamson if (status) 63039b7b9fccSAndy Adamson goto out; 6304bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63059b7b9fccSAndy Adamson if (status) 63061da177e4SLinus Torvalds goto out; 6307bf269551SChuck Lever status = decode_putfh(xdr); 6308bf269551SChuck Lever if (status) 63091da177e4SLinus Torvalds goto out; 6310bf269551SChuck Lever status = decode_lookup(xdr); 6311bf269551SChuck Lever if (status) 63121da177e4SLinus Torvalds goto out; 6313bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6314bf269551SChuck Lever if (status) 63151da177e4SLinus Torvalds goto out; 6316aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63171da177e4SLinus Torvalds out: 63181da177e4SLinus Torvalds return status; 63191da177e4SLinus Torvalds } 63201da177e4SLinus Torvalds 63211da177e4SLinus Torvalds /* 63225b5faaf6SJeff Layton * Decode LOOKUPP response 63235b5faaf6SJeff Layton */ 63245b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 63255b5faaf6SJeff Layton void *data) 63265b5faaf6SJeff Layton { 63275b5faaf6SJeff Layton struct nfs4_lookupp_res *res = data; 63285b5faaf6SJeff Layton struct compound_hdr hdr; 63295b5faaf6SJeff Layton int status; 63305b5faaf6SJeff Layton 63315b5faaf6SJeff Layton status = decode_compound_hdr(xdr, &hdr); 63325b5faaf6SJeff Layton if (status) 63335b5faaf6SJeff Layton goto out; 63345b5faaf6SJeff Layton status = decode_sequence(xdr, &res->seq_res, rqstp); 63355b5faaf6SJeff Layton if (status) 63365b5faaf6SJeff Layton goto out; 63375b5faaf6SJeff Layton status = decode_putfh(xdr); 63385b5faaf6SJeff Layton if (status) 63395b5faaf6SJeff Layton goto out; 63405b5faaf6SJeff Layton status = decode_lookupp(xdr); 63415b5faaf6SJeff Layton if (status) 63425b5faaf6SJeff Layton goto out; 63435b5faaf6SJeff Layton status = decode_getfh(xdr, res->fh); 63445b5faaf6SJeff Layton if (status) 63455b5faaf6SJeff Layton goto out; 63465b5faaf6SJeff Layton status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63475b5faaf6SJeff Layton out: 63485b5faaf6SJeff Layton return status; 63495b5faaf6SJeff Layton } 63505b5faaf6SJeff Layton 63515b5faaf6SJeff Layton /* 63521da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 63531da177e4SLinus Torvalds */ 6354bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6355bf269551SChuck Lever struct xdr_stream *xdr, 6356fc016483SChristoph Hellwig void *data) 63571da177e4SLinus Torvalds { 6358fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 63591da177e4SLinus Torvalds struct compound_hdr hdr; 63601da177e4SLinus Torvalds int status; 63611da177e4SLinus Torvalds 6362bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63639b7b9fccSAndy Adamson if (status) 63649b7b9fccSAndy Adamson goto out; 6365bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63669b7b9fccSAndy Adamson if (status) 63671da177e4SLinus Torvalds goto out; 6368bf269551SChuck Lever status = decode_putrootfh(xdr); 6369bf269551SChuck Lever if (status) 63701da177e4SLinus Torvalds goto out; 6371bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6372bf269551SChuck Lever if (status == 0) 6373aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6374aa9c2669SDavid Quigley res->label, res->server); 63751da177e4SLinus Torvalds out: 63761da177e4SLinus Torvalds return status; 63771da177e4SLinus Torvalds } 63781da177e4SLinus Torvalds 63791da177e4SLinus Torvalds /* 63801da177e4SLinus Torvalds * Decode REMOVE response 63811da177e4SLinus Torvalds */ 6382bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6383fc016483SChristoph Hellwig void *data) 63841da177e4SLinus Torvalds { 6385fc016483SChristoph Hellwig struct nfs_removeres *res = data; 63861da177e4SLinus Torvalds struct compound_hdr hdr; 63871da177e4SLinus Torvalds int status; 63881da177e4SLinus Torvalds 6389bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63909b7b9fccSAndy Adamson if (status) 63919b7b9fccSAndy Adamson goto out; 6392bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63939b7b9fccSAndy Adamson if (status) 63941da177e4SLinus Torvalds goto out; 6395bf269551SChuck Lever status = decode_putfh(xdr); 6396bf269551SChuck Lever if (status) 639716e42959STrond Myklebust goto out; 6398bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 63991da177e4SLinus Torvalds out: 64001da177e4SLinus Torvalds return status; 64011da177e4SLinus Torvalds } 64021da177e4SLinus Torvalds 64031da177e4SLinus Torvalds /* 64041da177e4SLinus Torvalds * Decode RENAME response 64051da177e4SLinus Torvalds */ 6406bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6407fc016483SChristoph Hellwig void *data) 64081da177e4SLinus Torvalds { 6409fc016483SChristoph Hellwig struct nfs_renameres *res = data; 64101da177e4SLinus Torvalds struct compound_hdr hdr; 64111da177e4SLinus Torvalds int status; 64121da177e4SLinus Torvalds 6413bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64149b7b9fccSAndy Adamson if (status) 64159b7b9fccSAndy Adamson goto out; 6416bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64179b7b9fccSAndy Adamson if (status) 64181da177e4SLinus Torvalds goto out; 6419bf269551SChuck Lever status = decode_putfh(xdr); 6420bf269551SChuck Lever if (status) 64211da177e4SLinus Torvalds goto out; 6422bf269551SChuck Lever status = decode_savefh(xdr); 6423bf269551SChuck Lever if (status) 64241da177e4SLinus Torvalds goto out; 6425bf269551SChuck Lever status = decode_putfh(xdr); 6426bf269551SChuck Lever if (status) 64271da177e4SLinus Torvalds goto out; 6428bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 64291da177e4SLinus Torvalds out: 64301da177e4SLinus Torvalds return status; 64311da177e4SLinus Torvalds } 64321da177e4SLinus Torvalds 64331da177e4SLinus Torvalds /* 64341da177e4SLinus Torvalds * Decode LINK response 64351da177e4SLinus Torvalds */ 6436bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6437fc016483SChristoph Hellwig void *data) 64381da177e4SLinus Torvalds { 6439fc016483SChristoph Hellwig struct nfs4_link_res *res = data; 64401da177e4SLinus Torvalds struct compound_hdr hdr; 64411da177e4SLinus Torvalds int status; 64421da177e4SLinus Torvalds 6443bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64449b7b9fccSAndy Adamson if (status) 64459b7b9fccSAndy Adamson goto out; 6446bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64479b7b9fccSAndy Adamson if (status) 64481da177e4SLinus Torvalds goto out; 6449bf269551SChuck Lever status = decode_putfh(xdr); 6450bf269551SChuck Lever if (status) 64511da177e4SLinus Torvalds goto out; 6452bf269551SChuck Lever status = decode_savefh(xdr); 6453bf269551SChuck Lever if (status) 64541da177e4SLinus Torvalds goto out; 6455bf269551SChuck Lever status = decode_putfh(xdr); 6456bf269551SChuck Lever if (status) 64571da177e4SLinus Torvalds goto out; 6458bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6459bf269551SChuck Lever if (status) 646091ba2eeeSTrond Myklebust goto out; 646191ba2eeeSTrond Myklebust /* 646291ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 646391ba2eeeSTrond Myklebust * filehandle. 646491ba2eeeSTrond Myklebust */ 6465bf269551SChuck Lever status = decode_restorefh(xdr); 6466bf269551SChuck Lever if (status) 646791ba2eeeSTrond Myklebust goto out; 6468aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64691da177e4SLinus Torvalds out: 64701da177e4SLinus Torvalds return status; 64711da177e4SLinus Torvalds } 64721da177e4SLinus Torvalds 64731da177e4SLinus Torvalds /* 64741da177e4SLinus Torvalds * Decode CREATE response 64751da177e4SLinus Torvalds */ 6476bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6477fc016483SChristoph Hellwig void *data) 64781da177e4SLinus Torvalds { 6479fc016483SChristoph Hellwig struct nfs4_create_res *res = data; 64801da177e4SLinus Torvalds struct compound_hdr hdr; 64811da177e4SLinus Torvalds int status; 64821da177e4SLinus Torvalds 6483bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64849b7b9fccSAndy Adamson if (status) 64859b7b9fccSAndy Adamson goto out; 6486bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64879b7b9fccSAndy Adamson if (status) 64881da177e4SLinus Torvalds goto out; 6489bf269551SChuck Lever status = decode_putfh(xdr); 6490bf269551SChuck Lever if (status) 64911da177e4SLinus Torvalds goto out; 6492bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6493bf269551SChuck Lever if (status) 64941da177e4SLinus Torvalds goto out; 6495bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6496bf269551SChuck Lever if (status) 64971da177e4SLinus Torvalds goto out; 6498aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64991da177e4SLinus Torvalds out: 65001da177e4SLinus Torvalds return status; 65011da177e4SLinus Torvalds } 65021da177e4SLinus Torvalds 65031da177e4SLinus Torvalds /* 65041da177e4SLinus Torvalds * Decode SYMLINK response 65051da177e4SLinus Torvalds */ 6506bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6507fc016483SChristoph Hellwig void *res) 65081da177e4SLinus Torvalds { 6509bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 65101da177e4SLinus Torvalds } 65111da177e4SLinus Torvalds 65121da177e4SLinus Torvalds /* 65131da177e4SLinus Torvalds * Decode GETATTR response 65141da177e4SLinus Torvalds */ 6515bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6516fc016483SChristoph Hellwig void *data) 65171da177e4SLinus Torvalds { 6518fc016483SChristoph Hellwig struct nfs4_getattr_res *res = data; 65191da177e4SLinus Torvalds struct compound_hdr hdr; 65201da177e4SLinus Torvalds int status; 65211da177e4SLinus Torvalds 6522bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65231da177e4SLinus Torvalds if (status) 65241da177e4SLinus Torvalds goto out; 6525bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65269b7b9fccSAndy Adamson if (status) 65279b7b9fccSAndy Adamson goto out; 6528bf269551SChuck Lever status = decode_putfh(xdr); 65291da177e4SLinus Torvalds if (status) 65301da177e4SLinus Torvalds goto out; 6531aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 65321da177e4SLinus Torvalds out: 65331da177e4SLinus Torvalds return status; 65341da177e4SLinus Torvalds } 65351da177e4SLinus Torvalds 653623ec6965SJ. Bruce Fields /* 653723ec6965SJ. Bruce Fields * Encode an SETACL request 653823ec6965SJ. Bruce Fields */ 65399f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 6540fcc85819SChristoph Hellwig const void *data) 654123ec6965SJ. Bruce Fields { 6542fcc85819SChristoph Hellwig const struct nfs_setaclargs *args = data; 654323ec6965SJ. Bruce Fields struct compound_hdr hdr = { 654466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 654523ec6965SJ. Bruce Fields }; 654623ec6965SJ. Bruce Fields 65479f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 65489f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 65499f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 65509f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6551d017931cSAndy Adamson encode_nops(&hdr); 655223ec6965SJ. Bruce Fields } 655305d564feSAndy Adamson 655423ec6965SJ. Bruce Fields /* 655523ec6965SJ. Bruce Fields * Decode SETACL response 655623ec6965SJ. Bruce Fields */ 655723ec6965SJ. Bruce Fields static int 6558bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6559fc016483SChristoph Hellwig void *data) 656023ec6965SJ. Bruce Fields { 6561fc016483SChristoph Hellwig struct nfs_setaclres *res = data; 656223ec6965SJ. Bruce Fields struct compound_hdr hdr; 656323ec6965SJ. Bruce Fields int status; 656423ec6965SJ. Bruce Fields 6565bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 656623ec6965SJ. Bruce Fields if (status) 656723ec6965SJ. Bruce Fields goto out; 6568bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65699b7b9fccSAndy Adamson if (status) 65709b7b9fccSAndy Adamson goto out; 6571bf269551SChuck Lever status = decode_putfh(xdr); 657223ec6965SJ. Bruce Fields if (status) 657323ec6965SJ. Bruce Fields goto out; 6574bf269551SChuck Lever status = decode_setattr(xdr); 657523ec6965SJ. Bruce Fields out: 657623ec6965SJ. Bruce Fields return status; 657723ec6965SJ. Bruce Fields } 65781da177e4SLinus Torvalds 65791da177e4SLinus Torvalds /* 6580029d105eSJ. Bruce Fields * Decode GETACL response 6581029d105eSJ. Bruce Fields */ 6582029d105eSJ. Bruce Fields static int 6583bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6584fc016483SChristoph Hellwig void *data) 6585029d105eSJ. Bruce Fields { 6586fc016483SChristoph Hellwig struct nfs_getaclres *res = data; 6587029d105eSJ. Bruce Fields struct compound_hdr hdr; 6588029d105eSJ. Bruce Fields int status; 6589029d105eSJ. Bruce Fields 6590331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6591331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6592331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6593331818f1STrond Myklebust } 6594bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6595029d105eSJ. Bruce Fields if (status) 6596029d105eSJ. Bruce Fields goto out; 6597bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65989b7b9fccSAndy Adamson if (status) 65999b7b9fccSAndy Adamson goto out; 6600bf269551SChuck Lever status = decode_putfh(xdr); 6601029d105eSJ. Bruce Fields if (status) 6602029d105eSJ. Bruce Fields goto out; 6603bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6604029d105eSJ. Bruce Fields 6605029d105eSJ. Bruce Fields out: 6606029d105eSJ. Bruce Fields return status; 6607029d105eSJ. Bruce Fields } 6608029d105eSJ. Bruce Fields 6609029d105eSJ. Bruce Fields /* 66101da177e4SLinus Torvalds * Decode CLOSE response 66111da177e4SLinus Torvalds */ 6612bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6613fc016483SChristoph Hellwig void *data) 66141da177e4SLinus Torvalds { 6615fc016483SChristoph Hellwig struct nfs_closeres *res = data; 66161da177e4SLinus Torvalds struct compound_hdr hdr; 66171da177e4SLinus Torvalds int status; 66181da177e4SLinus Torvalds 6619bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66201da177e4SLinus Torvalds if (status) 66211da177e4SLinus Torvalds goto out; 6622bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66239b7b9fccSAndy Adamson if (status) 66249b7b9fccSAndy Adamson goto out; 6625bf269551SChuck Lever status = decode_putfh(xdr); 66261da177e4SLinus Torvalds if (status) 66271da177e4SLinus Torvalds goto out; 6628cf805165STrond Myklebust if (res->lr_res) { 6629cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6630cf805165STrond Myklebust res->lr_ret = status; 6631cf805165STrond Myklebust if (status) 6632cf805165STrond Myklebust goto out; 6633cf805165STrond Myklebust } 6634d8d84983STrond Myklebust if (res->fattr != NULL) { 6635d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6636516a6af6STrond Myklebust if (status != 0) 6637516a6af6STrond Myklebust goto out; 6638d8d84983STrond Myklebust } 6639d8d84983STrond Myklebust status = decode_close(xdr, res); 66401da177e4SLinus Torvalds out: 66411da177e4SLinus Torvalds return status; 66421da177e4SLinus Torvalds } 66431da177e4SLinus Torvalds 66441da177e4SLinus Torvalds /* 66451da177e4SLinus Torvalds * Decode OPEN response 66461da177e4SLinus Torvalds */ 6647bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6648fc016483SChristoph Hellwig void *data) 66491da177e4SLinus Torvalds { 6650fc016483SChristoph Hellwig struct nfs_openres *res = data; 66511da177e4SLinus Torvalds struct compound_hdr hdr; 66521da177e4SLinus Torvalds int status; 66531da177e4SLinus Torvalds 6654bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66551da177e4SLinus Torvalds if (status) 66561da177e4SLinus Torvalds goto out; 6657bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66589b7b9fccSAndy Adamson if (status) 66599b7b9fccSAndy Adamson goto out; 6660bf269551SChuck Lever status = decode_putfh(xdr); 66611da177e4SLinus Torvalds if (status) 66621da177e4SLinus Torvalds goto out; 6663bf269551SChuck Lever status = decode_open(xdr, res); 66641da177e4SLinus Torvalds if (status) 66651da177e4SLinus Torvalds goto out; 666601913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 666701913b49SWeston Andros Adamson if (status) 66681da177e4SLinus Torvalds goto out; 6669ae2bb032SWeston Andros Adamson if (res->access_request) 66706168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6671aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 667256f487f8SFred Isaman if (res->lg_res) 667356f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res); 66741da177e4SLinus Torvalds out: 66751da177e4SLinus Torvalds return status; 66761da177e4SLinus Torvalds } 66771da177e4SLinus Torvalds 66781da177e4SLinus Torvalds /* 66791da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 66801da177e4SLinus Torvalds */ 6681bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6682bf269551SChuck Lever struct xdr_stream *xdr, 6683fc016483SChristoph Hellwig void *data) 66841da177e4SLinus Torvalds { 6685fc016483SChristoph Hellwig struct nfs_open_confirmres *res = data; 66861da177e4SLinus Torvalds struct compound_hdr hdr; 66871da177e4SLinus Torvalds int status; 66881da177e4SLinus Torvalds 6689bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66901da177e4SLinus Torvalds if (status) 66911da177e4SLinus Torvalds goto out; 6692bf269551SChuck Lever status = decode_putfh(xdr); 66931da177e4SLinus Torvalds if (status) 66941da177e4SLinus Torvalds goto out; 6695bf269551SChuck Lever status = decode_open_confirm(xdr, res); 66961da177e4SLinus Torvalds out: 66971da177e4SLinus Torvalds return status; 66981da177e4SLinus Torvalds } 66991da177e4SLinus Torvalds 67001da177e4SLinus Torvalds /* 67011da177e4SLinus Torvalds * Decode OPEN response 67021da177e4SLinus Torvalds */ 6703bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6704bf269551SChuck Lever struct xdr_stream *xdr, 6705fc016483SChristoph Hellwig void *data) 67061da177e4SLinus Torvalds { 6707fc016483SChristoph Hellwig struct nfs_openres *res = data; 67081da177e4SLinus Torvalds struct compound_hdr hdr; 67091da177e4SLinus Torvalds int status; 67101da177e4SLinus Torvalds 6711bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67121da177e4SLinus Torvalds if (status) 67131da177e4SLinus Torvalds goto out; 6714bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67159b7b9fccSAndy Adamson if (status) 67169b7b9fccSAndy Adamson goto out; 6717bf269551SChuck Lever status = decode_putfh(xdr); 67181da177e4SLinus Torvalds if (status) 67191da177e4SLinus Torvalds goto out; 6720bf269551SChuck Lever status = decode_open(xdr, res); 6721864472e9STrond Myklebust if (status) 6722864472e9STrond Myklebust goto out; 6723ae2bb032SWeston Andros Adamson if (res->access_request) 67246168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 67256926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 672656f487f8SFred Isaman if (res->lg_res) 672756f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res); 67281da177e4SLinus Torvalds out: 67291da177e4SLinus Torvalds return status; 67301da177e4SLinus Torvalds } 67311da177e4SLinus Torvalds 67321da177e4SLinus Torvalds /* 67331da177e4SLinus Torvalds * Decode SETATTR response 67341da177e4SLinus Torvalds */ 6735bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6736bf269551SChuck Lever struct xdr_stream *xdr, 6737fc016483SChristoph Hellwig void *data) 67381da177e4SLinus Torvalds { 6739fc016483SChristoph Hellwig struct nfs_setattrres *res = data; 67401da177e4SLinus Torvalds struct compound_hdr hdr; 67411da177e4SLinus Torvalds int status; 67421da177e4SLinus Torvalds 6743bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67441da177e4SLinus Torvalds if (status) 67451da177e4SLinus Torvalds goto out; 6746bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67479b7b9fccSAndy Adamson if (status) 67489b7b9fccSAndy Adamson goto out; 6749bf269551SChuck Lever status = decode_putfh(xdr); 67501da177e4SLinus Torvalds if (status) 67511da177e4SLinus Torvalds goto out; 6752bf269551SChuck Lever status = decode_setattr(xdr); 67531da177e4SLinus Torvalds if (status) 67541da177e4SLinus Torvalds goto out; 6755aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 67561da177e4SLinus Torvalds out: 67571da177e4SLinus Torvalds return status; 67581da177e4SLinus Torvalds } 67591da177e4SLinus Torvalds 67601da177e4SLinus Torvalds /* 67611da177e4SLinus Torvalds * Decode LOCK response 67621da177e4SLinus Torvalds */ 6763bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6764fc016483SChristoph Hellwig void *data) 67651da177e4SLinus Torvalds { 6766fc016483SChristoph Hellwig struct nfs_lock_res *res = data; 67671da177e4SLinus Torvalds struct compound_hdr hdr; 67681da177e4SLinus Torvalds int status; 67691da177e4SLinus Torvalds 6770bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67711da177e4SLinus Torvalds if (status) 67721da177e4SLinus Torvalds goto out; 6773bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67749b7b9fccSAndy Adamson if (status) 67759b7b9fccSAndy Adamson goto out; 6776bf269551SChuck Lever status = decode_putfh(xdr); 67771da177e4SLinus Torvalds if (status) 67781da177e4SLinus Torvalds goto out; 6779bf269551SChuck Lever status = decode_lock(xdr, res); 67801da177e4SLinus Torvalds out: 67811da177e4SLinus Torvalds return status; 67821da177e4SLinus Torvalds } 67831da177e4SLinus Torvalds 67841da177e4SLinus Torvalds /* 67851da177e4SLinus Torvalds * Decode LOCKT response 67861da177e4SLinus Torvalds */ 6787bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6788fc016483SChristoph Hellwig void *data) 67891da177e4SLinus Torvalds { 6790fc016483SChristoph Hellwig struct nfs_lockt_res *res = data; 67911da177e4SLinus Torvalds struct compound_hdr hdr; 67921da177e4SLinus Torvalds int status; 67931da177e4SLinus Torvalds 6794bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67951da177e4SLinus Torvalds if (status) 67961da177e4SLinus Torvalds goto out; 6797bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67989b7b9fccSAndy Adamson if (status) 67999b7b9fccSAndy Adamson goto out; 6800bf269551SChuck Lever status = decode_putfh(xdr); 68011da177e4SLinus Torvalds if (status) 68021da177e4SLinus Torvalds goto out; 6803bf269551SChuck Lever status = decode_lockt(xdr, res); 68041da177e4SLinus Torvalds out: 68051da177e4SLinus Torvalds return status; 68061da177e4SLinus Torvalds } 68071da177e4SLinus Torvalds 68081da177e4SLinus Torvalds /* 68091da177e4SLinus Torvalds * Decode LOCKU response 68101da177e4SLinus Torvalds */ 6811bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6812fc016483SChristoph Hellwig void *data) 68131da177e4SLinus Torvalds { 6814fc016483SChristoph Hellwig struct nfs_locku_res *res = data; 68151da177e4SLinus Torvalds struct compound_hdr hdr; 68161da177e4SLinus Torvalds int status; 68171da177e4SLinus Torvalds 6818bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68191da177e4SLinus Torvalds if (status) 68201da177e4SLinus Torvalds goto out; 6821bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68229b7b9fccSAndy Adamson if (status) 68239b7b9fccSAndy Adamson goto out; 6824bf269551SChuck Lever status = decode_putfh(xdr); 68251da177e4SLinus Torvalds if (status) 68261da177e4SLinus Torvalds goto out; 6827bf269551SChuck Lever status = decode_locku(xdr, res); 68281da177e4SLinus Torvalds out: 68291da177e4SLinus Torvalds return status; 68301da177e4SLinus Torvalds } 68311da177e4SLinus Torvalds 6832bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6833bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6834d3c7b7ccSTrond Myklebust { 6835d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6836d3c7b7ccSTrond Myklebust int status; 6837d3c7b7ccSTrond Myklebust 6838bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6839d3c7b7ccSTrond Myklebust if (!status) 6840bf269551SChuck Lever status = decode_release_lockowner(xdr); 6841d3c7b7ccSTrond Myklebust return status; 6842d3c7b7ccSTrond Myklebust } 6843d3c7b7ccSTrond Myklebust 68441da177e4SLinus Torvalds /* 68451da177e4SLinus Torvalds * Decode READLINK response 68461da177e4SLinus Torvalds */ 6847bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6848bf269551SChuck Lever struct xdr_stream *xdr, 6849fc016483SChristoph Hellwig void *data) 68501da177e4SLinus Torvalds { 6851fc016483SChristoph Hellwig struct nfs4_readlink_res *res = data; 68521da177e4SLinus Torvalds struct compound_hdr hdr; 68531da177e4SLinus Torvalds int status; 68541da177e4SLinus Torvalds 6855bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68561da177e4SLinus Torvalds if (status) 68571da177e4SLinus Torvalds goto out; 6858bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68599b7b9fccSAndy Adamson if (status) 68609b7b9fccSAndy Adamson goto out; 6861bf269551SChuck Lever status = decode_putfh(xdr); 68621da177e4SLinus Torvalds if (status) 68631da177e4SLinus Torvalds goto out; 6864bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 68651da177e4SLinus Torvalds out: 68661da177e4SLinus Torvalds return status; 68671da177e4SLinus Torvalds } 68681da177e4SLinus Torvalds 68691da177e4SLinus Torvalds /* 68701da177e4SLinus Torvalds * Decode READDIR response 68711da177e4SLinus Torvalds */ 6872bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6873fc016483SChristoph Hellwig void *data) 68741da177e4SLinus Torvalds { 6875fc016483SChristoph Hellwig struct nfs4_readdir_res *res = data; 68761da177e4SLinus Torvalds struct compound_hdr hdr; 68771da177e4SLinus Torvalds int status; 68781da177e4SLinus Torvalds 6879bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68801da177e4SLinus Torvalds if (status) 68811da177e4SLinus Torvalds goto out; 6882bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 68839b7b9fccSAndy Adamson if (status) 68849b7b9fccSAndy Adamson goto out; 6885bf269551SChuck Lever status = decode_putfh(xdr); 68861da177e4SLinus Torvalds if (status) 68871da177e4SLinus Torvalds goto out; 6888bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 68891da177e4SLinus Torvalds out: 68901da177e4SLinus Torvalds return status; 68911da177e4SLinus Torvalds } 68921da177e4SLinus Torvalds 68931da177e4SLinus Torvalds /* 68941da177e4SLinus Torvalds * Decode Read response 68951da177e4SLinus Torvalds */ 6896bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6897fc016483SChristoph Hellwig void *data) 68981da177e4SLinus Torvalds { 6899fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 69001da177e4SLinus Torvalds struct compound_hdr hdr; 69011da177e4SLinus Torvalds int status; 69021da177e4SLinus Torvalds 6903bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6904aabff4ddSPeng Tao res->op_status = hdr.status; 69051da177e4SLinus Torvalds if (status) 69061da177e4SLinus Torvalds goto out; 6907bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69089b7b9fccSAndy Adamson if (status) 69099b7b9fccSAndy Adamson goto out; 6910bf269551SChuck Lever status = decode_putfh(xdr); 69111da177e4SLinus Torvalds if (status) 69121da177e4SLinus Torvalds goto out; 6913bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 69141da177e4SLinus Torvalds if (!status) 69151da177e4SLinus Torvalds status = res->count; 69161da177e4SLinus Torvalds out: 69171da177e4SLinus Torvalds return status; 69181da177e4SLinus Torvalds } 69191da177e4SLinus Torvalds 69201da177e4SLinus Torvalds /* 69211da177e4SLinus Torvalds * Decode WRITE response 69221da177e4SLinus Torvalds */ 6923bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6924fc016483SChristoph Hellwig void *data) 69251da177e4SLinus Torvalds { 6926fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 69271da177e4SLinus Torvalds struct compound_hdr hdr; 69281da177e4SLinus Torvalds int status; 69291da177e4SLinus Torvalds 6930bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6931aabff4ddSPeng Tao res->op_status = hdr.status; 69321da177e4SLinus Torvalds if (status) 69331da177e4SLinus Torvalds goto out; 6934bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69359b7b9fccSAndy Adamson if (status) 69369b7b9fccSAndy Adamson goto out; 6937bf269551SChuck Lever status = decode_putfh(xdr); 69381da177e4SLinus Torvalds if (status) 69391da177e4SLinus Torvalds goto out; 6940bf269551SChuck Lever status = decode_write(xdr, res); 69414f9838c7STrond Myklebust if (status) 69424f9838c7STrond Myklebust goto out; 69437ffd1064SFred Isaman if (res->fattr) 69446926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 69451da177e4SLinus Torvalds if (!status) 69461da177e4SLinus Torvalds status = res->count; 69471da177e4SLinus Torvalds out: 69481da177e4SLinus Torvalds return status; 69491da177e4SLinus Torvalds } 69501da177e4SLinus Torvalds 69511da177e4SLinus Torvalds /* 69521da177e4SLinus Torvalds * Decode COMMIT response 69531da177e4SLinus Torvalds */ 6954bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6955fc016483SChristoph Hellwig void *data) 69561da177e4SLinus Torvalds { 6957fc016483SChristoph Hellwig struct nfs_commitres *res = data; 69581da177e4SLinus Torvalds struct compound_hdr hdr; 69591da177e4SLinus Torvalds int status; 69601da177e4SLinus Torvalds 6961bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6962aabff4ddSPeng Tao res->op_status = hdr.status; 69631da177e4SLinus Torvalds if (status) 69641da177e4SLinus Torvalds goto out; 6965bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69669b7b9fccSAndy Adamson if (status) 69679b7b9fccSAndy Adamson goto out; 6968bf269551SChuck Lever status = decode_putfh(xdr); 69691da177e4SLinus Torvalds if (status) 69701da177e4SLinus Torvalds goto out; 6971bf269551SChuck Lever status = decode_commit(xdr, res); 69721da177e4SLinus Torvalds out: 69731da177e4SLinus Torvalds return status; 69741da177e4SLinus Torvalds } 69751da177e4SLinus Torvalds 69761da177e4SLinus Torvalds /* 69778b173218SRicardo Labiaga * Decode FSINFO response 69781da177e4SLinus Torvalds */ 6979bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 6980fc016483SChristoph Hellwig void *data) 69811da177e4SLinus Torvalds { 6982fc016483SChristoph Hellwig struct nfs4_fsinfo_res *res = data; 69831da177e4SLinus Torvalds struct compound_hdr hdr; 69841da177e4SLinus Torvalds int status; 69851da177e4SLinus Torvalds 6986bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69871da177e4SLinus Torvalds if (!status) 6988bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69899b7b9fccSAndy Adamson if (!status) 6990bf269551SChuck Lever status = decode_putfh(xdr); 69911da177e4SLinus Torvalds if (!status) 6992bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 69931da177e4SLinus Torvalds return status; 69941da177e4SLinus Torvalds } 69951da177e4SLinus Torvalds 69961da177e4SLinus Torvalds /* 69978b173218SRicardo Labiaga * Decode PATHCONF response 69981da177e4SLinus Torvalds */ 6999bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 7000fc016483SChristoph Hellwig void *data) 70011da177e4SLinus Torvalds { 7002fc016483SChristoph Hellwig struct nfs4_pathconf_res *res = data; 70031da177e4SLinus Torvalds struct compound_hdr hdr; 70041da177e4SLinus Torvalds int status; 70051da177e4SLinus Torvalds 7006bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70071da177e4SLinus Torvalds if (!status) 7008bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70099b7b9fccSAndy Adamson if (!status) 7010bf269551SChuck Lever status = decode_putfh(xdr); 70111da177e4SLinus Torvalds if (!status) 7012bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 70131da177e4SLinus Torvalds return status; 70141da177e4SLinus Torvalds } 70151da177e4SLinus Torvalds 70161da177e4SLinus Torvalds /* 70178b173218SRicardo Labiaga * Decode STATFS response 70181da177e4SLinus Torvalds */ 7019bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 7020fc016483SChristoph Hellwig void *data) 70211da177e4SLinus Torvalds { 7022fc016483SChristoph Hellwig struct nfs4_statfs_res *res = data; 70231da177e4SLinus Torvalds struct compound_hdr hdr; 70241da177e4SLinus Torvalds int status; 70251da177e4SLinus Torvalds 7026bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70271da177e4SLinus Torvalds if (!status) 7028bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70299b7b9fccSAndy Adamson if (!status) 7030bf269551SChuck Lever status = decode_putfh(xdr); 70311da177e4SLinus Torvalds if (!status) 7032bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 70331da177e4SLinus Torvalds return status; 70341da177e4SLinus Torvalds } 70351da177e4SLinus Torvalds 70361da177e4SLinus Torvalds /* 70378b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 70381da177e4SLinus Torvalds */ 7039bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 7040bf269551SChuck Lever struct xdr_stream *xdr, 7041fc016483SChristoph Hellwig void *data) 70421da177e4SLinus Torvalds { 7043fc016483SChristoph Hellwig struct nfs4_server_caps_res *res = data; 70441da177e4SLinus Torvalds struct compound_hdr hdr; 70451da177e4SLinus Torvalds int status; 70461da177e4SLinus Torvalds 7047bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70489b7b9fccSAndy Adamson if (status) 70499b7b9fccSAndy Adamson goto out; 7050bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 70519b7b9fccSAndy Adamson if (status) 70521da177e4SLinus Torvalds goto out; 7053bf269551SChuck Lever status = decode_putfh(xdr); 7054bf269551SChuck Lever if (status) 70551da177e4SLinus Torvalds goto out; 7056bf269551SChuck Lever status = decode_server_caps(xdr, res); 70571da177e4SLinus Torvalds out: 70581da177e4SLinus Torvalds return status; 70591da177e4SLinus Torvalds } 70601da177e4SLinus Torvalds 70611da177e4SLinus Torvalds /* 70621da177e4SLinus Torvalds * Decode RENEW response 70631da177e4SLinus Torvalds */ 7064bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 7065bf269551SChuck Lever void *__unused) 70661da177e4SLinus Torvalds { 70671da177e4SLinus Torvalds struct compound_hdr hdr; 70681da177e4SLinus Torvalds int status; 70691da177e4SLinus Torvalds 7070bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70711da177e4SLinus Torvalds if (!status) 7072bf269551SChuck Lever status = decode_renew(xdr); 70731da177e4SLinus Torvalds return status; 70741da177e4SLinus Torvalds } 70751da177e4SLinus Torvalds 70761da177e4SLinus Torvalds /* 70778b173218SRicardo Labiaga * Decode SETCLIENTID response 70781da177e4SLinus Torvalds */ 7079bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 7080bf269551SChuck Lever struct xdr_stream *xdr, 7081fc016483SChristoph Hellwig void *data) 70821da177e4SLinus Torvalds { 7083fc016483SChristoph Hellwig struct nfs4_setclientid_res *res = data; 70841da177e4SLinus Torvalds struct compound_hdr hdr; 70851da177e4SLinus Torvalds int status; 70861da177e4SLinus Torvalds 7087bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70881da177e4SLinus Torvalds if (!status) 7089bf269551SChuck Lever status = decode_setclientid(xdr, res); 70901da177e4SLinus Torvalds return status; 70911da177e4SLinus Torvalds } 70921da177e4SLinus Torvalds 70931da177e4SLinus Torvalds /* 70948b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 70951da177e4SLinus Torvalds */ 7096bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 7097fc016483SChristoph Hellwig struct xdr_stream *xdr, 7098fc016483SChristoph Hellwig void *data) 70991da177e4SLinus Torvalds { 71001da177e4SLinus Torvalds struct compound_hdr hdr; 71011da177e4SLinus Torvalds int status; 71021da177e4SLinus Torvalds 7103bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71041da177e4SLinus Torvalds if (!status) 7105bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 71061da177e4SLinus Torvalds return status; 71071da177e4SLinus Torvalds } 71081da177e4SLinus Torvalds 71091da177e4SLinus Torvalds /* 71108b173218SRicardo Labiaga * Decode DELEGRETURN response 71111da177e4SLinus Torvalds */ 7112bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 7113bf269551SChuck Lever struct xdr_stream *xdr, 7114fc016483SChristoph Hellwig void *data) 71151da177e4SLinus Torvalds { 7116fc016483SChristoph Hellwig struct nfs4_delegreturnres *res = data; 71171da177e4SLinus Torvalds struct compound_hdr hdr; 71181da177e4SLinus Torvalds int status; 71191da177e4SLinus Torvalds 7120bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71219b7b9fccSAndy Adamson if (status) 71229b7b9fccSAndy Adamson goto out; 7123bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 71249b7b9fccSAndy Adamson if (status) 7125fa178f29STrond Myklebust goto out; 7126bf269551SChuck Lever status = decode_putfh(xdr); 7127fa178f29STrond Myklebust if (status != 0) 7128fa178f29STrond Myklebust goto out; 7129586f1c39STrond Myklebust if (res->lr_res) { 7130586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 7131586f1c39STrond Myklebust res->lr_ret = status; 7132586f1c39STrond Myklebust if (status) 7133586f1c39STrond Myklebust goto out; 7134586f1c39STrond Myklebust } 71358ac2b422STrond Myklebust if (res->fattr) { 7136e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 7137556ae3bbSJeff Layton if (status != 0) 7138556ae3bbSJeff Layton goto out; 71398ac2b422STrond Myklebust } 7140e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 7141fa178f29STrond Myklebust out: 71421da177e4SLinus Torvalds return status; 71431da177e4SLinus Torvalds } 71441da177e4SLinus Torvalds 7145683b57b4STrond Myklebust /* 71468b173218SRicardo Labiaga * Decode FS_LOCATIONS response 7147683b57b4STrond Myklebust */ 7148bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 7149bf269551SChuck Lever struct xdr_stream *xdr, 7150fc016483SChristoph Hellwig void *data) 7151683b57b4STrond Myklebust { 7152fc016483SChristoph Hellwig struct nfs4_fs_locations_res *res = data; 7153683b57b4STrond Myklebust struct compound_hdr hdr; 7154683b57b4STrond Myklebust int status; 7155683b57b4STrond Myklebust 7156bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71579b7b9fccSAndy Adamson if (status) 71589b7b9fccSAndy Adamson goto out; 7159bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 71609b7b9fccSAndy Adamson if (status) 7161683b57b4STrond Myklebust goto out; 7162bf269551SChuck Lever status = decode_putfh(xdr); 7163bf269551SChuck Lever if (status) 7164683b57b4STrond Myklebust goto out; 7165b03d735bSChuck Lever if (res->migration) { 7166b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7167b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7168b03d735bSChuck Lever &res->fs_locations->fattr, 7169b03d735bSChuck Lever NULL, res->fs_locations, 7170b03d735bSChuck Lever NULL, res->fs_locations->server); 7171b03d735bSChuck Lever if (status) 7172b03d735bSChuck Lever goto out; 7173b03d735bSChuck Lever if (res->renew) 7174b03d735bSChuck Lever status = decode_renew(xdr); 7175b03d735bSChuck Lever } else { 7176bf269551SChuck Lever status = decode_lookup(xdr); 7177bf269551SChuck Lever if (status) 7178683b57b4STrond Myklebust goto out; 7179bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 7180b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7181b03d735bSChuck Lever &res->fs_locations->fattr, 71828b7e3f49STrond Myklebust NULL, res->fs_locations, 7183aa9c2669SDavid Quigley NULL, res->fs_locations->server); 7184b03d735bSChuck Lever } 7185683b57b4STrond Myklebust out: 7186683b57b4STrond Myklebust return status; 7187683b57b4STrond Myklebust } 7188683b57b4STrond Myklebust 71895a5ea0d4SBryan Schumaker /* 71905a5ea0d4SBryan Schumaker * Decode SECINFO response 71915a5ea0d4SBryan Schumaker */ 71925a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 71935a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 7194fc016483SChristoph Hellwig void *data) 71955a5ea0d4SBryan Schumaker { 7196fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 71975a5ea0d4SBryan Schumaker struct compound_hdr hdr; 71985a5ea0d4SBryan Schumaker int status; 71995a5ea0d4SBryan Schumaker 72005a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 72015a5ea0d4SBryan Schumaker if (status) 72025a5ea0d4SBryan Schumaker goto out; 72035a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 72045a5ea0d4SBryan Schumaker if (status) 72055a5ea0d4SBryan Schumaker goto out; 72065a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 72075a5ea0d4SBryan Schumaker if (status) 72085a5ea0d4SBryan Schumaker goto out; 72095a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 72105a5ea0d4SBryan Schumaker out: 72115a5ea0d4SBryan Schumaker return status; 72125a5ea0d4SBryan Schumaker } 72135a5ea0d4SBryan Schumaker 721444c99933SChuck Lever /* 721544c99933SChuck Lever * Decode FSID_PRESENT response 721644c99933SChuck Lever */ 721744c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 721844c99933SChuck Lever struct xdr_stream *xdr, 7219fc016483SChristoph Hellwig void *data) 722044c99933SChuck Lever { 7221fc016483SChristoph Hellwig struct nfs4_fsid_present_res *res = data; 722244c99933SChuck Lever struct compound_hdr hdr; 722344c99933SChuck Lever int status; 722444c99933SChuck Lever 722544c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 722644c99933SChuck Lever if (status) 722744c99933SChuck Lever goto out; 722844c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 722944c99933SChuck Lever if (status) 723044c99933SChuck Lever goto out; 723144c99933SChuck Lever status = decode_putfh(xdr); 723244c99933SChuck Lever if (status) 723344c99933SChuck Lever goto out; 723444c99933SChuck Lever status = decode_getfh(xdr, res->fh); 723544c99933SChuck Lever if (status) 723644c99933SChuck Lever goto out; 723744c99933SChuck Lever if (res->renew) 723844c99933SChuck Lever status = decode_renew(xdr); 723944c99933SChuck Lever out: 724044c99933SChuck Lever return status; 724144c99933SChuck Lever } 724244c99933SChuck Lever 724399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 724499fe60d0SBenny Halevy /* 72457c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 72467c44f1aeSWeston Andros Adamson */ 72477c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 72487c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 72497c44f1aeSWeston Andros Adamson void *res) 72507c44f1aeSWeston Andros Adamson { 72517c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 72527c44f1aeSWeston Andros Adamson int status; 72537c44f1aeSWeston Andros Adamson 72547c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 72557c44f1aeSWeston Andros Adamson if (!status) 72567c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 72577c44f1aeSWeston Andros Adamson return status; 72587c44f1aeSWeston Andros Adamson } 72597c44f1aeSWeston Andros Adamson 72607c44f1aeSWeston Andros Adamson /* 72618b173218SRicardo Labiaga * Decode EXCHANGE_ID response 726299fe60d0SBenny Halevy */ 7263bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7264bf269551SChuck Lever struct xdr_stream *xdr, 726599fe60d0SBenny Halevy void *res) 726699fe60d0SBenny Halevy { 726799fe60d0SBenny Halevy struct compound_hdr hdr; 726899fe60d0SBenny Halevy int status; 726999fe60d0SBenny Halevy 7270bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 727199fe60d0SBenny Halevy if (!status) 7272bf269551SChuck Lever status = decode_exchange_id(xdr, res); 727399fe60d0SBenny Halevy return status; 727499fe60d0SBenny Halevy } 72752050f0ccSAndy Adamson 72762050f0ccSAndy Adamson /* 72778b173218SRicardo Labiaga * Decode CREATE_SESSION response 7278fc931582SAndy Adamson */ 7279bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7280bf269551SChuck Lever struct xdr_stream *xdr, 7281fc016483SChristoph Hellwig void *res) 7282fc931582SAndy Adamson { 7283fc931582SAndy Adamson struct compound_hdr hdr; 7284fc931582SAndy Adamson int status; 7285fc931582SAndy Adamson 7286bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7287fc931582SAndy Adamson if (!status) 7288bf269551SChuck Lever status = decode_create_session(xdr, res); 7289fc931582SAndy Adamson return status; 7290fc931582SAndy Adamson } 7291fc931582SAndy Adamson 7292fc931582SAndy Adamson /* 72938b173218SRicardo Labiaga * Decode DESTROY_SESSION response 72940f3e66c6SAndy Adamson */ 7295bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7296bf269551SChuck Lever struct xdr_stream *xdr, 7297bf269551SChuck Lever void *res) 72980f3e66c6SAndy Adamson { 72990f3e66c6SAndy Adamson struct compound_hdr hdr; 73000f3e66c6SAndy Adamson int status; 73010f3e66c6SAndy Adamson 7302bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 73030f3e66c6SAndy Adamson if (!status) 7304bf269551SChuck Lever status = decode_destroy_session(xdr, res); 73050f3e66c6SAndy Adamson return status; 73060f3e66c6SAndy Adamson } 73070f3e66c6SAndy Adamson 73080f3e66c6SAndy Adamson /* 730966245539STrond Myklebust * Decode DESTROY_CLIENTID response 731066245539STrond Myklebust */ 731166245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 731266245539STrond Myklebust struct xdr_stream *xdr, 731366245539STrond Myklebust void *res) 731466245539STrond Myklebust { 731566245539STrond Myklebust struct compound_hdr hdr; 731666245539STrond Myklebust int status; 731766245539STrond Myklebust 731866245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 731966245539STrond Myklebust if (!status) 732066245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 732166245539STrond Myklebust return status; 732266245539STrond Myklebust } 732366245539STrond Myklebust 732466245539STrond Myklebust /* 73258b173218SRicardo Labiaga * Decode SEQUENCE response 7326fc01cea9SAndy Adamson */ 7327bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7328bf269551SChuck Lever struct xdr_stream *xdr, 7329fc016483SChristoph Hellwig void *res) 7330fc01cea9SAndy Adamson { 7331fc01cea9SAndy Adamson struct compound_hdr hdr; 7332fc01cea9SAndy Adamson int status; 7333fc01cea9SAndy Adamson 7334bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7335fc01cea9SAndy Adamson if (!status) 7336bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7337fc01cea9SAndy Adamson return status; 7338fc01cea9SAndy Adamson } 7339fc01cea9SAndy Adamson 7340fc01cea9SAndy Adamson /* 73418b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 73422050f0ccSAndy Adamson */ 7343bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7344bf269551SChuck Lever struct xdr_stream *xdr, 7345fc016483SChristoph Hellwig void *data) 73462050f0ccSAndy Adamson { 7347fc016483SChristoph Hellwig struct nfs4_get_lease_time_res *res = data; 73482050f0ccSAndy Adamson struct compound_hdr hdr; 73492050f0ccSAndy Adamson int status; 73502050f0ccSAndy Adamson 7351bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 73522050f0ccSAndy Adamson if (!status) 7353bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 73542050f0ccSAndy Adamson if (!status) 7355bf269551SChuck Lever status = decode_putrootfh(xdr); 73562050f0ccSAndy Adamson if (!status) 7357bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 73582050f0ccSAndy Adamson return status; 73592050f0ccSAndy Adamson } 736018019753SRicardo Labiaga 736118019753SRicardo Labiaga /* 736218019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 736318019753SRicardo Labiaga */ 7364bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7365bf269551SChuck Lever struct xdr_stream *xdr, 7366fc016483SChristoph Hellwig void *data) 736718019753SRicardo Labiaga { 7368fc016483SChristoph Hellwig struct nfs41_reclaim_complete_res *res = data; 736918019753SRicardo Labiaga struct compound_hdr hdr; 737018019753SRicardo Labiaga int status; 737118019753SRicardo Labiaga 7372bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 737318019753SRicardo Labiaga if (!status) 7374bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 737518019753SRicardo Labiaga if (!status) 73768ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 737718019753SRicardo Labiaga return status; 737818019753SRicardo Labiaga } 7379b1f69b75SAndy Adamson 7380b1f69b75SAndy Adamson /* 7381b1f69b75SAndy Adamson * Decode GETDEVINFO response 7382b1f69b75SAndy Adamson */ 7383bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7384bf269551SChuck Lever struct xdr_stream *xdr, 7385fc016483SChristoph Hellwig void *data) 7386b1f69b75SAndy Adamson { 7387fc016483SChristoph Hellwig struct nfs4_getdeviceinfo_res *res = data; 7388b1f69b75SAndy Adamson struct compound_hdr hdr; 7389b1f69b75SAndy Adamson int status; 7390b1f69b75SAndy Adamson 7391bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7392b1f69b75SAndy Adamson if (status != 0) 7393b1f69b75SAndy Adamson goto out; 7394bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7395b1f69b75SAndy Adamson if (status != 0) 7396b1f69b75SAndy Adamson goto out; 73974e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7398b1f69b75SAndy Adamson out: 7399b1f69b75SAndy Adamson return status; 7400b1f69b75SAndy Adamson } 7401b1f69b75SAndy Adamson 7402b1f69b75SAndy Adamson /* 7403b1f69b75SAndy Adamson * Decode LAYOUTGET response 7404b1f69b75SAndy Adamson */ 7405bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7406bf269551SChuck Lever struct xdr_stream *xdr, 7407fc016483SChristoph Hellwig void *data) 7408b1f69b75SAndy Adamson { 7409fc016483SChristoph Hellwig struct nfs4_layoutget_res *res = data; 7410b1f69b75SAndy Adamson struct compound_hdr hdr; 7411b1f69b75SAndy Adamson int status; 7412b1f69b75SAndy Adamson 7413bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7414b1f69b75SAndy Adamson if (status) 7415b1f69b75SAndy Adamson goto out; 7416bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7417b1f69b75SAndy Adamson if (status) 7418b1f69b75SAndy Adamson goto out; 7419bf269551SChuck Lever status = decode_putfh(xdr); 7420b1f69b75SAndy Adamson if (status) 7421b1f69b75SAndy Adamson goto out; 7422bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7423b1f69b75SAndy Adamson out: 7424b1f69b75SAndy Adamson return status; 7425b1f69b75SAndy Adamson } 7426863a3c6cSAndy Adamson 7427863a3c6cSAndy Adamson /* 7428cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7429cbe82603SBenny Halevy */ 7430cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7431cbe82603SBenny Halevy struct xdr_stream *xdr, 7432fc016483SChristoph Hellwig void *data) 7433cbe82603SBenny Halevy { 7434fc016483SChristoph Hellwig struct nfs4_layoutreturn_res *res = data; 7435cbe82603SBenny Halevy struct compound_hdr hdr; 7436cbe82603SBenny Halevy int status; 7437cbe82603SBenny Halevy 7438cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7439cbe82603SBenny Halevy if (status) 7440cbe82603SBenny Halevy goto out; 7441cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7442cbe82603SBenny Halevy if (status) 7443cbe82603SBenny Halevy goto out; 7444cbe82603SBenny Halevy status = decode_putfh(xdr); 7445cbe82603SBenny Halevy if (status) 7446cbe82603SBenny Halevy goto out; 7447cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7448cbe82603SBenny Halevy out: 7449cbe82603SBenny Halevy return status; 7450cbe82603SBenny Halevy } 7451cbe82603SBenny Halevy 7452cbe82603SBenny Halevy /* 7453863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7454863a3c6cSAndy Adamson */ 7455863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7456863a3c6cSAndy Adamson struct xdr_stream *xdr, 7457fc016483SChristoph Hellwig void *data) 7458863a3c6cSAndy Adamson { 7459fc016483SChristoph Hellwig struct nfs4_layoutcommit_res *res = data; 7460863a3c6cSAndy Adamson struct compound_hdr hdr; 7461863a3c6cSAndy Adamson int status; 7462863a3c6cSAndy Adamson 7463863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7464863a3c6cSAndy Adamson if (status) 7465863a3c6cSAndy Adamson goto out; 7466863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7467863a3c6cSAndy Adamson if (status) 7468863a3c6cSAndy Adamson goto out; 7469863a3c6cSAndy Adamson status = decode_putfh(xdr); 7470863a3c6cSAndy Adamson if (status) 7471863a3c6cSAndy Adamson goto out; 7472863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7473863a3c6cSAndy Adamson if (status) 7474863a3c6cSAndy Adamson goto out; 74756926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7476863a3c6cSAndy Adamson out: 7477863a3c6cSAndy Adamson return status; 7478863a3c6cSAndy Adamson } 7479fca78d6dSBryan Schumaker 7480fca78d6dSBryan Schumaker /* 7481fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7482fca78d6dSBryan Schumaker */ 7483fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7484fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7485fc016483SChristoph Hellwig void *data) 7486fca78d6dSBryan Schumaker { 7487fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 7488fca78d6dSBryan Schumaker struct compound_hdr hdr; 7489fca78d6dSBryan Schumaker int status; 7490fca78d6dSBryan Schumaker 7491fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7492fca78d6dSBryan Schumaker if (status) 7493fca78d6dSBryan Schumaker goto out; 7494fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7495fca78d6dSBryan Schumaker if (status) 7496fca78d6dSBryan Schumaker goto out; 7497fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7498fca78d6dSBryan Schumaker if (status) 7499fca78d6dSBryan Schumaker goto out; 750031e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7501fca78d6dSBryan Schumaker out: 7502fca78d6dSBryan Schumaker return status; 7503fca78d6dSBryan Schumaker } 75047d974794SBryan Schumaker 75057d974794SBryan Schumaker /* 75067d974794SBryan Schumaker * Decode TEST_STATEID response 75077d974794SBryan Schumaker */ 75087d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 75097d974794SBryan Schumaker struct xdr_stream *xdr, 7510fc016483SChristoph Hellwig void *data) 75117d974794SBryan Schumaker { 7512fc016483SChristoph Hellwig struct nfs41_test_stateid_res *res = data; 75137d974794SBryan Schumaker struct compound_hdr hdr; 75147d974794SBryan Schumaker int status; 75157d974794SBryan Schumaker 75167d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 75177d974794SBryan Schumaker if (status) 75187d974794SBryan Schumaker goto out; 75197d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 75207d974794SBryan Schumaker if (status) 75217d974794SBryan Schumaker goto out; 75227d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 75237d974794SBryan Schumaker out: 75247d974794SBryan Schumaker return status; 75257d974794SBryan Schumaker } 75269aeda35fSBryan Schumaker 75279aeda35fSBryan Schumaker /* 75289aeda35fSBryan Schumaker * Decode FREE_STATEID response 75299aeda35fSBryan Schumaker */ 75309aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 75319aeda35fSBryan Schumaker struct xdr_stream *xdr, 7532fc016483SChristoph Hellwig void *data) 75339aeda35fSBryan Schumaker { 7534fc016483SChristoph Hellwig struct nfs41_free_stateid_res *res = data; 75359aeda35fSBryan Schumaker struct compound_hdr hdr; 75369aeda35fSBryan Schumaker int status; 75379aeda35fSBryan Schumaker 75389aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 75399aeda35fSBryan Schumaker if (status) 75409aeda35fSBryan Schumaker goto out; 75419aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 75429aeda35fSBryan Schumaker if (status) 75439aeda35fSBryan Schumaker goto out; 75449aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 75459aeda35fSBryan Schumaker out: 75469aeda35fSBryan Schumaker return status; 75479aeda35fSBryan Schumaker } 754899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 754999fe60d0SBenny Halevy 7550573c4e1eSChuck Lever /** 7551573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7552573c4e1eSChuck Lever * the local page cache. 7553573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7554573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7555573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7556573c4e1eSChuck Lever * 7557573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7558573c4e1eSChuck Lever * returned. 7559573c4e1eSChuck Lever * 7560573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7561573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7562573c4e1eSChuck Lever * on a directory already in our cache. 7563573c4e1eSChuck Lever */ 7564573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7565a7a3b1e9SBenjamin Coddington bool plus) 75661da177e4SLinus Torvalds { 7567256e48bbSTrond Myklebust unsigned int savep; 7568dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 75691da177e4SLinus Torvalds uint32_t len; 757098de9ce6SFrank Sorenson uint64_t new_cookie; 7571babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7572babddc72SBryan Schumaker if (unlikely(!p)) 7573babddc72SBryan Schumaker goto out_overflow; 7574c08e76d0SChuck Lever if (*p == xdr_zero) { 7575babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7576babddc72SBryan Schumaker if (unlikely(!p)) 7577babddc72SBryan Schumaker goto out_overflow; 7578c08e76d0SChuck Lever if (*p == xdr_zero) 7579573c4e1eSChuck Lever return -EAGAIN; 75801da177e4SLinus Torvalds entry->eof = 1; 7581573c4e1eSChuck Lever return -EBADCOOKIE; 75821da177e4SLinus Torvalds } 75831da177e4SLinus Torvalds 7584babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7585babddc72SBryan Schumaker if (unlikely(!p)) 7586babddc72SBryan Schumaker goto out_overflow; 758798de9ce6SFrank Sorenson p = xdr_decode_hyper(p, &new_cookie); 7588c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7589babddc72SBryan Schumaker 75909af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7591babddc72SBryan Schumaker if (unlikely(!p)) 7592babddc72SBryan Schumaker goto out_overflow; 75931da177e4SLinus Torvalds entry->name = (const char *) p; 75941da177e4SLinus Torvalds 75951da177e4SLinus Torvalds /* 75961da177e4SLinus Torvalds * In case the server doesn't return an inode number, 75971da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 75981da177e4SLinus Torvalds * since glibc seems to choke on it...) 75991da177e4SLinus Torvalds */ 76001da177e4SLinus Torvalds entry->ino = 1; 76014f082222STrond Myklebust entry->fattr->valid = 0; 76021da177e4SLinus Torvalds 76039af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7604babddc72SBryan Schumaker goto out_overflow; 76059af8c222STrond Myklebust 7606256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7607babddc72SBryan Schumaker goto out_overflow; 76089af8c222STrond Myklebust 7609573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7610aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7611babddc72SBryan Schumaker goto out_overflow; 761228331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 761328331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 761428331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 761582f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 76169af8c222STrond Myklebust 76170b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 76180b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 76190b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 76200b26a0bfSTrond Myklebust 762198de9ce6SFrank Sorenson entry->prev_cookie = entry->cookie; 762298de9ce6SFrank Sorenson entry->cookie = new_cookie; 762398de9ce6SFrank Sorenson 7624573c4e1eSChuck Lever return 0; 7625babddc72SBryan Schumaker 7626babddc72SBryan Schumaker out_overflow: 7627babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7628573c4e1eSChuck Lever return -EAGAIN; 76291da177e4SLinus Torvalds } 76301da177e4SLinus Torvalds 76311da177e4SLinus Torvalds /* 76321da177e4SLinus Torvalds * We need to translate between nfs status return values and 76331da177e4SLinus Torvalds * the local errno values which may not be the same. 76341da177e4SLinus Torvalds */ 76351da177e4SLinus Torvalds static struct { 76361da177e4SLinus Torvalds int stat; 76371da177e4SLinus Torvalds int errno; 76381da177e4SLinus Torvalds } nfs_errtbl[] = { 76391da177e4SLinus Torvalds { NFS4_OK, 0 }, 7640856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7641856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7642856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7643856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7644856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7645856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7646856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7647856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7648856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7649856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7650856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7651856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7652856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7653856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7654856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7655856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7656856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7657856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7658856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7659856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7660856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7661856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7662fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7663856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7664856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7665856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7666856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7667856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7668856dff3dSBenny Halevy { -1, -EIO } 76691da177e4SLinus Torvalds }; 76701da177e4SLinus Torvalds 76711da177e4SLinus Torvalds /* 76721da177e4SLinus Torvalds * Convert an NFS error code to a local one. 76731da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 76741da177e4SLinus Torvalds */ 76751da177e4SLinus Torvalds static int 76760a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 76771da177e4SLinus Torvalds { 76781da177e4SLinus Torvalds int i; 76791da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 76801da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 76811da177e4SLinus Torvalds return nfs_errtbl[i].errno; 76821da177e4SLinus Torvalds } 76831da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 76841da177e4SLinus Torvalds /* The server is looney tunes. */ 7685fdcb4577STrond Myklebust return -EREMOTEIO; 76861da177e4SLinus Torvalds } 76871da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 76881da177e4SLinus Torvalds * handle it. 76891da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 76901da177e4SLinus Torvalds * not conflict with native Linux error codes. 76911da177e4SLinus Torvalds */ 7692856dff3dSBenny Halevy return -stat; 76931da177e4SLinus Torvalds } 76941da177e4SLinus Torvalds 76951c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 76961c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 76971c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 76981c6dcbe5SAnna Schumaker 76991da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 77001da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 77011da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 7702fcc85819SChristoph Hellwig .p_encode = nfs4_xdr_##argtype, \ 7703fc016483SChristoph Hellwig .p_decode = nfs4_xdr_##restype, \ 77042bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 77052bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7706cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7707cc0175c1SChuck Lever .p_name = #proc, \ 77081da177e4SLinus Torvalds } 77091da177e4SLinus Torvalds 77107c61f0d3SAnna Schumaker #define STUB(proc) \ 77117c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 77127c61f0d3SAnna Schumaker .p_name = #proc, \ 77137c61f0d3SAnna Schumaker } 77147c61f0d3SAnna Schumaker 77158634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1) 77168634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 77178634ef5eSTrond Myklebust PROC(proc, argtype, restype) 77188634ef5eSTrond Myklebust #else 77198634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 77208634ef5eSTrond Myklebust STUB(proc) 77218634ef5eSTrond Myklebust #endif 77228634ef5eSTrond Myklebust 77238634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2) 77248634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 77258634ef5eSTrond Myklebust PROC(proc, argtype, restype) 77268634ef5eSTrond Myklebust #else 77278634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 77288634ef5eSTrond Myklebust STUB(proc) 77298634ef5eSTrond Myklebust #endif 77308634ef5eSTrond Myklebust 7731511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = { 77321da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 77331da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 77341da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 77351da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 77361da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 77371da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 77381da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 77391da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 77401da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 77411da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 77421da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 77431da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 77441da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 77451da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 77461da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 77471da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 77481da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 77491da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 77501da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 77511da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 77521da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 77531da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 77541da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 77551da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 77561da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 77571da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 77581da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 77591da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 77601da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 77611da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 77621da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7763029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 776423ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7765683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7766d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 77675a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 776844c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 77698634ef5eSTrond Myklebust PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 77708634ef5eSTrond Myklebust PROC41(CREATE_SESSION, enc_create_session, dec_create_session), 77718634ef5eSTrond Myklebust PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 77728634ef5eSTrond Myklebust PROC41(SEQUENCE, enc_sequence, dec_sequence), 77738634ef5eSTrond Myklebust PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 77748634ef5eSTrond Myklebust PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete), 77758634ef5eSTrond Myklebust PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 77768634ef5eSTrond Myklebust PROC41(LAYOUTGET, enc_layoutget, dec_layoutget), 77778634ef5eSTrond Myklebust PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 77788634ef5eSTrond Myklebust PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 77798634ef5eSTrond Myklebust PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 77808634ef5eSTrond Myklebust PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid), 77818634ef5eSTrond Myklebust PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid), 77827c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 77838634ef5eSTrond Myklebust PROC41(BIND_CONN_TO_SESSION, 7784ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 77858634ef5eSTrond Myklebust PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid), 77868634ef5eSTrond Myklebust PROC42(SEEK, enc_seek, dec_seek), 77878634ef5eSTrond Myklebust PROC42(ALLOCATE, enc_allocate, dec_allocate), 77888634ef5eSTrond Myklebust PROC42(DEALLOCATE, enc_deallocate, dec_deallocate), 77898634ef5eSTrond Myklebust PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 77908634ef5eSTrond Myklebust PROC42(CLONE, enc_clone, dec_clone), 77918634ef5eSTrond Myklebust PROC42(COPY, enc_copy, dec_copy), 7792cb95deeaSOlga Kornievskaia PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel), 77938634ef5eSTrond Myklebust PROC(LOOKUPP, enc_lookupp, dec_lookupp), 77941da177e4SLinus Torvalds }; 77951da177e4SLinus Torvalds 7796c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)]; 7797a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 77981da177e4SLinus Torvalds .number = 4, 7799e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 7800c551858aSChristoph Hellwig .procs = nfs4_procedures, 7801c551858aSChristoph Hellwig .counts = nfs_version4_counts, 78021da177e4SLinus Torvalds }; 78031da177e4SLinus Torvalds 78041da177e4SLinus Torvalds /* 78051da177e4SLinus Torvalds * Local variables: 78061da177e4SLinus Torvalds * c-basic-offset: 8 78071da177e4SLinus Torvalds * End: 78081da177e4SLinus Torvalds */ 7809