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> 551da177e4SLinus Torvalds #include <linux/nfs_idmap.h> 56f092075dSChuck Lever 574ce79717STrond Myklebust #include "nfs4_fs.h" 584882ef72SAlexandros Batsakis #include "internal.h" 5976e697baSTrond Myklebust #include "nfs4session.h" 60b1f69b75SAndy Adamson #include "pnfs.h" 61f092075dSChuck Lever #include "netns.h" 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 661da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 671da177e4SLinus Torvalds 680a8ea437SDavid Howells static int nfs4_stat_to_errno(int); 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */ 711da177e4SLinus Torvalds #ifdef DEBUG 721da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20 731da177e4SLinus Torvalds #else 741da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0 751da177e4SLinus Torvalds #endif 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* lock,open owner id: 789f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) 791da177e4SLinus Torvalds */ 8095b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2) 81d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4) 829104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 831da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 841da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) 851da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1) 861da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2) 879104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 889104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) 899104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 909104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) 911da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \ 921da177e4SLinus Torvalds (NFS4_FHSIZE >> 2)) 931da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz) 941da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz) 951da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz) 961da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz) 971da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \ 981da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2)) 99e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4 10096928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz) 1011da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2)) 1021da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2)) 103bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 104bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) 105aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL 106aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */ 107aa9c2669SDavid Quigley #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN)) 108aa9c2669SDavid Quigley #else 109aa9c2669SDavid Quigley #define nfs4_label_maxsz 0 110aa9c2669SDavid Quigley #endif 11188034c3dSAndy Adamson /* We support only one layout type per file system */ 11288034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8) 11396928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */ 11496928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \ 11588034c3dSAndy Adamson 3 + 3 + 3 + nfs4_owner_maxsz + \ 116aa9c2669SDavid Quigley nfs4_group_maxsz + nfs4_label_maxsz + \ 117aa9c2669SDavid Quigley decode_mdsthreshold_maxsz)) 11896928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \ 11996928206SJ. Bruce Fields nfs4_fattr_value_maxsz) 12096928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz) 1219104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \ 1229104a55dSTrond Myklebust 1 + 2 + 1 + \ 1239104a55dSTrond Myklebust nfs4_owner_maxsz + \ 1249104a55dSTrond Myklebust nfs4_group_maxsz + \ 125aa9c2669SDavid Quigley nfs4_label_maxsz + \ 1269104a55dSTrond Myklebust 4 + 4) 1271da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz) 1281da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz) 12956ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz) 13056ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz) 1312f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz) 132dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three 133dae100c2SFred Isaman * layout types will be returned. 134dae100c2SFred Isaman */ 135dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 136dae100c2SFred Isaman nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 1371da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 1381da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz) 1391da177e4SLinus Torvalds #define encode_setclientid_maxsz \ 1401da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 141cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 142cc38bac3SChuck Lever XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \ 143cc38bac3SChuck Lever 1 /* sc_prog */ + \ 1446dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1456dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 146cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1471da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1481da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1496dd3436bSChuck Lever 2 /* clientid */ + \ 1506dd3436bSChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 1516dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1526dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) 1531da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \ 1541da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 1551da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2)) 1561da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \ 1571da177e4SLinus Torvalds (op_decode_hdr_maxsz) 158e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 159e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz) 1602cebf828STrond Myklebust #define encode_share_access_maxsz \ 1612cebf828STrond Myklebust (2) 1624882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1632cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1642cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1652cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1662cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1672cebf828STrond Myklebust open_owner_id_maxsz + \ 1682cebf828STrond Myklebust encode_opentype_maxsz + \ 1692cebf828STrond Myklebust encode_claim_null_maxsz) 1702cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1719104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1722cebf828STrond Myklebust decode_ace_maxsz) 1732cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1742cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1759104a55dSTrond Myklebust decode_stateid_maxsz + \ 1762cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1772cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1782cebf828STrond Myklebust decode_delegation_maxsz) 1799104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1809104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1819104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1829104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1839104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1849104a55dSTrond Myklebust decode_stateid_maxsz) 1859104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 1869104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1879104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 1889104a55dSTrond Myklebust encode_share_access_maxsz) 1899104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 1909104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1919104a55dSTrond Myklebust decode_stateid_maxsz) 1929104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 1939104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 1949104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 1959104a55dSTrond Myklebust decode_stateid_maxsz) 1969104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 1979104a55dSTrond Myklebust encode_stateid_maxsz + \ 1989104a55dSTrond Myklebust encode_attrs_maxsz) 1999104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 2009104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 2019104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 2029104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2039104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 2049104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 205aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \ 206aa9c2669SDavid Quigley nfs4_label_maxsz) 2079104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 208a7697f6fSChuck Lever decode_verifier_maxsz) 2099104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 2109104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 2119104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2129104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2139104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2149104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2159104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2169104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2179104a55dSTrond Myklebust decode_verifier_maxsz) 2181da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2191da177e4SLinus Torvalds nfs4_name_maxsz) 2206ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2216ce18391SBenny Halevy decode_change_info_maxsz) 2221da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2231da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2246ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2256ce18391SBenny Halevy decode_change_info_maxsz + \ 2266ce18391SBenny Halevy decode_change_info_maxsz) 2271da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2281da177e4SLinus Torvalds nfs4_name_maxsz) 2296ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 230daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2319104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2329104a55dSTrond Myklebust 7 + \ 233daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 234daccbdedSTrond Myklebust encode_lockowner_maxsz) 2359104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2369104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2379104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2389104a55dSTrond Myklebust decode_lock_denied_maxsz) 239daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 240daccbdedSTrond Myklebust encode_lockowner_maxsz) 2419104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2429104a55dSTrond Myklebust decode_lock_denied_maxsz) 2439104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2449104a55dSTrond Myklebust encode_stateid_maxsz + \ 2459104a55dSTrond Myklebust 4) 2469104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2479104a55dSTrond Myklebust decode_stateid_maxsz) 248d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 249d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 250d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 251d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 252d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2539104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2549104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2551da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2561da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 25794a6d753SChuck Lever 1 + \ 25896928206SJ. Bruce Fields nfs4_fattr_maxsz) 2591da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2601da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2619104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2629104a55dSTrond Myklebust encode_attrs_maxsz) 2632cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2642cebf828STrond Myklebust decode_change_info_maxsz + \ 2652cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2669104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2679104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2681da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2691da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2709104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2719104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2729104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2739104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2749104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2759104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 276e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 277e6889620STrond Myklebust (encode_getattr_maxsz) 278e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 279e6889620STrond Myklebust (0) 2805a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2811650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2829b7b9fccSAndy Adamson 2839b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 284fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 285d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 286d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 287fc931582SAndy Adamson 28899fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 28999fe60d0SBenny Halevy encode_verifier_maxsz + \ 29099fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 29199fe60d0SBenny Halevy XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \ 29299fe60d0SBenny Halevy 1 /* flags */ + \ 29399fe60d0SBenny Halevy 1 /* spa_how */ + \ 2942031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 2952031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 2962031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 297db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 298db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 299db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 300db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 301d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 302db8ac8baSWeston Andros Adamson 3 /* nii_date */) 30399fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 30499fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 30599fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 30699fe60d0SBenny Halevy 1 /* eir_flags */ + \ 30799fe60d0SBenny Halevy 1 /* spr_how */ + \ 3082031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3092031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3102031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 31199fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 31299fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 31399fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 31499fe60d0SBenny Halevy /* eir_server_scope<> */ \ 31599fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 31699fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 3177d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3187d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3197d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3207d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3217d2ed9acSWeston Andros Adamson 3 /* nii_date */) 322fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 323fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 324fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 325fc931582SAndy Adamson 1 /* ca_rdma_ird */) 326fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 327fc931582SAndy Adamson 2 /* csa_clientid */ + \ 328fc931582SAndy Adamson 1 /* csa_sequence */ + \ 329fc931582SAndy Adamson 1 /* csa_flags */ + \ 330fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 331fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 332fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 333fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 334fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 335fc931582SAndy Adamson 1 /* stamp */ + \ 336fc931582SAndy Adamson 1 /* machinename.len */ + \ 337fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 338fc931582SAndy Adamson 1 /* uid */ + \ 339fc931582SAndy Adamson 1 /* gid */ + \ 340fc931582SAndy Adamson 1 /* gids.len (0) */) 341fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 342fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 343fc931582SAndy Adamson 1 /* csr_sequence */ + \ 344fc931582SAndy Adamson 1 /* csr_flags */ + \ 345fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 346fc931582SAndy Adamson decode_channel_attrs_maxsz) 3477c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3487c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3497c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3507c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3517c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3527c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3537c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3547c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3557c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3567c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3570f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3580f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 35966245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 36066245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 361fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 362fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 363fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 364fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 36518019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 36618019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 36784c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \ 36884c9dee3SChristoph Hellwig XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 36984c9dee3SChristoph Hellwig 1 /* layout type */ + \ 37084c9dee3SChristoph Hellwig 1 /* maxcount */ + \ 37184c9dee3SChristoph Hellwig 1 /* bitmap size */ + \ 37284c9dee3SChristoph Hellwig 1 /* notification bitmap length */ + \ 37384c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 374b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 375b1f69b75SAndy Adamson 1 /* layout type */ + \ 376b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 377b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 378b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 37984c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 380b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 381b1f69b75SAndy Adamson encode_stateid_maxsz) 382b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 383b1f69b75SAndy Adamson decode_stateid_maxsz + \ 384b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 385863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 386863a3c6cSAndy Adamson 2 /* offset */ + \ 387863a3c6cSAndy Adamson 2 /* length */ + \ 388863a3c6cSAndy Adamson 1 /* reclaim */ + \ 389863a3c6cSAndy Adamson encode_stateid_maxsz + \ 390863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 391863a3c6cSAndy Adamson 2 /* last byte written */ + \ 392863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 393863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 3945f919c9fSChristoph Hellwig 1 /* layoutupdate4 opaqueue len */) 3955f919c9fSChristoph Hellwig /* the actual content of layoutupdate4 should 3965f919c9fSChristoph Hellwig be allocated by drivers and spliced in 3975f919c9fSChristoph Hellwig using xdr_write_pages */ 398863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 399cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 400cbe82603SBenny Halevy encode_stateid_maxsz + \ 401cbe82603SBenny Halevy 1 /* FIXME: opaque lrf_body always empty at the moment */) 402cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 403cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 404fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 405fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 4067d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 4077d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4087d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 4099aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 4109aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4119f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 4129b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 4139b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 4149b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 4159b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4169b7b9fccSAndy Adamson 4171da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4181da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4191da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4209b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4211da177e4SLinus Torvalds encode_putfh_maxsz + \ 4229104a55dSTrond Myklebust encode_read_maxsz) 4231da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4249b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4251da177e4SLinus Torvalds decode_putfh_maxsz + \ 4269104a55dSTrond Myklebust decode_read_maxsz) 4271da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4291da177e4SLinus Torvalds encode_putfh_maxsz + \ 4309104a55dSTrond Myklebust encode_readlink_maxsz) 4311da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4331da177e4SLinus Torvalds decode_putfh_maxsz + \ 4349104a55dSTrond Myklebust decode_readlink_maxsz) 4351da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4369b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4371da177e4SLinus Torvalds encode_putfh_maxsz + \ 4389104a55dSTrond Myklebust encode_readdir_maxsz) 4391da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4409b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4411da177e4SLinus Torvalds decode_putfh_maxsz + \ 4429104a55dSTrond Myklebust decode_readdir_maxsz) 4431da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4449b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4451da177e4SLinus Torvalds encode_putfh_maxsz + \ 4469104a55dSTrond Myklebust encode_write_maxsz + \ 4474f9838c7STrond Myklebust encode_getattr_maxsz) 4481da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4499b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4501da177e4SLinus Torvalds decode_putfh_maxsz + \ 4519104a55dSTrond Myklebust decode_write_maxsz + \ 4524f9838c7STrond Myklebust decode_getattr_maxsz) 4531da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4549b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4551da177e4SLinus Torvalds encode_putfh_maxsz + \ 4568582715eSTrond Myklebust encode_commit_maxsz) 4571da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4589b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4591da177e4SLinus Torvalds decode_putfh_maxsz + \ 4608582715eSTrond Myklebust decode_commit_maxsz) 4611da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4629b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4631da177e4SLinus Torvalds encode_putfh_maxsz + \ 4642cebf828STrond Myklebust encode_open_maxsz + \ 4656168f62cSWeston Andros Adamson encode_access_maxsz + \ 4662cebf828STrond Myklebust encode_getfh_maxsz + \ 4672cebf828STrond Myklebust encode_getattr_maxsz) 4681da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4699b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4701da177e4SLinus Torvalds decode_putfh_maxsz + \ 4712cebf828STrond Myklebust decode_open_maxsz + \ 4726168f62cSWeston Andros Adamson decode_access_maxsz + \ 4732cebf828STrond Myklebust decode_getfh_maxsz + \ 4742cebf828STrond Myklebust decode_getattr_maxsz) 4751da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4761da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4771da177e4SLinus Torvalds encode_putfh_maxsz + \ 4789104a55dSTrond Myklebust encode_open_confirm_maxsz) 4799104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4809104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4811da177e4SLinus Torvalds decode_putfh_maxsz + \ 4829104a55dSTrond Myklebust decode_open_confirm_maxsz) 4831da177e4SLinus Torvalds #define NFS4_enc_open_noattr_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_getattr_maxsz) 4891da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 4909b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4911da177e4SLinus Torvalds decode_putfh_maxsz + \ 4922cebf828STrond Myklebust decode_open_maxsz + \ 4936168f62cSWeston Andros Adamson decode_access_maxsz + \ 4942cebf828STrond Myklebust decode_getattr_maxsz) 4951da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 4961da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4979b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4981da177e4SLinus Torvalds encode_putfh_maxsz + \ 4999104a55dSTrond Myklebust encode_open_downgrade_maxsz + \ 500516a6af6STrond Myklebust encode_getattr_maxsz) 5011da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 5021da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5039b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5041da177e4SLinus Torvalds decode_putfh_maxsz + \ 5059104a55dSTrond Myklebust decode_open_downgrade_maxsz + \ 506516a6af6STrond Myklebust decode_getattr_maxsz) 5071da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 5089b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5091da177e4SLinus Torvalds encode_putfh_maxsz + \ 5109104a55dSTrond Myklebust encode_close_maxsz + \ 511516a6af6STrond Myklebust encode_getattr_maxsz) 5121da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 5139b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5141da177e4SLinus Torvalds decode_putfh_maxsz + \ 5159104a55dSTrond Myklebust decode_close_maxsz + \ 516516a6af6STrond Myklebust decode_getattr_maxsz) 5171da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 5189b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5191da177e4SLinus Torvalds encode_putfh_maxsz + \ 5209104a55dSTrond Myklebust encode_setattr_maxsz + \ 5211da177e4SLinus Torvalds encode_getattr_maxsz) 5221da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5239b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5241da177e4SLinus Torvalds decode_putfh_maxsz + \ 5259104a55dSTrond Myklebust decode_setattr_maxsz + \ 5269104a55dSTrond Myklebust decode_getattr_maxsz) 5271da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5289b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5291da177e4SLinus Torvalds encode_putfh_maxsz + \ 5301da177e4SLinus Torvalds encode_fsinfo_maxsz) 5311da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5329b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5331da177e4SLinus Torvalds decode_putfh_maxsz + \ 5341da177e4SLinus Torvalds decode_fsinfo_maxsz) 5351da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5361da177e4SLinus Torvalds encode_renew_maxsz) 5371da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5381da177e4SLinus Torvalds decode_renew_maxsz) 5391da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5401da177e4SLinus Torvalds encode_setclientid_maxsz) 5411da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5421da177e4SLinus Torvalds decode_setclientid_maxsz) 5431da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5441da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 54583ca7f5aSChuck Lever encode_setclientid_confirm_maxsz) 5461da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5471da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 54883ca7f5aSChuck Lever decode_setclientid_confirm_maxsz) 5491da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5509b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5511da177e4SLinus Torvalds encode_putfh_maxsz + \ 5529104a55dSTrond Myklebust encode_lock_maxsz) 5531da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5549b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5551da177e4SLinus Torvalds decode_putfh_maxsz + \ 5569104a55dSTrond Myklebust decode_lock_maxsz) 5571da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5589b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5591da177e4SLinus Torvalds encode_putfh_maxsz + \ 5609104a55dSTrond Myklebust encode_lockt_maxsz) 5619104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5629b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5639104a55dSTrond Myklebust decode_putfh_maxsz + \ 5649104a55dSTrond Myklebust decode_lockt_maxsz) 5651da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5669b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5671da177e4SLinus Torvalds encode_putfh_maxsz + \ 5689104a55dSTrond Myklebust encode_locku_maxsz) 5691da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5709b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5711da177e4SLinus Torvalds decode_putfh_maxsz + \ 5729104a55dSTrond Myklebust decode_locku_maxsz) 573d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 574d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 575d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 576d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 577d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 578d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5791da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5809b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5811da177e4SLinus Torvalds encode_putfh_maxsz + \ 58276b32999STrond Myklebust encode_access_maxsz + \ 58376b32999STrond Myklebust encode_getattr_maxsz) 5841da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5859b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5861da177e4SLinus Torvalds decode_putfh_maxsz + \ 58776b32999STrond Myklebust decode_access_maxsz + \ 58876b32999STrond Myklebust decode_getattr_maxsz) 5891da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 5909b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5911da177e4SLinus Torvalds encode_putfh_maxsz + \ 59244c99933SChuck Lever encode_getattr_maxsz + \ 59344c99933SChuck Lever encode_renew_maxsz) 5941da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 5959b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5961da177e4SLinus Torvalds decode_putfh_maxsz + \ 59744c99933SChuck Lever decode_getattr_maxsz + \ 59844c99933SChuck Lever decode_renew_maxsz) 5991da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 6009b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6011da177e4SLinus Torvalds encode_putfh_maxsz + \ 6021da177e4SLinus Torvalds encode_lookup_maxsz + \ 6031da177e4SLinus Torvalds encode_getattr_maxsz + \ 6041da177e4SLinus Torvalds encode_getfh_maxsz) 6051da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 6069b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6071da177e4SLinus Torvalds decode_putfh_maxsz + \ 608e6889620STrond Myklebust decode_lookup_maxsz + \ 6091da177e4SLinus Torvalds decode_getattr_maxsz + \ 6101da177e4SLinus Torvalds decode_getfh_maxsz) 6111da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 6129b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6131da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 6141da177e4SLinus Torvalds encode_getattr_maxsz + \ 6151da177e4SLinus Torvalds encode_getfh_maxsz) 6161da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6181da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6191da177e4SLinus Torvalds decode_getattr_maxsz + \ 6201da177e4SLinus Torvalds decode_getfh_maxsz) 6211da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6229b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6231da177e4SLinus Torvalds encode_putfh_maxsz + \ 624778d2817STrond Myklebust encode_remove_maxsz) 6251da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6269b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6271da177e4SLinus Torvalds decode_putfh_maxsz + \ 628778d2817STrond Myklebust decode_remove_maxsz) 6291da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6309b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6311da177e4SLinus Torvalds encode_putfh_maxsz + \ 6321da177e4SLinus Torvalds encode_savefh_maxsz + \ 6331da177e4SLinus Torvalds encode_putfh_maxsz + \ 634778d2817STrond Myklebust encode_rename_maxsz) 6351da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6369b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6371da177e4SLinus Torvalds decode_putfh_maxsz + \ 6381da177e4SLinus Torvalds decode_savefh_maxsz + \ 6391da177e4SLinus Torvalds decode_putfh_maxsz + \ 640778d2817STrond Myklebust decode_rename_maxsz) 6411da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6429b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6431da177e4SLinus Torvalds encode_putfh_maxsz + \ 6441da177e4SLinus Torvalds encode_savefh_maxsz + \ 6451da177e4SLinus Torvalds encode_putfh_maxsz + \ 64691ba2eeeSTrond Myklebust encode_link_maxsz + \ 64791ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 648a9f6991bSTrond Myklebust encode_getattr_maxsz) 6491da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6509b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6511da177e4SLinus Torvalds decode_putfh_maxsz + \ 6521da177e4SLinus Torvalds decode_savefh_maxsz + \ 6531da177e4SLinus Torvalds decode_putfh_maxsz + \ 65491ba2eeeSTrond Myklebust decode_link_maxsz + \ 65591ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 65691ba2eeeSTrond Myklebust decode_getattr_maxsz) 6571da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6589b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6591da177e4SLinus Torvalds encode_putfh_maxsz + \ 6601da177e4SLinus Torvalds encode_symlink_maxsz + \ 6611da177e4SLinus Torvalds encode_getattr_maxsz + \ 6621da177e4SLinus Torvalds encode_getfh_maxsz) 6631da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6649b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6651da177e4SLinus Torvalds decode_putfh_maxsz + \ 6661da177e4SLinus Torvalds decode_symlink_maxsz + \ 6671da177e4SLinus Torvalds decode_getattr_maxsz + \ 6681da177e4SLinus Torvalds decode_getfh_maxsz) 6691da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6709b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6711da177e4SLinus Torvalds encode_putfh_maxsz + \ 6721da177e4SLinus Torvalds encode_create_maxsz + \ 67356ae19f3STrond Myklebust encode_getfh_maxsz + \ 67456ae19f3STrond Myklebust encode_getattr_maxsz) 6751da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 6769b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6771da177e4SLinus Torvalds decode_putfh_maxsz + \ 6781da177e4SLinus Torvalds decode_create_maxsz + \ 67956ae19f3STrond Myklebust decode_getfh_maxsz + \ 68056ae19f3STrond Myklebust decode_getattr_maxsz) 6811da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 6829b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6831da177e4SLinus Torvalds encode_putfh_maxsz + \ 6841da177e4SLinus Torvalds encode_getattr_maxsz) 6851da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 6869b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6871da177e4SLinus Torvalds decode_putfh_maxsz + \ 6881da177e4SLinus Torvalds decode_getattr_maxsz) 6891da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 6909b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6911da177e4SLinus Torvalds encode_putfh_maxsz + \ 6929104a55dSTrond Myklebust encode_statfs_maxsz) 6931da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 6949b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6951da177e4SLinus Torvalds decode_putfh_maxsz + \ 6969104a55dSTrond Myklebust decode_statfs_maxsz) 6971da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 6989b7b9fccSAndy Adamson encode_sequence_maxsz + \ 699ab91f264STrond Myklebust encode_putfh_maxsz + \ 7001da177e4SLinus Torvalds encode_getattr_maxsz) 7011da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 7029b7b9fccSAndy Adamson decode_sequence_maxsz + \ 703ab91f264STrond Myklebust decode_putfh_maxsz + \ 7041da177e4SLinus Torvalds decode_getattr_maxsz) 7051da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 7069b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7071da177e4SLinus Torvalds encode_putfh_maxsz + \ 708fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 709fa178f29STrond Myklebust encode_getattr_maxsz) 7101da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7119b7b9fccSAndy Adamson decode_sequence_maxsz + \ 712fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 713fa178f29STrond Myklebust decode_getattr_maxsz) 714029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7159b7b9fccSAndy Adamson encode_sequence_maxsz + \ 716029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7179104a55dSTrond Myklebust encode_getacl_maxsz) 718029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7199b7b9fccSAndy Adamson decode_sequence_maxsz + \ 720029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7219104a55dSTrond Myklebust decode_getacl_maxsz) 72223ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7239b7b9fccSAndy Adamson encode_sequence_maxsz + \ 72423ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7259104a55dSTrond Myklebust encode_setacl_maxsz) 72623ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7279b7b9fccSAndy Adamson decode_sequence_maxsz + \ 72823ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7299104a55dSTrond Myklebust decode_setacl_maxsz) 730683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 731683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7329b7b9fccSAndy Adamson encode_sequence_maxsz + \ 733683b57b4STrond Myklebust encode_putfh_maxsz + \ 734e6889620STrond Myklebust encode_lookup_maxsz + \ 735b03d735bSChuck Lever encode_fs_locations_maxsz + \ 736b03d735bSChuck Lever encode_renew_maxsz) 737683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 738683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7399b7b9fccSAndy Adamson decode_sequence_maxsz + \ 740683b57b4STrond Myklebust decode_putfh_maxsz + \ 741e6889620STrond Myklebust decode_lookup_maxsz + \ 742b03d735bSChuck Lever decode_fs_locations_maxsz + \ 743b03d735bSChuck Lever decode_renew_maxsz) 7445a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7455a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7465a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7475a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7485a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7495a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7505a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7515a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 75244c99933SChuck Lever #define NFS4_enc_fsid_present_sz \ 75344c99933SChuck Lever (compound_encode_hdr_maxsz + \ 75444c99933SChuck Lever encode_sequence_maxsz + \ 75544c99933SChuck Lever encode_putfh_maxsz + \ 75644c99933SChuck Lever encode_getfh_maxsz + \ 75744c99933SChuck Lever encode_renew_maxsz) 75844c99933SChuck Lever #define NFS4_dec_fsid_present_sz \ 75944c99933SChuck Lever (compound_decode_hdr_maxsz + \ 76044c99933SChuck Lever decode_sequence_maxsz + \ 76144c99933SChuck Lever decode_putfh_maxsz + \ 76244c99933SChuck Lever decode_getfh_maxsz + \ 76344c99933SChuck Lever decode_renew_maxsz) 76499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 7657c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 7667c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 7677c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 7687c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 7697c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 7707c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 77199fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 77299fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 77399fe60d0SBenny Halevy encode_exchange_id_maxsz) 77499fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 77599fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 77699fe60d0SBenny Halevy decode_exchange_id_maxsz) 777fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 778fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 779fc931582SAndy Adamson encode_create_session_maxsz) 780fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 781fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 782fc931582SAndy Adamson decode_create_session_maxsz) 7830f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 7840f3e66c6SAndy Adamson encode_destroy_session_maxsz) 7850f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 7860f3e66c6SAndy Adamson decode_destroy_session_maxsz) 78766245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 78866245539STrond Myklebust encode_destroy_clientid_maxsz) 78966245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 79066245539STrond Myklebust decode_destroy_clientid_maxsz) 791fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 792fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 793fc01cea9SAndy Adamson encode_sequence_maxsz) 794fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 795fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 796fc01cea9SAndy Adamson decode_sequence_maxsz) 7972050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 7982050f0ccSAndy Adamson encode_sequence_maxsz + \ 7992050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 8002050f0ccSAndy Adamson encode_fsinfo_maxsz) 8012050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 8022050f0ccSAndy Adamson decode_sequence_maxsz + \ 8032050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 8042050f0ccSAndy Adamson decode_fsinfo_maxsz) 80518019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 80618019753SRicardo Labiaga encode_sequence_maxsz + \ 80718019753SRicardo Labiaga encode_reclaim_complete_maxsz) 80818019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 80918019753SRicardo Labiaga decode_sequence_maxsz + \ 81018019753SRicardo Labiaga decode_reclaim_complete_maxsz) 811b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 812b1f69b75SAndy Adamson encode_sequence_maxsz +\ 813b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 814b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 815b1f69b75SAndy Adamson decode_sequence_maxsz + \ 816b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 817b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 818b1f69b75SAndy Adamson encode_sequence_maxsz + \ 819b1f69b75SAndy Adamson encode_putfh_maxsz + \ 820b1f69b75SAndy Adamson encode_layoutget_maxsz) 821b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 822b1f69b75SAndy Adamson decode_sequence_maxsz + \ 823b1f69b75SAndy Adamson decode_putfh_maxsz + \ 824b1f69b75SAndy Adamson decode_layoutget_maxsz) 825863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 826863a3c6cSAndy Adamson encode_sequence_maxsz +\ 827863a3c6cSAndy Adamson encode_putfh_maxsz + \ 828863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 829863a3c6cSAndy Adamson encode_getattr_maxsz) 830863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 831863a3c6cSAndy Adamson decode_sequence_maxsz + \ 832863a3c6cSAndy Adamson decode_putfh_maxsz + \ 833863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 834863a3c6cSAndy Adamson decode_getattr_maxsz) 835cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 836cbe82603SBenny Halevy encode_sequence_maxsz + \ 837cbe82603SBenny Halevy encode_putfh_maxsz + \ 838cbe82603SBenny Halevy encode_layoutreturn_maxsz) 839cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 840cbe82603SBenny Halevy decode_sequence_maxsz + \ 841cbe82603SBenny Halevy decode_putfh_maxsz + \ 842cbe82603SBenny Halevy decode_layoutreturn_maxsz) 843fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 844fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 845fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 846fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 847fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 848fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 849fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 850fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8517d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8527d974794SBryan Schumaker encode_sequence_maxsz + \ 8537d974794SBryan Schumaker encode_test_stateid_maxsz) 8547d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8557d974794SBryan Schumaker decode_sequence_maxsz + \ 8567d974794SBryan Schumaker decode_test_stateid_maxsz) 8579aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8589aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8599aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8609aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8619aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8629aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8632449ea2eSAlexandros Batsakis 8642449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8652449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8662449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8672449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8682449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8692449ea2eSAlexandros Batsakis XDR_UNIT); 8702449ea2eSAlexandros Batsakis 8712449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8722449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 8732449ea2eSAlexandros Batsakis decode_sequence_maxsz + 8742449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 8752449ea2eSAlexandros Batsakis XDR_UNIT); 876f1c097beSAndy Adamson 877f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH + 878f1c097beSAndy Adamson compound_decode_hdr_maxsz + 879f1c097beSAndy Adamson decode_sequence_maxsz) * 880f1c097beSAndy Adamson XDR_UNIT); 881f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 88299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 8831da177e4SLinus Torvalds 884bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 885bca79478STrond Myklebust [NF4BAD] = 0, 886bca79478STrond Myklebust [NF4REG] = S_IFREG, 887bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 888bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 889bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 890bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 891bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 892bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 893bca79478STrond Myklebust [NF4ATTRDIR] = 0, 894bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 8951da177e4SLinus Torvalds }; 8961da177e4SLinus Torvalds 8971da177e4SLinus Torvalds struct compound_hdr { 8981da177e4SLinus Torvalds int32_t status; 8991da177e4SLinus Torvalds uint32_t nops; 900d017931cSAndy Adamson __be32 * nops_p; 9011da177e4SLinus Torvalds uint32_t taglen; 9021da177e4SLinus Torvalds char * tag; 9030c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 90466cc0429SBenny Halevy u32 minorversion; 9051da177e4SLinus Torvalds }; 9061da177e4SLinus Torvalds 90713c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 90813c65ce9SBenny Halevy { 90913c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 91013c65ce9SBenny Halevy BUG_ON(!p); 91113c65ce9SBenny Halevy return p; 91213c65ce9SBenny Halevy } 9131da177e4SLinus Torvalds 914cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 915cb17e556STrond Myklebust { 916cb17e556STrond Myklebust __be32 *p; 917cb17e556STrond Myklebust 918cb17e556STrond Myklebust p = xdr_reserve_space(xdr, len); 919cb17e556STrond Myklebust xdr_encode_opaque_fixed(p, buf, len); 920cb17e556STrond Myklebust } 921cb17e556STrond Myklebust 9221da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 9231da177e4SLinus Torvalds { 9248687b63aSAl Viro __be32 *p; 9251da177e4SLinus Torvalds 9266fdfb0bcSTrond Myklebust p = reserve_space(xdr, 4 + len); 9271da177e4SLinus Torvalds xdr_encode_opaque(p, str, len); 9281da177e4SLinus Torvalds } 9291da177e4SLinus Torvalds 9304ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9314ade9821STrond Myklebust { 9324ade9821STrond Myklebust __be32 *p; 9334ade9821STrond Myklebust 9344ade9821STrond Myklebust p = reserve_space(xdr, 4); 9354ade9821STrond Myklebust *p = cpu_to_be32(n); 9364ade9821STrond Myklebust } 9374ade9821STrond Myklebust 938ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 939ff2eb681STrond Myklebust { 940ff2eb681STrond Myklebust __be32 *p; 941ff2eb681STrond Myklebust 942ff2eb681STrond Myklebust p = reserve_space(xdr, 8); 943ff2eb681STrond Myklebust xdr_encode_hyper(p, n); 944ff2eb681STrond Myklebust } 945ff2eb681STrond Myklebust 9464ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9474ade9821STrond Myklebust const struct nfs_seqid *seqid) 9484ade9821STrond Myklebust { 949a6796419STrond Myklebust if (seqid != NULL) 9504ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 951a6796419STrond Myklebust else 952a6796419STrond Myklebust encode_uint32(xdr, 0); 9534ade9821STrond Myklebust } 9544ade9821STrond Myklebust 9550c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9560c4e8c18SBenny Halevy struct rpc_rqst *req, 9570c4e8c18SBenny Halevy struct compound_hdr *hdr) 9581da177e4SLinus Torvalds { 9598687b63aSAl Viro __be32 *p; 960a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9610c4e8c18SBenny Halevy 9620c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9630c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9640c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9650c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9661da177e4SLinus Torvalds 9677fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 9686fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9696fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 970e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 971d017931cSAndy Adamson hdr->nops_p = p; 97234558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 973d017931cSAndy Adamson } 974d017931cSAndy Adamson 975ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 976ab19b481STrond Myklebust uint32_t replen, 977ab19b481STrond Myklebust struct compound_hdr *hdr) 978ab19b481STrond Myklebust { 979ab19b481STrond Myklebust encode_uint32(xdr, op); 980ab19b481STrond Myklebust hdr->nops++; 981ab19b481STrond Myklebust hdr->replen += replen; 982ab19b481STrond Myklebust } 983ab19b481STrond Myklebust 984d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 985d017931cSAndy Adamson { 9867fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 987d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 9881da177e4SLinus Torvalds } 9891da177e4SLinus Torvalds 990ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 991ea9d23f5STrond Myklebust { 9922d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 993ea9d23f5STrond Myklebust } 994ea9d23f5STrond Myklebust 9951da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 9961da177e4SLinus Torvalds { 997cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 9981da177e4SLinus Torvalds } 9991da177e4SLinus Torvalds 1000aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1001aa9c2669SDavid Quigley const struct nfs4_label *label, 1002aa9c2669SDavid Quigley const struct nfs_server *server) 10031da177e4SLinus Torvalds { 10041da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10051da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10061da177e4SLinus Torvalds int owner_namelen = 0; 10071da177e4SLinus Torvalds int owner_grouplen = 0; 10088687b63aSAl Viro __be32 *p; 1009d7067b2dSTrond Myklebust unsigned i; 1010d7067b2dSTrond Myklebust uint32_t len = 0; 1011d7067b2dSTrond Myklebust uint32_t bmval_len; 1012d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10131da177e4SLinus Torvalds 10141da177e4SLinus Torvalds /* 10151da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10161da177e4SLinus Torvalds * In the worst-case, this would be 1017a09df2caSDavid Quigley * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 1018a09df2caSDavid Quigley * = 40 bytes, plus any contribution from variable-length fields 101923ec6965SJ. Bruce Fields * such as owner/group. 10201da177e4SLinus Torvalds */ 1021d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_SIZE) { 1022d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10231da177e4SLinus Torvalds len += 8; 1024d7067b2dSTrond Myklebust } 1025d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 1026d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10271da177e4SLinus Torvalds len += 4; 1028d7067b2dSTrond Myklebust } 10291da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 1030e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10311da177e4SLinus Torvalds if (owner_namelen < 0) { 1032fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1033e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 10341da177e4SLinus Torvalds /* XXX */ 10351da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10361da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10371da177e4SLinus Torvalds /* goto out; */ 10381da177e4SLinus Torvalds } 1039d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 10401da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10411da177e4SLinus Torvalds } 10421da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 1043e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10441da177e4SLinus Torvalds if (owner_grouplen < 0) { 1045fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1046e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 10471da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10481da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10491da177e4SLinus Torvalds /* goto out; */ 10501da177e4SLinus Torvalds } 1051d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 10521da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10531da177e4SLinus Torvalds } 1054d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1055d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10561da177e4SLinus Torvalds len += 16; 1057d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1058d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10591da177e4SLinus Torvalds len += 4; 1060d7067b2dSTrond Myklebust } 1061d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1062d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10631da177e4SLinus Torvalds len += 16; 1064d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1065d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10661da177e4SLinus Torvalds len += 4; 1067d7067b2dSTrond Myklebust } 1068b4a2cf76STrond Myklebust if (label) { 1069b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1070d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1071d7067b2dSTrond Myklebust } 1072d7067b2dSTrond Myklebust 1073d7067b2dSTrond Myklebust if (bmval[2] != 0) 1074b4a2cf76STrond Myklebust bmval_len = 3; 1075d7067b2dSTrond Myklebust else if (bmval[1] != 0) 1076d7067b2dSTrond Myklebust bmval_len = 2; 1077d7067b2dSTrond Myklebust else 1078d7067b2dSTrond Myklebust bmval_len = 1; 1079b4a2cf76STrond Myklebust 1080d7067b2dSTrond Myklebust p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len); 10811da177e4SLinus Torvalds 1082b4a2cf76STrond Myklebust *p++ = cpu_to_be32(bmval_len); 1083d7067b2dSTrond Myklebust for (i = 0; i < bmval_len; i++) 1084d7067b2dSTrond Myklebust *p++ = cpu_to_be32(bmval[i]); 1085d7067b2dSTrond Myklebust *p++ = cpu_to_be32(len); 10861da177e4SLinus Torvalds 1087d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1088b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1089d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1090e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1091d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1092811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1093d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1094811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1095d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 10961da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1097e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1098042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec); 1099d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 1100d7067b2dSTrond Myklebust } else 1101e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11021da177e4SLinus Torvalds } 1103d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11041da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1105e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1106042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec); 1107e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 1108d7067b2dSTrond Myklebust } else 1109e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11101da177e4SLinus Torvalds } 1111d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1112aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1113aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1114aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1115aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1116aa9c2669SDavid Quigley } 11171da177e4SLinus Torvalds 11181da177e4SLinus Torvalds /* out: */ 11191da177e4SLinus Torvalds } 11201da177e4SLinus Torvalds 1121cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11221da177e4SLinus Torvalds { 1123475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1124475d4ba0STrond Myklebust encode_uint32(xdr, access); 11251da177e4SLinus Torvalds } 11261da177e4SLinus Torvalds 1127cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11281da177e4SLinus Torvalds { 1129ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11304ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1131566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11321da177e4SLinus Torvalds } 11331da177e4SLinus Torvalds 11340b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11351da177e4SLinus Torvalds { 11368687b63aSAl Viro __be32 *p; 11371da177e4SLinus Torvalds 1138475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1139475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1140b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 114134558513SBenny Halevy *p = cpu_to_be32(args->count); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds 1144cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11451da177e4SLinus Torvalds { 11468687b63aSAl Viro __be32 *p; 11471da177e4SLinus Torvalds 1148475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1149475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11501da177e4SLinus Torvalds 11511da177e4SLinus Torvalds switch (create->ftype) { 11521da177e4SLinus Torvalds case NF4LNK: 115313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 115434558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 115594a6d753SChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len); 11561da177e4SLinus Torvalds break; 11571da177e4SLinus Torvalds 11581da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 115913c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1160e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 116134558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11621da177e4SLinus Torvalds break; 11631da177e4SLinus Torvalds 11641da177e4SLinus Torvalds default: 11651da177e4SLinus Torvalds break; 11661da177e4SLinus Torvalds } 11671da177e4SLinus Torvalds 1168811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 1169aa9c2669SDavid Quigley encode_attrs(xdr, create->attrs, create->label, create->server); 11701da177e4SLinus Torvalds } 11711da177e4SLinus Torvalds 1172cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11731da177e4SLinus Torvalds { 11748687b63aSAl Viro __be32 *p; 11751da177e4SLinus Torvalds 1176475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1177475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1178e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 117934558513SBenny Halevy *p = cpu_to_be32(bitmap); 11801da177e4SLinus Torvalds } 11811da177e4SLinus Torvalds 1182cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 11831da177e4SLinus Torvalds { 11848687b63aSAl Viro __be32 *p; 11851da177e4SLinus Torvalds 1186475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1187475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1188e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1189e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 119034558513SBenny Halevy *p = cpu_to_be32(bm1); 11911da177e4SLinus Torvalds } 11921da177e4SLinus Torvalds 1193dae100c2SFred Isaman static void 1194dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1195dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1196dae100c2SFred Isaman struct compound_hdr *hdr) 1197dae100c2SFred Isaman { 1198dae100c2SFred Isaman __be32 *p; 1199dae100c2SFred Isaman 1200ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1201dae100c2SFred Isaman if (bm2) { 1202dae100c2SFred Isaman p = reserve_space(xdr, 16); 1203dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1204dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1205dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1206dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1207dae100c2SFred Isaman } else if (bm1) { 1208dae100c2SFred Isaman p = reserve_space(xdr, 12); 1209dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1210dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1211dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1212dae100c2SFred Isaman } else { 1213dae100c2SFred Isaman p = reserve_space(xdr, 8); 1214dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1215dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1216dae100c2SFred Isaman } 1217dae100c2SFred Isaman } 1218dae100c2SFred Isaman 1219cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12201da177e4SLinus Torvalds { 1221a09df2caSDavid Quigley encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1222a09df2caSDavid Quigley bitmask[1] & nfs4_fattr_bitmap[1], 1223a09df2caSDavid Quigley bitmask[2] & nfs4_fattr_bitmap[2], 1224a09df2caSDavid Quigley hdr); 12251da177e4SLinus Torvalds } 12261da177e4SLinus Torvalds 122788034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12281549210fSTrond Myklebust const u32 *open_bitmap, 122988034c3dSAndy Adamson struct compound_hdr *hdr) 123088034c3dSAndy Adamson { 123188034c3dSAndy Adamson encode_getattr_three(xdr, 12321549210fSTrond Myklebust bitmask[0] & open_bitmap[0], 12331549210fSTrond Myklebust bitmask[1] & open_bitmap[1], 12341549210fSTrond Myklebust bitmask[2] & open_bitmap[2], 123588034c3dSAndy Adamson hdr); 123688034c3dSAndy Adamson } 123788034c3dSAndy Adamson 1238cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12391da177e4SLinus Torvalds { 1240dae100c2SFred Isaman encode_getattr_three(xdr, 1241dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1242dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1243dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1244dae100c2SFred Isaman hdr); 12451da177e4SLinus Torvalds } 12461da177e4SLinus Torvalds 1247cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1248830b8e33SManoj Naik { 1249cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1250cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1251830b8e33SManoj Naik } 1252830b8e33SManoj Naik 1253cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12541da177e4SLinus Torvalds { 1255ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12561da177e4SLinus Torvalds } 12571da177e4SLinus Torvalds 1258cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12591da177e4SLinus Torvalds { 1260ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12616fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12621da177e4SLinus Torvalds } 12631da177e4SLinus Torvalds 1264911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1265911d1aafSTrond Myklebust { 1266f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1267911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1268911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1269911d1aafSTrond Myklebust } 1270911d1aafSTrond Myklebust 1271911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1272911d1aafSTrond Myklebust { 1273911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1274911d1aafSTrond Myklebust return ~(uint64_t)0; 1275911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1276911d1aafSTrond Myklebust } 1277911d1aafSTrond Myklebust 1278daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1279daccbdedSTrond Myklebust { 1280daccbdedSTrond Myklebust __be32 *p; 1281daccbdedSTrond Myklebust 1282d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1283daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1284d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1285daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1286d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1287daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1288daccbdedSTrond Myklebust } 1289daccbdedSTrond Myklebust 12901da177e4SLinus Torvalds /* 12911da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 12921da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 12931da177e4SLinus Torvalds */ 1294cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 12951da177e4SLinus Torvalds { 12968687b63aSAl Viro __be32 *p; 12971da177e4SLinus Torvalds 1298475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1299475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1300e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1301e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1302b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1303b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 130434558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1305911d1aafSTrond Myklebust if (args->new_lock_owner){ 13064ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1307ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->open_stateid); 13084ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1309daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13101da177e4SLinus Torvalds } 13111da177e4SLinus Torvalds else { 1312ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->lock_stateid); 13134ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13141da177e4SLinus Torvalds } 13151da177e4SLinus Torvalds } 13161da177e4SLinus Torvalds 1317cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13181da177e4SLinus Torvalds { 13198687b63aSAl Viro __be32 *p; 13201da177e4SLinus Torvalds 1321475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1322475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1323e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1324b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1325b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1326daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13271da177e4SLinus Torvalds } 13281da177e4SLinus Torvalds 1329cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13301da177e4SLinus Torvalds { 13318687b63aSAl Viro __be32 *p; 13321da177e4SLinus Torvalds 1333475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1334475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13354ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1336ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 1337ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1338b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 133934558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13401da177e4SLinus Torvalds } 13411da177e4SLinus Torvalds 1342d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1343d3c7b7ccSTrond Myklebust { 1344ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1345d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1346d3c7b7ccSTrond Myklebust } 1347d3c7b7ccSTrond Myklebust 1348cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13491da177e4SLinus Torvalds { 1350ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13516fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13521da177e4SLinus Torvalds } 13531da177e4SLinus Torvalds 1354dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 13551da177e4SLinus Torvalds { 13568687b63aSAl Viro __be32 *p; 13571da177e4SLinus Torvalds 135813c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1359dc0b027dSTrond Myklebust switch (fmode & (FMODE_READ|FMODE_WRITE)) { 13601da177e4SLinus Torvalds case FMODE_READ: 1361e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); 13621da177e4SLinus Torvalds break; 13631da177e4SLinus Torvalds case FMODE_WRITE: 1364e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); 13651da177e4SLinus Torvalds break; 13661da177e4SLinus Torvalds case FMODE_READ|FMODE_WRITE: 1367e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); 13681da177e4SLinus Torvalds break; 13691da177e4SLinus Torvalds default: 1370e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); 13711da177e4SLinus Torvalds } 137234558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13731da177e4SLinus Torvalds } 13741da177e4SLinus Torvalds 13751da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13761da177e4SLinus Torvalds { 13778687b63aSAl Viro __be32 *p; 13781da177e4SLinus Torvalds /* 13791da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13801da177e4SLinus Torvalds * owner 4 = 32 13811da177e4SLinus Torvalds */ 13824ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1383dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 138495b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1385b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 138695b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 138793f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1388d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 138995b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 139095b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 13911da177e4SLinus Torvalds } 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13941da177e4SLinus Torvalds { 1395549b19ccSTrond Myklebust struct iattr dummy; 13968687b63aSAl Viro __be32 *p; 13971da177e4SLinus Torvalds 139813c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1399549b19ccSTrond Myklebust switch(arg->createmode) { 1400549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 140134558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 1402aa9c2669SDavid Quigley encode_attrs(xdr, arg->u.attrs, arg->label, arg->server); 14031da177e4SLinus Torvalds break; 1404549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14054882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 1406aa9c2669SDavid Quigley encode_attrs(xdr, arg->u.attrs, arg->label, arg->server); 1407549b19ccSTrond Myklebust break; 1408549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1409549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1410549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1411549b19ccSTrond Myklebust break; 1412549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14134882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14144882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 14154882ef72SAlexandros Batsakis dummy.ia_valid = 0; 1416aa9c2669SDavid Quigley encode_attrs(xdr, &dummy, arg->label, arg->server); 14174882ef72SAlexandros Batsakis } 14184882ef72SAlexandros Batsakis } 14191da177e4SLinus Torvalds 14201da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14211da177e4SLinus Torvalds { 14228687b63aSAl Viro __be32 *p; 14231da177e4SLinus Torvalds 142413c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14251da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14261da177e4SLinus Torvalds case 0: 142734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14281da177e4SLinus Torvalds break; 14291da177e4SLinus Torvalds default: 143034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14311da177e4SLinus Torvalds encode_createmode(xdr, arg); 14321da177e4SLinus Torvalds } 14331da177e4SLinus Torvalds } 14341da177e4SLinus Torvalds 1435bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14361da177e4SLinus Torvalds { 14378687b63aSAl Viro __be32 *p; 14381da177e4SLinus Torvalds 143913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14401da177e4SLinus Torvalds switch (delegation_type) { 14411da177e4SLinus Torvalds case 0: 144234558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14431da177e4SLinus Torvalds break; 14441da177e4SLinus Torvalds case FMODE_READ: 144534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14461da177e4SLinus Torvalds break; 14471da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 144834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14491da177e4SLinus Torvalds break; 14501da177e4SLinus Torvalds default: 14511da177e4SLinus Torvalds BUG(); 14521da177e4SLinus Torvalds } 14531da177e4SLinus Torvalds } 14541da177e4SLinus Torvalds 14551da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14561da177e4SLinus Torvalds { 14578687b63aSAl Viro __be32 *p; 14581da177e4SLinus Torvalds 145913c65ce9SBenny Halevy p = reserve_space(xdr, 4); 146034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14611da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14621da177e4SLinus Torvalds } 14631da177e4SLinus Torvalds 1464bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14651da177e4SLinus Torvalds { 14668687b63aSAl Viro __be32 *p; 14671da177e4SLinus Torvalds 146813c65ce9SBenny Halevy p = reserve_space(xdr, 4); 146934558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14701da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14711da177e4SLinus Torvalds } 14721da177e4SLinus Torvalds 14731da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14741da177e4SLinus Torvalds { 14758687b63aSAl Viro __be32 *p; 14761da177e4SLinus Torvalds 1477ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1478ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1479ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14801da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14811da177e4SLinus Torvalds } 14821da177e4SLinus Torvalds 1483d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1484d9fc6619STrond Myklebust { 1485d9fc6619STrond Myklebust __be32 *p; 1486d9fc6619STrond Myklebust 1487d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1488d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1489d9fc6619STrond Myklebust } 1490d9fc6619STrond Myklebust 1491d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1492d9fc6619STrond Myklebust { 1493d9fc6619STrond Myklebust __be32 *p; 1494d9fc6619STrond Myklebust 1495d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1496d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1497d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1498d9fc6619STrond Myklebust } 1499d9fc6619STrond Myklebust 1500cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15011da177e4SLinus Torvalds { 1502ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15031da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15041da177e4SLinus Torvalds encode_opentype(xdr, arg); 15051da177e4SLinus Torvalds switch (arg->claim) { 15061da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15071da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15081da177e4SLinus Torvalds break; 15091da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15101da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15111da177e4SLinus Torvalds break; 15121da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15131da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15141da177e4SLinus Torvalds break; 1515d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1516d9fc6619STrond Myklebust encode_claim_fh(xdr); 1517d9fc6619STrond Myklebust break; 1518d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1519d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1520d9fc6619STrond Myklebust break; 15211da177e4SLinus Torvalds default: 15221da177e4SLinus Torvalds BUG(); 15231da177e4SLinus Torvalds } 15241da177e4SLinus Torvalds } 15251da177e4SLinus Torvalds 1526cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15271da177e4SLinus Torvalds { 1528ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1529ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15304ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds 1533cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15341da177e4SLinus Torvalds { 1535ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1536566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15374ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1538dc0b027dSTrond Myklebust encode_share_access(xdr, arg->fmode); 15391da177e4SLinus Torvalds } 15401da177e4SLinus Torvalds 1541cf8cdbe5SAndy Adamson static void 1542d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15431da177e4SLinus Torvalds { 1544ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15456fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15461da177e4SLinus Torvalds } 15471da177e4SLinus Torvalds 1548cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15491da177e4SLinus Torvalds { 1550ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15511da177e4SLinus Torvalds } 15521da177e4SLinus Torvalds 15533c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15543c6b899cSAnna Schumaker struct compound_hdr *hdr) 15551da177e4SLinus Torvalds { 15568687b63aSAl Viro __be32 *p; 15571da177e4SLinus Torvalds 1558ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15599b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15601da177e4SLinus Torvalds 156113c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1562b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 156334558513SBenny Halevy *p = cpu_to_be32(args->count); 15641da177e4SLinus Torvalds } 15651da177e4SLinus Torvalds 1566cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15671da177e4SLinus Torvalds { 1568aa9c2669SDavid Quigley uint32_t attrs[3] = { 156928331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 157028331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 157128331a46STrond Myklebust }; 15726f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1573cd93710eSChuck Lever __be32 *p, verf[2]; 1574d204c5d2STrond Myklebust uint32_t attrlen = 0; 1575d204c5d2STrond Myklebust unsigned int i; 15761da177e4SLinus Torvalds 157782f2e547SBryan Schumaker if (readdir->plus) { 157882f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 157928331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 158082f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 158182f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 158282f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 158382f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1584d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 15856f7a35bdSTrond Myklebust dircount >>= 1; 158682f2e547SBryan Schumaker } 158728331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 158828331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 158928331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1590d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1591d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1592d204c5d2STrond Myklebust if (attrs[i] != 0) 1593d204c5d2STrond Myklebust attrlen = i+1; 1594d204c5d2STrond Myklebust } 15956f7a35bdSTrond Myklebust 1596475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1597ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1598cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1599d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16006f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16016f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1602d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1603d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1604d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1605cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1606aa9c2669SDavid Quigley 1607aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 160844109241SFred Isaman __func__, 1609eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1610cd93710eSChuck Lever verf[0], verf[1], 1611eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1612aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1613aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16141da177e4SLinus Torvalds } 16151da177e4SLinus Torvalds 1616cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16171da177e4SLinus Torvalds { 1618ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16191da177e4SLinus Torvalds } 16201da177e4SLinus Torvalds 1621cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16221da177e4SLinus Torvalds { 1623ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16246fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds 1627cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16281da177e4SLinus Torvalds { 1629ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1630811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1631811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16321da177e4SLinus Torvalds } 16331da177e4SLinus Torvalds 1634bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1635bb4dae5eSChuck Lever struct compound_hdr *hdr) 16361da177e4SLinus Torvalds { 1637475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1638ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16391da177e4SLinus Torvalds } 16401da177e4SLinus Torvalds 1641cf8cdbe5SAndy Adamson static void 1642d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 164356ae19f3STrond Myklebust { 1644ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 164556ae19f3STrond Myklebust } 164656ae19f3STrond Myklebust 16479f06c719SChuck Lever static void 1648d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 164923ec6965SJ. Bruce Fields { 16508687b63aSAl Viro __be32 *p; 165123ec6965SJ. Bruce Fields 1652ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1653ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 165413c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1655e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 165634558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 165713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 165834558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 165923ec6965SJ. Bruce Fields xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 166023ec6965SJ. Bruce Fields } 166123ec6965SJ. Bruce Fields 1662cf8cdbe5SAndy Adamson static void 1663d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16641da177e4SLinus Torvalds { 1665ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16661da177e4SLinus Torvalds } 16671da177e4SLinus Torvalds 1668cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16691da177e4SLinus Torvalds { 1670ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1671ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 1672aa9c2669SDavid Quigley encode_attrs(xdr, arg->iap, arg->label, server); 16731da177e4SLinus Torvalds } 16741da177e4SLinus Torvalds 1675cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16761da177e4SLinus Torvalds { 16778687b63aSAl Viro __be32 *p; 16781da177e4SLinus Torvalds 167970019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1680cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16811da177e4SLinus Torvalds 16821da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 168313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 168434558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16851da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16861da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 168713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 168834558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_cb_ident); 16891da177e4SLinus Torvalds } 16901da177e4SLinus Torvalds 1691bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 16921da177e4SLinus Torvalds { 1693475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1694475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1695ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1696cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 16971da177e4SLinus Torvalds } 16981da177e4SLinus Torvalds 16993c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17003c6b899cSAnna Schumaker struct compound_hdr *hdr) 17011da177e4SLinus Torvalds { 17028687b63aSAl Viro __be32 *p; 17031da177e4SLinus Torvalds 1704ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17059b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17061da177e4SLinus Torvalds 170713c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1708b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1709e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 171034558513SBenny Halevy *p = cpu_to_be32(args->count); 17111da177e4SLinus Torvalds 17121da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17131da177e4SLinus Torvalds } 17141da177e4SLinus Torvalds 1715cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17161da177e4SLinus Torvalds { 1717ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1718ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17191da177e4SLinus Torvalds } 17209b7b9fccSAndy Adamson 17215a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17225a5ea0d4SBryan Schumaker { 1723ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17246fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17255a5ea0d4SBryan Schumaker } 17265a5ea0d4SBryan Schumaker 172799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17289b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17297c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 17307c44f1aeSWeston Andros Adamson struct nfs4_session *session, 17317c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17327c44f1aeSWeston Andros Adamson { 17337c44f1aeSWeston Andros Adamson __be32 *p; 17347c44f1aeSWeston Andros Adamson 17357c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17367c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 17377c44f1aeSWeston Andros Adamson encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 17387c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 17397c44f1aeSWeston Andros Adamson *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH); 17407c44f1aeSWeston Andros Adamson *p = 0; /* use_conn_in_rdma_mode = False */ 17417c44f1aeSWeston Andros Adamson } 17427c44f1aeSWeston Andros Adamson 17432031cd1aSWeston Andros Adamson static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 17442031cd1aSWeston Andros Adamson { 17452031cd1aSWeston Andros Adamson unsigned int i; 17462031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17472031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17482031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17492031cd1aSWeston Andros Adamson } 17502031cd1aSWeston Andros Adamson 175199fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 175299fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 175399fe60d0SBenny Halevy struct compound_hdr *hdr) 175499fe60d0SBenny Halevy { 175599fe60d0SBenny Halevy __be32 *p; 1756d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1757db8ac8baSWeston Andros Adamson int len = 0; 175899fe60d0SBenny Halevy 175970019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1760cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 176199fe60d0SBenny Halevy 176299fe60d0SBenny Halevy encode_string(xdr, args->id_len, args->id); 176399fe60d0SBenny Halevy 17642031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17652031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17662031cd1aSWeston Andros Adamson 17672031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17682031cd1aSWeston Andros Adamson case SP4_NONE: 17692031cd1aSWeston Andros Adamson break; 17702031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17712031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 17722031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 17732031cd1aSWeston Andros Adamson break; 17742031cd1aSWeston Andros Adamson default: 17752031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 17762031cd1aSWeston Andros Adamson break; 17772031cd1aSWeston Andros Adamson } 1778db8ac8baSWeston Andros Adamson 1779db8ac8baSWeston Andros Adamson if (send_implementation_id && 1780db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1781db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1782d751f748SJim Rees <= sizeof(impl_name) + 1) 1783db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1784db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1785db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1786db8ac8baSWeston Andros Adamson 1787db8ac8baSWeston Andros Adamson if (len > 0) { 17882031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1789db8ac8baSWeston Andros Adamson 1790db8ac8baSWeston Andros Adamson encode_string(xdr, 1791db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1792db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1793db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1794db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1795db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1796db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1797db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1798db8ac8baSWeston Andros Adamson } else 17992031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 180099fe60d0SBenny Halevy } 1801fc931582SAndy Adamson 1802fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1803fc931582SAndy Adamson struct nfs41_create_session_args *args, 1804fc931582SAndy Adamson struct compound_hdr *hdr) 1805fc931582SAndy Adamson { 1806fc931582SAndy Adamson __be32 *p; 1807fc931582SAndy Adamson char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; 1808fc931582SAndy Adamson uint32_t len; 1809fc931582SAndy Adamson struct nfs_client *clp = args->client; 1810f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18118e0d46e1SMike Sager u32 max_resp_sz_cached; 18128e0d46e1SMike Sager 18138e0d46e1SMike Sager /* 18148e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18158e0d46e1SMike Sager * 2 is the verifier. 18168e0d46e1SMike Sager */ 18178e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 18188e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1819fc931582SAndy Adamson 1820fc931582SAndy Adamson len = scnprintf(machine_name, sizeof(machine_name), "%s", 1821fc931582SAndy Adamson clp->cl_ipaddr); 182242edd698SBenny Halevy 1823475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 1824475d4ba0STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12); 1825114f64b5SAndy Adamson p = xdr_encode_hyper(p, clp->cl_clientid); 1826e75bc1c8SBenny Halevy *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1827e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1828fc931582SAndy Adamson 1829fc931582SAndy Adamson /* Fore Channel */ 1830c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1831e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1832e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18338e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1834e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1835e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1836e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1837fc931582SAndy Adamson 1838fc931582SAndy Adamson /* Back Channel */ 1839c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1840e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1841e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1842e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1843e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1844e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1845e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1846fc931582SAndy Adamson 1847e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1848e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1849e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1850fc931582SAndy Adamson 1851fc931582SAndy Adamson /* authsys_parms rfc1831 */ 185217f26b12STrond Myklebust *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */ 1853811652bdSBenny Halevy p = xdr_encode_opaque(p, machine_name, len); 1854e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 185634558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1857fc931582SAndy Adamson } 18580f3e66c6SAndy Adamson 18590f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 18600f3e66c6SAndy Adamson struct nfs4_session *session, 18610f3e66c6SAndy Adamson struct compound_hdr *hdr) 18620f3e66c6SAndy Adamson { 1863475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1864475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18650f3e66c6SAndy Adamson } 186618019753SRicardo Labiaga 186766245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 186866245539STrond Myklebust uint64_t clientid, 186966245539STrond Myklebust struct compound_hdr *hdr) 187066245539STrond Myklebust { 187166245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 187266245539STrond Myklebust encode_uint64(xdr, clientid); 187366245539STrond Myklebust } 187466245539STrond Myklebust 187518019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 187618019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 187718019753SRicardo Labiaga struct compound_hdr *hdr) 187818019753SRicardo Labiaga { 1879475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1880475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 188118019753SRicardo Labiaga } 188299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 188399fe60d0SBenny Halevy 18849b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18859b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18869b7b9fccSAndy Adamson struct compound_hdr *hdr) 18879b7b9fccSAndy Adamson { 18889b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18892b2fa717STrond Myklebust struct nfs4_session *session; 1890fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 18912b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1892fc01cea9SAndy Adamson __be32 *p; 18939b7b9fccSAndy Adamson 18942b2fa717STrond Myklebust tp = slot->table; 18952b2fa717STrond Myklebust session = tp->session; 18963bd2384aSChuck Lever if (!session) 18973bd2384aSChuck Lever return; 1898fc01cea9SAndy Adamson 1899475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1900fc01cea9SAndy Adamson 1901fc01cea9SAndy Adamson /* 1902fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1903fc01cea9SAndy Adamson */ 1904fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1905fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1906fc01cea9SAndy Adamson __func__, 1907fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1908fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1909fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1910fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19112b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1912fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1913475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 191493f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1915e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19162b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1917e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 191834558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19199b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19209b7b9fccSAndy Adamson } 19219b7b9fccSAndy Adamson 1922b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1923b1f69b75SAndy Adamson static void 1924b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1925b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1926b1f69b75SAndy Adamson struct compound_hdr *hdr) 1927b1f69b75SAndy Adamson { 1928b1f69b75SAndy Adamson __be32 *p; 1929b1f69b75SAndy Adamson 1930475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 193184c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1932b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1933b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1934b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1935f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 193684c9dee3SChristoph Hellwig 193784c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 193884c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 193984c9dee3SChristoph Hellwig *p++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE); 1940b1f69b75SAndy Adamson } 1941b1f69b75SAndy Adamson 1942b1f69b75SAndy Adamson static void 1943b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1944b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1945b1f69b75SAndy Adamson struct compound_hdr *hdr) 1946b1f69b75SAndy Adamson { 1947b1f69b75SAndy Adamson __be32 *p; 1948b1f69b75SAndy Adamson 1949475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1950475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1951b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1952b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1953b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1954b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1955b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1956b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1957ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1958475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1959b1f69b75SAndy Adamson 1960b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1961b1f69b75SAndy Adamson __func__, 1962b1f69b75SAndy Adamson args->type, 1963b1f69b75SAndy Adamson args->range.iomode, 1964b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1965b1f69b75SAndy Adamson (unsigned long)args->range.length, 1966b1f69b75SAndy Adamson args->maxcount); 1967b1f69b75SAndy Adamson } 1968863a3c6cSAndy Adamson 1969863a3c6cSAndy Adamson static int 1970863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1971ac7db726SBenny Halevy struct inode *inode, 19725f919c9fSChristoph Hellwig struct nfs4_layoutcommit_args *args, 1973863a3c6cSAndy Adamson struct compound_hdr *hdr) 1974863a3c6cSAndy Adamson { 1975863a3c6cSAndy Adamson __be32 *p; 1976863a3c6cSAndy Adamson 1977863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1978863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1979863a3c6cSAndy Adamson 1980475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1981475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1982863a3c6cSAndy Adamson /* Only whole file layouts */ 1983863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19843557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1985ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1986ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1987ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1988863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1989863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 1990863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1991863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 1992ac7db726SBenny Halevy 19935f919c9fSChristoph Hellwig if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) { 1994ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1995ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 19965f919c9fSChristoph Hellwig } else { 19975f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 19985f919c9fSChristoph Hellwig if (args->layoutupdate_pages) { 19995f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20005f919c9fSChristoph Hellwig args->layoutupdate_len); 20015f919c9fSChristoph Hellwig } 20025f919c9fSChristoph Hellwig } 2003863a3c6cSAndy Adamson 2004863a3c6cSAndy Adamson return 0; 2005863a3c6cSAndy Adamson } 2006cbe82603SBenny Halevy 2007cbe82603SBenny Halevy static void 2008cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2009cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2010cbe82603SBenny Halevy struct compound_hdr *hdr) 2011cbe82603SBenny Halevy { 2012cbe82603SBenny Halevy __be32 *p; 2013cbe82603SBenny Halevy 2014475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2015475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2016cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2017cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 2018cbe82603SBenny Halevy *p++ = cpu_to_be32(IOMODE_ANY); 2019cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2020ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 2021cbe82603SBenny Halevy p = xdr_encode_hyper(p, 0); 2022cbe82603SBenny Halevy p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 2023cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2024ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2025cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 202604a55549SAndy Adamson if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 202704a55549SAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 202804a55549SAndy Adamson NFS_I(args->inode)->layout, xdr, args); 2029475d4ba0STrond Myklebust } else 2030475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2031cbe82603SBenny Halevy } 2032fca78d6dSBryan Schumaker 2033fca78d6dSBryan Schumaker static int 2034fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2035fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2036fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2037fca78d6dSBryan Schumaker { 2038475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2039475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2040fca78d6dSBryan Schumaker return 0; 2041fca78d6dSBryan Schumaker } 20427d974794SBryan Schumaker 20437d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 20447d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 20457d974794SBryan Schumaker struct compound_hdr *hdr) 20467d974794SBryan Schumaker { 2047475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2048475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2049ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20507d974794SBryan Schumaker } 20519aeda35fSBryan Schumaker 20529aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 20539aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 20549aeda35fSBryan Schumaker struct compound_hdr *hdr) 20559aeda35fSBryan Schumaker { 2056ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20577c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20589aeda35fSBryan Schumaker } 2059b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2060b1f69b75SAndy Adamson 20611da177e4SLinus Torvalds /* 20621da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20631da177e4SLinus Torvalds */ 20641da177e4SLinus Torvalds 206566cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 206666cc0429SBenny Halevy { 206766cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 20683bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 20693bd2384aSChuck Lever if (session) 20703bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 207166cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 207266cc0429SBenny Halevy return 0; 207366cc0429SBenny Halevy } 207466cc0429SBenny Halevy 20751da177e4SLinus Torvalds /* 20761da177e4SLinus Torvalds * Encode an ACCESS request 20771da177e4SLinus Torvalds */ 20789f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 20799f06c719SChuck Lever const struct nfs4_accessargs *args) 20801da177e4SLinus Torvalds { 20811da177e4SLinus Torvalds struct compound_hdr hdr = { 208266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 20831da177e4SLinus Torvalds }; 20841da177e4SLinus Torvalds 20859f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 20869f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 20879f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 20889f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 20899f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2090d017931cSAndy Adamson encode_nops(&hdr); 20911da177e4SLinus Torvalds } 20921da177e4SLinus Torvalds 20931da177e4SLinus Torvalds /* 20941da177e4SLinus Torvalds * Encode LOOKUP request 20951da177e4SLinus Torvalds */ 20969f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 20979f06c719SChuck Lever const struct nfs4_lookup_arg *args) 20981da177e4SLinus Torvalds { 20991da177e4SLinus Torvalds struct compound_hdr hdr = { 210066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21011da177e4SLinus Torvalds }; 21021da177e4SLinus Torvalds 21039f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21049f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21059f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21069f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21079f06c719SChuck Lever encode_getfh(xdr, &hdr); 21089f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2109d017931cSAndy Adamson encode_nops(&hdr); 21101da177e4SLinus Torvalds } 21111da177e4SLinus Torvalds 21121da177e4SLinus Torvalds /* 21131da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21141da177e4SLinus Torvalds */ 21159f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21169f06c719SChuck Lever struct xdr_stream *xdr, 21179f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 21181da177e4SLinus Torvalds { 21191da177e4SLinus Torvalds struct compound_hdr hdr = { 212066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21211da177e4SLinus Torvalds }; 21221da177e4SLinus Torvalds 21239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21249f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21259f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21269f06c719SChuck Lever encode_getfh(xdr, &hdr); 21279f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2128d017931cSAndy Adamson encode_nops(&hdr); 21291da177e4SLinus Torvalds } 21301da177e4SLinus Torvalds 21311da177e4SLinus Torvalds /* 21321da177e4SLinus Torvalds * Encode REMOVE request 21331da177e4SLinus Torvalds */ 21349f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 21359f06c719SChuck Lever const struct nfs_removeargs *args) 21361da177e4SLinus Torvalds { 21371da177e4SLinus Torvalds struct compound_hdr hdr = { 213866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21391da177e4SLinus Torvalds }; 21401da177e4SLinus Torvalds 21419f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21429f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21439f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21449f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2145d017931cSAndy Adamson encode_nops(&hdr); 21461da177e4SLinus Torvalds } 21471da177e4SLinus Torvalds 21481da177e4SLinus Torvalds /* 21491da177e4SLinus Torvalds * Encode RENAME request 21501da177e4SLinus Torvalds */ 21519f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 21529f06c719SChuck Lever const struct nfs_renameargs *args) 21531da177e4SLinus Torvalds { 21541da177e4SLinus Torvalds struct compound_hdr hdr = { 215566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21561da177e4SLinus Torvalds }; 21571da177e4SLinus Torvalds 21589f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21599f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21609f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21619f06c719SChuck Lever encode_savefh(xdr, &hdr); 21629f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21639f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2164d017931cSAndy Adamson encode_nops(&hdr); 21651da177e4SLinus Torvalds } 21661da177e4SLinus Torvalds 21671da177e4SLinus Torvalds /* 21681da177e4SLinus Torvalds * Encode LINK request 21691da177e4SLinus Torvalds */ 21709f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 21719f06c719SChuck Lever const struct nfs4_link_arg *args) 21721da177e4SLinus Torvalds { 21731da177e4SLinus Torvalds struct compound_hdr hdr = { 217466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21751da177e4SLinus Torvalds }; 21761da177e4SLinus Torvalds 21779f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21789f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21799f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21809f06c719SChuck Lever encode_savefh(xdr, &hdr); 21819f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 21829f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 21839f06c719SChuck Lever encode_restorefh(xdr, &hdr); 21849f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2185d017931cSAndy Adamson encode_nops(&hdr); 21861da177e4SLinus Torvalds } 21871da177e4SLinus Torvalds 21881da177e4SLinus Torvalds /* 21891da177e4SLinus Torvalds * Encode CREATE request 21901da177e4SLinus Torvalds */ 21919f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 21929f06c719SChuck Lever const struct nfs4_create_arg *args) 21931da177e4SLinus Torvalds { 21941da177e4SLinus Torvalds struct compound_hdr hdr = { 219566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21961da177e4SLinus Torvalds }; 21971da177e4SLinus Torvalds 21989f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21999f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22009f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22019f06c719SChuck Lever encode_create(xdr, args, &hdr); 22029f06c719SChuck Lever encode_getfh(xdr, &hdr); 22039f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2204d017931cSAndy Adamson encode_nops(&hdr); 22051da177e4SLinus Torvalds } 22061da177e4SLinus Torvalds 22071da177e4SLinus Torvalds /* 22081da177e4SLinus Torvalds * Encode SYMLINK request 22091da177e4SLinus Torvalds */ 22109f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 22119f06c719SChuck Lever const struct nfs4_create_arg *args) 22121da177e4SLinus Torvalds { 22139f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22141da177e4SLinus Torvalds } 22151da177e4SLinus Torvalds 22161da177e4SLinus Torvalds /* 22171da177e4SLinus Torvalds * Encode GETATTR request 22181da177e4SLinus Torvalds */ 22199f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 22209f06c719SChuck Lever const struct nfs4_getattr_arg *args) 22211da177e4SLinus Torvalds { 22221da177e4SLinus Torvalds struct compound_hdr hdr = { 222366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22241da177e4SLinus Torvalds }; 22251da177e4SLinus Torvalds 22269f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22279f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22289f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22299f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2230d017931cSAndy Adamson encode_nops(&hdr); 22311da177e4SLinus Torvalds } 22321da177e4SLinus Torvalds 22331da177e4SLinus Torvalds /* 22341da177e4SLinus Torvalds * Encode a CLOSE request 22351da177e4SLinus Torvalds */ 22369f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 22379f06c719SChuck Lever struct nfs_closeargs *args) 22381da177e4SLinus Torvalds { 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_close(xdr, args, &hdr); 22479f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2248d017931cSAndy Adamson encode_nops(&hdr); 22491da177e4SLinus Torvalds } 22501da177e4SLinus Torvalds 22511da177e4SLinus Torvalds /* 22521da177e4SLinus Torvalds * Encode an OPEN request 22531da177e4SLinus Torvalds */ 22549f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 22559f06c719SChuck Lever struct nfs_openargs *args) 22561da177e4SLinus Torvalds { 22571da177e4SLinus Torvalds struct compound_hdr hdr = { 225866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22591da177e4SLinus Torvalds }; 22601da177e4SLinus Torvalds 22619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22649f06c719SChuck Lever encode_open(xdr, args, &hdr); 22659f06c719SChuck Lever encode_getfh(xdr, &hdr); 2266ae2bb032SWeston Andros Adamson if (args->access) 22676168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 22681549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2269d017931cSAndy Adamson encode_nops(&hdr); 22701da177e4SLinus Torvalds } 22711da177e4SLinus Torvalds 22721da177e4SLinus Torvalds /* 22731da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 22741da177e4SLinus Torvalds */ 22759f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22769f06c719SChuck Lever struct xdr_stream *xdr, 22779f06c719SChuck Lever struct nfs_open_confirmargs *args) 22781da177e4SLinus Torvalds { 22791da177e4SLinus Torvalds struct compound_hdr hdr = { 2280d017931cSAndy Adamson .nops = 0, 22811da177e4SLinus Torvalds }; 22821da177e4SLinus Torvalds 22839f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22849f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22859f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2286d017931cSAndy Adamson encode_nops(&hdr); 22871da177e4SLinus Torvalds } 22881da177e4SLinus Torvalds 22891da177e4SLinus Torvalds /* 22901da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 22911da177e4SLinus Torvalds */ 22929f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 22939f06c719SChuck Lever struct xdr_stream *xdr, 22949f06c719SChuck Lever struct nfs_openargs *args) 22951da177e4SLinus Torvalds { 22961da177e4SLinus Torvalds struct compound_hdr hdr = { 229766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22981da177e4SLinus Torvalds }; 22991da177e4SLinus Torvalds 23009f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23019f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23029f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23039f06c719SChuck Lever encode_open(xdr, args, &hdr); 2304ae2bb032SWeston Andros Adamson if (args->access) 23056168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2306e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2307d017931cSAndy Adamson encode_nops(&hdr); 23081da177e4SLinus Torvalds } 23091da177e4SLinus Torvalds 23101da177e4SLinus Torvalds /* 23111da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23121da177e4SLinus Torvalds */ 23139f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23149f06c719SChuck Lever struct xdr_stream *xdr, 23159f06c719SChuck Lever struct nfs_closeargs *args) 23161da177e4SLinus Torvalds { 23171da177e4SLinus Torvalds struct compound_hdr hdr = { 231866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23191da177e4SLinus Torvalds }; 23201da177e4SLinus Torvalds 23219f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23229f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23239f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23249f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 23259f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2326d017931cSAndy Adamson encode_nops(&hdr); 23271da177e4SLinus Torvalds } 23281da177e4SLinus Torvalds 23291da177e4SLinus Torvalds /* 23301da177e4SLinus Torvalds * Encode a LOCK request 23311da177e4SLinus Torvalds */ 23329f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 23339f06c719SChuck Lever struct nfs_lock_args *args) 23341da177e4SLinus Torvalds { 23351da177e4SLinus Torvalds struct compound_hdr hdr = { 233666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23371da177e4SLinus Torvalds }; 23381da177e4SLinus Torvalds 23399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23419f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23429f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2343d017931cSAndy Adamson encode_nops(&hdr); 23441da177e4SLinus Torvalds } 23451da177e4SLinus Torvalds 23461da177e4SLinus Torvalds /* 23471da177e4SLinus Torvalds * Encode a LOCKT request 23481da177e4SLinus Torvalds */ 23499f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 23509f06c719SChuck Lever struct nfs_lockt_args *args) 23511da177e4SLinus Torvalds { 23521da177e4SLinus Torvalds struct compound_hdr hdr = { 235366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23541da177e4SLinus Torvalds }; 23551da177e4SLinus Torvalds 23569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23579f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23589f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23599f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2360d017931cSAndy Adamson encode_nops(&hdr); 23611da177e4SLinus Torvalds } 23621da177e4SLinus Torvalds 23631da177e4SLinus Torvalds /* 23641da177e4SLinus Torvalds * Encode a LOCKU request 23651da177e4SLinus Torvalds */ 23669f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 23679f06c719SChuck Lever struct nfs_locku_args *args) 23681da177e4SLinus Torvalds { 23691da177e4SLinus Torvalds struct compound_hdr hdr = { 237066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23711da177e4SLinus Torvalds }; 23721da177e4SLinus Torvalds 23739f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23749f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23759f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23769f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2377d017931cSAndy Adamson encode_nops(&hdr); 23781da177e4SLinus Torvalds } 23791da177e4SLinus Torvalds 23809f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 23819f06c719SChuck Lever struct xdr_stream *xdr, 23829f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2383d3c7b7ccSTrond Myklebust { 2384d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2385d3c7b7ccSTrond Myklebust .minorversion = 0, 2386d3c7b7ccSTrond Myklebust }; 2387d3c7b7ccSTrond Myklebust 23889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23899f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2390d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2391d3c7b7ccSTrond Myklebust } 2392d3c7b7ccSTrond Myklebust 23931da177e4SLinus Torvalds /* 23941da177e4SLinus Torvalds * Encode a READLINK request 23951da177e4SLinus Torvalds */ 23969f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 23979f06c719SChuck Lever const struct nfs4_readlink *args) 23981da177e4SLinus Torvalds { 23991da177e4SLinus Torvalds struct compound_hdr hdr = { 240066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24011da177e4SLinus Torvalds }; 24021da177e4SLinus Torvalds 24039f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24049f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24059f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24069f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2407e3a535e1STrond Myklebust 240828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2409e3a535e1STrond Myklebust args->pgbase, args->pglen); 2410d017931cSAndy Adamson encode_nops(&hdr); 24111da177e4SLinus Torvalds } 24121da177e4SLinus Torvalds 24131da177e4SLinus Torvalds /* 24141da177e4SLinus Torvalds * Encode a READDIR request 24151da177e4SLinus Torvalds */ 24169f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 24179f06c719SChuck Lever const struct nfs4_readdir_arg *args) 24181da177e4SLinus Torvalds { 24191da177e4SLinus Torvalds struct compound_hdr hdr = { 242066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24211da177e4SLinus Torvalds }; 24221da177e4SLinus Torvalds 24239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24249f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24259f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24269f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2427d6ac02dfSTrond Myklebust 242828f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2429d6ac02dfSTrond Myklebust args->pgbase, args->count); 2430d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 243128f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2432d6ac02dfSTrond Myklebust args->pgbase, args->count); 2433d017931cSAndy Adamson encode_nops(&hdr); 24341da177e4SLinus Torvalds } 24351da177e4SLinus Torvalds 24361da177e4SLinus Torvalds /* 24371da177e4SLinus Torvalds * Encode a READ request 24381da177e4SLinus Torvalds */ 24399f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 24403c6b899cSAnna Schumaker struct nfs_pgio_args *args) 24411da177e4SLinus Torvalds { 24421da177e4SLinus Torvalds struct compound_hdr hdr = { 244366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24441da177e4SLinus Torvalds }; 24451da177e4SLinus Torvalds 24469f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24479f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24489f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24499f06c719SChuck Lever encode_read(xdr, args, &hdr); 24501da177e4SLinus Torvalds 245128f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 24521da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 24534f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2454d017931cSAndy Adamson encode_nops(&hdr); 24551da177e4SLinus Torvalds } 24561da177e4SLinus Torvalds 24571da177e4SLinus Torvalds /* 24581da177e4SLinus Torvalds * Encode an SETATTR request 24591da177e4SLinus Torvalds */ 24609f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 24619f06c719SChuck Lever struct nfs_setattrargs *args) 24621da177e4SLinus Torvalds { 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_setattr(xdr, args, args->server, &hdr); 24719f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2472d017931cSAndy Adamson encode_nops(&hdr); 24731da177e4SLinus Torvalds } 24741da177e4SLinus Torvalds 24751da177e4SLinus Torvalds /* 2476029d105eSJ. Bruce Fields * Encode a GETACL request 2477029d105eSJ. Bruce Fields */ 24789f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2479029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2480029d105eSJ. Bruce Fields { 2481029d105eSJ. Bruce Fields struct compound_hdr hdr = { 248266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2483029d105eSJ. Bruce Fields }; 248428f56694SBenny Halevy uint32_t replen; 2485029d105eSJ. Bruce Fields 24869f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24879f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24889f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2489bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 24909f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2491cf8cdbe5SAndy Adamson 249228f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 2493029d105eSJ. Bruce Fields args->acl_pages, args->acl_pgbase, args->acl_len); 2494bf118a34SAndy Adamson 2495d017931cSAndy Adamson encode_nops(&hdr); 2496029d105eSJ. Bruce Fields } 2497029d105eSJ. Bruce Fields 2498029d105eSJ. Bruce Fields /* 24991da177e4SLinus Torvalds * Encode a WRITE request 25001da177e4SLinus Torvalds */ 25019f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 25023c6b899cSAnna Schumaker struct nfs_pgio_args *args) 25031da177e4SLinus Torvalds { 25041da177e4SLinus Torvalds struct compound_hdr hdr = { 250566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25061da177e4SLinus Torvalds }; 25071da177e4SLinus Torvalds 25089f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25099f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25109f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25119f06c719SChuck Lever encode_write(xdr, args, &hdr); 25124f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25137ffd1064SFred Isaman if (args->bitmask) 25149f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2515d017931cSAndy Adamson encode_nops(&hdr); 25161da177e4SLinus Torvalds } 25171da177e4SLinus Torvalds 25181da177e4SLinus Torvalds /* 25191da177e4SLinus Torvalds * a COMMIT request 25201da177e4SLinus Torvalds */ 25219f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 25220b7c0153SFred Isaman struct nfs_commitargs *args) 25231da177e4SLinus Torvalds { 25241da177e4SLinus Torvalds struct compound_hdr hdr = { 252566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25261da177e4SLinus Torvalds }; 25271da177e4SLinus Torvalds 25289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25299f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25309f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25319f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2532d017931cSAndy Adamson encode_nops(&hdr); 25331da177e4SLinus Torvalds } 25341da177e4SLinus Torvalds 25351da177e4SLinus Torvalds /* 25361da177e4SLinus Torvalds * FSINFO request 25371da177e4SLinus Torvalds */ 25389f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 25399f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 25401da177e4SLinus Torvalds { 25411da177e4SLinus Torvalds struct compound_hdr hdr = { 254266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25431da177e4SLinus Torvalds }; 25441da177e4SLinus Torvalds 25459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25479f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25489f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2549d017931cSAndy Adamson encode_nops(&hdr); 25501da177e4SLinus Torvalds } 25511da177e4SLinus Torvalds 25521da177e4SLinus Torvalds /* 25531da177e4SLinus Torvalds * a PATHCONF request 25541da177e4SLinus Torvalds */ 25559f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 25569f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 25571da177e4SLinus Torvalds { 25581da177e4SLinus Torvalds struct compound_hdr hdr = { 255966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25601da177e4SLinus Torvalds }; 25611da177e4SLinus Torvalds 25629f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25639f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25649f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25659f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2566d017931cSAndy Adamson &hdr); 2567d017931cSAndy Adamson encode_nops(&hdr); 25681da177e4SLinus Torvalds } 25691da177e4SLinus Torvalds 25701da177e4SLinus Torvalds /* 25711da177e4SLinus Torvalds * a STATFS request 25721da177e4SLinus Torvalds */ 25739f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 25749f06c719SChuck Lever const struct nfs4_statfs_arg *args) 25751da177e4SLinus Torvalds { 25761da177e4SLinus Torvalds struct compound_hdr hdr = { 257766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25781da177e4SLinus Torvalds }; 25791da177e4SLinus Torvalds 25809f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25819f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25829f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25839f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2584d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2585d017931cSAndy Adamson encode_nops(&hdr); 25861da177e4SLinus Torvalds } 25871da177e4SLinus Torvalds 25881da177e4SLinus Torvalds /* 25891da177e4SLinus Torvalds * GETATTR_BITMAP request 25901da177e4SLinus Torvalds */ 25919f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 25929f06c719SChuck Lever struct xdr_stream *xdr, 259343652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 25941da177e4SLinus Torvalds { 25951da177e4SLinus Torvalds struct compound_hdr hdr = { 259666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25971da177e4SLinus Torvalds }; 25981da177e4SLinus Torvalds 25999f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26009f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26019f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26029f06c719SChuck Lever encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2603264e6351SChuck Lever FATTR4_WORD0_FH_EXPIRE_TYPE| 26041da177e4SLinus Torvalds FATTR4_WORD0_LINK_SUPPORT| 26051da177e4SLinus Torvalds FATTR4_WORD0_SYMLINK_SUPPORT| 2606d017931cSAndy Adamson FATTR4_WORD0_ACLSUPPORT, &hdr); 2607d017931cSAndy Adamson encode_nops(&hdr); 26081da177e4SLinus Torvalds } 26091da177e4SLinus Torvalds 26101da177e4SLinus Torvalds /* 26111da177e4SLinus Torvalds * a RENEW request 26121da177e4SLinus Torvalds */ 26139f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 26149f06c719SChuck Lever struct nfs_client *clp) 26151da177e4SLinus Torvalds { 26161da177e4SLinus Torvalds struct compound_hdr hdr = { 2617d017931cSAndy Adamson .nops = 0, 26181da177e4SLinus Torvalds }; 26191da177e4SLinus Torvalds 26209f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2621bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2622d017931cSAndy Adamson encode_nops(&hdr); 26231da177e4SLinus Torvalds } 26241da177e4SLinus Torvalds 26251da177e4SLinus Torvalds /* 26261da177e4SLinus Torvalds * a SETCLIENTID request 26271da177e4SLinus Torvalds */ 26289f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 26299f06c719SChuck Lever struct xdr_stream *xdr, 26309f06c719SChuck Lever struct nfs4_setclientid *sc) 26311da177e4SLinus Torvalds { 26321da177e4SLinus Torvalds struct compound_hdr hdr = { 2633d017931cSAndy Adamson .nops = 0, 26341da177e4SLinus Torvalds }; 26351da177e4SLinus Torvalds 26369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26379f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2638d017931cSAndy Adamson encode_nops(&hdr); 26391da177e4SLinus Torvalds } 26401da177e4SLinus Torvalds 26411da177e4SLinus Torvalds /* 26421da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 26431da177e4SLinus Torvalds */ 26449f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 26459f06c719SChuck Lever struct xdr_stream *xdr, 26469f06c719SChuck Lever struct nfs4_setclientid_res *arg) 26471da177e4SLinus Torvalds { 26481da177e4SLinus Torvalds struct compound_hdr hdr = { 2649d017931cSAndy Adamson .nops = 0, 26501da177e4SLinus Torvalds }; 26511da177e4SLinus Torvalds 26529f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26539f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2654d017931cSAndy Adamson encode_nops(&hdr); 26551da177e4SLinus Torvalds } 26561da177e4SLinus Torvalds 26571da177e4SLinus Torvalds /* 26581da177e4SLinus Torvalds * DELEGRETURN request 26591da177e4SLinus Torvalds */ 26609f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 26619f06c719SChuck Lever struct xdr_stream *xdr, 26629f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 26631da177e4SLinus Torvalds { 26641da177e4SLinus Torvalds struct compound_hdr hdr = { 266566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26661da177e4SLinus Torvalds }; 26671da177e4SLinus Torvalds 26689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26709f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26719f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2672e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2673d017931cSAndy Adamson encode_nops(&hdr); 26741da177e4SLinus Torvalds } 26751da177e4SLinus Torvalds 26761da177e4SLinus Torvalds /* 2677683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2678683b57b4STrond Myklebust */ 26799f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 26809f06c719SChuck Lever struct xdr_stream *xdr, 26819f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2682683b57b4STrond Myklebust { 2683683b57b4STrond Myklebust struct compound_hdr hdr = { 268466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2685683b57b4STrond Myklebust }; 268628f56694SBenny Halevy uint32_t replen; 2687683b57b4STrond Myklebust 26889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26899f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2690b03d735bSChuck Lever if (args->migration) { 2691b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2692b03d735bSChuck Lever replen = hdr.replen; 2693b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2694b03d735bSChuck Lever if (args->renew) 2695b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2696b03d735bSChuck Lever } else { 26979f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 26989f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2699b03d735bSChuck Lever replen = hdr.replen; 27009f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2701b03d735bSChuck Lever } 2702cf8cdbe5SAndy Adamson 2703b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 270428f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2705683b57b4STrond Myklebust 0, PAGE_SIZE); 2706d017931cSAndy Adamson encode_nops(&hdr); 2707683b57b4STrond Myklebust } 2708683b57b4STrond Myklebust 27095a5ea0d4SBryan Schumaker /* 27105a5ea0d4SBryan Schumaker * Encode SECINFO request 27115a5ea0d4SBryan Schumaker */ 27125a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 27135a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 27145a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 27155a5ea0d4SBryan Schumaker { 27165a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 27175a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27185a5ea0d4SBryan Schumaker }; 27195a5ea0d4SBryan Schumaker 27205a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 27215a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 27225a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 27235a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 27245a5ea0d4SBryan Schumaker encode_nops(&hdr); 27255a5ea0d4SBryan Schumaker } 27265a5ea0d4SBryan Schumaker 272744c99933SChuck Lever /* 272844c99933SChuck Lever * Encode FSID_PRESENT request 272944c99933SChuck Lever */ 273044c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 273144c99933SChuck Lever struct xdr_stream *xdr, 273244c99933SChuck Lever struct nfs4_fsid_present_arg *args) 273344c99933SChuck Lever { 273444c99933SChuck Lever struct compound_hdr hdr = { 273544c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 273644c99933SChuck Lever }; 273744c99933SChuck Lever 273844c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 273944c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 274044c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 274144c99933SChuck Lever encode_getfh(xdr, &hdr); 274244c99933SChuck Lever if (args->renew) 274344c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 274444c99933SChuck Lever encode_nops(&hdr); 274544c99933SChuck Lever } 274644c99933SChuck Lever 274799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 274899fe60d0SBenny Halevy /* 27497c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 27507c44f1aeSWeston Andros Adamson */ 27517c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 27527c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 27537c44f1aeSWeston Andros Adamson struct nfs_client *clp) 27547c44f1aeSWeston Andros Adamson { 27557c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 27567c44f1aeSWeston Andros Adamson .minorversion = clp->cl_mvops->minor_version, 27577c44f1aeSWeston Andros Adamson }; 27587c44f1aeSWeston Andros Adamson 27597c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 27607c44f1aeSWeston Andros Adamson encode_bind_conn_to_session(xdr, clp->cl_session, &hdr); 27617c44f1aeSWeston Andros Adamson encode_nops(&hdr); 27627c44f1aeSWeston Andros Adamson } 27637c44f1aeSWeston Andros Adamson 27647c44f1aeSWeston Andros Adamson /* 276599fe60d0SBenny Halevy * EXCHANGE_ID request 276699fe60d0SBenny Halevy */ 27679f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 27689f06c719SChuck Lever struct xdr_stream *xdr, 276999fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 277099fe60d0SBenny Halevy { 277199fe60d0SBenny Halevy struct compound_hdr hdr = { 2772a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 277399fe60d0SBenny Halevy }; 277499fe60d0SBenny Halevy 27759f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27769f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 277799fe60d0SBenny Halevy encode_nops(&hdr); 277899fe60d0SBenny Halevy } 27792050f0ccSAndy Adamson 27802050f0ccSAndy Adamson /* 2781fc931582SAndy Adamson * a CREATE_SESSION request 2782fc931582SAndy Adamson */ 27839f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 27849f06c719SChuck Lever struct xdr_stream *xdr, 2785fc931582SAndy Adamson struct nfs41_create_session_args *args) 2786fc931582SAndy Adamson { 2787fc931582SAndy Adamson struct compound_hdr hdr = { 2788a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2789fc931582SAndy Adamson }; 2790fc931582SAndy Adamson 27919f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27929f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2793fc931582SAndy Adamson encode_nops(&hdr); 2794fc931582SAndy Adamson } 2795fc931582SAndy Adamson 2796fc931582SAndy Adamson /* 27970f3e66c6SAndy Adamson * a DESTROY_SESSION request 27980f3e66c6SAndy Adamson */ 27999f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 28009f06c719SChuck Lever struct xdr_stream *xdr, 28010f3e66c6SAndy Adamson struct nfs4_session *session) 28020f3e66c6SAndy Adamson { 28030f3e66c6SAndy Adamson struct compound_hdr hdr = { 2804a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 28050f3e66c6SAndy Adamson }; 28060f3e66c6SAndy Adamson 28079f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28089f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 28090f3e66c6SAndy Adamson encode_nops(&hdr); 28100f3e66c6SAndy Adamson } 28110f3e66c6SAndy Adamson 28120f3e66c6SAndy Adamson /* 281366245539STrond Myklebust * a DESTROY_CLIENTID request 281466245539STrond Myklebust */ 281566245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 281666245539STrond Myklebust struct xdr_stream *xdr, 281766245539STrond Myklebust struct nfs_client *clp) 281866245539STrond Myklebust { 281966245539STrond Myklebust struct compound_hdr hdr = { 282066245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 282166245539STrond Myklebust }; 282266245539STrond Myklebust 282366245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 282466245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 282566245539STrond Myklebust encode_nops(&hdr); 282666245539STrond Myklebust } 282766245539STrond Myklebust 282866245539STrond Myklebust /* 2829fc01cea9SAndy Adamson * a SEQUENCE request 2830fc01cea9SAndy Adamson */ 28319f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2832fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2833fc01cea9SAndy Adamson { 2834fc01cea9SAndy Adamson struct compound_hdr hdr = { 2835fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2836fc01cea9SAndy Adamson }; 2837fc01cea9SAndy Adamson 28389f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28399f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2840fc01cea9SAndy Adamson encode_nops(&hdr); 2841fc01cea9SAndy Adamson } 2842fc01cea9SAndy Adamson 2843fc01cea9SAndy Adamson /* 28442050f0ccSAndy Adamson * a GET_LEASE_TIME request 28452050f0ccSAndy Adamson */ 28469f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 28479f06c719SChuck Lever struct xdr_stream *xdr, 28482050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 28492050f0ccSAndy Adamson { 28502050f0ccSAndy Adamson struct compound_hdr hdr = { 28512050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 28522050f0ccSAndy Adamson }; 2853dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 28542050f0ccSAndy Adamson 28559f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28569f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 28579f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 28589f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 28592050f0ccSAndy Adamson encode_nops(&hdr); 28602050f0ccSAndy Adamson } 286118019753SRicardo Labiaga 286218019753SRicardo Labiaga /* 286318019753SRicardo Labiaga * a RECLAIM_COMPLETE request 286418019753SRicardo Labiaga */ 28659f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 28669f06c719SChuck Lever struct xdr_stream *xdr, 286718019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 286818019753SRicardo Labiaga { 286918019753SRicardo Labiaga struct compound_hdr hdr = { 287018019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 287118019753SRicardo Labiaga }; 287218019753SRicardo Labiaga 28739f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28749f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28759f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 287618019753SRicardo Labiaga encode_nops(&hdr); 287718019753SRicardo Labiaga } 287818019753SRicardo Labiaga 2879b1f69b75SAndy Adamson /* 2880b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2881b1f69b75SAndy Adamson */ 28829f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 28839f06c719SChuck Lever struct xdr_stream *xdr, 2884b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2885b1f69b75SAndy Adamson { 2886b1f69b75SAndy Adamson struct compound_hdr hdr = { 2887b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2888b1f69b75SAndy Adamson }; 2889b1f69b75SAndy Adamson 28909f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28919f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28929f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2893b1f69b75SAndy Adamson 2894b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2895b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2896b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2897b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2898b1f69b75SAndy Adamson args->pdev->pglen); 2899b1f69b75SAndy Adamson 2900b1f69b75SAndy Adamson encode_nops(&hdr); 2901b1f69b75SAndy Adamson } 2902b1f69b75SAndy Adamson 2903b1f69b75SAndy Adamson /* 2904b1f69b75SAndy Adamson * Encode LAYOUTGET request 2905b1f69b75SAndy Adamson */ 29069f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 29079f06c719SChuck Lever struct xdr_stream *xdr, 2908b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2909b1f69b75SAndy Adamson { 2910b1f69b75SAndy Adamson struct compound_hdr hdr = { 2911b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2912b1f69b75SAndy Adamson }; 2913b1f69b75SAndy Adamson 29149f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29159f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29169f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 29179f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 291835124a09SWeston Andros Adamson 291935124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 292035124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 292135124a09SWeston Andros Adamson 2922b1f69b75SAndy Adamson encode_nops(&hdr); 2923b1f69b75SAndy Adamson } 2924863a3c6cSAndy Adamson 2925863a3c6cSAndy Adamson /* 2926863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2927863a3c6cSAndy Adamson */ 2928cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2929863a3c6cSAndy Adamson struct xdr_stream *xdr, 2930863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2931863a3c6cSAndy Adamson { 2932ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2933ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2934863a3c6cSAndy Adamson struct compound_hdr hdr = { 2935863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2936863a3c6cSAndy Adamson }; 2937863a3c6cSAndy Adamson 2938863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2939863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2940863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2941ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2942863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2943863a3c6cSAndy Adamson encode_nops(&hdr); 2944cbe82603SBenny Halevy } 2945cbe82603SBenny Halevy 2946cbe82603SBenny Halevy /* 2947cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2948cbe82603SBenny Halevy */ 2949cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2950cbe82603SBenny Halevy struct xdr_stream *xdr, 2951cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2952cbe82603SBenny Halevy { 2953cbe82603SBenny Halevy struct compound_hdr hdr = { 2954cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2955cbe82603SBenny Halevy }; 2956cbe82603SBenny Halevy 2957cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2958cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2959cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2960cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2961cbe82603SBenny Halevy encode_nops(&hdr); 2962863a3c6cSAndy Adamson } 2963fca78d6dSBryan Schumaker 2964fca78d6dSBryan Schumaker /* 2965fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2966fca78d6dSBryan Schumaker */ 2967fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2968fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2969fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2970fca78d6dSBryan Schumaker { 2971fca78d6dSBryan Schumaker struct compound_hdr hdr = { 2972fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2973fca78d6dSBryan Schumaker }; 2974fca78d6dSBryan Schumaker 2975fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 2976fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 2977fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 2978fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 2979fca78d6dSBryan Schumaker encode_nops(&hdr); 2980fca78d6dSBryan Schumaker return 0; 2981fca78d6dSBryan Schumaker } 29827d974794SBryan Schumaker 29837d974794SBryan Schumaker /* 29847d974794SBryan Schumaker * Encode TEST_STATEID request 29857d974794SBryan Schumaker */ 29867d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 29877d974794SBryan Schumaker struct xdr_stream *xdr, 29887d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 29897d974794SBryan Schumaker { 29907d974794SBryan Schumaker struct compound_hdr hdr = { 29917d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 29927d974794SBryan Schumaker }; 29937d974794SBryan Schumaker 29947d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 29957d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 29967d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 29977d974794SBryan Schumaker encode_nops(&hdr); 29987d974794SBryan Schumaker } 29999aeda35fSBryan Schumaker 30009aeda35fSBryan Schumaker /* 30019aeda35fSBryan Schumaker * Encode FREE_STATEID request 30029aeda35fSBryan Schumaker */ 30039aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 30049aeda35fSBryan Schumaker struct xdr_stream *xdr, 30059aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 30069aeda35fSBryan Schumaker { 30079aeda35fSBryan Schumaker struct compound_hdr hdr = { 30089aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30099aeda35fSBryan Schumaker }; 30109aeda35fSBryan Schumaker 30119aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30129aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30139aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 30149aeda35fSBryan Schumaker encode_nops(&hdr); 30159aeda35fSBryan Schumaker } 301699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 301799fe60d0SBenny Halevy 3018686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3019686841b3SBenny Halevy { 3020686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3021686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3022686841b3SBenny Halevy func, xdr->end - xdr->p); 3023686841b3SBenny Halevy } 30241da177e4SLinus Torvalds 3025683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 30261da177e4SLinus Torvalds { 30278687b63aSAl Viro __be32 *p; 30281da177e4SLinus Torvalds 3029c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3030c0eae66eSBenny Halevy if (unlikely(!p)) 3031c0eae66eSBenny Halevy goto out_overflow; 3032cccddf4fSBenny Halevy *len = be32_to_cpup(p); 3033c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 3034c0eae66eSBenny Halevy if (unlikely(!p)) 3035c0eae66eSBenny Halevy goto out_overflow; 30361da177e4SLinus Torvalds *string = (char *)p; 30371da177e4SLinus Torvalds return 0; 3038c0eae66eSBenny Halevy out_overflow: 3039c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3040c0eae66eSBenny Halevy return -EIO; 30411da177e4SLinus Torvalds } 30421da177e4SLinus Torvalds 30431da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 30441da177e4SLinus Torvalds { 30458687b63aSAl Viro __be32 *p; 30461da177e4SLinus Torvalds 3047c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3048c0eae66eSBenny Halevy if (unlikely(!p)) 3049c0eae66eSBenny Halevy goto out_overflow; 30506f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3051cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 30521da177e4SLinus Torvalds 3053c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3054c0eae66eSBenny Halevy if (unlikely(!p)) 3055c0eae66eSBenny Halevy goto out_overflow; 30561da177e4SLinus Torvalds hdr->tag = (char *)p; 30571da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3058cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3059aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3060aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 30611da177e4SLinus Torvalds return 0; 3062c0eae66eSBenny Halevy out_overflow: 3063c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3064c0eae66eSBenny Halevy return -EIO; 30651da177e4SLinus Torvalds } 30661da177e4SLinus Torvalds 3067c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3068c7848f69STrond Myklebust int *nfs_retval) 30691da177e4SLinus Torvalds { 30708687b63aSAl Viro __be32 *p; 30711da177e4SLinus Torvalds uint32_t opnum; 30721da177e4SLinus Torvalds int32_t nfserr; 30731da177e4SLinus Torvalds 3074c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3075c0eae66eSBenny Halevy if (unlikely(!p)) 3076c0eae66eSBenny Halevy goto out_overflow; 30776f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3078c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3079c7848f69STrond Myklebust goto out_bad_operation; 3080c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3081c7848f69STrond Myklebust if (nfserr == NFS_OK) 3082c7848f69STrond Myklebust *nfs_retval = 0; 3083c7848f69STrond Myklebust else 3084c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3085c7848f69STrond Myklebust return true; 3086c7848f69STrond Myklebust out_bad_operation: 3087fe82a183SChuck Lever dprintk("nfs: Server returned operation" 30881da177e4SLinus Torvalds " %d but we issued a request for %d\n", 30891da177e4SLinus Torvalds opnum, expected); 3090c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3091c7848f69STrond Myklebust return false; 3092c0eae66eSBenny Halevy out_overflow: 3093c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3094c7848f69STrond Myklebust *nfs_retval = -EIO; 3095c7848f69STrond Myklebust return false; 3096c7848f69STrond Myklebust } 3097c7848f69STrond Myklebust 3098c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3099c7848f69STrond Myklebust { 3100c7848f69STrond Myklebust int retval; 3101c7848f69STrond Myklebust 3102c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3103c7848f69STrond Myklebust return retval; 31041da177e4SLinus Torvalds } 31051da177e4SLinus Torvalds 31061da177e4SLinus Torvalds /* Dummy routine */ 3107adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 31081da177e4SLinus Torvalds { 31098687b63aSAl Viro __be32 *p; 3110683b57b4STrond Myklebust unsigned int strlen; 31111da177e4SLinus Torvalds char *str; 31121da177e4SLinus Torvalds 3113c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3114c0eae66eSBenny Halevy if (likely(p)) 31151da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3116c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3117c0eae66eSBenny Halevy return -EIO; 31181da177e4SLinus Torvalds } 31191da177e4SLinus Torvalds 31201da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 31211da177e4SLinus Torvalds { 31228687b63aSAl Viro uint32_t bmlen; 31238687b63aSAl Viro __be32 *p; 31241da177e4SLinus Torvalds 3125c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3126c0eae66eSBenny Halevy if (unlikely(!p)) 3127c0eae66eSBenny Halevy goto out_overflow; 3128cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 31291da177e4SLinus Torvalds 3130dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3131c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3132c0eae66eSBenny Halevy if (unlikely(!p)) 3133c0eae66eSBenny Halevy goto out_overflow; 31341da177e4SLinus Torvalds if (bmlen > 0) { 31356f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3136dae100c2SFred Isaman if (bmlen > 1) { 3137dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3138dae100c2SFred Isaman if (bmlen > 2) 3139dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3140dae100c2SFred Isaman } 31411da177e4SLinus Torvalds } 31421da177e4SLinus Torvalds return 0; 3143c0eae66eSBenny Halevy out_overflow: 3144c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3145c0eae66eSBenny Halevy return -EIO; 31461da177e4SLinus Torvalds } 31471da177e4SLinus Torvalds 3148256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 31491da177e4SLinus Torvalds { 31508687b63aSAl Viro __be32 *p; 31511da177e4SLinus Torvalds 3152c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3153c0eae66eSBenny Halevy if (unlikely(!p)) 3154c0eae66eSBenny Halevy goto out_overflow; 3155cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3156256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 31571da177e4SLinus Torvalds return 0; 3158c0eae66eSBenny Halevy out_overflow: 3159c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3160c0eae66eSBenny Halevy return -EIO; 31611da177e4SLinus Torvalds } 31621da177e4SLinus Torvalds 31631da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 31641da177e4SLinus Torvalds { 31651da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 31663388bff5SRoman Borisov int ret; 31673388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 31683388bff5SRoman Borisov if (unlikely(ret < 0)) 31693388bff5SRoman Borisov return ret; 31701da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 31711da177e4SLinus Torvalds } else 3172dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3173dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3174dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 31751da177e4SLinus Torvalds return 0; 31761da177e4SLinus Torvalds } 31771da177e4SLinus Torvalds 31781da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 31791da177e4SLinus Torvalds { 31808687b63aSAl Viro __be32 *p; 3181409924e4STrond Myklebust int ret = 0; 31821da177e4SLinus Torvalds 31831da177e4SLinus Torvalds *type = 0; 31841da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 31851da177e4SLinus Torvalds return -EIO; 31861da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3187c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3188c0eae66eSBenny Halevy if (unlikely(!p)) 3189c0eae66eSBenny Halevy goto out_overflow; 3190cccddf4fSBenny Halevy *type = be32_to_cpup(p); 31911da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 31923110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 31931da177e4SLinus Torvalds return -EIO; 31941da177e4SLinus Torvalds } 31951da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3196409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 31971da177e4SLinus Torvalds } 3198bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3199409924e4STrond Myklebust return ret; 3200c0eae66eSBenny Halevy out_overflow: 3201c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3202c0eae66eSBenny Halevy return -EIO; 32031da177e4SLinus Torvalds } 32041da177e4SLinus Torvalds 3205264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3206264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3207264e6351SChuck Lever { 3208264e6351SChuck Lever __be32 *p; 3209264e6351SChuck Lever 3210264e6351SChuck Lever *type = 0; 3211264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3212264e6351SChuck Lever return -EIO; 3213264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3214264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3215264e6351SChuck Lever if (unlikely(!p)) 3216264e6351SChuck Lever goto out_overflow; 3217264e6351SChuck Lever *type = be32_to_cpup(p); 3218264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3219264e6351SChuck Lever } 3220264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3221264e6351SChuck Lever return 0; 3222264e6351SChuck Lever out_overflow: 3223264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3224264e6351SChuck Lever return -EIO; 3225264e6351SChuck Lever } 3226264e6351SChuck Lever 32271da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 32281da177e4SLinus Torvalds { 32298687b63aSAl Viro __be32 *p; 3230409924e4STrond Myklebust int ret = 0; 32311da177e4SLinus Torvalds 32321da177e4SLinus Torvalds *change = 0; 32331da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 32341da177e4SLinus Torvalds return -EIO; 32351da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3236c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3237c0eae66eSBenny Halevy if (unlikely(!p)) 3238c0eae66eSBenny Halevy goto out_overflow; 3239cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 32401da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3241409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 32421da177e4SLinus Torvalds } 32433110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 32441da177e4SLinus Torvalds (unsigned long long)*change); 3245409924e4STrond Myklebust return ret; 3246c0eae66eSBenny Halevy out_overflow: 3247c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3248c0eae66eSBenny Halevy return -EIO; 32491da177e4SLinus Torvalds } 32501da177e4SLinus Torvalds 32511da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 32521da177e4SLinus Torvalds { 32538687b63aSAl Viro __be32 *p; 3254409924e4STrond Myklebust int ret = 0; 32551da177e4SLinus Torvalds 32561da177e4SLinus Torvalds *size = 0; 32571da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 32581da177e4SLinus Torvalds return -EIO; 32591da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3260c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3261c0eae66eSBenny Halevy if (unlikely(!p)) 3262c0eae66eSBenny Halevy goto out_overflow; 3263cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 32641da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3265409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 32661da177e4SLinus Torvalds } 32673110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3268409924e4STrond Myklebust return ret; 3269c0eae66eSBenny Halevy out_overflow: 3270c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3271c0eae66eSBenny Halevy return -EIO; 32721da177e4SLinus Torvalds } 32731da177e4SLinus Torvalds 32741da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32751da177e4SLinus Torvalds { 32768687b63aSAl Viro __be32 *p; 32771da177e4SLinus Torvalds 32781da177e4SLinus Torvalds *res = 0; 32791da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U))) 32801da177e4SLinus Torvalds return -EIO; 32811da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) { 3282c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3283c0eae66eSBenny Halevy if (unlikely(!p)) 3284c0eae66eSBenny Halevy goto out_overflow; 3285cccddf4fSBenny Halevy *res = be32_to_cpup(p); 32861da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT; 32871da177e4SLinus Torvalds } 32883110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true"); 32891da177e4SLinus Torvalds return 0; 3290c0eae66eSBenny Halevy out_overflow: 3291c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3292c0eae66eSBenny Halevy return -EIO; 32931da177e4SLinus Torvalds } 32941da177e4SLinus Torvalds 32951da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 32961da177e4SLinus Torvalds { 32978687b63aSAl Viro __be32 *p; 32981da177e4SLinus Torvalds 32991da177e4SLinus Torvalds *res = 0; 33001da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 33011da177e4SLinus Torvalds return -EIO; 33021da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3303c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3304c0eae66eSBenny Halevy if (unlikely(!p)) 3305c0eae66eSBenny Halevy goto out_overflow; 3306cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33071da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 33081da177e4SLinus Torvalds } 33093110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 33101da177e4SLinus Torvalds return 0; 3311c0eae66eSBenny Halevy out_overflow: 3312c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3313c0eae66eSBenny Halevy return -EIO; 33141da177e4SLinus Torvalds } 33151da177e4SLinus Torvalds 33168b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 33171da177e4SLinus Torvalds { 33188687b63aSAl Viro __be32 *p; 3319409924e4STrond Myklebust int ret = 0; 33201da177e4SLinus Torvalds 33211da177e4SLinus Torvalds fsid->major = 0; 33221da177e4SLinus Torvalds fsid->minor = 0; 33231da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 33241da177e4SLinus Torvalds return -EIO; 33251da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3326c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3327c0eae66eSBenny Halevy if (unlikely(!p)) 3328c0eae66eSBenny Halevy goto out_overflow; 33293ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3330cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 33311da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3332409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 33331da177e4SLinus Torvalds } 33343110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 33351da177e4SLinus Torvalds (unsigned long long)fsid->major, 33361da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3337409924e4STrond Myklebust return ret; 3338c0eae66eSBenny Halevy out_overflow: 3339c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3340c0eae66eSBenny Halevy return -EIO; 33411da177e4SLinus Torvalds } 33421da177e4SLinus Torvalds 33431da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33441da177e4SLinus Torvalds { 33458687b63aSAl Viro __be32 *p; 33461da177e4SLinus Torvalds 33471da177e4SLinus Torvalds *res = 60; 33481da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 33491da177e4SLinus Torvalds return -EIO; 33501da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3351c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3352c0eae66eSBenny Halevy if (unlikely(!p)) 3353c0eae66eSBenny Halevy goto out_overflow; 3354cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33551da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 33561da177e4SLinus Torvalds } 33573110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 33581da177e4SLinus Torvalds return 0; 3359c0eae66eSBenny Halevy out_overflow: 3360c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3361c0eae66eSBenny Halevy return -EIO; 33621da177e4SLinus Torvalds } 33631da177e4SLinus Torvalds 3364ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3365ae42c70aSBryan Schumaker { 3366ae42c70aSBryan Schumaker __be32 *p; 3367ae42c70aSBryan Schumaker 3368ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3369ae42c70aSBryan Schumaker return -EIO; 3370ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3371ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3372ae42c70aSBryan Schumaker if (unlikely(!p)) 3373ae42c70aSBryan Schumaker goto out_overflow; 3374ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3375ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3376ae42c70aSBryan Schumaker } 3377ae42c70aSBryan Schumaker return 0; 3378ae42c70aSBryan Schumaker out_overflow: 3379ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3380ae42c70aSBryan Schumaker return -EIO; 3381ae42c70aSBryan Schumaker } 3382ae42c70aSBryan Schumaker 3383ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3384ae42c70aSBryan Schumaker { 3385ae42c70aSBryan Schumaker __be32 *p; 3386ae42c70aSBryan Schumaker int len; 3387ae42c70aSBryan Schumaker 33887ad07353STrond Myklebust if (fh != NULL) 3389ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3390ae42c70aSBryan Schumaker 3391ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3392ae42c70aSBryan Schumaker return -EIO; 3393ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3394ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3395ae42c70aSBryan Schumaker if (unlikely(!p)) 3396ae42c70aSBryan Schumaker goto out_overflow; 3397ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3398ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3399ae42c70aSBryan Schumaker return -EIO; 3400ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3401ae42c70aSBryan Schumaker if (unlikely(!p)) 3402ae42c70aSBryan Schumaker goto out_overflow; 34037ad07353STrond Myklebust if (fh != NULL) { 3404ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 34057ad07353STrond Myklebust fh->size = len; 34067ad07353STrond Myklebust } 3407ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3408ae42c70aSBryan Schumaker } 3409ae42c70aSBryan Schumaker return 0; 3410ae42c70aSBryan Schumaker out_overflow: 3411ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3412ae42c70aSBryan Schumaker return -EIO; 3413ae42c70aSBryan Schumaker } 3414ae42c70aSBryan Schumaker 34151da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34161da177e4SLinus Torvalds { 34178687b63aSAl Viro __be32 *p; 34181da177e4SLinus Torvalds 3419a1800acaSMalahal Naineni *res = 0; 34201da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 34211da177e4SLinus Torvalds return -EIO; 34221da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3423c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3424c0eae66eSBenny Halevy if (unlikely(!p)) 3425c0eae66eSBenny Halevy goto out_overflow; 3426cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34271da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 34281da177e4SLinus Torvalds } 34293110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 34301da177e4SLinus Torvalds return 0; 3431c0eae66eSBenny Halevy out_overflow: 3432c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3433c0eae66eSBenny Halevy return -EIO; 34341da177e4SLinus Torvalds } 34351da177e4SLinus Torvalds 34361da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 34371da177e4SLinus Torvalds { 34388687b63aSAl Viro __be32 *p; 3439409924e4STrond Myklebust int ret = 0; 34401da177e4SLinus Torvalds 34411da177e4SLinus Torvalds *fileid = 0; 34421da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 34431da177e4SLinus Torvalds return -EIO; 34441da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3445c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3446c0eae66eSBenny Halevy if (unlikely(!p)) 3447c0eae66eSBenny Halevy goto out_overflow; 3448cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 34491da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3450409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 34511da177e4SLinus Torvalds } 34523110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3453409924e4STrond Myklebust return ret; 3454c0eae66eSBenny Halevy out_overflow: 3455c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3456c0eae66eSBenny Halevy return -EIO; 34571da177e4SLinus Torvalds } 34581da177e4SLinus Torvalds 345999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 346099baf625SManoj Naik { 34618687b63aSAl Viro __be32 *p; 3462409924e4STrond Myklebust int ret = 0; 346399baf625SManoj Naik 346499baf625SManoj Naik *fileid = 0; 346599baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 346699baf625SManoj Naik return -EIO; 346799baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3468c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3469c0eae66eSBenny Halevy if (unlikely(!p)) 3470c0eae66eSBenny Halevy goto out_overflow; 3471cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 347299baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 347328331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 347499baf625SManoj Naik } 34753110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3476409924e4STrond Myklebust return ret; 3477c0eae66eSBenny Halevy out_overflow: 3478c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3479c0eae66eSBenny Halevy return -EIO; 348099baf625SManoj Naik } 348199baf625SManoj Naik 34821da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 34831da177e4SLinus Torvalds { 34848687b63aSAl Viro __be32 *p; 34851da177e4SLinus Torvalds int status = 0; 34861da177e4SLinus Torvalds 34871da177e4SLinus Torvalds *res = 0; 34881da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 34891da177e4SLinus Torvalds return -EIO; 34901da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3491c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3492c0eae66eSBenny Halevy if (unlikely(!p)) 3493c0eae66eSBenny Halevy goto out_overflow; 3494cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 34951da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 34961da177e4SLinus Torvalds } 34973110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 34981da177e4SLinus Torvalds return status; 3499c0eae66eSBenny Halevy out_overflow: 3500c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3501c0eae66eSBenny Halevy return -EIO; 35021da177e4SLinus Torvalds } 35031da177e4SLinus Torvalds 35041da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35051da177e4SLinus Torvalds { 35068687b63aSAl Viro __be32 *p; 35071da177e4SLinus Torvalds int status = 0; 35081da177e4SLinus Torvalds 35091da177e4SLinus Torvalds *res = 0; 35101da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 35111da177e4SLinus Torvalds return -EIO; 35121da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3513c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3514c0eae66eSBenny Halevy if (unlikely(!p)) 3515c0eae66eSBenny Halevy goto out_overflow; 3516cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35171da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 35181da177e4SLinus Torvalds } 35193110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 35201da177e4SLinus Torvalds return status; 3521c0eae66eSBenny Halevy out_overflow: 3522c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3523c0eae66eSBenny Halevy return -EIO; 35241da177e4SLinus Torvalds } 35251da177e4SLinus Torvalds 35261da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35271da177e4SLinus Torvalds { 35288687b63aSAl Viro __be32 *p; 35291da177e4SLinus Torvalds int status = 0; 35301da177e4SLinus Torvalds 35311da177e4SLinus Torvalds *res = 0; 35321da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 35331da177e4SLinus Torvalds return -EIO; 35341da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3535c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3536c0eae66eSBenny Halevy if (unlikely(!p)) 3537c0eae66eSBenny Halevy goto out_overflow; 3538cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35391da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 35401da177e4SLinus Torvalds } 35413110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 35421da177e4SLinus Torvalds return status; 3543c0eae66eSBenny Halevy out_overflow: 3544c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3545c0eae66eSBenny Halevy return -EIO; 35461da177e4SLinus Torvalds } 35471da177e4SLinus Torvalds 35487aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 35497aaa0b3bSManoj Naik { 3550464ad6b1SChuck Lever u32 n; 35518687b63aSAl Viro __be32 *p; 35527aaa0b3bSManoj Naik int status = 0; 35537aaa0b3bSManoj Naik 3554c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3555c0eae66eSBenny Halevy if (unlikely(!p)) 3556c0eae66eSBenny Halevy goto out_overflow; 3557cccddf4fSBenny Halevy n = be32_to_cpup(p); 355833a43f28SAndy Adamson if (n == 0) 355933a43f28SAndy Adamson goto root_path; 356002a2976cSChuck Lever dprintk("pathname4: "); 3561809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3562809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3563809b426cSTrond Myklebust goto out_eio; 3564809b426cSTrond Myklebust } 3565809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 35667aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 35677aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 35687aaa0b3bSManoj Naik if (unlikely(status != 0)) 35697aaa0b3bSManoj Naik goto out_eio; 357095a13f7bSTrond Myklebust ifdebug (XDR) 357102a2976cSChuck Lever pr_cont("%s%.*s ", 357202a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 357302a2976cSChuck Lever component->len, component->data); 35747aaa0b3bSManoj Naik } 35757aaa0b3bSManoj Naik out: 35767aaa0b3bSManoj Naik return status; 357733a43f28SAndy Adamson root_path: 357833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 357933a43f28SAndy Adamson path->ncomponents = 1; 358033a43f28SAndy Adamson path->components[0].len=0; 358133a43f28SAndy Adamson path->components[0].data=NULL; 358202a2976cSChuck Lever dprintk("pathname4: /\n"); 358333a43f28SAndy Adamson goto out; 35847aaa0b3bSManoj Naik out_eio: 35857aaa0b3bSManoj Naik dprintk(" status %d", status); 35867aaa0b3bSManoj Naik status = -EIO; 35877aaa0b3bSManoj Naik goto out; 3588c0eae66eSBenny Halevy out_overflow: 3589c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3590c0eae66eSBenny Halevy return -EIO; 35917aaa0b3bSManoj Naik } 35927aaa0b3bSManoj Naik 35937aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3594683b57b4STrond Myklebust { 3595683b57b4STrond Myklebust int n; 35968687b63aSAl Viro __be32 *p; 3597683b57b4STrond Myklebust int status = -EIO; 3598683b57b4STrond Myklebust 3599683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3600683b57b4STrond Myklebust goto out; 3601683b57b4STrond Myklebust status = 0; 3602683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3603683b57b4STrond Myklebust goto out; 36048b7e3f49STrond Myklebust status = -EIO; 36058b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 36068b7e3f49STrond Myklebust if (unlikely(res == NULL)) 36078b7e3f49STrond Myklebust goto out; 360802a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 36097aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3610683b57b4STrond Myklebust if (unlikely(status != 0)) 3611683b57b4STrond Myklebust goto out; 3612c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3613c0eae66eSBenny Halevy if (unlikely(!p)) 3614c0eae66eSBenny Halevy goto out_overflow; 3615cccddf4fSBenny Halevy n = be32_to_cpup(p); 3616683b57b4STrond Myklebust if (n <= 0) 3617683b57b4STrond Myklebust goto out_eio; 3618809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3619464ad6b1SChuck Lever u32 m; 3620809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3621683b57b4STrond Myklebust 3622809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3623809b426cSTrond Myklebust break; 3624809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3625c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3626c0eae66eSBenny Halevy if (unlikely(!p)) 3627c0eae66eSBenny Halevy goto out_overflow; 3628cccddf4fSBenny Halevy m = be32_to_cpup(p); 36297aaa0b3bSManoj Naik 363002a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3631809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3632809b426cSTrond Myklebust struct nfs4_string *server; 3633809b426cSTrond Myklebust 3634809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3635464ad6b1SChuck Lever unsigned int i; 3636464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3637464ad6b1SChuck Lever "returned for location %u\n", 36383110ff80SHarvey Harrison __func__, 3639464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3640464ad6b1SChuck Lever m, res->nlocations); 36417aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 36422e42c3e2STrond Myklebust unsigned int len; 36437aaa0b3bSManoj Naik char *data; 36447aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3645683b57b4STrond Myklebust if (unlikely(status != 0)) 3646683b57b4STrond Myklebust goto out_eio; 36477aaa0b3bSManoj Naik } 3648809b426cSTrond Myklebust break; 36497aaa0b3bSManoj Naik } 3650809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3651809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3652809b426cSTrond Myklebust if (unlikely(status != 0)) 3653809b426cSTrond Myklebust goto out_eio; 3654809b426cSTrond Myklebust dprintk("%s ", server->data); 36557aaa0b3bSManoj Naik } 36567aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 36577aaa0b3bSManoj Naik if (unlikely(status != 0)) 36587aaa0b3bSManoj Naik goto out_eio; 3659683b57b4STrond Myklebust } 3660409924e4STrond Myklebust if (res->nlocations != 0) 366181934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3662683b57b4STrond Myklebust out: 36633110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3664683b57b4STrond Myklebust return status; 3665c0eae66eSBenny Halevy out_overflow: 3666c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3667683b57b4STrond Myklebust out_eio: 3668683b57b4STrond Myklebust status = -EIO; 3669683b57b4STrond Myklebust goto out; 3670683b57b4STrond Myklebust } 3671683b57b4STrond Myklebust 36721da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 36731da177e4SLinus Torvalds { 36748687b63aSAl Viro __be32 *p; 36751da177e4SLinus Torvalds int status = 0; 36761da177e4SLinus Torvalds 36771da177e4SLinus Torvalds *res = 0; 36781da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 36791da177e4SLinus Torvalds return -EIO; 36801da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3681c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3682c0eae66eSBenny Halevy if (unlikely(!p)) 3683c0eae66eSBenny Halevy goto out_overflow; 3684cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 36851da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 36861da177e4SLinus Torvalds } 36873110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 36881da177e4SLinus Torvalds return status; 3689c0eae66eSBenny Halevy out_overflow: 3690c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3691c0eae66eSBenny Halevy return -EIO; 36921da177e4SLinus Torvalds } 36931da177e4SLinus Torvalds 36941da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 36951da177e4SLinus Torvalds { 36968687b63aSAl Viro __be32 *p; 36971da177e4SLinus Torvalds int status = 0; 36981da177e4SLinus Torvalds 36991da177e4SLinus Torvalds *maxlink = 1; 37001da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 37011da177e4SLinus Torvalds return -EIO; 37021da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3703c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3704c0eae66eSBenny Halevy if (unlikely(!p)) 3705c0eae66eSBenny Halevy goto out_overflow; 3706cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 37071da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 37081da177e4SLinus Torvalds } 37093110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 37101da177e4SLinus Torvalds return status; 3711c0eae66eSBenny Halevy out_overflow: 3712c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3713c0eae66eSBenny Halevy return -EIO; 37141da177e4SLinus Torvalds } 37151da177e4SLinus Torvalds 37161da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 37171da177e4SLinus Torvalds { 37188687b63aSAl Viro __be32 *p; 37191da177e4SLinus Torvalds int status = 0; 37201da177e4SLinus Torvalds 37211da177e4SLinus Torvalds *maxname = 1024; 37221da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 37231da177e4SLinus Torvalds return -EIO; 37241da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3725c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3726c0eae66eSBenny Halevy if (unlikely(!p)) 3727c0eae66eSBenny Halevy goto out_overflow; 3728cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 37291da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 37301da177e4SLinus Torvalds } 37313110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 37321da177e4SLinus Torvalds return status; 3733c0eae66eSBenny Halevy out_overflow: 3734c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3735c0eae66eSBenny Halevy return -EIO; 37361da177e4SLinus Torvalds } 37371da177e4SLinus Torvalds 37381da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37391da177e4SLinus Torvalds { 37408687b63aSAl Viro __be32 *p; 37411da177e4SLinus Torvalds int status = 0; 37421da177e4SLinus Torvalds 37431da177e4SLinus Torvalds *res = 1024; 37441da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 37451da177e4SLinus Torvalds return -EIO; 37461da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 37471da177e4SLinus Torvalds uint64_t maxread; 3748c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3749c0eae66eSBenny Halevy if (unlikely(!p)) 3750c0eae66eSBenny Halevy goto out_overflow; 3751cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 37521da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 37531da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 37541da177e4SLinus Torvalds *res = (uint32_t)maxread; 37551da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 37561da177e4SLinus Torvalds } 37573110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 37581da177e4SLinus Torvalds return status; 3759c0eae66eSBenny Halevy out_overflow: 3760c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3761c0eae66eSBenny Halevy return -EIO; 37621da177e4SLinus Torvalds } 37631da177e4SLinus Torvalds 37641da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37651da177e4SLinus Torvalds { 37668687b63aSAl Viro __be32 *p; 37671da177e4SLinus Torvalds int status = 0; 37681da177e4SLinus Torvalds 37691da177e4SLinus Torvalds *res = 1024; 37701da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 37711da177e4SLinus Torvalds return -EIO; 37721da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 37731da177e4SLinus Torvalds uint64_t maxwrite; 3774c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3775c0eae66eSBenny Halevy if (unlikely(!p)) 3776c0eae66eSBenny Halevy goto out_overflow; 3777cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 37781da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 37791da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 37801da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 37811da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 37821da177e4SLinus Torvalds } 37833110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 37841da177e4SLinus Torvalds return status; 3785c0eae66eSBenny Halevy out_overflow: 3786c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3787c0eae66eSBenny Halevy return -EIO; 37881da177e4SLinus Torvalds } 37891da177e4SLinus Torvalds 3790bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 37911da177e4SLinus Torvalds { 3792bca79478STrond Myklebust uint32_t tmp; 37938687b63aSAl Viro __be32 *p; 3794409924e4STrond Myklebust int ret = 0; 37951da177e4SLinus Torvalds 37961da177e4SLinus Torvalds *mode = 0; 37971da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 37981da177e4SLinus Torvalds return -EIO; 37991da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3800c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3801c0eae66eSBenny Halevy if (unlikely(!p)) 3802c0eae66eSBenny Halevy goto out_overflow; 3803cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3804bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 38051da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3806409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 38071da177e4SLinus Torvalds } 38083110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3809409924e4STrond Myklebust return ret; 3810c0eae66eSBenny Halevy out_overflow: 3811c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3812c0eae66eSBenny Halevy return -EIO; 38131da177e4SLinus Torvalds } 38141da177e4SLinus Torvalds 38151da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 38161da177e4SLinus Torvalds { 38178687b63aSAl Viro __be32 *p; 3818409924e4STrond Myklebust int ret = 0; 38191da177e4SLinus Torvalds 38201da177e4SLinus Torvalds *nlink = 1; 38211da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 38221da177e4SLinus Torvalds return -EIO; 38231da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3824c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3825c0eae66eSBenny Halevy if (unlikely(!p)) 3826c0eae66eSBenny Halevy goto out_overflow; 3827cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 38281da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3829409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 38301da177e4SLinus Torvalds } 38313110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3832409924e4STrond Myklebust return ret; 3833c0eae66eSBenny Halevy out_overflow: 3834c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3835c0eae66eSBenny Halevy return -EIO; 38361da177e4SLinus Torvalds } 38371da177e4SLinus Torvalds 383880e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3839e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 38406926afd1STrond Myklebust struct nfs4_string *owner_name) 38411da177e4SLinus Torvalds { 38428687b63aSAl Viro uint32_t len; 38438687b63aSAl Viro __be32 *p; 3844409924e4STrond Myklebust int ret = 0; 38451da177e4SLinus Torvalds 3846e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 38471da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 38481da177e4SLinus Torvalds return -EIO; 38491da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3850c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3851c0eae66eSBenny Halevy if (unlikely(!p)) 3852c0eae66eSBenny Halevy goto out_overflow; 3853cccddf4fSBenny Halevy len = be32_to_cpup(p); 3854c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3855c0eae66eSBenny Halevy if (unlikely(!p)) 3856c0eae66eSBenny Halevy goto out_overflow; 38576926afd1STrond Myklebust if (owner_name != NULL) { 38586926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 38596926afd1STrond Myklebust if (owner_name->data != NULL) { 38606926afd1STrond Myklebust owner_name->len = len; 38616926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 38626926afd1STrond Myklebust } 386380e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3864e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3865409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3866409924e4STrond Myklebust else 38671da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 38683110ff80SHarvey Harrison __func__); 38691da177e4SLinus Torvalds } else 3870fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 38713110ff80SHarvey Harrison __func__, len); 38721da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 38731da177e4SLinus Torvalds } 3874e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3875409924e4STrond Myklebust return ret; 3876c0eae66eSBenny Halevy out_overflow: 3877c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3878c0eae66eSBenny Halevy return -EIO; 38791da177e4SLinus Torvalds } 38801da177e4SLinus Torvalds 388180e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3882e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 38836926afd1STrond Myklebust struct nfs4_string *group_name) 38841da177e4SLinus Torvalds { 38858687b63aSAl Viro uint32_t len; 38868687b63aSAl Viro __be32 *p; 3887409924e4STrond Myklebust int ret = 0; 38881da177e4SLinus Torvalds 3889e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 38901da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 38911da177e4SLinus Torvalds return -EIO; 38921da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3893c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3894c0eae66eSBenny Halevy if (unlikely(!p)) 3895c0eae66eSBenny Halevy goto out_overflow; 3896cccddf4fSBenny Halevy len = be32_to_cpup(p); 3897c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3898c0eae66eSBenny Halevy if (unlikely(!p)) 3899c0eae66eSBenny Halevy goto out_overflow; 39006926afd1STrond Myklebust if (group_name != NULL) { 39016926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 39026926afd1STrond Myklebust if (group_name->data != NULL) { 39036926afd1STrond Myklebust group_name->len = len; 39046926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 39056926afd1STrond Myklebust } 390680e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3907e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3908409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3909409924e4STrond Myklebust else 39101da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 39113110ff80SHarvey Harrison __func__); 39121da177e4SLinus Torvalds } else 3913fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 39143110ff80SHarvey Harrison __func__, len); 39151da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 39161da177e4SLinus Torvalds } 3917e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 3918409924e4STrond Myklebust return ret; 3919c0eae66eSBenny Halevy out_overflow: 3920c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3921c0eae66eSBenny Halevy return -EIO; 39221da177e4SLinus Torvalds } 39231da177e4SLinus Torvalds 39241da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 39251da177e4SLinus Torvalds { 39268687b63aSAl Viro uint32_t major = 0, minor = 0; 39278687b63aSAl Viro __be32 *p; 3928409924e4STrond Myklebust int ret = 0; 39291da177e4SLinus Torvalds 39301da177e4SLinus Torvalds *rdev = MKDEV(0,0); 39311da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 39321da177e4SLinus Torvalds return -EIO; 39331da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 39341da177e4SLinus Torvalds dev_t tmp; 39351da177e4SLinus Torvalds 3936c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3937c0eae66eSBenny Halevy if (unlikely(!p)) 3938c0eae66eSBenny Halevy goto out_overflow; 39396f723f77SBenny Halevy major = be32_to_cpup(p++); 3940cccddf4fSBenny Halevy minor = be32_to_cpup(p); 39411da177e4SLinus Torvalds tmp = MKDEV(major, minor); 39421da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 39431da177e4SLinus Torvalds *rdev = tmp; 39441da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3945409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 39461da177e4SLinus Torvalds } 39473110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3948409924e4STrond Myklebust return ret; 3949c0eae66eSBenny Halevy out_overflow: 3950c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3951c0eae66eSBenny Halevy return -EIO; 39521da177e4SLinus Torvalds } 39531da177e4SLinus Torvalds 39541da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39551da177e4SLinus Torvalds { 39568687b63aSAl Viro __be32 *p; 39571da177e4SLinus Torvalds int status = 0; 39581da177e4SLinus Torvalds 39591da177e4SLinus Torvalds *res = 0; 39601da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 39611da177e4SLinus Torvalds return -EIO; 39621da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 3963c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3964c0eae66eSBenny Halevy if (unlikely(!p)) 3965c0eae66eSBenny Halevy goto out_overflow; 3966cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39671da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 39681da177e4SLinus Torvalds } 39693110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 39701da177e4SLinus Torvalds return status; 3971c0eae66eSBenny Halevy out_overflow: 3972c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3973c0eae66eSBenny Halevy return -EIO; 39741da177e4SLinus Torvalds } 39751da177e4SLinus Torvalds 39761da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39771da177e4SLinus Torvalds { 39788687b63aSAl Viro __be32 *p; 39791da177e4SLinus Torvalds int status = 0; 39801da177e4SLinus Torvalds 39811da177e4SLinus Torvalds *res = 0; 39821da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 39831da177e4SLinus Torvalds return -EIO; 39841da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 3985c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3986c0eae66eSBenny Halevy if (unlikely(!p)) 3987c0eae66eSBenny Halevy goto out_overflow; 3988cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 39891da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 39901da177e4SLinus Torvalds } 39913110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 39921da177e4SLinus Torvalds return status; 3993c0eae66eSBenny Halevy out_overflow: 3994c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3995c0eae66eSBenny Halevy return -EIO; 39961da177e4SLinus Torvalds } 39971da177e4SLinus Torvalds 39981da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39991da177e4SLinus Torvalds { 40008687b63aSAl Viro __be32 *p; 40011da177e4SLinus Torvalds int status = 0; 40021da177e4SLinus Torvalds 40031da177e4SLinus Torvalds *res = 0; 40041da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 40051da177e4SLinus Torvalds return -EIO; 40061da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4007c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4008c0eae66eSBenny Halevy if (unlikely(!p)) 4009c0eae66eSBenny Halevy goto out_overflow; 4010cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40111da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 40121da177e4SLinus Torvalds } 40133110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 40141da177e4SLinus Torvalds return status; 4015c0eae66eSBenny Halevy out_overflow: 4016c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4017c0eae66eSBenny Halevy return -EIO; 40181da177e4SLinus Torvalds } 40191da177e4SLinus Torvalds 40201da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 40211da177e4SLinus Torvalds { 40228687b63aSAl Viro __be32 *p; 4023409924e4STrond Myklebust int ret = 0; 40241da177e4SLinus Torvalds 40251da177e4SLinus Torvalds *used = 0; 40261da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 40271da177e4SLinus Torvalds return -EIO; 40281da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4029c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4030c0eae66eSBenny Halevy if (unlikely(!p)) 4031c0eae66eSBenny Halevy goto out_overflow; 4032cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 40331da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4034409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 40351da177e4SLinus Torvalds } 40363110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 40371da177e4SLinus Torvalds (unsigned long long)*used); 4038409924e4STrond Myklebust return ret; 4039c0eae66eSBenny Halevy out_overflow: 4040c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4041c0eae66eSBenny Halevy return -EIO; 40421da177e4SLinus Torvalds } 40431da177e4SLinus Torvalds 40441da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 40451da177e4SLinus Torvalds { 40468687b63aSAl Viro __be32 *p; 40471da177e4SLinus Torvalds uint64_t sec; 40481da177e4SLinus Torvalds uint32_t nsec; 40491da177e4SLinus Torvalds 4050c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4051c0eae66eSBenny Halevy if (unlikely(!p)) 4052c0eae66eSBenny Halevy goto out_overflow; 40533ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 4054cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 40551da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 40561da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 40571da177e4SLinus Torvalds return 0; 4058c0eae66eSBenny Halevy out_overflow: 4059c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4060c0eae66eSBenny Halevy return -EIO; 40611da177e4SLinus Torvalds } 40621da177e4SLinus Torvalds 40631da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40641da177e4SLinus Torvalds { 40651da177e4SLinus Torvalds int status = 0; 40661da177e4SLinus Torvalds 40671da177e4SLinus Torvalds time->tv_sec = 0; 40681da177e4SLinus Torvalds time->tv_nsec = 0; 40691da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 40701da177e4SLinus Torvalds return -EIO; 40711da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 40721da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4073409924e4STrond Myklebust if (status == 0) 4074409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 40751da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 40761da177e4SLinus Torvalds } 40773110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 40781da177e4SLinus Torvalds return status; 40791da177e4SLinus Torvalds } 40801da177e4SLinus Torvalds 40811da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 40821da177e4SLinus Torvalds { 40831da177e4SLinus Torvalds int status = 0; 40841da177e4SLinus Torvalds 40851da177e4SLinus Torvalds time->tv_sec = 0; 40861da177e4SLinus Torvalds time->tv_nsec = 0; 40871da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 40881da177e4SLinus Torvalds return -EIO; 40891da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 40901da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4091409924e4STrond Myklebust if (status == 0) 4092409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 40931da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 40941da177e4SLinus Torvalds } 40953110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 40961da177e4SLinus Torvalds return status; 40971da177e4SLinus Torvalds } 40981da177e4SLinus Torvalds 409955b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 410055b6e774SRicardo Labiaga struct timespec *time) 410155b6e774SRicardo Labiaga { 410255b6e774SRicardo Labiaga int status = 0; 410355b6e774SRicardo Labiaga 410455b6e774SRicardo Labiaga time->tv_sec = 0; 410555b6e774SRicardo Labiaga time->tv_nsec = 0; 410655b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 410755b6e774SRicardo Labiaga return -EIO; 410855b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 410955b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 411055b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 411155b6e774SRicardo Labiaga } 411255b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 411355b6e774SRicardo Labiaga (long)time->tv_nsec); 411455b6e774SRicardo Labiaga return status; 411555b6e774SRicardo Labiaga } 411655b6e774SRicardo Labiaga 4117aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4118aa9c2669SDavid Quigley struct nfs4_label *label) 4119aa9c2669SDavid Quigley { 4120aa9c2669SDavid Quigley uint32_t pi = 0; 4121aa9c2669SDavid Quigley uint32_t lfs = 0; 4122aa9c2669SDavid Quigley __u32 len; 4123aa9c2669SDavid Quigley __be32 *p; 4124aa9c2669SDavid Quigley int status = 0; 4125aa9c2669SDavid Quigley 4126aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4127aa9c2669SDavid Quigley return -EIO; 4128aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4129aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4130aa9c2669SDavid Quigley if (unlikely(!p)) 4131aa9c2669SDavid Quigley goto out_overflow; 4132aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4133aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4134aa9c2669SDavid Quigley if (unlikely(!p)) 4135aa9c2669SDavid Quigley goto out_overflow; 4136aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4137aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4138aa9c2669SDavid Quigley if (unlikely(!p)) 4139aa9c2669SDavid Quigley goto out_overflow; 4140aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4141aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4142aa9c2669SDavid Quigley if (unlikely(!p)) 4143aa9c2669SDavid Quigley goto out_overflow; 4144aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4145aa9c2669SDavid Quigley if (label) { 4146aa9c2669SDavid Quigley memcpy(label->label, p, len); 4147aa9c2669SDavid Quigley label->len = len; 4148aa9c2669SDavid Quigley label->pi = pi; 4149aa9c2669SDavid Quigley label->lfs = lfs; 4150aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4151aa9c2669SDavid Quigley } 4152aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4153aa9c2669SDavid Quigley } else 4154aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4155aa9c2669SDavid Quigley __func__, len); 4156aa9c2669SDavid Quigley } 4157aa9c2669SDavid Quigley if (label && label->label) 4158aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4159aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4160aa9c2669SDavid Quigley return status; 4161aa9c2669SDavid Quigley 4162aa9c2669SDavid Quigley out_overflow: 4163aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4164aa9c2669SDavid Quigley return -EIO; 4165aa9c2669SDavid Quigley } 4166aa9c2669SDavid Quigley 41671da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41681da177e4SLinus Torvalds { 41691da177e4SLinus Torvalds int status = 0; 41701da177e4SLinus Torvalds 41711da177e4SLinus Torvalds time->tv_sec = 0; 41721da177e4SLinus Torvalds time->tv_nsec = 0; 41731da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 41741da177e4SLinus Torvalds return -EIO; 41751da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 41761da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4177409924e4STrond Myklebust if (status == 0) 4178409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 41791da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 41801da177e4SLinus Torvalds } 41813110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 41821da177e4SLinus Torvalds return status; 41831da177e4SLinus Torvalds } 41841da177e4SLinus Torvalds 4185256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 41861da177e4SLinus Torvalds { 41871da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4188256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 41891da177e4SLinus Torvalds 41901da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4191fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4192fe82a183SChuck Lever "%u %c %u\n", 41933110ff80SHarvey Harrison __func__, 41941da177e4SLinus Torvalds attrwords << 2, 41951da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 41961da177e4SLinus Torvalds nwords << 2); 41971da177e4SLinus Torvalds return -EIO; 41981da177e4SLinus Torvalds } 41991da177e4SLinus Torvalds return 0; 42001da177e4SLinus Torvalds } 42011da177e4SLinus Torvalds 42021da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42031da177e4SLinus Torvalds { 42048687b63aSAl Viro __be32 *p; 42051da177e4SLinus Torvalds 4206c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4207c0eae66eSBenny Halevy if (unlikely(!p)) 4208c0eae66eSBenny Halevy goto out_overflow; 42096f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 42103ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4211cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 42121da177e4SLinus Torvalds return 0; 4213c0eae66eSBenny Halevy out_overflow: 4214c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4215c0eae66eSBenny Halevy return -EIO; 42161da177e4SLinus Torvalds } 42171da177e4SLinus Torvalds 42186168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 42191da177e4SLinus Torvalds { 42208687b63aSAl Viro __be32 *p; 42211da177e4SLinus Torvalds uint32_t supp, acc; 42221da177e4SLinus Torvalds int status; 42231da177e4SLinus Torvalds 42241da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 42251da177e4SLinus Torvalds if (status) 42261da177e4SLinus Torvalds return status; 4227c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4228c0eae66eSBenny Halevy if (unlikely(!p)) 4229c0eae66eSBenny Halevy goto out_overflow; 42306f723f77SBenny Halevy supp = be32_to_cpup(p++); 4231cccddf4fSBenny Halevy acc = be32_to_cpup(p); 42326168f62cSWeston Andros Adamson *supported = supp; 42336168f62cSWeston Andros Adamson *access = acc; 42341da177e4SLinus Torvalds return 0; 4235c0eae66eSBenny Halevy out_overflow: 4236c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4237c0eae66eSBenny Halevy return -EIO; 42381da177e4SLinus Torvalds } 42391da177e4SLinus Torvalds 424007d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 42411da177e4SLinus Torvalds { 42428687b63aSAl Viro __be32 *p; 424307d30434SBenny Halevy 424407d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 424507d30434SBenny Halevy if (likely(p)) { 424607d30434SBenny Halevy memcpy(buf, p, len); 424707d30434SBenny Halevy return 0; 424807d30434SBenny Halevy } 424907d30434SBenny Halevy print_overflow_msg(__func__, xdr); 425007d30434SBenny Halevy return -EIO; 425107d30434SBenny Halevy } 425207d30434SBenny Halevy 425307d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 425407d30434SBenny Halevy { 42552d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 42561da177e4SLinus Torvalds } 42571da177e4SLinus Torvalds 42581da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 42591da177e4SLinus Torvalds { 42601da177e4SLinus Torvalds int status; 42611da177e4SLinus Torvalds 42621da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4263c1d51931STrond Myklebust if (status != -EIO) 4264c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 426507d30434SBenny Halevy if (!status) 426607d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 42671da177e4SLinus Torvalds return status; 42681da177e4SLinus Torvalds } 42691da177e4SLinus Torvalds 4270db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4271db942bbdSBenny Halevy { 4272cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 42731da177e4SLinus Torvalds } 42741da177e4SLinus Torvalds 42752f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 42762f2c63bcSTrond Myklebust { 42772f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 42782f2c63bcSTrond Myklebust } 42792f2c63bcSTrond Myklebust 42800b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 42811da177e4SLinus Torvalds { 42821da177e4SLinus Torvalds int status; 42831da177e4SLinus Torvalds 42841da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4285db942bbdSBenny Halevy if (!status) 42862f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 42871da177e4SLinus Torvalds return status; 42881da177e4SLinus Torvalds } 42891da177e4SLinus Torvalds 42901da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42911da177e4SLinus Torvalds { 42928687b63aSAl Viro __be32 *p; 42931da177e4SLinus Torvalds uint32_t bmlen; 42941da177e4SLinus Torvalds int status; 42951da177e4SLinus Torvalds 42961da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 42971da177e4SLinus Torvalds if (status) 42981da177e4SLinus Torvalds return status; 42991da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 43001da177e4SLinus Torvalds return status; 4301c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4302c0eae66eSBenny Halevy if (unlikely(!p)) 4303c0eae66eSBenny Halevy goto out_overflow; 4304cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4305c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4306c0eae66eSBenny Halevy if (likely(p)) 43071da177e4SLinus Torvalds return 0; 4308c0eae66eSBenny Halevy out_overflow: 4309c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4310c0eae66eSBenny Halevy return -EIO; 43111da177e4SLinus Torvalds } 43121da177e4SLinus Torvalds 43131da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 43141da177e4SLinus Torvalds { 4315256e48bbSTrond Myklebust unsigned int savep; 4316dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43171da177e4SLinus Torvalds int status; 43181da177e4SLinus Torvalds 43191da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43201da177e4SLinus Torvalds goto xdr_error; 43211da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43221da177e4SLinus Torvalds goto xdr_error; 43231da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43241da177e4SLinus Torvalds goto xdr_error; 43251da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 43261da177e4SLinus Torvalds goto xdr_error; 4327264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4328264e6351SChuck Lever &res->fh_expire_type)) != 0) 4329264e6351SChuck Lever goto xdr_error; 43301da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 43311da177e4SLinus Torvalds goto xdr_error; 43321da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 43331da177e4SLinus Torvalds goto xdr_error; 43341da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 43351da177e4SLinus Torvalds goto xdr_error; 43361da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43371da177e4SLinus Torvalds xdr_error: 43383110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43391da177e4SLinus Torvalds return status; 43401da177e4SLinus Torvalds } 43411da177e4SLinus Torvalds 43421da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 43431da177e4SLinus Torvalds { 4344256e48bbSTrond Myklebust unsigned int savep; 4345dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43461da177e4SLinus Torvalds int status; 43471da177e4SLinus Torvalds 43481da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43491da177e4SLinus Torvalds goto xdr_error; 43501da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43511da177e4SLinus Torvalds goto xdr_error; 43521da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43531da177e4SLinus Torvalds goto xdr_error; 43541da177e4SLinus Torvalds 43551da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 43561da177e4SLinus Torvalds goto xdr_error; 43571da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 43581da177e4SLinus Torvalds goto xdr_error; 43591da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 43601da177e4SLinus Torvalds goto xdr_error; 43611da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 43621da177e4SLinus Torvalds goto xdr_error; 43631da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 43641da177e4SLinus Torvalds goto xdr_error; 43651da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 43661da177e4SLinus Torvalds goto xdr_error; 43671da177e4SLinus Torvalds 43681da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43691da177e4SLinus Torvalds xdr_error: 43703110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43711da177e4SLinus Torvalds return status; 43721da177e4SLinus Torvalds } 43731da177e4SLinus Torvalds 43741da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 43751da177e4SLinus Torvalds { 4376256e48bbSTrond Myklebust unsigned int savep; 4377dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43781da177e4SLinus Torvalds int status; 43791da177e4SLinus Torvalds 43801da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43811da177e4SLinus Torvalds goto xdr_error; 43821da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43831da177e4SLinus Torvalds goto xdr_error; 43841da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43851da177e4SLinus Torvalds goto xdr_error; 43861da177e4SLinus Torvalds 43871da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 43881da177e4SLinus Torvalds goto xdr_error; 43891da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 43901da177e4SLinus Torvalds goto xdr_error; 43911da177e4SLinus Torvalds 43921da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43931da177e4SLinus Torvalds xdr_error: 43943110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43951da177e4SLinus Torvalds return status; 43961da177e4SLinus Torvalds } 43971da177e4SLinus Torvalds 439888034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 439988034c3dSAndy Adamson uint32_t *bitmap, 440088034c3dSAndy Adamson uint64_t *res, 440188034c3dSAndy Adamson uint32_t hint_bit) 440288034c3dSAndy Adamson { 440388034c3dSAndy Adamson __be32 *p; 440488034c3dSAndy Adamson 440588034c3dSAndy Adamson *res = 0; 440688034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 440788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 440888034c3dSAndy Adamson if (unlikely(!p)) 440988034c3dSAndy Adamson goto out_overflow; 441088034c3dSAndy Adamson xdr_decode_hyper(p, res); 441188034c3dSAndy Adamson } 441288034c3dSAndy Adamson return 0; 441388034c3dSAndy Adamson out_overflow: 441488034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 441588034c3dSAndy Adamson return -EIO; 441688034c3dSAndy Adamson } 441788034c3dSAndy Adamson 441888034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 441988034c3dSAndy Adamson struct nfs4_threshold *res) 442088034c3dSAndy Adamson { 4421256e48bbSTrond Myklebust __be32 *p; 4422256e48bbSTrond Myklebust unsigned int savep; 442388034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 442488034c3dSAndy Adamson int status; 442588034c3dSAndy Adamson 442688034c3dSAndy Adamson /* layout type */ 442788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 442888034c3dSAndy Adamson if (unlikely(!p)) { 442988034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 443088034c3dSAndy Adamson return -EIO; 443188034c3dSAndy Adamson } 443288034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 443388034c3dSAndy Adamson 443488034c3dSAndy Adamson /* thi_hintset bitmap */ 443588034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 443688034c3dSAndy Adamson if (status < 0) 443788034c3dSAndy Adamson goto xdr_error; 443888034c3dSAndy Adamson 443988034c3dSAndy Adamson /* thi_hintlist length */ 444088034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 444188034c3dSAndy Adamson if (status < 0) 444288034c3dSAndy Adamson goto xdr_error; 444388034c3dSAndy Adamson /* thi_hintlist */ 444488034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 444588034c3dSAndy Adamson if (status < 0) 444688034c3dSAndy Adamson goto xdr_error; 444788034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 444888034c3dSAndy Adamson if (status < 0) 444988034c3dSAndy Adamson goto xdr_error; 445088034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 445188034c3dSAndy Adamson THRESHOLD_RD_IO); 445288034c3dSAndy Adamson if (status < 0) 445388034c3dSAndy Adamson goto xdr_error; 445488034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 445588034c3dSAndy Adamson THRESHOLD_WR_IO); 445688034c3dSAndy Adamson if (status < 0) 445788034c3dSAndy Adamson goto xdr_error; 445888034c3dSAndy Adamson 445988034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 446088034c3dSAndy Adamson res->bm = bitmap[0]; 446188034c3dSAndy Adamson 446288034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 446388034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 446488034c3dSAndy Adamson res->wr_io_sz); 446588034c3dSAndy Adamson xdr_error: 446688034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 446788034c3dSAndy Adamson return status; 446888034c3dSAndy Adamson } 446988034c3dSAndy Adamson 447088034c3dSAndy Adamson /* 447188034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 447288034c3dSAndy Adamson */ 447388034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 447488034c3dSAndy Adamson uint32_t *bitmap, 447588034c3dSAndy Adamson struct nfs4_threshold *res) 447688034c3dSAndy Adamson { 447788034c3dSAndy Adamson __be32 *p; 447888034c3dSAndy Adamson int status = 0; 447988034c3dSAndy Adamson uint32_t num; 448088034c3dSAndy Adamson 448188034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 448288034c3dSAndy Adamson return -EIO; 4483029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 44841549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 44851549210fSTrond Myklebust if (unlikely(res == NULL)) 44861549210fSTrond Myklebust return -EREMOTEIO; 448788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 448888034c3dSAndy Adamson if (unlikely(!p)) 448988034c3dSAndy Adamson goto out_overflow; 449088034c3dSAndy Adamson num = be32_to_cpup(p); 449188034c3dSAndy Adamson if (num == 0) 449288034c3dSAndy Adamson return 0; 449388034c3dSAndy Adamson if (num > 1) 449488034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 449588034c3dSAndy Adamson "drivers per filesystem not supported\n", 449688034c3dSAndy Adamson __func__); 449788034c3dSAndy Adamson 449888034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4499029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 450088034c3dSAndy Adamson } 450188034c3dSAndy Adamson return status; 450288034c3dSAndy Adamson out_overflow: 450388034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 450488034c3dSAndy Adamson return -EIO; 450588034c3dSAndy Adamson } 450688034c3dSAndy Adamson 4507ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4508ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4509aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 45106926afd1STrond Myklebust const struct nfs_server *server) 45111da177e4SLinus Torvalds { 4512bca79478STrond Myklebust int status; 4513bca79478STrond Myklebust umode_t fmode = 0; 4514ae42c70aSBryan Schumaker uint32_t type; 4515ee7b75fcSTrond Myklebust int32_t err; 45161da177e4SLinus Torvalds 4517f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4518f26c7a78STrond Myklebust if (status < 0) 45191da177e4SLinus Torvalds goto xdr_error; 4520409924e4STrond Myklebust fattr->mode = 0; 4521409924e4STrond Myklebust if (status != 0) { 4522409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4523409924e4STrond Myklebust fattr->valid |= status; 4524409924e4STrond Myklebust } 45251da177e4SLinus Torvalds 4526f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4527f26c7a78STrond Myklebust if (status < 0) 45281da177e4SLinus Torvalds goto xdr_error; 4529409924e4STrond Myklebust fattr->valid |= status; 4530f26c7a78STrond Myklebust 4531f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4532f26c7a78STrond Myklebust if (status < 0) 45331da177e4SLinus Torvalds goto xdr_error; 4534409924e4STrond Myklebust fattr->valid |= status; 4535f26c7a78STrond Myklebust 4536f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4537f26c7a78STrond Myklebust if (status < 0) 45381da177e4SLinus Torvalds goto xdr_error; 4539409924e4STrond Myklebust fattr->valid |= status; 4540f26c7a78STrond Myklebust 4541ee7b75fcSTrond Myklebust err = 0; 4542ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4543ae42c70aSBryan Schumaker if (status < 0) 4544ae42c70aSBryan Schumaker goto xdr_error; 4545ae42c70aSBryan Schumaker 4546ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4547ae42c70aSBryan Schumaker if (status < 0) 4548ae42c70aSBryan Schumaker goto xdr_error; 4549ae42c70aSBryan Schumaker 4550f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4551f26c7a78STrond Myklebust if (status < 0) 45521da177e4SLinus Torvalds goto xdr_error; 4553409924e4STrond Myklebust fattr->valid |= status; 4554f26c7a78STrond Myklebust 45558b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4556f26c7a78STrond Myklebust if (status < 0) 4557683b57b4STrond Myklebust goto xdr_error; 4558409924e4STrond Myklebust fattr->valid |= status; 4559f26c7a78STrond Myklebust 4560f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4561f26c7a78STrond Myklebust if (status < 0) 45621da177e4SLinus Torvalds goto xdr_error; 4563409924e4STrond Myklebust if (status != 0) { 45641da177e4SLinus Torvalds fattr->mode |= fmode; 4565409924e4STrond Myklebust fattr->valid |= status; 4566409924e4STrond Myklebust } 4567f26c7a78STrond Myklebust 4568f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4569f26c7a78STrond Myklebust if (status < 0) 45701da177e4SLinus Torvalds goto xdr_error; 4571409924e4STrond Myklebust fattr->valid |= status; 4572f26c7a78STrond Myklebust 45736926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4574f26c7a78STrond Myklebust if (status < 0) 45751da177e4SLinus Torvalds goto xdr_error; 4576409924e4STrond Myklebust fattr->valid |= status; 4577f26c7a78STrond Myklebust 45786926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4579f26c7a78STrond Myklebust if (status < 0) 45801da177e4SLinus Torvalds goto xdr_error; 4581409924e4STrond Myklebust fattr->valid |= status; 4582f26c7a78STrond Myklebust 4583f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4584f26c7a78STrond Myklebust if (status < 0) 45851da177e4SLinus Torvalds goto xdr_error; 4586409924e4STrond Myklebust fattr->valid |= status; 4587f26c7a78STrond Myklebust 4588f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4589f26c7a78STrond Myklebust if (status < 0) 45901da177e4SLinus Torvalds goto xdr_error; 4591409924e4STrond Myklebust fattr->valid |= status; 4592f26c7a78STrond Myklebust 4593f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4594f26c7a78STrond Myklebust if (status < 0) 45951da177e4SLinus Torvalds goto xdr_error; 4596409924e4STrond Myklebust fattr->valid |= status; 4597f26c7a78STrond Myklebust 4598f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4599f26c7a78STrond Myklebust if (status < 0) 46001da177e4SLinus Torvalds goto xdr_error; 4601409924e4STrond Myklebust fattr->valid |= status; 4602f26c7a78STrond Myklebust 4603f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4604f26c7a78STrond Myklebust if (status < 0) 46051da177e4SLinus Torvalds goto xdr_error; 4606409924e4STrond Myklebust fattr->valid |= status; 4607f26c7a78STrond Myklebust 460828331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4609f26c7a78STrond Myklebust if (status < 0) 461099baf625SManoj Naik goto xdr_error; 4611409924e4STrond Myklebust fattr->valid |= status; 4612f26c7a78STrond Myklebust 461388034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 461488034c3dSAndy Adamson if (status < 0) 461588034c3dSAndy Adamson goto xdr_error; 461688034c3dSAndy Adamson 4617aa9c2669SDavid Quigley if (label) { 4618aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4619aa9c2669SDavid Quigley if (status < 0) 4620aa9c2669SDavid Quigley goto xdr_error; 4621aa9c2669SDavid Quigley fattr->valid |= status; 4622aa9c2669SDavid Quigley } 4623aa9c2669SDavid Quigley 4624ae42c70aSBryan Schumaker xdr_error: 4625ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4626ae42c70aSBryan Schumaker return status; 4627ae42c70aSBryan Schumaker } 4628ae42c70aSBryan Schumaker 4629ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 46308b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4631aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4632ae42c70aSBryan Schumaker { 4633256e48bbSTrond Myklebust unsigned int savep; 4634ae42c70aSBryan Schumaker uint32_t attrlen, 4635dae100c2SFred Isaman bitmap[3] = {0}; 4636ae42c70aSBryan Schumaker int status; 4637ae42c70aSBryan Schumaker 4638ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4639ae42c70aSBryan Schumaker if (status < 0) 4640ae42c70aSBryan Schumaker goto xdr_error; 4641ae42c70aSBryan Schumaker 4642ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4643ae42c70aSBryan Schumaker if (status < 0) 4644ae42c70aSBryan Schumaker goto xdr_error; 4645ae42c70aSBryan Schumaker 4646ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4647ae42c70aSBryan Schumaker if (status < 0) 4648ae42c70aSBryan Schumaker goto xdr_error; 4649ae42c70aSBryan Schumaker 4650aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4651aa9c2669SDavid Quigley label, server); 4652ae42c70aSBryan Schumaker if (status < 0) 4653ae42c70aSBryan Schumaker goto xdr_error; 4654ae42c70aSBryan Schumaker 4655f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 46561da177e4SLinus Torvalds xdr_error: 46573110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 46581da177e4SLinus Torvalds return status; 46591da177e4SLinus Torvalds } 46601da177e4SLinus Torvalds 4661aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4662aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4663aa9c2669SDavid Quigley { 4664aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4665aa9c2669SDavid Quigley } 4666aa9c2669SDavid Quigley 4667ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 46686926afd1STrond Myklebust const struct nfs_server *server) 4669ae42c70aSBryan Schumaker { 4670aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4671ae42c70aSBryan Schumaker } 46721da177e4SLinus Torvalds 4673504913fbSAndy Adamson /* 4674504913fbSAndy Adamson * Decode potentially multiple layout types. Currently we only support 4675504913fbSAndy Adamson * one layout driver per file system. 4676504913fbSAndy Adamson */ 4677504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr, 4678504913fbSAndy Adamson uint32_t *layouttype) 4679504913fbSAndy Adamson { 4680b8a8a0ddSTrond Myklebust __be32 *p; 4681504913fbSAndy Adamson int num; 4682504913fbSAndy Adamson 4683504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4684504913fbSAndy Adamson if (unlikely(!p)) 4685504913fbSAndy Adamson goto out_overflow; 4686504913fbSAndy Adamson num = be32_to_cpup(p); 4687504913fbSAndy Adamson 4688504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4689504913fbSAndy Adamson if (num == 0) { 4690504913fbSAndy Adamson *layouttype = 0; 4691504913fbSAndy Adamson return 0; 4692504913fbSAndy Adamson } 4693504913fbSAndy Adamson if (num > 1) 4694a030889aSWeston Andros Adamson printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout " 4695a030889aSWeston Andros Adamson "drivers per filesystem not supported\n", __func__); 4696504913fbSAndy Adamson 4697504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4698504913fbSAndy Adamson p = xdr_inline_decode(xdr, num * 4); 4699504913fbSAndy Adamson if (unlikely(!p)) 4700504913fbSAndy Adamson goto out_overflow; 4701504913fbSAndy Adamson *layouttype = be32_to_cpup(p); 4702504913fbSAndy Adamson return 0; 4703504913fbSAndy Adamson out_overflow: 4704504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4705504913fbSAndy Adamson return -EIO; 4706504913fbSAndy Adamson } 4707504913fbSAndy Adamson 4708504913fbSAndy Adamson /* 4709504913fbSAndy Adamson * The type of file system exported. 4710504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4711504913fbSAndy Adamson */ 4712504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4713504913fbSAndy Adamson uint32_t *layouttype) 4714504913fbSAndy Adamson { 4715504913fbSAndy Adamson int status = 0; 4716504913fbSAndy Adamson 4717504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4718504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4719504913fbSAndy Adamson return -EIO; 4720504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4721504913fbSAndy Adamson status = decode_first_pnfs_layout_type(xdr, layouttype); 4722504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 4723504913fbSAndy Adamson } else 4724504913fbSAndy Adamson *layouttype = 0; 4725504913fbSAndy Adamson return status; 4726504913fbSAndy Adamson } 4727504913fbSAndy Adamson 4728dae100c2SFred Isaman /* 4729dae100c2SFred Isaman * The prefered block size for layout directed io 4730dae100c2SFred Isaman */ 4731dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4732dae100c2SFred Isaman uint32_t *res) 4733dae100c2SFred Isaman { 4734dae100c2SFred Isaman __be32 *p; 4735dae100c2SFred Isaman 4736dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4737dae100c2SFred Isaman *res = 0; 4738dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4739dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4740dae100c2SFred Isaman if (unlikely(!p)) { 4741dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4742dae100c2SFred Isaman return -EIO; 4743dae100c2SFred Isaman } 4744dae100c2SFred Isaman *res = be32_to_cpup(p); 4745dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4746dae100c2SFred Isaman } 4747dae100c2SFred Isaman return 0; 4748dae100c2SFred Isaman } 4749dae100c2SFred Isaman 47501da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 47511da177e4SLinus Torvalds { 4752256e48bbSTrond Myklebust unsigned int savep; 4753dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 47541da177e4SLinus Torvalds int status; 47551da177e4SLinus Torvalds 47561da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 47571da177e4SLinus Torvalds goto xdr_error; 47581da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 47591da177e4SLinus Torvalds goto xdr_error; 47601da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 47611da177e4SLinus Torvalds goto xdr_error; 47621da177e4SLinus Torvalds 47631da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 47641da177e4SLinus Torvalds 47651da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 47661da177e4SLinus Torvalds goto xdr_error; 47671da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 47681da177e4SLinus Torvalds goto xdr_error; 47691da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 47701da177e4SLinus Torvalds goto xdr_error; 47711da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 47721da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 47731da177e4SLinus Torvalds goto xdr_error; 47741da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 477555b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 477655b6e774SRicardo Labiaga if (status != 0) 477755b6e774SRicardo Labiaga goto xdr_error; 4778504913fbSAndy Adamson status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype); 4779504913fbSAndy Adamson if (status != 0) 4780504913fbSAndy Adamson goto xdr_error; 4781dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4782dae100c2SFred Isaman if (status) 4783dae100c2SFred Isaman goto xdr_error; 47841da177e4SLinus Torvalds 47851da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 47861da177e4SLinus Torvalds xdr_error: 47873110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 47881da177e4SLinus Torvalds return status; 47891da177e4SLinus Torvalds } 47901da177e4SLinus Torvalds 47911da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 47921da177e4SLinus Torvalds { 47938687b63aSAl Viro __be32 *p; 47941da177e4SLinus Torvalds uint32_t len; 47951da177e4SLinus Torvalds int status; 47961da177e4SLinus Torvalds 47979936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 47989936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 47999936781dSTrond Myklebust 48001da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 48011da177e4SLinus Torvalds if (status) 48021da177e4SLinus Torvalds return status; 48031da177e4SLinus Torvalds 4804c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4805c0eae66eSBenny Halevy if (unlikely(!p)) 4806c0eae66eSBenny Halevy goto out_overflow; 4807cccddf4fSBenny Halevy len = be32_to_cpup(p); 48081da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 48091da177e4SLinus Torvalds return -EIO; 48101da177e4SLinus Torvalds fh->size = len; 4811c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4812c0eae66eSBenny Halevy if (unlikely(!p)) 4813c0eae66eSBenny Halevy goto out_overflow; 481499398d06SBenny Halevy memcpy(fh->data, p, len); 48151da177e4SLinus Torvalds return 0; 4816c0eae66eSBenny Halevy out_overflow: 4817c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4818c0eae66eSBenny Halevy return -EIO; 48191da177e4SLinus Torvalds } 48201da177e4SLinus Torvalds 48211da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 48221da177e4SLinus Torvalds { 48231da177e4SLinus Torvalds int status; 48241da177e4SLinus Torvalds 48251da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 48261da177e4SLinus Torvalds if (status) 48271da177e4SLinus Torvalds return status; 48281da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 48291da177e4SLinus Torvalds } 48301da177e4SLinus Torvalds 48311da177e4SLinus Torvalds /* 48321da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 48331da177e4SLinus Torvalds */ 4834911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 48351da177e4SLinus Torvalds { 4836911d1aafSTrond Myklebust uint64_t offset, length, clientid; 48378687b63aSAl Viro __be32 *p; 4838911d1aafSTrond Myklebust uint32_t namelen, type; 48391da177e4SLinus Torvalds 4840babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4841c0eae66eSBenny Halevy if (unlikely(!p)) 4842c0eae66eSBenny Halevy goto out_overflow; 4843babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 48443ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4845babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4846babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4847911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4848911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4849911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4850911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4851911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4852911d1aafSTrond Myklebust if (type & 1) 4853911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4854911d1aafSTrond Myklebust fl->fl_pid = 0; 4855911d1aafSTrond Myklebust } 4856babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4857babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4858babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4859c0eae66eSBenny Halevy if (likely(p)) 48601da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4861c0eae66eSBenny Halevy out_overflow: 4862c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4863c0eae66eSBenny Halevy return -EIO; 48641da177e4SLinus Torvalds } 48651da177e4SLinus Torvalds 4866911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 48671da177e4SLinus Torvalds { 48681da177e4SLinus Torvalds int status; 48691da177e4SLinus Torvalds 48701da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4871c1d51931STrond Myklebust if (status == -EIO) 4872c1d51931STrond Myklebust goto out; 48731da177e4SLinus Torvalds if (status == 0) { 487407d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 487507d30434SBenny Halevy if (unlikely(status)) 487607d30434SBenny Halevy goto out; 48771da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4878c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4879c1d51931STrond Myklebust if (res->open_seqid != NULL) 4880c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4881c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4882c1d51931STrond Myklebust out: 48831da177e4SLinus Torvalds return status; 48841da177e4SLinus Torvalds } 48851da177e4SLinus Torvalds 4886911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 48871da177e4SLinus Torvalds { 48881da177e4SLinus Torvalds int status; 48891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 48901da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 4891911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 48921da177e4SLinus Torvalds return status; 48931da177e4SLinus Torvalds } 48941da177e4SLinus Torvalds 4895911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 48961da177e4SLinus Torvalds { 48971da177e4SLinus Torvalds int status; 48981da177e4SLinus Torvalds 48991da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 4900c1d51931STrond Myklebust if (status != -EIO) 4901c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 490207d30434SBenny Halevy if (status == 0) 490307d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 49041da177e4SLinus Torvalds return status; 49051da177e4SLinus Torvalds } 49061da177e4SLinus Torvalds 4907d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 4908d3c7b7ccSTrond Myklebust { 4909d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 4910d3c7b7ccSTrond Myklebust } 4911d3c7b7ccSTrond Myklebust 49121da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 49131da177e4SLinus Torvalds { 49141da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 49151da177e4SLinus Torvalds } 49161da177e4SLinus Torvalds 49171da177e4SLinus Torvalds /* This is too sick! */ 49181da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize) 49191da177e4SLinus Torvalds { 49208687b63aSAl Viro __be32 *p; 49211da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 49221da177e4SLinus Torvalds 4923c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4924c0eae66eSBenny Halevy if (unlikely(!p)) 4925c0eae66eSBenny Halevy goto out_overflow; 49266f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 49271da177e4SLinus Torvalds switch (limit_type) { 49281da177e4SLinus Torvalds case 1: 4929cccddf4fSBenny Halevy xdr_decode_hyper(p, maxsize); 49301da177e4SLinus Torvalds break; 49311da177e4SLinus Torvalds case 2: 49326f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 4933cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 49341da177e4SLinus Torvalds *maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 49351da177e4SLinus Torvalds } 49361da177e4SLinus Torvalds return 0; 4937c0eae66eSBenny Halevy out_overflow: 4938c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4939c0eae66eSBenny Halevy return -EIO; 49401da177e4SLinus Torvalds } 49411da177e4SLinus Torvalds 49421da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 49431da177e4SLinus Torvalds { 49448687b63aSAl Viro __be32 *p; 49451da177e4SLinus Torvalds uint32_t delegation_type; 494607d30434SBenny Halevy int status; 49471da177e4SLinus Torvalds 4948c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4949c0eae66eSBenny Halevy if (unlikely(!p)) 4950c0eae66eSBenny Halevy goto out_overflow; 4951cccddf4fSBenny Halevy delegation_type = be32_to_cpup(p); 49521da177e4SLinus Torvalds if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { 49531da177e4SLinus Torvalds res->delegation_type = 0; 49541da177e4SLinus Torvalds return 0; 49551da177e4SLinus Torvalds } 495607d30434SBenny Halevy status = decode_stateid(xdr, &res->delegation); 495707d30434SBenny Halevy if (unlikely(status)) 495807d30434SBenny Halevy return status; 4959c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4960c0eae66eSBenny Halevy if (unlikely(!p)) 4961c0eae66eSBenny Halevy goto out_overflow; 4962cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 496305d564feSAndy Adamson 49641da177e4SLinus Torvalds switch (delegation_type) { 49651da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 49661da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 49671da177e4SLinus Torvalds break; 49681da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 49691da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 49701da177e4SLinus Torvalds if (decode_space_limit(xdr, &res->maxsize) < 0) 49711da177e4SLinus Torvalds return -EIO; 49721da177e4SLinus Torvalds } 49737539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 4974c0eae66eSBenny Halevy out_overflow: 4975c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4976c0eae66eSBenny Halevy return -EIO; 49771da177e4SLinus Torvalds } 49781da177e4SLinus Torvalds 49791da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 49801da177e4SLinus Torvalds { 49818687b63aSAl Viro __be32 *p; 4982aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 49831da177e4SLinus Torvalds int status; 49841da177e4SLinus Torvalds 4985c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 4986c7848f69STrond Myklebust return status; 4987c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 4988c7848f69STrond Myklebust if (status) 4989c7848f69STrond Myklebust return status; 499007d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 499107d30434SBenny Halevy if (unlikely(status)) 49921da177e4SLinus Torvalds return status; 49931da177e4SLinus Torvalds 49941da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 49951da177e4SLinus Torvalds 4996c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4997c0eae66eSBenny Halevy if (unlikely(!p)) 4998c0eae66eSBenny Halevy goto out_overflow; 49996f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5000cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 50011da177e4SLinus Torvalds if (bmlen > 10) 50021da177e4SLinus Torvalds goto xdr_error; 50031da177e4SLinus Torvalds 5004c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5005c0eae66eSBenny Halevy if (unlikely(!p)) 5006c0eae66eSBenny Halevy goto out_overflow; 5007aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5008aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 50096f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5010aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5011aa53ed54SJeff Layton res->attrset[i] = 0; 5012aa53ed54SJeff Layton 50131da177e4SLinus Torvalds return decode_delegation(xdr, res); 50141da177e4SLinus Torvalds xdr_error: 50153110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 50161da177e4SLinus Torvalds return -EIO; 5017c0eae66eSBenny Halevy out_overflow: 5018c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5019c0eae66eSBenny Halevy return -EIO; 50201da177e4SLinus Torvalds } 50211da177e4SLinus Torvalds 50221da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 50231da177e4SLinus Torvalds { 50241da177e4SLinus Torvalds int status; 50251da177e4SLinus Torvalds 50261da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5027c1d51931STrond Myklebust if (status != -EIO) 5028c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 502907d30434SBenny Halevy if (!status) 503007d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 50311da177e4SLinus Torvalds return status; 50321da177e4SLinus Torvalds } 50331da177e4SLinus Torvalds 50341da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 50351da177e4SLinus Torvalds { 50361da177e4SLinus Torvalds int status; 50371da177e4SLinus Torvalds 50381da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5039c1d51931STrond Myklebust if (status != -EIO) 5040c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 504107d30434SBenny Halevy if (!status) 504207d30434SBenny Halevy status = decode_stateid(xdr, &res->stateid); 50431da177e4SLinus Torvalds return status; 50441da177e4SLinus Torvalds } 50451da177e4SLinus Torvalds 50461da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 50471da177e4SLinus Torvalds { 50481da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 50491da177e4SLinus Torvalds } 50501da177e4SLinus Torvalds 50511da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 50521da177e4SLinus Torvalds { 50531da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 50541da177e4SLinus Torvalds } 50551da177e4SLinus Torvalds 50569137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 50579137bdf3SAnna Schumaker struct nfs_pgio_res *res) 50581da177e4SLinus Torvalds { 50598687b63aSAl Viro __be32 *p; 506064bd577eSTrond Myklebust uint32_t count, eof, recvd; 50611da177e4SLinus Torvalds int status; 50621da177e4SLinus Torvalds 50631da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 50641da177e4SLinus Torvalds if (status) 50651da177e4SLinus Torvalds return status; 5066c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5067c0eae66eSBenny Halevy if (unlikely(!p)) 5068c0eae66eSBenny Halevy goto out_overflow; 50696f723f77SBenny Halevy eof = be32_to_cpup(p++); 5070cccddf4fSBenny Halevy count = be32_to_cpup(p); 507164bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 50721da177e4SLinus Torvalds if (count > recvd) { 5073fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 50741da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 50751da177e4SLinus Torvalds count = recvd; 50761da177e4SLinus Torvalds eof = 0; 50771da177e4SLinus Torvalds } 50781da177e4SLinus Torvalds res->eof = eof; 50791da177e4SLinus Torvalds res->count = count; 50801da177e4SLinus Torvalds return 0; 5081c0eae66eSBenny Halevy out_overflow: 5082c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5083c0eae66eSBenny Halevy return -EIO; 50841da177e4SLinus Torvalds } 50851da177e4SLinus Torvalds 50861da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 50871da177e4SLinus Torvalds { 5088bcecff77SChuck Lever int status; 5089cd93710eSChuck Lever __be32 verf[2]; 50901da177e4SLinus Torvalds 50911da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5092db942bbdSBenny Halevy if (!status) 5093db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5094db942bbdSBenny Halevy if (unlikely(status)) 50951da177e4SLinus Torvalds return status; 5096cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 509744109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5098cd93710eSChuck Lever __func__, verf[0], verf[1]); 509964bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 51001da177e4SLinus Torvalds } 51011da177e4SLinus Torvalds 51021da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 51031da177e4SLinus Torvalds { 51041da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5105bcecff77SChuck Lever u32 len, recvd; 51068687b63aSAl Viro __be32 *p; 51071da177e4SLinus Torvalds int status; 51081da177e4SLinus Torvalds 51091da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 51101da177e4SLinus Torvalds if (status) 51111da177e4SLinus Torvalds return status; 51121da177e4SLinus Torvalds 51131da177e4SLinus Torvalds /* Convert length of symlink */ 5114c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5115c0eae66eSBenny Halevy if (unlikely(!p)) 5116c0eae66eSBenny Halevy goto out_overflow; 5117cccddf4fSBenny Halevy len = be32_to_cpup(p); 51181da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5119fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 51201da177e4SLinus Torvalds return -ENAMETOOLONG; 51211da177e4SLinus Torvalds } 512264bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 51231da177e4SLinus Torvalds if (recvd < len) { 5124fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 51251da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 51261da177e4SLinus Torvalds return -EIO; 51271da177e4SLinus Torvalds } 51281da177e4SLinus Torvalds /* 51291da177e4SLinus Torvalds * The XDR encode routine has set things up so that 51301da177e4SLinus Torvalds * the link text will be copied directly into the 51311da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 51321da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 51331da177e4SLinus Torvalds * null-termination). 51341da177e4SLinus Torvalds */ 5135b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 51361da177e4SLinus Torvalds return 0; 5137c0eae66eSBenny Halevy out_overflow: 5138c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5139c0eae66eSBenny Halevy return -EIO; 51401da177e4SLinus Torvalds } 51411da177e4SLinus Torvalds 51421da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 51431da177e4SLinus Torvalds { 51441da177e4SLinus Torvalds int status; 51451da177e4SLinus Torvalds 51461da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 51471da177e4SLinus Torvalds if (status) 51481da177e4SLinus Torvalds goto out; 51491da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 51501da177e4SLinus Torvalds out: 51511da177e4SLinus Torvalds return status; 51521da177e4SLinus Torvalds } 51531da177e4SLinus Torvalds 51541da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 51551da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 51561da177e4SLinus Torvalds { 51571da177e4SLinus Torvalds int status; 51581da177e4SLinus Torvalds 51591da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 51601da177e4SLinus Torvalds if (status) 51611da177e4SLinus Torvalds goto out; 51621da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 51631da177e4SLinus Torvalds goto out; 51641da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 51651da177e4SLinus Torvalds out: 51661da177e4SLinus Torvalds return status; 51671da177e4SLinus Torvalds } 51681da177e4SLinus Torvalds 51691da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 51701da177e4SLinus Torvalds { 51711da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 51721da177e4SLinus Torvalds } 51731da177e4SLinus Torvalds 517456ae19f3STrond Myklebust static int 517556ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 517656ae19f3STrond Myklebust { 517756ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 517856ae19f3STrond Myklebust } 517956ae19f3STrond Myklebust 5180029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5181bf118a34SAndy Adamson struct nfs_getaclres *res) 5182029d105eSJ. Bruce Fields { 5183256e48bbSTrond Myklebust unsigned int savep; 5184029d105eSJ. Bruce Fields uint32_t attrlen, 5185dae100c2SFred Isaman bitmap[3] = {0}; 5186029d105eSJ. Bruce Fields int status; 5187cff298c7STrond Myklebust unsigned int pg_offset; 5188029d105eSJ. Bruce Fields 5189bf118a34SAndy Adamson res->acl_len = 0; 5190029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5191029d105eSJ. Bruce Fields goto out; 51925a006899SSachin Prabhu 5193519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5194519d3959STrond Myklebust 5195cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5196cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 51975a006899SSachin Prabhu 5198029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5199029d105eSJ. Bruce Fields goto out; 5200029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5201029d105eSJ. Bruce Fields goto out; 5202029d105eSJ. Bruce Fields 5203029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5204029d105eSJ. Bruce Fields return -EIO; 5205029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5206029d105eSJ. Bruce Fields 5207bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5208bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5209bf118a34SAndy Adamson * variable length bitmaps.*/ 5210cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5211519d3959STrond Myklebust res->acl_len = attrlen; 52121f1ea6c2STrond Myklebust 52131f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 52141f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 52151f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 52161f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5217519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5218cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5219029d105eSJ. Bruce Fields } 52208c233cf9SJ. Bruce Fields } else 52218c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5222029d105eSJ. Bruce Fields 5223029d105eSJ. Bruce Fields out: 5224029d105eSJ. Bruce Fields return status; 5225029d105eSJ. Bruce Fields } 5226029d105eSJ. Bruce Fields 52271da177e4SLinus Torvalds static int 52281da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 52291da177e4SLinus Torvalds { 52301da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 52311da177e4SLinus Torvalds } 52321da177e4SLinus Torvalds 52339e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 52341da177e4SLinus Torvalds { 52358687b63aSAl Viro __be32 *p; 52361da177e4SLinus Torvalds uint32_t bmlen; 52371da177e4SLinus Torvalds int status; 52381da177e4SLinus Torvalds 52391da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 52401da177e4SLinus Torvalds if (status) 52411da177e4SLinus Torvalds return status; 5242c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5243c0eae66eSBenny Halevy if (unlikely(!p)) 5244c0eae66eSBenny Halevy goto out_overflow; 5245cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5246c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5247c0eae66eSBenny Halevy if (likely(p)) 52481da177e4SLinus Torvalds return 0; 5249c0eae66eSBenny Halevy out_overflow: 5250c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5251c0eae66eSBenny Halevy return -EIO; 52521da177e4SLinus Torvalds } 52531da177e4SLinus Torvalds 5254bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 52551da177e4SLinus Torvalds { 52568687b63aSAl Viro __be32 *p; 52571da177e4SLinus Torvalds uint32_t opnum; 52581da177e4SLinus Torvalds int32_t nfserr; 52591da177e4SLinus Torvalds 5260c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5261c0eae66eSBenny Halevy if (unlikely(!p)) 5262c0eae66eSBenny Halevy goto out_overflow; 52636f723f77SBenny Halevy opnum = be32_to_cpup(p++); 52641da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5265fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 52661da177e4SLinus Torvalds " %d\n", opnum); 52671da177e4SLinus Torvalds return -EIO; 52681da177e4SLinus Torvalds } 5269cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 52701da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5271c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5272c0eae66eSBenny Halevy if (unlikely(!p)) 5273c0eae66eSBenny Halevy goto out_overflow; 5274bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5275bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 52761da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 52771da177e4SLinus Torvalds uint32_t len; 52781da177e4SLinus Torvalds 52791da177e4SLinus Torvalds /* skip netid string */ 5280c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5281c0eae66eSBenny Halevy if (unlikely(!p)) 5282c0eae66eSBenny Halevy goto out_overflow; 5283cccddf4fSBenny Halevy len = be32_to_cpup(p); 5284c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5285c0eae66eSBenny Halevy if (unlikely(!p)) 5286c0eae66eSBenny Halevy goto out_overflow; 52871da177e4SLinus Torvalds 52881da177e4SLinus Torvalds /* skip uaddr string */ 5289c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5290c0eae66eSBenny Halevy if (unlikely(!p)) 5291c0eae66eSBenny Halevy goto out_overflow; 5292cccddf4fSBenny Halevy len = be32_to_cpup(p); 5293c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5294c0eae66eSBenny Halevy if (unlikely(!p)) 5295c0eae66eSBenny Halevy goto out_overflow; 52961da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 52971da177e4SLinus Torvalds } else 5298856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 52991da177e4SLinus Torvalds 53001da177e4SLinus Torvalds return 0; 5301c0eae66eSBenny Halevy out_overflow: 5302c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5303c0eae66eSBenny Halevy return -EIO; 53041da177e4SLinus Torvalds } 53051da177e4SLinus Torvalds 53061da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 53071da177e4SLinus Torvalds { 53081da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 53091da177e4SLinus Torvalds } 53101da177e4SLinus Torvalds 53119137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 53121da177e4SLinus Torvalds { 53138687b63aSAl Viro __be32 *p; 53141da177e4SLinus Torvalds int status; 53151da177e4SLinus Torvalds 53161da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 53171da177e4SLinus Torvalds if (status) 53181da177e4SLinus Torvalds return status; 53191da177e4SLinus Torvalds 53202f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5321c0eae66eSBenny Halevy if (unlikely(!p)) 5322c0eae66eSBenny Halevy goto out_overflow; 53236f723f77SBenny Halevy res->count = be32_to_cpup(p++); 53246f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 53252f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5326c0eae66eSBenny Halevy out_overflow: 5327c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5328c0eae66eSBenny Halevy return -EIO; 53291da177e4SLinus Torvalds } 53301da177e4SLinus Torvalds 53311da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 53321da177e4SLinus Torvalds { 53331da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 53341da177e4SLinus Torvalds } 53351da177e4SLinus Torvalds 5336fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5337fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 53385a5ea0d4SBryan Schumaker { 5339fb15b26fSChuck Lever u32 oid_len; 53405a5ea0d4SBryan Schumaker __be32 *p; 53415a5ea0d4SBryan Schumaker 53425a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 53435a5ea0d4SBryan Schumaker if (unlikely(!p)) 53445a5ea0d4SBryan Schumaker goto out_overflow; 5345fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5346fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 53475a5ea0d4SBryan Schumaker goto out_err; 53485a5ea0d4SBryan Schumaker 5349fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 53505a5ea0d4SBryan Schumaker if (unlikely(!p)) 53515a5ea0d4SBryan Schumaker goto out_overflow; 5352fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5353fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 53545a5ea0d4SBryan Schumaker 53555a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 53565a5ea0d4SBryan Schumaker if (unlikely(!p)) 53575a5ea0d4SBryan Schumaker goto out_overflow; 5358fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5359fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 53605a5ea0d4SBryan Schumaker 53615a5ea0d4SBryan Schumaker return 0; 53625a5ea0d4SBryan Schumaker 53635a5ea0d4SBryan Schumaker out_overflow: 53645a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 53655a5ea0d4SBryan Schumaker return -EIO; 53665a5ea0d4SBryan Schumaker out_err: 53675a5ea0d4SBryan Schumaker return -EINVAL; 53685a5ea0d4SBryan Schumaker } 53695a5ea0d4SBryan Schumaker 537031e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 53715a5ea0d4SBryan Schumaker { 5372fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5373fb15b26fSChuck Lever unsigned int i, num_flavors; 53745a5ea0d4SBryan Schumaker int status; 53755a5ea0d4SBryan Schumaker __be32 *p; 53765a5ea0d4SBryan Schumaker 53775a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 53785a5ea0d4SBryan Schumaker if (unlikely(!p)) 53795a5ea0d4SBryan Schumaker goto out_overflow; 53805a5ea0d4SBryan Schumaker 5381c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5382c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5383c3dfc280SBryan Schumaker 5384c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 53855a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5386c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 53875a5ea0d4SBryan Schumaker break; 53885a5ea0d4SBryan Schumaker 53895a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 53905a5ea0d4SBryan Schumaker if (unlikely(!p)) 53915a5ea0d4SBryan Schumaker goto out_overflow; 53925a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 53935a5ea0d4SBryan Schumaker 53945a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5395613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5396613e901eSBryan Schumaker if (status) 5397613e901eSBryan Schumaker goto out; 53985a5ea0d4SBryan Schumaker } 5399c3dfc280SBryan Schumaker res->flavors->num_flavors++; 54005a5ea0d4SBryan Schumaker } 54015a5ea0d4SBryan Schumaker 540231e4dda4SBryan Schumaker status = 0; 5403613e901eSBryan Schumaker out: 5404613e901eSBryan Schumaker return status; 54055a5ea0d4SBryan Schumaker out_overflow: 54065a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 54075a5ea0d4SBryan Schumaker return -EIO; 54085a5ea0d4SBryan Schumaker } 54095a5ea0d4SBryan Schumaker 541031e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 541131e4dda4SBryan Schumaker { 541231e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 541331e4dda4SBryan Schumaker if (status) 541431e4dda4SBryan Schumaker return status; 541531e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 541631e4dda4SBryan Schumaker } 541731e4dda4SBryan Schumaker 541899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 541931e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 542031e4dda4SBryan Schumaker { 542131e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 542231e4dda4SBryan Schumaker if (status) 542331e4dda4SBryan Schumaker return status; 542431e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 542531e4dda4SBryan Schumaker } 542631e4dda4SBryan Schumaker 54272031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 54282031cd1aSWeston Andros Adamson { 54292031cd1aSWeston Andros Adamson __be32 *p; 54302031cd1aSWeston Andros Adamson uint32_t bitmap_words; 54312031cd1aSWeston Andros Adamson unsigned int i; 54322031cd1aSWeston Andros Adamson 54332031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 54342031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 54352031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 54362031cd1aSWeston Andros Adamson return -EIO; 54372031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 54382031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 54392031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 54402031cd1aSWeston Andros Adamson 54412031cd1aSWeston Andros Adamson return 0; 54422031cd1aSWeston Andros Adamson } 54432031cd1aSWeston Andros Adamson 544499fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 544599fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 544699fe60d0SBenny Halevy { 544799fe60d0SBenny Halevy __be32 *p; 544899fe60d0SBenny Halevy uint32_t dummy; 54492460ba57SBenny Halevy char *dummy_str; 545099fe60d0SBenny Halevy int status; 54517d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 545299fe60d0SBenny Halevy 545399fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 545499fe60d0SBenny Halevy if (status) 545599fe60d0SBenny Halevy return status; 545699fe60d0SBenny Halevy 5457c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5458c0eae66eSBenny Halevy if (unlikely(!p)) 5459c0eae66eSBenny Halevy goto out_overflow; 546032b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5461c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5462c0eae66eSBenny Halevy if (unlikely(!p)) 5463c0eae66eSBenny Halevy goto out_overflow; 546432b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 546532b01310STrond Myklebust res->flags = be32_to_cpup(p++); 546699fe60d0SBenny Halevy 54672031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 54682031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 54692031cd1aSWeston Andros Adamson case SP4_NONE: 54702031cd1aSWeston Andros Adamson break; 54712031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 54722031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 54732031cd1aSWeston Andros Adamson if (status) 54742031cd1aSWeston Andros Adamson return status; 54752031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 54762031cd1aSWeston Andros Adamson if (status) 54772031cd1aSWeston Andros Adamson return status; 54782031cd1aSWeston Andros Adamson break; 54792031cd1aSWeston Andros Adamson default: 54802031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 548199fe60d0SBenny Halevy return -EIO; 54822031cd1aSWeston Andros Adamson } 548399fe60d0SBenny Halevy 5484acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5485c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5486c0eae66eSBenny Halevy if (unlikely(!p)) 5487c0eae66eSBenny Halevy goto out_overflow; 5488acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 548999fe60d0SBenny Halevy 5490acdeb69dSChuck Lever /* server_owner4.so_major_id */ 54912460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 54922460ba57SBenny Halevy if (unlikely(status)) 54932460ba57SBenny Halevy return status; 549478fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 549578fe0f41SWeston Andros Adamson return -EIO; 5496acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5497acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 549878fe0f41SWeston Andros Adamson 5499acdeb69dSChuck Lever /* server_scope4 */ 5500acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5501acdeb69dSChuck Lever if (unlikely(status)) 5502acdeb69dSChuck Lever return status; 5503acdeb69dSChuck Lever if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 5504acdeb69dSChuck Lever return -EIO; 550578fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 550678fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 550778fe0f41SWeston Andros Adamson 55087d2ed9acSWeston Andros Adamson /* Implementation Id */ 55097d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 55107d2ed9acSWeston Andros Adamson if (unlikely(!p)) 55117d2ed9acSWeston Andros Adamson goto out_overflow; 55127d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 55137d2ed9acSWeston Andros Adamson 55147d2ed9acSWeston Andros Adamson if (impl_id_count) { 55157d2ed9acSWeston Andros Adamson /* nii_domain */ 55162460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55172460ba57SBenny Halevy if (unlikely(status)) 55182460ba57SBenny Halevy return status; 55197d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 55207d2ed9acSWeston Andros Adamson return -EIO; 55217d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 552299fe60d0SBenny Halevy 55237d2ed9acSWeston Andros Adamson /* nii_name */ 55247d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 55257d2ed9acSWeston Andros Adamson if (unlikely(status)) 55267d2ed9acSWeston Andros Adamson return status; 55277d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 55287d2ed9acSWeston Andros Adamson return -EIO; 55297d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 55307d2ed9acSWeston Andros Adamson 55317d2ed9acSWeston Andros Adamson /* nii_date */ 55327d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 55337d2ed9acSWeston Andros Adamson if (unlikely(!p)) 55347d2ed9acSWeston Andros Adamson goto out_overflow; 55357d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 55367d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 55377d2ed9acSWeston Andros Adamson 55387d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 55397d2ed9acSWeston Andros Adamson } 554099fe60d0SBenny Halevy return 0; 5541c0eae66eSBenny Halevy out_overflow: 5542c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5543c0eae66eSBenny Halevy return -EIO; 554499fe60d0SBenny Halevy } 5545fc931582SAndy Adamson 5546fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5547fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5548fc931582SAndy Adamson { 5549fc931582SAndy Adamson __be32 *p; 5550c9c30dd5SBenny Halevy u32 nr_attrs, val; 5551fc931582SAndy Adamson 5552c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5553c0eae66eSBenny Halevy if (unlikely(!p)) 5554c0eae66eSBenny Halevy goto out_overflow; 5555c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5556c9c30dd5SBenny Halevy if (val) 5557c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 55586f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 55596f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 55606f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 55616f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 55626f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5563cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5564fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5565a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5566a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5567fc931582SAndy Adamson return -EINVAL; 5568fc931582SAndy Adamson } 5569c0eae66eSBenny Halevy if (nr_attrs == 1) { 5570c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5571c0eae66eSBenny Halevy if (unlikely(!p)) 5572c0eae66eSBenny Halevy goto out_overflow; 5573c0eae66eSBenny Halevy } 5574fc931582SAndy Adamson return 0; 5575c0eae66eSBenny Halevy out_overflow: 5576c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5577c0eae66eSBenny Halevy return -EIO; 5578fc931582SAndy Adamson } 5579fc931582SAndy Adamson 5580e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5581e78291e4SBenny Halevy { 5582e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5583fc931582SAndy Adamson } 5584fc931582SAndy Adamson 55857c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 55867c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 55877c44f1aeSWeston Andros Adamson { 55887c44f1aeSWeston Andros Adamson __be32 *p; 55897c44f1aeSWeston Andros Adamson int status; 55907c44f1aeSWeston Andros Adamson 55917c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 55927c44f1aeSWeston Andros Adamson if (!status) 55937c44f1aeSWeston Andros Adamson status = decode_sessionid(xdr, &res->session->sess_id); 55947c44f1aeSWeston Andros Adamson if (unlikely(status)) 55957c44f1aeSWeston Andros Adamson return status; 55967c44f1aeSWeston Andros Adamson 55977c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 55987c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 55997c44f1aeSWeston Andros Adamson if (unlikely(!p)) 56007c44f1aeSWeston Andros Adamson goto out_overflow; 56017c44f1aeSWeston Andros Adamson 56027c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 56037c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 56047c44f1aeSWeston Andros Adamson return -EIO; 56057c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 56067c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 56077c44f1aeSWeston Andros Adamson else 56087c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 56097c44f1aeSWeston Andros Adamson 56107c44f1aeSWeston Andros Adamson return 0; 56117c44f1aeSWeston Andros Adamson out_overflow: 56127c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 56137c44f1aeSWeston Andros Adamson return -EIO; 56147c44f1aeSWeston Andros Adamson } 56157c44f1aeSWeston Andros Adamson 5616fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5617fc931582SAndy Adamson struct nfs41_create_session_res *res) 5618fc931582SAndy Adamson { 5619fc931582SAndy Adamson __be32 *p; 5620fc931582SAndy Adamson int status; 5621fc931582SAndy Adamson struct nfs_client *clp = res->client; 5622fc931582SAndy Adamson struct nfs4_session *session = clp->cl_session; 5623fc931582SAndy Adamson 5624fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5625e78291e4SBenny Halevy if (!status) 5626e78291e4SBenny Halevy status = decode_sessionid(xdr, &session->sess_id); 5627e78291e4SBenny Halevy if (unlikely(status)) 5628fc931582SAndy Adamson return status; 5629fc931582SAndy Adamson 5630fc931582SAndy Adamson /* seqid, flags */ 5631c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5632c0eae66eSBenny Halevy if (unlikely(!p)) 5633c0eae66eSBenny Halevy goto out_overflow; 56346f723f77SBenny Halevy clp->cl_seqid = be32_to_cpup(p++); 5635cccddf4fSBenny Halevy session->flags = be32_to_cpup(p); 5636fc931582SAndy Adamson 5637fc931582SAndy Adamson /* Channel attributes */ 5638fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->fc_attrs); 5639fc931582SAndy Adamson if (!status) 5640fc931582SAndy Adamson status = decode_chan_attrs(xdr, &session->bc_attrs); 5641fc931582SAndy Adamson return status; 5642c0eae66eSBenny Halevy out_overflow: 5643c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5644c0eae66eSBenny Halevy return -EIO; 5645fc931582SAndy Adamson } 56460f3e66c6SAndy Adamson 56470f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 56480f3e66c6SAndy Adamson { 56490f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 56500f3e66c6SAndy Adamson } 565118019753SRicardo Labiaga 565266245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 565366245539STrond Myklebust { 565466245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 565566245539STrond Myklebust } 565666245539STrond Myklebust 565718019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 565818019753SRicardo Labiaga { 565918019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 566018019753SRicardo Labiaga } 566199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 566299fe60d0SBenny Halevy 56639b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 56649b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 56659b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 56669b7b9fccSAndy Adamson { 56679b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5668e3725ec0STrond Myklebust struct nfs4_session *session; 5669fc01cea9SAndy Adamson struct nfs4_sessionid id; 5670fc01cea9SAndy Adamson u32 dummy; 5671fc01cea9SAndy Adamson int status; 5672fc01cea9SAndy Adamson __be32 *p; 5673fc01cea9SAndy Adamson 5674e3725ec0STrond Myklebust if (res->sr_slot == NULL) 56759b7b9fccSAndy Adamson return 0; 56763bd2384aSChuck Lever if (!res->sr_slot->table->session) 56773bd2384aSChuck Lever return 0; 56789b7b9fccSAndy Adamson 5679fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5680e78291e4SBenny Halevy if (!status) 5681e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5682e78291e4SBenny Halevy if (unlikely(status)) 5683fc01cea9SAndy Adamson goto out_err; 56849b7b9fccSAndy Adamson 5685fc01cea9SAndy Adamson /* 5686fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5687fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5688fc01cea9SAndy Adamson */ 5689fdcb4577STrond Myklebust status = -EREMOTEIO; 5690e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5691fc01cea9SAndy Adamson 5692e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5693fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5694fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5695fc01cea9SAndy Adamson goto out_err; 5696fc01cea9SAndy Adamson } 5697e78291e4SBenny Halevy 5698c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5699c0eae66eSBenny Halevy if (unlikely(!p)) 5700c0eae66eSBenny Halevy goto out_overflow; 5701e78291e4SBenny Halevy 5702fc01cea9SAndy Adamson /* seqid */ 57036f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5704dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5705fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5706fc01cea9SAndy Adamson goto out_err; 5707fc01cea9SAndy Adamson } 5708fc01cea9SAndy Adamson /* slot id */ 57096f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5710df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5711fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5712fc01cea9SAndy Adamson goto out_err; 5713fc01cea9SAndy Adamson } 5714da0507b7STrond Myklebust /* highest slot id */ 5715da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5716464ee9f9STrond Myklebust /* target highest slot id */ 5717464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 57180629e370SAlexandros Batsakis /* result flags */ 57190629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5720fc01cea9SAndy Adamson status = 0; 5721fc01cea9SAndy Adamson out_err: 5722fc01cea9SAndy Adamson res->sr_status = status; 5723fc01cea9SAndy Adamson return status; 5724c0eae66eSBenny Halevy out_overflow: 5725c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5726c0eae66eSBenny Halevy status = -EIO; 5727c0eae66eSBenny Halevy goto out_err; 5728fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 57299b7b9fccSAndy Adamson return 0; 5730fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 57319b7b9fccSAndy Adamson } 57329b7b9fccSAndy Adamson 5733b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 5734b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 5735b1f69b75SAndy Adamson struct pnfs_device *pdev) 5736b1f69b75SAndy Adamson { 5737b1f69b75SAndy Adamson __be32 *p; 5738b1f69b75SAndy Adamson uint32_t len, type; 5739b1f69b75SAndy Adamson int status; 5740b1f69b75SAndy Adamson 5741b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5742b1f69b75SAndy Adamson if (status) { 5743b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5744b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5745b1f69b75SAndy Adamson if (unlikely(!p)) 5746b1f69b75SAndy Adamson goto out_overflow; 5747b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5748b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5749b1f69b75SAndy Adamson __func__, pdev->mincount); 5750b1f69b75SAndy Adamson } 5751b1f69b75SAndy Adamson return status; 5752b1f69b75SAndy Adamson } 5753b1f69b75SAndy Adamson 5754b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5755b1f69b75SAndy Adamson if (unlikely(!p)) 5756b1f69b75SAndy Adamson goto out_overflow; 5757b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5758b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5759b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5760b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5761b1f69b75SAndy Adamson return -EINVAL; 5762b1f69b75SAndy Adamson } 5763b1f69b75SAndy Adamson /* 5764b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5765b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5766b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5767b1f69b75SAndy Adamson */ 5768b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 576913fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 577013fe4ba1STrond Myklebust goto out_overflow; 5771b1f69b75SAndy Adamson 5772b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5773b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5774b1f69b75SAndy Adamson if (unlikely(!p)) 5775b1f69b75SAndy Adamson goto out_overflow; 5776b1f69b75SAndy Adamson len = be32_to_cpup(p); 5777b1f69b75SAndy Adamson if (len) { 5778ead00597SChuck Lever uint32_t i; 5779b1f69b75SAndy Adamson 5780b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5781b1f69b75SAndy Adamson if (unlikely(!p)) 5782b1f69b75SAndy Adamson goto out_overflow; 578384c9dee3SChristoph Hellwig 578484c9dee3SChristoph Hellwig if (be32_to_cpup(p++) & 578584c9dee3SChristoph Hellwig ~(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE)) { 578684c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 578784c9dee3SChristoph Hellwig __func__); 578884c9dee3SChristoph Hellwig } 578984c9dee3SChristoph Hellwig 579084c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 579184c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 579284c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 5793b1f69b75SAndy Adamson __func__); 5794b1f69b75SAndy Adamson return -EIO; 5795b1f69b75SAndy Adamson } 5796b1f69b75SAndy Adamson } 5797b1f69b75SAndy Adamson } 5798b1f69b75SAndy Adamson return 0; 5799b1f69b75SAndy Adamson out_overflow: 5800b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5801b1f69b75SAndy Adamson return -EIO; 5802b1f69b75SAndy Adamson } 5803b1f69b75SAndy Adamson 5804b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5805b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5806b1f69b75SAndy Adamson { 5807b1f69b75SAndy Adamson __be32 *p; 5808b1f69b75SAndy Adamson int status; 5809b1f69b75SAndy Adamson u32 layout_count; 581064bd577eSTrond Myklebust u32 recvd; 5811b1f69b75SAndy Adamson 5812b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5813b1f69b75SAndy Adamson if (status) 5814b1f69b75SAndy Adamson return status; 5815ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5816b1f69b75SAndy Adamson if (unlikely(!p)) 5817b1f69b75SAndy Adamson goto out_overflow; 5818ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 5819ea9d23f5STrond Myklebust decode_stateid(xdr, &res->stateid); 5820ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5821ea9d23f5STrond Myklebust if (unlikely(!p)) 5822ea9d23f5STrond Myklebust goto out_overflow; 5823b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5824b1f69b75SAndy Adamson if (!layout_count) { 5825b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5826b1f69b75SAndy Adamson __func__); 5827b1f69b75SAndy Adamson return -EINVAL; 5828b1f69b75SAndy Adamson } 5829b1f69b75SAndy Adamson 583035124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5831b1f69b75SAndy Adamson if (unlikely(!p)) 5832b1f69b75SAndy Adamson goto out_overflow; 5833b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5834b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5835b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5836b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 583735124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5838b1f69b75SAndy Adamson 5839b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5840b1f69b75SAndy Adamson __func__, 5841b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5842b1f69b75SAndy Adamson (unsigned long)res->range.length, 5843b1f69b75SAndy Adamson res->range.iomode, 5844b1f69b75SAndy Adamson res->type, 584535124a09SWeston Andros Adamson res->layoutp->len); 5846b1f69b75SAndy Adamson 584764bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 584835124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 584935124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 585035124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 585135124a09SWeston Andros Adamson res->layoutp->len, recvd); 585235124a09SWeston Andros Adamson return -EINVAL; 585335124a09SWeston Andros Adamson } 585435124a09SWeston Andros Adamson 5855b1f69b75SAndy Adamson if (layout_count > 1) { 5856b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 5857b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 5858b1f69b75SAndy Adamson * the client may see a response that is less than the 5859b1f69b75SAndy Adamson * minimum it requested. 5860b1f69b75SAndy Adamson */ 5861b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 5862b1f69b75SAndy Adamson __func__, layout_count); 5863b1f69b75SAndy Adamson } 5864b1f69b75SAndy Adamson 5865b1f69b75SAndy Adamson return 0; 5866b1f69b75SAndy Adamson out_overflow: 5867b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5868b1f69b75SAndy Adamson return -EIO; 5869b1f69b75SAndy Adamson } 5870863a3c6cSAndy Adamson 5871cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 5872cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 5873cbe82603SBenny Halevy { 5874cbe82603SBenny Halevy __be32 *p; 5875cbe82603SBenny Halevy int status; 5876cbe82603SBenny Halevy 5877cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 5878cbe82603SBenny Halevy if (status) 5879cbe82603SBenny Halevy return status; 5880cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 5881cbe82603SBenny Halevy if (unlikely(!p)) 5882cbe82603SBenny Halevy goto out_overflow; 5883cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 5884cbe82603SBenny Halevy if (res->lrs_present) 5885cbe82603SBenny Halevy status = decode_stateid(xdr, &res->stateid); 5886cbe82603SBenny Halevy return status; 5887cbe82603SBenny Halevy out_overflow: 5888cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 5889cbe82603SBenny Halevy return -EIO; 5890cbe82603SBenny Halevy } 5891cbe82603SBenny Halevy 5892863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 5893863a3c6cSAndy Adamson struct rpc_rqst *req, 5894863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 5895863a3c6cSAndy Adamson { 5896863a3c6cSAndy Adamson __be32 *p; 5897863a3c6cSAndy Adamson __u32 sizechanged; 5898863a3c6cSAndy Adamson int status; 5899863a3c6cSAndy Adamson 5900863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 5901db29c089SAndy Adamson res->status = status; 5902863a3c6cSAndy Adamson if (status) 5903863a3c6cSAndy Adamson return status; 5904863a3c6cSAndy Adamson 5905863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 5906863a3c6cSAndy Adamson if (unlikely(!p)) 5907863a3c6cSAndy Adamson goto out_overflow; 5908863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 5909863a3c6cSAndy Adamson 5910863a3c6cSAndy Adamson if (sizechanged) { 5911863a3c6cSAndy Adamson /* throw away new size */ 5912863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 5913863a3c6cSAndy Adamson if (unlikely(!p)) 5914863a3c6cSAndy Adamson goto out_overflow; 5915863a3c6cSAndy Adamson } 5916863a3c6cSAndy Adamson return 0; 5917863a3c6cSAndy Adamson out_overflow: 5918863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 5919863a3c6cSAndy Adamson return -EIO; 5920863a3c6cSAndy Adamson } 59217d974794SBryan Schumaker 59227d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 59237d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 59247d974794SBryan Schumaker { 59257d974794SBryan Schumaker __be32 *p; 59267d974794SBryan Schumaker int status; 59277d974794SBryan Schumaker int num_res; 59287d974794SBryan Schumaker 59297d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 59307d974794SBryan Schumaker if (status) 59317d974794SBryan Schumaker return status; 59327d974794SBryan Schumaker 59337d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 59347d974794SBryan Schumaker if (unlikely(!p)) 59357d974794SBryan Schumaker goto out_overflow; 59367d974794SBryan Schumaker num_res = be32_to_cpup(p++); 59377d974794SBryan Schumaker if (num_res != 1) 59387d974794SBryan Schumaker goto out; 59397d974794SBryan Schumaker 59407d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 59417d974794SBryan Schumaker if (unlikely(!p)) 59427d974794SBryan Schumaker goto out_overflow; 59437d974794SBryan Schumaker res->status = be32_to_cpup(p++); 59441cab0652SBryan Schumaker 59451cab0652SBryan Schumaker return status; 59467d974794SBryan Schumaker out_overflow: 59477d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 59487d974794SBryan Schumaker out: 59497d974794SBryan Schumaker return -EIO; 59507d974794SBryan Schumaker } 59519aeda35fSBryan Schumaker 59529aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 59539aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 59549aeda35fSBryan Schumaker { 59559f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 59569aeda35fSBryan Schumaker return res->status; 59579aeda35fSBryan Schumaker } 5958b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 5959b1f69b75SAndy Adamson 59601da177e4SLinus Torvalds /* 596149c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 596249c2559eSBenny Halevy */ 596349c2559eSBenny Halevy 596449c2559eSBenny Halevy /* 59651da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 59661da177e4SLinus Torvalds */ 5967bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 5968bf269551SChuck Lever struct xdr_stream *xdr, 5969bf269551SChuck Lever struct nfs_closeres *res) 59701da177e4SLinus Torvalds { 59711da177e4SLinus Torvalds struct compound_hdr hdr; 59721da177e4SLinus Torvalds int status; 59731da177e4SLinus Torvalds 5974bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 59751da177e4SLinus Torvalds if (status) 59761da177e4SLinus Torvalds goto out; 5977bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 59789b7b9fccSAndy Adamson if (status) 59799b7b9fccSAndy Adamson goto out; 5980bf269551SChuck Lever status = decode_putfh(xdr); 59811da177e4SLinus Torvalds if (status) 59821da177e4SLinus Torvalds goto out; 5983bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 5984516a6af6STrond Myklebust if (status != 0) 5985516a6af6STrond Myklebust goto out; 59866926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 59871da177e4SLinus Torvalds out: 59881da177e4SLinus Torvalds return status; 59891da177e4SLinus Torvalds } 59901da177e4SLinus Torvalds 59911da177e4SLinus Torvalds /* 59921da177e4SLinus Torvalds * Decode ACCESS response 59931da177e4SLinus Torvalds */ 5994bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 5995bf269551SChuck Lever struct nfs4_accessres *res) 59961da177e4SLinus Torvalds { 59971da177e4SLinus Torvalds struct compound_hdr hdr; 59981da177e4SLinus Torvalds int status; 59991da177e4SLinus Torvalds 6000bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60019b7b9fccSAndy Adamson if (status) 60029b7b9fccSAndy Adamson goto out; 6003bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60049b7b9fccSAndy Adamson if (status) 60051da177e4SLinus Torvalds goto out; 6006bf269551SChuck Lever status = decode_putfh(xdr); 600776b32999STrond Myklebust if (status != 0) 600876b32999STrond Myklebust goto out; 60096168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 601076b32999STrond Myklebust if (status != 0) 601176b32999STrond Myklebust goto out; 60126926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 60131da177e4SLinus Torvalds out: 60141da177e4SLinus Torvalds return status; 60151da177e4SLinus Torvalds } 60161da177e4SLinus Torvalds 60171da177e4SLinus Torvalds /* 60181da177e4SLinus Torvalds * Decode LOOKUP response 60191da177e4SLinus Torvalds */ 6020bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6021bf269551SChuck Lever struct nfs4_lookup_res *res) 60221da177e4SLinus Torvalds { 60231da177e4SLinus Torvalds struct compound_hdr hdr; 60241da177e4SLinus Torvalds int status; 60251da177e4SLinus Torvalds 6026bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60279b7b9fccSAndy Adamson if (status) 60289b7b9fccSAndy Adamson goto out; 6029bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60309b7b9fccSAndy Adamson if (status) 60311da177e4SLinus Torvalds goto out; 6032bf269551SChuck Lever status = decode_putfh(xdr); 6033bf269551SChuck Lever if (status) 60341da177e4SLinus Torvalds goto out; 6035bf269551SChuck Lever status = decode_lookup(xdr); 6036bf269551SChuck Lever if (status) 60371da177e4SLinus Torvalds goto out; 6038bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6039bf269551SChuck Lever if (status) 60401da177e4SLinus Torvalds goto out; 6041aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 60421da177e4SLinus Torvalds out: 60431da177e4SLinus Torvalds return status; 60441da177e4SLinus Torvalds } 60451da177e4SLinus Torvalds 60461da177e4SLinus Torvalds /* 60471da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 60481da177e4SLinus Torvalds */ 6049bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6050bf269551SChuck Lever struct xdr_stream *xdr, 6051bf269551SChuck Lever struct nfs4_lookup_res *res) 60521da177e4SLinus Torvalds { 60531da177e4SLinus Torvalds struct compound_hdr hdr; 60541da177e4SLinus Torvalds int status; 60551da177e4SLinus Torvalds 6056bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60579b7b9fccSAndy Adamson if (status) 60589b7b9fccSAndy Adamson goto out; 6059bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60609b7b9fccSAndy Adamson if (status) 60611da177e4SLinus Torvalds goto out; 6062bf269551SChuck Lever status = decode_putrootfh(xdr); 6063bf269551SChuck Lever if (status) 60641da177e4SLinus Torvalds goto out; 6065bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6066bf269551SChuck Lever if (status == 0) 6067aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6068aa9c2669SDavid Quigley res->label, res->server); 60691da177e4SLinus Torvalds out: 60701da177e4SLinus Torvalds return status; 60711da177e4SLinus Torvalds } 60721da177e4SLinus Torvalds 60731da177e4SLinus Torvalds /* 60741da177e4SLinus Torvalds * Decode REMOVE response 60751da177e4SLinus Torvalds */ 6076bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6077bf269551SChuck Lever struct nfs_removeres *res) 60781da177e4SLinus Torvalds { 60791da177e4SLinus Torvalds struct compound_hdr hdr; 60801da177e4SLinus Torvalds int status; 60811da177e4SLinus Torvalds 6082bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 60839b7b9fccSAndy Adamson if (status) 60849b7b9fccSAndy Adamson goto out; 6085bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 60869b7b9fccSAndy Adamson if (status) 60871da177e4SLinus Torvalds goto out; 6088bf269551SChuck Lever status = decode_putfh(xdr); 6089bf269551SChuck Lever if (status) 609016e42959STrond Myklebust goto out; 6091bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 60921da177e4SLinus Torvalds out: 60931da177e4SLinus Torvalds return status; 60941da177e4SLinus Torvalds } 60951da177e4SLinus Torvalds 60961da177e4SLinus Torvalds /* 60971da177e4SLinus Torvalds * Decode RENAME response 60981da177e4SLinus Torvalds */ 6099bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6100bf269551SChuck Lever struct nfs_renameres *res) 61011da177e4SLinus Torvalds { 61021da177e4SLinus Torvalds struct compound_hdr hdr; 61031da177e4SLinus Torvalds int status; 61041da177e4SLinus Torvalds 6105bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61069b7b9fccSAndy Adamson if (status) 61079b7b9fccSAndy Adamson goto out; 6108bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61099b7b9fccSAndy Adamson if (status) 61101da177e4SLinus Torvalds goto out; 6111bf269551SChuck Lever status = decode_putfh(xdr); 6112bf269551SChuck Lever if (status) 61131da177e4SLinus Torvalds goto out; 6114bf269551SChuck Lever status = decode_savefh(xdr); 6115bf269551SChuck Lever if (status) 61161da177e4SLinus Torvalds goto out; 6117bf269551SChuck Lever status = decode_putfh(xdr); 6118bf269551SChuck Lever if (status) 61191da177e4SLinus Torvalds goto out; 6120bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 61211da177e4SLinus Torvalds out: 61221da177e4SLinus Torvalds return status; 61231da177e4SLinus Torvalds } 61241da177e4SLinus Torvalds 61251da177e4SLinus Torvalds /* 61261da177e4SLinus Torvalds * Decode LINK response 61271da177e4SLinus Torvalds */ 6128bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6129bf269551SChuck Lever struct nfs4_link_res *res) 61301da177e4SLinus Torvalds { 61311da177e4SLinus Torvalds struct compound_hdr hdr; 61321da177e4SLinus Torvalds int status; 61331da177e4SLinus Torvalds 6134bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61359b7b9fccSAndy Adamson if (status) 61369b7b9fccSAndy Adamson goto out; 6137bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61389b7b9fccSAndy Adamson if (status) 61391da177e4SLinus Torvalds goto out; 6140bf269551SChuck Lever status = decode_putfh(xdr); 6141bf269551SChuck Lever if (status) 61421da177e4SLinus Torvalds goto out; 6143bf269551SChuck Lever status = decode_savefh(xdr); 6144bf269551SChuck Lever if (status) 61451da177e4SLinus Torvalds goto out; 6146bf269551SChuck Lever status = decode_putfh(xdr); 6147bf269551SChuck Lever if (status) 61481da177e4SLinus Torvalds goto out; 6149bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6150bf269551SChuck Lever if (status) 615191ba2eeeSTrond Myklebust goto out; 615291ba2eeeSTrond Myklebust /* 615391ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 615491ba2eeeSTrond Myklebust * filehandle. 615591ba2eeeSTrond Myklebust */ 6156bf269551SChuck Lever status = decode_restorefh(xdr); 6157bf269551SChuck Lever if (status) 615891ba2eeeSTrond Myklebust goto out; 6159aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 61601da177e4SLinus Torvalds out: 61611da177e4SLinus Torvalds return status; 61621da177e4SLinus Torvalds } 61631da177e4SLinus Torvalds 61641da177e4SLinus Torvalds /* 61651da177e4SLinus Torvalds * Decode CREATE response 61661da177e4SLinus Torvalds */ 6167bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6168bf269551SChuck Lever struct nfs4_create_res *res) 61691da177e4SLinus Torvalds { 61701da177e4SLinus Torvalds struct compound_hdr hdr; 61711da177e4SLinus Torvalds int status; 61721da177e4SLinus Torvalds 6173bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61749b7b9fccSAndy Adamson if (status) 61759b7b9fccSAndy Adamson goto out; 6176bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61779b7b9fccSAndy Adamson if (status) 61781da177e4SLinus Torvalds goto out; 6179bf269551SChuck Lever status = decode_putfh(xdr); 6180bf269551SChuck Lever if (status) 61811da177e4SLinus Torvalds goto out; 6182bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6183bf269551SChuck Lever if (status) 61841da177e4SLinus Torvalds goto out; 6185bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6186bf269551SChuck Lever if (status) 61871da177e4SLinus Torvalds goto out; 6188aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 61891da177e4SLinus Torvalds out: 61901da177e4SLinus Torvalds return status; 61911da177e4SLinus Torvalds } 61921da177e4SLinus Torvalds 61931da177e4SLinus Torvalds /* 61941da177e4SLinus Torvalds * Decode SYMLINK response 61951da177e4SLinus Torvalds */ 6196bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6197bf269551SChuck Lever struct nfs4_create_res *res) 61981da177e4SLinus Torvalds { 6199bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 62001da177e4SLinus Torvalds } 62011da177e4SLinus Torvalds 62021da177e4SLinus Torvalds /* 62031da177e4SLinus Torvalds * Decode GETATTR response 62041da177e4SLinus Torvalds */ 6205bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6206bf269551SChuck Lever struct nfs4_getattr_res *res) 62071da177e4SLinus Torvalds { 62081da177e4SLinus Torvalds struct compound_hdr hdr; 62091da177e4SLinus Torvalds int status; 62101da177e4SLinus Torvalds 6211bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62121da177e4SLinus Torvalds if (status) 62131da177e4SLinus Torvalds goto out; 6214bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62159b7b9fccSAndy Adamson if (status) 62169b7b9fccSAndy Adamson goto out; 6217bf269551SChuck Lever status = decode_putfh(xdr); 62181da177e4SLinus Torvalds if (status) 62191da177e4SLinus Torvalds goto out; 6220aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 62211da177e4SLinus Torvalds out: 62221da177e4SLinus Torvalds return status; 62231da177e4SLinus Torvalds } 62241da177e4SLinus Torvalds 622523ec6965SJ. Bruce Fields /* 622623ec6965SJ. Bruce Fields * Encode an SETACL request 622723ec6965SJ. Bruce Fields */ 62289f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 62299f06c719SChuck Lever struct nfs_setaclargs *args) 623023ec6965SJ. Bruce Fields { 623123ec6965SJ. Bruce Fields struct compound_hdr hdr = { 623266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 623323ec6965SJ. Bruce Fields }; 623423ec6965SJ. Bruce Fields 62359f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 62369f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 62379f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 62389f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6239d017931cSAndy Adamson encode_nops(&hdr); 624023ec6965SJ. Bruce Fields } 624105d564feSAndy Adamson 624223ec6965SJ. Bruce Fields /* 624323ec6965SJ. Bruce Fields * Decode SETACL response 624423ec6965SJ. Bruce Fields */ 624523ec6965SJ. Bruce Fields static int 6246bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 624773c403a9SBenny Halevy struct nfs_setaclres *res) 624823ec6965SJ. Bruce Fields { 624923ec6965SJ. Bruce Fields struct compound_hdr hdr; 625023ec6965SJ. Bruce Fields int status; 625123ec6965SJ. Bruce Fields 6252bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 625323ec6965SJ. Bruce Fields if (status) 625423ec6965SJ. Bruce Fields goto out; 6255bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62569b7b9fccSAndy Adamson if (status) 62579b7b9fccSAndy Adamson goto out; 6258bf269551SChuck Lever status = decode_putfh(xdr); 625923ec6965SJ. Bruce Fields if (status) 626023ec6965SJ. Bruce Fields goto out; 6261bf269551SChuck Lever status = decode_setattr(xdr); 626223ec6965SJ. Bruce Fields out: 626323ec6965SJ. Bruce Fields return status; 626423ec6965SJ. Bruce Fields } 62651da177e4SLinus Torvalds 62661da177e4SLinus Torvalds /* 6267029d105eSJ. Bruce Fields * Decode GETACL response 6268029d105eSJ. Bruce Fields */ 6269029d105eSJ. Bruce Fields static int 6270bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6271663c79b3SBenny Halevy struct nfs_getaclres *res) 6272029d105eSJ. Bruce Fields { 6273029d105eSJ. Bruce Fields struct compound_hdr hdr; 6274029d105eSJ. Bruce Fields int status; 6275029d105eSJ. Bruce Fields 6276331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6277331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6278331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6279331818f1STrond Myklebust } 6280bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6281029d105eSJ. Bruce Fields if (status) 6282029d105eSJ. Bruce Fields goto out; 6283bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62849b7b9fccSAndy Adamson if (status) 62859b7b9fccSAndy Adamson goto out; 6286bf269551SChuck Lever status = decode_putfh(xdr); 6287029d105eSJ. Bruce Fields if (status) 6288029d105eSJ. Bruce Fields goto out; 6289bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6290029d105eSJ. Bruce Fields 6291029d105eSJ. Bruce Fields out: 6292029d105eSJ. Bruce Fields return status; 6293029d105eSJ. Bruce Fields } 6294029d105eSJ. Bruce Fields 6295029d105eSJ. Bruce Fields /* 62961da177e4SLinus Torvalds * Decode CLOSE response 62971da177e4SLinus Torvalds */ 6298bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6299bf269551SChuck Lever struct nfs_closeres *res) 63001da177e4SLinus Torvalds { 63011da177e4SLinus Torvalds struct compound_hdr hdr; 63021da177e4SLinus Torvalds int status; 63031da177e4SLinus Torvalds 6304bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63051da177e4SLinus Torvalds if (status) 63061da177e4SLinus Torvalds goto out; 6307bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63089b7b9fccSAndy Adamson if (status) 63099b7b9fccSAndy Adamson goto out; 6310bf269551SChuck Lever status = decode_putfh(xdr); 63111da177e4SLinus Torvalds if (status) 63121da177e4SLinus Torvalds goto out; 6313bf269551SChuck Lever status = decode_close(xdr, res); 6314516a6af6STrond Myklebust if (status != 0) 6315516a6af6STrond Myklebust goto out; 6316516a6af6STrond Myklebust /* 6317516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6318516a6af6STrond Myklebust * in which case the getattr call will fail with 6319516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6320516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6321516a6af6STrond Myklebust */ 63226926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 63231da177e4SLinus Torvalds out: 63241da177e4SLinus Torvalds return status; 63251da177e4SLinus Torvalds } 63261da177e4SLinus Torvalds 63271da177e4SLinus Torvalds /* 63281da177e4SLinus Torvalds * Decode OPEN response 63291da177e4SLinus Torvalds */ 6330bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6331bf269551SChuck Lever struct nfs_openres *res) 63321da177e4SLinus Torvalds { 63331da177e4SLinus Torvalds struct compound_hdr hdr; 63341da177e4SLinus Torvalds int status; 63351da177e4SLinus Torvalds 6336bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63371da177e4SLinus Torvalds if (status) 63381da177e4SLinus Torvalds goto out; 6339bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63409b7b9fccSAndy Adamson if (status) 63419b7b9fccSAndy Adamson goto out; 6342bf269551SChuck Lever status = decode_putfh(xdr); 63431da177e4SLinus Torvalds if (status) 63441da177e4SLinus Torvalds goto out; 6345bf269551SChuck Lever status = decode_open(xdr, res); 63461da177e4SLinus Torvalds if (status) 63471da177e4SLinus Torvalds goto out; 634801913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 634901913b49SWeston Andros Adamson if (status) 63501da177e4SLinus Torvalds goto out; 6351ae2bb032SWeston Andros Adamson if (res->access_request) 63526168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6353aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 63541da177e4SLinus Torvalds out: 63551da177e4SLinus Torvalds return status; 63561da177e4SLinus Torvalds } 63571da177e4SLinus Torvalds 63581da177e4SLinus Torvalds /* 63591da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 63601da177e4SLinus Torvalds */ 6361bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6362bf269551SChuck Lever struct xdr_stream *xdr, 6363bf269551SChuck Lever struct nfs_open_confirmres *res) 63641da177e4SLinus Torvalds { 63651da177e4SLinus Torvalds struct compound_hdr hdr; 63661da177e4SLinus Torvalds int status; 63671da177e4SLinus Torvalds 6368bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63691da177e4SLinus Torvalds if (status) 63701da177e4SLinus Torvalds goto out; 6371bf269551SChuck Lever status = decode_putfh(xdr); 63721da177e4SLinus Torvalds if (status) 63731da177e4SLinus Torvalds goto out; 6374bf269551SChuck Lever status = decode_open_confirm(xdr, res); 63751da177e4SLinus Torvalds out: 63761da177e4SLinus Torvalds return status; 63771da177e4SLinus Torvalds } 63781da177e4SLinus Torvalds 63791da177e4SLinus Torvalds /* 63801da177e4SLinus Torvalds * Decode OPEN response 63811da177e4SLinus Torvalds */ 6382bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6383bf269551SChuck Lever struct xdr_stream *xdr, 6384bf269551SChuck Lever struct nfs_openres *res) 63851da177e4SLinus Torvalds { 63861da177e4SLinus Torvalds struct compound_hdr hdr; 63871da177e4SLinus Torvalds int status; 63881da177e4SLinus Torvalds 6389bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63901da177e4SLinus Torvalds if (status) 63911da177e4SLinus Torvalds goto out; 6392bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63939b7b9fccSAndy Adamson if (status) 63949b7b9fccSAndy Adamson goto out; 6395bf269551SChuck Lever status = decode_putfh(xdr); 63961da177e4SLinus Torvalds if (status) 63971da177e4SLinus Torvalds goto out; 6398bf269551SChuck Lever status = decode_open(xdr, res); 6399864472e9STrond Myklebust if (status) 6400864472e9STrond Myklebust goto out; 6401ae2bb032SWeston Andros Adamson if (res->access_request) 64026168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 64036926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 64041da177e4SLinus Torvalds out: 64051da177e4SLinus Torvalds return status; 64061da177e4SLinus Torvalds } 64071da177e4SLinus Torvalds 64081da177e4SLinus Torvalds /* 64091da177e4SLinus Torvalds * Decode SETATTR response 64101da177e4SLinus Torvalds */ 6411bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6412bf269551SChuck Lever struct xdr_stream *xdr, 6413bf269551SChuck Lever struct nfs_setattrres *res) 64141da177e4SLinus Torvalds { 64151da177e4SLinus Torvalds struct compound_hdr hdr; 64161da177e4SLinus Torvalds int status; 64171da177e4SLinus Torvalds 6418bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64191da177e4SLinus Torvalds if (status) 64201da177e4SLinus Torvalds goto out; 6421bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64229b7b9fccSAndy Adamson if (status) 64239b7b9fccSAndy Adamson goto out; 6424bf269551SChuck Lever status = decode_putfh(xdr); 64251da177e4SLinus Torvalds if (status) 64261da177e4SLinus Torvalds goto out; 6427bf269551SChuck Lever status = decode_setattr(xdr); 64281da177e4SLinus Torvalds if (status) 64291da177e4SLinus Torvalds goto out; 6430aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 64311da177e4SLinus Torvalds out: 64321da177e4SLinus Torvalds return status; 64331da177e4SLinus Torvalds } 64341da177e4SLinus Torvalds 64351da177e4SLinus Torvalds /* 64361da177e4SLinus Torvalds * Decode LOCK response 64371da177e4SLinus Torvalds */ 6438bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6439bf269551SChuck Lever struct nfs_lock_res *res) 64401da177e4SLinus Torvalds { 64411da177e4SLinus Torvalds struct compound_hdr hdr; 64421da177e4SLinus Torvalds int status; 64431da177e4SLinus Torvalds 6444bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64451da177e4SLinus Torvalds if (status) 64461da177e4SLinus Torvalds goto out; 6447bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64489b7b9fccSAndy Adamson if (status) 64499b7b9fccSAndy Adamson goto out; 6450bf269551SChuck Lever status = decode_putfh(xdr); 64511da177e4SLinus Torvalds if (status) 64521da177e4SLinus Torvalds goto out; 6453bf269551SChuck Lever status = decode_lock(xdr, res); 64541da177e4SLinus Torvalds out: 64551da177e4SLinus Torvalds return status; 64561da177e4SLinus Torvalds } 64571da177e4SLinus Torvalds 64581da177e4SLinus Torvalds /* 64591da177e4SLinus Torvalds * Decode LOCKT response 64601da177e4SLinus Torvalds */ 6461bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6462bf269551SChuck Lever struct nfs_lockt_res *res) 64631da177e4SLinus Torvalds { 64641da177e4SLinus Torvalds struct compound_hdr hdr; 64651da177e4SLinus Torvalds int status; 64661da177e4SLinus Torvalds 6467bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64681da177e4SLinus Torvalds if (status) 64691da177e4SLinus Torvalds goto out; 6470bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64719b7b9fccSAndy Adamson if (status) 64729b7b9fccSAndy Adamson goto out; 6473bf269551SChuck Lever status = decode_putfh(xdr); 64741da177e4SLinus Torvalds if (status) 64751da177e4SLinus Torvalds goto out; 6476bf269551SChuck Lever status = decode_lockt(xdr, res); 64771da177e4SLinus Torvalds out: 64781da177e4SLinus Torvalds return status; 64791da177e4SLinus Torvalds } 64801da177e4SLinus Torvalds 64811da177e4SLinus Torvalds /* 64821da177e4SLinus Torvalds * Decode LOCKU response 64831da177e4SLinus Torvalds */ 6484bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6485bf269551SChuck Lever struct nfs_locku_res *res) 64861da177e4SLinus Torvalds { 64871da177e4SLinus Torvalds struct compound_hdr hdr; 64881da177e4SLinus Torvalds int status; 64891da177e4SLinus Torvalds 6490bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64911da177e4SLinus Torvalds if (status) 64921da177e4SLinus Torvalds goto out; 6493bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64949b7b9fccSAndy Adamson if (status) 64959b7b9fccSAndy Adamson goto out; 6496bf269551SChuck Lever status = decode_putfh(xdr); 64971da177e4SLinus Torvalds if (status) 64981da177e4SLinus Torvalds goto out; 6499bf269551SChuck Lever status = decode_locku(xdr, res); 65001da177e4SLinus Torvalds out: 65011da177e4SLinus Torvalds return status; 65021da177e4SLinus Torvalds } 65031da177e4SLinus Torvalds 6504bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6505bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6506d3c7b7ccSTrond Myklebust { 6507d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6508d3c7b7ccSTrond Myklebust int status; 6509d3c7b7ccSTrond Myklebust 6510bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6511d3c7b7ccSTrond Myklebust if (!status) 6512bf269551SChuck Lever status = decode_release_lockowner(xdr); 6513d3c7b7ccSTrond Myklebust return status; 6514d3c7b7ccSTrond Myklebust } 6515d3c7b7ccSTrond Myklebust 65161da177e4SLinus Torvalds /* 65171da177e4SLinus Torvalds * Decode READLINK response 65181da177e4SLinus Torvalds */ 6519bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6520bf269551SChuck Lever struct xdr_stream *xdr, 6521f50c7000SBenny Halevy struct nfs4_readlink_res *res) 65221da177e4SLinus Torvalds { 65231da177e4SLinus Torvalds struct compound_hdr hdr; 65241da177e4SLinus Torvalds int status; 65251da177e4SLinus Torvalds 6526bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65271da177e4SLinus Torvalds if (status) 65281da177e4SLinus Torvalds goto out; 6529bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65309b7b9fccSAndy Adamson if (status) 65319b7b9fccSAndy Adamson goto out; 6532bf269551SChuck Lever status = decode_putfh(xdr); 65331da177e4SLinus Torvalds if (status) 65341da177e4SLinus Torvalds goto out; 6535bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 65361da177e4SLinus Torvalds out: 65371da177e4SLinus Torvalds return status; 65381da177e4SLinus Torvalds } 65391da177e4SLinus Torvalds 65401da177e4SLinus Torvalds /* 65411da177e4SLinus Torvalds * Decode READDIR response 65421da177e4SLinus Torvalds */ 6543bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6544bf269551SChuck Lever struct nfs4_readdir_res *res) 65451da177e4SLinus Torvalds { 65461da177e4SLinus Torvalds struct compound_hdr hdr; 65471da177e4SLinus Torvalds int status; 65481da177e4SLinus Torvalds 6549bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65501da177e4SLinus Torvalds if (status) 65511da177e4SLinus Torvalds goto out; 6552bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65539b7b9fccSAndy Adamson if (status) 65549b7b9fccSAndy Adamson goto out; 6555bf269551SChuck Lever status = decode_putfh(xdr); 65561da177e4SLinus Torvalds if (status) 65571da177e4SLinus Torvalds goto out; 6558bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 65591da177e4SLinus Torvalds out: 65601da177e4SLinus Torvalds return status; 65611da177e4SLinus Torvalds } 65621da177e4SLinus Torvalds 65631da177e4SLinus Torvalds /* 65641da177e4SLinus Torvalds * Decode Read response 65651da177e4SLinus Torvalds */ 6566bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 65679137bdf3SAnna Schumaker struct nfs_pgio_res *res) 65681da177e4SLinus Torvalds { 65691da177e4SLinus Torvalds struct compound_hdr hdr; 65701da177e4SLinus Torvalds int status; 65711da177e4SLinus Torvalds 6572bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65731da177e4SLinus Torvalds if (status) 65741da177e4SLinus Torvalds goto out; 6575bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65769b7b9fccSAndy Adamson if (status) 65779b7b9fccSAndy Adamson goto out; 6578bf269551SChuck Lever status = decode_putfh(xdr); 65791da177e4SLinus Torvalds if (status) 65801da177e4SLinus Torvalds goto out; 6581bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 65821da177e4SLinus Torvalds if (!status) 65831da177e4SLinus Torvalds status = res->count; 65841da177e4SLinus Torvalds out: 65851da177e4SLinus Torvalds return status; 65861da177e4SLinus Torvalds } 65871da177e4SLinus Torvalds 65881da177e4SLinus Torvalds /* 65891da177e4SLinus Torvalds * Decode WRITE response 65901da177e4SLinus Torvalds */ 6591bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 65929137bdf3SAnna Schumaker struct nfs_pgio_res *res) 65931da177e4SLinus Torvalds { 65941da177e4SLinus Torvalds struct compound_hdr hdr; 65951da177e4SLinus Torvalds int status; 65961da177e4SLinus Torvalds 6597bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65981da177e4SLinus Torvalds if (status) 65991da177e4SLinus Torvalds goto out; 6600bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66019b7b9fccSAndy Adamson if (status) 66029b7b9fccSAndy Adamson goto out; 6603bf269551SChuck Lever status = decode_putfh(xdr); 66041da177e4SLinus Torvalds if (status) 66051da177e4SLinus Torvalds goto out; 6606bf269551SChuck Lever status = decode_write(xdr, res); 66074f9838c7STrond Myklebust if (status) 66084f9838c7STrond Myklebust goto out; 66097ffd1064SFred Isaman if (res->fattr) 66106926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 66111da177e4SLinus Torvalds if (!status) 66121da177e4SLinus Torvalds status = res->count; 66131da177e4SLinus Torvalds out: 66141da177e4SLinus Torvalds return status; 66151da177e4SLinus Torvalds } 66161da177e4SLinus Torvalds 66171da177e4SLinus Torvalds /* 66181da177e4SLinus Torvalds * Decode COMMIT response 66191da177e4SLinus Torvalds */ 6620bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 66210b7c0153SFred Isaman struct nfs_commitres *res) 66221da177e4SLinus Torvalds { 66231da177e4SLinus Torvalds struct compound_hdr hdr; 66241da177e4SLinus Torvalds int status; 66251da177e4SLinus Torvalds 6626bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66271da177e4SLinus Torvalds if (status) 66281da177e4SLinus Torvalds goto out; 6629bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66309b7b9fccSAndy Adamson if (status) 66319b7b9fccSAndy Adamson goto out; 6632bf269551SChuck Lever status = decode_putfh(xdr); 66331da177e4SLinus Torvalds if (status) 66341da177e4SLinus Torvalds goto out; 6635bf269551SChuck Lever status = decode_commit(xdr, res); 66361da177e4SLinus Torvalds out: 66371da177e4SLinus Torvalds return status; 66381da177e4SLinus Torvalds } 66391da177e4SLinus Torvalds 66401da177e4SLinus Torvalds /* 66418b173218SRicardo Labiaga * Decode FSINFO response 66421da177e4SLinus Torvalds */ 6643bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 66443dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 66451da177e4SLinus Torvalds { 66461da177e4SLinus Torvalds struct compound_hdr hdr; 66471da177e4SLinus Torvalds int status; 66481da177e4SLinus Torvalds 6649bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66501da177e4SLinus Torvalds if (!status) 6651bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 66529b7b9fccSAndy Adamson if (!status) 6653bf269551SChuck Lever status = decode_putfh(xdr); 66541da177e4SLinus Torvalds if (!status) 6655bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 66561da177e4SLinus Torvalds return status; 66571da177e4SLinus Torvalds } 66581da177e4SLinus Torvalds 66591da177e4SLinus Torvalds /* 66608b173218SRicardo Labiaga * Decode PATHCONF response 66611da177e4SLinus Torvalds */ 6662bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6663d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 66641da177e4SLinus Torvalds { 66651da177e4SLinus Torvalds struct compound_hdr hdr; 66661da177e4SLinus Torvalds int status; 66671da177e4SLinus Torvalds 6668bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66691da177e4SLinus Torvalds if (!status) 6670bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 66719b7b9fccSAndy Adamson if (!status) 6672bf269551SChuck Lever status = decode_putfh(xdr); 66731da177e4SLinus Torvalds if (!status) 6674bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 66751da177e4SLinus Torvalds return status; 66761da177e4SLinus Torvalds } 66771da177e4SLinus Torvalds 66781da177e4SLinus Torvalds /* 66798b173218SRicardo Labiaga * Decode STATFS response 66801da177e4SLinus Torvalds */ 6681bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 668224ad148aSBenny Halevy struct nfs4_statfs_res *res) 66831da177e4SLinus Torvalds { 66841da177e4SLinus Torvalds struct compound_hdr hdr; 66851da177e4SLinus Torvalds int status; 66861da177e4SLinus Torvalds 6687bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66881da177e4SLinus Torvalds if (!status) 6689bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 66909b7b9fccSAndy Adamson if (!status) 6691bf269551SChuck Lever status = decode_putfh(xdr); 66921da177e4SLinus Torvalds if (!status) 6693bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 66941da177e4SLinus Torvalds return status; 66951da177e4SLinus Torvalds } 66961da177e4SLinus Torvalds 66971da177e4SLinus Torvalds /* 66988b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 66991da177e4SLinus Torvalds */ 6700bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6701bf269551SChuck Lever struct xdr_stream *xdr, 6702bf269551SChuck Lever struct nfs4_server_caps_res *res) 67031da177e4SLinus Torvalds { 67041da177e4SLinus Torvalds struct compound_hdr hdr; 67051da177e4SLinus Torvalds int status; 67061da177e4SLinus Torvalds 6707bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67089b7b9fccSAndy Adamson if (status) 67099b7b9fccSAndy Adamson goto out; 6710bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 67119b7b9fccSAndy Adamson if (status) 67121da177e4SLinus Torvalds goto out; 6713bf269551SChuck Lever status = decode_putfh(xdr); 6714bf269551SChuck Lever if (status) 67151da177e4SLinus Torvalds goto out; 6716bf269551SChuck Lever status = decode_server_caps(xdr, res); 67171da177e4SLinus Torvalds out: 67181da177e4SLinus Torvalds return status; 67191da177e4SLinus Torvalds } 67201da177e4SLinus Torvalds 67211da177e4SLinus Torvalds /* 67221da177e4SLinus Torvalds * Decode RENEW response 67231da177e4SLinus Torvalds */ 6724bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6725bf269551SChuck Lever void *__unused) 67261da177e4SLinus Torvalds { 67271da177e4SLinus Torvalds struct compound_hdr hdr; 67281da177e4SLinus Torvalds int status; 67291da177e4SLinus Torvalds 6730bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67311da177e4SLinus Torvalds if (!status) 6732bf269551SChuck Lever status = decode_renew(xdr); 67331da177e4SLinus Torvalds return status; 67341da177e4SLinus Torvalds } 67351da177e4SLinus Torvalds 67361da177e4SLinus Torvalds /* 67378b173218SRicardo Labiaga * Decode SETCLIENTID response 67381da177e4SLinus Torvalds */ 6739bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6740bf269551SChuck Lever struct xdr_stream *xdr, 6741bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 67421da177e4SLinus Torvalds { 67431da177e4SLinus Torvalds struct compound_hdr hdr; 67441da177e4SLinus Torvalds int status; 67451da177e4SLinus Torvalds 6746bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67471da177e4SLinus Torvalds if (!status) 6748bf269551SChuck Lever status = decode_setclientid(xdr, res); 67491da177e4SLinus Torvalds return status; 67501da177e4SLinus Torvalds } 67511da177e4SLinus Torvalds 67521da177e4SLinus Torvalds /* 67538b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 67541da177e4SLinus Torvalds */ 6755bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 675683ca7f5aSChuck Lever struct xdr_stream *xdr) 67571da177e4SLinus Torvalds { 67581da177e4SLinus Torvalds struct compound_hdr hdr; 67591da177e4SLinus Torvalds int status; 67601da177e4SLinus Torvalds 6761bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67621da177e4SLinus Torvalds if (!status) 6763bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 67641da177e4SLinus Torvalds return status; 67651da177e4SLinus Torvalds } 67661da177e4SLinus Torvalds 67671da177e4SLinus Torvalds /* 67688b173218SRicardo Labiaga * Decode DELEGRETURN response 67691da177e4SLinus Torvalds */ 6770bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6771bf269551SChuck Lever struct xdr_stream *xdr, 6772bf269551SChuck Lever struct nfs4_delegreturnres *res) 67731da177e4SLinus Torvalds { 67741da177e4SLinus Torvalds struct compound_hdr hdr; 67751da177e4SLinus Torvalds int status; 67761da177e4SLinus Torvalds 6777bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67789b7b9fccSAndy Adamson if (status) 67799b7b9fccSAndy Adamson goto out; 6780bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67819b7b9fccSAndy Adamson if (status) 6782fa178f29STrond Myklebust goto out; 6783bf269551SChuck Lever status = decode_putfh(xdr); 6784fa178f29STrond Myklebust if (status != 0) 6785fa178f29STrond Myklebust goto out; 6786e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6787556ae3bbSJeff Layton if (status != 0) 6788556ae3bbSJeff Layton goto out; 6789e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6790fa178f29STrond Myklebust out: 67911da177e4SLinus Torvalds return status; 67921da177e4SLinus Torvalds } 67931da177e4SLinus Torvalds 6794683b57b4STrond Myklebust /* 67958b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6796683b57b4STrond Myklebust */ 6797bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6798bf269551SChuck Lever struct xdr_stream *xdr, 679922958463SBenny Halevy struct nfs4_fs_locations_res *res) 6800683b57b4STrond Myklebust { 6801683b57b4STrond Myklebust struct compound_hdr hdr; 6802683b57b4STrond Myklebust int status; 6803683b57b4STrond Myklebust 6804bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68059b7b9fccSAndy Adamson if (status) 68069b7b9fccSAndy Adamson goto out; 6807bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68089b7b9fccSAndy Adamson if (status) 6809683b57b4STrond Myklebust goto out; 6810bf269551SChuck Lever status = decode_putfh(xdr); 6811bf269551SChuck Lever if (status) 6812683b57b4STrond Myklebust goto out; 6813b03d735bSChuck Lever if (res->migration) { 6814b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6815b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6816b03d735bSChuck Lever &res->fs_locations->fattr, 6817b03d735bSChuck Lever NULL, res->fs_locations, 6818b03d735bSChuck Lever NULL, res->fs_locations->server); 6819b03d735bSChuck Lever if (status) 6820b03d735bSChuck Lever goto out; 6821b03d735bSChuck Lever if (res->renew) 6822b03d735bSChuck Lever status = decode_renew(xdr); 6823b03d735bSChuck Lever } else { 6824bf269551SChuck Lever status = decode_lookup(xdr); 6825bf269551SChuck Lever if (status) 6826683b57b4STrond Myklebust goto out; 6827bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6828b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6829b03d735bSChuck Lever &res->fs_locations->fattr, 68308b7e3f49STrond Myklebust NULL, res->fs_locations, 6831aa9c2669SDavid Quigley NULL, res->fs_locations->server); 6832b03d735bSChuck Lever } 6833683b57b4STrond Myklebust out: 6834683b57b4STrond Myklebust return status; 6835683b57b4STrond Myklebust } 6836683b57b4STrond Myklebust 68375a5ea0d4SBryan Schumaker /* 68385a5ea0d4SBryan Schumaker * Decode SECINFO response 68395a5ea0d4SBryan Schumaker */ 68405a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 68415a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 68425a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 68435a5ea0d4SBryan Schumaker { 68445a5ea0d4SBryan Schumaker struct compound_hdr hdr; 68455a5ea0d4SBryan Schumaker int status; 68465a5ea0d4SBryan Schumaker 68475a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 68485a5ea0d4SBryan Schumaker if (status) 68495a5ea0d4SBryan Schumaker goto out; 68505a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 68515a5ea0d4SBryan Schumaker if (status) 68525a5ea0d4SBryan Schumaker goto out; 68535a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 68545a5ea0d4SBryan Schumaker if (status) 68555a5ea0d4SBryan Schumaker goto out; 68565a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 68575a5ea0d4SBryan Schumaker out: 68585a5ea0d4SBryan Schumaker return status; 68595a5ea0d4SBryan Schumaker } 68605a5ea0d4SBryan Schumaker 686144c99933SChuck Lever /* 686244c99933SChuck Lever * Decode FSID_PRESENT response 686344c99933SChuck Lever */ 686444c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 686544c99933SChuck Lever struct xdr_stream *xdr, 686644c99933SChuck Lever struct nfs4_fsid_present_res *res) 686744c99933SChuck Lever { 686844c99933SChuck Lever struct compound_hdr hdr; 686944c99933SChuck Lever int status; 687044c99933SChuck Lever 687144c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 687244c99933SChuck Lever if (status) 687344c99933SChuck Lever goto out; 687444c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 687544c99933SChuck Lever if (status) 687644c99933SChuck Lever goto out; 687744c99933SChuck Lever status = decode_putfh(xdr); 687844c99933SChuck Lever if (status) 687944c99933SChuck Lever goto out; 688044c99933SChuck Lever status = decode_getfh(xdr, res->fh); 688144c99933SChuck Lever if (status) 688244c99933SChuck Lever goto out; 688344c99933SChuck Lever if (res->renew) 688444c99933SChuck Lever status = decode_renew(xdr); 688544c99933SChuck Lever out: 688644c99933SChuck Lever return status; 688744c99933SChuck Lever } 688844c99933SChuck Lever 688999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 689099fe60d0SBenny Halevy /* 68917c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 68927c44f1aeSWeston Andros Adamson */ 68937c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 68947c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 68957c44f1aeSWeston Andros Adamson void *res) 68967c44f1aeSWeston Andros Adamson { 68977c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 68987c44f1aeSWeston Andros Adamson int status; 68997c44f1aeSWeston Andros Adamson 69007c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 69017c44f1aeSWeston Andros Adamson if (!status) 69027c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 69037c44f1aeSWeston Andros Adamson return status; 69047c44f1aeSWeston Andros Adamson } 69057c44f1aeSWeston Andros Adamson 69067c44f1aeSWeston Andros Adamson /* 69078b173218SRicardo Labiaga * Decode EXCHANGE_ID response 690899fe60d0SBenny Halevy */ 6909bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 6910bf269551SChuck Lever struct xdr_stream *xdr, 691199fe60d0SBenny Halevy void *res) 691299fe60d0SBenny Halevy { 691399fe60d0SBenny Halevy struct compound_hdr hdr; 691499fe60d0SBenny Halevy int status; 691599fe60d0SBenny Halevy 6916bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 691799fe60d0SBenny Halevy if (!status) 6918bf269551SChuck Lever status = decode_exchange_id(xdr, res); 691999fe60d0SBenny Halevy return status; 692099fe60d0SBenny Halevy } 69212050f0ccSAndy Adamson 69222050f0ccSAndy Adamson /* 69238b173218SRicardo Labiaga * Decode CREATE_SESSION response 6924fc931582SAndy Adamson */ 6925bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 6926bf269551SChuck Lever struct xdr_stream *xdr, 6927fc931582SAndy Adamson struct nfs41_create_session_res *res) 6928fc931582SAndy Adamson { 6929fc931582SAndy Adamson struct compound_hdr hdr; 6930fc931582SAndy Adamson int status; 6931fc931582SAndy Adamson 6932bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6933fc931582SAndy Adamson if (!status) 6934bf269551SChuck Lever status = decode_create_session(xdr, res); 6935fc931582SAndy Adamson return status; 6936fc931582SAndy Adamson } 6937fc931582SAndy Adamson 6938fc931582SAndy Adamson /* 69398b173218SRicardo Labiaga * Decode DESTROY_SESSION response 69400f3e66c6SAndy Adamson */ 6941bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 6942bf269551SChuck Lever struct xdr_stream *xdr, 6943bf269551SChuck Lever void *res) 69440f3e66c6SAndy Adamson { 69450f3e66c6SAndy Adamson struct compound_hdr hdr; 69460f3e66c6SAndy Adamson int status; 69470f3e66c6SAndy Adamson 6948bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69490f3e66c6SAndy Adamson if (!status) 6950bf269551SChuck Lever status = decode_destroy_session(xdr, res); 69510f3e66c6SAndy Adamson return status; 69520f3e66c6SAndy Adamson } 69530f3e66c6SAndy Adamson 69540f3e66c6SAndy Adamson /* 695566245539STrond Myklebust * Decode DESTROY_CLIENTID response 695666245539STrond Myklebust */ 695766245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 695866245539STrond Myklebust struct xdr_stream *xdr, 695966245539STrond Myklebust void *res) 696066245539STrond Myklebust { 696166245539STrond Myklebust struct compound_hdr hdr; 696266245539STrond Myklebust int status; 696366245539STrond Myklebust 696466245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 696566245539STrond Myklebust if (!status) 696666245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 696766245539STrond Myklebust return status; 696866245539STrond Myklebust } 696966245539STrond Myklebust 697066245539STrond Myklebust /* 69718b173218SRicardo Labiaga * Decode SEQUENCE response 6972fc01cea9SAndy Adamson */ 6973bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 6974bf269551SChuck Lever struct xdr_stream *xdr, 6975fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 6976fc01cea9SAndy Adamson { 6977fc01cea9SAndy Adamson struct compound_hdr hdr; 6978fc01cea9SAndy Adamson int status; 6979fc01cea9SAndy Adamson 6980bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6981fc01cea9SAndy Adamson if (!status) 6982bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 6983fc01cea9SAndy Adamson return status; 6984fc01cea9SAndy Adamson } 6985fc01cea9SAndy Adamson 6986fc01cea9SAndy Adamson /* 69878b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 69882050f0ccSAndy Adamson */ 6989bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 6990bf269551SChuck Lever struct xdr_stream *xdr, 69912050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 69922050f0ccSAndy Adamson { 69932050f0ccSAndy Adamson struct compound_hdr hdr; 69942050f0ccSAndy Adamson int status; 69952050f0ccSAndy Adamson 6996bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69972050f0ccSAndy Adamson if (!status) 6998bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 69992050f0ccSAndy Adamson if (!status) 7000bf269551SChuck Lever status = decode_putrootfh(xdr); 70012050f0ccSAndy Adamson if (!status) 7002bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 70032050f0ccSAndy Adamson return status; 70042050f0ccSAndy Adamson } 700518019753SRicardo Labiaga 700618019753SRicardo Labiaga /* 700718019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 700818019753SRicardo Labiaga */ 7009bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7010bf269551SChuck Lever struct xdr_stream *xdr, 701118019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 701218019753SRicardo Labiaga { 701318019753SRicardo Labiaga struct compound_hdr hdr; 701418019753SRicardo Labiaga int status; 701518019753SRicardo Labiaga 7016bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 701718019753SRicardo Labiaga if (!status) 7018bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 701918019753SRicardo Labiaga if (!status) 70208ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 702118019753SRicardo Labiaga return status; 702218019753SRicardo Labiaga } 7023b1f69b75SAndy Adamson 7024b1f69b75SAndy Adamson /* 7025b1f69b75SAndy Adamson * Decode GETDEVINFO response 7026b1f69b75SAndy Adamson */ 7027bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7028bf269551SChuck Lever struct xdr_stream *xdr, 7029b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 7030b1f69b75SAndy Adamson { 7031b1f69b75SAndy Adamson struct compound_hdr hdr; 7032b1f69b75SAndy Adamson int status; 7033b1f69b75SAndy Adamson 7034bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7035b1f69b75SAndy Adamson if (status != 0) 7036b1f69b75SAndy Adamson goto out; 7037bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7038b1f69b75SAndy Adamson if (status != 0) 7039b1f69b75SAndy Adamson goto out; 7040bf269551SChuck Lever status = decode_getdeviceinfo(xdr, res->pdev); 7041b1f69b75SAndy Adamson out: 7042b1f69b75SAndy Adamson return status; 7043b1f69b75SAndy Adamson } 7044b1f69b75SAndy Adamson 7045b1f69b75SAndy Adamson /* 7046b1f69b75SAndy Adamson * Decode LAYOUTGET response 7047b1f69b75SAndy Adamson */ 7048bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7049bf269551SChuck Lever struct xdr_stream *xdr, 7050b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 7051b1f69b75SAndy Adamson { 7052b1f69b75SAndy Adamson struct compound_hdr hdr; 7053b1f69b75SAndy Adamson int status; 7054b1f69b75SAndy Adamson 7055bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7056b1f69b75SAndy Adamson if (status) 7057b1f69b75SAndy Adamson goto out; 7058bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7059b1f69b75SAndy Adamson if (status) 7060b1f69b75SAndy Adamson goto out; 7061bf269551SChuck Lever status = decode_putfh(xdr); 7062b1f69b75SAndy Adamson if (status) 7063b1f69b75SAndy Adamson goto out; 7064bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7065b1f69b75SAndy Adamson out: 7066b1f69b75SAndy Adamson return status; 7067b1f69b75SAndy Adamson } 7068863a3c6cSAndy Adamson 7069863a3c6cSAndy Adamson /* 7070cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7071cbe82603SBenny Halevy */ 7072cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7073cbe82603SBenny Halevy struct xdr_stream *xdr, 7074cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 7075cbe82603SBenny Halevy { 7076cbe82603SBenny Halevy struct compound_hdr hdr; 7077cbe82603SBenny Halevy int status; 7078cbe82603SBenny Halevy 7079cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7080cbe82603SBenny Halevy if (status) 7081cbe82603SBenny Halevy goto out; 7082cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7083cbe82603SBenny Halevy if (status) 7084cbe82603SBenny Halevy goto out; 7085cbe82603SBenny Halevy status = decode_putfh(xdr); 7086cbe82603SBenny Halevy if (status) 7087cbe82603SBenny Halevy goto out; 7088cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7089cbe82603SBenny Halevy out: 7090cbe82603SBenny Halevy return status; 7091cbe82603SBenny Halevy } 7092cbe82603SBenny Halevy 7093cbe82603SBenny Halevy /* 7094863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7095863a3c6cSAndy Adamson */ 7096863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7097863a3c6cSAndy Adamson struct xdr_stream *xdr, 7098863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 7099863a3c6cSAndy Adamson { 7100863a3c6cSAndy Adamson struct compound_hdr hdr; 7101863a3c6cSAndy Adamson int status; 7102863a3c6cSAndy Adamson 7103863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7104863a3c6cSAndy Adamson if (status) 7105863a3c6cSAndy Adamson goto out; 7106863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7107863a3c6cSAndy Adamson if (status) 7108863a3c6cSAndy Adamson goto out; 7109863a3c6cSAndy Adamson status = decode_putfh(xdr); 7110863a3c6cSAndy Adamson if (status) 7111863a3c6cSAndy Adamson goto out; 7112863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7113863a3c6cSAndy Adamson if (status) 7114863a3c6cSAndy Adamson goto out; 71156926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7116863a3c6cSAndy Adamson out: 7117863a3c6cSAndy Adamson return status; 7118863a3c6cSAndy Adamson } 7119fca78d6dSBryan Schumaker 7120fca78d6dSBryan Schumaker /* 7121fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7122fca78d6dSBryan Schumaker */ 7123fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7124fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7125fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 7126fca78d6dSBryan Schumaker { 7127fca78d6dSBryan Schumaker struct compound_hdr hdr; 7128fca78d6dSBryan Schumaker int status; 7129fca78d6dSBryan Schumaker 7130fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7131fca78d6dSBryan Schumaker if (status) 7132fca78d6dSBryan Schumaker goto out; 7133fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7134fca78d6dSBryan Schumaker if (status) 7135fca78d6dSBryan Schumaker goto out; 7136fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7137fca78d6dSBryan Schumaker if (status) 7138fca78d6dSBryan Schumaker goto out; 713931e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7140fca78d6dSBryan Schumaker out: 7141fca78d6dSBryan Schumaker return status; 7142fca78d6dSBryan Schumaker } 71437d974794SBryan Schumaker 71447d974794SBryan Schumaker /* 71457d974794SBryan Schumaker * Decode TEST_STATEID response 71467d974794SBryan Schumaker */ 71477d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 71487d974794SBryan Schumaker struct xdr_stream *xdr, 71497d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 71507d974794SBryan Schumaker { 71517d974794SBryan Schumaker struct compound_hdr hdr; 71527d974794SBryan Schumaker int status; 71537d974794SBryan Schumaker 71547d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 71557d974794SBryan Schumaker if (status) 71567d974794SBryan Schumaker goto out; 71577d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 71587d974794SBryan Schumaker if (status) 71597d974794SBryan Schumaker goto out; 71607d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 71617d974794SBryan Schumaker out: 71627d974794SBryan Schumaker return status; 71637d974794SBryan Schumaker } 71649aeda35fSBryan Schumaker 71659aeda35fSBryan Schumaker /* 71669aeda35fSBryan Schumaker * Decode FREE_STATEID response 71679aeda35fSBryan Schumaker */ 71689aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 71699aeda35fSBryan Schumaker struct xdr_stream *xdr, 71709aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 71719aeda35fSBryan Schumaker { 71729aeda35fSBryan Schumaker struct compound_hdr hdr; 71739aeda35fSBryan Schumaker int status; 71749aeda35fSBryan Schumaker 71759aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 71769aeda35fSBryan Schumaker if (status) 71779aeda35fSBryan Schumaker goto out; 71789aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 71799aeda35fSBryan Schumaker if (status) 71809aeda35fSBryan Schumaker goto out; 71819aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 71829aeda35fSBryan Schumaker out: 71839aeda35fSBryan Schumaker return status; 71849aeda35fSBryan Schumaker } 718599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 718699fe60d0SBenny Halevy 7187573c4e1eSChuck Lever /** 7188573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7189573c4e1eSChuck Lever * the local page cache. 7190573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7191573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7192573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7193573c4e1eSChuck Lever * 7194573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7195573c4e1eSChuck Lever * returned. 7196573c4e1eSChuck Lever * 7197573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7198573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7199573c4e1eSChuck Lever * on a directory already in our cache. 7200573c4e1eSChuck Lever */ 7201573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7202573c4e1eSChuck Lever int plus) 72031da177e4SLinus Torvalds { 7204256e48bbSTrond Myklebust unsigned int savep; 7205dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 72061da177e4SLinus Torvalds uint32_t len; 7207babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7208babddc72SBryan Schumaker if (unlikely(!p)) 7209babddc72SBryan Schumaker goto out_overflow; 7210c08e76d0SChuck Lever if (*p == xdr_zero) { 7211babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7212babddc72SBryan Schumaker if (unlikely(!p)) 7213babddc72SBryan Schumaker goto out_overflow; 7214c08e76d0SChuck Lever if (*p == xdr_zero) 7215573c4e1eSChuck Lever return -EAGAIN; 72161da177e4SLinus Torvalds entry->eof = 1; 7217573c4e1eSChuck Lever return -EBADCOOKIE; 72181da177e4SLinus Torvalds } 72191da177e4SLinus Torvalds 7220babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7221babddc72SBryan Schumaker if (unlikely(!p)) 7222babddc72SBryan Schumaker goto out_overflow; 72231da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 72241da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7225c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7226babddc72SBryan Schumaker 72279af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7228babddc72SBryan Schumaker if (unlikely(!p)) 7229babddc72SBryan Schumaker goto out_overflow; 72301da177e4SLinus Torvalds entry->name = (const char *) p; 72311da177e4SLinus Torvalds 72321da177e4SLinus Torvalds /* 72331da177e4SLinus Torvalds * In case the server doesn't return an inode number, 72341da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 72351da177e4SLinus Torvalds * since glibc seems to choke on it...) 72361da177e4SLinus Torvalds */ 72371da177e4SLinus Torvalds entry->ino = 1; 72384f082222STrond Myklebust entry->fattr->valid = 0; 72391da177e4SLinus Torvalds 72409af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7241babddc72SBryan Schumaker goto out_overflow; 72429af8c222STrond Myklebust 7243256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7244babddc72SBryan Schumaker goto out_overflow; 72459af8c222STrond Myklebust 7246573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7247aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7248babddc72SBryan Schumaker goto out_overflow; 724928331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 725028331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 725128331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 725282f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 72539af8c222STrond Myklebust 72540b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 72550b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 72560b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 72570b26a0bfSTrond Myklebust 7258573c4e1eSChuck Lever return 0; 7259babddc72SBryan Schumaker 7260babddc72SBryan Schumaker out_overflow: 7261babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7262573c4e1eSChuck Lever return -EAGAIN; 72631da177e4SLinus Torvalds } 72641da177e4SLinus Torvalds 72651da177e4SLinus Torvalds /* 72661da177e4SLinus Torvalds * We need to translate between nfs status return values and 72671da177e4SLinus Torvalds * the local errno values which may not be the same. 72681da177e4SLinus Torvalds */ 72691da177e4SLinus Torvalds static struct { 72701da177e4SLinus Torvalds int stat; 72711da177e4SLinus Torvalds int errno; 72721da177e4SLinus Torvalds } nfs_errtbl[] = { 72731da177e4SLinus Torvalds { NFS4_OK, 0 }, 7274856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7275856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7276856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7277856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7278856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7279856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7280856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7281856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7282856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7283856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7284856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7285856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7286856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7287856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7288856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7289856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7290856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7291856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7292856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7293856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7294856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7295856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7296fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7297856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7298856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7299856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7300856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7301856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7302856dff3dSBenny Halevy { -1, -EIO } 73031da177e4SLinus Torvalds }; 73041da177e4SLinus Torvalds 73051da177e4SLinus Torvalds /* 73061da177e4SLinus Torvalds * Convert an NFS error code to a local one. 73071da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 73081da177e4SLinus Torvalds */ 73091da177e4SLinus Torvalds static int 73100a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 73111da177e4SLinus Torvalds { 73121da177e4SLinus Torvalds int i; 73131da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 73141da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 73151da177e4SLinus Torvalds return nfs_errtbl[i].errno; 73161da177e4SLinus Torvalds } 73171da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 73181da177e4SLinus Torvalds /* The server is looney tunes. */ 7319fdcb4577STrond Myklebust return -EREMOTEIO; 73201da177e4SLinus Torvalds } 73211da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 73221da177e4SLinus Torvalds * handle it. 73231da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 73241da177e4SLinus Torvalds * not conflict with native Linux error codes. 73251da177e4SLinus Torvalds */ 7326856dff3dSBenny Halevy return -stat; 73271da177e4SLinus Torvalds } 73281da177e4SLinus Torvalds 73291c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 73301c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 73311c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 73321c6dcbe5SAnna Schumaker 73331da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 73341da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 73351da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 73369f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7337bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 73382bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 73392bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7340cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7341cc0175c1SChuck Lever .p_name = #proc, \ 73421da177e4SLinus Torvalds } 73431da177e4SLinus Torvalds 73441da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 73451da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 73461da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 73471da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 73481da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 73491da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 73501da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 73511da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 73521da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 73531da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 73541da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 73551da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 73561da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 73571da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 73581da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 73591da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 73601da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 73611da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 73621da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 73631da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 73641da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 73651da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 73661da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 73671da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 73681da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 73691da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 73701da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 73711da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 73721da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 73731da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 73741da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 73751da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7376029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 737723ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7378683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7379d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 73805a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 738144c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 738299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 738399fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7384fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 73850f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7386fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 73872050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 738818019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7389b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7390b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7391863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7392cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7393fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 73947d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 73959aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 7396ad24ecfbSTrond Myklebust PROC(BIND_CONN_TO_SESSION, 7397ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 739866245539STrond Myklebust PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 739999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 74001c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 74011c6dcbe5SAnna Schumaker PROC(SEEK, enc_seek, dec_seek), 7402f4ac1674SAnna Schumaker PROC(ALLOCATE, enc_allocate, dec_allocate), 7403624bd5b7SAnna Schumaker PROC(DEALLOCATE, enc_deallocate, dec_deallocate), 74041c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 74051da177e4SLinus Torvalds }; 74061da177e4SLinus Torvalds 7407a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 74081da177e4SLinus Torvalds .number = 4, 7409e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 74101da177e4SLinus Torvalds .procs = nfs4_procedures 74111da177e4SLinus Torvalds }; 74121da177e4SLinus Torvalds 74131da177e4SLinus Torvalds /* 74141da177e4SLinus Torvalds * Local variables: 74151da177e4SLinus Torvalds * c-basic-offset: 8 74161da177e4SLinus Torvalds * End: 74171da177e4SLinus Torvalds */ 7418