11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * fs/nfs/nfs4xdr.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Client-side XDR for NFSv4. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (c) 2002 The Regents of the University of Michigan. 71da177e4SLinus Torvalds * All rights reserved. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Kendrick Smith <kmsmith@umich.edu> 101da177e4SLinus Torvalds * Andy Adamson <andros@umich.edu> 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without 131da177e4SLinus Torvalds * modification, are permitted provided that the following conditions 141da177e4SLinus Torvalds * are met: 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright 171da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer. 181da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce the above copyright 191da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer in the 201da177e4SLinus Torvalds * documentation and/or other materials provided with the distribution. 211da177e4SLinus Torvalds * 3. Neither the name of the University nor the names of its 221da177e4SLinus Torvalds * contributors may be used to endorse or promote products derived 231da177e4SLinus Torvalds * from this software without specific prior written permission. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 261da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 271da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 281da177e4SLinus Torvalds * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291da177e4SLinus Torvalds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301da177e4SLinus Torvalds * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311da177e4SLinus Torvalds * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 321da177e4SLinus Torvalds * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 331da177e4SLinus Torvalds * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 341da177e4SLinus Torvalds * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 351da177e4SLinus Torvalds * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 361da177e4SLinus Torvalds */ 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #include <linux/param.h> 391da177e4SLinus Torvalds #include <linux/time.h> 401da177e4SLinus Torvalds #include <linux/mm.h> 411da177e4SLinus Torvalds #include <linux/errno.h> 421da177e4SLinus Torvalds #include <linux/string.h> 431da177e4SLinus Torvalds #include <linux/in.h> 441da177e4SLinus Torvalds #include <linux/pagemap.h> 451da177e4SLinus Torvalds #include <linux/proc_fs.h> 461da177e4SLinus Torvalds #include <linux/kdev_t.h> 47db8ac8baSWeston Andros Adamson #include <linux/module.h> 48db8ac8baSWeston Andros Adamson #include <linux/utsname.h> 491da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h> 502449ea2eSAlexandros Batsakis #include <linux/sunrpc/msg_prot.h> 515a5ea0d4SBryan Schumaker #include <linux/sunrpc/gss_api.h> 521da177e4SLinus Torvalds #include <linux/nfs.h> 531da177e4SLinus Torvalds #include <linux/nfs4.h> 541da177e4SLinus Torvalds #include <linux/nfs_fs.h> 55f092075dSChuck Lever 564ce79717STrond Myklebust #include "nfs4_fs.h" 574882ef72SAlexandros Batsakis #include "internal.h" 5840c64c26SAnna Schumaker #include "nfs4idmap.h" 5976e697baSTrond Myklebust #include "nfs4session.h" 60b1f69b75SAndy Adamson #include "pnfs.h" 61f092075dSChuck Lever #include "netns.h" 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */ 661da177e4SLinus Torvalds #define errno_NFSERR_IO EIO 671da177e4SLinus Torvalds 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) + \ 142b8fb2f59SJeff Layton /* client name */ \ 143b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 144cc38bac3SChuck Lever 1 /* sc_prog */ + \ 1456dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1466dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \ 147cc38bac3SChuck Lever 1) /* sc_cb_ident */ 1481da177e4SLinus Torvalds #define decode_setclientid_maxsz \ 1491da177e4SLinus Torvalds (op_decode_hdr_maxsz + \ 1506dd3436bSChuck Lever 2 /* clientid */ + \ 1516dd3436bSChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \ 1526dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \ 1536dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) 1541da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \ 1551da177e4SLinus Torvalds (op_encode_hdr_maxsz + \ 1561da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2)) 1571da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \ 1581da177e4SLinus Torvalds (op_decode_hdr_maxsz) 159e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 160e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz) 1612cebf828STrond Myklebust #define encode_share_access_maxsz \ 1622cebf828STrond Myklebust (2) 1634882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz) 1642cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz) 1652cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz) 1662cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \ 1672cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \ 1682cebf828STrond Myklebust open_owner_id_maxsz + \ 1692cebf828STrond Myklebust encode_opentype_maxsz + \ 1702cebf828STrond Myklebust encode_claim_null_maxsz) 1712cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz) 1729104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \ 1732cebf828STrond Myklebust decode_ace_maxsz) 1742cebf828STrond Myklebust #define decode_change_info_maxsz (5) 1752cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \ 1769104a55dSTrond Myklebust decode_stateid_maxsz + \ 1772cebf828STrond Myklebust decode_change_info_maxsz + 1 + \ 1782cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \ 1792cebf828STrond Myklebust decode_delegation_maxsz) 1809104a55dSTrond Myklebust #define encode_open_confirm_maxsz \ 1819104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1829104a55dSTrond Myklebust encode_stateid_maxsz + 1) 1839104a55dSTrond Myklebust #define decode_open_confirm_maxsz \ 1849104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1859104a55dSTrond Myklebust decode_stateid_maxsz) 1869104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \ 1879104a55dSTrond Myklebust (op_encode_hdr_maxsz + \ 1889104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \ 1899104a55dSTrond Myklebust encode_share_access_maxsz) 1909104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \ 1919104a55dSTrond Myklebust (op_decode_hdr_maxsz + \ 1929104a55dSTrond Myklebust decode_stateid_maxsz) 1939104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \ 1949104a55dSTrond Myklebust 1 + encode_stateid_maxsz) 1959104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \ 1969104a55dSTrond Myklebust decode_stateid_maxsz) 1979104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \ 1989104a55dSTrond Myklebust encode_stateid_maxsz + \ 1999104a55dSTrond Myklebust encode_attrs_maxsz) 2009104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \ 2019104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz) 2029104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \ 2039104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2049104a55dSTrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2) 2059104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \ 206aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \ 207aa9c2669SDavid Quigley nfs4_label_maxsz) 2089104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \ 209a7697f6fSChuck Lever decode_verifier_maxsz) 2109104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz) 2119104a55dSTrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1) 2129104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \ 2139104a55dSTrond Myklebust encode_stateid_maxsz + 4) 2149104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \ 2159104a55dSTrond Myklebust 2 + decode_verifier_maxsz) 2169104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3) 2179104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \ 2189104a55dSTrond Myklebust decode_verifier_maxsz) 2191da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \ 2201da177e4SLinus Torvalds nfs4_name_maxsz) 2216ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \ 2226ce18391SBenny Halevy decode_change_info_maxsz) 2231da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \ 2241da177e4SLinus Torvalds 2 * nfs4_name_maxsz) 2256ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \ 2266ce18391SBenny Halevy decode_change_info_maxsz + \ 2276ce18391SBenny Halevy decode_change_info_maxsz) 2281da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \ 2291da177e4SLinus Torvalds nfs4_name_maxsz) 2306ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz) 231daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7) 2329104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \ 2339104a55dSTrond Myklebust 7 + \ 234daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \ 235daccbdedSTrond Myklebust encode_lockowner_maxsz) 2369104a55dSTrond Myklebust #define decode_lock_denied_maxsz \ 2379104a55dSTrond Myklebust (8 + decode_lockowner_maxsz) 2389104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \ 2399104a55dSTrond Myklebust decode_lock_denied_maxsz) 240daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \ 241daccbdedSTrond Myklebust encode_lockowner_maxsz) 2429104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \ 2439104a55dSTrond Myklebust decode_lock_denied_maxsz) 2449104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \ 2459104a55dSTrond Myklebust encode_stateid_maxsz + \ 2469104a55dSTrond Myklebust 4) 2479104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \ 2489104a55dSTrond Myklebust decode_stateid_maxsz) 249d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \ 250d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \ 251d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 252d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \ 253d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz) 2549104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1) 2559104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2) 2561da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \ 2571da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \ 25894a6d753SChuck Lever 1 + \ 25996928206SJ. Bruce Fields nfs4_fattr_maxsz) 2601da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8) 2611da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \ 2629104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \ 2639104a55dSTrond Myklebust encode_attrs_maxsz) 2642cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \ 2652cebf828STrond Myklebust decode_change_info_maxsz + \ 2662cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz) 2679104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz) 2689104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz) 2691da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4) 2701da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz) 2719104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz) 2729104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \ 2739104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz + 1) 2749104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \ 2759104a55dSTrond Myklebust encode_stateid_maxsz + 3) 2769104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz) 277e6889620STrond Myklebust #define encode_fs_locations_maxsz \ 278e6889620STrond Myklebust (encode_getattr_maxsz) 279e6889620STrond Myklebust #define decode_fs_locations_maxsz \ 280e6889620STrond Myklebust (0) 2815a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 2821650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 2839b7b9fccSAndy Adamson 2849b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 285fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64) 286d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 287d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 288fc931582SAndy Adamson 28999fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 29099fe60d0SBenny Halevy encode_verifier_maxsz + \ 29199fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \ 292b8fb2f59SJeff Layton /* eia_clientowner */ \ 293b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 29499fe60d0SBenny Halevy 1 /* flags */ + \ 29599fe60d0SBenny Halevy 1 /* spa_how */ + \ 2962031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 2972031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 2982031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 299db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \ 300db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \ 301db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 302db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \ 303d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 304db8ac8baSWeston Andros Adamson 3 /* nii_date */) 30599fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 30699fe60d0SBenny Halevy 2 /* eir_clientid */ + \ 30799fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \ 30899fe60d0SBenny Halevy 1 /* eir_flags */ + \ 30999fe60d0SBenny Halevy 1 /* spr_how */ + \ 3102031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \ 3112031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 3122031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \ 31399fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \ 31499fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \ 31599fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 31699fe60d0SBenny Halevy /* eir_server_scope<> */ \ 31799fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 31899fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \ 3197d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \ 3207d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3217d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \ 3227d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 3237d2ed9acSWeston Andros Adamson 3 /* nii_date */) 324fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 325fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \ 326fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \ 327fc931582SAndy Adamson 1 /* ca_rdma_ird */) 328fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \ 329fc931582SAndy Adamson 2 /* csa_clientid */ + \ 330fc931582SAndy Adamson 1 /* csa_sequence */ + \ 331fc931582SAndy Adamson 1 /* csa_flags */ + \ 332fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 333fc931582SAndy Adamson encode_channel_attrs_maxsz + \ 334fc931582SAndy Adamson 1 /* csa_cb_program */ + \ 335fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \ 336fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \ 337fc931582SAndy Adamson 1 /* stamp */ + \ 338fc931582SAndy Adamson 1 /* machinename.len */ + \ 339fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \ 340fc931582SAndy Adamson 1 /* uid */ + \ 341fc931582SAndy Adamson 1 /* gid */ + \ 342fc931582SAndy Adamson 1 /* gids.len (0) */) 343fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \ 344fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 345fc931582SAndy Adamson 1 /* csr_sequence */ + \ 346fc931582SAndy Adamson 1 /* csr_flags */ + \ 347fc931582SAndy Adamson decode_channel_attrs_maxsz + \ 348fc931582SAndy Adamson decode_channel_attrs_maxsz) 3497c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \ 3507c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \ 3517c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3527c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \ 3537c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */) 3547c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \ 3557c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \ 3567c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \ 3577c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \ 3587c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */) 3590f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) 3600f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz) 36166245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2) 36266245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz) 363fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \ 364fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4) 365fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \ 366fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) 36718019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) 36818019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) 36984c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \ 37084c9dee3SChristoph Hellwig XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 37184c9dee3SChristoph Hellwig 1 /* layout type */ + \ 37284c9dee3SChristoph Hellwig 1 /* maxcount */ + \ 37384c9dee3SChristoph Hellwig 1 /* bitmap size */ + \ 37484c9dee3SChristoph Hellwig 1 /* notification bitmap length */ + \ 37584c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 376b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \ 377b1f69b75SAndy Adamson 1 /* layout type */ + \ 378b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \ 379b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \ 380b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \ 38184c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */) 382b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \ 383b1f69b75SAndy Adamson encode_stateid_maxsz) 384b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \ 385b1f69b75SAndy Adamson decode_stateid_maxsz + \ 386b1f69b75SAndy Adamson XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE)) 387863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \ 388863a3c6cSAndy Adamson 2 /* offset */ + \ 389863a3c6cSAndy Adamson 2 /* length */ + \ 390863a3c6cSAndy Adamson 1 /* reclaim */ + \ 391863a3c6cSAndy Adamson encode_stateid_maxsz + \ 392863a3c6cSAndy Adamson 1 /* new offset (true) */ + \ 393863a3c6cSAndy Adamson 2 /* last byte written */ + \ 394863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \ 395863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \ 3965f919c9fSChristoph Hellwig 1 /* layoutupdate4 opaqueue len */) 3975f919c9fSChristoph Hellwig /* the actual content of layoutupdate4 should 3985f919c9fSChristoph Hellwig be allocated by drivers and spliced in 3995f919c9fSChristoph Hellwig using xdr_write_pages */ 400863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3) 401cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \ 402cbe82603SBenny Halevy encode_stateid_maxsz + \ 4036669cb8bSTrond Myklebust 1 + \ 4046669cb8bSTrond Myklebust XDR_QUADLEN(NFS4_OPAQUE_LIMIT)) 405cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \ 406cbe82603SBenny Halevy 1 + decode_stateid_maxsz) 407fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1) 408fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz 4097d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \ 4107d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4117d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1) 4129aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 4139aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE)) 4149f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 4159b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */ 4169b7b9fccSAndy Adamson #define encode_sequence_maxsz 0 4179b7b9fccSAndy Adamson #define decode_sequence_maxsz 0 418cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0 419cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0 4209b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 4219b7b9fccSAndy Adamson 4221da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 4231da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ 4241da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \ 4259b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4261da177e4SLinus Torvalds encode_putfh_maxsz + \ 4279104a55dSTrond Myklebust encode_read_maxsz) 4281da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \ 4299b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4301da177e4SLinus Torvalds decode_putfh_maxsz + \ 4319104a55dSTrond Myklebust decode_read_maxsz) 4321da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \ 4339b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4341da177e4SLinus Torvalds encode_putfh_maxsz + \ 4359104a55dSTrond Myklebust encode_readlink_maxsz) 4361da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \ 4379b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4381da177e4SLinus Torvalds decode_putfh_maxsz + \ 4399104a55dSTrond Myklebust decode_readlink_maxsz) 4401da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ 4419b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4421da177e4SLinus Torvalds encode_putfh_maxsz + \ 4439104a55dSTrond Myklebust encode_readdir_maxsz) 4441da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ 4459b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4461da177e4SLinus Torvalds decode_putfh_maxsz + \ 4479104a55dSTrond Myklebust decode_readdir_maxsz) 4481da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ 4499b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4501da177e4SLinus Torvalds encode_putfh_maxsz + \ 4519104a55dSTrond Myklebust encode_write_maxsz + \ 4524f9838c7STrond Myklebust encode_getattr_maxsz) 4531da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \ 4549b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4551da177e4SLinus Torvalds decode_putfh_maxsz + \ 4569104a55dSTrond Myklebust decode_write_maxsz + \ 4574f9838c7STrond Myklebust decode_getattr_maxsz) 4581da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \ 4599b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4601da177e4SLinus Torvalds encode_putfh_maxsz + \ 4618582715eSTrond Myklebust encode_commit_maxsz) 4621da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \ 4639b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4641da177e4SLinus Torvalds decode_putfh_maxsz + \ 4658582715eSTrond Myklebust decode_commit_maxsz) 4661da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \ 4679b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4681da177e4SLinus Torvalds encode_putfh_maxsz + \ 4692cebf828STrond Myklebust encode_open_maxsz + \ 4706168f62cSWeston Andros Adamson encode_access_maxsz + \ 4712cebf828STrond Myklebust encode_getfh_maxsz + \ 4722cebf828STrond Myklebust encode_getattr_maxsz) 4731da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \ 4749b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4751da177e4SLinus Torvalds decode_putfh_maxsz + \ 4762cebf828STrond Myklebust decode_open_maxsz + \ 4776168f62cSWeston Andros Adamson decode_access_maxsz + \ 4782cebf828STrond Myklebust decode_getfh_maxsz + \ 4792cebf828STrond Myklebust decode_getattr_maxsz) 4801da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \ 4811da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 4821da177e4SLinus Torvalds encode_putfh_maxsz + \ 4839104a55dSTrond Myklebust encode_open_confirm_maxsz) 4849104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \ 4859104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \ 4861da177e4SLinus Torvalds decode_putfh_maxsz + \ 4879104a55dSTrond Myklebust decode_open_confirm_maxsz) 4881da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \ 4899b7b9fccSAndy Adamson encode_sequence_maxsz + \ 4901da177e4SLinus Torvalds encode_putfh_maxsz + \ 4912cebf828STrond Myklebust encode_open_maxsz + \ 4926168f62cSWeston Andros Adamson encode_access_maxsz + \ 4932cebf828STrond Myklebust encode_getattr_maxsz) 4941da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \ 4959b7b9fccSAndy Adamson decode_sequence_maxsz + \ 4961da177e4SLinus Torvalds decode_putfh_maxsz + \ 4972cebf828STrond Myklebust decode_open_maxsz + \ 4986168f62cSWeston Andros Adamson decode_access_maxsz + \ 4992cebf828STrond Myklebust decode_getattr_maxsz) 5001da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \ 5011da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 5029b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5031da177e4SLinus Torvalds encode_putfh_maxsz + \ 5043947b74dSTrond Myklebust encode_open_downgrade_maxsz) 5051da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \ 5061da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 5079b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5081da177e4SLinus Torvalds decode_putfh_maxsz + \ 5093947b74dSTrond Myklebust decode_open_downgrade_maxsz) 5101da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \ 5119b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5121da177e4SLinus Torvalds encode_putfh_maxsz + \ 513cf805165STrond Myklebust encode_layoutreturn_maxsz + \ 5149104a55dSTrond Myklebust encode_close_maxsz + \ 515516a6af6STrond Myklebust encode_getattr_maxsz) 5161da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \ 5179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5181da177e4SLinus Torvalds decode_putfh_maxsz + \ 519cf805165STrond Myklebust decode_layoutreturn_maxsz + \ 5209104a55dSTrond Myklebust decode_close_maxsz + \ 521516a6af6STrond Myklebust decode_getattr_maxsz) 5221da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \ 5239b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5241da177e4SLinus Torvalds encode_putfh_maxsz + \ 5259104a55dSTrond Myklebust encode_setattr_maxsz + \ 5261da177e4SLinus Torvalds encode_getattr_maxsz) 5271da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \ 5289b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5291da177e4SLinus Torvalds decode_putfh_maxsz + \ 5309104a55dSTrond Myklebust decode_setattr_maxsz + \ 5319104a55dSTrond Myklebust decode_getattr_maxsz) 5321da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \ 5339b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5341da177e4SLinus Torvalds encode_putfh_maxsz + \ 5351da177e4SLinus Torvalds encode_fsinfo_maxsz) 5361da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \ 5379b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5381da177e4SLinus Torvalds decode_putfh_maxsz + \ 5391da177e4SLinus Torvalds decode_fsinfo_maxsz) 5401da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \ 5411da177e4SLinus Torvalds encode_renew_maxsz) 5421da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \ 5431da177e4SLinus Torvalds decode_renew_maxsz) 5441da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \ 5451da177e4SLinus Torvalds encode_setclientid_maxsz) 5461da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \ 5471da177e4SLinus Torvalds decode_setclientid_maxsz) 5481da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \ 5491da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \ 55083ca7f5aSChuck Lever encode_setclientid_confirm_maxsz) 5511da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \ 5521da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \ 55383ca7f5aSChuck Lever decode_setclientid_confirm_maxsz) 5541da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \ 5559b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5561da177e4SLinus Torvalds encode_putfh_maxsz + \ 5579104a55dSTrond Myklebust encode_lock_maxsz) 5581da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \ 5599b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5601da177e4SLinus Torvalds decode_putfh_maxsz + \ 5619104a55dSTrond Myklebust decode_lock_maxsz) 5621da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \ 5639b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5641da177e4SLinus Torvalds encode_putfh_maxsz + \ 5659104a55dSTrond Myklebust encode_lockt_maxsz) 5669104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \ 5679b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5689104a55dSTrond Myklebust decode_putfh_maxsz + \ 5699104a55dSTrond Myklebust decode_lockt_maxsz) 5701da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \ 5719b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5721da177e4SLinus Torvalds encode_putfh_maxsz + \ 5739104a55dSTrond Myklebust encode_locku_maxsz) 5741da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \ 5759b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5761da177e4SLinus Torvalds decode_putfh_maxsz + \ 5779104a55dSTrond Myklebust decode_locku_maxsz) 578d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \ 579d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \ 580d3c7b7ccSTrond Myklebust encode_lockowner_maxsz) 581d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \ 582d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \ 583d3c7b7ccSTrond Myklebust decode_lockowner_maxsz) 5841da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \ 5859b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5861da177e4SLinus Torvalds encode_putfh_maxsz + \ 58776b32999STrond Myklebust encode_access_maxsz + \ 58876b32999STrond Myklebust encode_getattr_maxsz) 5891da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \ 5909b7b9fccSAndy Adamson decode_sequence_maxsz + \ 5911da177e4SLinus Torvalds decode_putfh_maxsz + \ 59276b32999STrond Myklebust decode_access_maxsz + \ 59376b32999STrond Myklebust decode_getattr_maxsz) 5941da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \ 5959b7b9fccSAndy Adamson encode_sequence_maxsz + \ 5961da177e4SLinus Torvalds encode_putfh_maxsz + \ 59744c99933SChuck Lever encode_getattr_maxsz + \ 59844c99933SChuck Lever encode_renew_maxsz) 5991da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \ 6009b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6011da177e4SLinus Torvalds decode_putfh_maxsz + \ 60244c99933SChuck Lever decode_getattr_maxsz + \ 60344c99933SChuck Lever decode_renew_maxsz) 6041da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ 6059b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6061da177e4SLinus Torvalds encode_putfh_maxsz + \ 6071da177e4SLinus Torvalds encode_lookup_maxsz + \ 6081da177e4SLinus Torvalds encode_getattr_maxsz + \ 6091da177e4SLinus Torvalds encode_getfh_maxsz) 6101da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \ 6119b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6121da177e4SLinus Torvalds decode_putfh_maxsz + \ 613e6889620STrond Myklebust decode_lookup_maxsz + \ 6141da177e4SLinus Torvalds decode_getattr_maxsz + \ 6151da177e4SLinus Torvalds decode_getfh_maxsz) 6161da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \ 6179b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6181da177e4SLinus Torvalds encode_putrootfh_maxsz + \ 6191da177e4SLinus Torvalds encode_getattr_maxsz + \ 6201da177e4SLinus Torvalds encode_getfh_maxsz) 6211da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \ 6229b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6231da177e4SLinus Torvalds decode_putrootfh_maxsz + \ 6241da177e4SLinus Torvalds decode_getattr_maxsz + \ 6251da177e4SLinus Torvalds decode_getfh_maxsz) 6261da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \ 6279b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6281da177e4SLinus Torvalds encode_putfh_maxsz + \ 629778d2817STrond Myklebust encode_remove_maxsz) 6301da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \ 6319b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6321da177e4SLinus Torvalds decode_putfh_maxsz + \ 633778d2817STrond Myklebust decode_remove_maxsz) 6341da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \ 6359b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6361da177e4SLinus Torvalds encode_putfh_maxsz + \ 6371da177e4SLinus Torvalds encode_savefh_maxsz + \ 6381da177e4SLinus Torvalds encode_putfh_maxsz + \ 639778d2817STrond Myklebust encode_rename_maxsz) 6401da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \ 6419b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6421da177e4SLinus Torvalds decode_putfh_maxsz + \ 6431da177e4SLinus Torvalds decode_savefh_maxsz + \ 6441da177e4SLinus Torvalds decode_putfh_maxsz + \ 645778d2817STrond Myklebust decode_rename_maxsz) 6461da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \ 6479b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6481da177e4SLinus Torvalds encode_putfh_maxsz + \ 6491da177e4SLinus Torvalds encode_savefh_maxsz + \ 6501da177e4SLinus Torvalds encode_putfh_maxsz + \ 65191ba2eeeSTrond Myklebust encode_link_maxsz + \ 65291ba2eeeSTrond Myklebust encode_restorefh_maxsz + \ 653a9f6991bSTrond Myklebust encode_getattr_maxsz) 6541da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \ 6559b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6561da177e4SLinus Torvalds decode_putfh_maxsz + \ 6571da177e4SLinus Torvalds decode_savefh_maxsz + \ 6581da177e4SLinus Torvalds decode_putfh_maxsz + \ 65991ba2eeeSTrond Myklebust decode_link_maxsz + \ 66091ba2eeeSTrond Myklebust decode_restorefh_maxsz + \ 66191ba2eeeSTrond Myklebust decode_getattr_maxsz) 6621da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \ 6639b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6641da177e4SLinus Torvalds encode_putfh_maxsz + \ 6651da177e4SLinus Torvalds encode_symlink_maxsz + \ 6661da177e4SLinus Torvalds encode_getattr_maxsz + \ 6671da177e4SLinus Torvalds encode_getfh_maxsz) 6681da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \ 6699b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6701da177e4SLinus Torvalds decode_putfh_maxsz + \ 6711da177e4SLinus Torvalds decode_symlink_maxsz + \ 6721da177e4SLinus Torvalds decode_getattr_maxsz + \ 6731da177e4SLinus Torvalds decode_getfh_maxsz) 6741da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \ 6759b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6761da177e4SLinus Torvalds encode_putfh_maxsz + \ 6771da177e4SLinus Torvalds encode_create_maxsz + \ 67856ae19f3STrond Myklebust encode_getfh_maxsz + \ 67956ae19f3STrond Myklebust encode_getattr_maxsz) 6801da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \ 6819b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6821da177e4SLinus Torvalds decode_putfh_maxsz + \ 6831da177e4SLinus Torvalds decode_create_maxsz + \ 68456ae19f3STrond Myklebust decode_getfh_maxsz + \ 68556ae19f3STrond Myklebust decode_getattr_maxsz) 6861da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \ 6879b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6881da177e4SLinus Torvalds encode_putfh_maxsz + \ 6891da177e4SLinus Torvalds encode_getattr_maxsz) 6901da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \ 6919b7b9fccSAndy Adamson decode_sequence_maxsz + \ 6921da177e4SLinus Torvalds decode_putfh_maxsz + \ 6931da177e4SLinus Torvalds decode_getattr_maxsz) 6941da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \ 6959b7b9fccSAndy Adamson encode_sequence_maxsz + \ 6961da177e4SLinus Torvalds encode_putfh_maxsz + \ 6979104a55dSTrond Myklebust encode_statfs_maxsz) 6981da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \ 6999b7b9fccSAndy Adamson decode_sequence_maxsz + \ 7001da177e4SLinus Torvalds decode_putfh_maxsz + \ 7019104a55dSTrond Myklebust decode_statfs_maxsz) 7021da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \ 7039b7b9fccSAndy Adamson encode_sequence_maxsz + \ 704ab91f264STrond Myklebust encode_putfh_maxsz + \ 7051da177e4SLinus Torvalds encode_getattr_maxsz) 7061da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \ 7079b7b9fccSAndy Adamson decode_sequence_maxsz + \ 708ab91f264STrond Myklebust decode_putfh_maxsz + \ 7091da177e4SLinus Torvalds decode_getattr_maxsz) 7101da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \ 7119b7b9fccSAndy Adamson encode_sequence_maxsz + \ 7121da177e4SLinus Torvalds encode_putfh_maxsz + \ 713586f1c39STrond Myklebust encode_layoutreturn_maxsz + \ 714fa178f29STrond Myklebust encode_delegreturn_maxsz + \ 715fa178f29STrond Myklebust encode_getattr_maxsz) 7161da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \ 7179b7b9fccSAndy Adamson decode_sequence_maxsz + \ 718d8434d4cSTrond Myklebust decode_putfh_maxsz + \ 719586f1c39STrond Myklebust decode_layoutreturn_maxsz + \ 720fa178f29STrond Myklebust decode_delegreturn_maxsz + \ 721fa178f29STrond Myklebust decode_getattr_maxsz) 722029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \ 7239b7b9fccSAndy Adamson encode_sequence_maxsz + \ 724029d105eSJ. Bruce Fields encode_putfh_maxsz + \ 7259104a55dSTrond Myklebust encode_getacl_maxsz) 726029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \ 7279b7b9fccSAndy Adamson decode_sequence_maxsz + \ 728029d105eSJ. Bruce Fields decode_putfh_maxsz + \ 7299104a55dSTrond Myklebust decode_getacl_maxsz) 73023ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \ 7319b7b9fccSAndy Adamson encode_sequence_maxsz + \ 73223ec6965SJ. Bruce Fields encode_putfh_maxsz + \ 7339104a55dSTrond Myklebust encode_setacl_maxsz) 73423ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \ 7359b7b9fccSAndy Adamson decode_sequence_maxsz + \ 73623ec6965SJ. Bruce Fields decode_putfh_maxsz + \ 7379104a55dSTrond Myklebust decode_setacl_maxsz) 738683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \ 739683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \ 7409b7b9fccSAndy Adamson encode_sequence_maxsz + \ 741683b57b4STrond Myklebust encode_putfh_maxsz + \ 742e6889620STrond Myklebust encode_lookup_maxsz + \ 743b03d735bSChuck Lever encode_fs_locations_maxsz + \ 744b03d735bSChuck Lever encode_renew_maxsz) 745683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \ 746683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \ 7479b7b9fccSAndy Adamson decode_sequence_maxsz + \ 748683b57b4STrond Myklebust decode_putfh_maxsz + \ 749e6889620STrond Myklebust decode_lookup_maxsz + \ 750b03d735bSChuck Lever decode_fs_locations_maxsz + \ 751b03d735bSChuck Lever decode_renew_maxsz) 7525a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \ 7535a5ea0d4SBryan Schumaker encode_sequence_maxsz + \ 7545a5ea0d4SBryan Schumaker encode_putfh_maxsz + \ 7555a5ea0d4SBryan Schumaker encode_secinfo_maxsz) 7565a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \ 7575a5ea0d4SBryan Schumaker decode_sequence_maxsz + \ 7585a5ea0d4SBryan Schumaker decode_putfh_maxsz + \ 7595a5ea0d4SBryan Schumaker decode_secinfo_maxsz) 76044c99933SChuck Lever #define NFS4_enc_fsid_present_sz \ 76144c99933SChuck Lever (compound_encode_hdr_maxsz + \ 76244c99933SChuck Lever encode_sequence_maxsz + \ 76344c99933SChuck Lever encode_putfh_maxsz + \ 76444c99933SChuck Lever encode_getfh_maxsz + \ 76544c99933SChuck Lever encode_renew_maxsz) 76644c99933SChuck Lever #define NFS4_dec_fsid_present_sz \ 76744c99933SChuck Lever (compound_decode_hdr_maxsz + \ 76844c99933SChuck Lever decode_sequence_maxsz + \ 76944c99933SChuck Lever decode_putfh_maxsz + \ 77044c99933SChuck Lever decode_getfh_maxsz + \ 77144c99933SChuck Lever decode_renew_maxsz) 77299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 7737c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \ 7747c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \ 7757c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz) 7767c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \ 7777c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \ 7787c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz) 77999fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \ 78099fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \ 78199fe60d0SBenny Halevy encode_exchange_id_maxsz) 78299fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \ 78399fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \ 78499fe60d0SBenny Halevy decode_exchange_id_maxsz) 785fc931582SAndy Adamson #define NFS4_enc_create_session_sz \ 786fc931582SAndy Adamson (compound_encode_hdr_maxsz + \ 787fc931582SAndy Adamson encode_create_session_maxsz) 788fc931582SAndy Adamson #define NFS4_dec_create_session_sz \ 789fc931582SAndy Adamson (compound_decode_hdr_maxsz + \ 790fc931582SAndy Adamson decode_create_session_maxsz) 7910f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \ 7920f3e66c6SAndy Adamson encode_destroy_session_maxsz) 7930f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \ 7940f3e66c6SAndy Adamson decode_destroy_session_maxsz) 79566245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \ 79666245539STrond Myklebust encode_destroy_clientid_maxsz) 79766245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \ 79866245539STrond Myklebust decode_destroy_clientid_maxsz) 799fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \ 800fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 801fc01cea9SAndy Adamson encode_sequence_maxsz) 802fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \ 803fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \ 804fc01cea9SAndy Adamson decode_sequence_maxsz) 8052050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 8062050f0ccSAndy Adamson encode_sequence_maxsz + \ 8072050f0ccSAndy Adamson encode_putrootfh_maxsz + \ 8082050f0ccSAndy Adamson encode_fsinfo_maxsz) 8092050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \ 8102050f0ccSAndy Adamson decode_sequence_maxsz + \ 8112050f0ccSAndy Adamson decode_putrootfh_maxsz + \ 8122050f0ccSAndy Adamson decode_fsinfo_maxsz) 81318019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 81418019753SRicardo Labiaga encode_sequence_maxsz + \ 81518019753SRicardo Labiaga encode_reclaim_complete_maxsz) 81618019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \ 81718019753SRicardo Labiaga decode_sequence_maxsz + \ 81818019753SRicardo Labiaga decode_reclaim_complete_maxsz) 819b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \ 820b1f69b75SAndy Adamson encode_sequence_maxsz +\ 821b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz) 822b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \ 823b1f69b75SAndy Adamson decode_sequence_maxsz + \ 824b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz) 825b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \ 826b1f69b75SAndy Adamson encode_sequence_maxsz + \ 827b1f69b75SAndy Adamson encode_putfh_maxsz + \ 828b1f69b75SAndy Adamson encode_layoutget_maxsz) 829b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \ 830b1f69b75SAndy Adamson decode_sequence_maxsz + \ 831b1f69b75SAndy Adamson decode_putfh_maxsz + \ 832b1f69b75SAndy Adamson decode_layoutget_maxsz) 833863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \ 834863a3c6cSAndy Adamson encode_sequence_maxsz +\ 835863a3c6cSAndy Adamson encode_putfh_maxsz + \ 836863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \ 837863a3c6cSAndy Adamson encode_getattr_maxsz) 838863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \ 839863a3c6cSAndy Adamson decode_sequence_maxsz + \ 840863a3c6cSAndy Adamson decode_putfh_maxsz + \ 841863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \ 842863a3c6cSAndy Adamson decode_getattr_maxsz) 843cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \ 844cbe82603SBenny Halevy encode_sequence_maxsz + \ 845cbe82603SBenny Halevy encode_putfh_maxsz + \ 846cbe82603SBenny Halevy encode_layoutreturn_maxsz) 847cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \ 848cbe82603SBenny Halevy decode_sequence_maxsz + \ 849cbe82603SBenny Halevy decode_putfh_maxsz + \ 850cbe82603SBenny Halevy decode_layoutreturn_maxsz) 851fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \ 852fca78d6dSBryan Schumaker encode_sequence_maxsz + \ 853fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\ 854fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz) 855fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \ 856fca78d6dSBryan Schumaker decode_sequence_maxsz + \ 857fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \ 858fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz) 8597d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \ 8607d974794SBryan Schumaker encode_sequence_maxsz + \ 8617d974794SBryan Schumaker encode_test_stateid_maxsz) 8627d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \ 8637d974794SBryan Schumaker decode_sequence_maxsz + \ 8647d974794SBryan Schumaker decode_test_stateid_maxsz) 8659aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \ 8669aeda35fSBryan Schumaker encode_sequence_maxsz + \ 8679aeda35fSBryan Schumaker encode_free_stateid_maxsz) 8689aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \ 8699aeda35fSBryan Schumaker decode_sequence_maxsz + \ 8709aeda35fSBryan Schumaker decode_free_stateid_maxsz) 8712449ea2eSAlexandros Batsakis 8722449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8732449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz + 8742449ea2eSAlexandros Batsakis encode_sequence_maxsz + 8752449ea2eSAlexandros Batsakis encode_putfh_maxsz + 8762449ea2eSAlexandros Batsakis encode_getattr_maxsz) * 8772449ea2eSAlexandros Batsakis XDR_UNIT); 8782449ea2eSAlexandros Batsakis 8792449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH + 8802449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz + 8812449ea2eSAlexandros Batsakis decode_sequence_maxsz + 8822449ea2eSAlexandros Batsakis decode_putfh_maxsz) * 8832449ea2eSAlexandros Batsakis XDR_UNIT); 884f1c097beSAndy Adamson 885f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH + 886f1c097beSAndy Adamson compound_decode_hdr_maxsz + 887f1c097beSAndy Adamson decode_sequence_maxsz) * 888f1c097beSAndy Adamson XDR_UNIT); 889f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 89099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 8911da177e4SLinus Torvalds 892bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = { 893bca79478STrond Myklebust [NF4BAD] = 0, 894bca79478STrond Myklebust [NF4REG] = S_IFREG, 895bca79478STrond Myklebust [NF4DIR] = S_IFDIR, 896bca79478STrond Myklebust [NF4BLK] = S_IFBLK, 897bca79478STrond Myklebust [NF4CHR] = S_IFCHR, 898bca79478STrond Myklebust [NF4LNK] = S_IFLNK, 899bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK, 900bca79478STrond Myklebust [NF4FIFO] = S_IFIFO, 901bca79478STrond Myklebust [NF4ATTRDIR] = 0, 902bca79478STrond Myklebust [NF4NAMEDATTR] = 0, 9031da177e4SLinus Torvalds }; 9041da177e4SLinus Torvalds 9051da177e4SLinus Torvalds struct compound_hdr { 9061da177e4SLinus Torvalds int32_t status; 9071da177e4SLinus Torvalds uint32_t nops; 908d017931cSAndy Adamson __be32 * nops_p; 9091da177e4SLinus Torvalds uint32_t taglen; 9101da177e4SLinus Torvalds char * tag; 9110c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */ 91266cc0429SBenny Halevy u32 minorversion; 9131da177e4SLinus Torvalds }; 9141da177e4SLinus Torvalds 91513c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) 91613c65ce9SBenny Halevy { 91713c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes); 91813c65ce9SBenny Halevy BUG_ON(!p); 91913c65ce9SBenny Halevy return p; 92013c65ce9SBenny Halevy } 9211da177e4SLinus Torvalds 922cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) 923cb17e556STrond Myklebust { 924cb17e556STrond Myklebust __be32 *p; 925cb17e556STrond Myklebust 926cb17e556STrond Myklebust p = xdr_reserve_space(xdr, len); 927cb17e556STrond Myklebust xdr_encode_opaque_fixed(p, buf, len); 928cb17e556STrond Myklebust } 929cb17e556STrond Myklebust 9301da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 9311da177e4SLinus Torvalds { 9328687b63aSAl Viro __be32 *p; 9331da177e4SLinus Torvalds 9346fdfb0bcSTrond Myklebust p = reserve_space(xdr, 4 + len); 9351da177e4SLinus Torvalds xdr_encode_opaque(p, str, len); 9361da177e4SLinus Torvalds } 9371da177e4SLinus Torvalds 9384ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n) 9394ade9821STrond Myklebust { 9404ade9821STrond Myklebust __be32 *p; 9414ade9821STrond Myklebust 9424ade9821STrond Myklebust p = reserve_space(xdr, 4); 9434ade9821STrond Myklebust *p = cpu_to_be32(n); 9444ade9821STrond Myklebust } 9454ade9821STrond Myklebust 946ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n) 947ff2eb681STrond Myklebust { 948ff2eb681STrond Myklebust __be32 *p; 949ff2eb681STrond Myklebust 950ff2eb681STrond Myklebust p = reserve_space(xdr, 8); 951ff2eb681STrond Myklebust xdr_encode_hyper(p, n); 952ff2eb681STrond Myklebust } 953ff2eb681STrond Myklebust 9544ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr, 9554ade9821STrond Myklebust const struct nfs_seqid *seqid) 9564ade9821STrond Myklebust { 957a6796419STrond Myklebust if (seqid != NULL) 9584ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter); 959a6796419STrond Myklebust else 960a6796419STrond Myklebust encode_uint32(xdr, 0); 9614ade9821STrond Myklebust } 9624ade9821STrond Myklebust 9630c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr, 9640c4e8c18SBenny Halevy struct rpc_rqst *req, 9650c4e8c18SBenny Halevy struct compound_hdr *hdr) 9661da177e4SLinus Torvalds { 9678687b63aSAl Viro __be32 *p; 968a17c2153STrond Myklebust struct rpc_auth *auth = req->rq_cred->cr_auth; 9690c4e8c18SBenny Halevy 9700c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply. 9710c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent, 9720c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */ 9730c4e8c18SBenny Halevy hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 9741da177e4SLinus Torvalds 9757fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 9766fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag); 9776fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8); 978e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion); 979d017931cSAndy Adamson hdr->nops_p = p; 98034558513SBenny Halevy *p = cpu_to_be32(hdr->nops); 981d017931cSAndy Adamson } 982d017931cSAndy Adamson 983ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op, 984ab19b481STrond Myklebust uint32_t replen, 985ab19b481STrond Myklebust struct compound_hdr *hdr) 986ab19b481STrond Myklebust { 987ab19b481STrond Myklebust encode_uint32(xdr, op); 988ab19b481STrond Myklebust hdr->nops++; 989ab19b481STrond Myklebust hdr->replen += replen; 990ab19b481STrond Myklebust } 991ab19b481STrond Myklebust 992d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr) 993d017931cSAndy Adamson { 9947fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 995d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops); 9961da177e4SLinus Torvalds } 9971da177e4SLinus Torvalds 998ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid) 999ea9d23f5STrond Myklebust { 10002d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 1001ea9d23f5STrond Myklebust } 1002ea9d23f5STrond Myklebust 10031da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 10041da177e4SLinus Torvalds { 1005cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE); 10061da177e4SLinus Torvalds } 10071da177e4SLinus Torvalds 1008aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, 1009aa9c2669SDavid Quigley const struct nfs4_label *label, 10105334c5bdSKinglong Mee const struct nfs_server *server, 10115334c5bdSKinglong Mee bool excl_check) 10121da177e4SLinus Torvalds { 10131da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ]; 10141da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ]; 10151da177e4SLinus Torvalds int owner_namelen = 0; 10161da177e4SLinus Torvalds int owner_grouplen = 0; 10178687b63aSAl Viro __be32 *p; 1018d7067b2dSTrond Myklebust unsigned i; 1019d7067b2dSTrond Myklebust uint32_t len = 0; 1020d7067b2dSTrond Myklebust uint32_t bmval_len; 1021d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 }; 10221da177e4SLinus Torvalds 10231da177e4SLinus Torvalds /* 10241da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once. 10251da177e4SLinus Torvalds * In the worst-case, this would be 1026a09df2caSDavid Quigley * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) 1027a09df2caSDavid Quigley * = 40 bytes, plus any contribution from variable-length fields 102823ec6965SJ. Bruce Fields * such as owner/group. 10291da177e4SLinus Torvalds */ 1030d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_SIZE) { 1031d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE; 10321da177e4SLinus Torvalds len += 8; 1033d7067b2dSTrond Myklebust } 1034d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) { 1035d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE; 10361da177e4SLinus Torvalds len += 4; 1037d7067b2dSTrond Myklebust } 10381da177e4SLinus Torvalds if (iap->ia_valid & ATTR_UID) { 1039e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ); 10401da177e4SLinus Torvalds if (owner_namelen < 0) { 1041fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n", 1042e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid)); 10431da177e4SLinus Torvalds /* XXX */ 10441da177e4SLinus Torvalds strcpy(owner_name, "nobody"); 10451da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1; 10461da177e4SLinus Torvalds /* goto out; */ 10471da177e4SLinus Torvalds } 1048d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER; 10491da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2); 10501da177e4SLinus Torvalds } 10511da177e4SLinus Torvalds if (iap->ia_valid & ATTR_GID) { 1052e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ); 10531da177e4SLinus Torvalds if (owner_grouplen < 0) { 1054fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n", 1055e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid)); 10561da177e4SLinus Torvalds strcpy(owner_group, "nobody"); 10571da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1; 10581da177e4SLinus Torvalds /* goto out; */ 10591da177e4SLinus Torvalds } 1060d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP; 10611da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); 10621da177e4SLinus Torvalds } 1063d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) { 1064d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10651da177e4SLinus Torvalds len += 16; 1066d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) { 1067d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET; 10681da177e4SLinus Torvalds len += 4; 1069d7067b2dSTrond Myklebust } 1070d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) { 1071d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10721da177e4SLinus Torvalds len += 16; 1073d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) { 1074d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET; 10751da177e4SLinus Torvalds len += 4; 1076d7067b2dSTrond Myklebust } 10775334c5bdSKinglong Mee 10785334c5bdSKinglong Mee if (excl_check) { 10795334c5bdSKinglong Mee const u32 *excl_bmval = server->exclcreat_bitmask; 10805334c5bdSKinglong Mee bmval[0] &= excl_bmval[0]; 10815334c5bdSKinglong Mee bmval[1] &= excl_bmval[1]; 10825334c5bdSKinglong Mee bmval[2] &= excl_bmval[2]; 10835334c5bdSKinglong Mee 10845334c5bdSKinglong Mee if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) 10855334c5bdSKinglong Mee label = NULL; 10865334c5bdSKinglong Mee } 10875334c5bdSKinglong Mee 1088b4a2cf76STrond Myklebust if (label) { 1089b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); 1090d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; 1091d7067b2dSTrond Myklebust } 1092d7067b2dSTrond Myklebust 1093d7067b2dSTrond Myklebust if (bmval[2] != 0) 1094b4a2cf76STrond Myklebust bmval_len = 3; 1095d7067b2dSTrond Myklebust else if (bmval[1] != 0) 1096d7067b2dSTrond Myklebust bmval_len = 2; 1097d7067b2dSTrond Myklebust else 1098d7067b2dSTrond Myklebust bmval_len = 1; 1099b4a2cf76STrond Myklebust 1100d7067b2dSTrond Myklebust p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len); 11011da177e4SLinus Torvalds 1102b4a2cf76STrond Myklebust *p++ = cpu_to_be32(bmval_len); 1103d7067b2dSTrond Myklebust for (i = 0; i < bmval_len; i++) 1104d7067b2dSTrond Myklebust *p++ = cpu_to_be32(bmval[i]); 1105d7067b2dSTrond Myklebust *p++ = cpu_to_be32(len); 11061da177e4SLinus Torvalds 1107d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE) 1108b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size); 1109d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE) 1110e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); 1111d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER) 1112811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen); 1113d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) 1114811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen); 1115d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { 11161da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) { 1117e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1118042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec); 1119d3f6baaaSTrond Myklebust *p++ = cpu_to_be32(iap->ia_atime.tv_nsec); 1120d7067b2dSTrond Myklebust } else 1121e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11221da177e4SLinus Torvalds } 1123d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { 11241da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) { 1125e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME); 1126042ad0b3SBryan Schumaker p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec); 1127e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec); 1128d7067b2dSTrond Myklebust } else 1129e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME); 11301da177e4SLinus Torvalds } 1131d7067b2dSTrond Myklebust if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { 1132aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs); 1133aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi); 1134aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len); 1135aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len); 1136aa9c2669SDavid Quigley } 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds /* out: */ 11391da177e4SLinus Torvalds } 11401da177e4SLinus Torvalds 1141cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 11421da177e4SLinus Torvalds { 1143475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr); 1144475d4ba0STrond Myklebust encode_uint32(xdr, access); 11451da177e4SLinus Torvalds } 11461da177e4SLinus Torvalds 1147cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 11481da177e4SLinus Torvalds { 1149ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); 11504ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 1151566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 11521da177e4SLinus Torvalds } 11531da177e4SLinus Torvalds 11540b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) 11551da177e4SLinus Torvalds { 11568687b63aSAl Viro __be32 *p; 11571da177e4SLinus Torvalds 1158475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr); 1159475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1160b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 116134558513SBenny Halevy *p = cpu_to_be32(args->count); 11621da177e4SLinus Torvalds } 11631da177e4SLinus Torvalds 1164cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 11651da177e4SLinus Torvalds { 11668687b63aSAl Viro __be32 *p; 11671da177e4SLinus Torvalds 1168475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr); 1169475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype); 11701da177e4SLinus Torvalds 11711da177e4SLinus Torvalds switch (create->ftype) { 11721da177e4SLinus Torvalds case NF4LNK: 117313c65ce9SBenny Halevy p = reserve_space(xdr, 4); 117434558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len); 11752fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0, 11762fcc213aSChuck Lever create->u.symlink.len); 11772fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE; 11781da177e4SLinus Torvalds break; 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds case NF4BLK: case NF4CHR: 118113c65ce9SBenny Halevy p = reserve_space(xdr, 8); 1182e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1); 118334558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2); 11841da177e4SLinus Torvalds break; 11851da177e4SLinus Torvalds 11861da177e4SLinus Torvalds default: 11871da177e4SLinus Torvalds break; 11881da177e4SLinus Torvalds } 11891da177e4SLinus Torvalds 1190811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name); 11915334c5bdSKinglong Mee encode_attrs(xdr, create->attrs, create->label, create->server, false); 11921da177e4SLinus Torvalds } 11931da177e4SLinus Torvalds 1194cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr) 11951da177e4SLinus Torvalds { 11968687b63aSAl Viro __be32 *p; 11971da177e4SLinus Torvalds 1198475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1199475d4ba0STrond Myklebust p = reserve_space(xdr, 8); 1200e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 120134558513SBenny Halevy *p = cpu_to_be32(bitmap); 12021da177e4SLinus Torvalds } 12031da177e4SLinus Torvalds 1204cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 12051da177e4SLinus Torvalds { 12068687b63aSAl Viro __be32 *p; 12071da177e4SLinus Torvalds 1208475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1209475d4ba0STrond Myklebust p = reserve_space(xdr, 12); 1210e75bc1c8SBenny Halevy *p++ = cpu_to_be32(2); 1211e75bc1c8SBenny Halevy *p++ = cpu_to_be32(bm0); 121234558513SBenny Halevy *p = cpu_to_be32(bm1); 12131da177e4SLinus Torvalds } 12141da177e4SLinus Torvalds 1215dae100c2SFred Isaman static void 1216dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr, 1217dae100c2SFred Isaman uint32_t bm0, uint32_t bm1, uint32_t bm2, 1218dae100c2SFred Isaman struct compound_hdr *hdr) 1219dae100c2SFred Isaman { 1220dae100c2SFred Isaman __be32 *p; 1221dae100c2SFred Isaman 1222ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr); 1223dae100c2SFred Isaman if (bm2) { 1224dae100c2SFred Isaman p = reserve_space(xdr, 16); 1225dae100c2SFred Isaman *p++ = cpu_to_be32(3); 1226dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1227dae100c2SFred Isaman *p++ = cpu_to_be32(bm1); 1228dae100c2SFred Isaman *p = cpu_to_be32(bm2); 1229dae100c2SFred Isaman } else if (bm1) { 1230dae100c2SFred Isaman p = reserve_space(xdr, 12); 1231dae100c2SFred Isaman *p++ = cpu_to_be32(2); 1232dae100c2SFred Isaman *p++ = cpu_to_be32(bm0); 1233dae100c2SFred Isaman *p = cpu_to_be32(bm1); 1234dae100c2SFred Isaman } else { 1235dae100c2SFred Isaman p = reserve_space(xdr, 8); 1236dae100c2SFred Isaman *p++ = cpu_to_be32(1); 1237dae100c2SFred Isaman *p = cpu_to_be32(bm0); 1238dae100c2SFred Isaman } 1239dae100c2SFred Isaman } 1240dae100c2SFred Isaman 1241cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12421da177e4SLinus Torvalds { 1243a09df2caSDavid Quigley encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0], 1244a09df2caSDavid Quigley bitmask[1] & nfs4_fattr_bitmap[1], 1245a09df2caSDavid Quigley bitmask[2] & nfs4_fattr_bitmap[2], 1246a09df2caSDavid Quigley hdr); 12471da177e4SLinus Torvalds } 12481da177e4SLinus Torvalds 124988034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask, 12501549210fSTrond Myklebust const u32 *open_bitmap, 125188034c3dSAndy Adamson struct compound_hdr *hdr) 125288034c3dSAndy Adamson { 125388034c3dSAndy Adamson encode_getattr_three(xdr, 12541549210fSTrond Myklebust bitmask[0] & open_bitmap[0], 12551549210fSTrond Myklebust bitmask[1] & open_bitmap[1], 12561549210fSTrond Myklebust bitmask[2] & open_bitmap[2], 125788034c3dSAndy Adamson hdr); 125888034c3dSAndy Adamson } 125988034c3dSAndy Adamson 1260cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 12611da177e4SLinus Torvalds { 1262dae100c2SFred Isaman encode_getattr_three(xdr, 1263dae100c2SFred Isaman bitmask[0] & nfs4_fsinfo_bitmap[0], 1264dae100c2SFred Isaman bitmask[1] & nfs4_fsinfo_bitmap[1], 1265dae100c2SFred Isaman bitmask[2] & nfs4_fsinfo_bitmap[2], 1266dae100c2SFred Isaman hdr); 12671da177e4SLinus Torvalds } 12681da177e4SLinus Torvalds 1269cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1270830b8e33SManoj Naik { 1271cf8cdbe5SAndy Adamson encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0], 1272cf8cdbe5SAndy Adamson bitmask[1] & nfs4_fs_locations_bitmap[1], hdr); 1273830b8e33SManoj Naik } 1274830b8e33SManoj Naik 1275cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 12761da177e4SLinus Torvalds { 1277ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr); 12781da177e4SLinus Torvalds } 12791da177e4SLinus Torvalds 1280cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 12811da177e4SLinus Torvalds { 1282ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr); 12836fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 12841da177e4SLinus Torvalds } 12851da177e4SLinus Torvalds 1286911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block) 1287911d1aafSTrond Myklebust { 1288f44106e2SJeff Layton if (fl->fl_type == F_RDLCK) 1289911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT; 1290911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT; 1291911d1aafSTrond Myklebust } 1292911d1aafSTrond Myklebust 1293911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl) 1294911d1aafSTrond Myklebust { 1295911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX) 1296911d1aafSTrond Myklebust return ~(uint64_t)0; 1297911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1; 1298911d1aafSTrond Myklebust } 1299911d1aafSTrond Myklebust 1300daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner) 1301daccbdedSTrond Myklebust { 1302daccbdedSTrond Myklebust __be32 *p; 1303daccbdedSTrond Myklebust 1304d035c36cSTrond Myklebust p = reserve_space(xdr, 32); 1305daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid); 1306d035c36cSTrond Myklebust *p++ = cpu_to_be32(20); 1307daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8); 1308d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev); 1309daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id); 1310daccbdedSTrond Myklebust } 1311daccbdedSTrond Myklebust 13121da177e4SLinus Torvalds /* 13131da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32 13141da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 13151da177e4SLinus Torvalds */ 1316cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr) 13171da177e4SLinus Torvalds { 13188687b63aSAl Viro __be32 *p; 13191da177e4SLinus Torvalds 1320475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr); 1321475d4ba0STrond Myklebust p = reserve_space(xdr, 28); 1322e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1323e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim); 1324b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1325b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 132634558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner); 1327911d1aafSTrond Myklebust if (args->new_lock_owner){ 13284ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid); 1329425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid); 13304ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 1331daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13321da177e4SLinus Torvalds } 13331da177e4SLinus Torvalds else { 1334425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid); 13354ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid); 13361da177e4SLinus Torvalds } 13371da177e4SLinus Torvalds } 13381da177e4SLinus Torvalds 1339cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 13401da177e4SLinus Torvalds { 13418687b63aSAl Viro __be32 *p; 13421da177e4SLinus Torvalds 1343475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr); 1344475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1345e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1346b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 1347b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1348daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner); 13491da177e4SLinus Torvalds } 13501da177e4SLinus Torvalds 1351cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 13521da177e4SLinus Torvalds { 13538687b63aSAl Viro __be32 *p; 13541da177e4SLinus Torvalds 1355475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); 1356475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); 13574ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid); 1358425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1359ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 1360b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start); 136134558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 13621da177e4SLinus Torvalds } 13631da177e4SLinus Torvalds 1364d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1365d3c7b7ccSTrond Myklebust { 1366ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1367d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner); 1368d3c7b7ccSTrond Myklebust } 1369d3c7b7ccSTrond Myklebust 1370cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 13711da177e4SLinus Torvalds { 1372ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr); 13736fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 13741da177e4SLinus Torvalds } 13751da177e4SLinus Torvalds 13766ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access) 13771da177e4SLinus Torvalds { 13788687b63aSAl Viro __be32 *p; 13791da177e4SLinus Torvalds 138013c65ce9SBenny Halevy p = reserve_space(xdr, 8); 13816ae37339STrond Myklebust *p++ = cpu_to_be32(share_access); 138234558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ 13831da177e4SLinus Torvalds } 13841da177e4SLinus Torvalds 13851da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg) 13861da177e4SLinus Torvalds { 13878687b63aSAl Viro __be32 *p; 13881da177e4SLinus Torvalds /* 13891da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 13901da177e4SLinus Torvalds * owner 4 = 32 13911da177e4SLinus Torvalds */ 13924ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 13936ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 139495b72eb0STrond Myklebust p = reserve_space(xdr, 36); 1395b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid); 139695b72eb0STrond Myklebust *p++ = cpu_to_be32(24); 139793f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8); 1398d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev); 139995b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier); 140095b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time); 14011da177e4SLinus Torvalds } 14021da177e4SLinus Torvalds 14031da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14041da177e4SLinus Torvalds { 14058687b63aSAl Viro __be32 *p; 14061da177e4SLinus Torvalds 140713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 1408549b19ccSTrond Myklebust switch(arg->createmode) { 1409549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED: 141034558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED); 14115334c5bdSKinglong Mee encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false); 14121da177e4SLinus Torvalds break; 1413549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED: 14144882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED); 14155334c5bdSKinglong Mee encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false); 1416549b19ccSTrond Myklebust break; 1417549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE: 1418549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE); 1419549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier); 1420549b19ccSTrond Myklebust break; 1421549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1: 14224882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1); 14234882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier); 14245334c5bdSKinglong Mee encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true); 14254882ef72SAlexandros Batsakis } 14264882ef72SAlexandros Batsakis } 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg) 14291da177e4SLinus Torvalds { 14308687b63aSAl Viro __be32 *p; 14311da177e4SLinus Torvalds 143213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14331da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) { 14341da177e4SLinus Torvalds case 0: 143534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 14361da177e4SLinus Torvalds break; 14371da177e4SLinus Torvalds default: 143834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE); 14391da177e4SLinus Torvalds encode_createmode(xdr, arg); 14401da177e4SLinus Torvalds } 14411da177e4SLinus Torvalds } 14421da177e4SLinus Torvalds 1443bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type) 14441da177e4SLinus Torvalds { 14458687b63aSAl Viro __be32 *p; 14461da177e4SLinus Torvalds 144713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 14481da177e4SLinus Torvalds switch (delegation_type) { 14491da177e4SLinus Torvalds case 0: 145034558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE); 14511da177e4SLinus Torvalds break; 14521da177e4SLinus Torvalds case FMODE_READ: 145334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ); 14541da177e4SLinus Torvalds break; 14551da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ: 145634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE); 14571da177e4SLinus Torvalds break; 14581da177e4SLinus Torvalds default: 14591da177e4SLinus Torvalds BUG(); 14601da177e4SLinus Torvalds } 14611da177e4SLinus Torvalds } 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name) 14641da177e4SLinus Torvalds { 14658687b63aSAl Viro __be32 *p; 14661da177e4SLinus Torvalds 146713c65ce9SBenny Halevy p = reserve_space(xdr, 4); 146834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL); 14691da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14701da177e4SLinus Torvalds } 14711da177e4SLinus Torvalds 1472bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type) 14731da177e4SLinus Torvalds { 14748687b63aSAl Viro __be32 *p; 14751da177e4SLinus Torvalds 147613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 147734558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS); 14781da177e4SLinus Torvalds encode_delegation_type(xdr, type); 14791da177e4SLinus Torvalds } 14801da177e4SLinus Torvalds 14811da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid) 14821da177e4SLinus Torvalds { 14838687b63aSAl Viro __be32 *p; 14841da177e4SLinus Torvalds 1485ea9d23f5STrond Myklebust p = reserve_space(xdr, 4); 1486ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1487ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 14881da177e4SLinus Torvalds encode_string(xdr, name->len, name->name); 14891da177e4SLinus Torvalds } 14901da177e4SLinus Torvalds 1491d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr) 1492d9fc6619STrond Myklebust { 1493d9fc6619STrond Myklebust __be32 *p; 1494d9fc6619STrond Myklebust 1495d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1496d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH); 1497d9fc6619STrond Myklebust } 1498d9fc6619STrond Myklebust 1499d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid) 1500d9fc6619STrond Myklebust { 1501d9fc6619STrond Myklebust __be32 *p; 1502d9fc6619STrond Myklebust 1503d9fc6619STrond Myklebust p = reserve_space(xdr, 4); 1504d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH); 1505d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid); 1506d9fc6619STrond Myklebust } 1507d9fc6619STrond Myklebust 1508cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 15091da177e4SLinus Torvalds { 1510ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr); 15111da177e4SLinus Torvalds encode_openhdr(xdr, arg); 15121da177e4SLinus Torvalds encode_opentype(xdr, arg); 15131da177e4SLinus Torvalds switch (arg->claim) { 15141da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 15151da177e4SLinus Torvalds encode_claim_null(xdr, arg->name); 15161da177e4SLinus Torvalds break; 15171da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 15181da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type); 15191da177e4SLinus Torvalds break; 15201da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR: 15211da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation); 15221da177e4SLinus Torvalds break; 1523d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH: 1524d9fc6619STrond Myklebust encode_claim_fh(xdr); 1525d9fc6619STrond Myklebust break; 1526d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1527d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation); 1528d9fc6619STrond Myklebust break; 15291da177e4SLinus Torvalds default: 15301da177e4SLinus Torvalds BUG(); 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds } 15331da177e4SLinus Torvalds 1534cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 15351da177e4SLinus Torvalds { 1536ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr); 1537ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid); 15384ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15391da177e4SLinus Torvalds } 15401da177e4SLinus Torvalds 1541cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 15421da177e4SLinus Torvalds { 1543ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); 1544566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 15454ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid); 15466ae37339STrond Myklebust encode_share_access(xdr, arg->share_access); 15471da177e4SLinus Torvalds } 15481da177e4SLinus Torvalds 1549cf8cdbe5SAndy Adamson static void 1550d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 15511da177e4SLinus Torvalds { 1552ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr); 15536fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data); 15541da177e4SLinus Torvalds } 15551da177e4SLinus Torvalds 1556cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 15571da177e4SLinus Torvalds { 1558ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr); 15591da177e4SLinus Torvalds } 15601da177e4SLinus Torvalds 15613c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 15623c6b899cSAnna Schumaker struct compound_hdr *hdr) 15631da177e4SLinus Torvalds { 15648687b63aSAl Viro __be32 *p; 15651da177e4SLinus Torvalds 1566ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr); 15679b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 15681da177e4SLinus Torvalds 156913c65ce9SBenny Halevy p = reserve_space(xdr, 12); 1570b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 157134558513SBenny Halevy *p = cpu_to_be32(args->count); 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds 1574cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 15751da177e4SLinus Torvalds { 1576aa9c2669SDavid Quigley uint32_t attrs[3] = { 157728331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR, 157828331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID, 157928331a46STrond Myklebust }; 15806f7a35bdSTrond Myklebust uint32_t dircount = readdir->count >> 1; 1581cd93710eSChuck Lever __be32 *p, verf[2]; 1582d204c5d2STrond Myklebust uint32_t attrlen = 0; 1583d204c5d2STrond Myklebust unsigned int i; 15841da177e4SLinus Torvalds 158582f2e547SBryan Schumaker if (readdir->plus) { 158682f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 158728331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID; 158882f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER| 158982f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| 159082f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| 159182f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 1592d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; 15936f7a35bdSTrond Myklebust dircount >>= 1; 159482f2e547SBryan Schumaker } 159528331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */ 159628331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 159728331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID; 1598d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) { 1599d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i]; 1600d204c5d2STrond Myklebust if (attrs[i] != 0) 1601d204c5d2STrond Myklebust attrlen = i+1; 1602d204c5d2STrond Myklebust } 16036f7a35bdSTrond Myklebust 1604475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr); 1605ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie); 1606cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier); 1607d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2)); 16086f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount); 16096f7a35bdSTrond Myklebust *p++ = cpu_to_be32(readdir->count); 1610d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen); 1611d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++) 1612d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]); 1613cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 1614aa9c2669SDavid Quigley 1615aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n", 161644109241SFred Isaman __func__, 1617eadf4598STrond Myklebust (unsigned long long)readdir->cookie, 1618cd93710eSChuck Lever verf[0], verf[1], 1619eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0], 1620aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1], 1621aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]); 16221da177e4SLinus Torvalds } 16231da177e4SLinus Torvalds 1624cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 16251da177e4SLinus Torvalds { 1626ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr); 16271da177e4SLinus Torvalds } 16281da177e4SLinus Torvalds 1629cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 16301da177e4SLinus Torvalds { 1631ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr); 16326fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 16331da177e4SLinus Torvalds } 16341da177e4SLinus Torvalds 1635cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 16361da177e4SLinus Torvalds { 1637ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr); 1638811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name); 1639811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name); 16401da177e4SLinus Torvalds } 16411da177e4SLinus Torvalds 1642bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid, 1643bb4dae5eSChuck Lever struct compound_hdr *hdr) 16441da177e4SLinus Torvalds { 1645475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr); 1646ff2eb681STrond Myklebust encode_uint64(xdr, clid); 16471da177e4SLinus Torvalds } 16481da177e4SLinus Torvalds 1649cf8cdbe5SAndy Adamson static void 1650d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 165156ae19f3STrond Myklebust { 1652ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr); 165356ae19f3STrond Myklebust } 165456ae19f3STrond Myklebust 16559f06c719SChuck Lever static void 1656d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) 165723ec6965SJ. Bruce Fields { 16588687b63aSAl Viro __be32 *p; 165923ec6965SJ. Bruce Fields 1660ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr); 1661ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid); 166213c65ce9SBenny Halevy p = reserve_space(xdr, 2*4); 1663e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 166434558513SBenny Halevy *p = cpu_to_be32(FATTR4_WORD0_ACL); 166513c65ce9SBenny Halevy p = reserve_space(xdr, 4); 166634558513SBenny Halevy *p = cpu_to_be32(arg->acl_len); 16678fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len); 166823ec6965SJ. Bruce Fields } 166923ec6965SJ. Bruce Fields 1670cf8cdbe5SAndy Adamson static void 1671d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 16721da177e4SLinus Torvalds { 1673ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr); 16741da177e4SLinus Torvalds } 16751da177e4SLinus Torvalds 1676cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 16771da177e4SLinus Torvalds { 1678ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr); 1679ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid); 16805334c5bdSKinglong Mee encode_attrs(xdr, arg->iap, arg->label, server, false); 16811da177e4SLinus Torvalds } 16821da177e4SLinus Torvalds 1683cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr) 16841da177e4SLinus Torvalds { 16858687b63aSAl Viro __be32 *p; 16861da177e4SLinus Torvalds 168770019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr); 1688cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier); 16891da177e4SLinus Torvalds 16903a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id), 16913a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id); 169213c65ce9SBenny Halevy p = reserve_space(xdr, 4); 169334558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog); 16941da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid); 16951da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 169613c65ce9SBenny Halevy p = reserve_space(xdr, 4); 16973a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident); 16981da177e4SLinus Torvalds } 16991da177e4SLinus Torvalds 1700bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 17011da177e4SLinus Torvalds { 1702475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM, 1703475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr); 1704ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid); 1705cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm); 17061da177e4SLinus Torvalds } 17071da177e4SLinus Torvalds 17083c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args, 17093c6b899cSAnna Schumaker struct compound_hdr *hdr) 17101da177e4SLinus Torvalds { 17118687b63aSAl Viro __be32 *p; 17121da177e4SLinus Torvalds 1713ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr); 17149b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 17151da177e4SLinus Torvalds 171613c65ce9SBenny Halevy p = reserve_space(xdr, 16); 1717b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset); 1718e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable); 171934558513SBenny Halevy *p = cpu_to_be32(args->count); 17201da177e4SLinus Torvalds 17211da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 17221da177e4SLinus Torvalds } 17231da177e4SLinus Torvalds 1724cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 17251da177e4SLinus Torvalds { 1726ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr); 1727ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid); 17281da177e4SLinus Torvalds } 17299b7b9fccSAndy Adamson 17305a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 17315a5ea0d4SBryan Schumaker { 1732ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr); 17336fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name); 17345a5ea0d4SBryan Schumaker } 17355a5ea0d4SBryan Schumaker 173699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 17379b7b9fccSAndy Adamson /* NFSv4.1 operations */ 17387c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr, 173971a097c6STrond Myklebust struct nfs41_bind_conn_to_session_args *args, 17407c44f1aeSWeston Andros Adamson struct compound_hdr *hdr) 17417c44f1aeSWeston Andros Adamson { 17427c44f1aeSWeston Andros Adamson __be32 *p; 17437c44f1aeSWeston Andros Adamson 17447c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION, 17457c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr); 174671a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN); 17477c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8); 174871a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir); 174971a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0); 17507c44f1aeSWeston Andros Adamson } 17517c44f1aeSWeston Andros Adamson 17522031cd1aSWeston Andros Adamson static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 17532031cd1aSWeston Andros Adamson { 17542031cd1aSWeston Andros Adamson unsigned int i; 17552031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS); 17562031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) 17572031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]); 17582031cd1aSWeston Andros Adamson } 17592031cd1aSWeston Andros Adamson 176099fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr, 176199fe60d0SBenny Halevy struct nfs41_exchange_id_args *args, 176299fe60d0SBenny Halevy struct compound_hdr *hdr) 176399fe60d0SBenny Halevy { 176499fe60d0SBenny Halevy __be32 *p; 1765d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT]; 1766db8ac8baSWeston Andros Adamson int len = 0; 176799fe60d0SBenny Halevy 176870019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); 1769cd93710eSChuck Lever encode_nfs4_verifier(xdr, args->verifier); 177099fe60d0SBenny Halevy 17713a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id), 17723a6bb738SJeff Layton args->client->cl_owner_id); 177399fe60d0SBenny Halevy 17742031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags); 17752031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how); 17762031cd1aSWeston Andros Adamson 17772031cd1aSWeston Andros Adamson switch (args->state_protect.how) { 17782031cd1aSWeston Andros Adamson case SP4_NONE: 17792031cd1aSWeston Andros Adamson break; 17802031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 17812031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce); 17822031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow); 17832031cd1aSWeston Andros Adamson break; 17842031cd1aSWeston Andros Adamson default: 17852031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 17862031cd1aSWeston Andros Adamson break; 17872031cd1aSWeston Andros Adamson } 1788db8ac8baSWeston Andros Adamson 1789db8ac8baSWeston Andros Adamson if (send_implementation_id && 1790db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1791db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1792d751f748SJim Rees <= sizeof(impl_name) + 1) 1793db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1794db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release, 1795db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine); 1796db8ac8baSWeston Andros Adamson 1797db8ac8baSWeston Andros Adamson if (len > 0) { 17982031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */ 1799db8ac8baSWeston Andros Adamson 1800db8ac8baSWeston Andros Adamson encode_string(xdr, 1801db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1, 1802db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN); 1803db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name); 1804db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */ 1805db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12); 1806db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0); 1807db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0); 1808db8ac8baSWeston Andros Adamson } else 18092031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */ 181099fe60d0SBenny Halevy } 1811fc931582SAndy Adamson 1812fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr, 1813fc931582SAndy Adamson struct nfs41_create_session_args *args, 1814fc931582SAndy Adamson struct compound_hdr *hdr) 1815fc931582SAndy Adamson { 1816fc931582SAndy Adamson __be32 *p; 1817fc931582SAndy Adamson struct nfs_client *clp = args->client; 181889f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient; 1819f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 18208e0d46e1SMike Sager u32 max_resp_sz_cached; 18218e0d46e1SMike Sager 18228e0d46e1SMike Sager /* 18238e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound. 18248e0d46e1SMike Sager * 2 is the verifier. 18258e0d46e1SMike Sager */ 18268e0d46e1SMike Sager max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 18278e0d46e1SMike Sager RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; 1828fc931582SAndy Adamson 1829475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); 183089f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); 183179969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid); 183279969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */ 1833e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */ 1834fc931582SAndy Adamson 1835fc931582SAndy Adamson /* Fore Channel */ 1836c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1837e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */ 1838e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */ 18398e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */ 1840e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */ 1841e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */ 1842e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1843fc931582SAndy Adamson 1844fc931582SAndy Adamson /* Back Channel */ 1845c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */ 1846e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */ 1847e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */ 1848e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */ 1849e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */ 1850e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */ 1851e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */ 1852fc931582SAndy Adamson 1853e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */ 1854e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1); 1855e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */ 1856fc931582SAndy Adamson 1857fc931582SAndy Adamson /* authsys_parms rfc1831 */ 18582f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */ 185989f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); 1860e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */ 1861e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */ 186234558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */ 1863fc931582SAndy Adamson } 18640f3e66c6SAndy Adamson 18650f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr, 18660f3e66c6SAndy Adamson struct nfs4_session *session, 18670f3e66c6SAndy Adamson struct compound_hdr *hdr) 18680f3e66c6SAndy Adamson { 1869475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr); 1870475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 18710f3e66c6SAndy Adamson } 187218019753SRicardo Labiaga 187366245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr, 187466245539STrond Myklebust uint64_t clientid, 187566245539STrond Myklebust struct compound_hdr *hdr) 187666245539STrond Myklebust { 187766245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr); 187866245539STrond Myklebust encode_uint64(xdr, clientid); 187966245539STrond Myklebust } 188066245539STrond Myklebust 188118019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr, 188218019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args, 188318019753SRicardo Labiaga struct compound_hdr *hdr) 188418019753SRicardo Labiaga { 1885475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1886475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs); 188718019753SRicardo Labiaga } 188899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 188999fe60d0SBenny Halevy 18909b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr, 18919b7b9fccSAndy Adamson const struct nfs4_sequence_args *args, 18929b7b9fccSAndy Adamson struct compound_hdr *hdr) 18939b7b9fccSAndy Adamson { 18949b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 18952b2fa717STrond Myklebust struct nfs4_session *session; 1896fc01cea9SAndy Adamson struct nfs4_slot_table *tp; 18972b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot; 1898fc01cea9SAndy Adamson __be32 *p; 18999b7b9fccSAndy Adamson 19002b2fa717STrond Myklebust tp = slot->table; 19012b2fa717STrond Myklebust session = tp->session; 19023bd2384aSChuck Lever if (!session) 19033bd2384aSChuck Lever return; 1904fc01cea9SAndy Adamson 1905475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1906fc01cea9SAndy Adamson 1907fc01cea9SAndy Adamson /* 1908fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this 1909fc01cea9SAndy Adamson */ 1910fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d " 1911fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n", 1912fc01cea9SAndy Adamson __func__, 1913fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0], 1914fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1], 1915fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2], 1916fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3], 19172b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr, 1918fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this); 1919475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 192093f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1921e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr); 19222b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr); 1923e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid); 192434558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this); 19259b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 19269b7b9fccSAndy Adamson } 19279b7b9fccSAndy Adamson 1928b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1 1929b1f69b75SAndy Adamson static void 1930b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr, 1931b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args, 1932b1f69b75SAndy Adamson struct compound_hdr *hdr) 1933b1f69b75SAndy Adamson { 1934b1f69b75SAndy Adamson __be32 *p; 1935b1f69b75SAndy Adamson 1936475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr); 193784c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4); 1938b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1939b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE); 1940b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type); 1941f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */ 194284c9dee3SChristoph Hellwig 194384c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4); 194484c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */ 19454e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types); 1946b1f69b75SAndy Adamson } 1947b1f69b75SAndy Adamson 1948b1f69b75SAndy Adamson static void 1949b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr, 1950b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args, 1951b1f69b75SAndy Adamson struct compound_hdr *hdr) 1952b1f69b75SAndy Adamson { 1953b1f69b75SAndy Adamson __be32 *p; 1954b1f69b75SAndy Adamson 1955475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr); 1956475d4ba0STrond Myklebust p = reserve_space(xdr, 36); 1957b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */ 1958b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type); 1959b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode); 1960b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset); 1961b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length); 1962b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength); 1963ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 1964475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount); 1965b1f69b75SAndy Adamson 1966b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1967b1f69b75SAndy Adamson __func__, 1968b1f69b75SAndy Adamson args->type, 1969b1f69b75SAndy Adamson args->range.iomode, 1970b1f69b75SAndy Adamson (unsigned long)args->range.offset, 1971b1f69b75SAndy Adamson (unsigned long)args->range.length, 1972b1f69b75SAndy Adamson args->maxcount); 1973b1f69b75SAndy Adamson } 1974863a3c6cSAndy Adamson 1975863a3c6cSAndy Adamson static int 1976863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr, 1977ac7db726SBenny Halevy struct inode *inode, 19785f919c9fSChristoph Hellwig struct nfs4_layoutcommit_args *args, 1979863a3c6cSAndy Adamson struct compound_hdr *hdr) 1980863a3c6cSAndy Adamson { 1981863a3c6cSAndy Adamson __be32 *p; 1982863a3c6cSAndy Adamson 1983863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1984863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1985863a3c6cSAndy Adamson 1986475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr); 1987475d4ba0STrond Myklebust p = reserve_space(xdr, 20); 1988863a3c6cSAndy Adamson /* Only whole file layouts */ 1989863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */ 19903557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1991ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */ 1992ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 19932e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) { 1994ea9d23f5STrond Myklebust p = reserve_space(xdr, 20); 1995863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1996863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten); 19972e18d4d8STrond Myklebust } else { 19982e18d4d8STrond Myklebust p = reserve_space(xdr, 12); 19992e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */ 20002e18d4d8STrond Myklebust } 2001863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 2002863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */ 2003ac7db726SBenny Halevy 20045f919c9fSChristoph Hellwig if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) { 2005ac7db726SBenny Halevy NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 2006ac7db726SBenny Halevy NFS_I(inode)->layout, xdr, args); 20075f919c9fSChristoph Hellwig } else { 20085f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len); 20095f919c9fSChristoph Hellwig if (args->layoutupdate_pages) { 20105f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0, 20115f919c9fSChristoph Hellwig args->layoutupdate_len); 20125f919c9fSChristoph Hellwig } 20135f919c9fSChristoph Hellwig } 2014863a3c6cSAndy Adamson 2015863a3c6cSAndy Adamson return 0; 2016863a3c6cSAndy Adamson } 2017cbe82603SBenny Halevy 2018cbe82603SBenny Halevy static void 2019cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr, 2020cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args, 2021cbe82603SBenny Halevy struct compound_hdr *hdr) 2022cbe82603SBenny Halevy { 202394e5c571STrond Myklebust const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld; 2024cbe82603SBenny Halevy __be32 *p; 2025cbe82603SBenny Halevy 2026475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr); 2027475d4ba0STrond Myklebust p = reserve_space(xdr, 16); 2028cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 2029cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type); 203015eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode); 2031cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE); 2032ea9d23f5STrond Myklebust p = reserve_space(xdr, 16); 203315eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset); 203415eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length); 2035cbe82603SBenny Halevy spin_lock(&args->inode->i_lock); 2036ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 2037cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock); 20384d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode) 20394d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private); 20404d796d75STrond Myklebust else if (lr_ops->encode_layoutreturn) 204194e5c571STrond Myklebust lr_ops->encode_layoutreturn(xdr, args); 204294e5c571STrond Myklebust else 2043475d4ba0STrond Myklebust encode_uint32(xdr, 0); 2044cbe82603SBenny Halevy } 2045fca78d6dSBryan Schumaker 2046fca78d6dSBryan Schumaker static int 2047fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr, 2048fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args, 2049fca78d6dSBryan Schumaker struct compound_hdr *hdr) 2050fca78d6dSBryan Schumaker { 2051475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr); 2052475d4ba0STrond Myklebust encode_uint32(xdr, args->style); 2053fca78d6dSBryan Schumaker return 0; 2054fca78d6dSBryan Schumaker } 20557d974794SBryan Schumaker 20567d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr, 20577d974794SBryan Schumaker struct nfs41_test_stateid_args *args, 20587d974794SBryan Schumaker struct compound_hdr *hdr) 20597d974794SBryan Schumaker { 2060475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr); 2061475d4ba0STrond Myklebust encode_uint32(xdr, 1); 2062ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid); 20637d974794SBryan Schumaker } 20649aeda35fSBryan Schumaker 20659aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr, 20669aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args, 20679aeda35fSBryan Schumaker struct compound_hdr *hdr) 20689aeda35fSBryan Schumaker { 2069ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 20707c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid); 20719aeda35fSBryan Schumaker } 2072cf805165STrond Myklebust #else 2073cf805165STrond Myklebust static inline void 2074cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr, 2075cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args, 2076cf805165STrond Myklebust struct compound_hdr *hdr) 2077cf805165STrond Myklebust { 2078cf805165STrond Myklebust } 2079b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 2080b1f69b75SAndy Adamson 20811da177e4SLinus Torvalds /* 20821da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES. 20831da177e4SLinus Torvalds */ 20841da177e4SLinus Torvalds 208566cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 208666cc0429SBenny Halevy { 208766cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1) 20883bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session; 20893bd2384aSChuck Lever if (session) 20903bd2384aSChuck Lever return session->clp->cl_mvops->minor_version; 209166cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 209266cc0429SBenny Halevy return 0; 209366cc0429SBenny Halevy } 209466cc0429SBenny Halevy 20951da177e4SLinus Torvalds /* 20961da177e4SLinus Torvalds * Encode an ACCESS request 20971da177e4SLinus Torvalds */ 20989f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, 20999f06c719SChuck Lever const struct nfs4_accessargs *args) 21001da177e4SLinus Torvalds { 21011da177e4SLinus Torvalds struct compound_hdr hdr = { 210266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21031da177e4SLinus Torvalds }; 21041da177e4SLinus Torvalds 21059f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21069f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21089f06c719SChuck Lever encode_access(xdr, args->access, &hdr); 21099f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2110d017931cSAndy Adamson encode_nops(&hdr); 21111da177e4SLinus Torvalds } 21121da177e4SLinus Torvalds 21131da177e4SLinus Torvalds /* 21141da177e4SLinus Torvalds * Encode LOOKUP request 21151da177e4SLinus Torvalds */ 21169f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, 21179f06c719SChuck Lever const struct nfs4_lookup_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_putfh(xdr, args->dir_fh, &hdr); 21269f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 21279f06c719SChuck Lever encode_getfh(xdr, &hdr); 21289f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2129d017931cSAndy Adamson encode_nops(&hdr); 21301da177e4SLinus Torvalds } 21311da177e4SLinus Torvalds 21321da177e4SLinus Torvalds /* 21331da177e4SLinus Torvalds * Encode LOOKUP_ROOT request 21341da177e4SLinus Torvalds */ 21359f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, 21369f06c719SChuck Lever struct xdr_stream *xdr, 21379f06c719SChuck Lever const struct nfs4_lookup_root_arg *args) 21381da177e4SLinus Torvalds { 21391da177e4SLinus Torvalds struct compound_hdr hdr = { 214066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21411da177e4SLinus Torvalds }; 21421da177e4SLinus Torvalds 21439f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21449f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21459f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 21469f06c719SChuck Lever encode_getfh(xdr, &hdr); 21479f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2148d017931cSAndy Adamson encode_nops(&hdr); 21491da177e4SLinus Torvalds } 21501da177e4SLinus Torvalds 21511da177e4SLinus Torvalds /* 21521da177e4SLinus Torvalds * Encode REMOVE request 21531da177e4SLinus Torvalds */ 21549f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, 21559f06c719SChuck Lever const struct nfs_removeargs *args) 21561da177e4SLinus Torvalds { 21571da177e4SLinus Torvalds struct compound_hdr hdr = { 215866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21591da177e4SLinus Torvalds }; 21601da177e4SLinus Torvalds 21619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 21649f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr); 2165d017931cSAndy Adamson encode_nops(&hdr); 21661da177e4SLinus Torvalds } 21671da177e4SLinus Torvalds 21681da177e4SLinus Torvalds /* 21691da177e4SLinus Torvalds * Encode RENAME request 21701da177e4SLinus Torvalds */ 21719f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, 21729f06c719SChuck Lever const struct nfs_renameargs *args) 21731da177e4SLinus Torvalds { 21741da177e4SLinus Torvalds struct compound_hdr hdr = { 217566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21761da177e4SLinus Torvalds }; 21771da177e4SLinus Torvalds 21789f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21799f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21809f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr); 21819f06c719SChuck Lever encode_savefh(xdr, &hdr); 21829f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr); 21839f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr); 2184d017931cSAndy Adamson encode_nops(&hdr); 21851da177e4SLinus Torvalds } 21861da177e4SLinus Torvalds 21871da177e4SLinus Torvalds /* 21881da177e4SLinus Torvalds * Encode LINK request 21891da177e4SLinus Torvalds */ 21909f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, 21919f06c719SChuck Lever const struct nfs4_link_arg *args) 21921da177e4SLinus Torvalds { 21931da177e4SLinus Torvalds struct compound_hdr hdr = { 219466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 21951da177e4SLinus Torvalds }; 21961da177e4SLinus Torvalds 21979f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 21989f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 21999f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22009f06c719SChuck Lever encode_savefh(xdr, &hdr); 22019f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22029f06c719SChuck Lever encode_link(xdr, args->name, &hdr); 22039f06c719SChuck Lever encode_restorefh(xdr, &hdr); 22049f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2205d017931cSAndy Adamson encode_nops(&hdr); 22061da177e4SLinus Torvalds } 22071da177e4SLinus Torvalds 22081da177e4SLinus Torvalds /* 22091da177e4SLinus Torvalds * Encode CREATE request 22101da177e4SLinus Torvalds */ 22119f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, 22129f06c719SChuck Lever const struct nfs4_create_arg *args) 22131da177e4SLinus Torvalds { 22141da177e4SLinus Torvalds struct compound_hdr hdr = { 221566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22161da177e4SLinus Torvalds }; 22171da177e4SLinus Torvalds 22189f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22199f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22209f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 22219f06c719SChuck Lever encode_create(xdr, args, &hdr); 22229f06c719SChuck Lever encode_getfh(xdr, &hdr); 22239f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2224d017931cSAndy Adamson encode_nops(&hdr); 22251da177e4SLinus Torvalds } 22261da177e4SLinus Torvalds 22271da177e4SLinus Torvalds /* 22281da177e4SLinus Torvalds * Encode SYMLINK request 22291da177e4SLinus Torvalds */ 22309f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, 22319f06c719SChuck Lever const struct nfs4_create_arg *args) 22321da177e4SLinus Torvalds { 22339f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args); 22341da177e4SLinus Torvalds } 22351da177e4SLinus Torvalds 22361da177e4SLinus Torvalds /* 22371da177e4SLinus Torvalds * Encode GETATTR request 22381da177e4SLinus Torvalds */ 22399f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, 22409f06c719SChuck Lever const struct nfs4_getattr_arg *args) 22411da177e4SLinus Torvalds { 22421da177e4SLinus Torvalds struct compound_hdr hdr = { 224366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22441da177e4SLinus Torvalds }; 22451da177e4SLinus Torvalds 22469f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22479f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22489f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22499f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2250d017931cSAndy Adamson encode_nops(&hdr); 22511da177e4SLinus Torvalds } 22521da177e4SLinus Torvalds 22531da177e4SLinus Torvalds /* 22541da177e4SLinus Torvalds * Encode a CLOSE request 22551da177e4SLinus Torvalds */ 22569f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, 22579f06c719SChuck Lever struct nfs_closeargs *args) 22581da177e4SLinus Torvalds { 22591da177e4SLinus Torvalds struct compound_hdr hdr = { 226066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22611da177e4SLinus Torvalds }; 22621da177e4SLinus Torvalds 22639f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22649f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22659f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 2266cf805165STrond Myklebust if (args->lr_args) 2267cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 22689f06c719SChuck Lever encode_close(xdr, args, &hdr); 22693ecefc92STrond Myklebust if (args->bitmask != NULL) 22709f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2271d017931cSAndy Adamson encode_nops(&hdr); 22721da177e4SLinus Torvalds } 22731da177e4SLinus Torvalds 22741da177e4SLinus Torvalds /* 22751da177e4SLinus Torvalds * Encode an OPEN request 22761da177e4SLinus Torvalds */ 22779f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, 22789f06c719SChuck Lever struct nfs_openargs *args) 22791da177e4SLinus Torvalds { 22801da177e4SLinus Torvalds struct compound_hdr hdr = { 228166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 22821da177e4SLinus Torvalds }; 22831da177e4SLinus Torvalds 22849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 22859f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 22869f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 22879f06c719SChuck Lever encode_open(xdr, args, &hdr); 22889f06c719SChuck Lever encode_getfh(xdr, &hdr); 2289ae2bb032SWeston Andros Adamson if (args->access) 22906168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 22911549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2292d017931cSAndy Adamson encode_nops(&hdr); 22931da177e4SLinus Torvalds } 22941da177e4SLinus Torvalds 22951da177e4SLinus Torvalds /* 22961da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request 22971da177e4SLinus Torvalds */ 22989f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, 22999f06c719SChuck Lever struct xdr_stream *xdr, 23009f06c719SChuck Lever struct nfs_open_confirmargs *args) 23011da177e4SLinus Torvalds { 23021da177e4SLinus Torvalds struct compound_hdr hdr = { 2303d017931cSAndy Adamson .nops = 0, 23041da177e4SLinus Torvalds }; 23051da177e4SLinus Torvalds 23069f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23079f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23089f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr); 2309d017931cSAndy Adamson encode_nops(&hdr); 23101da177e4SLinus Torvalds } 23111da177e4SLinus Torvalds 23121da177e4SLinus Torvalds /* 23131da177e4SLinus Torvalds * Encode an OPEN request with no attributes. 23141da177e4SLinus Torvalds */ 23159f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, 23169f06c719SChuck Lever struct xdr_stream *xdr, 23179f06c719SChuck Lever struct nfs_openargs *args) 23181da177e4SLinus Torvalds { 23191da177e4SLinus Torvalds struct compound_hdr hdr = { 232066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23211da177e4SLinus Torvalds }; 23221da177e4SLinus Torvalds 23239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23249f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23259f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23269f06c719SChuck Lever encode_open(xdr, args, &hdr); 2327ae2bb032SWeston Andros Adamson if (args->access) 23286168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr); 2329e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr); 2330d017931cSAndy Adamson encode_nops(&hdr); 23311da177e4SLinus Torvalds } 23321da177e4SLinus Torvalds 23331da177e4SLinus Torvalds /* 23341da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request 23351da177e4SLinus Torvalds */ 23369f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, 23379f06c719SChuck Lever struct xdr_stream *xdr, 23389f06c719SChuck Lever struct nfs_closeargs *args) 23391da177e4SLinus Torvalds { 23401da177e4SLinus Torvalds struct compound_hdr hdr = { 234166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23421da177e4SLinus Torvalds }; 23431da177e4SLinus Torvalds 23449f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23459f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23469f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23479f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr); 2348d017931cSAndy Adamson encode_nops(&hdr); 23491da177e4SLinus Torvalds } 23501da177e4SLinus Torvalds 23511da177e4SLinus Torvalds /* 23521da177e4SLinus Torvalds * Encode a LOCK request 23531da177e4SLinus Torvalds */ 23549f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, 23559f06c719SChuck Lever struct nfs_lock_args *args) 23561da177e4SLinus Torvalds { 23571da177e4SLinus Torvalds struct compound_hdr hdr = { 235866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23591da177e4SLinus Torvalds }; 23601da177e4SLinus Torvalds 23619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23649f06c719SChuck Lever encode_lock(xdr, args, &hdr); 2365d017931cSAndy Adamson encode_nops(&hdr); 23661da177e4SLinus Torvalds } 23671da177e4SLinus Torvalds 23681da177e4SLinus Torvalds /* 23691da177e4SLinus Torvalds * Encode a LOCKT request 23701da177e4SLinus Torvalds */ 23719f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, 23729f06c719SChuck Lever struct nfs_lockt_args *args) 23731da177e4SLinus Torvalds { 23741da177e4SLinus Torvalds struct compound_hdr hdr = { 237566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23761da177e4SLinus Torvalds }; 23771da177e4SLinus Torvalds 23789f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23799f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23809f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23819f06c719SChuck Lever encode_lockt(xdr, args, &hdr); 2382d017931cSAndy Adamson encode_nops(&hdr); 23831da177e4SLinus Torvalds } 23841da177e4SLinus Torvalds 23851da177e4SLinus Torvalds /* 23861da177e4SLinus Torvalds * Encode a LOCKU request 23871da177e4SLinus Torvalds */ 23889f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, 23899f06c719SChuck Lever struct nfs_locku_args *args) 23901da177e4SLinus Torvalds { 23911da177e4SLinus Torvalds struct compound_hdr hdr = { 239266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 23931da177e4SLinus Torvalds }; 23941da177e4SLinus Torvalds 23959f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 23969f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 23979f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 23989f06c719SChuck Lever encode_locku(xdr, args, &hdr); 2399d017931cSAndy Adamson encode_nops(&hdr); 24001da177e4SLinus Torvalds } 24011da177e4SLinus Torvalds 24029f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 24039f06c719SChuck Lever struct xdr_stream *xdr, 24049f06c719SChuck Lever struct nfs_release_lockowner_args *args) 2405d3c7b7ccSTrond Myklebust { 2406d3c7b7ccSTrond Myklebust struct compound_hdr hdr = { 2407d3c7b7ccSTrond Myklebust .minorversion = 0, 2408d3c7b7ccSTrond Myklebust }; 2409d3c7b7ccSTrond Myklebust 24109f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24119f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2412d3c7b7ccSTrond Myklebust encode_nops(&hdr); 2413d3c7b7ccSTrond Myklebust } 2414d3c7b7ccSTrond Myklebust 24151da177e4SLinus Torvalds /* 24161da177e4SLinus Torvalds * Encode a READLINK request 24171da177e4SLinus Torvalds */ 24189f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, 24199f06c719SChuck Lever const struct nfs4_readlink *args) 24201da177e4SLinus Torvalds { 24211da177e4SLinus Torvalds struct compound_hdr hdr = { 242266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24231da177e4SLinus Torvalds }; 24241da177e4SLinus Torvalds 24259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24279f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24289f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr); 2429e3a535e1STrond Myklebust 243028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2431e3a535e1STrond Myklebust args->pgbase, args->pglen); 2432d017931cSAndy Adamson encode_nops(&hdr); 24331da177e4SLinus Torvalds } 24341da177e4SLinus Torvalds 24351da177e4SLinus Torvalds /* 24361da177e4SLinus Torvalds * Encode a READDIR request 24371da177e4SLinus Torvalds */ 24389f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, 24399f06c719SChuck Lever const struct nfs4_readdir_arg *args) 24401da177e4SLinus Torvalds { 24411da177e4SLinus Torvalds struct compound_hdr hdr = { 244266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24431da177e4SLinus Torvalds }; 24441da177e4SLinus Torvalds 24459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24479f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24489f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr); 2449d6ac02dfSTrond Myklebust 245028f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, 2451d6ac02dfSTrond Myklebust args->pgbase, args->count); 2452d6ac02dfSTrond Myklebust dprintk("%s: inlined page args = (%u, %p, %u, %u)\n", 245328f56694SBenny Halevy __func__, hdr.replen << 2, args->pages, 2454d6ac02dfSTrond Myklebust args->pgbase, args->count); 2455d017931cSAndy Adamson encode_nops(&hdr); 24561da177e4SLinus Torvalds } 24571da177e4SLinus Torvalds 24581da177e4SLinus Torvalds /* 24591da177e4SLinus Torvalds * Encode a READ request 24601da177e4SLinus Torvalds */ 24619f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, 24623c6b899cSAnna Schumaker struct nfs_pgio_args *args) 24631da177e4SLinus Torvalds { 24641da177e4SLinus Torvalds struct compound_hdr hdr = { 246566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24661da177e4SLinus Torvalds }; 24671da177e4SLinus Torvalds 24689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24709f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24719f06c719SChuck Lever encode_read(xdr, args, &hdr); 24721da177e4SLinus Torvalds 247328f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 24741da177e4SLinus Torvalds args->pages, args->pgbase, args->count); 24754f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ; 2476d017931cSAndy Adamson encode_nops(&hdr); 24771da177e4SLinus Torvalds } 24781da177e4SLinus Torvalds 24791da177e4SLinus Torvalds /* 24801da177e4SLinus Torvalds * Encode an SETATTR request 24811da177e4SLinus Torvalds */ 24829f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, 24839f06c719SChuck Lever struct nfs_setattrargs *args) 24841da177e4SLinus Torvalds { 24851da177e4SLinus Torvalds struct compound_hdr hdr = { 248666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 24871da177e4SLinus Torvalds }; 24881da177e4SLinus Torvalds 24899f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 24909f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 24919f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 24929f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr); 24939f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2494d017931cSAndy Adamson encode_nops(&hdr); 24951da177e4SLinus Torvalds } 24961da177e4SLinus Torvalds 24971da177e4SLinus Torvalds /* 2498029d105eSJ. Bruce Fields * Encode a GETACL request 2499029d105eSJ. Bruce Fields */ 25009f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, 2501029d105eSJ. Bruce Fields struct nfs_getaclargs *args) 2502029d105eSJ. Bruce Fields { 2503029d105eSJ. Bruce Fields struct compound_hdr hdr = { 250466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2505029d105eSJ. Bruce Fields }; 250628f56694SBenny Halevy uint32_t replen; 2507029d105eSJ. Bruce Fields 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); 2511bf118a34SAndy Adamson replen = hdr.replen + op_decode_hdr_maxsz + 1; 25129f06c719SChuck Lever encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); 2513cf8cdbe5SAndy Adamson 251428f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, 25158fbcf237SAndreas Gruenbacher args->acl_pages, 0, args->acl_len); 2516bf118a34SAndy Adamson 2517d017931cSAndy Adamson encode_nops(&hdr); 2518029d105eSJ. Bruce Fields } 2519029d105eSJ. Bruce Fields 2520029d105eSJ. Bruce Fields /* 25211da177e4SLinus Torvalds * Encode a WRITE request 25221da177e4SLinus Torvalds */ 25239f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, 25243c6b899cSAnna Schumaker struct nfs_pgio_args *args) 25251da177e4SLinus Torvalds { 25261da177e4SLinus Torvalds struct compound_hdr hdr = { 252766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25281da177e4SLinus Torvalds }; 25291da177e4SLinus Torvalds 25309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25329f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25339f06c719SChuck Lever encode_write(xdr, args, &hdr); 25344f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE; 25357ffd1064SFred Isaman if (args->bitmask) 25369f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2537d017931cSAndy Adamson encode_nops(&hdr); 25381da177e4SLinus Torvalds } 25391da177e4SLinus Torvalds 25401da177e4SLinus Torvalds /* 25411da177e4SLinus Torvalds * a COMMIT request 25421da177e4SLinus Torvalds */ 25439f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, 25440b7c0153SFred Isaman struct nfs_commitargs *args) 25451da177e4SLinus Torvalds { 25461da177e4SLinus Torvalds struct compound_hdr hdr = { 254766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25481da177e4SLinus Torvalds }; 25491da177e4SLinus Torvalds 25509f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25519f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25529f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25539f06c719SChuck Lever encode_commit(xdr, args, &hdr); 2554d017931cSAndy Adamson encode_nops(&hdr); 25551da177e4SLinus Torvalds } 25561da177e4SLinus Torvalds 25571da177e4SLinus Torvalds /* 25581da177e4SLinus Torvalds * FSINFO request 25591da177e4SLinus Torvalds */ 25609f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 25619f06c719SChuck Lever struct nfs4_fsinfo_arg *args) 25621da177e4SLinus Torvalds { 25631da177e4SLinus Torvalds struct compound_hdr hdr = { 256466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25651da177e4SLinus Torvalds }; 25661da177e4SLinus Torvalds 25679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25689f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25699f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25709f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr); 2571d017931cSAndy Adamson encode_nops(&hdr); 25721da177e4SLinus Torvalds } 25731da177e4SLinus Torvalds 25741da177e4SLinus Torvalds /* 25751da177e4SLinus Torvalds * a PATHCONF request 25761da177e4SLinus Torvalds */ 25779f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 25789f06c719SChuck Lever const struct nfs4_pathconf_arg *args) 25791da177e4SLinus Torvalds { 25801da177e4SLinus Torvalds struct compound_hdr hdr = { 258166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 25821da177e4SLinus Torvalds }; 25831da177e4SLinus Torvalds 25849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 25859f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 25869f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 25879f06c719SChuck Lever encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], 2588d017931cSAndy Adamson &hdr); 2589d017931cSAndy Adamson encode_nops(&hdr); 25901da177e4SLinus Torvalds } 25911da177e4SLinus Torvalds 25921da177e4SLinus Torvalds /* 25931da177e4SLinus Torvalds * a STATFS request 25941da177e4SLinus Torvalds */ 25959f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 25969f06c719SChuck Lever const struct nfs4_statfs_arg *args) 25971da177e4SLinus Torvalds { 25981da177e4SLinus Torvalds struct compound_hdr hdr = { 259966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26001da177e4SLinus Torvalds }; 26011da177e4SLinus Torvalds 26029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26039f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26049f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 26059f06c719SChuck Lever encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], 2606d017931cSAndy Adamson args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); 2607d017931cSAndy Adamson encode_nops(&hdr); 26081da177e4SLinus Torvalds } 26091da177e4SLinus Torvalds 26101da177e4SLinus Torvalds /* 26111da177e4SLinus Torvalds * GETATTR_BITMAP request 26121da177e4SLinus Torvalds */ 26139f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, 26149f06c719SChuck Lever struct xdr_stream *xdr, 261543652ad5SBenny Halevy struct nfs4_server_caps_arg *args) 26161da177e4SLinus Torvalds { 26178c61282fSKinglong Mee const u32 *bitmask = args->bitmask; 26181da177e4SLinus Torvalds struct compound_hdr hdr = { 261966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26201da177e4SLinus Torvalds }; 26211da177e4SLinus Torvalds 26229f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26239f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26249f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 26258c61282fSKinglong Mee encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr); 2626d017931cSAndy Adamson encode_nops(&hdr); 26271da177e4SLinus Torvalds } 26281da177e4SLinus Torvalds 26291da177e4SLinus Torvalds /* 26301da177e4SLinus Torvalds * a RENEW request 26311da177e4SLinus Torvalds */ 26329f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 26339f06c719SChuck Lever struct nfs_client *clp) 26341da177e4SLinus Torvalds { 26351da177e4SLinus Torvalds struct compound_hdr hdr = { 2636d017931cSAndy Adamson .nops = 0, 26371da177e4SLinus Torvalds }; 26381da177e4SLinus Torvalds 26399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 2640bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr); 2641d017931cSAndy Adamson encode_nops(&hdr); 26421da177e4SLinus Torvalds } 26431da177e4SLinus Torvalds 26441da177e4SLinus Torvalds /* 26451da177e4SLinus Torvalds * a SETCLIENTID request 26461da177e4SLinus Torvalds */ 26479f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, 26489f06c719SChuck Lever struct xdr_stream *xdr, 26499f06c719SChuck Lever struct nfs4_setclientid *sc) 26501da177e4SLinus Torvalds { 26511da177e4SLinus Torvalds struct compound_hdr hdr = { 2652d017931cSAndy Adamson .nops = 0, 26531da177e4SLinus Torvalds }; 26541da177e4SLinus Torvalds 26559f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26569f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr); 2657d017931cSAndy Adamson encode_nops(&hdr); 26581da177e4SLinus Torvalds } 26591da177e4SLinus Torvalds 26601da177e4SLinus Torvalds /* 26611da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request 26621da177e4SLinus Torvalds */ 26639f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, 26649f06c719SChuck Lever struct xdr_stream *xdr, 26659f06c719SChuck Lever struct nfs4_setclientid_res *arg) 26661da177e4SLinus Torvalds { 26671da177e4SLinus Torvalds struct compound_hdr hdr = { 2668d017931cSAndy Adamson .nops = 0, 26691da177e4SLinus Torvalds }; 26701da177e4SLinus Torvalds 26719f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26729f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr); 2673d017931cSAndy Adamson encode_nops(&hdr); 26741da177e4SLinus Torvalds } 26751da177e4SLinus Torvalds 26761da177e4SLinus Torvalds /* 26771da177e4SLinus Torvalds * DELEGRETURN request 26781da177e4SLinus Torvalds */ 26799f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, 26809f06c719SChuck Lever struct xdr_stream *xdr, 26819f06c719SChuck Lever const struct nfs4_delegreturnargs *args) 26821da177e4SLinus Torvalds { 26831da177e4SLinus Torvalds struct compound_hdr hdr = { 268466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 26851da177e4SLinus Torvalds }; 26861da177e4SLinus Torvalds 26879f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 26889f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 26899f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr); 2690586f1c39STrond Myklebust if (args->lr_args) 2691586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr); 26929f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr); 2693e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr); 2694d017931cSAndy Adamson encode_nops(&hdr); 26951da177e4SLinus Torvalds } 26961da177e4SLinus Torvalds 26971da177e4SLinus Torvalds /* 2698683b57b4STrond Myklebust * Encode FS_LOCATIONS request 2699683b57b4STrond Myklebust */ 27009f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, 27019f06c719SChuck Lever struct xdr_stream *xdr, 27029f06c719SChuck Lever struct nfs4_fs_locations_arg *args) 2703683b57b4STrond Myklebust { 2704683b57b4STrond Myklebust struct compound_hdr hdr = { 270566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2706683b57b4STrond Myklebust }; 270728f56694SBenny Halevy uint32_t replen; 2708683b57b4STrond Myklebust 27099f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27109f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 2711b03d735bSChuck Lever if (args->migration) { 2712b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr); 2713b03d735bSChuck Lever replen = hdr.replen; 2714b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2715b03d735bSChuck Lever if (args->renew) 2716b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr); 2717b03d735bSChuck Lever } else { 27189f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr); 27199f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr); 2720b03d735bSChuck Lever replen = hdr.replen; 27219f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr); 2722b03d735bSChuck Lever } 2723cf8cdbe5SAndy Adamson 2724b03d735bSChuck Lever /* Set up reply kvec to capture returned fs_locations array. */ 272528f56694SBenny Halevy xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, 2726683b57b4STrond Myklebust 0, PAGE_SIZE); 2727d017931cSAndy Adamson encode_nops(&hdr); 2728683b57b4STrond Myklebust } 2729683b57b4STrond Myklebust 27305a5ea0d4SBryan Schumaker /* 27315a5ea0d4SBryan Schumaker * Encode SECINFO request 27325a5ea0d4SBryan Schumaker */ 27335a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, 27345a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 27355a5ea0d4SBryan Schumaker struct nfs4_secinfo_arg *args) 27365a5ea0d4SBryan Schumaker { 27375a5ea0d4SBryan Schumaker struct compound_hdr hdr = { 27385a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 27395a5ea0d4SBryan Schumaker }; 27405a5ea0d4SBryan Schumaker 27415a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 27425a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 27435a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr); 27445a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr); 27455a5ea0d4SBryan Schumaker encode_nops(&hdr); 27465a5ea0d4SBryan Schumaker } 27475a5ea0d4SBryan Schumaker 274844c99933SChuck Lever /* 274944c99933SChuck Lever * Encode FSID_PRESENT request 275044c99933SChuck Lever */ 275144c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req, 275244c99933SChuck Lever struct xdr_stream *xdr, 275344c99933SChuck Lever struct nfs4_fsid_present_arg *args) 275444c99933SChuck Lever { 275544c99933SChuck Lever struct compound_hdr hdr = { 275644c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args), 275744c99933SChuck Lever }; 275844c99933SChuck Lever 275944c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr); 276044c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 276144c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr); 276244c99933SChuck Lever encode_getfh(xdr, &hdr); 276344c99933SChuck Lever if (args->renew) 276444c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr); 276544c99933SChuck Lever encode_nops(&hdr); 276644c99933SChuck Lever } 276744c99933SChuck Lever 276899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 276999fe60d0SBenny Halevy /* 27707c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request 27717c44f1aeSWeston Andros Adamson */ 27727c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req, 27737c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 277471a097c6STrond Myklebust struct nfs41_bind_conn_to_session_args *args) 27757c44f1aeSWeston Andros Adamson { 27767c44f1aeSWeston Andros Adamson struct compound_hdr hdr = { 277771a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 27787c44f1aeSWeston Andros Adamson }; 27797c44f1aeSWeston Andros Adamson 27807c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr); 278171a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr); 27827c44f1aeSWeston Andros Adamson encode_nops(&hdr); 27837c44f1aeSWeston Andros Adamson } 27847c44f1aeSWeston Andros Adamson 27857c44f1aeSWeston Andros Adamson /* 278699fe60d0SBenny Halevy * EXCHANGE_ID request 278799fe60d0SBenny Halevy */ 27889f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, 27899f06c719SChuck Lever struct xdr_stream *xdr, 279099fe60d0SBenny Halevy struct nfs41_exchange_id_args *args) 279199fe60d0SBenny Halevy { 279299fe60d0SBenny Halevy struct compound_hdr hdr = { 2793a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 279499fe60d0SBenny Halevy }; 279599fe60d0SBenny Halevy 27969f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 27979f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr); 279899fe60d0SBenny Halevy encode_nops(&hdr); 279999fe60d0SBenny Halevy } 28002050f0ccSAndy Adamson 28012050f0ccSAndy Adamson /* 2802fc931582SAndy Adamson * a CREATE_SESSION request 2803fc931582SAndy Adamson */ 28049f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, 28059f06c719SChuck Lever struct xdr_stream *xdr, 2806fc931582SAndy Adamson struct nfs41_create_session_args *args) 2807fc931582SAndy Adamson { 2808fc931582SAndy Adamson struct compound_hdr hdr = { 2809a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version, 2810fc931582SAndy Adamson }; 2811fc931582SAndy Adamson 28129f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28139f06c719SChuck Lever encode_create_session(xdr, args, &hdr); 2814fc931582SAndy Adamson encode_nops(&hdr); 2815fc931582SAndy Adamson } 2816fc931582SAndy Adamson 2817fc931582SAndy Adamson /* 28180f3e66c6SAndy Adamson * a DESTROY_SESSION request 28190f3e66c6SAndy Adamson */ 28209f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, 28219f06c719SChuck Lever struct xdr_stream *xdr, 28220f3e66c6SAndy Adamson struct nfs4_session *session) 28230f3e66c6SAndy Adamson { 28240f3e66c6SAndy Adamson struct compound_hdr hdr = { 2825a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version, 28260f3e66c6SAndy Adamson }; 28270f3e66c6SAndy Adamson 28289f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28299f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr); 28300f3e66c6SAndy Adamson encode_nops(&hdr); 28310f3e66c6SAndy Adamson } 28320f3e66c6SAndy Adamson 28330f3e66c6SAndy Adamson /* 283466245539STrond Myklebust * a DESTROY_CLIENTID request 283566245539STrond Myklebust */ 283666245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req, 283766245539STrond Myklebust struct xdr_stream *xdr, 283866245539STrond Myklebust struct nfs_client *clp) 283966245539STrond Myklebust { 284066245539STrond Myklebust struct compound_hdr hdr = { 284166245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version, 284266245539STrond Myklebust }; 284366245539STrond Myklebust 284466245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr); 284566245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr); 284666245539STrond Myklebust encode_nops(&hdr); 284766245539STrond Myklebust } 284866245539STrond Myklebust 284966245539STrond Myklebust /* 2850fc01cea9SAndy Adamson * a SEQUENCE request 2851fc01cea9SAndy Adamson */ 28529f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, 2853fc01cea9SAndy Adamson struct nfs4_sequence_args *args) 2854fc01cea9SAndy Adamson { 2855fc01cea9SAndy Adamson struct compound_hdr hdr = { 2856fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args), 2857fc01cea9SAndy Adamson }; 2858fc01cea9SAndy Adamson 28599f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28609f06c719SChuck Lever encode_sequence(xdr, args, &hdr); 2861fc01cea9SAndy Adamson encode_nops(&hdr); 2862fc01cea9SAndy Adamson } 2863fc01cea9SAndy Adamson 2864fc01cea9SAndy Adamson /* 28652050f0ccSAndy Adamson * a GET_LEASE_TIME request 28662050f0ccSAndy Adamson */ 28679f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, 28689f06c719SChuck Lever struct xdr_stream *xdr, 28692050f0ccSAndy Adamson struct nfs4_get_lease_time_args *args) 28702050f0ccSAndy Adamson { 28712050f0ccSAndy Adamson struct compound_hdr hdr = { 28722050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), 28732050f0ccSAndy Adamson }; 2874dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME }; 28752050f0ccSAndy Adamson 28769f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28779f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr); 28789f06c719SChuck Lever encode_putrootfh(xdr, &hdr); 28799f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr); 28802050f0ccSAndy Adamson encode_nops(&hdr); 28812050f0ccSAndy Adamson } 288218019753SRicardo Labiaga 288318019753SRicardo Labiaga /* 288418019753SRicardo Labiaga * a RECLAIM_COMPLETE request 288518019753SRicardo Labiaga */ 28869f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, 28879f06c719SChuck Lever struct xdr_stream *xdr, 288818019753SRicardo Labiaga struct nfs41_reclaim_complete_args *args) 288918019753SRicardo Labiaga { 289018019753SRicardo Labiaga struct compound_hdr hdr = { 289118019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args) 289218019753SRicardo Labiaga }; 289318019753SRicardo Labiaga 28949f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 28959f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 28969f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr); 289718019753SRicardo Labiaga encode_nops(&hdr); 289818019753SRicardo Labiaga } 289918019753SRicardo Labiaga 2900b1f69b75SAndy Adamson /* 2901b1f69b75SAndy Adamson * Encode GETDEVICEINFO request 2902b1f69b75SAndy Adamson */ 29039f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, 29049f06c719SChuck Lever struct xdr_stream *xdr, 2905b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_args *args) 2906b1f69b75SAndy Adamson { 2907b1f69b75SAndy Adamson struct compound_hdr hdr = { 2908b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2909b1f69b75SAndy Adamson }; 2910b1f69b75SAndy Adamson 29119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29139f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr); 2914b1f69b75SAndy Adamson 2915b1f69b75SAndy Adamson /* set up reply kvec. Subtract notification bitmap max size (2) 2916b1f69b75SAndy Adamson * so that notification bitmap is put in xdr_buf tail */ 2917b1f69b75SAndy Adamson xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2, 2918b1f69b75SAndy Adamson args->pdev->pages, args->pdev->pgbase, 2919b1f69b75SAndy Adamson args->pdev->pglen); 2920b1f69b75SAndy Adamson 2921b1f69b75SAndy Adamson encode_nops(&hdr); 2922b1f69b75SAndy Adamson } 2923b1f69b75SAndy Adamson 2924b1f69b75SAndy Adamson /* 2925b1f69b75SAndy Adamson * Encode LAYOUTGET request 2926b1f69b75SAndy Adamson */ 29279f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, 29289f06c719SChuck Lever struct xdr_stream *xdr, 2929b1f69b75SAndy Adamson struct nfs4_layoutget_args *args) 2930b1f69b75SAndy Adamson { 2931b1f69b75SAndy Adamson struct compound_hdr hdr = { 2932b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2933b1f69b75SAndy Adamson }; 2934b1f69b75SAndy Adamson 29359f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 29369f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 29379f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr); 29389f06c719SChuck Lever encode_layoutget(xdr, args, &hdr); 293935124a09SWeston Andros Adamson 294035124a09SWeston Andros Adamson xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, 294135124a09SWeston Andros Adamson args->layout.pages, 0, args->layout.pglen); 294235124a09SWeston Andros Adamson 2943b1f69b75SAndy Adamson encode_nops(&hdr); 2944b1f69b75SAndy Adamson } 2945863a3c6cSAndy Adamson 2946863a3c6cSAndy Adamson /* 2947863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request 2948863a3c6cSAndy Adamson */ 2949cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req, 2950863a3c6cSAndy Adamson struct xdr_stream *xdr, 2951863a3c6cSAndy Adamson struct nfs4_layoutcommit_args *args) 2952863a3c6cSAndy Adamson { 2953ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data = 2954ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args); 2955863a3c6cSAndy Adamson struct compound_hdr hdr = { 2956863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2957863a3c6cSAndy Adamson }; 2958863a3c6cSAndy Adamson 2959863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr); 2960863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr); 2961863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2962ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr); 2963863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr); 2964863a3c6cSAndy Adamson encode_nops(&hdr); 2965cbe82603SBenny Halevy } 2966cbe82603SBenny Halevy 2967cbe82603SBenny Halevy /* 2968cbe82603SBenny Halevy * Encode LAYOUTRETURN request 2969cbe82603SBenny Halevy */ 2970cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req, 2971cbe82603SBenny Halevy struct xdr_stream *xdr, 2972cbe82603SBenny Halevy struct nfs4_layoutreturn_args *args) 2973cbe82603SBenny Halevy { 2974cbe82603SBenny Halevy struct compound_hdr hdr = { 2975cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2976cbe82603SBenny Halevy }; 2977cbe82603SBenny Halevy 2978cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr); 2979cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr); 2980cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr); 2981cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr); 2982cbe82603SBenny Halevy encode_nops(&hdr); 2983863a3c6cSAndy Adamson } 2984fca78d6dSBryan Schumaker 2985fca78d6dSBryan Schumaker /* 2986fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request 2987fca78d6dSBryan Schumaker */ 2988fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req, 2989fca78d6dSBryan Schumaker struct xdr_stream *xdr, 2990fca78d6dSBryan Schumaker struct nfs41_secinfo_no_name_args *args) 2991fca78d6dSBryan Schumaker { 2992fca78d6dSBryan Schumaker struct compound_hdr hdr = { 2993fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 2994fca78d6dSBryan Schumaker }; 2995fca78d6dSBryan Schumaker 2996fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 2997fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 2998fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr); 2999fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr); 3000fca78d6dSBryan Schumaker encode_nops(&hdr); 3001fca78d6dSBryan Schumaker return 0; 3002fca78d6dSBryan Schumaker } 30037d974794SBryan Schumaker 30047d974794SBryan Schumaker /* 30057d974794SBryan Schumaker * Encode TEST_STATEID request 30067d974794SBryan Schumaker */ 30077d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req, 30087d974794SBryan Schumaker struct xdr_stream *xdr, 30097d974794SBryan Schumaker struct nfs41_test_stateid_args *args) 30107d974794SBryan Schumaker { 30117d974794SBryan Schumaker struct compound_hdr hdr = { 30127d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30137d974794SBryan Schumaker }; 30147d974794SBryan Schumaker 30157d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30167d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30177d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr); 30187d974794SBryan Schumaker encode_nops(&hdr); 30197d974794SBryan Schumaker } 30209aeda35fSBryan Schumaker 30219aeda35fSBryan Schumaker /* 30229aeda35fSBryan Schumaker * Encode FREE_STATEID request 30239aeda35fSBryan Schumaker */ 30249aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req, 30259aeda35fSBryan Schumaker struct xdr_stream *xdr, 30269aeda35fSBryan Schumaker struct nfs41_free_stateid_args *args) 30279aeda35fSBryan Schumaker { 30289aeda35fSBryan Schumaker struct compound_hdr hdr = { 30299aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args), 30309aeda35fSBryan Schumaker }; 30319aeda35fSBryan Schumaker 30329aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr); 30339aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr); 30349aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr); 30359aeda35fSBryan Schumaker encode_nops(&hdr); 30369aeda35fSBryan Schumaker } 303799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 303899fe60d0SBenny Halevy 3039686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 3040686841b3SBenny Halevy { 3041686841b3SBenny Halevy dprintk("nfs: %s: prematurely hit end of receive buffer. " 3042686841b3SBenny Halevy "Remaining buffer length is %tu words.\n", 3043686841b3SBenny Halevy func, xdr->end - xdr->p); 3044686841b3SBenny Halevy } 30451da177e4SLinus Torvalds 3046683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 30471da177e4SLinus Torvalds { 30488687b63aSAl Viro __be32 *p; 30491da177e4SLinus Torvalds 3050c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3051c0eae66eSBenny Halevy if (unlikely(!p)) 3052c0eae66eSBenny Halevy goto out_overflow; 3053cccddf4fSBenny Halevy *len = be32_to_cpup(p); 3054c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, *len); 3055c0eae66eSBenny Halevy if (unlikely(!p)) 3056c0eae66eSBenny Halevy goto out_overflow; 30571da177e4SLinus Torvalds *string = (char *)p; 30581da177e4SLinus Torvalds return 0; 3059c0eae66eSBenny Halevy out_overflow: 3060c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3061c0eae66eSBenny Halevy return -EIO; 30621da177e4SLinus Torvalds } 30631da177e4SLinus Torvalds 30641da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) 30651da177e4SLinus Torvalds { 30668687b63aSAl Viro __be32 *p; 30671da177e4SLinus Torvalds 3068c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3069c0eae66eSBenny Halevy if (unlikely(!p)) 3070c0eae66eSBenny Halevy goto out_overflow; 30716f723f77SBenny Halevy hdr->status = be32_to_cpup(p++); 3072cccddf4fSBenny Halevy hdr->taglen = be32_to_cpup(p); 30731da177e4SLinus Torvalds 3074c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, hdr->taglen + 4); 3075c0eae66eSBenny Halevy if (unlikely(!p)) 3076c0eae66eSBenny Halevy goto out_overflow; 30771da177e4SLinus Torvalds hdr->tag = (char *)p; 30781da177e4SLinus Torvalds p += XDR_QUADLEN(hdr->taglen); 3079cccddf4fSBenny Halevy hdr->nops = be32_to_cpup(p); 3080aadf6152SBenny Halevy if (unlikely(hdr->nops < 1)) 3081aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status); 30821da177e4SLinus Torvalds return 0; 3083c0eae66eSBenny Halevy out_overflow: 3084c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3085c0eae66eSBenny Halevy return -EIO; 30861da177e4SLinus Torvalds } 30871da177e4SLinus Torvalds 3088c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected, 3089c7848f69STrond Myklebust int *nfs_retval) 30901da177e4SLinus Torvalds { 30918687b63aSAl Viro __be32 *p; 30921da177e4SLinus Torvalds uint32_t opnum; 30931da177e4SLinus Torvalds int32_t nfserr; 30941da177e4SLinus Torvalds 3095c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3096c0eae66eSBenny Halevy if (unlikely(!p)) 3097c0eae66eSBenny Halevy goto out_overflow; 30986f723f77SBenny Halevy opnum = be32_to_cpup(p++); 3099c7848f69STrond Myklebust if (unlikely(opnum != expected)) 3100c7848f69STrond Myklebust goto out_bad_operation; 3101c7848f69STrond Myklebust nfserr = be32_to_cpup(p); 3102c7848f69STrond Myklebust if (nfserr == NFS_OK) 3103c7848f69STrond Myklebust *nfs_retval = 0; 3104c7848f69STrond Myklebust else 3105c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr); 3106c7848f69STrond Myklebust return true; 3107c7848f69STrond Myklebust out_bad_operation: 3108fe82a183SChuck Lever dprintk("nfs: Server returned operation" 31091da177e4SLinus Torvalds " %d but we issued a request for %d\n", 31101da177e4SLinus Torvalds opnum, expected); 3111c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO; 3112c7848f69STrond Myklebust return false; 3113c0eae66eSBenny Halevy out_overflow: 3114c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3115c7848f69STrond Myklebust *nfs_retval = -EIO; 3116c7848f69STrond Myklebust return false; 3117c7848f69STrond Myklebust } 3118c7848f69STrond Myklebust 3119c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3120c7848f69STrond Myklebust { 3121c7848f69STrond Myklebust int retval; 3122c7848f69STrond Myklebust 3123c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval); 3124c7848f69STrond Myklebust return retval; 31251da177e4SLinus Torvalds } 31261da177e4SLinus Torvalds 31271da177e4SLinus Torvalds /* Dummy routine */ 3128adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp) 31291da177e4SLinus Torvalds { 31308687b63aSAl Viro __be32 *p; 3131683b57b4STrond Myklebust unsigned int strlen; 31321da177e4SLinus Torvalds char *str; 31331da177e4SLinus Torvalds 3134c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 3135c0eae66eSBenny Halevy if (likely(p)) 31361da177e4SLinus Torvalds return decode_opaque_inline(xdr, &strlen, &str); 3137c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3138c0eae66eSBenny Halevy return -EIO; 31391da177e4SLinus Torvalds } 31401da177e4SLinus Torvalds 31411da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) 31421da177e4SLinus Torvalds { 31438687b63aSAl Viro uint32_t bmlen; 31448687b63aSAl Viro __be32 *p; 31451da177e4SLinus Torvalds 3146c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3147c0eae66eSBenny Halevy if (unlikely(!p)) 3148c0eae66eSBenny Halevy goto out_overflow; 3149cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 31501da177e4SLinus Torvalds 3151dae100c2SFred Isaman bitmap[0] = bitmap[1] = bitmap[2] = 0; 3152c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, (bmlen << 2)); 3153c0eae66eSBenny Halevy if (unlikely(!p)) 3154c0eae66eSBenny Halevy goto out_overflow; 31551da177e4SLinus Torvalds if (bmlen > 0) { 31566f723f77SBenny Halevy bitmap[0] = be32_to_cpup(p++); 3157dae100c2SFred Isaman if (bmlen > 1) { 3158dae100c2SFred Isaman bitmap[1] = be32_to_cpup(p++); 3159dae100c2SFred Isaman if (bmlen > 2) 3160dae100c2SFred Isaman bitmap[2] = be32_to_cpup(p); 3161dae100c2SFred Isaman } 31621da177e4SLinus Torvalds } 31631da177e4SLinus Torvalds return 0; 3164c0eae66eSBenny Halevy out_overflow: 3165c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3166c0eae66eSBenny Halevy return -EIO; 31671da177e4SLinus Torvalds } 31681da177e4SLinus Torvalds 3169256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep) 31701da177e4SLinus Torvalds { 31718687b63aSAl Viro __be32 *p; 31721da177e4SLinus Torvalds 3173c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3174c0eae66eSBenny Halevy if (unlikely(!p)) 3175c0eae66eSBenny Halevy goto out_overflow; 3176cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p); 3177256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr); 31781da177e4SLinus Torvalds return 0; 3179c0eae66eSBenny Halevy out_overflow: 3180c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3181c0eae66eSBenny Halevy return -EIO; 31821da177e4SLinus Torvalds } 31831da177e4SLinus Torvalds 31841da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask) 31851da177e4SLinus Torvalds { 31861da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) { 31873388bff5SRoman Borisov int ret; 31883388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask); 31893388bff5SRoman Borisov if (unlikely(ret < 0)) 31903388bff5SRoman Borisov return ret; 31911da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 31921da177e4SLinus Torvalds } else 3193dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0; 3194dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 3195dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]); 31961da177e4SLinus Torvalds return 0; 31971da177e4SLinus Torvalds } 31981da177e4SLinus Torvalds 31991da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type) 32001da177e4SLinus Torvalds { 32018687b63aSAl Viro __be32 *p; 3202409924e4STrond Myklebust int ret = 0; 32031da177e4SLinus Torvalds 32041da177e4SLinus Torvalds *type = 0; 32051da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U))) 32061da177e4SLinus Torvalds return -EIO; 32071da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) { 3208c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3209c0eae66eSBenny Halevy if (unlikely(!p)) 3210c0eae66eSBenny Halevy goto out_overflow; 3211cccddf4fSBenny Halevy *type = be32_to_cpup(p); 32121da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) { 32133110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type); 32141da177e4SLinus Torvalds return -EIO; 32151da177e4SLinus Torvalds } 32161da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE; 3217409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE; 32181da177e4SLinus Torvalds } 3219bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]); 3220409924e4STrond Myklebust return ret; 3221c0eae66eSBenny Halevy out_overflow: 3222c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3223c0eae66eSBenny Halevy return -EIO; 32241da177e4SLinus Torvalds } 32251da177e4SLinus Torvalds 3226264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr, 3227264e6351SChuck Lever uint32_t *bitmap, uint32_t *type) 3228264e6351SChuck Lever { 3229264e6351SChuck Lever __be32 *p; 3230264e6351SChuck Lever 3231264e6351SChuck Lever *type = 0; 3232264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U))) 3233264e6351SChuck Lever return -EIO; 3234264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) { 3235264e6351SChuck Lever p = xdr_inline_decode(xdr, 4); 3236264e6351SChuck Lever if (unlikely(!p)) 3237264e6351SChuck Lever goto out_overflow; 3238264e6351SChuck Lever *type = be32_to_cpup(p); 3239264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE; 3240264e6351SChuck Lever } 3241264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type); 3242264e6351SChuck Lever return 0; 3243264e6351SChuck Lever out_overflow: 3244264e6351SChuck Lever print_overflow_msg(__func__, xdr); 3245264e6351SChuck Lever return -EIO; 3246264e6351SChuck Lever } 3247264e6351SChuck Lever 32481da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 32491da177e4SLinus Torvalds { 32508687b63aSAl Viro __be32 *p; 3251409924e4STrond Myklebust int ret = 0; 32521da177e4SLinus Torvalds 32531da177e4SLinus Torvalds *change = 0; 32541da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U))) 32551da177e4SLinus Torvalds return -EIO; 32561da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) { 3257c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3258c0eae66eSBenny Halevy if (unlikely(!p)) 3259c0eae66eSBenny Halevy goto out_overflow; 3260cccddf4fSBenny Halevy xdr_decode_hyper(p, change); 32611da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE; 3262409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE; 32631da177e4SLinus Torvalds } 32643110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__, 32651da177e4SLinus Torvalds (unsigned long long)*change); 3266409924e4STrond Myklebust return ret; 3267c0eae66eSBenny Halevy out_overflow: 3268c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3269c0eae66eSBenny Halevy return -EIO; 32701da177e4SLinus Torvalds } 32711da177e4SLinus Torvalds 32721da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size) 32731da177e4SLinus Torvalds { 32748687b63aSAl Viro __be32 *p; 3275409924e4STrond Myklebust int ret = 0; 32761da177e4SLinus Torvalds 32771da177e4SLinus Torvalds *size = 0; 32781da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U))) 32791da177e4SLinus Torvalds return -EIO; 32801da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) { 3281c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3282c0eae66eSBenny Halevy if (unlikely(!p)) 3283c0eae66eSBenny Halevy goto out_overflow; 3284cccddf4fSBenny Halevy xdr_decode_hyper(p, size); 32851da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE; 3286409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE; 32871da177e4SLinus Torvalds } 32883110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size); 3289409924e4STrond Myklebust return ret; 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_link_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_LINK_SUPPORT - 1U))) 33011da177e4SLinus Torvalds return -EIO; 33021da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_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_LINK_SUPPORT; 33081da177e4SLinus Torvalds } 33093110ff80SHarvey Harrison dprintk("%s: link 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 33161da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33171da177e4SLinus Torvalds { 33188687b63aSAl Viro __be32 *p; 33191da177e4SLinus Torvalds 33201da177e4SLinus Torvalds *res = 0; 33211da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U))) 33221da177e4SLinus Torvalds return -EIO; 33231da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) { 3324c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3325c0eae66eSBenny Halevy if (unlikely(!p)) 3326c0eae66eSBenny Halevy goto out_overflow; 3327cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33281da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT; 33291da177e4SLinus Torvalds } 33303110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true"); 33311da177e4SLinus Torvalds return 0; 3332c0eae66eSBenny Halevy out_overflow: 3333c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3334c0eae66eSBenny Halevy return -EIO; 33351da177e4SLinus Torvalds } 33361da177e4SLinus Torvalds 33378b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid) 33381da177e4SLinus Torvalds { 33398687b63aSAl Viro __be32 *p; 3340409924e4STrond Myklebust int ret = 0; 33411da177e4SLinus Torvalds 33421da177e4SLinus Torvalds fsid->major = 0; 33431da177e4SLinus Torvalds fsid->minor = 0; 33441da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U))) 33451da177e4SLinus Torvalds return -EIO; 33461da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) { 3347c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16); 3348c0eae66eSBenny Halevy if (unlikely(!p)) 3349c0eae66eSBenny Halevy goto out_overflow; 33503ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major); 3351cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor); 33521da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID; 3353409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID; 33541da177e4SLinus Torvalds } 33553110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__, 33561da177e4SLinus Torvalds (unsigned long long)fsid->major, 33571da177e4SLinus Torvalds (unsigned long long)fsid->minor); 3358409924e4STrond Myklebust return ret; 3359c0eae66eSBenny Halevy out_overflow: 3360c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3361c0eae66eSBenny Halevy return -EIO; 33621da177e4SLinus Torvalds } 33631da177e4SLinus Torvalds 33641da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 33651da177e4SLinus Torvalds { 33668687b63aSAl Viro __be32 *p; 33671da177e4SLinus Torvalds 33681da177e4SLinus Torvalds *res = 60; 33691da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U))) 33701da177e4SLinus Torvalds return -EIO; 33711da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) { 3372c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3373c0eae66eSBenny Halevy if (unlikely(!p)) 3374c0eae66eSBenny Halevy goto out_overflow; 3375cccddf4fSBenny Halevy *res = be32_to_cpup(p); 33761da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME; 33771da177e4SLinus Torvalds } 33783110ff80SHarvey Harrison dprintk("%s: file size=%u\n", __func__, (unsigned int)*res); 33791da177e4SLinus Torvalds return 0; 3380c0eae66eSBenny Halevy out_overflow: 3381c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3382c0eae66eSBenny Halevy return -EIO; 33831da177e4SLinus Torvalds } 33841da177e4SLinus Torvalds 3385ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res) 3386ae42c70aSBryan Schumaker { 3387ae42c70aSBryan Schumaker __be32 *p; 3388ae42c70aSBryan Schumaker 3389ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U))) 3390ae42c70aSBryan Schumaker return -EIO; 3391ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) { 3392ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3393ae42c70aSBryan Schumaker if (unlikely(!p)) 3394ae42c70aSBryan Schumaker goto out_overflow; 3395ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR; 3396ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p); 3397ae42c70aSBryan Schumaker } 3398ae42c70aSBryan Schumaker return 0; 3399ae42c70aSBryan Schumaker out_overflow: 3400ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3401ae42c70aSBryan Schumaker return -EIO; 3402ae42c70aSBryan Schumaker } 3403ae42c70aSBryan Schumaker 34048c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr, 34058c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask) 34068c61282fSKinglong Mee { 34078c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) { 34088c61282fSKinglong Mee int ret; 34098c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask); 34108c61282fSKinglong Mee if (unlikely(ret < 0)) 34118c61282fSKinglong Mee return ret; 34128c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT; 34138c61282fSKinglong Mee } else 34148c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0; 34158c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__, 34168c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]); 34178c61282fSKinglong Mee return 0; 34188c61282fSKinglong Mee } 34198c61282fSKinglong Mee 3420ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh) 3421ae42c70aSBryan Schumaker { 3422ae42c70aSBryan Schumaker __be32 *p; 3423ae42c70aSBryan Schumaker int len; 3424ae42c70aSBryan Schumaker 34257ad07353STrond Myklebust if (fh != NULL) 3426ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh)); 3427ae42c70aSBryan Schumaker 3428ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U))) 3429ae42c70aSBryan Schumaker return -EIO; 3430ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) { 3431ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4); 3432ae42c70aSBryan Schumaker if (unlikely(!p)) 3433ae42c70aSBryan Schumaker goto out_overflow; 3434ae42c70aSBryan Schumaker len = be32_to_cpup(p); 3435ae42c70aSBryan Schumaker if (len > NFS4_FHSIZE) 3436ae42c70aSBryan Schumaker return -EIO; 3437ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len); 3438ae42c70aSBryan Schumaker if (unlikely(!p)) 3439ae42c70aSBryan Schumaker goto out_overflow; 34407ad07353STrond Myklebust if (fh != NULL) { 3441ae42c70aSBryan Schumaker memcpy(fh->data, p, len); 34427ad07353STrond Myklebust fh->size = len; 34437ad07353STrond Myklebust } 3444ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE; 3445ae42c70aSBryan Schumaker } 3446ae42c70aSBryan Schumaker return 0; 3447ae42c70aSBryan Schumaker out_overflow: 3448ae42c70aSBryan Schumaker print_overflow_msg(__func__, xdr); 3449ae42c70aSBryan Schumaker return -EIO; 3450ae42c70aSBryan Schumaker } 3451ae42c70aSBryan Schumaker 34521da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 34531da177e4SLinus Torvalds { 34548687b63aSAl Viro __be32 *p; 34551da177e4SLinus Torvalds 3456a1800acaSMalahal Naineni *res = 0; 34571da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U))) 34581da177e4SLinus Torvalds return -EIO; 34591da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) { 3460c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3461c0eae66eSBenny Halevy if (unlikely(!p)) 3462c0eae66eSBenny Halevy goto out_overflow; 3463cccddf4fSBenny Halevy *res = be32_to_cpup(p); 34641da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT; 34651da177e4SLinus Torvalds } 34663110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res); 34671da177e4SLinus Torvalds return 0; 3468c0eae66eSBenny Halevy out_overflow: 3469c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3470c0eae66eSBenny Halevy return -EIO; 34711da177e4SLinus Torvalds } 34721da177e4SLinus Torvalds 34731da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 34741da177e4SLinus Torvalds { 34758687b63aSAl Viro __be32 *p; 3476409924e4STrond Myklebust int ret = 0; 34771da177e4SLinus Torvalds 34781da177e4SLinus Torvalds *fileid = 0; 34791da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U))) 34801da177e4SLinus Torvalds return -EIO; 34811da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) { 3482c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3483c0eae66eSBenny Halevy if (unlikely(!p)) 3484c0eae66eSBenny Halevy goto out_overflow; 3485cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 34861da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID; 3487409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID; 34881da177e4SLinus Torvalds } 34893110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3490409924e4STrond Myklebust return ret; 3491c0eae66eSBenny Halevy out_overflow: 3492c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3493c0eae66eSBenny Halevy return -EIO; 34941da177e4SLinus Torvalds } 34951da177e4SLinus Torvalds 349699baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid) 349799baf625SManoj Naik { 34988687b63aSAl Viro __be32 *p; 3499409924e4STrond Myklebust int ret = 0; 350099baf625SManoj Naik 350199baf625SManoj Naik *fileid = 0; 350299baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U))) 350399baf625SManoj Naik return -EIO; 350499baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) { 3505c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3506c0eae66eSBenny Halevy if (unlikely(!p)) 3507c0eae66eSBenny Halevy goto out_overflow; 3508cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid); 350999baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 351028331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID; 351199baf625SManoj Naik } 35123110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid); 3513409924e4STrond Myklebust return ret; 3514c0eae66eSBenny Halevy out_overflow: 3515c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3516c0eae66eSBenny Halevy return -EIO; 351799baf625SManoj Naik } 351899baf625SManoj Naik 35191da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35201da177e4SLinus Torvalds { 35218687b63aSAl Viro __be32 *p; 35221da177e4SLinus Torvalds int status = 0; 35231da177e4SLinus Torvalds 35241da177e4SLinus Torvalds *res = 0; 35251da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U))) 35261da177e4SLinus Torvalds return -EIO; 35271da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) { 3528c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3529c0eae66eSBenny Halevy if (unlikely(!p)) 3530c0eae66eSBenny Halevy goto out_overflow; 3531cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35321da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL; 35331da177e4SLinus Torvalds } 35343110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res); 35351da177e4SLinus Torvalds return status; 3536c0eae66eSBenny Halevy out_overflow: 3537c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3538c0eae66eSBenny Halevy return -EIO; 35391da177e4SLinus Torvalds } 35401da177e4SLinus Torvalds 35411da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35421da177e4SLinus Torvalds { 35438687b63aSAl Viro __be32 *p; 35441da177e4SLinus Torvalds int status = 0; 35451da177e4SLinus Torvalds 35461da177e4SLinus Torvalds *res = 0; 35471da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U))) 35481da177e4SLinus Torvalds return -EIO; 35491da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) { 3550c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3551c0eae66eSBenny Halevy if (unlikely(!p)) 3552c0eae66eSBenny Halevy goto out_overflow; 3553cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35541da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE; 35551da177e4SLinus Torvalds } 35563110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res); 35571da177e4SLinus Torvalds return status; 3558c0eae66eSBenny Halevy out_overflow: 3559c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3560c0eae66eSBenny Halevy return -EIO; 35611da177e4SLinus Torvalds } 35621da177e4SLinus Torvalds 35631da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 35641da177e4SLinus Torvalds { 35658687b63aSAl Viro __be32 *p; 35661da177e4SLinus Torvalds int status = 0; 35671da177e4SLinus Torvalds 35681da177e4SLinus Torvalds *res = 0; 35691da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U))) 35701da177e4SLinus Torvalds return -EIO; 35711da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) { 3572c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3573c0eae66eSBenny Halevy if (unlikely(!p)) 3574c0eae66eSBenny Halevy goto out_overflow; 3575cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 35761da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL; 35771da177e4SLinus Torvalds } 35783110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res); 35791da177e4SLinus Torvalds return status; 3580c0eae66eSBenny Halevy out_overflow: 3581c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3582c0eae66eSBenny Halevy return -EIO; 35831da177e4SLinus Torvalds } 35841da177e4SLinus Torvalds 35857aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path) 35867aaa0b3bSManoj Naik { 3587464ad6b1SChuck Lever u32 n; 35888687b63aSAl Viro __be32 *p; 35897aaa0b3bSManoj Naik int status = 0; 35907aaa0b3bSManoj Naik 3591c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3592c0eae66eSBenny Halevy if (unlikely(!p)) 3593c0eae66eSBenny Halevy goto out_overflow; 3594cccddf4fSBenny Halevy n = be32_to_cpup(p); 359533a43f28SAndy Adamson if (n == 0) 359633a43f28SAndy Adamson goto root_path; 359702a2976cSChuck Lever dprintk("pathname4: "); 3598809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) { 3599809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n); 3600809b426cSTrond Myklebust goto out_eio; 3601809b426cSTrond Myklebust } 3602809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) { 36037aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents]; 36047aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data); 36057aaa0b3bSManoj Naik if (unlikely(status != 0)) 36067aaa0b3bSManoj Naik goto out_eio; 360795a13f7bSTrond Myklebust ifdebug (XDR) 360802a2976cSChuck Lever pr_cont("%s%.*s ", 360902a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""), 361002a2976cSChuck Lever component->len, component->data); 36117aaa0b3bSManoj Naik } 36127aaa0b3bSManoj Naik out: 36137aaa0b3bSManoj Naik return status; 361433a43f28SAndy Adamson root_path: 361533a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */ 361633a43f28SAndy Adamson path->ncomponents = 1; 361733a43f28SAndy Adamson path->components[0].len=0; 361833a43f28SAndy Adamson path->components[0].data=NULL; 361902a2976cSChuck Lever dprintk("pathname4: /\n"); 362033a43f28SAndy Adamson goto out; 36217aaa0b3bSManoj Naik out_eio: 36227aaa0b3bSManoj Naik dprintk(" status %d", status); 36237aaa0b3bSManoj Naik status = -EIO; 36247aaa0b3bSManoj Naik goto out; 3625c0eae66eSBenny Halevy out_overflow: 3626c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3627c0eae66eSBenny Halevy return -EIO; 36287aaa0b3bSManoj Naik } 36297aaa0b3bSManoj Naik 36307aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res) 3631683b57b4STrond Myklebust { 3632683b57b4STrond Myklebust int n; 36338687b63aSAl Viro __be32 *p; 3634683b57b4STrond Myklebust int status = -EIO; 3635683b57b4STrond Myklebust 3636683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U))) 3637683b57b4STrond Myklebust goto out; 3638683b57b4STrond Myklebust status = 0; 3639683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3640683b57b4STrond Myklebust goto out; 3641f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS; 36428b7e3f49STrond Myklebust status = -EIO; 36438b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */ 36448b7e3f49STrond Myklebust if (unlikely(res == NULL)) 36458b7e3f49STrond Myklebust goto out; 364602a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__); 36477aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path); 3648683b57b4STrond Myklebust if (unlikely(status != 0)) 3649683b57b4STrond Myklebust goto out; 3650c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3651c0eae66eSBenny Halevy if (unlikely(!p)) 3652c0eae66eSBenny Halevy goto out_overflow; 3653cccddf4fSBenny Halevy n = be32_to_cpup(p); 3654683b57b4STrond Myklebust if (n <= 0) 3655683b57b4STrond Myklebust goto out_eio; 3656809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) { 3657464ad6b1SChuck Lever u32 m; 3658809b426cSTrond Myklebust struct nfs4_fs_location *loc; 3659683b57b4STrond Myklebust 3660809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES) 3661809b426cSTrond Myklebust break; 3662809b426cSTrond Myklebust loc = &res->locations[res->nlocations]; 3663c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3664c0eae66eSBenny Halevy if (unlikely(!p)) 3665c0eae66eSBenny Halevy goto out_overflow; 3666cccddf4fSBenny Halevy m = be32_to_cpup(p); 36677aaa0b3bSManoj Naik 366802a2976cSChuck Lever dprintk("%s: servers:\n", __func__); 3669809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) { 3670809b426cSTrond Myklebust struct nfs4_string *server; 3671809b426cSTrond Myklebust 3672809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) { 3673464ad6b1SChuck Lever unsigned int i; 3674464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers " 3675464ad6b1SChuck Lever "returned for location %u\n", 36763110ff80SHarvey Harrison __func__, 3677464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS, 3678464ad6b1SChuck Lever m, res->nlocations); 36797aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) { 36802e42c3e2STrond Myklebust unsigned int len; 36817aaa0b3bSManoj Naik char *data; 36827aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data); 3683683b57b4STrond Myklebust if (unlikely(status != 0)) 3684683b57b4STrond Myklebust goto out_eio; 36857aaa0b3bSManoj Naik } 3686809b426cSTrond Myklebust break; 36877aaa0b3bSManoj Naik } 3688809b426cSTrond Myklebust server = &loc->servers[loc->nservers]; 3689809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data); 3690809b426cSTrond Myklebust if (unlikely(status != 0)) 3691809b426cSTrond Myklebust goto out_eio; 3692809b426cSTrond Myklebust dprintk("%s ", server->data); 36937aaa0b3bSManoj Naik } 36947aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath); 36957aaa0b3bSManoj Naik if (unlikely(status != 0)) 36967aaa0b3bSManoj Naik goto out_eio; 3697683b57b4STrond Myklebust } 3698409924e4STrond Myklebust if (res->nlocations != 0) 369981934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS; 3700683b57b4STrond Myklebust out: 37013110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3702683b57b4STrond Myklebust return status; 3703c0eae66eSBenny Halevy out_overflow: 3704c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3705683b57b4STrond Myklebust out_eio: 3706683b57b4STrond Myklebust status = -EIO; 3707683b57b4STrond Myklebust goto out; 3708683b57b4STrond Myklebust } 3709683b57b4STrond Myklebust 37101da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 37111da177e4SLinus Torvalds { 37128687b63aSAl Viro __be32 *p; 37131da177e4SLinus Torvalds int status = 0; 37141da177e4SLinus Torvalds 37151da177e4SLinus Torvalds *res = 0; 37161da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U))) 37171da177e4SLinus Torvalds return -EIO; 37181da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) { 3719c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3720c0eae66eSBenny Halevy if (unlikely(!p)) 3721c0eae66eSBenny Halevy goto out_overflow; 3722cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 37231da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE; 37241da177e4SLinus Torvalds } 37253110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res); 37261da177e4SLinus Torvalds return status; 3727c0eae66eSBenny Halevy out_overflow: 3728c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3729c0eae66eSBenny Halevy return -EIO; 37301da177e4SLinus Torvalds } 37311da177e4SLinus Torvalds 37321da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink) 37331da177e4SLinus Torvalds { 37348687b63aSAl Viro __be32 *p; 37351da177e4SLinus Torvalds int status = 0; 37361da177e4SLinus Torvalds 37371da177e4SLinus Torvalds *maxlink = 1; 37381da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U))) 37391da177e4SLinus Torvalds return -EIO; 37401da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) { 3741c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3742c0eae66eSBenny Halevy if (unlikely(!p)) 3743c0eae66eSBenny Halevy goto out_overflow; 3744cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p); 37451da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK; 37461da177e4SLinus Torvalds } 37473110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink); 37481da177e4SLinus Torvalds return status; 3749c0eae66eSBenny Halevy out_overflow: 3750c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3751c0eae66eSBenny Halevy return -EIO; 37521da177e4SLinus Torvalds } 37531da177e4SLinus Torvalds 37541da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname) 37551da177e4SLinus Torvalds { 37568687b63aSAl Viro __be32 *p; 37571da177e4SLinus Torvalds int status = 0; 37581da177e4SLinus Torvalds 37591da177e4SLinus Torvalds *maxname = 1024; 37601da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U))) 37611da177e4SLinus Torvalds return -EIO; 37621da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) { 3763c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3764c0eae66eSBenny Halevy if (unlikely(!p)) 3765c0eae66eSBenny Halevy goto out_overflow; 3766cccddf4fSBenny Halevy *maxname = be32_to_cpup(p); 37671da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME; 37681da177e4SLinus Torvalds } 37693110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname); 37701da177e4SLinus Torvalds return status; 3771c0eae66eSBenny Halevy out_overflow: 3772c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3773c0eae66eSBenny Halevy return -EIO; 37741da177e4SLinus Torvalds } 37751da177e4SLinus Torvalds 37761da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 37771da177e4SLinus Torvalds { 37788687b63aSAl Viro __be32 *p; 37791da177e4SLinus Torvalds int status = 0; 37801da177e4SLinus Torvalds 37811da177e4SLinus Torvalds *res = 1024; 37821da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U))) 37831da177e4SLinus Torvalds return -EIO; 37841da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) { 37851da177e4SLinus Torvalds uint64_t maxread; 3786c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3787c0eae66eSBenny Halevy if (unlikely(!p)) 3788c0eae66eSBenny Halevy goto out_overflow; 3789cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread); 37901da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF) 37911da177e4SLinus Torvalds maxread = 0x7FFFFFFF; 37921da177e4SLinus Torvalds *res = (uint32_t)maxread; 37931da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD; 37941da177e4SLinus Torvalds } 37953110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res); 37961da177e4SLinus Torvalds return status; 3797c0eae66eSBenny Halevy out_overflow: 3798c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3799c0eae66eSBenny Halevy return -EIO; 38001da177e4SLinus Torvalds } 38011da177e4SLinus Torvalds 38021da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res) 38031da177e4SLinus Torvalds { 38048687b63aSAl Viro __be32 *p; 38051da177e4SLinus Torvalds int status = 0; 38061da177e4SLinus Torvalds 38071da177e4SLinus Torvalds *res = 1024; 38081da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U))) 38091da177e4SLinus Torvalds return -EIO; 38101da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) { 38111da177e4SLinus Torvalds uint64_t maxwrite; 3812c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3813c0eae66eSBenny Halevy if (unlikely(!p)) 3814c0eae66eSBenny Halevy goto out_overflow; 3815cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite); 38161da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF) 38171da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF; 38181da177e4SLinus Torvalds *res = (uint32_t)maxwrite; 38191da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE; 38201da177e4SLinus Torvalds } 38213110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res); 38221da177e4SLinus Torvalds return status; 3823c0eae66eSBenny Halevy out_overflow: 3824c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3825c0eae66eSBenny Halevy return -EIO; 38261da177e4SLinus Torvalds } 38271da177e4SLinus Torvalds 3828bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode) 38291da177e4SLinus Torvalds { 3830bca79478STrond Myklebust uint32_t tmp; 38318687b63aSAl Viro __be32 *p; 3832409924e4STrond Myklebust int ret = 0; 38331da177e4SLinus Torvalds 38341da177e4SLinus Torvalds *mode = 0; 38351da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U))) 38361da177e4SLinus Torvalds return -EIO; 38371da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { 3838c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3839c0eae66eSBenny Halevy if (unlikely(!p)) 3840c0eae66eSBenny Halevy goto out_overflow; 3841cccddf4fSBenny Halevy tmp = be32_to_cpup(p); 3842bca79478STrond Myklebust *mode = tmp & ~S_IFMT; 38431da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE; 3844409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE; 38451da177e4SLinus Torvalds } 38463110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); 3847409924e4STrond Myklebust return ret; 3848c0eae66eSBenny Halevy out_overflow: 3849c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3850c0eae66eSBenny Halevy return -EIO; 38511da177e4SLinus Torvalds } 38521da177e4SLinus Torvalds 38531da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink) 38541da177e4SLinus Torvalds { 38558687b63aSAl Viro __be32 *p; 3856409924e4STrond Myklebust int ret = 0; 38571da177e4SLinus Torvalds 38581da177e4SLinus Torvalds *nlink = 1; 38591da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U))) 38601da177e4SLinus Torvalds return -EIO; 38611da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) { 3862c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3863c0eae66eSBenny Halevy if (unlikely(!p)) 3864c0eae66eSBenny Halevy goto out_overflow; 3865cccddf4fSBenny Halevy *nlink = be32_to_cpup(p); 38661da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS; 3867409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK; 38681da177e4SLinus Torvalds } 38693110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink); 3870409924e4STrond Myklebust return ret; 3871c0eae66eSBenny Halevy out_overflow: 3872c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3873c0eae66eSBenny Halevy return -EIO; 38741da177e4SLinus Torvalds } 38751da177e4SLinus Torvalds 387680e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, 3877e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid, 38786926afd1STrond Myklebust struct nfs4_string *owner_name) 38791da177e4SLinus Torvalds { 38808687b63aSAl Viro uint32_t len; 38818687b63aSAl Viro __be32 *p; 3882409924e4STrond Myklebust int ret = 0; 38831da177e4SLinus Torvalds 3884e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2); 38851da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U))) 38861da177e4SLinus Torvalds return -EIO; 38871da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) { 3888c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3889c0eae66eSBenny Halevy if (unlikely(!p)) 3890c0eae66eSBenny Halevy goto out_overflow; 3891cccddf4fSBenny Halevy len = be32_to_cpup(p); 3892c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3893c0eae66eSBenny Halevy if (unlikely(!p)) 3894c0eae66eSBenny Halevy goto out_overflow; 38956926afd1STrond Myklebust if (owner_name != NULL) { 38966926afd1STrond Myklebust owner_name->data = kmemdup(p, len, GFP_NOWAIT); 38976926afd1STrond Myklebust if (owner_name->data != NULL) { 38986926afd1STrond Myklebust owner_name->len = len; 38996926afd1STrond Myklebust ret = NFS_ATTR_FATTR_OWNER_NAME; 39006926afd1STrond Myklebust } 390180e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3902e4fd72a1STrond Myklebust if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0) 3903409924e4STrond Myklebust ret = NFS_ATTR_FATTR_OWNER; 3904409924e4STrond Myklebust else 39051da177e4SLinus Torvalds dprintk("%s: nfs_map_name_to_uid failed!\n", 39063110ff80SHarvey Harrison __func__); 39071da177e4SLinus Torvalds } else 3908fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 39093110ff80SHarvey Harrison __func__, len); 39101da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER; 39111da177e4SLinus Torvalds } 3912e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid)); 3913409924e4STrond Myklebust return ret; 3914c0eae66eSBenny Halevy out_overflow: 3915c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3916c0eae66eSBenny Halevy return -EIO; 39171da177e4SLinus Torvalds } 39181da177e4SLinus Torvalds 391980e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, 3920e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid, 39216926afd1STrond Myklebust struct nfs4_string *group_name) 39221da177e4SLinus Torvalds { 39238687b63aSAl Viro uint32_t len; 39248687b63aSAl Viro __be32 *p; 3925409924e4STrond Myklebust int ret = 0; 39261da177e4SLinus Torvalds 3927e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2); 39281da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U))) 39291da177e4SLinus Torvalds return -EIO; 39301da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) { 3931c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 3932c0eae66eSBenny Halevy if (unlikely(!p)) 3933c0eae66eSBenny Halevy goto out_overflow; 3934cccddf4fSBenny Halevy len = be32_to_cpup(p); 3935c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 3936c0eae66eSBenny Halevy if (unlikely(!p)) 3937c0eae66eSBenny Halevy goto out_overflow; 39386926afd1STrond Myklebust if (group_name != NULL) { 39396926afd1STrond Myklebust group_name->data = kmemdup(p, len, GFP_NOWAIT); 39406926afd1STrond Myklebust if (group_name->data != NULL) { 39416926afd1STrond Myklebust group_name->len = len; 39426926afd1STrond Myklebust ret = NFS_ATTR_FATTR_GROUP_NAME; 39436926afd1STrond Myklebust } 394480e52aceSTrond Myklebust } else if (len < XDR_MAX_NETOBJ) { 3945e4fd72a1STrond Myklebust if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0) 3946409924e4STrond Myklebust ret = NFS_ATTR_FATTR_GROUP; 3947409924e4STrond Myklebust else 39481da177e4SLinus Torvalds dprintk("%s: nfs_map_group_to_gid failed!\n", 39493110ff80SHarvey Harrison __func__); 39501da177e4SLinus Torvalds } else 3951fe82a183SChuck Lever dprintk("%s: name too long (%u)!\n", 39523110ff80SHarvey Harrison __func__, len); 39531da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP; 39541da177e4SLinus Torvalds } 3955e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid)); 3956409924e4STrond Myklebust return ret; 3957c0eae66eSBenny Halevy out_overflow: 3958c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3959c0eae66eSBenny Halevy return -EIO; 39601da177e4SLinus Torvalds } 39611da177e4SLinus Torvalds 39621da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev) 39631da177e4SLinus Torvalds { 39648687b63aSAl Viro uint32_t major = 0, minor = 0; 39658687b63aSAl Viro __be32 *p; 3966409924e4STrond Myklebust int ret = 0; 39671da177e4SLinus Torvalds 39681da177e4SLinus Torvalds *rdev = MKDEV(0,0); 39691da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U))) 39701da177e4SLinus Torvalds return -EIO; 39711da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) { 39721da177e4SLinus Torvalds dev_t tmp; 39731da177e4SLinus Torvalds 3974c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 3975c0eae66eSBenny Halevy if (unlikely(!p)) 3976c0eae66eSBenny Halevy goto out_overflow; 39776f723f77SBenny Halevy major = be32_to_cpup(p++); 3978cccddf4fSBenny Halevy minor = be32_to_cpup(p); 39791da177e4SLinus Torvalds tmp = MKDEV(major, minor); 39801da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor) 39811da177e4SLinus Torvalds *rdev = tmp; 39821da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV; 3983409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV; 39841da177e4SLinus Torvalds } 39853110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor); 3986409924e4STrond Myklebust return ret; 3987c0eae66eSBenny Halevy out_overflow: 3988c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 3989c0eae66eSBenny Halevy return -EIO; 39901da177e4SLinus Torvalds } 39911da177e4SLinus Torvalds 39921da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 39931da177e4SLinus Torvalds { 39948687b63aSAl Viro __be32 *p; 39951da177e4SLinus Torvalds int status = 0; 39961da177e4SLinus Torvalds 39971da177e4SLinus Torvalds *res = 0; 39981da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U))) 39991da177e4SLinus Torvalds return -EIO; 40001da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) { 4001c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4002c0eae66eSBenny Halevy if (unlikely(!p)) 4003c0eae66eSBenny Halevy goto out_overflow; 4004cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40051da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL; 40061da177e4SLinus Torvalds } 40073110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res); 40081da177e4SLinus Torvalds return status; 4009c0eae66eSBenny Halevy out_overflow: 4010c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4011c0eae66eSBenny Halevy return -EIO; 40121da177e4SLinus Torvalds } 40131da177e4SLinus Torvalds 40141da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40151da177e4SLinus Torvalds { 40168687b63aSAl Viro __be32 *p; 40171da177e4SLinus Torvalds int status = 0; 40181da177e4SLinus Torvalds 40191da177e4SLinus Torvalds *res = 0; 40201da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U))) 40211da177e4SLinus Torvalds return -EIO; 40221da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) { 4023c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4024c0eae66eSBenny Halevy if (unlikely(!p)) 4025c0eae66eSBenny Halevy goto out_overflow; 4026cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40271da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE; 40281da177e4SLinus Torvalds } 40293110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res); 40301da177e4SLinus Torvalds return status; 4031c0eae66eSBenny Halevy out_overflow: 4032c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4033c0eae66eSBenny Halevy return -EIO; 40341da177e4SLinus Torvalds } 40351da177e4SLinus Torvalds 40361da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res) 40371da177e4SLinus Torvalds { 40388687b63aSAl Viro __be32 *p; 40391da177e4SLinus Torvalds int status = 0; 40401da177e4SLinus Torvalds 40411da177e4SLinus Torvalds *res = 0; 40421da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U))) 40431da177e4SLinus Torvalds return -EIO; 40441da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) { 4045c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4046c0eae66eSBenny Halevy if (unlikely(!p)) 4047c0eae66eSBenny Halevy goto out_overflow; 4048cccddf4fSBenny Halevy xdr_decode_hyper(p, res); 40491da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL; 40501da177e4SLinus Torvalds } 40513110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res); 40521da177e4SLinus Torvalds return status; 4053c0eae66eSBenny Halevy out_overflow: 4054c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4055c0eae66eSBenny Halevy return -EIO; 40561da177e4SLinus Torvalds } 40571da177e4SLinus Torvalds 40581da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used) 40591da177e4SLinus Torvalds { 40608687b63aSAl Viro __be32 *p; 4061409924e4STrond Myklebust int ret = 0; 40621da177e4SLinus Torvalds 40631da177e4SLinus Torvalds *used = 0; 40641da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U))) 40651da177e4SLinus Torvalds return -EIO; 40661da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) { 4067c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4068c0eae66eSBenny Halevy if (unlikely(!p)) 4069c0eae66eSBenny Halevy goto out_overflow; 4070cccddf4fSBenny Halevy xdr_decode_hyper(p, used); 40711da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED; 4072409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED; 40731da177e4SLinus Torvalds } 40743110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__, 40751da177e4SLinus Torvalds (unsigned long long)*used); 4076409924e4STrond Myklebust return ret; 4077c0eae66eSBenny Halevy out_overflow: 4078c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4079c0eae66eSBenny Halevy return -EIO; 40801da177e4SLinus Torvalds } 40811da177e4SLinus Torvalds 40821da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time) 40831da177e4SLinus Torvalds { 40848687b63aSAl Viro __be32 *p; 40851da177e4SLinus Torvalds uint64_t sec; 40861da177e4SLinus Torvalds uint32_t nsec; 40871da177e4SLinus Torvalds 4088c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 4089c0eae66eSBenny Halevy if (unlikely(!p)) 4090c0eae66eSBenny Halevy goto out_overflow; 40913ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &sec); 4092cccddf4fSBenny Halevy nsec = be32_to_cpup(p); 40931da177e4SLinus Torvalds time->tv_sec = (time_t)sec; 40941da177e4SLinus Torvalds time->tv_nsec = (long)nsec; 40951da177e4SLinus Torvalds return 0; 4096c0eae66eSBenny Halevy out_overflow: 4097c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4098c0eae66eSBenny Halevy return -EIO; 40991da177e4SLinus Torvalds } 41001da177e4SLinus Torvalds 41011da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41021da177e4SLinus Torvalds { 41031da177e4SLinus Torvalds int status = 0; 41041da177e4SLinus Torvalds 41051da177e4SLinus Torvalds time->tv_sec = 0; 41061da177e4SLinus Torvalds time->tv_nsec = 0; 41071da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U))) 41081da177e4SLinus Torvalds return -EIO; 41091da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) { 41101da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4111409924e4STrond Myklebust if (status == 0) 4112409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME; 41131da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS; 41141da177e4SLinus Torvalds } 41153110ff80SHarvey Harrison dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec); 41161da177e4SLinus Torvalds return status; 41171da177e4SLinus Torvalds } 41181da177e4SLinus Torvalds 41191da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 41201da177e4SLinus Torvalds { 41211da177e4SLinus Torvalds int status = 0; 41221da177e4SLinus Torvalds 41231da177e4SLinus Torvalds time->tv_sec = 0; 41241da177e4SLinus Torvalds time->tv_nsec = 0; 41251da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U))) 41261da177e4SLinus Torvalds return -EIO; 41271da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) { 41281da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4129409924e4STrond Myklebust if (status == 0) 4130409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME; 41311da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA; 41321da177e4SLinus Torvalds } 41333110ff80SHarvey Harrison dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec); 41341da177e4SLinus Torvalds return status; 41351da177e4SLinus Torvalds } 41361da177e4SLinus Torvalds 413755b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap, 413855b6e774SRicardo Labiaga struct timespec *time) 413955b6e774SRicardo Labiaga { 414055b6e774SRicardo Labiaga int status = 0; 414155b6e774SRicardo Labiaga 414255b6e774SRicardo Labiaga time->tv_sec = 0; 414355b6e774SRicardo Labiaga time->tv_nsec = 0; 414455b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U))) 414555b6e774SRicardo Labiaga return -EIO; 414655b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) { 414755b6e774SRicardo Labiaga status = decode_attr_time(xdr, time); 414855b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA; 414955b6e774SRicardo Labiaga } 415055b6e774SRicardo Labiaga dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec, 415155b6e774SRicardo Labiaga (long)time->tv_nsec); 415255b6e774SRicardo Labiaga return status; 415355b6e774SRicardo Labiaga } 415455b6e774SRicardo Labiaga 4155aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, 4156aa9c2669SDavid Quigley struct nfs4_label *label) 4157aa9c2669SDavid Quigley { 4158aa9c2669SDavid Quigley uint32_t pi = 0; 4159aa9c2669SDavid Quigley uint32_t lfs = 0; 4160aa9c2669SDavid Quigley __u32 len; 4161aa9c2669SDavid Quigley __be32 *p; 4162aa9c2669SDavid Quigley int status = 0; 4163aa9c2669SDavid Quigley 4164aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U))) 4165aa9c2669SDavid Quigley return -EIO; 4166aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) { 4167aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4168aa9c2669SDavid Quigley if (unlikely(!p)) 4169aa9c2669SDavid Quigley goto out_overflow; 4170aa9c2669SDavid Quigley lfs = be32_to_cpup(p++); 4171aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4172aa9c2669SDavid Quigley if (unlikely(!p)) 4173aa9c2669SDavid Quigley goto out_overflow; 4174aa9c2669SDavid Quigley pi = be32_to_cpup(p++); 4175aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4); 4176aa9c2669SDavid Quigley if (unlikely(!p)) 4177aa9c2669SDavid Quigley goto out_overflow; 4178aa9c2669SDavid Quigley len = be32_to_cpup(p++); 4179aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len); 4180aa9c2669SDavid Quigley if (unlikely(!p)) 4181aa9c2669SDavid Quigley goto out_overflow; 4182aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) { 4183aa9c2669SDavid Quigley if (label) { 4184aa9c2669SDavid Quigley memcpy(label->label, p, len); 4185aa9c2669SDavid Quigley label->len = len; 4186aa9c2669SDavid Quigley label->pi = pi; 4187aa9c2669SDavid Quigley label->lfs = lfs; 4188aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; 4189aa9c2669SDavid Quigley } 4190aa9c2669SDavid Quigley bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL; 4191aa9c2669SDavid Quigley } else 4192aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n", 4193aa9c2669SDavid Quigley __func__, len); 4194aa9c2669SDavid Quigley } 4195aa9c2669SDavid Quigley if (label && label->label) 4196aa9c2669SDavid Quigley dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, 4197aa9c2669SDavid Quigley (char *)label->label, label->len, label->pi, label->lfs); 4198aa9c2669SDavid Quigley return status; 4199aa9c2669SDavid Quigley 4200aa9c2669SDavid Quigley out_overflow: 4201aa9c2669SDavid Quigley print_overflow_msg(__func__, xdr); 4202aa9c2669SDavid Quigley return -EIO; 4203aa9c2669SDavid Quigley } 4204aa9c2669SDavid Quigley 42051da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time) 42061da177e4SLinus Torvalds { 42071da177e4SLinus Torvalds int status = 0; 42081da177e4SLinus Torvalds 42091da177e4SLinus Torvalds time->tv_sec = 0; 42101da177e4SLinus Torvalds time->tv_nsec = 0; 42111da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U))) 42121da177e4SLinus Torvalds return -EIO; 42131da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) { 42141da177e4SLinus Torvalds status = decode_attr_time(xdr, time); 4215409924e4STrond Myklebust if (status == 0) 4216409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME; 42171da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY; 42181da177e4SLinus Torvalds } 42193110ff80SHarvey Harrison dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec); 42201da177e4SLinus Torvalds return status; 42211da177e4SLinus Torvalds } 42221da177e4SLinus Torvalds 4223256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen) 42241da177e4SLinus Torvalds { 42251da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen); 4226256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2; 42271da177e4SLinus Torvalds 42281da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) { 4229fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: " 4230fe82a183SChuck Lever "%u %c %u\n", 42313110ff80SHarvey Harrison __func__, 42321da177e4SLinus Torvalds attrwords << 2, 42331da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>', 42341da177e4SLinus Torvalds nwords << 2); 42351da177e4SLinus Torvalds return -EIO; 42361da177e4SLinus Torvalds } 42371da177e4SLinus Torvalds return 0; 42381da177e4SLinus Torvalds } 42391da177e4SLinus Torvalds 42401da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 42411da177e4SLinus Torvalds { 42428687b63aSAl Viro __be32 *p; 42431da177e4SLinus Torvalds 4244c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 4245c0eae66eSBenny Halevy if (unlikely(!p)) 4246c0eae66eSBenny Halevy goto out_overflow; 42476f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++); 42483ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before); 4249cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after); 42501da177e4SLinus Torvalds return 0; 4251c0eae66eSBenny Halevy out_overflow: 4252c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4253c0eae66eSBenny Halevy return -EIO; 42541da177e4SLinus Torvalds } 42551da177e4SLinus Torvalds 42566168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) 42571da177e4SLinus Torvalds { 42588687b63aSAl Viro __be32 *p; 42591da177e4SLinus Torvalds uint32_t supp, acc; 42601da177e4SLinus Torvalds int status; 42611da177e4SLinus Torvalds 42621da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS); 42631da177e4SLinus Torvalds if (status) 42641da177e4SLinus Torvalds return status; 4265c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 4266c0eae66eSBenny Halevy if (unlikely(!p)) 4267c0eae66eSBenny Halevy goto out_overflow; 42686f723f77SBenny Halevy supp = be32_to_cpup(p++); 4269cccddf4fSBenny Halevy acc = be32_to_cpup(p); 42706168f62cSWeston Andros Adamson *supported = supp; 42716168f62cSWeston Andros Adamson *access = acc; 42721da177e4SLinus Torvalds return 0; 4273c0eae66eSBenny Halevy out_overflow: 4274c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4275c0eae66eSBenny Halevy return -EIO; 42761da177e4SLinus Torvalds } 42771da177e4SLinus Torvalds 427807d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) 42791da177e4SLinus Torvalds { 42808687b63aSAl Viro __be32 *p; 428107d30434SBenny Halevy 428207d30434SBenny Halevy p = xdr_inline_decode(xdr, len); 428307d30434SBenny Halevy if (likely(p)) { 428407d30434SBenny Halevy memcpy(buf, p, len); 428507d30434SBenny Halevy return 0; 428607d30434SBenny Halevy } 428707d30434SBenny Halevy print_overflow_msg(__func__, xdr); 428807d30434SBenny Halevy return -EIO; 428907d30434SBenny Halevy } 429007d30434SBenny Halevy 429107d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 429207d30434SBenny Halevy { 42932d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); 42941da177e4SLinus Torvalds } 42951da177e4SLinus Torvalds 429693b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 429793b717fdSTrond Myklebust { 429893b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE; 429993b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 430093b717fdSTrond Myklebust } 430193b717fdSTrond Myklebust 430293b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 430393b717fdSTrond Myklebust { 430493b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE; 430593b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 430693b717fdSTrond Myklebust } 430793b717fdSTrond Myklebust 430893b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 430993b717fdSTrond Myklebust { 431093b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE; 431193b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 431293b717fdSTrond Myklebust } 431393b717fdSTrond Myklebust 43141da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 43151da177e4SLinus Torvalds { 43161da177e4SLinus Torvalds int status; 43171da177e4SLinus Torvalds 43181da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE); 4319c1d51931STrond Myklebust if (status != -EIO) 4320c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 432107d30434SBenny Halevy if (!status) 432293b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 43231da177e4SLinus Torvalds return status; 43241da177e4SLinus Torvalds } 43251da177e4SLinus Torvalds 4326db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4327db942bbdSBenny Halevy { 4328cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE); 43291da177e4SLinus Torvalds } 43301da177e4SLinus Torvalds 43312f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier) 43322f2c63bcSTrond Myklebust { 43332f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE); 43342f2c63bcSTrond Myklebust } 43352f2c63bcSTrond Myklebust 43360b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res) 43371da177e4SLinus Torvalds { 43381da177e4SLinus Torvalds int status; 43391da177e4SLinus Torvalds 43401da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT); 4341db942bbdSBenny Halevy if (!status) 43422f2c63bcSTrond Myklebust status = decode_write_verifier(xdr, &res->verf->verifier); 43431da177e4SLinus Torvalds return status; 43441da177e4SLinus Torvalds } 43451da177e4SLinus Torvalds 43461da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 43471da177e4SLinus Torvalds { 43488687b63aSAl Viro __be32 *p; 43491da177e4SLinus Torvalds uint32_t bmlen; 43501da177e4SLinus Torvalds int status; 43511da177e4SLinus Torvalds 43521da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE); 43531da177e4SLinus Torvalds if (status) 43541da177e4SLinus Torvalds return status; 43551da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo))) 43561da177e4SLinus Torvalds return status; 4357c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4358c0eae66eSBenny Halevy if (unlikely(!p)) 4359c0eae66eSBenny Halevy goto out_overflow; 4360cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 4361c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 4362c0eae66eSBenny Halevy if (likely(p)) 43631da177e4SLinus Torvalds return 0; 4364c0eae66eSBenny Halevy out_overflow: 4365c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4366c0eae66eSBenny Halevy return -EIO; 43671da177e4SLinus Torvalds } 43681da177e4SLinus Torvalds 43691da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res) 43701da177e4SLinus Torvalds { 4371256e48bbSTrond Myklebust unsigned int savep; 4372dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 43731da177e4SLinus Torvalds int status; 43741da177e4SLinus Torvalds 43751da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 43761da177e4SLinus Torvalds goto xdr_error; 43771da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 43781da177e4SLinus Torvalds goto xdr_error; 43791da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 43801da177e4SLinus Torvalds goto xdr_error; 43811da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 43821da177e4SLinus Torvalds goto xdr_error; 4383264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap, 4384264e6351SChuck Lever &res->fh_expire_type)) != 0) 4385264e6351SChuck Lever goto xdr_error; 43861da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 43871da177e4SLinus Torvalds goto xdr_error; 43881da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 43891da177e4SLinus Torvalds goto xdr_error; 43901da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0) 43911da177e4SLinus Torvalds goto xdr_error; 43928c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap, 43938c61282fSKinglong Mee res->exclcreat_bitmask)) != 0) 43948c61282fSKinglong Mee goto xdr_error; 43951da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 43961da177e4SLinus Torvalds xdr_error: 43973110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 43981da177e4SLinus Torvalds return status; 43991da177e4SLinus Torvalds } 44001da177e4SLinus Torvalds 44011da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat) 44021da177e4SLinus Torvalds { 4403256e48bbSTrond Myklebust unsigned int savep; 4404dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44051da177e4SLinus Torvalds int status; 44061da177e4SLinus Torvalds 44071da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44081da177e4SLinus Torvalds goto xdr_error; 44091da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44101da177e4SLinus Torvalds goto xdr_error; 44111da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44121da177e4SLinus Torvalds goto xdr_error; 44131da177e4SLinus Torvalds 44141da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0) 44151da177e4SLinus Torvalds goto xdr_error; 44161da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0) 44171da177e4SLinus Torvalds goto xdr_error; 44181da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0) 44191da177e4SLinus Torvalds goto xdr_error; 44201ca843a2SAndreas Gruenbacher 44211ca843a2SAndreas Gruenbacher status = -EIO; 44221ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 44231ca843a2SAndreas Gruenbacher goto xdr_error; 44241ca843a2SAndreas Gruenbacher 44251da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0) 44261da177e4SLinus Torvalds goto xdr_error; 44271da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0) 44281da177e4SLinus Torvalds goto xdr_error; 44291da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0) 44301da177e4SLinus Torvalds goto xdr_error; 44311da177e4SLinus Torvalds 44321da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44331da177e4SLinus Torvalds xdr_error: 44343110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44351da177e4SLinus Torvalds return status; 44361da177e4SLinus Torvalds } 44371da177e4SLinus Torvalds 44381da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf) 44391da177e4SLinus Torvalds { 4440256e48bbSTrond Myklebust unsigned int savep; 4441dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0}; 44421da177e4SLinus Torvalds int status; 44431da177e4SLinus Torvalds 44441da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 44451da177e4SLinus Torvalds goto xdr_error; 44461da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 44471da177e4SLinus Torvalds goto xdr_error; 44481da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 44491da177e4SLinus Torvalds goto xdr_error; 44501da177e4SLinus Torvalds 44511da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0) 44521da177e4SLinus Torvalds goto xdr_error; 44531da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0) 44541da177e4SLinus Torvalds goto xdr_error; 44551da177e4SLinus Torvalds 44561da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 44571da177e4SLinus Torvalds xdr_error: 44583110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 44591da177e4SLinus Torvalds return status; 44601da177e4SLinus Torvalds } 44611da177e4SLinus Torvalds 446288034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr, 446388034c3dSAndy Adamson uint32_t *bitmap, 446488034c3dSAndy Adamson uint64_t *res, 446588034c3dSAndy Adamson uint32_t hint_bit) 446688034c3dSAndy Adamson { 446788034c3dSAndy Adamson __be32 *p; 446888034c3dSAndy Adamson 446988034c3dSAndy Adamson *res = 0; 447088034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) { 447188034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8); 447288034c3dSAndy Adamson if (unlikely(!p)) 447388034c3dSAndy Adamson goto out_overflow; 447488034c3dSAndy Adamson xdr_decode_hyper(p, res); 447588034c3dSAndy Adamson } 447688034c3dSAndy Adamson return 0; 447788034c3dSAndy Adamson out_overflow: 447888034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 447988034c3dSAndy Adamson return -EIO; 448088034c3dSAndy Adamson } 448188034c3dSAndy Adamson 448288034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr, 448388034c3dSAndy Adamson struct nfs4_threshold *res) 448488034c3dSAndy Adamson { 4485256e48bbSTrond Myklebust __be32 *p; 4486256e48bbSTrond Myklebust unsigned int savep; 448788034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen; 448888034c3dSAndy Adamson int status; 448988034c3dSAndy Adamson 449088034c3dSAndy Adamson /* layout type */ 449188034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 449288034c3dSAndy Adamson if (unlikely(!p)) { 449388034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 449488034c3dSAndy Adamson return -EIO; 449588034c3dSAndy Adamson } 449688034c3dSAndy Adamson res->l_type = be32_to_cpup(p); 449788034c3dSAndy Adamson 449888034c3dSAndy Adamson /* thi_hintset bitmap */ 449988034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap); 450088034c3dSAndy Adamson if (status < 0) 450188034c3dSAndy Adamson goto xdr_error; 450288034c3dSAndy Adamson 450388034c3dSAndy Adamson /* thi_hintlist length */ 450488034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep); 450588034c3dSAndy Adamson if (status < 0) 450688034c3dSAndy Adamson goto xdr_error; 450788034c3dSAndy Adamson /* thi_hintlist */ 450888034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD); 450988034c3dSAndy Adamson if (status < 0) 451088034c3dSAndy Adamson goto xdr_error; 451188034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR); 451288034c3dSAndy Adamson if (status < 0) 451388034c3dSAndy Adamson goto xdr_error; 451488034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz, 451588034c3dSAndy Adamson THRESHOLD_RD_IO); 451688034c3dSAndy Adamson if (status < 0) 451788034c3dSAndy Adamson goto xdr_error; 451888034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz, 451988034c3dSAndy Adamson THRESHOLD_WR_IO); 452088034c3dSAndy Adamson if (status < 0) 452188034c3dSAndy Adamson goto xdr_error; 452288034c3dSAndy Adamson 452388034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen); 452488034c3dSAndy Adamson res->bm = bitmap[0]; 452588034c3dSAndy Adamson 452688034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", 452788034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz, 452888034c3dSAndy Adamson res->wr_io_sz); 452988034c3dSAndy Adamson xdr_error: 453088034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status); 453188034c3dSAndy Adamson return status; 453288034c3dSAndy Adamson } 453388034c3dSAndy Adamson 453488034c3dSAndy Adamson /* 453588034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O 453688034c3dSAndy Adamson */ 453788034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr, 453888034c3dSAndy Adamson uint32_t *bitmap, 453988034c3dSAndy Adamson struct nfs4_threshold *res) 454088034c3dSAndy Adamson { 454188034c3dSAndy Adamson __be32 *p; 454288034c3dSAndy Adamson int status = 0; 454388034c3dSAndy Adamson uint32_t num; 454488034c3dSAndy Adamson 454588034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U))) 454688034c3dSAndy Adamson return -EIO; 4547029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) { 45481549210fSTrond Myklebust /* Did the server return an unrequested attribute? */ 45491549210fSTrond Myklebust if (unlikely(res == NULL)) 45501549210fSTrond Myklebust return -EREMOTEIO; 455188034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4); 455288034c3dSAndy Adamson if (unlikely(!p)) 455388034c3dSAndy Adamson goto out_overflow; 455488034c3dSAndy Adamson num = be32_to_cpup(p); 455588034c3dSAndy Adamson if (num == 0) 455688034c3dSAndy Adamson return 0; 455788034c3dSAndy Adamson if (num > 1) 455888034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout " 455988034c3dSAndy Adamson "drivers per filesystem not supported\n", 456088034c3dSAndy Adamson __func__); 456188034c3dSAndy Adamson 456288034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res); 4563029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD; 456488034c3dSAndy Adamson } 456588034c3dSAndy Adamson return status; 456688034c3dSAndy Adamson out_overflow: 456788034c3dSAndy Adamson print_overflow_msg(__func__, xdr); 456888034c3dSAndy Adamson return -EIO; 456988034c3dSAndy Adamson } 457088034c3dSAndy Adamson 4571ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4572ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh, 4573aa9c2669SDavid Quigley struct nfs4_fs_locations *fs_loc, struct nfs4_label *label, 45746926afd1STrond Myklebust const struct nfs_server *server) 45751da177e4SLinus Torvalds { 4576bca79478STrond Myklebust int status; 4577bca79478STrond Myklebust umode_t fmode = 0; 4578ae42c70aSBryan Schumaker uint32_t type; 4579ee7b75fcSTrond Myklebust int32_t err; 45801da177e4SLinus Torvalds 4581f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type); 4582f26c7a78STrond Myklebust if (status < 0) 45831da177e4SLinus Torvalds goto xdr_error; 4584409924e4STrond Myklebust fattr->mode = 0; 4585409924e4STrond Myklebust if (status != 0) { 4586409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type]; 4587409924e4STrond Myklebust fattr->valid |= status; 4588409924e4STrond Myklebust } 45891da177e4SLinus Torvalds 4590f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr); 4591f26c7a78STrond Myklebust if (status < 0) 45921da177e4SLinus Torvalds goto xdr_error; 4593409924e4STrond Myklebust fattr->valid |= status; 4594f26c7a78STrond Myklebust 4595f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size); 4596f26c7a78STrond Myklebust if (status < 0) 45971da177e4SLinus Torvalds goto xdr_error; 4598409924e4STrond Myklebust fattr->valid |= status; 4599f26c7a78STrond Myklebust 4600f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid); 4601f26c7a78STrond Myklebust if (status < 0) 46021da177e4SLinus Torvalds goto xdr_error; 4603409924e4STrond Myklebust fattr->valid |= status; 4604f26c7a78STrond Myklebust 4605ee7b75fcSTrond Myklebust err = 0; 4606ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err); 4607ae42c70aSBryan Schumaker if (status < 0) 4608ae42c70aSBryan Schumaker goto xdr_error; 4609ae42c70aSBryan Schumaker 4610ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh); 4611ae42c70aSBryan Schumaker if (status < 0) 4612ae42c70aSBryan Schumaker goto xdr_error; 4613ae42c70aSBryan Schumaker 4614f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid); 4615f26c7a78STrond Myklebust if (status < 0) 46161da177e4SLinus Torvalds goto xdr_error; 4617409924e4STrond Myklebust fattr->valid |= status; 4618f26c7a78STrond Myklebust 46198b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc); 4620f26c7a78STrond Myklebust if (status < 0) 4621683b57b4STrond Myklebust goto xdr_error; 4622409924e4STrond Myklebust fattr->valid |= status; 4623f26c7a78STrond Myklebust 46241ca843a2SAndreas Gruenbacher status = -EIO; 46251ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 46261ca843a2SAndreas Gruenbacher goto xdr_error; 46271ca843a2SAndreas Gruenbacher 4628f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode); 4629f26c7a78STrond Myklebust if (status < 0) 46301da177e4SLinus Torvalds goto xdr_error; 4631409924e4STrond Myklebust if (status != 0) { 46321da177e4SLinus Torvalds fattr->mode |= fmode; 4633409924e4STrond Myklebust fattr->valid |= status; 4634409924e4STrond Myklebust } 4635f26c7a78STrond Myklebust 4636f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink); 4637f26c7a78STrond Myklebust if (status < 0) 46381da177e4SLinus Torvalds goto xdr_error; 4639409924e4STrond Myklebust fattr->valid |= status; 4640f26c7a78STrond Myklebust 46416926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name); 4642f26c7a78STrond Myklebust if (status < 0) 46431da177e4SLinus Torvalds goto xdr_error; 4644409924e4STrond Myklebust fattr->valid |= status; 4645f26c7a78STrond Myklebust 46466926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name); 4647f26c7a78STrond Myklebust if (status < 0) 46481da177e4SLinus Torvalds goto xdr_error; 4649409924e4STrond Myklebust fattr->valid |= status; 4650f26c7a78STrond Myklebust 4651f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev); 4652f26c7a78STrond Myklebust if (status < 0) 46531da177e4SLinus Torvalds goto xdr_error; 4654409924e4STrond Myklebust fattr->valid |= status; 4655f26c7a78STrond Myklebust 4656f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used); 4657f26c7a78STrond Myklebust if (status < 0) 46581da177e4SLinus Torvalds goto xdr_error; 4659409924e4STrond Myklebust fattr->valid |= status; 4660f26c7a78STrond Myklebust 4661f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime); 4662f26c7a78STrond Myklebust if (status < 0) 46631da177e4SLinus Torvalds goto xdr_error; 4664409924e4STrond Myklebust fattr->valid |= status; 4665f26c7a78STrond Myklebust 4666f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime); 4667f26c7a78STrond Myklebust if (status < 0) 46681da177e4SLinus Torvalds goto xdr_error; 4669409924e4STrond Myklebust fattr->valid |= status; 4670f26c7a78STrond Myklebust 4671f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime); 4672f26c7a78STrond Myklebust if (status < 0) 46731da177e4SLinus Torvalds goto xdr_error; 4674409924e4STrond Myklebust fattr->valid |= status; 4675f26c7a78STrond Myklebust 467628331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid); 4677f26c7a78STrond Myklebust if (status < 0) 467899baf625SManoj Naik goto xdr_error; 4679409924e4STrond Myklebust fattr->valid |= status; 4680f26c7a78STrond Myklebust 46811ca843a2SAndreas Gruenbacher status = -EIO; 46821ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 46831ca843a2SAndreas Gruenbacher goto xdr_error; 46841ca843a2SAndreas Gruenbacher 468588034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold); 468688034c3dSAndy Adamson if (status < 0) 468788034c3dSAndy Adamson goto xdr_error; 468888034c3dSAndy Adamson 4689aa9c2669SDavid Quigley if (label) { 4690aa9c2669SDavid Quigley status = decode_attr_security_label(xdr, bitmap, label); 4691aa9c2669SDavid Quigley if (status < 0) 4692aa9c2669SDavid Quigley goto xdr_error; 4693aa9c2669SDavid Quigley fattr->valid |= status; 4694aa9c2669SDavid Quigley } 4695aa9c2669SDavid Quigley 4696ae42c70aSBryan Schumaker xdr_error: 4697ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status); 4698ae42c70aSBryan Schumaker return status; 4699ae42c70aSBryan Schumaker } 4700ae42c70aSBryan Schumaker 4701ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47028b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc, 4703aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4704ae42c70aSBryan Schumaker { 4705256e48bbSTrond Myklebust unsigned int savep; 4706ae42c70aSBryan Schumaker uint32_t attrlen, 4707dae100c2SFred Isaman bitmap[3] = {0}; 4708ae42c70aSBryan Schumaker int status; 4709ae42c70aSBryan Schumaker 4710ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR); 4711ae42c70aSBryan Schumaker if (status < 0) 4712ae42c70aSBryan Schumaker goto xdr_error; 4713ae42c70aSBryan Schumaker 4714ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap); 4715ae42c70aSBryan Schumaker if (status < 0) 4716ae42c70aSBryan Schumaker goto xdr_error; 4717ae42c70aSBryan Schumaker 4718ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep); 4719ae42c70aSBryan Schumaker if (status < 0) 4720ae42c70aSBryan Schumaker goto xdr_error; 4721ae42c70aSBryan Schumaker 4722aa9c2669SDavid Quigley status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, 4723aa9c2669SDavid Quigley label, server); 4724ae42c70aSBryan Schumaker if (status < 0) 4725ae42c70aSBryan Schumaker goto xdr_error; 4726ae42c70aSBryan Schumaker 4727f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen); 47281da177e4SLinus Torvalds xdr_error: 47293110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status); 47301da177e4SLinus Torvalds return status; 47311da177e4SLinus Torvalds } 47321da177e4SLinus Torvalds 4733aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4734aa9c2669SDavid Quigley struct nfs4_label *label, const struct nfs_server *server) 4735aa9c2669SDavid Quigley { 4736aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server); 4737aa9c2669SDavid Quigley } 4738aa9c2669SDavid Quigley 4739ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 47406926afd1STrond Myklebust const struct nfs_server *server) 4741ae42c70aSBryan Schumaker { 4742aa9c2669SDavid Quigley return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server); 4743ae42c70aSBryan Schumaker } 47441da177e4SLinus Torvalds 4745504913fbSAndy Adamson /* 47463132e49eSJeff Layton * Decode potentially multiple layout types. 4747504913fbSAndy Adamson */ 47483132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr, 4749ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4750504913fbSAndy Adamson { 4751b8a8a0ddSTrond Myklebust __be32 *p; 4752ca440c38SJeff Layton uint32_t i; 4753504913fbSAndy Adamson 4754504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4); 4755504913fbSAndy Adamson if (unlikely(!p)) 4756504913fbSAndy Adamson goto out_overflow; 4757ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p); 4758504913fbSAndy Adamson 4759504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */ 4760ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0) 4761504913fbSAndy Adamson return 0; 4762504913fbSAndy Adamson 4763504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */ 4764ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4); 4765504913fbSAndy Adamson if (unlikely(!p)) 4766504913fbSAndy Adamson goto out_overflow; 4767ca440c38SJeff Layton 4768ca440c38SJeff Layton /* If we get too many, then just cap it at the max */ 4769ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) { 4770ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n", 4771ca440c38SJeff Layton __func__, fsinfo->nlayouttypes); 4772ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES; 4773ca440c38SJeff Layton } 4774ca440c38SJeff Layton 4775ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i) 4776ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++); 4777504913fbSAndy Adamson return 0; 4778504913fbSAndy Adamson out_overflow: 4779504913fbSAndy Adamson print_overflow_msg(__func__, xdr); 4780504913fbSAndy Adamson return -EIO; 4781504913fbSAndy Adamson } 4782504913fbSAndy Adamson 4783504913fbSAndy Adamson /* 4784504913fbSAndy Adamson * The type of file system exported. 4785504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case. 4786504913fbSAndy Adamson */ 4787504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap, 4788ca440c38SJeff Layton struct nfs_fsinfo *fsinfo) 4789504913fbSAndy Adamson { 4790504913fbSAndy Adamson int status = 0; 4791504913fbSAndy Adamson 4792504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]); 4793504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U))) 4794504913fbSAndy Adamson return -EIO; 4795504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) { 4796ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo); 4797504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES; 47983132e49eSJeff Layton } 4799504913fbSAndy Adamson return status; 4800504913fbSAndy Adamson } 4801504913fbSAndy Adamson 4802dae100c2SFred Isaman /* 4803dae100c2SFred Isaman * The prefered block size for layout directed io 4804dae100c2SFred Isaman */ 4805dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 4806dae100c2SFred Isaman uint32_t *res) 4807dae100c2SFred Isaman { 4808dae100c2SFred Isaman __be32 *p; 4809dae100c2SFred Isaman 4810dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4811dae100c2SFred Isaman *res = 0; 4812dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) { 4813dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4); 4814dae100c2SFred Isaman if (unlikely(!p)) { 4815dae100c2SFred Isaman print_overflow_msg(__func__, xdr); 4816dae100c2SFred Isaman return -EIO; 4817dae100c2SFred Isaman } 4818dae100c2SFred Isaman *res = be32_to_cpup(p); 4819dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE; 4820dae100c2SFred Isaman } 4821dae100c2SFred Isaman return 0; 4822dae100c2SFred Isaman } 4823dae100c2SFred Isaman 48242a92ee92SPeng Tao /* 48252a92ee92SPeng Tao * The granularity of a CLONE operation. 48262a92ee92SPeng Tao */ 48272a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap, 48282a92ee92SPeng Tao uint32_t *res) 48292a92ee92SPeng Tao { 48302a92ee92SPeng Tao __be32 *p; 48312a92ee92SPeng Tao 48322a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 48332a92ee92SPeng Tao *res = 0; 48342a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) { 48352a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4); 48362a92ee92SPeng Tao if (unlikely(!p)) { 48372a92ee92SPeng Tao print_overflow_msg(__func__, xdr); 48382a92ee92SPeng Tao return -EIO; 48392a92ee92SPeng Tao } 48402a92ee92SPeng Tao *res = be32_to_cpup(p); 48412a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE; 48422a92ee92SPeng Tao } 48432a92ee92SPeng Tao return 0; 48442a92ee92SPeng Tao } 48452a92ee92SPeng Tao 48461da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 48471da177e4SLinus Torvalds { 4848256e48bbSTrond Myklebust unsigned int savep; 4849dae100c2SFred Isaman uint32_t attrlen, bitmap[3]; 48501da177e4SLinus Torvalds int status; 48511da177e4SLinus Torvalds 48521da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 48531da177e4SLinus Torvalds goto xdr_error; 48541da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 48551da177e4SLinus Torvalds goto xdr_error; 48561da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 48571da177e4SLinus Torvalds goto xdr_error; 48581da177e4SLinus Torvalds 48591da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */ 48601da177e4SLinus Torvalds 48611da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0) 48621da177e4SLinus Torvalds goto xdr_error; 48631da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0) 48641da177e4SLinus Torvalds goto xdr_error; 48651da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0) 48661da177e4SLinus Torvalds goto xdr_error; 48671da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax; 48681da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0) 48691da177e4SLinus Torvalds goto xdr_error; 48701da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax; 48711ca843a2SAndreas Gruenbacher 48721ca843a2SAndreas Gruenbacher status = -EIO; 48731ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0])) 48741ca843a2SAndreas Gruenbacher goto xdr_error; 48751ca843a2SAndreas Gruenbacher 487655b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta); 487755b6e774SRicardo Labiaga if (status != 0) 487855b6e774SRicardo Labiaga goto xdr_error; 4879ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo); 4880504913fbSAndy Adamson if (status != 0) 4881504913fbSAndy Adamson goto xdr_error; 48821ca843a2SAndreas Gruenbacher 48831ca843a2SAndreas Gruenbacher status = -EIO; 48841ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1])) 48851ca843a2SAndreas Gruenbacher goto xdr_error; 48861ca843a2SAndreas Gruenbacher 4887dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize); 4888dae100c2SFred Isaman if (status) 4889dae100c2SFred Isaman goto xdr_error; 48902a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize); 48912a92ee92SPeng Tao if (status) 48922a92ee92SPeng Tao goto xdr_error; 48931da177e4SLinus Torvalds 48941da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen); 48951da177e4SLinus Torvalds xdr_error: 48963110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status); 48971da177e4SLinus Torvalds return status; 48981da177e4SLinus Torvalds } 48991da177e4SLinus Torvalds 49001da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh) 49011da177e4SLinus Torvalds { 49028687b63aSAl Viro __be32 *p; 49031da177e4SLinus Torvalds uint32_t len; 49041da177e4SLinus Torvalds int status; 49051da177e4SLinus Torvalds 49069936781dSTrond Myklebust /* Zero handle first to allow comparisons */ 49079936781dSTrond Myklebust memset(fh, 0, sizeof(*fh)); 49089936781dSTrond Myklebust 49091da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH); 49101da177e4SLinus Torvalds if (status) 49111da177e4SLinus Torvalds return status; 49121da177e4SLinus Torvalds 4913c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 4914c0eae66eSBenny Halevy if (unlikely(!p)) 4915c0eae66eSBenny Halevy goto out_overflow; 4916cccddf4fSBenny Halevy len = be32_to_cpup(p); 49171da177e4SLinus Torvalds if (len > NFS4_FHSIZE) 49181da177e4SLinus Torvalds return -EIO; 49191da177e4SLinus Torvalds fh->size = len; 4920c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 4921c0eae66eSBenny Halevy if (unlikely(!p)) 4922c0eae66eSBenny Halevy goto out_overflow; 492399398d06SBenny Halevy memcpy(fh->data, p, len); 49241da177e4SLinus Torvalds return 0; 4925c0eae66eSBenny Halevy out_overflow: 4926c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4927c0eae66eSBenny Halevy return -EIO; 49281da177e4SLinus Torvalds } 49291da177e4SLinus Torvalds 49301da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 49311da177e4SLinus Torvalds { 49321da177e4SLinus Torvalds int status; 49331da177e4SLinus Torvalds 49341da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK); 49351da177e4SLinus Torvalds if (status) 49361da177e4SLinus Torvalds return status; 49371da177e4SLinus Torvalds return decode_change_info(xdr, cinfo); 49381da177e4SLinus Torvalds } 49391da177e4SLinus Torvalds 49401da177e4SLinus Torvalds /* 49411da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4. 49421da177e4SLinus Torvalds */ 4943911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl) 49441da177e4SLinus Torvalds { 4945911d1aafSTrond Myklebust uint64_t offset, length, clientid; 49468687b63aSAl Viro __be32 *p; 4947911d1aafSTrond Myklebust uint32_t namelen, type; 49481da177e4SLinus Torvalds 4949babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */ 4950c0eae66eSBenny Halevy if (unlikely(!p)) 4951c0eae66eSBenny Halevy goto out_overflow; 4952babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */ 49533ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length); 4954babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */ 4955babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */ 4956911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset; 4957911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1; 4958911d1aafSTrond Myklebust if (length == ~(uint64_t)0) 4959911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX; 4960911d1aafSTrond Myklebust fl->fl_type = F_WRLCK; 4961911d1aafSTrond Myklebust if (type & 1) 4962911d1aafSTrond Myklebust fl->fl_type = F_RDLCK; 4963911d1aafSTrond Myklebust fl->fl_pid = 0; 4964911d1aafSTrond Myklebust } 4965babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */ 4966babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */ 4967babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */ 4968c0eae66eSBenny Halevy if (likely(p)) 49691da177e4SLinus Torvalds return -NFS4ERR_DENIED; 4970c0eae66eSBenny Halevy out_overflow: 4971c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 4972c0eae66eSBenny Halevy return -EIO; 49731da177e4SLinus Torvalds } 49741da177e4SLinus Torvalds 4975911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res) 49761da177e4SLinus Torvalds { 49771da177e4SLinus Torvalds int status; 49781da177e4SLinus Torvalds 49791da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK); 4980c1d51931STrond Myklebust if (status == -EIO) 4981c1d51931STrond Myklebust goto out; 49821da177e4SLinus Torvalds if (status == 0) { 498393b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 498407d30434SBenny Halevy if (unlikely(status)) 498507d30434SBenny Halevy goto out; 49861da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED) 4987c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL); 4988c1d51931STrond Myklebust if (res->open_seqid != NULL) 4989c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid); 4990c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid); 4991c1d51931STrond Myklebust out: 49921da177e4SLinus Torvalds return status; 49931da177e4SLinus Torvalds } 49941da177e4SLinus Torvalds 4995911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res) 49961da177e4SLinus Torvalds { 49971da177e4SLinus Torvalds int status; 49981da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT); 49991da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED) 5000911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied); 50011da177e4SLinus Torvalds return status; 50021da177e4SLinus Torvalds } 50031da177e4SLinus Torvalds 5004911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res) 50051da177e4SLinus Torvalds { 50061da177e4SLinus Torvalds int status; 50071da177e4SLinus Torvalds 50081da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU); 5009c1d51931STrond Myklebust if (status != -EIO) 5010c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid); 501107d30434SBenny Halevy if (status == 0) 501293b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid); 50131da177e4SLinus Torvalds return status; 50141da177e4SLinus Torvalds } 50151da177e4SLinus Torvalds 5016d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr) 5017d3c7b7ccSTrond Myklebust { 5018d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5019d3c7b7ccSTrond Myklebust } 5020d3c7b7ccSTrond Myklebust 50211da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr) 50221da177e4SLinus Torvalds { 50231da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP); 50241da177e4SLinus Torvalds } 50251da177e4SLinus Torvalds 50261da177e4SLinus Torvalds /* This is too sick! */ 50277d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr, 50287d160a6cSTrond Myklebust unsigned long *pagemod_limit) 50291da177e4SLinus Torvalds { 50308687b63aSAl Viro __be32 *p; 50311da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize; 50327d160a6cSTrond Myklebust u64 maxsize = 0; 50331da177e4SLinus Torvalds 5034c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5035c0eae66eSBenny Halevy if (unlikely(!p)) 5036c0eae66eSBenny Halevy goto out_overflow; 50376f723f77SBenny Halevy limit_type = be32_to_cpup(p++); 50381da177e4SLinus Torvalds switch (limit_type) { 50397d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE: 50407d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize); 50411da177e4SLinus Torvalds break; 50427d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS: 50436f723f77SBenny Halevy nblocks = be32_to_cpup(p++); 5044cccddf4fSBenny Halevy blocksize = be32_to_cpup(p); 50457d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize; 50461da177e4SLinus Torvalds } 504709cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT; 50487d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX); 50491da177e4SLinus Torvalds return 0; 5050c0eae66eSBenny Halevy out_overflow: 5051c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5052c0eae66eSBenny Halevy return -EIO; 50531da177e4SLinus Torvalds } 50541da177e4SLinus Torvalds 50556ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr, 50566ae37339STrond Myklebust uint32_t delegation_type, 50576ae37339STrond Myklebust struct nfs_openres *res) 50581da177e4SLinus Torvalds { 50598687b63aSAl Viro __be32 *p; 506007d30434SBenny Halevy int status; 50611da177e4SLinus Torvalds 506293b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation); 506307d30434SBenny Halevy if (unlikely(status)) 506407d30434SBenny Halevy return status; 5065c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5066c0eae66eSBenny Halevy if (unlikely(!p)) 5067c0eae66eSBenny Halevy goto out_overflow; 5068cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p); 506905d564feSAndy Adamson 50701da177e4SLinus Torvalds switch (delegation_type) { 50711da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ: 50721da177e4SLinus Torvalds res->delegation_type = FMODE_READ; 50731da177e4SLinus Torvalds break; 50741da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE: 50751da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ; 50767d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0) 50771da177e4SLinus Torvalds return -EIO; 50781da177e4SLinus Torvalds } 50797539bbabSDavid Howells return decode_ace(xdr, NULL, res->server->nfs_client); 5080c0eae66eSBenny Halevy out_overflow: 5081c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5082c0eae66eSBenny Halevy return -EIO; 50831da177e4SLinus Torvalds } 50841da177e4SLinus Torvalds 50856ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 50866ae37339STrond Myklebust { 50876ae37339STrond Myklebust __be32 *p; 50886ae37339STrond Myklebust uint32_t why_no_delegation; 50896ae37339STrond Myklebust 50906ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 50916ae37339STrond Myklebust if (unlikely(!p)) 50926ae37339STrond Myklebust goto out_overflow; 50936ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p); 50946ae37339STrond Myklebust switch (why_no_delegation) { 50956ae37339STrond Myklebust case WND4_CONTENTION: 50966ae37339STrond Myklebust case WND4_RESOURCE: 50976ae37339STrond Myklebust xdr_inline_decode(xdr, 4); 50986ae37339STrond Myklebust /* Ignore for now */ 50996ae37339STrond Myklebust } 51006ae37339STrond Myklebust return 0; 51016ae37339STrond Myklebust out_overflow: 51026ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51036ae37339STrond Myklebust return -EIO; 51046ae37339STrond Myklebust } 51056ae37339STrond Myklebust 51066ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) 51076ae37339STrond Myklebust { 51086ae37339STrond Myklebust __be32 *p; 51096ae37339STrond Myklebust uint32_t delegation_type; 51106ae37339STrond Myklebust 51116ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4); 51126ae37339STrond Myklebust if (unlikely(!p)) 51136ae37339STrond Myklebust goto out_overflow; 51146ae37339STrond Myklebust delegation_type = be32_to_cpup(p); 51156ae37339STrond Myklebust res->delegation_type = 0; 51166ae37339STrond Myklebust switch (delegation_type) { 51176ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE: 51186ae37339STrond Myklebust return 0; 51196ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ: 51206ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE: 51216ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res); 51226ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT: 51236ae37339STrond Myklebust return decode_no_delegation(xdr, res); 51246ae37339STrond Myklebust } 51256ae37339STrond Myklebust return -EIO; 51266ae37339STrond Myklebust out_overflow: 51276ae37339STrond Myklebust print_overflow_msg(__func__, xdr); 51286ae37339STrond Myklebust return -EIO; 51296ae37339STrond Myklebust } 51306ae37339STrond Myklebust 51311da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) 51321da177e4SLinus Torvalds { 51338687b63aSAl Viro __be32 *p; 5134aa53ed54SJeff Layton uint32_t savewords, bmlen, i; 51351da177e4SLinus Torvalds int status; 51361da177e4SLinus Torvalds 5137c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status)) 5138c7848f69STrond Myklebust return status; 5139c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 5140c7848f69STrond Myklebust if (status) 5141c7848f69STrond Myklebust return status; 514293b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 514307d30434SBenny Halevy if (unlikely(status)) 51441da177e4SLinus Torvalds return status; 51451da177e4SLinus Torvalds 51461da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo); 51471da177e4SLinus Torvalds 5148c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5149c0eae66eSBenny Halevy if (unlikely(!p)) 5150c0eae66eSBenny Halevy goto out_overflow; 51516f723f77SBenny Halevy res->rflags = be32_to_cpup(p++); 5152cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 51531da177e4SLinus Torvalds if (bmlen > 10) 51541da177e4SLinus Torvalds goto xdr_error; 51551da177e4SLinus Torvalds 5156c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5157c0eae66eSBenny Halevy if (unlikely(!p)) 5158c0eae66eSBenny Halevy goto out_overflow; 5159aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE); 5160aa53ed54SJeff Layton for (i = 0; i < savewords; ++i) 51616f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++); 5162aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++) 5163aa53ed54SJeff Layton res->attrset[i] = 0; 5164aa53ed54SJeff Layton 51651da177e4SLinus Torvalds return decode_delegation(xdr, res); 51661da177e4SLinus Torvalds xdr_error: 51673110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen); 51681da177e4SLinus Torvalds return -EIO; 5169c0eae66eSBenny Halevy out_overflow: 5170c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5171c0eae66eSBenny Halevy return -EIO; 51721da177e4SLinus Torvalds } 51731da177e4SLinus Torvalds 51741da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res) 51751da177e4SLinus Torvalds { 51761da177e4SLinus Torvalds int status; 51771da177e4SLinus Torvalds 51781da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 5179c1d51931STrond Myklebust if (status != -EIO) 5180c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 518107d30434SBenny Halevy if (!status) 518293b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 51831da177e4SLinus Torvalds return status; 51841da177e4SLinus Torvalds } 51851da177e4SLinus Torvalds 51861da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res) 51871da177e4SLinus Torvalds { 51881da177e4SLinus Torvalds int status; 51891da177e4SLinus Torvalds 51901da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 5191c1d51931STrond Myklebust if (status != -EIO) 5192c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid); 519307d30434SBenny Halevy if (!status) 519493b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid); 51951da177e4SLinus Torvalds return status; 51961da177e4SLinus Torvalds } 51971da177e4SLinus Torvalds 51981da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr) 51991da177e4SLinus Torvalds { 52001da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH); 52011da177e4SLinus Torvalds } 52021da177e4SLinus Torvalds 52031da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr) 52041da177e4SLinus Torvalds { 52051da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH); 52061da177e4SLinus Torvalds } 52071da177e4SLinus Torvalds 52089137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, 52099137bdf3SAnna Schumaker struct nfs_pgio_res *res) 52101da177e4SLinus Torvalds { 52118687b63aSAl Viro __be32 *p; 521264bd577eSTrond Myklebust uint32_t count, eof, recvd; 52131da177e4SLinus Torvalds int status; 52141da177e4SLinus Torvalds 52151da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ); 52161da177e4SLinus Torvalds if (status) 52171da177e4SLinus Torvalds return status; 5218c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5219c0eae66eSBenny Halevy if (unlikely(!p)) 5220c0eae66eSBenny Halevy goto out_overflow; 52216f723f77SBenny Halevy eof = be32_to_cpup(p++); 5222cccddf4fSBenny Halevy count = be32_to_cpup(p); 522364bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count); 52241da177e4SLinus Torvalds if (count > recvd) { 5225fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: " 52261da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd); 52271da177e4SLinus Torvalds count = recvd; 52281da177e4SLinus Torvalds eof = 0; 52291da177e4SLinus Torvalds } 52301da177e4SLinus Torvalds res->eof = eof; 52311da177e4SLinus Torvalds res->count = count; 52321da177e4SLinus Torvalds return 0; 5233c0eae66eSBenny Halevy out_overflow: 5234c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5235c0eae66eSBenny Halevy return -EIO; 52361da177e4SLinus Torvalds } 52371da177e4SLinus Torvalds 52381da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir) 52391da177e4SLinus Torvalds { 5240bcecff77SChuck Lever int status; 5241cd93710eSChuck Lever __be32 verf[2]; 52421da177e4SLinus Torvalds 52431da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR); 5244db942bbdSBenny Halevy if (!status) 5245db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data); 5246db942bbdSBenny Halevy if (unlikely(status)) 52471da177e4SLinus Torvalds return status; 5248cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf)); 524944109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n", 5250cd93710eSChuck Lever __func__, verf[0], verf[1]); 525164bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len); 52521da177e4SLinus Torvalds } 52531da177e4SLinus Torvalds 52541da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 52551da177e4SLinus Torvalds { 52561da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 5257bcecff77SChuck Lever u32 len, recvd; 52588687b63aSAl Viro __be32 *p; 52591da177e4SLinus Torvalds int status; 52601da177e4SLinus Torvalds 52611da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK); 52621da177e4SLinus Torvalds if (status) 52631da177e4SLinus Torvalds return status; 52641da177e4SLinus Torvalds 52651da177e4SLinus Torvalds /* Convert length of symlink */ 5266c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5267c0eae66eSBenny Halevy if (unlikely(!p)) 5268c0eae66eSBenny Halevy goto out_overflow; 5269cccddf4fSBenny Halevy len = be32_to_cpup(p); 52701da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) { 5271fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n"); 52721da177e4SLinus Torvalds return -ENAMETOOLONG; 52731da177e4SLinus Torvalds } 527464bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len); 52751da177e4SLinus Torvalds if (recvd < len) { 5276fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: " 52771da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd); 52781da177e4SLinus Torvalds return -EIO; 52791da177e4SLinus Torvalds } 52801da177e4SLinus Torvalds /* 52811da177e4SLinus Torvalds * The XDR encode routine has set things up so that 52821da177e4SLinus Torvalds * the link text will be copied directly into the 52831da177e4SLinus Torvalds * buffer. We just have to do overflow-checking, 52841da177e4SLinus Torvalds * and and null-terminate the text (the VFS expects 52851da177e4SLinus Torvalds * null-termination). 52861da177e4SLinus Torvalds */ 5287b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len); 52881da177e4SLinus Torvalds return 0; 5289c0eae66eSBenny Halevy out_overflow: 5290c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5291c0eae66eSBenny Halevy return -EIO; 52921da177e4SLinus Torvalds } 52931da177e4SLinus Torvalds 52941da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) 52951da177e4SLinus Torvalds { 52961da177e4SLinus Torvalds int status; 52971da177e4SLinus Torvalds 52981da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE); 52991da177e4SLinus Torvalds if (status) 53001da177e4SLinus Torvalds goto out; 53011da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo); 53021da177e4SLinus Torvalds out: 53031da177e4SLinus Torvalds return status; 53041da177e4SLinus Torvalds } 53051da177e4SLinus Torvalds 53061da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo, 53071da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo) 53081da177e4SLinus Torvalds { 53091da177e4SLinus Torvalds int status; 53101da177e4SLinus Torvalds 53111da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME); 53121da177e4SLinus Torvalds if (status) 53131da177e4SLinus Torvalds goto out; 53141da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo))) 53151da177e4SLinus Torvalds goto out; 53161da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo); 53171da177e4SLinus Torvalds out: 53181da177e4SLinus Torvalds return status; 53191da177e4SLinus Torvalds } 53201da177e4SLinus Torvalds 53211da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr) 53221da177e4SLinus Torvalds { 53231da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW); 53241da177e4SLinus Torvalds } 53251da177e4SLinus Torvalds 532656ae19f3STrond Myklebust static int 532756ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr) 532856ae19f3STrond Myklebust { 532956ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH); 533056ae19f3STrond Myklebust } 533156ae19f3STrond Myklebust 5332029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req, 5333bf118a34SAndy Adamson struct nfs_getaclres *res) 5334029d105eSJ. Bruce Fields { 5335256e48bbSTrond Myklebust unsigned int savep; 5336029d105eSJ. Bruce Fields uint32_t attrlen, 5337dae100c2SFred Isaman bitmap[3] = {0}; 5338029d105eSJ. Bruce Fields int status; 5339cff298c7STrond Myklebust unsigned int pg_offset; 5340029d105eSJ. Bruce Fields 5341bf118a34SAndy Adamson res->acl_len = 0; 5342029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) 5343029d105eSJ. Bruce Fields goto out; 53445a006899SSachin Prabhu 5345519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len); 5346519d3959STrond Myklebust 5347cff298c7STrond Myklebust /* Calculate the offset of the page data */ 5348cff298c7STrond Myklebust pg_offset = xdr->buf->head[0].iov_len; 53495a006899SSachin Prabhu 5350029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0) 5351029d105eSJ. Bruce Fields goto out; 5352029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0) 5353029d105eSJ. Bruce Fields goto out; 5354029d105eSJ. Bruce Fields 5355029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U))) 5356029d105eSJ. Bruce Fields return -EIO; 5357029d105eSJ. Bruce Fields if (likely(bitmap[0] & FATTR4_WORD0_ACL)) { 5358029d105eSJ. Bruce Fields 5359bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words 5360bf118a34SAndy Adamson * are stored with the acl data to handle the problem of 5361bf118a34SAndy Adamson * variable length bitmaps.*/ 5362cff298c7STrond Myklebust res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5363519d3959STrond Myklebust res->acl_len = attrlen; 53641f1ea6c2STrond Myklebust 53651f1ea6c2STrond Myklebust /* Check for receive buffer overflow */ 53661f1ea6c2STrond Myklebust if (res->acl_len > (xdr->nwords << 2) || 53671f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) { 53681f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC; 5369519d3959STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5370cff298c7STrond Myklebust attrlen, xdr->nwords << 2); 5371029d105eSJ. Bruce Fields } 53728c233cf9SJ. Bruce Fields } else 53738c233cf9SJ. Bruce Fields status = -EOPNOTSUPP; 5374029d105eSJ. Bruce Fields 5375029d105eSJ. Bruce Fields out: 5376029d105eSJ. Bruce Fields return status; 5377029d105eSJ. Bruce Fields } 5378029d105eSJ. Bruce Fields 53791da177e4SLinus Torvalds static int 53801da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr) 53811da177e4SLinus Torvalds { 53821da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH); 53831da177e4SLinus Torvalds } 53841da177e4SLinus Torvalds 53859e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr) 53861da177e4SLinus Torvalds { 53878687b63aSAl Viro __be32 *p; 53881da177e4SLinus Torvalds uint32_t bmlen; 53891da177e4SLinus Torvalds int status; 53901da177e4SLinus Torvalds 53911da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR); 53921da177e4SLinus Torvalds if (status) 53931da177e4SLinus Torvalds return status; 5394c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5395c0eae66eSBenny Halevy if (unlikely(!p)) 5396c0eae66eSBenny Halevy goto out_overflow; 5397cccddf4fSBenny Halevy bmlen = be32_to_cpup(p); 5398c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2); 5399c0eae66eSBenny Halevy if (likely(p)) 54001da177e4SLinus Torvalds return 0; 5401c0eae66eSBenny Halevy out_overflow: 5402c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5403c0eae66eSBenny Halevy return -EIO; 54041da177e4SLinus Torvalds } 54051da177e4SLinus Torvalds 5406bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res) 54071da177e4SLinus Torvalds { 54088687b63aSAl Viro __be32 *p; 54091da177e4SLinus Torvalds uint32_t opnum; 54101da177e4SLinus Torvalds int32_t nfserr; 54111da177e4SLinus Torvalds 5412c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5413c0eae66eSBenny Halevy if (unlikely(!p)) 5414c0eae66eSBenny Halevy goto out_overflow; 54156f723f77SBenny Halevy opnum = be32_to_cpup(p++); 54161da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) { 5417fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation" 54181da177e4SLinus Torvalds " %d\n", opnum); 54191da177e4SLinus Torvalds return -EIO; 54201da177e4SLinus Torvalds } 5421cccddf4fSBenny Halevy nfserr = be32_to_cpup(p); 54221da177e4SLinus Torvalds if (nfserr == NFS_OK) { 5423c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE); 5424c0eae66eSBenny Halevy if (unlikely(!p)) 5425c0eae66eSBenny Halevy goto out_overflow; 5426bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid); 5427bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE); 54281da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) { 54291da177e4SLinus Torvalds uint32_t len; 54301da177e4SLinus Torvalds 54311da177e4SLinus Torvalds /* skip netid string */ 5432c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5433c0eae66eSBenny Halevy if (unlikely(!p)) 5434c0eae66eSBenny Halevy goto out_overflow; 5435cccddf4fSBenny Halevy len = be32_to_cpup(p); 5436c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5437c0eae66eSBenny Halevy if (unlikely(!p)) 5438c0eae66eSBenny Halevy goto out_overflow; 54391da177e4SLinus Torvalds 54401da177e4SLinus Torvalds /* skip uaddr string */ 5441c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); 5442c0eae66eSBenny Halevy if (unlikely(!p)) 5443c0eae66eSBenny Halevy goto out_overflow; 5444cccddf4fSBenny Halevy len = be32_to_cpup(p); 5445c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len); 5446c0eae66eSBenny Halevy if (unlikely(!p)) 5447c0eae66eSBenny Halevy goto out_overflow; 54481da177e4SLinus Torvalds return -NFSERR_CLID_INUSE; 54491da177e4SLinus Torvalds } else 5450856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr); 54511da177e4SLinus Torvalds 54521da177e4SLinus Torvalds return 0; 5453c0eae66eSBenny Halevy out_overflow: 5454c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5455c0eae66eSBenny Halevy return -EIO; 54561da177e4SLinus Torvalds } 54571da177e4SLinus Torvalds 54581da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr) 54591da177e4SLinus Torvalds { 54601da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM); 54611da177e4SLinus Torvalds } 54621da177e4SLinus Torvalds 54639137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res) 54641da177e4SLinus Torvalds { 54658687b63aSAl Viro __be32 *p; 54661da177e4SLinus Torvalds int status; 54671da177e4SLinus Torvalds 54681da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE); 54691da177e4SLinus Torvalds if (status) 54701da177e4SLinus Torvalds return status; 54711da177e4SLinus Torvalds 54722f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8); 5473c0eae66eSBenny Halevy if (unlikely(!p)) 5474c0eae66eSBenny Halevy goto out_overflow; 54756f723f77SBenny Halevy res->count = be32_to_cpup(p++); 54766f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++); 54772f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier); 5478c0eae66eSBenny Halevy out_overflow: 5479c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5480c0eae66eSBenny Halevy return -EIO; 54811da177e4SLinus Torvalds } 54821da177e4SLinus Torvalds 54831da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr) 54841da177e4SLinus Torvalds { 54851da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN); 54861da177e4SLinus Torvalds } 54871da177e4SLinus Torvalds 5488fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr, 5489fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor) 54905a5ea0d4SBryan Schumaker { 5491fb15b26fSChuck Lever u32 oid_len; 54925a5ea0d4SBryan Schumaker __be32 *p; 54935a5ea0d4SBryan Schumaker 54945a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 54955a5ea0d4SBryan Schumaker if (unlikely(!p)) 54965a5ea0d4SBryan Schumaker goto out_overflow; 5497fb15b26fSChuck Lever oid_len = be32_to_cpup(p); 5498fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN) 54995a5ea0d4SBryan Schumaker goto out_err; 55005a5ea0d4SBryan Schumaker 5501fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len); 55025a5ea0d4SBryan Schumaker if (unlikely(!p)) 55035a5ea0d4SBryan Schumaker goto out_overflow; 5504fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len); 5505fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len; 55065a5ea0d4SBryan Schumaker 55075a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8); 55085a5ea0d4SBryan Schumaker if (unlikely(!p)) 55095a5ea0d4SBryan Schumaker goto out_overflow; 5510fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++); 5511fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p); 55125a5ea0d4SBryan Schumaker 55135a5ea0d4SBryan Schumaker return 0; 55145a5ea0d4SBryan Schumaker 55155a5ea0d4SBryan Schumaker out_overflow: 55165a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55175a5ea0d4SBryan Schumaker return -EIO; 55185a5ea0d4SBryan Schumaker out_err: 55195a5ea0d4SBryan Schumaker return -EINVAL; 55205a5ea0d4SBryan Schumaker } 55215a5ea0d4SBryan Schumaker 552231e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 55235a5ea0d4SBryan Schumaker { 5524fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor; 5525fb15b26fSChuck Lever unsigned int i, num_flavors; 55265a5ea0d4SBryan Schumaker int status; 55275a5ea0d4SBryan Schumaker __be32 *p; 55285a5ea0d4SBryan Schumaker 55295a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55305a5ea0d4SBryan Schumaker if (unlikely(!p)) 55315a5ea0d4SBryan Schumaker goto out_overflow; 55325a5ea0d4SBryan Schumaker 5533c3dfc280SBryan Schumaker res->flavors->num_flavors = 0; 5534c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p); 5535c3dfc280SBryan Schumaker 5536c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) { 55375a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i]; 5538c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE) 55395a5ea0d4SBryan Schumaker break; 55405a5ea0d4SBryan Schumaker 55415a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4); 55425a5ea0d4SBryan Schumaker if (unlikely(!p)) 55435a5ea0d4SBryan Schumaker goto out_overflow; 55445a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p); 55455a5ea0d4SBryan Schumaker 55465a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) { 5547613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor); 5548613e901eSBryan Schumaker if (status) 5549613e901eSBryan Schumaker goto out; 55505a5ea0d4SBryan Schumaker } 5551c3dfc280SBryan Schumaker res->flavors->num_flavors++; 55525a5ea0d4SBryan Schumaker } 55535a5ea0d4SBryan Schumaker 555431e4dda4SBryan Schumaker status = 0; 5555613e901eSBryan Schumaker out: 5556613e901eSBryan Schumaker return status; 55575a5ea0d4SBryan Schumaker out_overflow: 55585a5ea0d4SBryan Schumaker print_overflow_msg(__func__, xdr); 55595a5ea0d4SBryan Schumaker return -EIO; 55605a5ea0d4SBryan Schumaker } 55615a5ea0d4SBryan Schumaker 556231e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 556331e4dda4SBryan Schumaker { 556431e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO); 556531e4dda4SBryan Schumaker if (status) 556631e4dda4SBryan Schumaker return status; 556731e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 556831e4dda4SBryan Schumaker } 556931e4dda4SBryan Schumaker 557099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 557131e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 557231e4dda4SBryan Schumaker { 557331e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); 557431e4dda4SBryan Schumaker if (status) 557531e4dda4SBryan Schumaker return status; 557631e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res); 557731e4dda4SBryan Schumaker } 557831e4dda4SBryan Schumaker 55792031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map) 55802031cd1aSWeston Andros Adamson { 55812031cd1aSWeston Andros Adamson __be32 *p; 55822031cd1aSWeston Andros Adamson uint32_t bitmap_words; 55832031cd1aSWeston Andros Adamson unsigned int i; 55842031cd1aSWeston Andros Adamson 55852031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 55862031cd1aSWeston Andros Adamson bitmap_words = be32_to_cpup(p++); 55872031cd1aSWeston Andros Adamson if (bitmap_words > NFS4_OP_MAP_NUM_WORDS) 55882031cd1aSWeston Andros Adamson return -EIO; 55892031cd1aSWeston Andros Adamson p = xdr_inline_decode(xdr, 4 * bitmap_words); 55902031cd1aSWeston Andros Adamson for (i = 0; i < bitmap_words; i++) 55912031cd1aSWeston Andros Adamson op_map->u.words[i] = be32_to_cpup(p++); 55922031cd1aSWeston Andros Adamson 55932031cd1aSWeston Andros Adamson return 0; 55942031cd1aSWeston Andros Adamson } 55952031cd1aSWeston Andros Adamson 559699fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr, 559799fe60d0SBenny Halevy struct nfs41_exchange_id_res *res) 559899fe60d0SBenny Halevy { 559999fe60d0SBenny Halevy __be32 *p; 560099fe60d0SBenny Halevy uint32_t dummy; 56012460ba57SBenny Halevy char *dummy_str; 560299fe60d0SBenny Halevy int status; 56037d2ed9acSWeston Andros Adamson uint32_t impl_id_count; 560499fe60d0SBenny Halevy 560599fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 560699fe60d0SBenny Halevy if (status) 560799fe60d0SBenny Halevy return status; 560899fe60d0SBenny Halevy 5609c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5610c0eae66eSBenny Halevy if (unlikely(!p)) 5611c0eae66eSBenny Halevy goto out_overflow; 561232b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid); 5613c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12); 5614c0eae66eSBenny Halevy if (unlikely(!p)) 5615c0eae66eSBenny Halevy goto out_overflow; 561632b01310STrond Myklebust res->seqid = be32_to_cpup(p++); 561732b01310STrond Myklebust res->flags = be32_to_cpup(p++); 561899fe60d0SBenny Halevy 56192031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p); 56202031cd1aSWeston Andros Adamson switch (res->state_protect.how) { 56212031cd1aSWeston Andros Adamson case SP4_NONE: 56222031cd1aSWeston Andros Adamson break; 56232031cd1aSWeston Andros Adamson case SP4_MACH_CRED: 56242031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce); 56252031cd1aSWeston Andros Adamson if (status) 56262031cd1aSWeston Andros Adamson return status; 56272031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow); 56282031cd1aSWeston Andros Adamson if (status) 56292031cd1aSWeston Andros Adamson return status; 56302031cd1aSWeston Andros Adamson break; 56312031cd1aSWeston Andros Adamson default: 56322031cd1aSWeston Andros Adamson WARN_ON_ONCE(1); 563399fe60d0SBenny Halevy return -EIO; 56342031cd1aSWeston Andros Adamson } 563599fe60d0SBenny Halevy 5636acdeb69dSChuck Lever /* server_owner4.so_minor_id */ 5637c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5638c0eae66eSBenny Halevy if (unlikely(!p)) 5639c0eae66eSBenny Halevy goto out_overflow; 5640acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id); 564199fe60d0SBenny Halevy 5642acdeb69dSChuck Lever /* server_owner4.so_major_id */ 56432460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56442460ba57SBenny Halevy if (unlikely(status)) 56452460ba57SBenny Halevy return status; 564678fe0f41SWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 564778fe0f41SWeston Andros Adamson return -EIO; 5648acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy); 5649acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy; 565078fe0f41SWeston Andros Adamson 5651acdeb69dSChuck Lever /* server_scope4 */ 5652acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5653acdeb69dSChuck Lever if (unlikely(status)) 5654acdeb69dSChuck Lever return status; 5655acdeb69dSChuck Lever if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 5656acdeb69dSChuck Lever return -EIO; 565778fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy); 565878fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy; 565978fe0f41SWeston Andros Adamson 56607d2ed9acSWeston Andros Adamson /* Implementation Id */ 56617d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4); 56627d2ed9acSWeston Andros Adamson if (unlikely(!p)) 56637d2ed9acSWeston Andros Adamson goto out_overflow; 56647d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++); 56657d2ed9acSWeston Andros Adamson 56667d2ed9acSWeston Andros Adamson if (impl_id_count) { 56677d2ed9acSWeston Andros Adamson /* nii_domain */ 56682460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56692460ba57SBenny Halevy if (unlikely(status)) 56702460ba57SBenny Halevy return status; 56717d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 56727d2ed9acSWeston Andros Adamson return -EIO; 56737d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy); 567499fe60d0SBenny Halevy 56757d2ed9acSWeston Andros Adamson /* nii_name */ 56767d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str); 56777d2ed9acSWeston Andros Adamson if (unlikely(status)) 56787d2ed9acSWeston Andros Adamson return status; 56797d2ed9acSWeston Andros Adamson if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) 56807d2ed9acSWeston Andros Adamson return -EIO; 56817d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy); 56827d2ed9acSWeston Andros Adamson 56837d2ed9acSWeston Andros Adamson /* nii_date */ 56847d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12); 56857d2ed9acSWeston Andros Adamson if (unlikely(!p)) 56867d2ed9acSWeston Andros Adamson goto out_overflow; 56877d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds); 56887d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p); 56897d2ed9acSWeston Andros Adamson 56907d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */ 56917d2ed9acSWeston Andros Adamson } 569299fe60d0SBenny Halevy return 0; 5693c0eae66eSBenny Halevy out_overflow: 5694c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5695c0eae66eSBenny Halevy return -EIO; 569699fe60d0SBenny Halevy } 5697fc931582SAndy Adamson 5698fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr, 5699fc931582SAndy Adamson struct nfs4_channel_attrs *attrs) 5700fc931582SAndy Adamson { 5701fc931582SAndy Adamson __be32 *p; 5702c9c30dd5SBenny Halevy u32 nr_attrs, val; 5703fc931582SAndy Adamson 5704c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28); 5705c0eae66eSBenny Halevy if (unlikely(!p)) 5706c0eae66eSBenny Halevy goto out_overflow; 5707c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */ 5708c9c30dd5SBenny Halevy if (val) 5709c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */ 57106f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++); 57116f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++); 57126f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++); 57136f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++); 57146f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++); 5715cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p); 5716fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) { 5717a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs " 5718a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs); 5719fc931582SAndy Adamson return -EINVAL; 5720fc931582SAndy Adamson } 5721c0eae66eSBenny Halevy if (nr_attrs == 1) { 5722c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */ 5723c0eae66eSBenny Halevy if (unlikely(!p)) 5724c0eae66eSBenny Halevy goto out_overflow; 5725c0eae66eSBenny Halevy } 5726fc931582SAndy Adamson return 0; 5727c0eae66eSBenny Halevy out_overflow: 5728c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5729c0eae66eSBenny Halevy return -EIO; 5730fc931582SAndy Adamson } 5731fc931582SAndy Adamson 5732e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) 5733e78291e4SBenny Halevy { 5734e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); 5735fc931582SAndy Adamson } 5736fc931582SAndy Adamson 57377c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr, 57387c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res) 57397c44f1aeSWeston Andros Adamson { 57407c44f1aeSWeston Andros Adamson __be32 *p; 57417c44f1aeSWeston Andros Adamson int status; 57427c44f1aeSWeston Andros Adamson 57437c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION); 57447c44f1aeSWeston Andros Adamson if (!status) 574571a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 57467c44f1aeSWeston Andros Adamson if (unlikely(status)) 57477c44f1aeSWeston Andros Adamson return status; 57487c44f1aeSWeston Andros Adamson 57497c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */ 57507c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8); 57517c44f1aeSWeston Andros Adamson if (unlikely(!p)) 57527c44f1aeSWeston Andros Adamson goto out_overflow; 57537c44f1aeSWeston Andros Adamson 57547c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++); 57557c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH) 57567c44f1aeSWeston Andros Adamson return -EIO; 57577c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0) 57587c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false; 57597c44f1aeSWeston Andros Adamson else 57607c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true; 57617c44f1aeSWeston Andros Adamson 57627c44f1aeSWeston Andros Adamson return 0; 57637c44f1aeSWeston Andros Adamson out_overflow: 57647c44f1aeSWeston Andros Adamson print_overflow_msg(__func__, xdr); 57657c44f1aeSWeston Andros Adamson return -EIO; 57667c44f1aeSWeston Andros Adamson } 57677c44f1aeSWeston Andros Adamson 5768fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr, 5769fc931582SAndy Adamson struct nfs41_create_session_res *res) 5770fc931582SAndy Adamson { 5771fc931582SAndy Adamson __be32 *p; 5772fc931582SAndy Adamson int status; 5773fc931582SAndy Adamson 5774fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION); 5775e78291e4SBenny Halevy if (!status) 577679969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid); 5777e78291e4SBenny Halevy if (unlikely(status)) 5778fc931582SAndy Adamson return status; 5779fc931582SAndy Adamson 5780fc931582SAndy Adamson /* seqid, flags */ 5781c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8); 5782c0eae66eSBenny Halevy if (unlikely(!p)) 5783c0eae66eSBenny Halevy goto out_overflow; 578479969dd1STrond Myklebust res->seqid = be32_to_cpup(p++); 578579969dd1STrond Myklebust res->flags = be32_to_cpup(p); 5786fc931582SAndy Adamson 5787fc931582SAndy Adamson /* Channel attributes */ 578879969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs); 5789fc931582SAndy Adamson if (!status) 579079969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs); 5791fc931582SAndy Adamson return status; 5792c0eae66eSBenny Halevy out_overflow: 5793c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5794c0eae66eSBenny Halevy return -EIO; 5795fc931582SAndy Adamson } 57960f3e66c6SAndy Adamson 57970f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy) 57980f3e66c6SAndy Adamson { 57990f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION); 58000f3e66c6SAndy Adamson } 580118019753SRicardo Labiaga 580266245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy) 580366245539STrond Myklebust { 580466245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID); 580566245539STrond Myklebust } 580666245539STrond Myklebust 580718019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy) 580818019753SRicardo Labiaga { 580918019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 581018019753SRicardo Labiaga } 581199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 581299fe60d0SBenny Halevy 58139b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr, 58149b7b9fccSAndy Adamson struct nfs4_sequence_res *res, 58159b7b9fccSAndy Adamson struct rpc_rqst *rqstp) 58169b7b9fccSAndy Adamson { 58179b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1) 5818e3725ec0STrond Myklebust struct nfs4_session *session; 5819fc01cea9SAndy Adamson struct nfs4_sessionid id; 5820fc01cea9SAndy Adamson u32 dummy; 5821fc01cea9SAndy Adamson int status; 5822fc01cea9SAndy Adamson __be32 *p; 5823fc01cea9SAndy Adamson 5824e3725ec0STrond Myklebust if (res->sr_slot == NULL) 58259b7b9fccSAndy Adamson return 0; 58263bd2384aSChuck Lever if (!res->sr_slot->table->session) 58273bd2384aSChuck Lever return 0; 58289b7b9fccSAndy Adamson 5829fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE); 5830e78291e4SBenny Halevy if (!status) 5831e78291e4SBenny Halevy status = decode_sessionid(xdr, &id); 5832e78291e4SBenny Halevy if (unlikely(status)) 5833fc01cea9SAndy Adamson goto out_err; 58349b7b9fccSAndy Adamson 5835fc01cea9SAndy Adamson /* 5836fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or 5837fc01cea9SAndy Adamson * sequence number, the server is looney tunes. 5838fc01cea9SAndy Adamson */ 5839fdcb4577STrond Myklebust status = -EREMOTEIO; 5840e3725ec0STrond Myklebust session = res->sr_slot->table->session; 5841fc01cea9SAndy Adamson 5842e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data, 5843fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) { 5844fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__); 5845fc01cea9SAndy Adamson goto out_err; 5846fc01cea9SAndy Adamson } 5847e78291e4SBenny Halevy 5848c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20); 5849c0eae66eSBenny Halevy if (unlikely(!p)) 5850c0eae66eSBenny Halevy goto out_overflow; 5851e78291e4SBenny Halevy 5852fc01cea9SAndy Adamson /* seqid */ 58536f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5854dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) { 5855fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__); 5856fc01cea9SAndy Adamson goto out_err; 5857fc01cea9SAndy Adamson } 5858fc01cea9SAndy Adamson /* slot id */ 58596f723f77SBenny Halevy dummy = be32_to_cpup(p++); 5860df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) { 5861fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__); 5862fc01cea9SAndy Adamson goto out_err; 5863fc01cea9SAndy Adamson } 5864da0507b7STrond Myklebust /* highest slot id */ 5865da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++); 5866464ee9f9STrond Myklebust /* target highest slot id */ 5867464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++); 58680629e370SAlexandros Batsakis /* result flags */ 58690629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p); 5870fc01cea9SAndy Adamson status = 0; 5871fc01cea9SAndy Adamson out_err: 5872fc01cea9SAndy Adamson res->sr_status = status; 5873fc01cea9SAndy Adamson return status; 5874c0eae66eSBenny Halevy out_overflow: 5875c0eae66eSBenny Halevy print_overflow_msg(__func__, xdr); 5876c0eae66eSBenny Halevy status = -EIO; 5877c0eae66eSBenny Halevy goto out_err; 5878fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */ 58799b7b9fccSAndy Adamson return 0; 5880fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 58819b7b9fccSAndy Adamson } 58829b7b9fccSAndy Adamson 5883b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1) 588493b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 588593b717fdSTrond Myklebust { 588693b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE; 588793b717fdSTrond Myklebust return decode_stateid(xdr, stateid); 588893b717fdSTrond Myklebust } 588993b717fdSTrond Myklebust 5890b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr, 58914e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res) 5892b1f69b75SAndy Adamson { 58934e590803STrond Myklebust struct pnfs_device *pdev = res->pdev; 5894b1f69b75SAndy Adamson __be32 *p; 5895b1f69b75SAndy Adamson uint32_t len, type; 5896b1f69b75SAndy Adamson int status; 5897b1f69b75SAndy Adamson 5898b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO); 5899b1f69b75SAndy Adamson if (status) { 5900b1f69b75SAndy Adamson if (status == -ETOOSMALL) { 5901b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5902b1f69b75SAndy Adamson if (unlikely(!p)) 5903b1f69b75SAndy Adamson goto out_overflow; 5904b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 5905b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n", 5906b1f69b75SAndy Adamson __func__, pdev->mincount); 5907b1f69b75SAndy Adamson } 5908b1f69b75SAndy Adamson return status; 5909b1f69b75SAndy Adamson } 5910b1f69b75SAndy Adamson 5911b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8); 5912b1f69b75SAndy Adamson if (unlikely(!p)) 5913b1f69b75SAndy Adamson goto out_overflow; 5914b1f69b75SAndy Adamson type = be32_to_cpup(p++); 5915b1f69b75SAndy Adamson if (type != pdev->layout_type) { 5916b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n", 5917b1f69b75SAndy Adamson __func__, pdev->layout_type, type); 5918b1f69b75SAndy Adamson return -EINVAL; 5919b1f69b75SAndy Adamson } 5920b1f69b75SAndy Adamson /* 5921b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places 5922b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages) 5923b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail 5924b1f69b75SAndy Adamson */ 5925b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p); 592613fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount) 592713fe4ba1STrond Myklebust goto out_overflow; 5928b1f69b75SAndy Adamson 5929b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */ 5930b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4); 5931b1f69b75SAndy Adamson if (unlikely(!p)) 5932b1f69b75SAndy Adamson goto out_overflow; 5933b1f69b75SAndy Adamson len = be32_to_cpup(p); 5934b1f69b75SAndy Adamson if (len) { 5935ead00597SChuck Lever uint32_t i; 5936b1f69b75SAndy Adamson 5937b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len); 5938b1f69b75SAndy Adamson if (unlikely(!p)) 5939b1f69b75SAndy Adamson goto out_overflow; 594084c9dee3SChristoph Hellwig 59414e590803STrond Myklebust res->notification = be32_to_cpup(p++); 594284c9dee3SChristoph Hellwig for (i = 1; i < len; i++) { 594384c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) { 594484c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n", 5945b1f69b75SAndy Adamson __func__); 5946b1f69b75SAndy Adamson return -EIO; 5947b1f69b75SAndy Adamson } 5948b1f69b75SAndy Adamson } 5949b1f69b75SAndy Adamson } 5950b1f69b75SAndy Adamson return 0; 5951b1f69b75SAndy Adamson out_overflow: 5952b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 5953b1f69b75SAndy Adamson return -EIO; 5954b1f69b75SAndy Adamson } 5955b1f69b75SAndy Adamson 5956b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 5957b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 5958b1f69b75SAndy Adamson { 5959b1f69b75SAndy Adamson __be32 *p; 5960b1f69b75SAndy Adamson int status; 5961b1f69b75SAndy Adamson u32 layout_count; 596264bd577eSTrond Myklebust u32 recvd; 5963b1f69b75SAndy Adamson 5964b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET); 5965b1f69b75SAndy Adamson if (status) 5966b1f69b75SAndy Adamson return status; 5967ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5968b1f69b75SAndy Adamson if (unlikely(!p)) 5969b1f69b75SAndy Adamson goto out_overflow; 5970ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p); 597193b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid); 5972ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4); 5973ea9d23f5STrond Myklebust if (unlikely(!p)) 5974ea9d23f5STrond Myklebust goto out_overflow; 5975b1f69b75SAndy Adamson layout_count = be32_to_cpup(p); 5976b1f69b75SAndy Adamson if (!layout_count) { 5977b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n", 5978b1f69b75SAndy Adamson __func__); 5979b1f69b75SAndy Adamson return -EINVAL; 5980b1f69b75SAndy Adamson } 5981b1f69b75SAndy Adamson 598235124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28); 5983b1f69b75SAndy Adamson if (unlikely(!p)) 5984b1f69b75SAndy Adamson goto out_overflow; 5985b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset); 5986b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length); 5987b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++); 5988b1f69b75SAndy Adamson res->type = be32_to_cpup(p++); 598935124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p); 5990b1f69b75SAndy Adamson 5991b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", 5992b1f69b75SAndy Adamson __func__, 5993b1f69b75SAndy Adamson (unsigned long)res->range.offset, 5994b1f69b75SAndy Adamson (unsigned long)res->range.length, 5995b1f69b75SAndy Adamson res->range.iomode, 5996b1f69b75SAndy Adamson res->type, 599735124a09SWeston Andros Adamson res->layoutp->len); 5998b1f69b75SAndy Adamson 599964bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len); 600035124a09SWeston Andros Adamson if (res->layoutp->len > recvd) { 600135124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: " 600235124a09SWeston Andros Adamson "layout len %u > recvd %u\n", 600335124a09SWeston Andros Adamson res->layoutp->len, recvd); 600435124a09SWeston Andros Adamson return -EINVAL; 600535124a09SWeston Andros Adamson } 600635124a09SWeston Andros Adamson 6007b1f69b75SAndy Adamson if (layout_count > 1) { 6008b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any 6009b1f69b75SAndy Adamson * further entries are just ignored. Note that this means 6010b1f69b75SAndy Adamson * the client may see a response that is less than the 6011b1f69b75SAndy Adamson * minimum it requested. 6012b1f69b75SAndy Adamson */ 6013b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n", 6014b1f69b75SAndy Adamson __func__, layout_count); 6015b1f69b75SAndy Adamson } 6016b1f69b75SAndy Adamson 6017b1f69b75SAndy Adamson return 0; 6018b1f69b75SAndy Adamson out_overflow: 6019b1f69b75SAndy Adamson print_overflow_msg(__func__, xdr); 6020b1f69b75SAndy Adamson return -EIO; 6021b1f69b75SAndy Adamson } 6022863a3c6cSAndy Adamson 6023cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr, 6024cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 6025cbe82603SBenny Halevy { 6026cbe82603SBenny Halevy __be32 *p; 6027cbe82603SBenny Halevy int status; 6028cbe82603SBenny Halevy 6029cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN); 6030cbe82603SBenny Halevy if (status) 6031cbe82603SBenny Halevy return status; 6032cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4); 6033cbe82603SBenny Halevy if (unlikely(!p)) 6034cbe82603SBenny Halevy goto out_overflow; 6035cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p); 6036cbe82603SBenny Halevy if (res->lrs_present) 603793b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid); 6038cbe82603SBenny Halevy return status; 6039cbe82603SBenny Halevy out_overflow: 6040cbe82603SBenny Halevy print_overflow_msg(__func__, xdr); 6041cbe82603SBenny Halevy return -EIO; 6042cbe82603SBenny Halevy } 6043cbe82603SBenny Halevy 6044863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr, 6045863a3c6cSAndy Adamson struct rpc_rqst *req, 6046863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 6047863a3c6cSAndy Adamson { 6048863a3c6cSAndy Adamson __be32 *p; 6049863a3c6cSAndy Adamson __u32 sizechanged; 6050863a3c6cSAndy Adamson int status; 6051863a3c6cSAndy Adamson 6052863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT); 6053db29c089SAndy Adamson res->status = status; 6054863a3c6cSAndy Adamson if (status) 6055863a3c6cSAndy Adamson return status; 6056863a3c6cSAndy Adamson 6057863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4); 6058863a3c6cSAndy Adamson if (unlikely(!p)) 6059863a3c6cSAndy Adamson goto out_overflow; 6060863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p); 6061863a3c6cSAndy Adamson 6062863a3c6cSAndy Adamson if (sizechanged) { 6063863a3c6cSAndy Adamson /* throw away new size */ 6064863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8); 6065863a3c6cSAndy Adamson if (unlikely(!p)) 6066863a3c6cSAndy Adamson goto out_overflow; 6067863a3c6cSAndy Adamson } 6068863a3c6cSAndy Adamson return 0; 6069863a3c6cSAndy Adamson out_overflow: 6070863a3c6cSAndy Adamson print_overflow_msg(__func__, xdr); 6071863a3c6cSAndy Adamson return -EIO; 6072863a3c6cSAndy Adamson } 60737d974794SBryan Schumaker 60747d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr, 60757d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 60767d974794SBryan Schumaker { 60777d974794SBryan Schumaker __be32 *p; 60787d974794SBryan Schumaker int status; 60797d974794SBryan Schumaker int num_res; 60807d974794SBryan Schumaker 60817d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID); 60827d974794SBryan Schumaker if (status) 60837d974794SBryan Schumaker return status; 60847d974794SBryan Schumaker 60857d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 60867d974794SBryan Schumaker if (unlikely(!p)) 60877d974794SBryan Schumaker goto out_overflow; 60887d974794SBryan Schumaker num_res = be32_to_cpup(p++); 60897d974794SBryan Schumaker if (num_res != 1) 60907d974794SBryan Schumaker goto out; 60917d974794SBryan Schumaker 60927d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4); 60937d974794SBryan Schumaker if (unlikely(!p)) 60947d974794SBryan Schumaker goto out_overflow; 60957d974794SBryan Schumaker res->status = be32_to_cpup(p++); 60961cab0652SBryan Schumaker 60971cab0652SBryan Schumaker return status; 60987d974794SBryan Schumaker out_overflow: 60997d974794SBryan Schumaker print_overflow_msg(__func__, xdr); 61007d974794SBryan Schumaker out: 61017d974794SBryan Schumaker return -EIO; 61027d974794SBryan Schumaker } 61039aeda35fSBryan Schumaker 61049aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr, 61059aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 61069aeda35fSBryan Schumaker { 61079f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 61089aeda35fSBryan Schumaker return res->status; 61099aeda35fSBryan Schumaker } 6110cf805165STrond Myklebust #else 6111cf805165STrond Myklebust static inline 6112cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr, 6113cf805165STrond Myklebust struct nfs4_layoutreturn_res *res) 6114cf805165STrond Myklebust { 6115cf805165STrond Myklebust return 0; 6116cf805165STrond Myklebust } 6117b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 6118b1f69b75SAndy Adamson 61191da177e4SLinus Torvalds /* 612049c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES. 612149c2559eSBenny Halevy */ 612249c2559eSBenny Halevy 612349c2559eSBenny Halevy /* 61241da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response 61251da177e4SLinus Torvalds */ 6126bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, 6127bf269551SChuck Lever struct xdr_stream *xdr, 6128bf269551SChuck Lever struct nfs_closeres *res) 61291da177e4SLinus Torvalds { 61301da177e4SLinus Torvalds struct compound_hdr hdr; 61311da177e4SLinus Torvalds int status; 61321da177e4SLinus Torvalds 6133bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61341da177e4SLinus Torvalds if (status) 61351da177e4SLinus Torvalds goto out; 6136bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61379b7b9fccSAndy Adamson if (status) 61389b7b9fccSAndy Adamson goto out; 6139bf269551SChuck Lever status = decode_putfh(xdr); 61401da177e4SLinus Torvalds if (status) 61411da177e4SLinus Torvalds goto out; 6142bf269551SChuck Lever status = decode_open_downgrade(xdr, res); 61431da177e4SLinus Torvalds out: 61441da177e4SLinus Torvalds return status; 61451da177e4SLinus Torvalds } 61461da177e4SLinus Torvalds 61471da177e4SLinus Torvalds /* 61481da177e4SLinus Torvalds * Decode ACCESS response 61491da177e4SLinus Torvalds */ 6150bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6151bf269551SChuck Lever struct nfs4_accessres *res) 61521da177e4SLinus Torvalds { 61531da177e4SLinus Torvalds struct compound_hdr hdr; 61541da177e4SLinus Torvalds int status; 61551da177e4SLinus Torvalds 6156bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61579b7b9fccSAndy Adamson if (status) 61589b7b9fccSAndy Adamson goto out; 6159bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61609b7b9fccSAndy Adamson if (status) 61611da177e4SLinus Torvalds goto out; 6162bf269551SChuck Lever status = decode_putfh(xdr); 616376b32999STrond Myklebust if (status != 0) 616476b32999STrond Myklebust goto out; 61656168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access); 616676b32999STrond Myklebust if (status != 0) 616776b32999STrond Myklebust goto out; 61686926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 61691da177e4SLinus Torvalds out: 61701da177e4SLinus Torvalds return status; 61711da177e4SLinus Torvalds } 61721da177e4SLinus Torvalds 61731da177e4SLinus Torvalds /* 61741da177e4SLinus Torvalds * Decode LOOKUP response 61751da177e4SLinus Torvalds */ 6176bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6177bf269551SChuck Lever struct nfs4_lookup_res *res) 61781da177e4SLinus Torvalds { 61791da177e4SLinus Torvalds struct compound_hdr hdr; 61801da177e4SLinus Torvalds int status; 61811da177e4SLinus Torvalds 6182bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 61839b7b9fccSAndy Adamson if (status) 61849b7b9fccSAndy Adamson goto out; 6185bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 61869b7b9fccSAndy Adamson if (status) 61871da177e4SLinus Torvalds goto out; 6188bf269551SChuck Lever status = decode_putfh(xdr); 6189bf269551SChuck Lever if (status) 61901da177e4SLinus Torvalds goto out; 6191bf269551SChuck Lever status = decode_lookup(xdr); 6192bf269551SChuck Lever if (status) 61931da177e4SLinus Torvalds goto out; 6194bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6195bf269551SChuck Lever if (status) 61961da177e4SLinus Torvalds goto out; 6197aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 61981da177e4SLinus Torvalds out: 61991da177e4SLinus Torvalds return status; 62001da177e4SLinus Torvalds } 62011da177e4SLinus Torvalds 62021da177e4SLinus Torvalds /* 62031da177e4SLinus Torvalds * Decode LOOKUP_ROOT response 62041da177e4SLinus Torvalds */ 6205bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, 6206bf269551SChuck Lever struct xdr_stream *xdr, 6207bf269551SChuck Lever struct nfs4_lookup_res *res) 62081da177e4SLinus Torvalds { 62091da177e4SLinus Torvalds struct compound_hdr hdr; 62101da177e4SLinus Torvalds int status; 62111da177e4SLinus Torvalds 6212bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62139b7b9fccSAndy Adamson if (status) 62149b7b9fccSAndy Adamson goto out; 6215bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62169b7b9fccSAndy Adamson if (status) 62171da177e4SLinus Torvalds goto out; 6218bf269551SChuck Lever status = decode_putrootfh(xdr); 6219bf269551SChuck Lever if (status) 62201da177e4SLinus Torvalds goto out; 6221bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6222bf269551SChuck Lever if (status == 0) 6223aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, 6224aa9c2669SDavid Quigley res->label, res->server); 62251da177e4SLinus Torvalds out: 62261da177e4SLinus Torvalds return status; 62271da177e4SLinus Torvalds } 62281da177e4SLinus Torvalds 62291da177e4SLinus Torvalds /* 62301da177e4SLinus Torvalds * Decode REMOVE response 62311da177e4SLinus Torvalds */ 6232bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6233bf269551SChuck Lever struct nfs_removeres *res) 62341da177e4SLinus Torvalds { 62351da177e4SLinus Torvalds struct compound_hdr hdr; 62361da177e4SLinus Torvalds int status; 62371da177e4SLinus Torvalds 6238bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62399b7b9fccSAndy Adamson if (status) 62409b7b9fccSAndy Adamson goto out; 6241bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62429b7b9fccSAndy Adamson if (status) 62431da177e4SLinus Torvalds goto out; 6244bf269551SChuck Lever status = decode_putfh(xdr); 6245bf269551SChuck Lever if (status) 624616e42959STrond Myklebust goto out; 6247bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo); 62481da177e4SLinus Torvalds out: 62491da177e4SLinus Torvalds return status; 62501da177e4SLinus Torvalds } 62511da177e4SLinus Torvalds 62521da177e4SLinus Torvalds /* 62531da177e4SLinus Torvalds * Decode RENAME response 62541da177e4SLinus Torvalds */ 6255bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6256bf269551SChuck Lever struct nfs_renameres *res) 62571da177e4SLinus Torvalds { 62581da177e4SLinus Torvalds struct compound_hdr hdr; 62591da177e4SLinus Torvalds int status; 62601da177e4SLinus Torvalds 6261bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62629b7b9fccSAndy Adamson if (status) 62639b7b9fccSAndy Adamson goto out; 6264bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62659b7b9fccSAndy Adamson if (status) 62661da177e4SLinus Torvalds goto out; 6267bf269551SChuck Lever status = decode_putfh(xdr); 6268bf269551SChuck Lever if (status) 62691da177e4SLinus Torvalds goto out; 6270bf269551SChuck Lever status = decode_savefh(xdr); 6271bf269551SChuck Lever if (status) 62721da177e4SLinus Torvalds goto out; 6273bf269551SChuck Lever status = decode_putfh(xdr); 6274bf269551SChuck Lever if (status) 62751da177e4SLinus Torvalds goto out; 6276bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); 62771da177e4SLinus Torvalds out: 62781da177e4SLinus Torvalds return status; 62791da177e4SLinus Torvalds } 62801da177e4SLinus Torvalds 62811da177e4SLinus Torvalds /* 62821da177e4SLinus Torvalds * Decode LINK response 62831da177e4SLinus Torvalds */ 6284bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6285bf269551SChuck Lever struct nfs4_link_res *res) 62861da177e4SLinus Torvalds { 62871da177e4SLinus Torvalds struct compound_hdr hdr; 62881da177e4SLinus Torvalds int status; 62891da177e4SLinus Torvalds 6290bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 62919b7b9fccSAndy Adamson if (status) 62929b7b9fccSAndy Adamson goto out; 6293bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 62949b7b9fccSAndy Adamson if (status) 62951da177e4SLinus Torvalds goto out; 6296bf269551SChuck Lever status = decode_putfh(xdr); 6297bf269551SChuck Lever if (status) 62981da177e4SLinus Torvalds goto out; 6299bf269551SChuck Lever status = decode_savefh(xdr); 6300bf269551SChuck Lever if (status) 63011da177e4SLinus Torvalds goto out; 6302bf269551SChuck Lever status = decode_putfh(xdr); 6303bf269551SChuck Lever if (status) 63041da177e4SLinus Torvalds goto out; 6305bf269551SChuck Lever status = decode_link(xdr, &res->cinfo); 6306bf269551SChuck Lever if (status) 630791ba2eeeSTrond Myklebust goto out; 630891ba2eeeSTrond Myklebust /* 630991ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current 631091ba2eeeSTrond Myklebust * filehandle. 631191ba2eeeSTrond Myklebust */ 6312bf269551SChuck Lever status = decode_restorefh(xdr); 6313bf269551SChuck Lever if (status) 631491ba2eeeSTrond Myklebust goto out; 6315aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63161da177e4SLinus Torvalds out: 63171da177e4SLinus Torvalds return status; 63181da177e4SLinus Torvalds } 63191da177e4SLinus Torvalds 63201da177e4SLinus Torvalds /* 63211da177e4SLinus Torvalds * Decode CREATE response 63221da177e4SLinus Torvalds */ 6323bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6324bf269551SChuck Lever struct nfs4_create_res *res) 63251da177e4SLinus Torvalds { 63261da177e4SLinus Torvalds struct compound_hdr hdr; 63271da177e4SLinus Torvalds int status; 63281da177e4SLinus Torvalds 6329bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63309b7b9fccSAndy Adamson if (status) 63319b7b9fccSAndy Adamson goto out; 6332bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63339b7b9fccSAndy Adamson if (status) 63341da177e4SLinus Torvalds goto out; 6335bf269551SChuck Lever status = decode_putfh(xdr); 6336bf269551SChuck Lever if (status) 63371da177e4SLinus Torvalds goto out; 6338bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo); 6339bf269551SChuck Lever if (status) 63401da177e4SLinus Torvalds goto out; 6341bf269551SChuck Lever status = decode_getfh(xdr, res->fh); 6342bf269551SChuck Lever if (status) 63431da177e4SLinus Torvalds goto out; 6344aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63451da177e4SLinus Torvalds out: 63461da177e4SLinus Torvalds return status; 63471da177e4SLinus Torvalds } 63481da177e4SLinus Torvalds 63491da177e4SLinus Torvalds /* 63501da177e4SLinus Torvalds * Decode SYMLINK response 63511da177e4SLinus Torvalds */ 6352bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6353bf269551SChuck Lever struct nfs4_create_res *res) 63541da177e4SLinus Torvalds { 6355bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res); 63561da177e4SLinus Torvalds } 63571da177e4SLinus Torvalds 63581da177e4SLinus Torvalds /* 63591da177e4SLinus Torvalds * Decode GETATTR response 63601da177e4SLinus Torvalds */ 6361bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6362bf269551SChuck Lever struct nfs4_getattr_res *res) 63631da177e4SLinus Torvalds { 63641da177e4SLinus Torvalds struct compound_hdr hdr; 63651da177e4SLinus Torvalds int status; 63661da177e4SLinus Torvalds 6367bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 63681da177e4SLinus Torvalds if (status) 63691da177e4SLinus Torvalds goto out; 6370bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 63719b7b9fccSAndy Adamson if (status) 63729b7b9fccSAndy Adamson goto out; 6373bf269551SChuck Lever status = decode_putfh(xdr); 63741da177e4SLinus Torvalds if (status) 63751da177e4SLinus Torvalds goto out; 6376aa9c2669SDavid Quigley status = decode_getfattr_label(xdr, res->fattr, res->label, res->server); 63771da177e4SLinus Torvalds out: 63781da177e4SLinus Torvalds return status; 63791da177e4SLinus Torvalds } 63801da177e4SLinus Torvalds 638123ec6965SJ. Bruce Fields /* 638223ec6965SJ. Bruce Fields * Encode an SETACL request 638323ec6965SJ. Bruce Fields */ 63849f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, 63859f06c719SChuck Lever struct nfs_setaclargs *args) 638623ec6965SJ. Bruce Fields { 638723ec6965SJ. Bruce Fields struct compound_hdr hdr = { 638866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args), 638923ec6965SJ. Bruce Fields }; 639023ec6965SJ. Bruce Fields 63919f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr); 63929f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr); 63939f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr); 63949f06c719SChuck Lever encode_setacl(xdr, args, &hdr); 6395d017931cSAndy Adamson encode_nops(&hdr); 639623ec6965SJ. Bruce Fields } 639705d564feSAndy Adamson 639823ec6965SJ. Bruce Fields /* 639923ec6965SJ. Bruce Fields * Decode SETACL response 640023ec6965SJ. Bruce Fields */ 640123ec6965SJ. Bruce Fields static int 6402bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 640373c403a9SBenny Halevy struct nfs_setaclres *res) 640423ec6965SJ. Bruce Fields { 640523ec6965SJ. Bruce Fields struct compound_hdr hdr; 640623ec6965SJ. Bruce Fields int status; 640723ec6965SJ. Bruce Fields 6408bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 640923ec6965SJ. Bruce Fields if (status) 641023ec6965SJ. Bruce Fields goto out; 6411bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64129b7b9fccSAndy Adamson if (status) 64139b7b9fccSAndy Adamson goto out; 6414bf269551SChuck Lever status = decode_putfh(xdr); 641523ec6965SJ. Bruce Fields if (status) 641623ec6965SJ. Bruce Fields goto out; 6417bf269551SChuck Lever status = decode_setattr(xdr); 641823ec6965SJ. Bruce Fields out: 641923ec6965SJ. Bruce Fields return status; 642023ec6965SJ. Bruce Fields } 64211da177e4SLinus Torvalds 64221da177e4SLinus Torvalds /* 6423029d105eSJ. Bruce Fields * Decode GETACL response 6424029d105eSJ. Bruce Fields */ 6425029d105eSJ. Bruce Fields static int 6426bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6427663c79b3SBenny Halevy struct nfs_getaclres *res) 6428029d105eSJ. Bruce Fields { 6429029d105eSJ. Bruce Fields struct compound_hdr hdr; 6430029d105eSJ. Bruce Fields int status; 6431029d105eSJ. Bruce Fields 6432331818f1STrond Myklebust if (res->acl_scratch != NULL) { 6433331818f1STrond Myklebust void *p = page_address(res->acl_scratch); 6434331818f1STrond Myklebust xdr_set_scratch_buffer(xdr, p, PAGE_SIZE); 6435331818f1STrond Myklebust } 6436bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6437029d105eSJ. Bruce Fields if (status) 6438029d105eSJ. Bruce Fields goto out; 6439bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64409b7b9fccSAndy Adamson if (status) 64419b7b9fccSAndy Adamson goto out; 6442bf269551SChuck Lever status = decode_putfh(xdr); 6443029d105eSJ. Bruce Fields if (status) 6444029d105eSJ. Bruce Fields goto out; 6445bf118a34SAndy Adamson status = decode_getacl(xdr, rqstp, res); 6446029d105eSJ. Bruce Fields 6447029d105eSJ. Bruce Fields out: 6448029d105eSJ. Bruce Fields return status; 6449029d105eSJ. Bruce Fields } 6450029d105eSJ. Bruce Fields 6451029d105eSJ. Bruce Fields /* 64521da177e4SLinus Torvalds * Decode CLOSE response 64531da177e4SLinus Torvalds */ 6454bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6455bf269551SChuck Lever struct nfs_closeres *res) 64561da177e4SLinus Torvalds { 64571da177e4SLinus Torvalds struct compound_hdr hdr; 64581da177e4SLinus Torvalds int status; 64591da177e4SLinus Torvalds 6460bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64611da177e4SLinus Torvalds if (status) 64621da177e4SLinus Torvalds goto out; 6463bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 64649b7b9fccSAndy Adamson if (status) 64659b7b9fccSAndy Adamson goto out; 6466bf269551SChuck Lever status = decode_putfh(xdr); 64671da177e4SLinus Torvalds if (status) 64681da177e4SLinus Torvalds goto out; 6469cf805165STrond Myklebust if (res->lr_res) { 6470cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6471cf805165STrond Myklebust res->lr_ret = status; 6472cf805165STrond Myklebust if (status) 6473cf805165STrond Myklebust goto out; 6474cf805165STrond Myklebust } 6475bf269551SChuck Lever status = decode_close(xdr, res); 6476516a6af6STrond Myklebust if (status != 0) 6477516a6af6STrond Myklebust goto out; 6478516a6af6STrond Myklebust /* 6479516a6af6STrond Myklebust * Note: Server may do delete on close for this file 6480516a6af6STrond Myklebust * in which case the getattr call will fail with 6481516a6af6STrond Myklebust * an ESTALE error. Shouldn't be a problem, 6482516a6af6STrond Myklebust * though, since fattr->valid will remain unset. 6483516a6af6STrond Myklebust */ 64846926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 64851da177e4SLinus Torvalds out: 64861da177e4SLinus Torvalds return status; 64871da177e4SLinus Torvalds } 64881da177e4SLinus Torvalds 64891da177e4SLinus Torvalds /* 64901da177e4SLinus Torvalds * Decode OPEN response 64911da177e4SLinus Torvalds */ 6492bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6493bf269551SChuck Lever struct nfs_openres *res) 64941da177e4SLinus Torvalds { 64951da177e4SLinus Torvalds struct compound_hdr hdr; 64961da177e4SLinus Torvalds int status; 64971da177e4SLinus Torvalds 6498bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 64991da177e4SLinus Torvalds if (status) 65001da177e4SLinus Torvalds goto out; 6501bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65029b7b9fccSAndy Adamson if (status) 65039b7b9fccSAndy Adamson goto out; 6504bf269551SChuck Lever status = decode_putfh(xdr); 65051da177e4SLinus Torvalds if (status) 65061da177e4SLinus Torvalds goto out; 6507bf269551SChuck Lever status = decode_open(xdr, res); 65081da177e4SLinus Torvalds if (status) 65091da177e4SLinus Torvalds goto out; 651001913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh); 651101913b49SWeston Andros Adamson if (status) 65121da177e4SLinus Torvalds goto out; 6513ae2bb032SWeston Andros Adamson if (res->access_request) 65146168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 6515aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server); 65161da177e4SLinus Torvalds out: 65171da177e4SLinus Torvalds return status; 65181da177e4SLinus Torvalds } 65191da177e4SLinus Torvalds 65201da177e4SLinus Torvalds /* 65211da177e4SLinus Torvalds * Decode OPEN_CONFIRM response 65221da177e4SLinus Torvalds */ 6523bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, 6524bf269551SChuck Lever struct xdr_stream *xdr, 6525bf269551SChuck Lever struct nfs_open_confirmres *res) 65261da177e4SLinus Torvalds { 65271da177e4SLinus Torvalds struct compound_hdr hdr; 65281da177e4SLinus Torvalds int status; 65291da177e4SLinus Torvalds 6530bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65311da177e4SLinus Torvalds if (status) 65321da177e4SLinus Torvalds goto out; 6533bf269551SChuck Lever status = decode_putfh(xdr); 65341da177e4SLinus Torvalds if (status) 65351da177e4SLinus Torvalds goto out; 6536bf269551SChuck Lever status = decode_open_confirm(xdr, res); 65371da177e4SLinus Torvalds out: 65381da177e4SLinus Torvalds return status; 65391da177e4SLinus Torvalds } 65401da177e4SLinus Torvalds 65411da177e4SLinus Torvalds /* 65421da177e4SLinus Torvalds * Decode OPEN response 65431da177e4SLinus Torvalds */ 6544bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, 6545bf269551SChuck Lever struct xdr_stream *xdr, 6546bf269551SChuck Lever struct nfs_openres *res) 65471da177e4SLinus Torvalds { 65481da177e4SLinus Torvalds struct compound_hdr hdr; 65491da177e4SLinus Torvalds int status; 65501da177e4SLinus Torvalds 6551bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65521da177e4SLinus Torvalds if (status) 65531da177e4SLinus Torvalds goto out; 6554bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65559b7b9fccSAndy Adamson if (status) 65569b7b9fccSAndy Adamson goto out; 6557bf269551SChuck Lever status = decode_putfh(xdr); 65581da177e4SLinus Torvalds if (status) 65591da177e4SLinus Torvalds goto out; 6560bf269551SChuck Lever status = decode_open(xdr, res); 6561864472e9STrond Myklebust if (status) 6562864472e9STrond Myklebust goto out; 6563ae2bb032SWeston Andros Adamson if (res->access_request) 65646168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result); 65656926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server); 65661da177e4SLinus Torvalds out: 65671da177e4SLinus Torvalds return status; 65681da177e4SLinus Torvalds } 65691da177e4SLinus Torvalds 65701da177e4SLinus Torvalds /* 65711da177e4SLinus Torvalds * Decode SETATTR response 65721da177e4SLinus Torvalds */ 6573bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, 6574bf269551SChuck Lever struct xdr_stream *xdr, 6575bf269551SChuck Lever struct nfs_setattrres *res) 65761da177e4SLinus Torvalds { 65771da177e4SLinus Torvalds struct compound_hdr hdr; 65781da177e4SLinus Torvalds int status; 65791da177e4SLinus Torvalds 6580bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 65811da177e4SLinus Torvalds if (status) 65821da177e4SLinus Torvalds goto out; 6583bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 65849b7b9fccSAndy Adamson if (status) 65859b7b9fccSAndy Adamson goto out; 6586bf269551SChuck Lever status = decode_putfh(xdr); 65871da177e4SLinus Torvalds if (status) 65881da177e4SLinus Torvalds goto out; 6589bf269551SChuck Lever status = decode_setattr(xdr); 65901da177e4SLinus Torvalds if (status) 65911da177e4SLinus Torvalds goto out; 6592aa9c2669SDavid Quigley decode_getfattr_label(xdr, res->fattr, res->label, res->server); 65931da177e4SLinus Torvalds out: 65941da177e4SLinus Torvalds return status; 65951da177e4SLinus Torvalds } 65961da177e4SLinus Torvalds 65971da177e4SLinus Torvalds /* 65981da177e4SLinus Torvalds * Decode LOCK response 65991da177e4SLinus Torvalds */ 6600bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6601bf269551SChuck Lever struct nfs_lock_res *res) 66021da177e4SLinus Torvalds { 66031da177e4SLinus Torvalds struct compound_hdr hdr; 66041da177e4SLinus Torvalds int status; 66051da177e4SLinus Torvalds 6606bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66071da177e4SLinus Torvalds if (status) 66081da177e4SLinus Torvalds goto out; 6609bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66109b7b9fccSAndy Adamson if (status) 66119b7b9fccSAndy Adamson goto out; 6612bf269551SChuck Lever status = decode_putfh(xdr); 66131da177e4SLinus Torvalds if (status) 66141da177e4SLinus Torvalds goto out; 6615bf269551SChuck Lever status = decode_lock(xdr, res); 66161da177e4SLinus Torvalds out: 66171da177e4SLinus Torvalds return status; 66181da177e4SLinus Torvalds } 66191da177e4SLinus Torvalds 66201da177e4SLinus Torvalds /* 66211da177e4SLinus Torvalds * Decode LOCKT response 66221da177e4SLinus Torvalds */ 6623bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6624bf269551SChuck Lever struct nfs_lockt_res *res) 66251da177e4SLinus Torvalds { 66261da177e4SLinus Torvalds struct compound_hdr hdr; 66271da177e4SLinus Torvalds int status; 66281da177e4SLinus Torvalds 6629bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66301da177e4SLinus Torvalds if (status) 66311da177e4SLinus Torvalds goto out; 6632bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66339b7b9fccSAndy Adamson if (status) 66349b7b9fccSAndy Adamson goto out; 6635bf269551SChuck Lever status = decode_putfh(xdr); 66361da177e4SLinus Torvalds if (status) 66371da177e4SLinus Torvalds goto out; 6638bf269551SChuck Lever status = decode_lockt(xdr, res); 66391da177e4SLinus Torvalds out: 66401da177e4SLinus Torvalds return status; 66411da177e4SLinus Torvalds } 66421da177e4SLinus Torvalds 66431da177e4SLinus Torvalds /* 66441da177e4SLinus Torvalds * Decode LOCKU response 66451da177e4SLinus Torvalds */ 6646bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6647bf269551SChuck Lever struct nfs_locku_res *res) 66481da177e4SLinus Torvalds { 66491da177e4SLinus Torvalds struct compound_hdr hdr; 66501da177e4SLinus Torvalds int status; 66511da177e4SLinus Torvalds 6652bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66531da177e4SLinus Torvalds if (status) 66541da177e4SLinus Torvalds goto out; 6655bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66569b7b9fccSAndy Adamson if (status) 66579b7b9fccSAndy Adamson goto out; 6658bf269551SChuck Lever status = decode_putfh(xdr); 66591da177e4SLinus Torvalds if (status) 66601da177e4SLinus Torvalds goto out; 6661bf269551SChuck Lever status = decode_locku(xdr, res); 66621da177e4SLinus Torvalds out: 66631da177e4SLinus Torvalds return status; 66641da177e4SLinus Torvalds } 66651da177e4SLinus Torvalds 6666bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6667bf269551SChuck Lever struct xdr_stream *xdr, void *dummy) 6668d3c7b7ccSTrond Myklebust { 6669d3c7b7ccSTrond Myklebust struct compound_hdr hdr; 6670d3c7b7ccSTrond Myklebust int status; 6671d3c7b7ccSTrond Myklebust 6672bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6673d3c7b7ccSTrond Myklebust if (!status) 6674bf269551SChuck Lever status = decode_release_lockowner(xdr); 6675d3c7b7ccSTrond Myklebust return status; 6676d3c7b7ccSTrond Myklebust } 6677d3c7b7ccSTrond Myklebust 66781da177e4SLinus Torvalds /* 66791da177e4SLinus Torvalds * Decode READLINK response 66801da177e4SLinus Torvalds */ 6681bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, 6682bf269551SChuck Lever struct xdr_stream *xdr, 6683f50c7000SBenny Halevy struct nfs4_readlink_res *res) 66841da177e4SLinus Torvalds { 66851da177e4SLinus Torvalds struct compound_hdr hdr; 66861da177e4SLinus Torvalds int status; 66871da177e4SLinus Torvalds 6688bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 66891da177e4SLinus Torvalds if (status) 66901da177e4SLinus Torvalds goto out; 6691bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 66929b7b9fccSAndy Adamson if (status) 66939b7b9fccSAndy Adamson goto out; 6694bf269551SChuck Lever status = decode_putfh(xdr); 66951da177e4SLinus Torvalds if (status) 66961da177e4SLinus Torvalds goto out; 6697bf269551SChuck Lever status = decode_readlink(xdr, rqstp); 66981da177e4SLinus Torvalds out: 66991da177e4SLinus Torvalds return status; 67001da177e4SLinus Torvalds } 67011da177e4SLinus Torvalds 67021da177e4SLinus Torvalds /* 67031da177e4SLinus Torvalds * Decode READDIR response 67041da177e4SLinus Torvalds */ 6705bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6706bf269551SChuck Lever struct nfs4_readdir_res *res) 67071da177e4SLinus Torvalds { 67081da177e4SLinus Torvalds struct compound_hdr hdr; 67091da177e4SLinus Torvalds int status; 67101da177e4SLinus Torvalds 6711bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 67121da177e4SLinus Torvalds if (status) 67131da177e4SLinus Torvalds goto out; 6714bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67159b7b9fccSAndy Adamson if (status) 67169b7b9fccSAndy Adamson goto out; 6717bf269551SChuck Lever status = decode_putfh(xdr); 67181da177e4SLinus Torvalds if (status) 67191da177e4SLinus Torvalds goto out; 6720bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res); 67211da177e4SLinus Torvalds out: 67221da177e4SLinus Torvalds return status; 67231da177e4SLinus Torvalds } 67241da177e4SLinus Torvalds 67251da177e4SLinus Torvalds /* 67261da177e4SLinus Torvalds * Decode Read response 67271da177e4SLinus Torvalds */ 6728bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 67299137bdf3SAnna Schumaker struct nfs_pgio_res *res) 67301da177e4SLinus Torvalds { 67311da177e4SLinus Torvalds struct compound_hdr hdr; 67321da177e4SLinus Torvalds int status; 67331da177e4SLinus Torvalds 6734bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6735aabff4ddSPeng Tao res->op_status = hdr.status; 67361da177e4SLinus Torvalds if (status) 67371da177e4SLinus Torvalds goto out; 6738bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67399b7b9fccSAndy Adamson if (status) 67409b7b9fccSAndy Adamson goto out; 6741bf269551SChuck Lever status = decode_putfh(xdr); 67421da177e4SLinus Torvalds if (status) 67431da177e4SLinus Torvalds goto out; 6744bf269551SChuck Lever status = decode_read(xdr, rqstp, res); 67451da177e4SLinus Torvalds if (!status) 67461da177e4SLinus Torvalds status = res->count; 67471da177e4SLinus Torvalds out: 67481da177e4SLinus Torvalds return status; 67491da177e4SLinus Torvalds } 67501da177e4SLinus Torvalds 67511da177e4SLinus Torvalds /* 67521da177e4SLinus Torvalds * Decode WRITE response 67531da177e4SLinus Torvalds */ 6754bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 67559137bdf3SAnna Schumaker struct nfs_pgio_res *res) 67561da177e4SLinus Torvalds { 67571da177e4SLinus Torvalds struct compound_hdr hdr; 67581da177e4SLinus Torvalds int status; 67591da177e4SLinus Torvalds 6760bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6761aabff4ddSPeng Tao res->op_status = hdr.status; 67621da177e4SLinus Torvalds if (status) 67631da177e4SLinus Torvalds goto out; 6764bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67659b7b9fccSAndy Adamson if (status) 67669b7b9fccSAndy Adamson goto out; 6767bf269551SChuck Lever status = decode_putfh(xdr); 67681da177e4SLinus Torvalds if (status) 67691da177e4SLinus Torvalds goto out; 6770bf269551SChuck Lever status = decode_write(xdr, res); 67714f9838c7STrond Myklebust if (status) 67724f9838c7STrond Myklebust goto out; 67737ffd1064SFred Isaman if (res->fattr) 67746926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 67751da177e4SLinus Torvalds if (!status) 67761da177e4SLinus Torvalds status = res->count; 67771da177e4SLinus Torvalds out: 67781da177e4SLinus Torvalds return status; 67791da177e4SLinus Torvalds } 67801da177e4SLinus Torvalds 67811da177e4SLinus Torvalds /* 67821da177e4SLinus Torvalds * Decode COMMIT response 67831da177e4SLinus Torvalds */ 6784bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 67850b7c0153SFred Isaman struct nfs_commitres *res) 67861da177e4SLinus Torvalds { 67871da177e4SLinus Torvalds struct compound_hdr hdr; 67881da177e4SLinus Torvalds int status; 67891da177e4SLinus Torvalds 6790bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 6791aabff4ddSPeng Tao res->op_status = hdr.status; 67921da177e4SLinus Torvalds if (status) 67931da177e4SLinus Torvalds goto out; 6794bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 67959b7b9fccSAndy Adamson if (status) 67969b7b9fccSAndy Adamson goto out; 6797bf269551SChuck Lever status = decode_putfh(xdr); 67981da177e4SLinus Torvalds if (status) 67991da177e4SLinus Torvalds goto out; 6800bf269551SChuck Lever status = decode_commit(xdr, res); 68011da177e4SLinus Torvalds out: 68021da177e4SLinus Torvalds return status; 68031da177e4SLinus Torvalds } 68041da177e4SLinus Torvalds 68051da177e4SLinus Torvalds /* 68068b173218SRicardo Labiaga * Decode FSINFO response 68071da177e4SLinus Torvalds */ 6808bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, 68093dda5e43SBenny Halevy struct nfs4_fsinfo_res *res) 68101da177e4SLinus Torvalds { 68111da177e4SLinus Torvalds struct compound_hdr hdr; 68121da177e4SLinus Torvalds int status; 68131da177e4SLinus Torvalds 6814bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68151da177e4SLinus Torvalds if (!status) 6816bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68179b7b9fccSAndy Adamson if (!status) 6818bf269551SChuck Lever status = decode_putfh(xdr); 68191da177e4SLinus Torvalds if (!status) 6820bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo); 68211da177e4SLinus Torvalds return status; 68221da177e4SLinus Torvalds } 68231da177e4SLinus Torvalds 68241da177e4SLinus Torvalds /* 68258b173218SRicardo Labiaga * Decode PATHCONF response 68261da177e4SLinus Torvalds */ 6827bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, 6828d45b2989SBenny Halevy struct nfs4_pathconf_res *res) 68291da177e4SLinus Torvalds { 68301da177e4SLinus Torvalds struct compound_hdr hdr; 68311da177e4SLinus Torvalds int status; 68321da177e4SLinus Torvalds 6833bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68341da177e4SLinus Torvalds if (!status) 6835bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68369b7b9fccSAndy Adamson if (!status) 6837bf269551SChuck Lever status = decode_putfh(xdr); 68381da177e4SLinus Torvalds if (!status) 6839bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf); 68401da177e4SLinus Torvalds return status; 68411da177e4SLinus Torvalds } 68421da177e4SLinus Torvalds 68431da177e4SLinus Torvalds /* 68448b173218SRicardo Labiaga * Decode STATFS response 68451da177e4SLinus Torvalds */ 6846bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, 684724ad148aSBenny Halevy struct nfs4_statfs_res *res) 68481da177e4SLinus Torvalds { 68491da177e4SLinus Torvalds struct compound_hdr hdr; 68501da177e4SLinus Torvalds int status; 68511da177e4SLinus Torvalds 6852bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68531da177e4SLinus Torvalds if (!status) 6854bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68559b7b9fccSAndy Adamson if (!status) 6856bf269551SChuck Lever status = decode_putfh(xdr); 68571da177e4SLinus Torvalds if (!status) 6858bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat); 68591da177e4SLinus Torvalds return status; 68601da177e4SLinus Torvalds } 68611da177e4SLinus Torvalds 68621da177e4SLinus Torvalds /* 68638b173218SRicardo Labiaga * Decode GETATTR_BITMAP response 68641da177e4SLinus Torvalds */ 6865bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, 6866bf269551SChuck Lever struct xdr_stream *xdr, 6867bf269551SChuck Lever struct nfs4_server_caps_res *res) 68681da177e4SLinus Torvalds { 68691da177e4SLinus Torvalds struct compound_hdr hdr; 68701da177e4SLinus Torvalds int status; 68711da177e4SLinus Torvalds 6872bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68739b7b9fccSAndy Adamson if (status) 68749b7b9fccSAndy Adamson goto out; 6875bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 68769b7b9fccSAndy Adamson if (status) 68771da177e4SLinus Torvalds goto out; 6878bf269551SChuck Lever status = decode_putfh(xdr); 6879bf269551SChuck Lever if (status) 68801da177e4SLinus Torvalds goto out; 6881bf269551SChuck Lever status = decode_server_caps(xdr, res); 68821da177e4SLinus Torvalds out: 68831da177e4SLinus Torvalds return status; 68841da177e4SLinus Torvalds } 68851da177e4SLinus Torvalds 68861da177e4SLinus Torvalds /* 68871da177e4SLinus Torvalds * Decode RENEW response 68881da177e4SLinus Torvalds */ 6889bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 6890bf269551SChuck Lever void *__unused) 68911da177e4SLinus Torvalds { 68921da177e4SLinus Torvalds struct compound_hdr hdr; 68931da177e4SLinus Torvalds int status; 68941da177e4SLinus Torvalds 6895bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 68961da177e4SLinus Torvalds if (!status) 6897bf269551SChuck Lever status = decode_renew(xdr); 68981da177e4SLinus Torvalds return status; 68991da177e4SLinus Torvalds } 69001da177e4SLinus Torvalds 69011da177e4SLinus Torvalds /* 69028b173218SRicardo Labiaga * Decode SETCLIENTID response 69031da177e4SLinus Torvalds */ 6904bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, 6905bf269551SChuck Lever struct xdr_stream *xdr, 6906bb8b27e5STrond Myklebust struct nfs4_setclientid_res *res) 69071da177e4SLinus Torvalds { 69081da177e4SLinus Torvalds struct compound_hdr hdr; 69091da177e4SLinus Torvalds int status; 69101da177e4SLinus Torvalds 6911bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69121da177e4SLinus Torvalds if (!status) 6913bf269551SChuck Lever status = decode_setclientid(xdr, res); 69141da177e4SLinus Torvalds return status; 69151da177e4SLinus Torvalds } 69161da177e4SLinus Torvalds 69171da177e4SLinus Torvalds /* 69188b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response 69191da177e4SLinus Torvalds */ 6920bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, 692183ca7f5aSChuck Lever struct xdr_stream *xdr) 69221da177e4SLinus Torvalds { 69231da177e4SLinus Torvalds struct compound_hdr hdr; 69241da177e4SLinus Torvalds int status; 69251da177e4SLinus Torvalds 6926bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69271da177e4SLinus Torvalds if (!status) 6928bf269551SChuck Lever status = decode_setclientid_confirm(xdr); 69291da177e4SLinus Torvalds return status; 69301da177e4SLinus Torvalds } 69311da177e4SLinus Torvalds 69321da177e4SLinus Torvalds /* 69338b173218SRicardo Labiaga * Decode DELEGRETURN response 69341da177e4SLinus Torvalds */ 6935bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, 6936bf269551SChuck Lever struct xdr_stream *xdr, 6937bf269551SChuck Lever struct nfs4_delegreturnres *res) 69381da177e4SLinus Torvalds { 69391da177e4SLinus Torvalds struct compound_hdr hdr; 69401da177e4SLinus Torvalds int status; 69411da177e4SLinus Torvalds 6942bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69439b7b9fccSAndy Adamson if (status) 69449b7b9fccSAndy Adamson goto out; 6945bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 69469b7b9fccSAndy Adamson if (status) 6947fa178f29STrond Myklebust goto out; 6948bf269551SChuck Lever status = decode_putfh(xdr); 6949fa178f29STrond Myklebust if (status != 0) 6950fa178f29STrond Myklebust goto out; 6951586f1c39STrond Myklebust if (res->lr_res) { 6952586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res); 6953586f1c39STrond Myklebust res->lr_ret = status; 6954586f1c39STrond Myklebust if (status) 6955586f1c39STrond Myklebust goto out; 6956586f1c39STrond Myklebust } 6957e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server); 6958556ae3bbSJeff Layton if (status != 0) 6959556ae3bbSJeff Layton goto out; 6960e144cbccSTrond Myklebust status = decode_delegreturn(xdr); 6961fa178f29STrond Myklebust out: 69621da177e4SLinus Torvalds return status; 69631da177e4SLinus Torvalds } 69641da177e4SLinus Torvalds 6965683b57b4STrond Myklebust /* 69668b173218SRicardo Labiaga * Decode FS_LOCATIONS response 6967683b57b4STrond Myklebust */ 6968bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, 6969bf269551SChuck Lever struct xdr_stream *xdr, 697022958463SBenny Halevy struct nfs4_fs_locations_res *res) 6971683b57b4STrond Myklebust { 6972683b57b4STrond Myklebust struct compound_hdr hdr; 6973683b57b4STrond Myklebust int status; 6974683b57b4STrond Myklebust 6975bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 69769b7b9fccSAndy Adamson if (status) 69779b7b9fccSAndy Adamson goto out; 6978bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req); 69799b7b9fccSAndy Adamson if (status) 6980683b57b4STrond Myklebust goto out; 6981bf269551SChuck Lever status = decode_putfh(xdr); 6982bf269551SChuck Lever if (status) 6983683b57b4STrond Myklebust goto out; 6984b03d735bSChuck Lever if (res->migration) { 6985b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6986b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 6987b03d735bSChuck Lever &res->fs_locations->fattr, 6988b03d735bSChuck Lever NULL, res->fs_locations, 6989b03d735bSChuck Lever NULL, res->fs_locations->server); 6990b03d735bSChuck Lever if (status) 6991b03d735bSChuck Lever goto out; 6992b03d735bSChuck Lever if (res->renew) 6993b03d735bSChuck Lever status = decode_renew(xdr); 6994b03d735bSChuck Lever } else { 6995bf269551SChuck Lever status = decode_lookup(xdr); 6996bf269551SChuck Lever if (status) 6997683b57b4STrond Myklebust goto out; 6998bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE); 6999b03d735bSChuck Lever status = decode_getfattr_generic(xdr, 7000b03d735bSChuck Lever &res->fs_locations->fattr, 70018b7e3f49STrond Myklebust NULL, res->fs_locations, 7002aa9c2669SDavid Quigley NULL, res->fs_locations->server); 7003b03d735bSChuck Lever } 7004683b57b4STrond Myklebust out: 7005683b57b4STrond Myklebust return status; 7006683b57b4STrond Myklebust } 7007683b57b4STrond Myklebust 70085a5ea0d4SBryan Schumaker /* 70095a5ea0d4SBryan Schumaker * Decode SECINFO response 70105a5ea0d4SBryan Schumaker */ 70115a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, 70125a5ea0d4SBryan Schumaker struct xdr_stream *xdr, 70135a5ea0d4SBryan Schumaker struct nfs4_secinfo_res *res) 70145a5ea0d4SBryan Schumaker { 70155a5ea0d4SBryan Schumaker struct compound_hdr hdr; 70165a5ea0d4SBryan Schumaker int status; 70175a5ea0d4SBryan Schumaker 70185a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 70195a5ea0d4SBryan Schumaker if (status) 70205a5ea0d4SBryan Schumaker goto out; 70215a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 70225a5ea0d4SBryan Schumaker if (status) 70235a5ea0d4SBryan Schumaker goto out; 70245a5ea0d4SBryan Schumaker status = decode_putfh(xdr); 70255a5ea0d4SBryan Schumaker if (status) 70265a5ea0d4SBryan Schumaker goto out; 70275a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res); 70285a5ea0d4SBryan Schumaker out: 70295a5ea0d4SBryan Schumaker return status; 70305a5ea0d4SBryan Schumaker } 70315a5ea0d4SBryan Schumaker 703244c99933SChuck Lever /* 703344c99933SChuck Lever * Decode FSID_PRESENT response 703444c99933SChuck Lever */ 703544c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp, 703644c99933SChuck Lever struct xdr_stream *xdr, 703744c99933SChuck Lever struct nfs4_fsid_present_res *res) 703844c99933SChuck Lever { 703944c99933SChuck Lever struct compound_hdr hdr; 704044c99933SChuck Lever int status; 704144c99933SChuck Lever 704244c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr); 704344c99933SChuck Lever if (status) 704444c99933SChuck Lever goto out; 704544c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 704644c99933SChuck Lever if (status) 704744c99933SChuck Lever goto out; 704844c99933SChuck Lever status = decode_putfh(xdr); 704944c99933SChuck Lever if (status) 705044c99933SChuck Lever goto out; 705144c99933SChuck Lever status = decode_getfh(xdr, res->fh); 705244c99933SChuck Lever if (status) 705344c99933SChuck Lever goto out; 705444c99933SChuck Lever if (res->renew) 705544c99933SChuck Lever status = decode_renew(xdr); 705644c99933SChuck Lever out: 705744c99933SChuck Lever return status; 705844c99933SChuck Lever } 705944c99933SChuck Lever 706099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 706199fe60d0SBenny Halevy /* 70627c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response 70637c44f1aeSWeston Andros Adamson */ 70647c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp, 70657c44f1aeSWeston Andros Adamson struct xdr_stream *xdr, 70667c44f1aeSWeston Andros Adamson void *res) 70677c44f1aeSWeston Andros Adamson { 70687c44f1aeSWeston Andros Adamson struct compound_hdr hdr; 70697c44f1aeSWeston Andros Adamson int status; 70707c44f1aeSWeston Andros Adamson 70717c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr); 70727c44f1aeSWeston Andros Adamson if (!status) 70737c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res); 70747c44f1aeSWeston Andros Adamson return status; 70757c44f1aeSWeston Andros Adamson } 70767c44f1aeSWeston Andros Adamson 70777c44f1aeSWeston Andros Adamson /* 70788b173218SRicardo Labiaga * Decode EXCHANGE_ID response 707999fe60d0SBenny Halevy */ 7080bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, 7081bf269551SChuck Lever struct xdr_stream *xdr, 708299fe60d0SBenny Halevy void *res) 708399fe60d0SBenny Halevy { 708499fe60d0SBenny Halevy struct compound_hdr hdr; 708599fe60d0SBenny Halevy int status; 708699fe60d0SBenny Halevy 7087bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 708899fe60d0SBenny Halevy if (!status) 7089bf269551SChuck Lever status = decode_exchange_id(xdr, res); 709099fe60d0SBenny Halevy return status; 709199fe60d0SBenny Halevy } 70922050f0ccSAndy Adamson 70932050f0ccSAndy Adamson /* 70948b173218SRicardo Labiaga * Decode CREATE_SESSION response 7095fc931582SAndy Adamson */ 7096bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, 7097bf269551SChuck Lever struct xdr_stream *xdr, 7098fc931582SAndy Adamson struct nfs41_create_session_res *res) 7099fc931582SAndy Adamson { 7100fc931582SAndy Adamson struct compound_hdr hdr; 7101fc931582SAndy Adamson int status; 7102fc931582SAndy Adamson 7103bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7104fc931582SAndy Adamson if (!status) 7105bf269551SChuck Lever status = decode_create_session(xdr, res); 7106fc931582SAndy Adamson return status; 7107fc931582SAndy Adamson } 7108fc931582SAndy Adamson 7109fc931582SAndy Adamson /* 71108b173218SRicardo Labiaga * Decode DESTROY_SESSION response 71110f3e66c6SAndy Adamson */ 7112bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, 7113bf269551SChuck Lever struct xdr_stream *xdr, 7114bf269551SChuck Lever void *res) 71150f3e66c6SAndy Adamson { 71160f3e66c6SAndy Adamson struct compound_hdr hdr; 71170f3e66c6SAndy Adamson int status; 71180f3e66c6SAndy Adamson 7119bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71200f3e66c6SAndy Adamson if (!status) 7121bf269551SChuck Lever status = decode_destroy_session(xdr, res); 71220f3e66c6SAndy Adamson return status; 71230f3e66c6SAndy Adamson } 71240f3e66c6SAndy Adamson 71250f3e66c6SAndy Adamson /* 712666245539STrond Myklebust * Decode DESTROY_CLIENTID response 712766245539STrond Myklebust */ 712866245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp, 712966245539STrond Myklebust struct xdr_stream *xdr, 713066245539STrond Myklebust void *res) 713166245539STrond Myklebust { 713266245539STrond Myklebust struct compound_hdr hdr; 713366245539STrond Myklebust int status; 713466245539STrond Myklebust 713566245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr); 713666245539STrond Myklebust if (!status) 713766245539STrond Myklebust status = decode_destroy_clientid(xdr, res); 713866245539STrond Myklebust return status; 713966245539STrond Myklebust } 714066245539STrond Myklebust 714166245539STrond Myklebust /* 71428b173218SRicardo Labiaga * Decode SEQUENCE response 7143fc01cea9SAndy Adamson */ 7144bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, 7145bf269551SChuck Lever struct xdr_stream *xdr, 7146fc01cea9SAndy Adamson struct nfs4_sequence_res *res) 7147fc01cea9SAndy Adamson { 7148fc01cea9SAndy Adamson struct compound_hdr hdr; 7149fc01cea9SAndy Adamson int status; 7150fc01cea9SAndy Adamson 7151bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7152fc01cea9SAndy Adamson if (!status) 7153bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp); 7154fc01cea9SAndy Adamson return status; 7155fc01cea9SAndy Adamson } 7156fc01cea9SAndy Adamson 7157fc01cea9SAndy Adamson /* 71588b173218SRicardo Labiaga * Decode GET_LEASE_TIME response 71592050f0ccSAndy Adamson */ 7160bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, 7161bf269551SChuck Lever struct xdr_stream *xdr, 71622050f0ccSAndy Adamson struct nfs4_get_lease_time_res *res) 71632050f0ccSAndy Adamson { 71642050f0ccSAndy Adamson struct compound_hdr hdr; 71652050f0ccSAndy Adamson int status; 71662050f0ccSAndy Adamson 7167bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 71682050f0ccSAndy Adamson if (!status) 7169bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp); 71702050f0ccSAndy Adamson if (!status) 7171bf269551SChuck Lever status = decode_putrootfh(xdr); 71722050f0ccSAndy Adamson if (!status) 7173bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo); 71742050f0ccSAndy Adamson return status; 71752050f0ccSAndy Adamson } 717618019753SRicardo Labiaga 717718019753SRicardo Labiaga /* 717818019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response 717918019753SRicardo Labiaga */ 7180bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, 7181bf269551SChuck Lever struct xdr_stream *xdr, 718218019753SRicardo Labiaga struct nfs41_reclaim_complete_res *res) 718318019753SRicardo Labiaga { 718418019753SRicardo Labiaga struct compound_hdr hdr; 718518019753SRicardo Labiaga int status; 718618019753SRicardo Labiaga 7187bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 718818019753SRicardo Labiaga if (!status) 7189bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 719018019753SRicardo Labiaga if (!status) 71918ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL); 719218019753SRicardo Labiaga return status; 719318019753SRicardo Labiaga } 7194b1f69b75SAndy Adamson 7195b1f69b75SAndy Adamson /* 7196b1f69b75SAndy Adamson * Decode GETDEVINFO response 7197b1f69b75SAndy Adamson */ 7198bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, 7199bf269551SChuck Lever struct xdr_stream *xdr, 7200b1f69b75SAndy Adamson struct nfs4_getdeviceinfo_res *res) 7201b1f69b75SAndy Adamson { 7202b1f69b75SAndy Adamson struct compound_hdr hdr; 7203b1f69b75SAndy Adamson int status; 7204b1f69b75SAndy Adamson 7205bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7206b1f69b75SAndy Adamson if (status != 0) 7207b1f69b75SAndy Adamson goto out; 7208bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7209b1f69b75SAndy Adamson if (status != 0) 7210b1f69b75SAndy Adamson goto out; 72114e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res); 7212b1f69b75SAndy Adamson out: 7213b1f69b75SAndy Adamson return status; 7214b1f69b75SAndy Adamson } 7215b1f69b75SAndy Adamson 7216b1f69b75SAndy Adamson /* 7217b1f69b75SAndy Adamson * Decode LAYOUTGET response 7218b1f69b75SAndy Adamson */ 7219bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, 7220bf269551SChuck Lever struct xdr_stream *xdr, 7221b1f69b75SAndy Adamson struct nfs4_layoutget_res *res) 7222b1f69b75SAndy Adamson { 7223b1f69b75SAndy Adamson struct compound_hdr hdr; 7224b1f69b75SAndy Adamson int status; 7225b1f69b75SAndy Adamson 7226bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr); 7227b1f69b75SAndy Adamson if (status) 7228b1f69b75SAndy Adamson goto out; 7229bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp); 7230b1f69b75SAndy Adamson if (status) 7231b1f69b75SAndy Adamson goto out; 7232bf269551SChuck Lever status = decode_putfh(xdr); 7233b1f69b75SAndy Adamson if (status) 7234b1f69b75SAndy Adamson goto out; 7235bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res); 7236b1f69b75SAndy Adamson out: 7237b1f69b75SAndy Adamson return status; 7238b1f69b75SAndy Adamson } 7239863a3c6cSAndy Adamson 7240863a3c6cSAndy Adamson /* 7241cbe82603SBenny Halevy * Decode LAYOUTRETURN response 7242cbe82603SBenny Halevy */ 7243cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp, 7244cbe82603SBenny Halevy struct xdr_stream *xdr, 7245cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res) 7246cbe82603SBenny Halevy { 7247cbe82603SBenny Halevy struct compound_hdr hdr; 7248cbe82603SBenny Halevy int status; 7249cbe82603SBenny Halevy 7250cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr); 7251cbe82603SBenny Halevy if (status) 7252cbe82603SBenny Halevy goto out; 7253cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp); 7254cbe82603SBenny Halevy if (status) 7255cbe82603SBenny Halevy goto out; 7256cbe82603SBenny Halevy status = decode_putfh(xdr); 7257cbe82603SBenny Halevy if (status) 7258cbe82603SBenny Halevy goto out; 7259cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res); 7260cbe82603SBenny Halevy out: 7261cbe82603SBenny Halevy return status; 7262cbe82603SBenny Halevy } 7263cbe82603SBenny Halevy 7264cbe82603SBenny Halevy /* 7265863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response 7266863a3c6cSAndy Adamson */ 7267863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp, 7268863a3c6cSAndy Adamson struct xdr_stream *xdr, 7269863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res) 7270863a3c6cSAndy Adamson { 7271863a3c6cSAndy Adamson struct compound_hdr hdr; 7272863a3c6cSAndy Adamson int status; 7273863a3c6cSAndy Adamson 7274863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr); 7275863a3c6cSAndy Adamson if (status) 7276863a3c6cSAndy Adamson goto out; 7277863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp); 7278863a3c6cSAndy Adamson if (status) 7279863a3c6cSAndy Adamson goto out; 7280863a3c6cSAndy Adamson status = decode_putfh(xdr); 7281863a3c6cSAndy Adamson if (status) 7282863a3c6cSAndy Adamson goto out; 7283863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res); 7284863a3c6cSAndy Adamson if (status) 7285863a3c6cSAndy Adamson goto out; 72866926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server); 7287863a3c6cSAndy Adamson out: 7288863a3c6cSAndy Adamson return status; 7289863a3c6cSAndy Adamson } 7290fca78d6dSBryan Schumaker 7291fca78d6dSBryan Schumaker /* 7292fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response 7293fca78d6dSBryan Schumaker */ 7294fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp, 7295fca78d6dSBryan Schumaker struct xdr_stream *xdr, 7296fca78d6dSBryan Schumaker struct nfs4_secinfo_res *res) 7297fca78d6dSBryan Schumaker { 7298fca78d6dSBryan Schumaker struct compound_hdr hdr; 7299fca78d6dSBryan Schumaker int status; 7300fca78d6dSBryan Schumaker 7301fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 7302fca78d6dSBryan Schumaker if (status) 7303fca78d6dSBryan Schumaker goto out; 7304fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 7305fca78d6dSBryan Schumaker if (status) 7306fca78d6dSBryan Schumaker goto out; 7307fca78d6dSBryan Schumaker status = decode_putrootfh(xdr); 7308fca78d6dSBryan Schumaker if (status) 7309fca78d6dSBryan Schumaker goto out; 731031e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res); 7311fca78d6dSBryan Schumaker out: 7312fca78d6dSBryan Schumaker return status; 7313fca78d6dSBryan Schumaker } 73147d974794SBryan Schumaker 73157d974794SBryan Schumaker /* 73167d974794SBryan Schumaker * Decode TEST_STATEID response 73177d974794SBryan Schumaker */ 73187d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp, 73197d974794SBryan Schumaker struct xdr_stream *xdr, 73207d974794SBryan Schumaker struct nfs41_test_stateid_res *res) 73217d974794SBryan Schumaker { 73227d974794SBryan Schumaker struct compound_hdr hdr; 73237d974794SBryan Schumaker int status; 73247d974794SBryan Schumaker 73257d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 73267d974794SBryan Schumaker if (status) 73277d974794SBryan Schumaker goto out; 73287d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 73297d974794SBryan Schumaker if (status) 73307d974794SBryan Schumaker goto out; 73317d974794SBryan Schumaker status = decode_test_stateid(xdr, res); 73327d974794SBryan Schumaker out: 73337d974794SBryan Schumaker return status; 73347d974794SBryan Schumaker } 73359aeda35fSBryan Schumaker 73369aeda35fSBryan Schumaker /* 73379aeda35fSBryan Schumaker * Decode FREE_STATEID response 73389aeda35fSBryan Schumaker */ 73399aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp, 73409aeda35fSBryan Schumaker struct xdr_stream *xdr, 73419aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res) 73429aeda35fSBryan Schumaker { 73439aeda35fSBryan Schumaker struct compound_hdr hdr; 73449aeda35fSBryan Schumaker int status; 73459aeda35fSBryan Schumaker 73469aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr); 73479aeda35fSBryan Schumaker if (status) 73489aeda35fSBryan Schumaker goto out; 73499aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp); 73509aeda35fSBryan Schumaker if (status) 73519aeda35fSBryan Schumaker goto out; 73529aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res); 73539aeda35fSBryan Schumaker out: 73549aeda35fSBryan Schumaker return status; 73559aeda35fSBryan Schumaker } 735699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 735799fe60d0SBenny Halevy 7358573c4e1eSChuck Lever /** 7359573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in 7360573c4e1eSChuck Lever * the local page cache. 7361573c4e1eSChuck Lever * @xdr: XDR stream where entry resides 7362573c4e1eSChuck Lever * @entry: buffer to fill in with entry data 7363573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry 7364573c4e1eSChuck Lever * 7365573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is 7366573c4e1eSChuck Lever * returned. 7367573c4e1eSChuck Lever * 7368573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but 7369573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call 7370573c4e1eSChuck Lever * on a directory already in our cache. 7371573c4e1eSChuck Lever */ 7372573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 7373573c4e1eSChuck Lever int plus) 73741da177e4SLinus Torvalds { 7375256e48bbSTrond Myklebust unsigned int savep; 7376dae100c2SFred Isaman uint32_t bitmap[3] = {0}; 73771da177e4SLinus Torvalds uint32_t len; 7378babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4); 7379babddc72SBryan Schumaker if (unlikely(!p)) 7380babddc72SBryan Schumaker goto out_overflow; 7381c08e76d0SChuck Lever if (*p == xdr_zero) { 7382babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4); 7383babddc72SBryan Schumaker if (unlikely(!p)) 7384babddc72SBryan Schumaker goto out_overflow; 7385c08e76d0SChuck Lever if (*p == xdr_zero) 7386573c4e1eSChuck Lever return -EAGAIN; 73871da177e4SLinus Torvalds entry->eof = 1; 7388573c4e1eSChuck Lever return -EBADCOOKIE; 73891da177e4SLinus Torvalds } 73901da177e4SLinus Torvalds 7391babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12); 7392babddc72SBryan Schumaker if (unlikely(!p)) 7393babddc72SBryan Schumaker goto out_overflow; 73941da177e4SLinus Torvalds entry->prev_cookie = entry->cookie; 73951da177e4SLinus Torvalds p = xdr_decode_hyper(p, &entry->cookie); 7396c08e76d0SChuck Lever entry->len = be32_to_cpup(p); 7397babddc72SBryan Schumaker 73989af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len); 7399babddc72SBryan Schumaker if (unlikely(!p)) 7400babddc72SBryan Schumaker goto out_overflow; 74011da177e4SLinus Torvalds entry->name = (const char *) p; 74021da177e4SLinus Torvalds 74031da177e4SLinus Torvalds /* 74041da177e4SLinus Torvalds * In case the server doesn't return an inode number, 74051da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0, 74061da177e4SLinus Torvalds * since glibc seems to choke on it...) 74071da177e4SLinus Torvalds */ 74081da177e4SLinus Torvalds entry->ino = 1; 74094f082222STrond Myklebust entry->fattr->valid = 0; 74101da177e4SLinus Torvalds 74119af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0) 7412babddc72SBryan Schumaker goto out_overflow; 74139af8c222STrond Myklebust 7414256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0) 7415babddc72SBryan Schumaker goto out_overflow; 74169af8c222STrond Myklebust 7417573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 7418aa9c2669SDavid Quigley NULL, entry->label, entry->server) < 0) 7419babddc72SBryan Schumaker goto out_overflow; 742028331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 742128331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid; 742228331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 742382f2e547SBryan Schumaker entry->ino = entry->fattr->fileid; 74249af8c222STrond Myklebust 74250b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN; 74260b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE) 74270b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 74280b26a0bfSTrond Myklebust 7429573c4e1eSChuck Lever return 0; 7430babddc72SBryan Schumaker 7431babddc72SBryan Schumaker out_overflow: 7432babddc72SBryan Schumaker print_overflow_msg(__func__, xdr); 7433573c4e1eSChuck Lever return -EAGAIN; 74341da177e4SLinus Torvalds } 74351da177e4SLinus Torvalds 74361da177e4SLinus Torvalds /* 74371da177e4SLinus Torvalds * We need to translate between nfs status return values and 74381da177e4SLinus Torvalds * the local errno values which may not be the same. 74391da177e4SLinus Torvalds */ 74401da177e4SLinus Torvalds static struct { 74411da177e4SLinus Torvalds int stat; 74421da177e4SLinus Torvalds int errno; 74431da177e4SLinus Torvalds } nfs_errtbl[] = { 74441da177e4SLinus Torvalds { NFS4_OK, 0 }, 7445856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM }, 7446856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT }, 7447856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO}, 7448856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO }, 7449856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES }, 7450856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST }, 7451856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV }, 7452856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR }, 7453856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR }, 7454856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL }, 7455856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG }, 7456856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC }, 7457856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS }, 7458856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK }, 7459856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, 7460856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, 7461856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT }, 7462856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE }, 7463856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE }, 7464856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, 7465856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP }, 7466856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL }, 7467fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO }, 7468856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE }, 7469856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN }, 7470856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP }, 7471856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, 7472856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK }, 7473856dff3dSBenny Halevy { -1, -EIO } 74741da177e4SLinus Torvalds }; 74751da177e4SLinus Torvalds 74761da177e4SLinus Torvalds /* 74771da177e4SLinus Torvalds * Convert an NFS error code to a local one. 74781da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3. 74791da177e4SLinus Torvalds */ 74801da177e4SLinus Torvalds static int 74810a8ea437SDavid Howells nfs4_stat_to_errno(int stat) 74821da177e4SLinus Torvalds { 74831da177e4SLinus Torvalds int i; 74841da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) { 74851da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat) 74861da177e4SLinus Torvalds return nfs_errtbl[i].errno; 74871da177e4SLinus Torvalds } 74881da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) { 74891da177e4SLinus Torvalds /* The server is looney tunes. */ 7490fdcb4577STrond Myklebust return -EREMOTEIO; 74911da177e4SLinus Torvalds } 74921da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should 74931da177e4SLinus Torvalds * handle it. 74941da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should 74951da177e4SLinus Torvalds * not conflict with native Linux error codes. 74961da177e4SLinus Torvalds */ 7497856dff3dSBenny Halevy return -stat; 74981da177e4SLinus Torvalds } 74991da177e4SLinus Torvalds 75001c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 75011c6dcbe5SAnna Schumaker #include "nfs42xdr.c" 75021c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 75031c6dcbe5SAnna Schumaker 75041da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \ 75051da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \ 75061da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \ 75079f06c719SChuck Lever .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ 7508bf269551SChuck Lever .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ 75092bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \ 75102bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \ 7511cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \ 7512cc0175c1SChuck Lever .p_name = #proc, \ 75131da177e4SLinus Torvalds } 75141da177e4SLinus Torvalds 75157c61f0d3SAnna Schumaker #define STUB(proc) \ 75167c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \ 75177c61f0d3SAnna Schumaker .p_name = #proc, \ 75187c61f0d3SAnna Schumaker } 75197c61f0d3SAnna Schumaker 75201da177e4SLinus Torvalds struct rpc_procinfo nfs4_procedures[] = { 75211da177e4SLinus Torvalds PROC(READ, enc_read, dec_read), 75221da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write), 75231da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit), 75241da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open), 75251da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), 75261da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), 75271da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), 75281da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close), 75291da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr), 75301da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo), 75311da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew), 75321da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 75331da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 75341da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock), 75351da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt), 75361da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku), 75371da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access), 75381da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr), 75391da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup), 75401da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), 75411da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove), 75421da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename), 75431da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link), 75441da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink), 75451da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create), 75461da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf), 75471da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs), 75481da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink), 75491da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir), 75501da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), 75511da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), 7552029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl), 755323ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl), 7554683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7555d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 75565a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo), 755744c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 755899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1) 755999fe60d0SBenny Halevy PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), 7560fc931582SAndy Adamson PROC(CREATE_SESSION, enc_create_session, dec_create_session), 75610f3e66c6SAndy Adamson PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), 7562fc01cea9SAndy Adamson PROC(SEQUENCE, enc_sequence, dec_sequence), 75632050f0ccSAndy Adamson PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), 756418019753SRicardo Labiaga PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), 7565b1f69b75SAndy Adamson PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), 7566b1f69b75SAndy Adamson PROC(LAYOUTGET, enc_layoutget, dec_layoutget), 7567863a3c6cSAndy Adamson PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit), 7568cbe82603SBenny Halevy PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn), 7569fca78d6dSBryan Schumaker PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 75707d974794SBryan Schumaker PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 75719aeda35fSBryan Schumaker PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 75727c61f0d3SAnna Schumaker STUB(GETDEVICELIST), 7573ad24ecfbSTrond Myklebust PROC(BIND_CONN_TO_SESSION, 7574ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session), 757566245539STrond Myklebust PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 757699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */ 75771c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2 75781c6dcbe5SAnna Schumaker PROC(SEEK, enc_seek, dec_seek), 7579f4ac1674SAnna Schumaker PROC(ALLOCATE, enc_allocate, dec_allocate), 7580624bd5b7SAnna Schumaker PROC(DEALLOCATE, enc_deallocate, dec_deallocate), 7581be3a5d23STrond Myklebust PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats), 758236022770SPeng Tao PROC(CLONE, enc_clone, dec_clone), 75832e72448bSAnna Schumaker PROC(COPY, enc_copy, dec_copy), 75841c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */ 75851da177e4SLinus Torvalds }; 75861da177e4SLinus Torvalds 7587a613fa16STrond Myklebust const struct rpc_version nfs_version4 = { 75881da177e4SLinus Torvalds .number = 4, 7589e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures), 75901da177e4SLinus Torvalds .procs = nfs4_procedures 75911da177e4SLinus Torvalds }; 75921da177e4SLinus Torvalds 75931da177e4SLinus Torvalds /* 75941da177e4SLinus Torvalds * Local variables: 75951da177e4SLinus Torvalds * c-basic-offset: 8 75961da177e4SLinus Torvalds * End: 75971da177e4SLinus Torvalds */ 7598