xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision 8ee2b78a)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  fs/nfs/nfs4xdr.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Client-side XDR for NFSv4.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  Copyright (c) 2002 The Regents of the University of Michigan.
71da177e4SLinus Torvalds  *  All rights reserved.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  *  Kendrick Smith <kmsmith@umich.edu>
101da177e4SLinus Torvalds  *  Andy Adamson   <andros@umich.edu>
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *  Redistribution and use in source and binary forms, with or without
131da177e4SLinus Torvalds  *  modification, are permitted provided that the following conditions
141da177e4SLinus Torvalds  *  are met:
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  *  1. Redistributions of source code must retain the above copyright
171da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer.
181da177e4SLinus Torvalds  *  2. Redistributions in binary form must reproduce the above copyright
191da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer in the
201da177e4SLinus Torvalds  *     documentation and/or other materials provided with the distribution.
211da177e4SLinus Torvalds  *  3. Neither the name of the University nor the names of its
221da177e4SLinus Torvalds  *     contributors may be used to endorse or promote products derived
231da177e4SLinus Torvalds  *     from this software without specific prior written permission.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
261da177e4SLinus Torvalds  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
271da177e4SLinus Torvalds  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
281da177e4SLinus Torvalds  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291da177e4SLinus Torvalds  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301da177e4SLinus Torvalds  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311da177e4SLinus Torvalds  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
321da177e4SLinus Torvalds  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
331da177e4SLinus Torvalds  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
341da177e4SLinus Torvalds  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
351da177e4SLinus Torvalds  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361da177e4SLinus Torvalds  */
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #include <linux/param.h>
391da177e4SLinus Torvalds #include <linux/time.h>
401da177e4SLinus Torvalds #include <linux/mm.h>
411da177e4SLinus Torvalds #include <linux/errno.h>
421da177e4SLinus Torvalds #include <linux/string.h>
431da177e4SLinus Torvalds #include <linux/in.h>
441da177e4SLinus Torvalds #include <linux/pagemap.h>
451da177e4SLinus Torvalds #include <linux/proc_fs.h>
461da177e4SLinus Torvalds #include <linux/kdev_t.h>
47db8ac8baSWeston Andros Adamson #include <linux/module.h>
48db8ac8baSWeston Andros Adamson #include <linux/utsname.h>
491da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h>
502449ea2eSAlexandros Batsakis #include <linux/sunrpc/msg_prot.h>
515a5ea0d4SBryan Schumaker #include <linux/sunrpc/gss_api.h>
521da177e4SLinus Torvalds #include <linux/nfs.h>
531da177e4SLinus Torvalds #include <linux/nfs4.h>
541da177e4SLinus Torvalds #include <linux/nfs_fs.h>
551da177e4SLinus Torvalds #include <linux/nfs_idmap.h>
56f092075dSChuck Lever 
574ce79717STrond Myklebust #include "nfs4_fs.h"
584882ef72SAlexandros Batsakis #include "internal.h"
5976e697baSTrond Myklebust #include "nfs4session.h"
60b1f69b75SAndy Adamson #include "pnfs.h"
61f092075dSChuck Lever #include "netns.h"
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_XDR
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
661da177e4SLinus Torvalds #define errno_NFSERR_IO		EIO
671da177e4SLinus Torvalds 
680a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
711da177e4SLinus Torvalds #ifdef DEBUG
721da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		20
731da177e4SLinus Torvalds #else
741da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		0
751da177e4SLinus Torvalds #endif
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /* lock,open owner id:
789f958ab8STrond Myklebust  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
791da177e4SLinus Torvalds  */
8095b72eb0STrond Myklebust #define open_owner_id_maxsz	(1 + 2 + 1 + 1 + 2)
81d035c36cSTrond Myklebust #define lock_owner_id_maxsz	(1 + 1 + 4)
829104a55dSTrond Myklebust #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
831da177e4SLinus Torvalds #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
841da177e4SLinus Torvalds #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
851da177e4SLinus Torvalds #define op_encode_hdr_maxsz	(1)
861da177e4SLinus Torvalds #define op_decode_hdr_maxsz	(2)
879104a55dSTrond Myklebust #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
889104a55dSTrond Myklebust #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
899104a55dSTrond Myklebust #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
909104a55dSTrond Myklebust #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
911da177e4SLinus Torvalds #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
921da177e4SLinus Torvalds 				(NFS4_FHSIZE >> 2))
931da177e4SLinus Torvalds #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
941da177e4SLinus Torvalds #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
951da177e4SLinus Torvalds #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
961da177e4SLinus Torvalds #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
971da177e4SLinus Torvalds #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
981da177e4SLinus Torvalds 				((3+NFS4_FHSIZE) >> 2))
99e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
10096928206SJ. Bruce Fields #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1011da177e4SLinus Torvalds #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
1021da177e4SLinus Torvalds #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
103bd625ba8STrond Myklebust #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
104bd625ba8STrond Myklebust #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
105aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL
106aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107aa9c2669SDavid Quigley #define	nfs4_label_maxsz	(4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
108aa9c2669SDavid Quigley #else
109aa9c2669SDavid Quigley #define	nfs4_label_maxsz	0
110aa9c2669SDavid Quigley #endif
11188034c3dSAndy Adamson /* We support only one layout type per file system */
11288034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
11396928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
11496928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
11588034c3dSAndy Adamson 				3 + 3 + 3 + nfs4_owner_maxsz + \
116aa9c2669SDavid Quigley 				nfs4_group_maxsz + nfs4_label_maxsz + \
117aa9c2669SDavid Quigley 				 decode_mdsthreshold_maxsz))
11896928206SJ. Bruce Fields #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
11996928206SJ. Bruce Fields 				nfs4_fattr_value_maxsz)
12096928206SJ. Bruce Fields #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1219104a55dSTrond Myklebust #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
1229104a55dSTrond Myklebust 				 1 + 2 + 1 + \
1239104a55dSTrond Myklebust 				nfs4_owner_maxsz + \
1249104a55dSTrond Myklebust 				nfs4_group_maxsz + \
125aa9c2669SDavid Quigley 				nfs4_label_maxsz + \
1269104a55dSTrond Myklebust 				4 + 4)
1271da177e4SLinus Torvalds #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
1281da177e4SLinus Torvalds #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
12956ae19f3STrond Myklebust #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
13056ae19f3STrond Myklebust #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
1312f42b5d0SFred Isaman #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
132dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
133dae100c2SFred Isaman  * layout types will be returned.
134dae100c2SFred Isaman  */
135dae100c2SFred Isaman #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
136dae100c2SFred Isaman 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1371da177e4SLinus Torvalds #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
1381da177e4SLinus Torvalds #define decode_renew_maxsz	(op_decode_hdr_maxsz)
1391da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1401da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
141cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
143cc38bac3SChuck Lever 				1 /* sc_prog */ + \
144cc38bac3SChuck Lever 				XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145cc38bac3SChuck Lever 				XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
146cc38bac3SChuck Lever 				1) /* sc_cb_ident */
1471da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1481da177e4SLinus Torvalds 				(op_decode_hdr_maxsz + \
1491da177e4SLinus Torvalds 				2 + \
1501da177e4SLinus Torvalds 				1024) /* large value for CLID_INUSE */
1511da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1521da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
1531da177e4SLinus Torvalds 				3 + (NFS4_VERIFIER_SIZE >> 2))
1541da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1551da177e4SLinus Torvalds 				(op_decode_hdr_maxsz)
156e6889620STrond Myklebust #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
157e6889620STrond Myklebust #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
1582cebf828STrond Myklebust #define encode_share_access_maxsz \
1592cebf828STrond Myklebust 				(2)
1604882ef72SAlexandros Batsakis #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
1612cebf828STrond Myklebust #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
1622cebf828STrond Myklebust #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
1632cebf828STrond Myklebust #define encode_open_maxsz	(op_encode_hdr_maxsz + \
1642cebf828STrond Myklebust 				2 + encode_share_access_maxsz + 2 + \
1652cebf828STrond Myklebust 				open_owner_id_maxsz + \
1662cebf828STrond Myklebust 				encode_opentype_maxsz + \
1672cebf828STrond Myklebust 				encode_claim_null_maxsz)
1682cebf828STrond Myklebust #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
1699104a55dSTrond Myklebust #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
1702cebf828STrond Myklebust 				decode_ace_maxsz)
1712cebf828STrond Myklebust #define decode_change_info_maxsz	(5)
1722cebf828STrond Myklebust #define decode_open_maxsz	(op_decode_hdr_maxsz + \
1739104a55dSTrond Myklebust 				decode_stateid_maxsz + \
1742cebf828STrond Myklebust 				decode_change_info_maxsz + 1 + \
1752cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz + \
1762cebf828STrond Myklebust 				decode_delegation_maxsz)
1779104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
1789104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1799104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1)
1809104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
1819104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1829104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1839104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
1849104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1859104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1 + \
1869104a55dSTrond Myklebust 				 encode_share_access_maxsz)
1879104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
1889104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1899104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1909104a55dSTrond Myklebust #define encode_close_maxsz	(op_encode_hdr_maxsz + \
1919104a55dSTrond Myklebust 				 1 + encode_stateid_maxsz)
1929104a55dSTrond Myklebust #define decode_close_maxsz	(op_decode_hdr_maxsz + \
1939104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1949104a55dSTrond Myklebust #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
1959104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
1969104a55dSTrond Myklebust 				 encode_attrs_maxsz)
1979104a55dSTrond Myklebust #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
1989104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz)
1999104a55dSTrond Myklebust #define encode_read_maxsz	(op_encode_hdr_maxsz + \
2009104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2019104a55dSTrond Myklebust #define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
2029104a55dSTrond Myklebust #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
203aa9c2669SDavid Quigley 				 2 + encode_verifier_maxsz + 5 + \
204aa9c2669SDavid Quigley 				nfs4_label_maxsz)
2059104a55dSTrond Myklebust #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
206a7697f6fSChuck Lever 				 decode_verifier_maxsz)
2079104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
2089104a55dSTrond Myklebust #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
2099104a55dSTrond Myklebust #define encode_write_maxsz	(op_encode_hdr_maxsz + \
2109104a55dSTrond Myklebust 				 encode_stateid_maxsz + 4)
2119104a55dSTrond Myklebust #define decode_write_maxsz	(op_decode_hdr_maxsz + \
2129104a55dSTrond Myklebust 				 2 + decode_verifier_maxsz)
2139104a55dSTrond Myklebust #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
2149104a55dSTrond Myklebust #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
2159104a55dSTrond Myklebust 				 decode_verifier_maxsz)
2161da177e4SLinus Torvalds #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
2171da177e4SLinus Torvalds 				nfs4_name_maxsz)
2186ce18391SBenny Halevy #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
2196ce18391SBenny Halevy 				 decode_change_info_maxsz)
2201da177e4SLinus Torvalds #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
2211da177e4SLinus Torvalds 				2 * nfs4_name_maxsz)
2226ce18391SBenny Halevy #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
2236ce18391SBenny Halevy 				 decode_change_info_maxsz + \
2246ce18391SBenny Halevy 				 decode_change_info_maxsz)
2251da177e4SLinus Torvalds #define encode_link_maxsz	(op_encode_hdr_maxsz + \
2261da177e4SLinus Torvalds 				nfs4_name_maxsz)
2276ce18391SBenny Halevy #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
228daccbdedSTrond Myklebust #define encode_lockowner_maxsz	(7)
2299104a55dSTrond Myklebust #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
2309104a55dSTrond Myklebust 				 7 + \
231daccbdedSTrond Myklebust 				 1 + encode_stateid_maxsz + 1 + \
232daccbdedSTrond Myklebust 				 encode_lockowner_maxsz)
2339104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2349104a55dSTrond Myklebust 				(8 + decode_lockowner_maxsz)
2359104a55dSTrond Myklebust #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
2369104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
237daccbdedSTrond Myklebust #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
238daccbdedSTrond Myklebust 				encode_lockowner_maxsz)
2399104a55dSTrond Myklebust #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
2409104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
2419104a55dSTrond Myklebust #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
2429104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2439104a55dSTrond Myklebust 				 4)
2449104a55dSTrond Myklebust #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
2459104a55dSTrond Myklebust 				 decode_stateid_maxsz)
246d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
247d3c7b7ccSTrond Myklebust 				(op_encode_hdr_maxsz + \
248d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
249d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
250d3c7b7ccSTrond Myklebust 				(op_decode_hdr_maxsz)
2519104a55dSTrond Myklebust #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
2529104a55dSTrond Myklebust #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
2531da177e4SLinus Torvalds #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
2541da177e4SLinus Torvalds 				1 + nfs4_name_maxsz + \
25594a6d753SChuck Lever 				1 + \
25696928206SJ. Bruce Fields 				nfs4_fattr_maxsz)
2571da177e4SLinus Torvalds #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
2581da177e4SLinus Torvalds #define encode_create_maxsz	(op_encode_hdr_maxsz + \
2599104a55dSTrond Myklebust 				1 + 2 + nfs4_name_maxsz + \
2609104a55dSTrond Myklebust 				encode_attrs_maxsz)
2612cebf828STrond Myklebust #define decode_create_maxsz	(op_decode_hdr_maxsz + \
2622cebf828STrond Myklebust 				decode_change_info_maxsz + \
2632cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz)
2649104a55dSTrond Myklebust #define encode_statfs_maxsz	(encode_getattr_maxsz)
2659104a55dSTrond Myklebust #define decode_statfs_maxsz	(decode_getattr_maxsz)
2661da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2671da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2689104a55dSTrond Myklebust #define encode_getacl_maxsz	(encode_getattr_maxsz)
2699104a55dSTrond Myklebust #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
2709104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz + 1)
2719104a55dSTrond Myklebust #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
2729104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2739104a55dSTrond Myklebust #define decode_setacl_maxsz	(decode_setattr_maxsz)
274e6889620STrond Myklebust #define encode_fs_locations_maxsz \
275e6889620STrond Myklebust 				(encode_getattr_maxsz)
276e6889620STrond Myklebust #define decode_fs_locations_maxsz \
277e6889620STrond Myklebust 				(0)
2785a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
2791650add2SBryan Schumaker #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
2809b7b9fccSAndy Adamson 
2819b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
282fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
283d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
284d751f748SJim Rees 			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
285fc931582SAndy Adamson 
28699fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
28799fe60d0SBenny Halevy 				encode_verifier_maxsz + \
28899fe60d0SBenny Halevy 				1 /* co_ownerid.len */ + \
28999fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
29099fe60d0SBenny Halevy 				1 /* flags */ + \
29199fe60d0SBenny Halevy 				1 /* spa_how */ + \
2922031cd1aSWeston Andros Adamson 				/* max is SP4_MACH_CRED (for now) */ + \
2932031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
2942031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
295db8ac8baSWeston Andros Adamson 				1 /* implementation id array of size 1 */ + \
296db8ac8baSWeston Andros Adamson 				1 /* nii_domain */ + \
297db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298db8ac8baSWeston Andros Adamson 				1 /* nii_name */ + \
299d751f748SJim Rees 				XDR_QUADLEN(IMPL_NAME_LIMIT) + \
300db8ac8baSWeston Andros Adamson 				3 /* nii_date */)
30199fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
30299fe60d0SBenny Halevy 				2 /* eir_clientid */ + \
30399fe60d0SBenny Halevy 				1 /* eir_sequenceid */ + \
30499fe60d0SBenny Halevy 				1 /* eir_flags */ + \
30599fe60d0SBenny Halevy 				1 /* spr_how */ + \
3062031cd1aSWeston Andros Adamson 				  /* max is SP4_MACH_CRED (for now) */ + \
3072031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
3082031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
30999fe60d0SBenny Halevy 				2 /* eir_server_owner.so_minor_id */ + \
31099fe60d0SBenny Halevy 				/* eir_server_owner.so_major_id<> */ \
31199fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
31299fe60d0SBenny Halevy 				/* eir_server_scope<> */ \
31399fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
31499fe60d0SBenny Halevy 				1 /* eir_server_impl_id array length */ + \
3157d2ed9acSWeston Andros Adamson 				1 /* nii_domain */ + \
3167d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3177d2ed9acSWeston Andros Adamson 				1 /* nii_name */ + \
3187d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3197d2ed9acSWeston Andros Adamson 				3 /* nii_date */)
320fc931582SAndy Adamson #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
321fc931582SAndy Adamson #define decode_channel_attrs_maxsz  (6 + \
322fc931582SAndy Adamson 				     1 /* ca_rdma_ird.len */ + \
323fc931582SAndy Adamson 				     1 /* ca_rdma_ird */)
324fc931582SAndy Adamson #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
325fc931582SAndy Adamson 				     2 /* csa_clientid */ + \
326fc931582SAndy Adamson 				     1 /* csa_sequence */ + \
327fc931582SAndy Adamson 				     1 /* csa_flags */ + \
328fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
329fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
330fc931582SAndy Adamson 				     1 /* csa_cb_program */ + \
331fc931582SAndy Adamson 				     1 /* csa_sec_parms.len (1) */ + \
332fc931582SAndy Adamson 				     1 /* cb_secflavor (AUTH_SYS) */ + \
333fc931582SAndy Adamson 				     1 /* stamp */ + \
334fc931582SAndy Adamson 				     1 /* machinename.len */ + \
335fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
336fc931582SAndy Adamson 				     1 /* uid */ + \
337fc931582SAndy Adamson 				     1 /* gid */ + \
338fc931582SAndy Adamson 				     1 /* gids.len (0) */)
339fc931582SAndy Adamson #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
340fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
341fc931582SAndy Adamson 				     1 /* csr_sequence */ + \
342fc931582SAndy Adamson 				     1 /* csr_flags */ + \
343fc931582SAndy Adamson 				     decode_channel_attrs_maxsz + \
344fc931582SAndy Adamson 				     decode_channel_attrs_maxsz)
3457c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
3467c44f1aeSWeston Andros Adamson 				     /* bctsa_sessid */ \
3477c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3487c44f1aeSWeston Andros Adamson 				     1 /* bctsa_dir */ + \
3497c44f1aeSWeston Andros Adamson 				     1 /* bctsa_use_conn_in_rdma_mode */)
3507c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +	\
3517c44f1aeSWeston Andros Adamson 				     /* bctsr_sessid */ \
3527c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3537c44f1aeSWeston Andros Adamson 				     1 /* bctsr_dir */ + \
3547c44f1aeSWeston Andros Adamson 				     1 /* bctsr_use_conn_in_rdma_mode */)
3550f3e66c6SAndy Adamson #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
3560f3e66c6SAndy Adamson #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
35766245539STrond Myklebust #define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
35866245539STrond Myklebust #define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
359fc01cea9SAndy Adamson #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
360fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
361fc01cea9SAndy Adamson #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
362fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
36318019753SRicardo Labiaga #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
36418019753SRicardo Labiaga #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
3657f11d8d3SAndy Adamson #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
3667f11d8d3SAndy Adamson 				encode_verifier_maxsz)
3677f11d8d3SAndy Adamson #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
3687f11d8d3SAndy Adamson 				2 /* nfs_cookie4 gdlr_cookie */ + \
3697f11d8d3SAndy Adamson 				decode_verifier_maxsz \
3707f11d8d3SAndy Adamson 				  /* verifier4 gdlr_verifier */ + \
3717f11d8d3SAndy Adamson 				1 /* gdlr_deviceid_list count */ + \
3727f11d8d3SAndy Adamson 				XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
3737f11d8d3SAndy Adamson 					    NFS4_DEVICEID4_SIZE) \
3747f11d8d3SAndy Adamson 				  /* gdlr_deviceid_list */ + \
3757f11d8d3SAndy Adamson 				1 /* bool gdlr_eof */)
376b1f69b75SAndy Adamson #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
377b1f69b75SAndy Adamson 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
378b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
379b1f69b75SAndy Adamson 				1 /* layout type */ + \
380b1f69b75SAndy Adamson 				1 /* opaque devaddr4 length */ + \
381b1f69b75SAndy Adamson 				  /* devaddr4 payload is read into page */ \
382b1f69b75SAndy Adamson 				1 /* notification bitmap length */ + \
383b1f69b75SAndy Adamson 				1 /* notification bitmap */)
384b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
385b1f69b75SAndy Adamson 				encode_stateid_maxsz)
386b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
387b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
388b1f69b75SAndy Adamson 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
389863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
390863a3c6cSAndy Adamson 				2 /* offset */ + \
391863a3c6cSAndy Adamson 				2 /* length */ + \
392863a3c6cSAndy Adamson 				1 /* reclaim */ + \
393863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
394863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
395863a3c6cSAndy Adamson 				2 /* last byte written */ + \
396863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
397863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
398863a3c6cSAndy Adamson 				1 /* NULL filelayout layoutupdate4 payload */)
399863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
400cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
401cbe82603SBenny Halevy 				encode_stateid_maxsz + \
402cbe82603SBenny Halevy 				1 /* FIXME: opaque lrf_body always empty at the moment */)
403cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
404cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
405fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
406fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
4077d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
4087d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4097d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
4109aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
4119aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4129f79fb48SAndy Adamson #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz)
4139b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
4149b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
4159b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
4169b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4179b7b9fccSAndy Adamson 
4181da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
4191da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
4201da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
4219b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4221da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4239104a55dSTrond Myklebust 				encode_read_maxsz)
4241da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
4259b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4261da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4279104a55dSTrond Myklebust 				decode_read_maxsz)
4281da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
4299b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4301da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4319104a55dSTrond Myklebust 				encode_readlink_maxsz)
4321da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4339b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4341da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4359104a55dSTrond Myklebust 				decode_readlink_maxsz)
4361da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4379b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4381da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4399104a55dSTrond Myklebust 				encode_readdir_maxsz)
4401da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4419b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4421da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4439104a55dSTrond Myklebust 				decode_readdir_maxsz)
4441da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4459b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4461da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4479104a55dSTrond Myklebust 				encode_write_maxsz + \
4484f9838c7STrond Myklebust 				encode_getattr_maxsz)
4491da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4509b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4511da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4529104a55dSTrond Myklebust 				decode_write_maxsz + \
4534f9838c7STrond Myklebust 				decode_getattr_maxsz)
4541da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4559b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4561da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4578582715eSTrond Myklebust 				encode_commit_maxsz)
4581da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4599b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4601da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4618582715eSTrond Myklebust 				decode_commit_maxsz)
4621da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4639b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4641da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4652cebf828STrond Myklebust 				encode_open_maxsz + \
4666168f62cSWeston Andros Adamson 				encode_access_maxsz + \
4672cebf828STrond Myklebust 				encode_getfh_maxsz + \
4682cebf828STrond Myklebust 				encode_getattr_maxsz)
4691da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4709b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4711da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4722cebf828STrond Myklebust 				decode_open_maxsz + \
4736168f62cSWeston Andros Adamson 				decode_access_maxsz + \
4742cebf828STrond Myklebust 				decode_getfh_maxsz + \
4752cebf828STrond Myklebust 				decode_getattr_maxsz)
4761da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
4771da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4781da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4799104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
4809104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
4819104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
4821da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4839104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
4841da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
4859b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
4861da177e4SLinus Torvalds 					encode_putfh_maxsz + \
4872cebf828STrond Myklebust 					encode_open_maxsz + \
4886168f62cSWeston Andros Adamson 					encode_access_maxsz + \
4892cebf828STrond Myklebust 					encode_getattr_maxsz)
4901da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
4919b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
4921da177e4SLinus Torvalds 					decode_putfh_maxsz + \
4932cebf828STrond Myklebust 					decode_open_maxsz + \
4946168f62cSWeston Andros Adamson 					decode_access_maxsz + \
4952cebf828STrond Myklebust 					decode_getattr_maxsz)
4961da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
4971da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4989b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
4991da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5009104a55dSTrond Myklebust 				 encode_open_downgrade_maxsz + \
501516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5021da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
5031da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5049b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5051da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5069104a55dSTrond Myklebust 				 decode_open_downgrade_maxsz + \
507516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5081da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
5099b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5101da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5119104a55dSTrond Myklebust 				 encode_close_maxsz + \
512516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5131da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
5149b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5151da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5169104a55dSTrond Myklebust 				 decode_close_maxsz + \
517516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5181da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
5199b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5201da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5219104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
5221da177e4SLinus Torvalds 				 encode_getattr_maxsz)
5231da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
5249b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5251da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5269104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
5279104a55dSTrond Myklebust 				 decode_getattr_maxsz)
5281da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5299b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5301da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5311da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5321da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5339b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5341da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5351da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5361da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5371da177e4SLinus Torvalds 				encode_renew_maxsz)
5381da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5391da177e4SLinus Torvalds 				decode_renew_maxsz)
5401da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5411da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5421da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5431da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5441da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5451da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
54683ca7f5aSChuck Lever 				encode_setclientid_confirm_maxsz)
5471da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5481da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
54983ca7f5aSChuck Lever 				decode_setclientid_confirm_maxsz)
5501da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5519b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5521da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5539104a55dSTrond Myklebust 				encode_lock_maxsz)
5541da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5559b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5561da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5579104a55dSTrond Myklebust 				decode_lock_maxsz)
5581da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5599b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5601da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5619104a55dSTrond Myklebust 				encode_lockt_maxsz)
5629104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5639b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5649104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5659104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5661da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5679b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5681da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5699104a55dSTrond Myklebust 				encode_locku_maxsz)
5701da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5719b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5721da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5739104a55dSTrond Myklebust 				decode_locku_maxsz)
574d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
575d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
576d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
577d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
578d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
579d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
5801da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
5819b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5821da177e4SLinus Torvalds 				encode_putfh_maxsz + \
58376b32999STrond Myklebust 				encode_access_maxsz + \
58476b32999STrond Myklebust 				encode_getattr_maxsz)
5851da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
5869b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5871da177e4SLinus Torvalds 				decode_putfh_maxsz + \
58876b32999STrond Myklebust 				decode_access_maxsz + \
58976b32999STrond Myklebust 				decode_getattr_maxsz)
5901da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
5919b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5921da177e4SLinus Torvalds 				encode_putfh_maxsz + \
59344c99933SChuck Lever 				encode_getattr_maxsz + \
59444c99933SChuck Lever 				encode_renew_maxsz)
5951da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
5969b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5971da177e4SLinus Torvalds 				decode_putfh_maxsz + \
59844c99933SChuck Lever 				decode_getattr_maxsz + \
59944c99933SChuck Lever 				decode_renew_maxsz)
6001da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
6019b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6021da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6031da177e4SLinus Torvalds 				encode_lookup_maxsz + \
6041da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6051da177e4SLinus Torvalds 				encode_getfh_maxsz)
6061da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
6079b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6081da177e4SLinus Torvalds 				decode_putfh_maxsz + \
609e6889620STrond Myklebust 				decode_lookup_maxsz + \
6101da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6111da177e4SLinus Torvalds 				decode_getfh_maxsz)
6121da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
6139b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6141da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
6151da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6161da177e4SLinus Torvalds 				encode_getfh_maxsz)
6171da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6189b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6191da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
6201da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6211da177e4SLinus Torvalds 				decode_getfh_maxsz)
6221da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
6239b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6241da177e4SLinus Torvalds 				encode_putfh_maxsz + \
625778d2817STrond Myklebust 				encode_remove_maxsz)
6261da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6279b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6281da177e4SLinus Torvalds 				decode_putfh_maxsz + \
629778d2817STrond Myklebust 				decode_remove_maxsz)
6301da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6319b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6321da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6331da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6341da177e4SLinus Torvalds 				encode_putfh_maxsz + \
635778d2817STrond Myklebust 				encode_rename_maxsz)
6361da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6379b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6381da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6391da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6401da177e4SLinus Torvalds 				decode_putfh_maxsz + \
641778d2817STrond Myklebust 				decode_rename_maxsz)
6421da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6439b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6441da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6451da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6461da177e4SLinus Torvalds 				encode_putfh_maxsz + \
64791ba2eeeSTrond Myklebust 				encode_link_maxsz + \
64891ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
649a9f6991bSTrond Myklebust 				encode_getattr_maxsz)
6501da177e4SLinus Torvalds #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
6519b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6521da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6531da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6541da177e4SLinus Torvalds 				decode_putfh_maxsz + \
65591ba2eeeSTrond Myklebust 				decode_link_maxsz + \
65691ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
65791ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6581da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6599b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6601da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6611da177e4SLinus Torvalds 				encode_symlink_maxsz + \
6621da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6631da177e4SLinus Torvalds 				encode_getfh_maxsz)
6641da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
6659b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6661da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6671da177e4SLinus Torvalds 				decode_symlink_maxsz + \
6681da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6691da177e4SLinus Torvalds 				decode_getfh_maxsz)
6701da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
6719b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6721da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6731da177e4SLinus Torvalds 				encode_create_maxsz + \
67456ae19f3STrond Myklebust 				encode_getfh_maxsz + \
67556ae19f3STrond Myklebust 				encode_getattr_maxsz)
6761da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
6779b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6781da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6791da177e4SLinus Torvalds 				decode_create_maxsz + \
68056ae19f3STrond Myklebust 				decode_getfh_maxsz + \
68156ae19f3STrond Myklebust 				decode_getattr_maxsz)
6821da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
6839b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6841da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6851da177e4SLinus Torvalds 				encode_getattr_maxsz)
6861da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
6879b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6881da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6891da177e4SLinus Torvalds 				decode_getattr_maxsz)
6901da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
6919b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6921da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6939104a55dSTrond Myklebust 				encode_statfs_maxsz)
6941da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
6959b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6961da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6979104a55dSTrond Myklebust 				decode_statfs_maxsz)
6981da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
6999b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
700ab91f264STrond Myklebust 				encode_putfh_maxsz + \
7011da177e4SLinus Torvalds 				encode_getattr_maxsz)
7021da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
7039b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
704ab91f264STrond Myklebust 				decode_putfh_maxsz + \
7051da177e4SLinus Torvalds 				decode_getattr_maxsz)
7061da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
7079b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7081da177e4SLinus Torvalds 				encode_putfh_maxsz + \
709fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
710fa178f29STrond Myklebust 				encode_getattr_maxsz)
7111da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7129b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
713fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
714fa178f29STrond Myklebust 				decode_getattr_maxsz)
715029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
7169b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
717029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7189104a55dSTrond Myklebust 				encode_getacl_maxsz)
719029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7209b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
721029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7229104a55dSTrond Myklebust 				decode_getacl_maxsz)
72323ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7249b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
72523ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7269104a55dSTrond Myklebust 				encode_setacl_maxsz)
72723ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7289b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
72923ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7309104a55dSTrond Myklebust 				decode_setacl_maxsz)
731683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
732683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7339b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
734683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
735e6889620STrond Myklebust 				 encode_lookup_maxsz + \
736b03d735bSChuck Lever 				 encode_fs_locations_maxsz + \
737b03d735bSChuck Lever 				 encode_renew_maxsz)
738683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
739683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7409b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
741683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
742e6889620STrond Myklebust 				 decode_lookup_maxsz + \
743b03d735bSChuck Lever 				 decode_fs_locations_maxsz + \
744b03d735bSChuck Lever 				 decode_renew_maxsz)
7455a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7465a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7475a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7485a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7495a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7505a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7515a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7525a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
75344c99933SChuck Lever #define NFS4_enc_fsid_present_sz \
75444c99933SChuck Lever 				(compound_encode_hdr_maxsz + \
75544c99933SChuck Lever 				 encode_sequence_maxsz + \
75644c99933SChuck Lever 				 encode_putfh_maxsz + \
75744c99933SChuck Lever 				 encode_getfh_maxsz + \
75844c99933SChuck Lever 				 encode_renew_maxsz)
75944c99933SChuck Lever #define NFS4_dec_fsid_present_sz \
76044c99933SChuck Lever 				(compound_decode_hdr_maxsz + \
76144c99933SChuck Lever 				 decode_sequence_maxsz + \
76244c99933SChuck Lever 				 decode_putfh_maxsz + \
76344c99933SChuck Lever 				 decode_getfh_maxsz + \
76444c99933SChuck Lever 				 decode_renew_maxsz)
76599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
7667c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
7677c44f1aeSWeston Andros Adamson 				(compound_encode_hdr_maxsz + \
7687c44f1aeSWeston Andros Adamson 				 encode_bind_conn_to_session_maxsz)
7697c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
7707c44f1aeSWeston Andros Adamson 				(compound_decode_hdr_maxsz + \
7717c44f1aeSWeston Andros Adamson 				 decode_bind_conn_to_session_maxsz)
77299fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
77399fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
77499fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
77599fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
77699fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
77799fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
778fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
779fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
780fc931582SAndy Adamson 				 encode_create_session_maxsz)
781fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
782fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
783fc931582SAndy Adamson 				 decode_create_session_maxsz)
7840f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
7850f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
7860f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
7870f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
78866245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
78966245539STrond Myklebust 					 encode_destroy_clientid_maxsz)
79066245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
79166245539STrond Myklebust 					 decode_destroy_clientid_maxsz)
792fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
793fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
794fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
795fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
796fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
797fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
7982050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
7992050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
8002050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
8012050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
8022050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
8032050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
8042050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
8052050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
80618019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
80718019753SRicardo Labiaga 					 encode_sequence_maxsz + \
80818019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
80918019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
81018019753SRicardo Labiaga 					 decode_sequence_maxsz + \
81118019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
8127f11d8d3SAndy Adamson #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
8137f11d8d3SAndy Adamson 				encode_sequence_maxsz + \
8147f11d8d3SAndy Adamson 				encode_putfh_maxsz + \
8157f11d8d3SAndy Adamson 				encode_getdevicelist_maxsz)
8167f11d8d3SAndy Adamson #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
8177f11d8d3SAndy Adamson 				decode_sequence_maxsz + \
8187f11d8d3SAndy Adamson 				decode_putfh_maxsz + \
8197f11d8d3SAndy Adamson 				decode_getdevicelist_maxsz)
820b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
821b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
822b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
823b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
824b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
825b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
826b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
827b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
828b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
829b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
830b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
831b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
832b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
833b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
834863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
835863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
836863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
837863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
838863a3c6cSAndy Adamson 				encode_getattr_maxsz)
839863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
840863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
841863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
842863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
843863a3c6cSAndy Adamson 				decode_getattr_maxsz)
844cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
845cbe82603SBenny Halevy 				encode_sequence_maxsz + \
846cbe82603SBenny Halevy 				encode_putfh_maxsz + \
847cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
848cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
849cbe82603SBenny Halevy 				decode_sequence_maxsz + \
850cbe82603SBenny Halevy 				decode_putfh_maxsz + \
851cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
852fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
853fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
854fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
855fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
856fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
857fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
858fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
859fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8607d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8617d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8627d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8637d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
8647d974794SBryan Schumaker 					 decode_sequence_maxsz + \
8657d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
8669aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
8679aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
8689aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
8699aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
8709aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
8719aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
8722449ea2eSAlexandros Batsakis 
8732449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8742449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
8752449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
8762449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
8772449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
8782449ea2eSAlexandros Batsakis 				     XDR_UNIT);
8792449ea2eSAlexandros Batsakis 
8802449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8812449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
8822449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
8832449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
8842449ea2eSAlexandros Batsakis 				    XDR_UNIT);
885f1c097beSAndy Adamson 
886f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
887f1c097beSAndy Adamson 					   compound_decode_hdr_maxsz +
888f1c097beSAndy Adamson 					   decode_sequence_maxsz) *
889f1c097beSAndy Adamson 					  XDR_UNIT);
890f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
89199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
8921da177e4SLinus Torvalds 
893bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
894bca79478STrond Myklebust 	[NF4BAD] = 0,
895bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
896bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
897bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
898bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
899bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
900bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
901bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
902bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
903bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
9041da177e4SLinus Torvalds };
9051da177e4SLinus Torvalds 
9061da177e4SLinus Torvalds struct compound_hdr {
9071da177e4SLinus Torvalds 	int32_t		status;
9081da177e4SLinus Torvalds 	uint32_t	nops;
909d017931cSAndy Adamson 	__be32 *	nops_p;
9101da177e4SLinus Torvalds 	uint32_t	taglen;
9111da177e4SLinus Torvalds 	char *		tag;
9120c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
91366cc0429SBenny Halevy 	u32		minorversion;
9141da177e4SLinus Torvalds };
9151da177e4SLinus Torvalds 
91613c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
91713c65ce9SBenny Halevy {
91813c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
91913c65ce9SBenny Halevy 	BUG_ON(!p);
92013c65ce9SBenny Halevy 	return p;
92113c65ce9SBenny Halevy }
9221da177e4SLinus Torvalds 
923cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
924cb17e556STrond Myklebust {
925cb17e556STrond Myklebust 	__be32 *p;
926cb17e556STrond Myklebust 
927cb17e556STrond Myklebust 	p = xdr_reserve_space(xdr, len);
928cb17e556STrond Myklebust 	xdr_encode_opaque_fixed(p, buf, len);
929cb17e556STrond Myklebust }
930cb17e556STrond Myklebust 
9311da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
9321da177e4SLinus Torvalds {
9338687b63aSAl Viro 	__be32 *p;
9341da177e4SLinus Torvalds 
9356fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 4 + len);
9361da177e4SLinus Torvalds 	xdr_encode_opaque(p, str, len);
9371da177e4SLinus Torvalds }
9381da177e4SLinus Torvalds 
9394ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9404ade9821STrond Myklebust {
9414ade9821STrond Myklebust 	__be32 *p;
9424ade9821STrond Myklebust 
9434ade9821STrond Myklebust 	p = reserve_space(xdr, 4);
9444ade9821STrond Myklebust 	*p = cpu_to_be32(n);
9454ade9821STrond Myklebust }
9464ade9821STrond Myklebust 
947ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
948ff2eb681STrond Myklebust {
949ff2eb681STrond Myklebust 	__be32 *p;
950ff2eb681STrond Myklebust 
951ff2eb681STrond Myklebust 	p = reserve_space(xdr, 8);
952ff2eb681STrond Myklebust 	xdr_encode_hyper(p, n);
953ff2eb681STrond Myklebust }
954ff2eb681STrond Myklebust 
9554ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
9564ade9821STrond Myklebust 		const struct nfs_seqid *seqid)
9574ade9821STrond Myklebust {
9584ade9821STrond Myklebust 	encode_uint32(xdr, seqid->sequence->counter);
9594ade9821STrond Myklebust }
9604ade9821STrond Myklebust 
9610c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
9620c4e8c18SBenny Halevy 				struct rpc_rqst *req,
9630c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
9641da177e4SLinus Torvalds {
9658687b63aSAl Viro 	__be32 *p;
966a17c2153STrond Myklebust 	struct rpc_auth *auth = req->rq_cred->cr_auth;
9670c4e8c18SBenny Halevy 
9680c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
9690c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
9700c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
9710c4e8c18SBenny Halevy 	hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
9721da177e4SLinus Torvalds 
9737fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
9746fdfb0bcSTrond Myklebust 	encode_string(xdr, hdr->taglen, hdr->tag);
9756fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 8);
976e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
977d017931cSAndy Adamson 	hdr->nops_p = p;
97834558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
979d017931cSAndy Adamson }
980d017931cSAndy Adamson 
981ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
982ab19b481STrond Myklebust 		uint32_t replen,
983ab19b481STrond Myklebust 		struct compound_hdr *hdr)
984ab19b481STrond Myklebust {
985ab19b481STrond Myklebust 	encode_uint32(xdr, op);
986ab19b481STrond Myklebust 	hdr->nops++;
987ab19b481STrond Myklebust 	hdr->replen += replen;
988ab19b481STrond Myklebust }
989ab19b481STrond Myklebust 
990d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
991d017931cSAndy Adamson {
9927fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
993d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
9941da177e4SLinus Torvalds }
9951da177e4SLinus Torvalds 
996ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
997ea9d23f5STrond Myklebust {
9982d2f24adSTrond Myklebust 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
999ea9d23f5STrond Myklebust }
1000ea9d23f5STrond Myklebust 
10011da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
10021da177e4SLinus Torvalds {
1003cb17e556STrond Myklebust 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
10041da177e4SLinus Torvalds }
10051da177e4SLinus Torvalds 
1006aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1007aa9c2669SDavid Quigley 				const struct nfs4_label *label,
1008aa9c2669SDavid Quigley 				const struct nfs_server *server)
10091da177e4SLinus Torvalds {
10101da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
10111da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
10121da177e4SLinus Torvalds 	int owner_namelen = 0;
10131da177e4SLinus Torvalds 	int owner_grouplen = 0;
10148687b63aSAl Viro 	__be32 *p;
1015d7067b2dSTrond Myklebust 	unsigned i;
1016d7067b2dSTrond Myklebust 	uint32_t len = 0;
1017d7067b2dSTrond Myklebust 	uint32_t bmval_len;
1018d7067b2dSTrond Myklebust 	uint32_t bmval[3] = { 0 };
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds 	/*
10211da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
10221da177e4SLinus Torvalds 	 * In the worst-case, this would be
1023a09df2caSDavid Quigley 	 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1024a09df2caSDavid Quigley 	 * = 40 bytes, plus any contribution from variable-length fields
102523ec6965SJ. Bruce Fields 	 *            such as owner/group.
10261da177e4SLinus Torvalds 	 */
1027d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_SIZE) {
1028d7067b2dSTrond Myklebust 		bmval[0] |= FATTR4_WORD0_SIZE;
10291da177e4SLinus Torvalds 		len += 8;
1030d7067b2dSTrond Myklebust 	}
1031d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MODE) {
1032d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_MODE;
10331da177e4SLinus Torvalds 		len += 4;
1034d7067b2dSTrond Myklebust 	}
10351da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
1036e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
10371da177e4SLinus Torvalds 		if (owner_namelen < 0) {
1038fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
1039e5782076SEric W. Biederman 					from_kuid(&init_user_ns, iap->ia_uid));
10401da177e4SLinus Torvalds 			/* XXX */
10411da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
10421da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
10431da177e4SLinus Torvalds 			/* goto out; */
10441da177e4SLinus Torvalds 		}
1045d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER;
10461da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
10471da177e4SLinus Torvalds 	}
10481da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
1049e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
10501da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
1051fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
1052e5782076SEric W. Biederman 					from_kgid(&init_user_ns, iap->ia_gid));
10531da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
10541da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
10551da177e4SLinus Torvalds 			/* goto out; */
10561da177e4SLinus Torvalds 		}
1057d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
10581da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
10591da177e4SLinus Torvalds 	}
1060d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_ATIME_SET) {
1061d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
10621da177e4SLinus Torvalds 		len += 16;
1063d7067b2dSTrond Myklebust 	} else if (iap->ia_valid & ATTR_ATIME) {
1064d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
10651da177e4SLinus Torvalds 		len += 4;
1066d7067b2dSTrond Myklebust 	}
1067d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MTIME_SET) {
1068d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
10691da177e4SLinus Torvalds 		len += 16;
1070d7067b2dSTrond Myklebust 	} else if (iap->ia_valid & ATTR_MTIME) {
1071d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
10721da177e4SLinus Torvalds 		len += 4;
1073d7067b2dSTrond Myklebust 	}
1074b4a2cf76STrond Myklebust 	if (label) {
1075b4a2cf76STrond Myklebust 		len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1076d7067b2dSTrond Myklebust 		bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1077d7067b2dSTrond Myklebust 	}
1078d7067b2dSTrond Myklebust 
1079d7067b2dSTrond Myklebust 	if (bmval[2] != 0)
1080b4a2cf76STrond Myklebust 		bmval_len = 3;
1081d7067b2dSTrond Myklebust 	else if (bmval[1] != 0)
1082d7067b2dSTrond Myklebust 		bmval_len = 2;
1083d7067b2dSTrond Myklebust 	else
1084d7067b2dSTrond Myklebust 		bmval_len = 1;
1085b4a2cf76STrond Myklebust 
1086d7067b2dSTrond Myklebust 	p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
10871da177e4SLinus Torvalds 
1088b4a2cf76STrond Myklebust 	*p++ = cpu_to_be32(bmval_len);
1089d7067b2dSTrond Myklebust 	for (i = 0; i < bmval_len; i++)
1090d7067b2dSTrond Myklebust 		*p++ = cpu_to_be32(bmval[i]);
1091d7067b2dSTrond Myklebust 	*p++ = cpu_to_be32(len);
10921da177e4SLinus Torvalds 
1093d7067b2dSTrond Myklebust 	if (bmval[0] & FATTR4_WORD0_SIZE)
1094b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
1095d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_MODE)
1096e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1097d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER)
1098811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
1099d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1100811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1101d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
11021da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_ATIME_SET) {
1103e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1104042ad0b3SBryan Schumaker 			p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1105d3f6baaaSTrond Myklebust 			*p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1106d7067b2dSTrond Myklebust 		} else
1107e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11081da177e4SLinus Torvalds 	}
1109d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
11101da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_MTIME_SET) {
1111e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1112042ad0b3SBryan Schumaker 			p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1113e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1114d7067b2dSTrond Myklebust 		} else
1115e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11161da177e4SLinus Torvalds 	}
1117d7067b2dSTrond Myklebust 	if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1118aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->lfs);
1119aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->pi);
1120aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->len);
1121aa9c2669SDavid Quigley 		p = xdr_encode_opaque_fixed(p, label->label, label->len);
1122aa9c2669SDavid Quigley 	}
11231da177e4SLinus Torvalds 
11241da177e4SLinus Torvalds /* out: */
11251da177e4SLinus Torvalds }
11261da177e4SLinus Torvalds 
1127cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
11281da177e4SLinus Torvalds {
1129475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1130475d4ba0STrond Myklebust 	encode_uint32(xdr, access);
11311da177e4SLinus Torvalds }
11321da177e4SLinus Torvalds 
1133cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
11341da177e4SLinus Torvalds {
1135ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
11364ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1137ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
11381da177e4SLinus Torvalds }
11391da177e4SLinus Torvalds 
11400b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
11411da177e4SLinus Torvalds {
11428687b63aSAl Viro 	__be32 *p;
11431da177e4SLinus Torvalds 
1144475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1145475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1146b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
114734558513SBenny Halevy 	*p = cpu_to_be32(args->count);
11481da177e4SLinus Torvalds }
11491da177e4SLinus Torvalds 
1150cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
11511da177e4SLinus Torvalds {
11528687b63aSAl Viro 	__be32 *p;
11531da177e4SLinus Torvalds 
1154475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1155475d4ba0STrond Myklebust 	encode_uint32(xdr, create->ftype);
11561da177e4SLinus Torvalds 
11571da177e4SLinus Torvalds 	switch (create->ftype) {
11581da177e4SLinus Torvalds 	case NF4LNK:
115913c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
116034558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
116194a6d753SChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
11621da177e4SLinus Torvalds 		break;
11631da177e4SLinus Torvalds 
11641da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
116513c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1166e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
116734558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
11681da177e4SLinus Torvalds 		break;
11691da177e4SLinus Torvalds 
11701da177e4SLinus Torvalds 	default:
11711da177e4SLinus Torvalds 		break;
11721da177e4SLinus Torvalds 	}
11731da177e4SLinus Torvalds 
1174811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
1175aa9c2669SDavid Quigley 	encode_attrs(xdr, create->attrs, create->label, create->server);
11761da177e4SLinus Torvalds }
11771da177e4SLinus Torvalds 
1178cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
11791da177e4SLinus Torvalds {
11808687b63aSAl Viro 	__be32 *p;
11811da177e4SLinus Torvalds 
1182475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1183475d4ba0STrond Myklebust 	p = reserve_space(xdr, 8);
1184e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
118534558513SBenny Halevy 	*p = cpu_to_be32(bitmap);
11861da177e4SLinus Torvalds }
11871da177e4SLinus Torvalds 
1188cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
11891da177e4SLinus Torvalds {
11908687b63aSAl Viro 	__be32 *p;
11911da177e4SLinus Torvalds 
1192475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1193475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1194e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
1195e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(bm0);
119634558513SBenny Halevy 	*p = cpu_to_be32(bm1);
11971da177e4SLinus Torvalds }
11981da177e4SLinus Torvalds 
1199dae100c2SFred Isaman static void
1200dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr,
1201dae100c2SFred Isaman 		     uint32_t bm0, uint32_t bm1, uint32_t bm2,
1202dae100c2SFred Isaman 		     struct compound_hdr *hdr)
1203dae100c2SFred Isaman {
1204dae100c2SFred Isaman 	__be32 *p;
1205dae100c2SFred Isaman 
1206ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1207dae100c2SFred Isaman 	if (bm2) {
1208dae100c2SFred Isaman 		p = reserve_space(xdr, 16);
1209dae100c2SFred Isaman 		*p++ = cpu_to_be32(3);
1210dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1211dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm1);
1212dae100c2SFred Isaman 		*p = cpu_to_be32(bm2);
1213dae100c2SFred Isaman 	} else if (bm1) {
1214dae100c2SFred Isaman 		p = reserve_space(xdr, 12);
1215dae100c2SFred Isaman 		*p++ = cpu_to_be32(2);
1216dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1217dae100c2SFred Isaman 		*p = cpu_to_be32(bm1);
1218dae100c2SFred Isaman 	} else {
1219dae100c2SFred Isaman 		p = reserve_space(xdr, 8);
1220dae100c2SFred Isaman 		*p++ = cpu_to_be32(1);
1221dae100c2SFred Isaman 		*p = cpu_to_be32(bm0);
1222dae100c2SFred Isaman 	}
1223dae100c2SFred Isaman }
1224dae100c2SFred Isaman 
1225cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12261da177e4SLinus Torvalds {
1227a09df2caSDavid Quigley 	encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1228a09df2caSDavid Quigley 			   bitmask[1] & nfs4_fattr_bitmap[1],
1229a09df2caSDavid Quigley 			   bitmask[2] & nfs4_fattr_bitmap[2],
1230a09df2caSDavid Quigley 			   hdr);
12311da177e4SLinus Torvalds }
12321da177e4SLinus Torvalds 
123388034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
12341549210fSTrond Myklebust 				 const u32 *open_bitmap,
123588034c3dSAndy Adamson 				 struct compound_hdr *hdr)
123688034c3dSAndy Adamson {
123788034c3dSAndy Adamson 	encode_getattr_three(xdr,
12381549210fSTrond Myklebust 			     bitmask[0] & open_bitmap[0],
12391549210fSTrond Myklebust 			     bitmask[1] & open_bitmap[1],
12401549210fSTrond Myklebust 			     bitmask[2] & open_bitmap[2],
124188034c3dSAndy Adamson 			     hdr);
124288034c3dSAndy Adamson }
124388034c3dSAndy Adamson 
1244cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12451da177e4SLinus Torvalds {
1246dae100c2SFred Isaman 	encode_getattr_three(xdr,
1247dae100c2SFred Isaman 			     bitmask[0] & nfs4_fsinfo_bitmap[0],
1248dae100c2SFred Isaman 			     bitmask[1] & nfs4_fsinfo_bitmap[1],
1249dae100c2SFred Isaman 			     bitmask[2] & nfs4_fsinfo_bitmap[2],
1250dae100c2SFred Isaman 			     hdr);
12511da177e4SLinus Torvalds }
12521da177e4SLinus Torvalds 
1253cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1254830b8e33SManoj Naik {
1255cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1256cf8cdbe5SAndy Adamson 			   bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1257830b8e33SManoj Naik }
1258830b8e33SManoj Naik 
1259cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12601da177e4SLinus Torvalds {
1261ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12621da177e4SLinus Torvalds }
12631da177e4SLinus Torvalds 
1264cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12651da177e4SLinus Torvalds {
1266ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
12676fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
12681da177e4SLinus Torvalds }
12691da177e4SLinus Torvalds 
1270911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1271911d1aafSTrond Myklebust {
1272f44106e2SJeff Layton 	if (fl->fl_type == F_RDLCK)
1273911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1274911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1275911d1aafSTrond Myklebust }
1276911d1aafSTrond Myklebust 
1277911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1278911d1aafSTrond Myklebust {
1279911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1280911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1281911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1282911d1aafSTrond Myklebust }
1283911d1aafSTrond Myklebust 
1284daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1285daccbdedSTrond Myklebust {
1286daccbdedSTrond Myklebust 	__be32 *p;
1287daccbdedSTrond Myklebust 
1288d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1289daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1290d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1291daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1292d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1293daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1294daccbdedSTrond Myklebust }
1295daccbdedSTrond Myklebust 
12961da177e4SLinus Torvalds /*
12971da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
12981da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
12991da177e4SLinus Torvalds  */
1300cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
13011da177e4SLinus Torvalds {
13028687b63aSAl Viro 	__be32 *p;
13031da177e4SLinus Torvalds 
1304475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1305475d4ba0STrond Myklebust 	p = reserve_space(xdr, 28);
1306e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1307e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1308b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1309b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
131034558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1311911d1aafSTrond Myklebust 	if (args->new_lock_owner){
13124ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->open_seqid);
1313ea9d23f5STrond Myklebust 		encode_nfs4_stateid(xdr, args->open_stateid);
13144ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
1315daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
13161da177e4SLinus Torvalds 	}
13171da177e4SLinus Torvalds 	else {
1318ea9d23f5STrond Myklebust 		encode_nfs4_stateid(xdr, args->lock_stateid);
13194ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
13201da177e4SLinus Torvalds 	}
13211da177e4SLinus Torvalds }
13221da177e4SLinus Torvalds 
1323cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
13241da177e4SLinus Torvalds {
13258687b63aSAl Viro 	__be32 *p;
13261da177e4SLinus Torvalds 
1327475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1328475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1329e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1330b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1331b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1332daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
13331da177e4SLinus Torvalds }
13341da177e4SLinus Torvalds 
1335cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
13361da177e4SLinus Torvalds {
13378687b63aSAl Viro 	__be32 *p;
13381da177e4SLinus Torvalds 
1339475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1340475d4ba0STrond Myklebust 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13414ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, args->seqid);
1342ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
1343ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1344b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
134534558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13461da177e4SLinus Torvalds }
13471da177e4SLinus Torvalds 
1348d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1349d3c7b7ccSTrond Myklebust {
1350ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1351d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1352d3c7b7ccSTrond Myklebust }
1353d3c7b7ccSTrond Myklebust 
1354cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13551da177e4SLinus Torvalds {
1356ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13576fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
13581da177e4SLinus Torvalds }
13591da177e4SLinus Torvalds 
1360dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
13611da177e4SLinus Torvalds {
13628687b63aSAl Viro 	__be32 *p;
13631da177e4SLinus Torvalds 
136413c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1365dc0b027dSTrond Myklebust 	switch (fmode & (FMODE_READ|FMODE_WRITE)) {
13661da177e4SLinus Torvalds 	case FMODE_READ:
1367e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
13681da177e4SLinus Torvalds 		break;
13691da177e4SLinus Torvalds 	case FMODE_WRITE:
1370e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
13711da177e4SLinus Torvalds 		break;
13721da177e4SLinus Torvalds 	case FMODE_READ|FMODE_WRITE:
1373e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
13741da177e4SLinus Torvalds 		break;
13751da177e4SLinus Torvalds 	default:
1376e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
13771da177e4SLinus Torvalds 	}
137834558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13791da177e4SLinus Torvalds }
13801da177e4SLinus Torvalds 
13811da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13821da177e4SLinus Torvalds {
13838687b63aSAl Viro 	__be32 *p;
13841da177e4SLinus Torvalds  /*
13851da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
13861da177e4SLinus Torvalds  * owner 4 = 32
13871da177e4SLinus Torvalds  */
13884ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1389dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
139095b72eb0STrond Myklebust 	p = reserve_space(xdr, 36);
1391b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
139295b72eb0STrond Myklebust 	*p++ = cpu_to_be32(24);
139393f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1394d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
139595b72eb0STrond Myklebust 	*p++ = cpu_to_be32(arg->id.uniquifier);
139695b72eb0STrond Myklebust 	xdr_encode_hyper(p, arg->id.create_time);
13971da177e4SLinus Torvalds }
13981da177e4SLinus Torvalds 
13991da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14001da177e4SLinus Torvalds {
1401549b19ccSTrond Myklebust 	struct iattr dummy;
14028687b63aSAl Viro 	__be32 *p;
14031da177e4SLinus Torvalds 
140413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
1405549b19ccSTrond Myklebust 	switch(arg->createmode) {
1406549b19ccSTrond Myklebust 	case NFS4_CREATE_UNCHECKED:
140734558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1408aa9c2669SDavid Quigley 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
14091da177e4SLinus Torvalds 		break;
1410549b19ccSTrond Myklebust 	case NFS4_CREATE_GUARDED:
14114882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
1412aa9c2669SDavid Quigley 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
1413549b19ccSTrond Myklebust 		break;
1414549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE:
1415549b19ccSTrond Myklebust 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1416549b19ccSTrond Myklebust 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1417549b19ccSTrond Myklebust 		break;
1418549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE4_1:
14194882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
14204882ef72SAlexandros Batsakis 		encode_nfs4_verifier(xdr, &arg->u.verifier);
14214882ef72SAlexandros Batsakis 		dummy.ia_valid = 0;
1422aa9c2669SDavid Quigley 		encode_attrs(xdr, &dummy, arg->label, arg->server);
14234882ef72SAlexandros Batsakis 	}
14244882ef72SAlexandros Batsakis }
14251da177e4SLinus Torvalds 
14261da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14271da177e4SLinus Torvalds {
14288687b63aSAl Viro 	__be32 *p;
14291da177e4SLinus Torvalds 
143013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14311da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14321da177e4SLinus Torvalds 	case 0:
143334558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14341da177e4SLinus Torvalds 		break;
14351da177e4SLinus Torvalds 	default:
143634558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14371da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14381da177e4SLinus Torvalds 	}
14391da177e4SLinus Torvalds }
14401da177e4SLinus Torvalds 
1441bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14421da177e4SLinus Torvalds {
14438687b63aSAl Viro 	__be32 *p;
14441da177e4SLinus Torvalds 
144513c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14461da177e4SLinus Torvalds 	switch (delegation_type) {
14471da177e4SLinus Torvalds 	case 0:
144834558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14491da177e4SLinus Torvalds 		break;
14501da177e4SLinus Torvalds 	case FMODE_READ:
145134558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14521da177e4SLinus Torvalds 		break;
14531da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
145434558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14551da177e4SLinus Torvalds 		break;
14561da177e4SLinus Torvalds 	default:
14571da177e4SLinus Torvalds 		BUG();
14581da177e4SLinus Torvalds 	}
14591da177e4SLinus Torvalds }
14601da177e4SLinus Torvalds 
14611da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14621da177e4SLinus Torvalds {
14638687b63aSAl Viro 	__be32 *p;
14641da177e4SLinus Torvalds 
146513c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
146634558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14671da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14681da177e4SLinus Torvalds }
14691da177e4SLinus Torvalds 
1470bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14711da177e4SLinus Torvalds {
14728687b63aSAl Viro 	__be32 *p;
14731da177e4SLinus Torvalds 
147413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
147534558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14761da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14771da177e4SLinus Torvalds }
14781da177e4SLinus Torvalds 
14791da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14801da177e4SLinus Torvalds {
14818687b63aSAl Viro 	__be32 *p;
14821da177e4SLinus Torvalds 
1483ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 4);
1484ea9d23f5STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1485ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
14861da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14871da177e4SLinus Torvalds }
14881da177e4SLinus Torvalds 
1489d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr)
1490d9fc6619STrond Myklebust {
1491d9fc6619STrond Myklebust 	__be32 *p;
1492d9fc6619STrond Myklebust 
1493d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1494d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1495d9fc6619STrond Myklebust }
1496d9fc6619STrond Myklebust 
1497d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1498d9fc6619STrond Myklebust {
1499d9fc6619STrond Myklebust 	__be32 *p;
1500d9fc6619STrond Myklebust 
1501d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1502d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1503d9fc6619STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
1504d9fc6619STrond Myklebust }
1505d9fc6619STrond Myklebust 
1506cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
15071da177e4SLinus Torvalds {
1508ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
15091da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
15101da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
15111da177e4SLinus Torvalds 	switch (arg->claim) {
15121da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
15131da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
15141da177e4SLinus Torvalds 		break;
15151da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
15161da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
15171da177e4SLinus Torvalds 		break;
15181da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
15191da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
15201da177e4SLinus Torvalds 		break;
1521d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_FH:
1522d9fc6619STrond Myklebust 		encode_claim_fh(xdr);
1523d9fc6619STrond Myklebust 		break;
1524d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1525d9fc6619STrond Myklebust 		encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1526d9fc6619STrond Myklebust 		break;
15271da177e4SLinus Torvalds 	default:
15281da177e4SLinus Torvalds 		BUG();
15291da177e4SLinus Torvalds 	}
15301da177e4SLinus Torvalds }
15311da177e4SLinus Torvalds 
1532cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
15331da177e4SLinus Torvalds {
1534ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1535ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
15364ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15371da177e4SLinus Torvalds }
15381da177e4SLinus Torvalds 
1539cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
15401da177e4SLinus Torvalds {
1541ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1542ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
15434ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1544dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
15451da177e4SLinus Torvalds }
15461da177e4SLinus Torvalds 
1547cf8cdbe5SAndy Adamson static void
1548d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15491da177e4SLinus Torvalds {
1550ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
15516fdfb0bcSTrond Myklebust 	encode_string(xdr, fh->size, fh->data);
15521da177e4SLinus Torvalds }
15531da177e4SLinus Torvalds 
1554cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15551da177e4SLinus Torvalds {
1556ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15571da177e4SLinus Torvalds }
15581da177e4SLinus Torvalds 
15593c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
15603c6b899cSAnna Schumaker 			struct compound_hdr *hdr)
15611da177e4SLinus Torvalds {
15628687b63aSAl Viro 	__be32 *p;
15631da177e4SLinus Torvalds 
1564ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
15659b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
15661da177e4SLinus Torvalds 
156713c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1568b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
156934558513SBenny Halevy 	*p = cpu_to_be32(args->count);
15701da177e4SLinus Torvalds }
15711da177e4SLinus Torvalds 
1572cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15731da177e4SLinus Torvalds {
1574aa9c2669SDavid Quigley 	uint32_t attrs[3] = {
157528331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
157628331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
157728331a46STrond Myklebust 	};
15786f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
1579cd93710eSChuck Lever 	__be32 *p, verf[2];
1580d204c5d2STrond Myklebust 	uint32_t attrlen = 0;
1581d204c5d2STrond Myklebust 	unsigned int i;
15821da177e4SLinus Torvalds 
158382f2e547SBryan Schumaker 	if (readdir->plus) {
158482f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
158528331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
158682f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
158782f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
158882f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
158982f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1590d204c5d2STrond Myklebust 		attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
15916f7a35bdSTrond Myklebust 		dircount >>= 1;
159282f2e547SBryan Schumaker 	}
159328331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
159428331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
159528331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
1596d204c5d2STrond Myklebust 	for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1597d204c5d2STrond Myklebust 		attrs[i] &= readdir->bitmask[i];
1598d204c5d2STrond Myklebust 		if (attrs[i] != 0)
1599d204c5d2STrond Myklebust 			attrlen = i+1;
1600d204c5d2STrond Myklebust 	}
16016f7a35bdSTrond Myklebust 
1602475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1603ff2eb681STrond Myklebust 	encode_uint64(xdr, readdir->cookie);
1604cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &readdir->verifier);
1605d204c5d2STrond Myklebust 	p = reserve_space(xdr, 12 + (attrlen << 2));
16066f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
16076f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
1608d204c5d2STrond Myklebust 	*p++ = cpu_to_be32(attrlen);
1609d204c5d2STrond Myklebust 	for (i = 0; i < attrlen; i++)
1610d204c5d2STrond Myklebust 		*p++ = cpu_to_be32(attrs[i]);
1611cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
1612aa9c2669SDavid Quigley 
1613aa9c2669SDavid Quigley 	dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
161444109241SFred Isaman 			__func__,
1615eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1616cd93710eSChuck Lever 			verf[0], verf[1],
1617eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1618aa9c2669SDavid Quigley 			attrs[1] & readdir->bitmask[1],
1619aa9c2669SDavid Quigley 			attrs[2] & readdir->bitmask[2]);
16201da177e4SLinus Torvalds }
16211da177e4SLinus Torvalds 
1622cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16231da177e4SLinus Torvalds {
1624ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
16251da177e4SLinus Torvalds }
16261da177e4SLinus Torvalds 
1627cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16281da177e4SLinus Torvalds {
1629ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
16306fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
16311da177e4SLinus Torvalds }
16321da177e4SLinus Torvalds 
1633cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16341da177e4SLinus Torvalds {
1635ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1636811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1637811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
16381da177e4SLinus Torvalds }
16391da177e4SLinus Torvalds 
1640bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16421da177e4SLinus Torvalds {
1643475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1644ff2eb681STrond Myklebust 	encode_uint64(xdr, clid);
16451da177e4SLinus Torvalds }
16461da177e4SLinus Torvalds 
1647cf8cdbe5SAndy Adamson static void
1648d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
164956ae19f3STrond Myklebust {
1650ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
165156ae19f3STrond Myklebust }
165256ae19f3STrond Myklebust 
16539f06c719SChuck Lever static void
1654d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
165523ec6965SJ. Bruce Fields {
16568687b63aSAl Viro 	__be32 *p;
165723ec6965SJ. Bruce Fields 
1658ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1659ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &zero_stateid);
166013c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1661e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
166234558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
166313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
166434558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
166523ec6965SJ. Bruce Fields 	xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
166623ec6965SJ. Bruce Fields }
166723ec6965SJ. Bruce Fields 
1668cf8cdbe5SAndy Adamson static void
1669d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16701da177e4SLinus Torvalds {
1671ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
16721da177e4SLinus Torvalds }
16731da177e4SLinus Torvalds 
1674cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16751da177e4SLinus Torvalds {
1676ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1677ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
1678aa9c2669SDavid Quigley 	encode_attrs(xdr, arg->iap, arg->label, server);
16791da177e4SLinus Torvalds }
16801da177e4SLinus Torvalds 
1681cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
16821da177e4SLinus Torvalds {
16838687b63aSAl Viro 	__be32 *p;
16841da177e4SLinus Torvalds 
168570019514STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1686cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
16871da177e4SLinus Torvalds 
16881da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
168913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
169034558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
16911da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
16921da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
169313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
169434558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_cb_ident);
16951da177e4SLinus Torvalds }
16961da177e4SLinus Torvalds 
1697bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
16981da177e4SLinus Torvalds {
1699475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1700475d4ba0STrond Myklebust 			decode_setclientid_confirm_maxsz, hdr);
1701ff2eb681STrond Myklebust 	encode_uint64(xdr, arg->clientid);
1702cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &arg->confirm);
17031da177e4SLinus Torvalds }
17041da177e4SLinus Torvalds 
17053c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
17063c6b899cSAnna Schumaker 			 struct compound_hdr *hdr)
17071da177e4SLinus Torvalds {
17088687b63aSAl Viro 	__be32 *p;
17091da177e4SLinus Torvalds 
1710ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
17119b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
17121da177e4SLinus Torvalds 
171313c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1714b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1715e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
171634558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17171da177e4SLinus Torvalds 
17181da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
17191da177e4SLinus Torvalds }
17201da177e4SLinus Torvalds 
1721cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17221da177e4SLinus Torvalds {
1723ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1724ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
17251da177e4SLinus Torvalds }
17269b7b9fccSAndy Adamson 
17275a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17285a5ea0d4SBryan Schumaker {
1729ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
17306fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
17315a5ea0d4SBryan Schumaker }
17325a5ea0d4SBryan Schumaker 
173399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17349b7b9fccSAndy Adamson /* NFSv4.1 operations */
17357c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
17367c44f1aeSWeston Andros Adamson 				   struct nfs4_session *session,
17377c44f1aeSWeston Andros Adamson 				   struct compound_hdr *hdr)
17387c44f1aeSWeston Andros Adamson {
17397c44f1aeSWeston Andros Adamson 	__be32 *p;
17407c44f1aeSWeston Andros Adamson 
17417c44f1aeSWeston Andros Adamson 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17427c44f1aeSWeston Andros Adamson 		decode_bind_conn_to_session_maxsz, hdr);
17437c44f1aeSWeston Andros Adamson 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
17447c44f1aeSWeston Andros Adamson 	p = xdr_reserve_space(xdr, 8);
17457c44f1aeSWeston Andros Adamson 	*p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
17467c44f1aeSWeston Andros Adamson 	*p = 0;	/* use_conn_in_rdma_mode = False */
17477c44f1aeSWeston Andros Adamson }
17487c44f1aeSWeston Andros Adamson 
17492031cd1aSWeston Andros Adamson static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
17502031cd1aSWeston Andros Adamson {
17512031cd1aSWeston Andros Adamson 	unsigned int i;
17522031cd1aSWeston Andros Adamson 	encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
17532031cd1aSWeston Andros Adamson 	for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
17542031cd1aSWeston Andros Adamson 		encode_uint32(xdr, op_map->u.words[i]);
17552031cd1aSWeston Andros Adamson }
17562031cd1aSWeston Andros Adamson 
175799fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
175899fe60d0SBenny Halevy 			       struct nfs41_exchange_id_args *args,
175999fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
176099fe60d0SBenny Halevy {
176199fe60d0SBenny Halevy 	__be32 *p;
1762d751f748SJim Rees 	char impl_name[IMPL_NAME_LIMIT];
1763db8ac8baSWeston Andros Adamson 	int len = 0;
176499fe60d0SBenny Halevy 
176570019514STrond Myklebust 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1766cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, args->verifier);
176799fe60d0SBenny Halevy 
176899fe60d0SBenny Halevy 	encode_string(xdr, args->id_len, args->id);
176999fe60d0SBenny Halevy 
17702031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->flags);
17712031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->state_protect.how);
17722031cd1aSWeston Andros Adamson 
17732031cd1aSWeston Andros Adamson 	switch (args->state_protect.how) {
17742031cd1aSWeston Andros Adamson 	case SP4_NONE:
17752031cd1aSWeston Andros Adamson 		break;
17762031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
17772031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.enforce);
17782031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.allow);
17792031cd1aSWeston Andros Adamson 		break;
17802031cd1aSWeston Andros Adamson 	default:
17812031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
17822031cd1aSWeston Andros Adamson 		break;
17832031cd1aSWeston Andros Adamson 	}
1784db8ac8baSWeston Andros Adamson 
1785db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1786db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1787db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1788d751f748SJim Rees 		<= sizeof(impl_name) + 1)
1789db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1790db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1791db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1792db8ac8baSWeston Andros Adamson 
1793db8ac8baSWeston Andros Adamson 	if (len > 0) {
17942031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 1);	/* implementation id array length=1 */
1795db8ac8baSWeston Andros Adamson 
1796db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1797db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1798db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1799db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1800db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1801db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1802db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1803db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1804db8ac8baSWeston Andros Adamson 	} else
18052031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 0);	/* implementation id array length=0 */
180699fe60d0SBenny Halevy }
1807fc931582SAndy Adamson 
1808fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1809fc931582SAndy Adamson 				  struct nfs41_create_session_args *args,
1810fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1811fc931582SAndy Adamson {
1812fc931582SAndy Adamson 	__be32 *p;
1813fc931582SAndy Adamson 	char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1814fc931582SAndy Adamson 	uint32_t len;
1815fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
1816f092075dSChuck Lever 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
18178e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18188e0d46e1SMike Sager 
18198e0d46e1SMike Sager 	/*
18208e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18218e0d46e1SMike Sager 	 * 2 is the verifier.
18228e0d46e1SMike Sager 	 */
18238e0d46e1SMike Sager 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
18248e0d46e1SMike Sager 			      RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1825fc931582SAndy Adamson 
1826fc931582SAndy Adamson 	len = scnprintf(machine_name, sizeof(machine_name), "%s",
1827fc931582SAndy Adamson 			clp->cl_ipaddr);
182842edd698SBenny Halevy 
1829475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1830475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1831114f64b5SAndy Adamson 	p = xdr_encode_hyper(p, clp->cl_clientid);
1832e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(clp->cl_seqid);			/*Sequence id */
1833e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1834fc931582SAndy Adamson 
1835fc931582SAndy Adamson 	/* Fore Channel */
1836c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1837e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1838e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18398e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1840e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1841e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1842e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1843fc931582SAndy Adamson 
1844fc931582SAndy Adamson 	/* Back Channel */
1845c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1846e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1847e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1848e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1849e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1850e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1851e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1852fc931582SAndy Adamson 
1853e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1854e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1855e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1856fc931582SAndy Adamson 
1857fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
185817f26b12STrond Myklebust 	*p++ = cpu_to_be32(nn->boot_time.tv_nsec);	/* stamp */
1859811652bdSBenny Halevy 	p = xdr_encode_opaque(p, machine_name, len);
1860e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1861e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
186234558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1863fc931582SAndy Adamson }
18640f3e66c6SAndy Adamson 
18650f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
18660f3e66c6SAndy Adamson 				   struct nfs4_session *session,
18670f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18680f3e66c6SAndy Adamson {
1869475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1870475d4ba0STrond Myklebust 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18710f3e66c6SAndy Adamson }
187218019753SRicardo Labiaga 
187366245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
187466245539STrond Myklebust 				   uint64_t clientid,
187566245539STrond Myklebust 				   struct compound_hdr *hdr)
187666245539STrond Myklebust {
187766245539STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
187866245539STrond Myklebust 	encode_uint64(xdr, clientid);
187966245539STrond Myklebust }
188066245539STrond Myklebust 
188118019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
188218019753SRicardo Labiaga 				    struct nfs41_reclaim_complete_args *args,
188318019753SRicardo Labiaga 				    struct compound_hdr *hdr)
188418019753SRicardo Labiaga {
1885475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1886475d4ba0STrond Myklebust 	encode_uint32(xdr, args->one_fs);
188718019753SRicardo Labiaga }
188899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
188999fe60d0SBenny Halevy 
18909b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
18919b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
18929b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
18939b7b9fccSAndy Adamson {
18949b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
18952b2fa717STrond Myklebust 	struct nfs4_session *session;
1896fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
18972b2fa717STrond Myklebust 	struct nfs4_slot *slot = args->sa_slot;
1898fc01cea9SAndy Adamson 	__be32 *p;
18999b7b9fccSAndy Adamson 
19002b2fa717STrond Myklebust 	tp = slot->table;
19012b2fa717STrond Myklebust 	session = tp->session;
19023bd2384aSChuck Lever 	if (!session)
19033bd2384aSChuck Lever 		return;
1904fc01cea9SAndy Adamson 
1905475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1906fc01cea9SAndy Adamson 
1907fc01cea9SAndy Adamson 	/*
1908fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1909fc01cea9SAndy Adamson 	 */
1910fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1911fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1912fc01cea9SAndy Adamson 		__func__,
1913fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1914fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1915fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1916fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
19172b2fa717STrond Myklebust 		slot->seq_nr, slot->slot_nr,
1918fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
1919475d4ba0STrond Myklebust 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
192093f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1921e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
19222b2fa717STrond Myklebust 	*p++ = cpu_to_be32(slot->slot_nr);
1923e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
192434558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19259b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19269b7b9fccSAndy Adamson }
19279b7b9fccSAndy Adamson 
1928b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1929b1f69b75SAndy Adamson static void
19307f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr,
19317f11d8d3SAndy Adamson 		     const struct nfs4_getdevicelist_args *args,
19327f11d8d3SAndy Adamson 		     struct compound_hdr *hdr)
19337f11d8d3SAndy Adamson {
19347f11d8d3SAndy Adamson 	__be32 *p;
19357f11d8d3SAndy Adamson 	nfs4_verifier dummy = {
19367f11d8d3SAndy Adamson 		.data = "dummmmmy",
19377f11d8d3SAndy Adamson 	};
19387f11d8d3SAndy Adamson 
1939475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1940475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
19417f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(args->layoutclass);
19427f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
19437f11d8d3SAndy Adamson 	xdr_encode_hyper(p, 0ULL);                          /* cookie */
19447f11d8d3SAndy Adamson 	encode_nfs4_verifier(xdr, &dummy);
19457f11d8d3SAndy Adamson }
19467f11d8d3SAndy Adamson 
19477f11d8d3SAndy Adamson static void
1948b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1949b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1950b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1951b1f69b75SAndy Adamson {
1952b1f69b75SAndy Adamson 	__be32 *p;
1953b1f69b75SAndy Adamson 
1954475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1955475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1956b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1957b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1958b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1959f1c097beSAndy Adamson 	*p++ = cpu_to_be32(args->pdev->maxcount);	/* gdia_maxcount */
1960b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);				/* bitmap length 0 */
1961b1f69b75SAndy Adamson }
1962b1f69b75SAndy Adamson 
1963b1f69b75SAndy Adamson static void
1964b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1965b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1966b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1967b1f69b75SAndy Adamson {
1968b1f69b75SAndy Adamson 	__be32 *p;
1969b1f69b75SAndy Adamson 
1970475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1971475d4ba0STrond Myklebust 	p = reserve_space(xdr, 36);
1972b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1973b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
1974b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
1975b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
1976b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
1977b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
1978ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1979475d4ba0STrond Myklebust 	encode_uint32(xdr, args->maxcount);
1980b1f69b75SAndy Adamson 
1981b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1982b1f69b75SAndy Adamson 		__func__,
1983b1f69b75SAndy Adamson 		args->type,
1984b1f69b75SAndy Adamson 		args->range.iomode,
1985b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
1986b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
1987b1f69b75SAndy Adamson 		args->maxcount);
1988b1f69b75SAndy Adamson }
1989863a3c6cSAndy Adamson 
1990863a3c6cSAndy Adamson static int
1991863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
1992ac7db726SBenny Halevy 		    struct inode *inode,
1993863a3c6cSAndy Adamson 		    const struct nfs4_layoutcommit_args *args,
1994863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
1995863a3c6cSAndy Adamson {
1996863a3c6cSAndy Adamson 	__be32 *p;
1997863a3c6cSAndy Adamson 
1998863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1999863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2000863a3c6cSAndy Adamson 
2001475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2002475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
2003863a3c6cSAndy Adamson 	/* Only whole file layouts */
2004863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
20053557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
2006ea9d23f5STrond Myklebust 	*p = cpu_to_be32(0); /* reclaim */
2007ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
2008ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 20);
2009863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2010863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, args->lastbytewritten);
2011863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2012863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2013ac7db726SBenny Halevy 
2014ac7db726SBenny Halevy 	if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2015ac7db726SBenny Halevy 		NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2016ac7db726SBenny Halevy 			NFS_I(inode)->layout, xdr, args);
2017475d4ba0STrond Myklebust 	else
2018475d4ba0STrond Myklebust 		encode_uint32(xdr, 0); /* no layout-type payload */
2019863a3c6cSAndy Adamson 
2020863a3c6cSAndy Adamson 	return 0;
2021863a3c6cSAndy Adamson }
2022cbe82603SBenny Halevy 
2023cbe82603SBenny Halevy static void
2024cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2025cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2026cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2027cbe82603SBenny Halevy {
2028cbe82603SBenny Halevy 	__be32 *p;
2029cbe82603SBenny Halevy 
2030475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2031475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
2032cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2033cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
2034cbe82603SBenny Halevy 	*p++ = cpu_to_be32(IOMODE_ANY);
2035cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2036ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
2037cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, 0);
2038cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2039cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2040ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
2041cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
204204a55549SAndy Adamson 	if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
204304a55549SAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
204404a55549SAndy Adamson 			NFS_I(args->inode)->layout, xdr, args);
2045475d4ba0STrond Myklebust 	} else
2046475d4ba0STrond Myklebust 		encode_uint32(xdr, 0);
2047cbe82603SBenny Halevy }
2048fca78d6dSBryan Schumaker 
2049fca78d6dSBryan Schumaker static int
2050fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2051fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2052fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2053fca78d6dSBryan Schumaker {
2054475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2055475d4ba0STrond Myklebust 	encode_uint32(xdr, args->style);
2056fca78d6dSBryan Schumaker 	return 0;
2057fca78d6dSBryan Schumaker }
20587d974794SBryan Schumaker 
20597d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
20607d974794SBryan Schumaker 				struct nfs41_test_stateid_args *args,
20617d974794SBryan Schumaker 				struct compound_hdr *hdr)
20627d974794SBryan Schumaker {
2063475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2064475d4ba0STrond Myklebust 	encode_uint32(xdr, 1);
2065ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20667d974794SBryan Schumaker }
20679aeda35fSBryan Schumaker 
20689aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
20699aeda35fSBryan Schumaker 				struct nfs41_free_stateid_args *args,
20709aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
20719aeda35fSBryan Schumaker {
2072ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
20737c1d5faeSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20749aeda35fSBryan Schumaker }
2075b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2076b1f69b75SAndy Adamson 
20771da177e4SLinus Torvalds /*
20781da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
20791da177e4SLinus Torvalds  */
20801da177e4SLinus Torvalds 
208166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
208266cc0429SBenny Halevy {
208366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
20843bd2384aSChuck Lever 	struct nfs4_session *session = args->sa_slot->table->session;
20853bd2384aSChuck Lever 	if (session)
20863bd2384aSChuck Lever 		return session->clp->cl_mvops->minor_version;
208766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
208866cc0429SBenny Halevy 	return 0;
208966cc0429SBenny Halevy }
209066cc0429SBenny Halevy 
20911da177e4SLinus Torvalds /*
20921da177e4SLinus Torvalds  * Encode an ACCESS request
20931da177e4SLinus Torvalds  */
20949f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
20959f06c719SChuck Lever 				const struct nfs4_accessargs *args)
20961da177e4SLinus Torvalds {
20971da177e4SLinus Torvalds 	struct compound_hdr hdr = {
209866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
20991da177e4SLinus Torvalds 	};
21001da177e4SLinus Torvalds 
21019f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21029f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21039f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21049f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
21059f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2106d017931cSAndy Adamson 	encode_nops(&hdr);
21071da177e4SLinus Torvalds }
21081da177e4SLinus Torvalds 
21091da177e4SLinus Torvalds /*
21101da177e4SLinus Torvalds  * Encode LOOKUP request
21111da177e4SLinus Torvalds  */
21129f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
21139f06c719SChuck Lever 				const struct nfs4_lookup_arg *args)
21141da177e4SLinus Torvalds {
21151da177e4SLinus Torvalds 	struct compound_hdr hdr = {
211666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21171da177e4SLinus Torvalds 	};
21181da177e4SLinus Torvalds 
21199f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21209f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21219f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21229f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21239f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21249f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2125d017931cSAndy Adamson 	encode_nops(&hdr);
21261da177e4SLinus Torvalds }
21271da177e4SLinus Torvalds 
21281da177e4SLinus Torvalds /*
21291da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21301da177e4SLinus Torvalds  */
21319f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21329f06c719SChuck Lever 				     struct xdr_stream *xdr,
21339f06c719SChuck Lever 				     const struct nfs4_lookup_root_arg *args)
21341da177e4SLinus Torvalds {
21351da177e4SLinus Torvalds 	struct compound_hdr hdr = {
213666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21371da177e4SLinus Torvalds 	};
21381da177e4SLinus Torvalds 
21399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21409f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21419f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21429f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21439f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2144d017931cSAndy Adamson 	encode_nops(&hdr);
21451da177e4SLinus Torvalds }
21461da177e4SLinus Torvalds 
21471da177e4SLinus Torvalds /*
21481da177e4SLinus Torvalds  * Encode REMOVE request
21491da177e4SLinus Torvalds  */
21509f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
21519f06c719SChuck Lever 				const struct nfs_removeargs *args)
21521da177e4SLinus Torvalds {
21531da177e4SLinus Torvalds 	struct compound_hdr hdr = {
215466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21551da177e4SLinus Torvalds 	};
21561da177e4SLinus Torvalds 
21579f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21589f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21599f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21609f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
2161d017931cSAndy Adamson 	encode_nops(&hdr);
21621da177e4SLinus Torvalds }
21631da177e4SLinus Torvalds 
21641da177e4SLinus Torvalds /*
21651da177e4SLinus Torvalds  * Encode RENAME request
21661da177e4SLinus Torvalds  */
21679f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
21689f06c719SChuck Lever 				const struct nfs_renameargs *args)
21691da177e4SLinus Torvalds {
21701da177e4SLinus Torvalds 	struct compound_hdr hdr = {
217166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21721da177e4SLinus Torvalds 	};
21731da177e4SLinus Torvalds 
21749f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21759f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21769f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
21779f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21789f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
21799f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2180d017931cSAndy Adamson 	encode_nops(&hdr);
21811da177e4SLinus Torvalds }
21821da177e4SLinus Torvalds 
21831da177e4SLinus Torvalds /*
21841da177e4SLinus Torvalds  * Encode LINK request
21851da177e4SLinus Torvalds  */
21869f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
21879f06c719SChuck Lever 			     const struct nfs4_link_arg *args)
21881da177e4SLinus Torvalds {
21891da177e4SLinus Torvalds 	struct compound_hdr hdr = {
219066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21911da177e4SLinus Torvalds 	};
21921da177e4SLinus Torvalds 
21939f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21949f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21959f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21969f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21979f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21989f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
21999f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22009f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2201d017931cSAndy Adamson 	encode_nops(&hdr);
22021da177e4SLinus Torvalds }
22031da177e4SLinus Torvalds 
22041da177e4SLinus Torvalds /*
22051da177e4SLinus Torvalds  * Encode CREATE request
22061da177e4SLinus Torvalds  */
22079f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
22089f06c719SChuck Lever 				const struct nfs4_create_arg *args)
22091da177e4SLinus Torvalds {
22101da177e4SLinus Torvalds 	struct compound_hdr hdr = {
221166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22121da177e4SLinus Torvalds 	};
22131da177e4SLinus Torvalds 
22149f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22159f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22169f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22179f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22189f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22199f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2220d017931cSAndy Adamson 	encode_nops(&hdr);
22211da177e4SLinus Torvalds }
22221da177e4SLinus Torvalds 
22231da177e4SLinus Torvalds /*
22241da177e4SLinus Torvalds  * Encode SYMLINK request
22251da177e4SLinus Torvalds  */
22269f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
22279f06c719SChuck Lever 				 const struct nfs4_create_arg *args)
22281da177e4SLinus Torvalds {
22299f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22301da177e4SLinus Torvalds }
22311da177e4SLinus Torvalds 
22321da177e4SLinus Torvalds /*
22331da177e4SLinus Torvalds  * Encode GETATTR request
22341da177e4SLinus Torvalds  */
22359f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
22369f06c719SChuck Lever 				 const struct nfs4_getattr_arg *args)
22371da177e4SLinus Torvalds {
22381da177e4SLinus Torvalds 	struct compound_hdr hdr = {
223966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22401da177e4SLinus Torvalds 	};
22411da177e4SLinus Torvalds 
22429f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22439f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22449f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22459f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2246d017931cSAndy Adamson 	encode_nops(&hdr);
22471da177e4SLinus Torvalds }
22481da177e4SLinus Torvalds 
22491da177e4SLinus Torvalds /*
22501da177e4SLinus Torvalds  * Encode a CLOSE request
22511da177e4SLinus Torvalds  */
22529f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
22539f06c719SChuck Lever 			       struct nfs_closeargs *args)
22541da177e4SLinus Torvalds {
22551da177e4SLinus Torvalds 	struct compound_hdr hdr = {
225666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22571da177e4SLinus Torvalds 	};
22581da177e4SLinus Torvalds 
22599f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22609f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22619f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22629f06c719SChuck Lever 	encode_close(xdr, args, &hdr);
22639f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2264d017931cSAndy Adamson 	encode_nops(&hdr);
22651da177e4SLinus Torvalds }
22661da177e4SLinus Torvalds 
22671da177e4SLinus Torvalds /*
22681da177e4SLinus Torvalds  * Encode an OPEN request
22691da177e4SLinus Torvalds  */
22709f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
22719f06c719SChuck Lever 			      struct nfs_openargs *args)
22721da177e4SLinus Torvalds {
22731da177e4SLinus Torvalds 	struct compound_hdr hdr = {
227466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22751da177e4SLinus Torvalds 	};
22761da177e4SLinus Torvalds 
22779f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22789f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22799f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22809f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
22819f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
2282ae2bb032SWeston Andros Adamson 	if (args->access)
22836168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
22841549210fSTrond Myklebust 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2285d017931cSAndy Adamson 	encode_nops(&hdr);
22861da177e4SLinus Torvalds }
22871da177e4SLinus Torvalds 
22881da177e4SLinus Torvalds /*
22891da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
22901da177e4SLinus Torvalds  */
22919f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
22929f06c719SChuck Lever 				      struct xdr_stream *xdr,
22939f06c719SChuck Lever 				      struct nfs_open_confirmargs *args)
22941da177e4SLinus Torvalds {
22951da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2296d017931cSAndy Adamson 		.nops   = 0,
22971da177e4SLinus Torvalds 	};
22981da177e4SLinus Torvalds 
22999f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23009f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23019f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2302d017931cSAndy Adamson 	encode_nops(&hdr);
23031da177e4SLinus Torvalds }
23041da177e4SLinus Torvalds 
23051da177e4SLinus Torvalds /*
23061da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
23071da177e4SLinus Torvalds  */
23089f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
23099f06c719SChuck Lever 				     struct xdr_stream *xdr,
23109f06c719SChuck Lever 				     struct nfs_openargs *args)
23111da177e4SLinus Torvalds {
23121da177e4SLinus Torvalds 	struct compound_hdr hdr = {
231366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23141da177e4SLinus Torvalds 	};
23151da177e4SLinus Torvalds 
23169f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23179f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23189f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23199f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
2320ae2bb032SWeston Andros Adamson 	if (args->access)
23216168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
2322e23008ecSAndy Adamson 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2323d017931cSAndy Adamson 	encode_nops(&hdr);
23241da177e4SLinus Torvalds }
23251da177e4SLinus Torvalds 
23261da177e4SLinus Torvalds /*
23271da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23281da177e4SLinus Torvalds  */
23299f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
23309f06c719SChuck Lever 					struct xdr_stream *xdr,
23319f06c719SChuck Lever 					struct nfs_closeargs *args)
23321da177e4SLinus Torvalds {
23331da177e4SLinus Torvalds 	struct compound_hdr hdr = {
233466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23351da177e4SLinus Torvalds 	};
23361da177e4SLinus Torvalds 
23379f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23389f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23399f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23409f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
23419f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2342d017931cSAndy Adamson 	encode_nops(&hdr);
23431da177e4SLinus Torvalds }
23441da177e4SLinus Torvalds 
23451da177e4SLinus Torvalds /*
23461da177e4SLinus Torvalds  * Encode a LOCK request
23471da177e4SLinus Torvalds  */
23489f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
23499f06c719SChuck Lever 			      struct nfs_lock_args *args)
23501da177e4SLinus Torvalds {
23511da177e4SLinus Torvalds 	struct compound_hdr hdr = {
235266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23531da177e4SLinus Torvalds 	};
23541da177e4SLinus Torvalds 
23559f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23569f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23579f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23589f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2359d017931cSAndy Adamson 	encode_nops(&hdr);
23601da177e4SLinus Torvalds }
23611da177e4SLinus Torvalds 
23621da177e4SLinus Torvalds /*
23631da177e4SLinus Torvalds  * Encode a LOCKT request
23641da177e4SLinus Torvalds  */
23659f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
23669f06c719SChuck Lever 			       struct nfs_lockt_args *args)
23671da177e4SLinus Torvalds {
23681da177e4SLinus Torvalds 	struct compound_hdr hdr = {
236966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23701da177e4SLinus Torvalds 	};
23711da177e4SLinus Torvalds 
23729f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23739f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23749f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23759f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2376d017931cSAndy Adamson 	encode_nops(&hdr);
23771da177e4SLinus Torvalds }
23781da177e4SLinus Torvalds 
23791da177e4SLinus Torvalds /*
23801da177e4SLinus Torvalds  * Encode a LOCKU request
23811da177e4SLinus Torvalds  */
23829f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
23839f06c719SChuck Lever 			       struct nfs_locku_args *args)
23841da177e4SLinus Torvalds {
23851da177e4SLinus Torvalds 	struct compound_hdr hdr = {
238666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23871da177e4SLinus Torvalds 	};
23881da177e4SLinus Torvalds 
23899f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23909f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23919f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23929f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2393d017931cSAndy Adamson 	encode_nops(&hdr);
23941da177e4SLinus Torvalds }
23951da177e4SLinus Torvalds 
23969f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
23979f06c719SChuck Lever 					   struct xdr_stream *xdr,
23989f06c719SChuck Lever 					struct nfs_release_lockowner_args *args)
2399d3c7b7ccSTrond Myklebust {
2400d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2401d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2402d3c7b7ccSTrond Myklebust 	};
2403d3c7b7ccSTrond Myklebust 
24049f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24059f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2406d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2407d3c7b7ccSTrond Myklebust }
2408d3c7b7ccSTrond Myklebust 
24091da177e4SLinus Torvalds /*
24101da177e4SLinus Torvalds  * Encode a READLINK request
24111da177e4SLinus Torvalds  */
24129f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
24139f06c719SChuck Lever 				  const struct nfs4_readlink *args)
24141da177e4SLinus Torvalds {
24151da177e4SLinus Torvalds 	struct compound_hdr hdr = {
241666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24171da177e4SLinus Torvalds 	};
24181da177e4SLinus Torvalds 
24199f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24209f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24219f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24229f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2423e3a535e1STrond Myklebust 
242428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2425e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2426d017931cSAndy Adamson 	encode_nops(&hdr);
24271da177e4SLinus Torvalds }
24281da177e4SLinus Torvalds 
24291da177e4SLinus Torvalds /*
24301da177e4SLinus Torvalds  * Encode a READDIR request
24311da177e4SLinus Torvalds  */
24329f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
24339f06c719SChuck Lever 				 const struct nfs4_readdir_arg *args)
24341da177e4SLinus Torvalds {
24351da177e4SLinus Torvalds 	struct compound_hdr hdr = {
243666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24371da177e4SLinus Torvalds 	};
24381da177e4SLinus Torvalds 
24399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24409f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24419f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24429f06c719SChuck Lever 	encode_readdir(xdr, args, req, &hdr);
2443d6ac02dfSTrond Myklebust 
244428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2445d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2446d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
244728f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2448d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2449d017931cSAndy Adamson 	encode_nops(&hdr);
24501da177e4SLinus Torvalds }
24511da177e4SLinus Torvalds 
24521da177e4SLinus Torvalds /*
24531da177e4SLinus Torvalds  * Encode a READ request
24541da177e4SLinus Torvalds  */
24559f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
24563c6b899cSAnna Schumaker 			      struct nfs_pgio_args *args)
24571da177e4SLinus Torvalds {
24581da177e4SLinus Torvalds 	struct compound_hdr hdr = {
245966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24601da177e4SLinus Torvalds 	};
24611da177e4SLinus Torvalds 
24629f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24639f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24649f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24659f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
24661da177e4SLinus Torvalds 
246728f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
24681da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
24694f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2470d017931cSAndy Adamson 	encode_nops(&hdr);
24711da177e4SLinus Torvalds }
24721da177e4SLinus Torvalds 
24731da177e4SLinus Torvalds /*
24741da177e4SLinus Torvalds  * Encode an SETATTR request
24751da177e4SLinus Torvalds  */
24769f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
24779f06c719SChuck Lever 				 struct nfs_setattrargs *args)
24781da177e4SLinus Torvalds {
24791da177e4SLinus Torvalds 	struct compound_hdr hdr = {
248066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24811da177e4SLinus Torvalds 	};
24821da177e4SLinus Torvalds 
24839f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24849f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24859f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24869f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
24879f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2488d017931cSAndy Adamson 	encode_nops(&hdr);
24891da177e4SLinus Torvalds }
24901da177e4SLinus Torvalds 
24911da177e4SLinus Torvalds /*
2492029d105eSJ. Bruce Fields  * Encode a GETACL request
2493029d105eSJ. Bruce Fields  */
24949f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2495029d105eSJ. Bruce Fields 				struct nfs_getaclargs *args)
2496029d105eSJ. Bruce Fields {
2497029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
249866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2499029d105eSJ. Bruce Fields 	};
250028f56694SBenny Halevy 	uint32_t replen;
2501029d105eSJ. Bruce Fields 
25029f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25039f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25049f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2505bf118a34SAndy Adamson 	replen = hdr.replen + op_decode_hdr_maxsz + 1;
25069f06c719SChuck Lever 	encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2507cf8cdbe5SAndy Adamson 
250828f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2509029d105eSJ. Bruce Fields 		args->acl_pages, args->acl_pgbase, args->acl_len);
2510bf118a34SAndy Adamson 
2511d017931cSAndy Adamson 	encode_nops(&hdr);
2512029d105eSJ. Bruce Fields }
2513029d105eSJ. Bruce Fields 
2514029d105eSJ. Bruce Fields /*
25151da177e4SLinus Torvalds  * Encode a WRITE request
25161da177e4SLinus Torvalds  */
25179f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
25183c6b899cSAnna Schumaker 			       struct nfs_pgio_args *args)
25191da177e4SLinus Torvalds {
25201da177e4SLinus Torvalds 	struct compound_hdr hdr = {
252166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25221da177e4SLinus Torvalds 	};
25231da177e4SLinus Torvalds 
25249f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25259f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25269f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25279f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
25284f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
25297ffd1064SFred Isaman 	if (args->bitmask)
25309f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2531d017931cSAndy Adamson 	encode_nops(&hdr);
25321da177e4SLinus Torvalds }
25331da177e4SLinus Torvalds 
25341da177e4SLinus Torvalds /*
25351da177e4SLinus Torvalds  *  a COMMIT request
25361da177e4SLinus Torvalds  */
25379f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
25380b7c0153SFred Isaman 				struct nfs_commitargs *args)
25391da177e4SLinus Torvalds {
25401da177e4SLinus Torvalds 	struct compound_hdr hdr = {
254166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25421da177e4SLinus Torvalds 	};
25431da177e4SLinus Torvalds 
25449f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25459f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25469f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25479f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2548d017931cSAndy Adamson 	encode_nops(&hdr);
25491da177e4SLinus Torvalds }
25501da177e4SLinus Torvalds 
25511da177e4SLinus Torvalds /*
25521da177e4SLinus Torvalds  * FSINFO request
25531da177e4SLinus Torvalds  */
25549f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
25559f06c719SChuck Lever 				struct nfs4_fsinfo_arg *args)
25561da177e4SLinus Torvalds {
25571da177e4SLinus Torvalds 	struct compound_hdr hdr = {
255866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25591da177e4SLinus Torvalds 	};
25601da177e4SLinus Torvalds 
25619f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25629f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25639f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25649f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2565d017931cSAndy Adamson 	encode_nops(&hdr);
25661da177e4SLinus Torvalds }
25671da177e4SLinus Torvalds 
25681da177e4SLinus Torvalds /*
25691da177e4SLinus Torvalds  * a PATHCONF request
25701da177e4SLinus Torvalds  */
25719f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
25729f06c719SChuck Lever 				  const struct nfs4_pathconf_arg *args)
25731da177e4SLinus Torvalds {
25741da177e4SLinus Torvalds 	struct compound_hdr hdr = {
257566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25761da177e4SLinus Torvalds 	};
25771da177e4SLinus Torvalds 
25789f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25799f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25809f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25819f06c719SChuck Lever 	encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2582d017931cSAndy Adamson 			   &hdr);
2583d017931cSAndy Adamson 	encode_nops(&hdr);
25841da177e4SLinus Torvalds }
25851da177e4SLinus Torvalds 
25861da177e4SLinus Torvalds /*
25871da177e4SLinus Torvalds  * a STATFS request
25881da177e4SLinus Torvalds  */
25899f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
25909f06c719SChuck Lever 				const struct nfs4_statfs_arg *args)
25911da177e4SLinus Torvalds {
25921da177e4SLinus Torvalds 	struct compound_hdr hdr = {
259366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25941da177e4SLinus Torvalds 	};
25951da177e4SLinus Torvalds 
25969f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25979f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25989f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25999f06c719SChuck Lever 	encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2600d017931cSAndy Adamson 			   args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2601d017931cSAndy Adamson 	encode_nops(&hdr);
26021da177e4SLinus Torvalds }
26031da177e4SLinus Torvalds 
26041da177e4SLinus Torvalds /*
26051da177e4SLinus Torvalds  * GETATTR_BITMAP request
26061da177e4SLinus Torvalds  */
26079f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
26089f06c719SChuck Lever 				     struct xdr_stream *xdr,
260943652ad5SBenny Halevy 				     struct nfs4_server_caps_arg *args)
26101da177e4SLinus Torvalds {
26111da177e4SLinus Torvalds 	struct compound_hdr hdr = {
261266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26131da177e4SLinus Torvalds 	};
26141da177e4SLinus Torvalds 
26159f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26169f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26179f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
26189f06c719SChuck Lever 	encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2619264e6351SChuck Lever 			   FATTR4_WORD0_FH_EXPIRE_TYPE|
26201da177e4SLinus Torvalds 			   FATTR4_WORD0_LINK_SUPPORT|
26211da177e4SLinus Torvalds 			   FATTR4_WORD0_SYMLINK_SUPPORT|
2622d017931cSAndy Adamson 			   FATTR4_WORD0_ACLSUPPORT, &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);
26879f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2688e144cbccSTrond Myklebust 	encode_delegreturn(xdr, args->stateid, &hdr);
2689d017931cSAndy Adamson 	encode_nops(&hdr);
26901da177e4SLinus Torvalds }
26911da177e4SLinus Torvalds 
26921da177e4SLinus Torvalds /*
2693683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2694683b57b4STrond Myklebust  */
26959f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
26969f06c719SChuck Lever 				      struct xdr_stream *xdr,
26979f06c719SChuck Lever 				      struct nfs4_fs_locations_arg *args)
2698683b57b4STrond Myklebust {
2699683b57b4STrond Myklebust 	struct compound_hdr hdr = {
270066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2701683b57b4STrond Myklebust 	};
270228f56694SBenny Halevy 	uint32_t replen;
2703683b57b4STrond Myklebust 
27049f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27059f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
2706b03d735bSChuck Lever 	if (args->migration) {
2707b03d735bSChuck Lever 		encode_putfh(xdr, args->fh, &hdr);
2708b03d735bSChuck Lever 		replen = hdr.replen;
2709b03d735bSChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2710b03d735bSChuck Lever 		if (args->renew)
2711b03d735bSChuck Lever 			encode_renew(xdr, args->clientid, &hdr);
2712b03d735bSChuck Lever 	} else {
27139f06c719SChuck Lever 		encode_putfh(xdr, args->dir_fh, &hdr);
27149f06c719SChuck Lever 		encode_lookup(xdr, args->name, &hdr);
2715b03d735bSChuck Lever 		replen = hdr.replen;
27169f06c719SChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2717b03d735bSChuck Lever 	}
2718cf8cdbe5SAndy Adamson 
2719b03d735bSChuck Lever 	/* Set up reply kvec to capture returned fs_locations array. */
272028f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2721683b57b4STrond Myklebust 			0, PAGE_SIZE);
2722d017931cSAndy Adamson 	encode_nops(&hdr);
2723683b57b4STrond Myklebust }
2724683b57b4STrond Myklebust 
27255a5ea0d4SBryan Schumaker /*
27265a5ea0d4SBryan Schumaker  * Encode SECINFO request
27275a5ea0d4SBryan Schumaker  */
27285a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
27295a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
27305a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_arg *args)
27315a5ea0d4SBryan Schumaker {
27325a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
27335a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27345a5ea0d4SBryan Schumaker 	};
27355a5ea0d4SBryan Schumaker 
27365a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
27375a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
27385a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
27395a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
27405a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
27415a5ea0d4SBryan Schumaker }
27425a5ea0d4SBryan Schumaker 
274344c99933SChuck Lever /*
274444c99933SChuck Lever  * Encode FSID_PRESENT request
274544c99933SChuck Lever  */
274644c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
274744c99933SChuck Lever 				      struct xdr_stream *xdr,
274844c99933SChuck Lever 				      struct nfs4_fsid_present_arg *args)
274944c99933SChuck Lever {
275044c99933SChuck Lever 	struct compound_hdr hdr = {
275144c99933SChuck Lever 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
275244c99933SChuck Lever 	};
275344c99933SChuck Lever 
275444c99933SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
275544c99933SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
275644c99933SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
275744c99933SChuck Lever 	encode_getfh(xdr, &hdr);
275844c99933SChuck Lever 	if (args->renew)
275944c99933SChuck Lever 		encode_renew(xdr, args->clientid, &hdr);
276044c99933SChuck Lever 	encode_nops(&hdr);
276144c99933SChuck Lever }
276244c99933SChuck Lever 
276399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
276499fe60d0SBenny Halevy /*
27657c44f1aeSWeston Andros Adamson  * BIND_CONN_TO_SESSION request
27667c44f1aeSWeston Andros Adamson  */
27677c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
27687c44f1aeSWeston Andros Adamson 				struct xdr_stream *xdr,
27697c44f1aeSWeston Andros Adamson 				struct nfs_client *clp)
27707c44f1aeSWeston Andros Adamson {
27717c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr = {
27727c44f1aeSWeston Andros Adamson 		.minorversion = clp->cl_mvops->minor_version,
27737c44f1aeSWeston Andros Adamson 	};
27747c44f1aeSWeston Andros Adamson 
27757c44f1aeSWeston Andros Adamson 	encode_compound_hdr(xdr, req, &hdr);
27767c44f1aeSWeston Andros Adamson 	encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
27777c44f1aeSWeston Andros Adamson 	encode_nops(&hdr);
27787c44f1aeSWeston Andros Adamson }
27797c44f1aeSWeston Andros Adamson 
27807c44f1aeSWeston Andros Adamson /*
278199fe60d0SBenny Halevy  * EXCHANGE_ID request
278299fe60d0SBenny Halevy  */
27839f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
27849f06c719SChuck Lever 				     struct xdr_stream *xdr,
278599fe60d0SBenny Halevy 				     struct nfs41_exchange_id_args *args)
278699fe60d0SBenny Halevy {
278799fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2788a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
278999fe60d0SBenny Halevy 	};
279099fe60d0SBenny Halevy 
27919f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27929f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
279399fe60d0SBenny Halevy 	encode_nops(&hdr);
279499fe60d0SBenny Halevy }
27952050f0ccSAndy Adamson 
27962050f0ccSAndy Adamson /*
2797fc931582SAndy Adamson  * a CREATE_SESSION request
2798fc931582SAndy Adamson  */
27999f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
28009f06c719SChuck Lever 					struct xdr_stream *xdr,
2801fc931582SAndy Adamson 					struct nfs41_create_session_args *args)
2802fc931582SAndy Adamson {
2803fc931582SAndy Adamson 	struct compound_hdr hdr = {
2804a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2805fc931582SAndy Adamson 	};
2806fc931582SAndy Adamson 
28079f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28089f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2809fc931582SAndy Adamson 	encode_nops(&hdr);
2810fc931582SAndy Adamson }
2811fc931582SAndy Adamson 
2812fc931582SAndy Adamson /*
28130f3e66c6SAndy Adamson  * a DESTROY_SESSION request
28140f3e66c6SAndy Adamson  */
28159f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
28169f06c719SChuck Lever 					 struct xdr_stream *xdr,
28170f3e66c6SAndy Adamson 					 struct nfs4_session *session)
28180f3e66c6SAndy Adamson {
28190f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2820a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
28210f3e66c6SAndy Adamson 	};
28220f3e66c6SAndy Adamson 
28239f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28249f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
28250f3e66c6SAndy Adamson 	encode_nops(&hdr);
28260f3e66c6SAndy Adamson }
28270f3e66c6SAndy Adamson 
28280f3e66c6SAndy Adamson /*
282966245539STrond Myklebust  * a DESTROY_CLIENTID request
283066245539STrond Myklebust  */
283166245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
283266245539STrond Myklebust 					 struct xdr_stream *xdr,
283366245539STrond Myklebust 					 struct nfs_client *clp)
283466245539STrond Myklebust {
283566245539STrond Myklebust 	struct compound_hdr hdr = {
283666245539STrond Myklebust 		.minorversion = clp->cl_mvops->minor_version,
283766245539STrond Myklebust 	};
283866245539STrond Myklebust 
283966245539STrond Myklebust 	encode_compound_hdr(xdr, req, &hdr);
284066245539STrond Myklebust 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
284166245539STrond Myklebust 	encode_nops(&hdr);
284266245539STrond Myklebust }
284366245539STrond Myklebust 
284466245539STrond Myklebust /*
2845fc01cea9SAndy Adamson  * a SEQUENCE request
2846fc01cea9SAndy Adamson  */
28479f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2848fc01cea9SAndy Adamson 				  struct nfs4_sequence_args *args)
2849fc01cea9SAndy Adamson {
2850fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2851fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2852fc01cea9SAndy Adamson 	};
2853fc01cea9SAndy Adamson 
28549f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28559f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2856fc01cea9SAndy Adamson 	encode_nops(&hdr);
2857fc01cea9SAndy Adamson }
2858fc01cea9SAndy Adamson 
2859fc01cea9SAndy Adamson /*
28602050f0ccSAndy Adamson  * a GET_LEASE_TIME request
28612050f0ccSAndy Adamson  */
28629f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
28639f06c719SChuck Lever 					struct xdr_stream *xdr,
28642050f0ccSAndy Adamson 					struct nfs4_get_lease_time_args *args)
28652050f0ccSAndy Adamson {
28662050f0ccSAndy Adamson 	struct compound_hdr hdr = {
28672050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
28682050f0ccSAndy Adamson 	};
2869dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
28702050f0ccSAndy Adamson 
28719f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28729f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
28739f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
28749f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
28752050f0ccSAndy Adamson 	encode_nops(&hdr);
28762050f0ccSAndy Adamson }
287718019753SRicardo Labiaga 
287818019753SRicardo Labiaga /*
287918019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
288018019753SRicardo Labiaga  */
28819f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
28829f06c719SChuck Lever 					  struct xdr_stream *xdr,
288318019753SRicardo Labiaga 				struct nfs41_reclaim_complete_args *args)
288418019753SRicardo Labiaga {
288518019753SRicardo Labiaga 	struct compound_hdr hdr = {
288618019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
288718019753SRicardo Labiaga 	};
288818019753SRicardo Labiaga 
28899f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28909f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28919f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
289218019753SRicardo Labiaga 	encode_nops(&hdr);
289318019753SRicardo Labiaga }
289418019753SRicardo Labiaga 
2895b1f69b75SAndy Adamson /*
28967f11d8d3SAndy Adamson  * Encode GETDEVICELIST request
28977f11d8d3SAndy Adamson  */
28987f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
28997f11d8d3SAndy Adamson 				       struct xdr_stream *xdr,
29007f11d8d3SAndy Adamson 				       struct nfs4_getdevicelist_args *args)
29017f11d8d3SAndy Adamson {
29027f11d8d3SAndy Adamson 	struct compound_hdr hdr = {
29037f11d8d3SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
29047f11d8d3SAndy Adamson 	};
29057f11d8d3SAndy Adamson 
29067f11d8d3SAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
29077f11d8d3SAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
29087f11d8d3SAndy Adamson 	encode_putfh(xdr, args->fh, &hdr);
29097f11d8d3SAndy Adamson 	encode_getdevicelist(xdr, args, &hdr);
29107f11d8d3SAndy Adamson 	encode_nops(&hdr);
29117f11d8d3SAndy Adamson }
29127f11d8d3SAndy Adamson 
29137f11d8d3SAndy Adamson /*
2914b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
2915b1f69b75SAndy Adamson  */
29169f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
29179f06c719SChuck Lever 				       struct xdr_stream *xdr,
2918b1f69b75SAndy Adamson 				       struct nfs4_getdeviceinfo_args *args)
2919b1f69b75SAndy Adamson {
2920b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2921b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2922b1f69b75SAndy Adamson 	};
2923b1f69b75SAndy Adamson 
29249f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29259f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29269f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
2927b1f69b75SAndy Adamson 
2928b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
2929b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
2930b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2931b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
2932b1f69b75SAndy Adamson 			 args->pdev->pglen);
2933b1f69b75SAndy Adamson 
2934b1f69b75SAndy Adamson 	encode_nops(&hdr);
2935b1f69b75SAndy Adamson }
2936b1f69b75SAndy Adamson 
2937b1f69b75SAndy Adamson /*
2938b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
2939b1f69b75SAndy Adamson  */
29409f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
29419f06c719SChuck Lever 				   struct xdr_stream *xdr,
2942b1f69b75SAndy Adamson 				   struct nfs4_layoutget_args *args)
2943b1f69b75SAndy Adamson {
2944b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2945b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2946b1f69b75SAndy Adamson 	};
2947b1f69b75SAndy Adamson 
29489f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29499f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29509f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
29519f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
295235124a09SWeston Andros Adamson 
295335124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
295435124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
295535124a09SWeston Andros Adamson 
2956b1f69b75SAndy Adamson 	encode_nops(&hdr);
2957b1f69b75SAndy Adamson }
2958863a3c6cSAndy Adamson 
2959863a3c6cSAndy Adamson /*
2960863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
2961863a3c6cSAndy Adamson  */
2962cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2963863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
2964863a3c6cSAndy Adamson 				      struct nfs4_layoutcommit_args *args)
2965863a3c6cSAndy Adamson {
2966ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
2967ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
2968863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
2969863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970863a3c6cSAndy Adamson 	};
2971863a3c6cSAndy Adamson 
2972863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
2973863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
2974863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2975ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2976863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
2977863a3c6cSAndy Adamson 	encode_nops(&hdr);
2978cbe82603SBenny Halevy }
2979cbe82603SBenny Halevy 
2980cbe82603SBenny Halevy /*
2981cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
2982cbe82603SBenny Halevy  */
2983cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2984cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
2985cbe82603SBenny Halevy 				      struct nfs4_layoutreturn_args *args)
2986cbe82603SBenny Halevy {
2987cbe82603SBenny Halevy 	struct compound_hdr hdr = {
2988cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989cbe82603SBenny Halevy 	};
2990cbe82603SBenny Halevy 
2991cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
2992cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
2993cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2994cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
2995cbe82603SBenny Halevy 	encode_nops(&hdr);
2996863a3c6cSAndy Adamson }
2997fca78d6dSBryan Schumaker 
2998fca78d6dSBryan Schumaker /*
2999fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
3000fca78d6dSBryan Schumaker  */
3001fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3002fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
3003fca78d6dSBryan Schumaker 					struct nfs41_secinfo_no_name_args *args)
3004fca78d6dSBryan Schumaker {
3005fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
3006fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3007fca78d6dSBryan Schumaker 	};
3008fca78d6dSBryan Schumaker 
3009fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
3010fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
3011fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
3012fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
3013fca78d6dSBryan Schumaker 	encode_nops(&hdr);
3014fca78d6dSBryan Schumaker 	return 0;
3015fca78d6dSBryan Schumaker }
30167d974794SBryan Schumaker 
30177d974794SBryan Schumaker /*
30187d974794SBryan Schumaker  *  Encode TEST_STATEID request
30197d974794SBryan Schumaker  */
30207d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
30217d974794SBryan Schumaker 				      struct xdr_stream *xdr,
30227d974794SBryan Schumaker 				      struct nfs41_test_stateid_args *args)
30237d974794SBryan Schumaker {
30247d974794SBryan Schumaker 	struct compound_hdr hdr = {
30257d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30267d974794SBryan Schumaker 	};
30277d974794SBryan Schumaker 
30287d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30297d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30307d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
30317d974794SBryan Schumaker 	encode_nops(&hdr);
30327d974794SBryan Schumaker }
30339aeda35fSBryan Schumaker 
30349aeda35fSBryan Schumaker /*
30359aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
30369aeda35fSBryan Schumaker  */
30379aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
30389aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
30399aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_args *args)
30409aeda35fSBryan Schumaker {
30419aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
30429aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30439aeda35fSBryan Schumaker 	};
30449aeda35fSBryan Schumaker 
30459aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30469aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30479aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
30489aeda35fSBryan Schumaker 	encode_nops(&hdr);
30499aeda35fSBryan Schumaker }
305099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
305199fe60d0SBenny Halevy 
3052686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3053686841b3SBenny Halevy {
3054686841b3SBenny Halevy 	dprintk("nfs: %s: prematurely hit end of receive buffer. "
3055686841b3SBenny Halevy 		"Remaining buffer length is %tu words.\n",
3056686841b3SBenny Halevy 		func, xdr->end - xdr->p);
3057686841b3SBenny Halevy }
30581da177e4SLinus Torvalds 
3059683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
30601da177e4SLinus Torvalds {
30618687b63aSAl Viro 	__be32 *p;
30621da177e4SLinus Torvalds 
3063c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3064c0eae66eSBenny Halevy 	if (unlikely(!p))
3065c0eae66eSBenny Halevy 		goto out_overflow;
3066cccddf4fSBenny Halevy 	*len = be32_to_cpup(p);
3067c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, *len);
3068c0eae66eSBenny Halevy 	if (unlikely(!p))
3069c0eae66eSBenny Halevy 		goto out_overflow;
30701da177e4SLinus Torvalds 	*string = (char *)p;
30711da177e4SLinus Torvalds 	return 0;
3072c0eae66eSBenny Halevy out_overflow:
3073c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3074c0eae66eSBenny Halevy 	return -EIO;
30751da177e4SLinus Torvalds }
30761da177e4SLinus Torvalds 
30771da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
30781da177e4SLinus Torvalds {
30798687b63aSAl Viro 	__be32 *p;
30801da177e4SLinus Torvalds 
3081c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3082c0eae66eSBenny Halevy 	if (unlikely(!p))
3083c0eae66eSBenny Halevy 		goto out_overflow;
30846f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3085cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
30861da177e4SLinus Torvalds 
3087c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3088c0eae66eSBenny Halevy 	if (unlikely(!p))
3089c0eae66eSBenny Halevy 		goto out_overflow;
30901da177e4SLinus Torvalds 	hdr->tag = (char *)p;
30911da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3092cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3093aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3094aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
30951da177e4SLinus Torvalds 	return 0;
3096c0eae66eSBenny Halevy out_overflow:
3097c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3098c0eae66eSBenny Halevy 	return -EIO;
30991da177e4SLinus Torvalds }
31001da177e4SLinus Torvalds 
3101c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3102c7848f69STrond Myklebust 		int *nfs_retval)
31031da177e4SLinus Torvalds {
31048687b63aSAl Viro 	__be32 *p;
31051da177e4SLinus Torvalds 	uint32_t opnum;
31061da177e4SLinus Torvalds 	int32_t nfserr;
31071da177e4SLinus Torvalds 
3108c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3109c0eae66eSBenny Halevy 	if (unlikely(!p))
3110c0eae66eSBenny Halevy 		goto out_overflow;
31116f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
3112c7848f69STrond Myklebust 	if (unlikely(opnum != expected))
3113c7848f69STrond Myklebust 		goto out_bad_operation;
3114c7848f69STrond Myklebust 	nfserr = be32_to_cpup(p);
3115c7848f69STrond Myklebust 	if (nfserr == NFS_OK)
3116c7848f69STrond Myklebust 		*nfs_retval = 0;
3117c7848f69STrond Myklebust 	else
3118c7848f69STrond Myklebust 		*nfs_retval = nfs4_stat_to_errno(nfserr);
3119c7848f69STrond Myklebust 	return true;
3120c7848f69STrond Myklebust out_bad_operation:
3121fe82a183SChuck Lever 	dprintk("nfs: Server returned operation"
31221da177e4SLinus Torvalds 		" %d but we issued a request for %d\n",
31231da177e4SLinus Torvalds 			opnum, expected);
3124c7848f69STrond Myklebust 	*nfs_retval = -EREMOTEIO;
3125c7848f69STrond Myklebust 	return false;
3126c0eae66eSBenny Halevy out_overflow:
3127c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3128c7848f69STrond Myklebust 	*nfs_retval = -EIO;
3129c7848f69STrond Myklebust 	return false;
3130c7848f69STrond Myklebust }
3131c7848f69STrond Myklebust 
3132c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3133c7848f69STrond Myklebust {
3134c7848f69STrond Myklebust 	int retval;
3135c7848f69STrond Myklebust 
3136c7848f69STrond Myklebust 	__decode_op_hdr(xdr, expected, &retval);
3137c7848f69STrond Myklebust 	return retval;
31381da177e4SLinus Torvalds }
31391da177e4SLinus Torvalds 
31401da177e4SLinus Torvalds /* Dummy routine */
3141adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
31421da177e4SLinus Torvalds {
31438687b63aSAl Viro 	__be32 *p;
3144683b57b4STrond Myklebust 	unsigned int strlen;
31451da177e4SLinus Torvalds 	char *str;
31461da177e4SLinus Torvalds 
3147c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3148c0eae66eSBenny Halevy 	if (likely(p))
31491da177e4SLinus Torvalds 		return decode_opaque_inline(xdr, &strlen, &str);
3150c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3151c0eae66eSBenny Halevy 	return -EIO;
31521da177e4SLinus Torvalds }
31531da177e4SLinus Torvalds 
31541da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
31551da177e4SLinus Torvalds {
31568687b63aSAl Viro 	uint32_t bmlen;
31578687b63aSAl Viro 	__be32 *p;
31581da177e4SLinus Torvalds 
3159c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3160c0eae66eSBenny Halevy 	if (unlikely(!p))
3161c0eae66eSBenny Halevy 		goto out_overflow;
3162cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
31631da177e4SLinus Torvalds 
3164dae100c2SFred Isaman 	bitmap[0] = bitmap[1] = bitmap[2] = 0;
3165c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, (bmlen << 2));
3166c0eae66eSBenny Halevy 	if (unlikely(!p))
3167c0eae66eSBenny Halevy 		goto out_overflow;
31681da177e4SLinus Torvalds 	if (bmlen > 0) {
31696f723f77SBenny Halevy 		bitmap[0] = be32_to_cpup(p++);
3170dae100c2SFred Isaman 		if (bmlen > 1) {
3171dae100c2SFred Isaman 			bitmap[1] = be32_to_cpup(p++);
3172dae100c2SFred Isaman 			if (bmlen > 2)
3173dae100c2SFred Isaman 				bitmap[2] = be32_to_cpup(p);
3174dae100c2SFred Isaman 		}
31751da177e4SLinus Torvalds 	}
31761da177e4SLinus Torvalds 	return 0;
3177c0eae66eSBenny Halevy out_overflow:
3178c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3179c0eae66eSBenny Halevy 	return -EIO;
31801da177e4SLinus Torvalds }
31811da177e4SLinus Torvalds 
3182256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
31831da177e4SLinus Torvalds {
31848687b63aSAl Viro 	__be32 *p;
31851da177e4SLinus Torvalds 
3186c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3187c0eae66eSBenny Halevy 	if (unlikely(!p))
3188c0eae66eSBenny Halevy 		goto out_overflow;
3189cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
3190256e48bbSTrond Myklebust 	*savep = xdr_stream_pos(xdr);
31911da177e4SLinus Torvalds 	return 0;
3192c0eae66eSBenny Halevy out_overflow:
3193c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3194c0eae66eSBenny Halevy 	return -EIO;
31951da177e4SLinus Torvalds }
31961da177e4SLinus Torvalds 
31971da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
31981da177e4SLinus Torvalds {
31991da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
32003388bff5SRoman Borisov 		int ret;
32013388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
32023388bff5SRoman Borisov 		if (unlikely(ret < 0))
32033388bff5SRoman Borisov 			return ret;
32041da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
32051da177e4SLinus Torvalds 	} else
3206dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3207dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3208dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
32091da177e4SLinus Torvalds 	return 0;
32101da177e4SLinus Torvalds }
32111da177e4SLinus Torvalds 
32121da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
32131da177e4SLinus Torvalds {
32148687b63aSAl Viro 	__be32 *p;
3215409924e4STrond Myklebust 	int ret = 0;
32161da177e4SLinus Torvalds 
32171da177e4SLinus Torvalds 	*type = 0;
32181da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
32191da177e4SLinus Torvalds 		return -EIO;
32201da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3221c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3222c0eae66eSBenny Halevy 		if (unlikely(!p))
3223c0eae66eSBenny Halevy 			goto out_overflow;
3224cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
32251da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
32263110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
32271da177e4SLinus Torvalds 			return -EIO;
32281da177e4SLinus Torvalds 		}
32291da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3230409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32311da177e4SLinus Torvalds 	}
3232bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3233409924e4STrond Myklebust 	return ret;
3234c0eae66eSBenny Halevy out_overflow:
3235c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3236c0eae66eSBenny Halevy 	return -EIO;
32371da177e4SLinus Torvalds }
32381da177e4SLinus Torvalds 
3239264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3240264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3241264e6351SChuck Lever {
3242264e6351SChuck Lever 	__be32 *p;
3243264e6351SChuck Lever 
3244264e6351SChuck Lever 	*type = 0;
3245264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3246264e6351SChuck Lever 		return -EIO;
3247264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3248264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3249264e6351SChuck Lever 		if (unlikely(!p))
3250264e6351SChuck Lever 			goto out_overflow;
3251264e6351SChuck Lever 		*type = be32_to_cpup(p);
3252264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3253264e6351SChuck Lever 	}
3254264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3255264e6351SChuck Lever 	return 0;
3256264e6351SChuck Lever out_overflow:
3257264e6351SChuck Lever 	print_overflow_msg(__func__, xdr);
3258264e6351SChuck Lever 	return -EIO;
3259264e6351SChuck Lever }
3260264e6351SChuck Lever 
32611da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
32621da177e4SLinus Torvalds {
32638687b63aSAl Viro 	__be32 *p;
3264409924e4STrond Myklebust 	int ret = 0;
32651da177e4SLinus Torvalds 
32661da177e4SLinus Torvalds 	*change = 0;
32671da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
32681da177e4SLinus Torvalds 		return -EIO;
32691da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3270c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3271c0eae66eSBenny Halevy 		if (unlikely(!p))
3272c0eae66eSBenny Halevy 			goto out_overflow;
3273cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
32741da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3275409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
32761da177e4SLinus Torvalds 	}
32773110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
32781da177e4SLinus Torvalds 			(unsigned long long)*change);
3279409924e4STrond Myklebust 	return ret;
3280c0eae66eSBenny Halevy out_overflow:
3281c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3282c0eae66eSBenny Halevy 	return -EIO;
32831da177e4SLinus Torvalds }
32841da177e4SLinus Torvalds 
32851da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
32861da177e4SLinus Torvalds {
32878687b63aSAl Viro 	__be32 *p;
3288409924e4STrond Myklebust 	int ret = 0;
32891da177e4SLinus Torvalds 
32901da177e4SLinus Torvalds 	*size = 0;
32911da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
32921da177e4SLinus Torvalds 		return -EIO;
32931da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3294c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3295c0eae66eSBenny Halevy 		if (unlikely(!p))
3296c0eae66eSBenny Halevy 			goto out_overflow;
3297cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
32981da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3299409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
33001da177e4SLinus Torvalds 	}
33013110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3302409924e4STrond Myklebust 	return ret;
3303c0eae66eSBenny Halevy out_overflow:
3304c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3305c0eae66eSBenny Halevy 	return -EIO;
33061da177e4SLinus Torvalds }
33071da177e4SLinus Torvalds 
33081da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33091da177e4SLinus Torvalds {
33108687b63aSAl Viro 	__be32 *p;
33111da177e4SLinus Torvalds 
33121da177e4SLinus Torvalds 	*res = 0;
33131da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
33141da177e4SLinus Torvalds 		return -EIO;
33151da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3316c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3317c0eae66eSBenny Halevy 		if (unlikely(!p))
3318c0eae66eSBenny Halevy 			goto out_overflow;
3319cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33201da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
33211da177e4SLinus Torvalds 	}
33223110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
33231da177e4SLinus Torvalds 	return 0;
3324c0eae66eSBenny Halevy out_overflow:
3325c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3326c0eae66eSBenny Halevy 	return -EIO;
33271da177e4SLinus Torvalds }
33281da177e4SLinus Torvalds 
33291da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33301da177e4SLinus Torvalds {
33318687b63aSAl Viro 	__be32 *p;
33321da177e4SLinus Torvalds 
33331da177e4SLinus Torvalds 	*res = 0;
33341da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
33351da177e4SLinus Torvalds 		return -EIO;
33361da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3337c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3338c0eae66eSBenny Halevy 		if (unlikely(!p))
3339c0eae66eSBenny Halevy 			goto out_overflow;
3340cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33411da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
33421da177e4SLinus Torvalds 	}
33433110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
33441da177e4SLinus Torvalds 	return 0;
3345c0eae66eSBenny Halevy out_overflow:
3346c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3347c0eae66eSBenny Halevy 	return -EIO;
33481da177e4SLinus Torvalds }
33491da177e4SLinus Torvalds 
33508b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
33511da177e4SLinus Torvalds {
33528687b63aSAl Viro 	__be32 *p;
3353409924e4STrond Myklebust 	int ret = 0;
33541da177e4SLinus Torvalds 
33551da177e4SLinus Torvalds 	fsid->major = 0;
33561da177e4SLinus Torvalds 	fsid->minor = 0;
33571da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
33581da177e4SLinus Torvalds 		return -EIO;
33591da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3360c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3361c0eae66eSBenny Halevy 		if (unlikely(!p))
3362c0eae66eSBenny Halevy 			goto out_overflow;
33633ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3364cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
33651da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3366409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
33671da177e4SLinus Torvalds 	}
33683110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
33691da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
33701da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3371409924e4STrond Myklebust 	return ret;
3372c0eae66eSBenny Halevy out_overflow:
3373c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3374c0eae66eSBenny Halevy 	return -EIO;
33751da177e4SLinus Torvalds }
33761da177e4SLinus Torvalds 
33771da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33781da177e4SLinus Torvalds {
33798687b63aSAl Viro 	__be32 *p;
33801da177e4SLinus Torvalds 
33811da177e4SLinus Torvalds 	*res = 60;
33821da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
33831da177e4SLinus Torvalds 		return -EIO;
33841da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3385c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3386c0eae66eSBenny Halevy 		if (unlikely(!p))
3387c0eae66eSBenny Halevy 			goto out_overflow;
3388cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33891da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
33901da177e4SLinus Torvalds 	}
33913110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
33921da177e4SLinus Torvalds 	return 0;
3393c0eae66eSBenny Halevy out_overflow:
3394c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3395c0eae66eSBenny Halevy 	return -EIO;
33961da177e4SLinus Torvalds }
33971da177e4SLinus Torvalds 
3398ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3399ae42c70aSBryan Schumaker {
3400ae42c70aSBryan Schumaker 	__be32 *p;
3401ae42c70aSBryan Schumaker 
3402ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3403ae42c70aSBryan Schumaker 		return -EIO;
3404ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3405ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3406ae42c70aSBryan Schumaker 		if (unlikely(!p))
3407ae42c70aSBryan Schumaker 			goto out_overflow;
3408ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3409ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3410ae42c70aSBryan Schumaker 	}
3411ae42c70aSBryan Schumaker 	return 0;
3412ae42c70aSBryan Schumaker out_overflow:
3413ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3414ae42c70aSBryan Schumaker 	return -EIO;
3415ae42c70aSBryan Schumaker }
3416ae42c70aSBryan Schumaker 
3417ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3418ae42c70aSBryan Schumaker {
3419ae42c70aSBryan Schumaker 	__be32 *p;
3420ae42c70aSBryan Schumaker 	int len;
3421ae42c70aSBryan Schumaker 
34227ad07353STrond Myklebust 	if (fh != NULL)
3423ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3424ae42c70aSBryan Schumaker 
3425ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3426ae42c70aSBryan Schumaker 		return -EIO;
3427ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3428ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3429ae42c70aSBryan Schumaker 		if (unlikely(!p))
3430ae42c70aSBryan Schumaker 			goto out_overflow;
3431ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3432ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3433ae42c70aSBryan Schumaker 			return -EIO;
3434ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3435ae42c70aSBryan Schumaker 		if (unlikely(!p))
3436ae42c70aSBryan Schumaker 			goto out_overflow;
34377ad07353STrond Myklebust 		if (fh != NULL) {
3438ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
34397ad07353STrond Myklebust 			fh->size = len;
34407ad07353STrond Myklebust 		}
3441ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3442ae42c70aSBryan Schumaker 	}
3443ae42c70aSBryan Schumaker 	return 0;
3444ae42c70aSBryan Schumaker out_overflow:
3445ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3446ae42c70aSBryan Schumaker 	return -EIO;
3447ae42c70aSBryan Schumaker }
3448ae42c70aSBryan Schumaker 
34491da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34501da177e4SLinus Torvalds {
34518687b63aSAl Viro 	__be32 *p;
34521da177e4SLinus Torvalds 
3453a1800acaSMalahal Naineni 	*res = 0;
34541da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
34551da177e4SLinus Torvalds 		return -EIO;
34561da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3457c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3458c0eae66eSBenny Halevy 		if (unlikely(!p))
3459c0eae66eSBenny Halevy 			goto out_overflow;
3460cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34611da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
34621da177e4SLinus Torvalds 	}
34633110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
34641da177e4SLinus Torvalds 	return 0;
3465c0eae66eSBenny Halevy out_overflow:
3466c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3467c0eae66eSBenny Halevy 	return -EIO;
34681da177e4SLinus Torvalds }
34691da177e4SLinus Torvalds 
34701da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
34711da177e4SLinus Torvalds {
34728687b63aSAl Viro 	__be32 *p;
3473409924e4STrond Myklebust 	int ret = 0;
34741da177e4SLinus Torvalds 
34751da177e4SLinus Torvalds 	*fileid = 0;
34761da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
34771da177e4SLinus Torvalds 		return -EIO;
34781da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3479c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3480c0eae66eSBenny Halevy 		if (unlikely(!p))
3481c0eae66eSBenny Halevy 			goto out_overflow;
3482cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
34831da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3484409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
34851da177e4SLinus Torvalds 	}
34863110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3487409924e4STrond Myklebust 	return ret;
3488c0eae66eSBenny Halevy out_overflow:
3489c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3490c0eae66eSBenny Halevy 	return -EIO;
34911da177e4SLinus Torvalds }
34921da177e4SLinus Torvalds 
349399baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
349499baf625SManoj Naik {
34958687b63aSAl Viro 	__be32 *p;
3496409924e4STrond Myklebust 	int ret = 0;
349799baf625SManoj Naik 
349899baf625SManoj Naik 	*fileid = 0;
349999baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
350099baf625SManoj Naik 		return -EIO;
350199baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3502c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3503c0eae66eSBenny Halevy 		if (unlikely(!p))
3504c0eae66eSBenny Halevy 			goto out_overflow;
3505cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
350699baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
350728331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
350899baf625SManoj Naik 	}
35093110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3510409924e4STrond Myklebust 	return ret;
3511c0eae66eSBenny Halevy out_overflow:
3512c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3513c0eae66eSBenny Halevy 	return -EIO;
351499baf625SManoj Naik }
351599baf625SManoj Naik 
35161da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35171da177e4SLinus Torvalds {
35188687b63aSAl Viro 	__be32 *p;
35191da177e4SLinus Torvalds 	int status = 0;
35201da177e4SLinus Torvalds 
35211da177e4SLinus Torvalds 	*res = 0;
35221da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
35231da177e4SLinus Torvalds 		return -EIO;
35241da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3525c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3526c0eae66eSBenny Halevy 		if (unlikely(!p))
3527c0eae66eSBenny Halevy 			goto out_overflow;
3528cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35291da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
35301da177e4SLinus Torvalds 	}
35313110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
35321da177e4SLinus Torvalds 	return status;
3533c0eae66eSBenny Halevy out_overflow:
3534c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3535c0eae66eSBenny Halevy 	return -EIO;
35361da177e4SLinus Torvalds }
35371da177e4SLinus Torvalds 
35381da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35391da177e4SLinus Torvalds {
35408687b63aSAl Viro 	__be32 *p;
35411da177e4SLinus Torvalds 	int status = 0;
35421da177e4SLinus Torvalds 
35431da177e4SLinus Torvalds 	*res = 0;
35441da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
35451da177e4SLinus Torvalds 		return -EIO;
35461da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3547c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3548c0eae66eSBenny Halevy 		if (unlikely(!p))
3549c0eae66eSBenny Halevy 			goto out_overflow;
3550cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35511da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
35521da177e4SLinus Torvalds 	}
35533110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
35541da177e4SLinus Torvalds 	return status;
3555c0eae66eSBenny Halevy out_overflow:
3556c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3557c0eae66eSBenny Halevy 	return -EIO;
35581da177e4SLinus Torvalds }
35591da177e4SLinus Torvalds 
35601da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35611da177e4SLinus Torvalds {
35628687b63aSAl Viro 	__be32 *p;
35631da177e4SLinus Torvalds 	int status = 0;
35641da177e4SLinus Torvalds 
35651da177e4SLinus Torvalds 	*res = 0;
35661da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
35671da177e4SLinus Torvalds 		return -EIO;
35681da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3569c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3570c0eae66eSBenny Halevy 		if (unlikely(!p))
3571c0eae66eSBenny Halevy 			goto out_overflow;
3572cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35731da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
35741da177e4SLinus Torvalds 	}
35753110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
35761da177e4SLinus Torvalds 	return status;
3577c0eae66eSBenny Halevy out_overflow:
3578c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3579c0eae66eSBenny Halevy 	return -EIO;
35801da177e4SLinus Torvalds }
35811da177e4SLinus Torvalds 
35827aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
35837aaa0b3bSManoj Naik {
3584464ad6b1SChuck Lever 	u32 n;
35858687b63aSAl Viro 	__be32 *p;
35867aaa0b3bSManoj Naik 	int status = 0;
35877aaa0b3bSManoj Naik 
3588c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3589c0eae66eSBenny Halevy 	if (unlikely(!p))
3590c0eae66eSBenny Halevy 		goto out_overflow;
3591cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
359233a43f28SAndy Adamson 	if (n == 0)
359333a43f28SAndy Adamson 		goto root_path;
359402a2976cSChuck Lever 	dprintk("pathname4: ");
3595809b426cSTrond Myklebust 	if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3596809b426cSTrond Myklebust 		dprintk("cannot parse %d components in path\n", n);
3597809b426cSTrond Myklebust 		goto out_eio;
3598809b426cSTrond Myklebust 	}
3599809b426cSTrond Myklebust 	for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
36007aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
36017aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
36027aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36037aaa0b3bSManoj Naik 			goto out_eio;
360495a13f7bSTrond Myklebust 		ifdebug (XDR)
360502a2976cSChuck Lever 			pr_cont("%s%.*s ",
360602a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
360702a2976cSChuck Lever 				component->len, component->data);
36087aaa0b3bSManoj Naik 	}
36097aaa0b3bSManoj Naik out:
36107aaa0b3bSManoj Naik 	return status;
361133a43f28SAndy Adamson root_path:
361233a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
361333a43f28SAndy Adamson 	path->ncomponents = 1;
361433a43f28SAndy Adamson 	path->components[0].len=0;
361533a43f28SAndy Adamson 	path->components[0].data=NULL;
361602a2976cSChuck Lever 	dprintk("pathname4: /\n");
361733a43f28SAndy Adamson 	goto out;
36187aaa0b3bSManoj Naik out_eio:
36197aaa0b3bSManoj Naik 	dprintk(" status %d", status);
36207aaa0b3bSManoj Naik 	status = -EIO;
36217aaa0b3bSManoj Naik 	goto out;
3622c0eae66eSBenny Halevy out_overflow:
3623c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3624c0eae66eSBenny Halevy 	return -EIO;
36257aaa0b3bSManoj Naik }
36267aaa0b3bSManoj Naik 
36277aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3628683b57b4STrond Myklebust {
3629683b57b4STrond Myklebust 	int n;
36308687b63aSAl Viro 	__be32 *p;
3631683b57b4STrond Myklebust 	int status = -EIO;
3632683b57b4STrond Myklebust 
3633683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3634683b57b4STrond Myklebust 		goto out;
3635683b57b4STrond Myklebust 	status = 0;
3636683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3637683b57b4STrond Myklebust 		goto out;
36388b7e3f49STrond Myklebust 	status = -EIO;
36398b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
36408b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
36418b7e3f49STrond Myklebust 		goto out;
364202a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
36437aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3644683b57b4STrond Myklebust 	if (unlikely(status != 0))
3645683b57b4STrond Myklebust 		goto out;
3646c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3647c0eae66eSBenny Halevy 	if (unlikely(!p))
3648c0eae66eSBenny Halevy 		goto out_overflow;
3649cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3650683b57b4STrond Myklebust 	if (n <= 0)
3651683b57b4STrond Myklebust 		goto out_eio;
3652809b426cSTrond Myklebust 	for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3653464ad6b1SChuck Lever 		u32 m;
3654809b426cSTrond Myklebust 		struct nfs4_fs_location *loc;
3655683b57b4STrond Myklebust 
3656809b426cSTrond Myklebust 		if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3657809b426cSTrond Myklebust 			break;
3658809b426cSTrond Myklebust 		loc = &res->locations[res->nlocations];
3659c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3660c0eae66eSBenny Halevy 		if (unlikely(!p))
3661c0eae66eSBenny Halevy 			goto out_overflow;
3662cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
36637aaa0b3bSManoj Naik 
366402a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
3665809b426cSTrond Myklebust 		for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3666809b426cSTrond Myklebust 			struct nfs4_string *server;
3667809b426cSTrond Myklebust 
3668809b426cSTrond Myklebust 			if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3669464ad6b1SChuck Lever 				unsigned int i;
3670464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3671464ad6b1SChuck Lever 					"returned for location %u\n",
36723110ff80SHarvey Harrison 						__func__,
3673464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3674464ad6b1SChuck Lever 						m, res->nlocations);
36757aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
36762e42c3e2STrond Myklebust 					unsigned int len;
36777aaa0b3bSManoj Naik 					char *data;
36787aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3679683b57b4STrond Myklebust 					if (unlikely(status != 0))
3680683b57b4STrond Myklebust 						goto out_eio;
36817aaa0b3bSManoj Naik 				}
3682809b426cSTrond Myklebust 				break;
36837aaa0b3bSManoj Naik 			}
3684809b426cSTrond Myklebust 			server = &loc->servers[loc->nservers];
3685809b426cSTrond Myklebust 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3686809b426cSTrond Myklebust 			if (unlikely(status != 0))
3687809b426cSTrond Myklebust 				goto out_eio;
3688809b426cSTrond Myklebust 			dprintk("%s ", server->data);
36897aaa0b3bSManoj Naik 		}
36907aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
36917aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36927aaa0b3bSManoj Naik 			goto out_eio;
3693683b57b4STrond Myklebust 	}
3694409924e4STrond Myklebust 	if (res->nlocations != 0)
369581934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3696683b57b4STrond Myklebust out:
36973110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3698683b57b4STrond Myklebust 	return status;
3699c0eae66eSBenny Halevy out_overflow:
3700c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3701683b57b4STrond Myklebust out_eio:
3702683b57b4STrond Myklebust 	status = -EIO;
3703683b57b4STrond Myklebust 	goto out;
3704683b57b4STrond Myklebust }
3705683b57b4STrond Myklebust 
37061da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
37071da177e4SLinus Torvalds {
37088687b63aSAl Viro 	__be32 *p;
37091da177e4SLinus Torvalds 	int status = 0;
37101da177e4SLinus Torvalds 
37111da177e4SLinus Torvalds 	*res = 0;
37121da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
37131da177e4SLinus Torvalds 		return -EIO;
37141da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3715c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3716c0eae66eSBenny Halevy 		if (unlikely(!p))
3717c0eae66eSBenny Halevy 			goto out_overflow;
3718cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
37191da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
37201da177e4SLinus Torvalds 	}
37213110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
37221da177e4SLinus Torvalds 	return status;
3723c0eae66eSBenny Halevy out_overflow:
3724c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3725c0eae66eSBenny Halevy 	return -EIO;
37261da177e4SLinus Torvalds }
37271da177e4SLinus Torvalds 
37281da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
37291da177e4SLinus Torvalds {
37308687b63aSAl Viro 	__be32 *p;
37311da177e4SLinus Torvalds 	int status = 0;
37321da177e4SLinus Torvalds 
37331da177e4SLinus Torvalds 	*maxlink = 1;
37341da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
37351da177e4SLinus Torvalds 		return -EIO;
37361da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3737c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3738c0eae66eSBenny Halevy 		if (unlikely(!p))
3739c0eae66eSBenny Halevy 			goto out_overflow;
3740cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
37411da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
37421da177e4SLinus Torvalds 	}
37433110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
37441da177e4SLinus Torvalds 	return status;
3745c0eae66eSBenny Halevy out_overflow:
3746c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3747c0eae66eSBenny Halevy 	return -EIO;
37481da177e4SLinus Torvalds }
37491da177e4SLinus Torvalds 
37501da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
37511da177e4SLinus Torvalds {
37528687b63aSAl Viro 	__be32 *p;
37531da177e4SLinus Torvalds 	int status = 0;
37541da177e4SLinus Torvalds 
37551da177e4SLinus Torvalds 	*maxname = 1024;
37561da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
37571da177e4SLinus Torvalds 		return -EIO;
37581da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3759c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3760c0eae66eSBenny Halevy 		if (unlikely(!p))
3761c0eae66eSBenny Halevy 			goto out_overflow;
3762cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
37631da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
37641da177e4SLinus Torvalds 	}
37653110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
37661da177e4SLinus Torvalds 	return status;
3767c0eae66eSBenny Halevy out_overflow:
3768c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3769c0eae66eSBenny Halevy 	return -EIO;
37701da177e4SLinus Torvalds }
37711da177e4SLinus Torvalds 
37721da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37731da177e4SLinus Torvalds {
37748687b63aSAl Viro 	__be32 *p;
37751da177e4SLinus Torvalds 	int status = 0;
37761da177e4SLinus Torvalds 
37771da177e4SLinus Torvalds 	*res = 1024;
37781da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
37791da177e4SLinus Torvalds 		return -EIO;
37801da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
37811da177e4SLinus Torvalds 		uint64_t maxread;
3782c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3783c0eae66eSBenny Halevy 		if (unlikely(!p))
3784c0eae66eSBenny Halevy 			goto out_overflow;
3785cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
37861da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
37871da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
37881da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
37891da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
37901da177e4SLinus Torvalds 	}
37913110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
37921da177e4SLinus Torvalds 	return status;
3793c0eae66eSBenny Halevy out_overflow:
3794c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3795c0eae66eSBenny Halevy 	return -EIO;
37961da177e4SLinus Torvalds }
37971da177e4SLinus Torvalds 
37981da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37991da177e4SLinus Torvalds {
38008687b63aSAl Viro 	__be32 *p;
38011da177e4SLinus Torvalds 	int status = 0;
38021da177e4SLinus Torvalds 
38031da177e4SLinus Torvalds 	*res = 1024;
38041da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
38051da177e4SLinus Torvalds 		return -EIO;
38061da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
38071da177e4SLinus Torvalds 		uint64_t maxwrite;
3808c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3809c0eae66eSBenny Halevy 		if (unlikely(!p))
3810c0eae66eSBenny Halevy 			goto out_overflow;
3811cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
38121da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
38131da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
38141da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
38151da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
38161da177e4SLinus Torvalds 	}
38173110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
38181da177e4SLinus Torvalds 	return status;
3819c0eae66eSBenny Halevy out_overflow:
3820c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3821c0eae66eSBenny Halevy 	return -EIO;
38221da177e4SLinus Torvalds }
38231da177e4SLinus Torvalds 
3824bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
38251da177e4SLinus Torvalds {
3826bca79478STrond Myklebust 	uint32_t tmp;
38278687b63aSAl Viro 	__be32 *p;
3828409924e4STrond Myklebust 	int ret = 0;
38291da177e4SLinus Torvalds 
38301da177e4SLinus Torvalds 	*mode = 0;
38311da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38321da177e4SLinus Torvalds 		return -EIO;
38331da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3834c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3835c0eae66eSBenny Halevy 		if (unlikely(!p))
3836c0eae66eSBenny Halevy 			goto out_overflow;
3837cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3838bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
38391da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3840409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
38411da177e4SLinus Torvalds 	}
38423110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3843409924e4STrond Myklebust 	return ret;
3844c0eae66eSBenny Halevy out_overflow:
3845c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3846c0eae66eSBenny Halevy 	return -EIO;
38471da177e4SLinus Torvalds }
38481da177e4SLinus Torvalds 
38491da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
38501da177e4SLinus Torvalds {
38518687b63aSAl Viro 	__be32 *p;
3852409924e4STrond Myklebust 	int ret = 0;
38531da177e4SLinus Torvalds 
38541da177e4SLinus Torvalds 	*nlink = 1;
38551da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
38561da177e4SLinus Torvalds 		return -EIO;
38571da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3858c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3859c0eae66eSBenny Halevy 		if (unlikely(!p))
3860c0eae66eSBenny Halevy 			goto out_overflow;
3861cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
38621da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3863409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
38641da177e4SLinus Torvalds 	}
38653110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3866409924e4STrond Myklebust 	return ret;
3867c0eae66eSBenny Halevy out_overflow:
3868c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3869c0eae66eSBenny Halevy 	return -EIO;
38701da177e4SLinus Torvalds }
38711da177e4SLinus Torvalds 
387280e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3873e5782076SEric W. Biederman 		const struct nfs_server *server, kuid_t *uid,
38746926afd1STrond Myklebust 		struct nfs4_string *owner_name)
38751da177e4SLinus Torvalds {
38768687b63aSAl Viro 	uint32_t len;
38778687b63aSAl Viro 	__be32 *p;
3878409924e4STrond Myklebust 	int ret = 0;
38791da177e4SLinus Torvalds 
3880e5782076SEric W. Biederman 	*uid = make_kuid(&init_user_ns, -2);
38811da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
38821da177e4SLinus Torvalds 		return -EIO;
38831da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3884c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3885c0eae66eSBenny Halevy 		if (unlikely(!p))
3886c0eae66eSBenny Halevy 			goto out_overflow;
3887cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3888c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3889c0eae66eSBenny Halevy 		if (unlikely(!p))
3890c0eae66eSBenny Halevy 			goto out_overflow;
38916926afd1STrond Myklebust 		if (owner_name != NULL) {
38926926afd1STrond Myklebust 			owner_name->data = kmemdup(p, len, GFP_NOWAIT);
38936926afd1STrond Myklebust 			if (owner_name->data != NULL) {
38946926afd1STrond Myklebust 				owner_name->len = len;
38956926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER_NAME;
38966926afd1STrond Myklebust 			}
389780e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3898e4fd72a1STrond Myklebust 			if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3899409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER;
3900409924e4STrond Myklebust 			else
39011da177e4SLinus Torvalds 				dprintk("%s: nfs_map_name_to_uid failed!\n",
39023110ff80SHarvey Harrison 						__func__);
39031da177e4SLinus Torvalds 		} else
3904fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
39053110ff80SHarvey Harrison 					__func__, len);
39061da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER;
39071da177e4SLinus Torvalds 	}
3908e5782076SEric W. Biederman 	dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3909409924e4STrond Myklebust 	return ret;
3910c0eae66eSBenny Halevy out_overflow:
3911c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3912c0eae66eSBenny Halevy 	return -EIO;
39131da177e4SLinus Torvalds }
39141da177e4SLinus Torvalds 
391580e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3916e5782076SEric W. Biederman 		const struct nfs_server *server, kgid_t *gid,
39176926afd1STrond Myklebust 		struct nfs4_string *group_name)
39181da177e4SLinus Torvalds {
39198687b63aSAl Viro 	uint32_t len;
39208687b63aSAl Viro 	__be32 *p;
3921409924e4STrond Myklebust 	int ret = 0;
39221da177e4SLinus Torvalds 
3923e5782076SEric W. Biederman 	*gid = make_kgid(&init_user_ns, -2);
39241da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
39251da177e4SLinus Torvalds 		return -EIO;
39261da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3927c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3928c0eae66eSBenny Halevy 		if (unlikely(!p))
3929c0eae66eSBenny Halevy 			goto out_overflow;
3930cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3931c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3932c0eae66eSBenny Halevy 		if (unlikely(!p))
3933c0eae66eSBenny Halevy 			goto out_overflow;
39346926afd1STrond Myklebust 		if (group_name != NULL) {
39356926afd1STrond Myklebust 			group_name->data = kmemdup(p, len, GFP_NOWAIT);
39366926afd1STrond Myklebust 			if (group_name->data != NULL) {
39376926afd1STrond Myklebust 				group_name->len = len;
39386926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP_NAME;
39396926afd1STrond Myklebust 			}
394080e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3941e4fd72a1STrond Myklebust 			if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3942409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP;
3943409924e4STrond Myklebust 			else
39441da177e4SLinus Torvalds 				dprintk("%s: nfs_map_group_to_gid failed!\n",
39453110ff80SHarvey Harrison 						__func__);
39461da177e4SLinus Torvalds 		} else
3947fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
39483110ff80SHarvey Harrison 					__func__, len);
39491da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
39501da177e4SLinus Torvalds 	}
3951e5782076SEric W. Biederman 	dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3952409924e4STrond Myklebust 	return ret;
3953c0eae66eSBenny Halevy out_overflow:
3954c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3955c0eae66eSBenny Halevy 	return -EIO;
39561da177e4SLinus Torvalds }
39571da177e4SLinus Torvalds 
39581da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
39591da177e4SLinus Torvalds {
39608687b63aSAl Viro 	uint32_t major = 0, minor = 0;
39618687b63aSAl Viro 	__be32 *p;
3962409924e4STrond Myklebust 	int ret = 0;
39631da177e4SLinus Torvalds 
39641da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
39651da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
39661da177e4SLinus Torvalds 		return -EIO;
39671da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
39681da177e4SLinus Torvalds 		dev_t tmp;
39691da177e4SLinus Torvalds 
3970c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3971c0eae66eSBenny Halevy 		if (unlikely(!p))
3972c0eae66eSBenny Halevy 			goto out_overflow;
39736f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3974cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
39751da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
39761da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
39771da177e4SLinus Torvalds 			*rdev = tmp;
39781da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3979409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
39801da177e4SLinus Torvalds 	}
39813110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3982409924e4STrond Myklebust 	return ret;
3983c0eae66eSBenny Halevy out_overflow:
3984c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3985c0eae66eSBenny Halevy 	return -EIO;
39861da177e4SLinus Torvalds }
39871da177e4SLinus Torvalds 
39881da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39891da177e4SLinus Torvalds {
39908687b63aSAl Viro 	__be32 *p;
39911da177e4SLinus Torvalds 	int status = 0;
39921da177e4SLinus Torvalds 
39931da177e4SLinus Torvalds 	*res = 0;
39941da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
39951da177e4SLinus Torvalds 		return -EIO;
39961da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3997c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3998c0eae66eSBenny Halevy 		if (unlikely(!p))
3999c0eae66eSBenny Halevy 			goto out_overflow;
4000cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40011da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
40021da177e4SLinus Torvalds 	}
40033110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
40041da177e4SLinus Torvalds 	return status;
4005c0eae66eSBenny Halevy out_overflow:
4006c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4007c0eae66eSBenny Halevy 	return -EIO;
40081da177e4SLinus Torvalds }
40091da177e4SLinus Torvalds 
40101da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40111da177e4SLinus Torvalds {
40128687b63aSAl Viro 	__be32 *p;
40131da177e4SLinus Torvalds 	int status = 0;
40141da177e4SLinus Torvalds 
40151da177e4SLinus Torvalds 	*res = 0;
40161da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40171da177e4SLinus Torvalds 		return -EIO;
40181da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4019c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4020c0eae66eSBenny Halevy 		if (unlikely(!p))
4021c0eae66eSBenny Halevy 			goto out_overflow;
4022cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40231da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40241da177e4SLinus Torvalds 	}
40253110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40261da177e4SLinus Torvalds 	return status;
4027c0eae66eSBenny Halevy out_overflow:
4028c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4029c0eae66eSBenny Halevy 	return -EIO;
40301da177e4SLinus Torvalds }
40311da177e4SLinus Torvalds 
40321da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40331da177e4SLinus Torvalds {
40348687b63aSAl Viro 	__be32 *p;
40351da177e4SLinus Torvalds 	int status = 0;
40361da177e4SLinus Torvalds 
40371da177e4SLinus Torvalds 	*res = 0;
40381da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
40391da177e4SLinus Torvalds 		return -EIO;
40401da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4041c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4042c0eae66eSBenny Halevy 		if (unlikely(!p))
4043c0eae66eSBenny Halevy 			goto out_overflow;
4044cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40451da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
40461da177e4SLinus Torvalds 	}
40473110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
40481da177e4SLinus Torvalds 	return status;
4049c0eae66eSBenny Halevy out_overflow:
4050c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4051c0eae66eSBenny Halevy 	return -EIO;
40521da177e4SLinus Torvalds }
40531da177e4SLinus Torvalds 
40541da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
40551da177e4SLinus Torvalds {
40568687b63aSAl Viro 	__be32 *p;
4057409924e4STrond Myklebust 	int ret = 0;
40581da177e4SLinus Torvalds 
40591da177e4SLinus Torvalds 	*used = 0;
40601da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
40611da177e4SLinus Torvalds 		return -EIO;
40621da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4063c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4064c0eae66eSBenny Halevy 		if (unlikely(!p))
4065c0eae66eSBenny Halevy 			goto out_overflow;
4066cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
40671da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4068409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
40691da177e4SLinus Torvalds 	}
40703110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
40711da177e4SLinus Torvalds 			(unsigned long long)*used);
4072409924e4STrond Myklebust 	return ret;
4073c0eae66eSBenny Halevy out_overflow:
4074c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4075c0eae66eSBenny Halevy 	return -EIO;
40761da177e4SLinus Torvalds }
40771da177e4SLinus Torvalds 
40781da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
40791da177e4SLinus Torvalds {
40808687b63aSAl Viro 	__be32 *p;
40811da177e4SLinus Torvalds 	uint64_t sec;
40821da177e4SLinus Torvalds 	uint32_t nsec;
40831da177e4SLinus Torvalds 
4084c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4085c0eae66eSBenny Halevy 	if (unlikely(!p))
4086c0eae66eSBenny Halevy 		goto out_overflow;
40873ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &sec);
4088cccddf4fSBenny Halevy 	nsec = be32_to_cpup(p);
40891da177e4SLinus Torvalds 	time->tv_sec = (time_t)sec;
40901da177e4SLinus Torvalds 	time->tv_nsec = (long)nsec;
40911da177e4SLinus Torvalds 	return 0;
4092c0eae66eSBenny Halevy out_overflow:
4093c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4094c0eae66eSBenny Halevy 	return -EIO;
40951da177e4SLinus Torvalds }
40961da177e4SLinus Torvalds 
40971da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40981da177e4SLinus Torvalds {
40991da177e4SLinus Torvalds 	int status = 0;
41001da177e4SLinus Torvalds 
41011da177e4SLinus Torvalds 	time->tv_sec = 0;
41021da177e4SLinus Torvalds 	time->tv_nsec = 0;
41031da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
41041da177e4SLinus Torvalds 		return -EIO;
41051da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
41061da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4107409924e4STrond Myklebust 		if (status == 0)
4108409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
41091da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
41101da177e4SLinus Torvalds 	}
41113110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
41121da177e4SLinus Torvalds 	return status;
41131da177e4SLinus Torvalds }
41141da177e4SLinus Torvalds 
41151da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41161da177e4SLinus Torvalds {
41171da177e4SLinus Torvalds 	int status = 0;
41181da177e4SLinus Torvalds 
41191da177e4SLinus Torvalds 	time->tv_sec = 0;
41201da177e4SLinus Torvalds 	time->tv_nsec = 0;
41211da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41221da177e4SLinus Torvalds 		return -EIO;
41231da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41241da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4125409924e4STrond Myklebust 		if (status == 0)
4126409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
41271da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41281da177e4SLinus Torvalds 	}
41293110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
41301da177e4SLinus Torvalds 	return status;
41311da177e4SLinus Torvalds }
41321da177e4SLinus Torvalds 
413355b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
413455b6e774SRicardo Labiaga 				  struct timespec *time)
413555b6e774SRicardo Labiaga {
413655b6e774SRicardo Labiaga 	int status = 0;
413755b6e774SRicardo Labiaga 
413855b6e774SRicardo Labiaga 	time->tv_sec = 0;
413955b6e774SRicardo Labiaga 	time->tv_nsec = 0;
414055b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
414155b6e774SRicardo Labiaga 		return -EIO;
414255b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
414355b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
414455b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
414555b6e774SRicardo Labiaga 	}
414655b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
414755b6e774SRicardo Labiaga 		(long)time->tv_nsec);
414855b6e774SRicardo Labiaga 	return status;
414955b6e774SRicardo Labiaga }
415055b6e774SRicardo Labiaga 
4151aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4152aa9c2669SDavid Quigley 					struct nfs4_label *label)
4153aa9c2669SDavid Quigley {
4154aa9c2669SDavid Quigley 	uint32_t pi = 0;
4155aa9c2669SDavid Quigley 	uint32_t lfs = 0;
4156aa9c2669SDavid Quigley 	__u32 len;
4157aa9c2669SDavid Quigley 	__be32 *p;
4158aa9c2669SDavid Quigley 	int status = 0;
4159aa9c2669SDavid Quigley 
4160aa9c2669SDavid Quigley 	if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4161aa9c2669SDavid Quigley 		return -EIO;
4162aa9c2669SDavid Quigley 	if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4163aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4164aa9c2669SDavid Quigley 		if (unlikely(!p))
4165aa9c2669SDavid Quigley 			goto out_overflow;
4166aa9c2669SDavid Quigley 		lfs = be32_to_cpup(p++);
4167aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4168aa9c2669SDavid Quigley 		if (unlikely(!p))
4169aa9c2669SDavid Quigley 			goto out_overflow;
4170aa9c2669SDavid Quigley 		pi = be32_to_cpup(p++);
4171aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4172aa9c2669SDavid Quigley 		if (unlikely(!p))
4173aa9c2669SDavid Quigley 			goto out_overflow;
4174aa9c2669SDavid Quigley 		len = be32_to_cpup(p++);
4175aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, len);
4176aa9c2669SDavid Quigley 		if (unlikely(!p))
4177aa9c2669SDavid Quigley 			goto out_overflow;
4178aa9c2669SDavid Quigley 		if (len < NFS4_MAXLABELLEN) {
4179aa9c2669SDavid Quigley 			if (label) {
4180aa9c2669SDavid Quigley 				memcpy(label->label, p, len);
4181aa9c2669SDavid Quigley 				label->len = len;
4182aa9c2669SDavid Quigley 				label->pi = pi;
4183aa9c2669SDavid Quigley 				label->lfs = lfs;
4184aa9c2669SDavid Quigley 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4185aa9c2669SDavid Quigley 			}
4186aa9c2669SDavid Quigley 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4187aa9c2669SDavid Quigley 		} else
4188aa9c2669SDavid Quigley 			printk(KERN_WARNING "%s: label too long (%u)!\n",
4189aa9c2669SDavid Quigley 					__func__, len);
4190aa9c2669SDavid Quigley 	}
4191aa9c2669SDavid Quigley 	if (label && label->label)
4192aa9c2669SDavid Quigley 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4193aa9c2669SDavid Quigley 			(char *)label->label, label->len, label->pi, label->lfs);
4194aa9c2669SDavid Quigley 	return status;
4195aa9c2669SDavid Quigley 
4196aa9c2669SDavid Quigley out_overflow:
4197aa9c2669SDavid Quigley 	print_overflow_msg(__func__, xdr);
4198aa9c2669SDavid Quigley 	return -EIO;
4199aa9c2669SDavid Quigley }
4200aa9c2669SDavid Quigley 
42011da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
42021da177e4SLinus Torvalds {
42031da177e4SLinus Torvalds 	int status = 0;
42041da177e4SLinus Torvalds 
42051da177e4SLinus Torvalds 	time->tv_sec = 0;
42061da177e4SLinus Torvalds 	time->tv_nsec = 0;
42071da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
42081da177e4SLinus Torvalds 		return -EIO;
42091da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
42101da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4211409924e4STrond Myklebust 		if (status == 0)
4212409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
42131da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
42141da177e4SLinus Torvalds 	}
42153110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
42161da177e4SLinus Torvalds 	return status;
42171da177e4SLinus Torvalds }
42181da177e4SLinus Torvalds 
4219256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
42201da177e4SLinus Torvalds {
42211da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4222256e48bbSTrond Myklebust 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
42231da177e4SLinus Torvalds 
42241da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4225fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4226fe82a183SChuck Lever 			"%u %c %u\n",
42273110ff80SHarvey Harrison 				__func__,
42281da177e4SLinus Torvalds 				attrwords << 2,
42291da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
42301da177e4SLinus Torvalds 				nwords << 2);
42311da177e4SLinus Torvalds 		return -EIO;
42321da177e4SLinus Torvalds 	}
42331da177e4SLinus Torvalds 	return 0;
42341da177e4SLinus Torvalds }
42351da177e4SLinus Torvalds 
42361da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
42371da177e4SLinus Torvalds {
42388687b63aSAl Viro 	__be32 *p;
42391da177e4SLinus Torvalds 
4240c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4241c0eae66eSBenny Halevy 	if (unlikely(!p))
4242c0eae66eSBenny Halevy 		goto out_overflow;
42436f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
42443ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4245cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
42461da177e4SLinus Torvalds 	return 0;
4247c0eae66eSBenny Halevy out_overflow:
4248c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4249c0eae66eSBenny Halevy 	return -EIO;
42501da177e4SLinus Torvalds }
42511da177e4SLinus Torvalds 
42526168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
42531da177e4SLinus Torvalds {
42548687b63aSAl Viro 	__be32 *p;
42551da177e4SLinus Torvalds 	uint32_t supp, acc;
42561da177e4SLinus Torvalds 	int status;
42571da177e4SLinus Torvalds 
42581da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
42591da177e4SLinus Torvalds 	if (status)
42601da177e4SLinus Torvalds 		return status;
4261c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4262c0eae66eSBenny Halevy 	if (unlikely(!p))
4263c0eae66eSBenny Halevy 		goto out_overflow;
42646f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4265cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
42666168f62cSWeston Andros Adamson 	*supported = supp;
42676168f62cSWeston Andros Adamson 	*access = acc;
42681da177e4SLinus Torvalds 	return 0;
4269c0eae66eSBenny Halevy out_overflow:
4270c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4271c0eae66eSBenny Halevy 	return -EIO;
42721da177e4SLinus Torvalds }
42731da177e4SLinus Torvalds 
427407d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
42751da177e4SLinus Torvalds {
42768687b63aSAl Viro 	__be32 *p;
427707d30434SBenny Halevy 
427807d30434SBenny Halevy 	p = xdr_inline_decode(xdr, len);
427907d30434SBenny Halevy 	if (likely(p)) {
428007d30434SBenny Halevy 		memcpy(buf, p, len);
428107d30434SBenny Halevy 		return 0;
428207d30434SBenny Halevy 	}
428307d30434SBenny Halevy 	print_overflow_msg(__func__, xdr);
428407d30434SBenny Halevy 	return -EIO;
428507d30434SBenny Halevy }
428607d30434SBenny Halevy 
428707d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
428807d30434SBenny Halevy {
42892d2f24adSTrond Myklebust 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
42901da177e4SLinus Torvalds }
42911da177e4SLinus Torvalds 
42921da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
42931da177e4SLinus Torvalds {
42941da177e4SLinus Torvalds 	int status;
42951da177e4SLinus Torvalds 
42961da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4297c1d51931STrond Myklebust 	if (status != -EIO)
4298c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
429907d30434SBenny Halevy 	if (!status)
430007d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
43011da177e4SLinus Torvalds 	return status;
43021da177e4SLinus Torvalds }
43031da177e4SLinus Torvalds 
4304db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4305db942bbdSBenny Halevy {
4306cd93710eSChuck Lever 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
43071da177e4SLinus Torvalds }
43081da177e4SLinus Torvalds 
43092f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
43102f2c63bcSTrond Myklebust {
43112f2c63bcSTrond Myklebust 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
43122f2c63bcSTrond Myklebust }
43132f2c63bcSTrond Myklebust 
43140b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
43151da177e4SLinus Torvalds {
43161da177e4SLinus Torvalds 	int status;
43171da177e4SLinus Torvalds 
43181da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4319db942bbdSBenny Halevy 	if (!status)
43202f2c63bcSTrond Myklebust 		status = decode_write_verifier(xdr, &res->verf->verifier);
43211da177e4SLinus Torvalds 	return status;
43221da177e4SLinus Torvalds }
43231da177e4SLinus Torvalds 
43241da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
43251da177e4SLinus Torvalds {
43268687b63aSAl Viro 	__be32 *p;
43271da177e4SLinus Torvalds 	uint32_t bmlen;
43281da177e4SLinus Torvalds 	int status;
43291da177e4SLinus Torvalds 
43301da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
43311da177e4SLinus Torvalds 	if (status)
43321da177e4SLinus Torvalds 		return status;
43331da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
43341da177e4SLinus Torvalds 		return status;
4335c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4336c0eae66eSBenny Halevy 	if (unlikely(!p))
4337c0eae66eSBenny Halevy 		goto out_overflow;
4338cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4339c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4340c0eae66eSBenny Halevy 	if (likely(p))
43411da177e4SLinus Torvalds 		return 0;
4342c0eae66eSBenny Halevy out_overflow:
4343c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4344c0eae66eSBenny Halevy 	return -EIO;
43451da177e4SLinus Torvalds }
43461da177e4SLinus Torvalds 
43471da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
43481da177e4SLinus Torvalds {
4349256e48bbSTrond Myklebust 	unsigned int savep;
4350dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43511da177e4SLinus Torvalds 	int status;
43521da177e4SLinus Torvalds 
43531da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43541da177e4SLinus Torvalds 		goto xdr_error;
43551da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43561da177e4SLinus Torvalds 		goto xdr_error;
43571da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43581da177e4SLinus Torvalds 		goto xdr_error;
43591da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
43601da177e4SLinus Torvalds 		goto xdr_error;
4361264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4362264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4363264e6351SChuck Lever 		goto xdr_error;
43641da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
43651da177e4SLinus Torvalds 		goto xdr_error;
43661da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
43671da177e4SLinus Torvalds 		goto xdr_error;
43681da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
43691da177e4SLinus Torvalds 		goto xdr_error;
43701da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43711da177e4SLinus Torvalds xdr_error:
43723110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43731da177e4SLinus Torvalds 	return status;
43741da177e4SLinus Torvalds }
43751da177e4SLinus Torvalds 
43761da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
43771da177e4SLinus Torvalds {
4378256e48bbSTrond Myklebust 	unsigned int savep;
4379dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43801da177e4SLinus Torvalds 	int status;
43811da177e4SLinus Torvalds 
43821da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43831da177e4SLinus Torvalds 		goto xdr_error;
43841da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43851da177e4SLinus Torvalds 		goto xdr_error;
43861da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43871da177e4SLinus Torvalds 		goto xdr_error;
43881da177e4SLinus Torvalds 
43891da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
43901da177e4SLinus Torvalds 		goto xdr_error;
43911da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
43921da177e4SLinus Torvalds 		goto xdr_error;
43931da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
43941da177e4SLinus Torvalds 		goto xdr_error;
43951da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
43961da177e4SLinus Torvalds 		goto xdr_error;
43971da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
43981da177e4SLinus Torvalds 		goto xdr_error;
43991da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
44001da177e4SLinus Torvalds 		goto xdr_error;
44011da177e4SLinus Torvalds 
44021da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44031da177e4SLinus Torvalds xdr_error:
44043110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44051da177e4SLinus Torvalds 	return status;
44061da177e4SLinus Torvalds }
44071da177e4SLinus Torvalds 
44081da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
44091da177e4SLinus Torvalds {
4410256e48bbSTrond Myklebust 	unsigned int savep;
4411dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
44121da177e4SLinus Torvalds 	int status;
44131da177e4SLinus Torvalds 
44141da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44151da177e4SLinus Torvalds 		goto xdr_error;
44161da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44171da177e4SLinus Torvalds 		goto xdr_error;
44181da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44191da177e4SLinus Torvalds 		goto xdr_error;
44201da177e4SLinus Torvalds 
44211da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
44221da177e4SLinus Torvalds 		goto xdr_error;
44231da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
44241da177e4SLinus Torvalds 		goto xdr_error;
44251da177e4SLinus Torvalds 
44261da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44271da177e4SLinus Torvalds xdr_error:
44283110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44291da177e4SLinus Torvalds 	return status;
44301da177e4SLinus Torvalds }
44311da177e4SLinus Torvalds 
443288034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
443388034c3dSAndy Adamson 				  uint32_t *bitmap,
443488034c3dSAndy Adamson 				  uint64_t *res,
443588034c3dSAndy Adamson 				  uint32_t hint_bit)
443688034c3dSAndy Adamson {
443788034c3dSAndy Adamson 	__be32 *p;
443888034c3dSAndy Adamson 
443988034c3dSAndy Adamson 	*res = 0;
444088034c3dSAndy Adamson 	if (likely(bitmap[0] & hint_bit)) {
444188034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
444288034c3dSAndy Adamson 		if (unlikely(!p))
444388034c3dSAndy Adamson 			goto out_overflow;
444488034c3dSAndy Adamson 		xdr_decode_hyper(p, res);
444588034c3dSAndy Adamson 	}
444688034c3dSAndy Adamson 	return 0;
444788034c3dSAndy Adamson out_overflow:
444888034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
444988034c3dSAndy Adamson 	return -EIO;
445088034c3dSAndy Adamson }
445188034c3dSAndy Adamson 
445288034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
445388034c3dSAndy Adamson 					struct nfs4_threshold *res)
445488034c3dSAndy Adamson {
4455256e48bbSTrond Myklebust 	__be32 *p;
4456256e48bbSTrond Myklebust 	unsigned int savep;
445788034c3dSAndy Adamson 	uint32_t bitmap[3] = {0,}, attrlen;
445888034c3dSAndy Adamson 	int status;
445988034c3dSAndy Adamson 
446088034c3dSAndy Adamson 	/* layout type */
446188034c3dSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
446288034c3dSAndy Adamson 	if (unlikely(!p)) {
446388034c3dSAndy Adamson 		print_overflow_msg(__func__, xdr);
446488034c3dSAndy Adamson 		return -EIO;
446588034c3dSAndy Adamson 	}
446688034c3dSAndy Adamson 	res->l_type = be32_to_cpup(p);
446788034c3dSAndy Adamson 
446888034c3dSAndy Adamson 	/* thi_hintset bitmap */
446988034c3dSAndy Adamson 	status = decode_attr_bitmap(xdr, bitmap);
447088034c3dSAndy Adamson 	if (status < 0)
447188034c3dSAndy Adamson 		goto xdr_error;
447288034c3dSAndy Adamson 
447388034c3dSAndy Adamson 	/* thi_hintlist length */
447488034c3dSAndy Adamson 	status = decode_attr_length(xdr, &attrlen, &savep);
447588034c3dSAndy Adamson 	if (status < 0)
447688034c3dSAndy Adamson 		goto xdr_error;
447788034c3dSAndy Adamson 	/* thi_hintlist */
447888034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
447988034c3dSAndy Adamson 	if (status < 0)
448088034c3dSAndy Adamson 		goto xdr_error;
448188034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
448288034c3dSAndy Adamson 	if (status < 0)
448388034c3dSAndy Adamson 		goto xdr_error;
448488034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
448588034c3dSAndy Adamson 				       THRESHOLD_RD_IO);
448688034c3dSAndy Adamson 	if (status < 0)
448788034c3dSAndy Adamson 		goto xdr_error;
448888034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
448988034c3dSAndy Adamson 				       THRESHOLD_WR_IO);
449088034c3dSAndy Adamson 	if (status < 0)
449188034c3dSAndy Adamson 		goto xdr_error;
449288034c3dSAndy Adamson 
449388034c3dSAndy Adamson 	status = verify_attr_len(xdr, savep, attrlen);
449488034c3dSAndy Adamson 	res->bm = bitmap[0];
449588034c3dSAndy Adamson 
449688034c3dSAndy Adamson 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
449788034c3dSAndy Adamson 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
449888034c3dSAndy Adamson 		res->wr_io_sz);
449988034c3dSAndy Adamson xdr_error:
450088034c3dSAndy Adamson 	dprintk("%s ret=%d!\n", __func__, status);
450188034c3dSAndy Adamson 	return status;
450288034c3dSAndy Adamson }
450388034c3dSAndy Adamson 
450488034c3dSAndy Adamson /*
450588034c3dSAndy Adamson  * Thresholds on pNFS direct I/O vrs MDS I/O
450688034c3dSAndy Adamson  */
450788034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
450888034c3dSAndy Adamson 				    uint32_t *bitmap,
450988034c3dSAndy Adamson 				    struct nfs4_threshold *res)
451088034c3dSAndy Adamson {
451188034c3dSAndy Adamson 	__be32 *p;
451288034c3dSAndy Adamson 	int status = 0;
451388034c3dSAndy Adamson 	uint32_t num;
451488034c3dSAndy Adamson 
451588034c3dSAndy Adamson 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
451688034c3dSAndy Adamson 		return -EIO;
4517029c5347STrond Myklebust 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
45181549210fSTrond Myklebust 		/* Did the server return an unrequested attribute? */
45191549210fSTrond Myklebust 		if (unlikely(res == NULL))
45201549210fSTrond Myklebust 			return -EREMOTEIO;
452188034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 4);
452288034c3dSAndy Adamson 		if (unlikely(!p))
452388034c3dSAndy Adamson 			goto out_overflow;
452488034c3dSAndy Adamson 		num = be32_to_cpup(p);
452588034c3dSAndy Adamson 		if (num == 0)
452688034c3dSAndy Adamson 			return 0;
452788034c3dSAndy Adamson 		if (num > 1)
452888034c3dSAndy Adamson 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
452988034c3dSAndy Adamson 				"drivers per filesystem not supported\n",
453088034c3dSAndy Adamson 				__func__);
453188034c3dSAndy Adamson 
453288034c3dSAndy Adamson 		status = decode_first_threshold_item4(xdr, res);
4533029c5347STrond Myklebust 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
453488034c3dSAndy Adamson 	}
453588034c3dSAndy Adamson 	return status;
453688034c3dSAndy Adamson out_overflow:
453788034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
453888034c3dSAndy Adamson 	return -EIO;
453988034c3dSAndy Adamson }
454088034c3dSAndy Adamson 
4541ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4542ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
4543aa9c2669SDavid Quigley 		struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
45446926afd1STrond Myklebust 		const struct nfs_server *server)
45451da177e4SLinus Torvalds {
4546bca79478STrond Myklebust 	int status;
4547bca79478STrond Myklebust 	umode_t fmode = 0;
4548ae42c70aSBryan Schumaker 	uint32_t type;
4549ee7b75fcSTrond Myklebust 	int32_t err;
45501da177e4SLinus Torvalds 
4551f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4552f26c7a78STrond Myklebust 	if (status < 0)
45531da177e4SLinus Torvalds 		goto xdr_error;
4554409924e4STrond Myklebust 	fattr->mode = 0;
4555409924e4STrond Myklebust 	if (status != 0) {
4556409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4557409924e4STrond Myklebust 		fattr->valid |= status;
4558409924e4STrond Myklebust 	}
45591da177e4SLinus Torvalds 
4560f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4561f26c7a78STrond Myklebust 	if (status < 0)
45621da177e4SLinus Torvalds 		goto xdr_error;
4563409924e4STrond Myklebust 	fattr->valid |= status;
4564f26c7a78STrond Myklebust 
4565f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4566f26c7a78STrond Myklebust 	if (status < 0)
45671da177e4SLinus Torvalds 		goto xdr_error;
4568409924e4STrond Myklebust 	fattr->valid |= status;
4569f26c7a78STrond Myklebust 
4570f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4571f26c7a78STrond Myklebust 	if (status < 0)
45721da177e4SLinus Torvalds 		goto xdr_error;
4573409924e4STrond Myklebust 	fattr->valid |= status;
4574f26c7a78STrond Myklebust 
4575ee7b75fcSTrond Myklebust 	err = 0;
4576ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4577ae42c70aSBryan Schumaker 	if (status < 0)
4578ae42c70aSBryan Schumaker 		goto xdr_error;
4579ae42c70aSBryan Schumaker 
4580ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4581ae42c70aSBryan Schumaker 	if (status < 0)
4582ae42c70aSBryan Schumaker 		goto xdr_error;
4583ae42c70aSBryan Schumaker 
4584f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4585f26c7a78STrond Myklebust 	if (status < 0)
45861da177e4SLinus Torvalds 		goto xdr_error;
4587409924e4STrond Myklebust 	fattr->valid |= status;
4588f26c7a78STrond Myklebust 
45898b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4590f26c7a78STrond Myklebust 	if (status < 0)
4591683b57b4STrond Myklebust 		goto xdr_error;
4592409924e4STrond Myklebust 	fattr->valid |= status;
4593f26c7a78STrond Myklebust 
4594f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4595f26c7a78STrond Myklebust 	if (status < 0)
45961da177e4SLinus Torvalds 		goto xdr_error;
4597409924e4STrond Myklebust 	if (status != 0) {
45981da177e4SLinus Torvalds 		fattr->mode |= fmode;
4599409924e4STrond Myklebust 		fattr->valid |= status;
4600409924e4STrond Myklebust 	}
4601f26c7a78STrond Myklebust 
4602f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4603f26c7a78STrond Myklebust 	if (status < 0)
46041da177e4SLinus Torvalds 		goto xdr_error;
4605409924e4STrond Myklebust 	fattr->valid |= status;
4606f26c7a78STrond Myklebust 
46076926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4608f26c7a78STrond Myklebust 	if (status < 0)
46091da177e4SLinus Torvalds 		goto xdr_error;
4610409924e4STrond Myklebust 	fattr->valid |= status;
4611f26c7a78STrond Myklebust 
46126926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4613f26c7a78STrond Myklebust 	if (status < 0)
46141da177e4SLinus Torvalds 		goto xdr_error;
4615409924e4STrond Myklebust 	fattr->valid |= status;
4616f26c7a78STrond Myklebust 
4617f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4618f26c7a78STrond Myklebust 	if (status < 0)
46191da177e4SLinus Torvalds 		goto xdr_error;
4620409924e4STrond Myklebust 	fattr->valid |= status;
4621f26c7a78STrond Myklebust 
4622f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4623f26c7a78STrond Myklebust 	if (status < 0)
46241da177e4SLinus Torvalds 		goto xdr_error;
4625409924e4STrond Myklebust 	fattr->valid |= status;
4626f26c7a78STrond Myklebust 
4627f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4628f26c7a78STrond Myklebust 	if (status < 0)
46291da177e4SLinus Torvalds 		goto xdr_error;
4630409924e4STrond Myklebust 	fattr->valid |= status;
4631f26c7a78STrond Myklebust 
4632f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4633f26c7a78STrond Myklebust 	if (status < 0)
46341da177e4SLinus Torvalds 		goto xdr_error;
4635409924e4STrond Myklebust 	fattr->valid |= status;
4636f26c7a78STrond Myklebust 
4637f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4638f26c7a78STrond Myklebust 	if (status < 0)
46391da177e4SLinus Torvalds 		goto xdr_error;
4640409924e4STrond Myklebust 	fattr->valid |= status;
4641f26c7a78STrond Myklebust 
464228331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4643f26c7a78STrond Myklebust 	if (status < 0)
464499baf625SManoj Naik 		goto xdr_error;
4645409924e4STrond Myklebust 	fattr->valid |= status;
4646f26c7a78STrond Myklebust 
464788034c3dSAndy Adamson 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
464888034c3dSAndy Adamson 	if (status < 0)
464988034c3dSAndy Adamson 		goto xdr_error;
465088034c3dSAndy Adamson 
4651aa9c2669SDavid Quigley 	if (label) {
4652aa9c2669SDavid Quigley 		status = decode_attr_security_label(xdr, bitmap, label);
4653aa9c2669SDavid Quigley 		if (status < 0)
4654aa9c2669SDavid Quigley 			goto xdr_error;
4655aa9c2669SDavid Quigley 		fattr->valid |= status;
4656aa9c2669SDavid Quigley 	}
4657aa9c2669SDavid Quigley 
4658ae42c70aSBryan Schumaker xdr_error:
4659ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4660ae42c70aSBryan Schumaker 	return status;
4661ae42c70aSBryan Schumaker }
4662ae42c70aSBryan Schumaker 
4663ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
46648b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4665aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4666ae42c70aSBryan Schumaker {
4667256e48bbSTrond Myklebust 	unsigned int savep;
4668ae42c70aSBryan Schumaker 	uint32_t attrlen,
4669dae100c2SFred Isaman 		 bitmap[3] = {0};
4670ae42c70aSBryan Schumaker 	int status;
4671ae42c70aSBryan Schumaker 
4672ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4673ae42c70aSBryan Schumaker 	if (status < 0)
4674ae42c70aSBryan Schumaker 		goto xdr_error;
4675ae42c70aSBryan Schumaker 
4676ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4677ae42c70aSBryan Schumaker 	if (status < 0)
4678ae42c70aSBryan Schumaker 		goto xdr_error;
4679ae42c70aSBryan Schumaker 
4680ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4681ae42c70aSBryan Schumaker 	if (status < 0)
4682ae42c70aSBryan Schumaker 		goto xdr_error;
4683ae42c70aSBryan Schumaker 
4684aa9c2669SDavid Quigley 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4685aa9c2669SDavid Quigley 					label, server);
4686ae42c70aSBryan Schumaker 	if (status < 0)
4687ae42c70aSBryan Schumaker 		goto xdr_error;
4688ae42c70aSBryan Schumaker 
4689f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
46901da177e4SLinus Torvalds xdr_error:
46913110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
46921da177e4SLinus Torvalds 	return status;
46931da177e4SLinus Torvalds }
46941da177e4SLinus Torvalds 
4695aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4696aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4697aa9c2669SDavid Quigley {
4698aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4699aa9c2669SDavid Quigley }
4700aa9c2669SDavid Quigley 
4701ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47026926afd1STrond Myklebust 		const struct nfs_server *server)
4703ae42c70aSBryan Schumaker {
4704aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4705ae42c70aSBryan Schumaker }
47061da177e4SLinus Torvalds 
4707504913fbSAndy Adamson /*
4708504913fbSAndy Adamson  * Decode potentially multiple layout types. Currently we only support
4709504913fbSAndy Adamson  * one layout driver per file system.
4710504913fbSAndy Adamson  */
4711504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4712504913fbSAndy Adamson 					 uint32_t *layouttype)
4713504913fbSAndy Adamson {
4714b8a8a0ddSTrond Myklebust 	__be32 *p;
4715504913fbSAndy Adamson 	int num;
4716504913fbSAndy Adamson 
4717504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4718504913fbSAndy Adamson 	if (unlikely(!p))
4719504913fbSAndy Adamson 		goto out_overflow;
4720504913fbSAndy Adamson 	num = be32_to_cpup(p);
4721504913fbSAndy Adamson 
4722504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4723504913fbSAndy Adamson 	if (num == 0) {
4724504913fbSAndy Adamson 		*layouttype = 0;
4725504913fbSAndy Adamson 		return 0;
4726504913fbSAndy Adamson 	}
4727504913fbSAndy Adamson 	if (num > 1)
4728a030889aSWeston Andros Adamson 		printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4729a030889aSWeston Andros Adamson 			"drivers per filesystem not supported\n", __func__);
4730504913fbSAndy Adamson 
4731504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4732504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, num * 4);
4733504913fbSAndy Adamson 	if (unlikely(!p))
4734504913fbSAndy Adamson 		goto out_overflow;
4735504913fbSAndy Adamson 	*layouttype = be32_to_cpup(p);
4736504913fbSAndy Adamson 	return 0;
4737504913fbSAndy Adamson out_overflow:
4738504913fbSAndy Adamson 	print_overflow_msg(__func__, xdr);
4739504913fbSAndy Adamson 	return -EIO;
4740504913fbSAndy Adamson }
4741504913fbSAndy Adamson 
4742504913fbSAndy Adamson /*
4743504913fbSAndy Adamson  * The type of file system exported.
4744504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4745504913fbSAndy Adamson  */
4746504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4747504913fbSAndy Adamson 				uint32_t *layouttype)
4748504913fbSAndy Adamson {
4749504913fbSAndy Adamson 	int status = 0;
4750504913fbSAndy Adamson 
4751504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4752504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4753504913fbSAndy Adamson 		return -EIO;
4754504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4755504913fbSAndy Adamson 		status = decode_first_pnfs_layout_type(xdr, layouttype);
4756504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4757504913fbSAndy Adamson 	} else
4758504913fbSAndy Adamson 		*layouttype = 0;
4759504913fbSAndy Adamson 	return status;
4760504913fbSAndy Adamson }
4761504913fbSAndy Adamson 
4762dae100c2SFred Isaman /*
4763dae100c2SFred Isaman  * The prefered block size for layout directed io
4764dae100c2SFred Isaman  */
4765dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4766dae100c2SFred Isaman 				      uint32_t *res)
4767dae100c2SFred Isaman {
4768dae100c2SFred Isaman 	__be32 *p;
4769dae100c2SFred Isaman 
4770dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4771dae100c2SFred Isaman 	*res = 0;
4772dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4773dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4774dae100c2SFred Isaman 		if (unlikely(!p)) {
4775dae100c2SFred Isaman 			print_overflow_msg(__func__, xdr);
4776dae100c2SFred Isaman 			return -EIO;
4777dae100c2SFred Isaman 		}
4778dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4779dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4780dae100c2SFred Isaman 	}
4781dae100c2SFred Isaman 	return 0;
4782dae100c2SFred Isaman }
4783dae100c2SFred Isaman 
47841da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
47851da177e4SLinus Torvalds {
4786256e48bbSTrond Myklebust 	unsigned int savep;
4787dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
47881da177e4SLinus Torvalds 	int status;
47891da177e4SLinus Torvalds 
47901da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
47911da177e4SLinus Torvalds 		goto xdr_error;
47921da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
47931da177e4SLinus Torvalds 		goto xdr_error;
47941da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
47951da177e4SLinus Torvalds 		goto xdr_error;
47961da177e4SLinus Torvalds 
47971da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
47981da177e4SLinus Torvalds 
47991da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
48001da177e4SLinus Torvalds 		goto xdr_error;
48011da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
48021da177e4SLinus Torvalds 		goto xdr_error;
48031da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
48041da177e4SLinus Torvalds 		goto xdr_error;
48051da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
48061da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
48071da177e4SLinus Torvalds 		goto xdr_error;
48081da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
480955b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
481055b6e774SRicardo Labiaga 	if (status != 0)
481155b6e774SRicardo Labiaga 		goto xdr_error;
4812504913fbSAndy Adamson 	status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4813504913fbSAndy Adamson 	if (status != 0)
4814504913fbSAndy Adamson 		goto xdr_error;
4815dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4816dae100c2SFred Isaman 	if (status)
4817dae100c2SFred Isaman 		goto xdr_error;
48181da177e4SLinus Torvalds 
48191da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
48201da177e4SLinus Torvalds xdr_error:
48213110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
48221da177e4SLinus Torvalds 	return status;
48231da177e4SLinus Torvalds }
48241da177e4SLinus Torvalds 
48251da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
48261da177e4SLinus Torvalds {
48278687b63aSAl Viro 	__be32 *p;
48281da177e4SLinus Torvalds 	uint32_t len;
48291da177e4SLinus Torvalds 	int status;
48301da177e4SLinus Torvalds 
48319936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
48329936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
48339936781dSTrond Myklebust 
48341da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
48351da177e4SLinus Torvalds 	if (status)
48361da177e4SLinus Torvalds 		return status;
48371da177e4SLinus Torvalds 
4838c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4839c0eae66eSBenny Halevy 	if (unlikely(!p))
4840c0eae66eSBenny Halevy 		goto out_overflow;
4841cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
48421da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
48431da177e4SLinus Torvalds 		return -EIO;
48441da177e4SLinus Torvalds 	fh->size = len;
4845c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4846c0eae66eSBenny Halevy 	if (unlikely(!p))
4847c0eae66eSBenny Halevy 		goto out_overflow;
484899398d06SBenny Halevy 	memcpy(fh->data, p, len);
48491da177e4SLinus Torvalds 	return 0;
4850c0eae66eSBenny Halevy out_overflow:
4851c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4852c0eae66eSBenny Halevy 	return -EIO;
48531da177e4SLinus Torvalds }
48541da177e4SLinus Torvalds 
48551da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
48561da177e4SLinus Torvalds {
48571da177e4SLinus Torvalds 	int status;
48581da177e4SLinus Torvalds 
48591da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
48601da177e4SLinus Torvalds 	if (status)
48611da177e4SLinus Torvalds 		return status;
48621da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
48631da177e4SLinus Torvalds }
48641da177e4SLinus Torvalds 
48651da177e4SLinus Torvalds /*
48661da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
48671da177e4SLinus Torvalds  */
4868911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
48691da177e4SLinus Torvalds {
4870911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
48718687b63aSAl Viro 	__be32 *p;
4872911d1aafSTrond Myklebust 	uint32_t namelen, type;
48731da177e4SLinus Torvalds 
4874babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4875c0eae66eSBenny Halevy 	if (unlikely(!p))
4876c0eae66eSBenny Halevy 		goto out_overflow;
4877babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
48783ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4879babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4880babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4881911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4882911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4883911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4884911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4885911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4886911d1aafSTrond Myklebust 		if (type & 1)
4887911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4888911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4889911d1aafSTrond Myklebust 	}
4890babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4891babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4892babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4893c0eae66eSBenny Halevy 	if (likely(p))
48941da177e4SLinus Torvalds 		return -NFS4ERR_DENIED;
4895c0eae66eSBenny Halevy out_overflow:
4896c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4897c0eae66eSBenny Halevy 	return -EIO;
48981da177e4SLinus Torvalds }
48991da177e4SLinus Torvalds 
4900911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
49011da177e4SLinus Torvalds {
49021da177e4SLinus Torvalds 	int status;
49031da177e4SLinus Torvalds 
49041da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4905c1d51931STrond Myklebust 	if (status == -EIO)
4906c1d51931STrond Myklebust 		goto out;
49071da177e4SLinus Torvalds 	if (status == 0) {
490807d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
490907d30434SBenny Halevy 		if (unlikely(status))
491007d30434SBenny Halevy 			goto out;
49111da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4912c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4913c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4914c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4915c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4916c1d51931STrond Myklebust out:
49171da177e4SLinus Torvalds 	return status;
49181da177e4SLinus Torvalds }
49191da177e4SLinus Torvalds 
4920911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
49211da177e4SLinus Torvalds {
49221da177e4SLinus Torvalds 	int status;
49231da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
49241da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4925911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
49261da177e4SLinus Torvalds 	return status;
49271da177e4SLinus Torvalds }
49281da177e4SLinus Torvalds 
4929911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
49301da177e4SLinus Torvalds {
49311da177e4SLinus Torvalds 	int status;
49321da177e4SLinus Torvalds 
49331da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4934c1d51931STrond Myklebust 	if (status != -EIO)
4935c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
493607d30434SBenny Halevy 	if (status == 0)
493707d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
49381da177e4SLinus Torvalds 	return status;
49391da177e4SLinus Torvalds }
49401da177e4SLinus Torvalds 
4941d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
4942d3c7b7ccSTrond Myklebust {
4943d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4944d3c7b7ccSTrond Myklebust }
4945d3c7b7ccSTrond Myklebust 
49461da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
49471da177e4SLinus Torvalds {
49481da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
49491da177e4SLinus Torvalds }
49501da177e4SLinus Torvalds 
49511da177e4SLinus Torvalds /* This is too sick! */
49521da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
49531da177e4SLinus Torvalds {
49548687b63aSAl Viro 	__be32 *p;
49551da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
49561da177e4SLinus Torvalds 
4957c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4958c0eae66eSBenny Halevy 	if (unlikely(!p))
4959c0eae66eSBenny Halevy 		goto out_overflow;
49606f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
49611da177e4SLinus Torvalds 	switch (limit_type) {
49621da177e4SLinus Torvalds 	case 1:
4963cccddf4fSBenny Halevy 		xdr_decode_hyper(p, maxsize);
49641da177e4SLinus Torvalds 		break;
49651da177e4SLinus Torvalds 	case 2:
49666f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
4967cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
49681da177e4SLinus Torvalds 		*maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
49691da177e4SLinus Torvalds 	}
49701da177e4SLinus Torvalds 	return 0;
4971c0eae66eSBenny Halevy out_overflow:
4972c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4973c0eae66eSBenny Halevy 	return -EIO;
49741da177e4SLinus Torvalds }
49751da177e4SLinus Torvalds 
49761da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
49771da177e4SLinus Torvalds {
49788687b63aSAl Viro 	__be32 *p;
49791da177e4SLinus Torvalds 	uint32_t delegation_type;
498007d30434SBenny Halevy 	int status;
49811da177e4SLinus Torvalds 
4982c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4983c0eae66eSBenny Halevy 	if (unlikely(!p))
4984c0eae66eSBenny Halevy 		goto out_overflow;
4985cccddf4fSBenny Halevy 	delegation_type = be32_to_cpup(p);
49861da177e4SLinus Torvalds 	if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
49871da177e4SLinus Torvalds 		res->delegation_type = 0;
49881da177e4SLinus Torvalds 		return 0;
49891da177e4SLinus Torvalds 	}
499007d30434SBenny Halevy 	status = decode_stateid(xdr, &res->delegation);
499107d30434SBenny Halevy 	if (unlikely(status))
499207d30434SBenny Halevy 		return status;
4993c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4994c0eae66eSBenny Halevy 	if (unlikely(!p))
4995c0eae66eSBenny Halevy 		goto out_overflow;
4996cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
499705d564feSAndy Adamson 
49981da177e4SLinus Torvalds 	switch (delegation_type) {
49991da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
50001da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
50011da177e4SLinus Torvalds 		break;
50021da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
50031da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
50041da177e4SLinus Torvalds 		if (decode_space_limit(xdr, &res->maxsize) < 0)
50051da177e4SLinus Torvalds 				return -EIO;
50061da177e4SLinus Torvalds 	}
50077539bbabSDavid Howells 	return decode_ace(xdr, NULL, res->server->nfs_client);
5008c0eae66eSBenny Halevy out_overflow:
5009c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5010c0eae66eSBenny Halevy 	return -EIO;
50111da177e4SLinus Torvalds }
50121da177e4SLinus Torvalds 
50131da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
50141da177e4SLinus Torvalds {
50158687b63aSAl Viro 	__be32 *p;
5016aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
50171da177e4SLinus Torvalds 	int status;
50181da177e4SLinus Torvalds 
5019c7848f69STrond Myklebust 	if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5020c7848f69STrond Myklebust 		return status;
5021c1d51931STrond Myklebust 	nfs_increment_open_seqid(status, res->seqid);
5022c7848f69STrond Myklebust 	if (status)
5023c7848f69STrond Myklebust 		return status;
502407d30434SBenny Halevy 	status = decode_stateid(xdr, &res->stateid);
502507d30434SBenny Halevy 	if (unlikely(status))
50261da177e4SLinus Torvalds 		return status;
50271da177e4SLinus Torvalds 
50281da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
50291da177e4SLinus Torvalds 
5030c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5031c0eae66eSBenny Halevy 	if (unlikely(!p))
5032c0eae66eSBenny Halevy 		goto out_overflow;
50336f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
5034cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
50351da177e4SLinus Torvalds 	if (bmlen > 10)
50361da177e4SLinus Torvalds 		goto xdr_error;
50371da177e4SLinus Torvalds 
5038c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5039c0eae66eSBenny Halevy 	if (unlikely(!p))
5040c0eae66eSBenny Halevy 		goto out_overflow;
5041aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5042aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
50436f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
5044aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
5045aa53ed54SJeff Layton 		res->attrset[i] = 0;
5046aa53ed54SJeff Layton 
50471da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
50481da177e4SLinus Torvalds xdr_error:
50493110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
50501da177e4SLinus Torvalds 	return -EIO;
5051c0eae66eSBenny Halevy out_overflow:
5052c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5053c0eae66eSBenny Halevy 	return -EIO;
50541da177e4SLinus Torvalds }
50551da177e4SLinus Torvalds 
50561da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
50571da177e4SLinus Torvalds {
50581da177e4SLinus Torvalds 	int status;
50591da177e4SLinus Torvalds 
50601da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5061c1d51931STrond Myklebust 	if (status != -EIO)
5062c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
506307d30434SBenny Halevy 	if (!status)
506407d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
50651da177e4SLinus Torvalds 	return status;
50661da177e4SLinus Torvalds }
50671da177e4SLinus Torvalds 
50681da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
50691da177e4SLinus Torvalds {
50701da177e4SLinus Torvalds 	int status;
50711da177e4SLinus Torvalds 
50721da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5073c1d51931STrond Myklebust 	if (status != -EIO)
5074c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
507507d30434SBenny Halevy 	if (!status)
507607d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
50771da177e4SLinus Torvalds 	return status;
50781da177e4SLinus Torvalds }
50791da177e4SLinus Torvalds 
50801da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
50811da177e4SLinus Torvalds {
50821da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
50831da177e4SLinus Torvalds }
50841da177e4SLinus Torvalds 
50851da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
50861da177e4SLinus Torvalds {
50871da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
50881da177e4SLinus Torvalds }
50891da177e4SLinus Torvalds 
50909137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
50919137bdf3SAnna Schumaker 		       struct nfs_pgio_res *res)
50921da177e4SLinus Torvalds {
50938687b63aSAl Viro 	__be32 *p;
509464bd577eSTrond Myklebust 	uint32_t count, eof, recvd;
50951da177e4SLinus Torvalds 	int status;
50961da177e4SLinus Torvalds 
50971da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
50981da177e4SLinus Torvalds 	if (status)
50991da177e4SLinus Torvalds 		return status;
5100c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5101c0eae66eSBenny Halevy 	if (unlikely(!p))
5102c0eae66eSBenny Halevy 		goto out_overflow;
51036f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
5104cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
510564bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, count);
51061da177e4SLinus Torvalds 	if (count > recvd) {
5107fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
51081da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
51091da177e4SLinus Torvalds 		count = recvd;
51101da177e4SLinus Torvalds 		eof = 0;
51111da177e4SLinus Torvalds 	}
51121da177e4SLinus Torvalds 	res->eof = eof;
51131da177e4SLinus Torvalds 	res->count = count;
51141da177e4SLinus Torvalds 	return 0;
5115c0eae66eSBenny Halevy out_overflow:
5116c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5117c0eae66eSBenny Halevy 	return -EIO;
51181da177e4SLinus Torvalds }
51191da177e4SLinus Torvalds 
51201da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
51211da177e4SLinus Torvalds {
5122bcecff77SChuck Lever 	int		status;
5123cd93710eSChuck Lever 	__be32		verf[2];
51241da177e4SLinus Torvalds 
51251da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
5126db942bbdSBenny Halevy 	if (!status)
5127db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
5128db942bbdSBenny Halevy 	if (unlikely(status))
51291da177e4SLinus Torvalds 		return status;
5130cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
513144109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
5132cd93710eSChuck Lever 			__func__, verf[0], verf[1]);
513364bd577eSTrond Myklebust 	return xdr_read_pages(xdr, xdr->buf->page_len);
51341da177e4SLinus Torvalds }
51351da177e4SLinus Torvalds 
51361da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
51371da177e4SLinus Torvalds {
51381da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5139bcecff77SChuck Lever 	u32 len, recvd;
51408687b63aSAl Viro 	__be32 *p;
51411da177e4SLinus Torvalds 	int status;
51421da177e4SLinus Torvalds 
51431da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
51441da177e4SLinus Torvalds 	if (status)
51451da177e4SLinus Torvalds 		return status;
51461da177e4SLinus Torvalds 
51471da177e4SLinus Torvalds 	/* Convert length of symlink */
5148c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5149c0eae66eSBenny Halevy 	if (unlikely(!p))
5150c0eae66eSBenny Halevy 		goto out_overflow;
5151cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
51521da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
5153fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
51541da177e4SLinus Torvalds 		return -ENAMETOOLONG;
51551da177e4SLinus Torvalds 	}
515664bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, len);
51571da177e4SLinus Torvalds 	if (recvd < len) {
5158fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
51591da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
51601da177e4SLinus Torvalds 		return -EIO;
51611da177e4SLinus Torvalds 	}
51621da177e4SLinus Torvalds 	/*
51631da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
51641da177e4SLinus Torvalds 	 * the link text will be copied directly into the
51651da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
51661da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
51671da177e4SLinus Torvalds 	 * null-termination).
51681da177e4SLinus Torvalds 	 */
5169b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
51701da177e4SLinus Torvalds 	return 0;
5171c0eae66eSBenny Halevy out_overflow:
5172c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5173c0eae66eSBenny Halevy 	return -EIO;
51741da177e4SLinus Torvalds }
51751da177e4SLinus Torvalds 
51761da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
51771da177e4SLinus Torvalds {
51781da177e4SLinus Torvalds 	int status;
51791da177e4SLinus Torvalds 
51801da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
51811da177e4SLinus Torvalds 	if (status)
51821da177e4SLinus Torvalds 		goto out;
51831da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
51841da177e4SLinus Torvalds out:
51851da177e4SLinus Torvalds 	return status;
51861da177e4SLinus Torvalds }
51871da177e4SLinus Torvalds 
51881da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
51891da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
51901da177e4SLinus Torvalds {
51911da177e4SLinus Torvalds 	int status;
51921da177e4SLinus Torvalds 
51931da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
51941da177e4SLinus Torvalds 	if (status)
51951da177e4SLinus Torvalds 		goto out;
51961da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
51971da177e4SLinus Torvalds 		goto out;
51981da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
51991da177e4SLinus Torvalds out:
52001da177e4SLinus Torvalds 	return status;
52011da177e4SLinus Torvalds }
52021da177e4SLinus Torvalds 
52031da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
52041da177e4SLinus Torvalds {
52051da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
52061da177e4SLinus Torvalds }
52071da177e4SLinus Torvalds 
520856ae19f3STrond Myklebust static int
520956ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
521056ae19f3STrond Myklebust {
521156ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
521256ae19f3STrond Myklebust }
521356ae19f3STrond Myklebust 
5214029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5215bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5216029d105eSJ. Bruce Fields {
5217256e48bbSTrond Myklebust 	unsigned int savep;
5218029d105eSJ. Bruce Fields 	uint32_t attrlen,
5219dae100c2SFred Isaman 		 bitmap[3] = {0};
5220029d105eSJ. Bruce Fields 	int status;
5221cff298c7STrond Myklebust 	unsigned int pg_offset;
5222029d105eSJ. Bruce Fields 
5223bf118a34SAndy Adamson 	res->acl_len = 0;
5224029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5225029d105eSJ. Bruce Fields 		goto out;
52265a006899SSachin Prabhu 
5227519d3959STrond Myklebust 	xdr_enter_page(xdr, xdr->buf->page_len);
5228519d3959STrond Myklebust 
5229cff298c7STrond Myklebust 	/* Calculate the offset of the page data */
5230cff298c7STrond Myklebust 	pg_offset = xdr->buf->head[0].iov_len;
52315a006899SSachin Prabhu 
5232029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5233029d105eSJ. Bruce Fields 		goto out;
5234029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5235029d105eSJ. Bruce Fields 		goto out;
5236029d105eSJ. Bruce Fields 
5237029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5238029d105eSJ. Bruce Fields 		return -EIO;
5239029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5240029d105eSJ. Bruce Fields 
5241bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5242bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5243bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5244cff298c7STrond Myklebust 		res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5245519d3959STrond Myklebust 		res->acl_len = attrlen;
52461f1ea6c2STrond Myklebust 
52471f1ea6c2STrond Myklebust 		/* Check for receive buffer overflow */
52481f1ea6c2STrond Myklebust 		if (res->acl_len > (xdr->nwords << 2) ||
52491f1ea6c2STrond Myklebust 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
52501f1ea6c2STrond Myklebust 			res->acl_flags |= NFS4_ACL_TRUNC;
5251519d3959STrond Myklebust 			dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5252cff298c7STrond Myklebust 					attrlen, xdr->nwords << 2);
5253029d105eSJ. Bruce Fields 		}
52548c233cf9SJ. Bruce Fields 	} else
52558c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5256029d105eSJ. Bruce Fields 
5257029d105eSJ. Bruce Fields out:
5258029d105eSJ. Bruce Fields 	return status;
5259029d105eSJ. Bruce Fields }
5260029d105eSJ. Bruce Fields 
52611da177e4SLinus Torvalds static int
52621da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
52631da177e4SLinus Torvalds {
52641da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
52651da177e4SLinus Torvalds }
52661da177e4SLinus Torvalds 
52679e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
52681da177e4SLinus Torvalds {
52698687b63aSAl Viro 	__be32 *p;
52701da177e4SLinus Torvalds 	uint32_t bmlen;
52711da177e4SLinus Torvalds 	int status;
52721da177e4SLinus Torvalds 
52731da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
52741da177e4SLinus Torvalds 	if (status)
52751da177e4SLinus Torvalds 		return status;
5276c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5277c0eae66eSBenny Halevy 	if (unlikely(!p))
5278c0eae66eSBenny Halevy 		goto out_overflow;
5279cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
5280c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5281c0eae66eSBenny Halevy 	if (likely(p))
52821da177e4SLinus Torvalds 		return 0;
5283c0eae66eSBenny Halevy out_overflow:
5284c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5285c0eae66eSBenny Halevy 	return -EIO;
52861da177e4SLinus Torvalds }
52871da177e4SLinus Torvalds 
5288bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
52891da177e4SLinus Torvalds {
52908687b63aSAl Viro 	__be32 *p;
52911da177e4SLinus Torvalds 	uint32_t opnum;
52921da177e4SLinus Torvalds 	int32_t nfserr;
52931da177e4SLinus Torvalds 
5294c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5295c0eae66eSBenny Halevy 	if (unlikely(!p))
5296c0eae66eSBenny Halevy 		goto out_overflow;
52976f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
52981da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5299fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
53001da177e4SLinus Torvalds 			" %d\n", opnum);
53011da177e4SLinus Torvalds 		return -EIO;
53021da177e4SLinus Torvalds 	}
5303cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
53041da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5305c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5306c0eae66eSBenny Halevy 		if (unlikely(!p))
5307c0eae66eSBenny Halevy 			goto out_overflow;
5308bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5309bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
53101da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
53111da177e4SLinus Torvalds 		uint32_t len;
53121da177e4SLinus Torvalds 
53131da177e4SLinus Torvalds 		/* skip netid string */
5314c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5315c0eae66eSBenny Halevy 		if (unlikely(!p))
5316c0eae66eSBenny Halevy 			goto out_overflow;
5317cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5318c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5319c0eae66eSBenny Halevy 		if (unlikely(!p))
5320c0eae66eSBenny Halevy 			goto out_overflow;
53211da177e4SLinus Torvalds 
53221da177e4SLinus Torvalds 		/* skip uaddr string */
5323c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5324c0eae66eSBenny Halevy 		if (unlikely(!p))
5325c0eae66eSBenny Halevy 			goto out_overflow;
5326cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5327c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5328c0eae66eSBenny Halevy 		if (unlikely(!p))
5329c0eae66eSBenny Halevy 			goto out_overflow;
53301da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
53311da177e4SLinus Torvalds 	} else
5332856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
53331da177e4SLinus Torvalds 
53341da177e4SLinus Torvalds 	return 0;
5335c0eae66eSBenny Halevy out_overflow:
5336c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5337c0eae66eSBenny Halevy 	return -EIO;
53381da177e4SLinus Torvalds }
53391da177e4SLinus Torvalds 
53401da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
53411da177e4SLinus Torvalds {
53421da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
53431da177e4SLinus Torvalds }
53441da177e4SLinus Torvalds 
53459137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
53461da177e4SLinus Torvalds {
53478687b63aSAl Viro 	__be32 *p;
53481da177e4SLinus Torvalds 	int status;
53491da177e4SLinus Torvalds 
53501da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
53511da177e4SLinus Torvalds 	if (status)
53521da177e4SLinus Torvalds 		return status;
53531da177e4SLinus Torvalds 
53542f2c63bcSTrond Myklebust 	p = xdr_inline_decode(xdr, 8);
5355c0eae66eSBenny Halevy 	if (unlikely(!p))
5356c0eae66eSBenny Halevy 		goto out_overflow;
53576f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
53586f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
53592f2c63bcSTrond Myklebust 	return decode_write_verifier(xdr, &res->verf->verifier);
5360c0eae66eSBenny Halevy out_overflow:
5361c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5362c0eae66eSBenny Halevy 	return -EIO;
53631da177e4SLinus Torvalds }
53641da177e4SLinus Torvalds 
53651da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
53661da177e4SLinus Torvalds {
53671da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
53681da177e4SLinus Torvalds }
53691da177e4SLinus Torvalds 
5370fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr,
5371fb15b26fSChuck Lever 			      struct nfs4_secinfo4 *flavor)
53725a5ea0d4SBryan Schumaker {
5373fb15b26fSChuck Lever 	u32 oid_len;
53745a5ea0d4SBryan Schumaker 	__be32 *p;
53755a5ea0d4SBryan Schumaker 
53765a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
53775a5ea0d4SBryan Schumaker 	if (unlikely(!p))
53785a5ea0d4SBryan Schumaker 		goto out_overflow;
5379fb15b26fSChuck Lever 	oid_len = be32_to_cpup(p);
5380fb15b26fSChuck Lever 	if (oid_len > GSS_OID_MAX_LEN)
53815a5ea0d4SBryan Schumaker 		goto out_err;
53825a5ea0d4SBryan Schumaker 
5383fb15b26fSChuck Lever 	p = xdr_inline_decode(xdr, oid_len);
53845a5ea0d4SBryan Schumaker 	if (unlikely(!p))
53855a5ea0d4SBryan Schumaker 		goto out_overflow;
5386fb15b26fSChuck Lever 	memcpy(flavor->flavor_info.oid.data, p, oid_len);
5387fb15b26fSChuck Lever 	flavor->flavor_info.oid.len = oid_len;
53885a5ea0d4SBryan Schumaker 
53895a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
53905a5ea0d4SBryan Schumaker 	if (unlikely(!p))
53915a5ea0d4SBryan Schumaker 		goto out_overflow;
5392fb15b26fSChuck Lever 	flavor->flavor_info.qop = be32_to_cpup(p++);
5393fb15b26fSChuck Lever 	flavor->flavor_info.service = be32_to_cpup(p);
53945a5ea0d4SBryan Schumaker 
53955a5ea0d4SBryan Schumaker 	return 0;
53965a5ea0d4SBryan Schumaker 
53975a5ea0d4SBryan Schumaker out_overflow:
53985a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
53995a5ea0d4SBryan Schumaker 	return -EIO;
54005a5ea0d4SBryan Schumaker out_err:
54015a5ea0d4SBryan Schumaker 	return -EINVAL;
54025a5ea0d4SBryan Schumaker }
54035a5ea0d4SBryan Schumaker 
540431e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
54055a5ea0d4SBryan Schumaker {
5406fb15b26fSChuck Lever 	struct nfs4_secinfo4 *sec_flavor;
5407fb15b26fSChuck Lever 	unsigned int i, num_flavors;
54085a5ea0d4SBryan Schumaker 	int status;
54095a5ea0d4SBryan Schumaker 	__be32 *p;
54105a5ea0d4SBryan Schumaker 
54115a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
54125a5ea0d4SBryan Schumaker 	if (unlikely(!p))
54135a5ea0d4SBryan Schumaker 		goto out_overflow;
54145a5ea0d4SBryan Schumaker 
5415c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5416c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5417c3dfc280SBryan Schumaker 
5418c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
54195a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5420c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
54215a5ea0d4SBryan Schumaker 			break;
54225a5ea0d4SBryan Schumaker 
54235a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
54245a5ea0d4SBryan Schumaker 		if (unlikely(!p))
54255a5ea0d4SBryan Schumaker 			goto out_overflow;
54265a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
54275a5ea0d4SBryan Schumaker 
54285a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5429613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5430613e901eSBryan Schumaker 			if (status)
5431613e901eSBryan Schumaker 				goto out;
54325a5ea0d4SBryan Schumaker 		}
5433c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
54345a5ea0d4SBryan Schumaker 	}
54355a5ea0d4SBryan Schumaker 
543631e4dda4SBryan Schumaker 	status = 0;
5437613e901eSBryan Schumaker out:
5438613e901eSBryan Schumaker 	return status;
54395a5ea0d4SBryan Schumaker out_overflow:
54405a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
54415a5ea0d4SBryan Schumaker 	return -EIO;
54425a5ea0d4SBryan Schumaker }
54435a5ea0d4SBryan Schumaker 
544431e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
544531e4dda4SBryan Schumaker {
544631e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO);
544731e4dda4SBryan Schumaker 	if (status)
544831e4dda4SBryan Schumaker 		return status;
544931e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
545031e4dda4SBryan Schumaker }
545131e4dda4SBryan Schumaker 
545299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
545331e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
545431e4dda4SBryan Schumaker {
545531e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
545631e4dda4SBryan Schumaker 	if (status)
545731e4dda4SBryan Schumaker 		return status;
545831e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
545931e4dda4SBryan Schumaker }
546031e4dda4SBryan Schumaker 
54612031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
54622031cd1aSWeston Andros Adamson {
54632031cd1aSWeston Andros Adamson 	__be32 *p;
54642031cd1aSWeston Andros Adamson 	uint32_t bitmap_words;
54652031cd1aSWeston Andros Adamson 	unsigned int i;
54662031cd1aSWeston Andros Adamson 
54672031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
54682031cd1aSWeston Andros Adamson 	bitmap_words = be32_to_cpup(p++);
54692031cd1aSWeston Andros Adamson 	if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
54702031cd1aSWeston Andros Adamson 		return -EIO;
54712031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4 * bitmap_words);
54722031cd1aSWeston Andros Adamson 	for (i = 0; i < bitmap_words; i++)
54732031cd1aSWeston Andros Adamson 		op_map->u.words[i] = be32_to_cpup(p++);
54742031cd1aSWeston Andros Adamson 
54752031cd1aSWeston Andros Adamson 	return 0;
54762031cd1aSWeston Andros Adamson }
54772031cd1aSWeston Andros Adamson 
547899fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
547999fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
548099fe60d0SBenny Halevy {
548199fe60d0SBenny Halevy 	__be32 *p;
548299fe60d0SBenny Halevy 	uint32_t dummy;
54832460ba57SBenny Halevy 	char *dummy_str;
548499fe60d0SBenny Halevy 	int status;
54857d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
548699fe60d0SBenny Halevy 
548799fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
548899fe60d0SBenny Halevy 	if (status)
548999fe60d0SBenny Halevy 		return status;
549099fe60d0SBenny Halevy 
5491c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5492c0eae66eSBenny Halevy 	if (unlikely(!p))
5493c0eae66eSBenny Halevy 		goto out_overflow;
549432b01310STrond Myklebust 	xdr_decode_hyper(p, &res->clientid);
5495c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5496c0eae66eSBenny Halevy 	if (unlikely(!p))
5497c0eae66eSBenny Halevy 		goto out_overflow;
549832b01310STrond Myklebust 	res->seqid = be32_to_cpup(p++);
549932b01310STrond Myklebust 	res->flags = be32_to_cpup(p++);
550099fe60d0SBenny Halevy 
55012031cd1aSWeston Andros Adamson 	res->state_protect.how = be32_to_cpup(p);
55022031cd1aSWeston Andros Adamson 	switch (res->state_protect.how) {
55032031cd1aSWeston Andros Adamson 	case SP4_NONE:
55042031cd1aSWeston Andros Adamson 		break;
55052031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
55062031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.enforce);
55072031cd1aSWeston Andros Adamson 		if (status)
55082031cd1aSWeston Andros Adamson 			return status;
55092031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.allow);
55102031cd1aSWeston Andros Adamson 		if (status)
55112031cd1aSWeston Andros Adamson 			return status;
55122031cd1aSWeston Andros Adamson 		break;
55132031cd1aSWeston Andros Adamson 	default:
55142031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
551599fe60d0SBenny Halevy 		return -EIO;
55162031cd1aSWeston Andros Adamson 	}
551799fe60d0SBenny Halevy 
5518acdeb69dSChuck Lever 	/* server_owner4.so_minor_id */
5519c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5520c0eae66eSBenny Halevy 	if (unlikely(!p))
5521c0eae66eSBenny Halevy 		goto out_overflow;
5522acdeb69dSChuck Lever 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
552399fe60d0SBenny Halevy 
5524acdeb69dSChuck Lever 	/* server_owner4.so_major_id */
55252460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55262460ba57SBenny Halevy 	if (unlikely(status))
55272460ba57SBenny Halevy 		return status;
552878fe0f41SWeston Andros Adamson 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
552978fe0f41SWeston Andros Adamson 		return -EIO;
5530acdeb69dSChuck Lever 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5531acdeb69dSChuck Lever 	res->server_owner->major_id_sz = dummy;
553278fe0f41SWeston Andros Adamson 
5533acdeb69dSChuck Lever 	/* server_scope4 */
5534acdeb69dSChuck Lever 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5535acdeb69dSChuck Lever 	if (unlikely(status))
5536acdeb69dSChuck Lever 		return status;
5537acdeb69dSChuck Lever 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5538acdeb69dSChuck Lever 		return -EIO;
553978fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
554078fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
554178fe0f41SWeston Andros Adamson 
55427d2ed9acSWeston Andros Adamson 	/* Implementation Id */
55437d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
55447d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
55457d2ed9acSWeston Andros Adamson 		goto out_overflow;
55467d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
55477d2ed9acSWeston Andros Adamson 
55487d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
55497d2ed9acSWeston Andros Adamson 		/* nii_domain */
55502460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55512460ba57SBenny Halevy 		if (unlikely(status))
55522460ba57SBenny Halevy 			return status;
55537d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
55547d2ed9acSWeston Andros Adamson 			return -EIO;
55557d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
555699fe60d0SBenny Halevy 
55577d2ed9acSWeston Andros Adamson 		/* nii_name */
55587d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55597d2ed9acSWeston Andros Adamson 		if (unlikely(status))
55607d2ed9acSWeston Andros Adamson 			return status;
55617d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
55627d2ed9acSWeston Andros Adamson 			return -EIO;
55637d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
55647d2ed9acSWeston Andros Adamson 
55657d2ed9acSWeston Andros Adamson 		/* nii_date */
55667d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
55677d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
55687d2ed9acSWeston Andros Adamson 			goto out_overflow;
55697d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
55707d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
55717d2ed9acSWeston Andros Adamson 
55727d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
55737d2ed9acSWeston Andros Adamson 	}
557499fe60d0SBenny Halevy 	return 0;
5575c0eae66eSBenny Halevy out_overflow:
5576c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5577c0eae66eSBenny Halevy 	return -EIO;
557899fe60d0SBenny Halevy }
5579fc931582SAndy Adamson 
5580fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5581fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5582fc931582SAndy Adamson {
5583fc931582SAndy Adamson 	__be32 *p;
5584c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5585fc931582SAndy Adamson 
5586c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5587c0eae66eSBenny Halevy 	if (unlikely(!p))
5588c0eae66eSBenny Halevy 		goto out_overflow;
5589c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5590c9c30dd5SBenny Halevy 	if (val)
5591c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
55926f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
55936f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
55946f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
55956f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
55966f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5597cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5598fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5599a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5600a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5601fc931582SAndy Adamson 		return -EINVAL;
5602fc931582SAndy Adamson 	}
5603c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5604c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5605c0eae66eSBenny Halevy 		if (unlikely(!p))
5606c0eae66eSBenny Halevy 			goto out_overflow;
5607c0eae66eSBenny Halevy 	}
5608fc931582SAndy Adamson 	return 0;
5609c0eae66eSBenny Halevy out_overflow:
5610c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5611c0eae66eSBenny Halevy 	return -EIO;
5612fc931582SAndy Adamson }
5613fc931582SAndy Adamson 
5614e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5615e78291e4SBenny Halevy {
5616e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5617fc931582SAndy Adamson }
5618fc931582SAndy Adamson 
56197c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
56207c44f1aeSWeston Andros Adamson 				struct nfs41_bind_conn_to_session_res *res)
56217c44f1aeSWeston Andros Adamson {
56227c44f1aeSWeston Andros Adamson 	__be32 *p;
56237c44f1aeSWeston Andros Adamson 	int status;
56247c44f1aeSWeston Andros Adamson 
56257c44f1aeSWeston Andros Adamson 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
56267c44f1aeSWeston Andros Adamson 	if (!status)
56277c44f1aeSWeston Andros Adamson 		status = decode_sessionid(xdr, &res->session->sess_id);
56287c44f1aeSWeston Andros Adamson 	if (unlikely(status))
56297c44f1aeSWeston Andros Adamson 		return status;
56307c44f1aeSWeston Andros Adamson 
56317c44f1aeSWeston Andros Adamson 	/* dir flags, rdma mode bool */
56327c44f1aeSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 8);
56337c44f1aeSWeston Andros Adamson 	if (unlikely(!p))
56347c44f1aeSWeston Andros Adamson 		goto out_overflow;
56357c44f1aeSWeston Andros Adamson 
56367c44f1aeSWeston Andros Adamson 	res->dir = be32_to_cpup(p++);
56377c44f1aeSWeston Andros Adamson 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
56387c44f1aeSWeston Andros Adamson 		return -EIO;
56397c44f1aeSWeston Andros Adamson 	if (be32_to_cpup(p) == 0)
56407c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = false;
56417c44f1aeSWeston Andros Adamson 	else
56427c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = true;
56437c44f1aeSWeston Andros Adamson 
56447c44f1aeSWeston Andros Adamson 	return 0;
56457c44f1aeSWeston Andros Adamson out_overflow:
56467c44f1aeSWeston Andros Adamson 	print_overflow_msg(__func__, xdr);
56477c44f1aeSWeston Andros Adamson 	return -EIO;
56487c44f1aeSWeston Andros Adamson }
56497c44f1aeSWeston Andros Adamson 
5650fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5651fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5652fc931582SAndy Adamson {
5653fc931582SAndy Adamson 	__be32 *p;
5654fc931582SAndy Adamson 	int status;
5655fc931582SAndy Adamson 	struct nfs_client *clp = res->client;
5656fc931582SAndy Adamson 	struct nfs4_session *session = clp->cl_session;
5657fc931582SAndy Adamson 
5658fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5659e78291e4SBenny Halevy 	if (!status)
5660e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &session->sess_id);
5661e78291e4SBenny Halevy 	if (unlikely(status))
5662fc931582SAndy Adamson 		return status;
5663fc931582SAndy Adamson 
5664fc931582SAndy Adamson 	/* seqid, flags */
5665c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5666c0eae66eSBenny Halevy 	if (unlikely(!p))
5667c0eae66eSBenny Halevy 		goto out_overflow;
56686f723f77SBenny Halevy 	clp->cl_seqid = be32_to_cpup(p++);
5669cccddf4fSBenny Halevy 	session->flags = be32_to_cpup(p);
5670fc931582SAndy Adamson 
5671fc931582SAndy Adamson 	/* Channel attributes */
5672fc931582SAndy Adamson 	status = decode_chan_attrs(xdr, &session->fc_attrs);
5673fc931582SAndy Adamson 	if (!status)
5674fc931582SAndy Adamson 		status = decode_chan_attrs(xdr, &session->bc_attrs);
5675fc931582SAndy Adamson 	return status;
5676c0eae66eSBenny Halevy out_overflow:
5677c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5678c0eae66eSBenny Halevy 	return -EIO;
5679fc931582SAndy Adamson }
56800f3e66c6SAndy Adamson 
56810f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
56820f3e66c6SAndy Adamson {
56830f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
56840f3e66c6SAndy Adamson }
568518019753SRicardo Labiaga 
568666245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
568766245539STrond Myklebust {
568866245539STrond Myklebust 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
568966245539STrond Myklebust }
569066245539STrond Myklebust 
569118019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
569218019753SRicardo Labiaga {
569318019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
569418019753SRicardo Labiaga }
569599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
569699fe60d0SBenny Halevy 
56979b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
56989b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
56999b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
57009b7b9fccSAndy Adamson {
57019b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5702e3725ec0STrond Myklebust 	struct nfs4_session *session;
5703fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5704fc01cea9SAndy Adamson 	u32 dummy;
5705fc01cea9SAndy Adamson 	int status;
5706fc01cea9SAndy Adamson 	__be32 *p;
5707fc01cea9SAndy Adamson 
5708e3725ec0STrond Myklebust 	if (res->sr_slot == NULL)
57099b7b9fccSAndy Adamson 		return 0;
57103bd2384aSChuck Lever 	if (!res->sr_slot->table->session)
57113bd2384aSChuck Lever 		return 0;
57129b7b9fccSAndy Adamson 
5713fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5714e78291e4SBenny Halevy 	if (!status)
5715e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5716e78291e4SBenny Halevy 	if (unlikely(status))
5717fc01cea9SAndy Adamson 		goto out_err;
57189b7b9fccSAndy Adamson 
5719fc01cea9SAndy Adamson 	/*
5720fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5721fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5722fc01cea9SAndy Adamson 	 */
5723fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5724e3725ec0STrond Myklebust 	session = res->sr_slot->table->session;
5725fc01cea9SAndy Adamson 
5726e3725ec0STrond Myklebust 	if (memcmp(id.data, session->sess_id.data,
5727fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5728fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5729fc01cea9SAndy Adamson 		goto out_err;
5730fc01cea9SAndy Adamson 	}
5731e78291e4SBenny Halevy 
5732c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5733c0eae66eSBenny Halevy 	if (unlikely(!p))
5734c0eae66eSBenny Halevy 		goto out_overflow;
5735e78291e4SBenny Halevy 
5736fc01cea9SAndy Adamson 	/* seqid */
57376f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5738dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5739fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5740fc01cea9SAndy Adamson 		goto out_err;
5741fc01cea9SAndy Adamson 	}
5742fc01cea9SAndy Adamson 	/* slot id */
57436f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5744df2fabffSTrond Myklebust 	if (dummy != res->sr_slot->slot_nr) {
5745fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5746fc01cea9SAndy Adamson 		goto out_err;
5747fc01cea9SAndy Adamson 	}
5748da0507b7STrond Myklebust 	/* highest slot id */
5749da0507b7STrond Myklebust 	res->sr_highest_slotid = be32_to_cpup(p++);
5750464ee9f9STrond Myklebust 	/* target highest slot id */
5751464ee9f9STrond Myklebust 	res->sr_target_highest_slotid = be32_to_cpup(p++);
57520629e370SAlexandros Batsakis 	/* result flags */
57530629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5754fc01cea9SAndy Adamson 	status = 0;
5755fc01cea9SAndy Adamson out_err:
5756fc01cea9SAndy Adamson 	res->sr_status = status;
5757fc01cea9SAndy Adamson 	return status;
5758c0eae66eSBenny Halevy out_overflow:
5759c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5760c0eae66eSBenny Halevy 	status = -EIO;
5761c0eae66eSBenny Halevy 	goto out_err;
5762fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
57639b7b9fccSAndy Adamson 	return 0;
5764fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
57659b7b9fccSAndy Adamson }
57669b7b9fccSAndy Adamson 
5767b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
57687f11d8d3SAndy Adamson /*
57697f11d8d3SAndy Adamson  * TODO: Need to handle case when EOF != true;
57707f11d8d3SAndy Adamson  */
57717f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr,
57727f11d8d3SAndy Adamson 				struct pnfs_devicelist *res)
57737f11d8d3SAndy Adamson {
57747f11d8d3SAndy Adamson 	__be32 *p;
57757f11d8d3SAndy Adamson 	int status, i;
577698d94524STrond Myklebust 	nfs4_verifier verftemp;
57777f11d8d3SAndy Adamson 
57787f11d8d3SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICELIST);
57797f11d8d3SAndy Adamson 	if (status)
57807f11d8d3SAndy Adamson 		return status;
57817f11d8d3SAndy Adamson 
57827f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr, 8 + 8 + 4);
57837f11d8d3SAndy Adamson 	if (unlikely(!p))
57847f11d8d3SAndy Adamson 		goto out_overflow;
57857f11d8d3SAndy Adamson 
57867f11d8d3SAndy Adamson 	/* TODO: Skip cookie for now */
57877f11d8d3SAndy Adamson 	p += 2;
57887f11d8d3SAndy Adamson 
57897f11d8d3SAndy Adamson 	/* Read verifier */
579098d94524STrond Myklebust 	p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
57917f11d8d3SAndy Adamson 
57927f11d8d3SAndy Adamson 	res->num_devs = be32_to_cpup(p);
57937f11d8d3SAndy Adamson 
57947f11d8d3SAndy Adamson 	dprintk("%s: num_dev %d\n", __func__, res->num_devs);
57957f11d8d3SAndy Adamson 
57967f11d8d3SAndy Adamson 	if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5797a030889aSWeston Andros Adamson 		printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
57987f11d8d3SAndy Adamson 				__func__, res->num_devs);
57997f11d8d3SAndy Adamson 		return -EIO;
58007f11d8d3SAndy Adamson 	}
58017f11d8d3SAndy Adamson 
58027f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr,
58037f11d8d3SAndy Adamson 			      res->num_devs * NFS4_DEVICEID4_SIZE + 4);
58047f11d8d3SAndy Adamson 	if (unlikely(!p))
58057f11d8d3SAndy Adamson 		goto out_overflow;
58067f11d8d3SAndy Adamson 	for (i = 0; i < res->num_devs; i++)
58077f11d8d3SAndy Adamson 		p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
58087f11d8d3SAndy Adamson 					    NFS4_DEVICEID4_SIZE);
58097f11d8d3SAndy Adamson 	res->eof = be32_to_cpup(p);
58107f11d8d3SAndy Adamson 	return 0;
58117f11d8d3SAndy Adamson out_overflow:
58127f11d8d3SAndy Adamson 	print_overflow_msg(__func__, xdr);
58137f11d8d3SAndy Adamson 	return -EIO;
58147f11d8d3SAndy Adamson }
5815b1f69b75SAndy Adamson 
5816b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
5817b1f69b75SAndy Adamson 				struct pnfs_device *pdev)
5818b1f69b75SAndy Adamson {
5819b1f69b75SAndy Adamson 	__be32 *p;
5820b1f69b75SAndy Adamson 	uint32_t len, type;
5821b1f69b75SAndy Adamson 	int status;
5822b1f69b75SAndy Adamson 
5823b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5824b1f69b75SAndy Adamson 	if (status) {
5825b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5826b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5827b1f69b75SAndy Adamson 			if (unlikely(!p))
5828b1f69b75SAndy Adamson 				goto out_overflow;
5829b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5830b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5831b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5832b1f69b75SAndy Adamson 		}
5833b1f69b75SAndy Adamson 		return status;
5834b1f69b75SAndy Adamson 	}
5835b1f69b75SAndy Adamson 
5836b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5837b1f69b75SAndy Adamson 	if (unlikely(!p))
5838b1f69b75SAndy Adamson 		goto out_overflow;
5839b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5840b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5841b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5842b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5843b1f69b75SAndy Adamson 		return -EINVAL;
5844b1f69b75SAndy Adamson 	}
5845b1f69b75SAndy Adamson 	/*
5846b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5847b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5848b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5849b1f69b75SAndy Adamson 	 */
5850b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
585113fe4ba1STrond Myklebust 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
585213fe4ba1STrond Myklebust 		goto out_overflow;
5853b1f69b75SAndy Adamson 
5854b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5855b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5856b1f69b75SAndy Adamson 	if (unlikely(!p))
5857b1f69b75SAndy Adamson 		goto out_overflow;
5858b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5859b1f69b75SAndy Adamson 	if (len) {
5860ead00597SChuck Lever 		uint32_t i;
5861b1f69b75SAndy Adamson 
5862b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5863b1f69b75SAndy Adamson 		if (unlikely(!p))
5864b1f69b75SAndy Adamson 			goto out_overflow;
5865b1f69b75SAndy Adamson 		for (i = 0; i < len; i++, p++) {
5866b1f69b75SAndy Adamson 			if (be32_to_cpup(p)) {
5867b1f69b75SAndy Adamson 				dprintk("%s: notifications not supported\n",
5868b1f69b75SAndy Adamson 					__func__);
5869b1f69b75SAndy Adamson 				return -EIO;
5870b1f69b75SAndy Adamson 			}
5871b1f69b75SAndy Adamson 		}
5872b1f69b75SAndy Adamson 	}
5873b1f69b75SAndy Adamson 	return 0;
5874b1f69b75SAndy Adamson out_overflow:
5875b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5876b1f69b75SAndy Adamson 	return -EIO;
5877b1f69b75SAndy Adamson }
5878b1f69b75SAndy Adamson 
5879b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5880b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5881b1f69b75SAndy Adamson {
5882b1f69b75SAndy Adamson 	__be32 *p;
5883b1f69b75SAndy Adamson 	int status;
5884b1f69b75SAndy Adamson 	u32 layout_count;
588564bd577eSTrond Myklebust 	u32 recvd;
5886b1f69b75SAndy Adamson 
5887b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5888b1f69b75SAndy Adamson 	if (status)
5889b1f69b75SAndy Adamson 		return status;
5890ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5891b1f69b75SAndy Adamson 	if (unlikely(!p))
5892b1f69b75SAndy Adamson 		goto out_overflow;
5893ea9d23f5STrond Myklebust 	res->return_on_close = be32_to_cpup(p);
5894ea9d23f5STrond Myklebust 	decode_stateid(xdr, &res->stateid);
5895ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5896ea9d23f5STrond Myklebust 	if (unlikely(!p))
5897ea9d23f5STrond Myklebust 		goto out_overflow;
5898b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5899b1f69b75SAndy Adamson 	if (!layout_count) {
5900b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5901b1f69b75SAndy Adamson 			__func__);
5902b1f69b75SAndy Adamson 		return -EINVAL;
5903b1f69b75SAndy Adamson 	}
5904b1f69b75SAndy Adamson 
590535124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5906b1f69b75SAndy Adamson 	if (unlikely(!p))
5907b1f69b75SAndy Adamson 		goto out_overflow;
5908b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5909b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5910b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5911b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
591235124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5913b1f69b75SAndy Adamson 
5914b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5915b1f69b75SAndy Adamson 		__func__,
5916b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5917b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5918b1f69b75SAndy Adamson 		res->range.iomode,
5919b1f69b75SAndy Adamson 		res->type,
592035124a09SWeston Andros Adamson 		res->layoutp->len);
5921b1f69b75SAndy Adamson 
592264bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, res->layoutp->len);
592335124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
592435124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
592535124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
592635124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
592735124a09SWeston Andros Adamson 		return -EINVAL;
592835124a09SWeston Andros Adamson 	}
592935124a09SWeston Andros Adamson 
5930b1f69b75SAndy Adamson 	if (layout_count > 1) {
5931b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5932b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5933b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5934b1f69b75SAndy Adamson 		 * minimum it requested.
5935b1f69b75SAndy Adamson 		 */
5936b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5937b1f69b75SAndy Adamson 			__func__, layout_count);
5938b1f69b75SAndy Adamson 	}
5939b1f69b75SAndy Adamson 
5940b1f69b75SAndy Adamson 	return 0;
5941b1f69b75SAndy Adamson out_overflow:
5942b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5943b1f69b75SAndy Adamson 	return -EIO;
5944b1f69b75SAndy Adamson }
5945863a3c6cSAndy Adamson 
5946cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
5947cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
5948cbe82603SBenny Halevy {
5949cbe82603SBenny Halevy 	__be32 *p;
5950cbe82603SBenny Halevy 	int status;
5951cbe82603SBenny Halevy 
5952cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5953cbe82603SBenny Halevy 	if (status)
5954cbe82603SBenny Halevy 		return status;
5955cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5956cbe82603SBenny Halevy 	if (unlikely(!p))
5957cbe82603SBenny Halevy 		goto out_overflow;
5958cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
5959cbe82603SBenny Halevy 	if (res->lrs_present)
5960cbe82603SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
5961cbe82603SBenny Halevy 	return status;
5962cbe82603SBenny Halevy out_overflow:
5963cbe82603SBenny Halevy 	print_overflow_msg(__func__, xdr);
5964cbe82603SBenny Halevy 	return -EIO;
5965cbe82603SBenny Halevy }
5966cbe82603SBenny Halevy 
5967863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
5968863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
5969863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
5970863a3c6cSAndy Adamson {
5971863a3c6cSAndy Adamson 	__be32 *p;
5972863a3c6cSAndy Adamson 	__u32 sizechanged;
5973863a3c6cSAndy Adamson 	int status;
5974863a3c6cSAndy Adamson 
5975863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5976db29c089SAndy Adamson 	res->status = status;
5977863a3c6cSAndy Adamson 	if (status)
5978863a3c6cSAndy Adamson 		return status;
5979863a3c6cSAndy Adamson 
5980863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5981863a3c6cSAndy Adamson 	if (unlikely(!p))
5982863a3c6cSAndy Adamson 		goto out_overflow;
5983863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
5984863a3c6cSAndy Adamson 
5985863a3c6cSAndy Adamson 	if (sizechanged) {
5986863a3c6cSAndy Adamson 		/* throw away new size */
5987863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
5988863a3c6cSAndy Adamson 		if (unlikely(!p))
5989863a3c6cSAndy Adamson 			goto out_overflow;
5990863a3c6cSAndy Adamson 	}
5991863a3c6cSAndy Adamson 	return 0;
5992863a3c6cSAndy Adamson out_overflow:
5993863a3c6cSAndy Adamson 	print_overflow_msg(__func__, xdr);
5994863a3c6cSAndy Adamson 	return -EIO;
5995863a3c6cSAndy Adamson }
59967d974794SBryan Schumaker 
59977d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
59987d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
59997d974794SBryan Schumaker {
60007d974794SBryan Schumaker 	__be32 *p;
60017d974794SBryan Schumaker 	int status;
60027d974794SBryan Schumaker 	int num_res;
60037d974794SBryan Schumaker 
60047d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
60057d974794SBryan Schumaker 	if (status)
60067d974794SBryan Schumaker 		return status;
60077d974794SBryan Schumaker 
60087d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
60097d974794SBryan Schumaker 	if (unlikely(!p))
60107d974794SBryan Schumaker 		goto out_overflow;
60117d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
60127d974794SBryan Schumaker 	if (num_res != 1)
60137d974794SBryan Schumaker 		goto out;
60147d974794SBryan Schumaker 
60157d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
60167d974794SBryan Schumaker 	if (unlikely(!p))
60177d974794SBryan Schumaker 		goto out_overflow;
60187d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
60191cab0652SBryan Schumaker 
60201cab0652SBryan Schumaker 	return status;
60217d974794SBryan Schumaker out_overflow:
60227d974794SBryan Schumaker 	print_overflow_msg(__func__, xdr);
60237d974794SBryan Schumaker out:
60247d974794SBryan Schumaker 	return -EIO;
60257d974794SBryan Schumaker }
60269aeda35fSBryan Schumaker 
60279aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
60289aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
60299aeda35fSBryan Schumaker {
60309f79fb48SAndy Adamson 	res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
60319aeda35fSBryan Schumaker 	return res->status;
60329aeda35fSBryan Schumaker }
6033b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
6034b1f69b75SAndy Adamson 
60351da177e4SLinus Torvalds /*
603649c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
603749c2559eSBenny Halevy  */
603849c2559eSBenny Halevy 
603949c2559eSBenny Halevy /*
60401da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
60411da177e4SLinus Torvalds  */
6042bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6043bf269551SChuck Lever 				       struct xdr_stream *xdr,
6044bf269551SChuck Lever 				       struct nfs_closeres *res)
60451da177e4SLinus Torvalds {
60461da177e4SLinus Torvalds 	struct compound_hdr hdr;
60471da177e4SLinus Torvalds 	int status;
60481da177e4SLinus Torvalds 
6049bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60501da177e4SLinus Torvalds 	if (status)
60511da177e4SLinus Torvalds 		goto out;
6052bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60539b7b9fccSAndy Adamson 	if (status)
60549b7b9fccSAndy Adamson 		goto out;
6055bf269551SChuck Lever 	status = decode_putfh(xdr);
60561da177e4SLinus Torvalds 	if (status)
60571da177e4SLinus Torvalds 		goto out;
6058bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
6059516a6af6STrond Myklebust 	if (status != 0)
6060516a6af6STrond Myklebust 		goto out;
60616926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
60621da177e4SLinus Torvalds out:
60631da177e4SLinus Torvalds 	return status;
60641da177e4SLinus Torvalds }
60651da177e4SLinus Torvalds 
60661da177e4SLinus Torvalds /*
60671da177e4SLinus Torvalds  * Decode ACCESS response
60681da177e4SLinus Torvalds  */
6069bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6070bf269551SChuck Lever 			       struct nfs4_accessres *res)
60711da177e4SLinus Torvalds {
60721da177e4SLinus Torvalds 	struct compound_hdr hdr;
60731da177e4SLinus Torvalds 	int status;
60741da177e4SLinus Torvalds 
6075bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60769b7b9fccSAndy Adamson 	if (status)
60779b7b9fccSAndy Adamson 		goto out;
6078bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60799b7b9fccSAndy Adamson 	if (status)
60801da177e4SLinus Torvalds 		goto out;
6081bf269551SChuck Lever 	status = decode_putfh(xdr);
608276b32999STrond Myklebust 	if (status != 0)
608376b32999STrond Myklebust 		goto out;
60846168f62cSWeston Andros Adamson 	status = decode_access(xdr, &res->supported, &res->access);
608576b32999STrond Myklebust 	if (status != 0)
608676b32999STrond Myklebust 		goto out;
60876926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
60881da177e4SLinus Torvalds out:
60891da177e4SLinus Torvalds 	return status;
60901da177e4SLinus Torvalds }
60911da177e4SLinus Torvalds 
60921da177e4SLinus Torvalds /*
60931da177e4SLinus Torvalds  * Decode LOOKUP response
60941da177e4SLinus Torvalds  */
6095bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6096bf269551SChuck Lever 			       struct nfs4_lookup_res *res)
60971da177e4SLinus Torvalds {
60981da177e4SLinus Torvalds 	struct compound_hdr hdr;
60991da177e4SLinus Torvalds 	int status;
61001da177e4SLinus Torvalds 
6101bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61029b7b9fccSAndy Adamson 	if (status)
61039b7b9fccSAndy Adamson 		goto out;
6104bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61059b7b9fccSAndy Adamson 	if (status)
61061da177e4SLinus Torvalds 		goto out;
6107bf269551SChuck Lever 	status = decode_putfh(xdr);
6108bf269551SChuck Lever 	if (status)
61091da177e4SLinus Torvalds 		goto out;
6110bf269551SChuck Lever 	status = decode_lookup(xdr);
6111bf269551SChuck Lever 	if (status)
61121da177e4SLinus Torvalds 		goto out;
6113bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6114bf269551SChuck Lever 	if (status)
61151da177e4SLinus Torvalds 		goto out;
6116aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
61171da177e4SLinus Torvalds out:
61181da177e4SLinus Torvalds 	return status;
61191da177e4SLinus Torvalds }
61201da177e4SLinus Torvalds 
61211da177e4SLinus Torvalds /*
61221da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
61231da177e4SLinus Torvalds  */
6124bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6125bf269551SChuck Lever 				    struct xdr_stream *xdr,
6126bf269551SChuck Lever 				    struct nfs4_lookup_res *res)
61271da177e4SLinus Torvalds {
61281da177e4SLinus Torvalds 	struct compound_hdr hdr;
61291da177e4SLinus Torvalds 	int status;
61301da177e4SLinus Torvalds 
6131bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61329b7b9fccSAndy Adamson 	if (status)
61339b7b9fccSAndy Adamson 		goto out;
6134bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61359b7b9fccSAndy Adamson 	if (status)
61361da177e4SLinus Torvalds 		goto out;
6137bf269551SChuck Lever 	status = decode_putrootfh(xdr);
6138bf269551SChuck Lever 	if (status)
61391da177e4SLinus Torvalds 		goto out;
6140bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6141bf269551SChuck Lever 	if (status == 0)
6142aa9c2669SDavid Quigley 		status = decode_getfattr_label(xdr, res->fattr,
6143aa9c2669SDavid Quigley 						res->label, res->server);
61441da177e4SLinus Torvalds out:
61451da177e4SLinus Torvalds 	return status;
61461da177e4SLinus Torvalds }
61471da177e4SLinus Torvalds 
61481da177e4SLinus Torvalds /*
61491da177e4SLinus Torvalds  * Decode REMOVE response
61501da177e4SLinus Torvalds  */
6151bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6152bf269551SChuck Lever 			       struct nfs_removeres *res)
61531da177e4SLinus Torvalds {
61541da177e4SLinus Torvalds 	struct compound_hdr hdr;
61551da177e4SLinus Torvalds 	int status;
61561da177e4SLinus Torvalds 
6157bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61589b7b9fccSAndy Adamson 	if (status)
61599b7b9fccSAndy Adamson 		goto out;
6160bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61619b7b9fccSAndy Adamson 	if (status)
61621da177e4SLinus Torvalds 		goto out;
6163bf269551SChuck Lever 	status = decode_putfh(xdr);
6164bf269551SChuck Lever 	if (status)
616516e42959STrond Myklebust 		goto out;
6166bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
61671da177e4SLinus Torvalds out:
61681da177e4SLinus Torvalds 	return status;
61691da177e4SLinus Torvalds }
61701da177e4SLinus Torvalds 
61711da177e4SLinus Torvalds /*
61721da177e4SLinus Torvalds  * Decode RENAME response
61731da177e4SLinus Torvalds  */
6174bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6175bf269551SChuck Lever 			       struct nfs_renameres *res)
61761da177e4SLinus Torvalds {
61771da177e4SLinus Torvalds 	struct compound_hdr hdr;
61781da177e4SLinus Torvalds 	int status;
61791da177e4SLinus Torvalds 
6180bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61819b7b9fccSAndy Adamson 	if (status)
61829b7b9fccSAndy Adamson 		goto out;
6183bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61849b7b9fccSAndy Adamson 	if (status)
61851da177e4SLinus Torvalds 		goto out;
6186bf269551SChuck Lever 	status = decode_putfh(xdr);
6187bf269551SChuck Lever 	if (status)
61881da177e4SLinus Torvalds 		goto out;
6189bf269551SChuck Lever 	status = decode_savefh(xdr);
6190bf269551SChuck Lever 	if (status)
61911da177e4SLinus Torvalds 		goto out;
6192bf269551SChuck Lever 	status = decode_putfh(xdr);
6193bf269551SChuck Lever 	if (status)
61941da177e4SLinus Torvalds 		goto out;
6195bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
61961da177e4SLinus Torvalds out:
61971da177e4SLinus Torvalds 	return status;
61981da177e4SLinus Torvalds }
61991da177e4SLinus Torvalds 
62001da177e4SLinus Torvalds /*
62011da177e4SLinus Torvalds  * Decode LINK response
62021da177e4SLinus Torvalds  */
6203bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6204bf269551SChuck Lever 			     struct nfs4_link_res *res)
62051da177e4SLinus Torvalds {
62061da177e4SLinus Torvalds 	struct compound_hdr hdr;
62071da177e4SLinus Torvalds 	int status;
62081da177e4SLinus Torvalds 
6209bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62109b7b9fccSAndy Adamson 	if (status)
62119b7b9fccSAndy Adamson 		goto out;
6212bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62139b7b9fccSAndy Adamson 	if (status)
62141da177e4SLinus Torvalds 		goto out;
6215bf269551SChuck Lever 	status = decode_putfh(xdr);
6216bf269551SChuck Lever 	if (status)
62171da177e4SLinus Torvalds 		goto out;
6218bf269551SChuck Lever 	status = decode_savefh(xdr);
6219bf269551SChuck Lever 	if (status)
62201da177e4SLinus Torvalds 		goto out;
6221bf269551SChuck Lever 	status = decode_putfh(xdr);
6222bf269551SChuck Lever 	if (status)
62231da177e4SLinus Torvalds 		goto out;
6224bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
6225bf269551SChuck Lever 	if (status)
622691ba2eeeSTrond Myklebust 		goto out;
622791ba2eeeSTrond Myklebust 	/*
622891ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
622991ba2eeeSTrond Myklebust 	 *             filehandle.
623091ba2eeeSTrond Myklebust 	 */
6231bf269551SChuck Lever 	status = decode_restorefh(xdr);
6232bf269551SChuck Lever 	if (status)
623391ba2eeeSTrond Myklebust 		goto out;
6234aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62351da177e4SLinus Torvalds out:
62361da177e4SLinus Torvalds 	return status;
62371da177e4SLinus Torvalds }
62381da177e4SLinus Torvalds 
62391da177e4SLinus Torvalds /*
62401da177e4SLinus Torvalds  * Decode CREATE response
62411da177e4SLinus Torvalds  */
6242bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6243bf269551SChuck Lever 			       struct nfs4_create_res *res)
62441da177e4SLinus Torvalds {
62451da177e4SLinus Torvalds 	struct compound_hdr hdr;
62461da177e4SLinus Torvalds 	int status;
62471da177e4SLinus Torvalds 
6248bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62499b7b9fccSAndy Adamson 	if (status)
62509b7b9fccSAndy Adamson 		goto out;
6251bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62529b7b9fccSAndy Adamson 	if (status)
62531da177e4SLinus Torvalds 		goto out;
6254bf269551SChuck Lever 	status = decode_putfh(xdr);
6255bf269551SChuck Lever 	if (status)
62561da177e4SLinus Torvalds 		goto out;
6257bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6258bf269551SChuck Lever 	if (status)
62591da177e4SLinus Torvalds 		goto out;
6260bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6261bf269551SChuck Lever 	if (status)
62621da177e4SLinus Torvalds 		goto out;
6263aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62641da177e4SLinus Torvalds out:
62651da177e4SLinus Torvalds 	return status;
62661da177e4SLinus Torvalds }
62671da177e4SLinus Torvalds 
62681da177e4SLinus Torvalds /*
62691da177e4SLinus Torvalds  * Decode SYMLINK response
62701da177e4SLinus Torvalds  */
6271bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6272bf269551SChuck Lever 				struct nfs4_create_res *res)
62731da177e4SLinus Torvalds {
6274bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
62751da177e4SLinus Torvalds }
62761da177e4SLinus Torvalds 
62771da177e4SLinus Torvalds /*
62781da177e4SLinus Torvalds  * Decode GETATTR response
62791da177e4SLinus Torvalds  */
6280bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6281bf269551SChuck Lever 				struct nfs4_getattr_res *res)
62821da177e4SLinus Torvalds {
62831da177e4SLinus Torvalds 	struct compound_hdr hdr;
62841da177e4SLinus Torvalds 	int status;
62851da177e4SLinus Torvalds 
6286bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62871da177e4SLinus Torvalds 	if (status)
62881da177e4SLinus Torvalds 		goto out;
6289bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62909b7b9fccSAndy Adamson 	if (status)
62919b7b9fccSAndy Adamson 		goto out;
6292bf269551SChuck Lever 	status = decode_putfh(xdr);
62931da177e4SLinus Torvalds 	if (status)
62941da177e4SLinus Torvalds 		goto out;
6295aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62961da177e4SLinus Torvalds out:
62971da177e4SLinus Torvalds 	return status;
62981da177e4SLinus Torvalds }
62991da177e4SLinus Torvalds 
630023ec6965SJ. Bruce Fields /*
630123ec6965SJ. Bruce Fields  * Encode an SETACL request
630223ec6965SJ. Bruce Fields  */
63039f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
63049f06c719SChuck Lever 				struct nfs_setaclargs *args)
630523ec6965SJ. Bruce Fields {
630623ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
630766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
630823ec6965SJ. Bruce Fields 	};
630923ec6965SJ. Bruce Fields 
63109f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
63119f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
63129f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
63139f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6314d017931cSAndy Adamson 	encode_nops(&hdr);
631523ec6965SJ. Bruce Fields }
631605d564feSAndy Adamson 
631723ec6965SJ. Bruce Fields /*
631823ec6965SJ. Bruce Fields  * Decode SETACL response
631923ec6965SJ. Bruce Fields  */
632023ec6965SJ. Bruce Fields static int
6321bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
632273c403a9SBenny Halevy 		    struct nfs_setaclres *res)
632323ec6965SJ. Bruce Fields {
632423ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
632523ec6965SJ. Bruce Fields 	int status;
632623ec6965SJ. Bruce Fields 
6327bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
632823ec6965SJ. Bruce Fields 	if (status)
632923ec6965SJ. Bruce Fields 		goto out;
6330bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63319b7b9fccSAndy Adamson 	if (status)
63329b7b9fccSAndy Adamson 		goto out;
6333bf269551SChuck Lever 	status = decode_putfh(xdr);
633423ec6965SJ. Bruce Fields 	if (status)
633523ec6965SJ. Bruce Fields 		goto out;
6336bf269551SChuck Lever 	status = decode_setattr(xdr);
633723ec6965SJ. Bruce Fields out:
633823ec6965SJ. Bruce Fields 	return status;
633923ec6965SJ. Bruce Fields }
63401da177e4SLinus Torvalds 
63411da177e4SLinus Torvalds /*
6342029d105eSJ. Bruce Fields  * Decode GETACL response
6343029d105eSJ. Bruce Fields  */
6344029d105eSJ. Bruce Fields static int
6345bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6346663c79b3SBenny Halevy 		    struct nfs_getaclres *res)
6347029d105eSJ. Bruce Fields {
6348029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6349029d105eSJ. Bruce Fields 	int status;
6350029d105eSJ. Bruce Fields 
6351331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6352331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6353331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6354331818f1STrond Myklebust 	}
6355bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6356029d105eSJ. Bruce Fields 	if (status)
6357029d105eSJ. Bruce Fields 		goto out;
6358bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63599b7b9fccSAndy Adamson 	if (status)
63609b7b9fccSAndy Adamson 		goto out;
6361bf269551SChuck Lever 	status = decode_putfh(xdr);
6362029d105eSJ. Bruce Fields 	if (status)
6363029d105eSJ. Bruce Fields 		goto out;
6364bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6365029d105eSJ. Bruce Fields 
6366029d105eSJ. Bruce Fields out:
6367029d105eSJ. Bruce Fields 	return status;
6368029d105eSJ. Bruce Fields }
6369029d105eSJ. Bruce Fields 
6370029d105eSJ. Bruce Fields /*
63711da177e4SLinus Torvalds  * Decode CLOSE response
63721da177e4SLinus Torvalds  */
6373bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6374bf269551SChuck Lever 			      struct nfs_closeres *res)
63751da177e4SLinus Torvalds {
63761da177e4SLinus Torvalds 	struct compound_hdr hdr;
63771da177e4SLinus Torvalds 	int status;
63781da177e4SLinus Torvalds 
6379bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63801da177e4SLinus Torvalds 	if (status)
63811da177e4SLinus Torvalds 		goto out;
6382bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63839b7b9fccSAndy Adamson 	if (status)
63849b7b9fccSAndy Adamson 		goto out;
6385bf269551SChuck Lever 	status = decode_putfh(xdr);
63861da177e4SLinus Torvalds 	if (status)
63871da177e4SLinus Torvalds 		goto out;
6388bf269551SChuck Lever 	status = decode_close(xdr, res);
6389516a6af6STrond Myklebust 	if (status != 0)
6390516a6af6STrond Myklebust 		goto out;
6391516a6af6STrond Myklebust 	/*
6392516a6af6STrond Myklebust 	 * Note: Server may do delete on close for this file
6393516a6af6STrond Myklebust 	 * 	in which case the getattr call will fail with
6394516a6af6STrond Myklebust 	 * 	an ESTALE error. Shouldn't be a problem,
6395516a6af6STrond Myklebust 	 * 	though, since fattr->valid will remain unset.
6396516a6af6STrond Myklebust 	 */
63976926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
63981da177e4SLinus Torvalds out:
63991da177e4SLinus Torvalds 	return status;
64001da177e4SLinus Torvalds }
64011da177e4SLinus Torvalds 
64021da177e4SLinus Torvalds /*
64031da177e4SLinus Torvalds  * Decode OPEN response
64041da177e4SLinus Torvalds  */
6405bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6406bf269551SChuck Lever 			     struct nfs_openres *res)
64071da177e4SLinus Torvalds {
64081da177e4SLinus Torvalds 	struct compound_hdr hdr;
64091da177e4SLinus Torvalds 	int status;
64101da177e4SLinus Torvalds 
6411bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64121da177e4SLinus Torvalds 	if (status)
64131da177e4SLinus Torvalds 		goto out;
6414bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64159b7b9fccSAndy Adamson 	if (status)
64169b7b9fccSAndy Adamson 		goto out;
6417bf269551SChuck Lever 	status = decode_putfh(xdr);
64181da177e4SLinus Torvalds 	if (status)
64191da177e4SLinus Torvalds 		goto out;
6420bf269551SChuck Lever 	status = decode_open(xdr, res);
64211da177e4SLinus Torvalds 	if (status)
64221da177e4SLinus Torvalds 		goto out;
642301913b49SWeston Andros Adamson 	status = decode_getfh(xdr, &res->fh);
642401913b49SWeston Andros Adamson 	if (status)
64251da177e4SLinus Torvalds 		goto out;
6426ae2bb032SWeston Andros Adamson 	if (res->access_request)
64276168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
6428aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
64291da177e4SLinus Torvalds out:
64301da177e4SLinus Torvalds 	return status;
64311da177e4SLinus Torvalds }
64321da177e4SLinus Torvalds 
64331da177e4SLinus Torvalds /*
64341da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
64351da177e4SLinus Torvalds  */
6436bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6437bf269551SChuck Lever 				     struct xdr_stream *xdr,
6438bf269551SChuck Lever 				     struct nfs_open_confirmres *res)
64391da177e4SLinus Torvalds {
64401da177e4SLinus Torvalds 	struct compound_hdr hdr;
64411da177e4SLinus Torvalds 	int status;
64421da177e4SLinus Torvalds 
6443bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64441da177e4SLinus Torvalds 	if (status)
64451da177e4SLinus Torvalds 		goto out;
6446bf269551SChuck Lever 	status = decode_putfh(xdr);
64471da177e4SLinus Torvalds 	if (status)
64481da177e4SLinus Torvalds 		goto out;
6449bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
64501da177e4SLinus Torvalds out:
64511da177e4SLinus Torvalds 	return status;
64521da177e4SLinus Torvalds }
64531da177e4SLinus Torvalds 
64541da177e4SLinus Torvalds /*
64551da177e4SLinus Torvalds  * Decode OPEN response
64561da177e4SLinus Torvalds  */
6457bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6458bf269551SChuck Lever 				    struct xdr_stream *xdr,
6459bf269551SChuck Lever 				    struct nfs_openres *res)
64601da177e4SLinus Torvalds {
64611da177e4SLinus Torvalds 	struct compound_hdr hdr;
64621da177e4SLinus Torvalds 	int status;
64631da177e4SLinus Torvalds 
6464bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64651da177e4SLinus Torvalds 	if (status)
64661da177e4SLinus Torvalds 		goto out;
6467bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64689b7b9fccSAndy Adamson 	if (status)
64699b7b9fccSAndy Adamson 		goto out;
6470bf269551SChuck Lever 	status = decode_putfh(xdr);
64711da177e4SLinus Torvalds 	if (status)
64721da177e4SLinus Torvalds 		goto out;
6473bf269551SChuck Lever 	status = decode_open(xdr, res);
6474864472e9STrond Myklebust 	if (status)
6475864472e9STrond Myklebust 		goto out;
6476ae2bb032SWeston Andros Adamson 	if (res->access_request)
64776168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
64786926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
64791da177e4SLinus Torvalds out:
64801da177e4SLinus Torvalds 	return status;
64811da177e4SLinus Torvalds }
64821da177e4SLinus Torvalds 
64831da177e4SLinus Torvalds /*
64841da177e4SLinus Torvalds  * Decode SETATTR response
64851da177e4SLinus Torvalds  */
6486bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6487bf269551SChuck Lever 				struct xdr_stream *xdr,
6488bf269551SChuck Lever 				struct nfs_setattrres *res)
64891da177e4SLinus Torvalds {
64901da177e4SLinus Torvalds 	struct compound_hdr hdr;
64911da177e4SLinus Torvalds 	int status;
64921da177e4SLinus Torvalds 
6493bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64941da177e4SLinus Torvalds 	if (status)
64951da177e4SLinus Torvalds 		goto out;
6496bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64979b7b9fccSAndy Adamson 	if (status)
64989b7b9fccSAndy Adamson 		goto out;
6499bf269551SChuck Lever 	status = decode_putfh(xdr);
65001da177e4SLinus Torvalds 	if (status)
65011da177e4SLinus Torvalds 		goto out;
6502bf269551SChuck Lever 	status = decode_setattr(xdr);
65031da177e4SLinus Torvalds 	if (status)
65041da177e4SLinus Torvalds 		goto out;
6505aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
65061da177e4SLinus Torvalds out:
65071da177e4SLinus Torvalds 	return status;
65081da177e4SLinus Torvalds }
65091da177e4SLinus Torvalds 
65101da177e4SLinus Torvalds /*
65111da177e4SLinus Torvalds  * Decode LOCK response
65121da177e4SLinus Torvalds  */
6513bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6514bf269551SChuck Lever 			     struct nfs_lock_res *res)
65151da177e4SLinus Torvalds {
65161da177e4SLinus Torvalds 	struct compound_hdr hdr;
65171da177e4SLinus Torvalds 	int status;
65181da177e4SLinus Torvalds 
6519bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65201da177e4SLinus Torvalds 	if (status)
65211da177e4SLinus Torvalds 		goto out;
6522bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65239b7b9fccSAndy Adamson 	if (status)
65249b7b9fccSAndy Adamson 		goto out;
6525bf269551SChuck Lever 	status = decode_putfh(xdr);
65261da177e4SLinus Torvalds 	if (status)
65271da177e4SLinus Torvalds 		goto out;
6528bf269551SChuck Lever 	status = decode_lock(xdr, res);
65291da177e4SLinus Torvalds out:
65301da177e4SLinus Torvalds 	return status;
65311da177e4SLinus Torvalds }
65321da177e4SLinus Torvalds 
65331da177e4SLinus Torvalds /*
65341da177e4SLinus Torvalds  * Decode LOCKT response
65351da177e4SLinus Torvalds  */
6536bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6537bf269551SChuck Lever 			      struct nfs_lockt_res *res)
65381da177e4SLinus Torvalds {
65391da177e4SLinus Torvalds 	struct compound_hdr hdr;
65401da177e4SLinus Torvalds 	int status;
65411da177e4SLinus Torvalds 
6542bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65431da177e4SLinus Torvalds 	if (status)
65441da177e4SLinus Torvalds 		goto out;
6545bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65469b7b9fccSAndy Adamson 	if (status)
65479b7b9fccSAndy Adamson 		goto out;
6548bf269551SChuck Lever 	status = decode_putfh(xdr);
65491da177e4SLinus Torvalds 	if (status)
65501da177e4SLinus Torvalds 		goto out;
6551bf269551SChuck Lever 	status = decode_lockt(xdr, res);
65521da177e4SLinus Torvalds out:
65531da177e4SLinus Torvalds 	return status;
65541da177e4SLinus Torvalds }
65551da177e4SLinus Torvalds 
65561da177e4SLinus Torvalds /*
65571da177e4SLinus Torvalds  * Decode LOCKU response
65581da177e4SLinus Torvalds  */
6559bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6560bf269551SChuck Lever 			      struct nfs_locku_res *res)
65611da177e4SLinus Torvalds {
65621da177e4SLinus Torvalds 	struct compound_hdr hdr;
65631da177e4SLinus Torvalds 	int status;
65641da177e4SLinus Torvalds 
6565bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65661da177e4SLinus Torvalds 	if (status)
65671da177e4SLinus Torvalds 		goto out;
6568bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65699b7b9fccSAndy Adamson 	if (status)
65709b7b9fccSAndy Adamson 		goto out;
6571bf269551SChuck Lever 	status = decode_putfh(xdr);
65721da177e4SLinus Torvalds 	if (status)
65731da177e4SLinus Torvalds 		goto out;
6574bf269551SChuck Lever 	status = decode_locku(xdr, res);
65751da177e4SLinus Torvalds out:
65761da177e4SLinus Torvalds 	return status;
65771da177e4SLinus Torvalds }
65781da177e4SLinus Torvalds 
6579bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6580bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6581d3c7b7ccSTrond Myklebust {
6582d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6583d3c7b7ccSTrond Myklebust 	int status;
6584d3c7b7ccSTrond Myklebust 
6585bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6586d3c7b7ccSTrond Myklebust 	if (!status)
6587bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6588d3c7b7ccSTrond Myklebust 	return status;
6589d3c7b7ccSTrond Myklebust }
6590d3c7b7ccSTrond Myklebust 
65911da177e4SLinus Torvalds /*
65921da177e4SLinus Torvalds  * Decode READLINK response
65931da177e4SLinus Torvalds  */
6594bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6595bf269551SChuck Lever 				 struct xdr_stream *xdr,
6596f50c7000SBenny Halevy 				 struct nfs4_readlink_res *res)
65971da177e4SLinus Torvalds {
65981da177e4SLinus Torvalds 	struct compound_hdr hdr;
65991da177e4SLinus Torvalds 	int status;
66001da177e4SLinus Torvalds 
6601bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66021da177e4SLinus Torvalds 	if (status)
66031da177e4SLinus Torvalds 		goto out;
6604bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66059b7b9fccSAndy Adamson 	if (status)
66069b7b9fccSAndy Adamson 		goto out;
6607bf269551SChuck Lever 	status = decode_putfh(xdr);
66081da177e4SLinus Torvalds 	if (status)
66091da177e4SLinus Torvalds 		goto out;
6610bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
66111da177e4SLinus Torvalds out:
66121da177e4SLinus Torvalds 	return status;
66131da177e4SLinus Torvalds }
66141da177e4SLinus Torvalds 
66151da177e4SLinus Torvalds /*
66161da177e4SLinus Torvalds  * Decode READDIR response
66171da177e4SLinus Torvalds  */
6618bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6619bf269551SChuck Lever 				struct nfs4_readdir_res *res)
66201da177e4SLinus Torvalds {
66211da177e4SLinus Torvalds 	struct compound_hdr hdr;
66221da177e4SLinus Torvalds 	int status;
66231da177e4SLinus Torvalds 
6624bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66251da177e4SLinus Torvalds 	if (status)
66261da177e4SLinus Torvalds 		goto out;
6627bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66289b7b9fccSAndy Adamson 	if (status)
66299b7b9fccSAndy Adamson 		goto out;
6630bf269551SChuck Lever 	status = decode_putfh(xdr);
66311da177e4SLinus Torvalds 	if (status)
66321da177e4SLinus Torvalds 		goto out;
6633bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
66341da177e4SLinus Torvalds out:
66351da177e4SLinus Torvalds 	return status;
66361da177e4SLinus Torvalds }
66371da177e4SLinus Torvalds 
66381da177e4SLinus Torvalds /*
66391da177e4SLinus Torvalds  * Decode Read response
66401da177e4SLinus Torvalds  */
6641bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
66429137bdf3SAnna Schumaker 			     struct nfs_pgio_res *res)
66431da177e4SLinus Torvalds {
66441da177e4SLinus Torvalds 	struct compound_hdr hdr;
66451da177e4SLinus Torvalds 	int status;
66461da177e4SLinus Torvalds 
6647bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66481da177e4SLinus Torvalds 	if (status)
66491da177e4SLinus Torvalds 		goto out;
6650bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66519b7b9fccSAndy Adamson 	if (status)
66529b7b9fccSAndy Adamson 		goto out;
6653bf269551SChuck Lever 	status = decode_putfh(xdr);
66541da177e4SLinus Torvalds 	if (status)
66551da177e4SLinus Torvalds 		goto out;
6656bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
66571da177e4SLinus Torvalds 	if (!status)
66581da177e4SLinus Torvalds 		status = res->count;
66591da177e4SLinus Torvalds out:
66601da177e4SLinus Torvalds 	return status;
66611da177e4SLinus Torvalds }
66621da177e4SLinus Torvalds 
66631da177e4SLinus Torvalds /*
66641da177e4SLinus Torvalds  * Decode WRITE response
66651da177e4SLinus Torvalds  */
6666bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
66679137bdf3SAnna Schumaker 			      struct nfs_pgio_res *res)
66681da177e4SLinus Torvalds {
66691da177e4SLinus Torvalds 	struct compound_hdr hdr;
66701da177e4SLinus Torvalds 	int status;
66711da177e4SLinus Torvalds 
6672bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66731da177e4SLinus Torvalds 	if (status)
66741da177e4SLinus Torvalds 		goto out;
6675bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66769b7b9fccSAndy Adamson 	if (status)
66779b7b9fccSAndy Adamson 		goto out;
6678bf269551SChuck Lever 	status = decode_putfh(xdr);
66791da177e4SLinus Torvalds 	if (status)
66801da177e4SLinus Torvalds 		goto out;
6681bf269551SChuck Lever 	status = decode_write(xdr, res);
66824f9838c7STrond Myklebust 	if (status)
66834f9838c7STrond Myklebust 		goto out;
66847ffd1064SFred Isaman 	if (res->fattr)
66856926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
66861da177e4SLinus Torvalds 	if (!status)
66871da177e4SLinus Torvalds 		status = res->count;
66881da177e4SLinus Torvalds out:
66891da177e4SLinus Torvalds 	return status;
66901da177e4SLinus Torvalds }
66911da177e4SLinus Torvalds 
66921da177e4SLinus Torvalds /*
66931da177e4SLinus Torvalds  * Decode COMMIT response
66941da177e4SLinus Torvalds  */
6695bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
66960b7c0153SFred Isaman 			       struct nfs_commitres *res)
66971da177e4SLinus Torvalds {
66981da177e4SLinus Torvalds 	struct compound_hdr hdr;
66991da177e4SLinus Torvalds 	int status;
67001da177e4SLinus Torvalds 
6701bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67021da177e4SLinus Torvalds 	if (status)
67031da177e4SLinus Torvalds 		goto out;
6704bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67059b7b9fccSAndy Adamson 	if (status)
67069b7b9fccSAndy Adamson 		goto out;
6707bf269551SChuck Lever 	status = decode_putfh(xdr);
67081da177e4SLinus Torvalds 	if (status)
67091da177e4SLinus Torvalds 		goto out;
6710bf269551SChuck Lever 	status = decode_commit(xdr, res);
67111da177e4SLinus Torvalds out:
67121da177e4SLinus Torvalds 	return status;
67131da177e4SLinus Torvalds }
67141da177e4SLinus Torvalds 
67151da177e4SLinus Torvalds /*
67168b173218SRicardo Labiaga  * Decode FSINFO response
67171da177e4SLinus Torvalds  */
6718bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
67193dda5e43SBenny Halevy 			       struct nfs4_fsinfo_res *res)
67201da177e4SLinus Torvalds {
67211da177e4SLinus Torvalds 	struct compound_hdr hdr;
67221da177e4SLinus Torvalds 	int status;
67231da177e4SLinus Torvalds 
6724bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67251da177e4SLinus Torvalds 	if (!status)
6726bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67279b7b9fccSAndy Adamson 	if (!status)
6728bf269551SChuck Lever 		status = decode_putfh(xdr);
67291da177e4SLinus Torvalds 	if (!status)
6730bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
67311da177e4SLinus Torvalds 	return status;
67321da177e4SLinus Torvalds }
67331da177e4SLinus Torvalds 
67341da177e4SLinus Torvalds /*
67358b173218SRicardo Labiaga  * Decode PATHCONF response
67361da177e4SLinus Torvalds  */
6737bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6738d45b2989SBenny Halevy 				 struct nfs4_pathconf_res *res)
67391da177e4SLinus Torvalds {
67401da177e4SLinus Torvalds 	struct compound_hdr hdr;
67411da177e4SLinus Torvalds 	int status;
67421da177e4SLinus Torvalds 
6743bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67441da177e4SLinus Torvalds 	if (!status)
6745bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67469b7b9fccSAndy Adamson 	if (!status)
6747bf269551SChuck Lever 		status = decode_putfh(xdr);
67481da177e4SLinus Torvalds 	if (!status)
6749bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
67501da177e4SLinus Torvalds 	return status;
67511da177e4SLinus Torvalds }
67521da177e4SLinus Torvalds 
67531da177e4SLinus Torvalds /*
67548b173218SRicardo Labiaga  * Decode STATFS response
67551da177e4SLinus Torvalds  */
6756bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
675724ad148aSBenny Halevy 			       struct nfs4_statfs_res *res)
67581da177e4SLinus Torvalds {
67591da177e4SLinus Torvalds 	struct compound_hdr hdr;
67601da177e4SLinus Torvalds 	int status;
67611da177e4SLinus Torvalds 
6762bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67631da177e4SLinus Torvalds 	if (!status)
6764bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67659b7b9fccSAndy Adamson 	if (!status)
6766bf269551SChuck Lever 		status = decode_putfh(xdr);
67671da177e4SLinus Torvalds 	if (!status)
6768bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
67691da177e4SLinus Torvalds 	return status;
67701da177e4SLinus Torvalds }
67711da177e4SLinus Torvalds 
67721da177e4SLinus Torvalds /*
67738b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
67741da177e4SLinus Torvalds  */
6775bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6776bf269551SChuck Lever 				    struct xdr_stream *xdr,
6777bf269551SChuck Lever 				    struct nfs4_server_caps_res *res)
67781da177e4SLinus Torvalds {
67791da177e4SLinus Torvalds 	struct compound_hdr hdr;
67801da177e4SLinus Torvalds 	int status;
67811da177e4SLinus Torvalds 
6782bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67839b7b9fccSAndy Adamson 	if (status)
67849b7b9fccSAndy Adamson 		goto out;
6785bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
67869b7b9fccSAndy Adamson 	if (status)
67871da177e4SLinus Torvalds 		goto out;
6788bf269551SChuck Lever 	status = decode_putfh(xdr);
6789bf269551SChuck Lever 	if (status)
67901da177e4SLinus Torvalds 		goto out;
6791bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
67921da177e4SLinus Torvalds out:
67931da177e4SLinus Torvalds 	return status;
67941da177e4SLinus Torvalds }
67951da177e4SLinus Torvalds 
67961da177e4SLinus Torvalds /*
67971da177e4SLinus Torvalds  * Decode RENEW response
67981da177e4SLinus Torvalds  */
6799bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6800bf269551SChuck Lever 			      void *__unused)
68011da177e4SLinus Torvalds {
68021da177e4SLinus Torvalds 	struct compound_hdr hdr;
68031da177e4SLinus Torvalds 	int status;
68041da177e4SLinus Torvalds 
6805bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68061da177e4SLinus Torvalds 	if (!status)
6807bf269551SChuck Lever 		status = decode_renew(xdr);
68081da177e4SLinus Torvalds 	return status;
68091da177e4SLinus Torvalds }
68101da177e4SLinus Torvalds 
68111da177e4SLinus Torvalds /*
68128b173218SRicardo Labiaga  * Decode SETCLIENTID response
68131da177e4SLinus Torvalds  */
6814bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6815bf269551SChuck Lever 				    struct xdr_stream *xdr,
6816bb8b27e5STrond Myklebust 				    struct nfs4_setclientid_res *res)
68171da177e4SLinus Torvalds {
68181da177e4SLinus Torvalds 	struct compound_hdr hdr;
68191da177e4SLinus Torvalds 	int status;
68201da177e4SLinus Torvalds 
6821bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68221da177e4SLinus Torvalds 	if (!status)
6823bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
68241da177e4SLinus Torvalds 	return status;
68251da177e4SLinus Torvalds }
68261da177e4SLinus Torvalds 
68271da177e4SLinus Torvalds /*
68288b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
68291da177e4SLinus Torvalds  */
6830bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
683183ca7f5aSChuck Lever 					    struct xdr_stream *xdr)
68321da177e4SLinus Torvalds {
68331da177e4SLinus Torvalds 	struct compound_hdr hdr;
68341da177e4SLinus Torvalds 	int status;
68351da177e4SLinus Torvalds 
6836bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68371da177e4SLinus Torvalds 	if (!status)
6838bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
68391da177e4SLinus Torvalds 	return status;
68401da177e4SLinus Torvalds }
68411da177e4SLinus Torvalds 
68421da177e4SLinus Torvalds /*
68438b173218SRicardo Labiaga  * Decode DELEGRETURN response
68441da177e4SLinus Torvalds  */
6845bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6846bf269551SChuck Lever 				    struct xdr_stream *xdr,
6847bf269551SChuck Lever 				    struct nfs4_delegreturnres *res)
68481da177e4SLinus Torvalds {
68491da177e4SLinus Torvalds 	struct compound_hdr hdr;
68501da177e4SLinus Torvalds 	int status;
68511da177e4SLinus Torvalds 
6852bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68539b7b9fccSAndy Adamson 	if (status)
68549b7b9fccSAndy Adamson 		goto out;
6855bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68569b7b9fccSAndy Adamson 	if (status)
6857fa178f29STrond Myklebust 		goto out;
6858bf269551SChuck Lever 	status = decode_putfh(xdr);
6859fa178f29STrond Myklebust 	if (status != 0)
6860fa178f29STrond Myklebust 		goto out;
6861e144cbccSTrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
6862556ae3bbSJeff Layton 	if (status != 0)
6863556ae3bbSJeff Layton 		goto out;
6864e144cbccSTrond Myklebust 	status = decode_delegreturn(xdr);
6865fa178f29STrond Myklebust out:
68661da177e4SLinus Torvalds 	return status;
68671da177e4SLinus Torvalds }
68681da177e4SLinus Torvalds 
6869683b57b4STrond Myklebust /*
68708b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6871683b57b4STrond Myklebust  */
6872bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6873bf269551SChuck Lever 				     struct xdr_stream *xdr,
687422958463SBenny Halevy 				     struct nfs4_fs_locations_res *res)
6875683b57b4STrond Myklebust {
6876683b57b4STrond Myklebust 	struct compound_hdr hdr;
6877683b57b4STrond Myklebust 	int status;
6878683b57b4STrond Myklebust 
6879bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68809b7b9fccSAndy Adamson 	if (status)
68819b7b9fccSAndy Adamson 		goto out;
6882bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
68839b7b9fccSAndy Adamson 	if (status)
6884683b57b4STrond Myklebust 		goto out;
6885bf269551SChuck Lever 	status = decode_putfh(xdr);
6886bf269551SChuck Lever 	if (status)
6887683b57b4STrond Myklebust 		goto out;
6888b03d735bSChuck Lever 	if (res->migration) {
6889b03d735bSChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6890b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6891b03d735bSChuck Lever 					&res->fs_locations->fattr,
6892b03d735bSChuck Lever 					 NULL, res->fs_locations,
6893b03d735bSChuck Lever 					 NULL, res->fs_locations->server);
6894b03d735bSChuck Lever 		if (status)
6895b03d735bSChuck Lever 			goto out;
6896b03d735bSChuck Lever 		if (res->renew)
6897b03d735bSChuck Lever 			status = decode_renew(xdr);
6898b03d735bSChuck Lever 	} else {
6899bf269551SChuck Lever 		status = decode_lookup(xdr);
6900bf269551SChuck Lever 		if (status)
6901683b57b4STrond Myklebust 			goto out;
6902bf269551SChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6903b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6904b03d735bSChuck Lever 					&res->fs_locations->fattr,
69058b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
6906aa9c2669SDavid Quigley 					 NULL, res->fs_locations->server);
6907b03d735bSChuck Lever 	}
6908683b57b4STrond Myklebust out:
6909683b57b4STrond Myklebust 	return status;
6910683b57b4STrond Myklebust }
6911683b57b4STrond Myklebust 
69125a5ea0d4SBryan Schumaker /*
69135a5ea0d4SBryan Schumaker  * Decode SECINFO response
69145a5ea0d4SBryan Schumaker  */
69155a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
69165a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
69175a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_res *res)
69185a5ea0d4SBryan Schumaker {
69195a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
69205a5ea0d4SBryan Schumaker 	int status;
69215a5ea0d4SBryan Schumaker 
69225a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69235a5ea0d4SBryan Schumaker 	if (status)
69245a5ea0d4SBryan Schumaker 		goto out;
69255a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69265a5ea0d4SBryan Schumaker 	if (status)
69275a5ea0d4SBryan Schumaker 		goto out;
69285a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
69295a5ea0d4SBryan Schumaker 	if (status)
69305a5ea0d4SBryan Schumaker 		goto out;
69315a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
69325a5ea0d4SBryan Schumaker out:
69335a5ea0d4SBryan Schumaker 	return status;
69345a5ea0d4SBryan Schumaker }
69355a5ea0d4SBryan Schumaker 
693644c99933SChuck Lever /*
693744c99933SChuck Lever  * Decode FSID_PRESENT response
693844c99933SChuck Lever  */
693944c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
694044c99933SChuck Lever 				     struct xdr_stream *xdr,
694144c99933SChuck Lever 				     struct nfs4_fsid_present_res *res)
694244c99933SChuck Lever {
694344c99933SChuck Lever 	struct compound_hdr hdr;
694444c99933SChuck Lever 	int status;
694544c99933SChuck Lever 
694644c99933SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
694744c99933SChuck Lever 	if (status)
694844c99933SChuck Lever 		goto out;
694944c99933SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
695044c99933SChuck Lever 	if (status)
695144c99933SChuck Lever 		goto out;
695244c99933SChuck Lever 	status = decode_putfh(xdr);
695344c99933SChuck Lever 	if (status)
695444c99933SChuck Lever 		goto out;
695544c99933SChuck Lever 	status = decode_getfh(xdr, res->fh);
695644c99933SChuck Lever 	if (status)
695744c99933SChuck Lever 		goto out;
695844c99933SChuck Lever 	if (res->renew)
695944c99933SChuck Lever 		status = decode_renew(xdr);
696044c99933SChuck Lever out:
696144c99933SChuck Lever 	return status;
696244c99933SChuck Lever }
696344c99933SChuck Lever 
696499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
696599fe60d0SBenny Halevy /*
69667c44f1aeSWeston Andros Adamson  * Decode BIND_CONN_TO_SESSION response
69677c44f1aeSWeston Andros Adamson  */
69687c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
69697c44f1aeSWeston Andros Adamson 					struct xdr_stream *xdr,
69707c44f1aeSWeston Andros Adamson 					void *res)
69717c44f1aeSWeston Andros Adamson {
69727c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr;
69737c44f1aeSWeston Andros Adamson 	int status;
69747c44f1aeSWeston Andros Adamson 
69757c44f1aeSWeston Andros Adamson 	status = decode_compound_hdr(xdr, &hdr);
69767c44f1aeSWeston Andros Adamson 	if (!status)
69777c44f1aeSWeston Andros Adamson 		status = decode_bind_conn_to_session(xdr, res);
69787c44f1aeSWeston Andros Adamson 	return status;
69797c44f1aeSWeston Andros Adamson }
69807c44f1aeSWeston Andros Adamson 
69817c44f1aeSWeston Andros Adamson /*
69828b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
698399fe60d0SBenny Halevy  */
6984bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6985bf269551SChuck Lever 				    struct xdr_stream *xdr,
698699fe60d0SBenny Halevy 				    void *res)
698799fe60d0SBenny Halevy {
698899fe60d0SBenny Halevy 	struct compound_hdr hdr;
698999fe60d0SBenny Halevy 	int status;
699099fe60d0SBenny Halevy 
6991bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
699299fe60d0SBenny Halevy 	if (!status)
6993bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
699499fe60d0SBenny Halevy 	return status;
699599fe60d0SBenny Halevy }
69962050f0ccSAndy Adamson 
69972050f0ccSAndy Adamson /*
69988b173218SRicardo Labiaga  * Decode CREATE_SESSION response
6999fc931582SAndy Adamson  */
7000bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7001bf269551SChuck Lever 				       struct xdr_stream *xdr,
7002fc931582SAndy Adamson 				       struct nfs41_create_session_res *res)
7003fc931582SAndy Adamson {
7004fc931582SAndy Adamson 	struct compound_hdr hdr;
7005fc931582SAndy Adamson 	int status;
7006fc931582SAndy Adamson 
7007bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7008fc931582SAndy Adamson 	if (!status)
7009bf269551SChuck Lever 		status = decode_create_session(xdr, res);
7010fc931582SAndy Adamson 	return status;
7011fc931582SAndy Adamson }
7012fc931582SAndy Adamson 
7013fc931582SAndy Adamson /*
70148b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
70150f3e66c6SAndy Adamson  */
7016bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7017bf269551SChuck Lever 					struct xdr_stream *xdr,
7018bf269551SChuck Lever 					void *res)
70190f3e66c6SAndy Adamson {
70200f3e66c6SAndy Adamson 	struct compound_hdr hdr;
70210f3e66c6SAndy Adamson 	int status;
70220f3e66c6SAndy Adamson 
7023bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70240f3e66c6SAndy Adamson 	if (!status)
7025bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
70260f3e66c6SAndy Adamson 	return status;
70270f3e66c6SAndy Adamson }
70280f3e66c6SAndy Adamson 
70290f3e66c6SAndy Adamson /*
703066245539STrond Myklebust  * Decode DESTROY_CLIENTID response
703166245539STrond Myklebust  */
703266245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
703366245539STrond Myklebust 					struct xdr_stream *xdr,
703466245539STrond Myklebust 					void *res)
703566245539STrond Myklebust {
703666245539STrond Myklebust 	struct compound_hdr hdr;
703766245539STrond Myklebust 	int status;
703866245539STrond Myklebust 
703966245539STrond Myklebust 	status = decode_compound_hdr(xdr, &hdr);
704066245539STrond Myklebust 	if (!status)
704166245539STrond Myklebust 		status = decode_destroy_clientid(xdr, res);
704266245539STrond Myklebust 	return status;
704366245539STrond Myklebust }
704466245539STrond Myklebust 
704566245539STrond Myklebust /*
70468b173218SRicardo Labiaga  * Decode SEQUENCE response
7047fc01cea9SAndy Adamson  */
7048bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7049bf269551SChuck Lever 				 struct xdr_stream *xdr,
7050fc01cea9SAndy Adamson 				 struct nfs4_sequence_res *res)
7051fc01cea9SAndy Adamson {
7052fc01cea9SAndy Adamson 	struct compound_hdr hdr;
7053fc01cea9SAndy Adamson 	int status;
7054fc01cea9SAndy Adamson 
7055bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7056fc01cea9SAndy Adamson 	if (!status)
7057bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
7058fc01cea9SAndy Adamson 	return status;
7059fc01cea9SAndy Adamson }
7060fc01cea9SAndy Adamson 
7061fc01cea9SAndy Adamson /*
70628b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
70632050f0ccSAndy Adamson  */
7064bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7065bf269551SChuck Lever 				       struct xdr_stream *xdr,
70662050f0ccSAndy Adamson 				       struct nfs4_get_lease_time_res *res)
70672050f0ccSAndy Adamson {
70682050f0ccSAndy Adamson 	struct compound_hdr hdr;
70692050f0ccSAndy Adamson 	int status;
70702050f0ccSAndy Adamson 
7071bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70722050f0ccSAndy Adamson 	if (!status)
7073bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
70742050f0ccSAndy Adamson 	if (!status)
7075bf269551SChuck Lever 		status = decode_putrootfh(xdr);
70762050f0ccSAndy Adamson 	if (!status)
7077bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
70782050f0ccSAndy Adamson 	return status;
70792050f0ccSAndy Adamson }
708018019753SRicardo Labiaga 
708118019753SRicardo Labiaga /*
708218019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
708318019753SRicardo Labiaga  */
7084bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7085bf269551SChuck Lever 					 struct xdr_stream *xdr,
708618019753SRicardo Labiaga 					 struct nfs41_reclaim_complete_res *res)
708718019753SRicardo Labiaga {
708818019753SRicardo Labiaga 	struct compound_hdr hdr;
708918019753SRicardo Labiaga 	int status;
709018019753SRicardo Labiaga 
7091bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
709218019753SRicardo Labiaga 	if (!status)
7093bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
709418019753SRicardo Labiaga 	if (!status)
70958ee2b78aSHimangi Saraogi 		status = decode_reclaim_complete(xdr, NULL);
709618019753SRicardo Labiaga 	return status;
709718019753SRicardo Labiaga }
7098b1f69b75SAndy Adamson 
7099b1f69b75SAndy Adamson /*
71007f11d8d3SAndy Adamson  * Decode GETDEVICELIST response
71017f11d8d3SAndy Adamson  */
71027f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
71037f11d8d3SAndy Adamson 				      struct xdr_stream *xdr,
71047f11d8d3SAndy Adamson 				      struct nfs4_getdevicelist_res *res)
71057f11d8d3SAndy Adamson {
71067f11d8d3SAndy Adamson 	struct compound_hdr hdr;
71077f11d8d3SAndy Adamson 	int status;
71087f11d8d3SAndy Adamson 
71097f11d8d3SAndy Adamson 	dprintk("encoding getdevicelist!\n");
71107f11d8d3SAndy Adamson 
71117f11d8d3SAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
71127f11d8d3SAndy Adamson 	if (status != 0)
71137f11d8d3SAndy Adamson 		goto out;
71147f11d8d3SAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
71157f11d8d3SAndy Adamson 	if (status != 0)
71167f11d8d3SAndy Adamson 		goto out;
71177f11d8d3SAndy Adamson 	status = decode_putfh(xdr);
71187f11d8d3SAndy Adamson 	if (status != 0)
71197f11d8d3SAndy Adamson 		goto out;
71207f11d8d3SAndy Adamson 	status = decode_getdevicelist(xdr, res->devlist);
71217f11d8d3SAndy Adamson out:
71227f11d8d3SAndy Adamson 	return status;
71237f11d8d3SAndy Adamson }
71247f11d8d3SAndy Adamson 
71257f11d8d3SAndy Adamson /*
7126b1f69b75SAndy Adamson  * Decode GETDEVINFO response
7127b1f69b75SAndy Adamson  */
7128bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7129bf269551SChuck Lever 				      struct xdr_stream *xdr,
7130b1f69b75SAndy Adamson 				      struct nfs4_getdeviceinfo_res *res)
7131b1f69b75SAndy Adamson {
7132b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7133b1f69b75SAndy Adamson 	int status;
7134b1f69b75SAndy Adamson 
7135bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7136b1f69b75SAndy Adamson 	if (status != 0)
7137b1f69b75SAndy Adamson 		goto out;
7138bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7139b1f69b75SAndy Adamson 	if (status != 0)
7140b1f69b75SAndy Adamson 		goto out;
7141bf269551SChuck Lever 	status = decode_getdeviceinfo(xdr, res->pdev);
7142b1f69b75SAndy Adamson out:
7143b1f69b75SAndy Adamson 	return status;
7144b1f69b75SAndy Adamson }
7145b1f69b75SAndy Adamson 
7146b1f69b75SAndy Adamson /*
7147b1f69b75SAndy Adamson  * Decode LAYOUTGET response
7148b1f69b75SAndy Adamson  */
7149bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7150bf269551SChuck Lever 				  struct xdr_stream *xdr,
7151b1f69b75SAndy Adamson 				  struct nfs4_layoutget_res *res)
7152b1f69b75SAndy Adamson {
7153b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7154b1f69b75SAndy Adamson 	int status;
7155b1f69b75SAndy Adamson 
7156bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7157b1f69b75SAndy Adamson 	if (status)
7158b1f69b75SAndy Adamson 		goto out;
7159bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7160b1f69b75SAndy Adamson 	if (status)
7161b1f69b75SAndy Adamson 		goto out;
7162bf269551SChuck Lever 	status = decode_putfh(xdr);
7163b1f69b75SAndy Adamson 	if (status)
7164b1f69b75SAndy Adamson 		goto out;
7165bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
7166b1f69b75SAndy Adamson out:
7167b1f69b75SAndy Adamson 	return status;
7168b1f69b75SAndy Adamson }
7169863a3c6cSAndy Adamson 
7170863a3c6cSAndy Adamson /*
7171cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
7172cbe82603SBenny Halevy  */
7173cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7174cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
7175cbe82603SBenny Halevy 				     struct nfs4_layoutreturn_res *res)
7176cbe82603SBenny Halevy {
7177cbe82603SBenny Halevy 	struct compound_hdr hdr;
7178cbe82603SBenny Halevy 	int status;
7179cbe82603SBenny Halevy 
7180cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
7181cbe82603SBenny Halevy 	if (status)
7182cbe82603SBenny Halevy 		goto out;
7183cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7184cbe82603SBenny Halevy 	if (status)
7185cbe82603SBenny Halevy 		goto out;
7186cbe82603SBenny Halevy 	status = decode_putfh(xdr);
7187cbe82603SBenny Halevy 	if (status)
7188cbe82603SBenny Halevy 		goto out;
7189cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
7190cbe82603SBenny Halevy out:
7191cbe82603SBenny Halevy 	return status;
7192cbe82603SBenny Halevy }
7193cbe82603SBenny Halevy 
7194cbe82603SBenny Halevy /*
7195863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
7196863a3c6cSAndy Adamson  */
7197863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7198863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
7199863a3c6cSAndy Adamson 				     struct nfs4_layoutcommit_res *res)
7200863a3c6cSAndy Adamson {
7201863a3c6cSAndy Adamson 	struct compound_hdr hdr;
7202863a3c6cSAndy Adamson 	int status;
7203863a3c6cSAndy Adamson 
7204863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
7205863a3c6cSAndy Adamson 	if (status)
7206863a3c6cSAndy Adamson 		goto out;
7207863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7208863a3c6cSAndy Adamson 	if (status)
7209863a3c6cSAndy Adamson 		goto out;
7210863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
7211863a3c6cSAndy Adamson 	if (status)
7212863a3c6cSAndy Adamson 		goto out;
7213863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
7214863a3c6cSAndy Adamson 	if (status)
7215863a3c6cSAndy Adamson 		goto out;
72166926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
7217863a3c6cSAndy Adamson out:
7218863a3c6cSAndy Adamson 	return status;
7219863a3c6cSAndy Adamson }
7220fca78d6dSBryan Schumaker 
7221fca78d6dSBryan Schumaker /*
7222fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
7223fca78d6dSBryan Schumaker  */
7224fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7225fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
7226fca78d6dSBryan Schumaker 					struct nfs4_secinfo_res *res)
7227fca78d6dSBryan Schumaker {
7228fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
7229fca78d6dSBryan Schumaker 	int status;
7230fca78d6dSBryan Schumaker 
7231fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
7232fca78d6dSBryan Schumaker 	if (status)
7233fca78d6dSBryan Schumaker 		goto out;
7234fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7235fca78d6dSBryan Schumaker 	if (status)
7236fca78d6dSBryan Schumaker 		goto out;
7237fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
7238fca78d6dSBryan Schumaker 	if (status)
7239fca78d6dSBryan Schumaker 		goto out;
724031e4dda4SBryan Schumaker 	status = decode_secinfo_no_name(xdr, res);
7241fca78d6dSBryan Schumaker out:
7242fca78d6dSBryan Schumaker 	return status;
7243fca78d6dSBryan Schumaker }
72447d974794SBryan Schumaker 
72457d974794SBryan Schumaker /*
72467d974794SBryan Schumaker  * Decode TEST_STATEID response
72477d974794SBryan Schumaker  */
72487d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
72497d974794SBryan Schumaker 				     struct xdr_stream *xdr,
72507d974794SBryan Schumaker 				     struct nfs41_test_stateid_res *res)
72517d974794SBryan Schumaker {
72527d974794SBryan Schumaker 	struct compound_hdr hdr;
72537d974794SBryan Schumaker 	int status;
72547d974794SBryan Schumaker 
72557d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
72567d974794SBryan Schumaker 	if (status)
72577d974794SBryan Schumaker 		goto out;
72587d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
72597d974794SBryan Schumaker 	if (status)
72607d974794SBryan Schumaker 		goto out;
72617d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
72627d974794SBryan Schumaker out:
72637d974794SBryan Schumaker 	return status;
72647d974794SBryan Schumaker }
72659aeda35fSBryan Schumaker 
72669aeda35fSBryan Schumaker /*
72679aeda35fSBryan Schumaker  * Decode FREE_STATEID response
72689aeda35fSBryan Schumaker  */
72699aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
72709aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
72719aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_res *res)
72729aeda35fSBryan Schumaker {
72739aeda35fSBryan Schumaker 	struct compound_hdr hdr;
72749aeda35fSBryan Schumaker 	int status;
72759aeda35fSBryan Schumaker 
72769aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
72779aeda35fSBryan Schumaker 	if (status)
72789aeda35fSBryan Schumaker 		goto out;
72799aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
72809aeda35fSBryan Schumaker 	if (status)
72819aeda35fSBryan Schumaker 		goto out;
72829aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
72839aeda35fSBryan Schumaker out:
72849aeda35fSBryan Schumaker 	return status;
72859aeda35fSBryan Schumaker }
728699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
728799fe60d0SBenny Halevy 
7288573c4e1eSChuck Lever /**
7289573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7290573c4e1eSChuck Lever  *                      the local page cache.
7291573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7292573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7293573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7294573c4e1eSChuck Lever  *
7295573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7296573c4e1eSChuck Lever  * returned.
7297573c4e1eSChuck Lever  *
7298573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7299573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7300573c4e1eSChuck Lever  * on a directory already in our cache.
7301573c4e1eSChuck Lever  */
7302573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7303573c4e1eSChuck Lever 		       int plus)
73041da177e4SLinus Torvalds {
7305256e48bbSTrond Myklebust 	unsigned int savep;
7306dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
73071da177e4SLinus Torvalds 	uint32_t len;
7308babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7309babddc72SBryan Schumaker 	if (unlikely(!p))
7310babddc72SBryan Schumaker 		goto out_overflow;
7311c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7312babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7313babddc72SBryan Schumaker 		if (unlikely(!p))
7314babddc72SBryan Schumaker 			goto out_overflow;
7315c08e76d0SChuck Lever 		if (*p == xdr_zero)
7316573c4e1eSChuck Lever 			return -EAGAIN;
73171da177e4SLinus Torvalds 		entry->eof = 1;
7318573c4e1eSChuck Lever 		return -EBADCOOKIE;
73191da177e4SLinus Torvalds 	}
73201da177e4SLinus Torvalds 
7321babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7322babddc72SBryan Schumaker 	if (unlikely(!p))
7323babddc72SBryan Schumaker 		goto out_overflow;
73241da177e4SLinus Torvalds 	entry->prev_cookie = entry->cookie;
73251da177e4SLinus Torvalds 	p = xdr_decode_hyper(p, &entry->cookie);
7326c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7327babddc72SBryan Schumaker 
73289af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7329babddc72SBryan Schumaker 	if (unlikely(!p))
7330babddc72SBryan Schumaker 		goto out_overflow;
73311da177e4SLinus Torvalds 	entry->name = (const char *) p;
73321da177e4SLinus Torvalds 
73331da177e4SLinus Torvalds 	/*
73341da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
73351da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
73361da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
73371da177e4SLinus Torvalds 	 */
73381da177e4SLinus Torvalds 	entry->ino = 1;
73394f082222STrond Myklebust 	entry->fattr->valid = 0;
73401da177e4SLinus Torvalds 
73419af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7342babddc72SBryan Schumaker 		goto out_overflow;
73439af8c222STrond Myklebust 
7344256e48bbSTrond Myklebust 	if (decode_attr_length(xdr, &len, &savep) < 0)
7345babddc72SBryan Schumaker 		goto out_overflow;
73469af8c222STrond Myklebust 
7347573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7348aa9c2669SDavid Quigley 			NULL, entry->label, entry->server) < 0)
7349babddc72SBryan Schumaker 		goto out_overflow;
735028331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
735128331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
735228331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
735382f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
73549af8c222STrond Myklebust 
73550b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
73560b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
73570b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
73580b26a0bfSTrond Myklebust 
7359573c4e1eSChuck Lever 	return 0;
7360babddc72SBryan Schumaker 
7361babddc72SBryan Schumaker out_overflow:
7362babddc72SBryan Schumaker 	print_overflow_msg(__func__, xdr);
7363573c4e1eSChuck Lever 	return -EAGAIN;
73641da177e4SLinus Torvalds }
73651da177e4SLinus Torvalds 
73661da177e4SLinus Torvalds /*
73671da177e4SLinus Torvalds  * We need to translate between nfs status return values and
73681da177e4SLinus Torvalds  * the local errno values which may not be the same.
73691da177e4SLinus Torvalds  */
73701da177e4SLinus Torvalds static struct {
73711da177e4SLinus Torvalds 	int stat;
73721da177e4SLinus Torvalds 	int errno;
73731da177e4SLinus Torvalds } nfs_errtbl[] = {
73741da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7375856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7376856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7377856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7378856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7379856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7380856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7381856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7382856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7383856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7384856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7385856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7386856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7387856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7388856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7389856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7390856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7391856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7392856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7393856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7394856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7395856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7396856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7397fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7398856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7399856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7400856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7401856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7402856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7403856dff3dSBenny Halevy 	{ -1,			-EIO		}
74041da177e4SLinus Torvalds };
74051da177e4SLinus Torvalds 
74061da177e4SLinus Torvalds /*
74071da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
74081da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
74091da177e4SLinus Torvalds  */
74101da177e4SLinus Torvalds static int
74110a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
74121da177e4SLinus Torvalds {
74131da177e4SLinus Torvalds 	int i;
74141da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
74151da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
74161da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
74171da177e4SLinus Torvalds 	}
74181da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
74191da177e4SLinus Torvalds 		/* The server is looney tunes. */
7420fdcb4577STrond Myklebust 		return -EREMOTEIO;
74211da177e4SLinus Torvalds 	}
74221da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
74231da177e4SLinus Torvalds 	 * handle it.
74241da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
74251da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
74261da177e4SLinus Torvalds 	 */
7427856dff3dSBenny Halevy 	return -stat;
74281da177e4SLinus Torvalds }
74291da177e4SLinus Torvalds 
74301da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
74311da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
74321da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
74339f06c719SChuck Lever 	.p_encode = (kxdreproc_t)nfs4_xdr_##argtype,		\
7434bf269551SChuck Lever 	.p_decode = (kxdrdproc_t)nfs4_xdr_##restype,		\
74352bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
74362bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7437cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7438cc0175c1SChuck Lever 	.p_name   = #proc,					\
74391da177e4SLinus Torvalds }
74401da177e4SLinus Torvalds 
74411da177e4SLinus Torvalds struct rpc_procinfo	nfs4_procedures[] = {
74421da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
74431da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
74441da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
74451da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
74461da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
74471da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
74481da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
74491da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
74501da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
74511da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
74521da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
74531da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
74541da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
74551da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
74561da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
74571da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
74581da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
74591da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
74601da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
74611da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
74621da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
74631da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
74641da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
74651da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
74661da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
74671da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
74681da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
74691da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
74701da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
74711da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
74721da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7473029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
747423ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7475683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7476d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
74775a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
747844c99933SChuck Lever 	PROC(FSID_PRESENT,	enc_fsid_present,	dec_fsid_present),
747999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
748099fe60d0SBenny Halevy 	PROC(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
7481fc931582SAndy Adamson 	PROC(CREATE_SESSION,	enc_create_session,	dec_create_session),
74820f3e66c6SAndy Adamson 	PROC(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
7483fc01cea9SAndy Adamson 	PROC(SEQUENCE,		enc_sequence,		dec_sequence),
74842050f0ccSAndy Adamson 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
748518019753SRicardo Labiaga 	PROC(RECLAIM_COMPLETE,	enc_reclaim_complete,	dec_reclaim_complete),
7486b1f69b75SAndy Adamson 	PROC(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
7487b1f69b75SAndy Adamson 	PROC(LAYOUTGET,		enc_layoutget,		dec_layoutget),
7488863a3c6cSAndy Adamson 	PROC(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
7489cbe82603SBenny Halevy 	PROC(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
7490fca78d6dSBryan Schumaker 	PROC(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
74917d974794SBryan Schumaker 	PROC(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
74929aeda35fSBryan Schumaker 	PROC(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
74937f11d8d3SAndy Adamson 	PROC(GETDEVICELIST,	enc_getdevicelist,	dec_getdevicelist),
7494ad24ecfbSTrond Myklebust 	PROC(BIND_CONN_TO_SESSION,
7495ad24ecfbSTrond Myklebust 			enc_bind_conn_to_session, dec_bind_conn_to_session),
749666245539STrond Myklebust 	PROC(DESTROY_CLIENTID,	enc_destroy_clientid,	dec_destroy_clientid),
749799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
74981da177e4SLinus Torvalds };
74991da177e4SLinus Torvalds 
7500a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
75011da177e4SLinus Torvalds 	.number			= 4,
7502e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
75031da177e4SLinus Torvalds 	.procs			= nfs4_procedures
75041da177e4SLinus Torvalds };
75051da177e4SLinus Torvalds 
75061da177e4SLinus Torvalds /*
75071da177e4SLinus Torvalds  * Local variables:
75081da177e4SLinus Torvalds  *  c-basic-offset: 8
75091da177e4SLinus Torvalds  * End:
75101da177e4SLinus Torvalds  */
7511