xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision d0b496d2)
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>
564ce79717STrond Myklebust #include "nfs4_fs.h"
574882ef72SAlexandros Batsakis #include "internal.h"
58b1f69b75SAndy Adamson #include "pnfs.h"
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_XDR
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
631da177e4SLinus Torvalds #define errno_NFSERR_IO		EIO
641da177e4SLinus Torvalds 
650a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
681da177e4SLinus Torvalds #ifdef DEBUG
691da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		20
701da177e4SLinus Torvalds #else
711da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		0
721da177e4SLinus Torvalds #endif
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds /* lock,open owner id:
759f958ab8STrond Myklebust  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
761da177e4SLinus Torvalds  */
77d035c36cSTrond Myklebust #define open_owner_id_maxsz	(1 + 1 + 4)
78d035c36cSTrond Myklebust #define lock_owner_id_maxsz	(1 + 1 + 4)
799104a55dSTrond Myklebust #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
801da177e4SLinus Torvalds #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
811da177e4SLinus Torvalds #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
821da177e4SLinus Torvalds #define op_encode_hdr_maxsz	(1)
831da177e4SLinus Torvalds #define op_decode_hdr_maxsz	(2)
849104a55dSTrond Myklebust #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
859104a55dSTrond Myklebust #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
869104a55dSTrond Myklebust #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
879104a55dSTrond Myklebust #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
881da177e4SLinus Torvalds #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
891da177e4SLinus Torvalds 				(NFS4_FHSIZE >> 2))
901da177e4SLinus Torvalds #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
911da177e4SLinus Torvalds #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
921da177e4SLinus Torvalds #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
931da177e4SLinus Torvalds #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
941da177e4SLinus Torvalds #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
951da177e4SLinus Torvalds 				((3+NFS4_FHSIZE) >> 2))
96e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
9796928206SJ. Bruce Fields #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
981da177e4SLinus Torvalds #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
991da177e4SLinus Torvalds #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
100bd625ba8STrond Myklebust #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
101bd625ba8STrond Myklebust #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
10296928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
10396928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
104bd625ba8STrond Myklebust 				3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
10596928206SJ. Bruce Fields #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
10696928206SJ. Bruce Fields 				nfs4_fattr_value_maxsz)
10796928206SJ. Bruce Fields #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1089104a55dSTrond Myklebust #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
1099104a55dSTrond Myklebust 				 1 + 2 + 1 + \
1109104a55dSTrond Myklebust 				nfs4_owner_maxsz + \
1119104a55dSTrond Myklebust 				nfs4_group_maxsz + \
1129104a55dSTrond Myklebust 				4 + 4)
1131da177e4SLinus Torvalds #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
1141da177e4SLinus Torvalds #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
11556ae19f3STrond Myklebust #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
11656ae19f3STrond Myklebust #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
1172f42b5d0SFred Isaman #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
118dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
119dae100c2SFred Isaman  * layout types will be returned.
120dae100c2SFred Isaman  */
121dae100c2SFred Isaman #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
122dae100c2SFred Isaman 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1231da177e4SLinus Torvalds #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
1241da177e4SLinus Torvalds #define decode_renew_maxsz	(op_decode_hdr_maxsz)
1251da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1261da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
127cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129cc38bac3SChuck Lever 				1 /* sc_prog */ + \
130cc38bac3SChuck Lever 				XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131cc38bac3SChuck Lever 				XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132cc38bac3SChuck Lever 				1) /* sc_cb_ident */
1331da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1341da177e4SLinus Torvalds 				(op_decode_hdr_maxsz + \
1351da177e4SLinus Torvalds 				2 + \
1361da177e4SLinus Torvalds 				1024) /* large value for CLID_INUSE */
1371da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1381da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
1391da177e4SLinus Torvalds 				3 + (NFS4_VERIFIER_SIZE >> 2))
1401da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1411da177e4SLinus Torvalds 				(op_decode_hdr_maxsz)
142e6889620STrond Myklebust #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
143e6889620STrond Myklebust #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
1442cebf828STrond Myklebust #define encode_share_access_maxsz \
1452cebf828STrond Myklebust 				(2)
1464882ef72SAlexandros Batsakis #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
1472cebf828STrond Myklebust #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
1482cebf828STrond Myklebust #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
1492cebf828STrond Myklebust #define encode_open_maxsz	(op_encode_hdr_maxsz + \
1502cebf828STrond Myklebust 				2 + encode_share_access_maxsz + 2 + \
1512cebf828STrond Myklebust 				open_owner_id_maxsz + \
1522cebf828STrond Myklebust 				encode_opentype_maxsz + \
1532cebf828STrond Myklebust 				encode_claim_null_maxsz)
1542cebf828STrond Myklebust #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
1559104a55dSTrond Myklebust #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
1562cebf828STrond Myklebust 				decode_ace_maxsz)
1572cebf828STrond Myklebust #define decode_change_info_maxsz	(5)
1582cebf828STrond Myklebust #define decode_open_maxsz	(op_decode_hdr_maxsz + \
1599104a55dSTrond Myklebust 				decode_stateid_maxsz + \
1602cebf828STrond Myklebust 				decode_change_info_maxsz + 1 + \
1612cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz + \
1622cebf828STrond Myklebust 				decode_delegation_maxsz)
1639104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
1649104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1659104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1)
1669104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
1679104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1689104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1699104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
1709104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1719104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1 + \
1729104a55dSTrond Myklebust 				 encode_share_access_maxsz)
1739104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
1749104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1759104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1769104a55dSTrond Myklebust #define encode_close_maxsz	(op_encode_hdr_maxsz + \
1779104a55dSTrond Myklebust 				 1 + encode_stateid_maxsz)
1789104a55dSTrond Myklebust #define decode_close_maxsz	(op_decode_hdr_maxsz + \
1799104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1809104a55dSTrond Myklebust #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
1819104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
1829104a55dSTrond Myklebust 				 encode_attrs_maxsz)
1839104a55dSTrond Myklebust #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
1849104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz)
1859104a55dSTrond Myklebust #define encode_read_maxsz	(op_encode_hdr_maxsz + \
1869104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
1879104a55dSTrond Myklebust #define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
1889104a55dSTrond Myklebust #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
1899104a55dSTrond Myklebust 				 2 + encode_verifier_maxsz + 5)
1909104a55dSTrond Myklebust #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
1919104a55dSTrond Myklebust 				 decode_verifier_maxsz)
1929104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
1939104a55dSTrond Myklebust #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
1949104a55dSTrond Myklebust #define encode_write_maxsz	(op_encode_hdr_maxsz + \
1959104a55dSTrond Myklebust 				 encode_stateid_maxsz + 4)
1969104a55dSTrond Myklebust #define decode_write_maxsz	(op_decode_hdr_maxsz + \
1979104a55dSTrond Myklebust 				 2 + decode_verifier_maxsz)
1989104a55dSTrond Myklebust #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
1999104a55dSTrond Myklebust #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
2009104a55dSTrond Myklebust 				 decode_verifier_maxsz)
2011da177e4SLinus Torvalds #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
2021da177e4SLinus Torvalds 				nfs4_name_maxsz)
2036ce18391SBenny Halevy #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
2046ce18391SBenny Halevy 				 decode_change_info_maxsz)
2051da177e4SLinus Torvalds #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
2061da177e4SLinus Torvalds 				2 * nfs4_name_maxsz)
2076ce18391SBenny Halevy #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
2086ce18391SBenny Halevy 				 decode_change_info_maxsz + \
2096ce18391SBenny Halevy 				 decode_change_info_maxsz)
2101da177e4SLinus Torvalds #define encode_link_maxsz	(op_encode_hdr_maxsz + \
2111da177e4SLinus Torvalds 				nfs4_name_maxsz)
2126ce18391SBenny Halevy #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
213daccbdedSTrond Myklebust #define encode_lockowner_maxsz	(7)
2149104a55dSTrond Myklebust #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
2159104a55dSTrond Myklebust 				 7 + \
216daccbdedSTrond Myklebust 				 1 + encode_stateid_maxsz + 1 + \
217daccbdedSTrond Myklebust 				 encode_lockowner_maxsz)
2189104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2199104a55dSTrond Myklebust 				(8 + decode_lockowner_maxsz)
2209104a55dSTrond Myklebust #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
2219104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
222daccbdedSTrond Myklebust #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
223daccbdedSTrond Myklebust 				encode_lockowner_maxsz)
2249104a55dSTrond Myklebust #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
2259104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
2269104a55dSTrond Myklebust #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
2279104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2289104a55dSTrond Myklebust 				 4)
2299104a55dSTrond Myklebust #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
2309104a55dSTrond Myklebust 				 decode_stateid_maxsz)
231d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
232d3c7b7ccSTrond Myklebust 				(op_encode_hdr_maxsz + \
233d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
234d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
235d3c7b7ccSTrond Myklebust 				(op_decode_hdr_maxsz)
2369104a55dSTrond Myklebust #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
2379104a55dSTrond Myklebust #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
2381da177e4SLinus Torvalds #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
2391da177e4SLinus Torvalds 				1 + nfs4_name_maxsz + \
24094a6d753SChuck Lever 				1 + \
24196928206SJ. Bruce Fields 				nfs4_fattr_maxsz)
2421da177e4SLinus Torvalds #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
2431da177e4SLinus Torvalds #define encode_create_maxsz	(op_encode_hdr_maxsz + \
2449104a55dSTrond Myklebust 				1 + 2 + nfs4_name_maxsz + \
2459104a55dSTrond Myklebust 				encode_attrs_maxsz)
2462cebf828STrond Myklebust #define decode_create_maxsz	(op_decode_hdr_maxsz + \
2472cebf828STrond Myklebust 				decode_change_info_maxsz + \
2482cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz)
2499104a55dSTrond Myklebust #define encode_statfs_maxsz	(encode_getattr_maxsz)
2509104a55dSTrond Myklebust #define decode_statfs_maxsz	(decode_getattr_maxsz)
2511da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2521da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2539104a55dSTrond Myklebust #define encode_getacl_maxsz	(encode_getattr_maxsz)
2549104a55dSTrond Myklebust #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
2559104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz + 1)
2569104a55dSTrond Myklebust #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
2579104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2589104a55dSTrond Myklebust #define decode_setacl_maxsz	(decode_setattr_maxsz)
259e6889620STrond Myklebust #define encode_fs_locations_maxsz \
260e6889620STrond Myklebust 				(encode_getattr_maxsz)
261e6889620STrond Myklebust #define decode_fs_locations_maxsz \
262e6889620STrond Myklebust 				(0)
2635a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
2641650add2SBryan Schumaker #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
2659b7b9fccSAndy Adamson 
2669b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
267fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
268fc931582SAndy Adamson 
26999fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
27099fe60d0SBenny Halevy 				encode_verifier_maxsz + \
27199fe60d0SBenny Halevy 				1 /* co_ownerid.len */ + \
27299fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
27399fe60d0SBenny Halevy 				1 /* flags */ + \
27499fe60d0SBenny Halevy 				1 /* spa_how */ + \
27599fe60d0SBenny Halevy 				0 /* SP4_NONE (for now) */ + \
276db8ac8baSWeston Andros Adamson 				1 /* implementation id array of size 1 */ + \
277db8ac8baSWeston Andros Adamson 				1 /* nii_domain */ + \
278db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279db8ac8baSWeston Andros Adamson 				1 /* nii_name */ + \
280db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281db8ac8baSWeston Andros Adamson 				3 /* nii_date */)
28299fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
28399fe60d0SBenny Halevy 				2 /* eir_clientid */ + \
28499fe60d0SBenny Halevy 				1 /* eir_sequenceid */ + \
28599fe60d0SBenny Halevy 				1 /* eir_flags */ + \
28699fe60d0SBenny Halevy 				1 /* spr_how */ + \
28799fe60d0SBenny Halevy 				0 /* SP4_NONE (for now) */ + \
28899fe60d0SBenny Halevy 				2 /* eir_server_owner.so_minor_id */ + \
28999fe60d0SBenny Halevy 				/* eir_server_owner.so_major_id<> */ \
29099fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
29199fe60d0SBenny Halevy 				/* eir_server_scope<> */ \
29299fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
29399fe60d0SBenny Halevy 				1 /* eir_server_impl_id array length */ + \
2947d2ed9acSWeston Andros Adamson 				1 /* nii_domain */ + \
2957d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
2967d2ed9acSWeston Andros Adamson 				1 /* nii_name */ + \
2977d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
2987d2ed9acSWeston Andros Adamson 				3 /* nii_date */)
299fc931582SAndy Adamson #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
300fc931582SAndy Adamson #define decode_channel_attrs_maxsz  (6 + \
301fc931582SAndy Adamson 				     1 /* ca_rdma_ird.len */ + \
302fc931582SAndy Adamson 				     1 /* ca_rdma_ird */)
303fc931582SAndy Adamson #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
304fc931582SAndy Adamson 				     2 /* csa_clientid */ + \
305fc931582SAndy Adamson 				     1 /* csa_sequence */ + \
306fc931582SAndy Adamson 				     1 /* csa_flags */ + \
307fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
308fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
309fc931582SAndy Adamson 				     1 /* csa_cb_program */ + \
310fc931582SAndy Adamson 				     1 /* csa_sec_parms.len (1) */ + \
311fc931582SAndy Adamson 				     1 /* cb_secflavor (AUTH_SYS) */ + \
312fc931582SAndy Adamson 				     1 /* stamp */ + \
313fc931582SAndy Adamson 				     1 /* machinename.len */ + \
314fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315fc931582SAndy Adamson 				     1 /* uid */ + \
316fc931582SAndy Adamson 				     1 /* gid */ + \
317fc931582SAndy Adamson 				     1 /* gids.len (0) */)
318fc931582SAndy Adamson #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
319fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320fc931582SAndy Adamson 				     1 /* csr_sequence */ + \
321fc931582SAndy Adamson 				     1 /* csr_flags */ + \
322fc931582SAndy Adamson 				     decode_channel_attrs_maxsz + \
323fc931582SAndy Adamson 				     decode_channel_attrs_maxsz)
3240f3e66c6SAndy Adamson #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
3250f3e66c6SAndy Adamson #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
326fc01cea9SAndy Adamson #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
327fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328fc01cea9SAndy Adamson #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
329fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
33018019753SRicardo Labiaga #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
33118019753SRicardo Labiaga #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
3327f11d8d3SAndy Adamson #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
3337f11d8d3SAndy Adamson 				encode_verifier_maxsz)
3347f11d8d3SAndy Adamson #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
3357f11d8d3SAndy Adamson 				2 /* nfs_cookie4 gdlr_cookie */ + \
3367f11d8d3SAndy Adamson 				decode_verifier_maxsz \
3377f11d8d3SAndy Adamson 				  /* verifier4 gdlr_verifier */ + \
3387f11d8d3SAndy Adamson 				1 /* gdlr_deviceid_list count */ + \
3397f11d8d3SAndy Adamson 				XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
3407f11d8d3SAndy Adamson 					    NFS4_DEVICEID4_SIZE) \
3417f11d8d3SAndy Adamson 				  /* gdlr_deviceid_list */ + \
3427f11d8d3SAndy Adamson 				1 /* bool gdlr_eof */)
343b1f69b75SAndy Adamson #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344b1f69b75SAndy Adamson 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346b1f69b75SAndy Adamson 				1 /* layout type */ + \
347b1f69b75SAndy Adamson 				1 /* opaque devaddr4 length */ + \
348b1f69b75SAndy Adamson 				  /* devaddr4 payload is read into page */ \
349b1f69b75SAndy Adamson 				1 /* notification bitmap length */ + \
350b1f69b75SAndy Adamson 				1 /* notification bitmap */)
351b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
352b1f69b75SAndy Adamson 				encode_stateid_maxsz)
353b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
354b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
355b1f69b75SAndy Adamson 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
356863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
357863a3c6cSAndy Adamson 				2 /* offset */ + \
358863a3c6cSAndy Adamson 				2 /* length */ + \
359863a3c6cSAndy Adamson 				1 /* reclaim */ + \
360863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
361863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
362863a3c6cSAndy Adamson 				2 /* last byte written */ + \
363863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
364863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
365863a3c6cSAndy Adamson 				1 /* NULL filelayout layoutupdate4 payload */)
366863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
367cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368cbe82603SBenny Halevy 				encode_stateid_maxsz + \
369cbe82603SBenny Halevy 				1 /* FIXME: opaque lrf_body always empty at the moment */)
370cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
372fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
3747d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
3757d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
3767d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
3779aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
3789aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
3799aeda35fSBryan Schumaker #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz + 1)
3809b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
3819b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
3829b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
3839b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
3849b7b9fccSAndy Adamson 
3851da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
3861da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
3871da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
3889b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
3891da177e4SLinus Torvalds 				encode_putfh_maxsz + \
3909104a55dSTrond Myklebust 				encode_read_maxsz)
3911da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
3929b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
3931da177e4SLinus Torvalds 				decode_putfh_maxsz + \
3949104a55dSTrond Myklebust 				decode_read_maxsz)
3951da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
3969b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
3971da177e4SLinus Torvalds 				encode_putfh_maxsz + \
3989104a55dSTrond Myklebust 				encode_readlink_maxsz)
3991da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4009b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4011da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4029104a55dSTrond Myklebust 				decode_readlink_maxsz)
4031da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4049b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4051da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4069104a55dSTrond Myklebust 				encode_readdir_maxsz)
4071da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4089b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4091da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4109104a55dSTrond Myklebust 				decode_readdir_maxsz)
4111da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4129b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4131da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4149104a55dSTrond Myklebust 				encode_write_maxsz + \
4154f9838c7STrond Myklebust 				encode_getattr_maxsz)
4161da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4179b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4181da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4199104a55dSTrond Myklebust 				decode_write_maxsz + \
4204f9838c7STrond Myklebust 				decode_getattr_maxsz)
4211da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4229b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4231da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4249104a55dSTrond Myklebust 				encode_commit_maxsz + \
4254f9838c7STrond Myklebust 				encode_getattr_maxsz)
4261da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4279b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4281da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4299104a55dSTrond Myklebust 				decode_commit_maxsz + \
4304f9838c7STrond Myklebust 				decode_getattr_maxsz)
4311da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4329b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4331da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4342cebf828STrond Myklebust 				encode_savefh_maxsz + \
4352cebf828STrond Myklebust 				encode_open_maxsz + \
4362cebf828STrond Myklebust 				encode_getfh_maxsz + \
4371da177e4SLinus Torvalds 				encode_getattr_maxsz + \
4382cebf828STrond Myklebust 				encode_restorefh_maxsz + \
4392cebf828STrond Myklebust 				encode_getattr_maxsz)
4401da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4419b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4421da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4432cebf828STrond Myklebust 				decode_savefh_maxsz + \
4442cebf828STrond Myklebust 				decode_open_maxsz + \
4452cebf828STrond Myklebust 				decode_getfh_maxsz + \
4461da177e4SLinus Torvalds 				decode_getattr_maxsz + \
4472cebf828STrond Myklebust 				decode_restorefh_maxsz + \
4482cebf828STrond Myklebust 				decode_getattr_maxsz)
4491da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
4501da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4511da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4529104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
4539104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
4549104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
4551da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4569104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
4571da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
4589b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
4591da177e4SLinus Torvalds 					encode_putfh_maxsz + \
4602cebf828STrond Myklebust 					encode_open_maxsz + \
4612cebf828STrond Myklebust 					encode_getattr_maxsz)
4621da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
4639b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
4641da177e4SLinus Torvalds 					decode_putfh_maxsz + \
4652cebf828STrond Myklebust 					decode_open_maxsz + \
4662cebf828STrond Myklebust 					decode_getattr_maxsz)
4671da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
4681da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4699b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
4701da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4719104a55dSTrond Myklebust 				 encode_open_downgrade_maxsz + \
472516a6af6STrond Myklebust 				 encode_getattr_maxsz)
4731da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
4741da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
4759b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
4761da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4779104a55dSTrond Myklebust 				 decode_open_downgrade_maxsz + \
478516a6af6STrond Myklebust 				 decode_getattr_maxsz)
4791da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
4809b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
4811da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4829104a55dSTrond Myklebust 				 encode_close_maxsz + \
483516a6af6STrond Myklebust 				 encode_getattr_maxsz)
4841da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
4859b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
4861da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4879104a55dSTrond Myklebust 				 decode_close_maxsz + \
488516a6af6STrond Myklebust 				 decode_getattr_maxsz)
4891da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
4909b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
4911da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4929104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
4931da177e4SLinus Torvalds 				 encode_getattr_maxsz)
4941da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
4959b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
4961da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4979104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
4989104a55dSTrond Myklebust 				 decode_getattr_maxsz)
4991da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5009b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5011da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5021da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5031da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5049b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5051da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5061da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5071da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5081da177e4SLinus Torvalds 				encode_renew_maxsz)
5091da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5101da177e4SLinus Torvalds 				decode_renew_maxsz)
5111da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5121da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5131da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5141da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5151da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5161da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5171da177e4SLinus Torvalds 				encode_setclientid_confirm_maxsz + \
5181da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
5191da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5201da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5211da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5221da177e4SLinus Torvalds 				decode_setclientid_confirm_maxsz + \
5231da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
5241da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5251da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5269b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5271da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5289104a55dSTrond Myklebust 				encode_lock_maxsz)
5291da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5309b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5311da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5329104a55dSTrond Myklebust 				decode_lock_maxsz)
5331da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5349b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5351da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5369104a55dSTrond Myklebust 				encode_lockt_maxsz)
5379104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5389b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5399104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5409104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5411da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5429b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5431da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5449104a55dSTrond Myklebust 				encode_locku_maxsz)
5451da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5469b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5471da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5489104a55dSTrond Myklebust 				decode_locku_maxsz)
549d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
550d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
551d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
552d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
553d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
554d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
5551da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
5569b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5571da177e4SLinus Torvalds 				encode_putfh_maxsz + \
55876b32999STrond Myklebust 				encode_access_maxsz + \
55976b32999STrond Myklebust 				encode_getattr_maxsz)
5601da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
5619b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5621da177e4SLinus Torvalds 				decode_putfh_maxsz + \
56376b32999STrond Myklebust 				decode_access_maxsz + \
56476b32999STrond Myklebust 				decode_getattr_maxsz)
5651da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
5669b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5671da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5681da177e4SLinus Torvalds 				encode_getattr_maxsz)
5691da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
5709b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5711da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5721da177e4SLinus Torvalds 				decode_getattr_maxsz)
5731da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
5749b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5751da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5761da177e4SLinus Torvalds 				encode_lookup_maxsz + \
5771da177e4SLinus Torvalds 				encode_getattr_maxsz + \
5781da177e4SLinus Torvalds 				encode_getfh_maxsz)
5791da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
5809b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5811da177e4SLinus Torvalds 				decode_putfh_maxsz + \
582e6889620STrond Myklebust 				decode_lookup_maxsz + \
5831da177e4SLinus Torvalds 				decode_getattr_maxsz + \
5841da177e4SLinus Torvalds 				decode_getfh_maxsz)
5851da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
5869b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5871da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
5881da177e4SLinus Torvalds 				encode_getattr_maxsz + \
5891da177e4SLinus Torvalds 				encode_getfh_maxsz)
5901da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
5919b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5921da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
5931da177e4SLinus Torvalds 				decode_getattr_maxsz + \
5941da177e4SLinus Torvalds 				decode_getfh_maxsz)
5951da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
5969b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5971da177e4SLinus Torvalds 				encode_putfh_maxsz + \
59816e42959STrond Myklebust 				encode_remove_maxsz + \
59916e42959STrond Myklebust 				encode_getattr_maxsz)
6001da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6019b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6021da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6036ce18391SBenny Halevy 				decode_remove_maxsz + \
60416e42959STrond Myklebust 				decode_getattr_maxsz)
6051da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6069b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6071da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6081da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6091da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6106caf2c82STrond Myklebust 				encode_rename_maxsz + \
6116caf2c82STrond Myklebust 				encode_getattr_maxsz + \
6126caf2c82STrond Myklebust 				encode_restorefh_maxsz + \
6136caf2c82STrond Myklebust 				encode_getattr_maxsz)
6141da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6159b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6161da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6171da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6181da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6196caf2c82STrond Myklebust 				decode_rename_maxsz + \
6206caf2c82STrond Myklebust 				decode_getattr_maxsz + \
6216caf2c82STrond Myklebust 				decode_restorefh_maxsz + \
6226caf2c82STrond Myklebust 				decode_getattr_maxsz)
6231da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6249b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6251da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6261da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6271da177e4SLinus Torvalds 				encode_putfh_maxsz + \
62891ba2eeeSTrond Myklebust 				encode_link_maxsz + \
62991ba2eeeSTrond Myklebust 				decode_getattr_maxsz + \
63091ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
63191ba2eeeSTrond Myklebust 				decode_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_getattr_maxsz + \
63991ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
64091ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6411da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6429b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6431da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6441da177e4SLinus Torvalds 				encode_symlink_maxsz + \
6451da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6461da177e4SLinus Torvalds 				encode_getfh_maxsz)
6471da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
6489b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6491da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6501da177e4SLinus Torvalds 				decode_symlink_maxsz + \
6511da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6521da177e4SLinus Torvalds 				decode_getfh_maxsz)
6531da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
6549b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6551da177e4SLinus Torvalds 				encode_putfh_maxsz + \
65656ae19f3STrond Myklebust 				encode_savefh_maxsz + \
6571da177e4SLinus Torvalds 				encode_create_maxsz + \
65856ae19f3STrond Myklebust 				encode_getfh_maxsz + \
6591da177e4SLinus Torvalds 				encode_getattr_maxsz + \
66056ae19f3STrond Myklebust 				encode_restorefh_maxsz + \
66156ae19f3STrond Myklebust 				encode_getattr_maxsz)
6621da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
6639b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6641da177e4SLinus Torvalds 				decode_putfh_maxsz + \
66556ae19f3STrond Myklebust 				decode_savefh_maxsz + \
6661da177e4SLinus Torvalds 				decode_create_maxsz + \
66756ae19f3STrond Myklebust 				decode_getfh_maxsz + \
6681da177e4SLinus Torvalds 				decode_getattr_maxsz + \
66956ae19f3STrond Myklebust 				decode_restorefh_maxsz + \
67056ae19f3STrond Myklebust 				decode_getattr_maxsz)
6711da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
6729b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6731da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6741da177e4SLinus Torvalds 				encode_getattr_maxsz)
6751da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
6769b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6771da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6781da177e4SLinus Torvalds 				decode_getattr_maxsz)
6791da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
6809b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6811da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6829104a55dSTrond Myklebust 				encode_statfs_maxsz)
6831da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
6849b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6851da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6869104a55dSTrond Myklebust 				decode_statfs_maxsz)
6871da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
6889b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
689ab91f264STrond Myklebust 				encode_putfh_maxsz + \
6901da177e4SLinus Torvalds 				encode_getattr_maxsz)
6911da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
6929b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
693ab91f264STrond Myklebust 				decode_putfh_maxsz + \
6941da177e4SLinus Torvalds 				decode_getattr_maxsz)
6951da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
6969b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6971da177e4SLinus Torvalds 				encode_putfh_maxsz + \
698fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
699fa178f29STrond Myklebust 				encode_getattr_maxsz)
7001da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7019b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
702fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
703fa178f29STrond Myklebust 				decode_getattr_maxsz)
704029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
7059b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
706029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7079104a55dSTrond Myklebust 				encode_getacl_maxsz)
708029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7099b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
710029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7119104a55dSTrond Myklebust 				decode_getacl_maxsz)
71223ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7139b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
71423ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7159104a55dSTrond Myklebust 				encode_setacl_maxsz)
71623ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7179b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
71823ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7199104a55dSTrond Myklebust 				decode_setacl_maxsz)
720683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
721683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7229b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
723683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
724e6889620STrond Myklebust 				 encode_lookup_maxsz + \
725e6889620STrond Myklebust 				 encode_fs_locations_maxsz)
726683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
727683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7289b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
729683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
730e6889620STrond Myklebust 				 decode_lookup_maxsz + \
731e6889620STrond Myklebust 				 decode_fs_locations_maxsz)
7325a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7335a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7345a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7355a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7365a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7375a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7385a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7395a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
74099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
74199fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
74299fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
74399fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
74499fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
74599fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
74699fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
747fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
748fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
749fc931582SAndy Adamson 				 encode_create_session_maxsz)
750fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
751fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
752fc931582SAndy Adamson 				 decode_create_session_maxsz)
7530f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
7540f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
7550f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
7560f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
757fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
758fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
759fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
760fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
761fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
762fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
7632050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
7642050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
7652050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
7662050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
7672050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
7682050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
7692050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
7702050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
77118019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
77218019753SRicardo Labiaga 					 encode_sequence_maxsz + \
77318019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
77418019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
77518019753SRicardo Labiaga 					 decode_sequence_maxsz + \
77618019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
7777f11d8d3SAndy Adamson #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
7787f11d8d3SAndy Adamson 				encode_sequence_maxsz + \
7797f11d8d3SAndy Adamson 				encode_putfh_maxsz + \
7807f11d8d3SAndy Adamson 				encode_getdevicelist_maxsz)
7817f11d8d3SAndy Adamson #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
7827f11d8d3SAndy Adamson 				decode_sequence_maxsz + \
7837f11d8d3SAndy Adamson 				decode_putfh_maxsz + \
7847f11d8d3SAndy Adamson 				decode_getdevicelist_maxsz)
785b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
786b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
787b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
788b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
789b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
790b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
791b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
792b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
793b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
794b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
795b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
796b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
797b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
798b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
799863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
801863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
802863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
803863a3c6cSAndy Adamson 				encode_getattr_maxsz)
804863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
806863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
807863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
808863a3c6cSAndy Adamson 				decode_getattr_maxsz)
809cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810cbe82603SBenny Halevy 				encode_sequence_maxsz + \
811cbe82603SBenny Halevy 				encode_putfh_maxsz + \
812cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
813cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814cbe82603SBenny Halevy 				decode_sequence_maxsz + \
815cbe82603SBenny Halevy 				decode_putfh_maxsz + \
816cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
817fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
818fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
819fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
820fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
821fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
822fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
823fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
824fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8257d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8267d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8277d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8287d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
8297d974794SBryan Schumaker 					 decode_sequence_maxsz + \
8307d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
8319aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
8329aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
8339aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
8349aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
8359aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
8369aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
8372449ea2eSAlexandros Batsakis 
8382449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8392449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
8402449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
8412449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
8422449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
8432449ea2eSAlexandros Batsakis 				     XDR_UNIT);
8442449ea2eSAlexandros Batsakis 
8452449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8462449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
8472449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
8482449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
8492449ea2eSAlexandros Batsakis 				    XDR_UNIT);
85099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
8511da177e4SLinus Torvalds 
852db8ac8baSWeston Andros Adamson static unsigned short send_implementation_id = 1;
853db8ac8baSWeston Andros Adamson 
854db8ac8baSWeston Andros Adamson module_param(send_implementation_id, ushort, 0644);
855db8ac8baSWeston Andros Adamson MODULE_PARM_DESC(send_implementation_id,
856db8ac8baSWeston Andros Adamson 		"Send implementation ID with NFSv4.1 exchange_id");
857db8ac8baSWeston Andros Adamson 
858bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
859bca79478STrond Myklebust 	[NF4BAD] = 0,
860bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
861bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
862bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
863bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
864bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
865bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
866bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
867bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
868bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
8691da177e4SLinus Torvalds };
8701da177e4SLinus Torvalds 
8711da177e4SLinus Torvalds struct compound_hdr {
8721da177e4SLinus Torvalds 	int32_t		status;
8731da177e4SLinus Torvalds 	uint32_t	nops;
874d017931cSAndy Adamson 	__be32 *	nops_p;
8751da177e4SLinus Torvalds 	uint32_t	taglen;
8761da177e4SLinus Torvalds 	char *		tag;
8770c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
87866cc0429SBenny Halevy 	u32		minorversion;
8791da177e4SLinus Torvalds };
8801da177e4SLinus Torvalds 
88113c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
88213c65ce9SBenny Halevy {
88313c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
88413c65ce9SBenny Halevy 	BUG_ON(!p);
88513c65ce9SBenny Halevy 	return p;
88613c65ce9SBenny Halevy }
8871da177e4SLinus Torvalds 
8881da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
8891da177e4SLinus Torvalds {
8908687b63aSAl Viro 	__be32 *p;
8911da177e4SLinus Torvalds 
8921da177e4SLinus Torvalds 	p = xdr_reserve_space(xdr, 4 + len);
8931da177e4SLinus Torvalds 	BUG_ON(p == NULL);
8941da177e4SLinus Torvalds 	xdr_encode_opaque(p, str, len);
8951da177e4SLinus Torvalds }
8961da177e4SLinus Torvalds 
8970c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
8980c4e8c18SBenny Halevy 				struct rpc_rqst *req,
8990c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
9001da177e4SLinus Torvalds {
9018687b63aSAl Viro 	__be32 *p;
902a17c2153STrond Myklebust 	struct rpc_auth *auth = req->rq_cred->cr_auth;
9030c4e8c18SBenny Halevy 
9040c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
9050c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
9060c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
9070c4e8c18SBenny Halevy 	hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
9081da177e4SLinus Torvalds 
9091da177e4SLinus Torvalds 	BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
910811652bdSBenny Halevy 	p = reserve_space(xdr, 4 + hdr->taglen + 8);
911811652bdSBenny Halevy 	p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
912e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
913d017931cSAndy Adamson 	hdr->nops_p = p;
91434558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
915d017931cSAndy Adamson }
916d017931cSAndy Adamson 
917d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
918d017931cSAndy Adamson {
919fc931582SAndy Adamson 	BUG_ON(hdr->nops > NFS4_MAX_OPS);
920d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
9211da177e4SLinus Torvalds }
9221da177e4SLinus Torvalds 
9231da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
9241da177e4SLinus Torvalds {
9258687b63aSAl Viro 	__be32 *p;
9261da177e4SLinus Torvalds 
9271da177e4SLinus Torvalds 	p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
9281da177e4SLinus Torvalds 	BUG_ON(p == NULL);
9291da177e4SLinus Torvalds 	xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
9301da177e4SLinus Torvalds }
9311da177e4SLinus Torvalds 
932cf8cdbe5SAndy Adamson static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
9331da177e4SLinus Torvalds {
9341da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
9351da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
9361da177e4SLinus Torvalds 	int owner_namelen = 0;
9371da177e4SLinus Torvalds 	int owner_grouplen = 0;
9388687b63aSAl Viro 	__be32 *p;
9398687b63aSAl Viro 	__be32 *q;
9401da177e4SLinus Torvalds 	int len;
9411da177e4SLinus Torvalds 	uint32_t bmval0 = 0;
9421da177e4SLinus Torvalds 	uint32_t bmval1 = 0;
9431da177e4SLinus Torvalds 
9441da177e4SLinus Torvalds 	/*
9451da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
9461da177e4SLinus Torvalds 	 * In the worst-case, this would be
9471da177e4SLinus Torvalds 	 *   12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
9481da177e4SLinus Torvalds 	 *          = 36 bytes, plus any contribution from variable-length fields
94923ec6965SJ. Bruce Fields 	 *            such as owner/group.
9501da177e4SLinus Torvalds 	 */
9511da177e4SLinus Torvalds 	len = 16;
9521da177e4SLinus Torvalds 
9531da177e4SLinus Torvalds 	/* Sigh */
9541da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_SIZE)
9551da177e4SLinus Torvalds 		len += 8;
9561da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MODE)
9571da177e4SLinus Torvalds 		len += 4;
9581da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
959e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
9601da177e4SLinus Torvalds 		if (owner_namelen < 0) {
961fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
9621da177e4SLinus Torvalds 					iap->ia_uid);
9631da177e4SLinus Torvalds 			/* XXX */
9641da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
9651da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
9661da177e4SLinus Torvalds 			/* goto out; */
9671da177e4SLinus Torvalds 		}
9681da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
9691da177e4SLinus Torvalds 	}
9701da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
971e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
9721da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
973fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
9741da177e4SLinus Torvalds 					iap->ia_gid);
9751da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
9761da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
9771da177e4SLinus Torvalds 			/* goto out; */
9781da177e4SLinus Torvalds 		}
9791da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
9801da177e4SLinus Torvalds 	}
9811da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_ATIME_SET)
9821da177e4SLinus Torvalds 		len += 16;
9831da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_ATIME)
9841da177e4SLinus Torvalds 		len += 4;
9851da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MTIME_SET)
9861da177e4SLinus Torvalds 		len += 16;
9871da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_MTIME)
9881da177e4SLinus Torvalds 		len += 4;
98913c65ce9SBenny Halevy 	p = reserve_space(xdr, len);
9901da177e4SLinus Torvalds 
9911da177e4SLinus Torvalds 	/*
9921da177e4SLinus Torvalds 	 * We write the bitmap length now, but leave the bitmap and the attribute
9931da177e4SLinus Torvalds 	 * buffer length to be backfilled at the end of this routine.
9941da177e4SLinus Torvalds 	 */
995e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
9961da177e4SLinus Torvalds 	q = p;
9971da177e4SLinus Torvalds 	p += 3;
9981da177e4SLinus Torvalds 
9991da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_SIZE) {
10001da177e4SLinus Torvalds 		bmval0 |= FATTR4_WORD0_SIZE;
1001b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
10021da177e4SLinus Torvalds 	}
10031da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MODE) {
10041da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_MODE;
1005e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
10061da177e4SLinus Torvalds 	}
10071da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
10081da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_OWNER;
1009811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
10101da177e4SLinus Torvalds 	}
10111da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
10121da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_OWNER_GROUP;
1013811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
10141da177e4SLinus Torvalds 	}
10151da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_ATIME_SET) {
10161da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1017e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1018e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
1019d3f6baaaSTrond Myklebust 		*p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1020d3f6baaaSTrond Myklebust 		*p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
10211da177e4SLinus Torvalds 	}
10221da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_ATIME) {
10231da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1024e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
10251da177e4SLinus Torvalds 	}
10261da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MTIME_SET) {
10271da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1028e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1029e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
1030e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1031e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
10321da177e4SLinus Torvalds 	}
10331da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_MTIME) {
10341da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1035e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
10361da177e4SLinus Torvalds 	}
10371da177e4SLinus Torvalds 
10381da177e4SLinus Torvalds 	/*
10391da177e4SLinus Torvalds 	 * Now we backfill the bitmap and the attribute buffer length.
10401da177e4SLinus Torvalds 	 */
10411da177e4SLinus Torvalds 	if (len != ((char *)p - (char *)q) + 4) {
1042f9fd2d9cSWeston Andros Adamson 		printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
10431da177e4SLinus Torvalds 				len, ((char *)p - (char *)q) + 4);
10441da177e4SLinus Torvalds 		BUG();
10451da177e4SLinus Torvalds 	}
10461da177e4SLinus Torvalds 	len = (char *)p - (char *)q - 12;
10471da177e4SLinus Torvalds 	*q++ = htonl(bmval0);
10481da177e4SLinus Torvalds 	*q++ = htonl(bmval1);
104934558513SBenny Halevy 	*q = htonl(len);
10501da177e4SLinus Torvalds 
10511da177e4SLinus Torvalds /* out: */
10521da177e4SLinus Torvalds }
10531da177e4SLinus Torvalds 
1054cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
10551da177e4SLinus Torvalds {
10568687b63aSAl Viro 	__be32 *p;
10571da177e4SLinus Torvalds 
105813c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1059e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_ACCESS);
106034558513SBenny Halevy 	*p = cpu_to_be32(access);
1061d017931cSAndy Adamson 	hdr->nops++;
1062dadf0c27SBenny Halevy 	hdr->replen += decode_access_maxsz;
10631da177e4SLinus Torvalds }
10641da177e4SLinus Torvalds 
1065cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
10661da177e4SLinus Torvalds {
10678687b63aSAl Viro 	__be32 *p;
10681da177e4SLinus Torvalds 
106913c65ce9SBenny Halevy 	p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1070e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_CLOSE);
1071e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(arg->seqid->sequence->counter);
107234558513SBenny Halevy 	xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1073d017931cSAndy Adamson 	hdr->nops++;
1074dadf0c27SBenny Halevy 	hdr->replen += decode_close_maxsz;
10751da177e4SLinus Torvalds }
10761da177e4SLinus Torvalds 
1077cf8cdbe5SAndy Adamson static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
10781da177e4SLinus Torvalds {
10798687b63aSAl Viro 	__be32 *p;
10801da177e4SLinus Torvalds 
108113c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1082e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_COMMIT);
1083b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
108434558513SBenny Halevy 	*p = cpu_to_be32(args->count);
1085d017931cSAndy Adamson 	hdr->nops++;
1086dadf0c27SBenny Halevy 	hdr->replen += decode_commit_maxsz;
10871da177e4SLinus Torvalds }
10881da177e4SLinus Torvalds 
1089cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
10901da177e4SLinus Torvalds {
10918687b63aSAl Viro 	__be32 *p;
10921da177e4SLinus Torvalds 
109313c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1094e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_CREATE);
109534558513SBenny Halevy 	*p = cpu_to_be32(create->ftype);
10961da177e4SLinus Torvalds 
10971da177e4SLinus Torvalds 	switch (create->ftype) {
10981da177e4SLinus Torvalds 	case NF4LNK:
109913c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
110034558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
110194a6d753SChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
11021da177e4SLinus Torvalds 		break;
11031da177e4SLinus Torvalds 
11041da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
110513c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1106e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
110734558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
11081da177e4SLinus Torvalds 		break;
11091da177e4SLinus Torvalds 
11101da177e4SLinus Torvalds 	default:
11111da177e4SLinus Torvalds 		break;
11121da177e4SLinus Torvalds 	}
11131da177e4SLinus Torvalds 
1114811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
1115d017931cSAndy Adamson 	hdr->nops++;
1116dadf0c27SBenny Halevy 	hdr->replen += decode_create_maxsz;
11171da177e4SLinus Torvalds 
1118cf8cdbe5SAndy Adamson 	encode_attrs(xdr, create->attrs, create->server);
11191da177e4SLinus Torvalds }
11201da177e4SLinus Torvalds 
1121cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
11221da177e4SLinus Torvalds {
11238687b63aSAl Viro 	__be32 *p;
11241da177e4SLinus Torvalds 
112513c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1126e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_GETATTR);
1127e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
112834558513SBenny Halevy 	*p = cpu_to_be32(bitmap);
1129d017931cSAndy Adamson 	hdr->nops++;
1130dadf0c27SBenny Halevy 	hdr->replen += decode_getattr_maxsz;
11311da177e4SLinus Torvalds }
11321da177e4SLinus Torvalds 
1133cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
11341da177e4SLinus Torvalds {
11358687b63aSAl Viro 	__be32 *p;
11361da177e4SLinus Torvalds 
113713c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1138e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_GETATTR);
1139e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
1140e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(bm0);
114134558513SBenny Halevy 	*p = cpu_to_be32(bm1);
1142d017931cSAndy Adamson 	hdr->nops++;
1143dadf0c27SBenny Halevy 	hdr->replen += decode_getattr_maxsz;
11441da177e4SLinus Torvalds }
11451da177e4SLinus Torvalds 
1146dae100c2SFred Isaman static void
1147dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr,
1148dae100c2SFred Isaman 		     uint32_t bm0, uint32_t bm1, uint32_t bm2,
1149dae100c2SFred Isaman 		     struct compound_hdr *hdr)
1150dae100c2SFred Isaman {
1151dae100c2SFred Isaman 	__be32 *p;
1152dae100c2SFred Isaman 
1153dae100c2SFred Isaman 	p = reserve_space(xdr, 4);
1154dae100c2SFred Isaman 	*p = cpu_to_be32(OP_GETATTR);
1155dae100c2SFred Isaman 	if (bm2) {
1156dae100c2SFred Isaman 		p = reserve_space(xdr, 16);
1157dae100c2SFred Isaman 		*p++ = cpu_to_be32(3);
1158dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1159dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm1);
1160dae100c2SFred Isaman 		*p = cpu_to_be32(bm2);
1161dae100c2SFred Isaman 	} else if (bm1) {
1162dae100c2SFred Isaman 		p = reserve_space(xdr, 12);
1163dae100c2SFred Isaman 		*p++ = cpu_to_be32(2);
1164dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1165dae100c2SFred Isaman 		*p = cpu_to_be32(bm1);
1166dae100c2SFred Isaman 	} else {
1167dae100c2SFred Isaman 		p = reserve_space(xdr, 8);
1168dae100c2SFred Isaman 		*p++ = cpu_to_be32(1);
1169dae100c2SFred Isaman 		*p = cpu_to_be32(bm0);
1170dae100c2SFred Isaman 	}
1171dae100c2SFred Isaman 	hdr->nops++;
1172dae100c2SFred Isaman 	hdr->replen += decode_getattr_maxsz;
1173dae100c2SFred Isaman }
1174dae100c2SFred Isaman 
1175cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
11761da177e4SLinus Torvalds {
1177cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1178d017931cSAndy Adamson 			   bitmask[1] & nfs4_fattr_bitmap[1], hdr);
11791da177e4SLinus Torvalds }
11801da177e4SLinus Torvalds 
1181cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
11821da177e4SLinus Torvalds {
1183dae100c2SFred Isaman 	encode_getattr_three(xdr,
1184dae100c2SFred Isaman 			     bitmask[0] & nfs4_fsinfo_bitmap[0],
1185dae100c2SFred Isaman 			     bitmask[1] & nfs4_fsinfo_bitmap[1],
1186dae100c2SFred Isaman 			     bitmask[2] & nfs4_fsinfo_bitmap[2],
1187dae100c2SFred Isaman 			     hdr);
11881da177e4SLinus Torvalds }
11891da177e4SLinus Torvalds 
1190cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1191830b8e33SManoj Naik {
1192cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1193cf8cdbe5SAndy Adamson 			   bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1194830b8e33SManoj Naik }
1195830b8e33SManoj Naik 
1196cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
11971da177e4SLinus Torvalds {
11988687b63aSAl Viro 	__be32 *p;
11991da177e4SLinus Torvalds 
120013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
120134558513SBenny Halevy 	*p = cpu_to_be32(OP_GETFH);
1202d017931cSAndy Adamson 	hdr->nops++;
1203dadf0c27SBenny Halevy 	hdr->replen += decode_getfh_maxsz;
12041da177e4SLinus Torvalds }
12051da177e4SLinus Torvalds 
1206cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12071da177e4SLinus Torvalds {
12088687b63aSAl Viro 	__be32 *p;
12091da177e4SLinus Torvalds 
121013c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + name->len);
1211e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LINK);
1212811652bdSBenny Halevy 	xdr_encode_opaque(p, name->name, name->len);
1213d017931cSAndy Adamson 	hdr->nops++;
1214dadf0c27SBenny Halevy 	hdr->replen += decode_link_maxsz;
12151da177e4SLinus Torvalds }
12161da177e4SLinus Torvalds 
1217911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1218911d1aafSTrond Myklebust {
1219911d1aafSTrond Myklebust 	if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1220911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1221911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1222911d1aafSTrond Myklebust }
1223911d1aafSTrond Myklebust 
1224911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1225911d1aafSTrond Myklebust {
1226911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1227911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1228911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1229911d1aafSTrond Myklebust }
1230911d1aafSTrond Myklebust 
1231daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1232daccbdedSTrond Myklebust {
1233daccbdedSTrond Myklebust 	__be32 *p;
1234daccbdedSTrond Myklebust 
1235d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1236daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1237d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1238daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1239d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1240daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1241daccbdedSTrond Myklebust }
1242daccbdedSTrond Myklebust 
12431da177e4SLinus Torvalds /*
12441da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
12451da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
12461da177e4SLinus Torvalds  */
1247cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
12481da177e4SLinus Torvalds {
12498687b63aSAl Viro 	__be32 *p;
12501da177e4SLinus Torvalds 
125113c65ce9SBenny Halevy 	p = reserve_space(xdr, 32);
1252e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOCK);
1253e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1254e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1255b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1256b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
125734558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1258911d1aafSTrond Myklebust 	if (args->new_lock_owner){
1259daccbdedSTrond Myklebust 		p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1260e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(args->open_seqid->sequence->counter);
126193f0cf25SBenny Halevy 		p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1262e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1263daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
12641da177e4SLinus Torvalds 	}
12651da177e4SLinus Torvalds 	else {
126613c65ce9SBenny Halevy 		p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
126793f0cf25SBenny Halevy 		p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
126834558513SBenny Halevy 		*p = cpu_to_be32(args->lock_seqid->sequence->counter);
12691da177e4SLinus Torvalds 	}
1270d017931cSAndy Adamson 	hdr->nops++;
1271dadf0c27SBenny Halevy 	hdr->replen += decode_lock_maxsz;
12721da177e4SLinus Torvalds }
12731da177e4SLinus Torvalds 
1274cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
12751da177e4SLinus Torvalds {
12768687b63aSAl Viro 	__be32 *p;
12771da177e4SLinus Torvalds 
1278daccbdedSTrond Myklebust 	p = reserve_space(xdr, 24);
1279e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOCKT);
1280e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1281b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1282b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1283daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
1284d017931cSAndy Adamson 	hdr->nops++;
1285dadf0c27SBenny Halevy 	hdr->replen += decode_lockt_maxsz;
12861da177e4SLinus Torvalds }
12871da177e4SLinus Torvalds 
1288cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
12891da177e4SLinus Torvalds {
12908687b63aSAl Viro 	__be32 *p;
12911da177e4SLinus Torvalds 
129213c65ce9SBenny Halevy 	p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1293e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOCKU);
1294e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1295e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->seqid->sequence->counter);
129693f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1297b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
129834558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1299d017931cSAndy Adamson 	hdr->nops++;
1300dadf0c27SBenny Halevy 	hdr->replen += decode_locku_maxsz;
13011da177e4SLinus Torvalds }
13021da177e4SLinus Torvalds 
1303d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1304d3c7b7ccSTrond Myklebust {
1305d3c7b7ccSTrond Myklebust 	__be32 *p;
1306d3c7b7ccSTrond Myklebust 
1307d3c7b7ccSTrond Myklebust 	p = reserve_space(xdr, 4);
1308d3c7b7ccSTrond Myklebust 	*p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1309d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1310d3c7b7ccSTrond Myklebust 	hdr->nops++;
1311d3c7b7ccSTrond Myklebust 	hdr->replen += decode_release_lockowner_maxsz;
1312d3c7b7ccSTrond Myklebust }
1313d3c7b7ccSTrond Myklebust 
1314cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13151da177e4SLinus Torvalds {
13161da177e4SLinus Torvalds 	int len = name->len;
13178687b63aSAl Viro 	__be32 *p;
13181da177e4SLinus Torvalds 
131913c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + len);
1320e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOOKUP);
1321811652bdSBenny Halevy 	xdr_encode_opaque(p, name->name, len);
1322d017931cSAndy Adamson 	hdr->nops++;
1323dadf0c27SBenny Halevy 	hdr->replen += decode_lookup_maxsz;
13241da177e4SLinus Torvalds }
13251da177e4SLinus Torvalds 
1326dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
13271da177e4SLinus Torvalds {
13288687b63aSAl Viro 	__be32 *p;
13291da177e4SLinus Torvalds 
133013c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1331dc0b027dSTrond Myklebust 	switch (fmode & (FMODE_READ|FMODE_WRITE)) {
13321da177e4SLinus Torvalds 	case FMODE_READ:
1333e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
13341da177e4SLinus Torvalds 		break;
13351da177e4SLinus Torvalds 	case FMODE_WRITE:
1336e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
13371da177e4SLinus Torvalds 		break;
13381da177e4SLinus Torvalds 	case FMODE_READ|FMODE_WRITE:
1339e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
13401da177e4SLinus Torvalds 		break;
13411da177e4SLinus Torvalds 	default:
1342e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
13431da177e4SLinus Torvalds 	}
134434558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13451da177e4SLinus Torvalds }
13461da177e4SLinus Torvalds 
13471da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13481da177e4SLinus Torvalds {
13498687b63aSAl Viro 	__be32 *p;
13501da177e4SLinus Torvalds  /*
13511da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
13521da177e4SLinus Torvalds  * owner 4 = 32
13531da177e4SLinus Torvalds  */
135413c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1355e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_OPEN);
135634558513SBenny Halevy 	*p = cpu_to_be32(arg->seqid->sequence->counter);
1357dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
1358d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1359b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
1360d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
136193f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1362d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
136334558513SBenny Halevy 	xdr_encode_hyper(p, arg->id);
13641da177e4SLinus Torvalds }
13651da177e4SLinus Torvalds 
13661da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13671da177e4SLinus Torvalds {
13688687b63aSAl Viro 	__be32 *p;
13694882ef72SAlexandros Batsakis 	struct nfs_client *clp;
13701da177e4SLinus Torvalds 
137113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
13721da177e4SLinus Torvalds 	switch(arg->open_flags & O_EXCL) {
13731da177e4SLinus Torvalds 	case 0:
137434558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
13751da177e4SLinus Torvalds 		encode_attrs(xdr, arg->u.attrs, arg->server);
13761da177e4SLinus Torvalds 		break;
13771da177e4SLinus Torvalds 	default:
13784882ef72SAlexandros Batsakis 		clp = arg->server->nfs_client;
1379a4432345STrond Myklebust 		if (clp->cl_mvops->minor_version > 0) {
13804882ef72SAlexandros Batsakis 			if (nfs4_has_persistent_session(clp)) {
13814882ef72SAlexandros Batsakis 				*p = cpu_to_be32(NFS4_CREATE_GUARDED);
13824882ef72SAlexandros Batsakis 				encode_attrs(xdr, arg->u.attrs, arg->server);
13834882ef72SAlexandros Batsakis 			} else {
13844882ef72SAlexandros Batsakis 				struct iattr dummy;
13854882ef72SAlexandros Batsakis 
13864882ef72SAlexandros Batsakis 				*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
13874882ef72SAlexandros Batsakis 				encode_nfs4_verifier(xdr, &arg->u.verifier);
13884882ef72SAlexandros Batsakis 				dummy.ia_valid = 0;
13894882ef72SAlexandros Batsakis 				encode_attrs(xdr, &dummy, arg->server);
13904882ef72SAlexandros Batsakis 			}
13914882ef72SAlexandros Batsakis 		} else {
139234558513SBenny Halevy 			*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
13931da177e4SLinus Torvalds 			encode_nfs4_verifier(xdr, &arg->u.verifier);
13941da177e4SLinus Torvalds 		}
13951da177e4SLinus Torvalds 	}
13964882ef72SAlexandros Batsakis }
13971da177e4SLinus Torvalds 
13981da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13991da177e4SLinus Torvalds {
14008687b63aSAl Viro 	__be32 *p;
14011da177e4SLinus Torvalds 
140213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14031da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14041da177e4SLinus Torvalds 	case 0:
140534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14061da177e4SLinus Torvalds 		break;
14071da177e4SLinus Torvalds 	default:
14081da177e4SLinus Torvalds 		BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
140934558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14101da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14111da177e4SLinus Torvalds 	}
14121da177e4SLinus Torvalds }
14131da177e4SLinus Torvalds 
1414bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14151da177e4SLinus Torvalds {
14168687b63aSAl Viro 	__be32 *p;
14171da177e4SLinus Torvalds 
141813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14191da177e4SLinus Torvalds 	switch (delegation_type) {
14201da177e4SLinus Torvalds 	case 0:
142134558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14221da177e4SLinus Torvalds 		break;
14231da177e4SLinus Torvalds 	case FMODE_READ:
142434558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14251da177e4SLinus Torvalds 		break;
14261da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
142734558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14281da177e4SLinus Torvalds 		break;
14291da177e4SLinus Torvalds 	default:
14301da177e4SLinus Torvalds 		BUG();
14311da177e4SLinus Torvalds 	}
14321da177e4SLinus Torvalds }
14331da177e4SLinus Torvalds 
14341da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14351da177e4SLinus Torvalds {
14368687b63aSAl Viro 	__be32 *p;
14371da177e4SLinus Torvalds 
143813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
143934558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14401da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14411da177e4SLinus Torvalds }
14421da177e4SLinus Torvalds 
1443bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14441da177e4SLinus Torvalds {
14458687b63aSAl Viro 	__be32 *p;
14461da177e4SLinus Torvalds 
144713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
144834558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14491da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14501da177e4SLinus Torvalds }
14511da177e4SLinus Torvalds 
14521da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14531da177e4SLinus Torvalds {
14548687b63aSAl Viro 	__be32 *p;
14551da177e4SLinus Torvalds 
145613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1457e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
145834558513SBenny Halevy 	xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
14591da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14601da177e4SLinus Torvalds }
14611da177e4SLinus Torvalds 
1462cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
14631da177e4SLinus Torvalds {
14641da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
14651da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
14661da177e4SLinus Torvalds 	switch (arg->claim) {
14671da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
14681da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
14691da177e4SLinus Torvalds 		break;
14701da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
14711da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
14721da177e4SLinus Torvalds 		break;
14731da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
14741da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
14751da177e4SLinus Torvalds 		break;
14761da177e4SLinus Torvalds 	default:
14771da177e4SLinus Torvalds 		BUG();
14781da177e4SLinus Torvalds 	}
1479d017931cSAndy Adamson 	hdr->nops++;
1480dadf0c27SBenny Halevy 	hdr->replen += decode_open_maxsz;
14811da177e4SLinus Torvalds }
14821da177e4SLinus Torvalds 
1483cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
14841da177e4SLinus Torvalds {
14858687b63aSAl Viro 	__be32 *p;
14861da177e4SLinus Torvalds 
148713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1488e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_OPEN_CONFIRM);
148993f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
149034558513SBenny Halevy 	*p = cpu_to_be32(arg->seqid->sequence->counter);
1491d017931cSAndy Adamson 	hdr->nops++;
1492dadf0c27SBenny Halevy 	hdr->replen += decode_open_confirm_maxsz;
14931da177e4SLinus Torvalds }
14941da177e4SLinus Torvalds 
1495cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
14961da177e4SLinus Torvalds {
14978687b63aSAl Viro 	__be32 *p;
14981da177e4SLinus Torvalds 
149913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1500e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
150193f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
150234558513SBenny Halevy 	*p = cpu_to_be32(arg->seqid->sequence->counter);
1503dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
1504d017931cSAndy Adamson 	hdr->nops++;
1505dadf0c27SBenny Halevy 	hdr->replen += decode_open_downgrade_maxsz;
15061da177e4SLinus Torvalds }
15071da177e4SLinus Torvalds 
1508cf8cdbe5SAndy Adamson static void
1509d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15101da177e4SLinus Torvalds {
15111da177e4SLinus Torvalds 	int len = fh->size;
15128687b63aSAl Viro 	__be32 *p;
15131da177e4SLinus Torvalds 
151413c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + len);
1515e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_PUTFH);
1516811652bdSBenny Halevy 	xdr_encode_opaque(p, fh->data, len);
1517d017931cSAndy Adamson 	hdr->nops++;
1518dadf0c27SBenny Halevy 	hdr->replen += decode_putfh_maxsz;
15191da177e4SLinus Torvalds }
15201da177e4SLinus Torvalds 
1521cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15221da177e4SLinus Torvalds {
15238687b63aSAl Viro 	__be32 *p;
15241da177e4SLinus Torvalds 
152513c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
152634558513SBenny Halevy 	*p = cpu_to_be32(OP_PUTROOTFH);
1527d017931cSAndy Adamson 	hdr->nops++;
1528dadf0c27SBenny Halevy 	hdr->replen += decode_putrootfh_maxsz;
15291da177e4SLinus Torvalds }
15301da177e4SLinus Torvalds 
1531d0b496d2STrond Myklebust static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
15321da177e4SLinus Torvalds {
15331da177e4SLinus Torvalds 	nfs4_stateid stateid;
15348687b63aSAl Viro 	__be32 *p;
15351da177e4SLinus Torvalds 
153613c65ce9SBenny Halevy 	p = reserve_space(xdr, NFS4_STATEID_SIZE);
15371da177e4SLinus Torvalds 	if (ctx->state != NULL) {
153877041ed9STrond Myklebust 		nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
153989d1ea65SAndy Adamson 		if (zero_seqid)
154089d1ea65SAndy Adamson 			stateid.stateid.seqid = 0;
154134558513SBenny Halevy 		xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
15421da177e4SLinus Torvalds 	} else
154334558513SBenny Halevy 		xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
15441da177e4SLinus Torvalds }
15451da177e4SLinus Torvalds 
1546cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
15471da177e4SLinus Torvalds {
15488687b63aSAl Viro 	__be32 *p;
15491da177e4SLinus Torvalds 
155013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
155134558513SBenny Halevy 	*p = cpu_to_be32(OP_READ);
15521da177e4SLinus Torvalds 
1553d0b496d2STrond Myklebust 	encode_open_stateid(xdr, args->context, args->lock_context,
155489d1ea65SAndy Adamson 		       hdr->minorversion);
15551da177e4SLinus Torvalds 
155613c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1557b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
155834558513SBenny Halevy 	*p = cpu_to_be32(args->count);
1559d017931cSAndy Adamson 	hdr->nops++;
1560dadf0c27SBenny Halevy 	hdr->replen += decode_read_maxsz;
15611da177e4SLinus Torvalds }
15621da177e4SLinus Torvalds 
1563cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15641da177e4SLinus Torvalds {
156528331a46STrond Myklebust 	uint32_t attrs[2] = {
156628331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
156728331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
156828331a46STrond Myklebust 	};
15696f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
15708687b63aSAl Viro 	__be32 *p;
15711da177e4SLinus Torvalds 
157282f2e547SBryan Schumaker 	if (readdir->plus) {
157382f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
157428331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
157582f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
157682f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
157782f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
157882f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
15796f7a35bdSTrond Myklebust 		dircount >>= 1;
158082f2e547SBryan Schumaker 	}
158128331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
158228331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
158328331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
15846f7a35bdSTrond Myklebust 
15856f7a35bdSTrond Myklebust 	p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
15866f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(OP_READDIR);
15876f7a35bdSTrond Myklebust 	p = xdr_encode_hyper(p, readdir->cookie);
15886f7a35bdSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
15896f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
15906f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
15916f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(2);
159282f2e547SBryan Schumaker 
1593e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
159434558513SBenny Halevy 	*p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1595d017931cSAndy Adamson 	hdr->nops++;
1596dadf0c27SBenny Halevy 	hdr->replen += decode_readdir_maxsz;
159744109241SFred Isaman 	dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
159844109241SFred Isaman 			__func__,
1599eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1600eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[0],
1601eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[1],
1602eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1603eadf4598STrond Myklebust 			attrs[1] & readdir->bitmask[1]);
16041da177e4SLinus Torvalds }
16051da177e4SLinus Torvalds 
1606cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16071da177e4SLinus Torvalds {
16088687b63aSAl Viro 	__be32 *p;
16091da177e4SLinus Torvalds 
161013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
161134558513SBenny Halevy 	*p = cpu_to_be32(OP_READLINK);
1612d017931cSAndy Adamson 	hdr->nops++;
1613dadf0c27SBenny Halevy 	hdr->replen += decode_readlink_maxsz;
16141da177e4SLinus Torvalds }
16151da177e4SLinus Torvalds 
1616cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16171da177e4SLinus Torvalds {
16188687b63aSAl Viro 	__be32 *p;
16191da177e4SLinus Torvalds 
162013c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + name->len);
1621e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_REMOVE);
1622811652bdSBenny Halevy 	xdr_encode_opaque(p, name->name, name->len);
1623d017931cSAndy Adamson 	hdr->nops++;
1624dadf0c27SBenny Halevy 	hdr->replen += decode_remove_maxsz;
16251da177e4SLinus Torvalds }
16261da177e4SLinus Torvalds 
1627cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16281da177e4SLinus Torvalds {
16298687b63aSAl Viro 	__be32 *p;
16301da177e4SLinus Torvalds 
1631811652bdSBenny Halevy 	p = reserve_space(xdr, 4);
1632811652bdSBenny Halevy 	*p = cpu_to_be32(OP_RENAME);
1633811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1634811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
1635d017931cSAndy Adamson 	hdr->nops++;
1636dadf0c27SBenny Halevy 	hdr->replen += decode_rename_maxsz;
16371da177e4SLinus Torvalds }
16381da177e4SLinus Torvalds 
1639bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1640bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16411da177e4SLinus Torvalds {
16428687b63aSAl Viro 	__be32 *p;
16431da177e4SLinus Torvalds 
164413c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1645e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_RENEW);
1646bb4dae5eSChuck Lever 	xdr_encode_hyper(p, clid);
1647d017931cSAndy Adamson 	hdr->nops++;
1648dadf0c27SBenny Halevy 	hdr->replen += decode_renew_maxsz;
16491da177e4SLinus Torvalds }
16501da177e4SLinus Torvalds 
1651cf8cdbe5SAndy Adamson static void
1652d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
165356ae19f3STrond Myklebust {
16548687b63aSAl Viro 	__be32 *p;
165556ae19f3STrond Myklebust 
165613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
165734558513SBenny Halevy 	*p = cpu_to_be32(OP_RESTOREFH);
1658d017931cSAndy Adamson 	hdr->nops++;
1659dadf0c27SBenny Halevy 	hdr->replen += decode_restorefh_maxsz;
166056ae19f3STrond Myklebust }
166156ae19f3STrond Myklebust 
16629f06c719SChuck Lever static void
1663d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
166423ec6965SJ. Bruce Fields {
16658687b63aSAl Viro 	__be32 *p;
166623ec6965SJ. Bruce Fields 
166713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1668e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETATTR);
166934558513SBenny Halevy 	xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
167013c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1671e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
167234558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
16739f06c719SChuck Lever 	BUG_ON(arg->acl_len % 4);
167413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
167534558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
167623ec6965SJ. Bruce Fields 	xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1677d017931cSAndy Adamson 	hdr->nops++;
1678dadf0c27SBenny Halevy 	hdr->replen += decode_setacl_maxsz;
167923ec6965SJ. Bruce Fields }
168023ec6965SJ. Bruce Fields 
1681cf8cdbe5SAndy Adamson static void
1682d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16831da177e4SLinus Torvalds {
16848687b63aSAl Viro 	__be32 *p;
16851da177e4SLinus Torvalds 
168613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
168734558513SBenny Halevy 	*p = cpu_to_be32(OP_SAVEFH);
1688d017931cSAndy Adamson 	hdr->nops++;
1689dadf0c27SBenny Halevy 	hdr->replen += decode_savefh_maxsz;
16901da177e4SLinus Torvalds }
16911da177e4SLinus Torvalds 
1692cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16931da177e4SLinus Torvalds {
16948687b63aSAl Viro 	__be32 *p;
16951da177e4SLinus Torvalds 
169613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1697e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETATTR);
169834558513SBenny Halevy 	xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1699d017931cSAndy Adamson 	hdr->nops++;
1700dadf0c27SBenny Halevy 	hdr->replen += decode_setattr_maxsz;
1701cf8cdbe5SAndy Adamson 	encode_attrs(xdr, arg->iap, server);
17021da177e4SLinus Torvalds }
17031da177e4SLinus Torvalds 
1704cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
17051da177e4SLinus Torvalds {
17068687b63aSAl Viro 	__be32 *p;
17071da177e4SLinus Torvalds 
170813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1709e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETCLIENTID);
171034558513SBenny Halevy 	xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
17111da177e4SLinus Torvalds 
17121da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
171313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
171434558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
17151da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
17161da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
171713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
171834558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_cb_ident);
1719d017931cSAndy Adamson 	hdr->nops++;
1720dadf0c27SBenny Halevy 	hdr->replen += decode_setclientid_maxsz;
17211da177e4SLinus Torvalds }
17221da177e4SLinus Torvalds 
1723bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
17241da177e4SLinus Torvalds {
17258687b63aSAl Viro 	__be32 *p;
17261da177e4SLinus Torvalds 
172713c65ce9SBenny Halevy 	p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1728e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1729bb8b27e5STrond Myklebust 	p = xdr_encode_hyper(p, arg->clientid);
1730bb8b27e5STrond Myklebust 	xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1731d017931cSAndy Adamson 	hdr->nops++;
1732dadf0c27SBenny Halevy 	hdr->replen += decode_setclientid_confirm_maxsz;
17331da177e4SLinus Torvalds }
17341da177e4SLinus Torvalds 
1735cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
17361da177e4SLinus Torvalds {
17378687b63aSAl Viro 	__be32 *p;
17381da177e4SLinus Torvalds 
173913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
174034558513SBenny Halevy 	*p = cpu_to_be32(OP_WRITE);
17411da177e4SLinus Torvalds 
1742d0b496d2STrond Myklebust 	encode_open_stateid(xdr, args->context, args->lock_context,
174389d1ea65SAndy Adamson 		       hdr->minorversion);
17441da177e4SLinus Torvalds 
174513c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1746b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1747e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
174834558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17491da177e4SLinus Torvalds 
17501da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1751d017931cSAndy Adamson 	hdr->nops++;
1752dadf0c27SBenny Halevy 	hdr->replen += decode_write_maxsz;
17531da177e4SLinus Torvalds }
17541da177e4SLinus Torvalds 
1755cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17561da177e4SLinus Torvalds {
17578687b63aSAl Viro 	__be32 *p;
17581da177e4SLinus Torvalds 
175913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
17601da177e4SLinus Torvalds 
1761e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_DELEGRETURN);
176234558513SBenny Halevy 	xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1763d017931cSAndy Adamson 	hdr->nops++;
1764dadf0c27SBenny Halevy 	hdr->replen += decode_delegreturn_maxsz;
17651da177e4SLinus Torvalds }
17669b7b9fccSAndy Adamson 
17675a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17685a5ea0d4SBryan Schumaker {
17695a5ea0d4SBryan Schumaker 	int len = name->len;
17705a5ea0d4SBryan Schumaker 	__be32 *p;
17715a5ea0d4SBryan Schumaker 
17725a5ea0d4SBryan Schumaker 	p = reserve_space(xdr, 8 + len);
17735a5ea0d4SBryan Schumaker 	*p++ = cpu_to_be32(OP_SECINFO);
17745a5ea0d4SBryan Schumaker 	xdr_encode_opaque(p, name->name, len);
17755a5ea0d4SBryan Schumaker 	hdr->nops++;
17765a5ea0d4SBryan Schumaker 	hdr->replen += decode_secinfo_maxsz;
17775a5ea0d4SBryan Schumaker }
17785a5ea0d4SBryan Schumaker 
177999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17809b7b9fccSAndy Adamson /* NFSv4.1 operations */
178199fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
178299fe60d0SBenny Halevy 			       struct nfs41_exchange_id_args *args,
178399fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
178499fe60d0SBenny Halevy {
178599fe60d0SBenny Halevy 	__be32 *p;
1786db8ac8baSWeston Andros Adamson 	char impl_name[NFS4_OPAQUE_LIMIT];
1787db8ac8baSWeston Andros Adamson 	int len = 0;
178899fe60d0SBenny Halevy 
178913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1790e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_EXCHANGE_ID);
179134558513SBenny Halevy 	xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
179299fe60d0SBenny Halevy 
179399fe60d0SBenny Halevy 	encode_string(xdr, args->id_len, args->id);
179499fe60d0SBenny Halevy 
179513c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1796e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);
1797e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);	/* zero length state_protect4_a */
1798db8ac8baSWeston Andros Adamson 
1799db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1800db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1801db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1802db8ac8baSWeston Andros Adamson 		<= NFS4_OPAQUE_LIMIT + 1)
1803db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1804db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1805db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1806db8ac8baSWeston Andros Adamson 
1807db8ac8baSWeston Andros Adamson 	if (len > 0) {
1808db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(1);	/* implementation id array length=1 */
1809db8ac8baSWeston Andros Adamson 
1810db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1811db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1812db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1813db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1814db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1815db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1816db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1817db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1818db8ac8baSWeston Andros Adamson 	} else
1819db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);	/* implementation id array length=0 */
1820db8ac8baSWeston Andros Adamson 
182199fe60d0SBenny Halevy 	hdr->nops++;
182299fe60d0SBenny Halevy 	hdr->replen += decode_exchange_id_maxsz;
182399fe60d0SBenny Halevy }
1824fc931582SAndy Adamson 
1825fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1826fc931582SAndy Adamson 				  struct nfs41_create_session_args *args,
1827fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1828fc931582SAndy Adamson {
1829fc931582SAndy Adamson 	__be32 *p;
1830fc931582SAndy Adamson 	char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1831fc931582SAndy Adamson 	uint32_t len;
1832fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
18338e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18348e0d46e1SMike Sager 
18358e0d46e1SMike Sager 	/*
18368e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18378e0d46e1SMike Sager 	 * 2 is the verifier.
18388e0d46e1SMike Sager 	 */
18398e0d46e1SMike Sager 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
18408e0d46e1SMike Sager 			      RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1841fc931582SAndy Adamson 
1842fc931582SAndy Adamson 	len = scnprintf(machine_name, sizeof(machine_name), "%s",
1843fc931582SAndy Adamson 			clp->cl_ipaddr);
184442edd698SBenny Halevy 
184513c65ce9SBenny Halevy 	p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1846e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_CREATE_SESSION);
1847114f64b5SAndy Adamson 	p = xdr_encode_hyper(p, clp->cl_clientid);
1848e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(clp->cl_seqid);			/*Sequence id */
1849e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1850fc931582SAndy Adamson 
1851fc931582SAndy Adamson 	/* Fore Channel */
1852c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1853e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1854e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18558e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1856e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1857e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1858e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1859fc931582SAndy Adamson 
1860fc931582SAndy Adamson 	/* Back Channel */
1861c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1862e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1863e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1864e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1865e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1866e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1867e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1868fc931582SAndy Adamson 
1869e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1870e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1871e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1872fc931582SAndy Adamson 
1873fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
1874e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec);	/* stamp */
1875811652bdSBenny Halevy 	p = xdr_encode_opaque(p, machine_name, len);
1876e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1877e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
187834558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1879fc931582SAndy Adamson 	hdr->nops++;
1880fc931582SAndy Adamson 	hdr->replen += decode_create_session_maxsz;
1881fc931582SAndy Adamson }
18820f3e66c6SAndy Adamson 
18830f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
18840f3e66c6SAndy Adamson 				   struct nfs4_session *session,
18850f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18860f3e66c6SAndy Adamson {
18870f3e66c6SAndy Adamson 	__be32 *p;
188813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1889e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_DESTROY_SESSION);
189034558513SBenny Halevy 	xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18910f3e66c6SAndy Adamson 	hdr->nops++;
18920f3e66c6SAndy Adamson 	hdr->replen += decode_destroy_session_maxsz;
18930f3e66c6SAndy Adamson }
189418019753SRicardo Labiaga 
189518019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
189618019753SRicardo Labiaga 				    struct nfs41_reclaim_complete_args *args,
189718019753SRicardo Labiaga 				    struct compound_hdr *hdr)
189818019753SRicardo Labiaga {
189918019753SRicardo Labiaga 	__be32 *p;
190018019753SRicardo Labiaga 
190118019753SRicardo Labiaga 	p = reserve_space(xdr, 8);
190218019753SRicardo Labiaga 	*p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
190318019753SRicardo Labiaga 	*p++ = cpu_to_be32(args->one_fs);
190418019753SRicardo Labiaga 	hdr->nops++;
190518019753SRicardo Labiaga 	hdr->replen += decode_reclaim_complete_maxsz;
190618019753SRicardo Labiaga }
190799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
190899fe60d0SBenny Halevy 
19099b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
19109b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
19119b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
19129b7b9fccSAndy Adamson {
19139b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
19149b7b9fccSAndy Adamson 	struct nfs4_session *session = args->sa_session;
1915fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
1916fc01cea9SAndy Adamson 	struct nfs4_slot *slot;
1917fc01cea9SAndy Adamson 	__be32 *p;
19189b7b9fccSAndy Adamson 
19199b7b9fccSAndy Adamson 	if (!session)
19209b7b9fccSAndy Adamson 		return;
19219b7b9fccSAndy Adamson 
1922fc01cea9SAndy Adamson 	tp = &session->fc_slot_table;
1923fc01cea9SAndy Adamson 
1924fc01cea9SAndy Adamson 	WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1925fc01cea9SAndy Adamson 	slot = tp->slots + args->sa_slotid;
1926fc01cea9SAndy Adamson 
192713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1928e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SEQUENCE);
1929fc01cea9SAndy Adamson 
1930fc01cea9SAndy Adamson 	/*
1931fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1932fc01cea9SAndy Adamson 	 */
1933fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1934fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1935fc01cea9SAndy Adamson 		__func__,
1936fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1937fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1938fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1939fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
1940fc01cea9SAndy Adamson 		slot->seq_nr, args->sa_slotid,
1941fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
194293f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1943e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
1944e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->sa_slotid);
1945e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
194634558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19479b7b9fccSAndy Adamson 	hdr->nops++;
19489b7b9fccSAndy Adamson 	hdr->replen += decode_sequence_maxsz;
19499b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19509b7b9fccSAndy Adamson }
19519b7b9fccSAndy Adamson 
1952b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1953b1f69b75SAndy Adamson static void
19547f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr,
19557f11d8d3SAndy Adamson 		     const struct nfs4_getdevicelist_args *args,
19567f11d8d3SAndy Adamson 		     struct compound_hdr *hdr)
19577f11d8d3SAndy Adamson {
19587f11d8d3SAndy Adamson 	__be32 *p;
19597f11d8d3SAndy Adamson 	nfs4_verifier dummy = {
19607f11d8d3SAndy Adamson 		.data = "dummmmmy",
19617f11d8d3SAndy Adamson 	};
19627f11d8d3SAndy Adamson 
19637f11d8d3SAndy Adamson 	p = reserve_space(xdr, 20);
19647f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(OP_GETDEVICELIST);
19657f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(args->layoutclass);
19667f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
19677f11d8d3SAndy Adamson 	xdr_encode_hyper(p, 0ULL);                          /* cookie */
19687f11d8d3SAndy Adamson 	encode_nfs4_verifier(xdr, &dummy);
19697f11d8d3SAndy Adamson 	hdr->nops++;
19707f11d8d3SAndy Adamson 	hdr->replen += decode_getdevicelist_maxsz;
19717f11d8d3SAndy Adamson }
19727f11d8d3SAndy Adamson 
19737f11d8d3SAndy Adamson static void
1974b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1975b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1976b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1977b1f69b75SAndy Adamson {
1978b1f69b75SAndy Adamson 	__be32 *p;
1979b1f69b75SAndy Adamson 
1980b1f69b75SAndy Adamson 	p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1981b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(OP_GETDEVICEINFO);
1982b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1983b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1984b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1985b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->pglen);		/* gdia_maxcount */
1986b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);				/* bitmap length 0 */
1987b1f69b75SAndy Adamson 	hdr->nops++;
1988b1f69b75SAndy Adamson 	hdr->replen += decode_getdeviceinfo_maxsz;
1989b1f69b75SAndy Adamson }
1990b1f69b75SAndy Adamson 
1991b1f69b75SAndy Adamson static void
1992b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1993b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1994b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1995b1f69b75SAndy Adamson {
1996b1f69b75SAndy Adamson 	__be32 *p;
1997b1f69b75SAndy Adamson 
1998b1f69b75SAndy Adamson 	p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1999b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(OP_LAYOUTGET);
2000b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
2001b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
2002b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
2003b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
2004b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
2005b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
2006cf7d63f1SFred Isaman 	p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2007b1f69b75SAndy Adamson 	*p = cpu_to_be32(args->maxcount);
2008b1f69b75SAndy Adamson 
2009b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2010b1f69b75SAndy Adamson 		__func__,
2011b1f69b75SAndy Adamson 		args->type,
2012b1f69b75SAndy Adamson 		args->range.iomode,
2013b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
2014b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
2015b1f69b75SAndy Adamson 		args->maxcount);
2016b1f69b75SAndy Adamson 	hdr->nops++;
2017b1f69b75SAndy Adamson 	hdr->replen += decode_layoutget_maxsz;
2018b1f69b75SAndy Adamson }
2019863a3c6cSAndy Adamson 
2020863a3c6cSAndy Adamson static int
2021863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
2022ac7db726SBenny Halevy 		    struct inode *inode,
2023863a3c6cSAndy Adamson 		    const struct nfs4_layoutcommit_args *args,
2024863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
2025863a3c6cSAndy Adamson {
2026863a3c6cSAndy Adamson 	__be32 *p;
2027863a3c6cSAndy Adamson 
2028863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2029863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2030863a3c6cSAndy Adamson 
2031ac7db726SBenny Halevy 	p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
2032863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2033863a3c6cSAndy Adamson 	/* Only whole file layouts */
2034863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
20353557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
2036863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* reclaim */
2037863a3c6cSAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2038863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2039863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, args->lastbytewritten);
2040863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2041863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2042ac7db726SBenny Halevy 
2043ac7db726SBenny Halevy 	if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2044ac7db726SBenny Halevy 		NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2045ac7db726SBenny Halevy 			NFS_I(inode)->layout, xdr, args);
2046ac7db726SBenny Halevy 	else {
2047ac7db726SBenny Halevy 		p = reserve_space(xdr, 4);
2048ac7db726SBenny Halevy 		*p = cpu_to_be32(0); /* no layout-type payload */
2049ac7db726SBenny Halevy 	}
2050863a3c6cSAndy Adamson 
2051863a3c6cSAndy Adamson 	hdr->nops++;
2052863a3c6cSAndy Adamson 	hdr->replen += decode_layoutcommit_maxsz;
2053863a3c6cSAndy Adamson 	return 0;
2054863a3c6cSAndy Adamson }
2055cbe82603SBenny Halevy 
2056cbe82603SBenny Halevy static void
2057cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2058cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2059cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2060cbe82603SBenny Halevy {
2061cbe82603SBenny Halevy 	__be32 *p;
2062cbe82603SBenny Halevy 
2063cbe82603SBenny Halevy 	p = reserve_space(xdr, 20);
2064cbe82603SBenny Halevy 	*p++ = cpu_to_be32(OP_LAYOUTRETURN);
2065cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2066cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
2067cbe82603SBenny Halevy 	*p++ = cpu_to_be32(IOMODE_ANY);
2068cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2069cbe82603SBenny Halevy 	p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2070cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, 0);
2071cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2072cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2073cbe82603SBenny Halevy 	xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2074cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
207504a55549SAndy Adamson 	if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
207604a55549SAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
207704a55549SAndy Adamson 			NFS_I(args->inode)->layout, xdr, args);
207804a55549SAndy Adamson 	} else {
2079cbe82603SBenny Halevy 		p = reserve_space(xdr, 4);
2080cbe82603SBenny Halevy 		*p = cpu_to_be32(0);
208104a55549SAndy Adamson 	}
2082cbe82603SBenny Halevy 	hdr->nops++;
2083cbe82603SBenny Halevy 	hdr->replen += decode_layoutreturn_maxsz;
2084cbe82603SBenny Halevy }
2085fca78d6dSBryan Schumaker 
2086fca78d6dSBryan Schumaker static int
2087fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2088fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2089fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2090fca78d6dSBryan Schumaker {
2091fca78d6dSBryan Schumaker 	__be32 *p;
2092fca78d6dSBryan Schumaker 	p = reserve_space(xdr, 8);
2093fca78d6dSBryan Schumaker 	*p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2094fca78d6dSBryan Schumaker 	*p++ = cpu_to_be32(args->style);
2095fca78d6dSBryan Schumaker 	hdr->nops++;
2096fca78d6dSBryan Schumaker 	hdr->replen += decode_secinfo_no_name_maxsz;
2097fca78d6dSBryan Schumaker 	return 0;
2098fca78d6dSBryan Schumaker }
20997d974794SBryan Schumaker 
21007d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
21017d974794SBryan Schumaker 				struct nfs41_test_stateid_args *args,
21027d974794SBryan Schumaker 				struct compound_hdr *hdr)
21037d974794SBryan Schumaker {
21047d974794SBryan Schumaker 	__be32 *p;
21057d974794SBryan Schumaker 
21067d974794SBryan Schumaker 	p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
21077d974794SBryan Schumaker 	*p++ = cpu_to_be32(OP_TEST_STATEID);
21087d974794SBryan Schumaker 	*p++ = cpu_to_be32(1);
21097d974794SBryan Schumaker 	xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
21107d974794SBryan Schumaker 	hdr->nops++;
21117d974794SBryan Schumaker 	hdr->replen += decode_test_stateid_maxsz;
21127d974794SBryan Schumaker }
21139aeda35fSBryan Schumaker 
21149aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
21159aeda35fSBryan Schumaker 				struct nfs41_free_stateid_args *args,
21169aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
21179aeda35fSBryan Schumaker {
21189aeda35fSBryan Schumaker 	__be32 *p;
21199aeda35fSBryan Schumaker 	p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
21209aeda35fSBryan Schumaker 	*p++ = cpu_to_be32(OP_FREE_STATEID);
21219aeda35fSBryan Schumaker 	xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
21229aeda35fSBryan Schumaker 	hdr->nops++;
21239aeda35fSBryan Schumaker 	hdr->replen += decode_free_stateid_maxsz;
21249aeda35fSBryan Schumaker }
2125b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2126b1f69b75SAndy Adamson 
21271da177e4SLinus Torvalds /*
21281da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
21291da177e4SLinus Torvalds  */
21301da177e4SLinus Torvalds 
213166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
213266cc0429SBenny Halevy {
213366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
213466cc0429SBenny Halevy 	if (args->sa_session)
2135a4432345STrond Myklebust 		return args->sa_session->clp->cl_mvops->minor_version;
213666cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
213766cc0429SBenny Halevy 	return 0;
213866cc0429SBenny Halevy }
213966cc0429SBenny Halevy 
21401da177e4SLinus Torvalds /*
21411da177e4SLinus Torvalds  * Encode an ACCESS request
21421da177e4SLinus Torvalds  */
21439f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
21449f06c719SChuck Lever 				const struct nfs4_accessargs *args)
21451da177e4SLinus Torvalds {
21461da177e4SLinus Torvalds 	struct compound_hdr hdr = {
214766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21481da177e4SLinus Torvalds 	};
21491da177e4SLinus Torvalds 
21509f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21519f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21529f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21539f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
21549f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2155d017931cSAndy Adamson 	encode_nops(&hdr);
21561da177e4SLinus Torvalds }
21571da177e4SLinus Torvalds 
21581da177e4SLinus Torvalds /*
21591da177e4SLinus Torvalds  * Encode LOOKUP request
21601da177e4SLinus Torvalds  */
21619f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
21629f06c719SChuck Lever 				const struct nfs4_lookup_arg *args)
21631da177e4SLinus Torvalds {
21641da177e4SLinus Torvalds 	struct compound_hdr hdr = {
216566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21661da177e4SLinus Torvalds 	};
21671da177e4SLinus Torvalds 
21689f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21699f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21709f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21719f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21729f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21739f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2174d017931cSAndy Adamson 	encode_nops(&hdr);
21751da177e4SLinus Torvalds }
21761da177e4SLinus Torvalds 
21771da177e4SLinus Torvalds /*
21781da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21791da177e4SLinus Torvalds  */
21809f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21819f06c719SChuck Lever 				     struct xdr_stream *xdr,
21829f06c719SChuck Lever 				     const struct nfs4_lookup_root_arg *args)
21831da177e4SLinus Torvalds {
21841da177e4SLinus Torvalds 	struct compound_hdr hdr = {
218566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21861da177e4SLinus Torvalds 	};
21871da177e4SLinus Torvalds 
21889f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21899f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21909f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21919f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21929f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2193d017931cSAndy Adamson 	encode_nops(&hdr);
21941da177e4SLinus Torvalds }
21951da177e4SLinus Torvalds 
21961da177e4SLinus Torvalds /*
21971da177e4SLinus Torvalds  * Encode REMOVE request
21981da177e4SLinus Torvalds  */
21999f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
22009f06c719SChuck Lever 				const struct nfs_removeargs *args)
22011da177e4SLinus Torvalds {
22021da177e4SLinus Torvalds 	struct compound_hdr hdr = {
220366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22041da177e4SLinus Torvalds 	};
22051da177e4SLinus Torvalds 
22069f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22079f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22089f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22099f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
22109f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2211d017931cSAndy Adamson 	encode_nops(&hdr);
22121da177e4SLinus Torvalds }
22131da177e4SLinus Torvalds 
22141da177e4SLinus Torvalds /*
22151da177e4SLinus Torvalds  * Encode RENAME request
22161da177e4SLinus Torvalds  */
22179f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
22189f06c719SChuck Lever 				const struct nfs_renameargs *args)
22191da177e4SLinus Torvalds {
22201da177e4SLinus Torvalds 	struct compound_hdr hdr = {
222166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22221da177e4SLinus Torvalds 	};
22231da177e4SLinus Torvalds 
22249f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22259f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22269f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
22279f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22289f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
22299f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
22309f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
22319f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22329f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2233d017931cSAndy Adamson 	encode_nops(&hdr);
22341da177e4SLinus Torvalds }
22351da177e4SLinus Torvalds 
22361da177e4SLinus Torvalds /*
22371da177e4SLinus Torvalds  * Encode LINK request
22381da177e4SLinus Torvalds  */
22399f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
22409f06c719SChuck Lever 			     const struct nfs4_link_arg *args)
22411da177e4SLinus Torvalds {
22421da177e4SLinus Torvalds 	struct compound_hdr hdr = {
224366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22441da177e4SLinus Torvalds 	};
22451da177e4SLinus Torvalds 
22469f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22479f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22489f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22499f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22509f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22519f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
22529f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
22539f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22549f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2255d017931cSAndy Adamson 	encode_nops(&hdr);
22561da177e4SLinus Torvalds }
22571da177e4SLinus Torvalds 
22581da177e4SLinus Torvalds /*
22591da177e4SLinus Torvalds  * Encode CREATE request
22601da177e4SLinus Torvalds  */
22619f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
22629f06c719SChuck Lever 				const struct nfs4_create_arg *args)
22631da177e4SLinus Torvalds {
22641da177e4SLinus Torvalds 	struct compound_hdr hdr = {
226566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22661da177e4SLinus Torvalds 	};
22671da177e4SLinus Torvalds 
22689f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22699f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22709f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22719f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22729f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22739f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22749f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
22759f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22769f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2277d017931cSAndy Adamson 	encode_nops(&hdr);
22781da177e4SLinus Torvalds }
22791da177e4SLinus Torvalds 
22801da177e4SLinus Torvalds /*
22811da177e4SLinus Torvalds  * Encode SYMLINK request
22821da177e4SLinus Torvalds  */
22839f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
22849f06c719SChuck Lever 				 const struct nfs4_create_arg *args)
22851da177e4SLinus Torvalds {
22869f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22871da177e4SLinus Torvalds }
22881da177e4SLinus Torvalds 
22891da177e4SLinus Torvalds /*
22901da177e4SLinus Torvalds  * Encode GETATTR request
22911da177e4SLinus Torvalds  */
22929f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
22939f06c719SChuck Lever 				 const struct nfs4_getattr_arg *args)
22941da177e4SLinus Torvalds {
22951da177e4SLinus Torvalds 	struct compound_hdr hdr = {
229666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22971da177e4SLinus Torvalds 	};
22981da177e4SLinus Torvalds 
22999f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23009f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23019f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23029f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2303d017931cSAndy Adamson 	encode_nops(&hdr);
23041da177e4SLinus Torvalds }
23051da177e4SLinus Torvalds 
23061da177e4SLinus Torvalds /*
23071da177e4SLinus Torvalds  * Encode a CLOSE request
23081da177e4SLinus Torvalds  */
23099f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
23109f06c719SChuck Lever 			       struct nfs_closeargs *args)
23111da177e4SLinus Torvalds {
23121da177e4SLinus Torvalds 	struct compound_hdr hdr = {
231366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23141da177e4SLinus Torvalds 	};
23151da177e4SLinus Torvalds 
23169f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23179f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23189f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23199f06c719SChuck Lever 	encode_close(xdr, args, &hdr);
23209f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2321d017931cSAndy Adamson 	encode_nops(&hdr);
23221da177e4SLinus Torvalds }
23231da177e4SLinus Torvalds 
23241da177e4SLinus Torvalds /*
23251da177e4SLinus Torvalds  * Encode an OPEN request
23261da177e4SLinus Torvalds  */
23279f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
23289f06c719SChuck Lever 			      struct nfs_openargs *args)
23291da177e4SLinus Torvalds {
23301da177e4SLinus Torvalds 	struct compound_hdr hdr = {
233166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23321da177e4SLinus Torvalds 	};
23331da177e4SLinus Torvalds 
23349f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23359f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23369f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23379f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
23389f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
23399f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
23409f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
23419f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
23426926afd1STrond Myklebust 	encode_getfattr(xdr, args->dir_bitmask, &hdr);
2343d017931cSAndy Adamson 	encode_nops(&hdr);
23441da177e4SLinus Torvalds }
23451da177e4SLinus Torvalds 
23461da177e4SLinus Torvalds /*
23471da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
23481da177e4SLinus Torvalds  */
23499f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
23509f06c719SChuck Lever 				      struct xdr_stream *xdr,
23519f06c719SChuck Lever 				      struct nfs_open_confirmargs *args)
23521da177e4SLinus Torvalds {
23531da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2354d017931cSAndy Adamson 		.nops   = 0,
23551da177e4SLinus Torvalds 	};
23561da177e4SLinus Torvalds 
23579f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23589f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23599f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2360d017931cSAndy Adamson 	encode_nops(&hdr);
23611da177e4SLinus Torvalds }
23621da177e4SLinus Torvalds 
23631da177e4SLinus Torvalds /*
23641da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
23651da177e4SLinus Torvalds  */
23669f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
23679f06c719SChuck Lever 				     struct xdr_stream *xdr,
23689f06c719SChuck Lever 				     struct nfs_openargs *args)
23691da177e4SLinus Torvalds {
23701da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23721da177e4SLinus Torvalds 	};
23731da177e4SLinus Torvalds 
23749f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23759f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23769f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23779f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
23789f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2379d017931cSAndy Adamson 	encode_nops(&hdr);
23801da177e4SLinus Torvalds }
23811da177e4SLinus Torvalds 
23821da177e4SLinus Torvalds /*
23831da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23841da177e4SLinus Torvalds  */
23859f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
23869f06c719SChuck Lever 					struct xdr_stream *xdr,
23879f06c719SChuck Lever 					struct nfs_closeargs *args)
23881da177e4SLinus Torvalds {
23891da177e4SLinus Torvalds 	struct compound_hdr hdr = {
239066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23911da177e4SLinus Torvalds 	};
23921da177e4SLinus Torvalds 
23939f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23949f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23959f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23969f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
23979f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2398d017931cSAndy Adamson 	encode_nops(&hdr);
23991da177e4SLinus Torvalds }
24001da177e4SLinus Torvalds 
24011da177e4SLinus Torvalds /*
24021da177e4SLinus Torvalds  * Encode a LOCK request
24031da177e4SLinus Torvalds  */
24049f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
24059f06c719SChuck Lever 			      struct nfs_lock_args *args)
24061da177e4SLinus Torvalds {
24071da177e4SLinus Torvalds 	struct compound_hdr hdr = {
240866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24091da177e4SLinus Torvalds 	};
24101da177e4SLinus Torvalds 
24119f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24129f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24139f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24149f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2415d017931cSAndy Adamson 	encode_nops(&hdr);
24161da177e4SLinus Torvalds }
24171da177e4SLinus Torvalds 
24181da177e4SLinus Torvalds /*
24191da177e4SLinus Torvalds  * Encode a LOCKT request
24201da177e4SLinus Torvalds  */
24219f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
24229f06c719SChuck Lever 			       struct nfs_lockt_args *args)
24231da177e4SLinus Torvalds {
24241da177e4SLinus Torvalds 	struct compound_hdr hdr = {
242566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24261da177e4SLinus Torvalds 	};
24271da177e4SLinus Torvalds 
24289f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24299f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24309f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24319f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2432d017931cSAndy Adamson 	encode_nops(&hdr);
24331da177e4SLinus Torvalds }
24341da177e4SLinus Torvalds 
24351da177e4SLinus Torvalds /*
24361da177e4SLinus Torvalds  * Encode a LOCKU request
24371da177e4SLinus Torvalds  */
24389f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
24399f06c719SChuck Lever 			       struct nfs_locku_args *args)
24401da177e4SLinus Torvalds {
24411da177e4SLinus Torvalds 	struct compound_hdr hdr = {
244266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24431da177e4SLinus Torvalds 	};
24441da177e4SLinus Torvalds 
24459f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24469f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24479f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24489f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2449d017931cSAndy Adamson 	encode_nops(&hdr);
24501da177e4SLinus Torvalds }
24511da177e4SLinus Torvalds 
24529f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
24539f06c719SChuck Lever 					   struct xdr_stream *xdr,
24549f06c719SChuck Lever 					struct nfs_release_lockowner_args *args)
2455d3c7b7ccSTrond Myklebust {
2456d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2457d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2458d3c7b7ccSTrond Myklebust 	};
2459d3c7b7ccSTrond Myklebust 
24609f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24619f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2462d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2463d3c7b7ccSTrond Myklebust }
2464d3c7b7ccSTrond Myklebust 
24651da177e4SLinus Torvalds /*
24661da177e4SLinus Torvalds  * Encode a READLINK request
24671da177e4SLinus Torvalds  */
24689f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
24699f06c719SChuck Lever 				  const struct nfs4_readlink *args)
24701da177e4SLinus Torvalds {
24711da177e4SLinus Torvalds 	struct compound_hdr hdr = {
247266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24731da177e4SLinus Torvalds 	};
24741da177e4SLinus Torvalds 
24759f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24769f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24779f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24789f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2479e3a535e1STrond Myklebust 
248028f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2481e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2482d017931cSAndy Adamson 	encode_nops(&hdr);
24831da177e4SLinus Torvalds }
24841da177e4SLinus Torvalds 
24851da177e4SLinus Torvalds /*
24861da177e4SLinus Torvalds  * Encode a READDIR request
24871da177e4SLinus Torvalds  */
24889f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
24899f06c719SChuck Lever 				 const struct nfs4_readdir_arg *args)
24901da177e4SLinus Torvalds {
24911da177e4SLinus Torvalds 	struct compound_hdr hdr = {
249266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24931da177e4SLinus Torvalds 	};
24941da177e4SLinus Torvalds 
24959f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24969f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24979f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24989f06c719SChuck Lever 	encode_readdir(xdr, args, req, &hdr);
2499d6ac02dfSTrond Myklebust 
250028f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2501d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2502d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
250328f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2504d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2505d017931cSAndy Adamson 	encode_nops(&hdr);
25061da177e4SLinus Torvalds }
25071da177e4SLinus Torvalds 
25081da177e4SLinus Torvalds /*
25091da177e4SLinus Torvalds  * Encode a READ request
25101da177e4SLinus Torvalds  */
25119f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
25129f06c719SChuck Lever 			      struct nfs_readargs *args)
25131da177e4SLinus Torvalds {
25141da177e4SLinus Torvalds 	struct compound_hdr hdr = {
251566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25161da177e4SLinus Torvalds 	};
25171da177e4SLinus Torvalds 
25189f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25199f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25209f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25219f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
25221da177e4SLinus Torvalds 
252328f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
25241da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
25254f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2526d017931cSAndy Adamson 	encode_nops(&hdr);
25271da177e4SLinus Torvalds }
25281da177e4SLinus Torvalds 
25291da177e4SLinus Torvalds /*
25301da177e4SLinus Torvalds  * Encode an SETATTR request
25311da177e4SLinus Torvalds  */
25329f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
25339f06c719SChuck Lever 				 struct nfs_setattrargs *args)
25341da177e4SLinus Torvalds {
25351da177e4SLinus Torvalds 	struct compound_hdr hdr = {
253666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25371da177e4SLinus Torvalds 	};
25381da177e4SLinus Torvalds 
25399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25409f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25419f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25429f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
25439f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2544d017931cSAndy Adamson 	encode_nops(&hdr);
25451da177e4SLinus Torvalds }
25461da177e4SLinus Torvalds 
25471da177e4SLinus Torvalds /*
2548029d105eSJ. Bruce Fields  * Encode a GETACL request
2549029d105eSJ. Bruce Fields  */
25509f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2551029d105eSJ. Bruce Fields 				struct nfs_getaclargs *args)
2552029d105eSJ. Bruce Fields {
2553029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
255466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2555029d105eSJ. Bruce Fields 	};
255628f56694SBenny Halevy 	uint32_t replen;
2557029d105eSJ. Bruce Fields 
25589f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25599f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25609f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2561bf118a34SAndy Adamson 	replen = hdr.replen + op_decode_hdr_maxsz + 1;
25629f06c719SChuck Lever 	encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2563cf8cdbe5SAndy Adamson 
256428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2565029d105eSJ. Bruce Fields 		args->acl_pages, args->acl_pgbase, args->acl_len);
2566bf118a34SAndy Adamson 
2567d017931cSAndy Adamson 	encode_nops(&hdr);
2568029d105eSJ. Bruce Fields }
2569029d105eSJ. Bruce Fields 
2570029d105eSJ. Bruce Fields /*
25711da177e4SLinus Torvalds  * Encode a WRITE request
25721da177e4SLinus Torvalds  */
25739f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
25749f06c719SChuck Lever 			       struct nfs_writeargs *args)
25751da177e4SLinus Torvalds {
25761da177e4SLinus Torvalds 	struct compound_hdr hdr = {
257766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25781da177e4SLinus Torvalds 	};
25791da177e4SLinus Torvalds 
25809f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25819f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25829f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25839f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
25844f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
25857ffd1064SFred Isaman 	if (args->bitmask)
25869f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2587d017931cSAndy Adamson 	encode_nops(&hdr);
25881da177e4SLinus Torvalds }
25891da177e4SLinus Torvalds 
25901da177e4SLinus Torvalds /*
25911da177e4SLinus Torvalds  *  a COMMIT request
25921da177e4SLinus Torvalds  */
25939f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
25949f06c719SChuck Lever 				struct nfs_writeargs *args)
25951da177e4SLinus Torvalds {
25961da177e4SLinus Torvalds 	struct compound_hdr hdr = {
259766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25981da177e4SLinus Torvalds 	};
25991da177e4SLinus Torvalds 
26009f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26019f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26029f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26039f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2604988b6dceSFred Isaman 	if (args->bitmask)
26059f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2606d017931cSAndy Adamson 	encode_nops(&hdr);
26071da177e4SLinus Torvalds }
26081da177e4SLinus Torvalds 
26091da177e4SLinus Torvalds /*
26101da177e4SLinus Torvalds  * FSINFO request
26111da177e4SLinus Torvalds  */
26129f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
26139f06c719SChuck Lever 				struct nfs4_fsinfo_arg *args)
26141da177e4SLinus Torvalds {
26151da177e4SLinus Torvalds 	struct compound_hdr hdr = {
261666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26171da177e4SLinus Torvalds 	};
26181da177e4SLinus Torvalds 
26199f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26209f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26219f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26229f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2623d017931cSAndy Adamson 	encode_nops(&hdr);
26241da177e4SLinus Torvalds }
26251da177e4SLinus Torvalds 
26261da177e4SLinus Torvalds /*
26271da177e4SLinus Torvalds  * a PATHCONF request
26281da177e4SLinus Torvalds  */
26299f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
26309f06c719SChuck Lever 				  const struct nfs4_pathconf_arg *args)
26311da177e4SLinus Torvalds {
26321da177e4SLinus Torvalds 	struct compound_hdr hdr = {
263366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26341da177e4SLinus Torvalds 	};
26351da177e4SLinus Torvalds 
26369f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26379f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26389f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26399f06c719SChuck Lever 	encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2640d017931cSAndy Adamson 			   &hdr);
2641d017931cSAndy Adamson 	encode_nops(&hdr);
26421da177e4SLinus Torvalds }
26431da177e4SLinus Torvalds 
26441da177e4SLinus Torvalds /*
26451da177e4SLinus Torvalds  * a STATFS request
26461da177e4SLinus Torvalds  */
26479f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
26489f06c719SChuck Lever 				const struct nfs4_statfs_arg *args)
26491da177e4SLinus Torvalds {
26501da177e4SLinus Torvalds 	struct compound_hdr hdr = {
265166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26521da177e4SLinus Torvalds 	};
26531da177e4SLinus Torvalds 
26549f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26559f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26569f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26579f06c719SChuck Lever 	encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2658d017931cSAndy Adamson 			   args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2659d017931cSAndy Adamson 	encode_nops(&hdr);
26601da177e4SLinus Torvalds }
26611da177e4SLinus Torvalds 
26621da177e4SLinus Torvalds /*
26631da177e4SLinus Torvalds  * GETATTR_BITMAP request
26641da177e4SLinus Torvalds  */
26659f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
26669f06c719SChuck Lever 				     struct xdr_stream *xdr,
266743652ad5SBenny Halevy 				     struct nfs4_server_caps_arg *args)
26681da177e4SLinus Torvalds {
26691da177e4SLinus Torvalds 	struct compound_hdr hdr = {
267066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26711da177e4SLinus Torvalds 	};
26721da177e4SLinus Torvalds 
26739f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26749f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26759f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
26769f06c719SChuck Lever 	encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2677264e6351SChuck Lever 			   FATTR4_WORD0_FH_EXPIRE_TYPE|
26781da177e4SLinus Torvalds 			   FATTR4_WORD0_LINK_SUPPORT|
26791da177e4SLinus Torvalds 			   FATTR4_WORD0_SYMLINK_SUPPORT|
2680d017931cSAndy Adamson 			   FATTR4_WORD0_ACLSUPPORT, &hdr);
2681d017931cSAndy Adamson 	encode_nops(&hdr);
26821da177e4SLinus Torvalds }
26831da177e4SLinus Torvalds 
26841da177e4SLinus Torvalds /*
26851da177e4SLinus Torvalds  * a RENEW request
26861da177e4SLinus Torvalds  */
26879f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
26889f06c719SChuck Lever 			       struct nfs_client *clp)
26891da177e4SLinus Torvalds {
26901da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2691d017931cSAndy Adamson 		.nops	= 0,
26921da177e4SLinus Torvalds 	};
26931da177e4SLinus Torvalds 
26949f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2695bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2696d017931cSAndy Adamson 	encode_nops(&hdr);
26971da177e4SLinus Torvalds }
26981da177e4SLinus Torvalds 
26991da177e4SLinus Torvalds /*
27001da177e4SLinus Torvalds  * a SETCLIENTID request
27011da177e4SLinus Torvalds  */
27029f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
27039f06c719SChuck Lever 				     struct xdr_stream *xdr,
27049f06c719SChuck Lever 				     struct nfs4_setclientid *sc)
27051da177e4SLinus Torvalds {
27061da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2707d017931cSAndy Adamson 		.nops	= 0,
27081da177e4SLinus Torvalds 	};
27091da177e4SLinus Torvalds 
27109f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27119f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2712d017931cSAndy Adamson 	encode_nops(&hdr);
27131da177e4SLinus Torvalds }
27141da177e4SLinus Torvalds 
27151da177e4SLinus Torvalds /*
27161da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
27171da177e4SLinus Torvalds  */
27189f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
27199f06c719SChuck Lever 					     struct xdr_stream *xdr,
27209f06c719SChuck Lever 					     struct nfs4_setclientid_res *arg)
27211da177e4SLinus Torvalds {
27221da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2723d017931cSAndy Adamson 		.nops	= 0,
27241da177e4SLinus Torvalds 	};
2725dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
27261da177e4SLinus Torvalds 
27279f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27289f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
27299f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
27309f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
2731d017931cSAndy Adamson 	encode_nops(&hdr);
27321da177e4SLinus Torvalds }
27331da177e4SLinus Torvalds 
27341da177e4SLinus Torvalds /*
27351da177e4SLinus Torvalds  * DELEGRETURN request
27361da177e4SLinus Torvalds  */
27379f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
27389f06c719SChuck Lever 				     struct xdr_stream *xdr,
27399f06c719SChuck Lever 				     const struct nfs4_delegreturnargs *args)
27401da177e4SLinus Torvalds {
27411da177e4SLinus Torvalds 	struct compound_hdr hdr = {
274266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27431da177e4SLinus Torvalds 	};
27441da177e4SLinus Torvalds 
27459f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27469f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27479f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
27489f06c719SChuck Lever 	encode_delegreturn(xdr, args->stateid, &hdr);
27499f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2750d017931cSAndy Adamson 	encode_nops(&hdr);
27511da177e4SLinus Torvalds }
27521da177e4SLinus Torvalds 
27531da177e4SLinus Torvalds /*
2754683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2755683b57b4STrond Myklebust  */
27569f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
27579f06c719SChuck Lever 				      struct xdr_stream *xdr,
27589f06c719SChuck Lever 				      struct nfs4_fs_locations_arg *args)
2759683b57b4STrond Myklebust {
2760683b57b4STrond Myklebust 	struct compound_hdr hdr = {
276166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2762683b57b4STrond Myklebust 	};
276328f56694SBenny Halevy 	uint32_t replen;
2764683b57b4STrond Myklebust 
27659f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27669f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27679f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
27689f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
276928f56694SBenny Halevy 	replen = hdr.replen;	/* get the attribute into args->page */
27709f06c719SChuck Lever 	encode_fs_locations(xdr, args->bitmask, &hdr);
2771cf8cdbe5SAndy Adamson 
277228f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2773683b57b4STrond Myklebust 			0, PAGE_SIZE);
2774d017931cSAndy Adamson 	encode_nops(&hdr);
2775683b57b4STrond Myklebust }
2776683b57b4STrond Myklebust 
27775a5ea0d4SBryan Schumaker /*
27785a5ea0d4SBryan Schumaker  * Encode SECINFO request
27795a5ea0d4SBryan Schumaker  */
27805a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
27815a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
27825a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_arg *args)
27835a5ea0d4SBryan Schumaker {
27845a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
27855a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27865a5ea0d4SBryan Schumaker 	};
27875a5ea0d4SBryan Schumaker 
27885a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
27895a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
27905a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
27915a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
27925a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
27935a5ea0d4SBryan Schumaker }
27945a5ea0d4SBryan Schumaker 
279599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
279699fe60d0SBenny Halevy /*
279799fe60d0SBenny Halevy  * EXCHANGE_ID request
279899fe60d0SBenny Halevy  */
27999f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
28009f06c719SChuck Lever 				     struct xdr_stream *xdr,
280199fe60d0SBenny Halevy 				     struct nfs41_exchange_id_args *args)
280299fe60d0SBenny Halevy {
280399fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2804a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
280599fe60d0SBenny Halevy 	};
280699fe60d0SBenny Halevy 
28079f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28089f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
280999fe60d0SBenny Halevy 	encode_nops(&hdr);
281099fe60d0SBenny Halevy }
28112050f0ccSAndy Adamson 
28122050f0ccSAndy Adamson /*
2813fc931582SAndy Adamson  * a CREATE_SESSION request
2814fc931582SAndy Adamson  */
28159f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
28169f06c719SChuck Lever 					struct xdr_stream *xdr,
2817fc931582SAndy Adamson 					struct nfs41_create_session_args *args)
2818fc931582SAndy Adamson {
2819fc931582SAndy Adamson 	struct compound_hdr hdr = {
2820a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2821fc931582SAndy Adamson 	};
2822fc931582SAndy Adamson 
28239f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28249f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2825fc931582SAndy Adamson 	encode_nops(&hdr);
2826fc931582SAndy Adamson }
2827fc931582SAndy Adamson 
2828fc931582SAndy Adamson /*
28290f3e66c6SAndy Adamson  * a DESTROY_SESSION request
28300f3e66c6SAndy Adamson  */
28319f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
28329f06c719SChuck Lever 					 struct xdr_stream *xdr,
28330f3e66c6SAndy Adamson 					 struct nfs4_session *session)
28340f3e66c6SAndy Adamson {
28350f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2836a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
28370f3e66c6SAndy Adamson 	};
28380f3e66c6SAndy Adamson 
28399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28409f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
28410f3e66c6SAndy Adamson 	encode_nops(&hdr);
28420f3e66c6SAndy Adamson }
28430f3e66c6SAndy Adamson 
28440f3e66c6SAndy Adamson /*
2845fc01cea9SAndy Adamson  * a SEQUENCE request
2846fc01cea9SAndy Adamson  */
28479f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2848fc01cea9SAndy Adamson 				  struct nfs4_sequence_args *args)
2849fc01cea9SAndy Adamson {
2850fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2851fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2852fc01cea9SAndy Adamson 	};
2853fc01cea9SAndy Adamson 
28549f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28559f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2856fc01cea9SAndy Adamson 	encode_nops(&hdr);
2857fc01cea9SAndy Adamson }
2858fc01cea9SAndy Adamson 
2859fc01cea9SAndy Adamson /*
28602050f0ccSAndy Adamson  * a GET_LEASE_TIME request
28612050f0ccSAndy Adamson  */
28629f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
28639f06c719SChuck Lever 					struct xdr_stream *xdr,
28642050f0ccSAndy Adamson 					struct nfs4_get_lease_time_args *args)
28652050f0ccSAndy Adamson {
28662050f0ccSAndy Adamson 	struct compound_hdr hdr = {
28672050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
28682050f0ccSAndy Adamson 	};
2869dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
28702050f0ccSAndy Adamson 
28719f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28729f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
28739f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
28749f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
28752050f0ccSAndy Adamson 	encode_nops(&hdr);
28762050f0ccSAndy Adamson }
287718019753SRicardo Labiaga 
287818019753SRicardo Labiaga /*
287918019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
288018019753SRicardo Labiaga  */
28819f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
28829f06c719SChuck Lever 					  struct xdr_stream *xdr,
288318019753SRicardo Labiaga 				struct nfs41_reclaim_complete_args *args)
288418019753SRicardo Labiaga {
288518019753SRicardo Labiaga 	struct compound_hdr hdr = {
288618019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
288718019753SRicardo Labiaga 	};
288818019753SRicardo Labiaga 
28899f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28909f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28919f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
289218019753SRicardo Labiaga 	encode_nops(&hdr);
289318019753SRicardo Labiaga }
289418019753SRicardo Labiaga 
2895b1f69b75SAndy Adamson /*
28967f11d8d3SAndy Adamson  * Encode GETDEVICELIST request
28977f11d8d3SAndy Adamson  */
28987f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
28997f11d8d3SAndy Adamson 				       struct xdr_stream *xdr,
29007f11d8d3SAndy Adamson 				       struct nfs4_getdevicelist_args *args)
29017f11d8d3SAndy Adamson {
29027f11d8d3SAndy Adamson 	struct compound_hdr hdr = {
29037f11d8d3SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
29047f11d8d3SAndy Adamson 	};
29057f11d8d3SAndy Adamson 
29067f11d8d3SAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
29077f11d8d3SAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
29087f11d8d3SAndy Adamson 	encode_putfh(xdr, args->fh, &hdr);
29097f11d8d3SAndy Adamson 	encode_getdevicelist(xdr, args, &hdr);
29107f11d8d3SAndy Adamson 	encode_nops(&hdr);
29117f11d8d3SAndy Adamson }
29127f11d8d3SAndy Adamson 
29137f11d8d3SAndy Adamson /*
2914b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
2915b1f69b75SAndy Adamson  */
29169f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
29179f06c719SChuck Lever 				       struct xdr_stream *xdr,
2918b1f69b75SAndy Adamson 				       struct nfs4_getdeviceinfo_args *args)
2919b1f69b75SAndy Adamson {
2920b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2921b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2922b1f69b75SAndy Adamson 	};
2923b1f69b75SAndy Adamson 
29249f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29259f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29269f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
2927b1f69b75SAndy Adamson 
2928b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
2929b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
2930b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2931b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
2932b1f69b75SAndy Adamson 			 args->pdev->pglen);
2933b1f69b75SAndy Adamson 
2934b1f69b75SAndy Adamson 	encode_nops(&hdr);
2935b1f69b75SAndy Adamson }
2936b1f69b75SAndy Adamson 
2937b1f69b75SAndy Adamson /*
2938b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
2939b1f69b75SAndy Adamson  */
29409f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
29419f06c719SChuck Lever 				   struct xdr_stream *xdr,
2942b1f69b75SAndy Adamson 				   struct nfs4_layoutget_args *args)
2943b1f69b75SAndy Adamson {
2944b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2945b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2946b1f69b75SAndy Adamson 	};
2947b1f69b75SAndy Adamson 
29489f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29499f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29509f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
29519f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
295235124a09SWeston Andros Adamson 
295335124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
295435124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
295535124a09SWeston Andros Adamson 
2956b1f69b75SAndy Adamson 	encode_nops(&hdr);
2957b1f69b75SAndy Adamson }
2958863a3c6cSAndy Adamson 
2959863a3c6cSAndy Adamson /*
2960863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
2961863a3c6cSAndy Adamson  */
2962cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2963863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
2964863a3c6cSAndy Adamson 				      struct nfs4_layoutcommit_args *args)
2965863a3c6cSAndy Adamson {
2966ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
2967ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
2968863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
2969863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970863a3c6cSAndy Adamson 	};
2971863a3c6cSAndy Adamson 
2972863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
2973863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
2974863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2975ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2976863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
2977863a3c6cSAndy Adamson 	encode_nops(&hdr);
2978cbe82603SBenny Halevy }
2979cbe82603SBenny Halevy 
2980cbe82603SBenny Halevy /*
2981cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
2982cbe82603SBenny Halevy  */
2983cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2984cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
2985cbe82603SBenny Halevy 				      struct nfs4_layoutreturn_args *args)
2986cbe82603SBenny Halevy {
2987cbe82603SBenny Halevy 	struct compound_hdr hdr = {
2988cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989cbe82603SBenny Halevy 	};
2990cbe82603SBenny Halevy 
2991cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
2992cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
2993cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2994cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
2995cbe82603SBenny Halevy 	encode_nops(&hdr);
2996863a3c6cSAndy Adamson }
2997fca78d6dSBryan Schumaker 
2998fca78d6dSBryan Schumaker /*
2999fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
3000fca78d6dSBryan Schumaker  */
3001fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3002fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
3003fca78d6dSBryan Schumaker 					struct nfs41_secinfo_no_name_args *args)
3004fca78d6dSBryan Schumaker {
3005fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
3006fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3007fca78d6dSBryan Schumaker 	};
3008fca78d6dSBryan Schumaker 
3009fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
3010fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
3011fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
3012fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
3013fca78d6dSBryan Schumaker 	encode_nops(&hdr);
3014fca78d6dSBryan Schumaker 	return 0;
3015fca78d6dSBryan Schumaker }
30167d974794SBryan Schumaker 
30177d974794SBryan Schumaker /*
30187d974794SBryan Schumaker  *  Encode TEST_STATEID request
30197d974794SBryan Schumaker  */
30207d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
30217d974794SBryan Schumaker 				      struct xdr_stream *xdr,
30227d974794SBryan Schumaker 				      struct nfs41_test_stateid_args *args)
30237d974794SBryan Schumaker {
30247d974794SBryan Schumaker 	struct compound_hdr hdr = {
30257d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30267d974794SBryan Schumaker 	};
30277d974794SBryan Schumaker 
30287d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30297d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30307d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
30317d974794SBryan Schumaker 	encode_nops(&hdr);
30327d974794SBryan Schumaker }
30339aeda35fSBryan Schumaker 
30349aeda35fSBryan Schumaker /*
30359aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
30369aeda35fSBryan Schumaker  */
30379aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
30389aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
30399aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_args *args)
30409aeda35fSBryan Schumaker {
30419aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
30429aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30439aeda35fSBryan Schumaker 	};
30449aeda35fSBryan Schumaker 
30459aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30469aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30479aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
30489aeda35fSBryan Schumaker 	encode_nops(&hdr);
30499aeda35fSBryan Schumaker }
305099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
305199fe60d0SBenny Halevy 
3052686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3053686841b3SBenny Halevy {
3054686841b3SBenny Halevy 	dprintk("nfs: %s: prematurely hit end of receive buffer. "
3055686841b3SBenny Halevy 		"Remaining buffer length is %tu words.\n",
3056686841b3SBenny Halevy 		func, xdr->end - xdr->p);
3057686841b3SBenny Halevy }
30581da177e4SLinus Torvalds 
3059683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
30601da177e4SLinus Torvalds {
30618687b63aSAl Viro 	__be32 *p;
30621da177e4SLinus Torvalds 
3063c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3064c0eae66eSBenny Halevy 	if (unlikely(!p))
3065c0eae66eSBenny Halevy 		goto out_overflow;
3066cccddf4fSBenny Halevy 	*len = be32_to_cpup(p);
3067c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, *len);
3068c0eae66eSBenny Halevy 	if (unlikely(!p))
3069c0eae66eSBenny Halevy 		goto out_overflow;
30701da177e4SLinus Torvalds 	*string = (char *)p;
30711da177e4SLinus Torvalds 	return 0;
3072c0eae66eSBenny Halevy out_overflow:
3073c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3074c0eae66eSBenny Halevy 	return -EIO;
30751da177e4SLinus Torvalds }
30761da177e4SLinus Torvalds 
30771da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
30781da177e4SLinus Torvalds {
30798687b63aSAl Viro 	__be32 *p;
30801da177e4SLinus Torvalds 
3081c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3082c0eae66eSBenny Halevy 	if (unlikely(!p))
3083c0eae66eSBenny Halevy 		goto out_overflow;
30846f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3085cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
30861da177e4SLinus Torvalds 
3087c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3088c0eae66eSBenny Halevy 	if (unlikely(!p))
3089c0eae66eSBenny Halevy 		goto out_overflow;
30901da177e4SLinus Torvalds 	hdr->tag = (char *)p;
30911da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3092cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3093aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3094aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
30951da177e4SLinus Torvalds 	return 0;
3096c0eae66eSBenny Halevy out_overflow:
3097c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3098c0eae66eSBenny Halevy 	return -EIO;
30991da177e4SLinus Torvalds }
31001da177e4SLinus Torvalds 
31011da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
31021da177e4SLinus Torvalds {
31038687b63aSAl Viro 	__be32 *p;
31041da177e4SLinus Torvalds 	uint32_t opnum;
31051da177e4SLinus Torvalds 	int32_t nfserr;
31061da177e4SLinus Torvalds 
3107c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3108c0eae66eSBenny Halevy 	if (unlikely(!p))
3109c0eae66eSBenny Halevy 		goto out_overflow;
31106f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
31111da177e4SLinus Torvalds 	if (opnum != expected) {
3112fe82a183SChuck Lever 		dprintk("nfs: Server returned operation"
31131da177e4SLinus Torvalds 			" %d but we issued a request for %d\n",
31141da177e4SLinus Torvalds 				opnum, expected);
31151da177e4SLinus Torvalds 		return -EIO;
31161da177e4SLinus Torvalds 	}
3117cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
31181da177e4SLinus Torvalds 	if (nfserr != NFS_OK)
3119856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
31201da177e4SLinus Torvalds 	return 0;
3121c0eae66eSBenny Halevy out_overflow:
3122c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3123c0eae66eSBenny Halevy 	return -EIO;
31241da177e4SLinus Torvalds }
31251da177e4SLinus Torvalds 
31261da177e4SLinus Torvalds /* Dummy routine */
3127adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
31281da177e4SLinus Torvalds {
31298687b63aSAl Viro 	__be32 *p;
3130683b57b4STrond Myklebust 	unsigned int strlen;
31311da177e4SLinus Torvalds 	char *str;
31321da177e4SLinus Torvalds 
3133c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3134c0eae66eSBenny Halevy 	if (likely(p))
31351da177e4SLinus Torvalds 		return decode_opaque_inline(xdr, &strlen, &str);
3136c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3137c0eae66eSBenny Halevy 	return -EIO;
31381da177e4SLinus Torvalds }
31391da177e4SLinus Torvalds 
31401da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
31411da177e4SLinus Torvalds {
31428687b63aSAl Viro 	uint32_t bmlen;
31438687b63aSAl Viro 	__be32 *p;
31441da177e4SLinus Torvalds 
3145c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3146c0eae66eSBenny Halevy 	if (unlikely(!p))
3147c0eae66eSBenny Halevy 		goto out_overflow;
3148cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
31491da177e4SLinus Torvalds 
3150dae100c2SFred Isaman 	bitmap[0] = bitmap[1] = bitmap[2] = 0;
3151c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, (bmlen << 2));
3152c0eae66eSBenny Halevy 	if (unlikely(!p))
3153c0eae66eSBenny Halevy 		goto out_overflow;
31541da177e4SLinus Torvalds 	if (bmlen > 0) {
31556f723f77SBenny Halevy 		bitmap[0] = be32_to_cpup(p++);
3156dae100c2SFred Isaman 		if (bmlen > 1) {
3157dae100c2SFred Isaman 			bitmap[1] = be32_to_cpup(p++);
3158dae100c2SFred Isaman 			if (bmlen > 2)
3159dae100c2SFred Isaman 				bitmap[2] = be32_to_cpup(p);
3160dae100c2SFred Isaman 		}
31611da177e4SLinus Torvalds 	}
31621da177e4SLinus Torvalds 	return 0;
3163c0eae66eSBenny Halevy out_overflow:
3164c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3165c0eae66eSBenny Halevy 	return -EIO;
31661da177e4SLinus Torvalds }
31671da177e4SLinus Torvalds 
31688687b63aSAl Viro static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
31691da177e4SLinus Torvalds {
31708687b63aSAl Viro 	__be32 *p;
31711da177e4SLinus Torvalds 
3172c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3173c0eae66eSBenny Halevy 	if (unlikely(!p))
3174c0eae66eSBenny Halevy 		goto out_overflow;
3175cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
31761da177e4SLinus Torvalds 	*savep = xdr->p;
31771da177e4SLinus Torvalds 	return 0;
3178c0eae66eSBenny Halevy out_overflow:
3179c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3180c0eae66eSBenny Halevy 	return -EIO;
31811da177e4SLinus Torvalds }
31821da177e4SLinus Torvalds 
31831da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
31841da177e4SLinus Torvalds {
31851da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
31863388bff5SRoman Borisov 		int ret;
31873388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
31883388bff5SRoman Borisov 		if (unlikely(ret < 0))
31893388bff5SRoman Borisov 			return ret;
31901da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
31911da177e4SLinus Torvalds 	} else
3192dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3193dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3194dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
31951da177e4SLinus Torvalds 	return 0;
31961da177e4SLinus Torvalds }
31971da177e4SLinus Torvalds 
31981da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
31991da177e4SLinus Torvalds {
32008687b63aSAl Viro 	__be32 *p;
3201409924e4STrond Myklebust 	int ret = 0;
32021da177e4SLinus Torvalds 
32031da177e4SLinus Torvalds 	*type = 0;
32041da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
32051da177e4SLinus Torvalds 		return -EIO;
32061da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3207c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3208c0eae66eSBenny Halevy 		if (unlikely(!p))
3209c0eae66eSBenny Halevy 			goto out_overflow;
3210cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
32111da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
32123110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
32131da177e4SLinus Torvalds 			return -EIO;
32141da177e4SLinus Torvalds 		}
32151da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3216409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32171da177e4SLinus Torvalds 	}
3218bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3219409924e4STrond Myklebust 	return ret;
3220c0eae66eSBenny Halevy out_overflow:
3221c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3222c0eae66eSBenny Halevy 	return -EIO;
32231da177e4SLinus Torvalds }
32241da177e4SLinus Torvalds 
3225264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3226264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3227264e6351SChuck Lever {
3228264e6351SChuck Lever 	__be32 *p;
3229264e6351SChuck Lever 
3230264e6351SChuck Lever 	*type = 0;
3231264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3232264e6351SChuck Lever 		return -EIO;
3233264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3234264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3235264e6351SChuck Lever 		if (unlikely(!p))
3236264e6351SChuck Lever 			goto out_overflow;
3237264e6351SChuck Lever 		*type = be32_to_cpup(p);
3238264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3239264e6351SChuck Lever 	}
3240264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3241264e6351SChuck Lever 	return 0;
3242264e6351SChuck Lever out_overflow:
3243264e6351SChuck Lever 	print_overflow_msg(__func__, xdr);
3244264e6351SChuck Lever 	return -EIO;
3245264e6351SChuck Lever }
3246264e6351SChuck Lever 
32471da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
32481da177e4SLinus Torvalds {
32498687b63aSAl Viro 	__be32 *p;
3250409924e4STrond Myklebust 	int ret = 0;
32511da177e4SLinus Torvalds 
32521da177e4SLinus Torvalds 	*change = 0;
32531da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
32541da177e4SLinus Torvalds 		return -EIO;
32551da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3256c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3257c0eae66eSBenny Halevy 		if (unlikely(!p))
3258c0eae66eSBenny Halevy 			goto out_overflow;
3259cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
32601da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3261409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
32621da177e4SLinus Torvalds 	}
32633110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
32641da177e4SLinus Torvalds 			(unsigned long long)*change);
3265409924e4STrond Myklebust 	return ret;
3266c0eae66eSBenny Halevy out_overflow:
3267c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3268c0eae66eSBenny Halevy 	return -EIO;
32691da177e4SLinus Torvalds }
32701da177e4SLinus Torvalds 
32711da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
32721da177e4SLinus Torvalds {
32738687b63aSAl Viro 	__be32 *p;
3274409924e4STrond Myklebust 	int ret = 0;
32751da177e4SLinus Torvalds 
32761da177e4SLinus Torvalds 	*size = 0;
32771da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
32781da177e4SLinus Torvalds 		return -EIO;
32791da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3280c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3281c0eae66eSBenny Halevy 		if (unlikely(!p))
3282c0eae66eSBenny Halevy 			goto out_overflow;
3283cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
32841da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3285409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
32861da177e4SLinus Torvalds 	}
32873110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3288409924e4STrond Myklebust 	return ret;
3289c0eae66eSBenny Halevy out_overflow:
3290c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3291c0eae66eSBenny Halevy 	return -EIO;
32921da177e4SLinus Torvalds }
32931da177e4SLinus Torvalds 
32941da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32951da177e4SLinus Torvalds {
32968687b63aSAl Viro 	__be32 *p;
32971da177e4SLinus Torvalds 
32981da177e4SLinus Torvalds 	*res = 0;
32991da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
33001da177e4SLinus Torvalds 		return -EIO;
33011da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3302c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3303c0eae66eSBenny Halevy 		if (unlikely(!p))
3304c0eae66eSBenny Halevy 			goto out_overflow;
3305cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33061da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
33071da177e4SLinus Torvalds 	}
33083110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
33091da177e4SLinus Torvalds 	return 0;
3310c0eae66eSBenny Halevy out_overflow:
3311c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3312c0eae66eSBenny Halevy 	return -EIO;
33131da177e4SLinus Torvalds }
33141da177e4SLinus Torvalds 
33151da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33161da177e4SLinus Torvalds {
33178687b63aSAl Viro 	__be32 *p;
33181da177e4SLinus Torvalds 
33191da177e4SLinus Torvalds 	*res = 0;
33201da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
33211da177e4SLinus Torvalds 		return -EIO;
33221da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3323c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3324c0eae66eSBenny Halevy 		if (unlikely(!p))
3325c0eae66eSBenny Halevy 			goto out_overflow;
3326cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33271da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
33281da177e4SLinus Torvalds 	}
33293110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
33301da177e4SLinus Torvalds 	return 0;
3331c0eae66eSBenny Halevy out_overflow:
3332c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3333c0eae66eSBenny Halevy 	return -EIO;
33341da177e4SLinus Torvalds }
33351da177e4SLinus Torvalds 
33368b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
33371da177e4SLinus Torvalds {
33388687b63aSAl Viro 	__be32 *p;
3339409924e4STrond Myklebust 	int ret = 0;
33401da177e4SLinus Torvalds 
33411da177e4SLinus Torvalds 	fsid->major = 0;
33421da177e4SLinus Torvalds 	fsid->minor = 0;
33431da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
33441da177e4SLinus Torvalds 		return -EIO;
33451da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3346c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3347c0eae66eSBenny Halevy 		if (unlikely(!p))
3348c0eae66eSBenny Halevy 			goto out_overflow;
33493ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3350cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
33511da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3352409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
33531da177e4SLinus Torvalds 	}
33543110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
33551da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
33561da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3357409924e4STrond Myklebust 	return ret;
3358c0eae66eSBenny Halevy out_overflow:
3359c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3360c0eae66eSBenny Halevy 	return -EIO;
33611da177e4SLinus Torvalds }
33621da177e4SLinus Torvalds 
33631da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33641da177e4SLinus Torvalds {
33658687b63aSAl Viro 	__be32 *p;
33661da177e4SLinus Torvalds 
33671da177e4SLinus Torvalds 	*res = 60;
33681da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
33691da177e4SLinus Torvalds 		return -EIO;
33701da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3371c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3372c0eae66eSBenny Halevy 		if (unlikely(!p))
3373c0eae66eSBenny Halevy 			goto out_overflow;
3374cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33751da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
33761da177e4SLinus Torvalds 	}
33773110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
33781da177e4SLinus Torvalds 	return 0;
3379c0eae66eSBenny Halevy out_overflow:
3380c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3381c0eae66eSBenny Halevy 	return -EIO;
33821da177e4SLinus Torvalds }
33831da177e4SLinus Torvalds 
3384ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3385ae42c70aSBryan Schumaker {
3386ae42c70aSBryan Schumaker 	__be32 *p;
3387ae42c70aSBryan Schumaker 
3388ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3389ae42c70aSBryan Schumaker 		return -EIO;
3390ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3391ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3392ae42c70aSBryan Schumaker 		if (unlikely(!p))
3393ae42c70aSBryan Schumaker 			goto out_overflow;
3394ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3395ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3396ae42c70aSBryan Schumaker 	}
3397ae42c70aSBryan Schumaker 	return 0;
3398ae42c70aSBryan Schumaker out_overflow:
3399ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3400ae42c70aSBryan Schumaker 	return -EIO;
3401ae42c70aSBryan Schumaker }
3402ae42c70aSBryan Schumaker 
3403ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3404ae42c70aSBryan Schumaker {
3405ae42c70aSBryan Schumaker 	__be32 *p;
3406ae42c70aSBryan Schumaker 	int len;
3407ae42c70aSBryan Schumaker 
34087ad07353STrond Myklebust 	if (fh != NULL)
3409ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3410ae42c70aSBryan Schumaker 
3411ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3412ae42c70aSBryan Schumaker 		return -EIO;
3413ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3414ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3415ae42c70aSBryan Schumaker 		if (unlikely(!p))
3416ae42c70aSBryan Schumaker 			goto out_overflow;
3417ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3418ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3419ae42c70aSBryan Schumaker 			return -EIO;
3420ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3421ae42c70aSBryan Schumaker 		if (unlikely(!p))
3422ae42c70aSBryan Schumaker 			goto out_overflow;
34237ad07353STrond Myklebust 		if (fh != NULL) {
3424ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
34257ad07353STrond Myklebust 			fh->size = len;
34267ad07353STrond Myklebust 		}
3427ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3428ae42c70aSBryan Schumaker 	}
3429ae42c70aSBryan Schumaker 	return 0;
3430ae42c70aSBryan Schumaker out_overflow:
3431ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3432ae42c70aSBryan Schumaker 	return -EIO;
3433ae42c70aSBryan Schumaker }
3434ae42c70aSBryan Schumaker 
34351da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34361da177e4SLinus Torvalds {
34378687b63aSAl Viro 	__be32 *p;
34381da177e4SLinus Torvalds 
34391da177e4SLinus Torvalds 	*res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
34401da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
34411da177e4SLinus Torvalds 		return -EIO;
34421da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3443c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3444c0eae66eSBenny Halevy 		if (unlikely(!p))
3445c0eae66eSBenny Halevy 			goto out_overflow;
3446cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34471da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
34481da177e4SLinus Torvalds 	}
34493110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
34501da177e4SLinus Torvalds 	return 0;
3451c0eae66eSBenny Halevy out_overflow:
3452c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3453c0eae66eSBenny Halevy 	return -EIO;
34541da177e4SLinus Torvalds }
34551da177e4SLinus Torvalds 
34561da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
34571da177e4SLinus Torvalds {
34588687b63aSAl Viro 	__be32 *p;
3459409924e4STrond Myklebust 	int ret = 0;
34601da177e4SLinus Torvalds 
34611da177e4SLinus Torvalds 	*fileid = 0;
34621da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
34631da177e4SLinus Torvalds 		return -EIO;
34641da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3465c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3466c0eae66eSBenny Halevy 		if (unlikely(!p))
3467c0eae66eSBenny Halevy 			goto out_overflow;
3468cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
34691da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3470409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
34711da177e4SLinus Torvalds 	}
34723110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3473409924e4STrond Myklebust 	return ret;
3474c0eae66eSBenny Halevy out_overflow:
3475c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3476c0eae66eSBenny Halevy 	return -EIO;
34771da177e4SLinus Torvalds }
34781da177e4SLinus Torvalds 
347999baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
348099baf625SManoj Naik {
34818687b63aSAl Viro 	__be32 *p;
3482409924e4STrond Myklebust 	int ret = 0;
348399baf625SManoj Naik 
348499baf625SManoj Naik 	*fileid = 0;
348599baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
348699baf625SManoj Naik 		return -EIO;
348799baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3488c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3489c0eae66eSBenny Halevy 		if (unlikely(!p))
3490c0eae66eSBenny Halevy 			goto out_overflow;
3491cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
349299baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
349328331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
349499baf625SManoj Naik 	}
34953110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3496409924e4STrond Myklebust 	return ret;
3497c0eae66eSBenny Halevy out_overflow:
3498c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3499c0eae66eSBenny Halevy 	return -EIO;
350099baf625SManoj Naik }
350199baf625SManoj Naik 
35021da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35031da177e4SLinus Torvalds {
35048687b63aSAl Viro 	__be32 *p;
35051da177e4SLinus Torvalds 	int status = 0;
35061da177e4SLinus Torvalds 
35071da177e4SLinus Torvalds 	*res = 0;
35081da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
35091da177e4SLinus Torvalds 		return -EIO;
35101da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3511c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3512c0eae66eSBenny Halevy 		if (unlikely(!p))
3513c0eae66eSBenny Halevy 			goto out_overflow;
3514cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35151da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
35161da177e4SLinus Torvalds 	}
35173110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
35181da177e4SLinus Torvalds 	return status;
3519c0eae66eSBenny Halevy out_overflow:
3520c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3521c0eae66eSBenny Halevy 	return -EIO;
35221da177e4SLinus Torvalds }
35231da177e4SLinus Torvalds 
35241da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35251da177e4SLinus Torvalds {
35268687b63aSAl Viro 	__be32 *p;
35271da177e4SLinus Torvalds 	int status = 0;
35281da177e4SLinus Torvalds 
35291da177e4SLinus Torvalds 	*res = 0;
35301da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
35311da177e4SLinus Torvalds 		return -EIO;
35321da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3533c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3534c0eae66eSBenny Halevy 		if (unlikely(!p))
3535c0eae66eSBenny Halevy 			goto out_overflow;
3536cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35371da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
35381da177e4SLinus Torvalds 	}
35393110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
35401da177e4SLinus Torvalds 	return status;
3541c0eae66eSBenny Halevy out_overflow:
3542c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3543c0eae66eSBenny Halevy 	return -EIO;
35441da177e4SLinus Torvalds }
35451da177e4SLinus Torvalds 
35461da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35471da177e4SLinus Torvalds {
35488687b63aSAl Viro 	__be32 *p;
35491da177e4SLinus Torvalds 	int status = 0;
35501da177e4SLinus Torvalds 
35511da177e4SLinus Torvalds 	*res = 0;
35521da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
35531da177e4SLinus Torvalds 		return -EIO;
35541da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3555c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3556c0eae66eSBenny Halevy 		if (unlikely(!p))
3557c0eae66eSBenny Halevy 			goto out_overflow;
3558cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35591da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
35601da177e4SLinus Torvalds 	}
35613110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
35621da177e4SLinus Torvalds 	return status;
3563c0eae66eSBenny Halevy out_overflow:
3564c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3565c0eae66eSBenny Halevy 	return -EIO;
35661da177e4SLinus Torvalds }
35671da177e4SLinus Torvalds 
35687aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
35697aaa0b3bSManoj Naik {
3570464ad6b1SChuck Lever 	u32 n;
35718687b63aSAl Viro 	__be32 *p;
35727aaa0b3bSManoj Naik 	int status = 0;
35737aaa0b3bSManoj Naik 
3574c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3575c0eae66eSBenny Halevy 	if (unlikely(!p))
3576c0eae66eSBenny Halevy 		goto out_overflow;
3577cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
357833a43f28SAndy Adamson 	if (n == 0)
357933a43f28SAndy Adamson 		goto root_path;
358002a2976cSChuck Lever 	dprintk("pathname4: ");
35817aaa0b3bSManoj Naik 	path->ncomponents = 0;
35827aaa0b3bSManoj Naik 	while (path->ncomponents < n) {
35837aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
35847aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
35857aaa0b3bSManoj Naik 		if (unlikely(status != 0))
35867aaa0b3bSManoj Naik 			goto out_eio;
358702a2976cSChuck Lever 		if (unlikely(nfs_debug & NFSDBG_XDR))
358802a2976cSChuck Lever 			pr_cont("%s%.*s ",
358902a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
359002a2976cSChuck Lever 				component->len, component->data);
35917aaa0b3bSManoj Naik 		if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
35927aaa0b3bSManoj Naik 			path->ncomponents++;
35937aaa0b3bSManoj Naik 		else {
35947aaa0b3bSManoj Naik 			dprintk("cannot parse %d components in path\n", n);
35957aaa0b3bSManoj Naik 			goto out_eio;
35967aaa0b3bSManoj Naik 		}
35977aaa0b3bSManoj Naik 	}
35987aaa0b3bSManoj Naik out:
35997aaa0b3bSManoj Naik 	return status;
360033a43f28SAndy Adamson root_path:
360133a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
360233a43f28SAndy Adamson 	path->ncomponents = 1;
360333a43f28SAndy Adamson 	path->components[0].len=0;
360433a43f28SAndy Adamson 	path->components[0].data=NULL;
360502a2976cSChuck Lever 	dprintk("pathname4: /\n");
360633a43f28SAndy Adamson 	goto out;
36077aaa0b3bSManoj Naik out_eio:
36087aaa0b3bSManoj Naik 	dprintk(" status %d", status);
36097aaa0b3bSManoj Naik 	status = -EIO;
36107aaa0b3bSManoj Naik 	goto out;
3611c0eae66eSBenny Halevy out_overflow:
3612c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3613c0eae66eSBenny Halevy 	return -EIO;
36147aaa0b3bSManoj Naik }
36157aaa0b3bSManoj Naik 
36167aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3617683b57b4STrond Myklebust {
3618683b57b4STrond Myklebust 	int n;
36198687b63aSAl Viro 	__be32 *p;
3620683b57b4STrond Myklebust 	int status = -EIO;
3621683b57b4STrond Myklebust 
3622683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3623683b57b4STrond Myklebust 		goto out;
3624683b57b4STrond Myklebust 	status = 0;
3625683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3626683b57b4STrond Myklebust 		goto out;
36278b7e3f49STrond Myklebust 	status = -EIO;
36288b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
36298b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
36308b7e3f49STrond Myklebust 		goto out;
363102a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
36327aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3633683b57b4STrond Myklebust 	if (unlikely(status != 0))
3634683b57b4STrond Myklebust 		goto out;
3635c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3636c0eae66eSBenny Halevy 	if (unlikely(!p))
3637c0eae66eSBenny Halevy 		goto out_overflow;
3638cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3639683b57b4STrond Myklebust 	if (n <= 0)
3640683b57b4STrond Myklebust 		goto out_eio;
3641683b57b4STrond Myklebust 	res->nlocations = 0;
3642683b57b4STrond Myklebust 	while (res->nlocations < n) {
3643464ad6b1SChuck Lever 		u32 m;
36447aaa0b3bSManoj Naik 		struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3645683b57b4STrond Myklebust 
3646c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3647c0eae66eSBenny Halevy 		if (unlikely(!p))
3648c0eae66eSBenny Halevy 			goto out_overflow;
3649cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
36507aaa0b3bSManoj Naik 
36517aaa0b3bSManoj Naik 		loc->nservers = 0;
365202a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
36537aaa0b3bSManoj Naik 		while (loc->nservers < m) {
36547aaa0b3bSManoj Naik 			struct nfs4_string *server = &loc->servers[loc->nservers];
36557aaa0b3bSManoj Naik 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3656683b57b4STrond Myklebust 			if (unlikely(status != 0))
3657683b57b4STrond Myklebust 				goto out_eio;
36587aaa0b3bSManoj Naik 			dprintk("%s ", server->data);
36597aaa0b3bSManoj Naik 			if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
36607aaa0b3bSManoj Naik 				loc->nservers++;
36617aaa0b3bSManoj Naik 			else {
3662464ad6b1SChuck Lever 				unsigned int i;
3663464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3664464ad6b1SChuck Lever 					"returned for location %u\n",
36653110ff80SHarvey Harrison 						__func__,
3666464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3667464ad6b1SChuck Lever 						m, res->nlocations);
36687aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
36692e42c3e2STrond Myklebust 					unsigned int len;
36707aaa0b3bSManoj Naik 					char *data;
36717aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3672683b57b4STrond Myklebust 					if (unlikely(status != 0))
3673683b57b4STrond Myklebust 						goto out_eio;
36747aaa0b3bSManoj Naik 				}
36757aaa0b3bSManoj Naik 			}
36767aaa0b3bSManoj Naik 		}
36777aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
36787aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36797aaa0b3bSManoj Naik 			goto out_eio;
36807aaa0b3bSManoj Naik 		if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3681683b57b4STrond Myklebust 			res->nlocations++;
3682683b57b4STrond Myklebust 	}
3683409924e4STrond Myklebust 	if (res->nlocations != 0)
368481934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3685683b57b4STrond Myklebust out:
36863110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3687683b57b4STrond Myklebust 	return status;
3688c0eae66eSBenny Halevy out_overflow:
3689c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3690683b57b4STrond Myklebust out_eio:
3691683b57b4STrond Myklebust 	status = -EIO;
3692683b57b4STrond Myklebust 	goto out;
3693683b57b4STrond Myklebust }
3694683b57b4STrond Myklebust 
36951da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36961da177e4SLinus Torvalds {
36978687b63aSAl Viro 	__be32 *p;
36981da177e4SLinus Torvalds 	int status = 0;
36991da177e4SLinus Torvalds 
37001da177e4SLinus Torvalds 	*res = 0;
37011da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
37021da177e4SLinus Torvalds 		return -EIO;
37031da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3704c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3705c0eae66eSBenny Halevy 		if (unlikely(!p))
3706c0eae66eSBenny Halevy 			goto out_overflow;
3707cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
37081da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
37091da177e4SLinus Torvalds 	}
37103110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
37111da177e4SLinus Torvalds 	return status;
3712c0eae66eSBenny Halevy out_overflow:
3713c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3714c0eae66eSBenny Halevy 	return -EIO;
37151da177e4SLinus Torvalds }
37161da177e4SLinus Torvalds 
37171da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
37181da177e4SLinus Torvalds {
37198687b63aSAl Viro 	__be32 *p;
37201da177e4SLinus Torvalds 	int status = 0;
37211da177e4SLinus Torvalds 
37221da177e4SLinus Torvalds 	*maxlink = 1;
37231da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
37241da177e4SLinus Torvalds 		return -EIO;
37251da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3726c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3727c0eae66eSBenny Halevy 		if (unlikely(!p))
3728c0eae66eSBenny Halevy 			goto out_overflow;
3729cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
37301da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
37311da177e4SLinus Torvalds 	}
37323110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
37331da177e4SLinus Torvalds 	return status;
3734c0eae66eSBenny Halevy out_overflow:
3735c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3736c0eae66eSBenny Halevy 	return -EIO;
37371da177e4SLinus Torvalds }
37381da177e4SLinus Torvalds 
37391da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
37401da177e4SLinus Torvalds {
37418687b63aSAl Viro 	__be32 *p;
37421da177e4SLinus Torvalds 	int status = 0;
37431da177e4SLinus Torvalds 
37441da177e4SLinus Torvalds 	*maxname = 1024;
37451da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
37461da177e4SLinus Torvalds 		return -EIO;
37471da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3748c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3749c0eae66eSBenny Halevy 		if (unlikely(!p))
3750c0eae66eSBenny Halevy 			goto out_overflow;
3751cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
37521da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
37531da177e4SLinus Torvalds 	}
37543110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
37551da177e4SLinus Torvalds 	return status;
3756c0eae66eSBenny Halevy out_overflow:
3757c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3758c0eae66eSBenny Halevy 	return -EIO;
37591da177e4SLinus Torvalds }
37601da177e4SLinus Torvalds 
37611da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37621da177e4SLinus Torvalds {
37638687b63aSAl Viro 	__be32 *p;
37641da177e4SLinus Torvalds 	int status = 0;
37651da177e4SLinus Torvalds 
37661da177e4SLinus Torvalds 	*res = 1024;
37671da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
37681da177e4SLinus Torvalds 		return -EIO;
37691da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
37701da177e4SLinus Torvalds 		uint64_t maxread;
3771c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3772c0eae66eSBenny Halevy 		if (unlikely(!p))
3773c0eae66eSBenny Halevy 			goto out_overflow;
3774cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
37751da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
37761da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
37771da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
37781da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
37791da177e4SLinus Torvalds 	}
37803110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
37811da177e4SLinus Torvalds 	return status;
3782c0eae66eSBenny Halevy out_overflow:
3783c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3784c0eae66eSBenny Halevy 	return -EIO;
37851da177e4SLinus Torvalds }
37861da177e4SLinus Torvalds 
37871da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37881da177e4SLinus Torvalds {
37898687b63aSAl Viro 	__be32 *p;
37901da177e4SLinus Torvalds 	int status = 0;
37911da177e4SLinus Torvalds 
37921da177e4SLinus Torvalds 	*res = 1024;
37931da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
37941da177e4SLinus Torvalds 		return -EIO;
37951da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
37961da177e4SLinus Torvalds 		uint64_t maxwrite;
3797c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3798c0eae66eSBenny Halevy 		if (unlikely(!p))
3799c0eae66eSBenny Halevy 			goto out_overflow;
3800cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
38011da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
38021da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
38031da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
38041da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
38051da177e4SLinus Torvalds 	}
38063110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
38071da177e4SLinus Torvalds 	return status;
3808c0eae66eSBenny Halevy out_overflow:
3809c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3810c0eae66eSBenny Halevy 	return -EIO;
38111da177e4SLinus Torvalds }
38121da177e4SLinus Torvalds 
3813bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
38141da177e4SLinus Torvalds {
3815bca79478STrond Myklebust 	uint32_t tmp;
38168687b63aSAl Viro 	__be32 *p;
3817409924e4STrond Myklebust 	int ret = 0;
38181da177e4SLinus Torvalds 
38191da177e4SLinus Torvalds 	*mode = 0;
38201da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38211da177e4SLinus Torvalds 		return -EIO;
38221da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3823c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3824c0eae66eSBenny Halevy 		if (unlikely(!p))
3825c0eae66eSBenny Halevy 			goto out_overflow;
3826cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3827bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
38281da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3829409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
38301da177e4SLinus Torvalds 	}
38313110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3832409924e4STrond Myklebust 	return ret;
3833c0eae66eSBenny Halevy out_overflow:
3834c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3835c0eae66eSBenny Halevy 	return -EIO;
38361da177e4SLinus Torvalds }
38371da177e4SLinus Torvalds 
38381da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
38391da177e4SLinus Torvalds {
38408687b63aSAl Viro 	__be32 *p;
3841409924e4STrond Myklebust 	int ret = 0;
38421da177e4SLinus Torvalds 
38431da177e4SLinus Torvalds 	*nlink = 1;
38441da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
38451da177e4SLinus Torvalds 		return -EIO;
38461da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3847c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3848c0eae66eSBenny Halevy 		if (unlikely(!p))
3849c0eae66eSBenny Halevy 			goto out_overflow;
3850cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
38511da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3852409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
38531da177e4SLinus Torvalds 	}
38543110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3855409924e4STrond Myklebust 	return ret;
3856c0eae66eSBenny Halevy out_overflow:
3857c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3858c0eae66eSBenny Halevy 	return -EIO;
38591da177e4SLinus Torvalds }
38601da177e4SLinus Torvalds 
386180e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
38626926afd1STrond Myklebust 		const struct nfs_server *server, uint32_t *uid,
38636926afd1STrond Myklebust 		struct nfs4_string *owner_name)
38641da177e4SLinus Torvalds {
38658687b63aSAl Viro 	uint32_t len;
38668687b63aSAl Viro 	__be32 *p;
3867409924e4STrond Myklebust 	int ret = 0;
38681da177e4SLinus Torvalds 
38691da177e4SLinus Torvalds 	*uid = -2;
38701da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
38711da177e4SLinus Torvalds 		return -EIO;
38721da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3873c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3874c0eae66eSBenny Halevy 		if (unlikely(!p))
3875c0eae66eSBenny Halevy 			goto out_overflow;
3876cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3877c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3878c0eae66eSBenny Halevy 		if (unlikely(!p))
3879c0eae66eSBenny Halevy 			goto out_overflow;
38806926afd1STrond Myklebust 		if (owner_name != NULL) {
38816926afd1STrond Myklebust 			owner_name->data = kmemdup(p, len, GFP_NOWAIT);
38826926afd1STrond Myklebust 			if (owner_name->data != NULL) {
38836926afd1STrond Myklebust 				owner_name->len = len;
38846926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER_NAME;
38856926afd1STrond Myklebust 			}
388680e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3887e4fd72a1STrond Myklebust 			if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3888409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER;
3889409924e4STrond Myklebust 			else
38901da177e4SLinus Torvalds 				dprintk("%s: nfs_map_name_to_uid failed!\n",
38913110ff80SHarvey Harrison 						__func__);
38921da177e4SLinus Torvalds 		} else
3893fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
38943110ff80SHarvey Harrison 					__func__, len);
38951da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER;
38961da177e4SLinus Torvalds 	}
38973110ff80SHarvey Harrison 	dprintk("%s: uid=%d\n", __func__, (int)*uid);
3898409924e4STrond Myklebust 	return ret;
3899c0eae66eSBenny Halevy out_overflow:
3900c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3901c0eae66eSBenny Halevy 	return -EIO;
39021da177e4SLinus Torvalds }
39031da177e4SLinus Torvalds 
390480e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
39056926afd1STrond Myklebust 		const struct nfs_server *server, uint32_t *gid,
39066926afd1STrond Myklebust 		struct nfs4_string *group_name)
39071da177e4SLinus Torvalds {
39088687b63aSAl Viro 	uint32_t len;
39098687b63aSAl Viro 	__be32 *p;
3910409924e4STrond Myklebust 	int ret = 0;
39111da177e4SLinus Torvalds 
39121da177e4SLinus Torvalds 	*gid = -2;
39131da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
39141da177e4SLinus Torvalds 		return -EIO;
39151da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3916c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3917c0eae66eSBenny Halevy 		if (unlikely(!p))
3918c0eae66eSBenny Halevy 			goto out_overflow;
3919cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3920c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3921c0eae66eSBenny Halevy 		if (unlikely(!p))
3922c0eae66eSBenny Halevy 			goto out_overflow;
39236926afd1STrond Myklebust 		if (group_name != NULL) {
39246926afd1STrond Myklebust 			group_name->data = kmemdup(p, len, GFP_NOWAIT);
39256926afd1STrond Myklebust 			if (group_name->data != NULL) {
39266926afd1STrond Myklebust 				group_name->len = len;
39276926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP_NAME;
39286926afd1STrond Myklebust 			}
392980e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3930e4fd72a1STrond Myklebust 			if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3931409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP;
3932409924e4STrond Myklebust 			else
39331da177e4SLinus Torvalds 				dprintk("%s: nfs_map_group_to_gid failed!\n",
39343110ff80SHarvey Harrison 						__func__);
39351da177e4SLinus Torvalds 		} else
3936fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
39373110ff80SHarvey Harrison 					__func__, len);
39381da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
39391da177e4SLinus Torvalds 	}
39403110ff80SHarvey Harrison 	dprintk("%s: gid=%d\n", __func__, (int)*gid);
3941409924e4STrond Myklebust 	return ret;
3942c0eae66eSBenny Halevy out_overflow:
3943c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3944c0eae66eSBenny Halevy 	return -EIO;
39451da177e4SLinus Torvalds }
39461da177e4SLinus Torvalds 
39471da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
39481da177e4SLinus Torvalds {
39498687b63aSAl Viro 	uint32_t major = 0, minor = 0;
39508687b63aSAl Viro 	__be32 *p;
3951409924e4STrond Myklebust 	int ret = 0;
39521da177e4SLinus Torvalds 
39531da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
39541da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
39551da177e4SLinus Torvalds 		return -EIO;
39561da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
39571da177e4SLinus Torvalds 		dev_t tmp;
39581da177e4SLinus Torvalds 
3959c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3960c0eae66eSBenny Halevy 		if (unlikely(!p))
3961c0eae66eSBenny Halevy 			goto out_overflow;
39626f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3963cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
39641da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
39651da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
39661da177e4SLinus Torvalds 			*rdev = tmp;
39671da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3968409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
39691da177e4SLinus Torvalds 	}
39703110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3971409924e4STrond Myklebust 	return ret;
3972c0eae66eSBenny Halevy out_overflow:
3973c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3974c0eae66eSBenny Halevy 	return -EIO;
39751da177e4SLinus Torvalds }
39761da177e4SLinus Torvalds 
39771da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39781da177e4SLinus Torvalds {
39798687b63aSAl Viro 	__be32 *p;
39801da177e4SLinus Torvalds 	int status = 0;
39811da177e4SLinus Torvalds 
39821da177e4SLinus Torvalds 	*res = 0;
39831da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
39841da177e4SLinus Torvalds 		return -EIO;
39851da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3986c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3987c0eae66eSBenny Halevy 		if (unlikely(!p))
3988c0eae66eSBenny Halevy 			goto out_overflow;
3989cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39901da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
39911da177e4SLinus Torvalds 	}
39923110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
39931da177e4SLinus Torvalds 	return status;
3994c0eae66eSBenny Halevy out_overflow:
3995c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3996c0eae66eSBenny Halevy 	return -EIO;
39971da177e4SLinus Torvalds }
39981da177e4SLinus Torvalds 
39991da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40001da177e4SLinus Torvalds {
40018687b63aSAl Viro 	__be32 *p;
40021da177e4SLinus Torvalds 	int status = 0;
40031da177e4SLinus Torvalds 
40041da177e4SLinus Torvalds 	*res = 0;
40051da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40061da177e4SLinus Torvalds 		return -EIO;
40071da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4008c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4009c0eae66eSBenny Halevy 		if (unlikely(!p))
4010c0eae66eSBenny Halevy 			goto out_overflow;
4011cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40121da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40131da177e4SLinus Torvalds 	}
40143110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40151da177e4SLinus Torvalds 	return status;
4016c0eae66eSBenny Halevy out_overflow:
4017c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4018c0eae66eSBenny Halevy 	return -EIO;
40191da177e4SLinus Torvalds }
40201da177e4SLinus Torvalds 
40211da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40221da177e4SLinus Torvalds {
40238687b63aSAl Viro 	__be32 *p;
40241da177e4SLinus Torvalds 	int status = 0;
40251da177e4SLinus Torvalds 
40261da177e4SLinus Torvalds 	*res = 0;
40271da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
40281da177e4SLinus Torvalds 		return -EIO;
40291da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4030c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4031c0eae66eSBenny Halevy 		if (unlikely(!p))
4032c0eae66eSBenny Halevy 			goto out_overflow;
4033cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40341da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
40351da177e4SLinus Torvalds 	}
40363110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
40371da177e4SLinus Torvalds 	return status;
4038c0eae66eSBenny Halevy out_overflow:
4039c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4040c0eae66eSBenny Halevy 	return -EIO;
40411da177e4SLinus Torvalds }
40421da177e4SLinus Torvalds 
40431da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
40441da177e4SLinus Torvalds {
40458687b63aSAl Viro 	__be32 *p;
4046409924e4STrond Myklebust 	int ret = 0;
40471da177e4SLinus Torvalds 
40481da177e4SLinus Torvalds 	*used = 0;
40491da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
40501da177e4SLinus Torvalds 		return -EIO;
40511da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4052c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4053c0eae66eSBenny Halevy 		if (unlikely(!p))
4054c0eae66eSBenny Halevy 			goto out_overflow;
4055cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
40561da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4057409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
40581da177e4SLinus Torvalds 	}
40593110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
40601da177e4SLinus Torvalds 			(unsigned long long)*used);
4061409924e4STrond Myklebust 	return ret;
4062c0eae66eSBenny Halevy out_overflow:
4063c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4064c0eae66eSBenny Halevy 	return -EIO;
40651da177e4SLinus Torvalds }
40661da177e4SLinus Torvalds 
40671da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
40681da177e4SLinus Torvalds {
40698687b63aSAl Viro 	__be32 *p;
40701da177e4SLinus Torvalds 	uint64_t sec;
40711da177e4SLinus Torvalds 	uint32_t nsec;
40721da177e4SLinus Torvalds 
4073c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4074c0eae66eSBenny Halevy 	if (unlikely(!p))
4075c0eae66eSBenny Halevy 		goto out_overflow;
40763ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &sec);
4077cccddf4fSBenny Halevy 	nsec = be32_to_cpup(p);
40781da177e4SLinus Torvalds 	time->tv_sec = (time_t)sec;
40791da177e4SLinus Torvalds 	time->tv_nsec = (long)nsec;
40801da177e4SLinus Torvalds 	return 0;
4081c0eae66eSBenny Halevy out_overflow:
4082c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4083c0eae66eSBenny Halevy 	return -EIO;
40841da177e4SLinus Torvalds }
40851da177e4SLinus Torvalds 
40861da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40871da177e4SLinus Torvalds {
40881da177e4SLinus Torvalds 	int status = 0;
40891da177e4SLinus Torvalds 
40901da177e4SLinus Torvalds 	time->tv_sec = 0;
40911da177e4SLinus Torvalds 	time->tv_nsec = 0;
40921da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
40931da177e4SLinus Torvalds 		return -EIO;
40941da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
40951da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4096409924e4STrond Myklebust 		if (status == 0)
4097409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
40981da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
40991da177e4SLinus Torvalds 	}
41003110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
41011da177e4SLinus Torvalds 	return status;
41021da177e4SLinus Torvalds }
41031da177e4SLinus Torvalds 
41041da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41051da177e4SLinus Torvalds {
41061da177e4SLinus Torvalds 	int status = 0;
41071da177e4SLinus Torvalds 
41081da177e4SLinus Torvalds 	time->tv_sec = 0;
41091da177e4SLinus Torvalds 	time->tv_nsec = 0;
41101da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41111da177e4SLinus Torvalds 		return -EIO;
41121da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41131da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4114409924e4STrond Myklebust 		if (status == 0)
4115409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
41161da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41171da177e4SLinus Torvalds 	}
41183110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
41191da177e4SLinus Torvalds 	return status;
41201da177e4SLinus Torvalds }
41211da177e4SLinus Torvalds 
412255b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
412355b6e774SRicardo Labiaga 				  struct timespec *time)
412455b6e774SRicardo Labiaga {
412555b6e774SRicardo Labiaga 	int status = 0;
412655b6e774SRicardo Labiaga 
412755b6e774SRicardo Labiaga 	time->tv_sec = 0;
412855b6e774SRicardo Labiaga 	time->tv_nsec = 0;
412955b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
413055b6e774SRicardo Labiaga 		return -EIO;
413155b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
413255b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
413355b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
413455b6e774SRicardo Labiaga 	}
413555b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
413655b6e774SRicardo Labiaga 		(long)time->tv_nsec);
413755b6e774SRicardo Labiaga 	return status;
413855b6e774SRicardo Labiaga }
413955b6e774SRicardo Labiaga 
41401da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41411da177e4SLinus Torvalds {
41421da177e4SLinus Torvalds 	int status = 0;
41431da177e4SLinus Torvalds 
41441da177e4SLinus Torvalds 	time->tv_sec = 0;
41451da177e4SLinus Torvalds 	time->tv_nsec = 0;
41461da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
41471da177e4SLinus Torvalds 		return -EIO;
41481da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
41491da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4150409924e4STrond Myklebust 		if (status == 0)
4151409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
41521da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
41531da177e4SLinus Torvalds 	}
41543110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
41551da177e4SLinus Torvalds 	return status;
41561da177e4SLinus Torvalds }
41571da177e4SLinus Torvalds 
41588687b63aSAl Viro static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
41591da177e4SLinus Torvalds {
41601da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
41611da177e4SLinus Torvalds 	unsigned int nwords = xdr->p - savep;
41621da177e4SLinus Torvalds 
41631da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4164fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4165fe82a183SChuck Lever 			"%u %c %u\n",
41663110ff80SHarvey Harrison 				__func__,
41671da177e4SLinus Torvalds 				attrwords << 2,
41681da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
41691da177e4SLinus Torvalds 				nwords << 2);
41701da177e4SLinus Torvalds 		return -EIO;
41711da177e4SLinus Torvalds 	}
41721da177e4SLinus Torvalds 	return 0;
41731da177e4SLinus Torvalds }
41741da177e4SLinus Torvalds 
41751da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
41761da177e4SLinus Torvalds {
41778687b63aSAl Viro 	__be32 *p;
41781da177e4SLinus Torvalds 
4179c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4180c0eae66eSBenny Halevy 	if (unlikely(!p))
4181c0eae66eSBenny Halevy 		goto out_overflow;
41826f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
41833ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4184cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
41851da177e4SLinus Torvalds 	return 0;
4186c0eae66eSBenny Halevy out_overflow:
4187c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4188c0eae66eSBenny Halevy 	return -EIO;
41891da177e4SLinus Torvalds }
41901da177e4SLinus Torvalds 
41911da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
41921da177e4SLinus Torvalds {
41938687b63aSAl Viro 	__be32 *p;
41941da177e4SLinus Torvalds 	uint32_t supp, acc;
41951da177e4SLinus Torvalds 	int status;
41961da177e4SLinus Torvalds 
41971da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
41981da177e4SLinus Torvalds 	if (status)
41991da177e4SLinus Torvalds 		return status;
4200c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4201c0eae66eSBenny Halevy 	if (unlikely(!p))
4202c0eae66eSBenny Halevy 		goto out_overflow;
42036f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4204cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
42051da177e4SLinus Torvalds 	access->supported = supp;
42061da177e4SLinus Torvalds 	access->access = acc;
42071da177e4SLinus Torvalds 	return 0;
4208c0eae66eSBenny Halevy out_overflow:
4209c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4210c0eae66eSBenny Halevy 	return -EIO;
42111da177e4SLinus Torvalds }
42121da177e4SLinus Torvalds 
421307d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
42141da177e4SLinus Torvalds {
42158687b63aSAl Viro 	__be32 *p;
421607d30434SBenny Halevy 
421707d30434SBenny Halevy 	p = xdr_inline_decode(xdr, len);
421807d30434SBenny Halevy 	if (likely(p)) {
421907d30434SBenny Halevy 		memcpy(buf, p, len);
422007d30434SBenny Halevy 		return 0;
422107d30434SBenny Halevy 	}
422207d30434SBenny Halevy 	print_overflow_msg(__func__, xdr);
422307d30434SBenny Halevy 	return -EIO;
422407d30434SBenny Halevy }
422507d30434SBenny Halevy 
422607d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
422707d30434SBenny Halevy {
422807d30434SBenny Halevy 	return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
42291da177e4SLinus Torvalds }
42301da177e4SLinus Torvalds 
42311da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
42321da177e4SLinus Torvalds {
42331da177e4SLinus Torvalds 	int status;
42341da177e4SLinus Torvalds 
42351da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4236c1d51931STrond Myklebust 	if (status != -EIO)
4237c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
423807d30434SBenny Halevy 	if (!status)
423907d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
42401da177e4SLinus Torvalds 	return status;
42411da177e4SLinus Torvalds }
42421da177e4SLinus Torvalds 
4243db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4244db942bbdSBenny Halevy {
4245db942bbdSBenny Halevy 	return decode_opaque_fixed(xdr, verifier, 8);
42461da177e4SLinus Torvalds }
42471da177e4SLinus Torvalds 
42481da177e4SLinus Torvalds static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
42491da177e4SLinus Torvalds {
42501da177e4SLinus Torvalds 	int status;
42511da177e4SLinus Torvalds 
42521da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4253db942bbdSBenny Halevy 	if (!status)
4254db942bbdSBenny Halevy 		status = decode_verifier(xdr, res->verf->verifier);
42551da177e4SLinus Torvalds 	return status;
42561da177e4SLinus Torvalds }
42571da177e4SLinus Torvalds 
42581da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
42591da177e4SLinus Torvalds {
42608687b63aSAl Viro 	__be32 *p;
42611da177e4SLinus Torvalds 	uint32_t bmlen;
42621da177e4SLinus Torvalds 	int status;
42631da177e4SLinus Torvalds 
42641da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
42651da177e4SLinus Torvalds 	if (status)
42661da177e4SLinus Torvalds 		return status;
42671da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
42681da177e4SLinus Torvalds 		return status;
4269c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4270c0eae66eSBenny Halevy 	if (unlikely(!p))
4271c0eae66eSBenny Halevy 		goto out_overflow;
4272cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4273c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4274c0eae66eSBenny Halevy 	if (likely(p))
42751da177e4SLinus Torvalds 		return 0;
4276c0eae66eSBenny Halevy out_overflow:
4277c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4278c0eae66eSBenny Halevy 	return -EIO;
42791da177e4SLinus Torvalds }
42801da177e4SLinus Torvalds 
42811da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
42821da177e4SLinus Torvalds {
42838687b63aSAl Viro 	__be32 *savep;
4284dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
42851da177e4SLinus Torvalds 	int status;
42861da177e4SLinus Torvalds 
42871da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
42881da177e4SLinus Torvalds 		goto xdr_error;
42891da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
42901da177e4SLinus Torvalds 		goto xdr_error;
42911da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
42921da177e4SLinus Torvalds 		goto xdr_error;
42931da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
42941da177e4SLinus Torvalds 		goto xdr_error;
4295264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4296264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4297264e6351SChuck Lever 		goto xdr_error;
42981da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
42991da177e4SLinus Torvalds 		goto xdr_error;
43001da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
43011da177e4SLinus Torvalds 		goto xdr_error;
43021da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
43031da177e4SLinus Torvalds 		goto xdr_error;
43041da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43051da177e4SLinus Torvalds xdr_error:
43063110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43071da177e4SLinus Torvalds 	return status;
43081da177e4SLinus Torvalds }
43091da177e4SLinus Torvalds 
43101da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
43111da177e4SLinus Torvalds {
43128687b63aSAl Viro 	__be32 *savep;
4313dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43141da177e4SLinus Torvalds 	int status;
43151da177e4SLinus Torvalds 
43161da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43171da177e4SLinus Torvalds 		goto xdr_error;
43181da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43191da177e4SLinus Torvalds 		goto xdr_error;
43201da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43211da177e4SLinus Torvalds 		goto xdr_error;
43221da177e4SLinus Torvalds 
43231da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
43241da177e4SLinus Torvalds 		goto xdr_error;
43251da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
43261da177e4SLinus Torvalds 		goto xdr_error;
43271da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
43281da177e4SLinus Torvalds 		goto xdr_error;
43291da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
43301da177e4SLinus Torvalds 		goto xdr_error;
43311da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
43321da177e4SLinus Torvalds 		goto xdr_error;
43331da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
43341da177e4SLinus Torvalds 		goto xdr_error;
43351da177e4SLinus Torvalds 
43361da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43371da177e4SLinus Torvalds xdr_error:
43383110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43391da177e4SLinus Torvalds 	return status;
43401da177e4SLinus Torvalds }
43411da177e4SLinus Torvalds 
43421da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
43431da177e4SLinus Torvalds {
43448687b63aSAl Viro 	__be32 *savep;
4345dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43461da177e4SLinus Torvalds 	int status;
43471da177e4SLinus Torvalds 
43481da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43491da177e4SLinus Torvalds 		goto xdr_error;
43501da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43511da177e4SLinus Torvalds 		goto xdr_error;
43521da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43531da177e4SLinus Torvalds 		goto xdr_error;
43541da177e4SLinus Torvalds 
43551da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
43561da177e4SLinus Torvalds 		goto xdr_error;
43571da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
43581da177e4SLinus Torvalds 		goto xdr_error;
43591da177e4SLinus Torvalds 
43601da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43611da177e4SLinus Torvalds xdr_error:
43623110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43631da177e4SLinus Torvalds 	return status;
43641da177e4SLinus Torvalds }
43651da177e4SLinus Torvalds 
4366ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4367ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
43688b7e3f49STrond Myklebust 		struct nfs4_fs_locations *fs_loc,
43696926afd1STrond Myklebust 		const struct nfs_server *server)
43701da177e4SLinus Torvalds {
4371bca79478STrond Myklebust 	int status;
4372bca79478STrond Myklebust 	umode_t fmode = 0;
4373ae42c70aSBryan Schumaker 	uint32_t type;
4374ee7b75fcSTrond Myklebust 	int32_t err;
43751da177e4SLinus Torvalds 
4376f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4377f26c7a78STrond Myklebust 	if (status < 0)
43781da177e4SLinus Torvalds 		goto xdr_error;
4379409924e4STrond Myklebust 	fattr->mode = 0;
4380409924e4STrond Myklebust 	if (status != 0) {
4381409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4382409924e4STrond Myklebust 		fattr->valid |= status;
4383409924e4STrond Myklebust 	}
43841da177e4SLinus Torvalds 
4385f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4386f26c7a78STrond Myklebust 	if (status < 0)
43871da177e4SLinus Torvalds 		goto xdr_error;
4388409924e4STrond Myklebust 	fattr->valid |= status;
4389f26c7a78STrond Myklebust 
4390f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4391f26c7a78STrond Myklebust 	if (status < 0)
43921da177e4SLinus Torvalds 		goto xdr_error;
4393409924e4STrond Myklebust 	fattr->valid |= status;
4394f26c7a78STrond Myklebust 
4395f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4396f26c7a78STrond Myklebust 	if (status < 0)
43971da177e4SLinus Torvalds 		goto xdr_error;
4398409924e4STrond Myklebust 	fattr->valid |= status;
4399f26c7a78STrond Myklebust 
4400ee7b75fcSTrond Myklebust 	err = 0;
4401ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4402ae42c70aSBryan Schumaker 	if (status < 0)
4403ae42c70aSBryan Schumaker 		goto xdr_error;
4404ee7b75fcSTrond Myklebust 	if (err == -NFS4ERR_WRONGSEC)
4405ee7b75fcSTrond Myklebust 		nfs_fixup_secinfo_attributes(fattr, fh);
4406ae42c70aSBryan Schumaker 
4407ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4408ae42c70aSBryan Schumaker 	if (status < 0)
4409ae42c70aSBryan Schumaker 		goto xdr_error;
4410ae42c70aSBryan Schumaker 
4411f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4412f26c7a78STrond Myklebust 	if (status < 0)
44131da177e4SLinus Torvalds 		goto xdr_error;
4414409924e4STrond Myklebust 	fattr->valid |= status;
4415f26c7a78STrond Myklebust 
44168b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4417f26c7a78STrond Myklebust 	if (status < 0)
4418683b57b4STrond Myklebust 		goto xdr_error;
4419409924e4STrond Myklebust 	fattr->valid |= status;
4420f26c7a78STrond Myklebust 
4421f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4422f26c7a78STrond Myklebust 	if (status < 0)
44231da177e4SLinus Torvalds 		goto xdr_error;
4424409924e4STrond Myklebust 	if (status != 0) {
44251da177e4SLinus Torvalds 		fattr->mode |= fmode;
4426409924e4STrond Myklebust 		fattr->valid |= status;
4427409924e4STrond Myklebust 	}
4428f26c7a78STrond Myklebust 
4429f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4430f26c7a78STrond Myklebust 	if (status < 0)
44311da177e4SLinus Torvalds 		goto xdr_error;
4432409924e4STrond Myklebust 	fattr->valid |= status;
4433f26c7a78STrond Myklebust 
44346926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4435f26c7a78STrond Myklebust 	if (status < 0)
44361da177e4SLinus Torvalds 		goto xdr_error;
4437409924e4STrond Myklebust 	fattr->valid |= status;
4438f26c7a78STrond Myklebust 
44396926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4440f26c7a78STrond Myklebust 	if (status < 0)
44411da177e4SLinus Torvalds 		goto xdr_error;
4442409924e4STrond Myklebust 	fattr->valid |= status;
4443f26c7a78STrond Myklebust 
4444f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4445f26c7a78STrond Myklebust 	if (status < 0)
44461da177e4SLinus Torvalds 		goto xdr_error;
4447409924e4STrond Myklebust 	fattr->valid |= status;
4448f26c7a78STrond Myklebust 
4449f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4450f26c7a78STrond Myklebust 	if (status < 0)
44511da177e4SLinus Torvalds 		goto xdr_error;
4452409924e4STrond Myklebust 	fattr->valid |= status;
4453f26c7a78STrond Myklebust 
4454f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4455f26c7a78STrond Myklebust 	if (status < 0)
44561da177e4SLinus Torvalds 		goto xdr_error;
4457409924e4STrond Myklebust 	fattr->valid |= status;
4458f26c7a78STrond Myklebust 
4459f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4460f26c7a78STrond Myklebust 	if (status < 0)
44611da177e4SLinus Torvalds 		goto xdr_error;
4462409924e4STrond Myklebust 	fattr->valid |= status;
4463f26c7a78STrond Myklebust 
4464f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4465f26c7a78STrond Myklebust 	if (status < 0)
44661da177e4SLinus Torvalds 		goto xdr_error;
4467409924e4STrond Myklebust 	fattr->valid |= status;
4468f26c7a78STrond Myklebust 
446928331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4470f26c7a78STrond Myklebust 	if (status < 0)
447199baf625SManoj Naik 		goto xdr_error;
4472409924e4STrond Myklebust 	fattr->valid |= status;
4473f26c7a78STrond Myklebust 
4474ae42c70aSBryan Schumaker xdr_error:
4475ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4476ae42c70aSBryan Schumaker 	return status;
4477ae42c70aSBryan Schumaker }
4478ae42c70aSBryan Schumaker 
4479ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
44808b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
44818b7e3f49STrond Myklebust 		const struct nfs_server *server)
4482ae42c70aSBryan Schumaker {
4483ae42c70aSBryan Schumaker 	__be32 *savep;
4484ae42c70aSBryan Schumaker 	uint32_t attrlen,
4485dae100c2SFred Isaman 		 bitmap[3] = {0};
4486ae42c70aSBryan Schumaker 	int status;
4487ae42c70aSBryan Schumaker 
4488ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4489ae42c70aSBryan Schumaker 	if (status < 0)
4490ae42c70aSBryan Schumaker 		goto xdr_error;
4491ae42c70aSBryan Schumaker 
4492ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4493ae42c70aSBryan Schumaker 	if (status < 0)
4494ae42c70aSBryan Schumaker 		goto xdr_error;
4495ae42c70aSBryan Schumaker 
4496ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4497ae42c70aSBryan Schumaker 	if (status < 0)
4498ae42c70aSBryan Schumaker 		goto xdr_error;
4499ae42c70aSBryan Schumaker 
45008b7e3f49STrond Myklebust 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4501ae42c70aSBryan Schumaker 	if (status < 0)
4502ae42c70aSBryan Schumaker 		goto xdr_error;
4503ae42c70aSBryan Schumaker 
4504f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
45051da177e4SLinus Torvalds xdr_error:
45063110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
45071da177e4SLinus Torvalds 	return status;
45081da177e4SLinus Torvalds }
45091da177e4SLinus Torvalds 
4510ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
45116926afd1STrond Myklebust 		const struct nfs_server *server)
4512ae42c70aSBryan Schumaker {
45138b7e3f49STrond Myklebust 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4514ae42c70aSBryan Schumaker }
45151da177e4SLinus Torvalds 
4516504913fbSAndy Adamson /*
4517504913fbSAndy Adamson  * Decode potentially multiple layout types. Currently we only support
4518504913fbSAndy Adamson  * one layout driver per file system.
4519504913fbSAndy Adamson  */
4520504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4521504913fbSAndy Adamson 					 uint32_t *layouttype)
4522504913fbSAndy Adamson {
4523504913fbSAndy Adamson 	uint32_t *p;
4524504913fbSAndy Adamson 	int num;
4525504913fbSAndy Adamson 
4526504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4527504913fbSAndy Adamson 	if (unlikely(!p))
4528504913fbSAndy Adamson 		goto out_overflow;
4529504913fbSAndy Adamson 	num = be32_to_cpup(p);
4530504913fbSAndy Adamson 
4531504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4532504913fbSAndy Adamson 	if (num == 0) {
4533504913fbSAndy Adamson 		*layouttype = 0;
4534504913fbSAndy Adamson 		return 0;
4535504913fbSAndy Adamson 	}
4536504913fbSAndy Adamson 	if (num > 1)
4537a030889aSWeston Andros Adamson 		printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4538a030889aSWeston Andros Adamson 			"drivers per filesystem not supported\n", __func__);
4539504913fbSAndy Adamson 
4540504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4541504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, num * 4);
4542504913fbSAndy Adamson 	if (unlikely(!p))
4543504913fbSAndy Adamson 		goto out_overflow;
4544504913fbSAndy Adamson 	*layouttype = be32_to_cpup(p);
4545504913fbSAndy Adamson 	return 0;
4546504913fbSAndy Adamson out_overflow:
4547504913fbSAndy Adamson 	print_overflow_msg(__func__, xdr);
4548504913fbSAndy Adamson 	return -EIO;
4549504913fbSAndy Adamson }
4550504913fbSAndy Adamson 
4551504913fbSAndy Adamson /*
4552504913fbSAndy Adamson  * The type of file system exported.
4553504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4554504913fbSAndy Adamson  */
4555504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4556504913fbSAndy Adamson 				uint32_t *layouttype)
4557504913fbSAndy Adamson {
4558504913fbSAndy Adamson 	int status = 0;
4559504913fbSAndy Adamson 
4560504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4561504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4562504913fbSAndy Adamson 		return -EIO;
4563504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4564504913fbSAndy Adamson 		status = decode_first_pnfs_layout_type(xdr, layouttype);
4565504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4566504913fbSAndy Adamson 	} else
4567504913fbSAndy Adamson 		*layouttype = 0;
4568504913fbSAndy Adamson 	return status;
4569504913fbSAndy Adamson }
4570504913fbSAndy Adamson 
4571dae100c2SFred Isaman /*
4572dae100c2SFred Isaman  * The prefered block size for layout directed io
4573dae100c2SFred Isaman  */
4574dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4575dae100c2SFred Isaman 				      uint32_t *res)
4576dae100c2SFred Isaman {
4577dae100c2SFred Isaman 	__be32 *p;
4578dae100c2SFred Isaman 
4579dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4580dae100c2SFred Isaman 	*res = 0;
4581dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4582dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4583dae100c2SFred Isaman 		if (unlikely(!p)) {
4584dae100c2SFred Isaman 			print_overflow_msg(__func__, xdr);
4585dae100c2SFred Isaman 			return -EIO;
4586dae100c2SFred Isaman 		}
4587dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4588dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4589dae100c2SFred Isaman 	}
4590dae100c2SFred Isaman 	return 0;
4591dae100c2SFred Isaman }
4592dae100c2SFred Isaman 
45931da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
45941da177e4SLinus Torvalds {
45958687b63aSAl Viro 	__be32 *savep;
4596dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
45971da177e4SLinus Torvalds 	int status;
45981da177e4SLinus Torvalds 
45991da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
46001da177e4SLinus Torvalds 		goto xdr_error;
46011da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
46021da177e4SLinus Torvalds 		goto xdr_error;
46031da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
46041da177e4SLinus Torvalds 		goto xdr_error;
46051da177e4SLinus Torvalds 
46061da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
46071da177e4SLinus Torvalds 
46081da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
46091da177e4SLinus Torvalds 		goto xdr_error;
46101da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
46111da177e4SLinus Torvalds 		goto xdr_error;
46121da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
46131da177e4SLinus Torvalds 		goto xdr_error;
46141da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
46151da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
46161da177e4SLinus Torvalds 		goto xdr_error;
46171da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
461855b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
461955b6e774SRicardo Labiaga 	if (status != 0)
462055b6e774SRicardo Labiaga 		goto xdr_error;
4621504913fbSAndy Adamson 	status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4622504913fbSAndy Adamson 	if (status != 0)
4623504913fbSAndy Adamson 		goto xdr_error;
4624dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4625dae100c2SFred Isaman 	if (status)
4626dae100c2SFred Isaman 		goto xdr_error;
46271da177e4SLinus Torvalds 
46281da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
46291da177e4SLinus Torvalds xdr_error:
46303110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
46311da177e4SLinus Torvalds 	return status;
46321da177e4SLinus Torvalds }
46331da177e4SLinus Torvalds 
46341da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
46351da177e4SLinus Torvalds {
46368687b63aSAl Viro 	__be32 *p;
46371da177e4SLinus Torvalds 	uint32_t len;
46381da177e4SLinus Torvalds 	int status;
46391da177e4SLinus Torvalds 
46409936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
46419936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
46429936781dSTrond Myklebust 
46431da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
46441da177e4SLinus Torvalds 	if (status)
46451da177e4SLinus Torvalds 		return status;
46461da177e4SLinus Torvalds 
4647c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4648c0eae66eSBenny Halevy 	if (unlikely(!p))
4649c0eae66eSBenny Halevy 		goto out_overflow;
4650cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
46511da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
46521da177e4SLinus Torvalds 		return -EIO;
46531da177e4SLinus Torvalds 	fh->size = len;
4654c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4655c0eae66eSBenny Halevy 	if (unlikely(!p))
4656c0eae66eSBenny Halevy 		goto out_overflow;
465799398d06SBenny Halevy 	memcpy(fh->data, p, len);
46581da177e4SLinus Torvalds 	return 0;
4659c0eae66eSBenny Halevy out_overflow:
4660c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4661c0eae66eSBenny Halevy 	return -EIO;
46621da177e4SLinus Torvalds }
46631da177e4SLinus Torvalds 
46641da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
46651da177e4SLinus Torvalds {
46661da177e4SLinus Torvalds 	int status;
46671da177e4SLinus Torvalds 
46681da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
46691da177e4SLinus Torvalds 	if (status)
46701da177e4SLinus Torvalds 		return status;
46711da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
46721da177e4SLinus Torvalds }
46731da177e4SLinus Torvalds 
46741da177e4SLinus Torvalds /*
46751da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
46761da177e4SLinus Torvalds  */
4677911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
46781da177e4SLinus Torvalds {
4679911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
46808687b63aSAl Viro 	__be32 *p;
4681911d1aafSTrond Myklebust 	uint32_t namelen, type;
46821da177e4SLinus Torvalds 
4683babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4684c0eae66eSBenny Halevy 	if (unlikely(!p))
4685c0eae66eSBenny Halevy 		goto out_overflow;
4686babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
46873ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4688babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4689babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4690911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4691911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4692911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4693911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4694911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4695911d1aafSTrond Myklebust 		if (type & 1)
4696911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4697911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4698911d1aafSTrond Myklebust 	}
4699babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4700babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4701babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4702c0eae66eSBenny Halevy 	if (likely(p))
47031da177e4SLinus Torvalds 		return -NFS4ERR_DENIED;
4704c0eae66eSBenny Halevy out_overflow:
4705c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4706c0eae66eSBenny Halevy 	return -EIO;
47071da177e4SLinus Torvalds }
47081da177e4SLinus Torvalds 
4709911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
47101da177e4SLinus Torvalds {
47111da177e4SLinus Torvalds 	int status;
47121da177e4SLinus Torvalds 
47131da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4714c1d51931STrond Myklebust 	if (status == -EIO)
4715c1d51931STrond Myklebust 		goto out;
47161da177e4SLinus Torvalds 	if (status == 0) {
471707d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
471807d30434SBenny Halevy 		if (unlikely(status))
471907d30434SBenny Halevy 			goto out;
47201da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4721c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4722c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4723c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4724c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4725c1d51931STrond Myklebust out:
47261da177e4SLinus Torvalds 	return status;
47271da177e4SLinus Torvalds }
47281da177e4SLinus Torvalds 
4729911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
47301da177e4SLinus Torvalds {
47311da177e4SLinus Torvalds 	int status;
47321da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
47331da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4734911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
47351da177e4SLinus Torvalds 	return status;
47361da177e4SLinus Torvalds }
47371da177e4SLinus Torvalds 
4738911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
47391da177e4SLinus Torvalds {
47401da177e4SLinus Torvalds 	int status;
47411da177e4SLinus Torvalds 
47421da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4743c1d51931STrond Myklebust 	if (status != -EIO)
4744c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
474507d30434SBenny Halevy 	if (status == 0)
474607d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
47471da177e4SLinus Torvalds 	return status;
47481da177e4SLinus Torvalds }
47491da177e4SLinus Torvalds 
4750d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
4751d3c7b7ccSTrond Myklebust {
4752d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4753d3c7b7ccSTrond Myklebust }
4754d3c7b7ccSTrond Myklebust 
47551da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
47561da177e4SLinus Torvalds {
47571da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
47581da177e4SLinus Torvalds }
47591da177e4SLinus Torvalds 
47601da177e4SLinus Torvalds /* This is too sick! */
47611da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
47621da177e4SLinus Torvalds {
47638687b63aSAl Viro 	__be32 *p;
47641da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
47651da177e4SLinus Torvalds 
4766c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4767c0eae66eSBenny Halevy 	if (unlikely(!p))
4768c0eae66eSBenny Halevy 		goto out_overflow;
47696f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
47701da177e4SLinus Torvalds 	switch (limit_type) {
47711da177e4SLinus Torvalds 	case 1:
4772cccddf4fSBenny Halevy 		xdr_decode_hyper(p, maxsize);
47731da177e4SLinus Torvalds 		break;
47741da177e4SLinus Torvalds 	case 2:
47756f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
4776cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
47771da177e4SLinus Torvalds 		*maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
47781da177e4SLinus Torvalds 	}
47791da177e4SLinus Torvalds 	return 0;
4780c0eae66eSBenny Halevy out_overflow:
4781c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4782c0eae66eSBenny Halevy 	return -EIO;
47831da177e4SLinus Torvalds }
47841da177e4SLinus Torvalds 
47851da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
47861da177e4SLinus Torvalds {
47878687b63aSAl Viro 	__be32 *p;
47881da177e4SLinus Torvalds 	uint32_t delegation_type;
478907d30434SBenny Halevy 	int status;
47901da177e4SLinus Torvalds 
4791c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4792c0eae66eSBenny Halevy 	if (unlikely(!p))
4793c0eae66eSBenny Halevy 		goto out_overflow;
4794cccddf4fSBenny Halevy 	delegation_type = be32_to_cpup(p);
47951da177e4SLinus Torvalds 	if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
47961da177e4SLinus Torvalds 		res->delegation_type = 0;
47971da177e4SLinus Torvalds 		return 0;
47981da177e4SLinus Torvalds 	}
479907d30434SBenny Halevy 	status = decode_stateid(xdr, &res->delegation);
480007d30434SBenny Halevy 	if (unlikely(status))
480107d30434SBenny Halevy 		return status;
4802c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4803c0eae66eSBenny Halevy 	if (unlikely(!p))
4804c0eae66eSBenny Halevy 		goto out_overflow;
4805cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
480605d564feSAndy Adamson 
48071da177e4SLinus Torvalds 	switch (delegation_type) {
48081da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
48091da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
48101da177e4SLinus Torvalds 		break;
48111da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
48121da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
48131da177e4SLinus Torvalds 		if (decode_space_limit(xdr, &res->maxsize) < 0)
48141da177e4SLinus Torvalds 				return -EIO;
48151da177e4SLinus Torvalds 	}
48167539bbabSDavid Howells 	return decode_ace(xdr, NULL, res->server->nfs_client);
4817c0eae66eSBenny Halevy out_overflow:
4818c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4819c0eae66eSBenny Halevy 	return -EIO;
48201da177e4SLinus Torvalds }
48211da177e4SLinus Torvalds 
48221da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
48231da177e4SLinus Torvalds {
48248687b63aSAl Viro 	__be32 *p;
4825aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
48261da177e4SLinus Torvalds 	int status;
48271da177e4SLinus Torvalds 
48281da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN);
4829c1d51931STrond Myklebust 	if (status != -EIO)
4830c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
483107d30434SBenny Halevy 	if (!status)
483207d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
483307d30434SBenny Halevy 	if (unlikely(status))
48341da177e4SLinus Torvalds 		return status;
48351da177e4SLinus Torvalds 
48361da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
48371da177e4SLinus Torvalds 
4838c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4839c0eae66eSBenny Halevy 	if (unlikely(!p))
4840c0eae66eSBenny Halevy 		goto out_overflow;
48416f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
4842cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
48431da177e4SLinus Torvalds 	if (bmlen > 10)
48441da177e4SLinus Torvalds 		goto xdr_error;
48451da177e4SLinus Torvalds 
4846c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4847c0eae66eSBenny Halevy 	if (unlikely(!p))
4848c0eae66eSBenny Halevy 		goto out_overflow;
4849aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4850aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
48516f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
4852aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
4853aa53ed54SJeff Layton 		res->attrset[i] = 0;
4854aa53ed54SJeff Layton 
48551da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
48561da177e4SLinus Torvalds xdr_error:
48573110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
48581da177e4SLinus Torvalds 	return -EIO;
4859c0eae66eSBenny Halevy out_overflow:
4860c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4861c0eae66eSBenny Halevy 	return -EIO;
48621da177e4SLinus Torvalds }
48631da177e4SLinus Torvalds 
48641da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
48651da177e4SLinus Torvalds {
48661da177e4SLinus Torvalds 	int status;
48671da177e4SLinus Torvalds 
48681da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4869c1d51931STrond Myklebust 	if (status != -EIO)
4870c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
487107d30434SBenny Halevy 	if (!status)
487207d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
48731da177e4SLinus Torvalds 	return status;
48741da177e4SLinus Torvalds }
48751da177e4SLinus Torvalds 
48761da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
48771da177e4SLinus Torvalds {
48781da177e4SLinus Torvalds 	int status;
48791da177e4SLinus Torvalds 
48801da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4881c1d51931STrond Myklebust 	if (status != -EIO)
4882c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
488307d30434SBenny Halevy 	if (!status)
488407d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
48851da177e4SLinus Torvalds 	return status;
48861da177e4SLinus Torvalds }
48871da177e4SLinus Torvalds 
48881da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
48891da177e4SLinus Torvalds {
48901da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
48911da177e4SLinus Torvalds }
48921da177e4SLinus Torvalds 
48931da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
48941da177e4SLinus Torvalds {
48951da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
48961da177e4SLinus Torvalds }
48971da177e4SLinus Torvalds 
48981da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
48991da177e4SLinus Torvalds {
49001da177e4SLinus Torvalds 	struct kvec *iov = req->rq_rcv_buf.head;
49018687b63aSAl Viro 	__be32 *p;
49021da177e4SLinus Torvalds 	uint32_t count, eof, recvd, hdrlen;
49031da177e4SLinus Torvalds 	int status;
49041da177e4SLinus Torvalds 
49051da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
49061da177e4SLinus Torvalds 	if (status)
49071da177e4SLinus Torvalds 		return status;
4908c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4909c0eae66eSBenny Halevy 	if (unlikely(!p))
4910c0eae66eSBenny Halevy 		goto out_overflow;
49116f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
4912cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
49138111f373SChuck Lever 	hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
49141da177e4SLinus Torvalds 	recvd = req->rq_rcv_buf.len - hdrlen;
49151da177e4SLinus Torvalds 	if (count > recvd) {
4916fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
49171da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
49181da177e4SLinus Torvalds 		count = recvd;
49191da177e4SLinus Torvalds 		eof = 0;
49201da177e4SLinus Torvalds 	}
49211da177e4SLinus Torvalds 	xdr_read_pages(xdr, count);
49221da177e4SLinus Torvalds 	res->eof = eof;
49231da177e4SLinus Torvalds 	res->count = count;
49241da177e4SLinus Torvalds 	return 0;
4925c0eae66eSBenny Halevy out_overflow:
4926c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4927c0eae66eSBenny Halevy 	return -EIO;
49281da177e4SLinus Torvalds }
49291da177e4SLinus Torvalds 
49301da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
49311da177e4SLinus Torvalds {
49321da177e4SLinus Torvalds 	struct xdr_buf	*rcvbuf = &req->rq_rcv_buf;
49331da177e4SLinus Torvalds 	struct kvec	*iov = rcvbuf->head;
4934bcecff77SChuck Lever 	size_t		hdrlen;
4935bcecff77SChuck Lever 	u32		recvd, pglen = rcvbuf->page_len;
4936bcecff77SChuck Lever 	int		status;
49371da177e4SLinus Torvalds 
49381da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
4939db942bbdSBenny Halevy 	if (!status)
4940db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
4941db942bbdSBenny Halevy 	if (unlikely(status))
49421da177e4SLinus Torvalds 		return status;
494344109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
494444109241SFred Isaman 			__func__,
4945eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[0],
4946eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[1]);
4947eadf4598STrond Myklebust 
49481da177e4SLinus Torvalds 
4949db942bbdSBenny Halevy 	hdrlen = (char *) xdr->p - (char *) iov->iov_base;
49501da177e4SLinus Torvalds 	recvd = rcvbuf->len - hdrlen;
49511da177e4SLinus Torvalds 	if (pglen > recvd)
49521da177e4SLinus Torvalds 		pglen = recvd;
49531da177e4SLinus Torvalds 	xdr_read_pages(xdr, pglen);
49541da177e4SLinus Torvalds 
49557bda2cdfSJeff Layton 
4956ac396128STrond Myklebust 	return pglen;
49571da177e4SLinus Torvalds }
49581da177e4SLinus Torvalds 
49591da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
49601da177e4SLinus Torvalds {
49611da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
49621da177e4SLinus Torvalds 	struct kvec *iov = rcvbuf->head;
4963bcecff77SChuck Lever 	size_t hdrlen;
4964bcecff77SChuck Lever 	u32 len, recvd;
49658687b63aSAl Viro 	__be32 *p;
49661da177e4SLinus Torvalds 	int status;
49671da177e4SLinus Torvalds 
49681da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
49691da177e4SLinus Torvalds 	if (status)
49701da177e4SLinus Torvalds 		return status;
49711da177e4SLinus Torvalds 
49721da177e4SLinus Torvalds 	/* Convert length of symlink */
4973c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4974c0eae66eSBenny Halevy 	if (unlikely(!p))
4975c0eae66eSBenny Halevy 		goto out_overflow;
4976cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
49771da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
4978fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
49791da177e4SLinus Torvalds 		return -ENAMETOOLONG;
49801da177e4SLinus Torvalds 	}
49811da177e4SLinus Torvalds 	hdrlen = (char *) xdr->p - (char *) iov->iov_base;
49821da177e4SLinus Torvalds 	recvd = req->rq_rcv_buf.len - hdrlen;
49831da177e4SLinus Torvalds 	if (recvd < len) {
4984fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
49851da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
49861da177e4SLinus Torvalds 		return -EIO;
49871da177e4SLinus Torvalds 	}
49881da177e4SLinus Torvalds 	xdr_read_pages(xdr, len);
49891da177e4SLinus Torvalds 	/*
49901da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
49911da177e4SLinus Torvalds 	 * the link text will be copied directly into the
49921da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
49931da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
49941da177e4SLinus Torvalds 	 * null-termination).
49951da177e4SLinus Torvalds 	 */
4996b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
49971da177e4SLinus Torvalds 	return 0;
4998c0eae66eSBenny Halevy out_overflow:
4999c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5000c0eae66eSBenny Halevy 	return -EIO;
50011da177e4SLinus Torvalds }
50021da177e4SLinus Torvalds 
50031da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
50041da177e4SLinus Torvalds {
50051da177e4SLinus Torvalds 	int status;
50061da177e4SLinus Torvalds 
50071da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
50081da177e4SLinus Torvalds 	if (status)
50091da177e4SLinus Torvalds 		goto out;
50101da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
50111da177e4SLinus Torvalds out:
50121da177e4SLinus Torvalds 	return status;
50131da177e4SLinus Torvalds }
50141da177e4SLinus Torvalds 
50151da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
50161da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
50171da177e4SLinus Torvalds {
50181da177e4SLinus Torvalds 	int status;
50191da177e4SLinus Torvalds 
50201da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
50211da177e4SLinus Torvalds 	if (status)
50221da177e4SLinus Torvalds 		goto out;
50231da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
50241da177e4SLinus Torvalds 		goto out;
50251da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
50261da177e4SLinus Torvalds out:
50271da177e4SLinus Torvalds 	return status;
50281da177e4SLinus Torvalds }
50291da177e4SLinus Torvalds 
50301da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
50311da177e4SLinus Torvalds {
50321da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
50331da177e4SLinus Torvalds }
50341da177e4SLinus Torvalds 
503556ae19f3STrond Myklebust static int
503656ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
503756ae19f3STrond Myklebust {
503856ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
503956ae19f3STrond Myklebust }
504056ae19f3STrond Myklebust 
5041029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5042bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5043029d105eSJ. Bruce Fields {
5044bf118a34SAndy Adamson 	__be32 *savep, *bm_p;
5045029d105eSJ. Bruce Fields 	uint32_t attrlen,
5046dae100c2SFred Isaman 		 bitmap[3] = {0};
5047029d105eSJ. Bruce Fields 	struct kvec *iov = req->rq_rcv_buf.head;
5048029d105eSJ. Bruce Fields 	int status;
5049029d105eSJ. Bruce Fields 
5050bf118a34SAndy Adamson 	res->acl_len = 0;
5051029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5052029d105eSJ. Bruce Fields 		goto out;
5053bf118a34SAndy Adamson 	bm_p = xdr->p;
5054029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5055029d105eSJ. Bruce Fields 		goto out;
5056029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5057029d105eSJ. Bruce Fields 		goto out;
5058029d105eSJ. Bruce Fields 
5059029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5060029d105eSJ. Bruce Fields 		return -EIO;
5061029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5062bcecff77SChuck Lever 		size_t hdrlen;
5063bcecff77SChuck Lever 		u32 recvd;
5064029d105eSJ. Bruce Fields 
5065bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5066bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5067bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5068bf118a34SAndy Adamson 		xdr->p = bm_p;
5069bf118a34SAndy Adamson 		res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5070bf118a34SAndy Adamson 		res->acl_data_offset <<= 2;
5071bf118a34SAndy Adamson 
5072029d105eSJ. Bruce Fields 		/* We ignore &savep and don't do consistency checks on
5073029d105eSJ. Bruce Fields 		 * the attr length.  Let userspace figure it out.... */
5074029d105eSJ. Bruce Fields 		hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
5075bf118a34SAndy Adamson 		attrlen += res->acl_data_offset;
5076029d105eSJ. Bruce Fields 		recvd = req->rq_rcv_buf.len - hdrlen;
5077029d105eSJ. Bruce Fields 		if (attrlen > recvd) {
5078bf118a34SAndy Adamson 			if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5079bf118a34SAndy Adamson 				/* getxattr interface called with a NULL buf */
5080bf118a34SAndy Adamson 				res->acl_len = attrlen;
5081bf118a34SAndy Adamson 				goto out;
5082bf118a34SAndy Adamson 			}
5083bf118a34SAndy Adamson 			dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
5084029d105eSJ. Bruce Fields 					attrlen, recvd);
5085029d105eSJ. Bruce Fields 			return -EINVAL;
5086029d105eSJ. Bruce Fields 		}
5087029d105eSJ. Bruce Fields 		xdr_read_pages(xdr, attrlen);
5088bf118a34SAndy Adamson 		res->acl_len = attrlen;
50898c233cf9SJ. Bruce Fields 	} else
50908c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5091029d105eSJ. Bruce Fields 
5092029d105eSJ. Bruce Fields out:
5093029d105eSJ. Bruce Fields 	return status;
5094029d105eSJ. Bruce Fields }
5095029d105eSJ. Bruce Fields 
50961da177e4SLinus Torvalds static int
50971da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
50981da177e4SLinus Torvalds {
50991da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
51001da177e4SLinus Torvalds }
51011da177e4SLinus Torvalds 
51029e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
51031da177e4SLinus Torvalds {
51048687b63aSAl Viro 	__be32 *p;
51051da177e4SLinus Torvalds 	uint32_t bmlen;
51061da177e4SLinus Torvalds 	int status;
51071da177e4SLinus Torvalds 
51081da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
51091da177e4SLinus Torvalds 	if (status)
51101da177e4SLinus Torvalds 		return status;
5111c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5112c0eae66eSBenny Halevy 	if (unlikely(!p))
5113c0eae66eSBenny Halevy 		goto out_overflow;
5114cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
5115c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5116c0eae66eSBenny Halevy 	if (likely(p))
51171da177e4SLinus Torvalds 		return 0;
5118c0eae66eSBenny Halevy out_overflow:
5119c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5120c0eae66eSBenny Halevy 	return -EIO;
51211da177e4SLinus Torvalds }
51221da177e4SLinus Torvalds 
5123bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
51241da177e4SLinus Torvalds {
51258687b63aSAl Viro 	__be32 *p;
51261da177e4SLinus Torvalds 	uint32_t opnum;
51271da177e4SLinus Torvalds 	int32_t nfserr;
51281da177e4SLinus Torvalds 
5129c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5130c0eae66eSBenny Halevy 	if (unlikely(!p))
5131c0eae66eSBenny Halevy 		goto out_overflow;
51326f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
51331da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5134fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
51351da177e4SLinus Torvalds 			" %d\n", opnum);
51361da177e4SLinus Torvalds 		return -EIO;
51371da177e4SLinus Torvalds 	}
5138cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
51391da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5140c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5141c0eae66eSBenny Halevy 		if (unlikely(!p))
5142c0eae66eSBenny Halevy 			goto out_overflow;
5143bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5144bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
51451da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
51461da177e4SLinus Torvalds 		uint32_t len;
51471da177e4SLinus Torvalds 
51481da177e4SLinus Torvalds 		/* skip netid string */
5149c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5150c0eae66eSBenny Halevy 		if (unlikely(!p))
5151c0eae66eSBenny Halevy 			goto out_overflow;
5152cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5153c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5154c0eae66eSBenny Halevy 		if (unlikely(!p))
5155c0eae66eSBenny Halevy 			goto out_overflow;
51561da177e4SLinus Torvalds 
51571da177e4SLinus Torvalds 		/* skip uaddr string */
5158c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5159c0eae66eSBenny Halevy 		if (unlikely(!p))
5160c0eae66eSBenny Halevy 			goto out_overflow;
5161cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5162c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5163c0eae66eSBenny Halevy 		if (unlikely(!p))
5164c0eae66eSBenny Halevy 			goto out_overflow;
51651da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
51661da177e4SLinus Torvalds 	} else
5167856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
51681da177e4SLinus Torvalds 
51691da177e4SLinus Torvalds 	return 0;
5170c0eae66eSBenny Halevy out_overflow:
5171c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5172c0eae66eSBenny Halevy 	return -EIO;
51731da177e4SLinus Torvalds }
51741da177e4SLinus Torvalds 
51751da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
51761da177e4SLinus Torvalds {
51771da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
51781da177e4SLinus Torvalds }
51791da177e4SLinus Torvalds 
51801da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
51811da177e4SLinus Torvalds {
51828687b63aSAl Viro 	__be32 *p;
51831da177e4SLinus Torvalds 	int status;
51841da177e4SLinus Torvalds 
51851da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
51861da177e4SLinus Torvalds 	if (status)
51871da177e4SLinus Torvalds 		return status;
51881da177e4SLinus Torvalds 
5189c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 16);
5190c0eae66eSBenny Halevy 	if (unlikely(!p))
5191c0eae66eSBenny Halevy 		goto out_overflow;
51926f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
51936f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
519499398d06SBenny Halevy 	memcpy(res->verf->verifier, p, 8);
51951da177e4SLinus Torvalds 	return 0;
5196c0eae66eSBenny Halevy out_overflow:
5197c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5198c0eae66eSBenny Halevy 	return -EIO;
51991da177e4SLinus Torvalds }
52001da177e4SLinus Torvalds 
52011da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
52021da177e4SLinus Torvalds {
52031da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
52041da177e4SLinus Torvalds }
52051da177e4SLinus Torvalds 
52065a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
52075a5ea0d4SBryan Schumaker {
52085a5ea0d4SBryan Schumaker 	__be32 *p;
52095a5ea0d4SBryan Schumaker 
52105a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
52115a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52125a5ea0d4SBryan Schumaker 		goto out_overflow;
52135a5ea0d4SBryan Schumaker 	flavor->gss.sec_oid4.len = be32_to_cpup(p);
52145a5ea0d4SBryan Schumaker 	if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
52155a5ea0d4SBryan Schumaker 		goto out_err;
52165a5ea0d4SBryan Schumaker 
52175a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
52185a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52195a5ea0d4SBryan Schumaker 		goto out_overflow;
52205a5ea0d4SBryan Schumaker 	memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
52215a5ea0d4SBryan Schumaker 
52225a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
52235a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52245a5ea0d4SBryan Schumaker 		goto out_overflow;
52255a5ea0d4SBryan Schumaker 	flavor->gss.qop4 = be32_to_cpup(p++);
52265a5ea0d4SBryan Schumaker 	flavor->gss.service = be32_to_cpup(p);
52275a5ea0d4SBryan Schumaker 
52285a5ea0d4SBryan Schumaker 	return 0;
52295a5ea0d4SBryan Schumaker 
52305a5ea0d4SBryan Schumaker out_overflow:
52315a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
52325a5ea0d4SBryan Schumaker 	return -EIO;
52335a5ea0d4SBryan Schumaker out_err:
52345a5ea0d4SBryan Schumaker 	return -EINVAL;
52355a5ea0d4SBryan Schumaker }
52365a5ea0d4SBryan Schumaker 
52375a5ea0d4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
52385a5ea0d4SBryan Schumaker {
52395a5ea0d4SBryan Schumaker 	struct nfs4_secinfo_flavor *sec_flavor;
52405a5ea0d4SBryan Schumaker 	int status;
52415a5ea0d4SBryan Schumaker 	__be32 *p;
5242c3dfc280SBryan Schumaker 	int i, num_flavors;
52435a5ea0d4SBryan Schumaker 
52445a5ea0d4SBryan Schumaker 	status = decode_op_hdr(xdr, OP_SECINFO);
5245613e901eSBryan Schumaker 	if (status)
5246613e901eSBryan Schumaker 		goto out;
52475a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
52485a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52495a5ea0d4SBryan Schumaker 		goto out_overflow;
52505a5ea0d4SBryan Schumaker 
5251c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5252c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5253c3dfc280SBryan Schumaker 
5254c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
52555a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5256c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
52575a5ea0d4SBryan Schumaker 			break;
52585a5ea0d4SBryan Schumaker 
52595a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
52605a5ea0d4SBryan Schumaker 		if (unlikely(!p))
52615a5ea0d4SBryan Schumaker 			goto out_overflow;
52625a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
52635a5ea0d4SBryan Schumaker 
52645a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5265613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5266613e901eSBryan Schumaker 			if (status)
5267613e901eSBryan Schumaker 				goto out;
52685a5ea0d4SBryan Schumaker 		}
5269c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
52705a5ea0d4SBryan Schumaker 	}
52715a5ea0d4SBryan Schumaker 
5272613e901eSBryan Schumaker out:
5273613e901eSBryan Schumaker 	return status;
52745a5ea0d4SBryan Schumaker out_overflow:
52755a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
52765a5ea0d4SBryan Schumaker 	return -EIO;
52775a5ea0d4SBryan Schumaker }
52785a5ea0d4SBryan Schumaker 
527999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
528099fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
528199fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
528299fe60d0SBenny Halevy {
528399fe60d0SBenny Halevy 	__be32 *p;
528499fe60d0SBenny Halevy 	uint32_t dummy;
52852460ba57SBenny Halevy 	char *dummy_str;
528699fe60d0SBenny Halevy 	int status;
528799fe60d0SBenny Halevy 	struct nfs_client *clp = res->client;
52887d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
528999fe60d0SBenny Halevy 
529099fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
529199fe60d0SBenny Halevy 	if (status)
529299fe60d0SBenny Halevy 		return status;
529399fe60d0SBenny Halevy 
5294c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5295c0eae66eSBenny Halevy 	if (unlikely(!p))
5296c0eae66eSBenny Halevy 		goto out_overflow;
5297114f64b5SAndy Adamson 	xdr_decode_hyper(p, &clp->cl_clientid);
5298c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5299c0eae66eSBenny Halevy 	if (unlikely(!p))
5300c0eae66eSBenny Halevy 		goto out_overflow;
53016f723f77SBenny Halevy 	clp->cl_seqid = be32_to_cpup(p++);
53026f723f77SBenny Halevy 	clp->cl_exchange_flags = be32_to_cpup(p++);
530399fe60d0SBenny Halevy 
530499fe60d0SBenny Halevy 	/* We ask for SP4_NONE */
5305cccddf4fSBenny Halevy 	dummy = be32_to_cpup(p);
530699fe60d0SBenny Halevy 	if (dummy != SP4_NONE)
530799fe60d0SBenny Halevy 		return -EIO;
530899fe60d0SBenny Halevy 
530999fe60d0SBenny Halevy 	/* Throw away minor_id */
5310c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5311c0eae66eSBenny Halevy 	if (unlikely(!p))
5312c0eae66eSBenny Halevy 		goto out_overflow;
531399fe60d0SBenny Halevy 
531499fe60d0SBenny Halevy 	/* Throw away Major id */
53152460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53162460ba57SBenny Halevy 	if (unlikely(status))
53172460ba57SBenny Halevy 		return status;
531899fe60d0SBenny Halevy 
531978fe0f41SWeston Andros Adamson 	/* Save server_scope */
53202460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53212460ba57SBenny Halevy 	if (unlikely(status))
53222460ba57SBenny Halevy 		return status;
532399fe60d0SBenny Halevy 
532478fe0f41SWeston Andros Adamson 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
532578fe0f41SWeston Andros Adamson 		return -EIO;
532678fe0f41SWeston Andros Adamson 
532778fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
532878fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
532978fe0f41SWeston Andros Adamson 
53307d2ed9acSWeston Andros Adamson 	/* Implementation Id */
53317d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
53327d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
53337d2ed9acSWeston Andros Adamson 		goto out_overflow;
53347d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
53357d2ed9acSWeston Andros Adamson 
53367d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
53377d2ed9acSWeston Andros Adamson 		/* nii_domain */
53382460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53392460ba57SBenny Halevy 		if (unlikely(status))
53402460ba57SBenny Halevy 			return status;
53417d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
53427d2ed9acSWeston Andros Adamson 			return -EIO;
53437d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
534499fe60d0SBenny Halevy 
53457d2ed9acSWeston Andros Adamson 		/* nii_name */
53467d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53477d2ed9acSWeston Andros Adamson 		if (unlikely(status))
53487d2ed9acSWeston Andros Adamson 			return status;
53497d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
53507d2ed9acSWeston Andros Adamson 			return -EIO;
53517d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
53527d2ed9acSWeston Andros Adamson 
53537d2ed9acSWeston Andros Adamson 		/* nii_date */
53547d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
53557d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
53567d2ed9acSWeston Andros Adamson 			goto out_overflow;
53577d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
53587d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
53597d2ed9acSWeston Andros Adamson 
53607d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
53617d2ed9acSWeston Andros Adamson 	}
536299fe60d0SBenny Halevy 	return 0;
5363c0eae66eSBenny Halevy out_overflow:
5364c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5365c0eae66eSBenny Halevy 	return -EIO;
536699fe60d0SBenny Halevy }
5367fc931582SAndy Adamson 
5368fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5369fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5370fc931582SAndy Adamson {
5371fc931582SAndy Adamson 	__be32 *p;
5372c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5373fc931582SAndy Adamson 
5374c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5375c0eae66eSBenny Halevy 	if (unlikely(!p))
5376c0eae66eSBenny Halevy 		goto out_overflow;
5377c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5378c9c30dd5SBenny Halevy 	if (val)
5379c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
53806f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
53816f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
53826f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
53836f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
53846f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5385cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5386fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5387a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5388a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5389fc931582SAndy Adamson 		return -EINVAL;
5390fc931582SAndy Adamson 	}
5391c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5392c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5393c0eae66eSBenny Halevy 		if (unlikely(!p))
5394c0eae66eSBenny Halevy 			goto out_overflow;
5395c0eae66eSBenny Halevy 	}
5396fc931582SAndy Adamson 	return 0;
5397c0eae66eSBenny Halevy out_overflow:
5398c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5399c0eae66eSBenny Halevy 	return -EIO;
5400fc931582SAndy Adamson }
5401fc931582SAndy Adamson 
5402e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5403e78291e4SBenny Halevy {
5404e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5405fc931582SAndy Adamson }
5406fc931582SAndy Adamson 
5407fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5408fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5409fc931582SAndy Adamson {
5410fc931582SAndy Adamson 	__be32 *p;
5411fc931582SAndy Adamson 	int status;
5412fc931582SAndy Adamson 	struct nfs_client *clp = res->client;
5413fc931582SAndy Adamson 	struct nfs4_session *session = clp->cl_session;
5414fc931582SAndy Adamson 
5415fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5416e78291e4SBenny Halevy 	if (!status)
5417e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &session->sess_id);
5418e78291e4SBenny Halevy 	if (unlikely(status))
5419fc931582SAndy Adamson 		return status;
5420fc931582SAndy Adamson 
5421fc931582SAndy Adamson 	/* seqid, flags */
5422c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5423c0eae66eSBenny Halevy 	if (unlikely(!p))
5424c0eae66eSBenny Halevy 		goto out_overflow;
54256f723f77SBenny Halevy 	clp->cl_seqid = be32_to_cpup(p++);
5426cccddf4fSBenny Halevy 	session->flags = be32_to_cpup(p);
5427fc931582SAndy Adamson 
5428fc931582SAndy Adamson 	/* Channel attributes */
5429fc931582SAndy Adamson 	status = decode_chan_attrs(xdr, &session->fc_attrs);
5430fc931582SAndy Adamson 	if (!status)
5431fc931582SAndy Adamson 		status = decode_chan_attrs(xdr, &session->bc_attrs);
5432fc931582SAndy Adamson 	return status;
5433c0eae66eSBenny Halevy out_overflow:
5434c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5435c0eae66eSBenny Halevy 	return -EIO;
5436fc931582SAndy Adamson }
54370f3e66c6SAndy Adamson 
54380f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
54390f3e66c6SAndy Adamson {
54400f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
54410f3e66c6SAndy Adamson }
544218019753SRicardo Labiaga 
544318019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
544418019753SRicardo Labiaga {
544518019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
544618019753SRicardo Labiaga }
544799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
544899fe60d0SBenny Halevy 
54499b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
54509b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
54519b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
54529b7b9fccSAndy Adamson {
54539b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5454fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5455fc01cea9SAndy Adamson 	u32 dummy;
5456fc01cea9SAndy Adamson 	int status;
5457fc01cea9SAndy Adamson 	__be32 *p;
5458fc01cea9SAndy Adamson 
54599b7b9fccSAndy Adamson 	if (!res->sr_session)
54609b7b9fccSAndy Adamson 		return 0;
54619b7b9fccSAndy Adamson 
5462fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5463e78291e4SBenny Halevy 	if (!status)
5464e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5465e78291e4SBenny Halevy 	if (unlikely(status))
5466fc01cea9SAndy Adamson 		goto out_err;
54679b7b9fccSAndy Adamson 
5468fc01cea9SAndy Adamson 	/*
5469fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5470fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5471fc01cea9SAndy Adamson 	 */
5472fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5473fc01cea9SAndy Adamson 
5474fc01cea9SAndy Adamson 	if (memcmp(id.data, res->sr_session->sess_id.data,
5475fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5476fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5477fc01cea9SAndy Adamson 		goto out_err;
5478fc01cea9SAndy Adamson 	}
5479e78291e4SBenny Halevy 
5480c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5481c0eae66eSBenny Halevy 	if (unlikely(!p))
5482c0eae66eSBenny Halevy 		goto out_overflow;
5483e78291e4SBenny Halevy 
5484fc01cea9SAndy Adamson 	/* seqid */
54856f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5486dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5487fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5488fc01cea9SAndy Adamson 		goto out_err;
5489fc01cea9SAndy Adamson 	}
5490fc01cea9SAndy Adamson 	/* slot id */
54916f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5492dfb4f309SBenny Halevy 	if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5493fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5494fc01cea9SAndy Adamson 		goto out_err;
5495fc01cea9SAndy Adamson 	}
5496fc01cea9SAndy Adamson 	/* highest slot id - currently not processed */
54976f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5498fc01cea9SAndy Adamson 	/* target highest slot id - currently not processed */
54996f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
55000629e370SAlexandros Batsakis 	/* result flags */
55010629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5502fc01cea9SAndy Adamson 	status = 0;
5503fc01cea9SAndy Adamson out_err:
5504fc01cea9SAndy Adamson 	res->sr_status = status;
5505fc01cea9SAndy Adamson 	return status;
5506c0eae66eSBenny Halevy out_overflow:
5507c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5508c0eae66eSBenny Halevy 	status = -EIO;
5509c0eae66eSBenny Halevy 	goto out_err;
5510fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
55119b7b9fccSAndy Adamson 	return 0;
5512fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
55139b7b9fccSAndy Adamson }
55149b7b9fccSAndy Adamson 
5515b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
55167f11d8d3SAndy Adamson /*
55177f11d8d3SAndy Adamson  * TODO: Need to handle case when EOF != true;
55187f11d8d3SAndy Adamson  */
55197f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr,
55207f11d8d3SAndy Adamson 				struct pnfs_devicelist *res)
55217f11d8d3SAndy Adamson {
55227f11d8d3SAndy Adamson 	__be32 *p;
55237f11d8d3SAndy Adamson 	int status, i;
55247f11d8d3SAndy Adamson 	struct nfs_writeverf verftemp;
55257f11d8d3SAndy Adamson 
55267f11d8d3SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICELIST);
55277f11d8d3SAndy Adamson 	if (status)
55287f11d8d3SAndy Adamson 		return status;
55297f11d8d3SAndy Adamson 
55307f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr, 8 + 8 + 4);
55317f11d8d3SAndy Adamson 	if (unlikely(!p))
55327f11d8d3SAndy Adamson 		goto out_overflow;
55337f11d8d3SAndy Adamson 
55347f11d8d3SAndy Adamson 	/* TODO: Skip cookie for now */
55357f11d8d3SAndy Adamson 	p += 2;
55367f11d8d3SAndy Adamson 
55377f11d8d3SAndy Adamson 	/* Read verifier */
55387f11d8d3SAndy Adamson 	p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
55397f11d8d3SAndy Adamson 
55407f11d8d3SAndy Adamson 	res->num_devs = be32_to_cpup(p);
55417f11d8d3SAndy Adamson 
55427f11d8d3SAndy Adamson 	dprintk("%s: num_dev %d\n", __func__, res->num_devs);
55437f11d8d3SAndy Adamson 
55447f11d8d3SAndy Adamson 	if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5545a030889aSWeston Andros Adamson 		printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
55467f11d8d3SAndy Adamson 				__func__, res->num_devs);
55477f11d8d3SAndy Adamson 		return -EIO;
55487f11d8d3SAndy Adamson 	}
55497f11d8d3SAndy Adamson 
55507f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr,
55517f11d8d3SAndy Adamson 			      res->num_devs * NFS4_DEVICEID4_SIZE + 4);
55527f11d8d3SAndy Adamson 	if (unlikely(!p))
55537f11d8d3SAndy Adamson 		goto out_overflow;
55547f11d8d3SAndy Adamson 	for (i = 0; i < res->num_devs; i++)
55557f11d8d3SAndy Adamson 		p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
55567f11d8d3SAndy Adamson 					    NFS4_DEVICEID4_SIZE);
55577f11d8d3SAndy Adamson 	res->eof = be32_to_cpup(p);
55587f11d8d3SAndy Adamson 	return 0;
55597f11d8d3SAndy Adamson out_overflow:
55607f11d8d3SAndy Adamson 	print_overflow_msg(__func__, xdr);
55617f11d8d3SAndy Adamson 	return -EIO;
55627f11d8d3SAndy Adamson }
5563b1f69b75SAndy Adamson 
5564b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
5565b1f69b75SAndy Adamson 				struct pnfs_device *pdev)
5566b1f69b75SAndy Adamson {
5567b1f69b75SAndy Adamson 	__be32 *p;
5568b1f69b75SAndy Adamson 	uint32_t len, type;
5569b1f69b75SAndy Adamson 	int status;
5570b1f69b75SAndy Adamson 
5571b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5572b1f69b75SAndy Adamson 	if (status) {
5573b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5574b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5575b1f69b75SAndy Adamson 			if (unlikely(!p))
5576b1f69b75SAndy Adamson 				goto out_overflow;
5577b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5578b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5579b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5580b1f69b75SAndy Adamson 		}
5581b1f69b75SAndy Adamson 		return status;
5582b1f69b75SAndy Adamson 	}
5583b1f69b75SAndy Adamson 
5584b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5585b1f69b75SAndy Adamson 	if (unlikely(!p))
5586b1f69b75SAndy Adamson 		goto out_overflow;
5587b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5588b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5589b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5590b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5591b1f69b75SAndy Adamson 		return -EINVAL;
5592b1f69b75SAndy Adamson 	}
5593b1f69b75SAndy Adamson 	/*
5594b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5595b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5596b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5597b1f69b75SAndy Adamson 	 */
5598b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
5599b1f69b75SAndy Adamson 	xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5600b1f69b75SAndy Adamson 
5601b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5602b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5603b1f69b75SAndy Adamson 	if (unlikely(!p))
5604b1f69b75SAndy Adamson 		goto out_overflow;
5605b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5606b1f69b75SAndy Adamson 	if (len) {
5607ead00597SChuck Lever 		uint32_t i;
5608b1f69b75SAndy Adamson 
5609b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5610b1f69b75SAndy Adamson 		if (unlikely(!p))
5611b1f69b75SAndy Adamson 			goto out_overflow;
5612b1f69b75SAndy Adamson 		for (i = 0; i < len; i++, p++) {
5613b1f69b75SAndy Adamson 			if (be32_to_cpup(p)) {
5614b1f69b75SAndy Adamson 				dprintk("%s: notifications not supported\n",
5615b1f69b75SAndy Adamson 					__func__);
5616b1f69b75SAndy Adamson 				return -EIO;
5617b1f69b75SAndy Adamson 			}
5618b1f69b75SAndy Adamson 		}
5619b1f69b75SAndy Adamson 	}
5620b1f69b75SAndy Adamson 	return 0;
5621b1f69b75SAndy Adamson out_overflow:
5622b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5623b1f69b75SAndy Adamson 	return -EIO;
5624b1f69b75SAndy Adamson }
5625b1f69b75SAndy Adamson 
5626b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5627b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5628b1f69b75SAndy Adamson {
5629b1f69b75SAndy Adamson 	__be32 *p;
5630b1f69b75SAndy Adamson 	int status;
5631b1f69b75SAndy Adamson 	u32 layout_count;
563235124a09SWeston Andros Adamson 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
563335124a09SWeston Andros Adamson 	struct kvec *iov = rcvbuf->head;
563435124a09SWeston Andros Adamson 	u32 hdrlen, recvd;
5635b1f69b75SAndy Adamson 
5636b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5637b1f69b75SAndy Adamson 	if (status)
5638b1f69b75SAndy Adamson 		return status;
5639b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5640b1f69b75SAndy Adamson 	if (unlikely(!p))
5641b1f69b75SAndy Adamson 		goto out_overflow;
5642b1f69b75SAndy Adamson 	res->return_on_close = be32_to_cpup(p++);
5643b1f69b75SAndy Adamson 	p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5644b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5645b1f69b75SAndy Adamson 	if (!layout_count) {
5646b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5647b1f69b75SAndy Adamson 			__func__);
5648b1f69b75SAndy Adamson 		return -EINVAL;
5649b1f69b75SAndy Adamson 	}
5650b1f69b75SAndy Adamson 
565135124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5652b1f69b75SAndy Adamson 	if (unlikely(!p))
5653b1f69b75SAndy Adamson 		goto out_overflow;
5654b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5655b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5656b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5657b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
565835124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5659b1f69b75SAndy Adamson 
5660b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5661b1f69b75SAndy Adamson 		__func__,
5662b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5663b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5664b1f69b75SAndy Adamson 		res->range.iomode,
5665b1f69b75SAndy Adamson 		res->type,
566635124a09SWeston Andros Adamson 		res->layoutp->len);
5667b1f69b75SAndy Adamson 
566835124a09SWeston Andros Adamson 	hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
566935124a09SWeston Andros Adamson 	recvd = req->rq_rcv_buf.len - hdrlen;
567035124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
567135124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
567235124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
567335124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
567435124a09SWeston Andros Adamson 		return -EINVAL;
567535124a09SWeston Andros Adamson 	}
567635124a09SWeston Andros Adamson 
567735124a09SWeston Andros Adamson 	xdr_read_pages(xdr, res->layoutp->len);
5678b1f69b75SAndy Adamson 
5679b1f69b75SAndy Adamson 	if (layout_count > 1) {
5680b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5681b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5682b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5683b1f69b75SAndy Adamson 		 * minimum it requested.
5684b1f69b75SAndy Adamson 		 */
5685b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5686b1f69b75SAndy Adamson 			__func__, layout_count);
5687b1f69b75SAndy Adamson 	}
5688b1f69b75SAndy Adamson 
5689b1f69b75SAndy Adamson 	return 0;
5690b1f69b75SAndy Adamson out_overflow:
5691b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5692b1f69b75SAndy Adamson 	return -EIO;
5693b1f69b75SAndy Adamson }
5694863a3c6cSAndy Adamson 
5695cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
5696cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
5697cbe82603SBenny Halevy {
5698cbe82603SBenny Halevy 	__be32 *p;
5699cbe82603SBenny Halevy 	int status;
5700cbe82603SBenny Halevy 
5701cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5702cbe82603SBenny Halevy 	if (status)
5703cbe82603SBenny Halevy 		return status;
5704cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5705cbe82603SBenny Halevy 	if (unlikely(!p))
5706cbe82603SBenny Halevy 		goto out_overflow;
5707cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
5708cbe82603SBenny Halevy 	if (res->lrs_present)
5709cbe82603SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
5710cbe82603SBenny Halevy 	return status;
5711cbe82603SBenny Halevy out_overflow:
5712cbe82603SBenny Halevy 	print_overflow_msg(__func__, xdr);
5713cbe82603SBenny Halevy 	return -EIO;
5714cbe82603SBenny Halevy }
5715cbe82603SBenny Halevy 
5716863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
5717863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
5718863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
5719863a3c6cSAndy Adamson {
5720863a3c6cSAndy Adamson 	__be32 *p;
5721863a3c6cSAndy Adamson 	__u32 sizechanged;
5722863a3c6cSAndy Adamson 	int status;
5723863a3c6cSAndy Adamson 
5724863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5725db29c089SAndy Adamson 	res->status = status;
5726863a3c6cSAndy Adamson 	if (status)
5727863a3c6cSAndy Adamson 		return status;
5728863a3c6cSAndy Adamson 
5729863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5730863a3c6cSAndy Adamson 	if (unlikely(!p))
5731863a3c6cSAndy Adamson 		goto out_overflow;
5732863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
5733863a3c6cSAndy Adamson 
5734863a3c6cSAndy Adamson 	if (sizechanged) {
5735863a3c6cSAndy Adamson 		/* throw away new size */
5736863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
5737863a3c6cSAndy Adamson 		if (unlikely(!p))
5738863a3c6cSAndy Adamson 			goto out_overflow;
5739863a3c6cSAndy Adamson 	}
5740863a3c6cSAndy Adamson 	return 0;
5741863a3c6cSAndy Adamson out_overflow:
5742863a3c6cSAndy Adamson 	print_overflow_msg(__func__, xdr);
5743863a3c6cSAndy Adamson 	return -EIO;
5744863a3c6cSAndy Adamson }
57457d974794SBryan Schumaker 
57467d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
57477d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
57487d974794SBryan Schumaker {
57497d974794SBryan Schumaker 	__be32 *p;
57507d974794SBryan Schumaker 	int status;
57517d974794SBryan Schumaker 	int num_res;
57527d974794SBryan Schumaker 
57537d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
57547d974794SBryan Schumaker 	if (status)
57557d974794SBryan Schumaker 		return status;
57567d974794SBryan Schumaker 
57577d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
57587d974794SBryan Schumaker 	if (unlikely(!p))
57597d974794SBryan Schumaker 		goto out_overflow;
57607d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
57617d974794SBryan Schumaker 	if (num_res != 1)
57627d974794SBryan Schumaker 		goto out;
57637d974794SBryan Schumaker 
57647d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
57657d974794SBryan Schumaker 	if (unlikely(!p))
57667d974794SBryan Schumaker 		goto out_overflow;
57677d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
57681cab0652SBryan Schumaker 
57691cab0652SBryan Schumaker 	return status;
57707d974794SBryan Schumaker out_overflow:
57717d974794SBryan Schumaker 	print_overflow_msg(__func__, xdr);
57727d974794SBryan Schumaker out:
57737d974794SBryan Schumaker 	return -EIO;
57747d974794SBryan Schumaker }
57759aeda35fSBryan Schumaker 
57769aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
57779aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
57789aeda35fSBryan Schumaker {
57799aeda35fSBryan Schumaker 	__be32 *p;
57809aeda35fSBryan Schumaker 	int status;
57819aeda35fSBryan Schumaker 
57829aeda35fSBryan Schumaker 	status = decode_op_hdr(xdr, OP_FREE_STATEID);
57839aeda35fSBryan Schumaker 	if (status)
57849aeda35fSBryan Schumaker 		return status;
57859aeda35fSBryan Schumaker 
57869aeda35fSBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
57879aeda35fSBryan Schumaker 	if (unlikely(!p))
57889aeda35fSBryan Schumaker 		goto out_overflow;
57899aeda35fSBryan Schumaker 	res->status = be32_to_cpup(p++);
57909aeda35fSBryan Schumaker 	return res->status;
57919aeda35fSBryan Schumaker out_overflow:
57929aeda35fSBryan Schumaker 	print_overflow_msg(__func__, xdr);
57939aeda35fSBryan Schumaker 	return -EIO;
57949aeda35fSBryan Schumaker }
5795b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
5796b1f69b75SAndy Adamson 
57971da177e4SLinus Torvalds /*
579849c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
579949c2559eSBenny Halevy  */
580049c2559eSBenny Halevy 
580149c2559eSBenny Halevy /*
58021da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
58031da177e4SLinus Torvalds  */
5804bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5805bf269551SChuck Lever 				       struct xdr_stream *xdr,
5806bf269551SChuck Lever 				       struct nfs_closeres *res)
58071da177e4SLinus Torvalds {
58081da177e4SLinus Torvalds 	struct compound_hdr hdr;
58091da177e4SLinus Torvalds 	int status;
58101da177e4SLinus Torvalds 
5811bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58121da177e4SLinus Torvalds 	if (status)
58131da177e4SLinus Torvalds 		goto out;
5814bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58159b7b9fccSAndy Adamson 	if (status)
58169b7b9fccSAndy Adamson 		goto out;
5817bf269551SChuck Lever 	status = decode_putfh(xdr);
58181da177e4SLinus Torvalds 	if (status)
58191da177e4SLinus Torvalds 		goto out;
5820bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
5821516a6af6STrond Myklebust 	if (status != 0)
5822516a6af6STrond Myklebust 		goto out;
58236926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
58241da177e4SLinus Torvalds out:
58251da177e4SLinus Torvalds 	return status;
58261da177e4SLinus Torvalds }
58271da177e4SLinus Torvalds 
58281da177e4SLinus Torvalds /*
58291da177e4SLinus Torvalds  * Decode ACCESS response
58301da177e4SLinus Torvalds  */
5831bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5832bf269551SChuck Lever 			       struct nfs4_accessres *res)
58331da177e4SLinus Torvalds {
58341da177e4SLinus Torvalds 	struct compound_hdr hdr;
58351da177e4SLinus Torvalds 	int status;
58361da177e4SLinus Torvalds 
5837bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58389b7b9fccSAndy Adamson 	if (status)
58399b7b9fccSAndy Adamson 		goto out;
5840bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58419b7b9fccSAndy Adamson 	if (status)
58421da177e4SLinus Torvalds 		goto out;
5843bf269551SChuck Lever 	status = decode_putfh(xdr);
584476b32999STrond Myklebust 	if (status != 0)
584576b32999STrond Myklebust 		goto out;
5846bf269551SChuck Lever 	status = decode_access(xdr, res);
584776b32999STrond Myklebust 	if (status != 0)
584876b32999STrond Myklebust 		goto out;
58496926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
58501da177e4SLinus Torvalds out:
58511da177e4SLinus Torvalds 	return status;
58521da177e4SLinus Torvalds }
58531da177e4SLinus Torvalds 
58541da177e4SLinus Torvalds /*
58551da177e4SLinus Torvalds  * Decode LOOKUP response
58561da177e4SLinus Torvalds  */
5857bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5858bf269551SChuck Lever 			       struct nfs4_lookup_res *res)
58591da177e4SLinus Torvalds {
58601da177e4SLinus Torvalds 	struct compound_hdr hdr;
58611da177e4SLinus Torvalds 	int status;
58621da177e4SLinus Torvalds 
5863bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58649b7b9fccSAndy Adamson 	if (status)
58659b7b9fccSAndy Adamson 		goto out;
5866bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58679b7b9fccSAndy Adamson 	if (status)
58681da177e4SLinus Torvalds 		goto out;
5869bf269551SChuck Lever 	status = decode_putfh(xdr);
5870bf269551SChuck Lever 	if (status)
58711da177e4SLinus Torvalds 		goto out;
5872bf269551SChuck Lever 	status = decode_lookup(xdr);
5873bf269551SChuck Lever 	if (status)
58741da177e4SLinus Torvalds 		goto out;
5875bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
5876bf269551SChuck Lever 	if (status)
58771da177e4SLinus Torvalds 		goto out;
58786926afd1STrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
58791da177e4SLinus Torvalds out:
58801da177e4SLinus Torvalds 	return status;
58811da177e4SLinus Torvalds }
58821da177e4SLinus Torvalds 
58831da177e4SLinus Torvalds /*
58841da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
58851da177e4SLinus Torvalds  */
5886bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5887bf269551SChuck Lever 				    struct xdr_stream *xdr,
5888bf269551SChuck Lever 				    struct nfs4_lookup_res *res)
58891da177e4SLinus Torvalds {
58901da177e4SLinus Torvalds 	struct compound_hdr hdr;
58911da177e4SLinus Torvalds 	int status;
58921da177e4SLinus Torvalds 
5893bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58949b7b9fccSAndy Adamson 	if (status)
58959b7b9fccSAndy Adamson 		goto out;
5896bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58979b7b9fccSAndy Adamson 	if (status)
58981da177e4SLinus Torvalds 		goto out;
5899bf269551SChuck Lever 	status = decode_putrootfh(xdr);
5900bf269551SChuck Lever 	if (status)
59011da177e4SLinus Torvalds 		goto out;
5902bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
5903bf269551SChuck Lever 	if (status == 0)
59046926afd1STrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
59051da177e4SLinus Torvalds out:
59061da177e4SLinus Torvalds 	return status;
59071da177e4SLinus Torvalds }
59081da177e4SLinus Torvalds 
59091da177e4SLinus Torvalds /*
59101da177e4SLinus Torvalds  * Decode REMOVE response
59111da177e4SLinus Torvalds  */
5912bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5913bf269551SChuck Lever 			       struct nfs_removeres *res)
59141da177e4SLinus Torvalds {
59151da177e4SLinus Torvalds 	struct compound_hdr hdr;
59161da177e4SLinus Torvalds 	int status;
59171da177e4SLinus Torvalds 
5918bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59199b7b9fccSAndy Adamson 	if (status)
59209b7b9fccSAndy Adamson 		goto out;
5921bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59229b7b9fccSAndy Adamson 	if (status)
59231da177e4SLinus Torvalds 		goto out;
5924bf269551SChuck Lever 	status = decode_putfh(xdr);
5925bf269551SChuck Lever 	if (status)
592616e42959STrond Myklebust 		goto out;
5927bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
5928bf269551SChuck Lever 	if (status)
592916e42959STrond Myklebust 		goto out;
59306926afd1STrond Myklebust 	decode_getfattr(xdr, res->dir_attr, res->server);
59311da177e4SLinus Torvalds out:
59321da177e4SLinus Torvalds 	return status;
59331da177e4SLinus Torvalds }
59341da177e4SLinus Torvalds 
59351da177e4SLinus Torvalds /*
59361da177e4SLinus Torvalds  * Decode RENAME response
59371da177e4SLinus Torvalds  */
5938bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5939bf269551SChuck Lever 			       struct nfs_renameres *res)
59401da177e4SLinus Torvalds {
59411da177e4SLinus Torvalds 	struct compound_hdr hdr;
59421da177e4SLinus Torvalds 	int status;
59431da177e4SLinus Torvalds 
5944bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59459b7b9fccSAndy Adamson 	if (status)
59469b7b9fccSAndy Adamson 		goto out;
5947bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59489b7b9fccSAndy Adamson 	if (status)
59491da177e4SLinus Torvalds 		goto out;
5950bf269551SChuck Lever 	status = decode_putfh(xdr);
5951bf269551SChuck Lever 	if (status)
59521da177e4SLinus Torvalds 		goto out;
5953bf269551SChuck Lever 	status = decode_savefh(xdr);
5954bf269551SChuck Lever 	if (status)
59551da177e4SLinus Torvalds 		goto out;
5956bf269551SChuck Lever 	status = decode_putfh(xdr);
5957bf269551SChuck Lever 	if (status)
59581da177e4SLinus Torvalds 		goto out;
5959bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5960bf269551SChuck Lever 	if (status)
59616caf2c82STrond Myklebust 		goto out;
59626caf2c82STrond Myklebust 	/* Current FH is target directory */
59636926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->new_fattr, res->server))
59646caf2c82STrond Myklebust 		goto out;
5965bf269551SChuck Lever 	status = decode_restorefh(xdr);
5966bf269551SChuck Lever 	if (status)
59676caf2c82STrond Myklebust 		goto out;
59686926afd1STrond Myklebust 	decode_getfattr(xdr, res->old_fattr, res->server);
59691da177e4SLinus Torvalds out:
59701da177e4SLinus Torvalds 	return status;
59711da177e4SLinus Torvalds }
59721da177e4SLinus Torvalds 
59731da177e4SLinus Torvalds /*
59741da177e4SLinus Torvalds  * Decode LINK response
59751da177e4SLinus Torvalds  */
5976bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5977bf269551SChuck Lever 			     struct nfs4_link_res *res)
59781da177e4SLinus Torvalds {
59791da177e4SLinus Torvalds 	struct compound_hdr hdr;
59801da177e4SLinus Torvalds 	int status;
59811da177e4SLinus Torvalds 
5982bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59839b7b9fccSAndy Adamson 	if (status)
59849b7b9fccSAndy Adamson 		goto out;
5985bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59869b7b9fccSAndy Adamson 	if (status)
59871da177e4SLinus Torvalds 		goto out;
5988bf269551SChuck Lever 	status = decode_putfh(xdr);
5989bf269551SChuck Lever 	if (status)
59901da177e4SLinus Torvalds 		goto out;
5991bf269551SChuck Lever 	status = decode_savefh(xdr);
5992bf269551SChuck Lever 	if (status)
59931da177e4SLinus Torvalds 		goto out;
5994bf269551SChuck Lever 	status = decode_putfh(xdr);
5995bf269551SChuck Lever 	if (status)
59961da177e4SLinus Torvalds 		goto out;
5997bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
5998bf269551SChuck Lever 	if (status)
599991ba2eeeSTrond Myklebust 		goto out;
600091ba2eeeSTrond Myklebust 	/*
600191ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
600291ba2eeeSTrond Myklebust 	 *             filehandle.
600391ba2eeeSTrond Myklebust 	 */
60046926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->dir_attr, res->server))
600591ba2eeeSTrond Myklebust 		goto out;
6006bf269551SChuck Lever 	status = decode_restorefh(xdr);
6007bf269551SChuck Lever 	if (status)
600891ba2eeeSTrond Myklebust 		goto out;
60096926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
60101da177e4SLinus Torvalds out:
60111da177e4SLinus Torvalds 	return status;
60121da177e4SLinus Torvalds }
60131da177e4SLinus Torvalds 
60141da177e4SLinus Torvalds /*
60151da177e4SLinus Torvalds  * Decode CREATE response
60161da177e4SLinus Torvalds  */
6017bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6018bf269551SChuck Lever 			       struct nfs4_create_res *res)
60191da177e4SLinus Torvalds {
60201da177e4SLinus Torvalds 	struct compound_hdr hdr;
60211da177e4SLinus Torvalds 	int status;
60221da177e4SLinus Torvalds 
6023bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60249b7b9fccSAndy Adamson 	if (status)
60259b7b9fccSAndy Adamson 		goto out;
6026bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60279b7b9fccSAndy Adamson 	if (status)
60281da177e4SLinus Torvalds 		goto out;
6029bf269551SChuck Lever 	status = decode_putfh(xdr);
6030bf269551SChuck Lever 	if (status)
60311da177e4SLinus Torvalds 		goto out;
6032bf269551SChuck Lever 	status = decode_savefh(xdr);
6033bf269551SChuck Lever 	if (status)
603456ae19f3STrond Myklebust 		goto out;
6035bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6036bf269551SChuck Lever 	if (status)
60371da177e4SLinus Torvalds 		goto out;
6038bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6039bf269551SChuck Lever 	if (status)
60401da177e4SLinus Torvalds 		goto out;
60416926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->fattr, res->server))
604256ae19f3STrond Myklebust 		goto out;
6043bf269551SChuck Lever 	status = decode_restorefh(xdr);
6044bf269551SChuck Lever 	if (status)
604556ae19f3STrond Myklebust 		goto out;
60466926afd1STrond Myklebust 	decode_getfattr(xdr, res->dir_fattr, res->server);
60471da177e4SLinus Torvalds out:
60481da177e4SLinus Torvalds 	return status;
60491da177e4SLinus Torvalds }
60501da177e4SLinus Torvalds 
60511da177e4SLinus Torvalds /*
60521da177e4SLinus Torvalds  * Decode SYMLINK response
60531da177e4SLinus Torvalds  */
6054bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6055bf269551SChuck Lever 				struct nfs4_create_res *res)
60561da177e4SLinus Torvalds {
6057bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
60581da177e4SLinus Torvalds }
60591da177e4SLinus Torvalds 
60601da177e4SLinus Torvalds /*
60611da177e4SLinus Torvalds  * Decode GETATTR response
60621da177e4SLinus Torvalds  */
6063bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6064bf269551SChuck Lever 				struct nfs4_getattr_res *res)
60651da177e4SLinus Torvalds {
60661da177e4SLinus Torvalds 	struct compound_hdr hdr;
60671da177e4SLinus Torvalds 	int status;
60681da177e4SLinus Torvalds 
6069bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60701da177e4SLinus Torvalds 	if (status)
60711da177e4SLinus Torvalds 		goto out;
6072bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60739b7b9fccSAndy Adamson 	if (status)
60749b7b9fccSAndy Adamson 		goto out;
6075bf269551SChuck Lever 	status = decode_putfh(xdr);
60761da177e4SLinus Torvalds 	if (status)
60771da177e4SLinus Torvalds 		goto out;
60786926afd1STrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
60791da177e4SLinus Torvalds out:
60801da177e4SLinus Torvalds 	return status;
60811da177e4SLinus Torvalds }
60821da177e4SLinus Torvalds 
608323ec6965SJ. Bruce Fields /*
608423ec6965SJ. Bruce Fields  * Encode an SETACL request
608523ec6965SJ. Bruce Fields  */
60869f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
60879f06c719SChuck Lever 				struct nfs_setaclargs *args)
608823ec6965SJ. Bruce Fields {
608923ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
609066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
609123ec6965SJ. Bruce Fields 	};
609223ec6965SJ. Bruce Fields 
60939f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
60949f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
60959f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
60969f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6097d017931cSAndy Adamson 	encode_nops(&hdr);
609823ec6965SJ. Bruce Fields }
609905d564feSAndy Adamson 
610023ec6965SJ. Bruce Fields /*
610123ec6965SJ. Bruce Fields  * Decode SETACL response
610223ec6965SJ. Bruce Fields  */
610323ec6965SJ. Bruce Fields static int
6104bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
610573c403a9SBenny Halevy 		    struct nfs_setaclres *res)
610623ec6965SJ. Bruce Fields {
610723ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
610823ec6965SJ. Bruce Fields 	int status;
610923ec6965SJ. Bruce Fields 
6110bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
611123ec6965SJ. Bruce Fields 	if (status)
611223ec6965SJ. Bruce Fields 		goto out;
6113bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61149b7b9fccSAndy Adamson 	if (status)
61159b7b9fccSAndy Adamson 		goto out;
6116bf269551SChuck Lever 	status = decode_putfh(xdr);
611723ec6965SJ. Bruce Fields 	if (status)
611823ec6965SJ. Bruce Fields 		goto out;
6119bf269551SChuck Lever 	status = decode_setattr(xdr);
612023ec6965SJ. Bruce Fields out:
612123ec6965SJ. Bruce Fields 	return status;
612223ec6965SJ. Bruce Fields }
61231da177e4SLinus Torvalds 
61241da177e4SLinus Torvalds /*
6125029d105eSJ. Bruce Fields  * Decode GETACL response
6126029d105eSJ. Bruce Fields  */
6127029d105eSJ. Bruce Fields static int
6128bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6129663c79b3SBenny Halevy 		    struct nfs_getaclres *res)
6130029d105eSJ. Bruce Fields {
6131029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6132029d105eSJ. Bruce Fields 	int status;
6133029d105eSJ. Bruce Fields 
6134331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6135331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6136331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6137331818f1STrond Myklebust 	}
6138bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6139029d105eSJ. Bruce Fields 	if (status)
6140029d105eSJ. Bruce Fields 		goto out;
6141bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61429b7b9fccSAndy Adamson 	if (status)
61439b7b9fccSAndy Adamson 		goto out;
6144bf269551SChuck Lever 	status = decode_putfh(xdr);
6145029d105eSJ. Bruce Fields 	if (status)
6146029d105eSJ. Bruce Fields 		goto out;
6147bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6148029d105eSJ. Bruce Fields 
6149029d105eSJ. Bruce Fields out:
6150029d105eSJ. Bruce Fields 	return status;
6151029d105eSJ. Bruce Fields }
6152029d105eSJ. Bruce Fields 
6153029d105eSJ. Bruce Fields /*
61541da177e4SLinus Torvalds  * Decode CLOSE response
61551da177e4SLinus Torvalds  */
6156bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6157bf269551SChuck Lever 			      struct nfs_closeres *res)
61581da177e4SLinus Torvalds {
61591da177e4SLinus Torvalds 	struct compound_hdr hdr;
61601da177e4SLinus Torvalds 	int status;
61611da177e4SLinus Torvalds 
6162bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61631da177e4SLinus Torvalds 	if (status)
61641da177e4SLinus Torvalds 		goto out;
6165bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61669b7b9fccSAndy Adamson 	if (status)
61679b7b9fccSAndy Adamson 		goto out;
6168bf269551SChuck Lever 	status = decode_putfh(xdr);
61691da177e4SLinus Torvalds 	if (status)
61701da177e4SLinus Torvalds 		goto out;
6171bf269551SChuck Lever 	status = decode_close(xdr, res);
6172516a6af6STrond Myklebust 	if (status != 0)
6173516a6af6STrond Myklebust 		goto out;
6174516a6af6STrond Myklebust 	/*
6175516a6af6STrond Myklebust 	 * Note: Server may do delete on close for this file
6176516a6af6STrond Myklebust 	 * 	in which case the getattr call will fail with
6177516a6af6STrond Myklebust 	 * 	an ESTALE error. Shouldn't be a problem,
6178516a6af6STrond Myklebust 	 * 	though, since fattr->valid will remain unset.
6179516a6af6STrond Myklebust 	 */
61806926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
61811da177e4SLinus Torvalds out:
61821da177e4SLinus Torvalds 	return status;
61831da177e4SLinus Torvalds }
61841da177e4SLinus Torvalds 
61851da177e4SLinus Torvalds /*
61861da177e4SLinus Torvalds  * Decode OPEN response
61871da177e4SLinus Torvalds  */
6188bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6189bf269551SChuck Lever 			     struct nfs_openres *res)
61901da177e4SLinus Torvalds {
61911da177e4SLinus Torvalds 	struct compound_hdr hdr;
61921da177e4SLinus Torvalds 	int status;
61931da177e4SLinus Torvalds 
6194bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61951da177e4SLinus Torvalds 	if (status)
61961da177e4SLinus Torvalds 		goto out;
6197bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61989b7b9fccSAndy Adamson 	if (status)
61999b7b9fccSAndy Adamson 		goto out;
6200bf269551SChuck Lever 	status = decode_putfh(xdr);
62011da177e4SLinus Torvalds 	if (status)
62021da177e4SLinus Torvalds 		goto out;
6203bf269551SChuck Lever 	status = decode_savefh(xdr);
620456ae19f3STrond Myklebust 	if (status)
620556ae19f3STrond Myklebust 		goto out;
6206bf269551SChuck Lever 	status = decode_open(xdr, res);
62071da177e4SLinus Torvalds 	if (status)
62081da177e4SLinus Torvalds 		goto out;
6209bf269551SChuck Lever 	if (decode_getfh(xdr, &res->fh) != 0)
62101da177e4SLinus Torvalds 		goto out;
62116926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
621256ae19f3STrond Myklebust 		goto out;
6213bf269551SChuck Lever 	if (decode_restorefh(xdr) != 0)
621456ae19f3STrond Myklebust 		goto out;
62156926afd1STrond Myklebust 	decode_getfattr(xdr, res->dir_attr, res->server);
62161da177e4SLinus Torvalds out:
62171da177e4SLinus Torvalds 	return status;
62181da177e4SLinus Torvalds }
62191da177e4SLinus Torvalds 
62201da177e4SLinus Torvalds /*
62211da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
62221da177e4SLinus Torvalds  */
6223bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6224bf269551SChuck Lever 				     struct xdr_stream *xdr,
6225bf269551SChuck Lever 				     struct nfs_open_confirmres *res)
62261da177e4SLinus Torvalds {
62271da177e4SLinus Torvalds 	struct compound_hdr hdr;
62281da177e4SLinus Torvalds 	int status;
62291da177e4SLinus Torvalds 
6230bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62311da177e4SLinus Torvalds 	if (status)
62321da177e4SLinus Torvalds 		goto out;
6233bf269551SChuck Lever 	status = decode_putfh(xdr);
62341da177e4SLinus Torvalds 	if (status)
62351da177e4SLinus Torvalds 		goto out;
6236bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
62371da177e4SLinus Torvalds out:
62381da177e4SLinus Torvalds 	return status;
62391da177e4SLinus Torvalds }
62401da177e4SLinus Torvalds 
62411da177e4SLinus Torvalds /*
62421da177e4SLinus Torvalds  * Decode OPEN response
62431da177e4SLinus Torvalds  */
6244bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6245bf269551SChuck Lever 				    struct xdr_stream *xdr,
6246bf269551SChuck Lever 				    struct nfs_openres *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_sequence(xdr, &res->seq_res, rqstp);
62559b7b9fccSAndy Adamson 	if (status)
62569b7b9fccSAndy Adamson 		goto out;
6257bf269551SChuck Lever 	status = decode_putfh(xdr);
62581da177e4SLinus Torvalds 	if (status)
62591da177e4SLinus Torvalds 		goto out;
6260bf269551SChuck Lever 	status = decode_open(xdr, res);
6261864472e9STrond Myklebust 	if (status)
6262864472e9STrond Myklebust 		goto out;
62636926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
62641da177e4SLinus Torvalds out:
62651da177e4SLinus Torvalds 	return status;
62661da177e4SLinus Torvalds }
62671da177e4SLinus Torvalds 
62681da177e4SLinus Torvalds /*
62691da177e4SLinus Torvalds  * Decode SETATTR response
62701da177e4SLinus Torvalds  */
6271bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6272bf269551SChuck Lever 				struct xdr_stream *xdr,
6273bf269551SChuck Lever 				struct nfs_setattrres *res)
62741da177e4SLinus Torvalds {
62751da177e4SLinus Torvalds 	struct compound_hdr hdr;
62761da177e4SLinus Torvalds 	int status;
62771da177e4SLinus Torvalds 
6278bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62791da177e4SLinus Torvalds 	if (status)
62801da177e4SLinus Torvalds 		goto out;
6281bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62829b7b9fccSAndy Adamson 	if (status)
62839b7b9fccSAndy Adamson 		goto out;
6284bf269551SChuck Lever 	status = decode_putfh(xdr);
62851da177e4SLinus Torvalds 	if (status)
62861da177e4SLinus Torvalds 		goto out;
6287bf269551SChuck Lever 	status = decode_setattr(xdr);
62881da177e4SLinus Torvalds 	if (status)
62891da177e4SLinus Torvalds 		goto out;
62906926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
62911da177e4SLinus Torvalds out:
62921da177e4SLinus Torvalds 	return status;
62931da177e4SLinus Torvalds }
62941da177e4SLinus Torvalds 
62951da177e4SLinus Torvalds /*
62961da177e4SLinus Torvalds  * Decode LOCK response
62971da177e4SLinus Torvalds  */
6298bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6299bf269551SChuck Lever 			     struct nfs_lock_res *res)
63001da177e4SLinus Torvalds {
63011da177e4SLinus Torvalds 	struct compound_hdr hdr;
63021da177e4SLinus Torvalds 	int status;
63031da177e4SLinus Torvalds 
6304bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63051da177e4SLinus Torvalds 	if (status)
63061da177e4SLinus Torvalds 		goto out;
6307bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63089b7b9fccSAndy Adamson 	if (status)
63099b7b9fccSAndy Adamson 		goto out;
6310bf269551SChuck Lever 	status = decode_putfh(xdr);
63111da177e4SLinus Torvalds 	if (status)
63121da177e4SLinus Torvalds 		goto out;
6313bf269551SChuck Lever 	status = decode_lock(xdr, res);
63141da177e4SLinus Torvalds out:
63151da177e4SLinus Torvalds 	return status;
63161da177e4SLinus Torvalds }
63171da177e4SLinus Torvalds 
63181da177e4SLinus Torvalds /*
63191da177e4SLinus Torvalds  * Decode LOCKT response
63201da177e4SLinus Torvalds  */
6321bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6322bf269551SChuck Lever 			      struct nfs_lockt_res *res)
63231da177e4SLinus Torvalds {
63241da177e4SLinus Torvalds 	struct compound_hdr hdr;
63251da177e4SLinus Torvalds 	int status;
63261da177e4SLinus Torvalds 
6327bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63281da177e4SLinus Torvalds 	if (status)
63291da177e4SLinus Torvalds 		goto out;
6330bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63319b7b9fccSAndy Adamson 	if (status)
63329b7b9fccSAndy Adamson 		goto out;
6333bf269551SChuck Lever 	status = decode_putfh(xdr);
63341da177e4SLinus Torvalds 	if (status)
63351da177e4SLinus Torvalds 		goto out;
6336bf269551SChuck Lever 	status = decode_lockt(xdr, res);
63371da177e4SLinus Torvalds out:
63381da177e4SLinus Torvalds 	return status;
63391da177e4SLinus Torvalds }
63401da177e4SLinus Torvalds 
63411da177e4SLinus Torvalds /*
63421da177e4SLinus Torvalds  * Decode LOCKU response
63431da177e4SLinus Torvalds  */
6344bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6345bf269551SChuck Lever 			      struct nfs_locku_res *res)
63461da177e4SLinus Torvalds {
63471da177e4SLinus Torvalds 	struct compound_hdr hdr;
63481da177e4SLinus Torvalds 	int status;
63491da177e4SLinus Torvalds 
6350bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63511da177e4SLinus Torvalds 	if (status)
63521da177e4SLinus Torvalds 		goto out;
6353bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63549b7b9fccSAndy Adamson 	if (status)
63559b7b9fccSAndy Adamson 		goto out;
6356bf269551SChuck Lever 	status = decode_putfh(xdr);
63571da177e4SLinus Torvalds 	if (status)
63581da177e4SLinus Torvalds 		goto out;
6359bf269551SChuck Lever 	status = decode_locku(xdr, res);
63601da177e4SLinus Torvalds out:
63611da177e4SLinus Torvalds 	return status;
63621da177e4SLinus Torvalds }
63631da177e4SLinus Torvalds 
6364bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6365bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6366d3c7b7ccSTrond Myklebust {
6367d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6368d3c7b7ccSTrond Myklebust 	int status;
6369d3c7b7ccSTrond Myklebust 
6370bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6371d3c7b7ccSTrond Myklebust 	if (!status)
6372bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6373d3c7b7ccSTrond Myklebust 	return status;
6374d3c7b7ccSTrond Myklebust }
6375d3c7b7ccSTrond Myklebust 
63761da177e4SLinus Torvalds /*
63771da177e4SLinus Torvalds  * Decode READLINK response
63781da177e4SLinus Torvalds  */
6379bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6380bf269551SChuck Lever 				 struct xdr_stream *xdr,
6381f50c7000SBenny Halevy 				 struct nfs4_readlink_res *res)
63821da177e4SLinus Torvalds {
63831da177e4SLinus Torvalds 	struct compound_hdr hdr;
63841da177e4SLinus Torvalds 	int status;
63851da177e4SLinus Torvalds 
6386bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63871da177e4SLinus Torvalds 	if (status)
63881da177e4SLinus Torvalds 		goto out;
6389bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63909b7b9fccSAndy Adamson 	if (status)
63919b7b9fccSAndy Adamson 		goto out;
6392bf269551SChuck Lever 	status = decode_putfh(xdr);
63931da177e4SLinus Torvalds 	if (status)
63941da177e4SLinus Torvalds 		goto out;
6395bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
63961da177e4SLinus Torvalds out:
63971da177e4SLinus Torvalds 	return status;
63981da177e4SLinus Torvalds }
63991da177e4SLinus Torvalds 
64001da177e4SLinus Torvalds /*
64011da177e4SLinus Torvalds  * Decode READDIR response
64021da177e4SLinus Torvalds  */
6403bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6404bf269551SChuck Lever 				struct nfs4_readdir_res *res)
64051da177e4SLinus Torvalds {
64061da177e4SLinus Torvalds 	struct compound_hdr hdr;
64071da177e4SLinus Torvalds 	int status;
64081da177e4SLinus Torvalds 
6409bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64101da177e4SLinus Torvalds 	if (status)
64111da177e4SLinus Torvalds 		goto out;
6412bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64139b7b9fccSAndy Adamson 	if (status)
64149b7b9fccSAndy Adamson 		goto out;
6415bf269551SChuck Lever 	status = decode_putfh(xdr);
64161da177e4SLinus Torvalds 	if (status)
64171da177e4SLinus Torvalds 		goto out;
6418bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
64191da177e4SLinus Torvalds out:
64201da177e4SLinus Torvalds 	return status;
64211da177e4SLinus Torvalds }
64221da177e4SLinus Torvalds 
64231da177e4SLinus Torvalds /*
64241da177e4SLinus Torvalds  * Decode Read response
64251da177e4SLinus Torvalds  */
6426bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6427bf269551SChuck Lever 			     struct nfs_readres *res)
64281da177e4SLinus Torvalds {
64291da177e4SLinus Torvalds 	struct compound_hdr hdr;
64301da177e4SLinus Torvalds 	int status;
64311da177e4SLinus Torvalds 
6432bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64331da177e4SLinus Torvalds 	if (status)
64341da177e4SLinus Torvalds 		goto out;
6435bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64369b7b9fccSAndy Adamson 	if (status)
64379b7b9fccSAndy Adamson 		goto out;
6438bf269551SChuck Lever 	status = decode_putfh(xdr);
64391da177e4SLinus Torvalds 	if (status)
64401da177e4SLinus Torvalds 		goto out;
6441bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
64421da177e4SLinus Torvalds 	if (!status)
64431da177e4SLinus Torvalds 		status = res->count;
64441da177e4SLinus Torvalds out:
64451da177e4SLinus Torvalds 	return status;
64461da177e4SLinus Torvalds }
64471da177e4SLinus Torvalds 
64481da177e4SLinus Torvalds /*
64491da177e4SLinus Torvalds  * Decode WRITE response
64501da177e4SLinus Torvalds  */
6451bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6452bf269551SChuck Lever 			      struct nfs_writeres *res)
64531da177e4SLinus Torvalds {
64541da177e4SLinus Torvalds 	struct compound_hdr hdr;
64551da177e4SLinus Torvalds 	int status;
64561da177e4SLinus Torvalds 
6457bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64581da177e4SLinus Torvalds 	if (status)
64591da177e4SLinus Torvalds 		goto out;
6460bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64619b7b9fccSAndy Adamson 	if (status)
64629b7b9fccSAndy Adamson 		goto out;
6463bf269551SChuck Lever 	status = decode_putfh(xdr);
64641da177e4SLinus Torvalds 	if (status)
64651da177e4SLinus Torvalds 		goto out;
6466bf269551SChuck Lever 	status = decode_write(xdr, res);
64674f9838c7STrond Myklebust 	if (status)
64684f9838c7STrond Myklebust 		goto out;
64697ffd1064SFred Isaman 	if (res->fattr)
64706926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
64711da177e4SLinus Torvalds 	if (!status)
64721da177e4SLinus Torvalds 		status = res->count;
64731da177e4SLinus Torvalds out:
64741da177e4SLinus Torvalds 	return status;
64751da177e4SLinus Torvalds }
64761da177e4SLinus Torvalds 
64771da177e4SLinus Torvalds /*
64781da177e4SLinus Torvalds  * Decode COMMIT response
64791da177e4SLinus Torvalds  */
6480bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6481bf269551SChuck Lever 			       struct nfs_writeres *res)
64821da177e4SLinus Torvalds {
64831da177e4SLinus Torvalds 	struct compound_hdr hdr;
64841da177e4SLinus Torvalds 	int status;
64851da177e4SLinus Torvalds 
6486bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64871da177e4SLinus Torvalds 	if (status)
64881da177e4SLinus Torvalds 		goto out;
6489bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64909b7b9fccSAndy Adamson 	if (status)
64919b7b9fccSAndy Adamson 		goto out;
6492bf269551SChuck Lever 	status = decode_putfh(xdr);
64931da177e4SLinus Torvalds 	if (status)
64941da177e4SLinus Torvalds 		goto out;
6495bf269551SChuck Lever 	status = decode_commit(xdr, res);
64964f9838c7STrond Myklebust 	if (status)
64974f9838c7STrond Myklebust 		goto out;
6498988b6dceSFred Isaman 	if (res->fattr)
64996926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
65001da177e4SLinus Torvalds out:
65011da177e4SLinus Torvalds 	return status;
65021da177e4SLinus Torvalds }
65031da177e4SLinus Torvalds 
65041da177e4SLinus Torvalds /*
65058b173218SRicardo Labiaga  * Decode FSINFO response
65061da177e4SLinus Torvalds  */
6507bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
65083dda5e43SBenny Halevy 			       struct nfs4_fsinfo_res *res)
65091da177e4SLinus Torvalds {
65101da177e4SLinus Torvalds 	struct compound_hdr hdr;
65111da177e4SLinus Torvalds 	int status;
65121da177e4SLinus Torvalds 
6513bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65141da177e4SLinus Torvalds 	if (!status)
6515bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65169b7b9fccSAndy Adamson 	if (!status)
6517bf269551SChuck Lever 		status = decode_putfh(xdr);
65181da177e4SLinus Torvalds 	if (!status)
6519bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
65201da177e4SLinus Torvalds 	return status;
65211da177e4SLinus Torvalds }
65221da177e4SLinus Torvalds 
65231da177e4SLinus Torvalds /*
65248b173218SRicardo Labiaga  * Decode PATHCONF response
65251da177e4SLinus Torvalds  */
6526bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6527d45b2989SBenny Halevy 				 struct nfs4_pathconf_res *res)
65281da177e4SLinus Torvalds {
65291da177e4SLinus Torvalds 	struct compound_hdr hdr;
65301da177e4SLinus Torvalds 	int status;
65311da177e4SLinus Torvalds 
6532bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65331da177e4SLinus Torvalds 	if (!status)
6534bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65359b7b9fccSAndy Adamson 	if (!status)
6536bf269551SChuck Lever 		status = decode_putfh(xdr);
65371da177e4SLinus Torvalds 	if (!status)
6538bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
65391da177e4SLinus Torvalds 	return status;
65401da177e4SLinus Torvalds }
65411da177e4SLinus Torvalds 
65421da177e4SLinus Torvalds /*
65438b173218SRicardo Labiaga  * Decode STATFS response
65441da177e4SLinus Torvalds  */
6545bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
654624ad148aSBenny Halevy 			       struct nfs4_statfs_res *res)
65471da177e4SLinus Torvalds {
65481da177e4SLinus Torvalds 	struct compound_hdr hdr;
65491da177e4SLinus Torvalds 	int status;
65501da177e4SLinus Torvalds 
6551bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65521da177e4SLinus Torvalds 	if (!status)
6553bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65549b7b9fccSAndy Adamson 	if (!status)
6555bf269551SChuck Lever 		status = decode_putfh(xdr);
65561da177e4SLinus Torvalds 	if (!status)
6557bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
65581da177e4SLinus Torvalds 	return status;
65591da177e4SLinus Torvalds }
65601da177e4SLinus Torvalds 
65611da177e4SLinus Torvalds /*
65628b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
65631da177e4SLinus Torvalds  */
6564bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6565bf269551SChuck Lever 				    struct xdr_stream *xdr,
6566bf269551SChuck Lever 				    struct nfs4_server_caps_res *res)
65671da177e4SLinus Torvalds {
65681da177e4SLinus Torvalds 	struct compound_hdr hdr;
65691da177e4SLinus Torvalds 	int status;
65701da177e4SLinus Torvalds 
6571bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65729b7b9fccSAndy Adamson 	if (status)
65739b7b9fccSAndy Adamson 		goto out;
6574bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
65759b7b9fccSAndy Adamson 	if (status)
65761da177e4SLinus Torvalds 		goto out;
6577bf269551SChuck Lever 	status = decode_putfh(xdr);
6578bf269551SChuck Lever 	if (status)
65791da177e4SLinus Torvalds 		goto out;
6580bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
65811da177e4SLinus Torvalds out:
65821da177e4SLinus Torvalds 	return status;
65831da177e4SLinus Torvalds }
65841da177e4SLinus Torvalds 
65851da177e4SLinus Torvalds /*
65861da177e4SLinus Torvalds  * Decode RENEW response
65871da177e4SLinus Torvalds  */
6588bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6589bf269551SChuck Lever 			      void *__unused)
65901da177e4SLinus Torvalds {
65911da177e4SLinus Torvalds 	struct compound_hdr hdr;
65921da177e4SLinus Torvalds 	int status;
65931da177e4SLinus Torvalds 
6594bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65951da177e4SLinus Torvalds 	if (!status)
6596bf269551SChuck Lever 		status = decode_renew(xdr);
65971da177e4SLinus Torvalds 	return status;
65981da177e4SLinus Torvalds }
65991da177e4SLinus Torvalds 
66001da177e4SLinus Torvalds /*
66018b173218SRicardo Labiaga  * Decode SETCLIENTID response
66021da177e4SLinus Torvalds  */
6603bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6604bf269551SChuck Lever 				    struct xdr_stream *xdr,
6605bb8b27e5STrond Myklebust 				    struct nfs4_setclientid_res *res)
66061da177e4SLinus Torvalds {
66071da177e4SLinus Torvalds 	struct compound_hdr hdr;
66081da177e4SLinus Torvalds 	int status;
66091da177e4SLinus Torvalds 
6610bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66111da177e4SLinus Torvalds 	if (!status)
6612bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
66131da177e4SLinus Torvalds 	return status;
66141da177e4SLinus Torvalds }
66151da177e4SLinus Torvalds 
66161da177e4SLinus Torvalds /*
66178b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
66181da177e4SLinus Torvalds  */
6619bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6620bf269551SChuck Lever 					    struct xdr_stream *xdr,
6621bf269551SChuck Lever 					    struct nfs_fsinfo *fsinfo)
66221da177e4SLinus Torvalds {
66231da177e4SLinus Torvalds 	struct compound_hdr hdr;
66241da177e4SLinus Torvalds 	int status;
66251da177e4SLinus Torvalds 
6626bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66271da177e4SLinus Torvalds 	if (!status)
6628bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
66291da177e4SLinus Torvalds 	if (!status)
6630bf269551SChuck Lever 		status = decode_putrootfh(xdr);
66311da177e4SLinus Torvalds 	if (!status)
6632bf269551SChuck Lever 		status = decode_fsinfo(xdr, fsinfo);
66331da177e4SLinus Torvalds 	return status;
66341da177e4SLinus Torvalds }
66351da177e4SLinus Torvalds 
66361da177e4SLinus Torvalds /*
66378b173218SRicardo Labiaga  * Decode DELEGRETURN response
66381da177e4SLinus Torvalds  */
6639bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6640bf269551SChuck Lever 				    struct xdr_stream *xdr,
6641bf269551SChuck Lever 				    struct nfs4_delegreturnres *res)
66421da177e4SLinus Torvalds {
66431da177e4SLinus Torvalds 	struct compound_hdr hdr;
66441da177e4SLinus Torvalds 	int status;
66451da177e4SLinus Torvalds 
6646bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66479b7b9fccSAndy Adamson 	if (status)
66489b7b9fccSAndy Adamson 		goto out;
6649bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66509b7b9fccSAndy Adamson 	if (status)
6651fa178f29STrond Myklebust 		goto out;
6652bf269551SChuck Lever 	status = decode_putfh(xdr);
6653fa178f29STrond Myklebust 	if (status != 0)
6654fa178f29STrond Myklebust 		goto out;
6655bf269551SChuck Lever 	status = decode_delegreturn(xdr);
6656556ae3bbSJeff Layton 	if (status != 0)
6657556ae3bbSJeff Layton 		goto out;
66586926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
6659fa178f29STrond Myklebust out:
66601da177e4SLinus Torvalds 	return status;
66611da177e4SLinus Torvalds }
66621da177e4SLinus Torvalds 
6663683b57b4STrond Myklebust /*
66648b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6665683b57b4STrond Myklebust  */
6666bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6667bf269551SChuck Lever 				     struct xdr_stream *xdr,
666822958463SBenny Halevy 				     struct nfs4_fs_locations_res *res)
6669683b57b4STrond Myklebust {
6670683b57b4STrond Myklebust 	struct compound_hdr hdr;
6671683b57b4STrond Myklebust 	int status;
6672683b57b4STrond Myklebust 
6673bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66749b7b9fccSAndy Adamson 	if (status)
66759b7b9fccSAndy Adamson 		goto out;
6676bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
66779b7b9fccSAndy Adamson 	if (status)
6678683b57b4STrond Myklebust 		goto out;
6679bf269551SChuck Lever 	status = decode_putfh(xdr);
6680bf269551SChuck Lever 	if (status)
6681683b57b4STrond Myklebust 		goto out;
6682bf269551SChuck Lever 	status = decode_lookup(xdr);
6683bf269551SChuck Lever 	if (status)
6684683b57b4STrond Myklebust 		goto out;
6685bf269551SChuck Lever 	xdr_enter_page(xdr, PAGE_SIZE);
66868b7e3f49STrond Myklebust 	status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
66878b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
66886926afd1STrond Myklebust 					 res->fs_locations->server);
6689683b57b4STrond Myklebust out:
6690683b57b4STrond Myklebust 	return status;
6691683b57b4STrond Myklebust }
6692683b57b4STrond Myklebust 
66935a5ea0d4SBryan Schumaker /*
66945a5ea0d4SBryan Schumaker  * Decode SECINFO response
66955a5ea0d4SBryan Schumaker  */
66965a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
66975a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
66985a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_res *res)
66995a5ea0d4SBryan Schumaker {
67005a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
67015a5ea0d4SBryan Schumaker 	int status;
67025a5ea0d4SBryan Schumaker 
67035a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
67045a5ea0d4SBryan Schumaker 	if (status)
67055a5ea0d4SBryan Schumaker 		goto out;
67065a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67075a5ea0d4SBryan Schumaker 	if (status)
67085a5ea0d4SBryan Schumaker 		goto out;
67095a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
67105a5ea0d4SBryan Schumaker 	if (status)
67115a5ea0d4SBryan Schumaker 		goto out;
67125a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
67135a5ea0d4SBryan Schumaker out:
67145a5ea0d4SBryan Schumaker 	return status;
67155a5ea0d4SBryan Schumaker }
67165a5ea0d4SBryan Schumaker 
671799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
671899fe60d0SBenny Halevy /*
67198b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
672099fe60d0SBenny Halevy  */
6721bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6722bf269551SChuck Lever 				    struct xdr_stream *xdr,
672399fe60d0SBenny Halevy 				    void *res)
672499fe60d0SBenny Halevy {
672599fe60d0SBenny Halevy 	struct compound_hdr hdr;
672699fe60d0SBenny Halevy 	int status;
672799fe60d0SBenny Halevy 
6728bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
672999fe60d0SBenny Halevy 	if (!status)
6730bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
673199fe60d0SBenny Halevy 	return status;
673299fe60d0SBenny Halevy }
67332050f0ccSAndy Adamson 
67342050f0ccSAndy Adamson /*
67358b173218SRicardo Labiaga  * Decode CREATE_SESSION response
6736fc931582SAndy Adamson  */
6737bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6738bf269551SChuck Lever 				       struct xdr_stream *xdr,
6739fc931582SAndy Adamson 				       struct nfs41_create_session_res *res)
6740fc931582SAndy Adamson {
6741fc931582SAndy Adamson 	struct compound_hdr hdr;
6742fc931582SAndy Adamson 	int status;
6743fc931582SAndy Adamson 
6744bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6745fc931582SAndy Adamson 	if (!status)
6746bf269551SChuck Lever 		status = decode_create_session(xdr, res);
6747fc931582SAndy Adamson 	return status;
6748fc931582SAndy Adamson }
6749fc931582SAndy Adamson 
6750fc931582SAndy Adamson /*
67518b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
67520f3e66c6SAndy Adamson  */
6753bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6754bf269551SChuck Lever 					struct xdr_stream *xdr,
6755bf269551SChuck Lever 					void *res)
67560f3e66c6SAndy Adamson {
67570f3e66c6SAndy Adamson 	struct compound_hdr hdr;
67580f3e66c6SAndy Adamson 	int status;
67590f3e66c6SAndy Adamson 
6760bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67610f3e66c6SAndy Adamson 	if (!status)
6762bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
67630f3e66c6SAndy Adamson 	return status;
67640f3e66c6SAndy Adamson }
67650f3e66c6SAndy Adamson 
67660f3e66c6SAndy Adamson /*
67678b173218SRicardo Labiaga  * Decode SEQUENCE response
6768fc01cea9SAndy Adamson  */
6769bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6770bf269551SChuck Lever 				 struct xdr_stream *xdr,
6771fc01cea9SAndy Adamson 				 struct nfs4_sequence_res *res)
6772fc01cea9SAndy Adamson {
6773fc01cea9SAndy Adamson 	struct compound_hdr hdr;
6774fc01cea9SAndy Adamson 	int status;
6775fc01cea9SAndy Adamson 
6776bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6777fc01cea9SAndy Adamson 	if (!status)
6778bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
6779fc01cea9SAndy Adamson 	return status;
6780fc01cea9SAndy Adamson }
6781fc01cea9SAndy Adamson 
6782fc01cea9SAndy Adamson /*
67838b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
67842050f0ccSAndy Adamson  */
6785bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6786bf269551SChuck Lever 				       struct xdr_stream *xdr,
67872050f0ccSAndy Adamson 				       struct nfs4_get_lease_time_res *res)
67882050f0ccSAndy Adamson {
67892050f0ccSAndy Adamson 	struct compound_hdr hdr;
67902050f0ccSAndy Adamson 	int status;
67912050f0ccSAndy Adamson 
6792bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67932050f0ccSAndy Adamson 	if (!status)
6794bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
67952050f0ccSAndy Adamson 	if (!status)
6796bf269551SChuck Lever 		status = decode_putrootfh(xdr);
67972050f0ccSAndy Adamson 	if (!status)
6798bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
67992050f0ccSAndy Adamson 	return status;
68002050f0ccSAndy Adamson }
680118019753SRicardo Labiaga 
680218019753SRicardo Labiaga /*
680318019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
680418019753SRicardo Labiaga  */
6805bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6806bf269551SChuck Lever 					 struct xdr_stream *xdr,
680718019753SRicardo Labiaga 					 struct nfs41_reclaim_complete_res *res)
680818019753SRicardo Labiaga {
680918019753SRicardo Labiaga 	struct compound_hdr hdr;
681018019753SRicardo Labiaga 	int status;
681118019753SRicardo Labiaga 
6812bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
681318019753SRicardo Labiaga 	if (!status)
6814bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
681518019753SRicardo Labiaga 	if (!status)
6816bf269551SChuck Lever 		status = decode_reclaim_complete(xdr, (void *)NULL);
681718019753SRicardo Labiaga 	return status;
681818019753SRicardo Labiaga }
6819b1f69b75SAndy Adamson 
6820b1f69b75SAndy Adamson /*
68217f11d8d3SAndy Adamson  * Decode GETDEVICELIST response
68227f11d8d3SAndy Adamson  */
68237f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
68247f11d8d3SAndy Adamson 				      struct xdr_stream *xdr,
68257f11d8d3SAndy Adamson 				      struct nfs4_getdevicelist_res *res)
68267f11d8d3SAndy Adamson {
68277f11d8d3SAndy Adamson 	struct compound_hdr hdr;
68287f11d8d3SAndy Adamson 	int status;
68297f11d8d3SAndy Adamson 
68307f11d8d3SAndy Adamson 	dprintk("encoding getdevicelist!\n");
68317f11d8d3SAndy Adamson 
68327f11d8d3SAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
68337f11d8d3SAndy Adamson 	if (status != 0)
68347f11d8d3SAndy Adamson 		goto out;
68357f11d8d3SAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68367f11d8d3SAndy Adamson 	if (status != 0)
68377f11d8d3SAndy Adamson 		goto out;
68387f11d8d3SAndy Adamson 	status = decode_putfh(xdr);
68397f11d8d3SAndy Adamson 	if (status != 0)
68407f11d8d3SAndy Adamson 		goto out;
68417f11d8d3SAndy Adamson 	status = decode_getdevicelist(xdr, res->devlist);
68427f11d8d3SAndy Adamson out:
68437f11d8d3SAndy Adamson 	return status;
68447f11d8d3SAndy Adamson }
68457f11d8d3SAndy Adamson 
68467f11d8d3SAndy Adamson /*
6847b1f69b75SAndy Adamson  * Decode GETDEVINFO response
6848b1f69b75SAndy Adamson  */
6849bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6850bf269551SChuck Lever 				      struct xdr_stream *xdr,
6851b1f69b75SAndy Adamson 				      struct nfs4_getdeviceinfo_res *res)
6852b1f69b75SAndy Adamson {
6853b1f69b75SAndy Adamson 	struct compound_hdr hdr;
6854b1f69b75SAndy Adamson 	int status;
6855b1f69b75SAndy Adamson 
6856bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6857b1f69b75SAndy Adamson 	if (status != 0)
6858b1f69b75SAndy Adamson 		goto out;
6859bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6860b1f69b75SAndy Adamson 	if (status != 0)
6861b1f69b75SAndy Adamson 		goto out;
6862bf269551SChuck Lever 	status = decode_getdeviceinfo(xdr, res->pdev);
6863b1f69b75SAndy Adamson out:
6864b1f69b75SAndy Adamson 	return status;
6865b1f69b75SAndy Adamson }
6866b1f69b75SAndy Adamson 
6867b1f69b75SAndy Adamson /*
6868b1f69b75SAndy Adamson  * Decode LAYOUTGET response
6869b1f69b75SAndy Adamson  */
6870bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6871bf269551SChuck Lever 				  struct xdr_stream *xdr,
6872b1f69b75SAndy Adamson 				  struct nfs4_layoutget_res *res)
6873b1f69b75SAndy Adamson {
6874b1f69b75SAndy Adamson 	struct compound_hdr hdr;
6875b1f69b75SAndy Adamson 	int status;
6876b1f69b75SAndy Adamson 
6877bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6878b1f69b75SAndy Adamson 	if (status)
6879b1f69b75SAndy Adamson 		goto out;
6880bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6881b1f69b75SAndy Adamson 	if (status)
6882b1f69b75SAndy Adamson 		goto out;
6883bf269551SChuck Lever 	status = decode_putfh(xdr);
6884b1f69b75SAndy Adamson 	if (status)
6885b1f69b75SAndy Adamson 		goto out;
6886bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
6887b1f69b75SAndy Adamson out:
6888b1f69b75SAndy Adamson 	return status;
6889b1f69b75SAndy Adamson }
6890863a3c6cSAndy Adamson 
6891863a3c6cSAndy Adamson /*
6892cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
6893cbe82603SBenny Halevy  */
6894cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6895cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
6896cbe82603SBenny Halevy 				     struct nfs4_layoutreturn_res *res)
6897cbe82603SBenny Halevy {
6898cbe82603SBenny Halevy 	struct compound_hdr hdr;
6899cbe82603SBenny Halevy 	int status;
6900cbe82603SBenny Halevy 
6901cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
6902cbe82603SBenny Halevy 	if (status)
6903cbe82603SBenny Halevy 		goto out;
6904cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6905cbe82603SBenny Halevy 	if (status)
6906cbe82603SBenny Halevy 		goto out;
6907cbe82603SBenny Halevy 	status = decode_putfh(xdr);
6908cbe82603SBenny Halevy 	if (status)
6909cbe82603SBenny Halevy 		goto out;
6910cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
6911cbe82603SBenny Halevy out:
6912cbe82603SBenny Halevy 	return status;
6913cbe82603SBenny Halevy }
6914cbe82603SBenny Halevy 
6915cbe82603SBenny Halevy /*
6916863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
6917863a3c6cSAndy Adamson  */
6918863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6919863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
6920863a3c6cSAndy Adamson 				     struct nfs4_layoutcommit_res *res)
6921863a3c6cSAndy Adamson {
6922863a3c6cSAndy Adamson 	struct compound_hdr hdr;
6923863a3c6cSAndy Adamson 	int status;
6924863a3c6cSAndy Adamson 
6925863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
6926863a3c6cSAndy Adamson 	if (status)
6927863a3c6cSAndy Adamson 		goto out;
6928863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6929863a3c6cSAndy Adamson 	if (status)
6930863a3c6cSAndy Adamson 		goto out;
6931863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
6932863a3c6cSAndy Adamson 	if (status)
6933863a3c6cSAndy Adamson 		goto out;
6934863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
6935863a3c6cSAndy Adamson 	if (status)
6936863a3c6cSAndy Adamson 		goto out;
69376926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
6938863a3c6cSAndy Adamson out:
6939863a3c6cSAndy Adamson 	return status;
6940863a3c6cSAndy Adamson }
6941fca78d6dSBryan Schumaker 
6942fca78d6dSBryan Schumaker /*
6943fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
6944fca78d6dSBryan Schumaker  */
6945fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6946fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
6947fca78d6dSBryan Schumaker 					struct nfs4_secinfo_res *res)
6948fca78d6dSBryan Schumaker {
6949fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
6950fca78d6dSBryan Schumaker 	int status;
6951fca78d6dSBryan Schumaker 
6952fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
6953fca78d6dSBryan Schumaker 	if (status)
6954fca78d6dSBryan Schumaker 		goto out;
6955fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6956fca78d6dSBryan Schumaker 	if (status)
6957fca78d6dSBryan Schumaker 		goto out;
6958fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
6959fca78d6dSBryan Schumaker 	if (status)
6960fca78d6dSBryan Schumaker 		goto out;
6961fca78d6dSBryan Schumaker 	status = decode_secinfo(xdr, res);
6962fca78d6dSBryan Schumaker out:
6963fca78d6dSBryan Schumaker 	return status;
6964fca78d6dSBryan Schumaker }
69657d974794SBryan Schumaker 
69667d974794SBryan Schumaker /*
69677d974794SBryan Schumaker  * Decode TEST_STATEID response
69687d974794SBryan Schumaker  */
69697d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
69707d974794SBryan Schumaker 				     struct xdr_stream *xdr,
69717d974794SBryan Schumaker 				     struct nfs41_test_stateid_res *res)
69727d974794SBryan Schumaker {
69737d974794SBryan Schumaker 	struct compound_hdr hdr;
69747d974794SBryan Schumaker 	int status;
69757d974794SBryan Schumaker 
69767d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69777d974794SBryan Schumaker 	if (status)
69787d974794SBryan Schumaker 		goto out;
69797d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69807d974794SBryan Schumaker 	if (status)
69817d974794SBryan Schumaker 		goto out;
69827d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
69837d974794SBryan Schumaker out:
69847d974794SBryan Schumaker 	return status;
69857d974794SBryan Schumaker }
69869aeda35fSBryan Schumaker 
69879aeda35fSBryan Schumaker /*
69889aeda35fSBryan Schumaker  * Decode FREE_STATEID response
69899aeda35fSBryan Schumaker  */
69909aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
69919aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
69929aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_res *res)
69939aeda35fSBryan Schumaker {
69949aeda35fSBryan Schumaker 	struct compound_hdr hdr;
69959aeda35fSBryan Schumaker 	int status;
69969aeda35fSBryan Schumaker 
69979aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69989aeda35fSBryan Schumaker 	if (status)
69999aeda35fSBryan Schumaker 		goto out;
70009aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
70019aeda35fSBryan Schumaker 	if (status)
70029aeda35fSBryan Schumaker 		goto out;
70039aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
70049aeda35fSBryan Schumaker out:
70059aeda35fSBryan Schumaker 	return status;
70069aeda35fSBryan Schumaker }
700799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
700899fe60d0SBenny Halevy 
7009573c4e1eSChuck Lever /**
7010573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7011573c4e1eSChuck Lever  *                      the local page cache.
7012573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7013573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7014573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7015573c4e1eSChuck Lever  *
7016573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7017573c4e1eSChuck Lever  * returned.
7018573c4e1eSChuck Lever  *
7019573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7020573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7021573c4e1eSChuck Lever  * on a directory already in our cache.
7022573c4e1eSChuck Lever  */
7023573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7024573c4e1eSChuck Lever 		       int plus)
70251da177e4SLinus Torvalds {
7026dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
70271da177e4SLinus Torvalds 	uint32_t len;
7028babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7029babddc72SBryan Schumaker 	if (unlikely(!p))
7030babddc72SBryan Schumaker 		goto out_overflow;
7031c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7032babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7033babddc72SBryan Schumaker 		if (unlikely(!p))
7034babddc72SBryan Schumaker 			goto out_overflow;
7035c08e76d0SChuck Lever 		if (*p == xdr_zero)
7036573c4e1eSChuck Lever 			return -EAGAIN;
70371da177e4SLinus Torvalds 		entry->eof = 1;
7038573c4e1eSChuck Lever 		return -EBADCOOKIE;
70391da177e4SLinus Torvalds 	}
70401da177e4SLinus Torvalds 
7041babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7042babddc72SBryan Schumaker 	if (unlikely(!p))
7043babddc72SBryan Schumaker 		goto out_overflow;
70441da177e4SLinus Torvalds 	entry->prev_cookie = entry->cookie;
70451da177e4SLinus Torvalds 	p = xdr_decode_hyper(p, &entry->cookie);
7046c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7047babddc72SBryan Schumaker 
70489af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7049babddc72SBryan Schumaker 	if (unlikely(!p))
7050babddc72SBryan Schumaker 		goto out_overflow;
70511da177e4SLinus Torvalds 	entry->name = (const char *) p;
70521da177e4SLinus Torvalds 
70531da177e4SLinus Torvalds 	/*
70541da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
70551da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
70561da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
70571da177e4SLinus Torvalds 	 */
70581da177e4SLinus Torvalds 	entry->ino = 1;
70594f082222STrond Myklebust 	entry->fattr->valid = 0;
70601da177e4SLinus Torvalds 
70619af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7062babddc72SBryan Schumaker 		goto out_overflow;
70639af8c222STrond Myklebust 
70649af8c222STrond Myklebust 	if (decode_attr_length(xdr, &len, &p) < 0)
7065babddc72SBryan Schumaker 		goto out_overflow;
70669af8c222STrond Myklebust 
7067573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
70688b7e3f49STrond Myklebust 				  NULL, entry->server) < 0)
7069babddc72SBryan Schumaker 		goto out_overflow;
707028331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
707128331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
707228331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
707382f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
70749af8c222STrond Myklebust 
70750b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
70760b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
70770b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
70780b26a0bfSTrond Myklebust 
7079573c4e1eSChuck Lever 	return 0;
7080babddc72SBryan Schumaker 
7081babddc72SBryan Schumaker out_overflow:
7082babddc72SBryan Schumaker 	print_overflow_msg(__func__, xdr);
7083573c4e1eSChuck Lever 	return -EAGAIN;
70841da177e4SLinus Torvalds }
70851da177e4SLinus Torvalds 
70861da177e4SLinus Torvalds /*
70871da177e4SLinus Torvalds  * We need to translate between nfs status return values and
70881da177e4SLinus Torvalds  * the local errno values which may not be the same.
70891da177e4SLinus Torvalds  */
70901da177e4SLinus Torvalds static struct {
70911da177e4SLinus Torvalds 	int stat;
70921da177e4SLinus Torvalds 	int errno;
70931da177e4SLinus Torvalds } nfs_errtbl[] = {
70941da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7095856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7096856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7097856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7098856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7099856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7100856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7101856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7102856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7103856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7104856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7105856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7106856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7107856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7108856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7109856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7110856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7111856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7112856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7113856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7114856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7115856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7116856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7117fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7118856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7119856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7120856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7121856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7122856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7123856dff3dSBenny Halevy 	{ -1,			-EIO		}
71241da177e4SLinus Torvalds };
71251da177e4SLinus Torvalds 
71261da177e4SLinus Torvalds /*
71271da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
71281da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
71291da177e4SLinus Torvalds  */
71301da177e4SLinus Torvalds static int
71310a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
71321da177e4SLinus Torvalds {
71331da177e4SLinus Torvalds 	int i;
71341da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
71351da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
71361da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
71371da177e4SLinus Torvalds 	}
71381da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
71391da177e4SLinus Torvalds 		/* The server is looney tunes. */
7140fdcb4577STrond Myklebust 		return -EREMOTEIO;
71411da177e4SLinus Torvalds 	}
71421da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
71431da177e4SLinus Torvalds 	 * handle it.
71441da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
71451da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
71461da177e4SLinus Torvalds 	 */
7147856dff3dSBenny Halevy 	return -stat;
71481da177e4SLinus Torvalds }
71491da177e4SLinus Torvalds 
71501da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
71511da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
71521da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
71539f06c719SChuck Lever 	.p_encode = (kxdreproc_t)nfs4_xdr_##argtype,		\
7154bf269551SChuck Lever 	.p_decode = (kxdrdproc_t)nfs4_xdr_##restype,		\
71552bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
71562bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7157cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7158cc0175c1SChuck Lever 	.p_name   = #proc,					\
71591da177e4SLinus Torvalds }
71601da177e4SLinus Torvalds 
71611da177e4SLinus Torvalds struct rpc_procinfo	nfs4_procedures[] = {
71621da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
71631da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
71641da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
71651da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
71661da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
71671da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
71681da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
71691da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
71701da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
71711da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
71721da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
71731da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
71741da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
71751da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
71761da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
71771da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
71781da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
71791da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
71801da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
71811da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
71821da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
71831da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
71841da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
71851da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
71861da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
71871da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
71881da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
71891da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
71901da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
71911da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
71921da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7193029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
719423ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7195683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7196d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
71975a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
719899fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
719999fe60d0SBenny Halevy 	PROC(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
7200fc931582SAndy Adamson 	PROC(CREATE_SESSION,	enc_create_session,	dec_create_session),
72010f3e66c6SAndy Adamson 	PROC(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
7202fc01cea9SAndy Adamson 	PROC(SEQUENCE,		enc_sequence,		dec_sequence),
72032050f0ccSAndy Adamson 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
720418019753SRicardo Labiaga 	PROC(RECLAIM_COMPLETE,	enc_reclaim_complete,	dec_reclaim_complete),
7205b1f69b75SAndy Adamson 	PROC(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
7206b1f69b75SAndy Adamson 	PROC(LAYOUTGET,		enc_layoutget,		dec_layoutget),
7207863a3c6cSAndy Adamson 	PROC(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
7208cbe82603SBenny Halevy 	PROC(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
7209fca78d6dSBryan Schumaker 	PROC(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
72107d974794SBryan Schumaker 	PROC(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
72119aeda35fSBryan Schumaker 	PROC(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
72127f11d8d3SAndy Adamson 	PROC(GETDEVICELIST,	enc_getdevicelist,	dec_getdevicelist),
721399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
72141da177e4SLinus Torvalds };
72151da177e4SLinus Torvalds 
7216a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
72171da177e4SLinus Torvalds 	.number			= 4,
7218e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
72191da177e4SLinus Torvalds 	.procs			= nfs4_procedures
72201da177e4SLinus Torvalds };
72211da177e4SLinus Torvalds 
72221da177e4SLinus Torvalds /*
72231da177e4SLinus Torvalds  * Local variables:
72241da177e4SLinus Torvalds  *  c-basic-offset: 8
72251da177e4SLinus Torvalds  * End:
72261da177e4SLinus Torvalds  */
7227