xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision 36b3743f)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  fs/nfs/nfs4xdr.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Client-side XDR for NFSv4.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  Copyright (c) 2002 The Regents of the University of Michigan.
71da177e4SLinus Torvalds  *  All rights reserved.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  *  Kendrick Smith <kmsmith@umich.edu>
101da177e4SLinus Torvalds  *  Andy Adamson   <andros@umich.edu>
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *  Redistribution and use in source and binary forms, with or without
131da177e4SLinus Torvalds  *  modification, are permitted provided that the following conditions
141da177e4SLinus Torvalds  *  are met:
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  *  1. Redistributions of source code must retain the above copyright
171da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer.
181da177e4SLinus Torvalds  *  2. Redistributions in binary form must reproduce the above copyright
191da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer in the
201da177e4SLinus Torvalds  *     documentation and/or other materials provided with the distribution.
211da177e4SLinus Torvalds  *  3. Neither the name of the University nor the names of its
221da177e4SLinus Torvalds  *     contributors may be used to endorse or promote products derived
231da177e4SLinus Torvalds  *     from this software without specific prior written permission.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
261da177e4SLinus Torvalds  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
271da177e4SLinus Torvalds  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
281da177e4SLinus Torvalds  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291da177e4SLinus Torvalds  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301da177e4SLinus Torvalds  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311da177e4SLinus Torvalds  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
321da177e4SLinus Torvalds  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
331da177e4SLinus Torvalds  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
341da177e4SLinus Torvalds  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
351da177e4SLinus Torvalds  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361da177e4SLinus Torvalds  */
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #include <linux/param.h>
391da177e4SLinus Torvalds #include <linux/time.h>
401da177e4SLinus Torvalds #include <linux/mm.h>
411da177e4SLinus Torvalds #include <linux/errno.h>
421da177e4SLinus Torvalds #include <linux/string.h>
431da177e4SLinus Torvalds #include <linux/in.h>
441da177e4SLinus Torvalds #include <linux/pagemap.h>
451da177e4SLinus Torvalds #include <linux/proc_fs.h>
461da177e4SLinus Torvalds #include <linux/kdev_t.h>
47db8ac8baSWeston Andros Adamson #include <linux/module.h>
48db8ac8baSWeston Andros Adamson #include <linux/utsname.h>
491da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h>
502449ea2eSAlexandros Batsakis #include <linux/sunrpc/msg_prot.h>
515a5ea0d4SBryan Schumaker #include <linux/sunrpc/gss_api.h>
521da177e4SLinus Torvalds #include <linux/nfs.h>
531da177e4SLinus Torvalds #include <linux/nfs4.h>
541da177e4SLinus Torvalds #include <linux/nfs_fs.h>
55dff25ddbSAndreas Gruenbacher #include <linux/fs_struct.h>
56f092075dSChuck Lever 
574ce79717STrond Myklebust #include "nfs4_fs.h"
584882ef72SAlexandros Batsakis #include "internal.h"
5940c64c26SAnna Schumaker #include "nfs4idmap.h"
6076e697baSTrond Myklebust #include "nfs4session.h"
61b1f69b75SAndy Adamson #include "pnfs.h"
62f092075dSChuck Lever #include "netns.h"
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_XDR
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
671da177e4SLinus Torvalds #define errno_NFSERR_IO		EIO
681da177e4SLinus Torvalds 
690a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
721da177e4SLinus Torvalds #ifdef DEBUG
731da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		20
741da177e4SLinus Torvalds #else
751da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		0
761da177e4SLinus Torvalds #endif
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds /* lock,open owner id:
799f958ab8STrond Myklebust  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
801da177e4SLinus Torvalds  */
8195b72eb0STrond Myklebust #define open_owner_id_maxsz	(1 + 2 + 1 + 1 + 2)
82d035c36cSTrond Myklebust #define lock_owner_id_maxsz	(1 + 1 + 4)
839104a55dSTrond Myklebust #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
841da177e4SLinus Torvalds #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
851da177e4SLinus Torvalds #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
861da177e4SLinus Torvalds #define op_encode_hdr_maxsz	(1)
871da177e4SLinus Torvalds #define op_decode_hdr_maxsz	(2)
889104a55dSTrond Myklebust #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
899104a55dSTrond Myklebust #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
909104a55dSTrond Myklebust #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
919104a55dSTrond Myklebust #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
921da177e4SLinus Torvalds #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
931da177e4SLinus Torvalds 				(NFS4_FHSIZE >> 2))
941da177e4SLinus Torvalds #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
951da177e4SLinus Torvalds #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
961da177e4SLinus Torvalds #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
971da177e4SLinus Torvalds #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
981da177e4SLinus Torvalds #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
991da177e4SLinus Torvalds 				((3+NFS4_FHSIZE) >> 2))
100e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
10196928206SJ. Bruce Fields #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
10236b3743fSTrond Myklebust #define nfstime4_maxsz		(3)
1031da177e4SLinus Torvalds #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
1041da177e4SLinus Torvalds #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
105bd625ba8STrond Myklebust #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
106bd625ba8STrond Myklebust #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
107aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL
108aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
109aa9c2669SDavid Quigley #define	nfs4_label_maxsz	(4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
110aa9c2669SDavid Quigley #else
111aa9c2669SDavid Quigley #define	nfs4_label_maxsz	0
112aa9c2669SDavid Quigley #endif
11388034c3dSAndy Adamson /* We support only one layout type per file system */
11488034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
11596928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
11696928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
11736b3743fSTrond Myklebust 				3*nfstime4_maxsz + \
11836b3743fSTrond Myklebust 				nfs4_owner_maxsz + \
119aa9c2669SDavid Quigley 				nfs4_group_maxsz + nfs4_label_maxsz + \
120aa9c2669SDavid Quigley 				 decode_mdsthreshold_maxsz))
12196928206SJ. Bruce Fields #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
12296928206SJ. Bruce Fields 				nfs4_fattr_value_maxsz)
12396928206SJ. Bruce Fields #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1249104a55dSTrond Myklebust #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
1259104a55dSTrond Myklebust 				 1 + 2 + 1 + \
1269104a55dSTrond Myklebust 				nfs4_owner_maxsz + \
1279104a55dSTrond Myklebust 				nfs4_group_maxsz + \
128aa9c2669SDavid Quigley 				nfs4_label_maxsz + \
12936b3743fSTrond Myklebust 				1 + nfstime4_maxsz + \
13036b3743fSTrond Myklebust 				1 + nfstime4_maxsz)
1311da177e4SLinus Torvalds #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
1321da177e4SLinus Torvalds #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
13356ae19f3STrond Myklebust #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
13456ae19f3STrond Myklebust #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
1352f42b5d0SFred Isaman #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
136dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
137dae100c2SFred Isaman  * layout types will be returned.
138dae100c2SFred Isaman  */
139dae100c2SFred Isaman #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
140dae100c2SFred Isaman 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1411da177e4SLinus Torvalds #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
1421da177e4SLinus Torvalds #define decode_renew_maxsz	(op_decode_hdr_maxsz)
1431da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1441da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
145cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
146b8fb2f59SJeff Layton 				/* client name */ \
147b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
148cc38bac3SChuck Lever 				1 /* sc_prog */ + \
1496dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1506dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
151cc38bac3SChuck Lever 				1) /* sc_cb_ident */
1521da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1531da177e4SLinus Torvalds 				(op_decode_hdr_maxsz + \
1546dd3436bSChuck Lever 				2 /* clientid */ + \
1556dd3436bSChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
1566dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1576dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
1581da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1591da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
1601da177e4SLinus Torvalds 				3 + (NFS4_VERIFIER_SIZE >> 2))
1611da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1621da177e4SLinus Torvalds 				(op_decode_hdr_maxsz)
163e6889620STrond Myklebust #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
164e6889620STrond Myklebust #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
1655b5faaf6SJeff Layton #define encode_lookupp_maxsz	(op_encode_hdr_maxsz)
1665b5faaf6SJeff Layton #define decode_lookupp_maxsz	(op_decode_hdr_maxsz)
1672cebf828STrond Myklebust #define encode_share_access_maxsz \
1682cebf828STrond Myklebust 				(2)
1694882ef72SAlexandros Batsakis #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
1702cebf828STrond Myklebust #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
1712cebf828STrond Myklebust #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
1722cebf828STrond Myklebust #define encode_open_maxsz	(op_encode_hdr_maxsz + \
1732cebf828STrond Myklebust 				2 + encode_share_access_maxsz + 2 + \
1742cebf828STrond Myklebust 				open_owner_id_maxsz + \
1752cebf828STrond Myklebust 				encode_opentype_maxsz + \
1762cebf828STrond Myklebust 				encode_claim_null_maxsz)
1775a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz	(3)
1782cebf828STrond Myklebust #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
1799104a55dSTrond Myklebust #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
1805a1f6d9eSTrond Myklebust 				decode_space_limit_maxsz + \
1812cebf828STrond Myklebust 				decode_ace_maxsz)
1822cebf828STrond Myklebust #define decode_change_info_maxsz	(5)
1832cebf828STrond Myklebust #define decode_open_maxsz	(op_decode_hdr_maxsz + \
1849104a55dSTrond Myklebust 				decode_stateid_maxsz + \
1852cebf828STrond Myklebust 				decode_change_info_maxsz + 1 + \
1862cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz + \
1872cebf828STrond Myklebust 				decode_delegation_maxsz)
1889104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
1899104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1909104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1)
1919104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
1929104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1939104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1949104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
1959104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1969104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1 + \
1979104a55dSTrond Myklebust 				 encode_share_access_maxsz)
1989104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
1999104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
2009104a55dSTrond Myklebust 				 decode_stateid_maxsz)
2019104a55dSTrond Myklebust #define encode_close_maxsz	(op_encode_hdr_maxsz + \
2029104a55dSTrond Myklebust 				 1 + encode_stateid_maxsz)
2039104a55dSTrond Myklebust #define decode_close_maxsz	(op_decode_hdr_maxsz + \
2049104a55dSTrond Myklebust 				 decode_stateid_maxsz)
2059104a55dSTrond Myklebust #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
2069104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2079104a55dSTrond Myklebust 				 encode_attrs_maxsz)
2089104a55dSTrond Myklebust #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
2099104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz)
2109104a55dSTrond Myklebust #define encode_read_maxsz	(op_encode_hdr_maxsz + \
2119104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2129104a55dSTrond Myklebust #define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
2139104a55dSTrond Myklebust #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
214aa9c2669SDavid Quigley 				 2 + encode_verifier_maxsz + 5 + \
215aa9c2669SDavid Quigley 				nfs4_label_maxsz)
2169104a55dSTrond Myklebust #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
217a7697f6fSChuck Lever 				 decode_verifier_maxsz)
2189104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
2199104a55dSTrond Myklebust #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
2209104a55dSTrond Myklebust #define encode_write_maxsz	(op_encode_hdr_maxsz + \
2219104a55dSTrond Myklebust 				 encode_stateid_maxsz + 4)
2229104a55dSTrond Myklebust #define decode_write_maxsz	(op_decode_hdr_maxsz + \
2239104a55dSTrond Myklebust 				 2 + decode_verifier_maxsz)
2249104a55dSTrond Myklebust #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
2259104a55dSTrond Myklebust #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
2269104a55dSTrond Myklebust 				 decode_verifier_maxsz)
2271da177e4SLinus Torvalds #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
2281da177e4SLinus Torvalds 				nfs4_name_maxsz)
2296ce18391SBenny Halevy #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
2306ce18391SBenny Halevy 				 decode_change_info_maxsz)
2311da177e4SLinus Torvalds #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
2321da177e4SLinus Torvalds 				2 * nfs4_name_maxsz)
2336ce18391SBenny Halevy #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
2346ce18391SBenny Halevy 				 decode_change_info_maxsz + \
2356ce18391SBenny Halevy 				 decode_change_info_maxsz)
2361da177e4SLinus Torvalds #define encode_link_maxsz	(op_encode_hdr_maxsz + \
2371da177e4SLinus Torvalds 				nfs4_name_maxsz)
2386ce18391SBenny Halevy #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
239daccbdedSTrond Myklebust #define encode_lockowner_maxsz	(7)
2409104a55dSTrond Myklebust #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
2419104a55dSTrond Myklebust 				 7 + \
242daccbdedSTrond Myklebust 				 1 + encode_stateid_maxsz + 1 + \
243daccbdedSTrond Myklebust 				 encode_lockowner_maxsz)
2449104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2459104a55dSTrond Myklebust 				(8 + decode_lockowner_maxsz)
2469104a55dSTrond Myklebust #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
2479104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
248daccbdedSTrond Myklebust #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
249daccbdedSTrond Myklebust 				encode_lockowner_maxsz)
2509104a55dSTrond Myklebust #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
2519104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
2529104a55dSTrond Myklebust #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
2539104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2549104a55dSTrond Myklebust 				 4)
2559104a55dSTrond Myklebust #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
2569104a55dSTrond Myklebust 				 decode_stateid_maxsz)
257d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
258d3c7b7ccSTrond Myklebust 				(op_encode_hdr_maxsz + \
259d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
260d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
261d3c7b7ccSTrond Myklebust 				(op_decode_hdr_maxsz)
2629104a55dSTrond Myklebust #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
2639104a55dSTrond Myklebust #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
2641da177e4SLinus Torvalds #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
2651da177e4SLinus Torvalds 				1 + nfs4_name_maxsz + \
26694a6d753SChuck Lever 				1 + \
26796928206SJ. Bruce Fields 				nfs4_fattr_maxsz)
2681da177e4SLinus Torvalds #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
2691da177e4SLinus Torvalds #define encode_create_maxsz	(op_encode_hdr_maxsz + \
2709104a55dSTrond Myklebust 				1 + 2 + nfs4_name_maxsz + \
2719104a55dSTrond Myklebust 				encode_attrs_maxsz)
2722cebf828STrond Myklebust #define decode_create_maxsz	(op_decode_hdr_maxsz + \
2732cebf828STrond Myklebust 				decode_change_info_maxsz + \
2742cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz)
2759104a55dSTrond Myklebust #define encode_statfs_maxsz	(encode_getattr_maxsz)
2769104a55dSTrond Myklebust #define decode_statfs_maxsz	(decode_getattr_maxsz)
2771da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2781da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2799104a55dSTrond Myklebust #define encode_getacl_maxsz	(encode_getattr_maxsz)
2809104a55dSTrond Myklebust #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
2819104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz + 1)
2829104a55dSTrond Myklebust #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
2839104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2849104a55dSTrond Myklebust #define decode_setacl_maxsz	(decode_setattr_maxsz)
285e6889620STrond Myklebust #define encode_fs_locations_maxsz \
286e6889620STrond Myklebust 				(encode_getattr_maxsz)
287e6889620STrond Myklebust #define decode_fs_locations_maxsz \
288e6889620STrond Myklebust 				(0)
2895a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
2901650add2SBryan Schumaker #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
2919b7b9fccSAndy Adamson 
2929b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
293fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
294d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
295d751f748SJim Rees 			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
296fc931582SAndy Adamson 
29799fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
29899fe60d0SBenny Halevy 				encode_verifier_maxsz + \
29999fe60d0SBenny Halevy 				1 /* co_ownerid.len */ + \
300b8fb2f59SJeff Layton 				/* eia_clientowner */ \
301b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
30299fe60d0SBenny Halevy 				1 /* flags */ + \
30399fe60d0SBenny Halevy 				1 /* spa_how */ + \
3042031cd1aSWeston Andros Adamson 				/* max is SP4_MACH_CRED (for now) */ + \
3052031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
3062031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
307db8ac8baSWeston Andros Adamson 				1 /* implementation id array of size 1 */ + \
308db8ac8baSWeston Andros Adamson 				1 /* nii_domain */ + \
309db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
310db8ac8baSWeston Andros Adamson 				1 /* nii_name */ + \
311d751f748SJim Rees 				XDR_QUADLEN(IMPL_NAME_LIMIT) + \
312db8ac8baSWeston Andros Adamson 				3 /* nii_date */)
31399fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
31499fe60d0SBenny Halevy 				2 /* eir_clientid */ + \
31599fe60d0SBenny Halevy 				1 /* eir_sequenceid */ + \
31699fe60d0SBenny Halevy 				1 /* eir_flags */ + \
31799fe60d0SBenny Halevy 				1 /* spr_how */ + \
3182031cd1aSWeston Andros Adamson 				  /* max is SP4_MACH_CRED (for now) */ + \
3192031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
3202031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
32199fe60d0SBenny Halevy 				2 /* eir_server_owner.so_minor_id */ + \
32299fe60d0SBenny Halevy 				/* eir_server_owner.so_major_id<> */ \
32399fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
32499fe60d0SBenny Halevy 				/* eir_server_scope<> */ \
32599fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
32699fe60d0SBenny Halevy 				1 /* eir_server_impl_id array length */ + \
3277d2ed9acSWeston Andros Adamson 				1 /* nii_domain */ + \
3287d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3297d2ed9acSWeston Andros Adamson 				1 /* nii_name */ + \
3307d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3317d2ed9acSWeston Andros Adamson 				3 /* nii_date */)
332fc931582SAndy Adamson #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
333fc931582SAndy Adamson #define decode_channel_attrs_maxsz  (6 + \
334fc931582SAndy Adamson 				     1 /* ca_rdma_ird.len */ + \
335fc931582SAndy Adamson 				     1 /* ca_rdma_ird */)
336fc931582SAndy Adamson #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
337fc931582SAndy Adamson 				     2 /* csa_clientid */ + \
338fc931582SAndy Adamson 				     1 /* csa_sequence */ + \
339fc931582SAndy Adamson 				     1 /* csa_flags */ + \
340fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
341fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
342fc931582SAndy Adamson 				     1 /* csa_cb_program */ + \
343fc931582SAndy Adamson 				     1 /* csa_sec_parms.len (1) */ + \
344fc931582SAndy Adamson 				     1 /* cb_secflavor (AUTH_SYS) */ + \
345fc931582SAndy Adamson 				     1 /* stamp */ + \
346fc931582SAndy Adamson 				     1 /* machinename.len */ + \
347fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
348fc931582SAndy Adamson 				     1 /* uid */ + \
349fc931582SAndy Adamson 				     1 /* gid */ + \
350fc931582SAndy Adamson 				     1 /* gids.len (0) */)
351fc931582SAndy Adamson #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
352fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353fc931582SAndy Adamson 				     1 /* csr_sequence */ + \
354fc931582SAndy Adamson 				     1 /* csr_flags */ + \
355fc931582SAndy Adamson 				     decode_channel_attrs_maxsz + \
356fc931582SAndy Adamson 				     decode_channel_attrs_maxsz)
3577c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
3587c44f1aeSWeston Andros Adamson 				     /* bctsa_sessid */ \
3597c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3607c44f1aeSWeston Andros Adamson 				     1 /* bctsa_dir */ + \
3617c44f1aeSWeston Andros Adamson 				     1 /* bctsa_use_conn_in_rdma_mode */)
3627c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +	\
3637c44f1aeSWeston Andros Adamson 				     /* bctsr_sessid */ \
3647c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3657c44f1aeSWeston Andros Adamson 				     1 /* bctsr_dir */ + \
3667c44f1aeSWeston Andros Adamson 				     1 /* bctsr_use_conn_in_rdma_mode */)
3670f3e66c6SAndy Adamson #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
3680f3e66c6SAndy Adamson #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
36966245539STrond Myklebust #define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
37066245539STrond Myklebust #define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
371fc01cea9SAndy Adamson #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
372fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
373fc01cea9SAndy Adamson #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
374fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
37518019753SRicardo Labiaga #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
37618019753SRicardo Labiaga #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
37784c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
37884c9dee3SChristoph Hellwig 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
37984c9dee3SChristoph Hellwig 				1 /* layout type */ + \
38084c9dee3SChristoph Hellwig 				1 /* maxcount */ + \
38184c9dee3SChristoph Hellwig 				1 /* bitmap size */ + \
38284c9dee3SChristoph Hellwig 				1 /* notification bitmap length */ + \
38384c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
384b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
385b1f69b75SAndy Adamson 				1 /* layout type */ + \
386b1f69b75SAndy Adamson 				1 /* opaque devaddr4 length */ + \
387b1f69b75SAndy Adamson 				  /* devaddr4 payload is read into page */ \
388b1f69b75SAndy Adamson 				1 /* notification bitmap length */ + \
38984c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
390b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
391b1f69b75SAndy Adamson 				encode_stateid_maxsz)
392b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
393b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
394b1f69b75SAndy Adamson 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
395863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
396863a3c6cSAndy Adamson 				2 /* offset */ + \
397863a3c6cSAndy Adamson 				2 /* length */ + \
398863a3c6cSAndy Adamson 				1 /* reclaim */ + \
399863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
400863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
401863a3c6cSAndy Adamson 				2 /* last byte written */ + \
402863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
403863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
4045f919c9fSChristoph Hellwig 				1 /* layoutupdate4 opaqueue len */)
4055f919c9fSChristoph Hellwig 				  /* the actual content of layoutupdate4 should
4065f919c9fSChristoph Hellwig 				     be allocated by drivers and spliced in
4075f919c9fSChristoph Hellwig 				     using xdr_write_pages */
408863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
409cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
410cbe82603SBenny Halevy 				encode_stateid_maxsz + \
4116669cb8bSTrond Myklebust 				1 + \
4126669cb8bSTrond Myklebust 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
413cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
414cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
415fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
416fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
4177d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
4187d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4197d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
4209aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
4219aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4229f79fb48SAndy Adamson #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz)
4239b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
4249b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
4259b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
426cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0
427cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0
4289b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4299b7b9fccSAndy Adamson 
4301da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
4311da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
4321da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
4339b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4341da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4359104a55dSTrond Myklebust 				encode_read_maxsz)
4361da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
4379b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4381da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4399104a55dSTrond Myklebust 				decode_read_maxsz)
4401da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
4419b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4421da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4439104a55dSTrond Myklebust 				encode_readlink_maxsz)
4441da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4459b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4461da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4479104a55dSTrond Myklebust 				decode_readlink_maxsz)
4481da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4499b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4501da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4519104a55dSTrond Myklebust 				encode_readdir_maxsz)
4521da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4539b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4541da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4559104a55dSTrond Myklebust 				decode_readdir_maxsz)
4561da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4579b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4581da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4599104a55dSTrond Myklebust 				encode_write_maxsz + \
4604f9838c7STrond Myklebust 				encode_getattr_maxsz)
4611da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4629b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4631da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4649104a55dSTrond Myklebust 				decode_write_maxsz + \
4654f9838c7STrond Myklebust 				decode_getattr_maxsz)
4661da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4679b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4681da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4698582715eSTrond Myklebust 				encode_commit_maxsz)
4701da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4719b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4721da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4738582715eSTrond Myklebust 				decode_commit_maxsz)
4741da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4759b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4761da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4772cebf828STrond Myklebust 				encode_open_maxsz + \
4786168f62cSWeston Andros Adamson 				encode_access_maxsz + \
4792cebf828STrond Myklebust 				encode_getfh_maxsz + \
4802cebf828STrond Myklebust 				encode_getattr_maxsz)
4811da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4829b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4831da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4842cebf828STrond Myklebust 				decode_open_maxsz + \
4856168f62cSWeston Andros Adamson 				decode_access_maxsz + \
4862cebf828STrond Myklebust 				decode_getfh_maxsz + \
4872cebf828STrond Myklebust 				decode_getattr_maxsz)
4881da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
4891da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4901da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4919104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
4929104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
4939104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
4941da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4959104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
4961da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
4979b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
4981da177e4SLinus Torvalds 					encode_putfh_maxsz + \
4992cebf828STrond Myklebust 					encode_open_maxsz + \
5006168f62cSWeston Andros Adamson 					encode_access_maxsz + \
5012cebf828STrond Myklebust 					encode_getattr_maxsz)
5021da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
5039b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
5041da177e4SLinus Torvalds 					decode_putfh_maxsz + \
5052cebf828STrond Myklebust 					decode_open_maxsz + \
5066168f62cSWeston Andros Adamson 					decode_access_maxsz + \
5072cebf828STrond Myklebust 					decode_getattr_maxsz)
5081da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
5091da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5109b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5111da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
512b6808145STrond Myklebust 				 encode_layoutreturn_maxsz + \
5133947b74dSTrond Myklebust 				 encode_open_downgrade_maxsz)
5141da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
5151da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5169b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5171da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
518b6808145STrond Myklebust 				 decode_layoutreturn_maxsz + \
5193947b74dSTrond Myklebust 				 decode_open_downgrade_maxsz)
5201da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
5219b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5221da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
523cf805165STrond Myklebust 				 encode_layoutreturn_maxsz + \
5249104a55dSTrond Myklebust 				 encode_close_maxsz + \
525516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5261da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
5279b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5281da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
529cf805165STrond Myklebust 				 decode_layoutreturn_maxsz + \
5309104a55dSTrond Myklebust 				 decode_close_maxsz + \
531516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5321da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
5339b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5341da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5359104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
5361da177e4SLinus Torvalds 				 encode_getattr_maxsz)
5371da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
5389b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5391da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5409104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
5419104a55dSTrond Myklebust 				 decode_getattr_maxsz)
5421da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5439b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5441da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5451da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5461da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5479b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5481da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5491da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5501da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5511da177e4SLinus Torvalds 				encode_renew_maxsz)
5521da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5531da177e4SLinus Torvalds 				decode_renew_maxsz)
5541da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5551da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5561da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5571da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5581da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5591da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
56083ca7f5aSChuck Lever 				encode_setclientid_confirm_maxsz)
5611da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5621da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
56383ca7f5aSChuck Lever 				decode_setclientid_confirm_maxsz)
5641da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5659b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5661da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5679104a55dSTrond Myklebust 				encode_lock_maxsz)
5681da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5699b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5701da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5719104a55dSTrond Myklebust 				decode_lock_maxsz)
5721da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5739b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5741da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5759104a55dSTrond Myklebust 				encode_lockt_maxsz)
5769104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5779b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5789104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5799104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5801da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5819b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5821da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5839104a55dSTrond Myklebust 				encode_locku_maxsz)
5841da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5859b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5861da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5879104a55dSTrond Myklebust 				decode_locku_maxsz)
588d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
589d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
590d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
591d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
592d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
593d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
5941da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
5959b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5961da177e4SLinus Torvalds 				encode_putfh_maxsz + \
59776b32999STrond Myklebust 				encode_access_maxsz + \
59876b32999STrond Myklebust 				encode_getattr_maxsz)
5991da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
6009b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6011da177e4SLinus Torvalds 				decode_putfh_maxsz + \
60276b32999STrond Myklebust 				decode_access_maxsz + \
60376b32999STrond Myklebust 				decode_getattr_maxsz)
6041da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
6059b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6061da177e4SLinus Torvalds 				encode_putfh_maxsz + \
60744c99933SChuck Lever 				encode_getattr_maxsz + \
60844c99933SChuck Lever 				encode_renew_maxsz)
6091da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
6109b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6111da177e4SLinus Torvalds 				decode_putfh_maxsz + \
61244c99933SChuck Lever 				decode_getattr_maxsz + \
61344c99933SChuck Lever 				decode_renew_maxsz)
6141da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
6159b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6161da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6171da177e4SLinus Torvalds 				encode_lookup_maxsz + \
6181da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6191da177e4SLinus Torvalds 				encode_getfh_maxsz)
6201da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
6219b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6221da177e4SLinus Torvalds 				decode_putfh_maxsz + \
623e6889620STrond Myklebust 				decode_lookup_maxsz + \
6241da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6251da177e4SLinus Torvalds 				decode_getfh_maxsz)
6265b5faaf6SJeff Layton #define NFS4_enc_lookupp_sz	(compound_encode_hdr_maxsz + \
6275b5faaf6SJeff Layton 				encode_sequence_maxsz + \
6285b5faaf6SJeff Layton 				encode_putfh_maxsz + \
6295b5faaf6SJeff Layton 				encode_lookupp_maxsz + \
6305b5faaf6SJeff Layton 				encode_getattr_maxsz + \
6315b5faaf6SJeff Layton 				encode_getfh_maxsz)
6325b5faaf6SJeff Layton #define NFS4_dec_lookupp_sz	(compound_decode_hdr_maxsz + \
6335b5faaf6SJeff Layton 				decode_sequence_maxsz + \
6345b5faaf6SJeff Layton 				decode_putfh_maxsz + \
6355b5faaf6SJeff Layton 				decode_lookupp_maxsz + \
6365b5faaf6SJeff Layton 				decode_getattr_maxsz + \
6375b5faaf6SJeff Layton 				decode_getfh_maxsz)
6381da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
6399b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6401da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
6411da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6421da177e4SLinus Torvalds 				encode_getfh_maxsz)
6431da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6449b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6451da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
6461da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6471da177e4SLinus Torvalds 				decode_getfh_maxsz)
6481da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
6499b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6501da177e4SLinus Torvalds 				encode_putfh_maxsz + \
651778d2817STrond Myklebust 				encode_remove_maxsz)
6521da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6539b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6541da177e4SLinus Torvalds 				decode_putfh_maxsz + \
655778d2817STrond Myklebust 				decode_remove_maxsz)
6561da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6579b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6581da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6591da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6601da177e4SLinus Torvalds 				encode_putfh_maxsz + \
661778d2817STrond Myklebust 				encode_rename_maxsz)
6621da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6639b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6641da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6651da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6661da177e4SLinus Torvalds 				decode_putfh_maxsz + \
667778d2817STrond Myklebust 				decode_rename_maxsz)
6681da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6699b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6701da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6711da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6721da177e4SLinus Torvalds 				encode_putfh_maxsz + \
67391ba2eeeSTrond Myklebust 				encode_link_maxsz + \
67491ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
675a9f6991bSTrond Myklebust 				encode_getattr_maxsz)
6761da177e4SLinus Torvalds #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
6779b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6781da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6791da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6801da177e4SLinus Torvalds 				decode_putfh_maxsz + \
68191ba2eeeSTrond Myklebust 				decode_link_maxsz + \
68291ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
68391ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6841da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6859b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6861da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6871da177e4SLinus Torvalds 				encode_symlink_maxsz + \
6881da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6891da177e4SLinus Torvalds 				encode_getfh_maxsz)
6901da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
6919b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6921da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6931da177e4SLinus Torvalds 				decode_symlink_maxsz + \
6941da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6951da177e4SLinus Torvalds 				decode_getfh_maxsz)
6961da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
6979b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6981da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6991da177e4SLinus Torvalds 				encode_create_maxsz + \
70056ae19f3STrond Myklebust 				encode_getfh_maxsz + \
70156ae19f3STrond Myklebust 				encode_getattr_maxsz)
7021da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
7039b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7041da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7051da177e4SLinus Torvalds 				decode_create_maxsz + \
70656ae19f3STrond Myklebust 				decode_getfh_maxsz + \
70756ae19f3STrond Myklebust 				decode_getattr_maxsz)
7081da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
7099b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7101da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7111da177e4SLinus Torvalds 				encode_getattr_maxsz)
7121da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
7139b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7141da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7151da177e4SLinus Torvalds 				decode_getattr_maxsz)
7161da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
7179b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7181da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7199104a55dSTrond Myklebust 				encode_statfs_maxsz)
7201da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
7219b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7221da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7239104a55dSTrond Myklebust 				decode_statfs_maxsz)
7241da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
7259b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
726ab91f264STrond Myklebust 				encode_putfh_maxsz + \
7271da177e4SLinus Torvalds 				encode_getattr_maxsz)
7281da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
7299b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
730ab91f264STrond Myklebust 				decode_putfh_maxsz + \
7311da177e4SLinus Torvalds 				decode_getattr_maxsz)
7321da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
7339b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7341da177e4SLinus Torvalds 				encode_putfh_maxsz + \
735586f1c39STrond Myklebust 				encode_layoutreturn_maxsz + \
736fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
737fa178f29STrond Myklebust 				encode_getattr_maxsz)
7381da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7399b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
740d8434d4cSTrond Myklebust 				decode_putfh_maxsz + \
741586f1c39STrond Myklebust 				decode_layoutreturn_maxsz + \
742fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
743fa178f29STrond Myklebust 				decode_getattr_maxsz)
744029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
7459b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
746029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7479104a55dSTrond Myklebust 				encode_getacl_maxsz)
748029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7499b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
750029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7519104a55dSTrond Myklebust 				decode_getacl_maxsz)
75223ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7539b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
75423ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7559104a55dSTrond Myklebust 				encode_setacl_maxsz)
75623ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7579b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
75823ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7599104a55dSTrond Myklebust 				decode_setacl_maxsz)
760683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
761683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7629b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
763683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
764e6889620STrond Myklebust 				 encode_lookup_maxsz + \
765b03d735bSChuck Lever 				 encode_fs_locations_maxsz + \
766b03d735bSChuck Lever 				 encode_renew_maxsz)
767683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
768683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7699b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
770683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
771e6889620STrond Myklebust 				 decode_lookup_maxsz + \
772b03d735bSChuck Lever 				 decode_fs_locations_maxsz + \
773b03d735bSChuck Lever 				 decode_renew_maxsz)
7745a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7755a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7765a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7775a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7785a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7795a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7805a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7815a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
78244c99933SChuck Lever #define NFS4_enc_fsid_present_sz \
78344c99933SChuck Lever 				(compound_encode_hdr_maxsz + \
78444c99933SChuck Lever 				 encode_sequence_maxsz + \
78544c99933SChuck Lever 				 encode_putfh_maxsz + \
78644c99933SChuck Lever 				 encode_getfh_maxsz + \
78744c99933SChuck Lever 				 encode_renew_maxsz)
78844c99933SChuck Lever #define NFS4_dec_fsid_present_sz \
78944c99933SChuck Lever 				(compound_decode_hdr_maxsz + \
79044c99933SChuck Lever 				 decode_sequence_maxsz + \
79144c99933SChuck Lever 				 decode_putfh_maxsz + \
79244c99933SChuck Lever 				 decode_getfh_maxsz + \
79344c99933SChuck Lever 				 decode_renew_maxsz)
79499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
7957c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
7967c44f1aeSWeston Andros Adamson 				(compound_encode_hdr_maxsz + \
7977c44f1aeSWeston Andros Adamson 				 encode_bind_conn_to_session_maxsz)
7987c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
7997c44f1aeSWeston Andros Adamson 				(compound_decode_hdr_maxsz + \
8007c44f1aeSWeston Andros Adamson 				 decode_bind_conn_to_session_maxsz)
80199fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
80299fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
80399fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
80499fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
80599fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
80699fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
807fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
808fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
809fc931582SAndy Adamson 				 encode_create_session_maxsz)
810fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
811fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
812fc931582SAndy Adamson 				 decode_create_session_maxsz)
8130f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
8140f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
8150f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
8160f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
81766245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
81866245539STrond Myklebust 					 encode_destroy_clientid_maxsz)
81966245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
82066245539STrond Myklebust 					 decode_destroy_clientid_maxsz)
821fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
822fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
823fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
824fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
825fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
826fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
8272050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
8282050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
8292050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
8302050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
8312050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
8322050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
8332050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
8342050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
83518019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
83618019753SRicardo Labiaga 					 encode_sequence_maxsz + \
83718019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
83818019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
83918019753SRicardo Labiaga 					 decode_sequence_maxsz + \
84018019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
841b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
842b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
843b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
844b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
845b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
846b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
847b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
848b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
849b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
850b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
851b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
852b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
853b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
854b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
855863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
856863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
857863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
858863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
859863a3c6cSAndy Adamson 				encode_getattr_maxsz)
860863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
861863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
862863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
863863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
864863a3c6cSAndy Adamson 				decode_getattr_maxsz)
865cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
866cbe82603SBenny Halevy 				encode_sequence_maxsz + \
867cbe82603SBenny Halevy 				encode_putfh_maxsz + \
868cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
869cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
870cbe82603SBenny Halevy 				decode_sequence_maxsz + \
871cbe82603SBenny Halevy 				decode_putfh_maxsz + \
872cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
873fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
874fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
875fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
876fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
877fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
878fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
879fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
880fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8817d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8827d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8837d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8847d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
8857d974794SBryan Schumaker 					 decode_sequence_maxsz + \
8867d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
8879aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
8889aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
8899aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
8909aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
8919aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
8929aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
8932449ea2eSAlexandros Batsakis 
8942449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8952449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
8962449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
8972449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
8982449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
8992449ea2eSAlexandros Batsakis 				     XDR_UNIT);
9002449ea2eSAlexandros Batsakis 
9012449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
9022449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
9032449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
9042449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
9052449ea2eSAlexandros Batsakis 				    XDR_UNIT);
906f1c097beSAndy Adamson 
907f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
908f1c097beSAndy Adamson 					   compound_decode_hdr_maxsz +
909f1c097beSAndy Adamson 					   decode_sequence_maxsz) *
910f1c097beSAndy Adamson 					  XDR_UNIT);
911f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
91299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
9131da177e4SLinus Torvalds 
914bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
915bca79478STrond Myklebust 	[NF4BAD] = 0,
916bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
917bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
918bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
919bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
920bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
921bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
922bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
923bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
924bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
9251da177e4SLinus Torvalds };
9261da177e4SLinus Torvalds 
9271da177e4SLinus Torvalds struct compound_hdr {
9281da177e4SLinus Torvalds 	int32_t		status;
9291da177e4SLinus Torvalds 	uint32_t	nops;
930d017931cSAndy Adamson 	__be32 *	nops_p;
9311da177e4SLinus Torvalds 	uint32_t	taglen;
9321da177e4SLinus Torvalds 	char *		tag;
9330c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
93466cc0429SBenny Halevy 	u32		minorversion;
9351da177e4SLinus Torvalds };
9361da177e4SLinus Torvalds 
93713c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
93813c65ce9SBenny Halevy {
93913c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
94013c65ce9SBenny Halevy 	BUG_ON(!p);
94113c65ce9SBenny Halevy 	return p;
94213c65ce9SBenny Halevy }
9431da177e4SLinus Torvalds 
944cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
945cb17e556STrond Myklebust {
946ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
947cb17e556STrond Myklebust }
948cb17e556STrond Myklebust 
9491da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
9501da177e4SLinus Torvalds {
951ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
9521da177e4SLinus Torvalds }
9531da177e4SLinus Torvalds 
9544ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9554ade9821STrond Myklebust {
956ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
9574ade9821STrond Myklebust }
9584ade9821STrond Myklebust 
959ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
960ff2eb681STrond Myklebust {
961ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
962ff2eb681STrond Myklebust }
963ff2eb681STrond Myklebust 
96437c88763STrond Myklebust static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
96537c88763STrond Myklebust 		const __u32 *bitmap, size_t len)
96637c88763STrond Myklebust {
96737c88763STrond Myklebust 	ssize_t ret;
96837c88763STrond Myklebust 
96937c88763STrond Myklebust 	/* Trim empty words */
97037c88763STrond Myklebust 	while (len > 0 && bitmap[len-1] == 0)
97137c88763STrond Myklebust 		len--;
97237c88763STrond Myklebust 	ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
97337c88763STrond Myklebust 	if (WARN_ON_ONCE(ret < 0))
97437c88763STrond Myklebust 		return ret;
97537c88763STrond Myklebust 	return len;
97637c88763STrond Myklebust }
97737c88763STrond Myklebust 
97837c88763STrond Myklebust static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
97937c88763STrond Myklebust 		__u32 *res, size_t len)
98037c88763STrond Myklebust {
98137c88763STrond Myklebust 	size_t i;
98237c88763STrond Myklebust 	__u32 tmp;
98337c88763STrond Myklebust 
98437c88763STrond Myklebust 	while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
98537c88763STrond Myklebust 		len--;
98637c88763STrond Myklebust 	for (i = len; i-- > 0;) {
98737c88763STrond Myklebust 		tmp = bitmap[i] & mask[i];
98837c88763STrond Myklebust 		res[i] = tmp;
98937c88763STrond Myklebust 	}
99037c88763STrond Myklebust 	return len;
99137c88763STrond Myklebust }
99237c88763STrond Myklebust 
9934ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
9944ade9821STrond Myklebust 		const struct nfs_seqid *seqid)
9954ade9821STrond Myklebust {
996a6796419STrond Myklebust 	if (seqid != NULL)
9974ade9821STrond Myklebust 		encode_uint32(xdr, seqid->sequence->counter);
998a6796419STrond Myklebust 	else
999a6796419STrond Myklebust 		encode_uint32(xdr, 0);
10004ade9821STrond Myklebust }
10014ade9821STrond Myklebust 
10020c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
10030c4e8c18SBenny Halevy 				struct rpc_rqst *req,
10040c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
10051da177e4SLinus Torvalds {
10068687b63aSAl Viro 	__be32 *p;
1007a17c2153STrond Myklebust 	struct rpc_auth *auth = req->rq_cred->cr_auth;
10080c4e8c18SBenny Halevy 
10090c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
10100c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
10110c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
10120c4e8c18SBenny Halevy 	hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
10131da177e4SLinus Torvalds 
10147fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
10156fdfb0bcSTrond Myklebust 	encode_string(xdr, hdr->taglen, hdr->tag);
10166fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 8);
1017e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
1018d017931cSAndy Adamson 	hdr->nops_p = p;
101934558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
1020d017931cSAndy Adamson }
1021d017931cSAndy Adamson 
1022ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1023ab19b481STrond Myklebust 		uint32_t replen,
1024ab19b481STrond Myklebust 		struct compound_hdr *hdr)
1025ab19b481STrond Myklebust {
1026ab19b481STrond Myklebust 	encode_uint32(xdr, op);
1027ab19b481STrond Myklebust 	hdr->nops++;
1028ab19b481STrond Myklebust 	hdr->replen += replen;
1029ab19b481STrond Myklebust }
1030ab19b481STrond Myklebust 
1031d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
1032d017931cSAndy Adamson {
10337fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
1034d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
10351da177e4SLinus Torvalds }
10361da177e4SLinus Torvalds 
1037ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1038ea9d23f5STrond Myklebust {
10392d2f24adSTrond Myklebust 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1040ea9d23f5STrond Myklebust }
1041ea9d23f5STrond Myklebust 
10421da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
10431da177e4SLinus Torvalds {
1044cb17e556STrond Myklebust 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
10451da177e4SLinus Torvalds }
10461da177e4SLinus Torvalds 
104736b3743fSTrond Myklebust static __be32 *
104836b3743fSTrond Myklebust xdr_encode_nfstime4(__be32 *p, const struct timespec *t)
104936b3743fSTrond Myklebust {
105036b3743fSTrond Myklebust 	p = xdr_encode_hyper(p, (__s64)t->tv_sec);
105136b3743fSTrond Myklebust 	*p++ = cpu_to_be32(t->tv_nsec);
105236b3743fSTrond Myklebust 	return p;
105336b3743fSTrond Myklebust }
105436b3743fSTrond Myklebust 
1055aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1056aa9c2669SDavid Quigley 				const struct nfs4_label *label,
105728cf22d0STrond Myklebust 				const umode_t *umask,
10585334c5bdSKinglong Mee 				const struct nfs_server *server,
105928cf22d0STrond Myklebust 				const uint32_t attrmask[])
10601da177e4SLinus Torvalds {
10611da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
10621da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
10631da177e4SLinus Torvalds 	int owner_namelen = 0;
10641da177e4SLinus Torvalds 	int owner_grouplen = 0;
10658687b63aSAl Viro 	__be32 *p;
1066d7067b2dSTrond Myklebust 	uint32_t len = 0;
1067d7067b2dSTrond Myklebust 	uint32_t bmval[3] = { 0 };
10681da177e4SLinus Torvalds 
10691da177e4SLinus Torvalds 	/*
10701da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
10711da177e4SLinus Torvalds 	 */
107228cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
1073d7067b2dSTrond Myklebust 		bmval[0] |= FATTR4_WORD0_SIZE;
10741da177e4SLinus Torvalds 		len += 8;
1075d7067b2dSTrond Myklebust 	}
1076d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MODE) {
107728cf22d0STrond Myklebust 		if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
1078dff25ddbSAndreas Gruenbacher 			bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1079dff25ddbSAndreas Gruenbacher 			len += 8;
108028cf22d0STrond Myklebust 		} else if (attrmask[1] & FATTR4_WORD1_MODE) {
1081d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_MODE;
10821da177e4SLinus Torvalds 			len += 4;
1083d7067b2dSTrond Myklebust 		}
1084dff25ddbSAndreas Gruenbacher 	}
108528cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
1086e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
10871da177e4SLinus Torvalds 		if (owner_namelen < 0) {
1088fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
1089e5782076SEric W. Biederman 					from_kuid(&init_user_ns, iap->ia_uid));
10901da177e4SLinus Torvalds 			/* XXX */
10911da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
10921da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
10931da177e4SLinus Torvalds 			/* goto out; */
10941da177e4SLinus Torvalds 		}
1095d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER;
10961da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
10971da177e4SLinus Torvalds 	}
109828cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_GID) &&
109928cf22d0STrond Myklebust 	   (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
1100e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
11011da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
1102fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
1103e5782076SEric W. Biederman 					from_kgid(&init_user_ns, iap->ia_gid));
11041da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
11051da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
11061da177e4SLinus Torvalds 			/* goto out; */
11071da177e4SLinus Torvalds 		}
1108d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
11091da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
11101da177e4SLinus Torvalds 	}
111128cf22d0STrond Myklebust 	if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1112d7067b2dSTrond Myklebust 		if (iap->ia_valid & ATTR_ATIME_SET) {
1113d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
111436b3743fSTrond Myklebust 			len += 4 + (nfstime4_maxsz << 2);
1115d7067b2dSTrond Myklebust 		} else if (iap->ia_valid & ATTR_ATIME) {
1116d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
11171da177e4SLinus Torvalds 			len += 4;
1118d7067b2dSTrond Myklebust 		}
111928cf22d0STrond Myklebust 	}
112028cf22d0STrond Myklebust 	if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1121d7067b2dSTrond Myklebust 		if (iap->ia_valid & ATTR_MTIME_SET) {
1122d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
112336b3743fSTrond Myklebust 			len += 4 + (nfstime4_maxsz << 2);
1124d7067b2dSTrond Myklebust 		} else if (iap->ia_valid & ATTR_MTIME) {
1125d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
11261da177e4SLinus Torvalds 			len += 4;
1127d7067b2dSTrond Myklebust 		}
11285334c5bdSKinglong Mee 	}
11295334c5bdSKinglong Mee 
113028cf22d0STrond Myklebust 	if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1131b4a2cf76STrond Myklebust 		len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1132d7067b2dSTrond Myklebust 		bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1133d7067b2dSTrond Myklebust 	}
1134d7067b2dSTrond Myklebust 
113540a3426cSTrond Myklebust 	xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
113640a3426cSTrond Myklebust 	xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
11371da177e4SLinus Torvalds 
1138d7067b2dSTrond Myklebust 	if (bmval[0] & FATTR4_WORD0_SIZE)
1139b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
1140d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_MODE)
1141e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1142d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER)
1143811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
1144d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1145811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1146d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
11471da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_ATIME_SET) {
1148e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
114936b3743fSTrond Myklebust 			p = xdr_encode_nfstime4(p, &iap->ia_atime);
1150d7067b2dSTrond Myklebust 		} else
1151e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11521da177e4SLinus Torvalds 	}
1153d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
11541da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_MTIME_SET) {
1155e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
115636b3743fSTrond Myklebust 			p = xdr_encode_nfstime4(p, &iap->ia_mtime);
1157d7067b2dSTrond Myklebust 		} else
1158e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11591da177e4SLinus Torvalds 	}
1160d7067b2dSTrond Myklebust 	if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1161aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->lfs);
1162aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->pi);
1163aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->len);
1164aa9c2669SDavid Quigley 		p = xdr_encode_opaque_fixed(p, label->label, label->len);
1165aa9c2669SDavid Quigley 	}
1166dff25ddbSAndreas Gruenbacher 	if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1167dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1168dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(*umask);
1169dff25ddbSAndreas Gruenbacher 	}
11701da177e4SLinus Torvalds 
11711da177e4SLinus Torvalds /* out: */
11721da177e4SLinus Torvalds }
11731da177e4SLinus Torvalds 
1174cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
11751da177e4SLinus Torvalds {
1176475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1177475d4ba0STrond Myklebust 	encode_uint32(xdr, access);
11781da177e4SLinus Torvalds }
11791da177e4SLinus Torvalds 
1180cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
11811da177e4SLinus Torvalds {
1182ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
11834ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1184566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
11851da177e4SLinus Torvalds }
11861da177e4SLinus Torvalds 
11870b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
11881da177e4SLinus Torvalds {
11898687b63aSAl Viro 	__be32 *p;
11901da177e4SLinus Torvalds 
1191475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1192475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1193b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
119434558513SBenny Halevy 	*p = cpu_to_be32(args->count);
11951da177e4SLinus Torvalds }
11961da177e4SLinus Torvalds 
1197cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
11981da177e4SLinus Torvalds {
11998687b63aSAl Viro 	__be32 *p;
12001da177e4SLinus Torvalds 
1201475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1202475d4ba0STrond Myklebust 	encode_uint32(xdr, create->ftype);
12031da177e4SLinus Torvalds 
12041da177e4SLinus Torvalds 	switch (create->ftype) {
12051da177e4SLinus Torvalds 	case NF4LNK:
120613c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
120734558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
12082fcc213aSChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0,
12092fcc213aSChuck Lever 				create->u.symlink.len);
12102fcc213aSChuck Lever 		xdr->buf->flags |= XDRBUF_WRITE;
12111da177e4SLinus Torvalds 		break;
12121da177e4SLinus Torvalds 
12131da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
121413c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1215e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
121634558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
12171da177e4SLinus Torvalds 		break;
12181da177e4SLinus Torvalds 
12191da177e4SLinus Torvalds 	default:
12201da177e4SLinus Torvalds 		break;
12211da177e4SLinus Torvalds 	}
12221da177e4SLinus Torvalds 
1223811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
122428cf22d0STrond Myklebust 	encode_attrs(xdr, create->attrs, create->label, &create->umask,
122528cf22d0STrond Myklebust 			create->server, create->server->attr_bitmask);
12261da177e4SLinus Torvalds }
12271da177e4SLinus Torvalds 
122837c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr,
122937c88763STrond Myklebust 		const __u32 *bitmap, const __u32 *mask, size_t len,
1230dae100c2SFred Isaman 		struct compound_hdr *hdr)
1231dae100c2SFred Isaman {
123237c88763STrond Myklebust 	__u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
1233dae100c2SFred Isaman 
1234ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
123537c88763STrond Myklebust 	if (mask) {
123637c88763STrond Myklebust 		if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
123737c88763STrond Myklebust 			len = ARRAY_SIZE(masked_bitmap);
123837c88763STrond Myklebust 		len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
123937c88763STrond Myklebust 		bitmap = masked_bitmap;
1240dae100c2SFred Isaman 	}
124137c88763STrond Myklebust 	xdr_encode_bitmap4(xdr, bitmap, len);
1242dae100c2SFred Isaman }
1243dae100c2SFred Isaman 
1244cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12451da177e4SLinus Torvalds {
124637c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
124737c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
12481da177e4SLinus Torvalds }
12491da177e4SLinus Torvalds 
125088034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
12511549210fSTrond Myklebust 				 const u32 *open_bitmap,
125288034c3dSAndy Adamson 				 struct compound_hdr *hdr)
125388034c3dSAndy Adamson {
125437c88763STrond Myklebust 	encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
125588034c3dSAndy Adamson }
125688034c3dSAndy Adamson 
1257cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12581da177e4SLinus Torvalds {
125937c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
126037c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
12611da177e4SLinus Torvalds }
12621da177e4SLinus Torvalds 
1263cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1264830b8e33SManoj Naik {
126537c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
126637c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
1267830b8e33SManoj Naik }
1268830b8e33SManoj Naik 
1269cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12701da177e4SLinus Torvalds {
1271ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12721da177e4SLinus Torvalds }
12731da177e4SLinus Torvalds 
1274cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12751da177e4SLinus Torvalds {
1276ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
12776fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
12781da177e4SLinus Torvalds }
12791da177e4SLinus Torvalds 
1280911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1281911d1aafSTrond Myklebust {
1282f44106e2SJeff Layton 	if (fl->fl_type == F_RDLCK)
1283911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1284911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1285911d1aafSTrond Myklebust }
1286911d1aafSTrond Myklebust 
1287911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1288911d1aafSTrond Myklebust {
1289911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1290911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1291911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1292911d1aafSTrond Myklebust }
1293911d1aafSTrond Myklebust 
1294daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1295daccbdedSTrond Myklebust {
1296daccbdedSTrond Myklebust 	__be32 *p;
1297daccbdedSTrond Myklebust 
1298d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1299daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1300d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1301daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1302d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1303daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1304daccbdedSTrond Myklebust }
1305daccbdedSTrond Myklebust 
13061da177e4SLinus Torvalds /*
13071da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
13081da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
13091da177e4SLinus Torvalds  */
1310cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
13111da177e4SLinus Torvalds {
13128687b63aSAl Viro 	__be32 *p;
13131da177e4SLinus Torvalds 
1314475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1315475d4ba0STrond Myklebust 	p = reserve_space(xdr, 28);
1316e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1317e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1318b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1319b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
132034558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1321911d1aafSTrond Myklebust 	if (args->new_lock_owner){
13224ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->open_seqid);
1323425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->open_stateid);
13244ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
1325daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
13261da177e4SLinus Torvalds 	}
13271da177e4SLinus Torvalds 	else {
1328425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->lock_stateid);
13294ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
13301da177e4SLinus Torvalds 	}
13311da177e4SLinus Torvalds }
13321da177e4SLinus Torvalds 
1333cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
13341da177e4SLinus Torvalds {
13358687b63aSAl Viro 	__be32 *p;
13361da177e4SLinus Torvalds 
1337475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1338475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1339e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1340b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1341b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1342daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
13431da177e4SLinus Torvalds }
13441da177e4SLinus Torvalds 
1345cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
13461da177e4SLinus Torvalds {
13478687b63aSAl Viro 	__be32 *p;
13481da177e4SLinus Torvalds 
1349475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1350475d4ba0STrond Myklebust 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13514ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, args->seqid);
1352425c1d4eSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1353ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1354b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
135534558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13561da177e4SLinus Torvalds }
13571da177e4SLinus Torvalds 
1358d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1359d3c7b7ccSTrond Myklebust {
1360ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1361d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1362d3c7b7ccSTrond Myklebust }
1363d3c7b7ccSTrond Myklebust 
1364cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13651da177e4SLinus Torvalds {
1366ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13676fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
13681da177e4SLinus Torvalds }
13691da177e4SLinus Torvalds 
13705b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
13715b5faaf6SJeff Layton {
13725b5faaf6SJeff Layton 	encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
13735b5faaf6SJeff Layton }
13745b5faaf6SJeff Layton 
13756ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
13761da177e4SLinus Torvalds {
13778687b63aSAl Viro 	__be32 *p;
13781da177e4SLinus Torvalds 
137913c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
13806ae37339STrond Myklebust 	*p++ = cpu_to_be32(share_access);
138134558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13821da177e4SLinus Torvalds }
13831da177e4SLinus Torvalds 
13841da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13851da177e4SLinus Torvalds {
13868687b63aSAl Viro 	__be32 *p;
13871da177e4SLinus Torvalds  /*
13881da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
13891da177e4SLinus Torvalds  * owner 4 = 32
13901da177e4SLinus Torvalds  */
13914ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
13926ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
139395b72eb0STrond Myklebust 	p = reserve_space(xdr, 36);
1394b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
139595b72eb0STrond Myklebust 	*p++ = cpu_to_be32(24);
139693f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1397d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
139895b72eb0STrond Myklebust 	*p++ = cpu_to_be32(arg->id.uniquifier);
139995b72eb0STrond Myklebust 	xdr_encode_hyper(p, arg->id.create_time);
14001da177e4SLinus Torvalds }
14011da177e4SLinus Torvalds 
14021da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14031da177e4SLinus Torvalds {
14048687b63aSAl Viro 	__be32 *p;
14051da177e4SLinus Torvalds 
140613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
1407549b19ccSTrond Myklebust 	switch(arg->createmode) {
1408549b19ccSTrond Myklebust 	case NFS4_CREATE_UNCHECKED:
140934558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
141028cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
141128cf22d0STrond Myklebust 				arg->server, arg->server->attr_bitmask);
14121da177e4SLinus Torvalds 		break;
1413549b19ccSTrond Myklebust 	case NFS4_CREATE_GUARDED:
14144882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
141528cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
141628cf22d0STrond Myklebust 				arg->server, arg->server->attr_bitmask);
1417549b19ccSTrond Myklebust 		break;
1418549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE:
1419549b19ccSTrond Myklebust 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1420549b19ccSTrond Myklebust 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1421549b19ccSTrond Myklebust 		break;
1422549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE4_1:
14234882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
14244882ef72SAlexandros Batsakis 		encode_nfs4_verifier(xdr, &arg->u.verifier);
142528cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
142628cf22d0STrond Myklebust 				arg->server, arg->server->exclcreat_bitmask);
14274882ef72SAlexandros Batsakis 	}
14284882ef72SAlexandros Batsakis }
14291da177e4SLinus Torvalds 
14301da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14311da177e4SLinus Torvalds {
14328687b63aSAl Viro 	__be32 *p;
14331da177e4SLinus Torvalds 
143413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14351da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14361da177e4SLinus Torvalds 	case 0:
143734558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14381da177e4SLinus Torvalds 		break;
14391da177e4SLinus Torvalds 	default:
144034558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14411da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14421da177e4SLinus Torvalds 	}
14431da177e4SLinus Torvalds }
14441da177e4SLinus Torvalds 
1445bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14461da177e4SLinus Torvalds {
14478687b63aSAl Viro 	__be32 *p;
14481da177e4SLinus Torvalds 
144913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14501da177e4SLinus Torvalds 	switch (delegation_type) {
14511da177e4SLinus Torvalds 	case 0:
145234558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14531da177e4SLinus Torvalds 		break;
14541da177e4SLinus Torvalds 	case FMODE_READ:
145534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14561da177e4SLinus Torvalds 		break;
14571da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
145834558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14591da177e4SLinus Torvalds 		break;
14601da177e4SLinus Torvalds 	default:
14611da177e4SLinus Torvalds 		BUG();
14621da177e4SLinus Torvalds 	}
14631da177e4SLinus Torvalds }
14641da177e4SLinus Torvalds 
14651da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14661da177e4SLinus Torvalds {
14678687b63aSAl Viro 	__be32 *p;
14681da177e4SLinus Torvalds 
146913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
147034558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14711da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14721da177e4SLinus Torvalds }
14731da177e4SLinus Torvalds 
1474bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14751da177e4SLinus Torvalds {
14768687b63aSAl Viro 	__be32 *p;
14771da177e4SLinus Torvalds 
147813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
147934558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14801da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14811da177e4SLinus Torvalds }
14821da177e4SLinus Torvalds 
14831da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14841da177e4SLinus Torvalds {
14858687b63aSAl Viro 	__be32 *p;
14861da177e4SLinus Torvalds 
1487ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 4);
1488ea9d23f5STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1489ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
14901da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14911da177e4SLinus Torvalds }
14921da177e4SLinus Torvalds 
1493d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr)
1494d9fc6619STrond Myklebust {
1495d9fc6619STrond Myklebust 	__be32 *p;
1496d9fc6619STrond Myklebust 
1497d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1498d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1499d9fc6619STrond Myklebust }
1500d9fc6619STrond Myklebust 
1501d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1502d9fc6619STrond Myklebust {
1503d9fc6619STrond Myklebust 	__be32 *p;
1504d9fc6619STrond Myklebust 
1505d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1506d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1507d9fc6619STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
1508d9fc6619STrond Myklebust }
1509d9fc6619STrond Myklebust 
1510cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
15111da177e4SLinus Torvalds {
1512ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
15131da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
15141da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
15151da177e4SLinus Torvalds 	switch (arg->claim) {
15161da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
15171da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
15181da177e4SLinus Torvalds 		break;
15191da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
15201da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
15211da177e4SLinus Torvalds 		break;
15221da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
15231da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
15241da177e4SLinus Torvalds 		break;
1525d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_FH:
1526d9fc6619STrond Myklebust 		encode_claim_fh(xdr);
1527d9fc6619STrond Myklebust 		break;
1528d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1529d9fc6619STrond Myklebust 		encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1530d9fc6619STrond Myklebust 		break;
15311da177e4SLinus Torvalds 	default:
15321da177e4SLinus Torvalds 		BUG();
15331da177e4SLinus Torvalds 	}
15341da177e4SLinus Torvalds }
15351da177e4SLinus Torvalds 
1536cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
15371da177e4SLinus Torvalds {
1538ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1539ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
15404ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15411da177e4SLinus Torvalds }
15421da177e4SLinus Torvalds 
1543cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
15441da177e4SLinus Torvalds {
1545ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1546566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
15474ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15486ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
15491da177e4SLinus Torvalds }
15501da177e4SLinus Torvalds 
1551cf8cdbe5SAndy Adamson static void
1552d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15531da177e4SLinus Torvalds {
1554ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
15556fdfb0bcSTrond Myklebust 	encode_string(xdr, fh->size, fh->data);
15561da177e4SLinus Torvalds }
15571da177e4SLinus Torvalds 
1558cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15591da177e4SLinus Torvalds {
1560ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15611da177e4SLinus Torvalds }
15621da177e4SLinus Torvalds 
15633c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
15643c6b899cSAnna Schumaker 			struct compound_hdr *hdr)
15651da177e4SLinus Torvalds {
15668687b63aSAl Viro 	__be32 *p;
15671da177e4SLinus Torvalds 
1568ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
15699b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
15701da177e4SLinus Torvalds 
157113c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1572b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
157334558513SBenny Halevy 	*p = cpu_to_be32(args->count);
15741da177e4SLinus Torvalds }
15751da177e4SLinus Torvalds 
1576cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15771da177e4SLinus Torvalds {
1578aa9c2669SDavid Quigley 	uint32_t attrs[3] = {
157928331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
158028331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
158128331a46STrond Myklebust 	};
15826f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
1583cd93710eSChuck Lever 	__be32 *p, verf[2];
1584d204c5d2STrond Myklebust 	uint32_t attrlen = 0;
1585d204c5d2STrond Myklebust 	unsigned int i;
15861da177e4SLinus Torvalds 
158782f2e547SBryan Schumaker 	if (readdir->plus) {
158882f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
158928331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
159082f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
159182f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
159282f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
159382f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1594d204c5d2STrond Myklebust 		attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
15956f7a35bdSTrond Myklebust 		dircount >>= 1;
159682f2e547SBryan Schumaker 	}
159728331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
159828331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
159928331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
1600d204c5d2STrond Myklebust 	for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1601d204c5d2STrond Myklebust 		attrs[i] &= readdir->bitmask[i];
1602d204c5d2STrond Myklebust 		if (attrs[i] != 0)
1603d204c5d2STrond Myklebust 			attrlen = i+1;
1604d204c5d2STrond Myklebust 	}
16056f7a35bdSTrond Myklebust 
1606475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1607ff2eb681STrond Myklebust 	encode_uint64(xdr, readdir->cookie);
1608cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &readdir->verifier);
1609d204c5d2STrond Myklebust 	p = reserve_space(xdr, 12 + (attrlen << 2));
16106f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
16116f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
1612d204c5d2STrond Myklebust 	*p++ = cpu_to_be32(attrlen);
1613d204c5d2STrond Myklebust 	for (i = 0; i < attrlen; i++)
1614d204c5d2STrond Myklebust 		*p++ = cpu_to_be32(attrs[i]);
1615cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
1616aa9c2669SDavid Quigley 
1617aa9c2669SDavid Quigley 	dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
161844109241SFred Isaman 			__func__,
1619eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1620cd93710eSChuck Lever 			verf[0], verf[1],
1621eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1622aa9c2669SDavid Quigley 			attrs[1] & readdir->bitmask[1],
1623aa9c2669SDavid Quigley 			attrs[2] & readdir->bitmask[2]);
16241da177e4SLinus Torvalds }
16251da177e4SLinus Torvalds 
1626cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16271da177e4SLinus Torvalds {
1628ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
16291da177e4SLinus Torvalds }
16301da177e4SLinus Torvalds 
1631cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16321da177e4SLinus Torvalds {
1633ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
16346fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
16351da177e4SLinus Torvalds }
16361da177e4SLinus Torvalds 
1637cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16381da177e4SLinus Torvalds {
1639ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1640811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1641811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
16421da177e4SLinus Torvalds }
16431da177e4SLinus Torvalds 
1644bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1645bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16461da177e4SLinus Torvalds {
1647475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1648ff2eb681STrond Myklebust 	encode_uint64(xdr, clid);
16491da177e4SLinus Torvalds }
16501da177e4SLinus Torvalds 
1651cf8cdbe5SAndy Adamson static void
1652d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
165356ae19f3STrond Myklebust {
1654ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
165556ae19f3STrond Myklebust }
165656ae19f3STrond Myklebust 
16579f06c719SChuck Lever static void
1658fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1659fcc85819SChristoph Hellwig 		struct compound_hdr *hdr)
166023ec6965SJ. Bruce Fields {
16618687b63aSAl Viro 	__be32 *p;
166223ec6965SJ. Bruce Fields 
1663ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1664ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &zero_stateid);
166513c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1666e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
166734558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
166813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
166934558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
16708fbcf237SAndreas Gruenbacher 	xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
167123ec6965SJ. Bruce Fields }
167223ec6965SJ. Bruce Fields 
1673cf8cdbe5SAndy Adamson static void
1674d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16751da177e4SLinus Torvalds {
1676ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
16771da177e4SLinus Torvalds }
16781da177e4SLinus Torvalds 
1679cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16801da177e4SLinus Torvalds {
1681ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1682ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
168328cf22d0STrond Myklebust 	encode_attrs(xdr, arg->iap, arg->label, NULL, server,
168428cf22d0STrond Myklebust 			server->attr_bitmask);
16851da177e4SLinus Torvalds }
16861da177e4SLinus Torvalds 
1687cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
16881da177e4SLinus Torvalds {
16898687b63aSAl Viro 	__be32 *p;
16901da177e4SLinus Torvalds 
169170019514STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1692cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
16931da177e4SLinus Torvalds 
16943a6bb738SJeff Layton 	encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
16953a6bb738SJeff Layton 			setclientid->sc_clnt->cl_owner_id);
169613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
169734558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
16981da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
16991da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
170013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
17013a6bb738SJeff Layton 	*p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
17021da177e4SLinus Torvalds }
17031da177e4SLinus Torvalds 
1704bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
17051da177e4SLinus Torvalds {
1706475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1707475d4ba0STrond Myklebust 			decode_setclientid_confirm_maxsz, hdr);
1708ff2eb681STrond Myklebust 	encode_uint64(xdr, arg->clientid);
1709cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &arg->confirm);
17101da177e4SLinus Torvalds }
17111da177e4SLinus Torvalds 
17123c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
17133c6b899cSAnna Schumaker 			 struct compound_hdr *hdr)
17141da177e4SLinus Torvalds {
17158687b63aSAl Viro 	__be32 *p;
17161da177e4SLinus Torvalds 
1717ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
17189b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
17191da177e4SLinus Torvalds 
172013c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1721b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1722e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
172334558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17241da177e4SLinus Torvalds 
17251da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
17261da177e4SLinus Torvalds }
17271da177e4SLinus Torvalds 
1728cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17291da177e4SLinus Torvalds {
1730ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1731ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
17321da177e4SLinus Torvalds }
17339b7b9fccSAndy Adamson 
17345a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17355a5ea0d4SBryan Schumaker {
1736ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
17376fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
17385a5ea0d4SBryan Schumaker }
17395a5ea0d4SBryan Schumaker 
174099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17419b7b9fccSAndy Adamson /* NFSv4.1 operations */
17427c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1743fcc85819SChristoph Hellwig 				   const struct nfs41_bind_conn_to_session_args *args,
17447c44f1aeSWeston Andros Adamson 				   struct compound_hdr *hdr)
17457c44f1aeSWeston Andros Adamson {
17467c44f1aeSWeston Andros Adamson 	__be32 *p;
17477c44f1aeSWeston Andros Adamson 
17487c44f1aeSWeston Andros Adamson 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17497c44f1aeSWeston Andros Adamson 		decode_bind_conn_to_session_maxsz, hdr);
175071a097c6STrond Myklebust 	encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
17517c44f1aeSWeston Andros Adamson 	p = xdr_reserve_space(xdr, 8);
175271a097c6STrond Myklebust 	*p++ = cpu_to_be32(args->dir);
175371a097c6STrond Myklebust 	*p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
17547c44f1aeSWeston Andros Adamson }
17557c44f1aeSWeston Andros Adamson 
1756fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
17572031cd1aSWeston Andros Adamson {
17582031cd1aSWeston Andros Adamson 	unsigned int i;
17592031cd1aSWeston Andros Adamson 	encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
17602031cd1aSWeston Andros Adamson 	for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
17612031cd1aSWeston Andros Adamson 		encode_uint32(xdr, op_map->u.words[i]);
17622031cd1aSWeston Andros Adamson }
17632031cd1aSWeston Andros Adamson 
176499fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
1765fcc85819SChristoph Hellwig 			       const struct nfs41_exchange_id_args *args,
176699fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
176799fe60d0SBenny Halevy {
176899fe60d0SBenny Halevy 	__be32 *p;
1769d751f748SJim Rees 	char impl_name[IMPL_NAME_LIMIT];
1770db8ac8baSWeston Andros Adamson 	int len = 0;
177199fe60d0SBenny Halevy 
177270019514STrond Myklebust 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1773fd40559cSTrond Myklebust 	encode_nfs4_verifier(xdr, &args->verifier);
177499fe60d0SBenny Halevy 
17753a6bb738SJeff Layton 	encode_string(xdr, strlen(args->client->cl_owner_id),
17763a6bb738SJeff Layton 			args->client->cl_owner_id);
177799fe60d0SBenny Halevy 
17782031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->flags);
17792031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->state_protect.how);
17802031cd1aSWeston Andros Adamson 
17812031cd1aSWeston Andros Adamson 	switch (args->state_protect.how) {
17822031cd1aSWeston Andros Adamson 	case SP4_NONE:
17832031cd1aSWeston Andros Adamson 		break;
17842031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
17852031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.enforce);
17862031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.allow);
17872031cd1aSWeston Andros Adamson 		break;
17882031cd1aSWeston Andros Adamson 	default:
17892031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
17902031cd1aSWeston Andros Adamson 		break;
17912031cd1aSWeston Andros Adamson 	}
1792db8ac8baSWeston Andros Adamson 
1793db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1794db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1795db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1796d751f748SJim Rees 		<= sizeof(impl_name) + 1)
1797db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1798db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1799db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1800db8ac8baSWeston Andros Adamson 
1801db8ac8baSWeston Andros Adamson 	if (len > 0) {
18022031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 1);	/* implementation id array length=1 */
1803db8ac8baSWeston Andros Adamson 
1804db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1805db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1806db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1807db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1808db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1809db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1810db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1811db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1812db8ac8baSWeston Andros Adamson 	} else
18132031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 0);	/* implementation id array length=0 */
181499fe60d0SBenny Halevy }
1815fc931582SAndy Adamson 
1816fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1817fcc85819SChristoph Hellwig 				  const struct nfs41_create_session_args *args,
1818fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1819fc931582SAndy Adamson {
1820fc931582SAndy Adamson 	__be32 *p;
1821fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
182289f0ff38STrond Myklebust 	struct rpc_clnt *clnt = clp->cl_rpcclient;
1823f092075dSChuck Lever 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
18248e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18258e0d46e1SMike Sager 
18268e0d46e1SMike Sager 	/*
18278e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18288e0d46e1SMike Sager 	 * 2 is the verifier.
18298e0d46e1SMike Sager 	 */
183035c036efSJ. Bruce Fields 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
183135c036efSJ. Bruce Fields 				* XDR_UNIT + RPC_MAX_AUTH_SIZE;
1832fc931582SAndy Adamson 
1833475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
183489f0ff38STrond Myklebust 	p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
183579969dd1STrond Myklebust 	p = xdr_encode_hyper(p, args->clientid);
183679969dd1STrond Myklebust 	*p++ = cpu_to_be32(args->seqid);			/*Sequence id */
1837e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1838fc931582SAndy Adamson 
1839fc931582SAndy Adamson 	/* Fore Channel */
1840c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1841e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1842e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18438e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1844e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1845e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1846e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1847fc931582SAndy Adamson 
1848fc931582SAndy Adamson 	/* Back Channel */
1849c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1850e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1851e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1852e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1853e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1854e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1855e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1856fc931582SAndy Adamson 
1857e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1858e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1859e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1860fc931582SAndy Adamson 
1861fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
18622f86e091SDeepa Dinamani 	*p++ = cpu_to_be32(ktime_to_ns(nn->boot_time));	/* stamp */
186389f0ff38STrond Myklebust 	p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1864e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1865e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
186634558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1867fc931582SAndy Adamson }
18680f3e66c6SAndy Adamson 
18690f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
1870fcc85819SChristoph Hellwig 				   const struct nfs4_session *session,
18710f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18720f3e66c6SAndy Adamson {
1873475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1874475d4ba0STrond Myklebust 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18750f3e66c6SAndy Adamson }
187618019753SRicardo Labiaga 
187766245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
187866245539STrond Myklebust 				   uint64_t clientid,
187966245539STrond Myklebust 				   struct compound_hdr *hdr)
188066245539STrond Myklebust {
188166245539STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
188266245539STrond Myklebust 	encode_uint64(xdr, clientid);
188366245539STrond Myklebust }
188466245539STrond Myklebust 
188518019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
1886fcc85819SChristoph Hellwig 				    const struct nfs41_reclaim_complete_args *args,
188718019753SRicardo Labiaga 				    struct compound_hdr *hdr)
188818019753SRicardo Labiaga {
1889475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1890475d4ba0STrond Myklebust 	encode_uint32(xdr, args->one_fs);
189118019753SRicardo Labiaga }
189299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
189399fe60d0SBenny Halevy 
18949b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
18959b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
18969b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
18979b7b9fccSAndy Adamson {
18989b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
18992b2fa717STrond Myklebust 	struct nfs4_session *session;
1900fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
19012b2fa717STrond Myklebust 	struct nfs4_slot *slot = args->sa_slot;
1902fc01cea9SAndy Adamson 	__be32 *p;
19039b7b9fccSAndy Adamson 
19042b2fa717STrond Myklebust 	tp = slot->table;
19052b2fa717STrond Myklebust 	session = tp->session;
19063bd2384aSChuck Lever 	if (!session)
19073bd2384aSChuck Lever 		return;
1908fc01cea9SAndy Adamson 
1909475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1910fc01cea9SAndy Adamson 
1911fc01cea9SAndy Adamson 	/*
1912fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1913fc01cea9SAndy Adamson 	 */
1914fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1915fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1916fc01cea9SAndy Adamson 		__func__,
1917fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1918fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1919fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1920fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
19212b2fa717STrond Myklebust 		slot->seq_nr, slot->slot_nr,
1922fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
1923475d4ba0STrond Myklebust 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
192493f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1925e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
19262b2fa717STrond Myklebust 	*p++ = cpu_to_be32(slot->slot_nr);
1927e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
192834558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19299b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19309b7b9fccSAndy Adamson }
19319b7b9fccSAndy Adamson 
1932b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1933b1f69b75SAndy Adamson static void
1934b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1935b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1936b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1937b1f69b75SAndy Adamson {
1938b1f69b75SAndy Adamson 	__be32 *p;
1939b1f69b75SAndy Adamson 
1940475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
194184c9dee3SChristoph Hellwig 	p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1942b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1943b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1944b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1945f1c097beSAndy Adamson 	*p++ = cpu_to_be32(args->pdev->maxcount);	/* gdia_maxcount */
194684c9dee3SChristoph Hellwig 
194784c9dee3SChristoph Hellwig 	p = reserve_space(xdr, 4 + 4);
194884c9dee3SChristoph Hellwig 	*p++ = cpu_to_be32(1);			/* bitmap length */
19494e590803STrond Myklebust 	*p++ = cpu_to_be32(args->notify_types);
1950b1f69b75SAndy Adamson }
1951b1f69b75SAndy Adamson 
1952b1f69b75SAndy Adamson static void
1953b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1954b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1955b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1956b1f69b75SAndy Adamson {
1957b1f69b75SAndy Adamson 	__be32 *p;
1958b1f69b75SAndy Adamson 
1959475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1960475d4ba0STrond Myklebust 	p = reserve_space(xdr, 36);
1961b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1962b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
1963b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
1964b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
1965b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
1966b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
1967ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1968475d4ba0STrond Myklebust 	encode_uint32(xdr, args->maxcount);
1969b1f69b75SAndy Adamson 
1970b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1971b1f69b75SAndy Adamson 		__func__,
1972b1f69b75SAndy Adamson 		args->type,
1973b1f69b75SAndy Adamson 		args->range.iomode,
1974b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
1975b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
1976b1f69b75SAndy Adamson 		args->maxcount);
1977b1f69b75SAndy Adamson }
1978863a3c6cSAndy Adamson 
1979863a3c6cSAndy Adamson static int
1980863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
1981ac7db726SBenny Halevy 		    struct inode *inode,
1982fcc85819SChristoph Hellwig 		    const struct nfs4_layoutcommit_args *args,
1983863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
1984863a3c6cSAndy Adamson {
1985863a3c6cSAndy Adamson 	__be32 *p;
1986863a3c6cSAndy Adamson 
1987863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1989863a3c6cSAndy Adamson 
1990475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1991475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1992863a3c6cSAndy Adamson 	/* Only whole file layouts */
1993863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
19943557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
1995ea9d23f5STrond Myklebust 	*p = cpu_to_be32(0); /* reclaim */
1996ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
19972e18d4d8STrond Myklebust 	if (args->lastbytewritten != U64_MAX) {
1998ea9d23f5STrond Myklebust 		p = reserve_space(xdr, 20);
1999863a3c6cSAndy Adamson 		*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2000863a3c6cSAndy Adamson 		p = xdr_encode_hyper(p, args->lastbytewritten);
20012e18d4d8STrond Myklebust 	} else {
20022e18d4d8STrond Myklebust 		p = reserve_space(xdr, 12);
20032e18d4d8STrond Myklebust 		*p++ = cpu_to_be32(0); /* newoffset = FALSE */
20042e18d4d8STrond Myklebust 	}
2005863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2006863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2007ac7db726SBenny Halevy 
20085f919c9fSChristoph Hellwig 	encode_uint32(xdr, args->layoutupdate_len);
200973504740STrond Myklebust 	if (args->layoutupdate_pages)
20105f919c9fSChristoph Hellwig 		xdr_write_pages(xdr, args->layoutupdate_pages, 0,
20115f919c9fSChristoph Hellwig 				args->layoutupdate_len);
2012863a3c6cSAndy Adamson 
2013863a3c6cSAndy Adamson 	return 0;
2014863a3c6cSAndy Adamson }
2015cbe82603SBenny Halevy 
2016cbe82603SBenny Halevy static void
2017cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2018cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2019cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2020cbe82603SBenny Halevy {
2021cbe82603SBenny Halevy 	__be32 *p;
2022cbe82603SBenny Halevy 
2023475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2024475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
2025cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2026cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
202715eb67c1SPeng Tao 	*p++ = cpu_to_be32(args->range.iomode);
2028cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2029ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
203015eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.offset);
203115eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.length);
2032cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2033ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
2034cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
20354d796d75STrond Myklebust 	if (args->ld_private->ops && args->ld_private->ops->encode)
20364d796d75STrond Myklebust 		args->ld_private->ops->encode(xdr, args, args->ld_private);
203794e5c571STrond Myklebust 	else
2038475d4ba0STrond Myklebust 		encode_uint32(xdr, 0);
2039cbe82603SBenny Halevy }
2040fca78d6dSBryan Schumaker 
2041fca78d6dSBryan Schumaker static int
2042fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2043fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2044fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2045fca78d6dSBryan Schumaker {
2046475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2047475d4ba0STrond Myklebust 	encode_uint32(xdr, args->style);
2048fca78d6dSBryan Schumaker 	return 0;
2049fca78d6dSBryan Schumaker }
20507d974794SBryan Schumaker 
20517d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
2052fcc85819SChristoph Hellwig 				const struct nfs41_test_stateid_args *args,
20537d974794SBryan Schumaker 				struct compound_hdr *hdr)
20547d974794SBryan Schumaker {
2055475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2056475d4ba0STrond Myklebust 	encode_uint32(xdr, 1);
2057ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20587d974794SBryan Schumaker }
20599aeda35fSBryan Schumaker 
20609aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
2061fcc85819SChristoph Hellwig 				const struct nfs41_free_stateid_args *args,
20629aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
20639aeda35fSBryan Schumaker {
2064ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
20657c1d5faeSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20669aeda35fSBryan Schumaker }
2067cf805165STrond Myklebust #else
2068cf805165STrond Myklebust static inline void
2069cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr,
2070cf805165STrond Myklebust 		    const struct nfs4_layoutreturn_args *args,
2071cf805165STrond Myklebust 		    struct compound_hdr *hdr)
2072cf805165STrond Myklebust {
2073cf805165STrond Myklebust }
2074b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2075b1f69b75SAndy Adamson 
20761da177e4SLinus Torvalds /*
20771da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
20781da177e4SLinus Torvalds  */
20791da177e4SLinus Torvalds 
208066cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
208166cc0429SBenny Halevy {
208266cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
20833bd2384aSChuck Lever 	struct nfs4_session *session = args->sa_slot->table->session;
20843bd2384aSChuck Lever 	if (session)
20853bd2384aSChuck Lever 		return session->clp->cl_mvops->minor_version;
208666cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
208766cc0429SBenny Halevy 	return 0;
208866cc0429SBenny Halevy }
208966cc0429SBenny Halevy 
20901da177e4SLinus Torvalds /*
20911da177e4SLinus Torvalds  * Encode an ACCESS request
20921da177e4SLinus Torvalds  */
20939f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2094fcc85819SChristoph Hellwig 				const void *data)
20951da177e4SLinus Torvalds {
2096fcc85819SChristoph Hellwig 	const struct nfs4_accessargs *args = data;
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,
2113fcc85819SChristoph Hellwig 				const void *data)
21141da177e4SLinus Torvalds {
2115fcc85819SChristoph Hellwig 	const struct nfs4_lookup_arg *args = data;
21161da177e4SLinus Torvalds 	struct compound_hdr hdr = {
211766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21181da177e4SLinus Torvalds 	};
21191da177e4SLinus Torvalds 
21209f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21219f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21229f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21239f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21249f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21259f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2126d017931cSAndy Adamson 	encode_nops(&hdr);
21271da177e4SLinus Torvalds }
21281da177e4SLinus Torvalds 
21291da177e4SLinus Torvalds /*
21305b5faaf6SJeff Layton  * Encode LOOKUPP request
21315b5faaf6SJeff Layton  */
21325b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
21335b5faaf6SJeff Layton 		const void *data)
21345b5faaf6SJeff Layton {
21355b5faaf6SJeff Layton 	const struct nfs4_lookupp_arg *args = data;
21365b5faaf6SJeff Layton 	struct compound_hdr hdr = {
21375b5faaf6SJeff Layton 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21385b5faaf6SJeff Layton 	};
21395b5faaf6SJeff Layton 
21405b5faaf6SJeff Layton 	encode_compound_hdr(xdr, req, &hdr);
21415b5faaf6SJeff Layton 	encode_sequence(xdr, &args->seq_args, &hdr);
21425b5faaf6SJeff Layton 	encode_putfh(xdr, args->fh, &hdr);
21435b5faaf6SJeff Layton 	encode_lookupp(xdr, &hdr);
21445b5faaf6SJeff Layton 	encode_getfh(xdr, &hdr);
21455b5faaf6SJeff Layton 	encode_getfattr(xdr, args->bitmask, &hdr);
21465b5faaf6SJeff Layton 	encode_nops(&hdr);
21475b5faaf6SJeff Layton }
21485b5faaf6SJeff Layton 
21495b5faaf6SJeff Layton /*
21501da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21511da177e4SLinus Torvalds  */
21529f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21539f06c719SChuck Lever 				     struct xdr_stream *xdr,
2154fcc85819SChristoph Hellwig 				     const void *data)
21551da177e4SLinus Torvalds {
2156fcc85819SChristoph Hellwig 	const struct nfs4_lookup_root_arg *args = data;
21571da177e4SLinus Torvalds 	struct compound_hdr hdr = {
215866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21591da177e4SLinus Torvalds 	};
21601da177e4SLinus Torvalds 
21619f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21629f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21639f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21649f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21659f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2166d017931cSAndy Adamson 	encode_nops(&hdr);
21671da177e4SLinus Torvalds }
21681da177e4SLinus Torvalds 
21691da177e4SLinus Torvalds /*
21701da177e4SLinus Torvalds  * Encode REMOVE request
21711da177e4SLinus Torvalds  */
21729f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2173fcc85819SChristoph Hellwig 				const void *data)
21741da177e4SLinus Torvalds {
2175fcc85819SChristoph Hellwig 	const struct nfs_removeargs *args = data;
21761da177e4SLinus Torvalds 	struct compound_hdr hdr = {
217766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21781da177e4SLinus Torvalds 	};
21791da177e4SLinus Torvalds 
21809f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21819f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21829f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21839f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
2184d017931cSAndy Adamson 	encode_nops(&hdr);
21851da177e4SLinus Torvalds }
21861da177e4SLinus Torvalds 
21871da177e4SLinus Torvalds /*
21881da177e4SLinus Torvalds  * Encode RENAME request
21891da177e4SLinus Torvalds  */
21909f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2191fcc85819SChristoph Hellwig 				const void *data)
21921da177e4SLinus Torvalds {
2193fcc85819SChristoph Hellwig 	const struct nfs_renameargs *args = data;
21941da177e4SLinus Torvalds 	struct compound_hdr hdr = {
219566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21961da177e4SLinus Torvalds 	};
21971da177e4SLinus Torvalds 
21989f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21999f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22009f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
22019f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22029f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
22039f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2204d017931cSAndy Adamson 	encode_nops(&hdr);
22051da177e4SLinus Torvalds }
22061da177e4SLinus Torvalds 
22071da177e4SLinus Torvalds /*
22081da177e4SLinus Torvalds  * Encode LINK request
22091da177e4SLinus Torvalds  */
22109f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2211fcc85819SChristoph Hellwig 			      const void *data)
22121da177e4SLinus Torvalds {
2213fcc85819SChristoph Hellwig 	const struct nfs4_link_arg *args = data;
22141da177e4SLinus Torvalds 	struct compound_hdr hdr = {
221566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22161da177e4SLinus Torvalds 	};
22171da177e4SLinus Torvalds 
22189f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22199f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22209f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22219f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22229f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22239f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
22249f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22259f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2226d017931cSAndy Adamson 	encode_nops(&hdr);
22271da177e4SLinus Torvalds }
22281da177e4SLinus Torvalds 
22291da177e4SLinus Torvalds /*
22301da177e4SLinus Torvalds  * Encode CREATE request
22311da177e4SLinus Torvalds  */
22329f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2233fcc85819SChristoph Hellwig 				const void *data)
22341da177e4SLinus Torvalds {
2235fcc85819SChristoph Hellwig 	const struct nfs4_create_arg *args = data;
22361da177e4SLinus Torvalds 	struct compound_hdr hdr = {
223766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22381da177e4SLinus Torvalds 	};
22391da177e4SLinus Torvalds 
22409f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22419f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22429f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22439f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22449f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22459f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2246d017931cSAndy Adamson 	encode_nops(&hdr);
22471da177e4SLinus Torvalds }
22481da177e4SLinus Torvalds 
22491da177e4SLinus Torvalds /*
22501da177e4SLinus Torvalds  * Encode SYMLINK request
22511da177e4SLinus Torvalds  */
22529f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2253fcc85819SChristoph Hellwig 				 const void *data)
22541da177e4SLinus Torvalds {
2255fcc85819SChristoph Hellwig 	const struct nfs4_create_arg *args = data;
2256fcc85819SChristoph Hellwig 
22579f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22581da177e4SLinus Torvalds }
22591da177e4SLinus Torvalds 
22601da177e4SLinus Torvalds /*
22611da177e4SLinus Torvalds  * Encode GETATTR request
22621da177e4SLinus Torvalds  */
22639f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2264fcc85819SChristoph Hellwig 				 const void *data)
22651da177e4SLinus Torvalds {
2266fcc85819SChristoph Hellwig 	const struct nfs4_getattr_arg *args = data;
22671da177e4SLinus Torvalds 	struct compound_hdr hdr = {
226866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22691da177e4SLinus Torvalds 	};
22701da177e4SLinus Torvalds 
22719f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22729f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22739f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22749f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2275d017931cSAndy Adamson 	encode_nops(&hdr);
22761da177e4SLinus Torvalds }
22771da177e4SLinus Torvalds 
22781da177e4SLinus Torvalds /*
22791da177e4SLinus Torvalds  * Encode a CLOSE request
22801da177e4SLinus Torvalds  */
22819f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2282fcc85819SChristoph Hellwig 			       const void *data)
22831da177e4SLinus Torvalds {
2284fcc85819SChristoph Hellwig 	const struct nfs_closeargs *args = data;
22851da177e4SLinus Torvalds 	struct compound_hdr hdr = {
228666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22871da177e4SLinus Torvalds 	};
22881da177e4SLinus Torvalds 
22899f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22909f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22919f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2292cf805165STrond Myklebust 	if (args->lr_args)
2293cf805165STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
22943ecefc92STrond Myklebust 	if (args->bitmask != NULL)
22959f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2296d8d84983STrond Myklebust 	encode_close(xdr, args, &hdr);
2297d017931cSAndy Adamson 	encode_nops(&hdr);
22981da177e4SLinus Torvalds }
22991da177e4SLinus Torvalds 
23001da177e4SLinus Torvalds /*
23011da177e4SLinus Torvalds  * Encode an OPEN request
23021da177e4SLinus Torvalds  */
23039f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2304fcc85819SChristoph Hellwig 			      const void *data)
23051da177e4SLinus Torvalds {
2306fcc85819SChristoph Hellwig 	const struct nfs_openargs *args = data;
23071da177e4SLinus Torvalds 	struct compound_hdr hdr = {
230866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23091da177e4SLinus Torvalds 	};
23101da177e4SLinus Torvalds 
23119f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23129f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23139f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23149f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
23159f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
2316ae2bb032SWeston Andros Adamson 	if (args->access)
23176168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
23181549210fSTrond Myklebust 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2319d017931cSAndy Adamson 	encode_nops(&hdr);
23201da177e4SLinus Torvalds }
23211da177e4SLinus Torvalds 
23221da177e4SLinus Torvalds /*
23231da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
23241da177e4SLinus Torvalds  */
23259f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
23269f06c719SChuck Lever 				      struct xdr_stream *xdr,
2327fcc85819SChristoph Hellwig 				      const void *data)
23281da177e4SLinus Torvalds {
2329fcc85819SChristoph Hellwig 	const struct nfs_open_confirmargs *args = data;
23301da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2331d017931cSAndy Adamson 		.nops   = 0,
23321da177e4SLinus Torvalds 	};
23331da177e4SLinus Torvalds 
23349f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23359f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23369f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2337d017931cSAndy Adamson 	encode_nops(&hdr);
23381da177e4SLinus Torvalds }
23391da177e4SLinus Torvalds 
23401da177e4SLinus Torvalds /*
23411da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
23421da177e4SLinus Torvalds  */
23439f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
23449f06c719SChuck Lever 				     struct xdr_stream *xdr,
2345fcc85819SChristoph Hellwig 				     const void *data)
23461da177e4SLinus Torvalds {
2347fcc85819SChristoph Hellwig 	const struct nfs_openargs *args = data;
23481da177e4SLinus Torvalds 	struct compound_hdr hdr = {
234966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23501da177e4SLinus Torvalds 	};
23511da177e4SLinus Torvalds 
23529f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23539f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23549f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23559f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
2356ae2bb032SWeston Andros Adamson 	if (args->access)
23576168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
2358e23008ecSAndy Adamson 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2359d017931cSAndy Adamson 	encode_nops(&hdr);
23601da177e4SLinus Torvalds }
23611da177e4SLinus Torvalds 
23621da177e4SLinus Torvalds /*
23631da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23641da177e4SLinus Torvalds  */
23659f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
23669f06c719SChuck Lever 					struct xdr_stream *xdr,
2367fcc85819SChristoph Hellwig 					const void *data)
23681da177e4SLinus Torvalds {
2369fcc85819SChristoph Hellwig 	const struct nfs_closeargs *args = data;
23701da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23721da177e4SLinus Torvalds 	};
23731da177e4SLinus Torvalds 
23749f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23759f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23769f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2377b6808145STrond Myklebust 	if (args->lr_args)
2378b6808145STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
23799f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
2380d017931cSAndy Adamson 	encode_nops(&hdr);
23811da177e4SLinus Torvalds }
23821da177e4SLinus Torvalds 
23831da177e4SLinus Torvalds /*
23841da177e4SLinus Torvalds  * Encode a LOCK request
23851da177e4SLinus Torvalds  */
23869f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2387fcc85819SChristoph Hellwig 			      const void *data)
23881da177e4SLinus Torvalds {
2389fcc85819SChristoph Hellwig 	const struct nfs_lock_args *args = data;
23901da177e4SLinus Torvalds 	struct compound_hdr hdr = {
239166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23921da177e4SLinus Torvalds 	};
23931da177e4SLinus Torvalds 
23949f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23959f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23969f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23979f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2398d017931cSAndy Adamson 	encode_nops(&hdr);
23991da177e4SLinus Torvalds }
24001da177e4SLinus Torvalds 
24011da177e4SLinus Torvalds /*
24021da177e4SLinus Torvalds  * Encode a LOCKT request
24031da177e4SLinus Torvalds  */
24049f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2405fcc85819SChristoph Hellwig 			       const void *data)
24061da177e4SLinus Torvalds {
2407fcc85819SChristoph Hellwig 	const struct nfs_lockt_args *args = data;
24081da177e4SLinus Torvalds 	struct compound_hdr hdr = {
240966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24101da177e4SLinus Torvalds 	};
24111da177e4SLinus Torvalds 
24129f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24139f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24149f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24159f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2416d017931cSAndy Adamson 	encode_nops(&hdr);
24171da177e4SLinus Torvalds }
24181da177e4SLinus Torvalds 
24191da177e4SLinus Torvalds /*
24201da177e4SLinus Torvalds  * Encode a LOCKU request
24211da177e4SLinus Torvalds  */
24229f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2423fcc85819SChristoph Hellwig 			       const void *data)
24241da177e4SLinus Torvalds {
2425fcc85819SChristoph Hellwig 	const struct nfs_locku_args *args = data;
24261da177e4SLinus Torvalds 	struct compound_hdr hdr = {
242766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24281da177e4SLinus Torvalds 	};
24291da177e4SLinus Torvalds 
24309f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24319f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24329f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24339f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2434d017931cSAndy Adamson 	encode_nops(&hdr);
24351da177e4SLinus Torvalds }
24361da177e4SLinus Torvalds 
24379f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
24389f06c719SChuck Lever 					   struct xdr_stream *xdr,
2439fcc85819SChristoph Hellwig 					   const void *data)
2440d3c7b7ccSTrond Myklebust {
2441fcc85819SChristoph Hellwig 	const struct nfs_release_lockowner_args *args = data;
2442d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2443d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2444d3c7b7ccSTrond Myklebust 	};
2445d3c7b7ccSTrond Myklebust 
24469f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24479f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2448d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2449d3c7b7ccSTrond Myklebust }
2450d3c7b7ccSTrond Myklebust 
24511da177e4SLinus Torvalds /*
24521da177e4SLinus Torvalds  * Encode a READLINK request
24531da177e4SLinus Torvalds  */
24549f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2455fcc85819SChristoph Hellwig 				  const void *data)
24561da177e4SLinus Torvalds {
2457fcc85819SChristoph Hellwig 	const struct nfs4_readlink *args = data;
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_readlink(xdr, args, req, &hdr);
2466e3a535e1STrond Myklebust 
246728f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2468e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2469d017931cSAndy Adamson 	encode_nops(&hdr);
24701da177e4SLinus Torvalds }
24711da177e4SLinus Torvalds 
24721da177e4SLinus Torvalds /*
24731da177e4SLinus Torvalds  * Encode a READDIR request
24741da177e4SLinus Torvalds  */
24759f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2476fcc85819SChristoph Hellwig 				 const void *data)
24771da177e4SLinus Torvalds {
2478fcc85819SChristoph Hellwig 	const struct nfs4_readdir_arg *args = data;
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_readdir(xdr, args, req, &hdr);
2487d6ac02dfSTrond Myklebust 
248828f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2489d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2490d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
249128f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2492d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2493d017931cSAndy Adamson 	encode_nops(&hdr);
24941da177e4SLinus Torvalds }
24951da177e4SLinus Torvalds 
24961da177e4SLinus Torvalds /*
24971da177e4SLinus Torvalds  * Encode a READ request
24981da177e4SLinus Torvalds  */
24999f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2500fcc85819SChristoph Hellwig 			      const void *data)
25011da177e4SLinus Torvalds {
2502fcc85819SChristoph Hellwig 	const struct nfs_pgio_args *args = data;
25031da177e4SLinus Torvalds 	struct compound_hdr hdr = {
250466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25051da177e4SLinus Torvalds 	};
25061da177e4SLinus Torvalds 
25079f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25089f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25099f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25109f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
25111da177e4SLinus Torvalds 
251228f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
25131da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
25144f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2515d017931cSAndy Adamson 	encode_nops(&hdr);
25161da177e4SLinus Torvalds }
25171da177e4SLinus Torvalds 
25181da177e4SLinus Torvalds /*
25191da177e4SLinus Torvalds  * Encode an SETATTR request
25201da177e4SLinus Torvalds  */
25219f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2522fcc85819SChristoph Hellwig 				 const void *data)
25231da177e4SLinus Torvalds {
2524fcc85819SChristoph Hellwig 	const struct nfs_setattrargs *args = data;
25251da177e4SLinus Torvalds 	struct compound_hdr hdr = {
252666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25271da177e4SLinus Torvalds 	};
25281da177e4SLinus Torvalds 
25299f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25309f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25319f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25329f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
25339f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2534d017931cSAndy Adamson 	encode_nops(&hdr);
25351da177e4SLinus Torvalds }
25361da177e4SLinus Torvalds 
25371da177e4SLinus Torvalds /*
2538029d105eSJ. Bruce Fields  * Encode a GETACL request
2539029d105eSJ. Bruce Fields  */
25409f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2541fcc85819SChristoph Hellwig 				const void *data)
2542029d105eSJ. Bruce Fields {
2543fcc85819SChristoph Hellwig 	const struct nfs_getaclargs *args = data;
2544029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
254566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2546029d105eSJ. Bruce Fields 	};
254737c88763STrond Myklebust 	const __u32 nfs4_acl_bitmap[1] = {
254837c88763STrond Myklebust 		[0] = FATTR4_WORD0_ACL,
254937c88763STrond Myklebust 	};
255028f56694SBenny Halevy 	uint32_t replen;
2551029d105eSJ. Bruce Fields 
25529f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25539f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25549f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25556682c14bSJ. Bruce Fields 	replen = hdr.replen + op_decode_hdr_maxsz;
255637c88763STrond Myklebust 	encode_getattr(xdr, nfs4_acl_bitmap, NULL,
255737c88763STrond Myklebust 			ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
2558cf8cdbe5SAndy Adamson 
255928f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
25608fbcf237SAndreas Gruenbacher 		args->acl_pages, 0, args->acl_len);
2561bf118a34SAndy Adamson 
2562d017931cSAndy Adamson 	encode_nops(&hdr);
2563029d105eSJ. Bruce Fields }
2564029d105eSJ. Bruce Fields 
2565029d105eSJ. Bruce Fields /*
25661da177e4SLinus Torvalds  * Encode a WRITE request
25671da177e4SLinus Torvalds  */
25689f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2569fcc85819SChristoph Hellwig 			       const void *data)
25701da177e4SLinus Torvalds {
2571fcc85819SChristoph Hellwig 	const struct nfs_pgio_args *args = data;
25721da177e4SLinus Torvalds 	struct compound_hdr hdr = {
257366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25741da177e4SLinus Torvalds 	};
25751da177e4SLinus Torvalds 
25769f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25779f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25789f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25799f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
25804f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
25817ffd1064SFred Isaman 	if (args->bitmask)
25829f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2583d017931cSAndy Adamson 	encode_nops(&hdr);
25841da177e4SLinus Torvalds }
25851da177e4SLinus Torvalds 
25861da177e4SLinus Torvalds /*
25871da177e4SLinus Torvalds  *  a COMMIT request
25881da177e4SLinus Torvalds  */
25899f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2590fcc85819SChristoph Hellwig 				const void *data)
25911da177e4SLinus Torvalds {
2592fcc85819SChristoph Hellwig 	const struct nfs_commitargs *args = data;
25931da177e4SLinus Torvalds 	struct compound_hdr hdr = {
259466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25951da177e4SLinus Torvalds 	};
25961da177e4SLinus Torvalds 
25979f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25989f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25999f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26009f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2601d017931cSAndy Adamson 	encode_nops(&hdr);
26021da177e4SLinus Torvalds }
26031da177e4SLinus Torvalds 
26041da177e4SLinus Torvalds /*
26051da177e4SLinus Torvalds  * FSINFO request
26061da177e4SLinus Torvalds  */
26079f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2608fcc85819SChristoph Hellwig 				const void *data)
26091da177e4SLinus Torvalds {
2610fcc85819SChristoph Hellwig 	const struct nfs4_fsinfo_arg *args = data;
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->fh, &hdr);
26189f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2619d017931cSAndy Adamson 	encode_nops(&hdr);
26201da177e4SLinus Torvalds }
26211da177e4SLinus Torvalds 
26221da177e4SLinus Torvalds /*
26231da177e4SLinus Torvalds  * a PATHCONF request
26241da177e4SLinus Torvalds  */
26259f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2626fcc85819SChristoph Hellwig 				  const void *data)
26271da177e4SLinus Torvalds {
2628fcc85819SChristoph Hellwig 	const struct nfs4_pathconf_arg *args = data;
26291da177e4SLinus Torvalds 	struct compound_hdr hdr = {
263066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26311da177e4SLinus Torvalds 	};
26321da177e4SLinus Torvalds 
26339f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26349f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26359f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
263637c88763STrond Myklebust 	encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
263737c88763STrond Myklebust 			ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
2638d017931cSAndy Adamson 	encode_nops(&hdr);
26391da177e4SLinus Torvalds }
26401da177e4SLinus Torvalds 
26411da177e4SLinus Torvalds /*
26421da177e4SLinus Torvalds  * a STATFS request
26431da177e4SLinus Torvalds  */
26449f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2645fcc85819SChristoph Hellwig 				const void *data)
26461da177e4SLinus Torvalds {
2647fcc85819SChristoph Hellwig 	const struct nfs4_statfs_arg *args = data;
26481da177e4SLinus Torvalds 	struct compound_hdr hdr = {
264966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26501da177e4SLinus Torvalds 	};
26511da177e4SLinus Torvalds 
26529f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26539f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26549f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
265537c88763STrond Myklebust 	encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
265637c88763STrond Myklebust 			ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
2657d017931cSAndy Adamson 	encode_nops(&hdr);
26581da177e4SLinus Torvalds }
26591da177e4SLinus Torvalds 
26601da177e4SLinus Torvalds /*
26611da177e4SLinus Torvalds  * GETATTR_BITMAP request
26621da177e4SLinus Torvalds  */
26639f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
26649f06c719SChuck Lever 				     struct xdr_stream *xdr,
2665fcc85819SChristoph Hellwig 				     const void *data)
26661da177e4SLinus Torvalds {
2667fcc85819SChristoph Hellwig 	const struct nfs4_server_caps_arg *args = data;
26688c61282fSKinglong Mee 	const u32 *bitmask = args->bitmask;
26691da177e4SLinus Torvalds 	struct compound_hdr hdr = {
267066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26711da177e4SLinus Torvalds 	};
26721da177e4SLinus Torvalds 
26739f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26749f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26759f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
267637c88763STrond Myklebust 	encode_getattr(xdr, bitmask, NULL, 3, &hdr);
2677d017931cSAndy Adamson 	encode_nops(&hdr);
26781da177e4SLinus Torvalds }
26791da177e4SLinus Torvalds 
26801da177e4SLinus Torvalds /*
26811da177e4SLinus Torvalds  * a RENEW request
26821da177e4SLinus Torvalds  */
26839f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2684fcc85819SChristoph Hellwig 			       const void *data)
2685fcc85819SChristoph Hellwig 
26861da177e4SLinus Torvalds {
2687fcc85819SChristoph Hellwig 	const struct nfs_client *clp = data;
26881da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2689d017931cSAndy Adamson 		.nops	= 0,
26901da177e4SLinus Torvalds 	};
26911da177e4SLinus Torvalds 
26929f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2693bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2694d017931cSAndy Adamson 	encode_nops(&hdr);
26951da177e4SLinus Torvalds }
26961da177e4SLinus Torvalds 
26971da177e4SLinus Torvalds /*
26981da177e4SLinus Torvalds  * a SETCLIENTID request
26991da177e4SLinus Torvalds  */
27009f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
27019f06c719SChuck Lever 				     struct xdr_stream *xdr,
2702fcc85819SChristoph Hellwig 				     const void *data)
27031da177e4SLinus Torvalds {
2704fcc85819SChristoph Hellwig 	const struct nfs4_setclientid *sc = data;
27051da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2706d017931cSAndy Adamson 		.nops	= 0,
27071da177e4SLinus Torvalds 	};
27081da177e4SLinus Torvalds 
27099f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27109f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2711d017931cSAndy Adamson 	encode_nops(&hdr);
27121da177e4SLinus Torvalds }
27131da177e4SLinus Torvalds 
27141da177e4SLinus Torvalds /*
27151da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
27161da177e4SLinus Torvalds  */
27179f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
27189f06c719SChuck Lever 					     struct xdr_stream *xdr,
2719fcc85819SChristoph Hellwig 					     const void *data)
27201da177e4SLinus Torvalds {
2721fcc85819SChristoph Hellwig 	const struct nfs4_setclientid_res *arg = data;
27221da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2723d017931cSAndy Adamson 		.nops	= 0,
27241da177e4SLinus Torvalds 	};
27251da177e4SLinus Torvalds 
27269f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27279f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
2728d017931cSAndy Adamson 	encode_nops(&hdr);
27291da177e4SLinus Torvalds }
27301da177e4SLinus Torvalds 
27311da177e4SLinus Torvalds /*
27321da177e4SLinus Torvalds  * DELEGRETURN request
27331da177e4SLinus Torvalds  */
27349f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
27359f06c719SChuck Lever 				     struct xdr_stream *xdr,
2736fcc85819SChristoph Hellwig 				     const void *data)
27371da177e4SLinus Torvalds {
2738fcc85819SChristoph Hellwig 	const struct nfs4_delegreturnargs *args = data;
27391da177e4SLinus Torvalds 	struct compound_hdr hdr = {
274066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27411da177e4SLinus Torvalds 	};
27421da177e4SLinus Torvalds 
27439f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27449f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27459f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
2746586f1c39STrond Myklebust 	if (args->lr_args)
2747586f1c39STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
27488ac2b422STrond Myklebust 	if (args->bitmask)
27499f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2750e144cbccSTrond Myklebust 	encode_delegreturn(xdr, args->stateid, &hdr);
2751d017931cSAndy Adamson 	encode_nops(&hdr);
27521da177e4SLinus Torvalds }
27531da177e4SLinus Torvalds 
27541da177e4SLinus Torvalds /*
2755683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2756683b57b4STrond Myklebust  */
27579f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
27589f06c719SChuck Lever 				      struct xdr_stream *xdr,
2759fcc85819SChristoph Hellwig 				      const void *data)
2760683b57b4STrond Myklebust {
2761fcc85819SChristoph Hellwig 	const struct nfs4_fs_locations_arg *args = data;
2762683b57b4STrond Myklebust 	struct compound_hdr hdr = {
276366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2764683b57b4STrond Myklebust 	};
276528f56694SBenny Halevy 	uint32_t replen;
2766683b57b4STrond Myklebust 
27679f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27689f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
2769b03d735bSChuck Lever 	if (args->migration) {
2770b03d735bSChuck Lever 		encode_putfh(xdr, args->fh, &hdr);
2771b03d735bSChuck Lever 		replen = hdr.replen;
2772b03d735bSChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2773b03d735bSChuck Lever 		if (args->renew)
2774b03d735bSChuck Lever 			encode_renew(xdr, args->clientid, &hdr);
2775b03d735bSChuck Lever 	} else {
27769f06c719SChuck Lever 		encode_putfh(xdr, args->dir_fh, &hdr);
27779f06c719SChuck Lever 		encode_lookup(xdr, args->name, &hdr);
2778b03d735bSChuck Lever 		replen = hdr.replen;
27799f06c719SChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2780b03d735bSChuck Lever 	}
2781cf8cdbe5SAndy Adamson 
2782b03d735bSChuck Lever 	/* Set up reply kvec to capture returned fs_locations array. */
2783fcc85819SChristoph Hellwig 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2784fcc85819SChristoph Hellwig 			 (struct page **)&args->page, 0, PAGE_SIZE);
2785d017931cSAndy Adamson 	encode_nops(&hdr);
2786683b57b4STrond Myklebust }
2787683b57b4STrond Myklebust 
27885a5ea0d4SBryan Schumaker /*
27895a5ea0d4SBryan Schumaker  * Encode SECINFO request
27905a5ea0d4SBryan Schumaker  */
27915a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
27925a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
2793fcc85819SChristoph Hellwig 				const void *data)
27945a5ea0d4SBryan Schumaker {
2795fcc85819SChristoph Hellwig 	const struct nfs4_secinfo_arg *args = data;
27965a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
27975a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27985a5ea0d4SBryan Schumaker 	};
27995a5ea0d4SBryan Schumaker 
28005a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
28015a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
28025a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
28035a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
28045a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
28055a5ea0d4SBryan Schumaker }
28065a5ea0d4SBryan Schumaker 
280744c99933SChuck Lever /*
280844c99933SChuck Lever  * Encode FSID_PRESENT request
280944c99933SChuck Lever  */
281044c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
281144c99933SChuck Lever 				      struct xdr_stream *xdr,
2812fcc85819SChristoph Hellwig 				      const void *data)
281344c99933SChuck Lever {
2814fcc85819SChristoph Hellwig 	const struct nfs4_fsid_present_arg *args = data;
281544c99933SChuck Lever 	struct compound_hdr hdr = {
281644c99933SChuck Lever 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
281744c99933SChuck Lever 	};
281844c99933SChuck Lever 
281944c99933SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
282044c99933SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
282144c99933SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
282244c99933SChuck Lever 	encode_getfh(xdr, &hdr);
282344c99933SChuck Lever 	if (args->renew)
282444c99933SChuck Lever 		encode_renew(xdr, args->clientid, &hdr);
282544c99933SChuck Lever 	encode_nops(&hdr);
282644c99933SChuck Lever }
282744c99933SChuck Lever 
282899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
282999fe60d0SBenny Halevy /*
28307c44f1aeSWeston Andros Adamson  * BIND_CONN_TO_SESSION request
28317c44f1aeSWeston Andros Adamson  */
28327c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
28337c44f1aeSWeston Andros Adamson 				struct xdr_stream *xdr,
2834fcc85819SChristoph Hellwig 				const void *data)
28357c44f1aeSWeston Andros Adamson {
2836fcc85819SChristoph Hellwig 	const struct nfs41_bind_conn_to_session_args *args = data;
28377c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr = {
283871a097c6STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
28397c44f1aeSWeston Andros Adamson 	};
28407c44f1aeSWeston Andros Adamson 
28417c44f1aeSWeston Andros Adamson 	encode_compound_hdr(xdr, req, &hdr);
284271a097c6STrond Myklebust 	encode_bind_conn_to_session(xdr, args, &hdr);
28437c44f1aeSWeston Andros Adamson 	encode_nops(&hdr);
28447c44f1aeSWeston Andros Adamson }
28457c44f1aeSWeston Andros Adamson 
28467c44f1aeSWeston Andros Adamson /*
284799fe60d0SBenny Halevy  * EXCHANGE_ID request
284899fe60d0SBenny Halevy  */
28499f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
28509f06c719SChuck Lever 				     struct xdr_stream *xdr,
2851fcc85819SChristoph Hellwig 				     const void *data)
285299fe60d0SBenny Halevy {
2853fcc85819SChristoph Hellwig 	const struct nfs41_exchange_id_args *args = data;
285499fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2855a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
285699fe60d0SBenny Halevy 	};
285799fe60d0SBenny Halevy 
28589f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28599f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
286099fe60d0SBenny Halevy 	encode_nops(&hdr);
286199fe60d0SBenny Halevy }
28622050f0ccSAndy Adamson 
28632050f0ccSAndy Adamson /*
2864fc931582SAndy Adamson  * a CREATE_SESSION request
2865fc931582SAndy Adamson  */
28669f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
28679f06c719SChuck Lever 					struct xdr_stream *xdr,
2868fcc85819SChristoph Hellwig 					const void *data)
2869fc931582SAndy Adamson {
2870fcc85819SChristoph Hellwig 	const struct nfs41_create_session_args *args = data;
2871fc931582SAndy Adamson 	struct compound_hdr hdr = {
2872a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2873fc931582SAndy Adamson 	};
2874fc931582SAndy Adamson 
28759f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28769f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2877fc931582SAndy Adamson 	encode_nops(&hdr);
2878fc931582SAndy Adamson }
2879fc931582SAndy Adamson 
2880fc931582SAndy Adamson /*
28810f3e66c6SAndy Adamson  * a DESTROY_SESSION request
28820f3e66c6SAndy Adamson  */
28839f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
28849f06c719SChuck Lever 					 struct xdr_stream *xdr,
2885fcc85819SChristoph Hellwig 					 const void *data)
28860f3e66c6SAndy Adamson {
2887fcc85819SChristoph Hellwig 	const struct nfs4_session *session = data;
28880f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2889a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
28900f3e66c6SAndy Adamson 	};
28910f3e66c6SAndy Adamson 
28929f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28939f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
28940f3e66c6SAndy Adamson 	encode_nops(&hdr);
28950f3e66c6SAndy Adamson }
28960f3e66c6SAndy Adamson 
28970f3e66c6SAndy Adamson /*
289866245539STrond Myklebust  * a DESTROY_CLIENTID request
289966245539STrond Myklebust  */
290066245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
290166245539STrond Myklebust 					 struct xdr_stream *xdr,
2902fcc85819SChristoph Hellwig 					 const void *data)
290366245539STrond Myklebust {
2904fcc85819SChristoph Hellwig 	const struct nfs_client *clp = data;
290566245539STrond Myklebust 	struct compound_hdr hdr = {
290666245539STrond Myklebust 		.minorversion = clp->cl_mvops->minor_version,
290766245539STrond Myklebust 	};
290866245539STrond Myklebust 
290966245539STrond Myklebust 	encode_compound_hdr(xdr, req, &hdr);
291066245539STrond Myklebust 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
291166245539STrond Myklebust 	encode_nops(&hdr);
291266245539STrond Myklebust }
291366245539STrond Myklebust 
291466245539STrond Myklebust /*
2915fc01cea9SAndy Adamson  * a SEQUENCE request
2916fc01cea9SAndy Adamson  */
29179f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2918fcc85819SChristoph Hellwig 				  const void *data)
2919fc01cea9SAndy Adamson {
2920fcc85819SChristoph Hellwig 	const struct nfs4_sequence_args *args = data;
2921fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2922fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2923fc01cea9SAndy Adamson 	};
2924fc01cea9SAndy Adamson 
29259f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29269f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2927fc01cea9SAndy Adamson 	encode_nops(&hdr);
2928fc01cea9SAndy Adamson }
2929fc01cea9SAndy Adamson 
2930fc01cea9SAndy Adamson /*
29312050f0ccSAndy Adamson  * a GET_LEASE_TIME request
29322050f0ccSAndy Adamson  */
29339f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
29349f06c719SChuck Lever 					struct xdr_stream *xdr,
2935fcc85819SChristoph Hellwig 					const void *data)
29362050f0ccSAndy Adamson {
2937fcc85819SChristoph Hellwig 	const struct nfs4_get_lease_time_args *args = data;
29382050f0ccSAndy Adamson 	struct compound_hdr hdr = {
29392050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
29402050f0ccSAndy Adamson 	};
2941dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
29422050f0ccSAndy Adamson 
29439f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29449f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
29459f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
29469f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
29472050f0ccSAndy Adamson 	encode_nops(&hdr);
29482050f0ccSAndy Adamson }
294918019753SRicardo Labiaga 
295018019753SRicardo Labiaga /*
295118019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
295218019753SRicardo Labiaga  */
29539f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
29549f06c719SChuck Lever 					  struct xdr_stream *xdr,
2955fcc85819SChristoph Hellwig 					  const void *data)
295618019753SRicardo Labiaga {
2957fcc85819SChristoph Hellwig 	const struct nfs41_reclaim_complete_args *args = data;
295818019753SRicardo Labiaga 	struct compound_hdr hdr = {
295918019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
296018019753SRicardo Labiaga 	};
296118019753SRicardo Labiaga 
29629f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29639f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29649f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
296518019753SRicardo Labiaga 	encode_nops(&hdr);
296618019753SRicardo Labiaga }
296718019753SRicardo Labiaga 
2968b1f69b75SAndy Adamson /*
2969b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
2970b1f69b75SAndy Adamson  */
29719f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
29729f06c719SChuck Lever 				       struct xdr_stream *xdr,
2973fcc85819SChristoph Hellwig 				       const void *data)
2974b1f69b75SAndy Adamson {
2975fcc85819SChristoph Hellwig 	const struct nfs4_getdeviceinfo_args *args = data;
2976b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2977b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2978b1f69b75SAndy Adamson 	};
2979b1f69b75SAndy Adamson 
29809f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29819f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29829f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
2983b1f69b75SAndy Adamson 
2984b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
2985b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
2986b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2987b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
2988b1f69b75SAndy Adamson 			 args->pdev->pglen);
2989b1f69b75SAndy Adamson 
2990b1f69b75SAndy Adamson 	encode_nops(&hdr);
2991b1f69b75SAndy Adamson }
2992b1f69b75SAndy Adamson 
2993b1f69b75SAndy Adamson /*
2994b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
2995b1f69b75SAndy Adamson  */
29969f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
29979f06c719SChuck Lever 				   struct xdr_stream *xdr,
2998fcc85819SChristoph Hellwig 				   const void *data)
2999b1f69b75SAndy Adamson {
3000fcc85819SChristoph Hellwig 	const struct nfs4_layoutget_args *args = data;
3001b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
3002b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3003b1f69b75SAndy Adamson 	};
3004b1f69b75SAndy Adamson 
30059f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
30069f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
30079f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
30089f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
300935124a09SWeston Andros Adamson 
301035124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
301135124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
301235124a09SWeston Andros Adamson 
3013b1f69b75SAndy Adamson 	encode_nops(&hdr);
3014b1f69b75SAndy Adamson }
3015863a3c6cSAndy Adamson 
3016863a3c6cSAndy Adamson /*
3017863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
3018863a3c6cSAndy Adamson  */
3019cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3020863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
3021fcc85819SChristoph Hellwig 				      const void *priv)
3022863a3c6cSAndy Adamson {
3023fcc85819SChristoph Hellwig 	const struct nfs4_layoutcommit_args *args = priv;
3024ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
3025ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
3026863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
3027863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3028863a3c6cSAndy Adamson 	};
3029863a3c6cSAndy Adamson 
3030863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
3031863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
3032863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3033ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
3034863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
3035863a3c6cSAndy Adamson 	encode_nops(&hdr);
3036cbe82603SBenny Halevy }
3037cbe82603SBenny Halevy 
3038cbe82603SBenny Halevy /*
3039cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
3040cbe82603SBenny Halevy  */
3041cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3042cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
3043fcc85819SChristoph Hellwig 				      const void *data)
3044cbe82603SBenny Halevy {
3045fcc85819SChristoph Hellwig 	const struct nfs4_layoutreturn_args *args = data;
3046cbe82603SBenny Halevy 	struct compound_hdr hdr = {
3047cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3048cbe82603SBenny Halevy 	};
3049cbe82603SBenny Halevy 
3050cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
3051cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
3052cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3053cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
3054cbe82603SBenny Halevy 	encode_nops(&hdr);
3055863a3c6cSAndy Adamson }
3056fca78d6dSBryan Schumaker 
3057fca78d6dSBryan Schumaker /*
3058fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
3059fca78d6dSBryan Schumaker  */
3060fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3061fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
3062fcc85819SChristoph Hellwig 					const void *data)
3063fca78d6dSBryan Schumaker {
3064fcc85819SChristoph Hellwig 	const struct nfs41_secinfo_no_name_args *args = data;
3065fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
3066fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3067fca78d6dSBryan Schumaker 	};
3068fca78d6dSBryan Schumaker 
3069fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
3070fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
3071fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
3072fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
3073fca78d6dSBryan Schumaker 	encode_nops(&hdr);
3074fca78d6dSBryan Schumaker }
30757d974794SBryan Schumaker 
30767d974794SBryan Schumaker /*
30777d974794SBryan Schumaker  *  Encode TEST_STATEID request
30787d974794SBryan Schumaker  */
30797d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
30807d974794SBryan Schumaker 				      struct xdr_stream *xdr,
3081fcc85819SChristoph Hellwig 				      const void *data)
30827d974794SBryan Schumaker {
3083fcc85819SChristoph Hellwig 	const struct nfs41_test_stateid_args *args = data;
30847d974794SBryan Schumaker 	struct compound_hdr hdr = {
30857d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30867d974794SBryan Schumaker 	};
30877d974794SBryan Schumaker 
30887d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30897d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30907d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
30917d974794SBryan Schumaker 	encode_nops(&hdr);
30927d974794SBryan Schumaker }
30939aeda35fSBryan Schumaker 
30949aeda35fSBryan Schumaker /*
30959aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
30969aeda35fSBryan Schumaker  */
30979aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
30989aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
3099fcc85819SChristoph Hellwig 				     const void *data)
31009aeda35fSBryan Schumaker {
3101fcc85819SChristoph Hellwig 	const struct nfs41_free_stateid_args *args = data;
31029aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
31039aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
31049aeda35fSBryan Schumaker 	};
31059aeda35fSBryan Schumaker 
31069aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
31079aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
31089aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
31099aeda35fSBryan Schumaker 	encode_nops(&hdr);
31109aeda35fSBryan Schumaker }
311199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
311299fe60d0SBenny Halevy 
3113686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3114686841b3SBenny Halevy {
3115686841b3SBenny Halevy 	dprintk("nfs: %s: prematurely hit end of receive buffer. "
3116686841b3SBenny Halevy 		"Remaining buffer length is %tu words.\n",
3117686841b3SBenny Halevy 		func, xdr->end - xdr->p);
3118686841b3SBenny Halevy }
31191da177e4SLinus Torvalds 
3120683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
31211da177e4SLinus Torvalds {
31226da59ce2STrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
31236da59ce2STrond Myklebust 			NFS4_OPAQUE_LIMIT);
31246da59ce2STrond Myklebust 	if (unlikely(ret < 0)) {
31256da59ce2STrond Myklebust 		if (ret == -EBADMSG)
3126c0eae66eSBenny Halevy 			print_overflow_msg(__func__, xdr);
3127c0eae66eSBenny Halevy 		return -EIO;
31281da177e4SLinus Torvalds 	}
31296da59ce2STrond Myklebust 	*len = ret;
31306da59ce2STrond Myklebust 	return 0;
31316da59ce2STrond Myklebust }
31321da177e4SLinus Torvalds 
31331da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
31341da177e4SLinus Torvalds {
31358687b63aSAl Viro 	__be32 *p;
31361da177e4SLinus Torvalds 
3137c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3138c0eae66eSBenny Halevy 	if (unlikely(!p))
3139c0eae66eSBenny Halevy 		goto out_overflow;
31406f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3141cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
31421da177e4SLinus Torvalds 
3143c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3144c0eae66eSBenny Halevy 	if (unlikely(!p))
3145c0eae66eSBenny Halevy 		goto out_overflow;
31461da177e4SLinus Torvalds 	hdr->tag = (char *)p;
31471da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3148cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3149aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3150aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
31511da177e4SLinus Torvalds 	return 0;
3152c0eae66eSBenny Halevy out_overflow:
3153c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3154c0eae66eSBenny Halevy 	return -EIO;
31551da177e4SLinus Torvalds }
31561da177e4SLinus Torvalds 
3157c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3158c7848f69STrond Myklebust 		int *nfs_retval)
31591da177e4SLinus Torvalds {
31608687b63aSAl Viro 	__be32 *p;
31611da177e4SLinus Torvalds 	uint32_t opnum;
31621da177e4SLinus Torvalds 	int32_t nfserr;
31631da177e4SLinus Torvalds 
3164c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3165c0eae66eSBenny Halevy 	if (unlikely(!p))
3166c0eae66eSBenny Halevy 		goto out_overflow;
31676f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
3168c7848f69STrond Myklebust 	if (unlikely(opnum != expected))
3169c7848f69STrond Myklebust 		goto out_bad_operation;
3170c7848f69STrond Myklebust 	nfserr = be32_to_cpup(p);
3171c7848f69STrond Myklebust 	if (nfserr == NFS_OK)
3172c7848f69STrond Myklebust 		*nfs_retval = 0;
3173c7848f69STrond Myklebust 	else
3174c7848f69STrond Myklebust 		*nfs_retval = nfs4_stat_to_errno(nfserr);
3175c7848f69STrond Myklebust 	return true;
3176c7848f69STrond Myklebust out_bad_operation:
3177fe82a183SChuck Lever 	dprintk("nfs: Server returned operation"
31781da177e4SLinus Torvalds 		" %d but we issued a request for %d\n",
31791da177e4SLinus Torvalds 			opnum, expected);
3180c7848f69STrond Myklebust 	*nfs_retval = -EREMOTEIO;
3181c7848f69STrond Myklebust 	return false;
3182c0eae66eSBenny Halevy out_overflow:
3183c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3184c7848f69STrond Myklebust 	*nfs_retval = -EIO;
3185c7848f69STrond Myklebust 	return false;
3186c7848f69STrond Myklebust }
3187c7848f69STrond Myklebust 
3188c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3189c7848f69STrond Myklebust {
3190c7848f69STrond Myklebust 	int retval;
3191c7848f69STrond Myklebust 
3192c7848f69STrond Myklebust 	__decode_op_hdr(xdr, expected, &retval);
3193c7848f69STrond Myklebust 	return retval;
31941da177e4SLinus Torvalds }
31951da177e4SLinus Torvalds 
31961da177e4SLinus Torvalds /* Dummy routine */
31971bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace)
31981da177e4SLinus Torvalds {
31998687b63aSAl Viro 	__be32 *p;
3200683b57b4STrond Myklebust 	unsigned int strlen;
32011da177e4SLinus Torvalds 	char *str;
32021da177e4SLinus Torvalds 
3203c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3204c0eae66eSBenny Halevy 	if (likely(p))
32051da177e4SLinus Torvalds 		return decode_opaque_inline(xdr, &strlen, &str);
3206c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3207c0eae66eSBenny Halevy 	return -EIO;
32081da177e4SLinus Torvalds }
32091da177e4SLinus Torvalds 
321037c88763STrond Myklebust static ssize_t
321137c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
32121da177e4SLinus Torvalds {
321337c88763STrond Myklebust 	ssize_t ret;
32141da177e4SLinus Torvalds 
321537c88763STrond Myklebust 	ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
321637c88763STrond Myklebust 	if (likely(ret >= 0))
321737c88763STrond Myklebust 		return ret;
321837c88763STrond Myklebust 	if (ret == -EMSGSIZE)
321937c88763STrond Myklebust 		return sz;
3220c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3221c0eae66eSBenny Halevy 	return -EIO;
32221da177e4SLinus Torvalds }
32231da177e4SLinus Torvalds 
322437c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
322537c88763STrond Myklebust {
322637c88763STrond Myklebust 	ssize_t ret;
322737c88763STrond Myklebust 	ret = decode_bitmap4(xdr, bitmap, 3);
322837c88763STrond Myklebust 	return ret < 0 ? ret : 0;
322937c88763STrond Myklebust }
323037c88763STrond Myklebust 
3231256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
32321da177e4SLinus Torvalds {
32338687b63aSAl Viro 	__be32 *p;
32341da177e4SLinus Torvalds 
3235c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3236c0eae66eSBenny Halevy 	if (unlikely(!p))
3237c0eae66eSBenny Halevy 		goto out_overflow;
3238cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
3239256e48bbSTrond Myklebust 	*savep = xdr_stream_pos(xdr);
32401da177e4SLinus Torvalds 	return 0;
3241c0eae66eSBenny Halevy out_overflow:
3242c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3243c0eae66eSBenny Halevy 	return -EIO;
32441da177e4SLinus Torvalds }
32451da177e4SLinus Torvalds 
32461da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
32471da177e4SLinus Torvalds {
32481da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
32493388bff5SRoman Borisov 		int ret;
32503388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
32513388bff5SRoman Borisov 		if (unlikely(ret < 0))
32523388bff5SRoman Borisov 			return ret;
32531da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
32541da177e4SLinus Torvalds 	} else
3255dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3256dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3257dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
32581da177e4SLinus Torvalds 	return 0;
32591da177e4SLinus Torvalds }
32601da177e4SLinus Torvalds 
32611da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
32621da177e4SLinus Torvalds {
32638687b63aSAl Viro 	__be32 *p;
3264409924e4STrond Myklebust 	int ret = 0;
32651da177e4SLinus Torvalds 
32661da177e4SLinus Torvalds 	*type = 0;
32671da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
32681da177e4SLinus Torvalds 		return -EIO;
32691da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3270c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3271c0eae66eSBenny Halevy 		if (unlikely(!p))
3272c0eae66eSBenny Halevy 			goto out_overflow;
3273cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
32741da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
32753110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
32761da177e4SLinus Torvalds 			return -EIO;
32771da177e4SLinus Torvalds 		}
32781da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3279409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32801da177e4SLinus Torvalds 	}
3281bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3282409924e4STrond Myklebust 	return ret;
3283c0eae66eSBenny Halevy out_overflow:
3284c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3285c0eae66eSBenny Halevy 	return -EIO;
32861da177e4SLinus Torvalds }
32871da177e4SLinus Torvalds 
3288264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3289264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3290264e6351SChuck Lever {
3291264e6351SChuck Lever 	__be32 *p;
3292264e6351SChuck Lever 
3293264e6351SChuck Lever 	*type = 0;
3294264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3295264e6351SChuck Lever 		return -EIO;
3296264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3297264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3298264e6351SChuck Lever 		if (unlikely(!p))
3299264e6351SChuck Lever 			goto out_overflow;
3300264e6351SChuck Lever 		*type = be32_to_cpup(p);
3301264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3302264e6351SChuck Lever 	}
3303264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3304264e6351SChuck Lever 	return 0;
3305264e6351SChuck Lever out_overflow:
3306264e6351SChuck Lever 	print_overflow_msg(__func__, xdr);
3307264e6351SChuck Lever 	return -EIO;
3308264e6351SChuck Lever }
3309264e6351SChuck Lever 
33101da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
33111da177e4SLinus Torvalds {
33128687b63aSAl Viro 	__be32 *p;
3313409924e4STrond Myklebust 	int ret = 0;
33141da177e4SLinus Torvalds 
33151da177e4SLinus Torvalds 	*change = 0;
33161da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
33171da177e4SLinus Torvalds 		return -EIO;
33181da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3319c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3320c0eae66eSBenny Halevy 		if (unlikely(!p))
3321c0eae66eSBenny Halevy 			goto out_overflow;
3322cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
33231da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3324409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
33251da177e4SLinus Torvalds 	}
33263110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
33271da177e4SLinus Torvalds 			(unsigned long long)*change);
3328409924e4STrond Myklebust 	return ret;
3329c0eae66eSBenny Halevy out_overflow:
3330c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3331c0eae66eSBenny Halevy 	return -EIO;
33321da177e4SLinus Torvalds }
33331da177e4SLinus Torvalds 
33341da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
33351da177e4SLinus Torvalds {
33368687b63aSAl Viro 	__be32 *p;
3337409924e4STrond Myklebust 	int ret = 0;
33381da177e4SLinus Torvalds 
33391da177e4SLinus Torvalds 	*size = 0;
33401da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
33411da177e4SLinus Torvalds 		return -EIO;
33421da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3343c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3344c0eae66eSBenny Halevy 		if (unlikely(!p))
3345c0eae66eSBenny Halevy 			goto out_overflow;
3346cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
33471da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3348409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
33491da177e4SLinus Torvalds 	}
33503110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3351409924e4STrond Myklebust 	return ret;
3352c0eae66eSBenny Halevy out_overflow:
3353c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3354c0eae66eSBenny Halevy 	return -EIO;
33551da177e4SLinus Torvalds }
33561da177e4SLinus Torvalds 
33571da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33581da177e4SLinus Torvalds {
33598687b63aSAl Viro 	__be32 *p;
33601da177e4SLinus Torvalds 
33611da177e4SLinus Torvalds 	*res = 0;
33621da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
33631da177e4SLinus Torvalds 		return -EIO;
33641da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3365c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3366c0eae66eSBenny Halevy 		if (unlikely(!p))
3367c0eae66eSBenny Halevy 			goto out_overflow;
3368cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33691da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
33701da177e4SLinus Torvalds 	}
33713110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
33721da177e4SLinus Torvalds 	return 0;
3373c0eae66eSBenny Halevy out_overflow:
3374c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3375c0eae66eSBenny Halevy 	return -EIO;
33761da177e4SLinus Torvalds }
33771da177e4SLinus Torvalds 
33781da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33791da177e4SLinus Torvalds {
33808687b63aSAl Viro 	__be32 *p;
33811da177e4SLinus Torvalds 
33821da177e4SLinus Torvalds 	*res = 0;
33831da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
33841da177e4SLinus Torvalds 		return -EIO;
33851da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3386c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3387c0eae66eSBenny Halevy 		if (unlikely(!p))
3388c0eae66eSBenny Halevy 			goto out_overflow;
3389cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33901da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
33911da177e4SLinus Torvalds 	}
33923110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
33931da177e4SLinus Torvalds 	return 0;
3394c0eae66eSBenny Halevy out_overflow:
3395c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3396c0eae66eSBenny Halevy 	return -EIO;
33971da177e4SLinus Torvalds }
33981da177e4SLinus Torvalds 
33998b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
34001da177e4SLinus Torvalds {
34018687b63aSAl Viro 	__be32 *p;
3402409924e4STrond Myklebust 	int ret = 0;
34031da177e4SLinus Torvalds 
34041da177e4SLinus Torvalds 	fsid->major = 0;
34051da177e4SLinus Torvalds 	fsid->minor = 0;
34061da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
34071da177e4SLinus Torvalds 		return -EIO;
34081da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3409c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3410c0eae66eSBenny Halevy 		if (unlikely(!p))
3411c0eae66eSBenny Halevy 			goto out_overflow;
34123ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3413cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
34141da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3415409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
34161da177e4SLinus Torvalds 	}
34173110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
34181da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
34191da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3420409924e4STrond Myklebust 	return ret;
3421c0eae66eSBenny Halevy out_overflow:
3422c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3423c0eae66eSBenny Halevy 	return -EIO;
34241da177e4SLinus Torvalds }
34251da177e4SLinus Torvalds 
34261da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34271da177e4SLinus Torvalds {
34288687b63aSAl Viro 	__be32 *p;
34291da177e4SLinus Torvalds 
34301da177e4SLinus Torvalds 	*res = 60;
34311da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
34321da177e4SLinus Torvalds 		return -EIO;
34331da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3434c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3435c0eae66eSBenny Halevy 		if (unlikely(!p))
3436c0eae66eSBenny Halevy 			goto out_overflow;
3437cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34381da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
34391da177e4SLinus Torvalds 	}
34403110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
34411da177e4SLinus Torvalds 	return 0;
3442c0eae66eSBenny Halevy out_overflow:
3443c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3444c0eae66eSBenny Halevy 	return -EIO;
34451da177e4SLinus Torvalds }
34461da177e4SLinus Torvalds 
3447ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3448ae42c70aSBryan Schumaker {
3449ae42c70aSBryan Schumaker 	__be32 *p;
3450ae42c70aSBryan Schumaker 
3451ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3452ae42c70aSBryan Schumaker 		return -EIO;
3453ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3454ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3455ae42c70aSBryan Schumaker 		if (unlikely(!p))
3456ae42c70aSBryan Schumaker 			goto out_overflow;
3457ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3458ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3459ae42c70aSBryan Schumaker 	}
3460ae42c70aSBryan Schumaker 	return 0;
3461ae42c70aSBryan Schumaker out_overflow:
3462ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3463ae42c70aSBryan Schumaker 	return -EIO;
3464ae42c70aSBryan Schumaker }
3465ae42c70aSBryan Schumaker 
34668c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
34678c61282fSKinglong Mee 				 uint32_t *bitmap, uint32_t *bitmask)
34688c61282fSKinglong Mee {
34698c61282fSKinglong Mee 	if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
34708c61282fSKinglong Mee 		int ret;
34718c61282fSKinglong Mee 		ret = decode_attr_bitmap(xdr, bitmask);
34728c61282fSKinglong Mee 		if (unlikely(ret < 0))
34738c61282fSKinglong Mee 			return ret;
34748c61282fSKinglong Mee 		bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
34758c61282fSKinglong Mee 	} else
34768c61282fSKinglong Mee 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
34778c61282fSKinglong Mee 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
34788c61282fSKinglong Mee 		bitmask[0], bitmask[1], bitmask[2]);
34798c61282fSKinglong Mee 	return 0;
34808c61282fSKinglong Mee }
34818c61282fSKinglong Mee 
3482ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3483ae42c70aSBryan Schumaker {
3484ae42c70aSBryan Schumaker 	__be32 *p;
3485ae42c70aSBryan Schumaker 	int len;
3486ae42c70aSBryan Schumaker 
34877ad07353STrond Myklebust 	if (fh != NULL)
3488ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3489ae42c70aSBryan Schumaker 
3490ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3491ae42c70aSBryan Schumaker 		return -EIO;
3492ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3493ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3494ae42c70aSBryan Schumaker 		if (unlikely(!p))
3495ae42c70aSBryan Schumaker 			goto out_overflow;
3496ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3497ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3498ae42c70aSBryan Schumaker 			return -EIO;
3499ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3500ae42c70aSBryan Schumaker 		if (unlikely(!p))
3501ae42c70aSBryan Schumaker 			goto out_overflow;
35027ad07353STrond Myklebust 		if (fh != NULL) {
3503ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
35047ad07353STrond Myklebust 			fh->size = len;
35057ad07353STrond Myklebust 		}
3506ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3507ae42c70aSBryan Schumaker 	}
3508ae42c70aSBryan Schumaker 	return 0;
3509ae42c70aSBryan Schumaker out_overflow:
3510ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3511ae42c70aSBryan Schumaker 	return -EIO;
3512ae42c70aSBryan Schumaker }
3513ae42c70aSBryan Schumaker 
35141da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
35151da177e4SLinus Torvalds {
35168687b63aSAl Viro 	__be32 *p;
35171da177e4SLinus Torvalds 
3518a1800acaSMalahal Naineni 	*res = 0;
35191da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
35201da177e4SLinus Torvalds 		return -EIO;
35211da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3522c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3523c0eae66eSBenny Halevy 		if (unlikely(!p))
3524c0eae66eSBenny Halevy 			goto out_overflow;
3525cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
35261da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
35271da177e4SLinus Torvalds 	}
35283110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
35291da177e4SLinus Torvalds 	return 0;
3530c0eae66eSBenny Halevy out_overflow:
3531c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3532c0eae66eSBenny Halevy 	return -EIO;
35331da177e4SLinus Torvalds }
35341da177e4SLinus Torvalds 
35351da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
35361da177e4SLinus Torvalds {
35378687b63aSAl Viro 	__be32 *p;
3538409924e4STrond Myklebust 	int ret = 0;
35391da177e4SLinus Torvalds 
35401da177e4SLinus Torvalds 	*fileid = 0;
35411da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
35421da177e4SLinus Torvalds 		return -EIO;
35431da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3544c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3545c0eae66eSBenny Halevy 		if (unlikely(!p))
3546c0eae66eSBenny Halevy 			goto out_overflow;
3547cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
35481da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3549409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
35501da177e4SLinus Torvalds 	}
35513110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3552409924e4STrond Myklebust 	return ret;
3553c0eae66eSBenny Halevy out_overflow:
3554c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3555c0eae66eSBenny Halevy 	return -EIO;
35561da177e4SLinus Torvalds }
35571da177e4SLinus Torvalds 
355899baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
355999baf625SManoj Naik {
35608687b63aSAl Viro 	__be32 *p;
3561409924e4STrond Myklebust 	int ret = 0;
356299baf625SManoj Naik 
356399baf625SManoj Naik 	*fileid = 0;
356499baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
356599baf625SManoj Naik 		return -EIO;
356699baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3567c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3568c0eae66eSBenny Halevy 		if (unlikely(!p))
3569c0eae66eSBenny Halevy 			goto out_overflow;
3570cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
357199baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
357228331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
357399baf625SManoj Naik 	}
35743110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3575409924e4STrond Myklebust 	return ret;
3576c0eae66eSBenny Halevy out_overflow:
3577c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3578c0eae66eSBenny Halevy 	return -EIO;
357999baf625SManoj Naik }
358099baf625SManoj Naik 
35811da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35821da177e4SLinus Torvalds {
35838687b63aSAl Viro 	__be32 *p;
35841da177e4SLinus Torvalds 	int status = 0;
35851da177e4SLinus Torvalds 
35861da177e4SLinus Torvalds 	*res = 0;
35871da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
35881da177e4SLinus Torvalds 		return -EIO;
35891da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3590c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3591c0eae66eSBenny Halevy 		if (unlikely(!p))
3592c0eae66eSBenny Halevy 			goto out_overflow;
3593cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35941da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
35951da177e4SLinus Torvalds 	}
35963110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
35971da177e4SLinus Torvalds 	return status;
3598c0eae66eSBenny Halevy out_overflow:
3599c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3600c0eae66eSBenny Halevy 	return -EIO;
36011da177e4SLinus Torvalds }
36021da177e4SLinus Torvalds 
36031da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36041da177e4SLinus Torvalds {
36058687b63aSAl Viro 	__be32 *p;
36061da177e4SLinus Torvalds 	int status = 0;
36071da177e4SLinus Torvalds 
36081da177e4SLinus Torvalds 	*res = 0;
36091da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
36101da177e4SLinus Torvalds 		return -EIO;
36111da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3612c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3613c0eae66eSBenny Halevy 		if (unlikely(!p))
3614c0eae66eSBenny Halevy 			goto out_overflow;
3615cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
36161da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
36171da177e4SLinus Torvalds 	}
36183110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
36191da177e4SLinus Torvalds 	return status;
3620c0eae66eSBenny Halevy out_overflow:
3621c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3622c0eae66eSBenny Halevy 	return -EIO;
36231da177e4SLinus Torvalds }
36241da177e4SLinus Torvalds 
36251da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36261da177e4SLinus Torvalds {
36278687b63aSAl Viro 	__be32 *p;
36281da177e4SLinus Torvalds 	int status = 0;
36291da177e4SLinus Torvalds 
36301da177e4SLinus Torvalds 	*res = 0;
36311da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
36321da177e4SLinus Torvalds 		return -EIO;
36331da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3634c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3635c0eae66eSBenny Halevy 		if (unlikely(!p))
3636c0eae66eSBenny Halevy 			goto out_overflow;
3637cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
36381da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
36391da177e4SLinus Torvalds 	}
36403110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
36411da177e4SLinus Torvalds 	return status;
3642c0eae66eSBenny Halevy out_overflow:
3643c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3644c0eae66eSBenny Halevy 	return -EIO;
36451da177e4SLinus Torvalds }
36461da177e4SLinus Torvalds 
36477aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
36487aaa0b3bSManoj Naik {
3649464ad6b1SChuck Lever 	u32 n;
36508687b63aSAl Viro 	__be32 *p;
36517aaa0b3bSManoj Naik 	int status = 0;
36527aaa0b3bSManoj Naik 
3653c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3654c0eae66eSBenny Halevy 	if (unlikely(!p))
3655c0eae66eSBenny Halevy 		goto out_overflow;
3656cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
365733a43f28SAndy Adamson 	if (n == 0)
365833a43f28SAndy Adamson 		goto root_path;
365902a2976cSChuck Lever 	dprintk("pathname4: ");
3660809b426cSTrond Myklebust 	if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3661809b426cSTrond Myklebust 		dprintk("cannot parse %d components in path\n", n);
3662809b426cSTrond Myklebust 		goto out_eio;
3663809b426cSTrond Myklebust 	}
3664809b426cSTrond Myklebust 	for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
36657aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
36667aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
36677aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36687aaa0b3bSManoj Naik 			goto out_eio;
366995a13f7bSTrond Myklebust 		ifdebug (XDR)
367002a2976cSChuck Lever 			pr_cont("%s%.*s ",
367102a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
367202a2976cSChuck Lever 				component->len, component->data);
36737aaa0b3bSManoj Naik 	}
36747aaa0b3bSManoj Naik out:
36757aaa0b3bSManoj Naik 	return status;
367633a43f28SAndy Adamson root_path:
367733a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
367833a43f28SAndy Adamson 	path->ncomponents = 1;
367933a43f28SAndy Adamson 	path->components[0].len=0;
368033a43f28SAndy Adamson 	path->components[0].data=NULL;
368102a2976cSChuck Lever 	dprintk("pathname4: /\n");
368233a43f28SAndy Adamson 	goto out;
36837aaa0b3bSManoj Naik out_eio:
36847aaa0b3bSManoj Naik 	dprintk(" status %d", status);
36857aaa0b3bSManoj Naik 	status = -EIO;
36867aaa0b3bSManoj Naik 	goto out;
3687c0eae66eSBenny Halevy out_overflow:
3688c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3689c0eae66eSBenny Halevy 	return -EIO;
36907aaa0b3bSManoj Naik }
36917aaa0b3bSManoj Naik 
36927aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3693683b57b4STrond Myklebust {
3694683b57b4STrond Myklebust 	int n;
36958687b63aSAl Viro 	__be32 *p;
3696683b57b4STrond Myklebust 	int status = -EIO;
3697683b57b4STrond Myklebust 
3698683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3699683b57b4STrond Myklebust 		goto out;
3700683b57b4STrond Myklebust 	status = 0;
3701683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3702683b57b4STrond Myklebust 		goto out;
3703f54423a1SKinglong Mee 	bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
37048b7e3f49STrond Myklebust 	status = -EIO;
37058b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
37068b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
37078b7e3f49STrond Myklebust 		goto out;
370802a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
37097aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3710683b57b4STrond Myklebust 	if (unlikely(status != 0))
3711683b57b4STrond Myklebust 		goto out;
3712c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3713c0eae66eSBenny Halevy 	if (unlikely(!p))
3714c0eae66eSBenny Halevy 		goto out_overflow;
3715cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3716683b57b4STrond Myklebust 	if (n <= 0)
3717683b57b4STrond Myklebust 		goto out_eio;
3718809b426cSTrond Myklebust 	for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3719464ad6b1SChuck Lever 		u32 m;
3720809b426cSTrond Myklebust 		struct nfs4_fs_location *loc;
3721683b57b4STrond Myklebust 
3722809b426cSTrond Myklebust 		if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3723809b426cSTrond Myklebust 			break;
3724809b426cSTrond Myklebust 		loc = &res->locations[res->nlocations];
3725c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3726c0eae66eSBenny Halevy 		if (unlikely(!p))
3727c0eae66eSBenny Halevy 			goto out_overflow;
3728cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
37297aaa0b3bSManoj Naik 
373002a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
3731809b426cSTrond Myklebust 		for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3732809b426cSTrond Myklebust 			struct nfs4_string *server;
3733809b426cSTrond Myklebust 
3734809b426cSTrond Myklebust 			if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3735464ad6b1SChuck Lever 				unsigned int i;
3736464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3737464ad6b1SChuck Lever 					"returned for location %u\n",
37383110ff80SHarvey Harrison 						__func__,
3739464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3740464ad6b1SChuck Lever 						m, res->nlocations);
37417aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
37422e42c3e2STrond Myklebust 					unsigned int len;
37437aaa0b3bSManoj Naik 					char *data;
37447aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3745683b57b4STrond Myklebust 					if (unlikely(status != 0))
3746683b57b4STrond Myklebust 						goto out_eio;
37477aaa0b3bSManoj Naik 				}
3748809b426cSTrond Myklebust 				break;
37497aaa0b3bSManoj Naik 			}
3750809b426cSTrond Myklebust 			server = &loc->servers[loc->nservers];
3751809b426cSTrond Myklebust 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3752809b426cSTrond Myklebust 			if (unlikely(status != 0))
3753809b426cSTrond Myklebust 				goto out_eio;
3754809b426cSTrond Myklebust 			dprintk("%s ", server->data);
37557aaa0b3bSManoj Naik 		}
37567aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
37577aaa0b3bSManoj Naik 		if (unlikely(status != 0))
37587aaa0b3bSManoj Naik 			goto out_eio;
3759683b57b4STrond Myklebust 	}
3760409924e4STrond Myklebust 	if (res->nlocations != 0)
376181934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3762683b57b4STrond Myklebust out:
37633110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3764683b57b4STrond Myklebust 	return status;
3765c0eae66eSBenny Halevy out_overflow:
3766c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3767683b57b4STrond Myklebust out_eio:
3768683b57b4STrond Myklebust 	status = -EIO;
3769683b57b4STrond Myklebust 	goto out;
3770683b57b4STrond Myklebust }
3771683b57b4STrond Myklebust 
37721da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
37731da177e4SLinus Torvalds {
37748687b63aSAl Viro 	__be32 *p;
37751da177e4SLinus Torvalds 	int status = 0;
37761da177e4SLinus Torvalds 
37771da177e4SLinus Torvalds 	*res = 0;
37781da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
37791da177e4SLinus Torvalds 		return -EIO;
37801da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3781c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3782c0eae66eSBenny Halevy 		if (unlikely(!p))
3783c0eae66eSBenny Halevy 			goto out_overflow;
3784cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
37851da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
37861da177e4SLinus Torvalds 	}
37873110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
37881da177e4SLinus Torvalds 	return status;
3789c0eae66eSBenny Halevy out_overflow:
3790c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3791c0eae66eSBenny Halevy 	return -EIO;
37921da177e4SLinus Torvalds }
37931da177e4SLinus Torvalds 
37941da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
37951da177e4SLinus Torvalds {
37968687b63aSAl Viro 	__be32 *p;
37971da177e4SLinus Torvalds 	int status = 0;
37981da177e4SLinus Torvalds 
37991da177e4SLinus Torvalds 	*maxlink = 1;
38001da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
38011da177e4SLinus Torvalds 		return -EIO;
38021da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3803c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3804c0eae66eSBenny Halevy 		if (unlikely(!p))
3805c0eae66eSBenny Halevy 			goto out_overflow;
3806cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
38071da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
38081da177e4SLinus Torvalds 	}
38093110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
38101da177e4SLinus Torvalds 	return status;
3811c0eae66eSBenny Halevy out_overflow:
3812c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3813c0eae66eSBenny Halevy 	return -EIO;
38141da177e4SLinus Torvalds }
38151da177e4SLinus Torvalds 
38161da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
38171da177e4SLinus Torvalds {
38188687b63aSAl Viro 	__be32 *p;
38191da177e4SLinus Torvalds 	int status = 0;
38201da177e4SLinus Torvalds 
38211da177e4SLinus Torvalds 	*maxname = 1024;
38221da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
38231da177e4SLinus Torvalds 		return -EIO;
38241da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3825c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3826c0eae66eSBenny Halevy 		if (unlikely(!p))
3827c0eae66eSBenny Halevy 			goto out_overflow;
3828cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
38291da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
38301da177e4SLinus Torvalds 	}
38313110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
38321da177e4SLinus Torvalds 	return status;
3833c0eae66eSBenny Halevy out_overflow:
3834c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3835c0eae66eSBenny Halevy 	return -EIO;
38361da177e4SLinus Torvalds }
38371da177e4SLinus Torvalds 
38381da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
38391da177e4SLinus Torvalds {
38408687b63aSAl Viro 	__be32 *p;
38411da177e4SLinus Torvalds 	int status = 0;
38421da177e4SLinus Torvalds 
38431da177e4SLinus Torvalds 	*res = 1024;
38441da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
38451da177e4SLinus Torvalds 		return -EIO;
38461da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
38471da177e4SLinus Torvalds 		uint64_t maxread;
3848c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3849c0eae66eSBenny Halevy 		if (unlikely(!p))
3850c0eae66eSBenny Halevy 			goto out_overflow;
3851cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
38521da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
38531da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
38541da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
38551da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
38561da177e4SLinus Torvalds 	}
38573110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
38581da177e4SLinus Torvalds 	return status;
3859c0eae66eSBenny Halevy out_overflow:
3860c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3861c0eae66eSBenny Halevy 	return -EIO;
38621da177e4SLinus Torvalds }
38631da177e4SLinus Torvalds 
38641da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
38651da177e4SLinus Torvalds {
38668687b63aSAl Viro 	__be32 *p;
38671da177e4SLinus Torvalds 	int status = 0;
38681da177e4SLinus Torvalds 
38691da177e4SLinus Torvalds 	*res = 1024;
38701da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
38711da177e4SLinus Torvalds 		return -EIO;
38721da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
38731da177e4SLinus Torvalds 		uint64_t maxwrite;
3874c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3875c0eae66eSBenny Halevy 		if (unlikely(!p))
3876c0eae66eSBenny Halevy 			goto out_overflow;
3877cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
38781da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
38791da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
38801da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
38811da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
38821da177e4SLinus Torvalds 	}
38833110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
38841da177e4SLinus Torvalds 	return status;
3885c0eae66eSBenny Halevy out_overflow:
3886c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3887c0eae66eSBenny Halevy 	return -EIO;
38881da177e4SLinus Torvalds }
38891da177e4SLinus Torvalds 
3890bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
38911da177e4SLinus Torvalds {
3892bca79478STrond Myklebust 	uint32_t tmp;
38938687b63aSAl Viro 	__be32 *p;
3894409924e4STrond Myklebust 	int ret = 0;
38951da177e4SLinus Torvalds 
38961da177e4SLinus Torvalds 	*mode = 0;
38971da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38981da177e4SLinus Torvalds 		return -EIO;
38991da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3900c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3901c0eae66eSBenny Halevy 		if (unlikely(!p))
3902c0eae66eSBenny Halevy 			goto out_overflow;
3903cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3904bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
39051da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3906409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
39071da177e4SLinus Torvalds 	}
39083110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3909409924e4STrond Myklebust 	return ret;
3910c0eae66eSBenny Halevy out_overflow:
3911c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3912c0eae66eSBenny Halevy 	return -EIO;
39131da177e4SLinus Torvalds }
39141da177e4SLinus Torvalds 
39151da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
39161da177e4SLinus Torvalds {
39178687b63aSAl Viro 	__be32 *p;
3918409924e4STrond Myklebust 	int ret = 0;
39191da177e4SLinus Torvalds 
39201da177e4SLinus Torvalds 	*nlink = 1;
39211da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
39221da177e4SLinus Torvalds 		return -EIO;
39231da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3924c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3925c0eae66eSBenny Halevy 		if (unlikely(!p))
3926c0eae66eSBenny Halevy 			goto out_overflow;
3927cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
39281da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3929409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
39301da177e4SLinus Torvalds 	}
39313110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3932409924e4STrond Myklebust 	return ret;
3933c0eae66eSBenny Halevy out_overflow:
3934c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3935c0eae66eSBenny Halevy 	return -EIO;
39361da177e4SLinus Torvalds }
39371da177e4SLinus Torvalds 
3938686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3939686a816aSTrond Myklebust 		struct nfs4_string *name, gfp_t gfp_flags)
3940686a816aSTrond Myklebust {
3941686a816aSTrond Myklebust 	ssize_t ret;
3942686a816aSTrond Myklebust 
3943686a816aSTrond Myklebust 	ret = xdr_stream_decode_string_dup(xdr, &name->data,
3944686a816aSTrond Myklebust 			XDR_MAX_NETOBJ, gfp_flags);
3945686a816aSTrond Myklebust 	name->len = 0;
3946686a816aSTrond Myklebust 	if (ret > 0)
3947686a816aSTrond Myklebust 		name->len = ret;
3948686a816aSTrond Myklebust 	return ret;
3949686a816aSTrond Myklebust }
3950686a816aSTrond Myklebust 
395180e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3952e5782076SEric W. Biederman 		const struct nfs_server *server, kuid_t *uid,
39536926afd1STrond Myklebust 		struct nfs4_string *owner_name)
39541da177e4SLinus Torvalds {
3955686a816aSTrond Myklebust 	ssize_t len;
3956686a816aSTrond Myklebust 	char *p;
39571da177e4SLinus Torvalds 
3958e5782076SEric W. Biederman 	*uid = make_kuid(&init_user_ns, -2);
39591da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
39601da177e4SLinus Torvalds 		return -EIO;
3961686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3962686a816aSTrond Myklebust 		return 0;
39631da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER;
3964686a816aSTrond Myklebust 
3965686a816aSTrond Myklebust 	if (owner_name != NULL) {
3966e8d8aa46STrond Myklebust 		len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
3967686a816aSTrond Myklebust 		if (len <= 0)
3968686a816aSTrond Myklebust 			goto out;
3969686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, owner_name->data);
3970686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER_NAME;
3971686a816aSTrond Myklebust 	} else {
3972686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3973686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
3974686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3975686a816aSTrond Myklebust 			goto out;
3976e5782076SEric W. Biederman 		dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3977686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER;
3978686a816aSTrond Myklebust 	}
3979686a816aSTrond Myklebust out:
3980686a816aSTrond Myklebust 	if (len != -EBADMSG)
3981686a816aSTrond Myklebust 		return 0;
3982c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3983c0eae66eSBenny Halevy 	return -EIO;
39841da177e4SLinus Torvalds }
39851da177e4SLinus Torvalds 
398680e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3987e5782076SEric W. Biederman 		const struct nfs_server *server, kgid_t *gid,
39886926afd1STrond Myklebust 		struct nfs4_string *group_name)
39891da177e4SLinus Torvalds {
3990686a816aSTrond Myklebust 	ssize_t len;
3991686a816aSTrond Myklebust 	char *p;
39921da177e4SLinus Torvalds 
3993e5782076SEric W. Biederman 	*gid = make_kgid(&init_user_ns, -2);
39941da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
39951da177e4SLinus Torvalds 		return -EIO;
3996686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3997686a816aSTrond Myklebust 		return 0;
39981da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3999686a816aSTrond Myklebust 
4000686a816aSTrond Myklebust 	if (group_name != NULL) {
4001e8d8aa46STrond Myklebust 		len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
4002686a816aSTrond Myklebust 		if (len <= 0)
4003686a816aSTrond Myklebust 			goto out;
4004686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, group_name->data);
40056f1f6220SKinglong Mee 		return NFS_ATTR_FATTR_GROUP_NAME;
4006686a816aSTrond Myklebust 	} else {
4007686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4008686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
4009686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4010686a816aSTrond Myklebust 			goto out;
4011e5782076SEric W. Biederman 		dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4012686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_GROUP;
4013686a816aSTrond Myklebust 	}
4014686a816aSTrond Myklebust out:
4015686a816aSTrond Myklebust 	if (len != -EBADMSG)
4016686a816aSTrond Myklebust 		return 0;
4017c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4018c0eae66eSBenny Halevy 	return -EIO;
40191da177e4SLinus Torvalds }
40201da177e4SLinus Torvalds 
40211da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
40221da177e4SLinus Torvalds {
40238687b63aSAl Viro 	uint32_t major = 0, minor = 0;
40248687b63aSAl Viro 	__be32 *p;
4025409924e4STrond Myklebust 	int ret = 0;
40261da177e4SLinus Torvalds 
40271da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
40281da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
40291da177e4SLinus Torvalds 		return -EIO;
40301da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
40311da177e4SLinus Torvalds 		dev_t tmp;
40321da177e4SLinus Torvalds 
4033c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4034c0eae66eSBenny Halevy 		if (unlikely(!p))
4035c0eae66eSBenny Halevy 			goto out_overflow;
40366f723f77SBenny Halevy 		major = be32_to_cpup(p++);
4037cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
40381da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
40391da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
40401da177e4SLinus Torvalds 			*rdev = tmp;
40411da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
4042409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
40431da177e4SLinus Torvalds 	}
40443110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
4045409924e4STrond Myklebust 	return ret;
4046c0eae66eSBenny Halevy out_overflow:
4047c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4048c0eae66eSBenny Halevy 	return -EIO;
40491da177e4SLinus Torvalds }
40501da177e4SLinus Torvalds 
40511da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40521da177e4SLinus Torvalds {
40538687b63aSAl Viro 	__be32 *p;
40541da177e4SLinus Torvalds 	int status = 0;
40551da177e4SLinus Torvalds 
40561da177e4SLinus Torvalds 	*res = 0;
40571da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
40581da177e4SLinus Torvalds 		return -EIO;
40591da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4060c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4061c0eae66eSBenny Halevy 		if (unlikely(!p))
4062c0eae66eSBenny Halevy 			goto out_overflow;
4063cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40641da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
40651da177e4SLinus Torvalds 	}
40663110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
40671da177e4SLinus Torvalds 	return status;
4068c0eae66eSBenny Halevy out_overflow:
4069c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4070c0eae66eSBenny Halevy 	return -EIO;
40711da177e4SLinus Torvalds }
40721da177e4SLinus Torvalds 
40731da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40741da177e4SLinus Torvalds {
40758687b63aSAl Viro 	__be32 *p;
40761da177e4SLinus Torvalds 	int status = 0;
40771da177e4SLinus Torvalds 
40781da177e4SLinus Torvalds 	*res = 0;
40791da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40801da177e4SLinus Torvalds 		return -EIO;
40811da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4082c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4083c0eae66eSBenny Halevy 		if (unlikely(!p))
4084c0eae66eSBenny Halevy 			goto out_overflow;
4085cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40861da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40871da177e4SLinus Torvalds 	}
40883110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40891da177e4SLinus Torvalds 	return status;
4090c0eae66eSBenny Halevy out_overflow:
4091c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4092c0eae66eSBenny Halevy 	return -EIO;
40931da177e4SLinus Torvalds }
40941da177e4SLinus Torvalds 
40951da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40961da177e4SLinus Torvalds {
40978687b63aSAl Viro 	__be32 *p;
40981da177e4SLinus Torvalds 	int status = 0;
40991da177e4SLinus Torvalds 
41001da177e4SLinus Torvalds 	*res = 0;
41011da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
41021da177e4SLinus Torvalds 		return -EIO;
41031da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4104c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4105c0eae66eSBenny Halevy 		if (unlikely(!p))
4106c0eae66eSBenny Halevy 			goto out_overflow;
4107cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
41081da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
41091da177e4SLinus Torvalds 	}
41103110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
41111da177e4SLinus Torvalds 	return status;
4112c0eae66eSBenny Halevy out_overflow:
4113c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4114c0eae66eSBenny Halevy 	return -EIO;
41151da177e4SLinus Torvalds }
41161da177e4SLinus Torvalds 
41171da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
41181da177e4SLinus Torvalds {
41198687b63aSAl Viro 	__be32 *p;
4120409924e4STrond Myklebust 	int ret = 0;
41211da177e4SLinus Torvalds 
41221da177e4SLinus Torvalds 	*used = 0;
41231da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
41241da177e4SLinus Torvalds 		return -EIO;
41251da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4126c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4127c0eae66eSBenny Halevy 		if (unlikely(!p))
4128c0eae66eSBenny Halevy 			goto out_overflow;
4129cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
41301da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4131409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
41321da177e4SLinus Torvalds 	}
41333110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
41341da177e4SLinus Torvalds 			(unsigned long long)*used);
4135409924e4STrond Myklebust 	return ret;
4136c0eae66eSBenny Halevy out_overflow:
4137c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4138c0eae66eSBenny Halevy 	return -EIO;
41391da177e4SLinus Torvalds }
41401da177e4SLinus Torvalds 
414136b3743fSTrond Myklebust static __be32 *
414236b3743fSTrond Myklebust xdr_decode_nfstime4(__be32 *p, struct timespec *t)
414336b3743fSTrond Myklebust {
414436b3743fSTrond Myklebust 	__u64 sec;
414536b3743fSTrond Myklebust 
414636b3743fSTrond Myklebust 	p = xdr_decode_hyper(p, &sec);
414736b3743fSTrond Myklebust 	t-> tv_sec = (time_t)sec;
414836b3743fSTrond Myklebust 	t->tv_nsec = be32_to_cpup(p++);
414936b3743fSTrond Myklebust 	return p;
415036b3743fSTrond Myklebust }
415136b3743fSTrond Myklebust 
41521da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
41531da177e4SLinus Torvalds {
41548687b63aSAl Viro 	__be32 *p;
41551da177e4SLinus Torvalds 
415636b3743fSTrond Myklebust 	p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
4157c0eae66eSBenny Halevy 	if (unlikely(!p))
4158c0eae66eSBenny Halevy 		goto out_overflow;
415936b3743fSTrond Myklebust 	xdr_decode_nfstime4(p, time);
41601da177e4SLinus Torvalds 	return 0;
4161c0eae66eSBenny Halevy out_overflow:
4162c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4163c0eae66eSBenny Halevy 	return -EIO;
41641da177e4SLinus Torvalds }
41651da177e4SLinus Torvalds 
41661da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41671da177e4SLinus Torvalds {
41681da177e4SLinus Torvalds 	int status = 0;
41691da177e4SLinus Torvalds 
41701da177e4SLinus Torvalds 	time->tv_sec = 0;
41711da177e4SLinus Torvalds 	time->tv_nsec = 0;
41721da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
41731da177e4SLinus Torvalds 		return -EIO;
41741da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
41751da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4176409924e4STrond Myklebust 		if (status == 0)
4177409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
41781da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
41791da177e4SLinus Torvalds 	}
41803110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
41811da177e4SLinus Torvalds 	return status;
41821da177e4SLinus Torvalds }
41831da177e4SLinus Torvalds 
41841da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41851da177e4SLinus Torvalds {
41861da177e4SLinus Torvalds 	int status = 0;
41871da177e4SLinus Torvalds 
41881da177e4SLinus Torvalds 	time->tv_sec = 0;
41891da177e4SLinus Torvalds 	time->tv_nsec = 0;
41901da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41911da177e4SLinus Torvalds 		return -EIO;
41921da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41931da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4194409924e4STrond Myklebust 		if (status == 0)
4195409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
41961da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41971da177e4SLinus Torvalds 	}
41983110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
41991da177e4SLinus Torvalds 	return status;
42001da177e4SLinus Torvalds }
42011da177e4SLinus Torvalds 
420255b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
420355b6e774SRicardo Labiaga 				  struct timespec *time)
420455b6e774SRicardo Labiaga {
420555b6e774SRicardo Labiaga 	int status = 0;
420655b6e774SRicardo Labiaga 
420755b6e774SRicardo Labiaga 	time->tv_sec = 0;
420855b6e774SRicardo Labiaga 	time->tv_nsec = 0;
420955b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
421055b6e774SRicardo Labiaga 		return -EIO;
421155b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
421255b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
421355b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
421455b6e774SRicardo Labiaga 	}
421555b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
421655b6e774SRicardo Labiaga 		(long)time->tv_nsec);
421755b6e774SRicardo Labiaga 	return status;
421855b6e774SRicardo Labiaga }
421955b6e774SRicardo Labiaga 
4220aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4221aa9c2669SDavid Quigley 					struct nfs4_label *label)
4222aa9c2669SDavid Quigley {
4223aa9c2669SDavid Quigley 	uint32_t pi = 0;
4224aa9c2669SDavid Quigley 	uint32_t lfs = 0;
4225aa9c2669SDavid Quigley 	__u32 len;
4226aa9c2669SDavid Quigley 	__be32 *p;
4227aa9c2669SDavid Quigley 	int status = 0;
4228aa9c2669SDavid Quigley 
4229aa9c2669SDavid Quigley 	if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4230aa9c2669SDavid Quigley 		return -EIO;
4231aa9c2669SDavid Quigley 	if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4232aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4233aa9c2669SDavid Quigley 		if (unlikely(!p))
4234aa9c2669SDavid Quigley 			goto out_overflow;
4235aa9c2669SDavid Quigley 		lfs = be32_to_cpup(p++);
4236aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4237aa9c2669SDavid Quigley 		if (unlikely(!p))
4238aa9c2669SDavid Quigley 			goto out_overflow;
4239aa9c2669SDavid Quigley 		pi = be32_to_cpup(p++);
4240aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4241aa9c2669SDavid Quigley 		if (unlikely(!p))
4242aa9c2669SDavid Quigley 			goto out_overflow;
4243aa9c2669SDavid Quigley 		len = be32_to_cpup(p++);
4244aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, len);
4245aa9c2669SDavid Quigley 		if (unlikely(!p))
4246aa9c2669SDavid Quigley 			goto out_overflow;
4247aa9c2669SDavid Quigley 		if (len < NFS4_MAXLABELLEN) {
4248aa9c2669SDavid Quigley 			if (label) {
4249aa9c2669SDavid Quigley 				memcpy(label->label, p, len);
4250aa9c2669SDavid Quigley 				label->len = len;
4251aa9c2669SDavid Quigley 				label->pi = pi;
4252aa9c2669SDavid Quigley 				label->lfs = lfs;
4253aa9c2669SDavid Quigley 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4254aa9c2669SDavid Quigley 			}
4255aa9c2669SDavid Quigley 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4256aa9c2669SDavid Quigley 		} else
4257aa9c2669SDavid Quigley 			printk(KERN_WARNING "%s: label too long (%u)!\n",
4258aa9c2669SDavid Quigley 					__func__, len);
4259aa9c2669SDavid Quigley 	}
4260aa9c2669SDavid Quigley 	if (label && label->label)
4261aa9c2669SDavid Quigley 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4262aa9c2669SDavid Quigley 			(char *)label->label, label->len, label->pi, label->lfs);
4263aa9c2669SDavid Quigley 	return status;
4264aa9c2669SDavid Quigley 
4265aa9c2669SDavid Quigley out_overflow:
4266aa9c2669SDavid Quigley 	print_overflow_msg(__func__, xdr);
4267aa9c2669SDavid Quigley 	return -EIO;
4268aa9c2669SDavid Quigley }
4269aa9c2669SDavid Quigley 
42701da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
42711da177e4SLinus Torvalds {
42721da177e4SLinus Torvalds 	int status = 0;
42731da177e4SLinus Torvalds 
42741da177e4SLinus Torvalds 	time->tv_sec = 0;
42751da177e4SLinus Torvalds 	time->tv_nsec = 0;
42761da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
42771da177e4SLinus Torvalds 		return -EIO;
42781da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
42791da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4280409924e4STrond Myklebust 		if (status == 0)
4281409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
42821da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
42831da177e4SLinus Torvalds 	}
42843110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
42851da177e4SLinus Torvalds 	return status;
42861da177e4SLinus Torvalds }
42871da177e4SLinus Torvalds 
4288256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
42891da177e4SLinus Torvalds {
42901da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4291256e48bbSTrond Myklebust 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
42921da177e4SLinus Torvalds 
42931da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4294fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4295fe82a183SChuck Lever 			"%u %c %u\n",
42963110ff80SHarvey Harrison 				__func__,
42971da177e4SLinus Torvalds 				attrwords << 2,
42981da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
42991da177e4SLinus Torvalds 				nwords << 2);
43001da177e4SLinus Torvalds 		return -EIO;
43011da177e4SLinus Torvalds 	}
43021da177e4SLinus Torvalds 	return 0;
43031da177e4SLinus Torvalds }
43041da177e4SLinus Torvalds 
43051da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
43061da177e4SLinus Torvalds {
43078687b63aSAl Viro 	__be32 *p;
43081da177e4SLinus Torvalds 
4309c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4310c0eae66eSBenny Halevy 	if (unlikely(!p))
4311c0eae66eSBenny Halevy 		goto out_overflow;
43126f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
43133ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4314cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
43151da177e4SLinus Torvalds 	return 0;
4316c0eae66eSBenny Halevy out_overflow:
4317c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4318c0eae66eSBenny Halevy 	return -EIO;
43191da177e4SLinus Torvalds }
43201da177e4SLinus Torvalds 
43216168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
43221da177e4SLinus Torvalds {
43238687b63aSAl Viro 	__be32 *p;
43241da177e4SLinus Torvalds 	uint32_t supp, acc;
43251da177e4SLinus Torvalds 	int status;
43261da177e4SLinus Torvalds 
43271da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
43281da177e4SLinus Torvalds 	if (status)
43291da177e4SLinus Torvalds 		return status;
4330c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4331c0eae66eSBenny Halevy 	if (unlikely(!p))
4332c0eae66eSBenny Halevy 		goto out_overflow;
43336f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4334cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
43356168f62cSWeston Andros Adamson 	*supported = supp;
43366168f62cSWeston Andros Adamson 	*access = acc;
43371da177e4SLinus Torvalds 	return 0;
4338c0eae66eSBenny Halevy out_overflow:
4339c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4340c0eae66eSBenny Halevy 	return -EIO;
43411da177e4SLinus Torvalds }
43421da177e4SLinus Torvalds 
434307d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
43441da177e4SLinus Torvalds {
4345ab6e9aafSTrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4346ab6e9aafSTrond Myklebust 	if (unlikely(ret < 0)) {
434707d30434SBenny Halevy 		print_overflow_msg(__func__, xdr);
434807d30434SBenny Halevy 		return -EIO;
434907d30434SBenny Halevy 	}
4350ab6e9aafSTrond Myklebust 	return 0;
4351ab6e9aafSTrond Myklebust }
435207d30434SBenny Halevy 
435307d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
435407d30434SBenny Halevy {
43552d2f24adSTrond Myklebust 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
43561da177e4SLinus Torvalds }
43571da177e4SLinus Torvalds 
435893b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
435993b717fdSTrond Myklebust {
436093b717fdSTrond Myklebust 	stateid->type = NFS4_OPEN_STATEID_TYPE;
436193b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
436293b717fdSTrond Myklebust }
436393b717fdSTrond Myklebust 
436493b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
436593b717fdSTrond Myklebust {
436693b717fdSTrond Myklebust 	stateid->type = NFS4_LOCK_STATEID_TYPE;
436793b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
436893b717fdSTrond Myklebust }
436993b717fdSTrond Myklebust 
437093b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
437193b717fdSTrond Myklebust {
437293b717fdSTrond Myklebust 	stateid->type = NFS4_DELEGATION_STATEID_TYPE;
437393b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
437493b717fdSTrond Myklebust }
437593b717fdSTrond Myklebust 
4376fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4377fcd8843cSTrond Myklebust {
4378fcd8843cSTrond Myklebust 	nfs4_stateid dummy;
4379fcd8843cSTrond Myklebust 
4380fcd8843cSTrond Myklebust 	nfs4_stateid_copy(stateid, &invalid_stateid);
4381fcd8843cSTrond Myklebust 	return decode_stateid(xdr, &dummy);
4382fcd8843cSTrond Myklebust }
4383fcd8843cSTrond Myklebust 
43841da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
43851da177e4SLinus Torvalds {
43861da177e4SLinus Torvalds 	int status;
43871da177e4SLinus Torvalds 
43881da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4389c1d51931STrond Myklebust 	if (status != -EIO)
4390c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
439107d30434SBenny Halevy 	if (!status)
4392fcd8843cSTrond Myklebust 		status = decode_invalid_stateid(xdr, &res->stateid);
43931da177e4SLinus Torvalds 	return status;
43941da177e4SLinus Torvalds }
43951da177e4SLinus Torvalds 
4396db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4397db942bbdSBenny Halevy {
4398cd93710eSChuck Lever 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
43991da177e4SLinus Torvalds }
44001da177e4SLinus Torvalds 
44012f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
44022f2c63bcSTrond Myklebust {
44032f2c63bcSTrond Myklebust 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
44042f2c63bcSTrond Myklebust }
44052f2c63bcSTrond Myklebust 
44060b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
44071da177e4SLinus Torvalds {
44081da177e4SLinus Torvalds 	int status;
44091da177e4SLinus Torvalds 
44101da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4411db942bbdSBenny Halevy 	if (!status)
44122f2c63bcSTrond Myklebust 		status = decode_write_verifier(xdr, &res->verf->verifier);
44131da177e4SLinus Torvalds 	return status;
44141da177e4SLinus Torvalds }
44151da177e4SLinus Torvalds 
44161da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
44171da177e4SLinus Torvalds {
44188687b63aSAl Viro 	__be32 *p;
44191da177e4SLinus Torvalds 	uint32_t bmlen;
44201da177e4SLinus Torvalds 	int status;
44211da177e4SLinus Torvalds 
44221da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
44231da177e4SLinus Torvalds 	if (status)
44241da177e4SLinus Torvalds 		return status;
44251da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
44261da177e4SLinus Torvalds 		return status;
4427c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4428c0eae66eSBenny Halevy 	if (unlikely(!p))
4429c0eae66eSBenny Halevy 		goto out_overflow;
4430cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4431c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4432c0eae66eSBenny Halevy 	if (likely(p))
44331da177e4SLinus Torvalds 		return 0;
4434c0eae66eSBenny Halevy out_overflow:
4435c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4436c0eae66eSBenny Halevy 	return -EIO;
44371da177e4SLinus Torvalds }
44381da177e4SLinus Torvalds 
44391da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
44401da177e4SLinus Torvalds {
4441256e48bbSTrond Myklebust 	unsigned int savep;
4442dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
44431da177e4SLinus Torvalds 	int status;
44441da177e4SLinus Torvalds 
44451da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44461da177e4SLinus Torvalds 		goto xdr_error;
44471da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44481da177e4SLinus Torvalds 		goto xdr_error;
44491da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44501da177e4SLinus Torvalds 		goto xdr_error;
44511da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
44521da177e4SLinus Torvalds 		goto xdr_error;
4453264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4454264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4455264e6351SChuck Lever 		goto xdr_error;
44561da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
44571da177e4SLinus Torvalds 		goto xdr_error;
44581da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
44591da177e4SLinus Torvalds 		goto xdr_error;
44601da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
44611da177e4SLinus Torvalds 		goto xdr_error;
44628c61282fSKinglong Mee 	if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
44638c61282fSKinglong Mee 				res->exclcreat_bitmask)) != 0)
44648c61282fSKinglong Mee 		goto xdr_error;
44651da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44661da177e4SLinus Torvalds xdr_error:
44673110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44681da177e4SLinus Torvalds 	return status;
44691da177e4SLinus Torvalds }
44701da177e4SLinus Torvalds 
44711da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
44721da177e4SLinus Torvalds {
4473256e48bbSTrond Myklebust 	unsigned int savep;
4474dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
44751da177e4SLinus Torvalds 	int status;
44761da177e4SLinus Torvalds 
44771da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44781da177e4SLinus Torvalds 		goto xdr_error;
44791da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44801da177e4SLinus Torvalds 		goto xdr_error;
44811da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44821da177e4SLinus Torvalds 		goto xdr_error;
44831da177e4SLinus Torvalds 
44841da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
44851da177e4SLinus Torvalds 		goto xdr_error;
44861da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
44871da177e4SLinus Torvalds 		goto xdr_error;
44881da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
44891da177e4SLinus Torvalds 		goto xdr_error;
44901ca843a2SAndreas Gruenbacher 
44911ca843a2SAndreas Gruenbacher 	status = -EIO;
44921ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
44931ca843a2SAndreas Gruenbacher 		goto xdr_error;
44941ca843a2SAndreas Gruenbacher 
44951da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
44961da177e4SLinus Torvalds 		goto xdr_error;
44971da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
44981da177e4SLinus Torvalds 		goto xdr_error;
44991da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
45001da177e4SLinus Torvalds 		goto xdr_error;
45011da177e4SLinus Torvalds 
45021da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
45031da177e4SLinus Torvalds xdr_error:
45043110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
45051da177e4SLinus Torvalds 	return status;
45061da177e4SLinus Torvalds }
45071da177e4SLinus Torvalds 
45081da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
45091da177e4SLinus Torvalds {
4510256e48bbSTrond Myklebust 	unsigned int savep;
4511dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
45121da177e4SLinus Torvalds 	int status;
45131da177e4SLinus Torvalds 
45141da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
45151da177e4SLinus Torvalds 		goto xdr_error;
45161da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
45171da177e4SLinus Torvalds 		goto xdr_error;
45181da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
45191da177e4SLinus Torvalds 		goto xdr_error;
45201da177e4SLinus Torvalds 
45211da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
45221da177e4SLinus Torvalds 		goto xdr_error;
45231da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
45241da177e4SLinus Torvalds 		goto xdr_error;
45251da177e4SLinus Torvalds 
45261da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
45271da177e4SLinus Torvalds xdr_error:
45283110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
45291da177e4SLinus Torvalds 	return status;
45301da177e4SLinus Torvalds }
45311da177e4SLinus Torvalds 
453288034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
453388034c3dSAndy Adamson 				  uint32_t *bitmap,
453488034c3dSAndy Adamson 				  uint64_t *res,
453588034c3dSAndy Adamson 				  uint32_t hint_bit)
453688034c3dSAndy Adamson {
453788034c3dSAndy Adamson 	__be32 *p;
453888034c3dSAndy Adamson 
453988034c3dSAndy Adamson 	*res = 0;
454088034c3dSAndy Adamson 	if (likely(bitmap[0] & hint_bit)) {
454188034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
454288034c3dSAndy Adamson 		if (unlikely(!p))
454388034c3dSAndy Adamson 			goto out_overflow;
454488034c3dSAndy Adamson 		xdr_decode_hyper(p, res);
454588034c3dSAndy Adamson 	}
454688034c3dSAndy Adamson 	return 0;
454788034c3dSAndy Adamson out_overflow:
454888034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
454988034c3dSAndy Adamson 	return -EIO;
455088034c3dSAndy Adamson }
455188034c3dSAndy Adamson 
455288034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
455388034c3dSAndy Adamson 					struct nfs4_threshold *res)
455488034c3dSAndy Adamson {
4555256e48bbSTrond Myklebust 	__be32 *p;
4556256e48bbSTrond Myklebust 	unsigned int savep;
455788034c3dSAndy Adamson 	uint32_t bitmap[3] = {0,}, attrlen;
455888034c3dSAndy Adamson 	int status;
455988034c3dSAndy Adamson 
456088034c3dSAndy Adamson 	/* layout type */
456188034c3dSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
456288034c3dSAndy Adamson 	if (unlikely(!p)) {
456388034c3dSAndy Adamson 		print_overflow_msg(__func__, xdr);
456488034c3dSAndy Adamson 		return -EIO;
456588034c3dSAndy Adamson 	}
456688034c3dSAndy Adamson 	res->l_type = be32_to_cpup(p);
456788034c3dSAndy Adamson 
456888034c3dSAndy Adamson 	/* thi_hintset bitmap */
456988034c3dSAndy Adamson 	status = decode_attr_bitmap(xdr, bitmap);
457088034c3dSAndy Adamson 	if (status < 0)
457188034c3dSAndy Adamson 		goto xdr_error;
457288034c3dSAndy Adamson 
457388034c3dSAndy Adamson 	/* thi_hintlist length */
457488034c3dSAndy Adamson 	status = decode_attr_length(xdr, &attrlen, &savep);
457588034c3dSAndy Adamson 	if (status < 0)
457688034c3dSAndy Adamson 		goto xdr_error;
457788034c3dSAndy Adamson 	/* thi_hintlist */
457888034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
457988034c3dSAndy Adamson 	if (status < 0)
458088034c3dSAndy Adamson 		goto xdr_error;
458188034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
458288034c3dSAndy Adamson 	if (status < 0)
458388034c3dSAndy Adamson 		goto xdr_error;
458488034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
458588034c3dSAndy Adamson 				       THRESHOLD_RD_IO);
458688034c3dSAndy Adamson 	if (status < 0)
458788034c3dSAndy Adamson 		goto xdr_error;
458888034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
458988034c3dSAndy Adamson 				       THRESHOLD_WR_IO);
459088034c3dSAndy Adamson 	if (status < 0)
459188034c3dSAndy Adamson 		goto xdr_error;
459288034c3dSAndy Adamson 
459388034c3dSAndy Adamson 	status = verify_attr_len(xdr, savep, attrlen);
459488034c3dSAndy Adamson 	res->bm = bitmap[0];
459588034c3dSAndy Adamson 
459688034c3dSAndy Adamson 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
459788034c3dSAndy Adamson 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
459888034c3dSAndy Adamson 		res->wr_io_sz);
459988034c3dSAndy Adamson xdr_error:
460088034c3dSAndy Adamson 	dprintk("%s ret=%d!\n", __func__, status);
460188034c3dSAndy Adamson 	return status;
460288034c3dSAndy Adamson }
460388034c3dSAndy Adamson 
460488034c3dSAndy Adamson /*
460588034c3dSAndy Adamson  * Thresholds on pNFS direct I/O vrs MDS I/O
460688034c3dSAndy Adamson  */
460788034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
460888034c3dSAndy Adamson 				    uint32_t *bitmap,
460988034c3dSAndy Adamson 				    struct nfs4_threshold *res)
461088034c3dSAndy Adamson {
461188034c3dSAndy Adamson 	__be32 *p;
461288034c3dSAndy Adamson 	int status = 0;
461388034c3dSAndy Adamson 	uint32_t num;
461488034c3dSAndy Adamson 
461588034c3dSAndy Adamson 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
461688034c3dSAndy Adamson 		return -EIO;
4617029c5347STrond Myklebust 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
46181549210fSTrond Myklebust 		/* Did the server return an unrequested attribute? */
46191549210fSTrond Myklebust 		if (unlikely(res == NULL))
46201549210fSTrond Myklebust 			return -EREMOTEIO;
462188034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 4);
462288034c3dSAndy Adamson 		if (unlikely(!p))
462388034c3dSAndy Adamson 			goto out_overflow;
462488034c3dSAndy Adamson 		num = be32_to_cpup(p);
462588034c3dSAndy Adamson 		if (num == 0)
462688034c3dSAndy Adamson 			return 0;
462788034c3dSAndy Adamson 		if (num > 1)
462888034c3dSAndy Adamson 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
462988034c3dSAndy Adamson 				"drivers per filesystem not supported\n",
463088034c3dSAndy Adamson 				__func__);
463188034c3dSAndy Adamson 
463288034c3dSAndy Adamson 		status = decode_first_threshold_item4(xdr, res);
4633029c5347STrond Myklebust 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
463488034c3dSAndy Adamson 	}
463588034c3dSAndy Adamson 	return status;
463688034c3dSAndy Adamson out_overflow:
463788034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
463888034c3dSAndy Adamson 	return -EIO;
463988034c3dSAndy Adamson }
464088034c3dSAndy Adamson 
4641ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4642ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
4643aa9c2669SDavid Quigley 		struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
46446926afd1STrond Myklebust 		const struct nfs_server *server)
46451da177e4SLinus Torvalds {
4646bca79478STrond Myklebust 	int status;
4647bca79478STrond Myklebust 	umode_t fmode = 0;
4648ae42c70aSBryan Schumaker 	uint32_t type;
4649ee7b75fcSTrond Myklebust 	int32_t err;
46501da177e4SLinus Torvalds 
4651f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4652f26c7a78STrond Myklebust 	if (status < 0)
46531da177e4SLinus Torvalds 		goto xdr_error;
4654409924e4STrond Myklebust 	fattr->mode = 0;
4655409924e4STrond Myklebust 	if (status != 0) {
4656409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4657409924e4STrond Myklebust 		fattr->valid |= status;
4658409924e4STrond Myklebust 	}
46591da177e4SLinus Torvalds 
4660f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4661f26c7a78STrond Myklebust 	if (status < 0)
46621da177e4SLinus Torvalds 		goto xdr_error;
4663409924e4STrond Myklebust 	fattr->valid |= status;
4664f26c7a78STrond Myklebust 
4665f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4666f26c7a78STrond Myklebust 	if (status < 0)
46671da177e4SLinus Torvalds 		goto xdr_error;
4668409924e4STrond Myklebust 	fattr->valid |= status;
4669f26c7a78STrond Myklebust 
4670f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4671f26c7a78STrond Myklebust 	if (status < 0)
46721da177e4SLinus Torvalds 		goto xdr_error;
4673409924e4STrond Myklebust 	fattr->valid |= status;
4674f26c7a78STrond Myklebust 
4675ee7b75fcSTrond Myklebust 	err = 0;
4676ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4677ae42c70aSBryan Schumaker 	if (status < 0)
4678ae42c70aSBryan Schumaker 		goto xdr_error;
4679ae42c70aSBryan Schumaker 
4680ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4681ae42c70aSBryan Schumaker 	if (status < 0)
4682ae42c70aSBryan Schumaker 		goto xdr_error;
4683ae42c70aSBryan Schumaker 
4684f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4685f26c7a78STrond Myklebust 	if (status < 0)
46861da177e4SLinus Torvalds 		goto xdr_error;
4687409924e4STrond Myklebust 	fattr->valid |= status;
4688f26c7a78STrond Myklebust 
46898b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4690f26c7a78STrond Myklebust 	if (status < 0)
4691683b57b4STrond Myklebust 		goto xdr_error;
4692409924e4STrond Myklebust 	fattr->valid |= status;
4693f26c7a78STrond Myklebust 
46941ca843a2SAndreas Gruenbacher 	status = -EIO;
46951ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
46961ca843a2SAndreas Gruenbacher 		goto xdr_error;
46971ca843a2SAndreas Gruenbacher 
4698f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4699f26c7a78STrond Myklebust 	if (status < 0)
47001da177e4SLinus Torvalds 		goto xdr_error;
4701409924e4STrond Myklebust 	if (status != 0) {
47021da177e4SLinus Torvalds 		fattr->mode |= fmode;
4703409924e4STrond Myklebust 		fattr->valid |= status;
4704409924e4STrond Myklebust 	}
4705f26c7a78STrond Myklebust 
4706f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4707f26c7a78STrond Myklebust 	if (status < 0)
47081da177e4SLinus Torvalds 		goto xdr_error;
4709409924e4STrond Myklebust 	fattr->valid |= status;
4710f26c7a78STrond Myklebust 
47116926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4712f26c7a78STrond Myklebust 	if (status < 0)
47131da177e4SLinus Torvalds 		goto xdr_error;
4714409924e4STrond Myklebust 	fattr->valid |= status;
4715f26c7a78STrond Myklebust 
47166926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4717f26c7a78STrond Myklebust 	if (status < 0)
47181da177e4SLinus Torvalds 		goto xdr_error;
4719409924e4STrond Myklebust 	fattr->valid |= status;
4720f26c7a78STrond Myklebust 
4721f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4722f26c7a78STrond Myklebust 	if (status < 0)
47231da177e4SLinus Torvalds 		goto xdr_error;
4724409924e4STrond Myklebust 	fattr->valid |= status;
4725f26c7a78STrond Myklebust 
4726f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4727f26c7a78STrond Myklebust 	if (status < 0)
47281da177e4SLinus Torvalds 		goto xdr_error;
4729409924e4STrond Myklebust 	fattr->valid |= status;
4730f26c7a78STrond Myklebust 
4731f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4732f26c7a78STrond Myklebust 	if (status < 0)
47331da177e4SLinus Torvalds 		goto xdr_error;
4734409924e4STrond Myklebust 	fattr->valid |= status;
4735f26c7a78STrond Myklebust 
4736f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4737f26c7a78STrond Myklebust 	if (status < 0)
47381da177e4SLinus Torvalds 		goto xdr_error;
4739409924e4STrond Myklebust 	fattr->valid |= status;
4740f26c7a78STrond Myklebust 
4741f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4742f26c7a78STrond Myklebust 	if (status < 0)
47431da177e4SLinus Torvalds 		goto xdr_error;
4744409924e4STrond Myklebust 	fattr->valid |= status;
4745f26c7a78STrond Myklebust 
474628331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4747f26c7a78STrond Myklebust 	if (status < 0)
474899baf625SManoj Naik 		goto xdr_error;
4749409924e4STrond Myklebust 	fattr->valid |= status;
4750f26c7a78STrond Myklebust 
47511ca843a2SAndreas Gruenbacher 	status = -EIO;
47521ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
47531ca843a2SAndreas Gruenbacher 		goto xdr_error;
47541ca843a2SAndreas Gruenbacher 
475588034c3dSAndy Adamson 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
475688034c3dSAndy Adamson 	if (status < 0)
475788034c3dSAndy Adamson 		goto xdr_error;
475888034c3dSAndy Adamson 
4759aa9c2669SDavid Quigley 	if (label) {
4760aa9c2669SDavid Quigley 		status = decode_attr_security_label(xdr, bitmap, label);
4761aa9c2669SDavid Quigley 		if (status < 0)
4762aa9c2669SDavid Quigley 			goto xdr_error;
4763aa9c2669SDavid Quigley 		fattr->valid |= status;
4764aa9c2669SDavid Quigley 	}
4765aa9c2669SDavid Quigley 
4766ae42c70aSBryan Schumaker xdr_error:
4767ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4768ae42c70aSBryan Schumaker 	return status;
4769ae42c70aSBryan Schumaker }
4770ae42c70aSBryan Schumaker 
4771ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47728b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4773aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4774ae42c70aSBryan Schumaker {
4775256e48bbSTrond Myklebust 	unsigned int savep;
4776ae42c70aSBryan Schumaker 	uint32_t attrlen,
4777dae100c2SFred Isaman 		 bitmap[3] = {0};
4778ae42c70aSBryan Schumaker 	int status;
4779ae42c70aSBryan Schumaker 
4780ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4781ae42c70aSBryan Schumaker 	if (status < 0)
4782ae42c70aSBryan Schumaker 		goto xdr_error;
4783ae42c70aSBryan Schumaker 
4784ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4785ae42c70aSBryan Schumaker 	if (status < 0)
4786ae42c70aSBryan Schumaker 		goto xdr_error;
4787ae42c70aSBryan Schumaker 
4788ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4789ae42c70aSBryan Schumaker 	if (status < 0)
4790ae42c70aSBryan Schumaker 		goto xdr_error;
4791ae42c70aSBryan Schumaker 
4792aa9c2669SDavid Quigley 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4793aa9c2669SDavid Quigley 					label, server);
4794ae42c70aSBryan Schumaker 	if (status < 0)
4795ae42c70aSBryan Schumaker 		goto xdr_error;
4796ae42c70aSBryan Schumaker 
4797f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
47981da177e4SLinus Torvalds xdr_error:
47993110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
48001da177e4SLinus Torvalds 	return status;
48011da177e4SLinus Torvalds }
48021da177e4SLinus Torvalds 
4803aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4804aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4805aa9c2669SDavid Quigley {
4806aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4807aa9c2669SDavid Quigley }
4808aa9c2669SDavid Quigley 
4809ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
48106926afd1STrond Myklebust 		const struct nfs_server *server)
4811ae42c70aSBryan Schumaker {
4812aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4813ae42c70aSBryan Schumaker }
48141da177e4SLinus Torvalds 
4815504913fbSAndy Adamson /*
48163132e49eSJeff Layton  * Decode potentially multiple layout types.
4817504913fbSAndy Adamson  */
48183132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4819ca440c38SJeff Layton 				    struct nfs_fsinfo *fsinfo)
4820504913fbSAndy Adamson {
4821b8a8a0ddSTrond Myklebust 	__be32 *p;
4822ca440c38SJeff Layton 	uint32_t i;
4823504913fbSAndy Adamson 
4824504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4825504913fbSAndy Adamson 	if (unlikely(!p))
4826504913fbSAndy Adamson 		goto out_overflow;
4827ca440c38SJeff Layton 	fsinfo->nlayouttypes = be32_to_cpup(p);
4828504913fbSAndy Adamson 
4829504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4830ca440c38SJeff Layton 	if (fsinfo->nlayouttypes == 0)
4831504913fbSAndy Adamson 		return 0;
4832504913fbSAndy Adamson 
4833504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4834ca440c38SJeff Layton 	p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4835504913fbSAndy Adamson 	if (unlikely(!p))
4836504913fbSAndy Adamson 		goto out_overflow;
4837ca440c38SJeff Layton 
4838ca440c38SJeff Layton 	/* If we get too many, then just cap it at the max */
4839ca440c38SJeff Layton 	if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4840ca440c38SJeff Layton 		printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4841ca440c38SJeff Layton 			__func__, fsinfo->nlayouttypes);
4842ca440c38SJeff Layton 		fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4843ca440c38SJeff Layton 	}
4844ca440c38SJeff Layton 
4845ca440c38SJeff Layton 	for(i = 0; i < fsinfo->nlayouttypes; ++i)
4846ca440c38SJeff Layton 		fsinfo->layouttype[i] = be32_to_cpup(p++);
4847504913fbSAndy Adamson 	return 0;
4848504913fbSAndy Adamson out_overflow:
4849504913fbSAndy Adamson 	print_overflow_msg(__func__, xdr);
4850504913fbSAndy Adamson 	return -EIO;
4851504913fbSAndy Adamson }
4852504913fbSAndy Adamson 
4853504913fbSAndy Adamson /*
4854504913fbSAndy Adamson  * The type of file system exported.
4855504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4856504913fbSAndy Adamson  */
4857504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4858ca440c38SJeff Layton 				struct nfs_fsinfo *fsinfo)
4859504913fbSAndy Adamson {
4860504913fbSAndy Adamson 	int status = 0;
4861504913fbSAndy Adamson 
4862504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4863504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4864504913fbSAndy Adamson 		return -EIO;
4865504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4866ca440c38SJeff Layton 		status = decode_pnfs_layout_types(xdr, fsinfo);
4867504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
48683132e49eSJeff Layton 	}
4869504913fbSAndy Adamson 	return status;
4870504913fbSAndy Adamson }
4871504913fbSAndy Adamson 
4872dae100c2SFred Isaman /*
4873dae100c2SFred Isaman  * The prefered block size for layout directed io
4874dae100c2SFred Isaman  */
4875dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4876dae100c2SFred Isaman 				      uint32_t *res)
4877dae100c2SFred Isaman {
4878dae100c2SFred Isaman 	__be32 *p;
4879dae100c2SFred Isaman 
4880dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4881dae100c2SFred Isaman 	*res = 0;
4882dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4883dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4884dae100c2SFred Isaman 		if (unlikely(!p)) {
4885dae100c2SFred Isaman 			print_overflow_msg(__func__, xdr);
4886dae100c2SFred Isaman 			return -EIO;
4887dae100c2SFred Isaman 		}
4888dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4889dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4890dae100c2SFred Isaman 	}
4891dae100c2SFred Isaman 	return 0;
4892dae100c2SFred Isaman }
4893dae100c2SFred Isaman 
48942a92ee92SPeng Tao /*
48952a92ee92SPeng Tao  * The granularity of a CLONE operation.
48962a92ee92SPeng Tao  */
48972a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
48982a92ee92SPeng Tao 				     uint32_t *res)
48992a92ee92SPeng Tao {
49002a92ee92SPeng Tao 	__be32 *p;
49012a92ee92SPeng Tao 
49022a92ee92SPeng Tao 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
49032a92ee92SPeng Tao 	*res = 0;
49042a92ee92SPeng Tao 	if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
49052a92ee92SPeng Tao 		p = xdr_inline_decode(xdr, 4);
49062a92ee92SPeng Tao 		if (unlikely(!p)) {
49072a92ee92SPeng Tao 			print_overflow_msg(__func__, xdr);
49082a92ee92SPeng Tao 			return -EIO;
49092a92ee92SPeng Tao 		}
49102a92ee92SPeng Tao 		*res = be32_to_cpup(p);
49112a92ee92SPeng Tao 		bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
49122a92ee92SPeng Tao 	}
49132a92ee92SPeng Tao 	return 0;
49142a92ee92SPeng Tao }
49152a92ee92SPeng Tao 
49161da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
49171da177e4SLinus Torvalds {
4918256e48bbSTrond Myklebust 	unsigned int savep;
4919dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
49201da177e4SLinus Torvalds 	int status;
49211da177e4SLinus Torvalds 
49221da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
49231da177e4SLinus Torvalds 		goto xdr_error;
49241da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
49251da177e4SLinus Torvalds 		goto xdr_error;
49261da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
49271da177e4SLinus Torvalds 		goto xdr_error;
49281da177e4SLinus Torvalds 
49291da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
49301da177e4SLinus Torvalds 
49311da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
49321da177e4SLinus Torvalds 		goto xdr_error;
49331da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
49341da177e4SLinus Torvalds 		goto xdr_error;
49351da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
49361da177e4SLinus Torvalds 		goto xdr_error;
49371da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
49381da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
49391da177e4SLinus Torvalds 		goto xdr_error;
49401da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
49411ca843a2SAndreas Gruenbacher 
49421ca843a2SAndreas Gruenbacher 	status = -EIO;
49431ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
49441ca843a2SAndreas Gruenbacher 		goto xdr_error;
49451ca843a2SAndreas Gruenbacher 
494655b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
494755b6e774SRicardo Labiaga 	if (status != 0)
494855b6e774SRicardo Labiaga 		goto xdr_error;
4949ca440c38SJeff Layton 	status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4950504913fbSAndy Adamson 	if (status != 0)
4951504913fbSAndy Adamson 		goto xdr_error;
49521ca843a2SAndreas Gruenbacher 
49531ca843a2SAndreas Gruenbacher 	status = -EIO;
49541ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
49551ca843a2SAndreas Gruenbacher 		goto xdr_error;
49561ca843a2SAndreas Gruenbacher 
4957dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4958dae100c2SFred Isaman 	if (status)
4959dae100c2SFred Isaman 		goto xdr_error;
49602a92ee92SPeng Tao 	status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
49612a92ee92SPeng Tao 	if (status)
49622a92ee92SPeng Tao 		goto xdr_error;
49631da177e4SLinus Torvalds 
49641da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
49651da177e4SLinus Torvalds xdr_error:
49663110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
49671da177e4SLinus Torvalds 	return status;
49681da177e4SLinus Torvalds }
49691da177e4SLinus Torvalds 
49701da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
49711da177e4SLinus Torvalds {
49728687b63aSAl Viro 	__be32 *p;
49731da177e4SLinus Torvalds 	uint32_t len;
49741da177e4SLinus Torvalds 	int status;
49751da177e4SLinus Torvalds 
49769936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
49779936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
49789936781dSTrond Myklebust 
49791da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
49801da177e4SLinus Torvalds 	if (status)
49811da177e4SLinus Torvalds 		return status;
49821da177e4SLinus Torvalds 
4983c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4984c0eae66eSBenny Halevy 	if (unlikely(!p))
4985c0eae66eSBenny Halevy 		goto out_overflow;
4986cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
49871da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
49881da177e4SLinus Torvalds 		return -EIO;
49891da177e4SLinus Torvalds 	fh->size = len;
4990c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4991c0eae66eSBenny Halevy 	if (unlikely(!p))
4992c0eae66eSBenny Halevy 		goto out_overflow;
499399398d06SBenny Halevy 	memcpy(fh->data, p, len);
49941da177e4SLinus Torvalds 	return 0;
4995c0eae66eSBenny Halevy out_overflow:
4996c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4997c0eae66eSBenny Halevy 	return -EIO;
49981da177e4SLinus Torvalds }
49991da177e4SLinus Torvalds 
50001da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
50011da177e4SLinus Torvalds {
50021da177e4SLinus Torvalds 	int status;
50031da177e4SLinus Torvalds 
50041da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
50051da177e4SLinus Torvalds 	if (status)
50061da177e4SLinus Torvalds 		return status;
50071da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
50081da177e4SLinus Torvalds }
50091da177e4SLinus Torvalds 
50101da177e4SLinus Torvalds /*
50111da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
50121da177e4SLinus Torvalds  */
5013911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
50141da177e4SLinus Torvalds {
5015911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
50168687b63aSAl Viro 	__be32 *p;
5017911d1aafSTrond Myklebust 	uint32_t namelen, type;
50181da177e4SLinus Torvalds 
5019babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
5020c0eae66eSBenny Halevy 	if (unlikely(!p))
5021c0eae66eSBenny Halevy 		goto out_overflow;
5022babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
50233ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
5024babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
5025babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
5026911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
5027911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
5028911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
5029911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
5030911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
5031911d1aafSTrond Myklebust 		if (type & 1)
5032911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
5033911d1aafSTrond Myklebust 		fl->fl_pid = 0;
5034911d1aafSTrond Myklebust 	}
5035babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5036babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
5037babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
5038c0eae66eSBenny Halevy 	if (likely(p))
50391da177e4SLinus Torvalds 		return -NFS4ERR_DENIED;
5040c0eae66eSBenny Halevy out_overflow:
5041c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5042c0eae66eSBenny Halevy 	return -EIO;
50431da177e4SLinus Torvalds }
50441da177e4SLinus Torvalds 
5045911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
50461da177e4SLinus Torvalds {
50471da177e4SLinus Torvalds 	int status;
50481da177e4SLinus Torvalds 
50491da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
5050c1d51931STrond Myklebust 	if (status == -EIO)
5051c1d51931STrond Myklebust 		goto out;
50521da177e4SLinus Torvalds 	if (status == 0) {
505393b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
505407d30434SBenny Halevy 		if (unlikely(status))
505507d30434SBenny Halevy 			goto out;
50561da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
5057c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
5058c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
5059c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
5060c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
5061c1d51931STrond Myklebust out:
50621da177e4SLinus Torvalds 	return status;
50631da177e4SLinus Torvalds }
50641da177e4SLinus Torvalds 
5065911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
50661da177e4SLinus Torvalds {
50671da177e4SLinus Torvalds 	int status;
50681da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
50691da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
5070911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
50711da177e4SLinus Torvalds 	return status;
50721da177e4SLinus Torvalds }
50731da177e4SLinus Torvalds 
5074911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
50751da177e4SLinus Torvalds {
50761da177e4SLinus Torvalds 	int status;
50771da177e4SLinus Torvalds 
50781da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
5079c1d51931STrond Myklebust 	if (status != -EIO)
5080c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
508107d30434SBenny Halevy 	if (status == 0)
508293b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
50831da177e4SLinus Torvalds 	return status;
50841da177e4SLinus Torvalds }
50851da177e4SLinus Torvalds 
5086d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
5087d3c7b7ccSTrond Myklebust {
5088d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5089d3c7b7ccSTrond Myklebust }
5090d3c7b7ccSTrond Myklebust 
50911da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
50921da177e4SLinus Torvalds {
50931da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
50941da177e4SLinus Torvalds }
50951da177e4SLinus Torvalds 
50965b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr)
50975b5faaf6SJeff Layton {
50985b5faaf6SJeff Layton 	return decode_op_hdr(xdr, OP_LOOKUPP);
50995b5faaf6SJeff Layton }
51005b5faaf6SJeff Layton 
51011da177e4SLinus Torvalds /* This is too sick! */
51027d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr,
51037d160a6cSTrond Myklebust 		unsigned long *pagemod_limit)
51041da177e4SLinus Torvalds {
51058687b63aSAl Viro 	__be32 *p;
51061da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
51077d160a6cSTrond Myklebust 	u64 maxsize = 0;
51081da177e4SLinus Torvalds 
5109c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5110c0eae66eSBenny Halevy 	if (unlikely(!p))
5111c0eae66eSBenny Halevy 		goto out_overflow;
51126f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
51131da177e4SLinus Torvalds 	switch (limit_type) {
51147d160a6cSTrond Myklebust 	case NFS4_LIMIT_SIZE:
51157d160a6cSTrond Myklebust 		xdr_decode_hyper(p, &maxsize);
51161da177e4SLinus Torvalds 		break;
51177d160a6cSTrond Myklebust 	case NFS4_LIMIT_BLOCKS:
51186f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
5119cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
51207d160a6cSTrond Myklebust 		maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
51211da177e4SLinus Torvalds 	}
512209cbfeafSKirill A. Shutemov 	maxsize >>= PAGE_SHIFT;
51237d160a6cSTrond Myklebust 	*pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
51241da177e4SLinus Torvalds 	return 0;
5125c0eae66eSBenny Halevy out_overflow:
5126c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5127c0eae66eSBenny Halevy 	return -EIO;
51281da177e4SLinus Torvalds }
51291da177e4SLinus Torvalds 
51306ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr,
51316ae37339STrond Myklebust 		uint32_t delegation_type,
51326ae37339STrond Myklebust 		struct nfs_openres *res)
51331da177e4SLinus Torvalds {
51348687b63aSAl Viro 	__be32 *p;
513507d30434SBenny Halevy 	int status;
51361da177e4SLinus Torvalds 
513793b717fdSTrond Myklebust 	status = decode_delegation_stateid(xdr, &res->delegation);
513807d30434SBenny Halevy 	if (unlikely(status))
513907d30434SBenny Halevy 		return status;
5140c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5141c0eae66eSBenny Halevy 	if (unlikely(!p))
5142c0eae66eSBenny Halevy 		goto out_overflow;
5143cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
514405d564feSAndy Adamson 
51451da177e4SLinus Torvalds 	switch (delegation_type) {
51461da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
51471da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
51481da177e4SLinus Torvalds 		break;
51491da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
51501da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
51517d160a6cSTrond Myklebust 		if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
51521da177e4SLinus Torvalds 				return -EIO;
51531da177e4SLinus Torvalds 	}
51541bbe60ffSTrond Myklebust 	return decode_ace(xdr, NULL);
5155c0eae66eSBenny Halevy out_overflow:
5156c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5157c0eae66eSBenny Halevy 	return -EIO;
51581da177e4SLinus Torvalds }
51591da177e4SLinus Torvalds 
51606ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
51616ae37339STrond Myklebust {
51626ae37339STrond Myklebust 	__be32 *p;
51636ae37339STrond Myklebust 	uint32_t why_no_delegation;
51646ae37339STrond Myklebust 
51656ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
51666ae37339STrond Myklebust 	if (unlikely(!p))
51676ae37339STrond Myklebust 		goto out_overflow;
51686ae37339STrond Myklebust 	why_no_delegation = be32_to_cpup(p);
51696ae37339STrond Myklebust 	switch (why_no_delegation) {
51706ae37339STrond Myklebust 		case WND4_CONTENTION:
51716ae37339STrond Myklebust 		case WND4_RESOURCE:
51726ae37339STrond Myklebust 			xdr_inline_decode(xdr, 4);
51736ae37339STrond Myklebust 			/* Ignore for now */
51746ae37339STrond Myklebust 	}
51756ae37339STrond Myklebust 	return 0;
51766ae37339STrond Myklebust out_overflow:
51776ae37339STrond Myklebust 	print_overflow_msg(__func__, xdr);
51786ae37339STrond Myklebust 	return -EIO;
51796ae37339STrond Myklebust }
51806ae37339STrond Myklebust 
51816ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
51826ae37339STrond Myklebust {
51836ae37339STrond Myklebust 	__be32 *p;
51846ae37339STrond Myklebust 	uint32_t delegation_type;
51856ae37339STrond Myklebust 
51866ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
51876ae37339STrond Myklebust 	if (unlikely(!p))
51886ae37339STrond Myklebust 		goto out_overflow;
51896ae37339STrond Myklebust 	delegation_type = be32_to_cpup(p);
51906ae37339STrond Myklebust 	res->delegation_type = 0;
51916ae37339STrond Myklebust 	switch (delegation_type) {
51926ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE:
51936ae37339STrond Myklebust 		return 0;
51946ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_READ:
51956ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_WRITE:
51966ae37339STrond Myklebust 		return decode_rw_delegation(xdr, delegation_type, res);
51976ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE_EXT:
51986ae37339STrond Myklebust 		return decode_no_delegation(xdr, res);
51996ae37339STrond Myklebust 	}
52006ae37339STrond Myklebust 	return -EIO;
52016ae37339STrond Myklebust out_overflow:
52026ae37339STrond Myklebust 	print_overflow_msg(__func__, xdr);
52036ae37339STrond Myklebust 	return -EIO;
52046ae37339STrond Myklebust }
52056ae37339STrond Myklebust 
52061da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
52071da177e4SLinus Torvalds {
52088687b63aSAl Viro 	__be32 *p;
5209aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
52101da177e4SLinus Torvalds 	int status;
52111da177e4SLinus Torvalds 
5212c7848f69STrond Myklebust 	if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5213c7848f69STrond Myklebust 		return status;
5214c1d51931STrond Myklebust 	nfs_increment_open_seqid(status, res->seqid);
5215c7848f69STrond Myklebust 	if (status)
5216c7848f69STrond Myklebust 		return status;
521793b717fdSTrond Myklebust 	status = decode_open_stateid(xdr, &res->stateid);
521807d30434SBenny Halevy 	if (unlikely(status))
52191da177e4SLinus Torvalds 		return status;
52201da177e4SLinus Torvalds 
52211da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
52221da177e4SLinus Torvalds 
5223c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5224c0eae66eSBenny Halevy 	if (unlikely(!p))
5225c0eae66eSBenny Halevy 		goto out_overflow;
52266f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
5227cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
52281da177e4SLinus Torvalds 	if (bmlen > 10)
52291da177e4SLinus Torvalds 		goto xdr_error;
52301da177e4SLinus Torvalds 
5231c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5232c0eae66eSBenny Halevy 	if (unlikely(!p))
5233c0eae66eSBenny Halevy 		goto out_overflow;
5234aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5235aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
52366f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
5237aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
5238aa53ed54SJeff Layton 		res->attrset[i] = 0;
5239aa53ed54SJeff Layton 
52401da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
52411da177e4SLinus Torvalds xdr_error:
52423110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
52431da177e4SLinus Torvalds 	return -EIO;
5244c0eae66eSBenny Halevy out_overflow:
5245c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5246c0eae66eSBenny Halevy 	return -EIO;
52471da177e4SLinus Torvalds }
52481da177e4SLinus Torvalds 
52491da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
52501da177e4SLinus Torvalds {
52511da177e4SLinus Torvalds 	int status;
52521da177e4SLinus Torvalds 
52531da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5254c1d51931STrond Myklebust 	if (status != -EIO)
5255c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
525607d30434SBenny Halevy 	if (!status)
525793b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
52581da177e4SLinus Torvalds 	return status;
52591da177e4SLinus Torvalds }
52601da177e4SLinus Torvalds 
52611da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
52621da177e4SLinus Torvalds {
52631da177e4SLinus Torvalds 	int status;
52641da177e4SLinus Torvalds 
52651da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5266c1d51931STrond Myklebust 	if (status != -EIO)
5267c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
526807d30434SBenny Halevy 	if (!status)
526993b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
52701da177e4SLinus Torvalds 	return status;
52711da177e4SLinus Torvalds }
52721da177e4SLinus Torvalds 
52731da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
52741da177e4SLinus Torvalds {
52751da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
52761da177e4SLinus Torvalds }
52771da177e4SLinus Torvalds 
52781da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
52791da177e4SLinus Torvalds {
52801da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
52811da177e4SLinus Torvalds }
52821da177e4SLinus Torvalds 
52839137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
52849137bdf3SAnna Schumaker 		       struct nfs_pgio_res *res)
52851da177e4SLinus Torvalds {
52868687b63aSAl Viro 	__be32 *p;
528764bd577eSTrond Myklebust 	uint32_t count, eof, recvd;
52881da177e4SLinus Torvalds 	int status;
52891da177e4SLinus Torvalds 
52901da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
52911da177e4SLinus Torvalds 	if (status)
52921da177e4SLinus Torvalds 		return status;
5293c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5294c0eae66eSBenny Halevy 	if (unlikely(!p))
5295c0eae66eSBenny Halevy 		goto out_overflow;
52966f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
5297cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
529864bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, count);
52991da177e4SLinus Torvalds 	if (count > recvd) {
5300fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
53011da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
53021da177e4SLinus Torvalds 		count = recvd;
53031da177e4SLinus Torvalds 		eof = 0;
53041da177e4SLinus Torvalds 	}
53051da177e4SLinus Torvalds 	res->eof = eof;
53061da177e4SLinus Torvalds 	res->count = count;
53071da177e4SLinus Torvalds 	return 0;
5308c0eae66eSBenny Halevy out_overflow:
5309c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5310c0eae66eSBenny Halevy 	return -EIO;
53111da177e4SLinus Torvalds }
53121da177e4SLinus Torvalds 
53131da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
53141da177e4SLinus Torvalds {
5315bcecff77SChuck Lever 	int		status;
5316cd93710eSChuck Lever 	__be32		verf[2];
53171da177e4SLinus Torvalds 
53181da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
5319db942bbdSBenny Halevy 	if (!status)
5320db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
5321db942bbdSBenny Halevy 	if (unlikely(status))
53221da177e4SLinus Torvalds 		return status;
5323cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
532444109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
5325cd93710eSChuck Lever 			__func__, verf[0], verf[1]);
532664bd577eSTrond Myklebust 	return xdr_read_pages(xdr, xdr->buf->page_len);
53271da177e4SLinus Torvalds }
53281da177e4SLinus Torvalds 
53291da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
53301da177e4SLinus Torvalds {
53311da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5332bcecff77SChuck Lever 	u32 len, recvd;
53338687b63aSAl Viro 	__be32 *p;
53341da177e4SLinus Torvalds 	int status;
53351da177e4SLinus Torvalds 
53361da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
53371da177e4SLinus Torvalds 	if (status)
53381da177e4SLinus Torvalds 		return status;
53391da177e4SLinus Torvalds 
53401da177e4SLinus Torvalds 	/* Convert length of symlink */
5341c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5342c0eae66eSBenny Halevy 	if (unlikely(!p))
5343c0eae66eSBenny Halevy 		goto out_overflow;
5344cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
53451da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
5346fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
53471da177e4SLinus Torvalds 		return -ENAMETOOLONG;
53481da177e4SLinus Torvalds 	}
534964bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, len);
53501da177e4SLinus Torvalds 	if (recvd < len) {
5351fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
53521da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
53531da177e4SLinus Torvalds 		return -EIO;
53541da177e4SLinus Torvalds 	}
53551da177e4SLinus Torvalds 	/*
53561da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
53571da177e4SLinus Torvalds 	 * the link text will be copied directly into the
53581da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
53591da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
53601da177e4SLinus Torvalds 	 * null-termination).
53611da177e4SLinus Torvalds 	 */
5362b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
53631da177e4SLinus Torvalds 	return 0;
5364c0eae66eSBenny Halevy out_overflow:
5365c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5366c0eae66eSBenny Halevy 	return -EIO;
53671da177e4SLinus Torvalds }
53681da177e4SLinus Torvalds 
53691da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
53701da177e4SLinus Torvalds {
53711da177e4SLinus Torvalds 	int status;
53721da177e4SLinus Torvalds 
53731da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
53741da177e4SLinus Torvalds 	if (status)
53751da177e4SLinus Torvalds 		goto out;
53761da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
53771da177e4SLinus Torvalds out:
53781da177e4SLinus Torvalds 	return status;
53791da177e4SLinus Torvalds }
53801da177e4SLinus Torvalds 
53811da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
53821da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
53831da177e4SLinus Torvalds {
53841da177e4SLinus Torvalds 	int status;
53851da177e4SLinus Torvalds 
53861da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
53871da177e4SLinus Torvalds 	if (status)
53881da177e4SLinus Torvalds 		goto out;
53891da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
53901da177e4SLinus Torvalds 		goto out;
53911da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
53921da177e4SLinus Torvalds out:
53931da177e4SLinus Torvalds 	return status;
53941da177e4SLinus Torvalds }
53951da177e4SLinus Torvalds 
53961da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
53971da177e4SLinus Torvalds {
53981da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
53991da177e4SLinus Torvalds }
54001da177e4SLinus Torvalds 
540156ae19f3STrond Myklebust static int
540256ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
540356ae19f3STrond Myklebust {
540456ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
540556ae19f3STrond Myklebust }
540656ae19f3STrond Myklebust 
5407029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5408bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5409029d105eSJ. Bruce Fields {
5410256e48bbSTrond Myklebust 	unsigned int savep;
5411029d105eSJ. Bruce Fields 	uint32_t attrlen,
5412dae100c2SFred Isaman 		 bitmap[3] = {0};
5413029d105eSJ. Bruce Fields 	int status;
5414cff298c7STrond Myklebust 	unsigned int pg_offset;
5415029d105eSJ. Bruce Fields 
5416bf118a34SAndy Adamson 	res->acl_len = 0;
5417029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5418029d105eSJ. Bruce Fields 		goto out;
54195a006899SSachin Prabhu 
5420519d3959STrond Myklebust 	xdr_enter_page(xdr, xdr->buf->page_len);
5421519d3959STrond Myklebust 
5422cff298c7STrond Myklebust 	/* Calculate the offset of the page data */
5423cff298c7STrond Myklebust 	pg_offset = xdr->buf->head[0].iov_len;
54245a006899SSachin Prabhu 
5425029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5426029d105eSJ. Bruce Fields 		goto out;
5427029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5428029d105eSJ. Bruce Fields 		goto out;
5429029d105eSJ. Bruce Fields 
5430029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5431029d105eSJ. Bruce Fields 		return -EIO;
5432029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5433029d105eSJ. Bruce Fields 
5434bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5435bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5436bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5437cff298c7STrond Myklebust 		res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5438519d3959STrond Myklebust 		res->acl_len = attrlen;
54391f1ea6c2STrond Myklebust 
54401f1ea6c2STrond Myklebust 		/* Check for receive buffer overflow */
54411f1ea6c2STrond Myklebust 		if (res->acl_len > (xdr->nwords << 2) ||
54421f1ea6c2STrond Myklebust 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
54431f1ea6c2STrond Myklebust 			res->acl_flags |= NFS4_ACL_TRUNC;
5444519d3959STrond Myklebust 			dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5445cff298c7STrond Myklebust 					attrlen, xdr->nwords << 2);
5446029d105eSJ. Bruce Fields 		}
54478c233cf9SJ. Bruce Fields 	} else
54488c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5449029d105eSJ. Bruce Fields 
5450029d105eSJ. Bruce Fields out:
5451029d105eSJ. Bruce Fields 	return status;
5452029d105eSJ. Bruce Fields }
5453029d105eSJ. Bruce Fields 
54541da177e4SLinus Torvalds static int
54551da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
54561da177e4SLinus Torvalds {
54571da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
54581da177e4SLinus Torvalds }
54591da177e4SLinus Torvalds 
54609e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
54611da177e4SLinus Torvalds {
54621da177e4SLinus Torvalds 	int status;
54631da177e4SLinus Torvalds 
54641da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
54651da177e4SLinus Torvalds 	if (status)
54661da177e4SLinus Torvalds 		return status;
546737c88763STrond Myklebust 	if (decode_bitmap4(xdr, NULL, 0) >= 0)
54681da177e4SLinus Torvalds 		return 0;
5469c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5470c0eae66eSBenny Halevy 	return -EIO;
54711da177e4SLinus Torvalds }
54721da177e4SLinus Torvalds 
5473bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
54741da177e4SLinus Torvalds {
54758687b63aSAl Viro 	__be32 *p;
54761da177e4SLinus Torvalds 	uint32_t opnum;
54771da177e4SLinus Torvalds 	int32_t nfserr;
54781da177e4SLinus Torvalds 
5479c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5480c0eae66eSBenny Halevy 	if (unlikely(!p))
5481c0eae66eSBenny Halevy 		goto out_overflow;
54826f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
54831da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5484fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
54851da177e4SLinus Torvalds 			" %d\n", opnum);
54861da177e4SLinus Torvalds 		return -EIO;
54871da177e4SLinus Torvalds 	}
5488cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
54891da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5490c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5491c0eae66eSBenny Halevy 		if (unlikely(!p))
5492c0eae66eSBenny Halevy 			goto out_overflow;
5493bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5494bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
54951da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
54961da177e4SLinus Torvalds 		uint32_t len;
54971da177e4SLinus Torvalds 
54981da177e4SLinus Torvalds 		/* skip netid string */
5499c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5500c0eae66eSBenny Halevy 		if (unlikely(!p))
5501c0eae66eSBenny Halevy 			goto out_overflow;
5502cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5503c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5504c0eae66eSBenny Halevy 		if (unlikely(!p))
5505c0eae66eSBenny Halevy 			goto out_overflow;
55061da177e4SLinus Torvalds 
55071da177e4SLinus Torvalds 		/* skip uaddr string */
5508c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5509c0eae66eSBenny Halevy 		if (unlikely(!p))
5510c0eae66eSBenny Halevy 			goto out_overflow;
5511cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5512c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5513c0eae66eSBenny Halevy 		if (unlikely(!p))
5514c0eae66eSBenny Halevy 			goto out_overflow;
55151da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
55161da177e4SLinus Torvalds 	} else
5517856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
55181da177e4SLinus Torvalds 
55191da177e4SLinus Torvalds 	return 0;
5520c0eae66eSBenny Halevy out_overflow:
5521c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5522c0eae66eSBenny Halevy 	return -EIO;
55231da177e4SLinus Torvalds }
55241da177e4SLinus Torvalds 
55251da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
55261da177e4SLinus Torvalds {
55271da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
55281da177e4SLinus Torvalds }
55291da177e4SLinus Torvalds 
55309137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
55311da177e4SLinus Torvalds {
55328687b63aSAl Viro 	__be32 *p;
55331da177e4SLinus Torvalds 	int status;
55341da177e4SLinus Torvalds 
55351da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
55361da177e4SLinus Torvalds 	if (status)
55371da177e4SLinus Torvalds 		return status;
55381da177e4SLinus Torvalds 
55392f2c63bcSTrond Myklebust 	p = xdr_inline_decode(xdr, 8);
5540c0eae66eSBenny Halevy 	if (unlikely(!p))
5541c0eae66eSBenny Halevy 		goto out_overflow;
55426f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
55436f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
55442f2c63bcSTrond Myklebust 	return decode_write_verifier(xdr, &res->verf->verifier);
5545c0eae66eSBenny Halevy out_overflow:
5546c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5547c0eae66eSBenny Halevy 	return -EIO;
55481da177e4SLinus Torvalds }
55491da177e4SLinus Torvalds 
55501da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
55511da177e4SLinus Torvalds {
55521da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
55531da177e4SLinus Torvalds }
55541da177e4SLinus Torvalds 
5555fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr,
5556fb15b26fSChuck Lever 			      struct nfs4_secinfo4 *flavor)
55575a5ea0d4SBryan Schumaker {
5558fb15b26fSChuck Lever 	u32 oid_len;
55595a5ea0d4SBryan Schumaker 	__be32 *p;
55605a5ea0d4SBryan Schumaker 
55615a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
55625a5ea0d4SBryan Schumaker 	if (unlikely(!p))
55635a5ea0d4SBryan Schumaker 		goto out_overflow;
5564fb15b26fSChuck Lever 	oid_len = be32_to_cpup(p);
5565fb15b26fSChuck Lever 	if (oid_len > GSS_OID_MAX_LEN)
55665a5ea0d4SBryan Schumaker 		goto out_err;
55675a5ea0d4SBryan Schumaker 
5568fb15b26fSChuck Lever 	p = xdr_inline_decode(xdr, oid_len);
55695a5ea0d4SBryan Schumaker 	if (unlikely(!p))
55705a5ea0d4SBryan Schumaker 		goto out_overflow;
5571fb15b26fSChuck Lever 	memcpy(flavor->flavor_info.oid.data, p, oid_len);
5572fb15b26fSChuck Lever 	flavor->flavor_info.oid.len = oid_len;
55735a5ea0d4SBryan Schumaker 
55745a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
55755a5ea0d4SBryan Schumaker 	if (unlikely(!p))
55765a5ea0d4SBryan Schumaker 		goto out_overflow;
5577fb15b26fSChuck Lever 	flavor->flavor_info.qop = be32_to_cpup(p++);
5578fb15b26fSChuck Lever 	flavor->flavor_info.service = be32_to_cpup(p);
55795a5ea0d4SBryan Schumaker 
55805a5ea0d4SBryan Schumaker 	return 0;
55815a5ea0d4SBryan Schumaker 
55825a5ea0d4SBryan Schumaker out_overflow:
55835a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
55845a5ea0d4SBryan Schumaker 	return -EIO;
55855a5ea0d4SBryan Schumaker out_err:
55865a5ea0d4SBryan Schumaker 	return -EINVAL;
55875a5ea0d4SBryan Schumaker }
55885a5ea0d4SBryan Schumaker 
558931e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
55905a5ea0d4SBryan Schumaker {
5591fb15b26fSChuck Lever 	struct nfs4_secinfo4 *sec_flavor;
5592fb15b26fSChuck Lever 	unsigned int i, num_flavors;
55935a5ea0d4SBryan Schumaker 	int status;
55945a5ea0d4SBryan Schumaker 	__be32 *p;
55955a5ea0d4SBryan Schumaker 
55965a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
55975a5ea0d4SBryan Schumaker 	if (unlikely(!p))
55985a5ea0d4SBryan Schumaker 		goto out_overflow;
55995a5ea0d4SBryan Schumaker 
5600c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5601c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5602c3dfc280SBryan Schumaker 
5603c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
56045a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5605c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
56065a5ea0d4SBryan Schumaker 			break;
56075a5ea0d4SBryan Schumaker 
56085a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
56095a5ea0d4SBryan Schumaker 		if (unlikely(!p))
56105a5ea0d4SBryan Schumaker 			goto out_overflow;
56115a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
56125a5ea0d4SBryan Schumaker 
56135a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5614613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5615613e901eSBryan Schumaker 			if (status)
5616613e901eSBryan Schumaker 				goto out;
56175a5ea0d4SBryan Schumaker 		}
5618c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
56195a5ea0d4SBryan Schumaker 	}
56205a5ea0d4SBryan Schumaker 
562131e4dda4SBryan Schumaker 	status = 0;
5622613e901eSBryan Schumaker out:
5623613e901eSBryan Schumaker 	return status;
56245a5ea0d4SBryan Schumaker out_overflow:
56255a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
56265a5ea0d4SBryan Schumaker 	return -EIO;
56275a5ea0d4SBryan Schumaker }
56285a5ea0d4SBryan Schumaker 
562931e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
563031e4dda4SBryan Schumaker {
563131e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO);
563231e4dda4SBryan Schumaker 	if (status)
563331e4dda4SBryan Schumaker 		return status;
563431e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
563531e4dda4SBryan Schumaker }
563631e4dda4SBryan Schumaker 
563799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
563831e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
563931e4dda4SBryan Schumaker {
564031e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
564131e4dda4SBryan Schumaker 	if (status)
564231e4dda4SBryan Schumaker 		return status;
564331e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
564431e4dda4SBryan Schumaker }
564531e4dda4SBryan Schumaker 
56462031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
56472031cd1aSWeston Andros Adamson {
56482031cd1aSWeston Andros Adamson 	__be32 *p;
56492031cd1aSWeston Andros Adamson 	uint32_t bitmap_words;
56502031cd1aSWeston Andros Adamson 	unsigned int i;
56512031cd1aSWeston Andros Adamson 
56522031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
56534edabfd7SPan Bian 	if (!p)
56544edabfd7SPan Bian 		return -EIO;
56552031cd1aSWeston Andros Adamson 	bitmap_words = be32_to_cpup(p++);
56562031cd1aSWeston Andros Adamson 	if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
56572031cd1aSWeston Andros Adamson 		return -EIO;
56582031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4 * bitmap_words);
56592031cd1aSWeston Andros Adamson 	for (i = 0; i < bitmap_words; i++)
56602031cd1aSWeston Andros Adamson 		op_map->u.words[i] = be32_to_cpup(p++);
56612031cd1aSWeston Andros Adamson 
56622031cd1aSWeston Andros Adamson 	return 0;
56632031cd1aSWeston Andros Adamson }
56642031cd1aSWeston Andros Adamson 
566599fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
566699fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
566799fe60d0SBenny Halevy {
566899fe60d0SBenny Halevy 	__be32 *p;
566999fe60d0SBenny Halevy 	uint32_t dummy;
56702460ba57SBenny Halevy 	char *dummy_str;
567199fe60d0SBenny Halevy 	int status;
56727d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
567399fe60d0SBenny Halevy 
567499fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
567599fe60d0SBenny Halevy 	if (status)
567699fe60d0SBenny Halevy 		return status;
567799fe60d0SBenny Halevy 
5678c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5679c0eae66eSBenny Halevy 	if (unlikely(!p))
5680c0eae66eSBenny Halevy 		goto out_overflow;
568132b01310STrond Myklebust 	xdr_decode_hyper(p, &res->clientid);
5682c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5683c0eae66eSBenny Halevy 	if (unlikely(!p))
5684c0eae66eSBenny Halevy 		goto out_overflow;
568532b01310STrond Myklebust 	res->seqid = be32_to_cpup(p++);
568632b01310STrond Myklebust 	res->flags = be32_to_cpup(p++);
568799fe60d0SBenny Halevy 
56882031cd1aSWeston Andros Adamson 	res->state_protect.how = be32_to_cpup(p);
56892031cd1aSWeston Andros Adamson 	switch (res->state_protect.how) {
56902031cd1aSWeston Andros Adamson 	case SP4_NONE:
56912031cd1aSWeston Andros Adamson 		break;
56922031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
56932031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.enforce);
56942031cd1aSWeston Andros Adamson 		if (status)
56952031cd1aSWeston Andros Adamson 			return status;
56962031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.allow);
56972031cd1aSWeston Andros Adamson 		if (status)
56982031cd1aSWeston Andros Adamson 			return status;
56992031cd1aSWeston Andros Adamson 		break;
57002031cd1aSWeston Andros Adamson 	default:
57012031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
570299fe60d0SBenny Halevy 		return -EIO;
57032031cd1aSWeston Andros Adamson 	}
570499fe60d0SBenny Halevy 
5705acdeb69dSChuck Lever 	/* server_owner4.so_minor_id */
5706c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5707c0eae66eSBenny Halevy 	if (unlikely(!p))
5708c0eae66eSBenny Halevy 		goto out_overflow;
5709acdeb69dSChuck Lever 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
571099fe60d0SBenny Halevy 
5711acdeb69dSChuck Lever 	/* server_owner4.so_major_id */
57122460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
57132460ba57SBenny Halevy 	if (unlikely(status))
57142460ba57SBenny Halevy 		return status;
5715acdeb69dSChuck Lever 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5716acdeb69dSChuck Lever 	res->server_owner->major_id_sz = dummy;
571778fe0f41SWeston Andros Adamson 
5718acdeb69dSChuck Lever 	/* server_scope4 */
5719acdeb69dSChuck Lever 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5720acdeb69dSChuck Lever 	if (unlikely(status))
5721acdeb69dSChuck Lever 		return status;
572278fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
572378fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
572478fe0f41SWeston Andros Adamson 
57257d2ed9acSWeston Andros Adamson 	/* Implementation Id */
57267d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
57277d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
57287d2ed9acSWeston Andros Adamson 		goto out_overflow;
57297d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
57307d2ed9acSWeston Andros Adamson 
57317d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
57327d2ed9acSWeston Andros Adamson 		/* nii_domain */
57332460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
57342460ba57SBenny Halevy 		if (unlikely(status))
57352460ba57SBenny Halevy 			return status;
57367d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
573799fe60d0SBenny Halevy 
57387d2ed9acSWeston Andros Adamson 		/* nii_name */
57397d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
57407d2ed9acSWeston Andros Adamson 		if (unlikely(status))
57417d2ed9acSWeston Andros Adamson 			return status;
57427d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
57437d2ed9acSWeston Andros Adamson 
57447d2ed9acSWeston Andros Adamson 		/* nii_date */
57457d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
57467d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
57477d2ed9acSWeston Andros Adamson 			goto out_overflow;
57487d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
57497d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
57507d2ed9acSWeston Andros Adamson 
57517d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
57527d2ed9acSWeston Andros Adamson 	}
575399fe60d0SBenny Halevy 	return 0;
5754c0eae66eSBenny Halevy out_overflow:
5755c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5756c0eae66eSBenny Halevy 	return -EIO;
575799fe60d0SBenny Halevy }
5758fc931582SAndy Adamson 
5759fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5760fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5761fc931582SAndy Adamson {
5762fc931582SAndy Adamson 	__be32 *p;
5763c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5764fc931582SAndy Adamson 
5765c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5766c0eae66eSBenny Halevy 	if (unlikely(!p))
5767c0eae66eSBenny Halevy 		goto out_overflow;
5768c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5769c9c30dd5SBenny Halevy 	if (val)
5770c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
57716f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
57726f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
57736f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
57746f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
57756f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5776cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5777fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5778a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5779a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5780fc931582SAndy Adamson 		return -EINVAL;
5781fc931582SAndy Adamson 	}
5782c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5783c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5784c0eae66eSBenny Halevy 		if (unlikely(!p))
5785c0eae66eSBenny Halevy 			goto out_overflow;
5786c0eae66eSBenny Halevy 	}
5787fc931582SAndy Adamson 	return 0;
5788c0eae66eSBenny Halevy out_overflow:
5789c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5790c0eae66eSBenny Halevy 	return -EIO;
5791fc931582SAndy Adamson }
5792fc931582SAndy Adamson 
5793e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5794e78291e4SBenny Halevy {
5795e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5796fc931582SAndy Adamson }
5797fc931582SAndy Adamson 
57987c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
57997c44f1aeSWeston Andros Adamson 				struct nfs41_bind_conn_to_session_res *res)
58007c44f1aeSWeston Andros Adamson {
58017c44f1aeSWeston Andros Adamson 	__be32 *p;
58027c44f1aeSWeston Andros Adamson 	int status;
58037c44f1aeSWeston Andros Adamson 
58047c44f1aeSWeston Andros Adamson 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
58057c44f1aeSWeston Andros Adamson 	if (!status)
580671a097c6STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
58077c44f1aeSWeston Andros Adamson 	if (unlikely(status))
58087c44f1aeSWeston Andros Adamson 		return status;
58097c44f1aeSWeston Andros Adamson 
58107c44f1aeSWeston Andros Adamson 	/* dir flags, rdma mode bool */
58117c44f1aeSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 8);
58127c44f1aeSWeston Andros Adamson 	if (unlikely(!p))
58137c44f1aeSWeston Andros Adamson 		goto out_overflow;
58147c44f1aeSWeston Andros Adamson 
58157c44f1aeSWeston Andros Adamson 	res->dir = be32_to_cpup(p++);
58167c44f1aeSWeston Andros Adamson 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
58177c44f1aeSWeston Andros Adamson 		return -EIO;
58187c44f1aeSWeston Andros Adamson 	if (be32_to_cpup(p) == 0)
58197c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = false;
58207c44f1aeSWeston Andros Adamson 	else
58217c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = true;
58227c44f1aeSWeston Andros Adamson 
58237c44f1aeSWeston Andros Adamson 	return 0;
58247c44f1aeSWeston Andros Adamson out_overflow:
58257c44f1aeSWeston Andros Adamson 	print_overflow_msg(__func__, xdr);
58267c44f1aeSWeston Andros Adamson 	return -EIO;
58277c44f1aeSWeston Andros Adamson }
58287c44f1aeSWeston Andros Adamson 
5829fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5830fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5831fc931582SAndy Adamson {
5832fc931582SAndy Adamson 	__be32 *p;
5833fc931582SAndy Adamson 	int status;
5834fc931582SAndy Adamson 
5835fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5836e78291e4SBenny Halevy 	if (!status)
583779969dd1STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
5838e78291e4SBenny Halevy 	if (unlikely(status))
5839fc931582SAndy Adamson 		return status;
5840fc931582SAndy Adamson 
5841fc931582SAndy Adamson 	/* seqid, flags */
5842c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5843c0eae66eSBenny Halevy 	if (unlikely(!p))
5844c0eae66eSBenny Halevy 		goto out_overflow;
584579969dd1STrond Myklebust 	res->seqid = be32_to_cpup(p++);
584679969dd1STrond Myklebust 	res->flags = be32_to_cpup(p);
5847fc931582SAndy Adamson 
5848fc931582SAndy Adamson 	/* Channel attributes */
584979969dd1STrond Myklebust 	status = decode_chan_attrs(xdr, &res->fc_attrs);
5850fc931582SAndy Adamson 	if (!status)
585179969dd1STrond Myklebust 		status = decode_chan_attrs(xdr, &res->bc_attrs);
5852fc931582SAndy Adamson 	return status;
5853c0eae66eSBenny Halevy out_overflow:
5854c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5855c0eae66eSBenny Halevy 	return -EIO;
5856fc931582SAndy Adamson }
58570f3e66c6SAndy Adamson 
58580f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
58590f3e66c6SAndy Adamson {
58600f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
58610f3e66c6SAndy Adamson }
586218019753SRicardo Labiaga 
586366245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
586466245539STrond Myklebust {
586566245539STrond Myklebust 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
586666245539STrond Myklebust }
586766245539STrond Myklebust 
586818019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
586918019753SRicardo Labiaga {
587018019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
587118019753SRicardo Labiaga }
587299fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
587399fe60d0SBenny Halevy 
58749b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
58759b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
58769b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
58779b7b9fccSAndy Adamson {
58789b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5879e3725ec0STrond Myklebust 	struct nfs4_session *session;
5880fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5881fc01cea9SAndy Adamson 	u32 dummy;
5882fc01cea9SAndy Adamson 	int status;
5883fc01cea9SAndy Adamson 	__be32 *p;
5884fc01cea9SAndy Adamson 
5885e3725ec0STrond Myklebust 	if (res->sr_slot == NULL)
58869b7b9fccSAndy Adamson 		return 0;
58873bd2384aSChuck Lever 	if (!res->sr_slot->table->session)
58883bd2384aSChuck Lever 		return 0;
58899b7b9fccSAndy Adamson 
5890fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5891e78291e4SBenny Halevy 	if (!status)
5892e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5893e78291e4SBenny Halevy 	if (unlikely(status))
5894fc01cea9SAndy Adamson 		goto out_err;
58959b7b9fccSAndy Adamson 
5896fc01cea9SAndy Adamson 	/*
5897fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5898fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5899fc01cea9SAndy Adamson 	 */
5900fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5901e3725ec0STrond Myklebust 	session = res->sr_slot->table->session;
5902fc01cea9SAndy Adamson 
5903e3725ec0STrond Myklebust 	if (memcmp(id.data, session->sess_id.data,
5904fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5905fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5906fc01cea9SAndy Adamson 		goto out_err;
5907fc01cea9SAndy Adamson 	}
5908e78291e4SBenny Halevy 
5909c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5910c0eae66eSBenny Halevy 	if (unlikely(!p))
5911c0eae66eSBenny Halevy 		goto out_overflow;
5912e78291e4SBenny Halevy 
5913fc01cea9SAndy Adamson 	/* seqid */
59146f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5915dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5916fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5917fc01cea9SAndy Adamson 		goto out_err;
5918fc01cea9SAndy Adamson 	}
5919fc01cea9SAndy Adamson 	/* slot id */
59206f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5921df2fabffSTrond Myklebust 	if (dummy != res->sr_slot->slot_nr) {
5922fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5923fc01cea9SAndy Adamson 		goto out_err;
5924fc01cea9SAndy Adamson 	}
5925da0507b7STrond Myklebust 	/* highest slot id */
5926da0507b7STrond Myklebust 	res->sr_highest_slotid = be32_to_cpup(p++);
5927464ee9f9STrond Myklebust 	/* target highest slot id */
5928464ee9f9STrond Myklebust 	res->sr_target_highest_slotid = be32_to_cpup(p++);
59290629e370SAlexandros Batsakis 	/* result flags */
59300629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5931fc01cea9SAndy Adamson 	status = 0;
5932fc01cea9SAndy Adamson out_err:
5933fc01cea9SAndy Adamson 	res->sr_status = status;
5934fc01cea9SAndy Adamson 	return status;
5935c0eae66eSBenny Halevy out_overflow:
5936c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5937c0eae66eSBenny Halevy 	status = -EIO;
5938c0eae66eSBenny Halevy 	goto out_err;
5939fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
59409b7b9fccSAndy Adamson 	return 0;
5941fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
59429b7b9fccSAndy Adamson }
59439b7b9fccSAndy Adamson 
5944b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
594593b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
594693b717fdSTrond Myklebust {
594793b717fdSTrond Myklebust 	stateid->type = NFS4_LAYOUT_STATEID_TYPE;
594893b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
594993b717fdSTrond Myklebust }
595093b717fdSTrond Myklebust 
5951b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
59524e590803STrond Myklebust 				struct nfs4_getdeviceinfo_res *res)
5953b1f69b75SAndy Adamson {
59544e590803STrond Myklebust 	struct pnfs_device *pdev = res->pdev;
5955b1f69b75SAndy Adamson 	__be32 *p;
5956b1f69b75SAndy Adamson 	uint32_t len, type;
5957b1f69b75SAndy Adamson 	int status;
5958b1f69b75SAndy Adamson 
5959b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5960b1f69b75SAndy Adamson 	if (status) {
5961b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5962b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5963b1f69b75SAndy Adamson 			if (unlikely(!p))
5964b1f69b75SAndy Adamson 				goto out_overflow;
5965b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5966b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5967b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5968b1f69b75SAndy Adamson 		}
5969b1f69b75SAndy Adamson 		return status;
5970b1f69b75SAndy Adamson 	}
5971b1f69b75SAndy Adamson 
5972b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5973b1f69b75SAndy Adamson 	if (unlikely(!p))
5974b1f69b75SAndy Adamson 		goto out_overflow;
5975b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5976b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5977b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5978b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5979b1f69b75SAndy Adamson 		return -EINVAL;
5980b1f69b75SAndy Adamson 	}
5981b1f69b75SAndy Adamson 	/*
5982b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5983b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5984b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5985b1f69b75SAndy Adamson 	 */
5986b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
598713fe4ba1STrond Myklebust 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
598813fe4ba1STrond Myklebust 		goto out_overflow;
5989b1f69b75SAndy Adamson 
5990b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5991b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5992b1f69b75SAndy Adamson 	if (unlikely(!p))
5993b1f69b75SAndy Adamson 		goto out_overflow;
5994b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5995b1f69b75SAndy Adamson 	if (len) {
5996ead00597SChuck Lever 		uint32_t i;
5997b1f69b75SAndy Adamson 
5998b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5999b1f69b75SAndy Adamson 		if (unlikely(!p))
6000b1f69b75SAndy Adamson 			goto out_overflow;
600184c9dee3SChristoph Hellwig 
60024e590803STrond Myklebust 		res->notification = be32_to_cpup(p++);
600384c9dee3SChristoph Hellwig 		for (i = 1; i < len; i++) {
600484c9dee3SChristoph Hellwig 			if (be32_to_cpup(p++)) {
600584c9dee3SChristoph Hellwig 				dprintk("%s: unsupported notification\n",
6006b1f69b75SAndy Adamson 					__func__);
6007b1f69b75SAndy Adamson 				return -EIO;
6008b1f69b75SAndy Adamson 			}
6009b1f69b75SAndy Adamson 		}
6010b1f69b75SAndy Adamson 	}
6011b1f69b75SAndy Adamson 	return 0;
6012b1f69b75SAndy Adamson out_overflow:
6013b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
6014b1f69b75SAndy Adamson 	return -EIO;
6015b1f69b75SAndy Adamson }
6016b1f69b75SAndy Adamson 
6017b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6018b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
6019b1f69b75SAndy Adamson {
6020b1f69b75SAndy Adamson 	__be32 *p;
6021b1f69b75SAndy Adamson 	int status;
6022b1f69b75SAndy Adamson 	u32 layout_count;
602364bd577eSTrond Myklebust 	u32 recvd;
6024b1f69b75SAndy Adamson 
6025b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
6026b1f69b75SAndy Adamson 	if (status)
6027b1f69b75SAndy Adamson 		return status;
6028ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
6029b1f69b75SAndy Adamson 	if (unlikely(!p))
6030b1f69b75SAndy Adamson 		goto out_overflow;
6031ea9d23f5STrond Myklebust 	res->return_on_close = be32_to_cpup(p);
603293b717fdSTrond Myklebust 	decode_layout_stateid(xdr, &res->stateid);
6033ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
6034ea9d23f5STrond Myklebust 	if (unlikely(!p))
6035ea9d23f5STrond Myklebust 		goto out_overflow;
6036b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
6037b1f69b75SAndy Adamson 	if (!layout_count) {
6038b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
6039b1f69b75SAndy Adamson 			__func__);
6040b1f69b75SAndy Adamson 		return -EINVAL;
6041b1f69b75SAndy Adamson 	}
6042b1f69b75SAndy Adamson 
604335124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
6044b1f69b75SAndy Adamson 	if (unlikely(!p))
6045b1f69b75SAndy Adamson 		goto out_overflow;
6046b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
6047b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
6048b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
6049b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
605035124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
6051b1f69b75SAndy Adamson 
6052b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6053b1f69b75SAndy Adamson 		__func__,
6054b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
6055b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
6056b1f69b75SAndy Adamson 		res->range.iomode,
6057b1f69b75SAndy Adamson 		res->type,
605835124a09SWeston Andros Adamson 		res->layoutp->len);
6059b1f69b75SAndy Adamson 
606064bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, res->layoutp->len);
606135124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
606235124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
606335124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
606435124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
606535124a09SWeston Andros Adamson 		return -EINVAL;
606635124a09SWeston Andros Adamson 	}
606735124a09SWeston Andros Adamson 
6068b1f69b75SAndy Adamson 	if (layout_count > 1) {
6069b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
6070b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
6071b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
6072b1f69b75SAndy Adamson 		 * minimum it requested.
6073b1f69b75SAndy Adamson 		 */
6074b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
6075b1f69b75SAndy Adamson 			__func__, layout_count);
6076b1f69b75SAndy Adamson 	}
6077b1f69b75SAndy Adamson 
6078b1f69b75SAndy Adamson 	return 0;
6079b1f69b75SAndy Adamson out_overflow:
6080b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
6081b1f69b75SAndy Adamson 	return -EIO;
6082b1f69b75SAndy Adamson }
6083863a3c6cSAndy Adamson 
6084cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
6085cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
6086cbe82603SBenny Halevy {
6087cbe82603SBenny Halevy 	__be32 *p;
6088cbe82603SBenny Halevy 	int status;
6089cbe82603SBenny Halevy 
6090cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6091cbe82603SBenny Halevy 	if (status)
6092cbe82603SBenny Halevy 		return status;
6093cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
6094cbe82603SBenny Halevy 	if (unlikely(!p))
6095cbe82603SBenny Halevy 		goto out_overflow;
6096cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
6097cbe82603SBenny Halevy 	if (res->lrs_present)
609893b717fdSTrond Myklebust 		status = decode_layout_stateid(xdr, &res->stateid);
6099fcd8843cSTrond Myklebust 	else
6100fcd8843cSTrond Myklebust 		nfs4_stateid_copy(&res->stateid, &invalid_stateid);
6101cbe82603SBenny Halevy 	return status;
6102cbe82603SBenny Halevy out_overflow:
6103cbe82603SBenny Halevy 	print_overflow_msg(__func__, xdr);
6104cbe82603SBenny Halevy 	return -EIO;
6105cbe82603SBenny Halevy }
6106cbe82603SBenny Halevy 
6107863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
6108863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
6109863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
6110863a3c6cSAndy Adamson {
6111863a3c6cSAndy Adamson 	__be32 *p;
6112863a3c6cSAndy Adamson 	__u32 sizechanged;
6113863a3c6cSAndy Adamson 	int status;
6114863a3c6cSAndy Adamson 
6115863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
6116db29c089SAndy Adamson 	res->status = status;
6117863a3c6cSAndy Adamson 	if (status)
6118863a3c6cSAndy Adamson 		return status;
6119863a3c6cSAndy Adamson 
6120863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
6121863a3c6cSAndy Adamson 	if (unlikely(!p))
6122863a3c6cSAndy Adamson 		goto out_overflow;
6123863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
6124863a3c6cSAndy Adamson 
6125863a3c6cSAndy Adamson 	if (sizechanged) {
6126863a3c6cSAndy Adamson 		/* throw away new size */
6127863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
6128863a3c6cSAndy Adamson 		if (unlikely(!p))
6129863a3c6cSAndy Adamson 			goto out_overflow;
6130863a3c6cSAndy Adamson 	}
6131863a3c6cSAndy Adamson 	return 0;
6132863a3c6cSAndy Adamson out_overflow:
6133863a3c6cSAndy Adamson 	print_overflow_msg(__func__, xdr);
6134863a3c6cSAndy Adamson 	return -EIO;
6135863a3c6cSAndy Adamson }
61367d974794SBryan Schumaker 
61377d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
61387d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
61397d974794SBryan Schumaker {
61407d974794SBryan Schumaker 	__be32 *p;
61417d974794SBryan Schumaker 	int status;
61427d974794SBryan Schumaker 	int num_res;
61437d974794SBryan Schumaker 
61447d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
61457d974794SBryan Schumaker 	if (status)
61467d974794SBryan Schumaker 		return status;
61477d974794SBryan Schumaker 
61487d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
61497d974794SBryan Schumaker 	if (unlikely(!p))
61507d974794SBryan Schumaker 		goto out_overflow;
61517d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
61527d974794SBryan Schumaker 	if (num_res != 1)
61537d974794SBryan Schumaker 		goto out;
61547d974794SBryan Schumaker 
61557d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
61567d974794SBryan Schumaker 	if (unlikely(!p))
61577d974794SBryan Schumaker 		goto out_overflow;
61587d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
61591cab0652SBryan Schumaker 
61601cab0652SBryan Schumaker 	return status;
61617d974794SBryan Schumaker out_overflow:
61627d974794SBryan Schumaker 	print_overflow_msg(__func__, xdr);
61637d974794SBryan Schumaker out:
61647d974794SBryan Schumaker 	return -EIO;
61657d974794SBryan Schumaker }
61669aeda35fSBryan Schumaker 
61679aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
61689aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
61699aeda35fSBryan Schumaker {
61709f79fb48SAndy Adamson 	res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
61719aeda35fSBryan Schumaker 	return res->status;
61729aeda35fSBryan Schumaker }
6173cf805165STrond Myklebust #else
6174cf805165STrond Myklebust static inline
6175cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr,
6176cf805165STrond Myklebust 			       struct nfs4_layoutreturn_res *res)
6177cf805165STrond Myklebust {
6178cf805165STrond Myklebust 	return 0;
6179cf805165STrond Myklebust }
6180b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
6181b1f69b75SAndy Adamson 
61821da177e4SLinus Torvalds /*
618349c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
618449c2559eSBenny Halevy  */
618549c2559eSBenny Halevy 
618649c2559eSBenny Halevy /*
61871da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
61881da177e4SLinus Torvalds  */
6189bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6190bf269551SChuck Lever 				       struct xdr_stream *xdr,
6191fc016483SChristoph Hellwig 				       void *data)
61921da177e4SLinus Torvalds {
6193fc016483SChristoph Hellwig 	struct nfs_closeres *res = data;
61941da177e4SLinus Torvalds 	struct compound_hdr hdr;
61951da177e4SLinus Torvalds 	int status;
61961da177e4SLinus Torvalds 
6197bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61981da177e4SLinus Torvalds 	if (status)
61991da177e4SLinus Torvalds 		goto out;
6200bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62019b7b9fccSAndy Adamson 	if (status)
62029b7b9fccSAndy Adamson 		goto out;
6203bf269551SChuck Lever 	status = decode_putfh(xdr);
62041da177e4SLinus Torvalds 	if (status)
62051da177e4SLinus Torvalds 		goto out;
6206b6808145STrond Myklebust 	if (res->lr_res) {
6207b6808145STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6208b6808145STrond Myklebust 		res->lr_ret = status;
6209b6808145STrond Myklebust 		if (status)
6210b6808145STrond Myklebust 			goto out;
6211b6808145STrond Myklebust 	}
6212bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
62131da177e4SLinus Torvalds out:
62141da177e4SLinus Torvalds 	return status;
62151da177e4SLinus Torvalds }
62161da177e4SLinus Torvalds 
62171da177e4SLinus Torvalds /*
62181da177e4SLinus Torvalds  * Decode ACCESS response
62191da177e4SLinus Torvalds  */
6220bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6221fc016483SChristoph Hellwig 			       void *data)
62221da177e4SLinus Torvalds {
6223fc016483SChristoph Hellwig 	struct nfs4_accessres *res = data;
62241da177e4SLinus Torvalds 	struct compound_hdr hdr;
62251da177e4SLinus Torvalds 	int status;
62261da177e4SLinus Torvalds 
6227bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62289b7b9fccSAndy Adamson 	if (status)
62299b7b9fccSAndy Adamson 		goto out;
6230bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62319b7b9fccSAndy Adamson 	if (status)
62321da177e4SLinus Torvalds 		goto out;
6233bf269551SChuck Lever 	status = decode_putfh(xdr);
623476b32999STrond Myklebust 	if (status != 0)
623576b32999STrond Myklebust 		goto out;
62366168f62cSWeston Andros Adamson 	status = decode_access(xdr, &res->supported, &res->access);
623776b32999STrond Myklebust 	if (status != 0)
623876b32999STrond Myklebust 		goto out;
62396926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
62401da177e4SLinus Torvalds out:
62411da177e4SLinus Torvalds 	return status;
62421da177e4SLinus Torvalds }
62431da177e4SLinus Torvalds 
62441da177e4SLinus Torvalds /*
62451da177e4SLinus Torvalds  * Decode LOOKUP response
62461da177e4SLinus Torvalds  */
6247bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6248fc016483SChristoph Hellwig 			       void *data)
62491da177e4SLinus Torvalds {
6250fc016483SChristoph Hellwig 	struct nfs4_lookup_res *res = data;
62511da177e4SLinus Torvalds 	struct compound_hdr hdr;
62521da177e4SLinus Torvalds 	int status;
62531da177e4SLinus Torvalds 
6254bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62559b7b9fccSAndy Adamson 	if (status)
62569b7b9fccSAndy Adamson 		goto out;
6257bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62589b7b9fccSAndy Adamson 	if (status)
62591da177e4SLinus Torvalds 		goto out;
6260bf269551SChuck Lever 	status = decode_putfh(xdr);
6261bf269551SChuck Lever 	if (status)
62621da177e4SLinus Torvalds 		goto out;
6263bf269551SChuck Lever 	status = decode_lookup(xdr);
6264bf269551SChuck Lever 	if (status)
62651da177e4SLinus Torvalds 		goto out;
6266bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6267bf269551SChuck Lever 	if (status)
62681da177e4SLinus Torvalds 		goto out;
6269aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62701da177e4SLinus Torvalds out:
62711da177e4SLinus Torvalds 	return status;
62721da177e4SLinus Torvalds }
62731da177e4SLinus Torvalds 
62741da177e4SLinus Torvalds /*
62755b5faaf6SJeff Layton  * Decode LOOKUPP response
62765b5faaf6SJeff Layton  */
62775b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
62785b5faaf6SJeff Layton 		void *data)
62795b5faaf6SJeff Layton {
62805b5faaf6SJeff Layton 	struct nfs4_lookupp_res *res = data;
62815b5faaf6SJeff Layton 	struct compound_hdr hdr;
62825b5faaf6SJeff Layton 	int status;
62835b5faaf6SJeff Layton 
62845b5faaf6SJeff Layton 	status = decode_compound_hdr(xdr, &hdr);
62855b5faaf6SJeff Layton 	if (status)
62865b5faaf6SJeff Layton 		goto out;
62875b5faaf6SJeff Layton 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62885b5faaf6SJeff Layton 	if (status)
62895b5faaf6SJeff Layton 		goto out;
62905b5faaf6SJeff Layton 	status = decode_putfh(xdr);
62915b5faaf6SJeff Layton 	if (status)
62925b5faaf6SJeff Layton 		goto out;
62935b5faaf6SJeff Layton 	status = decode_lookupp(xdr);
62945b5faaf6SJeff Layton 	if (status)
62955b5faaf6SJeff Layton 		goto out;
62965b5faaf6SJeff Layton 	status = decode_getfh(xdr, res->fh);
62975b5faaf6SJeff Layton 	if (status)
62985b5faaf6SJeff Layton 		goto out;
62995b5faaf6SJeff Layton 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63005b5faaf6SJeff Layton out:
63015b5faaf6SJeff Layton 	return status;
63025b5faaf6SJeff Layton }
63035b5faaf6SJeff Layton 
63045b5faaf6SJeff Layton /*
63051da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
63061da177e4SLinus Torvalds  */
6307bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6308bf269551SChuck Lever 				    struct xdr_stream *xdr,
6309fc016483SChristoph Hellwig 				    void *data)
63101da177e4SLinus Torvalds {
6311fc016483SChristoph Hellwig 	struct nfs4_lookup_res *res = data;
63121da177e4SLinus Torvalds 	struct compound_hdr hdr;
63131da177e4SLinus Torvalds 	int status;
63141da177e4SLinus Torvalds 
6315bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63169b7b9fccSAndy Adamson 	if (status)
63179b7b9fccSAndy Adamson 		goto out;
6318bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63199b7b9fccSAndy Adamson 	if (status)
63201da177e4SLinus Torvalds 		goto out;
6321bf269551SChuck Lever 	status = decode_putrootfh(xdr);
6322bf269551SChuck Lever 	if (status)
63231da177e4SLinus Torvalds 		goto out;
6324bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6325bf269551SChuck Lever 	if (status == 0)
6326aa9c2669SDavid Quigley 		status = decode_getfattr_label(xdr, res->fattr,
6327aa9c2669SDavid Quigley 						res->label, res->server);
63281da177e4SLinus Torvalds out:
63291da177e4SLinus Torvalds 	return status;
63301da177e4SLinus Torvalds }
63311da177e4SLinus Torvalds 
63321da177e4SLinus Torvalds /*
63331da177e4SLinus Torvalds  * Decode REMOVE response
63341da177e4SLinus Torvalds  */
6335bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6336fc016483SChristoph Hellwig 			       void *data)
63371da177e4SLinus Torvalds {
6338fc016483SChristoph Hellwig 	struct nfs_removeres *res = data;
63391da177e4SLinus Torvalds 	struct compound_hdr hdr;
63401da177e4SLinus Torvalds 	int status;
63411da177e4SLinus Torvalds 
6342bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63439b7b9fccSAndy Adamson 	if (status)
63449b7b9fccSAndy Adamson 		goto out;
6345bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63469b7b9fccSAndy Adamson 	if (status)
63471da177e4SLinus Torvalds 		goto out;
6348bf269551SChuck Lever 	status = decode_putfh(xdr);
6349bf269551SChuck Lever 	if (status)
635016e42959STrond Myklebust 		goto out;
6351bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
63521da177e4SLinus Torvalds out:
63531da177e4SLinus Torvalds 	return status;
63541da177e4SLinus Torvalds }
63551da177e4SLinus Torvalds 
63561da177e4SLinus Torvalds /*
63571da177e4SLinus Torvalds  * Decode RENAME response
63581da177e4SLinus Torvalds  */
6359bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6360fc016483SChristoph Hellwig 			       void *data)
63611da177e4SLinus Torvalds {
6362fc016483SChristoph Hellwig 	struct nfs_renameres *res = data;
63631da177e4SLinus Torvalds 	struct compound_hdr hdr;
63641da177e4SLinus Torvalds 	int status;
63651da177e4SLinus Torvalds 
6366bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63679b7b9fccSAndy Adamson 	if (status)
63689b7b9fccSAndy Adamson 		goto out;
6369bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63709b7b9fccSAndy Adamson 	if (status)
63711da177e4SLinus Torvalds 		goto out;
6372bf269551SChuck Lever 	status = decode_putfh(xdr);
6373bf269551SChuck Lever 	if (status)
63741da177e4SLinus Torvalds 		goto out;
6375bf269551SChuck Lever 	status = decode_savefh(xdr);
6376bf269551SChuck Lever 	if (status)
63771da177e4SLinus Torvalds 		goto out;
6378bf269551SChuck Lever 	status = decode_putfh(xdr);
6379bf269551SChuck Lever 	if (status)
63801da177e4SLinus Torvalds 		goto out;
6381bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
63821da177e4SLinus Torvalds out:
63831da177e4SLinus Torvalds 	return status;
63841da177e4SLinus Torvalds }
63851da177e4SLinus Torvalds 
63861da177e4SLinus Torvalds /*
63871da177e4SLinus Torvalds  * Decode LINK response
63881da177e4SLinus Torvalds  */
6389bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6390fc016483SChristoph Hellwig 			     void *data)
63911da177e4SLinus Torvalds {
6392fc016483SChristoph Hellwig 	struct nfs4_link_res *res = data;
63931da177e4SLinus Torvalds 	struct compound_hdr hdr;
63941da177e4SLinus Torvalds 	int status;
63951da177e4SLinus Torvalds 
6396bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63979b7b9fccSAndy Adamson 	if (status)
63989b7b9fccSAndy Adamson 		goto out;
6399bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64009b7b9fccSAndy Adamson 	if (status)
64011da177e4SLinus Torvalds 		goto out;
6402bf269551SChuck Lever 	status = decode_putfh(xdr);
6403bf269551SChuck Lever 	if (status)
64041da177e4SLinus Torvalds 		goto out;
6405bf269551SChuck Lever 	status = decode_savefh(xdr);
6406bf269551SChuck Lever 	if (status)
64071da177e4SLinus Torvalds 		goto out;
6408bf269551SChuck Lever 	status = decode_putfh(xdr);
6409bf269551SChuck Lever 	if (status)
64101da177e4SLinus Torvalds 		goto out;
6411bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
6412bf269551SChuck Lever 	if (status)
641391ba2eeeSTrond Myklebust 		goto out;
641491ba2eeeSTrond Myklebust 	/*
641591ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
641691ba2eeeSTrond Myklebust 	 *             filehandle.
641791ba2eeeSTrond Myklebust 	 */
6418bf269551SChuck Lever 	status = decode_restorefh(xdr);
6419bf269551SChuck Lever 	if (status)
642091ba2eeeSTrond Myklebust 		goto out;
6421aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
64221da177e4SLinus Torvalds out:
64231da177e4SLinus Torvalds 	return status;
64241da177e4SLinus Torvalds }
64251da177e4SLinus Torvalds 
64261da177e4SLinus Torvalds /*
64271da177e4SLinus Torvalds  * Decode CREATE response
64281da177e4SLinus Torvalds  */
6429bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6430fc016483SChristoph Hellwig 			       void *data)
64311da177e4SLinus Torvalds {
6432fc016483SChristoph Hellwig 	struct nfs4_create_res *res = data;
64331da177e4SLinus Torvalds 	struct compound_hdr hdr;
64341da177e4SLinus Torvalds 	int status;
64351da177e4SLinus Torvalds 
6436bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64379b7b9fccSAndy Adamson 	if (status)
64389b7b9fccSAndy Adamson 		goto out;
6439bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64409b7b9fccSAndy Adamson 	if (status)
64411da177e4SLinus Torvalds 		goto out;
6442bf269551SChuck Lever 	status = decode_putfh(xdr);
6443bf269551SChuck Lever 	if (status)
64441da177e4SLinus Torvalds 		goto out;
6445bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6446bf269551SChuck Lever 	if (status)
64471da177e4SLinus Torvalds 		goto out;
6448bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6449bf269551SChuck Lever 	if (status)
64501da177e4SLinus Torvalds 		goto out;
6451aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
64521da177e4SLinus Torvalds out:
64531da177e4SLinus Torvalds 	return status;
64541da177e4SLinus Torvalds }
64551da177e4SLinus Torvalds 
64561da177e4SLinus Torvalds /*
64571da177e4SLinus Torvalds  * Decode SYMLINK response
64581da177e4SLinus Torvalds  */
6459bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6460fc016483SChristoph Hellwig 				void *res)
64611da177e4SLinus Torvalds {
6462bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
64631da177e4SLinus Torvalds }
64641da177e4SLinus Torvalds 
64651da177e4SLinus Torvalds /*
64661da177e4SLinus Torvalds  * Decode GETATTR response
64671da177e4SLinus Torvalds  */
6468bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6469fc016483SChristoph Hellwig 				void *data)
64701da177e4SLinus Torvalds {
6471fc016483SChristoph Hellwig 	struct nfs4_getattr_res *res = data;
64721da177e4SLinus Torvalds 	struct compound_hdr hdr;
64731da177e4SLinus Torvalds 	int status;
64741da177e4SLinus Torvalds 
6475bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64761da177e4SLinus Torvalds 	if (status)
64771da177e4SLinus Torvalds 		goto out;
6478bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64799b7b9fccSAndy Adamson 	if (status)
64809b7b9fccSAndy Adamson 		goto out;
6481bf269551SChuck Lever 	status = decode_putfh(xdr);
64821da177e4SLinus Torvalds 	if (status)
64831da177e4SLinus Torvalds 		goto out;
6484aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
64851da177e4SLinus Torvalds out:
64861da177e4SLinus Torvalds 	return status;
64871da177e4SLinus Torvalds }
64881da177e4SLinus Torvalds 
648923ec6965SJ. Bruce Fields /*
649023ec6965SJ. Bruce Fields  * Encode an SETACL request
649123ec6965SJ. Bruce Fields  */
64929f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6493fcc85819SChristoph Hellwig 				const void *data)
649423ec6965SJ. Bruce Fields {
6495fcc85819SChristoph Hellwig 	const struct nfs_setaclargs *args = data;
649623ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
649766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
649823ec6965SJ. Bruce Fields 	};
649923ec6965SJ. Bruce Fields 
65009f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
65019f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
65029f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
65039f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6504d017931cSAndy Adamson 	encode_nops(&hdr);
650523ec6965SJ. Bruce Fields }
650605d564feSAndy Adamson 
650723ec6965SJ. Bruce Fields /*
650823ec6965SJ. Bruce Fields  * Decode SETACL response
650923ec6965SJ. Bruce Fields  */
651023ec6965SJ. Bruce Fields static int
6511bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6512fc016483SChristoph Hellwig 		    void *data)
651323ec6965SJ. Bruce Fields {
6514fc016483SChristoph Hellwig 	struct nfs_setaclres *res = data;
651523ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
651623ec6965SJ. Bruce Fields 	int status;
651723ec6965SJ. Bruce Fields 
6518bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
651923ec6965SJ. Bruce Fields 	if (status)
652023ec6965SJ. Bruce Fields 		goto out;
6521bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65229b7b9fccSAndy Adamson 	if (status)
65239b7b9fccSAndy Adamson 		goto out;
6524bf269551SChuck Lever 	status = decode_putfh(xdr);
652523ec6965SJ. Bruce Fields 	if (status)
652623ec6965SJ. Bruce Fields 		goto out;
6527bf269551SChuck Lever 	status = decode_setattr(xdr);
652823ec6965SJ. Bruce Fields out:
652923ec6965SJ. Bruce Fields 	return status;
653023ec6965SJ. Bruce Fields }
65311da177e4SLinus Torvalds 
65321da177e4SLinus Torvalds /*
6533029d105eSJ. Bruce Fields  * Decode GETACL response
6534029d105eSJ. Bruce Fields  */
6535029d105eSJ. Bruce Fields static int
6536bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6537fc016483SChristoph Hellwig 		    void *data)
6538029d105eSJ. Bruce Fields {
6539fc016483SChristoph Hellwig 	struct nfs_getaclres *res = data;
6540029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6541029d105eSJ. Bruce Fields 	int status;
6542029d105eSJ. Bruce Fields 
6543331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6544331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6545331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6546331818f1STrond Myklebust 	}
6547bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6548029d105eSJ. Bruce Fields 	if (status)
6549029d105eSJ. Bruce Fields 		goto out;
6550bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65519b7b9fccSAndy Adamson 	if (status)
65529b7b9fccSAndy Adamson 		goto out;
6553bf269551SChuck Lever 	status = decode_putfh(xdr);
6554029d105eSJ. Bruce Fields 	if (status)
6555029d105eSJ. Bruce Fields 		goto out;
6556bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6557029d105eSJ. Bruce Fields 
6558029d105eSJ. Bruce Fields out:
6559029d105eSJ. Bruce Fields 	return status;
6560029d105eSJ. Bruce Fields }
6561029d105eSJ. Bruce Fields 
6562029d105eSJ. Bruce Fields /*
65631da177e4SLinus Torvalds  * Decode CLOSE response
65641da177e4SLinus Torvalds  */
6565bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6566fc016483SChristoph Hellwig 			      void *data)
65671da177e4SLinus Torvalds {
6568fc016483SChristoph Hellwig 	struct nfs_closeres *res = data;
65691da177e4SLinus Torvalds 	struct compound_hdr hdr;
65701da177e4SLinus Torvalds 	int status;
65711da177e4SLinus Torvalds 
6572bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65731da177e4SLinus Torvalds 	if (status)
65741da177e4SLinus Torvalds 		goto out;
6575bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65769b7b9fccSAndy Adamson 	if (status)
65779b7b9fccSAndy Adamson 		goto out;
6578bf269551SChuck Lever 	status = decode_putfh(xdr);
65791da177e4SLinus Torvalds 	if (status)
65801da177e4SLinus Torvalds 		goto out;
6581cf805165STrond Myklebust 	if (res->lr_res) {
6582cf805165STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6583cf805165STrond Myklebust 		res->lr_ret = status;
6584cf805165STrond Myklebust 		if (status)
6585cf805165STrond Myklebust 			goto out;
6586cf805165STrond Myklebust 	}
6587d8d84983STrond Myklebust 	if (res->fattr != NULL) {
6588d8d84983STrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
6589516a6af6STrond Myklebust 		if (status != 0)
6590516a6af6STrond Myklebust 			goto out;
6591d8d84983STrond Myklebust 	}
6592d8d84983STrond Myklebust 	status = decode_close(xdr, res);
65931da177e4SLinus Torvalds out:
65941da177e4SLinus Torvalds 	return status;
65951da177e4SLinus Torvalds }
65961da177e4SLinus Torvalds 
65971da177e4SLinus Torvalds /*
65981da177e4SLinus Torvalds  * Decode OPEN response
65991da177e4SLinus Torvalds  */
6600bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6601fc016483SChristoph Hellwig 			     void *data)
66021da177e4SLinus Torvalds {
6603fc016483SChristoph Hellwig 	struct nfs_openres *res = data;
66041da177e4SLinus Torvalds 	struct compound_hdr hdr;
66051da177e4SLinus Torvalds 	int status;
66061da177e4SLinus Torvalds 
6607bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66081da177e4SLinus Torvalds 	if (status)
66091da177e4SLinus Torvalds 		goto out;
6610bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66119b7b9fccSAndy Adamson 	if (status)
66129b7b9fccSAndy Adamson 		goto out;
6613bf269551SChuck Lever 	status = decode_putfh(xdr);
66141da177e4SLinus Torvalds 	if (status)
66151da177e4SLinus Torvalds 		goto out;
6616bf269551SChuck Lever 	status = decode_open(xdr, res);
66171da177e4SLinus Torvalds 	if (status)
66181da177e4SLinus Torvalds 		goto out;
661901913b49SWeston Andros Adamson 	status = decode_getfh(xdr, &res->fh);
662001913b49SWeston Andros Adamson 	if (status)
66211da177e4SLinus Torvalds 		goto out;
6622ae2bb032SWeston Andros Adamson 	if (res->access_request)
66236168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
6624aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
66251da177e4SLinus Torvalds out:
66261da177e4SLinus Torvalds 	return status;
66271da177e4SLinus Torvalds }
66281da177e4SLinus Torvalds 
66291da177e4SLinus Torvalds /*
66301da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
66311da177e4SLinus Torvalds  */
6632bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6633bf269551SChuck Lever 				     struct xdr_stream *xdr,
6634fc016483SChristoph Hellwig 				     void *data)
66351da177e4SLinus Torvalds {
6636fc016483SChristoph Hellwig 	struct nfs_open_confirmres *res = data;
66371da177e4SLinus Torvalds 	struct compound_hdr hdr;
66381da177e4SLinus Torvalds 	int status;
66391da177e4SLinus Torvalds 
6640bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66411da177e4SLinus Torvalds 	if (status)
66421da177e4SLinus Torvalds 		goto out;
6643bf269551SChuck Lever 	status = decode_putfh(xdr);
66441da177e4SLinus Torvalds 	if (status)
66451da177e4SLinus Torvalds 		goto out;
6646bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
66471da177e4SLinus Torvalds out:
66481da177e4SLinus Torvalds 	return status;
66491da177e4SLinus Torvalds }
66501da177e4SLinus Torvalds 
66511da177e4SLinus Torvalds /*
66521da177e4SLinus Torvalds  * Decode OPEN response
66531da177e4SLinus Torvalds  */
6654bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6655bf269551SChuck Lever 				    struct xdr_stream *xdr,
6656fc016483SChristoph Hellwig 				    void *data)
66571da177e4SLinus Torvalds {
6658fc016483SChristoph Hellwig 	struct nfs_openres *res = data;
66591da177e4SLinus Torvalds 	struct compound_hdr hdr;
66601da177e4SLinus Torvalds 	int status;
66611da177e4SLinus Torvalds 
6662bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66631da177e4SLinus Torvalds 	if (status)
66641da177e4SLinus Torvalds 		goto out;
6665bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66669b7b9fccSAndy Adamson 	if (status)
66679b7b9fccSAndy Adamson 		goto out;
6668bf269551SChuck Lever 	status = decode_putfh(xdr);
66691da177e4SLinus Torvalds 	if (status)
66701da177e4SLinus Torvalds 		goto out;
6671bf269551SChuck Lever 	status = decode_open(xdr, res);
6672864472e9STrond Myklebust 	if (status)
6673864472e9STrond Myklebust 		goto out;
6674ae2bb032SWeston Andros Adamson 	if (res->access_request)
66756168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
66766926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
66771da177e4SLinus Torvalds out:
66781da177e4SLinus Torvalds 	return status;
66791da177e4SLinus Torvalds }
66801da177e4SLinus Torvalds 
66811da177e4SLinus Torvalds /*
66821da177e4SLinus Torvalds  * Decode SETATTR response
66831da177e4SLinus Torvalds  */
6684bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6685bf269551SChuck Lever 				struct xdr_stream *xdr,
6686fc016483SChristoph Hellwig 				void *data)
66871da177e4SLinus Torvalds {
6688fc016483SChristoph Hellwig 	struct nfs_setattrres *res = data;
66891da177e4SLinus Torvalds 	struct compound_hdr hdr;
66901da177e4SLinus Torvalds 	int status;
66911da177e4SLinus Torvalds 
6692bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66931da177e4SLinus Torvalds 	if (status)
66941da177e4SLinus Torvalds 		goto out;
6695bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66969b7b9fccSAndy Adamson 	if (status)
66979b7b9fccSAndy Adamson 		goto out;
6698bf269551SChuck Lever 	status = decode_putfh(xdr);
66991da177e4SLinus Torvalds 	if (status)
67001da177e4SLinus Torvalds 		goto out;
6701bf269551SChuck Lever 	status = decode_setattr(xdr);
67021da177e4SLinus Torvalds 	if (status)
67031da177e4SLinus Torvalds 		goto out;
6704aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
67051da177e4SLinus Torvalds out:
67061da177e4SLinus Torvalds 	return status;
67071da177e4SLinus Torvalds }
67081da177e4SLinus Torvalds 
67091da177e4SLinus Torvalds /*
67101da177e4SLinus Torvalds  * Decode LOCK response
67111da177e4SLinus Torvalds  */
6712bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6713fc016483SChristoph Hellwig 			     void *data)
67141da177e4SLinus Torvalds {
6715fc016483SChristoph Hellwig 	struct nfs_lock_res *res = data;
67161da177e4SLinus Torvalds 	struct compound_hdr hdr;
67171da177e4SLinus Torvalds 	int status;
67181da177e4SLinus Torvalds 
6719bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67201da177e4SLinus Torvalds 	if (status)
67211da177e4SLinus Torvalds 		goto out;
6722bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67239b7b9fccSAndy Adamson 	if (status)
67249b7b9fccSAndy Adamson 		goto out;
6725bf269551SChuck Lever 	status = decode_putfh(xdr);
67261da177e4SLinus Torvalds 	if (status)
67271da177e4SLinus Torvalds 		goto out;
6728bf269551SChuck Lever 	status = decode_lock(xdr, res);
67291da177e4SLinus Torvalds out:
67301da177e4SLinus Torvalds 	return status;
67311da177e4SLinus Torvalds }
67321da177e4SLinus Torvalds 
67331da177e4SLinus Torvalds /*
67341da177e4SLinus Torvalds  * Decode LOCKT response
67351da177e4SLinus Torvalds  */
6736bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6737fc016483SChristoph Hellwig 			      void *data)
67381da177e4SLinus Torvalds {
6739fc016483SChristoph Hellwig 	struct nfs_lockt_res *res = data;
67401da177e4SLinus Torvalds 	struct compound_hdr hdr;
67411da177e4SLinus Torvalds 	int status;
67421da177e4SLinus Torvalds 
6743bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67441da177e4SLinus Torvalds 	if (status)
67451da177e4SLinus Torvalds 		goto out;
6746bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67479b7b9fccSAndy Adamson 	if (status)
67489b7b9fccSAndy Adamson 		goto out;
6749bf269551SChuck Lever 	status = decode_putfh(xdr);
67501da177e4SLinus Torvalds 	if (status)
67511da177e4SLinus Torvalds 		goto out;
6752bf269551SChuck Lever 	status = decode_lockt(xdr, res);
67531da177e4SLinus Torvalds out:
67541da177e4SLinus Torvalds 	return status;
67551da177e4SLinus Torvalds }
67561da177e4SLinus Torvalds 
67571da177e4SLinus Torvalds /*
67581da177e4SLinus Torvalds  * Decode LOCKU response
67591da177e4SLinus Torvalds  */
6760bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6761fc016483SChristoph Hellwig 			      void *data)
67621da177e4SLinus Torvalds {
6763fc016483SChristoph Hellwig 	struct nfs_locku_res *res = data;
67641da177e4SLinus Torvalds 	struct compound_hdr hdr;
67651da177e4SLinus Torvalds 	int status;
67661da177e4SLinus Torvalds 
6767bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67681da177e4SLinus Torvalds 	if (status)
67691da177e4SLinus Torvalds 		goto out;
6770bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67719b7b9fccSAndy Adamson 	if (status)
67729b7b9fccSAndy Adamson 		goto out;
6773bf269551SChuck Lever 	status = decode_putfh(xdr);
67741da177e4SLinus Torvalds 	if (status)
67751da177e4SLinus Torvalds 		goto out;
6776bf269551SChuck Lever 	status = decode_locku(xdr, res);
67771da177e4SLinus Torvalds out:
67781da177e4SLinus Torvalds 	return status;
67791da177e4SLinus Torvalds }
67801da177e4SLinus Torvalds 
6781bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6782bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6783d3c7b7ccSTrond Myklebust {
6784d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6785d3c7b7ccSTrond Myklebust 	int status;
6786d3c7b7ccSTrond Myklebust 
6787bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6788d3c7b7ccSTrond Myklebust 	if (!status)
6789bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6790d3c7b7ccSTrond Myklebust 	return status;
6791d3c7b7ccSTrond Myklebust }
6792d3c7b7ccSTrond Myklebust 
67931da177e4SLinus Torvalds /*
67941da177e4SLinus Torvalds  * Decode READLINK response
67951da177e4SLinus Torvalds  */
6796bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6797bf269551SChuck Lever 				 struct xdr_stream *xdr,
6798fc016483SChristoph Hellwig 				 void *data)
67991da177e4SLinus Torvalds {
6800fc016483SChristoph Hellwig 	struct nfs4_readlink_res *res = data;
68011da177e4SLinus Torvalds 	struct compound_hdr hdr;
68021da177e4SLinus Torvalds 	int status;
68031da177e4SLinus Torvalds 
6804bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68051da177e4SLinus Torvalds 	if (status)
68061da177e4SLinus Torvalds 		goto out;
6807bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68089b7b9fccSAndy Adamson 	if (status)
68099b7b9fccSAndy Adamson 		goto out;
6810bf269551SChuck Lever 	status = decode_putfh(xdr);
68111da177e4SLinus Torvalds 	if (status)
68121da177e4SLinus Torvalds 		goto out;
6813bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
68141da177e4SLinus Torvalds out:
68151da177e4SLinus Torvalds 	return status;
68161da177e4SLinus Torvalds }
68171da177e4SLinus Torvalds 
68181da177e4SLinus Torvalds /*
68191da177e4SLinus Torvalds  * Decode READDIR response
68201da177e4SLinus Torvalds  */
6821bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6822fc016483SChristoph Hellwig 				void *data)
68231da177e4SLinus Torvalds {
6824fc016483SChristoph Hellwig 	struct nfs4_readdir_res *res = data;
68251da177e4SLinus Torvalds 	struct compound_hdr hdr;
68261da177e4SLinus Torvalds 	int status;
68271da177e4SLinus Torvalds 
6828bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68291da177e4SLinus Torvalds 	if (status)
68301da177e4SLinus Torvalds 		goto out;
6831bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68329b7b9fccSAndy Adamson 	if (status)
68339b7b9fccSAndy Adamson 		goto out;
6834bf269551SChuck Lever 	status = decode_putfh(xdr);
68351da177e4SLinus Torvalds 	if (status)
68361da177e4SLinus Torvalds 		goto out;
6837bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
68381da177e4SLinus Torvalds out:
68391da177e4SLinus Torvalds 	return status;
68401da177e4SLinus Torvalds }
68411da177e4SLinus Torvalds 
68421da177e4SLinus Torvalds /*
68431da177e4SLinus Torvalds  * Decode Read response
68441da177e4SLinus Torvalds  */
6845bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6846fc016483SChristoph Hellwig 			     void *data)
68471da177e4SLinus Torvalds {
6848fc016483SChristoph Hellwig 	struct nfs_pgio_res *res = data;
68491da177e4SLinus Torvalds 	struct compound_hdr hdr;
68501da177e4SLinus Torvalds 	int status;
68511da177e4SLinus Torvalds 
6852bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6853aabff4ddSPeng Tao 	res->op_status = hdr.status;
68541da177e4SLinus Torvalds 	if (status)
68551da177e4SLinus Torvalds 		goto out;
6856bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68579b7b9fccSAndy Adamson 	if (status)
68589b7b9fccSAndy Adamson 		goto out;
6859bf269551SChuck Lever 	status = decode_putfh(xdr);
68601da177e4SLinus Torvalds 	if (status)
68611da177e4SLinus Torvalds 		goto out;
6862bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
68631da177e4SLinus Torvalds 	if (!status)
68641da177e4SLinus Torvalds 		status = res->count;
68651da177e4SLinus Torvalds out:
68661da177e4SLinus Torvalds 	return status;
68671da177e4SLinus Torvalds }
68681da177e4SLinus Torvalds 
68691da177e4SLinus Torvalds /*
68701da177e4SLinus Torvalds  * Decode WRITE response
68711da177e4SLinus Torvalds  */
6872bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6873fc016483SChristoph Hellwig 			      void *data)
68741da177e4SLinus Torvalds {
6875fc016483SChristoph Hellwig 	struct nfs_pgio_res *res = data;
68761da177e4SLinus Torvalds 	struct compound_hdr hdr;
68771da177e4SLinus Torvalds 	int status;
68781da177e4SLinus Torvalds 
6879bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6880aabff4ddSPeng Tao 	res->op_status = hdr.status;
68811da177e4SLinus Torvalds 	if (status)
68821da177e4SLinus Torvalds 		goto out;
6883bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68849b7b9fccSAndy Adamson 	if (status)
68859b7b9fccSAndy Adamson 		goto out;
6886bf269551SChuck Lever 	status = decode_putfh(xdr);
68871da177e4SLinus Torvalds 	if (status)
68881da177e4SLinus Torvalds 		goto out;
6889bf269551SChuck Lever 	status = decode_write(xdr, res);
68904f9838c7STrond Myklebust 	if (status)
68914f9838c7STrond Myklebust 		goto out;
68927ffd1064SFred Isaman 	if (res->fattr)
68936926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
68941da177e4SLinus Torvalds 	if (!status)
68951da177e4SLinus Torvalds 		status = res->count;
68961da177e4SLinus Torvalds out:
68971da177e4SLinus Torvalds 	return status;
68981da177e4SLinus Torvalds }
68991da177e4SLinus Torvalds 
69001da177e4SLinus Torvalds /*
69011da177e4SLinus Torvalds  * Decode COMMIT response
69021da177e4SLinus Torvalds  */
6903bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6904fc016483SChristoph Hellwig 			       void *data)
69051da177e4SLinus Torvalds {
6906fc016483SChristoph Hellwig 	struct nfs_commitres *res = data;
69071da177e4SLinus Torvalds 	struct compound_hdr hdr;
69081da177e4SLinus Torvalds 	int status;
69091da177e4SLinus Torvalds 
6910bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6911aabff4ddSPeng Tao 	res->op_status = hdr.status;
69121da177e4SLinus Torvalds 	if (status)
69131da177e4SLinus Torvalds 		goto out;
6914bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69159b7b9fccSAndy Adamson 	if (status)
69169b7b9fccSAndy Adamson 		goto out;
6917bf269551SChuck Lever 	status = decode_putfh(xdr);
69181da177e4SLinus Torvalds 	if (status)
69191da177e4SLinus Torvalds 		goto out;
6920bf269551SChuck Lever 	status = decode_commit(xdr, res);
69211da177e4SLinus Torvalds out:
69221da177e4SLinus Torvalds 	return status;
69231da177e4SLinus Torvalds }
69241da177e4SLinus Torvalds 
69251da177e4SLinus Torvalds /*
69268b173218SRicardo Labiaga  * Decode FSINFO response
69271da177e4SLinus Torvalds  */
6928bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6929fc016483SChristoph Hellwig 			       void *data)
69301da177e4SLinus Torvalds {
6931fc016483SChristoph Hellwig 	struct nfs4_fsinfo_res *res = data;
69321da177e4SLinus Torvalds 	struct compound_hdr hdr;
69331da177e4SLinus Torvalds 	int status;
69341da177e4SLinus Torvalds 
6935bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69361da177e4SLinus Torvalds 	if (!status)
6937bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
69389b7b9fccSAndy Adamson 	if (!status)
6939bf269551SChuck Lever 		status = decode_putfh(xdr);
69401da177e4SLinus Torvalds 	if (!status)
6941bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
69421da177e4SLinus Torvalds 	return status;
69431da177e4SLinus Torvalds }
69441da177e4SLinus Torvalds 
69451da177e4SLinus Torvalds /*
69468b173218SRicardo Labiaga  * Decode PATHCONF response
69471da177e4SLinus Torvalds  */
6948bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6949fc016483SChristoph Hellwig 				 void *data)
69501da177e4SLinus Torvalds {
6951fc016483SChristoph Hellwig 	struct nfs4_pathconf_res *res = data;
69521da177e4SLinus Torvalds 	struct compound_hdr hdr;
69531da177e4SLinus Torvalds 	int status;
69541da177e4SLinus Torvalds 
6955bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69561da177e4SLinus Torvalds 	if (!status)
6957bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
69589b7b9fccSAndy Adamson 	if (!status)
6959bf269551SChuck Lever 		status = decode_putfh(xdr);
69601da177e4SLinus Torvalds 	if (!status)
6961bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
69621da177e4SLinus Torvalds 	return status;
69631da177e4SLinus Torvalds }
69641da177e4SLinus Torvalds 
69651da177e4SLinus Torvalds /*
69668b173218SRicardo Labiaga  * Decode STATFS response
69671da177e4SLinus Torvalds  */
6968bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6969fc016483SChristoph Hellwig 			       void *data)
69701da177e4SLinus Torvalds {
6971fc016483SChristoph Hellwig 	struct nfs4_statfs_res *res = data;
69721da177e4SLinus Torvalds 	struct compound_hdr hdr;
69731da177e4SLinus Torvalds 	int status;
69741da177e4SLinus Torvalds 
6975bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69761da177e4SLinus Torvalds 	if (!status)
6977bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
69789b7b9fccSAndy Adamson 	if (!status)
6979bf269551SChuck Lever 		status = decode_putfh(xdr);
69801da177e4SLinus Torvalds 	if (!status)
6981bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
69821da177e4SLinus Torvalds 	return status;
69831da177e4SLinus Torvalds }
69841da177e4SLinus Torvalds 
69851da177e4SLinus Torvalds /*
69868b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
69871da177e4SLinus Torvalds  */
6988bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6989bf269551SChuck Lever 				    struct xdr_stream *xdr,
6990fc016483SChristoph Hellwig 				    void *data)
69911da177e4SLinus Torvalds {
6992fc016483SChristoph Hellwig 	struct nfs4_server_caps_res *res = data;
69931da177e4SLinus Torvalds 	struct compound_hdr hdr;
69941da177e4SLinus Torvalds 	int status;
69951da177e4SLinus Torvalds 
6996bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69979b7b9fccSAndy Adamson 	if (status)
69989b7b9fccSAndy Adamson 		goto out;
6999bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
70009b7b9fccSAndy Adamson 	if (status)
70011da177e4SLinus Torvalds 		goto out;
7002bf269551SChuck Lever 	status = decode_putfh(xdr);
7003bf269551SChuck Lever 	if (status)
70041da177e4SLinus Torvalds 		goto out;
7005bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
70061da177e4SLinus Torvalds out:
70071da177e4SLinus Torvalds 	return status;
70081da177e4SLinus Torvalds }
70091da177e4SLinus Torvalds 
70101da177e4SLinus Torvalds /*
70111da177e4SLinus Torvalds  * Decode RENEW response
70121da177e4SLinus Torvalds  */
7013bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
7014bf269551SChuck Lever 			      void *__unused)
70151da177e4SLinus Torvalds {
70161da177e4SLinus Torvalds 	struct compound_hdr hdr;
70171da177e4SLinus Torvalds 	int status;
70181da177e4SLinus Torvalds 
7019bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70201da177e4SLinus Torvalds 	if (!status)
7021bf269551SChuck Lever 		status = decode_renew(xdr);
70221da177e4SLinus Torvalds 	return status;
70231da177e4SLinus Torvalds }
70241da177e4SLinus Torvalds 
70251da177e4SLinus Torvalds /*
70268b173218SRicardo Labiaga  * Decode SETCLIENTID response
70271da177e4SLinus Torvalds  */
7028bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
7029bf269551SChuck Lever 				    struct xdr_stream *xdr,
7030fc016483SChristoph Hellwig 				    void *data)
70311da177e4SLinus Torvalds {
7032fc016483SChristoph Hellwig 	struct nfs4_setclientid_res *res = data;
70331da177e4SLinus Torvalds 	struct compound_hdr hdr;
70341da177e4SLinus Torvalds 	int status;
70351da177e4SLinus Torvalds 
7036bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70371da177e4SLinus Torvalds 	if (!status)
7038bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
70391da177e4SLinus Torvalds 	return status;
70401da177e4SLinus Torvalds }
70411da177e4SLinus Torvalds 
70421da177e4SLinus Torvalds /*
70438b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
70441da177e4SLinus Torvalds  */
7045bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
7046fc016483SChristoph Hellwig 					    struct xdr_stream *xdr,
7047fc016483SChristoph Hellwig 					    void *data)
70481da177e4SLinus Torvalds {
70491da177e4SLinus Torvalds 	struct compound_hdr hdr;
70501da177e4SLinus Torvalds 	int status;
70511da177e4SLinus Torvalds 
7052bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70531da177e4SLinus Torvalds 	if (!status)
7054bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
70551da177e4SLinus Torvalds 	return status;
70561da177e4SLinus Torvalds }
70571da177e4SLinus Torvalds 
70581da177e4SLinus Torvalds /*
70598b173218SRicardo Labiaga  * Decode DELEGRETURN response
70601da177e4SLinus Torvalds  */
7061bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7062bf269551SChuck Lever 				    struct xdr_stream *xdr,
7063fc016483SChristoph Hellwig 				    void *data)
70641da177e4SLinus Torvalds {
7065fc016483SChristoph Hellwig 	struct nfs4_delegreturnres *res = data;
70661da177e4SLinus Torvalds 	struct compound_hdr hdr;
70671da177e4SLinus Torvalds 	int status;
70681da177e4SLinus Torvalds 
7069bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70709b7b9fccSAndy Adamson 	if (status)
70719b7b9fccSAndy Adamson 		goto out;
7072bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
70739b7b9fccSAndy Adamson 	if (status)
7074fa178f29STrond Myklebust 		goto out;
7075bf269551SChuck Lever 	status = decode_putfh(xdr);
7076fa178f29STrond Myklebust 	if (status != 0)
7077fa178f29STrond Myklebust 		goto out;
7078586f1c39STrond Myklebust 	if (res->lr_res) {
7079586f1c39STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
7080586f1c39STrond Myklebust 		res->lr_ret = status;
7081586f1c39STrond Myklebust 		if (status)
7082586f1c39STrond Myklebust 			goto out;
7083586f1c39STrond Myklebust 	}
70848ac2b422STrond Myklebust 	if (res->fattr) {
7085e144cbccSTrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
7086556ae3bbSJeff Layton 		if (status != 0)
7087556ae3bbSJeff Layton 			goto out;
70888ac2b422STrond Myklebust 	}
7089e144cbccSTrond Myklebust 	status = decode_delegreturn(xdr);
7090fa178f29STrond Myklebust out:
70911da177e4SLinus Torvalds 	return status;
70921da177e4SLinus Torvalds }
70931da177e4SLinus Torvalds 
7094683b57b4STrond Myklebust /*
70958b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
7096683b57b4STrond Myklebust  */
7097bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7098bf269551SChuck Lever 				     struct xdr_stream *xdr,
7099fc016483SChristoph Hellwig 				     void *data)
7100683b57b4STrond Myklebust {
7101fc016483SChristoph Hellwig 	struct nfs4_fs_locations_res *res = data;
7102683b57b4STrond Myklebust 	struct compound_hdr hdr;
7103683b57b4STrond Myklebust 	int status;
7104683b57b4STrond Myklebust 
7105bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
71069b7b9fccSAndy Adamson 	if (status)
71079b7b9fccSAndy Adamson 		goto out;
7108bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
71099b7b9fccSAndy Adamson 	if (status)
7110683b57b4STrond Myklebust 		goto out;
7111bf269551SChuck Lever 	status = decode_putfh(xdr);
7112bf269551SChuck Lever 	if (status)
7113683b57b4STrond Myklebust 		goto out;
7114b03d735bSChuck Lever 	if (res->migration) {
7115b03d735bSChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
7116b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
7117b03d735bSChuck Lever 					&res->fs_locations->fattr,
7118b03d735bSChuck Lever 					 NULL, res->fs_locations,
7119b03d735bSChuck Lever 					 NULL, res->fs_locations->server);
7120b03d735bSChuck Lever 		if (status)
7121b03d735bSChuck Lever 			goto out;
7122b03d735bSChuck Lever 		if (res->renew)
7123b03d735bSChuck Lever 			status = decode_renew(xdr);
7124b03d735bSChuck Lever 	} else {
7125bf269551SChuck Lever 		status = decode_lookup(xdr);
7126bf269551SChuck Lever 		if (status)
7127683b57b4STrond Myklebust 			goto out;
7128bf269551SChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
7129b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
7130b03d735bSChuck Lever 					&res->fs_locations->fattr,
71318b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
7132aa9c2669SDavid Quigley 					 NULL, res->fs_locations->server);
7133b03d735bSChuck Lever 	}
7134683b57b4STrond Myklebust out:
7135683b57b4STrond Myklebust 	return status;
7136683b57b4STrond Myklebust }
7137683b57b4STrond Myklebust 
71385a5ea0d4SBryan Schumaker /*
71395a5ea0d4SBryan Schumaker  * Decode SECINFO response
71405a5ea0d4SBryan Schumaker  */
71415a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
71425a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
7143fc016483SChristoph Hellwig 				void *data)
71445a5ea0d4SBryan Schumaker {
7145fc016483SChristoph Hellwig 	struct nfs4_secinfo_res *res = data;
71465a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
71475a5ea0d4SBryan Schumaker 	int status;
71485a5ea0d4SBryan Schumaker 
71495a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
71505a5ea0d4SBryan Schumaker 	if (status)
71515a5ea0d4SBryan Schumaker 		goto out;
71525a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
71535a5ea0d4SBryan Schumaker 	if (status)
71545a5ea0d4SBryan Schumaker 		goto out;
71555a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
71565a5ea0d4SBryan Schumaker 	if (status)
71575a5ea0d4SBryan Schumaker 		goto out;
71585a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
71595a5ea0d4SBryan Schumaker out:
71605a5ea0d4SBryan Schumaker 	return status;
71615a5ea0d4SBryan Schumaker }
71625a5ea0d4SBryan Schumaker 
716344c99933SChuck Lever /*
716444c99933SChuck Lever  * Decode FSID_PRESENT response
716544c99933SChuck Lever  */
716644c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
716744c99933SChuck Lever 				     struct xdr_stream *xdr,
7168fc016483SChristoph Hellwig 				     void *data)
716944c99933SChuck Lever {
7170fc016483SChristoph Hellwig 	struct nfs4_fsid_present_res *res = data;
717144c99933SChuck Lever 	struct compound_hdr hdr;
717244c99933SChuck Lever 	int status;
717344c99933SChuck Lever 
717444c99933SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
717544c99933SChuck Lever 	if (status)
717644c99933SChuck Lever 		goto out;
717744c99933SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
717844c99933SChuck Lever 	if (status)
717944c99933SChuck Lever 		goto out;
718044c99933SChuck Lever 	status = decode_putfh(xdr);
718144c99933SChuck Lever 	if (status)
718244c99933SChuck Lever 		goto out;
718344c99933SChuck Lever 	status = decode_getfh(xdr, res->fh);
718444c99933SChuck Lever 	if (status)
718544c99933SChuck Lever 		goto out;
718644c99933SChuck Lever 	if (res->renew)
718744c99933SChuck Lever 		status = decode_renew(xdr);
718844c99933SChuck Lever out:
718944c99933SChuck Lever 	return status;
719044c99933SChuck Lever }
719144c99933SChuck Lever 
719299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
719399fe60d0SBenny Halevy /*
71947c44f1aeSWeston Andros Adamson  * Decode BIND_CONN_TO_SESSION response
71957c44f1aeSWeston Andros Adamson  */
71967c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
71977c44f1aeSWeston Andros Adamson 					struct xdr_stream *xdr,
71987c44f1aeSWeston Andros Adamson 					void *res)
71997c44f1aeSWeston Andros Adamson {
72007c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr;
72017c44f1aeSWeston Andros Adamson 	int status;
72027c44f1aeSWeston Andros Adamson 
72037c44f1aeSWeston Andros Adamson 	status = decode_compound_hdr(xdr, &hdr);
72047c44f1aeSWeston Andros Adamson 	if (!status)
72057c44f1aeSWeston Andros Adamson 		status = decode_bind_conn_to_session(xdr, res);
72067c44f1aeSWeston Andros Adamson 	return status;
72077c44f1aeSWeston Andros Adamson }
72087c44f1aeSWeston Andros Adamson 
72097c44f1aeSWeston Andros Adamson /*
72108b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
721199fe60d0SBenny Halevy  */
7212bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7213bf269551SChuck Lever 				    struct xdr_stream *xdr,
721499fe60d0SBenny Halevy 				    void *res)
721599fe60d0SBenny Halevy {
721699fe60d0SBenny Halevy 	struct compound_hdr hdr;
721799fe60d0SBenny Halevy 	int status;
721899fe60d0SBenny Halevy 
7219bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
722099fe60d0SBenny Halevy 	if (!status)
7221bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
722299fe60d0SBenny Halevy 	return status;
722399fe60d0SBenny Halevy }
72242050f0ccSAndy Adamson 
72252050f0ccSAndy Adamson /*
72268b173218SRicardo Labiaga  * Decode CREATE_SESSION response
7227fc931582SAndy Adamson  */
7228bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7229bf269551SChuck Lever 				       struct xdr_stream *xdr,
7230fc016483SChristoph Hellwig 				       void *res)
7231fc931582SAndy Adamson {
7232fc931582SAndy Adamson 	struct compound_hdr hdr;
7233fc931582SAndy Adamson 	int status;
7234fc931582SAndy Adamson 
7235bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7236fc931582SAndy Adamson 	if (!status)
7237bf269551SChuck Lever 		status = decode_create_session(xdr, res);
7238fc931582SAndy Adamson 	return status;
7239fc931582SAndy Adamson }
7240fc931582SAndy Adamson 
7241fc931582SAndy Adamson /*
72428b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
72430f3e66c6SAndy Adamson  */
7244bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7245bf269551SChuck Lever 					struct xdr_stream *xdr,
7246bf269551SChuck Lever 					void *res)
72470f3e66c6SAndy Adamson {
72480f3e66c6SAndy Adamson 	struct compound_hdr hdr;
72490f3e66c6SAndy Adamson 	int status;
72500f3e66c6SAndy Adamson 
7251bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
72520f3e66c6SAndy Adamson 	if (!status)
7253bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
72540f3e66c6SAndy Adamson 	return status;
72550f3e66c6SAndy Adamson }
72560f3e66c6SAndy Adamson 
72570f3e66c6SAndy Adamson /*
725866245539STrond Myklebust  * Decode DESTROY_CLIENTID response
725966245539STrond Myklebust  */
726066245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
726166245539STrond Myklebust 					struct xdr_stream *xdr,
726266245539STrond Myklebust 					void *res)
726366245539STrond Myklebust {
726466245539STrond Myklebust 	struct compound_hdr hdr;
726566245539STrond Myklebust 	int status;
726666245539STrond Myklebust 
726766245539STrond Myklebust 	status = decode_compound_hdr(xdr, &hdr);
726866245539STrond Myklebust 	if (!status)
726966245539STrond Myklebust 		status = decode_destroy_clientid(xdr, res);
727066245539STrond Myklebust 	return status;
727166245539STrond Myklebust }
727266245539STrond Myklebust 
727366245539STrond Myklebust /*
72748b173218SRicardo Labiaga  * Decode SEQUENCE response
7275fc01cea9SAndy Adamson  */
7276bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7277bf269551SChuck Lever 				 struct xdr_stream *xdr,
7278fc016483SChristoph Hellwig 				 void *res)
7279fc01cea9SAndy Adamson {
7280fc01cea9SAndy Adamson 	struct compound_hdr hdr;
7281fc01cea9SAndy Adamson 	int status;
7282fc01cea9SAndy Adamson 
7283bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7284fc01cea9SAndy Adamson 	if (!status)
7285bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
7286fc01cea9SAndy Adamson 	return status;
7287fc01cea9SAndy Adamson }
7288fc01cea9SAndy Adamson 
7289fc01cea9SAndy Adamson /*
72908b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
72912050f0ccSAndy Adamson  */
7292bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7293bf269551SChuck Lever 				       struct xdr_stream *xdr,
7294fc016483SChristoph Hellwig 				       void *data)
72952050f0ccSAndy Adamson {
7296fc016483SChristoph Hellwig 	struct nfs4_get_lease_time_res *res = data;
72972050f0ccSAndy Adamson 	struct compound_hdr hdr;
72982050f0ccSAndy Adamson 	int status;
72992050f0ccSAndy Adamson 
7300bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
73012050f0ccSAndy Adamson 	if (!status)
7302bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
73032050f0ccSAndy Adamson 	if (!status)
7304bf269551SChuck Lever 		status = decode_putrootfh(xdr);
73052050f0ccSAndy Adamson 	if (!status)
7306bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
73072050f0ccSAndy Adamson 	return status;
73082050f0ccSAndy Adamson }
730918019753SRicardo Labiaga 
731018019753SRicardo Labiaga /*
731118019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
731218019753SRicardo Labiaga  */
7313bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7314bf269551SChuck Lever 					 struct xdr_stream *xdr,
7315fc016483SChristoph Hellwig 					 void *data)
731618019753SRicardo Labiaga {
7317fc016483SChristoph Hellwig 	struct nfs41_reclaim_complete_res *res = data;
731818019753SRicardo Labiaga 	struct compound_hdr hdr;
731918019753SRicardo Labiaga 	int status;
732018019753SRicardo Labiaga 
7321bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
732218019753SRicardo Labiaga 	if (!status)
7323bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
732418019753SRicardo Labiaga 	if (!status)
73258ee2b78aSHimangi Saraogi 		status = decode_reclaim_complete(xdr, NULL);
732618019753SRicardo Labiaga 	return status;
732718019753SRicardo Labiaga }
7328b1f69b75SAndy Adamson 
7329b1f69b75SAndy Adamson /*
7330b1f69b75SAndy Adamson  * Decode GETDEVINFO response
7331b1f69b75SAndy Adamson  */
7332bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7333bf269551SChuck Lever 				      struct xdr_stream *xdr,
7334fc016483SChristoph Hellwig 				      void *data)
7335b1f69b75SAndy Adamson {
7336fc016483SChristoph Hellwig 	struct nfs4_getdeviceinfo_res *res = data;
7337b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7338b1f69b75SAndy Adamson 	int status;
7339b1f69b75SAndy Adamson 
7340bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7341b1f69b75SAndy Adamson 	if (status != 0)
7342b1f69b75SAndy Adamson 		goto out;
7343bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7344b1f69b75SAndy Adamson 	if (status != 0)
7345b1f69b75SAndy Adamson 		goto out;
73464e590803STrond Myklebust 	status = decode_getdeviceinfo(xdr, res);
7347b1f69b75SAndy Adamson out:
7348b1f69b75SAndy Adamson 	return status;
7349b1f69b75SAndy Adamson }
7350b1f69b75SAndy Adamson 
7351b1f69b75SAndy Adamson /*
7352b1f69b75SAndy Adamson  * Decode LAYOUTGET response
7353b1f69b75SAndy Adamson  */
7354bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7355bf269551SChuck Lever 				  struct xdr_stream *xdr,
7356fc016483SChristoph Hellwig 				  void *data)
7357b1f69b75SAndy Adamson {
7358fc016483SChristoph Hellwig 	struct nfs4_layoutget_res *res = data;
7359b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7360b1f69b75SAndy Adamson 	int status;
7361b1f69b75SAndy Adamson 
7362bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7363b1f69b75SAndy Adamson 	if (status)
7364b1f69b75SAndy Adamson 		goto out;
7365bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7366b1f69b75SAndy Adamson 	if (status)
7367b1f69b75SAndy Adamson 		goto out;
7368bf269551SChuck Lever 	status = decode_putfh(xdr);
7369b1f69b75SAndy Adamson 	if (status)
7370b1f69b75SAndy Adamson 		goto out;
7371bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
7372b1f69b75SAndy Adamson out:
7373b1f69b75SAndy Adamson 	return status;
7374b1f69b75SAndy Adamson }
7375863a3c6cSAndy Adamson 
7376863a3c6cSAndy Adamson /*
7377cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
7378cbe82603SBenny Halevy  */
7379cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7380cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
7381fc016483SChristoph Hellwig 				     void *data)
7382cbe82603SBenny Halevy {
7383fc016483SChristoph Hellwig 	struct nfs4_layoutreturn_res *res = data;
7384cbe82603SBenny Halevy 	struct compound_hdr hdr;
7385cbe82603SBenny Halevy 	int status;
7386cbe82603SBenny Halevy 
7387cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
7388cbe82603SBenny Halevy 	if (status)
7389cbe82603SBenny Halevy 		goto out;
7390cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7391cbe82603SBenny Halevy 	if (status)
7392cbe82603SBenny Halevy 		goto out;
7393cbe82603SBenny Halevy 	status = decode_putfh(xdr);
7394cbe82603SBenny Halevy 	if (status)
7395cbe82603SBenny Halevy 		goto out;
7396cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
7397cbe82603SBenny Halevy out:
7398cbe82603SBenny Halevy 	return status;
7399cbe82603SBenny Halevy }
7400cbe82603SBenny Halevy 
7401cbe82603SBenny Halevy /*
7402863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
7403863a3c6cSAndy Adamson  */
7404863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7405863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
7406fc016483SChristoph Hellwig 				     void *data)
7407863a3c6cSAndy Adamson {
7408fc016483SChristoph Hellwig 	struct nfs4_layoutcommit_res *res = data;
7409863a3c6cSAndy Adamson 	struct compound_hdr hdr;
7410863a3c6cSAndy Adamson 	int status;
7411863a3c6cSAndy Adamson 
7412863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
7413863a3c6cSAndy Adamson 	if (status)
7414863a3c6cSAndy Adamson 		goto out;
7415863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7416863a3c6cSAndy Adamson 	if (status)
7417863a3c6cSAndy Adamson 		goto out;
7418863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
7419863a3c6cSAndy Adamson 	if (status)
7420863a3c6cSAndy Adamson 		goto out;
7421863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
7422863a3c6cSAndy Adamson 	if (status)
7423863a3c6cSAndy Adamson 		goto out;
74246926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
7425863a3c6cSAndy Adamson out:
7426863a3c6cSAndy Adamson 	return status;
7427863a3c6cSAndy Adamson }
7428fca78d6dSBryan Schumaker 
7429fca78d6dSBryan Schumaker /*
7430fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
7431fca78d6dSBryan Schumaker  */
7432fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7433fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
7434fc016483SChristoph Hellwig 					void *data)
7435fca78d6dSBryan Schumaker {
7436fc016483SChristoph Hellwig 	struct nfs4_secinfo_res *res = data;
7437fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
7438fca78d6dSBryan Schumaker 	int status;
7439fca78d6dSBryan Schumaker 
7440fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
7441fca78d6dSBryan Schumaker 	if (status)
7442fca78d6dSBryan Schumaker 		goto out;
7443fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7444fca78d6dSBryan Schumaker 	if (status)
7445fca78d6dSBryan Schumaker 		goto out;
7446fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
7447fca78d6dSBryan Schumaker 	if (status)
7448fca78d6dSBryan Schumaker 		goto out;
744931e4dda4SBryan Schumaker 	status = decode_secinfo_no_name(xdr, res);
7450fca78d6dSBryan Schumaker out:
7451fca78d6dSBryan Schumaker 	return status;
7452fca78d6dSBryan Schumaker }
74537d974794SBryan Schumaker 
74547d974794SBryan Schumaker /*
74557d974794SBryan Schumaker  * Decode TEST_STATEID response
74567d974794SBryan Schumaker  */
74577d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
74587d974794SBryan Schumaker 				     struct xdr_stream *xdr,
7459fc016483SChristoph Hellwig 				     void *data)
74607d974794SBryan Schumaker {
7461fc016483SChristoph Hellwig 	struct nfs41_test_stateid_res *res = data;
74627d974794SBryan Schumaker 	struct compound_hdr hdr;
74637d974794SBryan Schumaker 	int status;
74647d974794SBryan Schumaker 
74657d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
74667d974794SBryan Schumaker 	if (status)
74677d974794SBryan Schumaker 		goto out;
74687d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
74697d974794SBryan Schumaker 	if (status)
74707d974794SBryan Schumaker 		goto out;
74717d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
74727d974794SBryan Schumaker out:
74737d974794SBryan Schumaker 	return status;
74747d974794SBryan Schumaker }
74759aeda35fSBryan Schumaker 
74769aeda35fSBryan Schumaker /*
74779aeda35fSBryan Schumaker  * Decode FREE_STATEID response
74789aeda35fSBryan Schumaker  */
74799aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
74809aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
7481fc016483SChristoph Hellwig 				     void *data)
74829aeda35fSBryan Schumaker {
7483fc016483SChristoph Hellwig 	struct nfs41_free_stateid_res *res = data;
74849aeda35fSBryan Schumaker 	struct compound_hdr hdr;
74859aeda35fSBryan Schumaker 	int status;
74869aeda35fSBryan Schumaker 
74879aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
74889aeda35fSBryan Schumaker 	if (status)
74899aeda35fSBryan Schumaker 		goto out;
74909aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
74919aeda35fSBryan Schumaker 	if (status)
74929aeda35fSBryan Schumaker 		goto out;
74939aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
74949aeda35fSBryan Schumaker out:
74959aeda35fSBryan Schumaker 	return status;
74969aeda35fSBryan Schumaker }
749799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
749899fe60d0SBenny Halevy 
7499573c4e1eSChuck Lever /**
7500573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7501573c4e1eSChuck Lever  *                      the local page cache.
7502573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7503573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7504573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7505573c4e1eSChuck Lever  *
7506573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7507573c4e1eSChuck Lever  * returned.
7508573c4e1eSChuck Lever  *
7509573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7510573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7511573c4e1eSChuck Lever  * on a directory already in our cache.
7512573c4e1eSChuck Lever  */
7513573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7514a7a3b1e9SBenjamin Coddington 		       bool plus)
75151da177e4SLinus Torvalds {
7516256e48bbSTrond Myklebust 	unsigned int savep;
7517dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
75181da177e4SLinus Torvalds 	uint32_t len;
7519babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7520babddc72SBryan Schumaker 	if (unlikely(!p))
7521babddc72SBryan Schumaker 		goto out_overflow;
7522c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7523babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7524babddc72SBryan Schumaker 		if (unlikely(!p))
7525babddc72SBryan Schumaker 			goto out_overflow;
7526c08e76d0SChuck Lever 		if (*p == xdr_zero)
7527573c4e1eSChuck Lever 			return -EAGAIN;
75281da177e4SLinus Torvalds 		entry->eof = 1;
7529573c4e1eSChuck Lever 		return -EBADCOOKIE;
75301da177e4SLinus Torvalds 	}
75311da177e4SLinus Torvalds 
7532babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7533babddc72SBryan Schumaker 	if (unlikely(!p))
7534babddc72SBryan Schumaker 		goto out_overflow;
75351da177e4SLinus Torvalds 	entry->prev_cookie = entry->cookie;
75361da177e4SLinus Torvalds 	p = xdr_decode_hyper(p, &entry->cookie);
7537c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7538babddc72SBryan Schumaker 
75399af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7540babddc72SBryan Schumaker 	if (unlikely(!p))
7541babddc72SBryan Schumaker 		goto out_overflow;
75421da177e4SLinus Torvalds 	entry->name = (const char *) p;
75431da177e4SLinus Torvalds 
75441da177e4SLinus Torvalds 	/*
75451da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
75461da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
75471da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
75481da177e4SLinus Torvalds 	 */
75491da177e4SLinus Torvalds 	entry->ino = 1;
75504f082222STrond Myklebust 	entry->fattr->valid = 0;
75511da177e4SLinus Torvalds 
75529af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7553babddc72SBryan Schumaker 		goto out_overflow;
75549af8c222STrond Myklebust 
7555256e48bbSTrond Myklebust 	if (decode_attr_length(xdr, &len, &savep) < 0)
7556babddc72SBryan Schumaker 		goto out_overflow;
75579af8c222STrond Myklebust 
7558573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7559aa9c2669SDavid Quigley 			NULL, entry->label, entry->server) < 0)
7560babddc72SBryan Schumaker 		goto out_overflow;
756128331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
756228331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
756328331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
756482f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
75659af8c222STrond Myklebust 
75660b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
75670b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
75680b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
75690b26a0bfSTrond Myklebust 
7570573c4e1eSChuck Lever 	return 0;
7571babddc72SBryan Schumaker 
7572babddc72SBryan Schumaker out_overflow:
7573babddc72SBryan Schumaker 	print_overflow_msg(__func__, xdr);
7574573c4e1eSChuck Lever 	return -EAGAIN;
75751da177e4SLinus Torvalds }
75761da177e4SLinus Torvalds 
75771da177e4SLinus Torvalds /*
75781da177e4SLinus Torvalds  * We need to translate between nfs status return values and
75791da177e4SLinus Torvalds  * the local errno values which may not be the same.
75801da177e4SLinus Torvalds  */
75811da177e4SLinus Torvalds static struct {
75821da177e4SLinus Torvalds 	int stat;
75831da177e4SLinus Torvalds 	int errno;
75841da177e4SLinus Torvalds } nfs_errtbl[] = {
75851da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7586856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7587856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7588856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7589856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7590856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7591856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7592856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7593856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7594856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7595856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7596856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7597856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7598856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7599856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7600856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7601856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7602856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7603856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7604856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7605856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7606856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7607856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7608fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7609856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7610856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7611856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7612856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7613856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7614856dff3dSBenny Halevy 	{ -1,			-EIO		}
76151da177e4SLinus Torvalds };
76161da177e4SLinus Torvalds 
76171da177e4SLinus Torvalds /*
76181da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
76191da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
76201da177e4SLinus Torvalds  */
76211da177e4SLinus Torvalds static int
76220a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
76231da177e4SLinus Torvalds {
76241da177e4SLinus Torvalds 	int i;
76251da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
76261da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
76271da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
76281da177e4SLinus Torvalds 	}
76291da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
76301da177e4SLinus Torvalds 		/* The server is looney tunes. */
7631fdcb4577STrond Myklebust 		return -EREMOTEIO;
76321da177e4SLinus Torvalds 	}
76331da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
76341da177e4SLinus Torvalds 	 * handle it.
76351da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
76361da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
76371da177e4SLinus Torvalds 	 */
7638856dff3dSBenny Halevy 	return -stat;
76391da177e4SLinus Torvalds }
76401da177e4SLinus Torvalds 
76411c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
76421c6dcbe5SAnna Schumaker #include "nfs42xdr.c"
76431c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
76441c6dcbe5SAnna Schumaker 
76451da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
76461da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
76471da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
7648fcc85819SChristoph Hellwig 	.p_encode = nfs4_xdr_##argtype,				\
7649fc016483SChristoph Hellwig 	.p_decode = nfs4_xdr_##restype,				\
76502bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
76512bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7652cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7653cc0175c1SChuck Lever 	.p_name   = #proc,					\
76541da177e4SLinus Torvalds }
76551da177e4SLinus Torvalds 
76567c61f0d3SAnna Schumaker #define STUB(proc)		\
76577c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = {	\
76587c61f0d3SAnna Schumaker 	.p_name = #proc,	\
76597c61f0d3SAnna Schumaker }
76607c61f0d3SAnna Schumaker 
76618634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1)
76628634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype)				\
76638634ef5eSTrond Myklebust 	PROC(proc, argtype, restype)
76648634ef5eSTrond Myklebust #else
76658634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype)				\
76668634ef5eSTrond Myklebust 	STUB(proc)
76678634ef5eSTrond Myklebust #endif
76688634ef5eSTrond Myklebust 
76698634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2)
76708634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype)				\
76718634ef5eSTrond Myklebust 	PROC(proc, argtype, restype)
76728634ef5eSTrond Myklebust #else
76738634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype)				\
76748634ef5eSTrond Myklebust 	STUB(proc)
76758634ef5eSTrond Myklebust #endif
76768634ef5eSTrond Myklebust 
7677511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = {
76781da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
76791da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
76801da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
76811da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
76821da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
76831da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
76841da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
76851da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
76861da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
76871da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
76881da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
76891da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
76901da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
76911da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
76921da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
76931da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
76941da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
76951da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
76961da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
76971da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
76981da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
76991da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
77001da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
77011da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
77021da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
77031da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
77041da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
77051da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
77061da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
77071da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
77081da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7709029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
771023ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7711683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7712d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
77135a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
771444c99933SChuck Lever 	PROC(FSID_PRESENT,	enc_fsid_present,	dec_fsid_present),
77158634ef5eSTrond Myklebust 	PROC41(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
77168634ef5eSTrond Myklebust 	PROC41(CREATE_SESSION,	enc_create_session,	dec_create_session),
77178634ef5eSTrond Myklebust 	PROC41(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
77188634ef5eSTrond Myklebust 	PROC41(SEQUENCE,	enc_sequence,		dec_sequence),
77198634ef5eSTrond Myklebust 	PROC41(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
77208634ef5eSTrond Myklebust 	PROC41(RECLAIM_COMPLETE,enc_reclaim_complete,	dec_reclaim_complete),
77218634ef5eSTrond Myklebust 	PROC41(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
77228634ef5eSTrond Myklebust 	PROC41(LAYOUTGET,	enc_layoutget,		dec_layoutget),
77238634ef5eSTrond Myklebust 	PROC41(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
77248634ef5eSTrond Myklebust 	PROC41(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
77258634ef5eSTrond Myklebust 	PROC41(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
77268634ef5eSTrond Myklebust 	PROC41(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
77278634ef5eSTrond Myklebust 	PROC41(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
77287c61f0d3SAnna Schumaker 	STUB(GETDEVICELIST),
77298634ef5eSTrond Myklebust 	PROC41(BIND_CONN_TO_SESSION,
7730ad24ecfbSTrond Myklebust 			enc_bind_conn_to_session, dec_bind_conn_to_session),
77318634ef5eSTrond Myklebust 	PROC41(DESTROY_CLIENTID,enc_destroy_clientid,	dec_destroy_clientid),
77328634ef5eSTrond Myklebust 	PROC42(SEEK,		enc_seek,		dec_seek),
77338634ef5eSTrond Myklebust 	PROC42(ALLOCATE,	enc_allocate,		dec_allocate),
77348634ef5eSTrond Myklebust 	PROC42(DEALLOCATE,	enc_deallocate,		dec_deallocate),
77358634ef5eSTrond Myklebust 	PROC42(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
77368634ef5eSTrond Myklebust 	PROC42(CLONE,		enc_clone,		dec_clone),
77378634ef5eSTrond Myklebust 	PROC42(COPY,		enc_copy,		dec_copy),
77388634ef5eSTrond Myklebust 	PROC(LOOKUPP,		enc_lookupp,		dec_lookupp),
77391da177e4SLinus Torvalds };
77401da177e4SLinus Torvalds 
7741c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
7742a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
77431da177e4SLinus Torvalds 	.number			= 4,
7744e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
7745c551858aSChristoph Hellwig 	.procs			= nfs4_procedures,
7746c551858aSChristoph Hellwig 	.counts			= nfs_version4_counts,
77471da177e4SLinus Torvalds };
77481da177e4SLinus Torvalds 
77491da177e4SLinus Torvalds /*
77501da177e4SLinus Torvalds  * Local variables:
77511da177e4SLinus Torvalds  *  c-basic-offset: 8
77521da177e4SLinus Torvalds  * End:
77531da177e4SLinus Torvalds  */
7754