xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision 2a369153)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  fs/nfs/nfs4xdr.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Client-side XDR for NFSv4.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  Copyright (c) 2002 The Regents of the University of Michigan.
71da177e4SLinus Torvalds  *  All rights reserved.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  *  Kendrick Smith <kmsmith@umich.edu>
101da177e4SLinus Torvalds  *  Andy Adamson   <andros@umich.edu>
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *  Redistribution and use in source and binary forms, with or without
131da177e4SLinus Torvalds  *  modification, are permitted provided that the following conditions
141da177e4SLinus Torvalds  *  are met:
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  *  1. Redistributions of source code must retain the above copyright
171da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer.
181da177e4SLinus Torvalds  *  2. Redistributions in binary form must reproduce the above copyright
191da177e4SLinus Torvalds  *     notice, this list of conditions and the following disclaimer in the
201da177e4SLinus Torvalds  *     documentation and/or other materials provided with the distribution.
211da177e4SLinus Torvalds  *  3. Neither the name of the University nor the names of its
221da177e4SLinus Torvalds  *     contributors may be used to endorse or promote products derived
231da177e4SLinus Torvalds  *     from this software without specific prior written permission.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
261da177e4SLinus Torvalds  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
271da177e4SLinus Torvalds  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
281da177e4SLinus Torvalds  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291da177e4SLinus Torvalds  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301da177e4SLinus Torvalds  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311da177e4SLinus Torvalds  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
321da177e4SLinus Torvalds  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
331da177e4SLinus Torvalds  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
341da177e4SLinus Torvalds  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
351da177e4SLinus Torvalds  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361da177e4SLinus Torvalds  */
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #include <linux/param.h>
391da177e4SLinus Torvalds #include <linux/time.h>
401da177e4SLinus Torvalds #include <linux/mm.h>
411da177e4SLinus Torvalds #include <linux/errno.h>
421da177e4SLinus Torvalds #include <linux/string.h>
431da177e4SLinus Torvalds #include <linux/in.h>
441da177e4SLinus Torvalds #include <linux/pagemap.h>
451da177e4SLinus Torvalds #include <linux/proc_fs.h>
461da177e4SLinus Torvalds #include <linux/kdev_t.h>
47db8ac8baSWeston Andros Adamson #include <linux/module.h>
48db8ac8baSWeston Andros Adamson #include <linux/utsname.h>
491da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h>
502449ea2eSAlexandros Batsakis #include <linux/sunrpc/msg_prot.h>
515a5ea0d4SBryan Schumaker #include <linux/sunrpc/gss_api.h>
521da177e4SLinus Torvalds #include <linux/nfs.h>
531da177e4SLinus Torvalds #include <linux/nfs4.h>
541da177e4SLinus Torvalds #include <linux/nfs_fs.h>
551da177e4SLinus Torvalds #include <linux/nfs_idmap.h>
56f092075dSChuck Lever 
574ce79717STrond Myklebust #include "nfs4_fs.h"
584882ef72SAlexandros Batsakis #include "internal.h"
59b1f69b75SAndy Adamson #include "pnfs.h"
60f092075dSChuck Lever #include "netns.h"
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_XDR
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
651da177e4SLinus Torvalds #define errno_NFSERR_IO		EIO
661da177e4SLinus Torvalds 
670a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
701da177e4SLinus Torvalds #ifdef DEBUG
711da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		20
721da177e4SLinus Torvalds #else
731da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		0
741da177e4SLinus Torvalds #endif
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds /* lock,open owner id:
779f958ab8STrond Myklebust  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
781da177e4SLinus Torvalds  */
7995b72eb0STrond Myklebust #define open_owner_id_maxsz	(1 + 2 + 1 + 1 + 2)
80d035c36cSTrond Myklebust #define lock_owner_id_maxsz	(1 + 1 + 4)
819104a55dSTrond Myklebust #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
821da177e4SLinus Torvalds #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
831da177e4SLinus Torvalds #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
841da177e4SLinus Torvalds #define op_encode_hdr_maxsz	(1)
851da177e4SLinus Torvalds #define op_decode_hdr_maxsz	(2)
869104a55dSTrond Myklebust #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
879104a55dSTrond Myklebust #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
889104a55dSTrond Myklebust #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
899104a55dSTrond Myklebust #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
901da177e4SLinus Torvalds #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
911da177e4SLinus Torvalds 				(NFS4_FHSIZE >> 2))
921da177e4SLinus Torvalds #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
931da177e4SLinus Torvalds #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
941da177e4SLinus Torvalds #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
951da177e4SLinus Torvalds #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
961da177e4SLinus Torvalds #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
971da177e4SLinus Torvalds 				((3+NFS4_FHSIZE) >> 2))
98e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
9996928206SJ. Bruce Fields #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1001da177e4SLinus Torvalds #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
1011da177e4SLinus Torvalds #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
102bd625ba8STrond Myklebust #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
103bd625ba8STrond Myklebust #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
10488034c3dSAndy Adamson /* We support only one layout type per file system */
10588034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
10696928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
10796928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
10888034c3dSAndy Adamson 				3 + 3 + 3 + nfs4_owner_maxsz + \
10988034c3dSAndy Adamson 				nfs4_group_maxsz + decode_mdsthreshold_maxsz))
11096928206SJ. Bruce Fields #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
11196928206SJ. Bruce Fields 				nfs4_fattr_value_maxsz)
11296928206SJ. Bruce Fields #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1139104a55dSTrond Myklebust #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
1149104a55dSTrond Myklebust 				 1 + 2 + 1 + \
1159104a55dSTrond Myklebust 				nfs4_owner_maxsz + \
1169104a55dSTrond Myklebust 				nfs4_group_maxsz + \
1179104a55dSTrond Myklebust 				4 + 4)
1181da177e4SLinus Torvalds #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
1191da177e4SLinus Torvalds #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
12056ae19f3STrond Myklebust #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
12156ae19f3STrond Myklebust #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
1222f42b5d0SFred Isaman #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
123dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
124dae100c2SFred Isaman  * layout types will be returned.
125dae100c2SFred Isaman  */
126dae100c2SFred Isaman #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
127dae100c2SFred Isaman 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1281da177e4SLinus Torvalds #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
1291da177e4SLinus Torvalds #define decode_renew_maxsz	(op_decode_hdr_maxsz)
1301da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1311da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
132cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
133cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
134cc38bac3SChuck Lever 				1 /* sc_prog */ + \
135cc38bac3SChuck Lever 				XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
136cc38bac3SChuck Lever 				XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
137cc38bac3SChuck Lever 				1) /* sc_cb_ident */
1381da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1391da177e4SLinus Torvalds 				(op_decode_hdr_maxsz + \
1401da177e4SLinus Torvalds 				2 + \
1411da177e4SLinus Torvalds 				1024) /* large value for CLID_INUSE */
1421da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1431da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
1441da177e4SLinus Torvalds 				3 + (NFS4_VERIFIER_SIZE >> 2))
1451da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1461da177e4SLinus Torvalds 				(op_decode_hdr_maxsz)
147e6889620STrond Myklebust #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
148e6889620STrond Myklebust #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
1492cebf828STrond Myklebust #define encode_share_access_maxsz \
1502cebf828STrond Myklebust 				(2)
1514882ef72SAlexandros Batsakis #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
1522cebf828STrond Myklebust #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
1532cebf828STrond Myklebust #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
1542cebf828STrond Myklebust #define encode_open_maxsz	(op_encode_hdr_maxsz + \
1552cebf828STrond Myklebust 				2 + encode_share_access_maxsz + 2 + \
1562cebf828STrond Myklebust 				open_owner_id_maxsz + \
1572cebf828STrond Myklebust 				encode_opentype_maxsz + \
1582cebf828STrond Myklebust 				encode_claim_null_maxsz)
1592cebf828STrond Myklebust #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
1609104a55dSTrond Myklebust #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
1612cebf828STrond Myklebust 				decode_ace_maxsz)
1622cebf828STrond Myklebust #define decode_change_info_maxsz	(5)
1632cebf828STrond Myklebust #define decode_open_maxsz	(op_decode_hdr_maxsz + \
1649104a55dSTrond Myklebust 				decode_stateid_maxsz + \
1652cebf828STrond Myklebust 				decode_change_info_maxsz + 1 + \
1662cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz + \
1672cebf828STrond Myklebust 				decode_delegation_maxsz)
1689104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
1699104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1709104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1)
1719104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
1729104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1739104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1749104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
1759104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1769104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1 + \
1779104a55dSTrond Myklebust 				 encode_share_access_maxsz)
1789104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
1799104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1809104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1819104a55dSTrond Myklebust #define encode_close_maxsz	(op_encode_hdr_maxsz + \
1829104a55dSTrond Myklebust 				 1 + encode_stateid_maxsz)
1839104a55dSTrond Myklebust #define decode_close_maxsz	(op_decode_hdr_maxsz + \
1849104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1859104a55dSTrond Myklebust #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
1869104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
1879104a55dSTrond Myklebust 				 encode_attrs_maxsz)
1889104a55dSTrond Myklebust #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
1899104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz)
1909104a55dSTrond Myklebust #define encode_read_maxsz	(op_encode_hdr_maxsz + \
1919104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
1929104a55dSTrond Myklebust #define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
1939104a55dSTrond Myklebust #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
1949104a55dSTrond Myklebust 				 2 + encode_verifier_maxsz + 5)
1959104a55dSTrond Myklebust #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
1969104a55dSTrond Myklebust 				 decode_verifier_maxsz)
1979104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
1989104a55dSTrond Myklebust #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
1999104a55dSTrond Myklebust #define encode_write_maxsz	(op_encode_hdr_maxsz + \
2009104a55dSTrond Myklebust 				 encode_stateid_maxsz + 4)
2019104a55dSTrond Myklebust #define decode_write_maxsz	(op_decode_hdr_maxsz + \
2029104a55dSTrond Myklebust 				 2 + decode_verifier_maxsz)
2039104a55dSTrond Myklebust #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
2049104a55dSTrond Myklebust #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
2059104a55dSTrond Myklebust 				 decode_verifier_maxsz)
2061da177e4SLinus Torvalds #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
2071da177e4SLinus Torvalds 				nfs4_name_maxsz)
2086ce18391SBenny Halevy #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
2096ce18391SBenny Halevy 				 decode_change_info_maxsz)
2101da177e4SLinus Torvalds #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
2111da177e4SLinus Torvalds 				2 * nfs4_name_maxsz)
2126ce18391SBenny Halevy #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
2136ce18391SBenny Halevy 				 decode_change_info_maxsz + \
2146ce18391SBenny Halevy 				 decode_change_info_maxsz)
2151da177e4SLinus Torvalds #define encode_link_maxsz	(op_encode_hdr_maxsz + \
2161da177e4SLinus Torvalds 				nfs4_name_maxsz)
2176ce18391SBenny Halevy #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
218daccbdedSTrond Myklebust #define encode_lockowner_maxsz	(7)
2199104a55dSTrond Myklebust #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
2209104a55dSTrond Myklebust 				 7 + \
221daccbdedSTrond Myklebust 				 1 + encode_stateid_maxsz + 1 + \
222daccbdedSTrond Myklebust 				 encode_lockowner_maxsz)
2239104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2249104a55dSTrond Myklebust 				(8 + decode_lockowner_maxsz)
2259104a55dSTrond Myklebust #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
2269104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
227daccbdedSTrond Myklebust #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
228daccbdedSTrond Myklebust 				encode_lockowner_maxsz)
2299104a55dSTrond Myklebust #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
2309104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
2319104a55dSTrond Myklebust #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
2329104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2339104a55dSTrond Myklebust 				 4)
2349104a55dSTrond Myklebust #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
2359104a55dSTrond Myklebust 				 decode_stateid_maxsz)
236d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
237d3c7b7ccSTrond Myklebust 				(op_encode_hdr_maxsz + \
238d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
239d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
240d3c7b7ccSTrond Myklebust 				(op_decode_hdr_maxsz)
2419104a55dSTrond Myklebust #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
2429104a55dSTrond Myklebust #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
2431da177e4SLinus Torvalds #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
2441da177e4SLinus Torvalds 				1 + nfs4_name_maxsz + \
24594a6d753SChuck Lever 				1 + \
24696928206SJ. Bruce Fields 				nfs4_fattr_maxsz)
2471da177e4SLinus Torvalds #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
2481da177e4SLinus Torvalds #define encode_create_maxsz	(op_encode_hdr_maxsz + \
2499104a55dSTrond Myklebust 				1 + 2 + nfs4_name_maxsz + \
2509104a55dSTrond Myklebust 				encode_attrs_maxsz)
2512cebf828STrond Myklebust #define decode_create_maxsz	(op_decode_hdr_maxsz + \
2522cebf828STrond Myklebust 				decode_change_info_maxsz + \
2532cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz)
2549104a55dSTrond Myklebust #define encode_statfs_maxsz	(encode_getattr_maxsz)
2559104a55dSTrond Myklebust #define decode_statfs_maxsz	(decode_getattr_maxsz)
2561da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2571da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2589104a55dSTrond Myklebust #define encode_getacl_maxsz	(encode_getattr_maxsz)
2599104a55dSTrond Myklebust #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
2609104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz + 1)
2619104a55dSTrond Myklebust #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
2629104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2639104a55dSTrond Myklebust #define decode_setacl_maxsz	(decode_setattr_maxsz)
264e6889620STrond Myklebust #define encode_fs_locations_maxsz \
265e6889620STrond Myklebust 				(encode_getattr_maxsz)
266e6889620STrond Myklebust #define decode_fs_locations_maxsz \
267e6889620STrond Myklebust 				(0)
2685a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
2691650add2SBryan Schumaker #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
2709b7b9fccSAndy Adamson 
2719b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
272fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
273fc931582SAndy Adamson 
27499fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
27599fe60d0SBenny Halevy 				encode_verifier_maxsz + \
27699fe60d0SBenny Halevy 				1 /* co_ownerid.len */ + \
27799fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
27899fe60d0SBenny Halevy 				1 /* flags */ + \
27999fe60d0SBenny Halevy 				1 /* spa_how */ + \
28099fe60d0SBenny Halevy 				0 /* SP4_NONE (for now) */ + \
281db8ac8baSWeston Andros Adamson 				1 /* implementation id array of size 1 */ + \
282db8ac8baSWeston Andros Adamson 				1 /* nii_domain */ + \
283db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
284db8ac8baSWeston Andros Adamson 				1 /* nii_name */ + \
285db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
286db8ac8baSWeston Andros Adamson 				3 /* nii_date */)
28799fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
28899fe60d0SBenny Halevy 				2 /* eir_clientid */ + \
28999fe60d0SBenny Halevy 				1 /* eir_sequenceid */ + \
29099fe60d0SBenny Halevy 				1 /* eir_flags */ + \
29199fe60d0SBenny Halevy 				1 /* spr_how */ + \
29299fe60d0SBenny Halevy 				0 /* SP4_NONE (for now) */ + \
29399fe60d0SBenny Halevy 				2 /* eir_server_owner.so_minor_id */ + \
29499fe60d0SBenny Halevy 				/* eir_server_owner.so_major_id<> */ \
29599fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
29699fe60d0SBenny Halevy 				/* eir_server_scope<> */ \
29799fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
29899fe60d0SBenny Halevy 				1 /* eir_server_impl_id array length */ + \
2997d2ed9acSWeston Andros Adamson 				1 /* nii_domain */ + \
3007d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3017d2ed9acSWeston Andros Adamson 				1 /* nii_name */ + \
3027d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3037d2ed9acSWeston Andros Adamson 				3 /* nii_date */)
304fc931582SAndy Adamson #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
305fc931582SAndy Adamson #define decode_channel_attrs_maxsz  (6 + \
306fc931582SAndy Adamson 				     1 /* ca_rdma_ird.len */ + \
307fc931582SAndy Adamson 				     1 /* ca_rdma_ird */)
308fc931582SAndy Adamson #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
309fc931582SAndy Adamson 				     2 /* csa_clientid */ + \
310fc931582SAndy Adamson 				     1 /* csa_sequence */ + \
311fc931582SAndy Adamson 				     1 /* csa_flags */ + \
312fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
313fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
314fc931582SAndy Adamson 				     1 /* csa_cb_program */ + \
315fc931582SAndy Adamson 				     1 /* csa_sec_parms.len (1) */ + \
316fc931582SAndy Adamson 				     1 /* cb_secflavor (AUTH_SYS) */ + \
317fc931582SAndy Adamson 				     1 /* stamp */ + \
318fc931582SAndy Adamson 				     1 /* machinename.len */ + \
319fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
320fc931582SAndy Adamson 				     1 /* uid */ + \
321fc931582SAndy Adamson 				     1 /* gid */ + \
322fc931582SAndy Adamson 				     1 /* gids.len (0) */)
323fc931582SAndy Adamson #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
324fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
325fc931582SAndy Adamson 				     1 /* csr_sequence */ + \
326fc931582SAndy Adamson 				     1 /* csr_flags */ + \
327fc931582SAndy Adamson 				     decode_channel_attrs_maxsz + \
328fc931582SAndy Adamson 				     decode_channel_attrs_maxsz)
3297c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
3307c44f1aeSWeston Andros Adamson 				     /* bctsa_sessid */ \
3317c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3327c44f1aeSWeston Andros Adamson 				     1 /* bctsa_dir */ + \
3337c44f1aeSWeston Andros Adamson 				     1 /* bctsa_use_conn_in_rdma_mode */)
3347c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +	\
3357c44f1aeSWeston Andros Adamson 				     /* bctsr_sessid */ \
3367c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3377c44f1aeSWeston Andros Adamson 				     1 /* bctsr_dir */ + \
3387c44f1aeSWeston Andros Adamson 				     1 /* bctsr_use_conn_in_rdma_mode */)
3390f3e66c6SAndy Adamson #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
3400f3e66c6SAndy Adamson #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
34166245539STrond Myklebust #define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
34266245539STrond Myklebust #define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
343fc01cea9SAndy Adamson #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
344fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
345fc01cea9SAndy Adamson #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
346fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
34718019753SRicardo Labiaga #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
34818019753SRicardo Labiaga #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
3497f11d8d3SAndy Adamson #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
3507f11d8d3SAndy Adamson 				encode_verifier_maxsz)
3517f11d8d3SAndy Adamson #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
3527f11d8d3SAndy Adamson 				2 /* nfs_cookie4 gdlr_cookie */ + \
3537f11d8d3SAndy Adamson 				decode_verifier_maxsz \
3547f11d8d3SAndy Adamson 				  /* verifier4 gdlr_verifier */ + \
3557f11d8d3SAndy Adamson 				1 /* gdlr_deviceid_list count */ + \
3567f11d8d3SAndy Adamson 				XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
3577f11d8d3SAndy Adamson 					    NFS4_DEVICEID4_SIZE) \
3587f11d8d3SAndy Adamson 				  /* gdlr_deviceid_list */ + \
3597f11d8d3SAndy Adamson 				1 /* bool gdlr_eof */)
360b1f69b75SAndy Adamson #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
361b1f69b75SAndy Adamson 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
362b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
363b1f69b75SAndy Adamson 				1 /* layout type */ + \
364b1f69b75SAndy Adamson 				1 /* opaque devaddr4 length */ + \
365b1f69b75SAndy Adamson 				  /* devaddr4 payload is read into page */ \
366b1f69b75SAndy Adamson 				1 /* notification bitmap length */ + \
367b1f69b75SAndy Adamson 				1 /* notification bitmap */)
368b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
369b1f69b75SAndy Adamson 				encode_stateid_maxsz)
370b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
371b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
372b1f69b75SAndy Adamson 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
373863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
374863a3c6cSAndy Adamson 				2 /* offset */ + \
375863a3c6cSAndy Adamson 				2 /* length */ + \
376863a3c6cSAndy Adamson 				1 /* reclaim */ + \
377863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
378863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
379863a3c6cSAndy Adamson 				2 /* last byte written */ + \
380863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
381863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
382863a3c6cSAndy Adamson 				1 /* NULL filelayout layoutupdate4 payload */)
383863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
384cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
385cbe82603SBenny Halevy 				encode_stateid_maxsz + \
386cbe82603SBenny Halevy 				1 /* FIXME: opaque lrf_body always empty at the moment */)
387cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
388cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
389fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
390fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
3917d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
3927d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
3937d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
3949aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
3959aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
3969aeda35fSBryan Schumaker #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz + 1)
3979b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
3989b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
3999b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
4009b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4019b7b9fccSAndy Adamson 
4021da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
4031da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
4041da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
4059b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4061da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4079104a55dSTrond Myklebust 				encode_read_maxsz)
4081da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
4099b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4101da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4119104a55dSTrond Myklebust 				decode_read_maxsz)
4121da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
4139b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4141da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4159104a55dSTrond Myklebust 				encode_readlink_maxsz)
4161da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4179b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4181da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4199104a55dSTrond Myklebust 				decode_readlink_maxsz)
4201da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4219b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4221da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4239104a55dSTrond Myklebust 				encode_readdir_maxsz)
4241da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4259b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4261da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4279104a55dSTrond Myklebust 				decode_readdir_maxsz)
4281da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4299b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4301da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4319104a55dSTrond Myklebust 				encode_write_maxsz + \
4324f9838c7STrond Myklebust 				encode_getattr_maxsz)
4331da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4349b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4351da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4369104a55dSTrond Myklebust 				decode_write_maxsz + \
4374f9838c7STrond Myklebust 				decode_getattr_maxsz)
4381da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4399b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4401da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4418582715eSTrond Myklebust 				encode_commit_maxsz)
4421da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4439b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4441da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4458582715eSTrond Myklebust 				decode_commit_maxsz)
4461da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4479b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4481da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4492cebf828STrond Myklebust 				encode_open_maxsz + \
4502cebf828STrond Myklebust 				encode_getfh_maxsz + \
4512cebf828STrond Myklebust 				encode_getattr_maxsz)
4521da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4539b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4541da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4552cebf828STrond Myklebust 				decode_open_maxsz + \
4562cebf828STrond Myklebust 				decode_getfh_maxsz + \
4572cebf828STrond Myklebust 				decode_getattr_maxsz)
4581da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
4591da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4601da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4619104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
4629104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
4639104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
4641da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4659104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
4661da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
4679b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
4681da177e4SLinus Torvalds 					encode_putfh_maxsz + \
4692cebf828STrond Myklebust 					encode_open_maxsz + \
4702cebf828STrond Myklebust 					encode_getattr_maxsz)
4711da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
4729b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
4731da177e4SLinus Torvalds 					decode_putfh_maxsz + \
4742cebf828STrond Myklebust 					decode_open_maxsz + \
4752cebf828STrond Myklebust 					decode_getattr_maxsz)
4761da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
4771da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4789b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
4791da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4809104a55dSTrond Myklebust 				 encode_open_downgrade_maxsz + \
481516a6af6STrond Myklebust 				 encode_getattr_maxsz)
4821da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
4831da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
4849b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
4851da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4869104a55dSTrond Myklebust 				 decode_open_downgrade_maxsz + \
487516a6af6STrond Myklebust 				 decode_getattr_maxsz)
4881da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
4899b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
4901da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4919104a55dSTrond Myklebust 				 encode_close_maxsz + \
492516a6af6STrond Myklebust 				 encode_getattr_maxsz)
4931da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
4949b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
4951da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4969104a55dSTrond Myklebust 				 decode_close_maxsz + \
497516a6af6STrond Myklebust 				 decode_getattr_maxsz)
4981da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
4999b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5001da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5019104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
5021da177e4SLinus Torvalds 				 encode_getattr_maxsz)
5031da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
5049b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5051da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5069104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
5079104a55dSTrond Myklebust 				 decode_getattr_maxsz)
5081da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5099b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5101da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5111da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5121da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5139b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5141da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5151da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5161da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5171da177e4SLinus Torvalds 				encode_renew_maxsz)
5181da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5191da177e4SLinus Torvalds 				decode_renew_maxsz)
5201da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5211da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5221da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5231da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5241da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5251da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5261da177e4SLinus Torvalds 				encode_setclientid_confirm_maxsz + \
5271da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
5281da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5291da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5301da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5311da177e4SLinus Torvalds 				decode_setclientid_confirm_maxsz + \
5321da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
5331da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5341da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5359b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5361da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5379104a55dSTrond Myklebust 				encode_lock_maxsz)
5381da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5399b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5401da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5419104a55dSTrond Myklebust 				decode_lock_maxsz)
5421da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5439b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5441da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5459104a55dSTrond Myklebust 				encode_lockt_maxsz)
5469104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5479b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5489104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5499104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5501da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5519b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5521da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5539104a55dSTrond Myklebust 				encode_locku_maxsz)
5541da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5559b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5561da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5579104a55dSTrond Myklebust 				decode_locku_maxsz)
558d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
559d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
560d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
561d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
562d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
563d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
5641da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
5659b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5661da177e4SLinus Torvalds 				encode_putfh_maxsz + \
56776b32999STrond Myklebust 				encode_access_maxsz + \
56876b32999STrond Myklebust 				encode_getattr_maxsz)
5691da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
5709b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5711da177e4SLinus Torvalds 				decode_putfh_maxsz + \
57276b32999STrond Myklebust 				decode_access_maxsz + \
57376b32999STrond Myklebust 				decode_getattr_maxsz)
5741da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
5759b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5761da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5771da177e4SLinus Torvalds 				encode_getattr_maxsz)
5781da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
5799b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5801da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5811da177e4SLinus Torvalds 				decode_getattr_maxsz)
5821da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
5839b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5841da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5851da177e4SLinus Torvalds 				encode_lookup_maxsz + \
5861da177e4SLinus Torvalds 				encode_getattr_maxsz + \
5871da177e4SLinus Torvalds 				encode_getfh_maxsz)
5881da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
5899b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5901da177e4SLinus Torvalds 				decode_putfh_maxsz + \
591e6889620STrond Myklebust 				decode_lookup_maxsz + \
5921da177e4SLinus Torvalds 				decode_getattr_maxsz + \
5931da177e4SLinus Torvalds 				decode_getfh_maxsz)
5941da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
5959b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5961da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
5971da177e4SLinus Torvalds 				encode_getattr_maxsz + \
5981da177e4SLinus Torvalds 				encode_getfh_maxsz)
5991da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6009b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6011da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
6021da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6031da177e4SLinus Torvalds 				decode_getfh_maxsz)
6041da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
6059b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6061da177e4SLinus Torvalds 				encode_putfh_maxsz + \
607778d2817STrond Myklebust 				encode_remove_maxsz)
6081da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6099b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6101da177e4SLinus Torvalds 				decode_putfh_maxsz + \
611778d2817STrond Myklebust 				decode_remove_maxsz)
6121da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6139b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6141da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6151da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6161da177e4SLinus Torvalds 				encode_putfh_maxsz + \
617778d2817STrond Myklebust 				encode_rename_maxsz)
6181da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6199b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6201da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6211da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6221da177e4SLinus Torvalds 				decode_putfh_maxsz + \
623778d2817STrond Myklebust 				decode_rename_maxsz)
6241da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6259b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6261da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6271da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6281da177e4SLinus Torvalds 				encode_putfh_maxsz + \
62991ba2eeeSTrond Myklebust 				encode_link_maxsz + \
63091ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
631a9f6991bSTrond Myklebust 				encode_getattr_maxsz)
6321da177e4SLinus Torvalds #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
6339b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6341da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6351da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6361da177e4SLinus Torvalds 				decode_putfh_maxsz + \
63791ba2eeeSTrond Myklebust 				decode_link_maxsz + \
63891ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
63991ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6401da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6419b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6421da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6431da177e4SLinus Torvalds 				encode_symlink_maxsz + \
6441da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6451da177e4SLinus Torvalds 				encode_getfh_maxsz)
6461da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
6479b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6481da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6491da177e4SLinus Torvalds 				decode_symlink_maxsz + \
6501da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6511da177e4SLinus Torvalds 				decode_getfh_maxsz)
6521da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
6539b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6541da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6551da177e4SLinus Torvalds 				encode_create_maxsz + \
65656ae19f3STrond Myklebust 				encode_getfh_maxsz + \
65756ae19f3STrond Myklebust 				encode_getattr_maxsz)
6581da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
6599b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6601da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6611da177e4SLinus Torvalds 				decode_create_maxsz + \
66256ae19f3STrond Myklebust 				decode_getfh_maxsz + \
66356ae19f3STrond Myklebust 				decode_getattr_maxsz)
6641da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
6659b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6661da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6671da177e4SLinus Torvalds 				encode_getattr_maxsz)
6681da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
6699b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6701da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6711da177e4SLinus Torvalds 				decode_getattr_maxsz)
6721da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
6739b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6741da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6759104a55dSTrond Myklebust 				encode_statfs_maxsz)
6761da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
6779b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6781da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6799104a55dSTrond Myklebust 				decode_statfs_maxsz)
6801da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
6819b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
682ab91f264STrond Myklebust 				encode_putfh_maxsz + \
6831da177e4SLinus Torvalds 				encode_getattr_maxsz)
6841da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
6859b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
686ab91f264STrond Myklebust 				decode_putfh_maxsz + \
6871da177e4SLinus Torvalds 				decode_getattr_maxsz)
6881da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
6899b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6901da177e4SLinus Torvalds 				encode_putfh_maxsz + \
691fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
692fa178f29STrond Myklebust 				encode_getattr_maxsz)
6931da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
6949b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
695fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
696fa178f29STrond Myklebust 				decode_getattr_maxsz)
697029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
6989b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
699029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7009104a55dSTrond Myklebust 				encode_getacl_maxsz)
701029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7029b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
703029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7049104a55dSTrond Myklebust 				decode_getacl_maxsz)
70523ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7069b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
70723ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7089104a55dSTrond Myklebust 				encode_setacl_maxsz)
70923ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7109b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
71123ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7129104a55dSTrond Myklebust 				decode_setacl_maxsz)
713683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
714683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7159b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
716683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
717e6889620STrond Myklebust 				 encode_lookup_maxsz + \
718e6889620STrond Myklebust 				 encode_fs_locations_maxsz)
719683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
720683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7219b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
722683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
723e6889620STrond Myklebust 				 decode_lookup_maxsz + \
724e6889620STrond Myklebust 				 decode_fs_locations_maxsz)
7255a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7265a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7275a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7285a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7295a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7305a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7315a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7325a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
73399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
7347c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
7357c44f1aeSWeston Andros Adamson 				(compound_encode_hdr_maxsz + \
7367c44f1aeSWeston Andros Adamson 				 encode_bind_conn_to_session_maxsz)
7377c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
7387c44f1aeSWeston Andros Adamson 				(compound_decode_hdr_maxsz + \
7397c44f1aeSWeston Andros Adamson 				 decode_bind_conn_to_session_maxsz)
74099fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
74199fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
74299fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
74399fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
74499fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
74599fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
746fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
747fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
748fc931582SAndy Adamson 				 encode_create_session_maxsz)
749fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
750fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
751fc931582SAndy Adamson 				 decode_create_session_maxsz)
7520f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
7530f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
7540f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
7550f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
75666245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
75766245539STrond Myklebust 					 encode_destroy_clientid_maxsz)
75866245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
75966245539STrond Myklebust 					 decode_destroy_clientid_maxsz)
760fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
761fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
762fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
763fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
764fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
765fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
7662050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
7672050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
7682050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
7692050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
7702050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
7712050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
7722050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
7732050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
77418019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
77518019753SRicardo Labiaga 					 encode_sequence_maxsz + \
77618019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
77718019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
77818019753SRicardo Labiaga 					 decode_sequence_maxsz + \
77918019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
7807f11d8d3SAndy Adamson #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
7817f11d8d3SAndy Adamson 				encode_sequence_maxsz + \
7827f11d8d3SAndy Adamson 				encode_putfh_maxsz + \
7837f11d8d3SAndy Adamson 				encode_getdevicelist_maxsz)
7847f11d8d3SAndy Adamson #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
7857f11d8d3SAndy Adamson 				decode_sequence_maxsz + \
7867f11d8d3SAndy Adamson 				decode_putfh_maxsz + \
7877f11d8d3SAndy Adamson 				decode_getdevicelist_maxsz)
788b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
789b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
790b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
791b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
792b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
793b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
794b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
795b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
796b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
797b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
798b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
799b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
800b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
801b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
802863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
803863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
804863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
805863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
806863a3c6cSAndy Adamson 				encode_getattr_maxsz)
807863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
808863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
809863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
810863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
811863a3c6cSAndy Adamson 				decode_getattr_maxsz)
812cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
813cbe82603SBenny Halevy 				encode_sequence_maxsz + \
814cbe82603SBenny Halevy 				encode_putfh_maxsz + \
815cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
816cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
817cbe82603SBenny Halevy 				decode_sequence_maxsz + \
818cbe82603SBenny Halevy 				decode_putfh_maxsz + \
819cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
820fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
821fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
822fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
823fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
824fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
825fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
826fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
827fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8287d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8297d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8307d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8317d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
8327d974794SBryan Schumaker 					 decode_sequence_maxsz + \
8337d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
8349aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
8359aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
8369aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
8379aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
8389aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
8399aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
8402449ea2eSAlexandros Batsakis 
8412449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8422449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
8432449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
8442449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
8452449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
8462449ea2eSAlexandros Batsakis 				     XDR_UNIT);
8472449ea2eSAlexandros Batsakis 
8482449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8492449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
8502449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
8512449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
8522449ea2eSAlexandros Batsakis 				    XDR_UNIT);
85399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
8541da177e4SLinus Torvalds 
855bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
856bca79478STrond Myklebust 	[NF4BAD] = 0,
857bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
858bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
859bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
860bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
861bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
862bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
863bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
864bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
865bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
8661da177e4SLinus Torvalds };
8671da177e4SLinus Torvalds 
8681da177e4SLinus Torvalds struct compound_hdr {
8691da177e4SLinus Torvalds 	int32_t		status;
8701da177e4SLinus Torvalds 	uint32_t	nops;
871d017931cSAndy Adamson 	__be32 *	nops_p;
8721da177e4SLinus Torvalds 	uint32_t	taglen;
8731da177e4SLinus Torvalds 	char *		tag;
8740c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
87566cc0429SBenny Halevy 	u32		minorversion;
8761da177e4SLinus Torvalds };
8771da177e4SLinus Torvalds 
87813c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
87913c65ce9SBenny Halevy {
88013c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
88113c65ce9SBenny Halevy 	BUG_ON(!p);
88213c65ce9SBenny Halevy 	return p;
88313c65ce9SBenny Halevy }
8841da177e4SLinus Torvalds 
885cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
886cb17e556STrond Myklebust {
887cb17e556STrond Myklebust 	__be32 *p;
888cb17e556STrond Myklebust 
889cb17e556STrond Myklebust 	p = xdr_reserve_space(xdr, len);
890cb17e556STrond Myklebust 	xdr_encode_opaque_fixed(p, buf, len);
891cb17e556STrond Myklebust }
892cb17e556STrond Myklebust 
8931da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
8941da177e4SLinus Torvalds {
8958687b63aSAl Viro 	__be32 *p;
8961da177e4SLinus Torvalds 
8976fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 4 + len);
8981da177e4SLinus Torvalds 	xdr_encode_opaque(p, str, len);
8991da177e4SLinus Torvalds }
9001da177e4SLinus Torvalds 
9014ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9024ade9821STrond Myklebust {
9034ade9821STrond Myklebust 	__be32 *p;
9044ade9821STrond Myklebust 
9054ade9821STrond Myklebust 	p = reserve_space(xdr, 4);
9064ade9821STrond Myklebust 	*p = cpu_to_be32(n);
9074ade9821STrond Myklebust }
9084ade9821STrond Myklebust 
909ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
910ff2eb681STrond Myklebust {
911ff2eb681STrond Myklebust 	__be32 *p;
912ff2eb681STrond Myklebust 
913ff2eb681STrond Myklebust 	p = reserve_space(xdr, 8);
914ff2eb681STrond Myklebust 	xdr_encode_hyper(p, n);
915ff2eb681STrond Myklebust }
916ff2eb681STrond Myklebust 
9174ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
9184ade9821STrond Myklebust 		const struct nfs_seqid *seqid)
9194ade9821STrond Myklebust {
9204ade9821STrond Myklebust 	encode_uint32(xdr, seqid->sequence->counter);
9214ade9821STrond Myklebust }
9224ade9821STrond Myklebust 
9230c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
9240c4e8c18SBenny Halevy 				struct rpc_rqst *req,
9250c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
9261da177e4SLinus Torvalds {
9278687b63aSAl Viro 	__be32 *p;
928a17c2153STrond Myklebust 	struct rpc_auth *auth = req->rq_cred->cr_auth;
9290c4e8c18SBenny Halevy 
9300c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
9310c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
9320c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
9330c4e8c18SBenny Halevy 	hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
9341da177e4SLinus Torvalds 
9351da177e4SLinus Torvalds 	BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
9366fdfb0bcSTrond Myklebust 	encode_string(xdr, hdr->taglen, hdr->tag);
9376fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 8);
938e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
939d017931cSAndy Adamson 	hdr->nops_p = p;
94034558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
941d017931cSAndy Adamson }
942d017931cSAndy Adamson 
943ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
944ab19b481STrond Myklebust 		uint32_t replen,
945ab19b481STrond Myklebust 		struct compound_hdr *hdr)
946ab19b481STrond Myklebust {
947ab19b481STrond Myklebust 	encode_uint32(xdr, op);
948ab19b481STrond Myklebust 	hdr->nops++;
949ab19b481STrond Myklebust 	hdr->replen += replen;
950ab19b481STrond Myklebust }
951ab19b481STrond Myklebust 
952d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
953d017931cSAndy Adamson {
954fc931582SAndy Adamson 	BUG_ON(hdr->nops > NFS4_MAX_OPS);
955d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
9561da177e4SLinus Torvalds }
9571da177e4SLinus Torvalds 
958ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
959ea9d23f5STrond Myklebust {
9602d2f24adSTrond Myklebust 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
961ea9d23f5STrond Myklebust }
962ea9d23f5STrond Myklebust 
9631da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
9641da177e4SLinus Torvalds {
965cb17e556STrond Myklebust 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
9661da177e4SLinus Torvalds }
9671da177e4SLinus Torvalds 
968cf8cdbe5SAndy Adamson static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
9691da177e4SLinus Torvalds {
9701da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
9711da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
9721da177e4SLinus Torvalds 	int owner_namelen = 0;
9731da177e4SLinus Torvalds 	int owner_grouplen = 0;
9748687b63aSAl Viro 	__be32 *p;
9758687b63aSAl Viro 	__be32 *q;
9761da177e4SLinus Torvalds 	int len;
9771da177e4SLinus Torvalds 	uint32_t bmval0 = 0;
9781da177e4SLinus Torvalds 	uint32_t bmval1 = 0;
9791da177e4SLinus Torvalds 
9801da177e4SLinus Torvalds 	/*
9811da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
9821da177e4SLinus Torvalds 	 * In the worst-case, this would be
9831da177e4SLinus Torvalds 	 *   12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
9841da177e4SLinus Torvalds 	 *          = 36 bytes, plus any contribution from variable-length fields
98523ec6965SJ. Bruce Fields 	 *            such as owner/group.
9861da177e4SLinus Torvalds 	 */
9871da177e4SLinus Torvalds 	len = 16;
9881da177e4SLinus Torvalds 
9891da177e4SLinus Torvalds 	/* Sigh */
9901da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_SIZE)
9911da177e4SLinus Torvalds 		len += 8;
9921da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MODE)
9931da177e4SLinus Torvalds 		len += 4;
9941da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
995e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
9961da177e4SLinus Torvalds 		if (owner_namelen < 0) {
997fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
9981da177e4SLinus Torvalds 					iap->ia_uid);
9991da177e4SLinus Torvalds 			/* XXX */
10001da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
10011da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
10021da177e4SLinus Torvalds 			/* goto out; */
10031da177e4SLinus Torvalds 		}
10041da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
10051da177e4SLinus Torvalds 	}
10061da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
1007e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
10081da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
1009fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
10101da177e4SLinus Torvalds 					iap->ia_gid);
10111da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
10121da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
10131da177e4SLinus Torvalds 			/* goto out; */
10141da177e4SLinus Torvalds 		}
10151da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
10161da177e4SLinus Torvalds 	}
10171da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_ATIME_SET)
10181da177e4SLinus Torvalds 		len += 16;
10191da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_ATIME)
10201da177e4SLinus Torvalds 		len += 4;
10211da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MTIME_SET)
10221da177e4SLinus Torvalds 		len += 16;
10231da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_MTIME)
10241da177e4SLinus Torvalds 		len += 4;
102513c65ce9SBenny Halevy 	p = reserve_space(xdr, len);
10261da177e4SLinus Torvalds 
10271da177e4SLinus Torvalds 	/*
10281da177e4SLinus Torvalds 	 * We write the bitmap length now, but leave the bitmap and the attribute
10291da177e4SLinus Torvalds 	 * buffer length to be backfilled at the end of this routine.
10301da177e4SLinus Torvalds 	 */
1031e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
10321da177e4SLinus Torvalds 	q = p;
10331da177e4SLinus Torvalds 	p += 3;
10341da177e4SLinus Torvalds 
10351da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_SIZE) {
10361da177e4SLinus Torvalds 		bmval0 |= FATTR4_WORD0_SIZE;
1037b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
10381da177e4SLinus Torvalds 	}
10391da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MODE) {
10401da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_MODE;
1041e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
10421da177e4SLinus Torvalds 	}
10431da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
10441da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_OWNER;
1045811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
10461da177e4SLinus Torvalds 	}
10471da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
10481da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_OWNER_GROUP;
1049811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
10501da177e4SLinus Torvalds 	}
10511da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_ATIME_SET) {
10521da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1053e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1054e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
1055d3f6baaaSTrond Myklebust 		*p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1056d3f6baaaSTrond Myklebust 		*p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
10571da177e4SLinus Torvalds 	}
10581da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_ATIME) {
10591da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1060e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
10611da177e4SLinus Torvalds 	}
10621da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MTIME_SET) {
10631da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1064e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1065e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
1066e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1067e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
10681da177e4SLinus Torvalds 	}
10691da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_MTIME) {
10701da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1071e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
10721da177e4SLinus Torvalds 	}
10731da177e4SLinus Torvalds 
10741da177e4SLinus Torvalds 	/*
10751da177e4SLinus Torvalds 	 * Now we backfill the bitmap and the attribute buffer length.
10761da177e4SLinus Torvalds 	 */
10771da177e4SLinus Torvalds 	if (len != ((char *)p - (char *)q) + 4) {
1078f9fd2d9cSWeston Andros Adamson 		printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
10791da177e4SLinus Torvalds 				len, ((char *)p - (char *)q) + 4);
10801da177e4SLinus Torvalds 		BUG();
10811da177e4SLinus Torvalds 	}
10821da177e4SLinus Torvalds 	len = (char *)p - (char *)q - 12;
10831da177e4SLinus Torvalds 	*q++ = htonl(bmval0);
10841da177e4SLinus Torvalds 	*q++ = htonl(bmval1);
108534558513SBenny Halevy 	*q = htonl(len);
10861da177e4SLinus Torvalds 
10871da177e4SLinus Torvalds /* out: */
10881da177e4SLinus Torvalds }
10891da177e4SLinus Torvalds 
1090cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
10911da177e4SLinus Torvalds {
1092475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1093475d4ba0STrond Myklebust 	encode_uint32(xdr, access);
10941da177e4SLinus Torvalds }
10951da177e4SLinus Torvalds 
1096cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
10971da177e4SLinus Torvalds {
1098ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
10994ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1100ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
11011da177e4SLinus Torvalds }
11021da177e4SLinus Torvalds 
11030b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
11041da177e4SLinus Torvalds {
11058687b63aSAl Viro 	__be32 *p;
11061da177e4SLinus Torvalds 
1107475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1108475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1109b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
111034558513SBenny Halevy 	*p = cpu_to_be32(args->count);
11111da177e4SLinus Torvalds }
11121da177e4SLinus Torvalds 
1113cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
11141da177e4SLinus Torvalds {
11158687b63aSAl Viro 	__be32 *p;
11161da177e4SLinus Torvalds 
1117475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1118475d4ba0STrond Myklebust 	encode_uint32(xdr, create->ftype);
11191da177e4SLinus Torvalds 
11201da177e4SLinus Torvalds 	switch (create->ftype) {
11211da177e4SLinus Torvalds 	case NF4LNK:
112213c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
112334558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
112494a6d753SChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
11251da177e4SLinus Torvalds 		break;
11261da177e4SLinus Torvalds 
11271da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
112813c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1129e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
113034558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
11311da177e4SLinus Torvalds 		break;
11321da177e4SLinus Torvalds 
11331da177e4SLinus Torvalds 	default:
11341da177e4SLinus Torvalds 		break;
11351da177e4SLinus Torvalds 	}
11361da177e4SLinus Torvalds 
1137811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
1138cf8cdbe5SAndy Adamson 	encode_attrs(xdr, create->attrs, create->server);
11391da177e4SLinus Torvalds }
11401da177e4SLinus Torvalds 
1141cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
11421da177e4SLinus Torvalds {
11438687b63aSAl Viro 	__be32 *p;
11441da177e4SLinus Torvalds 
1145475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1146475d4ba0STrond Myklebust 	p = reserve_space(xdr, 8);
1147e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
114834558513SBenny Halevy 	*p = cpu_to_be32(bitmap);
11491da177e4SLinus Torvalds }
11501da177e4SLinus Torvalds 
1151cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
11521da177e4SLinus Torvalds {
11538687b63aSAl Viro 	__be32 *p;
11541da177e4SLinus Torvalds 
1155475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1156475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1157e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
1158e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(bm0);
115934558513SBenny Halevy 	*p = cpu_to_be32(bm1);
11601da177e4SLinus Torvalds }
11611da177e4SLinus Torvalds 
1162dae100c2SFred Isaman static void
1163dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr,
1164dae100c2SFred Isaman 		     uint32_t bm0, uint32_t bm1, uint32_t bm2,
1165dae100c2SFred Isaman 		     struct compound_hdr *hdr)
1166dae100c2SFred Isaman {
1167dae100c2SFred Isaman 	__be32 *p;
1168dae100c2SFred Isaman 
1169ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1170dae100c2SFred Isaman 	if (bm2) {
1171dae100c2SFred Isaman 		p = reserve_space(xdr, 16);
1172dae100c2SFred Isaman 		*p++ = cpu_to_be32(3);
1173dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1174dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm1);
1175dae100c2SFred Isaman 		*p = cpu_to_be32(bm2);
1176dae100c2SFred Isaman 	} else if (bm1) {
1177dae100c2SFred Isaman 		p = reserve_space(xdr, 12);
1178dae100c2SFred Isaman 		*p++ = cpu_to_be32(2);
1179dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1180dae100c2SFred Isaman 		*p = cpu_to_be32(bm1);
1181dae100c2SFred Isaman 	} else {
1182dae100c2SFred Isaman 		p = reserve_space(xdr, 8);
1183dae100c2SFred Isaman 		*p++ = cpu_to_be32(1);
1184dae100c2SFred Isaman 		*p = cpu_to_be32(bm0);
1185dae100c2SFred Isaman 	}
1186dae100c2SFred Isaman }
1187dae100c2SFred Isaman 
1188cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
11891da177e4SLinus Torvalds {
1190cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1191d017931cSAndy Adamson 			   bitmask[1] & nfs4_fattr_bitmap[1], hdr);
11921da177e4SLinus Torvalds }
11931da177e4SLinus Torvalds 
119488034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
11951549210fSTrond Myklebust 				 const u32 *open_bitmap,
119688034c3dSAndy Adamson 				 struct compound_hdr *hdr)
119788034c3dSAndy Adamson {
119888034c3dSAndy Adamson 	encode_getattr_three(xdr,
11991549210fSTrond Myklebust 			     bitmask[0] & open_bitmap[0],
12001549210fSTrond Myklebust 			     bitmask[1] & open_bitmap[1],
12011549210fSTrond Myklebust 			     bitmask[2] & open_bitmap[2],
120288034c3dSAndy Adamson 			     hdr);
120388034c3dSAndy Adamson }
120488034c3dSAndy Adamson 
1205cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12061da177e4SLinus Torvalds {
1207dae100c2SFred Isaman 	encode_getattr_three(xdr,
1208dae100c2SFred Isaman 			     bitmask[0] & nfs4_fsinfo_bitmap[0],
1209dae100c2SFred Isaman 			     bitmask[1] & nfs4_fsinfo_bitmap[1],
1210dae100c2SFred Isaman 			     bitmask[2] & nfs4_fsinfo_bitmap[2],
1211dae100c2SFred Isaman 			     hdr);
12121da177e4SLinus Torvalds }
12131da177e4SLinus Torvalds 
1214cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1215830b8e33SManoj Naik {
1216cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1217cf8cdbe5SAndy Adamson 			   bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1218830b8e33SManoj Naik }
1219830b8e33SManoj Naik 
1220cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12211da177e4SLinus Torvalds {
1222ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12231da177e4SLinus Torvalds }
12241da177e4SLinus Torvalds 
1225cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12261da177e4SLinus Torvalds {
1227ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
12286fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
12291da177e4SLinus Torvalds }
12301da177e4SLinus Torvalds 
1231911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1232911d1aafSTrond Myklebust {
1233f44106e2SJeff Layton 	if (fl->fl_type == F_RDLCK)
1234911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1235911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1236911d1aafSTrond Myklebust }
1237911d1aafSTrond Myklebust 
1238911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1239911d1aafSTrond Myklebust {
1240911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1241911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1242911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1243911d1aafSTrond Myklebust }
1244911d1aafSTrond Myklebust 
1245daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1246daccbdedSTrond Myklebust {
1247daccbdedSTrond Myklebust 	__be32 *p;
1248daccbdedSTrond Myklebust 
1249d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1250daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1251d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1252daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1253d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1254daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1255daccbdedSTrond Myklebust }
1256daccbdedSTrond Myklebust 
12571da177e4SLinus Torvalds /*
12581da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
12591da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
12601da177e4SLinus Torvalds  */
1261cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
12621da177e4SLinus Torvalds {
12638687b63aSAl Viro 	__be32 *p;
12641da177e4SLinus Torvalds 
1265475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1266475d4ba0STrond Myklebust 	p = reserve_space(xdr, 28);
1267e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1268e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1269b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1270b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
127134558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1272911d1aafSTrond Myklebust 	if (args->new_lock_owner){
12734ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->open_seqid);
1274ea9d23f5STrond Myklebust 		encode_nfs4_stateid(xdr, args->open_stateid);
12754ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
1276daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
12771da177e4SLinus Torvalds 	}
12781da177e4SLinus Torvalds 	else {
1279ea9d23f5STrond Myklebust 		encode_nfs4_stateid(xdr, args->lock_stateid);
12804ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
12811da177e4SLinus Torvalds 	}
12821da177e4SLinus Torvalds }
12831da177e4SLinus Torvalds 
1284cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
12851da177e4SLinus Torvalds {
12868687b63aSAl Viro 	__be32 *p;
12871da177e4SLinus Torvalds 
1288475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1289475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1290e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1291b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1292b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1293daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
12941da177e4SLinus Torvalds }
12951da177e4SLinus Torvalds 
1296cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
12971da177e4SLinus Torvalds {
12988687b63aSAl Viro 	__be32 *p;
12991da177e4SLinus Torvalds 
1300475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1301475d4ba0STrond Myklebust 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13024ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, args->seqid);
1303ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
1304ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1305b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
130634558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13071da177e4SLinus Torvalds }
13081da177e4SLinus Torvalds 
1309d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1310d3c7b7ccSTrond Myklebust {
1311ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1312d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1313d3c7b7ccSTrond Myklebust }
1314d3c7b7ccSTrond Myklebust 
1315cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13161da177e4SLinus Torvalds {
1317ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13186fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
13191da177e4SLinus Torvalds }
13201da177e4SLinus Torvalds 
1321dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
13221da177e4SLinus Torvalds {
13238687b63aSAl Viro 	__be32 *p;
13241da177e4SLinus Torvalds 
132513c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1326dc0b027dSTrond Myklebust 	switch (fmode & (FMODE_READ|FMODE_WRITE)) {
13271da177e4SLinus Torvalds 	case FMODE_READ:
1328e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
13291da177e4SLinus Torvalds 		break;
13301da177e4SLinus Torvalds 	case FMODE_WRITE:
1331e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
13321da177e4SLinus Torvalds 		break;
13331da177e4SLinus Torvalds 	case FMODE_READ|FMODE_WRITE:
1334e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
13351da177e4SLinus Torvalds 		break;
13361da177e4SLinus Torvalds 	default:
1337e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
13381da177e4SLinus Torvalds 	}
133934558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13401da177e4SLinus Torvalds }
13411da177e4SLinus Torvalds 
13421da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13431da177e4SLinus Torvalds {
13448687b63aSAl Viro 	__be32 *p;
13451da177e4SLinus Torvalds  /*
13461da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
13471da177e4SLinus Torvalds  * owner 4 = 32
13481da177e4SLinus Torvalds  */
13494ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1350dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
135195b72eb0STrond Myklebust 	p = reserve_space(xdr, 36);
1352b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
135395b72eb0STrond Myklebust 	*p++ = cpu_to_be32(24);
135493f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1355d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
135695b72eb0STrond Myklebust 	*p++ = cpu_to_be32(arg->id.uniquifier);
135795b72eb0STrond Myklebust 	xdr_encode_hyper(p, arg->id.create_time);
13581da177e4SLinus Torvalds }
13591da177e4SLinus Torvalds 
13601da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13611da177e4SLinus Torvalds {
13628687b63aSAl Viro 	__be32 *p;
13634882ef72SAlexandros Batsakis 	struct nfs_client *clp;
13641da177e4SLinus Torvalds 
136513c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
13661da177e4SLinus Torvalds 	switch(arg->open_flags & O_EXCL) {
13671da177e4SLinus Torvalds 	case 0:
136834558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
13691da177e4SLinus Torvalds 		encode_attrs(xdr, arg->u.attrs, arg->server);
13701da177e4SLinus Torvalds 		break;
13711da177e4SLinus Torvalds 	default:
13724882ef72SAlexandros Batsakis 		clp = arg->server->nfs_client;
1373a4432345STrond Myklebust 		if (clp->cl_mvops->minor_version > 0) {
13744882ef72SAlexandros Batsakis 			if (nfs4_has_persistent_session(clp)) {
13754882ef72SAlexandros Batsakis 				*p = cpu_to_be32(NFS4_CREATE_GUARDED);
13764882ef72SAlexandros Batsakis 				encode_attrs(xdr, arg->u.attrs, arg->server);
13774882ef72SAlexandros Batsakis 			} else {
13784882ef72SAlexandros Batsakis 				struct iattr dummy;
13794882ef72SAlexandros Batsakis 
13804882ef72SAlexandros Batsakis 				*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
13814882ef72SAlexandros Batsakis 				encode_nfs4_verifier(xdr, &arg->u.verifier);
13824882ef72SAlexandros Batsakis 				dummy.ia_valid = 0;
13834882ef72SAlexandros Batsakis 				encode_attrs(xdr, &dummy, arg->server);
13844882ef72SAlexandros Batsakis 			}
13854882ef72SAlexandros Batsakis 		} else {
138634558513SBenny Halevy 			*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
13871da177e4SLinus Torvalds 			encode_nfs4_verifier(xdr, &arg->u.verifier);
13881da177e4SLinus Torvalds 		}
13891da177e4SLinus Torvalds 	}
13904882ef72SAlexandros Batsakis }
13911da177e4SLinus Torvalds 
13921da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13931da177e4SLinus Torvalds {
13948687b63aSAl Viro 	__be32 *p;
13951da177e4SLinus Torvalds 
139613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
13971da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
13981da177e4SLinus Torvalds 	case 0:
139934558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14001da177e4SLinus Torvalds 		break;
14011da177e4SLinus Torvalds 	default:
14021da177e4SLinus Torvalds 		BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
140334558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14041da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14051da177e4SLinus Torvalds 	}
14061da177e4SLinus Torvalds }
14071da177e4SLinus Torvalds 
1408bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14091da177e4SLinus Torvalds {
14108687b63aSAl Viro 	__be32 *p;
14111da177e4SLinus Torvalds 
141213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14131da177e4SLinus Torvalds 	switch (delegation_type) {
14141da177e4SLinus Torvalds 	case 0:
141534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14161da177e4SLinus Torvalds 		break;
14171da177e4SLinus Torvalds 	case FMODE_READ:
141834558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14191da177e4SLinus Torvalds 		break;
14201da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
142134558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14221da177e4SLinus Torvalds 		break;
14231da177e4SLinus Torvalds 	default:
14241da177e4SLinus Torvalds 		BUG();
14251da177e4SLinus Torvalds 	}
14261da177e4SLinus Torvalds }
14271da177e4SLinus Torvalds 
14281da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14291da177e4SLinus Torvalds {
14308687b63aSAl Viro 	__be32 *p;
14311da177e4SLinus Torvalds 
143213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
143334558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14341da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14351da177e4SLinus Torvalds }
14361da177e4SLinus Torvalds 
1437bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14381da177e4SLinus Torvalds {
14398687b63aSAl Viro 	__be32 *p;
14401da177e4SLinus Torvalds 
144113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
144234558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14431da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14441da177e4SLinus Torvalds }
14451da177e4SLinus Torvalds 
14461da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14471da177e4SLinus Torvalds {
14488687b63aSAl Viro 	__be32 *p;
14491da177e4SLinus Torvalds 
1450ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 4);
1451ea9d23f5STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1452ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
14531da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14541da177e4SLinus Torvalds }
14551da177e4SLinus Torvalds 
1456cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
14571da177e4SLinus Torvalds {
1458ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
14591da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
14601da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
14611da177e4SLinus Torvalds 	switch (arg->claim) {
14621da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
14631da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
14641da177e4SLinus Torvalds 		break;
14651da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
14661da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
14671da177e4SLinus Torvalds 		break;
14681da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
14691da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
14701da177e4SLinus Torvalds 		break;
14711da177e4SLinus Torvalds 	default:
14721da177e4SLinus Torvalds 		BUG();
14731da177e4SLinus Torvalds 	}
14741da177e4SLinus Torvalds }
14751da177e4SLinus Torvalds 
1476cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
14771da177e4SLinus Torvalds {
1478ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1479ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
14804ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
14811da177e4SLinus Torvalds }
14821da177e4SLinus Torvalds 
1483cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
14841da177e4SLinus Torvalds {
1485ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1486ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
14874ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1488dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
14891da177e4SLinus Torvalds }
14901da177e4SLinus Torvalds 
1491cf8cdbe5SAndy Adamson static void
1492d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
14931da177e4SLinus Torvalds {
1494ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
14956fdfb0bcSTrond Myklebust 	encode_string(xdr, fh->size, fh->data);
14961da177e4SLinus Torvalds }
14971da177e4SLinus Torvalds 
1498cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
14991da177e4SLinus Torvalds {
1500ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15011da177e4SLinus Torvalds }
15021da177e4SLinus Torvalds 
15034fc8796dSTrond Myklebust static void encode_open_stateid(struct xdr_stream *xdr,
15044fc8796dSTrond Myklebust 		const struct nfs_open_context *ctx,
15054fc8796dSTrond Myklebust 		const struct nfs_lock_context *l_ctx,
15064fc8796dSTrond Myklebust 		fmode_t fmode,
15074fc8796dSTrond Myklebust 		int zero_seqid)
15081da177e4SLinus Torvalds {
15091da177e4SLinus Torvalds 	nfs4_stateid stateid;
15101da177e4SLinus Torvalds 
15111da177e4SLinus Torvalds 	if (ctx->state != NULL) {
15122a369153STrond Myklebust 		const struct nfs_lockowner *lockowner = NULL;
15132a369153STrond Myklebust 
15142a369153STrond Myklebust 		if (l_ctx != NULL)
15152a369153STrond Myklebust 			lockowner = &l_ctx->lockowner;
15164fc8796dSTrond Myklebust 		nfs4_select_rw_stateid(&stateid, ctx->state,
15172a369153STrond Myklebust 				fmode, lockowner);
151889d1ea65SAndy Adamson 		if (zero_seqid)
15192d2f24adSTrond Myklebust 			stateid.seqid = 0;
1520ea9d23f5STrond Myklebust 		encode_nfs4_stateid(xdr, &stateid);
15211da177e4SLinus Torvalds 	} else
1522ea9d23f5STrond Myklebust 		encode_nfs4_stateid(xdr, &zero_stateid);
15231da177e4SLinus Torvalds }
15241da177e4SLinus Torvalds 
1525cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
15261da177e4SLinus Torvalds {
15278687b63aSAl Viro 	__be32 *p;
15281da177e4SLinus Torvalds 
1529ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1530d0b496d2STrond Myklebust 	encode_open_stateid(xdr, args->context, args->lock_context,
15314fc8796dSTrond Myklebust 			FMODE_READ, hdr->minorversion);
15321da177e4SLinus Torvalds 
153313c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1534b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
153534558513SBenny Halevy 	*p = cpu_to_be32(args->count);
15361da177e4SLinus Torvalds }
15371da177e4SLinus Torvalds 
1538cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15391da177e4SLinus Torvalds {
154028331a46STrond Myklebust 	uint32_t attrs[2] = {
154128331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
154228331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
154328331a46STrond Myklebust 	};
15446f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
1545cd93710eSChuck Lever 	__be32 *p, verf[2];
15461da177e4SLinus Torvalds 
154782f2e547SBryan Schumaker 	if (readdir->plus) {
154882f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
154928331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
155082f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
155182f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
155282f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
155382f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
15546f7a35bdSTrond Myklebust 		dircount >>= 1;
155582f2e547SBryan Schumaker 	}
155628331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
155728331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
155828331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
15596f7a35bdSTrond Myklebust 
1560475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1561ff2eb681STrond Myklebust 	encode_uint64(xdr, readdir->cookie);
1562cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &readdir->verifier);
1563cd93710eSChuck Lever 	p = reserve_space(xdr, 20);
15646f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
15656f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
15666f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(2);
156782f2e547SBryan Schumaker 
1568e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
156934558513SBenny Halevy 	*p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1570cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
157144109241SFred Isaman 	dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
157244109241SFred Isaman 			__func__,
1573eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1574cd93710eSChuck Lever 			verf[0], verf[1],
1575eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1576eadf4598STrond Myklebust 			attrs[1] & readdir->bitmask[1]);
15771da177e4SLinus Torvalds }
15781da177e4SLinus Torvalds 
1579cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
15801da177e4SLinus Torvalds {
1581ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
15821da177e4SLinus Torvalds }
15831da177e4SLinus Torvalds 
1584cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
15851da177e4SLinus Torvalds {
1586ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
15876fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
15881da177e4SLinus Torvalds }
15891da177e4SLinus Torvalds 
1590cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
15911da177e4SLinus Torvalds {
1592ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1593811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1594811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
15951da177e4SLinus Torvalds }
15961da177e4SLinus Torvalds 
1597bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1598bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
15991da177e4SLinus Torvalds {
1600475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1601ff2eb681STrond Myklebust 	encode_uint64(xdr, clid);
16021da177e4SLinus Torvalds }
16031da177e4SLinus Torvalds 
1604cf8cdbe5SAndy Adamson static void
1605d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
160656ae19f3STrond Myklebust {
1607ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
160856ae19f3STrond Myklebust }
160956ae19f3STrond Myklebust 
16109f06c719SChuck Lever static void
1611d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
161223ec6965SJ. Bruce Fields {
16138687b63aSAl Viro 	__be32 *p;
161423ec6965SJ. Bruce Fields 
1615ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1616ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &zero_stateid);
161713c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1618e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
161934558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
16209f06c719SChuck Lever 	BUG_ON(arg->acl_len % 4);
162113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
162234558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
162323ec6965SJ. Bruce Fields 	xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
162423ec6965SJ. Bruce Fields }
162523ec6965SJ. Bruce Fields 
1626cf8cdbe5SAndy Adamson static void
1627d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16281da177e4SLinus Torvalds {
1629ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
16301da177e4SLinus Torvalds }
16311da177e4SLinus Torvalds 
1632cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16331da177e4SLinus Torvalds {
1634ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1635ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
1636cf8cdbe5SAndy Adamson 	encode_attrs(xdr, arg->iap, server);
16371da177e4SLinus Torvalds }
16381da177e4SLinus Torvalds 
1639cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
16401da177e4SLinus Torvalds {
16418687b63aSAl Viro 	__be32 *p;
16421da177e4SLinus Torvalds 
164370019514STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1644cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
16451da177e4SLinus Torvalds 
16461da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
164713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
164834558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
16491da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
16501da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
165113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
165234558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_cb_ident);
16531da177e4SLinus Torvalds }
16541da177e4SLinus Torvalds 
1655bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
16561da177e4SLinus Torvalds {
1657475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1658475d4ba0STrond Myklebust 			decode_setclientid_confirm_maxsz, hdr);
1659ff2eb681STrond Myklebust 	encode_uint64(xdr, arg->clientid);
1660cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &arg->confirm);
16611da177e4SLinus Torvalds }
16621da177e4SLinus Torvalds 
1663cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
16641da177e4SLinus Torvalds {
16658687b63aSAl Viro 	__be32 *p;
16661da177e4SLinus Torvalds 
1667ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1668d0b496d2STrond Myklebust 	encode_open_stateid(xdr, args->context, args->lock_context,
16694fc8796dSTrond Myklebust 			FMODE_WRITE, hdr->minorversion);
16701da177e4SLinus Torvalds 
167113c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1672b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1673e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
167434558513SBenny Halevy 	*p = cpu_to_be32(args->count);
16751da177e4SLinus Torvalds 
16761da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
16771da177e4SLinus Torvalds }
16781da177e4SLinus Torvalds 
1679cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
16801da177e4SLinus Torvalds {
1681ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1682ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
16831da177e4SLinus Torvalds }
16849b7b9fccSAndy Adamson 
16855a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16865a5ea0d4SBryan Schumaker {
1687ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
16886fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
16895a5ea0d4SBryan Schumaker }
16905a5ea0d4SBryan Schumaker 
169199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
16929b7b9fccSAndy Adamson /* NFSv4.1 operations */
16937c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
16947c44f1aeSWeston Andros Adamson 				   struct nfs4_session *session,
16957c44f1aeSWeston Andros Adamson 				   struct compound_hdr *hdr)
16967c44f1aeSWeston Andros Adamson {
16977c44f1aeSWeston Andros Adamson 	__be32 *p;
16987c44f1aeSWeston Andros Adamson 
16997c44f1aeSWeston Andros Adamson 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17007c44f1aeSWeston Andros Adamson 		decode_bind_conn_to_session_maxsz, hdr);
17017c44f1aeSWeston Andros Adamson 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
17027c44f1aeSWeston Andros Adamson 	p = xdr_reserve_space(xdr, 8);
17037c44f1aeSWeston Andros Adamson 	*p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
17047c44f1aeSWeston Andros Adamson 	*p = 0;	/* use_conn_in_rdma_mode = False */
17057c44f1aeSWeston Andros Adamson }
17067c44f1aeSWeston Andros Adamson 
170799fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
170899fe60d0SBenny Halevy 			       struct nfs41_exchange_id_args *args,
170999fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
171099fe60d0SBenny Halevy {
171199fe60d0SBenny Halevy 	__be32 *p;
1712db8ac8baSWeston Andros Adamson 	char impl_name[NFS4_OPAQUE_LIMIT];
1713db8ac8baSWeston Andros Adamson 	int len = 0;
171499fe60d0SBenny Halevy 
171570019514STrond Myklebust 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1716cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, args->verifier);
171799fe60d0SBenny Halevy 
171899fe60d0SBenny Halevy 	encode_string(xdr, args->id_len, args->id);
171999fe60d0SBenny Halevy 
172013c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1721e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);
1722e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);	/* zero length state_protect4_a */
1723db8ac8baSWeston Andros Adamson 
1724db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1725db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1726db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1727db8ac8baSWeston Andros Adamson 		<= NFS4_OPAQUE_LIMIT + 1)
1728db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1729db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1730db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1731db8ac8baSWeston Andros Adamson 
1732db8ac8baSWeston Andros Adamson 	if (len > 0) {
1733db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(1);	/* implementation id array length=1 */
1734db8ac8baSWeston Andros Adamson 
1735db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1736db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1737db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1738db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1739db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1740db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1741db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1742db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1743db8ac8baSWeston Andros Adamson 	} else
1744db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);	/* implementation id array length=0 */
174599fe60d0SBenny Halevy }
1746fc931582SAndy Adamson 
1747fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1748fc931582SAndy Adamson 				  struct nfs41_create_session_args *args,
1749fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1750fc931582SAndy Adamson {
1751fc931582SAndy Adamson 	__be32 *p;
1752fc931582SAndy Adamson 	char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1753fc931582SAndy Adamson 	uint32_t len;
1754fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
1755f092075dSChuck Lever 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
17568e0d46e1SMike Sager 	u32 max_resp_sz_cached;
17578e0d46e1SMike Sager 
17588e0d46e1SMike Sager 	/*
17598e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
17608e0d46e1SMike Sager 	 * 2 is the verifier.
17618e0d46e1SMike Sager 	 */
17628e0d46e1SMike Sager 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
17638e0d46e1SMike Sager 			      RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1764fc931582SAndy Adamson 
1765fc931582SAndy Adamson 	len = scnprintf(machine_name, sizeof(machine_name), "%s",
1766fc931582SAndy Adamson 			clp->cl_ipaddr);
176742edd698SBenny Halevy 
1768475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1769475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1770114f64b5SAndy Adamson 	p = xdr_encode_hyper(p, clp->cl_clientid);
1771e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(clp->cl_seqid);			/*Sequence id */
1772e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1773fc931582SAndy Adamson 
1774fc931582SAndy Adamson 	/* Fore Channel */
1775c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1776e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1777e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
17788e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1779e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1780e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1781e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1782fc931582SAndy Adamson 
1783fc931582SAndy Adamson 	/* Back Channel */
1784c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1785e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1786e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1787e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1788e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1789e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1790e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1791fc931582SAndy Adamson 
1792e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1793e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1794e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1795fc931582SAndy Adamson 
1796fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
1797f092075dSChuck Lever 	*p++ = (__be32)nn->boot_time.tv_nsec;		/* stamp */
1798811652bdSBenny Halevy 	p = xdr_encode_opaque(p, machine_name, len);
1799e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1800e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
180134558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1802fc931582SAndy Adamson }
18030f3e66c6SAndy Adamson 
18040f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
18050f3e66c6SAndy Adamson 				   struct nfs4_session *session,
18060f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18070f3e66c6SAndy Adamson {
1808475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1809475d4ba0STrond Myklebust 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18100f3e66c6SAndy Adamson }
181118019753SRicardo Labiaga 
181266245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
181366245539STrond Myklebust 				   uint64_t clientid,
181466245539STrond Myklebust 				   struct compound_hdr *hdr)
181566245539STrond Myklebust {
181666245539STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
181766245539STrond Myklebust 	encode_uint64(xdr, clientid);
181866245539STrond Myklebust }
181966245539STrond Myklebust 
182018019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
182118019753SRicardo Labiaga 				    struct nfs41_reclaim_complete_args *args,
182218019753SRicardo Labiaga 				    struct compound_hdr *hdr)
182318019753SRicardo Labiaga {
1824475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1825475d4ba0STrond Myklebust 	encode_uint32(xdr, args->one_fs);
182618019753SRicardo Labiaga }
182799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
182899fe60d0SBenny Halevy 
18299b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
18309b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
18319b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
18329b7b9fccSAndy Adamson {
18339b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
18349b7b9fccSAndy Adamson 	struct nfs4_session *session = args->sa_session;
1835fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
1836fc01cea9SAndy Adamson 	struct nfs4_slot *slot;
1837fc01cea9SAndy Adamson 	__be32 *p;
18389b7b9fccSAndy Adamson 
18399b7b9fccSAndy Adamson 	if (!session)
18409b7b9fccSAndy Adamson 		return;
18419b7b9fccSAndy Adamson 
1842fc01cea9SAndy Adamson 	tp = &session->fc_slot_table;
1843fc01cea9SAndy Adamson 
1844fc01cea9SAndy Adamson 	WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1845fc01cea9SAndy Adamson 	slot = tp->slots + args->sa_slotid;
1846fc01cea9SAndy Adamson 
1847475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1848fc01cea9SAndy Adamson 
1849fc01cea9SAndy Adamson 	/*
1850fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1851fc01cea9SAndy Adamson 	 */
1852fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1853fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1854fc01cea9SAndy Adamson 		__func__,
1855fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1856fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1857fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1858fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
1859fc01cea9SAndy Adamson 		slot->seq_nr, args->sa_slotid,
1860fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
1861475d4ba0STrond Myklebust 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
186293f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1863e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
1864e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->sa_slotid);
1865e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
186634558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
18679b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
18689b7b9fccSAndy Adamson }
18699b7b9fccSAndy Adamson 
1870b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1871b1f69b75SAndy Adamson static void
18727f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr,
18737f11d8d3SAndy Adamson 		     const struct nfs4_getdevicelist_args *args,
18747f11d8d3SAndy Adamson 		     struct compound_hdr *hdr)
18757f11d8d3SAndy Adamson {
18767f11d8d3SAndy Adamson 	__be32 *p;
18777f11d8d3SAndy Adamson 	nfs4_verifier dummy = {
18787f11d8d3SAndy Adamson 		.data = "dummmmmy",
18797f11d8d3SAndy Adamson 	};
18807f11d8d3SAndy Adamson 
1881475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1882475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
18837f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(args->layoutclass);
18847f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
18857f11d8d3SAndy Adamson 	xdr_encode_hyper(p, 0ULL);                          /* cookie */
18867f11d8d3SAndy Adamson 	encode_nfs4_verifier(xdr, &dummy);
18877f11d8d3SAndy Adamson }
18887f11d8d3SAndy Adamson 
18897f11d8d3SAndy Adamson static void
1890b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1891b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1892b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1893b1f69b75SAndy Adamson {
1894b1f69b75SAndy Adamson 	__be32 *p;
1895b1f69b75SAndy Adamson 
1896475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1897475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1898b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1899b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1900b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1901b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->pglen);		/* gdia_maxcount */
1902b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);				/* bitmap length 0 */
1903b1f69b75SAndy Adamson }
1904b1f69b75SAndy Adamson 
1905b1f69b75SAndy Adamson static void
1906b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1907b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1908b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1909b1f69b75SAndy Adamson {
1910b1f69b75SAndy Adamson 	__be32 *p;
1911b1f69b75SAndy Adamson 
1912475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1913475d4ba0STrond Myklebust 	p = reserve_space(xdr, 36);
1914b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1915b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
1916b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
1917b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
1918b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
1919b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
1920ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1921475d4ba0STrond Myklebust 	encode_uint32(xdr, args->maxcount);
1922b1f69b75SAndy Adamson 
1923b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1924b1f69b75SAndy Adamson 		__func__,
1925b1f69b75SAndy Adamson 		args->type,
1926b1f69b75SAndy Adamson 		args->range.iomode,
1927b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
1928b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
1929b1f69b75SAndy Adamson 		args->maxcount);
1930b1f69b75SAndy Adamson }
1931863a3c6cSAndy Adamson 
1932863a3c6cSAndy Adamson static int
1933863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
1934ac7db726SBenny Halevy 		    struct inode *inode,
1935863a3c6cSAndy Adamson 		    const struct nfs4_layoutcommit_args *args,
1936863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
1937863a3c6cSAndy Adamson {
1938863a3c6cSAndy Adamson 	__be32 *p;
1939863a3c6cSAndy Adamson 
1940863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1941863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1942863a3c6cSAndy Adamson 
1943475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1944475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1945863a3c6cSAndy Adamson 	/* Only whole file layouts */
1946863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
19473557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
1948ea9d23f5STrond Myklebust 	*p = cpu_to_be32(0); /* reclaim */
1949ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1950ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 20);
1951863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(1); /* newoffset = TRUE */
1952863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, args->lastbytewritten);
1953863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1954863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1955ac7db726SBenny Halevy 
1956ac7db726SBenny Halevy 	if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1957ac7db726SBenny Halevy 		NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1958ac7db726SBenny Halevy 			NFS_I(inode)->layout, xdr, args);
1959475d4ba0STrond Myklebust 	else
1960475d4ba0STrond Myklebust 		encode_uint32(xdr, 0); /* no layout-type payload */
1961863a3c6cSAndy Adamson 
1962863a3c6cSAndy Adamson 	return 0;
1963863a3c6cSAndy Adamson }
1964cbe82603SBenny Halevy 
1965cbe82603SBenny Halevy static void
1966cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
1967cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
1968cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
1969cbe82603SBenny Halevy {
1970cbe82603SBenny Halevy 	__be32 *p;
1971cbe82603SBenny Halevy 
1972475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1973475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
1974cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
1975cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
1976cbe82603SBenny Halevy 	*p++ = cpu_to_be32(IOMODE_ANY);
1977cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
1978ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1979cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, 0);
1980cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1981cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
1982ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1983cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
198404a55549SAndy Adamson 	if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
198504a55549SAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
198604a55549SAndy Adamson 			NFS_I(args->inode)->layout, xdr, args);
1987475d4ba0STrond Myklebust 	} else
1988475d4ba0STrond Myklebust 		encode_uint32(xdr, 0);
1989cbe82603SBenny Halevy }
1990fca78d6dSBryan Schumaker 
1991fca78d6dSBryan Schumaker static int
1992fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
1993fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
1994fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
1995fca78d6dSBryan Schumaker {
1996475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1997475d4ba0STrond Myklebust 	encode_uint32(xdr, args->style);
1998fca78d6dSBryan Schumaker 	return 0;
1999fca78d6dSBryan Schumaker }
20007d974794SBryan Schumaker 
20017d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
20027d974794SBryan Schumaker 				struct nfs41_test_stateid_args *args,
20037d974794SBryan Schumaker 				struct compound_hdr *hdr)
20047d974794SBryan Schumaker {
2005475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2006475d4ba0STrond Myklebust 	encode_uint32(xdr, 1);
2007ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20087d974794SBryan Schumaker }
20099aeda35fSBryan Schumaker 
20109aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
20119aeda35fSBryan Schumaker 				struct nfs41_free_stateid_args *args,
20129aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
20139aeda35fSBryan Schumaker {
2014ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2015ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20169aeda35fSBryan Schumaker }
2017b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2018b1f69b75SAndy Adamson 
20191da177e4SLinus Torvalds /*
20201da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
20211da177e4SLinus Torvalds  */
20221da177e4SLinus Torvalds 
202366cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
202466cc0429SBenny Halevy {
202566cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
202666cc0429SBenny Halevy 	if (args->sa_session)
2027a4432345STrond Myklebust 		return args->sa_session->clp->cl_mvops->minor_version;
202866cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
202966cc0429SBenny Halevy 	return 0;
203066cc0429SBenny Halevy }
203166cc0429SBenny Halevy 
20321da177e4SLinus Torvalds /*
20331da177e4SLinus Torvalds  * Encode an ACCESS request
20341da177e4SLinus Torvalds  */
20359f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
20369f06c719SChuck Lever 				const struct nfs4_accessargs *args)
20371da177e4SLinus Torvalds {
20381da177e4SLinus Torvalds 	struct compound_hdr hdr = {
203966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
20401da177e4SLinus Torvalds 	};
20411da177e4SLinus Torvalds 
20429f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
20439f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
20449f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
20459f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
20469f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2047d017931cSAndy Adamson 	encode_nops(&hdr);
20481da177e4SLinus Torvalds }
20491da177e4SLinus Torvalds 
20501da177e4SLinus Torvalds /*
20511da177e4SLinus Torvalds  * Encode LOOKUP request
20521da177e4SLinus Torvalds  */
20539f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
20549f06c719SChuck Lever 				const struct nfs4_lookup_arg *args)
20551da177e4SLinus Torvalds {
20561da177e4SLinus Torvalds 	struct compound_hdr hdr = {
205766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
20581da177e4SLinus Torvalds 	};
20591da177e4SLinus Torvalds 
20609f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
20619f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
20629f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
20639f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
20649f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
20659f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2066d017931cSAndy Adamson 	encode_nops(&hdr);
20671da177e4SLinus Torvalds }
20681da177e4SLinus Torvalds 
20691da177e4SLinus Torvalds /*
20701da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
20711da177e4SLinus Torvalds  */
20729f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
20739f06c719SChuck Lever 				     struct xdr_stream *xdr,
20749f06c719SChuck Lever 				     const struct nfs4_lookup_root_arg *args)
20751da177e4SLinus Torvalds {
20761da177e4SLinus Torvalds 	struct compound_hdr hdr = {
207766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
20781da177e4SLinus Torvalds 	};
20791da177e4SLinus Torvalds 
20809f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
20819f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
20829f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
20839f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
20849f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2085d017931cSAndy Adamson 	encode_nops(&hdr);
20861da177e4SLinus Torvalds }
20871da177e4SLinus Torvalds 
20881da177e4SLinus Torvalds /*
20891da177e4SLinus Torvalds  * Encode REMOVE request
20901da177e4SLinus Torvalds  */
20919f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
20929f06c719SChuck Lever 				const struct nfs_removeargs *args)
20931da177e4SLinus Torvalds {
20941da177e4SLinus Torvalds 	struct compound_hdr hdr = {
209566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
20961da177e4SLinus Torvalds 	};
20971da177e4SLinus Torvalds 
20989f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
20999f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21009f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21019f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
2102d017931cSAndy Adamson 	encode_nops(&hdr);
21031da177e4SLinus Torvalds }
21041da177e4SLinus Torvalds 
21051da177e4SLinus Torvalds /*
21061da177e4SLinus Torvalds  * Encode RENAME request
21071da177e4SLinus Torvalds  */
21089f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
21099f06c719SChuck Lever 				const struct nfs_renameargs *args)
21101da177e4SLinus Torvalds {
21111da177e4SLinus Torvalds 	struct compound_hdr hdr = {
211266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21131da177e4SLinus Torvalds 	};
21141da177e4SLinus Torvalds 
21159f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21169f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21179f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
21189f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21199f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
21209f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2121d017931cSAndy Adamson 	encode_nops(&hdr);
21221da177e4SLinus Torvalds }
21231da177e4SLinus Torvalds 
21241da177e4SLinus Torvalds /*
21251da177e4SLinus Torvalds  * Encode LINK request
21261da177e4SLinus Torvalds  */
21279f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
21289f06c719SChuck Lever 			     const struct nfs4_link_arg *args)
21291da177e4SLinus Torvalds {
21301da177e4SLinus Torvalds 	struct compound_hdr hdr = {
213166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21321da177e4SLinus Torvalds 	};
21331da177e4SLinus Torvalds 
21349f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21359f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21369f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21379f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21389f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21399f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
21409f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
21419f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2142d017931cSAndy Adamson 	encode_nops(&hdr);
21431da177e4SLinus Torvalds }
21441da177e4SLinus Torvalds 
21451da177e4SLinus Torvalds /*
21461da177e4SLinus Torvalds  * Encode CREATE request
21471da177e4SLinus Torvalds  */
21489f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
21499f06c719SChuck Lever 				const struct nfs4_create_arg *args)
21501da177e4SLinus Torvalds {
21511da177e4SLinus Torvalds 	struct compound_hdr hdr = {
215266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21531da177e4SLinus Torvalds 	};
21541da177e4SLinus Torvalds 
21559f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21569f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21579f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21589f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
21599f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21609f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2161d017931cSAndy Adamson 	encode_nops(&hdr);
21621da177e4SLinus Torvalds }
21631da177e4SLinus Torvalds 
21641da177e4SLinus Torvalds /*
21651da177e4SLinus Torvalds  * Encode SYMLINK request
21661da177e4SLinus Torvalds  */
21679f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
21689f06c719SChuck Lever 				 const struct nfs4_create_arg *args)
21691da177e4SLinus Torvalds {
21709f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
21711da177e4SLinus Torvalds }
21721da177e4SLinus Torvalds 
21731da177e4SLinus Torvalds /*
21741da177e4SLinus Torvalds  * Encode GETATTR request
21751da177e4SLinus Torvalds  */
21769f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
21779f06c719SChuck Lever 				 const struct nfs4_getattr_arg *args)
21781da177e4SLinus Torvalds {
21791da177e4SLinus Torvalds 	struct compound_hdr hdr = {
218066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21811da177e4SLinus Torvalds 	};
21821da177e4SLinus Torvalds 
21839f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21849f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21859f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21869f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2187d017931cSAndy Adamson 	encode_nops(&hdr);
21881da177e4SLinus Torvalds }
21891da177e4SLinus Torvalds 
21901da177e4SLinus Torvalds /*
21911da177e4SLinus Torvalds  * Encode a CLOSE request
21921da177e4SLinus Torvalds  */
21939f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
21949f06c719SChuck Lever 			       struct nfs_closeargs *args)
21951da177e4SLinus Torvalds {
21961da177e4SLinus Torvalds 	struct compound_hdr hdr = {
219766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21981da177e4SLinus Torvalds 	};
21991da177e4SLinus Torvalds 
22009f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22019f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22029f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22039f06c719SChuck Lever 	encode_close(xdr, args, &hdr);
22049f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2205d017931cSAndy Adamson 	encode_nops(&hdr);
22061da177e4SLinus Torvalds }
22071da177e4SLinus Torvalds 
22081da177e4SLinus Torvalds /*
22091da177e4SLinus Torvalds  * Encode an OPEN request
22101da177e4SLinus Torvalds  */
22119f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
22129f06c719SChuck Lever 			      struct nfs_openargs *args)
22131da177e4SLinus Torvalds {
22141da177e4SLinus Torvalds 	struct compound_hdr hdr = {
221566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22161da177e4SLinus Torvalds 	};
22171da177e4SLinus Torvalds 
22189f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22199f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22209f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22219f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
22229f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22231549210fSTrond Myklebust 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2224d017931cSAndy Adamson 	encode_nops(&hdr);
22251da177e4SLinus Torvalds }
22261da177e4SLinus Torvalds 
22271da177e4SLinus Torvalds /*
22281da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
22291da177e4SLinus Torvalds  */
22309f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
22319f06c719SChuck Lever 				      struct xdr_stream *xdr,
22329f06c719SChuck Lever 				      struct nfs_open_confirmargs *args)
22331da177e4SLinus Torvalds {
22341da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2235d017931cSAndy Adamson 		.nops   = 0,
22361da177e4SLinus Torvalds 	};
22371da177e4SLinus Torvalds 
22389f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22399f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22409f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2241d017931cSAndy Adamson 	encode_nops(&hdr);
22421da177e4SLinus Torvalds }
22431da177e4SLinus Torvalds 
22441da177e4SLinus Torvalds /*
22451da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
22461da177e4SLinus Torvalds  */
22479f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
22489f06c719SChuck Lever 				     struct xdr_stream *xdr,
22499f06c719SChuck Lever 				     struct nfs_openargs *args)
22501da177e4SLinus Torvalds {
22511da177e4SLinus Torvalds 	struct compound_hdr hdr = {
225266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22531da177e4SLinus Torvalds 	};
22541da177e4SLinus Torvalds 
22559f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22569f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22579f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22589f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
22599f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2260d017931cSAndy Adamson 	encode_nops(&hdr);
22611da177e4SLinus Torvalds }
22621da177e4SLinus Torvalds 
22631da177e4SLinus Torvalds /*
22641da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
22651da177e4SLinus Torvalds  */
22669f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
22679f06c719SChuck Lever 					struct xdr_stream *xdr,
22689f06c719SChuck Lever 					struct nfs_closeargs *args)
22691da177e4SLinus Torvalds {
22701da177e4SLinus Torvalds 	struct compound_hdr hdr = {
227166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22721da177e4SLinus Torvalds 	};
22731da177e4SLinus Torvalds 
22749f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22759f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22769f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22779f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
22789f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2279d017931cSAndy Adamson 	encode_nops(&hdr);
22801da177e4SLinus Torvalds }
22811da177e4SLinus Torvalds 
22821da177e4SLinus Torvalds /*
22831da177e4SLinus Torvalds  * Encode a LOCK request
22841da177e4SLinus Torvalds  */
22859f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
22869f06c719SChuck Lever 			      struct nfs_lock_args *args)
22871da177e4SLinus Torvalds {
22881da177e4SLinus Torvalds 	struct compound_hdr hdr = {
228966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22901da177e4SLinus Torvalds 	};
22911da177e4SLinus Torvalds 
22929f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22939f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22949f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22959f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2296d017931cSAndy Adamson 	encode_nops(&hdr);
22971da177e4SLinus Torvalds }
22981da177e4SLinus Torvalds 
22991da177e4SLinus Torvalds /*
23001da177e4SLinus Torvalds  * Encode a LOCKT request
23011da177e4SLinus Torvalds  */
23029f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
23039f06c719SChuck Lever 			       struct nfs_lockt_args *args)
23041da177e4SLinus Torvalds {
23051da177e4SLinus Torvalds 	struct compound_hdr hdr = {
230666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23071da177e4SLinus Torvalds 	};
23081da177e4SLinus Torvalds 
23099f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23109f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23119f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23129f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2313d017931cSAndy Adamson 	encode_nops(&hdr);
23141da177e4SLinus Torvalds }
23151da177e4SLinus Torvalds 
23161da177e4SLinus Torvalds /*
23171da177e4SLinus Torvalds  * Encode a LOCKU request
23181da177e4SLinus Torvalds  */
23199f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
23209f06c719SChuck Lever 			       struct nfs_locku_args *args)
23211da177e4SLinus Torvalds {
23221da177e4SLinus Torvalds 	struct compound_hdr hdr = {
232366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23241da177e4SLinus Torvalds 	};
23251da177e4SLinus Torvalds 
23269f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23279f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23289f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23299f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2330d017931cSAndy Adamson 	encode_nops(&hdr);
23311da177e4SLinus Torvalds }
23321da177e4SLinus Torvalds 
23339f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
23349f06c719SChuck Lever 					   struct xdr_stream *xdr,
23359f06c719SChuck Lever 					struct nfs_release_lockowner_args *args)
2336d3c7b7ccSTrond Myklebust {
2337d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2338d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2339d3c7b7ccSTrond Myklebust 	};
2340d3c7b7ccSTrond Myklebust 
23419f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23429f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2343d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2344d3c7b7ccSTrond Myklebust }
2345d3c7b7ccSTrond Myklebust 
23461da177e4SLinus Torvalds /*
23471da177e4SLinus Torvalds  * Encode a READLINK request
23481da177e4SLinus Torvalds  */
23499f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
23509f06c719SChuck Lever 				  const struct nfs4_readlink *args)
23511da177e4SLinus Torvalds {
23521da177e4SLinus Torvalds 	struct compound_hdr hdr = {
235366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23541da177e4SLinus Torvalds 	};
23551da177e4SLinus Torvalds 
23569f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23579f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23589f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23599f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2360e3a535e1STrond Myklebust 
236128f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2362e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2363d017931cSAndy Adamson 	encode_nops(&hdr);
23641da177e4SLinus Torvalds }
23651da177e4SLinus Torvalds 
23661da177e4SLinus Torvalds /*
23671da177e4SLinus Torvalds  * Encode a READDIR request
23681da177e4SLinus Torvalds  */
23699f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
23709f06c719SChuck Lever 				 const struct nfs4_readdir_arg *args)
23711da177e4SLinus Torvalds {
23721da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23741da177e4SLinus Torvalds 	};
23751da177e4SLinus Torvalds 
23769f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23779f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23789f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23799f06c719SChuck Lever 	encode_readdir(xdr, args, req, &hdr);
2380d6ac02dfSTrond Myklebust 
238128f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2382d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2383d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
238428f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2385d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2386d017931cSAndy Adamson 	encode_nops(&hdr);
23871da177e4SLinus Torvalds }
23881da177e4SLinus Torvalds 
23891da177e4SLinus Torvalds /*
23901da177e4SLinus Torvalds  * Encode a READ request
23911da177e4SLinus Torvalds  */
23929f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
23939f06c719SChuck Lever 			      struct nfs_readargs *args)
23941da177e4SLinus Torvalds {
23951da177e4SLinus Torvalds 	struct compound_hdr hdr = {
239666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23971da177e4SLinus Torvalds 	};
23981da177e4SLinus Torvalds 
23999f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24009f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24019f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24029f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
24031da177e4SLinus Torvalds 
240428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
24051da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
24064f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2407d017931cSAndy Adamson 	encode_nops(&hdr);
24081da177e4SLinus Torvalds }
24091da177e4SLinus Torvalds 
24101da177e4SLinus Torvalds /*
24111da177e4SLinus Torvalds  * Encode an SETATTR request
24121da177e4SLinus Torvalds  */
24139f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
24149f06c719SChuck Lever 				 struct nfs_setattrargs *args)
24151da177e4SLinus Torvalds {
24161da177e4SLinus Torvalds 	struct compound_hdr hdr = {
241766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24181da177e4SLinus Torvalds 	};
24191da177e4SLinus Torvalds 
24209f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24219f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24229f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24239f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
24249f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2425d017931cSAndy Adamson 	encode_nops(&hdr);
24261da177e4SLinus Torvalds }
24271da177e4SLinus Torvalds 
24281da177e4SLinus Torvalds /*
2429029d105eSJ. Bruce Fields  * Encode a GETACL request
2430029d105eSJ. Bruce Fields  */
24319f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2432029d105eSJ. Bruce Fields 				struct nfs_getaclargs *args)
2433029d105eSJ. Bruce Fields {
2434029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
243566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2436029d105eSJ. Bruce Fields 	};
243728f56694SBenny Halevy 	uint32_t replen;
2438029d105eSJ. Bruce Fields 
24399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24409f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24419f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2442bf118a34SAndy Adamson 	replen = hdr.replen + op_decode_hdr_maxsz + 1;
24439f06c719SChuck Lever 	encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2444cf8cdbe5SAndy Adamson 
244528f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2446029d105eSJ. Bruce Fields 		args->acl_pages, args->acl_pgbase, args->acl_len);
2447bf118a34SAndy Adamson 
2448d017931cSAndy Adamson 	encode_nops(&hdr);
2449029d105eSJ. Bruce Fields }
2450029d105eSJ. Bruce Fields 
2451029d105eSJ. Bruce Fields /*
24521da177e4SLinus Torvalds  * Encode a WRITE request
24531da177e4SLinus Torvalds  */
24549f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
24559f06c719SChuck Lever 			       struct nfs_writeargs *args)
24561da177e4SLinus Torvalds {
24571da177e4SLinus Torvalds 	struct compound_hdr hdr = {
245866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24591da177e4SLinus Torvalds 	};
24601da177e4SLinus Torvalds 
24619f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24629f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24639f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24649f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
24654f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
24667ffd1064SFred Isaman 	if (args->bitmask)
24679f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2468d017931cSAndy Adamson 	encode_nops(&hdr);
24691da177e4SLinus Torvalds }
24701da177e4SLinus Torvalds 
24711da177e4SLinus Torvalds /*
24721da177e4SLinus Torvalds  *  a COMMIT request
24731da177e4SLinus Torvalds  */
24749f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
24750b7c0153SFred Isaman 				struct nfs_commitargs *args)
24761da177e4SLinus Torvalds {
24771da177e4SLinus Torvalds 	struct compound_hdr hdr = {
247866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24791da177e4SLinus Torvalds 	};
24801da177e4SLinus Torvalds 
24819f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24829f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24839f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24849f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2485d017931cSAndy Adamson 	encode_nops(&hdr);
24861da177e4SLinus Torvalds }
24871da177e4SLinus Torvalds 
24881da177e4SLinus Torvalds /*
24891da177e4SLinus Torvalds  * FSINFO request
24901da177e4SLinus Torvalds  */
24919f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
24929f06c719SChuck Lever 				struct nfs4_fsinfo_arg *args)
24931da177e4SLinus Torvalds {
24941da177e4SLinus Torvalds 	struct compound_hdr hdr = {
249566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24961da177e4SLinus Torvalds 	};
24971da177e4SLinus Torvalds 
24989f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24999f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25009f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25019f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2502d017931cSAndy Adamson 	encode_nops(&hdr);
25031da177e4SLinus Torvalds }
25041da177e4SLinus Torvalds 
25051da177e4SLinus Torvalds /*
25061da177e4SLinus Torvalds  * a PATHCONF request
25071da177e4SLinus Torvalds  */
25089f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
25099f06c719SChuck Lever 				  const struct nfs4_pathconf_arg *args)
25101da177e4SLinus Torvalds {
25111da177e4SLinus Torvalds 	struct compound_hdr hdr = {
251266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25131da177e4SLinus Torvalds 	};
25141da177e4SLinus Torvalds 
25159f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25169f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25179f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25189f06c719SChuck Lever 	encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2519d017931cSAndy Adamson 			   &hdr);
2520d017931cSAndy Adamson 	encode_nops(&hdr);
25211da177e4SLinus Torvalds }
25221da177e4SLinus Torvalds 
25231da177e4SLinus Torvalds /*
25241da177e4SLinus Torvalds  * a STATFS request
25251da177e4SLinus Torvalds  */
25269f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
25279f06c719SChuck Lever 				const struct nfs4_statfs_arg *args)
25281da177e4SLinus Torvalds {
25291da177e4SLinus Torvalds 	struct compound_hdr hdr = {
253066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25311da177e4SLinus Torvalds 	};
25321da177e4SLinus Torvalds 
25339f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25349f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25359f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25369f06c719SChuck Lever 	encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2537d017931cSAndy Adamson 			   args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2538d017931cSAndy Adamson 	encode_nops(&hdr);
25391da177e4SLinus Torvalds }
25401da177e4SLinus Torvalds 
25411da177e4SLinus Torvalds /*
25421da177e4SLinus Torvalds  * GETATTR_BITMAP request
25431da177e4SLinus Torvalds  */
25449f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
25459f06c719SChuck Lever 				     struct xdr_stream *xdr,
254643652ad5SBenny Halevy 				     struct nfs4_server_caps_arg *args)
25471da177e4SLinus Torvalds {
25481da177e4SLinus Torvalds 	struct compound_hdr hdr = {
254966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25501da177e4SLinus Torvalds 	};
25511da177e4SLinus Torvalds 
25529f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25539f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25549f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
25559f06c719SChuck Lever 	encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2556264e6351SChuck Lever 			   FATTR4_WORD0_FH_EXPIRE_TYPE|
25571da177e4SLinus Torvalds 			   FATTR4_WORD0_LINK_SUPPORT|
25581da177e4SLinus Torvalds 			   FATTR4_WORD0_SYMLINK_SUPPORT|
2559d017931cSAndy Adamson 			   FATTR4_WORD0_ACLSUPPORT, &hdr);
2560d017931cSAndy Adamson 	encode_nops(&hdr);
25611da177e4SLinus Torvalds }
25621da177e4SLinus Torvalds 
25631da177e4SLinus Torvalds /*
25641da177e4SLinus Torvalds  * a RENEW request
25651da177e4SLinus Torvalds  */
25669f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
25679f06c719SChuck Lever 			       struct nfs_client *clp)
25681da177e4SLinus Torvalds {
25691da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2570d017931cSAndy Adamson 		.nops	= 0,
25711da177e4SLinus Torvalds 	};
25721da177e4SLinus Torvalds 
25739f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2574bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2575d017931cSAndy Adamson 	encode_nops(&hdr);
25761da177e4SLinus Torvalds }
25771da177e4SLinus Torvalds 
25781da177e4SLinus Torvalds /*
25791da177e4SLinus Torvalds  * a SETCLIENTID request
25801da177e4SLinus Torvalds  */
25819f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
25829f06c719SChuck Lever 				     struct xdr_stream *xdr,
25839f06c719SChuck Lever 				     struct nfs4_setclientid *sc)
25841da177e4SLinus Torvalds {
25851da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2586d017931cSAndy Adamson 		.nops	= 0,
25871da177e4SLinus Torvalds 	};
25881da177e4SLinus Torvalds 
25899f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25909f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2591d017931cSAndy Adamson 	encode_nops(&hdr);
25921da177e4SLinus Torvalds }
25931da177e4SLinus Torvalds 
25941da177e4SLinus Torvalds /*
25951da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
25961da177e4SLinus Torvalds  */
25979f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
25989f06c719SChuck Lever 					     struct xdr_stream *xdr,
25999f06c719SChuck Lever 					     struct nfs4_setclientid_res *arg)
26001da177e4SLinus Torvalds {
26011da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2602d017931cSAndy Adamson 		.nops	= 0,
26031da177e4SLinus Torvalds 	};
2604dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
26051da177e4SLinus Torvalds 
26069f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26079f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
26089f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
26099f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
2610d017931cSAndy Adamson 	encode_nops(&hdr);
26111da177e4SLinus Torvalds }
26121da177e4SLinus Torvalds 
26131da177e4SLinus Torvalds /*
26141da177e4SLinus Torvalds  * DELEGRETURN request
26151da177e4SLinus Torvalds  */
26169f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
26179f06c719SChuck Lever 				     struct xdr_stream *xdr,
26189f06c719SChuck Lever 				     const struct nfs4_delegreturnargs *args)
26191da177e4SLinus Torvalds {
26201da177e4SLinus Torvalds 	struct compound_hdr hdr = {
262166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26221da177e4SLinus Torvalds 	};
26231da177e4SLinus Torvalds 
26249f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26259f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26269f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
26279f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2628e144cbccSTrond Myklebust 	encode_delegreturn(xdr, args->stateid, &hdr);
2629d017931cSAndy Adamson 	encode_nops(&hdr);
26301da177e4SLinus Torvalds }
26311da177e4SLinus Torvalds 
26321da177e4SLinus Torvalds /*
2633683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2634683b57b4STrond Myklebust  */
26359f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
26369f06c719SChuck Lever 				      struct xdr_stream *xdr,
26379f06c719SChuck Lever 				      struct nfs4_fs_locations_arg *args)
2638683b57b4STrond Myklebust {
2639683b57b4STrond Myklebust 	struct compound_hdr hdr = {
264066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2641683b57b4STrond Myklebust 	};
264228f56694SBenny Halevy 	uint32_t replen;
2643683b57b4STrond Myklebust 
26449f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26459f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26469f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
26479f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
264828f56694SBenny Halevy 	replen = hdr.replen;	/* get the attribute into args->page */
26499f06c719SChuck Lever 	encode_fs_locations(xdr, args->bitmask, &hdr);
2650cf8cdbe5SAndy Adamson 
265128f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2652683b57b4STrond Myklebust 			0, PAGE_SIZE);
2653d017931cSAndy Adamson 	encode_nops(&hdr);
2654683b57b4STrond Myklebust }
2655683b57b4STrond Myklebust 
26565a5ea0d4SBryan Schumaker /*
26575a5ea0d4SBryan Schumaker  * Encode SECINFO request
26585a5ea0d4SBryan Schumaker  */
26595a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
26605a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
26615a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_arg *args)
26625a5ea0d4SBryan Schumaker {
26635a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
26645a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26655a5ea0d4SBryan Schumaker 	};
26665a5ea0d4SBryan Schumaker 
26675a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
26685a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
26695a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
26705a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
26715a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
26725a5ea0d4SBryan Schumaker }
26735a5ea0d4SBryan Schumaker 
267499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
267599fe60d0SBenny Halevy /*
26767c44f1aeSWeston Andros Adamson  * BIND_CONN_TO_SESSION request
26777c44f1aeSWeston Andros Adamson  */
26787c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
26797c44f1aeSWeston Andros Adamson 				struct xdr_stream *xdr,
26807c44f1aeSWeston Andros Adamson 				struct nfs_client *clp)
26817c44f1aeSWeston Andros Adamson {
26827c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr = {
26837c44f1aeSWeston Andros Adamson 		.minorversion = clp->cl_mvops->minor_version,
26847c44f1aeSWeston Andros Adamson 	};
26857c44f1aeSWeston Andros Adamson 
26867c44f1aeSWeston Andros Adamson 	encode_compound_hdr(xdr, req, &hdr);
26877c44f1aeSWeston Andros Adamson 	encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
26887c44f1aeSWeston Andros Adamson 	encode_nops(&hdr);
26897c44f1aeSWeston Andros Adamson }
26907c44f1aeSWeston Andros Adamson 
26917c44f1aeSWeston Andros Adamson /*
269299fe60d0SBenny Halevy  * EXCHANGE_ID request
269399fe60d0SBenny Halevy  */
26949f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
26959f06c719SChuck Lever 				     struct xdr_stream *xdr,
269699fe60d0SBenny Halevy 				     struct nfs41_exchange_id_args *args)
269799fe60d0SBenny Halevy {
269899fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2699a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
270099fe60d0SBenny Halevy 	};
270199fe60d0SBenny Halevy 
27029f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27039f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
270499fe60d0SBenny Halevy 	encode_nops(&hdr);
270599fe60d0SBenny Halevy }
27062050f0ccSAndy Adamson 
27072050f0ccSAndy Adamson /*
2708fc931582SAndy Adamson  * a CREATE_SESSION request
2709fc931582SAndy Adamson  */
27109f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
27119f06c719SChuck Lever 					struct xdr_stream *xdr,
2712fc931582SAndy Adamson 					struct nfs41_create_session_args *args)
2713fc931582SAndy Adamson {
2714fc931582SAndy Adamson 	struct compound_hdr hdr = {
2715a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2716fc931582SAndy Adamson 	};
2717fc931582SAndy Adamson 
27189f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27199f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2720fc931582SAndy Adamson 	encode_nops(&hdr);
2721fc931582SAndy Adamson }
2722fc931582SAndy Adamson 
2723fc931582SAndy Adamson /*
27240f3e66c6SAndy Adamson  * a DESTROY_SESSION request
27250f3e66c6SAndy Adamson  */
27269f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
27279f06c719SChuck Lever 					 struct xdr_stream *xdr,
27280f3e66c6SAndy Adamson 					 struct nfs4_session *session)
27290f3e66c6SAndy Adamson {
27300f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2731a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
27320f3e66c6SAndy Adamson 	};
27330f3e66c6SAndy Adamson 
27349f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27359f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
27360f3e66c6SAndy Adamson 	encode_nops(&hdr);
27370f3e66c6SAndy Adamson }
27380f3e66c6SAndy Adamson 
27390f3e66c6SAndy Adamson /*
274066245539STrond Myklebust  * a DESTROY_CLIENTID request
274166245539STrond Myklebust  */
274266245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
274366245539STrond Myklebust 					 struct xdr_stream *xdr,
274466245539STrond Myklebust 					 struct nfs_client *clp)
274566245539STrond Myklebust {
274666245539STrond Myklebust 	struct compound_hdr hdr = {
274766245539STrond Myklebust 		.minorversion = clp->cl_mvops->minor_version,
274866245539STrond Myklebust 	};
274966245539STrond Myklebust 
275066245539STrond Myklebust 	encode_compound_hdr(xdr, req, &hdr);
275166245539STrond Myklebust 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
275266245539STrond Myklebust 	encode_nops(&hdr);
275366245539STrond Myklebust }
275466245539STrond Myklebust 
275566245539STrond Myklebust /*
2756fc01cea9SAndy Adamson  * a SEQUENCE request
2757fc01cea9SAndy Adamson  */
27589f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2759fc01cea9SAndy Adamson 				  struct nfs4_sequence_args *args)
2760fc01cea9SAndy Adamson {
2761fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2762fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2763fc01cea9SAndy Adamson 	};
2764fc01cea9SAndy Adamson 
27659f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27669f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2767fc01cea9SAndy Adamson 	encode_nops(&hdr);
2768fc01cea9SAndy Adamson }
2769fc01cea9SAndy Adamson 
2770fc01cea9SAndy Adamson /*
27712050f0ccSAndy Adamson  * a GET_LEASE_TIME request
27722050f0ccSAndy Adamson  */
27739f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
27749f06c719SChuck Lever 					struct xdr_stream *xdr,
27752050f0ccSAndy Adamson 					struct nfs4_get_lease_time_args *args)
27762050f0ccSAndy Adamson {
27772050f0ccSAndy Adamson 	struct compound_hdr hdr = {
27782050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
27792050f0ccSAndy Adamson 	};
2780dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
27812050f0ccSAndy Adamson 
27829f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27839f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
27849f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
27859f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
27862050f0ccSAndy Adamson 	encode_nops(&hdr);
27872050f0ccSAndy Adamson }
278818019753SRicardo Labiaga 
278918019753SRicardo Labiaga /*
279018019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
279118019753SRicardo Labiaga  */
27929f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
27939f06c719SChuck Lever 					  struct xdr_stream *xdr,
279418019753SRicardo Labiaga 				struct nfs41_reclaim_complete_args *args)
279518019753SRicardo Labiaga {
279618019753SRicardo Labiaga 	struct compound_hdr hdr = {
279718019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
279818019753SRicardo Labiaga 	};
279918019753SRicardo Labiaga 
28009f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28019f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28029f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
280318019753SRicardo Labiaga 	encode_nops(&hdr);
280418019753SRicardo Labiaga }
280518019753SRicardo Labiaga 
2806b1f69b75SAndy Adamson /*
28077f11d8d3SAndy Adamson  * Encode GETDEVICELIST request
28087f11d8d3SAndy Adamson  */
28097f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
28107f11d8d3SAndy Adamson 				       struct xdr_stream *xdr,
28117f11d8d3SAndy Adamson 				       struct nfs4_getdevicelist_args *args)
28127f11d8d3SAndy Adamson {
28137f11d8d3SAndy Adamson 	struct compound_hdr hdr = {
28147f11d8d3SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
28157f11d8d3SAndy Adamson 	};
28167f11d8d3SAndy Adamson 
28177f11d8d3SAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
28187f11d8d3SAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
28197f11d8d3SAndy Adamson 	encode_putfh(xdr, args->fh, &hdr);
28207f11d8d3SAndy Adamson 	encode_getdevicelist(xdr, args, &hdr);
28217f11d8d3SAndy Adamson 	encode_nops(&hdr);
28227f11d8d3SAndy Adamson }
28237f11d8d3SAndy Adamson 
28247f11d8d3SAndy Adamson /*
2825b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
2826b1f69b75SAndy Adamson  */
28279f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
28289f06c719SChuck Lever 				       struct xdr_stream *xdr,
2829b1f69b75SAndy Adamson 				       struct nfs4_getdeviceinfo_args *args)
2830b1f69b75SAndy Adamson {
2831b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2832b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2833b1f69b75SAndy Adamson 	};
2834b1f69b75SAndy Adamson 
28359f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28369f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28379f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
2838b1f69b75SAndy Adamson 
2839b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
2840b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
2841b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2842b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
2843b1f69b75SAndy Adamson 			 args->pdev->pglen);
2844b1f69b75SAndy Adamson 
2845b1f69b75SAndy Adamson 	encode_nops(&hdr);
2846b1f69b75SAndy Adamson }
2847b1f69b75SAndy Adamson 
2848b1f69b75SAndy Adamson /*
2849b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
2850b1f69b75SAndy Adamson  */
28519f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
28529f06c719SChuck Lever 				   struct xdr_stream *xdr,
2853b1f69b75SAndy Adamson 				   struct nfs4_layoutget_args *args)
2854b1f69b75SAndy Adamson {
2855b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2856b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2857b1f69b75SAndy Adamson 	};
2858b1f69b75SAndy Adamson 
28599f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28609f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28619f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
28629f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
286335124a09SWeston Andros Adamson 
286435124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
286535124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
286635124a09SWeston Andros Adamson 
2867b1f69b75SAndy Adamson 	encode_nops(&hdr);
2868b1f69b75SAndy Adamson }
2869863a3c6cSAndy Adamson 
2870863a3c6cSAndy Adamson /*
2871863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
2872863a3c6cSAndy Adamson  */
2873cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2874863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
2875863a3c6cSAndy Adamson 				      struct nfs4_layoutcommit_args *args)
2876863a3c6cSAndy Adamson {
2877ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
2878ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
2879863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
2880863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2881863a3c6cSAndy Adamson 	};
2882863a3c6cSAndy Adamson 
2883863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
2884863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
2885863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2886ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2887863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
2888863a3c6cSAndy Adamson 	encode_nops(&hdr);
2889cbe82603SBenny Halevy }
2890cbe82603SBenny Halevy 
2891cbe82603SBenny Halevy /*
2892cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
2893cbe82603SBenny Halevy  */
2894cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2895cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
2896cbe82603SBenny Halevy 				      struct nfs4_layoutreturn_args *args)
2897cbe82603SBenny Halevy {
2898cbe82603SBenny Halevy 	struct compound_hdr hdr = {
2899cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2900cbe82603SBenny Halevy 	};
2901cbe82603SBenny Halevy 
2902cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
2903cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
2904cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2905cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
2906cbe82603SBenny Halevy 	encode_nops(&hdr);
2907863a3c6cSAndy Adamson }
2908fca78d6dSBryan Schumaker 
2909fca78d6dSBryan Schumaker /*
2910fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
2911fca78d6dSBryan Schumaker  */
2912fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2913fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
2914fca78d6dSBryan Schumaker 					struct nfs41_secinfo_no_name_args *args)
2915fca78d6dSBryan Schumaker {
2916fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
2917fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2918fca78d6dSBryan Schumaker 	};
2919fca78d6dSBryan Schumaker 
2920fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
2921fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
2922fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
2923fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
2924fca78d6dSBryan Schumaker 	encode_nops(&hdr);
2925fca78d6dSBryan Schumaker 	return 0;
2926fca78d6dSBryan Schumaker }
29277d974794SBryan Schumaker 
29287d974794SBryan Schumaker /*
29297d974794SBryan Schumaker  *  Encode TEST_STATEID request
29307d974794SBryan Schumaker  */
29317d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
29327d974794SBryan Schumaker 				      struct xdr_stream *xdr,
29337d974794SBryan Schumaker 				      struct nfs41_test_stateid_args *args)
29347d974794SBryan Schumaker {
29357d974794SBryan Schumaker 	struct compound_hdr hdr = {
29367d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
29377d974794SBryan Schumaker 	};
29387d974794SBryan Schumaker 
29397d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
29407d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
29417d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
29427d974794SBryan Schumaker 	encode_nops(&hdr);
29437d974794SBryan Schumaker }
29449aeda35fSBryan Schumaker 
29459aeda35fSBryan Schumaker /*
29469aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
29479aeda35fSBryan Schumaker  */
29489aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
29499aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
29509aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_args *args)
29519aeda35fSBryan Schumaker {
29529aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
29539aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
29549aeda35fSBryan Schumaker 	};
29559aeda35fSBryan Schumaker 
29569aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
29579aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
29589aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
29599aeda35fSBryan Schumaker 	encode_nops(&hdr);
29609aeda35fSBryan Schumaker }
296199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
296299fe60d0SBenny Halevy 
2963686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2964686841b3SBenny Halevy {
2965686841b3SBenny Halevy 	dprintk("nfs: %s: prematurely hit end of receive buffer. "
2966686841b3SBenny Halevy 		"Remaining buffer length is %tu words.\n",
2967686841b3SBenny Halevy 		func, xdr->end - xdr->p);
2968686841b3SBenny Halevy }
29691da177e4SLinus Torvalds 
2970683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
29711da177e4SLinus Torvalds {
29728687b63aSAl Viro 	__be32 *p;
29731da177e4SLinus Torvalds 
2974c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
2975c0eae66eSBenny Halevy 	if (unlikely(!p))
2976c0eae66eSBenny Halevy 		goto out_overflow;
2977cccddf4fSBenny Halevy 	*len = be32_to_cpup(p);
2978c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, *len);
2979c0eae66eSBenny Halevy 	if (unlikely(!p))
2980c0eae66eSBenny Halevy 		goto out_overflow;
29811da177e4SLinus Torvalds 	*string = (char *)p;
29821da177e4SLinus Torvalds 	return 0;
2983c0eae66eSBenny Halevy out_overflow:
2984c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
2985c0eae66eSBenny Halevy 	return -EIO;
29861da177e4SLinus Torvalds }
29871da177e4SLinus Torvalds 
29881da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
29891da177e4SLinus Torvalds {
29908687b63aSAl Viro 	__be32 *p;
29911da177e4SLinus Torvalds 
2992c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
2993c0eae66eSBenny Halevy 	if (unlikely(!p))
2994c0eae66eSBenny Halevy 		goto out_overflow;
29956f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
2996cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
29971da177e4SLinus Torvalds 
2998c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
2999c0eae66eSBenny Halevy 	if (unlikely(!p))
3000c0eae66eSBenny Halevy 		goto out_overflow;
30011da177e4SLinus Torvalds 	hdr->tag = (char *)p;
30021da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3003cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3004aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3005aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
30061da177e4SLinus Torvalds 	return 0;
3007c0eae66eSBenny Halevy out_overflow:
3008c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3009c0eae66eSBenny Halevy 	return -EIO;
30101da177e4SLinus Torvalds }
30111da177e4SLinus Torvalds 
30121da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
30131da177e4SLinus Torvalds {
30148687b63aSAl Viro 	__be32 *p;
30151da177e4SLinus Torvalds 	uint32_t opnum;
30161da177e4SLinus Torvalds 	int32_t nfserr;
30171da177e4SLinus Torvalds 
3018c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3019c0eae66eSBenny Halevy 	if (unlikely(!p))
3020c0eae66eSBenny Halevy 		goto out_overflow;
30216f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
30221da177e4SLinus Torvalds 	if (opnum != expected) {
3023fe82a183SChuck Lever 		dprintk("nfs: Server returned operation"
30241da177e4SLinus Torvalds 			" %d but we issued a request for %d\n",
30251da177e4SLinus Torvalds 				opnum, expected);
30261da177e4SLinus Torvalds 		return -EIO;
30271da177e4SLinus Torvalds 	}
3028cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
30291da177e4SLinus Torvalds 	if (nfserr != NFS_OK)
3030856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
30311da177e4SLinus Torvalds 	return 0;
3032c0eae66eSBenny Halevy out_overflow:
3033c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3034c0eae66eSBenny Halevy 	return -EIO;
30351da177e4SLinus Torvalds }
30361da177e4SLinus Torvalds 
30371da177e4SLinus Torvalds /* Dummy routine */
3038adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
30391da177e4SLinus Torvalds {
30408687b63aSAl Viro 	__be32 *p;
3041683b57b4STrond Myklebust 	unsigned int strlen;
30421da177e4SLinus Torvalds 	char *str;
30431da177e4SLinus Torvalds 
3044c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3045c0eae66eSBenny Halevy 	if (likely(p))
30461da177e4SLinus Torvalds 		return decode_opaque_inline(xdr, &strlen, &str);
3047c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3048c0eae66eSBenny Halevy 	return -EIO;
30491da177e4SLinus Torvalds }
30501da177e4SLinus Torvalds 
30511da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
30521da177e4SLinus Torvalds {
30538687b63aSAl Viro 	uint32_t bmlen;
30548687b63aSAl Viro 	__be32 *p;
30551da177e4SLinus Torvalds 
3056c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3057c0eae66eSBenny Halevy 	if (unlikely(!p))
3058c0eae66eSBenny Halevy 		goto out_overflow;
3059cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
30601da177e4SLinus Torvalds 
3061dae100c2SFred Isaman 	bitmap[0] = bitmap[1] = bitmap[2] = 0;
3062c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, (bmlen << 2));
3063c0eae66eSBenny Halevy 	if (unlikely(!p))
3064c0eae66eSBenny Halevy 		goto out_overflow;
30651da177e4SLinus Torvalds 	if (bmlen > 0) {
30666f723f77SBenny Halevy 		bitmap[0] = be32_to_cpup(p++);
3067dae100c2SFred Isaman 		if (bmlen > 1) {
3068dae100c2SFred Isaman 			bitmap[1] = be32_to_cpup(p++);
3069dae100c2SFred Isaman 			if (bmlen > 2)
3070dae100c2SFred Isaman 				bitmap[2] = be32_to_cpup(p);
3071dae100c2SFred Isaman 		}
30721da177e4SLinus Torvalds 	}
30731da177e4SLinus Torvalds 	return 0;
3074c0eae66eSBenny Halevy out_overflow:
3075c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3076c0eae66eSBenny Halevy 	return -EIO;
30771da177e4SLinus Torvalds }
30781da177e4SLinus Torvalds 
3079256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
30801da177e4SLinus Torvalds {
30818687b63aSAl Viro 	__be32 *p;
30821da177e4SLinus Torvalds 
3083c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3084c0eae66eSBenny Halevy 	if (unlikely(!p))
3085c0eae66eSBenny Halevy 		goto out_overflow;
3086cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
3087256e48bbSTrond Myklebust 	*savep = xdr_stream_pos(xdr);
30881da177e4SLinus Torvalds 	return 0;
3089c0eae66eSBenny Halevy out_overflow:
3090c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3091c0eae66eSBenny Halevy 	return -EIO;
30921da177e4SLinus Torvalds }
30931da177e4SLinus Torvalds 
30941da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
30951da177e4SLinus Torvalds {
30961da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
30973388bff5SRoman Borisov 		int ret;
30983388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
30993388bff5SRoman Borisov 		if (unlikely(ret < 0))
31003388bff5SRoman Borisov 			return ret;
31011da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
31021da177e4SLinus Torvalds 	} else
3103dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3104dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3105dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
31061da177e4SLinus Torvalds 	return 0;
31071da177e4SLinus Torvalds }
31081da177e4SLinus Torvalds 
31091da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
31101da177e4SLinus Torvalds {
31118687b63aSAl Viro 	__be32 *p;
3112409924e4STrond Myklebust 	int ret = 0;
31131da177e4SLinus Torvalds 
31141da177e4SLinus Torvalds 	*type = 0;
31151da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
31161da177e4SLinus Torvalds 		return -EIO;
31171da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3118c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3119c0eae66eSBenny Halevy 		if (unlikely(!p))
3120c0eae66eSBenny Halevy 			goto out_overflow;
3121cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
31221da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
31233110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
31241da177e4SLinus Torvalds 			return -EIO;
31251da177e4SLinus Torvalds 		}
31261da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3127409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
31281da177e4SLinus Torvalds 	}
3129bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3130409924e4STrond Myklebust 	return ret;
3131c0eae66eSBenny Halevy out_overflow:
3132c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3133c0eae66eSBenny Halevy 	return -EIO;
31341da177e4SLinus Torvalds }
31351da177e4SLinus Torvalds 
3136264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3137264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3138264e6351SChuck Lever {
3139264e6351SChuck Lever 	__be32 *p;
3140264e6351SChuck Lever 
3141264e6351SChuck Lever 	*type = 0;
3142264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3143264e6351SChuck Lever 		return -EIO;
3144264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3145264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3146264e6351SChuck Lever 		if (unlikely(!p))
3147264e6351SChuck Lever 			goto out_overflow;
3148264e6351SChuck Lever 		*type = be32_to_cpup(p);
3149264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3150264e6351SChuck Lever 	}
3151264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3152264e6351SChuck Lever 	return 0;
3153264e6351SChuck Lever out_overflow:
3154264e6351SChuck Lever 	print_overflow_msg(__func__, xdr);
3155264e6351SChuck Lever 	return -EIO;
3156264e6351SChuck Lever }
3157264e6351SChuck Lever 
31581da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
31591da177e4SLinus Torvalds {
31608687b63aSAl Viro 	__be32 *p;
3161409924e4STrond Myklebust 	int ret = 0;
31621da177e4SLinus Torvalds 
31631da177e4SLinus Torvalds 	*change = 0;
31641da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
31651da177e4SLinus Torvalds 		return -EIO;
31661da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3167c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3168c0eae66eSBenny Halevy 		if (unlikely(!p))
3169c0eae66eSBenny Halevy 			goto out_overflow;
3170cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
31711da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3172409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
31731da177e4SLinus Torvalds 	}
31743110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
31751da177e4SLinus Torvalds 			(unsigned long long)*change);
3176409924e4STrond Myklebust 	return ret;
3177c0eae66eSBenny Halevy out_overflow:
3178c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3179c0eae66eSBenny Halevy 	return -EIO;
31801da177e4SLinus Torvalds }
31811da177e4SLinus Torvalds 
31821da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
31831da177e4SLinus Torvalds {
31848687b63aSAl Viro 	__be32 *p;
3185409924e4STrond Myklebust 	int ret = 0;
31861da177e4SLinus Torvalds 
31871da177e4SLinus Torvalds 	*size = 0;
31881da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
31891da177e4SLinus Torvalds 		return -EIO;
31901da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3191c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3192c0eae66eSBenny Halevy 		if (unlikely(!p))
3193c0eae66eSBenny Halevy 			goto out_overflow;
3194cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
31951da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3196409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
31971da177e4SLinus Torvalds 	}
31983110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3199409924e4STrond Myklebust 	return ret;
3200c0eae66eSBenny Halevy out_overflow:
3201c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3202c0eae66eSBenny Halevy 	return -EIO;
32031da177e4SLinus Torvalds }
32041da177e4SLinus Torvalds 
32051da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32061da177e4SLinus Torvalds {
32078687b63aSAl Viro 	__be32 *p;
32081da177e4SLinus Torvalds 
32091da177e4SLinus Torvalds 	*res = 0;
32101da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
32111da177e4SLinus Torvalds 		return -EIO;
32121da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3213c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3214c0eae66eSBenny Halevy 		if (unlikely(!p))
3215c0eae66eSBenny Halevy 			goto out_overflow;
3216cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
32171da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
32181da177e4SLinus Torvalds 	}
32193110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
32201da177e4SLinus Torvalds 	return 0;
3221c0eae66eSBenny Halevy out_overflow:
3222c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3223c0eae66eSBenny Halevy 	return -EIO;
32241da177e4SLinus Torvalds }
32251da177e4SLinus Torvalds 
32261da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32271da177e4SLinus Torvalds {
32288687b63aSAl Viro 	__be32 *p;
32291da177e4SLinus Torvalds 
32301da177e4SLinus Torvalds 	*res = 0;
32311da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
32321da177e4SLinus Torvalds 		return -EIO;
32331da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3234c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3235c0eae66eSBenny Halevy 		if (unlikely(!p))
3236c0eae66eSBenny Halevy 			goto out_overflow;
3237cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
32381da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
32391da177e4SLinus Torvalds 	}
32403110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
32411da177e4SLinus Torvalds 	return 0;
3242c0eae66eSBenny Halevy out_overflow:
3243c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3244c0eae66eSBenny Halevy 	return -EIO;
32451da177e4SLinus Torvalds }
32461da177e4SLinus Torvalds 
32478b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
32481da177e4SLinus Torvalds {
32498687b63aSAl Viro 	__be32 *p;
3250409924e4STrond Myklebust 	int ret = 0;
32511da177e4SLinus Torvalds 
32521da177e4SLinus Torvalds 	fsid->major = 0;
32531da177e4SLinus Torvalds 	fsid->minor = 0;
32541da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
32551da177e4SLinus Torvalds 		return -EIO;
32561da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3257c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3258c0eae66eSBenny Halevy 		if (unlikely(!p))
3259c0eae66eSBenny Halevy 			goto out_overflow;
32603ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3261cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
32621da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3263409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
32641da177e4SLinus Torvalds 	}
32653110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
32661da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
32671da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3268409924e4STrond Myklebust 	return ret;
3269c0eae66eSBenny Halevy out_overflow:
3270c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3271c0eae66eSBenny Halevy 	return -EIO;
32721da177e4SLinus Torvalds }
32731da177e4SLinus Torvalds 
32741da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32751da177e4SLinus Torvalds {
32768687b63aSAl Viro 	__be32 *p;
32771da177e4SLinus Torvalds 
32781da177e4SLinus Torvalds 	*res = 60;
32791da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
32801da177e4SLinus Torvalds 		return -EIO;
32811da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3282c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3283c0eae66eSBenny Halevy 		if (unlikely(!p))
3284c0eae66eSBenny Halevy 			goto out_overflow;
3285cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
32861da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
32871da177e4SLinus Torvalds 	}
32883110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
32891da177e4SLinus Torvalds 	return 0;
3290c0eae66eSBenny Halevy out_overflow:
3291c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3292c0eae66eSBenny Halevy 	return -EIO;
32931da177e4SLinus Torvalds }
32941da177e4SLinus Torvalds 
3295ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3296ae42c70aSBryan Schumaker {
3297ae42c70aSBryan Schumaker 	__be32 *p;
3298ae42c70aSBryan Schumaker 
3299ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3300ae42c70aSBryan Schumaker 		return -EIO;
3301ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3302ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3303ae42c70aSBryan Schumaker 		if (unlikely(!p))
3304ae42c70aSBryan Schumaker 			goto out_overflow;
3305ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3306ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3307ae42c70aSBryan Schumaker 	}
3308ae42c70aSBryan Schumaker 	return 0;
3309ae42c70aSBryan Schumaker out_overflow:
3310ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3311ae42c70aSBryan Schumaker 	return -EIO;
3312ae42c70aSBryan Schumaker }
3313ae42c70aSBryan Schumaker 
3314ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3315ae42c70aSBryan Schumaker {
3316ae42c70aSBryan Schumaker 	__be32 *p;
3317ae42c70aSBryan Schumaker 	int len;
3318ae42c70aSBryan Schumaker 
33197ad07353STrond Myklebust 	if (fh != NULL)
3320ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3321ae42c70aSBryan Schumaker 
3322ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3323ae42c70aSBryan Schumaker 		return -EIO;
3324ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3325ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3326ae42c70aSBryan Schumaker 		if (unlikely(!p))
3327ae42c70aSBryan Schumaker 			goto out_overflow;
3328ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3329ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3330ae42c70aSBryan Schumaker 			return -EIO;
3331ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3332ae42c70aSBryan Schumaker 		if (unlikely(!p))
3333ae42c70aSBryan Schumaker 			goto out_overflow;
33347ad07353STrond Myklebust 		if (fh != NULL) {
3335ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
33367ad07353STrond Myklebust 			fh->size = len;
33377ad07353STrond Myklebust 		}
3338ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3339ae42c70aSBryan Schumaker 	}
3340ae42c70aSBryan Schumaker 	return 0;
3341ae42c70aSBryan Schumaker out_overflow:
3342ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3343ae42c70aSBryan Schumaker 	return -EIO;
3344ae42c70aSBryan Schumaker }
3345ae42c70aSBryan Schumaker 
33461da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33471da177e4SLinus Torvalds {
33488687b63aSAl Viro 	__be32 *p;
33491da177e4SLinus Torvalds 
33501da177e4SLinus Torvalds 	*res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
33511da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
33521da177e4SLinus Torvalds 		return -EIO;
33531da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3354c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3355c0eae66eSBenny Halevy 		if (unlikely(!p))
3356c0eae66eSBenny Halevy 			goto out_overflow;
3357cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33581da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
33591da177e4SLinus Torvalds 	}
33603110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
33611da177e4SLinus Torvalds 	return 0;
3362c0eae66eSBenny Halevy out_overflow:
3363c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3364c0eae66eSBenny Halevy 	return -EIO;
33651da177e4SLinus Torvalds }
33661da177e4SLinus Torvalds 
33671da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
33681da177e4SLinus Torvalds {
33698687b63aSAl Viro 	__be32 *p;
3370409924e4STrond Myklebust 	int ret = 0;
33711da177e4SLinus Torvalds 
33721da177e4SLinus Torvalds 	*fileid = 0;
33731da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
33741da177e4SLinus Torvalds 		return -EIO;
33751da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3376c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3377c0eae66eSBenny Halevy 		if (unlikely(!p))
3378c0eae66eSBenny Halevy 			goto out_overflow;
3379cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
33801da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3381409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
33821da177e4SLinus Torvalds 	}
33833110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3384409924e4STrond Myklebust 	return ret;
3385c0eae66eSBenny Halevy out_overflow:
3386c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3387c0eae66eSBenny Halevy 	return -EIO;
33881da177e4SLinus Torvalds }
33891da177e4SLinus Torvalds 
339099baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
339199baf625SManoj Naik {
33928687b63aSAl Viro 	__be32 *p;
3393409924e4STrond Myklebust 	int ret = 0;
339499baf625SManoj Naik 
339599baf625SManoj Naik 	*fileid = 0;
339699baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
339799baf625SManoj Naik 		return -EIO;
339899baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3399c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3400c0eae66eSBenny Halevy 		if (unlikely(!p))
3401c0eae66eSBenny Halevy 			goto out_overflow;
3402cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
340399baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
340428331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
340599baf625SManoj Naik 	}
34063110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3407409924e4STrond Myklebust 	return ret;
3408c0eae66eSBenny Halevy out_overflow:
3409c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3410c0eae66eSBenny Halevy 	return -EIO;
341199baf625SManoj Naik }
341299baf625SManoj Naik 
34131da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
34141da177e4SLinus Torvalds {
34158687b63aSAl Viro 	__be32 *p;
34161da177e4SLinus Torvalds 	int status = 0;
34171da177e4SLinus Torvalds 
34181da177e4SLinus Torvalds 	*res = 0;
34191da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
34201da177e4SLinus Torvalds 		return -EIO;
34211da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3422c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3423c0eae66eSBenny Halevy 		if (unlikely(!p))
3424c0eae66eSBenny Halevy 			goto out_overflow;
3425cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
34261da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
34271da177e4SLinus Torvalds 	}
34283110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
34291da177e4SLinus Torvalds 	return status;
3430c0eae66eSBenny Halevy out_overflow:
3431c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3432c0eae66eSBenny Halevy 	return -EIO;
34331da177e4SLinus Torvalds }
34341da177e4SLinus Torvalds 
34351da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
34361da177e4SLinus Torvalds {
34378687b63aSAl Viro 	__be32 *p;
34381da177e4SLinus Torvalds 	int status = 0;
34391da177e4SLinus Torvalds 
34401da177e4SLinus Torvalds 	*res = 0;
34411da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
34421da177e4SLinus Torvalds 		return -EIO;
34431da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3444c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3445c0eae66eSBenny Halevy 		if (unlikely(!p))
3446c0eae66eSBenny Halevy 			goto out_overflow;
3447cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
34481da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
34491da177e4SLinus Torvalds 	}
34503110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
34511da177e4SLinus Torvalds 	return status;
3452c0eae66eSBenny Halevy out_overflow:
3453c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3454c0eae66eSBenny Halevy 	return -EIO;
34551da177e4SLinus Torvalds }
34561da177e4SLinus Torvalds 
34571da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
34581da177e4SLinus Torvalds {
34598687b63aSAl Viro 	__be32 *p;
34601da177e4SLinus Torvalds 	int status = 0;
34611da177e4SLinus Torvalds 
34621da177e4SLinus Torvalds 	*res = 0;
34631da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
34641da177e4SLinus Torvalds 		return -EIO;
34651da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3466c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3467c0eae66eSBenny Halevy 		if (unlikely(!p))
3468c0eae66eSBenny Halevy 			goto out_overflow;
3469cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
34701da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
34711da177e4SLinus Torvalds 	}
34723110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
34731da177e4SLinus Torvalds 	return status;
3474c0eae66eSBenny Halevy out_overflow:
3475c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3476c0eae66eSBenny Halevy 	return -EIO;
34771da177e4SLinus Torvalds }
34781da177e4SLinus Torvalds 
34797aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
34807aaa0b3bSManoj Naik {
3481464ad6b1SChuck Lever 	u32 n;
34828687b63aSAl Viro 	__be32 *p;
34837aaa0b3bSManoj Naik 	int status = 0;
34847aaa0b3bSManoj Naik 
3485c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3486c0eae66eSBenny Halevy 	if (unlikely(!p))
3487c0eae66eSBenny Halevy 		goto out_overflow;
3488cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
348933a43f28SAndy Adamson 	if (n == 0)
349033a43f28SAndy Adamson 		goto root_path;
349102a2976cSChuck Lever 	dprintk("pathname4: ");
34927aaa0b3bSManoj Naik 	path->ncomponents = 0;
34937aaa0b3bSManoj Naik 	while (path->ncomponents < n) {
34947aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
34957aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
34967aaa0b3bSManoj Naik 		if (unlikely(status != 0))
34977aaa0b3bSManoj Naik 			goto out_eio;
349895a13f7bSTrond Myklebust 		ifdebug (XDR)
349902a2976cSChuck Lever 			pr_cont("%s%.*s ",
350002a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
350102a2976cSChuck Lever 				component->len, component->data);
35027aaa0b3bSManoj Naik 		if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
35037aaa0b3bSManoj Naik 			path->ncomponents++;
35047aaa0b3bSManoj Naik 		else {
35057aaa0b3bSManoj Naik 			dprintk("cannot parse %d components in path\n", n);
35067aaa0b3bSManoj Naik 			goto out_eio;
35077aaa0b3bSManoj Naik 		}
35087aaa0b3bSManoj Naik 	}
35097aaa0b3bSManoj Naik out:
35107aaa0b3bSManoj Naik 	return status;
351133a43f28SAndy Adamson root_path:
351233a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
351333a43f28SAndy Adamson 	path->ncomponents = 1;
351433a43f28SAndy Adamson 	path->components[0].len=0;
351533a43f28SAndy Adamson 	path->components[0].data=NULL;
351602a2976cSChuck Lever 	dprintk("pathname4: /\n");
351733a43f28SAndy Adamson 	goto out;
35187aaa0b3bSManoj Naik out_eio:
35197aaa0b3bSManoj Naik 	dprintk(" status %d", status);
35207aaa0b3bSManoj Naik 	status = -EIO;
35217aaa0b3bSManoj Naik 	goto out;
3522c0eae66eSBenny Halevy out_overflow:
3523c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3524c0eae66eSBenny Halevy 	return -EIO;
35257aaa0b3bSManoj Naik }
35267aaa0b3bSManoj Naik 
35277aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3528683b57b4STrond Myklebust {
3529683b57b4STrond Myklebust 	int n;
35308687b63aSAl Viro 	__be32 *p;
3531683b57b4STrond Myklebust 	int status = -EIO;
3532683b57b4STrond Myklebust 
3533683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3534683b57b4STrond Myklebust 		goto out;
3535683b57b4STrond Myklebust 	status = 0;
3536683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3537683b57b4STrond Myklebust 		goto out;
35388b7e3f49STrond Myklebust 	status = -EIO;
35398b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
35408b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
35418b7e3f49STrond Myklebust 		goto out;
354202a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
35437aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3544683b57b4STrond Myklebust 	if (unlikely(status != 0))
3545683b57b4STrond Myklebust 		goto out;
3546c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3547c0eae66eSBenny Halevy 	if (unlikely(!p))
3548c0eae66eSBenny Halevy 		goto out_overflow;
3549cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3550683b57b4STrond Myklebust 	if (n <= 0)
3551683b57b4STrond Myklebust 		goto out_eio;
3552683b57b4STrond Myklebust 	res->nlocations = 0;
3553683b57b4STrond Myklebust 	while (res->nlocations < n) {
3554464ad6b1SChuck Lever 		u32 m;
35557aaa0b3bSManoj Naik 		struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3556683b57b4STrond Myklebust 
3557c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3558c0eae66eSBenny Halevy 		if (unlikely(!p))
3559c0eae66eSBenny Halevy 			goto out_overflow;
3560cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
35617aaa0b3bSManoj Naik 
35627aaa0b3bSManoj Naik 		loc->nservers = 0;
356302a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
35647aaa0b3bSManoj Naik 		while (loc->nservers < m) {
35657aaa0b3bSManoj Naik 			struct nfs4_string *server = &loc->servers[loc->nservers];
35667aaa0b3bSManoj Naik 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3567683b57b4STrond Myklebust 			if (unlikely(status != 0))
3568683b57b4STrond Myklebust 				goto out_eio;
35697aaa0b3bSManoj Naik 			dprintk("%s ", server->data);
35707aaa0b3bSManoj Naik 			if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
35717aaa0b3bSManoj Naik 				loc->nservers++;
35727aaa0b3bSManoj Naik 			else {
3573464ad6b1SChuck Lever 				unsigned int i;
3574464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3575464ad6b1SChuck Lever 					"returned for location %u\n",
35763110ff80SHarvey Harrison 						__func__,
3577464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3578464ad6b1SChuck Lever 						m, res->nlocations);
35797aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
35802e42c3e2STrond Myklebust 					unsigned int len;
35817aaa0b3bSManoj Naik 					char *data;
35827aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3583683b57b4STrond Myklebust 					if (unlikely(status != 0))
3584683b57b4STrond Myklebust 						goto out_eio;
35857aaa0b3bSManoj Naik 				}
35867aaa0b3bSManoj Naik 			}
35877aaa0b3bSManoj Naik 		}
35887aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
35897aaa0b3bSManoj Naik 		if (unlikely(status != 0))
35907aaa0b3bSManoj Naik 			goto out_eio;
35917aaa0b3bSManoj Naik 		if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3592683b57b4STrond Myklebust 			res->nlocations++;
3593683b57b4STrond Myklebust 	}
3594409924e4STrond Myklebust 	if (res->nlocations != 0)
359581934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3596683b57b4STrond Myklebust out:
35973110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3598683b57b4STrond Myklebust 	return status;
3599c0eae66eSBenny Halevy out_overflow:
3600c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3601683b57b4STrond Myklebust out_eio:
3602683b57b4STrond Myklebust 	status = -EIO;
3603683b57b4STrond Myklebust 	goto out;
3604683b57b4STrond Myklebust }
3605683b57b4STrond Myklebust 
36061da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36071da177e4SLinus Torvalds {
36088687b63aSAl Viro 	__be32 *p;
36091da177e4SLinus Torvalds 	int status = 0;
36101da177e4SLinus Torvalds 
36111da177e4SLinus Torvalds 	*res = 0;
36121da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
36131da177e4SLinus Torvalds 		return -EIO;
36141da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3615c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3616c0eae66eSBenny Halevy 		if (unlikely(!p))
3617c0eae66eSBenny Halevy 			goto out_overflow;
3618cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
36191da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
36201da177e4SLinus Torvalds 	}
36213110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
36221da177e4SLinus Torvalds 	return status;
3623c0eae66eSBenny Halevy out_overflow:
3624c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3625c0eae66eSBenny Halevy 	return -EIO;
36261da177e4SLinus Torvalds }
36271da177e4SLinus Torvalds 
36281da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
36291da177e4SLinus Torvalds {
36308687b63aSAl Viro 	__be32 *p;
36311da177e4SLinus Torvalds 	int status = 0;
36321da177e4SLinus Torvalds 
36331da177e4SLinus Torvalds 	*maxlink = 1;
36341da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
36351da177e4SLinus Torvalds 		return -EIO;
36361da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3637c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3638c0eae66eSBenny Halevy 		if (unlikely(!p))
3639c0eae66eSBenny Halevy 			goto out_overflow;
3640cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
36411da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
36421da177e4SLinus Torvalds 	}
36433110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
36441da177e4SLinus Torvalds 	return status;
3645c0eae66eSBenny Halevy out_overflow:
3646c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3647c0eae66eSBenny Halevy 	return -EIO;
36481da177e4SLinus Torvalds }
36491da177e4SLinus Torvalds 
36501da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
36511da177e4SLinus Torvalds {
36528687b63aSAl Viro 	__be32 *p;
36531da177e4SLinus Torvalds 	int status = 0;
36541da177e4SLinus Torvalds 
36551da177e4SLinus Torvalds 	*maxname = 1024;
36561da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
36571da177e4SLinus Torvalds 		return -EIO;
36581da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3659c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3660c0eae66eSBenny Halevy 		if (unlikely(!p))
3661c0eae66eSBenny Halevy 			goto out_overflow;
3662cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
36631da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
36641da177e4SLinus Torvalds 	}
36653110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
36661da177e4SLinus Torvalds 	return status;
3667c0eae66eSBenny Halevy out_overflow:
3668c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3669c0eae66eSBenny Halevy 	return -EIO;
36701da177e4SLinus Torvalds }
36711da177e4SLinus Torvalds 
36721da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
36731da177e4SLinus Torvalds {
36748687b63aSAl Viro 	__be32 *p;
36751da177e4SLinus Torvalds 	int status = 0;
36761da177e4SLinus Torvalds 
36771da177e4SLinus Torvalds 	*res = 1024;
36781da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
36791da177e4SLinus Torvalds 		return -EIO;
36801da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
36811da177e4SLinus Torvalds 		uint64_t maxread;
3682c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3683c0eae66eSBenny Halevy 		if (unlikely(!p))
3684c0eae66eSBenny Halevy 			goto out_overflow;
3685cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
36861da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
36871da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
36881da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
36891da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
36901da177e4SLinus Torvalds 	}
36913110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
36921da177e4SLinus Torvalds 	return status;
3693c0eae66eSBenny Halevy out_overflow:
3694c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3695c0eae66eSBenny Halevy 	return -EIO;
36961da177e4SLinus Torvalds }
36971da177e4SLinus Torvalds 
36981da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
36991da177e4SLinus Torvalds {
37008687b63aSAl Viro 	__be32 *p;
37011da177e4SLinus Torvalds 	int status = 0;
37021da177e4SLinus Torvalds 
37031da177e4SLinus Torvalds 	*res = 1024;
37041da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
37051da177e4SLinus Torvalds 		return -EIO;
37061da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
37071da177e4SLinus Torvalds 		uint64_t maxwrite;
3708c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3709c0eae66eSBenny Halevy 		if (unlikely(!p))
3710c0eae66eSBenny Halevy 			goto out_overflow;
3711cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
37121da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
37131da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
37141da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
37151da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
37161da177e4SLinus Torvalds 	}
37173110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
37181da177e4SLinus Torvalds 	return status;
3719c0eae66eSBenny Halevy out_overflow:
3720c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3721c0eae66eSBenny Halevy 	return -EIO;
37221da177e4SLinus Torvalds }
37231da177e4SLinus Torvalds 
3724bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
37251da177e4SLinus Torvalds {
3726bca79478STrond Myklebust 	uint32_t tmp;
37278687b63aSAl Viro 	__be32 *p;
3728409924e4STrond Myklebust 	int ret = 0;
37291da177e4SLinus Torvalds 
37301da177e4SLinus Torvalds 	*mode = 0;
37311da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
37321da177e4SLinus Torvalds 		return -EIO;
37331da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3734c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3735c0eae66eSBenny Halevy 		if (unlikely(!p))
3736c0eae66eSBenny Halevy 			goto out_overflow;
3737cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3738bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
37391da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3740409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
37411da177e4SLinus Torvalds 	}
37423110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3743409924e4STrond Myklebust 	return ret;
3744c0eae66eSBenny Halevy out_overflow:
3745c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3746c0eae66eSBenny Halevy 	return -EIO;
37471da177e4SLinus Torvalds }
37481da177e4SLinus Torvalds 
37491da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
37501da177e4SLinus Torvalds {
37518687b63aSAl Viro 	__be32 *p;
3752409924e4STrond Myklebust 	int ret = 0;
37531da177e4SLinus Torvalds 
37541da177e4SLinus Torvalds 	*nlink = 1;
37551da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
37561da177e4SLinus Torvalds 		return -EIO;
37571da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3758c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3759c0eae66eSBenny Halevy 		if (unlikely(!p))
3760c0eae66eSBenny Halevy 			goto out_overflow;
3761cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
37621da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3763409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
37641da177e4SLinus Torvalds 	}
37653110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3766409924e4STrond Myklebust 	return ret;
3767c0eae66eSBenny Halevy out_overflow:
3768c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3769c0eae66eSBenny Halevy 	return -EIO;
37701da177e4SLinus Torvalds }
37711da177e4SLinus Torvalds 
377280e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
37736926afd1STrond Myklebust 		const struct nfs_server *server, uint32_t *uid,
37746926afd1STrond Myklebust 		struct nfs4_string *owner_name)
37751da177e4SLinus Torvalds {
37768687b63aSAl Viro 	uint32_t len;
37778687b63aSAl Viro 	__be32 *p;
3778409924e4STrond Myklebust 	int ret = 0;
37791da177e4SLinus Torvalds 
37801da177e4SLinus Torvalds 	*uid = -2;
37811da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
37821da177e4SLinus Torvalds 		return -EIO;
37831da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3784c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3785c0eae66eSBenny Halevy 		if (unlikely(!p))
3786c0eae66eSBenny Halevy 			goto out_overflow;
3787cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3788c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3789c0eae66eSBenny Halevy 		if (unlikely(!p))
3790c0eae66eSBenny Halevy 			goto out_overflow;
37916926afd1STrond Myklebust 		if (owner_name != NULL) {
37926926afd1STrond Myklebust 			owner_name->data = kmemdup(p, len, GFP_NOWAIT);
37936926afd1STrond Myklebust 			if (owner_name->data != NULL) {
37946926afd1STrond Myklebust 				owner_name->len = len;
37956926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER_NAME;
37966926afd1STrond Myklebust 			}
379780e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3798e4fd72a1STrond Myklebust 			if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3799409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER;
3800409924e4STrond Myklebust 			else
38011da177e4SLinus Torvalds 				dprintk("%s: nfs_map_name_to_uid failed!\n",
38023110ff80SHarvey Harrison 						__func__);
38031da177e4SLinus Torvalds 		} else
3804fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
38053110ff80SHarvey Harrison 					__func__, len);
38061da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER;
38071da177e4SLinus Torvalds 	}
38083110ff80SHarvey Harrison 	dprintk("%s: uid=%d\n", __func__, (int)*uid);
3809409924e4STrond Myklebust 	return ret;
3810c0eae66eSBenny Halevy out_overflow:
3811c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3812c0eae66eSBenny Halevy 	return -EIO;
38131da177e4SLinus Torvalds }
38141da177e4SLinus Torvalds 
381580e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
38166926afd1STrond Myklebust 		const struct nfs_server *server, uint32_t *gid,
38176926afd1STrond Myklebust 		struct nfs4_string *group_name)
38181da177e4SLinus Torvalds {
38198687b63aSAl Viro 	uint32_t len;
38208687b63aSAl Viro 	__be32 *p;
3821409924e4STrond Myklebust 	int ret = 0;
38221da177e4SLinus Torvalds 
38231da177e4SLinus Torvalds 	*gid = -2;
38241da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
38251da177e4SLinus Torvalds 		return -EIO;
38261da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3827c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3828c0eae66eSBenny Halevy 		if (unlikely(!p))
3829c0eae66eSBenny Halevy 			goto out_overflow;
3830cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3831c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3832c0eae66eSBenny Halevy 		if (unlikely(!p))
3833c0eae66eSBenny Halevy 			goto out_overflow;
38346926afd1STrond Myklebust 		if (group_name != NULL) {
38356926afd1STrond Myklebust 			group_name->data = kmemdup(p, len, GFP_NOWAIT);
38366926afd1STrond Myklebust 			if (group_name->data != NULL) {
38376926afd1STrond Myklebust 				group_name->len = len;
38386926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP_NAME;
38396926afd1STrond Myklebust 			}
384080e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3841e4fd72a1STrond Myklebust 			if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3842409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP;
3843409924e4STrond Myklebust 			else
38441da177e4SLinus Torvalds 				dprintk("%s: nfs_map_group_to_gid failed!\n",
38453110ff80SHarvey Harrison 						__func__);
38461da177e4SLinus Torvalds 		} else
3847fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
38483110ff80SHarvey Harrison 					__func__, len);
38491da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
38501da177e4SLinus Torvalds 	}
38513110ff80SHarvey Harrison 	dprintk("%s: gid=%d\n", __func__, (int)*gid);
3852409924e4STrond Myklebust 	return ret;
3853c0eae66eSBenny Halevy out_overflow:
3854c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3855c0eae66eSBenny Halevy 	return -EIO;
38561da177e4SLinus Torvalds }
38571da177e4SLinus Torvalds 
38581da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
38591da177e4SLinus Torvalds {
38608687b63aSAl Viro 	uint32_t major = 0, minor = 0;
38618687b63aSAl Viro 	__be32 *p;
3862409924e4STrond Myklebust 	int ret = 0;
38631da177e4SLinus Torvalds 
38641da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
38651da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
38661da177e4SLinus Torvalds 		return -EIO;
38671da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
38681da177e4SLinus Torvalds 		dev_t tmp;
38691da177e4SLinus Torvalds 
3870c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3871c0eae66eSBenny Halevy 		if (unlikely(!p))
3872c0eae66eSBenny Halevy 			goto out_overflow;
38736f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3874cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
38751da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
38761da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
38771da177e4SLinus Torvalds 			*rdev = tmp;
38781da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3879409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
38801da177e4SLinus Torvalds 	}
38813110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3882409924e4STrond Myklebust 	return ret;
3883c0eae66eSBenny Halevy out_overflow:
3884c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3885c0eae66eSBenny Halevy 	return -EIO;
38861da177e4SLinus Torvalds }
38871da177e4SLinus Torvalds 
38881da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
38891da177e4SLinus Torvalds {
38908687b63aSAl Viro 	__be32 *p;
38911da177e4SLinus Torvalds 	int status = 0;
38921da177e4SLinus Torvalds 
38931da177e4SLinus Torvalds 	*res = 0;
38941da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
38951da177e4SLinus Torvalds 		return -EIO;
38961da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3897c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3898c0eae66eSBenny Halevy 		if (unlikely(!p))
3899c0eae66eSBenny Halevy 			goto out_overflow;
3900cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39011da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
39021da177e4SLinus Torvalds 	}
39033110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
39041da177e4SLinus Torvalds 	return status;
3905c0eae66eSBenny Halevy out_overflow:
3906c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3907c0eae66eSBenny Halevy 	return -EIO;
39081da177e4SLinus Torvalds }
39091da177e4SLinus Torvalds 
39101da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39111da177e4SLinus Torvalds {
39128687b63aSAl Viro 	__be32 *p;
39131da177e4SLinus Torvalds 	int status = 0;
39141da177e4SLinus Torvalds 
39151da177e4SLinus Torvalds 	*res = 0;
39161da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
39171da177e4SLinus Torvalds 		return -EIO;
39181da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3919c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3920c0eae66eSBenny Halevy 		if (unlikely(!p))
3921c0eae66eSBenny Halevy 			goto out_overflow;
3922cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39231da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
39241da177e4SLinus Torvalds 	}
39253110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
39261da177e4SLinus Torvalds 	return status;
3927c0eae66eSBenny Halevy out_overflow:
3928c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3929c0eae66eSBenny Halevy 	return -EIO;
39301da177e4SLinus Torvalds }
39311da177e4SLinus Torvalds 
39321da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39331da177e4SLinus Torvalds {
39348687b63aSAl Viro 	__be32 *p;
39351da177e4SLinus Torvalds 	int status = 0;
39361da177e4SLinus Torvalds 
39371da177e4SLinus Torvalds 	*res = 0;
39381da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
39391da177e4SLinus Torvalds 		return -EIO;
39401da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3941c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3942c0eae66eSBenny Halevy 		if (unlikely(!p))
3943c0eae66eSBenny Halevy 			goto out_overflow;
3944cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39451da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
39461da177e4SLinus Torvalds 	}
39473110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
39481da177e4SLinus Torvalds 	return status;
3949c0eae66eSBenny Halevy out_overflow:
3950c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3951c0eae66eSBenny Halevy 	return -EIO;
39521da177e4SLinus Torvalds }
39531da177e4SLinus Torvalds 
39541da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
39551da177e4SLinus Torvalds {
39568687b63aSAl Viro 	__be32 *p;
3957409924e4STrond Myklebust 	int ret = 0;
39581da177e4SLinus Torvalds 
39591da177e4SLinus Torvalds 	*used = 0;
39601da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
39611da177e4SLinus Torvalds 		return -EIO;
39621da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3963c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3964c0eae66eSBenny Halevy 		if (unlikely(!p))
3965c0eae66eSBenny Halevy 			goto out_overflow;
3966cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
39671da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3968409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
39691da177e4SLinus Torvalds 	}
39703110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
39711da177e4SLinus Torvalds 			(unsigned long long)*used);
3972409924e4STrond Myklebust 	return ret;
3973c0eae66eSBenny Halevy out_overflow:
3974c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3975c0eae66eSBenny Halevy 	return -EIO;
39761da177e4SLinus Torvalds }
39771da177e4SLinus Torvalds 
39781da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
39791da177e4SLinus Torvalds {
39808687b63aSAl Viro 	__be32 *p;
39811da177e4SLinus Torvalds 	uint64_t sec;
39821da177e4SLinus Torvalds 	uint32_t nsec;
39831da177e4SLinus Torvalds 
3984c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3985c0eae66eSBenny Halevy 	if (unlikely(!p))
3986c0eae66eSBenny Halevy 		goto out_overflow;
39873ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &sec);
3988cccddf4fSBenny Halevy 	nsec = be32_to_cpup(p);
39891da177e4SLinus Torvalds 	time->tv_sec = (time_t)sec;
39901da177e4SLinus Torvalds 	time->tv_nsec = (long)nsec;
39911da177e4SLinus Torvalds 	return 0;
3992c0eae66eSBenny Halevy out_overflow:
3993c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3994c0eae66eSBenny Halevy 	return -EIO;
39951da177e4SLinus Torvalds }
39961da177e4SLinus Torvalds 
39971da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
39981da177e4SLinus Torvalds {
39991da177e4SLinus Torvalds 	int status = 0;
40001da177e4SLinus Torvalds 
40011da177e4SLinus Torvalds 	time->tv_sec = 0;
40021da177e4SLinus Torvalds 	time->tv_nsec = 0;
40031da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
40041da177e4SLinus Torvalds 		return -EIO;
40051da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
40061da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4007409924e4STrond Myklebust 		if (status == 0)
4008409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
40091da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
40101da177e4SLinus Torvalds 	}
40113110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
40121da177e4SLinus Torvalds 	return status;
40131da177e4SLinus Torvalds }
40141da177e4SLinus Torvalds 
40151da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40161da177e4SLinus Torvalds {
40171da177e4SLinus Torvalds 	int status = 0;
40181da177e4SLinus Torvalds 
40191da177e4SLinus Torvalds 	time->tv_sec = 0;
40201da177e4SLinus Torvalds 	time->tv_nsec = 0;
40211da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
40221da177e4SLinus Torvalds 		return -EIO;
40231da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
40241da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4025409924e4STrond Myklebust 		if (status == 0)
4026409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
40271da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
40281da177e4SLinus Torvalds 	}
40293110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
40301da177e4SLinus Torvalds 	return status;
40311da177e4SLinus Torvalds }
40321da177e4SLinus Torvalds 
403355b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
403455b6e774SRicardo Labiaga 				  struct timespec *time)
403555b6e774SRicardo Labiaga {
403655b6e774SRicardo Labiaga 	int status = 0;
403755b6e774SRicardo Labiaga 
403855b6e774SRicardo Labiaga 	time->tv_sec = 0;
403955b6e774SRicardo Labiaga 	time->tv_nsec = 0;
404055b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
404155b6e774SRicardo Labiaga 		return -EIO;
404255b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
404355b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
404455b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
404555b6e774SRicardo Labiaga 	}
404655b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
404755b6e774SRicardo Labiaga 		(long)time->tv_nsec);
404855b6e774SRicardo Labiaga 	return status;
404955b6e774SRicardo Labiaga }
405055b6e774SRicardo Labiaga 
40511da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40521da177e4SLinus Torvalds {
40531da177e4SLinus Torvalds 	int status = 0;
40541da177e4SLinus Torvalds 
40551da177e4SLinus Torvalds 	time->tv_sec = 0;
40561da177e4SLinus Torvalds 	time->tv_nsec = 0;
40571da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
40581da177e4SLinus Torvalds 		return -EIO;
40591da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
40601da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4061409924e4STrond Myklebust 		if (status == 0)
4062409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
40631da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
40641da177e4SLinus Torvalds 	}
40653110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
40661da177e4SLinus Torvalds 	return status;
40671da177e4SLinus Torvalds }
40681da177e4SLinus Torvalds 
4069256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
40701da177e4SLinus Torvalds {
40711da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4072256e48bbSTrond Myklebust 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
40731da177e4SLinus Torvalds 
40741da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4075fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4076fe82a183SChuck Lever 			"%u %c %u\n",
40773110ff80SHarvey Harrison 				__func__,
40781da177e4SLinus Torvalds 				attrwords << 2,
40791da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
40801da177e4SLinus Torvalds 				nwords << 2);
40811da177e4SLinus Torvalds 		return -EIO;
40821da177e4SLinus Torvalds 	}
40831da177e4SLinus Torvalds 	return 0;
40841da177e4SLinus Torvalds }
40851da177e4SLinus Torvalds 
40861da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
40871da177e4SLinus Torvalds {
40888687b63aSAl Viro 	__be32 *p;
40891da177e4SLinus Torvalds 
4090c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4091c0eae66eSBenny Halevy 	if (unlikely(!p))
4092c0eae66eSBenny Halevy 		goto out_overflow;
40936f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
40943ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4095cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
40961da177e4SLinus Torvalds 	return 0;
4097c0eae66eSBenny Halevy out_overflow:
4098c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4099c0eae66eSBenny Halevy 	return -EIO;
41001da177e4SLinus Torvalds }
41011da177e4SLinus Torvalds 
41021da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
41031da177e4SLinus Torvalds {
41048687b63aSAl Viro 	__be32 *p;
41051da177e4SLinus Torvalds 	uint32_t supp, acc;
41061da177e4SLinus Torvalds 	int status;
41071da177e4SLinus Torvalds 
41081da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
41091da177e4SLinus Torvalds 	if (status)
41101da177e4SLinus Torvalds 		return status;
4111c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4112c0eae66eSBenny Halevy 	if (unlikely(!p))
4113c0eae66eSBenny Halevy 		goto out_overflow;
41146f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4115cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
41161da177e4SLinus Torvalds 	access->supported = supp;
41171da177e4SLinus Torvalds 	access->access = acc;
41181da177e4SLinus Torvalds 	return 0;
4119c0eae66eSBenny Halevy out_overflow:
4120c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4121c0eae66eSBenny Halevy 	return -EIO;
41221da177e4SLinus Torvalds }
41231da177e4SLinus Torvalds 
412407d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
41251da177e4SLinus Torvalds {
41268687b63aSAl Viro 	__be32 *p;
412707d30434SBenny Halevy 
412807d30434SBenny Halevy 	p = xdr_inline_decode(xdr, len);
412907d30434SBenny Halevy 	if (likely(p)) {
413007d30434SBenny Halevy 		memcpy(buf, p, len);
413107d30434SBenny Halevy 		return 0;
413207d30434SBenny Halevy 	}
413307d30434SBenny Halevy 	print_overflow_msg(__func__, xdr);
413407d30434SBenny Halevy 	return -EIO;
413507d30434SBenny Halevy }
413607d30434SBenny Halevy 
413707d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
413807d30434SBenny Halevy {
41392d2f24adSTrond Myklebust 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
41401da177e4SLinus Torvalds }
41411da177e4SLinus Torvalds 
41421da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
41431da177e4SLinus Torvalds {
41441da177e4SLinus Torvalds 	int status;
41451da177e4SLinus Torvalds 
41461da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4147c1d51931STrond Myklebust 	if (status != -EIO)
4148c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
414907d30434SBenny Halevy 	if (!status)
415007d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
41511da177e4SLinus Torvalds 	return status;
41521da177e4SLinus Torvalds }
41531da177e4SLinus Torvalds 
4154db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4155db942bbdSBenny Halevy {
4156cd93710eSChuck Lever 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
41571da177e4SLinus Torvalds }
41581da177e4SLinus Torvalds 
41592f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
41602f2c63bcSTrond Myklebust {
41612f2c63bcSTrond Myklebust 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
41622f2c63bcSTrond Myklebust }
41632f2c63bcSTrond Myklebust 
41640b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
41651da177e4SLinus Torvalds {
41661da177e4SLinus Torvalds 	int status;
41671da177e4SLinus Torvalds 
41681da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4169db942bbdSBenny Halevy 	if (!status)
41702f2c63bcSTrond Myklebust 		status = decode_write_verifier(xdr, &res->verf->verifier);
41711da177e4SLinus Torvalds 	return status;
41721da177e4SLinus Torvalds }
41731da177e4SLinus Torvalds 
41741da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
41751da177e4SLinus Torvalds {
41768687b63aSAl Viro 	__be32 *p;
41771da177e4SLinus Torvalds 	uint32_t bmlen;
41781da177e4SLinus Torvalds 	int status;
41791da177e4SLinus Torvalds 
41801da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
41811da177e4SLinus Torvalds 	if (status)
41821da177e4SLinus Torvalds 		return status;
41831da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
41841da177e4SLinus Torvalds 		return status;
4185c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4186c0eae66eSBenny Halevy 	if (unlikely(!p))
4187c0eae66eSBenny Halevy 		goto out_overflow;
4188cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4189c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4190c0eae66eSBenny Halevy 	if (likely(p))
41911da177e4SLinus Torvalds 		return 0;
4192c0eae66eSBenny Halevy out_overflow:
4193c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4194c0eae66eSBenny Halevy 	return -EIO;
41951da177e4SLinus Torvalds }
41961da177e4SLinus Torvalds 
41971da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
41981da177e4SLinus Torvalds {
4199256e48bbSTrond Myklebust 	unsigned int savep;
4200dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
42011da177e4SLinus Torvalds 	int status;
42021da177e4SLinus Torvalds 
42031da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
42041da177e4SLinus Torvalds 		goto xdr_error;
42051da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
42061da177e4SLinus Torvalds 		goto xdr_error;
42071da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
42081da177e4SLinus Torvalds 		goto xdr_error;
42091da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
42101da177e4SLinus Torvalds 		goto xdr_error;
4211264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4212264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4213264e6351SChuck Lever 		goto xdr_error;
42141da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
42151da177e4SLinus Torvalds 		goto xdr_error;
42161da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
42171da177e4SLinus Torvalds 		goto xdr_error;
42181da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
42191da177e4SLinus Torvalds 		goto xdr_error;
42201da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
42211da177e4SLinus Torvalds xdr_error:
42223110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
42231da177e4SLinus Torvalds 	return status;
42241da177e4SLinus Torvalds }
42251da177e4SLinus Torvalds 
42261da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
42271da177e4SLinus Torvalds {
4228256e48bbSTrond Myklebust 	unsigned int savep;
4229dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
42301da177e4SLinus Torvalds 	int status;
42311da177e4SLinus Torvalds 
42321da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
42331da177e4SLinus Torvalds 		goto xdr_error;
42341da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
42351da177e4SLinus Torvalds 		goto xdr_error;
42361da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
42371da177e4SLinus Torvalds 		goto xdr_error;
42381da177e4SLinus Torvalds 
42391da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
42401da177e4SLinus Torvalds 		goto xdr_error;
42411da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
42421da177e4SLinus Torvalds 		goto xdr_error;
42431da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
42441da177e4SLinus Torvalds 		goto xdr_error;
42451da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
42461da177e4SLinus Torvalds 		goto xdr_error;
42471da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
42481da177e4SLinus Torvalds 		goto xdr_error;
42491da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
42501da177e4SLinus Torvalds 		goto xdr_error;
42511da177e4SLinus Torvalds 
42521da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
42531da177e4SLinus Torvalds xdr_error:
42543110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
42551da177e4SLinus Torvalds 	return status;
42561da177e4SLinus Torvalds }
42571da177e4SLinus Torvalds 
42581da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
42591da177e4SLinus Torvalds {
4260256e48bbSTrond Myklebust 	unsigned int savep;
4261dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
42621da177e4SLinus Torvalds 	int status;
42631da177e4SLinus Torvalds 
42641da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
42651da177e4SLinus Torvalds 		goto xdr_error;
42661da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
42671da177e4SLinus Torvalds 		goto xdr_error;
42681da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
42691da177e4SLinus Torvalds 		goto xdr_error;
42701da177e4SLinus Torvalds 
42711da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
42721da177e4SLinus Torvalds 		goto xdr_error;
42731da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
42741da177e4SLinus Torvalds 		goto xdr_error;
42751da177e4SLinus Torvalds 
42761da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
42771da177e4SLinus Torvalds xdr_error:
42783110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
42791da177e4SLinus Torvalds 	return status;
42801da177e4SLinus Torvalds }
42811da177e4SLinus Torvalds 
428288034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
428388034c3dSAndy Adamson 				  uint32_t *bitmap,
428488034c3dSAndy Adamson 				  uint64_t *res,
428588034c3dSAndy Adamson 				  uint32_t hint_bit)
428688034c3dSAndy Adamson {
428788034c3dSAndy Adamson 	__be32 *p;
428888034c3dSAndy Adamson 
428988034c3dSAndy Adamson 	*res = 0;
429088034c3dSAndy Adamson 	if (likely(bitmap[0] & hint_bit)) {
429188034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
429288034c3dSAndy Adamson 		if (unlikely(!p))
429388034c3dSAndy Adamson 			goto out_overflow;
429488034c3dSAndy Adamson 		xdr_decode_hyper(p, res);
429588034c3dSAndy Adamson 	}
429688034c3dSAndy Adamson 	return 0;
429788034c3dSAndy Adamson out_overflow:
429888034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
429988034c3dSAndy Adamson 	return -EIO;
430088034c3dSAndy Adamson }
430188034c3dSAndy Adamson 
430288034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
430388034c3dSAndy Adamson 					struct nfs4_threshold *res)
430488034c3dSAndy Adamson {
4305256e48bbSTrond Myklebust 	__be32 *p;
4306256e48bbSTrond Myklebust 	unsigned int savep;
430788034c3dSAndy Adamson 	uint32_t bitmap[3] = {0,}, attrlen;
430888034c3dSAndy Adamson 	int status;
430988034c3dSAndy Adamson 
431088034c3dSAndy Adamson 	/* layout type */
431188034c3dSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
431288034c3dSAndy Adamson 	if (unlikely(!p)) {
431388034c3dSAndy Adamson 		print_overflow_msg(__func__, xdr);
431488034c3dSAndy Adamson 		return -EIO;
431588034c3dSAndy Adamson 	}
431688034c3dSAndy Adamson 	res->l_type = be32_to_cpup(p);
431788034c3dSAndy Adamson 
431888034c3dSAndy Adamson 	/* thi_hintset bitmap */
431988034c3dSAndy Adamson 	status = decode_attr_bitmap(xdr, bitmap);
432088034c3dSAndy Adamson 	if (status < 0)
432188034c3dSAndy Adamson 		goto xdr_error;
432288034c3dSAndy Adamson 
432388034c3dSAndy Adamson 	/* thi_hintlist length */
432488034c3dSAndy Adamson 	status = decode_attr_length(xdr, &attrlen, &savep);
432588034c3dSAndy Adamson 	if (status < 0)
432688034c3dSAndy Adamson 		goto xdr_error;
432788034c3dSAndy Adamson 	/* thi_hintlist */
432888034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
432988034c3dSAndy Adamson 	if (status < 0)
433088034c3dSAndy Adamson 		goto xdr_error;
433188034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
433288034c3dSAndy Adamson 	if (status < 0)
433388034c3dSAndy Adamson 		goto xdr_error;
433488034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
433588034c3dSAndy Adamson 				       THRESHOLD_RD_IO);
433688034c3dSAndy Adamson 	if (status < 0)
433788034c3dSAndy Adamson 		goto xdr_error;
433888034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
433988034c3dSAndy Adamson 				       THRESHOLD_WR_IO);
434088034c3dSAndy Adamson 	if (status < 0)
434188034c3dSAndy Adamson 		goto xdr_error;
434288034c3dSAndy Adamson 
434388034c3dSAndy Adamson 	status = verify_attr_len(xdr, savep, attrlen);
434488034c3dSAndy Adamson 	res->bm = bitmap[0];
434588034c3dSAndy Adamson 
434688034c3dSAndy Adamson 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
434788034c3dSAndy Adamson 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
434888034c3dSAndy Adamson 		res->wr_io_sz);
434988034c3dSAndy Adamson xdr_error:
435088034c3dSAndy Adamson 	dprintk("%s ret=%d!\n", __func__, status);
435188034c3dSAndy Adamson 	return status;
435288034c3dSAndy Adamson }
435388034c3dSAndy Adamson 
435488034c3dSAndy Adamson /*
435588034c3dSAndy Adamson  * Thresholds on pNFS direct I/O vrs MDS I/O
435688034c3dSAndy Adamson  */
435788034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
435888034c3dSAndy Adamson 				    uint32_t *bitmap,
435988034c3dSAndy Adamson 				    struct nfs4_threshold *res)
436088034c3dSAndy Adamson {
436188034c3dSAndy Adamson 	__be32 *p;
436288034c3dSAndy Adamson 	int status = 0;
436388034c3dSAndy Adamson 	uint32_t num;
436488034c3dSAndy Adamson 
436588034c3dSAndy Adamson 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
436688034c3dSAndy Adamson 		return -EIO;
4367029c5347STrond Myklebust 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
43681549210fSTrond Myklebust 		/* Did the server return an unrequested attribute? */
43691549210fSTrond Myklebust 		if (unlikely(res == NULL))
43701549210fSTrond Myklebust 			return -EREMOTEIO;
437188034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 4);
437288034c3dSAndy Adamson 		if (unlikely(!p))
437388034c3dSAndy Adamson 			goto out_overflow;
437488034c3dSAndy Adamson 		num = be32_to_cpup(p);
437588034c3dSAndy Adamson 		if (num == 0)
437688034c3dSAndy Adamson 			return 0;
437788034c3dSAndy Adamson 		if (num > 1)
437888034c3dSAndy Adamson 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
437988034c3dSAndy Adamson 				"drivers per filesystem not supported\n",
438088034c3dSAndy Adamson 				__func__);
438188034c3dSAndy Adamson 
438288034c3dSAndy Adamson 		status = decode_first_threshold_item4(xdr, res);
4383029c5347STrond Myklebust 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
438488034c3dSAndy Adamson 	}
438588034c3dSAndy Adamson 	return status;
438688034c3dSAndy Adamson out_overflow:
438788034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
438888034c3dSAndy Adamson 	return -EIO;
438988034c3dSAndy Adamson }
439088034c3dSAndy Adamson 
4391ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4392ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
43938b7e3f49STrond Myklebust 		struct nfs4_fs_locations *fs_loc,
43946926afd1STrond Myklebust 		const struct nfs_server *server)
43951da177e4SLinus Torvalds {
4396bca79478STrond Myklebust 	int status;
4397bca79478STrond Myklebust 	umode_t fmode = 0;
4398ae42c70aSBryan Schumaker 	uint32_t type;
4399ee7b75fcSTrond Myklebust 	int32_t err;
44001da177e4SLinus Torvalds 
4401f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4402f26c7a78STrond Myklebust 	if (status < 0)
44031da177e4SLinus Torvalds 		goto xdr_error;
4404409924e4STrond Myklebust 	fattr->mode = 0;
4405409924e4STrond Myklebust 	if (status != 0) {
4406409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4407409924e4STrond Myklebust 		fattr->valid |= status;
4408409924e4STrond Myklebust 	}
44091da177e4SLinus Torvalds 
4410f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4411f26c7a78STrond Myklebust 	if (status < 0)
44121da177e4SLinus Torvalds 		goto xdr_error;
4413409924e4STrond Myklebust 	fattr->valid |= status;
4414f26c7a78STrond Myklebust 
4415f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4416f26c7a78STrond Myklebust 	if (status < 0)
44171da177e4SLinus Torvalds 		goto xdr_error;
4418409924e4STrond Myklebust 	fattr->valid |= status;
4419f26c7a78STrond Myklebust 
4420f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4421f26c7a78STrond Myklebust 	if (status < 0)
44221da177e4SLinus Torvalds 		goto xdr_error;
4423409924e4STrond Myklebust 	fattr->valid |= status;
4424f26c7a78STrond Myklebust 
4425ee7b75fcSTrond Myklebust 	err = 0;
4426ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4427ae42c70aSBryan Schumaker 	if (status < 0)
4428ae42c70aSBryan Schumaker 		goto xdr_error;
4429ae42c70aSBryan Schumaker 
4430ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4431ae42c70aSBryan Schumaker 	if (status < 0)
4432ae42c70aSBryan Schumaker 		goto xdr_error;
4433ae42c70aSBryan Schumaker 
4434f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4435f26c7a78STrond Myklebust 	if (status < 0)
44361da177e4SLinus Torvalds 		goto xdr_error;
4437409924e4STrond Myklebust 	fattr->valid |= status;
4438f26c7a78STrond Myklebust 
44398b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4440f26c7a78STrond Myklebust 	if (status < 0)
4441683b57b4STrond Myklebust 		goto xdr_error;
4442409924e4STrond Myklebust 	fattr->valid |= status;
4443f26c7a78STrond Myklebust 
4444f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4445f26c7a78STrond Myklebust 	if (status < 0)
44461da177e4SLinus Torvalds 		goto xdr_error;
4447409924e4STrond Myklebust 	if (status != 0) {
44481da177e4SLinus Torvalds 		fattr->mode |= fmode;
4449409924e4STrond Myklebust 		fattr->valid |= status;
4450409924e4STrond Myklebust 	}
4451f26c7a78STrond Myklebust 
4452f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4453f26c7a78STrond Myklebust 	if (status < 0)
44541da177e4SLinus Torvalds 		goto xdr_error;
4455409924e4STrond Myklebust 	fattr->valid |= status;
4456f26c7a78STrond Myklebust 
44576926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4458f26c7a78STrond Myklebust 	if (status < 0)
44591da177e4SLinus Torvalds 		goto xdr_error;
4460409924e4STrond Myklebust 	fattr->valid |= status;
4461f26c7a78STrond Myklebust 
44626926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4463f26c7a78STrond Myklebust 	if (status < 0)
44641da177e4SLinus Torvalds 		goto xdr_error;
4465409924e4STrond Myklebust 	fattr->valid |= status;
4466f26c7a78STrond Myklebust 
4467f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4468f26c7a78STrond Myklebust 	if (status < 0)
44691da177e4SLinus Torvalds 		goto xdr_error;
4470409924e4STrond Myklebust 	fattr->valid |= status;
4471f26c7a78STrond Myklebust 
4472f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4473f26c7a78STrond Myklebust 	if (status < 0)
44741da177e4SLinus Torvalds 		goto xdr_error;
4475409924e4STrond Myklebust 	fattr->valid |= status;
4476f26c7a78STrond Myklebust 
4477f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4478f26c7a78STrond Myklebust 	if (status < 0)
44791da177e4SLinus Torvalds 		goto xdr_error;
4480409924e4STrond Myklebust 	fattr->valid |= status;
4481f26c7a78STrond Myklebust 
4482f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4483f26c7a78STrond Myklebust 	if (status < 0)
44841da177e4SLinus Torvalds 		goto xdr_error;
4485409924e4STrond Myklebust 	fattr->valid |= status;
4486f26c7a78STrond Myklebust 
4487f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4488f26c7a78STrond Myklebust 	if (status < 0)
44891da177e4SLinus Torvalds 		goto xdr_error;
4490409924e4STrond Myklebust 	fattr->valid |= status;
4491f26c7a78STrond Myklebust 
449228331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4493f26c7a78STrond Myklebust 	if (status < 0)
449499baf625SManoj Naik 		goto xdr_error;
4495409924e4STrond Myklebust 	fattr->valid |= status;
4496f26c7a78STrond Myklebust 
449788034c3dSAndy Adamson 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
449888034c3dSAndy Adamson 	if (status < 0)
449988034c3dSAndy Adamson 		goto xdr_error;
450088034c3dSAndy Adamson 
4501ae42c70aSBryan Schumaker xdr_error:
4502ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4503ae42c70aSBryan Schumaker 	return status;
4504ae42c70aSBryan Schumaker }
4505ae42c70aSBryan Schumaker 
4506ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
45078b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
45088b7e3f49STrond Myklebust 		const struct nfs_server *server)
4509ae42c70aSBryan Schumaker {
4510256e48bbSTrond Myklebust 	unsigned int savep;
4511ae42c70aSBryan Schumaker 	uint32_t attrlen,
4512dae100c2SFred Isaman 		 bitmap[3] = {0};
4513ae42c70aSBryan Schumaker 	int status;
4514ae42c70aSBryan Schumaker 
4515ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4516ae42c70aSBryan Schumaker 	if (status < 0)
4517ae42c70aSBryan Schumaker 		goto xdr_error;
4518ae42c70aSBryan Schumaker 
4519ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4520ae42c70aSBryan Schumaker 	if (status < 0)
4521ae42c70aSBryan Schumaker 		goto xdr_error;
4522ae42c70aSBryan Schumaker 
4523ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4524ae42c70aSBryan Schumaker 	if (status < 0)
4525ae42c70aSBryan Schumaker 		goto xdr_error;
4526ae42c70aSBryan Schumaker 
45278b7e3f49STrond Myklebust 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4528ae42c70aSBryan Schumaker 	if (status < 0)
4529ae42c70aSBryan Schumaker 		goto xdr_error;
4530ae42c70aSBryan Schumaker 
4531f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
45321da177e4SLinus Torvalds xdr_error:
45333110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
45341da177e4SLinus Torvalds 	return status;
45351da177e4SLinus Torvalds }
45361da177e4SLinus Torvalds 
4537ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
45386926afd1STrond Myklebust 		const struct nfs_server *server)
4539ae42c70aSBryan Schumaker {
45408b7e3f49STrond Myklebust 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4541ae42c70aSBryan Schumaker }
45421da177e4SLinus Torvalds 
4543504913fbSAndy Adamson /*
4544504913fbSAndy Adamson  * Decode potentially multiple layout types. Currently we only support
4545504913fbSAndy Adamson  * one layout driver per file system.
4546504913fbSAndy Adamson  */
4547504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4548504913fbSAndy Adamson 					 uint32_t *layouttype)
4549504913fbSAndy Adamson {
4550504913fbSAndy Adamson 	uint32_t *p;
4551504913fbSAndy Adamson 	int num;
4552504913fbSAndy Adamson 
4553504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4554504913fbSAndy Adamson 	if (unlikely(!p))
4555504913fbSAndy Adamson 		goto out_overflow;
4556504913fbSAndy Adamson 	num = be32_to_cpup(p);
4557504913fbSAndy Adamson 
4558504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4559504913fbSAndy Adamson 	if (num == 0) {
4560504913fbSAndy Adamson 		*layouttype = 0;
4561504913fbSAndy Adamson 		return 0;
4562504913fbSAndy Adamson 	}
4563504913fbSAndy Adamson 	if (num > 1)
4564a030889aSWeston Andros Adamson 		printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4565a030889aSWeston Andros Adamson 			"drivers per filesystem not supported\n", __func__);
4566504913fbSAndy Adamson 
4567504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4568504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, num * 4);
4569504913fbSAndy Adamson 	if (unlikely(!p))
4570504913fbSAndy Adamson 		goto out_overflow;
4571504913fbSAndy Adamson 	*layouttype = be32_to_cpup(p);
4572504913fbSAndy Adamson 	return 0;
4573504913fbSAndy Adamson out_overflow:
4574504913fbSAndy Adamson 	print_overflow_msg(__func__, xdr);
4575504913fbSAndy Adamson 	return -EIO;
4576504913fbSAndy Adamson }
4577504913fbSAndy Adamson 
4578504913fbSAndy Adamson /*
4579504913fbSAndy Adamson  * The type of file system exported.
4580504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4581504913fbSAndy Adamson  */
4582504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4583504913fbSAndy Adamson 				uint32_t *layouttype)
4584504913fbSAndy Adamson {
4585504913fbSAndy Adamson 	int status = 0;
4586504913fbSAndy Adamson 
4587504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4588504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4589504913fbSAndy Adamson 		return -EIO;
4590504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4591504913fbSAndy Adamson 		status = decode_first_pnfs_layout_type(xdr, layouttype);
4592504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4593504913fbSAndy Adamson 	} else
4594504913fbSAndy Adamson 		*layouttype = 0;
4595504913fbSAndy Adamson 	return status;
4596504913fbSAndy Adamson }
4597504913fbSAndy Adamson 
4598dae100c2SFred Isaman /*
4599dae100c2SFred Isaman  * The prefered block size for layout directed io
4600dae100c2SFred Isaman  */
4601dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4602dae100c2SFred Isaman 				      uint32_t *res)
4603dae100c2SFred Isaman {
4604dae100c2SFred Isaman 	__be32 *p;
4605dae100c2SFred Isaman 
4606dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4607dae100c2SFred Isaman 	*res = 0;
4608dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4609dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4610dae100c2SFred Isaman 		if (unlikely(!p)) {
4611dae100c2SFred Isaman 			print_overflow_msg(__func__, xdr);
4612dae100c2SFred Isaman 			return -EIO;
4613dae100c2SFred Isaman 		}
4614dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4615dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4616dae100c2SFred Isaman 	}
4617dae100c2SFred Isaman 	return 0;
4618dae100c2SFred Isaman }
4619dae100c2SFred Isaman 
46201da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
46211da177e4SLinus Torvalds {
4622256e48bbSTrond Myklebust 	unsigned int savep;
4623dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
46241da177e4SLinus Torvalds 	int status;
46251da177e4SLinus Torvalds 
46261da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
46271da177e4SLinus Torvalds 		goto xdr_error;
46281da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
46291da177e4SLinus Torvalds 		goto xdr_error;
46301da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
46311da177e4SLinus Torvalds 		goto xdr_error;
46321da177e4SLinus Torvalds 
46331da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
46341da177e4SLinus Torvalds 
46351da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
46361da177e4SLinus Torvalds 		goto xdr_error;
46371da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
46381da177e4SLinus Torvalds 		goto xdr_error;
46391da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
46401da177e4SLinus Torvalds 		goto xdr_error;
46411da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
46421da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
46431da177e4SLinus Torvalds 		goto xdr_error;
46441da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
464555b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
464655b6e774SRicardo Labiaga 	if (status != 0)
464755b6e774SRicardo Labiaga 		goto xdr_error;
4648504913fbSAndy Adamson 	status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4649504913fbSAndy Adamson 	if (status != 0)
4650504913fbSAndy Adamson 		goto xdr_error;
4651dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4652dae100c2SFred Isaman 	if (status)
4653dae100c2SFred Isaman 		goto xdr_error;
46541da177e4SLinus Torvalds 
46551da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
46561da177e4SLinus Torvalds xdr_error:
46573110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
46581da177e4SLinus Torvalds 	return status;
46591da177e4SLinus Torvalds }
46601da177e4SLinus Torvalds 
46611da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
46621da177e4SLinus Torvalds {
46638687b63aSAl Viro 	__be32 *p;
46641da177e4SLinus Torvalds 	uint32_t len;
46651da177e4SLinus Torvalds 	int status;
46661da177e4SLinus Torvalds 
46679936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
46689936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
46699936781dSTrond Myklebust 
46701da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
46711da177e4SLinus Torvalds 	if (status)
46721da177e4SLinus Torvalds 		return status;
46731da177e4SLinus Torvalds 
4674c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4675c0eae66eSBenny Halevy 	if (unlikely(!p))
4676c0eae66eSBenny Halevy 		goto out_overflow;
4677cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
46781da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
46791da177e4SLinus Torvalds 		return -EIO;
46801da177e4SLinus Torvalds 	fh->size = len;
4681c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4682c0eae66eSBenny Halevy 	if (unlikely(!p))
4683c0eae66eSBenny Halevy 		goto out_overflow;
468499398d06SBenny Halevy 	memcpy(fh->data, p, len);
46851da177e4SLinus Torvalds 	return 0;
4686c0eae66eSBenny Halevy out_overflow:
4687c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4688c0eae66eSBenny Halevy 	return -EIO;
46891da177e4SLinus Torvalds }
46901da177e4SLinus Torvalds 
46911da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
46921da177e4SLinus Torvalds {
46931da177e4SLinus Torvalds 	int status;
46941da177e4SLinus Torvalds 
46951da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
46961da177e4SLinus Torvalds 	if (status)
46971da177e4SLinus Torvalds 		return status;
46981da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
46991da177e4SLinus Torvalds }
47001da177e4SLinus Torvalds 
47011da177e4SLinus Torvalds /*
47021da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
47031da177e4SLinus Torvalds  */
4704911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
47051da177e4SLinus Torvalds {
4706911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
47078687b63aSAl Viro 	__be32 *p;
4708911d1aafSTrond Myklebust 	uint32_t namelen, type;
47091da177e4SLinus Torvalds 
4710babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4711c0eae66eSBenny Halevy 	if (unlikely(!p))
4712c0eae66eSBenny Halevy 		goto out_overflow;
4713babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
47143ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4715babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4716babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4717911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4718911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4719911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4720911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4721911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4722911d1aafSTrond Myklebust 		if (type & 1)
4723911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4724911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4725911d1aafSTrond Myklebust 	}
4726babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4727babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4728babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4729c0eae66eSBenny Halevy 	if (likely(p))
47301da177e4SLinus Torvalds 		return -NFS4ERR_DENIED;
4731c0eae66eSBenny Halevy out_overflow:
4732c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4733c0eae66eSBenny Halevy 	return -EIO;
47341da177e4SLinus Torvalds }
47351da177e4SLinus Torvalds 
4736911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
47371da177e4SLinus Torvalds {
47381da177e4SLinus Torvalds 	int status;
47391da177e4SLinus Torvalds 
47401da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4741c1d51931STrond Myklebust 	if (status == -EIO)
4742c1d51931STrond Myklebust 		goto out;
47431da177e4SLinus Torvalds 	if (status == 0) {
474407d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
474507d30434SBenny Halevy 		if (unlikely(status))
474607d30434SBenny Halevy 			goto out;
47471da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4748c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4749c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4750c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4751c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4752c1d51931STrond Myklebust out:
47531da177e4SLinus Torvalds 	return status;
47541da177e4SLinus Torvalds }
47551da177e4SLinus Torvalds 
4756911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
47571da177e4SLinus Torvalds {
47581da177e4SLinus Torvalds 	int status;
47591da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
47601da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4761911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
47621da177e4SLinus Torvalds 	return status;
47631da177e4SLinus Torvalds }
47641da177e4SLinus Torvalds 
4765911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
47661da177e4SLinus Torvalds {
47671da177e4SLinus Torvalds 	int status;
47681da177e4SLinus Torvalds 
47691da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4770c1d51931STrond Myklebust 	if (status != -EIO)
4771c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
477207d30434SBenny Halevy 	if (status == 0)
477307d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
47741da177e4SLinus Torvalds 	return status;
47751da177e4SLinus Torvalds }
47761da177e4SLinus Torvalds 
4777d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
4778d3c7b7ccSTrond Myklebust {
4779d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4780d3c7b7ccSTrond Myklebust }
4781d3c7b7ccSTrond Myklebust 
47821da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
47831da177e4SLinus Torvalds {
47841da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
47851da177e4SLinus Torvalds }
47861da177e4SLinus Torvalds 
47871da177e4SLinus Torvalds /* This is too sick! */
47881da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
47891da177e4SLinus Torvalds {
47908687b63aSAl Viro 	__be32 *p;
47911da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
47921da177e4SLinus Torvalds 
4793c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4794c0eae66eSBenny Halevy 	if (unlikely(!p))
4795c0eae66eSBenny Halevy 		goto out_overflow;
47966f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
47971da177e4SLinus Torvalds 	switch (limit_type) {
47981da177e4SLinus Torvalds 	case 1:
4799cccddf4fSBenny Halevy 		xdr_decode_hyper(p, maxsize);
48001da177e4SLinus Torvalds 		break;
48011da177e4SLinus Torvalds 	case 2:
48026f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
4803cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
48041da177e4SLinus Torvalds 		*maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
48051da177e4SLinus Torvalds 	}
48061da177e4SLinus Torvalds 	return 0;
4807c0eae66eSBenny Halevy out_overflow:
4808c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4809c0eae66eSBenny Halevy 	return -EIO;
48101da177e4SLinus Torvalds }
48111da177e4SLinus Torvalds 
48121da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
48131da177e4SLinus Torvalds {
48148687b63aSAl Viro 	__be32 *p;
48151da177e4SLinus Torvalds 	uint32_t delegation_type;
481607d30434SBenny Halevy 	int status;
48171da177e4SLinus Torvalds 
4818c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4819c0eae66eSBenny Halevy 	if (unlikely(!p))
4820c0eae66eSBenny Halevy 		goto out_overflow;
4821cccddf4fSBenny Halevy 	delegation_type = be32_to_cpup(p);
48221da177e4SLinus Torvalds 	if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
48231da177e4SLinus Torvalds 		res->delegation_type = 0;
48241da177e4SLinus Torvalds 		return 0;
48251da177e4SLinus Torvalds 	}
482607d30434SBenny Halevy 	status = decode_stateid(xdr, &res->delegation);
482707d30434SBenny Halevy 	if (unlikely(status))
482807d30434SBenny Halevy 		return status;
4829c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4830c0eae66eSBenny Halevy 	if (unlikely(!p))
4831c0eae66eSBenny Halevy 		goto out_overflow;
4832cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
483305d564feSAndy Adamson 
48341da177e4SLinus Torvalds 	switch (delegation_type) {
48351da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
48361da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
48371da177e4SLinus Torvalds 		break;
48381da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
48391da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
48401da177e4SLinus Torvalds 		if (decode_space_limit(xdr, &res->maxsize) < 0)
48411da177e4SLinus Torvalds 				return -EIO;
48421da177e4SLinus Torvalds 	}
48437539bbabSDavid Howells 	return decode_ace(xdr, NULL, res->server->nfs_client);
4844c0eae66eSBenny Halevy out_overflow:
4845c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4846c0eae66eSBenny Halevy 	return -EIO;
48471da177e4SLinus Torvalds }
48481da177e4SLinus Torvalds 
48491da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
48501da177e4SLinus Torvalds {
48518687b63aSAl Viro 	__be32 *p;
4852aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
48531da177e4SLinus Torvalds 	int status;
48541da177e4SLinus Torvalds 
48551da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN);
4856c1d51931STrond Myklebust 	if (status != -EIO)
4857c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
485807d30434SBenny Halevy 	if (!status)
485907d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
486007d30434SBenny Halevy 	if (unlikely(status))
48611da177e4SLinus Torvalds 		return status;
48621da177e4SLinus Torvalds 
48631da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
48641da177e4SLinus Torvalds 
4865c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4866c0eae66eSBenny Halevy 	if (unlikely(!p))
4867c0eae66eSBenny Halevy 		goto out_overflow;
48686f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
4869cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
48701da177e4SLinus Torvalds 	if (bmlen > 10)
48711da177e4SLinus Torvalds 		goto xdr_error;
48721da177e4SLinus Torvalds 
4873c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4874c0eae66eSBenny Halevy 	if (unlikely(!p))
4875c0eae66eSBenny Halevy 		goto out_overflow;
4876aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4877aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
48786f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
4879aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
4880aa53ed54SJeff Layton 		res->attrset[i] = 0;
4881aa53ed54SJeff Layton 
48821da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
48831da177e4SLinus Torvalds xdr_error:
48843110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
48851da177e4SLinus Torvalds 	return -EIO;
4886c0eae66eSBenny Halevy out_overflow:
4887c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4888c0eae66eSBenny Halevy 	return -EIO;
48891da177e4SLinus Torvalds }
48901da177e4SLinus Torvalds 
48911da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
48921da177e4SLinus Torvalds {
48931da177e4SLinus Torvalds 	int status;
48941da177e4SLinus Torvalds 
48951da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4896c1d51931STrond Myklebust 	if (status != -EIO)
4897c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
489807d30434SBenny Halevy 	if (!status)
489907d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
49001da177e4SLinus Torvalds 	return status;
49011da177e4SLinus Torvalds }
49021da177e4SLinus Torvalds 
49031da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
49041da177e4SLinus Torvalds {
49051da177e4SLinus Torvalds 	int status;
49061da177e4SLinus Torvalds 
49071da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4908c1d51931STrond Myklebust 	if (status != -EIO)
4909c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
491007d30434SBenny Halevy 	if (!status)
491107d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
49121da177e4SLinus Torvalds 	return status;
49131da177e4SLinus Torvalds }
49141da177e4SLinus Torvalds 
49151da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
49161da177e4SLinus Torvalds {
49171da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
49181da177e4SLinus Torvalds }
49191da177e4SLinus Torvalds 
49201da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
49211da177e4SLinus Torvalds {
49221da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
49231da177e4SLinus Torvalds }
49241da177e4SLinus Torvalds 
49251da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
49261da177e4SLinus Torvalds {
49278687b63aSAl Viro 	__be32 *p;
492864bd577eSTrond Myklebust 	uint32_t count, eof, recvd;
49291da177e4SLinus Torvalds 	int status;
49301da177e4SLinus Torvalds 
49311da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
49321da177e4SLinus Torvalds 	if (status)
49331da177e4SLinus Torvalds 		return status;
4934c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4935c0eae66eSBenny Halevy 	if (unlikely(!p))
4936c0eae66eSBenny Halevy 		goto out_overflow;
49376f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
4938cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
493964bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, count);
49401da177e4SLinus Torvalds 	if (count > recvd) {
4941fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
49421da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
49431da177e4SLinus Torvalds 		count = recvd;
49441da177e4SLinus Torvalds 		eof = 0;
49451da177e4SLinus Torvalds 	}
49461da177e4SLinus Torvalds 	res->eof = eof;
49471da177e4SLinus Torvalds 	res->count = count;
49481da177e4SLinus Torvalds 	return 0;
4949c0eae66eSBenny Halevy out_overflow:
4950c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4951c0eae66eSBenny Halevy 	return -EIO;
49521da177e4SLinus Torvalds }
49531da177e4SLinus Torvalds 
49541da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
49551da177e4SLinus Torvalds {
4956bcecff77SChuck Lever 	int		status;
4957cd93710eSChuck Lever 	__be32		verf[2];
49581da177e4SLinus Torvalds 
49591da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
4960db942bbdSBenny Halevy 	if (!status)
4961db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
4962db942bbdSBenny Halevy 	if (unlikely(status))
49631da177e4SLinus Torvalds 		return status;
4964cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
496544109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
4966cd93710eSChuck Lever 			__func__, verf[0], verf[1]);
496764bd577eSTrond Myklebust 	return xdr_read_pages(xdr, xdr->buf->page_len);
49681da177e4SLinus Torvalds }
49691da177e4SLinus Torvalds 
49701da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
49711da177e4SLinus Torvalds {
49721da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4973bcecff77SChuck Lever 	u32 len, recvd;
49748687b63aSAl Viro 	__be32 *p;
49751da177e4SLinus Torvalds 	int status;
49761da177e4SLinus Torvalds 
49771da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
49781da177e4SLinus Torvalds 	if (status)
49791da177e4SLinus Torvalds 		return status;
49801da177e4SLinus Torvalds 
49811da177e4SLinus Torvalds 	/* Convert length of symlink */
4982c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4983c0eae66eSBenny Halevy 	if (unlikely(!p))
4984c0eae66eSBenny Halevy 		goto out_overflow;
4985cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
49861da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
4987fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
49881da177e4SLinus Torvalds 		return -ENAMETOOLONG;
49891da177e4SLinus Torvalds 	}
499064bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, len);
49911da177e4SLinus Torvalds 	if (recvd < len) {
4992fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
49931da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
49941da177e4SLinus Torvalds 		return -EIO;
49951da177e4SLinus Torvalds 	}
49961da177e4SLinus Torvalds 	/*
49971da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
49981da177e4SLinus Torvalds 	 * the link text will be copied directly into the
49991da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
50001da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
50011da177e4SLinus Torvalds 	 * null-termination).
50021da177e4SLinus Torvalds 	 */
5003b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
50041da177e4SLinus Torvalds 	return 0;
5005c0eae66eSBenny Halevy out_overflow:
5006c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5007c0eae66eSBenny Halevy 	return -EIO;
50081da177e4SLinus Torvalds }
50091da177e4SLinus Torvalds 
50101da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
50111da177e4SLinus Torvalds {
50121da177e4SLinus Torvalds 	int status;
50131da177e4SLinus Torvalds 
50141da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
50151da177e4SLinus Torvalds 	if (status)
50161da177e4SLinus Torvalds 		goto out;
50171da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
50181da177e4SLinus Torvalds out:
50191da177e4SLinus Torvalds 	return status;
50201da177e4SLinus Torvalds }
50211da177e4SLinus Torvalds 
50221da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
50231da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
50241da177e4SLinus Torvalds {
50251da177e4SLinus Torvalds 	int status;
50261da177e4SLinus Torvalds 
50271da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
50281da177e4SLinus Torvalds 	if (status)
50291da177e4SLinus Torvalds 		goto out;
50301da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
50311da177e4SLinus Torvalds 		goto out;
50321da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
50331da177e4SLinus Torvalds out:
50341da177e4SLinus Torvalds 	return status;
50351da177e4SLinus Torvalds }
50361da177e4SLinus Torvalds 
50371da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
50381da177e4SLinus Torvalds {
50391da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
50401da177e4SLinus Torvalds }
50411da177e4SLinus Torvalds 
504256ae19f3STrond Myklebust static int
504356ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
504456ae19f3STrond Myklebust {
504556ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
504656ae19f3STrond Myklebust }
504756ae19f3STrond Myklebust 
5048029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5049bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5050029d105eSJ. Bruce Fields {
5051256e48bbSTrond Myklebust 	unsigned int savep;
5052029d105eSJ. Bruce Fields 	uint32_t attrlen,
5053dae100c2SFred Isaman 		 bitmap[3] = {0};
5054029d105eSJ. Bruce Fields 	int status;
5055cff298c7STrond Myklebust 	unsigned int pg_offset;
5056029d105eSJ. Bruce Fields 
5057bf118a34SAndy Adamson 	res->acl_len = 0;
5058029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5059029d105eSJ. Bruce Fields 		goto out;
50605a006899SSachin Prabhu 
5061519d3959STrond Myklebust 	xdr_enter_page(xdr, xdr->buf->page_len);
5062519d3959STrond Myklebust 
5063cff298c7STrond Myklebust 	/* Calculate the offset of the page data */
5064cff298c7STrond Myklebust 	pg_offset = xdr->buf->head[0].iov_len;
50655a006899SSachin Prabhu 
5066029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5067029d105eSJ. Bruce Fields 		goto out;
5068029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5069029d105eSJ. Bruce Fields 		goto out;
5070029d105eSJ. Bruce Fields 
5071029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5072029d105eSJ. Bruce Fields 		return -EIO;
5073029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5074029d105eSJ. Bruce Fields 
5075bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5076bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5077bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5078cff298c7STrond Myklebust 		res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5079519d3959STrond Myklebust 		res->acl_len = attrlen;
50801f1ea6c2STrond Myklebust 
50811f1ea6c2STrond Myklebust 		/* Check for receive buffer overflow */
50821f1ea6c2STrond Myklebust 		if (res->acl_len > (xdr->nwords << 2) ||
50831f1ea6c2STrond Myklebust 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
50841f1ea6c2STrond Myklebust 			res->acl_flags |= NFS4_ACL_TRUNC;
5085519d3959STrond Myklebust 			dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5086cff298c7STrond Myklebust 					attrlen, xdr->nwords << 2);
5087029d105eSJ. Bruce Fields 		}
50888c233cf9SJ. Bruce Fields 	} else
50898c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5090029d105eSJ. Bruce Fields 
5091029d105eSJ. Bruce Fields out:
5092029d105eSJ. Bruce Fields 	return status;
5093029d105eSJ. Bruce Fields }
5094029d105eSJ. Bruce Fields 
50951da177e4SLinus Torvalds static int
50961da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
50971da177e4SLinus Torvalds {
50981da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
50991da177e4SLinus Torvalds }
51001da177e4SLinus Torvalds 
51019e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
51021da177e4SLinus Torvalds {
51038687b63aSAl Viro 	__be32 *p;
51041da177e4SLinus Torvalds 	uint32_t bmlen;
51051da177e4SLinus Torvalds 	int status;
51061da177e4SLinus Torvalds 
51071da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
51081da177e4SLinus Torvalds 	if (status)
51091da177e4SLinus Torvalds 		return status;
5110c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5111c0eae66eSBenny Halevy 	if (unlikely(!p))
5112c0eae66eSBenny Halevy 		goto out_overflow;
5113cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
5114c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5115c0eae66eSBenny Halevy 	if (likely(p))
51161da177e4SLinus Torvalds 		return 0;
5117c0eae66eSBenny Halevy out_overflow:
5118c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5119c0eae66eSBenny Halevy 	return -EIO;
51201da177e4SLinus Torvalds }
51211da177e4SLinus Torvalds 
5122bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
51231da177e4SLinus Torvalds {
51248687b63aSAl Viro 	__be32 *p;
51251da177e4SLinus Torvalds 	uint32_t opnum;
51261da177e4SLinus Torvalds 	int32_t nfserr;
51271da177e4SLinus Torvalds 
5128c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5129c0eae66eSBenny Halevy 	if (unlikely(!p))
5130c0eae66eSBenny Halevy 		goto out_overflow;
51316f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
51321da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5133fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
51341da177e4SLinus Torvalds 			" %d\n", opnum);
51351da177e4SLinus Torvalds 		return -EIO;
51361da177e4SLinus Torvalds 	}
5137cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
51381da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5139c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5140c0eae66eSBenny Halevy 		if (unlikely(!p))
5141c0eae66eSBenny Halevy 			goto out_overflow;
5142bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5143bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
51441da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
51451da177e4SLinus Torvalds 		uint32_t len;
51461da177e4SLinus Torvalds 
51471da177e4SLinus Torvalds 		/* skip netid string */
5148c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5149c0eae66eSBenny Halevy 		if (unlikely(!p))
5150c0eae66eSBenny Halevy 			goto out_overflow;
5151cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5152c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5153c0eae66eSBenny Halevy 		if (unlikely(!p))
5154c0eae66eSBenny Halevy 			goto out_overflow;
51551da177e4SLinus Torvalds 
51561da177e4SLinus Torvalds 		/* skip uaddr string */
5157c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5158c0eae66eSBenny Halevy 		if (unlikely(!p))
5159c0eae66eSBenny Halevy 			goto out_overflow;
5160cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5161c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5162c0eae66eSBenny Halevy 		if (unlikely(!p))
5163c0eae66eSBenny Halevy 			goto out_overflow;
51641da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
51651da177e4SLinus Torvalds 	} else
5166856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
51671da177e4SLinus Torvalds 
51681da177e4SLinus Torvalds 	return 0;
5169c0eae66eSBenny Halevy out_overflow:
5170c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5171c0eae66eSBenny Halevy 	return -EIO;
51721da177e4SLinus Torvalds }
51731da177e4SLinus Torvalds 
51741da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
51751da177e4SLinus Torvalds {
51761da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
51771da177e4SLinus Torvalds }
51781da177e4SLinus Torvalds 
51791da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
51801da177e4SLinus Torvalds {
51818687b63aSAl Viro 	__be32 *p;
51821da177e4SLinus Torvalds 	int status;
51831da177e4SLinus Torvalds 
51841da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
51851da177e4SLinus Torvalds 	if (status)
51861da177e4SLinus Torvalds 		return status;
51871da177e4SLinus Torvalds 
51882f2c63bcSTrond Myklebust 	p = xdr_inline_decode(xdr, 8);
5189c0eae66eSBenny Halevy 	if (unlikely(!p))
5190c0eae66eSBenny Halevy 		goto out_overflow;
51916f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
51926f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
51932f2c63bcSTrond Myklebust 	return decode_write_verifier(xdr, &res->verf->verifier);
5194c0eae66eSBenny Halevy out_overflow:
5195c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5196c0eae66eSBenny Halevy 	return -EIO;
51971da177e4SLinus Torvalds }
51981da177e4SLinus Torvalds 
51991da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
52001da177e4SLinus Torvalds {
52011da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
52021da177e4SLinus Torvalds }
52031da177e4SLinus Torvalds 
52045a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
52055a5ea0d4SBryan Schumaker {
52065a5ea0d4SBryan Schumaker 	__be32 *p;
52075a5ea0d4SBryan Schumaker 
52085a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
52095a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52105a5ea0d4SBryan Schumaker 		goto out_overflow;
52115a5ea0d4SBryan Schumaker 	flavor->gss.sec_oid4.len = be32_to_cpup(p);
52125a5ea0d4SBryan Schumaker 	if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
52135a5ea0d4SBryan Schumaker 		goto out_err;
52145a5ea0d4SBryan Schumaker 
52155a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
52165a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52175a5ea0d4SBryan Schumaker 		goto out_overflow;
52185a5ea0d4SBryan Schumaker 	memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
52195a5ea0d4SBryan Schumaker 
52205a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
52215a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52225a5ea0d4SBryan Schumaker 		goto out_overflow;
52235a5ea0d4SBryan Schumaker 	flavor->gss.qop4 = be32_to_cpup(p++);
52245a5ea0d4SBryan Schumaker 	flavor->gss.service = be32_to_cpup(p);
52255a5ea0d4SBryan Schumaker 
52265a5ea0d4SBryan Schumaker 	return 0;
52275a5ea0d4SBryan Schumaker 
52285a5ea0d4SBryan Schumaker out_overflow:
52295a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
52305a5ea0d4SBryan Schumaker 	return -EIO;
52315a5ea0d4SBryan Schumaker out_err:
52325a5ea0d4SBryan Schumaker 	return -EINVAL;
52335a5ea0d4SBryan Schumaker }
52345a5ea0d4SBryan Schumaker 
523531e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
52365a5ea0d4SBryan Schumaker {
52375a5ea0d4SBryan Schumaker 	struct nfs4_secinfo_flavor *sec_flavor;
52385a5ea0d4SBryan Schumaker 	int status;
52395a5ea0d4SBryan Schumaker 	__be32 *p;
5240c3dfc280SBryan Schumaker 	int i, num_flavors;
52415a5ea0d4SBryan Schumaker 
52425a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
52435a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52445a5ea0d4SBryan Schumaker 		goto out_overflow;
52455a5ea0d4SBryan Schumaker 
5246c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5247c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5248c3dfc280SBryan Schumaker 
5249c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
52505a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5251c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
52525a5ea0d4SBryan Schumaker 			break;
52535a5ea0d4SBryan Schumaker 
52545a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
52555a5ea0d4SBryan Schumaker 		if (unlikely(!p))
52565a5ea0d4SBryan Schumaker 			goto out_overflow;
52575a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
52585a5ea0d4SBryan Schumaker 
52595a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5260613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5261613e901eSBryan Schumaker 			if (status)
5262613e901eSBryan Schumaker 				goto out;
52635a5ea0d4SBryan Schumaker 		}
5264c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
52655a5ea0d4SBryan Schumaker 	}
52665a5ea0d4SBryan Schumaker 
526731e4dda4SBryan Schumaker 	status = 0;
5268613e901eSBryan Schumaker out:
5269613e901eSBryan Schumaker 	return status;
52705a5ea0d4SBryan Schumaker out_overflow:
52715a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
52725a5ea0d4SBryan Schumaker 	return -EIO;
52735a5ea0d4SBryan Schumaker }
52745a5ea0d4SBryan Schumaker 
527531e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
527631e4dda4SBryan Schumaker {
527731e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO);
527831e4dda4SBryan Schumaker 	if (status)
527931e4dda4SBryan Schumaker 		return status;
528031e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
528131e4dda4SBryan Schumaker }
528231e4dda4SBryan Schumaker 
528399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
528431e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
528531e4dda4SBryan Schumaker {
528631e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
528731e4dda4SBryan Schumaker 	if (status)
528831e4dda4SBryan Schumaker 		return status;
528931e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
529031e4dda4SBryan Schumaker }
529131e4dda4SBryan Schumaker 
529299fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
529399fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
529499fe60d0SBenny Halevy {
529599fe60d0SBenny Halevy 	__be32 *p;
529699fe60d0SBenny Halevy 	uint32_t dummy;
52972460ba57SBenny Halevy 	char *dummy_str;
529899fe60d0SBenny Halevy 	int status;
52997d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
530099fe60d0SBenny Halevy 
530199fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
530299fe60d0SBenny Halevy 	if (status)
530399fe60d0SBenny Halevy 		return status;
530499fe60d0SBenny Halevy 
5305c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5306c0eae66eSBenny Halevy 	if (unlikely(!p))
5307c0eae66eSBenny Halevy 		goto out_overflow;
530832b01310STrond Myklebust 	xdr_decode_hyper(p, &res->clientid);
5309c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5310c0eae66eSBenny Halevy 	if (unlikely(!p))
5311c0eae66eSBenny Halevy 		goto out_overflow;
531232b01310STrond Myklebust 	res->seqid = be32_to_cpup(p++);
531332b01310STrond Myklebust 	res->flags = be32_to_cpup(p++);
531499fe60d0SBenny Halevy 
531599fe60d0SBenny Halevy 	/* We ask for SP4_NONE */
5316cccddf4fSBenny Halevy 	dummy = be32_to_cpup(p);
531799fe60d0SBenny Halevy 	if (dummy != SP4_NONE)
531899fe60d0SBenny Halevy 		return -EIO;
531999fe60d0SBenny Halevy 
5320acdeb69dSChuck Lever 	/* server_owner4.so_minor_id */
5321c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5322c0eae66eSBenny Halevy 	if (unlikely(!p))
5323c0eae66eSBenny Halevy 		goto out_overflow;
5324acdeb69dSChuck Lever 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
532599fe60d0SBenny Halevy 
5326acdeb69dSChuck Lever 	/* server_owner4.so_major_id */
53272460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53282460ba57SBenny Halevy 	if (unlikely(status))
53292460ba57SBenny Halevy 		return status;
533078fe0f41SWeston Andros Adamson 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
533178fe0f41SWeston Andros Adamson 		return -EIO;
5332acdeb69dSChuck Lever 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5333acdeb69dSChuck Lever 	res->server_owner->major_id_sz = dummy;
533478fe0f41SWeston Andros Adamson 
5335acdeb69dSChuck Lever 	/* server_scope4 */
5336acdeb69dSChuck Lever 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5337acdeb69dSChuck Lever 	if (unlikely(status))
5338acdeb69dSChuck Lever 		return status;
5339acdeb69dSChuck Lever 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5340acdeb69dSChuck Lever 		return -EIO;
534178fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
534278fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
534378fe0f41SWeston Andros Adamson 
53447d2ed9acSWeston Andros Adamson 	/* Implementation Id */
53457d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
53467d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
53477d2ed9acSWeston Andros Adamson 		goto out_overflow;
53487d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
53497d2ed9acSWeston Andros Adamson 
53507d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
53517d2ed9acSWeston Andros Adamson 		/* nii_domain */
53522460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53532460ba57SBenny Halevy 		if (unlikely(status))
53542460ba57SBenny Halevy 			return status;
53557d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
53567d2ed9acSWeston Andros Adamson 			return -EIO;
53577d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
535899fe60d0SBenny Halevy 
53597d2ed9acSWeston Andros Adamson 		/* nii_name */
53607d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53617d2ed9acSWeston Andros Adamson 		if (unlikely(status))
53627d2ed9acSWeston Andros Adamson 			return status;
53637d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
53647d2ed9acSWeston Andros Adamson 			return -EIO;
53657d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
53667d2ed9acSWeston Andros Adamson 
53677d2ed9acSWeston Andros Adamson 		/* nii_date */
53687d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
53697d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
53707d2ed9acSWeston Andros Adamson 			goto out_overflow;
53717d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
53727d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
53737d2ed9acSWeston Andros Adamson 
53747d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
53757d2ed9acSWeston Andros Adamson 	}
537699fe60d0SBenny Halevy 	return 0;
5377c0eae66eSBenny Halevy out_overflow:
5378c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5379c0eae66eSBenny Halevy 	return -EIO;
538099fe60d0SBenny Halevy }
5381fc931582SAndy Adamson 
5382fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5383fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5384fc931582SAndy Adamson {
5385fc931582SAndy Adamson 	__be32 *p;
5386c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5387fc931582SAndy Adamson 
5388c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5389c0eae66eSBenny Halevy 	if (unlikely(!p))
5390c0eae66eSBenny Halevy 		goto out_overflow;
5391c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5392c9c30dd5SBenny Halevy 	if (val)
5393c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
53946f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
53956f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
53966f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
53976f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
53986f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5399cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5400fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5401a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5402a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5403fc931582SAndy Adamson 		return -EINVAL;
5404fc931582SAndy Adamson 	}
5405c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5406c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5407c0eae66eSBenny Halevy 		if (unlikely(!p))
5408c0eae66eSBenny Halevy 			goto out_overflow;
5409c0eae66eSBenny Halevy 	}
5410fc931582SAndy Adamson 	return 0;
5411c0eae66eSBenny Halevy out_overflow:
5412c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5413c0eae66eSBenny Halevy 	return -EIO;
5414fc931582SAndy Adamson }
5415fc931582SAndy Adamson 
5416e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5417e78291e4SBenny Halevy {
5418e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5419fc931582SAndy Adamson }
5420fc931582SAndy Adamson 
54217c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
54227c44f1aeSWeston Andros Adamson 				struct nfs41_bind_conn_to_session_res *res)
54237c44f1aeSWeston Andros Adamson {
54247c44f1aeSWeston Andros Adamson 	__be32 *p;
54257c44f1aeSWeston Andros Adamson 	int status;
54267c44f1aeSWeston Andros Adamson 
54277c44f1aeSWeston Andros Adamson 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
54287c44f1aeSWeston Andros Adamson 	if (!status)
54297c44f1aeSWeston Andros Adamson 		status = decode_sessionid(xdr, &res->session->sess_id);
54307c44f1aeSWeston Andros Adamson 	if (unlikely(status))
54317c44f1aeSWeston Andros Adamson 		return status;
54327c44f1aeSWeston Andros Adamson 
54337c44f1aeSWeston Andros Adamson 	/* dir flags, rdma mode bool */
54347c44f1aeSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 8);
54357c44f1aeSWeston Andros Adamson 	if (unlikely(!p))
54367c44f1aeSWeston Andros Adamson 		goto out_overflow;
54377c44f1aeSWeston Andros Adamson 
54387c44f1aeSWeston Andros Adamson 	res->dir = be32_to_cpup(p++);
54397c44f1aeSWeston Andros Adamson 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
54407c44f1aeSWeston Andros Adamson 		return -EIO;
54417c44f1aeSWeston Andros Adamson 	if (be32_to_cpup(p) == 0)
54427c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = false;
54437c44f1aeSWeston Andros Adamson 	else
54447c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = true;
54457c44f1aeSWeston Andros Adamson 
54467c44f1aeSWeston Andros Adamson 	return 0;
54477c44f1aeSWeston Andros Adamson out_overflow:
54487c44f1aeSWeston Andros Adamson 	print_overflow_msg(__func__, xdr);
54497c44f1aeSWeston Andros Adamson 	return -EIO;
54507c44f1aeSWeston Andros Adamson }
54517c44f1aeSWeston Andros Adamson 
5452fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5453fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5454fc931582SAndy Adamson {
5455fc931582SAndy Adamson 	__be32 *p;
5456fc931582SAndy Adamson 	int status;
5457fc931582SAndy Adamson 	struct nfs_client *clp = res->client;
5458fc931582SAndy Adamson 	struct nfs4_session *session = clp->cl_session;
5459fc931582SAndy Adamson 
5460fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5461e78291e4SBenny Halevy 	if (!status)
5462e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &session->sess_id);
5463e78291e4SBenny Halevy 	if (unlikely(status))
5464fc931582SAndy Adamson 		return status;
5465fc931582SAndy Adamson 
5466fc931582SAndy Adamson 	/* seqid, flags */
5467c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5468c0eae66eSBenny Halevy 	if (unlikely(!p))
5469c0eae66eSBenny Halevy 		goto out_overflow;
54706f723f77SBenny Halevy 	clp->cl_seqid = be32_to_cpup(p++);
5471cccddf4fSBenny Halevy 	session->flags = be32_to_cpup(p);
5472fc931582SAndy Adamson 
5473fc931582SAndy Adamson 	/* Channel attributes */
5474fc931582SAndy Adamson 	status = decode_chan_attrs(xdr, &session->fc_attrs);
5475fc931582SAndy Adamson 	if (!status)
5476fc931582SAndy Adamson 		status = decode_chan_attrs(xdr, &session->bc_attrs);
5477fc931582SAndy Adamson 	return status;
5478c0eae66eSBenny Halevy out_overflow:
5479c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5480c0eae66eSBenny Halevy 	return -EIO;
5481fc931582SAndy Adamson }
54820f3e66c6SAndy Adamson 
54830f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
54840f3e66c6SAndy Adamson {
54850f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
54860f3e66c6SAndy Adamson }
548718019753SRicardo Labiaga 
548866245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
548966245539STrond Myklebust {
549066245539STrond Myklebust 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
549166245539STrond Myklebust }
549266245539STrond Myklebust 
549318019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
549418019753SRicardo Labiaga {
549518019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
549618019753SRicardo Labiaga }
549799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
549899fe60d0SBenny Halevy 
54999b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
55009b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
55019b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
55029b7b9fccSAndy Adamson {
55039b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5504fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5505fc01cea9SAndy Adamson 	u32 dummy;
5506fc01cea9SAndy Adamson 	int status;
5507fc01cea9SAndy Adamson 	__be32 *p;
5508fc01cea9SAndy Adamson 
55099b7b9fccSAndy Adamson 	if (!res->sr_session)
55109b7b9fccSAndy Adamson 		return 0;
55119b7b9fccSAndy Adamson 
5512fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5513e78291e4SBenny Halevy 	if (!status)
5514e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5515e78291e4SBenny Halevy 	if (unlikely(status))
5516fc01cea9SAndy Adamson 		goto out_err;
55179b7b9fccSAndy Adamson 
5518fc01cea9SAndy Adamson 	/*
5519fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5520fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5521fc01cea9SAndy Adamson 	 */
5522fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5523fc01cea9SAndy Adamson 
5524fc01cea9SAndy Adamson 	if (memcmp(id.data, res->sr_session->sess_id.data,
5525fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5526fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5527fc01cea9SAndy Adamson 		goto out_err;
5528fc01cea9SAndy Adamson 	}
5529e78291e4SBenny Halevy 
5530c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5531c0eae66eSBenny Halevy 	if (unlikely(!p))
5532c0eae66eSBenny Halevy 		goto out_overflow;
5533e78291e4SBenny Halevy 
5534fc01cea9SAndy Adamson 	/* seqid */
55356f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5536dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5537fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5538fc01cea9SAndy Adamson 		goto out_err;
5539fc01cea9SAndy Adamson 	}
5540fc01cea9SAndy Adamson 	/* slot id */
55416f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5542dfb4f309SBenny Halevy 	if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5543fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5544fc01cea9SAndy Adamson 		goto out_err;
5545fc01cea9SAndy Adamson 	}
5546fc01cea9SAndy Adamson 	/* highest slot id - currently not processed */
55476f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5548fc01cea9SAndy Adamson 	/* target highest slot id - currently not processed */
55496f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
55500629e370SAlexandros Batsakis 	/* result flags */
55510629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5552fc01cea9SAndy Adamson 	status = 0;
5553fc01cea9SAndy Adamson out_err:
5554fc01cea9SAndy Adamson 	res->sr_status = status;
5555fc01cea9SAndy Adamson 	return status;
5556c0eae66eSBenny Halevy out_overflow:
5557c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5558c0eae66eSBenny Halevy 	status = -EIO;
5559c0eae66eSBenny Halevy 	goto out_err;
5560fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
55619b7b9fccSAndy Adamson 	return 0;
5562fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
55639b7b9fccSAndy Adamson }
55649b7b9fccSAndy Adamson 
5565b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
55667f11d8d3SAndy Adamson /*
55677f11d8d3SAndy Adamson  * TODO: Need to handle case when EOF != true;
55687f11d8d3SAndy Adamson  */
55697f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr,
55707f11d8d3SAndy Adamson 				struct pnfs_devicelist *res)
55717f11d8d3SAndy Adamson {
55727f11d8d3SAndy Adamson 	__be32 *p;
55737f11d8d3SAndy Adamson 	int status, i;
557498d94524STrond Myklebust 	nfs4_verifier verftemp;
55757f11d8d3SAndy Adamson 
55767f11d8d3SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICELIST);
55777f11d8d3SAndy Adamson 	if (status)
55787f11d8d3SAndy Adamson 		return status;
55797f11d8d3SAndy Adamson 
55807f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr, 8 + 8 + 4);
55817f11d8d3SAndy Adamson 	if (unlikely(!p))
55827f11d8d3SAndy Adamson 		goto out_overflow;
55837f11d8d3SAndy Adamson 
55847f11d8d3SAndy Adamson 	/* TODO: Skip cookie for now */
55857f11d8d3SAndy Adamson 	p += 2;
55867f11d8d3SAndy Adamson 
55877f11d8d3SAndy Adamson 	/* Read verifier */
558898d94524STrond Myklebust 	p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
55897f11d8d3SAndy Adamson 
55907f11d8d3SAndy Adamson 	res->num_devs = be32_to_cpup(p);
55917f11d8d3SAndy Adamson 
55927f11d8d3SAndy Adamson 	dprintk("%s: num_dev %d\n", __func__, res->num_devs);
55937f11d8d3SAndy Adamson 
55947f11d8d3SAndy Adamson 	if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5595a030889aSWeston Andros Adamson 		printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
55967f11d8d3SAndy Adamson 				__func__, res->num_devs);
55977f11d8d3SAndy Adamson 		return -EIO;
55987f11d8d3SAndy Adamson 	}
55997f11d8d3SAndy Adamson 
56007f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr,
56017f11d8d3SAndy Adamson 			      res->num_devs * NFS4_DEVICEID4_SIZE + 4);
56027f11d8d3SAndy Adamson 	if (unlikely(!p))
56037f11d8d3SAndy Adamson 		goto out_overflow;
56047f11d8d3SAndy Adamson 	for (i = 0; i < res->num_devs; i++)
56057f11d8d3SAndy Adamson 		p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
56067f11d8d3SAndy Adamson 					    NFS4_DEVICEID4_SIZE);
56077f11d8d3SAndy Adamson 	res->eof = be32_to_cpup(p);
56087f11d8d3SAndy Adamson 	return 0;
56097f11d8d3SAndy Adamson out_overflow:
56107f11d8d3SAndy Adamson 	print_overflow_msg(__func__, xdr);
56117f11d8d3SAndy Adamson 	return -EIO;
56127f11d8d3SAndy Adamson }
5613b1f69b75SAndy Adamson 
5614b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
5615b1f69b75SAndy Adamson 				struct pnfs_device *pdev)
5616b1f69b75SAndy Adamson {
5617b1f69b75SAndy Adamson 	__be32 *p;
5618b1f69b75SAndy Adamson 	uint32_t len, type;
5619b1f69b75SAndy Adamson 	int status;
5620b1f69b75SAndy Adamson 
5621b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5622b1f69b75SAndy Adamson 	if (status) {
5623b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5624b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5625b1f69b75SAndy Adamson 			if (unlikely(!p))
5626b1f69b75SAndy Adamson 				goto out_overflow;
5627b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5628b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5629b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5630b1f69b75SAndy Adamson 		}
5631b1f69b75SAndy Adamson 		return status;
5632b1f69b75SAndy Adamson 	}
5633b1f69b75SAndy Adamson 
5634b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5635b1f69b75SAndy Adamson 	if (unlikely(!p))
5636b1f69b75SAndy Adamson 		goto out_overflow;
5637b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5638b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5639b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5640b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5641b1f69b75SAndy Adamson 		return -EINVAL;
5642b1f69b75SAndy Adamson 	}
5643b1f69b75SAndy Adamson 	/*
5644b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5645b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5646b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5647b1f69b75SAndy Adamson 	 */
5648b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
564913fe4ba1STrond Myklebust 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
565013fe4ba1STrond Myklebust 		goto out_overflow;
5651b1f69b75SAndy Adamson 
5652b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5653b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5654b1f69b75SAndy Adamson 	if (unlikely(!p))
5655b1f69b75SAndy Adamson 		goto out_overflow;
5656b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5657b1f69b75SAndy Adamson 	if (len) {
5658ead00597SChuck Lever 		uint32_t i;
5659b1f69b75SAndy Adamson 
5660b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5661b1f69b75SAndy Adamson 		if (unlikely(!p))
5662b1f69b75SAndy Adamson 			goto out_overflow;
5663b1f69b75SAndy Adamson 		for (i = 0; i < len; i++, p++) {
5664b1f69b75SAndy Adamson 			if (be32_to_cpup(p)) {
5665b1f69b75SAndy Adamson 				dprintk("%s: notifications not supported\n",
5666b1f69b75SAndy Adamson 					__func__);
5667b1f69b75SAndy Adamson 				return -EIO;
5668b1f69b75SAndy Adamson 			}
5669b1f69b75SAndy Adamson 		}
5670b1f69b75SAndy Adamson 	}
5671b1f69b75SAndy Adamson 	return 0;
5672b1f69b75SAndy Adamson out_overflow:
5673b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5674b1f69b75SAndy Adamson 	return -EIO;
5675b1f69b75SAndy Adamson }
5676b1f69b75SAndy Adamson 
5677b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5678b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5679b1f69b75SAndy Adamson {
5680b1f69b75SAndy Adamson 	__be32 *p;
5681b1f69b75SAndy Adamson 	int status;
5682b1f69b75SAndy Adamson 	u32 layout_count;
568364bd577eSTrond Myklebust 	u32 recvd;
5684b1f69b75SAndy Adamson 
5685b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5686b1f69b75SAndy Adamson 	if (status)
5687b1f69b75SAndy Adamson 		return status;
5688ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5689b1f69b75SAndy Adamson 	if (unlikely(!p))
5690b1f69b75SAndy Adamson 		goto out_overflow;
5691ea9d23f5STrond Myklebust 	res->return_on_close = be32_to_cpup(p);
5692ea9d23f5STrond Myklebust 	decode_stateid(xdr, &res->stateid);
5693ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5694ea9d23f5STrond Myklebust 	if (unlikely(!p))
5695ea9d23f5STrond Myklebust 		goto out_overflow;
5696b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5697b1f69b75SAndy Adamson 	if (!layout_count) {
5698b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5699b1f69b75SAndy Adamson 			__func__);
5700b1f69b75SAndy Adamson 		return -EINVAL;
5701b1f69b75SAndy Adamson 	}
5702b1f69b75SAndy Adamson 
570335124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5704b1f69b75SAndy Adamson 	if (unlikely(!p))
5705b1f69b75SAndy Adamson 		goto out_overflow;
5706b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5707b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5708b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5709b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
571035124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5711b1f69b75SAndy Adamson 
5712b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5713b1f69b75SAndy Adamson 		__func__,
5714b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5715b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5716b1f69b75SAndy Adamson 		res->range.iomode,
5717b1f69b75SAndy Adamson 		res->type,
571835124a09SWeston Andros Adamson 		res->layoutp->len);
5719b1f69b75SAndy Adamson 
572064bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, res->layoutp->len);
572135124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
572235124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
572335124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
572435124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
572535124a09SWeston Andros Adamson 		return -EINVAL;
572635124a09SWeston Andros Adamson 	}
572735124a09SWeston Andros Adamson 
5728b1f69b75SAndy Adamson 	if (layout_count > 1) {
5729b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5730b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5731b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5732b1f69b75SAndy Adamson 		 * minimum it requested.
5733b1f69b75SAndy Adamson 		 */
5734b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5735b1f69b75SAndy Adamson 			__func__, layout_count);
5736b1f69b75SAndy Adamson 	}
5737b1f69b75SAndy Adamson 
5738b1f69b75SAndy Adamson 	return 0;
5739b1f69b75SAndy Adamson out_overflow:
5740b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5741b1f69b75SAndy Adamson 	return -EIO;
5742b1f69b75SAndy Adamson }
5743863a3c6cSAndy Adamson 
5744cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
5745cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
5746cbe82603SBenny Halevy {
5747cbe82603SBenny Halevy 	__be32 *p;
5748cbe82603SBenny Halevy 	int status;
5749cbe82603SBenny Halevy 
5750cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5751cbe82603SBenny Halevy 	if (status)
5752cbe82603SBenny Halevy 		return status;
5753cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5754cbe82603SBenny Halevy 	if (unlikely(!p))
5755cbe82603SBenny Halevy 		goto out_overflow;
5756cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
5757cbe82603SBenny Halevy 	if (res->lrs_present)
5758cbe82603SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
5759cbe82603SBenny Halevy 	return status;
5760cbe82603SBenny Halevy out_overflow:
5761cbe82603SBenny Halevy 	print_overflow_msg(__func__, xdr);
5762cbe82603SBenny Halevy 	return -EIO;
5763cbe82603SBenny Halevy }
5764cbe82603SBenny Halevy 
5765863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
5766863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
5767863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
5768863a3c6cSAndy Adamson {
5769863a3c6cSAndy Adamson 	__be32 *p;
5770863a3c6cSAndy Adamson 	__u32 sizechanged;
5771863a3c6cSAndy Adamson 	int status;
5772863a3c6cSAndy Adamson 
5773863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5774db29c089SAndy Adamson 	res->status = status;
5775863a3c6cSAndy Adamson 	if (status)
5776863a3c6cSAndy Adamson 		return status;
5777863a3c6cSAndy Adamson 
5778863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5779863a3c6cSAndy Adamson 	if (unlikely(!p))
5780863a3c6cSAndy Adamson 		goto out_overflow;
5781863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
5782863a3c6cSAndy Adamson 
5783863a3c6cSAndy Adamson 	if (sizechanged) {
5784863a3c6cSAndy Adamson 		/* throw away new size */
5785863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
5786863a3c6cSAndy Adamson 		if (unlikely(!p))
5787863a3c6cSAndy Adamson 			goto out_overflow;
5788863a3c6cSAndy Adamson 	}
5789863a3c6cSAndy Adamson 	return 0;
5790863a3c6cSAndy Adamson out_overflow:
5791863a3c6cSAndy Adamson 	print_overflow_msg(__func__, xdr);
5792863a3c6cSAndy Adamson 	return -EIO;
5793863a3c6cSAndy Adamson }
57947d974794SBryan Schumaker 
57957d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
57967d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
57977d974794SBryan Schumaker {
57987d974794SBryan Schumaker 	__be32 *p;
57997d974794SBryan Schumaker 	int status;
58007d974794SBryan Schumaker 	int num_res;
58017d974794SBryan Schumaker 
58027d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
58037d974794SBryan Schumaker 	if (status)
58047d974794SBryan Schumaker 		return status;
58057d974794SBryan Schumaker 
58067d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
58077d974794SBryan Schumaker 	if (unlikely(!p))
58087d974794SBryan Schumaker 		goto out_overflow;
58097d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
58107d974794SBryan Schumaker 	if (num_res != 1)
58117d974794SBryan Schumaker 		goto out;
58127d974794SBryan Schumaker 
58137d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
58147d974794SBryan Schumaker 	if (unlikely(!p))
58157d974794SBryan Schumaker 		goto out_overflow;
58167d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
58171cab0652SBryan Schumaker 
58181cab0652SBryan Schumaker 	return status;
58197d974794SBryan Schumaker out_overflow:
58207d974794SBryan Schumaker 	print_overflow_msg(__func__, xdr);
58217d974794SBryan Schumaker out:
58227d974794SBryan Schumaker 	return -EIO;
58237d974794SBryan Schumaker }
58249aeda35fSBryan Schumaker 
58259aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
58269aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
58279aeda35fSBryan Schumaker {
58289aeda35fSBryan Schumaker 	__be32 *p;
58299aeda35fSBryan Schumaker 	int status;
58309aeda35fSBryan Schumaker 
58319aeda35fSBryan Schumaker 	status = decode_op_hdr(xdr, OP_FREE_STATEID);
58329aeda35fSBryan Schumaker 	if (status)
58339aeda35fSBryan Schumaker 		return status;
58349aeda35fSBryan Schumaker 
58359aeda35fSBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
58369aeda35fSBryan Schumaker 	if (unlikely(!p))
58379aeda35fSBryan Schumaker 		goto out_overflow;
58389aeda35fSBryan Schumaker 	res->status = be32_to_cpup(p++);
58399aeda35fSBryan Schumaker 	return res->status;
58409aeda35fSBryan Schumaker out_overflow:
58419aeda35fSBryan Schumaker 	print_overflow_msg(__func__, xdr);
58429aeda35fSBryan Schumaker 	return -EIO;
58439aeda35fSBryan Schumaker }
5844b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
5845b1f69b75SAndy Adamson 
58461da177e4SLinus Torvalds /*
584749c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
584849c2559eSBenny Halevy  */
584949c2559eSBenny Halevy 
585049c2559eSBenny Halevy /*
58511da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
58521da177e4SLinus Torvalds  */
5853bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5854bf269551SChuck Lever 				       struct xdr_stream *xdr,
5855bf269551SChuck Lever 				       struct nfs_closeres *res)
58561da177e4SLinus Torvalds {
58571da177e4SLinus Torvalds 	struct compound_hdr hdr;
58581da177e4SLinus Torvalds 	int status;
58591da177e4SLinus Torvalds 
5860bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58611da177e4SLinus Torvalds 	if (status)
58621da177e4SLinus Torvalds 		goto out;
5863bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58649b7b9fccSAndy Adamson 	if (status)
58659b7b9fccSAndy Adamson 		goto out;
5866bf269551SChuck Lever 	status = decode_putfh(xdr);
58671da177e4SLinus Torvalds 	if (status)
58681da177e4SLinus Torvalds 		goto out;
5869bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
5870516a6af6STrond Myklebust 	if (status != 0)
5871516a6af6STrond Myklebust 		goto out;
58726926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
58731da177e4SLinus Torvalds out:
58741da177e4SLinus Torvalds 	return status;
58751da177e4SLinus Torvalds }
58761da177e4SLinus Torvalds 
58771da177e4SLinus Torvalds /*
58781da177e4SLinus Torvalds  * Decode ACCESS response
58791da177e4SLinus Torvalds  */
5880bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5881bf269551SChuck Lever 			       struct nfs4_accessres *res)
58821da177e4SLinus Torvalds {
58831da177e4SLinus Torvalds 	struct compound_hdr hdr;
58841da177e4SLinus Torvalds 	int status;
58851da177e4SLinus Torvalds 
5886bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58879b7b9fccSAndy Adamson 	if (status)
58889b7b9fccSAndy Adamson 		goto out;
5889bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58909b7b9fccSAndy Adamson 	if (status)
58911da177e4SLinus Torvalds 		goto out;
5892bf269551SChuck Lever 	status = decode_putfh(xdr);
589376b32999STrond Myklebust 	if (status != 0)
589476b32999STrond Myklebust 		goto out;
5895bf269551SChuck Lever 	status = decode_access(xdr, res);
589676b32999STrond Myklebust 	if (status != 0)
589776b32999STrond Myklebust 		goto out;
58986926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
58991da177e4SLinus Torvalds out:
59001da177e4SLinus Torvalds 	return status;
59011da177e4SLinus Torvalds }
59021da177e4SLinus Torvalds 
59031da177e4SLinus Torvalds /*
59041da177e4SLinus Torvalds  * Decode LOOKUP response
59051da177e4SLinus Torvalds  */
5906bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5907bf269551SChuck Lever 			       struct nfs4_lookup_res *res)
59081da177e4SLinus Torvalds {
59091da177e4SLinus Torvalds 	struct compound_hdr hdr;
59101da177e4SLinus Torvalds 	int status;
59111da177e4SLinus Torvalds 
5912bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59139b7b9fccSAndy Adamson 	if (status)
59149b7b9fccSAndy Adamson 		goto out;
5915bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59169b7b9fccSAndy Adamson 	if (status)
59171da177e4SLinus Torvalds 		goto out;
5918bf269551SChuck Lever 	status = decode_putfh(xdr);
5919bf269551SChuck Lever 	if (status)
59201da177e4SLinus Torvalds 		goto out;
5921bf269551SChuck Lever 	status = decode_lookup(xdr);
5922bf269551SChuck Lever 	if (status)
59231da177e4SLinus Torvalds 		goto out;
5924bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
5925bf269551SChuck Lever 	if (status)
59261da177e4SLinus Torvalds 		goto out;
59276926afd1STrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
59281da177e4SLinus Torvalds out:
59291da177e4SLinus Torvalds 	return status;
59301da177e4SLinus Torvalds }
59311da177e4SLinus Torvalds 
59321da177e4SLinus Torvalds /*
59331da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
59341da177e4SLinus Torvalds  */
5935bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5936bf269551SChuck Lever 				    struct xdr_stream *xdr,
5937bf269551SChuck Lever 				    struct nfs4_lookup_res *res)
59381da177e4SLinus Torvalds {
59391da177e4SLinus Torvalds 	struct compound_hdr hdr;
59401da177e4SLinus Torvalds 	int status;
59411da177e4SLinus Torvalds 
5942bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59439b7b9fccSAndy Adamson 	if (status)
59449b7b9fccSAndy Adamson 		goto out;
5945bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59469b7b9fccSAndy Adamson 	if (status)
59471da177e4SLinus Torvalds 		goto out;
5948bf269551SChuck Lever 	status = decode_putrootfh(xdr);
5949bf269551SChuck Lever 	if (status)
59501da177e4SLinus Torvalds 		goto out;
5951bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
5952bf269551SChuck Lever 	if (status == 0)
59536926afd1STrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
59541da177e4SLinus Torvalds out:
59551da177e4SLinus Torvalds 	return status;
59561da177e4SLinus Torvalds }
59571da177e4SLinus Torvalds 
59581da177e4SLinus Torvalds /*
59591da177e4SLinus Torvalds  * Decode REMOVE response
59601da177e4SLinus Torvalds  */
5961bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5962bf269551SChuck Lever 			       struct nfs_removeres *res)
59631da177e4SLinus Torvalds {
59641da177e4SLinus Torvalds 	struct compound_hdr hdr;
59651da177e4SLinus Torvalds 	int status;
59661da177e4SLinus Torvalds 
5967bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59689b7b9fccSAndy Adamson 	if (status)
59699b7b9fccSAndy Adamson 		goto out;
5970bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59719b7b9fccSAndy Adamson 	if (status)
59721da177e4SLinus Torvalds 		goto out;
5973bf269551SChuck Lever 	status = decode_putfh(xdr);
5974bf269551SChuck Lever 	if (status)
597516e42959STrond Myklebust 		goto out;
5976bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
59771da177e4SLinus Torvalds out:
59781da177e4SLinus Torvalds 	return status;
59791da177e4SLinus Torvalds }
59801da177e4SLinus Torvalds 
59811da177e4SLinus Torvalds /*
59821da177e4SLinus Torvalds  * Decode RENAME response
59831da177e4SLinus Torvalds  */
5984bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5985bf269551SChuck Lever 			       struct nfs_renameres *res)
59861da177e4SLinus Torvalds {
59871da177e4SLinus Torvalds 	struct compound_hdr hdr;
59881da177e4SLinus Torvalds 	int status;
59891da177e4SLinus Torvalds 
5990bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59919b7b9fccSAndy Adamson 	if (status)
59929b7b9fccSAndy Adamson 		goto out;
5993bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59949b7b9fccSAndy Adamson 	if (status)
59951da177e4SLinus Torvalds 		goto out;
5996bf269551SChuck Lever 	status = decode_putfh(xdr);
5997bf269551SChuck Lever 	if (status)
59981da177e4SLinus Torvalds 		goto out;
5999bf269551SChuck Lever 	status = decode_savefh(xdr);
6000bf269551SChuck Lever 	if (status)
60011da177e4SLinus Torvalds 		goto out;
6002bf269551SChuck Lever 	status = decode_putfh(xdr);
6003bf269551SChuck Lever 	if (status)
60041da177e4SLinus Torvalds 		goto out;
6005bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
60061da177e4SLinus Torvalds out:
60071da177e4SLinus Torvalds 	return status;
60081da177e4SLinus Torvalds }
60091da177e4SLinus Torvalds 
60101da177e4SLinus Torvalds /*
60111da177e4SLinus Torvalds  * Decode LINK response
60121da177e4SLinus Torvalds  */
6013bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6014bf269551SChuck Lever 			     struct nfs4_link_res *res)
60151da177e4SLinus Torvalds {
60161da177e4SLinus Torvalds 	struct compound_hdr hdr;
60171da177e4SLinus Torvalds 	int status;
60181da177e4SLinus Torvalds 
6019bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60209b7b9fccSAndy Adamson 	if (status)
60219b7b9fccSAndy Adamson 		goto out;
6022bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60239b7b9fccSAndy Adamson 	if (status)
60241da177e4SLinus Torvalds 		goto out;
6025bf269551SChuck Lever 	status = decode_putfh(xdr);
6026bf269551SChuck Lever 	if (status)
60271da177e4SLinus Torvalds 		goto out;
6028bf269551SChuck Lever 	status = decode_savefh(xdr);
6029bf269551SChuck Lever 	if (status)
60301da177e4SLinus Torvalds 		goto out;
6031bf269551SChuck Lever 	status = decode_putfh(xdr);
6032bf269551SChuck Lever 	if (status)
60331da177e4SLinus Torvalds 		goto out;
6034bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
6035bf269551SChuck Lever 	if (status)
603691ba2eeeSTrond Myklebust 		goto out;
603791ba2eeeSTrond Myklebust 	/*
603891ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
603991ba2eeeSTrond Myklebust 	 *             filehandle.
604091ba2eeeSTrond Myklebust 	 */
6041bf269551SChuck Lever 	status = decode_restorefh(xdr);
6042bf269551SChuck Lever 	if (status)
604391ba2eeeSTrond Myklebust 		goto out;
60446926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
60451da177e4SLinus Torvalds out:
60461da177e4SLinus Torvalds 	return status;
60471da177e4SLinus Torvalds }
60481da177e4SLinus Torvalds 
60491da177e4SLinus Torvalds /*
60501da177e4SLinus Torvalds  * Decode CREATE response
60511da177e4SLinus Torvalds  */
6052bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6053bf269551SChuck Lever 			       struct nfs4_create_res *res)
60541da177e4SLinus Torvalds {
60551da177e4SLinus Torvalds 	struct compound_hdr hdr;
60561da177e4SLinus Torvalds 	int status;
60571da177e4SLinus Torvalds 
6058bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60599b7b9fccSAndy Adamson 	if (status)
60609b7b9fccSAndy Adamson 		goto out;
6061bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60629b7b9fccSAndy Adamson 	if (status)
60631da177e4SLinus Torvalds 		goto out;
6064bf269551SChuck Lever 	status = decode_putfh(xdr);
6065bf269551SChuck Lever 	if (status)
60661da177e4SLinus Torvalds 		goto out;
6067bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6068bf269551SChuck Lever 	if (status)
60691da177e4SLinus Torvalds 		goto out;
6070bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6071bf269551SChuck Lever 	if (status)
60721da177e4SLinus Torvalds 		goto out;
60737c317fcfSTrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
60741da177e4SLinus Torvalds out:
60751da177e4SLinus Torvalds 	return status;
60761da177e4SLinus Torvalds }
60771da177e4SLinus Torvalds 
60781da177e4SLinus Torvalds /*
60791da177e4SLinus Torvalds  * Decode SYMLINK response
60801da177e4SLinus Torvalds  */
6081bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6082bf269551SChuck Lever 				struct nfs4_create_res *res)
60831da177e4SLinus Torvalds {
6084bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
60851da177e4SLinus Torvalds }
60861da177e4SLinus Torvalds 
60871da177e4SLinus Torvalds /*
60881da177e4SLinus Torvalds  * Decode GETATTR response
60891da177e4SLinus Torvalds  */
6090bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6091bf269551SChuck Lever 				struct nfs4_getattr_res *res)
60921da177e4SLinus Torvalds {
60931da177e4SLinus Torvalds 	struct compound_hdr hdr;
60941da177e4SLinus Torvalds 	int status;
60951da177e4SLinus Torvalds 
6096bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60971da177e4SLinus Torvalds 	if (status)
60981da177e4SLinus Torvalds 		goto out;
6099bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61009b7b9fccSAndy Adamson 	if (status)
61019b7b9fccSAndy Adamson 		goto out;
6102bf269551SChuck Lever 	status = decode_putfh(xdr);
61031da177e4SLinus Torvalds 	if (status)
61041da177e4SLinus Torvalds 		goto out;
61056926afd1STrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
61061da177e4SLinus Torvalds out:
61071da177e4SLinus Torvalds 	return status;
61081da177e4SLinus Torvalds }
61091da177e4SLinus Torvalds 
611023ec6965SJ. Bruce Fields /*
611123ec6965SJ. Bruce Fields  * Encode an SETACL request
611223ec6965SJ. Bruce Fields  */
61139f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
61149f06c719SChuck Lever 				struct nfs_setaclargs *args)
611523ec6965SJ. Bruce Fields {
611623ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
611766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
611823ec6965SJ. Bruce Fields 	};
611923ec6965SJ. Bruce Fields 
61209f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
61219f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
61229f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
61239f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6124d017931cSAndy Adamson 	encode_nops(&hdr);
612523ec6965SJ. Bruce Fields }
612605d564feSAndy Adamson 
612723ec6965SJ. Bruce Fields /*
612823ec6965SJ. Bruce Fields  * Decode SETACL response
612923ec6965SJ. Bruce Fields  */
613023ec6965SJ. Bruce Fields static int
6131bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
613273c403a9SBenny Halevy 		    struct nfs_setaclres *res)
613323ec6965SJ. Bruce Fields {
613423ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
613523ec6965SJ. Bruce Fields 	int status;
613623ec6965SJ. Bruce Fields 
6137bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
613823ec6965SJ. Bruce Fields 	if (status)
613923ec6965SJ. Bruce Fields 		goto out;
6140bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61419b7b9fccSAndy Adamson 	if (status)
61429b7b9fccSAndy Adamson 		goto out;
6143bf269551SChuck Lever 	status = decode_putfh(xdr);
614423ec6965SJ. Bruce Fields 	if (status)
614523ec6965SJ. Bruce Fields 		goto out;
6146bf269551SChuck Lever 	status = decode_setattr(xdr);
614723ec6965SJ. Bruce Fields out:
614823ec6965SJ. Bruce Fields 	return status;
614923ec6965SJ. Bruce Fields }
61501da177e4SLinus Torvalds 
61511da177e4SLinus Torvalds /*
6152029d105eSJ. Bruce Fields  * Decode GETACL response
6153029d105eSJ. Bruce Fields  */
6154029d105eSJ. Bruce Fields static int
6155bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6156663c79b3SBenny Halevy 		    struct nfs_getaclres *res)
6157029d105eSJ. Bruce Fields {
6158029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6159029d105eSJ. Bruce Fields 	int status;
6160029d105eSJ. Bruce Fields 
6161331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6162331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6163331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6164331818f1STrond Myklebust 	}
6165bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6166029d105eSJ. Bruce Fields 	if (status)
6167029d105eSJ. Bruce Fields 		goto out;
6168bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61699b7b9fccSAndy Adamson 	if (status)
61709b7b9fccSAndy Adamson 		goto out;
6171bf269551SChuck Lever 	status = decode_putfh(xdr);
6172029d105eSJ. Bruce Fields 	if (status)
6173029d105eSJ. Bruce Fields 		goto out;
6174bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6175029d105eSJ. Bruce Fields 
6176029d105eSJ. Bruce Fields out:
6177029d105eSJ. Bruce Fields 	return status;
6178029d105eSJ. Bruce Fields }
6179029d105eSJ. Bruce Fields 
6180029d105eSJ. Bruce Fields /*
61811da177e4SLinus Torvalds  * Decode CLOSE response
61821da177e4SLinus Torvalds  */
6183bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6184bf269551SChuck Lever 			      struct nfs_closeres *res)
61851da177e4SLinus Torvalds {
61861da177e4SLinus Torvalds 	struct compound_hdr hdr;
61871da177e4SLinus Torvalds 	int status;
61881da177e4SLinus Torvalds 
6189bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61901da177e4SLinus Torvalds 	if (status)
61911da177e4SLinus Torvalds 		goto out;
6192bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61939b7b9fccSAndy Adamson 	if (status)
61949b7b9fccSAndy Adamson 		goto out;
6195bf269551SChuck Lever 	status = decode_putfh(xdr);
61961da177e4SLinus Torvalds 	if (status)
61971da177e4SLinus Torvalds 		goto out;
6198bf269551SChuck Lever 	status = decode_close(xdr, res);
6199516a6af6STrond Myklebust 	if (status != 0)
6200516a6af6STrond Myklebust 		goto out;
6201516a6af6STrond Myklebust 	/*
6202516a6af6STrond Myklebust 	 * Note: Server may do delete on close for this file
6203516a6af6STrond Myklebust 	 * 	in which case the getattr call will fail with
6204516a6af6STrond Myklebust 	 * 	an ESTALE error. Shouldn't be a problem,
6205516a6af6STrond Myklebust 	 * 	though, since fattr->valid will remain unset.
6206516a6af6STrond Myklebust 	 */
62076926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
62081da177e4SLinus Torvalds out:
62091da177e4SLinus Torvalds 	return status;
62101da177e4SLinus Torvalds }
62111da177e4SLinus Torvalds 
62121da177e4SLinus Torvalds /*
62131da177e4SLinus Torvalds  * Decode OPEN response
62141da177e4SLinus Torvalds  */
6215bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6216bf269551SChuck Lever 			     struct nfs_openres *res)
62171da177e4SLinus Torvalds {
62181da177e4SLinus Torvalds 	struct compound_hdr hdr;
62191da177e4SLinus Torvalds 	int status;
62201da177e4SLinus Torvalds 
6221bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62221da177e4SLinus Torvalds 	if (status)
62231da177e4SLinus Torvalds 		goto out;
6224bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62259b7b9fccSAndy Adamson 	if (status)
62269b7b9fccSAndy Adamson 		goto out;
6227bf269551SChuck Lever 	status = decode_putfh(xdr);
62281da177e4SLinus Torvalds 	if (status)
62291da177e4SLinus Torvalds 		goto out;
6230bf269551SChuck Lever 	status = decode_open(xdr, res);
62311da177e4SLinus Torvalds 	if (status)
62321da177e4SLinus Torvalds 		goto out;
623301913b49SWeston Andros Adamson 	status = decode_getfh(xdr, &res->fh);
623401913b49SWeston Andros Adamson 	if (status)
62351da177e4SLinus Torvalds 		goto out;
623690ff0c54STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
62371da177e4SLinus Torvalds out:
62381da177e4SLinus Torvalds 	return status;
62391da177e4SLinus Torvalds }
62401da177e4SLinus Torvalds 
62411da177e4SLinus Torvalds /*
62421da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
62431da177e4SLinus Torvalds  */
6244bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6245bf269551SChuck Lever 				     struct xdr_stream *xdr,
6246bf269551SChuck Lever 				     struct nfs_open_confirmres *res)
62471da177e4SLinus Torvalds {
62481da177e4SLinus Torvalds 	struct compound_hdr hdr;
62491da177e4SLinus Torvalds 	int status;
62501da177e4SLinus Torvalds 
6251bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62521da177e4SLinus Torvalds 	if (status)
62531da177e4SLinus Torvalds 		goto out;
6254bf269551SChuck Lever 	status = decode_putfh(xdr);
62551da177e4SLinus Torvalds 	if (status)
62561da177e4SLinus Torvalds 		goto out;
6257bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
62581da177e4SLinus Torvalds out:
62591da177e4SLinus Torvalds 	return status;
62601da177e4SLinus Torvalds }
62611da177e4SLinus Torvalds 
62621da177e4SLinus Torvalds /*
62631da177e4SLinus Torvalds  * Decode OPEN response
62641da177e4SLinus Torvalds  */
6265bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6266bf269551SChuck Lever 				    struct xdr_stream *xdr,
6267bf269551SChuck Lever 				    struct nfs_openres *res)
62681da177e4SLinus Torvalds {
62691da177e4SLinus Torvalds 	struct compound_hdr hdr;
62701da177e4SLinus Torvalds 	int status;
62711da177e4SLinus Torvalds 
6272bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62731da177e4SLinus Torvalds 	if (status)
62741da177e4SLinus Torvalds 		goto out;
6275bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62769b7b9fccSAndy Adamson 	if (status)
62779b7b9fccSAndy Adamson 		goto out;
6278bf269551SChuck Lever 	status = decode_putfh(xdr);
62791da177e4SLinus Torvalds 	if (status)
62801da177e4SLinus Torvalds 		goto out;
6281bf269551SChuck Lever 	status = decode_open(xdr, res);
6282864472e9STrond Myklebust 	if (status)
6283864472e9STrond Myklebust 		goto out;
62846926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
62851da177e4SLinus Torvalds out:
62861da177e4SLinus Torvalds 	return status;
62871da177e4SLinus Torvalds }
62881da177e4SLinus Torvalds 
62891da177e4SLinus Torvalds /*
62901da177e4SLinus Torvalds  * Decode SETATTR response
62911da177e4SLinus Torvalds  */
6292bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6293bf269551SChuck Lever 				struct xdr_stream *xdr,
6294bf269551SChuck Lever 				struct nfs_setattrres *res)
62951da177e4SLinus Torvalds {
62961da177e4SLinus Torvalds 	struct compound_hdr hdr;
62971da177e4SLinus Torvalds 	int status;
62981da177e4SLinus Torvalds 
6299bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63001da177e4SLinus Torvalds 	if (status)
63011da177e4SLinus Torvalds 		goto out;
6302bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63039b7b9fccSAndy Adamson 	if (status)
63049b7b9fccSAndy Adamson 		goto out;
6305bf269551SChuck Lever 	status = decode_putfh(xdr);
63061da177e4SLinus Torvalds 	if (status)
63071da177e4SLinus Torvalds 		goto out;
6308bf269551SChuck Lever 	status = decode_setattr(xdr);
63091da177e4SLinus Torvalds 	if (status)
63101da177e4SLinus Torvalds 		goto out;
63116926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
63121da177e4SLinus Torvalds out:
63131da177e4SLinus Torvalds 	return status;
63141da177e4SLinus Torvalds }
63151da177e4SLinus Torvalds 
63161da177e4SLinus Torvalds /*
63171da177e4SLinus Torvalds  * Decode LOCK response
63181da177e4SLinus Torvalds  */
6319bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6320bf269551SChuck Lever 			     struct nfs_lock_res *res)
63211da177e4SLinus Torvalds {
63221da177e4SLinus Torvalds 	struct compound_hdr hdr;
63231da177e4SLinus Torvalds 	int status;
63241da177e4SLinus Torvalds 
6325bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63261da177e4SLinus Torvalds 	if (status)
63271da177e4SLinus Torvalds 		goto out;
6328bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63299b7b9fccSAndy Adamson 	if (status)
63309b7b9fccSAndy Adamson 		goto out;
6331bf269551SChuck Lever 	status = decode_putfh(xdr);
63321da177e4SLinus Torvalds 	if (status)
63331da177e4SLinus Torvalds 		goto out;
6334bf269551SChuck Lever 	status = decode_lock(xdr, res);
63351da177e4SLinus Torvalds out:
63361da177e4SLinus Torvalds 	return status;
63371da177e4SLinus Torvalds }
63381da177e4SLinus Torvalds 
63391da177e4SLinus Torvalds /*
63401da177e4SLinus Torvalds  * Decode LOCKT response
63411da177e4SLinus Torvalds  */
6342bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6343bf269551SChuck Lever 			      struct nfs_lockt_res *res)
63441da177e4SLinus Torvalds {
63451da177e4SLinus Torvalds 	struct compound_hdr hdr;
63461da177e4SLinus Torvalds 	int status;
63471da177e4SLinus Torvalds 
6348bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63491da177e4SLinus Torvalds 	if (status)
63501da177e4SLinus Torvalds 		goto out;
6351bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63529b7b9fccSAndy Adamson 	if (status)
63539b7b9fccSAndy Adamson 		goto out;
6354bf269551SChuck Lever 	status = decode_putfh(xdr);
63551da177e4SLinus Torvalds 	if (status)
63561da177e4SLinus Torvalds 		goto out;
6357bf269551SChuck Lever 	status = decode_lockt(xdr, res);
63581da177e4SLinus Torvalds out:
63591da177e4SLinus Torvalds 	return status;
63601da177e4SLinus Torvalds }
63611da177e4SLinus Torvalds 
63621da177e4SLinus Torvalds /*
63631da177e4SLinus Torvalds  * Decode LOCKU response
63641da177e4SLinus Torvalds  */
6365bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6366bf269551SChuck Lever 			      struct nfs_locku_res *res)
63671da177e4SLinus Torvalds {
63681da177e4SLinus Torvalds 	struct compound_hdr hdr;
63691da177e4SLinus Torvalds 	int status;
63701da177e4SLinus Torvalds 
6371bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63721da177e4SLinus Torvalds 	if (status)
63731da177e4SLinus Torvalds 		goto out;
6374bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63759b7b9fccSAndy Adamson 	if (status)
63769b7b9fccSAndy Adamson 		goto out;
6377bf269551SChuck Lever 	status = decode_putfh(xdr);
63781da177e4SLinus Torvalds 	if (status)
63791da177e4SLinus Torvalds 		goto out;
6380bf269551SChuck Lever 	status = decode_locku(xdr, res);
63811da177e4SLinus Torvalds out:
63821da177e4SLinus Torvalds 	return status;
63831da177e4SLinus Torvalds }
63841da177e4SLinus Torvalds 
6385bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6386bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6387d3c7b7ccSTrond Myklebust {
6388d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6389d3c7b7ccSTrond Myklebust 	int status;
6390d3c7b7ccSTrond Myklebust 
6391bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6392d3c7b7ccSTrond Myklebust 	if (!status)
6393bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6394d3c7b7ccSTrond Myklebust 	return status;
6395d3c7b7ccSTrond Myklebust }
6396d3c7b7ccSTrond Myklebust 
63971da177e4SLinus Torvalds /*
63981da177e4SLinus Torvalds  * Decode READLINK response
63991da177e4SLinus Torvalds  */
6400bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6401bf269551SChuck Lever 				 struct xdr_stream *xdr,
6402f50c7000SBenny Halevy 				 struct nfs4_readlink_res *res)
64031da177e4SLinus Torvalds {
64041da177e4SLinus Torvalds 	struct compound_hdr hdr;
64051da177e4SLinus Torvalds 	int status;
64061da177e4SLinus Torvalds 
6407bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64081da177e4SLinus Torvalds 	if (status)
64091da177e4SLinus Torvalds 		goto out;
6410bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64119b7b9fccSAndy Adamson 	if (status)
64129b7b9fccSAndy Adamson 		goto out;
6413bf269551SChuck Lever 	status = decode_putfh(xdr);
64141da177e4SLinus Torvalds 	if (status)
64151da177e4SLinus Torvalds 		goto out;
6416bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
64171da177e4SLinus Torvalds out:
64181da177e4SLinus Torvalds 	return status;
64191da177e4SLinus Torvalds }
64201da177e4SLinus Torvalds 
64211da177e4SLinus Torvalds /*
64221da177e4SLinus Torvalds  * Decode READDIR response
64231da177e4SLinus Torvalds  */
6424bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6425bf269551SChuck Lever 				struct nfs4_readdir_res *res)
64261da177e4SLinus Torvalds {
64271da177e4SLinus Torvalds 	struct compound_hdr hdr;
64281da177e4SLinus Torvalds 	int status;
64291da177e4SLinus Torvalds 
6430bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64311da177e4SLinus Torvalds 	if (status)
64321da177e4SLinus Torvalds 		goto out;
6433bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64349b7b9fccSAndy Adamson 	if (status)
64359b7b9fccSAndy Adamson 		goto out;
6436bf269551SChuck Lever 	status = decode_putfh(xdr);
64371da177e4SLinus Torvalds 	if (status)
64381da177e4SLinus Torvalds 		goto out;
6439bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
64401da177e4SLinus Torvalds out:
64411da177e4SLinus Torvalds 	return status;
64421da177e4SLinus Torvalds }
64431da177e4SLinus Torvalds 
64441da177e4SLinus Torvalds /*
64451da177e4SLinus Torvalds  * Decode Read response
64461da177e4SLinus Torvalds  */
6447bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6448bf269551SChuck Lever 			     struct nfs_readres *res)
64491da177e4SLinus Torvalds {
64501da177e4SLinus Torvalds 	struct compound_hdr hdr;
64511da177e4SLinus Torvalds 	int status;
64521da177e4SLinus Torvalds 
6453bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64541da177e4SLinus Torvalds 	if (status)
64551da177e4SLinus Torvalds 		goto out;
6456bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64579b7b9fccSAndy Adamson 	if (status)
64589b7b9fccSAndy Adamson 		goto out;
6459bf269551SChuck Lever 	status = decode_putfh(xdr);
64601da177e4SLinus Torvalds 	if (status)
64611da177e4SLinus Torvalds 		goto out;
6462bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
64631da177e4SLinus Torvalds 	if (!status)
64641da177e4SLinus Torvalds 		status = res->count;
64651da177e4SLinus Torvalds out:
64661da177e4SLinus Torvalds 	return status;
64671da177e4SLinus Torvalds }
64681da177e4SLinus Torvalds 
64691da177e4SLinus Torvalds /*
64701da177e4SLinus Torvalds  * Decode WRITE response
64711da177e4SLinus Torvalds  */
6472bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6473bf269551SChuck Lever 			      struct nfs_writeres *res)
64741da177e4SLinus Torvalds {
64751da177e4SLinus Torvalds 	struct compound_hdr hdr;
64761da177e4SLinus Torvalds 	int status;
64771da177e4SLinus Torvalds 
6478bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64791da177e4SLinus Torvalds 	if (status)
64801da177e4SLinus Torvalds 		goto out;
6481bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64829b7b9fccSAndy Adamson 	if (status)
64839b7b9fccSAndy Adamson 		goto out;
6484bf269551SChuck Lever 	status = decode_putfh(xdr);
64851da177e4SLinus Torvalds 	if (status)
64861da177e4SLinus Torvalds 		goto out;
6487bf269551SChuck Lever 	status = decode_write(xdr, res);
64884f9838c7STrond Myklebust 	if (status)
64894f9838c7STrond Myklebust 		goto out;
64907ffd1064SFred Isaman 	if (res->fattr)
64916926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
64921da177e4SLinus Torvalds 	if (!status)
64931da177e4SLinus Torvalds 		status = res->count;
64941da177e4SLinus Torvalds out:
64951da177e4SLinus Torvalds 	return status;
64961da177e4SLinus Torvalds }
64971da177e4SLinus Torvalds 
64981da177e4SLinus Torvalds /*
64991da177e4SLinus Torvalds  * Decode COMMIT response
65001da177e4SLinus Torvalds  */
6501bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
65020b7c0153SFred Isaman 			       struct nfs_commitres *res)
65031da177e4SLinus Torvalds {
65041da177e4SLinus Torvalds 	struct compound_hdr hdr;
65051da177e4SLinus Torvalds 	int status;
65061da177e4SLinus Torvalds 
6507bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65081da177e4SLinus Torvalds 	if (status)
65091da177e4SLinus Torvalds 		goto out;
6510bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65119b7b9fccSAndy Adamson 	if (status)
65129b7b9fccSAndy Adamson 		goto out;
6513bf269551SChuck Lever 	status = decode_putfh(xdr);
65141da177e4SLinus Torvalds 	if (status)
65151da177e4SLinus Torvalds 		goto out;
6516bf269551SChuck Lever 	status = decode_commit(xdr, res);
65171da177e4SLinus Torvalds out:
65181da177e4SLinus Torvalds 	return status;
65191da177e4SLinus Torvalds }
65201da177e4SLinus Torvalds 
65211da177e4SLinus Torvalds /*
65228b173218SRicardo Labiaga  * Decode FSINFO response
65231da177e4SLinus Torvalds  */
6524bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
65253dda5e43SBenny Halevy 			       struct nfs4_fsinfo_res *res)
65261da177e4SLinus Torvalds {
65271da177e4SLinus Torvalds 	struct compound_hdr hdr;
65281da177e4SLinus Torvalds 	int status;
65291da177e4SLinus Torvalds 
6530bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65311da177e4SLinus Torvalds 	if (!status)
6532bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65339b7b9fccSAndy Adamson 	if (!status)
6534bf269551SChuck Lever 		status = decode_putfh(xdr);
65351da177e4SLinus Torvalds 	if (!status)
6536bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
65371da177e4SLinus Torvalds 	return status;
65381da177e4SLinus Torvalds }
65391da177e4SLinus Torvalds 
65401da177e4SLinus Torvalds /*
65418b173218SRicardo Labiaga  * Decode PATHCONF response
65421da177e4SLinus Torvalds  */
6543bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6544d45b2989SBenny Halevy 				 struct nfs4_pathconf_res *res)
65451da177e4SLinus Torvalds {
65461da177e4SLinus Torvalds 	struct compound_hdr hdr;
65471da177e4SLinus Torvalds 	int status;
65481da177e4SLinus Torvalds 
6549bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65501da177e4SLinus Torvalds 	if (!status)
6551bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65529b7b9fccSAndy Adamson 	if (!status)
6553bf269551SChuck Lever 		status = decode_putfh(xdr);
65541da177e4SLinus Torvalds 	if (!status)
6555bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
65561da177e4SLinus Torvalds 	return status;
65571da177e4SLinus Torvalds }
65581da177e4SLinus Torvalds 
65591da177e4SLinus Torvalds /*
65608b173218SRicardo Labiaga  * Decode STATFS response
65611da177e4SLinus Torvalds  */
6562bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
656324ad148aSBenny Halevy 			       struct nfs4_statfs_res *res)
65641da177e4SLinus Torvalds {
65651da177e4SLinus Torvalds 	struct compound_hdr hdr;
65661da177e4SLinus Torvalds 	int status;
65671da177e4SLinus Torvalds 
6568bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65691da177e4SLinus Torvalds 	if (!status)
6570bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65719b7b9fccSAndy Adamson 	if (!status)
6572bf269551SChuck Lever 		status = decode_putfh(xdr);
65731da177e4SLinus Torvalds 	if (!status)
6574bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
65751da177e4SLinus Torvalds 	return status;
65761da177e4SLinus Torvalds }
65771da177e4SLinus Torvalds 
65781da177e4SLinus Torvalds /*
65798b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
65801da177e4SLinus Torvalds  */
6581bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6582bf269551SChuck Lever 				    struct xdr_stream *xdr,
6583bf269551SChuck Lever 				    struct nfs4_server_caps_res *res)
65841da177e4SLinus Torvalds {
65851da177e4SLinus Torvalds 	struct compound_hdr hdr;
65861da177e4SLinus Torvalds 	int status;
65871da177e4SLinus Torvalds 
6588bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65899b7b9fccSAndy Adamson 	if (status)
65909b7b9fccSAndy Adamson 		goto out;
6591bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
65929b7b9fccSAndy Adamson 	if (status)
65931da177e4SLinus Torvalds 		goto out;
6594bf269551SChuck Lever 	status = decode_putfh(xdr);
6595bf269551SChuck Lever 	if (status)
65961da177e4SLinus Torvalds 		goto out;
6597bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
65981da177e4SLinus Torvalds out:
65991da177e4SLinus Torvalds 	return status;
66001da177e4SLinus Torvalds }
66011da177e4SLinus Torvalds 
66021da177e4SLinus Torvalds /*
66031da177e4SLinus Torvalds  * Decode RENEW response
66041da177e4SLinus Torvalds  */
6605bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6606bf269551SChuck Lever 			      void *__unused)
66071da177e4SLinus Torvalds {
66081da177e4SLinus Torvalds 	struct compound_hdr hdr;
66091da177e4SLinus Torvalds 	int status;
66101da177e4SLinus Torvalds 
6611bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66121da177e4SLinus Torvalds 	if (!status)
6613bf269551SChuck Lever 		status = decode_renew(xdr);
66141da177e4SLinus Torvalds 	return status;
66151da177e4SLinus Torvalds }
66161da177e4SLinus Torvalds 
66171da177e4SLinus Torvalds /*
66188b173218SRicardo Labiaga  * Decode SETCLIENTID response
66191da177e4SLinus Torvalds  */
6620bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6621bf269551SChuck Lever 				    struct xdr_stream *xdr,
6622bb8b27e5STrond Myklebust 				    struct nfs4_setclientid_res *res)
66231da177e4SLinus Torvalds {
66241da177e4SLinus Torvalds 	struct compound_hdr hdr;
66251da177e4SLinus Torvalds 	int status;
66261da177e4SLinus Torvalds 
6627bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66281da177e4SLinus Torvalds 	if (!status)
6629bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
66301da177e4SLinus Torvalds 	return status;
66311da177e4SLinus Torvalds }
66321da177e4SLinus Torvalds 
66331da177e4SLinus Torvalds /*
66348b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
66351da177e4SLinus Torvalds  */
6636bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6637bf269551SChuck Lever 					    struct xdr_stream *xdr,
6638bf269551SChuck Lever 					    struct nfs_fsinfo *fsinfo)
66391da177e4SLinus Torvalds {
66401da177e4SLinus Torvalds 	struct compound_hdr hdr;
66411da177e4SLinus Torvalds 	int status;
66421da177e4SLinus Torvalds 
6643bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66441da177e4SLinus Torvalds 	if (!status)
6645bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
66461da177e4SLinus Torvalds 	if (!status)
6647bf269551SChuck Lever 		status = decode_putrootfh(xdr);
66481da177e4SLinus Torvalds 	if (!status)
6649bf269551SChuck Lever 		status = decode_fsinfo(xdr, fsinfo);
66501da177e4SLinus Torvalds 	return status;
66511da177e4SLinus Torvalds }
66521da177e4SLinus Torvalds 
66531da177e4SLinus Torvalds /*
66548b173218SRicardo Labiaga  * Decode DELEGRETURN response
66551da177e4SLinus Torvalds  */
6656bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6657bf269551SChuck Lever 				    struct xdr_stream *xdr,
6658bf269551SChuck Lever 				    struct nfs4_delegreturnres *res)
66591da177e4SLinus Torvalds {
66601da177e4SLinus Torvalds 	struct compound_hdr hdr;
66611da177e4SLinus Torvalds 	int status;
66621da177e4SLinus Torvalds 
6663bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66649b7b9fccSAndy Adamson 	if (status)
66659b7b9fccSAndy Adamson 		goto out;
6666bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66679b7b9fccSAndy Adamson 	if (status)
6668fa178f29STrond Myklebust 		goto out;
6669bf269551SChuck Lever 	status = decode_putfh(xdr);
6670fa178f29STrond Myklebust 	if (status != 0)
6671fa178f29STrond Myklebust 		goto out;
6672e144cbccSTrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
6673556ae3bbSJeff Layton 	if (status != 0)
6674556ae3bbSJeff Layton 		goto out;
6675e144cbccSTrond Myklebust 	status = decode_delegreturn(xdr);
6676fa178f29STrond Myklebust out:
66771da177e4SLinus Torvalds 	return status;
66781da177e4SLinus Torvalds }
66791da177e4SLinus Torvalds 
6680683b57b4STrond Myklebust /*
66818b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6682683b57b4STrond Myklebust  */
6683bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6684bf269551SChuck Lever 				     struct xdr_stream *xdr,
668522958463SBenny Halevy 				     struct nfs4_fs_locations_res *res)
6686683b57b4STrond Myklebust {
6687683b57b4STrond Myklebust 	struct compound_hdr hdr;
6688683b57b4STrond Myklebust 	int status;
6689683b57b4STrond Myklebust 
6690bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66919b7b9fccSAndy Adamson 	if (status)
66929b7b9fccSAndy Adamson 		goto out;
6693bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
66949b7b9fccSAndy Adamson 	if (status)
6695683b57b4STrond Myklebust 		goto out;
6696bf269551SChuck Lever 	status = decode_putfh(xdr);
6697bf269551SChuck Lever 	if (status)
6698683b57b4STrond Myklebust 		goto out;
6699bf269551SChuck Lever 	status = decode_lookup(xdr);
6700bf269551SChuck Lever 	if (status)
6701683b57b4STrond Myklebust 		goto out;
6702bf269551SChuck Lever 	xdr_enter_page(xdr, PAGE_SIZE);
67038b7e3f49STrond Myklebust 	status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
67048b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
67056926afd1STrond Myklebust 					 res->fs_locations->server);
6706683b57b4STrond Myklebust out:
6707683b57b4STrond Myklebust 	return status;
6708683b57b4STrond Myklebust }
6709683b57b4STrond Myklebust 
67105a5ea0d4SBryan Schumaker /*
67115a5ea0d4SBryan Schumaker  * Decode SECINFO response
67125a5ea0d4SBryan Schumaker  */
67135a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
67145a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
67155a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_res *res)
67165a5ea0d4SBryan Schumaker {
67175a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
67185a5ea0d4SBryan Schumaker 	int status;
67195a5ea0d4SBryan Schumaker 
67205a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
67215a5ea0d4SBryan Schumaker 	if (status)
67225a5ea0d4SBryan Schumaker 		goto out;
67235a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67245a5ea0d4SBryan Schumaker 	if (status)
67255a5ea0d4SBryan Schumaker 		goto out;
67265a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
67275a5ea0d4SBryan Schumaker 	if (status)
67285a5ea0d4SBryan Schumaker 		goto out;
67295a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
67305a5ea0d4SBryan Schumaker out:
67315a5ea0d4SBryan Schumaker 	return status;
67325a5ea0d4SBryan Schumaker }
67335a5ea0d4SBryan Schumaker 
673499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
673599fe60d0SBenny Halevy /*
67367c44f1aeSWeston Andros Adamson  * Decode BIND_CONN_TO_SESSION response
67377c44f1aeSWeston Andros Adamson  */
67387c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
67397c44f1aeSWeston Andros Adamson 					struct xdr_stream *xdr,
67407c44f1aeSWeston Andros Adamson 					void *res)
67417c44f1aeSWeston Andros Adamson {
67427c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr;
67437c44f1aeSWeston Andros Adamson 	int status;
67447c44f1aeSWeston Andros Adamson 
67457c44f1aeSWeston Andros Adamson 	status = decode_compound_hdr(xdr, &hdr);
67467c44f1aeSWeston Andros Adamson 	if (!status)
67477c44f1aeSWeston Andros Adamson 		status = decode_bind_conn_to_session(xdr, res);
67487c44f1aeSWeston Andros Adamson 	return status;
67497c44f1aeSWeston Andros Adamson }
67507c44f1aeSWeston Andros Adamson 
67517c44f1aeSWeston Andros Adamson /*
67528b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
675399fe60d0SBenny Halevy  */
6754bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6755bf269551SChuck Lever 				    struct xdr_stream *xdr,
675699fe60d0SBenny Halevy 				    void *res)
675799fe60d0SBenny Halevy {
675899fe60d0SBenny Halevy 	struct compound_hdr hdr;
675999fe60d0SBenny Halevy 	int status;
676099fe60d0SBenny Halevy 
6761bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
676299fe60d0SBenny Halevy 	if (!status)
6763bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
676499fe60d0SBenny Halevy 	return status;
676599fe60d0SBenny Halevy }
67662050f0ccSAndy Adamson 
67672050f0ccSAndy Adamson /*
67688b173218SRicardo Labiaga  * Decode CREATE_SESSION response
6769fc931582SAndy Adamson  */
6770bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6771bf269551SChuck Lever 				       struct xdr_stream *xdr,
6772fc931582SAndy Adamson 				       struct nfs41_create_session_res *res)
6773fc931582SAndy Adamson {
6774fc931582SAndy Adamson 	struct compound_hdr hdr;
6775fc931582SAndy Adamson 	int status;
6776fc931582SAndy Adamson 
6777bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6778fc931582SAndy Adamson 	if (!status)
6779bf269551SChuck Lever 		status = decode_create_session(xdr, res);
6780fc931582SAndy Adamson 	return status;
6781fc931582SAndy Adamson }
6782fc931582SAndy Adamson 
6783fc931582SAndy Adamson /*
67848b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
67850f3e66c6SAndy Adamson  */
6786bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6787bf269551SChuck Lever 					struct xdr_stream *xdr,
6788bf269551SChuck Lever 					void *res)
67890f3e66c6SAndy Adamson {
67900f3e66c6SAndy Adamson 	struct compound_hdr hdr;
67910f3e66c6SAndy Adamson 	int status;
67920f3e66c6SAndy Adamson 
6793bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67940f3e66c6SAndy Adamson 	if (!status)
6795bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
67960f3e66c6SAndy Adamson 	return status;
67970f3e66c6SAndy Adamson }
67980f3e66c6SAndy Adamson 
67990f3e66c6SAndy Adamson /*
680066245539STrond Myklebust  * Decode DESTROY_CLIENTID response
680166245539STrond Myklebust  */
680266245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
680366245539STrond Myklebust 					struct xdr_stream *xdr,
680466245539STrond Myklebust 					void *res)
680566245539STrond Myklebust {
680666245539STrond Myklebust 	struct compound_hdr hdr;
680766245539STrond Myklebust 	int status;
680866245539STrond Myklebust 
680966245539STrond Myklebust 	status = decode_compound_hdr(xdr, &hdr);
681066245539STrond Myklebust 	if (!status)
681166245539STrond Myklebust 		status = decode_destroy_clientid(xdr, res);
681266245539STrond Myklebust 	return status;
681366245539STrond Myklebust }
681466245539STrond Myklebust 
681566245539STrond Myklebust /*
68168b173218SRicardo Labiaga  * Decode SEQUENCE response
6817fc01cea9SAndy Adamson  */
6818bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6819bf269551SChuck Lever 				 struct xdr_stream *xdr,
6820fc01cea9SAndy Adamson 				 struct nfs4_sequence_res *res)
6821fc01cea9SAndy Adamson {
6822fc01cea9SAndy Adamson 	struct compound_hdr hdr;
6823fc01cea9SAndy Adamson 	int status;
6824fc01cea9SAndy Adamson 
6825bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6826fc01cea9SAndy Adamson 	if (!status)
6827bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
6828fc01cea9SAndy Adamson 	return status;
6829fc01cea9SAndy Adamson }
6830fc01cea9SAndy Adamson 
6831fc01cea9SAndy Adamson /*
68328b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
68332050f0ccSAndy Adamson  */
6834bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6835bf269551SChuck Lever 				       struct xdr_stream *xdr,
68362050f0ccSAndy Adamson 				       struct nfs4_get_lease_time_res *res)
68372050f0ccSAndy Adamson {
68382050f0ccSAndy Adamson 	struct compound_hdr hdr;
68392050f0ccSAndy Adamson 	int status;
68402050f0ccSAndy Adamson 
6841bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68422050f0ccSAndy Adamson 	if (!status)
6843bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
68442050f0ccSAndy Adamson 	if (!status)
6845bf269551SChuck Lever 		status = decode_putrootfh(xdr);
68462050f0ccSAndy Adamson 	if (!status)
6847bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
68482050f0ccSAndy Adamson 	return status;
68492050f0ccSAndy Adamson }
685018019753SRicardo Labiaga 
685118019753SRicardo Labiaga /*
685218019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
685318019753SRicardo Labiaga  */
6854bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6855bf269551SChuck Lever 					 struct xdr_stream *xdr,
685618019753SRicardo Labiaga 					 struct nfs41_reclaim_complete_res *res)
685718019753SRicardo Labiaga {
685818019753SRicardo Labiaga 	struct compound_hdr hdr;
685918019753SRicardo Labiaga 	int status;
686018019753SRicardo Labiaga 
6861bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
686218019753SRicardo Labiaga 	if (!status)
6863bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
686418019753SRicardo Labiaga 	if (!status)
6865bf269551SChuck Lever 		status = decode_reclaim_complete(xdr, (void *)NULL);
686618019753SRicardo Labiaga 	return status;
686718019753SRicardo Labiaga }
6868b1f69b75SAndy Adamson 
6869b1f69b75SAndy Adamson /*
68707f11d8d3SAndy Adamson  * Decode GETDEVICELIST response
68717f11d8d3SAndy Adamson  */
68727f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
68737f11d8d3SAndy Adamson 				      struct xdr_stream *xdr,
68747f11d8d3SAndy Adamson 				      struct nfs4_getdevicelist_res *res)
68757f11d8d3SAndy Adamson {
68767f11d8d3SAndy Adamson 	struct compound_hdr hdr;
68777f11d8d3SAndy Adamson 	int status;
68787f11d8d3SAndy Adamson 
68797f11d8d3SAndy Adamson 	dprintk("encoding getdevicelist!\n");
68807f11d8d3SAndy Adamson 
68817f11d8d3SAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
68827f11d8d3SAndy Adamson 	if (status != 0)
68837f11d8d3SAndy Adamson 		goto out;
68847f11d8d3SAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68857f11d8d3SAndy Adamson 	if (status != 0)
68867f11d8d3SAndy Adamson 		goto out;
68877f11d8d3SAndy Adamson 	status = decode_putfh(xdr);
68887f11d8d3SAndy Adamson 	if (status != 0)
68897f11d8d3SAndy Adamson 		goto out;
68907f11d8d3SAndy Adamson 	status = decode_getdevicelist(xdr, res->devlist);
68917f11d8d3SAndy Adamson out:
68927f11d8d3SAndy Adamson 	return status;
68937f11d8d3SAndy Adamson }
68947f11d8d3SAndy Adamson 
68957f11d8d3SAndy Adamson /*
6896b1f69b75SAndy Adamson  * Decode GETDEVINFO response
6897b1f69b75SAndy Adamson  */
6898bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6899bf269551SChuck Lever 				      struct xdr_stream *xdr,
6900b1f69b75SAndy Adamson 				      struct nfs4_getdeviceinfo_res *res)
6901b1f69b75SAndy Adamson {
6902b1f69b75SAndy Adamson 	struct compound_hdr hdr;
6903b1f69b75SAndy Adamson 	int status;
6904b1f69b75SAndy Adamson 
6905bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6906b1f69b75SAndy Adamson 	if (status != 0)
6907b1f69b75SAndy Adamson 		goto out;
6908bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6909b1f69b75SAndy Adamson 	if (status != 0)
6910b1f69b75SAndy Adamson 		goto out;
6911bf269551SChuck Lever 	status = decode_getdeviceinfo(xdr, res->pdev);
6912b1f69b75SAndy Adamson out:
6913b1f69b75SAndy Adamson 	return status;
6914b1f69b75SAndy Adamson }
6915b1f69b75SAndy Adamson 
6916b1f69b75SAndy Adamson /*
6917b1f69b75SAndy Adamson  * Decode LAYOUTGET response
6918b1f69b75SAndy Adamson  */
6919bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6920bf269551SChuck Lever 				  struct xdr_stream *xdr,
6921b1f69b75SAndy Adamson 				  struct nfs4_layoutget_res *res)
6922b1f69b75SAndy Adamson {
6923b1f69b75SAndy Adamson 	struct compound_hdr hdr;
6924b1f69b75SAndy Adamson 	int status;
6925b1f69b75SAndy Adamson 
6926bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6927b1f69b75SAndy Adamson 	if (status)
6928b1f69b75SAndy Adamson 		goto out;
6929bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6930b1f69b75SAndy Adamson 	if (status)
6931b1f69b75SAndy Adamson 		goto out;
6932bf269551SChuck Lever 	status = decode_putfh(xdr);
6933b1f69b75SAndy Adamson 	if (status)
6934b1f69b75SAndy Adamson 		goto out;
6935bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
6936b1f69b75SAndy Adamson out:
6937b1f69b75SAndy Adamson 	return status;
6938b1f69b75SAndy Adamson }
6939863a3c6cSAndy Adamson 
6940863a3c6cSAndy Adamson /*
6941cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
6942cbe82603SBenny Halevy  */
6943cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6944cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
6945cbe82603SBenny Halevy 				     struct nfs4_layoutreturn_res *res)
6946cbe82603SBenny Halevy {
6947cbe82603SBenny Halevy 	struct compound_hdr hdr;
6948cbe82603SBenny Halevy 	int status;
6949cbe82603SBenny Halevy 
6950cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
6951cbe82603SBenny Halevy 	if (status)
6952cbe82603SBenny Halevy 		goto out;
6953cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6954cbe82603SBenny Halevy 	if (status)
6955cbe82603SBenny Halevy 		goto out;
6956cbe82603SBenny Halevy 	status = decode_putfh(xdr);
6957cbe82603SBenny Halevy 	if (status)
6958cbe82603SBenny Halevy 		goto out;
6959cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
6960cbe82603SBenny Halevy out:
6961cbe82603SBenny Halevy 	return status;
6962cbe82603SBenny Halevy }
6963cbe82603SBenny Halevy 
6964cbe82603SBenny Halevy /*
6965863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
6966863a3c6cSAndy Adamson  */
6967863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6968863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
6969863a3c6cSAndy Adamson 				     struct nfs4_layoutcommit_res *res)
6970863a3c6cSAndy Adamson {
6971863a3c6cSAndy Adamson 	struct compound_hdr hdr;
6972863a3c6cSAndy Adamson 	int status;
6973863a3c6cSAndy Adamson 
6974863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
6975863a3c6cSAndy Adamson 	if (status)
6976863a3c6cSAndy Adamson 		goto out;
6977863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6978863a3c6cSAndy Adamson 	if (status)
6979863a3c6cSAndy Adamson 		goto out;
6980863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
6981863a3c6cSAndy Adamson 	if (status)
6982863a3c6cSAndy Adamson 		goto out;
6983863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
6984863a3c6cSAndy Adamson 	if (status)
6985863a3c6cSAndy Adamson 		goto out;
69866926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
6987863a3c6cSAndy Adamson out:
6988863a3c6cSAndy Adamson 	return status;
6989863a3c6cSAndy Adamson }
6990fca78d6dSBryan Schumaker 
6991fca78d6dSBryan Schumaker /*
6992fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
6993fca78d6dSBryan Schumaker  */
6994fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6995fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
6996fca78d6dSBryan Schumaker 					struct nfs4_secinfo_res *res)
6997fca78d6dSBryan Schumaker {
6998fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
6999fca78d6dSBryan Schumaker 	int status;
7000fca78d6dSBryan Schumaker 
7001fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
7002fca78d6dSBryan Schumaker 	if (status)
7003fca78d6dSBryan Schumaker 		goto out;
7004fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7005fca78d6dSBryan Schumaker 	if (status)
7006fca78d6dSBryan Schumaker 		goto out;
7007fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
7008fca78d6dSBryan Schumaker 	if (status)
7009fca78d6dSBryan Schumaker 		goto out;
701031e4dda4SBryan Schumaker 	status = decode_secinfo_no_name(xdr, res);
7011fca78d6dSBryan Schumaker out:
7012fca78d6dSBryan Schumaker 	return status;
7013fca78d6dSBryan Schumaker }
70147d974794SBryan Schumaker 
70157d974794SBryan Schumaker /*
70167d974794SBryan Schumaker  * Decode TEST_STATEID response
70177d974794SBryan Schumaker  */
70187d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
70197d974794SBryan Schumaker 				     struct xdr_stream *xdr,
70207d974794SBryan Schumaker 				     struct nfs41_test_stateid_res *res)
70217d974794SBryan Schumaker {
70227d974794SBryan Schumaker 	struct compound_hdr hdr;
70237d974794SBryan Schumaker 	int status;
70247d974794SBryan Schumaker 
70257d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
70267d974794SBryan Schumaker 	if (status)
70277d974794SBryan Schumaker 		goto out;
70287d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
70297d974794SBryan Schumaker 	if (status)
70307d974794SBryan Schumaker 		goto out;
70317d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
70327d974794SBryan Schumaker out:
70337d974794SBryan Schumaker 	return status;
70347d974794SBryan Schumaker }
70359aeda35fSBryan Schumaker 
70369aeda35fSBryan Schumaker /*
70379aeda35fSBryan Schumaker  * Decode FREE_STATEID response
70389aeda35fSBryan Schumaker  */
70399aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
70409aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
70419aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_res *res)
70429aeda35fSBryan Schumaker {
70439aeda35fSBryan Schumaker 	struct compound_hdr hdr;
70449aeda35fSBryan Schumaker 	int status;
70459aeda35fSBryan Schumaker 
70469aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
70479aeda35fSBryan Schumaker 	if (status)
70489aeda35fSBryan Schumaker 		goto out;
70499aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
70509aeda35fSBryan Schumaker 	if (status)
70519aeda35fSBryan Schumaker 		goto out;
70529aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
70539aeda35fSBryan Schumaker out:
70549aeda35fSBryan Schumaker 	return status;
70559aeda35fSBryan Schumaker }
705699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
705799fe60d0SBenny Halevy 
7058573c4e1eSChuck Lever /**
7059573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7060573c4e1eSChuck Lever  *                      the local page cache.
7061573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7062573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7063573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7064573c4e1eSChuck Lever  *
7065573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7066573c4e1eSChuck Lever  * returned.
7067573c4e1eSChuck Lever  *
7068573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7069573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7070573c4e1eSChuck Lever  * on a directory already in our cache.
7071573c4e1eSChuck Lever  */
7072573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7073573c4e1eSChuck Lever 		       int plus)
70741da177e4SLinus Torvalds {
7075256e48bbSTrond Myklebust 	unsigned int savep;
7076dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
70771da177e4SLinus Torvalds 	uint32_t len;
7078babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7079babddc72SBryan Schumaker 	if (unlikely(!p))
7080babddc72SBryan Schumaker 		goto out_overflow;
7081c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7082babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7083babddc72SBryan Schumaker 		if (unlikely(!p))
7084babddc72SBryan Schumaker 			goto out_overflow;
7085c08e76d0SChuck Lever 		if (*p == xdr_zero)
7086573c4e1eSChuck Lever 			return -EAGAIN;
70871da177e4SLinus Torvalds 		entry->eof = 1;
7088573c4e1eSChuck Lever 		return -EBADCOOKIE;
70891da177e4SLinus Torvalds 	}
70901da177e4SLinus Torvalds 
7091babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7092babddc72SBryan Schumaker 	if (unlikely(!p))
7093babddc72SBryan Schumaker 		goto out_overflow;
70941da177e4SLinus Torvalds 	entry->prev_cookie = entry->cookie;
70951da177e4SLinus Torvalds 	p = xdr_decode_hyper(p, &entry->cookie);
7096c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7097babddc72SBryan Schumaker 
70989af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7099babddc72SBryan Schumaker 	if (unlikely(!p))
7100babddc72SBryan Schumaker 		goto out_overflow;
71011da177e4SLinus Torvalds 	entry->name = (const char *) p;
71021da177e4SLinus Torvalds 
71031da177e4SLinus Torvalds 	/*
71041da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
71051da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
71061da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
71071da177e4SLinus Torvalds 	 */
71081da177e4SLinus Torvalds 	entry->ino = 1;
71094f082222STrond Myklebust 	entry->fattr->valid = 0;
71101da177e4SLinus Torvalds 
71119af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7112babddc72SBryan Schumaker 		goto out_overflow;
71139af8c222STrond Myklebust 
7114256e48bbSTrond Myklebust 	if (decode_attr_length(xdr, &len, &savep) < 0)
7115babddc72SBryan Schumaker 		goto out_overflow;
71169af8c222STrond Myklebust 
7117573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
71188b7e3f49STrond Myklebust 				  NULL, entry->server) < 0)
7119babddc72SBryan Schumaker 		goto out_overflow;
712028331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
712128331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
712228331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
712382f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
71249af8c222STrond Myklebust 
71250b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
71260b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
71270b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
71280b26a0bfSTrond Myklebust 
7129573c4e1eSChuck Lever 	return 0;
7130babddc72SBryan Schumaker 
7131babddc72SBryan Schumaker out_overflow:
7132babddc72SBryan Schumaker 	print_overflow_msg(__func__, xdr);
7133573c4e1eSChuck Lever 	return -EAGAIN;
71341da177e4SLinus Torvalds }
71351da177e4SLinus Torvalds 
71361da177e4SLinus Torvalds /*
71371da177e4SLinus Torvalds  * We need to translate between nfs status return values and
71381da177e4SLinus Torvalds  * the local errno values which may not be the same.
71391da177e4SLinus Torvalds  */
71401da177e4SLinus Torvalds static struct {
71411da177e4SLinus Torvalds 	int stat;
71421da177e4SLinus Torvalds 	int errno;
71431da177e4SLinus Torvalds } nfs_errtbl[] = {
71441da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7145856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7146856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7147856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7148856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7149856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7150856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7151856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7152856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7153856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7154856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7155856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7156856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7157856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7158856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7159856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7160856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7161856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7162856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7163856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7164856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7165856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7166856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7167fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7168856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7169856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7170856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7171856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7172856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7173856dff3dSBenny Halevy 	{ -1,			-EIO		}
71741da177e4SLinus Torvalds };
71751da177e4SLinus Torvalds 
71761da177e4SLinus Torvalds /*
71771da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
71781da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
71791da177e4SLinus Torvalds  */
71801da177e4SLinus Torvalds static int
71810a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
71821da177e4SLinus Torvalds {
71831da177e4SLinus Torvalds 	int i;
71841da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
71851da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
71861da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
71871da177e4SLinus Torvalds 	}
71881da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
71891da177e4SLinus Torvalds 		/* The server is looney tunes. */
7190fdcb4577STrond Myklebust 		return -EREMOTEIO;
71911da177e4SLinus Torvalds 	}
71921da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
71931da177e4SLinus Torvalds 	 * handle it.
71941da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
71951da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
71961da177e4SLinus Torvalds 	 */
7197856dff3dSBenny Halevy 	return -stat;
71981da177e4SLinus Torvalds }
71991da177e4SLinus Torvalds 
72001da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
72011da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
72021da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
72039f06c719SChuck Lever 	.p_encode = (kxdreproc_t)nfs4_xdr_##argtype,		\
7204bf269551SChuck Lever 	.p_decode = (kxdrdproc_t)nfs4_xdr_##restype,		\
72052bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
72062bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7207cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7208cc0175c1SChuck Lever 	.p_name   = #proc,					\
72091da177e4SLinus Torvalds }
72101da177e4SLinus Torvalds 
72111da177e4SLinus Torvalds struct rpc_procinfo	nfs4_procedures[] = {
72121da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
72131da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
72141da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
72151da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
72161da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
72171da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
72181da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
72191da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
72201da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
72211da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
72221da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
72231da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
72241da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
72251da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
72261da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
72271da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
72281da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
72291da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
72301da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
72311da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
72321da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
72331da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
72341da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
72351da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
72361da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
72371da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
72381da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
72391da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
72401da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
72411da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
72421da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7243029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
724423ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7245683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7246d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
72475a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
724899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
724999fe60d0SBenny Halevy 	PROC(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
7250fc931582SAndy Adamson 	PROC(CREATE_SESSION,	enc_create_session,	dec_create_session),
72510f3e66c6SAndy Adamson 	PROC(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
7252fc01cea9SAndy Adamson 	PROC(SEQUENCE,		enc_sequence,		dec_sequence),
72532050f0ccSAndy Adamson 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
725418019753SRicardo Labiaga 	PROC(RECLAIM_COMPLETE,	enc_reclaim_complete,	dec_reclaim_complete),
7255b1f69b75SAndy Adamson 	PROC(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
7256b1f69b75SAndy Adamson 	PROC(LAYOUTGET,		enc_layoutget,		dec_layoutget),
7257863a3c6cSAndy Adamson 	PROC(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
7258cbe82603SBenny Halevy 	PROC(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
7259fca78d6dSBryan Schumaker 	PROC(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
72607d974794SBryan Schumaker 	PROC(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
72619aeda35fSBryan Schumaker 	PROC(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
72627f11d8d3SAndy Adamson 	PROC(GETDEVICELIST,	enc_getdevicelist,	dec_getdevicelist),
7263ad24ecfbSTrond Myklebust 	PROC(BIND_CONN_TO_SESSION,
7264ad24ecfbSTrond Myklebust 			enc_bind_conn_to_session, dec_bind_conn_to_session),
726566245539STrond Myklebust 	PROC(DESTROY_CLIENTID,	enc_destroy_clientid,	dec_destroy_clientid),
726699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
72671da177e4SLinus Torvalds };
72681da177e4SLinus Torvalds 
7269a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
72701da177e4SLinus Torvalds 	.number			= 4,
7271e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
72721da177e4SLinus Torvalds 	.procs			= nfs4_procedures
72731da177e4SLinus Torvalds };
72741da177e4SLinus Torvalds 
72751da177e4SLinus Torvalds /*
72761da177e4SLinus Torvalds  * Local variables:
72771da177e4SLinus Torvalds  *  c-basic-offset: 8
72781da177e4SLinus Torvalds  * End:
72791da177e4SLinus Torvalds  */
7280