xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision 73504740)
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>
55dff25ddbSAndreas Gruenbacher #include <linux/fs_struct.h>
56f092075dSChuck Lever 
574ce79717STrond Myklebust #include "nfs4_fs.h"
584882ef72SAlexandros Batsakis #include "internal.h"
5940c64c26SAnna Schumaker #include "nfs4idmap.h"
6076e697baSTrond Myklebust #include "nfs4session.h"
61b1f69b75SAndy Adamson #include "pnfs.h"
62f092075dSChuck Lever #include "netns.h"
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_XDR
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
671da177e4SLinus Torvalds #define errno_NFSERR_IO		EIO
681da177e4SLinus Torvalds 
690a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
721da177e4SLinus Torvalds #ifdef DEBUG
731da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		20
741da177e4SLinus Torvalds #else
751da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		0
761da177e4SLinus Torvalds #endif
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds /* lock,open owner id:
799f958ab8STrond Myklebust  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
801da177e4SLinus Torvalds  */
8195b72eb0STrond Myklebust #define open_owner_id_maxsz	(1 + 2 + 1 + 1 + 2)
82d035c36cSTrond Myklebust #define lock_owner_id_maxsz	(1 + 1 + 4)
839104a55dSTrond Myklebust #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
841da177e4SLinus Torvalds #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
851da177e4SLinus Torvalds #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
861da177e4SLinus Torvalds #define op_encode_hdr_maxsz	(1)
871da177e4SLinus Torvalds #define op_decode_hdr_maxsz	(2)
889104a55dSTrond Myklebust #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
899104a55dSTrond Myklebust #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
909104a55dSTrond Myklebust #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
919104a55dSTrond Myklebust #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
921da177e4SLinus Torvalds #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
931da177e4SLinus Torvalds 				(NFS4_FHSIZE >> 2))
941da177e4SLinus Torvalds #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
951da177e4SLinus Torvalds #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
961da177e4SLinus Torvalds #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
971da177e4SLinus Torvalds #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
981da177e4SLinus Torvalds #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
991da177e4SLinus Torvalds 				((3+NFS4_FHSIZE) >> 2))
100e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
10196928206SJ. Bruce Fields #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1021da177e4SLinus Torvalds #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
1031da177e4SLinus Torvalds #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
104bd625ba8STrond Myklebust #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
105bd625ba8STrond Myklebust #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
106aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL
107aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108aa9c2669SDavid Quigley #define	nfs4_label_maxsz	(4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
109aa9c2669SDavid Quigley #else
110aa9c2669SDavid Quigley #define	nfs4_label_maxsz	0
111aa9c2669SDavid Quigley #endif
11288034c3dSAndy Adamson /* We support only one layout type per file system */
11388034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
11496928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
11596928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
11688034c3dSAndy Adamson 				3 + 3 + 3 + nfs4_owner_maxsz + \
117aa9c2669SDavid Quigley 				nfs4_group_maxsz + nfs4_label_maxsz + \
118aa9c2669SDavid Quigley 				 decode_mdsthreshold_maxsz))
11996928206SJ. Bruce Fields #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
12096928206SJ. Bruce Fields 				nfs4_fattr_value_maxsz)
12196928206SJ. Bruce Fields #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1229104a55dSTrond Myklebust #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
1239104a55dSTrond Myklebust 				 1 + 2 + 1 + \
1249104a55dSTrond Myklebust 				nfs4_owner_maxsz + \
1259104a55dSTrond Myklebust 				nfs4_group_maxsz + \
126aa9c2669SDavid Quigley 				nfs4_label_maxsz + \
1279104a55dSTrond Myklebust 				4 + 4)
1281da177e4SLinus Torvalds #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
1291da177e4SLinus Torvalds #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
13056ae19f3STrond Myklebust #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
13156ae19f3STrond Myklebust #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
1322f42b5d0SFred Isaman #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
133dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
134dae100c2SFred Isaman  * layout types will be returned.
135dae100c2SFred Isaman  */
136dae100c2SFred Isaman #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
137dae100c2SFred Isaman 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1381da177e4SLinus Torvalds #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
1391da177e4SLinus Torvalds #define decode_renew_maxsz	(op_decode_hdr_maxsz)
1401da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1411da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
142cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
143b8fb2f59SJeff Layton 				/* client name */ \
144b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
145cc38bac3SChuck Lever 				1 /* sc_prog */ + \
1466dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1476dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
148cc38bac3SChuck Lever 				1) /* sc_cb_ident */
1491da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1501da177e4SLinus Torvalds 				(op_decode_hdr_maxsz + \
1516dd3436bSChuck Lever 				2 /* clientid */ + \
1526dd3436bSChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
1536dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1546dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
1551da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1561da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
1571da177e4SLinus Torvalds 				3 + (NFS4_VERIFIER_SIZE >> 2))
1581da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1591da177e4SLinus Torvalds 				(op_decode_hdr_maxsz)
160e6889620STrond Myklebust #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
161e6889620STrond Myklebust #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
1622cebf828STrond Myklebust #define encode_share_access_maxsz \
1632cebf828STrond Myklebust 				(2)
1644882ef72SAlexandros Batsakis #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
1652cebf828STrond Myklebust #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
1662cebf828STrond Myklebust #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
1672cebf828STrond Myklebust #define encode_open_maxsz	(op_encode_hdr_maxsz + \
1682cebf828STrond Myklebust 				2 + encode_share_access_maxsz + 2 + \
1692cebf828STrond Myklebust 				open_owner_id_maxsz + \
1702cebf828STrond Myklebust 				encode_opentype_maxsz + \
1712cebf828STrond Myklebust 				encode_claim_null_maxsz)
1725a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz	(3)
1732cebf828STrond Myklebust #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
1749104a55dSTrond Myklebust #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
1755a1f6d9eSTrond Myklebust 				decode_space_limit_maxsz + \
1762cebf828STrond Myklebust 				decode_ace_maxsz)
1772cebf828STrond Myklebust #define decode_change_info_maxsz	(5)
1782cebf828STrond Myklebust #define decode_open_maxsz	(op_decode_hdr_maxsz + \
1799104a55dSTrond Myklebust 				decode_stateid_maxsz + \
1802cebf828STrond Myklebust 				decode_change_info_maxsz + 1 + \
1812cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz + \
1822cebf828STrond Myklebust 				decode_delegation_maxsz)
1839104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
1849104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1859104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1)
1869104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
1879104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1889104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1899104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
1909104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1919104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1 + \
1929104a55dSTrond Myklebust 				 encode_share_access_maxsz)
1939104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
1949104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1959104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1969104a55dSTrond Myklebust #define encode_close_maxsz	(op_encode_hdr_maxsz + \
1979104a55dSTrond Myklebust 				 1 + encode_stateid_maxsz)
1989104a55dSTrond Myklebust #define decode_close_maxsz	(op_decode_hdr_maxsz + \
1999104a55dSTrond Myklebust 				 decode_stateid_maxsz)
2009104a55dSTrond Myklebust #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
2019104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2029104a55dSTrond Myklebust 				 encode_attrs_maxsz)
2039104a55dSTrond Myklebust #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
2049104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz)
2059104a55dSTrond Myklebust #define encode_read_maxsz	(op_encode_hdr_maxsz + \
2069104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2079104a55dSTrond Myklebust #define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
2089104a55dSTrond Myklebust #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
209aa9c2669SDavid Quigley 				 2 + encode_verifier_maxsz + 5 + \
210aa9c2669SDavid Quigley 				nfs4_label_maxsz)
2119104a55dSTrond Myklebust #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
212a7697f6fSChuck Lever 				 decode_verifier_maxsz)
2139104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
2149104a55dSTrond Myklebust #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
2159104a55dSTrond Myklebust #define encode_write_maxsz	(op_encode_hdr_maxsz + \
2169104a55dSTrond Myklebust 				 encode_stateid_maxsz + 4)
2179104a55dSTrond Myklebust #define decode_write_maxsz	(op_decode_hdr_maxsz + \
2189104a55dSTrond Myklebust 				 2 + decode_verifier_maxsz)
2199104a55dSTrond Myklebust #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
2209104a55dSTrond Myklebust #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
2219104a55dSTrond Myklebust 				 decode_verifier_maxsz)
2221da177e4SLinus Torvalds #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
2231da177e4SLinus Torvalds 				nfs4_name_maxsz)
2246ce18391SBenny Halevy #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
2256ce18391SBenny Halevy 				 decode_change_info_maxsz)
2261da177e4SLinus Torvalds #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
2271da177e4SLinus Torvalds 				2 * nfs4_name_maxsz)
2286ce18391SBenny Halevy #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
2296ce18391SBenny Halevy 				 decode_change_info_maxsz + \
2306ce18391SBenny Halevy 				 decode_change_info_maxsz)
2311da177e4SLinus Torvalds #define encode_link_maxsz	(op_encode_hdr_maxsz + \
2321da177e4SLinus Torvalds 				nfs4_name_maxsz)
2336ce18391SBenny Halevy #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
234daccbdedSTrond Myklebust #define encode_lockowner_maxsz	(7)
2359104a55dSTrond Myklebust #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
2369104a55dSTrond Myklebust 				 7 + \
237daccbdedSTrond Myklebust 				 1 + encode_stateid_maxsz + 1 + \
238daccbdedSTrond Myklebust 				 encode_lockowner_maxsz)
2399104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2409104a55dSTrond Myklebust 				(8 + decode_lockowner_maxsz)
2419104a55dSTrond Myklebust #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
2429104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
243daccbdedSTrond Myklebust #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
244daccbdedSTrond Myklebust 				encode_lockowner_maxsz)
2459104a55dSTrond Myklebust #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
2469104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
2479104a55dSTrond Myklebust #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
2489104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2499104a55dSTrond Myklebust 				 4)
2509104a55dSTrond Myklebust #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
2519104a55dSTrond Myklebust 				 decode_stateid_maxsz)
252d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
253d3c7b7ccSTrond Myklebust 				(op_encode_hdr_maxsz + \
254d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
255d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
256d3c7b7ccSTrond Myklebust 				(op_decode_hdr_maxsz)
2579104a55dSTrond Myklebust #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
2589104a55dSTrond Myklebust #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
2591da177e4SLinus Torvalds #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
2601da177e4SLinus Torvalds 				1 + nfs4_name_maxsz + \
26194a6d753SChuck Lever 				1 + \
26296928206SJ. Bruce Fields 				nfs4_fattr_maxsz)
2631da177e4SLinus Torvalds #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
2641da177e4SLinus Torvalds #define encode_create_maxsz	(op_encode_hdr_maxsz + \
2659104a55dSTrond Myklebust 				1 + 2 + nfs4_name_maxsz + \
2669104a55dSTrond Myklebust 				encode_attrs_maxsz)
2672cebf828STrond Myklebust #define decode_create_maxsz	(op_decode_hdr_maxsz + \
2682cebf828STrond Myklebust 				decode_change_info_maxsz + \
2692cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz)
2709104a55dSTrond Myklebust #define encode_statfs_maxsz	(encode_getattr_maxsz)
2719104a55dSTrond Myklebust #define decode_statfs_maxsz	(decode_getattr_maxsz)
2721da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2731da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2749104a55dSTrond Myklebust #define encode_getacl_maxsz	(encode_getattr_maxsz)
2759104a55dSTrond Myklebust #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
2769104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz + 1)
2779104a55dSTrond Myklebust #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
2789104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2799104a55dSTrond Myklebust #define decode_setacl_maxsz	(decode_setattr_maxsz)
280e6889620STrond Myklebust #define encode_fs_locations_maxsz \
281e6889620STrond Myklebust 				(encode_getattr_maxsz)
282e6889620STrond Myklebust #define decode_fs_locations_maxsz \
283e6889620STrond Myklebust 				(0)
2845a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
2851650add2SBryan Schumaker #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
2869b7b9fccSAndy Adamson 
2879b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
288fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
289d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
290d751f748SJim Rees 			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
291fc931582SAndy Adamson 
29299fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
29399fe60d0SBenny Halevy 				encode_verifier_maxsz + \
29499fe60d0SBenny Halevy 				1 /* co_ownerid.len */ + \
295b8fb2f59SJeff Layton 				/* eia_clientowner */ \
296b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
29799fe60d0SBenny Halevy 				1 /* flags */ + \
29899fe60d0SBenny Halevy 				1 /* spa_how */ + \
2992031cd1aSWeston Andros Adamson 				/* max is SP4_MACH_CRED (for now) */ + \
3002031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
3012031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
302db8ac8baSWeston Andros Adamson 				1 /* implementation id array of size 1 */ + \
303db8ac8baSWeston Andros Adamson 				1 /* nii_domain */ + \
304db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
305db8ac8baSWeston Andros Adamson 				1 /* nii_name */ + \
306d751f748SJim Rees 				XDR_QUADLEN(IMPL_NAME_LIMIT) + \
307db8ac8baSWeston Andros Adamson 				3 /* nii_date */)
30899fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
30999fe60d0SBenny Halevy 				2 /* eir_clientid */ + \
31099fe60d0SBenny Halevy 				1 /* eir_sequenceid */ + \
31199fe60d0SBenny Halevy 				1 /* eir_flags */ + \
31299fe60d0SBenny Halevy 				1 /* spr_how */ + \
3132031cd1aSWeston Andros Adamson 				  /* max is SP4_MACH_CRED (for now) */ + \
3142031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
3152031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
31699fe60d0SBenny Halevy 				2 /* eir_server_owner.so_minor_id */ + \
31799fe60d0SBenny Halevy 				/* eir_server_owner.so_major_id<> */ \
31899fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
31999fe60d0SBenny Halevy 				/* eir_server_scope<> */ \
32099fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
32199fe60d0SBenny Halevy 				1 /* eir_server_impl_id array length */ + \
3227d2ed9acSWeston Andros Adamson 				1 /* nii_domain */ + \
3237d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3247d2ed9acSWeston Andros Adamson 				1 /* nii_name */ + \
3257d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3267d2ed9acSWeston Andros Adamson 				3 /* nii_date */)
327fc931582SAndy Adamson #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
328fc931582SAndy Adamson #define decode_channel_attrs_maxsz  (6 + \
329fc931582SAndy Adamson 				     1 /* ca_rdma_ird.len */ + \
330fc931582SAndy Adamson 				     1 /* ca_rdma_ird */)
331fc931582SAndy Adamson #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
332fc931582SAndy Adamson 				     2 /* csa_clientid */ + \
333fc931582SAndy Adamson 				     1 /* csa_sequence */ + \
334fc931582SAndy Adamson 				     1 /* csa_flags */ + \
335fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
336fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
337fc931582SAndy Adamson 				     1 /* csa_cb_program */ + \
338fc931582SAndy Adamson 				     1 /* csa_sec_parms.len (1) */ + \
339fc931582SAndy Adamson 				     1 /* cb_secflavor (AUTH_SYS) */ + \
340fc931582SAndy Adamson 				     1 /* stamp */ + \
341fc931582SAndy Adamson 				     1 /* machinename.len */ + \
342fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
343fc931582SAndy Adamson 				     1 /* uid */ + \
344fc931582SAndy Adamson 				     1 /* gid */ + \
345fc931582SAndy Adamson 				     1 /* gids.len (0) */)
346fc931582SAndy Adamson #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
347fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
348fc931582SAndy Adamson 				     1 /* csr_sequence */ + \
349fc931582SAndy Adamson 				     1 /* csr_flags */ + \
350fc931582SAndy Adamson 				     decode_channel_attrs_maxsz + \
351fc931582SAndy Adamson 				     decode_channel_attrs_maxsz)
3527c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
3537c44f1aeSWeston Andros Adamson 				     /* bctsa_sessid */ \
3547c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3557c44f1aeSWeston Andros Adamson 				     1 /* bctsa_dir */ + \
3567c44f1aeSWeston Andros Adamson 				     1 /* bctsa_use_conn_in_rdma_mode */)
3577c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +	\
3587c44f1aeSWeston Andros Adamson 				     /* bctsr_sessid */ \
3597c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3607c44f1aeSWeston Andros Adamson 				     1 /* bctsr_dir */ + \
3617c44f1aeSWeston Andros Adamson 				     1 /* bctsr_use_conn_in_rdma_mode */)
3620f3e66c6SAndy Adamson #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
3630f3e66c6SAndy Adamson #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
36466245539STrond Myklebust #define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
36566245539STrond Myklebust #define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
366fc01cea9SAndy Adamson #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
367fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
368fc01cea9SAndy Adamson #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
369fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
37018019753SRicardo Labiaga #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
37118019753SRicardo Labiaga #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
37284c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
37384c9dee3SChristoph Hellwig 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
37484c9dee3SChristoph Hellwig 				1 /* layout type */ + \
37584c9dee3SChristoph Hellwig 				1 /* maxcount */ + \
37684c9dee3SChristoph Hellwig 				1 /* bitmap size */ + \
37784c9dee3SChristoph Hellwig 				1 /* notification bitmap length */ + \
37884c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
379b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380b1f69b75SAndy Adamson 				1 /* layout type */ + \
381b1f69b75SAndy Adamson 				1 /* opaque devaddr4 length */ + \
382b1f69b75SAndy Adamson 				  /* devaddr4 payload is read into page */ \
383b1f69b75SAndy Adamson 				1 /* notification bitmap length */ + \
38484c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
385b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
386b1f69b75SAndy Adamson 				encode_stateid_maxsz)
387b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
388b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
389b1f69b75SAndy Adamson 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
390863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
391863a3c6cSAndy Adamson 				2 /* offset */ + \
392863a3c6cSAndy Adamson 				2 /* length */ + \
393863a3c6cSAndy Adamson 				1 /* reclaim */ + \
394863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
395863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
396863a3c6cSAndy Adamson 				2 /* last byte written */ + \
397863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
398863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
3995f919c9fSChristoph Hellwig 				1 /* layoutupdate4 opaqueue len */)
4005f919c9fSChristoph Hellwig 				  /* the actual content of layoutupdate4 should
4015f919c9fSChristoph Hellwig 				     be allocated by drivers and spliced in
4025f919c9fSChristoph Hellwig 				     using xdr_write_pages */
403863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
404cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
405cbe82603SBenny Halevy 				encode_stateid_maxsz + \
4066669cb8bSTrond Myklebust 				1 + \
4076669cb8bSTrond Myklebust 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
408cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
409cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
410fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
411fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
4127d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
4137d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4147d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
4159aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
4169aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4179f79fb48SAndy Adamson #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz)
4189b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
4199b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
4209b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
421cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0
422cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0
4239b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4249b7b9fccSAndy Adamson 
4251da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
4261da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
4271da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
4289b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4291da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4309104a55dSTrond Myklebust 				encode_read_maxsz)
4311da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
4329b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4331da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4349104a55dSTrond Myklebust 				decode_read_maxsz)
4351da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
4369b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4371da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4389104a55dSTrond Myklebust 				encode_readlink_maxsz)
4391da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4409b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4411da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4429104a55dSTrond Myklebust 				decode_readlink_maxsz)
4431da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4449b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4451da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4469104a55dSTrond Myklebust 				encode_readdir_maxsz)
4471da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4489b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4491da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4509104a55dSTrond Myklebust 				decode_readdir_maxsz)
4511da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4529b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4531da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4549104a55dSTrond Myklebust 				encode_write_maxsz + \
4554f9838c7STrond Myklebust 				encode_getattr_maxsz)
4561da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4579b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4581da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4599104a55dSTrond Myklebust 				decode_write_maxsz + \
4604f9838c7STrond Myklebust 				decode_getattr_maxsz)
4611da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4629b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4631da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4648582715eSTrond Myklebust 				encode_commit_maxsz)
4651da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4669b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4671da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4688582715eSTrond Myklebust 				decode_commit_maxsz)
4691da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4709b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4711da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4722cebf828STrond Myklebust 				encode_open_maxsz + \
4736168f62cSWeston Andros Adamson 				encode_access_maxsz + \
4742cebf828STrond Myklebust 				encode_getfh_maxsz + \
4752cebf828STrond Myklebust 				encode_getattr_maxsz)
4761da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4779b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4781da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4792cebf828STrond Myklebust 				decode_open_maxsz + \
4806168f62cSWeston Andros Adamson 				decode_access_maxsz + \
4812cebf828STrond Myklebust 				decode_getfh_maxsz + \
4822cebf828STrond Myklebust 				decode_getattr_maxsz)
4831da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
4841da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4851da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4869104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
4879104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
4889104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
4891da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4909104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
4911da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
4929b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
4931da177e4SLinus Torvalds 					encode_putfh_maxsz + \
4942cebf828STrond Myklebust 					encode_open_maxsz + \
4956168f62cSWeston Andros Adamson 					encode_access_maxsz + \
4962cebf828STrond Myklebust 					encode_getattr_maxsz)
4971da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
4989b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
4991da177e4SLinus Torvalds 					decode_putfh_maxsz + \
5002cebf828STrond Myklebust 					decode_open_maxsz + \
5016168f62cSWeston Andros Adamson 					decode_access_maxsz + \
5022cebf828STrond Myklebust 					decode_getattr_maxsz)
5031da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
5041da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5059b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5061da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
507b6808145STrond Myklebust 				 encode_layoutreturn_maxsz + \
5083947b74dSTrond Myklebust 				 encode_open_downgrade_maxsz)
5091da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
5101da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5119b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5121da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
513b6808145STrond Myklebust 				 decode_layoutreturn_maxsz + \
5143947b74dSTrond Myklebust 				 decode_open_downgrade_maxsz)
5151da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
5169b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5171da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
518cf805165STrond Myklebust 				 encode_layoutreturn_maxsz + \
5199104a55dSTrond Myklebust 				 encode_close_maxsz + \
520516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5211da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
5229b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5231da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
524cf805165STrond Myklebust 				 decode_layoutreturn_maxsz + \
5259104a55dSTrond Myklebust 				 decode_close_maxsz + \
526516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5271da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
5289b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5291da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5309104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
5311da177e4SLinus Torvalds 				 encode_getattr_maxsz)
5321da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
5339b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5341da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5359104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
5369104a55dSTrond Myklebust 				 decode_getattr_maxsz)
5371da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5389b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5391da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5401da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5411da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5429b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5431da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5441da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5451da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5461da177e4SLinus Torvalds 				encode_renew_maxsz)
5471da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5481da177e4SLinus Torvalds 				decode_renew_maxsz)
5491da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5501da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5511da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5521da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5531da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5541da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
55583ca7f5aSChuck Lever 				encode_setclientid_confirm_maxsz)
5561da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5571da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
55883ca7f5aSChuck Lever 				decode_setclientid_confirm_maxsz)
5591da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5609b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5611da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5629104a55dSTrond Myklebust 				encode_lock_maxsz)
5631da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5649b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5651da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5669104a55dSTrond Myklebust 				decode_lock_maxsz)
5671da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5689b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5691da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5709104a55dSTrond Myklebust 				encode_lockt_maxsz)
5719104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5729b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5739104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5749104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5751da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5769b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5771da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5789104a55dSTrond Myklebust 				encode_locku_maxsz)
5791da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5809b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5811da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5829104a55dSTrond Myklebust 				decode_locku_maxsz)
583d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
584d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
585d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
586d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
587d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
588d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
5891da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
5909b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5911da177e4SLinus Torvalds 				encode_putfh_maxsz + \
59276b32999STrond Myklebust 				encode_access_maxsz + \
59376b32999STrond Myklebust 				encode_getattr_maxsz)
5941da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
5959b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5961da177e4SLinus Torvalds 				decode_putfh_maxsz + \
59776b32999STrond Myklebust 				decode_access_maxsz + \
59876b32999STrond Myklebust 				decode_getattr_maxsz)
5991da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
6009b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6011da177e4SLinus Torvalds 				encode_putfh_maxsz + \
60244c99933SChuck Lever 				encode_getattr_maxsz + \
60344c99933SChuck Lever 				encode_renew_maxsz)
6041da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
6059b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6061da177e4SLinus Torvalds 				decode_putfh_maxsz + \
60744c99933SChuck Lever 				decode_getattr_maxsz + \
60844c99933SChuck Lever 				decode_renew_maxsz)
6091da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
6109b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6111da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6121da177e4SLinus Torvalds 				encode_lookup_maxsz + \
6131da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6141da177e4SLinus Torvalds 				encode_getfh_maxsz)
6151da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
6169b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6171da177e4SLinus Torvalds 				decode_putfh_maxsz + \
618e6889620STrond Myklebust 				decode_lookup_maxsz + \
6191da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6201da177e4SLinus Torvalds 				decode_getfh_maxsz)
6211da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
6229b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6231da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
6241da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6251da177e4SLinus Torvalds 				encode_getfh_maxsz)
6261da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6279b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6281da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
6291da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6301da177e4SLinus Torvalds 				decode_getfh_maxsz)
6311da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
6329b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6331da177e4SLinus Torvalds 				encode_putfh_maxsz + \
634778d2817STrond Myklebust 				encode_remove_maxsz)
6351da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6369b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6371da177e4SLinus Torvalds 				decode_putfh_maxsz + \
638778d2817STrond Myklebust 				decode_remove_maxsz)
6391da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6409b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6411da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6421da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6431da177e4SLinus Torvalds 				encode_putfh_maxsz + \
644778d2817STrond Myklebust 				encode_rename_maxsz)
6451da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6469b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6471da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6481da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6491da177e4SLinus Torvalds 				decode_putfh_maxsz + \
650778d2817STrond Myklebust 				decode_rename_maxsz)
6511da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6529b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6531da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6541da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6551da177e4SLinus Torvalds 				encode_putfh_maxsz + \
65691ba2eeeSTrond Myklebust 				encode_link_maxsz + \
65791ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
658a9f6991bSTrond Myklebust 				encode_getattr_maxsz)
6591da177e4SLinus Torvalds #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
6609b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6611da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6621da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6631da177e4SLinus Torvalds 				decode_putfh_maxsz + \
66491ba2eeeSTrond Myklebust 				decode_link_maxsz + \
66591ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
66691ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6671da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6689b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6691da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6701da177e4SLinus Torvalds 				encode_symlink_maxsz + \
6711da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6721da177e4SLinus Torvalds 				encode_getfh_maxsz)
6731da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
6749b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6751da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6761da177e4SLinus Torvalds 				decode_symlink_maxsz + \
6771da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6781da177e4SLinus Torvalds 				decode_getfh_maxsz)
6791da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
6809b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6811da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6821da177e4SLinus Torvalds 				encode_create_maxsz + \
68356ae19f3STrond Myklebust 				encode_getfh_maxsz + \
68456ae19f3STrond Myklebust 				encode_getattr_maxsz)
6851da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
6869b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6871da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6881da177e4SLinus Torvalds 				decode_create_maxsz + \
68956ae19f3STrond Myklebust 				decode_getfh_maxsz + \
69056ae19f3STrond Myklebust 				decode_getattr_maxsz)
6911da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
6929b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6931da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6941da177e4SLinus Torvalds 				encode_getattr_maxsz)
6951da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
6969b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6971da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6981da177e4SLinus Torvalds 				decode_getattr_maxsz)
6991da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
7009b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7011da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7029104a55dSTrond Myklebust 				encode_statfs_maxsz)
7031da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
7049b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7051da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7069104a55dSTrond Myklebust 				decode_statfs_maxsz)
7071da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
7089b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
709ab91f264STrond Myklebust 				encode_putfh_maxsz + \
7101da177e4SLinus Torvalds 				encode_getattr_maxsz)
7111da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
7129b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
713ab91f264STrond Myklebust 				decode_putfh_maxsz + \
7141da177e4SLinus Torvalds 				decode_getattr_maxsz)
7151da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
7169b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7171da177e4SLinus Torvalds 				encode_putfh_maxsz + \
718586f1c39STrond Myklebust 				encode_layoutreturn_maxsz + \
719fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
720fa178f29STrond Myklebust 				encode_getattr_maxsz)
7211da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7229b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
723d8434d4cSTrond Myklebust 				decode_putfh_maxsz + \
724586f1c39STrond Myklebust 				decode_layoutreturn_maxsz + \
725fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
726fa178f29STrond Myklebust 				decode_getattr_maxsz)
727029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
7289b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
729029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7309104a55dSTrond Myklebust 				encode_getacl_maxsz)
731029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7329b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
733029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7349104a55dSTrond Myklebust 				decode_getacl_maxsz)
73523ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7369b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
73723ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7389104a55dSTrond Myklebust 				encode_setacl_maxsz)
73923ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7409b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
74123ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7429104a55dSTrond Myklebust 				decode_setacl_maxsz)
743683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
744683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7459b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
746683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
747e6889620STrond Myklebust 				 encode_lookup_maxsz + \
748b03d735bSChuck Lever 				 encode_fs_locations_maxsz + \
749b03d735bSChuck Lever 				 encode_renew_maxsz)
750683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
751683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7529b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
753683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
754e6889620STrond Myklebust 				 decode_lookup_maxsz + \
755b03d735bSChuck Lever 				 decode_fs_locations_maxsz + \
756b03d735bSChuck Lever 				 decode_renew_maxsz)
7575a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7585a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7595a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7605a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7615a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7625a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7635a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7645a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
76544c99933SChuck Lever #define NFS4_enc_fsid_present_sz \
76644c99933SChuck Lever 				(compound_encode_hdr_maxsz + \
76744c99933SChuck Lever 				 encode_sequence_maxsz + \
76844c99933SChuck Lever 				 encode_putfh_maxsz + \
76944c99933SChuck Lever 				 encode_getfh_maxsz + \
77044c99933SChuck Lever 				 encode_renew_maxsz)
77144c99933SChuck Lever #define NFS4_dec_fsid_present_sz \
77244c99933SChuck Lever 				(compound_decode_hdr_maxsz + \
77344c99933SChuck Lever 				 decode_sequence_maxsz + \
77444c99933SChuck Lever 				 decode_putfh_maxsz + \
77544c99933SChuck Lever 				 decode_getfh_maxsz + \
77644c99933SChuck Lever 				 decode_renew_maxsz)
77799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
7787c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
7797c44f1aeSWeston Andros Adamson 				(compound_encode_hdr_maxsz + \
7807c44f1aeSWeston Andros Adamson 				 encode_bind_conn_to_session_maxsz)
7817c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
7827c44f1aeSWeston Andros Adamson 				(compound_decode_hdr_maxsz + \
7837c44f1aeSWeston Andros Adamson 				 decode_bind_conn_to_session_maxsz)
78499fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
78599fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
78699fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
78799fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
78899fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
78999fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
790fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
791fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
792fc931582SAndy Adamson 				 encode_create_session_maxsz)
793fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
794fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
795fc931582SAndy Adamson 				 decode_create_session_maxsz)
7960f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
7970f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
7980f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
7990f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
80066245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
80166245539STrond Myklebust 					 encode_destroy_clientid_maxsz)
80266245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
80366245539STrond Myklebust 					 decode_destroy_clientid_maxsz)
804fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
805fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
806fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
807fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
808fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
809fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
8102050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
8112050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
8122050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
8132050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
8142050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
8152050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
8162050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
8172050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
81818019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
81918019753SRicardo Labiaga 					 encode_sequence_maxsz + \
82018019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
82118019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
82218019753SRicardo Labiaga 					 decode_sequence_maxsz + \
82318019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
824b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
825b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
826b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
827b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
828b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
829b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
830b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
831b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
832b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
833b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
834b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
835b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
836b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
837b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
838863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
839863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
840863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
841863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
842863a3c6cSAndy Adamson 				encode_getattr_maxsz)
843863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
844863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
845863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
846863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
847863a3c6cSAndy Adamson 				decode_getattr_maxsz)
848cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
849cbe82603SBenny Halevy 				encode_sequence_maxsz + \
850cbe82603SBenny Halevy 				encode_putfh_maxsz + \
851cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
852cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
853cbe82603SBenny Halevy 				decode_sequence_maxsz + \
854cbe82603SBenny Halevy 				decode_putfh_maxsz + \
855cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
856fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
857fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
858fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
859fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
860fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
861fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
862fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
863fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8647d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8657d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8667d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8677d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
8687d974794SBryan Schumaker 					 decode_sequence_maxsz + \
8697d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
8709aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
8719aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
8729aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
8739aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
8749aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
8759aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
8762449ea2eSAlexandros Batsakis 
8772449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8782449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
8792449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
8802449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
8812449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
8822449ea2eSAlexandros Batsakis 				     XDR_UNIT);
8832449ea2eSAlexandros Batsakis 
8842449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8852449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
8862449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
8872449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
8882449ea2eSAlexandros Batsakis 				    XDR_UNIT);
889f1c097beSAndy Adamson 
890f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
891f1c097beSAndy Adamson 					   compound_decode_hdr_maxsz +
892f1c097beSAndy Adamson 					   decode_sequence_maxsz) *
893f1c097beSAndy Adamson 					  XDR_UNIT);
894f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
89599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
8961da177e4SLinus Torvalds 
897bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
898bca79478STrond Myklebust 	[NF4BAD] = 0,
899bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
900bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
901bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
902bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
903bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
904bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
905bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
906bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
907bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
9081da177e4SLinus Torvalds };
9091da177e4SLinus Torvalds 
9101da177e4SLinus Torvalds struct compound_hdr {
9111da177e4SLinus Torvalds 	int32_t		status;
9121da177e4SLinus Torvalds 	uint32_t	nops;
913d017931cSAndy Adamson 	__be32 *	nops_p;
9141da177e4SLinus Torvalds 	uint32_t	taglen;
9151da177e4SLinus Torvalds 	char *		tag;
9160c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
91766cc0429SBenny Halevy 	u32		minorversion;
9181da177e4SLinus Torvalds };
9191da177e4SLinus Torvalds 
92013c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
92113c65ce9SBenny Halevy {
92213c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
92313c65ce9SBenny Halevy 	BUG_ON(!p);
92413c65ce9SBenny Halevy 	return p;
92513c65ce9SBenny Halevy }
9261da177e4SLinus Torvalds 
927cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
928cb17e556STrond Myklebust {
929ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
930cb17e556STrond Myklebust }
931cb17e556STrond Myklebust 
9321da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
9331da177e4SLinus Torvalds {
934ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
9351da177e4SLinus Torvalds }
9361da177e4SLinus Torvalds 
9374ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9384ade9821STrond Myklebust {
939ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
9404ade9821STrond Myklebust }
9414ade9821STrond Myklebust 
942ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
943ff2eb681STrond Myklebust {
944ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
945ff2eb681STrond Myklebust }
946ff2eb681STrond Myklebust 
9474ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
9484ade9821STrond Myklebust 		const struct nfs_seqid *seqid)
9494ade9821STrond Myklebust {
950a6796419STrond Myklebust 	if (seqid != NULL)
9514ade9821STrond Myklebust 		encode_uint32(xdr, seqid->sequence->counter);
952a6796419STrond Myklebust 	else
953a6796419STrond Myklebust 		encode_uint32(xdr, 0);
9544ade9821STrond Myklebust }
9554ade9821STrond Myklebust 
9560c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
9570c4e8c18SBenny Halevy 				struct rpc_rqst *req,
9580c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
9591da177e4SLinus Torvalds {
9608687b63aSAl Viro 	__be32 *p;
961a17c2153STrond Myklebust 	struct rpc_auth *auth = req->rq_cred->cr_auth;
9620c4e8c18SBenny Halevy 
9630c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
9640c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
9650c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
9660c4e8c18SBenny Halevy 	hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
9671da177e4SLinus Torvalds 
9687fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
9696fdfb0bcSTrond Myklebust 	encode_string(xdr, hdr->taglen, hdr->tag);
9706fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 8);
971e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
972d017931cSAndy Adamson 	hdr->nops_p = p;
97334558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
974d017931cSAndy Adamson }
975d017931cSAndy Adamson 
976ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
977ab19b481STrond Myklebust 		uint32_t replen,
978ab19b481STrond Myklebust 		struct compound_hdr *hdr)
979ab19b481STrond Myklebust {
980ab19b481STrond Myklebust 	encode_uint32(xdr, op);
981ab19b481STrond Myklebust 	hdr->nops++;
982ab19b481STrond Myklebust 	hdr->replen += replen;
983ab19b481STrond Myklebust }
984ab19b481STrond Myklebust 
985d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
986d017931cSAndy Adamson {
9877fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
988d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
9891da177e4SLinus Torvalds }
9901da177e4SLinus Torvalds 
991ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
992ea9d23f5STrond Myklebust {
9932d2f24adSTrond Myklebust 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
994ea9d23f5STrond Myklebust }
995ea9d23f5STrond Myklebust 
9961da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
9971da177e4SLinus Torvalds {
998cb17e556STrond Myklebust 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
9991da177e4SLinus Torvalds }
10001da177e4SLinus Torvalds 
1001aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1002aa9c2669SDavid Quigley 				const struct nfs4_label *label,
10035334c5bdSKinglong Mee 				const struct nfs_server *server,
1004dff25ddbSAndreas Gruenbacher 				bool excl_check, const umode_t *umask)
10051da177e4SLinus Torvalds {
10061da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
10071da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
10081da177e4SLinus Torvalds 	int owner_namelen = 0;
10091da177e4SLinus Torvalds 	int owner_grouplen = 0;
10108687b63aSAl Viro 	__be32 *p;
1011d7067b2dSTrond Myklebust 	unsigned i;
1012d7067b2dSTrond Myklebust 	uint32_t len = 0;
1013d7067b2dSTrond Myklebust 	uint32_t bmval_len;
1014d7067b2dSTrond Myklebust 	uint32_t bmval[3] = { 0 };
10151da177e4SLinus Torvalds 
10161da177e4SLinus Torvalds 	/*
10171da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
10181da177e4SLinus Torvalds 	 */
1019d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_SIZE) {
1020d7067b2dSTrond Myklebust 		bmval[0] |= FATTR4_WORD0_SIZE;
10211da177e4SLinus Torvalds 		len += 8;
1022d7067b2dSTrond Myklebust 	}
1023dff25ddbSAndreas Gruenbacher 	if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK))
1024dff25ddbSAndreas Gruenbacher 		umask = NULL;
1025d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MODE) {
1026dff25ddbSAndreas Gruenbacher 		if (umask) {
1027dff25ddbSAndreas Gruenbacher 			bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1028dff25ddbSAndreas Gruenbacher 			len += 8;
1029dff25ddbSAndreas Gruenbacher 		} else {
1030d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_MODE;
10311da177e4SLinus Torvalds 			len += 4;
1032d7067b2dSTrond Myklebust 		}
1033dff25ddbSAndreas Gruenbacher 	}
10341da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
1035e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
10361da177e4SLinus Torvalds 		if (owner_namelen < 0) {
1037fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
1038e5782076SEric W. Biederman 					from_kuid(&init_user_ns, iap->ia_uid));
10391da177e4SLinus Torvalds 			/* XXX */
10401da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
10411da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
10421da177e4SLinus Torvalds 			/* goto out; */
10431da177e4SLinus Torvalds 		}
1044d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER;
10451da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
10461da177e4SLinus Torvalds 	}
10471da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
1048e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
10491da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
1050fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
1051e5782076SEric W. Biederman 					from_kgid(&init_user_ns, iap->ia_gid));
10521da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
10531da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
10541da177e4SLinus Torvalds 			/* goto out; */
10551da177e4SLinus Torvalds 		}
1056d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
10571da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
10581da177e4SLinus Torvalds 	}
1059d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_ATIME_SET) {
1060d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
10611da177e4SLinus Torvalds 		len += 16;
1062d7067b2dSTrond Myklebust 	} else if (iap->ia_valid & ATTR_ATIME) {
1063d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
10641da177e4SLinus Torvalds 		len += 4;
1065d7067b2dSTrond Myklebust 	}
1066d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MTIME_SET) {
1067d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
10681da177e4SLinus Torvalds 		len += 16;
1069d7067b2dSTrond Myklebust 	} else if (iap->ia_valid & ATTR_MTIME) {
1070d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
10711da177e4SLinus Torvalds 		len += 4;
1072d7067b2dSTrond Myklebust 	}
10735334c5bdSKinglong Mee 
10745334c5bdSKinglong Mee 	if (excl_check) {
10755334c5bdSKinglong Mee 		const u32 *excl_bmval = server->exclcreat_bitmask;
10765334c5bdSKinglong Mee 		bmval[0] &= excl_bmval[0];
10775334c5bdSKinglong Mee 		bmval[1] &= excl_bmval[1];
10785334c5bdSKinglong Mee 		bmval[2] &= excl_bmval[2];
10795334c5bdSKinglong Mee 
10805334c5bdSKinglong Mee 		if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
10815334c5bdSKinglong Mee 			label = NULL;
10825334c5bdSKinglong Mee 	}
10835334c5bdSKinglong Mee 
1084b4a2cf76STrond Myklebust 	if (label) {
1085b4a2cf76STrond Myklebust 		len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1086d7067b2dSTrond Myklebust 		bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1087d7067b2dSTrond Myklebust 	}
1088d7067b2dSTrond Myklebust 
1089d7067b2dSTrond Myklebust 	if (bmval[2] != 0)
1090b4a2cf76STrond Myklebust 		bmval_len = 3;
1091d7067b2dSTrond Myklebust 	else if (bmval[1] != 0)
1092d7067b2dSTrond Myklebust 		bmval_len = 2;
1093d7067b2dSTrond Myklebust 	else
1094d7067b2dSTrond Myklebust 		bmval_len = 1;
1095b4a2cf76STrond Myklebust 
1096d7067b2dSTrond Myklebust 	p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
10971da177e4SLinus Torvalds 
1098b4a2cf76STrond Myklebust 	*p++ = cpu_to_be32(bmval_len);
1099d7067b2dSTrond Myklebust 	for (i = 0; i < bmval_len; i++)
1100d7067b2dSTrond Myklebust 		*p++ = cpu_to_be32(bmval[i]);
1101d7067b2dSTrond Myklebust 	*p++ = cpu_to_be32(len);
11021da177e4SLinus Torvalds 
1103d7067b2dSTrond Myklebust 	if (bmval[0] & FATTR4_WORD0_SIZE)
1104b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
1105d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_MODE)
1106e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1107d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER)
1108811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
1109d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1110811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1111d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
11121da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_ATIME_SET) {
1113e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1114042ad0b3SBryan Schumaker 			p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1115d3f6baaaSTrond Myklebust 			*p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1116d7067b2dSTrond Myklebust 		} else
1117e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11181da177e4SLinus Torvalds 	}
1119d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
11201da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_MTIME_SET) {
1121e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1122042ad0b3SBryan Schumaker 			p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1123e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1124d7067b2dSTrond Myklebust 		} else
1125e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11261da177e4SLinus Torvalds 	}
1127d7067b2dSTrond Myklebust 	if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1128aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->lfs);
1129aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->pi);
1130aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->len);
1131aa9c2669SDavid Quigley 		p = xdr_encode_opaque_fixed(p, label->label, label->len);
1132aa9c2669SDavid Quigley 	}
1133dff25ddbSAndreas Gruenbacher 	if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1134dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1135dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(*umask);
1136dff25ddbSAndreas Gruenbacher 	}
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);
1191dff25ddbSAndreas Gruenbacher 	encode_attrs(xdr, create->attrs, create->label, create->server, false,
1192dff25ddbSAndreas Gruenbacher 		     &create->umask);
11931da177e4SLinus Torvalds }
11941da177e4SLinus Torvalds 
1195cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
11961da177e4SLinus Torvalds {
11978687b63aSAl Viro 	__be32 *p;
11981da177e4SLinus Torvalds 
1199475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1200475d4ba0STrond Myklebust 	p = reserve_space(xdr, 8);
1201e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
120234558513SBenny Halevy 	*p = cpu_to_be32(bitmap);
12031da177e4SLinus Torvalds }
12041da177e4SLinus Torvalds 
1205cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
12061da177e4SLinus Torvalds {
12078687b63aSAl Viro 	__be32 *p;
12081da177e4SLinus Torvalds 
1209475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1210475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1211e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
1212e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(bm0);
121334558513SBenny Halevy 	*p = cpu_to_be32(bm1);
12141da177e4SLinus Torvalds }
12151da177e4SLinus Torvalds 
1216dae100c2SFred Isaman static void
1217dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr,
1218dae100c2SFred Isaman 		     uint32_t bm0, uint32_t bm1, uint32_t bm2,
1219dae100c2SFred Isaman 		     struct compound_hdr *hdr)
1220dae100c2SFred Isaman {
1221dae100c2SFred Isaman 	__be32 *p;
1222dae100c2SFred Isaman 
1223ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1224dae100c2SFred Isaman 	if (bm2) {
1225dae100c2SFred Isaman 		p = reserve_space(xdr, 16);
1226dae100c2SFred Isaman 		*p++ = cpu_to_be32(3);
1227dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1228dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm1);
1229dae100c2SFred Isaman 		*p = cpu_to_be32(bm2);
1230dae100c2SFred Isaman 	} else if (bm1) {
1231dae100c2SFred Isaman 		p = reserve_space(xdr, 12);
1232dae100c2SFred Isaman 		*p++ = cpu_to_be32(2);
1233dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1234dae100c2SFred Isaman 		*p = cpu_to_be32(bm1);
1235dae100c2SFred Isaman 	} else {
1236dae100c2SFred Isaman 		p = reserve_space(xdr, 8);
1237dae100c2SFred Isaman 		*p++ = cpu_to_be32(1);
1238dae100c2SFred Isaman 		*p = cpu_to_be32(bm0);
1239dae100c2SFred Isaman 	}
1240dae100c2SFred Isaman }
1241dae100c2SFred Isaman 
1242cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12431da177e4SLinus Torvalds {
1244a09df2caSDavid Quigley 	encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1245a09df2caSDavid Quigley 			   bitmask[1] & nfs4_fattr_bitmap[1],
1246a09df2caSDavid Quigley 			   bitmask[2] & nfs4_fattr_bitmap[2],
1247a09df2caSDavid Quigley 			   hdr);
12481da177e4SLinus Torvalds }
12491da177e4SLinus Torvalds 
125088034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
12511549210fSTrond Myklebust 				 const u32 *open_bitmap,
125288034c3dSAndy Adamson 				 struct compound_hdr *hdr)
125388034c3dSAndy Adamson {
125488034c3dSAndy Adamson 	encode_getattr_three(xdr,
12551549210fSTrond Myklebust 			     bitmask[0] & open_bitmap[0],
12561549210fSTrond Myklebust 			     bitmask[1] & open_bitmap[1],
12571549210fSTrond Myklebust 			     bitmask[2] & open_bitmap[2],
125888034c3dSAndy Adamson 			     hdr);
125988034c3dSAndy Adamson }
126088034c3dSAndy Adamson 
1261cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12621da177e4SLinus Torvalds {
1263dae100c2SFred Isaman 	encode_getattr_three(xdr,
1264dae100c2SFred Isaman 			     bitmask[0] & nfs4_fsinfo_bitmap[0],
1265dae100c2SFred Isaman 			     bitmask[1] & nfs4_fsinfo_bitmap[1],
1266dae100c2SFred Isaman 			     bitmask[2] & nfs4_fsinfo_bitmap[2],
1267dae100c2SFred Isaman 			     hdr);
12681da177e4SLinus Torvalds }
12691da177e4SLinus Torvalds 
1270cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1271830b8e33SManoj Naik {
1272cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1273cf8cdbe5SAndy Adamson 			   bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1274830b8e33SManoj Naik }
1275830b8e33SManoj Naik 
1276cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12771da177e4SLinus Torvalds {
1278ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12791da177e4SLinus Torvalds }
12801da177e4SLinus Torvalds 
1281cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12821da177e4SLinus Torvalds {
1283ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
12846fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
12851da177e4SLinus Torvalds }
12861da177e4SLinus Torvalds 
1287911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1288911d1aafSTrond Myklebust {
1289f44106e2SJeff Layton 	if (fl->fl_type == F_RDLCK)
1290911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1291911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1292911d1aafSTrond Myklebust }
1293911d1aafSTrond Myklebust 
1294911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1295911d1aafSTrond Myklebust {
1296911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1297911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1298911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1299911d1aafSTrond Myklebust }
1300911d1aafSTrond Myklebust 
1301daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1302daccbdedSTrond Myklebust {
1303daccbdedSTrond Myklebust 	__be32 *p;
1304daccbdedSTrond Myklebust 
1305d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1306daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1307d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1308daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1309d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1310daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1311daccbdedSTrond Myklebust }
1312daccbdedSTrond Myklebust 
13131da177e4SLinus Torvalds /*
13141da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
13151da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
13161da177e4SLinus Torvalds  */
1317cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
13181da177e4SLinus Torvalds {
13198687b63aSAl Viro 	__be32 *p;
13201da177e4SLinus Torvalds 
1321475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1322475d4ba0STrond Myklebust 	p = reserve_space(xdr, 28);
1323e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1324e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1325b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1326b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
132734558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1328911d1aafSTrond Myklebust 	if (args->new_lock_owner){
13294ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->open_seqid);
1330425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->open_stateid);
13314ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
1332daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
13331da177e4SLinus Torvalds 	}
13341da177e4SLinus Torvalds 	else {
1335425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->lock_stateid);
13364ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
13371da177e4SLinus Torvalds 	}
13381da177e4SLinus Torvalds }
13391da177e4SLinus Torvalds 
1340cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
13411da177e4SLinus Torvalds {
13428687b63aSAl Viro 	__be32 *p;
13431da177e4SLinus Torvalds 
1344475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1345475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1346e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1347b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1348b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1349daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
13501da177e4SLinus Torvalds }
13511da177e4SLinus Torvalds 
1352cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
13531da177e4SLinus Torvalds {
13548687b63aSAl Viro 	__be32 *p;
13551da177e4SLinus Torvalds 
1356475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1357475d4ba0STrond Myklebust 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13584ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, args->seqid);
1359425c1d4eSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1360ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1361b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
136234558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13631da177e4SLinus Torvalds }
13641da177e4SLinus Torvalds 
1365d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1366d3c7b7ccSTrond Myklebust {
1367ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1368d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1369d3c7b7ccSTrond Myklebust }
1370d3c7b7ccSTrond Myklebust 
1371cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13721da177e4SLinus Torvalds {
1373ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13746fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
13751da177e4SLinus Torvalds }
13761da177e4SLinus Torvalds 
13776ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
13781da177e4SLinus Torvalds {
13798687b63aSAl Viro 	__be32 *p;
13801da177e4SLinus Torvalds 
138113c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
13826ae37339STrond Myklebust 	*p++ = cpu_to_be32(share_access);
138334558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13841da177e4SLinus Torvalds }
13851da177e4SLinus Torvalds 
13861da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13871da177e4SLinus Torvalds {
13888687b63aSAl Viro 	__be32 *p;
13891da177e4SLinus Torvalds  /*
13901da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
13911da177e4SLinus Torvalds  * owner 4 = 32
13921da177e4SLinus Torvalds  */
13934ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
13946ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
139595b72eb0STrond Myklebust 	p = reserve_space(xdr, 36);
1396b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
139795b72eb0STrond Myklebust 	*p++ = cpu_to_be32(24);
139893f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1399d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
140095b72eb0STrond Myklebust 	*p++ = cpu_to_be32(arg->id.uniquifier);
140195b72eb0STrond Myklebust 	xdr_encode_hyper(p, arg->id.create_time);
14021da177e4SLinus Torvalds }
14031da177e4SLinus Torvalds 
14041da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14051da177e4SLinus Torvalds {
14068687b63aSAl Viro 	__be32 *p;
14071da177e4SLinus Torvalds 
140813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
1409549b19ccSTrond Myklebust 	switch(arg->createmode) {
1410549b19ccSTrond Myklebust 	case NFS4_CREATE_UNCHECKED:
141134558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1412dff25ddbSAndreas Gruenbacher 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1413dff25ddbSAndreas Gruenbacher 			     &arg->umask);
14141da177e4SLinus Torvalds 		break;
1415549b19ccSTrond Myklebust 	case NFS4_CREATE_GUARDED:
14164882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
1417dff25ddbSAndreas Gruenbacher 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1418dff25ddbSAndreas Gruenbacher 			     &arg->umask);
1419549b19ccSTrond Myklebust 		break;
1420549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE:
1421549b19ccSTrond Myklebust 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1422549b19ccSTrond Myklebust 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1423549b19ccSTrond Myklebust 		break;
1424549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE4_1:
14254882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
14264882ef72SAlexandros Batsakis 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1427dff25ddbSAndreas Gruenbacher 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true,
1428dff25ddbSAndreas Gruenbacher 			     &arg->umask);
14294882ef72SAlexandros Batsakis 	}
14304882ef72SAlexandros Batsakis }
14311da177e4SLinus Torvalds 
14321da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14331da177e4SLinus Torvalds {
14348687b63aSAl Viro 	__be32 *p;
14351da177e4SLinus Torvalds 
143613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14371da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14381da177e4SLinus Torvalds 	case 0:
143934558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14401da177e4SLinus Torvalds 		break;
14411da177e4SLinus Torvalds 	default:
144234558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14431da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14441da177e4SLinus Torvalds 	}
14451da177e4SLinus Torvalds }
14461da177e4SLinus Torvalds 
1447bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14481da177e4SLinus Torvalds {
14498687b63aSAl Viro 	__be32 *p;
14501da177e4SLinus Torvalds 
145113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14521da177e4SLinus Torvalds 	switch (delegation_type) {
14531da177e4SLinus Torvalds 	case 0:
145434558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14551da177e4SLinus Torvalds 		break;
14561da177e4SLinus Torvalds 	case FMODE_READ:
145734558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14581da177e4SLinus Torvalds 		break;
14591da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
146034558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14611da177e4SLinus Torvalds 		break;
14621da177e4SLinus Torvalds 	default:
14631da177e4SLinus Torvalds 		BUG();
14641da177e4SLinus Torvalds 	}
14651da177e4SLinus Torvalds }
14661da177e4SLinus Torvalds 
14671da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14681da177e4SLinus Torvalds {
14698687b63aSAl Viro 	__be32 *p;
14701da177e4SLinus Torvalds 
147113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
147234558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14731da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14741da177e4SLinus Torvalds }
14751da177e4SLinus Torvalds 
1476bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14771da177e4SLinus Torvalds {
14788687b63aSAl Viro 	__be32 *p;
14791da177e4SLinus Torvalds 
148013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
148134558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14821da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14831da177e4SLinus Torvalds }
14841da177e4SLinus Torvalds 
14851da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14861da177e4SLinus Torvalds {
14878687b63aSAl Viro 	__be32 *p;
14881da177e4SLinus Torvalds 
1489ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 4);
1490ea9d23f5STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1491ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
14921da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14931da177e4SLinus Torvalds }
14941da177e4SLinus Torvalds 
1495d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr)
1496d9fc6619STrond Myklebust {
1497d9fc6619STrond Myklebust 	__be32 *p;
1498d9fc6619STrond Myklebust 
1499d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1500d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1501d9fc6619STrond Myklebust }
1502d9fc6619STrond Myklebust 
1503d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1504d9fc6619STrond Myklebust {
1505d9fc6619STrond Myklebust 	__be32 *p;
1506d9fc6619STrond Myklebust 
1507d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1508d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1509d9fc6619STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
1510d9fc6619STrond Myklebust }
1511d9fc6619STrond Myklebust 
1512cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
15131da177e4SLinus Torvalds {
1514ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
15151da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
15161da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
15171da177e4SLinus Torvalds 	switch (arg->claim) {
15181da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
15191da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
15201da177e4SLinus Torvalds 		break;
15211da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
15221da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
15231da177e4SLinus Torvalds 		break;
15241da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
15251da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
15261da177e4SLinus Torvalds 		break;
1527d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_FH:
1528d9fc6619STrond Myklebust 		encode_claim_fh(xdr);
1529d9fc6619STrond Myklebust 		break;
1530d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1531d9fc6619STrond Myklebust 		encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1532d9fc6619STrond Myklebust 		break;
15331da177e4SLinus Torvalds 	default:
15341da177e4SLinus Torvalds 		BUG();
15351da177e4SLinus Torvalds 	}
15361da177e4SLinus Torvalds }
15371da177e4SLinus Torvalds 
1538cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
15391da177e4SLinus Torvalds {
1540ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1541ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
15424ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15431da177e4SLinus Torvalds }
15441da177e4SLinus Torvalds 
1545cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
15461da177e4SLinus Torvalds {
1547ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1548566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
15494ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15506ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
15511da177e4SLinus Torvalds }
15521da177e4SLinus Torvalds 
1553cf8cdbe5SAndy Adamson static void
1554d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15551da177e4SLinus Torvalds {
1556ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
15576fdfb0bcSTrond Myklebust 	encode_string(xdr, fh->size, fh->data);
15581da177e4SLinus Torvalds }
15591da177e4SLinus Torvalds 
1560cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15611da177e4SLinus Torvalds {
1562ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15631da177e4SLinus Torvalds }
15641da177e4SLinus Torvalds 
15653c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
15663c6b899cSAnna Schumaker 			struct compound_hdr *hdr)
15671da177e4SLinus Torvalds {
15688687b63aSAl Viro 	__be32 *p;
15691da177e4SLinus Torvalds 
1570ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
15719b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
15721da177e4SLinus Torvalds 
157313c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1574b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
157534558513SBenny Halevy 	*p = cpu_to_be32(args->count);
15761da177e4SLinus Torvalds }
15771da177e4SLinus Torvalds 
1578cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15791da177e4SLinus Torvalds {
1580aa9c2669SDavid Quigley 	uint32_t attrs[3] = {
158128331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
158228331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
158328331a46STrond Myklebust 	};
15846f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
1585cd93710eSChuck Lever 	__be32 *p, verf[2];
1586d204c5d2STrond Myklebust 	uint32_t attrlen = 0;
1587d204c5d2STrond Myklebust 	unsigned int i;
15881da177e4SLinus Torvalds 
158982f2e547SBryan Schumaker 	if (readdir->plus) {
159082f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
159128331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
159282f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
159382f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
159482f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
159582f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1596d204c5d2STrond Myklebust 		attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
15976f7a35bdSTrond Myklebust 		dircount >>= 1;
159882f2e547SBryan Schumaker 	}
159928331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
160028331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
160128331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
1602d204c5d2STrond Myklebust 	for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1603d204c5d2STrond Myklebust 		attrs[i] &= readdir->bitmask[i];
1604d204c5d2STrond Myklebust 		if (attrs[i] != 0)
1605d204c5d2STrond Myklebust 			attrlen = i+1;
1606d204c5d2STrond Myklebust 	}
16076f7a35bdSTrond Myklebust 
1608475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1609ff2eb681STrond Myklebust 	encode_uint64(xdr, readdir->cookie);
1610cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &readdir->verifier);
1611d204c5d2STrond Myklebust 	p = reserve_space(xdr, 12 + (attrlen << 2));
16126f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
16136f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
1614d204c5d2STrond Myklebust 	*p++ = cpu_to_be32(attrlen);
1615d204c5d2STrond Myklebust 	for (i = 0; i < attrlen; i++)
1616d204c5d2STrond Myklebust 		*p++ = cpu_to_be32(attrs[i]);
1617cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
1618aa9c2669SDavid Quigley 
1619aa9c2669SDavid Quigley 	dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
162044109241SFred Isaman 			__func__,
1621eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1622cd93710eSChuck Lever 			verf[0], verf[1],
1623eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1624aa9c2669SDavid Quigley 			attrs[1] & readdir->bitmask[1],
1625aa9c2669SDavid Quigley 			attrs[2] & readdir->bitmask[2]);
16261da177e4SLinus Torvalds }
16271da177e4SLinus Torvalds 
1628cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16291da177e4SLinus Torvalds {
1630ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
16311da177e4SLinus Torvalds }
16321da177e4SLinus Torvalds 
1633cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16341da177e4SLinus Torvalds {
1635ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
16366fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
16371da177e4SLinus Torvalds }
16381da177e4SLinus Torvalds 
1639cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16401da177e4SLinus Torvalds {
1641ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1642811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1643811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
16441da177e4SLinus Torvalds }
16451da177e4SLinus Torvalds 
1646bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1647bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16481da177e4SLinus Torvalds {
1649475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1650ff2eb681STrond Myklebust 	encode_uint64(xdr, clid);
16511da177e4SLinus Torvalds }
16521da177e4SLinus Torvalds 
1653cf8cdbe5SAndy Adamson static void
1654d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
165556ae19f3STrond Myklebust {
1656ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
165756ae19f3STrond Myklebust }
165856ae19f3STrond Myklebust 
16599f06c719SChuck Lever static void
1660d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
166123ec6965SJ. Bruce Fields {
16628687b63aSAl Viro 	__be32 *p;
166323ec6965SJ. Bruce Fields 
1664ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1665ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &zero_stateid);
166613c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1667e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
166834558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
166913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
167034558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
16718fbcf237SAndreas Gruenbacher 	xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
167223ec6965SJ. Bruce Fields }
167323ec6965SJ. Bruce Fields 
1674cf8cdbe5SAndy Adamson static void
1675d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16761da177e4SLinus Torvalds {
1677ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
16781da177e4SLinus Torvalds }
16791da177e4SLinus Torvalds 
1680cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16811da177e4SLinus Torvalds {
1682ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1683ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
1684dff25ddbSAndreas Gruenbacher 	encode_attrs(xdr, arg->iap, arg->label, server, false, NULL);
16851da177e4SLinus Torvalds }
16861da177e4SLinus Torvalds 
1687cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
16881da177e4SLinus Torvalds {
16898687b63aSAl Viro 	__be32 *p;
16901da177e4SLinus Torvalds 
169170019514STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1692cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
16931da177e4SLinus Torvalds 
16943a6bb738SJeff Layton 	encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
16953a6bb738SJeff Layton 			setclientid->sc_clnt->cl_owner_id);
169613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
169734558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
16981da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
16991da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
170013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
17013a6bb738SJeff Layton 	*p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
17021da177e4SLinus Torvalds }
17031da177e4SLinus Torvalds 
1704bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
17051da177e4SLinus Torvalds {
1706475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1707475d4ba0STrond Myklebust 			decode_setclientid_confirm_maxsz, hdr);
1708ff2eb681STrond Myklebust 	encode_uint64(xdr, arg->clientid);
1709cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &arg->confirm);
17101da177e4SLinus Torvalds }
17111da177e4SLinus Torvalds 
17123c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
17133c6b899cSAnna Schumaker 			 struct compound_hdr *hdr)
17141da177e4SLinus Torvalds {
17158687b63aSAl Viro 	__be32 *p;
17161da177e4SLinus Torvalds 
1717ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
17189b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
17191da177e4SLinus Torvalds 
172013c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1721b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1722e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
172334558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17241da177e4SLinus Torvalds 
17251da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
17261da177e4SLinus Torvalds }
17271da177e4SLinus Torvalds 
1728cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17291da177e4SLinus Torvalds {
1730ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1731ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
17321da177e4SLinus Torvalds }
17339b7b9fccSAndy Adamson 
17345a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17355a5ea0d4SBryan Schumaker {
1736ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
17376fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
17385a5ea0d4SBryan Schumaker }
17395a5ea0d4SBryan Schumaker 
174099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17419b7b9fccSAndy Adamson /* NFSv4.1 operations */
17427c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
174371a097c6STrond Myklebust 				   struct nfs41_bind_conn_to_session_args *args,
17447c44f1aeSWeston Andros Adamson 				   struct compound_hdr *hdr)
17457c44f1aeSWeston Andros Adamson {
17467c44f1aeSWeston Andros Adamson 	__be32 *p;
17477c44f1aeSWeston Andros Adamson 
17487c44f1aeSWeston Andros Adamson 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17497c44f1aeSWeston Andros Adamson 		decode_bind_conn_to_session_maxsz, hdr);
175071a097c6STrond Myklebust 	encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
17517c44f1aeSWeston Andros Adamson 	p = xdr_reserve_space(xdr, 8);
175271a097c6STrond Myklebust 	*p++ = cpu_to_be32(args->dir);
175371a097c6STrond Myklebust 	*p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
17547c44f1aeSWeston Andros Adamson }
17557c44f1aeSWeston Andros Adamson 
17562031cd1aSWeston Andros Adamson static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
17572031cd1aSWeston Andros Adamson {
17582031cd1aSWeston Andros Adamson 	unsigned int i;
17592031cd1aSWeston Andros Adamson 	encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
17602031cd1aSWeston Andros Adamson 	for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
17612031cd1aSWeston Andros Adamson 		encode_uint32(xdr, op_map->u.words[i]);
17622031cd1aSWeston Andros Adamson }
17632031cd1aSWeston Andros Adamson 
176499fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
176599fe60d0SBenny Halevy 			       struct nfs41_exchange_id_args *args,
176699fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
176799fe60d0SBenny Halevy {
176899fe60d0SBenny Halevy 	__be32 *p;
1769d751f748SJim Rees 	char impl_name[IMPL_NAME_LIMIT];
1770db8ac8baSWeston Andros Adamson 	int len = 0;
177199fe60d0SBenny Halevy 
177270019514STrond Myklebust 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1773cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, args->verifier);
177499fe60d0SBenny Halevy 
17753a6bb738SJeff Layton 	encode_string(xdr, strlen(args->client->cl_owner_id),
17763a6bb738SJeff Layton 			args->client->cl_owner_id);
177799fe60d0SBenny Halevy 
17782031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->flags);
17792031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->state_protect.how);
17802031cd1aSWeston Andros Adamson 
17812031cd1aSWeston Andros Adamson 	switch (args->state_protect.how) {
17822031cd1aSWeston Andros Adamson 	case SP4_NONE:
17832031cd1aSWeston Andros Adamson 		break;
17842031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
17852031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.enforce);
17862031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.allow);
17872031cd1aSWeston Andros Adamson 		break;
17882031cd1aSWeston Andros Adamson 	default:
17892031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
17902031cd1aSWeston Andros Adamson 		break;
17912031cd1aSWeston Andros Adamson 	}
1792db8ac8baSWeston Andros Adamson 
1793db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1794db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1795db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1796d751f748SJim Rees 		<= sizeof(impl_name) + 1)
1797db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1798db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1799db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1800db8ac8baSWeston Andros Adamson 
1801db8ac8baSWeston Andros Adamson 	if (len > 0) {
18022031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 1);	/* implementation id array length=1 */
1803db8ac8baSWeston Andros Adamson 
1804db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1805db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1806db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1807db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1808db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1809db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1810db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1811db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1812db8ac8baSWeston Andros Adamson 	} else
18132031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 0);	/* implementation id array length=0 */
181499fe60d0SBenny Halevy }
1815fc931582SAndy Adamson 
1816fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1817fc931582SAndy Adamson 				  struct nfs41_create_session_args *args,
1818fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1819fc931582SAndy Adamson {
1820fc931582SAndy Adamson 	__be32 *p;
1821fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
182289f0ff38STrond Myklebust 	struct rpc_clnt *clnt = clp->cl_rpcclient;
1823f092075dSChuck Lever 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
18248e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18258e0d46e1SMike Sager 
18268e0d46e1SMike Sager 	/*
18278e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18288e0d46e1SMike Sager 	 * 2 is the verifier.
18298e0d46e1SMike Sager 	 */
18308e0d46e1SMike Sager 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
18318e0d46e1SMike Sager 			      RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1832fc931582SAndy Adamson 
1833475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
183489f0ff38STrond Myklebust 	p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
183579969dd1STrond Myklebust 	p = xdr_encode_hyper(p, args->clientid);
183679969dd1STrond Myklebust 	*p++ = cpu_to_be32(args->seqid);			/*Sequence id */
1837e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1838fc931582SAndy Adamson 
1839fc931582SAndy Adamson 	/* Fore Channel */
1840c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1841e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1842e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18438e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1844e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1845e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1846e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1847fc931582SAndy Adamson 
1848fc931582SAndy Adamson 	/* Back Channel */
1849c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1850e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1851e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1852e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1853e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1854e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1855e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1856fc931582SAndy Adamson 
1857e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1858e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1859e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1860fc931582SAndy Adamson 
1861fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
18622f86e091SDeepa Dinamani 	*p++ = cpu_to_be32(ktime_to_ns(nn->boot_time));	/* stamp */
186389f0ff38STrond Myklebust 	p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1864e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1865e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
186634558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1867fc931582SAndy Adamson }
18680f3e66c6SAndy Adamson 
18690f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
18700f3e66c6SAndy Adamson 				   struct nfs4_session *session,
18710f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18720f3e66c6SAndy Adamson {
1873475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1874475d4ba0STrond Myklebust 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18750f3e66c6SAndy Adamson }
187618019753SRicardo Labiaga 
187766245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
187866245539STrond Myklebust 				   uint64_t clientid,
187966245539STrond Myklebust 				   struct compound_hdr *hdr)
188066245539STrond Myklebust {
188166245539STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
188266245539STrond Myklebust 	encode_uint64(xdr, clientid);
188366245539STrond Myklebust }
188466245539STrond Myklebust 
188518019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
188618019753SRicardo Labiaga 				    struct nfs41_reclaim_complete_args *args,
188718019753SRicardo Labiaga 				    struct compound_hdr *hdr)
188818019753SRicardo Labiaga {
1889475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1890475d4ba0STrond Myklebust 	encode_uint32(xdr, args->one_fs);
189118019753SRicardo Labiaga }
189299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
189399fe60d0SBenny Halevy 
18949b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
18959b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
18969b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
18979b7b9fccSAndy Adamson {
18989b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
18992b2fa717STrond Myklebust 	struct nfs4_session *session;
1900fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
19012b2fa717STrond Myklebust 	struct nfs4_slot *slot = args->sa_slot;
1902fc01cea9SAndy Adamson 	__be32 *p;
19039b7b9fccSAndy Adamson 
19042b2fa717STrond Myklebust 	tp = slot->table;
19052b2fa717STrond Myklebust 	session = tp->session;
19063bd2384aSChuck Lever 	if (!session)
19073bd2384aSChuck Lever 		return;
1908fc01cea9SAndy Adamson 
1909475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1910fc01cea9SAndy Adamson 
1911fc01cea9SAndy Adamson 	/*
1912fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1913fc01cea9SAndy Adamson 	 */
1914fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1915fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1916fc01cea9SAndy Adamson 		__func__,
1917fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1918fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1919fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1920fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
19212b2fa717STrond Myklebust 		slot->seq_nr, slot->slot_nr,
1922fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
1923475d4ba0STrond Myklebust 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
192493f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1925e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
19262b2fa717STrond Myklebust 	*p++ = cpu_to_be32(slot->slot_nr);
1927e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
192834558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19299b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19309b7b9fccSAndy Adamson }
19319b7b9fccSAndy Adamson 
1932b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1933b1f69b75SAndy Adamson static void
1934b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1935b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1936b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1937b1f69b75SAndy Adamson {
1938b1f69b75SAndy Adamson 	__be32 *p;
1939b1f69b75SAndy Adamson 
1940475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
194184c9dee3SChristoph Hellwig 	p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1942b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1943b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1944b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1945f1c097beSAndy Adamson 	*p++ = cpu_to_be32(args->pdev->maxcount);	/* gdia_maxcount */
194684c9dee3SChristoph Hellwig 
194784c9dee3SChristoph Hellwig 	p = reserve_space(xdr, 4 + 4);
194884c9dee3SChristoph Hellwig 	*p++ = cpu_to_be32(1);			/* bitmap length */
19494e590803STrond Myklebust 	*p++ = cpu_to_be32(args->notify_types);
1950b1f69b75SAndy Adamson }
1951b1f69b75SAndy Adamson 
1952b1f69b75SAndy Adamson static void
1953b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1954b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1955b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1956b1f69b75SAndy Adamson {
1957b1f69b75SAndy Adamson 	__be32 *p;
1958b1f69b75SAndy Adamson 
1959475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1960475d4ba0STrond Myklebust 	p = reserve_space(xdr, 36);
1961b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1962b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
1963b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
1964b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
1965b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
1966b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
1967ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1968475d4ba0STrond Myklebust 	encode_uint32(xdr, args->maxcount);
1969b1f69b75SAndy Adamson 
1970b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1971b1f69b75SAndy Adamson 		__func__,
1972b1f69b75SAndy Adamson 		args->type,
1973b1f69b75SAndy Adamson 		args->range.iomode,
1974b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
1975b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
1976b1f69b75SAndy Adamson 		args->maxcount);
1977b1f69b75SAndy Adamson }
1978863a3c6cSAndy Adamson 
1979863a3c6cSAndy Adamson static int
1980863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
1981ac7db726SBenny Halevy 		    struct inode *inode,
19825f919c9fSChristoph Hellwig 		    struct nfs4_layoutcommit_args *args,
1983863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
1984863a3c6cSAndy Adamson {
1985863a3c6cSAndy Adamson 	__be32 *p;
1986863a3c6cSAndy Adamson 
1987863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1989863a3c6cSAndy Adamson 
1990475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1991475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1992863a3c6cSAndy Adamson 	/* Only whole file layouts */
1993863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
19943557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
1995ea9d23f5STrond Myklebust 	*p = cpu_to_be32(0); /* reclaim */
1996ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
19972e18d4d8STrond Myklebust 	if (args->lastbytewritten != U64_MAX) {
1998ea9d23f5STrond Myklebust 		p = reserve_space(xdr, 20);
1999863a3c6cSAndy Adamson 		*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2000863a3c6cSAndy Adamson 		p = xdr_encode_hyper(p, args->lastbytewritten);
20012e18d4d8STrond Myklebust 	} else {
20022e18d4d8STrond Myklebust 		p = reserve_space(xdr, 12);
20032e18d4d8STrond Myklebust 		*p++ = cpu_to_be32(0); /* newoffset = FALSE */
20042e18d4d8STrond Myklebust 	}
2005863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2006863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2007ac7db726SBenny Halevy 
20085f919c9fSChristoph Hellwig 	encode_uint32(xdr, args->layoutupdate_len);
200973504740STrond Myklebust 	if (args->layoutupdate_pages)
20105f919c9fSChristoph Hellwig 		xdr_write_pages(xdr, args->layoutupdate_pages, 0,
20115f919c9fSChristoph Hellwig 				args->layoutupdate_len);
2012863a3c6cSAndy Adamson 
2013863a3c6cSAndy Adamson 	return 0;
2014863a3c6cSAndy Adamson }
2015cbe82603SBenny Halevy 
2016cbe82603SBenny Halevy static void
2017cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2018cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2019cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2020cbe82603SBenny Halevy {
2021cbe82603SBenny Halevy 	__be32 *p;
2022cbe82603SBenny Halevy 
2023475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2024475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
2025cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2026cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
202715eb67c1SPeng Tao 	*p++ = cpu_to_be32(args->range.iomode);
2028cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2029ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
203015eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.offset);
203115eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.length);
2032cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2033ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
2034cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
20354d796d75STrond Myklebust 	if (args->ld_private->ops && args->ld_private->ops->encode)
20364d796d75STrond Myklebust 		args->ld_private->ops->encode(xdr, args, args->ld_private);
203794e5c571STrond Myklebust 	else
2038475d4ba0STrond Myklebust 		encode_uint32(xdr, 0);
2039cbe82603SBenny Halevy }
2040fca78d6dSBryan Schumaker 
2041fca78d6dSBryan Schumaker static int
2042fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2043fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2044fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2045fca78d6dSBryan Schumaker {
2046475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2047475d4ba0STrond Myklebust 	encode_uint32(xdr, args->style);
2048fca78d6dSBryan Schumaker 	return 0;
2049fca78d6dSBryan Schumaker }
20507d974794SBryan Schumaker 
20517d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
20527d974794SBryan Schumaker 				struct nfs41_test_stateid_args *args,
20537d974794SBryan Schumaker 				struct compound_hdr *hdr)
20547d974794SBryan Schumaker {
2055475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2056475d4ba0STrond Myklebust 	encode_uint32(xdr, 1);
2057ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20587d974794SBryan Schumaker }
20599aeda35fSBryan Schumaker 
20609aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
20619aeda35fSBryan Schumaker 				struct nfs41_free_stateid_args *args,
20629aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
20639aeda35fSBryan Schumaker {
2064ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
20657c1d5faeSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20669aeda35fSBryan Schumaker }
2067cf805165STrond Myklebust #else
2068cf805165STrond Myklebust static inline void
2069cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr,
2070cf805165STrond Myklebust 		    const struct nfs4_layoutreturn_args *args,
2071cf805165STrond Myklebust 		    struct compound_hdr *hdr)
2072cf805165STrond Myklebust {
2073cf805165STrond Myklebust }
2074b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2075b1f69b75SAndy Adamson 
20761da177e4SLinus Torvalds /*
20771da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
20781da177e4SLinus Torvalds  */
20791da177e4SLinus Torvalds 
208066cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
208166cc0429SBenny Halevy {
208266cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
20833bd2384aSChuck Lever 	struct nfs4_session *session = args->sa_slot->table->session;
20843bd2384aSChuck Lever 	if (session)
20853bd2384aSChuck Lever 		return session->clp->cl_mvops->minor_version;
208666cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
208766cc0429SBenny Halevy 	return 0;
208866cc0429SBenny Halevy }
208966cc0429SBenny Halevy 
20901da177e4SLinus Torvalds /*
20911da177e4SLinus Torvalds  * Encode an ACCESS request
20921da177e4SLinus Torvalds  */
20939f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
20949f06c719SChuck Lever 				const struct nfs4_accessargs *args)
20951da177e4SLinus Torvalds {
20961da177e4SLinus Torvalds 	struct compound_hdr hdr = {
209766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
20981da177e4SLinus Torvalds 	};
20991da177e4SLinus Torvalds 
21009f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21019f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21029f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21039f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
21049f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2105d017931cSAndy Adamson 	encode_nops(&hdr);
21061da177e4SLinus Torvalds }
21071da177e4SLinus Torvalds 
21081da177e4SLinus Torvalds /*
21091da177e4SLinus Torvalds  * Encode LOOKUP request
21101da177e4SLinus Torvalds  */
21119f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
21129f06c719SChuck Lever 				const struct nfs4_lookup_arg *args)
21131da177e4SLinus Torvalds {
21141da177e4SLinus Torvalds 	struct compound_hdr hdr = {
211566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21161da177e4SLinus Torvalds 	};
21171da177e4SLinus Torvalds 
21189f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21199f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21209f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21219f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21229f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21239f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2124d017931cSAndy Adamson 	encode_nops(&hdr);
21251da177e4SLinus Torvalds }
21261da177e4SLinus Torvalds 
21271da177e4SLinus Torvalds /*
21281da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21291da177e4SLinus Torvalds  */
21309f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21319f06c719SChuck Lever 				     struct xdr_stream *xdr,
21329f06c719SChuck Lever 				     const struct nfs4_lookup_root_arg *args)
21331da177e4SLinus Torvalds {
21341da177e4SLinus Torvalds 	struct compound_hdr hdr = {
213566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21361da177e4SLinus Torvalds 	};
21371da177e4SLinus Torvalds 
21389f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21399f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21409f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21419f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21429f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2143d017931cSAndy Adamson 	encode_nops(&hdr);
21441da177e4SLinus Torvalds }
21451da177e4SLinus Torvalds 
21461da177e4SLinus Torvalds /*
21471da177e4SLinus Torvalds  * Encode REMOVE request
21481da177e4SLinus Torvalds  */
21499f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
21509f06c719SChuck Lever 				const struct nfs_removeargs *args)
21511da177e4SLinus Torvalds {
21521da177e4SLinus Torvalds 	struct compound_hdr hdr = {
215366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21541da177e4SLinus Torvalds 	};
21551da177e4SLinus Torvalds 
21569f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21579f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21589f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21599f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
2160d017931cSAndy Adamson 	encode_nops(&hdr);
21611da177e4SLinus Torvalds }
21621da177e4SLinus Torvalds 
21631da177e4SLinus Torvalds /*
21641da177e4SLinus Torvalds  * Encode RENAME request
21651da177e4SLinus Torvalds  */
21669f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
21679f06c719SChuck Lever 				const struct nfs_renameargs *args)
21681da177e4SLinus Torvalds {
21691da177e4SLinus Torvalds 	struct compound_hdr hdr = {
217066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21711da177e4SLinus Torvalds 	};
21721da177e4SLinus Torvalds 
21739f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21749f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21759f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
21769f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21779f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
21789f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2179d017931cSAndy Adamson 	encode_nops(&hdr);
21801da177e4SLinus Torvalds }
21811da177e4SLinus Torvalds 
21821da177e4SLinus Torvalds /*
21831da177e4SLinus Torvalds  * Encode LINK request
21841da177e4SLinus Torvalds  */
21859f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
21869f06c719SChuck Lever 			     const struct nfs4_link_arg *args)
21871da177e4SLinus Torvalds {
21881da177e4SLinus Torvalds 	struct compound_hdr hdr = {
218966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21901da177e4SLinus Torvalds 	};
21911da177e4SLinus Torvalds 
21929f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21939f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21949f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21959f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21969f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21979f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
21989f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
21999f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2200d017931cSAndy Adamson 	encode_nops(&hdr);
22011da177e4SLinus Torvalds }
22021da177e4SLinus Torvalds 
22031da177e4SLinus Torvalds /*
22041da177e4SLinus Torvalds  * Encode CREATE request
22051da177e4SLinus Torvalds  */
22069f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
22079f06c719SChuck Lever 				const struct nfs4_create_arg *args)
22081da177e4SLinus Torvalds {
22091da177e4SLinus Torvalds 	struct compound_hdr hdr = {
221066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22111da177e4SLinus Torvalds 	};
22121da177e4SLinus Torvalds 
22139f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22149f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22159f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22169f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22179f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22189f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2219d017931cSAndy Adamson 	encode_nops(&hdr);
22201da177e4SLinus Torvalds }
22211da177e4SLinus Torvalds 
22221da177e4SLinus Torvalds /*
22231da177e4SLinus Torvalds  * Encode SYMLINK request
22241da177e4SLinus Torvalds  */
22259f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
22269f06c719SChuck Lever 				 const struct nfs4_create_arg *args)
22271da177e4SLinus Torvalds {
22289f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22291da177e4SLinus Torvalds }
22301da177e4SLinus Torvalds 
22311da177e4SLinus Torvalds /*
22321da177e4SLinus Torvalds  * Encode GETATTR request
22331da177e4SLinus Torvalds  */
22349f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
22359f06c719SChuck Lever 				 const struct nfs4_getattr_arg *args)
22361da177e4SLinus Torvalds {
22371da177e4SLinus Torvalds 	struct compound_hdr hdr = {
223866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22391da177e4SLinus Torvalds 	};
22401da177e4SLinus Torvalds 
22419f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22429f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22439f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22449f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2245d017931cSAndy Adamson 	encode_nops(&hdr);
22461da177e4SLinus Torvalds }
22471da177e4SLinus Torvalds 
22481da177e4SLinus Torvalds /*
22491da177e4SLinus Torvalds  * Encode a CLOSE request
22501da177e4SLinus Torvalds  */
22519f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
22529f06c719SChuck Lever 			       struct nfs_closeargs *args)
22531da177e4SLinus Torvalds {
22541da177e4SLinus Torvalds 	struct compound_hdr hdr = {
225566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22561da177e4SLinus Torvalds 	};
22571da177e4SLinus Torvalds 
22589f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22599f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22609f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2261cf805165STrond Myklebust 	if (args->lr_args)
2262cf805165STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
22633ecefc92STrond Myklebust 	if (args->bitmask != NULL)
22649f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2265d8d84983STrond Myklebust 	encode_close(xdr, args, &hdr);
2266d017931cSAndy Adamson 	encode_nops(&hdr);
22671da177e4SLinus Torvalds }
22681da177e4SLinus Torvalds 
22691da177e4SLinus Torvalds /*
22701da177e4SLinus Torvalds  * Encode an OPEN request
22711da177e4SLinus Torvalds  */
22729f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
22739f06c719SChuck Lever 			      struct nfs_openargs *args)
22741da177e4SLinus Torvalds {
22751da177e4SLinus Torvalds 	struct compound_hdr hdr = {
227666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22771da177e4SLinus Torvalds 	};
22781da177e4SLinus Torvalds 
22799f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22809f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22819f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22829f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
22839f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
2284ae2bb032SWeston Andros Adamson 	if (args->access)
22856168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
22861549210fSTrond Myklebust 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2287d017931cSAndy Adamson 	encode_nops(&hdr);
22881da177e4SLinus Torvalds }
22891da177e4SLinus Torvalds 
22901da177e4SLinus Torvalds /*
22911da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
22921da177e4SLinus Torvalds  */
22939f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
22949f06c719SChuck Lever 				      struct xdr_stream *xdr,
22959f06c719SChuck Lever 				      struct nfs_open_confirmargs *args)
22961da177e4SLinus Torvalds {
22971da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2298d017931cSAndy Adamson 		.nops   = 0,
22991da177e4SLinus Torvalds 	};
23001da177e4SLinus Torvalds 
23019f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23029f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23039f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2304d017931cSAndy Adamson 	encode_nops(&hdr);
23051da177e4SLinus Torvalds }
23061da177e4SLinus Torvalds 
23071da177e4SLinus Torvalds /*
23081da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
23091da177e4SLinus Torvalds  */
23109f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
23119f06c719SChuck Lever 				     struct xdr_stream *xdr,
23129f06c719SChuck Lever 				     struct nfs_openargs *args)
23131da177e4SLinus Torvalds {
23141da177e4SLinus Torvalds 	struct compound_hdr hdr = {
231566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23161da177e4SLinus Torvalds 	};
23171da177e4SLinus Torvalds 
23189f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23199f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23209f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23219f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
2322ae2bb032SWeston Andros Adamson 	if (args->access)
23236168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
2324e23008ecSAndy Adamson 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2325d017931cSAndy Adamson 	encode_nops(&hdr);
23261da177e4SLinus Torvalds }
23271da177e4SLinus Torvalds 
23281da177e4SLinus Torvalds /*
23291da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23301da177e4SLinus Torvalds  */
23319f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
23329f06c719SChuck Lever 					struct xdr_stream *xdr,
23339f06c719SChuck Lever 					struct nfs_closeargs *args)
23341da177e4SLinus Torvalds {
23351da177e4SLinus Torvalds 	struct compound_hdr hdr = {
233666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23371da177e4SLinus Torvalds 	};
23381da177e4SLinus Torvalds 
23399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23409f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23419f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2342b6808145STrond Myklebust 	if (args->lr_args)
2343b6808145STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
23449f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
2345d017931cSAndy Adamson 	encode_nops(&hdr);
23461da177e4SLinus Torvalds }
23471da177e4SLinus Torvalds 
23481da177e4SLinus Torvalds /*
23491da177e4SLinus Torvalds  * Encode a LOCK request
23501da177e4SLinus Torvalds  */
23519f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
23529f06c719SChuck Lever 			      struct nfs_lock_args *args)
23531da177e4SLinus Torvalds {
23541da177e4SLinus Torvalds 	struct compound_hdr hdr = {
235566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23561da177e4SLinus Torvalds 	};
23571da177e4SLinus Torvalds 
23589f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23599f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23609f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23619f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2362d017931cSAndy Adamson 	encode_nops(&hdr);
23631da177e4SLinus Torvalds }
23641da177e4SLinus Torvalds 
23651da177e4SLinus Torvalds /*
23661da177e4SLinus Torvalds  * Encode a LOCKT request
23671da177e4SLinus Torvalds  */
23689f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
23699f06c719SChuck Lever 			       struct nfs_lockt_args *args)
23701da177e4SLinus Torvalds {
23711da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23731da177e4SLinus Torvalds 	};
23741da177e4SLinus Torvalds 
23759f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23769f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23779f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23789f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2379d017931cSAndy Adamson 	encode_nops(&hdr);
23801da177e4SLinus Torvalds }
23811da177e4SLinus Torvalds 
23821da177e4SLinus Torvalds /*
23831da177e4SLinus Torvalds  * Encode a LOCKU request
23841da177e4SLinus Torvalds  */
23859f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
23869f06c719SChuck Lever 			       struct nfs_locku_args *args)
23871da177e4SLinus Torvalds {
23881da177e4SLinus Torvalds 	struct compound_hdr hdr = {
238966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23901da177e4SLinus Torvalds 	};
23911da177e4SLinus Torvalds 
23929f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23939f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23949f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23959f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2396d017931cSAndy Adamson 	encode_nops(&hdr);
23971da177e4SLinus Torvalds }
23981da177e4SLinus Torvalds 
23999f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
24009f06c719SChuck Lever 					   struct xdr_stream *xdr,
24019f06c719SChuck Lever 					struct nfs_release_lockowner_args *args)
2402d3c7b7ccSTrond Myklebust {
2403d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2404d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2405d3c7b7ccSTrond Myklebust 	};
2406d3c7b7ccSTrond Myklebust 
24079f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24089f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2409d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2410d3c7b7ccSTrond Myklebust }
2411d3c7b7ccSTrond Myklebust 
24121da177e4SLinus Torvalds /*
24131da177e4SLinus Torvalds  * Encode a READLINK request
24141da177e4SLinus Torvalds  */
24159f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
24169f06c719SChuck Lever 				  const struct nfs4_readlink *args)
24171da177e4SLinus Torvalds {
24181da177e4SLinus Torvalds 	struct compound_hdr hdr = {
241966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24201da177e4SLinus Torvalds 	};
24211da177e4SLinus Torvalds 
24229f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24239f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24249f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24259f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2426e3a535e1STrond Myklebust 
242728f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2428e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2429d017931cSAndy Adamson 	encode_nops(&hdr);
24301da177e4SLinus Torvalds }
24311da177e4SLinus Torvalds 
24321da177e4SLinus Torvalds /*
24331da177e4SLinus Torvalds  * Encode a READDIR request
24341da177e4SLinus Torvalds  */
24359f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
24369f06c719SChuck Lever 				 const struct nfs4_readdir_arg *args)
24371da177e4SLinus Torvalds {
24381da177e4SLinus Torvalds 	struct compound_hdr hdr = {
243966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24401da177e4SLinus Torvalds 	};
24411da177e4SLinus Torvalds 
24429f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24439f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24449f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24459f06c719SChuck Lever 	encode_readdir(xdr, args, req, &hdr);
2446d6ac02dfSTrond Myklebust 
244728f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2448d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2449d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
245028f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2451d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2452d017931cSAndy Adamson 	encode_nops(&hdr);
24531da177e4SLinus Torvalds }
24541da177e4SLinus Torvalds 
24551da177e4SLinus Torvalds /*
24561da177e4SLinus Torvalds  * Encode a READ request
24571da177e4SLinus Torvalds  */
24589f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
24593c6b899cSAnna Schumaker 			      struct nfs_pgio_args *args)
24601da177e4SLinus Torvalds {
24611da177e4SLinus Torvalds 	struct compound_hdr hdr = {
246266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24631da177e4SLinus Torvalds 	};
24641da177e4SLinus Torvalds 
24659f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24669f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24679f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24689f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
24691da177e4SLinus Torvalds 
247028f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
24711da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
24724f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2473d017931cSAndy Adamson 	encode_nops(&hdr);
24741da177e4SLinus Torvalds }
24751da177e4SLinus Torvalds 
24761da177e4SLinus Torvalds /*
24771da177e4SLinus Torvalds  * Encode an SETATTR request
24781da177e4SLinus Torvalds  */
24799f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
24809f06c719SChuck Lever 				 struct nfs_setattrargs *args)
24811da177e4SLinus Torvalds {
24821da177e4SLinus Torvalds 	struct compound_hdr hdr = {
248366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24841da177e4SLinus Torvalds 	};
24851da177e4SLinus Torvalds 
24869f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24879f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24889f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24899f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
24909f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2491d017931cSAndy Adamson 	encode_nops(&hdr);
24921da177e4SLinus Torvalds }
24931da177e4SLinus Torvalds 
24941da177e4SLinus Torvalds /*
2495029d105eSJ. Bruce Fields  * Encode a GETACL request
2496029d105eSJ. Bruce Fields  */
24979f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2498029d105eSJ. Bruce Fields 				struct nfs_getaclargs *args)
2499029d105eSJ. Bruce Fields {
2500029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
250166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2502029d105eSJ. Bruce Fields 	};
250328f56694SBenny Halevy 	uint32_t replen;
2504029d105eSJ. Bruce Fields 
25059f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25069f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25079f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25086682c14bSJ. Bruce Fields 	replen = hdr.replen + op_decode_hdr_maxsz;
25099f06c719SChuck Lever 	encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2510cf8cdbe5SAndy Adamson 
251128f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
25128fbcf237SAndreas Gruenbacher 		args->acl_pages, 0, args->acl_len);
2513bf118a34SAndy Adamson 
2514d017931cSAndy Adamson 	encode_nops(&hdr);
2515029d105eSJ. Bruce Fields }
2516029d105eSJ. Bruce Fields 
2517029d105eSJ. Bruce Fields /*
25181da177e4SLinus Torvalds  * Encode a WRITE request
25191da177e4SLinus Torvalds  */
25209f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
25213c6b899cSAnna Schumaker 			       struct nfs_pgio_args *args)
25221da177e4SLinus Torvalds {
25231da177e4SLinus Torvalds 	struct compound_hdr hdr = {
252466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25251da177e4SLinus Torvalds 	};
25261da177e4SLinus Torvalds 
25279f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25289f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25299f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25309f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
25314f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
25327ffd1064SFred Isaman 	if (args->bitmask)
25339f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2534d017931cSAndy Adamson 	encode_nops(&hdr);
25351da177e4SLinus Torvalds }
25361da177e4SLinus Torvalds 
25371da177e4SLinus Torvalds /*
25381da177e4SLinus Torvalds  *  a COMMIT request
25391da177e4SLinus Torvalds  */
25409f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
25410b7c0153SFred Isaman 				struct nfs_commitargs *args)
25421da177e4SLinus Torvalds {
25431da177e4SLinus Torvalds 	struct compound_hdr hdr = {
254466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25451da177e4SLinus Torvalds 	};
25461da177e4SLinus Torvalds 
25479f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25489f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25499f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25509f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2551d017931cSAndy Adamson 	encode_nops(&hdr);
25521da177e4SLinus Torvalds }
25531da177e4SLinus Torvalds 
25541da177e4SLinus Torvalds /*
25551da177e4SLinus Torvalds  * FSINFO request
25561da177e4SLinus Torvalds  */
25579f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
25589f06c719SChuck Lever 				struct nfs4_fsinfo_arg *args)
25591da177e4SLinus Torvalds {
25601da177e4SLinus Torvalds 	struct compound_hdr hdr = {
256166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25621da177e4SLinus Torvalds 	};
25631da177e4SLinus Torvalds 
25649f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25659f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25669f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25679f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2568d017931cSAndy Adamson 	encode_nops(&hdr);
25691da177e4SLinus Torvalds }
25701da177e4SLinus Torvalds 
25711da177e4SLinus Torvalds /*
25721da177e4SLinus Torvalds  * a PATHCONF request
25731da177e4SLinus Torvalds  */
25749f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
25759f06c719SChuck Lever 				  const struct nfs4_pathconf_arg *args)
25761da177e4SLinus Torvalds {
25771da177e4SLinus Torvalds 	struct compound_hdr hdr = {
257866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25791da177e4SLinus Torvalds 	};
25801da177e4SLinus Torvalds 
25819f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25829f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25839f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25849f06c719SChuck Lever 	encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2585d017931cSAndy Adamson 			   &hdr);
2586d017931cSAndy Adamson 	encode_nops(&hdr);
25871da177e4SLinus Torvalds }
25881da177e4SLinus Torvalds 
25891da177e4SLinus Torvalds /*
25901da177e4SLinus Torvalds  * a STATFS request
25911da177e4SLinus Torvalds  */
25929f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
25939f06c719SChuck Lever 				const struct nfs4_statfs_arg *args)
25941da177e4SLinus Torvalds {
25951da177e4SLinus Torvalds 	struct compound_hdr hdr = {
259666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25971da177e4SLinus Torvalds 	};
25981da177e4SLinus Torvalds 
25999f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26009f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26019f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26029f06c719SChuck Lever 	encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2603d017931cSAndy Adamson 			   args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2604d017931cSAndy Adamson 	encode_nops(&hdr);
26051da177e4SLinus Torvalds }
26061da177e4SLinus Torvalds 
26071da177e4SLinus Torvalds /*
26081da177e4SLinus Torvalds  * GETATTR_BITMAP request
26091da177e4SLinus Torvalds  */
26109f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
26119f06c719SChuck Lever 				     struct xdr_stream *xdr,
261243652ad5SBenny Halevy 				     struct nfs4_server_caps_arg *args)
26131da177e4SLinus Torvalds {
26148c61282fSKinglong Mee 	const u32 *bitmask = args->bitmask;
26151da177e4SLinus Torvalds 	struct compound_hdr hdr = {
261666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26171da177e4SLinus Torvalds 	};
26181da177e4SLinus Torvalds 
26199f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26209f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26219f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
26228c61282fSKinglong Mee 	encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
2623d017931cSAndy Adamson 	encode_nops(&hdr);
26241da177e4SLinus Torvalds }
26251da177e4SLinus Torvalds 
26261da177e4SLinus Torvalds /*
26271da177e4SLinus Torvalds  * a RENEW request
26281da177e4SLinus Torvalds  */
26299f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
26309f06c719SChuck Lever 			       struct nfs_client *clp)
26311da177e4SLinus Torvalds {
26321da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2633d017931cSAndy Adamson 		.nops	= 0,
26341da177e4SLinus Torvalds 	};
26351da177e4SLinus Torvalds 
26369f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2637bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2638d017931cSAndy Adamson 	encode_nops(&hdr);
26391da177e4SLinus Torvalds }
26401da177e4SLinus Torvalds 
26411da177e4SLinus Torvalds /*
26421da177e4SLinus Torvalds  * a SETCLIENTID request
26431da177e4SLinus Torvalds  */
26449f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
26459f06c719SChuck Lever 				     struct xdr_stream *xdr,
26469f06c719SChuck Lever 				     struct nfs4_setclientid *sc)
26471da177e4SLinus Torvalds {
26481da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2649d017931cSAndy Adamson 		.nops	= 0,
26501da177e4SLinus Torvalds 	};
26511da177e4SLinus Torvalds 
26529f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26539f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2654d017931cSAndy Adamson 	encode_nops(&hdr);
26551da177e4SLinus Torvalds }
26561da177e4SLinus Torvalds 
26571da177e4SLinus Torvalds /*
26581da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
26591da177e4SLinus Torvalds  */
26609f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
26619f06c719SChuck Lever 					     struct xdr_stream *xdr,
26629f06c719SChuck Lever 					     struct nfs4_setclientid_res *arg)
26631da177e4SLinus Torvalds {
26641da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2665d017931cSAndy Adamson 		.nops	= 0,
26661da177e4SLinus Torvalds 	};
26671da177e4SLinus Torvalds 
26689f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26699f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
2670d017931cSAndy Adamson 	encode_nops(&hdr);
26711da177e4SLinus Torvalds }
26721da177e4SLinus Torvalds 
26731da177e4SLinus Torvalds /*
26741da177e4SLinus Torvalds  * DELEGRETURN request
26751da177e4SLinus Torvalds  */
26769f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
26779f06c719SChuck Lever 				     struct xdr_stream *xdr,
26789f06c719SChuck Lever 				     const struct nfs4_delegreturnargs *args)
26791da177e4SLinus Torvalds {
26801da177e4SLinus Torvalds 	struct compound_hdr hdr = {
268166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26821da177e4SLinus Torvalds 	};
26831da177e4SLinus Torvalds 
26849f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26859f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26869f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
2687586f1c39STrond Myklebust 	if (args->lr_args)
2688586f1c39STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
26898ac2b422STrond Myklebust 	if (args->bitmask)
26909f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2691e144cbccSTrond Myklebust 	encode_delegreturn(xdr, args->stateid, &hdr);
2692d017931cSAndy Adamson 	encode_nops(&hdr);
26931da177e4SLinus Torvalds }
26941da177e4SLinus Torvalds 
26951da177e4SLinus Torvalds /*
2696683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2697683b57b4STrond Myklebust  */
26989f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
26999f06c719SChuck Lever 				      struct xdr_stream *xdr,
27009f06c719SChuck Lever 				      struct nfs4_fs_locations_arg *args)
2701683b57b4STrond Myklebust {
2702683b57b4STrond Myklebust 	struct compound_hdr hdr = {
270366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2704683b57b4STrond Myklebust 	};
270528f56694SBenny Halevy 	uint32_t replen;
2706683b57b4STrond Myklebust 
27079f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27089f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
2709b03d735bSChuck Lever 	if (args->migration) {
2710b03d735bSChuck Lever 		encode_putfh(xdr, args->fh, &hdr);
2711b03d735bSChuck Lever 		replen = hdr.replen;
2712b03d735bSChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2713b03d735bSChuck Lever 		if (args->renew)
2714b03d735bSChuck Lever 			encode_renew(xdr, args->clientid, &hdr);
2715b03d735bSChuck Lever 	} else {
27169f06c719SChuck Lever 		encode_putfh(xdr, args->dir_fh, &hdr);
27179f06c719SChuck Lever 		encode_lookup(xdr, args->name, &hdr);
2718b03d735bSChuck Lever 		replen = hdr.replen;
27199f06c719SChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2720b03d735bSChuck Lever 	}
2721cf8cdbe5SAndy Adamson 
2722b03d735bSChuck Lever 	/* Set up reply kvec to capture returned fs_locations array. */
272328f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2724683b57b4STrond Myklebust 			0, PAGE_SIZE);
2725d017931cSAndy Adamson 	encode_nops(&hdr);
2726683b57b4STrond Myklebust }
2727683b57b4STrond Myklebust 
27285a5ea0d4SBryan Schumaker /*
27295a5ea0d4SBryan Schumaker  * Encode SECINFO request
27305a5ea0d4SBryan Schumaker  */
27315a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
27325a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
27335a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_arg *args)
27345a5ea0d4SBryan Schumaker {
27355a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
27365a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27375a5ea0d4SBryan Schumaker 	};
27385a5ea0d4SBryan Schumaker 
27395a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
27405a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
27415a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
27425a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
27435a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
27445a5ea0d4SBryan Schumaker }
27455a5ea0d4SBryan Schumaker 
274644c99933SChuck Lever /*
274744c99933SChuck Lever  * Encode FSID_PRESENT request
274844c99933SChuck Lever  */
274944c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
275044c99933SChuck Lever 				      struct xdr_stream *xdr,
275144c99933SChuck Lever 				      struct nfs4_fsid_present_arg *args)
275244c99933SChuck Lever {
275344c99933SChuck Lever 	struct compound_hdr hdr = {
275444c99933SChuck Lever 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
275544c99933SChuck Lever 	};
275644c99933SChuck Lever 
275744c99933SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
275844c99933SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
275944c99933SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
276044c99933SChuck Lever 	encode_getfh(xdr, &hdr);
276144c99933SChuck Lever 	if (args->renew)
276244c99933SChuck Lever 		encode_renew(xdr, args->clientid, &hdr);
276344c99933SChuck Lever 	encode_nops(&hdr);
276444c99933SChuck Lever }
276544c99933SChuck Lever 
276699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
276799fe60d0SBenny Halevy /*
27687c44f1aeSWeston Andros Adamson  * BIND_CONN_TO_SESSION request
27697c44f1aeSWeston Andros Adamson  */
27707c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
27717c44f1aeSWeston Andros Adamson 				struct xdr_stream *xdr,
277271a097c6STrond Myklebust 				struct nfs41_bind_conn_to_session_args *args)
27737c44f1aeSWeston Andros Adamson {
27747c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr = {
277571a097c6STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
27767c44f1aeSWeston Andros Adamson 	};
27777c44f1aeSWeston Andros Adamson 
27787c44f1aeSWeston Andros Adamson 	encode_compound_hdr(xdr, req, &hdr);
277971a097c6STrond Myklebust 	encode_bind_conn_to_session(xdr, args, &hdr);
27807c44f1aeSWeston Andros Adamson 	encode_nops(&hdr);
27817c44f1aeSWeston Andros Adamson }
27827c44f1aeSWeston Andros Adamson 
27837c44f1aeSWeston Andros Adamson /*
278499fe60d0SBenny Halevy  * EXCHANGE_ID request
278599fe60d0SBenny Halevy  */
27869f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
27879f06c719SChuck Lever 				     struct xdr_stream *xdr,
278899fe60d0SBenny Halevy 				     struct nfs41_exchange_id_args *args)
278999fe60d0SBenny Halevy {
279099fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2791a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
279299fe60d0SBenny Halevy 	};
279399fe60d0SBenny Halevy 
27949f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27959f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
279699fe60d0SBenny Halevy 	encode_nops(&hdr);
279799fe60d0SBenny Halevy }
27982050f0ccSAndy Adamson 
27992050f0ccSAndy Adamson /*
2800fc931582SAndy Adamson  * a CREATE_SESSION request
2801fc931582SAndy Adamson  */
28029f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
28039f06c719SChuck Lever 					struct xdr_stream *xdr,
2804fc931582SAndy Adamson 					struct nfs41_create_session_args *args)
2805fc931582SAndy Adamson {
2806fc931582SAndy Adamson 	struct compound_hdr hdr = {
2807a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2808fc931582SAndy Adamson 	};
2809fc931582SAndy Adamson 
28109f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28119f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2812fc931582SAndy Adamson 	encode_nops(&hdr);
2813fc931582SAndy Adamson }
2814fc931582SAndy Adamson 
2815fc931582SAndy Adamson /*
28160f3e66c6SAndy Adamson  * a DESTROY_SESSION request
28170f3e66c6SAndy Adamson  */
28189f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
28199f06c719SChuck Lever 					 struct xdr_stream *xdr,
28200f3e66c6SAndy Adamson 					 struct nfs4_session *session)
28210f3e66c6SAndy Adamson {
28220f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2823a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
28240f3e66c6SAndy Adamson 	};
28250f3e66c6SAndy Adamson 
28269f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28279f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
28280f3e66c6SAndy Adamson 	encode_nops(&hdr);
28290f3e66c6SAndy Adamson }
28300f3e66c6SAndy Adamson 
28310f3e66c6SAndy Adamson /*
283266245539STrond Myklebust  * a DESTROY_CLIENTID request
283366245539STrond Myklebust  */
283466245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
283566245539STrond Myklebust 					 struct xdr_stream *xdr,
283666245539STrond Myklebust 					 struct nfs_client *clp)
283766245539STrond Myklebust {
283866245539STrond Myklebust 	struct compound_hdr hdr = {
283966245539STrond Myklebust 		.minorversion = clp->cl_mvops->minor_version,
284066245539STrond Myklebust 	};
284166245539STrond Myklebust 
284266245539STrond Myklebust 	encode_compound_hdr(xdr, req, &hdr);
284366245539STrond Myklebust 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
284466245539STrond Myklebust 	encode_nops(&hdr);
284566245539STrond Myklebust }
284666245539STrond Myklebust 
284766245539STrond Myklebust /*
2848fc01cea9SAndy Adamson  * a SEQUENCE request
2849fc01cea9SAndy Adamson  */
28509f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2851fc01cea9SAndy Adamson 				  struct nfs4_sequence_args *args)
2852fc01cea9SAndy Adamson {
2853fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2854fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2855fc01cea9SAndy Adamson 	};
2856fc01cea9SAndy Adamson 
28579f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28589f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2859fc01cea9SAndy Adamson 	encode_nops(&hdr);
2860fc01cea9SAndy Adamson }
2861fc01cea9SAndy Adamson 
2862fc01cea9SAndy Adamson /*
28632050f0ccSAndy Adamson  * a GET_LEASE_TIME request
28642050f0ccSAndy Adamson  */
28659f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
28669f06c719SChuck Lever 					struct xdr_stream *xdr,
28672050f0ccSAndy Adamson 					struct nfs4_get_lease_time_args *args)
28682050f0ccSAndy Adamson {
28692050f0ccSAndy Adamson 	struct compound_hdr hdr = {
28702050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
28712050f0ccSAndy Adamson 	};
2872dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
28732050f0ccSAndy Adamson 
28749f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28759f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
28769f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
28779f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
28782050f0ccSAndy Adamson 	encode_nops(&hdr);
28792050f0ccSAndy Adamson }
288018019753SRicardo Labiaga 
288118019753SRicardo Labiaga /*
288218019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
288318019753SRicardo Labiaga  */
28849f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
28859f06c719SChuck Lever 					  struct xdr_stream *xdr,
288618019753SRicardo Labiaga 				struct nfs41_reclaim_complete_args *args)
288718019753SRicardo Labiaga {
288818019753SRicardo Labiaga 	struct compound_hdr hdr = {
288918019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
289018019753SRicardo Labiaga 	};
289118019753SRicardo Labiaga 
28929f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28939f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28949f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
289518019753SRicardo Labiaga 	encode_nops(&hdr);
289618019753SRicardo Labiaga }
289718019753SRicardo Labiaga 
2898b1f69b75SAndy Adamson /*
2899b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
2900b1f69b75SAndy Adamson  */
29019f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
29029f06c719SChuck Lever 				       struct xdr_stream *xdr,
2903b1f69b75SAndy Adamson 				       struct nfs4_getdeviceinfo_args *args)
2904b1f69b75SAndy Adamson {
2905b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2906b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2907b1f69b75SAndy Adamson 	};
2908b1f69b75SAndy Adamson 
29099f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29109f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29119f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
2912b1f69b75SAndy Adamson 
2913b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
2914b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
2915b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2916b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
2917b1f69b75SAndy Adamson 			 args->pdev->pglen);
2918b1f69b75SAndy Adamson 
2919b1f69b75SAndy Adamson 	encode_nops(&hdr);
2920b1f69b75SAndy Adamson }
2921b1f69b75SAndy Adamson 
2922b1f69b75SAndy Adamson /*
2923b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
2924b1f69b75SAndy Adamson  */
29259f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
29269f06c719SChuck Lever 				   struct xdr_stream *xdr,
2927b1f69b75SAndy Adamson 				   struct nfs4_layoutget_args *args)
2928b1f69b75SAndy Adamson {
2929b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2930b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2931b1f69b75SAndy Adamson 	};
2932b1f69b75SAndy Adamson 
29339f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29349f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29359f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
29369f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
293735124a09SWeston Andros Adamson 
293835124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
293935124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
294035124a09SWeston Andros Adamson 
2941b1f69b75SAndy Adamson 	encode_nops(&hdr);
2942b1f69b75SAndy Adamson }
2943863a3c6cSAndy Adamson 
2944863a3c6cSAndy Adamson /*
2945863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
2946863a3c6cSAndy Adamson  */
2947cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2948863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
2949863a3c6cSAndy Adamson 				      struct nfs4_layoutcommit_args *args)
2950863a3c6cSAndy Adamson {
2951ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
2952ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
2953863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
2954863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2955863a3c6cSAndy Adamson 	};
2956863a3c6cSAndy Adamson 
2957863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
2958863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
2959863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2960ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2961863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
2962863a3c6cSAndy Adamson 	encode_nops(&hdr);
2963cbe82603SBenny Halevy }
2964cbe82603SBenny Halevy 
2965cbe82603SBenny Halevy /*
2966cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
2967cbe82603SBenny Halevy  */
2968cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2969cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
2970cbe82603SBenny Halevy 				      struct nfs4_layoutreturn_args *args)
2971cbe82603SBenny Halevy {
2972cbe82603SBenny Halevy 	struct compound_hdr hdr = {
2973cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2974cbe82603SBenny Halevy 	};
2975cbe82603SBenny Halevy 
2976cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
2977cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
2978cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2979cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
2980cbe82603SBenny Halevy 	encode_nops(&hdr);
2981863a3c6cSAndy Adamson }
2982fca78d6dSBryan Schumaker 
2983fca78d6dSBryan Schumaker /*
2984fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
2985fca78d6dSBryan Schumaker  */
2986fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2987fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
2988fca78d6dSBryan Schumaker 					struct nfs41_secinfo_no_name_args *args)
2989fca78d6dSBryan Schumaker {
2990fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
2991fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2992fca78d6dSBryan Schumaker 	};
2993fca78d6dSBryan Schumaker 
2994fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
2995fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
2996fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
2997fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
2998fca78d6dSBryan Schumaker 	encode_nops(&hdr);
2999fca78d6dSBryan Schumaker 	return 0;
3000fca78d6dSBryan Schumaker }
30017d974794SBryan Schumaker 
30027d974794SBryan Schumaker /*
30037d974794SBryan Schumaker  *  Encode TEST_STATEID request
30047d974794SBryan Schumaker  */
30057d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
30067d974794SBryan Schumaker 				      struct xdr_stream *xdr,
30077d974794SBryan Schumaker 				      struct nfs41_test_stateid_args *args)
30087d974794SBryan Schumaker {
30097d974794SBryan Schumaker 	struct compound_hdr hdr = {
30107d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30117d974794SBryan Schumaker 	};
30127d974794SBryan Schumaker 
30137d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30147d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30157d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
30167d974794SBryan Schumaker 	encode_nops(&hdr);
30177d974794SBryan Schumaker }
30189aeda35fSBryan Schumaker 
30199aeda35fSBryan Schumaker /*
30209aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
30219aeda35fSBryan Schumaker  */
30229aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
30239aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
30249aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_args *args)
30259aeda35fSBryan Schumaker {
30269aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
30279aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30289aeda35fSBryan Schumaker 	};
30299aeda35fSBryan Schumaker 
30309aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30319aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30329aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
30339aeda35fSBryan Schumaker 	encode_nops(&hdr);
30349aeda35fSBryan Schumaker }
303599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
303699fe60d0SBenny Halevy 
3037686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3038686841b3SBenny Halevy {
3039686841b3SBenny Halevy 	dprintk("nfs: %s: prematurely hit end of receive buffer. "
3040686841b3SBenny Halevy 		"Remaining buffer length is %tu words.\n",
3041686841b3SBenny Halevy 		func, xdr->end - xdr->p);
3042686841b3SBenny Halevy }
30431da177e4SLinus Torvalds 
3044683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
30451da177e4SLinus Torvalds {
30466da59ce2STrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
30476da59ce2STrond Myklebust 			NFS4_OPAQUE_LIMIT);
30486da59ce2STrond Myklebust 	if (unlikely(ret < 0)) {
30496da59ce2STrond Myklebust 		if (ret == -EBADMSG)
3050c0eae66eSBenny Halevy 			print_overflow_msg(__func__, xdr);
3051c0eae66eSBenny Halevy 		return -EIO;
30521da177e4SLinus Torvalds 	}
30536da59ce2STrond Myklebust 	*len = ret;
30546da59ce2STrond Myklebust 	return 0;
30556da59ce2STrond Myklebust }
30561da177e4SLinus Torvalds 
30571da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
30581da177e4SLinus Torvalds {
30598687b63aSAl Viro 	__be32 *p;
30601da177e4SLinus Torvalds 
3061c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3062c0eae66eSBenny Halevy 	if (unlikely(!p))
3063c0eae66eSBenny Halevy 		goto out_overflow;
30646f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3065cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
30661da177e4SLinus Torvalds 
3067c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3068c0eae66eSBenny Halevy 	if (unlikely(!p))
3069c0eae66eSBenny Halevy 		goto out_overflow;
30701da177e4SLinus Torvalds 	hdr->tag = (char *)p;
30711da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3072cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3073aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3074aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
30751da177e4SLinus Torvalds 	return 0;
3076c0eae66eSBenny Halevy out_overflow:
3077c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3078c0eae66eSBenny Halevy 	return -EIO;
30791da177e4SLinus Torvalds }
30801da177e4SLinus Torvalds 
3081c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3082c7848f69STrond Myklebust 		int *nfs_retval)
30831da177e4SLinus Torvalds {
30848687b63aSAl Viro 	__be32 *p;
30851da177e4SLinus Torvalds 	uint32_t opnum;
30861da177e4SLinus Torvalds 	int32_t nfserr;
30871da177e4SLinus Torvalds 
3088c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3089c0eae66eSBenny Halevy 	if (unlikely(!p))
3090c0eae66eSBenny Halevy 		goto out_overflow;
30916f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
3092c7848f69STrond Myklebust 	if (unlikely(opnum != expected))
3093c7848f69STrond Myklebust 		goto out_bad_operation;
3094c7848f69STrond Myklebust 	nfserr = be32_to_cpup(p);
3095c7848f69STrond Myklebust 	if (nfserr == NFS_OK)
3096c7848f69STrond Myklebust 		*nfs_retval = 0;
3097c7848f69STrond Myklebust 	else
3098c7848f69STrond Myklebust 		*nfs_retval = nfs4_stat_to_errno(nfserr);
3099c7848f69STrond Myklebust 	return true;
3100c7848f69STrond Myklebust out_bad_operation:
3101fe82a183SChuck Lever 	dprintk("nfs: Server returned operation"
31021da177e4SLinus Torvalds 		" %d but we issued a request for %d\n",
31031da177e4SLinus Torvalds 			opnum, expected);
3104c7848f69STrond Myklebust 	*nfs_retval = -EREMOTEIO;
3105c7848f69STrond Myklebust 	return false;
3106c0eae66eSBenny Halevy out_overflow:
3107c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3108c7848f69STrond Myklebust 	*nfs_retval = -EIO;
3109c7848f69STrond Myklebust 	return false;
3110c7848f69STrond Myklebust }
3111c7848f69STrond Myklebust 
3112c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3113c7848f69STrond Myklebust {
3114c7848f69STrond Myklebust 	int retval;
3115c7848f69STrond Myklebust 
3116c7848f69STrond Myklebust 	__decode_op_hdr(xdr, expected, &retval);
3117c7848f69STrond Myklebust 	return retval;
31181da177e4SLinus Torvalds }
31191da177e4SLinus Torvalds 
31201da177e4SLinus Torvalds /* Dummy routine */
31211bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace)
31221da177e4SLinus Torvalds {
31238687b63aSAl Viro 	__be32 *p;
3124683b57b4STrond Myklebust 	unsigned int strlen;
31251da177e4SLinus Torvalds 	char *str;
31261da177e4SLinus Torvalds 
3127c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3128c0eae66eSBenny Halevy 	if (likely(p))
31291da177e4SLinus Torvalds 		return decode_opaque_inline(xdr, &strlen, &str);
3130c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3131c0eae66eSBenny Halevy 	return -EIO;
31321da177e4SLinus Torvalds }
31331da177e4SLinus Torvalds 
31341da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
31351da177e4SLinus Torvalds {
31368687b63aSAl Viro 	uint32_t bmlen;
31378687b63aSAl Viro 	__be32 *p;
31381da177e4SLinus Torvalds 
3139c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3140c0eae66eSBenny Halevy 	if (unlikely(!p))
3141c0eae66eSBenny Halevy 		goto out_overflow;
3142cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
31431da177e4SLinus Torvalds 
3144dae100c2SFred Isaman 	bitmap[0] = bitmap[1] = bitmap[2] = 0;
3145c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, (bmlen << 2));
3146c0eae66eSBenny Halevy 	if (unlikely(!p))
3147c0eae66eSBenny Halevy 		goto out_overflow;
31481da177e4SLinus Torvalds 	if (bmlen > 0) {
31496f723f77SBenny Halevy 		bitmap[0] = be32_to_cpup(p++);
3150dae100c2SFred Isaman 		if (bmlen > 1) {
3151dae100c2SFred Isaman 			bitmap[1] = be32_to_cpup(p++);
3152dae100c2SFred Isaman 			if (bmlen > 2)
3153dae100c2SFred Isaman 				bitmap[2] = be32_to_cpup(p);
3154dae100c2SFred Isaman 		}
31551da177e4SLinus Torvalds 	}
31561da177e4SLinus Torvalds 	return 0;
3157c0eae66eSBenny Halevy out_overflow:
3158c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3159c0eae66eSBenny Halevy 	return -EIO;
31601da177e4SLinus Torvalds }
31611da177e4SLinus Torvalds 
3162256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
31631da177e4SLinus Torvalds {
31648687b63aSAl Viro 	__be32 *p;
31651da177e4SLinus Torvalds 
3166c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3167c0eae66eSBenny Halevy 	if (unlikely(!p))
3168c0eae66eSBenny Halevy 		goto out_overflow;
3169cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
3170256e48bbSTrond Myklebust 	*savep = xdr_stream_pos(xdr);
31711da177e4SLinus Torvalds 	return 0;
3172c0eae66eSBenny Halevy out_overflow:
3173c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3174c0eae66eSBenny Halevy 	return -EIO;
31751da177e4SLinus Torvalds }
31761da177e4SLinus Torvalds 
31771da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
31781da177e4SLinus Torvalds {
31791da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
31803388bff5SRoman Borisov 		int ret;
31813388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
31823388bff5SRoman Borisov 		if (unlikely(ret < 0))
31833388bff5SRoman Borisov 			return ret;
31841da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
31851da177e4SLinus Torvalds 	} else
3186dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3187dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3188dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
31891da177e4SLinus Torvalds 	return 0;
31901da177e4SLinus Torvalds }
31911da177e4SLinus Torvalds 
31921da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
31931da177e4SLinus Torvalds {
31948687b63aSAl Viro 	__be32 *p;
3195409924e4STrond Myklebust 	int ret = 0;
31961da177e4SLinus Torvalds 
31971da177e4SLinus Torvalds 	*type = 0;
31981da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
31991da177e4SLinus Torvalds 		return -EIO;
32001da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3201c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3202c0eae66eSBenny Halevy 		if (unlikely(!p))
3203c0eae66eSBenny Halevy 			goto out_overflow;
3204cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
32051da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
32063110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
32071da177e4SLinus Torvalds 			return -EIO;
32081da177e4SLinus Torvalds 		}
32091da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3210409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32111da177e4SLinus Torvalds 	}
3212bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3213409924e4STrond Myklebust 	return ret;
3214c0eae66eSBenny Halevy out_overflow:
3215c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3216c0eae66eSBenny Halevy 	return -EIO;
32171da177e4SLinus Torvalds }
32181da177e4SLinus Torvalds 
3219264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3220264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3221264e6351SChuck Lever {
3222264e6351SChuck Lever 	__be32 *p;
3223264e6351SChuck Lever 
3224264e6351SChuck Lever 	*type = 0;
3225264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3226264e6351SChuck Lever 		return -EIO;
3227264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3228264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3229264e6351SChuck Lever 		if (unlikely(!p))
3230264e6351SChuck Lever 			goto out_overflow;
3231264e6351SChuck Lever 		*type = be32_to_cpup(p);
3232264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3233264e6351SChuck Lever 	}
3234264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3235264e6351SChuck Lever 	return 0;
3236264e6351SChuck Lever out_overflow:
3237264e6351SChuck Lever 	print_overflow_msg(__func__, xdr);
3238264e6351SChuck Lever 	return -EIO;
3239264e6351SChuck Lever }
3240264e6351SChuck Lever 
32411da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
32421da177e4SLinus Torvalds {
32438687b63aSAl Viro 	__be32 *p;
3244409924e4STrond Myklebust 	int ret = 0;
32451da177e4SLinus Torvalds 
32461da177e4SLinus Torvalds 	*change = 0;
32471da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
32481da177e4SLinus Torvalds 		return -EIO;
32491da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3250c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3251c0eae66eSBenny Halevy 		if (unlikely(!p))
3252c0eae66eSBenny Halevy 			goto out_overflow;
3253cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
32541da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3255409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
32561da177e4SLinus Torvalds 	}
32573110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
32581da177e4SLinus Torvalds 			(unsigned long long)*change);
3259409924e4STrond Myklebust 	return ret;
3260c0eae66eSBenny Halevy out_overflow:
3261c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3262c0eae66eSBenny Halevy 	return -EIO;
32631da177e4SLinus Torvalds }
32641da177e4SLinus Torvalds 
32651da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
32661da177e4SLinus Torvalds {
32678687b63aSAl Viro 	__be32 *p;
3268409924e4STrond Myklebust 	int ret = 0;
32691da177e4SLinus Torvalds 
32701da177e4SLinus Torvalds 	*size = 0;
32711da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
32721da177e4SLinus Torvalds 		return -EIO;
32731da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3274c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3275c0eae66eSBenny Halevy 		if (unlikely(!p))
3276c0eae66eSBenny Halevy 			goto out_overflow;
3277cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
32781da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3279409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
32801da177e4SLinus Torvalds 	}
32813110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3282409924e4STrond Myklebust 	return ret;
3283c0eae66eSBenny Halevy out_overflow:
3284c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3285c0eae66eSBenny Halevy 	return -EIO;
32861da177e4SLinus Torvalds }
32871da177e4SLinus Torvalds 
32881da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32891da177e4SLinus Torvalds {
32908687b63aSAl Viro 	__be32 *p;
32911da177e4SLinus Torvalds 
32921da177e4SLinus Torvalds 	*res = 0;
32931da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
32941da177e4SLinus Torvalds 		return -EIO;
32951da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3296c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3297c0eae66eSBenny Halevy 		if (unlikely(!p))
3298c0eae66eSBenny Halevy 			goto out_overflow;
3299cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33001da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
33011da177e4SLinus Torvalds 	}
33023110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
33031da177e4SLinus Torvalds 	return 0;
3304c0eae66eSBenny Halevy out_overflow:
3305c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3306c0eae66eSBenny Halevy 	return -EIO;
33071da177e4SLinus Torvalds }
33081da177e4SLinus Torvalds 
33091da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33101da177e4SLinus Torvalds {
33118687b63aSAl Viro 	__be32 *p;
33121da177e4SLinus Torvalds 
33131da177e4SLinus Torvalds 	*res = 0;
33141da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
33151da177e4SLinus Torvalds 		return -EIO;
33161da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3317c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3318c0eae66eSBenny Halevy 		if (unlikely(!p))
3319c0eae66eSBenny Halevy 			goto out_overflow;
3320cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33211da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
33221da177e4SLinus Torvalds 	}
33233110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
33241da177e4SLinus Torvalds 	return 0;
3325c0eae66eSBenny Halevy out_overflow:
3326c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3327c0eae66eSBenny Halevy 	return -EIO;
33281da177e4SLinus Torvalds }
33291da177e4SLinus Torvalds 
33308b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
33311da177e4SLinus Torvalds {
33328687b63aSAl Viro 	__be32 *p;
3333409924e4STrond Myklebust 	int ret = 0;
33341da177e4SLinus Torvalds 
33351da177e4SLinus Torvalds 	fsid->major = 0;
33361da177e4SLinus Torvalds 	fsid->minor = 0;
33371da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
33381da177e4SLinus Torvalds 		return -EIO;
33391da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3340c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3341c0eae66eSBenny Halevy 		if (unlikely(!p))
3342c0eae66eSBenny Halevy 			goto out_overflow;
33433ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3344cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
33451da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3346409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
33471da177e4SLinus Torvalds 	}
33483110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
33491da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
33501da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3351409924e4STrond Myklebust 	return ret;
3352c0eae66eSBenny Halevy out_overflow:
3353c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3354c0eae66eSBenny Halevy 	return -EIO;
33551da177e4SLinus Torvalds }
33561da177e4SLinus Torvalds 
33571da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33581da177e4SLinus Torvalds {
33598687b63aSAl Viro 	__be32 *p;
33601da177e4SLinus Torvalds 
33611da177e4SLinus Torvalds 	*res = 60;
33621da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
33631da177e4SLinus Torvalds 		return -EIO;
33641da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3365c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3366c0eae66eSBenny Halevy 		if (unlikely(!p))
3367c0eae66eSBenny Halevy 			goto out_overflow;
3368cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33691da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
33701da177e4SLinus Torvalds 	}
33713110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
33721da177e4SLinus Torvalds 	return 0;
3373c0eae66eSBenny Halevy out_overflow:
3374c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3375c0eae66eSBenny Halevy 	return -EIO;
33761da177e4SLinus Torvalds }
33771da177e4SLinus Torvalds 
3378ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3379ae42c70aSBryan Schumaker {
3380ae42c70aSBryan Schumaker 	__be32 *p;
3381ae42c70aSBryan Schumaker 
3382ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3383ae42c70aSBryan Schumaker 		return -EIO;
3384ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3385ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3386ae42c70aSBryan Schumaker 		if (unlikely(!p))
3387ae42c70aSBryan Schumaker 			goto out_overflow;
3388ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3389ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3390ae42c70aSBryan Schumaker 	}
3391ae42c70aSBryan Schumaker 	return 0;
3392ae42c70aSBryan Schumaker out_overflow:
3393ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3394ae42c70aSBryan Schumaker 	return -EIO;
3395ae42c70aSBryan Schumaker }
3396ae42c70aSBryan Schumaker 
33978c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
33988c61282fSKinglong Mee 				 uint32_t *bitmap, uint32_t *bitmask)
33998c61282fSKinglong Mee {
34008c61282fSKinglong Mee 	if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
34018c61282fSKinglong Mee 		int ret;
34028c61282fSKinglong Mee 		ret = decode_attr_bitmap(xdr, bitmask);
34038c61282fSKinglong Mee 		if (unlikely(ret < 0))
34048c61282fSKinglong Mee 			return ret;
34058c61282fSKinglong Mee 		bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
34068c61282fSKinglong Mee 	} else
34078c61282fSKinglong Mee 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
34088c61282fSKinglong Mee 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
34098c61282fSKinglong Mee 		bitmask[0], bitmask[1], bitmask[2]);
34108c61282fSKinglong Mee 	return 0;
34118c61282fSKinglong Mee }
34128c61282fSKinglong Mee 
3413ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3414ae42c70aSBryan Schumaker {
3415ae42c70aSBryan Schumaker 	__be32 *p;
3416ae42c70aSBryan Schumaker 	int len;
3417ae42c70aSBryan Schumaker 
34187ad07353STrond Myklebust 	if (fh != NULL)
3419ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3420ae42c70aSBryan Schumaker 
3421ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3422ae42c70aSBryan Schumaker 		return -EIO;
3423ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3424ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3425ae42c70aSBryan Schumaker 		if (unlikely(!p))
3426ae42c70aSBryan Schumaker 			goto out_overflow;
3427ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3428ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3429ae42c70aSBryan Schumaker 			return -EIO;
3430ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3431ae42c70aSBryan Schumaker 		if (unlikely(!p))
3432ae42c70aSBryan Schumaker 			goto out_overflow;
34337ad07353STrond Myklebust 		if (fh != NULL) {
3434ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
34357ad07353STrond Myklebust 			fh->size = len;
34367ad07353STrond Myklebust 		}
3437ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3438ae42c70aSBryan Schumaker 	}
3439ae42c70aSBryan Schumaker 	return 0;
3440ae42c70aSBryan Schumaker out_overflow:
3441ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3442ae42c70aSBryan Schumaker 	return -EIO;
3443ae42c70aSBryan Schumaker }
3444ae42c70aSBryan Schumaker 
34451da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34461da177e4SLinus Torvalds {
34478687b63aSAl Viro 	__be32 *p;
34481da177e4SLinus Torvalds 
3449a1800acaSMalahal Naineni 	*res = 0;
34501da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
34511da177e4SLinus Torvalds 		return -EIO;
34521da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3453c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3454c0eae66eSBenny Halevy 		if (unlikely(!p))
3455c0eae66eSBenny Halevy 			goto out_overflow;
3456cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34571da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
34581da177e4SLinus Torvalds 	}
34593110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
34601da177e4SLinus Torvalds 	return 0;
3461c0eae66eSBenny Halevy out_overflow:
3462c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3463c0eae66eSBenny Halevy 	return -EIO;
34641da177e4SLinus Torvalds }
34651da177e4SLinus Torvalds 
34661da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
34671da177e4SLinus Torvalds {
34688687b63aSAl Viro 	__be32 *p;
3469409924e4STrond Myklebust 	int ret = 0;
34701da177e4SLinus Torvalds 
34711da177e4SLinus Torvalds 	*fileid = 0;
34721da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
34731da177e4SLinus Torvalds 		return -EIO;
34741da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3475c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3476c0eae66eSBenny Halevy 		if (unlikely(!p))
3477c0eae66eSBenny Halevy 			goto out_overflow;
3478cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
34791da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3480409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
34811da177e4SLinus Torvalds 	}
34823110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3483409924e4STrond Myklebust 	return ret;
3484c0eae66eSBenny Halevy out_overflow:
3485c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3486c0eae66eSBenny Halevy 	return -EIO;
34871da177e4SLinus Torvalds }
34881da177e4SLinus Torvalds 
348999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
349099baf625SManoj Naik {
34918687b63aSAl Viro 	__be32 *p;
3492409924e4STrond Myklebust 	int ret = 0;
349399baf625SManoj Naik 
349499baf625SManoj Naik 	*fileid = 0;
349599baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
349699baf625SManoj Naik 		return -EIO;
349799baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3498c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3499c0eae66eSBenny Halevy 		if (unlikely(!p))
3500c0eae66eSBenny Halevy 			goto out_overflow;
3501cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
350299baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
350328331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
350499baf625SManoj Naik 	}
35053110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3506409924e4STrond Myklebust 	return ret;
3507c0eae66eSBenny Halevy out_overflow:
3508c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3509c0eae66eSBenny Halevy 	return -EIO;
351099baf625SManoj Naik }
351199baf625SManoj Naik 
35121da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35131da177e4SLinus Torvalds {
35148687b63aSAl Viro 	__be32 *p;
35151da177e4SLinus Torvalds 	int status = 0;
35161da177e4SLinus Torvalds 
35171da177e4SLinus Torvalds 	*res = 0;
35181da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
35191da177e4SLinus Torvalds 		return -EIO;
35201da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3521c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3522c0eae66eSBenny Halevy 		if (unlikely(!p))
3523c0eae66eSBenny Halevy 			goto out_overflow;
3524cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35251da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
35261da177e4SLinus Torvalds 	}
35273110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
35281da177e4SLinus Torvalds 	return status;
3529c0eae66eSBenny Halevy out_overflow:
3530c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3531c0eae66eSBenny Halevy 	return -EIO;
35321da177e4SLinus Torvalds }
35331da177e4SLinus Torvalds 
35341da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35351da177e4SLinus Torvalds {
35368687b63aSAl Viro 	__be32 *p;
35371da177e4SLinus Torvalds 	int status = 0;
35381da177e4SLinus Torvalds 
35391da177e4SLinus Torvalds 	*res = 0;
35401da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
35411da177e4SLinus Torvalds 		return -EIO;
35421da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3543c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3544c0eae66eSBenny Halevy 		if (unlikely(!p))
3545c0eae66eSBenny Halevy 			goto out_overflow;
3546cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35471da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
35481da177e4SLinus Torvalds 	}
35493110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
35501da177e4SLinus Torvalds 	return status;
3551c0eae66eSBenny Halevy out_overflow:
3552c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3553c0eae66eSBenny Halevy 	return -EIO;
35541da177e4SLinus Torvalds }
35551da177e4SLinus Torvalds 
35561da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35571da177e4SLinus Torvalds {
35588687b63aSAl Viro 	__be32 *p;
35591da177e4SLinus Torvalds 	int status = 0;
35601da177e4SLinus Torvalds 
35611da177e4SLinus Torvalds 	*res = 0;
35621da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
35631da177e4SLinus Torvalds 		return -EIO;
35641da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3565c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3566c0eae66eSBenny Halevy 		if (unlikely(!p))
3567c0eae66eSBenny Halevy 			goto out_overflow;
3568cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35691da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
35701da177e4SLinus Torvalds 	}
35713110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
35721da177e4SLinus Torvalds 	return status;
3573c0eae66eSBenny Halevy out_overflow:
3574c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3575c0eae66eSBenny Halevy 	return -EIO;
35761da177e4SLinus Torvalds }
35771da177e4SLinus Torvalds 
35787aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
35797aaa0b3bSManoj Naik {
3580464ad6b1SChuck Lever 	u32 n;
35818687b63aSAl Viro 	__be32 *p;
35827aaa0b3bSManoj Naik 	int status = 0;
35837aaa0b3bSManoj Naik 
3584c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3585c0eae66eSBenny Halevy 	if (unlikely(!p))
3586c0eae66eSBenny Halevy 		goto out_overflow;
3587cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
358833a43f28SAndy Adamson 	if (n == 0)
358933a43f28SAndy Adamson 		goto root_path;
359002a2976cSChuck Lever 	dprintk("pathname4: ");
3591809b426cSTrond Myklebust 	if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3592809b426cSTrond Myklebust 		dprintk("cannot parse %d components in path\n", n);
3593809b426cSTrond Myklebust 		goto out_eio;
3594809b426cSTrond Myklebust 	}
3595809b426cSTrond Myklebust 	for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
35967aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
35977aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
35987aaa0b3bSManoj Naik 		if (unlikely(status != 0))
35997aaa0b3bSManoj Naik 			goto out_eio;
360095a13f7bSTrond Myklebust 		ifdebug (XDR)
360102a2976cSChuck Lever 			pr_cont("%s%.*s ",
360202a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
360302a2976cSChuck Lever 				component->len, component->data);
36047aaa0b3bSManoj Naik 	}
36057aaa0b3bSManoj Naik out:
36067aaa0b3bSManoj Naik 	return status;
360733a43f28SAndy Adamson root_path:
360833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
360933a43f28SAndy Adamson 	path->ncomponents = 1;
361033a43f28SAndy Adamson 	path->components[0].len=0;
361133a43f28SAndy Adamson 	path->components[0].data=NULL;
361202a2976cSChuck Lever 	dprintk("pathname4: /\n");
361333a43f28SAndy Adamson 	goto out;
36147aaa0b3bSManoj Naik out_eio:
36157aaa0b3bSManoj Naik 	dprintk(" status %d", status);
36167aaa0b3bSManoj Naik 	status = -EIO;
36177aaa0b3bSManoj Naik 	goto out;
3618c0eae66eSBenny Halevy out_overflow:
3619c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3620c0eae66eSBenny Halevy 	return -EIO;
36217aaa0b3bSManoj Naik }
36227aaa0b3bSManoj Naik 
36237aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3624683b57b4STrond Myklebust {
3625683b57b4STrond Myklebust 	int n;
36268687b63aSAl Viro 	__be32 *p;
3627683b57b4STrond Myklebust 	int status = -EIO;
3628683b57b4STrond Myklebust 
3629683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3630683b57b4STrond Myklebust 		goto out;
3631683b57b4STrond Myklebust 	status = 0;
3632683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3633683b57b4STrond Myklebust 		goto out;
3634f54423a1SKinglong Mee 	bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
36358b7e3f49STrond Myklebust 	status = -EIO;
36368b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
36378b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
36388b7e3f49STrond Myklebust 		goto out;
363902a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
36407aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3641683b57b4STrond Myklebust 	if (unlikely(status != 0))
3642683b57b4STrond Myklebust 		goto out;
3643c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3644c0eae66eSBenny Halevy 	if (unlikely(!p))
3645c0eae66eSBenny Halevy 		goto out_overflow;
3646cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3647683b57b4STrond Myklebust 	if (n <= 0)
3648683b57b4STrond Myklebust 		goto out_eio;
3649809b426cSTrond Myklebust 	for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3650464ad6b1SChuck Lever 		u32 m;
3651809b426cSTrond Myklebust 		struct nfs4_fs_location *loc;
3652683b57b4STrond Myklebust 
3653809b426cSTrond Myklebust 		if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3654809b426cSTrond Myklebust 			break;
3655809b426cSTrond Myklebust 		loc = &res->locations[res->nlocations];
3656c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3657c0eae66eSBenny Halevy 		if (unlikely(!p))
3658c0eae66eSBenny Halevy 			goto out_overflow;
3659cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
36607aaa0b3bSManoj Naik 
366102a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
3662809b426cSTrond Myklebust 		for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3663809b426cSTrond Myklebust 			struct nfs4_string *server;
3664809b426cSTrond Myklebust 
3665809b426cSTrond Myklebust 			if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3666464ad6b1SChuck Lever 				unsigned int i;
3667464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3668464ad6b1SChuck Lever 					"returned for location %u\n",
36693110ff80SHarvey Harrison 						__func__,
3670464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3671464ad6b1SChuck Lever 						m, res->nlocations);
36727aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
36732e42c3e2STrond Myklebust 					unsigned int len;
36747aaa0b3bSManoj Naik 					char *data;
36757aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3676683b57b4STrond Myklebust 					if (unlikely(status != 0))
3677683b57b4STrond Myklebust 						goto out_eio;
36787aaa0b3bSManoj Naik 				}
3679809b426cSTrond Myklebust 				break;
36807aaa0b3bSManoj Naik 			}
3681809b426cSTrond Myklebust 			server = &loc->servers[loc->nservers];
3682809b426cSTrond Myklebust 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3683809b426cSTrond Myklebust 			if (unlikely(status != 0))
3684809b426cSTrond Myklebust 				goto out_eio;
3685809b426cSTrond Myklebust 			dprintk("%s ", server->data);
36867aaa0b3bSManoj Naik 		}
36877aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
36887aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36897aaa0b3bSManoj Naik 			goto out_eio;
3690683b57b4STrond Myklebust 	}
3691409924e4STrond Myklebust 	if (res->nlocations != 0)
369281934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3693683b57b4STrond Myklebust out:
36943110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3695683b57b4STrond Myklebust 	return status;
3696c0eae66eSBenny Halevy out_overflow:
3697c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3698683b57b4STrond Myklebust out_eio:
3699683b57b4STrond Myklebust 	status = -EIO;
3700683b57b4STrond Myklebust 	goto out;
3701683b57b4STrond Myklebust }
3702683b57b4STrond Myklebust 
37031da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
37041da177e4SLinus Torvalds {
37058687b63aSAl Viro 	__be32 *p;
37061da177e4SLinus Torvalds 	int status = 0;
37071da177e4SLinus Torvalds 
37081da177e4SLinus Torvalds 	*res = 0;
37091da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
37101da177e4SLinus Torvalds 		return -EIO;
37111da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3712c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3713c0eae66eSBenny Halevy 		if (unlikely(!p))
3714c0eae66eSBenny Halevy 			goto out_overflow;
3715cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
37161da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
37171da177e4SLinus Torvalds 	}
37183110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
37191da177e4SLinus Torvalds 	return status;
3720c0eae66eSBenny Halevy out_overflow:
3721c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3722c0eae66eSBenny Halevy 	return -EIO;
37231da177e4SLinus Torvalds }
37241da177e4SLinus Torvalds 
37251da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
37261da177e4SLinus Torvalds {
37278687b63aSAl Viro 	__be32 *p;
37281da177e4SLinus Torvalds 	int status = 0;
37291da177e4SLinus Torvalds 
37301da177e4SLinus Torvalds 	*maxlink = 1;
37311da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
37321da177e4SLinus Torvalds 		return -EIO;
37331da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3734c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3735c0eae66eSBenny Halevy 		if (unlikely(!p))
3736c0eae66eSBenny Halevy 			goto out_overflow;
3737cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
37381da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
37391da177e4SLinus Torvalds 	}
37403110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
37411da177e4SLinus Torvalds 	return status;
3742c0eae66eSBenny Halevy out_overflow:
3743c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3744c0eae66eSBenny Halevy 	return -EIO;
37451da177e4SLinus Torvalds }
37461da177e4SLinus Torvalds 
37471da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
37481da177e4SLinus Torvalds {
37498687b63aSAl Viro 	__be32 *p;
37501da177e4SLinus Torvalds 	int status = 0;
37511da177e4SLinus Torvalds 
37521da177e4SLinus Torvalds 	*maxname = 1024;
37531da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
37541da177e4SLinus Torvalds 		return -EIO;
37551da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3756c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3757c0eae66eSBenny Halevy 		if (unlikely(!p))
3758c0eae66eSBenny Halevy 			goto out_overflow;
3759cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
37601da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
37611da177e4SLinus Torvalds 	}
37623110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
37631da177e4SLinus Torvalds 	return status;
3764c0eae66eSBenny Halevy out_overflow:
3765c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3766c0eae66eSBenny Halevy 	return -EIO;
37671da177e4SLinus Torvalds }
37681da177e4SLinus Torvalds 
37691da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37701da177e4SLinus Torvalds {
37718687b63aSAl Viro 	__be32 *p;
37721da177e4SLinus Torvalds 	int status = 0;
37731da177e4SLinus Torvalds 
37741da177e4SLinus Torvalds 	*res = 1024;
37751da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
37761da177e4SLinus Torvalds 		return -EIO;
37771da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
37781da177e4SLinus Torvalds 		uint64_t maxread;
3779c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3780c0eae66eSBenny Halevy 		if (unlikely(!p))
3781c0eae66eSBenny Halevy 			goto out_overflow;
3782cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
37831da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
37841da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
37851da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
37861da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
37871da177e4SLinus Torvalds 	}
37883110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
37891da177e4SLinus Torvalds 	return status;
3790c0eae66eSBenny Halevy out_overflow:
3791c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3792c0eae66eSBenny Halevy 	return -EIO;
37931da177e4SLinus Torvalds }
37941da177e4SLinus Torvalds 
37951da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37961da177e4SLinus Torvalds {
37978687b63aSAl Viro 	__be32 *p;
37981da177e4SLinus Torvalds 	int status = 0;
37991da177e4SLinus Torvalds 
38001da177e4SLinus Torvalds 	*res = 1024;
38011da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
38021da177e4SLinus Torvalds 		return -EIO;
38031da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
38041da177e4SLinus Torvalds 		uint64_t maxwrite;
3805c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3806c0eae66eSBenny Halevy 		if (unlikely(!p))
3807c0eae66eSBenny Halevy 			goto out_overflow;
3808cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
38091da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
38101da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
38111da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
38121da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
38131da177e4SLinus Torvalds 	}
38143110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
38151da177e4SLinus Torvalds 	return status;
3816c0eae66eSBenny Halevy out_overflow:
3817c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3818c0eae66eSBenny Halevy 	return -EIO;
38191da177e4SLinus Torvalds }
38201da177e4SLinus Torvalds 
3821bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
38221da177e4SLinus Torvalds {
3823bca79478STrond Myklebust 	uint32_t tmp;
38248687b63aSAl Viro 	__be32 *p;
3825409924e4STrond Myklebust 	int ret = 0;
38261da177e4SLinus Torvalds 
38271da177e4SLinus Torvalds 	*mode = 0;
38281da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38291da177e4SLinus Torvalds 		return -EIO;
38301da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3831c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3832c0eae66eSBenny Halevy 		if (unlikely(!p))
3833c0eae66eSBenny Halevy 			goto out_overflow;
3834cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3835bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
38361da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3837409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
38381da177e4SLinus Torvalds 	}
38393110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3840409924e4STrond Myklebust 	return ret;
3841c0eae66eSBenny Halevy out_overflow:
3842c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3843c0eae66eSBenny Halevy 	return -EIO;
38441da177e4SLinus Torvalds }
38451da177e4SLinus Torvalds 
38461da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
38471da177e4SLinus Torvalds {
38488687b63aSAl Viro 	__be32 *p;
3849409924e4STrond Myklebust 	int ret = 0;
38501da177e4SLinus Torvalds 
38511da177e4SLinus Torvalds 	*nlink = 1;
38521da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
38531da177e4SLinus Torvalds 		return -EIO;
38541da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3855c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3856c0eae66eSBenny Halevy 		if (unlikely(!p))
3857c0eae66eSBenny Halevy 			goto out_overflow;
3858cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
38591da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3860409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
38611da177e4SLinus Torvalds 	}
38623110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3863409924e4STrond Myklebust 	return ret;
3864c0eae66eSBenny Halevy out_overflow:
3865c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3866c0eae66eSBenny Halevy 	return -EIO;
38671da177e4SLinus Torvalds }
38681da177e4SLinus Torvalds 
3869686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3870686a816aSTrond Myklebust 		struct nfs4_string *name, gfp_t gfp_flags)
3871686a816aSTrond Myklebust {
3872686a816aSTrond Myklebust 	ssize_t ret;
3873686a816aSTrond Myklebust 
3874686a816aSTrond Myklebust 	ret = xdr_stream_decode_string_dup(xdr, &name->data,
3875686a816aSTrond Myklebust 			XDR_MAX_NETOBJ, gfp_flags);
3876686a816aSTrond Myklebust 	name->len = 0;
3877686a816aSTrond Myklebust 	if (ret > 0)
3878686a816aSTrond Myklebust 		name->len = ret;
3879686a816aSTrond Myklebust 	return ret;
3880686a816aSTrond Myklebust }
3881686a816aSTrond Myklebust 
388280e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3883e5782076SEric W. Biederman 		const struct nfs_server *server, kuid_t *uid,
38846926afd1STrond Myklebust 		struct nfs4_string *owner_name)
38851da177e4SLinus Torvalds {
3886686a816aSTrond Myklebust 	ssize_t len;
3887686a816aSTrond Myklebust 	char *p;
38881da177e4SLinus Torvalds 
3889e5782076SEric W. Biederman 	*uid = make_kuid(&init_user_ns, -2);
38901da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
38911da177e4SLinus Torvalds 		return -EIO;
3892686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3893686a816aSTrond Myklebust 		return 0;
38941da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER;
3895686a816aSTrond Myklebust 
3896686a816aSTrond Myklebust 	if (owner_name != NULL) {
3897686a816aSTrond Myklebust 		len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT);
3898686a816aSTrond Myklebust 		if (len <= 0)
3899686a816aSTrond Myklebust 			goto out;
3900686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, owner_name->data);
3901686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER_NAME;
3902686a816aSTrond Myklebust 	} else {
3903686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3904686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
3905686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3906686a816aSTrond Myklebust 			goto out;
3907e5782076SEric W. Biederman 		dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3908686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER;
3909686a816aSTrond Myklebust 	}
3910686a816aSTrond Myklebust out:
3911686a816aSTrond Myklebust 	if (len != -EBADMSG)
3912686a816aSTrond Myklebust 		return 0;
3913c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3914c0eae66eSBenny Halevy 	return -EIO;
39151da177e4SLinus Torvalds }
39161da177e4SLinus Torvalds 
391780e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3918e5782076SEric W. Biederman 		const struct nfs_server *server, kgid_t *gid,
39196926afd1STrond Myklebust 		struct nfs4_string *group_name)
39201da177e4SLinus Torvalds {
3921686a816aSTrond Myklebust 	ssize_t len;
3922686a816aSTrond Myklebust 	char *p;
39231da177e4SLinus Torvalds 
3924e5782076SEric W. Biederman 	*gid = make_kgid(&init_user_ns, -2);
39251da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
39261da177e4SLinus Torvalds 		return -EIO;
3927686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3928686a816aSTrond Myklebust 		return 0;
39291da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3930686a816aSTrond Myklebust 
3931686a816aSTrond Myklebust 	if (group_name != NULL) {
3932686a816aSTrond Myklebust 		len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT);
3933686a816aSTrond Myklebust 		if (len <= 0)
3934686a816aSTrond Myklebust 			goto out;
3935686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, group_name->data);
39366f1f6220SKinglong Mee 		return NFS_ATTR_FATTR_GROUP_NAME;
3937686a816aSTrond Myklebust 	} else {
3938686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3939686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
3940686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3941686a816aSTrond Myklebust 			goto out;
3942e5782076SEric W. Biederman 		dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3943686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_GROUP;
3944686a816aSTrond Myklebust 	}
3945686a816aSTrond Myklebust out:
3946686a816aSTrond Myklebust 	if (len != -EBADMSG)
3947686a816aSTrond Myklebust 		return 0;
3948c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3949c0eae66eSBenny Halevy 	return -EIO;
39501da177e4SLinus Torvalds }
39511da177e4SLinus Torvalds 
39521da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
39531da177e4SLinus Torvalds {
39548687b63aSAl Viro 	uint32_t major = 0, minor = 0;
39558687b63aSAl Viro 	__be32 *p;
3956409924e4STrond Myklebust 	int ret = 0;
39571da177e4SLinus Torvalds 
39581da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
39591da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
39601da177e4SLinus Torvalds 		return -EIO;
39611da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
39621da177e4SLinus Torvalds 		dev_t tmp;
39631da177e4SLinus Torvalds 
3964c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3965c0eae66eSBenny Halevy 		if (unlikely(!p))
3966c0eae66eSBenny Halevy 			goto out_overflow;
39676f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3968cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
39691da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
39701da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
39711da177e4SLinus Torvalds 			*rdev = tmp;
39721da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3973409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
39741da177e4SLinus Torvalds 	}
39753110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3976409924e4STrond Myklebust 	return ret;
3977c0eae66eSBenny Halevy out_overflow:
3978c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3979c0eae66eSBenny Halevy 	return -EIO;
39801da177e4SLinus Torvalds }
39811da177e4SLinus Torvalds 
39821da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39831da177e4SLinus Torvalds {
39848687b63aSAl Viro 	__be32 *p;
39851da177e4SLinus Torvalds 	int status = 0;
39861da177e4SLinus Torvalds 
39871da177e4SLinus Torvalds 	*res = 0;
39881da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
39891da177e4SLinus Torvalds 		return -EIO;
39901da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3991c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3992c0eae66eSBenny Halevy 		if (unlikely(!p))
3993c0eae66eSBenny Halevy 			goto out_overflow;
3994cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39951da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
39961da177e4SLinus Torvalds 	}
39973110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
39981da177e4SLinus Torvalds 	return status;
3999c0eae66eSBenny Halevy out_overflow:
4000c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4001c0eae66eSBenny Halevy 	return -EIO;
40021da177e4SLinus Torvalds }
40031da177e4SLinus Torvalds 
40041da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40051da177e4SLinus Torvalds {
40068687b63aSAl Viro 	__be32 *p;
40071da177e4SLinus Torvalds 	int status = 0;
40081da177e4SLinus Torvalds 
40091da177e4SLinus Torvalds 	*res = 0;
40101da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40111da177e4SLinus Torvalds 		return -EIO;
40121da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4013c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4014c0eae66eSBenny Halevy 		if (unlikely(!p))
4015c0eae66eSBenny Halevy 			goto out_overflow;
4016cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40171da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40181da177e4SLinus Torvalds 	}
40193110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40201da177e4SLinus Torvalds 	return status;
4021c0eae66eSBenny Halevy out_overflow:
4022c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4023c0eae66eSBenny Halevy 	return -EIO;
40241da177e4SLinus Torvalds }
40251da177e4SLinus Torvalds 
40261da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40271da177e4SLinus Torvalds {
40288687b63aSAl Viro 	__be32 *p;
40291da177e4SLinus Torvalds 	int status = 0;
40301da177e4SLinus Torvalds 
40311da177e4SLinus Torvalds 	*res = 0;
40321da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
40331da177e4SLinus Torvalds 		return -EIO;
40341da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4035c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4036c0eae66eSBenny Halevy 		if (unlikely(!p))
4037c0eae66eSBenny Halevy 			goto out_overflow;
4038cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40391da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
40401da177e4SLinus Torvalds 	}
40413110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
40421da177e4SLinus Torvalds 	return status;
4043c0eae66eSBenny Halevy out_overflow:
4044c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4045c0eae66eSBenny Halevy 	return -EIO;
40461da177e4SLinus Torvalds }
40471da177e4SLinus Torvalds 
40481da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
40491da177e4SLinus Torvalds {
40508687b63aSAl Viro 	__be32 *p;
4051409924e4STrond Myklebust 	int ret = 0;
40521da177e4SLinus Torvalds 
40531da177e4SLinus Torvalds 	*used = 0;
40541da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
40551da177e4SLinus Torvalds 		return -EIO;
40561da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4057c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4058c0eae66eSBenny Halevy 		if (unlikely(!p))
4059c0eae66eSBenny Halevy 			goto out_overflow;
4060cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
40611da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4062409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
40631da177e4SLinus Torvalds 	}
40643110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
40651da177e4SLinus Torvalds 			(unsigned long long)*used);
4066409924e4STrond Myklebust 	return ret;
4067c0eae66eSBenny Halevy out_overflow:
4068c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4069c0eae66eSBenny Halevy 	return -EIO;
40701da177e4SLinus Torvalds }
40711da177e4SLinus Torvalds 
40721da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
40731da177e4SLinus Torvalds {
40748687b63aSAl Viro 	__be32 *p;
40751da177e4SLinus Torvalds 	uint64_t sec;
40761da177e4SLinus Torvalds 	uint32_t nsec;
40771da177e4SLinus Torvalds 
4078c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4079c0eae66eSBenny Halevy 	if (unlikely(!p))
4080c0eae66eSBenny Halevy 		goto out_overflow;
40813ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &sec);
4082cccddf4fSBenny Halevy 	nsec = be32_to_cpup(p);
40831da177e4SLinus Torvalds 	time->tv_sec = (time_t)sec;
40841da177e4SLinus Torvalds 	time->tv_nsec = (long)nsec;
40851da177e4SLinus Torvalds 	return 0;
4086c0eae66eSBenny Halevy out_overflow:
4087c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4088c0eae66eSBenny Halevy 	return -EIO;
40891da177e4SLinus Torvalds }
40901da177e4SLinus Torvalds 
40911da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40921da177e4SLinus Torvalds {
40931da177e4SLinus Torvalds 	int status = 0;
40941da177e4SLinus Torvalds 
40951da177e4SLinus Torvalds 	time->tv_sec = 0;
40961da177e4SLinus Torvalds 	time->tv_nsec = 0;
40971da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
40981da177e4SLinus Torvalds 		return -EIO;
40991da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
41001da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4101409924e4STrond Myklebust 		if (status == 0)
4102409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
41031da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
41041da177e4SLinus Torvalds 	}
41053110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
41061da177e4SLinus Torvalds 	return status;
41071da177e4SLinus Torvalds }
41081da177e4SLinus Torvalds 
41091da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41101da177e4SLinus Torvalds {
41111da177e4SLinus Torvalds 	int status = 0;
41121da177e4SLinus Torvalds 
41131da177e4SLinus Torvalds 	time->tv_sec = 0;
41141da177e4SLinus Torvalds 	time->tv_nsec = 0;
41151da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41161da177e4SLinus Torvalds 		return -EIO;
41171da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41181da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4119409924e4STrond Myklebust 		if (status == 0)
4120409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
41211da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41221da177e4SLinus Torvalds 	}
41233110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
41241da177e4SLinus Torvalds 	return status;
41251da177e4SLinus Torvalds }
41261da177e4SLinus Torvalds 
412755b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
412855b6e774SRicardo Labiaga 				  struct timespec *time)
412955b6e774SRicardo Labiaga {
413055b6e774SRicardo Labiaga 	int status = 0;
413155b6e774SRicardo Labiaga 
413255b6e774SRicardo Labiaga 	time->tv_sec = 0;
413355b6e774SRicardo Labiaga 	time->tv_nsec = 0;
413455b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
413555b6e774SRicardo Labiaga 		return -EIO;
413655b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
413755b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
413855b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
413955b6e774SRicardo Labiaga 	}
414055b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
414155b6e774SRicardo Labiaga 		(long)time->tv_nsec);
414255b6e774SRicardo Labiaga 	return status;
414355b6e774SRicardo Labiaga }
414455b6e774SRicardo Labiaga 
4145aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4146aa9c2669SDavid Quigley 					struct nfs4_label *label)
4147aa9c2669SDavid Quigley {
4148aa9c2669SDavid Quigley 	uint32_t pi = 0;
4149aa9c2669SDavid Quigley 	uint32_t lfs = 0;
4150aa9c2669SDavid Quigley 	__u32 len;
4151aa9c2669SDavid Quigley 	__be32 *p;
4152aa9c2669SDavid Quigley 	int status = 0;
4153aa9c2669SDavid Quigley 
4154aa9c2669SDavid Quigley 	if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4155aa9c2669SDavid Quigley 		return -EIO;
4156aa9c2669SDavid Quigley 	if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4157aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4158aa9c2669SDavid Quigley 		if (unlikely(!p))
4159aa9c2669SDavid Quigley 			goto out_overflow;
4160aa9c2669SDavid Quigley 		lfs = be32_to_cpup(p++);
4161aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4162aa9c2669SDavid Quigley 		if (unlikely(!p))
4163aa9c2669SDavid Quigley 			goto out_overflow;
4164aa9c2669SDavid Quigley 		pi = be32_to_cpup(p++);
4165aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4166aa9c2669SDavid Quigley 		if (unlikely(!p))
4167aa9c2669SDavid Quigley 			goto out_overflow;
4168aa9c2669SDavid Quigley 		len = be32_to_cpup(p++);
4169aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, len);
4170aa9c2669SDavid Quigley 		if (unlikely(!p))
4171aa9c2669SDavid Quigley 			goto out_overflow;
4172aa9c2669SDavid Quigley 		if (len < NFS4_MAXLABELLEN) {
4173aa9c2669SDavid Quigley 			if (label) {
4174aa9c2669SDavid Quigley 				memcpy(label->label, p, len);
4175aa9c2669SDavid Quigley 				label->len = len;
4176aa9c2669SDavid Quigley 				label->pi = pi;
4177aa9c2669SDavid Quigley 				label->lfs = lfs;
4178aa9c2669SDavid Quigley 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4179aa9c2669SDavid Quigley 			}
4180aa9c2669SDavid Quigley 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4181aa9c2669SDavid Quigley 		} else
4182aa9c2669SDavid Quigley 			printk(KERN_WARNING "%s: label too long (%u)!\n",
4183aa9c2669SDavid Quigley 					__func__, len);
4184aa9c2669SDavid Quigley 	}
4185aa9c2669SDavid Quigley 	if (label && label->label)
4186aa9c2669SDavid Quigley 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4187aa9c2669SDavid Quigley 			(char *)label->label, label->len, label->pi, label->lfs);
4188aa9c2669SDavid Quigley 	return status;
4189aa9c2669SDavid Quigley 
4190aa9c2669SDavid Quigley out_overflow:
4191aa9c2669SDavid Quigley 	print_overflow_msg(__func__, xdr);
4192aa9c2669SDavid Quigley 	return -EIO;
4193aa9c2669SDavid Quigley }
4194aa9c2669SDavid Quigley 
41951da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41961da177e4SLinus Torvalds {
41971da177e4SLinus Torvalds 	int status = 0;
41981da177e4SLinus Torvalds 
41991da177e4SLinus Torvalds 	time->tv_sec = 0;
42001da177e4SLinus Torvalds 	time->tv_nsec = 0;
42011da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
42021da177e4SLinus Torvalds 		return -EIO;
42031da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
42041da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4205409924e4STrond Myklebust 		if (status == 0)
4206409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
42071da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
42081da177e4SLinus Torvalds 	}
42093110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
42101da177e4SLinus Torvalds 	return status;
42111da177e4SLinus Torvalds }
42121da177e4SLinus Torvalds 
4213256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
42141da177e4SLinus Torvalds {
42151da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4216256e48bbSTrond Myklebust 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
42171da177e4SLinus Torvalds 
42181da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4219fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4220fe82a183SChuck Lever 			"%u %c %u\n",
42213110ff80SHarvey Harrison 				__func__,
42221da177e4SLinus Torvalds 				attrwords << 2,
42231da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
42241da177e4SLinus Torvalds 				nwords << 2);
42251da177e4SLinus Torvalds 		return -EIO;
42261da177e4SLinus Torvalds 	}
42271da177e4SLinus Torvalds 	return 0;
42281da177e4SLinus Torvalds }
42291da177e4SLinus Torvalds 
42301da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
42311da177e4SLinus Torvalds {
42328687b63aSAl Viro 	__be32 *p;
42331da177e4SLinus Torvalds 
4234c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4235c0eae66eSBenny Halevy 	if (unlikely(!p))
4236c0eae66eSBenny Halevy 		goto out_overflow;
42376f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
42383ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4239cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
42401da177e4SLinus Torvalds 	return 0;
4241c0eae66eSBenny Halevy out_overflow:
4242c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4243c0eae66eSBenny Halevy 	return -EIO;
42441da177e4SLinus Torvalds }
42451da177e4SLinus Torvalds 
42466168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
42471da177e4SLinus Torvalds {
42488687b63aSAl Viro 	__be32 *p;
42491da177e4SLinus Torvalds 	uint32_t supp, acc;
42501da177e4SLinus Torvalds 	int status;
42511da177e4SLinus Torvalds 
42521da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
42531da177e4SLinus Torvalds 	if (status)
42541da177e4SLinus Torvalds 		return status;
4255c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4256c0eae66eSBenny Halevy 	if (unlikely(!p))
4257c0eae66eSBenny Halevy 		goto out_overflow;
42586f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4259cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
42606168f62cSWeston Andros Adamson 	*supported = supp;
42616168f62cSWeston Andros Adamson 	*access = acc;
42621da177e4SLinus Torvalds 	return 0;
4263c0eae66eSBenny Halevy out_overflow:
4264c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4265c0eae66eSBenny Halevy 	return -EIO;
42661da177e4SLinus Torvalds }
42671da177e4SLinus Torvalds 
426807d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
42691da177e4SLinus Torvalds {
4270ab6e9aafSTrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4271ab6e9aafSTrond Myklebust 	if (unlikely(ret < 0)) {
427207d30434SBenny Halevy 		print_overflow_msg(__func__, xdr);
427307d30434SBenny Halevy 		return -EIO;
427407d30434SBenny Halevy 	}
4275ab6e9aafSTrond Myklebust 	return 0;
4276ab6e9aafSTrond Myklebust }
427707d30434SBenny Halevy 
427807d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
427907d30434SBenny Halevy {
42802d2f24adSTrond Myklebust 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
42811da177e4SLinus Torvalds }
42821da177e4SLinus Torvalds 
428393b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
428493b717fdSTrond Myklebust {
428593b717fdSTrond Myklebust 	stateid->type = NFS4_OPEN_STATEID_TYPE;
428693b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
428793b717fdSTrond Myklebust }
428893b717fdSTrond Myklebust 
428993b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
429093b717fdSTrond Myklebust {
429193b717fdSTrond Myklebust 	stateid->type = NFS4_LOCK_STATEID_TYPE;
429293b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
429393b717fdSTrond Myklebust }
429493b717fdSTrond Myklebust 
429593b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
429693b717fdSTrond Myklebust {
429793b717fdSTrond Myklebust 	stateid->type = NFS4_DELEGATION_STATEID_TYPE;
429893b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
429993b717fdSTrond Myklebust }
430093b717fdSTrond Myklebust 
43011da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
43021da177e4SLinus Torvalds {
43031da177e4SLinus Torvalds 	int status;
43041da177e4SLinus Torvalds 
43051da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4306c1d51931STrond Myklebust 	if (status != -EIO)
4307c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
430807d30434SBenny Halevy 	if (!status)
430993b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
43101da177e4SLinus Torvalds 	return status;
43111da177e4SLinus Torvalds }
43121da177e4SLinus Torvalds 
4313db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4314db942bbdSBenny Halevy {
4315cd93710eSChuck Lever 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
43161da177e4SLinus Torvalds }
43171da177e4SLinus Torvalds 
43182f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
43192f2c63bcSTrond Myklebust {
43202f2c63bcSTrond Myklebust 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
43212f2c63bcSTrond Myklebust }
43222f2c63bcSTrond Myklebust 
43230b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
43241da177e4SLinus Torvalds {
43251da177e4SLinus Torvalds 	int status;
43261da177e4SLinus Torvalds 
43271da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4328db942bbdSBenny Halevy 	if (!status)
43292f2c63bcSTrond Myklebust 		status = decode_write_verifier(xdr, &res->verf->verifier);
43301da177e4SLinus Torvalds 	return status;
43311da177e4SLinus Torvalds }
43321da177e4SLinus Torvalds 
43331da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
43341da177e4SLinus Torvalds {
43358687b63aSAl Viro 	__be32 *p;
43361da177e4SLinus Torvalds 	uint32_t bmlen;
43371da177e4SLinus Torvalds 	int status;
43381da177e4SLinus Torvalds 
43391da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
43401da177e4SLinus Torvalds 	if (status)
43411da177e4SLinus Torvalds 		return status;
43421da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
43431da177e4SLinus Torvalds 		return status;
4344c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4345c0eae66eSBenny Halevy 	if (unlikely(!p))
4346c0eae66eSBenny Halevy 		goto out_overflow;
4347cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4348c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4349c0eae66eSBenny Halevy 	if (likely(p))
43501da177e4SLinus Torvalds 		return 0;
4351c0eae66eSBenny Halevy out_overflow:
4352c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4353c0eae66eSBenny Halevy 	return -EIO;
43541da177e4SLinus Torvalds }
43551da177e4SLinus Torvalds 
43561da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
43571da177e4SLinus Torvalds {
4358256e48bbSTrond Myklebust 	unsigned int savep;
4359dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43601da177e4SLinus Torvalds 	int status;
43611da177e4SLinus Torvalds 
43621da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43631da177e4SLinus Torvalds 		goto xdr_error;
43641da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43651da177e4SLinus Torvalds 		goto xdr_error;
43661da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43671da177e4SLinus Torvalds 		goto xdr_error;
43681da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
43691da177e4SLinus Torvalds 		goto xdr_error;
4370264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4371264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4372264e6351SChuck Lever 		goto xdr_error;
43731da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
43741da177e4SLinus Torvalds 		goto xdr_error;
43751da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
43761da177e4SLinus Torvalds 		goto xdr_error;
43771da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
43781da177e4SLinus Torvalds 		goto xdr_error;
43798c61282fSKinglong Mee 	if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
43808c61282fSKinglong Mee 				res->exclcreat_bitmask)) != 0)
43818c61282fSKinglong Mee 		goto xdr_error;
43821da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43831da177e4SLinus Torvalds xdr_error:
43843110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43851da177e4SLinus Torvalds 	return status;
43861da177e4SLinus Torvalds }
43871da177e4SLinus Torvalds 
43881da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
43891da177e4SLinus Torvalds {
4390256e48bbSTrond Myklebust 	unsigned int savep;
4391dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43921da177e4SLinus Torvalds 	int status;
43931da177e4SLinus Torvalds 
43941da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43951da177e4SLinus Torvalds 		goto xdr_error;
43961da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43971da177e4SLinus Torvalds 		goto xdr_error;
43981da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43991da177e4SLinus Torvalds 		goto xdr_error;
44001da177e4SLinus Torvalds 
44011da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
44021da177e4SLinus Torvalds 		goto xdr_error;
44031da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
44041da177e4SLinus Torvalds 		goto xdr_error;
44051da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
44061da177e4SLinus Torvalds 		goto xdr_error;
44071ca843a2SAndreas Gruenbacher 
44081ca843a2SAndreas Gruenbacher 	status = -EIO;
44091ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
44101ca843a2SAndreas Gruenbacher 		goto xdr_error;
44111ca843a2SAndreas Gruenbacher 
44121da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
44131da177e4SLinus Torvalds 		goto xdr_error;
44141da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
44151da177e4SLinus Torvalds 		goto xdr_error;
44161da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
44171da177e4SLinus Torvalds 		goto xdr_error;
44181da177e4SLinus Torvalds 
44191da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44201da177e4SLinus Torvalds xdr_error:
44213110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44221da177e4SLinus Torvalds 	return status;
44231da177e4SLinus Torvalds }
44241da177e4SLinus Torvalds 
44251da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
44261da177e4SLinus Torvalds {
4427256e48bbSTrond Myklebust 	unsigned int savep;
4428dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
44291da177e4SLinus Torvalds 	int status;
44301da177e4SLinus Torvalds 
44311da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44321da177e4SLinus Torvalds 		goto xdr_error;
44331da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44341da177e4SLinus Torvalds 		goto xdr_error;
44351da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44361da177e4SLinus Torvalds 		goto xdr_error;
44371da177e4SLinus Torvalds 
44381da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
44391da177e4SLinus Torvalds 		goto xdr_error;
44401da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
44411da177e4SLinus Torvalds 		goto xdr_error;
44421da177e4SLinus Torvalds 
44431da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44441da177e4SLinus Torvalds xdr_error:
44453110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44461da177e4SLinus Torvalds 	return status;
44471da177e4SLinus Torvalds }
44481da177e4SLinus Torvalds 
444988034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
445088034c3dSAndy Adamson 				  uint32_t *bitmap,
445188034c3dSAndy Adamson 				  uint64_t *res,
445288034c3dSAndy Adamson 				  uint32_t hint_bit)
445388034c3dSAndy Adamson {
445488034c3dSAndy Adamson 	__be32 *p;
445588034c3dSAndy Adamson 
445688034c3dSAndy Adamson 	*res = 0;
445788034c3dSAndy Adamson 	if (likely(bitmap[0] & hint_bit)) {
445888034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
445988034c3dSAndy Adamson 		if (unlikely(!p))
446088034c3dSAndy Adamson 			goto out_overflow;
446188034c3dSAndy Adamson 		xdr_decode_hyper(p, res);
446288034c3dSAndy Adamson 	}
446388034c3dSAndy Adamson 	return 0;
446488034c3dSAndy Adamson out_overflow:
446588034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
446688034c3dSAndy Adamson 	return -EIO;
446788034c3dSAndy Adamson }
446888034c3dSAndy Adamson 
446988034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
447088034c3dSAndy Adamson 					struct nfs4_threshold *res)
447188034c3dSAndy Adamson {
4472256e48bbSTrond Myklebust 	__be32 *p;
4473256e48bbSTrond Myklebust 	unsigned int savep;
447488034c3dSAndy Adamson 	uint32_t bitmap[3] = {0,}, attrlen;
447588034c3dSAndy Adamson 	int status;
447688034c3dSAndy Adamson 
447788034c3dSAndy Adamson 	/* layout type */
447888034c3dSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
447988034c3dSAndy Adamson 	if (unlikely(!p)) {
448088034c3dSAndy Adamson 		print_overflow_msg(__func__, xdr);
448188034c3dSAndy Adamson 		return -EIO;
448288034c3dSAndy Adamson 	}
448388034c3dSAndy Adamson 	res->l_type = be32_to_cpup(p);
448488034c3dSAndy Adamson 
448588034c3dSAndy Adamson 	/* thi_hintset bitmap */
448688034c3dSAndy Adamson 	status = decode_attr_bitmap(xdr, bitmap);
448788034c3dSAndy Adamson 	if (status < 0)
448888034c3dSAndy Adamson 		goto xdr_error;
448988034c3dSAndy Adamson 
449088034c3dSAndy Adamson 	/* thi_hintlist length */
449188034c3dSAndy Adamson 	status = decode_attr_length(xdr, &attrlen, &savep);
449288034c3dSAndy Adamson 	if (status < 0)
449388034c3dSAndy Adamson 		goto xdr_error;
449488034c3dSAndy Adamson 	/* thi_hintlist */
449588034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
449688034c3dSAndy Adamson 	if (status < 0)
449788034c3dSAndy Adamson 		goto xdr_error;
449888034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
449988034c3dSAndy Adamson 	if (status < 0)
450088034c3dSAndy Adamson 		goto xdr_error;
450188034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
450288034c3dSAndy Adamson 				       THRESHOLD_RD_IO);
450388034c3dSAndy Adamson 	if (status < 0)
450488034c3dSAndy Adamson 		goto xdr_error;
450588034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
450688034c3dSAndy Adamson 				       THRESHOLD_WR_IO);
450788034c3dSAndy Adamson 	if (status < 0)
450888034c3dSAndy Adamson 		goto xdr_error;
450988034c3dSAndy Adamson 
451088034c3dSAndy Adamson 	status = verify_attr_len(xdr, savep, attrlen);
451188034c3dSAndy Adamson 	res->bm = bitmap[0];
451288034c3dSAndy Adamson 
451388034c3dSAndy Adamson 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
451488034c3dSAndy Adamson 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
451588034c3dSAndy Adamson 		res->wr_io_sz);
451688034c3dSAndy Adamson xdr_error:
451788034c3dSAndy Adamson 	dprintk("%s ret=%d!\n", __func__, status);
451888034c3dSAndy Adamson 	return status;
451988034c3dSAndy Adamson }
452088034c3dSAndy Adamson 
452188034c3dSAndy Adamson /*
452288034c3dSAndy Adamson  * Thresholds on pNFS direct I/O vrs MDS I/O
452388034c3dSAndy Adamson  */
452488034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
452588034c3dSAndy Adamson 				    uint32_t *bitmap,
452688034c3dSAndy Adamson 				    struct nfs4_threshold *res)
452788034c3dSAndy Adamson {
452888034c3dSAndy Adamson 	__be32 *p;
452988034c3dSAndy Adamson 	int status = 0;
453088034c3dSAndy Adamson 	uint32_t num;
453188034c3dSAndy Adamson 
453288034c3dSAndy Adamson 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
453388034c3dSAndy Adamson 		return -EIO;
4534029c5347STrond Myklebust 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
45351549210fSTrond Myklebust 		/* Did the server return an unrequested attribute? */
45361549210fSTrond Myklebust 		if (unlikely(res == NULL))
45371549210fSTrond Myklebust 			return -EREMOTEIO;
453888034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 4);
453988034c3dSAndy Adamson 		if (unlikely(!p))
454088034c3dSAndy Adamson 			goto out_overflow;
454188034c3dSAndy Adamson 		num = be32_to_cpup(p);
454288034c3dSAndy Adamson 		if (num == 0)
454388034c3dSAndy Adamson 			return 0;
454488034c3dSAndy Adamson 		if (num > 1)
454588034c3dSAndy Adamson 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
454688034c3dSAndy Adamson 				"drivers per filesystem not supported\n",
454788034c3dSAndy Adamson 				__func__);
454888034c3dSAndy Adamson 
454988034c3dSAndy Adamson 		status = decode_first_threshold_item4(xdr, res);
4550029c5347STrond Myklebust 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
455188034c3dSAndy Adamson 	}
455288034c3dSAndy Adamson 	return status;
455388034c3dSAndy Adamson out_overflow:
455488034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
455588034c3dSAndy Adamson 	return -EIO;
455688034c3dSAndy Adamson }
455788034c3dSAndy Adamson 
4558ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4559ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
4560aa9c2669SDavid Quigley 		struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
45616926afd1STrond Myklebust 		const struct nfs_server *server)
45621da177e4SLinus Torvalds {
4563bca79478STrond Myklebust 	int status;
4564bca79478STrond Myklebust 	umode_t fmode = 0;
4565ae42c70aSBryan Schumaker 	uint32_t type;
4566ee7b75fcSTrond Myklebust 	int32_t err;
45671da177e4SLinus Torvalds 
4568f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4569f26c7a78STrond Myklebust 	if (status < 0)
45701da177e4SLinus Torvalds 		goto xdr_error;
4571409924e4STrond Myklebust 	fattr->mode = 0;
4572409924e4STrond Myklebust 	if (status != 0) {
4573409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4574409924e4STrond Myklebust 		fattr->valid |= status;
4575409924e4STrond Myklebust 	}
45761da177e4SLinus Torvalds 
4577f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4578f26c7a78STrond Myklebust 	if (status < 0)
45791da177e4SLinus Torvalds 		goto xdr_error;
4580409924e4STrond Myklebust 	fattr->valid |= status;
4581f26c7a78STrond Myklebust 
4582f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4583f26c7a78STrond Myklebust 	if (status < 0)
45841da177e4SLinus Torvalds 		goto xdr_error;
4585409924e4STrond Myklebust 	fattr->valid |= status;
4586f26c7a78STrond Myklebust 
4587f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4588f26c7a78STrond Myklebust 	if (status < 0)
45891da177e4SLinus Torvalds 		goto xdr_error;
4590409924e4STrond Myklebust 	fattr->valid |= status;
4591f26c7a78STrond Myklebust 
4592ee7b75fcSTrond Myklebust 	err = 0;
4593ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4594ae42c70aSBryan Schumaker 	if (status < 0)
4595ae42c70aSBryan Schumaker 		goto xdr_error;
4596ae42c70aSBryan Schumaker 
4597ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4598ae42c70aSBryan Schumaker 	if (status < 0)
4599ae42c70aSBryan Schumaker 		goto xdr_error;
4600ae42c70aSBryan Schumaker 
4601f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4602f26c7a78STrond Myklebust 	if (status < 0)
46031da177e4SLinus Torvalds 		goto xdr_error;
4604409924e4STrond Myklebust 	fattr->valid |= status;
4605f26c7a78STrond Myklebust 
46068b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4607f26c7a78STrond Myklebust 	if (status < 0)
4608683b57b4STrond Myklebust 		goto xdr_error;
4609409924e4STrond Myklebust 	fattr->valid |= status;
4610f26c7a78STrond Myklebust 
46111ca843a2SAndreas Gruenbacher 	status = -EIO;
46121ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
46131ca843a2SAndreas Gruenbacher 		goto xdr_error;
46141ca843a2SAndreas Gruenbacher 
4615f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4616f26c7a78STrond Myklebust 	if (status < 0)
46171da177e4SLinus Torvalds 		goto xdr_error;
4618409924e4STrond Myklebust 	if (status != 0) {
46191da177e4SLinus Torvalds 		fattr->mode |= fmode;
4620409924e4STrond Myklebust 		fattr->valid |= status;
4621409924e4STrond Myklebust 	}
4622f26c7a78STrond Myklebust 
4623f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4624f26c7a78STrond Myklebust 	if (status < 0)
46251da177e4SLinus Torvalds 		goto xdr_error;
4626409924e4STrond Myklebust 	fattr->valid |= status;
4627f26c7a78STrond Myklebust 
46286926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4629f26c7a78STrond Myklebust 	if (status < 0)
46301da177e4SLinus Torvalds 		goto xdr_error;
4631409924e4STrond Myklebust 	fattr->valid |= status;
4632f26c7a78STrond Myklebust 
46336926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4634f26c7a78STrond Myklebust 	if (status < 0)
46351da177e4SLinus Torvalds 		goto xdr_error;
4636409924e4STrond Myklebust 	fattr->valid |= status;
4637f26c7a78STrond Myklebust 
4638f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4639f26c7a78STrond Myklebust 	if (status < 0)
46401da177e4SLinus Torvalds 		goto xdr_error;
4641409924e4STrond Myklebust 	fattr->valid |= status;
4642f26c7a78STrond Myklebust 
4643f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4644f26c7a78STrond Myklebust 	if (status < 0)
46451da177e4SLinus Torvalds 		goto xdr_error;
4646409924e4STrond Myklebust 	fattr->valid |= status;
4647f26c7a78STrond Myklebust 
4648f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4649f26c7a78STrond Myklebust 	if (status < 0)
46501da177e4SLinus Torvalds 		goto xdr_error;
4651409924e4STrond Myklebust 	fattr->valid |= status;
4652f26c7a78STrond Myklebust 
4653f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4654f26c7a78STrond Myklebust 	if (status < 0)
46551da177e4SLinus Torvalds 		goto xdr_error;
4656409924e4STrond Myklebust 	fattr->valid |= status;
4657f26c7a78STrond Myklebust 
4658f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4659f26c7a78STrond Myklebust 	if (status < 0)
46601da177e4SLinus Torvalds 		goto xdr_error;
4661409924e4STrond Myklebust 	fattr->valid |= status;
4662f26c7a78STrond Myklebust 
466328331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4664f26c7a78STrond Myklebust 	if (status < 0)
466599baf625SManoj Naik 		goto xdr_error;
4666409924e4STrond Myklebust 	fattr->valid |= status;
4667f26c7a78STrond Myklebust 
46681ca843a2SAndreas Gruenbacher 	status = -EIO;
46691ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
46701ca843a2SAndreas Gruenbacher 		goto xdr_error;
46711ca843a2SAndreas Gruenbacher 
467288034c3dSAndy Adamson 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
467388034c3dSAndy Adamson 	if (status < 0)
467488034c3dSAndy Adamson 		goto xdr_error;
467588034c3dSAndy Adamson 
4676aa9c2669SDavid Quigley 	if (label) {
4677aa9c2669SDavid Quigley 		status = decode_attr_security_label(xdr, bitmap, label);
4678aa9c2669SDavid Quigley 		if (status < 0)
4679aa9c2669SDavid Quigley 			goto xdr_error;
4680aa9c2669SDavid Quigley 		fattr->valid |= status;
4681aa9c2669SDavid Quigley 	}
4682aa9c2669SDavid Quigley 
4683ae42c70aSBryan Schumaker xdr_error:
4684ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4685ae42c70aSBryan Schumaker 	return status;
4686ae42c70aSBryan Schumaker }
4687ae42c70aSBryan Schumaker 
4688ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
46898b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4690aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4691ae42c70aSBryan Schumaker {
4692256e48bbSTrond Myklebust 	unsigned int savep;
4693ae42c70aSBryan Schumaker 	uint32_t attrlen,
4694dae100c2SFred Isaman 		 bitmap[3] = {0};
4695ae42c70aSBryan Schumaker 	int status;
4696ae42c70aSBryan Schumaker 
4697ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4698ae42c70aSBryan Schumaker 	if (status < 0)
4699ae42c70aSBryan Schumaker 		goto xdr_error;
4700ae42c70aSBryan Schumaker 
4701ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4702ae42c70aSBryan Schumaker 	if (status < 0)
4703ae42c70aSBryan Schumaker 		goto xdr_error;
4704ae42c70aSBryan Schumaker 
4705ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4706ae42c70aSBryan Schumaker 	if (status < 0)
4707ae42c70aSBryan Schumaker 		goto xdr_error;
4708ae42c70aSBryan Schumaker 
4709aa9c2669SDavid Quigley 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4710aa9c2669SDavid Quigley 					label, server);
4711ae42c70aSBryan Schumaker 	if (status < 0)
4712ae42c70aSBryan Schumaker 		goto xdr_error;
4713ae42c70aSBryan Schumaker 
4714f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
47151da177e4SLinus Torvalds xdr_error:
47163110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
47171da177e4SLinus Torvalds 	return status;
47181da177e4SLinus Torvalds }
47191da177e4SLinus Torvalds 
4720aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4721aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4722aa9c2669SDavid Quigley {
4723aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4724aa9c2669SDavid Quigley }
4725aa9c2669SDavid Quigley 
4726ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47276926afd1STrond Myklebust 		const struct nfs_server *server)
4728ae42c70aSBryan Schumaker {
4729aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4730ae42c70aSBryan Schumaker }
47311da177e4SLinus Torvalds 
4732504913fbSAndy Adamson /*
47333132e49eSJeff Layton  * Decode potentially multiple layout types.
4734504913fbSAndy Adamson  */
47353132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4736ca440c38SJeff Layton 				    struct nfs_fsinfo *fsinfo)
4737504913fbSAndy Adamson {
4738b8a8a0ddSTrond Myklebust 	__be32 *p;
4739ca440c38SJeff Layton 	uint32_t i;
4740504913fbSAndy Adamson 
4741504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4742504913fbSAndy Adamson 	if (unlikely(!p))
4743504913fbSAndy Adamson 		goto out_overflow;
4744ca440c38SJeff Layton 	fsinfo->nlayouttypes = be32_to_cpup(p);
4745504913fbSAndy Adamson 
4746504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4747ca440c38SJeff Layton 	if (fsinfo->nlayouttypes == 0)
4748504913fbSAndy Adamson 		return 0;
4749504913fbSAndy Adamson 
4750504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4751ca440c38SJeff Layton 	p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4752504913fbSAndy Adamson 	if (unlikely(!p))
4753504913fbSAndy Adamson 		goto out_overflow;
4754ca440c38SJeff Layton 
4755ca440c38SJeff Layton 	/* If we get too many, then just cap it at the max */
4756ca440c38SJeff Layton 	if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4757ca440c38SJeff Layton 		printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4758ca440c38SJeff Layton 			__func__, fsinfo->nlayouttypes);
4759ca440c38SJeff Layton 		fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4760ca440c38SJeff Layton 	}
4761ca440c38SJeff Layton 
4762ca440c38SJeff Layton 	for(i = 0; i < fsinfo->nlayouttypes; ++i)
4763ca440c38SJeff Layton 		fsinfo->layouttype[i] = be32_to_cpup(p++);
4764504913fbSAndy Adamson 	return 0;
4765504913fbSAndy Adamson out_overflow:
4766504913fbSAndy Adamson 	print_overflow_msg(__func__, xdr);
4767504913fbSAndy Adamson 	return -EIO;
4768504913fbSAndy Adamson }
4769504913fbSAndy Adamson 
4770504913fbSAndy Adamson /*
4771504913fbSAndy Adamson  * The type of file system exported.
4772504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4773504913fbSAndy Adamson  */
4774504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4775ca440c38SJeff Layton 				struct nfs_fsinfo *fsinfo)
4776504913fbSAndy Adamson {
4777504913fbSAndy Adamson 	int status = 0;
4778504913fbSAndy Adamson 
4779504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4780504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4781504913fbSAndy Adamson 		return -EIO;
4782504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4783ca440c38SJeff Layton 		status = decode_pnfs_layout_types(xdr, fsinfo);
4784504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
47853132e49eSJeff Layton 	}
4786504913fbSAndy Adamson 	return status;
4787504913fbSAndy Adamson }
4788504913fbSAndy Adamson 
4789dae100c2SFred Isaman /*
4790dae100c2SFred Isaman  * The prefered block size for layout directed io
4791dae100c2SFred Isaman  */
4792dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4793dae100c2SFred Isaman 				      uint32_t *res)
4794dae100c2SFred Isaman {
4795dae100c2SFred Isaman 	__be32 *p;
4796dae100c2SFred Isaman 
4797dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4798dae100c2SFred Isaman 	*res = 0;
4799dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4800dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4801dae100c2SFred Isaman 		if (unlikely(!p)) {
4802dae100c2SFred Isaman 			print_overflow_msg(__func__, xdr);
4803dae100c2SFred Isaman 			return -EIO;
4804dae100c2SFred Isaman 		}
4805dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4806dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4807dae100c2SFred Isaman 	}
4808dae100c2SFred Isaman 	return 0;
4809dae100c2SFred Isaman }
4810dae100c2SFred Isaman 
48112a92ee92SPeng Tao /*
48122a92ee92SPeng Tao  * The granularity of a CLONE operation.
48132a92ee92SPeng Tao  */
48142a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
48152a92ee92SPeng Tao 				     uint32_t *res)
48162a92ee92SPeng Tao {
48172a92ee92SPeng Tao 	__be32 *p;
48182a92ee92SPeng Tao 
48192a92ee92SPeng Tao 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
48202a92ee92SPeng Tao 	*res = 0;
48212a92ee92SPeng Tao 	if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
48222a92ee92SPeng Tao 		p = xdr_inline_decode(xdr, 4);
48232a92ee92SPeng Tao 		if (unlikely(!p)) {
48242a92ee92SPeng Tao 			print_overflow_msg(__func__, xdr);
48252a92ee92SPeng Tao 			return -EIO;
48262a92ee92SPeng Tao 		}
48272a92ee92SPeng Tao 		*res = be32_to_cpup(p);
48282a92ee92SPeng Tao 		bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
48292a92ee92SPeng Tao 	}
48302a92ee92SPeng Tao 	return 0;
48312a92ee92SPeng Tao }
48322a92ee92SPeng Tao 
48331da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
48341da177e4SLinus Torvalds {
4835256e48bbSTrond Myklebust 	unsigned int savep;
4836dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
48371da177e4SLinus Torvalds 	int status;
48381da177e4SLinus Torvalds 
48391da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
48401da177e4SLinus Torvalds 		goto xdr_error;
48411da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
48421da177e4SLinus Torvalds 		goto xdr_error;
48431da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
48441da177e4SLinus Torvalds 		goto xdr_error;
48451da177e4SLinus Torvalds 
48461da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
48471da177e4SLinus Torvalds 
48481da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
48491da177e4SLinus Torvalds 		goto xdr_error;
48501da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
48511da177e4SLinus Torvalds 		goto xdr_error;
48521da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
48531da177e4SLinus Torvalds 		goto xdr_error;
48541da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
48551da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
48561da177e4SLinus Torvalds 		goto xdr_error;
48571da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
48581ca843a2SAndreas Gruenbacher 
48591ca843a2SAndreas Gruenbacher 	status = -EIO;
48601ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
48611ca843a2SAndreas Gruenbacher 		goto xdr_error;
48621ca843a2SAndreas Gruenbacher 
486355b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
486455b6e774SRicardo Labiaga 	if (status != 0)
486555b6e774SRicardo Labiaga 		goto xdr_error;
4866ca440c38SJeff Layton 	status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4867504913fbSAndy Adamson 	if (status != 0)
4868504913fbSAndy Adamson 		goto xdr_error;
48691ca843a2SAndreas Gruenbacher 
48701ca843a2SAndreas Gruenbacher 	status = -EIO;
48711ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
48721ca843a2SAndreas Gruenbacher 		goto xdr_error;
48731ca843a2SAndreas Gruenbacher 
4874dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4875dae100c2SFred Isaman 	if (status)
4876dae100c2SFred Isaman 		goto xdr_error;
48772a92ee92SPeng Tao 	status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
48782a92ee92SPeng Tao 	if (status)
48792a92ee92SPeng Tao 		goto xdr_error;
48801da177e4SLinus Torvalds 
48811da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
48821da177e4SLinus Torvalds xdr_error:
48833110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
48841da177e4SLinus Torvalds 	return status;
48851da177e4SLinus Torvalds }
48861da177e4SLinus Torvalds 
48871da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
48881da177e4SLinus Torvalds {
48898687b63aSAl Viro 	__be32 *p;
48901da177e4SLinus Torvalds 	uint32_t len;
48911da177e4SLinus Torvalds 	int status;
48921da177e4SLinus Torvalds 
48939936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
48949936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
48959936781dSTrond Myklebust 
48961da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
48971da177e4SLinus Torvalds 	if (status)
48981da177e4SLinus Torvalds 		return status;
48991da177e4SLinus Torvalds 
4900c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4901c0eae66eSBenny Halevy 	if (unlikely(!p))
4902c0eae66eSBenny Halevy 		goto out_overflow;
4903cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
49041da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
49051da177e4SLinus Torvalds 		return -EIO;
49061da177e4SLinus Torvalds 	fh->size = len;
4907c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4908c0eae66eSBenny Halevy 	if (unlikely(!p))
4909c0eae66eSBenny Halevy 		goto out_overflow;
491099398d06SBenny Halevy 	memcpy(fh->data, p, len);
49111da177e4SLinus Torvalds 	return 0;
4912c0eae66eSBenny Halevy out_overflow:
4913c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4914c0eae66eSBenny Halevy 	return -EIO;
49151da177e4SLinus Torvalds }
49161da177e4SLinus Torvalds 
49171da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
49181da177e4SLinus Torvalds {
49191da177e4SLinus Torvalds 	int status;
49201da177e4SLinus Torvalds 
49211da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
49221da177e4SLinus Torvalds 	if (status)
49231da177e4SLinus Torvalds 		return status;
49241da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
49251da177e4SLinus Torvalds }
49261da177e4SLinus Torvalds 
49271da177e4SLinus Torvalds /*
49281da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
49291da177e4SLinus Torvalds  */
4930911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
49311da177e4SLinus Torvalds {
4932911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
49338687b63aSAl Viro 	__be32 *p;
4934911d1aafSTrond Myklebust 	uint32_t namelen, type;
49351da177e4SLinus Torvalds 
4936babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4937c0eae66eSBenny Halevy 	if (unlikely(!p))
4938c0eae66eSBenny Halevy 		goto out_overflow;
4939babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
49403ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4941babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4942babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4943911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4944911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4945911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4946911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4947911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4948911d1aafSTrond Myklebust 		if (type & 1)
4949911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4950911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4951911d1aafSTrond Myklebust 	}
4952babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4953babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4954babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4955c0eae66eSBenny Halevy 	if (likely(p))
49561da177e4SLinus Torvalds 		return -NFS4ERR_DENIED;
4957c0eae66eSBenny Halevy out_overflow:
4958c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4959c0eae66eSBenny Halevy 	return -EIO;
49601da177e4SLinus Torvalds }
49611da177e4SLinus Torvalds 
4962911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
49631da177e4SLinus Torvalds {
49641da177e4SLinus Torvalds 	int status;
49651da177e4SLinus Torvalds 
49661da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4967c1d51931STrond Myklebust 	if (status == -EIO)
4968c1d51931STrond Myklebust 		goto out;
49691da177e4SLinus Torvalds 	if (status == 0) {
497093b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
497107d30434SBenny Halevy 		if (unlikely(status))
497207d30434SBenny Halevy 			goto out;
49731da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4974c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4975c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4976c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4977c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4978c1d51931STrond Myklebust out:
49791da177e4SLinus Torvalds 	return status;
49801da177e4SLinus Torvalds }
49811da177e4SLinus Torvalds 
4982911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
49831da177e4SLinus Torvalds {
49841da177e4SLinus Torvalds 	int status;
49851da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
49861da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4987911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
49881da177e4SLinus Torvalds 	return status;
49891da177e4SLinus Torvalds }
49901da177e4SLinus Torvalds 
4991911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
49921da177e4SLinus Torvalds {
49931da177e4SLinus Torvalds 	int status;
49941da177e4SLinus Torvalds 
49951da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4996c1d51931STrond Myklebust 	if (status != -EIO)
4997c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
499807d30434SBenny Halevy 	if (status == 0)
499993b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
50001da177e4SLinus Torvalds 	return status;
50011da177e4SLinus Torvalds }
50021da177e4SLinus Torvalds 
5003d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
5004d3c7b7ccSTrond Myklebust {
5005d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5006d3c7b7ccSTrond Myklebust }
5007d3c7b7ccSTrond Myklebust 
50081da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
50091da177e4SLinus Torvalds {
50101da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
50111da177e4SLinus Torvalds }
50121da177e4SLinus Torvalds 
50131da177e4SLinus Torvalds /* This is too sick! */
50147d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr,
50157d160a6cSTrond Myklebust 		unsigned long *pagemod_limit)
50161da177e4SLinus Torvalds {
50178687b63aSAl Viro 	__be32 *p;
50181da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
50197d160a6cSTrond Myklebust 	u64 maxsize = 0;
50201da177e4SLinus Torvalds 
5021c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5022c0eae66eSBenny Halevy 	if (unlikely(!p))
5023c0eae66eSBenny Halevy 		goto out_overflow;
50246f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
50251da177e4SLinus Torvalds 	switch (limit_type) {
50267d160a6cSTrond Myklebust 	case NFS4_LIMIT_SIZE:
50277d160a6cSTrond Myklebust 		xdr_decode_hyper(p, &maxsize);
50281da177e4SLinus Torvalds 		break;
50297d160a6cSTrond Myklebust 	case NFS4_LIMIT_BLOCKS:
50306f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
5031cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
50327d160a6cSTrond Myklebust 		maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
50331da177e4SLinus Torvalds 	}
503409cbfeafSKirill A. Shutemov 	maxsize >>= PAGE_SHIFT;
50357d160a6cSTrond Myklebust 	*pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
50361da177e4SLinus Torvalds 	return 0;
5037c0eae66eSBenny Halevy out_overflow:
5038c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5039c0eae66eSBenny Halevy 	return -EIO;
50401da177e4SLinus Torvalds }
50411da177e4SLinus Torvalds 
50426ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr,
50436ae37339STrond Myklebust 		uint32_t delegation_type,
50446ae37339STrond Myklebust 		struct nfs_openres *res)
50451da177e4SLinus Torvalds {
50468687b63aSAl Viro 	__be32 *p;
504707d30434SBenny Halevy 	int status;
50481da177e4SLinus Torvalds 
504993b717fdSTrond Myklebust 	status = decode_delegation_stateid(xdr, &res->delegation);
505007d30434SBenny Halevy 	if (unlikely(status))
505107d30434SBenny Halevy 		return status;
5052c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5053c0eae66eSBenny Halevy 	if (unlikely(!p))
5054c0eae66eSBenny Halevy 		goto out_overflow;
5055cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
505605d564feSAndy Adamson 
50571da177e4SLinus Torvalds 	switch (delegation_type) {
50581da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
50591da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
50601da177e4SLinus Torvalds 		break;
50611da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
50621da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
50637d160a6cSTrond Myklebust 		if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
50641da177e4SLinus Torvalds 				return -EIO;
50651da177e4SLinus Torvalds 	}
50661bbe60ffSTrond Myklebust 	return decode_ace(xdr, NULL);
5067c0eae66eSBenny Halevy out_overflow:
5068c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5069c0eae66eSBenny Halevy 	return -EIO;
50701da177e4SLinus Torvalds }
50711da177e4SLinus Torvalds 
50726ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50736ae37339STrond Myklebust {
50746ae37339STrond Myklebust 	__be32 *p;
50756ae37339STrond Myklebust 	uint32_t why_no_delegation;
50766ae37339STrond Myklebust 
50776ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50786ae37339STrond Myklebust 	if (unlikely(!p))
50796ae37339STrond Myklebust 		goto out_overflow;
50806ae37339STrond Myklebust 	why_no_delegation = be32_to_cpup(p);
50816ae37339STrond Myklebust 	switch (why_no_delegation) {
50826ae37339STrond Myklebust 		case WND4_CONTENTION:
50836ae37339STrond Myklebust 		case WND4_RESOURCE:
50846ae37339STrond Myklebust 			xdr_inline_decode(xdr, 4);
50856ae37339STrond Myklebust 			/* Ignore for now */
50866ae37339STrond Myklebust 	}
50876ae37339STrond Myklebust 	return 0;
50886ae37339STrond Myklebust out_overflow:
50896ae37339STrond Myklebust 	print_overflow_msg(__func__, xdr);
50906ae37339STrond Myklebust 	return -EIO;
50916ae37339STrond Myklebust }
50926ae37339STrond Myklebust 
50936ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50946ae37339STrond Myklebust {
50956ae37339STrond Myklebust 	__be32 *p;
50966ae37339STrond Myklebust 	uint32_t delegation_type;
50976ae37339STrond Myklebust 
50986ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50996ae37339STrond Myklebust 	if (unlikely(!p))
51006ae37339STrond Myklebust 		goto out_overflow;
51016ae37339STrond Myklebust 	delegation_type = be32_to_cpup(p);
51026ae37339STrond Myklebust 	res->delegation_type = 0;
51036ae37339STrond Myklebust 	switch (delegation_type) {
51046ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE:
51056ae37339STrond Myklebust 		return 0;
51066ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_READ:
51076ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_WRITE:
51086ae37339STrond Myklebust 		return decode_rw_delegation(xdr, delegation_type, res);
51096ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE_EXT:
51106ae37339STrond Myklebust 		return decode_no_delegation(xdr, res);
51116ae37339STrond Myklebust 	}
51126ae37339STrond Myklebust 	return -EIO;
51136ae37339STrond Myklebust out_overflow:
51146ae37339STrond Myklebust 	print_overflow_msg(__func__, xdr);
51156ae37339STrond Myklebust 	return -EIO;
51166ae37339STrond Myklebust }
51176ae37339STrond Myklebust 
51181da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
51191da177e4SLinus Torvalds {
51208687b63aSAl Viro 	__be32 *p;
5121aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
51221da177e4SLinus Torvalds 	int status;
51231da177e4SLinus Torvalds 
5124c7848f69STrond Myklebust 	if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5125c7848f69STrond Myklebust 		return status;
5126c1d51931STrond Myklebust 	nfs_increment_open_seqid(status, res->seqid);
5127c7848f69STrond Myklebust 	if (status)
5128c7848f69STrond Myklebust 		return status;
512993b717fdSTrond Myklebust 	status = decode_open_stateid(xdr, &res->stateid);
513007d30434SBenny Halevy 	if (unlikely(status))
51311da177e4SLinus Torvalds 		return status;
51321da177e4SLinus Torvalds 
51331da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
51341da177e4SLinus Torvalds 
5135c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5136c0eae66eSBenny Halevy 	if (unlikely(!p))
5137c0eae66eSBenny Halevy 		goto out_overflow;
51386f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
5139cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
51401da177e4SLinus Torvalds 	if (bmlen > 10)
51411da177e4SLinus Torvalds 		goto xdr_error;
51421da177e4SLinus Torvalds 
5143c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5144c0eae66eSBenny Halevy 	if (unlikely(!p))
5145c0eae66eSBenny Halevy 		goto out_overflow;
5146aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5147aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
51486f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
5149aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
5150aa53ed54SJeff Layton 		res->attrset[i] = 0;
5151aa53ed54SJeff Layton 
51521da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
51531da177e4SLinus Torvalds xdr_error:
51543110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
51551da177e4SLinus Torvalds 	return -EIO;
5156c0eae66eSBenny Halevy out_overflow:
5157c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5158c0eae66eSBenny Halevy 	return -EIO;
51591da177e4SLinus Torvalds }
51601da177e4SLinus Torvalds 
51611da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
51621da177e4SLinus Torvalds {
51631da177e4SLinus Torvalds 	int status;
51641da177e4SLinus Torvalds 
51651da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5166c1d51931STrond Myklebust 	if (status != -EIO)
5167c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
516807d30434SBenny Halevy 	if (!status)
516993b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51701da177e4SLinus Torvalds 	return status;
51711da177e4SLinus Torvalds }
51721da177e4SLinus Torvalds 
51731da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
51741da177e4SLinus Torvalds {
51751da177e4SLinus Torvalds 	int status;
51761da177e4SLinus Torvalds 
51771da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5178c1d51931STrond Myklebust 	if (status != -EIO)
5179c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
518007d30434SBenny Halevy 	if (!status)
518193b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51821da177e4SLinus Torvalds 	return status;
51831da177e4SLinus Torvalds }
51841da177e4SLinus Torvalds 
51851da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
51861da177e4SLinus Torvalds {
51871da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
51881da177e4SLinus Torvalds }
51891da177e4SLinus Torvalds 
51901da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
51911da177e4SLinus Torvalds {
51921da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
51931da177e4SLinus Torvalds }
51941da177e4SLinus Torvalds 
51959137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
51969137bdf3SAnna Schumaker 		       struct nfs_pgio_res *res)
51971da177e4SLinus Torvalds {
51988687b63aSAl Viro 	__be32 *p;
519964bd577eSTrond Myklebust 	uint32_t count, eof, recvd;
52001da177e4SLinus Torvalds 	int status;
52011da177e4SLinus Torvalds 
52021da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
52031da177e4SLinus Torvalds 	if (status)
52041da177e4SLinus Torvalds 		return status;
5205c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5206c0eae66eSBenny Halevy 	if (unlikely(!p))
5207c0eae66eSBenny Halevy 		goto out_overflow;
52086f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
5209cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
521064bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, count);
52111da177e4SLinus Torvalds 	if (count > recvd) {
5212fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
52131da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
52141da177e4SLinus Torvalds 		count = recvd;
52151da177e4SLinus Torvalds 		eof = 0;
52161da177e4SLinus Torvalds 	}
52171da177e4SLinus Torvalds 	res->eof = eof;
52181da177e4SLinus Torvalds 	res->count = count;
52191da177e4SLinus Torvalds 	return 0;
5220c0eae66eSBenny Halevy out_overflow:
5221c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5222c0eae66eSBenny Halevy 	return -EIO;
52231da177e4SLinus Torvalds }
52241da177e4SLinus Torvalds 
52251da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
52261da177e4SLinus Torvalds {
5227bcecff77SChuck Lever 	int		status;
5228cd93710eSChuck Lever 	__be32		verf[2];
52291da177e4SLinus Torvalds 
52301da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
5231db942bbdSBenny Halevy 	if (!status)
5232db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
5233db942bbdSBenny Halevy 	if (unlikely(status))
52341da177e4SLinus Torvalds 		return status;
5235cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
523644109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
5237cd93710eSChuck Lever 			__func__, verf[0], verf[1]);
523864bd577eSTrond Myklebust 	return xdr_read_pages(xdr, xdr->buf->page_len);
52391da177e4SLinus Torvalds }
52401da177e4SLinus Torvalds 
52411da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
52421da177e4SLinus Torvalds {
52431da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5244bcecff77SChuck Lever 	u32 len, recvd;
52458687b63aSAl Viro 	__be32 *p;
52461da177e4SLinus Torvalds 	int status;
52471da177e4SLinus Torvalds 
52481da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
52491da177e4SLinus Torvalds 	if (status)
52501da177e4SLinus Torvalds 		return status;
52511da177e4SLinus Torvalds 
52521da177e4SLinus Torvalds 	/* Convert length of symlink */
5253c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5254c0eae66eSBenny Halevy 	if (unlikely(!p))
5255c0eae66eSBenny Halevy 		goto out_overflow;
5256cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
52571da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
5258fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
52591da177e4SLinus Torvalds 		return -ENAMETOOLONG;
52601da177e4SLinus Torvalds 	}
526164bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, len);
52621da177e4SLinus Torvalds 	if (recvd < len) {
5263fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
52641da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
52651da177e4SLinus Torvalds 		return -EIO;
52661da177e4SLinus Torvalds 	}
52671da177e4SLinus Torvalds 	/*
52681da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
52691da177e4SLinus Torvalds 	 * the link text will be copied directly into the
52701da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
52711da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
52721da177e4SLinus Torvalds 	 * null-termination).
52731da177e4SLinus Torvalds 	 */
5274b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
52751da177e4SLinus Torvalds 	return 0;
5276c0eae66eSBenny Halevy out_overflow:
5277c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5278c0eae66eSBenny Halevy 	return -EIO;
52791da177e4SLinus Torvalds }
52801da177e4SLinus Torvalds 
52811da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
52821da177e4SLinus Torvalds {
52831da177e4SLinus Torvalds 	int status;
52841da177e4SLinus Torvalds 
52851da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
52861da177e4SLinus Torvalds 	if (status)
52871da177e4SLinus Torvalds 		goto out;
52881da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
52891da177e4SLinus Torvalds out:
52901da177e4SLinus Torvalds 	return status;
52911da177e4SLinus Torvalds }
52921da177e4SLinus Torvalds 
52931da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
52941da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
52951da177e4SLinus Torvalds {
52961da177e4SLinus Torvalds 	int status;
52971da177e4SLinus Torvalds 
52981da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
52991da177e4SLinus Torvalds 	if (status)
53001da177e4SLinus Torvalds 		goto out;
53011da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
53021da177e4SLinus Torvalds 		goto out;
53031da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
53041da177e4SLinus Torvalds out:
53051da177e4SLinus Torvalds 	return status;
53061da177e4SLinus Torvalds }
53071da177e4SLinus Torvalds 
53081da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
53091da177e4SLinus Torvalds {
53101da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
53111da177e4SLinus Torvalds }
53121da177e4SLinus Torvalds 
531356ae19f3STrond Myklebust static int
531456ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
531556ae19f3STrond Myklebust {
531656ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
531756ae19f3STrond Myklebust }
531856ae19f3STrond Myklebust 
5319029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5320bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5321029d105eSJ. Bruce Fields {
5322256e48bbSTrond Myklebust 	unsigned int savep;
5323029d105eSJ. Bruce Fields 	uint32_t attrlen,
5324dae100c2SFred Isaman 		 bitmap[3] = {0};
5325029d105eSJ. Bruce Fields 	int status;
5326cff298c7STrond Myklebust 	unsigned int pg_offset;
5327029d105eSJ. Bruce Fields 
5328bf118a34SAndy Adamson 	res->acl_len = 0;
5329029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5330029d105eSJ. Bruce Fields 		goto out;
53315a006899SSachin Prabhu 
5332519d3959STrond Myklebust 	xdr_enter_page(xdr, xdr->buf->page_len);
5333519d3959STrond Myklebust 
5334cff298c7STrond Myklebust 	/* Calculate the offset of the page data */
5335cff298c7STrond Myklebust 	pg_offset = xdr->buf->head[0].iov_len;
53365a006899SSachin Prabhu 
5337029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5338029d105eSJ. Bruce Fields 		goto out;
5339029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5340029d105eSJ. Bruce Fields 		goto out;
5341029d105eSJ. Bruce Fields 
5342029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5343029d105eSJ. Bruce Fields 		return -EIO;
5344029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5345029d105eSJ. Bruce Fields 
5346bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5347bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5348bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5349cff298c7STrond Myklebust 		res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5350519d3959STrond Myklebust 		res->acl_len = attrlen;
53511f1ea6c2STrond Myklebust 
53521f1ea6c2STrond Myklebust 		/* Check for receive buffer overflow */
53531f1ea6c2STrond Myklebust 		if (res->acl_len > (xdr->nwords << 2) ||
53541f1ea6c2STrond Myklebust 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
53551f1ea6c2STrond Myklebust 			res->acl_flags |= NFS4_ACL_TRUNC;
5356519d3959STrond Myklebust 			dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5357cff298c7STrond Myklebust 					attrlen, xdr->nwords << 2);
5358029d105eSJ. Bruce Fields 		}
53598c233cf9SJ. Bruce Fields 	} else
53608c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5361029d105eSJ. Bruce Fields 
5362029d105eSJ. Bruce Fields out:
5363029d105eSJ. Bruce Fields 	return status;
5364029d105eSJ. Bruce Fields }
5365029d105eSJ. Bruce Fields 
53661da177e4SLinus Torvalds static int
53671da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
53681da177e4SLinus Torvalds {
53691da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
53701da177e4SLinus Torvalds }
53711da177e4SLinus Torvalds 
53729e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
53731da177e4SLinus Torvalds {
53748687b63aSAl Viro 	__be32 *p;
53751da177e4SLinus Torvalds 	uint32_t bmlen;
53761da177e4SLinus Torvalds 	int status;
53771da177e4SLinus Torvalds 
53781da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
53791da177e4SLinus Torvalds 	if (status)
53801da177e4SLinus Torvalds 		return status;
5381c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5382c0eae66eSBenny Halevy 	if (unlikely(!p))
5383c0eae66eSBenny Halevy 		goto out_overflow;
5384cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
5385c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5386c0eae66eSBenny Halevy 	if (likely(p))
53871da177e4SLinus Torvalds 		return 0;
5388c0eae66eSBenny Halevy out_overflow:
5389c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5390c0eae66eSBenny Halevy 	return -EIO;
53911da177e4SLinus Torvalds }
53921da177e4SLinus Torvalds 
5393bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
53941da177e4SLinus Torvalds {
53958687b63aSAl Viro 	__be32 *p;
53961da177e4SLinus Torvalds 	uint32_t opnum;
53971da177e4SLinus Torvalds 	int32_t nfserr;
53981da177e4SLinus Torvalds 
5399c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5400c0eae66eSBenny Halevy 	if (unlikely(!p))
5401c0eae66eSBenny Halevy 		goto out_overflow;
54026f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
54031da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5404fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
54051da177e4SLinus Torvalds 			" %d\n", opnum);
54061da177e4SLinus Torvalds 		return -EIO;
54071da177e4SLinus Torvalds 	}
5408cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
54091da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5410c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5411c0eae66eSBenny Halevy 		if (unlikely(!p))
5412c0eae66eSBenny Halevy 			goto out_overflow;
5413bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5414bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
54151da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
54161da177e4SLinus Torvalds 		uint32_t len;
54171da177e4SLinus Torvalds 
54181da177e4SLinus Torvalds 		/* skip netid string */
5419c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5420c0eae66eSBenny Halevy 		if (unlikely(!p))
5421c0eae66eSBenny Halevy 			goto out_overflow;
5422cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5423c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5424c0eae66eSBenny Halevy 		if (unlikely(!p))
5425c0eae66eSBenny Halevy 			goto out_overflow;
54261da177e4SLinus Torvalds 
54271da177e4SLinus Torvalds 		/* skip uaddr string */
5428c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5429c0eae66eSBenny Halevy 		if (unlikely(!p))
5430c0eae66eSBenny Halevy 			goto out_overflow;
5431cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5432c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5433c0eae66eSBenny Halevy 		if (unlikely(!p))
5434c0eae66eSBenny Halevy 			goto out_overflow;
54351da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
54361da177e4SLinus Torvalds 	} else
5437856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
54381da177e4SLinus Torvalds 
54391da177e4SLinus Torvalds 	return 0;
5440c0eae66eSBenny Halevy out_overflow:
5441c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5442c0eae66eSBenny Halevy 	return -EIO;
54431da177e4SLinus Torvalds }
54441da177e4SLinus Torvalds 
54451da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
54461da177e4SLinus Torvalds {
54471da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
54481da177e4SLinus Torvalds }
54491da177e4SLinus Torvalds 
54509137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
54511da177e4SLinus Torvalds {
54528687b63aSAl Viro 	__be32 *p;
54531da177e4SLinus Torvalds 	int status;
54541da177e4SLinus Torvalds 
54551da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
54561da177e4SLinus Torvalds 	if (status)
54571da177e4SLinus Torvalds 		return status;
54581da177e4SLinus Torvalds 
54592f2c63bcSTrond Myklebust 	p = xdr_inline_decode(xdr, 8);
5460c0eae66eSBenny Halevy 	if (unlikely(!p))
5461c0eae66eSBenny Halevy 		goto out_overflow;
54626f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
54636f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
54642f2c63bcSTrond Myklebust 	return decode_write_verifier(xdr, &res->verf->verifier);
5465c0eae66eSBenny Halevy out_overflow:
5466c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5467c0eae66eSBenny Halevy 	return -EIO;
54681da177e4SLinus Torvalds }
54691da177e4SLinus Torvalds 
54701da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
54711da177e4SLinus Torvalds {
54721da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
54731da177e4SLinus Torvalds }
54741da177e4SLinus Torvalds 
5475fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr,
5476fb15b26fSChuck Lever 			      struct nfs4_secinfo4 *flavor)
54775a5ea0d4SBryan Schumaker {
5478fb15b26fSChuck Lever 	u32 oid_len;
54795a5ea0d4SBryan Schumaker 	__be32 *p;
54805a5ea0d4SBryan Schumaker 
54815a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
54825a5ea0d4SBryan Schumaker 	if (unlikely(!p))
54835a5ea0d4SBryan Schumaker 		goto out_overflow;
5484fb15b26fSChuck Lever 	oid_len = be32_to_cpup(p);
5485fb15b26fSChuck Lever 	if (oid_len > GSS_OID_MAX_LEN)
54865a5ea0d4SBryan Schumaker 		goto out_err;
54875a5ea0d4SBryan Schumaker 
5488fb15b26fSChuck Lever 	p = xdr_inline_decode(xdr, oid_len);
54895a5ea0d4SBryan Schumaker 	if (unlikely(!p))
54905a5ea0d4SBryan Schumaker 		goto out_overflow;
5491fb15b26fSChuck Lever 	memcpy(flavor->flavor_info.oid.data, p, oid_len);
5492fb15b26fSChuck Lever 	flavor->flavor_info.oid.len = oid_len;
54935a5ea0d4SBryan Schumaker 
54945a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
54955a5ea0d4SBryan Schumaker 	if (unlikely(!p))
54965a5ea0d4SBryan Schumaker 		goto out_overflow;
5497fb15b26fSChuck Lever 	flavor->flavor_info.qop = be32_to_cpup(p++);
5498fb15b26fSChuck Lever 	flavor->flavor_info.service = be32_to_cpup(p);
54995a5ea0d4SBryan Schumaker 
55005a5ea0d4SBryan Schumaker 	return 0;
55015a5ea0d4SBryan Schumaker 
55025a5ea0d4SBryan Schumaker out_overflow:
55035a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
55045a5ea0d4SBryan Schumaker 	return -EIO;
55055a5ea0d4SBryan Schumaker out_err:
55065a5ea0d4SBryan Schumaker 	return -EINVAL;
55075a5ea0d4SBryan Schumaker }
55085a5ea0d4SBryan Schumaker 
550931e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
55105a5ea0d4SBryan Schumaker {
5511fb15b26fSChuck Lever 	struct nfs4_secinfo4 *sec_flavor;
5512fb15b26fSChuck Lever 	unsigned int i, num_flavors;
55135a5ea0d4SBryan Schumaker 	int status;
55145a5ea0d4SBryan Schumaker 	__be32 *p;
55155a5ea0d4SBryan Schumaker 
55165a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
55175a5ea0d4SBryan Schumaker 	if (unlikely(!p))
55185a5ea0d4SBryan Schumaker 		goto out_overflow;
55195a5ea0d4SBryan Schumaker 
5520c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5521c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5522c3dfc280SBryan Schumaker 
5523c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
55245a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5525c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
55265a5ea0d4SBryan Schumaker 			break;
55275a5ea0d4SBryan Schumaker 
55285a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
55295a5ea0d4SBryan Schumaker 		if (unlikely(!p))
55305a5ea0d4SBryan Schumaker 			goto out_overflow;
55315a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
55325a5ea0d4SBryan Schumaker 
55335a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5534613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5535613e901eSBryan Schumaker 			if (status)
5536613e901eSBryan Schumaker 				goto out;
55375a5ea0d4SBryan Schumaker 		}
5538c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
55395a5ea0d4SBryan Schumaker 	}
55405a5ea0d4SBryan Schumaker 
554131e4dda4SBryan Schumaker 	status = 0;
5542613e901eSBryan Schumaker out:
5543613e901eSBryan Schumaker 	return status;
55445a5ea0d4SBryan Schumaker out_overflow:
55455a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
55465a5ea0d4SBryan Schumaker 	return -EIO;
55475a5ea0d4SBryan Schumaker }
55485a5ea0d4SBryan Schumaker 
554931e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
555031e4dda4SBryan Schumaker {
555131e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO);
555231e4dda4SBryan Schumaker 	if (status)
555331e4dda4SBryan Schumaker 		return status;
555431e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
555531e4dda4SBryan Schumaker }
555631e4dda4SBryan Schumaker 
555799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
555831e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
555931e4dda4SBryan Schumaker {
556031e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
556131e4dda4SBryan Schumaker 	if (status)
556231e4dda4SBryan Schumaker 		return status;
556331e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
556431e4dda4SBryan Schumaker }
556531e4dda4SBryan Schumaker 
55662031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
55672031cd1aSWeston Andros Adamson {
55682031cd1aSWeston Andros Adamson 	__be32 *p;
55692031cd1aSWeston Andros Adamson 	uint32_t bitmap_words;
55702031cd1aSWeston Andros Adamson 	unsigned int i;
55712031cd1aSWeston Andros Adamson 
55722031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
55732031cd1aSWeston Andros Adamson 	bitmap_words = be32_to_cpup(p++);
55742031cd1aSWeston Andros Adamson 	if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
55752031cd1aSWeston Andros Adamson 		return -EIO;
55762031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4 * bitmap_words);
55772031cd1aSWeston Andros Adamson 	for (i = 0; i < bitmap_words; i++)
55782031cd1aSWeston Andros Adamson 		op_map->u.words[i] = be32_to_cpup(p++);
55792031cd1aSWeston Andros Adamson 
55802031cd1aSWeston Andros Adamson 	return 0;
55812031cd1aSWeston Andros Adamson }
55822031cd1aSWeston Andros Adamson 
558399fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
558499fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
558599fe60d0SBenny Halevy {
558699fe60d0SBenny Halevy 	__be32 *p;
558799fe60d0SBenny Halevy 	uint32_t dummy;
55882460ba57SBenny Halevy 	char *dummy_str;
558999fe60d0SBenny Halevy 	int status;
55907d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
559199fe60d0SBenny Halevy 
559299fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
559399fe60d0SBenny Halevy 	if (status)
559499fe60d0SBenny Halevy 		return status;
559599fe60d0SBenny Halevy 
5596c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5597c0eae66eSBenny Halevy 	if (unlikely(!p))
5598c0eae66eSBenny Halevy 		goto out_overflow;
559932b01310STrond Myklebust 	xdr_decode_hyper(p, &res->clientid);
5600c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5601c0eae66eSBenny Halevy 	if (unlikely(!p))
5602c0eae66eSBenny Halevy 		goto out_overflow;
560332b01310STrond Myklebust 	res->seqid = be32_to_cpup(p++);
560432b01310STrond Myklebust 	res->flags = be32_to_cpup(p++);
560599fe60d0SBenny Halevy 
56062031cd1aSWeston Andros Adamson 	res->state_protect.how = be32_to_cpup(p);
56072031cd1aSWeston Andros Adamson 	switch (res->state_protect.how) {
56082031cd1aSWeston Andros Adamson 	case SP4_NONE:
56092031cd1aSWeston Andros Adamson 		break;
56102031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
56112031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.enforce);
56122031cd1aSWeston Andros Adamson 		if (status)
56132031cd1aSWeston Andros Adamson 			return status;
56142031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.allow);
56152031cd1aSWeston Andros Adamson 		if (status)
56162031cd1aSWeston Andros Adamson 			return status;
56172031cd1aSWeston Andros Adamson 		break;
56182031cd1aSWeston Andros Adamson 	default:
56192031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
562099fe60d0SBenny Halevy 		return -EIO;
56212031cd1aSWeston Andros Adamson 	}
562299fe60d0SBenny Halevy 
5623acdeb69dSChuck Lever 	/* server_owner4.so_minor_id */
5624c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5625c0eae66eSBenny Halevy 	if (unlikely(!p))
5626c0eae66eSBenny Halevy 		goto out_overflow;
5627acdeb69dSChuck Lever 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
562899fe60d0SBenny Halevy 
5629acdeb69dSChuck Lever 	/* server_owner4.so_major_id */
56302460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
56312460ba57SBenny Halevy 	if (unlikely(status))
56322460ba57SBenny Halevy 		return status;
5633acdeb69dSChuck Lever 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5634acdeb69dSChuck Lever 	res->server_owner->major_id_sz = dummy;
563578fe0f41SWeston Andros Adamson 
5636acdeb69dSChuck Lever 	/* server_scope4 */
5637acdeb69dSChuck Lever 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5638acdeb69dSChuck Lever 	if (unlikely(status))
5639acdeb69dSChuck Lever 		return status;
564078fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
564178fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
564278fe0f41SWeston Andros Adamson 
56437d2ed9acSWeston Andros Adamson 	/* Implementation Id */
56447d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
56457d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
56467d2ed9acSWeston Andros Adamson 		goto out_overflow;
56477d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
56487d2ed9acSWeston Andros Adamson 
56497d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
56507d2ed9acSWeston Andros Adamson 		/* nii_domain */
56512460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
56522460ba57SBenny Halevy 		if (unlikely(status))
56532460ba57SBenny Halevy 			return status;
56547d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
565599fe60d0SBenny Halevy 
56567d2ed9acSWeston Andros Adamson 		/* nii_name */
56577d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
56587d2ed9acSWeston Andros Adamson 		if (unlikely(status))
56597d2ed9acSWeston Andros Adamson 			return status;
56607d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
56617d2ed9acSWeston Andros Adamson 
56627d2ed9acSWeston Andros Adamson 		/* nii_date */
56637d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
56647d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
56657d2ed9acSWeston Andros Adamson 			goto out_overflow;
56667d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
56677d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
56687d2ed9acSWeston Andros Adamson 
56697d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
56707d2ed9acSWeston Andros Adamson 	}
567199fe60d0SBenny Halevy 	return 0;
5672c0eae66eSBenny Halevy out_overflow:
5673c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5674c0eae66eSBenny Halevy 	return -EIO;
567599fe60d0SBenny Halevy }
5676fc931582SAndy Adamson 
5677fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5678fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5679fc931582SAndy Adamson {
5680fc931582SAndy Adamson 	__be32 *p;
5681c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5682fc931582SAndy Adamson 
5683c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5684c0eae66eSBenny Halevy 	if (unlikely(!p))
5685c0eae66eSBenny Halevy 		goto out_overflow;
5686c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5687c9c30dd5SBenny Halevy 	if (val)
5688c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
56896f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
56906f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
56916f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
56926f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
56936f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5694cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5695fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5696a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5697a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5698fc931582SAndy Adamson 		return -EINVAL;
5699fc931582SAndy Adamson 	}
5700c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5701c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5702c0eae66eSBenny Halevy 		if (unlikely(!p))
5703c0eae66eSBenny Halevy 			goto out_overflow;
5704c0eae66eSBenny Halevy 	}
5705fc931582SAndy Adamson 	return 0;
5706c0eae66eSBenny Halevy out_overflow:
5707c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5708c0eae66eSBenny Halevy 	return -EIO;
5709fc931582SAndy Adamson }
5710fc931582SAndy Adamson 
5711e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5712e78291e4SBenny Halevy {
5713e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5714fc931582SAndy Adamson }
5715fc931582SAndy Adamson 
57167c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
57177c44f1aeSWeston Andros Adamson 				struct nfs41_bind_conn_to_session_res *res)
57187c44f1aeSWeston Andros Adamson {
57197c44f1aeSWeston Andros Adamson 	__be32 *p;
57207c44f1aeSWeston Andros Adamson 	int status;
57217c44f1aeSWeston Andros Adamson 
57227c44f1aeSWeston Andros Adamson 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
57237c44f1aeSWeston Andros Adamson 	if (!status)
572471a097c6STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
57257c44f1aeSWeston Andros Adamson 	if (unlikely(status))
57267c44f1aeSWeston Andros Adamson 		return status;
57277c44f1aeSWeston Andros Adamson 
57287c44f1aeSWeston Andros Adamson 	/* dir flags, rdma mode bool */
57297c44f1aeSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 8);
57307c44f1aeSWeston Andros Adamson 	if (unlikely(!p))
57317c44f1aeSWeston Andros Adamson 		goto out_overflow;
57327c44f1aeSWeston Andros Adamson 
57337c44f1aeSWeston Andros Adamson 	res->dir = be32_to_cpup(p++);
57347c44f1aeSWeston Andros Adamson 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
57357c44f1aeSWeston Andros Adamson 		return -EIO;
57367c44f1aeSWeston Andros Adamson 	if (be32_to_cpup(p) == 0)
57377c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = false;
57387c44f1aeSWeston Andros Adamson 	else
57397c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = true;
57407c44f1aeSWeston Andros Adamson 
57417c44f1aeSWeston Andros Adamson 	return 0;
57427c44f1aeSWeston Andros Adamson out_overflow:
57437c44f1aeSWeston Andros Adamson 	print_overflow_msg(__func__, xdr);
57447c44f1aeSWeston Andros Adamson 	return -EIO;
57457c44f1aeSWeston Andros Adamson }
57467c44f1aeSWeston Andros Adamson 
5747fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5748fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5749fc931582SAndy Adamson {
5750fc931582SAndy Adamson 	__be32 *p;
5751fc931582SAndy Adamson 	int status;
5752fc931582SAndy Adamson 
5753fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5754e78291e4SBenny Halevy 	if (!status)
575579969dd1STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
5756e78291e4SBenny Halevy 	if (unlikely(status))
5757fc931582SAndy Adamson 		return status;
5758fc931582SAndy Adamson 
5759fc931582SAndy Adamson 	/* seqid, flags */
5760c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5761c0eae66eSBenny Halevy 	if (unlikely(!p))
5762c0eae66eSBenny Halevy 		goto out_overflow;
576379969dd1STrond Myklebust 	res->seqid = be32_to_cpup(p++);
576479969dd1STrond Myklebust 	res->flags = be32_to_cpup(p);
5765fc931582SAndy Adamson 
5766fc931582SAndy Adamson 	/* Channel attributes */
576779969dd1STrond Myklebust 	status = decode_chan_attrs(xdr, &res->fc_attrs);
5768fc931582SAndy Adamson 	if (!status)
576979969dd1STrond Myklebust 		status = decode_chan_attrs(xdr, &res->bc_attrs);
5770fc931582SAndy Adamson 	return status;
5771c0eae66eSBenny Halevy out_overflow:
5772c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5773c0eae66eSBenny Halevy 	return -EIO;
5774fc931582SAndy Adamson }
57750f3e66c6SAndy Adamson 
57760f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
57770f3e66c6SAndy Adamson {
57780f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
57790f3e66c6SAndy Adamson }
578018019753SRicardo Labiaga 
578166245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
578266245539STrond Myklebust {
578366245539STrond Myklebust 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
578466245539STrond Myklebust }
578566245539STrond Myklebust 
578618019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
578718019753SRicardo Labiaga {
578818019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
578918019753SRicardo Labiaga }
579099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
579199fe60d0SBenny Halevy 
57929b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
57939b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
57949b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
57959b7b9fccSAndy Adamson {
57969b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5797e3725ec0STrond Myklebust 	struct nfs4_session *session;
5798fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5799fc01cea9SAndy Adamson 	u32 dummy;
5800fc01cea9SAndy Adamson 	int status;
5801fc01cea9SAndy Adamson 	__be32 *p;
5802fc01cea9SAndy Adamson 
5803e3725ec0STrond Myklebust 	if (res->sr_slot == NULL)
58049b7b9fccSAndy Adamson 		return 0;
58053bd2384aSChuck Lever 	if (!res->sr_slot->table->session)
58063bd2384aSChuck Lever 		return 0;
58079b7b9fccSAndy Adamson 
5808fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5809e78291e4SBenny Halevy 	if (!status)
5810e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5811e78291e4SBenny Halevy 	if (unlikely(status))
5812fc01cea9SAndy Adamson 		goto out_err;
58139b7b9fccSAndy Adamson 
5814fc01cea9SAndy Adamson 	/*
5815fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5816fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5817fc01cea9SAndy Adamson 	 */
5818fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5819e3725ec0STrond Myklebust 	session = res->sr_slot->table->session;
5820fc01cea9SAndy Adamson 
5821e3725ec0STrond Myklebust 	if (memcmp(id.data, session->sess_id.data,
5822fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5823fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5824fc01cea9SAndy Adamson 		goto out_err;
5825fc01cea9SAndy Adamson 	}
5826e78291e4SBenny Halevy 
5827c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5828c0eae66eSBenny Halevy 	if (unlikely(!p))
5829c0eae66eSBenny Halevy 		goto out_overflow;
5830e78291e4SBenny Halevy 
5831fc01cea9SAndy Adamson 	/* seqid */
58326f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5833dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5834fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5835fc01cea9SAndy Adamson 		goto out_err;
5836fc01cea9SAndy Adamson 	}
5837fc01cea9SAndy Adamson 	/* slot id */
58386f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5839df2fabffSTrond Myklebust 	if (dummy != res->sr_slot->slot_nr) {
5840fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5841fc01cea9SAndy Adamson 		goto out_err;
5842fc01cea9SAndy Adamson 	}
5843da0507b7STrond Myklebust 	/* highest slot id */
5844da0507b7STrond Myklebust 	res->sr_highest_slotid = be32_to_cpup(p++);
5845464ee9f9STrond Myklebust 	/* target highest slot id */
5846464ee9f9STrond Myklebust 	res->sr_target_highest_slotid = be32_to_cpup(p++);
58470629e370SAlexandros Batsakis 	/* result flags */
58480629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5849fc01cea9SAndy Adamson 	status = 0;
5850fc01cea9SAndy Adamson out_err:
5851fc01cea9SAndy Adamson 	res->sr_status = status;
5852fc01cea9SAndy Adamson 	return status;
5853c0eae66eSBenny Halevy out_overflow:
5854c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5855c0eae66eSBenny Halevy 	status = -EIO;
5856c0eae66eSBenny Halevy 	goto out_err;
5857fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
58589b7b9fccSAndy Adamson 	return 0;
5859fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
58609b7b9fccSAndy Adamson }
58619b7b9fccSAndy Adamson 
5862b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
586393b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
586493b717fdSTrond Myklebust {
586593b717fdSTrond Myklebust 	stateid->type = NFS4_LAYOUT_STATEID_TYPE;
586693b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
586793b717fdSTrond Myklebust }
586893b717fdSTrond Myklebust 
5869b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
58704e590803STrond Myklebust 				struct nfs4_getdeviceinfo_res *res)
5871b1f69b75SAndy Adamson {
58724e590803STrond Myklebust 	struct pnfs_device *pdev = res->pdev;
5873b1f69b75SAndy Adamson 	__be32 *p;
5874b1f69b75SAndy Adamson 	uint32_t len, type;
5875b1f69b75SAndy Adamson 	int status;
5876b1f69b75SAndy Adamson 
5877b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5878b1f69b75SAndy Adamson 	if (status) {
5879b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5880b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5881b1f69b75SAndy Adamson 			if (unlikely(!p))
5882b1f69b75SAndy Adamson 				goto out_overflow;
5883b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5884b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5885b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5886b1f69b75SAndy Adamson 		}
5887b1f69b75SAndy Adamson 		return status;
5888b1f69b75SAndy Adamson 	}
5889b1f69b75SAndy Adamson 
5890b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5891b1f69b75SAndy Adamson 	if (unlikely(!p))
5892b1f69b75SAndy Adamson 		goto out_overflow;
5893b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5894b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5895b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5896b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5897b1f69b75SAndy Adamson 		return -EINVAL;
5898b1f69b75SAndy Adamson 	}
5899b1f69b75SAndy Adamson 	/*
5900b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5901b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5902b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5903b1f69b75SAndy Adamson 	 */
5904b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
590513fe4ba1STrond Myklebust 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
590613fe4ba1STrond Myklebust 		goto out_overflow;
5907b1f69b75SAndy Adamson 
5908b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5909b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5910b1f69b75SAndy Adamson 	if (unlikely(!p))
5911b1f69b75SAndy Adamson 		goto out_overflow;
5912b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5913b1f69b75SAndy Adamson 	if (len) {
5914ead00597SChuck Lever 		uint32_t i;
5915b1f69b75SAndy Adamson 
5916b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5917b1f69b75SAndy Adamson 		if (unlikely(!p))
5918b1f69b75SAndy Adamson 			goto out_overflow;
591984c9dee3SChristoph Hellwig 
59204e590803STrond Myklebust 		res->notification = be32_to_cpup(p++);
592184c9dee3SChristoph Hellwig 		for (i = 1; i < len; i++) {
592284c9dee3SChristoph Hellwig 			if (be32_to_cpup(p++)) {
592384c9dee3SChristoph Hellwig 				dprintk("%s: unsupported notification\n",
5924b1f69b75SAndy Adamson 					__func__);
5925b1f69b75SAndy Adamson 				return -EIO;
5926b1f69b75SAndy Adamson 			}
5927b1f69b75SAndy Adamson 		}
5928b1f69b75SAndy Adamson 	}
5929b1f69b75SAndy Adamson 	return 0;
5930b1f69b75SAndy Adamson out_overflow:
5931b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5932b1f69b75SAndy Adamson 	return -EIO;
5933b1f69b75SAndy Adamson }
5934b1f69b75SAndy Adamson 
5935b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5936b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5937b1f69b75SAndy Adamson {
5938b1f69b75SAndy Adamson 	__be32 *p;
5939b1f69b75SAndy Adamson 	int status;
5940b1f69b75SAndy Adamson 	u32 layout_count;
594164bd577eSTrond Myklebust 	u32 recvd;
5942b1f69b75SAndy Adamson 
5943b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5944b1f69b75SAndy Adamson 	if (status)
5945b1f69b75SAndy Adamson 		return status;
5946ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5947b1f69b75SAndy Adamson 	if (unlikely(!p))
5948b1f69b75SAndy Adamson 		goto out_overflow;
5949ea9d23f5STrond Myklebust 	res->return_on_close = be32_to_cpup(p);
595093b717fdSTrond Myklebust 	decode_layout_stateid(xdr, &res->stateid);
5951ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5952ea9d23f5STrond Myklebust 	if (unlikely(!p))
5953ea9d23f5STrond Myklebust 		goto out_overflow;
5954b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5955b1f69b75SAndy Adamson 	if (!layout_count) {
5956b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5957b1f69b75SAndy Adamson 			__func__);
5958b1f69b75SAndy Adamson 		return -EINVAL;
5959b1f69b75SAndy Adamson 	}
5960b1f69b75SAndy Adamson 
596135124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5962b1f69b75SAndy Adamson 	if (unlikely(!p))
5963b1f69b75SAndy Adamson 		goto out_overflow;
5964b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5965b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5966b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5967b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
596835124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5969b1f69b75SAndy Adamson 
5970b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5971b1f69b75SAndy Adamson 		__func__,
5972b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5973b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5974b1f69b75SAndy Adamson 		res->range.iomode,
5975b1f69b75SAndy Adamson 		res->type,
597635124a09SWeston Andros Adamson 		res->layoutp->len);
5977b1f69b75SAndy Adamson 
597864bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, res->layoutp->len);
597935124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
598035124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
598135124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
598235124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
598335124a09SWeston Andros Adamson 		return -EINVAL;
598435124a09SWeston Andros Adamson 	}
598535124a09SWeston Andros Adamson 
5986b1f69b75SAndy Adamson 	if (layout_count > 1) {
5987b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5988b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5989b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5990b1f69b75SAndy Adamson 		 * minimum it requested.
5991b1f69b75SAndy Adamson 		 */
5992b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5993b1f69b75SAndy Adamson 			__func__, layout_count);
5994b1f69b75SAndy Adamson 	}
5995b1f69b75SAndy Adamson 
5996b1f69b75SAndy Adamson 	return 0;
5997b1f69b75SAndy Adamson out_overflow:
5998b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5999b1f69b75SAndy Adamson 	return -EIO;
6000b1f69b75SAndy Adamson }
6001863a3c6cSAndy Adamson 
6002cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
6003cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
6004cbe82603SBenny Halevy {
6005cbe82603SBenny Halevy 	__be32 *p;
6006cbe82603SBenny Halevy 	int status;
6007cbe82603SBenny Halevy 
6008cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6009cbe82603SBenny Halevy 	if (status)
6010cbe82603SBenny Halevy 		return status;
6011cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
6012cbe82603SBenny Halevy 	if (unlikely(!p))
6013cbe82603SBenny Halevy 		goto out_overflow;
6014cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
6015cbe82603SBenny Halevy 	if (res->lrs_present)
601693b717fdSTrond Myklebust 		status = decode_layout_stateid(xdr, &res->stateid);
6017cbe82603SBenny Halevy 	return status;
6018cbe82603SBenny Halevy out_overflow:
6019cbe82603SBenny Halevy 	print_overflow_msg(__func__, xdr);
6020cbe82603SBenny Halevy 	return -EIO;
6021cbe82603SBenny Halevy }
6022cbe82603SBenny Halevy 
6023863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
6024863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
6025863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
6026863a3c6cSAndy Adamson {
6027863a3c6cSAndy Adamson 	__be32 *p;
6028863a3c6cSAndy Adamson 	__u32 sizechanged;
6029863a3c6cSAndy Adamson 	int status;
6030863a3c6cSAndy Adamson 
6031863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
6032db29c089SAndy Adamson 	res->status = status;
6033863a3c6cSAndy Adamson 	if (status)
6034863a3c6cSAndy Adamson 		return status;
6035863a3c6cSAndy Adamson 
6036863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
6037863a3c6cSAndy Adamson 	if (unlikely(!p))
6038863a3c6cSAndy Adamson 		goto out_overflow;
6039863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
6040863a3c6cSAndy Adamson 
6041863a3c6cSAndy Adamson 	if (sizechanged) {
6042863a3c6cSAndy Adamson 		/* throw away new size */
6043863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
6044863a3c6cSAndy Adamson 		if (unlikely(!p))
6045863a3c6cSAndy Adamson 			goto out_overflow;
6046863a3c6cSAndy Adamson 	}
6047863a3c6cSAndy Adamson 	return 0;
6048863a3c6cSAndy Adamson out_overflow:
6049863a3c6cSAndy Adamson 	print_overflow_msg(__func__, xdr);
6050863a3c6cSAndy Adamson 	return -EIO;
6051863a3c6cSAndy Adamson }
60527d974794SBryan Schumaker 
60537d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
60547d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
60557d974794SBryan Schumaker {
60567d974794SBryan Schumaker 	__be32 *p;
60577d974794SBryan Schumaker 	int status;
60587d974794SBryan Schumaker 	int num_res;
60597d974794SBryan Schumaker 
60607d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
60617d974794SBryan Schumaker 	if (status)
60627d974794SBryan Schumaker 		return status;
60637d974794SBryan Schumaker 
60647d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
60657d974794SBryan Schumaker 	if (unlikely(!p))
60667d974794SBryan Schumaker 		goto out_overflow;
60677d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
60687d974794SBryan Schumaker 	if (num_res != 1)
60697d974794SBryan Schumaker 		goto out;
60707d974794SBryan Schumaker 
60717d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
60727d974794SBryan Schumaker 	if (unlikely(!p))
60737d974794SBryan Schumaker 		goto out_overflow;
60747d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
60751cab0652SBryan Schumaker 
60761cab0652SBryan Schumaker 	return status;
60777d974794SBryan Schumaker out_overflow:
60787d974794SBryan Schumaker 	print_overflow_msg(__func__, xdr);
60797d974794SBryan Schumaker out:
60807d974794SBryan Schumaker 	return -EIO;
60817d974794SBryan Schumaker }
60829aeda35fSBryan Schumaker 
60839aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
60849aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
60859aeda35fSBryan Schumaker {
60869f79fb48SAndy Adamson 	res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
60879aeda35fSBryan Schumaker 	return res->status;
60889aeda35fSBryan Schumaker }
6089cf805165STrond Myklebust #else
6090cf805165STrond Myklebust static inline
6091cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr,
6092cf805165STrond Myklebust 			       struct nfs4_layoutreturn_res *res)
6093cf805165STrond Myklebust {
6094cf805165STrond Myklebust 	return 0;
6095cf805165STrond Myklebust }
6096b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
6097b1f69b75SAndy Adamson 
60981da177e4SLinus Torvalds /*
609949c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
610049c2559eSBenny Halevy  */
610149c2559eSBenny Halevy 
610249c2559eSBenny Halevy /*
61031da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
61041da177e4SLinus Torvalds  */
6105bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6106bf269551SChuck Lever 				       struct xdr_stream *xdr,
6107bf269551SChuck Lever 				       struct nfs_closeres *res)
61081da177e4SLinus Torvalds {
61091da177e4SLinus Torvalds 	struct compound_hdr hdr;
61101da177e4SLinus Torvalds 	int status;
61111da177e4SLinus Torvalds 
6112bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61131da177e4SLinus Torvalds 	if (status)
61141da177e4SLinus Torvalds 		goto out;
6115bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61169b7b9fccSAndy Adamson 	if (status)
61179b7b9fccSAndy Adamson 		goto out;
6118bf269551SChuck Lever 	status = decode_putfh(xdr);
61191da177e4SLinus Torvalds 	if (status)
61201da177e4SLinus Torvalds 		goto out;
6121b6808145STrond Myklebust 	if (res->lr_res) {
6122b6808145STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6123b6808145STrond Myklebust 		res->lr_ret = status;
6124b6808145STrond Myklebust 		if (status)
6125b6808145STrond Myklebust 			goto out;
6126b6808145STrond Myklebust 	}
6127bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
61281da177e4SLinus Torvalds out:
61291da177e4SLinus Torvalds 	return status;
61301da177e4SLinus Torvalds }
61311da177e4SLinus Torvalds 
61321da177e4SLinus Torvalds /*
61331da177e4SLinus Torvalds  * Decode ACCESS response
61341da177e4SLinus Torvalds  */
6135bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6136bf269551SChuck Lever 			       struct nfs4_accessres *res)
61371da177e4SLinus Torvalds {
61381da177e4SLinus Torvalds 	struct compound_hdr hdr;
61391da177e4SLinus Torvalds 	int status;
61401da177e4SLinus Torvalds 
6141bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61429b7b9fccSAndy Adamson 	if (status)
61439b7b9fccSAndy Adamson 		goto out;
6144bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61459b7b9fccSAndy Adamson 	if (status)
61461da177e4SLinus Torvalds 		goto out;
6147bf269551SChuck Lever 	status = decode_putfh(xdr);
614876b32999STrond Myklebust 	if (status != 0)
614976b32999STrond Myklebust 		goto out;
61506168f62cSWeston Andros Adamson 	status = decode_access(xdr, &res->supported, &res->access);
615176b32999STrond Myklebust 	if (status != 0)
615276b32999STrond Myklebust 		goto out;
61536926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
61541da177e4SLinus Torvalds out:
61551da177e4SLinus Torvalds 	return status;
61561da177e4SLinus Torvalds }
61571da177e4SLinus Torvalds 
61581da177e4SLinus Torvalds /*
61591da177e4SLinus Torvalds  * Decode LOOKUP response
61601da177e4SLinus Torvalds  */
6161bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6162bf269551SChuck Lever 			       struct nfs4_lookup_res *res)
61631da177e4SLinus Torvalds {
61641da177e4SLinus Torvalds 	struct compound_hdr hdr;
61651da177e4SLinus Torvalds 	int status;
61661da177e4SLinus Torvalds 
6167bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61689b7b9fccSAndy Adamson 	if (status)
61699b7b9fccSAndy Adamson 		goto out;
6170bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61719b7b9fccSAndy Adamson 	if (status)
61721da177e4SLinus Torvalds 		goto out;
6173bf269551SChuck Lever 	status = decode_putfh(xdr);
6174bf269551SChuck Lever 	if (status)
61751da177e4SLinus Torvalds 		goto out;
6176bf269551SChuck Lever 	status = decode_lookup(xdr);
6177bf269551SChuck Lever 	if (status)
61781da177e4SLinus Torvalds 		goto out;
6179bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6180bf269551SChuck Lever 	if (status)
61811da177e4SLinus Torvalds 		goto out;
6182aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
61831da177e4SLinus Torvalds out:
61841da177e4SLinus Torvalds 	return status;
61851da177e4SLinus Torvalds }
61861da177e4SLinus Torvalds 
61871da177e4SLinus Torvalds /*
61881da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
61891da177e4SLinus Torvalds  */
6190bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6191bf269551SChuck Lever 				    struct xdr_stream *xdr,
6192bf269551SChuck Lever 				    struct nfs4_lookup_res *res)
61931da177e4SLinus Torvalds {
61941da177e4SLinus Torvalds 	struct compound_hdr hdr;
61951da177e4SLinus Torvalds 	int status;
61961da177e4SLinus Torvalds 
6197bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61989b7b9fccSAndy Adamson 	if (status)
61999b7b9fccSAndy Adamson 		goto out;
6200bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62019b7b9fccSAndy Adamson 	if (status)
62021da177e4SLinus Torvalds 		goto out;
6203bf269551SChuck Lever 	status = decode_putrootfh(xdr);
6204bf269551SChuck Lever 	if (status)
62051da177e4SLinus Torvalds 		goto out;
6206bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6207bf269551SChuck Lever 	if (status == 0)
6208aa9c2669SDavid Quigley 		status = decode_getfattr_label(xdr, res->fattr,
6209aa9c2669SDavid Quigley 						res->label, res->server);
62101da177e4SLinus Torvalds out:
62111da177e4SLinus Torvalds 	return status;
62121da177e4SLinus Torvalds }
62131da177e4SLinus Torvalds 
62141da177e4SLinus Torvalds /*
62151da177e4SLinus Torvalds  * Decode REMOVE response
62161da177e4SLinus Torvalds  */
6217bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6218bf269551SChuck Lever 			       struct nfs_removeres *res)
62191da177e4SLinus Torvalds {
62201da177e4SLinus Torvalds 	struct compound_hdr hdr;
62211da177e4SLinus Torvalds 	int status;
62221da177e4SLinus Torvalds 
6223bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62249b7b9fccSAndy Adamson 	if (status)
62259b7b9fccSAndy Adamson 		goto out;
6226bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62279b7b9fccSAndy Adamson 	if (status)
62281da177e4SLinus Torvalds 		goto out;
6229bf269551SChuck Lever 	status = decode_putfh(xdr);
6230bf269551SChuck Lever 	if (status)
623116e42959STrond Myklebust 		goto out;
6232bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
62331da177e4SLinus Torvalds out:
62341da177e4SLinus Torvalds 	return status;
62351da177e4SLinus Torvalds }
62361da177e4SLinus Torvalds 
62371da177e4SLinus Torvalds /*
62381da177e4SLinus Torvalds  * Decode RENAME response
62391da177e4SLinus Torvalds  */
6240bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6241bf269551SChuck Lever 			       struct nfs_renameres *res)
62421da177e4SLinus Torvalds {
62431da177e4SLinus Torvalds 	struct compound_hdr hdr;
62441da177e4SLinus Torvalds 	int status;
62451da177e4SLinus Torvalds 
6246bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62479b7b9fccSAndy Adamson 	if (status)
62489b7b9fccSAndy Adamson 		goto out;
6249bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62509b7b9fccSAndy Adamson 	if (status)
62511da177e4SLinus Torvalds 		goto out;
6252bf269551SChuck Lever 	status = decode_putfh(xdr);
6253bf269551SChuck Lever 	if (status)
62541da177e4SLinus Torvalds 		goto out;
6255bf269551SChuck Lever 	status = decode_savefh(xdr);
6256bf269551SChuck Lever 	if (status)
62571da177e4SLinus Torvalds 		goto out;
6258bf269551SChuck Lever 	status = decode_putfh(xdr);
6259bf269551SChuck Lever 	if (status)
62601da177e4SLinus Torvalds 		goto out;
6261bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
62621da177e4SLinus Torvalds out:
62631da177e4SLinus Torvalds 	return status;
62641da177e4SLinus Torvalds }
62651da177e4SLinus Torvalds 
62661da177e4SLinus Torvalds /*
62671da177e4SLinus Torvalds  * Decode LINK response
62681da177e4SLinus Torvalds  */
6269bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6270bf269551SChuck Lever 			     struct nfs4_link_res *res)
62711da177e4SLinus Torvalds {
62721da177e4SLinus Torvalds 	struct compound_hdr hdr;
62731da177e4SLinus Torvalds 	int status;
62741da177e4SLinus Torvalds 
6275bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62769b7b9fccSAndy Adamson 	if (status)
62779b7b9fccSAndy Adamson 		goto out;
6278bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62799b7b9fccSAndy Adamson 	if (status)
62801da177e4SLinus Torvalds 		goto out;
6281bf269551SChuck Lever 	status = decode_putfh(xdr);
6282bf269551SChuck Lever 	if (status)
62831da177e4SLinus Torvalds 		goto out;
6284bf269551SChuck Lever 	status = decode_savefh(xdr);
6285bf269551SChuck Lever 	if (status)
62861da177e4SLinus Torvalds 		goto out;
6287bf269551SChuck Lever 	status = decode_putfh(xdr);
6288bf269551SChuck Lever 	if (status)
62891da177e4SLinus Torvalds 		goto out;
6290bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
6291bf269551SChuck Lever 	if (status)
629291ba2eeeSTrond Myklebust 		goto out;
629391ba2eeeSTrond Myklebust 	/*
629491ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
629591ba2eeeSTrond Myklebust 	 *             filehandle.
629691ba2eeeSTrond Myklebust 	 */
6297bf269551SChuck Lever 	status = decode_restorefh(xdr);
6298bf269551SChuck Lever 	if (status)
629991ba2eeeSTrond Myklebust 		goto out;
6300aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63011da177e4SLinus Torvalds out:
63021da177e4SLinus Torvalds 	return status;
63031da177e4SLinus Torvalds }
63041da177e4SLinus Torvalds 
63051da177e4SLinus Torvalds /*
63061da177e4SLinus Torvalds  * Decode CREATE response
63071da177e4SLinus Torvalds  */
6308bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6309bf269551SChuck Lever 			       struct nfs4_create_res *res)
63101da177e4SLinus Torvalds {
63111da177e4SLinus Torvalds 	struct compound_hdr hdr;
63121da177e4SLinus Torvalds 	int status;
63131da177e4SLinus Torvalds 
6314bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63159b7b9fccSAndy Adamson 	if (status)
63169b7b9fccSAndy Adamson 		goto out;
6317bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63189b7b9fccSAndy Adamson 	if (status)
63191da177e4SLinus Torvalds 		goto out;
6320bf269551SChuck Lever 	status = decode_putfh(xdr);
6321bf269551SChuck Lever 	if (status)
63221da177e4SLinus Torvalds 		goto out;
6323bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6324bf269551SChuck Lever 	if (status)
63251da177e4SLinus Torvalds 		goto out;
6326bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6327bf269551SChuck Lever 	if (status)
63281da177e4SLinus Torvalds 		goto out;
6329aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63301da177e4SLinus Torvalds out:
63311da177e4SLinus Torvalds 	return status;
63321da177e4SLinus Torvalds }
63331da177e4SLinus Torvalds 
63341da177e4SLinus Torvalds /*
63351da177e4SLinus Torvalds  * Decode SYMLINK response
63361da177e4SLinus Torvalds  */
6337bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6338bf269551SChuck Lever 				struct nfs4_create_res *res)
63391da177e4SLinus Torvalds {
6340bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
63411da177e4SLinus Torvalds }
63421da177e4SLinus Torvalds 
63431da177e4SLinus Torvalds /*
63441da177e4SLinus Torvalds  * Decode GETATTR response
63451da177e4SLinus Torvalds  */
6346bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6347bf269551SChuck Lever 				struct nfs4_getattr_res *res)
63481da177e4SLinus Torvalds {
63491da177e4SLinus Torvalds 	struct compound_hdr hdr;
63501da177e4SLinus Torvalds 	int status;
63511da177e4SLinus Torvalds 
6352bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63531da177e4SLinus Torvalds 	if (status)
63541da177e4SLinus Torvalds 		goto out;
6355bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63569b7b9fccSAndy Adamson 	if (status)
63579b7b9fccSAndy Adamson 		goto out;
6358bf269551SChuck Lever 	status = decode_putfh(xdr);
63591da177e4SLinus Torvalds 	if (status)
63601da177e4SLinus Torvalds 		goto out;
6361aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63621da177e4SLinus Torvalds out:
63631da177e4SLinus Torvalds 	return status;
63641da177e4SLinus Torvalds }
63651da177e4SLinus Torvalds 
636623ec6965SJ. Bruce Fields /*
636723ec6965SJ. Bruce Fields  * Encode an SETACL request
636823ec6965SJ. Bruce Fields  */
63699f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
63709f06c719SChuck Lever 				struct nfs_setaclargs *args)
637123ec6965SJ. Bruce Fields {
637223ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
637366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
637423ec6965SJ. Bruce Fields 	};
637523ec6965SJ. Bruce Fields 
63769f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
63779f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
63789f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
63799f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6380d017931cSAndy Adamson 	encode_nops(&hdr);
638123ec6965SJ. Bruce Fields }
638205d564feSAndy Adamson 
638323ec6965SJ. Bruce Fields /*
638423ec6965SJ. Bruce Fields  * Decode SETACL response
638523ec6965SJ. Bruce Fields  */
638623ec6965SJ. Bruce Fields static int
6387bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
638873c403a9SBenny Halevy 		    struct nfs_setaclres *res)
638923ec6965SJ. Bruce Fields {
639023ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
639123ec6965SJ. Bruce Fields 	int status;
639223ec6965SJ. Bruce Fields 
6393bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
639423ec6965SJ. Bruce Fields 	if (status)
639523ec6965SJ. Bruce Fields 		goto out;
6396bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63979b7b9fccSAndy Adamson 	if (status)
63989b7b9fccSAndy Adamson 		goto out;
6399bf269551SChuck Lever 	status = decode_putfh(xdr);
640023ec6965SJ. Bruce Fields 	if (status)
640123ec6965SJ. Bruce Fields 		goto out;
6402bf269551SChuck Lever 	status = decode_setattr(xdr);
640323ec6965SJ. Bruce Fields out:
640423ec6965SJ. Bruce Fields 	return status;
640523ec6965SJ. Bruce Fields }
64061da177e4SLinus Torvalds 
64071da177e4SLinus Torvalds /*
6408029d105eSJ. Bruce Fields  * Decode GETACL response
6409029d105eSJ. Bruce Fields  */
6410029d105eSJ. Bruce Fields static int
6411bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6412663c79b3SBenny Halevy 		    struct nfs_getaclres *res)
6413029d105eSJ. Bruce Fields {
6414029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6415029d105eSJ. Bruce Fields 	int status;
6416029d105eSJ. Bruce Fields 
6417331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6418331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6419331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6420331818f1STrond Myklebust 	}
6421bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6422029d105eSJ. Bruce Fields 	if (status)
6423029d105eSJ. Bruce Fields 		goto out;
6424bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64259b7b9fccSAndy Adamson 	if (status)
64269b7b9fccSAndy Adamson 		goto out;
6427bf269551SChuck Lever 	status = decode_putfh(xdr);
6428029d105eSJ. Bruce Fields 	if (status)
6429029d105eSJ. Bruce Fields 		goto out;
6430bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6431029d105eSJ. Bruce Fields 
6432029d105eSJ. Bruce Fields out:
6433029d105eSJ. Bruce Fields 	return status;
6434029d105eSJ. Bruce Fields }
6435029d105eSJ. Bruce Fields 
6436029d105eSJ. Bruce Fields /*
64371da177e4SLinus Torvalds  * Decode CLOSE response
64381da177e4SLinus Torvalds  */
6439bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6440bf269551SChuck Lever 			      struct nfs_closeres *res)
64411da177e4SLinus Torvalds {
64421da177e4SLinus Torvalds 	struct compound_hdr hdr;
64431da177e4SLinus Torvalds 	int status;
64441da177e4SLinus Torvalds 
6445bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64461da177e4SLinus Torvalds 	if (status)
64471da177e4SLinus Torvalds 		goto out;
6448bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64499b7b9fccSAndy Adamson 	if (status)
64509b7b9fccSAndy Adamson 		goto out;
6451bf269551SChuck Lever 	status = decode_putfh(xdr);
64521da177e4SLinus Torvalds 	if (status)
64531da177e4SLinus Torvalds 		goto out;
6454cf805165STrond Myklebust 	if (res->lr_res) {
6455cf805165STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6456cf805165STrond Myklebust 		res->lr_ret = status;
6457cf805165STrond Myklebust 		if (status)
6458cf805165STrond Myklebust 			goto out;
6459cf805165STrond Myklebust 	}
6460d8d84983STrond Myklebust 	if (res->fattr != NULL) {
6461d8d84983STrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
6462516a6af6STrond Myklebust 		if (status != 0)
6463516a6af6STrond Myklebust 			goto out;
6464d8d84983STrond Myklebust 	}
6465d8d84983STrond Myklebust 	status = decode_close(xdr, res);
64661da177e4SLinus Torvalds out:
64671da177e4SLinus Torvalds 	return status;
64681da177e4SLinus Torvalds }
64691da177e4SLinus Torvalds 
64701da177e4SLinus Torvalds /*
64711da177e4SLinus Torvalds  * Decode OPEN response
64721da177e4SLinus Torvalds  */
6473bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6474bf269551SChuck Lever 			     struct nfs_openres *res)
64751da177e4SLinus Torvalds {
64761da177e4SLinus Torvalds 	struct compound_hdr hdr;
64771da177e4SLinus Torvalds 	int status;
64781da177e4SLinus Torvalds 
6479bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64801da177e4SLinus Torvalds 	if (status)
64811da177e4SLinus Torvalds 		goto out;
6482bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64839b7b9fccSAndy Adamson 	if (status)
64849b7b9fccSAndy Adamson 		goto out;
6485bf269551SChuck Lever 	status = decode_putfh(xdr);
64861da177e4SLinus Torvalds 	if (status)
64871da177e4SLinus Torvalds 		goto out;
6488bf269551SChuck Lever 	status = decode_open(xdr, res);
64891da177e4SLinus Torvalds 	if (status)
64901da177e4SLinus Torvalds 		goto out;
649101913b49SWeston Andros Adamson 	status = decode_getfh(xdr, &res->fh);
649201913b49SWeston Andros Adamson 	if (status)
64931da177e4SLinus Torvalds 		goto out;
6494ae2bb032SWeston Andros Adamson 	if (res->access_request)
64956168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
6496aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
64971da177e4SLinus Torvalds out:
64981da177e4SLinus Torvalds 	return status;
64991da177e4SLinus Torvalds }
65001da177e4SLinus Torvalds 
65011da177e4SLinus Torvalds /*
65021da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
65031da177e4SLinus Torvalds  */
6504bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6505bf269551SChuck Lever 				     struct xdr_stream *xdr,
6506bf269551SChuck Lever 				     struct nfs_open_confirmres *res)
65071da177e4SLinus Torvalds {
65081da177e4SLinus Torvalds 	struct compound_hdr hdr;
65091da177e4SLinus Torvalds 	int status;
65101da177e4SLinus Torvalds 
6511bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65121da177e4SLinus Torvalds 	if (status)
65131da177e4SLinus Torvalds 		goto out;
6514bf269551SChuck Lever 	status = decode_putfh(xdr);
65151da177e4SLinus Torvalds 	if (status)
65161da177e4SLinus Torvalds 		goto out;
6517bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
65181da177e4SLinus Torvalds out:
65191da177e4SLinus Torvalds 	return status;
65201da177e4SLinus Torvalds }
65211da177e4SLinus Torvalds 
65221da177e4SLinus Torvalds /*
65231da177e4SLinus Torvalds  * Decode OPEN response
65241da177e4SLinus Torvalds  */
6525bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6526bf269551SChuck Lever 				    struct xdr_stream *xdr,
6527bf269551SChuck Lever 				    struct nfs_openres *res)
65281da177e4SLinus Torvalds {
65291da177e4SLinus Torvalds 	struct compound_hdr hdr;
65301da177e4SLinus Torvalds 	int status;
65311da177e4SLinus Torvalds 
6532bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65331da177e4SLinus Torvalds 	if (status)
65341da177e4SLinus Torvalds 		goto out;
6535bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65369b7b9fccSAndy Adamson 	if (status)
65379b7b9fccSAndy Adamson 		goto out;
6538bf269551SChuck Lever 	status = decode_putfh(xdr);
65391da177e4SLinus Torvalds 	if (status)
65401da177e4SLinus Torvalds 		goto out;
6541bf269551SChuck Lever 	status = decode_open(xdr, res);
6542864472e9STrond Myklebust 	if (status)
6543864472e9STrond Myklebust 		goto out;
6544ae2bb032SWeston Andros Adamson 	if (res->access_request)
65456168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
65466926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
65471da177e4SLinus Torvalds out:
65481da177e4SLinus Torvalds 	return status;
65491da177e4SLinus Torvalds }
65501da177e4SLinus Torvalds 
65511da177e4SLinus Torvalds /*
65521da177e4SLinus Torvalds  * Decode SETATTR response
65531da177e4SLinus Torvalds  */
6554bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6555bf269551SChuck Lever 				struct xdr_stream *xdr,
6556bf269551SChuck Lever 				struct nfs_setattrres *res)
65571da177e4SLinus Torvalds {
65581da177e4SLinus Torvalds 	struct compound_hdr hdr;
65591da177e4SLinus Torvalds 	int status;
65601da177e4SLinus Torvalds 
6561bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65621da177e4SLinus Torvalds 	if (status)
65631da177e4SLinus Torvalds 		goto out;
6564bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65659b7b9fccSAndy Adamson 	if (status)
65669b7b9fccSAndy Adamson 		goto out;
6567bf269551SChuck Lever 	status = decode_putfh(xdr);
65681da177e4SLinus Torvalds 	if (status)
65691da177e4SLinus Torvalds 		goto out;
6570bf269551SChuck Lever 	status = decode_setattr(xdr);
65711da177e4SLinus Torvalds 	if (status)
65721da177e4SLinus Torvalds 		goto out;
6573aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
65741da177e4SLinus Torvalds out:
65751da177e4SLinus Torvalds 	return status;
65761da177e4SLinus Torvalds }
65771da177e4SLinus Torvalds 
65781da177e4SLinus Torvalds /*
65791da177e4SLinus Torvalds  * Decode LOCK response
65801da177e4SLinus Torvalds  */
6581bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6582bf269551SChuck Lever 			     struct nfs_lock_res *res)
65831da177e4SLinus Torvalds {
65841da177e4SLinus Torvalds 	struct compound_hdr hdr;
65851da177e4SLinus Torvalds 	int status;
65861da177e4SLinus Torvalds 
6587bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65881da177e4SLinus Torvalds 	if (status)
65891da177e4SLinus Torvalds 		goto out;
6590bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65919b7b9fccSAndy Adamson 	if (status)
65929b7b9fccSAndy Adamson 		goto out;
6593bf269551SChuck Lever 	status = decode_putfh(xdr);
65941da177e4SLinus Torvalds 	if (status)
65951da177e4SLinus Torvalds 		goto out;
6596bf269551SChuck Lever 	status = decode_lock(xdr, res);
65971da177e4SLinus Torvalds out:
65981da177e4SLinus Torvalds 	return status;
65991da177e4SLinus Torvalds }
66001da177e4SLinus Torvalds 
66011da177e4SLinus Torvalds /*
66021da177e4SLinus Torvalds  * Decode LOCKT response
66031da177e4SLinus Torvalds  */
6604bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6605bf269551SChuck Lever 			      struct nfs_lockt_res *res)
66061da177e4SLinus Torvalds {
66071da177e4SLinus Torvalds 	struct compound_hdr hdr;
66081da177e4SLinus Torvalds 	int status;
66091da177e4SLinus Torvalds 
6610bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66111da177e4SLinus Torvalds 	if (status)
66121da177e4SLinus Torvalds 		goto out;
6613bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66149b7b9fccSAndy Adamson 	if (status)
66159b7b9fccSAndy Adamson 		goto out;
6616bf269551SChuck Lever 	status = decode_putfh(xdr);
66171da177e4SLinus Torvalds 	if (status)
66181da177e4SLinus Torvalds 		goto out;
6619bf269551SChuck Lever 	status = decode_lockt(xdr, res);
66201da177e4SLinus Torvalds out:
66211da177e4SLinus Torvalds 	return status;
66221da177e4SLinus Torvalds }
66231da177e4SLinus Torvalds 
66241da177e4SLinus Torvalds /*
66251da177e4SLinus Torvalds  * Decode LOCKU response
66261da177e4SLinus Torvalds  */
6627bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6628bf269551SChuck Lever 			      struct nfs_locku_res *res)
66291da177e4SLinus Torvalds {
66301da177e4SLinus Torvalds 	struct compound_hdr hdr;
66311da177e4SLinus Torvalds 	int status;
66321da177e4SLinus Torvalds 
6633bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66341da177e4SLinus Torvalds 	if (status)
66351da177e4SLinus Torvalds 		goto out;
6636bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66379b7b9fccSAndy Adamson 	if (status)
66389b7b9fccSAndy Adamson 		goto out;
6639bf269551SChuck Lever 	status = decode_putfh(xdr);
66401da177e4SLinus Torvalds 	if (status)
66411da177e4SLinus Torvalds 		goto out;
6642bf269551SChuck Lever 	status = decode_locku(xdr, res);
66431da177e4SLinus Torvalds out:
66441da177e4SLinus Torvalds 	return status;
66451da177e4SLinus Torvalds }
66461da177e4SLinus Torvalds 
6647bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6648bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6649d3c7b7ccSTrond Myklebust {
6650d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6651d3c7b7ccSTrond Myklebust 	int status;
6652d3c7b7ccSTrond Myklebust 
6653bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6654d3c7b7ccSTrond Myklebust 	if (!status)
6655bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6656d3c7b7ccSTrond Myklebust 	return status;
6657d3c7b7ccSTrond Myklebust }
6658d3c7b7ccSTrond Myklebust 
66591da177e4SLinus Torvalds /*
66601da177e4SLinus Torvalds  * Decode READLINK response
66611da177e4SLinus Torvalds  */
6662bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6663bf269551SChuck Lever 				 struct xdr_stream *xdr,
6664f50c7000SBenny Halevy 				 struct nfs4_readlink_res *res)
66651da177e4SLinus Torvalds {
66661da177e4SLinus Torvalds 	struct compound_hdr hdr;
66671da177e4SLinus Torvalds 	int status;
66681da177e4SLinus Torvalds 
6669bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66701da177e4SLinus Torvalds 	if (status)
66711da177e4SLinus Torvalds 		goto out;
6672bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66739b7b9fccSAndy Adamson 	if (status)
66749b7b9fccSAndy Adamson 		goto out;
6675bf269551SChuck Lever 	status = decode_putfh(xdr);
66761da177e4SLinus Torvalds 	if (status)
66771da177e4SLinus Torvalds 		goto out;
6678bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
66791da177e4SLinus Torvalds out:
66801da177e4SLinus Torvalds 	return status;
66811da177e4SLinus Torvalds }
66821da177e4SLinus Torvalds 
66831da177e4SLinus Torvalds /*
66841da177e4SLinus Torvalds  * Decode READDIR response
66851da177e4SLinus Torvalds  */
6686bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6687bf269551SChuck Lever 				struct nfs4_readdir_res *res)
66881da177e4SLinus Torvalds {
66891da177e4SLinus Torvalds 	struct compound_hdr hdr;
66901da177e4SLinus Torvalds 	int status;
66911da177e4SLinus Torvalds 
6692bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66931da177e4SLinus Torvalds 	if (status)
66941da177e4SLinus Torvalds 		goto out;
6695bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66969b7b9fccSAndy Adamson 	if (status)
66979b7b9fccSAndy Adamson 		goto out;
6698bf269551SChuck Lever 	status = decode_putfh(xdr);
66991da177e4SLinus Torvalds 	if (status)
67001da177e4SLinus Torvalds 		goto out;
6701bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
67021da177e4SLinus Torvalds out:
67031da177e4SLinus Torvalds 	return status;
67041da177e4SLinus Torvalds }
67051da177e4SLinus Torvalds 
67061da177e4SLinus Torvalds /*
67071da177e4SLinus Torvalds  * Decode Read response
67081da177e4SLinus Torvalds  */
6709bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
67109137bdf3SAnna Schumaker 			     struct nfs_pgio_res *res)
67111da177e4SLinus Torvalds {
67121da177e4SLinus Torvalds 	struct compound_hdr hdr;
67131da177e4SLinus Torvalds 	int status;
67141da177e4SLinus Torvalds 
6715bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6716aabff4ddSPeng Tao 	res->op_status = hdr.status;
67171da177e4SLinus Torvalds 	if (status)
67181da177e4SLinus Torvalds 		goto out;
6719bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67209b7b9fccSAndy Adamson 	if (status)
67219b7b9fccSAndy Adamson 		goto out;
6722bf269551SChuck Lever 	status = decode_putfh(xdr);
67231da177e4SLinus Torvalds 	if (status)
67241da177e4SLinus Torvalds 		goto out;
6725bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
67261da177e4SLinus Torvalds 	if (!status)
67271da177e4SLinus Torvalds 		status = res->count;
67281da177e4SLinus Torvalds out:
67291da177e4SLinus Torvalds 	return status;
67301da177e4SLinus Torvalds }
67311da177e4SLinus Torvalds 
67321da177e4SLinus Torvalds /*
67331da177e4SLinus Torvalds  * Decode WRITE response
67341da177e4SLinus Torvalds  */
6735bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
67369137bdf3SAnna Schumaker 			      struct nfs_pgio_res *res)
67371da177e4SLinus Torvalds {
67381da177e4SLinus Torvalds 	struct compound_hdr hdr;
67391da177e4SLinus Torvalds 	int status;
67401da177e4SLinus Torvalds 
6741bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6742aabff4ddSPeng Tao 	res->op_status = hdr.status;
67431da177e4SLinus Torvalds 	if (status)
67441da177e4SLinus Torvalds 		goto out;
6745bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67469b7b9fccSAndy Adamson 	if (status)
67479b7b9fccSAndy Adamson 		goto out;
6748bf269551SChuck Lever 	status = decode_putfh(xdr);
67491da177e4SLinus Torvalds 	if (status)
67501da177e4SLinus Torvalds 		goto out;
6751bf269551SChuck Lever 	status = decode_write(xdr, res);
67524f9838c7STrond Myklebust 	if (status)
67534f9838c7STrond Myklebust 		goto out;
67547ffd1064SFred Isaman 	if (res->fattr)
67556926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
67561da177e4SLinus Torvalds 	if (!status)
67571da177e4SLinus Torvalds 		status = res->count;
67581da177e4SLinus Torvalds out:
67591da177e4SLinus Torvalds 	return status;
67601da177e4SLinus Torvalds }
67611da177e4SLinus Torvalds 
67621da177e4SLinus Torvalds /*
67631da177e4SLinus Torvalds  * Decode COMMIT response
67641da177e4SLinus Torvalds  */
6765bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
67660b7c0153SFred Isaman 			       struct nfs_commitres *res)
67671da177e4SLinus Torvalds {
67681da177e4SLinus Torvalds 	struct compound_hdr hdr;
67691da177e4SLinus Torvalds 	int status;
67701da177e4SLinus Torvalds 
6771bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6772aabff4ddSPeng Tao 	res->op_status = hdr.status;
67731da177e4SLinus Torvalds 	if (status)
67741da177e4SLinus Torvalds 		goto out;
6775bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67769b7b9fccSAndy Adamson 	if (status)
67779b7b9fccSAndy Adamson 		goto out;
6778bf269551SChuck Lever 	status = decode_putfh(xdr);
67791da177e4SLinus Torvalds 	if (status)
67801da177e4SLinus Torvalds 		goto out;
6781bf269551SChuck Lever 	status = decode_commit(xdr, res);
67821da177e4SLinus Torvalds out:
67831da177e4SLinus Torvalds 	return status;
67841da177e4SLinus Torvalds }
67851da177e4SLinus Torvalds 
67861da177e4SLinus Torvalds /*
67878b173218SRicardo Labiaga  * Decode FSINFO response
67881da177e4SLinus Torvalds  */
6789bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
67903dda5e43SBenny Halevy 			       struct nfs4_fsinfo_res *res)
67911da177e4SLinus Torvalds {
67921da177e4SLinus Torvalds 	struct compound_hdr hdr;
67931da177e4SLinus Torvalds 	int status;
67941da177e4SLinus Torvalds 
6795bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67961da177e4SLinus Torvalds 	if (!status)
6797bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67989b7b9fccSAndy Adamson 	if (!status)
6799bf269551SChuck Lever 		status = decode_putfh(xdr);
68001da177e4SLinus Torvalds 	if (!status)
6801bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
68021da177e4SLinus Torvalds 	return status;
68031da177e4SLinus Torvalds }
68041da177e4SLinus Torvalds 
68051da177e4SLinus Torvalds /*
68068b173218SRicardo Labiaga  * Decode PATHCONF response
68071da177e4SLinus Torvalds  */
6808bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6809d45b2989SBenny Halevy 				 struct nfs4_pathconf_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_pathconf(xdr, res->pathconf);
68211da177e4SLinus Torvalds 	return status;
68221da177e4SLinus Torvalds }
68231da177e4SLinus Torvalds 
68241da177e4SLinus Torvalds /*
68258b173218SRicardo Labiaga  * Decode STATFS response
68261da177e4SLinus Torvalds  */
6827bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
682824ad148aSBenny Halevy 			       struct nfs4_statfs_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_statfs(xdr, res->fsstat);
68401da177e4SLinus Torvalds 	return status;
68411da177e4SLinus Torvalds }
68421da177e4SLinus Torvalds 
68431da177e4SLinus Torvalds /*
68448b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
68451da177e4SLinus Torvalds  */
6846bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6847bf269551SChuck Lever 				    struct xdr_stream *xdr,
6848bf269551SChuck Lever 				    struct nfs4_server_caps_res *res)
68491da177e4SLinus Torvalds {
68501da177e4SLinus Torvalds 	struct compound_hdr hdr;
68511da177e4SLinus Torvalds 	int status;
68521da177e4SLinus Torvalds 
6853bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68549b7b9fccSAndy Adamson 	if (status)
68559b7b9fccSAndy Adamson 		goto out;
6856bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
68579b7b9fccSAndy Adamson 	if (status)
68581da177e4SLinus Torvalds 		goto out;
6859bf269551SChuck Lever 	status = decode_putfh(xdr);
6860bf269551SChuck Lever 	if (status)
68611da177e4SLinus Torvalds 		goto out;
6862bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
68631da177e4SLinus Torvalds out:
68641da177e4SLinus Torvalds 	return status;
68651da177e4SLinus Torvalds }
68661da177e4SLinus Torvalds 
68671da177e4SLinus Torvalds /*
68681da177e4SLinus Torvalds  * Decode RENEW response
68691da177e4SLinus Torvalds  */
6870bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6871bf269551SChuck Lever 			      void *__unused)
68721da177e4SLinus Torvalds {
68731da177e4SLinus Torvalds 	struct compound_hdr hdr;
68741da177e4SLinus Torvalds 	int status;
68751da177e4SLinus Torvalds 
6876bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68771da177e4SLinus Torvalds 	if (!status)
6878bf269551SChuck Lever 		status = decode_renew(xdr);
68791da177e4SLinus Torvalds 	return status;
68801da177e4SLinus Torvalds }
68811da177e4SLinus Torvalds 
68821da177e4SLinus Torvalds /*
68838b173218SRicardo Labiaga  * Decode SETCLIENTID response
68841da177e4SLinus Torvalds  */
6885bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6886bf269551SChuck Lever 				    struct xdr_stream *xdr,
6887bb8b27e5STrond Myklebust 				    struct nfs4_setclientid_res *res)
68881da177e4SLinus Torvalds {
68891da177e4SLinus Torvalds 	struct compound_hdr hdr;
68901da177e4SLinus Torvalds 	int status;
68911da177e4SLinus Torvalds 
6892bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68931da177e4SLinus Torvalds 	if (!status)
6894bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
68951da177e4SLinus Torvalds 	return status;
68961da177e4SLinus Torvalds }
68971da177e4SLinus Torvalds 
68981da177e4SLinus Torvalds /*
68998b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
69001da177e4SLinus Torvalds  */
6901bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
690283ca7f5aSChuck Lever 					    struct xdr_stream *xdr)
69031da177e4SLinus Torvalds {
69041da177e4SLinus Torvalds 	struct compound_hdr hdr;
69051da177e4SLinus Torvalds 	int status;
69061da177e4SLinus Torvalds 
6907bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69081da177e4SLinus Torvalds 	if (!status)
6909bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
69101da177e4SLinus Torvalds 	return status;
69111da177e4SLinus Torvalds }
69121da177e4SLinus Torvalds 
69131da177e4SLinus Torvalds /*
69148b173218SRicardo Labiaga  * Decode DELEGRETURN response
69151da177e4SLinus Torvalds  */
6916bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6917bf269551SChuck Lever 				    struct xdr_stream *xdr,
6918bf269551SChuck Lever 				    struct nfs4_delegreturnres *res)
69191da177e4SLinus Torvalds {
69201da177e4SLinus Torvalds 	struct compound_hdr hdr;
69211da177e4SLinus Torvalds 	int status;
69221da177e4SLinus Torvalds 
6923bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69249b7b9fccSAndy Adamson 	if (status)
69259b7b9fccSAndy Adamson 		goto out;
6926bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69279b7b9fccSAndy Adamson 	if (status)
6928fa178f29STrond Myklebust 		goto out;
6929bf269551SChuck Lever 	status = decode_putfh(xdr);
6930fa178f29STrond Myklebust 	if (status != 0)
6931fa178f29STrond Myklebust 		goto out;
6932586f1c39STrond Myklebust 	if (res->lr_res) {
6933586f1c39STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6934586f1c39STrond Myklebust 		res->lr_ret = status;
6935586f1c39STrond Myklebust 		if (status)
6936586f1c39STrond Myklebust 			goto out;
6937586f1c39STrond Myklebust 	}
69388ac2b422STrond Myklebust 	if (res->fattr) {
6939e144cbccSTrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
6940556ae3bbSJeff Layton 		if (status != 0)
6941556ae3bbSJeff Layton 			goto out;
69428ac2b422STrond Myklebust 	}
6943e144cbccSTrond Myklebust 	status = decode_delegreturn(xdr);
6944fa178f29STrond Myklebust out:
69451da177e4SLinus Torvalds 	return status;
69461da177e4SLinus Torvalds }
69471da177e4SLinus Torvalds 
6948683b57b4STrond Myklebust /*
69498b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6950683b57b4STrond Myklebust  */
6951bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6952bf269551SChuck Lever 				     struct xdr_stream *xdr,
695322958463SBenny Halevy 				     struct nfs4_fs_locations_res *res)
6954683b57b4STrond Myklebust {
6955683b57b4STrond Myklebust 	struct compound_hdr hdr;
6956683b57b4STrond Myklebust 	int status;
6957683b57b4STrond Myklebust 
6958bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69599b7b9fccSAndy Adamson 	if (status)
69609b7b9fccSAndy Adamson 		goto out;
6961bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
69629b7b9fccSAndy Adamson 	if (status)
6963683b57b4STrond Myklebust 		goto out;
6964bf269551SChuck Lever 	status = decode_putfh(xdr);
6965bf269551SChuck Lever 	if (status)
6966683b57b4STrond Myklebust 		goto out;
6967b03d735bSChuck Lever 	if (res->migration) {
6968b03d735bSChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6969b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6970b03d735bSChuck Lever 					&res->fs_locations->fattr,
6971b03d735bSChuck Lever 					 NULL, res->fs_locations,
6972b03d735bSChuck Lever 					 NULL, res->fs_locations->server);
6973b03d735bSChuck Lever 		if (status)
6974b03d735bSChuck Lever 			goto out;
6975b03d735bSChuck Lever 		if (res->renew)
6976b03d735bSChuck Lever 			status = decode_renew(xdr);
6977b03d735bSChuck Lever 	} else {
6978bf269551SChuck Lever 		status = decode_lookup(xdr);
6979bf269551SChuck Lever 		if (status)
6980683b57b4STrond Myklebust 			goto out;
6981bf269551SChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6982b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6983b03d735bSChuck Lever 					&res->fs_locations->fattr,
69848b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
6985aa9c2669SDavid Quigley 					 NULL, res->fs_locations->server);
6986b03d735bSChuck Lever 	}
6987683b57b4STrond Myklebust out:
6988683b57b4STrond Myklebust 	return status;
6989683b57b4STrond Myklebust }
6990683b57b4STrond Myklebust 
69915a5ea0d4SBryan Schumaker /*
69925a5ea0d4SBryan Schumaker  * Decode SECINFO response
69935a5ea0d4SBryan Schumaker  */
69945a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
69955a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
69965a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_res *res)
69975a5ea0d4SBryan Schumaker {
69985a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
69995a5ea0d4SBryan Schumaker 	int status;
70005a5ea0d4SBryan Schumaker 
70015a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
70025a5ea0d4SBryan Schumaker 	if (status)
70035a5ea0d4SBryan Schumaker 		goto out;
70045a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
70055a5ea0d4SBryan Schumaker 	if (status)
70065a5ea0d4SBryan Schumaker 		goto out;
70075a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
70085a5ea0d4SBryan Schumaker 	if (status)
70095a5ea0d4SBryan Schumaker 		goto out;
70105a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
70115a5ea0d4SBryan Schumaker out:
70125a5ea0d4SBryan Schumaker 	return status;
70135a5ea0d4SBryan Schumaker }
70145a5ea0d4SBryan Schumaker 
701544c99933SChuck Lever /*
701644c99933SChuck Lever  * Decode FSID_PRESENT response
701744c99933SChuck Lever  */
701844c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
701944c99933SChuck Lever 				     struct xdr_stream *xdr,
702044c99933SChuck Lever 				     struct nfs4_fsid_present_res *res)
702144c99933SChuck Lever {
702244c99933SChuck Lever 	struct compound_hdr hdr;
702344c99933SChuck Lever 	int status;
702444c99933SChuck Lever 
702544c99933SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
702644c99933SChuck Lever 	if (status)
702744c99933SChuck Lever 		goto out;
702844c99933SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
702944c99933SChuck Lever 	if (status)
703044c99933SChuck Lever 		goto out;
703144c99933SChuck Lever 	status = decode_putfh(xdr);
703244c99933SChuck Lever 	if (status)
703344c99933SChuck Lever 		goto out;
703444c99933SChuck Lever 	status = decode_getfh(xdr, res->fh);
703544c99933SChuck Lever 	if (status)
703644c99933SChuck Lever 		goto out;
703744c99933SChuck Lever 	if (res->renew)
703844c99933SChuck Lever 		status = decode_renew(xdr);
703944c99933SChuck Lever out:
704044c99933SChuck Lever 	return status;
704144c99933SChuck Lever }
704244c99933SChuck Lever 
704399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
704499fe60d0SBenny Halevy /*
70457c44f1aeSWeston Andros Adamson  * Decode BIND_CONN_TO_SESSION response
70467c44f1aeSWeston Andros Adamson  */
70477c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
70487c44f1aeSWeston Andros Adamson 					struct xdr_stream *xdr,
70497c44f1aeSWeston Andros Adamson 					void *res)
70507c44f1aeSWeston Andros Adamson {
70517c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr;
70527c44f1aeSWeston Andros Adamson 	int status;
70537c44f1aeSWeston Andros Adamson 
70547c44f1aeSWeston Andros Adamson 	status = decode_compound_hdr(xdr, &hdr);
70557c44f1aeSWeston Andros Adamson 	if (!status)
70567c44f1aeSWeston Andros Adamson 		status = decode_bind_conn_to_session(xdr, res);
70577c44f1aeSWeston Andros Adamson 	return status;
70587c44f1aeSWeston Andros Adamson }
70597c44f1aeSWeston Andros Adamson 
70607c44f1aeSWeston Andros Adamson /*
70618b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
706299fe60d0SBenny Halevy  */
7063bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7064bf269551SChuck Lever 				    struct xdr_stream *xdr,
706599fe60d0SBenny Halevy 				    void *res)
706699fe60d0SBenny Halevy {
706799fe60d0SBenny Halevy 	struct compound_hdr hdr;
706899fe60d0SBenny Halevy 	int status;
706999fe60d0SBenny Halevy 
7070bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
707199fe60d0SBenny Halevy 	if (!status)
7072bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
707399fe60d0SBenny Halevy 	return status;
707499fe60d0SBenny Halevy }
70752050f0ccSAndy Adamson 
70762050f0ccSAndy Adamson /*
70778b173218SRicardo Labiaga  * Decode CREATE_SESSION response
7078fc931582SAndy Adamson  */
7079bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7080bf269551SChuck Lever 				       struct xdr_stream *xdr,
7081fc931582SAndy Adamson 				       struct nfs41_create_session_res *res)
7082fc931582SAndy Adamson {
7083fc931582SAndy Adamson 	struct compound_hdr hdr;
7084fc931582SAndy Adamson 	int status;
7085fc931582SAndy Adamson 
7086bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7087fc931582SAndy Adamson 	if (!status)
7088bf269551SChuck Lever 		status = decode_create_session(xdr, res);
7089fc931582SAndy Adamson 	return status;
7090fc931582SAndy Adamson }
7091fc931582SAndy Adamson 
7092fc931582SAndy Adamson /*
70938b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
70940f3e66c6SAndy Adamson  */
7095bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7096bf269551SChuck Lever 					struct xdr_stream *xdr,
7097bf269551SChuck Lever 					void *res)
70980f3e66c6SAndy Adamson {
70990f3e66c6SAndy Adamson 	struct compound_hdr hdr;
71000f3e66c6SAndy Adamson 	int status;
71010f3e66c6SAndy Adamson 
7102bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
71030f3e66c6SAndy Adamson 	if (!status)
7104bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
71050f3e66c6SAndy Adamson 	return status;
71060f3e66c6SAndy Adamson }
71070f3e66c6SAndy Adamson 
71080f3e66c6SAndy Adamson /*
710966245539STrond Myklebust  * Decode DESTROY_CLIENTID response
711066245539STrond Myklebust  */
711166245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
711266245539STrond Myklebust 					struct xdr_stream *xdr,
711366245539STrond Myklebust 					void *res)
711466245539STrond Myklebust {
711566245539STrond Myklebust 	struct compound_hdr hdr;
711666245539STrond Myklebust 	int status;
711766245539STrond Myklebust 
711866245539STrond Myklebust 	status = decode_compound_hdr(xdr, &hdr);
711966245539STrond Myklebust 	if (!status)
712066245539STrond Myklebust 		status = decode_destroy_clientid(xdr, res);
712166245539STrond Myklebust 	return status;
712266245539STrond Myklebust }
712366245539STrond Myklebust 
712466245539STrond Myklebust /*
71258b173218SRicardo Labiaga  * Decode SEQUENCE response
7126fc01cea9SAndy Adamson  */
7127bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7128bf269551SChuck Lever 				 struct xdr_stream *xdr,
7129fc01cea9SAndy Adamson 				 struct nfs4_sequence_res *res)
7130fc01cea9SAndy Adamson {
7131fc01cea9SAndy Adamson 	struct compound_hdr hdr;
7132fc01cea9SAndy Adamson 	int status;
7133fc01cea9SAndy Adamson 
7134bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7135fc01cea9SAndy Adamson 	if (!status)
7136bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
7137fc01cea9SAndy Adamson 	return status;
7138fc01cea9SAndy Adamson }
7139fc01cea9SAndy Adamson 
7140fc01cea9SAndy Adamson /*
71418b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
71422050f0ccSAndy Adamson  */
7143bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7144bf269551SChuck Lever 				       struct xdr_stream *xdr,
71452050f0ccSAndy Adamson 				       struct nfs4_get_lease_time_res *res)
71462050f0ccSAndy Adamson {
71472050f0ccSAndy Adamson 	struct compound_hdr hdr;
71482050f0ccSAndy Adamson 	int status;
71492050f0ccSAndy Adamson 
7150bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
71512050f0ccSAndy Adamson 	if (!status)
7152bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
71532050f0ccSAndy Adamson 	if (!status)
7154bf269551SChuck Lever 		status = decode_putrootfh(xdr);
71552050f0ccSAndy Adamson 	if (!status)
7156bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
71572050f0ccSAndy Adamson 	return status;
71582050f0ccSAndy Adamson }
715918019753SRicardo Labiaga 
716018019753SRicardo Labiaga /*
716118019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
716218019753SRicardo Labiaga  */
7163bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7164bf269551SChuck Lever 					 struct xdr_stream *xdr,
716518019753SRicardo Labiaga 					 struct nfs41_reclaim_complete_res *res)
716618019753SRicardo Labiaga {
716718019753SRicardo Labiaga 	struct compound_hdr hdr;
716818019753SRicardo Labiaga 	int status;
716918019753SRicardo Labiaga 
7170bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
717118019753SRicardo Labiaga 	if (!status)
7172bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
717318019753SRicardo Labiaga 	if (!status)
71748ee2b78aSHimangi Saraogi 		status = decode_reclaim_complete(xdr, NULL);
717518019753SRicardo Labiaga 	return status;
717618019753SRicardo Labiaga }
7177b1f69b75SAndy Adamson 
7178b1f69b75SAndy Adamson /*
7179b1f69b75SAndy Adamson  * Decode GETDEVINFO response
7180b1f69b75SAndy Adamson  */
7181bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7182bf269551SChuck Lever 				      struct xdr_stream *xdr,
7183b1f69b75SAndy Adamson 				      struct nfs4_getdeviceinfo_res *res)
7184b1f69b75SAndy Adamson {
7185b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7186b1f69b75SAndy Adamson 	int status;
7187b1f69b75SAndy Adamson 
7188bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7189b1f69b75SAndy Adamson 	if (status != 0)
7190b1f69b75SAndy Adamson 		goto out;
7191bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7192b1f69b75SAndy Adamson 	if (status != 0)
7193b1f69b75SAndy Adamson 		goto out;
71944e590803STrond Myklebust 	status = decode_getdeviceinfo(xdr, res);
7195b1f69b75SAndy Adamson out:
7196b1f69b75SAndy Adamson 	return status;
7197b1f69b75SAndy Adamson }
7198b1f69b75SAndy Adamson 
7199b1f69b75SAndy Adamson /*
7200b1f69b75SAndy Adamson  * Decode LAYOUTGET response
7201b1f69b75SAndy Adamson  */
7202bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7203bf269551SChuck Lever 				  struct xdr_stream *xdr,
7204b1f69b75SAndy Adamson 				  struct nfs4_layoutget_res *res)
7205b1f69b75SAndy Adamson {
7206b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7207b1f69b75SAndy Adamson 	int status;
7208b1f69b75SAndy Adamson 
7209bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7210b1f69b75SAndy Adamson 	if (status)
7211b1f69b75SAndy Adamson 		goto out;
7212bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7213b1f69b75SAndy Adamson 	if (status)
7214b1f69b75SAndy Adamson 		goto out;
7215bf269551SChuck Lever 	status = decode_putfh(xdr);
7216b1f69b75SAndy Adamson 	if (status)
7217b1f69b75SAndy Adamson 		goto out;
7218bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
7219b1f69b75SAndy Adamson out:
7220b1f69b75SAndy Adamson 	return status;
7221b1f69b75SAndy Adamson }
7222863a3c6cSAndy Adamson 
7223863a3c6cSAndy Adamson /*
7224cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
7225cbe82603SBenny Halevy  */
7226cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7227cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
7228cbe82603SBenny Halevy 				     struct nfs4_layoutreturn_res *res)
7229cbe82603SBenny Halevy {
7230cbe82603SBenny Halevy 	struct compound_hdr hdr;
7231cbe82603SBenny Halevy 	int status;
7232cbe82603SBenny Halevy 
7233cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
7234cbe82603SBenny Halevy 	if (status)
7235cbe82603SBenny Halevy 		goto out;
7236cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7237cbe82603SBenny Halevy 	if (status)
7238cbe82603SBenny Halevy 		goto out;
7239cbe82603SBenny Halevy 	status = decode_putfh(xdr);
7240cbe82603SBenny Halevy 	if (status)
7241cbe82603SBenny Halevy 		goto out;
7242cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
7243cbe82603SBenny Halevy out:
7244cbe82603SBenny Halevy 	return status;
7245cbe82603SBenny Halevy }
7246cbe82603SBenny Halevy 
7247cbe82603SBenny Halevy /*
7248863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
7249863a3c6cSAndy Adamson  */
7250863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7251863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
7252863a3c6cSAndy Adamson 				     struct nfs4_layoutcommit_res *res)
7253863a3c6cSAndy Adamson {
7254863a3c6cSAndy Adamson 	struct compound_hdr hdr;
7255863a3c6cSAndy Adamson 	int status;
7256863a3c6cSAndy Adamson 
7257863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
7258863a3c6cSAndy Adamson 	if (status)
7259863a3c6cSAndy Adamson 		goto out;
7260863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7261863a3c6cSAndy Adamson 	if (status)
7262863a3c6cSAndy Adamson 		goto out;
7263863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
7264863a3c6cSAndy Adamson 	if (status)
7265863a3c6cSAndy Adamson 		goto out;
7266863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
7267863a3c6cSAndy Adamson 	if (status)
7268863a3c6cSAndy Adamson 		goto out;
72696926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
7270863a3c6cSAndy Adamson out:
7271863a3c6cSAndy Adamson 	return status;
7272863a3c6cSAndy Adamson }
7273fca78d6dSBryan Schumaker 
7274fca78d6dSBryan Schumaker /*
7275fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
7276fca78d6dSBryan Schumaker  */
7277fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7278fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
7279fca78d6dSBryan Schumaker 					struct nfs4_secinfo_res *res)
7280fca78d6dSBryan Schumaker {
7281fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
7282fca78d6dSBryan Schumaker 	int status;
7283fca78d6dSBryan Schumaker 
7284fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
7285fca78d6dSBryan Schumaker 	if (status)
7286fca78d6dSBryan Schumaker 		goto out;
7287fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7288fca78d6dSBryan Schumaker 	if (status)
7289fca78d6dSBryan Schumaker 		goto out;
7290fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
7291fca78d6dSBryan Schumaker 	if (status)
7292fca78d6dSBryan Schumaker 		goto out;
729331e4dda4SBryan Schumaker 	status = decode_secinfo_no_name(xdr, res);
7294fca78d6dSBryan Schumaker out:
7295fca78d6dSBryan Schumaker 	return status;
7296fca78d6dSBryan Schumaker }
72977d974794SBryan Schumaker 
72987d974794SBryan Schumaker /*
72997d974794SBryan Schumaker  * Decode TEST_STATEID response
73007d974794SBryan Schumaker  */
73017d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
73027d974794SBryan Schumaker 				     struct xdr_stream *xdr,
73037d974794SBryan Schumaker 				     struct nfs41_test_stateid_res *res)
73047d974794SBryan Schumaker {
73057d974794SBryan Schumaker 	struct compound_hdr hdr;
73067d974794SBryan Schumaker 	int status;
73077d974794SBryan Schumaker 
73087d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
73097d974794SBryan Schumaker 	if (status)
73107d974794SBryan Schumaker 		goto out;
73117d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
73127d974794SBryan Schumaker 	if (status)
73137d974794SBryan Schumaker 		goto out;
73147d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
73157d974794SBryan Schumaker out:
73167d974794SBryan Schumaker 	return status;
73177d974794SBryan Schumaker }
73189aeda35fSBryan Schumaker 
73199aeda35fSBryan Schumaker /*
73209aeda35fSBryan Schumaker  * Decode FREE_STATEID response
73219aeda35fSBryan Schumaker  */
73229aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
73239aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
73249aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_res *res)
73259aeda35fSBryan Schumaker {
73269aeda35fSBryan Schumaker 	struct compound_hdr hdr;
73279aeda35fSBryan Schumaker 	int status;
73289aeda35fSBryan Schumaker 
73299aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
73309aeda35fSBryan Schumaker 	if (status)
73319aeda35fSBryan Schumaker 		goto out;
73329aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
73339aeda35fSBryan Schumaker 	if (status)
73349aeda35fSBryan Schumaker 		goto out;
73359aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
73369aeda35fSBryan Schumaker out:
73379aeda35fSBryan Schumaker 	return status;
73389aeda35fSBryan Schumaker }
733999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
734099fe60d0SBenny Halevy 
7341573c4e1eSChuck Lever /**
7342573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7343573c4e1eSChuck Lever  *                      the local page cache.
7344573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7345573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7346573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7347573c4e1eSChuck Lever  *
7348573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7349573c4e1eSChuck Lever  * returned.
7350573c4e1eSChuck Lever  *
7351573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7352573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7353573c4e1eSChuck Lever  * on a directory already in our cache.
7354573c4e1eSChuck Lever  */
7355573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7356573c4e1eSChuck Lever 		       int plus)
73571da177e4SLinus Torvalds {
7358256e48bbSTrond Myklebust 	unsigned int savep;
7359dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
73601da177e4SLinus Torvalds 	uint32_t len;
7361babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7362babddc72SBryan Schumaker 	if (unlikely(!p))
7363babddc72SBryan Schumaker 		goto out_overflow;
7364c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7365babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7366babddc72SBryan Schumaker 		if (unlikely(!p))
7367babddc72SBryan Schumaker 			goto out_overflow;
7368c08e76d0SChuck Lever 		if (*p == xdr_zero)
7369573c4e1eSChuck Lever 			return -EAGAIN;
73701da177e4SLinus Torvalds 		entry->eof = 1;
7371573c4e1eSChuck Lever 		return -EBADCOOKIE;
73721da177e4SLinus Torvalds 	}
73731da177e4SLinus Torvalds 
7374babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7375babddc72SBryan Schumaker 	if (unlikely(!p))
7376babddc72SBryan Schumaker 		goto out_overflow;
73771da177e4SLinus Torvalds 	entry->prev_cookie = entry->cookie;
73781da177e4SLinus Torvalds 	p = xdr_decode_hyper(p, &entry->cookie);
7379c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7380babddc72SBryan Schumaker 
73819af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7382babddc72SBryan Schumaker 	if (unlikely(!p))
7383babddc72SBryan Schumaker 		goto out_overflow;
73841da177e4SLinus Torvalds 	entry->name = (const char *) p;
73851da177e4SLinus Torvalds 
73861da177e4SLinus Torvalds 	/*
73871da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
73881da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
73891da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
73901da177e4SLinus Torvalds 	 */
73911da177e4SLinus Torvalds 	entry->ino = 1;
73924f082222STrond Myklebust 	entry->fattr->valid = 0;
73931da177e4SLinus Torvalds 
73949af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7395babddc72SBryan Schumaker 		goto out_overflow;
73969af8c222STrond Myklebust 
7397256e48bbSTrond Myklebust 	if (decode_attr_length(xdr, &len, &savep) < 0)
7398babddc72SBryan Schumaker 		goto out_overflow;
73999af8c222STrond Myklebust 
7400573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7401aa9c2669SDavid Quigley 			NULL, entry->label, entry->server) < 0)
7402babddc72SBryan Schumaker 		goto out_overflow;
740328331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
740428331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
740528331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
740682f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
74079af8c222STrond Myklebust 
74080b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
74090b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
74100b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
74110b26a0bfSTrond Myklebust 
7412573c4e1eSChuck Lever 	return 0;
7413babddc72SBryan Schumaker 
7414babddc72SBryan Schumaker out_overflow:
7415babddc72SBryan Schumaker 	print_overflow_msg(__func__, xdr);
7416573c4e1eSChuck Lever 	return -EAGAIN;
74171da177e4SLinus Torvalds }
74181da177e4SLinus Torvalds 
74191da177e4SLinus Torvalds /*
74201da177e4SLinus Torvalds  * We need to translate between nfs status return values and
74211da177e4SLinus Torvalds  * the local errno values which may not be the same.
74221da177e4SLinus Torvalds  */
74231da177e4SLinus Torvalds static struct {
74241da177e4SLinus Torvalds 	int stat;
74251da177e4SLinus Torvalds 	int errno;
74261da177e4SLinus Torvalds } nfs_errtbl[] = {
74271da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7428856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7429856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7430856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7431856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7432856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7433856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7434856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7435856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7436856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7437856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7438856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7439856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7440856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7441856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7442856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7443856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7444856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7445856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7446856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7447856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7448856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7449856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7450fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7451856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7452856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7453856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7454856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7455856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7456856dff3dSBenny Halevy 	{ -1,			-EIO		}
74571da177e4SLinus Torvalds };
74581da177e4SLinus Torvalds 
74591da177e4SLinus Torvalds /*
74601da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
74611da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
74621da177e4SLinus Torvalds  */
74631da177e4SLinus Torvalds static int
74640a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
74651da177e4SLinus Torvalds {
74661da177e4SLinus Torvalds 	int i;
74671da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
74681da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
74691da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
74701da177e4SLinus Torvalds 	}
74711da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
74721da177e4SLinus Torvalds 		/* The server is looney tunes. */
7473fdcb4577STrond Myklebust 		return -EREMOTEIO;
74741da177e4SLinus Torvalds 	}
74751da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
74761da177e4SLinus Torvalds 	 * handle it.
74771da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
74781da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
74791da177e4SLinus Torvalds 	 */
7480856dff3dSBenny Halevy 	return -stat;
74811da177e4SLinus Torvalds }
74821da177e4SLinus Torvalds 
74831c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
74841c6dcbe5SAnna Schumaker #include "nfs42xdr.c"
74851c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
74861c6dcbe5SAnna Schumaker 
74871da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
74881da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
74891da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
74909f06c719SChuck Lever 	.p_encode = (kxdreproc_t)nfs4_xdr_##argtype,		\
7491bf269551SChuck Lever 	.p_decode = (kxdrdproc_t)nfs4_xdr_##restype,		\
74922bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
74932bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7494cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7495cc0175c1SChuck Lever 	.p_name   = #proc,					\
74961da177e4SLinus Torvalds }
74971da177e4SLinus Torvalds 
74987c61f0d3SAnna Schumaker #define STUB(proc)		\
74997c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = {	\
75007c61f0d3SAnna Schumaker 	.p_name = #proc,	\
75017c61f0d3SAnna Schumaker }
75027c61f0d3SAnna Schumaker 
75031da177e4SLinus Torvalds struct rpc_procinfo	nfs4_procedures[] = {
75041da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
75051da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
75061da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
75071da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
75081da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
75091da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
75101da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
75111da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
75121da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
75131da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
75141da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
75151da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
75161da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
75171da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
75181da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
75191da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
75201da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
75211da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
75221da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
75231da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
75241da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
75251da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
75261da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
75271da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
75281da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
75291da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
75301da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
75311da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
75321da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
75331da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
75341da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7535029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
753623ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7537683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7538d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
75395a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
754044c99933SChuck Lever 	PROC(FSID_PRESENT,	enc_fsid_present,	dec_fsid_present),
754199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
754299fe60d0SBenny Halevy 	PROC(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
7543fc931582SAndy Adamson 	PROC(CREATE_SESSION,	enc_create_session,	dec_create_session),
75440f3e66c6SAndy Adamson 	PROC(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
7545fc01cea9SAndy Adamson 	PROC(SEQUENCE,		enc_sequence,		dec_sequence),
75462050f0ccSAndy Adamson 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
754718019753SRicardo Labiaga 	PROC(RECLAIM_COMPLETE,	enc_reclaim_complete,	dec_reclaim_complete),
7548b1f69b75SAndy Adamson 	PROC(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
7549b1f69b75SAndy Adamson 	PROC(LAYOUTGET,		enc_layoutget,		dec_layoutget),
7550863a3c6cSAndy Adamson 	PROC(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
7551cbe82603SBenny Halevy 	PROC(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
7552fca78d6dSBryan Schumaker 	PROC(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
75537d974794SBryan Schumaker 	PROC(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
75549aeda35fSBryan Schumaker 	PROC(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
75557c61f0d3SAnna Schumaker 	STUB(GETDEVICELIST),
7556ad24ecfbSTrond Myklebust 	PROC(BIND_CONN_TO_SESSION,
7557ad24ecfbSTrond Myklebust 			enc_bind_conn_to_session, dec_bind_conn_to_session),
755866245539STrond Myklebust 	PROC(DESTROY_CLIENTID,	enc_destroy_clientid,	dec_destroy_clientid),
755999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
75601c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
75611c6dcbe5SAnna Schumaker 	PROC(SEEK,		enc_seek,		dec_seek),
7562f4ac1674SAnna Schumaker 	PROC(ALLOCATE,		enc_allocate,		dec_allocate),
7563624bd5b7SAnna Schumaker 	PROC(DEALLOCATE,	enc_deallocate,		dec_deallocate),
7564be3a5d23STrond Myklebust 	PROC(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
756536022770SPeng Tao 	PROC(CLONE,		enc_clone,		dec_clone),
75662e72448bSAnna Schumaker 	PROC(COPY,		enc_copy,		dec_copy),
75671c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
75681da177e4SLinus Torvalds };
75691da177e4SLinus Torvalds 
7570a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
75711da177e4SLinus Torvalds 	.number			= 4,
7572e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
75731da177e4SLinus Torvalds 	.procs			= nfs4_procedures
75741da177e4SLinus Torvalds };
75751da177e4SLinus Torvalds 
75761da177e4SLinus Torvalds /*
75771da177e4SLinus Torvalds  * Local variables:
75781da177e4SLinus Torvalds  *  c-basic-offset: 8
75791da177e4SLinus Torvalds  * End:
75801da177e4SLinus Torvalds  */
7581