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" 57f23f6584SChuck Lever #include "nfs4trace.h" 584882ef72SAlexandros Batsakis #include "internal.h" 5940c64c26SAnna Schumaker #include "nfs4idmap.h" 6076e697baSTrond Myklebust #include "nfs4session.h" 61b1f69b75SAndy Adamson #include "pnfs.h" 62f092075dSChuck Lever #include "netns.h" 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 671da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 681da177e4SLinus Torvalds 6956f487f8SFred Isaman struct compound_hdr; 700a8ea437SDavid Howells static int nfs4_stat_to_errno(int); 7156f487f8SFred Isaman static void encode_layoutget(struct xdr_stream *xdr, 7256f487f8SFred Isaman const struct nfs4_layoutget_args *args, 7356f487f8SFred Isaman struct compound_hdr *hdr); 7456f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 7556f487f8SFred Isaman struct nfs4_layoutget_res *res); 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 781da177e4SLinus Torvalds #ifdef DEBUG 791da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20 801da177e4SLinus Torvalds #else 811da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0 821da177e4SLinus Torvalds #endif 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds /* lock,open owner id: 859f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 861da177e4SLinus Torvalds */ 8795b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2) 88d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4) 899104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 901da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 911da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 921da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1) 931da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2) 949104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 959104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 969104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 979104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 981da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 991da177e4SLinus Torvalds (NFS4_FHSIZE >> 2)) 1001da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz) 1011da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 1021da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 1031da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz) 1041da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 1051da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2)) 106e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4 10796928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 10836b3743fSTrond Myklebust #define nfstime4_maxsz (3) 1091da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 1101da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 111bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 112bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 113aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL 114aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */ 115aa9c2669SDavid Quigley #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN)) 116aa9c2669SDavid Quigley #else 117aa9c2669SDavid Quigley #define nfs4_label_maxsz 0 118aa9c2669SDavid Quigley #endif 11988034c3dSAndy Adamson /* We support only one layout type per file system */ 12088034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8) 12196928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */ 12296928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 12336b3743fSTrond Myklebust 3*nfstime4_maxsz + \ 12436b3743fSTrond Myklebust nfs4_owner_maxsz + \ 125aa9c2669SDavid Quigley nfs4_group_maxsz + nfs4_label_maxsz + \ 126aa9c2669SDavid Quigley decode_mdsthreshold_maxsz)) 12796928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 12896928206SJ. Bruce Fields nfs4_fattr_value_maxsz) 12996928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 1309104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 1319104a55dSTrond Myklebust 1 + 2 + 1 + \ 1329104a55dSTrond Myklebust nfs4_owner_maxsz + \ 1339104a55dSTrond Myklebust nfs4_group_maxsz + \ 134aa9c2669SDavid Quigley nfs4_label_maxsz + \ 13536b3743fSTrond Myklebust 1 + nfstime4_maxsz + \ 13636b3743fSTrond Myklebust 1 + nfstime4_maxsz) 1371da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz) 1381da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz) 13956ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 14056ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 1412f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz) 142dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three 143dae100c2SFred Isaman * layout types will be returned. 144dae100c2SFred Isaman */ 145dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 146dae100c2SFred Isaman nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 1471da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 1481da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz) 1491da177e4SLinus Torvalds #define encode_setclientid_maxsz \ 1501da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 151cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 152b8fb2f59SJeff Layton /* client name */ \ 153b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 154cc38bac3SChuck Lever 1 /* sc_prog */ + \ 1556dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1566dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 157cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1581da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1591da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1606dd3436bSChuck Lever 2 /* clientid */ + \ 1616dd3436bSChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 1626dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1636dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) 1641da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \ 1651da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 1661da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2)) 1671da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \ 1681da177e4SLinus Torvalds (op_decode_hdr_maxsz) 169e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 170e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz) 1715b5faaf6SJeff Layton #define encode_lookupp_maxsz (op_encode_hdr_maxsz) 1725b5faaf6SJeff Layton #define decode_lookupp_maxsz (op_decode_hdr_maxsz) 1732cebf828STrond Myklebust #define encode_share_access_maxsz \ 1742cebf828STrond Myklebust (2) 1754882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1762cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1772cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1782cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1792cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1802cebf828STrond Myklebust open_owner_id_maxsz + \ 1812cebf828STrond Myklebust encode_opentype_maxsz + \ 1822cebf828STrond Myklebust encode_claim_null_maxsz) 1835a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz (3) 1842cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1859104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1865a1f6d9eSTrond Myklebust decode_space_limit_maxsz + \ 1872cebf828STrond Myklebust decode_ace_maxsz) 1882cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1892cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1909104a55dSTrond Myklebust decode_stateid_maxsz + \ 1912cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1922cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1932cebf828STrond Myklebust decode_delegation_maxsz) 1949104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1959104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1969104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1979104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1989104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1999104a55dSTrond Myklebust decode_stateid_maxsz) 2009104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 2019104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 2029104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 2039104a55dSTrond Myklebust encode_share_access_maxsz) 2049104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 2059104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 2069104a55dSTrond Myklebust decode_stateid_maxsz) 2079104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 2089104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 2099104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 2109104a55dSTrond Myklebust decode_stateid_maxsz) 2119104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 2129104a55dSTrond Myklebust encode_stateid_maxsz + \ 2139104a55dSTrond Myklebust encode_attrs_maxsz) 2149104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 2159104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 2169104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 2179104a55dSTrond Myklebust encode_stateid_maxsz + 3) 21802ef04e4SChuck Lever #define decode_read_maxsz (op_decode_hdr_maxsz + 2 + 1) 2199104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 220aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \ 221aa9c2669SDavid Quigley nfs4_label_maxsz) 2229104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 22302ef04e4SChuck Lever decode_verifier_maxsz + 1) 2249104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 22502ef04e4SChuck Lever #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + 1) 2269104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2279104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2289104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2299104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2309104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2319104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2329104a55dSTrond Myklebust decode_verifier_maxsz) 2331da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2341da177e4SLinus Torvalds nfs4_name_maxsz) 2356ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2366ce18391SBenny Halevy decode_change_info_maxsz) 2371da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2381da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2396ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2406ce18391SBenny Halevy decode_change_info_maxsz + \ 2416ce18391SBenny Halevy decode_change_info_maxsz) 2421da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2431da177e4SLinus Torvalds nfs4_name_maxsz) 2446ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 245daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2469104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2479104a55dSTrond Myklebust 7 + \ 248daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 249daccbdedSTrond Myklebust encode_lockowner_maxsz) 2509104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2519104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2529104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2539104a55dSTrond Myklebust decode_lock_denied_maxsz) 254daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 255daccbdedSTrond Myklebust encode_lockowner_maxsz) 2569104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2579104a55dSTrond Myklebust decode_lock_denied_maxsz) 2589104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2599104a55dSTrond Myklebust encode_stateid_maxsz + \ 2609104a55dSTrond Myklebust 4) 2619104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2629104a55dSTrond Myklebust decode_stateid_maxsz) 263d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 264d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 265d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 266d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 267d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2689104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2699104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2701da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2711da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 27294a6d753SChuck Lever 1 + \ 27396928206SJ. Bruce Fields nfs4_fattr_maxsz) 2741da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2751da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2769104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2779104a55dSTrond Myklebust encode_attrs_maxsz) 2782cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2792cebf828STrond Myklebust decode_change_info_maxsz + \ 2802cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2819104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2829104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2831da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2841da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2859104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2869104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 28702ef04e4SChuck Lever nfs4_fattr_bitmap_maxsz + 1 + 1) 2889104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2899104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2909104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 291e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 292e6889620STrond Myklebust (encode_getattr_maxsz) 293e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 29402ef04e4SChuck Lever (1) 2955a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2961650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2979b7b9fccSAndy Adamson 2989b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 299fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 300d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 301d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 302fc931582SAndy Adamson 30399fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 30499fe60d0SBenny Halevy encode_verifier_maxsz + \ 30599fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 306b8fb2f59SJeff Layton /* eia_clientowner */ \ 307b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 30899fe60d0SBenny Halevy 1 /* flags */ + \ 30999fe60d0SBenny Halevy 1 /* spa_how */ + \ 3102031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3112031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3122031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 313db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 314db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 315db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 316db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 317d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 318db8ac8baSWeston Andros Adamson 3 /* nii_date */) 31999fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 32099fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 32199fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 32299fe60d0SBenny Halevy 1 /* eir_flags */ + \ 32399fe60d0SBenny Halevy 1 /* spr_how */ + \ 3242031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3252031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3262031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 32799fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 32899fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 32999fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 33099fe60d0SBenny Halevy /* eir_server_scope<> */ \ 33199fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 33299fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 3337d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3347d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3357d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3367d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3377d2ed9acSWeston Andros Adamson 3 /* nii_date */) 338fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 339fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 340fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 341fc931582SAndy Adamson 1 /* ca_rdma_ird */) 342fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 343fc931582SAndy Adamson 2 /* csa_clientid */ + \ 344fc931582SAndy Adamson 1 /* csa_sequence */ + \ 345fc931582SAndy Adamson 1 /* csa_flags */ + \ 346fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 347fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 348fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 349fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 350fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 351fc931582SAndy Adamson 1 /* stamp */ + \ 352fc931582SAndy Adamson 1 /* machinename.len */ + \ 353fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 354fc931582SAndy Adamson 1 /* uid */ + \ 355fc931582SAndy Adamson 1 /* gid */ + \ 356fc931582SAndy Adamson 1 /* gids.len (0) */) 357fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 358fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 359fc931582SAndy Adamson 1 /* csr_sequence */ + \ 360fc931582SAndy Adamson 1 /* csr_flags */ + \ 361fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 362fc931582SAndy Adamson decode_channel_attrs_maxsz) 3637c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3647c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3657c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3667c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3677c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3687c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3697c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3707c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3717c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3727c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3730f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3740f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 37566245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 37666245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 377fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 378fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 379fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 380fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 38118019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 38218019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 38384c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \ 38484c9dee3SChristoph Hellwig XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 38584c9dee3SChristoph Hellwig 1 /* layout type */ + \ 38684c9dee3SChristoph Hellwig 1 /* maxcount */ + \ 38784c9dee3SChristoph Hellwig 1 /* bitmap size */ + \ 38884c9dee3SChristoph Hellwig 1 /* notification bitmap length */ + \ 38984c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 390b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 391b1f69b75SAndy Adamson 1 /* layout type */ + \ 392b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 393b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 394b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 39502ef04e4SChuck Lever 1 /* notification bitmap, word 0 */ + \ 39602ef04e4SChuck Lever 1 /* possible XDR padding */) 397b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 398b1f69b75SAndy Adamson encode_stateid_maxsz) 399b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 400b1f69b75SAndy Adamson decode_stateid_maxsz + \ 40102ef04e4SChuck Lever XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1) 402863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 403863a3c6cSAndy Adamson 2 /* offset */ + \ 404863a3c6cSAndy Adamson 2 /* length */ + \ 405863a3c6cSAndy Adamson 1 /* reclaim */ + \ 406863a3c6cSAndy Adamson encode_stateid_maxsz + \ 407863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 408863a3c6cSAndy Adamson 2 /* last byte written */ + \ 409863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 410863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 4115f919c9fSChristoph Hellwig 1 /* layoutupdate4 opaqueue len */) 4125f919c9fSChristoph Hellwig /* the actual content of layoutupdate4 should 4135f919c9fSChristoph Hellwig be allocated by drivers and spliced in 4145f919c9fSChristoph Hellwig using xdr_write_pages */ 415863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 416cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 417cbe82603SBenny Halevy encode_stateid_maxsz + \ 4186669cb8bSTrond Myklebust 1 + \ 4196669cb8bSTrond Myklebust XDR_QUADLEN(NFS4_OPAQUE_LIMIT)) 420cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 421cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 422fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 423fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 4247d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 4257d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4267d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 4279aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 4289aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4299f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 4309b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 4319b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 4329b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 433cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0 434cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0 43556f487f8SFred Isaman #define encode_layoutget_maxsz 0 43656f487f8SFred Isaman #define decode_layoutget_maxsz 0 4379b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4389b7b9fccSAndy Adamson 4391da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4401da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4411da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4429b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4431da177e4SLinus Torvalds encode_putfh_maxsz + \ 4449104a55dSTrond Myklebust encode_read_maxsz) 4451da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4469b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4471da177e4SLinus Torvalds decode_putfh_maxsz + \ 4489104a55dSTrond Myklebust decode_read_maxsz) 4491da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4509b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4511da177e4SLinus Torvalds encode_putfh_maxsz + \ 4529104a55dSTrond Myklebust encode_readlink_maxsz) 4531da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4549b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4551da177e4SLinus Torvalds decode_putfh_maxsz + \ 4569104a55dSTrond Myklebust decode_readlink_maxsz) 4571da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4589b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4591da177e4SLinus Torvalds encode_putfh_maxsz + \ 4609104a55dSTrond Myklebust encode_readdir_maxsz) 4611da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4629b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4631da177e4SLinus Torvalds decode_putfh_maxsz + \ 4649104a55dSTrond Myklebust decode_readdir_maxsz) 4651da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4669b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4671da177e4SLinus Torvalds encode_putfh_maxsz + \ 4689104a55dSTrond Myklebust encode_write_maxsz + \ 4694f9838c7STrond Myklebust encode_getattr_maxsz) 4701da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4719b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4721da177e4SLinus Torvalds decode_putfh_maxsz + \ 4739104a55dSTrond Myklebust decode_write_maxsz + \ 4744f9838c7STrond Myklebust decode_getattr_maxsz) 4751da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4769b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4771da177e4SLinus Torvalds encode_putfh_maxsz + \ 4788582715eSTrond Myklebust encode_commit_maxsz) 4791da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4809b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4811da177e4SLinus Torvalds decode_putfh_maxsz + \ 4828582715eSTrond Myklebust decode_commit_maxsz) 4831da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4849b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4851da177e4SLinus Torvalds encode_putfh_maxsz + \ 4862cebf828STrond Myklebust encode_open_maxsz + \ 4876168f62cSWeston Andros Adamson encode_access_maxsz + \ 4882cebf828STrond Myklebust encode_getfh_maxsz + \ 48956f487f8SFred Isaman encode_getattr_maxsz + \ 49056f487f8SFred Isaman encode_layoutget_maxsz) 4911da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4929b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4931da177e4SLinus Torvalds decode_putfh_maxsz + \ 4942cebf828STrond Myklebust decode_open_maxsz + \ 4956168f62cSWeston Andros Adamson decode_access_maxsz + \ 4962cebf828STrond Myklebust decode_getfh_maxsz + \ 49756f487f8SFred Isaman decode_getattr_maxsz + \ 49856f487f8SFred Isaman decode_layoutget_maxsz) 4991da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 5001da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5011da177e4SLinus Torvalds encode_putfh_maxsz + \ 5029104a55dSTrond Myklebust encode_open_confirm_maxsz) 5039104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 5049104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 5051da177e4SLinus Torvalds decode_putfh_maxsz + \ 5069104a55dSTrond Myklebust decode_open_confirm_maxsz) 5071da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 5089b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5091da177e4SLinus Torvalds encode_putfh_maxsz + \ 5102cebf828STrond Myklebust encode_open_maxsz + \ 5116168f62cSWeston Andros Adamson encode_access_maxsz + \ 51256f487f8SFred Isaman encode_getattr_maxsz + \ 51356f487f8SFred Isaman encode_layoutget_maxsz) 5141da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 5159b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5161da177e4SLinus Torvalds decode_putfh_maxsz + \ 5172cebf828STrond Myklebust decode_open_maxsz + \ 5186168f62cSWeston Andros Adamson decode_access_maxsz + \ 51956f487f8SFred Isaman decode_getattr_maxsz + \ 52056f487f8SFred Isaman decode_layoutget_maxsz) 5211da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 5221da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5239b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5241da177e4SLinus Torvalds encode_putfh_maxsz + \ 525b6808145STrond Myklebust encode_layoutreturn_maxsz + \ 5263947b74dSTrond Myklebust encode_open_downgrade_maxsz) 5271da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 5281da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5299b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5301da177e4SLinus Torvalds decode_putfh_maxsz + \ 531b6808145STrond Myklebust decode_layoutreturn_maxsz + \ 5323947b74dSTrond Myklebust decode_open_downgrade_maxsz) 5331da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 5349b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5351da177e4SLinus Torvalds encode_putfh_maxsz + \ 536cf805165STrond Myklebust encode_layoutreturn_maxsz + \ 5379104a55dSTrond Myklebust encode_close_maxsz + \ 538516a6af6STrond Myklebust encode_getattr_maxsz) 5391da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 5409b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5411da177e4SLinus Torvalds decode_putfh_maxsz + \ 542cf805165STrond Myklebust decode_layoutreturn_maxsz + \ 5439104a55dSTrond Myklebust decode_close_maxsz + \ 544516a6af6STrond Myklebust decode_getattr_maxsz) 5451da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 5469b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5471da177e4SLinus Torvalds encode_putfh_maxsz + \ 5489104a55dSTrond Myklebust encode_setattr_maxsz + \ 5491da177e4SLinus Torvalds encode_getattr_maxsz) 5501da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5519b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5521da177e4SLinus Torvalds decode_putfh_maxsz + \ 5539104a55dSTrond Myklebust decode_setattr_maxsz + \ 5549104a55dSTrond Myklebust decode_getattr_maxsz) 5551da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5569b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5571da177e4SLinus Torvalds encode_putfh_maxsz + \ 5581da177e4SLinus Torvalds encode_fsinfo_maxsz) 5591da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5609b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5611da177e4SLinus Torvalds decode_putfh_maxsz + \ 5621da177e4SLinus Torvalds decode_fsinfo_maxsz) 5631da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5641da177e4SLinus Torvalds encode_renew_maxsz) 5651da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5661da177e4SLinus Torvalds decode_renew_maxsz) 5671da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5681da177e4SLinus Torvalds encode_setclientid_maxsz) 5691da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5701da177e4SLinus Torvalds decode_setclientid_maxsz) 5711da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5721da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 57383ca7f5aSChuck Lever encode_setclientid_confirm_maxsz) 5741da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5751da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 57683ca7f5aSChuck Lever decode_setclientid_confirm_maxsz) 5771da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5789b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5791da177e4SLinus Torvalds encode_putfh_maxsz + \ 5809104a55dSTrond Myklebust encode_lock_maxsz) 5811da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5829b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5831da177e4SLinus Torvalds decode_putfh_maxsz + \ 5849104a55dSTrond Myklebust decode_lock_maxsz) 5851da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5869b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5871da177e4SLinus Torvalds encode_putfh_maxsz + \ 5889104a55dSTrond Myklebust encode_lockt_maxsz) 5899104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5909b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5919104a55dSTrond Myklebust decode_putfh_maxsz + \ 5929104a55dSTrond Myklebust decode_lockt_maxsz) 5931da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5949b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5951da177e4SLinus Torvalds encode_putfh_maxsz + \ 5969104a55dSTrond Myklebust encode_locku_maxsz) 5971da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5989b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5991da177e4SLinus Torvalds decode_putfh_maxsz + \ 6009104a55dSTrond Myklebust decode_locku_maxsz) 601d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 602d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 603d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 604d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 605d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 606d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 6071da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 6089b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6091da177e4SLinus Torvalds encode_putfh_maxsz + \ 61076b32999STrond Myklebust encode_access_maxsz + \ 61176b32999STrond Myklebust encode_getattr_maxsz) 6121da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 6139b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6141da177e4SLinus Torvalds decode_putfh_maxsz + \ 61576b32999STrond Myklebust decode_access_maxsz + \ 61676b32999STrond Myklebust decode_getattr_maxsz) 6171da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 6189b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6191da177e4SLinus Torvalds encode_putfh_maxsz + \ 62044c99933SChuck Lever encode_getattr_maxsz + \ 62144c99933SChuck Lever encode_renew_maxsz) 6221da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 6239b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6241da177e4SLinus Torvalds decode_putfh_maxsz + \ 62544c99933SChuck Lever decode_getattr_maxsz + \ 62644c99933SChuck Lever decode_renew_maxsz) 6271da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 6289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6291da177e4SLinus Torvalds encode_putfh_maxsz + \ 6301da177e4SLinus Torvalds encode_lookup_maxsz + \ 6311da177e4SLinus Torvalds encode_getattr_maxsz + \ 6321da177e4SLinus Torvalds encode_getfh_maxsz) 6331da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 6349b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6351da177e4SLinus Torvalds decode_putfh_maxsz + \ 636e6889620STrond Myklebust decode_lookup_maxsz + \ 6371da177e4SLinus Torvalds decode_getattr_maxsz + \ 6381da177e4SLinus Torvalds decode_getfh_maxsz) 6395b5faaf6SJeff Layton #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \ 6405b5faaf6SJeff Layton encode_sequence_maxsz + \ 6415b5faaf6SJeff Layton encode_putfh_maxsz + \ 6425b5faaf6SJeff Layton encode_lookupp_maxsz + \ 6435b5faaf6SJeff Layton encode_getattr_maxsz + \ 6445b5faaf6SJeff Layton encode_getfh_maxsz) 6455b5faaf6SJeff Layton #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \ 6465b5faaf6SJeff Layton decode_sequence_maxsz + \ 6475b5faaf6SJeff Layton decode_putfh_maxsz + \ 6485b5faaf6SJeff Layton decode_lookupp_maxsz + \ 6495b5faaf6SJeff Layton decode_getattr_maxsz + \ 6505b5faaf6SJeff Layton decode_getfh_maxsz) 6511da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 6529b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6531da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 6541da177e4SLinus Torvalds encode_getattr_maxsz + \ 6551da177e4SLinus Torvalds encode_getfh_maxsz) 6561da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6579b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6581da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6591da177e4SLinus Torvalds decode_getattr_maxsz + \ 6601da177e4SLinus Torvalds decode_getfh_maxsz) 6611da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6629b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6631da177e4SLinus Torvalds encode_putfh_maxsz + \ 664778d2817STrond Myklebust encode_remove_maxsz) 6651da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6669b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6671da177e4SLinus Torvalds decode_putfh_maxsz + \ 668778d2817STrond Myklebust decode_remove_maxsz) 6691da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6709b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6711da177e4SLinus Torvalds encode_putfh_maxsz + \ 6721da177e4SLinus Torvalds encode_savefh_maxsz + \ 6731da177e4SLinus Torvalds encode_putfh_maxsz + \ 674778d2817STrond Myklebust encode_rename_maxsz) 6751da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6769b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6771da177e4SLinus Torvalds decode_putfh_maxsz + \ 6781da177e4SLinus Torvalds decode_savefh_maxsz + \ 6791da177e4SLinus Torvalds decode_putfh_maxsz + \ 680778d2817STrond Myklebust decode_rename_maxsz) 6811da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6829b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6831da177e4SLinus Torvalds encode_putfh_maxsz + \ 6841da177e4SLinus Torvalds encode_savefh_maxsz + \ 6851da177e4SLinus Torvalds encode_putfh_maxsz + \ 68691ba2eeeSTrond Myklebust encode_link_maxsz + \ 68791ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 688a9f6991bSTrond Myklebust encode_getattr_maxsz) 6891da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6909b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6911da177e4SLinus Torvalds decode_putfh_maxsz + \ 6921da177e4SLinus Torvalds decode_savefh_maxsz + \ 6931da177e4SLinus Torvalds decode_putfh_maxsz + \ 69491ba2eeeSTrond Myklebust decode_link_maxsz + \ 69591ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 69691ba2eeeSTrond Myklebust decode_getattr_maxsz) 6971da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6989b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6991da177e4SLinus Torvalds encode_putfh_maxsz + \ 7001da177e4SLinus Torvalds encode_symlink_maxsz + \ 7011da177e4SLinus Torvalds encode_getattr_maxsz + \ 7021da177e4SLinus Torvalds encode_getfh_maxsz) 7031da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 7049b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7051da177e4SLinus Torvalds decode_putfh_maxsz + \ 7061da177e4SLinus Torvalds decode_symlink_maxsz + \ 7071da177e4SLinus Torvalds decode_getattr_maxsz + \ 7081da177e4SLinus Torvalds decode_getfh_maxsz) 7091da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 7109b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7111da177e4SLinus Torvalds encode_putfh_maxsz + \ 7121da177e4SLinus Torvalds encode_create_maxsz + \ 71356ae19f3STrond Myklebust encode_getfh_maxsz + \ 71456ae19f3STrond Myklebust encode_getattr_maxsz) 7151da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 7169b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7171da177e4SLinus Torvalds decode_putfh_maxsz + \ 7181da177e4SLinus Torvalds decode_create_maxsz + \ 71956ae19f3STrond Myklebust decode_getfh_maxsz + \ 72056ae19f3STrond Myklebust decode_getattr_maxsz) 7211da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 7229b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7231da177e4SLinus Torvalds encode_putfh_maxsz + \ 7241da177e4SLinus Torvalds encode_getattr_maxsz) 7251da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 7269b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7271da177e4SLinus Torvalds decode_putfh_maxsz + \ 7281da177e4SLinus Torvalds decode_getattr_maxsz) 7291da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 7309b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7311da177e4SLinus Torvalds encode_putfh_maxsz + \ 7329104a55dSTrond Myklebust encode_statfs_maxsz) 7331da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 7349b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7351da177e4SLinus Torvalds decode_putfh_maxsz + \ 7369104a55dSTrond Myklebust decode_statfs_maxsz) 7371da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 7389b7b9fccSAndy Adamson encode_sequence_maxsz + \ 739ab91f264STrond Myklebust encode_putfh_maxsz + \ 7401da177e4SLinus Torvalds encode_getattr_maxsz) 7411da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 7429b7b9fccSAndy Adamson decode_sequence_maxsz + \ 743ab91f264STrond Myklebust decode_putfh_maxsz + \ 7441da177e4SLinus Torvalds decode_getattr_maxsz) 7451da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 7469b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7471da177e4SLinus Torvalds encode_putfh_maxsz + \ 748586f1c39STrond Myklebust encode_layoutreturn_maxsz + \ 749fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 750fa178f29STrond Myklebust encode_getattr_maxsz) 7511da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7529b7b9fccSAndy Adamson decode_sequence_maxsz + \ 753d8434d4cSTrond Myklebust decode_putfh_maxsz + \ 754586f1c39STrond Myklebust decode_layoutreturn_maxsz + \ 755fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 756fa178f29STrond Myklebust decode_getattr_maxsz) 757029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7589b7b9fccSAndy Adamson encode_sequence_maxsz + \ 759029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7609104a55dSTrond Myklebust encode_getacl_maxsz) 761029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7629b7b9fccSAndy Adamson decode_sequence_maxsz + \ 763029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7649104a55dSTrond Myklebust decode_getacl_maxsz) 76523ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7669b7b9fccSAndy Adamson encode_sequence_maxsz + \ 76723ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7689104a55dSTrond Myklebust encode_setacl_maxsz) 76923ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7709b7b9fccSAndy Adamson decode_sequence_maxsz + \ 77123ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7729104a55dSTrond Myklebust decode_setacl_maxsz) 773683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 774683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7759b7b9fccSAndy Adamson encode_sequence_maxsz + \ 776683b57b4STrond Myklebust encode_putfh_maxsz + \ 777e6889620STrond Myklebust encode_lookup_maxsz + \ 778b03d735bSChuck Lever encode_fs_locations_maxsz + \ 779b03d735bSChuck Lever encode_renew_maxsz) 780683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 781683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7829b7b9fccSAndy Adamson decode_sequence_maxsz + \ 783683b57b4STrond Myklebust decode_putfh_maxsz + \ 784e6889620STrond Myklebust decode_lookup_maxsz + \ 785b03d735bSChuck Lever decode_fs_locations_maxsz + \ 786b03d735bSChuck Lever decode_renew_maxsz) 7875a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7885a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7895a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7905a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7915a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7925a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7935a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7945a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 79544c99933SChuck Lever #define NFS4_enc_fsid_present_sz \ 79644c99933SChuck Lever (compound_encode_hdr_maxsz + \ 79744c99933SChuck Lever encode_sequence_maxsz + \ 79844c99933SChuck Lever encode_putfh_maxsz + \ 79944c99933SChuck Lever encode_getfh_maxsz + \ 80044c99933SChuck Lever encode_renew_maxsz) 80144c99933SChuck Lever #define NFS4_dec_fsid_present_sz \ 80244c99933SChuck Lever (compound_decode_hdr_maxsz + \ 80344c99933SChuck Lever decode_sequence_maxsz + \ 80444c99933SChuck Lever decode_putfh_maxsz + \ 80544c99933SChuck Lever decode_getfh_maxsz + \ 80644c99933SChuck Lever decode_renew_maxsz) 80799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 8087c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 8097c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 8107c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 8117c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 8127c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 8137c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 81499fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 81599fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 81699fe60d0SBenny Halevy encode_exchange_id_maxsz) 81799fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 81899fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 81999fe60d0SBenny Halevy decode_exchange_id_maxsz) 820fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 821fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 822fc931582SAndy Adamson encode_create_session_maxsz) 823fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 824fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 825fc931582SAndy Adamson decode_create_session_maxsz) 8260f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 8270f3e66c6SAndy Adamson encode_destroy_session_maxsz) 8280f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 8290f3e66c6SAndy Adamson decode_destroy_session_maxsz) 83066245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 83166245539STrond Myklebust encode_destroy_clientid_maxsz) 83266245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 83366245539STrond Myklebust decode_destroy_clientid_maxsz) 834fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 835fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 836fc01cea9SAndy Adamson encode_sequence_maxsz) 837fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 838fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 839fc01cea9SAndy Adamson decode_sequence_maxsz) 8400efb01b2SDonald Buczek #endif 8412050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 8422050f0ccSAndy Adamson encode_sequence_maxsz + \ 8432050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 8442050f0ccSAndy Adamson encode_fsinfo_maxsz) 8452050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 8462050f0ccSAndy Adamson decode_sequence_maxsz + \ 8472050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 8482050f0ccSAndy Adamson decode_fsinfo_maxsz) 8490efb01b2SDonald Buczek #if defined(CONFIG_NFS_V4_1) 85018019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 85118019753SRicardo Labiaga encode_sequence_maxsz + \ 85218019753SRicardo Labiaga encode_reclaim_complete_maxsz) 85318019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 85418019753SRicardo Labiaga decode_sequence_maxsz + \ 85518019753SRicardo Labiaga decode_reclaim_complete_maxsz) 856b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 857b1f69b75SAndy Adamson encode_sequence_maxsz +\ 858b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 859b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 860b1f69b75SAndy Adamson decode_sequence_maxsz + \ 861b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 862b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 863b1f69b75SAndy Adamson encode_sequence_maxsz + \ 864b1f69b75SAndy Adamson encode_putfh_maxsz + \ 865b1f69b75SAndy Adamson encode_layoutget_maxsz) 866b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 867b1f69b75SAndy Adamson decode_sequence_maxsz + \ 868b1f69b75SAndy Adamson decode_putfh_maxsz + \ 869b1f69b75SAndy Adamson decode_layoutget_maxsz) 870863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 871863a3c6cSAndy Adamson encode_sequence_maxsz +\ 872863a3c6cSAndy Adamson encode_putfh_maxsz + \ 873863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 874863a3c6cSAndy Adamson encode_getattr_maxsz) 875863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 876863a3c6cSAndy Adamson decode_sequence_maxsz + \ 877863a3c6cSAndy Adamson decode_putfh_maxsz + \ 878863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 879863a3c6cSAndy Adamson decode_getattr_maxsz) 880cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 881cbe82603SBenny Halevy encode_sequence_maxsz + \ 882cbe82603SBenny Halevy encode_putfh_maxsz + \ 883cbe82603SBenny Halevy encode_layoutreturn_maxsz) 884cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 885cbe82603SBenny Halevy decode_sequence_maxsz + \ 886cbe82603SBenny Halevy decode_putfh_maxsz + \ 887cbe82603SBenny Halevy decode_layoutreturn_maxsz) 888fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 889fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 890fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 891fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 892fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 893fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 894fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 895fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8967d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8977d974794SBryan Schumaker encode_sequence_maxsz + \ 8987d974794SBryan Schumaker encode_test_stateid_maxsz) 8997d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 9007d974794SBryan Schumaker decode_sequence_maxsz + \ 9017d974794SBryan Schumaker decode_test_stateid_maxsz) 9029aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 9039aeda35fSBryan Schumaker encode_sequence_maxsz + \ 9049aeda35fSBryan Schumaker encode_free_stateid_maxsz) 9059aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 9069aeda35fSBryan Schumaker decode_sequence_maxsz + \ 9079aeda35fSBryan Schumaker decode_free_stateid_maxsz) 9082449ea2eSAlexandros Batsakis 9092449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 9102449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 9112449ea2eSAlexandros Batsakis encode_sequence_maxsz + 9122449ea2eSAlexandros Batsakis encode_putfh_maxsz + 9132449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 9142449ea2eSAlexandros Batsakis XDR_UNIT); 9152449ea2eSAlexandros Batsakis 9162449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 9172449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 9182449ea2eSAlexandros Batsakis decode_sequence_maxsz + 9192449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 9202449ea2eSAlexandros Batsakis XDR_UNIT); 921f1c097beSAndy Adamson 922f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH + 923f1c097beSAndy Adamson compound_decode_hdr_maxsz + 924f1c097beSAndy Adamson decode_sequence_maxsz) * 925f1c097beSAndy Adamson XDR_UNIT); 926f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 92799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 9281da177e4SLinus Torvalds 929bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 930bca79478STrond Myklebust [NF4BAD] = 0, 931bca79478STrond Myklebust [NF4REG] = S_IFREG, 932bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 933bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 934bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 935bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 936bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 937bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 938bca79478STrond Myklebust [NF4ATTRDIR] = 0, 939bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 9401da177e4SLinus Torvalds }; 9411da177e4SLinus Torvalds 9421da177e4SLinus Torvalds struct compound_hdr { 9431da177e4SLinus Torvalds int32_t status; 9441da177e4SLinus Torvalds uint32_t nops; 945d017931cSAndy Adamson __be32 * nops_p; 9461da177e4SLinus Torvalds uint32_t taglen; 9471da177e4SLinus Torvalds char * tag; 9480c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 94966cc0429SBenny Halevy u32 minorversion; 9501da177e4SLinus Torvalds }; 9511da177e4SLinus Torvalds 95213c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 95313c65ce9SBenny Halevy { 95413c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 95513c65ce9SBenny Halevy BUG_ON(!p); 95613c65ce9SBenny Halevy return p; 95713c65ce9SBenny Halevy } 9581da177e4SLinus Torvalds 959cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 960cb17e556STrond Myklebust { 961ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); 962cb17e556STrond Myklebust } 963cb17e556STrond Myklebust 9641da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 9651da177e4SLinus Torvalds { 966ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0); 9671da177e4SLinus Torvalds } 9681da177e4SLinus Torvalds 9694ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9704ade9821STrond Myklebust { 971ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0); 9724ade9821STrond Myklebust } 9734ade9821STrond Myklebust 974ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 975ff2eb681STrond Myklebust { 976ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0); 977ff2eb681STrond Myklebust } 978ff2eb681STrond Myklebust 97937c88763STrond Myklebust static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr, 98037c88763STrond Myklebust const __u32 *bitmap, size_t len) 98137c88763STrond Myklebust { 98237c88763STrond Myklebust ssize_t ret; 98337c88763STrond Myklebust 98437c88763STrond Myklebust /* Trim empty words */ 98537c88763STrond Myklebust while (len > 0 && bitmap[len-1] == 0) 98637c88763STrond Myklebust len--; 98737c88763STrond Myklebust ret = xdr_stream_encode_uint32_array(xdr, bitmap, len); 98837c88763STrond Myklebust if (WARN_ON_ONCE(ret < 0)) 98937c88763STrond Myklebust return ret; 99037c88763STrond Myklebust return len; 99137c88763STrond Myklebust } 99237c88763STrond Myklebust 99337c88763STrond Myklebust static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask, 99437c88763STrond Myklebust __u32 *res, size_t len) 99537c88763STrond Myklebust { 99637c88763STrond Myklebust size_t i; 99737c88763STrond Myklebust __u32 tmp; 99837c88763STrond Myklebust 99937c88763STrond Myklebust while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0)) 100037c88763STrond Myklebust len--; 100137c88763STrond Myklebust for (i = len; i-- > 0;) { 100237c88763STrond Myklebust tmp = bitmap[i] & mask[i]; 100337c88763STrond Myklebust res[i] = tmp; 100437c88763STrond Myklebust } 100537c88763STrond Myklebust return len; 100637c88763STrond Myklebust } 100737c88763STrond Myklebust 10084ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 10094ade9821STrond Myklebust const struct nfs_seqid *seqid) 10104ade9821STrond Myklebust { 1011a6796419STrond Myklebust if (seqid != NULL) 10124ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 1013a6796419STrond Myklebust else 1014a6796419STrond Myklebust encode_uint32(xdr, 0); 10154ade9821STrond Myklebust } 10164ade9821STrond Myklebust 10170c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 10180c4e8c18SBenny Halevy struct rpc_rqst *req, 10190c4e8c18SBenny Halevy struct compound_hdr *hdr) 10201da177e4SLinus Torvalds { 10218687b63aSAl Viro __be32 *p; 10220c4e8c18SBenny Halevy 10230c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 10240c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 10250c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 1026cf500bacSChuck Lever hdr->replen = 3 + hdr->taglen; 10271da177e4SLinus Torvalds 10287fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 10296fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 10306fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 1031e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 1032d017931cSAndy Adamson hdr->nops_p = p; 103334558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 1034d017931cSAndy Adamson } 1035d017931cSAndy Adamson 1036ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 1037ab19b481STrond Myklebust uint32_t replen, 1038ab19b481STrond Myklebust struct compound_hdr *hdr) 1039ab19b481STrond Myklebust { 1040ab19b481STrond Myklebust encode_uint32(xdr, op); 1041ab19b481STrond Myklebust hdr->nops++; 1042ab19b481STrond Myklebust hdr->replen += replen; 1043ab19b481STrond Myklebust } 1044ab19b481STrond Myklebust 1045d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 1046d017931cSAndy Adamson { 10477fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 1048d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds 1051ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1052ea9d23f5STrond Myklebust { 10532d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 1054ea9d23f5STrond Myklebust } 1055ea9d23f5STrond Myklebust 10561da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 10571da177e4SLinus Torvalds { 1058cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 10591da177e4SLinus Torvalds } 10601da177e4SLinus Torvalds 106136b3743fSTrond Myklebust static __be32 * 106236b3743fSTrond Myklebust xdr_encode_nfstime4(__be32 *p, const struct timespec *t) 106336b3743fSTrond Myklebust { 106436b3743fSTrond Myklebust p = xdr_encode_hyper(p, (__s64)t->tv_sec); 106536b3743fSTrond Myklebust *p++ = cpu_to_be32(t->tv_nsec); 106636b3743fSTrond Myklebust return p; 106736b3743fSTrond Myklebust } 106836b3743fSTrond Myklebust 1069aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1070aa9c2669SDavid Quigley const struct nfs4_label *label, 107128cf22d0STrond Myklebust const umode_t *umask, 10725334c5bdSKinglong Mee const struct nfs_server *server, 107328cf22d0STrond Myklebust const uint32_t attrmask[]) 10741da177e4SLinus Torvalds { 107595582b00SDeepa Dinamani struct timespec ts; 10761da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10771da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10781da177e4SLinus Torvalds int owner_namelen = 0; 10791da177e4SLinus Torvalds int owner_grouplen = 0; 10808687b63aSAl Viro __be32 *p; 1081d7067b2dSTrond Myklebust uint32_t len = 0; 1082d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10831da177e4SLinus Torvalds 10841da177e4SLinus Torvalds /* 10851da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10861da177e4SLinus Torvalds */ 108728cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) { 1088d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10891da177e4SLinus Torvalds len += 8; 1090d7067b2dSTrond Myklebust } 1091d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 109228cf22d0STrond Myklebust if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) { 1093dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK; 1094dff25ddbSAndreas Gruenbacher len += 8; 109528cf22d0STrond Myklebust } else if (attrmask[1] & FATTR4_WORD1_MODE) { 1096d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10971da177e4SLinus Torvalds len += 4; 1098d7067b2dSTrond Myklebust } 1099dff25ddbSAndreas Gruenbacher } 110028cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) { 1101e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 11021da177e4SLinus Torvalds if (owner_namelen < 0) { 1103fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1104e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 11051da177e4SLinus Torvalds /* XXX */ 11061da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 11071da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 11081da177e4SLinus Torvalds /* goto out; */ 11091da177e4SLinus Torvalds } 1110d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 11111da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 11121da177e4SLinus Torvalds } 111328cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_GID) && 111428cf22d0STrond Myklebust (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) { 1115e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 11161da177e4SLinus Torvalds if (owner_grouplen < 0) { 1117fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1118e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 11191da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 11201da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 11211da177e4SLinus Torvalds /* goto out; */ 11221da177e4SLinus Torvalds } 1123d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 11241da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 11251da177e4SLinus Torvalds } 112628cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 1127d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1128d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 112936b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2); 1130d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1131d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 11321da177e4SLinus Torvalds len += 4; 1133d7067b2dSTrond Myklebust } 113428cf22d0STrond Myklebust } 113528cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 1136d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1137d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 113836b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2); 1139d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1140d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 11411da177e4SLinus Torvalds len += 4; 1142d7067b2dSTrond Myklebust } 11435334c5bdSKinglong Mee } 11445334c5bdSKinglong Mee 114528cf22d0STrond Myklebust if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) { 1146b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1147d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1148d7067b2dSTrond Myklebust } 1149d7067b2dSTrond Myklebust 115040a3426cSTrond Myklebust xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval)); 115140a3426cSTrond Myklebust xdr_stream_encode_opaque_inline(xdr, (void **)&p, len); 11521da177e4SLinus Torvalds 1153d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1154b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1155d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1156e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1157d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1158811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1159d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1160811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1161d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11621da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1163e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 116495582b00SDeepa Dinamani ts = timespec64_to_timespec(iap->ia_atime); 116595582b00SDeepa Dinamani p = xdr_encode_nfstime4(p, &ts); 1166d7067b2dSTrond Myklebust } else 1167e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11681da177e4SLinus Torvalds } 1169d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11701da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1171e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 117295582b00SDeepa Dinamani ts = timespec64_to_timespec(iap->ia_mtime); 117395582b00SDeepa Dinamani p = xdr_encode_nfstime4(p, &ts); 1174d7067b2dSTrond Myklebust } else 1175e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11761da177e4SLinus Torvalds } 1177e2751463SJia-Ju Bai if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) { 1178aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1179aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1180aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1181aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1182aa9c2669SDavid Quigley } 1183dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { 1184dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1185dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask); 1186dff25ddbSAndreas Gruenbacher } 11871da177e4SLinus Torvalds 11881da177e4SLinus Torvalds /* out: */ 11891da177e4SLinus Torvalds } 11901da177e4SLinus Torvalds 1191cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11921da177e4SLinus Torvalds { 1193475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1194475d4ba0STrond Myklebust encode_uint32(xdr, access); 11951da177e4SLinus Torvalds } 11961da177e4SLinus Torvalds 1197cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11981da177e4SLinus Torvalds { 1199ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 12004ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1201566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 12021da177e4SLinus Torvalds } 12031da177e4SLinus Torvalds 12040b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 12051da177e4SLinus Torvalds { 12068687b63aSAl Viro __be32 *p; 12071da177e4SLinus Torvalds 1208475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1209475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1210b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 121134558513SBenny Halevy *p = cpu_to_be32(args->count); 12121da177e4SLinus Torvalds } 12131da177e4SLinus Torvalds 1214cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 12151da177e4SLinus Torvalds { 12168687b63aSAl Viro __be32 *p; 12171da177e4SLinus Torvalds 1218475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1219475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 12201da177e4SLinus Torvalds 12211da177e4SLinus Torvalds switch (create->ftype) { 12221da177e4SLinus Torvalds case NF4LNK: 122313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 122434558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 12252fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 12262fcc213aSChuck Lever create->u.symlink.len); 12272fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 12281da177e4SLinus Torvalds break; 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 123113c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1232e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 123334558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 12341da177e4SLinus Torvalds break; 12351da177e4SLinus Torvalds 12361da177e4SLinus Torvalds default: 12371da177e4SLinus Torvalds break; 12381da177e4SLinus Torvalds } 12391da177e4SLinus Torvalds 1240811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 124128cf22d0STrond Myklebust encode_attrs(xdr, create->attrs, create->label, &create->umask, 124228cf22d0STrond Myklebust create->server, create->server->attr_bitmask); 12431da177e4SLinus Torvalds } 12441da177e4SLinus Torvalds 124537c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr, 124637c88763STrond Myklebust const __u32 *bitmap, const __u32 *mask, size_t len, 1247dae100c2SFred Isaman struct compound_hdr *hdr) 1248dae100c2SFred Isaman { 124937c88763STrond Myklebust __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz]; 1250dae100c2SFred Isaman 1251ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 125237c88763STrond Myklebust if (mask) { 125337c88763STrond Myklebust if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap))) 125437c88763STrond Myklebust len = ARRAY_SIZE(masked_bitmap); 125537c88763STrond Myklebust len = mask_bitmap4(bitmap, mask, masked_bitmap, len); 125637c88763STrond Myklebust bitmap = masked_bitmap; 1257dae100c2SFred Isaman } 125837c88763STrond Myklebust xdr_encode_bitmap4(xdr, bitmap, len); 1259dae100c2SFred Isaman } 1260dae100c2SFred Isaman 1261cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12621da177e4SLinus Torvalds { 126337c88763STrond Myklebust encode_getattr(xdr, nfs4_fattr_bitmap, bitmask, 126437c88763STrond Myklebust ARRAY_SIZE(nfs4_fattr_bitmap), hdr); 12651da177e4SLinus Torvalds } 12661da177e4SLinus Torvalds 126788034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12681549210fSTrond Myklebust const u32 *open_bitmap, 126988034c3dSAndy Adamson struct compound_hdr *hdr) 127088034c3dSAndy Adamson { 127137c88763STrond Myklebust encode_getattr(xdr, open_bitmap, bitmask, 3, hdr); 127288034c3dSAndy Adamson } 127388034c3dSAndy Adamson 1274cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12751da177e4SLinus Torvalds { 127637c88763STrond Myklebust encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask, 127737c88763STrond Myklebust ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr); 12781da177e4SLinus Torvalds } 12791da177e4SLinus Torvalds 1280cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1281830b8e33SManoj Naik { 128237c88763STrond Myklebust encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask, 128337c88763STrond Myklebust ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr); 1284830b8e33SManoj Naik } 1285830b8e33SManoj Naik 1286cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12871da177e4SLinus Torvalds { 1288ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12891da177e4SLinus Torvalds } 12901da177e4SLinus Torvalds 1291cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12921da177e4SLinus Torvalds { 1293ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12946fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12951da177e4SLinus Torvalds } 12961da177e4SLinus Torvalds 1297911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1298911d1aafSTrond Myklebust { 1299f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1300911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1301911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1302911d1aafSTrond Myklebust } 1303911d1aafSTrond Myklebust 1304911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1305911d1aafSTrond Myklebust { 1306911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1307911d1aafSTrond Myklebust return ~(uint64_t)0; 1308911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1309911d1aafSTrond Myklebust } 1310911d1aafSTrond Myklebust 1311daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1312daccbdedSTrond Myklebust { 1313daccbdedSTrond Myklebust __be32 *p; 1314daccbdedSTrond Myklebust 1315d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1316daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1317d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1318daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1319d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1320daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1321daccbdedSTrond Myklebust } 1322daccbdedSTrond Myklebust 13231da177e4SLinus Torvalds /* 13241da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13251da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13261da177e4SLinus Torvalds */ 1327cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13281da177e4SLinus Torvalds { 13298687b63aSAl Viro __be32 *p; 13301da177e4SLinus Torvalds 1331475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1332475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1333e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1334e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1335b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1336b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 133734558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1338911d1aafSTrond Myklebust if (args->new_lock_owner){ 13394ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1340425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13414ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1342daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13431da177e4SLinus Torvalds } 13441da177e4SLinus Torvalds else { 1345425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13464ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13471da177e4SLinus Torvalds } 13481da177e4SLinus Torvalds } 13491da177e4SLinus Torvalds 1350cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13511da177e4SLinus Torvalds { 13528687b63aSAl Viro __be32 *p; 13531da177e4SLinus Torvalds 1354475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1355475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1356e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1357b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1358b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1359daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13601da177e4SLinus Torvalds } 13611da177e4SLinus Torvalds 1362cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13631da177e4SLinus Torvalds { 13648687b63aSAl Viro __be32 *p; 13651da177e4SLinus Torvalds 1366475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1367475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13684ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1369425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1370ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1371b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 137234558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13731da177e4SLinus Torvalds } 13741da177e4SLinus Torvalds 1375d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1376d3c7b7ccSTrond Myklebust { 1377ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1378d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1379d3c7b7ccSTrond Myklebust } 1380d3c7b7ccSTrond Myklebust 1381cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13821da177e4SLinus Torvalds { 1383ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13846fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13851da177e4SLinus Torvalds } 13861da177e4SLinus Torvalds 13875b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr) 13885b5faaf6SJeff Layton { 13895b5faaf6SJeff Layton encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr); 13905b5faaf6SJeff Layton } 13915b5faaf6SJeff Layton 13926ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13931da177e4SLinus Torvalds { 13948687b63aSAl Viro __be32 *p; 13951da177e4SLinus Torvalds 139613c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13976ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 139834558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13991da177e4SLinus Torvalds } 14001da177e4SLinus Torvalds 14011da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14021da177e4SLinus Torvalds { 14038687b63aSAl Viro __be32 *p; 14041da177e4SLinus Torvalds /* 14051da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 14061da177e4SLinus Torvalds * owner 4 = 32 14071da177e4SLinus Torvalds */ 14084ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 14096ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 141095b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1411b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 141295b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 141393f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1414d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 141595b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 141695b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 14171da177e4SLinus Torvalds } 14181da177e4SLinus Torvalds 14191da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14201da177e4SLinus Torvalds { 14218687b63aSAl Viro __be32 *p; 14221da177e4SLinus Torvalds 142313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1424549b19ccSTrond Myklebust switch(arg->createmode) { 1425549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 142634558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 142728cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 142828cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 14291da177e4SLinus Torvalds break; 1430549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14314882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 143228cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 143328cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask); 1434549b19ccSTrond Myklebust break; 1435549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1436549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1437549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1438549b19ccSTrond Myklebust break; 1439549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14404882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14414882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 144228cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask, 144328cf22d0STrond Myklebust arg->server, arg->server->exclcreat_bitmask); 14444882ef72SAlexandros Batsakis } 14454882ef72SAlexandros Batsakis } 14461da177e4SLinus Torvalds 14471da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14481da177e4SLinus Torvalds { 14498687b63aSAl Viro __be32 *p; 14501da177e4SLinus Torvalds 145113c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14521da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14531da177e4SLinus Torvalds case 0: 145434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14551da177e4SLinus Torvalds break; 14561da177e4SLinus Torvalds default: 145734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14581da177e4SLinus Torvalds encode_createmode(xdr, arg); 14591da177e4SLinus Torvalds } 14601da177e4SLinus Torvalds } 14611da177e4SLinus Torvalds 1462bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14631da177e4SLinus Torvalds { 14648687b63aSAl Viro __be32 *p; 14651da177e4SLinus Torvalds 146613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14671da177e4SLinus Torvalds switch (delegation_type) { 14681da177e4SLinus Torvalds case 0: 146934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14701da177e4SLinus Torvalds break; 14711da177e4SLinus Torvalds case FMODE_READ: 147234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14731da177e4SLinus Torvalds break; 14741da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 147534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14761da177e4SLinus Torvalds break; 14771da177e4SLinus Torvalds default: 14781da177e4SLinus Torvalds BUG(); 14791da177e4SLinus Torvalds } 14801da177e4SLinus Torvalds } 14811da177e4SLinus Torvalds 14821da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14831da177e4SLinus Torvalds { 14848687b63aSAl Viro __be32 *p; 14851da177e4SLinus Torvalds 148613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 148734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14881da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14891da177e4SLinus Torvalds } 14901da177e4SLinus Torvalds 1491bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14921da177e4SLinus Torvalds { 14938687b63aSAl Viro __be32 *p; 14941da177e4SLinus Torvalds 149513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 149634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14971da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds 15001da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 15011da177e4SLinus Torvalds { 15028687b63aSAl Viro __be32 *p; 15031da177e4SLinus Torvalds 1504ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1505ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1506ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 15071da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 15081da177e4SLinus Torvalds } 15091da177e4SLinus Torvalds 1510d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1511d9fc6619STrond Myklebust { 1512d9fc6619STrond Myklebust __be32 *p; 1513d9fc6619STrond Myklebust 1514d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1515d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1516d9fc6619STrond Myklebust } 1517d9fc6619STrond Myklebust 1518d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1519d9fc6619STrond Myklebust { 1520d9fc6619STrond Myklebust __be32 *p; 1521d9fc6619STrond Myklebust 1522d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1523d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1524d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1525d9fc6619STrond Myklebust } 1526d9fc6619STrond Myklebust 1527cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15281da177e4SLinus Torvalds { 1529ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15301da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15311da177e4SLinus Torvalds encode_opentype(xdr, arg); 15321da177e4SLinus Torvalds switch (arg->claim) { 15331da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15341da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15351da177e4SLinus Torvalds break; 15361da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15371da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15381da177e4SLinus Torvalds break; 15391da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15401da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15411da177e4SLinus Torvalds break; 1542d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1543d9fc6619STrond Myklebust encode_claim_fh(xdr); 1544d9fc6619STrond Myklebust break; 1545d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1546d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1547d9fc6619STrond Myklebust break; 15481da177e4SLinus Torvalds default: 15491da177e4SLinus Torvalds BUG(); 15501da177e4SLinus Torvalds } 15511da177e4SLinus Torvalds } 15521da177e4SLinus Torvalds 1553cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15541da177e4SLinus Torvalds { 1555ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1556ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15574ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15581da177e4SLinus Torvalds } 15591da177e4SLinus Torvalds 1560cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15611da177e4SLinus Torvalds { 1562ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1563566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15644ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15656ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15661da177e4SLinus Torvalds } 15671da177e4SLinus Torvalds 1568cf8cdbe5SAndy Adamson static void 1569d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15701da177e4SLinus Torvalds { 1571ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15726fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15731da177e4SLinus Torvalds } 15741da177e4SLinus Torvalds 1575cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15761da177e4SLinus Torvalds { 1577ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15781da177e4SLinus Torvalds } 15791da177e4SLinus Torvalds 15803c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15813c6b899cSAnna Schumaker struct compound_hdr *hdr) 15821da177e4SLinus Torvalds { 15838687b63aSAl Viro __be32 *p; 15841da177e4SLinus Torvalds 1585ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15869b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15871da177e4SLinus Torvalds 158813c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1589b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 159034558513SBenny Halevy *p = cpu_to_be32(args->count); 15911da177e4SLinus Torvalds } 15921da177e4SLinus Torvalds 1593cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15941da177e4SLinus Torvalds { 1595aa9c2669SDavid Quigley uint32_t attrs[3] = { 159628331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 159728331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 159828331a46STrond Myklebust }; 15996f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1600cd93710eSChuck Lever __be32 *p, verf[2]; 1601d204c5d2STrond Myklebust uint32_t attrlen = 0; 1602d204c5d2STrond Myklebust unsigned int i; 16031da177e4SLinus Torvalds 160482f2e547SBryan Schumaker if (readdir->plus) { 160582f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 160628331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 160782f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 160882f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 160982f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 161082f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1611d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 16126f7a35bdSTrond Myklebust dircount >>= 1; 161382f2e547SBryan Schumaker } 161428331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 161528331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 161628331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1617d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1618d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1619d204c5d2STrond Myklebust if (attrs[i] != 0) 1620d204c5d2STrond Myklebust attrlen = i+1; 1621d204c5d2STrond Myklebust } 16226f7a35bdSTrond Myklebust 1623475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1624ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1625cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1626d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16276f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16286f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1629d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1630d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1631d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1632cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1633aa9c2669SDavid Quigley 1634aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 163544109241SFred Isaman __func__, 1636eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1637cd93710eSChuck Lever verf[0], verf[1], 1638eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1639aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1640aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16411da177e4SLinus Torvalds } 16421da177e4SLinus Torvalds 1643cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16441da177e4SLinus Torvalds { 1645ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16461da177e4SLinus Torvalds } 16471da177e4SLinus Torvalds 1648cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16491da177e4SLinus Torvalds { 1650ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16516fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16521da177e4SLinus Torvalds } 16531da177e4SLinus Torvalds 1654cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16551da177e4SLinus Torvalds { 1656ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1657811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1658811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16591da177e4SLinus Torvalds } 16601da177e4SLinus Torvalds 1661bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1662bb4dae5eSChuck Lever struct compound_hdr *hdr) 16631da177e4SLinus Torvalds { 1664475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1665ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16661da177e4SLinus Torvalds } 16671da177e4SLinus Torvalds 1668cf8cdbe5SAndy Adamson static void 1669d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 167056ae19f3STrond Myklebust { 1671ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 167256ae19f3STrond Myklebust } 167356ae19f3STrond Myklebust 16749f06c719SChuck Lever static void 1675fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg, 1676fcc85819SChristoph Hellwig struct compound_hdr *hdr) 167723ec6965SJ. Bruce Fields { 16788687b63aSAl Viro __be32 *p; 167923ec6965SJ. Bruce Fields 1680ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1681ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 168213c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1683e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 168434558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 168513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 168634558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16878fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 168823ec6965SJ. Bruce Fields } 168923ec6965SJ. Bruce Fields 1690cf8cdbe5SAndy Adamson static void 1691d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16921da177e4SLinus Torvalds { 1693ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16941da177e4SLinus Torvalds } 16951da177e4SLinus Torvalds 1696cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16971da177e4SLinus Torvalds { 1698ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1699ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 170028cf22d0STrond Myklebust encode_attrs(xdr, arg->iap, arg->label, NULL, server, 170128cf22d0STrond Myklebust server->attr_bitmask); 17021da177e4SLinus Torvalds } 17031da177e4SLinus Torvalds 1704cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 17051da177e4SLinus Torvalds { 17068687b63aSAl Viro __be32 *p; 17071da177e4SLinus Torvalds 170870019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1709cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 17101da177e4SLinus Torvalds 17113a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 17123a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 171313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 171434558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 17151da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 17161da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 171713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 17183a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 17191da177e4SLinus Torvalds } 17201da177e4SLinus Torvalds 1721bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 17221da177e4SLinus Torvalds { 1723475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1724475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1725ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1726cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17271da177e4SLinus Torvalds } 17281da177e4SLinus Torvalds 17293c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17303c6b899cSAnna Schumaker struct compound_hdr *hdr) 17311da177e4SLinus Torvalds { 17328687b63aSAl Viro __be32 *p; 17331da177e4SLinus Torvalds 1734ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17359b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17361da177e4SLinus Torvalds 173713c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1738b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1739e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 174034558513SBenny Halevy *p = cpu_to_be32(args->count); 17411da177e4SLinus Torvalds 17421da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17431da177e4SLinus Torvalds } 17441da177e4SLinus Torvalds 1745cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17461da177e4SLinus Torvalds { 1747ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1748ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17491da177e4SLinus Torvalds } 17509b7b9fccSAndy Adamson 17515a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17525a5ea0d4SBryan Schumaker { 1753ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17546fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17555a5ea0d4SBryan Schumaker } 17565a5ea0d4SBryan Schumaker 175799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17589b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17597c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 1760fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args, 17617c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17627c44f1aeSWeston Andros Adamson { 17637c44f1aeSWeston Andros Adamson __be32 *p; 17647c44f1aeSWeston Andros Adamson 17657c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17667c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 176771a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17687c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 176971a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 177071a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17717c44f1aeSWeston Andros Adamson } 17727c44f1aeSWeston Andros Adamson 1773fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map) 17742031cd1aSWeston Andros Adamson { 17752031cd1aSWeston Andros Adamson unsigned int i; 17762031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17772031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17782031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17792031cd1aSWeston Andros Adamson } 17802031cd1aSWeston Andros Adamson 178199fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 1782fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args, 178399fe60d0SBenny Halevy struct compound_hdr *hdr) 178499fe60d0SBenny Halevy { 178599fe60d0SBenny Halevy __be32 *p; 1786d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1787db8ac8baSWeston Andros Adamson int len = 0; 178899fe60d0SBenny Halevy 178970019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1790fd40559cSTrond Myklebust encode_nfs4_verifier(xdr, &args->verifier); 179199fe60d0SBenny Halevy 17923a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17933a6bb738SJeff Layton args->client->cl_owner_id); 179499fe60d0SBenny Halevy 17952031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17962031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17972031cd1aSWeston Andros Adamson 17982031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17992031cd1aSWeston Andros Adamson case SP4_NONE: 18002031cd1aSWeston Andros Adamson break; 18012031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 18022031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 18032031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 18042031cd1aSWeston Andros Adamson break; 18052031cd1aSWeston Andros Adamson default: 18062031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 18072031cd1aSWeston Andros Adamson break; 18082031cd1aSWeston Andros Adamson } 1809db8ac8baSWeston Andros Adamson 1810db8ac8baSWeston Andros Adamson if (send_implementation_id && 1811db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1812db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1813d751f748SJim Rees <= sizeof(impl_name) + 1) 1814db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1815db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1816db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1817db8ac8baSWeston Andros Adamson 1818db8ac8baSWeston Andros Adamson if (len > 0) { 18192031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1820db8ac8baSWeston Andros Adamson 1821db8ac8baSWeston Andros Adamson encode_string(xdr, 1822db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1823db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1824db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1825db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1826db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1827db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1828db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1829db8ac8baSWeston Andros Adamson } else 18302031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 183199fe60d0SBenny Halevy } 1832fc931582SAndy Adamson 1833fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1834fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args, 1835fc931582SAndy Adamson struct compound_hdr *hdr) 1836fc931582SAndy Adamson { 1837fc931582SAndy Adamson __be32 *p; 1838fc931582SAndy Adamson struct nfs_client *clp = args->client; 183989f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1840f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18418e0d46e1SMike Sager u32 max_resp_sz_cached; 18428e0d46e1SMike Sager 18438e0d46e1SMike Sager /* 18448e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18458e0d46e1SMike Sager * 2 is the verifier. 18468e0d46e1SMike Sager */ 184735c036efSJ. Bruce Fields max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2) 184835c036efSJ. Bruce Fields * XDR_UNIT + RPC_MAX_AUTH_SIZE; 1849fc931582SAndy Adamson 1850475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 185189f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 185279969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 185379969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1854e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1855fc931582SAndy Adamson 1856fc931582SAndy Adamson /* Fore Channel */ 1857c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1858e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1859e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18608e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1861e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1862e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1863e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1864fc931582SAndy Adamson 1865fc931582SAndy Adamson /* Back Channel */ 1866c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1867e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1868e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1869e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1870e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1871e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1872e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1873fc931582SAndy Adamson 1874e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1875e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1876e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1877fc931582SAndy Adamson 1878fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18792f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 188089f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1881e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1882e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 188334558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1884fc931582SAndy Adamson } 18850f3e66c6SAndy Adamson 18860f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 1887fcc85819SChristoph Hellwig const struct nfs4_session *session, 18880f3e66c6SAndy Adamson struct compound_hdr *hdr) 18890f3e66c6SAndy Adamson { 1890475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1891475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18920f3e66c6SAndy Adamson } 189318019753SRicardo Labiaga 189466245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 189566245539STrond Myklebust uint64_t clientid, 189666245539STrond Myklebust struct compound_hdr *hdr) 189766245539STrond Myklebust { 189866245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 189966245539STrond Myklebust encode_uint64(xdr, clientid); 190066245539STrond Myklebust } 190166245539STrond Myklebust 190218019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 1903fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args, 190418019753SRicardo Labiaga struct compound_hdr *hdr) 190518019753SRicardo Labiaga { 1906475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1907475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 190818019753SRicardo Labiaga } 190999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 191099fe60d0SBenny Halevy 19119b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 19129b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 19139b7b9fccSAndy Adamson struct compound_hdr *hdr) 19149b7b9fccSAndy Adamson { 19159b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 19162b2fa717STrond Myklebust struct nfs4_session *session; 1917fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 19182b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1919fc01cea9SAndy Adamson __be32 *p; 19209b7b9fccSAndy Adamson 19212b2fa717STrond Myklebust tp = slot->table; 19222b2fa717STrond Myklebust session = tp->session; 19233bd2384aSChuck Lever if (!session) 19243bd2384aSChuck Lever return; 1925fc01cea9SAndy Adamson 1926475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1927fc01cea9SAndy Adamson 1928fc01cea9SAndy Adamson /* 1929fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1930fc01cea9SAndy Adamson */ 1931fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1932fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1933fc01cea9SAndy Adamson __func__, 1934fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1935fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1936fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1937fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19382b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1939fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1940475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 194193f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1942e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19432b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1944e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 194534558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19469b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19479b7b9fccSAndy Adamson } 19489b7b9fccSAndy Adamson 1949b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1950b1f69b75SAndy Adamson static void 1951b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1952b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1953b1f69b75SAndy Adamson struct compound_hdr *hdr) 1954b1f69b75SAndy Adamson { 1955b1f69b75SAndy Adamson __be32 *p; 1956b1f69b75SAndy Adamson 1957475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 195884c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1959b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1960b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1961b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1962f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 196384c9dee3SChristoph Hellwig 196484c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 196584c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19664e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1967b1f69b75SAndy Adamson } 1968b1f69b75SAndy Adamson 1969b1f69b75SAndy Adamson static void 1970b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1971b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1972b1f69b75SAndy Adamson struct compound_hdr *hdr) 1973b1f69b75SAndy Adamson { 1974b1f69b75SAndy Adamson __be32 *p; 1975b1f69b75SAndy Adamson 1976475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1977475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1978b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1979b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1980b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1981b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1982b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1983b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1984ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1985475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1986b1f69b75SAndy Adamson 1987b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1988b1f69b75SAndy Adamson __func__, 1989b1f69b75SAndy Adamson args->type, 1990b1f69b75SAndy Adamson args->range.iomode, 1991b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1992b1f69b75SAndy Adamson (unsigned long)args->range.length, 1993b1f69b75SAndy Adamson args->maxcount); 1994b1f69b75SAndy Adamson } 1995863a3c6cSAndy Adamson 1996863a3c6cSAndy Adamson static int 1997863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1998ac7db726SBenny Halevy struct inode *inode, 1999fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args, 2000863a3c6cSAndy Adamson struct compound_hdr *hdr) 2001863a3c6cSAndy Adamson { 2002863a3c6cSAndy Adamson __be32 *p; 2003863a3c6cSAndy Adamson 2004863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 2005863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 2006863a3c6cSAndy Adamson 2007475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 2008475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 2009863a3c6cSAndy Adamson /* Only whole file layouts */ 2010863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 20113557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 2012ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 2013ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20142e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 2015ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 2016863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 2017863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 20182e18d4d8STrond Myklebust } else { 20192e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 20202e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 20212e18d4d8STrond Myklebust } 2022863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2023863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2024ac7db726SBenny Halevy 20255f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 202673504740STrond Myklebust if (args->layoutupdate_pages) 20275f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20285f919c9fSChristoph Hellwig args->layoutupdate_len); 2029863a3c6cSAndy Adamson 2030863a3c6cSAndy Adamson return 0; 2031863a3c6cSAndy Adamson } 2032cbe82603SBenny Halevy 2033cbe82603SBenny Halevy static void 2034cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2035cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2036cbe82603SBenny Halevy struct compound_hdr *hdr) 2037cbe82603SBenny Halevy { 2038cbe82603SBenny Halevy __be32 *p; 2039cbe82603SBenny Halevy 2040475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2041475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2042cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2043cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 204415eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2045cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2046ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 204715eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 204815eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2049cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2050ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2051cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20524d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20534d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 205494e5c571STrond Myklebust else 2055475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2056cbe82603SBenny Halevy } 2057fca78d6dSBryan Schumaker 2058fca78d6dSBryan Schumaker static int 2059fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2060fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2061fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2062fca78d6dSBryan Schumaker { 2063475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2064475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2065fca78d6dSBryan Schumaker return 0; 2066fca78d6dSBryan Schumaker } 20677d974794SBryan Schumaker 20687d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 2069fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args, 20707d974794SBryan Schumaker struct compound_hdr *hdr) 20717d974794SBryan Schumaker { 2072475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2073475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2074ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20757d974794SBryan Schumaker } 20769aeda35fSBryan Schumaker 20779aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 2078fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args, 20799aeda35fSBryan Schumaker struct compound_hdr *hdr) 20809aeda35fSBryan Schumaker { 2081ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20827c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20839aeda35fSBryan Schumaker } 2084cf805165STrond Myklebust #else 2085cf805165STrond Myklebust static inline void 2086cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2087cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2088cf805165STrond Myklebust struct compound_hdr *hdr) 2089cf805165STrond Myklebust { 2090cf805165STrond Myklebust } 209156f487f8SFred Isaman 209256f487f8SFred Isaman static void 209356f487f8SFred Isaman encode_layoutget(struct xdr_stream *xdr, 209456f487f8SFred Isaman const struct nfs4_layoutget_args *args, 209556f487f8SFred Isaman struct compound_hdr *hdr) 209656f487f8SFred Isaman { 209756f487f8SFred Isaman } 2098b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2099b1f69b75SAndy Adamson 21001da177e4SLinus Torvalds /* 21011da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 21021da177e4SLinus Torvalds */ 21031da177e4SLinus Torvalds 210466cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 210566cc0429SBenny Halevy { 210666cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 21073bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 21083bd2384aSChuck Lever if (session) 21093bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 211066cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 211166cc0429SBenny Halevy return 0; 211266cc0429SBenny Halevy } 211366cc0429SBenny Halevy 21141da177e4SLinus Torvalds /* 21151da177e4SLinus Torvalds * Encode an ACCESS request 21161da177e4SLinus Torvalds */ 21179f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 2118fcc85819SChristoph Hellwig const void *data) 21191da177e4SLinus Torvalds { 2120fcc85819SChristoph Hellwig const struct nfs4_accessargs *args = data; 21211da177e4SLinus Torvalds struct compound_hdr hdr = { 212266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21231da177e4SLinus Torvalds }; 21241da177e4SLinus Torvalds 21259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21279f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21289f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21298bcbe7d9STrond Myklebust if (args->bitmask) 21309f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2131d017931cSAndy Adamson encode_nops(&hdr); 21321da177e4SLinus Torvalds } 21331da177e4SLinus Torvalds 21341da177e4SLinus Torvalds /* 21351da177e4SLinus Torvalds * Encode LOOKUP request 21361da177e4SLinus Torvalds */ 21379f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 2138fcc85819SChristoph Hellwig const void *data) 21391da177e4SLinus Torvalds { 2140fcc85819SChristoph Hellwig const struct nfs4_lookup_arg *args = data; 21411da177e4SLinus Torvalds struct compound_hdr hdr = { 214266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21431da177e4SLinus Torvalds }; 21441da177e4SLinus Torvalds 21459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21479f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21489f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21499f06c719SChuck Lever encode_getfh(xdr, &hdr); 21509f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2151d017931cSAndy Adamson encode_nops(&hdr); 21521da177e4SLinus Torvalds } 21531da177e4SLinus Torvalds 21541da177e4SLinus Torvalds /* 21555b5faaf6SJeff Layton * Encode LOOKUPP request 21565b5faaf6SJeff Layton */ 21575b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr, 21585b5faaf6SJeff Layton const void *data) 21595b5faaf6SJeff Layton { 21605b5faaf6SJeff Layton const struct nfs4_lookupp_arg *args = data; 21615b5faaf6SJeff Layton struct compound_hdr hdr = { 21625b5faaf6SJeff Layton .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21635b5faaf6SJeff Layton }; 21645b5faaf6SJeff Layton 21655b5faaf6SJeff Layton encode_compound_hdr(xdr, req, &hdr); 21665b5faaf6SJeff Layton encode_sequence(xdr, &args->seq_args, &hdr); 21675b5faaf6SJeff Layton encode_putfh(xdr, args->fh, &hdr); 21685b5faaf6SJeff Layton encode_lookupp(xdr, &hdr); 21695b5faaf6SJeff Layton encode_getfh(xdr, &hdr); 21705b5faaf6SJeff Layton encode_getfattr(xdr, args->bitmask, &hdr); 21715b5faaf6SJeff Layton encode_nops(&hdr); 21725b5faaf6SJeff Layton } 21735b5faaf6SJeff Layton 21745b5faaf6SJeff Layton /* 21751da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21761da177e4SLinus Torvalds */ 21779f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21789f06c719SChuck Lever struct xdr_stream *xdr, 2179fcc85819SChristoph Hellwig const void *data) 21801da177e4SLinus Torvalds { 2181fcc85819SChristoph Hellwig const struct nfs4_lookup_root_arg *args = data; 21821da177e4SLinus Torvalds struct compound_hdr hdr = { 218366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21841da177e4SLinus Torvalds }; 21851da177e4SLinus Torvalds 21869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21889f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21899f06c719SChuck Lever encode_getfh(xdr, &hdr); 21909f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2191d017931cSAndy Adamson encode_nops(&hdr); 21921da177e4SLinus Torvalds } 21931da177e4SLinus Torvalds 21941da177e4SLinus Torvalds /* 21951da177e4SLinus Torvalds * Encode REMOVE request 21961da177e4SLinus Torvalds */ 21979f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 2198fcc85819SChristoph Hellwig const void *data) 21991da177e4SLinus Torvalds { 2200fcc85819SChristoph Hellwig const struct nfs_removeargs *args = data; 22011da177e4SLinus Torvalds struct compound_hdr hdr = { 220266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22031da177e4SLinus Torvalds }; 22041da177e4SLinus Torvalds 22059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22089f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2209d017931cSAndy Adamson encode_nops(&hdr); 22101da177e4SLinus Torvalds } 22111da177e4SLinus Torvalds 22121da177e4SLinus Torvalds /* 22131da177e4SLinus Torvalds * Encode RENAME request 22141da177e4SLinus Torvalds */ 22159f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 2216fcc85819SChristoph Hellwig const void *data) 22171da177e4SLinus Torvalds { 2218fcc85819SChristoph Hellwig const struct nfs_renameargs *args = data; 22191da177e4SLinus Torvalds struct compound_hdr hdr = { 222066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22211da177e4SLinus Torvalds }; 22221da177e4SLinus Torvalds 22239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22249f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22259f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 22269f06c719SChuck Lever encode_savefh(xdr, &hdr); 22279f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 22289f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2229d017931cSAndy Adamson encode_nops(&hdr); 22301da177e4SLinus Torvalds } 22311da177e4SLinus Torvalds 22321da177e4SLinus Torvalds /* 22331da177e4SLinus Torvalds * Encode LINK request 22341da177e4SLinus Torvalds */ 22359f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 2236fcc85819SChristoph Hellwig const void *data) 22371da177e4SLinus Torvalds { 2238fcc85819SChristoph Hellwig const struct nfs4_link_arg *args = data; 22391da177e4SLinus Torvalds struct compound_hdr hdr = { 224066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22411da177e4SLinus Torvalds }; 22421da177e4SLinus Torvalds 22439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22459f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22469f06c719SChuck Lever encode_savefh(xdr, &hdr); 22479f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22489f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22499f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22509f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2251d017931cSAndy Adamson encode_nops(&hdr); 22521da177e4SLinus Torvalds } 22531da177e4SLinus Torvalds 22541da177e4SLinus Torvalds /* 22551da177e4SLinus Torvalds * Encode CREATE request 22561da177e4SLinus Torvalds */ 22579f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 2258fcc85819SChristoph Hellwig const void *data) 22591da177e4SLinus Torvalds { 2260fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 22611da177e4SLinus Torvalds struct compound_hdr hdr = { 226266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22631da177e4SLinus Torvalds }; 22641da177e4SLinus Torvalds 22659f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22669f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22679f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22689f06c719SChuck Lever encode_create(xdr, args, &hdr); 22699f06c719SChuck Lever encode_getfh(xdr, &hdr); 22709f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2271d017931cSAndy Adamson encode_nops(&hdr); 22721da177e4SLinus Torvalds } 22731da177e4SLinus Torvalds 22741da177e4SLinus Torvalds /* 22751da177e4SLinus Torvalds * Encode SYMLINK request 22761da177e4SLinus Torvalds */ 22779f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2278fcc85819SChristoph Hellwig const void *data) 22791da177e4SLinus Torvalds { 2280fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data; 2281fcc85819SChristoph Hellwig 22829f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22831da177e4SLinus Torvalds } 22841da177e4SLinus Torvalds 22851da177e4SLinus Torvalds /* 22861da177e4SLinus Torvalds * Encode GETATTR request 22871da177e4SLinus Torvalds */ 22889f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 2289fcc85819SChristoph Hellwig const void *data) 22901da177e4SLinus Torvalds { 2291fcc85819SChristoph Hellwig const struct nfs4_getattr_arg *args = data; 22921da177e4SLinus Torvalds struct compound_hdr hdr = { 229366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22941da177e4SLinus Torvalds }; 22951da177e4SLinus Torvalds 22969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22979f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22989f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22999f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2300d017931cSAndy Adamson encode_nops(&hdr); 23011da177e4SLinus Torvalds } 23021da177e4SLinus Torvalds 23031da177e4SLinus Torvalds /* 23041da177e4SLinus Torvalds * Encode a CLOSE request 23051da177e4SLinus Torvalds */ 23069f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 2307fcc85819SChristoph Hellwig const void *data) 23081da177e4SLinus Torvalds { 2309fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 23101da177e4SLinus Torvalds struct compound_hdr hdr = { 231166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23121da177e4SLinus Torvalds }; 23131da177e4SLinus Torvalds 23149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23169f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2317cf805165STrond Myklebust if (args->lr_args) 2318cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 23193ecefc92STrond Myklebust if (args->bitmask != NULL) 23209f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2321d8d84983STrond Myklebust encode_close(xdr, args, &hdr); 2322d017931cSAndy Adamson encode_nops(&hdr); 23231da177e4SLinus Torvalds } 23241da177e4SLinus Torvalds 23251da177e4SLinus Torvalds /* 23261da177e4SLinus Torvalds * Encode an OPEN request 23271da177e4SLinus Torvalds */ 23289f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 2329fcc85819SChristoph Hellwig const void *data) 23301da177e4SLinus Torvalds { 2331fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23321da177e4SLinus Torvalds struct compound_hdr hdr = { 233366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23341da177e4SLinus Torvalds }; 23351da177e4SLinus Torvalds 23369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23379f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23389f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23399f06c719SChuck Lever encode_open(xdr, args, &hdr); 23409f06c719SChuck Lever encode_getfh(xdr, &hdr); 2341ae2bb032SWeston Andros Adamson if (args->access) 23426168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 23431549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 234456f487f8SFred Isaman if (args->lg_args) { 234556f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr); 2346cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0, 2347cf500bacSChuck Lever args->lg_args->layout.pglen, 2348cf500bacSChuck Lever hdr.replen); 234956f487f8SFred Isaman } 2350d017931cSAndy Adamson encode_nops(&hdr); 23511da177e4SLinus Torvalds } 23521da177e4SLinus Torvalds 23531da177e4SLinus Torvalds /* 23541da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 23551da177e4SLinus Torvalds */ 23569f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 23579f06c719SChuck Lever struct xdr_stream *xdr, 2358fcc85819SChristoph Hellwig const void *data) 23591da177e4SLinus Torvalds { 2360fcc85819SChristoph Hellwig const struct nfs_open_confirmargs *args = data; 23611da177e4SLinus Torvalds struct compound_hdr hdr = { 2362d017931cSAndy Adamson .nops = 0, 23631da177e4SLinus Torvalds }; 23641da177e4SLinus Torvalds 23659f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23669f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23679f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2368d017931cSAndy Adamson encode_nops(&hdr); 23691da177e4SLinus Torvalds } 23701da177e4SLinus Torvalds 23711da177e4SLinus Torvalds /* 23721da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23731da177e4SLinus Torvalds */ 23749f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23759f06c719SChuck Lever struct xdr_stream *xdr, 2376fcc85819SChristoph Hellwig const void *data) 23771da177e4SLinus Torvalds { 2378fcc85819SChristoph Hellwig const struct nfs_openargs *args = data; 23791da177e4SLinus Torvalds struct compound_hdr hdr = { 238066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23811da177e4SLinus Torvalds }; 23821da177e4SLinus Torvalds 23839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23849f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23859f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23869f06c719SChuck Lever encode_open(xdr, args, &hdr); 2387ae2bb032SWeston Andros Adamson if (args->access) 23886168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2389e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 239056f487f8SFred Isaman if (args->lg_args) { 239156f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr); 2392cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0, 2393cf500bacSChuck Lever args->lg_args->layout.pglen, 2394cf500bacSChuck Lever hdr.replen); 239556f487f8SFred Isaman } 2396d017931cSAndy Adamson encode_nops(&hdr); 23971da177e4SLinus Torvalds } 23981da177e4SLinus Torvalds 23991da177e4SLinus Torvalds /* 24001da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 24011da177e4SLinus Torvalds */ 24029f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 24039f06c719SChuck Lever struct xdr_stream *xdr, 2404fcc85819SChristoph Hellwig const void *data) 24051da177e4SLinus Torvalds { 2406fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data; 24071da177e4SLinus Torvalds struct compound_hdr hdr = { 240866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24091da177e4SLinus Torvalds }; 24101da177e4SLinus Torvalds 24119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24139f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2414b6808145STrond Myklebust if (args->lr_args) 2415b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 24169f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2417d017931cSAndy Adamson encode_nops(&hdr); 24181da177e4SLinus Torvalds } 24191da177e4SLinus Torvalds 24201da177e4SLinus Torvalds /* 24211da177e4SLinus Torvalds * Encode a LOCK request 24221da177e4SLinus Torvalds */ 24239f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 2424fcc85819SChristoph Hellwig const void *data) 24251da177e4SLinus Torvalds { 2426fcc85819SChristoph Hellwig const struct nfs_lock_args *args = data; 24271da177e4SLinus Torvalds struct compound_hdr hdr = { 242866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24291da177e4SLinus Torvalds }; 24301da177e4SLinus Torvalds 24319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24339f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24349f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2435d017931cSAndy Adamson encode_nops(&hdr); 24361da177e4SLinus Torvalds } 24371da177e4SLinus Torvalds 24381da177e4SLinus Torvalds /* 24391da177e4SLinus Torvalds * Encode a LOCKT request 24401da177e4SLinus Torvalds */ 24419f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 2442fcc85819SChristoph Hellwig const void *data) 24431da177e4SLinus Torvalds { 2444fcc85819SChristoph Hellwig const struct nfs_lockt_args *args = data; 24451da177e4SLinus Torvalds struct compound_hdr hdr = { 244666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24471da177e4SLinus Torvalds }; 24481da177e4SLinus Torvalds 24499f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24509f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24519f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24529f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2453d017931cSAndy Adamson encode_nops(&hdr); 24541da177e4SLinus Torvalds } 24551da177e4SLinus Torvalds 24561da177e4SLinus Torvalds /* 24571da177e4SLinus Torvalds * Encode a LOCKU request 24581da177e4SLinus Torvalds */ 24599f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 2460fcc85819SChristoph Hellwig const void *data) 24611da177e4SLinus Torvalds { 2462fcc85819SChristoph Hellwig const struct nfs_locku_args *args = data; 24631da177e4SLinus Torvalds struct compound_hdr hdr = { 246466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24651da177e4SLinus Torvalds }; 24661da177e4SLinus Torvalds 24679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24699f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24709f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2471d017931cSAndy Adamson encode_nops(&hdr); 24721da177e4SLinus Torvalds } 24731da177e4SLinus Torvalds 24749f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24759f06c719SChuck Lever struct xdr_stream *xdr, 2476fcc85819SChristoph Hellwig const void *data) 2477d3c7b7ccSTrond Myklebust { 2478fcc85819SChristoph Hellwig const struct nfs_release_lockowner_args *args = data; 2479d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2480d3c7b7ccSTrond Myklebust .minorversion = 0, 2481d3c7b7ccSTrond Myklebust }; 2482d3c7b7ccSTrond Myklebust 24839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24849f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2485d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2486d3c7b7ccSTrond Myklebust } 2487d3c7b7ccSTrond Myklebust 24881da177e4SLinus Torvalds /* 24891da177e4SLinus Torvalds * Encode a READLINK request 24901da177e4SLinus Torvalds */ 24919f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 2492fcc85819SChristoph Hellwig const void *data) 24931da177e4SLinus Torvalds { 2494fcc85819SChristoph Hellwig const struct nfs4_readlink *args = data; 24951da177e4SLinus Torvalds struct compound_hdr hdr = { 249666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24971da177e4SLinus Torvalds }; 24981da177e4SLinus Torvalds 24999f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25009f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25019f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25029f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2503e3a535e1STrond Myklebust 2504cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pages, args->pgbase, 2505cf500bacSChuck Lever args->pglen, hdr.replen); 2506d017931cSAndy Adamson encode_nops(&hdr); 25071da177e4SLinus Torvalds } 25081da177e4SLinus Torvalds 25091da177e4SLinus Torvalds /* 25101da177e4SLinus Torvalds * Encode a READDIR request 25111da177e4SLinus Torvalds */ 25129f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 2513fcc85819SChristoph Hellwig const void *data) 25141da177e4SLinus Torvalds { 2515fcc85819SChristoph Hellwig const struct nfs4_readdir_arg *args = data; 25161da177e4SLinus Torvalds struct compound_hdr hdr = { 251766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25181da177e4SLinus Torvalds }; 25191da177e4SLinus Torvalds 25209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25219f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25229f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25239f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2524d6ac02dfSTrond Myklebust 2525cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pages, args->pgbase, 2526cf500bacSChuck Lever args->count, hdr.replen); 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 2546cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pages, args->pgbase, 2547cf500bacSChuck Lever args->count, hdr.replen); 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 2593cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->acl_pages, 0, 259429e7ca71SChuck Lever args->acl_len, replen + 1); 2595d017931cSAndy Adamson encode_nops(&hdr); 2596029d105eSJ. Bruce Fields } 2597029d105eSJ. Bruce Fields 2598029d105eSJ. Bruce Fields /* 25991da177e4SLinus Torvalds * Encode a WRITE request 26001da177e4SLinus Torvalds */ 26019f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 2602fcc85819SChristoph Hellwig const void *data) 26031da177e4SLinus Torvalds { 2604fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data; 26051da177e4SLinus Torvalds struct compound_hdr hdr = { 260666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26071da177e4SLinus Torvalds }; 26081da177e4SLinus Torvalds 26099f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26109f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26119f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26129f06c719SChuck Lever encode_write(xdr, args, &hdr); 26134f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 26147ffd1064SFred Isaman if (args->bitmask) 26159f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2616d017931cSAndy Adamson encode_nops(&hdr); 26171da177e4SLinus Torvalds } 26181da177e4SLinus Torvalds 26191da177e4SLinus Torvalds /* 26201da177e4SLinus Torvalds * a COMMIT request 26211da177e4SLinus Torvalds */ 26229f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 2623fcc85819SChristoph Hellwig const void *data) 26241da177e4SLinus Torvalds { 2625fcc85819SChristoph Hellwig const struct nfs_commitargs *args = data; 26261da177e4SLinus Torvalds struct compound_hdr hdr = { 262766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26281da177e4SLinus Torvalds }; 26291da177e4SLinus Torvalds 26309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26329f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26339f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2634d017931cSAndy Adamson encode_nops(&hdr); 26351da177e4SLinus Torvalds } 26361da177e4SLinus Torvalds 26371da177e4SLinus Torvalds /* 26381da177e4SLinus Torvalds * FSINFO request 26391da177e4SLinus Torvalds */ 26409f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 2641fcc85819SChristoph Hellwig const void *data) 26421da177e4SLinus Torvalds { 2643fcc85819SChristoph Hellwig const struct nfs4_fsinfo_arg *args = data; 26441da177e4SLinus Torvalds struct compound_hdr hdr = { 264566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26461da177e4SLinus Torvalds }; 26471da177e4SLinus Torvalds 26489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26499f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26509f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26519f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2652d017931cSAndy Adamson encode_nops(&hdr); 26531da177e4SLinus Torvalds } 26541da177e4SLinus Torvalds 26551da177e4SLinus Torvalds /* 26561da177e4SLinus Torvalds * a PATHCONF request 26571da177e4SLinus Torvalds */ 26589f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 2659fcc85819SChristoph Hellwig const void *data) 26601da177e4SLinus Torvalds { 2661fcc85819SChristoph Hellwig const struct nfs4_pathconf_arg *args = data; 26621da177e4SLinus Torvalds struct compound_hdr hdr = { 266366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26641da177e4SLinus Torvalds }; 26651da177e4SLinus Torvalds 26669f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26679f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26689f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 266937c88763STrond Myklebust encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask, 267037c88763STrond Myklebust ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr); 2671d017931cSAndy Adamson encode_nops(&hdr); 26721da177e4SLinus Torvalds } 26731da177e4SLinus Torvalds 26741da177e4SLinus Torvalds /* 26751da177e4SLinus Torvalds * a STATFS request 26761da177e4SLinus Torvalds */ 26779f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 2678fcc85819SChristoph Hellwig const void *data) 26791da177e4SLinus Torvalds { 2680fcc85819SChristoph Hellwig const struct nfs4_statfs_arg *args = data; 26811da177e4SLinus Torvalds struct compound_hdr hdr = { 268266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26831da177e4SLinus Torvalds }; 26841da177e4SLinus Torvalds 26859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26869f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26879f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 268837c88763STrond Myklebust encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask, 268937c88763STrond Myklebust ARRAY_SIZE(nfs4_statfs_bitmap), &hdr); 2690d017931cSAndy Adamson encode_nops(&hdr); 26911da177e4SLinus Torvalds } 26921da177e4SLinus Torvalds 26931da177e4SLinus Torvalds /* 26941da177e4SLinus Torvalds * GETATTR_BITMAP request 26951da177e4SLinus Torvalds */ 26969f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26979f06c719SChuck Lever struct xdr_stream *xdr, 2698fcc85819SChristoph Hellwig const void *data) 26991da177e4SLinus Torvalds { 2700fcc85819SChristoph Hellwig const struct nfs4_server_caps_arg *args = data; 27018c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 27021da177e4SLinus Torvalds struct compound_hdr hdr = { 270366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27041da177e4SLinus Torvalds }; 27051da177e4SLinus Torvalds 27069f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27079f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27089f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 270937c88763STrond Myklebust encode_getattr(xdr, bitmask, NULL, 3, &hdr); 2710d017931cSAndy Adamson encode_nops(&hdr); 27111da177e4SLinus Torvalds } 27121da177e4SLinus Torvalds 27131da177e4SLinus Torvalds /* 27141da177e4SLinus Torvalds * a RENEW request 27151da177e4SLinus Torvalds */ 27169f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 2717fcc85819SChristoph Hellwig const void *data) 2718fcc85819SChristoph Hellwig 27191da177e4SLinus Torvalds { 2720fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 27211da177e4SLinus Torvalds struct compound_hdr hdr = { 2722d017931cSAndy Adamson .nops = 0, 27231da177e4SLinus Torvalds }; 27241da177e4SLinus Torvalds 27259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2726bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2727d017931cSAndy Adamson encode_nops(&hdr); 27281da177e4SLinus Torvalds } 27291da177e4SLinus Torvalds 27301da177e4SLinus Torvalds /* 27311da177e4SLinus Torvalds * a SETCLIENTID request 27321da177e4SLinus Torvalds */ 27339f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 27349f06c719SChuck Lever struct xdr_stream *xdr, 2735fcc85819SChristoph Hellwig const void *data) 27361da177e4SLinus Torvalds { 2737fcc85819SChristoph Hellwig const struct nfs4_setclientid *sc = data; 27381da177e4SLinus Torvalds struct compound_hdr hdr = { 2739d017931cSAndy Adamson .nops = 0, 27401da177e4SLinus Torvalds }; 27411da177e4SLinus Torvalds 27429f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27439f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2744d017931cSAndy Adamson encode_nops(&hdr); 27451da177e4SLinus Torvalds } 27461da177e4SLinus Torvalds 27471da177e4SLinus Torvalds /* 27481da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 27491da177e4SLinus Torvalds */ 27509f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 27519f06c719SChuck Lever struct xdr_stream *xdr, 2752fcc85819SChristoph Hellwig const void *data) 27531da177e4SLinus Torvalds { 2754fcc85819SChristoph Hellwig const struct nfs4_setclientid_res *arg = data; 27551da177e4SLinus Torvalds struct compound_hdr hdr = { 2756d017931cSAndy Adamson .nops = 0, 27571da177e4SLinus Torvalds }; 27581da177e4SLinus Torvalds 27599f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27609f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2761d017931cSAndy Adamson encode_nops(&hdr); 27621da177e4SLinus Torvalds } 27631da177e4SLinus Torvalds 27641da177e4SLinus Torvalds /* 27651da177e4SLinus Torvalds * DELEGRETURN request 27661da177e4SLinus Torvalds */ 27679f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 27689f06c719SChuck Lever struct xdr_stream *xdr, 2769fcc85819SChristoph Hellwig const void *data) 27701da177e4SLinus Torvalds { 2771fcc85819SChristoph Hellwig const struct nfs4_delegreturnargs *args = data; 27721da177e4SLinus Torvalds struct compound_hdr hdr = { 277366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27741da177e4SLinus Torvalds }; 27751da177e4SLinus Torvalds 27769f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27779f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 27789f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2779586f1c39STrond Myklebust if (args->lr_args) 2780586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 27818ac2b422STrond Myklebust if (args->bitmask) 27829f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2783e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2784d017931cSAndy Adamson encode_nops(&hdr); 27851da177e4SLinus Torvalds } 27861da177e4SLinus Torvalds 27871da177e4SLinus Torvalds /* 2788683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2789683b57b4STrond Myklebust */ 27909f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27919f06c719SChuck Lever struct xdr_stream *xdr, 2792fcc85819SChristoph Hellwig const void *data) 2793683b57b4STrond Myklebust { 2794fcc85819SChristoph Hellwig const struct nfs4_fs_locations_arg *args = data; 2795683b57b4STrond Myklebust struct compound_hdr hdr = { 279666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2797683b57b4STrond Myklebust }; 279828f56694SBenny Halevy uint32_t replen; 2799683b57b4STrond Myklebust 28009f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28019f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2802b03d735bSChuck Lever if (args->migration) { 2803b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2804b03d735bSChuck Lever replen = hdr.replen; 2805b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2806b03d735bSChuck Lever if (args->renew) 2807b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2808b03d735bSChuck Lever } else { 28099f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 28109f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2811b03d735bSChuck Lever replen = hdr.replen; 28129f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2813b03d735bSChuck Lever } 2814cf8cdbe5SAndy Adamson 2815cf500bacSChuck Lever rpc_prepare_reply_pages(req, (struct page **)&args->page, 0, 281629e7ca71SChuck Lever PAGE_SIZE, replen + 1); 2817d017931cSAndy Adamson encode_nops(&hdr); 2818683b57b4STrond Myklebust } 2819683b57b4STrond Myklebust 28205a5ea0d4SBryan Schumaker /* 28215a5ea0d4SBryan Schumaker * Encode SECINFO request 28225a5ea0d4SBryan Schumaker */ 28235a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 28245a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 2825fcc85819SChristoph Hellwig const void *data) 28265a5ea0d4SBryan Schumaker { 2827fcc85819SChristoph Hellwig const struct nfs4_secinfo_arg *args = data; 28285a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 28295a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 28305a5ea0d4SBryan Schumaker }; 28315a5ea0d4SBryan Schumaker 28325a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 28335a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 28345a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 28355a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 28365a5ea0d4SBryan Schumaker encode_nops(&hdr); 28375a5ea0d4SBryan Schumaker } 28385a5ea0d4SBryan Schumaker 283944c99933SChuck Lever /* 284044c99933SChuck Lever * Encode FSID_PRESENT request 284144c99933SChuck Lever */ 284244c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 284344c99933SChuck Lever struct xdr_stream *xdr, 2844fcc85819SChristoph Hellwig const void *data) 284544c99933SChuck Lever { 2846fcc85819SChristoph Hellwig const struct nfs4_fsid_present_arg *args = data; 284744c99933SChuck Lever struct compound_hdr hdr = { 284844c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 284944c99933SChuck Lever }; 285044c99933SChuck Lever 285144c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 285244c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 285344c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 285444c99933SChuck Lever encode_getfh(xdr, &hdr); 285544c99933SChuck Lever if (args->renew) 285644c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 285744c99933SChuck Lever encode_nops(&hdr); 285844c99933SChuck Lever } 285944c99933SChuck Lever 286099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 286199fe60d0SBenny Halevy /* 28627c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 28637c44f1aeSWeston Andros Adamson */ 28647c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 28657c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 2866fcc85819SChristoph Hellwig const void *data) 28677c44f1aeSWeston Andros Adamson { 2868fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args = data; 28697c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 287071a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 28717c44f1aeSWeston Andros Adamson }; 28727c44f1aeSWeston Andros Adamson 28737c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 287471a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 28757c44f1aeSWeston Andros Adamson encode_nops(&hdr); 28767c44f1aeSWeston Andros Adamson } 28777c44f1aeSWeston Andros Adamson 28787c44f1aeSWeston Andros Adamson /* 287999fe60d0SBenny Halevy * EXCHANGE_ID request 288099fe60d0SBenny Halevy */ 28819f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 28829f06c719SChuck Lever struct xdr_stream *xdr, 2883fcc85819SChristoph Hellwig const void *data) 288499fe60d0SBenny Halevy { 2885fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args = data; 288699fe60d0SBenny Halevy struct compound_hdr hdr = { 2887a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 288899fe60d0SBenny Halevy }; 288999fe60d0SBenny Halevy 28909f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28919f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 289299fe60d0SBenny Halevy encode_nops(&hdr); 289399fe60d0SBenny Halevy } 28942050f0ccSAndy Adamson 28952050f0ccSAndy Adamson /* 2896fc931582SAndy Adamson * a CREATE_SESSION request 2897fc931582SAndy Adamson */ 28989f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28999f06c719SChuck Lever struct xdr_stream *xdr, 2900fcc85819SChristoph Hellwig const void *data) 2901fc931582SAndy Adamson { 2902fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args = data; 2903fc931582SAndy Adamson struct compound_hdr hdr = { 2904a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2905fc931582SAndy Adamson }; 2906fc931582SAndy Adamson 29079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29089f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2909fc931582SAndy Adamson encode_nops(&hdr); 2910fc931582SAndy Adamson } 2911fc931582SAndy Adamson 2912fc931582SAndy Adamson /* 29130f3e66c6SAndy Adamson * a DESTROY_SESSION request 29140f3e66c6SAndy Adamson */ 29159f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 29169f06c719SChuck Lever struct xdr_stream *xdr, 2917fcc85819SChristoph Hellwig const void *data) 29180f3e66c6SAndy Adamson { 2919fcc85819SChristoph Hellwig const struct nfs4_session *session = data; 29200f3e66c6SAndy Adamson struct compound_hdr hdr = { 2921a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 29220f3e66c6SAndy Adamson }; 29230f3e66c6SAndy Adamson 29249f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29259f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 29260f3e66c6SAndy Adamson encode_nops(&hdr); 29270f3e66c6SAndy Adamson } 29280f3e66c6SAndy Adamson 29290f3e66c6SAndy Adamson /* 293066245539STrond Myklebust * a DESTROY_CLIENTID request 293166245539STrond Myklebust */ 293266245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 293366245539STrond Myklebust struct xdr_stream *xdr, 2934fcc85819SChristoph Hellwig const void *data) 293566245539STrond Myklebust { 2936fcc85819SChristoph Hellwig const struct nfs_client *clp = data; 293766245539STrond Myklebust struct compound_hdr hdr = { 293866245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 293966245539STrond Myklebust }; 294066245539STrond Myklebust 294166245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 294266245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 294366245539STrond Myklebust encode_nops(&hdr); 294466245539STrond Myklebust } 294566245539STrond Myklebust 294666245539STrond Myklebust /* 2947fc01cea9SAndy Adamson * a SEQUENCE request 2948fc01cea9SAndy Adamson */ 29499f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2950fcc85819SChristoph Hellwig const void *data) 2951fc01cea9SAndy Adamson { 2952fcc85819SChristoph Hellwig const struct nfs4_sequence_args *args = data; 2953fc01cea9SAndy Adamson struct compound_hdr hdr = { 2954fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2955fc01cea9SAndy Adamson }; 2956fc01cea9SAndy Adamson 29579f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29589f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2959fc01cea9SAndy Adamson encode_nops(&hdr); 2960fc01cea9SAndy Adamson } 2961fc01cea9SAndy Adamson 29620efb01b2SDonald Buczek #endif 29630efb01b2SDonald Buczek 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 29840efb01b2SDonald Buczek #ifdef CONFIG_NFS_V4_1 29850efb01b2SDonald Buczek 298618019753SRicardo Labiaga /* 298718019753SRicardo Labiaga * a RECLAIM_COMPLETE request 298818019753SRicardo Labiaga */ 29899f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 29909f06c719SChuck Lever struct xdr_stream *xdr, 2991fcc85819SChristoph Hellwig const void *data) 299218019753SRicardo Labiaga { 2993fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args = data; 299418019753SRicardo Labiaga struct compound_hdr hdr = { 299518019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 299618019753SRicardo Labiaga }; 299718019753SRicardo Labiaga 29989f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29999f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 30009f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 300118019753SRicardo Labiaga encode_nops(&hdr); 300218019753SRicardo Labiaga } 300318019753SRicardo Labiaga 3004b1f69b75SAndy Adamson /* 3005b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 3006b1f69b75SAndy Adamson */ 30079f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 30089f06c719SChuck Lever struct xdr_stream *xdr, 3009fcc85819SChristoph Hellwig const void *data) 3010b1f69b75SAndy Adamson { 3011fcc85819SChristoph Hellwig const struct nfs4_getdeviceinfo_args *args = data; 3012b1f69b75SAndy Adamson struct compound_hdr hdr = { 3013b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3014b1f69b75SAndy Adamson }; 3015b1f69b75SAndy Adamson 30169f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 30179f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 30189f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 3019b1f69b75SAndy Adamson 3020b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 3021b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 3022cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase, 3023cf500bacSChuck Lever args->pdev->pglen, hdr.replen - 2); 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 3044cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->layout.pages, 0, 3045cf500bacSChuck Lever args->layout.pglen, hdr.replen); 3046b1f69b75SAndy Adamson encode_nops(&hdr); 3047b1f69b75SAndy Adamson } 3048863a3c6cSAndy Adamson 3049863a3c6cSAndy Adamson /* 3050863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 3051863a3c6cSAndy Adamson */ 3052cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 3053863a3c6cSAndy Adamson struct xdr_stream *xdr, 3054fcc85819SChristoph Hellwig const void *priv) 3055863a3c6cSAndy Adamson { 3056fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args = priv; 3057ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 3058ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 3059863a3c6cSAndy Adamson struct compound_hdr hdr = { 3060863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3061863a3c6cSAndy Adamson }; 3062863a3c6cSAndy Adamson 3063863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 3064863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 3065863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3066ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 3067863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 3068863a3c6cSAndy Adamson encode_nops(&hdr); 3069cbe82603SBenny Halevy } 3070cbe82603SBenny Halevy 3071cbe82603SBenny Halevy /* 3072cbe82603SBenny Halevy * Encode LAYOUTRETURN request 3073cbe82603SBenny Halevy */ 3074cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 3075cbe82603SBenny Halevy struct xdr_stream *xdr, 3076fcc85819SChristoph Hellwig const void *data) 3077cbe82603SBenny Halevy { 3078fcc85819SChristoph Hellwig const struct nfs4_layoutreturn_args *args = data; 3079cbe82603SBenny Halevy struct compound_hdr hdr = { 3080cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3081cbe82603SBenny Halevy }; 3082cbe82603SBenny Halevy 3083cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 3084cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 3085cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 3086cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 3087cbe82603SBenny Halevy encode_nops(&hdr); 3088863a3c6cSAndy Adamson } 3089fca78d6dSBryan Schumaker 3090fca78d6dSBryan Schumaker /* 3091fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 3092fca78d6dSBryan Schumaker */ 3093fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 3094fca78d6dSBryan Schumaker struct xdr_stream *xdr, 3095fcc85819SChristoph Hellwig const void *data) 3096fca78d6dSBryan Schumaker { 3097fcc85819SChristoph Hellwig const struct nfs41_secinfo_no_name_args *args = data; 3098fca78d6dSBryan Schumaker struct compound_hdr hdr = { 3099fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 3100fca78d6dSBryan Schumaker }; 3101fca78d6dSBryan Schumaker 3102fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 3103fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 3104fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 3105fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3106fca78d6dSBryan Schumaker encode_nops(&hdr); 3107fca78d6dSBryan Schumaker } 31087d974794SBryan Schumaker 31097d974794SBryan Schumaker /* 31107d974794SBryan Schumaker * Encode TEST_STATEID request 31117d974794SBryan Schumaker */ 31127d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 31137d974794SBryan Schumaker struct xdr_stream *xdr, 3114fcc85819SChristoph Hellwig const void *data) 31157d974794SBryan Schumaker { 3116fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args = data; 31177d974794SBryan Schumaker struct compound_hdr hdr = { 31187d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 31197d974794SBryan Schumaker }; 31207d974794SBryan Schumaker 31217d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31227d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31237d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 31247d974794SBryan Schumaker encode_nops(&hdr); 31257d974794SBryan Schumaker } 31269aeda35fSBryan Schumaker 31279aeda35fSBryan Schumaker /* 31289aeda35fSBryan Schumaker * Encode FREE_STATEID request 31299aeda35fSBryan Schumaker */ 31309aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 31319aeda35fSBryan Schumaker struct xdr_stream *xdr, 3132fcc85819SChristoph Hellwig const void *data) 31339aeda35fSBryan Schumaker { 3134fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args = data; 31359aeda35fSBryan Schumaker struct compound_hdr hdr = { 31369aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 31379aeda35fSBryan Schumaker }; 31389aeda35fSBryan Schumaker 31399aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 31409aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 31419aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 31429aeda35fSBryan Schumaker encode_nops(&hdr); 31439aeda35fSBryan Schumaker } 314499fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 314599fe60d0SBenny Halevy 3146683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 31471da177e4SLinus Torvalds { 31486da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, 31496da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT); 3150eb72f484SChuck Lever if (unlikely(ret < 0)) 3151c0eae66eSBenny Halevy return -EIO; 31526da59ce2STrond Myklebust *len = ret; 31536da59ce2STrond Myklebust return 0; 31546da59ce2STrond Myklebust } 31551da177e4SLinus Torvalds 31561da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 31571da177e4SLinus Torvalds { 31588687b63aSAl Viro __be32 *p; 31591da177e4SLinus Torvalds 3160c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3161c0eae66eSBenny Halevy if (unlikely(!p)) 3162eb72f484SChuck Lever return -EIO; 31636f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3164cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 31651da177e4SLinus Torvalds 3166c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3167c0eae66eSBenny Halevy if (unlikely(!p)) 3168eb72f484SChuck Lever return -EIO; 31691da177e4SLinus Torvalds hdr->tag = (char *)p; 31701da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3171cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3172aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3173aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 31741da177e4SLinus Torvalds return 0; 31751da177e4SLinus Torvalds } 31761da177e4SLinus Torvalds 3177c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3178c7848f69STrond Myklebust int *nfs_retval) 31791da177e4SLinus Torvalds { 31808687b63aSAl Viro __be32 *p; 31811da177e4SLinus Torvalds uint32_t opnum; 31821da177e4SLinus Torvalds int32_t nfserr; 31831da177e4SLinus Torvalds 3184c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3185c0eae66eSBenny Halevy if (unlikely(!p)) 3186c0eae66eSBenny Halevy goto out_overflow; 31876f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3188c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3189c7848f69STrond Myklebust goto out_bad_operation; 3190f23f6584SChuck Lever if (unlikely(*p != cpu_to_be32(NFS_OK))) 3191f23f6584SChuck Lever goto out_status; 3192c7848f69STrond Myklebust *nfs_retval = 0; 3193f23f6584SChuck Lever return true; 3194f23f6584SChuck Lever out_status: 3195f23f6584SChuck Lever nfserr = be32_to_cpup(p); 319662a92ba9SChuck Lever trace_nfs4_xdr_status(xdr, opnum, nfserr); 3197c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3198c7848f69STrond Myklebust return true; 3199c7848f69STrond Myklebust out_bad_operation: 3200fe82a183SChuck Lever dprintk("nfs: Server returned operation" 32011da177e4SLinus Torvalds " %d but we issued a request for %d\n", 32021da177e4SLinus Torvalds opnum, expected); 3203c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3204c7848f69STrond Myklebust return false; 3205c0eae66eSBenny Halevy out_overflow: 3206c7848f69STrond Myklebust *nfs_retval = -EIO; 3207c7848f69STrond Myklebust return false; 3208c7848f69STrond Myklebust } 3209c7848f69STrond Myklebust 3210c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3211c7848f69STrond Myklebust { 3212c7848f69STrond Myklebust int retval; 3213c7848f69STrond Myklebust 3214c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3215c7848f69STrond Myklebust return retval; 32161da177e4SLinus Torvalds } 32171da177e4SLinus Torvalds 32181da177e4SLinus Torvalds /* Dummy routine */ 32191bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace) 32201da177e4SLinus Torvalds { 32218687b63aSAl Viro __be32 *p; 3222683b57b4STrond Myklebust unsigned int strlen; 32231da177e4SLinus Torvalds char *str; 32241da177e4SLinus Torvalds 3225c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3226eb72f484SChuck Lever if (unlikely(!p)) 3227c0eae66eSBenny Halevy return -EIO; 3228eb72f484SChuck Lever return decode_opaque_inline(xdr, &strlen, &str); 32291da177e4SLinus Torvalds } 32301da177e4SLinus Torvalds 323137c88763STrond Myklebust static ssize_t 323237c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz) 32331da177e4SLinus Torvalds { 323437c88763STrond Myklebust ssize_t ret; 32351da177e4SLinus Torvalds 323637c88763STrond Myklebust ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz); 323737c88763STrond Myklebust if (likely(ret >= 0)) 323837c88763STrond Myklebust return ret; 3239eb72f484SChuck Lever if (ret != -EMSGSIZE) 3240c0eae66eSBenny Halevy return -EIO; 3241eb72f484SChuck Lever return sz; 32421da177e4SLinus Torvalds } 32431da177e4SLinus Torvalds 324437c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 324537c88763STrond Myklebust { 324637c88763STrond Myklebust ssize_t ret; 324737c88763STrond Myklebust ret = decode_bitmap4(xdr, bitmap, 3); 324837c88763STrond Myklebust return ret < 0 ? ret : 0; 324937c88763STrond Myklebust } 325037c88763STrond Myklebust 3251256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 32521da177e4SLinus Torvalds { 32538687b63aSAl Viro __be32 *p; 32541da177e4SLinus Torvalds 3255c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3256c0eae66eSBenny Halevy if (unlikely(!p)) 3257eb72f484SChuck Lever return -EIO; 3258cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3259256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 32601da177e4SLinus Torvalds return 0; 32611da177e4SLinus Torvalds } 32621da177e4SLinus Torvalds 32631da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 32641da177e4SLinus Torvalds { 32651da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 32663388bff5SRoman Borisov int ret; 32673388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 32683388bff5SRoman Borisov if (unlikely(ret < 0)) 32693388bff5SRoman Borisov return ret; 32701da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 32711da177e4SLinus Torvalds } else 3272dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3273dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3274dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 32751da177e4SLinus Torvalds return 0; 32761da177e4SLinus Torvalds } 32771da177e4SLinus Torvalds 32781da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32791da177e4SLinus Torvalds { 32808687b63aSAl Viro __be32 *p; 3281409924e4STrond Myklebust int ret = 0; 32821da177e4SLinus Torvalds 32831da177e4SLinus Torvalds *type = 0; 32841da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32851da177e4SLinus Torvalds return -EIO; 32861da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3287c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3288c0eae66eSBenny Halevy if (unlikely(!p)) 3289eb72f484SChuck Lever return -EIO; 3290cccddf4fSBenny Halevy *type = be32_to_cpup(p); 32911da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 32923110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 32931da177e4SLinus Torvalds return -EIO; 32941da177e4SLinus Torvalds } 32951da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3296409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 32971da177e4SLinus Torvalds } 3298bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3299409924e4STrond Myklebust return ret; 33001da177e4SLinus Torvalds } 33011da177e4SLinus Torvalds 3302264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3303264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3304264e6351SChuck Lever { 3305264e6351SChuck Lever __be32 *p; 3306264e6351SChuck Lever 3307264e6351SChuck Lever *type = 0; 3308264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3309264e6351SChuck Lever return -EIO; 3310264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3311264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3312264e6351SChuck Lever if (unlikely(!p)) 3313eb72f484SChuck Lever return -EIO; 3314264e6351SChuck Lever *type = be32_to_cpup(p); 3315264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3316264e6351SChuck Lever } 3317264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3318264e6351SChuck Lever return 0; 3319264e6351SChuck Lever } 3320264e6351SChuck Lever 33211da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 33221da177e4SLinus Torvalds { 33238687b63aSAl Viro __be32 *p; 3324409924e4STrond Myklebust int ret = 0; 33251da177e4SLinus Torvalds 33261da177e4SLinus Torvalds *change = 0; 33271da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 33281da177e4SLinus Torvalds return -EIO; 33291da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3330c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3331c0eae66eSBenny Halevy if (unlikely(!p)) 3332eb72f484SChuck Lever return -EIO; 3333cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 33341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3335409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 33361da177e4SLinus Torvalds } 33373110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 33381da177e4SLinus Torvalds (unsigned long long)*change); 3339409924e4STrond Myklebust return ret; 33401da177e4SLinus Torvalds } 33411da177e4SLinus Torvalds 33421da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 33431da177e4SLinus Torvalds { 33448687b63aSAl Viro __be32 *p; 3345409924e4STrond Myklebust int ret = 0; 33461da177e4SLinus Torvalds 33471da177e4SLinus Torvalds *size = 0; 33481da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 33491da177e4SLinus Torvalds return -EIO; 33501da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3351c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3352c0eae66eSBenny Halevy if (unlikely(!p)) 3353eb72f484SChuck Lever return -EIO; 3354cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 33551da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3356409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 33571da177e4SLinus Torvalds } 33583110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3359409924e4STrond Myklebust return ret; 33601da177e4SLinus Torvalds } 33611da177e4SLinus Torvalds 33621da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33631da177e4SLinus Torvalds { 33648687b63aSAl Viro __be32 *p; 33651da177e4SLinus Torvalds 33661da177e4SLinus Torvalds *res = 0; 33671da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 33681da177e4SLinus Torvalds return -EIO; 33691da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3370c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3371c0eae66eSBenny Halevy if (unlikely(!p)) 3372eb72f484SChuck Lever return -EIO; 3373cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33741da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 33751da177e4SLinus Torvalds } 33763110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 33771da177e4SLinus Torvalds return 0; 33781da177e4SLinus Torvalds } 33791da177e4SLinus Torvalds 33801da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33811da177e4SLinus Torvalds { 33828687b63aSAl Viro __be32 *p; 33831da177e4SLinus Torvalds 33841da177e4SLinus Torvalds *res = 0; 33851da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 33861da177e4SLinus Torvalds return -EIO; 33871da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3388c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3389c0eae66eSBenny Halevy if (unlikely(!p)) 3390eb72f484SChuck Lever return -EIO; 3391cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33921da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 33931da177e4SLinus Torvalds } 33943110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 33951da177e4SLinus Torvalds return 0; 33961da177e4SLinus Torvalds } 33971da177e4SLinus Torvalds 33988b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 33991da177e4SLinus Torvalds { 34008687b63aSAl Viro __be32 *p; 3401409924e4STrond Myklebust int ret = 0; 34021da177e4SLinus Torvalds 34031da177e4SLinus Torvalds fsid->major = 0; 34041da177e4SLinus Torvalds fsid->minor = 0; 34051da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 34061da177e4SLinus Torvalds return -EIO; 34071da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3408c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3409c0eae66eSBenny Halevy if (unlikely(!p)) 3410eb72f484SChuck Lever return -EIO; 34113ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3412cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 34131da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3414409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 34151da177e4SLinus Torvalds } 34163110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 34171da177e4SLinus Torvalds (unsigned long long)fsid->major, 34181da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3419409924e4STrond Myklebust return ret; 34201da177e4SLinus Torvalds } 34211da177e4SLinus Torvalds 34221da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34231da177e4SLinus Torvalds { 34248687b63aSAl Viro __be32 *p; 34251da177e4SLinus Torvalds 34261da177e4SLinus Torvalds *res = 60; 34271da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 34281da177e4SLinus Torvalds return -EIO; 34291da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3430c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3431c0eae66eSBenny Halevy if (unlikely(!p)) 3432eb72f484SChuck Lever return -EIO; 3433cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34341da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 34351da177e4SLinus Torvalds } 34362eaf426dSDonald Buczek dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res); 34371da177e4SLinus Torvalds return 0; 34381da177e4SLinus Torvalds } 34391da177e4SLinus Torvalds 3440ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3441ae42c70aSBryan Schumaker { 3442ae42c70aSBryan Schumaker __be32 *p; 3443ae42c70aSBryan Schumaker 3444ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3445ae42c70aSBryan Schumaker return -EIO; 3446ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3447ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3448ae42c70aSBryan Schumaker if (unlikely(!p)) 3449eb72f484SChuck Lever return -EIO; 3450ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3451ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3452ae42c70aSBryan Schumaker } 3453ae42c70aSBryan Schumaker return 0; 3454ae42c70aSBryan Schumaker } 3455ae42c70aSBryan Schumaker 34568c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 34578c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 34588c61282fSKinglong Mee { 34598c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 34608c61282fSKinglong Mee int ret; 34618c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 34628c61282fSKinglong Mee if (unlikely(ret < 0)) 34638c61282fSKinglong Mee return ret; 34648c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 34658c61282fSKinglong Mee } else 34668c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 34678c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 34688c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 34698c61282fSKinglong Mee return 0; 34708c61282fSKinglong Mee } 34718c61282fSKinglong Mee 3472ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3473ae42c70aSBryan Schumaker { 3474ae42c70aSBryan Schumaker __be32 *p; 347586bbd742SFrank Sorenson u32 len; 3476ae42c70aSBryan Schumaker 34777ad07353STrond Myklebust if (fh != NULL) 3478ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3479ae42c70aSBryan Schumaker 3480ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3481ae42c70aSBryan Schumaker return -EIO; 3482ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3483ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3484ae42c70aSBryan Schumaker if (unlikely(!p)) 3485eb72f484SChuck Lever return -EIO; 3486ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3487ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3488ae42c70aSBryan Schumaker return -EIO; 3489ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3490ae42c70aSBryan Schumaker if (unlikely(!p)) 3491eb72f484SChuck Lever return -EIO; 34927ad07353STrond Myklebust if (fh != NULL) { 3493ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 34947ad07353STrond Myklebust fh->size = len; 34957ad07353STrond Myklebust } 3496ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3497ae42c70aSBryan Schumaker } 3498ae42c70aSBryan Schumaker return 0; 3499ae42c70aSBryan Schumaker } 3500ae42c70aSBryan Schumaker 35011da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 35021da177e4SLinus Torvalds { 35038687b63aSAl Viro __be32 *p; 35041da177e4SLinus Torvalds 3505a1800acaSMalahal Naineni *res = 0; 35061da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 35071da177e4SLinus Torvalds return -EIO; 35081da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3509c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3510c0eae66eSBenny Halevy if (unlikely(!p)) 3511eb72f484SChuck Lever return -EIO; 3512cccddf4fSBenny Halevy *res = be32_to_cpup(p); 35131da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 35141da177e4SLinus Torvalds } 35153110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 35161da177e4SLinus Torvalds return 0; 35171da177e4SLinus Torvalds } 35181da177e4SLinus Torvalds 35191da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 35201da177e4SLinus Torvalds { 35218687b63aSAl Viro __be32 *p; 3522409924e4STrond Myklebust int ret = 0; 35231da177e4SLinus Torvalds 35241da177e4SLinus Torvalds *fileid = 0; 35251da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 35261da177e4SLinus Torvalds return -EIO; 35271da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3528c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3529c0eae66eSBenny Halevy if (unlikely(!p)) 3530eb72f484SChuck Lever return -EIO; 3531cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 35321da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3533409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 35341da177e4SLinus Torvalds } 35353110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3536409924e4STrond Myklebust return ret; 35371da177e4SLinus Torvalds } 35381da177e4SLinus Torvalds 353999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 354099baf625SManoj Naik { 35418687b63aSAl Viro __be32 *p; 3542409924e4STrond Myklebust int ret = 0; 354399baf625SManoj Naik 354499baf625SManoj Naik *fileid = 0; 354599baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 354699baf625SManoj Naik return -EIO; 354799baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3548c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3549c0eae66eSBenny Halevy if (unlikely(!p)) 3550eb72f484SChuck Lever return -EIO; 3551cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 355299baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 355328331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 355499baf625SManoj Naik } 35553110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3556409924e4STrond Myklebust return ret; 355799baf625SManoj Naik } 355899baf625SManoj Naik 35591da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35601da177e4SLinus Torvalds { 35618687b63aSAl Viro __be32 *p; 35621da177e4SLinus Torvalds int status = 0; 35631da177e4SLinus Torvalds 35641da177e4SLinus Torvalds *res = 0; 35651da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 35661da177e4SLinus Torvalds return -EIO; 35671da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3568c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3569c0eae66eSBenny Halevy if (unlikely(!p)) 3570eb72f484SChuck Lever return -EIO; 3571cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35721da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 35731da177e4SLinus Torvalds } 35743110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 35751da177e4SLinus Torvalds return status; 35761da177e4SLinus Torvalds } 35771da177e4SLinus Torvalds 35781da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35791da177e4SLinus Torvalds { 35808687b63aSAl Viro __be32 *p; 35811da177e4SLinus Torvalds int status = 0; 35821da177e4SLinus Torvalds 35831da177e4SLinus Torvalds *res = 0; 35841da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 35851da177e4SLinus Torvalds return -EIO; 35861da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3587c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3588c0eae66eSBenny Halevy if (unlikely(!p)) 3589eb72f484SChuck Lever return -EIO; 3590cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35911da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 35921da177e4SLinus Torvalds } 35933110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 35941da177e4SLinus Torvalds return status; 35951da177e4SLinus Torvalds } 35961da177e4SLinus Torvalds 35971da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35981da177e4SLinus Torvalds { 35998687b63aSAl Viro __be32 *p; 36001da177e4SLinus Torvalds int status = 0; 36011da177e4SLinus Torvalds 36021da177e4SLinus Torvalds *res = 0; 36031da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 36041da177e4SLinus Torvalds return -EIO; 36051da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3606c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3607c0eae66eSBenny Halevy if (unlikely(!p)) 3608eb72f484SChuck Lever return -EIO; 3609cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36101da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 36111da177e4SLinus Torvalds } 36123110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 36131da177e4SLinus Torvalds return status; 36141da177e4SLinus Torvalds } 36151da177e4SLinus Torvalds 36167aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 36177aaa0b3bSManoj Naik { 3618464ad6b1SChuck Lever u32 n; 36198687b63aSAl Viro __be32 *p; 36207aaa0b3bSManoj Naik int status = 0; 36217aaa0b3bSManoj Naik 3622c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3623c0eae66eSBenny Halevy if (unlikely(!p)) 3624eb72f484SChuck Lever return -EIO; 3625cccddf4fSBenny Halevy n = be32_to_cpup(p); 362633a43f28SAndy Adamson if (n == 0) 362733a43f28SAndy Adamson goto root_path; 362802a2976cSChuck Lever dprintk("pathname4: "); 3629809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3630809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3631809b426cSTrond Myklebust goto out_eio; 3632809b426cSTrond Myklebust } 3633809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36347aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 36357aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 36367aaa0b3bSManoj Naik if (unlikely(status != 0)) 36377aaa0b3bSManoj Naik goto out_eio; 363895a13f7bSTrond Myklebust ifdebug (XDR) 363902a2976cSChuck Lever pr_cont("%s%.*s ", 364002a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 364102a2976cSChuck Lever component->len, component->data); 36427aaa0b3bSManoj Naik } 36437aaa0b3bSManoj Naik out: 36447aaa0b3bSManoj Naik return status; 364533a43f28SAndy Adamson root_path: 364633a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 364733a43f28SAndy Adamson path->ncomponents = 1; 364833a43f28SAndy Adamson path->components[0].len=0; 364933a43f28SAndy Adamson path->components[0].data=NULL; 365002a2976cSChuck Lever dprintk("pathname4: /\n"); 365133a43f28SAndy Adamson goto out; 36527aaa0b3bSManoj Naik out_eio: 36537aaa0b3bSManoj Naik dprintk(" status %d", status); 36547aaa0b3bSManoj Naik status = -EIO; 36557aaa0b3bSManoj Naik goto out; 36567aaa0b3bSManoj Naik } 36577aaa0b3bSManoj Naik 36587aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3659683b57b4STrond Myklebust { 3660683b57b4STrond Myklebust int n; 36618687b63aSAl Viro __be32 *p; 3662683b57b4STrond Myklebust int status = -EIO; 3663683b57b4STrond Myklebust 3664683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3665683b57b4STrond Myklebust goto out; 3666683b57b4STrond Myklebust status = 0; 3667683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3668683b57b4STrond Myklebust goto out; 3669f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 36708b7e3f49STrond Myklebust status = -EIO; 36718b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 36728b7e3f49STrond Myklebust if (unlikely(res == NULL)) 36738b7e3f49STrond Myklebust goto out; 367402a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 36757aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3676683b57b4STrond Myklebust if (unlikely(status != 0)) 3677683b57b4STrond Myklebust goto out; 3678c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3679c0eae66eSBenny Halevy if (unlikely(!p)) 3680eb72f484SChuck Lever goto out_eio; 3681cccddf4fSBenny Halevy n = be32_to_cpup(p); 3682683b57b4STrond Myklebust if (n <= 0) 3683683b57b4STrond Myklebust goto out_eio; 3684809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3685464ad6b1SChuck Lever u32 m; 3686809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3687683b57b4STrond Myklebust 3688809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3689809b426cSTrond Myklebust break; 3690809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3691c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3692c0eae66eSBenny Halevy if (unlikely(!p)) 3693eb72f484SChuck Lever goto out_eio; 3694cccddf4fSBenny Halevy m = be32_to_cpup(p); 36957aaa0b3bSManoj Naik 369602a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3697809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3698809b426cSTrond Myklebust struct nfs4_string *server; 3699809b426cSTrond Myklebust 3700809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3701464ad6b1SChuck Lever unsigned int i; 3702464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3703464ad6b1SChuck Lever "returned for location %u\n", 37043110ff80SHarvey Harrison __func__, 3705464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3706464ad6b1SChuck Lever m, res->nlocations); 37077aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 37082e42c3e2STrond Myklebust unsigned int len; 37097aaa0b3bSManoj Naik char *data; 37107aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3711683b57b4STrond Myklebust if (unlikely(status != 0)) 3712683b57b4STrond Myklebust goto out_eio; 37137aaa0b3bSManoj Naik } 3714809b426cSTrond Myklebust break; 37157aaa0b3bSManoj Naik } 3716809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3717809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3718809b426cSTrond Myklebust if (unlikely(status != 0)) 3719809b426cSTrond Myklebust goto out_eio; 3720809b426cSTrond Myklebust dprintk("%s ", server->data); 37217aaa0b3bSManoj Naik } 37227aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 37237aaa0b3bSManoj Naik if (unlikely(status != 0)) 37247aaa0b3bSManoj Naik goto out_eio; 3725683b57b4STrond Myklebust } 3726409924e4STrond Myklebust if (res->nlocations != 0) 372781934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3728683b57b4STrond Myklebust out: 37293110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3730683b57b4STrond Myklebust return status; 3731683b57b4STrond Myklebust out_eio: 3732683b57b4STrond Myklebust status = -EIO; 3733683b57b4STrond Myklebust goto out; 3734683b57b4STrond Myklebust } 3735683b57b4STrond Myklebust 37361da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 37371da177e4SLinus Torvalds { 37388687b63aSAl Viro __be32 *p; 37391da177e4SLinus Torvalds int status = 0; 37401da177e4SLinus Torvalds 37411da177e4SLinus Torvalds *res = 0; 37421da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 37431da177e4SLinus Torvalds return -EIO; 37441da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3745c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3746c0eae66eSBenny Halevy if (unlikely(!p)) 3747eb72f484SChuck Lever return -EIO; 3748cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 37491da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 37501da177e4SLinus Torvalds } 37513110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 37521da177e4SLinus Torvalds return status; 37531da177e4SLinus Torvalds } 37541da177e4SLinus Torvalds 37551da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 37561da177e4SLinus Torvalds { 37578687b63aSAl Viro __be32 *p; 37581da177e4SLinus Torvalds int status = 0; 37591da177e4SLinus Torvalds 37601da177e4SLinus Torvalds *maxlink = 1; 37611da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 37621da177e4SLinus Torvalds return -EIO; 37631da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3764c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3765c0eae66eSBenny Halevy if (unlikely(!p)) 3766eb72f484SChuck Lever return -EIO; 3767cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 37681da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 37691da177e4SLinus Torvalds } 37703110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 37711da177e4SLinus Torvalds return status; 37721da177e4SLinus Torvalds } 37731da177e4SLinus Torvalds 37741da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 37751da177e4SLinus Torvalds { 37768687b63aSAl Viro __be32 *p; 37771da177e4SLinus Torvalds int status = 0; 37781da177e4SLinus Torvalds 37791da177e4SLinus Torvalds *maxname = 1024; 37801da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 37811da177e4SLinus Torvalds return -EIO; 37821da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3783c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3784c0eae66eSBenny Halevy if (unlikely(!p)) 3785eb72f484SChuck Lever return -EIO; 3786cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 37871da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 37881da177e4SLinus Torvalds } 37893110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 37901da177e4SLinus Torvalds return status; 37911da177e4SLinus Torvalds } 37921da177e4SLinus Torvalds 37931da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37941da177e4SLinus Torvalds { 37958687b63aSAl Viro __be32 *p; 37961da177e4SLinus Torvalds int status = 0; 37971da177e4SLinus Torvalds 37981da177e4SLinus Torvalds *res = 1024; 37991da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 38001da177e4SLinus Torvalds return -EIO; 38011da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 38021da177e4SLinus Torvalds uint64_t maxread; 3803c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3804c0eae66eSBenny Halevy if (unlikely(!p)) 3805eb72f484SChuck Lever return -EIO; 3806cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 38071da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 38081da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 38091da177e4SLinus Torvalds *res = (uint32_t)maxread; 38101da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 38111da177e4SLinus Torvalds } 38123110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 38131da177e4SLinus Torvalds return status; 38141da177e4SLinus Torvalds } 38151da177e4SLinus Torvalds 38161da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38171da177e4SLinus Torvalds { 38188687b63aSAl Viro __be32 *p; 38191da177e4SLinus Torvalds int status = 0; 38201da177e4SLinus Torvalds 38211da177e4SLinus Torvalds *res = 1024; 38221da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 38231da177e4SLinus Torvalds return -EIO; 38241da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 38251da177e4SLinus Torvalds uint64_t maxwrite; 3826c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3827c0eae66eSBenny Halevy if (unlikely(!p)) 3828eb72f484SChuck Lever return -EIO; 3829cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 38301da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 38311da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 38321da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 38331da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 38341da177e4SLinus Torvalds } 38353110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 38361da177e4SLinus Torvalds return status; 38371da177e4SLinus Torvalds } 38381da177e4SLinus Torvalds 3839bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 38401da177e4SLinus Torvalds { 3841bca79478STrond Myklebust uint32_t tmp; 38428687b63aSAl Viro __be32 *p; 3843409924e4STrond Myklebust int ret = 0; 38441da177e4SLinus Torvalds 38451da177e4SLinus Torvalds *mode = 0; 38461da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 38471da177e4SLinus Torvalds return -EIO; 38481da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3849c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3850c0eae66eSBenny Halevy if (unlikely(!p)) 3851eb72f484SChuck Lever return -EIO; 3852cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3853bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 38541da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3855409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 38561da177e4SLinus Torvalds } 38573110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3858409924e4STrond Myklebust return ret; 38591da177e4SLinus Torvalds } 38601da177e4SLinus Torvalds 38611da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 38621da177e4SLinus Torvalds { 38638687b63aSAl Viro __be32 *p; 3864409924e4STrond Myklebust int ret = 0; 38651da177e4SLinus Torvalds 38661da177e4SLinus Torvalds *nlink = 1; 38671da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 38681da177e4SLinus Torvalds return -EIO; 38691da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3870c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3871c0eae66eSBenny Halevy if (unlikely(!p)) 3872eb72f484SChuck Lever return -EIO; 3873cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 38741da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3875409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 38761da177e4SLinus Torvalds } 38773110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3878409924e4STrond Myklebust return ret; 38791da177e4SLinus Torvalds } 38801da177e4SLinus Torvalds 3881686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr, 3882686a816aSTrond Myklebust struct nfs4_string *name, gfp_t gfp_flags) 3883686a816aSTrond Myklebust { 3884686a816aSTrond Myklebust ssize_t ret; 3885686a816aSTrond Myklebust 3886686a816aSTrond Myklebust ret = xdr_stream_decode_string_dup(xdr, &name->data, 3887686a816aSTrond Myklebust XDR_MAX_NETOBJ, gfp_flags); 3888686a816aSTrond Myklebust name->len = 0; 3889686a816aSTrond Myklebust if (ret > 0) 3890686a816aSTrond Myklebust name->len = ret; 3891686a816aSTrond Myklebust return ret; 3892686a816aSTrond Myklebust } 3893686a816aSTrond Myklebust 389480e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3895e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 38966926afd1STrond Myklebust struct nfs4_string *owner_name) 38971da177e4SLinus Torvalds { 3898686a816aSTrond Myklebust ssize_t len; 3899686a816aSTrond Myklebust char *p; 39001da177e4SLinus Torvalds 3901e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 39021da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 39031da177e4SLinus Torvalds return -EIO; 3904686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER)) 3905686a816aSTrond Myklebust return 0; 39061da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 3907686a816aSTrond Myklebust 3908686a816aSTrond Myklebust if (owner_name != NULL) { 3909e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, owner_name, GFP_NOIO); 3910686a816aSTrond Myklebust if (len <= 0) 3911686a816aSTrond Myklebust goto out; 3912686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, owner_name->data); 3913686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER_NAME; 3914686a816aSTrond Myklebust } else { 3915686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 3916686a816aSTrond Myklebust XDR_MAX_NETOBJ); 3917686a816aSTrond Myklebust if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0) 3918686a816aSTrond Myklebust goto out; 3919e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3920686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER; 3921686a816aSTrond Myklebust } 3922686a816aSTrond Myklebust out: 3923eb72f484SChuck Lever if (len == -EBADMSG) 3924c0eae66eSBenny Halevy return -EIO; 3925eb72f484SChuck Lever return 0; 39261da177e4SLinus Torvalds } 39271da177e4SLinus Torvalds 392880e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3929e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 39306926afd1STrond Myklebust struct nfs4_string *group_name) 39311da177e4SLinus Torvalds { 3932686a816aSTrond Myklebust ssize_t len; 3933686a816aSTrond Myklebust char *p; 39341da177e4SLinus Torvalds 3935e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 39361da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 39371da177e4SLinus Torvalds return -EIO; 3938686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) 3939686a816aSTrond Myklebust return 0; 39401da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 3941686a816aSTrond Myklebust 3942686a816aSTrond Myklebust if (group_name != NULL) { 3943e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, group_name, GFP_NOIO); 3944686a816aSTrond Myklebust if (len <= 0) 3945686a816aSTrond Myklebust goto out; 3946686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, group_name->data); 39476f1f6220SKinglong Mee return NFS_ATTR_FATTR_GROUP_NAME; 3948686a816aSTrond Myklebust } else { 3949686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p, 3950686a816aSTrond Myklebust XDR_MAX_NETOBJ); 3951686a816aSTrond Myklebust if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0) 3952686a816aSTrond Myklebust goto out; 3953e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 3954686a816aSTrond Myklebust return NFS_ATTR_FATTR_GROUP; 3955686a816aSTrond Myklebust } 3956686a816aSTrond Myklebust out: 3957eb72f484SChuck Lever if (len == -EBADMSG) 3958c0eae66eSBenny Halevy return -EIO; 3959eb72f484SChuck Lever return 0; 39601da177e4SLinus Torvalds } 39611da177e4SLinus Torvalds 39621da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 39631da177e4SLinus Torvalds { 39648687b63aSAl Viro uint32_t major = 0, minor = 0; 39658687b63aSAl Viro __be32 *p; 3966409924e4STrond Myklebust int ret = 0; 39671da177e4SLinus Torvalds 39681da177e4SLinus Torvalds *rdev = MKDEV(0,0); 39691da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 39701da177e4SLinus Torvalds return -EIO; 39711da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 39721da177e4SLinus Torvalds dev_t tmp; 39731da177e4SLinus Torvalds 3974c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3975c0eae66eSBenny Halevy if (unlikely(!p)) 3976eb72f484SChuck Lever return -EIO; 39776f723f77SBenny Halevy major = be32_to_cpup(p++); 3978cccddf4fSBenny Halevy minor = be32_to_cpup(p); 39791da177e4SLinus Torvalds tmp = MKDEV(major, minor); 39801da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 39811da177e4SLinus Torvalds *rdev = tmp; 39821da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3983409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 39841da177e4SLinus Torvalds } 39853110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3986409924e4STrond Myklebust return ret; 39871da177e4SLinus Torvalds } 39881da177e4SLinus Torvalds 39891da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39901da177e4SLinus Torvalds { 39918687b63aSAl Viro __be32 *p; 39921da177e4SLinus Torvalds int status = 0; 39931da177e4SLinus Torvalds 39941da177e4SLinus Torvalds *res = 0; 39951da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 39961da177e4SLinus Torvalds return -EIO; 39971da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3998c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3999c0eae66eSBenny Halevy if (unlikely(!p)) 4000eb72f484SChuck Lever return -EIO; 4001cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40021da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40031da177e4SLinus Torvalds } 40043110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 40051da177e4SLinus Torvalds return status; 40061da177e4SLinus Torvalds } 40071da177e4SLinus Torvalds 40081da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40091da177e4SLinus Torvalds { 40108687b63aSAl Viro __be32 *p; 40111da177e4SLinus Torvalds int status = 0; 40121da177e4SLinus Torvalds 40131da177e4SLinus Torvalds *res = 0; 40141da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 40151da177e4SLinus Torvalds return -EIO; 40161da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4017c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4018c0eae66eSBenny Halevy if (unlikely(!p)) 4019eb72f484SChuck Lever return -EIO; 4020cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40211da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 40221da177e4SLinus Torvalds } 40233110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 40241da177e4SLinus Torvalds return status; 40251da177e4SLinus Torvalds } 40261da177e4SLinus Torvalds 40271da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40281da177e4SLinus Torvalds { 40298687b63aSAl Viro __be32 *p; 40301da177e4SLinus Torvalds int status = 0; 40311da177e4SLinus Torvalds 40321da177e4SLinus Torvalds *res = 0; 40331da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 40341da177e4SLinus Torvalds return -EIO; 40351da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4036c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4037c0eae66eSBenny Halevy if (unlikely(!p)) 4038eb72f484SChuck Lever return -EIO; 4039cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40401da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 40411da177e4SLinus Torvalds } 40423110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 40431da177e4SLinus Torvalds return status; 40441da177e4SLinus Torvalds } 40451da177e4SLinus Torvalds 40461da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 40471da177e4SLinus Torvalds { 40488687b63aSAl Viro __be32 *p; 4049409924e4STrond Myklebust int ret = 0; 40501da177e4SLinus Torvalds 40511da177e4SLinus Torvalds *used = 0; 40521da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 40531da177e4SLinus Torvalds return -EIO; 40541da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4055c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4056c0eae66eSBenny Halevy if (unlikely(!p)) 4057eb72f484SChuck Lever return -EIO; 4058cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 40591da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4060409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 40611da177e4SLinus Torvalds } 40623110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 40631da177e4SLinus Torvalds (unsigned long long)*used); 4064409924e4STrond Myklebust return ret; 40651da177e4SLinus Torvalds } 40661da177e4SLinus Torvalds 406736b3743fSTrond Myklebust static __be32 * 4068e86d5a02STrond Myklebust xdr_decode_nfstime4(__be32 *p, struct timespec64 *t) 406936b3743fSTrond Myklebust { 407036b3743fSTrond Myklebust __u64 sec; 407136b3743fSTrond Myklebust 407236b3743fSTrond Myklebust p = xdr_decode_hyper(p, &sec); 4073e86d5a02STrond Myklebust t-> tv_sec = sec; 407436b3743fSTrond Myklebust t->tv_nsec = be32_to_cpup(p++); 407536b3743fSTrond Myklebust return p; 407636b3743fSTrond Myklebust } 407736b3743fSTrond Myklebust 4078e86d5a02STrond Myklebust static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time) 40791da177e4SLinus Torvalds { 40808687b63aSAl Viro __be32 *p; 40811da177e4SLinus Torvalds 408236b3743fSTrond Myklebust p = xdr_inline_decode(xdr, nfstime4_maxsz << 2); 4083c0eae66eSBenny Halevy if (unlikely(!p)) 4084eb72f484SChuck Lever return -EIO; 408536b3743fSTrond Myklebust xdr_decode_nfstime4(p, time); 40861da177e4SLinus Torvalds return 0; 40871da177e4SLinus Torvalds } 40881da177e4SLinus Torvalds 4089e86d5a02STrond Myklebust static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time) 40901da177e4SLinus Torvalds { 40911da177e4SLinus Torvalds int status = 0; 40921da177e4SLinus Torvalds 40931da177e4SLinus Torvalds time->tv_sec = 0; 40941da177e4SLinus Torvalds time->tv_nsec = 0; 40951da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 40961da177e4SLinus Torvalds return -EIO; 40971da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 40981da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4099409924e4STrond Myklebust if (status == 0) 4100409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 41011da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 41021da177e4SLinus Torvalds } 41033110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 41041da177e4SLinus Torvalds return status; 41051da177e4SLinus Torvalds } 41061da177e4SLinus Torvalds 4107e86d5a02STrond Myklebust static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time) 41081da177e4SLinus Torvalds { 41091da177e4SLinus Torvalds int status = 0; 41101da177e4SLinus Torvalds 41111da177e4SLinus Torvalds time->tv_sec = 0; 41121da177e4SLinus Torvalds time->tv_nsec = 0; 41131da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 41141da177e4SLinus Torvalds return -EIO; 41151da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 41161da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4117409924e4STrond Myklebust if (status == 0) 4118409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 41191da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 41201da177e4SLinus Torvalds } 41213110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 41221da177e4SLinus Torvalds return status; 41231da177e4SLinus Torvalds } 41241da177e4SLinus Torvalds 412555b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 4126e86d5a02STrond Myklebust struct timespec64 *time) 412755b6e774SRicardo Labiaga { 412855b6e774SRicardo Labiaga int status = 0; 412955b6e774SRicardo Labiaga 413055b6e774SRicardo Labiaga time->tv_sec = 0; 413155b6e774SRicardo Labiaga time->tv_nsec = 0; 413255b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 413355b6e774SRicardo Labiaga return -EIO; 413455b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 413555b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 413655b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 413755b6e774SRicardo Labiaga } 413855b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 413955b6e774SRicardo Labiaga (long)time->tv_nsec); 414055b6e774SRicardo Labiaga return status; 414155b6e774SRicardo Labiaga } 414255b6e774SRicardo Labiaga 4143aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4144aa9c2669SDavid Quigley struct nfs4_label *label) 4145aa9c2669SDavid Quigley { 4146aa9c2669SDavid Quigley uint32_t pi = 0; 4147aa9c2669SDavid Quigley uint32_t lfs = 0; 4148aa9c2669SDavid Quigley __u32 len; 4149aa9c2669SDavid Quigley __be32 *p; 4150aa9c2669SDavid Quigley int status = 0; 4151aa9c2669SDavid Quigley 4152aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4153aa9c2669SDavid Quigley return -EIO; 4154aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4155aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4156aa9c2669SDavid Quigley if (unlikely(!p)) 4157eb72f484SChuck Lever return -EIO; 4158aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4159aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4160aa9c2669SDavid Quigley if (unlikely(!p)) 4161eb72f484SChuck Lever return -EIO; 4162aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4163aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4164aa9c2669SDavid Quigley if (unlikely(!p)) 4165eb72f484SChuck Lever return -EIO; 4166aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4167aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4168aa9c2669SDavid Quigley if (unlikely(!p)) 4169eb72f484SChuck Lever return -EIO; 4170aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4171aa9c2669SDavid Quigley if (label) { 4172aa9c2669SDavid Quigley memcpy(label->label, p, len); 4173aa9c2669SDavid Quigley label->len = len; 4174aa9c2669SDavid Quigley label->pi = pi; 4175aa9c2669SDavid Quigley label->lfs = lfs; 4176aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4177aa9c2669SDavid Quigley } 4178aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4179aa9c2669SDavid Quigley } else 4180aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4181aa9c2669SDavid Quigley __func__, len); 4182aa9c2669SDavid Quigley } 4183aa9c2669SDavid Quigley if (label && label->label) 4184aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4185aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4186aa9c2669SDavid Quigley return status; 4187aa9c2669SDavid Quigley } 4188aa9c2669SDavid Quigley 4189e86d5a02STrond Myklebust static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time) 41901da177e4SLinus Torvalds { 41911da177e4SLinus Torvalds int status = 0; 41921da177e4SLinus Torvalds 41931da177e4SLinus Torvalds time->tv_sec = 0; 41941da177e4SLinus Torvalds time->tv_nsec = 0; 41951da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 41961da177e4SLinus Torvalds return -EIO; 41971da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 41981da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4199409924e4STrond Myklebust if (status == 0) 4200409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 42011da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 42021da177e4SLinus Torvalds } 42033110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 42041da177e4SLinus Torvalds return status; 42051da177e4SLinus Torvalds } 42061da177e4SLinus Torvalds 4207256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 42081da177e4SLinus Torvalds { 42091da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4210256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 42111da177e4SLinus Torvalds 42121da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4213fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4214fe82a183SChuck Lever "%u %c %u\n", 42153110ff80SHarvey Harrison __func__, 42161da177e4SLinus Torvalds attrwords << 2, 42171da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 42181da177e4SLinus Torvalds nwords << 2); 42191da177e4SLinus Torvalds return -EIO; 42201da177e4SLinus Torvalds } 42211da177e4SLinus Torvalds return 0; 42221da177e4SLinus Torvalds } 42231da177e4SLinus Torvalds 42241da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42251da177e4SLinus Torvalds { 42268687b63aSAl Viro __be32 *p; 42271da177e4SLinus Torvalds 4228c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4229c0eae66eSBenny Halevy if (unlikely(!p)) 4230eb72f484SChuck Lever return -EIO; 42316f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 42323ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4233cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 42341da177e4SLinus Torvalds return 0; 42351da177e4SLinus Torvalds } 42361da177e4SLinus Torvalds 42376168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 42381da177e4SLinus Torvalds { 42398687b63aSAl Viro __be32 *p; 42401da177e4SLinus Torvalds uint32_t supp, acc; 42411da177e4SLinus Torvalds int status; 42421da177e4SLinus Torvalds 42431da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 42441da177e4SLinus Torvalds if (status) 42451da177e4SLinus Torvalds return status; 4246c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4247c0eae66eSBenny Halevy if (unlikely(!p)) 4248eb72f484SChuck Lever return -EIO; 42496f723f77SBenny Halevy supp = be32_to_cpup(p++); 4250cccddf4fSBenny Halevy acc = be32_to_cpup(p); 42516168f62cSWeston Andros Adamson *supported = supp; 42526168f62cSWeston Andros Adamson *access = acc; 42531da177e4SLinus Torvalds return 0; 42541da177e4SLinus Torvalds } 42551da177e4SLinus Torvalds 425607d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 42571da177e4SLinus Torvalds { 4258ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); 4259eb72f484SChuck Lever if (unlikely(ret < 0)) 426007d30434SBenny Halevy return -EIO; 4261ab6e9aafSTrond Myklebust return 0; 4262ab6e9aafSTrond Myklebust } 426307d30434SBenny Halevy 426407d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 426507d30434SBenny Halevy { 42662d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 42671da177e4SLinus Torvalds } 42681da177e4SLinus Torvalds 426993b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 427093b717fdSTrond Myklebust { 427193b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 427293b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 427393b717fdSTrond Myklebust } 427493b717fdSTrond Myklebust 427593b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 427693b717fdSTrond Myklebust { 427793b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 427893b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 427993b717fdSTrond Myklebust } 428093b717fdSTrond Myklebust 428193b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 428293b717fdSTrond Myklebust { 428393b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 428493b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 428593b717fdSTrond Myklebust } 428693b717fdSTrond Myklebust 4287fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 4288fcd8843cSTrond Myklebust { 4289fcd8843cSTrond Myklebust nfs4_stateid dummy; 4290fcd8843cSTrond Myklebust 4291fcd8843cSTrond Myklebust nfs4_stateid_copy(stateid, &invalid_stateid); 4292fcd8843cSTrond Myklebust return decode_stateid(xdr, &dummy); 4293fcd8843cSTrond Myklebust } 4294fcd8843cSTrond Myklebust 42951da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 42961da177e4SLinus Torvalds { 42971da177e4SLinus Torvalds int status; 42981da177e4SLinus Torvalds 42991da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4300c1d51931STrond Myklebust if (status != -EIO) 4301c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 430207d30434SBenny Halevy if (!status) 4303fcd8843cSTrond Myklebust status = decode_invalid_stateid(xdr, &res->stateid); 43041da177e4SLinus Torvalds return status; 43051da177e4SLinus Torvalds } 43061da177e4SLinus Torvalds 4307db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4308db942bbdSBenny Halevy { 4309cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 43101da177e4SLinus Torvalds } 43111da177e4SLinus Torvalds 43122f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 43132f2c63bcSTrond Myklebust { 43142f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 43152f2c63bcSTrond Myklebust } 43162f2c63bcSTrond Myklebust 43170b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 43181da177e4SLinus Torvalds { 43191da177e4SLinus Torvalds int status; 43201da177e4SLinus Torvalds 43211da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4322db942bbdSBenny Halevy if (!status) 43232f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 43241da177e4SLinus Torvalds return status; 43251da177e4SLinus Torvalds } 43261da177e4SLinus Torvalds 43271da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43281da177e4SLinus Torvalds { 43298687b63aSAl Viro __be32 *p; 43301da177e4SLinus Torvalds uint32_t bmlen; 43311da177e4SLinus Torvalds int status; 43321da177e4SLinus Torvalds 43331da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 43341da177e4SLinus Torvalds if (status) 43351da177e4SLinus Torvalds return status; 43361da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 43371da177e4SLinus Torvalds return status; 4338c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4339c0eae66eSBenny Halevy if (unlikely(!p)) 4340eb72f484SChuck Lever return -EIO; 4341cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4342c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4343c0eae66eSBenny Halevy if (likely(p)) 43441da177e4SLinus Torvalds return 0; 4345c0eae66eSBenny Halevy return -EIO; 43461da177e4SLinus Torvalds } 43471da177e4SLinus Torvalds 43481da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 43491da177e4SLinus Torvalds { 4350256e48bbSTrond Myklebust unsigned int savep; 4351dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43521da177e4SLinus Torvalds int status; 43531da177e4SLinus Torvalds 43541da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43551da177e4SLinus Torvalds goto xdr_error; 43561da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43571da177e4SLinus Torvalds goto xdr_error; 43581da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43591da177e4SLinus Torvalds goto xdr_error; 43601da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 43611da177e4SLinus Torvalds goto xdr_error; 4362264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4363264e6351SChuck Lever &res->fh_expire_type)) != 0) 4364264e6351SChuck Lever goto xdr_error; 43651da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 43661da177e4SLinus Torvalds goto xdr_error; 43671da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 43681da177e4SLinus Torvalds goto xdr_error; 43691da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 43701da177e4SLinus Torvalds goto xdr_error; 43718c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 43728c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 43738c61282fSKinglong Mee goto xdr_error; 43741da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43751da177e4SLinus Torvalds xdr_error: 43763110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43771da177e4SLinus Torvalds return status; 43781da177e4SLinus Torvalds } 43791da177e4SLinus Torvalds 43801da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 43811da177e4SLinus Torvalds { 4382256e48bbSTrond Myklebust unsigned int savep; 4383dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43841da177e4SLinus Torvalds int status; 43851da177e4SLinus Torvalds 43861da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43871da177e4SLinus Torvalds goto xdr_error; 43881da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43891da177e4SLinus Torvalds goto xdr_error; 43901da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43911da177e4SLinus Torvalds goto xdr_error; 43921da177e4SLinus Torvalds 43931da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 43941da177e4SLinus Torvalds goto xdr_error; 43951da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 43961da177e4SLinus Torvalds goto xdr_error; 43971da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 43981da177e4SLinus Torvalds goto xdr_error; 43991ca843a2SAndreas Gruenbacher 44001ca843a2SAndreas Gruenbacher status = -EIO; 44011ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 44021ca843a2SAndreas Gruenbacher goto xdr_error; 44031ca843a2SAndreas Gruenbacher 44041da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 44051da177e4SLinus Torvalds goto xdr_error; 44061da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 44071da177e4SLinus Torvalds goto xdr_error; 44081da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 44091da177e4SLinus Torvalds goto xdr_error; 44101da177e4SLinus Torvalds 44111da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44121da177e4SLinus Torvalds xdr_error: 44133110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44141da177e4SLinus Torvalds return status; 44151da177e4SLinus Torvalds } 44161da177e4SLinus Torvalds 44171da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 44181da177e4SLinus Torvalds { 4419256e48bbSTrond Myklebust unsigned int savep; 4420dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44211da177e4SLinus Torvalds int status; 44221da177e4SLinus Torvalds 44231da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44241da177e4SLinus Torvalds goto xdr_error; 44251da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44261da177e4SLinus Torvalds goto xdr_error; 44271da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44281da177e4SLinus Torvalds goto xdr_error; 44291da177e4SLinus Torvalds 44301da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 44311da177e4SLinus Torvalds goto xdr_error; 44321da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 44331da177e4SLinus Torvalds goto xdr_error; 44341da177e4SLinus Torvalds 44351da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44361da177e4SLinus Torvalds xdr_error: 44373110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44381da177e4SLinus Torvalds return status; 44391da177e4SLinus Torvalds } 44401da177e4SLinus Torvalds 444188034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 444288034c3dSAndy Adamson uint32_t *bitmap, 444388034c3dSAndy Adamson uint64_t *res, 444488034c3dSAndy Adamson uint32_t hint_bit) 444588034c3dSAndy Adamson { 444688034c3dSAndy Adamson __be32 *p; 444788034c3dSAndy Adamson 444888034c3dSAndy Adamson *res = 0; 444988034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 445088034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 445188034c3dSAndy Adamson if (unlikely(!p)) 4452eb72f484SChuck Lever return -EIO; 445388034c3dSAndy Adamson xdr_decode_hyper(p, res); 445488034c3dSAndy Adamson } 445588034c3dSAndy Adamson return 0; 445688034c3dSAndy Adamson } 445788034c3dSAndy Adamson 445888034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 445988034c3dSAndy Adamson struct nfs4_threshold *res) 446088034c3dSAndy Adamson { 4461256e48bbSTrond Myklebust __be32 *p; 4462256e48bbSTrond Myklebust unsigned int savep; 446388034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 446488034c3dSAndy Adamson int status; 446588034c3dSAndy Adamson 446688034c3dSAndy Adamson /* layout type */ 446788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 4468eb72f484SChuck Lever if (unlikely(!p)) 446988034c3dSAndy Adamson return -EIO; 447088034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 447188034c3dSAndy Adamson 447288034c3dSAndy Adamson /* thi_hintset bitmap */ 447388034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 447488034c3dSAndy Adamson if (status < 0) 447588034c3dSAndy Adamson goto xdr_error; 447688034c3dSAndy Adamson 447788034c3dSAndy Adamson /* thi_hintlist length */ 447888034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 447988034c3dSAndy Adamson if (status < 0) 448088034c3dSAndy Adamson goto xdr_error; 448188034c3dSAndy Adamson /* thi_hintlist */ 448288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 448388034c3dSAndy Adamson if (status < 0) 448488034c3dSAndy Adamson goto xdr_error; 448588034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 448688034c3dSAndy Adamson if (status < 0) 448788034c3dSAndy Adamson goto xdr_error; 448888034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 448988034c3dSAndy Adamson THRESHOLD_RD_IO); 449088034c3dSAndy Adamson if (status < 0) 449188034c3dSAndy Adamson goto xdr_error; 449288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 449388034c3dSAndy Adamson THRESHOLD_WR_IO); 449488034c3dSAndy Adamson if (status < 0) 449588034c3dSAndy Adamson goto xdr_error; 449688034c3dSAndy Adamson 449788034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 449888034c3dSAndy Adamson res->bm = bitmap[0]; 449988034c3dSAndy Adamson 450088034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 450188034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 450288034c3dSAndy Adamson res->wr_io_sz); 450388034c3dSAndy Adamson xdr_error: 450488034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 450588034c3dSAndy Adamson return status; 450688034c3dSAndy Adamson } 450788034c3dSAndy Adamson 450888034c3dSAndy Adamson /* 450988034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 451088034c3dSAndy Adamson */ 451188034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 451288034c3dSAndy Adamson uint32_t *bitmap, 451388034c3dSAndy Adamson struct nfs4_threshold *res) 451488034c3dSAndy Adamson { 451588034c3dSAndy Adamson __be32 *p; 451688034c3dSAndy Adamson int status = 0; 451788034c3dSAndy Adamson uint32_t num; 451888034c3dSAndy Adamson 451988034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 452088034c3dSAndy Adamson return -EIO; 4521029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 45221549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 45231549210fSTrond Myklebust if (unlikely(res == NULL)) 45241549210fSTrond Myklebust return -EREMOTEIO; 452588034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 452688034c3dSAndy Adamson if (unlikely(!p)) 4527eb72f484SChuck Lever return -EIO; 452888034c3dSAndy Adamson num = be32_to_cpup(p); 452988034c3dSAndy Adamson if (num == 0) 453088034c3dSAndy Adamson return 0; 453188034c3dSAndy Adamson if (num > 1) 453288034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 453388034c3dSAndy Adamson "drivers per filesystem not supported\n", 453488034c3dSAndy Adamson __func__); 453588034c3dSAndy Adamson 453688034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4537029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 453888034c3dSAndy Adamson } 453988034c3dSAndy Adamson return status; 454088034c3dSAndy Adamson } 454188034c3dSAndy Adamson 4542ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4543ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4544aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 45456926afd1STrond Myklebust const struct nfs_server *server) 45461da177e4SLinus Torvalds { 4547bca79478STrond Myklebust int status; 4548bca79478STrond Myklebust umode_t fmode = 0; 4549ae42c70aSBryan Schumaker uint32_t type; 4550ee7b75fcSTrond Myklebust int32_t err; 45511da177e4SLinus Torvalds 4552f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4553f26c7a78STrond Myklebust if (status < 0) 45541da177e4SLinus Torvalds goto xdr_error; 4555409924e4STrond Myklebust fattr->mode = 0; 4556409924e4STrond Myklebust if (status != 0) { 4557409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4558409924e4STrond Myklebust fattr->valid |= status; 4559409924e4STrond Myklebust } 45601da177e4SLinus Torvalds 4561f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4562f26c7a78STrond Myklebust if (status < 0) 45631da177e4SLinus Torvalds goto xdr_error; 4564409924e4STrond Myklebust fattr->valid |= status; 4565f26c7a78STrond Myklebust 4566f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4567f26c7a78STrond Myklebust if (status < 0) 45681da177e4SLinus Torvalds goto xdr_error; 4569409924e4STrond Myklebust fattr->valid |= status; 4570f26c7a78STrond Myklebust 4571f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4572f26c7a78STrond Myklebust if (status < 0) 45731da177e4SLinus Torvalds goto xdr_error; 4574409924e4STrond Myklebust fattr->valid |= status; 4575f26c7a78STrond Myklebust 4576ee7b75fcSTrond Myklebust err = 0; 4577ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4578ae42c70aSBryan Schumaker if (status < 0) 4579ae42c70aSBryan Schumaker goto xdr_error; 4580ae42c70aSBryan Schumaker 4581ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4582ae42c70aSBryan Schumaker if (status < 0) 4583ae42c70aSBryan Schumaker goto xdr_error; 4584ae42c70aSBryan Schumaker 4585f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4586f26c7a78STrond Myklebust if (status < 0) 45871da177e4SLinus Torvalds goto xdr_error; 4588409924e4STrond Myklebust fattr->valid |= status; 4589f26c7a78STrond Myklebust 45908b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4591f26c7a78STrond Myklebust if (status < 0) 4592683b57b4STrond Myklebust goto xdr_error; 4593409924e4STrond Myklebust fattr->valid |= status; 4594f26c7a78STrond Myklebust 45951ca843a2SAndreas Gruenbacher status = -EIO; 45961ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 45971ca843a2SAndreas Gruenbacher goto xdr_error; 45981ca843a2SAndreas Gruenbacher 4599f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4600f26c7a78STrond Myklebust if (status < 0) 46011da177e4SLinus Torvalds goto xdr_error; 4602409924e4STrond Myklebust if (status != 0) { 46031da177e4SLinus Torvalds fattr->mode |= fmode; 4604409924e4STrond Myklebust fattr->valid |= status; 4605409924e4STrond Myklebust } 4606f26c7a78STrond Myklebust 4607f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4608f26c7a78STrond Myklebust if (status < 0) 46091da177e4SLinus Torvalds goto xdr_error; 4610409924e4STrond Myklebust fattr->valid |= status; 4611f26c7a78STrond Myklebust 46126926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4613f26c7a78STrond Myklebust if (status < 0) 46141da177e4SLinus Torvalds goto xdr_error; 4615409924e4STrond Myklebust fattr->valid |= status; 4616f26c7a78STrond Myklebust 46176926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4618f26c7a78STrond Myklebust if (status < 0) 46191da177e4SLinus Torvalds goto xdr_error; 4620409924e4STrond Myklebust fattr->valid |= status; 4621f26c7a78STrond Myklebust 4622f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4623f26c7a78STrond Myklebust if (status < 0) 46241da177e4SLinus Torvalds goto xdr_error; 4625409924e4STrond Myklebust fattr->valid |= status; 4626f26c7a78STrond Myklebust 4627f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4628f26c7a78STrond Myklebust if (status < 0) 46291da177e4SLinus Torvalds goto xdr_error; 4630409924e4STrond Myklebust fattr->valid |= status; 4631f26c7a78STrond Myklebust 4632f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4633f26c7a78STrond Myklebust if (status < 0) 46341da177e4SLinus Torvalds goto xdr_error; 4635409924e4STrond Myklebust fattr->valid |= status; 4636f26c7a78STrond Myklebust 4637f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4638f26c7a78STrond Myklebust if (status < 0) 46391da177e4SLinus Torvalds goto xdr_error; 4640409924e4STrond Myklebust fattr->valid |= status; 4641f26c7a78STrond Myklebust 4642f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4643f26c7a78STrond Myklebust if (status < 0) 46441da177e4SLinus Torvalds goto xdr_error; 4645409924e4STrond Myklebust fattr->valid |= status; 4646f26c7a78STrond Myklebust 464728331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4648f26c7a78STrond Myklebust if (status < 0) 464999baf625SManoj Naik goto xdr_error; 4650409924e4STrond Myklebust fattr->valid |= status; 4651f26c7a78STrond Myklebust 46521ca843a2SAndreas Gruenbacher status = -EIO; 46531ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 46541ca843a2SAndreas Gruenbacher goto xdr_error; 46551ca843a2SAndreas Gruenbacher 465688034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 465788034c3dSAndy Adamson if (status < 0) 465888034c3dSAndy Adamson goto xdr_error; 465988034c3dSAndy Adamson 4660aa9c2669SDavid Quigley if (label) { 4661aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4662aa9c2669SDavid Quigley if (status < 0) 4663aa9c2669SDavid Quigley goto xdr_error; 4664aa9c2669SDavid Quigley fattr->valid |= status; 4665aa9c2669SDavid Quigley } 4666aa9c2669SDavid Quigley 4667ae42c70aSBryan Schumaker xdr_error: 4668ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4669ae42c70aSBryan Schumaker return status; 4670ae42c70aSBryan Schumaker } 4671ae42c70aSBryan Schumaker 4672ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 46738b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4674aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4675ae42c70aSBryan Schumaker { 4676256e48bbSTrond Myklebust unsigned int savep; 4677ae42c70aSBryan Schumaker uint32_t attrlen, 4678dae100c2SFred Isaman bitmap[3] = {0}; 4679ae42c70aSBryan Schumaker int status; 4680ae42c70aSBryan Schumaker 4681ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4682ae42c70aSBryan Schumaker if (status < 0) 4683ae42c70aSBryan Schumaker goto xdr_error; 4684ae42c70aSBryan Schumaker 4685ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4686ae42c70aSBryan Schumaker if (status < 0) 4687ae42c70aSBryan Schumaker goto xdr_error; 4688ae42c70aSBryan Schumaker 4689ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4690ae42c70aSBryan Schumaker if (status < 0) 4691ae42c70aSBryan Schumaker goto xdr_error; 4692ae42c70aSBryan Schumaker 4693aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4694aa9c2669SDavid Quigley label, server); 4695ae42c70aSBryan Schumaker if (status < 0) 4696ae42c70aSBryan Schumaker goto xdr_error; 4697ae42c70aSBryan Schumaker 4698f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 46991da177e4SLinus Torvalds xdr_error: 47003110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 47011da177e4SLinus Torvalds return status; 47021da177e4SLinus Torvalds } 47031da177e4SLinus Torvalds 4704aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4705aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4706aa9c2669SDavid Quigley { 4707aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4708aa9c2669SDavid Quigley } 4709aa9c2669SDavid Quigley 4710ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47116926afd1STrond Myklebust const struct nfs_server *server) 4712ae42c70aSBryan Schumaker { 4713aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4714ae42c70aSBryan Schumaker } 47151da177e4SLinus Torvalds 4716504913fbSAndy Adamson /* 47173132e49eSJeff Layton * Decode potentially multiple layout types. 4718504913fbSAndy Adamson */ 47193132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4720ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4721504913fbSAndy Adamson { 4722b8a8a0ddSTrond Myklebust __be32 *p; 4723ca440c38SJeff Layton uint32_t i; 4724504913fbSAndy Adamson 4725504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4726504913fbSAndy Adamson if (unlikely(!p)) 4727eb72f484SChuck Lever return -EIO; 4728ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4729504913fbSAndy Adamson 4730504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4731ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4732504913fbSAndy Adamson return 0; 4733504913fbSAndy Adamson 4734504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4735ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4736504913fbSAndy Adamson if (unlikely(!p)) 4737eb72f484SChuck Lever return -EIO; 4738ca440c38SJeff Layton 4739ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4740ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4741ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4742ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4743ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4744ca440c38SJeff Layton } 4745ca440c38SJeff Layton 4746ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4747ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4748504913fbSAndy Adamson return 0; 4749504913fbSAndy Adamson } 4750504913fbSAndy Adamson 4751504913fbSAndy Adamson /* 4752504913fbSAndy Adamson * The type of file system exported. 4753504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4754504913fbSAndy Adamson */ 4755504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4756ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4757504913fbSAndy Adamson { 4758504913fbSAndy Adamson int status = 0; 4759504913fbSAndy Adamson 4760504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4761504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4762504913fbSAndy Adamson return -EIO; 4763504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4764ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4765504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 47663132e49eSJeff Layton } 4767504913fbSAndy Adamson return status; 4768504913fbSAndy Adamson } 4769504913fbSAndy Adamson 4770dae100c2SFred Isaman /* 4771dae100c2SFred Isaman * The prefered block size for layout directed io 4772dae100c2SFred Isaman */ 4773dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4774dae100c2SFred Isaman uint32_t *res) 4775dae100c2SFred Isaman { 4776dae100c2SFred Isaman __be32 *p; 4777dae100c2SFred Isaman 4778dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4779dae100c2SFred Isaman *res = 0; 4780dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4781dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4782eb72f484SChuck Lever if (unlikely(!p)) 4783dae100c2SFred Isaman return -EIO; 4784dae100c2SFred Isaman *res = be32_to_cpup(p); 4785dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4786dae100c2SFred Isaman } 4787dae100c2SFred Isaman return 0; 4788dae100c2SFred Isaman } 4789dae100c2SFred Isaman 47902a92ee92SPeng Tao /* 47912a92ee92SPeng Tao * The granularity of a CLONE operation. 47922a92ee92SPeng Tao */ 47932a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 47942a92ee92SPeng Tao uint32_t *res) 47952a92ee92SPeng Tao { 47962a92ee92SPeng Tao __be32 *p; 47972a92ee92SPeng Tao 47982a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 47992a92ee92SPeng Tao *res = 0; 48002a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 48012a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 4802eb72f484SChuck Lever if (unlikely(!p)) 48032a92ee92SPeng Tao return -EIO; 48042a92ee92SPeng Tao *res = be32_to_cpup(p); 48052a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 48062a92ee92SPeng Tao } 48072a92ee92SPeng Tao return 0; 48082a92ee92SPeng Tao } 48092a92ee92SPeng Tao 48101da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 48111da177e4SLinus Torvalds { 4812256e48bbSTrond Myklebust unsigned int savep; 4813dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 48141da177e4SLinus Torvalds int status; 48151da177e4SLinus Torvalds 48161da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 48171da177e4SLinus Torvalds goto xdr_error; 48181da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 48191da177e4SLinus Torvalds goto xdr_error; 48201da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 48211da177e4SLinus Torvalds goto xdr_error; 48221da177e4SLinus Torvalds 48231da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 48241da177e4SLinus Torvalds 48251da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 48261da177e4SLinus Torvalds goto xdr_error; 48271da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 48281da177e4SLinus Torvalds goto xdr_error; 48291da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 48301da177e4SLinus Torvalds goto xdr_error; 48311da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 48321da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 48331da177e4SLinus Torvalds goto xdr_error; 48341da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 48351ca843a2SAndreas Gruenbacher 48361ca843a2SAndreas Gruenbacher status = -EIO; 48371ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 48381ca843a2SAndreas Gruenbacher goto xdr_error; 48391ca843a2SAndreas Gruenbacher 484055b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 484155b6e774SRicardo Labiaga if (status != 0) 484255b6e774SRicardo Labiaga goto xdr_error; 4843ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4844504913fbSAndy Adamson if (status != 0) 4845504913fbSAndy Adamson goto xdr_error; 48461ca843a2SAndreas Gruenbacher 48471ca843a2SAndreas Gruenbacher status = -EIO; 48481ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 48491ca843a2SAndreas Gruenbacher goto xdr_error; 48501ca843a2SAndreas Gruenbacher 4851dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4852dae100c2SFred Isaman if (status) 4853dae100c2SFred Isaman goto xdr_error; 48542a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 48552a92ee92SPeng Tao if (status) 48562a92ee92SPeng Tao goto xdr_error; 48571da177e4SLinus Torvalds 48581da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 48591da177e4SLinus Torvalds xdr_error: 48603110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 48611da177e4SLinus Torvalds return status; 48621da177e4SLinus Torvalds } 48631da177e4SLinus Torvalds 48641da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 48651da177e4SLinus Torvalds { 48668687b63aSAl Viro __be32 *p; 48671da177e4SLinus Torvalds uint32_t len; 48681da177e4SLinus Torvalds int status; 48691da177e4SLinus Torvalds 48709936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 48719936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 48729936781dSTrond Myklebust 48731da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 48741da177e4SLinus Torvalds if (status) 48751da177e4SLinus Torvalds return status; 48761da177e4SLinus Torvalds 4877c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4878c0eae66eSBenny Halevy if (unlikely(!p)) 4879eb72f484SChuck Lever return -EIO; 4880cccddf4fSBenny Halevy len = be32_to_cpup(p); 48811da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 48821da177e4SLinus Torvalds return -EIO; 48831da177e4SLinus Torvalds fh->size = len; 4884c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4885c0eae66eSBenny Halevy if (unlikely(!p)) 4886eb72f484SChuck Lever return -EIO; 488799398d06SBenny Halevy memcpy(fh->data, p, len); 48881da177e4SLinus Torvalds return 0; 48891da177e4SLinus Torvalds } 48901da177e4SLinus Torvalds 48911da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 48921da177e4SLinus Torvalds { 48931da177e4SLinus Torvalds int status; 48941da177e4SLinus Torvalds 48951da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 48961da177e4SLinus Torvalds if (status) 48971da177e4SLinus Torvalds return status; 48981da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 48991da177e4SLinus Torvalds } 49001da177e4SLinus Torvalds 49011da177e4SLinus Torvalds /* 49021da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 49031da177e4SLinus Torvalds */ 4904911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 49051da177e4SLinus Torvalds { 4906911d1aafSTrond Myklebust uint64_t offset, length, clientid; 49078687b63aSAl Viro __be32 *p; 4908911d1aafSTrond Myklebust uint32_t namelen, type; 49091da177e4SLinus Torvalds 4910babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4911c0eae66eSBenny Halevy if (unlikely(!p)) 4912eb72f484SChuck Lever return -EIO; 4913babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 49143ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4915babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4916babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4917911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4918911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4919911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4920911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4921911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4922911d1aafSTrond Myklebust if (type & 1) 4923911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4924911d1aafSTrond Myklebust fl->fl_pid = 0; 4925911d1aafSTrond Myklebust } 4926babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4927babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4928babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4929eb72f484SChuck Lever if (likely(!p)) 4930c0eae66eSBenny Halevy return -EIO; 4931eb72f484SChuck Lever return -NFS4ERR_DENIED; 49321da177e4SLinus Torvalds } 49331da177e4SLinus Torvalds 4934911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 49351da177e4SLinus Torvalds { 49361da177e4SLinus Torvalds int status; 49371da177e4SLinus Torvalds 49381da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4939c1d51931STrond Myklebust if (status == -EIO) 4940c1d51931STrond Myklebust goto out; 49411da177e4SLinus Torvalds if (status == 0) { 494293b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 494307d30434SBenny Halevy if (unlikely(status)) 494407d30434SBenny Halevy goto out; 49451da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4946c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4947c1d51931STrond Myklebust if (res->open_seqid != NULL) 4948c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4949c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4950c1d51931STrond Myklebust out: 49511da177e4SLinus Torvalds return status; 49521da177e4SLinus Torvalds } 49531da177e4SLinus Torvalds 4954911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 49551da177e4SLinus Torvalds { 49561da177e4SLinus Torvalds int status; 49571da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 49581da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4959911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 49601da177e4SLinus Torvalds return status; 49611da177e4SLinus Torvalds } 49621da177e4SLinus Torvalds 4963911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 49641da177e4SLinus Torvalds { 49651da177e4SLinus Torvalds int status; 49661da177e4SLinus Torvalds 49671da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4968c1d51931STrond Myklebust if (status != -EIO) 4969c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 497007d30434SBenny Halevy if (status == 0) 497193b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 49721da177e4SLinus Torvalds return status; 49731da177e4SLinus Torvalds } 49741da177e4SLinus Torvalds 4975d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4976d3c7b7ccSTrond Myklebust { 4977d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4978d3c7b7ccSTrond Myklebust } 4979d3c7b7ccSTrond Myklebust 49801da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 49811da177e4SLinus Torvalds { 49821da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 49831da177e4SLinus Torvalds } 49841da177e4SLinus Torvalds 49855b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr) 49865b5faaf6SJeff Layton { 49875b5faaf6SJeff Layton return decode_op_hdr(xdr, OP_LOOKUPP); 49885b5faaf6SJeff Layton } 49895b5faaf6SJeff Layton 49901da177e4SLinus Torvalds /* This is too sick! */ 49917d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 49927d160a6cSTrond Myklebust unsigned long *pagemod_limit) 49931da177e4SLinus Torvalds { 49948687b63aSAl Viro __be32 *p; 49951da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 49967d160a6cSTrond Myklebust u64 maxsize = 0; 49971da177e4SLinus Torvalds 4998c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4999c0eae66eSBenny Halevy if (unlikely(!p)) 5000eb72f484SChuck Lever return -EIO; 50016f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 50021da177e4SLinus Torvalds switch (limit_type) { 50037d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 50047d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 50051da177e4SLinus Torvalds break; 50067d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 50076f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5008cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 50097d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 50101da177e4SLinus Torvalds } 501109cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 50127d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 50131da177e4SLinus Torvalds return 0; 50141da177e4SLinus Torvalds } 50151da177e4SLinus Torvalds 50166ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 50176ae37339STrond Myklebust uint32_t delegation_type, 50186ae37339STrond Myklebust struct nfs_openres *res) 50191da177e4SLinus Torvalds { 50208687b63aSAl Viro __be32 *p; 502107d30434SBenny Halevy int status; 50221da177e4SLinus Torvalds 502393b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 502407d30434SBenny Halevy if (unlikely(status)) 502507d30434SBenny Halevy return status; 5026c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5027c0eae66eSBenny Halevy if (unlikely(!p)) 5028eb72f484SChuck Lever return -EIO; 5029cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 503005d564feSAndy Adamson 50311da177e4SLinus Torvalds switch (delegation_type) { 50321da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 50331da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 50341da177e4SLinus Torvalds break; 50351da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 50361da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 50377d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 50381da177e4SLinus Torvalds return -EIO; 50391da177e4SLinus Torvalds } 50401bbe60ffSTrond Myklebust return decode_ace(xdr, NULL); 50411da177e4SLinus Torvalds } 50421da177e4SLinus Torvalds 50436ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 50446ae37339STrond Myklebust { 50456ae37339STrond Myklebust __be32 *p; 50466ae37339STrond Myklebust uint32_t why_no_delegation; 50476ae37339STrond Myklebust 50486ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 50496ae37339STrond Myklebust if (unlikely(!p)) 5050eb72f484SChuck Lever return -EIO; 50516ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 50526ae37339STrond Myklebust switch (why_no_delegation) { 50536ae37339STrond Myklebust case WND4_CONTENTION: 50546ae37339STrond Myklebust case WND4_RESOURCE: 50556ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 50566ae37339STrond Myklebust /* Ignore for now */ 50576ae37339STrond Myklebust } 50586ae37339STrond Myklebust return 0; 50596ae37339STrond Myklebust } 50606ae37339STrond Myklebust 50616ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 50626ae37339STrond Myklebust { 50636ae37339STrond Myklebust __be32 *p; 50646ae37339STrond Myklebust uint32_t delegation_type; 50656ae37339STrond Myklebust 50666ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 50676ae37339STrond Myklebust if (unlikely(!p)) 5068eb72f484SChuck Lever return -EIO; 50696ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 50706ae37339STrond Myklebust res->delegation_type = 0; 50716ae37339STrond Myklebust switch (delegation_type) { 50726ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 50736ae37339STrond Myklebust return 0; 50746ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 50756ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 50766ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 50776ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 50786ae37339STrond Myklebust return decode_no_delegation(xdr, res); 50796ae37339STrond Myklebust } 50806ae37339STrond Myklebust return -EIO; 50816ae37339STrond Myklebust } 50826ae37339STrond Myklebust 50831da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 50841da177e4SLinus Torvalds { 50858687b63aSAl Viro __be32 *p; 5086aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 50871da177e4SLinus Torvalds int status; 50881da177e4SLinus Torvalds 5089c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5090c7848f69STrond Myklebust return status; 5091c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5092c7848f69STrond Myklebust if (status) 5093c7848f69STrond Myklebust return status; 509493b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 509507d30434SBenny Halevy if (unlikely(status)) 50961da177e4SLinus Torvalds return status; 50971da177e4SLinus Torvalds 50981da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 50991da177e4SLinus Torvalds 5100c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5101c0eae66eSBenny Halevy if (unlikely(!p)) 5102eb72f484SChuck Lever return -EIO; 51036f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5104cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 51051da177e4SLinus Torvalds if (bmlen > 10) 51061da177e4SLinus Torvalds goto xdr_error; 51071da177e4SLinus Torvalds 5108c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5109c0eae66eSBenny Halevy if (unlikely(!p)) 5110eb72f484SChuck Lever return -EIO; 5111aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5112aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 51136f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5114aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5115aa53ed54SJeff Layton res->attrset[i] = 0; 5116aa53ed54SJeff Layton 51171da177e4SLinus Torvalds return decode_delegation(xdr, res); 51181da177e4SLinus Torvalds xdr_error: 51193110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 51201da177e4SLinus Torvalds return -EIO; 51211da177e4SLinus Torvalds } 51221da177e4SLinus Torvalds 51231da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 51241da177e4SLinus Torvalds { 51251da177e4SLinus Torvalds int status; 51261da177e4SLinus Torvalds 51271da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5128c1d51931STrond Myklebust if (status != -EIO) 5129c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 513007d30434SBenny Halevy if (!status) 513193b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 51321da177e4SLinus Torvalds return status; 51331da177e4SLinus Torvalds } 51341da177e4SLinus Torvalds 51351da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 51361da177e4SLinus Torvalds { 51371da177e4SLinus Torvalds int status; 51381da177e4SLinus Torvalds 51391da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5140c1d51931STrond Myklebust if (status != -EIO) 5141c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 514207d30434SBenny Halevy if (!status) 514393b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 51441da177e4SLinus Torvalds return status; 51451da177e4SLinus Torvalds } 51461da177e4SLinus Torvalds 51471da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 51481da177e4SLinus Torvalds { 51491da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 51501da177e4SLinus Torvalds } 51511da177e4SLinus Torvalds 51521da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 51531da177e4SLinus Torvalds { 51541da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 51551da177e4SLinus Torvalds } 51561da177e4SLinus Torvalds 51579137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 51589137bdf3SAnna Schumaker struct nfs_pgio_res *res) 51591da177e4SLinus Torvalds { 51608687b63aSAl Viro __be32 *p; 516164bd577eSTrond Myklebust uint32_t count, eof, recvd; 51621da177e4SLinus Torvalds int status; 51631da177e4SLinus Torvalds 51641da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 51651da177e4SLinus Torvalds if (status) 51661da177e4SLinus Torvalds return status; 5167c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5168c0eae66eSBenny Halevy if (unlikely(!p)) 5169eb72f484SChuck Lever return -EIO; 51706f723f77SBenny Halevy eof = be32_to_cpup(p++); 5171cccddf4fSBenny Halevy count = be32_to_cpup(p); 517264bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 51731da177e4SLinus Torvalds if (count > recvd) { 5174fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 51751da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 51761da177e4SLinus Torvalds count = recvd; 51771da177e4SLinus Torvalds eof = 0; 51781da177e4SLinus Torvalds } 51791da177e4SLinus Torvalds res->eof = eof; 51801da177e4SLinus Torvalds res->count = count; 51811da177e4SLinus Torvalds return 0; 51821da177e4SLinus Torvalds } 51831da177e4SLinus Torvalds 51841da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 51851da177e4SLinus Torvalds { 5186bcecff77SChuck Lever int status; 5187cd93710eSChuck Lever __be32 verf[2]; 51881da177e4SLinus Torvalds 51891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5190db942bbdSBenny Halevy if (!status) 5191db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5192db942bbdSBenny Halevy if (unlikely(status)) 51931da177e4SLinus Torvalds return status; 5194cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 519544109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5196cd93710eSChuck Lever __func__, verf[0], verf[1]); 519764bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 51981da177e4SLinus Torvalds } 51991da177e4SLinus Torvalds 52001da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 52011da177e4SLinus Torvalds { 52021da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5203bcecff77SChuck Lever u32 len, recvd; 52048687b63aSAl Viro __be32 *p; 52051da177e4SLinus Torvalds int status; 52061da177e4SLinus Torvalds 52071da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 52081da177e4SLinus Torvalds if (status) 52091da177e4SLinus Torvalds return status; 52101da177e4SLinus Torvalds 52111da177e4SLinus Torvalds /* Convert length of symlink */ 5212c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5213c0eae66eSBenny Halevy if (unlikely(!p)) 5214eb72f484SChuck Lever return -EIO; 5215cccddf4fSBenny Halevy len = be32_to_cpup(p); 52161da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5217fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 52181da177e4SLinus Torvalds return -ENAMETOOLONG; 52191da177e4SLinus Torvalds } 522064bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 52211da177e4SLinus Torvalds if (recvd < len) { 5222fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 52231da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 52241da177e4SLinus Torvalds return -EIO; 52251da177e4SLinus Torvalds } 52261da177e4SLinus Torvalds /* 52271da177e4SLinus Torvalds * The XDR encode routine has set things up so that 52281da177e4SLinus Torvalds * the link text will be copied directly into the 52291da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 52301da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 52311da177e4SLinus Torvalds * null-termination). 52321da177e4SLinus Torvalds */ 5233b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 52341da177e4SLinus Torvalds return 0; 52351da177e4SLinus Torvalds } 52361da177e4SLinus Torvalds 52371da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 52381da177e4SLinus Torvalds { 52391da177e4SLinus Torvalds int status; 52401da177e4SLinus Torvalds 52411da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 52421da177e4SLinus Torvalds if (status) 52431da177e4SLinus Torvalds goto out; 52441da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 52451da177e4SLinus Torvalds out: 52461da177e4SLinus Torvalds return status; 52471da177e4SLinus Torvalds } 52481da177e4SLinus Torvalds 52491da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 52501da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 52511da177e4SLinus Torvalds { 52521da177e4SLinus Torvalds int status; 52531da177e4SLinus Torvalds 52541da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 52551da177e4SLinus Torvalds if (status) 52561da177e4SLinus Torvalds goto out; 52571da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 52581da177e4SLinus Torvalds goto out; 52591da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 52601da177e4SLinus Torvalds out: 52611da177e4SLinus Torvalds return status; 52621da177e4SLinus Torvalds } 52631da177e4SLinus Torvalds 52641da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 52651da177e4SLinus Torvalds { 52661da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 52671da177e4SLinus Torvalds } 52681da177e4SLinus Torvalds 526956ae19f3STrond Myklebust static int 527056ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 527156ae19f3STrond Myklebust { 527256ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 527356ae19f3STrond Myklebust } 527456ae19f3STrond Myklebust 5275029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5276bf118a34SAndy Adamson struct nfs_getaclres *res) 5277029d105eSJ. Bruce Fields { 5278256e48bbSTrond Myklebust unsigned int savep; 5279029d105eSJ. Bruce Fields uint32_t attrlen, 5280dae100c2SFred Isaman bitmap[3] = {0}; 5281029d105eSJ. Bruce Fields int status; 5282cff298c7STrond Myklebust unsigned int pg_offset; 5283029d105eSJ. Bruce Fields 5284bf118a34SAndy Adamson res->acl_len = 0; 5285029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5286029d105eSJ. Bruce Fields goto out; 52875a006899SSachin Prabhu 5288519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5289519d3959STrond Myklebust 5290cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5291cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 52925a006899SSachin Prabhu 5293029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5294029d105eSJ. Bruce Fields goto out; 5295029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5296029d105eSJ. Bruce Fields goto out; 5297029d105eSJ. Bruce Fields 5298029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5299029d105eSJ. Bruce Fields return -EIO; 5300029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5301029d105eSJ. Bruce Fields 5302bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5303bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5304bf118a34SAndy Adamson * variable length bitmaps.*/ 5305cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5306519d3959STrond Myklebust res->acl_len = attrlen; 53071f1ea6c2STrond Myklebust 53081f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 53091f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 53101f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 53111f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5312519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5313cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5314029d105eSJ. Bruce Fields } 53158c233cf9SJ. Bruce Fields } else 53168c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5317029d105eSJ. Bruce Fields 5318029d105eSJ. Bruce Fields out: 5319029d105eSJ. Bruce Fields return status; 5320029d105eSJ. Bruce Fields } 5321029d105eSJ. Bruce Fields 53221da177e4SLinus Torvalds static int 53231da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 53241da177e4SLinus Torvalds { 53251da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 53261da177e4SLinus Torvalds } 53271da177e4SLinus Torvalds 53289e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 53291da177e4SLinus Torvalds { 53301da177e4SLinus Torvalds int status; 53311da177e4SLinus Torvalds 53321da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 53331da177e4SLinus Torvalds if (status) 53341da177e4SLinus Torvalds return status; 533537c88763STrond Myklebust if (decode_bitmap4(xdr, NULL, 0) >= 0) 53361da177e4SLinus Torvalds return 0; 5337c0eae66eSBenny Halevy return -EIO; 53381da177e4SLinus Torvalds } 53391da177e4SLinus Torvalds 5340bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 53411da177e4SLinus Torvalds { 53428687b63aSAl Viro __be32 *p; 53431da177e4SLinus Torvalds uint32_t opnum; 53441da177e4SLinus Torvalds int32_t nfserr; 53451da177e4SLinus Torvalds 5346c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5347c0eae66eSBenny Halevy if (unlikely(!p)) 5348eb72f484SChuck Lever return -EIO; 53496f723f77SBenny Halevy opnum = be32_to_cpup(p++); 53501da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5351fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 53521da177e4SLinus Torvalds " %d\n", opnum); 53531da177e4SLinus Torvalds return -EIO; 53541da177e4SLinus Torvalds } 5355cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 53561da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5357c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5358c0eae66eSBenny Halevy if (unlikely(!p)) 5359eb72f484SChuck Lever return -EIO; 5360bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5361bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 53621da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 53631da177e4SLinus Torvalds uint32_t len; 53641da177e4SLinus Torvalds 53651da177e4SLinus Torvalds /* skip netid string */ 5366c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5367c0eae66eSBenny Halevy if (unlikely(!p)) 5368eb72f484SChuck Lever return -EIO; 5369cccddf4fSBenny Halevy len = be32_to_cpup(p); 5370c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5371c0eae66eSBenny Halevy if (unlikely(!p)) 5372eb72f484SChuck Lever return -EIO; 53731da177e4SLinus Torvalds 53741da177e4SLinus Torvalds /* skip uaddr string */ 5375c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5376c0eae66eSBenny Halevy if (unlikely(!p)) 5377eb72f484SChuck Lever return -EIO; 5378cccddf4fSBenny Halevy len = be32_to_cpup(p); 5379c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5380c0eae66eSBenny Halevy if (unlikely(!p)) 5381eb72f484SChuck Lever return -EIO; 53821da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 53831da177e4SLinus Torvalds } else 5384856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 53851da177e4SLinus Torvalds 53861da177e4SLinus Torvalds return 0; 53871da177e4SLinus Torvalds } 53881da177e4SLinus Torvalds 53891da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 53901da177e4SLinus Torvalds { 53911da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 53921da177e4SLinus Torvalds } 53931da177e4SLinus Torvalds 53949137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 53951da177e4SLinus Torvalds { 53968687b63aSAl Viro __be32 *p; 53971da177e4SLinus Torvalds int status; 53981da177e4SLinus Torvalds 53991da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 54001da177e4SLinus Torvalds if (status) 54011da177e4SLinus Torvalds return status; 54021da177e4SLinus Torvalds 54032f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5404c0eae66eSBenny Halevy if (unlikely(!p)) 5405eb72f484SChuck Lever return -EIO; 54066f723f77SBenny Halevy res->count = be32_to_cpup(p++); 54076f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 54082f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 54091da177e4SLinus Torvalds } 54101da177e4SLinus Torvalds 54111da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 54121da177e4SLinus Torvalds { 54131da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 54141da177e4SLinus Torvalds } 54151da177e4SLinus Torvalds 5416fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5417fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 54185a5ea0d4SBryan Schumaker { 5419fb15b26fSChuck Lever u32 oid_len; 54205a5ea0d4SBryan Schumaker __be32 *p; 54215a5ea0d4SBryan Schumaker 54225a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 54235a5ea0d4SBryan Schumaker if (unlikely(!p)) 5424eb72f484SChuck Lever return -EIO; 5425fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5426fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 5427eb72f484SChuck Lever return -EINVAL; 54285a5ea0d4SBryan Schumaker 5429fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 54305a5ea0d4SBryan Schumaker if (unlikely(!p)) 5431eb72f484SChuck Lever return -EIO; 5432fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5433fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 54345a5ea0d4SBryan Schumaker 54355a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 54365a5ea0d4SBryan Schumaker if (unlikely(!p)) 5437eb72f484SChuck Lever return -EIO; 5438fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5439fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 54405a5ea0d4SBryan Schumaker 54415a5ea0d4SBryan Schumaker return 0; 54425a5ea0d4SBryan Schumaker } 54435a5ea0d4SBryan Schumaker 544431e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 54455a5ea0d4SBryan Schumaker { 5446fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5447fb15b26fSChuck Lever unsigned int i, num_flavors; 54485a5ea0d4SBryan Schumaker int status; 54495a5ea0d4SBryan Schumaker __be32 *p; 54505a5ea0d4SBryan Schumaker 54515a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 54525a5ea0d4SBryan Schumaker if (unlikely(!p)) 5453eb72f484SChuck Lever return -EIO; 54545a5ea0d4SBryan Schumaker 5455c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5456c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5457c3dfc280SBryan Schumaker 5458c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 54595a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5460c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 54615a5ea0d4SBryan Schumaker break; 54625a5ea0d4SBryan Schumaker 54635a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 54645a5ea0d4SBryan Schumaker if (unlikely(!p)) 5465eb72f484SChuck Lever return -EIO; 54665a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 54675a5ea0d4SBryan Schumaker 54685a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5469613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5470613e901eSBryan Schumaker if (status) 5471613e901eSBryan Schumaker goto out; 54725a5ea0d4SBryan Schumaker } 5473c3dfc280SBryan Schumaker res->flavors->num_flavors++; 54745a5ea0d4SBryan Schumaker } 54755a5ea0d4SBryan Schumaker 547631e4dda4SBryan Schumaker status = 0; 5477613e901eSBryan Schumaker out: 5478613e901eSBryan Schumaker return status; 54795a5ea0d4SBryan Schumaker } 54805a5ea0d4SBryan Schumaker 548131e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 548231e4dda4SBryan Schumaker { 548331e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 548431e4dda4SBryan Schumaker if (status) 548531e4dda4SBryan Schumaker return status; 548631e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 548731e4dda4SBryan Schumaker } 548831e4dda4SBryan Schumaker 548999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 549031e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 549131e4dda4SBryan Schumaker { 549231e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 549331e4dda4SBryan Schumaker if (status) 549431e4dda4SBryan Schumaker return status; 549531e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 549631e4dda4SBryan Schumaker } 549731e4dda4SBryan Schumaker 54982031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 54992031cd1aSWeston Andros Adamson { 55002031cd1aSWeston Andros Adamson __be32 *p; 55012031cd1aSWeston Andros Adamson uint32_t bitmap_words; 55022031cd1aSWeston Andros Adamson unsigned int i; 55032031cd1aSWeston Andros Adamson 55042031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 55054edabfd7SPan Bian if (!p) 55064edabfd7SPan Bian return -EIO; 55072031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 55082031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 55092031cd1aSWeston Andros Adamson return -EIO; 55102031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 55112031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 55122031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 55132031cd1aSWeston Andros Adamson 55142031cd1aSWeston Andros Adamson return 0; 55152031cd1aSWeston Andros Adamson } 55162031cd1aSWeston Andros Adamson 551799fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 551899fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 551999fe60d0SBenny Halevy { 552099fe60d0SBenny Halevy __be32 *p; 552199fe60d0SBenny Halevy uint32_t dummy; 55222460ba57SBenny Halevy char *dummy_str; 552399fe60d0SBenny Halevy int status; 55247d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 552599fe60d0SBenny Halevy 552699fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 552799fe60d0SBenny Halevy if (status) 552899fe60d0SBenny Halevy return status; 552999fe60d0SBenny Halevy 5530c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5531c0eae66eSBenny Halevy if (unlikely(!p)) 5532eb72f484SChuck Lever return -EIO; 553332b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5534c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5535c0eae66eSBenny Halevy if (unlikely(!p)) 5536eb72f484SChuck Lever return -EIO; 553732b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 553832b01310STrond Myklebust res->flags = be32_to_cpup(p++); 553999fe60d0SBenny Halevy 55402031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 55412031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 55422031cd1aSWeston Andros Adamson case SP4_NONE: 55432031cd1aSWeston Andros Adamson break; 55442031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 55452031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 55462031cd1aSWeston Andros Adamson if (status) 55472031cd1aSWeston Andros Adamson return status; 55482031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 55492031cd1aSWeston Andros Adamson if (status) 55502031cd1aSWeston Andros Adamson return status; 55512031cd1aSWeston Andros Adamson break; 55522031cd1aSWeston Andros Adamson default: 55532031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 555499fe60d0SBenny Halevy return -EIO; 55552031cd1aSWeston Andros Adamson } 555699fe60d0SBenny Halevy 5557acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5558c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5559c0eae66eSBenny Halevy if (unlikely(!p)) 5560eb72f484SChuck Lever return -EIO; 5561acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 556299fe60d0SBenny Halevy 5563acdeb69dSChuck Lever /* server_owner4.so_major_id */ 55642460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55652460ba57SBenny Halevy if (unlikely(status)) 55662460ba57SBenny Halevy return status; 5567acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5568acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 556978fe0f41SWeston Andros Adamson 5570acdeb69dSChuck Lever /* server_scope4 */ 5571acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5572acdeb69dSChuck Lever if (unlikely(status)) 5573acdeb69dSChuck Lever return status; 557478fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 557578fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 557678fe0f41SWeston Andros Adamson 55777d2ed9acSWeston Andros Adamson /* Implementation Id */ 55787d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 55797d2ed9acSWeston Andros Adamson if (unlikely(!p)) 5580eb72f484SChuck Lever return -EIO; 55817d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 55827d2ed9acSWeston Andros Adamson 55837d2ed9acSWeston Andros Adamson if (impl_id_count) { 55847d2ed9acSWeston Andros Adamson /* nii_domain */ 55852460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55862460ba57SBenny Halevy if (unlikely(status)) 55872460ba57SBenny Halevy return status; 55887d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 558999fe60d0SBenny Halevy 55907d2ed9acSWeston Andros Adamson /* nii_name */ 55917d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55927d2ed9acSWeston Andros Adamson if (unlikely(status)) 55937d2ed9acSWeston Andros Adamson return status; 55947d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 55957d2ed9acSWeston Andros Adamson 55967d2ed9acSWeston Andros Adamson /* nii_date */ 55977d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 55987d2ed9acSWeston Andros Adamson if (unlikely(!p)) 5599eb72f484SChuck Lever return -EIO; 56007d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 56017d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 56027d2ed9acSWeston Andros Adamson 56037d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 56047d2ed9acSWeston Andros Adamson } 560599fe60d0SBenny Halevy return 0; 560699fe60d0SBenny Halevy } 5607fc931582SAndy Adamson 5608fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5609fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5610fc931582SAndy Adamson { 5611fc931582SAndy Adamson __be32 *p; 5612c9c30dd5SBenny Halevy u32 nr_attrs, val; 5613fc931582SAndy Adamson 5614c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5615c0eae66eSBenny Halevy if (unlikely(!p)) 5616eb72f484SChuck Lever return -EIO; 5617c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5618c9c30dd5SBenny Halevy if (val) 5619c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 56206f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 56216f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 56226f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 56236f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 56246f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5625cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5626fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5627a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5628a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5629fc931582SAndy Adamson return -EINVAL; 5630fc931582SAndy Adamson } 5631c0eae66eSBenny Halevy if (nr_attrs == 1) { 5632c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5633c0eae66eSBenny Halevy if (unlikely(!p)) 5634eb72f484SChuck Lever return -EIO; 5635c0eae66eSBenny Halevy } 5636fc931582SAndy Adamson return 0; 5637fc931582SAndy Adamson } 5638fc931582SAndy Adamson 5639e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5640e78291e4SBenny Halevy { 5641e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5642fc931582SAndy Adamson } 5643fc931582SAndy Adamson 56447c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 56457c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 56467c44f1aeSWeston Andros Adamson { 56477c44f1aeSWeston Andros Adamson __be32 *p; 56487c44f1aeSWeston Andros Adamson int status; 56497c44f1aeSWeston Andros Adamson 56507c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 56517c44f1aeSWeston Andros Adamson if (!status) 565271a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 56537c44f1aeSWeston Andros Adamson if (unlikely(status)) 56547c44f1aeSWeston Andros Adamson return status; 56557c44f1aeSWeston Andros Adamson 56567c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 56577c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 56587c44f1aeSWeston Andros Adamson if (unlikely(!p)) 5659eb72f484SChuck Lever return -EIO; 56607c44f1aeSWeston Andros Adamson 56617c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 56627c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 56637c44f1aeSWeston Andros Adamson return -EIO; 56647c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 56657c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 56667c44f1aeSWeston Andros Adamson else 56677c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 56687c44f1aeSWeston Andros Adamson 56697c44f1aeSWeston Andros Adamson return 0; 56707c44f1aeSWeston Andros Adamson } 56717c44f1aeSWeston Andros Adamson 5672fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5673fc931582SAndy Adamson struct nfs41_create_session_res *res) 5674fc931582SAndy Adamson { 5675fc931582SAndy Adamson __be32 *p; 5676fc931582SAndy Adamson int status; 5677fc931582SAndy Adamson 5678fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5679e78291e4SBenny Halevy if (!status) 568079969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5681e78291e4SBenny Halevy if (unlikely(status)) 5682fc931582SAndy Adamson return status; 5683fc931582SAndy Adamson 5684fc931582SAndy Adamson /* seqid, flags */ 5685c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5686c0eae66eSBenny Halevy if (unlikely(!p)) 5687eb72f484SChuck Lever return -EIO; 568879969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 568979969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5690fc931582SAndy Adamson 5691fc931582SAndy Adamson /* Channel attributes */ 569279969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5693fc931582SAndy Adamson if (!status) 569479969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5695fc931582SAndy Adamson return status; 5696fc931582SAndy Adamson } 56970f3e66c6SAndy Adamson 56980f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 56990f3e66c6SAndy Adamson { 57000f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 57010f3e66c6SAndy Adamson } 570218019753SRicardo Labiaga 570366245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 570466245539STrond Myklebust { 570566245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 570666245539STrond Myklebust } 570766245539STrond Myklebust 570818019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 570918019753SRicardo Labiaga { 571018019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 571118019753SRicardo Labiaga } 571299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 571399fe60d0SBenny Halevy 57149b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 57159b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 57169b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 57179b7b9fccSAndy Adamson { 57189b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5719e3725ec0STrond Myklebust struct nfs4_session *session; 5720fc01cea9SAndy Adamson struct nfs4_sessionid id; 5721fc01cea9SAndy Adamson u32 dummy; 5722fc01cea9SAndy Adamson int status; 5723fc01cea9SAndy Adamson __be32 *p; 5724fc01cea9SAndy Adamson 5725e3725ec0STrond Myklebust if (res->sr_slot == NULL) 57269b7b9fccSAndy Adamson return 0; 57273bd2384aSChuck Lever if (!res->sr_slot->table->session) 57283bd2384aSChuck Lever return 0; 57299b7b9fccSAndy Adamson 5730fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5731e78291e4SBenny Halevy if (!status) 5732e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5733e78291e4SBenny Halevy if (unlikely(status)) 5734fc01cea9SAndy Adamson goto out_err; 57359b7b9fccSAndy Adamson 5736fc01cea9SAndy Adamson /* 5737fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5738fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5739fc01cea9SAndy Adamson */ 5740fdcb4577STrond Myklebust status = -EREMOTEIO; 5741e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5742fc01cea9SAndy Adamson 5743e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5744fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5745fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5746fc01cea9SAndy Adamson goto out_err; 5747fc01cea9SAndy Adamson } 5748e78291e4SBenny Halevy 5749c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5750c0eae66eSBenny Halevy if (unlikely(!p)) 5751c0eae66eSBenny Halevy goto out_overflow; 5752e78291e4SBenny Halevy 5753fc01cea9SAndy Adamson /* seqid */ 57546f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5755dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5756fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5757fc01cea9SAndy Adamson goto out_err; 5758fc01cea9SAndy Adamson } 5759fc01cea9SAndy Adamson /* slot id */ 57606f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5761df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5762fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5763fc01cea9SAndy Adamson goto out_err; 5764fc01cea9SAndy Adamson } 5765da0507b7STrond Myklebust /* highest slot id */ 5766da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5767464ee9f9STrond Myklebust /* target highest slot id */ 5768464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 57690629e370SAlexandros Batsakis /* result flags */ 57700629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5771fc01cea9SAndy Adamson status = 0; 5772fc01cea9SAndy Adamson out_err: 5773fc01cea9SAndy Adamson res->sr_status = status; 5774fc01cea9SAndy Adamson return status; 5775c0eae66eSBenny Halevy out_overflow: 5776c0eae66eSBenny Halevy status = -EIO; 5777c0eae66eSBenny Halevy goto out_err; 5778fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 57799b7b9fccSAndy Adamson return 0; 5780fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 57819b7b9fccSAndy Adamson } 57829b7b9fccSAndy Adamson 5783b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 578493b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 578593b717fdSTrond Myklebust { 578693b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 578793b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 578893b717fdSTrond Myklebust } 578993b717fdSTrond Myklebust 5790b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 57914e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5792b1f69b75SAndy Adamson { 57934e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5794b1f69b75SAndy Adamson __be32 *p; 5795b1f69b75SAndy Adamson uint32_t len, type; 5796b1f69b75SAndy Adamson int status; 5797b1f69b75SAndy Adamson 5798b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5799b1f69b75SAndy Adamson if (status) { 5800b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5801b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5802b1f69b75SAndy Adamson if (unlikely(!p)) 5803eb72f484SChuck Lever return -EIO; 5804b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5805b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5806b1f69b75SAndy Adamson __func__, pdev->mincount); 5807b1f69b75SAndy Adamson } 5808b1f69b75SAndy Adamson return status; 5809b1f69b75SAndy Adamson } 5810b1f69b75SAndy Adamson 5811b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5812b1f69b75SAndy Adamson if (unlikely(!p)) 5813eb72f484SChuck Lever return -EIO; 5814b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5815b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5816b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5817b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5818b1f69b75SAndy Adamson return -EINVAL; 5819b1f69b75SAndy Adamson } 5820b1f69b75SAndy Adamson /* 5821b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5822b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5823b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5824b1f69b75SAndy Adamson */ 5825b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 582613fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 5827eb72f484SChuck Lever return -EIO; 5828b1f69b75SAndy Adamson 5829b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5830b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5831b1f69b75SAndy Adamson if (unlikely(!p)) 5832eb72f484SChuck Lever return -EIO; 5833b1f69b75SAndy Adamson len = be32_to_cpup(p); 5834b1f69b75SAndy Adamson if (len) { 5835ead00597SChuck Lever uint32_t i; 5836b1f69b75SAndy Adamson 5837b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5838b1f69b75SAndy Adamson if (unlikely(!p)) 5839eb72f484SChuck Lever return -EIO; 584084c9dee3SChristoph Hellwig 58414e590803STrond Myklebust res->notification = be32_to_cpup(p++); 584284c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 584384c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 584484c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 5845b1f69b75SAndy Adamson __func__); 5846b1f69b75SAndy Adamson return -EIO; 5847b1f69b75SAndy Adamson } 5848b1f69b75SAndy Adamson } 5849b1f69b75SAndy Adamson } 5850b1f69b75SAndy Adamson return 0; 5851b1f69b75SAndy Adamson } 5852b1f69b75SAndy Adamson 5853b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5854b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5855b1f69b75SAndy Adamson { 5856b1f69b75SAndy Adamson __be32 *p; 5857b1f69b75SAndy Adamson int status; 5858b1f69b75SAndy Adamson u32 layout_count; 585964bd577eSTrond Myklebust u32 recvd; 5860b1f69b75SAndy Adamson 5861b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5862b1f69b75SAndy Adamson if (status) 5863808ba32aSFred Isaman goto out; 5864ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5865b1f69b75SAndy Adamson if (unlikely(!p)) 5866b1f69b75SAndy Adamson goto out_overflow; 5867ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 586893b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 5869ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5870ea9d23f5STrond Myklebust if (unlikely(!p)) 5871ea9d23f5STrond Myklebust goto out_overflow; 5872b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5873b1f69b75SAndy Adamson if (!layout_count) { 5874b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5875b1f69b75SAndy Adamson __func__); 5876808ba32aSFred Isaman status = -EINVAL; 5877808ba32aSFred Isaman goto out; 5878b1f69b75SAndy Adamson } 5879b1f69b75SAndy Adamson 588035124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5881b1f69b75SAndy Adamson if (unlikely(!p)) 5882b1f69b75SAndy Adamson goto out_overflow; 5883b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5884b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5885b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5886b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 588735124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5888b1f69b75SAndy Adamson 5889b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5890b1f69b75SAndy Adamson __func__, 5891b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5892b1f69b75SAndy Adamson (unsigned long)res->range.length, 5893b1f69b75SAndy Adamson res->range.iomode, 5894b1f69b75SAndy Adamson res->type, 589535124a09SWeston Andros Adamson res->layoutp->len); 5896b1f69b75SAndy Adamson 589764bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 589835124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 589935124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 590035124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 590135124a09SWeston Andros Adamson res->layoutp->len, recvd); 5902808ba32aSFred Isaman status = -EINVAL; 5903808ba32aSFred Isaman goto out; 590435124a09SWeston Andros Adamson } 590535124a09SWeston Andros Adamson 5906b1f69b75SAndy Adamson if (layout_count > 1) { 5907b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5908b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5909b1f69b75SAndy Adamson * the client may see a response that is less than the 5910b1f69b75SAndy Adamson * minimum it requested. 5911b1f69b75SAndy Adamson */ 5912b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5913b1f69b75SAndy Adamson __func__, layout_count); 5914b1f69b75SAndy Adamson } 5915b1f69b75SAndy Adamson 5916808ba32aSFred Isaman out: 5917808ba32aSFred Isaman res->status = status; 5918808ba32aSFred Isaman return status; 5919b1f69b75SAndy Adamson out_overflow: 5920808ba32aSFred Isaman status = -EIO; 5921808ba32aSFred Isaman goto out; 5922b1f69b75SAndy Adamson } 5923863a3c6cSAndy Adamson 5924cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5925cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5926cbe82603SBenny Halevy { 5927cbe82603SBenny Halevy __be32 *p; 5928cbe82603SBenny Halevy int status; 5929cbe82603SBenny Halevy 5930cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5931cbe82603SBenny Halevy if (status) 5932cbe82603SBenny Halevy return status; 5933cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5934cbe82603SBenny Halevy if (unlikely(!p)) 5935eb72f484SChuck Lever return -EIO; 5936cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5937cbe82603SBenny Halevy if (res->lrs_present) 593893b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 5939fcd8843cSTrond Myklebust else 5940fcd8843cSTrond Myklebust nfs4_stateid_copy(&res->stateid, &invalid_stateid); 5941cbe82603SBenny Halevy return status; 5942cbe82603SBenny Halevy } 5943cbe82603SBenny Halevy 5944863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5945863a3c6cSAndy Adamson struct rpc_rqst *req, 5946863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5947863a3c6cSAndy Adamson { 5948863a3c6cSAndy Adamson __be32 *p; 5949863a3c6cSAndy Adamson __u32 sizechanged; 5950863a3c6cSAndy Adamson int status; 5951863a3c6cSAndy Adamson 5952863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5953db29c089SAndy Adamson res->status = status; 5954863a3c6cSAndy Adamson if (status) 5955863a3c6cSAndy Adamson return status; 5956863a3c6cSAndy Adamson 5957863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5958863a3c6cSAndy Adamson if (unlikely(!p)) 5959eb72f484SChuck Lever return -EIO; 5960863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5961863a3c6cSAndy Adamson 5962863a3c6cSAndy Adamson if (sizechanged) { 5963863a3c6cSAndy Adamson /* throw away new size */ 5964863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5965863a3c6cSAndy Adamson if (unlikely(!p)) 5966eb72f484SChuck Lever return -EIO; 5967863a3c6cSAndy Adamson } 5968863a3c6cSAndy Adamson return 0; 5969863a3c6cSAndy Adamson } 59707d974794SBryan Schumaker 59717d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 59727d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 59737d974794SBryan Schumaker { 59747d974794SBryan Schumaker __be32 *p; 59757d974794SBryan Schumaker int status; 59767d974794SBryan Schumaker int num_res; 59777d974794SBryan Schumaker 59787d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 59797d974794SBryan Schumaker if (status) 59807d974794SBryan Schumaker return status; 59817d974794SBryan Schumaker 59827d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 59837d974794SBryan Schumaker if (unlikely(!p)) 5984eb72f484SChuck Lever return -EIO; 59857d974794SBryan Schumaker num_res = be32_to_cpup(p++); 59867d974794SBryan Schumaker if (num_res != 1) 5987eb72f484SChuck Lever return -EIO; 59887d974794SBryan Schumaker 59897d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 59907d974794SBryan Schumaker if (unlikely(!p)) 5991eb72f484SChuck Lever return -EIO; 59927d974794SBryan Schumaker res->status = be32_to_cpup(p++); 59931cab0652SBryan Schumaker 59941cab0652SBryan Schumaker return status; 59957d974794SBryan Schumaker } 59969aeda35fSBryan Schumaker 59979aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 59989aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 59999aeda35fSBryan Schumaker { 60009f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 60019aeda35fSBryan Schumaker return res->status; 60029aeda35fSBryan Schumaker } 6003cf805165STrond Myklebust #else 6004cf805165STrond Myklebust static inline 6005cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6006cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6007cf805165STrond Myklebust { 6008cf805165STrond Myklebust return 0; 6009cf805165STrond Myklebust } 601056f487f8SFred Isaman 601156f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 601256f487f8SFred Isaman struct nfs4_layoutget_res *res) 601356f487f8SFred Isaman { 601456f487f8SFred Isaman return 0; 601556f487f8SFred Isaman } 601656f487f8SFred Isaman 6017b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6018b1f69b75SAndy Adamson 60191da177e4SLinus Torvalds /* 602049c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 602149c2559eSBenny Halevy */ 602249c2559eSBenny Halevy 602349c2559eSBenny Halevy /* 60241da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 60251da177e4SLinus Torvalds */ 6026bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6027bf269551SChuck Lever struct xdr_stream *xdr, 6028fc016483SChristoph Hellwig void *data) 60291da177e4SLinus Torvalds { 6030fc016483SChristoph Hellwig struct nfs_closeres *res = data; 60311da177e4SLinus Torvalds struct compound_hdr hdr; 60321da177e4SLinus Torvalds int status; 60331da177e4SLinus Torvalds 6034bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60351da177e4SLinus Torvalds if (status) 60361da177e4SLinus Torvalds goto out; 6037bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60389b7b9fccSAndy Adamson if (status) 60399b7b9fccSAndy Adamson goto out; 6040bf269551SChuck Lever status = decode_putfh(xdr); 60411da177e4SLinus Torvalds if (status) 60421da177e4SLinus Torvalds goto out; 6043b6808145STrond Myklebust if (res->lr_res) { 6044b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6045b6808145STrond Myklebust res->lr_ret = status; 6046b6808145STrond Myklebust if (status) 6047b6808145STrond Myklebust goto out; 6048b6808145STrond Myklebust } 6049bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 60501da177e4SLinus Torvalds out: 60511da177e4SLinus Torvalds return status; 60521da177e4SLinus Torvalds } 60531da177e4SLinus Torvalds 60541da177e4SLinus Torvalds /* 60551da177e4SLinus Torvalds * Decode ACCESS response 60561da177e4SLinus Torvalds */ 6057bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6058fc016483SChristoph Hellwig void *data) 60591da177e4SLinus Torvalds { 6060fc016483SChristoph Hellwig struct nfs4_accessres *res = data; 60611da177e4SLinus Torvalds struct compound_hdr hdr; 60621da177e4SLinus Torvalds int status; 60631da177e4SLinus Torvalds 6064bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60659b7b9fccSAndy Adamson if (status) 60669b7b9fccSAndy Adamson goto out; 6067bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60689b7b9fccSAndy Adamson if (status) 60691da177e4SLinus Torvalds goto out; 6070bf269551SChuck Lever status = decode_putfh(xdr); 607176b32999STrond Myklebust if (status != 0) 607276b32999STrond Myklebust goto out; 60736168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 607476b32999STrond Myklebust if (status != 0) 607576b32999STrond Myklebust goto out; 60768bcbe7d9STrond Myklebust if (res->fattr) 60776926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60781da177e4SLinus Torvalds out: 60791da177e4SLinus Torvalds return status; 60801da177e4SLinus Torvalds } 60811da177e4SLinus Torvalds 60821da177e4SLinus Torvalds /* 60831da177e4SLinus Torvalds * Decode LOOKUP response 60841da177e4SLinus Torvalds */ 6085bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6086fc016483SChristoph Hellwig void *data) 60871da177e4SLinus Torvalds { 6088fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 60891da177e4SLinus Torvalds struct compound_hdr hdr; 60901da177e4SLinus Torvalds int status; 60911da177e4SLinus Torvalds 6092bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60939b7b9fccSAndy Adamson if (status) 60949b7b9fccSAndy Adamson goto out; 6095bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60969b7b9fccSAndy Adamson if (status) 60971da177e4SLinus Torvalds goto out; 6098bf269551SChuck Lever status = decode_putfh(xdr); 6099bf269551SChuck Lever if (status) 61001da177e4SLinus Torvalds goto out; 6101bf269551SChuck Lever status = decode_lookup(xdr); 6102bf269551SChuck Lever if (status) 61031da177e4SLinus Torvalds goto out; 6104bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6105bf269551SChuck Lever if (status) 61061da177e4SLinus Torvalds goto out; 6107aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 61081da177e4SLinus Torvalds out: 61091da177e4SLinus Torvalds return status; 61101da177e4SLinus Torvalds } 61111da177e4SLinus Torvalds 61121da177e4SLinus Torvalds /* 61135b5faaf6SJeff Layton * Decode LOOKUPP response 61145b5faaf6SJeff Layton */ 61155b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 61165b5faaf6SJeff Layton void *data) 61175b5faaf6SJeff Layton { 61185b5faaf6SJeff Layton struct nfs4_lookupp_res *res = data; 61195b5faaf6SJeff Layton struct compound_hdr hdr; 61205b5faaf6SJeff Layton int status; 61215b5faaf6SJeff Layton 61225b5faaf6SJeff Layton status = decode_compound_hdr(xdr, &hdr); 61235b5faaf6SJeff Layton if (status) 61245b5faaf6SJeff Layton goto out; 61255b5faaf6SJeff Layton status = decode_sequence(xdr, &res->seq_res, rqstp); 61265b5faaf6SJeff Layton if (status) 61275b5faaf6SJeff Layton goto out; 61285b5faaf6SJeff Layton status = decode_putfh(xdr); 61295b5faaf6SJeff Layton if (status) 61305b5faaf6SJeff Layton goto out; 61315b5faaf6SJeff Layton status = decode_lookupp(xdr); 61325b5faaf6SJeff Layton if (status) 61335b5faaf6SJeff Layton goto out; 61345b5faaf6SJeff Layton status = decode_getfh(xdr, res->fh); 61355b5faaf6SJeff Layton if (status) 61365b5faaf6SJeff Layton goto out; 61375b5faaf6SJeff Layton status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 61385b5faaf6SJeff Layton out: 61395b5faaf6SJeff Layton return status; 61405b5faaf6SJeff Layton } 61415b5faaf6SJeff Layton 61425b5faaf6SJeff Layton /* 61431da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 61441da177e4SLinus Torvalds */ 6145bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6146bf269551SChuck Lever struct xdr_stream *xdr, 6147fc016483SChristoph Hellwig void *data) 61481da177e4SLinus Torvalds { 6149fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data; 61501da177e4SLinus Torvalds struct compound_hdr hdr; 61511da177e4SLinus Torvalds int status; 61521da177e4SLinus Torvalds 6153bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61549b7b9fccSAndy Adamson if (status) 61559b7b9fccSAndy Adamson goto out; 6156bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61579b7b9fccSAndy Adamson if (status) 61581da177e4SLinus Torvalds goto out; 6159bf269551SChuck Lever status = decode_putrootfh(xdr); 6160bf269551SChuck Lever if (status) 61611da177e4SLinus Torvalds goto out; 6162bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6163bf269551SChuck Lever if (status == 0) 6164aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6165aa9c2669SDavid Quigley res->label, res->server); 61661da177e4SLinus Torvalds out: 61671da177e4SLinus Torvalds return status; 61681da177e4SLinus Torvalds } 61691da177e4SLinus Torvalds 61701da177e4SLinus Torvalds /* 61711da177e4SLinus Torvalds * Decode REMOVE response 61721da177e4SLinus Torvalds */ 6173bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6174fc016483SChristoph Hellwig void *data) 61751da177e4SLinus Torvalds { 6176fc016483SChristoph Hellwig struct nfs_removeres *res = data; 61771da177e4SLinus Torvalds struct compound_hdr hdr; 61781da177e4SLinus Torvalds int status; 61791da177e4SLinus Torvalds 6180bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61819b7b9fccSAndy Adamson if (status) 61829b7b9fccSAndy Adamson goto out; 6183bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61849b7b9fccSAndy Adamson if (status) 61851da177e4SLinus Torvalds goto out; 6186bf269551SChuck Lever status = decode_putfh(xdr); 6187bf269551SChuck Lever if (status) 618816e42959STrond Myklebust goto out; 6189bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 61901da177e4SLinus Torvalds out: 61911da177e4SLinus Torvalds return status; 61921da177e4SLinus Torvalds } 61931da177e4SLinus Torvalds 61941da177e4SLinus Torvalds /* 61951da177e4SLinus Torvalds * Decode RENAME response 61961da177e4SLinus Torvalds */ 6197bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6198fc016483SChristoph Hellwig void *data) 61991da177e4SLinus Torvalds { 6200fc016483SChristoph Hellwig struct nfs_renameres *res = data; 62011da177e4SLinus Torvalds struct compound_hdr hdr; 62021da177e4SLinus Torvalds int status; 62031da177e4SLinus Torvalds 6204bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62059b7b9fccSAndy Adamson if (status) 62069b7b9fccSAndy Adamson goto out; 6207bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62089b7b9fccSAndy Adamson if (status) 62091da177e4SLinus Torvalds goto out; 6210bf269551SChuck Lever status = decode_putfh(xdr); 6211bf269551SChuck Lever if (status) 62121da177e4SLinus Torvalds goto out; 6213bf269551SChuck Lever status = decode_savefh(xdr); 6214bf269551SChuck Lever if (status) 62151da177e4SLinus Torvalds goto out; 6216bf269551SChuck Lever status = decode_putfh(xdr); 6217bf269551SChuck Lever if (status) 62181da177e4SLinus Torvalds goto out; 6219bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 62201da177e4SLinus Torvalds out: 62211da177e4SLinus Torvalds return status; 62221da177e4SLinus Torvalds } 62231da177e4SLinus Torvalds 62241da177e4SLinus Torvalds /* 62251da177e4SLinus Torvalds * Decode LINK response 62261da177e4SLinus Torvalds */ 6227bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6228fc016483SChristoph Hellwig void *data) 62291da177e4SLinus Torvalds { 6230fc016483SChristoph Hellwig struct nfs4_link_res *res = data; 62311da177e4SLinus Torvalds struct compound_hdr hdr; 62321da177e4SLinus Torvalds int status; 62331da177e4SLinus Torvalds 6234bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62359b7b9fccSAndy Adamson if (status) 62369b7b9fccSAndy Adamson goto out; 6237bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62389b7b9fccSAndy Adamson if (status) 62391da177e4SLinus Torvalds goto out; 6240bf269551SChuck Lever status = decode_putfh(xdr); 6241bf269551SChuck Lever if (status) 62421da177e4SLinus Torvalds goto out; 6243bf269551SChuck Lever status = decode_savefh(xdr); 6244bf269551SChuck Lever if (status) 62451da177e4SLinus Torvalds goto out; 6246bf269551SChuck Lever status = decode_putfh(xdr); 6247bf269551SChuck Lever if (status) 62481da177e4SLinus Torvalds goto out; 6249bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6250bf269551SChuck Lever if (status) 625191ba2eeeSTrond Myklebust goto out; 625291ba2eeeSTrond Myklebust /* 625391ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 625491ba2eeeSTrond Myklebust * filehandle. 625591ba2eeeSTrond Myklebust */ 6256bf269551SChuck Lever status = decode_restorefh(xdr); 6257bf269551SChuck Lever if (status) 625891ba2eeeSTrond Myklebust goto out; 6259aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62601da177e4SLinus Torvalds out: 62611da177e4SLinus Torvalds return status; 62621da177e4SLinus Torvalds } 62631da177e4SLinus Torvalds 62641da177e4SLinus Torvalds /* 62651da177e4SLinus Torvalds * Decode CREATE response 62661da177e4SLinus Torvalds */ 6267bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6268fc016483SChristoph Hellwig void *data) 62691da177e4SLinus Torvalds { 6270fc016483SChristoph Hellwig struct nfs4_create_res *res = data; 62711da177e4SLinus Torvalds struct compound_hdr hdr; 62721da177e4SLinus Torvalds int status; 62731da177e4SLinus Torvalds 6274bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62759b7b9fccSAndy Adamson if (status) 62769b7b9fccSAndy Adamson goto out; 6277bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62789b7b9fccSAndy Adamson if (status) 62791da177e4SLinus Torvalds goto out; 6280bf269551SChuck Lever status = decode_putfh(xdr); 6281bf269551SChuck Lever if (status) 62821da177e4SLinus Torvalds goto out; 6283bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6284bf269551SChuck Lever if (status) 62851da177e4SLinus Torvalds goto out; 6286bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6287bf269551SChuck Lever if (status) 62881da177e4SLinus Torvalds goto out; 6289aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62901da177e4SLinus Torvalds out: 62911da177e4SLinus Torvalds return status; 62921da177e4SLinus Torvalds } 62931da177e4SLinus Torvalds 62941da177e4SLinus Torvalds /* 62951da177e4SLinus Torvalds * Decode SYMLINK response 62961da177e4SLinus Torvalds */ 6297bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6298fc016483SChristoph Hellwig void *res) 62991da177e4SLinus Torvalds { 6300bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 63011da177e4SLinus Torvalds } 63021da177e4SLinus Torvalds 63031da177e4SLinus Torvalds /* 63041da177e4SLinus Torvalds * Decode GETATTR response 63051da177e4SLinus Torvalds */ 6306bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6307fc016483SChristoph Hellwig void *data) 63081da177e4SLinus Torvalds { 6309fc016483SChristoph Hellwig struct nfs4_getattr_res *res = data; 63101da177e4SLinus Torvalds struct compound_hdr hdr; 63111da177e4SLinus Torvalds int status; 63121da177e4SLinus Torvalds 6313bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63141da177e4SLinus Torvalds if (status) 63151da177e4SLinus Torvalds goto out; 6316bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63179b7b9fccSAndy Adamson if (status) 63189b7b9fccSAndy Adamson goto out; 6319bf269551SChuck Lever status = decode_putfh(xdr); 63201da177e4SLinus Torvalds if (status) 63211da177e4SLinus Torvalds goto out; 6322aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63231da177e4SLinus Torvalds out: 63241da177e4SLinus Torvalds return status; 63251da177e4SLinus Torvalds } 63261da177e4SLinus Torvalds 632723ec6965SJ. Bruce Fields /* 632823ec6965SJ. Bruce Fields * Encode an SETACL request 632923ec6965SJ. Bruce Fields */ 63309f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 6331fcc85819SChristoph Hellwig const void *data) 633223ec6965SJ. Bruce Fields { 6333fcc85819SChristoph Hellwig const struct nfs_setaclargs *args = data; 633423ec6965SJ. Bruce Fields struct compound_hdr hdr = { 633566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 633623ec6965SJ. Bruce Fields }; 633723ec6965SJ. Bruce Fields 63389f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 63399f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 63409f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 63419f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6342d017931cSAndy Adamson encode_nops(&hdr); 634323ec6965SJ. Bruce Fields } 634405d564feSAndy Adamson 634523ec6965SJ. Bruce Fields /* 634623ec6965SJ. Bruce Fields * Decode SETACL response 634723ec6965SJ. Bruce Fields */ 634823ec6965SJ. Bruce Fields static int 6349bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6350fc016483SChristoph Hellwig void *data) 635123ec6965SJ. Bruce Fields { 6352fc016483SChristoph Hellwig struct nfs_setaclres *res = data; 635323ec6965SJ. Bruce Fields struct compound_hdr hdr; 635423ec6965SJ. Bruce Fields int status; 635523ec6965SJ. Bruce Fields 6356bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 635723ec6965SJ. Bruce Fields if (status) 635823ec6965SJ. Bruce Fields goto out; 6359bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63609b7b9fccSAndy Adamson if (status) 63619b7b9fccSAndy Adamson goto out; 6362bf269551SChuck Lever status = decode_putfh(xdr); 636323ec6965SJ. Bruce Fields if (status) 636423ec6965SJ. Bruce Fields goto out; 6365bf269551SChuck Lever status = decode_setattr(xdr); 636623ec6965SJ. Bruce Fields out: 636723ec6965SJ. Bruce Fields return status; 636823ec6965SJ. Bruce Fields } 63691da177e4SLinus Torvalds 63701da177e4SLinus Torvalds /* 6371029d105eSJ. Bruce Fields * Decode GETACL response 6372029d105eSJ. Bruce Fields */ 6373029d105eSJ. Bruce Fields static int 6374bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6375fc016483SChristoph Hellwig void *data) 6376029d105eSJ. Bruce Fields { 6377fc016483SChristoph Hellwig struct nfs_getaclres *res = data; 6378029d105eSJ. Bruce Fields struct compound_hdr hdr; 6379029d105eSJ. Bruce Fields int status; 6380029d105eSJ. Bruce Fields 6381331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6382331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6383331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6384331818f1STrond Myklebust } 6385bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6386029d105eSJ. Bruce Fields if (status) 6387029d105eSJ. Bruce Fields goto out; 6388bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63899b7b9fccSAndy Adamson if (status) 63909b7b9fccSAndy Adamson goto out; 6391bf269551SChuck Lever status = decode_putfh(xdr); 6392029d105eSJ. Bruce Fields if (status) 6393029d105eSJ. Bruce Fields goto out; 6394bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6395029d105eSJ. Bruce Fields 6396029d105eSJ. Bruce Fields out: 6397029d105eSJ. Bruce Fields return status; 6398029d105eSJ. Bruce Fields } 6399029d105eSJ. Bruce Fields 6400029d105eSJ. Bruce Fields /* 64011da177e4SLinus Torvalds * Decode CLOSE response 64021da177e4SLinus Torvalds */ 6403bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6404fc016483SChristoph Hellwig void *data) 64051da177e4SLinus Torvalds { 6406fc016483SChristoph Hellwig struct nfs_closeres *res = data; 64071da177e4SLinus Torvalds struct compound_hdr hdr; 64081da177e4SLinus Torvalds int status; 64091da177e4SLinus Torvalds 6410bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64111da177e4SLinus Torvalds if (status) 64121da177e4SLinus Torvalds goto out; 6413bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64149b7b9fccSAndy Adamson if (status) 64159b7b9fccSAndy Adamson goto out; 6416bf269551SChuck Lever status = decode_putfh(xdr); 64171da177e4SLinus Torvalds if (status) 64181da177e4SLinus Torvalds goto out; 6419cf805165STrond Myklebust if (res->lr_res) { 6420cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6421cf805165STrond Myklebust res->lr_ret = status; 6422cf805165STrond Myklebust if (status) 6423cf805165STrond Myklebust goto out; 6424cf805165STrond Myklebust } 6425d8d84983STrond Myklebust if (res->fattr != NULL) { 6426d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6427516a6af6STrond Myklebust if (status != 0) 6428516a6af6STrond Myklebust goto out; 6429d8d84983STrond Myklebust } 6430d8d84983STrond Myklebust status = decode_close(xdr, res); 64311da177e4SLinus Torvalds out: 64321da177e4SLinus Torvalds return status; 64331da177e4SLinus Torvalds } 64341da177e4SLinus Torvalds 64351da177e4SLinus Torvalds /* 64361da177e4SLinus Torvalds * Decode OPEN response 64371da177e4SLinus Torvalds */ 6438bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6439fc016483SChristoph Hellwig void *data) 64401da177e4SLinus Torvalds { 6441fc016483SChristoph Hellwig struct nfs_openres *res = data; 64421da177e4SLinus Torvalds struct compound_hdr hdr; 64431da177e4SLinus Torvalds int status; 64441da177e4SLinus Torvalds 6445bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64461da177e4SLinus Torvalds if (status) 64471da177e4SLinus Torvalds goto out; 6448bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64499b7b9fccSAndy Adamson if (status) 64509b7b9fccSAndy Adamson goto out; 6451bf269551SChuck Lever status = decode_putfh(xdr); 64521da177e4SLinus Torvalds if (status) 64531da177e4SLinus Torvalds goto out; 6454bf269551SChuck Lever status = decode_open(xdr, res); 64551da177e4SLinus Torvalds if (status) 64561da177e4SLinus Torvalds goto out; 645701913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 645801913b49SWeston Andros Adamson if (status) 64591da177e4SLinus Torvalds goto out; 6460ae2bb032SWeston Andros Adamson if (res->access_request) 64616168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6462aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 646356f487f8SFred Isaman if (res->lg_res) 646456f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res); 64651da177e4SLinus Torvalds out: 64661da177e4SLinus Torvalds return status; 64671da177e4SLinus Torvalds } 64681da177e4SLinus Torvalds 64691da177e4SLinus Torvalds /* 64701da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 64711da177e4SLinus Torvalds */ 6472bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6473bf269551SChuck Lever struct xdr_stream *xdr, 6474fc016483SChristoph Hellwig void *data) 64751da177e4SLinus Torvalds { 6476fc016483SChristoph Hellwig struct nfs_open_confirmres *res = data; 64771da177e4SLinus Torvalds struct compound_hdr hdr; 64781da177e4SLinus Torvalds int status; 64791da177e4SLinus Torvalds 6480bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64811da177e4SLinus Torvalds if (status) 64821da177e4SLinus Torvalds goto out; 6483bf269551SChuck Lever status = decode_putfh(xdr); 64841da177e4SLinus Torvalds if (status) 64851da177e4SLinus Torvalds goto out; 6486bf269551SChuck Lever status = decode_open_confirm(xdr, res); 64871da177e4SLinus Torvalds out: 64881da177e4SLinus Torvalds return status; 64891da177e4SLinus Torvalds } 64901da177e4SLinus Torvalds 64911da177e4SLinus Torvalds /* 64921da177e4SLinus Torvalds * Decode OPEN response 64931da177e4SLinus Torvalds */ 6494bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6495bf269551SChuck Lever struct xdr_stream *xdr, 6496fc016483SChristoph Hellwig void *data) 64971da177e4SLinus Torvalds { 6498fc016483SChristoph Hellwig struct nfs_openres *res = data; 64991da177e4SLinus Torvalds struct compound_hdr hdr; 65001da177e4SLinus Torvalds int status; 65011da177e4SLinus Torvalds 6502bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65031da177e4SLinus Torvalds if (status) 65041da177e4SLinus Torvalds goto out; 6505bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65069b7b9fccSAndy Adamson if (status) 65079b7b9fccSAndy Adamson goto out; 6508bf269551SChuck Lever status = decode_putfh(xdr); 65091da177e4SLinus Torvalds if (status) 65101da177e4SLinus Torvalds goto out; 6511bf269551SChuck Lever status = decode_open(xdr, res); 6512864472e9STrond Myklebust if (status) 6513864472e9STrond Myklebust goto out; 6514ae2bb032SWeston Andros Adamson if (res->access_request) 65156168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 65166926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 651756f487f8SFred Isaman if (res->lg_res) 651856f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res); 65191da177e4SLinus Torvalds out: 65201da177e4SLinus Torvalds return status; 65211da177e4SLinus Torvalds } 65221da177e4SLinus Torvalds 65231da177e4SLinus Torvalds /* 65241da177e4SLinus Torvalds * Decode SETATTR response 65251da177e4SLinus Torvalds */ 6526bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6527bf269551SChuck Lever struct xdr_stream *xdr, 6528fc016483SChristoph Hellwig void *data) 65291da177e4SLinus Torvalds { 6530fc016483SChristoph Hellwig struct nfs_setattrres *res = data; 65311da177e4SLinus Torvalds struct compound_hdr hdr; 65321da177e4SLinus Torvalds int status; 65331da177e4SLinus Torvalds 6534bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65351da177e4SLinus Torvalds if (status) 65361da177e4SLinus Torvalds goto out; 6537bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65389b7b9fccSAndy Adamson if (status) 65399b7b9fccSAndy Adamson goto out; 6540bf269551SChuck Lever status = decode_putfh(xdr); 65411da177e4SLinus Torvalds if (status) 65421da177e4SLinus Torvalds goto out; 6543bf269551SChuck Lever status = decode_setattr(xdr); 65441da177e4SLinus Torvalds if (status) 65451da177e4SLinus Torvalds goto out; 6546aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 65471da177e4SLinus Torvalds out: 65481da177e4SLinus Torvalds return status; 65491da177e4SLinus Torvalds } 65501da177e4SLinus Torvalds 65511da177e4SLinus Torvalds /* 65521da177e4SLinus Torvalds * Decode LOCK response 65531da177e4SLinus Torvalds */ 6554bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6555fc016483SChristoph Hellwig void *data) 65561da177e4SLinus Torvalds { 6557fc016483SChristoph Hellwig struct nfs_lock_res *res = data; 65581da177e4SLinus Torvalds struct compound_hdr hdr; 65591da177e4SLinus Torvalds int status; 65601da177e4SLinus Torvalds 6561bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65621da177e4SLinus Torvalds if (status) 65631da177e4SLinus Torvalds goto out; 6564bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65659b7b9fccSAndy Adamson if (status) 65669b7b9fccSAndy Adamson goto out; 6567bf269551SChuck Lever status = decode_putfh(xdr); 65681da177e4SLinus Torvalds if (status) 65691da177e4SLinus Torvalds goto out; 6570bf269551SChuck Lever status = decode_lock(xdr, res); 65711da177e4SLinus Torvalds out: 65721da177e4SLinus Torvalds return status; 65731da177e4SLinus Torvalds } 65741da177e4SLinus Torvalds 65751da177e4SLinus Torvalds /* 65761da177e4SLinus Torvalds * Decode LOCKT response 65771da177e4SLinus Torvalds */ 6578bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6579fc016483SChristoph Hellwig void *data) 65801da177e4SLinus Torvalds { 6581fc016483SChristoph Hellwig struct nfs_lockt_res *res = data; 65821da177e4SLinus Torvalds struct compound_hdr hdr; 65831da177e4SLinus Torvalds int status; 65841da177e4SLinus Torvalds 6585bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65861da177e4SLinus Torvalds if (status) 65871da177e4SLinus Torvalds goto out; 6588bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65899b7b9fccSAndy Adamson if (status) 65909b7b9fccSAndy Adamson goto out; 6591bf269551SChuck Lever status = decode_putfh(xdr); 65921da177e4SLinus Torvalds if (status) 65931da177e4SLinus Torvalds goto out; 6594bf269551SChuck Lever status = decode_lockt(xdr, res); 65951da177e4SLinus Torvalds out: 65961da177e4SLinus Torvalds return status; 65971da177e4SLinus Torvalds } 65981da177e4SLinus Torvalds 65991da177e4SLinus Torvalds /* 66001da177e4SLinus Torvalds * Decode LOCKU response 66011da177e4SLinus Torvalds */ 6602bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6603fc016483SChristoph Hellwig void *data) 66041da177e4SLinus Torvalds { 6605fc016483SChristoph Hellwig struct nfs_locku_res *res = data; 66061da177e4SLinus Torvalds struct compound_hdr hdr; 66071da177e4SLinus Torvalds int status; 66081da177e4SLinus Torvalds 6609bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66101da177e4SLinus Torvalds if (status) 66111da177e4SLinus Torvalds goto out; 6612bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66139b7b9fccSAndy Adamson if (status) 66149b7b9fccSAndy Adamson goto out; 6615bf269551SChuck Lever status = decode_putfh(xdr); 66161da177e4SLinus Torvalds if (status) 66171da177e4SLinus Torvalds goto out; 6618bf269551SChuck Lever status = decode_locku(xdr, res); 66191da177e4SLinus Torvalds out: 66201da177e4SLinus Torvalds return status; 66211da177e4SLinus Torvalds } 66221da177e4SLinus Torvalds 6623bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6624bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6625d3c7b7ccSTrond Myklebust { 6626d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6627d3c7b7ccSTrond Myklebust int status; 6628d3c7b7ccSTrond Myklebust 6629bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6630d3c7b7ccSTrond Myklebust if (!status) 6631bf269551SChuck Lever status = decode_release_lockowner(xdr); 6632d3c7b7ccSTrond Myklebust return status; 6633d3c7b7ccSTrond Myklebust } 6634d3c7b7ccSTrond Myklebust 66351da177e4SLinus Torvalds /* 66361da177e4SLinus Torvalds * Decode READLINK response 66371da177e4SLinus Torvalds */ 6638bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6639bf269551SChuck Lever struct xdr_stream *xdr, 6640fc016483SChristoph Hellwig void *data) 66411da177e4SLinus Torvalds { 6642fc016483SChristoph Hellwig struct nfs4_readlink_res *res = data; 66431da177e4SLinus Torvalds struct compound_hdr hdr; 66441da177e4SLinus Torvalds int status; 66451da177e4SLinus Torvalds 6646bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66471da177e4SLinus Torvalds if (status) 66481da177e4SLinus Torvalds goto out; 6649bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66509b7b9fccSAndy Adamson if (status) 66519b7b9fccSAndy Adamson goto out; 6652bf269551SChuck Lever status = decode_putfh(xdr); 66531da177e4SLinus Torvalds if (status) 66541da177e4SLinus Torvalds goto out; 6655bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 66561da177e4SLinus Torvalds out: 66571da177e4SLinus Torvalds return status; 66581da177e4SLinus Torvalds } 66591da177e4SLinus Torvalds 66601da177e4SLinus Torvalds /* 66611da177e4SLinus Torvalds * Decode READDIR response 66621da177e4SLinus Torvalds */ 6663bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6664fc016483SChristoph Hellwig void *data) 66651da177e4SLinus Torvalds { 6666fc016483SChristoph Hellwig struct nfs4_readdir_res *res = data; 66671da177e4SLinus Torvalds struct compound_hdr hdr; 66681da177e4SLinus Torvalds int status; 66691da177e4SLinus Torvalds 6670bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66711da177e4SLinus Torvalds if (status) 66721da177e4SLinus Torvalds goto out; 6673bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66749b7b9fccSAndy Adamson if (status) 66759b7b9fccSAndy Adamson goto out; 6676bf269551SChuck Lever status = decode_putfh(xdr); 66771da177e4SLinus Torvalds if (status) 66781da177e4SLinus Torvalds goto out; 6679bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 66801da177e4SLinus Torvalds out: 66811da177e4SLinus Torvalds return status; 66821da177e4SLinus Torvalds } 66831da177e4SLinus Torvalds 66841da177e4SLinus Torvalds /* 66851da177e4SLinus Torvalds * Decode Read response 66861da177e4SLinus Torvalds */ 6687bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6688fc016483SChristoph Hellwig void *data) 66891da177e4SLinus Torvalds { 6690fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 66911da177e4SLinus Torvalds struct compound_hdr hdr; 66921da177e4SLinus Torvalds int status; 66931da177e4SLinus Torvalds 6694bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6695aabff4ddSPeng Tao res->op_status = hdr.status; 66961da177e4SLinus Torvalds if (status) 66971da177e4SLinus Torvalds goto out; 6698bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66999b7b9fccSAndy Adamson if (status) 67009b7b9fccSAndy Adamson goto out; 6701bf269551SChuck Lever status = decode_putfh(xdr); 67021da177e4SLinus Torvalds if (status) 67031da177e4SLinus Torvalds goto out; 6704bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 67051da177e4SLinus Torvalds if (!status) 67061da177e4SLinus Torvalds status = res->count; 67071da177e4SLinus Torvalds out: 67081da177e4SLinus Torvalds return status; 67091da177e4SLinus Torvalds } 67101da177e4SLinus Torvalds 67111da177e4SLinus Torvalds /* 67121da177e4SLinus Torvalds * Decode WRITE response 67131da177e4SLinus Torvalds */ 6714bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6715fc016483SChristoph Hellwig void *data) 67161da177e4SLinus Torvalds { 6717fc016483SChristoph Hellwig struct nfs_pgio_res *res = data; 67181da177e4SLinus Torvalds struct compound_hdr hdr; 67191da177e4SLinus Torvalds int status; 67201da177e4SLinus Torvalds 6721bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6722aabff4ddSPeng Tao res->op_status = hdr.status; 67231da177e4SLinus Torvalds if (status) 67241da177e4SLinus Torvalds goto out; 6725bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67269b7b9fccSAndy Adamson if (status) 67279b7b9fccSAndy Adamson goto out; 6728bf269551SChuck Lever status = decode_putfh(xdr); 67291da177e4SLinus Torvalds if (status) 67301da177e4SLinus Torvalds goto out; 6731bf269551SChuck Lever status = decode_write(xdr, res); 67324f9838c7STrond Myklebust if (status) 67334f9838c7STrond Myklebust goto out; 67347ffd1064SFred Isaman if (res->fattr) 67356926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 67361da177e4SLinus Torvalds if (!status) 67371da177e4SLinus Torvalds status = res->count; 67381da177e4SLinus Torvalds out: 67391da177e4SLinus Torvalds return status; 67401da177e4SLinus Torvalds } 67411da177e4SLinus Torvalds 67421da177e4SLinus Torvalds /* 67431da177e4SLinus Torvalds * Decode COMMIT response 67441da177e4SLinus Torvalds */ 6745bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6746fc016483SChristoph Hellwig void *data) 67471da177e4SLinus Torvalds { 6748fc016483SChristoph Hellwig struct nfs_commitres *res = data; 67491da177e4SLinus Torvalds struct compound_hdr hdr; 67501da177e4SLinus Torvalds int status; 67511da177e4SLinus Torvalds 6752bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6753aabff4ddSPeng Tao res->op_status = hdr.status; 67541da177e4SLinus Torvalds if (status) 67551da177e4SLinus Torvalds goto out; 6756bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67579b7b9fccSAndy Adamson if (status) 67589b7b9fccSAndy Adamson goto out; 6759bf269551SChuck Lever status = decode_putfh(xdr); 67601da177e4SLinus Torvalds if (status) 67611da177e4SLinus Torvalds goto out; 6762bf269551SChuck Lever status = decode_commit(xdr, res); 67631da177e4SLinus Torvalds out: 67641da177e4SLinus Torvalds return status; 67651da177e4SLinus Torvalds } 67661da177e4SLinus Torvalds 67671da177e4SLinus Torvalds /* 67688b173218SRicardo Labiaga * Decode FSINFO response 67691da177e4SLinus Torvalds */ 6770bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 6771fc016483SChristoph Hellwig void *data) 67721da177e4SLinus Torvalds { 6773fc016483SChristoph Hellwig struct nfs4_fsinfo_res *res = data; 67741da177e4SLinus Torvalds struct compound_hdr hdr; 67751da177e4SLinus Torvalds int status; 67761da177e4SLinus Torvalds 6777bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67781da177e4SLinus Torvalds if (!status) 6779bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 67809b7b9fccSAndy Adamson if (!status) 6781bf269551SChuck Lever status = decode_putfh(xdr); 67821da177e4SLinus Torvalds if (!status) 6783bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 67841da177e4SLinus Torvalds return status; 67851da177e4SLinus Torvalds } 67861da177e4SLinus Torvalds 67871da177e4SLinus Torvalds /* 67888b173218SRicardo Labiaga * Decode PATHCONF response 67891da177e4SLinus Torvalds */ 6790bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6791fc016483SChristoph Hellwig void *data) 67921da177e4SLinus Torvalds { 6793fc016483SChristoph Hellwig struct nfs4_pathconf_res *res = data; 67941da177e4SLinus Torvalds struct compound_hdr hdr; 67951da177e4SLinus Torvalds int status; 67961da177e4SLinus Torvalds 6797bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67981da177e4SLinus Torvalds if (!status) 6799bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68009b7b9fccSAndy Adamson if (!status) 6801bf269551SChuck Lever status = decode_putfh(xdr); 68021da177e4SLinus Torvalds if (!status) 6803bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 68041da177e4SLinus Torvalds return status; 68051da177e4SLinus Torvalds } 68061da177e4SLinus Torvalds 68071da177e4SLinus Torvalds /* 68088b173218SRicardo Labiaga * Decode STATFS response 68091da177e4SLinus Torvalds */ 6810bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 6811fc016483SChristoph Hellwig void *data) 68121da177e4SLinus Torvalds { 6813fc016483SChristoph Hellwig struct nfs4_statfs_res *res = data; 68141da177e4SLinus Torvalds struct compound_hdr hdr; 68151da177e4SLinus Torvalds int status; 68161da177e4SLinus Torvalds 6817bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68181da177e4SLinus Torvalds if (!status) 6819bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68209b7b9fccSAndy Adamson if (!status) 6821bf269551SChuck Lever status = decode_putfh(xdr); 68221da177e4SLinus Torvalds if (!status) 6823bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 68241da177e4SLinus Torvalds return status; 68251da177e4SLinus Torvalds } 68261da177e4SLinus Torvalds 68271da177e4SLinus Torvalds /* 68288b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 68291da177e4SLinus Torvalds */ 6830bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6831bf269551SChuck Lever struct xdr_stream *xdr, 6832fc016483SChristoph Hellwig void *data) 68331da177e4SLinus Torvalds { 6834fc016483SChristoph Hellwig struct nfs4_server_caps_res *res = data; 68351da177e4SLinus Torvalds struct compound_hdr hdr; 68361da177e4SLinus Torvalds int status; 68371da177e4SLinus Torvalds 6838bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68399b7b9fccSAndy Adamson if (status) 68409b7b9fccSAndy Adamson goto out; 6841bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68429b7b9fccSAndy Adamson if (status) 68431da177e4SLinus Torvalds goto out; 6844bf269551SChuck Lever status = decode_putfh(xdr); 6845bf269551SChuck Lever if (status) 68461da177e4SLinus Torvalds goto out; 6847bf269551SChuck Lever status = decode_server_caps(xdr, res); 68481da177e4SLinus Torvalds out: 68491da177e4SLinus Torvalds return status; 68501da177e4SLinus Torvalds } 68511da177e4SLinus Torvalds 68521da177e4SLinus Torvalds /* 68531da177e4SLinus Torvalds * Decode RENEW response 68541da177e4SLinus Torvalds */ 6855bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6856bf269551SChuck Lever void *__unused) 68571da177e4SLinus Torvalds { 68581da177e4SLinus Torvalds struct compound_hdr hdr; 68591da177e4SLinus Torvalds int status; 68601da177e4SLinus Torvalds 6861bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68621da177e4SLinus Torvalds if (!status) 6863bf269551SChuck Lever status = decode_renew(xdr); 68641da177e4SLinus Torvalds return status; 68651da177e4SLinus Torvalds } 68661da177e4SLinus Torvalds 68671da177e4SLinus Torvalds /* 68688b173218SRicardo Labiaga * Decode SETCLIENTID response 68691da177e4SLinus Torvalds */ 6870bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6871bf269551SChuck Lever struct xdr_stream *xdr, 6872fc016483SChristoph Hellwig void *data) 68731da177e4SLinus Torvalds { 6874fc016483SChristoph Hellwig struct nfs4_setclientid_res *res = data; 68751da177e4SLinus Torvalds struct compound_hdr hdr; 68761da177e4SLinus Torvalds int status; 68771da177e4SLinus Torvalds 6878bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68791da177e4SLinus Torvalds if (!status) 6880bf269551SChuck Lever status = decode_setclientid(xdr, res); 68811da177e4SLinus Torvalds return status; 68821da177e4SLinus Torvalds } 68831da177e4SLinus Torvalds 68841da177e4SLinus Torvalds /* 68858b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 68861da177e4SLinus Torvalds */ 6887bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 6888fc016483SChristoph Hellwig struct xdr_stream *xdr, 6889fc016483SChristoph Hellwig void *data) 68901da177e4SLinus Torvalds { 68911da177e4SLinus Torvalds struct compound_hdr hdr; 68921da177e4SLinus Torvalds int status; 68931da177e4SLinus Torvalds 6894bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68951da177e4SLinus Torvalds if (!status) 6896bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 68971da177e4SLinus Torvalds return status; 68981da177e4SLinus Torvalds } 68991da177e4SLinus Torvalds 69001da177e4SLinus Torvalds /* 69018b173218SRicardo Labiaga * Decode DELEGRETURN response 69021da177e4SLinus Torvalds */ 6903bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6904bf269551SChuck Lever struct xdr_stream *xdr, 6905fc016483SChristoph Hellwig void *data) 69061da177e4SLinus Torvalds { 6907fc016483SChristoph Hellwig struct nfs4_delegreturnres *res = data; 69081da177e4SLinus Torvalds struct compound_hdr hdr; 69091da177e4SLinus Torvalds int status; 69101da177e4SLinus Torvalds 6911bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69129b7b9fccSAndy Adamson if (status) 69139b7b9fccSAndy Adamson goto out; 6914bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69159b7b9fccSAndy Adamson if (status) 6916fa178f29STrond Myklebust goto out; 6917bf269551SChuck Lever status = decode_putfh(xdr); 6918fa178f29STrond Myklebust if (status != 0) 6919fa178f29STrond Myklebust goto out; 6920586f1c39STrond Myklebust if (res->lr_res) { 6921586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6922586f1c39STrond Myklebust res->lr_ret = status; 6923586f1c39STrond Myklebust if (status) 6924586f1c39STrond Myklebust goto out; 6925586f1c39STrond Myklebust } 69268ac2b422STrond Myklebust if (res->fattr) { 6927e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6928556ae3bbSJeff Layton if (status != 0) 6929556ae3bbSJeff Layton goto out; 69308ac2b422STrond Myklebust } 6931e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6932fa178f29STrond Myklebust out: 69331da177e4SLinus Torvalds return status; 69341da177e4SLinus Torvalds } 69351da177e4SLinus Torvalds 6936683b57b4STrond Myklebust /* 69378b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6938683b57b4STrond Myklebust */ 6939bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6940bf269551SChuck Lever struct xdr_stream *xdr, 6941fc016483SChristoph Hellwig void *data) 6942683b57b4STrond Myklebust { 6943fc016483SChristoph Hellwig struct nfs4_fs_locations_res *res = data; 6944683b57b4STrond Myklebust struct compound_hdr hdr; 6945683b57b4STrond Myklebust int status; 6946683b57b4STrond Myklebust 6947bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69489b7b9fccSAndy Adamson if (status) 69499b7b9fccSAndy Adamson goto out; 6950bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69519b7b9fccSAndy Adamson if (status) 6952683b57b4STrond Myklebust goto out; 6953bf269551SChuck Lever status = decode_putfh(xdr); 6954bf269551SChuck Lever if (status) 6955683b57b4STrond Myklebust goto out; 6956b03d735bSChuck Lever if (res->migration) { 6957b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6958b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6959b03d735bSChuck Lever &res->fs_locations->fattr, 6960b03d735bSChuck Lever NULL, res->fs_locations, 6961b03d735bSChuck Lever NULL, res->fs_locations->server); 6962b03d735bSChuck Lever if (status) 6963b03d735bSChuck Lever goto out; 6964b03d735bSChuck Lever if (res->renew) 6965b03d735bSChuck Lever status = decode_renew(xdr); 6966b03d735bSChuck Lever } else { 6967bf269551SChuck Lever status = decode_lookup(xdr); 6968bf269551SChuck Lever if (status) 6969683b57b4STrond Myklebust goto out; 6970bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6971b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6972b03d735bSChuck Lever &res->fs_locations->fattr, 69738b7e3f49STrond Myklebust NULL, res->fs_locations, 6974aa9c2669SDavid Quigley NULL, res->fs_locations->server); 6975b03d735bSChuck Lever } 6976683b57b4STrond Myklebust out: 6977683b57b4STrond Myklebust return status; 6978683b57b4STrond Myklebust } 6979683b57b4STrond Myklebust 69805a5ea0d4SBryan Schumaker /* 69815a5ea0d4SBryan Schumaker * Decode SECINFO response 69825a5ea0d4SBryan Schumaker */ 69835a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 69845a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 6985fc016483SChristoph Hellwig void *data) 69865a5ea0d4SBryan Schumaker { 6987fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 69885a5ea0d4SBryan Schumaker struct compound_hdr hdr; 69895a5ea0d4SBryan Schumaker int status; 69905a5ea0d4SBryan Schumaker 69915a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 69925a5ea0d4SBryan Schumaker if (status) 69935a5ea0d4SBryan Schumaker goto out; 69945a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 69955a5ea0d4SBryan Schumaker if (status) 69965a5ea0d4SBryan Schumaker goto out; 69975a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 69985a5ea0d4SBryan Schumaker if (status) 69995a5ea0d4SBryan Schumaker goto out; 70005a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 70015a5ea0d4SBryan Schumaker out: 70025a5ea0d4SBryan Schumaker return status; 70035a5ea0d4SBryan Schumaker } 70045a5ea0d4SBryan Schumaker 700544c99933SChuck Lever /* 700644c99933SChuck Lever * Decode FSID_PRESENT response 700744c99933SChuck Lever */ 700844c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 700944c99933SChuck Lever struct xdr_stream *xdr, 7010fc016483SChristoph Hellwig void *data) 701144c99933SChuck Lever { 7012fc016483SChristoph Hellwig struct nfs4_fsid_present_res *res = data; 701344c99933SChuck Lever struct compound_hdr hdr; 701444c99933SChuck Lever int status; 701544c99933SChuck Lever 701644c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 701744c99933SChuck Lever if (status) 701844c99933SChuck Lever goto out; 701944c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 702044c99933SChuck Lever if (status) 702144c99933SChuck Lever goto out; 702244c99933SChuck Lever status = decode_putfh(xdr); 702344c99933SChuck Lever if (status) 702444c99933SChuck Lever goto out; 702544c99933SChuck Lever status = decode_getfh(xdr, res->fh); 702644c99933SChuck Lever if (status) 702744c99933SChuck Lever goto out; 702844c99933SChuck Lever if (res->renew) 702944c99933SChuck Lever status = decode_renew(xdr); 703044c99933SChuck Lever out: 703144c99933SChuck Lever return status; 703244c99933SChuck Lever } 703344c99933SChuck Lever 703499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 703599fe60d0SBenny Halevy /* 70367c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 70377c44f1aeSWeston Andros Adamson */ 70387c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 70397c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 70407c44f1aeSWeston Andros Adamson void *res) 70417c44f1aeSWeston Andros Adamson { 70427c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 70437c44f1aeSWeston Andros Adamson int status; 70447c44f1aeSWeston Andros Adamson 70457c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 70467c44f1aeSWeston Andros Adamson if (!status) 70477c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 70487c44f1aeSWeston Andros Adamson return status; 70497c44f1aeSWeston Andros Adamson } 70507c44f1aeSWeston Andros Adamson 70517c44f1aeSWeston Andros Adamson /* 70528b173218SRicardo Labiaga * Decode EXCHANGE_ID response 705399fe60d0SBenny Halevy */ 7054bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7055bf269551SChuck Lever struct xdr_stream *xdr, 705699fe60d0SBenny Halevy void *res) 705799fe60d0SBenny Halevy { 705899fe60d0SBenny Halevy struct compound_hdr hdr; 705999fe60d0SBenny Halevy int status; 706099fe60d0SBenny Halevy 7061bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 706299fe60d0SBenny Halevy if (!status) 7063bf269551SChuck Lever status = decode_exchange_id(xdr, res); 706499fe60d0SBenny Halevy return status; 706599fe60d0SBenny Halevy } 70662050f0ccSAndy Adamson 70672050f0ccSAndy Adamson /* 70688b173218SRicardo Labiaga * Decode CREATE_SESSION response 7069fc931582SAndy Adamson */ 7070bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7071bf269551SChuck Lever struct xdr_stream *xdr, 7072fc016483SChristoph Hellwig void *res) 7073fc931582SAndy Adamson { 7074fc931582SAndy Adamson struct compound_hdr hdr; 7075fc931582SAndy Adamson int status; 7076fc931582SAndy Adamson 7077bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7078fc931582SAndy Adamson if (!status) 7079bf269551SChuck Lever status = decode_create_session(xdr, res); 7080fc931582SAndy Adamson return status; 7081fc931582SAndy Adamson } 7082fc931582SAndy Adamson 7083fc931582SAndy Adamson /* 70848b173218SRicardo Labiaga * Decode DESTROY_SESSION response 70850f3e66c6SAndy Adamson */ 7086bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7087bf269551SChuck Lever struct xdr_stream *xdr, 7088bf269551SChuck Lever void *res) 70890f3e66c6SAndy Adamson { 70900f3e66c6SAndy Adamson struct compound_hdr hdr; 70910f3e66c6SAndy Adamson int status; 70920f3e66c6SAndy Adamson 7093bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 70940f3e66c6SAndy Adamson if (!status) 7095bf269551SChuck Lever status = decode_destroy_session(xdr, res); 70960f3e66c6SAndy Adamson return status; 70970f3e66c6SAndy Adamson } 70980f3e66c6SAndy Adamson 70990f3e66c6SAndy Adamson /* 710066245539STrond Myklebust * Decode DESTROY_CLIENTID response 710166245539STrond Myklebust */ 710266245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 710366245539STrond Myklebust struct xdr_stream *xdr, 710466245539STrond Myklebust void *res) 710566245539STrond Myklebust { 710666245539STrond Myklebust struct compound_hdr hdr; 710766245539STrond Myklebust int status; 710866245539STrond Myklebust 710966245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 711066245539STrond Myklebust if (!status) 711166245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 711266245539STrond Myklebust return status; 711366245539STrond Myklebust } 711466245539STrond Myklebust 711566245539STrond Myklebust /* 71168b173218SRicardo Labiaga * Decode SEQUENCE response 7117fc01cea9SAndy Adamson */ 7118bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7119bf269551SChuck Lever struct xdr_stream *xdr, 7120fc016483SChristoph Hellwig void *res) 7121fc01cea9SAndy Adamson { 7122fc01cea9SAndy Adamson struct compound_hdr hdr; 7123fc01cea9SAndy Adamson int status; 7124fc01cea9SAndy Adamson 7125bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7126fc01cea9SAndy Adamson if (!status) 7127bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7128fc01cea9SAndy Adamson return status; 7129fc01cea9SAndy Adamson } 7130fc01cea9SAndy Adamson 71310efb01b2SDonald Buczek #endif 71320efb01b2SDonald Buczek 7133fc01cea9SAndy Adamson /* 71348b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 71352050f0ccSAndy Adamson */ 7136bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7137bf269551SChuck Lever struct xdr_stream *xdr, 7138fc016483SChristoph Hellwig void *data) 71392050f0ccSAndy Adamson { 7140fc016483SChristoph Hellwig struct nfs4_get_lease_time_res *res = data; 71412050f0ccSAndy Adamson struct compound_hdr hdr; 71422050f0ccSAndy Adamson int status; 71432050f0ccSAndy Adamson 7144bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71452050f0ccSAndy Adamson if (!status) 7146bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 71472050f0ccSAndy Adamson if (!status) 7148bf269551SChuck Lever status = decode_putrootfh(xdr); 71492050f0ccSAndy Adamson if (!status) 7150bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 71512050f0ccSAndy Adamson return status; 71522050f0ccSAndy Adamson } 715318019753SRicardo Labiaga 71540efb01b2SDonald Buczek #ifdef CONFIG_NFS_V4_1 71550efb01b2SDonald Buczek 715618019753SRicardo Labiaga /* 715718019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 715818019753SRicardo Labiaga */ 7159bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7160bf269551SChuck Lever struct xdr_stream *xdr, 7161fc016483SChristoph Hellwig void *data) 716218019753SRicardo Labiaga { 7163fc016483SChristoph Hellwig struct nfs41_reclaim_complete_res *res = data; 716418019753SRicardo Labiaga struct compound_hdr hdr; 716518019753SRicardo Labiaga int status; 716618019753SRicardo Labiaga 7167bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 716818019753SRicardo Labiaga if (!status) 7169bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 717018019753SRicardo Labiaga if (!status) 71718ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 717218019753SRicardo Labiaga return status; 717318019753SRicardo Labiaga } 7174b1f69b75SAndy Adamson 7175b1f69b75SAndy Adamson /* 7176b1f69b75SAndy Adamson * Decode GETDEVINFO response 7177b1f69b75SAndy Adamson */ 7178bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7179bf269551SChuck Lever struct xdr_stream *xdr, 7180fc016483SChristoph Hellwig void *data) 7181b1f69b75SAndy Adamson { 7182fc016483SChristoph Hellwig struct nfs4_getdeviceinfo_res *res = data; 7183b1f69b75SAndy Adamson struct compound_hdr hdr; 7184b1f69b75SAndy Adamson int status; 7185b1f69b75SAndy Adamson 7186bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7187b1f69b75SAndy Adamson if (status != 0) 7188b1f69b75SAndy Adamson goto out; 7189bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7190b1f69b75SAndy Adamson if (status != 0) 7191b1f69b75SAndy Adamson goto out; 71924e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7193b1f69b75SAndy Adamson out: 7194b1f69b75SAndy Adamson return status; 7195b1f69b75SAndy Adamson } 7196b1f69b75SAndy Adamson 7197b1f69b75SAndy Adamson /* 7198b1f69b75SAndy Adamson * Decode LAYOUTGET response 7199b1f69b75SAndy Adamson */ 7200bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7201bf269551SChuck Lever struct xdr_stream *xdr, 7202fc016483SChristoph Hellwig void *data) 7203b1f69b75SAndy Adamson { 7204fc016483SChristoph Hellwig struct nfs4_layoutget_res *res = data; 7205b1f69b75SAndy Adamson struct compound_hdr hdr; 7206b1f69b75SAndy Adamson int status; 7207b1f69b75SAndy Adamson 7208bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7209b1f69b75SAndy Adamson if (status) 7210b1f69b75SAndy Adamson goto out; 7211bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7212b1f69b75SAndy Adamson if (status) 7213b1f69b75SAndy Adamson goto out; 7214bf269551SChuck Lever status = decode_putfh(xdr); 7215b1f69b75SAndy Adamson if (status) 7216b1f69b75SAndy Adamson goto out; 7217bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7218b1f69b75SAndy Adamson out: 7219b1f69b75SAndy Adamson return status; 7220b1f69b75SAndy Adamson } 7221863a3c6cSAndy Adamson 7222863a3c6cSAndy Adamson /* 7223cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7224cbe82603SBenny Halevy */ 7225cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7226cbe82603SBenny Halevy struct xdr_stream *xdr, 7227fc016483SChristoph Hellwig void *data) 7228cbe82603SBenny Halevy { 7229fc016483SChristoph Hellwig struct nfs4_layoutreturn_res *res = data; 7230cbe82603SBenny Halevy struct compound_hdr hdr; 7231cbe82603SBenny Halevy int status; 7232cbe82603SBenny Halevy 7233cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7234cbe82603SBenny Halevy if (status) 7235cbe82603SBenny Halevy goto out; 7236cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7237cbe82603SBenny Halevy if (status) 7238cbe82603SBenny Halevy goto out; 7239cbe82603SBenny Halevy status = decode_putfh(xdr); 7240cbe82603SBenny Halevy if (status) 7241cbe82603SBenny Halevy goto out; 7242cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7243cbe82603SBenny Halevy out: 7244cbe82603SBenny Halevy return status; 7245cbe82603SBenny Halevy } 7246cbe82603SBenny Halevy 7247cbe82603SBenny Halevy /* 7248863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7249863a3c6cSAndy Adamson */ 7250863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7251863a3c6cSAndy Adamson struct xdr_stream *xdr, 7252fc016483SChristoph Hellwig void *data) 7253863a3c6cSAndy Adamson { 7254fc016483SChristoph Hellwig struct nfs4_layoutcommit_res *res = data; 7255863a3c6cSAndy Adamson struct compound_hdr hdr; 7256863a3c6cSAndy Adamson int status; 7257863a3c6cSAndy Adamson 7258863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7259863a3c6cSAndy Adamson if (status) 7260863a3c6cSAndy Adamson goto out; 7261863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7262863a3c6cSAndy Adamson if (status) 7263863a3c6cSAndy Adamson goto out; 7264863a3c6cSAndy Adamson status = decode_putfh(xdr); 7265863a3c6cSAndy Adamson if (status) 7266863a3c6cSAndy Adamson goto out; 7267863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7268863a3c6cSAndy Adamson if (status) 7269863a3c6cSAndy Adamson goto out; 72706926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7271863a3c6cSAndy Adamson out: 7272863a3c6cSAndy Adamson return status; 7273863a3c6cSAndy Adamson } 7274fca78d6dSBryan Schumaker 7275fca78d6dSBryan Schumaker /* 7276fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7277fca78d6dSBryan Schumaker */ 7278fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7279fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7280fc016483SChristoph Hellwig void *data) 7281fca78d6dSBryan Schumaker { 7282fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data; 7283fca78d6dSBryan Schumaker struct compound_hdr hdr; 7284fca78d6dSBryan Schumaker int status; 7285fca78d6dSBryan Schumaker 7286fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7287fca78d6dSBryan Schumaker if (status) 7288fca78d6dSBryan Schumaker goto out; 7289fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7290fca78d6dSBryan Schumaker if (status) 7291fca78d6dSBryan Schumaker goto out; 7292fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7293fca78d6dSBryan Schumaker if (status) 7294fca78d6dSBryan Schumaker goto out; 729531e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7296fca78d6dSBryan Schumaker out: 7297fca78d6dSBryan Schumaker return status; 7298fca78d6dSBryan Schumaker } 72997d974794SBryan Schumaker 73007d974794SBryan Schumaker /* 73017d974794SBryan Schumaker * Decode TEST_STATEID response 73027d974794SBryan Schumaker */ 73037d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 73047d974794SBryan Schumaker struct xdr_stream *xdr, 7305fc016483SChristoph Hellwig void *data) 73067d974794SBryan Schumaker { 7307fc016483SChristoph Hellwig struct nfs41_test_stateid_res *res = data; 73087d974794SBryan Schumaker struct compound_hdr hdr; 73097d974794SBryan Schumaker int status; 73107d974794SBryan Schumaker 73117d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 73127d974794SBryan Schumaker if (status) 73137d974794SBryan Schumaker goto out; 73147d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 73157d974794SBryan Schumaker if (status) 73167d974794SBryan Schumaker goto out; 73177d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 73187d974794SBryan Schumaker out: 73197d974794SBryan Schumaker return status; 73207d974794SBryan Schumaker } 73219aeda35fSBryan Schumaker 73229aeda35fSBryan Schumaker /* 73239aeda35fSBryan Schumaker * Decode FREE_STATEID response 73249aeda35fSBryan Schumaker */ 73259aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 73269aeda35fSBryan Schumaker struct xdr_stream *xdr, 7327fc016483SChristoph Hellwig void *data) 73289aeda35fSBryan Schumaker { 7329fc016483SChristoph Hellwig struct nfs41_free_stateid_res *res = data; 73309aeda35fSBryan Schumaker struct compound_hdr hdr; 73319aeda35fSBryan Schumaker int status; 73329aeda35fSBryan Schumaker 73339aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 73349aeda35fSBryan Schumaker if (status) 73359aeda35fSBryan Schumaker goto out; 73369aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 73379aeda35fSBryan Schumaker if (status) 73389aeda35fSBryan Schumaker goto out; 73399aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 73409aeda35fSBryan Schumaker out: 73419aeda35fSBryan Schumaker return status; 73429aeda35fSBryan Schumaker } 734399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 734499fe60d0SBenny Halevy 7345573c4e1eSChuck Lever /** 7346573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7347573c4e1eSChuck Lever * the local page cache. 7348573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7349573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7350573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7351573c4e1eSChuck Lever * 7352573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7353573c4e1eSChuck Lever * returned. 7354573c4e1eSChuck Lever * 7355573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7356573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7357573c4e1eSChuck Lever * on a directory already in our cache. 7358573c4e1eSChuck Lever */ 7359573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7360a7a3b1e9SBenjamin Coddington bool plus) 73611da177e4SLinus Torvalds { 7362256e48bbSTrond Myklebust unsigned int savep; 7363dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 73641da177e4SLinus Torvalds uint32_t len; 736598de9ce6SFrank Sorenson uint64_t new_cookie; 7366babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7367babddc72SBryan Schumaker if (unlikely(!p)) 7368eb72f484SChuck Lever return -EAGAIN; 7369c08e76d0SChuck Lever if (*p == xdr_zero) { 7370babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7371babddc72SBryan Schumaker if (unlikely(!p)) 7372eb72f484SChuck Lever return -EAGAIN; 7373c08e76d0SChuck Lever if (*p == xdr_zero) 7374573c4e1eSChuck Lever return -EAGAIN; 73751da177e4SLinus Torvalds entry->eof = 1; 7376573c4e1eSChuck Lever return -EBADCOOKIE; 73771da177e4SLinus Torvalds } 73781da177e4SLinus Torvalds 7379babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7380babddc72SBryan Schumaker if (unlikely(!p)) 7381eb72f484SChuck Lever return -EAGAIN; 738298de9ce6SFrank Sorenson p = xdr_decode_hyper(p, &new_cookie); 7383c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7384babddc72SBryan Schumaker 73859af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7386babddc72SBryan Schumaker if (unlikely(!p)) 7387eb72f484SChuck Lever return -EAGAIN; 73881da177e4SLinus Torvalds entry->name = (const char *) p; 73891da177e4SLinus Torvalds 73901da177e4SLinus Torvalds /* 73911da177e4SLinus Torvalds * In case the server doesn't return an inode number, 73921da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 73931da177e4SLinus Torvalds * since glibc seems to choke on it...) 73941da177e4SLinus Torvalds */ 73951da177e4SLinus Torvalds entry->ino = 1; 73964f082222STrond Myklebust entry->fattr->valid = 0; 73971da177e4SLinus Torvalds 73989af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7399eb72f484SChuck Lever return -EAGAIN; 74009af8c222STrond Myklebust 7401256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7402eb72f484SChuck Lever return -EAGAIN; 74039af8c222STrond Myklebust 7404573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7405aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7406eb72f484SChuck Lever return -EAGAIN; 740728331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 740828331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 740928331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 741082f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 74119af8c222STrond Myklebust 74120b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 74130b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 74140b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 74150b26a0bfSTrond Myklebust 741698de9ce6SFrank Sorenson entry->prev_cookie = entry->cookie; 741798de9ce6SFrank Sorenson entry->cookie = new_cookie; 741898de9ce6SFrank Sorenson 7419573c4e1eSChuck Lever return 0; 74201da177e4SLinus Torvalds } 74211da177e4SLinus Torvalds 74221da177e4SLinus Torvalds /* 74231da177e4SLinus Torvalds * We need to translate between nfs status return values and 74241da177e4SLinus Torvalds * the local errno values which may not be the same. 74251da177e4SLinus Torvalds */ 74261da177e4SLinus Torvalds static struct { 74271da177e4SLinus Torvalds int stat; 74281da177e4SLinus Torvalds int errno; 74291da177e4SLinus Torvalds } nfs_errtbl[] = { 74301da177e4SLinus Torvalds { NFS4_OK, 0 }, 7431856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7432856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7433856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7434856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7435856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7436856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7437856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7438856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7439856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7440856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7441856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7442856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7443856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7444856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7445856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7446856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7447856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7448856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7449856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7450856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7451856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7452856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7453fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7454856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7455856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7456856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7457856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7458856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7459856dff3dSBenny Halevy { -1, -EIO } 74601da177e4SLinus Torvalds }; 74611da177e4SLinus Torvalds 74621da177e4SLinus Torvalds /* 74631da177e4SLinus Torvalds * Convert an NFS error code to a local one. 74641da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 74651da177e4SLinus Torvalds */ 74661da177e4SLinus Torvalds static int 74670a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 74681da177e4SLinus Torvalds { 74691da177e4SLinus Torvalds int i; 74701da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 74711da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 74721da177e4SLinus Torvalds return nfs_errtbl[i].errno; 74731da177e4SLinus Torvalds } 74741da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 74751da177e4SLinus Torvalds /* The server is looney tunes. */ 7476fdcb4577STrond Myklebust return -EREMOTEIO; 74771da177e4SLinus Torvalds } 74781da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 74791da177e4SLinus Torvalds * handle it. 74801da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 74811da177e4SLinus Torvalds * not conflict with native Linux error codes. 74821da177e4SLinus Torvalds */ 7483856dff3dSBenny Halevy return -stat; 74841da177e4SLinus Torvalds } 74851da177e4SLinus Torvalds 74861c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 74871c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 74881c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 74891c6dcbe5SAnna Schumaker 74901da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 74911da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 74921da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 7493fcc85819SChristoph Hellwig .p_encode = nfs4_xdr_##argtype, \ 7494fc016483SChristoph Hellwig .p_decode = nfs4_xdr_##restype, \ 74952bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 74962bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7497cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7498cc0175c1SChuck Lever .p_name = #proc, \ 74991da177e4SLinus Torvalds } 75001da177e4SLinus Torvalds 75017c61f0d3SAnna Schumaker #define STUB(proc) \ 75027c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 75037c61f0d3SAnna Schumaker .p_name = #proc, \ 75047c61f0d3SAnna Schumaker } 75057c61f0d3SAnna Schumaker 75068634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1) 75078634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 75088634ef5eSTrond Myklebust PROC(proc, argtype, restype) 75098634ef5eSTrond Myklebust #else 75108634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \ 75118634ef5eSTrond Myklebust STUB(proc) 75128634ef5eSTrond Myklebust #endif 75138634ef5eSTrond Myklebust 75148634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2) 75158634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 75168634ef5eSTrond Myklebust PROC(proc, argtype, restype) 75178634ef5eSTrond Myklebust #else 75188634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \ 75198634ef5eSTrond Myklebust STUB(proc) 75208634ef5eSTrond Myklebust #endif 75218634ef5eSTrond Myklebust 7522511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = { 75231da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 75241da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 75251da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 75261da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 75271da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 75281da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 75291da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 75301da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 75311da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 75321da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 75331da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 75341da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 75351da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 75361da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 75371da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 75381da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 75391da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 75401da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 75411da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 75421da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 75431da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 75441da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 75451da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 75461da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 75471da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 75481da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 75491da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 75501da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 75511da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 75521da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 75531da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7554029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 755523ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7556683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7557d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 75585a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 755944c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 75608634ef5eSTrond Myklebust PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 75618634ef5eSTrond Myklebust PROC41(CREATE_SESSION, enc_create_session, dec_create_session), 75628634ef5eSTrond Myklebust PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 75638634ef5eSTrond Myklebust PROC41(SEQUENCE, enc_sequence, dec_sequence), 75640efb01b2SDonald Buczek PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 75658634ef5eSTrond Myklebust PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete), 75668634ef5eSTrond Myklebust PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 75678634ef5eSTrond Myklebust PROC41(LAYOUTGET, enc_layoutget, dec_layoutget), 75688634ef5eSTrond Myklebust PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 75698634ef5eSTrond Myklebust PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 75708634ef5eSTrond Myklebust PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 75718634ef5eSTrond Myklebust PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid), 75728634ef5eSTrond Myklebust PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid), 75737c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 75748634ef5eSTrond Myklebust PROC41(BIND_CONN_TO_SESSION, 7575ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 75768634ef5eSTrond Myklebust PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid), 75778634ef5eSTrond Myklebust PROC42(SEEK, enc_seek, dec_seek), 75788634ef5eSTrond Myklebust PROC42(ALLOCATE, enc_allocate, dec_allocate), 75798634ef5eSTrond Myklebust PROC42(DEALLOCATE, enc_deallocate, dec_deallocate), 75808634ef5eSTrond Myklebust PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 75818634ef5eSTrond Myklebust PROC42(CLONE, enc_clone, dec_clone), 75828634ef5eSTrond Myklebust PROC42(COPY, enc_copy, dec_copy), 7583cb95deeaSOlga Kornievskaia PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel), 75848634ef5eSTrond Myklebust PROC(LOOKUPP, enc_lookupp, dec_lookupp), 75853eb86093STrond Myklebust PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror), 75861da177e4SLinus Torvalds }; 75871da177e4SLinus Torvalds 7588c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)]; 7589a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 75901da177e4SLinus Torvalds .number = 4, 7591e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 7592c551858aSChristoph Hellwig .procs = nfs4_procedures, 7593c551858aSChristoph Hellwig .counts = nfs_version4_counts, 75941da177e4SLinus Torvalds }; 75951da177e4SLinus Torvalds 75961da177e4SLinus Torvalds /* 75971da177e4SLinus Torvalds * Local variables: 75981da177e4SLinus Torvalds * c-basic-offset: 8 75991da177e4SLinus Torvalds * End: 76001da177e4SLinus Torvalds */ 7601